aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/testhal/NUMICRO/NUC123/NUTINY-SDK-NUC123-V2.0/USB_HID/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/testhal/NUMICRO/NUC123/NUTINY-SDK-NUC123-V2.0/USB_HID/main.c')
-rw-r--r--lib/chibios-contrib/testhal/NUMICRO/NUC123/NUTINY-SDK-NUC123-V2.0/USB_HID/main.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/lib/chibios-contrib/testhal/NUMICRO/NUC123/NUTINY-SDK-NUC123-V2.0/USB_HID/main.c b/lib/chibios-contrib/testhal/NUMICRO/NUC123/NUTINY-SDK-NUC123-V2.0/USB_HID/main.c
new file mode 100644
index 000000000..ff143e2ba
--- /dev/null
+++ b/lib/chibios-contrib/testhal/NUMICRO/NUC123/NUTINY-SDK-NUC123-V2.0/USB_HID/main.c
@@ -0,0 +1,96 @@
1/*
2 Copyright (C) 2016 Jonathan Struebel
3 Modifications copyright (C) 2020 Alex Lewontin
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16*/
17#include "hal.h"
18
19#include "usbcfg.h"
20
21/*
22 * Onboard LED blinker thread, times are in milliseconds.
23 */
24static THD_WORKING_AREA(waBlinkThread, 128);
25static THD_FUNCTION(BlinkThread, arg)
26{
27
28 (void)arg;
29
30 chRegSetThreadName("blinker");
31 while (true) {
32 systime_t time = USBD1.state == USB_ACTIVE ? 250 : 500;
33 OnboardLED_Toggle();
34 chThdSleepMilliseconds(time);
35 }
36}
37
38/*
39 * Application entry point.
40 */
41int main(void)
42{
43 /*
44 * System initializations.
45 * - HAL initialization, this also initializes the configured device drivers
46 * and performs the board-specific initializations.
47 * - Kernel initialization, the main() function becomes a thread and the
48 * RTOS is active.
49 */
50 halInit();
51 chSysInit();
52 OnboardLED_Init();
53
54 /*
55 * Turn off the onboard LED.
56 */
57 OnboardLED_Off();
58
59 chDbgSuspendTrace(CH_DBG_TRACE_MASK_SWITCH);
60 /*
61 * Initializes a USB HID driver.
62 */
63 hidObjectInit(&UHD1);
64 hidStart(&UHD1, &usbhidcfg);
65
66 /*
67 * Activates the USB driver and then the USB bus pull-up on D+.
68 * Note, a delay is inserted in order to not have to disconnect the cable
69 * after a reset.
70 */
71
72 usbDisconnectBus(usbhidcfg.usbp);
73 chThdSleepMilliseconds(1000);
74 usbStart(usbhidcfg.usbp, &usbcfg);
75 chThdSleepMilliseconds(1000);
76 usbConnectBus(usbhidcfg.usbp);
77
78 /*
79 * Creates the blinker thread.
80 */
81 chThdCreateStatic(
82 waBlinkThread, sizeof(waBlinkThread), NORMALPRIO, BlinkThread, NULL);
83
84 while (true) {
85 if (usbhidcfg.usbp->state == USB_ACTIVE) {
86 uint8_t report;
87 size_t n = hidGetReport(0, &report, sizeof(report));
88 hidWriteReport(&UHD1, &report, n);
89 n = hidReadReportt(&UHD1, &report, sizeof(report), TIME_IMMEDIATE);
90 if (n > 0)
91 hidSetReport(0, &report, n);
92 }
93
94 chThdSleepMilliseconds(1000);
95 }
96}