Skip to content

Commit

Permalink
HID LED patch to stop flashing on UART poll
Browse files Browse the repository at this point in the history
This happens in WebUSB polling the UART for reads and the returned length 0 meaning no data
  • Loading branch information
brianesquilona committed Sep 4, 2018
1 parent 1e3eb6d commit 29a6db0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
12 changes: 11 additions & 1 deletion source/board/microbit.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
*/
#include "fsl_device_registers.h"
#include "IO_Config.h"

#include "DAP.h"
#include "RTL.h"
// URL_NAME and DRIVE_NAME must be 11 characters excluding
// the null terminated character
// Note - 4 byte alignemnt required as workaround for ARMCC compiler bug with weak references
Expand Down Expand Up @@ -76,3 +77,12 @@ void prerun_board_config(void) {
mb_version_t board_version = (mb_version_t)read_board_type_pin();
set_board_id(board_version);
}

// USB HID override function return 1 if the activity is trivial or response is null
uint8_t usbd_hid_no_activity(U8 *buf)
{
if(buf[0] == ID_DAP_Vendor3 && buf[1] == 0)
return 1;
else
return 0;
}
16 changes: 14 additions & 2 deletions source/daplink/cmsis-dap/usbd_user_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,17 @@ int usbd_hid_get_report(U8 rtype, U8 rid, U8 *buf, U8 req)
return (0);
}

// USB HID override function return 1 if the activity is trivial or response is null
__attribute__((weak))
uint8_t usbd_hid_no_activity(U8 *buf)
{
return 0;
}

// USB HID Callback: when data is received from the host
void usbd_hid_set_report(U8 rtype, U8 rid, U8 *buf, int len, U8 req)
{
main_led_state_t led_next_state = MAIN_LED_FLASH;
switch (rtype) {
case HID_REPORT_OUTPUT:
if (len == 0) {
Expand All @@ -123,6 +131,10 @@ void usbd_hid_set_report(U8 rtype, U8 rid, U8 *buf, int len, U8 req)
free_count--;
memcpy(USB_Request[recv_idx], buf, len);
DAP_ExecuteCommand(buf, USB_Request[recv_idx]);
if(usbd_hid_no_activity(USB_Request[recv_idx]) == 1){
//revert HID LED to default if the response is null
led_next_state = MAIN_LED_DEF;
}
recv_idx = (recv_idx + 1) % DAP_PACKET_COUNT;
send_count++;
if (USB_ResponseIdle) {
Expand All @@ -132,8 +144,8 @@ void usbd_hid_set_report(U8 rtype, U8 rid, U8 *buf, int len, U8 req)
} else {
util_assert(0);
}

main_blink_hid_led(MAIN_LED_FLASH);
main_blink_hid_led(led_next_state);

break;

Expand Down

0 comments on commit 29a6db0

Please sign in to comment.