mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-19 01:15:08 -04:00
fatal: refactor into sts namespace
This commit is contained in:
parent
442ebff829
commit
39d041466d
38 changed files with 2176 additions and 1926 deletions
|
@ -14,60 +14,86 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include "fatal_task_sound.hpp"
|
||||
|
||||
namespace sts::fatal::srv {
|
||||
|
||||
void StopSoundTask::StopSound() {
|
||||
/* Talk to the ALC5639 over I2C, and disable audio output. */
|
||||
{
|
||||
I2cSession audio;
|
||||
if (R_SUCCEEDED(i2cOpenSession(&audio, I2cDevice_Alc5639))) {
|
||||
struct {
|
||||
u16 dev;
|
||||
u8 val;
|
||||
} __attribute__((packed)) cmd;
|
||||
static_assert(sizeof(cmd) == 3, "I2C command definition!");
|
||||
namespace {
|
||||
|
||||
cmd.dev = 0xC801;
|
||||
cmd.val = 200;
|
||||
i2csessionSendAuto(&audio, &cmd, sizeof(cmd), I2cTransactionOption_All);
|
||||
/* Task definition. */
|
||||
class StopSoundTask : public ITask {
|
||||
private:
|
||||
void StopSound();
|
||||
public:
|
||||
virtual Result Run() override;
|
||||
virtual const char *GetName() const override {
|
||||
return "SoundTask";
|
||||
}
|
||||
};
|
||||
|
||||
cmd.dev = 0xC802;
|
||||
cmd.val = 200;
|
||||
i2csessionSendAuto(&audio, &cmd, sizeof(cmd), I2cTransactionOption_All);
|
||||
/* Task global. */
|
||||
StopSoundTask g_stop_sound_task;
|
||||
|
||||
cmd.dev = 0xC802;
|
||||
cmd.val = 200;
|
||||
i2csessionSendAuto(&audio, &cmd, sizeof(cmd), I2cTransactionOption_All);
|
||||
/* Task implementation. */
|
||||
void StopSoundTask::StopSound() {
|
||||
/* Talk to the ALC5639 over I2C, and disable audio output. */
|
||||
{
|
||||
I2cSession audio;
|
||||
if (R_SUCCEEDED(i2cOpenSession(&audio, I2cDevice_Alc5639))) {
|
||||
ON_SCOPE_EXIT { i2csessionClose(&audio); };
|
||||
|
||||
for (u16 dev = 97; dev <= 102; dev++) {
|
||||
cmd.dev = dev;
|
||||
cmd.val = 0;
|
||||
i2csessionSendAuto(&audio, &cmd, sizeof(cmd), I2cTransactionOption_All);
|
||||
struct {
|
||||
u16 dev;
|
||||
u8 val;
|
||||
} __attribute__((packed)) cmd;
|
||||
static_assert(sizeof(cmd) == 3, "I2C command definition!");
|
||||
|
||||
cmd.dev = 0xC801;
|
||||
cmd.val = 200;
|
||||
i2csessionSendAuto(&audio, &cmd, sizeof(cmd), I2cTransactionOption_All);
|
||||
|
||||
cmd.dev = 0xC802;
|
||||
cmd.val = 200;
|
||||
i2csessionSendAuto(&audio, &cmd, sizeof(cmd), I2cTransactionOption_All);
|
||||
|
||||
cmd.dev = 0xC802;
|
||||
cmd.val = 200;
|
||||
i2csessionSendAuto(&audio, &cmd, sizeof(cmd), I2cTransactionOption_All);
|
||||
|
||||
for (u16 dev = 97; dev <= 102; dev++) {
|
||||
cmd.dev = dev;
|
||||
cmd.val = 0;
|
||||
i2csessionSendAuto(&audio, &cmd, sizeof(cmd), I2cTransactionOption_All);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
i2csessionClose(&audio);
|
||||
/* Talk to the ALC5639 over GPIO, and disable audio output */
|
||||
{
|
||||
GpioPadSession audio;
|
||||
if (R_SUCCEEDED(gpioOpenSession(&audio, GpioPadName_AudioCodec))) {
|
||||
ON_SCOPE_EXIT { gpioPadClose(&audio); };
|
||||
|
||||
/* Set direction output, sleep 200 ms so it can take effect. */
|
||||
gpioPadSetDirection(&audio, GpioDirection_Output);
|
||||
svcSleepThread(200000000UL);
|
||||
|
||||
/* Pull audio codec low. */
|
||||
gpioPadSetValue(&audio, GpioValue_Low);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Result StopSoundTask::Run() {
|
||||
StopSound();
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Talk to the ALC5639 over GPIO, and disable audio output */
|
||||
{
|
||||
GpioPadSession audio;
|
||||
if (R_SUCCEEDED(gpioOpenSession(&audio, GpioPadName_AudioCodec))) {
|
||||
/* Set direction output, sleep 200 ms so it can take effect. */
|
||||
gpioPadSetDirection(&audio, GpioDirection_Output);
|
||||
svcSleepThread(200000000UL);
|
||||
|
||||
/* Pull audio codec low. */
|
||||
gpioPadSetValue(&audio, GpioValue_Low);
|
||||
|
||||
gpioPadClose(&audio);
|
||||
}
|
||||
ITask *GetStopSoundTask(const ThrowContext *ctx) {
|
||||
g_stop_sound_task.Initialize(ctx);
|
||||
return &g_stop_sound_task;
|
||||
}
|
||||
}
|
||||
|
||||
Result StopSoundTask::Run() {
|
||||
StopSound();
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue