diff --git a/drivers/usb/CMakeLists.txt b/drivers/usb/CMakeLists.txt index 7a0570f146d..e0d9f196b29 100644 --- a/drivers/usb/CMakeLists.txt +++ b/drivers/usb/CMakeLists.txt @@ -5,3 +5,4 @@ add_subdirectory_ifdef(CONFIG_UHC_DRIVER uhc) add_subdirectory_ifdef(CONFIG_UVB uvb) add_subdirectory_ifdef(CONFIG_USB_BC12 bc12) add_subdirectory_ifdef(CONFIG_USB_DEVICE_DRIVER device) +add_subdirectory(common) diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index 369b40f6fa3..bcccdf6b657 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig @@ -8,3 +8,4 @@ source "drivers/usb/udc/Kconfig" source "drivers/usb/uhc/Kconfig" source "drivers/usb/uvb/Kconfig" source "drivers/usb/device/Kconfig" +source "drivers/usb/common/Kconfig" diff --git a/drivers/usb/common/CMakeLists.txt b/drivers/usb/common/CMakeLists.txt new file mode 100644 index 00000000000..56e4c734ced --- /dev/null +++ b/drivers/usb/common/CMakeLists.txt @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory_ifdef(CONFIG_HAS_NRFX nrf_usbd_common) diff --git a/drivers/usb/common/Kconfig b/drivers/usb/common/Kconfig new file mode 100644 index 00000000000..7f6a02614b8 --- /dev/null +++ b/drivers/usb/common/Kconfig @@ -0,0 +1,4 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +rsource "nrf_usbd_common/Kconfig" diff --git a/drivers/usb/common/nrf_usbd_common/CMakeLists.txt b/drivers/usb/common/nrf_usbd_common/CMakeLists.txt new file mode 100644 index 00000000000..84952a8e5f8 --- /dev/null +++ b/drivers/usb/common/nrf_usbd_common/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if(CONFIG_NRF_USBD_COMMON) + zephyr_library() + + zephyr_include_directories(.) + + zephyr_library_sources(nrf_usbd_common.c) +endif() diff --git a/drivers/usb/common/nrf_usbd_common/Kconfig b/drivers/usb/common/nrf_usbd_common/Kconfig new file mode 100644 index 00000000000..ae8f631fc72 --- /dev/null +++ b/drivers/usb/common/nrf_usbd_common/Kconfig @@ -0,0 +1,20 @@ +# Copyright (c) 2016-2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +module = NRF_USBD_COMMON +module-str = nRF USBD common +source "subsys/logging/Kconfig.template.log_config" + +config NRF_USBD_COMMON + bool "USBD driver" + depends on HAS_NRFX + depends on $(dt_has_compat,$(DT_COMPAT_NORDIC_NRF_USBD)) + +config NRF_USBD_ISO_IN_ZLP + bool "Send ZLP on ISO IN when not ready" + depends on NRF_USBD_COMMON + default y + help + Controls the response of the ISO IN endpoint to an IN token when no + data is ready to be sent. When enabled, ZLP is sent when no data is + ready. When disabled, no response is sent (bus timeout occurs). diff --git a/modules/hal_nordic/nrfx/nrfx_usbd.c b/drivers/usb/common/nrf_usbd_common/nrf_usbd_common.c similarity index 62% rename from modules/hal_nordic/nrfx/nrfx_usbd.c rename to drivers/usb/common/nrf_usbd_common/nrf_usbd_common.c index 886bf448ce2..0a7235e9b52 100644 --- a/modules/hal_nordic/nrfx/nrfx_usbd.c +++ b/drivers/usb/common/nrf_usbd_common/nrf_usbd_common.c @@ -4,74 +4,69 @@ * SPDX-License-Identifier: Apache-2.0 */ +/* This file is undergoing transition towards native Zephyr nrf USB driver. */ + +/** @cond INTERNAL_HIDDEN */ + #include -#if NRFX_CHECK(NRFX_USBD_ENABLED) - -#include -#include "nrfx_usbd_errata.h" +#include "nrf_usbd_common.h" +#include "nrf_usbd_common_errata.h" #include -#define NRFX_LOG_MODULE USBD -#include +#include +LOG_MODULE_REGISTER(nrf_usbd_common, CONFIG_NRF_USBD_COMMON_LOG_LEVEL); -#ifndef NRFX_USBD_EARLY_DMA_PROCESS +#ifndef NRF_USBD_COMMON_EARLY_DMA_PROCESS /* Try to process DMA request when endpoint transmission has been detected * and just after last EasyDMA has been processed. * It speeds up the transmission a little (about 10% measured) * with a cost of more CPU power used. */ -#define NRFX_USBD_EARLY_DMA_PROCESS 1 +#define NRF_USBD_COMMON_EARLY_DMA_PROCESS 1 #endif -#ifndef NRFX_USBD_STARTED_EV_ENABLE -#define NRFX_USBD_STARTED_EV_ENABLE 0 +#ifndef NRF_USBD_COMMON_STARTED_EV_ENABLE +#define NRF_USBD_COMMON_STARTED_EV_ENABLE 0 #endif -#ifndef NRFX_USBD_CONFIG_ISO_IN_ZLP -/* - * Respond to an IN token on ISO IN endpoint with ZLP when no data is ready. - */ -#define NRFX_USBD_CONFIG_ISO_IN_ZLP 0 -#endif - -#ifndef NRFX_USBD_ISO_DEBUG +#ifndef NRF_USBD_COMMON_ISO_DEBUG /* Also generate information about ISOCHRONOUS events and transfers. * Turn this off if no ISOCHRONOUS transfers are going to be debugged and this * option generates a lot of useless messages. */ -#define NRFX_USBD_ISO_DEBUG 1 +#define NRF_USBD_COMMON_ISO_DEBUG 1 #endif -#ifndef NRFX_USBD_FAILED_TRANSFERS_DEBUG +#ifndef NRF_USBD_COMMON_FAILED_TRANSFERS_DEBUG /* Also generate debug information for failed transfers. * It might be useful but may generate a lot of useless debug messages * in some library usages (for example when transfer is generated and the * result is used to check whatever endpoint was busy. */ -#define NRFX_USBD_FAILED_TRANSFERS_DEBUG 1 +#define NRF_USBD_COMMON_FAILED_TRANSFERS_DEBUG 1 #endif -#ifndef NRFX_USBD_DMAREQ_PROCESS_DEBUG +#ifndef NRF_USBD_COMMON_DMAREQ_PROCESS_DEBUG /* Generate additional messages that mark the status inside * @ref usbd_dmareq_process. * It is useful to debug library internals but may generate a lot of * useless debug messages. */ -#define NRFX_USBD_DMAREQ_PROCESS_DEBUG 1 +#define NRF_USBD_COMMON_DMAREQ_PROCESS_DEBUG 1 #endif -#ifndef NRFX_USBD_USE_WORKAROUND_FOR_ANOMALY_211 +#ifndef NRF_USBD_COMMON_USE_WORKAROUND_FOR_ANOMALY_211 /* Anomaly 211 - Device remains in SUSPEND too long when host resumes * a bus activity (sending SOF packets) without a RESUME condition. */ -#define NRFX_USBD_USE_WORKAROUND_FOR_ANOMALY_211 0 +#define NRF_USBD_COMMON_USE_WORKAROUND_FOR_ANOMALY_211 0 #endif /** - * @defgroup nrfx_usbd_int USB Device driver internal part + * @defgroup nrf_usbd_common_int USB Device driver internal part * @internal - * @ingroup nrfx_usbd + * @ingroup nrf_usbd_common * * This part contains auxiliary internal macros, variables and functions. * @{ @@ -85,10 +80,9 @@ * * @param ep Endpoint number to validity check. */ -#define NRFX_USBD_ASSERT_EP_VALID(ep) \ - NRFX_ASSERT( \ - ((NRF_USBD_EPIN_CHECK(ep) && (NRF_USBD_EP_NR_GET(ep) < NRF_USBD_EPIN_CNT)) || \ - (NRF_USBD_EPOUT_CHECK(ep) && (NRF_USBD_EP_NR_GET(ep) < NRF_USBD_EPOUT_CNT)))); +#define NRF_USBD_COMMON_ASSERT_EP_VALID(ep) __ASSERT_NO_MSG( \ + ((NRF_USBD_EPIN_CHECK(ep) && (NRF_USBD_EP_NR_GET(ep) < NRF_USBD_EPIN_CNT)) || \ + (NRF_USBD_EPOUT_CHECK(ep) && (NRF_USBD_EP_NR_GET(ep) < NRF_USBD_EPOUT_CNT)))); /** * @brief Lowest position of bit for IN endpoint. @@ -96,7 +90,7 @@ * The first bit position corresponding to IN endpoint. * @sa ep2bit bit2ep */ -#define NRFX_USBD_EPIN_BITPOS_0 0 +#define NRF_USBD_COMMON_EPIN_BITPOS_0 0 /** * @brief Lowest position of bit for OUT endpoint. @@ -104,24 +98,24 @@ * The first bit position corresponding to OUT endpoint * @sa ep2bit bit2ep */ -#define NRFX_USBD_EPOUT_BITPOS_0 16 +#define NRF_USBD_COMMON_EPOUT_BITPOS_0 16 /** * @brief Input endpoint bits mask. */ -#define NRFX_USBD_EPIN_BIT_MASK (0xFFFFU << NRFX_USBD_EPIN_BITPOS_0) +#define NRF_USBD_COMMON_EPIN_BIT_MASK (0xFFFFU << NRF_USBD_COMMON_EPIN_BITPOS_0) /** * @brief Output endpoint bits mask. */ -#define NRFX_USBD_EPOUT_BIT_MASK (0xFFFFU << NRFX_USBD_EPOUT_BITPOS_0) +#define NRF_USBD_COMMON_EPOUT_BIT_MASK (0xFFFFU << NRF_USBD_COMMON_EPOUT_BITPOS_0) /** * @brief Isochronous endpoint bit mask */ -#define USBD_EPISO_BIT_MASK \ - ((1U << NRFX_USBD_EP_BITPOS(NRFX_USBD_EPOUT8)) | \ - (1U << NRFX_USBD_EP_BITPOS(NRFX_USBD_EPIN8))) +#define USBD_EPISO_BIT_MASK \ + ((1U << NRF_USBD_COMMON_EP_BITPOS(NRF_USBD_COMMON_EPOUT8)) | \ + (1U << NRF_USBD_COMMON_EP_BITPOS(NRF_USBD_COMMON_EPIN8))) /** * @brief Auxiliary macro to change EP number into bit position. @@ -132,9 +126,9 @@ * @param[in] ep Endpoint number. * @return Endpoint bit position. */ -#define NRFX_USBD_EP_BITPOS(ep) \ - ((NRF_USBD_EPIN_CHECK(ep) ? NRFX_USBD_EPIN_BITPOS_0 : NRFX_USBD_EPOUT_BITPOS_0) + \ - NRF_USBD_EP_NR_GET(ep)) +#define NRF_USBD_COMMON_EP_BITPOS(ep) \ + ((NRF_USBD_EPIN_CHECK(ep) ? NRF_USBD_COMMON_EPIN_BITPOS_0 : NRF_USBD_COMMON_EPOUT_BITPOS_0)\ + + NRF_USBD_EP_NR_GET(ep)) /** * @brief Helper macro for creating an endpoint transfer event. @@ -145,25 +139,28 @@ * * @return Initialized event constant variable. */ -#define NRFX_USBD_EP_TRANSFER_EVENT(name, endpont, ep_stat) \ - const nrfx_usbd_evt_t name = {NRFX_USBD_EVT_EPTRANSFER, \ +#define NRF_USBD_COMMON_EP_TRANSFER_EVENT(name, endpont, ep_stat) \ + const nrf_usbd_common_evt_t name = {NRF_USBD_COMMON_EVT_EPTRANSFER, \ .data = {.eptransfer = {.ep = endpont, .status = ep_stat}}} /* Check it the bit positions values match defined DATAEPSTATUS bit positions */ -NRFX_STATIC_ASSERT(NRFX_USBD_EP_BITPOS(NRFX_USBD_EPIN1) == USBD_EPDATASTATUS_EPIN1_Pos); -NRFX_STATIC_ASSERT(NRFX_USBD_EP_BITPOS(NRFX_USBD_EPIN2) == USBD_EPDATASTATUS_EPIN2_Pos); -NRFX_STATIC_ASSERT(NRFX_USBD_EP_BITPOS(NRFX_USBD_EPIN3) == USBD_EPDATASTATUS_EPIN3_Pos); -NRFX_STATIC_ASSERT(NRFX_USBD_EP_BITPOS(NRFX_USBD_EPIN4) == USBD_EPDATASTATUS_EPIN4_Pos); -NRFX_STATIC_ASSERT(NRFX_USBD_EP_BITPOS(NRFX_USBD_EPIN5) == USBD_EPDATASTATUS_EPIN5_Pos); -NRFX_STATIC_ASSERT(NRFX_USBD_EP_BITPOS(NRFX_USBD_EPIN6) == USBD_EPDATASTATUS_EPIN6_Pos); -NRFX_STATIC_ASSERT(NRFX_USBD_EP_BITPOS(NRFX_USBD_EPIN7) == USBD_EPDATASTATUS_EPIN7_Pos); -NRFX_STATIC_ASSERT(NRFX_USBD_EP_BITPOS(NRFX_USBD_EPOUT1) == USBD_EPDATASTATUS_EPOUT1_Pos); -NRFX_STATIC_ASSERT(NRFX_USBD_EP_BITPOS(NRFX_USBD_EPOUT2) == USBD_EPDATASTATUS_EPOUT2_Pos); -NRFX_STATIC_ASSERT(NRFX_USBD_EP_BITPOS(NRFX_USBD_EPOUT3) == USBD_EPDATASTATUS_EPOUT3_Pos); -NRFX_STATIC_ASSERT(NRFX_USBD_EP_BITPOS(NRFX_USBD_EPOUT4) == USBD_EPDATASTATUS_EPOUT4_Pos); -NRFX_STATIC_ASSERT(NRFX_USBD_EP_BITPOS(NRFX_USBD_EPOUT5) == USBD_EPDATASTATUS_EPOUT5_Pos); -NRFX_STATIC_ASSERT(NRFX_USBD_EP_BITPOS(NRFX_USBD_EPOUT6) == USBD_EPDATASTATUS_EPOUT6_Pos); -NRFX_STATIC_ASSERT(NRFX_USBD_EP_BITPOS(NRFX_USBD_EPOUT7) == USBD_EPDATASTATUS_EPOUT7_Pos); +BUILD_ASSERT( + (NRF_USBD_COMMON_EP_BITPOS(NRF_USBD_COMMON_EPIN1) == USBD_EPDATASTATUS_EPIN1_Pos) && + (NRF_USBD_COMMON_EP_BITPOS(NRF_USBD_COMMON_EPIN2) == USBD_EPDATASTATUS_EPIN2_Pos) && + (NRF_USBD_COMMON_EP_BITPOS(NRF_USBD_COMMON_EPIN3) == USBD_EPDATASTATUS_EPIN3_Pos) && + (NRF_USBD_COMMON_EP_BITPOS(NRF_USBD_COMMON_EPIN4) == USBD_EPDATASTATUS_EPIN4_Pos) && + (NRF_USBD_COMMON_EP_BITPOS(NRF_USBD_COMMON_EPIN5) == USBD_EPDATASTATUS_EPIN5_Pos) && + (NRF_USBD_COMMON_EP_BITPOS(NRF_USBD_COMMON_EPIN6) == USBD_EPDATASTATUS_EPIN6_Pos) && + (NRF_USBD_COMMON_EP_BITPOS(NRF_USBD_COMMON_EPIN7) == USBD_EPDATASTATUS_EPIN7_Pos) && + (NRF_USBD_COMMON_EP_BITPOS(NRF_USBD_COMMON_EPOUT1) == USBD_EPDATASTATUS_EPOUT1_Pos) && + (NRF_USBD_COMMON_EP_BITPOS(NRF_USBD_COMMON_EPOUT2) == USBD_EPDATASTATUS_EPOUT2_Pos) && + (NRF_USBD_COMMON_EP_BITPOS(NRF_USBD_COMMON_EPOUT3) == USBD_EPDATASTATUS_EPOUT3_Pos) && + (NRF_USBD_COMMON_EP_BITPOS(NRF_USBD_COMMON_EPOUT4) == USBD_EPDATASTATUS_EPOUT4_Pos) && + (NRF_USBD_COMMON_EP_BITPOS(NRF_USBD_COMMON_EPOUT5) == USBD_EPDATASTATUS_EPOUT5_Pos) && + (NRF_USBD_COMMON_EP_BITPOS(NRF_USBD_COMMON_EPOUT6) == USBD_EPDATASTATUS_EPOUT6_Pos) && + (NRF_USBD_COMMON_EP_BITPOS(NRF_USBD_COMMON_EPOUT7) == USBD_EPDATASTATUS_EPOUT7_Pos), + "NRF_USBD_COMMON bit positions do not match hardware" +); /** * @brief Current driver state. @@ -177,7 +174,7 @@ static nrfx_drv_state_t m_drv_state = NRFX_DRV_STATE_UNINITIALIZED; * * @note Currently it cannot be null if any interrupt is activated. */ -static nrfx_usbd_event_handler_t m_event_handler; +static nrf_usbd_common_event_handler_t m_event_handler; /** * @brief Detected state of the bus. @@ -196,8 +193,8 @@ static volatile bool m_bus_suspend; /** * @brief Internal constant that contains interrupts disabled in suspend state. * - * Internal constant used in @ref nrfx_usbd_suspend_irq_config and @ref nrfx_usbd_active_irq_config - * functions. + * Internal constant used in @ref nrf_usbd_common_suspend_irq_config and + * @ref nrf_usbd_common_active_irq_config functions. */ static const uint32_t m_irq_disabled_in_suspend = NRF_USBD_INT_ENDEPIN0_MASK | NRF_USBD_INT_EP0DATADONE_MASK | NRF_USBD_INT_ENDEPOUT0_MASK | @@ -209,7 +206,7 @@ static const uint32_t m_irq_disabled_in_suspend = * This variable is used to redirect internal setup data event * into selected endpoint (IN or OUT). */ -static nrfx_usbd_ep_t m_last_setup_dir; +static nrf_usbd_common_ep_t m_last_setup_dir; /** * @brief Mark endpoint readiness for DMA transfer. @@ -229,7 +226,7 @@ static uint32_t m_ep_ready; * Mask prepared USBD data for transmission. * It is cleared when no more data to transmit left. */ -static nrfx_atomic_t m_ep_dma_waiting; +static atomic_t m_ep_dma_waiting; /** * @brief Current EasyDMA state. @@ -258,12 +255,16 @@ static bool m_first_enable = true; * buffer is ready. */ typedef struct { - nrfx_usbd_handler_t handler; /*!< Handler for current transfer, function pointer. */ - void *p_context; /*!< Context for transfer handler. */ - size_t transfer_cnt; /*!< Number of transferred bytes in the current transfer. */ - uint16_t max_packet_size; /*!< Configured endpoint size. */ - nrfx_usbd_ep_status_t status; /*!< NRFX_SUCCESS or error code, never NRFX_ERROR_BUSY */ - /*!< - this one is calculated. */ + /** Handler for current transfer, function pointer. */ + nrf_usbd_common_handler_t handler; + /** Context for transfer handler. */ + void *p_context; + /** Number of transferred bytes in the current transfer. */ + size_t transfer_cnt; + /** Configured endpoint size. */ + uint16_t max_packet_size; + /** NRFX_SUCCESS or error code, never NRFX_ERROR_BUSY - this one is calculated. */ + nrf_usbd_common_ep_status_t status; } usbd_ep_state_t; /** @@ -286,7 +287,7 @@ static struct { * 3. RAM transfer with automatic ZLP. * 4. Flash transfer with automatic ZLP. */ -nrfx_usbd_transfer_t m_ep_feeder_state[NRF_USBD_EPIN_CNT]; +nrf_usbd_common_transfer_t m_ep_feeder_state[NRF_USBD_EPIN_CNT]; /** * @brief Status variables for integrated consumers. @@ -298,7 +299,7 @@ nrfx_usbd_transfer_t m_ep_feeder_state[NRF_USBD_EPIN_CNT]; * Transfer is finished automatically when received data block is smaller * than the endpoint buffer or all the required data is received. */ -nrfx_usbd_transfer_t m_ep_consumer_state[NRF_USBD_EPOUT_CNT]; +nrf_usbd_common_transfer_t m_ep_consumer_state[NRF_USBD_EPOUT_CNT]; /** * @brief Buffer used to send data directly from FLASH. @@ -310,7 +311,7 @@ nrfx_usbd_transfer_t m_ep_consumer_state[NRF_USBD_EPOUT_CNT]; * We do not need more buffers that one, because only one transfer can be pending * at once. */ -static uint32_t m_tx_buffer[NRFX_CEIL_DIV(NRFX_USBD_FEEDER_BUFFER_SIZE, sizeof(uint32_t))]; +static uint32_t m_tx_buffer[NRFX_CEIL_DIV(NRF_USBD_COMMON_FEEDER_BUFFER_SIZE, sizeof(uint32_t))]; /* Early declaration. Documentation above definition. */ static void usbd_dmareq_process(void); @@ -322,11 +323,11 @@ static void usbd_dmareq_process(void); * * @return Connected endpoint event code. * - * Marker to delete when not required anymore: >> NRFX_USBD_ERRATA_ENABLE <<. + * Marker to delete when not required anymore: >> NRF_USBD_COMMON_ERRATA_ENABLE <<. */ -static inline nrf_usbd_event_t nrfx_usbd_ep_to_endevent(nrfx_usbd_ep_t ep) +static inline nrf_usbd_event_t nrf_usbd_common_ep_to_endevent(nrf_usbd_common_ep_t ep) { - NRFX_USBD_ASSERT_EP_VALID(ep); + NRF_USBD_COMMON_ASSERT_EP_VALID(ep); static const nrf_usbd_event_t epin_endev[] = { NRF_USBD_EVENT_ENDEPIN0, NRF_USBD_EVENT_ENDEPIN1, NRF_USBD_EVENT_ENDEPIN2, @@ -348,9 +349,9 @@ static inline nrf_usbd_event_t nrfx_usbd_ep_to_endevent(nrfx_usbd_ep_t ep) * @return Interrupt mask related to the EasyDMA transfer end for the * chosen endpoint. */ -static inline uint32_t nrfx_usbd_ep_to_int(nrfx_usbd_ep_t ep) +static inline uint32_t nrf_usbd_common_ep_to_int(nrf_usbd_common_ep_t ep) { - NRFX_USBD_ASSERT_EP_VALID(ep); + NRF_USBD_COMMON_ASSERT_EP_VALID(ep); static const uint8_t epin_bitpos[] = { USBD_INTEN_ENDEPIN0_Pos, USBD_INTEN_ENDEPIN1_Pos, USBD_INTEN_ENDEPIN2_Pos, @@ -375,26 +376,26 @@ static inline uint32_t nrfx_usbd_ep_to_int(nrfx_usbd_ep_t ep) /** * @brief Integrated consumer to RAM buffer. * - * @param p_next See @ref nrfx_usbd_consumer_t documentation. - * @param p_context See @ref nrfx_usbd_consumer_t documentation. - * @param ep_size See @ref nrfx_usbd_consumer_t documentation. - * @param data_size See @ref nrfx_usbd_consumer_t documentation. + * @param p_next See @ref nrf_usbd_common_consumer_t documentation. + * @param p_context See @ref nrf_usbd_common_consumer_t documentation. + * @param ep_size See @ref nrf_usbd_common_consumer_t documentation. + * @param data_size See @ref nrf_usbd_common_consumer_t documentation. * * @retval true Continue transfer. * @retval false This was the last transfer. */ -bool nrfx_usbd_consumer(nrfx_usbd_ep_transfer_t *p_next, void *p_context, size_t ep_size, - size_t data_size) +bool nrf_usbd_common_consumer(nrf_usbd_common_ep_transfer_t *p_next, void *p_context, + size_t ep_size, size_t data_size) { - nrfx_usbd_transfer_t *p_transfer = (nrfx_usbd_transfer_t *)p_context; + nrf_usbd_common_transfer_t *p_transfer = (nrf_usbd_common_transfer_t *)p_context; - NRFX_ASSERT(ep_size >= data_size); - NRFX_ASSERT((p_transfer->p_data.rx == NULL) || nrfx_is_in_ram(p_transfer->p_data.rx)); + __ASSERT_NO_MSG(ep_size >= data_size); + __ASSERT_NO_MSG((p_transfer->p_data.rx == NULL) || nrfx_is_in_ram(p_transfer->p_data.rx)); size_t size = p_transfer->size; if (size < data_size) { - NRFX_LOG_DEBUG("consumer: buffer too small: r: %u, l: %u", data_size, size); + LOG_DBG("consumer: buffer too small: r: %u, l: %u", data_size, size); /* Buffer size to small */ p_next->size = 0; p_next->p_data = p_transfer->p_data; @@ -411,18 +412,19 @@ bool nrfx_usbd_consumer(nrfx_usbd_ep_transfer_t *p_next, void *p_context, size_t /** * @brief Integrated feeder from RAM source. * - * @param[out] p_next See @ref nrfx_usbd_feeder_t documentation. - * @param[in,out] p_context See @ref nrfx_usbd_feeder_t documentation. - * @param[in] ep_size See @ref nrfx_usbd_feeder_t documentation. + * @param[out] p_next See @ref nrf_usbd_common_feeder_t documentation. + * @param[in,out] p_context See @ref nrf_usbd_common_feeder_t documentation. + * @param[in] ep_size See @ref nrf_usbd_common_feeder_t documentation. * * @retval true Continue transfer. * @retval false This was the last transfer. */ -bool nrfx_usbd_feeder_ram(nrfx_usbd_ep_transfer_t *p_next, void *p_context, size_t ep_size) +bool nrf_usbd_common_feeder_ram(nrf_usbd_common_ep_transfer_t *p_next, + void *p_context, size_t ep_size) { - nrfx_usbd_transfer_t *p_transfer = (nrfx_usbd_transfer_t *)p_context; + nrf_usbd_common_transfer_t *p_transfer = (nrf_usbd_common_transfer_t *)p_context; - NRFX_ASSERT(nrfx_is_in_ram(p_transfer->p_data.tx)); + __ASSERT_NO_MSG(nrfx_is_in_ram(p_transfer->p_data.tx)); size_t tx_size = p_transfer->size; @@ -442,18 +444,19 @@ bool nrfx_usbd_feeder_ram(nrfx_usbd_ep_transfer_t *p_next, void *p_context, size /** * @brief Integrated feeder from RAM source with ZLP. * - * @param[out] p_next See @ref nrfx_usbd_feeder_t documentation. - * @param[in,out] p_context See @ref nrfx_usbd_feeder_t documentation. - * @param[in] ep_size See @ref nrfx_usbd_feeder_t documentation. + * @param[out] p_next See @ref nrf_usbd_common_feeder_t documentation. + * @param[in,out] p_context See @ref nrf_usbd_common_feeder_t documentation. + * @param[in] ep_size See @ref nrf_usbd_common_feeder_t documentation. * * @retval true Continue transfer. * @retval false This was the last transfer. */ -bool nrfx_usbd_feeder_ram_zlp(nrfx_usbd_ep_transfer_t *p_next, void *p_context, size_t ep_size) +bool nrf_usbd_common_feeder_ram_zlp(nrf_usbd_common_ep_transfer_t *p_next, + void *p_context, size_t ep_size) { - nrfx_usbd_transfer_t *p_transfer = (nrfx_usbd_transfer_t *)p_context; + nrf_usbd_common_transfer_t *p_transfer = (nrf_usbd_common_transfer_t *)p_context; - NRFX_ASSERT(nrfx_is_in_ram(p_transfer->p_data.tx)); + __ASSERT_NO_MSG(nrfx_is_in_ram(p_transfer->p_data.tx)); size_t tx_size = p_transfer->size; @@ -473,27 +476,28 @@ bool nrfx_usbd_feeder_ram_zlp(nrfx_usbd_ep_transfer_t *p_next, void *p_context, /** * @brief Integrated feeder from a flash source. * - * @param[out] p_next See @ref nrfx_usbd_feeder_t documentation. - * @param[in,out] p_context See @ref nrfx_usbd_feeder_t documentation. - * @param[in] ep_size See @ref nrfx_usbd_feeder_t documentation. + * @param[out] p_next See @ref nrf_usbd_common_feeder_t documentation. + * @param[in,out] p_context See @ref nrf_usbd_common_feeder_t documentation. + * @param[in] ep_size See @ref nrf_usbd_common_feeder_t documentation. * * @retval true Continue transfer. * @retval false This was the last transfer. */ -bool nrfx_usbd_feeder_flash(nrfx_usbd_ep_transfer_t *p_next, void *p_context, size_t ep_size) +bool nrf_usbd_common_feeder_flash(nrf_usbd_common_ep_transfer_t *p_next, + void *p_context, size_t ep_size) { - nrfx_usbd_transfer_t *p_transfer = (nrfx_usbd_transfer_t *)p_context; + nrf_usbd_common_transfer_t *p_transfer = (nrf_usbd_common_transfer_t *)p_context; - NRFX_ASSERT(!nrfx_is_in_ram(p_transfer->p_data.tx)); + __ASSERT_NO_MSG(!nrfx_is_in_ram(p_transfer->p_data.tx)); size_t tx_size = p_transfer->size; - void *p_buffer = nrfx_usbd_feeder_buffer_get(); + void *p_buffer = nrf_usbd_common_feeder_buffer_get(); if (tx_size > ep_size) { tx_size = ep_size; } - NRFX_ASSERT(tx_size <= NRFX_USBD_FEEDER_BUFFER_SIZE); + __ASSERT_NO_MSG(tx_size <= NRF_USBD_COMMON_FEEDER_BUFFER_SIZE); memcpy(p_buffer, (p_transfer->p_data.tx), tx_size); p_next->p_data.tx = p_buffer; @@ -508,27 +512,28 @@ bool nrfx_usbd_feeder_flash(nrfx_usbd_ep_transfer_t *p_next, void *p_context, si /** * @brief Integrated feeder from a flash source with ZLP. * - * @param[out] p_next See @ref nrfx_usbd_feeder_t documentation. - * @param[in,out] p_context See @ref nrfx_usbd_feeder_t documentation. - * @param[in] ep_size See @ref nrfx_usbd_feeder_t documentation. + * @param[out] p_next See @ref nrf_usbd_common_feeder_t documentation. + * @param[in,out] p_context See @ref nrf_usbd_common_feeder_t documentation. + * @param[in] ep_size See @ref nrf_usbd_common_feeder_t documentation. * * @retval true Continue transfer. * @retval false This was the last transfer. */ -bool nrfx_usbd_feeder_flash_zlp(nrfx_usbd_ep_transfer_t *p_next, void *p_context, size_t ep_size) +bool nrf_usbd_common_feeder_flash_zlp(nrf_usbd_common_ep_transfer_t *p_next, + void *p_context, size_t ep_size) { - nrfx_usbd_transfer_t *p_transfer = (nrfx_usbd_transfer_t *)p_context; + nrf_usbd_common_transfer_t *p_transfer = (nrf_usbd_common_transfer_t *)p_context; - NRFX_ASSERT(!nrfx_is_in_ram(p_transfer->p_data.tx)); + __ASSERT_NO_MSG(!nrfx_is_in_ram(p_transfer->p_data.tx)); size_t tx_size = p_transfer->size; - void *p_buffer = nrfx_usbd_feeder_buffer_get(); + void *p_buffer = nrf_usbd_common_feeder_buffer_get(); if (tx_size > ep_size) { tx_size = ep_size; } - NRFX_ASSERT(tx_size <= NRFX_USBD_FEEDER_BUFFER_SIZE); + __ASSERT_NO_MSG(tx_size <= NRF_USBD_COMMON_FEEDER_BUFFER_SIZE); if (tx_size != 0) { memcpy(p_buffer, (p_transfer->p_data.tx), tx_size); @@ -553,11 +558,11 @@ bool nrfx_usbd_feeder_flash_zlp(nrfx_usbd_ep_transfer_t *p_next, void *p_context * * @return Endpoint identifier in HAL. * - * @sa nrfx_usbd_ep_from_hal + * @sa nrf_usbd_common_ep_from_hal */ -static inline uint8_t ep_to_hal(nrfx_usbd_ep_t ep) +static inline uint8_t ep_to_hal(nrf_usbd_common_ep_t ep) { - NRFX_USBD_ASSERT_EP_VALID(ep); + NRF_USBD_COMMON_ASSERT_EP_VALID(ep); return (uint8_t)ep; } @@ -568,9 +573,9 @@ static inline uint8_t ep_to_hal(nrfx_usbd_ep_t ep) * * @return Task for starting EasyDMA transfer on selected endpoint. */ -static inline nrf_usbd_task_t task_start_ep(nrfx_usbd_ep_t ep) +static inline nrf_usbd_task_t task_start_ep(nrf_usbd_common_ep_t ep) { - NRFX_USBD_ASSERT_EP_VALID(ep); + NRF_USBD_COMMON_ASSERT_EP_VALID(ep); return (nrf_usbd_task_t)((NRF_USBD_EPIN_CHECK(ep) ? NRF_USBD_TASK_STARTEPIN0 : NRF_USBD_TASK_STARTEPOUT0) + (NRF_USBD_EP_NR_GET(ep) * sizeof(uint32_t))); @@ -584,9 +589,9 @@ static inline nrf_usbd_task_t task_start_ep(nrfx_usbd_ep_t ep) * * @param ep Endpoint number. */ -static inline usbd_ep_state_t *ep_state_access(nrfx_usbd_ep_t ep) +static inline usbd_ep_state_t *ep_state_access(nrf_usbd_common_ep_t ep) { - NRFX_USBD_ASSERT_EP_VALID(ep); + NRF_USBD_COMMON_ASSERT_EP_VALID(ep); return ((NRF_USBD_EPIN_CHECK(ep) ? m_ep_state.ep_in : m_ep_state.ep_out) + NRF_USBD_EP_NR_GET(ep)); } @@ -603,10 +608,10 @@ static inline usbd_ep_state_t *ep_state_access(nrfx_usbd_ep_t ep) * * @sa bit2ep */ -static inline uint8_t ep2bit(nrfx_usbd_ep_t ep) +static inline uint8_t ep2bit(nrf_usbd_common_ep_t ep) { - NRFX_USBD_ASSERT_EP_VALID(ep); - return NRFX_USBD_EP_BITPOS(ep); + NRF_USBD_COMMON_ASSERT_EP_VALID(ep); + return NRF_USBD_COMMON_EP_BITPOS(ep); } /** @@ -618,11 +623,12 @@ static inline uint8_t ep2bit(nrfx_usbd_ep_t ep) * * @sa ep2bit */ -static inline nrfx_usbd_ep_t bit2ep(uint8_t bitpos) +static inline nrf_usbd_common_ep_t bit2ep(uint8_t bitpos) { - NRFX_STATIC_ASSERT(NRFX_USBD_EPOUT_BITPOS_0 > NRFX_USBD_EPIN_BITPOS_0); - return (nrfx_usbd_ep_t)((bitpos >= NRFX_USBD_EPOUT_BITPOS_0) - ? NRF_USBD_EPOUT(bitpos - NRFX_USBD_EPOUT_BITPOS_0) + BUILD_ASSERT(NRF_USBD_COMMON_EPOUT_BITPOS_0 > NRF_USBD_COMMON_EPIN_BITPOS_0, + "OUT endpoint bits should be higher than IN endpoint bits"); + return (nrf_usbd_common_ep_t)((bitpos >= NRF_USBD_COMMON_EPOUT_BITPOS_0) + ? NRF_USBD_EPOUT(bitpos - NRF_USBD_COMMON_EPOUT_BITPOS_0) : NRF_USBD_EPIN(bitpos)); } @@ -634,7 +640,7 @@ static inline nrfx_usbd_ep_t bit2ep(uint8_t bitpos) */ static inline void usbd_dma_pending_set(void) { - if (nrfx_usbd_errata_199()) { + if (nrf_usbd_common_errata_199()) { *((volatile uint32_t *)0x40027C1C) = 0x00000082; } m_dma_pending = true; @@ -648,7 +654,7 @@ static inline void usbd_dma_pending_set(void) */ static inline void usbd_dma_pending_clear(void) { - if (nrfx_usbd_errata_199()) { + if (nrf_usbd_common_errata_199()) { *((volatile uint32_t *)0x40027C1C) = 0x00000000; } m_dma_pending = false; @@ -664,17 +670,17 @@ static inline void usbd_dma_pending_clear(void) * If it is OUT endpoint transmission would be directed from endpoint to RAM. * If it is in endpoint transmission would be directed from RAM to endpoint. */ -static inline void usbd_dma_start(nrfx_usbd_ep_t ep) +static inline void usbd_dma_start(nrf_usbd_common_ep_t ep) { nrf_usbd_task_trigger(NRF_USBD, task_start_ep(ep)); } -void nrfx_usbd_isoinconfig_set(nrf_usbd_isoinconfig_t config) +void nrf_usbd_common_isoinconfig_set(nrf_usbd_isoinconfig_t config) { nrf_usbd_isoinconfig_set(NRF_USBD, config); } -nrf_usbd_isoinconfig_t nrfx_usbd_isoinconfig_get(void) +nrf_usbd_isoinconfig_t nrf_usbd_common_isoinconfig_get(void) { return nrf_usbd_isoinconfig_get(NRF_USBD); } @@ -692,10 +698,9 @@ nrf_usbd_isoinconfig_t nrfx_usbd_isoinconfig_get(void) * @endcode * This function would check it again, but it makes it inside critical section. */ -static inline void usbd_ep_abort(nrfx_usbd_ep_t ep) +static inline void usbd_ep_abort(nrf_usbd_common_ep_t ep) { - NRFX_CRITICAL_SECTION_ENTER(); - + unsigned int irq_lock_key = irq_lock(); usbd_ep_state_t *p_state = ep_state_access(ep); if (NRF_USBD_EPOUT_CHECK(ep)) { @@ -704,18 +709,18 @@ static inline void usbd_ep_abort(nrfx_usbd_ep_t ep) /* If the bit in m_ep_dma_waiting in cleared - nothing would be * processed inside transfer processing */ - nrfx_usbd_transfer_out_drop(ep); + nrf_usbd_common_transfer_out_drop(ep); } else { p_state->handler.consumer = NULL; m_ep_dma_waiting &= ~(1U << ep2bit(ep)); m_ep_ready &= ~(1U << ep2bit(ep)); } /* Aborted */ - p_state->status = NRFX_USBD_EP_ABORTED; + p_state->status = NRF_USBD_COMMON_EP_ABORTED; } else { if (!NRF_USBD_EPISO_CHECK(ep)) { /* Workaround: Disarm the endpoint if there is any data buffered. */ - if (ep != NRFX_USBD_EPIN0) { + if (ep != NRF_USBD_COMMON_EPIN0) { *((volatile uint32_t *)((uint32_t)(NRF_USBD) + 0x800)) = 0x7B6 + (2u * (NRF_USBD_EP_NR_GET(ep) - 1)); uint8_t temp = @@ -738,15 +743,16 @@ static inline void usbd_ep_abort(nrfx_usbd_ep_t ep) m_ep_ready |= 1U << ep2bit(ep); p_state->handler.feeder = NULL; - p_state->status = NRFX_USBD_EP_ABORTED; - NRFX_USBD_EP_TRANSFER_EVENT(evt, ep, NRFX_USBD_EP_ABORTED); + p_state->status = NRF_USBD_COMMON_EP_ABORTED; + NRF_USBD_COMMON_EP_TRANSFER_EVENT(evt, ep, NRF_USBD_COMMON_EP_ABORTED); m_event_handler(&evt); } } - NRFX_CRITICAL_SECTION_EXIT(); + + irq_unlock(irq_lock_key); } -void nrfx_usbd_ep_abort(nrfx_usbd_ep_t ep) +void nrf_usbd_common_ep_abort(nrf_usbd_common_ep_t ep) { usbd_ep_abort(ep); } @@ -758,7 +764,7 @@ void nrfx_usbd_ep_abort(nrfx_usbd_ep_t ep) */ static void usbd_ep_abort_all(void) { - uint32_t ep_waiting = m_ep_dma_waiting | (m_ep_ready & NRFX_USBD_EPOUT_BIT_MASK); + uint32_t ep_waiting = m_ep_dma_waiting | (m_ep_ready & NRF_USBD_COMMON_EPOUT_BIT_MASK); while (ep_waiting != 0) { uint8_t bitpos = NRF_CTZ(ep_waiting); @@ -769,7 +775,7 @@ static void usbd_ep_abort_all(void) ep_waiting &= ~(1U << bitpos); } - m_ep_ready = (((1U << NRF_USBD_EPIN_CNT) - 1U) << NRFX_USBD_EPIN_BITPOS_0); + m_ep_ready = (((1U << NRF_USBD_EPIN_CNT) - 1U) << NRF_USBD_COMMON_EPIN_BITPOS_0); } /** @@ -780,7 +786,7 @@ static void usbd_ep_abort_all(void) */ static inline void usbd_int_rise(void) { - NRFX_IRQ_PENDING_SET(USBD_IRQn); + NVIC_SetPendingIRQ(USBD_IRQn); } /** @@ -793,16 +799,16 @@ static inline void usbd_int_rise(void) static void ev_usbreset_handler(void) { m_bus_suspend = false; - m_last_setup_dir = NRFX_USBD_EPOUT0; + m_last_setup_dir = NRF_USBD_COMMON_EPOUT0; - const nrfx_usbd_evt_t evt = {.type = NRFX_USBD_EVT_RESET}; + const nrf_usbd_common_evt_t evt = {.type = NRF_USBD_COMMON_EVT_RESET}; m_event_handler(&evt); } static void ev_started_handler(void) { -#if NRFX_USBD_STARTED_EV_ENABLE +#if NRF_USBD_COMMON_STARTED_EV_ENABLE /* Handler not used by the stack. * May be used for debugging. */ @@ -820,18 +826,18 @@ static void ev_started_handler(void) */ static inline void nrf_usbd_ep0in_dma_handler(void) { - const nrfx_usbd_ep_t ep = NRFX_USBD_EPIN0; + const nrf_usbd_common_ep_t ep = NRF_USBD_COMMON_EPIN0; - NRFX_LOG_DEBUG("USB event: DMA ready IN0"); + LOG_DBG("USB event: DMA ready IN0"); usbd_dma_pending_clear(); usbd_ep_state_t *p_state = ep_state_access(ep); - if (p_state->status == NRFX_USBD_EP_ABORTED) { + if (p_state->status == NRF_USBD_COMMON_EP_ABORTED) { /* Clear transfer information just in case */ - (void)(NRFX_ATOMIC_FETCH_AND(&m_ep_dma_waiting, ~(1U << ep2bit(ep)))); + (void)(atomic_and(&m_ep_dma_waiting, ~(1U << ep2bit(ep)))); } else if (p_state->handler.feeder == NULL) { - (void)(NRFX_ATOMIC_FETCH_AND(&m_ep_dma_waiting, ~(1U << ep2bit(ep)))); + (void)(atomic_and(&m_ep_dma_waiting, ~(1U << ep2bit(ep)))); } else { /* Nothing to do */ } @@ -846,21 +852,21 @@ static inline void nrf_usbd_ep0in_dma_handler(void) * * @param[in] ep Endpoint number. */ -static inline void nrf_usbd_epin_dma_handler(nrfx_usbd_ep_t ep) +static inline void nrf_usbd_epin_dma_handler(nrf_usbd_common_ep_t ep) { - NRFX_LOG_DEBUG("USB event: DMA ready IN: %x", ep); - NRFX_ASSERT(NRF_USBD_EPIN_CHECK(ep)); - NRFX_ASSERT(!NRF_USBD_EPISO_CHECK(ep)); - NRFX_ASSERT(NRF_USBD_EP_NR_GET(ep) > 0); + LOG_DBG("USB event: DMA ready IN: %x", ep); + __ASSERT_NO_MSG(NRF_USBD_EPIN_CHECK(ep)); + __ASSERT_NO_MSG(!NRF_USBD_EPISO_CHECK(ep)); + __ASSERT_NO_MSG(NRF_USBD_EP_NR_GET(ep) > 0); usbd_dma_pending_clear(); usbd_ep_state_t *p_state = ep_state_access(ep); - if (p_state->status == NRFX_USBD_EP_ABORTED) { + if (p_state->status == NRF_USBD_COMMON_EP_ABORTED) { /* Clear transfer information just in case */ - (void)(NRFX_ATOMIC_FETCH_AND(&m_ep_dma_waiting, ~(1U << ep2bit(ep)))); + (void)(atomic_and(&m_ep_dma_waiting, ~(1U << ep2bit(ep)))); } else if (p_state->handler.feeder == NULL) { - (void)(NRFX_ATOMIC_FETCH_AND(&m_ep_dma_waiting, ~(1U << ep2bit(ep)))); + (void)(atomic_and(&m_ep_dma_waiting, ~(1U << ep2bit(ep)))); } else { /* Nothing to do */ } @@ -869,26 +875,26 @@ static inline void nrf_usbd_epin_dma_handler(nrfx_usbd_ep_t ep) /** * @brief Handler for EasyDMA event from in isochronous endpoint. */ -static inline void nrf_usbd_epiniso_dma_handler(nrfx_usbd_ep_t ep) +static inline void nrf_usbd_epiniso_dma_handler(nrf_usbd_common_ep_t ep) { - if (NRFX_USBD_ISO_DEBUG) { - NRFX_LOG_DEBUG("USB event: DMA ready ISOIN: %x", ep); + if (NRF_USBD_COMMON_ISO_DEBUG) { + LOG_DBG("USB event: DMA ready ISOIN: %x", ep); } - NRFX_ASSERT(NRF_USBD_EPIN_CHECK(ep)); - NRFX_ASSERT(NRF_USBD_EPISO_CHECK(ep)); + __ASSERT_NO_MSG(NRF_USBD_EPIN_CHECK(ep)); + __ASSERT_NO_MSG(NRF_USBD_EPISO_CHECK(ep)); usbd_dma_pending_clear(); usbd_ep_state_t *p_state = ep_state_access(ep); - if (p_state->status == NRFX_USBD_EP_ABORTED) { + if (p_state->status == NRF_USBD_COMMON_EP_ABORTED) { /* Clear transfer information just in case */ - (void)(NRFX_ATOMIC_FETCH_AND(&m_ep_dma_waiting, ~(1U << ep2bit(ep)))); + (void)(atomic_and(&m_ep_dma_waiting, ~(1U << ep2bit(ep)))); } else if (p_state->handler.feeder == NULL) { - (void)(NRFX_ATOMIC_FETCH_AND(&m_ep_dma_waiting, ~(1U << ep2bit(ep)))); + (void)(atomic_and(&m_ep_dma_waiting, ~(1U << ep2bit(ep)))); /* Send event to the user - for an ISO IN endpoint, the whole transfer is finished * in this moment */ - NRFX_USBD_EP_TRANSFER_EVENT(evt, ep, NRFX_USBD_EP_OK); + NRF_USBD_COMMON_EP_TRANSFER_EVENT(evt, ep, NRF_USBD_COMMON_EP_OK); m_event_handler(&evt); } else { /* Nothing to do */ @@ -904,25 +910,25 @@ static inline void nrf_usbd_epiniso_dma_handler(nrfx_usbd_ep_t ep) */ static inline void nrf_usbd_ep0out_dma_handler(void) { - const nrfx_usbd_ep_t ep = NRFX_USBD_EPOUT0; + const nrf_usbd_common_ep_t ep = NRF_USBD_COMMON_EPOUT0; - NRFX_LOG_DEBUG("USB event: DMA ready OUT0"); + LOG_DBG("USB event: DMA ready OUT0"); usbd_dma_pending_clear(); usbd_ep_state_t *p_state = ep_state_access(ep); - if (p_state->status == NRFX_USBD_EP_ABORTED) { + if (p_state->status == NRF_USBD_COMMON_EP_ABORTED) { /* Clear transfer information just in case */ - (void)(NRFX_ATOMIC_FETCH_AND(&m_ep_dma_waiting, ~(1U << ep2bit(ep)))); + (void)(atomic_and(&m_ep_dma_waiting, ~(1U << ep2bit(ep)))); } else if (p_state->handler.consumer == NULL) { - (void)(NRFX_ATOMIC_FETCH_AND(&m_ep_dma_waiting, ~(1U << ep2bit(ep)))); + (void)(atomic_and(&m_ep_dma_waiting, ~(1U << ep2bit(ep)))); /* Send event to the user - for an OUT endpoint, the whole transfer is finished in * this moment */ - NRFX_USBD_EP_TRANSFER_EVENT(evt, ep, NRFX_USBD_EP_OK); + NRF_USBD_COMMON_EP_TRANSFER_EVENT(evt, ep, NRF_USBD_COMMON_EP_OK); m_event_handler(&evt); } else { - nrfx_usbd_setup_data_clear(); + nrf_usbd_common_setup_data_clear(); } } @@ -933,31 +939,31 @@ static inline void nrf_usbd_ep0out_dma_handler(void) * * @param[in] ep Endpoint number. */ -static inline void nrf_usbd_epout_dma_handler(nrfx_usbd_ep_t ep) +static inline void nrf_usbd_epout_dma_handler(nrf_usbd_common_ep_t ep) { - NRFX_LOG_DEBUG("DMA ready OUT: %x", ep); - NRFX_ASSERT(NRF_USBD_EPOUT_CHECK(ep)); - NRFX_ASSERT(!NRF_USBD_EPISO_CHECK(ep)); - NRFX_ASSERT(NRF_USBD_EP_NR_GET(ep) > 0); + LOG_DBG("DMA ready OUT: %x", ep); + __ASSERT_NO_MSG(NRF_USBD_EPOUT_CHECK(ep)); + __ASSERT_NO_MSG(!NRF_USBD_EPISO_CHECK(ep)); + __ASSERT_NO_MSG(NRF_USBD_EP_NR_GET(ep) > 0); usbd_dma_pending_clear(); usbd_ep_state_t *p_state = ep_state_access(ep); - if (p_state->status == NRFX_USBD_EP_ABORTED) { + if (p_state->status == NRF_USBD_COMMON_EP_ABORTED) { /* Clear transfer information just in case */ - (void)(NRFX_ATOMIC_FETCH_AND(&m_ep_dma_waiting, ~(1U << ep2bit(ep)))); + (void)(atomic_and(&m_ep_dma_waiting, ~(1U << ep2bit(ep)))); } else if (p_state->handler.consumer == NULL) { - (void)(NRFX_ATOMIC_FETCH_AND(&m_ep_dma_waiting, ~(1U << ep2bit(ep)))); + (void)(atomic_and(&m_ep_dma_waiting, ~(1U << ep2bit(ep)))); /* Send event to the user - for an OUT endpoint, the whole transfer is finished in * this moment */ - NRFX_USBD_EP_TRANSFER_EVENT(evt, ep, NRFX_USBD_EP_OK); + NRF_USBD_COMMON_EP_TRANSFER_EVENT(evt, ep, NRF_USBD_COMMON_EP_OK); m_event_handler(&evt); } else { /* Nothing to do */ } -#if NRFX_USBD_EARLY_DMA_PROCESS +#if NRF_USBD_COMMON_EARLY_DMA_PROCESS /* Speed up */ usbd_dmareq_process(); #endif @@ -966,24 +972,24 @@ static inline void nrf_usbd_epout_dma_handler(nrfx_usbd_ep_t ep) /** * @brief Handler for EasyDMA event from out isochronous endpoint. */ -static inline void nrf_usbd_epoutiso_dma_handler(nrfx_usbd_ep_t ep) +static inline void nrf_usbd_epoutiso_dma_handler(nrf_usbd_common_ep_t ep) { - if (NRFX_USBD_ISO_DEBUG) { - NRFX_LOG_DEBUG("DMA ready ISOOUT: %x", ep); + if (NRF_USBD_COMMON_ISO_DEBUG) { + LOG_DBG("DMA ready ISOOUT: %x", ep); } - NRFX_ASSERT(NRF_USBD_EPISO_CHECK(ep)); + __ASSERT_NO_MSG(NRF_USBD_EPISO_CHECK(ep)); usbd_dma_pending_clear(); usbd_ep_state_t *p_state = ep_state_access(ep); - if (p_state->status == NRFX_USBD_EP_ABORTED) { + if (p_state->status == NRF_USBD_COMMON_EP_ABORTED) { /* Nothing to do - just ignore */ } else if (p_state->handler.consumer == NULL) { - (void)(NRFX_ATOMIC_FETCH_AND(&m_ep_dma_waiting, ~(1U << ep2bit(ep)))); + (void)(atomic_and(&m_ep_dma_waiting, ~(1U << ep2bit(ep)))); /* Send event to the user - for an OUT endpoint, the whole transfer is finished in * this moment */ - NRFX_USBD_EP_TRANSFER_EVENT(evt, ep, NRFX_USBD_EP_OK); + NRF_USBD_COMMON_EP_TRANSFER_EVENT(evt, ep, NRF_USBD_COMMON_EP_OK); m_event_handler(&evt); } else { /* Nothing to do */ @@ -996,35 +1002,35 @@ static void ev_dma_epin0_handler(void) } static void ev_dma_epin1_handler(void) { - nrf_usbd_epin_dma_handler(NRFX_USBD_EPIN1); + nrf_usbd_epin_dma_handler(NRF_USBD_COMMON_EPIN1); } static void ev_dma_epin2_handler(void) { - nrf_usbd_epin_dma_handler(NRFX_USBD_EPIN2); + nrf_usbd_epin_dma_handler(NRF_USBD_COMMON_EPIN2); } static void ev_dma_epin3_handler(void) { - nrf_usbd_epin_dma_handler(NRFX_USBD_EPIN3); + nrf_usbd_epin_dma_handler(NRF_USBD_COMMON_EPIN3); } static void ev_dma_epin4_handler(void) { - nrf_usbd_epin_dma_handler(NRFX_USBD_EPIN4); + nrf_usbd_epin_dma_handler(NRF_USBD_COMMON_EPIN4); } static void ev_dma_epin5_handler(void) { - nrf_usbd_epin_dma_handler(NRFX_USBD_EPIN5); + nrf_usbd_epin_dma_handler(NRF_USBD_COMMON_EPIN5); } static void ev_dma_epin6_handler(void) { - nrf_usbd_epin_dma_handler(NRFX_USBD_EPIN6); + nrf_usbd_epin_dma_handler(NRF_USBD_COMMON_EPIN6); } static void ev_dma_epin7_handler(void) { - nrf_usbd_epin_dma_handler(NRFX_USBD_EPIN7); + nrf_usbd_epin_dma_handler(NRF_USBD_COMMON_EPIN7); } static void ev_dma_epin8_handler(void) { - nrf_usbd_epiniso_dma_handler(NRFX_USBD_EPIN8); + nrf_usbd_epiniso_dma_handler(NRF_USBD_COMMON_EPIN8); } static void ev_dma_epout0_handler(void) @@ -1033,48 +1039,49 @@ static void ev_dma_epout0_handler(void) } static void ev_dma_epout1_handler(void) { - nrf_usbd_epout_dma_handler(NRFX_USBD_EPOUT1); + nrf_usbd_epout_dma_handler(NRF_USBD_COMMON_EPOUT1); } static void ev_dma_epout2_handler(void) { - nrf_usbd_epout_dma_handler(NRFX_USBD_EPOUT2); + nrf_usbd_epout_dma_handler(NRF_USBD_COMMON_EPOUT2); } static void ev_dma_epout3_handler(void) { - nrf_usbd_epout_dma_handler(NRFX_USBD_EPOUT3); + nrf_usbd_epout_dma_handler(NRF_USBD_COMMON_EPOUT3); } static void ev_dma_epout4_handler(void) { - nrf_usbd_epout_dma_handler(NRFX_USBD_EPOUT4); + nrf_usbd_epout_dma_handler(NRF_USBD_COMMON_EPOUT4); } static void ev_dma_epout5_handler(void) { - nrf_usbd_epout_dma_handler(NRFX_USBD_EPOUT5); + nrf_usbd_epout_dma_handler(NRF_USBD_COMMON_EPOUT5); } static void ev_dma_epout6_handler(void) { - nrf_usbd_epout_dma_handler(NRFX_USBD_EPOUT6); + nrf_usbd_epout_dma_handler(NRF_USBD_COMMON_EPOUT6); } static void ev_dma_epout7_handler(void) { - nrf_usbd_epout_dma_handler(NRFX_USBD_EPOUT7); + nrf_usbd_epout_dma_handler(NRF_USBD_COMMON_EPOUT7); } static void ev_dma_epout8_handler(void) { - nrf_usbd_epoutiso_dma_handler(NRFX_USBD_EPOUT8); + nrf_usbd_epoutiso_dma_handler(NRF_USBD_COMMON_EPOUT8); } static void ev_sof_handler(void) { - nrfx_usbd_evt_t evt = { - NRFX_USBD_EVT_SOF, + nrf_usbd_common_evt_t evt = { + NRF_USBD_COMMON_EVT_SOF, .data = {.sof = {.framecnt = (uint16_t)nrf_usbd_framecntr_get(NRF_USBD)}}}; /* Process isochronous endpoints */ - uint32_t iso_ready_mask = (1U << ep2bit(NRFX_USBD_EPIN8)); + uint32_t iso_ready_mask = (1U << ep2bit(NRF_USBD_COMMON_EPIN8)); - if (nrf_usbd_episoout_size_get(NRF_USBD, NRFX_USBD_EPOUT8) != NRF_USBD_EPISOOUT_NO_DATA) { - iso_ready_mask |= (1U << ep2bit(NRFX_USBD_EPOUT8)); + if (nrf_usbd_episoout_size_get(NRF_USBD, NRF_USBD_COMMON_EPOUT8) != + NRF_USBD_EPISOOUT_NO_DATA) { + iso_ready_mask |= (1U << ep2bit(NRF_USBD_COMMON_EPOUT8)); } m_ep_ready |= iso_ready_mask; @@ -1088,9 +1095,9 @@ static void ev_sof_handler(void) * @param ep Endpoint number. * @param bitpos Bit position for selected endpoint number. */ -static void usbd_ep_data_handler(nrfx_usbd_ep_t ep, uint8_t bitpos) +static void usbd_ep_data_handler(nrf_usbd_common_ep_t ep, uint8_t bitpos) { - NRFX_LOG_DEBUG("USBD event: EndpointData: %x", ep); + LOG_DBG("USBD event: EndpointData: %x", ep); /* Mark endpoint ready for next DMA access */ m_ep_ready |= (1U << bitpos); @@ -1103,8 +1110,8 @@ static void usbd_ep_data_handler(nrfx_usbd_ep_t ep, uint8_t bitpos) * process, the OUT handler might call usbd_ep_data_handler without calling * nrf_usbd_epin_dma_handler (or nrf_usbd_ep0in_dma_handler) for the IN transaction. */ - if (nrf_usbd_event_get_and_clear(NRF_USBD, nrfx_usbd_ep_to_endevent(ep))) { - if (ep != NRFX_USBD_EPIN0) { + if (nrf_usbd_event_get_and_clear(NRF_USBD, nrf_usbd_common_ep_to_endevent(ep))) { + if (ep != NRF_USBD_COMMON_EPIN0) { nrf_usbd_epin_dma_handler(ep); } else { nrf_usbd_ep0in_dma_handler(); @@ -1112,17 +1119,17 @@ static void usbd_ep_data_handler(nrfx_usbd_ep_t ep, uint8_t bitpos) } if (0 == (m_ep_dma_waiting & (1U << bitpos))) { - NRFX_LOG_DEBUG("USBD event: EndpointData: In finished"); + LOG_DBG("USBD event: EndpointData: In finished"); /* No more data to be send - transmission finished */ - NRFX_USBD_EP_TRANSFER_EVENT(evt, ep, NRFX_USBD_EP_OK); + NRF_USBD_COMMON_EP_TRANSFER_EVENT(evt, ep, NRF_USBD_COMMON_EP_OK); m_event_handler(&evt); } } else { /* OUT endpoint (Host -> Device) */ if (0 == (m_ep_dma_waiting & (1U << bitpos))) { - NRFX_LOG_DEBUG("USBD event: EndpointData: Out waiting"); + LOG_DBG("USBD event: EndpointData: Out waiting"); /* No buffer prepared - send event to the application */ - NRFX_USBD_EP_TRANSFER_EVENT(evt, ep, NRFX_USBD_EP_WAITING); + NRF_USBD_COMMON_EP_TRANSFER_EVENT(evt, ep, NRF_USBD_COMMON_EP_WAITING); m_event_handler(&evt); } } @@ -1135,29 +1142,29 @@ static void ev_setup_data_handler(void) static void ev_setup_handler(void) { - NRFX_LOG_DEBUG("USBD event: Setup (rt:%.2x r:%.2x v:%.4x i:%.4x l:%u )", + LOG_DBG("USBD event: Setup (rt:%.2x r:%.2x v:%.4x i:%.4x l:%u )", nrf_usbd_setup_bmrequesttype_get(NRF_USBD), nrf_usbd_setup_brequest_get(NRF_USBD), nrf_usbd_setup_wvalue_get(NRF_USBD), nrf_usbd_setup_windex_get(NRF_USBD), nrf_usbd_setup_wlength_get(NRF_USBD)); uint8_t bmRequestType = nrf_usbd_setup_bmrequesttype_get(NRF_USBD); - if ((m_ep_dma_waiting | ((~m_ep_ready) & NRFX_USBD_EPIN_BIT_MASK)) & + if ((m_ep_dma_waiting | ((~m_ep_ready) & NRF_USBD_COMMON_EPIN_BIT_MASK)) & (1U << ep2bit(m_last_setup_dir))) { - NRFX_LOG_DEBUG("USBD drv: Trying to abort last transfer on EP0"); + LOG_DBG("USBD drv: Trying to abort last transfer on EP0"); usbd_ep_abort(m_last_setup_dir); } m_last_setup_dir = ((bmRequestType & USBD_BMREQUESTTYPE_DIRECTION_Msk) == (USBD_BMREQUESTTYPE_DIRECTION_HostToDevice << USBD_BMREQUESTTYPE_DIRECTION_Pos)) - ? NRFX_USBD_EPOUT0 - : NRFX_USBD_EPIN0; + ? NRF_USBD_COMMON_EPOUT0 + : NRF_USBD_COMMON_EPIN0; - (void)(NRFX_ATOMIC_FETCH_AND(&m_ep_dma_waiting, ~((1U << ep2bit(NRFX_USBD_EPOUT0)) | - (1U << ep2bit(NRFX_USBD_EPIN0))))); - m_ep_ready |= 1U << ep2bit(NRFX_USBD_EPIN0); + (void)(atomic_and(&m_ep_dma_waiting, ~((1U << ep2bit(NRF_USBD_COMMON_EPOUT0)) | + (1U << ep2bit(NRF_USBD_COMMON_EPIN0))))); + m_ep_ready |= 1U << ep2bit(NRF_USBD_COMMON_EPIN0); - const nrfx_usbd_evt_t evt = {.type = NRFX_USBD_EVT_SETUP}; + const nrf_usbd_common_evt_t evt = {.type = NRF_USBD_COMMON_EVT_SETUP}; m_event_handler(&evt); } @@ -1167,33 +1174,33 @@ static void ev_usbevent_handler(void) uint32_t event = nrf_usbd_eventcause_get_and_clear(NRF_USBD); if (event & NRF_USBD_EVENTCAUSE_ISOOUTCRC_MASK) { - NRFX_LOG_DEBUG("USBD event: ISOOUTCRC"); + LOG_DBG("USBD event: ISOOUTCRC"); /* Currently no support */ } if (event & NRF_USBD_EVENTCAUSE_SUSPEND_MASK) { - NRFX_LOG_DEBUG("USBD event: SUSPEND"); + LOG_DBG("USBD event: SUSPEND"); m_bus_suspend = true; - const nrfx_usbd_evt_t evt = {.type = NRFX_USBD_EVT_SUSPEND}; + const nrf_usbd_common_evt_t evt = {.type = NRF_USBD_COMMON_EVT_SUSPEND}; m_event_handler(&evt); } if (event & NRF_USBD_EVENTCAUSE_RESUME_MASK) { - NRFX_LOG_DEBUG("USBD event: RESUME"); + LOG_DBG("USBD event: RESUME"); m_bus_suspend = false; - const nrfx_usbd_evt_t evt = {.type = NRFX_USBD_EVT_RESUME}; + const nrf_usbd_common_evt_t evt = {.type = NRF_USBD_COMMON_EVT_RESUME}; m_event_handler(&evt); } if (event & NRF_USBD_EVENTCAUSE_WUREQ_MASK) { - NRFX_LOG_DEBUG("USBD event: WUREQ (%s)", m_bus_suspend ? "In Suspend" : "Active"); + LOG_DBG("USBD event: WUREQ (%s)", m_bus_suspend ? "In Suspend" : "Active"); if (m_bus_suspend) { - NRFX_ASSERT(!nrf_usbd_lowpower_check(NRF_USBD)); + __ASSERT_NO_MSG(!nrf_usbd_lowpower_check(NRF_USBD)); m_bus_suspend = false; nrf_usbd_dpdmvalue_set(NRF_USBD, NRF_USBD_DPDMVALUE_RESUME); nrf_usbd_task_trigger(NRF_USBD, NRF_USBD_TASK_DRIVEDPDM); - const nrfx_usbd_evt_t evt = {.type = NRFX_USBD_EVT_WUREQ}; + const nrf_usbd_common_evt_t evt = {.type = NRF_USBD_COMMON_EVT_WUREQ}; m_event_handler(&evt); } @@ -1205,18 +1212,18 @@ static void ev_epdata_handler(void) /* Get all endpoints that have acknowledged transfer */ uint32_t dataepstatus = nrf_usbd_epdatastatus_get_and_clear(NRF_USBD); - NRFX_LOG_DEBUG("USBD event: EndpointEPStatus: %x", dataepstatus); + LOG_DBG("USBD event: EndpointEPStatus: %x", dataepstatus); /* All finished endpoint have to be marked as busy */ while (dataepstatus) { uint8_t bitpos = NRF_CTZ(dataepstatus); - nrfx_usbd_ep_t ep = bit2ep(bitpos); + nrf_usbd_common_ep_t ep = bit2ep(bitpos); dataepstatus &= ~(1UL << bitpos); (void)(usbd_ep_data_handler(ep, bitpos)); } - if (NRFX_USBD_EARLY_DMA_PROCESS) { + if (NRF_USBD_COMMON_EARLY_DMA_PROCESS) { /* Speed up */ usbd_dmareq_process(); } @@ -1252,15 +1259,15 @@ static uint8_t usbd_dma_scheduler_algorithm(uint32_t req) * * @return The size of endpoint buffer. */ -static inline size_t usbd_ep_iso_capacity(nrfx_usbd_ep_t ep) +static inline size_t usbd_ep_iso_capacity(nrf_usbd_common_ep_t ep) { (void)ep; nrf_usbd_isosplit_t split = nrf_usbd_isosplit_get(NRF_USBD); if (split == NRF_USBD_ISOSPLIT_HALF) { - return NRFX_USBD_ISOSIZE / 2; + return NRF_USBD_COMMON_ISOSIZE / 2; } - return NRFX_USBD_ISOSIZE; + return NRF_USBD_COMMON_ISOSIZE; } /** @@ -1284,15 +1291,16 @@ static void usbd_dmareq_process(void) } else { pos = usbd_dma_scheduler_algorithm(req); } - nrfx_usbd_ep_t ep = bit2ep(pos); + nrf_usbd_common_ep_t ep = bit2ep(pos); usbd_ep_state_t *p_state = ep_state_access(ep); - nrfx_usbd_ep_transfer_t transfer; + nrf_usbd_common_ep_transfer_t transfer; bool continue_transfer; - NRFX_STATIC_ASSERT(offsetof(usbd_ep_state_t, handler.feeder) == - offsetof(usbd_ep_state_t, handler.consumer)); - NRFX_ASSERT((p_state->handler.feeder) != NULL); + BUILD_ASSERT(offsetof(usbd_ep_state_t, handler.feeder) == + offsetof(usbd_ep_state_t, handler.consumer), + "feeder and consumer must be in union"); + __ASSERT_NO_MSG((p_state->handler.feeder) != NULL); if (NRF_USBD_EPIN_CHECK(ep)) { /* Device -> Host */ @@ -1304,7 +1312,7 @@ static void usbd_dmareq_process(void) } } else { /* Host -> Device */ - const size_t rx_size = nrfx_usbd_epout_size_get(ep); + const size_t rx_size = nrf_usbd_common_epout_size_get(ep); continue_transfer = p_state->handler.consumer( &transfer, p_state->p_context, p_state->max_packet_size, @@ -1312,14 +1320,14 @@ static void usbd_dmareq_process(void) if (transfer.p_data.rx == NULL) { /* Dropping transfer - allow processing */ - NRFX_ASSERT(transfer.size == 0); + __ASSERT_NO_MSG(transfer.size == 0); } else if (transfer.size < rx_size) { - NRFX_LOG_DEBUG("Endpoint %x overload (r: %u, e: %u)", ep, + LOG_DBG("Endpoint %x overload (r: %u, e: %u)", ep, rx_size, transfer.size); - p_state->status = NRFX_USBD_EP_OVERLOAD; - (void)(NRFX_ATOMIC_FETCH_AND(&m_ep_dma_waiting, - ~(1U << pos))); - NRFX_USBD_EP_TRANSFER_EVENT(evt, ep, NRFX_USBD_EP_OVERLOAD); + p_state->status = NRF_USBD_COMMON_EP_OVERLOAD; + (void)(atomic_and(&m_ep_dma_waiting, ~(1U << pos))); + NRF_USBD_COMMON_EP_TRANSFER_EVENT(evt, ep, + NRF_USBD_COMMON_EP_OVERLOAD); m_event_handler(&evt); /* This endpoint will not be transmitted now, repeat the * loop @@ -1329,7 +1337,7 @@ static void usbd_dmareq_process(void) /* Nothing to do - only check integrity if assertions are * enabled */ - NRFX_ASSERT(transfer.size == rx_size); + __ASSERT_NO_MSG(transfer.size == rx_size); } if (!continue_transfer) { @@ -1339,9 +1347,8 @@ static void usbd_dmareq_process(void) usbd_dma_pending_set(); m_ep_ready &= ~(1U << pos); - if (NRFX_USBD_ISO_DEBUG || (!NRF_USBD_EPISO_CHECK(ep))) { - NRFX_LOG_DEBUG( - "USB DMA process: Starting transfer on EP: %x, size: %u", + if (NRF_USBD_COMMON_ISO_DEBUG || (!NRF_USBD_EPISO_CHECK(ep))) { + LOG_DBG("USB DMA process: Starting transfer on EP: %x, size: %u", ep, transfer.size); } /* Update number of currently transferred bytes */ @@ -1355,21 +1362,22 @@ static void usbd_dmareq_process(void) * transfer. This is quick fix to maintain stability of the stack. It cost * some performance but makes stack stable. */ - while (!nrf_usbd_event_check(NRF_USBD, nrfx_usbd_ep_to_endevent(ep))) { + while (!nrf_usbd_event_check(NRF_USBD, + nrf_usbd_common_ep_to_endevent(ep))) { /* Empty */ } /* DMA finished, track if total bytes transferred is even or odd */ m_dma_odd ^= nrf_usbd_ep_amount_get(NRF_USBD, ep) & 1; - if (NRFX_USBD_DMAREQ_PROCESS_DEBUG) { - NRFX_LOG_DEBUG("USB DMA process - finishing"); + if (NRF_USBD_COMMON_DMAREQ_PROCESS_DEBUG) { + LOG_DBG("USB DMA process - finishing"); } /* Transfer started - exit the loop */ break; } } else { - if (NRFX_USBD_DMAREQ_PROCESS_DEBUG) { - NRFX_LOG_DEBUG("USB DMA process - EasyDMA busy"); + if (NRF_USBD_COMMON_DMAREQ_PROCESS_DEBUG) { + LOG_DBG("USB DMA process - EasyDMA busy"); } } } @@ -1390,7 +1398,8 @@ static inline void usbd_eventcause_wait_and_clear(nrf_usbd_eventcause_mask_t eve */ static inline void usbd_errata_171_begin(void) { - NRFX_CRITICAL_SECTION_ENTER(); + unsigned int irq_lock_key = irq_lock(); + if (*((volatile uint32_t *)(0x4006EC00)) == 0x00000000) { *((volatile uint32_t *)(0x4006EC00)) = 0x00009375; *((volatile uint32_t *)(0x4006EC14)) = 0x000000C0; @@ -1398,7 +1407,8 @@ static inline void usbd_errata_171_begin(void) } else { *((volatile uint32_t *)(0x4006EC14)) = 0x000000C0; } - NRFX_CRITICAL_SECTION_EXIT(); + + irq_unlock(irq_lock_key); } /** @@ -1406,7 +1416,8 @@ static inline void usbd_errata_171_begin(void) */ static inline void usbd_errata_171_end(void) { - NRFX_CRITICAL_SECTION_ENTER(); + unsigned int irq_lock_key = irq_lock(); + if (*((volatile uint32_t *)(0x4006EC00)) == 0x00000000) { *((volatile uint32_t *)(0x4006EC00)) = 0x00009375; *((volatile uint32_t *)(0x4006EC14)) = 0x00000000; @@ -1414,7 +1425,8 @@ static inline void usbd_errata_171_end(void) } else { *((volatile uint32_t *)(0x4006EC14)) = 0x00000000; } - NRFX_CRITICAL_SECTION_EXIT(); + + irq_unlock(irq_lock_key); } /** @@ -1422,7 +1434,8 @@ static inline void usbd_errata_171_end(void) */ static inline void usbd_errata_187_211_begin(void) { - NRFX_CRITICAL_SECTION_ENTER(); + unsigned int irq_lock_key = irq_lock(); + if (*((volatile uint32_t *)(0x4006EC00)) == 0x00000000) { *((volatile uint32_t *)(0x4006EC00)) = 0x00009375; *((volatile uint32_t *)(0x4006ED14)) = 0x00000003; @@ -1430,7 +1443,8 @@ static inline void usbd_errata_187_211_begin(void) } else { *((volatile uint32_t *)(0x4006ED14)) = 0x00000003; } - NRFX_CRITICAL_SECTION_EXIT(); + + irq_unlock(irq_lock_key); } /** @@ -1438,7 +1452,8 @@ static inline void usbd_errata_187_211_begin(void) */ static inline void usbd_errata_187_211_end(void) { - NRFX_CRITICAL_SECTION_ENTER(); + unsigned int irq_lock_key = irq_lock(); + if (*((volatile uint32_t *)(0x4006EC00)) == 0x00000000) { *((volatile uint32_t *)(0x4006EC00)) = 0x00009375; *((volatile uint32_t *)(0x4006ED14)) = 0x00000000; @@ -1446,7 +1461,8 @@ static inline void usbd_errata_187_211_end(void) } else { *((volatile uint32_t *)(0x4006ED14)) = 0x00000000; } - NRFX_CRITICAL_SECTION_EXIT(); + + irq_unlock(irq_lock_key); } /** @@ -1454,11 +1470,11 @@ static inline void usbd_errata_187_211_end(void) */ static void usbd_enable(void) { - if (nrfx_usbd_errata_187()) { + if (nrf_usbd_common_errata_187()) { usbd_errata_187_211_begin(); } - if (nrfx_usbd_errata_171()) { + if (nrf_usbd_common_errata_171()) { usbd_errata_171_begin(); } @@ -1468,11 +1484,11 @@ static void usbd_enable(void) /* Waiting for peripheral to enable, this should take a few us */ usbd_eventcause_wait_and_clear(NRF_USBD_EVENTCAUSE_READY_MASK); - if (nrfx_usbd_errata_171()) { + if (nrf_usbd_common_errata_171()) { usbd_errata_171_end(); } - if (nrfx_usbd_errata_187()) { + if (nrf_usbd_common_errata_187()) { usbd_errata_187_211_end(); } } @@ -1513,7 +1529,7 @@ static const nrfx_irq_handler_t m_isr[] = {[USBD_INTEN_USBRESET_Pos] = ev_usbres * * @{ */ -void nrfx_usbd_irq_handler(void) +void nrf_usbd_common_irq_handler(void) { const uint32_t enabled = nrf_usbd_int_enable_get(NRF_USBD); uint32_t to_process = enabled; @@ -1551,9 +1567,9 @@ void nrfx_usbd_irq_handler(void) /** @} */ /** @} */ -nrfx_err_t nrfx_usbd_init(nrfx_usbd_event_handler_t event_handler) +nrfx_err_t nrf_usbd_common_init(nrf_usbd_common_event_handler_t event_handler) { - NRFX_ASSERT(event_handler); + __ASSERT_NO_MSG(event_handler); if (m_drv_state != NRFX_DRV_STATE_UNINITIALIZED) { return NRFX_ERROR_INVALID_STATE; @@ -1565,24 +1581,24 @@ nrfx_err_t nrfx_usbd_init(nrfx_usbd_event_handler_t event_handler) uint8_t n; for (n = 0; n < NRF_USBD_EPIN_CNT; ++n) { - nrfx_usbd_ep_t ep = NRFX_USBD_EPIN(n); + nrf_usbd_common_ep_t ep = NRF_USBD_COMMON_EPIN(n); - nrfx_usbd_ep_max_packet_size_set( - ep, NRF_USBD_EPISO_CHECK(ep) ? (NRFX_USBD_ISOSIZE / 2) : NRFX_USBD_EPSIZE); + nrf_usbd_common_ep_max_packet_size_set(ep, NRF_USBD_EPISO_CHECK(ep) ? + (NRF_USBD_COMMON_ISOSIZE / 2) : NRF_USBD_COMMON_EPSIZE); usbd_ep_state_t *p_state = ep_state_access(ep); - p_state->status = NRFX_USBD_EP_OK; + p_state->status = NRF_USBD_COMMON_EP_OK; p_state->handler.feeder = NULL; p_state->transfer_cnt = 0; } for (n = 0; n < NRF_USBD_EPOUT_CNT; ++n) { - nrfx_usbd_ep_t ep = NRFX_USBD_EPOUT(n); + nrf_usbd_common_ep_t ep = NRF_USBD_COMMON_EPOUT(n); - nrfx_usbd_ep_max_packet_size_set( - ep, NRF_USBD_EPISO_CHECK(ep) ? (NRFX_USBD_ISOSIZE / 2) : NRFX_USBD_EPSIZE); + nrf_usbd_common_ep_max_packet_size_set(ep, NRF_USBD_EPISO_CHECK(ep) ? + (NRF_USBD_COMMON_ISOSIZE / 2) : NRF_USBD_COMMON_EPSIZE); usbd_ep_state_t *p_state = ep_state_access(ep); - p_state->status = NRFX_USBD_EP_OK; + p_state->status = NRF_USBD_COMMON_EP_OK; p_state->handler.consumer = NULL; p_state->transfer_cnt = 0; } @@ -1590,24 +1606,24 @@ nrfx_err_t nrfx_usbd_init(nrfx_usbd_event_handler_t event_handler) return NRFX_SUCCESS; } -void nrfx_usbd_uninit(void) +void nrf_usbd_common_uninit(void) { - NRFX_ASSERT(m_drv_state == NRFX_DRV_STATE_INITIALIZED); + __ASSERT_NO_MSG(m_drv_state == NRFX_DRV_STATE_INITIALIZED); m_event_handler = NULL; m_drv_state = NRFX_DRV_STATE_UNINITIALIZED; } -void nrfx_usbd_enable(void) +void nrf_usbd_common_enable(void) { - NRFX_ASSERT(m_drv_state == NRFX_DRV_STATE_INITIALIZED); + __ASSERT_NO_MSG(m_drv_state == NRFX_DRV_STATE_INITIALIZED); /* Prepare for READY event receiving */ nrf_usbd_eventcause_clear(NRF_USBD, NRF_USBD_EVENTCAUSE_READY_MASK); usbd_enable(); - if (nrfx_usbd_errata_223() && m_first_enable) { + if (nrf_usbd_common_errata_223() && m_first_enable) { nrf_usbd_disable(NRF_USBD); usbd_enable(); @@ -1615,16 +1631,16 @@ void nrfx_usbd_enable(void) m_first_enable = false; } -#if NRFX_USBD_USE_WORKAROUND_FOR_ANOMALY_211 - if (nrfx_usbd_errata_187() || nrfx_usbd_errata_211()) +#if NRF_USBD_COMMON_USE_WORKAROUND_FOR_ANOMALY_211 + if (nrf_usbd_common_errata_187() || nrf_usbd_common_errata_211()) #else - if (nrfx_usbd_errata_187()) + if (nrf_usbd_common_errata_187()) #endif { usbd_errata_187_211_begin(); } - if (nrfx_usbd_errata_166()) { + if (nrf_usbd_common_errata_166()) { *((volatile uint32_t *)((uint32_t)(NRF_USBD) + 0x800)) = 0x7E3; *((volatile uint32_t *)((uint32_t)(NRF_USBD) + 0x804)) = 0x40; __ISB(); @@ -1633,36 +1649,36 @@ void nrfx_usbd_enable(void) nrf_usbd_isosplit_set(NRF_USBD, NRF_USBD_ISOSPLIT_HALF); - if (NRFX_USBD_CONFIG_ISO_IN_ZLP) { - nrfx_usbd_isoinconfig_set(NRF_USBD_ISOINCONFIG_ZERODATA); + if (IS_ENABLED(CONFIG_NRF_USBD_ISO_IN_ZLP)) { + nrf_usbd_common_isoinconfig_set(NRF_USBD_ISOINCONFIG_ZERODATA); } else { - nrfx_usbd_isoinconfig_set(NRF_USBD_ISOINCONFIG_NORESP); + nrf_usbd_common_isoinconfig_set(NRF_USBD_ISOINCONFIG_NORESP); } - m_ep_ready = (((1U << NRF_USBD_EPIN_CNT) - 1U) << NRFX_USBD_EPIN_BITPOS_0); + m_ep_ready = (((1U << NRF_USBD_EPIN_CNT) - 1U) << NRF_USBD_COMMON_EPIN_BITPOS_0); m_ep_dma_waiting = 0; m_dma_odd = 0; usbd_dma_pending_clear(); - m_last_setup_dir = NRFX_USBD_EPOUT0; + m_last_setup_dir = NRF_USBD_COMMON_EPOUT0; m_drv_state = NRFX_DRV_STATE_POWERED_ON; -#if NRFX_USBD_USE_WORKAROUND_FOR_ANOMALY_211 - if (nrfx_usbd_errata_187() && !nrfx_usbd_errata_211()) +#if NRF_USBD_COMMON_USE_WORKAROUND_FOR_ANOMALY_211 + if (nrf_usbd_common_errata_187() && !nrf_usbd_common_errata_211()) #else - if (nrfx_usbd_errata_187()) + if (nrf_usbd_common_errata_187()) #endif { usbd_errata_187_211_end(); } } -void nrfx_usbd_disable(void) +void nrf_usbd_common_disable(void) { - NRFX_ASSERT(m_drv_state != NRFX_DRV_STATE_UNINITIALIZED); + __ASSERT_NO_MSG(m_drv_state != NRFX_DRV_STATE_UNINITIALIZED); /* Stop just in case */ - nrfx_usbd_stop(); + nrf_usbd_common_stop(); /* Disable all parts */ nrf_usbd_int_disable(NRF_USBD, nrf_usbd_int_enable_get(NRF_USBD)); @@ -1671,8 +1687,8 @@ void nrfx_usbd_disable(void) * that total number of bytes transferred by DMA is even. */ nrf_usbd_event_clear(NRF_USBD, NRF_USBD_EVENT_ENDEPIN0); - nrf_usbd_ep_easydma_set(NRF_USBD, NRFX_USBD_EPIN0, (uint32_t)&m_dma_odd, 1); - usbd_dma_start(NRFX_USBD_EPIN0); + nrf_usbd_ep_easydma_set(NRF_USBD, NRF_USBD_COMMON_EPIN0, (uint32_t)&m_dma_odd, 1); + usbd_dma_start(NRF_USBD_COMMON_EPIN0); while (!nrf_usbd_event_check(NRF_USBD, NRF_USBD_EVENT_ENDEPIN0)) { } m_dma_odd = 0; @@ -1681,16 +1697,16 @@ void nrfx_usbd_disable(void) usbd_dma_pending_clear(); m_drv_state = NRFX_DRV_STATE_INITIALIZED; -#if NRFX_USBD_USE_WORKAROUND_FOR_ANOMALY_211 - if (nrfx_usbd_errata_211()) { +#if NRF_USBD_COMMON_USE_WORKAROUND_FOR_ANOMALY_211 + if (nrf_usbd_common_errata_211()) { usbd_errata_187_211_end(); } #endif } -void nrfx_usbd_start(bool enable_sof) +void nrf_usbd_common_start(bool enable_sof) { - NRFX_ASSERT(m_drv_state == NRFX_DRV_STATE_POWERED_ON); + __ASSERT_NO_MSG(m_drv_state == NRFX_DRV_STATE_POWERED_ON); m_bus_suspend = false; uint32_t ints_to_enable = NRF_USBD_INT_USBRESET_MASK | NRF_USBD_INT_STARTED_MASK | @@ -1706,21 +1722,20 @@ void nrfx_usbd_start(bool enable_sof) nrf_usbd_int_enable(NRF_USBD, ints_to_enable); /* Enable interrupt globally */ - NRFX_IRQ_PRIORITY_SET(USBD_IRQn, NRFX_USBD_DEFAULT_CONFIG_IRQ_PRIORITY); - NRFX_IRQ_ENABLE(USBD_IRQn); + irq_enable(USBD_IRQn); /* Enable pullups */ nrf_usbd_pullup_enable(NRF_USBD); } -void nrfx_usbd_stop(void) +void nrf_usbd_common_stop(void) { - NRFX_ASSERT(m_drv_state == NRFX_DRV_STATE_POWERED_ON); + __ASSERT_NO_MSG(m_drv_state == NRFX_DRV_STATE_POWERED_ON); /* Clear interrupt */ - NRFX_IRQ_PENDING_CLEAR(USBD_IRQn); + NVIC_ClearPendingIRQ(USBD_IRQn); - if (NRFX_IRQ_IS_ENABLED(USBD_IRQn)) { + if (irq_is_enabled(USBD_IRQn)) { /* Abort transfers */ usbd_ep_abort_all(); @@ -1728,33 +1743,33 @@ void nrfx_usbd_stop(void) nrf_usbd_pullup_disable(NRF_USBD); /* Disable interrupt globally */ - NRFX_IRQ_DISABLE(USBD_IRQn); + irq_disable(USBD_IRQn); /* Disable all interrupts */ nrf_usbd_int_disable(NRF_USBD, ~0U); } } -bool nrfx_usbd_is_initialized(void) +bool nrf_usbd_common_is_initialized(void) { return (m_drv_state >= NRFX_DRV_STATE_INITIALIZED); } -bool nrfx_usbd_is_enabled(void) +bool nrf_usbd_common_is_enabled(void) { return (m_drv_state >= NRFX_DRV_STATE_POWERED_ON); } -bool nrfx_usbd_is_started(void) +bool nrf_usbd_common_is_started(void) { - return (nrfx_usbd_is_enabled() && NRFX_IRQ_IS_ENABLED(USBD_IRQn)); + return (nrf_usbd_common_is_enabled() && irq_is_enabled(USBD_IRQn)); } -bool nrfx_usbd_suspend(void) +bool nrf_usbd_common_suspend(void) { bool suspended = false; + unsigned int irq_lock_key = irq_lock(); - NRFX_CRITICAL_SECTION_ENTER(); if (m_bus_suspend) { if (!(nrf_usbd_eventcause_get(NRF_USBD) & NRF_USBD_EVENTCAUSE_RESUME_MASK)) { nrf_usbd_lowpower_enable(NRF_USBD); @@ -1765,21 +1780,22 @@ bool nrfx_usbd_suspend(void) } } } - NRFX_CRITICAL_SECTION_EXIT(); + + irq_unlock(irq_lock_key); return suspended; } -bool nrfx_usbd_wakeup_req(void) +bool nrf_usbd_common_wakeup_req(void) { bool started = false; + unsigned int irq_lock_key = irq_lock(); - NRFX_CRITICAL_SECTION_ENTER(); if (m_bus_suspend && nrf_usbd_lowpower_check(NRF_USBD)) { nrf_usbd_lowpower_disable(NRF_USBD); started = true; - if (nrfx_usbd_errata_171()) { + if (nrf_usbd_common_errata_171()) { if (*((volatile uint32_t *)(0x4006EC00)) == 0x00000000) { *((volatile uint32_t *)(0x4006EC00)) = 0x00009375; *((volatile uint32_t *)(0x4006EC14)) = 0x000000C0; @@ -1789,66 +1805,67 @@ bool nrfx_usbd_wakeup_req(void) } } } - NRFX_CRITICAL_SECTION_EXIT(); + + irq_unlock(irq_lock_key); return started; } -bool nrfx_usbd_suspend_check(void) +bool nrf_usbd_common_suspend_check(void) { return nrf_usbd_lowpower_check(NRF_USBD); } -void nrfx_usbd_suspend_irq_config(void) +void nrf_usbd_common_suspend_irq_config(void) { nrf_usbd_int_disable(NRF_USBD, m_irq_disabled_in_suspend); } -void nrfx_usbd_active_irq_config(void) +void nrf_usbd_common_active_irq_config(void) { nrf_usbd_int_enable(NRF_USBD, m_irq_disabled_in_suspend); } -bool nrfx_usbd_bus_suspend_check(void) +bool nrf_usbd_common_bus_suspend_check(void) { return m_bus_suspend; } -void nrfx_usbd_force_bus_wakeup(void) +void nrf_usbd_common_force_bus_wakeup(void) { m_bus_suspend = false; } -void nrfx_usbd_ep_max_packet_size_set(nrfx_usbd_ep_t ep, uint16_t size) +void nrf_usbd_common_ep_max_packet_size_set(nrf_usbd_common_ep_t ep, uint16_t size) { /* Only the power of 2 size allowed for Control Endpoints */ - NRFX_ASSERT((((size & (size - 1)) == 0) || (NRF_USBD_EP_NR_GET(ep) != 0))); + __ASSERT_NO_MSG((((size & (size - 1)) == 0) || (NRF_USBD_EP_NR_GET(ep) != 0))); /* Only non zero size allowed for Control Endpoints */ - NRFX_ASSERT((size != 0) || (NRF_USBD_EP_NR_GET(ep) != 0)); + __ASSERT_NO_MSG((size != 0) || (NRF_USBD_EP_NR_GET(ep) != 0)); /* Packet size cannot be higher than maximum buffer size */ - NRFX_ASSERT((NRF_USBD_EPISO_CHECK(ep) && (size <= usbd_ep_iso_capacity(ep))) || - (!NRF_USBD_EPISO_CHECK(ep) && (size <= NRFX_USBD_EPSIZE))); + __ASSERT_NO_MSG((NRF_USBD_EPISO_CHECK(ep) && (size <= usbd_ep_iso_capacity(ep))) || + (!NRF_USBD_EPISO_CHECK(ep) && (size <= NRF_USBD_COMMON_EPSIZE))); usbd_ep_state_t *p_state = ep_state_access(ep); p_state->max_packet_size = size; } -uint16_t nrfx_usbd_ep_max_packet_size_get(nrfx_usbd_ep_t ep) +uint16_t nrf_usbd_common_ep_max_packet_size_get(nrf_usbd_common_ep_t ep) { usbd_ep_state_t const *p_state = ep_state_access(ep); return p_state->max_packet_size; } -bool nrfx_usbd_ep_enable_check(nrfx_usbd_ep_t ep) +bool nrf_usbd_common_ep_enable_check(nrf_usbd_common_ep_t ep) { return nrf_usbd_ep_enable_check(NRF_USBD, ep_to_hal(ep)); } -void nrfx_usbd_ep_enable(nrfx_usbd_ep_t ep) +void nrf_usbd_common_ep_enable(nrf_usbd_common_ep_t ep) { - nrf_usbd_int_enable(NRF_USBD, nrfx_usbd_ep_to_int(ep)); + nrf_usbd_int_enable(NRF_USBD, nrf_usbd_common_ep_to_int(ep)); if (nrf_usbd_ep_enable_check(NRF_USBD, ep)) { return; @@ -1856,21 +1873,23 @@ void nrfx_usbd_ep_enable(nrfx_usbd_ep_t ep) nrf_usbd_ep_enable(NRF_USBD, ep_to_hal(ep)); if ((NRF_USBD_EP_NR_GET(ep) != 0) && NRF_USBD_EPOUT_CHECK(ep) && !NRF_USBD_EPISO_CHECK(ep)) { - NRFX_CRITICAL_SECTION_ENTER(); - nrfx_usbd_transfer_out_drop(ep); + unsigned int irq_lock_key = irq_lock(); + + nrf_usbd_common_transfer_out_drop(ep); m_ep_dma_waiting &= ~(1U << ep2bit(ep)); - NRFX_CRITICAL_SECTION_EXIT(); + + irq_unlock(irq_lock_key); } } -void nrfx_usbd_ep_disable(nrfx_usbd_ep_t ep) +void nrf_usbd_common_ep_disable(nrf_usbd_common_ep_t ep) { usbd_ep_abort(ep); nrf_usbd_ep_disable(NRF_USBD, ep_to_hal(ep)); - nrf_usbd_int_disable(NRF_USBD, nrfx_usbd_ep_to_int(ep)); + nrf_usbd_int_disable(NRF_USBD, nrf_usbd_common_ep_to_int(ep)); } -void nrfx_usbd_ep_default_config(void) +void nrf_usbd_common_ep_default_config(void) { nrf_usbd_int_disable(NRF_USBD, NRF_USBD_INT_ENDEPIN1_MASK | NRF_USBD_INT_ENDEPIN2_MASK | @@ -1885,119 +1904,126 @@ void nrfx_usbd_ep_default_config(void) nrf_usbd_ep_default_config(NRF_USBD); } -nrfx_err_t nrfx_usbd_ep_transfer(nrfx_usbd_ep_t ep, nrfx_usbd_transfer_t const *p_transfer) +nrfx_err_t nrf_usbd_common_ep_transfer(nrf_usbd_common_ep_t ep, + nrf_usbd_common_transfer_t const *p_transfer) { nrfx_err_t ret; const uint8_t ep_bitpos = ep2bit(ep); + unsigned int irq_lock_key = irq_lock(); - NRFX_ASSERT(p_transfer != NULL); + __ASSERT_NO_MSG(p_transfer != NULL); - NRFX_CRITICAL_SECTION_ENTER(); /* Setup data transaction can go only in one direction at a time */ if ((NRF_USBD_EP_NR_GET(ep) == 0) && (ep != m_last_setup_dir)) { ret = NRFX_ERROR_INVALID_ADDR; - if (NRFX_USBD_FAILED_TRANSFERS_DEBUG && - (NRFX_USBD_ISO_DEBUG || (!NRF_USBD_EPISO_CHECK(ep)))) { - NRFX_LOG_DEBUG("Transfer failed: Invalid EPr\n"); + if (NRF_USBD_COMMON_FAILED_TRANSFERS_DEBUG && + (NRF_USBD_COMMON_ISO_DEBUG || (!NRF_USBD_EPISO_CHECK(ep)))) { + LOG_DBG("Transfer failed: Invalid EPr\n"); } - } else if ((m_ep_dma_waiting | ((~m_ep_ready) & NRFX_USBD_EPIN_BIT_MASK)) & + } else if ((m_ep_dma_waiting | ((~m_ep_ready) & NRF_USBD_COMMON_EPIN_BIT_MASK)) & (1U << ep_bitpos)) { /* IN (Device -> Host) transfer has to be transmitted out to allow new transmission */ ret = NRFX_ERROR_BUSY; - if (NRFX_USBD_FAILED_TRANSFERS_DEBUG) { - NRFX_LOG_DEBUG("Transfer failed: EP is busy"); + if (NRF_USBD_COMMON_FAILED_TRANSFERS_DEBUG) { + LOG_DBG("Transfer failed: EP is busy"); } } else { usbd_ep_state_t *p_state = ep_state_access(ep); /* Prepare transfer context and handler description */ - nrfx_usbd_transfer_t *p_context; + nrf_usbd_common_transfer_t *p_context; if (NRF_USBD_EPIN_CHECK(ep)) { p_context = m_ep_feeder_state + NRF_USBD_EP_NR_GET(ep); if (nrfx_is_in_ram(p_transfer->p_data.tx)) { /* RAM */ - if (0 == (p_transfer->flags & NRFX_USBD_TRANSFER_ZLP_FLAG)) { - p_state->handler.feeder = nrfx_usbd_feeder_ram; - if (NRFX_USBD_ISO_DEBUG || (!NRF_USBD_EPISO_CHECK(ep))) { - NRFX_LOG_DEBUG("Transfer called on endpoint %x, " - "size: %u, mode: " - "RAM", - ep, p_transfer->size); + if (0 == (p_transfer->flags & NRF_USBD_COMMON_TRANSFER_ZLP_FLAG)) { + p_state->handler.feeder = nrf_usbd_common_feeder_ram; + if (NRF_USBD_COMMON_ISO_DEBUG || + (!NRF_USBD_EPISO_CHECK(ep))) { + LOG_DBG("Transfer called on endpoint %x, " + "size: %u, mode: " + "RAM", + ep, p_transfer->size); } } else { - p_state->handler.feeder = nrfx_usbd_feeder_ram_zlp; - if (NRFX_USBD_ISO_DEBUG || (!NRF_USBD_EPISO_CHECK(ep))) { - NRFX_LOG_DEBUG("Transfer called on endpoint %x, " - "size: %u, mode: " - "RAM_ZLP", - ep, p_transfer->size); + p_state->handler.feeder = nrf_usbd_common_feeder_ram_zlp; + if (NRF_USBD_COMMON_ISO_DEBUG || + (!NRF_USBD_EPISO_CHECK(ep))) { + LOG_DBG("Transfer called on endpoint %x, " + "size: %u, mode: " + "RAM_ZLP", + ep, p_transfer->size); } } } else { /* Flash */ - if (0 == (p_transfer->flags & NRFX_USBD_TRANSFER_ZLP_FLAG)) { - p_state->handler.feeder = nrfx_usbd_feeder_flash; - if (NRFX_USBD_ISO_DEBUG || (!NRF_USBD_EPISO_CHECK(ep))) { - NRFX_LOG_DEBUG("Transfer called on endpoint %x, " - "size: %u, mode: " - "FLASH", - ep, p_transfer->size); + if (0 == (p_transfer->flags & NRF_USBD_COMMON_TRANSFER_ZLP_FLAG)) { + p_state->handler.feeder = nrf_usbd_common_feeder_flash; + if (NRF_USBD_COMMON_ISO_DEBUG || + (!NRF_USBD_EPISO_CHECK(ep))) { + LOG_DBG("Transfer called on endpoint %x, " + "size: %u, mode: " + "FLASH", + ep, p_transfer->size); } } else { - p_state->handler.feeder = nrfx_usbd_feeder_flash_zlp; - if (NRFX_USBD_ISO_DEBUG || (!NRF_USBD_EPISO_CHECK(ep))) { - NRFX_LOG_DEBUG("Transfer called on endpoint %x, " - "size: %u, mode: " - "FLASH_ZLP", - ep, p_transfer->size); + p_state->handler.feeder = nrf_usbd_common_feeder_flash_zlp; + if (NRF_USBD_COMMON_ISO_DEBUG || + (!NRF_USBD_EPISO_CHECK(ep))) { + LOG_DBG("Transfer called on endpoint %x, " + "size: %u, mode: " + "FLASH_ZLP", + ep, p_transfer->size); } } } } else { p_context = m_ep_consumer_state + NRF_USBD_EP_NR_GET(ep); - NRFX_ASSERT((p_transfer->p_data.rx == NULL) || + __ASSERT_NO_MSG((p_transfer->p_data.rx == NULL) || (nrfx_is_in_ram(p_transfer->p_data.rx))); - p_state->handler.consumer = nrfx_usbd_consumer; + p_state->handler.consumer = nrf_usbd_common_consumer; } *p_context = *p_transfer; p_state->p_context = p_context; p_state->transfer_cnt = 0; - p_state->status = NRFX_USBD_EP_OK; + p_state->status = NRF_USBD_COMMON_EP_OK; m_ep_dma_waiting |= 1U << ep_bitpos; ret = NRFX_SUCCESS; usbd_int_rise(); } - NRFX_CRITICAL_SECTION_EXIT(); + + irq_unlock(irq_lock_key); + return ret; } -nrfx_err_t nrfx_usbd_ep_handled_transfer(nrfx_usbd_ep_t ep, - nrfx_usbd_handler_desc_t const *p_handler) +nrfx_err_t nrf_usbd_common_ep_handled_transfer(nrf_usbd_common_ep_t ep, + nrf_usbd_common_handler_desc_t const *p_handler) { nrfx_err_t ret; const uint8_t ep_bitpos = ep2bit(ep); + unsigned int irq_lock_key = irq_lock(); - NRFX_ASSERT(p_handler != NULL); + __ASSERT_NO_MSG(p_handler != NULL); - NRFX_CRITICAL_SECTION_ENTER(); /* Setup data transaction can go only in one direction at a time */ if ((NRF_USBD_EP_NR_GET(ep) == 0) && (ep != m_last_setup_dir)) { ret = NRFX_ERROR_INVALID_ADDR; - if (NRFX_USBD_FAILED_TRANSFERS_DEBUG && - (NRFX_USBD_ISO_DEBUG || (!NRF_USBD_EPISO_CHECK(ep)))) { - NRFX_LOG_DEBUG("Transfer failed: Invalid EP"); + if (NRF_USBD_COMMON_FAILED_TRANSFERS_DEBUG && + (NRF_USBD_COMMON_ISO_DEBUG || (!NRF_USBD_EPISO_CHECK(ep)))) { + LOG_DBG("Transfer failed: Invalid EP"); } - } else if ((m_ep_dma_waiting | ((~m_ep_ready) & NRFX_USBD_EPIN_BIT_MASK)) & + } else if ((m_ep_dma_waiting | ((~m_ep_ready) & NRF_USBD_COMMON_EPIN_BIT_MASK)) & (1U << ep_bitpos)) { /* IN (Device -> Host) transfer has to be transmitted out to allow a new * transmission */ ret = NRFX_ERROR_BUSY; - if (NRFX_USBD_FAILED_TRANSFERS_DEBUG && - (NRFX_USBD_ISO_DEBUG || (!NRF_USBD_EPISO_CHECK(ep)))) { - NRFX_LOG_DEBUG("Transfer failed: EP is busy"); + if (NRF_USBD_COMMON_FAILED_TRANSFERS_DEBUG && + (NRF_USBD_COMMON_ISO_DEBUG || (!NRF_USBD_EPISO_CHECK(ep)))) { + LOG_DBG("Transfer failed: EP is busy"); } } else { /* Transfer can be configured now */ @@ -2006,74 +2032,78 @@ nrfx_err_t nrfx_usbd_ep_handled_transfer(nrfx_usbd_ep_t ep, p_state->transfer_cnt = 0; p_state->handler = p_handler->handler; p_state->p_context = p_handler->p_context; - p_state->status = NRFX_USBD_EP_OK; + p_state->status = NRF_USBD_COMMON_EP_OK; m_ep_dma_waiting |= 1U << ep_bitpos; ret = NRFX_SUCCESS; - if (NRFX_USBD_ISO_DEBUG || (!NRF_USBD_EPISO_CHECK(ep))) { - NRFX_LOG_DEBUG("Transfer called on endpoint %x, mode: Handler", ep); + if (NRF_USBD_COMMON_ISO_DEBUG || (!NRF_USBD_EPISO_CHECK(ep))) { + LOG_DBG("Transfer called on endpoint %x, mode: Handler", ep); } usbd_int_rise(); } - NRFX_CRITICAL_SECTION_EXIT(); + + irq_unlock(irq_lock_key); + return ret; } -void *nrfx_usbd_feeder_buffer_get(void) +void *nrf_usbd_common_feeder_buffer_get(void) { return m_tx_buffer; } -nrfx_usbd_ep_status_t nrfx_usbd_ep_status_get(nrfx_usbd_ep_t ep, size_t *p_size) +nrf_usbd_common_ep_status_t nrf_usbd_common_ep_status_get(nrf_usbd_common_ep_t ep, size_t *p_size) { - nrfx_usbd_ep_status_t ret; + nrf_usbd_common_ep_status_t ret; usbd_ep_state_t const *p_state = ep_state_access(ep); + unsigned int irq_lock_key = irq_lock(); - NRFX_CRITICAL_SECTION_ENTER(); *p_size = p_state->transfer_cnt; - ret = (p_state->handler.consumer == NULL) ? p_state->status : NRFX_USBD_EP_BUSY; - NRFX_CRITICAL_SECTION_EXIT(); + ret = (p_state->handler.consumer == NULL) ? p_state->status : NRF_USBD_COMMON_EP_BUSY; + + irq_unlock(irq_lock_key); + return ret; } -size_t nrfx_usbd_epout_size_get(nrfx_usbd_ep_t ep) +size_t nrf_usbd_common_epout_size_get(nrf_usbd_common_ep_t ep) { return nrf_usbd_epout_size_get(NRF_USBD, ep_to_hal(ep)); } -bool nrfx_usbd_ep_is_busy(nrfx_usbd_ep_t ep) +bool nrf_usbd_common_ep_is_busy(nrf_usbd_common_ep_t ep) { - return (0 != ((m_ep_dma_waiting | ((~m_ep_ready) & NRFX_USBD_EPIN_BIT_MASK)) & + return (0 != ((m_ep_dma_waiting | ((~m_ep_ready) & NRF_USBD_COMMON_EPIN_BIT_MASK)) & (1U << ep2bit(ep)))); } -void nrfx_usbd_ep_stall(nrfx_usbd_ep_t ep) +void nrf_usbd_common_ep_stall(nrf_usbd_common_ep_t ep) { - NRFX_LOG_DEBUG("USB: EP %x stalled.", ep); + LOG_DBG("USB: EP %x stalled.", ep); nrf_usbd_ep_stall(NRF_USBD, ep_to_hal(ep)); } -void nrfx_usbd_ep_stall_clear(nrfx_usbd_ep_t ep) +void nrf_usbd_common_ep_stall_clear(nrf_usbd_common_ep_t ep) { - if (NRF_USBD_EPOUT_CHECK(ep) && nrfx_usbd_ep_stall_check(ep)) { - nrfx_usbd_transfer_out_drop(ep); + if (NRF_USBD_EPOUT_CHECK(ep) && nrf_usbd_common_ep_stall_check(ep)) { + nrf_usbd_common_transfer_out_drop(ep); } nrf_usbd_ep_unstall(NRF_USBD, ep_to_hal(ep)); } -bool nrfx_usbd_ep_stall_check(nrfx_usbd_ep_t ep) +bool nrf_usbd_common_ep_stall_check(nrf_usbd_common_ep_t ep) { return nrf_usbd_ep_is_stall(NRF_USBD, ep_to_hal(ep)); } -void nrfx_usbd_ep_dtoggle_clear(nrfx_usbd_ep_t ep) +void nrf_usbd_common_ep_dtoggle_clear(nrf_usbd_common_ep_t ep) { nrf_usbd_dtoggle_set(NRF_USBD, ep, NRF_USBD_DTOGGLE_DATA0); } -void nrfx_usbd_setup_get(nrfx_usbd_setup_t *p_setup) +void nrf_usbd_common_setup_get(nrf_usbd_common_setup_t *p_setup) { - memset(p_setup, 0, sizeof(nrfx_usbd_setup_t)); + memset(p_setup, 0, sizeof(nrf_usbd_common_setup_t)); p_setup->bmRequestType = nrf_usbd_setup_bmrequesttype_get(NRF_USBD); p_setup->bRequest = nrf_usbd_setup_brequest_get(NRF_USBD); p_setup->wValue = nrf_usbd_setup_wvalue_get(NRF_USBD); @@ -2081,38 +2111,40 @@ void nrfx_usbd_setup_get(nrfx_usbd_setup_t *p_setup) p_setup->wLength = nrf_usbd_setup_wlength_get(NRF_USBD); } -void nrfx_usbd_setup_data_clear(void) +void nrf_usbd_common_setup_data_clear(void) { nrf_usbd_task_trigger(NRF_USBD, NRF_USBD_TASK_EP0RCVOUT); } -void nrfx_usbd_setup_clear(void) +void nrf_usbd_common_setup_clear(void) { - NRFX_LOG_DEBUG(">> ep0status >>"); + LOG_DBG(">> ep0status >>"); nrf_usbd_task_trigger(NRF_USBD, NRF_USBD_TASK_EP0STATUS); } -void nrfx_usbd_setup_stall(void) +void nrf_usbd_common_setup_stall(void) { - NRFX_LOG_DEBUG("Setup stalled."); + LOG_DBG("Setup stalled."); nrf_usbd_task_trigger(NRF_USBD, NRF_USBD_TASK_EP0STALL); } -nrfx_usbd_ep_t nrfx_usbd_last_setup_dir_get(void) +nrf_usbd_common_ep_t nrf_usbd_common_last_setup_dir_get(void) { return m_last_setup_dir; } -void nrfx_usbd_transfer_out_drop(nrfx_usbd_ep_t ep) +void nrf_usbd_common_transfer_out_drop(nrf_usbd_common_ep_t ep) { - NRFX_ASSERT(NRF_USBD_EPOUT_CHECK(ep)); + unsigned int irq_lock_key = irq_lock(); + + __ASSERT_NO_MSG(NRF_USBD_EPOUT_CHECK(ep)); - NRFX_CRITICAL_SECTION_ENTER(); m_ep_ready &= ~(1U << ep2bit(ep)); if (!NRF_USBD_EPISO_CHECK(ep)) { nrf_usbd_epout_clear(NRF_USBD, ep); } - NRFX_CRITICAL_SECTION_EXIT(); + + irq_unlock(irq_lock_key); } -#endif /* NRFX_CHECK(NRFX_USBD_ENABLED) */ +/** @endcond */ diff --git a/modules/hal_nordic/nrfx/nrfx_usbd.h b/drivers/usb/common/nrf_usbd_common/nrf_usbd_common.h similarity index 68% rename from modules/hal_nordic/nrfx/nrfx_usbd.h rename to drivers/usb/common/nrf_usbd_common/nrf_usbd_common.h index cf6251cb4bd..047c5a29709 100644 --- a/modules/hal_nordic/nrfx/nrfx_usbd.h +++ b/drivers/usb/common/nrf_usbd_common/nrf_usbd_common.h @@ -4,8 +4,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef NRFX_USBD_H__ -#define NRFX_USBD_H__ +/* This file is undergoing transition towards native Zephyr nrf USB driver. */ + +/** @cond INTERNAL_HIDDEN */ + +#ifndef NRF_USBD_COMMON_H__ +#define NRF_USBD_COMMON_H__ #include #include @@ -15,7 +19,7 @@ extern "C" { #endif /** - * @defgroup nrfx_usbd USBD driver + * @defgroup nrf_usbd_common USBD driver * @{ * @ingroup nrf_usbd * @brief Universal Serial Bus Device (USBD) peripheral driver. @@ -24,7 +28,7 @@ extern "C" { /** * @brief Number of bytes in the endpoint. */ -#define NRFX_USBD_EPSIZE 64 +#define NRF_USBD_COMMON_EPSIZE 64 /** * @brief Number of bytes for isochronous endpoints. @@ -35,14 +39,14 @@ extern "C" { * @sa nrf_usbd_isosplit_set * @sa nrf_usbd_isosplit_get */ -#define NRFX_USBD_ISOSIZE 1023 +#define NRF_USBD_COMMON_ISOSIZE 1023 /** * @brief The size of internal feeder buffer. * - * @sa nrfx_usbd_feeder_buffer_get + * @sa nrf_usbd_common_feeder_buffer_get */ -#define NRFX_USBD_FEEDER_BUFFER_SIZE NRFX_USBD_EPSIZE +#define NRF_USBD_COMMON_FEEDER_BUFFER_SIZE NRF_USBD_COMMON_EPSIZE /** * @name Macros for creating endpoint identifiers. @@ -60,7 +64,7 @@ extern "C" { * * @return Endpoint identifier that connects endpoint number and endpoint direction. */ -#define NRFX_USBD_EPIN(n) ((nrfx_usbd_ep_t)NRF_USBD_EPIN(n)) +#define NRF_USBD_COMMON_EPIN(n) ((nrf_usbd_common_ep_t)NRF_USBD_EPIN(n)) /** * @brief Create identifier for OUT endpoint. * @@ -70,7 +74,7 @@ extern "C" { * * @return Endpoint identifier that connects endpoint number and endpoint direction. */ -#define NRFX_USBD_EPOUT(n) ((nrfx_usbd_ep_t)NRF_USBD_EPOUT(n)) +#define NRF_USBD_COMMON_EPOUT(n) ((nrf_usbd_common_ep_t)NRF_USBD_EPOUT(n)) /** @} */ /** @@ -80,26 +84,26 @@ extern "C" { * This endpoint number is consistent with USB 2.0 specification. */ typedef enum { - NRFX_USBD_EPOUT0 = NRF_USBD_EPOUT(0), /**< Endpoint OUT 0 */ - NRFX_USBD_EPOUT1 = NRF_USBD_EPOUT(1), /**< Endpoint OUT 1 */ - NRFX_USBD_EPOUT2 = NRF_USBD_EPOUT(2), /**< Endpoint OUT 2 */ - NRFX_USBD_EPOUT3 = NRF_USBD_EPOUT(3), /**< Endpoint OUT 3 */ - NRFX_USBD_EPOUT4 = NRF_USBD_EPOUT(4), /**< Endpoint OUT 4 */ - NRFX_USBD_EPOUT5 = NRF_USBD_EPOUT(5), /**< Endpoint OUT 5 */ - NRFX_USBD_EPOUT6 = NRF_USBD_EPOUT(6), /**< Endpoint OUT 6 */ - NRFX_USBD_EPOUT7 = NRF_USBD_EPOUT(7), /**< Endpoint OUT 7 */ - NRFX_USBD_EPOUT8 = NRF_USBD_EPOUT(8), /**< Endpoint OUT 8 */ + NRF_USBD_COMMON_EPOUT0 = NRF_USBD_EPOUT(0), /**< Endpoint OUT 0 */ + NRF_USBD_COMMON_EPOUT1 = NRF_USBD_EPOUT(1), /**< Endpoint OUT 1 */ + NRF_USBD_COMMON_EPOUT2 = NRF_USBD_EPOUT(2), /**< Endpoint OUT 2 */ + NRF_USBD_COMMON_EPOUT3 = NRF_USBD_EPOUT(3), /**< Endpoint OUT 3 */ + NRF_USBD_COMMON_EPOUT4 = NRF_USBD_EPOUT(4), /**< Endpoint OUT 4 */ + NRF_USBD_COMMON_EPOUT5 = NRF_USBD_EPOUT(5), /**< Endpoint OUT 5 */ + NRF_USBD_COMMON_EPOUT6 = NRF_USBD_EPOUT(6), /**< Endpoint OUT 6 */ + NRF_USBD_COMMON_EPOUT7 = NRF_USBD_EPOUT(7), /**< Endpoint OUT 7 */ + NRF_USBD_COMMON_EPOUT8 = NRF_USBD_EPOUT(8), /**< Endpoint OUT 8 */ - NRFX_USBD_EPIN0 = NRF_USBD_EPIN(0), /**< Endpoint IN 0 */ - NRFX_USBD_EPIN1 = NRF_USBD_EPIN(1), /**< Endpoint IN 1 */ - NRFX_USBD_EPIN2 = NRF_USBD_EPIN(2), /**< Endpoint IN 2 */ - NRFX_USBD_EPIN3 = NRF_USBD_EPIN(3), /**< Endpoint IN 3 */ - NRFX_USBD_EPIN4 = NRF_USBD_EPIN(4), /**< Endpoint IN 4 */ - NRFX_USBD_EPIN5 = NRF_USBD_EPIN(5), /**< Endpoint IN 5 */ - NRFX_USBD_EPIN6 = NRF_USBD_EPIN(6), /**< Endpoint IN 6 */ - NRFX_USBD_EPIN7 = NRF_USBD_EPIN(7), /**< Endpoint IN 7 */ - NRFX_USBD_EPIN8 = NRF_USBD_EPIN(8), /**< Endpoint IN 8 */ -} nrfx_usbd_ep_t; + NRF_USBD_COMMON_EPIN0 = NRF_USBD_EPIN(0), /**< Endpoint IN 0 */ + NRF_USBD_COMMON_EPIN1 = NRF_USBD_EPIN(1), /**< Endpoint IN 1 */ + NRF_USBD_COMMON_EPIN2 = NRF_USBD_EPIN(2), /**< Endpoint IN 2 */ + NRF_USBD_COMMON_EPIN3 = NRF_USBD_EPIN(3), /**< Endpoint IN 3 */ + NRF_USBD_COMMON_EPIN4 = NRF_USBD_EPIN(4), /**< Endpoint IN 4 */ + NRF_USBD_COMMON_EPIN5 = NRF_USBD_EPIN(5), /**< Endpoint IN 5 */ + NRF_USBD_COMMON_EPIN6 = NRF_USBD_EPIN(6), /**< Endpoint IN 6 */ + NRF_USBD_COMMON_EPIN7 = NRF_USBD_EPIN(7), /**< Endpoint IN 7 */ + NRF_USBD_COMMON_EPIN8 = NRF_USBD_EPIN(8), /**< Endpoint IN 8 */ +} nrf_usbd_common_ep_t; /** * @brief Events generated by the driver. @@ -107,15 +111,15 @@ typedef enum { * Enumeration of possible events that may be generated by the driver. */ typedef enum { - NRFX_USBD_EVT_SOF, /**< Start Of Frame event on USB bus detected. */ - NRFX_USBD_EVT_RESET, /**< Reset condition on USB bus detected. */ - NRFX_USBD_EVT_SUSPEND, /**< This device should go to suspend mode now. */ - NRFX_USBD_EVT_RESUME, /**< This device should resume from suspend now. */ + NRF_USBD_COMMON_EVT_SOF, /**< Start Of Frame event on USB bus detected. */ + NRF_USBD_COMMON_EVT_RESET, /**< Reset condition on USB bus detected. */ + NRF_USBD_COMMON_EVT_SUSPEND, /**< This device should go to suspend mode now. */ + NRF_USBD_COMMON_EVT_RESUME, /**< This device should resume from suspend now. */ /** Wakeup request - the USBD peripheral is ready to generate * WAKEUP signal after exiting low power mode. */ - NRFX_USBD_EVT_WUREQ, - NRFX_USBD_EVT_SETUP, /**< Setup frame received and decoded. */ + NRF_USBD_COMMON_EVT_WUREQ, + NRF_USBD_COMMON_EVT_SETUP, /**< Setup frame received and decoded. */ /** For Rx (OUT: Host->Device): * 1. The packet has been received but there is no buffer * prepared for transfer already. @@ -125,21 +129,21 @@ typedef enum { * The last packet from requested transfer has been transferred * over USB bus and acknowledged. */ - NRFX_USBD_EVT_EPTRANSFER, - NRFX_USBD_EVT_CNT /**< Number of defined events. */ -} nrfx_usbd_event_type_t; + NRF_USBD_COMMON_EVT_EPTRANSFER, + NRF_USBD_COMMON_EVT_CNT /**< Number of defined events. */ +} nrf_usbd_common_event_type_t; /** * @brief Endpoint status codes. * - * Status codes that may be returned by @ref nrfx_usbd_ep_status_get or, except for - * @ref NRFX_USBD_EP_BUSY, reported together with @ref NRFX_USBD_EVT_EPTRANSFER. + * Status codes that may be returned by @ref nrf_usbd_common_ep_status_get or, except for + * @ref NRF_USBD_COMMON_EP_BUSY, reported together with @ref NRF_USBD_COMMON_EVT_EPTRANSFER. */ typedef enum { /** No error occurred. */ - NRFX_USBD_EP_OK, + NRF_USBD_COMMON_EP_OK, /** Data received, no buffer prepared already - waiting for configured transfer. */ - NRFX_USBD_EP_WAITING, + NRF_USBD_COMMON_EP_WAITING, /** Received number of bytes cannot fit given buffer. * This error would also be returned when next_transfer function * has been defined but currently received data cannot fit completely @@ -149,14 +153,14 @@ typedef enum { * When this error is reported - data is left inside endpoint * buffer. Clear endpoint or prepare new buffer and read it. */ - NRFX_USBD_EP_OVERLOAD, + NRF_USBD_COMMON_EP_OVERLOAD, /** EP0 transfer can be aborted when new setup comes. * Any other transfer can be aborted by USB reset or driver stopping. */ - NRFX_USBD_EP_ABORTED, + NRF_USBD_COMMON_EP_ABORTED, /** Transfer is in progress. */ - NRFX_USBD_EP_BUSY, -} nrfx_usbd_ep_status_t; + NRF_USBD_COMMON_EP_BUSY, +} nrf_usbd_common_ep_status_t; /** * @brief Event structure. @@ -164,27 +168,27 @@ typedef enum { * Structure passed to event handler. */ typedef struct { - nrfx_usbd_event_type_t type; /**< Event type. */ + nrf_usbd_common_event_type_t type; /**< Event type. */ union { struct { uint16_t framecnt; /**< Current value of frame counter. */ - } sof; /**< Data available for @ref NRFX_USBD_EVT_SOF. */ + } sof; /**< Data available for @ref NRF_USBD_COMMON_EVT_SOF. */ struct { - nrfx_usbd_ep_t ep; /**< Endpoint number. */ + nrf_usbd_common_ep_t ep; /**< Endpoint number. */ } isocrc; /**< Isochronouns channel endpoint number. */ struct { - nrfx_usbd_ep_t ep; /**< Endpoint number. */ - nrfx_usbd_ep_status_t status; /**< Status for the endpoint. */ + nrf_usbd_common_ep_t ep; /**< Endpoint number. */ + nrf_usbd_common_ep_status_t status; /**< Status for the endpoint. */ } eptransfer; /**< Endpoint transfer status. */ } data; /**< Union to store event data. */ -} nrfx_usbd_evt_t; +} nrf_usbd_common_evt_t; /** * @brief USBD event callback function type. * * @param[in] p_event Event information structure. */ -typedef void (*nrfx_usbd_event_handler_t)(nrfx_usbd_evt_t const *p_event); +typedef void (*nrf_usbd_common_event_handler_t)(nrf_usbd_common_evt_t const *p_event); /** * @brief Universal data pointer. @@ -195,7 +199,7 @@ typedef union { void const *tx; /*!< Constant TX buffer pointer. */ void *rx; /*!< Writable RX buffer pointer. */ uint32_t addr; /*!< Numeric value used internally by the driver. */ -} nrfx_usbd_data_ptr_t; +} nrf_usbd_common_data_ptr_t; /** * @brief Structure to be filled with information about the next transfer. @@ -205,9 +209,11 @@ typedef union { * can never be higher than the endpoint size. */ typedef struct { - nrfx_usbd_data_ptr_t p_data; /*!< Union with available data pointers used by the driver. */ - size_t size; /*!< Size of the requested transfer. */ -} nrfx_usbd_ep_transfer_t; + /** Union with available data pointers used by the driver. */ + nrf_usbd_common_data_ptr_t p_data; + /** Size of the requested transfer. */ + size_t size; +} nrf_usbd_common_ep_transfer_t; /** * @brief Flags for the current transfer. @@ -215,8 +221,8 @@ typedef struct { * Flags configured for the transfer that can be merged using the bitwise 'or' operator (|). */ typedef enum { - NRFX_USBD_TRANSFER_ZLP_FLAG = 1U << 0, /*!< Add a zero-length packet. */ -} nrfx_usbd_transfer_flags_t; + NRF_USBD_COMMON_TRANSFER_ZLP_FLAG = 1U << 0, /*!< Add a zero-length packet. */ +} nrf_usbd_common_transfer_flags_t; /** * @brief Total transfer configuration. @@ -225,11 +231,13 @@ typedef enum { * It is used by internal built-in feeders and consumers. */ typedef struct { - nrfx_usbd_data_ptr_t p_data; /*!< Union with available data pointers used by the driver. */ - size_t size; /*!< Total size of the requested transfer. */ - uint32_t flags; /*!< Transfer flags. */ - /**< Use the @ref nrfx_usbd_transfer_flags_t values. */ -} nrfx_usbd_transfer_t; + /** Union with available data pointers used by the driver. */ + nrf_usbd_common_data_ptr_t p_data; + /** Total size of the requested transfer. */ + size_t size; + /*!< Transfer flags. Use the @ref nrf_usbd_common_transfer_flags_t values. */ + uint32_t flags; +} nrf_usbd_common_transfer_t; /** * @brief Auxiliary macro for declaring IN transfer description with optional flags. @@ -239,23 +247,23 @@ typedef struct { * @param name Instance name. * @param tx_buff Buffer to transfer. * @param tx_size Transfer size. - * @param tx_flags Flags for the transfer (see @ref nrfx_usbd_transfer_flags_t). + * @param tx_flags Flags for the transfer (see @ref nrf_usbd_common_transfer_flags_t). * * @return Configured variable with total transfer description. */ -#define NRFX_USBD_TRANSFER_IN(name, tx_buff, tx_size, tx_flags) \ - const nrfx_usbd_transfer_t name = { \ +#define NRF_USBD_COMMON_TRANSFER_IN(name, tx_buff, tx_size, tx_flags) \ + const nrf_usbd_common_transfer_t name = { \ .p_data = {.tx = (tx_buff)}, .size = (tx_size), .flags = (tx_flags)} /** - * @brief Helper macro for declaring OUT transfer item (@ref nrfx_usbd_transfer_t). + * @brief Helper macro for declaring OUT transfer item (@ref nrf_usbd_common_transfer_t). * * @param name Instance name. * @param rx_buff Buffer to transfer. * @param rx_size Transfer size. */ -#define NRFX_USBD_TRANSFER_OUT(name, rx_buff, rx_size) \ - const nrfx_usbd_transfer_t name = { \ +#define NRF_USBD_COMMON_TRANSFER_OUT(name, rx_buff, rx_size) \ + const nrf_usbd_common_transfer_t name = { \ .p_data = {.rx = (rx_buff)}, .size = (rx_size), .flags = 0} /** @@ -271,7 +279,7 @@ typedef struct { * - Flash transfers are not automatically supported- you must copy them to the RAM buffer before. * * @note - * This function may use @ref nrfx_usbd_feeder_buffer_get to gain a temporary buffer + * This function may use @ref nrf_usbd_common_feeder_buffer_get to gain a temporary buffer * that can be used to prepare transfer. * * @param[out] p_next Structure with the data for the next transfer to be filled. @@ -284,7 +292,7 @@ typedef struct { * @retval true There is more data to be prepared and when the current transfer * finishes, the feeder function is expected to be called again. */ -typedef bool (*nrfx_usbd_feeder_t)(nrfx_usbd_ep_transfer_t *p_next, void *p_context, +typedef bool (*nrf_usbd_common_feeder_t)(nrf_usbd_common_ep_transfer_t *p_next, void *p_context, size_t ep_size); /** @@ -295,7 +303,7 @@ typedef bool (*nrfx_usbd_feeder_t)(nrfx_usbd_ep_transfer_t *p_next, void *p_cont * RX (Host->Device) endpoint transfer. * * The transfer must provide a buffer big enough to fit the whole data from the endpoint. - * Otherwise, the NRFX_USBD_EP_OVERLOAD event is generated. + * Otherwise, the NRF_USBD_COMMON_EP_OVERLOAD event is generated. * * @param[out] p_next Structure with the data for the next transfer to be filled. * Required only if the function returns true. @@ -308,7 +316,7 @@ typedef bool (*nrfx_usbd_feeder_t)(nrfx_usbd_ep_transfer_t *p_next, void *p_cont * @retval true There is more data to be prepared and when current transfer * finishes, the feeder function is expected to be called again. */ -typedef bool (*nrfx_usbd_consumer_t)(nrfx_usbd_ep_transfer_t *p_next, void *p_context, +typedef bool (*nrf_usbd_common_consumer_t)(nrf_usbd_common_ep_transfer_t *p_next, void *p_context, size_t ep_size, size_t data_size); /** @@ -317,9 +325,9 @@ typedef bool (*nrfx_usbd_consumer_t)(nrfx_usbd_ep_transfer_t *p_next, void *p_co * Union with feeder and consumer function pointer. */ typedef union { - nrfx_usbd_feeder_t feeder; /*!< Feeder function pointer. */ - nrfx_usbd_consumer_t consumer; /*!< Consumer function pointer. */ -} nrfx_usbd_handler_t; + nrf_usbd_common_feeder_t feeder; /*!< Feeder function pointer. */ + nrf_usbd_common_consumer_t consumer; /*!< Consumer function pointer. */ +} nrf_usbd_common_handler_t; /** * @brief USBD transfer descriptor. @@ -328,9 +336,11 @@ typedef union { * IN or OUT type of the transfer. */ typedef struct { - nrfx_usbd_handler_t handler; /*!< Handler for the current transfer, function pointer. */ - void *p_context; /*!< Context for the transfer handler. */ -} nrfx_usbd_handler_desc_t; + /** Handler for the current transfer, function pointer. */ + nrf_usbd_common_handler_t handler; + /** Context for the transfer handler. */ + void *p_context; +} nrf_usbd_common_handler_desc_t; /** * @brief Setup packet structure. @@ -343,7 +353,7 @@ typedef struct { uint16_t wValue; /*!< byte 2, 3 */ uint16_t wIndex; /*!< byte 4, 5 */ uint16_t wLength; /*!< byte 6, 7 */ -} nrfx_usbd_setup_t; +} nrf_usbd_common_setup_t; /** * @brief Driver initialization. @@ -353,12 +363,12 @@ typedef struct { * @retval NRFX_SUCCESS Initialization successful. * @retval NRFX_ERROR_INVALID_STATE Driver was already initialized. */ -nrfx_err_t nrfx_usbd_init(nrfx_usbd_event_handler_t event_handler); +nrfx_err_t nrf_usbd_common_init(nrf_usbd_common_event_handler_t event_handler); /** * @brief Driver deinitialization. */ -void nrfx_usbd_uninit(void); +void nrf_usbd_common_uninit(void); /** * @brief Enable the USBD port. @@ -368,15 +378,15 @@ void nrfx_usbd_uninit(void); * Enabled USBD peripheral would request HFCLK. * This function does not enable external oscillator, so if it is not enabled by other part of the * program after enabling USBD driver HFINT would be used for the USBD peripheral. - * It is perfectly fine until USBD is started. See @ref nrfx_usbd_start. + * It is perfectly fine until USBD is started. See @ref nrf_usbd_common_start. * * In normal situation this function should be called in reaction to USBDETECTED * event from POWER peripheral. * - * Interrupts and USB pins pull-up would stay disabled until @ref nrfx_usbd_start + * Interrupts and USB pins pull-up would stay disabled until @ref nrf_usbd_common_start * function is called. */ -void nrfx_usbd_enable(void); +void nrf_usbd_common_enable(void); /** * @brief Disable the USBD port. @@ -385,7 +395,7 @@ void nrfx_usbd_enable(void); * No events would be detected or processed by the driver. * Clock for the peripheral would be disconnected. */ -void nrfx_usbd_disable(void); +void nrf_usbd_common_disable(void); /** * @brief Start USB functionality. @@ -409,7 +419,7 @@ void nrfx_usbd_disable(void); * In other case any isochronous endpoint would stay busy * after first transmission. */ -void nrfx_usbd_start(bool enable_sof); +void nrf_usbd_common_start(bool enable_sof); /** * @brief Stop USB functionality. @@ -420,9 +430,9 @@ void nrfx_usbd_start(bool enable_sof); * * @note * This function can also be used to logically disconnect USB from the HOST that - * would force it to enumerate device after calling @ref nrfx_usbd_start. + * would force it to enumerate device after calling @ref nrf_usbd_common_start. */ -void nrfx_usbd_stop(void); +void nrf_usbd_common_stop(void); /** * @brief Check if driver is initialized. @@ -430,7 +440,7 @@ void nrfx_usbd_stop(void); * @retval false Driver is not initialized. * @retval true Driver is initialized. */ -bool nrfx_usbd_is_initialized(void); +bool nrf_usbd_common_is_initialized(void); /** * @brief Check if driver is enabled. @@ -438,7 +448,7 @@ bool nrfx_usbd_is_initialized(void); * @retval false Driver is disabled. * @retval true Driver is enabled. */ -bool nrfx_usbd_is_enabled(void); +bool nrf_usbd_common_is_enabled(void); /** * @brief Check if driver is started. @@ -447,13 +457,13 @@ bool nrfx_usbd_is_enabled(void); * @retval true Driver is started (fully functional). * @note The USBD peripheral interrupt state is checked. */ -bool nrfx_usbd_is_started(void); +bool nrf_usbd_common_is_started(void); /** * @brief Suspend USBD operation. * * The USBD peripheral is forced to go into the low power mode. - * The function has to be called in the reaction to @ref NRFX_USBD_EVT_SUSPEND event + * The function has to be called in the reaction to @ref NRF_USBD_COMMON_EVT_SUSPEND event * when the firmware is ready. * * After successful call of this function most of the USBD registers would be unavailable. @@ -463,7 +473,7 @@ bool nrfx_usbd_is_started(void); * @retval true USBD peripheral successfully suspended. * @retval false USBD peripheral was not suspended due to resume detection. */ -bool nrfx_usbd_suspend(void); +bool nrf_usbd_common_suspend(void); /** * @brief Start wake up procedure. @@ -474,19 +484,19 @@ bool nrfx_usbd_suspend(void); * The hardware starts measuring time when wake up is possible. * This may take 0-5 ms depending on how long the SUSPEND state was kept on the USB line. - * When NRFX_USBD_EVT_WUREQ event is generated it means that Wake Up signaling has just been + * When NRF_USBD_COMMON_EVT_WUREQ event is generated it means that Wake Up signaling has just been * started on the USB lines. * - * @note Do not expect only @ref NRFX_USBD_EVT_WUREQ event. - * There always may appear @ref NRFX_USBD_EVT_RESUME event. - * @note NRFX_USBD_EVT_WUREQ event means that Remote WakeUp signal + * @note Do not expect only @ref NRF_USBD_COMMON_EVT_WUREQ event. + * There always may appear @ref NRF_USBD_COMMON_EVT_RESUME event. + * @note NRF_USBD_COMMON_EVT_WUREQ event means that Remote WakeUp signal * has just begun to be generated. * This may take up to 20 ms for the bus to become active. * * @retval true WakeUp procedure started. * @retval false No WakeUp procedure started - bus is already active. */ -bool nrfx_usbd_wakeup_req(void); +bool nrf_usbd_common_wakeup_req(void); /** * @brief Check if USBD is in SUSPEND mode. @@ -496,7 +506,7 @@ bool nrfx_usbd_wakeup_req(void); * @retval true USBD peripheral is suspended. * @retval false USBD peripheral is active. */ -bool nrfx_usbd_suspend_check(void); +bool nrf_usbd_common_suspend_check(void); /** * @brief Enable only interrupts that should be processed in SUSPEND mode. @@ -508,19 +518,19 @@ bool nrfx_usbd_suspend_check(void); * Use this function to suspend interrupt processing that may require stable HFCLK until the * clock is enabled. * - * @sa nrfx_usbd_active_irq_config + * @sa nrf_usbd_common_active_irq_config */ -void nrfx_usbd_suspend_irq_config(void); +void nrf_usbd_common_suspend_irq_config(void); /** * @brief Default active interrupt configuration. * * Default interrupt configuration. - * Use in a pair with @ref nrfx_usbd_active_irq_config. + * Use in a pair with @ref nrf_usbd_common_active_irq_config. * - * @sa nrfx_usbd_suspend_irq_config + * @sa nrf_usbd_common_suspend_irq_config */ -void nrfx_usbd_active_irq_config(void); +void nrf_usbd_common_active_irq_config(void); /** * @brief Check the bus state. @@ -532,12 +542,12 @@ void nrfx_usbd_active_irq_config(void); * @retval true USBD bus is suspended. * @retval false USBD bus is active. */ -bool nrfx_usbd_bus_suspend_check(void); +bool nrf_usbd_common_bus_suspend_check(void); /** * @brief Force the bus state to active */ -void nrfx_usbd_force_bus_wakeup(void); +void nrf_usbd_common_force_bus_wakeup(void); /** * @brief Configure packet size that should be supported by the endpoint. @@ -549,10 +559,11 @@ void nrfx_usbd_force_bus_wakeup(void); * @param[in] ep Endpoint number. * @param[in] size Required maximum packet size. * - * @note Endpoint size is always set to @ref NRFX_USBD_EPSIZE or @ref NRFX_USBD_ISOSIZE / 2 - * when @ref nrfx_usbd_ep_enable function is called. + * @note Endpoint size is always set to @ref NRF_USBD_COMMON_EPSIZE + * or @ref NRF_USBD_COMMON_ISOSIZE / 2 + * when @ref nrf_usbd_common_ep_enable function is called. */ -void nrfx_usbd_ep_max_packet_size_set(nrfx_usbd_ep_t ep, uint16_t size); +void nrf_usbd_common_ep_max_packet_size_set(nrf_usbd_common_ep_t ep, uint16_t size); /** * @brief Get configured endpoint packet size. @@ -563,7 +574,7 @@ void nrfx_usbd_ep_max_packet_size_set(nrfx_usbd_ep_t ep, uint16_t size); * * @return Maximum pocket size configured on selected endpoint. */ -uint16_t nrfx_usbd_ep_max_packet_size_get(nrfx_usbd_ep_t ep); +uint16_t nrf_usbd_common_ep_max_packet_size_get(nrf_usbd_common_ep_t ep); /** * @brief Check if the selected endpoint is enabled. @@ -573,7 +584,7 @@ uint16_t nrfx_usbd_ep_max_packet_size_get(nrfx_usbd_ep_t ep); * @retval true Endpoint is enabled. * @retval false Endpoint is disabled. */ -bool nrfx_usbd_ep_enable_check(nrfx_usbd_ep_t ep); +bool nrf_usbd_common_ep_enable_check(nrf_usbd_common_ep_t ep); /** * @brief Enable selected endpoint. @@ -585,9 +596,9 @@ bool nrfx_usbd_ep_enable_check(nrfx_usbd_ep_t ep); * @note * Max packet size is set to endpoint default maximum value. * - * @sa nrfx_usbd_ep_max_packet_size_set + * @sa nrf_usbd_common_ep_max_packet_size_set */ -void nrfx_usbd_ep_enable(nrfx_usbd_ep_t ep); +void nrf_usbd_common_ep_enable(nrf_usbd_common_ep_t ep); /** * @brief Disable selected endpoint. @@ -596,14 +607,14 @@ void nrfx_usbd_ep_enable(nrfx_usbd_ep_t ep); * * @param[in] ep Endpoint number to disable. */ -void nrfx_usbd_ep_disable(nrfx_usbd_ep_t ep); +void nrf_usbd_common_ep_disable(nrf_usbd_common_ep_t ep); /** * @brief Disable all endpoints except for EP0. * * Disable all endpoints that can be disabled in USB device while it is still active. */ -void nrfx_usbd_ep_default_config(void); +void nrf_usbd_common_ep_default_config(void); /** * @brief Start sending data over endpoint. @@ -613,7 +624,7 @@ void nrfx_usbd_ep_default_config(void); * for transmission is prepared. * * @note Data buffer pointed by p_data have to be kept active till - * @ref NRFX_USBD_EVT_EPTRANSFER event is generated. + * @ref NRF_USBD_COMMON_EVT_EPTRANSFER event is generated. * * @param[in] ep Endpoint number. * For IN endpoint sending would be initiated. @@ -624,7 +635,8 @@ void nrfx_usbd_ep_default_config(void); * @retval NRFX_ERROR_BUSY Selected endpoint is pending. * @retval NRFX_ERROR_INVALID_ADDR Unexpected transfer on EPIN0 or EPOUT0. */ -nrfx_err_t nrfx_usbd_ep_transfer(nrfx_usbd_ep_t ep, nrfx_usbd_transfer_t const *p_transfer); +nrfx_err_t nrf_usbd_common_ep_transfer(nrf_usbd_common_ep_t ep, + nrf_usbd_common_transfer_t const *p_transfer); /** * @brief Start sending data over the endpoint using the transfer handler function. @@ -643,8 +655,8 @@ nrfx_err_t nrfx_usbd_ep_transfer(nrfx_usbd_ep_t ep, nrfx_usbd_transfer_t const * * @retval NRFX_ERROR_BUSY Selected endpoint is pending. * @retval NRFX_ERROR_INVALID_ADDR Unexpected transfer on EPIN0 or EPOUT0. */ -nrfx_err_t nrfx_usbd_ep_handled_transfer(nrfx_usbd_ep_t ep, - nrfx_usbd_handler_desc_t const *p_handler); +nrfx_err_t nrf_usbd_common_ep_handled_transfer(nrf_usbd_common_ep_t ep, + nrf_usbd_common_handler_desc_t const *p_handler); /** * @brief Get the temporary buffer to be used by the feeder. @@ -653,19 +665,19 @@ nrfx_err_t nrfx_usbd_ep_handled_transfer(nrfx_usbd_ep_t ep, * when the transfer is finished. * Use it for transfer preparation. * - * May be used inside the feeder configured in @ref nrfx_usbd_ep_handled_transfer. + * May be used inside the feeder configured in @ref nrf_usbd_common_ep_handled_transfer. * * @return Pointer to the buffer that can be used temporarily. * - * @sa NRFX_USBD_FEEDER_BUFFER_SIZE + * @sa NRF_USBD_COMMON_FEEDER_BUFFER_SIZE */ -void *nrfx_usbd_feeder_buffer_get(void); +void *nrf_usbd_common_feeder_buffer_get(void); /** * @brief Get the information about last finished or current transfer. * * Function returns the status of the last buffer set for transfer on selected endpoint. - * The status considers last buffer set by @ref nrfx_usbd_ep_transfer function or + * The status considers last buffer set by @ref nrf_usbd_common_ep_transfer function or * by transfer callback function. * * @param[in] ep Endpoint number. @@ -673,9 +685,9 @@ void *nrfx_usbd_feeder_buffer_get(void); * * @return Endpoint status. * - * @sa nrfx_usbd_ep_status_t + * @sa nrf_usbd_common_ep_status_t */ -nrfx_usbd_ep_status_t nrfx_usbd_ep_status_get(nrfx_usbd_ep_t ep, size_t *p_size); +nrf_usbd_common_ep_status_t nrf_usbd_common_ep_status_get(nrf_usbd_common_ep_t ep, size_t *p_size); /** * @brief Get number of received bytes. @@ -687,7 +699,7 @@ nrfx_usbd_ep_status_t nrfx_usbd_ep_status_get(nrfx_usbd_ep_t ep, size_t *p_size) * * @return Number of received bytes. */ -size_t nrfx_usbd_epout_size_get(nrfx_usbd_ep_t ep); +size_t nrf_usbd_common_epout_size_get(nrf_usbd_common_ep_t ep); /** * @brief Check if endpoint buffer is ready or is under USB IP control. @@ -701,7 +713,7 @@ size_t nrfx_usbd_epout_size_get(nrfx_usbd_ep_t ep); * and the endpoint does not have any data. * When endpoint is not busy: * - OUT (TX) endpoint: New data can be uploaded. - * - IN (RX) endpoint: New data can be downloaded using @ref nrfx_usbd_ep_transfer + * - IN (RX) endpoint: New data can be downloaded using @ref nrf_usbd_common_ep_transfer * function. * * @param[in] ep Endpoint number. @@ -709,7 +721,7 @@ size_t nrfx_usbd_epout_size_get(nrfx_usbd_ep_t ep); * @retval false Endpoint is not busy. * @retval true Endpoint is busy. */ -bool nrfx_usbd_ep_is_busy(nrfx_usbd_ep_t ep); +bool nrf_usbd_common_ep_is_busy(nrf_usbd_common_ep_t ep); /** * @brief Stall endpoint @@ -717,12 +729,12 @@ bool nrfx_usbd_ep_is_busy(nrfx_usbd_ep_t ep); * Stall endpoit to send error information during next transfer request from * the host. * - * @note To stall endpoint it is safer to use @ref nrfx_usbd_setup_stall + * @note To stall endpoint it is safer to use @ref nrf_usbd_common_setup_stall * @note Stalled endpoint would not be cleared when DMA transfer finishes. * * @param[in] ep Endpoint number to stall. */ -void nrfx_usbd_ep_stall(nrfx_usbd_ep_t ep); +void nrf_usbd_common_ep_stall(nrf_usbd_common_ep_t ep); /** * @brief Clear stall flag on endpoint. @@ -737,7 +749,7 @@ void nrfx_usbd_ep_stall(nrfx_usbd_ep_t ep); * * @param[in] ep Endpoint number. */ -void nrfx_usbd_ep_stall_clear(nrfx_usbd_ep_t ep); +void nrf_usbd_common_ep_stall_clear(nrf_usbd_common_ep_t ep); /** * @brief Check if endpoint is stalled. @@ -749,14 +761,14 @@ void nrfx_usbd_ep_stall_clear(nrfx_usbd_ep_t ep); * @retval false Endpoint is not stalled. * @retval true Endpoint is stalled. */ -bool nrfx_usbd_ep_stall_check(nrfx_usbd_ep_t ep); +bool nrf_usbd_common_ep_stall_check(nrf_usbd_common_ep_t ep); /** * @brief Clear current endpoint data toggle. * * @param[in] ep Endpoint number to clear. */ -void nrfx_usbd_ep_dtoggle_clear(nrfx_usbd_ep_t ep); +void nrf_usbd_common_ep_dtoggle_clear(nrf_usbd_common_ep_t ep); /** * @brief Get parsed setup data. @@ -766,7 +778,7 @@ void nrfx_usbd_ep_dtoggle_clear(nrfx_usbd_ep_t ep); * @param[out] p_setup Pointer to data structure that would be filled by * parsed data. */ -void nrfx_usbd_setup_get(nrfx_usbd_setup_t *p_setup); +void nrf_usbd_common_setup_get(nrf_usbd_common_setup_t *p_setup); /** * @brief Clear the control endpoint for packet reception during DATA stage. @@ -774,9 +786,9 @@ void nrfx_usbd_setup_get(nrfx_usbd_setup_t *p_setup); * This function may be called if any more data in control write transfer is expected. * Clears only OUT endpoint to be able to take another OUT data token. * It does not allow STATUS stage. - * @sa nrfx_usbd_setup_clear + * @sa nrf_usbd_common_setup_clear */ -void nrfx_usbd_setup_data_clear(void); +void nrf_usbd_common_setup_data_clear(void); /** * @brief Clear setup endpoint. @@ -784,45 +796,47 @@ void nrfx_usbd_setup_data_clear(void); * This function acknowledges setup when SETUP command was received and processed. * It has to be called if no data respond for the SETUP command is sent. */ -void nrfx_usbd_setup_clear(void); +void nrf_usbd_common_setup_clear(void); /** * @brief Stall setup endpoint. * * Mark an error on setup endpoint. */ -void nrfx_usbd_setup_stall(void); +void nrf_usbd_common_setup_stall(void); /** * @brief Abort pending transfer on selected endpoint. * * @param[in] ep Endpoint number. */ -void nrfx_usbd_ep_abort(nrfx_usbd_ep_t ep); +void nrf_usbd_common_ep_abort(nrf_usbd_common_ep_t ep); /** * @brief Get the information about expected transfer SETUP data direction. * * Function returns the information about last expected transfer direction. * - * @retval NRFX_USBD_EPOUT0 Expecting OUT (Host->Device) direction or no data. - * @retval NRFX_USBD_EPIN0 Expecting IN (Device->Host) direction. + * @retval NRF_USBD_COMMON_EPOUT0 Expecting OUT (Host->Device) direction or no data. + * @retval NRF_USBD_COMMON_EPIN0 Expecting IN (Device->Host) direction. */ -nrfx_usbd_ep_t nrfx_usbd_last_setup_dir_get(void); +nrf_usbd_common_ep_t nrf_usbd_common_last_setup_dir_get(void); /** * @brief Drop transfer on OUT endpoint. * * @param[in] ep OUT endpoint ID. */ -void nrfx_usbd_transfer_out_drop(nrfx_usbd_ep_t ep); +void nrf_usbd_common_transfer_out_drop(nrf_usbd_common_ep_t ep); /** @} */ -void nrfx_usbd_irq_handler(void); +void nrf_usbd_common_irq_handler(void); #ifdef __cplusplus } #endif -#endif /* NRFX_USBD_H__ */ +#endif /* NRF_USBD_COMMON_H__ */ + +/** @endcond */ diff --git a/drivers/usb/common/nrf_usbd_common/nrf_usbd_common_errata.h b/drivers/usb/common/nrf_usbd_common/nrf_usbd_common_errata.h new file mode 100644 index 00000000000..0ee23ccd2c5 --- /dev/null +++ b/drivers/usb/common/nrf_usbd_common/nrf_usbd_common_errata.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2016 - 2023, Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* This file is undergoing transition towards native Zephyr nrf USB driver. */ + +/** @cond INTERNAL_HIDDEN */ + +#ifndef NRF_USBD_COMMON_ERRATA_H__ +#define NRF_USBD_COMMON_ERRATA_H__ + +#include +#include + +#ifndef NRF_USBD_COMMON_ERRATA_ENABLE +/** + * @brief The constant that informs if errata should be enabled at all. + * + * If this constant is set to 0, all the Errata bug fixes will be automatically disabled. + */ +#define NRF_USBD_COMMON_ERRATA_ENABLE 1 +#endif + +/* Errata: ISO double buffering not functional. **/ +static inline bool nrf_usbd_common_errata_166(void) +{ + return NRF_USBD_COMMON_ERRATA_ENABLE && nrf52_errata_166(); +} + +/* Errata: USBD might not reach its active state. **/ +static inline bool nrf_usbd_common_errata_171(void) +{ + return NRF_USBD_COMMON_ERRATA_ENABLE && nrf52_errata_171(); +} + +/* Errata: USB cannot be enabled. **/ +static inline bool nrf_usbd_common_errata_187(void) +{ + return NRF_USBD_COMMON_ERRATA_ENABLE && nrf52_errata_187(); +} + +/* Errata: USBD cannot receive tasks during DMA. **/ +static inline bool nrf_usbd_common_errata_199(void) +{ + return NRF_USBD_COMMON_ERRATA_ENABLE && nrf52_errata_199(); +} + +/* Errata: Device remains in SUSPEND too long. */ +static inline bool nrf_usbd_common_errata_211(void) +{ + return NRF_USBD_COMMON_ERRATA_ENABLE && nrf52_errata_211(); +} + +/* Errata: Unexpected behavior after reset. **/ +static inline bool nrf_usbd_common_errata_223(void) +{ + return NRF_USBD_COMMON_ERRATA_ENABLE && nrf52_errata_223(); +} + +#endif /* NRF_USBD_COMMON_ERRATA_H__ */ + +/** @endcond */ diff --git a/drivers/usb/device/Kconfig b/drivers/usb/device/Kconfig index 768c0da7cf9..41d3d446f8d 100644 --- a/drivers/usb/device/Kconfig +++ b/drivers/usb/device/Kconfig @@ -104,7 +104,7 @@ config USB_NRFX bool "Nordic Semiconductor USB Device Controller Driver" default y depends on DT_HAS_NORDIC_NRF_USBD_ENABLED - select NRFX_USBD + select NRF_USBD_COMMON select NRFX_POWER imply USB_DEVICE_REMOTE_WAKEUP help diff --git a/drivers/usb/device/usb_dc_nrfx.c b/drivers/usb/device/usb_dc_nrfx.c index a8032baf1f1..49cb4621911 100644 --- a/drivers/usb/device/usb_dc_nrfx.c +++ b/drivers/usb/device/usb_dc_nrfx.c @@ -22,7 +22,8 @@ #include #include #include -#include +#include +#include #include @@ -288,12 +289,12 @@ static inline bool dev_ready(void) return get_usbd_ctx()->ready; } -static inline nrfx_usbd_ep_t ep_addr_to_nrfx(uint8_t ep) +static inline nrf_usbd_common_ep_t ep_addr_to_nrfx(uint8_t ep) { - return (nrfx_usbd_ep_t)ep; + return (nrf_usbd_common_ep_t)ep; } -static inline uint8_t nrfx_addr_to_ep(nrfx_usbd_ep_t ep) +static inline uint8_t nrfx_addr_to_ep(nrf_usbd_common_ep_t ep) { return (uint8_t)ep; } @@ -559,7 +560,7 @@ static void usbd_enable_endpoints(struct nrf_usbd_ctx *ctx) __ASSERT_NO_MSG(ep_ctx); if (ep_ctx->cfg.en) { - nrfx_usbd_ep_enable(ep_addr_to_nrfx(ep_ctx->cfg.addr)); + nrf_usbd_common_ep_enable(ep_addr_to_nrfx(ep_ctx->cfg.addr)); } } @@ -568,7 +569,7 @@ static void usbd_enable_endpoints(struct nrf_usbd_ctx *ctx) __ASSERT_NO_MSG(ep_ctx); if (ep_ctx->cfg.en) { - nrfx_usbd_ep_enable(ep_addr_to_nrfx(ep_ctx->cfg.addr)); + nrf_usbd_common_ep_enable(ep_addr_to_nrfx(ep_ctx->cfg.addr)); } } @@ -577,7 +578,7 @@ static void usbd_enable_endpoints(struct nrf_usbd_ctx *ctx) __ASSERT_NO_MSG(ep_ctx); if (ep_ctx->cfg.en) { - nrfx_usbd_ep_enable(ep_addr_to_nrfx(ep_ctx->cfg.addr)); + nrf_usbd_common_ep_enable(ep_addr_to_nrfx(ep_ctx->cfg.addr)); } } @@ -586,7 +587,7 @@ static void usbd_enable_endpoints(struct nrf_usbd_ctx *ctx) __ASSERT_NO_MSG(ep_ctx); if (ep_ctx->cfg.en) { - nrfx_usbd_ep_enable(ep_addr_to_nrfx(ep_ctx->cfg.addr)); + nrf_usbd_common_ep_enable(ep_addr_to_nrfx(ep_ctx->cfg.addr)); } } } @@ -606,7 +607,7 @@ static void ep_ctx_reset(struct nrf_usbd_ep_ctx *ep_ctx) /* Abort ongoing write operation. */ if (ep_ctx->write_in_progress) { - nrfx_usbd_ep_abort(ep_addr_to_nrfx(ep_ctx->cfg.addr)); + nrf_usbd_common_ep_abort(ep_addr_to_nrfx(ep_ctx->cfg.addr)); } ep_ctx->read_complete = true; @@ -673,9 +674,9 @@ static inline void usbd_work_process_pwr_events(struct usbd_pwr_event *pwr_evt) switch (pwr_evt->state) { case USBD_ATTACHED: - if (!nrfx_usbd_is_enabled()) { + if (!nrf_usbd_common_is_enabled()) { LOG_DBG("USB detected"); - nrfx_usbd_enable(); + nrf_usbd_common_enable(); err = hfxo_start(ctx); __ASSERT_NO_MSG(err >= 0); } @@ -687,7 +688,7 @@ static inline void usbd_work_process_pwr_events(struct usbd_pwr_event *pwr_evt) case USBD_POWERED: usbd_enable_endpoints(ctx); - nrfx_usbd_start(IS_ENABLED(CONFIG_USB_DEVICE_SOF)); + nrf_usbd_common_start(IS_ENABLED(CONFIG_USB_DEVICE_SOF)); ctx->ready = true; LOG_DBG("USB Powered"); @@ -699,7 +700,7 @@ static inline void usbd_work_process_pwr_events(struct usbd_pwr_event *pwr_evt) case USBD_DETACHED: ctx->ready = false; - nrfx_usbd_disable(); + nrf_usbd_common_disable(); err = hfxo_stop(ctx); __ASSERT_NO_MSG(err >= 0); @@ -712,7 +713,7 @@ static inline void usbd_work_process_pwr_events(struct usbd_pwr_event *pwr_evt) case USBD_SUSPENDED: if (dev_ready()) { - nrfx_usbd_suspend(); + nrf_usbd_common_suspend(); LOG_DBG("USB Suspend state"); if (ctx->status_cb) { @@ -771,7 +772,7 @@ static inline void usbd_work_process_setup(struct nrf_usbd_ep_ctx *ep_ctx) if (usb_reqtype_is_to_device(usbd_setup) && usbd_setup->wLength) { ctx->ctrl_read_len = usbd_setup->wLength; /* Allow data chunk on EP0 OUT */ - nrfx_usbd_setup_data_clear(); + nrf_usbd_common_setup_data_clear(); } else { ctx->ctrl_read_len = 0U; } @@ -791,9 +792,9 @@ static inline void usbd_work_process_recvreq(struct nrf_usbd_ctx *ctx, ep_ctx->read_complete = false; k_mutex_lock(&ctx->drv_lock, K_FOREVER); - NRFX_USBD_TRANSFER_OUT(transfer, ep_ctx->buf.data, - ep_ctx->cfg.max_sz); - nrfx_err_t err = nrfx_usbd_ep_transfer( + NRF_USBD_COMMON_TRANSFER_OUT(transfer, ep_ctx->buf.data, + ep_ctx->cfg.max_sz); + nrfx_err_t err = nrf_usbd_common_ep_transfer( ep_addr_to_nrfx(ep_ctx->cfg.addr), &transfer); if (err != NRFX_SUCCESS) { LOG_ERR("nRF USBD transfer error (OUT): 0x%02x", err); @@ -831,7 +832,7 @@ static inline void usbd_work_process_ep_events(struct usbd_ep_event *ep_evt) * no ZLP required. */ k_mutex_lock(&ctx->drv_lock, K_FOREVER); - nrfx_usbd_setup_clear(); + nrf_usbd_common_setup_clear(); k_mutex_unlock(&ctx->drv_lock); } ep_ctx->cfg.cb(ep_ctx->cfg.addr, @@ -842,14 +843,14 @@ static inline void usbd_work_process_ep_events(struct usbd_ep_event *ep_evt) } } -static void usbd_event_transfer_ctrl(nrfx_usbd_evt_t const *const p_event) +static void usbd_event_transfer_ctrl(nrf_usbd_common_evt_t const *const p_event) { struct nrf_usbd_ep_ctx *ep_ctx = endpoint_ctx(p_event->data.eptransfer.ep); if (NRF_USBD_EPIN_CHECK(p_event->data.eptransfer.ep)) { switch (p_event->data.eptransfer.status) { - case NRFX_USBD_EP_OK: { + case NRF_USBD_COMMON_EP_OK: { struct usbd_event *ev = usbd_evt_alloc(); if (!ev) { @@ -867,7 +868,7 @@ static void usbd_event_transfer_ctrl(nrfx_usbd_evt_t const *const p_event) } break; - case NRFX_USBD_EP_ABORTED: { + case NRF_USBD_COMMON_EP_ABORTED: { LOG_DBG("Endpoint 0x%02x write aborted", p_event->data.eptransfer.ep); } @@ -882,7 +883,7 @@ static void usbd_event_transfer_ctrl(nrfx_usbd_evt_t const *const p_event) } } else { switch (p_event->data.eptransfer.status) { - case NRFX_USBD_EP_WAITING: { + case NRF_USBD_COMMON_EP_WAITING: { struct usbd_event *ev = usbd_evt_alloc(); if (!ev) { @@ -901,23 +902,23 @@ static void usbd_event_transfer_ctrl(nrfx_usbd_evt_t const *const p_event) } break; - case NRFX_USBD_EP_OK: { + case NRF_USBD_COMMON_EP_OK: { struct nrf_usbd_ctx *ctx = get_usbd_ctx(); struct usbd_event *ev = usbd_evt_alloc(); if (!ev) { return; } - nrfx_usbd_ep_status_t err_code; + nrf_usbd_common_ep_status_t err_code; ev->evt_type = USBD_EVT_EP; ev->evt.ep_evt.evt_type = EP_EVT_RECV_COMPLETE; ev->evt.ep_evt.ep = ep_ctx; - err_code = nrfx_usbd_ep_status_get( + err_code = nrf_usbd_common_ep_status_get( p_event->data.eptransfer.ep, &ep_ctx->buf.len); - if (err_code != NRFX_USBD_EP_OK) { + if (err_code != NRF_USBD_COMMON_EP_OK) { LOG_ERR("_ep_status_get failed! Code: %d", err_code); __ASSERT_NO_MSG(0); @@ -927,7 +928,7 @@ static void usbd_event_transfer_ctrl(nrfx_usbd_evt_t const *const p_event) if (ctx->ctrl_read_len > ep_ctx->buf.len) { ctx->ctrl_read_len -= ep_ctx->buf.len; /* Allow next data chunk on EP0 OUT */ - nrfx_usbd_setup_data_clear(); + nrf_usbd_common_setup_data_clear(); } else { ctx->ctrl_read_len = 0U; } @@ -947,14 +948,14 @@ static void usbd_event_transfer_ctrl(nrfx_usbd_evt_t const *const p_event) } } -static void usbd_event_transfer_data(nrfx_usbd_evt_t const *const p_event) +static void usbd_event_transfer_data(nrf_usbd_common_evt_t const *const p_event) { struct nrf_usbd_ep_ctx *ep_ctx = endpoint_ctx(p_event->data.eptransfer.ep); if (NRF_USBD_EPIN_CHECK(p_event->data.eptransfer.ep)) { switch (p_event->data.eptransfer.status) { - case NRFX_USBD_EP_OK: { + case NRF_USBD_COMMON_EP_OK: { struct usbd_event *ev = usbd_evt_alloc(); if (!ev) { @@ -973,7 +974,7 @@ static void usbd_event_transfer_data(nrfx_usbd_evt_t const *const p_event) } break; - case NRFX_USBD_EP_ABORTED: { + case NRF_USBD_COMMON_EP_ABORTED: { LOG_DBG("Endpoint 0x%02x write aborted", p_event->data.eptransfer.ep); } @@ -989,7 +990,7 @@ static void usbd_event_transfer_data(nrfx_usbd_evt_t const *const p_event) } else { switch (p_event->data.eptransfer.status) { - case NRFX_USBD_EP_WAITING: { + case NRF_USBD_COMMON_EP_WAITING: { struct usbd_event *ev = usbd_evt_alloc(); if (!ev) { @@ -1009,7 +1010,7 @@ static void usbd_event_transfer_data(nrfx_usbd_evt_t const *const p_event) } break; - case NRFX_USBD_EP_OK: { + case NRF_USBD_COMMON_EP_OK: { struct usbd_event *ev = usbd_evt_alloc(); if (!ev) { @@ -1045,42 +1046,42 @@ static void usbd_event_transfer_data(nrfx_usbd_evt_t const *const p_event) /** * @brief nRFx USBD driver event handler function. */ -static void usbd_event_handler(nrfx_usbd_evt_t const *const p_event) +static void usbd_event_handler(nrf_usbd_common_evt_t const *const p_event) { struct usbd_event evt = {0}; bool put_evt = false; switch (p_event->type) { - case NRFX_USBD_EVT_SUSPEND: + case NRF_USBD_COMMON_EVT_SUSPEND: LOG_DBG("SUSPEND state detected"); evt.evt_type = USBD_EVT_POWER; evt.evt.pwr_evt.state = USBD_SUSPENDED; put_evt = true; break; - case NRFX_USBD_EVT_RESUME: + case NRF_USBD_COMMON_EVT_RESUME: LOG_DBG("RESUMING from suspend"); evt.evt_type = USBD_EVT_POWER; evt.evt.pwr_evt.state = USBD_RESUMED; put_evt = true; break; - case NRFX_USBD_EVT_WUREQ: + case NRF_USBD_COMMON_EVT_WUREQ: LOG_DBG("RemoteWU initiated"); evt.evt_type = USBD_EVT_POWER; evt.evt.pwr_evt.state = USBD_RESUMED; put_evt = true; break; - case NRFX_USBD_EVT_RESET: + case NRF_USBD_COMMON_EVT_RESET: evt.evt_type = USBD_EVT_RESET; put_evt = true; break; - case NRFX_USBD_EVT_SOF: + case NRF_USBD_COMMON_EVT_SOF: if (IS_ENABLED(CONFIG_USB_DEVICE_SOF)) { evt.evt_type = USBD_EVT_SOF; put_evt = true; } break; - case NRFX_USBD_EVT_EPTRANSFER: { + case NRF_USBD_COMMON_EVT_EPTRANSFER: { struct nrf_usbd_ep_ctx *ep_ctx; ep_ctx = endpoint_ctx(p_event->data.eptransfer.ep); @@ -1101,10 +1102,10 @@ static void usbd_event_handler(nrfx_usbd_evt_t const *const p_event) break; } - case NRFX_USBD_EVT_SETUP: { - nrfx_usbd_setup_t drv_setup; + case NRF_USBD_COMMON_EVT_SETUP: { + nrf_usbd_common_setup_t drv_setup; - nrfx_usbd_setup_get(&drv_setup); + nrf_usbd_common_setup_get(&drv_setup); if ((drv_setup.bRequest != USB_SREQ_SET_ADDRESS) || (USB_REQTYPE_GET_TYPE(drv_setup.bmRequestType) != USB_REQTYPE_TYPE_STANDARD)) { @@ -1147,8 +1148,8 @@ static inline void usbd_reinit(void) nrfx_err_t err; nrfx_power_usbevt_disable(); - nrfx_usbd_disable(); - nrfx_usbd_uninit(); + nrf_usbd_common_disable(); + nrf_usbd_common_uninit(); usbd_evt_flush(); @@ -1156,7 +1157,7 @@ static inline void usbd_reinit(void) __ASSERT_NO_MSG(ret == 0); nrfx_power_usbevt_enable(); - err = nrfx_usbd_init(usbd_event_handler); + err = nrf_usbd_common_init(usbd_event_handler); if (err != NRFX_SUCCESS) { LOG_DBG("nRF USBD driver reinit failed. Code: %d", err); @@ -1177,7 +1178,7 @@ static void usbd_sof_trigger_iso_read(void) struct usbd_event *ev; struct nrf_usbd_ep_ctx *ep_ctx; - ep_ctx = endpoint_ctx(NRFX_USBD_EPOUT8); + ep_ctx = endpoint_ctx(NRF_USBD_COMMON_EPOUT8); if (!ep_ctx) { LOG_ERR("There is no ISO ep"); return; @@ -1281,7 +1282,7 @@ int usb_dc_attach(void) (CLOCK_CONTROL_NRF_SUBSYS_HF))); IRQ_CONNECT(DT_INST_IRQN(0), DT_INST_IRQ(0, priority), - nrfx_isr, nrfx_usbd_irq_handler, 0); + nrfx_isr, nrf_usbd_common_irq_handler, 0); nrfx_power_usbevt_enable(); @@ -1316,8 +1317,8 @@ int usb_dc_detach(void) usbd_evt_flush(); - if (nrfx_usbd_is_enabled()) { - nrfx_usbd_disable(); + if (nrf_usbd_common_is_enabled()) { + nrf_usbd_common_disable(); } (void)hfxo_stop(ctx); @@ -1440,8 +1441,8 @@ int usb_dc_ep_configure(const struct usb_dc_ep_cfg_data *const ep_cfg) } } - nrfx_usbd_ep_max_packet_size_set(ep_addr_to_nrfx(ep_cfg->ep_addr), - ep_cfg->ep_mps); + nrf_usbd_common_ep_max_packet_size_set(ep_addr_to_nrfx(ep_cfg->ep_addr), + ep_cfg->ep_mps); return 0; } @@ -1461,11 +1462,11 @@ int usb_dc_ep_set_stall(const uint8_t ep) switch (ep_ctx->cfg.type) { case USB_DC_EP_CONTROL: - nrfx_usbd_setup_stall(); + nrf_usbd_common_setup_stall(); break; case USB_DC_EP_BULK: case USB_DC_EP_INTERRUPT: - nrfx_usbd_ep_stall(ep_addr_to_nrfx(ep)); + nrf_usbd_common_ep_stall(ep_addr_to_nrfx(ep)); break; case USB_DC_EP_ISOCHRONOUS: LOG_ERR("STALL unsupported on ISO endpoint"); @@ -1499,8 +1500,8 @@ int usb_dc_ep_clear_stall(const uint8_t ep) return -EINVAL; } - nrfx_usbd_ep_dtoggle_clear(ep_addr_to_nrfx(ep)); - nrfx_usbd_ep_stall_clear(ep_addr_to_nrfx(ep)); + nrf_usbd_common_ep_dtoggle_clear(ep_addr_to_nrfx(ep)); + nrf_usbd_common_ep_stall_clear(ep_addr_to_nrfx(ep)); LOG_DBG("Unstall on EP 0x%02x", ep); return 0; @@ -1528,7 +1529,7 @@ int usb_dc_ep_is_stalled(const uint8_t ep, uint8_t *const stalled) return -EINVAL; } - *stalled = (uint8_t) nrfx_usbd_ep_stall_check(ep_addr_to_nrfx(ep)); + *stalled = (uint8_t) nrf_usbd_common_ep_stall_check(ep_addr_to_nrfx(ep)); return 0; } @@ -1550,11 +1551,11 @@ int usb_dc_ep_enable(const uint8_t ep) /* ISO transactions for full-speed device do not support * toggle sequencing and should only send DATA0 PID. */ - nrfx_usbd_ep_dtoggle_clear(ep_addr_to_nrfx(ep)); + nrf_usbd_common_ep_dtoggle_clear(ep_addr_to_nrfx(ep)); /** Endpoint is enabled on SetInterface request. * This should also clear EP's halt status. */ - nrfx_usbd_ep_stall_clear(ep_addr_to_nrfx(ep)); + nrf_usbd_common_ep_stall_clear(ep_addr_to_nrfx(ep)); } if (ep_ctx->cfg.en) { return -EALREADY; @@ -1566,7 +1567,7 @@ int usb_dc_ep_enable(const uint8_t ep) /* Defer the endpoint enable if USBD is not ready yet. */ if (dev_ready()) { - nrfx_usbd_ep_enable(ep_addr_to_nrfx(ep)); + nrf_usbd_common_ep_enable(ep_addr_to_nrfx(ep)); } return 0; @@ -1587,8 +1588,8 @@ int usb_dc_ep_disable(const uint8_t ep) LOG_DBG("EP disable: 0x%02x", ep); - nrfx_usbd_ep_disable(ep_addr_to_nrfx(ep)); - /* Clear write_in_progress as nrfx_usbd_ep_disable() + nrf_usbd_common_ep_disable(ep_addr_to_nrfx(ep)); + /* Clear write_in_progress as nrf_usbd_common_ep_disable() * terminates endpoint transaction. */ ep_ctx->write_in_progress = false; @@ -1614,7 +1615,7 @@ int usb_dc_ep_flush(const uint8_t ep) ep_ctx->buf.len = 0U; ep_ctx->buf.curr = ep_ctx->buf.data; - nrfx_usbd_transfer_out_drop(ep_addr_to_nrfx(ep)); + nrf_usbd_common_transfer_out_drop(ep_addr_to_nrfx(ep)); return 0; } @@ -1682,15 +1683,15 @@ int usb_dc_ep_write(const uint8_t ep, const uint8_t *const data, * and perform appropriate action. */ if ((ep_ctx->cfg.type == USB_DC_EP_CONTROL) - && (nrfx_usbd_last_setup_dir_get() != ep)) { - nrfx_usbd_setup_clear(); + && (nrf_usbd_common_last_setup_dir_get() != ep)) { + nrf_usbd_common_setup_clear(); k_mutex_unlock(&ctx->drv_lock); return 0; } ep_ctx->write_in_progress = true; - NRFX_USBD_TRANSFER_IN(transfer, data, data_len, 0); - nrfx_err_t err = nrfx_usbd_ep_transfer(ep_addr_to_nrfx(ep), &transfer); + NRF_USBD_COMMON_TRANSFER_IN(transfer, data, data_len, 0); + nrfx_err_t err = nrf_usbd_common_ep_transfer(ep_addr_to_nrfx(ep), &transfer); if (err != NRFX_SUCCESS) { ep_ctx->write_in_progress = false; @@ -1870,7 +1871,7 @@ int usb_dc_ep_mps(const uint8_t ep) int usb_dc_wakeup_request(void) { - bool res = nrfx_usbd_wakeup_req(); + bool res = nrf_usbd_common_wakeup_req(); if (!res) { return -EAGAIN; @@ -1906,7 +1907,7 @@ static int usb_init(void) .handler = usb_dc_power_event_handler }; - err = nrfx_usbd_init(usbd_event_handler); + err = nrf_usbd_common_init(usbd_event_handler); if (err != NRFX_SUCCESS) { LOG_DBG("nRF USBD driver init failed. Code: %d", (uint32_t)err); return -EIO; diff --git a/drivers/usb/udc/Kconfig.nrf b/drivers/usb/udc/Kconfig.nrf index 0f424ffe5d0..93c5090bed2 100644 --- a/drivers/usb/udc/Kconfig.nrf +++ b/drivers/usb/udc/Kconfig.nrf @@ -5,7 +5,7 @@ config UDC_NRF bool "Nordic Semiconductor USB device controller driver" default y depends on DT_HAS_NORDIC_NRF_USBD_ENABLED - select NRFX_USBD + select NRF_USBD_COMMON select NRFX_POWER help nRF USB device controller driver. diff --git a/drivers/usb/udc/udc_nrf.c b/drivers/usb/udc/udc_nrf.c index 64fae5dae21..bca098347d8 100644 --- a/drivers/usb/udc/udc_nrf.c +++ b/drivers/usb/udc/udc_nrf.c @@ -21,7 +21,8 @@ #include #include -#include +#include +#include #include #include "udc_common.h" @@ -47,7 +48,7 @@ enum udc_nrf_event_type { struct udc_nrf_evt { enum udc_nrf_event_type type; union { - nrfx_usbd_evt_t hal_evt; + nrf_usbd_common_evt_t hal_evt; uint8_t ep; }; }; @@ -82,10 +83,10 @@ static struct onoff_client hfxo_cli; static void udc_nrf_clear_control_out(const struct device *dev) { - if (nrfx_usbd_last_setup_dir_get() == USB_CONTROL_EP_OUT && + if (nrf_usbd_common_last_setup_dir_get() == USB_CONTROL_EP_OUT && udc_nrf_setup_rcvd) { /* Allow data chunk on EP0 OUT */ - nrfx_usbd_setup_data_clear(); + nrf_usbd_common_setup_data_clear(); udc_nrf_setup_rcvd = false; LOG_INF("Allow data OUT"); } @@ -101,15 +102,15 @@ static void udc_event_xfer_in_next(const struct device *dev, const uint8_t ep) buf = udc_buf_peek(dev, ep); if (buf != NULL) { - nrfx_usbd_transfer_t xfer = { + nrf_usbd_common_transfer_t xfer = { .p_data = {.tx = buf->data}, .size = buf->len, .flags = udc_ep_buf_has_zlp(buf) ? - NRFX_USBD_TRANSFER_ZLP_FLAG : 0, + NRF_USBD_COMMON_TRANSFER_ZLP_FLAG : 0, }; nrfx_err_t err; - err = nrfx_usbd_ep_transfer(ep, &xfer); + err = nrf_usbd_common_ep_transfer(ep, &xfer); if (err != NRFX_SUCCESS) { LOG_ERR("ep 0x%02x nrfx error: %x", ep, err); /* REVISE: remove from endpoint queue? ASSERT? */ @@ -141,7 +142,7 @@ static void udc_event_xfer_ctrl_in(const struct device *dev, /* Update to next stage of control transfer */ udc_ctrl_update_stage(dev, buf); - nrfx_usbd_setup_clear(); + nrf_usbd_common_setup_clear(); } static void udc_event_fake_status_in(const struct device *dev) @@ -159,13 +160,13 @@ static void udc_event_fake_status_in(const struct device *dev) } static void udc_event_xfer_in(const struct device *dev, - nrfx_usbd_evt_t const *const event) + nrf_usbd_common_evt_t const *const event) { uint8_t ep = event->data.eptransfer.ep; struct net_buf *buf; switch (event->data.eptransfer.status) { - case NRFX_USBD_EP_OK: + case NRF_USBD_COMMON_EP_OK: buf = udc_buf_get(dev, ep); if (buf == NULL) { LOG_ERR("ep 0x%02x queue is empty", ep); @@ -181,7 +182,7 @@ static void udc_event_xfer_in(const struct device *dev, udc_submit_ep_event(dev, buf, 0); break; - case NRFX_USBD_EP_ABORTED: + case NRF_USBD_COMMON_EP_ABORTED: LOG_WRN("aborted IN ep 0x%02x", ep); buf = udc_buf_get_all(dev, ep); @@ -228,14 +229,14 @@ static void udc_event_xfer_out_next(const struct device *dev, const uint8_t ep) buf = udc_buf_peek(dev, ep); if (buf != NULL) { - nrfx_usbd_transfer_t xfer = { + nrf_usbd_common_transfer_t xfer = { .p_data = {.rx = buf->data}, .size = buf->size, .flags = 0, }; nrfx_err_t err; - err = nrfx_usbd_ep_transfer(ep, &xfer); + err = nrf_usbd_common_ep_transfer(ep, &xfer); if (err != NRFX_SUCCESS) { LOG_ERR("ep 0x%02x nrfx error: %x", ep, err); /* REVISE: remove from endpoint queue? ASSERT? */ @@ -249,24 +250,24 @@ static void udc_event_xfer_out_next(const struct device *dev, const uint8_t ep) } static void udc_event_xfer_out(const struct device *dev, - nrfx_usbd_evt_t const *const event) + nrf_usbd_common_evt_t const *const event) { uint8_t ep = event->data.eptransfer.ep; - nrfx_usbd_ep_status_t err_code; + nrf_usbd_common_ep_status_t err_code; struct net_buf *buf; size_t len; switch (event->data.eptransfer.status) { - case NRFX_USBD_EP_WAITING: + case NRF_USBD_COMMON_EP_WAITING: /* * There is nothing to do here, new transfer * will be tried in both cases later. */ break; - case NRFX_USBD_EP_OK: - err_code = nrfx_usbd_ep_status_get(ep, &len); - if (err_code != NRFX_USBD_EP_OK) { + case NRF_USBD_COMMON_EP_OK: + err_code = nrf_usbd_common_ep_status_get(ep, &len); + if (err_code != NRF_USBD_COMMON_EP_OK) { LOG_ERR("OUT transfer failed %d", err_code); } @@ -325,8 +326,8 @@ static int udc_event_xfer_setup(const struct device *dev) } udc_ep_buf_set_setup(buf); - nrfx_usbd_setup_get((nrfx_usbd_setup_t *)buf->data); - net_buf_add(buf, sizeof(nrfx_usbd_setup_t)); + nrf_usbd_common_setup_get((nrf_usbd_common_setup_t *)buf->data); + net_buf_add(buf, sizeof(nrf_usbd_common_setup_t)); udc_nrf_setup_rcvd = true; /* Update to next stage of control transfer */ @@ -366,7 +367,7 @@ static void udc_nrf_thread(void *p1, void *p2, void *p3) case UDC_NRF_EVT_HAL: ep = evt.hal_evt.data.eptransfer.ep; switch (evt.hal_evt.type) { - case NRFX_USBD_EVT_EPTRANSFER: + case NRF_USBD_COMMON_EVT_EPTRANSFER: start_xfer = true; if (USB_EP_DIR_IS_IN(ep)) { udc_event_xfer_in(dev, &evt.hal_evt); @@ -374,7 +375,7 @@ static void udc_nrf_thread(void *p1, void *p2, void *p3) udc_event_xfer_out(dev, &evt.hal_evt); } break; - case NRFX_USBD_EVT_SETUP: + case NRF_USBD_COMMON_EVT_SETUP: udc_event_xfer_setup(dev); break; default: @@ -419,33 +420,33 @@ static void udc_sof_check_iso_out(const struct device *dev) } } -static void usbd_event_handler(nrfx_usbd_evt_t const *const hal_evt) +static void usbd_event_handler(nrf_usbd_common_evt_t const *const hal_evt) { switch (hal_evt->type) { - case NRFX_USBD_EVT_SUSPEND: + case NRF_USBD_COMMON_EVT_SUSPEND: LOG_INF("SUSPEND state detected"); - nrfx_usbd_suspend(); + nrf_usbd_common_suspend(); udc_set_suspended(udc_nrf_dev, true); udc_submit_event(udc_nrf_dev, UDC_EVT_SUSPEND, 0); break; - case NRFX_USBD_EVT_RESUME: + case NRF_USBD_COMMON_EVT_RESUME: LOG_INF("RESUMING from suspend"); udc_set_suspended(udc_nrf_dev, false); udc_submit_event(udc_nrf_dev, UDC_EVT_RESUME, 0); break; - case NRFX_USBD_EVT_WUREQ: + case NRF_USBD_COMMON_EVT_WUREQ: LOG_INF("Remote wakeup initiated"); break; - case NRFX_USBD_EVT_RESET: + case NRF_USBD_COMMON_EVT_RESET: LOG_INF("Reset"); udc_submit_event(udc_nrf_dev, UDC_EVT_RESET, 0); break; - case NRFX_USBD_EVT_SOF: + case NRF_USBD_COMMON_EVT_SOF: udc_submit_event(udc_nrf_dev, UDC_EVT_SOF, 0); udc_sof_check_iso_out(udc_nrf_dev); break; - case NRFX_USBD_EVT_EPTRANSFER: - case NRFX_USBD_EVT_SETUP: { + case NRF_USBD_COMMON_EVT_EPTRANSFER: + case NRF_USBD_COMMON_EVT_SETUP: { struct udc_nrf_evt evt = { .type = UDC_NRF_EVT_HAL, .hal_evt = *hal_evt, @@ -471,7 +472,7 @@ static void udc_nrf_power_handler(nrfx_power_usb_evt_t pwr_evt) case NRFX_POWER_USB_EVT_READY: LOG_INF("POWER event ready"); udc_submit_event(udc_nrf_dev, UDC_EVT_VBUS_READY, 0); - nrfx_usbd_start(true); + nrf_usbd_common_start(true); break; case NRFX_POWER_USB_EVT_REMOVED: LOG_INF("POWER event removed"); @@ -489,7 +490,7 @@ static void udc_nrf_fake_status_in(const struct device *dev) .ep = USB_CONTROL_EP_IN, }; - if (nrfx_usbd_last_setup_dir_get() == USB_CONTROL_EP_OUT) { + if (nrf_usbd_common_last_setup_dir_get() == USB_CONTROL_EP_OUT) { /* Let controller perform status IN stage */ k_msgq_put(&drv_msgq, &evt, K_NO_WAIT); } @@ -519,9 +520,9 @@ static int udc_nrf_ep_enqueue(const struct device *dev, static int udc_nrf_ep_dequeue(const struct device *dev, struct udc_ep_config *cfg) { - bool busy = nrfx_usbd_ep_is_busy(cfg->addr); + bool busy = nrf_usbd_common_ep_is_busy(cfg->addr); - nrfx_usbd_ep_abort(cfg->addr); + nrf_usbd_common_ep_abort(cfg->addr); if (USB_EP_DIR_IS_OUT(cfg->addr) || !busy) { struct net_buf *buf; @@ -550,14 +551,14 @@ static int udc_nrf_ep_enable(const struct device *dev, __ASSERT_NO_MSG(cfg); mps = (cfg->mps == 0) ? cfg->caps.mps : cfg->mps; - nrfx_usbd_ep_max_packet_size_set(cfg->addr, mps); - nrfx_usbd_ep_enable(cfg->addr); + nrf_usbd_common_ep_max_packet_size_set(cfg->addr, mps); + nrf_usbd_common_ep_enable(cfg->addr); if (!NRF_USBD_EPISO_CHECK(cfg->addr)) { /* ISO transactions for full-speed device do not support * toggle sequencing and should only send DATA0 PID. */ - nrfx_usbd_ep_dtoggle_clear(cfg->addr); - nrfx_usbd_ep_stall_clear(cfg->addr); + nrf_usbd_common_ep_dtoggle_clear(cfg->addr); + nrf_usbd_common_ep_stall_clear(cfg->addr); } LOG_DBG("Enable ep 0x%02x", cfg->addr); @@ -569,7 +570,7 @@ static int udc_nrf_ep_disable(const struct device *dev, struct udc_ep_config *cfg) { __ASSERT_NO_MSG(cfg); - nrfx_usbd_ep_disable(cfg->addr); + nrf_usbd_common_ep_disable(cfg->addr); LOG_DBG("Disable ep 0x%02x", cfg->addr); return 0; @@ -582,9 +583,9 @@ static int udc_nrf_ep_set_halt(const struct device *dev, if (cfg->addr == USB_CONTROL_EP_OUT || cfg->addr == USB_CONTROL_EP_IN) { - nrfx_usbd_setup_stall(); + nrf_usbd_common_setup_stall(); } else { - nrfx_usbd_ep_stall(cfg->addr); + nrf_usbd_common_ep_stall(cfg->addr); } return 0; @@ -595,8 +596,8 @@ static int udc_nrf_ep_clear_halt(const struct device *dev, { LOG_DBG("Clear halt ep 0x%02x", cfg->addr); - nrfx_usbd_ep_dtoggle_clear(cfg->addr); - nrfx_usbd_ep_stall_clear(cfg->addr); + nrf_usbd_common_ep_dtoggle_clear(cfg->addr); + nrf_usbd_common_ep_stall_clear(cfg->addr); return 0; } @@ -616,7 +617,7 @@ static int udc_nrf_set_address(const struct device *dev, const uint8_t addr) static int udc_nrf_host_wakeup(const struct device *dev) { - bool res = nrfx_usbd_wakeup_req(); + bool res = nrf_usbd_common_wakeup_req(); LOG_DBG("Host wakeup request"); if (!res) { @@ -630,7 +631,7 @@ static int udc_nrf_enable(const struct device *dev) { int ret; - nrfx_usbd_enable(); + nrf_usbd_common_enable(); sys_notify_init_spinwait(&hfxo_cli.notify); ret = onoff_request(hfxo_mgr, &hfxo_cli); @@ -646,7 +647,7 @@ static int udc_nrf_disable(const struct device *dev) { int ret; - nrfx_usbd_disable(); + nrf_usbd_common_disable(); ret = onoff_cancel_or_release(hfxo_mgr, &hfxo_cli); if (ret < 0) { @@ -675,12 +676,12 @@ static int udc_nrf_init(const struct device *dev) #endif IRQ_CONNECT(DT_INST_IRQN(0), DT_INST_IRQ(0, priority), - nrfx_isr, nrfx_usbd_irq_handler, 0); + nrfx_isr, nrf_usbd_common_irq_handler, 0); (void)nrfx_power_init(&cfg->pwr); nrfx_power_usbevt_init(&cfg->evt); - ret = nrfx_usbd_init(usbd_event_handler); + ret = nrf_usbd_common_init(usbd_event_handler); if (ret != NRFX_SUCCESS) { LOG_ERR("nRF USBD driver initialization failed"); return -EIO; @@ -719,7 +720,7 @@ static int udc_nrf_shutdown(const struct device *dev) } nrfx_power_usbevt_disable(); - nrfx_usbd_uninit(); + nrf_usbd_common_uninit(); nrfx_power_usbevt_uninit(); #ifdef CONFIG_HAS_HW_NRF_USBREG irq_disable(USBREGULATOR_IRQn); @@ -748,14 +749,14 @@ static int udc_nrf_driver_init(const struct device *dev) ep_cfg_out[i].caps.out = 1; if (i == 0) { ep_cfg_out[i].caps.control = 1; - ep_cfg_out[i].caps.mps = NRFX_USBD_EPSIZE; + ep_cfg_out[i].caps.mps = NRF_USBD_COMMON_EPSIZE; } else if (i < (CFG_EPOUT_CNT + 1)) { ep_cfg_out[i].caps.bulk = 1; ep_cfg_out[i].caps.interrupt = 1; - ep_cfg_out[i].caps.mps = NRFX_USBD_EPSIZE; + ep_cfg_out[i].caps.mps = NRF_USBD_COMMON_EPSIZE; } else { ep_cfg_out[i].caps.iso = 1; - ep_cfg_out[i].caps.mps = NRFX_USBD_ISOSIZE / 2; + ep_cfg_out[i].caps.mps = NRF_USBD_COMMON_ISOSIZE / 2; } ep_cfg_out[i].addr = USB_EP_DIR_OUT | i; @@ -770,14 +771,14 @@ static int udc_nrf_driver_init(const struct device *dev) ep_cfg_in[i].caps.in = 1; if (i == 0) { ep_cfg_in[i].caps.control = 1; - ep_cfg_in[i].caps.mps = NRFX_USBD_EPSIZE; + ep_cfg_in[i].caps.mps = NRF_USBD_COMMON_EPSIZE; } else if (i < (CFG_EPIN_CNT + 1)) { ep_cfg_in[i].caps.bulk = 1; ep_cfg_in[i].caps.interrupt = 1; - ep_cfg_in[i].caps.mps = NRFX_USBD_EPSIZE; + ep_cfg_in[i].caps.mps = NRF_USBD_COMMON_EPSIZE; } else { ep_cfg_in[i].caps.iso = 1; - ep_cfg_in[i].caps.mps = NRFX_USBD_ISOSIZE / 2; + ep_cfg_in[i].caps.mps = NRF_USBD_COMMON_ISOSIZE / 2; } ep_cfg_in[i].addr = USB_EP_DIR_IN | i; diff --git a/modules/hal_nordic/nrfx/CMakeLists.txt b/modules/hal_nordic/nrfx/CMakeLists.txt index 4d637ba43f1..69afbcc9c51 100644 --- a/modules/hal_nordic/nrfx/CMakeLists.txt +++ b/modules/hal_nordic/nrfx/CMakeLists.txt @@ -104,7 +104,6 @@ zephyr_library_sources_ifdef(CONFIG_NRFX_TWIM ${SRC_DIR}/nrfx_twim.c) zephyr_library_sources_ifdef(CONFIG_NRFX_TWIS ${SRC_DIR}/nrfx_twis.c) zephyr_library_sources_ifdef(CONFIG_NRFX_UART ${SRC_DIR}/nrfx_uart.c) zephyr_library_sources_ifdef(CONFIG_NRFX_UARTE ${SRC_DIR}/nrfx_uarte.c) -zephyr_library_sources_ifdef(CONFIG_NRFX_USBD ${SRC_DIR}/nrfx_usbd.c) zephyr_library_sources_ifdef(CONFIG_NRFX_USBREG ${SRC_DIR}/nrfx_usbreg.c) zephyr_library_sources_ifdef(CONFIG_NRFX_WDT ${SRC_DIR}/nrfx_wdt.c) diff --git a/modules/hal_nordic/nrfx/Kconfig b/modules/hal_nordic/nrfx/Kconfig index 25ba1194da8..78d9671b3c4 100644 --- a/modules/hal_nordic/nrfx/Kconfig +++ b/modules/hal_nordic/nrfx/Kconfig @@ -519,19 +519,6 @@ config NRFX_UARTE3 depends on $(dt_nodelabel_has_compat,uart3,$(DT_COMPAT_NORDIC_NRF_UARTE)) select NRFX_UARTE -config NRFX_USBD - bool "USBD driver" - depends on $(dt_has_compat,$(DT_COMPAT_NORDIC_NRF_USBD)) - -config NRFX_USBD_ISO_IN_ZLP - bool "Send ZLP on ISO IN when not ready" - depends on NRFX_USBD - default y - help - Controls the response of the ISO IN endpoint to an IN token when no - data is ready to be sent. When enabled, ZLP is sent when no data is - ready. When disabled, no response is sent (bus timeout occurs). - config NRFX_USBREG bool "USBREG driver" depends on $(dt_has_compat,$(DT_COMPAT_NORDIC_NRF_USBREG)) diff --git a/modules/hal_nordic/nrfx/Kconfig.logging b/modules/hal_nordic/nrfx/Kconfig.logging index 41776380cdb..7f7b785e70c 100644 --- a/modules/hal_nordic/nrfx/Kconfig.logging +++ b/modules/hal_nordic/nrfx/Kconfig.logging @@ -132,10 +132,6 @@ config NRFX_UARTE_LOG bool "UARTE driver logging" depends on NRFX_UARTE -config NRFX_USBD_LOG - bool "USBD driver logging" - depends on NRFX_USBD - config NRFX_USBREG_LOG bool "USBREG driver logging" depends on NRFX_USBREG diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index ce4a6214f7d..04be67a7b43 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -546,17 +546,6 @@ #define NRFX_UARTE3_ENABLED 1 #endif -#ifdef CONFIG_NRFX_USBD -#define NRFX_USBD_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_USBD_LOG -#define NRFX_USBD_CONFIG_LOG_ENABLED 1 -#endif - -#ifdef CONFIG_NRFX_USBD_ISO_IN_ZLP -#define NRFX_USBD_CONFIG_ISO_IN_ZLP 1 -#endif - #ifdef CONFIG_NRFX_USBREG #define NRFX_USBREG_ENABLED 1 #endif diff --git a/modules/hal_nordic/nrfx/nrfx_usbd_errata.h b/modules/hal_nordic/nrfx/nrfx_usbd_errata.h deleted file mode 100644 index 7ce8b3955d3..00000000000 --- a/modules/hal_nordic/nrfx/nrfx_usbd_errata.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2016 - 2023, Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef NRFX_USBD_ERRATA_H__ -#define NRFX_USBD_ERRATA_H__ - -#include -#include - -#ifndef NRFX_USBD_ERRATA_ENABLE -/** - * @brief The constant that informs if errata should be enabled at all. - * - * If this constant is set to 0, all the Errata bug fixes will be automatically disabled. - */ -#define NRFX_USBD_ERRATA_ENABLE 1 -#endif - -/* Errata: ISO double buffering not functional. **/ -static inline bool nrfx_usbd_errata_166(void) -{ - return NRFX_USBD_ERRATA_ENABLE && nrf52_errata_166(); -} - -/* Errata: USBD might not reach its active state. **/ -static inline bool nrfx_usbd_errata_171(void) -{ - return NRFX_USBD_ERRATA_ENABLE && nrf52_errata_171(); -} - -/* Errata: USB cannot be enabled. **/ -static inline bool nrfx_usbd_errata_187(void) -{ - return NRFX_USBD_ERRATA_ENABLE && nrf52_errata_187(); -} - -/* Errata: USBD cannot receive tasks during DMA. **/ -static inline bool nrfx_usbd_errata_199(void) -{ - return NRFX_USBD_ERRATA_ENABLE && nrf52_errata_199(); -} - -/* Errata: Device remains in SUSPEND too long. */ -static inline bool nrfx_usbd_errata_211(void) -{ - return NRFX_USBD_ERRATA_ENABLE && nrf52_errata_211(); -} - -/* Errata: Unexpected behavior after reset. **/ -static inline bool nrfx_usbd_errata_223(void) -{ - return NRFX_USBD_ERRATA_ENABLE && nrf52_errata_223(); -} - -#endif /* NRFX_USBD_ERRATA_H__ */ diff --git a/subsys/usb/device/Kconfig b/subsys/usb/device/Kconfig index 8907d952d87..1f0a008058e 100644 --- a/subsys/usb/device/Kconfig +++ b/subsys/usb/device/Kconfig @@ -97,7 +97,7 @@ config USB_NUMOF_EP_WRITE_RETRIES config USB_DEVICE_SOF bool "Start of Frame processing in events" - default y if (USB_DEVICE_AUDIO && NRFX_USBD) + default y if (USB_DEVICE_AUDIO && NRF_USBD_COMMON) config USB_DEVICE_BOS bool "USB Binary Device Object Store (BOS)"