/
main.cpp
44 lines (37 loc) · 967 Bytes
/
main.cpp
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
/*
* Copyright (c) 2006-2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include "mbed.h"
#include "drivers/USBHID.h"
// Declare a USBHID device
USBHID HID(8, 8, 0x1234, 0x0006, 0x0001, true);
HID_REPORT output_report = {
.length = 8,
.data = {0}
};
HID_REPORT input_report = {
.length = 0,
.data = {0}
};
DigitalOut led_out(LED1);
int main(void)
{
while (1) {
// Fill the report
for (int i = 0; i < output_report.length; i++) {
output_report.data[i] = rand() & UINT8_MAX;
}
// Send the report
HID.send(&output_report);
// Try to read a msg
if (HID.read_nb(&input_report)) {
led_out = !led_out;
for (int i = 0; i < input_report.length; i++) {
printf("%d ", input_report.data[i]);
}
printf("\r\n");
}
}
}