Browse Source

keyb example: change led_stats to word, workaround for USB LLD.

master
flabbergast 7 years ago
parent
commit
3c5c5e038d
  1. 3
      projects/keyb/Makefile
  2. 4
      projects/keyb/main.c
  3. 3
      projects/keyb/usb_keyboard.c
  4. 2
      projects/keyb/usb_keyboard.h
  5. 9
      projects/keyb/usb_main.c

3
projects/keyb/Makefile

@ -205,7 +205,8 @@ CPPWARN = -Wall -Wextra -Wundef @@ -205,7 +205,8 @@ CPPWARN = -Wall -Wextra -Wundef
#
# List all user C define here, like -D_DEBUG=1
UDEFS = -DNKRO_ENABLE
UDEFS =
#-DNKRO_ENABLE
# Define ASM defines here
UADEFS =

4
projects/keyb/main.c

@ -128,6 +128,8 @@ int main (void) { @@ -128,6 +128,8 @@ int main (void) {
* Main loop
*/
while(true) {
chThdSleepMilliseconds(1000);
chThdSleepMilliseconds(200);
// caps lock led status
palWritePad(GPIOC, GPIOC_LED_RED, ((keyboard_led_stats & 2) == 2));
}
}

3
projects/keyb/usb_keyboard.c

@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
uint8_t keyboard_idle = 0;
uint8_t keyboard_protocol = 1;
uint8_t keyboard_led_stats = 0;
uint16_t keyboard_led_stats = 0;
#ifdef NKRO_ENABLE
bool keyboard_nkro = true;
#endif
@ -46,7 +46,6 @@ void kbd_sof_cb(USBDriver *usbp) { @@ -46,7 +46,6 @@ void kbd_sof_cb(USBDriver *usbp) {
if(keyboard_idle) {
#endif
keyboard_idle_count++;
palWritePad(GPIOC, GPIOC_LED_RED, keyboard_led_stats & 0b10);
if(keyboard_idle_count == 4*(uint16_t)keyboard_idle) {
keyboard_idle_count = 0;
// TODO: are we sure we want the KBD_ENDPOINT?

2
projects/keyb/usb_keyboard.h

@ -29,7 +29,7 @@ @@ -29,7 +29,7 @@
extern uint8_t keyboard_idle;
extern uint8_t keyboard_protocol;
extern bool keyboard_nkro;
extern uint8_t keyboard_led_stats;
extern uint16_t keyboard_led_stats;
extern report_keyboard_t keyboard_report_sent;

9
projects/keyb/usb_main.c

@ -830,14 +830,17 @@ static bool usb_request_hook_cb(USBDriver * usbp) { @@ -830,14 +830,17 @@ static bool usb_request_hook_cb(USBDriver * usbp) {
case HID_SET_REPORT:
switch(usbp->setup[4]) { // LSB(wIndex) (check MSB==0 and wLength==1?)
case KBD_INTERFACE:
#ifdef NKRO_ENABLE
#ifdef NKRO_ENABLE // well this doesn't actually work with NKRO enabled
// because we get 2 SET_REPORTs (one for each interface)
// and reading the next byte doesn't work properly
// and fails with endpoint_busy problem.
case NKRO_INTERFACE:
#endif
// keyboard_led_stats = <read byte from next OUT report>
// this sets the correct variables for _usb_ep0setup to continue and receive the byte
// except we run into unhandled exception
// usbSetupTransfer(usbp, &keyboard_led_stats, 1, NULL);
// return TRUE;
usbSetupTransfer(usbp, (uint8_t*)&keyboard_led_stats, 1, NULL);
return TRUE;
break;
}
break;

Loading…
Cancel
Save