1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
diff --git a/firmware/usbstack/usb_hid.c b/firmware/usbstack/usb_hid.c
index 213f971..46baff8 100644
--- a/firmware/usbstack/usb_hid.c
+++ b/firmware/usbstack/usb_hid.c
@@ -829,19 +786,19 @@ static void usb_hid_queue(unsigned char *data, int length)
 
 void usb_hid_send(usage_page_t usage_page, int id)
 {
-    uint8_t report_id, length;
+    uint8_t length;
     static unsigned char buf[HID_BUF_SIZE_CMD] USB_DEVBSS_ATTR
         __attribute__((aligned(32)));
     usb_hid_report_t *report = NULL;
 
-    for (report_id = 1; report_id < REPORT_ID_COUNT; report_id++)
-    {
+    for (uint8_t report_id = 1; report_id < REPORT_ID_COUNT; report_id++)
         if (usb_hid_reports[report_id].usage_page == usage_page)
         {
             report = &usb_hid_reports[report_id];
+            buf[0] = report_id;
             break;
         }
-    }
+
     if (!report)
     {
         logf("Unsupported usage_page");
@@ -849,7 +806,6 @@ void usb_hid_send(usage_page_t usage_page, int id)
     }
 
     logf("Sending cmd 0x%x", id);
-    buf[0] = report_id;
     length = report->buf_set(&buf[1], id) + 1;
     logf("length %u", length);
 
@@ -863,8 +819,7 @@ void usb_hid_send(usage_page_t usage_page, int id)
     if (report->is_key_released)
     {
         /* Key released */
-        memset(buf, 0, length);
-        buf[0] = report_id;
+        memset(&buf[1], 0, length-1);
 
         buf_dump(buf, length, "key release");
         usb_hid_queue(buf, length);