diff options
Diffstat (limited to 'tmk_core/protocol/vusb')
| -rw-r--r-- | tmk_core/protocol/vusb/protocol.c (renamed from tmk_core/protocol/vusb/main.c) | 89 | ||||
| -rw-r--r-- | tmk_core/protocol/vusb/usb_util.c | 2 | ||||
| -rw-r--r-- | tmk_core/protocol/vusb/vusb.c | 55 | 
3 files changed, 96 insertions, 50 deletions
diff --git a/tmk_core/protocol/vusb/main.c b/tmk_core/protocol/vusb/protocol.c index 53926a7493..89dc795b21 100644 --- a/tmk_core/protocol/vusb/main.c +++ b/tmk_core/protocol/vusb/protocol.c @@ -99,14 +99,11 @@ static void vusb_wakeup(void) {   */  static void setup_usb(void) { initForUsbConnectivity(); } -/** \brief Main - * - * FIXME: Needs doc - */ -int main(void) __attribute__((weak)); -int main(void) { +uint16_t sof_timer = 0; + +void protocol_setup(void) {  #if USB_COUNT_SOF -    uint16_t sof_timer = timer_read(); +    sof_timer = timer_read();  #endif  #ifdef CLKPR @@ -115,9 +112,14 @@ int main(void) {      clock_prescale_set(clock_div_1);  #endif      keyboard_setup(); +} + +void protocol_init(void) {      setup_usb();      sei(); +      keyboard_init(); +      host_set_driver(vusb_driver());      wait_ms(50); @@ -125,55 +127,52 @@ int main(void) {  #ifdef SLEEP_LED_ENABLE      sleep_led_init();  #endif +} -    while (1) { +void protocol_task(void) {  #if USB_COUNT_SOF -        if (usbSofCount != 0) { -            usbSofCount = 0; -            sof_timer   = timer_read(); -            if (vusb_suspended) { -                vusb_wakeup(); -            } -        } else { -            // Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1) -            if (!vusb_suspended && timer_elapsed(sof_timer) > 5) { -                vusb_suspend(); -            } -        } -#endif +    if (usbSofCount != 0) { +        usbSofCount = 0; +        sof_timer   = timer_read();          if (vusb_suspended) { +            vusb_wakeup(); +        } +    } else { +        // Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1) +        if (!vusb_suspended && timer_elapsed(sof_timer) > 5) {              vusb_suspend(); -            if (suspend_wakeup_condition()) { -                vusb_send_remote_wakeup(); -            } -        } else { -            usbPoll(); - -            // TODO: configuration process is inconsistent. it sometime fails. -            // To prevent failing to configure NOT scan keyboard during configuration -            if (usbConfiguration && usbInterruptIsReady()) { -                keyboard_task(); -            } -            vusb_transfer_keyboard(); +        } +    } +#endif +    if (vusb_suspended) { +        vusb_suspend(); +        if (suspend_wakeup_condition()) { +            vusb_send_remote_wakeup(); +        } +    } else { +        usbPoll(); + +        // TODO: configuration process is inconsistent. it sometime fails. +        // To prevent failing to configure NOT scan keyboard during configuration +        if (usbConfiguration && usbInterruptIsReady()) { +            keyboard_task(); +        } +        vusb_transfer_keyboard();  #ifdef RAW_ENABLE -            usbPoll(); +        usbPoll(); -            if (usbConfiguration && usbInterruptIsReady3()) { -                raw_hid_task(); -            } +        if (usbConfiguration && usbInterruptIsReady3()) { +            raw_hid_task(); +        }  #endif  #ifdef CONSOLE_ENABLE -            usbPoll(); +        usbPoll(); -            if (usbConfiguration && usbInterruptIsReady3()) { -                console_task(); -            } -#endif - -            // Run housekeeping -            housekeeping_task(); +        if (usbConfiguration && usbInterruptIsReady3()) { +            console_task();          } +#endif      }  } 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..485b20c900 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));      } @@ -291,6 +292,14 @@ static void send_consumer(uint16_t data) {  #endif  } +void send_digitizer(report_digitizer_t *report) { +#ifdef DIGITIZER_ENABLE +    if (usbInterruptIsReadyShared()) { +        usbSetInterruptShared((void *)report, sizeof(report_digitizer_t)); +    } +#endif +} +  /*------------------------------------------------------------------*   * Request from host                                                *   *------------------------------------------------------------------*/ @@ -509,8 +518,46 @@ const PROGMEM uchar shared_hid_report[] = {      0x95, 0x01,                //   Report Count (1)      0x75, 0x10,                //   Report Size (16)      0x81, 0x00,                //   Input (Data, Array, Absolute) -    0xC0                       // End Collection +    0xC0,                      // End Collection +#endif + +#ifdef DIGITIZER_ENABLE +    // Digitizer report descriptor +    0x05, 0x0D,                 // Usage Page (Digitizers) +    0x09, 0x01,                 // Usage (Digitizer) +    0xA1, 0x01,                 // Collection (Application) +    0x85, REPORT_ID_DIGITIZER,  //   Report ID +    0x09, 0x22,                 //   Usage (Finger) +    0xA1, 0x00,                 //   Collection (Physical) +    // Tip Switch (1 bit) +    0x09, 0x42,  //     Usage (Tip Switch) +    0x15, 0x00,  //     Logical Minimum +    0x25, 0x01,  //     Logical Maximum +    0x95, 0x01,  //     Report Count (1) +    0x75, 0x01,  //     Report Size (16) +    0x81, 0x02,  //     Input (Data, Variable, Absolute) +    // In Range (1 bit) +    0x09, 0x32,  //     Usage (In Range) +    0x81, 0x02,  //     Input (Data, Variable, Absolute) +    // Padding (6 bits) +    0x95, 0x06,  //     Report Count (6) +    0x81, 0x03,  //     Input (Constant) + +    // X/Y Position (4 bytes) +    0x05, 0x01,        //     Usage Page (Generic Desktop) +    0x26, 0xFF, 0x7F,  //     Logical Maximum (32767) +    0x95, 0x01,        //     Report Count (1) +    0x75, 0x10,        //     Report Size (16) +    0x65, 0x33,        //     Unit (Inch, English Linear) +    0x55, 0x0E,        //     Unit Exponent (-2) +    0x09, 0x30,        //     Usage (X) +    0x81, 0x02,        //     Input (Data, Variable, Absolute) +    0x09, 0x31,        //     Usage (Y) +    0x81, 0x02,        //     Input (Data, Variable, Absolute) +    0xC0,              //   End Collection +    0xC0               // End Collection  #endif +  #ifdef SHARED_EP_ENABLE  };  #endif @@ -598,10 +645,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  | 
