diff --git a/demos/host/tusb_config.h b/demos/host/tusb_config.h index f482e333b..1b0015dbf 100644 --- a/demos/host/tusb_config.h +++ b/demos/host/tusb_config.h @@ -58,13 +58,12 @@ //--------------------------------------------------------------------+ // CONTROLLER CONFIGURATION //--------------------------------------------------------------------+ -#define TUSB_CFG_CONTROLLER0_MODE TUSB_MODE_HOST -#define TUSB_CFG_CONTROLLER1_MODE TUSB_MODE_HOST +#define TUSB_CFG_CONTROLLER0_MODE (TUSB_MODE_HOST) +#define TUSB_CFG_CONTROLLER1_MODE (TUSB_MODE_HOST) //--------------------------------------------------------------------+ // HOST CONFIGURATION //--------------------------------------------------------------------+ -#define TUSB_CFG_HOST //------------- CONTROLLER -------------// #define TUSB_CFG_HOST_CONTROLLER_START_INDEX 0 diff --git a/tests/test/support/tusb_config.h b/tests/test/support/tusb_config.h index cf0566133..430f7e031 100644 --- a/tests/test/support/tusb_config.h +++ b/tests/test/support/tusb_config.h @@ -64,8 +64,6 @@ //--------------------------------------------------------------------+ // HOST CONFIGURATION //--------------------------------------------------------------------+ -#define TUSB_CFG_HOST - //------------- CORE -------------// #define TUSB_CFG_HOST_CONTROLLER_START_INDEX 0 diff --git a/tinyusb/class/hid_host.c b/tinyusb/class/hid_host.c index 56f8cf56b..fb4f4d230 100644 --- a/tinyusb/class/hid_host.c +++ b/tinyusb/class/hid_host.c @@ -37,7 +37,7 @@ #include "tusb_option.h" -#if defined TUSB_CFG_HOST && defined HOST_CLASS_HID +#if (MODE_HOST_SUPPORTED && defined HOST_CLASS_HID) #define _TINY_USB_SOURCE_FILE_ diff --git a/tinyusb/host/ehci/ehci.c b/tinyusb/host/ehci/ehci.c index 4c55065cc..c3fda3f3d 100644 --- a/tinyusb/host/ehci/ehci.c +++ b/tinyusb/host/ehci/ehci.c @@ -37,7 +37,7 @@ #include "common/common.h" -#if defined TUSB_CFG_HOST && (MCU == MCU_LPC43XX || MCU == MCU_LPC18XX) +#if MODE_HOST_SUPPORTED && (MCU == MCU_LPC43XX || MCU == MCU_LPC18XX) //--------------------------------------------------------------------+ // INCLUDE //--------------------------------------------------------------------+ diff --git a/tinyusb/host/hcd.c b/tinyusb/host/hcd.c index ad72d49c1..e81809c87 100644 --- a/tinyusb/host/hcd.c +++ b/tinyusb/host/hcd.c @@ -37,7 +37,7 @@ #include "hcd.h" -#ifdef TUSB_CFG_HOST +#if MODE_HOST_SUPPORTED #endif diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c index 4a63727b1..08adecf15 100644 --- a/tinyusb/host/usbh.c +++ b/tinyusb/host/usbh.c @@ -37,7 +37,7 @@ #include "common/common.h" -#ifdef TUSB_CFG_HOST +#if MODE_HOST_SUPPORTED #define _TINY_USB_SOURCE_FILE_ diff --git a/tinyusb/mcu_capacity.h b/tinyusb/mcu_capacity.h index b851ca44a..8e05edcaf 100644 --- a/tinyusb/mcu_capacity.h +++ b/tinyusb/mcu_capacity.h @@ -78,17 +78,6 @@ #define CAP_MODE_HOST #endif -#define CONTROLLER_HOST_NUMBER (\ - (TUSB_CFG_CONTROLLER0_MODE & TUSB_MODE_HOST) ? 1 : 0\ - +(TUSB_CFG_CONTROLLER1_MODE & TUSB_MODE_HOST) ? 1 : 0) - -#define CONTROLLER_DEVICE_NUMBER (\ - (TUSB_CFG_CONTROLLER0_MODE & TUSB_MODE_DEVICE) ? 1 : 0\ - +(TUSB_CFG_CONTROLLER1_MODE & TUSB_MODE_DEVICE) ? 1 : 0) - -#define MODE_HOST (CONTROLLER_HOST_NUMBER > 0) -#define MODE_DEVICE (CONTROLLER_DEVICE_NUMBER > 0) - //--------------------------------------------------------------------+ // Validation //--------------------------------------------------------------------+ diff --git a/tinyusb/tusb.c b/tinyusb/tusb.c index b45c7b601..49f8ef253 100644 --- a/tinyusb/tusb.c +++ b/tinyusb/tusb.c @@ -43,7 +43,7 @@ tusb_error_t tusb_init(void) { ASSERT_STATUS( hal_init() ) ; // hardware init -#ifdef TUSB_CFG_HOST +#if MODE_HOST_SUPPORTED ASSERT_STATUS( usbh_init() ); // host stack init #endif diff --git a/tinyusb/tusb.h b/tinyusb/tusb.h index 1129fec6a..8bc4d7af4 100644 --- a/tinyusb/tusb.h +++ b/tinyusb/tusb.h @@ -52,7 +52,7 @@ #include "hal/hal.h" #include "osal/osal.h" -#ifdef TUSB_CFG_HOST +#if MODE_HOST_SUPPORTED #include "host/usbh.h" #ifdef HOST_CLASS_HID @@ -60,7 +60,7 @@ #endif #endif -#ifdef TUSB_CFG_DEVICE +#if MODE_DEVICE_SUPPORTED #include "device/dcd.h" #if DEVICE_CLASS_HID @@ -72,9 +72,7 @@ #endif #endif -#if !(defined TUSB_CFG_HOST) && !(defined TUSB_CFG_DEVICE) - #error please enable either TUSB_CFG_HOST or TUSB_CFG_DEVICE -#endif + tusb_error_t tusb_init(void); diff --git a/tinyusb/tusb_option.h b/tinyusb/tusb_option.h index 3b1830419..274e4e0f9 100644 --- a/tinyusb/tusb_option.h +++ b/tinyusb/tusb_option.h @@ -63,12 +63,31 @@ #include "tusb_config.h" #include "mcu_capacity.h" +//--------------------------------------------------------------------+ +// CONTROLLER +//--------------------------------------------------------------------+ +#define TUSB_MODE_HOST 0x02 +#define TUSB_MODE_DEVICE 0x01 +#define TUSB_MODE_NONE 0x00 + +#define CONTROLLER_HOST_NUMBER (\ + ((TUSB_CFG_CONTROLLER0_MODE & TUSB_MODE_HOST) ? 1 : 0) + \ + ((TUSB_CFG_CONTROLLER1_MODE & TUSB_MODE_HOST) ? 1 : 0)) + +#define CONTROLLER_DEVICE_NUMBER (\ + ((TUSB_CFG_CONTROLLER0_MODE & TUSB_MODE_DEVICE) ? 1 : 0) + \ + ((TUSB_CFG_CONTROLLER1_MODE & TUSB_MODE_DEVICE) ? 1 : 0)) + +#define MODE_HOST_SUPPORTED (CONTROLLER_HOST_NUMBER > 0) +#define MODE_DEVICE_SUPPORTED (CONTROLLER_DEVICE_NUMBER > 0) + +#if !MODE_HOST_SUPPORTED && !MODE_DEVICE_SUPPORTED + #error please configure at least 1 TUSB_CFG_CONTROLLERn_MODE to TUSB_MODE_HOST and/or TUSB_MODE_DEVICE +#endif + //--------------------------------------------------------------------+ // COMMON OPTIONS //--------------------------------------------------------------------+ -#define TUSB_MODE_HOST BIN8(10) -#define TUSB_MODE_DEVICE BIN8(01) -#define TUSB_MODE_NONE BIN8(00) /// 0: no debug information 3: most debug information provided #ifndef TUSB_CFG_DEBUG @@ -97,9 +116,7 @@ //--------------------------------------------------------------------+ // HOST OPTIONS //--------------------------------------------------------------------+ -#ifdef TUSB_CFG_HOST - //------------- Controller -------------// - +#if MODE_HOST_SUPPORTED #ifndef TUSB_CFG_HOST_CONTROLLER_START_INDEX #error TUSB_CFG_HOST_CONTROLLER_START_INDEX is not defined #endif @@ -162,6 +179,8 @@ #define CDC_NOTIFICATION_EP_MAXPACKETSIZE 8 #define CDC_DATA_EP_MAXPACKET_SIZE 16 + + #ifdef __cplusplus } #endif