aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios/demos/AVR/RT-PRO-MICRO/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios/demos/AVR/RT-PRO-MICRO/main.c')
-rw-r--r--lib/chibios/demos/AVR/RT-PRO-MICRO/main.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/lib/chibios/demos/AVR/RT-PRO-MICRO/main.c b/lib/chibios/demos/AVR/RT-PRO-MICRO/main.c
new file mode 100644
index 000000000..cf26248d9
--- /dev/null
+++ b/lib/chibios/demos/AVR/RT-PRO-MICRO/main.c
@@ -0,0 +1,82 @@
1/*
2 ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#include "ch.h"
18#include "hal.h"
19#include "usbcfg.h"
20
21SerialUSBDriver SDU1;
22
23/*
24 * LED blinker thread, times are in milliseconds.
25 */
26static THD_WORKING_AREA(waThread1, 32);
27static THD_FUNCTION(Thread1, arg) {
28
29 (void)arg;
30 chRegSetThreadName("Blinker");
31 while (true) {
32 palTogglePad(IOPORT4, BOARD_LED1);
33 chThdSleepMilliseconds(1000);
34 }
35}
36
37/*
38 * Application entry point.
39 */
40int main(void) {
41
42 /*
43 * System initializations.
44 * - HAL initialization, this also initializes the configured device drivers
45 * and performs the board-specific initializations.
46 * - Kernel initialization, the main() function becomes a thread and the
47 * RTOS is active.
48 */
49 halInit();
50 chSysInit();
51
52 palSetPadMode(IOPORT4, BOARD_LED1, PAL_MODE_OUTPUT_PUSHPULL);
53 palClearPad(IOPORT4, BOARD_LED1);
54
55 /*
56 * Initializes a serial-over-USB CDC driver.
57 */
58 sduObjectInit(&SDU1);
59 sduStart(&SDU1, &serusbcfg);
60
61 /*
62 * Activates the USB driver and then the USB bus pull-up on D+.
63 * Note, a delay is inserted in order to not have to disconnect the cable
64 * after a reset.
65 */
66 usbDisconnectBus(serusbcfg.usbp);
67 chThdSleepMilliseconds(1000);
68 usbStart(serusbcfg.usbp, &usbcfg);
69 usbConnectBus(serusbcfg.usbp);
70
71 /*
72 * Starts the LED blinker thread.
73 */
74 chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
75
76 while (true) {
77 if (SDU1.config->usbp->state == USB_ACTIVE) {
78 chnWrite(&SDU1, (const uint8_t *)"Hello World!\r\n", 14);
79 }
80 chThdSleepMilliseconds(2000);
81 }
82}