summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2022-06-06 23:16:49 +0700
committerhathach <[email protected]>2022-06-06 23:16:49 +0700
commit7c8278303bc14770ea9fcd9f6e4a9dbba32572e3 (patch)
treedddfac5e4042638632d7187835733cde2a911029
parent9794a2b865df81e667b464481bb9b1c70587e64b (diff)
update all host examples
-rw-r--r--examples/dual/host_hid_to_device_cdc/src/main.c4
-rw-r--r--examples/dual/host_hid_to_device_cdc/src/tusb_config.h88
-rw-r--r--examples/host/bare_api/src/main.c6
-rw-r--r--examples/host/bare_api/src/tusb_config.h33
-rw-r--r--examples/host/cdc_msc_hid/src/main.c3
-rw-r--r--examples/host/cdc_msc_hid/src/tusb_config.h40
-rw-r--r--examples/host/hid_controller/src/main.c5
-rw-r--r--examples/host/hid_controller/src/tusb_config.h33
-rw-r--r--src/tusb_option.h8
9 files changed, 129 insertions, 91 deletions
diff --git a/examples/dual/host_hid_to_device_cdc/src/main.c b/examples/dual/host_hid_to_device_cdc/src/main.c
index 62ecb2c3f..6a25a28da 100644
--- a/examples/dual/host_hid_to_device_cdc/src/main.c
+++ b/examples/dual/host_hid_to_device_cdc/src/main.c
@@ -79,7 +79,9 @@ int main(void)
printf("TinyUSB Host HID <-> Device CDC Example\r\n");
- tusb_init();
+ // init device and host stack on configured roothub port
+ tud_init(BOARD_TUD_RHPORT);
+ tuh_init(BOARD_TUH_RHPORT);
while (1)
{
diff --git a/examples/dual/host_hid_to_device_cdc/src/tusb_config.h b/examples/dual/host_hid_to_device_cdc/src/tusb_config.h
index 9a8f31da0..f749bd712 100644
--- a/examples/dual/host_hid_to_device_cdc/src/tusb_config.h
+++ b/examples/dual/host_hid_to_device_cdc/src/tusb_config.h
@@ -30,75 +30,61 @@
extern "C" {
#endif
-//--------------------------------------------------------------------
-// COMMON CONFIGURATION
-//--------------------------------------------------------------------
-
-// defined by board.mk
-#ifndef CFG_TUSB_MCU
- #error CFG_TUSB_MCU must be defined
-#endif
+//--------------------------------------------------------------------+
+// Board Specific Configuration
+//--------------------------------------------------------------------+
// RHPort number used for device can be defined by board.mk, default to port 0
#ifndef BOARD_TUD_RHPORT
- #define BOARD_TUD_RHPORT 0
+#define BOARD_TUD_RHPORT 0
#endif
-// RHPort number used for device can be defined by board.mk, default to port 1
-#ifndef BOARD_TUH_RHPORT
- #define BOARD_TUH_RHPORT 1
-#endif
-
-// Use raspberry pio-usb for host
-#define CFG_TUH_RPI_PIO_USB 1
-
// 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_TUD_MAX_SPEED
- #if TU_CHECK_MCU(OPT_MCU_LPC18XX, OPT_MCU_LPC43XX, OPT_MCU_MIMXRT10XX, OPT_MCU_NUC505) ||\
- TU_CHECK_MCU(OPT_MCU_CXD56, OPT_MCU_SAMX7X, OPT_MCU_BCM2711) ||\
- TU_CHECK_MCU(OPT_MCU_FT90X, OPT_MCU_FT93X)
- #define BOARD_TUD_MAX_SPEED OPT_MODE_HIGH_SPEED
- #else
- #define BOARD_TUD_MAX_SPEED OPT_MODE_FULL_SPEED
- #endif
+#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
+#endif
+
+// RHPort number used for host can be defined by board.mk, default to port 1
+#ifndef BOARD_TUH_RHPORT
+#define BOARD_TUH_RHPORT 1
#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_TUH_MAX_SPEED
- #if TU_CHECK_MCU(OPT_MCU_LPC18XX, OPT_MCU_LPC43XX, OPT_MCU_MIMXRT10XX, OPT_MCU_NUC505) ||\
- TU_CHECK_MCU(OPT_MCU_CXD56, OPT_MCU_SAMX7X, OPT_MCU_BCM2711) ||\
- TU_CHECK_MCU(OPT_MCU_FT90X, OPT_MCU_FT93X)
- #define BOARD_TUH_MAX_SPEED OPT_MODE_HIGH_SPEED
- #else
- #define BOARD_TUH_MAX_SPEED OPT_MODE_FULL_SPEED
- #endif
+#define BOARD_TUH_MAX_SPEED OPT_MODE_DEFAULT_SPEED
#endif
-// Device mode with rhport and speed defined by board.mk
-#if BOARD_TUD_RHPORT == 0
- #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_TUD_MAX_SPEED)
-#elif BOARD_TUD_RHPORT == 1
- #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | BOARD_TUD_MAX_SPEED)
-#else
- #error "Incorrect RHPort configuration"
-#endif
+//--------------------------------------------------------------------
+// COMMON CONFIGURATION
+//--------------------------------------------------------------------
-// Device mode with rhport and speed defined by board.mk
-#if BOARD_TUH_RHPORT == 0
- #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_HOST | BOARD_TUH_MAX_SPEED)
-#elif BOARD_TUH_RHPORT == 1
- #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_HOST | BOARD_TUH_MAX_SPEED)
-#else
- #error "Incorrect RHPort configuration"
+// defined by compiler flags for flexibility
+#ifndef CFG_TUSB_MCU
+#error CFG_TUSB_MCU must be defined
#endif
-// This example doesn't use an RTOS
#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
+#define CFG_TUSB_OS OPT_OS_NONE
+#endif
+
+#ifndef CFG_TUSB_DEBUG
+#define CFG_TUSB_DEBUG 0
+#endif
+
+// Enable Device stack, Default is max speed that hardware controller could support with on-chip PHY
+#define CFG_TUD_ENABLED 1
+#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
+
+// Enable Host stack, Default is max speed that hardware controller could support with on-chip PHY
+#define CFG_TUH_ENABLED 1
+#define CFG_TUH_MAX_SPEED BOARD_TUH_MAX_SPEED
+
+#if CFG_TUSB_MCU == OPT_MCU_RP2040
+// Use pico-pio-usb as host controller for raspberry rp2040
+#define CFG_TUH_RPI_PIO_USB 1
#endif
+
// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
// #define CFG_TUSB_DEBUG 0
@@ -114,7 +100,7 @@
#endif
#ifndef CFG_TUSB_MEM_ALIGN
-#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
+#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
#endif
//--------------------------------------------------------------------
diff --git a/examples/host/bare_api/src/main.c b/examples/host/bare_api/src/main.c
index eb3f7d8d7..2cc05d34d 100644
--- a/examples/host/bare_api/src/main.c
+++ b/examples/host/bare_api/src/main.c
@@ -62,8 +62,10 @@ int main(void)
{
board_init();
- printf("TinyUSB Host HID Controller Example\r\n");
- tusb_init();
+ printf("TinyUSB Bare API Example\r\n");
+
+ // init host stack on configured roothub port
+ tuh_init(BOARD_TUH_RHPORT);
while (1)
{
diff --git a/examples/host/bare_api/src/tusb_config.h b/examples/host/bare_api/src/tusb_config.h
index 9b789290d..ed0aaf7da 100644
--- a/examples/host/bare_api/src/tusb_config.h
+++ b/examples/host/bare_api/src/tusb_config.h
@@ -30,27 +30,42 @@
extern "C" {
#endif
+//--------------------------------------------------------------------+
+// Board Specific Configuration
+//--------------------------------------------------------------------+
+
+// RHPort number used for host can be defined by board.mk, default to port 0
+#ifndef BOARD_TUH_RHPORT
+#define BOARD_TUH_RHPORT 0
+#endif
+
+// RHPort max operational speed can defined by board.mk
+#ifndef BOARD_TUH_MAX_SPEED
+#define BOARD_TUH_MAX_SPEED OPT_MODE_DEFAULT_SPEED
+#endif
+
//--------------------------------------------------------------------
// COMMON CONFIGURATION
//--------------------------------------------------------------------
// defined by compiler flags for flexibility
#ifndef CFG_TUSB_MCU
- #error CFG_TUSB_MCU must be defined
+#error CFG_TUSB_MCU must be defined
#endif
-#if CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX
- #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_HOST | OPT_MODE_HIGH_SPEED)
-#else
- #define CFG_TUSB_RHPORT0_MODE OPT_MODE_HOST
+#ifndef CFG_TUSB_OS
+#define CFG_TUSB_OS OPT_OS_NONE
#endif
-#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
+#ifndef CFG_TUSB_DEBUG
+#define CFG_TUSB_DEBUG 0
#endif
-// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
-// #define CFG_TUSB_DEBUG 0
+// Enable Host stack
+#define CFG_TUH_ENABLED 1
+
+// Default is max speed that hardware controller could support with on-chip PHY
+#define CFG_TUH_MAX_SPEED BOARD_TUH_MAX_SPEED
/* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment.
* Tinyusb use follows macros to declare transferring memory so that they can be put
diff --git a/examples/host/cdc_msc_hid/src/main.c b/examples/host/cdc_msc_hid/src/main.c
index 0fc7ef146..664cbf035 100644
--- a/examples/host/cdc_msc_hid/src/main.c
+++ b/examples/host/cdc_msc_hid/src/main.c
@@ -45,7 +45,8 @@ int main(void)
printf("TinyUSB Host CDC MSC HID Example\r\n");
- tusb_init();
+ // init host stack on configured roothub port
+ tuh_init(BOARD_TUH_RHPORT);
while (1)
{
diff --git a/examples/host/cdc_msc_hid/src/tusb_config.h b/examples/host/cdc_msc_hid/src/tusb_config.h
index e9e68cf5a..76d96b556 100644
--- a/examples/host/cdc_msc_hid/src/tusb_config.h
+++ b/examples/host/cdc_msc_hid/src/tusb_config.h
@@ -30,34 +30,42 @@
extern "C" {
#endif
+//--------------------------------------------------------------------+
+// Board Specific Configuration
+//--------------------------------------------------------------------+
+
+// RHPort number used for host can be defined by board.mk, default to port 0
+#ifndef BOARD_TUH_RHPORT
+#define BOARD_TUH_RHPORT 0
+#endif
+
+// RHPort max operational speed can defined by board.mk
+#ifndef BOARD_TUH_MAX_SPEED
+#define BOARD_TUH_MAX_SPEED OPT_MODE_DEFAULT_SPEED
+#endif
+
//--------------------------------------------------------------------
// COMMON CONFIGURATION
//--------------------------------------------------------------------
// defined by compiler flags for flexibility
#ifndef CFG_TUSB_MCU
- #error CFG_TUSB_MCU must be defined
+#error CFG_TUSB_MCU must be defined
#endif
-// Use raspberry pio-usb for host
-// #define CFG_TUH_RPI_PIO_USB 1
-// #define CFG_TUH_RPI_PIO_USB 1
-
-#if CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX
- #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_HOST | OPT_MODE_HIGH_SPEED)
-#elif defined(CFG_TUH_RPI_PIO_USB) && CFG_TUH_RPI_PIO_USB
- // rp2040: port0 is native, port 1 for PIO-USB
- #define CFG_TUSB_RHPORT1_MODE OPT_MODE_HOST
-#else
- #define CFG_TUSB_RHPORT0_MODE OPT_MODE_HOST
+#ifndef CFG_TUSB_OS
+#define CFG_TUSB_OS OPT_OS_NONE
#endif
-#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
+#ifndef CFG_TUSB_DEBUG
+#define CFG_TUSB_DEBUG 0
#endif
-// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
-// #define CFG_TUSB_DEBUG 0
+// Enable Host stack
+#define CFG_TUH_ENABLED 1
+
+// Default is max speed that hardware controller could support with on-chip PHY
+#define CFG_TUH_MAX_SPEED BOARD_TUH_MAX_SPEED
/* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment.
* Tinyusb use follows macros to declare transferring memory so that they can be put
diff --git a/examples/host/hid_controller/src/main.c b/examples/host/hid_controller/src/main.c
index b9b37a4d2..299a3ff10 100644
--- a/examples/host/hid_controller/src/main.c
+++ b/examples/host/hid_controller/src/main.c
@@ -49,9 +49,10 @@ int main(void)
board_init();
printf("TinyUSB Host HID Controller Example\r\n");
- printf("Note: Events only displayed for explictly supported controllers\r\n");
+ printf("Note: Events only displayed for explicit supported controllers\r\n");
- tusb_init();
+ // init host stack on configured roothub port
+ tuh_init(BOARD_TUH_RHPORT);
while (1)
{
diff --git a/examples/host/hid_controller/src/tusb_config.h b/examples/host/hid_controller/src/tusb_config.h
index 74b471ae4..475b9ca8f 100644
--- a/examples/host/hid_controller/src/tusb_config.h
+++ b/examples/host/hid_controller/src/tusb_config.h
@@ -30,27 +30,42 @@
extern "C" {
#endif
+//--------------------------------------------------------------------+
+// Board Specific Configuration
+//--------------------------------------------------------------------+
+
+// RHPort number used for host can be defined by board.mk, default to port 0
+#ifndef BOARD_TUH_RHPORT
+#define BOARD_TUH_RHPORT 0
+#endif
+
+// RHPort max operational speed can defined by board.mk
+#ifndef BOARD_TUH_MAX_SPEED
+#define BOARD_TUH_MAX_SPEED OPT_MODE_DEFAULT_SPEED
+#endif
+
//--------------------------------------------------------------------
// COMMON CONFIGURATION
//--------------------------------------------------------------------
// defined by compiler flags for flexibility
#ifndef CFG_TUSB_MCU
- #error CFG_TUSB_MCU must be defined
+#error CFG_TUSB_MCU must be defined
#endif
-#if CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX
- #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_HOST | OPT_MODE_HIGH_SPEED)
-#else
- #define CFG_TUSB_RHPORT0_MODE OPT_MODE_HOST
+#ifndef CFG_TUSB_OS
+#define CFG_TUSB_OS OPT_OS_NONE
#endif
-#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
+#ifndef CFG_TUSB_DEBUG
+#define CFG_TUSB_DEBUG 0
#endif
-// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
-// #define CFG_TUSB_DEBUG 0
+// Enable Host stack
+#define CFG_TUH_ENABLED 1
+
+// Default is max speed that hardware controller could support with on-chip PHY
+#define CFG_TUH_MAX_SPEED BOARD_TUH_MAX_SPEED
/* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment.
* Tinyusb use follows macros to declare transferring memory so that they can be put
diff --git a/src/tusb_option.h b/src/tusb_option.h
index 0a0b20dca..e332c5728 100644
--- a/src/tusb_option.h
+++ b/src/tusb_option.h
@@ -238,11 +238,19 @@ typedef int make_iso_compilers_happy ;
#define CFG_TUH_ENABLED (TUH_RHPORT_MODE & OPT_MODE_HOST)
#endif
+#ifndef CFG_TUH_MAX_SPEED
+ // fallback to use CFG_TUSB_RHPORTx_MODE
+ #define CFG_TUH_MAX_SPEED (TUH_RHPORT_MODE & OPT_MODE_SPEED_MASK)
+#endif
+
// For backward compatible
#define TUSB_OPT_DEVICE_ENABLED CFG_TUD_ENABLED
#define TUSB_OPT_HOST_ENABLED CFG_TUH_ENABLED
+//--------------------------------------------------------------------+
// TODO move later
+//--------------------------------------------------------------------+
+
// TUP_MCU_STRICT_ALIGN will overwrite TUP_ARCH_STRICT_ALIGN.
// In case TUP_MCU_STRICT_ALIGN = 1 and TUP_ARCH_STRICT_ALIGN =0, we will not reply on compiler
// to generate unaligned access code.