diff options
Diffstat (limited to 'tmk_core/protocol')
-rw-r--r-- | tmk_core/protocol/arm_atsam/main_arm_atsam.c | 26 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c | 309 | ||||
-rw-r--r-- | tmk_core/protocol/chibios/main.c | 9 | ||||
-rw-r--r-- | tmk_core/protocol/chibios/usb_main.c | 155 | ||||
-rw-r--r-- | tmk_core/protocol/chibios/usb_main.h | 14 | ||||
-rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 35 | ||||
-rw-r--r-- | tmk_core/protocol/lufa/lufa.h | 6 | ||||
-rw-r--r-- | tmk_core/protocol/vusb/main.c | 4 | ||||
-rw-r--r-- | tmk_core/protocol/vusb/vusb.c | 24 |
9 files changed, 282 insertions, 300 deletions
diff --git a/tmk_core/protocol/arm_atsam/main_arm_atsam.c b/tmk_core/protocol/arm_atsam/main_arm_atsam.c index a42d9daf38..9c8073dd9e 100644 --- a/tmk_core/protocol/arm_atsam/main_arm_atsam.c +++ b/tmk_core/protocol/arm_atsam/main_arm_atsam.c @@ -110,40 +110,34 @@ void send_mouse(report_mouse_t *report) { #endif // MOUSEKEY_ENABLE } -void send_system(uint16_t data) { #ifdef EXTRAKEY_ENABLE +void send_extra(uint8_t report_id, uint16_t data) { uint32_t irqflags; irqflags = __get_PRIMASK(); __disable_irq(); __DMB(); - udi_hid_exk_report.desc.report_id = REPORT_ID_SYSTEM; - if (data != 0) data = data - SYSTEM_POWER_DOWN + 1; + udi_hid_exk_report.desc.report_id = report_id; udi_hid_exk_report.desc.report_data = data; udi_hid_exk_b_report_valid = 1; udi_hid_exk_send_report(); __DMB(); __set_PRIMASK(irqflags); +} +#endif // EXTRAKEY_ENABLE + +void send_system(uint16_t data) { +#ifdef EXTRAKEY_ENABLE + if (data != 0) data = data - SYSTEM_POWER_DOWN + 1; + send_extra(REPORT_ID_SYSTEM, data); #endif // EXTRAKEY_ENABLE } void send_consumer(uint16_t data) { #ifdef EXTRAKEY_ENABLE - uint32_t irqflags; - - irqflags = __get_PRIMASK(); - __disable_irq(); - __DMB(); - - udi_hid_exk_report.desc.report_id = REPORT_ID_CONSUMER; - udi_hid_exk_report.desc.report_data = data; - udi_hid_exk_b_report_valid = 1; - udi_hid_exk_send_report(); - - __DMB(); - __set_PRIMASK(irqflags); + send_extra(REPORT_ID_CONSUMER, data); #endif // EXTRAKEY_ENABLE } diff --git a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c index c3952d50c8..5b32954071 100644 --- a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c +++ b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c @@ -98,30 +98,36 @@ UDC_DESC_STORAGE udi_hid_kbd_report_desc_t udi_hid_kbd_report_desc = {{ 0x05, 0x01, // Usage Page (Generic Desktop) 0x09, 0x06, // Usage (Keyboard) 0xA1, 0x01, // Collection (Application) + // Modifiers (8 bits) 0x05, 0x07, // Usage Page (Keyboard) - 0x19, 0xE0, // Usage Minimum (224) - 0x29, 0xE7, // Usage Maximum (231) + 0x19, 0xE0, // Usage Minimum (Keyboard Left Control) + 0x29, 0xE7, // Usage Maximum (Keyboard Right GUI) 0x15, 0x00, // Logical Minimum (0) 0x25, 0x01, // Logical Maximum (1) - 0x75, 0x01, // Report Size (1) 0x95, 0x08, // Report Count (8) + 0x75, 0x01, // Report Size (1) 0x81, 0x02, // Input (Data, Variable, Absolute) + // Reserved (1 byte) 0x81, 0x01, // Input (Constant) + // Keycodes (6 bytes) 0x19, 0x00, // Usage Minimum (0) 0x29, 0xFF, // Usage Maximum (255) 0x15, 0x00, // Logical Minimum (0) 0x25, 0xFF, // Logical Maximum (255) - 0x75, 0x08, // Report Size (8) 0x95, 0x06, // Report Count (6) - 0x81, 0x00, // Input (Data, Array) + 0x75, 0x08, // Report Size (8) + 0x81, 0x00, // Input (Data, Array, Absolute) + + // Status LEDs (5 bits) 0x05, 0x08, // Usage Page (LED) - 0x19, 0x01, // Usage Minimum (1) - 0x29, 0x05, // Usage Maximum (5) + 0x19, 0x01, // Usage Minimum (Num Lock) + 0x29, 0x05, // Usage Maximum (Kana) 0x15, 0x00, // Logical Minimum (0) 0x25, 0x01, // Logical Maximum (1) - 0x75, 0x01, // Report Size (1) 0x95, 0x05, // Report Count (5) + 0x75, 0x01, // Report Size (1) 0x91, 0x02, // Output (Data, Variable, Absolute) + // LED padding (3 bits) 0x95, 0x03, // Report Count (3) 0x91, 0x01, // Output (Constant) 0xC0 // End Collection @@ -231,43 +237,41 @@ static uint8_t udi_hid_nkro_report_trans[UDI_HID_NKRO_REPORT_SIZE]; COMPILER_WORD_ALIGNED UDC_DESC_STORAGE udi_hid_nkro_report_desc_t udi_hid_nkro_report_desc = {{ - 0x05, 0x01, // Usage Page (Generic Desktop), - 0x09, 0x06, // Usage (Keyboard), - 0xA1, 0x01, // Collection (Application) - Keyboard, - - // Mods - 0x75, 0x01, // Report Size (1), - 0x95, 0x08, // Report Count (8), - 0x15, 0x00, // Logical Minimum (0), - 0x25, 0x01, // Logical Maximum (1), - 0x05, 0x07, // Usage Page (Key Codes), - 0x19, 0xE0, // Usage Minimum (224), - 0x29, 0xE7, // Usage Maximum (231), - 0x81, 0x02, // Input (Data, Variable, Absolute), - - // LED Report - 0x75, 0x01, // Report Size (1), - 0x95, 0x05, // Report Count (5), - 0x05, 0x08, // Usage Page (LEDs), - 0x19, 0x01, // Usage Minimum (1), - 0x29, 0x05, // Usage Maximum (5), - 0x91, 0x02, // Output (Data, Variable, Absolute), - - // LED Report Padding - 0x75, 0x03, // Report Size (3), - 0x95, 0x01, // Report Count (1), - 0x91, 0x03, // Output (Constant), - - // Main keys - 0x75, 0x01, // Report Size (1), - 0x95, 0xF8, // Report Count (248), - 0x15, 0x00, // Logical Minimum (0), - 0x25, 0x01, // Logical Maximum (1), - 0x05, 0x07, // Usage Page (Key Codes), - 0x19, 0x00, // Usage Minimum (0), - 0x29, 0xF7, // Usage Maximum (247), - 0x81, 0x02, // Input (Data, Variable, Absolute, Bitfield), - 0xc0, // End Collection - Keyboard + 0x05, 0x01, // Usage Page (Generic Desktop) + 0x09, 0x06, // Usage (Keyboard) + 0xA1, 0x01, // Collection (Application) + + // Modifiers (8 bits) + 0x05, 0x07, // Usage Page (Keyboard/Keypad) + 0x19, 0xE0, // Usage Minimum (Keyboard Left Control) + 0x29, 0xE7, // Usage Maximum (Keyboard Right GUI) + 0x15, 0x00, // Logical Minimum (0) + 0x25, 0x01, // Logical Maximum (1) + 0x95, 0x08, // Report Count (8) + 0x75, 0x01, // Report Size (1) + 0x81, 0x02, // Input (Data, Variable, Absolute) + // Keycodes + 0x05, 0x07, // Usage Page (Keyboard/Keypad) + 0x19, 0x00, // Usage Minimum (0) + 0x29, 0xF7, // Usage Maximum (247) + 0x15, 0x00, // Logical Minimum (0) + 0x25, 0x01, // Logical Maximum (1) + 0x95, 0xF8, // Report Count (248) + 0x75, 0x01, // Report Size (1) + 0x81, 0x02, // Input (Data, Variable, Absolute, Bitfield) + + // Status LEDs (5 bits) + 0x05, 0x08, // Usage Page (LED) + 0x19, 0x01, // Usage Minimum (Num Lock) + 0x29, 0x05, // Usage Maximum (Kana) + 0x95, 0x05, // Report Count (5) + 0x75, 0x01, // Report Size (1) + 0x91, 0x02, // Output (Data, Variable, Absolute) + // LED padding (3 bits) + 0x95, 0x01, // Report Count (1) + 0x75, 0x03, // Report Size (3) + 0x91, 0x03, // Output (Constant) + 0xC0 // End Collection }}; static bool udi_hid_nkro_setreport(void); @@ -373,35 +377,39 @@ static uint8_t udi_hid_exk_report_trans[UDI_HID_EXK_REPORT_SIZE]; COMPILER_WORD_ALIGNED UDC_DESC_STORAGE udi_hid_exk_report_desc_t udi_hid_exk_report_desc = {{ - // System Control Collection (8 bits) - - 0x05, 0x01, // Usage Page (Generic Desktop), - 0x09, 0x80, // Usage (System Control), - 0xA1, 0x01, // Collection (Application), - 0x85, REPORT_ID_SYSTEM, // Report ID (2) (System), - 0x16, 0x01, 0x00, // Logical Minimum (1), - 0x26, 0x03, 0x00, // Logical Maximum (3), - 0x1A, 0x81, 0x00, // Usage Minimum (81) (System Power Down), - 0x2A, 0x83, 0x00, // Usage Maximum (83) (System Wake Up), - 0x75, 0x10, // Report Size (16), - 0x95, 0x01, // Report Count (1), - 0x81, 0x00, // Input (Data, Array), - 0xC0, // End Collection - System Control - - // Consumer Control Collection - Media Keys (16 bits) - - 0x05, 0x0C, // Usage Page (Consumer), - 0x09, 0x01, // Usage (Consumer Control), - 0xA1, 0x01, // Collection (Application), - 0x85, REPORT_ID_CONSUMER, // Report ID (3) (Consumer), - 0x16, 0x01, 0x00, // Logical Minimum (1), - 0x26, 0x9C, 0x02, // Logical Maximum (668), - 0x1A, 0x01, 0x00, // Usage Minimum (1), - 0x2A, 0x9C, 0x02, // Usage Maximum (668), - 0x75, 0x10, // Report Size (16), - 0x95, 0x01, // Report Count (1), - 0x81, 0x00, // Input (Data, Array), - 0xC0, // End Collection - Consumer Control + 0x05, 0x01, // Usage Page (Generic Desktop) + 0x09, 0x80, // Usage (System Control) + 0xA1, 0x01, // Collection (Application) + 0x85, REPORT_ID_SYSTEM, // Report ID + 0x1A, 0x81, + 0x00, // Usage Minimum (81) (System Power Down) + 0x2A, 0x83, + 0x00, // Usage Maximum (83) (System Wake Up) + 0x16, 0x01, + 0x00, // Logical Minimum (1) + 0x26, 0x03, + 0x00, // Logical Maximum (3) + 0x95, 0x01, // Report Count (1) + 0x75, 0x10, // Report Size (16) + 0x81, 0x00, // Input (Data, Array, Absolute) + 0xC0, // End Collection + + 0x05, 0x0C, // Usage Page (Consumer) + 0x09, 0x01, // Usage (Consumer Control) + 0xA1, 0x01, // Collection (Application) + 0x85, REPORT_ID_CONSUMER, // Report ID + 0x1A, 0x01, + 0x00, // Usage Minimum (Consumer Control) + 0x2A, 0x9C, + 0x02, // Usage Maximum (AC Distribute Vertically) + 0x16, 0x01, + 0x00, // Logical Minimum + 0x26, 0x9C, + 0x02, // Logical Maximum + 0x95, 0x01, // Report Count (1) + 0x75, 0x10, // Report Size (16) + 0x81, 0x00, // Input (Data, Array, Absolute) + 0xC0 // End Collection }}; static bool udi_hid_exk_setreport(void); @@ -506,49 +514,53 @@ static uint8_t udi_hid_mou_report_trans[UDI_HID_MOU_REPORT_SIZE]; COMPILER_WORD_ALIGNED UDC_DESC_STORAGE udi_hid_mou_report_desc_t udi_hid_mou_report_desc = {{ - 0x05, 0x01, // Usage Page (Generic Desktop), - 0x09, 0x02, // Usage (Mouse), - 0xA1, 0x01, // Collection (Application), - 0x09, 0x01, // Usage (Pointer), - 0xA1, 0x00, // Collection (Physical), - 0x05, 0x09, // Usage Page (Buttons), - 0x19, 0x01, // Usage Minimum (01), - 0x29, 0x05, // Usage Maximun (05), - 0x15, 0x00, // Logical Minimum (0), - 0x25, 0x01, // Logical Maximum (1), - 0x95, 0x05, // Report Count (5), - 0x75, 0x01, // Report Size (1), - 0x81, 0x02, // Input (Data, Variable, Absolute), ;5 button bits - 0x95, 0x01, // Report Count (1), - 0x75, 0x03, // Report Size (3), - 0x81, 0x01, // Input (Constant), ;3 bit padding, - - 0x05, 0x01, // Usage Page (Generic Desktop), - 0x09, 0x30, // Usage (X), - 0x09, 0x31, // Usage (Y), - 0x15, 0x81, // Logical Minimum (-127), - 0x25, 0x7F, // Logical Maximum (127), - 0x95, 0x02, // Report Count (2), - 0x75, 0x08, // Report Size (8), - 0x81, 0x06, // Input (Data, Variable, Relative), ;2 position bytes (X & Y), - - 0x09, 0x38, // Usage (Wheel), - 0x15, 0x81, // Logical Minimum (-127), - 0x25, 0x7F, // Logical Maximum (127), - 0x95, 0x01, // Report Count (1), - 0x75, 0x08, // Report Size (8), - 0x81, 0x06, // Input (Data, Variable, Relative), - - 0x05, 0x0C, // Usage Page (Consumer), - 0x0A, 0x38, 0x02, // Usage (AC Pan (Horizontal wheel)), - 0x15, 0x81, // Logical Minimum (-127), - 0x25, 0x7F, // Logical Maximum (127), - 0x95, 0x01, // Report Count (1), - 0x75, 0x08, // Report Size (8), - 0x81, 0x06, // Input (Data, Variable, Relative), - - 0xC0, // End Collection, - 0xC0, // End Collection + 0x05, 0x01, // Usage Page (Generic Desktop) + 0x09, 0x02, // Usage (Mouse) + 0xA1, 0x01, // Collection (Application) + 0x09, 0x01, // Usage (Pointer) + 0xA1, 0x00, // Collection (Physical) + // Buttons (5 bits) + 0x05, 0x09, // Usage Page (Button) + 0x19, 0x01, // Usage Minimum (Button 1) + 0x29, 0x05, // Usage Maximun (Button 5) + 0x15, 0x00, // Logical Minimum (0) + 0x25, 0x01, // Logical Maximum (1) + 0x95, 0x05, // Report Count (5) + 0x75, 0x01, // Report Size (1) + 0x81, 0x02, // Input (Data, Variable, Absolute) + // Button padding (3 bits) + 0x95, 0x01, // Report Count (1) + 0x75, 0x03, // Report Size (3) + 0x81, 0x01, // Input (Constant) + + // X/Y position (2 bytes) + 0x05, 0x01, // Usage Page (Generic Desktop) + 0x09, 0x30, // Usage (X) + 0x09, 0x31, // Usage (Y) + 0x15, 0x81, // Logical Minimum (-127) + 0x25, 0x7F, // Logical Maximum (127) + 0x95, 0x02, // Report Count (2) + 0x75, 0x08, // Report Size (8) + 0x81, 0x06, // Input (Data, Variable, Relative) + + // Vertical wheel (1 byte) + 0x09, 0x38, // Usage (Wheel) + 0x15, 0x81, // Logical Minimum (-127) + 0x25, 0x7F, // Logical Maximum (127) + 0x95, 0x01, // Report Count (1) + 0x75, 0x08, // Report Size (8) + 0x81, 0x06, // Input (Data, Variable, Relative) + + // Horizontal wheel (1 byte) + 0x05, 0x0C, // Usage Page (Consumer) + 0x0A, 0x38, 0x02, // Usage (AC Pan) + 0x15, 0x81, // Logical Minimum (-127) + 0x25, 0x7F, // Logical Maximum (127) + 0x95, 0x01, // Report Count (1) + 0x75, 0x08, // Report Size (8) + 0x81, 0x06, // Input (Data, Variable, Relative) + 0xC0, // End Collection + 0xC0 // End Collection }}; static void udi_hid_mou_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep); @@ -636,20 +648,21 @@ static uint8_t udi_hid_raw_report_trans[UDI_HID_RAW_REPORT_SIZE]; COMPILER_WORD_ALIGNED UDC_DESC_STORAGE udi_hid_raw_report_desc_t udi_hid_raw_report_desc = {{ - 0x06, // Usage Page (Vendor Defined) - 0xFF, 0xFF, - 0x0A, // Usage (Mouse) - 0xFF, 0xFF, 0xA1, 0x01, // Collection (Application) - 0x75, 0x08, // Report Size (8) - 0x15, 0x00, // Logical Minimum (0) - 0x25, 0xFF, // Logical Maximum (255) - 0x95, 0x40, // Report Count - 0x09, 0x01, // Usage (Input) - 0x81, 0x02, // Input (Data - 0x95, 0x40, // Report Count - 0x09, 0x02, // Usage (Output) - 0x91, 0x02, // Output (Data - 0xC0, // End Collection - Consumer Control + 0x06, 0x60, 0xFF, // Usage Page (Vendor Defined) + 0x09, 0x61, // Usage (Vendor Defined) + 0xA1, 0x01, // Collection (Application) + 0x75, 0x08, // Report Size (8) + 0x15, 0x00, // Logical Minimum (0) + 0x25, 0xFF, // Logical Maximum (255) + // Data to host + 0x09, 0x62, // Usage (Vendor Defined) + 0x95, RAW_EPSIZE, // Report Count + 0x81, 0x02, // Input (Data, Variable, Absolute) + // Data from host + 0x09, 0x63, // Usage (Vendor Defined) + 0x95, RAW_EPSIZE, // Report Count + 0x91, 0x02, // Output (Data, Variable, Absolute) + 0xC0 // End Collection }}; static bool udi_hid_raw_setreport(void); @@ -753,22 +766,24 @@ static uint8_t udi_hid_con_report_trans[UDI_HID_CON_REPORT_SIZE]; COMPILER_WORD_ALIGNED UDC_DESC_STORAGE udi_hid_con_report_desc_t udi_hid_con_report_desc = {{ - 0x06, 0x31, 0xFF, // Vendor Page (PJRC Teensy compatible) - 0x09, 0x74, // Vendor Usage (PJRC Teensy compatible) - 0xA1, 0x01, // Collection (Application) - 0x09, 0x75, // Usage (Vendor) - 0x15, 0x00, // Logical Minimum (0x00) - 0x26, 0xFF, 0x00, // Logical Maximum (0x00FF) - 0x95, CONSOLE_EPSIZE, // Report Count - 0x75, 0x08, // Report Size (8) - 0x81, 0x02, // Input (Data) - 0x09, 0x76, // Usage (Vendor) - 0x15, 0x00, // Logical Minimum (0x00) - 0x26, 0xFF, 0x00, // Logical Maximum (0x00FF) - 0x95, CONSOLE_EPSIZE, // Report Count - 0x75, 0x08, // Report Size (8) - 0x91, 0x02, // Output (Data) - 0xC0, // End Collection + 0x06, 0x31, 0xFF, // Usage Page (Vendor Defined - PJRC Teensy compatible) + 0x09, 0x74, // Usage (Vendor Defined - PJRC Teensy compatible) + 0xA1, 0x01, // Collection (Application) + // Data to host + 0x09, 0x75, // Usage (Vendor Defined) + 0x15, 0x00, // Logical Minimum (0x00) + 0x26, 0xFF, 0x00, // Logical Maximum (0x00FF) + 0x95, CONSOLE_EPSIZE, // Report Count + 0x75, 0x08, // Report Size (8) + 0x81, 0x02, // Input (Data, Variable, Absolute) + // Data from host + 0x09, 0x76, // Usage (Vendor Defined) + 0x15, 0x00, // Logical Minimum (0x00) + 0x26, 0xFF, 0x00, // Logical Maximum (0x00FF) + 0x95, CONSOLE_EPSIZE, // Report Count + 0x75, 0x08, // Report Size (8) + 0x91, 0x02, // Output (Data) + 0xC0 // End Collection }}; static bool udi_hid_con_setreport(void); diff --git a/tmk_core/protocol/chibios/main.c b/tmk_core/protocol/chibios/main.c index c304f4d795..a61ffad12d 100644 --- a/tmk_core/protocol/chibios/main.c +++ b/tmk_core/protocol/chibios/main.c @@ -81,6 +81,9 @@ void raw_hid_task(void); #ifdef CONSOLE_ENABLE void console_task(void); #endif +#ifdef MIDI_ENABLE +void midi_ep_task(void); +#endif /* TESTING * Amber LED blinker thread, times are in milliseconds. @@ -214,14 +217,14 @@ int main(void) { #ifdef CONSOLE_ENABLE console_task(); #endif +#ifdef MIDI_ENABLE + midi_ep_task(); +#endif #ifdef VIRTSER_ENABLE virtser_task(); #endif #ifdef RAW_ENABLE raw_hid_task(); #endif -#if defined(RGBLIGHT_ANIMATIONS) && defined(RGBLIGHT_ENABLE) - rgblight_task(); -#endif } } diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index 8fbe877dbf..d5eeffcbe4 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -60,10 +60,10 @@ extern keymap_config_t keymap_config; # define usb_lld_disconnect_bus(usbp) #endif -uint8_t keyboard_idle __attribute__((aligned(2))) = 0; -uint8_t keyboard_protocol __attribute__((aligned(2))) = 1; -uint16_t keyboard_led_stats __attribute__((aligned(2))) = 0; -volatile uint16_t keyboard_idle_count = 0; +uint8_t keyboard_idle __attribute__((aligned(2))) = 0; +uint8_t keyboard_protocol __attribute__((aligned(2))) = 1; +uint8_t keyboard_led_stats = 0; +volatile uint16_t keyboard_idle_count = 0; static virtual_timer_t keyboard_idle_timer; static void keyboard_idle_timer_cb(void *arg); @@ -175,61 +175,61 @@ typedef struct { } usb_driver_config_t; /* Reusable initialization structure - see USBEndpointConfig comment at top of file */ -#define QMK_USB_DRIVER_CONFIG(stream, notification, fixedsize) \ - { \ - .queue_capacity_in = stream##_IN_CAPACITY, .queue_capacity_out = stream##_OUT_CAPACITY, \ - .in_ep_config = \ - { \ - stream##_IN_MODE, /* Interrupt EP */ \ - NULL, /* SETUP packet notification callback */ \ - qmkusbDataTransmitted, /* IN notification callback */ \ - NULL, /* OUT notification callback */ \ - stream##_EPSIZE, /* IN maximum packet size */ \ - 0, /* OUT maximum packet size */ \ - NULL, /* IN Endpoint state */ \ - NULL, /* OUT endpoint state */ \ - 2, /* IN multiplier */ \ - NULL /* SETUP buffer (not a SETUP endpoint) */ \ - }, \ - .out_ep_config = \ - { \ - stream##_OUT_MODE, /* Interrupt EP */ \ - NULL, /* SETUP packet notification callback */ \ - NULL, /* IN notification callback */ \ - qmkusbDataReceived, /* OUT notification callback */ \ - 0, /* IN maximum packet size */ \ - stream##_EPSIZE, /* OUT maximum packet size */ \ - NULL, /* IN Endpoint state */ \ - NULL, /* OUT endpoint state */ \ - 2, /* IN multiplier */ \ - NULL, /* SETUP buffer (not a SETUP endpoint) */ \ - }, \ - .int_ep_config = \ - { \ - USB_EP_MODE_TYPE_INTR, /* Interrupt EP */ \ - NULL, /* SETUP packet notification callback */ \ - qmkusbInterruptTransmitted, /* IN notification callback */ \ - NULL, /* OUT notification callback */ \ - CDC_NOTIFICATION_EPSIZE, /* IN maximum packet size */ \ - 0, /* OUT maximum packet size */ \ - NULL, /* IN Endpoint state */ \ - NULL, /* OUT endpoint state */ \ - 2, /* IN multiplier */ \ - NULL, /* SETUP buffer (not a SETUP endpoint) */ \ - }, \ - .config = { \ - .usbp = &USB_DRIVER, \ - .bulk_in = stream##_IN_EPNUM, \ - .bulk_out = stream##_OUT_EPNUM, \ - .int_in = notification, \ - .in_buffers = stream##_IN_CAPACITY, \ - .out_buffers = stream##_OUT_CAPACITY, \ - .in_size = stream##_EPSIZE, \ - .out_size = stream##_EPSIZE, \ - .fixed_size = fixedsize, \ - .ib = (uint8_t[BQ_BUFFER_SIZE(stream##_IN_CAPACITY, stream##_EPSIZE)]){}, \ - .ob = (uint8_t[BQ_BUFFER_SIZE(stream##_OUT_CAPACITY, stream##_EPSIZE)]){}, \ - } \ +#define QMK_USB_DRIVER_CONFIG(stream, notification, fixedsize) \ + { \ + .queue_capacity_in = stream##_IN_CAPACITY, .queue_capacity_out = stream##_OUT_CAPACITY, \ + .in_ep_config = \ + { \ + stream##_IN_MODE, /* Interrupt EP */ \ + NULL, /* SETUP packet notification callback */ \ + qmkusbDataTransmitted, /* IN notification callback */ \ + NULL, /* OUT notification callback */ \ + stream##_EPSIZE, /* IN maximum packet size */ \ + 0, /* OUT maximum packet size */ \ + NULL, /* IN Endpoint state */ \ + NULL, /* OUT endpoint state */ \ + 2, /* IN multiplier */ \ + NULL /* SETUP buffer (not a SETUP endpoint) */ \ + }, \ + .out_ep_config = \ + { \ + stream##_OUT_MODE, /* Interrupt EP */ \ + NULL, /* SETUP packet notification callback */ \ + NULL, /* IN notification callback */ \ + qmkusbDataReceived, /* OUT notification callback */ \ + 0, /* IN maximum packet size */ \ + stream##_EPSIZE, /* OUT maximum packet size */ \ + NULL, /* IN Endpoint state */ \ + NULL, /* OUT endpoint state */ \ + 2, /* IN multiplier */ \ + NULL, /* SETUP buffer (not a SETUP endpoint) */ \ + }, \ + .int_ep_config = \ + { \ + USB_EP_MODE_TYPE_INTR, /* Interrupt EP */ \ + NULL, /* SETUP packet notification callback */ \ + qmkusbInterruptTransmitted, /* IN notification callback */ \ + NULL, /* OUT notification callback */ \ + CDC_NOTIFICATION_EPSIZE, /* IN maximum packet size */ \ + 0, /* OUT maximum packet size */ \ + NULL, /* IN Endpoint state */ \ + NULL, /* OUT endpoint state */ \ + 2, /* IN multiplier */ \ + NULL, /* SETUP buffer (not a SETUP endpoint) */ \ + }, \ + .config = { \ + .usbp = &USB_DRIVER, \ + .bulk_in = stream##_IN_EPNUM, \ + .bulk_out = stream##_OUT_EPNUM, \ + .int_in = notification, \ + .in_buffers = stream##_IN_CAPACITY, \ + .out_buffers = stream##_OUT_CAPACITY, \ + .in_size = stream##_EPSIZE, \ + .out_size = stream##_EPSIZE, \ + .fixed_size = fixedsize, \ + .ib = (__attribute__((aligned(4))) uint8_t[BQ_BUFFER_SIZE(stream##_IN_CAPACITY, stream##_EPSIZE)]){}, \ + .ob = (__attribute__((aligned(4))) uint8_t[BQ_BUFFER_SIZE(stream##_OUT_CAPACITY, stream##_EPSIZE)]){}, \ + } \ } typedef struct { @@ -381,14 +381,17 @@ static uint16_t get_hword(uint8_t *p) { * Other Device Required Optional Optional Optional Optional Optional */ -#if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP) static uint8_t set_report_buf[2] __attribute__((aligned(2))); static void set_led_transfer_cb(USBDriver *usbp) { - if ((set_report_buf[0] == REPORT_ID_KEYBOARD) || (set_report_buf[0] == REPORT_ID_NKRO)) { - keyboard_led_stats = set_report_buf[1]; + if (usbp->setup[6] == 2) { /* LSB(wLength) */ + uint8_t report_id = set_report_buf[0]; + if ((report_id == REPORT_ID_KEYBOARD) || (report_id == REPORT_ID_NKRO)) { + keyboard_led_stats = set_report_buf[1]; + } + } else { + keyboard_led_stats = set_report_buf[0]; } } -#endif /* Callback for SETUP request on the endpoint 0 (control) */ static bool usb_request_hook_cb(USBDriver *usbp) { @@ -444,18 +447,12 @@ static bool usb_request_hook_cb(USBDriver *usbp) { case USB_RTYPE_DIR_HOST2DEV: switch (usbp->setup[1]) { /* bRequest */ case HID_SET_REPORT: - switch (usbp->setup[4]) { /* LSB(wIndex) (check MSB==0 and wLength==1?) */ + switch (usbp->setup[4]) { /* LSB(wIndex) (check MSB==0?) */ + case KEYBOARD_INTERFACE: #if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP) case SHARED_INTERFACE: - usbSetupTransfer(usbp, set_report_buf, sizeof(set_report_buf), set_led_transfer_cb); - return TRUE; - break; #endif - - case KEYBOARD_INTERFACE: - /* keyboard_led_stats = <read byte from next OUT report> - * keyboard_led_stats needs be word (or dword), otherwise we get an exception on F0 */ - usbSetupTransfer(usbp, (uint8_t *)&keyboard_led_stats, 1, NULL); + usbSetupTransfer(usbp, set_report_buf, sizeof(set_report_buf), set_led_transfer_cb); return TRUE; break; } @@ -613,7 +610,7 @@ static void keyboard_idle_timer_cb(void *arg) { } /* LED status */ -uint8_t keyboard_leds(void) { return (uint8_t)(keyboard_led_stats & 0xFF); } +uint8_t keyboard_leds(void) { return keyboard_led_stats; } /* prepare and start sending a report IN * not callable from ISR or locked state */ @@ -836,7 +833,17 @@ bool recv_midi_packet(MIDI_EventPacket_t *const event) { size_t size = chnReadTimeout(&drivers.midi_driver.driver, (uint8_t *)event, sizeof(MIDI_EventPacket_t), TIME_IMMEDIATE); return size == sizeof(MIDI_EventPacket_t); } - +void midi_ep_task(void) { + uint8_t buffer[MIDI_STREAM_EPSIZE]; + size_t size = 0; + do { + size_t size = chnReadTimeout(&drivers.midi_driver.driver, buffer, sizeof(buffer), TIME_IMMEDIATE); + if (size > 0) { + MIDI_EventPacket_t event; + recv_midi_packet(&event); + } + } while (size > 0); +} #endif #ifdef VIRTSER_ENABLE diff --git a/tmk_core/protocol/chibios/usb_main.h b/tmk_core/protocol/chibios/usb_main.h index cd2bb695ba..17041b4f2f 100644 --- a/tmk_core/protocol/chibios/usb_main.h +++ b/tmk_core/protocol/chibios/usb_main.h @@ -72,20 +72,6 @@ void mouse_in_cb(USBDriver *usbp, usbep_t ep); /* shared IN request callback handler */ void shared_in_cb(USBDriver *usbp, usbep_t ep); -/* --------------- - * Extrakey header - * --------------- - */ - -#ifdef EXTRAKEY_ENABLE - -/* extra report structure */ -typedef struct { - uint8_t report_id; - uint16_t usage; -} __attribute__((packed)) report_extra_t; -#endif /* EXTRAKEY_ENABLE */ - /* -------------- * Console header * -------------- diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 8319b34e94..933b212c96 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -662,17 +662,17 @@ static void send_mouse(report_mouse_t *report) { #endif } -/** \brief Send System +/** \brief Send Extra * * FIXME: Needs doc */ -static void send_system(uint16_t data) { #ifdef EXTRAKEY_ENABLE +static void send_extra(uint8_t report_id, uint16_t data) { uint8_t timeout = 255; if (USB_DeviceState != DEVICE_STATE_Configured) return; - report_extra_t r = {.report_id = REPORT_ID_SYSTEM, .usage = data - SYSTEM_POWER_DOWN + 1}; + report_extra_t r = {.report_id = report_id, .usage = data}; Endpoint_SelectEndpoint(SHARED_IN_EPNUM); /* Check if write ready for a polling interval around 10ms */ @@ -681,6 +681,16 @@ static void send_system(uint16_t data) { Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL); Endpoint_ClearIN(); +} +#endif + +/** \brief Send System + * + * FIXME: Needs doc + */ +static void send_system(uint16_t data) { +#ifdef EXTRAKEY_ENABLE + send_extra(REPORT_ID_SYSTEM, data - SYSTEM_POWER_DOWN + 1); #endif } @@ -690,8 +700,7 @@ static void send_system(uint16_t data) { */ static void send_consumer(uint16_t data) { #ifdef EXTRAKEY_ENABLE - uint8_t timeout = 255; - uint8_t where = where_to_send(); + uint8_t where = where_to_send(); # ifdef BLUETOOTH_ENABLE if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) { @@ -729,15 +738,7 @@ static void send_consumer(uint16_t data) { return; } - report_extra_t r = {.report_id = REPORT_ID_CONSUMER, .usage = data}; - Endpoint_SelectEndpoint(SHARED_IN_EPNUM); - - /* Check if write ready for a polling interval around 10ms */ - while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40); - if (!Endpoint_IsReadWriteAllowed()) return; - - Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL); - Endpoint_ClearIN(); + send_extra(REPORT_ID_CONSUMER, data); #endif } @@ -869,7 +870,7 @@ void virtser_recv(uint8_t c) { void virtser_task(void) { uint16_t count = CDC_Device_BytesReceived(&cdc_device); uint8_t ch; - if (count) { + for (; count; --count) { ch = CDC_Device_ReceiveByte(&cdc_device); virtser_recv(ch); } @@ -998,10 +999,6 @@ int main(void) { MIDI_Device_USBTask(&USB_MIDI_Interface); #endif -#if defined(RGBLIGHT_ANIMATIONS) && defined(RGBLIGHT_ENABLE) - rgblight_task(); -#endif - #ifdef MODULE_ADAFRUIT_BLE adafruit_ble_task(); #endif diff --git a/tmk_core/protocol/lufa/lufa.h b/tmk_core/protocol/lufa/lufa.h index 652e4e79b7..1b88060f14 100644 --- a/tmk_core/protocol/lufa/lufa.h +++ b/tmk_core/protocol/lufa/lufa.h @@ -58,12 +58,6 @@ extern host_driver_t lufa_driver; } #endif -/* extra report structure */ -typedef struct { - uint8_t report_id; - uint16_t usage; -} __attribute__((packed)) report_extra_t; - #ifdef API_ENABLE # include "api.h" #endif diff --git a/tmk_core/protocol/vusb/main.c b/tmk_core/protocol/vusb/main.c index e6291900e6..06dc8ae67f 100644 --- a/tmk_core/protocol/vusb/main.c +++ b/tmk_core/protocol/vusb/main.c @@ -99,10 +99,6 @@ int main(void) { // To prevent failing to configure NOT scan keyboard during configuration if (usbConfiguration && usbInterruptIsReady()) { keyboard_task(); - -#if defined(RGBLIGHT_ANIMATIONS) && defined(RGBLIGHT_ENABLE) - rgblight_task(); -#endif } vusb_transfer_keyboard(); } diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index e669384455..110b3069bd 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c @@ -112,32 +112,22 @@ static void send_mouse(report_mouse_t *report) { } } -typedef struct { - uint8_t report_id; - uint16_t usage; -} __attribute__((packed)) report_extra_t; - -static void send_system(uint16_t data) { +static void send_extra(uint8_t report_id, uint16_t data) { + static uint8_t last_id = 0; static uint16_t last_data = 0; - if (data == last_data) return; + if ((report_id == last_id) && (data == last_data)) return; + last_id = report_id; last_data = data; - report_extra_t report = {.report_id = REPORT_ID_SYSTEM, .usage = data}; + report_extra_t report = {.report_id = report_id, .usage = data}; if (usbInterruptIsReady3()) { usbSetInterrupt3((void *)&report, sizeof(report)); } } -static void send_consumer(uint16_t data) { - static uint16_t last_data = 0; - if (data == last_data) return; - last_data = data; +static void send_system(uint16_t data) { send_extra(REPORT_ID_SYSTEM, data); } - report_extra_t report = {.report_id = REPORT_ID_CONSUMER, .usage = data}; - if (usbInterruptIsReady3()) { - usbSetInterrupt3((void *)&report, sizeof(report)); - } -} +static void send_consumer(uint16_t data) { send_extra(REPORT_ID_CONSUMER, data); } /*------------------------------------------------------------------* * Request from host * |