IR: Move to scheduler

This commit is contained in:
wheremyfoodat 2025-07-03 02:42:43 +03:00
parent b2904f391f
commit dc7f8a48bd
7 changed files with 29 additions and 14 deletions

View file

@ -12,7 +12,8 @@ struct Scheduler {
UpdateTimers = 1, // Update kernel timer objects
RunDSP = 2, // Make the emulated DSP run for one audio frame
SignalY2R = 3, // Signal that a Y2R conversion has finished
Panic = 4, // Dummy event that is always pending and should never be triggered (Timestamp = UINT64_MAX)
UpdateIR = 4, // Update an IR device (For now, just the CirclePad Pro/N3DS controls)
Panic = 5, // Dummy event that is always pending and should never be triggered (Timestamp = UINT64_MAX)
TotalNumberOfEvents // How many event types do we have in total?
};
static constexpr usize totalNumberOfEvents = static_cast<usize>(EventType::TotalNumberOfEvents);

View file

@ -44,7 +44,10 @@ namespace IR {
virtual void disconnect() override;
virtual void receivePayload(Payload payload) override;
CirclePadPro(SendCallback sendCallback) : IR::Device(sendCallback) {}
CirclePadPro(SendCallback sendCallback, Scheduler& scheduler) : IR::Device(sendCallback, scheduler) {}
ButtonState state;
// The current polling period in cycles, configured via the ConfigurePolling command
s64 period = Scheduler::nsToCycles(16000);
};
} // namespace IR

View file

@ -3,6 +3,7 @@
#include <span>
#include "helpers.hpp"
#include "scheduler.hpp"
namespace IR {
class Device {
@ -11,6 +12,7 @@ namespace IR {
protected:
using SendCallback = std::function<void(Payload)>; // Callback for sending data from IR device->3DS
Scheduler& scheduler;
SendCallback sendCallback;
public:
@ -18,6 +20,6 @@ namespace IR {
virtual void disconnect() = 0;
virtual void receivePayload(Payload payload) = 0;
Device(SendCallback sendCallback) : sendCallback(sendCallback) {}
Device(SendCallback sendCallback, Scheduler& scheduler) : sendCallback(sendCallback), scheduler(scheduler) {}
};
} // namespace IR

View file

@ -16,6 +16,7 @@
class Kernel;
class IRUserService {
using Payload = IR::Device::Payload;
using Handle = HorizonHandle;
enum class DeviceID : u8 {
@ -75,14 +76,11 @@ class IRUserService {
// The IR service uses CRC8 with generator polynomial = 0x07 for verifying packets received from IR devices
static u8 crc8(std::span<const u8> data);
// IR service calls this to send a console->device payload
void receivePayload(std::span<const u8> data);
// IR devices call this to send a device->console payload
void sendPayload(std::span<const u8> payload);
void sendPayload(Payload payload);
public:
IRUserService(Memory& mem, HIDService& hid, const EmulatorConfig& config, Kernel& kernel)
: mem(mem), hid(hid), config(config), kernel(kernel), cpp([&](IR::Device::Payload payload) { sendPayload(payload); }) {}
IRUserService(Memory& mem, HIDService& hid, const EmulatorConfig& config, Kernel& kernel);
void setCStickX(s16 value) { cpp.state.cStick.x = value; }
void setCStickY(s16 value) { cpp.state.cStick.y = value; }