diff --git a/os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.c b/os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.c index 1a60f44e..8342f35c 100644 --- a/os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.c +++ b/os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.c @@ -584,14 +584,14 @@ void usb_lld_start(USBDriver *usbp) { /* Force VBUS detect so the device thinks it is plugged into a host */ USB->PWR = USB_USB_PWR_VBUS_DETECT_OVERRIDE_EN | USB_USB_PWR_VBUS_DETECT; #else -#ifdef usb_vbus_detect +#if RP_USE_EXTERNAL_VBUS_DETECT == TRUE /* If VBUS is detected by pin without USB VBUS DET pin, * define usb_vbus_detect which returns true if VBUS is enabled. */ - if (usb_vbus_detect) { + if (usb_vbus_detect()) { USB->PWR = USB_USB_PWR_VBUS_DETECT_OVERRIDE_EN | USB_USB_PWR_VBUS_DETECT; } -#endif /* usb_vbus_detect */ +#endif /* RP_USE_EXTERNAL_VBUS_DETECT */ #endif /* RP_USB_FORCE_VBUS_DETECT */ /* Reset procedure enforced on driver start.*/ diff --git a/os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.h b/os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.h index 3de27e64..c6256525 100644 --- a/os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.h +++ b/os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.h @@ -33,10 +33,6 @@ /* Driver constants. */ /*===========================================================================*/ -#if !defined(RP_USB_USE_USBD1) -#error "RP_USB_USE_USBD1 not defined in registry" -#endif - /** * @brief Maximum endpoint address. */ @@ -57,6 +53,56 @@ */ #define USB_SET_ADDRESS_MODE USB_LATE_SET_ADDRESS +/*===========================================================================*/ +/* Driver pre-compile time settings. */ +/*===========================================================================*/ + +/** + * @brief USBD1 driver enable switch. + */ +#if !defined(RP_USB_USE_USBD1) || defined(__DOXYGEN__) +#define RP_USB_USE_USBD1 FALSE +#endif + +/** + * @brief Force to set VBUS detect register. + * @details If you want to use non VBUS DETECT pin for this purpose, + set this flag to FALSE and define bool usb_vbus_detect(void) function + which returns true to force VBUS DETECT. + See RP_USE_EXTERNAL_VBUS_DETECT. + */ +#if !defined(RP_USB_FORCE_VBUS_DETECT) || defined(__DOXYGEN__) +#define RP_USB_FORCE_VBUS_DETECT TRUE +#endif + +/** + * @brief Use custom VBUS detection. + @details If RP_USB_FORCE_VBUS_DETECT is FALSE, this flag can be TRUE + to detect custom function to detect VBUS. + */ +#if !defined(RP_USE_EXTERNAL_VBUS_DETECT) || defined(__DOXYGEN__) +#define RP_USE_EXTERNAL_VBUS_DETECT FALSE +#endif + +#if RP_USE_EXTERNAL_VBUS_DETECT == TRUE +extern bool usb_vbus_detect(void); +#endif + +/** + * @brief Enables the SOF interrupt. + */ +#if !defined(RP_USB_USE_SOF_INTR) || defined(__DOXYGEN__) +#define RP_USB_USE_SOF_INTR FALSE +#endif + +/** + * @brief Enables the error data sequence interrupt. + * @details This flag is useful if you develop low level driver. + */ +#if !defined(RP_USB_USE_ERROR_DATA_SEQ_INTR) || defined(__DOXYGEN__) +#define RP_USB_USE_ERROR_DATA_SEQ_INTR FALSE +#endif + /*===========================================================================*/ /* Driver data structures and types. */ /*===========================================================================*/ diff --git a/testhal/RP/RP2040/RT-RP2040-PICO-HID/cfg/mcuconf.h b/testhal/RP/RP2040/RT-RP2040-PICO-HID/cfg/mcuconf.h index d6b191f4..44190602 100644 --- a/testhal/RP/RP2040/RT-RP2040-PICO-HID/cfg/mcuconf.h +++ b/testhal/RP/RP2040/RT-RP2040-PICO-HID/cfg/mcuconf.h @@ -75,6 +75,7 @@ */ #define RP_USB_USE_USBD1 TRUE #define RP_USB_FORCE_VBUS_DETECT TRUE +#define RP_USE_EXTERNAL_VBUS_DETECT FALSE #define RP_USB_USE_SOF_INTR FALSE #define RP_USB_USE_ERROR_DATA_SEQ_INTR TRUE diff --git a/testhal/RP/RP2040/RT-RP2040-PICO-SERIAL/cfg/mcuconf.h b/testhal/RP/RP2040/RT-RP2040-PICO-SERIAL/cfg/mcuconf.h index 79abb121..f151ecd2 100644 --- a/testhal/RP/RP2040/RT-RP2040-PICO-SERIAL/cfg/mcuconf.h +++ b/testhal/RP/RP2040/RT-RP2040-PICO-SERIAL/cfg/mcuconf.h @@ -75,6 +75,7 @@ */ #define RP_USB_USE_USBD1 TRUE #define RP_USB_FORCE_VBUS_DETECT TRUE +#define RP_USE_EXTERNAL_VBUS_DETECT FALSE #define RP_USB_USE_SOF_INTR TRUE #define RP_USB_USE_ERROR_DATA_SEQ_INTR TRUE