mirror of
https://github.com/cathery/sys-con.git
synced 2024-07-05 10:48:46 +00:00
Implement PSC module
This commit is contained in:
parent
c93aa6304b
commit
b68134504b
|
@ -5,6 +5,7 @@
|
|||
#include "usb_module.h"
|
||||
#include "controller_handler.h"
|
||||
#include "config_handler.h"
|
||||
#include "psc_module.h"
|
||||
|
||||
#define APP_VERSION "0.6.0"
|
||||
|
||||
|
@ -80,12 +81,14 @@ int main(int argc, char *argv[])
|
|||
config::Initialize();
|
||||
handler::Initialize();
|
||||
usb::Initialize();
|
||||
psc::Initialize();
|
||||
|
||||
while (true)
|
||||
{
|
||||
svcSleepThread(1e+8L);
|
||||
}
|
||||
|
||||
psc::Exit();
|
||||
usb::Exit();
|
||||
handler::Exit();
|
||||
config::Exit();
|
||||
|
|
71
source/Sysmodule/source/psc_module.cpp
Normal file
71
source/Sysmodule/source/psc_module.cpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
#include "psc_module.h"
|
||||
#include <stratosphere.hpp>
|
||||
#include "usb_module.h"
|
||||
#include "config_handler.h"
|
||||
#include "controller_handler.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace syscon::psc
|
||||
{
|
||||
namespace
|
||||
{
|
||||
PscPmModule pscModule;
|
||||
Waiter pscModuleWaiter;
|
||||
const uint16_t dependencies[] = {PscPmModuleId_Usb};
|
||||
|
||||
void PscThreadFunc(void *arg);
|
||||
|
||||
ams::os::StaticThread<0x2'000> g_psc_thread(&PscThreadFunc, nullptr, 0x2C);
|
||||
|
||||
bool is_psc_thread_running = false;
|
||||
|
||||
void PscThreadFunc(void *arg)
|
||||
{
|
||||
WriteToLog("Starting PSC thread!");
|
||||
do {
|
||||
if (R_SUCCEEDED(waitSingle(pscModuleWaiter, U64_MAX)))
|
||||
{
|
||||
PscPmState pscState;
|
||||
u32 out_flags;
|
||||
if (R_SUCCEEDED(pscPmModuleGetRequest(&pscModule, &pscState, &out_flags)))
|
||||
{
|
||||
switch (pscState)
|
||||
{
|
||||
case PscPmState_ReadyAwaken:
|
||||
WriteToLog("Switch is awake! Enabling usb events...");
|
||||
usb::CreateUsbEvents();
|
||||
break;
|
||||
case PscPmState_ReadySleep:
|
||||
case PscPmState_ReadyShutdown:
|
||||
WriteToLog("Ready to sleep! Disabling usb events...");
|
||||
usb::DestroyUsbEvents();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
pscPmModuleAcknowledge(&pscModule, pscState);
|
||||
}
|
||||
}
|
||||
} while (is_psc_thread_running);
|
||||
}
|
||||
}
|
||||
Result Initialize()
|
||||
{
|
||||
R_TRY(pscmGetPmModule(&pscModule, static_cast<PscPmModuleId>(126), dependencies, sizeof(dependencies) / sizeof(uint16_t), true));
|
||||
pscModuleWaiter = waiterForEvent(&pscModule.event);
|
||||
is_psc_thread_running = true;
|
||||
return g_psc_thread.Start().GetValue();
|
||||
}
|
||||
|
||||
void Exit()
|
||||
{
|
||||
is_psc_thread_running = false;
|
||||
|
||||
pscPmModuleFinalize(&pscModule);
|
||||
pscPmModuleClose(&pscModule);
|
||||
eventClose(&pscModule.event);
|
||||
|
||||
g_psc_thread.CancelSynchronization();
|
||||
g_psc_thread.Join();
|
||||
}
|
||||
};
|
8
source/Sysmodule/source/psc_module.h
Normal file
8
source/Sysmodule/source/psc_module.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
#include "switch.h"
|
||||
|
||||
namespace syscon::psc
|
||||
{
|
||||
Result Initialize();
|
||||
void Exit();
|
||||
};
|
|
@ -180,24 +180,18 @@ namespace syscon::usb
|
|||
|
||||
Result Enable()
|
||||
{
|
||||
R_TRY(CreateCatchAllAvailableEvent());
|
||||
R_TRY(CreateDualshock3AvailableEvent());
|
||||
R_TRY(CreateDualshock4AvailableEvent());
|
||||
CreateUsbEvents();
|
||||
|
||||
is_usb_event_thread_running = true;
|
||||
R_TRY(g_usb_event_thread.Start().GetValue());
|
||||
|
||||
is_usb_interface_change_thread_running = true;
|
||||
R_TRY(g_usb_interface_change_thread.Start().GetValue());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Disable()
|
||||
{
|
||||
usbHsDestroyInterfaceAvailableEvent(&g_usbCatchAllEvent, CatchAllEventIndex);
|
||||
usbHsDestroyInterfaceAvailableEvent(&g_usbDualshock3Event, Dualshock3EventIndex);
|
||||
usbHsDestroyInterfaceAvailableEvent(&g_usbDualshock4Event, Dualshock4EventIndex);
|
||||
DestroyUsbEvents();
|
||||
|
||||
is_usb_event_thread_running = false;
|
||||
is_usb_interface_change_thread_running = false;
|
||||
|
@ -212,6 +206,21 @@ namespace syscon::usb
|
|||
handler::Reset();
|
||||
}
|
||||
|
||||
Result CreateUsbEvents()
|
||||
{
|
||||
R_TRY(CreateCatchAllAvailableEvent());
|
||||
R_TRY(CreateDualshock3AvailableEvent());
|
||||
R_TRY(CreateDualshock4AvailableEvent());
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DestroyUsbEvents()
|
||||
{
|
||||
usbHsDestroyInterfaceAvailableEvent(&g_usbCatchAllEvent, CatchAllEventIndex);
|
||||
usbHsDestroyInterfaceAvailableEvent(&g_usbDualshock3Event, Dualshock3EventIndex);
|
||||
usbHsDestroyInterfaceAvailableEvent(&g_usbDualshock4Event, Dualshock4EventIndex);
|
||||
}
|
||||
|
||||
Result ReloadDualshock4Event()
|
||||
{
|
||||
usbHsDestroyInterfaceAvailableEvent(&g_usbDualshock4Event, Dualshock4EventIndex);
|
||||
|
|
|
@ -9,5 +9,8 @@ namespace syscon::usb {
|
|||
Result Enable();
|
||||
void Disable();
|
||||
|
||||
Result CreateUsbEvents();
|
||||
void DestroyUsbEvents();
|
||||
|
||||
Result ReloadDualshock4Event();
|
||||
}
|
Loading…
Reference in New Issue
Block a user