diff --git a/Firmware/Keyboard/Config.c b/Firmware/Keyboard/Config.c index 254e3d7..ba70b17 100644 --- a/Firmware/Keyboard/Config.c +++ b/Firmware/Keyboard/Config.c @@ -33,7 +33,7 @@ void InitConfig(void) { sdvxConfig.version = FIRMWARE_VERSION; } -void SetConfig(uint8_t* config) { +void SetConfig(sdvx_config_t* config) { memcpy(&sdvxConfig, config, sizeof(sdvx_config_t)); // Version is set in firmware, not software sdvxConfig.version = FIRMWARE_VERSION; diff --git a/Firmware/Keyboard/Config.h b/Firmware/Keyboard/Config.h index 47daf82..2413a83 100644 --- a/Firmware/Keyboard/Config.h +++ b/Firmware/Keyboard/Config.h @@ -5,12 +5,15 @@ #include #include -// For ease of code sharing with the OsuPad -#define SWITCH_COUNT 7 +// 7 gameplay switches + macro combo switch +#define SWITCH_COUNT 8 #define MAGIC_RESET_NUMBER 42 #define FIRMWARE_VERSION 1 typedef struct { + // used to reboot into programming mode + uint8_t reboot; + uint8_t version; // SWITCH ORDER: A-D, FXL-R, START uint8_t switches[SWITCH_COUNT]; bool ledsOn; @@ -27,6 +30,6 @@ typedef struct { extern sdvx_config_t sdvxConfig; extern void InitConfig(void); -extern void SetConfig(uint8_t* config); +extern void SetConfig(sdvx_config_t* config); #endif \ No newline at end of file diff --git a/Firmware/Keyboard/DFU/hid_bootloader_loader.py b/Firmware/Keyboard/DFU/hid_bootloader_loader.py index 686be55..917d45f 100644 --- a/Firmware/Keyboard/DFU/hid_bootloader_loader.py +++ b/Firmware/Keyboard/DFU/hid_bootloader_loader.py @@ -64,7 +64,10 @@ def bootloader_boot(): try: hid_device = valid_hid_devices[0] hid_device.open() - output_report_data = [0,0,0,0,0,0,0,0,0,0,0,42] + # switch count + static stuff + report id + output_report_data = [0] * (8 + 9 + 1) + # report ID is 0 at byte 0 + output_report_data[1] = 42; hid_device.send_output_report(output_report_data) finally: diff --git a/Firmware/Keyboard/Descriptors.c b/Firmware/Keyboard/Descriptors.c index cf5f9e5..b1fdd50 100644 --- a/Firmware/Keyboard/Descriptors.c +++ b/Firmware/Keyboard/Descriptors.c @@ -53,13 +53,15 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM LEDReport[] = HID_RI_USAGE_MAXIMUM(8, LED_TOTAL_COUNT), // LED 8 + buttons HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE), - // INPUT is also needed to be recognised by Bemanitools - //HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE), - 0x79, STRING_ID_LED_INDIV, //HID_RI_STRING_MINIMUM(8, STRING_ID_LED_INDIV), - 0x89, STRING_ID_LED_INDIV + LED_TOTAL_COUNT, //HID_RI_STRING_MAXIMUM(8, STRING_ID_LED_INDIV + LED_COUNT), - HID_RI_USAGE_MINIMUM(8, 1), // LED 1 - HID_RI_USAGE_MAXIMUM(8, LED_TOTAL_COUNT), // LED 8 + buttons + // at least 1 INPUT is also needed to be recognised by Bemanitools + HID_RI_USAGE_MINIMUM(8, 1), + HID_RI_USAGE_MAXIMUM(8, 1), HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE), + //0x79, STRING_ID_LED_INDIV, //HID_RI_STRING_MINIMUM(8, STRING_ID_LED_INDIV), + //0x89, STRING_ID_LED_INDIV + LED_TOTAL_COUNT, //HID_RI_STRING_MAXIMUM(8, STRING_ID_LED_INDIV + LED_COUNT), + //HID_RI_USAGE_MINIMUM(8, 1), // LED 1 + //HID_RI_USAGE_MAXIMUM(8, LED_TOTAL_COUNT), // LED 8 + buttons + //HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE), HID_RI_END_COLLECTION(0), }; @@ -86,13 +88,9 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] = const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] = { /* Use the HID class driver's standard Mouse report. - * Min X/Y Axis values: -128 - * Max X/Y Axis values: 127 - * Min physical X/Y Axis values (used to determine resolution): -128 - * Max physical X/Y Axis values (used to determine resolution): 127 + * Min/max X/Y -128 to 127 * NOTE: need at least 1 button or report does not work - * Buttons: 1 - * Absolute screen coordinates: false + * Relative coordinates */ HID_DESCRIPTOR_MOUSE(-128, 127, -128, 127, 1, false) }; @@ -291,7 +289,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .EndpointAddress = LED_EPADDR, .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .EndpointSize = LED_EPSIZE, - .PollingIntervalMS = 15 + .PollingIntervalMS = 255 }, }; @@ -315,6 +313,7 @@ const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR(L"Po const USB_Descriptor_String_t PROGMEM ConfigString = USB_STRING_DESCRIPTOR(L"Pocket Voltex Config"); const USB_Descriptor_String_t PROGMEM LEDString = USB_STRING_DESCRIPTOR(L"Pocket Voltex LEDs"); const USB_Descriptor_String_t PROGMEM KnobString = USB_STRING_DESCRIPTOR(L"Pocket Voltex Knobs"); +// There may be a better way to do this const USB_Descriptor_String_t PROGMEM LEDString_indiv[] = { USB_STRING_DESCRIPTOR(L"L1-B"), USB_STRING_DESCRIPTOR(L"L1-G"), diff --git a/Firmware/Keyboard/Keyboard.c b/Firmware/Keyboard/Keyboard.c index 491f2f8..92e9d66 100644 --- a/Firmware/Keyboard/Keyboard.c +++ b/Firmware/Keyboard/Keyboard.c @@ -21,7 +21,7 @@ typedef struct typedef struct { - uint8_t mainLights[LED_RAW_COUNT]; + uint8_t mainLights[LED_PHYSICAL_COUNT]; uint8_t btFx[6]; } LED_Report_t; @@ -276,7 +276,7 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn USB_MouseReport_Data_t* MouseReport = (USB_MouseReport_Data_t*)ReportData; MouseReport->X = encoder_get(0); - MouseReport->Y = -encoder_get(1); + MouseReport->Y = encoder_get(1); led_knobs_update(MouseReport->X, MouseReport->Y); @@ -290,12 +290,7 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn memcpy(ConfigReport, &sdvxConfig, sizeof(sdvx_config_t)); *ReportSize = CONFIG_BYTES; return true; - }/* else if(HIDInterfaceInfo == &LED_HID_Interface) { - uint8_t* LEDReport = (uint8_t*)ReportData; - memcpy(LEDReport, (uint8_t*)leds, LED_TOTAL_COUNT); - *ReportSize = LED_TOTAL_COUNT; - return true; - }*/ + } *ReportSize = 0; return false; @@ -315,9 +310,9 @@ void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDI const void* ReportData, const uint16_t ReportSize) { if(HIDInterfaceInfo == &Generic_HID_Interface && ReportType == HID_REPORT_ITEM_Out) { - uint8_t* ConfigReport = (uint8_t*)ReportData; + sdvx_config_t* ConfigReport = (sdvx_config_t*)ReportData; // So we can upgrade firmware without having to hit the button - if(ConfigReport[CONFIG_BYTES-1] == MAGIC_RESET_NUMBER) { + if(ConfigReport->reboot == MAGIC_RESET_NUMBER) { RebootToBootloader(); } SetConfig(ConfigReport); @@ -326,7 +321,7 @@ void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDI hidTimeout = 0; LED_Report_t* LEDReport = (LED_Report_t*)ReportData; - memcpy((uint8_t*)leds, LEDReport->mainLights, LED_RAW_COUNT); + memcpy((uint8_t*)leds, LEDReport->mainLights, LED_PHYSICAL_COUNT); // Keep normal lights but override when we get flashes on BT or FX // BT LEDs flash pure white diff --git a/Firmware/Keyboard/LED.c b/Firmware/Keyboard/LED.c index 8469d24..0dd60bc 100644 --- a/Firmware/Keyboard/LED.c +++ b/Firmware/Keyboard/LED.c @@ -37,7 +37,7 @@ void led_init() { // all LEDs output LED_DDR |= LED_MASK; - memset((uint8_t*)leds, 0, LED_RAW_COUNT); + memset((uint8_t*)leds, 0, LED_PHYSICAL_COUNT); // 64 light levels * 60Hz update * 4 different GND pins = 15360Hz // 520 clock cycles for our interrupt handler diff --git a/Firmware/Keyboard/LED.h b/Firmware/Keyboard/LED.h index 6c66ccb..25b269b 100644 --- a/Firmware/Keyboard/LED.h +++ b/Firmware/Keyboard/LED.h @@ -4,18 +4,19 @@ #include #include #include +#include #include #define LED_COUNT 8 -#define LED_RAW_COUNT (LED_COUNT*3) +#define LED_PHYSICAL_COUNT (LED_COUNT*3) // BT + FX #define LED_VIRTUAL_COUNT 6 -#define LED_TOTAL_COUNT (LED_RAW_COUNT + LED_VIRTUAL_COUNT) +#define LED_TOTAL_COUNT (LED_PHYSICAL_COUNT + LED_VIRTUAL_COUNT) #define BRIGHTNESS_LEVELS 64 // Arranged left to right, top to bottom // LED order is BGR...BGR -volatile uint8_t leds[LED_RAW_COUNT]; +volatile uint8_t leds[LED_PHYSICAL_COUNT]; // Maps BT/FX keys to their associated LED // Order is BT-1-4, FX-L, FX-R @@ -30,7 +31,7 @@ void led_set_max(uint8_t num, uint8_t r, uint8_t g, uint8_t b); void led_set_all(uint8_t r, uint8_t g, uint8_t b); void led_set_indiv(uint8_t num, uint8_t val); -const static uint8_t ledLogCurve[] = { +PROGMEM const static uint8_t ledLogCurve[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9, diff --git a/Firmware/Keyboard/LEDPatterns.c b/Firmware/Keyboard/LEDPatterns.c index 2978306..79c8e66 100644 --- a/Firmware/Keyboard/LEDPatterns.c +++ b/Firmware/Keyboard/LEDPatterns.c @@ -1,4 +1,5 @@ #include "LEDPatterns.h" +#include static enum LEDMode animMode = NONE; static uint8_t frameCounter = 0; @@ -35,9 +36,6 @@ void led_frame(void) { frameCounter = 0; - uint8_t followDir; - RGBFader* follow; - switch(animMode) { case INIT_FLASH: if(flashDirection) { @@ -49,17 +47,19 @@ void led_frame(void) { } else { flash-=3; if(flash <= 0) { - //animMode = NONE; led_anim_follower(); flash = 0; } } - uint8_t bright = ledLogCurve[flash]; + uint8_t bright = pgm_read_byte(&ledLogCurve[flash]); led_set_all(bright, bright/2, 0); break; case FOLLOWER: - /*for(uint8_t led = 0; led < LED_COUNT; led++) { + for(uint8_t led = 0; led < LED_COUNT; led++) { + uint8_t followDir; + RGBFader* follow; + follow = followers + led; followDir = follow->direction; for(uint8_t i = 0; i < 3; i++) { @@ -79,7 +79,7 @@ void led_frame(void) { followDir >>= 1; } led_set(led, follow->value[0], follow->value[1], follow->value[2]); - }*/ + } break; case BREATHE: default: @@ -150,7 +150,7 @@ void led_anim_flash(void) { void led_anim_follower(void) { // Generated by FollowerGen.py - static const uint8_t followStart[][4] = { + static uint8_t PROGMEM followStart[][4] = { {63, 0, 0, 0b010}, {40, 0, 23, 0b001}, {39, 24, 0, 0b010}, @@ -164,8 +164,8 @@ void led_anim_follower(void) { for(uint8_t i = 0; i < LED_COUNT; i++) { for(uint8_t j = 0; j < 3; j++) { - followers[i].value[j] = followStart[i][j]; + followers[i].value[j] = pgm_read_byte(&followStart[i][j]); } - followers[i].direction = followStart[i][3]; + followers[i].direction = pgm_read_byte(&followStart[i][3]); } } \ No newline at end of file