@@ -1094,7 +1094,9 @@ static void keyboard_idle_timer_cb(void *arg) {
1094
1094
if (keyboard_idle ) {
1095
1095
#endif /* NKRO_ENABLE */
1096
1096
/* TODO: are we sure we want the KBD_ENDPOINT? */
1097
- usbStartTransmitI (usbp , KBD_ENDPOINT , (uint8_t * )& keyboard_report_sent , sizeof (keyboard_report_sent ));
1097
+ if (!usbGetTransmitStatusI (usbp , KBD_ENDPOINT )) {
1098
+ usbStartTransmitI (usbp , KBD_ENDPOINT , (uint8_t * )& keyboard_report_sent , KBD_EPSIZE );
1099
+ }
1098
1100
/* rearm the timer */
1099
1101
chVTSetI (& keyboard_idle_timer , 4 * MS2ST (keyboard_idle ), keyboard_idle_timer_cb , (void * )usbp );
1100
1102
}
@@ -1127,8 +1129,13 @@ void send_keyboard(report_keyboard_t *report) {
1127
1129
* this is more efficient */
1128
1130
/* busy wait, should be short and not very common */
1129
1131
osalSysLock ();
1130
- while (usbGetTransmitStatusI (& USB_DRIVER , NKRO_ENDPOINT ))
1131
- ;
1132
+ if (usbGetTransmitStatusI (& USB_DRIVER , NKRO_ENDPOINT )) {
1133
+ /* Need to either suspend, or loop and call unlock/lock during
1134
+ * every iteration - otherwise the system will remain locked,
1135
+ * no interrupts served, so USB not going through as well.
1136
+ * Note: for suspend, need USB_USE_WAIT == TRUE in halconf.h */
1137
+ osalThreadSuspendS (& (& USB_DRIVER )-> epc [NKRO_ENDPOINT ]-> in_state -> thread );
1138
+ }
1132
1139
usbStartTransmitI (& USB_DRIVER , NKRO_ENDPOINT , (uint8_t * )report , sizeof (report_keyboard_t ));
1133
1140
osalSysUnlock ();
1134
1141
} else
@@ -1137,8 +1144,13 @@ void send_keyboard(report_keyboard_t *report) {
1137
1144
/* need to wait until the previous packet has made it through */
1138
1145
/* busy wait, should be short and not very common */
1139
1146
osalSysLock ();
1140
- while (usbGetTransmitStatusI (& USB_DRIVER , KBD_ENDPOINT ))
1141
- ;
1147
+ if (usbGetTransmitStatusI (& USB_DRIVER , KBD_ENDPOINT )) {
1148
+ /* Need to either suspend, or loop and call unlock/lock during
1149
+ * every iteration - otherwise the system will remain locked,
1150
+ * no interrupts served, so USB not going through as well.
1151
+ * Note: for suspend, need USB_USE_WAIT == TRUE in halconf.h */
1152
+ osalThreadSuspendS (& (& USB_DRIVER )-> epc [KBD_ENDPOINT ]-> in_state -> thread );
1153
+ }
1142
1154
usbStartTransmitI (& USB_DRIVER , KBD_ENDPOINT , (uint8_t * )report , KBD_EPSIZE );
1143
1155
osalSysUnlock ();
1144
1156
}
0 commit comments