IO4 can be turned off (to live with official IO4 board)

This commit is contained in:
whowechina 2024-09-18 21:56:38 +08:00
parent f6d5364954
commit 757496f8a0
8 changed files with 180 additions and 165 deletions

Binary file not shown.

View File

@ -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 <joy|key1|key2>\n";
const char *usage = "Usage: hid <io4|key1|key2|off>\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;
}

View File

@ -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,

View File

@ -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 {

View File

@ -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);

View File

@ -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();

View File

@ -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");
}

View File

@ -148,4 +148,5 @@ enum {
// HID_REPORT_ID(REPORT_ID_NKRO)
void usb_descriptors_disable_io4();
#endif /* USB_DESCRIPTORS_H_ */