diff options
| -rw-r--r-- | keyboard/hhkb/Makefile.lufa | 3 | ||||
| -rw-r--r-- | protocol/lufa/descriptor.h | 2 | ||||
| -rw-r--r-- | protocol/lufa/lufa.c | 100 |
3 files changed, 65 insertions, 40 deletions
diff --git a/keyboard/hhkb/Makefile.lufa b/keyboard/hhkb/Makefile.lufa index cdd68f40a..0dc295e62 100644 --- a/keyboard/hhkb/Makefile.lufa +++ b/keyboard/hhkb/Makefile.lufa | |||
| @@ -93,6 +93,9 @@ ARCH = AVR8 | |||
| 93 | # CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. | 93 | # CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. |
| 94 | F_USB = $(F_CPU) | 94 | F_USB = $(F_CPU) |
| 95 | 95 | ||
| 96 | # Interrupt driven control endpoint task | ||
| 97 | OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT | ||
| 98 | |||
| 96 | 99 | ||
| 97 | # Build Options | 100 | # Build Options |
| 98 | # comment out to disable the options. | 101 | # comment out to disable the options. |
diff --git a/protocol/lufa/descriptor.h b/protocol/lufa/descriptor.h index 001e072e6..09fb24acc 100644 --- a/protocol/lufa/descriptor.h +++ b/protocol/lufa/descriptor.h | |||
| @@ -110,7 +110,7 @@ typedef struct | |||
| 110 | 110 | ||
| 111 | #define KEYBOARD_EPSIZE 8 | 111 | #define KEYBOARD_EPSIZE 8 |
| 112 | #define MOUSE_EPSIZE 8 | 112 | #define MOUSE_EPSIZE 8 |
| 113 | #define CONSOLE_EPSIZE 8 | 113 | #define CONSOLE_EPSIZE 32 |
| 114 | #define EXTRA_EPSIZE 8 | 114 | #define EXTRA_EPSIZE 8 |
| 115 | 115 | ||
| 116 | 116 | ||
diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c index 8fa719bc9..10511ba67 100644 --- a/protocol/lufa/lufa.c +++ b/protocol/lufa/lufa.c | |||
| @@ -69,7 +69,7 @@ static host_driver_t lufa_driver = { | |||
| 69 | 69 | ||
| 70 | 70 | ||
| 71 | static void SetupHardware(void); | 71 | static void SetupHardware(void); |
| 72 | static void Console_HID_Task(void); | 72 | static void Console_Task(void); |
| 73 | 73 | ||
| 74 | int main(void) | 74 | int main(void) |
| 75 | { | 75 | { |
| @@ -90,8 +90,9 @@ int main(void) | |||
| 90 | while (1) { | 90 | while (1) { |
| 91 | keyboard_proc(); | 91 | keyboard_proc(); |
| 92 | 92 | ||
| 93 | Console_HID_Task(); | 93 | #if !defined(INTERRUPT_CONTROL_ENDPOINT) |
| 94 | USB_USBTask(); | 94 | USB_USBTask(); |
| 95 | #endif | ||
| 95 | } | 96 | } |
| 96 | } | 97 | } |
| 97 | 98 | ||
| @@ -105,42 +106,52 @@ void SetupHardware(void) | |||
| 105 | clock_prescale_set(clock_div_1); | 106 | clock_prescale_set(clock_div_1); |
| 106 | 107 | ||
| 107 | USB_Init(); | 108 | USB_Init(); |
| 109 | |||
| 110 | // for Console_Task | ||
| 111 | USB_Device_EnableSOFEvents(); | ||
| 108 | } | 112 | } |
| 109 | 113 | ||
| 110 | static void Console_HID_Task(void) | 114 | static void Console_Task(void) |
| 111 | { | 115 | { |
| 112 | /* Device must be connected and configured for the task to run */ | 116 | /* Device must be connected and configured for the task to run */ |
| 113 | if (USB_DeviceState != DEVICE_STATE_Configured) | 117 | if (USB_DeviceState != DEVICE_STATE_Configured) |
| 114 | return; | 118 | return; |
| 115 | 119 | ||
| 116 | // TODO: impl receivechar()/recvchar() | 120 | uint8_t ep = Endpoint_GetCurrentEndpoint(); |
| 117 | Endpoint_SelectEndpoint(CONSOLE_OUT_EPNUM); | 121 | |
| 118 | 122 | #if 0 | |
| 119 | /* Check to see if a packet has been sent from the host */ | 123 | // TODO: impl receivechar()/recvchar() |
| 120 | if (Endpoint_IsOUTReceived()) | 124 | Endpoint_SelectEndpoint(CONSOLE_OUT_EPNUM); |
| 121 | { | 125 | |
| 122 | /* Check to see if the packet contains data */ | 126 | /* Check to see if a packet has been sent from the host */ |
| 123 | if (Endpoint_IsReadWriteAllowed()) | 127 | if (Endpoint_IsOUTReceived()) |
| 124 | { | 128 | { |
| 125 | /* Create a temporary buffer to hold the read in report from the host */ | 129 | /* Check to see if the packet contains data */ |
| 126 | uint8_t ConsoleData[CONSOLE_EPSIZE]; | 130 | if (Endpoint_IsReadWriteAllowed()) |
| 127 | 131 | { | |
| 128 | /* Read Console Report Data */ | 132 | /* Create a temporary buffer to hold the read in report from the host */ |
| 129 | Endpoint_Read_Stream_LE(&ConsoleData, sizeof(ConsoleData), NULL); | 133 | uint8_t ConsoleData[CONSOLE_EPSIZE]; |
| 130 | 134 | ||
| 131 | /* Process Console Report Data */ | 135 | /* Read Console Report Data */ |
| 132 | //ProcessConsoleHIDReport(ConsoleData); | 136 | Endpoint_Read_Stream_LE(&ConsoleData, sizeof(ConsoleData), NULL); |
| 133 | } | 137 | |
| 134 | 138 | /* Process Console Report Data */ | |
| 135 | /* Finalize the stream transfer to send the last packet */ | 139 | //ProcessConsoleHIDReport(ConsoleData); |
| 136 | Endpoint_ClearOUT(); | 140 | } |
| 137 | } | 141 | |
| 138 | 142 | /* Finalize the stream transfer to send the last packet */ | |
| 139 | /* IN packet */ | 143 | Endpoint_ClearOUT(); |
| 140 | Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM); | 144 | } |
| 141 | // send IN packet | 145 | #endif |
| 142 | if (Endpoint_IsINReady()) | 146 | |
| 143 | Endpoint_ClearIN(); | 147 | /* IN packet */ |
| 148 | Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM); | ||
| 149 | // flash senchar packet | ||
| 150 | if (Endpoint_IsINReady()) { | ||
| 151 | Endpoint_ClearIN(); | ||
| 152 | } | ||
| 153 | |||
| 154 | Endpoint_SelectEndpoint(ep); | ||
| 144 | } | 155 | } |
| 145 | 156 | ||
| 146 | 157 | ||
| @@ -157,6 +168,16 @@ void EVENT_USB_Device_Disconnect(void) | |||
| 157 | { | 168 | { |
| 158 | } | 169 | } |
| 159 | 170 | ||
| 171 | #define CONSOLE_TASK_INTERVAL 50 | ||
| 172 | void EVENT_USB_Device_StartOfFrame(void) | ||
| 173 | { | ||
| 174 | static uint8_t interval; | ||
| 175 | if (++interval == CONSOLE_TASK_INTERVAL) { | ||
| 176 | Console_Task(); | ||
| 177 | interval = 0; | ||
| 178 | } | ||
| 179 | } | ||
| 180 | |||
| 160 | /** Event handler for the USB_ConfigurationChanged event. | 181 | /** Event handler for the USB_ConfigurationChanged event. |
| 161 | * This is fired when the host sets the current configuration of the USB device after enumeration. | 182 | * This is fired when the host sets the current configuration of the USB device after enumeration. |
| 162 | */ | 183 | */ |
| @@ -182,7 +203,7 @@ void EVENT_USB_Device_ConfigurationChanged(void) | |||
| 182 | 203 | ||
| 183 | /* Setup Console HID Report Endpoints */ | 204 | /* Setup Console HID Report Endpoints */ |
| 184 | ConfigSuccess &= Endpoint_ConfigureEndpoint(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, | 205 | ConfigSuccess &= Endpoint_ConfigureEndpoint(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, |
| 185 | CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE); | 206 | CONSOLE_EPSIZE, ENDPOINT_BANK_DOUBLE); |
| 186 | ConfigSuccess &= Endpoint_ConfigureEndpoint(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, | 207 | ConfigSuccess &= Endpoint_ConfigureEndpoint(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, |
| 187 | CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE); | 208 | CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE); |
| 188 | } | 209 | } |
| @@ -374,6 +395,7 @@ static void send_consumer(uint16_t data) | |||
| 374 | /******************************************************************************* | 395 | /******************************************************************************* |
| 375 | * sendchar | 396 | * sendchar |
| 376 | ******************************************************************************/ | 397 | ******************************************************************************/ |
| 398 | #define SEND_TIMEOUT 10 | ||
| 377 | int8_t sendchar(uint8_t c) | 399 | int8_t sendchar(uint8_t c) |
| 378 | { | 400 | { |
| 379 | if (USB_DeviceState != DEVICE_STATE_Configured) | 401 | if (USB_DeviceState != DEVICE_STATE_Configured) |
| @@ -381,9 +403,9 @@ int8_t sendchar(uint8_t c) | |||
| 381 | 403 | ||
| 382 | Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM); | 404 | Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM); |
| 383 | 405 | ||
| 384 | uint8_t timeout = 10; | 406 | uint8_t timeout = SEND_TIMEOUT; |
| 385 | uint16_t prevFN = USB_Device_GetFrameNumber(); | 407 | uint16_t prevFN = USB_Device_GetFrameNumber(); |
| 386 | while (!Endpoint_IsINReady()) { | 408 | while (!Endpoint_IsReadWriteAllowed()) { |
| 387 | switch (USB_DeviceState) { | 409 | switch (USB_DeviceState) { |
| 388 | case DEVICE_STATE_Unattached: | 410 | case DEVICE_STATE_Unattached: |
| 389 | case DEVICE_STATE_Suspended: | 411 | case DEVICE_STATE_Suspended: |
| @@ -400,7 +422,7 @@ int8_t sendchar(uint8_t c) | |||
| 400 | 422 | ||
| 401 | Endpoint_Write_8(c); | 423 | Endpoint_Write_8(c); |
| 402 | 424 | ||
| 403 | // send when packet is full | 425 | // send when bank is full |
| 404 | if (!Endpoint_IsReadWriteAllowed()) | 426 | if (!Endpoint_IsReadWriteAllowed()) |
| 405 | Endpoint_ClearIN(); | 427 | Endpoint_ClearIN(); |
| 406 | 428 | ||
