diff --git a/Production/firmware/mai_pico.uf2 b/Production/firmware/mai_pico.uf2 index ed2cae5..0063ace 100644 Binary files a/Production/firmware/mai_pico.uf2 and b/Production/firmware/mai_pico.uf2 differ diff --git a/firmware/src/commands.c b/firmware/src/commands.c index 8f05b5c..56bce6c 100644 --- a/firmware/src/commands.c +++ b/firmware/src/commands.c @@ -61,10 +61,10 @@ static void disp_hid() { printf("[HID]\n"); const char *nkro[] = {"off", "key1", "key2"}; - printf(" Joy: %s, NKRO: %s\n", mai_cfg->hid.joy ? "ON" : "OFF", + printf(" IO4: %s, NKRO: %s\n", mai_cfg->hid.io4 ? "on" : "off", mai_cfg->hid.nkro <= 2 ? nkro[mai_cfg->hid.nkro] : "key1"); if (mai_runtime.key_stuck) { - printf(" !!! Button stuck, force JOY only !!!\n"); + printf(" !!! Button stuck, force IO4 only !!!\n"); } } @@ -221,32 +221,35 @@ static void handle_stat(int argc, char *argv[]) static void handle_hid(int argc, char *argv[]) { - const char *usage = "Usage: hid \n"; + const char *usage = "Usage: hid \n"; if (argc != 1) { printf(usage); return; } - const char *choices[] = {"joy", "key1", "key2"}; - int match = cli_match_prefix(choices, 3, argv[0]); + const char *choices[] = {"io4", "key1", "key2", "off"}; + int match = cli_match_prefix(choices, count_of(choices), argv[0]); if (match < 0) { printf(usage); return; } switch (match) { - break; case 1: - mai_cfg->hid.joy = 0; + mai_cfg->hid.io4 = 0; mai_cfg->hid.nkro = 1; break; case 2: - mai_cfg->hid.joy = 0; + mai_cfg->hid.io4 = 0; mai_cfg->hid.nkro = 2; break; + case 3: + mai_cfg->hid.io4 = 0; + mai_cfg->hid.nkro = 0; + break; case 0: default: - mai_cfg->hid.joy = 1; + mai_cfg->hid.io4 = 1; mai_cfg->hid.nkro = 0; break; } diff --git a/firmware/src/config.c b/firmware/src/config.c index 82c38de..c8cb4f3 100644 --- a/firmware/src/config.c +++ b/firmware/src/config.c @@ -26,8 +26,8 @@ static mai_cfg_t default_cfg = { .debounce_release = 2, }, .hid = { - .joy = 0, - .nkro = 1, + .io4 = 1, + .nkro = 0, }, .rgb = { .per_button = 1, diff --git a/firmware/src/config.h b/firmware/src/config.h index 4a0ab21..3e78474 100644 --- a/firmware/src/config.h +++ b/firmware/src/config.h @@ -25,7 +25,7 @@ typedef struct __attribute__((packed)) { int8_t zones[34]; } sense; struct { - uint8_t joy : 4; + uint8_t io4 : 4; uint8_t nkro : 4; } hid; struct { diff --git a/firmware/src/hid.c b/firmware/src/hid.c index 2dbe579..51c53a6 100644 --- a/firmware/src/hid.c +++ b/firmware/src/hid.c @@ -42,7 +42,7 @@ static uint16_t native_to_io4(uint16_t button) static void report_usb_hid() { if (tud_hid_ready()) { - if (mai_cfg->hid.joy || mai_runtime.key_stuck) { + if (mai_cfg->hid.io4 || mai_runtime.key_stuck) { static uint16_t last_buttons = 0; uint16_t buttons = button_read(); hid_joy.buttons[0] = native_to_io4(buttons); diff --git a/firmware/src/main.c b/firmware/src/main.c index 65c329c..fb78620 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -145,6 +145,10 @@ void init() save_init(board_id_32() ^ 0xcafe1111, &core1_io_lock); + if (!mai_cfg->hid.io4) { + usb_descriptors_disable_io4(); + } + touch_init(); button_init(); rgb_init(); diff --git a/firmware/src/usb_descriptors.c b/firmware/src/usb_descriptors.c index db51649..661f32a 100644 --- a/firmware/src/usb_descriptors.c +++ b/firmware/src/usb_descriptors.c @@ -157,13 +157,15 @@ uint8_t const* tud_descriptor_configuration_cb(uint8_t index) { static char serial_number_str[24] = "123456\0"; +static char joy_name_string[128] = "I/O CONTROL BD;15257;01;90;1831;6679A;00;GOUT=14_ADIN=8,E_ROTIN=4_COININ=2_SWIN=2,E_UQ1=41,6;"; + // array of pointer to string descriptors static const char *string_desc_arr[] = { (const char[]){0x09, 0x04}, // 0: is supported language is English (0x0409) "SEGA", // 1: Manufacturer "Mai Pico", // 2: Product serial_number_str, // 3: Serials, use chip ID - "I/O CONTROL BD;15257;01;90;1831;6679A;00;GOUT=14_ADIN=8,E_ROTIN=4_COININ=2_SWIN=2,E_UQ1=41,6;", + joy_name_string, "Mai Pico NKRO", "Mai Pico Command Line Port", "Mai Pico Touch Port", @@ -206,3 +208,8 @@ uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid) return _desc_str; } + +void usb_descriptors_disable_io4() +{ + strcpy(joy_name_string, "Mai Pico Joystick"); +} diff --git a/firmware/src/usb_descriptors.h b/firmware/src/usb_descriptors.h index 756bf2d..848d8b3 100644 --- a/firmware/src/usb_descriptors.h +++ b/firmware/src/usb_descriptors.h @@ -1,151 +1,152 @@ -#ifndef USB_DESCRIPTORS_H_ -#define USB_DESCRIPTORS_H_ - -#include "common/tusb_common.h" -#include "device/usbd.h" - -enum { - REPORT_ID_JOYSTICK = 1, - REPORT_ID_OUTPUT = 16, -}; - -// because they are missing from tusb_hid.h -#define HID_STRING_INDEX(x) HID_REPORT_ITEM(x, 7, RI_TYPE_LOCAL, 1) -#define HID_STRING_INDEX_N(x, n) HID_REPORT_ITEM(x, 7, RI_TYPE_LOCAL, n) -#define HID_STRING_MINIMUM(x) HID_REPORT_ITEM(x, 8, RI_TYPE_LOCAL, 1) -#define HID_STRING_MINIMUM_N(x, n) HID_REPORT_ITEM(x, 8, RI_TYPE_LOCAL, n) -#define HID_STRING_MAXIMUM(x) HID_REPORT_ITEM(x, 9, RI_TYPE_LOCAL, 1) -#define HID_STRING_MAXIMUM_N(x, n) HID_REPORT_ITEM(x, 9, RI_TYPE_LOCAL, n) - -// Joystick Report Descriptor to Emulate IO4 -#define MAIPICO_REPORT_DESC_JOYSTICK \ - HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ - HID_USAGE(HID_USAGE_DESKTOP_JOYSTICK), \ - HID_COLLECTION(HID_COLLECTION_APPLICATION), \ - HID_REPORT_ID(REPORT_ID_JOYSTICK) \ - \ - HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ - HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ - HID_USAGE(HID_USAGE_DESKTOP_X), \ - HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ - \ - HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ - HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ - HID_USAGE(HID_USAGE_DESKTOP_Y), \ - HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ - \ - HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ - HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ - HID_USAGE(HID_USAGE_DESKTOP_X), \ - HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ - \ - HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ - HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ - HID_USAGE(HID_USAGE_DESKTOP_Y), \ - HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ - \ - HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ - HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ - HID_USAGE(HID_USAGE_DESKTOP_X), \ - HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ - \ - HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ - HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ - HID_USAGE(HID_USAGE_DESKTOP_Y), \ - HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ - \ - HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ - HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ - HID_USAGE(HID_USAGE_DESKTOP_X), \ - HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ - \ - HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ - HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ - HID_USAGE(HID_USAGE_DESKTOP_Y), \ - HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ - \ - HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ - HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ - HID_USAGE(HID_USAGE_DESKTOP_RX), \ - HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ - \ - HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ - HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ - HID_USAGE(HID_USAGE_DESKTOP_RY), \ - HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ - \ - HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ - HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ - HID_USAGE(HID_USAGE_DESKTOP_RX), \ - HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ - \ - HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ - HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ - HID_USAGE(HID_USAGE_DESKTOP_RY), \ - HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ - \ - HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ - HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ - HID_USAGE(HID_USAGE_DESKTOP_SLIDER), \ - HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ - \ - HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ - HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ - HID_USAGE(HID_USAGE_DESKTOP_SLIDER), \ - HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ - \ - HID_REPORT_COUNT(48), HID_REPORT_SIZE(1), \ - HID_USAGE_MIN_N(1, 2), HID_USAGE_MAX_N(48, 2), \ - HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ - \ - HID_REPORT_COUNT(1), HID_REPORT_SIZE(232), \ - HID_INPUT(HID_CONSTANT | HID_ABSOLUTE), \ - \ - HID_USAGE_PAGE_N(0xffa0, 2), \ - HID_USAGE(0x00), \ - HID_REPORT_ID(REPORT_ID_OUTPUT) \ - HID_COLLECTION(HID_COLLECTION_APPLICATION), \ - HID_USAGE(0x00), \ - HID_LOGICAL_MIN(0), HID_LOGICAL_MAX(255), \ - HID_REPORT_COUNT(63), HID_REPORT_SIZE(8), \ - HID_OUTPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ - HID_COLLECTION_END, \ - HID_COLLECTION_END - -#define MAIPICO_REPORT_DESC_NKRO \ - HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ - HID_USAGE(HID_USAGE_DESKTOP_KEYBOARD), \ - HID_COLLECTION(HID_COLLECTION_APPLICATION), \ - /* Modifier */ \ - HID_REPORT_SIZE(1), \ - HID_REPORT_COUNT(8), \ - HID_USAGE_PAGE(HID_USAGE_PAGE_KEYBOARD), \ - HID_USAGE_MIN(224), \ - HID_USAGE_MAX(231), \ - HID_LOGICAL_MIN(0), \ - HID_LOGICAL_MAX(1), \ - HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ - /* LED output that we don't care */ \ - HID_REPORT_COUNT(5), \ - HID_REPORT_SIZE(1), \ - HID_USAGE_PAGE(HID_USAGE_PAGE_LED), \ - HID_USAGE_MIN(1), \ - HID_USAGE_MAX(5), \ - HID_OUTPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ - HID_REPORT_COUNT(1), \ - HID_REPORT_SIZE(3), \ - HID_OUTPUT(HID_CONSTANT), \ - /* Full Keyboard Bitmap */ \ - HID_REPORT_SIZE(1), \ - HID_REPORT_COUNT(120), \ - HID_LOGICAL_MIN(0), \ - HID_LOGICAL_MAX(1), \ - HID_USAGE_PAGE(HID_USAGE_PAGE_KEYBOARD), \ - HID_USAGE_MIN(0), \ - HID_USAGE_MAX(119), \ - HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ - HID_COLLECTION_END - -// HID_REPORT_ID(REPORT_ID_NKRO) - -#endif /* USB_DESCRIPTORS_H_ */ +#ifndef USB_DESCRIPTORS_H_ +#define USB_DESCRIPTORS_H_ + +#include "common/tusb_common.h" +#include "device/usbd.h" + +enum { + REPORT_ID_JOYSTICK = 1, + REPORT_ID_OUTPUT = 16, +}; + +// because they are missing from tusb_hid.h +#define HID_STRING_INDEX(x) HID_REPORT_ITEM(x, 7, RI_TYPE_LOCAL, 1) +#define HID_STRING_INDEX_N(x, n) HID_REPORT_ITEM(x, 7, RI_TYPE_LOCAL, n) +#define HID_STRING_MINIMUM(x) HID_REPORT_ITEM(x, 8, RI_TYPE_LOCAL, 1) +#define HID_STRING_MINIMUM_N(x, n) HID_REPORT_ITEM(x, 8, RI_TYPE_LOCAL, n) +#define HID_STRING_MAXIMUM(x) HID_REPORT_ITEM(x, 9, RI_TYPE_LOCAL, 1) +#define HID_STRING_MAXIMUM_N(x, n) HID_REPORT_ITEM(x, 9, RI_TYPE_LOCAL, n) + +// Joystick Report Descriptor to Emulate IO4 +#define MAIPICO_REPORT_DESC_JOYSTICK \ + HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ + HID_USAGE(HID_USAGE_DESKTOP_JOYSTICK), \ + HID_COLLECTION(HID_COLLECTION_APPLICATION), \ + HID_REPORT_ID(REPORT_ID_JOYSTICK) \ + \ + HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ + HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ + HID_USAGE(HID_USAGE_DESKTOP_X), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ + \ + HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ + HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ + HID_USAGE(HID_USAGE_DESKTOP_Y), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ + \ + HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ + HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ + HID_USAGE(HID_USAGE_DESKTOP_X), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ + \ + HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ + HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ + HID_USAGE(HID_USAGE_DESKTOP_Y), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ + \ + HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ + HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ + HID_USAGE(HID_USAGE_DESKTOP_X), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ + \ + HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ + HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ + HID_USAGE(HID_USAGE_DESKTOP_Y), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ + \ + HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ + HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ + HID_USAGE(HID_USAGE_DESKTOP_X), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ + \ + HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ + HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ + HID_USAGE(HID_USAGE_DESKTOP_Y), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ + \ + HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ + HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ + HID_USAGE(HID_USAGE_DESKTOP_RX), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ + \ + HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ + HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ + HID_USAGE(HID_USAGE_DESKTOP_RY), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ + \ + HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ + HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ + HID_USAGE(HID_USAGE_DESKTOP_RX), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ + \ + HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ + HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ + HID_USAGE(HID_USAGE_DESKTOP_RY), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ + \ + HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ + HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ + HID_USAGE(HID_USAGE_DESKTOP_SLIDER), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ + \ + HID_REPORT_COUNT(1), HID_REPORT_SIZE(16), \ + HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ + HID_USAGE(HID_USAGE_DESKTOP_SLIDER), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ + \ + HID_REPORT_COUNT(48), HID_REPORT_SIZE(1), \ + HID_USAGE_MIN_N(1, 2), HID_USAGE_MAX_N(48, 2), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ + \ + HID_REPORT_COUNT(1), HID_REPORT_SIZE(232), \ + HID_INPUT(HID_CONSTANT | HID_ABSOLUTE), \ + \ + HID_USAGE_PAGE_N(0xffa0, 2), \ + HID_USAGE(0x00), \ + HID_REPORT_ID(REPORT_ID_OUTPUT) \ + HID_COLLECTION(HID_COLLECTION_APPLICATION), \ + HID_USAGE(0x00), \ + HID_LOGICAL_MIN(0), HID_LOGICAL_MAX(255), \ + HID_REPORT_COUNT(63), HID_REPORT_SIZE(8), \ + HID_OUTPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ + HID_COLLECTION_END, \ + HID_COLLECTION_END + +#define MAIPICO_REPORT_DESC_NKRO \ + HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ + HID_USAGE(HID_USAGE_DESKTOP_KEYBOARD), \ + HID_COLLECTION(HID_COLLECTION_APPLICATION), \ + /* Modifier */ \ + HID_REPORT_SIZE(1), \ + HID_REPORT_COUNT(8), \ + HID_USAGE_PAGE(HID_USAGE_PAGE_KEYBOARD), \ + HID_USAGE_MIN(224), \ + HID_USAGE_MAX(231), \ + HID_LOGICAL_MIN(0), \ + HID_LOGICAL_MAX(1), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ + /* LED output that we don't care */ \ + HID_REPORT_COUNT(5), \ + HID_REPORT_SIZE(1), \ + HID_USAGE_PAGE(HID_USAGE_PAGE_LED), \ + HID_USAGE_MIN(1), \ + HID_USAGE_MAX(5), \ + HID_OUTPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ + HID_REPORT_COUNT(1), \ + HID_REPORT_SIZE(3), \ + HID_OUTPUT(HID_CONSTANT), \ + /* Full Keyboard Bitmap */ \ + HID_REPORT_SIZE(1), \ + HID_REPORT_COUNT(120), \ + HID_LOGICAL_MIN(0), \ + HID_LOGICAL_MAX(1), \ + HID_USAGE_PAGE(HID_USAGE_PAGE_KEYBOARD), \ + HID_USAGE_MIN(0), \ + HID_USAGE_MAX(119), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ + HID_COLLECTION_END + +// HID_REPORT_ID(REPORT_ID_NKRO) + +void usb_descriptors_disable_io4(); +#endif /* USB_DESCRIPTORS_H_ */