Skip to content

Commit

Permalink
Add support for X1 and X2 buttons.
Browse files Browse the repository at this point in the history
Co-authored-by: thirdr <ryan@pimoroni.com>
  • Loading branch information
Gadgetoid and thirdr committed May 23, 2024
1 parent 93d8400 commit 92e9bee
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
10 changes: 5 additions & 5 deletions custom_gamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
HID_REPORT_COUNT ( 2 ) ,\
HID_REPORT_SIZE ( 8 ) ,\
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
/* 13 bit Button Map */ \
/* 15 bit Button Map */ \
HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ) ,\
HID_USAGE_MIN ( 1 ) ,\
HID_USAGE_MAX ( 13 ) ,\
HID_USAGE_MAX ( 15 ) ,\
HID_LOGICAL_MIN ( 0 ) ,\
HID_LOGICAL_MAX ( 1 ) ,\
HID_REPORT_COUNT ( 13 ) ,\
HID_REPORT_COUNT ( 15 ) ,\
HID_REPORT_SIZE ( 1 ) ,\
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
/* 3 bit reserved */ \
HID_REPORT_COUNT ( 3 ) ,\
/* 1 bit reserved */ \
HID_REPORT_COUNT ( 1 ) ,\
HID_REPORT_SIZE ( 1 ) ,\
HID_INPUT ( HID_CONSTANT ) ,\
HID_COLLECTION_END \
Expand Down
14 changes: 10 additions & 4 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,21 @@ void hid_task(void)
if ( tud_hid_n_ready(ITF_GAMEPAD_1) )
{
//tud_hid_n_gamepad_report(ITF_GAMEPAD_1, 0, in.p1_x, in.p1_y, 0, 0, 0, 0, 0, in.p1 & BUTTON_MASK);
uint16_t hotkey = (in.util & UTIL_P1_HOTKEY) ? (1 << 12) : 0;
picade_gamepad_report(ITF_GAMEPAD_1, in.p1_x, in.p1_y, (in.p1 & BUTTON_MASK) | hotkey);
uint16_t extra = 0;
extra |= (in.util & UTIL_P1_HOTKEY) ? (1 << 12) : 0;
extra |= (in.util & UTIL_P1_X1) ? (1 << 13) : 0;
extra |= (in.util & UTIL_P1_X2) ? (1 << 14) : 0;
picade_gamepad_report(ITF_GAMEPAD_1, in.p1_x, in.p1_y, (in.p1 & BUTTON_MASK) | extra);
}

if ( tud_hid_n_ready(ITF_GAMEPAD_2) )
{
//tud_hid_n_gamepad_report(ITF_GAMEPAD_2, 0, in.p2_x, in.p2_y, 0, 0, 0, 0, 0, in.p2 & BUTTON_MASK);
uint16_t hotkey = (in.util & UTIL_P2_HOTKEY) ? (1 << 12) : 0;
picade_gamepad_report(ITF_GAMEPAD_2, in.p2_x, in.p2_y, (in.p2 & BUTTON_MASK) | hotkey);
uint16_t extra = 0;
extra |= (in.util & UTIL_P2_HOTKEY) ? (1 << 12) : 0;
extra |= (in.util & UTIL_P2_X1) ? (1 << 13) : 0;
extra |= (in.util & UTIL_P2_X2) ? (1 << 14) : 0;
picade_gamepad_report(ITF_GAMEPAD_2, in.p2_x, in.p2_y, (in.p2 & BUTTON_MASK) | extra);
}
}

Expand Down
12 changes: 4 additions & 8 deletions picade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ const int16_t BUTTON_MASK = 0b0000111111111111;

const uint8_t UTIL_P1_HOTKEY = 0b000001;
const uint8_t UTIL_P2_HOTKEY = 0b000010;

// Deprecated
const uint8_t UTIL_ENTER = 0b000001;
const uint8_t UTIL_ESCAPE = 0b000010;
const uint8_t UTIL_HOTKEY = 0b000100;
const uint8_t UTIL_A = 0b001000;
const uint8_t UTIL_B = 0b010000;
const uint8_t UTIL_C = 0b100000;
const uint8_t UTIL_P1_X1 = 0b000100;
const uint8_t UTIL_P1_X2 = 0b001000;
const uint8_t UTIL_P2_X1 = 0b010000;
const uint8_t UTIL_P2_X2 = 0b100000;

struct input_t {
uint16_t p1;
Expand Down

0 comments on commit 92e9bee

Please sign in to comment.