Skip to content

Commit 0004198

Browse files
microbit-carlosmathias-arm
authored andcommitted
Update hook to skip blinking on WebUSB HID serial traffic.
Move usbd_hid_no_activity() hook from usbd_user_hid.c to DAP_queue.c and rename it to DAP_activity_blink(). In this new location it can be used to skip HID LED blinking in traffic from USB bulk as well. Add default behaviour of skipping HID blink of DAP serial & MSD activity to the default hook for all projects. Remove customised hooks in the artemis & micro:bit projects as they are no longer needed.
1 parent 5e04123 commit 0004198

File tree

6 files changed

+21
-45
lines changed

6 files changed

+21
-45
lines changed

source/board/artemis_dk.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,6 @@ static void prerun_board_config(void)
5252
set_board_id(board_version);
5353
}
5454

55-
// USB HID override function return 1 if the activity is trivial or response is null
56-
uint8_t usbd_hid_no_activity(uint8_t *buf)
57-
{
58-
if (buf[0] == ID_DAP_Vendor3 && buf[1] == 0)
59-
return 1;
60-
else
61-
return 0;
62-
}
63-
6455
const board_info_t g_board_info = {
6556
.info_version = 0x1,
6657
.family_id = kAmbiq_ama3b1kk_FamilyID,

source/board/microbit.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,6 @@ static void prerun_board_config(void) {
6969
set_board_id(board_version);
7070
}
7171

72-
// USB HID override function return 1 if the activity is trivial or response is null
73-
uint8_t usbd_hid_no_activity(uint8_t *buf)
74-
{
75-
if(buf[0] == ID_DAP_Vendor3 && buf[1] == 0)
76-
return 1;
77-
else
78-
return 0;
79-
}
80-
8172
extern target_cfg_t target_device_nrf51822_16;
8273

8374
const board_info_t g_board_info = {

source/board/microbitv2/microbitv2.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -457,15 +457,6 @@ uint8_t board_detect_incompatible_image(const uint8_t *data, uint32_t size)
457457
return result == 0;
458458
}
459459

460-
// USB HID override function return 1 if the activity is trivial or response is null
461-
uint8_t usbd_hid_no_activity(uint8_t *buf)
462-
{
463-
if(buf[0] == ID_DAP_Vendor3 && buf[1] == 0)
464-
return 1;
465-
else
466-
return 0;
467-
}
468-
469460
// This function is called before the rest of target_set_state code, so it will
470461
// reset the micro:bit specific features state before the target state is executed
471462
static uint8_t target_set_state_microbit(target_state_t state)

source/daplink/cmsis-dap/DAP_queue.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
#include <string.h>
2323
#include "DAP_queue.h"
24+
#include "daplink_vendor_commands.h"
25+
#include "main_interface.h"
26+
2427
void DAP_queue_init(DAP_queue * queue)
2528
{
2629
queue->recv_idx = 0;
@@ -48,6 +51,20 @@ BOOL DAP_queue_get_send_buf(DAP_queue * queue, uint8_t ** buf, int * len)
4851
return (__FALSE);
4952
}
5053

54+
/*
55+
* Overridable function to determine if the DAP activity should trigger or
56+
* not the HID LED to flash.
57+
* Parameters: buf: buffer with DAP request
58+
* Return Value: 1 if DAP activity should blink the HID LED, 0 otherwise
59+
*/
60+
__WEAK uint8_t DAP_activity_blink(const uint8_t *buf)
61+
{
62+
// Skip UART and MSD DAPLink Vendor DAP commands as they already produce LED blinks
63+
return (buf[0] == ID_DAP_UART_Read ||
64+
buf[0] == ID_DAP_UART_Write ||
65+
buf[0] == ID_DAP_MSD_Write) ? 0 : 1;
66+
}
67+
5168
/*
5269
* Execute a request and store result to the DAP_queue
5370
* Parameters: queue - DAP queue, reqbuf = buffer with DAP request, len = of the request buffer, retbuf = buffer to peek on the result of the DAP operation
@@ -59,6 +76,10 @@ BOOL DAP_queue_execute_buf(DAP_queue * queue, const uint8_t *reqbuf, int len, ui
5976
{
6077
uint32_t rsize;
6178
if (queue->free_count > 0) {
79+
if (DAP_activity_blink(reqbuf)) {
80+
main_blink_hid_led(MAIN_LED_FLASH);
81+
}
82+
6283
if (len > DAP_PACKET_SIZE) {
6384
len = DAP_PACKET_SIZE;
6485
}

source/usb/bulk/usbd_bulk.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ void USBD_BULK_EP_BULKOUT_Event(U32 event)
7878
if ((DataInReceLen >= USBD_Bulk_BulkBufSize) ||
7979
(bytes_rece < usbd_bulk_maxpacketsize[USBD_HighSpeed])) {
8080
if (DAP_queue_execute_buf(&DAP_Cmd_queue, USBD_Bulk_BulkOutBuf, DataInReceLen, &rbuf)) {
81-
main_blink_hid_led(MAIN_LED_FLASH);
8281
//Trigger the BULKIn for the reply
8382
if (USB_ResponseIdle) {
8483
USBD_BULK_EP_BULKIN_Event(0);

source/usb/hid/usbd_user_hid.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
#include "DAP.h"
2929
#include "util.h"
3030
#include "DAP_queue.h"
31-
#include "daplink.h"
32-
#include DAPLINK_MAIN_HEADER
3331

3432

3533
#if (USBD_HID_OUTREPORT_MAX_SZ > DAP_PACKET_SIZE)
@@ -97,18 +95,10 @@ int usbd_hid_get_report(U8 rtype, U8 rid, U8 *buf, U8 req)
9795
return (0);
9896
}
9997

100-
// USB HID override function return 1 if the activity is trivial or response is null
101-
__attribute__((weak))
102-
uint8_t usbd_hid_no_activity(U8 *buf)
103-
{
104-
return 0;
105-
}
106-
10798
// USB HID Callback: when data is received from the host
10899
void usbd_hid_set_report(U8 rtype, U8 rid, U8 *buf, int len, U8 req)
109100
{
110101
uint8_t * rbuf;
111-
main_led_state_t led_next_state = MAIN_LED_FLASH;
112102
switch (rtype) {
113103
case HID_REPORT_OUTPUT:
114104
if (len == 0) {
@@ -122,20 +112,13 @@ void usbd_hid_set_report(U8 rtype, U8 rid, U8 *buf, int len, U8 req)
122112

123113
// execute and store to DAP_queue
124114
if (DAP_queue_execute_buf(&DAP_Cmd_queue, buf, len, &rbuf)) {
125-
if(usbd_hid_no_activity(rbuf) == 1){
126-
//revert HID LED to default if the response is null
127-
led_next_state = MAIN_LED_DEF;
128-
}
129115
if (USB_ResponseIdle) {
130116
hid_send_packet();
131117
USB_ResponseIdle = 0;
132118
}
133119
} else {
134120
util_assert(0);
135121
}
136-
137-
main_blink_hid_led(led_next_state);
138-
139122
break;
140123

141124
case HID_REPORT_FEATURE:

0 commit comments

Comments
 (0)