More CirclePad Pro improvements

This commit is contained in:
wheremyfoodat 2025-07-03 00:52:55 +03:00
parent 935e088ca1
commit 0ab8a6d956
14 changed files with 155 additions and 81 deletions

View file

@ -27,6 +27,12 @@ namespace HID::Keys {
GPIO0Inv = 1 << 12, // Inverted value of GPIO bit 0
GPIO14Inv = 1 << 13, // Inverted value of GPIO bit 14
// CirclePad Pro buttons. We store them in the HID service for ease, even though they're only used by the IR service
// Whenever the HID service writes to shared memory, we remember to mask them out
ZL = 1 << 14,
ZR = 1 << 15,
CirclePadProButtons = ZL | ZR,
CirclePadRight = 1 << 28, // X >= 41
CirclePadLeft = 1 << 29, // X <= -41
CirclePadUp = 1 << 30, // Y >= 41
@ -58,6 +64,9 @@ class HIDService {
s16 roll, pitch, yaw; // Gyroscope state
s16 accelX, accelY, accelZ; // Accelerometer state
// New 3DS/CirclePad Pro C-stick state
s16 cStickX, cStickY;
bool accelerometerEnabled;
bool eventsInitialized;
bool gyroEnabled;
@ -113,7 +122,7 @@ class HIDService {
// 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;
newButtons &= ~(HID::Keys::CirclePadLeft | HID::Keys::CirclePadRight);
if (x >= 41) // Pressing right
newButtons |= 1 << 28;
else if (x <= -41) // Pressing left
@ -125,13 +134,19 @@ class HIDService {
// 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;
newButtons &= ~(HID::Keys::CirclePadUp | HID::Keys::CirclePadDown);
if (y >= 41) // Pressing up
newButtons |= 1 << 30;
else if (y <= -41) // Pressing down
newButtons |= 1 << 31;
}
void setCStickX(s16 x) { cStickX = x; }
void setCStickY(s16 y) { cStickY = y; }
s16 getCStickX() { return cStickX; }
s16 getCStickY() { return cStickY; }
void setRoll(s16 value) { roll = value; }
void setPitch(s16 value) { pitch = value; }
void setYaw(s16 value) { yaw = value; }
@ -157,9 +172,6 @@ class HIDService {
touchScreenPressed = true;
}
void releaseTouchScreen() {
touchScreenPressed = false;
}
void releaseTouchScreen() { touchScreenPressed = false; }
bool isTouchScreenPressed() { return touchScreenPressed; }
};

View file

@ -8,7 +8,6 @@ namespace IR {
public:
struct ButtonState {
static constexpr int C_STICK_CENTER = 0x800;
static constexpr int C_STICK_RADIUS = 0x7FF;
union {
BitField<0, 8, u32> header;

View file

@ -8,6 +8,7 @@
#include "logger.hpp"
#include "memory.hpp"
#include "result/result.hpp"
#include "services/hid.hpp"
#include "services/ir/circlepad_pro.hpp"
// Circular dependencies in this project? Never
@ -23,6 +24,8 @@ class IRUserService {
Handle handle = KernelHandles::IR_USER;
Memory& mem;
Kernel& kernel;
// The IR service has a reference to the HID service as that's where the frontends store CirclePad Pro button state in
HIDService& hid;
const EmulatorConfig& config;
MAKE_LOG_FUNCTION(log, irUserLogger)
@ -76,11 +79,9 @@ class IRUserService {
void sendPayload(std::span<const u8> payload);
public:
IRUserService(Memory& mem, const EmulatorConfig& config, Kernel& kernel)
: mem(mem), config(config), kernel(kernel), cpp([&](IR::Device::Payload payload) { sendPayload(payload); }) {}
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); }) {}
void setZRPressed(bool pressed) { cpp.state.buttons.zrNotPressed = pressed ? 0 : 1; }
void setZLPressed(bool pressed) { cpp.state.buttons.zrNotPressed = pressed ? 0 : 1; }
void setCStickX(s16 value) { cpp.state.cStick.x = value; }
void setCStickY(s16 value) { cpp.state.cStick.y = value; }