diff --git a/README.md b/README.md index a209486e..36153367 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 SDVX in mind. Capable of handling 7 LEDs, 1 WS2812B RGB strip, and 2 encoders. 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 c97b943c..1bdb7119 100644 Binary files a/build_uf2/Pico_Game_Controller.uf2 and b/build_uf2/Pico_Game_Controller.uf2 differ diff --git a/build_uf2/README.md b/build_uf2/README.md index 8544e75f..94532614 100644 --- a/build_uf2/README.md +++ b/build_uf2/README.md @@ -4,7 +4,9 @@ Manually copied built uf2 file for quick flashing. Quick how-to flash: -1. Hold down Pi Pico button when plugging it in. +If you haven't already, download Pico_Game_Controller.uf2 first by clicking it above and then clicking the Download button near the top right. + +1. Hold down Pi Pico button when plugging it in. (This is the button on the bottom of the controller) 2. Drag Pico_Game_Controller.uf2 into the 'drive' RPI-RP2 3. Done! diff --git a/src/controller_config.h b/src/controller_config.h index 03f5e23e..47dfbc6e 100644 --- a/src/controller_config.h +++ b/src/controller_config.h @@ -1,11 +1,11 @@ #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 SW_GPIO_SIZE 9 // Number of switches +#define LED_GPIO_SIZE 7 // 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_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 @@ -18,14 +18,15 @@ #ifdef PICO_GAME_CONTROLLER_C // MODIFY KEYBINDS HERE, MAKE SURE LENGTHS MATCH SW_GPIO_SIZE -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_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, +}; const uint8_t SW_GPIO[] = { - 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 27, + 4, 6, 8, 10, 12, 14, 27, 18, 20, }; const uint8_t LED_GPIO[] = { - 5, 7, 9, 11, 13, 15, 17, 19, 21, 26, + 5, 7, 9, 11, 13, 15, 21, }; const uint8_t ENC_GPIO[] = {0, 2}; // L_ENC(0, 1); R_ENC(2, 3) const bool ENC_REV[] = {false, false}; // Reverse Encoders diff --git a/src/pico_game_controller.c b/src/pico_game_controller.c index 84d9b323..11d7e16c 100644 --- a/src/pico_game_controller.c +++ b/src/pico_game_controller.c @@ -111,7 +111,7 @@ void ws2812b_update(uint32_t counter) { * HID/Reactive Lights **/ void update_lights() { - for (int i = 0; i < LED_GPIO_SIZE; i++) { + for (int i = 0; i < LED_GPIO_SIZE - 1; i++) { if (time_us_64() - reactive_timeout_timestamp >= REACTIVE_TIMEOUT_MAX) { if (!gpio_get(SW_GPIO[i])) { gpio_put(LED_GPIO[i], 1); @@ -125,6 +125,20 @@ void update_lights() { gpio_put(LED_GPIO[i], 1); } } + /* start button sw_val index is offset by two with respect to LED_GPIO */ + if (time_us_64() - reactive_timeout_timestamp >= REACTIVE_TIMEOUT_MAX) { + if (!gpio_get(SW_GPIO[LED_GPIO_SIZE + 1])) { + gpio_put(LED_GPIO[LED_GPIO_SIZE - 1], 1); + } else { + gpio_put(LED_GPIO[LED_GPIO_SIZE - 1], 0); + } + } else { + if (lights_report.lights.buttons[LED_GPIO_SIZE - 1] == 0) { + gpio_put(LED_GPIO[LED_GPIO_SIZE - 1], 0); + } else { + gpio_put(LED_GPIO[LED_GPIO_SIZE - 1], 1); + } + } } } diff --git a/src/usb_descriptors.c b/src/usb_descriptors.c index 3ce32767..0c0aaaa7 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 = 0x101c, .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 = 0x101c, .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,25 +152,22 @@ 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 + "Konami Amusement", // 1: Manufacturer + "SOUND VOLTEX 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", - "Red 1", - "Green 1", - "Blue 1", - "Red 2", - "Green 2", - "Blue 2", + "BT-A", + "BT-B", + "BT-C", + "BT-D", + "FX-L", + "FX-R", + "Start", + "Left R", + "Left G", + "Left B", + "Right R", + "Right G", + "Right B", }; static uint16_t _desc_str[64]; diff --git a/src/usb_descriptors.h b/src/usb_descriptors.h index 9d30995c..d9b601c7 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,10 +27,10 @@ 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), \ @@ -45,7 +45,7 @@ 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(16), HID_USAGE_MIN(1), HID_USAGE_MAX(13), \ 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), \