diff --git a/NeoGeoControllerUSB/Gamepad.cpp b/NeoGeoControllerUSB/Gamepad.cpp index 490af9f..520b7d9 100644 --- a/NeoGeoControllerUSB/Gamepad.cpp +++ b/NeoGeoControllerUSB/Gamepad.cpp @@ -33,16 +33,12 @@ static const uint8_t _hidReportDescriptor[] PROGMEM = { 0x05, 0x09, // USAGE_PAGE (Button) 0x19, 0x01, // USAGE_MINIMUM (Button 1) - 0x29, 0x0c, // USAGE_MAXIMUM (Button 12) + 0x29, 0x08, // USAGE_MAXIMUM (Button 8) 0x15, 0x00, // LOGICAL_MINIMUM (0) 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x95, 0x0c, // REPORT_COUNT (12) + 0x95, 0x08, // REPORT_COUNT (8) 0x75, 0x01, // REPORT_SIZE (1) 0x81, 0x02, // INPUT (Data,Var,Abs) - - 0x95, 0x01, // REPORT_COUNT (1) ; pad out the bits into a number divisible by 8 - 0x75, 0x04, // REPORT_SIZE (4) - 0x81, 0x03, // INPUT (Const,Var,Abs) 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 0x09, 0x01, // USAGE (pointer) diff --git a/NeoGeoControllerUSB/Gamepad.h b/NeoGeoControllerUSB/Gamepad.h index 968bc4e..6a1ab76 100644 --- a/NeoGeoControllerUSB/Gamepad.h +++ b/NeoGeoControllerUSB/Gamepad.h @@ -31,7 +31,7 @@ extern const char* gp_serial; typedef struct { - uint16_t buttons : 12; + uint8_t buttons; int8_t X; int8_t Y; } GamepadReport; diff --git a/NeoGeoControllerUSB/NeoGeoControllerUSB.ino b/NeoGeoControllerUSB/NeoGeoControllerUSB.ino index 2cd3923..8e3ee5d 100644 --- a/NeoGeoControllerUSB/NeoGeoControllerUSB.ino +++ b/NeoGeoControllerUSB/NeoGeoControllerUSB.ino @@ -41,10 +41,10 @@ uint8_t axesPrev = 0x0f; uint8_t axesBits[4] = {0x10,0x20,0x40,0x80}; uint32_t axesMillis[4]; -uint16_t buttonsDirect = 0; -uint16_t buttons = 0; -uint16_t buttonsPrev = 0; -uint16_t buttonsBits[12] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x100,0x200,0x400,0x800}; +uint8_t buttonsDirect = 0; +uint8_t buttons = 0; +uint8_t buttonsPrev = 0; +uint8_t buttonsBits[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; uint32_t buttonsMillis[12]; #ifdef DEBUG @@ -63,6 +63,8 @@ void setup() PORTD |= B10011111; // Enable internal pull-up resistors DDRB &= ~B01111110; // Set PB1-PB6 as inputs PORTB |= B01111110; // Enable internal pull-up resistors + DDRC &= ~B01000000; // Set PC6 as input + PORTC |= B01000000; // Enable internal pull-up resistors // Debounce selector switch (currently disabled) DDRE &= ~B01000000; // Pin 7 as input @@ -88,7 +90,7 @@ void loop() { // Read axis and button inputs (bitwise NOT results in a 1 when button/axis pressed) axesDirect = ~(PINF & B11110000); - buttonsDirect = ~((PIND & B00011111) | ((PIND & B10000000) << 4) | ((PINB & B01111110) << 4)); + buttonsDirect = ~((PIND & B10011111) | (PINC & B01000000) | ((PINB & B00000010) << 4)); if(debounce) { @@ -106,7 +108,7 @@ void loop() } // Debounce buttons - for(pin=0; pin<12; pin++) + for(pin=0; pin<8; pin++) { // Check if the current pin state is different to the stored state and that enough time has passed since last change if((buttonsDirect & buttonsBits[pin]) != (buttons & buttonsBits[pin]) && (millisNow - buttonsMillis[pin]) > DEBOUNCE_TIME)