diff options
Diffstat (limited to 'tmk_core/protocol')
| -rw-r--r-- | tmk_core/protocol/arm_atsam/usb/udi_device_conf.h | 10 | ||||
| -rw-r--r-- | tmk_core/protocol/chibios/usb_main.c | 45 | ||||
| -rw-r--r-- | tmk_core/protocol/chibios/usb_util.c | 2 | ||||
| -rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 34 | ||||
| -rw-r--r-- | tmk_core/protocol/lufa/usb_util.c | 2 | ||||
| -rw-r--r-- | tmk_core/protocol/ps2_interrupt.c | 91 | ||||
| -rw-r--r-- | tmk_core/protocol/ps2_io_chibios.c | 55 | ||||
| -rw-r--r-- | tmk_core/protocol/ps2_mouse.c | 21 | ||||
| -rw-r--r-- | tmk_core/protocol/usb_descriptor.c | 6 | ||||
| -rw-r--r-- | tmk_core/protocol/usb_descriptor_common.h | 4 | ||||
| -rw-r--r-- | tmk_core/protocol/vusb/usb_util.c | 2 | ||||
| -rw-r--r-- | tmk_core/protocol/vusb/vusb.c | 7 | 
12 files changed, 215 insertions, 64 deletions
| diff --git a/tmk_core/protocol/arm_atsam/usb/udi_device_conf.h b/tmk_core/protocol/arm_atsam/usb/udi_device_conf.h index 9c9d94789d..1c0983115c 100644 --- a/tmk_core/protocol/arm_atsam/usb/udi_device_conf.h +++ b/tmk_core/protocol/arm_atsam/usb/udi_device_conf.h @@ -23,6 +23,10 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  #include "compiler.h"  #include "usb_protocol_hid.h" +#ifndef USB_POLLING_INTERVAL_MS +#    define USB_POLLING_INTERVAL_MS 10 +#endif +  #ifdef VIRTSER_ENABLE  // because CDC uses IAD (interface association descriptor  // per USB Interface Association Descriptor Device Class Code and Use Model 7/23/2003 Rev 1.0) @@ -118,7 +122,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  #define UDI_HID_KBD_EP_IN KEYBOARD_IN_EPNUM  #define NEXT_IN_EPNUM_1 (KEYBOARD_IN_EPNUM + 1)  #define UDI_HID_KBD_EP_SIZE KEYBOARD_EPSIZE -#define KBD_POLLING_INTERVAL 10 +#define KBD_POLLING_INTERVAL USB_POLLING_INTERVAL_MS  #ifndef UDI_HID_KBD_STRING_ID  #    define UDI_HID_KBD_STRING_ID 0  #endif @@ -128,7 +132,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  #    define NEXT_IN_EPNUM_2 (MOUSE_IN_EPNUM + 1)  #    define UDI_HID_MOU_EP_IN MOUSE_IN_EPNUM  #    define UDI_HID_MOU_EP_SIZE MOUSE_EPSIZE -#    define MOU_POLLING_INTERVAL 10 +#    define MOU_POLLING_INTERVAL USB_POLLING_INTERVAL_MS  #    ifndef UDI_HID_MOU_STRING_ID  #        define UDI_HID_MOU_STRING_ID 0  #    endif @@ -141,7 +145,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  #    define UDI_HID_EXK_EP_IN EXTRAKEY_IN_EPNUM  #    define NEXT_IN_EPNUM_3 (EXTRAKEY_IN_EPNUM + 1)  #    define UDI_HID_EXK_EP_SIZE EXTRAKEY_EPSIZE -#    define EXTRAKEY_POLLING_INTERVAL 10 +#    define EXTRAKEY_POLLING_INTERVAL USB_POLLING_INTERVAL_MS  #    ifndef UDI_HID_EXK_STRING_ID  #        define UDI_HID_EXK_STRING_ID 0  #    endif diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index d04302acae..e5edd74dcb 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -415,14 +415,18 @@ static inline void usb_event_wakeup_handler(void) {  #endif /* SLEEP_LED_ENABLE */  } +bool last_suspend_state = false; +  void usb_event_queue_task(void) {      usbevent_t event;      while (usb_event_queue_dequeue(&event)) {          switch (event) {              case USB_EVENT_SUSPEND: +                last_suspend_state = true;                  usb_event_suspend_handler();                  break;              case USB_EVENT_WAKEUP: +                last_suspend_state = false;                  usb_event_wakeup_handler();                  break;              default: @@ -464,6 +468,9 @@ static void usb_event_cb(USBDriver *usbp, usbevent_t event) {                  qmkusbConfigureHookI(&drivers.array[i].driver);              }              osalSysUnlockFromISR(); +            if (last_suspend_state) { +                usb_event_queue_enqueue(USB_EVENT_WAKEUP); +            }              return;          case USB_EVENT_SUSPEND:              usb_event_queue_enqueue(USB_EVENT_SUSPEND); @@ -518,7 +525,7 @@ static uint16_t get_hword(uint8_t *p) {   * Other Device    Required    Optional    Optional    Optional    Optional    Optional   */ -static uint8_t set_report_buf[2] __attribute__((aligned(2))); +static uint8_t set_report_buf[2] __attribute__((aligned(4)));  static void    set_led_transfer_cb(USBDriver *usbp) {      if (usbp->setup[6] == 2) { /* LSB(wLength) */          uint8_t report_id = set_report_buf[0]; @@ -705,7 +712,7 @@ void init_usb_driver(USBDriver *usbp) {      chVTObjectInit(&keyboard_idle_timer);  } -void restart_usb_driver(USBDriver *usbp) { +__attribute__((weak)) void restart_usb_driver(USBDriver *usbp) {      usbStop(usbp);      usbDisconnectBus(usbp); @@ -903,7 +910,8 @@ static void send_extra(uint8_t report_id, uint16_t data) {          return;      } -    report_extra_t report = {.report_id = report_id, .usage = data}; +    static report_extra_t report; +    report = (report_extra_t){.report_id = report_id, .usage = data};      usbStartTransmitI(&USB_DRIVER, SHARED_IN_EPNUM, (uint8_t *)&report, sizeof(report_extra_t));      osalSysUnlock(); @@ -1051,45 +1059,44 @@ void virtser_task(void) {  #ifdef JOYSTICK_ENABLE  void send_joystick_packet(joystick_t *joystick) { -    joystick_report_t rep = { +    static joystick_report_t rep; +    rep = (joystick_report_t) {  #    if JOYSTICK_AXES_COUNT > 0          .axes = -            { -                joystick->axes[0], +        { joystick->axes[0],  #        if JOYSTICK_AXES_COUNT >= 2 -                joystick->axes[1], +          joystick->axes[1],  #        endif  #        if JOYSTICK_AXES_COUNT >= 3 -                joystick->axes[2], +          joystick->axes[2],  #        endif  #        if JOYSTICK_AXES_COUNT >= 4 -                joystick->axes[3], +          joystick->axes[3],  #        endif  #        if JOYSTICK_AXES_COUNT >= 5 -                joystick->axes[4], +          joystick->axes[4],  #        endif  #        if JOYSTICK_AXES_COUNT >= 6 -                joystick->axes[5], +          joystick->axes[5],  #        endif -            }, +        },  #    endif  // JOYSTICK_AXES_COUNT>0  #    if JOYSTICK_BUTTON_COUNT > 0 -        .buttons = -            { -                joystick->buttons[0], +        .buttons = { +            joystick->buttons[0],  #        if JOYSTICK_BUTTON_COUNT > 8 -                joystick->buttons[1], +            joystick->buttons[1],  #        endif  #        if JOYSTICK_BUTTON_COUNT > 16 -                joystick->buttons[2], +            joystick->buttons[2],  #        endif  #        if JOYSTICK_BUTTON_COUNT > 24 -                joystick->buttons[3], +            joystick->buttons[3],  #        endif -            } +        }  #    endif  // JOYSTICK_BUTTON_COUNT>0      }; diff --git a/tmk_core/protocol/chibios/usb_util.c b/tmk_core/protocol/chibios/usb_util.c index 5945e8a8de..e32d6ebfa4 100644 --- a/tmk_core/protocol/chibios/usb_util.c +++ b/tmk_core/protocol/chibios/usb_util.c @@ -16,6 +16,6 @@  #include <hal.h>  #include "usb_util.h" -void usb_disable(void) { usbStop(&USBD1); } +void usb_disconnect(void) { usbStop(&USBD1); }  bool usb_connected_state(void) { return usbGetDriverStateI(&USBD1) == USB_ACTIVE; } diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 63619fdb3b..4ac079e168 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -314,45 +314,44 @@ static void Console_Task(void) {  void send_joystick_packet(joystick_t *joystick) {      uint8_t timeout = 255; -    joystick_report_t r = { +    static joystick_report_t; +    r = (joystick_report_t) {  #    if JOYSTICK_AXES_COUNT > 0          .axes = -            { -                joystick->axes[0], +        { joystick->axes[0],  #        if JOYSTICK_AXES_COUNT >= 2 -                joystick->axes[1], +          joystick->axes[1],  #        endif  #        if JOYSTICK_AXES_COUNT >= 3 -                joystick->axes[2], +          joystick->axes[2],  #        endif  #        if JOYSTICK_AXES_COUNT >= 4 -                joystick->axes[3], +          joystick->axes[3],  #        endif  #        if JOYSTICK_AXES_COUNT >= 5 -                joystick->axes[4], +          joystick->axes[4],  #        endif  #        if JOYSTICK_AXES_COUNT >= 6 -                joystick->axes[5], +          joystick->axes[5],  #        endif -            }, +        },  #    endif  // JOYSTICK_AXES_COUNT>0  #    if JOYSTICK_BUTTON_COUNT > 0 -        .buttons = -            { -                joystick->buttons[0], +        .buttons = { +            joystick->buttons[0],  #        if JOYSTICK_BUTTON_COUNT > 8 -                joystick->buttons[1], +            joystick->buttons[1],  #        endif  #        if JOYSTICK_BUTTON_COUNT > 16 -                joystick->buttons[2], +            joystick->buttons[2],  #        endif  #        if JOYSTICK_BUTTON_COUNT > 24 -                joystick->buttons[3], +            joystick->buttons[3],  #        endif -            } +        }  #    endif  // JOYSTICK_BUTTON_COUNT>0      }; @@ -768,7 +767,8 @@ static void send_extra(uint8_t report_id, uint16_t data) {      if (USB_DeviceState != DEVICE_STATE_Configured) return; -    report_extra_t r = {.report_id = report_id, .usage = data}; +    static report_extra_t r; +    r = (report_extra_t){.report_id = report_id, .usage = data};      Endpoint_SelectEndpoint(SHARED_IN_EPNUM);      /* Check if write ready for a polling interval around 10ms */ diff --git a/tmk_core/protocol/lufa/usb_util.c b/tmk_core/protocol/lufa/usb_util.c index 9e943a21b9..9691eff1e4 100644 --- a/tmk_core/protocol/lufa/usb_util.c +++ b/tmk_core/protocol/lufa/usb_util.c @@ -17,7 +17,7 @@  #include "usb_util.h"  #include "wait.h" -void usb_disable(void) { +void usb_disconnect(void) {      USB_Disable();      USB_DeviceState = DEVICE_STATE_Unattached;  } diff --git a/tmk_core/protocol/ps2_interrupt.c b/tmk_core/protocol/ps2_interrupt.c index 5afc8a82e4..780040d152 100644 --- a/tmk_core/protocol/ps2_interrupt.c +++ b/tmk_core/protocol/ps2_interrupt.c @@ -40,11 +40,19 @@ POSSIBILITY OF SUCH DAMAGE.   */  #include <stdbool.h> -#include <avr/interrupt.h> -#include <util/delay.h> + +#if defined(__AVR__) +#    include <avr/interrupt.h> +#elif defined(PROTOCOL_CHIBIOS)  // TODO: or STM32 ? +// chibiOS headers +#    include "ch.h" +#    include "hal.h" +#endif +  #include "ps2.h"  #include "ps2_io.h"  #include "print.h" +#include "wait.h"  #define WAIT(stat, us, err)     \      do {                        \ @@ -61,12 +69,30 @@ static inline void    pbuf_enqueue(uint8_t data);  static inline bool    pbuf_has_data(void);  static inline void    pbuf_clear(void); +#if defined(PROTOCOL_CHIBIOS) +void ps2_interrupt_service_routine(void); +void palCallback(void *arg) { ps2_interrupt_service_routine(); } + +#    define PS2_INT_INIT()                             \ +        { palSetLineMode(PS2_CLOCK, PAL_MODE_INPUT); } \ +        while (0) +#    define PS2_INT_ON()                                                \ +        {                                                               \ +            palEnableLineEvent(PS2_CLOCK, PAL_EVENT_MODE_FALLING_EDGE); \ +            palSetLineCallback(PS2_CLOCK, palCallback, NULL);           \ +        }                                                               \ +        while (0) +#    define PS2_INT_OFF()                   \ +        { palDisableLineEvent(PS2_CLOCK); } \ +        while (0) +#endif  // PROTOCOL_CHIBIOS +  void ps2_host_init(void) {      idle();      PS2_INT_INIT();      PS2_INT_ON();      // POR(150-2000ms) plus BAT(300-500ms) may take 2.5sec([3]p.20) -    //_delay_ms(2500); +    // wait_ms(2500);  }  uint8_t ps2_host_send(uint8_t data) { @@ -77,7 +103,7 @@ uint8_t ps2_host_send(uint8_t data) {      /* terminate a transmission if we have */      inhibit(); -    _delay_us(100);  // 100us [4]p.13, [5]p.50 +    wait_us(100);  // 100us [4]p.13, [5]p.50      /* 'Request to Send' and Start bit */      data_lo(); @@ -86,7 +112,6 @@ uint8_t ps2_host_send(uint8_t data) {      /* Data bit[2-9] */      for (uint8_t i = 0; i < 8; i++) { -        _delay_us(15);          if (data & (1 << i)) {              parity = !parity;              data_hi(); @@ -98,7 +123,7 @@ uint8_t ps2_host_send(uint8_t data) {      }      /* Parity bit */ -    _delay_us(15); +    wait_us(15);      if (parity) {          data_hi();      } else { @@ -108,7 +133,7 @@ uint8_t ps2_host_send(uint8_t data) {      WAIT(clock_lo, 50, 5);      /* Stop bit */ -    _delay_us(15); +    wait_us(15);      data_hi();      /* Ack */ @@ -132,7 +157,7 @@ uint8_t ps2_host_recv_response(void) {      // Command may take 25ms/20ms at most([5]p.46, [3]p.21)      uint8_t retry = 25;      while (retry-- && !pbuf_has_data()) { -        _delay_ms(1); +        wait_ms(1);      }      return pbuf_dequeue();  } @@ -148,7 +173,7 @@ uint8_t ps2_host_recv(void) {      }  } -ISR(PS2_INT_VECT) { +void ps2_interrupt_service_routine(void) {      static enum {          INIT,          START, @@ -218,6 +243,10 @@ RETURN:      return;  } +#if defined(__AVR__) +ISR(PS2_INT_VECT) { ps2_interrupt_service_routine(); } +#endif +  /* send LED state to keyboard */  void ps2_host_set_led(uint8_t led) {      ps2_host_send(0xED); @@ -232,8 +261,13 @@ static uint8_t     pbuf[PBUF_SIZE];  static uint8_t     pbuf_head = 0;  static uint8_t     pbuf_tail = 0;  static inline void pbuf_enqueue(uint8_t data) { +#if defined(__AVR__)      uint8_t sreg = SREG;      cli(); +#elif defined(PROTOCOL_CHIBIOS) +    chSysLockFromISR(); +#endif +      uint8_t next = (pbuf_head + 1) % PBUF_SIZE;      if (next != pbuf_tail) {          pbuf[pbuf_head] = data; @@ -241,31 +275,66 @@ static inline void pbuf_enqueue(uint8_t data) {      } else {          print("pbuf: full\n");      } + +#if defined(__AVR__)      SREG = sreg; +#elif defined(PROTOCOL_CHIBIOS) +    chSysUnlockFromISR(); +#endif  }  static inline uint8_t pbuf_dequeue(void) {      uint8_t val = 0; +#if defined(__AVR__)      uint8_t sreg = SREG;      cli(); +#elif defined(PROTOCOL_CHIBIOS) +    chSysLock(); +#endif +      if (pbuf_head != pbuf_tail) {          val       = pbuf[pbuf_tail];          pbuf_tail = (pbuf_tail + 1) % PBUF_SIZE;      } + +#if defined(__AVR__)      SREG = sreg; +#elif defined(PROTOCOL_CHIBIOS) +    chSysUnlock(); +#endif      return val;  }  static inline bool pbuf_has_data(void) { +#if defined(__AVR__)      uint8_t sreg = SREG;      cli(); +#elif defined(PROTOCOL_CHIBIOS) +    chSysLock(); +#endif +      bool has_data = (pbuf_head != pbuf_tail); -    SREG          = sreg; + +#if defined(__AVR__) +    SREG = sreg; +#elif defined(PROTOCOL_CHIBIOS) +    chSysUnlock(); +#endif      return has_data;  }  static inline void pbuf_clear(void) { +#if defined(__AVR__)      uint8_t sreg = SREG;      cli(); +#elif defined(PROTOCOL_CHIBIOS) +    chSysLock(); +#endif +      pbuf_head = pbuf_tail = 0; -    SREG                  = sreg; + +#if defined(__AVR__) +    SREG = sreg; +#elif defined(PROTOCOL_CHIBIOS) +    chSysUnlock(); +#endif  } diff --git a/tmk_core/protocol/ps2_io_chibios.c b/tmk_core/protocol/ps2_io_chibios.c new file mode 100644 index 0000000000..b672bd1f47 --- /dev/null +++ b/tmk_core/protocol/ps2_io_chibios.c @@ -0,0 +1,55 @@ +#include <stdbool.h> +#include "ps2_io.h" + +// chibiOS headers +#include "ch.h" +#include "hal.h" + +/* Check port settings for clock and data line */ +#if !(defined(PS2_CLOCK)) +#    error "PS/2 clock setting is required in config.h" +#endif + +#if !(defined(PS2_DATA)) +#    error "PS/2 data setting is required in config.h" +#endif + +/* + * Clock + */ +void clock_init(void) {} + +void clock_lo(void) { +    palSetLineMode(PS2_CLOCK, PAL_MODE_OUTPUT_OPENDRAIN); +    palWriteLine(PS2_CLOCK, PAL_LOW); +} + +void clock_hi(void) { +    palSetLineMode(PS2_CLOCK, PAL_MODE_OUTPUT_OPENDRAIN); +    palWriteLine(PS2_CLOCK, PAL_HIGH); +} + +bool clock_in(void) { +    palSetLineMode(PS2_CLOCK, PAL_MODE_INPUT); +    return palReadLine(PS2_CLOCK); +} + +/* + * Data + */ +void data_init(void) {} + +void data_lo(void) { +    palSetLineMode(PS2_DATA, PAL_MODE_OUTPUT_OPENDRAIN); +    palWriteLine(PS2_DATA, PAL_LOW); +} + +void data_hi(void) { +    palSetLineMode(PS2_DATA, PAL_MODE_OUTPUT_OPENDRAIN); +    palWriteLine(PS2_DATA, PAL_HIGH); +} + +bool data_in(void) { +    palSetLineMode(PS2_DATA, PAL_MODE_INPUT); +    return palReadLine(PS2_DATA); +} diff --git a/tmk_core/protocol/ps2_mouse.c b/tmk_core/protocol/ps2_mouse.c index 5415453a05..39251a6434 100644 --- a/tmk_core/protocol/ps2_mouse.c +++ b/tmk_core/protocol/ps2_mouse.c @@ -16,9 +16,13 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */  #include <stdbool.h> -#include <avr/io.h> -#include <util/delay.h> + +#if defined(__AVR__) +#    include <avr/io.h> +#endif +  #include "ps2_mouse.h" +#include "wait.h"  #include "host.h"  #include "timer.h"  #include "print.h" @@ -42,7 +46,7 @@ static inline void ps2_mouse_scroll_button_task(report_mouse_t *mouse_report);  void ps2_mouse_init(void) {      ps2_host_init(); -    _delay_ms(PS2_MOUSE_INIT_DELAY);  // wait for powering up +    wait_ms(PS2_MOUSE_INIT_DELAY);  // wait for powering up      PS2_MOUSE_SEND(PS2_MOUSE_RESET, "ps2_mouse_init: sending reset"); @@ -152,8 +156,15 @@ static inline void ps2_mouse_convert_report_to_hid(report_mouse_t *mouse_report)      mouse_report->x = X_IS_NEG ? ((!X_IS_OVF && -127 <= mouse_report->x && mouse_report->x <= -1) ? mouse_report->x : -127) : ((!X_IS_OVF && 0 <= mouse_report->x && mouse_report->x <= 127) ? mouse_report->x : 127);      mouse_report->y = Y_IS_NEG ? ((!Y_IS_OVF && -127 <= mouse_report->y && mouse_report->y <= -1) ? mouse_report->y : -127) : ((!Y_IS_OVF && 0 <= mouse_report->y && mouse_report->y <= 127) ? mouse_report->y : 127); +#ifdef PS2_MOUSE_INVERT_BUTTONS +    // swap left & right buttons +    uint8_t needs_left = mouse_report->buttons & PS2_MOUSE_BTN_RIGHT; +    uint8_t needs_right = mouse_report->buttons & PS2_MOUSE_BTN_LEFT; +    mouse_report->buttons = (mouse_report->buttons & ~(PS2_MOUSE_BTN_MASK)) | (needs_left ? PS2_MOUSE_BTN_LEFT : 0) | (needs_right ? PS2_MOUSE_BTN_RIGHT : 0); +#else      // remove sign and overflow flags      mouse_report->buttons &= PS2_MOUSE_BTN_MASK; +#endif  #ifdef PS2_MOUSE_INVERT_X      mouse_report->x = -mouse_report->x; @@ -210,7 +221,7 @@ static inline void ps2_mouse_enable_scrolling(void) {      PS2_MOUSE_SEND(PS2_MOUSE_SET_SAMPLE_RATE, "Set sample rate");      PS2_MOUSE_SEND(80, "80");      PS2_MOUSE_SEND(PS2_MOUSE_GET_DEVICE_ID, "Finished enabling scroll wheel"); -    _delay_ms(20); +    wait_ms(20);  }  #define PRESS_SCROLL_BUTTONS mouse_report->buttons |= (PS2_MOUSE_SCROLL_BTN_MASK) @@ -252,7 +263,7 @@ static inline void ps2_mouse_scroll_button_task(report_mouse_t *mouse_report) {          if (scroll_state == SCROLL_BTN && timer_elapsed(scroll_button_time) < PS2_MOUSE_SCROLL_BTN_SEND) {              PRESS_SCROLL_BUTTONS;              host_mouse_send(mouse_report); -            _delay_ms(100); +            wait_ms(100);              RELEASE_SCROLL_BUTTONS;          }  #endif diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c index ba7760f283..7a4a790315 100644 --- a/tmk_core/protocol/usb_descriptor.c +++ b/tmk_core/protocol/usb_descriptor.c @@ -351,7 +351,7 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = {          .Size                   = sizeof(USB_Descriptor_Device_t),          .Type                   = DTYPE_Device      }, -    .USBSpecification           = VERSION_BCD(1, 1, 0), +    .USBSpecification           = VERSION_BCD(2, 0, 0),  #if VIRTSER_ENABLE      .Class                      = USB_CSCP_IADDeviceClass, @@ -953,10 +953,10 @@ const USB_Descriptor_String_t PROGMEM ProductString = {  #if defined(SERIAL_NUMBER)  const USB_Descriptor_String_t PROGMEM SerialNumberString = {      .Header = { -        .Size                   = USB_STRING_LEN(sizeof(STR(SERIAL_NUMBER)) - 1), // Subtract 1 for null terminator +        .Size                   = USB_STRING_LEN(sizeof(SERIAL_NUMBER) - 1), // Subtract 1 for null terminator          .Type                   = DTYPE_String      }, -    .UnicodeString              = LSTR(SERIAL_NUMBER) +    .UnicodeString              = USBSTR(SERIAL_NUMBER)  };  #endif diff --git a/tmk_core/protocol/usb_descriptor_common.h b/tmk_core/protocol/usb_descriptor_common.h index b1f602c82e..ce0cf09763 100644 --- a/tmk_core/protocol/usb_descriptor_common.h +++ b/tmk_core/protocol/usb_descriptor_common.h @@ -16,6 +16,10 @@  #pragma once +// Prefix string literal with L for descriptors +#define USBCONCAT(a, b) a##b +#define USBSTR(s) USBCONCAT(L, s) +  /////////////////////  // RAW Usage page and ID configuration diff --git a/tmk_core/protocol/vusb/usb_util.c b/tmk_core/protocol/vusb/usb_util.c index 602854dbe6..4ee2d3188b 100644 --- a/tmk_core/protocol/vusb/usb_util.c +++ b/tmk_core/protocol/vusb/usb_util.c @@ -16,7 +16,7 @@  #include <usbdrv/usbdrv.h>  #include "usb_util.h" -void usb_disable(void) { usbDeviceDisconnect(); } +void usb_disconnect(void) { usbDeviceDisconnect(); }  bool usb_connected_state(void) {      usbPoll(); diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index 9362fbde78..98cebf6012 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c @@ -272,7 +272,8 @@ static void send_extra(uint8_t report_id, uint16_t data) {      last_id   = report_id;      last_data = data; -    report_extra_t report = {.report_id = report_id, .usage = data}; +    static report_extra_t report; +    report = (report_extra_t){.report_id = report_id, .usage = data};      if (usbInterruptIsReadyShared()) {          usbSetInterruptShared((void *)&report, sizeof(report_extra_t));      } @@ -598,10 +599,10 @@ const PROGMEM usbStringDescriptor_t usbStringDescriptorProduct = {  #if defined(SERIAL_NUMBER)  const PROGMEM usbStringDescriptor_t usbStringDescriptorSerial = {      .header = { -        .bLength         = USB_STRING_LEN(sizeof(STR(SERIAL_NUMBER)) - 1), +        .bLength         = USB_STRING_LEN(sizeof(SERIAL_NUMBER) - 1),          .bDescriptorType = USBDESCR_STRING      }, -    .bString             = LSTR(SERIAL_NUMBER) +    .bString             = USBSTR(SERIAL_NUMBER)  };  #endif | 
