diff options
| author | hathach <[email protected]> | 2019-04-19 13:16:06 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2019-04-19 13:16:06 +0700 |
| commit | ff8fe28c985f3059bbd0633a0f778dd6b9f5a9d1 (patch) | |
| tree | cc78edf690b4b6e97577db800267f75b47f214d5 /examples | |
| parent | 6796026476e14fc82402cdbd2dc4418f51240ae5 (diff) | |
move interface descriptor template to usbd.h, update exmaple
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/device/cdc_msc_hid/src/main.c | 64 | ||||
| -rw-r--r-- | examples/device/cdc_msc_hid/src/msc_disk.c | 1 | ||||
| -rw-r--r-- | examples/device/cdc_msc_hid/src/tusb_config.h | 3 | ||||
| -rw-r--r-- | examples/device/cdc_msc_hid/src/usb_descriptors.c | 9 | ||||
| -rw-r--r-- | examples/device/cdc_msc_hid_freertos/src/main.c | 67 | ||||
| -rw-r--r-- | examples/device/cdc_msc_hid_freertos/src/msc_disk.c | 1 | ||||
| -rw-r--r-- | examples/device/cdc_msc_hid_freertos/src/tusb_config.h | 3 | ||||
| -rw-r--r-- | examples/device/cdc_msc_hid_freertos/src/usb_descriptors.c | 9 |
8 files changed, 79 insertions, 78 deletions
diff --git a/examples/device/cdc_msc_hid/src/main.c b/examples/device/cdc_msc_hid/src/main.c index c5e7a3068..fc2f2aad0 100644 --- a/examples/device/cdc_msc_hid/src/main.c +++ b/examples/device/cdc_msc_hid/src/main.c @@ -21,7 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * - * This file is part of the TinyUSB stack. */ #include <stdlib.h> @@ -80,6 +79,38 @@ int main(void) } //--------------------------------------------------------------------+ +// Device callbacks +//--------------------------------------------------------------------+ + +// Invoked when device is mounted +void tud_mount_cb(void) +{ + blink_interval_ms = BLINK_MOUNTED; +} + +// Invoked when device is unmounted +void tud_umount_cb(void) +{ + blink_interval_ms = BLINK_NOT_MOUNTED; +} + +// Invoked when usb bus is suspended +// remote_wakeup_en : if host allow us to perform remote wakeup +// Within 7ms, device must draw an average of current less than 2.5 mA from bus +void tud_suspend_cb(bool remote_wakeup_en) +{ + (void) remote_wakeup_en; + blink_interval_ms = BLINK_SUSPENDED; +} + +// Invoked when usb bus is resumed +void tud_resume_cb(void) +{ + blink_interval_ms = BLINK_MOUNTED; +} + + +//--------------------------------------------------------------------+ // USB CDC //--------------------------------------------------------------------+ #if CFG_TUD_CDC @@ -218,37 +249,6 @@ void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uin #endif //--------------------------------------------------------------------+ -// Device callbacks -//--------------------------------------------------------------------+ - -// Invoked when device is mounted -void tud_mount_cb(void) -{ - blink_interval_ms = BLINK_MOUNTED; -} - -// Invoked when device is unmounted -void tud_umount_cb(void) -{ - blink_interval_ms = BLINK_NOT_MOUNTED; -} - -// Invoked when usb bus is suspended -// remote_wakeup_en : if host allow us to perform remote wakeup -// Within 7ms, device must draw an average of current less than 2.5 mA from bus -void tud_suspend_cb(bool remote_wakeup_en) -{ - (void) remote_wakeup_en; - blink_interval_ms = BLINK_SUSPENDED; -} - -// Invoked when usb bus is resumed -void tud_resume_cb(void) -{ - blink_interval_ms = BLINK_MOUNTED; -} - -//--------------------------------------------------------------------+ // BLINKING TASK //--------------------------------------------------------------------+ void led_blinking_task(void) diff --git a/examples/device/cdc_msc_hid/src/msc_disk.c b/examples/device/cdc_msc_hid/src/msc_disk.c index 8bcd056e3..f8f4f3cbe 100644 --- a/examples/device/cdc_msc_hid/src/msc_disk.c +++ b/examples/device/cdc_msc_hid/src/msc_disk.c @@ -21,7 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * - * This file is part of the TinyUSB stack. */ #include "bsp/board.h" diff --git a/examples/device/cdc_msc_hid/src/tusb_config.h b/examples/device/cdc_msc_hid/src/tusb_config.h index 2614bcb6f..7cea8b78f 100644 --- a/examples/device/cdc_msc_hid/src/tusb_config.h +++ b/examples/device/cdc_msc_hid/src/tusb_config.h @@ -21,7 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * - * This file is part of the TinyUSB stack. */ #ifndef _TUSB_CONFIG_H_ @@ -113,7 +112,7 @@ * This will occupies 256 bytes of ROM. It will also enable the use of extra APIs * - tud_hid_keyboard_send_char() */ -#define CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP 1 +#define CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP 0 #ifdef __cplusplus } diff --git a/examples/device/cdc_msc_hid/src/usb_descriptors.c b/examples/device/cdc_msc_hid/src/usb_descriptors.c index 28a4b28d1..c3bcc6f2b 100644 --- a/examples/device/cdc_msc_hid/src/usb_descriptors.c +++ b/examples/device/cdc_msc_hid/src/usb_descriptors.c @@ -21,7 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * - * This file is part of the TinyUSB stack. */ #include "tusb.h" @@ -68,6 +67,7 @@ tusb_desc_device_t const desc_device = }; //------------- HID Report Descriptor -------------// +#if CFG_TUD_HID enum { REPORT_ID_KEYBOARD = 1, @@ -79,6 +79,7 @@ uint8_t const desc_hid_report[] = HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(REPORT_ID_KEYBOARD), ), HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(REPORT_ID_MOUSE), ) }; +#endif //------------- Configuration Descriptor -------------// enum @@ -101,7 +102,7 @@ enum enum { - CONFIG_DESC_LEN = sizeof(tusb_desc_configuration_t) + CFG_TUD_CDC*TUD_CDC_DESC_LEN + CFG_TUD_MSC*TUD_MSC_DESC_LEN + CFG_TUD_HID*TUD_HID_DESC_LEN + CONFIG_TOTAL_LEN = TUD_CONFIG_DESC_LEN + CFG_TUD_CDC*TUD_CDC_DESC_LEN + CFG_TUD_MSC*TUD_MSC_DESC_LEN + CFG_TUD_HID*TUD_HID_DESC_LEN }; #if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX @@ -117,7 +118,7 @@ enum uint8_t const desc_configuration[] = { // Config: self-powered with remote wakeup support, max power up to 100 mA - TUD_CONFIG_DESCRIPTOR(ITF_NUM_TOTAL, 0, CONFIG_DESC_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), + TUD_CONFIG_DESCRIPTOR(ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), #if CFG_TUD_CDC TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, 0x81, 8, 0x02, 0x82, 64), @@ -167,5 +168,7 @@ tud_desc_set_t tud_desc_set = .string_arr = (uint8_t const **) string_desc_arr, .string_count = sizeof(string_desc_arr)/sizeof(string_desc_arr[0]), +#if CFG_TUD_HID .hid_report = desc_hid_report, +#endif }; diff --git a/examples/device/cdc_msc_hid_freertos/src/main.c b/examples/device/cdc_msc_hid_freertos/src/main.c index 2877cd382..f10c81d7c 100644 --- a/examples/device/cdc_msc_hid_freertos/src/main.c +++ b/examples/device/cdc_msc_hid_freertos/src/main.c @@ -21,7 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * - * This file is part of the TinyUSB stack. */ #include <stdlib.h> @@ -74,12 +73,12 @@ int main(void) // Create task #if CFG_TUD_CDC extern void cdc_task(void* params); - xTaskCreate( cdc_task, "cdc", 256, NULL, configMAX_PRIORITIES-2, NULL); + xTaskCreate( cdc_task, "cdc", 128, NULL, configMAX_PRIORITIES-2, NULL); #endif #if CFG_TUD_HID extern void hid_task(void* params); - xTaskCreate( hid_task, "hid", 256, NULL, configMAX_PRIORITIES-2, NULL); + xTaskCreate( hid_task, "hid", 128, NULL, configMAX_PRIORITIES-2, NULL); #endif vTaskStartScheduler(); @@ -103,6 +102,37 @@ void usb_device_task(void* param) } //--------------------------------------------------------------------+ +// Device callbacks +//--------------------------------------------------------------------+ + +// Invoked when device is mounted +void tud_mount_cb(void) +{ + xTimerChangePeriod(blink_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); +} + +// Invoked when usb bus is suspended +// remote_wakeup_en : if host allow us to perform remote wakeup +// Within 7ms, device must draw an average of current less than 2.5 mA from bus +void tud_suspend_cb(bool remote_wakeup_en) +{ + (void) remote_wakeup_en; + xTimerChangePeriod(blink_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); +} + +//--------------------------------------------------------------------+ // USB CDC //--------------------------------------------------------------------+ #if CFG_TUD_CDC @@ -250,37 +280,6 @@ void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uin #endif //--------------------------------------------------------------------+ -// Device callbacks -//--------------------------------------------------------------------+ - -// Invoked when device is mounted -void tud_mount_cb(void) -{ - xTimerChangePeriod(blink_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); -} - -// Invoked when usb bus is suspended -// remote_wakeup_en : if host allow us to perform remote wakeup -// Within 7ms, device must draw an average of current less than 2.5 mA from bus -void tud_suspend_cb(bool remote_wakeup_en) -{ - (void) remote_wakeup_en; - xTimerChangePeriod(blink_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); -} - -//--------------------------------------------------------------------+ // BLINKING TASK //--------------------------------------------------------------------+ void led_blinky_cb(TimerHandle_t xTimer) diff --git a/examples/device/cdc_msc_hid_freertos/src/msc_disk.c b/examples/device/cdc_msc_hid_freertos/src/msc_disk.c index 8bcd056e3..f8f4f3cbe 100644 --- a/examples/device/cdc_msc_hid_freertos/src/msc_disk.c +++ b/examples/device/cdc_msc_hid_freertos/src/msc_disk.c @@ -21,7 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * - * This file is part of the TinyUSB stack. */ #include "bsp/board.h" diff --git a/examples/device/cdc_msc_hid_freertos/src/tusb_config.h b/examples/device/cdc_msc_hid_freertos/src/tusb_config.h index 9444ca890..15f099548 100644 --- a/examples/device/cdc_msc_hid_freertos/src/tusb_config.h +++ b/examples/device/cdc_msc_hid_freertos/src/tusb_config.h @@ -21,7 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * - * This file is part of the TinyUSB stack. */ #ifndef _TUSB_CONFIG_H_ @@ -113,7 +112,7 @@ * This will occupies 256 bytes of ROM. It will also enable the use of extra APIs * - tud_hid_keyboard_send_char() */ -#define CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP 1 +#define CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP 0 #ifdef __cplusplus } diff --git a/examples/device/cdc_msc_hid_freertos/src/usb_descriptors.c b/examples/device/cdc_msc_hid_freertos/src/usb_descriptors.c index 28a4b28d1..c3bcc6f2b 100644 --- a/examples/device/cdc_msc_hid_freertos/src/usb_descriptors.c +++ b/examples/device/cdc_msc_hid_freertos/src/usb_descriptors.c @@ -21,7 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * - * This file is part of the TinyUSB stack. */ #include "tusb.h" @@ -68,6 +67,7 @@ tusb_desc_device_t const desc_device = }; //------------- HID Report Descriptor -------------// +#if CFG_TUD_HID enum { REPORT_ID_KEYBOARD = 1, @@ -79,6 +79,7 @@ uint8_t const desc_hid_report[] = HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(REPORT_ID_KEYBOARD), ), HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(REPORT_ID_MOUSE), ) }; +#endif //------------- Configuration Descriptor -------------// enum @@ -101,7 +102,7 @@ enum enum { - CONFIG_DESC_LEN = sizeof(tusb_desc_configuration_t) + CFG_TUD_CDC*TUD_CDC_DESC_LEN + CFG_TUD_MSC*TUD_MSC_DESC_LEN + CFG_TUD_HID*TUD_HID_DESC_LEN + CONFIG_TOTAL_LEN = TUD_CONFIG_DESC_LEN + CFG_TUD_CDC*TUD_CDC_DESC_LEN + CFG_TUD_MSC*TUD_MSC_DESC_LEN + CFG_TUD_HID*TUD_HID_DESC_LEN }; #if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX @@ -117,7 +118,7 @@ enum uint8_t const desc_configuration[] = { // Config: self-powered with remote wakeup support, max power up to 100 mA - TUD_CONFIG_DESCRIPTOR(ITF_NUM_TOTAL, 0, CONFIG_DESC_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), + TUD_CONFIG_DESCRIPTOR(ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), #if CFG_TUD_CDC TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, 0x81, 8, 0x02, 0x82, 64), @@ -167,5 +168,7 @@ tud_desc_set_t tud_desc_set = .string_arr = (uint8_t const **) string_desc_arr, .string_count = sizeof(string_desc_arr)/sizeof(string_desc_arr[0]), +#if CFG_TUD_HID .hid_report = desc_hid_report, +#endif }; |
