aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/protocol/vusb/vusb.c
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/protocol/vusb/vusb.c')
-rw-r--r--tmk_core/protocol/vusb/vusb.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c
index 35c0620d6..60e48c3a9 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/>.
27#include "host_driver.h" 27#include "host_driver.h"
28#include "vusb.h" 28#include "vusb.h"
29#include "bootloader.h" 29#include "bootloader.h"
30#include <util/delay.h>
30 31
31 32
32static uint8_t vusb_keyboard_leds = 0; 33static uint8_t vusb_keyboard_leds = 0;
@@ -46,22 +47,26 @@ typedef struct {
46 47
47static keyboard_report_t keyboard_report; // sent to PC 48static keyboard_report_t keyboard_report; // sent to PC
48 49
50#define VUSB_TRANSFER_KEYBOARD_MAX_TRIES 10
51
49/* transfer keyboard report from buffer */ 52/* transfer keyboard report from buffer */
50void vusb_transfer_keyboard(void) 53void vusb_transfer_keyboard(void)
51{ 54{
52 if (usbInterruptIsReady()) { 55 for (int i = 0; i < VUSB_TRANSFER_KEYBOARD_MAX_TRIES; i++) {
53 if (kbuf_head != kbuf_tail) { 56 if (usbInterruptIsReady()) {
54 usbSetInterrupt((void *)&kbuf[kbuf_tail], sizeof(report_keyboard_t)); 57 if (kbuf_head != kbuf_tail) {
55 kbuf_tail = (kbuf_tail + 1) % KBUF_SIZE; 58 usbSetInterrupt((void *)&kbuf[kbuf_tail], sizeof(report_keyboard_t));
56 if (debug_keyboard) { 59 kbuf_tail = (kbuf_tail + 1) % KBUF_SIZE;
57 print("V-USB: kbuf["); pdec(kbuf_tail); print("->"); pdec(kbuf_head); print("]("); 60 if (debug_keyboard) {
58 phex((kbuf_head < kbuf_tail) ? (KBUF_SIZE - kbuf_tail + kbuf_head) : (kbuf_head - kbuf_tail)); 61 print("V-USB: kbuf["); pdec(kbuf_tail); print("->"); pdec(kbuf_head); print("](");
59 print(")\n"); 62 phex((kbuf_head < kbuf_tail) ? (KBUF_SIZE - kbuf_tail + kbuf_head) : (kbuf_head - kbuf_tail));
63 print(")\n");
64 }
60 } 65 }
66 break;
61 } 67 }
62 } else { 68 usbPoll();
63 usbPoll(); 69 _delay_ms(1);
64 vusb_transfer_keyboard();
65 } 70 }
66} 71}
67 72