summaryrefslogtreecommitdiff
path: root/examples/device
diff options
context:
space:
mode:
authorhathach <[email protected]>2020-04-07 15:34:05 +0700
committerhathach <[email protected]>2020-04-07 16:05:04 +0700
commit73941137481e64897ee18fe63a7829dbed9af9d5 (patch)
tree80653827ca28dd3b6b205af587daea9b36896df6 /examples/device
parent3c724251f01300601e197f7b6646a5968b1d98df (diff)
example clean up
Diffstat (limited to 'examples/device')
-rw-r--r--examples/device/cdc_msc_freertos/src/main.c41
-rw-r--r--examples/device/cdc_msc_freertos/src/usb_descriptors.h34
-rw-r--r--examples/device/hid_composite/src/main.c1
3 files changed, 21 insertions, 55 deletions
diff --git a/examples/device/cdc_msc_freertos/src/main.c b/examples/device/cdc_msc_freertos/src/main.c
index 350358a68..d7217f964 100644
--- a/examples/device/cdc_msc_freertos/src/main.c
+++ b/examples/device/cdc_msc_freertos/src/main.c
@@ -52,18 +52,18 @@ enum {
};
// static timer
-StaticTimer_t static_blink;
-TimerHandle_t blink_tm;
+StaticTimer_t blinky_tmdef;
+TimerHandle_t blinky_tm;
// static task for usbd
#define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2)
-StackType_t stack_usbd[USBD_STACK_SIZE];
-StaticTask_t static_task_usbd;
+StackType_t usb_device_stack[USBD_STACK_SIZE];
+StaticTask_t usb_device_taskdef;
// static task for cdc
#define CDC_STACK_SZIE configMINIMAL_STACK_SIZE
-StackType_t stack_cdc[CDC_STACK_SZIE];
-StaticTask_t static_task_cdc;
+StackType_t cdc_stack[CDC_STACK_SZIE];
+StaticTask_t cdc_taskdef;
void led_blinky_cb(TimerHandle_t xTimer);
@@ -71,25 +71,20 @@ void usb_device_task(void* param);
void cdc_task(void* params);
/*------------- MAIN -------------*/
-#if CFG_TUSB_MCU == OPT_MCU_ESP32S2
-void app_main(void)
-#else
int main(void)
-#endif
{
board_init();
+ tusb_init();
// soft timer for blinky
- blink_tm = xTimerCreateStatic(NULL, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), true, NULL, led_blinky_cb, &static_blink);
- xTimerStart(blink_tm, 0);
-
- tusb_init();
+ blinky_tm = xTimerCreateStatic(NULL, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), true, NULL, led_blinky_cb, &blinky_tmdef);
+ xTimerStart(blinky_tm, 0);
// Create a task for tinyusb device stack
- (void) xTaskCreateStatic( usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, stack_usbd, &static_task_usbd);
+ (void) xTaskCreateStatic( usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_device_stack, &usb_device_taskdef);
// Create CDC task
- (void) xTaskCreateStatic( cdc_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES-2, stack_cdc, &static_task_cdc);
+ (void) xTaskCreateStatic( cdc_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES-2, cdc_stack, &cdc_taskdef);
// skip starting scheduler (and return) for ESP32-S2
#if CFG_TUSB_MCU != OPT_MCU_ESP32S2
@@ -97,8 +92,14 @@ int main(void)
NVIC_SystemReset();
return 0;
#endif
+}
+#if CFG_TUSB_MCU == OPT_MCU_ESP32S2
+void app_main(void)
+{
+ main();
}
+#endif
// USB Device Driver task
// This top level thread process all usb events and invoke callbacks
@@ -121,13 +122,13 @@ void usb_device_task(void* param)
// Invoked when device is mounted
void tud_mount_cb(void)
{
- xTimerChangePeriod(blink_tm, pdMS_TO_TICKS(BLINK_MOUNTED), 0);
+ xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_MOUNTED), 0);
}
// Invoked when device is unmounted
void tud_umount_cb(void)
{
- xTimerChangePeriod(blink_tm, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), 0);
+ xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), 0);
}
// Invoked when usb bus is suspended
@@ -136,13 +137,13 @@ void tud_umount_cb(void)
void tud_suspend_cb(bool remote_wakeup_en)
{
(void) remote_wakeup_en;
- xTimerChangePeriod(blink_tm, pdMS_TO_TICKS(BLINK_SUSPENDED), 0);
+ xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_SUSPENDED), 0);
}
// Invoked when usb bus is resumed
void tud_resume_cb(void)
{
- xTimerChangePeriod(blink_tm, pdMS_TO_TICKS(BLINK_MOUNTED), 0);
+ xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_MOUNTED), 0);
}
diff --git a/examples/device/cdc_msc_freertos/src/usb_descriptors.h b/examples/device/cdc_msc_freertos/src/usb_descriptors.h
deleted file mode 100644
index 6992d3349..000000000
--- a/examples/device/cdc_msc_freertos/src/usb_descriptors.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef USB_DESCRIPTORS_H_
-#define USB_DESCRIPTORS_H_
-
-enum
-{
- REPORT_ID_KEYBOARD = 1,
- REPORT_ID_MOUSE
-};
-
-#endif /* USB_DESCRIPTORS_H_ */
diff --git a/examples/device/hid_composite/src/main.c b/examples/device/hid_composite/src/main.c
index 4529e24f1..7207e4d4c 100644
--- a/examples/device/hid_composite/src/main.c
+++ b/examples/device/hid_composite/src/main.c
@@ -56,7 +56,6 @@ void hid_task(void);
int main(void)
{
board_init();
-
tusb_init();
while (1)