Merge pull request from wheremyfoodat/HID

HID service make-over
This commit is contained in:
wheremyfoodat 2023-06-06 18:42:53 +03:00 committed by GitHub
commit c7e3343974
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 205 additions and 16 deletions

View file

@ -199,7 +199,8 @@ public:
return &objects[handle];
}
void sendGPUInterrupt(GPUInterrupt type) { serviceManager.requestGPUInterrupt(type); }
ServiceManager& getServiceManager() { return serviceManager; }
void sendGPUInterrupt(GPUInterrupt type) { serviceManager.sendGPUInterrupt(type); }
void signalDSPEvents() { serviceManager.signalDSPEvents(); }
void updateInputs() { serviceManager.updateInputs(); }
};

View file

@ -6,6 +6,31 @@
#include "logger.hpp"
#include "memory.hpp"
namespace HID::Keys {
enum : u32 {
A = 1 << 0,
B = 1 << 1,
Select = 1 << 2,
Start = 1 << 3,
Right = 1 << 4,
Left = 1 << 5,
Up = 1 << 6,
Down = 1 << 7,
R = 1 << 8,
L = 1 << 9,
X = 1 << 10,
Y = 1 << 11,
GPIO0Inv = 1 << 12, // Inverted value of GPIO bit 0
GPIO14Inv = 1 << 13, // Inverted value of GPIO bit 14
CirclePadRight = 1 << 28, // X >= 41
CirclePadLeft = 1 << 29, // X <= -41
CirclePadUp = 1 << 30, // Y >= 41
CirclePadDown = 1u << 31 // Y <= -41
};
}
// Circular dependency because we need HID to spawn events
class Kernel;
@ -15,6 +40,16 @@ class HIDService {
Kernel& kernel;
u8* sharedMem = nullptr; // Pointer to HID shared memory
uint nextPadIndex;
uint nextTouchscreenIndex;
uint nextAccelerometerIndex;
uint nextGyroIndex;
u32 newButtons; // The button state currently being edited
u32 oldButtons; // The previous pad state
s16 circlePadX, circlePadY; // Circlepad state
bool accelerometerEnabled;
bool eventsInitialized;
bool gyroEnabled;
@ -30,11 +65,50 @@ class HIDService {
void getGyroscopeCoefficient(u32 messagePointer);
void getIPCHandles(u32 messagePointer);
// Don't call these prior to initializing shared mem pls
template <typename T>
T readSharedMem(size_t offset) {
return *(T*)&sharedMem[offset];
}
template <typename T>
void writeSharedMem(size_t offset, T value) {
*(T*)&sharedMem[offset] = value;
}
public:
HIDService(Memory& mem, Kernel& kernel) : mem(mem), kernel(kernel) {}
void reset();
void handleSyncRequest(u32 messagePointer);
void updateInputs();
void pressKey(u32 mask) { newButtons |= mask; }
void releaseKey(u32 mask) { newButtons &= ~mask; }
void setCirclepadX(s16 x) {
circlePadX = x;
// Turn bits 28 and 29 off in the new button state, which indicate whether the circlepad is steering left or right
// Then, set them according to the new value of x
newButtons &= ~0x3000'0000;
if (x >= 41) // Pressing right
newButtons |= 1 << 28;
else if (x <= -41) // Pressing left
newButtons |= 1 << 29;
}
void setCirclepadY(s16 y) {
circlePadY = y;
// Turn bits 30 and 31 off in the new button state, which indicate whether the circlepad is steering up or down
// Then, set them according to the new value of y
newButtons &= ~0xC000'0000;
if (y >= 41) // Pressing up
newButtons |= 1 << 30;
else if (y <= -41) // Pressing down
newButtons |= 1 << 31;
}
void updateInputs(u64 currentTimestamp);
void setSharedMem(u8* ptr) {
sharedMem = ptr;

View file

@ -79,10 +79,15 @@ public:
void sendCommandToService(u32 messagePointer, Handle handle);
// Wrappers for communicating with certain services
void requestGPUInterrupt(GPUInterrupt type) { gsp_gpu.requestInterrupt(type); }
void sendGPUInterrupt(GPUInterrupt type) { gsp_gpu.requestInterrupt(type); }
void setGSPSharedMem(u8* ptr) { gsp_gpu.setSharedMem(ptr); }
void setHIDSharedMem(u8* ptr) { hid.setSharedMem(ptr); }
void signalDSPEvents() { dsp.signalEvents(); }
void updateInputs() { hid.updateInputs(); }
void pressKey(u32 key) { hid.pressKey(key); }
void releaseKey(u32 key) { hid.releaseKey(key); }
void setCirclepadX(u16 x) { hid.setCirclepadX(x); }
void setCirclepadY(u16 y) { hid.setCirclepadY(y); }
void updateInputs(u64 currentTimestamp) { hid.updateInputs(currentTimestamp); }
};