summaryrefslogtreecommitdiff
path: root/examples/device/dynamic_configuration/src
diff options
context:
space:
mode:
authorhathach <[email protected]>2020-06-15 23:34:09 +0700
committerhathach <[email protected]>2020-06-15 23:34:09 +0700
commitc67b3a242e8873788e32bbb589836e265e8a9b53 (patch)
tree6d876fce67280b050d74dbfbdc662c0a3a6fcea6 /examples/device/dynamic_configuration/src
parent2dd1be13e5780509cc6ab4e5877dd8c4ffe77e45 (diff)
update example config and descriptor with better Highspeed support
Diffstat (limited to 'examples/device/dynamic_configuration/src')
-rw-r--r--examples/device/dynamic_configuration/src/tusb_config.h31
-rw-r--r--examples/device/dynamic_configuration/src/usb_descriptors.c4
2 files changed, 27 insertions, 8 deletions
diff --git a/examples/device/dynamic_configuration/src/tusb_config.h b/examples/device/dynamic_configuration/src/tusb_config.h
index 958a446ac..0950305eb 100644
--- a/examples/device/dynamic_configuration/src/tusb_config.h
+++ b/examples/device/dynamic_configuration/src/tusb_config.h
@@ -34,19 +34,38 @@
// COMMON CONFIGURATION
//--------------------------------------------------------------------
-// defined by compiler flags for flexibility
+// defined by board.mk
#ifndef CFG_TUSB_MCU
#error CFG_TUSB_MCU must be defined
#endif
-#if CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \
- CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56
- #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED)
+// RHPort number used for device can be defined by board.mk, default to port 0
+#ifndef BOARD_DEVICE_RHPORT_NUM
+ #define BOARD_DEVICE_RHPORT_NUM 0
+#endif
+
+// RHPort max operational speed can defined by board.mk
+// Default to Highspeed for MCU with internal HighSpeed PHY (can be port specific), otherwise FullSpeed
+#ifndef BOARD_DEVICE_RHPORT_SPEED
+ #if (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \
+ CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56)
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_HIGH_SPEED
+ #else
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED
+ #endif
+#endif
+
+// Device mode with rhport and speed defined by board.mk
+#if BOARD_DEVICE_RHPORT_NUM == 0
+ #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#elif BOARD_DEVICE_RHPORT_NUM == 1
+ #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
#else
- #define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
+ #error "Incorrect RHPort configuration"
#endif
-#define CFG_TUSB_OS OPT_OS_NONE
+// This example doesn't use an RTOS
+#define CFG_TUSB_OS OPT_OS_NONE
// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
// #define CFG_TUSB_DEBUG 0
diff --git a/examples/device/dynamic_configuration/src/usb_descriptors.c b/examples/device/dynamic_configuration/src/usb_descriptors.c
index 63468b496..a2017f954 100644
--- a/examples/device/dynamic_configuration/src/usb_descriptors.c
+++ b/examples/device/dynamic_configuration/src/usb_descriptors.c
@@ -166,7 +166,7 @@ uint8_t const desc_configuration_0[] =
TUD_CDC_DESCRIPTOR(ITF_0_NUM_CDC, 0, EPNUM_0_CDC_NOTIF, 8, EPNUM_0_CDC_OUT, EPNUM_0_CDC_IN, 64),
// Interface number, string index, EP Out & EP In address, EP size
- TUD_MIDI_DESCRIPTOR(ITF_0_NUM_MIDI, 0, EPNUM_0_MIDI_OUT, EPNUM_0_MIDI_IN, (CFG_TUSB_RHPORT0_MODE & OPT_MODE_HIGH_SPEED) ? 512 : 64),
+ TUD_MIDI_DESCRIPTOR(ITF_0_NUM_MIDI, 0, EPNUM_0_MIDI_OUT, EPNUM_0_MIDI_IN, TUD_OPT_HIGH_SPEED ? 512 : 64),
};
@@ -176,7 +176,7 @@ uint8_t const desc_configuraiton_1[] =
TUD_CONFIG_DESCRIPTOR(1, ITF_1_NUM_TOTAL, 0, CONFIG_1_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
// Interface number, string index, EP Out & EP In address, EP size
- TUD_MSC_DESCRIPTOR(ITF_1_NUM_MSC, 0, EPNUM_1_MSC_OUT, EPNUM_1_MSC_IN, (CFG_TUSB_RHPORT0_MODE & OPT_MODE_HIGH_SPEED) ? 512 : 64),
+ TUD_MSC_DESCRIPTOR(ITF_1_NUM_MSC, 0, EPNUM_1_MSC_OUT, EPNUM_1_MSC_IN, TUD_OPT_HIGH_SPEED ? 512 : 64),
};