2018-11-10 11:51:19 +00:00
|
|
|
/*
|
2021-10-04 19:59:10 +00:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2018-11-10 11:51:19 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-05-11 22:02:10 +00:00
|
|
|
#include <stratosphere.hpp>
|
2018-11-10 11:51:19 +00:00
|
|
|
#include "fatal_task_sound.hpp"
|
|
|
|
|
2019-10-24 09:30:10 +00:00
|
|
|
namespace ams::fatal::srv {
|
2018-11-10 11:51:19 +00:00
|
|
|
|
2019-07-19 02:09:35 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
/* Task definition. */
|
2019-10-19 03:31:15 +00:00
|
|
|
class StopSoundTask : public ITaskWithDefaultStack {
|
2019-07-19 02:09:35 +00:00
|
|
|
private:
|
|
|
|
void StopSound();
|
|
|
|
public:
|
|
|
|
virtual Result Run() override;
|
|
|
|
virtual const char *GetName() const override {
|
|
|
|
return "SoundTask";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Task global. */
|
|
|
|
StopSoundTask g_stop_sound_task;
|
|
|
|
|
|
|
|
/* 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); };
|
|
|
|
|
|
|
|
struct {
|
2020-11-21 06:29:24 +00:00
|
|
|
u8 reg;
|
|
|
|
u16 val;
|
2019-07-19 02:09:35 +00:00
|
|
|
} __attribute__((packed)) cmd;
|
|
|
|
static_assert(sizeof(cmd) == 3, "I2C command definition!");
|
|
|
|
|
2020-11-21 06:29:24 +00:00
|
|
|
cmd.reg = 0x01;
|
|
|
|
cmd.val = 0xC8C8;
|
2019-07-19 02:09:35 +00:00
|
|
|
i2csessionSendAuto(&audio, &cmd, sizeof(cmd), I2cTransactionOption_All);
|
|
|
|
|
2020-11-21 06:29:24 +00:00
|
|
|
cmd.reg = 0x02;
|
|
|
|
cmd.val = 0xC8C8;
|
2019-07-19 02:09:35 +00:00
|
|
|
i2csessionSendAuto(&audio, &cmd, sizeof(cmd), I2cTransactionOption_All);
|
|
|
|
|
2020-11-21 06:29:24 +00:00
|
|
|
for (u8 reg = 97; reg <= 102; reg++) {
|
|
|
|
cmd.reg = reg;
|
2019-07-19 02:09:35 +00:00
|
|
|
cmd.val = 0;
|
|
|
|
i2csessionSendAuto(&audio, &cmd, sizeof(cmd), I2cTransactionOption_All);
|
|
|
|
}
|
|
|
|
}
|
2018-11-10 12:07:26 +00:00
|
|
|
}
|
2019-06-17 23:41:03 +00:00
|
|
|
|
2019-07-19 02:09:35 +00:00
|
|
|
/* Talk to the ALC5639 over GPIO, and disable audio output */
|
|
|
|
{
|
2020-10-30 18:54:30 +00:00
|
|
|
gpio::GpioPadSession audio;
|
|
|
|
if (R_SUCCEEDED(gpio::OpenSession(std::addressof(audio), gpio::DeviceCode_CodecLdoEnTemp))) {
|
|
|
|
ON_SCOPE_EXIT { gpio::CloseSession(std::addressof(audio)); };
|
2019-06-17 23:41:03 +00:00
|
|
|
|
2019-07-19 02:09:35 +00:00
|
|
|
/* Set direction output, sleep 200 ms so it can take effect. */
|
2020-10-30 18:54:30 +00:00
|
|
|
gpio::SetDirection(std::addressof(audio), gpio::Direction_Output);
|
|
|
|
os::SleepThread(TimeSpan::FromMilliSeconds(200));
|
2019-06-17 23:41:03 +00:00
|
|
|
|
2019-07-19 02:09:35 +00:00
|
|
|
/* Pull audio codec low. */
|
2020-10-30 18:54:30 +00:00
|
|
|
gpio::SetValue(std::addressof(audio), gpio::GpioValue_Low);
|
2019-07-19 02:09:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-17 23:41:03 +00:00
|
|
|
|
2019-07-19 02:09:35 +00:00
|
|
|
Result StopSoundTask::Run() {
|
|
|
|
StopSound();
|
2019-10-24 08:40:44 +00:00
|
|
|
return ResultSuccess();
|
2018-11-10 12:07:26 +00:00
|
|
|
}
|
2019-07-19 02:09:35 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ITask *GetStopSoundTask(const ThrowContext *ctx) {
|
|
|
|
g_stop_sound_task.Initialize(ctx);
|
|
|
|
return &g_stop_sound_task;
|
2018-11-10 12:07:26 +00:00
|
|
|
}
|
2018-11-10 11:51:19 +00:00
|
|
|
|
2018-11-10 12:07:26 +00:00
|
|
|
}
|