diff --git a/jctool/ir_sensor.h b/jctool/ir_sensor.h index 2fca831..b804612 100644 --- a/jctool/ir_sensor.h +++ b/jctool/ir_sensor.h @@ -1,7 +1,7 @@ #pragma once // crc-8-ccitt / polynomial 0x07 look up table -uint8_t mcu_crc8_table[256] = { +static uint8_t mcu_crc8_table[256] = { 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15, 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D, 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65, 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D, 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5, 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD, @@ -21,7 +21,7 @@ uint8_t mcu_crc8_table[256] = { }; // ARGB Ironbow palette -uint32_t iron_palette[] = { +static uint32_t iron_palette[] = { 0xff000014, 0xff000025, 0xff00002a, 0xff000032, 0xff000036, 0xff00003e, 0xff000042, 0xff00004f, 0xff010055, 0xff010057, 0xff02005c, 0xff03005e, 0xff040063, 0xff050065, 0xff070069, 0xff0a0070, 0xff0b0073, 0xff0d0075, 0xff0d0076, 0xff100078, 0xff120079, 0xff15007c, 0xff17007d, 0xff1c0081, @@ -57,7 +57,7 @@ uint32_t iron_palette[] = { }; //ir registers to maximize output -uint8_t ir_registers[] = { +static uint8_t ir_registers[] = { 0x00, 0x00, 0x51, 0x00, 0x0F, 0x7C, 0x01, 0x00, 0x44, 0x01, 0x08, 0x7C, 0x02, 0x00, 0x7B, 0x02, 0x01, 0x7C, 0x03, 0x00, 0x6E, 0x03, 0x06, 0x7C, 0x04, 0x00, 0x05, diff --git a/jctool/jctool.cpp b/jctool/jctool.cpp index 703f438..b81e258 100644 --- a/jctool/jctool.cpp +++ b/jctool/jctool.cpp @@ -1602,6 +1602,7 @@ int ir_sensor(u8* buf_image, u8 ir_res_reg, u8 ir_res_no_of_packets, u16 ir_exposure, u8 ir_leds, u8 ir_digital_gain, u8 ir_ex_light_filter) { int res; u8 buf[0x170]; + static int output_buffer_length = 49; int error_reading = 0; int res_get = 0; // Set input report to x31 @@ -1614,7 +1615,7 @@ int ir_sensor(u8* buf_image, u8 ir_res_reg, u8 ir_res_no_of_packets, timming_byte++; pkt->subcmd = 0x03; pkt->subcmd_arg.arg1 = 0x31; - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); int retries = 0; while (1) { res = hid_read_timeout(handle, buf, sizeof(buf), 64); @@ -1644,7 +1645,7 @@ step1: timming_byte++; pkt->subcmd = 0x22; pkt->subcmd_arg.arg1 = 0x1; - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); int retries = 0; while (1) { res = hid_read_timeout(handle, buf, sizeof(buf), 64); @@ -1673,7 +1674,7 @@ step2: hdr->timer = timming_byte & 0xF; timming_byte++; pkt->subcmd = 0x01; - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); int retries = 0; while (1) { res = hid_read_timeout(handle, buf, sizeof(buf), 64); @@ -1713,7 +1714,7 @@ step3: pkt->subcmd_21_21.mcu_mode = 0x05; // MCU mode - 1: Standby, 4: NFC, 5: IR, 6: Initializing/FW Update? buf[48] = mcu_crc8_calc(buf + 12, 36); - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); int retries = 0; while (1) { res = hid_read_timeout(handle, buf, sizeof(buf), 64); @@ -1746,7 +1747,7 @@ step4: hdr->timer = timming_byte & 0xF; timming_byte++; pkt->subcmd = 0x01; - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); int retries = 0; while (1) { res = hid_read_timeout(handle, buf, sizeof(buf), 64); @@ -1788,7 +1789,7 @@ step5: pkt->subcmd_21_23_01.mcu_minor_v = 0x0900; // Set required IR MCU FW v3.09. Minor 0x0009. buf[48] = mcu_crc8_calc(buf + 12, 36); - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); int retries = 0; while (1) { res = hid_read_timeout(handle, buf, sizeof(buf), 64); @@ -1824,7 +1825,7 @@ step6: buf[47] = mcu_crc8_calc(buf + 11, 36); buf[48] = 0xFF; - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); int retries = 0; while (1) { res = hid_read_timeout(handle, buf, sizeof(buf), 64); @@ -1880,7 +1881,7 @@ step7: pkt->subcmd_21_23_04.reg9_val = 0xc8; buf[48] = mcu_crc8_calc(buf + 12, 36); - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); // Request IR mode status, before waiting for the x21 ack memset(buf, 0, sizeof(buf)); @@ -1891,7 +1892,7 @@ step7: pkt->subcmd_arg.arg1 = 0x02; buf[47] = mcu_crc8_calc(buf + 11, 36); buf[48] = 0xFF; - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); int retries = 0; while (1) { @@ -1932,7 +1933,7 @@ step8: pkt->subcmd_21_23_04.reg1_val = 0x01; buf[48] = mcu_crc8_calc(buf + 12, 36); - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); int retries = 0; while (1) { @@ -1943,7 +1944,7 @@ step8: goto step9; // If the Joy-Con gets to reply to the previous x11 - x03 02 cmd before sending the above, // it will reply with the following if we do not send x11 - x03 02 again: - else if (buf[15] == 0x23) // Got mcu mode config. + else if (buf[15] == 0x23) // Got mcu mode config write. goto step9; } retries++; @@ -1980,9 +1981,9 @@ step9: buf[48] = mcu_crc8_calc(buf + 11, 37); - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); Sleep(15); - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); int tries = 0; while (1) { res = hid_read_timeout(handle, buf, sizeof(buf), 64); @@ -2032,7 +2033,7 @@ step10: timming_byte++; pkt->subcmd = 0x22; pkt->subcmd_arg.arg1 = 0x00; - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); res = hid_read_timeout(handle, buf, sizeof(buf), 64); @@ -2047,7 +2048,7 @@ step10: timming_byte++; pkt->subcmd = 0x03; pkt->subcmd_arg.arg1 = 0x3f; - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); int retries = 0; while (1) { res = hid_read_timeout(handle, buf, sizeof(buf), 64); @@ -2078,6 +2079,7 @@ int nfc_tag_info() { int res; u8 buf[0x170]; u8 buf2[0x170]; + static int output_buffer_length = 49; int error_reading = 0; int res_get = 0; // Set input report to x31 @@ -2090,7 +2092,7 @@ int nfc_tag_info() { timming_byte++; pkt->subcmd = 0x03; pkt->subcmd_arg.arg1 = 0x31; - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); int retries = 0; while (1) { res = hid_read_timeout(handle, buf, sizeof(buf), 64); @@ -2120,7 +2122,7 @@ int nfc_tag_info() { timming_byte++; pkt->subcmd = 0x22; pkt->subcmd_arg.arg1 = 0x1; - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); int retries = 0; while (1) { res = hid_read_timeout(handle, buf, sizeof(buf), 64); @@ -2149,7 +2151,7 @@ int nfc_tag_info() { hdr->timer = timming_byte & 0xF; timming_byte++; pkt->subcmd = 0x01; - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); int retries = 0; while (1) { res = hid_read_timeout(handle, buf, sizeof(buf), 64); @@ -2189,7 +2191,7 @@ int nfc_tag_info() { pkt->subcmd_21_21.mcu_mode = 0x04; // MCU mode - 1: Standby, 4: NFC, 5: IR, 6: Initializing/FW Update? buf[48] = mcu_crc8_calc(buf + 12, 36); - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); int retries = 0; while (1) { res = hid_read_timeout(handle, buf, sizeof(buf), 64); @@ -2221,7 +2223,7 @@ int nfc_tag_info() { hdr->timer = timming_byte & 0xF; timming_byte++; pkt->subcmd = 0x01; - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); int retries = 0; while (1) { res = hid_read_timeout(handle, buf, sizeof(buf), 64); @@ -2261,7 +2263,7 @@ int nfc_tag_info() { buf[15] = 0x00; // Length of data after cmd header buf[47] = mcu_crc8_calc(buf + 11, 36); //Without the last byte - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); int retries = 0; while (1) { res = hid_read_timeout(handle, buf, sizeof(buf), 64); @@ -2304,7 +2306,7 @@ int nfc_tag_info() { //buf[20] = 0x01; buf[47] = mcu_crc8_calc(buf + 11, 36); //Without the last byte - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); int retries = 0; while (1) { if (!enable_NFCScanning) @@ -2377,7 +2379,7 @@ int nfc_tag_info() { buf2[47] = mcu_crc8_calc(buf2 + 11, 36); buf2[48] = 0xFF; - res = hid_write(handle, buf2, sizeof(buf2)); + res = hid_write(handle, buf2, output_buffer_length); int retries = 0; while (1) { res = hid_read_timeout(handle, buf2, sizeof(buf2), 64); @@ -2402,7 +2404,7 @@ int nfc_tag_info() { timming_byte++; pkt->subcmd = 0x22; pkt->subcmd_arg.arg1 = 0x00; - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); res = hid_read_timeout(handle, buf, sizeof(buf), 64); @@ -2416,7 +2418,7 @@ int nfc_tag_info() { timming_byte++; pkt->subcmd = 0x03; pkt->subcmd_arg.arg1 = 0x3f; - res = hid_write(handle, buf, sizeof(buf)); + res = hid_write(handle, buf, output_buffer_length); int retries = 0; while (1) { res = hid_read_timeout(handle, buf, sizeof(buf), 64); diff --git a/jctool/luts.h b/jctool/luts.h index 3272582..e1d1615 100644 --- a/jctool/luts.h +++ b/jctool/luts.h @@ -6,7 +6,7 @@ struct lut_amp { uint16_t la[101]; }; -lut_amp lut_joy_amp{ +static lut_amp lut_joy_amp{ { 0.00000f, 0.007843f, 0.011823f, 0.014061f, 0.01672f, 0.019885f, 0.023648f, 0.028123f, 0.033442f, 0.039771f, 0.047296f, 0.056246f, 0.066886f, 0.079542f, 0.094592f, 0.112491f, 0.117471f, 0.122671f, 0.128102f, 0.133774f, 0.139697f, 0.145882f, 0.152341f, 0.159085f, diff --git a/jctool/tune.h b/jctool/tune.h index 5d6fb77..7331875 100644 --- a/jctool/tune.h +++ b/jctool/tune.h @@ -1,7 +1,7 @@ #pragma once #include // Super Mario Bros - Main theme -uint32_t tune_SMB[2740] = { +static uint32_t tune_SMB[2740] = { 0xbf375f7b, 0xbe37c362, 0xbe10bf77, 0xcef75e6c, 0xc6f7de71, 0xbbf74240, 0xcef75e6e, 0xcef74279, 0xbe396775, 0xce37c36e, 0xce374374, 0xbe17df6f, 0xcf39e77d, 0xce3daf6b, 0xca175f40, 0xceecc260, 0xcef75e6c, 0xbee0e672, 0xbef75e6e, 0xbef0de6c, 0xcef7666c, 0xce39df74, 0xce37df6d, 0xcef03e78, @@ -347,7 +347,7 @@ uint32_t tune_SMB[2740] = { 0xbe306771, 0xbe308373, 0xce37436b, 0x06e0de68 }; // Super Mario Odyssey - Jump Up, Super Star! -uint32_t tune_SMO_OK[4941] = { +static uint32_t tune_SMO_OK[4941] = { 0x00014040, 0x00014040, 0x00014040, 0x00014040, 0x00014040, 0x00014040, 0x00014040, 0x530ca648, 0xef33f16b, 0xb34b2946, 0xeafd4342, 0xcad14640, 0xeba93348, 0x4b53d94a, 0x4339e646, 0xfb3f5646, 0xb3495945, 0xb752536c, 0x933b6745, 0xf355e945, 0x93be7a46, 0xfa7cd548, 0xad4bef84, 0x5c1b2e48,