diff options
author | Rasmus Schults <rasmusx@gmail.com> | 2018-04-08 00:07:26 +0300 |
---|---|---|
committer | Jack Humbert <jack.humb@gmail.com> | 2018-07-22 11:49:36 -0400 |
commit | 095b28e006e6a44d734c36f36a6ef4d6744065b5 (patch) | |
tree | 83f7fd24df747bdf3598faa387dd999655dce843 | |
parent | 8a27703ef4cc492be02e97dba49508aac89c25de (diff) |
Loop based vusb_transfer_keyboard
-rw-r--r-- | tmk_core/protocol/vusb/vusb.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index 35c0620d65..60e48c3a9c 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c @@ -27,6 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "host_driver.h" #include "vusb.h" #include "bootloader.h" +#include <util/delay.h> static uint8_t vusb_keyboard_leds = 0; @@ -46,22 +47,26 @@ typedef struct { static keyboard_report_t keyboard_report; // sent to PC +#define VUSB_TRANSFER_KEYBOARD_MAX_TRIES 10 + /* transfer keyboard report from buffer */ void vusb_transfer_keyboard(void) { - if (usbInterruptIsReady()) { - if (kbuf_head != kbuf_tail) { - usbSetInterrupt((void *)&kbuf[kbuf_tail], sizeof(report_keyboard_t)); - kbuf_tail = (kbuf_tail + 1) % KBUF_SIZE; - if (debug_keyboard) { - print("V-USB: kbuf["); pdec(kbuf_tail); print("->"); pdec(kbuf_head); print("]("); - phex((kbuf_head < kbuf_tail) ? (KBUF_SIZE - kbuf_tail + kbuf_head) : (kbuf_head - kbuf_tail)); - print(")\n"); + for (int i = 0; i < VUSB_TRANSFER_KEYBOARD_MAX_TRIES; i++) { + if (usbInterruptIsReady()) { + if (kbuf_head != kbuf_tail) { + usbSetInterrupt((void *)&kbuf[kbuf_tail], sizeof(report_keyboard_t)); + kbuf_tail = (kbuf_tail + 1) % KBUF_SIZE; + if (debug_keyboard) { + print("V-USB: kbuf["); pdec(kbuf_tail); print("->"); pdec(kbuf_head); print("]("); + phex((kbuf_head < kbuf_tail) ? (KBUF_SIZE - kbuf_tail + kbuf_head) : (kbuf_head - kbuf_tail)); + print(")\n"); + } } + break; } - } else { - usbPoll(); - vusb_transfer_keyboard(); + usbPoll(); + _delay_ms(1); } } |