12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #include "ch.h"
- #include "hal.h"
- #include "usbcfg.h"
- SerialUSBDriver SDU1;
- static THD_WORKING_AREA(waThread1, 32);
- static THD_FUNCTION(Thread1, arg) {
- (void)arg;
- chRegSetThreadName("Blinker");
- while (true) {
- palTogglePad(IOPORT3, BOARD_LED1);
- chThdSleepMilliseconds(500);
- }
- }
- int main(void) {
-
- halInit();
- chSysInit();
- palSetPadMode(IOPORT3, BOARD_LED1, PAL_MODE_OUTPUT_PUSHPULL);
- palClearPad(IOPORT3, BOARD_LED1);
-
- sduObjectInit(&SDU1);
- sduStart(&SDU1, &serusbcfg);
-
- usbDisconnectBus(serusbcfg.usbp);
- chThdSleepMilliseconds(1000);
- usbStart(serusbcfg.usbp, &usbcfg);
- usbConnectBus(serusbcfg.usbp);
-
- chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
- while (true) {
- if (SDU1.config->usbp->state == USB_ACTIVE) {
- chnWrite(&SDU1, (const uint8_t *)"Hello from Arduino Leonardo!\r\n", 30);
- }
- chThdSleepMilliseconds(2113);
- }
- }
|