diff --git a/README.md b/README.md index 85e5fbf..c1bd045 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Pico-Game-Controller -Code for a keyboard or game controller using a Raspberry Pi Pico. Capable of handling 11 buttons, 10 LEDs, 1 WS2812B RGB strip, and 2 encoders. Developed with SDVX and IIDX in mind - see branches release/pocket-sdvx-pico and release/pocket-iidx for preconfigured versions. +This branch was developed with IIDX in mind. Capable of handling 11 buttons, 11 LEDs, 1 WS2812B RGB strip, and 1 encoder. Note: 12 buttons/LEDs are reported but B8 should probably not be used (https://github.com/veroxzik/arduino-konami-spoof) Demo of this firmware running on Pocket SDVX Pico, purchasable at https://discord.gg/MmuKd73XbY diff --git a/build_uf2/Pico_Game_Controller.uf2 b/build_uf2/Pico_Game_Controller.uf2 index 10a29a2..9bd3c7e 100644 Binary files a/build_uf2/Pico_Game_Controller.uf2 and b/build_uf2/Pico_Game_Controller.uf2 differ diff --git a/src/controller_config.h b/src/controller_config.h index abca538..656543d 100644 --- a/src/controller_config.h +++ b/src/controller_config.h @@ -1,12 +1,12 @@ #ifndef CONTROLLER_CONFIG_H #define CONTROLLER_CONFIG_H -#define SW_GPIO_SIZE 11 // Number of switches -#define LED_GPIO_SIZE 10 // Number of switch LEDs -#define ENC_GPIO_SIZE 2 // Number of encoders -#define ENC_PPR 600 // Encoder PPR -#define MOUSE_SENS 1 // Mouse sensitivity multiplier -#define ENC_DEBOUNCE false // Encoder Debouncing +#define SW_GPIO_SIZE 12 // Number of switches +#define LED_GPIO_SIZE 12 // Number of switch LEDs +#define ENC_GPIO_SIZE 1 // Number of encoders +#define ENC_PPR 24 // Encoder PPR +#define MOUSE_SENS 5 // Mouse sensitivity multiplier +#define ENC_DEBOUNCE true // Encoder Debouncing #define SW_DEBOUNCE_TIME_US 4000 // Switch debounce delay in us #define ENC_PULSE (ENC_PPR * 4) // 4 pulses per PPR #define REACTIVE_TIMEOUT_MAX 1000000 // HID to reactive timeout in us @@ -22,13 +22,13 @@ const uint8_t SW_KEYCODE[] = {HID_KEY_D, HID_KEY_F, HID_KEY_J, HID_KEY_K, HID_KEY_C, HID_KEY_M, HID_KEY_A, HID_KEY_B, HID_KEY_1, HID_KEY_E, HID_KEY_G}; const uint8_t SW_GPIO[] = { - 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 27, + 2, 4, 6, 8, 10, 12, 14, 26, 16, 18, 20, 22, }; const uint8_t LED_GPIO[] = { - 5, 7, 9, 11, 13, 15, 17, 19, 21, 26, + 3, 5, 7, 9, 11, 13, 15, 27, 17, 19, 21, 26, }; -const uint8_t ENC_GPIO[] = {0, 2}; // L_ENC(0, 1); R_ENC(2, 3) -const bool ENC_REV[] = {false, false}; // Reverse Encoders +const uint8_t ENC_GPIO[] = {0}; // TT(0, 1) +const bool ENC_REV[] = {false}; // Reverse Encoders const uint8_t WS2812B_GPIO = 28; #endif diff --git a/src/pico_game_controller.c b/src/pico_game_controller.c index f14fcec..11ecebf 100644 --- a/src/pico_game_controller.c +++ b/src/pico_game_controller.c @@ -91,7 +91,6 @@ void update_lights() { struct report { uint16_t buttons; uint8_t joy0; - uint8_t joy1; } report; /** @@ -110,7 +109,6 @@ void joy_mode() { } report.joy0 = ((double)cur_enc_val[0] / ENC_PULSE) * (UINT8_MAX + 1); - report.joy1 = ((double)cur_enc_val[1] / ENC_PULSE) * (UINT8_MAX + 1); tud_hid_n_report(0x00, REPORT_ID_JOYSTICK, &report, sizeof(report)); } @@ -146,9 +144,8 @@ void key_mode() { delta[i] = (enc_val[i] - prev_enc_val[i]) * (ENC_REV[i] ? 1 : -1); prev_enc_val[i] = enc_val[i]; } - - tud_hid_mouse_report(REPORT_ID_MOUSE, 0x00, delta[0] * MOUSE_SENS, - delta[1] * MOUSE_SENS, 0, 0); + tud_hid_mouse_report(REPORT_ID_MOUSE, 0x00, delta[0] * MOUSE_SENS, 0, 0, + 0); } // Alternate reports kbm_report = !kbm_report; diff --git a/src/usb_descriptors.c b/src/usb_descriptors.c index 3ce3276..f4d1afc 100644 --- a/src/usb_descriptors.c +++ b/src/usb_descriptors.c @@ -34,10 +34,6 @@ * Auto ProductID layout's Bitmap: * [MSB] HID | MSC | CDC [LSB] */ -#define _PID_MAP(itf, n) ((CFG_TUD_##itf) << (n)) -#define USB_PID \ - (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \ - _PID_MAP(MIDI, 3) | _PID_MAP(VENDOR, 4)) //--------------------------------------------------------------------+ // Device Descriptors @@ -51,8 +47,8 @@ tusb_desc_device_t const desc_device_joy = { .bDeviceProtocol = 0x00, .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE, - .idVendor = 0xCafe, - .idProduct = USB_PID, + .idVendor = 0x1ccf, + .idProduct = 0x8048, .bcdDevice = 0x0100, .iManufacturer = 0x01, @@ -70,8 +66,8 @@ tusb_desc_device_t const desc_device_key = { .bDeviceProtocol = 0x00, .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE, - .idVendor = 0xCafe, - .idProduct = USB_PID, + .idVendor = 0x1ccf, + .idProduct = 0x8048, .bcdDevice = 0x0100, .iManufacturer = 0x01, @@ -92,14 +88,12 @@ uint8_t const* tud_descriptor_device_cb(void) { uint8_t const desc_hid_report_joy[] = { GAMECON_REPORT_DESC_JOYSTICK(HID_REPORT_ID(REPORT_ID_JOYSTICK)), - GAMECON_REPORT_DESC_LIGHTS(HID_REPORT_ID(REPORT_ID_LIGHTS)) -}; + GAMECON_REPORT_DESC_LIGHTS(HID_REPORT_ID(REPORT_ID_LIGHTS))}; uint8_t const desc_hid_report_key[] = { GAMECON_REPORT_DESC_LIGHTS(HID_REPORT_ID(REPORT_ID_LIGHTS)), GAMECON_REPORT_DESC_NKRO(HID_REPORT_ID(REPORT_ID_KEYBOARD)), - TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(REPORT_ID_MOUSE)) -}; + TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(REPORT_ID_MOUSE))}; // Invoked when received GET HID REPORT DESCRIPTOR // Application return pointer to descriptor @@ -131,7 +125,6 @@ uint8_t const desc_configuration_joy[] = { sizeof(desc_hid_report_joy), EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 1)}; - uint8_t const desc_configuration_key[] = { // Config number, interface count, string index, total length, attribute, // power in mA @@ -159,19 +152,21 @@ uint8_t const* tud_descriptor_configuration_cb(uint8_t index) { // array of pointer to string descriptors char const* string_desc_arr[] = { (const char[]){0x09, 0x04}, // 0: is supported language is English (0x0409) - "SpeedyPotato", // 1: Manufacturer - "Pico Game Controller", // 2: Product - "123456", // 3: Serials, should use chip ID - "Button 1", - "Button 2", - "Button 3", - "Button 4", - "Button 5", - "Button 6", - "Button 7", - "Button 8", - "Button 9", - "Button 10", + "Konami Amusement", // 1: Manufacturer + "beatmania IIDX controller premium model", // 2: Product + "123456", // 3: Serials, should use chip ID + "Key 1", + "Key 2", + "Key 3", + "Key 4", + "Key 5", + "Key 6", + "Key 7", + "UNUSED GPIO 27", + "Key E1", + "Key E2", + "Key E3", + "Key E4", "Red 1", "Green 1", "Blue 1", diff --git a/src/usb_descriptors.h b/src/usb_descriptors.h index 9d30995..fc3761a 100644 --- a/src/usb_descriptors.h +++ b/src/usb_descriptors.h @@ -2,8 +2,8 @@ #define USB_DESCRIPTORS_H_ #include "common/tusb_common.h" -#include "device/usbd.h" #include "controller_config.h" +#include "device/usbd.h" enum { REPORT_ID_JOYSTICK = 1, @@ -27,15 +27,15 @@ enum { HID_USAGE(HID_USAGE_DESKTOP_JOYSTICK), \ HID_COLLECTION(HID_COLLECTION_APPLICATION), \ __VA_ARGS__ HID_USAGE_PAGE(HID_USAGE_PAGE_BUTTON), HID_USAGE_MIN(1), \ - HID_USAGE_MAX(SW_GPIO_SIZE), \ - HID_LOGICAL_MIN(0), HID_LOGICAL_MAX(1), HID_REPORT_COUNT(SW_GPIO_SIZE), \ - HID_REPORT_SIZE(1), HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ - HID_REPORT_COUNT(1), HID_REPORT_SIZE(16 - SW_GPIO_SIZE), /*Padding*/\ + HID_USAGE_MAX(SW_GPIO_SIZE), HID_LOGICAL_MIN(0), HID_LOGICAL_MAX(1), \ + HID_REPORT_COUNT(SW_GPIO_SIZE), HID_REPORT_SIZE(1), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), HID_REPORT_COUNT(1), \ + HID_REPORT_SIZE(16 - SW_GPIO_SIZE), /*Padding*/ \ HID_INPUT(HID_CONSTANT | HID_VARIABLE | HID_ABSOLUTE), \ HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), HID_LOGICAL_MIN(0x00), \ HID_LOGICAL_MAX_N(0x00ff, 2), \ HID_USAGE(HID_USAGE_DESKTOP_X), /*Joystick*/ \ - HID_USAGE(HID_USAGE_DESKTOP_Y), HID_REPORT_COUNT(2), HID_REPORT_SIZE(8), \ + HID_REPORT_COUNT(2), HID_REPORT_SIZE(8), \ HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), HID_COLLECTION_END // Light Map @@ -45,9 +45,8 @@ enum { __VA_ARGS__ HID_REPORT_COUNT(LED_GPIO_SIZE + (WS2812B_LED_ZONES * 3)), \ HID_REPORT_SIZE(8), HID_LOGICAL_MIN(0x00), HID_LOGICAL_MAX_N(0x00ff, 2), \ HID_USAGE_PAGE(HID_USAGE_PAGE_ORDINAL), HID_STRING_MINIMUM(4), \ - HID_STRING_MAXIMUM(16), HID_USAGE_MIN(1), HID_USAGE_MAX(16), \ + HID_STRING_MAXIMUM(18), HID_USAGE_MIN(1), HID_USAGE_MAX(18), \ HID_OUTPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), HID_REPORT_COUNT(1), \ - HID_REPORT_SIZE(8), /*Padding*/ \ HID_INPUT(HID_CONSTANT | HID_VARIABLE | HID_ABSOLUTE), \ HID_COLLECTION_END