diff --git a/integration/nrfx/legacy/nrf_drv_comp.h b/integration/nrfx/legacy/nrf_drv_comp.h deleted file mode 100644 index e03661f..0000000 --- a/integration/nrfx/legacy/nrf_drv_comp.h +++ /dev/null @@ -1,137 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_DRV_COMP_H__ -#define NRF_DRV_COMP_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_drv_comp COMP driver - legacy layer - * @{ - * @ingroup nrf_comp - * - * @brief @tagAPI52 Layer providing compatibility with the former API. - */ - -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_comp_config_t nrf_drv_comp_config_t; - -/** @brief Macro for forwarding the new implementation. */ -#define VOLTAGE_THRESHOLD_TO_INT NRFX_VOLTAGE_THRESHOLD_TO_INT -/** @brief Macro for forwarding the new implementation. */ -#define COMP_CONFIG_TH NRFX_COMP_CONFIG_TH -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_COMP_DEFAULT_CONFIG NRFX_COMP_DEFAULT_CONFIG - -/** @brief Macro for forwarding the new implementation. */ -#define comp_events_handler_t nrfx_comp_event_handler_t -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_COMP_SHORT_STOP_AFTER_CROSS_EVT NRFX_COMP_SHORT_STOP_AFTER_CROSS_EVT -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_COMP_SHORT_STOP_AFTER_UP_EVT NRFX_COMP_SHORT_STOP_AFTER_UP_EVT -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_COMP_SHORT_STOP_AFTER_DOWN_EVT NRFX_COMP_SHORT_STOP_AFTER_DOWN_EVT -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_comp_short_mask_t nrfx_comp_short_mask_t -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_COMP_EVT_EN_CROSS_MASK NRFX_COMP_EVT_EN_CROSS_MASK -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_COMP_EVT_EN_UP_MASK NRFX_COMP_EVT_EN_UP_MASK -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_COMP_EVT_EN_DOWN_MASK NRFX_COMP_EVT_EN_DOWN_MASK -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_COMP_EVT_EN_READY_MASK NRFX_COMP_EVT_EN_READY_MASK -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_comp_evt_en_mask_t nrfx_comp_evt_en_mask_t - -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_comp_uninit nrfx_comp_uninit -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_comp_pin_select nrfx_comp_pin_select -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_comp_start nrfx_comp_start -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_comp_stop nrfx_comp_stop -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_comp_sample nrfx_comp_sample - -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_comp_task_address_get nrfx_comp_task_address_get -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_comp_event_address_get nrfx_comp_event_address_get - -/** - * @brief Function for initializing the COMP driver. - * - * This function initializes the COMP driver, but does not enable the peripheral or any interrupts. - * To start the driver, call the function @ref nrf_drv_comp_start() after initialization. - * - * If no configuration structure is provided, the driver is initialized with the default settings. - * - * @param[in] p_config Pointer to the structure with initial configuration. - * @param[in] event_handler Handler function. - * - * @retval NRF_ERROR_INVALID_PARAM If the configuration is invalid. - * @retval NRF_ERROR_INVALID_STATE If the driver has already been initialized. - * @retval NRF_ERROR_BUSY If the LPCOMP driver is initialized. - */ -__STATIC_INLINE ret_code_t nrf_drv_comp_init(nrf_drv_comp_config_t const * p_config, - comp_events_handler_t event_handler) -{ - if (p_config == NULL) - { - static nrfx_comp_config_t const default_config = NRFX_COMP_DEFAULT_CONFIG(NRF_COMP_INPUT_0); - p_config = &default_config; - } - return nrfx_comp_init(p_config, event_handler); -} - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif // NRF_DRV_COMP_H__ diff --git a/integration/nrfx/legacy/nrf_drv_i2s.h b/integration/nrfx/legacy/nrf_drv_i2s.h deleted file mode 100644 index 5abe4c7..0000000 --- a/integration/nrfx/legacy/nrf_drv_i2s.h +++ /dev/null @@ -1,112 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_DRV_I2S_H__ -#define NRF_DRV_I2S_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_drv_i2s I2S driver - legacy layer - * @{ - * @ingroup nrf_i2s - * - * @brief @tagAPI52 Layer providing compatibility with the former API. - */ - -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_i2s_config_t nrf_drv_i2s_config_t; -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_i2s_buffers_t nrf_drv_i2s_buffers_t; - -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_I2S_PIN_NOT_USED NRFX_I2S_PIN_NOT_USED -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_I2S_FLAG_SYNCHRONIZED_MODE NRFX_I2S_FLAG_SYNCHRONIZED_MODE -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_I2S_DEFAULT_CONFIG NRFX_I2S_DEFAULT_CONFIG -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_I2S_STATUS_NEXT_BUFFERS_NEEDED NRFX_I2S_STATUS_NEXT_BUFFERS_NEEDED -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_i2s_data_handler_t nrfx_i2s_data_handler_t - -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_i2s_uninit nrfx_i2s_uninit -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_i2s_start nrfx_i2s_start -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_i2s_next_buffers_set nrfx_i2s_next_buffers_set -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_i2s_stop nrfx_i2s_stop - -/** - * @brief Function for initializing the I2S driver. - * - * @param[in] p_config Pointer to the structure with initial configuration. - * If NULL, the default configuration is used. - * @param[in] handler Data handler provided by the user. Must not be NULL. - * - * @retval NRF_SUCCESS If initialization was successful. - * @retval NRF_ERROR_INVALID_STATE If the driver was already initialized. - * @retval NRF_ERROR_INVALID_PARAM If the requested combination of configuration - * options is not allowed by the I2S peripheral. - */ -__STATIC_INLINE ret_code_t nrf_drv_i2s_init(nrf_drv_i2s_config_t const * p_config, - nrf_drv_i2s_data_handler_t handler) -{ - if (p_config == NULL) - { - static nrfx_i2s_config_t const default_config = NRFX_I2S_DEFAULT_CONFIG; - p_config = &default_config; - } - return nrfx_i2s_init(p_config, handler); -} - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif // NRF_DRV_I2S_H__ diff --git a/integration/nrfx/legacy/nrf_drv_lpcomp.h b/integration/nrfx/legacy/nrf_drv_lpcomp.h deleted file mode 100644 index ed84684..0000000 --- a/integration/nrfx/legacy/nrf_drv_lpcomp.h +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Copyright (c) 2014 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_DRV_LPCOMP_H__ -#define NRF_DRV_LPCOMP_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_drv_lpcomp LPCOMP driver - legacy layer - * @{ - * @ingroup nrf_lpcomp - * - * @brief Layer providing compatibility with the former API. - */ - -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_lpcomp_config_t nrf_drv_lpcomp_config_t; - -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_LPCOMP_DEFAULT_CONFIG NRFX_LPCOMP_DEFAULT_CONFIG - -/** @brief Macro for forwarding the new implementation. */ -#define lpcomp_events_handler_t nrfx_lpcomp_event_handler_t - -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_lpcomp_init nrfx_lpcomp_init -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_lpcomp_uninit nrfx_lpcomp_uninit -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_lpcomp_enable nrfx_lpcomp_enable -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_lpcomp_disable nrfx_lpcomp_disable - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif // NRF_DRV_LPCOMP_H__ diff --git a/integration/nrfx/legacy/nrf_drv_pdm.h b/integration/nrfx/legacy/nrf_drv_pdm.h deleted file mode 100644 index a937500..0000000 --- a/integration/nrfx/legacy/nrf_drv_pdm.h +++ /dev/null @@ -1,116 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_DRV_PDM_H__ -#define NRF_DRV_PDM_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_drv_pdm PDM driver - legacy layer - * @{ - * @ingroup nrf_pdm - * - * @brief @tagAPI52 Layer providing compatibility with the former API. - */ - -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_pdm_config_t nrf_drv_pdm_config_t; -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_pdm_evt_t nrf_drv_pdm_evt_t; - -/** @brief Macro for forwarding the new implementation. */ -#define NRF_PDM_MAX_BUFFER_SIZE NRFX_PDM_MAX_BUFFER_SIZE -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_PDM_DEFAULT_CONFIG NRFX_PDM_DEFAULT_CONFIG - -/** @brief Macro for forwarding the new implementation. */ -#define PDM_NO_ERROR NRFX_PDM_NO_ERROR -/** @brief Macro for forwarding the new implementation. */ -#define PDM_ERROR_OVERFLOW NRFX_PDM_ERROR_OVERFLOW -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_pdm_error_t nrfx_pdm_error_t -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_pdm_event_handler_t nrfx_pdm_event_handler_t - -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_pdm_uninit nrfx_pdm_uninit -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_pdm_task_address_get nrfx_pdm_task_address_get -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_pdm_enable_check nrfx_pdm_enable_check -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_pdm_start nrfx_pdm_start -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_pdm_stop nrfx_pdm_stop -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_pdm_buffer_set nrfx_pdm_buffer_set - -/** - * @brief Function for initializing the PDM interface. - * - * @param[in] p_config Pointer to the structure with initial configuration. Cannot be NULL. - * @param[in] event_handler Event handler provided by the user. Cannot be NULL. - * - * @retval NRF_SUCCESS If initialization was successful. - * @retval NRF_ERROR_INVALID_STATE If the driver is already initialized. - * @retval NRF_ERROR_INVALID_PARAM If invalid parameters were specified. - */ -__STATIC_INLINE ret_code_t nrf_drv_pdm_init(nrf_drv_pdm_config_t const * p_config, - nrf_drv_pdm_event_handler_t event_handler) -{ - if (p_config == NULL) - { - return NRFX_ERROR_INVALID_PARAM; - } - return nrfx_pdm_init(p_config, event_handler); -} - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif // NRF_DRV_PDM_H__ diff --git a/integration/nrfx/legacy/nrf_drv_qdec.h b/integration/nrfx/legacy/nrf_drv_qdec.h deleted file mode 100644 index d0d7c2b..0000000 --- a/integration/nrfx/legacy/nrf_drv_qdec.h +++ /dev/null @@ -1,130 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_DRV_QDEC_H__ -#define NRF_DRV_QDEC_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_drv_qdec QDEC driver - legacy layer - * @{ - * @ingroup nrf_qdec - * - * @brief Layer providing compatibility with the former API. - */ - -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_qdec_config_t nrf_drv_qdec_config_t; -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_qdec_sample_data_evt_t nrf_drv_qdec_sample_data_evt_t; -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_qdec_report_data_evt_t nrf_drv_qdec_report_data_evt_t; -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_qdec_event_t nrf_drv_qdec_event_t; - -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_QDEC_DEFAULT_CONFIG NRFX_QDEC_DEFAULT_CONFIG - -/** @brief Macro for forwarding the new implementation. */ -#define qdec_event_handler_t nrfx_qdec_event_handler_t -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_qdec_uninit nrfx_qdec_uninit -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_qdec_enable nrfx_qdec_enable -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_qdec_disable nrfx_qdec_disable -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_qdec_accumulators_read nrfx_qdec_accumulators_read - -/** - * @brief Function for initializing QDEC. - * - * @param[in] p_config Pointer to the structure with initial configuration. - * @param[in] event_handler Event handler function. - * - * @retval NRF_SUCCESS If initialization was successful. - * @retval NRF_ERROR_INVALID_PARAM If invalid parameters were supplied. - * @retval NRF_ERROR_INVALID_STATE If QDEC was already initialized. - */ -__STATIC_INLINE ret_code_t nrf_drv_qdec_init(nrf_drv_qdec_config_t const * p_config, - qdec_event_handler_t event_handler) -{ - if (p_config == NULL) - { - static nrf_drv_qdec_config_t const default_config = NRFX_QDEC_DEFAULT_CONFIG; - p_config = &default_config; - } - return nrfx_qdec_init(p_config, event_handler); -} - -/** - * @brief Function for returning the address of a specific timer task. - * - * @param[in] task QDEC task. - * @param[out] p_task Task address. - */ -void nrf_drv_qdec_task_address_get(nrf_qdec_task_t task, uint32_t * p_task) -{ - *p_task = nrfx_qdec_task_address_get(task); -} - -/** - * @brief Function for returning the address of a specific timer event. - * - * @param[in] event QDEC event. - * @param[out] p_event Event address. - */ -void nrf_drv_qdec_event_address_get(nrf_qdec_event_t event, uint32_t * p_event) -{ - *p_event = nrfx_qdec_event_address_get(event); -} - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif // NRF_DRV_QDEC_H__ diff --git a/integration/nrfx/legacy/nrf_drv_qspi.h b/integration/nrfx/legacy/nrf_drv_qspi.h deleted file mode 100644 index 9490ab2..0000000 --- a/integration/nrfx/legacy/nrf_drv_qspi.h +++ /dev/null @@ -1,122 +0,0 @@ -/** - * Copyright (c) 2016 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_DRV_QSPI_H__ -#define NRF_DRV_QSPI_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_drv_qspi QSPI driver - legacy layer - * @{ - * @ingroup nrf_qspi - * - * @brief @tagAPI52840 Layer providing compatibility with the former API. - */ - -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_qspi_config_t nrf_drv_qspi_config_t; - -#if QSPI_PIN_SCK == NRF_QSPI_PIN_NOT_CONNECTED - #undef QSPI_PIN_SCK - #define QSPI_PIN_SCK BSP_QSPI_SCK_PIN -#endif -#if QSPI_PIN_CSN == NRF_QSPI_PIN_NOT_CONNECTED - #undef QSPI_PIN_CSN - #define QSPI_PIN_CSN BSP_QSPI_CSN_PIN -#endif -#if QSPI_PIN_IO0 == NRF_QSPI_PIN_NOT_CONNECTED - #undef QSPI_PIN_IO0 - #define QSPI_PIN_IO0 BSP_QSPI_IO0_PIN -#endif -#if QSPI_PIN_IO1 == NRF_QSPI_PIN_NOT_CONNECTED - #undef QSPI_PIN_IO1 - #define QSPI_PIN_IO1 BSP_QSPI_IO1_PIN -#endif -#if QSPI_PIN_IO2 == NRF_QSPI_PIN_NOT_CONNECTED - #undef QSPI_PIN_IO2 - #define QSPI_PIN_IO2 BSP_QSPI_IO2_PIN -#endif -#if QSPI_PIN_IO3 == NRF_QSPI_PIN_NOT_CONNECTED - #undef QSPI_PIN_IO3 - #define QSPI_PIN_IO3 BSP_QSPI_IO3_PIN -#endif - -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_QSPI_DEFAULT_CONFIG NRFX_QSPI_DEFAULT_CONFIG -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_QSPI_DEFAULT_CINSTR NRFX_QSPI_DEFAULT_CINSTR -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_QSPI_EVENT_DONE NRFX_QSPI_EVENT_DONE -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_qspi_evt_t nrfx_qspi_evt_t -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_qspi_handler_t nrfx_qspi_handler_t - -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_qspi_init nrfx_qspi_init -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_qspi_uninit nrfx_qspi_uninit -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_qspi_read nrfx_qspi_read -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_qspi_write nrfx_qspi_write -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_qspi_erase nrfx_qspi_erase -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_qspi_chip_erase nrfx_qspi_chip_erase -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_qspi_mem_busy_check nrfx_qspi_mem_busy_check -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_qspi_cinstr_xfer nrfx_qspi_cinstr_xfer -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_qspi_cinstr_quick_send nrfx_qspi_cinstr_quick_send - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif // NRF_DRV_QSPI_H__ diff --git a/integration/nrfx/legacy/nrf_drv_spis.c b/integration/nrfx/legacy/nrf_drv_spis.c deleted file mode 100644 index 6772d70..0000000 --- a/integration/nrfx/legacy/nrf_drv_spis.c +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright (c) 2018 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "nrf_drv_spis.h" - -static nrf_drv_spis_event_handler_t m_handlers[SPIS_COUNT]; - -static void spis_event_handler(nrfx_spis_evt_t const * p_event, - void * p_context) -{ - uint32_t inst_idx = (uint32_t)p_context; - m_handlers[inst_idx](*p_event); -} - -ret_code_t nrf_drv_spis_init(nrf_drv_spis_t const * const p_instance, - nrf_drv_spis_config_t const * p_config, - nrf_drv_spis_event_handler_t event_handler) -{ - uint32_t inst_idx = p_instance->drv_inst_idx; - m_handlers[inst_idx] = event_handler; - - return nrfx_spis_init(p_instance, - p_config, - spis_event_handler, - (void *)inst_idx); -} diff --git a/integration/nrfx/legacy/nrf_drv_spis.h b/integration/nrfx/legacy/nrf_drv_spis.h deleted file mode 100644 index 1c3fbee..0000000 --- a/integration/nrfx/legacy/nrf_drv_spis.h +++ /dev/null @@ -1,144 +0,0 @@ -/** - * Copyright (c) 2014 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_DRV_SPIS_H__ -#define NRF_DRV_SPIS_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_drv_spis SPIS driver - legacy layer - * @{ - * @ingroup nrf_spis - * - * @brief Layer providing compatibility with the former API. - */ - -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_spis_t nrf_drv_spis_t; -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_spis_config_t nrf_drv_spis_config_t; -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_spis_evt_t nrf_drv_spis_event_t; - -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_SPIS_INSTANCE NRFX_SPIS_INSTANCE -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_SPIS_DEFAULT_CONFIG NRFX_SPIS_DEFAULT_CONFIG -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_SPIS_DEFAULT_CSN_PULLUP NRFX_SPIS_DEFAULT_CSN_PULLUP -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_SPIS_DEFAULT_MISO_DRIVE NRFX_SPIS_DEFAULT_MISO_DRIVE -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_SPIS_PIN_NOT_USED NRFX_SPIS_PIN_NOT_USED - -/** @brief Macro for providing API backward compatibility. */ -#define NRF_DRV_SPIS_BIT_ORDER_LSB_FIRST NRF_SPIS_BIT_ORDER_LSB_FIRST -/** @brief Macro for providing API backward compatibility. */ -#define NRF_DRV_SPIS_BIT_ORDER_MSB_FIRST NRF_SPIS_BIT_ORDER_MSB_FIRST -/** @brief Macro for providing API backward compatibility. */ -#define nrf_drv_spis_endian_t nrf_spis_bit_order_t -/** @brief Macro for providing API backward compatibility. */ -#define NRF_DRV_SPIS_MODE_0 NRF_SPIS_MODE_0 -/** @brief Macro for providing API backward compatibility. */ -#define NRF_DRV_SPIS_MODE_1 NRF_SPIS_MODE_1 -/** @brief Macro for providing API backward compatibility. */ -#define NRF_DRV_SPIS_MODE_2 NRF_SPIS_MODE_2 -/** @brief Macro for providing API backward compatibility. */ -#define NRF_DRV_SPIS_MODE_3 NRF_SPIS_MODE_3 -/** @brief Macro for providing API backward compatibility. */ -#define nrf_drv_spis_mode_t nrf_spis_mode_t -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_SPIS_BUFFERS_SET_DONE NRFX_SPIS_BUFFERS_SET_DONE -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_SPIS_XFER_DONE NRFX_SPIS_XFER_DONE -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_SPIS_EVT_TYPE_MAX NRFX_SPIS_EVT_TYPE_MAX -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_spis_event_type_t nrfx_spis_evt_type_t - -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_spis_uninit nrfx_spis_uninit -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_spis_buffers_set nrfx_spis_buffers_set - -/** @brief SPI slave event callback function type. - * - * @param[in] event SPI slave driver event. - */ -typedef void (*nrf_drv_spis_event_handler_t)(nrf_drv_spis_event_t event); - -/** @brief Function for initializing the SPI slave driver instance. - * - * @note When the nRF52 Anomaly 109 workaround for SPIS is enabled, this function - * initializes the GPIOTE driver as well, and uses one of GPIOTE channels - * to detect falling edges on CSN pin. - * - * @param[in] p_instance Pointer to the driver instance structure. - * @param[in] p_config Pointer to the structure with the initial configuration. - * If NULL, the default configuration will be used. - * @param[in] event_handler Function to be called by the SPI slave driver upon event. - * - * @retval NRF_SUCCESS If the initialization was successful. - * @retval NRF_ERROR_INVALID_PARAM If an invalid parameter is supplied. - * @retval NRFX_ERROR_INVALID_STATE If the instance is already initialized. - * @retval NRF_ERROR_BUSY If some other peripheral with the same - * instance ID is already in use. This is - * possible only if PERIPHERAL_RESOURCE_SHARING_ENABLED - * is set to a value other than zero. - * @retval NRF_ERROR_INTERNAL GPIOTE channel for detecting falling edges - * on CSN pin cannot be initialized. Possible - * only when using nRF52 Anomaly 109 workaround. - */ -ret_code_t nrf_drv_spis_init(nrf_drv_spis_t const * const p_instance, - nrf_drv_spis_config_t const * p_config, - nrf_drv_spis_event_handler_t event_handler); - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif // NRF_DRV_SPIS_H__ diff --git a/integration/nrfx/legacy/nrf_drv_swi.c b/integration/nrfx/legacy/nrf_drv_swi.c deleted file mode 100644 index bc66f99..0000000 --- a/integration/nrfx/legacy/nrf_drv_swi.c +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "nrf_drv_swi.h" - -static nrfx_drv_state_t m_drv_state = NRFX_DRV_STATE_UNINITIALIZED; - -ret_code_t nrf_drv_swi_init(void) -{ - if (m_drv_state == NRFX_DRV_STATE_INITIALIZED) - { - return NRF_ERROR_MODULE_ALREADY_INITIALIZED; - } - - m_drv_state = NRFX_DRV_STATE_INITIALIZED; - return NRF_SUCCESS; -} - -ret_code_t nrf_drv_swi_uninit(void) -{ - if (m_drv_state == NRFX_DRV_STATE_UNINITIALIZED) - { - return NRF_ERROR_INVALID_STATE; - } - - nrfx_swi_all_free(); - m_drv_state = NRFX_DRV_STATE_UNINITIALIZED; - return NRF_SUCCESS; -} diff --git a/integration/nrfx/legacy/nrf_drv_swi.h b/integration/nrfx/legacy/nrf_drv_swi.h deleted file mode 100644 index ac74a06..0000000 --- a/integration/nrfx/legacy/nrf_drv_swi.h +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_DRV_SWI_H__ -#define NRF_DRV_SWI_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_drv_swi SWI driver - legacy layer - * @{ - * @ingroup nrf_swi_egu - * - * @brief Layer providing compatibility with the former API. - */ - -/** @brief Macro for forwarding the new implementation. */ -#define NRF_SWI_UNALLOCATED NRFX_SWI_UNALLOCATED -/** @brief Macro for forwarding the new implementation. */ -#define SWI_DEFAULT_PRIORITY NRFX_SWI_DEFAULT_PRIORITY - -/** @brief Macro for forwarding the new implementation. */ -#define nrf_swi_t nrfx_swi_t -/** @brief Macro for forwarding the new implementation. */ -#define nrf_swi_flags_t nrfx_swi_flags_t -/** @brief Macro for forwarding the new implementation. */ -#define nrf_swi_handler_t nrfx_swi_handler_t - -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_swi_alloc nrfx_swi_alloc -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_swi_free nrfx_swi_free -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_swi_trigger nrfx_swi_trigger - -#if NRF_MODULE_ENABLED(EGU) || defined(__SDK_DOXYGEN__) -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_swi_task_trigger_address_get nrfx_swi_task_trigger_address_get -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_swi_event_triggered_address_get nrfx_swi_event_triggered_address_get -#endif // NRF_MODULE_ENABLED(EGU) || defined(__SDK_DOXYGEN__) - -/** - * @brief Function for initializing the SWI module. - * - * @retval NRF_SUCCESS If the module was successfully initialized. - * @retval NRF_ERROR_MODULE_ALREADY_INITIALIZED If the module has already been initialized. - */ -ret_code_t nrf_drv_swi_init(void); - -/** - * @brief Function for uninitializing the SWI module. - * - * This function also frees all SWIs. - * - * @retval NRF_SUCCESS If the module was successfully uninitialized. - * @retval NRF_ERROR_INVALID_STATE If the module has not been initialized yet. - */ -ret_code_t nrf_drv_swi_uninit(void); - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif // NRF_DRV_SWI_H__ diff --git a/integration/nrfx/legacy/nrf_drv_systick.h b/integration/nrfx/legacy/nrf_drv_systick.h deleted file mode 100644 index f6b53a8..0000000 --- a/integration/nrfx/legacy/nrf_drv_systick.h +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Copyright (c) 2016 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_DRV_SYSTICK_H__ -#define NRF_DRV_SYSTICK_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_drv_systick ARM(R) SysTick driver - legacy layer - * @{ - * @ingroup nrf_systick - * - * @brief Layer providing compatibility with the former API. - */ - -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_systick_state_t nrf_drv_systick_state_t; - -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_systick_init nrfx_systick_init -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_systick_get nrfx_systick_get -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_systick_test nrfx_systick_test -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_systick_delay_ticks nrfx_systick_delay_ticks -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_systick_delay_us nrfx_systick_delay_us -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_systick_delay_ms nrfx_systick_delay_ms - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif // NRF_DRV_SYSTICK_H__ diff --git a/integration/nrfx/legacy/nrf_drv_twis.h b/integration/nrfx/legacy/nrf_drv_twis.h deleted file mode 100644 index 09cac36..0000000 --- a/integration/nrfx/legacy/nrf_drv_twis.h +++ /dev/null @@ -1,134 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_DRV_TWIS_H__ -#define NRF_DRV_TWIS_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_drv_twis TWIS driver - legacy layer - * @{ - * @ingroup nrf_twis - * - * @brief Layer providing compatibility with the former API. - */ - -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_twis_t nrf_drv_twis_t; -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_twis_config_t nrf_drv_twis_config_t; -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_twis_evt_t nrf_drv_twis_evt_t; - -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_TWIS_INSTANCE NRFX_TWIS_INSTANCE -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_TWIS_DEFAULT_CONFIG NRFX_TWIS_DEFAULT_CONFIG - -/** @brief Macro for forwarding the new implementation. */ -#define TWIS_EVT_READ_REQ NRFX_TWIS_EVT_READ_REQ -/** @brief Macro for forwarding the new implementation. */ -#define TWIS_EVT_READ_DONE NRFX_TWIS_EVT_READ_DONE -/** @brief Macro for forwarding the new implementation. */ -#define TWIS_EVT_READ_ERROR NRFX_TWIS_EVT_READ_ERROR -/** @brief Macro for forwarding the new implementation. */ -#define TWIS_EVT_WRITE_REQ NRFX_TWIS_EVT_WRITE_REQ -/** @brief Macro for forwarding the new implementation. */ -#define TWIS_EVT_WRITE_DONE NRFX_TWIS_EVT_WRITE_DONE -/** @brief Macro for forwarding the new implementation. */ -#define TWIS_EVT_WRITE_ERROR NRFX_TWIS_EVT_WRITE_ERROR -/** @brief Macro for forwarding the new implementation. */ -#define TWIS_EVT_GENERAL_ERROR NRFX_TWIS_EVT_GENERAL_ERROR -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_twis_evt_type_t nrfx_twis_evt_type_t -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_TWIS_ERROR_OVERFLOW NRFX_TWIS_ERROR_OVERFLOW -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_TWIS_ERROR_DATA_NACK NRFX_TWIS_ERROR_DATA_NACK -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_TWIS_ERROR_OVERREAD NRFX_TWIS_ERROR_OVERREAD -/** @brief Macro for forwarding the new implementation. */ -#define NRF_DRV_TWIS_ERROR_UNEXPECTED_EVENT NRFX_TWIS_ERROR_UNEXPECTED_EVENT -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_twis_error_t nrfx_twis_error_t -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_twis_event_handler_t nrfx_twis_event_handler_t - -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_twis_init nrfx_twis_init -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_twis_uninit nrfx_twis_uninit -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_twis_enable nrfx_twis_enable -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_twis_disable nrfx_twis_disable -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_twis_error_get_and_clear nrfx_twis_error_get_and_clear -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_twis_tx_prepare nrfx_twis_tx_prepare -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_twis_tx_amount nrfx_twis_tx_amount -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_twis_rx_prepare nrfx_twis_rx_prepare -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_twis_rx_amount nrfx_twis_rx_amount -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_twis_is_busy nrfx_twis_is_busy -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_twis_is_waiting_tx_buff nrfx_twis_is_waiting_tx_buff -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_twis_is_waiting_rx_buff nrfx_twis_is_waiting_rx_buff -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_twis_is_pending_tx nrfx_twis_is_pending_tx -/** @brief Macro for forwarding the new implementation. */ -#define nrf_drv_twis_is_pending_rx nrfx_twis_is_pending_rx - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif // NRF_DRV_TWIS_H__ diff --git a/integration/nrfx/legacy/nrf_drv_usbd.h b/integration/nrfx/legacy/nrf_drv_usbd.h deleted file mode 100644 index 7f8c49f..0000000 --- a/integration/nrfx/legacy/nrf_drv_usbd.h +++ /dev/null @@ -1,272 +0,0 @@ -/** - * Copyright (c) 2016 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_DRV_USBD_H__ -#define NRF_DRV_USBD_H__ - -#include "nrfx.h" -#include "nrfx_usbd.h" -#include "nrf_drv_usbd_errata.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_drv_usbd USBD driver - legacy layer - * @{ - * @ingroup nrf_usbd - * - * @brief @tagAPI52 Layer providing compatibility with the former API. - */ - -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_DMASCHEDULER_PRIORITIZED NRFX_USBD_DMASCHEDULER_PRIORITIZED -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_DMASCHEDULER_ROUNDROBIN NRFX_USBD_DMASCHEDULER_ROUNDROBIN -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EPSIZE NRFX_USBD_EPSIZE -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_ISOSIZE NRFX_USBD_ISOSIZE -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_FEEDER_BUFFER_SIZE NRFX_USBD_EPSIZE -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EPIN NRFX_USBD_EPIN -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EPOUT NRFX_USBD_EPOUT - -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_usbd_ep_t nrf_drv_usbd_ep_t; -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EPOUT0 NRFX_USBD_EPOUT0 -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EPOUT1 NRFX_USBD_EPOUT1 -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EPOUT2 NRFX_USBD_EPOUT2 -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EPOUT3 NRFX_USBD_EPOUT3 -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EPOUT4 NRFX_USBD_EPOUT4 -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EPOUT5 NRFX_USBD_EPOUT5 -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EPOUT6 NRFX_USBD_EPOUT6 -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EPOUT7 NRFX_USBD_EPOUT7 -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EPOUT8 NRFX_USBD_EPOUT8 -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EPIN0 NRFX_USBD_EPIN0 -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EPIN1 NRFX_USBD_EPIN1 -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EPIN2 NRFX_USBD_EPIN2 -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EPIN3 NRFX_USBD_EPIN3 -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EPIN4 NRFX_USBD_EPIN4 -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EPIN5 NRFX_USBD_EPIN5 -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EPIN6 NRFX_USBD_EPIN6 -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EPIN7 NRFX_USBD_EPIN7 -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EPIN8 NRFX_USBD_EPIN8 - -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_usbd_event_type_t nrf_drv_usbd_event_type_t; -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EVT_SOF NRFX_USBD_EVT_SOF -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EVT_RESET NRFX_USBD_EVT_RESET -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EVT_SUSPEND NRFX_USBD_EVT_SUSPEND -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EVT_RESUME NRFX_USBD_EVT_RESUME -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EVT_WUREQ NRFX_USBD_EVT_WUREQ -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EVT_SETUP NRFX_USBD_EVT_SETUP -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EVT_EPTRANSFER NRFX_USBD_EVT_EPTRANSFER -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_EVT_CNT NRFX_USBD_EVT_CNT - -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_USBD_EP_OK NRFX_USBD_EP_OK -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_USBD_EP_WAITING NRFX_USBD_EP_WAITING -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_USBD_EP_OVERLOAD NRFX_USBD_EP_OVERLOAD -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_USBD_EP_ABORTED NRFX_USBD_EP_ABORTED - -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_usbd_ep_status_t nrf_drv_usbd_ep_status_t; -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_usbd_evt_t nrf_drv_usbd_evt_t; -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_usbd_event_handler_t nrf_drv_usbd_event_handler_t; -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_usbd_data_ptr_t nrf_drv_usbd_data_ptr_t; -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_usbd_ep_transfer_t nrf_drv_usbd_ep_transfer_t; -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_usbd_transfer_flags_t nrf_drv_usbd_transfer_flags_t; -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_TRANSFER_ZLP_FLAG NRFX_USBD_TRANSFER_ZLP_FLAG - -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_usbd_transfer_t nrf_drv_usbd_transfer_t; - -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_TRANSFER_IN_FLAGS(name, tx_buff, tx_size, tx_flags) \ - NRFX_USBD_TRANSFER_IN(name, tx_buff, tx_size, tx_flags) -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_TRANSFER_IN(name, tx_buff, tx_size) \ - NRFX_USBD_TRANSFER_IN(name, tx_buff, tx_size, 0) -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_TRANSFER_IN_ZLP(name, tx_buff, tx_size) \ - NRFX_USBD_TRANSFER_IN(name, tx_buff, tx_size, NRFX_USBD_TRANSFER_ZLP_FLAG) -/** @brief Type definition for forwarding the new implementation. */ -#define NRF_DRV_USBD_TRANSFER_OUT NRFX_USBD_TRANSFER_OUT - -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_usbd_feeder_t nrf_drv_usbd_feeder_t; -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_usbd_consumer_t nrf_drv_usbd_consumer_t; -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_usbd_handler_t nrf_drv_usbd_handler_t; -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_usbd_handler_desc_t nrf_drv_usbd_handler_desc_t; -/** @brief Type definition for forwarding the new implementation. */ -typedef nrfx_usbd_setup_t nrf_drv_usbd_setup_t; - -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_init nrfx_usbd_init -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_enable nrfx_usbd_enable -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_disable nrfx_usbd_disable -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_start nrfx_usbd_start -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_stop nrfx_usbd_stop -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_is_initialized nrfx_usbd_is_initialized -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_is_enabled nrfx_usbd_is_enabled -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_is_started nrfx_usbd_is_started -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_suspend nrfx_usbd_suspend -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_wakeup_req nrfx_usbd_wakeup_req -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_suspend_check nrfx_usbd_suspend_check -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_suspend_irq_config nrfx_usbd_suspend_irq_config -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_active_irq_config nrfx_usbd_active_irq_config -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_force_bus_wakeup nrfx_usbd_force_bus_wakeup -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_bus_suspend_check nrfx_usbd_bus_suspend_check -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_ep_max_packet_size_set nrfx_usbd_ep_max_packet_size_set -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_ep_max_packet_size_get nrfx_usbd_ep_max_packet_size_get -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_ep_enable_check nrfx_usbd_ep_enable_check -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_ep_enable nrfx_usbd_ep_enable -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_ep_disable nrfx_usbd_ep_disable -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_ep_default_config nrfx_usbd_ep_default_config -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_ep_transfer nrfx_usbd_ep_transfer -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_ep_handled_transfer nrfx_usbd_ep_handled_transfer -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_feeder_buffer_get nrfx_usbd_feeder_buffer_get -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_ep_status_get nrfx_usbd_ep_status_get -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_epout_size_get nrfx_usbd_epout_size_get -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_ep_is_busy nrfx_usbd_ep_is_busy -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_ep_stall nrfx_usbd_ep_stall -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_ep_stall_clear nrfx_usbd_ep_stall_clear -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_ep_stall_check nrfx_usbd_ep_stall_check -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_ep_dtoggle_clear nrfx_usbd_ep_dtoggle_clear -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_setup_get nrfx_usbd_setup_get -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_setup_data_clear nrfx_usbd_setup_data_clear -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_setup_clear nrfx_usbd_setup_clear -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_setup_stall nrfx_usbd_setup_stall -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_ep_abort nrfx_usbd_ep_abort -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_last_setup_dir_get nrfx_usbd_last_setup_dir_get -/** @brief Type definition for forwarding the new implementation. */ -#define nrf_drv_usbd_transfer_out_drop nrfx_usbd_transfer_out_drop - -/** @brief Type definition for forwarding the new implementation. */ -static inline ret_code_t nrf_drv_usbd_uninit(void) -{ - nrfx_usbd_uninit(); - return NRF_SUCCESS; -} - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif /* NRF_DRV_USBD_H__ */ diff --git a/integration/nrfx/legacy/nrf_drv_usbd_errata.h b/integration/nrfx/legacy/nrf_drv_usbd_errata.h deleted file mode 100644 index 1abea34..0000000 --- a/integration/nrfx/legacy/nrf_drv_usbd_errata.h +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright (c) 2017 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_DRV_USBD_ERRATA_H__ -#define NRF_DRV_USBD_ERRATA_H__ - -#include "nrfx.h" - -#ifndef NRFX_USBD_ERRATA_ENABLE - #ifdef NRF_DRV_USBD_ERRATA_ENABLE - #define NRFX_USBD_ERRATA_ENABLE NRF_DRV_USBD_ERRATA_ENABLE - #endif -#endif - -#include "../src/nrfx_usbd_errata.h" - -#ifndef NRF_DRV_USBD_ERRATA_ENABLE -#define NRF_DRV_USBD_ERRATA_ENABLE NRFX_USBD_ERRATA_ENABLE -#endif - -#define nrf_drv_usbd_errata_type_52840 nrfx_usbd_errata_type_52840 -#define nrf_drv_usbd_errata_type_52840_proto1 nrfx_usbd_errata_type_52840_proto1 -#define nrf_drv_usbd_errata_type_52840_fp1 nrfx_usbd_errata_type_52840_fp1 -#define nrf_drv_usbd_errata_type_52840_fp2 nrfx_usbd_errata_type_52840_fp2 -#define nrf_drv_usbd_errata_104 nrfx_usbd_errata_104 -#define nrf_drv_usbd_errata_154 nrfx_usbd_errata_154 -#define nrf_drv_usbd_errata_166 nrfx_usbd_errata_166 -#define nrf_drv_usbd_errata_171 nrfx_usbd_errata_171 -#define nrf_drv_usbd_errata_187 nrfx_usbd_errata_187 -#define nrf_drv_usbd_errata_sizeepout_rw nrfx_usbd_errata_sizeepout_rw -#define nrf_drv_usb_errata_199 nrfx_usb_errata_199 - -#endif /* NRF_DRV_USBD_ERRATA_H__ */ diff --git a/modules/nrfx/drivers/include/nrfx_adc.h b/modules/nrfx/drivers/include/nrfx_adc.h deleted file mode 100644 index ec7e3b9..0000000 --- a/modules/nrfx/drivers/include/nrfx_adc.h +++ /dev/null @@ -1,289 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRFX_ADC_H__ -#define NRFX_ADC_H__ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrfx_adc ADC driver - * @{ - * @ingroup nrf_adc - * @brief Analog-to-Digital Converter (ADC) peripheral driver. - */ - -/** @brief Driver event types. */ -typedef enum -{ - NRFX_ADC_EVT_DONE, ///< Event generated when the buffer is filled with samples. - NRFX_ADC_EVT_SAMPLE, ///< Event generated when the requested channel is sampled. -} nrfx_adc_evt_type_t; - -/** @brief ADC driver DONE event structure. */ -typedef struct -{ - nrf_adc_value_t * p_buffer; ///< Pointer to the buffer with converted samples. - uint16_t size; ///< Number of samples in the buffer. -} nrfx_adc_done_evt_t; - -/** @brief SAMPLE event structure. */ -typedef struct -{ - nrf_adc_value_t sample; ///< Converted sample. -} nrfx_adc_sample_evt_t; - -/** @brief ADC driver event. */ -typedef struct -{ - nrfx_adc_evt_type_t type; ///< Event type. - union - { - nrfx_adc_done_evt_t done; ///< Data for DONE event. - nrfx_adc_sample_evt_t sample; ///< Data for SAMPLE event. - } data; ///< Union to store event data. -} nrfx_adc_evt_t; - -/** @brief Macro for initializing the ADC channel with the default configuration. */ -#define NRFX_ADC_DEFAULT_CHANNEL(analog_input) \ - { \ - NULL, \ - { \ - .resolution = NRF_ADC_CONFIG_RES_10BIT, \ - .scaling = NRF_ADC_CONFIG_SCALING_INPUT_FULL_SCALE, \ - .reference = NRF_ADC_CONFIG_REF_VBG, \ - .input = (analog_input), \ - .extref = NRF_ADC_CONFIG_EXTREFSEL_NONE \ - } \ - } - -/** @brief Forward declaration of the nrfx_adc_channel_t type. */ -typedef struct nrfx_adc_channel_s nrfx_adc_channel_t; - -/** - * @brief ADC channel. - * - * This structure is defined by the user and used by the driver. Therefore, it should - * not be defined on the stack as a local variable. - */ -struct nrfx_adc_channel_s -{ - nrfx_adc_channel_t * p_next; ///< Pointer to the next enabled channel (for internal use). - nrf_adc_config_t config; ///< ADC configuration for the current channel. -}; - -/** @brief ADC configuration. */ -typedef struct -{ - uint8_t interrupt_priority; ///< Priority of ADC interrupt. -} nrfx_adc_config_t; - -/** @brief ADC default configuration. */ -#define NRFX_ADC_DEFAULT_CONFIG \ -{ \ - .interrupt_priority = NRFX_ADC_CONFIG_IRQ_PRIORITY \ -} - -/** - * @brief User event handler prototype. - * - * This function is called when the requested number of samples has been processed. - * - * @param p_event Event. - */ -typedef void (*nrfx_adc_event_handler_t)(nrfx_adc_evt_t const * p_event); - -/** - * @brief Function for initializing the ADC. - * - * If a valid event handler is provided, the driver is initialized in non-blocking mode. - * If event_handler is NULL, the driver works in blocking mode. - * - * @param[in] p_config Pointer to the structure with the initial configuration. - * @param[in] event_handler Event handler provided by the user. - * - * @retval NRFX_SUCCESS Initialization was successful. - * @retval NRFX_ERROR_INVALID_STATE The driver is already initialized. - */ -nrfx_err_t nrfx_adc_init(nrfx_adc_config_t const * p_config, - nrfx_adc_event_handler_t event_handler); - -/** - * @brief Function for uninitializing the ADC. - * - * This function stops all ongoing conversions and disables all channels. - */ -void nrfx_adc_uninit(void); - -/** - * @brief Function for enabling an ADC channel. - * - * This function configures and enables the channel. When @ref nrfx_adc_buffer_convert is - * called, all channels that have been enabled with this function are sampled. - * - * This function can be called only when there is no conversion in progress - * (the ADC is not busy). - * - * @note The channel instance variable @p p_channel is used by the driver as an item - * in a list. Therefore, it cannot be an automatic variable that is located on the stack. - * - * @param[in] p_channel Pointer to the channel instance. - */ -void nrfx_adc_channel_enable(nrfx_adc_channel_t * const p_channel); - -/** - * @brief Function for disabling an ADC channel. - * - * This function can be called only when there is no conversion in progress - * (the ADC is not busy). - * - * @param p_channel Pointer to the channel instance. - */ -void nrfx_adc_channel_disable(nrfx_adc_channel_t * const p_channel); - -/** - * @brief Function for disabling all ADC channels. - * - * This function can be called only when there is no conversion in progress - * (the ADC is not busy). - */ -void nrfx_adc_all_channels_disable(void); - -/** - * @brief Function for starting ADC sampling. - * - * This function triggers single ADC sampling. If more than one channel is enabled, the driver - * emulates scanning and all channels are sampled in the order they were enabled. - */ -void nrfx_adc_sample(void); - -/** - * @brief Function for executing a single ADC conversion. - * - * This function selects the desired input and starts a single conversion. If a valid pointer - * is provided for the result, the function blocks until the conversion is completed. Otherwise, the - * function returns when the conversion is started, and the result is provided in an event (driver - * must be initialized in non-blocking mode, otherwise an assertion will fail). The function will - * fail if ADC is busy. The channel does not need to be enabled to perform a single conversion. - * - * @param[in] p_channel Channel. - * @param[out] p_value Pointer to the location where the result is to be placed. Unless NULL is - * provided, the function is blocking. - * - * @retval NRFX_SUCCESS Conversion was successful. - * @retval NRFX_ERROR_BUSY The ADC driver is busy. - */ -nrfx_err_t nrfx_adc_sample_convert(nrfx_adc_channel_t const * const p_channel, - nrf_adc_value_t * p_value); - -/** - * @brief Function for converting data to the buffer. - * - * If the driver is initialized in non-blocking mode, this function returns when the first - * conversion is set up. When the buffer is filled, the application is notified by the event - * handler. If the driver is initialized in blocking mode, the function returns when the buffer is - * filled. - * - * Conversion is done on all enabled channels, but it is not triggered by this - * function. This function will prepare the ADC for sampling and then - * wait for the SAMPLE task. Sampling can be triggered manually by the @ref - * nrfx_adc_sample function or by PPI using the @ref NRF_ADC_TASK_START task. - * - * @note If more than one channel is enabled, the function emulates scanning, and - * a single START task will trigger conversion on all enabled channels. For example: - * If 3 channels are enabled and the user requests 6 samples, the completion event - * handler will be called after 2 START tasks. - * - * @note The application must adjust the sampling frequency. The maximum frequency - * depends on the sampling timer and the maximum latency of the ADC interrupt. If - * an interrupt is not handled before the next sampling is triggered, the sample - * will be lost. - * - * @param[in] buffer Result buffer. - * @param[in] size Buffer size in samples. - * - * @retval NRFX_SUCCESS Conversion was successful. - * @retval NRFX_ERROR_BUSY The driver is busy. - */ -nrfx_err_t nrfx_adc_buffer_convert(nrf_adc_value_t * buffer, uint16_t size); - -/** - * @brief Function for retrieving the ADC state. - * - * @retval true The ADC is busy. - * @retval false The ADC is ready. - */ -bool nrfx_adc_is_busy(void); - -/** - * @brief Function for getting the address of the ADC START task. - * - * This function is used to get the address of the START task, which can be used to trigger ADC - * conversion. - * - * @return Start task address. - */ -__STATIC_INLINE uint32_t nrfx_adc_start_task_get(void); - -#ifndef SUPPRESS_INLINE_IMPLEMENTATION - -__STATIC_INLINE uint32_t nrfx_adc_start_task_get(void) -{ - return nrf_adc_task_address_get(NRF_ADC_TASK_START); -} - -#endif - -/** @} */ - - -void nrfx_adc_irq_handler(void); - - -#ifdef __cplusplus -} -#endif - -#endif // NRFX_ADC_H__ diff --git a/modules/nrfx/drivers/include/nrfx_comp.h b/modules/nrfx/drivers/include/nrfx_comp.h deleted file mode 100644 index b4b9cc3..0000000 --- a/modules/nrfx/drivers/include/nrfx_comp.h +++ /dev/null @@ -1,248 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRFX_COMP_H__ -#define NRFX_COMP_H__ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrfx_comp COMP driver - * @{ - * @ingroup nrf_comp - * @brief Comparator (COMP) peripheral driver. - */ - -/** - * @brief Macro for converting the threshold voltage to an integer value - * (needed by the COMP_TH register). - * - * @param[in] vol Voltage to be changed to COMP_TH register value. This value - * must not be smaller than reference voltage divided by 64. - * @param[in] ref Reference voltage. - */ -#define NRFX_VOLTAGE_THRESHOLD_TO_INT(vol, ref) \ - (uint8_t)(((vol) > ((ref) / 64)) ? (NRFX_ROUNDED_DIV((vol) * 64,(ref)) - 1) : 0) - -/** - * @brief COMP event handler function type. - * - * @param[in] event COMP event. - */ -typedef void (* nrfx_comp_event_handler_t)(nrf_comp_event_t event); - -/** @brief COMP shortcut masks. */ -typedef enum -{ - NRFX_COMP_SHORT_STOP_AFTER_CROSS_EVT = COMP_SHORTS_CROSS_STOP_Msk, /*!< Shortcut between the CROSS event and the STOP task. */ - NRFX_COMP_SHORT_STOP_AFTER_UP_EVT = COMP_SHORTS_UP_STOP_Msk, /*!< Shortcut between the UP event and the STOP task. */ - NRFX_COMP_SHORT_STOP_AFTER_DOWN_EVT = COMP_SHORTS_DOWN_STOP_Msk /*!< Shortcut between the DOWN event and the STOP task. */ -} nrfx_comp_short_mask_t; - -/** @brief COMP events masks. */ -typedef enum -{ - NRFX_COMP_EVT_EN_CROSS_MASK = COMP_INTENSET_CROSS_Msk, /*!< CROSS event (generated after VIN+ == VIN-). */ - NRFX_COMP_EVT_EN_UP_MASK = COMP_INTENSET_UP_Msk, /*!< UP event (generated when VIN+ crosses VIN- while increasing). */ - NRFX_COMP_EVT_EN_DOWN_MASK = COMP_INTENSET_DOWN_Msk, /*!< DOWN event (generated when VIN+ crosses VIN- while decreasing). */ - NRFX_COMP_EVT_EN_READY_MASK = COMP_INTENSET_READY_Msk /*!< READY event (generated when the module is ready). */ -} nrfx_comp_evt_en_mask_t; - -/** @brief COMP configuration. */ -typedef struct -{ - nrf_comp_ref_t reference; /**< Reference selection. */ - nrf_comp_ext_ref_t ext_ref; /**< External analog reference selection. */ - nrf_comp_main_mode_t main_mode; /**< Main operation mode. */ - nrf_comp_th_t threshold; /**< Structure holding THDOWN and THUP values needed by the COMP_TH register. */ - nrf_comp_sp_mode_t speed_mode; /**< Speed and power mode. */ - nrf_comp_hyst_t hyst; /**< Comparator hysteresis. */ -#if defined (COMP_ISOURCE_ISOURCE_Msk) || defined (__NRFX_DOXYGEN__) - nrf_isource_t isource; /**< Current source selected on analog input. */ -#endif - nrf_comp_input_t input; /**< Input to be monitored. */ - uint8_t interrupt_priority; /**< Interrupt priority. */ -} nrfx_comp_config_t; - -/** @brief COMP threshold default configuration. */ -#define NRFX_COMP_CONFIG_TH \ -{ \ - .th_down = NRFX_VOLTAGE_THRESHOLD_TO_INT(0.5, 1.8), \ - .th_up = NRFX_VOLTAGE_THRESHOLD_TO_INT(1.5, 1.8) \ -} - -/** @brief COMP driver default configuration including the COMP HAL configuration. */ -#if defined (COMP_ISOURCE_ISOURCE_Msk) || defined (__NRFX_DOXYGEN__) -#define NRFX_COMP_DEFAULT_CONFIG(_input) \ -{ \ - .reference = (nrf_comp_ref_t)NRFX_COMP_CONFIG_REF, \ - .ext_ref = NRF_COMP_EXT_REF_0, \ - .main_mode = (nrf_comp_main_mode_t)NRFX_COMP_CONFIG_MAIN_MODE, \ - .threshold = NRFX_COMP_CONFIG_TH, \ - .speed_mode = (nrf_comp_sp_mode_t)NRFX_COMP_CONFIG_SPEED_MODE, \ - .hyst = (nrf_comp_hyst_t)NRFX_COMP_CONFIG_HYST, \ - .isource = (nrf_isource_t)NRFX_COMP_CONFIG_ISOURCE, \ - .input = (nrf_comp_input_t)_input, \ - .interrupt_priority = NRFX_COMP_CONFIG_IRQ_PRIORITY \ -} -#else -#define NRFX_COMP_DEFAULT_CONFIG(_input) \ -{ \ - .reference = (nrf_comp_ref_t)NRFX_COMP_CONFIG_REF, \ - .ext_ref = NRF_COMP_EXT_REF_0, \ - .main_mode = (nrf_comp_main_mode_t)NRFX_COMP_CONFIG_MAIN_MODE, \ - .threshold = NRFX_COMP_CONFIG_TH, \ - .speed_mode = (nrf_comp_sp_mode_t)NRFX_COMP_CONFIG_SPEED_MODE, \ - .hyst = (nrf_comp_hyst_t)NRFX_COMP_CONFIG_HYST, \ - .input = (nrf_comp_input_t)_input, \ - .interrupt_priority = NRFX_COMP_CONFIG_IRQ_PRIORITY \ -} -#endif - -/** - * @brief Function for initializing the COMP driver. - * - * This function initializes the COMP driver, but does not enable the peripheral or any interrupts. - * To start the driver, call the function @ref nrfx_comp_start() after initialization. - * - * @param[in] p_config Pointer to the structure with the initial configuration. - * @param[in] event_handler Event handler provided by the user. - * Must not be NULL. - * - * @retval NRFX_SUCCESS Initialization was successful. - * @retval NRFX_ERROR_INVALID_STATE The driver has already been initialized. - * @retval NRFX_ERROR_BUSY The LPCOMP peripheral is already in use. - * This is possible only if @ref nrfx_prs module - * is enabled. - */ -nrfx_err_t nrfx_comp_init(nrfx_comp_config_t const * p_config, - nrfx_comp_event_handler_t event_handler); - -/** - * @brief Function for uninitializing the COMP driver. - * - * This function uninitializes the COMP driver. The COMP peripheral and - * its interrupts are disabled, and local variables are cleaned. After this call, you must - * initialize the driver again by calling nrfx_comp_init() if you want to use it. - * - * @sa nrfx_comp_stop - */ -void nrfx_comp_uninit(void); - -/** - * @brief Function for setting the analog input. - * - * @param[in] psel COMP analog pin selection. - */ -void nrfx_comp_pin_select(nrf_comp_input_t psel); - -/** - * @brief Function for starting the COMP peripheral and interrupts. - * - * Before calling this function, the driver must be initialized. This function - * enables the COMP peripheral and its interrupts. - * - * @param[in] comp_evt_en_mask Mask of events to be enabled. This parameter is to be built as - * an OR of elements from @ref nrfx_comp_evt_en_mask_t. - * @param[in] comp_shorts_mask Mask of shortcuts to be enabled. This parameter is to be built as - * an OR of elements from @ref nrfx_comp_short_mask_t. - * - * @sa nrfx_comp_init - */ -void nrfx_comp_start(uint32_t comp_evt_en_mask, uint32_t comp_shorts_mask); - -/** - * @brief Function for stopping the COMP peripheral. - * - * Before calling this function, the driver must be enabled. This function disables the COMP - * peripheral and its interrupts. - * - * @sa nrfx_comp_uninit - */ -void nrfx_comp_stop(void); - -/** - * @brief Function for copying the current state of the comparator result to the RESULT register. - * - * @retval 0 The input voltage is below the threshold (VIN+ < VIN-). - * @retval 1 The input voltage is above the threshold (VIN+ > VIN-). - */ -uint32_t nrfx_comp_sample(void); - -/** - * @brief Function for getting the address of a COMP task. - * - * @param[in] task COMP task. - * - * @return Address of the given COMP task. - */ -__STATIC_INLINE uint32_t nrfx_comp_task_address_get(nrf_comp_task_t task) -{ - return (uint32_t)nrf_comp_task_address_get(task); -} - -/** - * @brief Function for getting the address of a COMP event. - * - * @param[in] event COMP event. - * - * @return Address of the given COMP event. - */ -__STATIC_INLINE uint32_t nrfx_comp_event_address_get(nrf_comp_event_t event) -{ - return (uint32_t)nrf_comp_event_address_get(event); -} - -/** @} */ - - -void nrfx_comp_irq_handler(void); - - -#ifdef __cplusplus -} -#endif - -#endif // NRFX_COMP_H__ diff --git a/modules/nrfx/drivers/include/nrfx_dppi.h b/modules/nrfx/drivers/include/nrfx_dppi.h deleted file mode 100644 index 322f725..0000000 --- a/modules/nrfx/drivers/include/nrfx_dppi.h +++ /dev/null @@ -1,185 +0,0 @@ -/** - * Copyright (c) 2018 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRFX_DPPI_H__ -#define NRFX_DPPI_H__ - -#include -#include - -/** - * @defgroup nrfx_dppi DPPI allocator - * @{ - * @ingroup nrf_dppi - * @brief Distributed Programmable Peripheral Interconnect (DPPI) allocator. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** @brief Function for freeing all allocated channels and groups. */ -void nrfx_dppi_free(void); - -/** - * @brief Function for allocating a DPPI channel. - * @details This function allocates the first unused DPPI channel. - * - * @param[out] p_channel Pointer to the DPPI channel number that has been allocated. - * - * @retval NRFX_SUCCESS The channel was successfully allocated. - * @retval NRFX_ERROR_NO_MEM There is no available channel to be used. - */ -nrfx_err_t nrfx_dppi_channel_alloc(uint8_t * p_channel); - -/** - * @brief Function for freeing a DPPI channel. - * @details This function also disables the chosen channel. - * - * @param[in] channel DPPI channel to be freed. - * - * @retval NRFX_SUCCESS The channel was successfully freed. - * @retval NRFX_ERROR_INVALID_PARAM The specified channel is not allocated. - */ -nrfx_err_t nrfx_dppi_channel_free(uint8_t channel); - -/** - * @brief Function for enabling a DPPI channel. - * - * @param[in] channel DPPI channel to be enabled. - * - * @retval NRFX_SUCCESS The channel was successfully enabled. - * @retval NRFX_ERROR_INVALID_PARAM The specified channel is not allocated. - */ -nrfx_err_t nrfx_dppi_channel_enable(uint8_t channel); - -/** - * @brief Function for disabling a DPPI channel. - * - * @param[in] channel DPPI channel to be disabled. - * - * @retval NRFX_SUCCESS The channel was successfully disabled. - * @retval NRFX_ERROR_INVALID_PARAM The specified channel is not allocated. - */ -nrfx_err_t nrfx_dppi_channel_disable(uint8_t channel); - -/** - * @brief Function for allocating a DPPI channel group. - * @details This function allocates the first unused DPPI group. - * - * @param[out] p_group Pointer to the DPPI channel group that has been allocated. - * - * @retval NRFX_SUCCESS The channel group was successfully allocated. - * @retval NRFX_ERROR_NO_MEM There is no available channel group to be used. - */ -nrfx_err_t nrfx_dppi_group_alloc(nrf_dppi_channel_group_t * p_group); - -/** - * @brief Function for freeing a DPPI channel group. - * @details This function also disables the chosen group. - * - * @param[in] group DPPI channel group to be freed. - * - * @retval NRFX_SUCCESS The channel group was successfully freed. - * @retval NRFX_ERROR_INVALID_PARAM The specified group is not allocated. - */ -nrfx_err_t nrfx_dppi_group_free(nrf_dppi_channel_group_t group); - -/** - * @brief Function for including a DPPI channel in a channel group. - * - * @param[in] channel DPPI channel to be added. - * @param[in] group Channel group in which to include the channel. - * - * @retval NRFX_SUCCESS The channel was successfully included. - * @retval NRFX_ERROR_INVALID_PARAM The specified group or channel is not allocated. - */ -nrfx_err_t nrfx_dppi_channel_include_in_group(uint8_t channel, - nrf_dppi_channel_group_t group); - -/** - * @brief Function for removing a DPPI channel from a channel group. - * - * @param[in] channel DPPI channel to be removed. - * @param[in] group Channel group from which to remove the channel. - * - * @retval NRFX_SUCCESS The channel was successfully removed. - * @retval NRFX_ERROR_INVALID_PARAM The specified group or channel is not allocated. - */ -nrfx_err_t nrfx_dppi_channel_remove_from_group(uint8_t channel, - nrf_dppi_channel_group_t group); - -/** - * @brief Function for clearing a DPPI channel group. - * - * @param[in] group Channel group to be cleared. - * - * @retval NRFX_SUCCESS The group was successfully cleared. - * @retval NRFX_ERROR_INVALID_PARAM The specified group is not allocated. - */ -nrfx_err_t nrfx_dppi_group_clear(nrf_dppi_channel_group_t group); - -/** - * @brief Function for enabling a DPPI channel group. - * - * @param[in] group Channel group to be enabled. - * - * @retval NRFX_SUCCESS The group was successfully enabled. - * @retval NRFX_ERROR_INVALID_PARAM The specified group is not allocated. - */ -nrfx_err_t nrfx_dppi_group_enable(nrf_dppi_channel_group_t group); - -/** - * @brief Function for disabling a DPPI channel group. - * - * @param[in] group Channel group to be disabled. - * - * @retval NRFX_SUCCESS The group was successfully disabled. - * @retval NRFX_ERROR_INVALID_PARAM The specified group is not allocated. - */ -nrfx_err_t nrfx_dppi_group_disable(nrf_dppi_channel_group_t group); - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif // NRFX_DPPI_H__ diff --git a/modules/nrfx/drivers/include/nrfx_i2s.h b/modules/nrfx/drivers/include/nrfx_i2s.h deleted file mode 100644 index d9ac560..0000000 --- a/modules/nrfx/drivers/include/nrfx_i2s.h +++ /dev/null @@ -1,253 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRFX_I2S_H__ -#define NRFX_I2S_H__ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrfx_i2s I2S driver - * @{ - * @ingroup nrf_i2s - * @brief Inter-IC Sound (I2S) peripheral driver. - */ - - -/** - * @brief This value can be provided instead of a pin number for the signals - * SDOUT, SDIN, and MCK to specify that a given signal is not used - * and therefore does not need to be connected to a pin. - */ -#define NRFX_I2S_PIN_NOT_USED 0xFF - -/** @brief I2S driver configuration structure. */ -typedef struct -{ - uint8_t sck_pin; ///< SCK pin number. - uint8_t lrck_pin; ///< LRCK pin number. - uint8_t mck_pin; ///< MCK pin number. - /**< Optional. Use @ref NRFX_I2S_PIN_NOT_USED - * if this signal is not needed. */ - uint8_t sdout_pin; ///< SDOUT pin number. - /**< Optional. Use @ref NRFX_I2S_PIN_NOT_USED - * if this signal is not needed. */ - uint8_t sdin_pin; ///< SDIN pin number. - /**< Optional. Use @ref NRFX_I2S_PIN_NOT_USED - * if this signal is not needed. */ - uint8_t irq_priority; ///< Interrupt priority. - - nrf_i2s_mode_t mode; ///< Mode of operation. - nrf_i2s_format_t format; ///< Frame format. - nrf_i2s_align_t alignment; ///< Alignment of sample within a frame. - nrf_i2s_swidth_t sample_width; ///< Sample width. - nrf_i2s_channels_t channels; ///< Enabled channels. - nrf_i2s_mck_t mck_setup; ///< Master clock setup. - nrf_i2s_ratio_t ratio; ///< MCK/LRCK ratio. -} nrfx_i2s_config_t; - -/** @brief I2S driver buffers structure. */ -typedef struct -{ - uint32_t * p_rx_buffer; ///< Pointer to the buffer for received data. - uint32_t const * p_tx_buffer; ///< Pointer to the buffer with data to be sent. -} nrfx_i2s_buffers_t; - -/** @brief I2S driver default configuration. */ -#define NRFX_I2S_DEFAULT_CONFIG \ -{ \ - .sck_pin = NRFX_I2S_CONFIG_SCK_PIN, \ - .lrck_pin = NRFX_I2S_CONFIG_LRCK_PIN, \ - .mck_pin = NRFX_I2S_CONFIG_MCK_PIN, \ - .sdout_pin = NRFX_I2S_CONFIG_SDOUT_PIN, \ - .sdin_pin = NRFX_I2S_CONFIG_SDIN_PIN, \ - .irq_priority = NRFX_I2S_CONFIG_IRQ_PRIORITY, \ - .mode = (nrf_i2s_mode_t)NRFX_I2S_CONFIG_MASTER, \ - .format = (nrf_i2s_format_t)NRFX_I2S_CONFIG_FORMAT, \ - .alignment = (nrf_i2s_align_t)NRFX_I2S_CONFIG_ALIGN, \ - .sample_width = (nrf_i2s_swidth_t)NRFX_I2S_CONFIG_SWIDTH, \ - .channels = (nrf_i2s_channels_t)NRFX_I2S_CONFIG_CHANNELS, \ - .mck_setup = (nrf_i2s_mck_t)NRFX_I2S_CONFIG_MCK_SETUP, \ - .ratio = (nrf_i2s_ratio_t)NRFX_I2S_CONFIG_RATIO, \ -} - - -#define NRFX_I2S_STATUS_NEXT_BUFFERS_NEEDED (1UL << 0) - /**< The application must provide buffers that are to be used in the next - * part of the transfer. A call to @ref nrfx_i2s_next_buffers_set must - * be done before the currently used buffers are completely processed - * (that is, the time remaining for supplying the next buffers depends on - * the used size of the buffers). */ - -/** - * @brief I2S driver data handler type. - * - * A data handling function of this type must be specified during the initialization - * of the driver. The driver will call this function when it finishes using - * buffers passed to it by the application, and when it needs to be provided - * with buffers for the next part of the transfer. - * - * @note The @c p_released pointer passed to this function is temporary and - * will be invalid after the function returns, hence it cannot be stored - * and used later. If needed, the pointed content (that is, buffers pointers) - * must be copied instead. - * - * @param[in] p_released Pointer to a structure with pointers to buffers - * passed previously to the driver that will no longer - * be accessed by it (they can be now safely released or - * used for another purpose, in particular for a next - * part of the transfer). - * This pointer will be NULL if the application did not - * supply the buffers for the next part of the transfer - * (via a call to @ref nrfx_i2s_next_buffers_set) since - * the previous time the data handler signaled such need. - * This means that data corruption occurred (the previous - * buffers are used for the second time) and no buffers - * can be released at the moment. - * Both pointers in this structure are NULL when the - * handler is called for the first time after a transfer - * is started, because no data has been transferred yet - * at this point. In all successive calls the pointers - * specify what has been sent (TX) and what has been - * received (RX) in the part of transfer that has just - * been completed (provided that a given direction is - * enabled, see @ref nrfx_i2s_start). - * @param[in] status Bit field describing the current status of the transfer. - * It can be 0 or a combination of the following flags: - * - @ref NRFX_I2S_STATUS_NEXT_BUFFERS_NEEDED - */ -typedef void (* nrfx_i2s_data_handler_t)(nrfx_i2s_buffers_t const * p_released, - uint32_t status); - - -/** - * @brief Function for initializing the I2S driver. - * - * @param[in] p_config Pointer to the structure with the initial configuration. - * @param[in] handler Data handler provided by the user. Must not be NULL. - * - * @retval NRFX_SUCCESS Initialization was successful. - * @retval NRFX_ERROR_INVALID_STATE The driver was already initialized. - * @retval NRFX_ERROR_INVALID_PARAM The requested combination of configuration - * options is not allowed by the I2S peripheral. - */ -nrfx_err_t nrfx_i2s_init(nrfx_i2s_config_t const * p_config, - nrfx_i2s_data_handler_t handler); - -/** @brief Function for uninitializing the I2S driver. */ -void nrfx_i2s_uninit(void); - -/** - * @brief Function for starting the continuous I2S transfer. - * - * The I2S data transfer can be performed in one of three modes: RX (reception) - * only, TX (transmission) only, or in both directions simultaneously. - * The mode is selected by specifying a proper buffer for a given direction - * in the call to this function or by passing NULL instead if this direction - * is to be disabled. - * - * The length of the buffer (which is a common value for RX and TX if both - * directions are enabled) is specified in 32-bit words. One 32-bit memory - * word can either contain four 8-bit samples, two 16-bit samples, or one - * right-aligned 24-bit sample sign-extended to a 32-bit value. - * For a detailed memory mapping for different supported configurations, - * see the @linkProductSpecification52. - * - * @note Peripherals using EasyDMA (including I2S) require the transfer buffers - * to be placed in the Data RAM region. If this condition is not met, - * this function will fail with the error code NRFX_ERROR_INVALID_ADDR. - * - * @param[in] p_initial_buffers Pointer to a structure specifying the buffers - * to be used in the initial part of the transfer - * (buffers for all consecutive parts are provided - * through the data handler). - * @param[in] buffer_size Size of the buffers (in 32-bit words). - * Must not be 0. - * @param[in] flags Transfer options (0 for default settings). - * Currently, no additional flags are available. - * - * @retval NRFX_SUCCESS The operation was successful. - * @retval NRFX_ERROR_INVALID_STATE Transfer was already started or - * the driver has not been initialized. - * @retval NRFX_ERROR_INVALID_ADDR The provided buffers are not placed - * in the Data RAM region. - */ -nrfx_err_t nrfx_i2s_start(nrfx_i2s_buffers_t const * p_initial_buffers, - uint16_t buffer_size, - uint8_t flags); - -/** - * @brief Function for supplying the buffers to be used in the next part of - * the transfer. - * - * The application must call this function when the data handler receives - * @ref NRFX_I2S_STATUS_NEXT_BUFFERS_NEEDED in the @c status parameter. - * The call can be done immediately from the data handler function or later, - * but it has to be done before the I2S peripheral finishes processing the - * buffers supplied previously. Otherwise, data corruption will occur. - * - * @sa nrfx_i2s_data_handler_t - * - * @retval NRFX_SUCCESS If the operation was successful. - * @retval NRFX_ERROR_INVALID_STATE If the buffers were already supplied or - * the peripheral is currently being stopped. - */ -nrfx_err_t nrfx_i2s_next_buffers_set(nrfx_i2s_buffers_t const * p_buffers); - -/** @brief Function for stopping the I2S transfer. */ -void nrfx_i2s_stop(void); - -/** @} */ - - -void nrfx_i2s_irq_handler(void); - - -#ifdef __cplusplus -} -#endif - -#endif // NRFX_I2S_H__ - diff --git a/modules/nrfx/drivers/include/nrfx_lpcomp.h b/modules/nrfx/drivers/include/nrfx_lpcomp.h deleted file mode 100644 index fc9b4f4..0000000 --- a/modules/nrfx/drivers/include/nrfx_lpcomp.h +++ /dev/null @@ -1,153 +0,0 @@ -/** - * Copyright (c) 2014 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRFX_LPCOMP_H__ -#define NRFX_LPCOMP_H__ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrfx_lpcomp LPCOMP driver - * @{ - * @ingroup nrf_lpcomp - * @brief Low Power Comparator (LPCOMP) peripheral driver. - */ - -/** - * @brief LPCOMP event handler function type. - * @param[in] event LPCOMP event. - */ -typedef void (* nrfx_lpcomp_event_handler_t)(nrf_lpcomp_event_t event); - -/** @brief LPCOMP configuration. */ -typedef struct -{ - nrf_lpcomp_config_t hal; /**< LPCOMP HAL configuration. */ - nrf_lpcomp_input_t input; /**< Input to be monitored. */ - uint8_t interrupt_priority; /**< LPCOMP interrupt priority. */ -} nrfx_lpcomp_config_t; - -/** @brief LPCOMP driver default configuration, including the LPCOMP HAL configuration. */ -#ifdef NRF52_SERIES -#define NRFX_LPCOMP_DEFAULT_CONFIG \ -{ \ - .hal = { (nrf_lpcomp_ref_t)NRFX_LPCOMP_CONFIG_REFERENCE , \ - (nrf_lpcomp_detect_t)NRFX_LPCOMP_CONFIG_DETECTION, \ - (nrf_lpcomp_hysteresis_t)NRFX_LPCOMP_CONFIG_HYST }, \ - .input = (nrf_lpcomp_input_t)NRFX_LPCOMP_CONFIG_INPUT, \ - .interrupt_priority = NRFX_LPCOMP_CONFIG_IRQ_PRIORITY \ -} -#else -#define NRFX_LPCOMP_DEFAULT_CONFIG \ -{ \ - .hal = { (nrf_lpcomp_ref_t)NRFX_LPCOMP_CONFIG_REFERENCE , \ - (nrf_lpcomp_detect_t)NRFX_LPCOMP_CONFIG_DETECTION }, \ - .input = (nrf_lpcomp_input_t)NRFX_LPCOMP_CONFIG_INPUT, \ - .interrupt_priority = NRFX_LPCOMP_CONFIG_IRQ_PRIORITY \ -} -#endif - -/** - * @brief Function for initializing the LPCOMP driver. - * - * This function initializes the LPCOMP driver, but does not enable the peripheral or any interrupts. - * To start the driver, call the function nrfx_lpcomp_enable() after initialization. - * - * @param[in] p_config Pointer to the structure with the initial configuration. - * @param[in] event_handler Event handler provided by the user. - * Must not be NULL. - * - * @retval NRFX_SUCCESS Initialization was successful. - * @retval NRFX_ERROR_INVALID_STATE The driver has already been initialized. - * @retval NRFX_ERROR_BUSY The COMP peripheral is already in use. - * This is possible only if @ref nrfx_prs module - * is enabled. - */ -nrfx_err_t nrfx_lpcomp_init(nrfx_lpcomp_config_t const * p_config, - nrfx_lpcomp_event_handler_t event_handler); - -/** - * @brief Function for uninitializing the LCOMP driver. - * - * This function uninitializes the LPCOMP driver. The LPCOMP peripheral and - * its interrupts are disabled, and local variables are cleaned. After this call, you must - * initialize the driver again by calling nrfx_lpcomp_init() if you want to use it. - * - * @sa nrfx_lpcomp_disable - * @sa nrfx_lpcomp_init - */ -void nrfx_lpcomp_uninit(void); - -/** - * @brief Function for enabling the LPCOMP peripheral and interrupts. - * - * Before calling this function, the driver must be initialized. This function - * enables the LPCOMP peripheral and its interrupts. - * - * @sa nrfx_lpcomp_disable - */ -void nrfx_lpcomp_enable(void); - -/** - * @brief Function for disabling the LPCOMP peripheral. - * - * Before calling this function, the driver must be initialized. This function disables the LPCOMP - * peripheral and its interrupts. - * - * @sa nrfx_lpcomp_enable - */ -void nrfx_lpcomp_disable(void); - -/** @} */ - - -void nrfx_lpcomp_irq_handler(void); - - -#ifdef __cplusplus -} -#endif - -#endif // NRFX_LPCOMP_H__ diff --git a/modules/nrfx/drivers/include/nrfx_nfct.h b/modules/nrfx/drivers/include/nrfx_nfct.h deleted file mode 100644 index 7659d6a..0000000 --- a/modules/nrfx/drivers/include/nrfx_nfct.h +++ /dev/null @@ -1,357 +0,0 @@ -/** - * Copyright (c) 2018 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRFX_NFCT_H__ -#define NRFX_NFCT_H__ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrfx_nfct NFCT driver - * @{ - * @ingroup nrf_nfct - * @brief Near Field Communication Tag (NFCT) peripheral driver. - */ - -#define NRFX_NFCT_NFCID1_SINGLE_SIZE 4u ///< Length of single-size NFCID1. -#define NRFX_NFCT_NFCID1_DOUBLE_SIZE 7u ///< Length of double-size NFCID1. -#define NRFX_NFCT_NFCID1_TRIPLE_SIZE 10u ///< Length of triple-size NFCID1. - -#define NRFX_NFCT_NFCID1_DEFAULT_LEN NRFX_NFCT_NFCID1_DOUBLE_SIZE ///< Default length of NFC ID. */ - -/** @brief NFCT hardware states. */ -typedef enum -{ - NRFX_NFCT_STATE_DISABLED = NRF_NFCT_TASK_DISABLE, ///< NFC Tag is disabled (no sensing of an external NFC field). - NRFX_NFCT_STATE_SENSING = NRF_NFCT_TASK_SENSE, ///< NFC Tag is sensing whether there is an external NFC field. - NRFX_NFCT_STATE_ACTIVATED = NRF_NFCT_TASK_ACTIVATE, ///< NFC Tag is powered-up (see @ref nrfx_nfct_active_state_t for possible substates). -} nrfx_nfct_state_t; - -/** - * @brief NFC tag states, when NFCT hardware is activated. - * - * @details These states are substates of the @ref NRFX_NFCT_STATE_ACTIVATED state. - */ -typedef enum -{ - NRFX_NFCT_ACTIVE_STATE_IDLE = NRF_NFCT_TASK_GOIDLE, ///< NFC Tag is activated and idle (not selected by a reader). - NRFX_NFCT_ACTIVE_STATE_SLEEP = NRF_NFCT_TASK_GOSLEEP, ///< NFC Tag is sleeping. - NRFX_NFCT_ACTIVE_STATE_DEFAULT, ///< NFC Tag is either sleeping or idle, depending on the previous state before being selected by a poller. -} nrfx_nfct_active_state_t; - -/** - * @brief NFCT driver event types, passed to the upper-layer callback function - * provided during the initialization. - */ -typedef enum -{ - NRFX_NFCT_EVT_FIELD_DETECTED = NRF_NFCT_INT_FIELDDETECTED_MASK, ///< External NFC field is detected. - NRFX_NFCT_EVT_FIELD_LOST = NRF_NFCT_INT_FIELDLOST_MASK, ///< External NFC Field is lost. - NRFX_NFCT_EVT_SELECTED = NRF_NFCT_INT_SELECTED_MASK, ///< Tag was selected by the poller. - NRFX_NFCT_EVT_RX_FRAMESTART = NRF_NFCT_INT_RXFRAMESTART_MASK, ///< Data frame reception started. - NRFX_NFCT_EVT_RX_FRAMEEND = NRF_NFCT_INT_RXFRAMEEND_MASK, ///< Data frame is received. - NRFX_NFCT_EVT_TX_FRAMESTART = NRF_NFCT_INT_TXFRAMESTART_MASK, ///< Data frame transmission started. - NRFX_NFCT_EVT_TX_FRAMEEND = NRF_NFCT_INT_TXFRAMEEND_MASK, ///< Data frame is transmitted. - NRFX_NFCT_EVT_ERROR = NRF_NFCT_INT_ERROR_MASK, ///< Error occurred in an NFC communication. -} nrfx_nfct_evt_id_t; - -/** @brief NFCT timing-related error types. */ -typedef enum -{ - NRFX_NFCT_ERROR_FRAMEDELAYTIMEOUT, ///< No response frame was transmitted to the poller in the transmit window. - NRFX_NFCT_ERROR_NUM, ///< Total number of possible errors. -} nrfx_nfct_error_t; - -/** @brief NFCT driver parameter types. */ -typedef enum -{ - NRFX_NFCT_PARAM_ID_FDT, ///< NFC-A Frame Delay Time parameter. - NRFX_NFCT_PARAM_ID_SEL_RES, ///< Value of the 'Protocol' field in the NFC-A SEL_RES frame. - NRFX_NFCT_PARAM_ID_NFCID1, ///< NFC-A NFCID1 setting (NFC tag identifier). -} nrfx_nfct_param_id_t; - -/** @brief NFCID1 descriptor. */ -typedef struct -{ - uint8_t const * p_id; ///< NFCID1 data. - uint8_t id_size; ///< NFCID1 size. -} nrfx_nfct_nfcid1_t; - -/** @brief NFCT driver parameter descriptor. */ -typedef struct -{ - nrfx_nfct_param_id_t id; ///< Type of parameter. - union - { - uint32_t fdt; ///< NFC-A Frame Delay Time. Filled when nrfx_nfct_param_t::id is @ref NRFX_NFCT_PARAM_ID_FDT. - uint8_t sel_res_protocol; ///< NFC-A value of the 'Protocol' field in the SEL_RES frame. Filled when nrfx_nfct_param_t::id is @ref NRFX_NFCT_PARAM_ID_SEL_RES. - nrfx_nfct_nfcid1_t nfcid1; ///< NFC-A NFCID1 value (tag identifier). Filled when nrfx_nfct_param_t::id is @ref NRFX_NFCT_PARAM_ID_NFCID1. - } data; ///< Union to store parameter data. -} nrfx_nfct_param_t; - -/** @brief NFCT driver RX/TX buffer descriptor. */ -typedef struct -{ - uint32_t data_size; ///< RX/TX buffer size. - uint8_t const * p_data; ///< RX/TX buffer. -} nrfx_nfct_data_desc_t; - -/** @brief Structure used to describe the @ref NRFX_NFCT_EVT_RX_FRAMEEND event type. */ -typedef struct -{ - uint32_t rx_status; ///< RX error status. - nrfx_nfct_data_desc_t rx_data; ///< RX buffer. -} nrfx_nfct_evt_rx_frameend_t; - -/** @brief Structure used to describe the @ref NRFX_NFCT_EVT_TX_FRAMESTART event type. */ -typedef struct -{ - nrfx_nfct_data_desc_t tx_data; ///< TX buffer. -} nrfx_nfct_evt_tx_framestart_t; - -/** @brief Structure used to describe the @ref NRFX_NFCT_EVT_ERROR event type. */ -typedef struct -{ - nrfx_nfct_error_t reason; ///< Reason for error. -} nrfx_nfct_evt_error_t; - -/** @brief NFCT driver event. */ -typedef struct -{ - nrfx_nfct_evt_id_t evt_id; ///< Type of event. - union - { - nrfx_nfct_evt_rx_frameend_t rx_frameend; ///< End of the RX frame data. Filled when nrfx_nfct_evt_t::evt_id is @ref NRFX_NFCT_EVT_RX_FRAMEEND. - nrfx_nfct_evt_tx_framestart_t tx_framestart; ///< Start of the TX frame data. Filled when nrfx_nfct_evt_t::evt_id is @ref NRFX_NFCT_EVT_TX_FRAMESTART. - nrfx_nfct_evt_error_t error; ///< Error data. Filled when nrfx_nfct_evt_t::evt_id is @ref NRFX_NFCT_EVT_ERROR. - } params; ///< Union to store event data. -} nrfx_nfct_evt_t; - -/** - * @brief Callback descriptor to pass events from the NFCT driver to the upper layer. - * - * @param[in] p_event Pointer to the event descriptor. - * - * @note @ref NRFX_NFCT_EVT_FIELD_DETECTED and @ref NRFX_NFCT_EVT_FIELD_LOST are generated only on field state transitions, - * i.e. there will be no multiple events of the same type (out of the 2 mentioned) coming in a row. - */ -typedef void (*nrfx_nfct_handler_t)(nrfx_nfct_evt_t const * p_event); - -/** @brief NFCT driver configuration structure. */ -typedef struct -{ - uint32_t rxtx_int_mask; ///< Mask for enabling RX/TX events. Indicate which events must be forwarded to the upper layer by using @ref nrfx_nfct_evt_id_t. By default, no events are enabled. */ - nrfx_nfct_handler_t cb; ///< Callback. -} nrfx_nfct_config_t; - -/** - * @brief Function for initializing the NFCT driver. - * - * @param[in] p_config Pointer to the NFCT driver configuration structure. - * - * @retval NRFX_SUCCESS The NFCT driver was initialized successfully. - * @retval NRFX_ERROR_INVALID_STATE The NFCT driver is already initialized. - */ -nrfx_err_t nrfx_nfct_init(nrfx_nfct_config_t const * p_config); - -/** - * @brief Function for uninitializing the NFCT driver. - * - * After uninitialization, the instance is in disabled state. - */ -void nrfx_nfct_uninit(void); - -/** - * @brief Function for starting the NFC subsystem. - * - * After this function completes, NFC readers are able to detect the tag. - */ -void nrfx_nfct_enable(void); - -/** - * @brief Function for disabling the NFCT driver. - * - * After this function returns, NFC readers are no longer able to connect - * to the tag. - */ -void nrfx_nfct_disable(void); - -/** - * @brief Function for checking whether the external NFC field is present in the range of the tag. - * - * @retval true The NFC field is present. - * @retval false No NFC field is present. - */ -bool nrfx_nfct_field_check(void); - -/** - * @brief Function for preparing the NFCT driver for receiving an NFC frame. - * - * @param[in] p_rx_data Pointer to the RX buffer. - */ -void nrfx_nfct_rx(nrfx_nfct_data_desc_t const * p_rx_data); - -/** - * @brief Function for transmitting an NFC frame. - * - * @param[in] p_tx_data Pointer to the TX buffer. - * @param[in] delay_mode Delay mode of the NFCT frame timer. - * - * @retval NRFX_SUCCESS The operation was successful. - * @retval NRFX_ERROR_INVALID_LENGTH The TX buffer size is invalid. - * @retval NRFX_ERROR_BUSY Driver is already transferring. - */ -nrfx_err_t nrfx_nfct_tx(nrfx_nfct_data_desc_t const * p_tx_data, - nrf_nfct_frame_delay_mode_t delay_mode); - -/** - * @brief Function for moving the NFCT to a new state. - * - * @note The HFCLK must be running before activating the NFCT with - * @ref NRFX_NFCT_STATE_ACTIVATED. - * - * @param[in] state The required state. - */ -void nrfx_nfct_state_force(nrfx_nfct_state_t state); - -/** - * @brief Function for moving the NFCT to a new initial substate within @ref NRFX_NFCT_STATE_ACTIVATED. - * - * @param[in] sub_state The required substate. - */ -void nrfx_nfct_init_substate_force(nrfx_nfct_active_state_t sub_state); - -/** - * @brief Function for setting the NFC communication parameter. - * - * @note Parameter validation for length and acceptable values. - * - * @param[in] p_param Pointer to parameter descriptor. - * - * @retval NRFX_SUCCESS The operation was successful. - * @retval NRFX_ERROR_INVALID_PARAM The parameter data is invalid. - */ -nrfx_err_t nrfx_nfct_parameter_set(nrfx_nfct_param_t const * p_param); - -/** - * @brief Function for getting default bytes for NFCID1. - * - * @param[in,out] p_nfcid1_buff In: empty buffer for data; - * Out: buffer with the NFCID1 default data. These values - * can be used to fill the Type 2 Tag Internal Bytes. - * @param[in] nfcid1_buff_len Length of the NFCID1 buffer. - * - * @retval NRFX_SUCCESS The operation was successful. - * @retval NRFX_ERROR_INVALID_LENGTH Length of the NFCID buffer is different than - * @ref NRFX_NFCT_NFCID1_SINGLE_SIZE, - * @ref NRFX_NFCT_NFCID1_DOUBLE_SIZE, or - * @ref NRFX_NFCT_NFCID1_TRIPLE_SIZE. - */ -nrfx_err_t nrfx_nfct_nfcid1_default_bytes_get(uint8_t * const p_nfcid1_buff, - uint32_t nfcid1_buff_len); - -/** - * @brief Function for enabling the automatic collision resolution. - * - * @details As defined by the NFC Forum Digital Protocol Technical Specification (and ISO 14443-3), - * the automatic collision resolution is implemented in the NFCT hardware. - * This function allows enabling and disabling this feature. - */ -void nrfx_nfct_autocolres_enable(void); - -/** - * @brief Function for disabling the automatic collision resolution. - * - * @details See also details in @ref nrfx_nfct_autocolres_enable. - */ -void nrfx_nfct_autocolres_disable(void); - -/** @} */ - - -void nrfx_nfct_irq_handler(void); - - -#ifdef __cplusplus -} -#endif - - -/** - * @defgroup nrfx_nfct_fixes NFCT driver fixes and workarounds - * @{ - * @ingroup nrf_nfct - * @brief Fixes for hardware-related anomalies. - * - * If you are using the nRF52832 chip, the workarounds for the following anomalies are applied: - * - 79. NFCT: A false EVENTS_FIELDDETECTED event occurs after the field is lost. - * - 116. NFCT does not release HFCLK when switching from ACTIVATED to SENSE mode. - * To implement the first workaround, an instance of NRF_TIMER is used. After the NFC field is detected, - * the timing module periodically polls its state to determine when the field is turned off. - * To implement the second workaround, power reset is used to release the clock acquired by NFCT - * after the field is turned off. Note that the NFCT register configuration is restored to defaults. - * - * If you are using the nRF52840 chip, rev. Engineering A, the workarounds for the following anomalies - * are applied: - * - 98. NFCT: The NFCT is not able to communicate with the peer. - * - 116. NFCT does not release HFCLK when switching from ACTIVATED to SENSE mode. - * - 144. NFCT: Not optimal NFC performance - * - * If you are using the nRF52840 chip, rev. 1, or rev. Engineering B or C, the workarounds for the following - * anomalies are applied: - * - 190. NFCT: Event FIELDDETECTED can be generated too early. - * To implement this workaround, an instance of NRF_TIMER is used. After the NFC field is detected, - * the timing module measures the necessary waiting period after which NFCT can be activated. - * This debouncing technique is used to filter possible field instabilities. - * - * The application of the implemented workarounds for the nRF52840 chip is determined at runtime and depends - * on the chip variant. - * - * The current code contains a patch for the anomaly 25 (NFCT: Reset value of - * SENSRES register is incorrect), so that the module now works on Windows Phone. - * @} - */ - -#endif // NRFX_NFCT_H__ diff --git a/modules/nrfx/drivers/include/nrfx_pdm.h b/modules/nrfx/drivers/include/nrfx_pdm.h deleted file mode 100644 index 2b8043d..0000000 --- a/modules/nrfx/drivers/include/nrfx_pdm.h +++ /dev/null @@ -1,207 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRFX_PDM_H__ -#define NRFX_PDM_H__ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrfx_pdm PDM driver - * @{ - * @ingroup nrf_pdm - * @brief Pulse Density Modulation (PDM) peripheral driver. - */ - -/** @brief Maximum supported PDM buffer size. */ -#define NRFX_PDM_MAX_BUFFER_SIZE 32767 - -/** @brief PDM error type. */ -typedef enum -{ - NRFX_PDM_NO_ERROR = 0, ///< No error. - NRFX_PDM_ERROR_OVERFLOW = 1 ///< Overflow error. -} nrfx_pdm_error_t; - -/** @brief PDM event structure. */ -typedef struct -{ - bool buffer_requested; ///< Buffer request flag. - int16_t * buffer_released; ///< Pointer to the released buffer. Can be NULL. - nrfx_pdm_error_t error; ///< Error type. -} nrfx_pdm_evt_t; - -/** @brief PDM interface driver configuration structure. */ -typedef struct -{ - nrf_pdm_mode_t mode; ///< Interface operation mode. - nrf_pdm_edge_t edge; ///< Sampling mode. - uint8_t pin_clk; ///< CLK pin. - uint8_t pin_din; ///< DIN pin. - nrf_pdm_freq_t clock_freq; ///< Clock frequency. - nrf_pdm_gain_t gain_l; ///< Left channel gain. - nrf_pdm_gain_t gain_r; ///< Right channel gain. - uint8_t interrupt_priority; ///< Interrupt priority. -} nrfx_pdm_config_t; - -/** - * @brief Macro for setting @ref nrfx_pdm_config_t to default settings - * in the single-ended mode. - * - * @param _pin_clk CLK output pin. - * @param _pin_din DIN input pin. - */ -#define NRFX_PDM_DEFAULT_CONFIG(_pin_clk, _pin_din) \ -{ \ - .mode = (nrf_pdm_mode_t)NRFX_PDM_CONFIG_MODE, \ - .edge = (nrf_pdm_edge_t)NRFX_PDM_CONFIG_EDGE, \ - .pin_clk = _pin_clk, \ - .pin_din = _pin_din, \ - .clock_freq = (nrf_pdm_freq_t)NRFX_PDM_CONFIG_CLOCK_FREQ, \ - .gain_l = NRF_PDM_GAIN_DEFAULT, \ - .gain_r = NRF_PDM_GAIN_DEFAULT, \ - .interrupt_priority = NRFX_PDM_CONFIG_IRQ_PRIORITY \ -} - -/** - * @brief Handler for the PDM interface ready events. - * - * This event handler is called on a buffer request, an error or when a buffer - * is full and ready to be processed. - * - * @param[in] p_evt Pointer to the PDM event structure. - */ -typedef void (*nrfx_pdm_event_handler_t)(nrfx_pdm_evt_t const * const p_evt); - - -/** - * @brief Function for initializing the PDM interface. - * - * @param[in] p_config Pointer to the structure with the initial configuration. - * @param[in] event_handler Event handler provided by the user. Cannot be NULL. - * - * @retval NRFX_SUCCESS Initialization was successful. - * @retval NRFX_ERROR_INVALID_STATE The driver is already initialized. - * @retval NRFX_ERROR_INVALID_PARAM Invalid configuration was specified. - */ -nrfx_err_t nrfx_pdm_init(nrfx_pdm_config_t const * p_config, - nrfx_pdm_event_handler_t event_handler); - -/** - * @brief Function for uninitializing the PDM interface. - * - * This function stops PDM sampling, if it is in progress. - */ -void nrfx_pdm_uninit(void); - -/** - * @brief Function for getting the address of a PDM interface task. - * - * @param[in] task Task. - * - * @return Task address. - */ -__STATIC_INLINE uint32_t nrfx_pdm_task_address_get(nrf_pdm_task_t task) -{ - return nrf_pdm_task_address_get(task); -} - -/** - * @brief Function for getting the state of the PDM interface. - * - * @retval true The PDM interface is enabled. - * @retval false The PDM interface is disabled. - */ -__STATIC_INLINE bool nrfx_pdm_enable_check(void) -{ - return nrf_pdm_enable_check(); -} - -/** - * @brief Function for starting the PDM sampling. - * - * @retval NRFX_SUCCESS Sampling was started successfully or was already in progress. - * @retval NRFX_ERROR_BUSY Previous start/stop operation is in progress. - */ -nrfx_err_t nrfx_pdm_start(void); - -/** - * @brief Function for stopping the PDM sampling. - * - * When this function is called, the PDM interface is stopped after finishing - * the current frame. - * The event handler function might be called once more after calling this function. - * - * @retval NRFX_SUCCESS Sampling was stopped successfully or was already stopped before. - * @retval NRFX_ERROR_BUSY Previous start/stop operation is in progress. - */ -nrfx_err_t nrfx_pdm_stop(void); - -/** - * @brief Function for supplying the sample buffer. - * - * Call this function after every buffer request event. - * - * @param[in] buffer Pointer to the receive buffer. Cannot be NULL. - * @param[in] buffer_length Length of the receive buffer in 16-bit words. - * - * @retval NRFX_SUCCESS The buffer was applied successfully. - * @retval NRFX_ERROR_BUSY The buffer was already supplied or the peripheral is currently being stopped. - * @retval NRFX_ERROR_INVALID_STATE The driver was not initialized. - * @retval NRFX_ERROR_INVALID_PARAM Invalid parameters were provided. - */ -nrfx_err_t nrfx_pdm_buffer_set(int16_t * buffer, uint16_t buffer_length); - -/** @} */ - - -void nrfx_pdm_irq_handler(void); - - -#ifdef __cplusplus -} -#endif - -#endif // NRFX_PDM_H__ diff --git a/modules/nrfx/drivers/include/nrfx_qdec.h b/modules/nrfx/drivers/include/nrfx_qdec.h deleted file mode 100644 index b83bfc5..0000000 --- a/modules/nrfx/drivers/include/nrfx_qdec.h +++ /dev/null @@ -1,198 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRFX_QDEC_H__ -#define NRFX_QDEC_H__ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrfx_qdec QDEC driver - * @{ - * @ingroup nrf_qdec - * @brief Quadrature Decoder (QDEC) peripheral driver. - */ - -/** @brief QDEC configuration structure. */ -typedef struct -{ - nrf_qdec_reportper_t reportper; /**< Report period in samples. */ - nrf_qdec_sampleper_t sampleper; /**< Sampling period in microseconds. */ - uint32_t psela; /**< Pin number for A input. */ - uint32_t pselb; /**< Pin number for B input. */ - uint32_t pselled; /**< Pin number for LED output. */ - uint32_t ledpre; /**< Time (in microseconds) how long LED is switched on before sampling. */ - nrf_qdec_ledpol_t ledpol; /**< Active LED polarity. */ - bool dbfen; /**< State of debouncing filter. */ - bool sample_inten; /**< Enabling sample ready interrupt. */ - uint8_t interrupt_priority; /**< QDEC interrupt priority. */ -} nrfx_qdec_config_t; - -/**@brief QDEC default configuration. */ -#define NRFX_QDEC_DEFAULT_CONFIG \ -{ \ - .reportper = (nrf_qdec_reportper_t)NRFX_QDEC_CONFIG_REPORTPER, \ - .sampleper = (nrf_qdec_sampleper_t)NRFX_QDEC_CONFIG_SAMPLEPER, \ - .psela = NRFX_QDEC_CONFIG_PIO_A, \ - .pselb = NRFX_QDEC_CONFIG_PIO_B, \ - .pselled = NRFX_QDEC_CONFIG_PIO_LED, \ - .ledpre = NRFX_QDEC_CONFIG_LEDPRE, \ - .ledpol = (nrf_qdec_ledpol_t)NRFX_QDEC_CONFIG_LEDPOL, \ - .dbfen = NRFX_QDEC_CONFIG_DBFEN, \ - .sample_inten = NRFX_QDEC_CONFIG_SAMPLE_INTEN, \ - .interrupt_priority = NRFX_QDEC_CONFIG_IRQ_PRIORITY, \ -} - -/** @brief QDEC sample event data. */ -typedef struct -{ - int8_t value; /**< Sample value. */ -} nrfx_qdec_sample_data_evt_t; - -/** @brief QDEC report event data. */ -typedef struct -{ - int16_t acc; /**< Accumulated transitions. */ - uint16_t accdbl; /**< Accumulated double transitions. */ -} nrfx_qdec_report_data_evt_t; - -/** @brief QDEC event handler structure. */ -typedef struct -{ - nrf_qdec_event_t type; /**< Event type. */ - union - { - nrfx_qdec_sample_data_evt_t sample; /**< Sample event data. */ - nrfx_qdec_report_data_evt_t report; /**< Report event data. */ - } data; /**< Union to store event data. */ -} nrfx_qdec_event_t; - -/** - * @brief QDEC event handler. - * - * @param[in] event QDEC event structure. - */ -typedef void (*nrfx_qdec_event_handler_t)(nrfx_qdec_event_t event); - -/** - * @brief Function for initializing QDEC. - * - * @param[in] p_config Pointer to the structure with the initial configuration. - * @param[in] event_handler Event handler provided by the user. - * Must not be NULL. - * - * @retval NRFX_SUCCESS Initialization was successful. - * @retval NRFX_ERROR_INVALID_STATE The QDEC was already initialized. - */ -nrfx_err_t nrfx_qdec_init(nrfx_qdec_config_t const * p_config, - nrfx_qdec_event_handler_t event_handler); - -/** - * @brief Function for uninitializing QDEC. - * - * @note Function asserts if module is uninitialized. - */ -void nrfx_qdec_uninit(void); - -/** - * @brief Function for enabling QDEC. - * - * @note Function asserts if module is uninitialized or enabled. - */ -void nrfx_qdec_enable(void); - -/** - * @brief Function for disabling QDEC. - * - * @note Function asserts if module is uninitialized or disabled. - */ -void nrfx_qdec_disable(void); - -/** - * @brief Function for reading accumulated transitions from the QDEC peripheral. - * - * @note Function asserts if module is not enabled. - * @note Accumulators are cleared after reading. - * - * @param[out] p_acc Pointer to store the accumulated transitions. - * @param[out] p_accdbl Pointer to store the accumulated double transitions. - */ -void nrfx_qdec_accumulators_read(int16_t * p_acc, int16_t * p_accdbl); - -/** - * @brief Function for returning the address of the specified QDEC task. - * - * @param task QDEC task. - * - * @return Task address. - */ -__STATIC_INLINE uint32_t nrfx_qdec_task_address_get(nrf_qdec_task_t task) -{ - return (uint32_t)nrf_qdec_task_address_get(task); -} - -/** - * @brief Function for returning the address of the specified QDEC event. - * - * @param event QDEC event. - * - * @return Event address. - */ -__STATIC_INLINE uint32_t nrfx_qdec_event_address_get(nrf_qdec_event_t event) -{ - return (uint32_t)nrf_qdec_event_address_get(event); -} - -/** @} */ - - -void nrfx_qdec_irq_handler(void); - - -#ifdef __cplusplus -} -#endif - -#endif // NRFX_QDEC_H__ diff --git a/modules/nrfx/drivers/include/nrfx_qspi.h b/modules/nrfx/drivers/include/nrfx_qspi.h deleted file mode 100644 index fbeec0d..0000000 --- a/modules/nrfx/drivers/include/nrfx_qspi.h +++ /dev/null @@ -1,330 +0,0 @@ -/** - * Copyright (c) 2016 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRFX_QSPI_H__ -#define NRFX_QSPI_H__ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrfx_qspi QSPI driver - * @{ - * @ingroup nrf_qspi - * @brief Quad Serial Peripheral Interface (QSPI) peripheral driver. - */ - -/** @brief QSPI driver instance configuration structure. */ -typedef struct -{ - uint32_t xip_offset; /**< Address offset into the external memory for Execute in Place operation. */ - nrf_qspi_pins_t pins; /**< Pin configuration structure. */ - nrf_qspi_prot_conf_t prot_if; /**< Protocol layer interface configuration structure. */ - nrf_qspi_phy_conf_t phy_if; /**< Physical layer interface configuration structure. */ - uint8_t irq_priority; /**< Interrupt priority. */ -} nrfx_qspi_config_t; - -/** @brief QSPI instance default configuration. */ -#define NRFX_QSPI_DEFAULT_CONFIG \ -{ \ - .xip_offset = NRFX_QSPI_CONFIG_XIP_OFFSET, \ - .pins = { \ - .sck_pin = NRFX_QSPI_PIN_SCK, \ - .csn_pin = NRFX_QSPI_PIN_CSN, \ - .io0_pin = NRFX_QSPI_PIN_IO0, \ - .io1_pin = NRFX_QSPI_PIN_IO1, \ - .io2_pin = NRFX_QSPI_PIN_IO2, \ - .io3_pin = NRFX_QSPI_PIN_IO3, \ - }, \ - .prot_if = { \ - .readoc = (nrf_qspi_readoc_t)NRFX_QSPI_CONFIG_READOC, \ - .writeoc = (nrf_qspi_writeoc_t)NRFX_QSPI_CONFIG_WRITEOC, \ - .addrmode = (nrf_qspi_addrmode_t)NRFX_QSPI_CONFIG_ADDRMODE, \ - .dpmconfig = false, \ - }, \ - .phy_if = { \ - .sck_delay = (uint8_t)NRFX_QSPI_CONFIG_SCK_DELAY, \ - .dpmen = false, \ - .spi_mode = (nrf_qspi_spi_mode_t)NRFX_QSPI_CONFIG_MODE, \ - .sck_freq = (nrf_qspi_frequency_t)NRFX_QSPI_CONFIG_FREQUENCY, \ - }, \ - .irq_priority = (uint8_t)NRFX_QSPI_CONFIG_IRQ_PRIORITY, \ -} - -/** @brief QSPI custom instruction helper with the default configuration. */ -#define NRFX_QSPI_DEFAULT_CINSTR(opc, len) \ -{ \ - .opcode = (opc), \ - .length = (len), \ - .io2_level = false, \ - .io3_level = false, \ - .wipwait = false, \ - .wren = false \ -} - -/** - * @brief QSPI master driver event types, passed to the handler routine provided - * during initialization. - */ -typedef enum -{ - NRFX_QSPI_EVENT_DONE, /**< Transfer done. */ -} nrfx_qspi_evt_t; - -/** @brief QSPI driver event handler type. */ -typedef void (*nrfx_qspi_handler_t)(nrfx_qspi_evt_t event, void * p_context); - -/** - * @brief Function for initializing the QSPI driver instance. - * - * This function configures the peripheral and its interrupts, and activates it. During the - * activation process, the internal clocks are started and the QSPI peripheral tries to read - * the status byte to read the busy bit. Reading the status byte is done in a simple poll and wait - * mechanism. - * If the busy bit is 1, this indicates issues with the external memory device. As a result, - * @ref nrfx_qspi_init returns NRFX_ERROR_TIMEOUT. - * - * In case of issues: - * - Check the connection. - * - Make sure that the memory device does not perform other operations like erasing or writing. - * - Check if there is a short circuit. - * - * @param[in] p_config Pointer to the structure with the initial configuration. - * @param[in] handler Event handler provided by the user. If NULL, transfers - * will be performed in blocking mode. - * @param[in] p_context Pointer to context. Use in the interrupt handler. - * - * @retval NRFX_SUCCESS Initialization was successful. - * @retval NRFX_ERROR_TIMEOUT The peripheral cannot connect with external memory. - * @retval NRFX_ERROR_INVALID_STATE The driver was already initialized. - * @retval NRFX_ERROR_INVALID_PARAM The pin configuration was incorrect. - */ -nrfx_err_t nrfx_qspi_init(nrfx_qspi_config_t const * p_config, - nrfx_qspi_handler_t handler, - void * p_context); - -/** @brief Function for uninitializing the QSPI driver instance. */ -void nrfx_qspi_uninit(void); - -/** - * @brief Function for reading data from the QSPI memory. - * - * Write, read, and erase operations check memory device busy state before starting the operation. - * If the memory is busy, the resulting action depends on the mode in which the read operation is used: - * - blocking mode (without handler) - a delay occurs until the last operation runs and - * until the operation data is being read. - * - interrupt mode (with handler) - event emission occurs after the last operation - * and reading of data are finished. - * - * @param[out] p_rx_buffer Pointer to the receive buffer. - * @param[in] rx_buffer_length Size of the data to read. - * @param[in] src_address Address in memory to read from. - * - * @retval NRFX_SUCCESS The operation was successful (blocking mode) or operation - * was commissioned (handler mode). - * @retval NRFX_ERROR_BUSY The driver currently handles another operation. - * @retval NRFX_ERROR_INVALID_ADDR The provided buffer is not placed in the Data RAM region - * or its address is not aligned to a 32-bit word. - */ -nrfx_err_t nrfx_qspi_read(void * p_rx_buffer, - size_t rx_buffer_length, - uint32_t src_address); - -/** - * @brief Function for writing data to QSPI memory. - * - * Write, read, and erase operations check memory device busy state before starting the operation. - * If the memory is busy, the resulting action depends on the mode in which the write operation is used: - * - blocking mode (without handler) - a delay occurs until the last operation runs or - * until the operation data is being sent. - * - interrupt mode (with handler) - event emission occurs after the last operation - * and sending of operation data are finished. - * To manually control operation execution in the memory device, use @ref nrfx_qspi_mem_busy_check - * after executing the write function. - * Remember that an incoming event signalizes only that data was sent to the memory device and the periheral - * before the write operation checked if memory was busy. - * - * @param[in] p_tx_buffer Pointer to the writing buffer. - * @param[in] tx_buffer_length Size of the data to write. - * @param[in] dst_address Address in memory to write to. - * - * @retval NRFX_SUCCESS The operation was successful (blocking mode) or operation - * was commissioned (handler mode). - * @retval NRFX_ERROR_BUSY The driver currently handles other operation. - * @retval NRFX_ERROR_INVALID_ADDR The provided buffer is not placed in the Data RAM region - * or its address is not aligned to a 32-bit word. - */ -nrfx_err_t nrfx_qspi_write(void const * p_tx_buffer, - size_t tx_buffer_length, - uint32_t dst_address); - -/** - * @brief Function for starting erasing of one memory block - 4KB, 64KB, or the whole chip. - * - * Write, read, and erase operations check memory device busy state before starting the operation. - * If the memory is busy, the resulting action depends on the mode in which the erase operation is used: - * - blocking mode (without handler) - a delay occurs until the last operation runs or - * until the operation data is being sent. - * - interrupt mode (with handler) - event emission occurs after the last operation - * and sending of operation data are finished. - * To manually control operation execution in the memory device, use @ref nrfx_qspi_mem_busy_check - * after executing the erase function. - * Remember that an incoming event signalizes only that data was sent to the memory device and the periheral - * before the erase operation checked if memory was busy. - * - * @param[in] length Size of data to erase. See @ref nrf_qspi_erase_len_t. - * @param[in] start_address Memory address to start erasing. If chip erase is performed, address - * field is ommited. - * - * @retval NRFX_SUCCESS The operation was successful (blocking mode) or operation - * was commissioned (handler mode). - * @retval NRFX_ERROR_INVALID_ADDR The provided start address is not aligned to a 32-bit word. - * @retval NRFX_ERROR_BUSY The driver currently handles another operation. - */ -nrfx_err_t nrfx_qspi_erase(nrf_qspi_erase_len_t length, - uint32_t start_address); - -/** - * @brief Function for starting an erase operation of the whole chip. - * - * @retval NRFX_SUCCESS The operation was successful (blocking mode) or operation - * was commissioned (handler mode). - * @retval NRFX_ERROR_BUSY The driver currently handles another operation. - */ -nrfx_err_t nrfx_qspi_chip_erase(void); - -/** - * @brief Function for getting the current driver status and status byte of memory device with - * testing WIP (write in progress) bit. - * - * @retval NRFX_SUCCESS The driver and memory are ready to handle a new operation. - * @retval NRFX_ERROR_BUSY The driver or memory currently handle another operation. - */ -nrfx_err_t nrfx_qspi_mem_busy_check(void); - -/** - * @brief Function for sending operation code, sending data, and receiving data from the memory device. - * - * Use this function to transfer configuration data to memory and to receive data from memory. - * Pointers can be addresses from flash memory. - * This function is a synchronous function and should be used only if necessary. - * - * @param[in] p_config Pointer to the structure with opcode and transfer configuration. - * @param[in] p_tx_buffer Pointer to the array with data to send. Can be NULL if only opcode is transmitted. - * @param[out] p_rx_buffer Pointer to the array for data to receive. Can be NULL if there is nothing to receive. - * - * @retval NRFX_SUCCESS The operation was successful. - * @retval NRFX_ERROR_TIMEOUT The external memory is busy or there are connection issues. - * @retval NRFX_ERROR_BUSY The driver currently handles other operation. - */ -nrfx_err_t nrfx_qspi_cinstr_xfer(nrf_qspi_cinstr_conf_t const * p_config, - void const * p_tx_buffer, - void * p_rx_buffer); - -/** - * @brief Function for sending operation code and data to the memory device with simpler configuration. - * - * Use this function to transfer configuration data to memory and to receive data from memory. - * This function is a synchronous function and should be used only if necessary. - * - * @param[in] opcode Operation code. Sending first. - * @param[in] length Length of the data to send and opcode. See @ref nrf_qspi_cinstr_len_t. - * @param[in] p_tx_buffer Pointer to input data array. - * - * @retval NRFX_SUCCESS The operation was successful. - * @retval NRFX_ERROR_BUSY The driver currently handles another operation. - */ -nrfx_err_t nrfx_qspi_cinstr_quick_send(uint8_t opcode, - nrf_qspi_cinstr_len_t length, - void const * p_tx_buffer); - -/** - * @brief Function for starting the custom instruction long frame mode. - * - * The long frame mode is a mechanism that allows for arbitrary byte length custom instructions. - * Use this function to initiate a custom transaction by sending custom instruction opcode. - * To send and receive data, use @ref nrfx_qspi_lfm_xfer. - * - * @param[in] p_config Pointer to the structure with custom instruction opcode and transfer - * configuration. Transfer length must be set to @ref NRF_QSPI_CINSTR_LEN_1B. - * - * @retval NRFX_SUCCESS Operation was successful. - * @retval NRFX_ERROR_BUSY Driver currently handles other operation. - * @retval NRFX_ERROR_TIMEOUT External memory is busy or there are connection issues. - */ -nrfx_err_t nrfx_qspi_lfm_start(nrf_qspi_cinstr_conf_t const * p_config); - -/** - * @brief Function for sending and receiving data in the custom instruction long frame mode. - * - * Both specified buffers must be at least @p transfer_length bytes in size. - * - * @param[in] p_tx_buffer Pointer to the array with data to send. - * Can be NULL if there is nothing to send. - * @param[out] p_rx_buffer Pointer to the array for receiving data. - * Can be NULL if there is nothing to receive. - * @param[in] transfer_length Number of bytes to send and receive. - * @param[in] finalize True if custom instruction long frame mode is to be finalized - * after this transfer. - * - * @retval NRFX_SUCCESS Operation was successful. - * @retval NRFX_ERROR_TIMEOUT External memory is busy or there are connection issues. - * Long frame mode becomes deactivated. - */ -nrfx_err_t nrfx_qspi_lfm_xfer(void const * p_tx_buffer, - void * p_rx_buffer, - size_t transfer_length, - bool finalize); - -/** @} */ - - -void nrfx_qspi_irq_handler(void); - - -#ifdef __cplusplus -} -#endif - -#endif // NRFX_QSPI_H__ diff --git a/modules/nrfx/drivers/include/nrfx_spis.h b/modules/nrfx/drivers/include/nrfx_spis.h deleted file mode 100644 index 2ec37a0..0000000 --- a/modules/nrfx/drivers/include/nrfx_spis.h +++ /dev/null @@ -1,256 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRFX_SPIS_H__ -#define NRFX_SPIS_H__ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrfx_spis SPIS driver - * @{ - * @ingroup nrf_spis - * @brief Serial Peripheral Interface Slave with EasyDMA (SPIS) driver. - */ - -/** @brief Data structure for the Serial Peripheral Interface Slave with EasyDMA (SPIS) driver instance. */ -typedef struct -{ - NRF_SPIS_Type * p_reg; //!< Pointer to a structure with SPIS registers. - uint8_t drv_inst_idx; //!< Index of the driver instance. For internal use only. -} nrfx_spis_t; - -#ifndef __NRFX_DOXYGEN__ -enum { -#if NRFX_CHECK(NRFX_SPIS0_ENABLED) - NRFX_SPIS0_INST_IDX, -#endif -#if NRFX_CHECK(NRFX_SPIS1_ENABLED) - NRFX_SPIS1_INST_IDX, -#endif -#if NRFX_CHECK(NRFX_SPIS2_ENABLED) - NRFX_SPIS2_INST_IDX, -#endif -#if NRFX_CHECK(NRFX_SPIS3_ENABLED) - NRFX_SPIS3_INST_IDX, -#endif - NRFX_SPIS_ENABLED_COUNT -}; -#endif - -/** @brief Macro for creating an instance of the SPI slave driver. */ -#define NRFX_SPIS_INSTANCE(id) \ -{ \ - .p_reg = NRFX_CONCAT_2(NRF_SPIS, id), \ - .drv_inst_idx = NRFX_CONCAT_3(NRFX_SPIS, id, _INST_IDX), \ -} - -/** - * @brief This value can be provided instead of a pin number for the signals MOSI - * and MISO to specify that the given signal is not used and therefore - * does not need to be connected to a pin. - */ -#define NRFX_SPIS_PIN_NOT_USED 0xFF - -/** @brief Default pull-up configuration of the SPI CS. */ -#define NRFX_SPIS_DEFAULT_CSN_PULLUP NRF_GPIO_PIN_NOPULL -/** @brief Default drive configuration of the SPI MISO. */ -#define NRFX_SPIS_DEFAULT_MISO_DRIVE NRF_GPIO_PIN_S0S1 - -/** @brief SPI slave driver event types. */ -typedef enum -{ - NRFX_SPIS_BUFFERS_SET_DONE, //!< Memory buffer set event. Memory buffers have been set successfully to the SPI slave device, and SPI transaction can be done. - NRFX_SPIS_XFER_DONE, //!< SPI transaction event. SPI transaction has been completed. - NRFX_SPIS_EVT_TYPE_MAX //!< Enumeration upper bound. -} nrfx_spis_evt_type_t; - -/** @brief SPI slave driver event structure. */ -typedef struct -{ - nrfx_spis_evt_type_t evt_type; //!< Type of the event. - size_t rx_amount; //!< Number of bytes received in the last transaction. This parameter is only valid for @ref NRFX_SPIS_XFER_DONE events. - size_t tx_amount; //!< Number of bytes transmitted in the last transaction. This parameter is only valid for @ref NRFX_SPIS_XFER_DONE events. -} nrfx_spis_evt_t; - -/** @brief The default configuration of the SPI slave instance. */ -#define NRFX_SPIS_DEFAULT_CONFIG \ -{ \ - .miso_pin = NRFX_SPIS_PIN_NOT_USED, \ - .mosi_pin = NRFX_SPIS_PIN_NOT_USED, \ - .sck_pin = NRFX_SPIS_PIN_NOT_USED, \ - .csn_pin = NRFX_SPIS_PIN_NOT_USED, \ - .mode = NRF_SPIS_MODE_0, \ - .bit_order = NRF_SPIS_BIT_ORDER_MSB_FIRST, \ - .csn_pullup = NRFX_SPIS_DEFAULT_CSN_PULLUP, \ - .miso_drive = NRFX_SPIS_DEFAULT_MISO_DRIVE, \ - .def = NRFX_SPIS_DEFAULT_DEF, \ - .orc = NRFX_SPIS_DEFAULT_ORC, \ - .irq_priority = NRFX_SPIS_DEFAULT_CONFIG_IRQ_PRIORITY, \ -} - -/** @brief SPI peripheral device configuration data. */ -typedef struct -{ - uint32_t miso_pin; //!< SPI MISO pin (optional). - /**< Set @ref NRFX_SPIS_PIN_NOT_USED - * if this signal is not needed. */ - uint32_t mosi_pin; //!< SPI MOSI pin (optional). - /**< Set @ref NRFX_SPIS_PIN_NOT_USED - * if this signal is not needed. */ - uint32_t sck_pin; //!< SPI SCK pin. - uint32_t csn_pin; //!< SPI CSN pin. - nrf_spis_mode_t mode; //!< SPI mode. - nrf_spis_bit_order_t bit_order; //!< SPI transaction bit order. - nrf_gpio_pin_pull_t csn_pullup; //!< CSN pin pull-up configuration. - nrf_gpio_pin_drive_t miso_drive; //!< MISO pin drive configuration. - uint8_t def; //!< Character clocked out in case of an ignored transaction. - uint8_t orc; //!< Character clocked out after an over-read of the transmit buffer. - uint8_t irq_priority; //!< Interrupt priority. -} nrfx_spis_config_t; - - -/** - * @brief SPI slave driver event handler type. - * - * @param[in] p_event Pointer to the event structure. The structure is - * allocated on the stack so it is valid only until - * the event handler returns. - * @param[in] p_context Context set on initialization. - */ -typedef void (*nrfx_spis_event_handler_t)(nrfx_spis_evt_t const * p_event, - void * p_context); - -/** - * @brief Function for initializing the SPI slave driver instance. - * - * @note When the nRF52 Anomaly 109 workaround for SPIS is enabled, this function - * initializes the GPIOTE driver as well, and uses one of GPIOTE channels - * to detect falling edges on CSN pin. - * - * @param[in] p_instance Pointer to the driver instance structure. - * @param[in] p_config Pointer to the structure with the initial configuration. - * @param[in] event_handler Function to be called by the SPI slave driver upon event. - * Must not be NULL. - * @param[in] p_context Context passed to the event handler. - * - * @retval NRFX_SUCCESS The initialization was successful. - * @retval NRFX_ERROR_INVALID_STATE The instance is already initialized. - * @retval NRFX_ERROR_INVALID_PARAM Invalid parameter is supplied. - * @retval NRFX_ERROR_BUSY Some other peripheral with the same - * instance ID is already in use. This is - * possible only if @ref nrfx_prs module - * is enabled. - * @retval NRFX_ERROR_INTERNAL GPIOTE channel for detecting falling edges - * on CSN pin cannot be initialized. Possible - * only when using nRF52 Anomaly 109 workaround. - */ -nrfx_err_t nrfx_spis_init(nrfx_spis_t const * const p_instance, - nrfx_spis_config_t const * p_config, - nrfx_spis_event_handler_t event_handler, - void * p_context); - -/** - * @brief Function for uninitializing the SPI slave driver instance. - * - * @param[in] p_instance Pointer to the driver instance structure. - */ -void nrfx_spis_uninit(nrfx_spis_t const * const p_instance); - -/** - * @brief Function for preparing the SPI slave instance for a single SPI transaction. - * - * This function prepares the SPI slave device to be ready for a single SPI transaction. It configures - * the SPI slave device to use the memory supplied with the function call in SPI transactions. - * - * When either the memory buffer configuration or the SPI transaction has been - * completed, the event callback function will be called with the appropriate event - * @ref nrfx_spis_evt_type_t. The callback function can be called before returning from - * this function, because it is called from the SPI slave interrupt context. - * - * @note This function can be called from the callback function context. - * - * @note Client applications must call this function after every @ref NRFX_SPIS_XFER_DONE event if - * the SPI slave driver must be prepared for a possible new SPI transaction. - * - * @note Peripherals using EasyDMA (including SPIS) require the transfer buffers - * to be placed in the Data RAM region. If this condition is not met, - * this function will fail with the error code NRFX_ERROR_INVALID_ADDR. - * - * @param[in] p_instance Pointer to the driver instance structure. - * @param[in] p_tx_buffer Pointer to the TX buffer. Can be NULL when the buffer length is zero. - * @param[in] p_rx_buffer Pointer to the RX buffer. Can be NULL when the buffer length is zero. - * @param[in] tx_buffer_length Length of the TX buffer in bytes. - * @param[in] rx_buffer_length Length of the RX buffer in bytes. - * - * @retval NRFX_SUCCESS The operation was successful. - * @retval NRFX_ERROR_INVALID_STATE The operation failed because the SPI slave device is in an incorrect state. - * @retval NRFX_ERROR_INVALID_ADDR The provided buffers are not placed in the Data - * RAM region. - * @retval NRFX_ERROR_INVALID_LENGTH Provided lengths exceed the EasyDMA limits for the peripheral. - * @retval NRFX_ERROR_INTERNAL The operation failed because of an internal error. - */ -nrfx_err_t nrfx_spis_buffers_set(nrfx_spis_t const * const p_instance, - uint8_t const * p_tx_buffer, - size_t tx_buffer_length, - uint8_t * p_rx_buffer, - size_t rx_buffer_length); - -/** @} */ - - -void nrfx_spis_0_irq_handler(void); -void nrfx_spis_1_irq_handler(void); -void nrfx_spis_2_irq_handler(void); -void nrfx_spis_3_irq_handler(void); - - -#ifdef __cplusplus -} -#endif - -#endif // NRFX_SPIS_H__ - diff --git a/modules/nrfx/drivers/include/nrfx_swi.h b/modules/nrfx/drivers/include/nrfx_swi.h deleted file mode 100644 index ebd2315..0000000 --- a/modules/nrfx/drivers/include/nrfx_swi.h +++ /dev/null @@ -1,245 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRFX_SWI_H__ -#define NRFX_SWI_H__ - -#include - -#if NRFX_CHECK(NRFX_EGU_ENABLED) -#include -#endif - -#ifndef SWI_COUNT -#define SWI_COUNT EGU_COUNT -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrfx_swi SWI driver - * @{ - * @ingroup nrf_swi_egu - * - * @brief Driver for managing software interrupts (SWI). - */ - -/** @brief SWI instance. */ -typedef uint8_t nrfx_swi_t; - -/** - * @brief SWI user flags. - * - * User flags are set during the SWI trigger and passed to the callback function as an argument. - */ -typedef uint16_t nrfx_swi_flags_t; - -/** @brief Unallocated instance value. */ -#define NRFX_SWI_UNALLOCATED ((nrfx_swi_t)0xFFuL) - -/** @brief Default SWI priority. */ -#define NRFX_SWI_DEFAULT_PRIORITY APP_IRQ_PRIORITY_LOWEST - -/** - * @brief SWI handler function. - * - * @param swi SWI instance. - * @param flags User flags. - */ -typedef void (*nrfx_swi_handler_t)(nrfx_swi_t swi, nrfx_swi_flags_t flags); - -/** - * @brief Function for allocating the first unused SWI instance and setting a handler. - * - * If provided handler is not NULL, an allocated SWI has its interrupt enabled by default. - * The interrupt can be disabled by @ref nrfx_swi_int_disable. - * - * @param[out] p_swi Points to a place where the allocated SWI instance - * number is to be stored. - * @param[in] event_handler Event handler function. - * If NULL, no interrupt will be enabled. - * It can be NULL only if the EGU driver is enabled. - * For classic SWI, it must be a valid handler pointer. - * @param[in] irq_priority Interrupt priority. - * - * @retval NRFX_SUCCESS The SWI was successfully allocated. - * @retval NRFX_ERROR_NO_MEM There is no available SWI to be used. - */ -nrfx_err_t nrfx_swi_alloc(nrfx_swi_t * p_swi, - nrfx_swi_handler_t event_handler, - uint32_t irq_priority); - -/** - * @brief Function for disabling an allocated SWI interrupt. - * - * Use @ref nrfx_swi_int_enable to re-enable the interrupt. - * - * @param[in] swi SWI instance. - */ -void nrfx_swi_int_disable(nrfx_swi_t swi); - -/** - * @brief Function for enabling an allocated SWI interrupt. - * - * @param[in] swi SWI instance. - */ -void nrfx_swi_int_enable(nrfx_swi_t swi); - -/** - * @brief Function for freeing a previously allocated SWI. - * - * @param[in,out] p_swi SWI instance to free. The value is changed to - * @ref NRFX_SWI_UNALLOCATED on success. - */ -void nrfx_swi_free(nrfx_swi_t * p_swi); - -/** @brief Function for freeing all allocated SWIs. */ -void nrfx_swi_all_free(void); - -/** - * @brief Function for triggering the SWI. - * - * @param[in] swi SWI to trigger. - * @param[in] flag_number Number of user flag to trigger. - */ -void nrfx_swi_trigger(nrfx_swi_t swi, - uint8_t flag_number); - -/** - * @brief Function for checking if the specified SWI is currently allocated. - * - * @param[in] swi SWI instance. - * - * @retval true The SWI instance is allocated. - * @retval false The SWI instance is not allocated. - */ -bool nrfx_swi_is_allocated(nrfx_swi_t swi); - -#if NRFX_CHECK(NRFX_EGU_ENABLED) || defined(__NRFX_DOXYGEN__) - -/** - * @brief Function for returning the base address of the EGU peripheral - * associated with the specified SWI instance. - * - * @param[in] swi SWI instance. - * - * @return EGU base address or NULL if the specified SWI instance number - * is too high. - */ -__STATIC_INLINE NRF_EGU_Type * nrfx_swi_egu_instance_get(nrfx_swi_t swi) -{ -#if (EGU_COUNT < SWI_COUNT) - if (swi >= EGU_COUNT) - { - return NULL; - } -#endif - uint32_t offset = ((uint32_t)swi) * ((uint32_t)NRF_EGU1 - (uint32_t)NRF_EGU0); - return (NRF_EGU_Type *)((uint32_t)NRF_EGU0 + offset); -} - -/** - * @brief Function for returning the EGU trigger task address. - * - * @param[in] swi SWI instance. - * @param[in] channel Number of the EGU channel. - * - * @return Address of the EGU trigger task. - */ -__STATIC_INLINE uint32_t nrfx_swi_task_trigger_address_get(nrfx_swi_t swi, - uint8_t channel) -{ - NRFX_ASSERT(nrfx_swi_is_allocated(swi)); - - NRF_EGU_Type * p_egu = nrfx_swi_egu_instance_get(swi); -#if (EGU_COUNT < SWI_COUNT) - if (p_egu == NULL) - { - return 0; - } -#endif - - return (uint32_t)nrf_egu_task_trigger_address_get(p_egu, channel); -} - -/** - * @brief Function for returning the EGU-triggered event address. - * - * @param[in] swi SWI instance. - * @param[in] channel Number of the EGU channel. - * - * @return Address of the EGU-triggered event. - */ -__STATIC_INLINE uint32_t nrfx_swi_event_triggered_address_get(nrfx_swi_t swi, - uint8_t channel) -{ - NRFX_ASSERT(nrfx_swi_is_allocated(swi)); - - NRF_EGU_Type * p_egu = nrfx_swi_egu_instance_get(swi); -#if (EGU_COUNT < SWI_COUNT) - if (p_egu == NULL) - { - return 0; - } -#endif - - return (uint32_t)nrf_egu_event_triggered_address_get(p_egu, channel); -} - -#endif // NRFX_CHECK(NRFX_EGU_ENABLED) || defined(__NRFX_DOXYGEN__) - -/** @} */ - - -void nrfx_swi_0_irq_handler(void); -void nrfx_swi_1_irq_handler(void); -void nrfx_swi_2_irq_handler(void); -void nrfx_swi_3_irq_handler(void); -void nrfx_swi_4_irq_handler(void); -void nrfx_swi_5_irq_handler(void); - - -#ifdef __cplusplus -} -#endif - -#endif // NRFX_SWI_H__ diff --git a/modules/nrfx/drivers/include/nrfx_systick.h b/modules/nrfx/drivers/include/nrfx_systick.h deleted file mode 100644 index 0a02b7a..0000000 --- a/modules/nrfx/drivers/include/nrfx_systick.h +++ /dev/null @@ -1,135 +0,0 @@ -/** - * Copyright (c) 2016 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRFX_SYSTICK_H__ -#define NRFX_SYSTICK_H__ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrfx_systick ARM(R) SysTick driver - * @{ - * @ingroup nrf_systick - * - * @brief ARM(R) SysTick driver. - * - * This driver configures ARM(R) SysTick as a free-running timer. - * This timer is used to generate delays and pool for timeouts. - * Only relatively short timeouts are supported. - * The SysTick works on 64MHz and is 24-bit wide. - * This means that it overflows around 4 times per second and - * around 250 microseconds will be the highest supported time in the library. - * As it is hard to detect if the overflow is generated without - * using interrupts, the maximum delay range is halved for safety reasons. - */ - -/** - * @brief The value type that holds the SysTick state. - * - * This variable is used to count the requested timeout. - * @sa nrfx_systick_get - */ -typedef struct { - uint32_t time; //!< Registered time value. -} nrfx_systick_state_t; - -/** - * @brief Function for configuring and starting the timer. - * - * Function configures SysTick as a free-running timer without interrupt. - */ -void nrfx_systick_init(void); - -/** - * @brief Function for getting the current SysTick state. - * - * Function gets the current state of the SysTick timer. - * It can be used to check time-out by @ref nrfx_systick_test. - * - * @param[out] p_state The pointer to the state variable to be filled. - */ -void nrfx_systick_get(nrfx_systick_state_t * p_state); - -/** - * @brief Function for testing if the current time is higher in relation to the remembered state. - * - * @param[in] p_state Remembered state set by @ref nrfx_systick_get - * @param[in] us Required time-out. - * - * @retval true The current time is higher than the specified state plus the given time-out. - * @retval false The current time is lower than the specified state plus the given time-out. - */ -bool nrfx_systick_test(nrfx_systick_state_t const * p_state, uint32_t us); - -/** - * @brief Function for delaying the execution for the specified amount of CPU ticks. - * - * @param[in] ticks Number of CPU ticks when the execution is blocked. - */ -void nrfx_systick_delay_ticks(uint32_t ticks); - -/** - * @brief Function for delaying the execution for the specified amount of microseconds. - * - * @param[in] us Number of microseconds when the execution is blocked. - */ -void nrfx_systick_delay_us(uint32_t us); - -/** - * @brief Function for delaying the execution for the specified amount of milliseconds. - * - * This delay function removes the limits of the highest possible delay value. - * - * @param[in] ms Number of milliseconds when the execution is blocked. - */ -void nrfx_systick_delay_ms(uint32_t ms); - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif /* NRFX_SYSTICK_H__ */ diff --git a/modules/nrfx/drivers/include/nrfx_temp.h b/modules/nrfx/drivers/include/nrfx_temp.h deleted file mode 100644 index ebc39c8..0000000 --- a/modules/nrfx/drivers/include/nrfx_temp.h +++ /dev/null @@ -1,162 +0,0 @@ -/** - * Copyright (c) 2019 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRFX_TEMP_H__ -#define NRFX_TEMP_H__ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrfx_temp TEMP driver - * @{ - * @ingroup nrf_temp - * @brief Temperature sensor (TEMP) driver. - */ - -/** @brief Structure for TEMP configuration. */ -typedef struct -{ - uint8_t interrupt_priority; /**< Interrupt priority. */ -} nrfx_temp_config_t; - -/** @brief TEMP default configuration. */ -#define NRFX_TEMP_DEFAULT_CONFIG \ - { \ - .interrupt_priority = NRFX_TEMP_DEFAULT_CONFIG_IRQ_PRIORITY, \ - } - -/** - * @brief TEMP driver data ready handler type. - * - * @param temperature Raw temperature in a 2's complement signed value - * representation. This value can be converted to Celsius - * scale using the @ref nrfx_temp_calculate() function. - */ -typedef void (* nrfx_temp_data_handler_t)(int32_t raw_temperature); - -/** - * @brief Function for initializing the TEMP driver. - * - * @param[in] p_config Pointer to the structure with initial configuration. - * @param[in] handler Data handler provided by the user. If not provided, - * the driver is initialized in blocking mode. - * - * @retval NRFX_SUCCESS Driver was successfully initialized. - * @retval NRFX_ERROR_ALREADY_INITIALIZED Driver was already initialized. - */ -nrfx_err_t nrfx_temp_init(nrfx_temp_config_t const * p_config, nrfx_temp_data_handler_t handler); - -/** @brief Function for uninitializing the TEMP driver. */ -void nrfx_temp_uninit(void); - -/** - * @brief Function for getting the temperature measurement in a 2's complement - * signed value representation. - * - * This function returns the last value prepared by the TEMP peripheral. - * In blocking mode, it should be used after calling the @ref nrfx_temp_measure() - * function. In non-blocking mode, it is called internally by the driver, - * and the value it returns is passed to the data handler. - * - * @return Temperature measurement result in a 2's complement signed value - * representation. - */ -__STATIC_INLINE int32_t nrfx_temp_result_get(void); - -/** - * @brief Function for calculating the temperature value in Celsius scale from raw data. - * - * The returned temperature value is in Celsius scale, multiplied by 100 - * For example, the actual temperature of 25.75[C] will be returned as a 2575 signed integer. - * Measurement accuracy is 0.25[C]. - * - * @param[in] raw_measurement Temperature value in a 2's complement signed - * value representation. - * - * @return Temperature measurement result. - */ -int32_t nrfx_temp_calculate(int32_t raw_measurement); - -/** - * @brief Function for starting the temperature measurement. - * - * Non-blocking mode: - * This function returns immediately. After a measurement, the handler specified - * during initialization is called, with measurement result as the parameter. - * - * Blocking mode: - * This function waits until the measurement is finished. The value should be read - * using the @ref nrfx_temp_result_get() function. - * - * @retval NRFX_SUCCESS In non-blocking mode: Measurement was started. - * An interrupt will be generated soon.
- * In blocking mode: - * Measurement was started and finished. Data can - * be read using the @ref nrfx_temp_result_get() function. - * @retval NRFX_ERROR_INTERNAL In non-blocking mode: - * Not applicable.
- * In blocking mode: - * Measurement data ready event did not occur. - */ -nrfx_err_t nrfx_temp_measure(void); - -#ifndef SUPPRESS_INLINE_IMPLEMENTATION - -__STATIC_INLINE int32_t nrfx_temp_result_get(void) -{ - return nrf_temp_result_get(NRF_TEMP); -} - -#endif // SUPPRESS_INLINE_IMPLEMENTATION - -/** @} */ - -void nrfx_temp_irq_handler(void); - -#ifdef __cplusplus -} -#endif - -#endif // NRFX_TEMP_H__ diff --git a/modules/nrfx/drivers/include/nrfx_twis.h b/modules/nrfx/drivers/include/nrfx_twis.h deleted file mode 100644 index 3336666..0000000 --- a/modules/nrfx/drivers/include/nrfx_twis.h +++ /dev/null @@ -1,403 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRFX_TWIS_H__ -#define NRFX_TWIS_H__ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrfx_twis TWIS driver - * @{ - * @ingroup nrf_twis - * @brief Two Wire Interface Slave with EasyDMA (TWIS) peripheral driver. - */ - -/** @brief TWIS driver instance data structure. */ -typedef struct -{ - NRF_TWIS_Type * p_reg; ///< Pointer to a structure with TWIS registers. - uint8_t drv_inst_idx; ///< Index of the driver instance. For internal use only. -} nrfx_twis_t; - -#ifndef __NRFX_DOXYGEN__ -enum { -#if NRFX_CHECK(NRFX_TWIS0_ENABLED) - NRFX_TWIS0_INST_IDX, -#endif -#if NRFX_CHECK(NRFX_TWIS1_ENABLED) - NRFX_TWIS1_INST_IDX, -#endif -#if NRFX_CHECK(NRFX_TWIS2_ENABLED) - NRFX_TWIS2_INST_IDX, -#endif -#if NRFX_CHECK(NRFX_TWIS3_ENABLED) - NRFX_TWIS3_INST_IDX, -#endif - NRFX_TWIS_ENABLED_COUNT -}; -#endif - -/** @brief Macro for creating a TWIS driver instance. */ -#define NRFX_TWIS_INSTANCE(id) \ -{ \ - .p_reg = NRFX_CONCAT_2(NRF_TWIS, id), \ - .drv_inst_idx = NRFX_CONCAT_3(NRFX_TWIS, id, _INST_IDX), \ -} - -/** @brief Event callback function event definitions. */ -typedef enum -{ - NRFX_TWIS_EVT_READ_REQ, ///< Read request detected. - /**< If there is no buffer prepared, buf_req flag in the even will be set. - Call then @ref nrfx_twis_tx_prepare to give parameters for buffer. - */ - NRFX_TWIS_EVT_READ_DONE, ///< Read request finished - free any data. - NRFX_TWIS_EVT_READ_ERROR, ///< Read request finished with error. - NRFX_TWIS_EVT_WRITE_REQ, ///< Write request detected. - /**< If there is no buffer prepared, buf_req flag in the even will be set. - Call then @ref nrfx_twis_rx_prepare to give parameters for buffer. - */ - NRFX_TWIS_EVT_WRITE_DONE, ///< Write request finished - process data. - NRFX_TWIS_EVT_WRITE_ERROR, ///< Write request finished with error. - NRFX_TWIS_EVT_GENERAL_ERROR ///< Error that happens not inside WRITE or READ transaction. -} nrfx_twis_evt_type_t; - -/** - * @brief Possible error sources. - * - * This is flag enum - values from this enum can be connected using logical or operator. - * @note - * You can use directly @ref nrf_twis_error_t. Error type enum is redefined here because - * of possible future extension (eg. supporting timeouts and synchronous mode). - */ -typedef enum -{ - NRFX_TWIS_ERROR_OVERFLOW = NRF_TWIS_ERROR_OVERFLOW, /**< RX buffer overflow detected, and prevented. */ - NRFX_TWIS_ERROR_DATA_NACK = NRF_TWIS_ERROR_DATA_NACK, /**< NACK sent after receiving a data byte. */ - NRFX_TWIS_ERROR_OVERREAD = NRF_TWIS_ERROR_OVERREAD, /**< TX buffer over-read detected, and prevented. */ - NRFX_TWIS_ERROR_UNEXPECTED_EVENT = 1 << 8 /**< Unexpected event detected by state machine. */ -} nrfx_twis_error_t; - -/** @brief TWIS driver event structure. */ -typedef struct -{ - nrfx_twis_evt_type_t type; ///< Event type. - union - { - bool buf_req; ///< Flag for @ref NRFX_TWIS_EVT_READ_REQ and @ref NRFX_TWIS_EVT_WRITE_REQ. - /**< Information if transmission buffer requires to be prepared. */ - uint32_t tx_amount; ///< Data for @ref NRFX_TWIS_EVT_READ_DONE. - uint32_t rx_amount; ///< Data for @ref NRFX_TWIS_EVT_WRITE_DONE. - uint32_t error; ///< Data for @ref NRFX_TWIS_EVT_GENERAL_ERROR. - } data; ///< Union to store event data. -} nrfx_twis_evt_t; - -/** - * @brief TWI slave event callback function type. - * - * @param[in] p_event Event information structure. - */ -typedef void (*nrfx_twis_event_handler_t)(nrfx_twis_evt_t const * p_event); - -/** @brief Structure for TWIS configuration. */ -typedef struct -{ - uint32_t addr[2]; //!< Set addresses that this slave should respond. Set 0 to disable. - uint32_t scl; //!< SCL pin number. - uint32_t sda; //!< SDA pin number. - nrf_gpio_pin_pull_t scl_pull; //!< SCL pin pull. - nrf_gpio_pin_pull_t sda_pull; //!< SDA pin pull. - uint8_t interrupt_priority; //!< The priority of interrupt for the module to be set. -} nrfx_twis_config_t; - -/** @brief Generate the default configuration for the TWIS driver instance. */ -#define NRFX_TWIS_DEFAULT_CONFIG \ -{ \ - .addr = { NRFX_TWIS_DEFAULT_CONFIG_ADDR0, \ - NRFX_TWIS_DEFAULT_CONFIG_ADDR1 }, \ - .scl = 31, \ - .sda = 31, \ - .scl_pull = (nrf_gpio_pin_pull_t)NRFX_TWIS_DEFAULT_CONFIG_SCL_PULL, \ - .sda_pull = (nrf_gpio_pin_pull_t)NRFX_TWIS_DEFAULT_CONFIG_SDA_PULL, \ - .interrupt_priority = NRFX_TWIS_DEFAULT_CONFIG_IRQ_PRIORITY \ -} - -/** - * @brief Function for initializing the TWIS driver instance. - * - * Function initializes and enables the TWIS driver. - * @attention After driver initialization enable it with @ref nrfx_twis_enable. - * - * @param[in] p_instance Pointer to the driver instance structure. - * @attention @em p_instance has to be global object. - * It will be used by interrupts so make it sure that object - * is not destroyed when function is leaving. - * @param[in] p_config Pointer to the structure with the initial configuration. - * @param[in] event_handler Event handler provided by the user. - * - * @retval NRFX_SUCCESS Initialization is successful. - * @retval NRFX_ERROR_INVALID_STATE The driver is already initialized. - * @retval NRFX_ERROR_BUSY Some other peripheral with the same - * instance ID is already in use. This is - * possible only if NRFX_PRS_ENABLED - * is set to a value other than zero. - */ -nrfx_err_t nrfx_twis_init(nrfx_twis_t const * p_instance, - nrfx_twis_config_t const * p_config, - nrfx_twis_event_handler_t event_handler); - -/** - * @brief Function for uninitializing the TWIS driver instance. - * - * Function uninitializes the peripheral and resets all registers to default values. - * - * @note - * It is safe to call nrfx_twis_uninit even before initialization. - * Actually, @ref nrfx_twis_init function calls this function to - * make sure that TWIS state is known. - * @note - * If TWIS driver was in uninitialized state before calling this function, - * the selected pins would not be reset to default configuration. - * - * @param[in] p_instance Pointer to the driver instance structure. - */ -void nrfx_twis_uninit(nrfx_twis_t const * p_instance); - -/** - * @brief Function for enabling the TWIS instance. - * - * This function enables the TWIS instance. - * Function defined if there is need for dynamically enabling and disabling the peripheral. - * Use @ref nrfx_twis_enable and @ref nrfx_twis_disable functions. - * They do not change any configuration registers. - * - * @param p_instance Pointer to the driver instance structure. - */ -void nrfx_twis_enable(nrfx_twis_t const * p_instance); - -/** - * @brief Function for disabling the TWIS instance. - * - * This function disables the TWIS instance, which gives possibility to turn off the TWIS while - * holding configuration done by @ref nrfx_twis_init. - * - * @param p_instance Pointer to the driver instance structure. - */ -void nrfx_twis_disable(nrfx_twis_t const * p_instance); - -/** - * @brief Function for getting and clearing the last error flags. - * - * This function gets the information about errors. - * This is also the only possibility to exit from the error substate of the internal state machine. - * @attention - * This function clears error state and flags. - * - * @param[in] p_instance Pointer to the driver instance structure. - * - * @return Error flags defined in @ref nrfx_twis_error_t. - */ -uint32_t nrfx_twis_error_get_and_clear(nrfx_twis_t const * p_instance); - -/** - * @brief Function for preparing the data for sending. - * - * This function is to be used in response to the @ref NRFX_TWIS_EVT_READ_REQ event. - * - * @note Peripherals using EasyDMA (including TWIS) require the transfer buffers - * to be placed in the Data RAM region. If this condition is not met, - * this function will fail with the error code NRFX_ERROR_INVALID_ADDR. - * @attention Transmission buffer must be placed in RAM. - * - * @param[in] p_instance Pointer to the driver instance structure. - * @param[in] p_buf Transmission buffer. - * @param[in] size Maximum number of bytes that master may read from buffer given. - * - * @retval NRFX_SUCCESS The preparation finished properly. - * @retval NRFX_ERROR_INVALID_ADDR The given @em p_buf is not placed inside the RAM. - * @retval NRFX_ERROR_INVALID_LENGTH There is a wrong value in the @em size parameter. - * @retval NRFX_ERROR_INVALID_STATE The module is not initialized or not enabled. - */ -nrfx_err_t nrfx_twis_tx_prepare(nrfx_twis_t const * p_instance, - void const * p_buf, - size_t size); - -/** - * @brief Function for getting the number of transmitted bytes. - * - * This function returns the number of bytes sent. - * This function can be called after @ref NRFX_TWIS_EVT_READ_DONE or @ref NRFX_TWIS_EVT_READ_ERROR events. - * - * @param[in] p_instance Pointer to the driver instance structure. - * - * @return Number of bytes sent. - */ -__STATIC_INLINE size_t nrfx_twis_tx_amount(nrfx_twis_t const * p_instance); - -/** - * @brief Function for preparing the data for receiving. - * - * This function must be used in response to the @ref NRFX_TWIS_EVT_WRITE_REQ event. - * - * @note Peripherals using EasyDMA (including TWIS) require the transfer buffers - * to be placed in the Data RAM region. If this condition is not met, - * this function fails with the error code NRFX_ERROR_INVALID_ADDR. - * - * @param[in] p_instance Pointer to the driver instance structure. - * @param[in] p_buf Buffer that is to be filled with received data. - * @param[in] size Size of the buffer (maximum amount of data to receive). - * - * @retval NRFX_SUCCESS The preparation finished properly. - * @retval NRFX_ERROR_INVALID_ADDR The given @em p_buf is not placed inside the RAM. - * @retval NRFX_ERROR_INVALID_LENGTH There is a wrong value in the @em size parameter. - * @retval NRFX_ERROR_INVALID_STATE The module is not initialized or not enabled. - */ -nrfx_err_t nrfx_twis_rx_prepare(nrfx_twis_t const * p_instance, - void * p_buf, - size_t size); - -/** - * @brief Function for getting the number of received bytes. - * - * This function returns number of bytes received. - * It can be called after @ref NRFX_TWIS_EVT_WRITE_DONE or @ref NRFX_TWIS_EVT_WRITE_ERROR events. - * - * @param[in] p_instance Pointer to the driver instance structure. - * - * @return Number of bytes received. - */ -__STATIC_INLINE size_t nrfx_twis_rx_amount(nrfx_twis_t const * p_instance); - -/** - * @brief Function for checking if the driver is busy right now. - * - * This function tests the actual driver substate. - * If the driver is in any other state than IDLE or ERROR, this function returns true. - * - * @param[in] p_instance Pointer to the driver instance structure. - * - * @retval true The driver is in state other than ERROR or IDLE. - * @retval false There is no transmission pending. - */ -bool nrfx_twis_is_busy(nrfx_twis_t const * p_instance); - -/** - * @brief Function for checking if the driver is waiting for a TX buffer. - * - * If this function returns true, the driver is stalled expecting - * of the @ref nrfx_twis_tx_prepare function call. - * - * @param[in] p_instance Pointer to the driver instance structure. - * - * @retval true The driver is waiting for @ref nrfx_twis_tx_prepare. - * @retval false The driver is not in the state where it is waiting for preparing a TX buffer. - */ -bool nrfx_twis_is_waiting_tx_buff(nrfx_twis_t const * p_instance); - -/** - * @brief Function for checking if the driver is waiting for an RX buffer. - * - * If this function returns true, the driver is stalled expecting - * of the @ref nrfx_twis_rx_prepare function call. - * - * @param[in] p_instance Pointer to the driver instance structure. - * - * @retval true The driver is waiting for @ref nrfx_twis_rx_prepare. - * @retval false The driver is not in the state where it is waiting for preparing an RX buffer. - */ -bool nrfx_twis_is_waiting_rx_buff(nrfx_twis_t const * p_instance); - -/** - * @brief Function for checking if the driver is sending data. - * - * If this function returns true, there is an ongoing output transmission. - * - * @param[in] p_instance Pointer to the driver instance structure. - * - * @retval true There is an ongoing output transmission. - * @retval false The driver is in other state. - */ -bool nrfx_twis_is_pending_tx(nrfx_twis_t const * p_instance); - -/** - * @brief Function for checking if the driver is receiving data. - * - * If this function returns true, there is an ongoing input transmission. - * - * @param[in] p_instance Pointer to the driver instance structure. - * - * @retval true There is an ongoing input transmission. - * @retval false The driver is in other state. - */ -bool nrfx_twis_is_pending_rx(nrfx_twis_t const * p_instance); - -#ifndef SUPPRESS_INLINE_IMPLEMENTATION -__STATIC_INLINE size_t nrfx_twis_tx_amount(nrfx_twis_t const * p_instance) -{ - return nrf_twis_tx_amount_get(p_instance->p_reg); -} - -__STATIC_INLINE size_t nrfx_twis_rx_amount(nrfx_twis_t const * p_instance) -{ - return nrf_twis_rx_amount_get(p_instance->p_reg); -} -#endif // SUPPRESS_INLINE_IMPLEMENTATION - -/** @} */ - - -void nrfx_twis_0_irq_handler(void); -void nrfx_twis_1_irq_handler(void); -void nrfx_twis_2_irq_handler(void); -void nrfx_twis_3_irq_handler(void); - - -#ifdef __cplusplus -} -#endif - -#endif // NRFX_TWIS_H__ diff --git a/modules/nrfx/drivers/include/nrfx_usbd.h b/modules/nrfx/drivers/include/nrfx_usbd.h deleted file mode 100644 index 0d1b6d7..0000000 --- a/modules/nrfx/drivers/include/nrfx_usbd.h +++ /dev/null @@ -1,872 +0,0 @@ -/** - * Copyright (c) 2016 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRFX_USBD_H__ -#define NRFX_USBD_H__ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrfx_usbd USBD driver - * @{ - * @ingroup nrf_usbd - * @brief Universal Serial Bus Device (USBD) peripheral driver. - */ - -/** - * @brief Number of bytes in the endpoint. - */ -#define NRFX_USBD_EPSIZE 64 - -/** - * @brief Number of bytes for isochronous endpoints. - * - * Number of bytes for isochronous endpoints in total. - * This number would be shared between IN and OUT endpoint. - * It may be also assigned totaly to one endpoint. - * @sa nrf_usbd_isosplit_set - * @sa nrf_usbd_isosplit_get - */ -#define NRFX_USBD_ISOSIZE 1024 - -/** - * @brief The size of internal feeder buffer. - * - * @sa nrfx_usbd_feeder_buffer_get - */ -#define NRFX_USBD_FEEDER_BUFFER_SIZE NRFX_USBD_EPSIZE - -/** - * @name Macros for creating endpoint identifiers. - * - * Auxiliary macros for creating endpoint identifiers compatible with the USB specification. - * @{ - * @brief Create identifier for IN endpoint. - * - * Simple macro to create IN endpoint identifier for given endpoint number. - * - * @param[in] n Endpoint number. - * - * @return Endpoint identifier that connects endpoint number and endpoint direction. - */ -#define NRFX_USBD_EPIN(n) ((nrfx_usbd_ep_t)NRF_USBD_EPIN(n)) -/** - * @brief Create identifier for OUT endpoint. - * - * Simple macro to create OUT endpoint identifier for given endpoint number. - * - * @param[in] n Endpoint number. - * - * @return Endpoint identifier that connects endpoint number and endpoint direction. - */ -#define NRFX_USBD_EPOUT(n) ((nrfx_usbd_ep_t)NRF_USBD_EPOUT(n)) -/** @} */ - -/** - * @brief Endpoint identifier. - * - * Endpoint identifier used in the driver. - * 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 */ - - 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; - -/** - * @brief Events generated by the driver. - * - * 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. */ - NRFX_USBD_EVT_WUREQ, /**< Wakeup request - the USBD peripheral is ready to generate - WAKEUP signal after exiting low power mode. */ - NRFX_USBD_EVT_SETUP, /**< Setup frame received and decoded. */ - NRFX_USBD_EVT_EPTRANSFER, /**< For Rx (OUT: Host->Device): - * 1. The packet has been received but there is no buffer prepared for transfer already. - * 2. Whole transfer has been finished. - * - * For Tx (IN: Device->Host): - * The last packet from requested transfer has been transfered over USB bus and acknowledged. - */ - NRFX_USBD_EVT_CNT /**< Number of defined events. */ -} nrfx_usbd_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. - */ -typedef enum -{ - NRFX_USBD_EP_OK, /**< No error occured. */ - NRFX_USBD_EP_WAITING, /**< Data received, no buffer prepared already - waiting for configured transfer. */ - NRFX_USBD_EP_OVERLOAD, /**< 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 in current buffer. - * No data split from single endpoint transmission is supported. - * - * When this error is reported - data is left inside endpoint buffer. - * Clear endpoint or prepare new buffer and read it. - */ - NRFX_USBD_EP_ABORTED, /**< EP0 transfer can be aborted when new setup comes. - * Any other transfer can be aborted by USB reset or driver stopping. - */ - NRFX_USBD_EP_BUSY, /**< Transfer is in progress. */ -} nrfx_usbd_ep_status_t; - -/** - * @brief Event structure. - * - * Structure passed to event handler. - */ -typedef struct -{ - nrfx_usbd_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. */ - struct { - nrfx_usbd_ep_t ep; /**< Endpoint number. */ - } isocrc; - struct { - nrfx_usbd_ep_t ep; /**< Endpoint number. */ - nrfx_usbd_ep_status_t status; /**< Status for the endpoint. */ - } eptransfer; - } data; /**< Union to store event data. */ -} nrfx_usbd_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); - -/** - * @brief Universal data pointer. - * - * Universal data pointer that can be used for any type of transfer. - */ -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; - -/** - * @brief Structure to be filled with information about the next transfer. - * - * This is used mainly for transfer feeders and consumers. - * It describes a single endpoint transfer and therefore the size of the buffer - * 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; - -/** - * @brief Flags for the current transfer. - * - * 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; - -/** - * @brief Total transfer configuration. - * - * This structure is used to configure total transfer information. - * 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; - -/** - * @brief Auxiliary macro for declaring IN transfer description with optional flags. - * - * The base macro for creating transfers with any configuration option. - * - * @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). - * - * @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 = { \ - .p_data = { .tx = (tx_buff) }, \ - .size = (tx_size), \ - .flags = (tx_flags) \ - } - -/** - * @brief Helper macro for declaring OUT transfer item (@ref nrfx_usbd_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 = { \ - .p_data = { .rx = (rx_buff) }, \ - .size = (rx_size), \ - .flags = 0 \ - } - -/** - * @brief USBD transfer feeder. - * - * Pointer for a transfer feeder. - * Transfer feeder is a feedback function used to prepare a single - * TX (Device->Host) endpoint transfer. - * - * The transfers provided by the feeder must be simple: - * - The size of the transfer provided by this function is limited to a single endpoint buffer. - * Bigger transfers are not handled automatically in this case. - * - 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 - * that can be used to prepare transfer. - * - * @param[out] p_next Structure with the data for the next transfer to be filled. - * Required only if the function returns true. - * @param[in,out] p_context Context variable configured with the transfer. - * @param[in] ep_size The endpoint size. - * - * @retval false The current transfer is the last one - you do not need to call - * the function again. - * @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, - size_t ep_size); - -/** - * @brief USBD transfer consumer. - * - * Pointer for a transfer consumer. - * Transfer consumer is a feedback function used to prepare a single - * 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. - * - * @param[out] p_next Structure with the data for the next transfer to be filled. - * Required only if the function returns true. - * @param[in,out] p_context Context variable configured with the transfer. - * @param[in] ep_size The endpoint size. - * @param[in] data_size Number of received bytes in the endpoint buffer. - * - * @retval false Current transfer is the last one - you do not need to call - * the function again. - * @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, - size_t ep_size, - size_t data_size); - -/** - * @brief Universal transfer handler. - * - * 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; - -/** - * @brief USBD transfer descriptor. - * - * Universal structure that may hold the setup for callback configuration for - * 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; - -/** - * @brief Setup packet structure. - * - * Structure that contains interpreted SETUP packet as described in USB specification. - */ -typedef struct -{ - uint8_t bmRequestType; //!< byte 0 - uint8_t bRequest; //!< byte 1 - uint16_t wValue; //!< byte 2, 3 - uint16_t wIndex; //!< byte 4, 5 - uint16_t wLength; //!< byte 6, 7 -} nrfx_usbd_setup_t; - -/** - * @brief Driver initialization. - * - * @param[in] event_handler Event handler provided by the user. Cannot be null. - * - * @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); - -/** - * @brief Driver deinitialization. - */ -void nrfx_usbd_uninit(void); - -/** - * @brief Enable the USBD port. - * - * After calling this function USBD peripheral would be enabled. - * The USB LDO would be enabled. - * 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. - * - * 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 - * function is called. - */ -void nrfx_usbd_enable(void); - -/** - * @brief Disable the USBD port. - * - * After calling this function USBD peripheral would be disabled. - * No events would be detected or processed by the driver. - * Clock for the peripheral would be disconnected. - */ -void nrfx_usbd_disable(void); - -/** - * @brief Start USB functionality. - * - * After calling this function USBD peripheral should be fully functional - * and all new incoming events / interrupts would be processed by the driver. - * - * Also only after calling this function host sees new connected device. - * - * Call this function when USBD power LDO regulator is ready - on USBPWRRDY event - * from POWER peripheral. - * - * Before USBD interrupts are enabled, external HFXO is requested. - * - * @param enable_sof The flag that is used to enable SOF processing. - * If it is false, SOF interrupt is left disabled and will not be generated. - * This improves power saving if SOF is not required. - * - * @note If the isochronous endpoints are going to be used, - * it is required to enable the SOF. - * In other case any isochronous endpoint would stay busy - * after first transmission. - */ -void nrfx_usbd_start(bool enable_sof); - -/** - * @brief Stop USB functionality. - * - * This function disables USBD pull-up and interrupts. - * - * The HFXO request is released in this function. - * - * @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. - */ -void nrfx_usbd_stop(void); - -/** - * @brief Check if driver is initialized. - * - * @retval false Driver is not initialized. - * @retval true Driver is initialized. - */ -bool nrfx_usbd_is_initialized(void); - -/** - * @brief Check if driver is enabled. - * - * @retval false Driver is disabled. - * @retval true Driver is enabled. - */ -bool nrfx_usbd_is_enabled(void); - -/** - * @brief Check if driver is started. - * - * @retval false Driver is not started. - * @retval true Driver is started (fully functional). - * @note The USBD peripheral interrupt state is checked. - */ -bool nrfx_usbd_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 - * when the firmware is ready. - * - * After successful call of this function most of the USBD registers would be unavailable. - * - * @note Check returned value for the feedback if suspending was successful. - * - * @retval true USBD peripheral successfully suspended. - * @retval false USBD peripheral was not suspended due to resume detection. - */ -bool nrfx_usbd_suspend(void); - -/** - * @brief Start wake up procedure. - * - * The USBD peripheral is forced to quit the low power mode. - * After calling this function all the USBD registers would be available. - * - * 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 - * 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 - * 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); - -/** - * @brief Check if USBD is in SUSPEND mode. - * - * @note This is the information about peripheral itself, not about the bus state. - * - * @retval true USBD peripheral is suspended. - * @retval false USBD peripheral is active. - */ -bool nrfx_usbd_suspend_check(void); - -/** - * @brief Enable only interrupts that should be processed in SUSPEND mode. - * - * Auxiliary function to help with SUSPEND mode integration. - * It enables only the interrupts that can be properly processed without stable HFCLK. - * - * Normally all the interrupts are enabled. - * Use this function to suspend interrupt processing that may require stable HFCLK until the - * clock is enabled. - * - * @sa nrfx_usbd_active_irq_config - */ -void nrfx_usbd_suspend_irq_config(void); - -/** - * @brief Default active interrupt configuration. - * - * Default interrupt configuration. - * Use in a pair with @ref nrfx_usbd_active_irq_config. - * - * @sa nrfx_usbd_suspend_irq_config - */ -void nrfx_usbd_active_irq_config(void); - -/** - * @brief Check the bus state. - * - * This function checks if the bus state is suspended. - * - * @note The value returned by this function changes on SUSPEND and RESUME event processing. - * - * @retval true USBD bus is suspended. - * @retval false USBD bus is active. - */ -bool nrfx_usbd_bus_suspend_check(void); - -/** - * @brief Force the bus state to active - */ -void nrfx_usbd_force_bus_wakeup(void); - -/** - * @brief Configure packet size that should be supported by the endpoint. - * - * The real endpoint buffer size is always the same. - * This value sets max packet size that would be transmitted over the endpoint. - * This is required by the driver. - * - * @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. - */ -void nrfx_usbd_ep_max_packet_size_set(nrfx_usbd_ep_t ep, uint16_t size); - -/** - * @brief Get configured endpoint packet size. - * - * Function to get configured endpoint size on the buffer. - * - * @param[in] ep Endpoint number. - * - * @return Maximum pocket size configured on selected endpoint. - */ -uint16_t nrfx_usbd_ep_max_packet_size_get(nrfx_usbd_ep_t ep); - -/** - * @brief Check if the selected endpoint is enabled. - * - * @param[in] ep Endpoint number to check. - * - * @retval true Endpoint is enabled. - * @retval false Endpoint is disabled. - */ -bool nrfx_usbd_ep_enable_check(nrfx_usbd_ep_t ep); - -/** - * @brief Enable selected endpoint. - * - * This function enables endpoint itself and its interrupts. - * - * @param[in] ep Endpoint number to enable. - * - * @note - * Max packet size is set to endpoint default maximum value. - * - * @sa nrfx_usbd_ep_max_packet_size_set - */ -void nrfx_usbd_ep_enable(nrfx_usbd_ep_t ep); - -/** - * @brief Disable selected endpoint. - * - * This function disables endpoint itself and its interrupts. - * - * @param[in] ep Endpoint number to disable. - */ -void nrfx_usbd_ep_disable(nrfx_usbd_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); - -/** - * @brief Start sending data over endpoint. - * - * Function initializes endpoint transmission. - * This is asynchronous function - it finishes immediately after configuration - * 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. - * - * @param[in] ep Endpoint number. - * For IN endpoint sending would be initiated. - * For OUT endpoint receiving would be initiated. - * @param[in] p_transfer Transfer parameters. - * - * @retval NRFX_SUCCESS Transfer queued or started. - * @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); - -/** - * @brief Start sending data over the endpoint using the transfer handler function. - * - * This function initializes an endpoint transmission. - * Just before data is transmitted, the transfer handler - * is called and it prepares a data chunk. - * - * @param[in] ep Endpoint number. - * For an IN endpoint, sending is initiated. - * For an OUT endpoint, receiving is initiated. - * @param[in] p_handler Transfer handler - feeder for IN direction and consumer for - * OUT direction. - * - * @retval NRFX_SUCCESS Transfer queued or started. - * @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); - -/** - * @brief Get the temporary buffer to be used by the feeder. - * - * This buffer is used for TX transfers and it can be reused automatically - * when the transfer is finished. - * Use it for transfer preparation. - * - * May be used inside the feeder configured in @ref nrfx_usbd_ep_handled_transfer. - * - * @return Pointer to the buffer that can be used temporarily. - * - * @sa NRFX_USBD_FEEDER_BUFFER_SIZE - */ -void * nrfx_usbd_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 - * by transfer callback function. - * - * @param[in] ep Endpoint number. - * @param[out] p_size Information about the current/last transfer size. - * - * @return Endpoint status. - * - * @sa nrfx_usbd_ep_status_t - */ -nrfx_usbd_ep_status_t nrfx_usbd_ep_status_get(nrfx_usbd_ep_t ep, size_t * p_size); - -/** - * @brief Get number of received bytes. - * - * Get the number of received bytes. - * The function behavior is undefined when called on IN endpoint. - * - * @param[in] ep Endpoint number. - * - * @return Number of received bytes. - */ -size_t nrfx_usbd_epout_size_get(nrfx_usbd_ep_t ep); - -/** - * @brief Check if endpoint buffer is ready or is under USB IP control. - * - * Function to test if endpoint is busy. - * Endpoint that is busy cannot be accessed by MCU. - * It means that: - * - OUT (TX) endpoint: Last uploaded data is still in endpoint and is waiting - * to be received by the host. - * - IN (RX) endpoint: Endpoint is ready to receive data from the host - * 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 - * function. - * - * @param[in] ep Endpoint number. - * - * @retval false Endpoint is not busy. - * @retval true Endpoint is busy. - */ -bool nrfx_usbd_ep_is_busy(nrfx_usbd_ep_t ep); - -/** - * @brief Stall endpoint - * - * 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 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); - -/** - * @brief Clear stall flag on endpoint. - * - * This function clears endpoint that is stalled. - * @note - * If it is OUT endpoint (receiving) it would be also prepared for reception. - * It means that busy flag would be set. - * @note - * In endpoint (transmitting) would not be cleared - it gives possibility to - * write new data before transmitting. - * - * @param[in] ep Endpoint number. - */ -void nrfx_usbd_ep_stall_clear(nrfx_usbd_ep_t ep); - -/** - * @brief Check if endpoint is stalled. - * - * This function gets stall state of selected endpoint. - * - * @param[in] ep Endpoint number to check. - * - * @retval false Endpoint is not stalled. - * @retval true Endpoint is stalled. - */ -bool nrfx_usbd_ep_stall_check(nrfx_usbd_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); - -/** - * @brief Get parsed setup data. - * - * Function fills the parsed setup data structure. - * - * @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); - -/** - * @brief Clear the control endpoint for packet reception during DATA stage. - * - * 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 - */ -void nrfx_usbd_setup_data_clear(void); - -/** - * @brief Clear setup endpoint. - * - * 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); - -/** - * @brief Stall setup endpoint. - * - * Mark an error on setup endpoint. - */ -void nrfx_usbd_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); - -/** - * @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. - */ -nrfx_usbd_ep_t nrfx_usbd_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 nrfx_usbd_irq_handler(void); - - -#ifdef __cplusplus -} -#endif - -#endif // NRFX_USBD_H__ diff --git a/modules/nrfx/drivers/src/nrfx_adc.c b/modules/nrfx/drivers/src/nrfx_adc.c deleted file mode 100644 index b3c9ce6..0000000 --- a/modules/nrfx/drivers/src/nrfx_adc.c +++ /dev/null @@ -1,340 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include - -#if NRFX_CHECK(NRFX_ADC_ENABLED) - -#include - -#define NRFX_LOG_MODULE ADC -#include - -#define EVT_TO_STR(event) (event == NRF_ADC_EVENT_END ? "NRF_ADC_EVENT_END" : "UNKNOWN EVENT") - -typedef struct -{ - nrfx_adc_event_handler_t event_handler; - nrfx_adc_channel_t * p_head; - nrfx_adc_channel_t * p_current_conv; - nrf_adc_value_t * p_buffer; - uint16_t size; - uint16_t idx; - nrfx_drv_state_t state; -} adc_cb_t; - -static adc_cb_t m_cb; - -nrfx_err_t nrfx_adc_init(nrfx_adc_config_t const * p_config, - nrfx_adc_event_handler_t event_handler) -{ - NRFX_ASSERT(p_config); - nrfx_err_t err_code; - - if (m_cb.state != NRFX_DRV_STATE_UNINITIALIZED) - { - err_code = NRFX_ERROR_INVALID_STATE; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - - nrf_adc_event_clear(NRF_ADC_EVENT_END); - if (event_handler) - { - NRFX_IRQ_PRIORITY_SET(ADC_IRQn, p_config->interrupt_priority); - NRFX_IRQ_ENABLE(ADC_IRQn); - } - m_cb.event_handler = event_handler; - m_cb.state = NRFX_DRV_STATE_INITIALIZED; - - err_code = NRFX_SUCCESS; - NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; -} - -void nrfx_adc_uninit(void) -{ - NRFX_IRQ_DISABLE(ADC_IRQn); - nrf_adc_int_disable(NRF_ADC_INT_END_MASK); - nrf_adc_task_trigger(NRF_ADC_TASK_STOP); - - // Disable all channels. This must be done after the interrupt is disabled - // because adc_sample_process() dereferences this pointer when it needs to - // switch back to the first channel in the list (when the number of samples - // to read is bigger than the number of enabled channels). - m_cb.p_head = NULL; - - m_cb.state = NRFX_DRV_STATE_UNINITIALIZED; -} - -void nrfx_adc_channel_enable(nrfx_adc_channel_t * const p_channel) -{ - NRFX_ASSERT(!nrfx_adc_is_busy()); - - p_channel->p_next = NULL; - if (m_cb.p_head == NULL) - { - m_cb.p_head = p_channel; - } - else - { - nrfx_adc_channel_t * p_curr_channel = m_cb.p_head; - while (p_curr_channel->p_next != NULL) - { - NRFX_ASSERT(p_channel != p_curr_channel); - p_curr_channel = p_curr_channel->p_next; - } - p_curr_channel->p_next = p_channel; - } - - NRFX_LOG_INFO("Enabled."); -} - -void nrfx_adc_channel_disable(nrfx_adc_channel_t * const p_channel) -{ - NRFX_ASSERT(m_cb.p_head); - NRFX_ASSERT(!nrfx_adc_is_busy()); - - nrfx_adc_channel_t * p_curr_channel = m_cb.p_head; - nrfx_adc_channel_t * p_prev_channel = NULL; - while (p_curr_channel != p_channel) - { - p_prev_channel = p_curr_channel; - p_curr_channel = p_curr_channel->p_next; - NRFX_ASSERT(p_curr_channel != NULL); - } - if (p_prev_channel) - { - p_prev_channel->p_next = p_curr_channel->p_next; - } - else - { - m_cb.p_head = p_curr_channel->p_next; - } - - NRFX_LOG_INFO("Disabled."); -} - -void nrfx_adc_all_channels_disable(void) -{ - NRFX_ASSERT(!nrfx_adc_is_busy()); - - m_cb.p_head = NULL; -} - -void nrfx_adc_sample(void) -{ - NRFX_ASSERT(m_cb.state != NRFX_DRV_STATE_UNINITIALIZED); - NRFX_ASSERT(!nrf_adc_busy_check()); - nrf_adc_task_trigger(NRF_ADC_TASK_START); -} - -nrfx_err_t nrfx_adc_sample_convert(nrfx_adc_channel_t const * const p_channel, - nrf_adc_value_t * p_value) -{ - nrfx_err_t err_code; - - NRFX_ASSERT(m_cb.state != NRFX_DRV_STATE_UNINITIALIZED); - if (m_cb.state == NRFX_DRV_STATE_POWERED_ON) - { - err_code = NRFX_ERROR_BUSY; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - else - { - m_cb.state = NRFX_DRV_STATE_POWERED_ON; - - nrf_adc_init(&p_channel->config); - nrf_adc_enable(); - nrf_adc_int_disable(NRF_ADC_INT_END_MASK); - nrf_adc_task_trigger(NRF_ADC_TASK_START); - if (p_value) - { - while (!nrf_adc_event_check(NRF_ADC_EVENT_END)) {} - nrf_adc_event_clear(NRF_ADC_EVENT_END); - *p_value = (nrf_adc_value_t)nrf_adc_result_get(); - nrf_adc_disable(); - - m_cb.state = NRFX_DRV_STATE_INITIALIZED; - } - else - { - NRFX_ASSERT(m_cb.event_handler); - m_cb.p_buffer = NULL; - nrf_adc_int_enable(NRF_ADC_INT_END_MASK); - } - err_code = NRFX_SUCCESS; - NRFX_LOG_INFO("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } -} - -static bool adc_sample_process() -{ - nrf_adc_event_clear(NRF_ADC_EVENT_END); - nrf_adc_disable(); - m_cb.p_buffer[m_cb.idx] = (nrf_adc_value_t)nrf_adc_result_get(); - m_cb.idx++; - if (m_cb.idx < m_cb.size) - { - bool task_trigger = false; - if (m_cb.p_current_conv->p_next == NULL) - { - // Make sure the list of channels has not been somehow removed - // (it is when all channels are disabled). - NRFX_ASSERT(m_cb.p_head); - - m_cb.p_current_conv = m_cb.p_head; - } - else - { - m_cb.p_current_conv = m_cb.p_current_conv->p_next; - task_trigger = true; - } - nrf_adc_init(&m_cb.p_current_conv->config); - nrf_adc_enable(); - if (task_trigger) - { - nrf_adc_task_trigger(NRF_ADC_TASK_START); - } - return false; - } - else - { - return true; - } -} - -nrfx_err_t nrfx_adc_buffer_convert(nrf_adc_value_t * buffer, uint16_t size) -{ - NRFX_ASSERT(m_cb.state != NRFX_DRV_STATE_UNINITIALIZED); - - nrfx_err_t err_code; - - NRFX_LOG_INFO("Number of samples requested to convert: %d.", size); - - if (m_cb.state == NRFX_DRV_STATE_POWERED_ON) - { - err_code = NRFX_ERROR_BUSY; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - else - { - m_cb.state = NRFX_DRV_STATE_POWERED_ON; - m_cb.p_current_conv = m_cb.p_head; - m_cb.size = size; - m_cb.idx = 0; - m_cb.p_buffer = buffer; - nrf_adc_init(&m_cb.p_current_conv->config); - nrf_adc_event_clear(NRF_ADC_EVENT_END); - nrf_adc_enable(); - if (m_cb.event_handler) - { - nrf_adc_int_enable(NRF_ADC_INT_END_MASK); - } - else - { - while (1) - { - while (!nrf_adc_event_check(NRF_ADC_EVENT_END)){} - - if (adc_sample_process()) - { - m_cb.state = NRFX_DRV_STATE_INITIALIZED; - break; - } - } - } - err_code = NRFX_SUCCESS; - NRFX_LOG_INFO("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } -} - -bool nrfx_adc_is_busy(void) -{ - NRFX_ASSERT(m_cb.state != NRFX_DRV_STATE_UNINITIALIZED); - return (m_cb.state == NRFX_DRV_STATE_POWERED_ON) ? true : false; -} - -void nrfx_adc_irq_handler(void) -{ - if (m_cb.p_buffer == NULL) - { - nrf_adc_event_clear(NRF_ADC_EVENT_END); - NRFX_LOG_DEBUG("Event: %s.",NRFX_LOG_ERROR_STRING_GET(NRF_ADC_EVENT_END)); - nrf_adc_int_disable(NRF_ADC_INT_END_MASK); - nrf_adc_disable(); - nrfx_adc_evt_t evt; - evt.type = NRFX_ADC_EVT_SAMPLE; - evt.data.sample.sample = (nrf_adc_value_t)nrf_adc_result_get(); - NRFX_LOG_DEBUG("ADC data:"); - NRFX_LOG_HEXDUMP_DEBUG((uint8_t *)(&evt.data.sample.sample), sizeof(nrf_adc_value_t)); - m_cb.state = NRFX_DRV_STATE_INITIALIZED; - m_cb.event_handler(&evt); - } - else if (adc_sample_process()) - { - NRFX_LOG_DEBUG("Event: %s.", NRFX_LOG_ERROR_STRING_GET(NRF_ADC_EVENT_END)); - nrf_adc_int_disable(NRF_ADC_INT_END_MASK); - nrfx_adc_evt_t evt; - evt.type = NRFX_ADC_EVT_DONE; - evt.data.done.p_buffer = m_cb.p_buffer; - evt.data.done.size = m_cb.size; - m_cb.state = NRFX_DRV_STATE_INITIALIZED; - NRFX_LOG_DEBUG("ADC data:"); - NRFX_LOG_HEXDUMP_DEBUG((uint8_t *)m_cb.p_buffer, m_cb.size * sizeof(nrf_adc_value_t)); - m_cb.event_handler(&evt); - } -} - -#endif // NRFX_CHECK(NRFX_ADC_ENABLED) diff --git a/modules/nrfx/drivers/src/nrfx_comp.c b/modules/nrfx/drivers/src/nrfx_comp.c deleted file mode 100644 index 846b67c..0000000 --- a/modules/nrfx/drivers/src/nrfx_comp.c +++ /dev/null @@ -1,212 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include - -#if NRFX_CHECK(NRFX_COMP_ENABLED) - -#include -#include "prs/nrfx_prs.h" - -#define NRFX_LOG_MODULE COMP -#include - -#define EVT_TO_STR(event) \ - (event == NRF_COMP_EVENT_READY ? "NRF_COMP_EVENT_READY" : \ - (event == NRF_COMP_EVENT_DOWN ? "NRF_COMP_EVENT_DOWN" : \ - (event == NRF_COMP_EVENT_UP ? "NRF_COMP_EVENT_UP" : \ - (event == NRF_COMP_EVENT_CROSS ? "NRF_COMP_EVENT_CROSS" : \ - "UNKNOWN ERROR")))) - - -static nrfx_comp_event_handler_t m_comp_event_handler = NULL; -static nrfx_drv_state_t m_state = NRFX_DRV_STATE_UNINITIALIZED; - -static void comp_execute_handler(nrf_comp_event_t event, uint32_t event_mask) -{ - if (nrf_comp_event_check(event) && nrf_comp_int_enable_check(event_mask)) - { - nrf_comp_event_clear(event); - NRFX_LOG_DEBUG("Event: %s.", EVT_TO_STR(event)); - - m_comp_event_handler(event); - } -} - -void nrfx_comp_irq_handler(void) -{ - comp_execute_handler(NRF_COMP_EVENT_READY, COMP_INTENSET_READY_Msk); - comp_execute_handler(NRF_COMP_EVENT_DOWN, COMP_INTENSET_DOWN_Msk); - comp_execute_handler(NRF_COMP_EVENT_UP, COMP_INTENSET_UP_Msk); - comp_execute_handler(NRF_COMP_EVENT_CROSS, COMP_INTENSET_CROSS_Msk); -} - - -nrfx_err_t nrfx_comp_init(nrfx_comp_config_t const * p_config, - nrfx_comp_event_handler_t event_handler) -{ - NRFX_ASSERT(p_config); - NRFX_ASSERT(event_handler); - nrfx_err_t err_code; - - if (m_state != NRFX_DRV_STATE_UNINITIALIZED) - { // COMP driver is already initialized - err_code = NRFX_ERROR_INVALID_STATE; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - - m_comp_event_handler = event_handler; - -#if NRFX_CHECK(NRFX_PRS_ENABLED) - if (nrfx_prs_acquire(NRF_COMP, nrfx_comp_irq_handler) != NRFX_SUCCESS) - { - err_code = NRFX_ERROR_BUSY; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } -#endif - - nrf_comp_ref_set(p_config->reference); - - //If external source is chosen, write to appropriate register. - if (p_config->reference == COMP_REFSEL_REFSEL_ARef) - { - nrf_comp_ext_ref_set(p_config->ext_ref); - } - - nrf_comp_th_set(p_config->threshold); - nrf_comp_main_mode_set(p_config->main_mode); - nrf_comp_speed_mode_set(p_config->speed_mode); - nrf_comp_hysteresis_set(p_config->hyst); -#if defined (COMP_ISOURCE_ISOURCE_Msk) - nrf_comp_isource_set(p_config->isource); -#endif - nrf_comp_shorts_disable(NRFX_COMP_SHORT_STOP_AFTER_CROSS_EVT | - NRFX_COMP_SHORT_STOP_AFTER_UP_EVT | - NRFX_COMP_SHORT_STOP_AFTER_DOWN_EVT); - nrf_comp_int_disable(COMP_INTENCLR_CROSS_Msk | - COMP_INTENCLR_UP_Msk | - COMP_INTENCLR_DOWN_Msk | - COMP_INTENCLR_READY_Msk); - - nrf_comp_input_select(p_config->input); - - nrf_comp_enable(); - - nrf_comp_task_trigger(NRF_COMP_TASK_STOP); - - // Clear events to be sure there are no leftovers. - nrf_comp_event_clear(NRF_COMP_EVENT_READY); - nrf_comp_event_clear(NRF_COMP_EVENT_DOWN); - nrf_comp_event_clear(NRF_COMP_EVENT_UP); - nrf_comp_event_clear(NRF_COMP_EVENT_CROSS); - - NRFX_IRQ_PRIORITY_SET(nrfx_get_irq_number(NRF_COMP), p_config->interrupt_priority); - NRFX_IRQ_ENABLE(nrfx_get_irq_number(NRF_COMP)); - - m_state = NRFX_DRV_STATE_INITIALIZED; - - err_code = NRFX_SUCCESS; - NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; -} - -void nrfx_comp_uninit(void) -{ - NRFX_ASSERT(m_state != NRFX_DRV_STATE_UNINITIALIZED); - NRFX_IRQ_DISABLE(nrfx_get_irq_number(NRF_COMP)); - nrf_comp_disable(); -#if NRFX_CHECK(NRFX_PRS_ENABLED) - nrfx_prs_release(NRF_COMP); -#endif - m_state = NRFX_DRV_STATE_UNINITIALIZED; - m_comp_event_handler = NULL; - NRFX_LOG_INFO("Uninitialized."); -} - -void nrfx_comp_pin_select(nrf_comp_input_t psel) -{ - bool comp_enable_state = nrf_comp_enable_check(); - nrf_comp_task_trigger(NRF_COMP_TASK_STOP); - if (m_state == NRFX_DRV_STATE_POWERED_ON) - { - m_state = NRFX_DRV_STATE_INITIALIZED; - } - nrf_comp_disable(); - nrf_comp_input_select(psel); - if (comp_enable_state == true) - { - nrf_comp_enable(); - } -} - -void nrfx_comp_start(uint32_t comp_int_mask, uint32_t comp_shorts_mask) -{ - NRFX_ASSERT(m_state == NRFX_DRV_STATE_INITIALIZED); - nrf_comp_int_enable(comp_int_mask); - nrf_comp_shorts_enable(comp_shorts_mask); - nrf_comp_task_trigger(NRF_COMP_TASK_START); - m_state = NRFX_DRV_STATE_POWERED_ON; - NRFX_LOG_INFO("Enabled."); -} - -void nrfx_comp_stop(void) -{ - NRFX_ASSERT(m_state == NRFX_DRV_STATE_POWERED_ON); - nrf_comp_shorts_disable(UINT32_MAX); - nrf_comp_int_disable(UINT32_MAX); - nrf_comp_task_trigger(NRF_COMP_TASK_STOP); - m_state = NRFX_DRV_STATE_INITIALIZED; - NRFX_LOG_INFO("Disabled."); -} - -uint32_t nrfx_comp_sample() -{ - NRFX_ASSERT(m_state == NRFX_DRV_STATE_POWERED_ON); - nrf_comp_task_trigger(NRF_COMP_TASK_SAMPLE); - return nrf_comp_result_get(); -} - -#endif // NRFX_CHECK(NRFX_COMP_ENABLED) diff --git a/modules/nrfx/drivers/src/nrfx_dppi.c b/modules/nrfx/drivers/src/nrfx_dppi.c deleted file mode 100644 index e13897c..0000000 --- a/modules/nrfx/drivers/src/nrfx_dppi.c +++ /dev/null @@ -1,319 +0,0 @@ -/** - * Copyright (c) 2018 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include - -#if NRFX_CHECK(NRFX_DPPI_ENABLED) - -#include - -#define NRFX_LOG_MODULE DPPI -#include - -#if !defined(NRFX_DPPI_CHANNELS_USED) -// Default mask of DPPI channels reserved for other modules. -#define NRFX_DPPI_CHANNELS_USED 0x00000000uL -#endif - -#if !defined(NRFX_DPPI_GROUPS_USED) -// Default mask of DPPI groups reserved for other modules. -#define NRFX_DPPI_GROUPS_USED 0x00000000uL -#endif - -#define DPPI_AVAILABLE_CHANNELS_MASK \ - (((1UL << DPPI_CH_NUM) - 1) & (~NRFX_DPPI_CHANNELS_USED)) - -#define DPPI_AVAILABLE_GROUPS_MASK \ - (((1UL << DPPI_GROUP_NUM) - 1) & (~NRFX_DPPI_GROUPS_USED)) - -/** @brief Set bit at given position. */ -#define DPPI_BIT_SET(pos) (1uL << (pos)) - -static uint32_t m_allocated_channels; - -static uint8_t m_allocated_groups; - -__STATIC_INLINE bool channel_is_allocated(uint8_t channel) -{ - return ((m_allocated_channels & DPPI_BIT_SET(channel)) != 0); -} - -__STATIC_INLINE bool group_is_allocated(nrf_dppi_channel_group_t group) -{ - return ((m_allocated_groups & DPPI_BIT_SET(group)) != 0); -} - -void nrfx_dppi_free(void) -{ - uint32_t mask = m_allocated_groups; - nrf_dppi_channel_group_t group = NRF_DPPI_CHANNEL_GROUP0; - - // Disable all channels - nrf_dppi_channels_disable(NRF_DPPIC, m_allocated_channels); - - // Clear all groups configurations - while (mask) - { - if (mask & DPPI_BIT_SET(group)) - { - nrf_dppi_group_clear(NRF_DPPIC, group); - mask &= ~DPPI_BIT_SET(group); - } - group++; - } - - // Clear all allocated channels. - m_allocated_channels = 0; - - // Clear all allocated groups. - m_allocated_groups = 0; -} - -nrfx_err_t nrfx_dppi_channel_alloc(uint8_t * p_channel) -{ - nrfx_err_t err_code; - - // Get mask of available DPPI channels - uint32_t remaining_channels = DPPI_AVAILABLE_CHANNELS_MASK & ~(m_allocated_channels); - uint8_t channel = 0; - - if (!remaining_channels) - { - err_code = NRFX_ERROR_NO_MEM; - NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - - // Find first free channel - while (!(remaining_channels & DPPI_BIT_SET(channel))) - { - channel++; - } - - m_allocated_channels |= DPPI_BIT_SET(channel); - *p_channel = channel; - - err_code = NRFX_SUCCESS; - NRFX_LOG_INFO("Allocated channel: %d.", channel); - return err_code; -} - -nrfx_err_t nrfx_dppi_channel_free(uint8_t channel) -{ - nrfx_err_t err_code = NRFX_SUCCESS; - - if (!channel_is_allocated(channel)) - { - err_code = NRFX_ERROR_INVALID_PARAM; - } - else - { - // First disable this channel - nrf_dppi_channels_disable(NRF_DPPIC, DPPI_BIT_SET(channel)); - // Clear channel allocated indication. - m_allocated_channels &= ~DPPI_BIT_SET(channel); - } - NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; -} - -nrfx_err_t nrfx_dppi_channel_enable(uint8_t channel) -{ - nrfx_err_t err_code = NRFX_SUCCESS; - - if (!channel_is_allocated(channel)) - { - err_code = NRFX_ERROR_INVALID_PARAM; - } - else - { - nrf_dppi_channels_enable(NRF_DPPIC, DPPI_BIT_SET(channel)); - } - NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; -} - -nrfx_err_t nrfx_dppi_channel_disable(uint8_t channel) -{ - nrfx_err_t err_code = NRFX_SUCCESS; - - if (!channel_is_allocated(channel)) - { - err_code = NRFX_ERROR_INVALID_PARAM; - } - else - { - nrf_dppi_channels_disable(NRF_DPPIC, DPPI_BIT_SET(channel)); - err_code = NRFX_SUCCESS; - } - NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; -} - -nrfx_err_t nrfx_dppi_group_alloc(nrf_dppi_channel_group_t * p_group) -{ - nrfx_err_t err_code; - - // Get mask of available DPPI groups - uint32_t remaining_groups = DPPI_AVAILABLE_GROUPS_MASK & ~(m_allocated_groups); - nrf_dppi_channel_group_t group = NRF_DPPI_CHANNEL_GROUP0; - - if (!remaining_groups) - { - err_code = NRFX_ERROR_NO_MEM; - NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - - // Find first free group - while (!(remaining_groups & DPPI_BIT_SET(group))) - { - group++; - } - - m_allocated_groups |= DPPI_BIT_SET(group); - *p_group = group; - - err_code = NRFX_SUCCESS; - NRFX_LOG_INFO("Allocated channel: %d.", group); - return err_code; -} - -nrfx_err_t nrfx_dppi_group_free(nrf_dppi_channel_group_t group) -{ - nrfx_err_t err_code = NRFX_SUCCESS; - - if (!group_is_allocated(group)) - { - err_code = NRFX_ERROR_INVALID_PARAM; - } - else - { - nrf_dppi_group_disable(NRF_DPPIC, group); - // Set bit value to zero at position corresponding to the group number. - m_allocated_groups &= ~DPPI_BIT_SET(group); - } - NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; -} - -nrfx_err_t nrfx_dppi_channel_include_in_group(uint8_t channel, - nrf_dppi_channel_group_t group) -{ - nrfx_err_t err_code = NRFX_SUCCESS; - - if (!group_is_allocated(group) || !channel_is_allocated(channel)) - { - err_code = NRFX_ERROR_INVALID_PARAM; - } - else - { - nrf_dppi_channels_include_in_group(NRF_DPPIC, DPPI_BIT_SET(channel), group); - } - NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; -} - -nrfx_err_t nrfx_dppi_channel_remove_from_group(uint8_t channel, - nrf_dppi_channel_group_t group) -{ - nrfx_err_t err_code = NRFX_SUCCESS; - - if (!group_is_allocated(group) || !channel_is_allocated(channel)) - { - err_code = NRFX_ERROR_INVALID_PARAM; - } - else - { - nrf_dppi_channels_remove_from_group(NRF_DPPIC, DPPI_BIT_SET(channel), group); - } - NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; -} - -nrfx_err_t nrfx_dppi_group_clear(nrf_dppi_channel_group_t group) -{ - nrfx_err_t err_code = NRFX_SUCCESS; - - if (!group_is_allocated(group)) - { - err_code = NRFX_ERROR_INVALID_PARAM; - } - else - { - nrf_dppi_channels_remove_from_group(NRF_DPPIC, DPPI_AVAILABLE_CHANNELS_MASK, group); - } - NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; -} - -nrfx_err_t nrfx_dppi_group_enable(nrf_dppi_channel_group_t group) -{ - nrfx_err_t err_code = NRFX_SUCCESS; - - if (!group_is_allocated(group)) - { - err_code = NRFX_ERROR_INVALID_PARAM; - } - else - { - nrf_dppi_group_enable(NRF_DPPIC, group); - } - NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; -} - -nrfx_err_t nrfx_dppi_group_disable(nrf_dppi_channel_group_t group) -{ - nrfx_err_t err_code = NRFX_SUCCESS; - - if (!group_is_allocated(group)) - { - err_code = NRFX_ERROR_INVALID_PARAM; - } - else - { - nrf_dppi_group_disable(NRF_DPPIC, group); - } - NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; -} - -#endif // NRFX_CHECK(NRFX_DPPI_ENABLED) diff --git a/modules/nrfx/drivers/src/nrfx_i2s.c b/modules/nrfx/drivers/src/nrfx_i2s.c deleted file mode 100644 index 89c208e..0000000 --- a/modules/nrfx/drivers/src/nrfx_i2s.c +++ /dev/null @@ -1,445 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include - -#if NRFX_CHECK(NRFX_I2S_ENABLED) - -#include -#include - -#define NRFX_LOG_MODULE I2S -#include - -#define EVT_TO_STR(event) \ - (event == NRF_I2S_EVENT_RXPTRUPD ? "NRF_I2S_EVENT_RXPTRUPD" : \ - (event == NRF_I2S_EVENT_TXPTRUPD ? "NRF_I2S_EVENT_TXPTRUPD" : \ - (event == NRF_I2S_EVENT_STOPPED ? "NRF_I2S_EVENT_STOPPED" : \ - "UNKNOWN EVENT"))) - -#if !defined(USE_WORKAROUND_FOR_I2S_STOP_ANOMALY) && \ - (defined(NRF52832_XXAA) || defined(NRF52832_XXAB) || defined(NRF52840_XXAA) || \ - defined(NRF9160_XXAA)) -// Enable workaround for nRF52832 and nRF52840 anomaly 194 / nrf9160 anomaly 1 -// (STOP task does not switch off all resources). -#define USE_WORKAROUND_FOR_I2S_STOP_ANOMALY 1 -#endif - -// Control block - driver instance local data. -typedef struct -{ - nrfx_i2s_data_handler_t handler; - nrfx_drv_state_t state; - - bool use_rx : 1; - bool use_tx : 1; - bool rx_ready : 1; - bool tx_ready : 1; - bool buffers_needed : 1; - bool buffers_reused : 1; - - uint16_t buffer_size; - nrfx_i2s_buffers_t next_buffers; - nrfx_i2s_buffers_t current_buffers; -} i2s_control_block_t; -static i2s_control_block_t m_cb; - - -static void configure_pins(nrfx_i2s_config_t const * p_config) -{ - uint32_t mck_pin, sdout_pin, sdin_pin; - - // Configure pins used by the peripheral: - - // - SCK and LRCK (required) - depending on the mode of operation these - // pins are configured as outputs (in Master mode) or inputs (in Slave - // mode). - if (p_config->mode == NRF_I2S_MODE_MASTER) - { - nrf_gpio_cfg_output(p_config->sck_pin); - nrf_gpio_cfg_output(p_config->lrck_pin); - } - else - { - nrf_gpio_cfg_input(p_config->sck_pin, NRF_GPIO_PIN_NOPULL); - nrf_gpio_cfg_input(p_config->lrck_pin, NRF_GPIO_PIN_NOPULL); - } - - // - MCK (optional) - always output, - if (p_config->mck_pin != NRFX_I2S_PIN_NOT_USED) - { - mck_pin = p_config->mck_pin; - nrf_gpio_cfg_output(mck_pin); - } - else - { - mck_pin = NRF_I2S_PIN_NOT_CONNECTED; - } - - // - SDOUT (optional) - always output, - if (p_config->sdout_pin != NRFX_I2S_PIN_NOT_USED) - { - sdout_pin = p_config->sdout_pin; - nrf_gpio_cfg_output(sdout_pin); - } - else - { - sdout_pin = NRF_I2S_PIN_NOT_CONNECTED; - } - - // - SDIN (optional) - always input. - if (p_config->sdin_pin != NRFX_I2S_PIN_NOT_USED) - { - sdin_pin = p_config->sdin_pin; - nrf_gpio_cfg_input(sdin_pin, NRF_GPIO_PIN_NOPULL); - } - else - { - sdin_pin = NRF_I2S_PIN_NOT_CONNECTED; - } - - nrf_i2s_pins_set(NRF_I2S, - p_config->sck_pin, - p_config->lrck_pin, - mck_pin, - sdout_pin, - sdin_pin); -} - - -nrfx_err_t nrfx_i2s_init(nrfx_i2s_config_t const * p_config, - nrfx_i2s_data_handler_t handler) -{ - NRFX_ASSERT(p_config); - NRFX_ASSERT(handler); - - nrfx_err_t err_code; - - if (m_cb.state != NRFX_DRV_STATE_UNINITIALIZED) - { - err_code = NRFX_ERROR_INVALID_STATE; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - - if (!nrf_i2s_configure(NRF_I2S, - p_config->mode, - p_config->format, - p_config->alignment, - p_config->sample_width, - p_config->channels, - p_config->mck_setup, - p_config->ratio)) - { - err_code = NRFX_ERROR_INVALID_PARAM; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - configure_pins(p_config); - - m_cb.handler = handler; - - NRFX_IRQ_PRIORITY_SET(I2S_IRQn, p_config->irq_priority); - NRFX_IRQ_ENABLE(I2S_IRQn); - - m_cb.state = NRFX_DRV_STATE_INITIALIZED; - - NRFX_LOG_INFO("Initialized."); - return NRFX_SUCCESS; -} - - -void nrfx_i2s_uninit(void) -{ - NRFX_ASSERT(m_cb.state != NRFX_DRV_STATE_UNINITIALIZED); - - nrfx_i2s_stop(); - - NRFX_IRQ_DISABLE(I2S_IRQn); - - nrf_i2s_pins_set(NRF_I2S, - NRF_I2S_PIN_NOT_CONNECTED, - NRF_I2S_PIN_NOT_CONNECTED, - NRF_I2S_PIN_NOT_CONNECTED, - NRF_I2S_PIN_NOT_CONNECTED, - NRF_I2S_PIN_NOT_CONNECTED); - - m_cb.state = NRFX_DRV_STATE_UNINITIALIZED; - NRFX_LOG_INFO("Uninitialized."); -} - - -nrfx_err_t nrfx_i2s_start(nrfx_i2s_buffers_t const * p_initial_buffers, - uint16_t buffer_size, - uint8_t flags) -{ - NRFX_ASSERT(p_initial_buffers != NULL); - NRFX_ASSERT(p_initial_buffers->p_rx_buffer != NULL || - p_initial_buffers->p_tx_buffer != NULL); - NRFX_ASSERT((p_initial_buffers->p_rx_buffer == NULL) || - (nrfx_is_in_ram(p_initial_buffers->p_rx_buffer) && - nrfx_is_word_aligned(p_initial_buffers->p_rx_buffer))); - NRFX_ASSERT((p_initial_buffers->p_tx_buffer == NULL) || - (nrfx_is_in_ram(p_initial_buffers->p_tx_buffer) && - nrfx_is_word_aligned(p_initial_buffers->p_tx_buffer))); - NRFX_ASSERT(buffer_size != 0); - (void)(flags); - - nrfx_err_t err_code; - - if (m_cb.state != NRFX_DRV_STATE_INITIALIZED) - { - err_code = NRFX_ERROR_INVALID_STATE; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - - if (((p_initial_buffers->p_rx_buffer != NULL) - && !nrfx_is_in_ram(p_initial_buffers->p_rx_buffer)) - || - ((p_initial_buffers->p_tx_buffer != NULL) - && !nrfx_is_in_ram(p_initial_buffers->p_tx_buffer))) - { - err_code = NRFX_ERROR_INVALID_ADDR; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - - m_cb.use_rx = (p_initial_buffers->p_rx_buffer != NULL); - m_cb.use_tx = (p_initial_buffers->p_tx_buffer != NULL); - m_cb.rx_ready = false; - m_cb.tx_ready = false; - m_cb.buffers_needed = false; - m_cb.buffer_size = buffer_size; - - // Set the provided initial buffers as next, they will become the current - // ones after the IRQ handler is called for the first time, what will occur - // right after the START task is triggered. - m_cb.next_buffers = *p_initial_buffers; - m_cb.current_buffers.p_rx_buffer = NULL; - m_cb.current_buffers.p_tx_buffer = NULL; - - nrf_i2s_transfer_set(NRF_I2S, - m_cb.buffer_size, - m_cb.next_buffers.p_rx_buffer, - m_cb.next_buffers.p_tx_buffer); - - nrf_i2s_enable(NRF_I2S); - - m_cb.state = NRFX_DRV_STATE_POWERED_ON; - - nrf_i2s_event_clear(NRF_I2S, NRF_I2S_EVENT_RXPTRUPD); - nrf_i2s_event_clear(NRF_I2S, NRF_I2S_EVENT_TXPTRUPD); - nrf_i2s_event_clear(NRF_I2S, NRF_I2S_EVENT_STOPPED); - nrf_i2s_int_enable(NRF_I2S, (m_cb.use_rx ? NRF_I2S_INT_RXPTRUPD_MASK : 0) | - (m_cb.use_tx ? NRF_I2S_INT_TXPTRUPD_MASK : 0) | - NRF_I2S_INT_STOPPED_MASK); - nrf_i2s_task_trigger(NRF_I2S, NRF_I2S_TASK_START); - - NRFX_LOG_INFO("Started."); - return NRFX_SUCCESS; -} - - -nrfx_err_t nrfx_i2s_next_buffers_set(nrfx_i2s_buffers_t const * p_buffers) -{ - NRFX_ASSERT(m_cb.state == NRFX_DRV_STATE_POWERED_ON); - NRFX_ASSERT(p_buffers); - NRFX_ASSERT((p_buffers->p_rx_buffer == NULL) || - (nrfx_is_in_ram(p_buffers->p_rx_buffer) && - nrfx_is_word_aligned(p_buffers->p_rx_buffer))); - NRFX_ASSERT((p_buffers->p_tx_buffer == NULL) || - (nrfx_is_in_ram(p_buffers->p_tx_buffer) && - nrfx_is_word_aligned(p_buffers->p_tx_buffer))); - - nrfx_err_t err_code; - - if (!m_cb.buffers_needed) - { - err_code = NRFX_ERROR_INVALID_STATE; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - - if (((p_buffers->p_rx_buffer != NULL) - && !nrfx_is_in_ram(p_buffers->p_rx_buffer)) - || - ((p_buffers->p_tx_buffer != NULL) - && !nrfx_is_in_ram(p_buffers->p_tx_buffer))) - { - err_code = NRFX_ERROR_INVALID_ADDR; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - - if (m_cb.use_tx) - { - NRFX_ASSERT(p_buffers->p_tx_buffer != NULL); - nrf_i2s_tx_buffer_set(NRF_I2S, p_buffers->p_tx_buffer); - } - if (m_cb.use_rx) - { - NRFX_ASSERT(p_buffers->p_rx_buffer != NULL); - nrf_i2s_rx_buffer_set(NRF_I2S, p_buffers->p_rx_buffer); - } - - m_cb.next_buffers = *p_buffers; - m_cb.buffers_needed = false; - - return NRFX_SUCCESS; -} - - -void nrfx_i2s_stop(void) -{ - NRFX_ASSERT(m_cb.state != NRFX_DRV_STATE_UNINITIALIZED); - - m_cb.buffers_needed = false; - - // First disable interrupts, then trigger the STOP task, so no spurious - // RXPTRUPD and TXPTRUPD events (see nRF52 anomaly 55) are processed. - nrf_i2s_int_disable(NRF_I2S, NRF_I2S_INT_RXPTRUPD_MASK | - NRF_I2S_INT_TXPTRUPD_MASK); - nrf_i2s_task_trigger(NRF_I2S, NRF_I2S_TASK_STOP); - -#if NRFX_CHECK(USE_WORKAROUND_FOR_I2S_STOP_ANOMALY) - *((volatile uint32_t *)(((uint32_t)NRF_I2S) + 0x38)) = 1; - *((volatile uint32_t *)(((uint32_t)NRF_I2S) + 0x3C)) = 1; -#endif -} - - -void nrfx_i2s_irq_handler(void) -{ - if (nrf_i2s_event_check(NRF_I2S, NRF_I2S_EVENT_TXPTRUPD)) - { - nrf_i2s_event_clear(NRF_I2S, NRF_I2S_EVENT_TXPTRUPD); - m_cb.tx_ready = true; - if (m_cb.use_tx && m_cb.buffers_needed) - { - m_cb.buffers_reused = true; - } - } - if (nrf_i2s_event_check(NRF_I2S, NRF_I2S_EVENT_RXPTRUPD)) - { - nrf_i2s_event_clear(NRF_I2S, NRF_I2S_EVENT_RXPTRUPD); - m_cb.rx_ready = true; - if (m_cb.use_rx && m_cb.buffers_needed) - { - m_cb.buffers_reused = true; - } - } - - if (nrf_i2s_event_check(NRF_I2S, NRF_I2S_EVENT_STOPPED)) - { - nrf_i2s_event_clear(NRF_I2S, NRF_I2S_EVENT_STOPPED); - nrf_i2s_int_disable(NRF_I2S, NRF_I2S_INT_STOPPED_MASK); - nrf_i2s_disable(NRF_I2S); - - // When stopped, release all buffers, including these scheduled for - // the next transfer. - m_cb.handler(&m_cb.current_buffers, 0); - m_cb.handler(&m_cb.next_buffers, 0); - - m_cb.state = NRFX_DRV_STATE_INITIALIZED; - NRFX_LOG_INFO("Stopped."); - } - else - { - // Check if the requested transfer has been completed: - // - full-duplex mode - if ((m_cb.use_tx && m_cb.use_rx && m_cb.tx_ready && m_cb.rx_ready) || - // - TX only mode - (!m_cb.use_rx && m_cb.tx_ready) || - // - RX only mode - (!m_cb.use_tx && m_cb.rx_ready)) - { - m_cb.tx_ready = false; - m_cb.rx_ready = false; - - // If the application did not supply the buffers for the next - // part of the transfer until this moment, the current buffers - // cannot be released, since the I2S peripheral already started - // using them. Signal this situation to the application by - // passing NULL instead of the structure with released buffers. - if (m_cb.buffers_reused) - { - m_cb.buffers_reused = false; - // This will most likely be set at this point. However, there is - // a small time window between TXPTRUPD and RXPTRUPD events, - // and it is theoretically possible that next buffers will be - // set in this window, so to be sure this flag is set to true, - // set it explicitly. - m_cb.buffers_needed = true; - m_cb.handler(NULL, - NRFX_I2S_STATUS_NEXT_BUFFERS_NEEDED); - } - else - { - // Buffers that have been used by the I2S peripheral (current) - // are now released and will be returned to the application, - // and the ones scheduled to be used as next become the current - // ones. - nrfx_i2s_buffers_t released_buffers = m_cb.current_buffers; - m_cb.current_buffers = m_cb.next_buffers; - m_cb.next_buffers.p_rx_buffer = NULL; - m_cb.next_buffers.p_tx_buffer = NULL; - m_cb.buffers_needed = true; - m_cb.handler(&released_buffers, - NRFX_I2S_STATUS_NEXT_BUFFERS_NEEDED); - } - - } - } -} - -#endif // NRFX_CHECK(NRFX_I2S_ENABLED) diff --git a/modules/nrfx/drivers/src/nrfx_lpcomp.c b/modules/nrfx/drivers/src/nrfx_lpcomp.c deleted file mode 100644 index 4f9792e..0000000 --- a/modules/nrfx/drivers/src/nrfx_lpcomp.c +++ /dev/null @@ -1,174 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include - -#if NRFX_CHECK(NRFX_LPCOMP_ENABLED) - -#include -#include "prs/nrfx_prs.h" - -#define NRFX_LOG_MODULE LPCOMP -#include - -#define EVT_TO_STR(event) \ - (event == NRF_LPCOMP_EVENT_READY ? "NRF_LPCOMP_EVENT_READY" : \ - (event == NRF_LPCOMP_EVENT_DOWN ? "NRF_LPCOMP_EVENT_DOWN" : \ - (event == NRF_LPCOMP_EVENT_UP ? "NRF_LPCOMP_EVENT_UP" : \ - (event == NRF_LPCOMP_EVENT_CROSS ? "NRF_LPCOMP_EVENT_CROSS" : \ - "UNKNOWN EVENT")))) - - -static nrfx_lpcomp_event_handler_t m_lpcomp_event_handler = NULL; -static nrfx_drv_state_t m_state = NRFX_DRV_STATE_UNINITIALIZED; - -static void lpcomp_execute_handler(nrf_lpcomp_event_t event, uint32_t event_mask) -{ - if (nrf_lpcomp_event_check(event) && nrf_lpcomp_int_enable_check(event_mask)) - { - nrf_lpcomp_event_clear(event); - NRFX_LOG_DEBUG("Event: %s.", EVT_TO_STR(event)); - - m_lpcomp_event_handler(event); - } -} - -void nrfx_lpcomp_irq_handler(void) -{ - lpcomp_execute_handler(NRF_LPCOMP_EVENT_READY, LPCOMP_INTENSET_READY_Msk); - lpcomp_execute_handler(NRF_LPCOMP_EVENT_DOWN, LPCOMP_INTENSET_DOWN_Msk); - lpcomp_execute_handler(NRF_LPCOMP_EVENT_UP, LPCOMP_INTENSET_UP_Msk); - lpcomp_execute_handler(NRF_LPCOMP_EVENT_CROSS, LPCOMP_INTENSET_CROSS_Msk); -} - -nrfx_err_t nrfx_lpcomp_init(nrfx_lpcomp_config_t const * p_config, - nrfx_lpcomp_event_handler_t event_handler) -{ - NRFX_ASSERT(p_config); - NRFX_ASSERT(event_handler); - nrfx_err_t err_code; - - if (m_state != NRFX_DRV_STATE_UNINITIALIZED) - { // LPCOMP driver is already initialized - err_code = NRFX_ERROR_INVALID_STATE; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - - m_lpcomp_event_handler = event_handler; - -#if NRFX_CHECK(NRFX_PRS_ENABLED) - if (nrfx_prs_acquire(NRF_LPCOMP, nrfx_lpcomp_irq_handler) != NRFX_SUCCESS) - { - err_code = NRFX_ERROR_BUSY; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } -#endif - - nrf_lpcomp_configure(&(p_config->hal)); - - nrf_lpcomp_input_select(p_config->input); - - switch (p_config->hal.detection) - { - case NRF_LPCOMP_DETECT_UP: - nrf_lpcomp_int_enable(LPCOMP_INTENSET_UP_Msk); - break; - - case NRF_LPCOMP_DETECT_DOWN: - nrf_lpcomp_int_enable(LPCOMP_INTENSET_DOWN_Msk); - break; - - case NRF_LPCOMP_DETECT_CROSS: - nrf_lpcomp_int_enable(LPCOMP_INTENSET_CROSS_Msk); - break; - - default: - break; - } - nrf_lpcomp_shorts_enable(NRF_LPCOMP_SHORT_READY_SAMPLE_MASK); - - NRFX_IRQ_PRIORITY_SET(LPCOMP_IRQn, p_config->interrupt_priority); - NRFX_IRQ_ENABLE(LPCOMP_IRQn); - - m_state = NRFX_DRV_STATE_INITIALIZED; - - err_code = NRFX_SUCCESS; - NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; -} - -void nrfx_lpcomp_uninit(void) -{ - NRFX_ASSERT(m_state != NRFX_DRV_STATE_UNINITIALIZED); - NRFX_IRQ_DISABLE(LPCOMP_IRQn); - nrfx_lpcomp_disable(); -#if NRFX_CHECK(NRFX_PRS_ENABLED) - nrfx_prs_release(NRF_LPCOMP); -#endif - m_state = NRFX_DRV_STATE_UNINITIALIZED; - m_lpcomp_event_handler = NULL; - NRFX_LOG_INFO("Uninitialized."); -} - -void nrfx_lpcomp_enable(void) -{ - NRFX_ASSERT(m_state == NRFX_DRV_STATE_INITIALIZED); - nrf_lpcomp_enable(); - nrf_lpcomp_task_trigger(NRF_LPCOMP_TASK_START); - m_state = NRFX_DRV_STATE_POWERED_ON; - NRFX_LOG_INFO("Enabled."); -} - -void nrfx_lpcomp_disable(void) -{ - NRFX_ASSERT(m_state == NRFX_DRV_STATE_POWERED_ON); - nrf_lpcomp_disable(); - nrf_lpcomp_task_trigger(NRF_LPCOMP_TASK_STOP); - m_state = NRFX_DRV_STATE_INITIALIZED; - NRFX_LOG_INFO("Disabled."); -} - -#endif // NRFX_CHECK(NRFX_LPCOMP_ENABLED) diff --git a/modules/nrfx/drivers/src/nrfx_nfct.c b/modules/nrfx/drivers/src/nrfx_nfct.c deleted file mode 100644 index a7bdaac..0000000 --- a/modules/nrfx/drivers/src/nrfx_nfct.c +++ /dev/null @@ -1,867 +0,0 @@ -/** - * Copyright (c) 2018 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include - -#if NRFX_CHECK(NRFX_NFCT_ENABLED) - -#include - -#define NRFX_LOG_MODULE NFCT -#include - -#if defined(NRF52832_XXAA) || defined(NRF52832_XXAB) || \ - defined(NRF52833_XXAA) || defined(NRF52840_XXAA) -#define USE_TIMER_WORKAROUND -#endif - -#if defined(USE_TIMER_WORKAROUND) -#include - -typedef struct -{ - const nrfx_timer_t timer; /**< Timer instance that supports the correct NFC field detection. */ -#if defined(NRF52833_XXAA) || defined(NRF52840_XXAA) - bool fieldevents_filter_active; /**< Flag that indicates that the field events are ignored. */ - bool is_hfclk_on; /**< HFCLK has started - one of the NFC activation conditions. */ - bool is_delayed; /**< Required time delay has passed - one of the NFC activation conditions. */ -#else - uint32_t field_state_cnt; /**< Counter of the FIELDLOST events. */ -#endif // defined(NRF52833_XXAA) || defined(NRF52840_XXAA) -} nrfx_nfct_timer_workaround_t; - -#if defined(NRF52833_XXAA) || defined(NRF52840_XXAA) - #define NRFX_NFCT_ACTIVATE_DELAY 1000 /**< Minimal delay in us between NFC field detection and activation of NFCT. */ - #define NRFX_NFCT_TIMER_PERIOD NRFX_NFCT_ACTIVATE_DELAY -#else - #define NRFX_NFCT_FIELDLOST_THR 7 - #define NRFX_NFCT_FIELD_TIMER_PERIOD 100 /**< Field polling period in us. */ - #define NRFX_NFCT_TIMER_PERIOD NRFX_NFCT_FIELD_TIMER_PERIOD -#endif // defined(NRF52833_XXAA) || defined(NRF52840_XXAA) -#define NRFX_NFCT_TIMER_INSTANCE 4 /**< Timer instance used for various workarounds for the NFCT HW issues.*/ - -static nrfx_nfct_timer_workaround_t m_timer_workaround = -{ - .timer = NRFX_TIMER_INSTANCE(NRFX_NFCT_TIMER_INSTANCE), -}; -#endif // defined(USE_TIMER_WORKAROUND) - -#define NRFX_NFCT_FWT_MAX_DIFF 1u /**< The maximal difference between the requested FWT and HW-limited FWT settings.*/ -#define NFCT_FRAMEDELAYMAX_DEFAULT (0x00001000UL) /**< Default value of the FRAMEDELAYMAX. */ - -/* Mask of all possible interrupts that are relevant for data reception. */ -#define NRFX_NFCT_RX_INT_MASK (NRF_NFCT_INT_RXFRAMESTART_MASK | \ - NRF_NFCT_INT_RXFRAMEEND_MASK | \ - NRF_NFCT_INT_RXERROR_MASK) - -/* Mask of all possible interrupts that are relevant for data transmission. */ -#define NRFX_NFCT_TX_INT_MASK (NRF_NFCT_INT_TXFRAMESTART_MASK | \ - NRF_NFCT_INT_TXFRAMEEND_MASK) - - -/* Mask of all possible errors from the @ref NRF_NFCT_EVENT_RXERROR event. */ -#define NRFX_NFCT_FRAME_STATUS_RX_ALL_MASK (NRF_NFCT_RX_FRAME_STATUS_CRC_MASK | \ - NRF_NFCT_RX_FRAME_STATUS_PARITY_MASK | \ - NRF_NFCT_RX_FRAME_STATUS_OVERRUN_MASK) - -/* Mask of all possible errors from the @ref NRF_NFCT_EVENT_ERROR event. */ -#if defined (NRF52832_XXAA) || defined(NRF52832_XXAB) -#define NRFX_NFCT_ERROR_STATUS_ALL_MASK (NRF_NFCT_ERROR_FRAMEDELAYTIMEOUT_MASK | \ - NRF_NFCT_ERROR_NFCFIELDTOOSTRONG_MASK | \ - NRF_NFCT_ERROR_NFCFIELDTOOWEAK_MASK) -#else -#define NRFX_NFCT_ERROR_STATUS_ALL_MASK (NRF_NFCT_ERROR_FRAMEDELAYTIMEOUT_MASK) -#endif - -/* Macros for conversion of bits to bytes. */ -#define NRFX_NFCT_BYTES_TO_BITS(_bytes) ((_bytes) << 3) -#define NRFX_NFCT_BITS_TO_BYTES(_bits) ((_bits) >> 3) - -/* Macro for checking whether the NFCT interrupt is active. */ -#define NRFX_NFCT_EVT_ACTIVE(_name) (nrf_nfct_event_check(NRFX_CONCAT_2(NRF_NFCT_EVENT_, _name)) && \ - nrf_nfct_int_enable_check(NRFX_CONCAT_3(NRF_NFCT_INT_, _name, _MASK))) - -/* Macro for callback execution. */ -#define NRFX_NFCT_CB_HANDLE(_cb, _evt) \ - if (_cb != NULL) \ - { \ - _cb(&_evt); \ - } - -typedef enum -{ - NRFX_NFC_FIELD_STATE_NONE, /**< Initial value that indicates no NFCT field events. */ - NRFX_NFC_FIELD_STATE_OFF, /**< The NFCT FIELDLOST event has been set. */ - NRFX_NFC_FIELD_STATE_ON, /**< The NFCT FIELDDETECTED event has been set. */ - NRFX_NFC_FIELD_STATE_UNKNOWN /**< Both NFCT field events have been set - ambiguous state. */ -} nrfx_nfct_field_state_t; - -/**@brief NFCT control block. */ -typedef struct -{ - nrfx_nfct_config_t config; - nrfx_drv_state_t state; - volatile bool field_on; - uint32_t frame_delay_max; -} nrfx_nfct_control_block_t; - -static nrfx_nfct_control_block_t m_nfct_cb; - -/** - * @brief Common part of the setup used for the NFCT initialization and reinitialization. - */ -static void nrfx_nfct_hw_init_setup(void) -{ - // Use Window Grid frame delay mode. - nrf_nfct_frame_delay_mode_set(NRF_NFCT_FRAME_DELAY_MODE_WINDOWGRID); - - /* Begin: Workaround for anomaly 25 */ - /* Workaround for wrong SENSRES values require using SDD00001, but here SDD00100 is used - because it is required to operate with Windows Phone */ - nrf_nfct_sensres_bit_frame_sdd_set(NRF_NFCT_SENSRES_BIT_FRAME_SDD_00100); - /* End: Workaround for anomaly 25 */ -} - -static void nrfx_nfct_frame_delay_max_set(bool default_delay) -{ - if (default_delay) - { - nrf_nfct_frame_delay_max_set(NFCT_FRAMEDELAYMAX_DEFAULT); - } - else - { - nrf_nfct_frame_delay_max_set(m_nfct_cb.frame_delay_max); - } -} - -/**@brief Function for evaluating and handling the NFC field events. - * - * @param[in] field_state Current field state. - */ -static void nrfx_nfct_field_event_handler(volatile nrfx_nfct_field_state_t field_state) -{ - nrfx_nfct_evt_t nfct_evt; - -#if defined(NRF52833_XXAA) || defined(NRF52840_XXAA) - if(m_timer_workaround.fieldevents_filter_active) - { - return; - } -#endif // defined(NRF52833_XXAA) || defined(NRF52840_XXAA) - - if (field_state == NRFX_NFC_FIELD_STATE_UNKNOWN) - { - /* Probe NFC field */ - field_state = (nrfx_nfct_field_check()) ? NRFX_NFC_FIELD_STATE_ON : NRFX_NFC_FIELD_STATE_OFF; - } - - /* Field event service. Only take action on field transition - - * based on the value of m_nfct_cb.field_on - */ - switch (field_state) - { - case NRFX_NFC_FIELD_STATE_ON: - if (!m_nfct_cb.field_on) - { -#if defined(NRF52833_XXAA) || defined(NRF52840_XXAA) - /* Begin: Workaround for anomaly 190 */ - m_timer_workaround.is_hfclk_on = false; - m_timer_workaround.is_delayed = false; - m_timer_workaround.fieldevents_filter_active = true; - - nrfx_timer_clear(&m_timer_workaround.timer); - nrfx_timer_enable(&m_timer_workaround.timer); - /* End: Workaround for anomaly 190 */ -#elif defined(NRF52832_XXAA) || defined(NRF52832_XXAB) - nrfx_timer_clear(&m_timer_workaround.timer); - nrfx_timer_enable(&m_timer_workaround.timer); - m_timer_workaround.field_state_cnt = 0; -#endif // defined(NRF52833_XXAA) || defined(NRF52840_XXAA) - - m_nfct_cb.field_on = true; - nfct_evt.evt_id = NRFX_NFCT_EVT_FIELD_DETECTED; - NRFX_NFCT_CB_HANDLE(m_nfct_cb.config.cb, nfct_evt); - } - break; - - case NRFX_NFC_FIELD_STATE_OFF: - if (m_nfct_cb.field_on) - { - nrf_nfct_task_trigger(NRF_NFCT_TASK_SENSE); - nrf_nfct_int_disable(NRFX_NFCT_RX_INT_MASK | NRFX_NFCT_TX_INT_MASK); - m_nfct_cb.field_on = false; - nfct_evt.evt_id = NRFX_NFCT_EVT_FIELD_LOST; - - /* Begin: Workaround for anomaly 218 */ - nrfx_nfct_frame_delay_max_set(true); - /* End: Workaround for anomaly 218 */ - - NRFX_NFCT_CB_HANDLE(m_nfct_cb.config.cb, nfct_evt); - } - break; - - default: - /* No implementation required */ - break; - } -} - -#if defined(USE_TIMER_WORKAROUND) - -#if defined(NRF52833_XXAA) || defined(NRF52840_XXAA) -static void nrfx_nfct_activate_check(void) -{ - static bool is_field_validation_pending = false; - - if (is_field_validation_pending) - { - is_field_validation_pending = false; - m_timer_workaround.fieldevents_filter_active = false; - - // Check the field status and take action if field is lost. - nrfx_nfct_field_event_handler(NRFX_NFC_FIELD_STATE_UNKNOWN); - return; - } - - if ((m_timer_workaround.is_hfclk_on) && (m_timer_workaround.is_delayed)) - { - nrf_nfct_task_trigger(NRF_NFCT_TASK_ACTIVATE); - is_field_validation_pending = true; - - // Start the timer second time to validate whether the tag has locked to the field. - nrfx_timer_clear(&m_timer_workaround.timer); - nrfx_timer_enable(&m_timer_workaround.timer); - } -} -#endif // defined(NRF52833_XXAA) || defined(NRF52840_XXAA) - -#if defined(NRF52832_XXAA) || defined(NRF52832_XXAB) -/* Begin: Workaround for anomaly 116 */ -static inline void nrfx_nfct_reset(void) -{ - uint32_t fdm; - uint32_t int_enabled; - uint8_t nfcid1[NRF_NFCT_SENSRES_NFCID1_SIZE_TRIPLE]; - nrf_nfct_sensres_nfcid1_size_t nfcid1_size; - nrf_nfct_selres_protocol_t protocol; - - // Save parameter settings before the reset of the NFCT peripheral. - fdm = nrf_nfct_frame_delay_max_get(); - nfcid1_size = nrf_nfct_nfcid1_get(nfcid1); - protocol = nrf_nfct_selsres_protocol_get(); - int_enabled = nrf_nfct_int_enable_get(); - - // Reset the NFCT peripheral. - *(volatile uint32_t *)0x40005FFC = 0; - *(volatile uint32_t *)0x40005FFC; - *(volatile uint32_t *)0x40005FFC = 1; - - // Restore parameter settings after the reset of the NFCT peripheral. - nrf_nfct_frame_delay_max_set(fdm); - nrf_nfct_nfcid1_set(nfcid1, nfcid1_size); - nrf_nfct_selres_protocol_set(protocol); - - // Restore general HW configuration. - nrfx_nfct_hw_init_setup(); - - // Restore interrupts. - nrf_nfct_int_enable(int_enabled); - - // Disable interrupts associated with data exchange. - nrf_nfct_int_disable(NRFX_NFCT_RX_INT_MASK | NRFX_NFCT_TX_INT_MASK); - - NRFX_LOG_INFO("Reinitialize"); -} -/* End: Workaround for anomaly 116 */ - -static void nrfx_nfct_field_poll(void) -{ - if (!nrfx_nfct_field_check()) - { - if (++m_timer_workaround.field_state_cnt > NRFX_NFCT_FIELDLOST_THR) - { - nrfx_nfct_evt_t nfct_evt = - { - .evt_id = NRFX_NFCT_EVT_FIELD_LOST, - }; - - nrfx_timer_disable(&m_timer_workaround.timer); - m_nfct_cb.field_on = false; - - /* Begin: Workaround for anomaly 218 */ - nrfx_nfct_frame_delay_max_set(true); - /* End: Workaround for anomaly 218 */ - - /* Begin: Workaround for anomaly 116 */ - /* resume the NFCT to initialized state */ - nrfx_nfct_reset(); - /* End: Workaround for anomaly 116 */ - - NRFX_NFCT_CB_HANDLE(m_nfct_cb.config.cb, nfct_evt); - } - return; - } - - m_timer_workaround.field_state_cnt = 0; -} -#endif // defined(NRF52832_XXAA) || defined(NRF52832_XXAB) - -static void nrfx_nfct_field_timer_handler(nrf_timer_event_t event_type, void * p_context) -{ - (void)p_context; - - if (event_type != NRF_TIMER_EVENT_COMPARE0) - { - return; - } - -#if defined(NRF52833_XXAA) || defined(NRF52840_XXAA) - m_timer_workaround.is_delayed = true; - - nrfx_timer_disable(&m_timer_workaround.timer); - nrfx_nfct_activate_check(); -#else - nrfx_nfct_field_poll(); -#endif // defined(NRF52833_XXAA) || defined(NRF52840_XXAA) -} - -static inline nrfx_err_t nrfx_nfct_field_timer_config(void) -{ - nrfx_err_t err_code; - nrfx_timer_config_t timer_cfg = - { - .frequency = NRF_TIMER_FREQ_1MHz, - .mode = NRF_TIMER_MODE_TIMER, - .bit_width = NRF_TIMER_BIT_WIDTH_16, - .interrupt_priority = NRFX_NFCT_CONFIG_IRQ_PRIORITY - }; - - err_code = nrfx_timer_init(&m_timer_workaround.timer, &timer_cfg, nrfx_nfct_field_timer_handler); - if (err_code != NRFX_SUCCESS) - { - return err_code; - } - - nrfx_timer_extended_compare(&m_timer_workaround.timer, - NRF_TIMER_CC_CHANNEL0, - nrfx_timer_us_to_ticks(&m_timer_workaround.timer, NRFX_NFCT_TIMER_PERIOD), - NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, - true); - return err_code; -} -#endif // defined(USE_TIMER_WORKAROUND) - -static inline nrf_nfct_sensres_nfcid1_size_t nrf_nfct_nfcid1_size_to_sensres_size(uint8_t nfcid1_size) -{ - switch (nfcid1_size) - { - case NRFX_NFCT_NFCID1_SINGLE_SIZE: - return NRF_NFCT_SENSRES_NFCID1_SIZE_SINGLE; - - case NRFX_NFCT_NFCID1_DOUBLE_SIZE: - return NRF_NFCT_SENSRES_NFCID1_SIZE_DOUBLE; - - case NRFX_NFCT_NFCID1_TRIPLE_SIZE: - return NRF_NFCT_SENSRES_NFCID1_SIZE_TRIPLE; - - default: - return NRF_NFCT_SENSRES_NFCID1_SIZE_DOUBLE; - } -} - -static inline void nrfx_nfct_rxtx_int_enable(uint32_t rxtx_int_mask) -{ - nrf_nfct_int_enable(rxtx_int_mask & m_nfct_cb.config.rxtx_int_mask); -} - -nrfx_err_t nrfx_nfct_init(nrfx_nfct_config_t const * p_config) -{ - NRFX_ASSERT(p_config); - - nrfx_err_t err_code = NRFX_SUCCESS; - - if (m_nfct_cb.state != NRFX_DRV_STATE_UNINITIALIZED) - { - return NRFX_ERROR_INVALID_STATE; - } - - m_nfct_cb.config = *p_config; - nrfx_nfct_hw_init_setup(); - - NRFX_IRQ_PENDING_CLEAR(NFCT_IRQn); - NRFX_IRQ_PRIORITY_SET(NFCT_IRQn, NRFX_NFCT_CONFIG_IRQ_PRIORITY); - NRFX_IRQ_ENABLE(NFCT_IRQn); - -#if defined(USE_TIMER_WORKAROUND) - /* Initialize Timer module as the workaround for NFCT HW issues. */ - err_code = nrfx_nfct_field_timer_config(); -#endif // defined(USE_TIMER_WORKAROUND) - - if (err_code == NRFX_SUCCESS) - { - uint8_t default_nfcid1[NRFX_NFCT_NFCID1_DEFAULT_LEN]; - err_code = nrfx_nfct_nfcid1_default_bytes_get(default_nfcid1, sizeof(default_nfcid1)); - NRFX_ASSERT(err_code == NRFX_SUCCESS); - nrf_nfct_nfcid1_set(default_nfcid1, NRF_NFCT_SENSRES_NFCID1_SIZE_DEFAULT); - } - else - { - return err_code; - } - - m_nfct_cb.state = NRFX_DRV_STATE_INITIALIZED; - m_nfct_cb.frame_delay_max = NFCT_FRAMEDELAYMAX_DEFAULT; - - NRFX_LOG_INFO("Initialized"); - return err_code; -} - -void nrfx_nfct_uninit(void) -{ - nrfx_nfct_disable(); - - NRFX_IRQ_DISABLE(NFCT_IRQn); - NRFX_IRQ_PENDING_CLEAR(NFCT_IRQn); - -#if defined(USE_TIMER_WORKAROUND) - /* De-initialize Timer module as the workaround for NFCT HW issues. */ - nrfx_timer_uninit(&m_timer_workaround.timer); -#endif // defined(USE_TIMER_WORKAROUND) - - m_nfct_cb.state = NRFX_DRV_STATE_UNINITIALIZED; -} - -void nrfx_nfct_enable(void) -{ - nrf_nfct_error_status_clear(NRFX_NFCT_ERROR_STATUS_ALL_MASK); - nrf_nfct_task_trigger(NRF_NFCT_TASK_SENSE); - - nrf_nfct_int_enable(NRF_NFCT_INT_FIELDDETECTED_MASK | NRF_NFCT_INT_ERROR_MASK | - NRF_NFCT_INT_SELECTED_MASK); -#if !defined(NRF52832_XXAA) && !defined(NRF52832_XXAB) - nrf_nfct_int_enable(NRF_NFCT_INT_FIELDLOST_MASK); -#endif // !defined(NRF52832_XXAA) && !defined(NRF52832_XXAB) - - NRFX_LOG_INFO("Start"); -} - -void nrfx_nfct_disable(void) -{ - nrf_nfct_int_disable(NRF_NFCT_DISABLE_ALL_INT); - nrf_nfct_task_trigger(NRF_NFCT_TASK_DISABLE); - - NRFX_LOG_INFO("Stop"); -} - -bool nrfx_nfct_field_check(void) -{ - uint32_t const field_state = nrf_nfct_field_status_get(); - - if (((field_state & NRF_NFCT_FIELD_STATE_PRESENT_MASK) == 0) && - ((field_state & NRF_NFCT_FIELD_STATE_LOCK_MASK) == 0)) - { - /* Field is not active */ - return false; - } - - return true; -} - -void nrfx_nfct_rx(nrfx_nfct_data_desc_t const * p_tx_data) -{ - NRFX_ASSERT(p_tx_data); - - nrf_nfct_rxtx_buffer_set((uint8_t *) p_tx_data->p_data, p_tx_data->data_size); - - nrfx_nfct_rxtx_int_enable(NRFX_NFCT_RX_INT_MASK); - nrf_nfct_task_trigger(NRF_NFCT_TASK_ENABLERXDATA); -} - -nrfx_err_t nrfx_nfct_tx(nrfx_nfct_data_desc_t const * p_tx_data, - nrf_nfct_frame_delay_mode_t delay_mode) -{ - NRFX_ASSERT(p_tx_data); - NRFX_ASSERT(p_tx_data->p_data); - - nrfx_err_t err = NRFX_SUCCESS; - - if (p_tx_data->data_size == 0) - { - return NRFX_ERROR_INVALID_LENGTH; - } - - NRFX_CRITICAL_SECTION_ENTER(); - - /* In case when NFC frame transmission has already started, it returns an error. */ - if (NRFX_NFCT_EVT_ACTIVE(TXFRAMESTART)) - { - err = NRFX_ERROR_BUSY; - } - else - { - /* In case when Tx operation was scheduled with delay, stop scheduled Tx operation. */ - *(volatile uint32_t *)0x40005010 = 0x01; - - nrf_nfct_rxtx_buffer_set((uint8_t *) p_tx_data->p_data, p_tx_data->data_size); - nrf_nfct_tx_bits_set(NRFX_NFCT_BYTES_TO_BITS(p_tx_data->data_size)); - nrf_nfct_frame_delay_mode_set((nrf_nfct_frame_delay_mode_t) delay_mode); - nrfx_nfct_frame_delay_max_set(false); - - nrfx_nfct_rxtx_int_enable(NRFX_NFCT_TX_INT_MASK); - nrf_nfct_task_trigger(NRF_NFCT_TASK_STARTTX); - - NRFX_LOG_INFO("Tx start"); - } - - NRFX_CRITICAL_SECTION_EXIT(); - - return err; -} - -void nrfx_nfct_state_force(nrfx_nfct_state_t state) -{ -#if defined(NRF52833_XXAA) || defined(NRF52840_XXAA) - if (state == NRFX_NFCT_STATE_ACTIVATED) - { - m_timer_workaround.is_hfclk_on = true; - /* NFCT will be activated based on additional conditions */ - nrfx_nfct_activate_check(); - return; - } -#endif // defined(NRF52833_XXAA) || defined(NRF52840_XXAA) - nrf_nfct_task_trigger((nrf_nfct_task_t) state); -} - -void nrfx_nfct_init_substate_force(nrfx_nfct_active_state_t sub_state) -{ - if (sub_state == NRFX_NFCT_ACTIVE_STATE_DEFAULT) - { -#if defined(NRF52832_XXAA) || defined(NRF52832_XXAB) - if (((*(uint32_t volatile *)(0x40005420)) & 0x1UL) == (1UL)) -#else - if (nrf_nfct_sleep_state_get() == NRF_NFCT_SLEEP_STATE_SLEEP_A) -#endif //defined(NRF52832_XXAA) || defined(NRF52832_XXAB) - { - // Default state is SLEEP_A - nrf_nfct_task_trigger(NRF_NFCT_TASK_GOSLEEP); - } - else - { - // Default state is IDLE - nrf_nfct_task_trigger(NRF_NFCT_TASK_GOIDLE); - } - } - else - { - nrf_nfct_task_trigger((nrf_nfct_task_t) sub_state); - } - - /* Begin: Workaround for anomaly 218 */ - nrfx_nfct_frame_delay_max_set(true); - /* End: Workaround for anomaly 218 */ - - /* Disable TX/RX here (will be enabled at SELECTED) */ - nrf_nfct_int_disable(NRFX_NFCT_RX_INT_MASK | NRFX_NFCT_TX_INT_MASK); -} - -nrfx_err_t nrfx_nfct_parameter_set(nrfx_nfct_param_t const * p_param) -{ - NRFX_ASSERT(p_param); - - switch (p_param->id) - { - case NRFX_NFCT_PARAM_ID_FDT: - { - uint32_t delay = p_param->data.fdt; - uint32_t delay_thr = NFCT_FRAMEDELAYMAX_FRAMEDELAYMAX_Msk; - - // Delay validation. - if (delay > (delay_thr + NRFX_NFCT_FWT_MAX_DIFF)) - { - return NRFX_ERROR_INVALID_PARAM; - } - - delay = (delay > delay_thr) ? delay_thr : delay; - m_nfct_cb.frame_delay_max = delay; - break; - } - - case NRFX_NFCT_PARAM_ID_SEL_RES: - if (p_param->data.sel_res_protocol > NRF_NFCT_SELRES_PROTOCOL_NFCDEP_T4AT) - { - return NRFX_ERROR_INVALID_PARAM; - } - - nrf_nfct_selres_protocol_set((nrf_nfct_selres_protocol_t) p_param->data.sel_res_protocol); - break; - - case NRFX_NFCT_PARAM_ID_NFCID1: - { - nrf_nfct_sensres_nfcid1_size_t id_size_mask; - - id_size_mask = nrf_nfct_nfcid1_size_to_sensres_size(p_param->data.nfcid1.id_size); - nrf_nfct_nfcid1_set(p_param->data.nfcid1.p_id, id_size_mask); - break; - } - - default: - break; - } - - return NRFX_SUCCESS; -} - -nrfx_err_t nrfx_nfct_nfcid1_default_bytes_get(uint8_t * const p_nfcid1_buff, - uint32_t nfcid1_buff_len) -{ - if ((nfcid1_buff_len != NRFX_NFCT_NFCID1_SINGLE_SIZE) && - (nfcid1_buff_len != NRFX_NFCT_NFCID1_DOUBLE_SIZE) && - (nfcid1_buff_len != NRFX_NFCT_NFCID1_TRIPLE_SIZE)) - { - return NRFX_ERROR_INVALID_LENGTH; - } - - uint32_t nfc_tag_header0 = NRF_FICR->NFC.TAGHEADER0; - uint32_t nfc_tag_header1 = NRF_FICR->NFC.TAGHEADER1; - uint32_t nfc_tag_header2 = NRF_FICR->NFC.TAGHEADER2; - - p_nfcid1_buff[0] = (uint8_t) (nfc_tag_header0 >> 0); - p_nfcid1_buff[1] = (uint8_t) (nfc_tag_header0 >> 8); - p_nfcid1_buff[2] = (uint8_t) (nfc_tag_header0 >> 16); - p_nfcid1_buff[3] = (uint8_t) (nfc_tag_header1 >> 0); - - if (nfcid1_buff_len != NRFX_NFCT_NFCID1_SINGLE_SIZE) - { - p_nfcid1_buff[4] = (uint8_t) (nfc_tag_header1 >> 8); - p_nfcid1_buff[5] = (uint8_t) (nfc_tag_header1 >> 16); - p_nfcid1_buff[6] = (uint8_t) (nfc_tag_header1 >> 24); - - if (nfcid1_buff_len == NRFX_NFCT_NFCID1_TRIPLE_SIZE) - { - p_nfcid1_buff[7] = (uint8_t) (nfc_tag_header2 >> 0); - p_nfcid1_buff[8] = (uint8_t) (nfc_tag_header2 >> 8); - p_nfcid1_buff[9] = (uint8_t) (nfc_tag_header2 >> 16); - } - /* Begin: Workaround for anomaly 181. */ - /* Workaround for wrong value in NFCID1. Value 0x88 cannot be used as byte 3 - of a double-size NFCID1, according to the NFC Forum Digital Protocol specification. */ - else if (p_nfcid1_buff[3] == 0x88) - { - p_nfcid1_buff[3] |= 0x11; - } - /* End: Workaround for anomaly 181 */ - } - - return NRFX_SUCCESS; -} - -void nrfx_nfct_autocolres_enable(void) -{ -#if defined(NRF52832_XXAA) || defined(NRF52832_XXAB) - (*(uint32_t *)(0x4000559C)) &= (~(0x1UL)); -#else - nrf_nfct_autocolres_enable(); -#endif //defined(NRF52832_XXAA) || defined(NRF52832_XXAB) -} - -void nrfx_nfct_autocolres_disable(void) -{ -#if defined(NRF52832_XXAA) || defined(NRF52832_XXAB) - (*(uint32_t *)(0x4000559C)) |= (0x1UL); -#else - nrf_nfct_autocolres_disable(); -#endif //defined(NRF52832_XXAA) || defined(NRF52832_XXAB) -} - -void nrfx_nfct_irq_handler(void) -{ - nrfx_nfct_field_state_t current_field = NRFX_NFC_FIELD_STATE_NONE; - - if (NRFX_NFCT_EVT_ACTIVE(FIELDDETECTED)) - { - nrf_nfct_event_clear(NRF_NFCT_EVENT_FIELDDETECTED); - current_field = NRFX_NFC_FIELD_STATE_ON; - - NRFX_LOG_DEBUG("Field detected"); - } - -#if !defined(NRF52832_XXAA) && !defined(NRF52832_XXAB) - if (NRFX_NFCT_EVT_ACTIVE(FIELDLOST)) - { - nrf_nfct_event_clear(NRF_NFCT_EVENT_FIELDLOST); - current_field = (current_field == NRFX_NFC_FIELD_STATE_NONE) ? - NRFX_NFC_FIELD_STATE_OFF : NRFX_NFC_FIELD_STATE_UNKNOWN; - - NRFX_LOG_DEBUG("Field lost"); - } -#endif //!defined(NRF52832_XXAA) && !defined(NRF52832_XXAB) - - /* Perform actions if any FIELD event is active */ - if (current_field != NRFX_NFC_FIELD_STATE_NONE) - { - nrfx_nfct_field_event_handler(current_field); - } - - if (NRFX_NFCT_EVT_ACTIVE(RXFRAMEEND)) - { - nrf_nfct_event_clear(NRF_NFCT_EVENT_RXFRAMEEND); - - nrfx_nfct_evt_t nfct_evt = - { - .evt_id = NRFX_NFCT_EVT_RX_FRAMEEND - }; - - /* Take into account only the number of whole bytes. */ - nfct_evt.params.rx_frameend.rx_status = 0; - nfct_evt.params.rx_frameend.rx_data.p_data = nrf_nfct_rxtx_buffer_get(); - nfct_evt.params.rx_frameend.rx_data.data_size = NRFX_NFCT_BITS_TO_BYTES(nrf_nfct_rx_bits_get(true)); - - if (NRFX_NFCT_EVT_ACTIVE(RXERROR)) - { - nfct_evt.params.rx_frameend.rx_status = - (nrf_nfct_rx_frame_status_get() & NRFX_NFCT_FRAME_STATUS_RX_ALL_MASK); - nrf_nfct_event_clear(NRF_NFCT_EVENT_RXERROR); - - NRFX_LOG_DEBUG("Rx error (0x%x)", (unsigned int) nfct_evt.params.rx_frameend.rx_status); - - /* Clear rx frame status */ - nrf_nfct_rx_frame_status_clear(NRFX_NFCT_FRAME_STATUS_RX_ALL_MASK); - } - - NRFX_NFCT_CB_HANDLE(m_nfct_cb.config.cb, nfct_evt); - - /* Clear TXFRAMESTART EVENT so it can be checked in hal_nfc_send */ - nrf_nfct_event_clear(NRF_NFCT_EVENT_TXFRAMESTART); - - NRFX_LOG_DEBUG("Rx fend"); - } - - if (NRFX_NFCT_EVT_ACTIVE(TXFRAMEEND)) - { - nrf_nfct_event_clear(NRF_NFCT_EVENT_TXFRAMEEND); - - nrfx_nfct_evt_t nfct_evt = - { - .evt_id = NRFX_NFCT_EVT_TX_FRAMEEND - }; - - /* Disable TX END event to ignore frame transmission other than READ response */ - nrf_nfct_int_disable(NRFX_NFCT_TX_INT_MASK); - - NRFX_NFCT_CB_HANDLE(m_nfct_cb.config.cb, nfct_evt); - - NRFX_LOG_DEBUG("Tx fend"); - } - - if (NRFX_NFCT_EVT_ACTIVE(SELECTED)) - { - nrf_nfct_event_clear(NRF_NFCT_EVENT_SELECTED); - /* Clear also RX END and RXERROR events because SW does not take care of - commands that were received before selecting the tag. */ - nrf_nfct_event_clear(NRF_NFCT_EVENT_RXFRAMEEND); - nrf_nfct_event_clear(NRF_NFCT_EVENT_RXERROR); - nrf_nfct_event_clear(NRF_NFCT_EVENT_TXFRAMESTART); - nrf_nfct_event_clear(NRF_NFCT_EVENT_TXFRAMEEND); - - /* Begin: Workaround for anomaly 218 */ - nrfx_nfct_frame_delay_max_set(false); - /* End: Workaround for anomaly 218 */ - - /* At this point any previous error status can be ignored. */ - nrf_nfct_rx_frame_status_clear(NRFX_NFCT_FRAME_STATUS_RX_ALL_MASK); - nrf_nfct_error_status_clear(NRFX_NFCT_ERROR_STATUS_ALL_MASK); - - nrfx_nfct_evt_t nfct_evt = - { - .evt_id = NRFX_NFCT_EVT_SELECTED - }; - NRFX_NFCT_CB_HANDLE(m_nfct_cb.config.cb, nfct_evt); - - NRFX_LOG_DEBUG("Selected"); - } - - if (NRFX_NFCT_EVT_ACTIVE(ERROR)) - { - uint32_t err_status = nrf_nfct_error_status_get(); - nrf_nfct_event_clear(NRF_NFCT_EVENT_ERROR); - - nrfx_nfct_evt_t nfct_evt = - { - .evt_id = NRFX_NFCT_EVT_ERROR - }; - - /* Clear FRAMEDELAYTIMEOUT error (expected HW behaviour) when SLP_REQ command was received. */ - if (err_status & NRF_NFCT_ERROR_FRAMEDELAYTIMEOUT_MASK) - { - nrf_nfct_error_status_clear(NRF_NFCT_ERROR_FRAMEDELAYTIMEOUT_MASK); - - nfct_evt.params.error.reason = NRFX_NFCT_ERROR_FRAMEDELAYTIMEOUT; - NRFX_NFCT_CB_HANDLE(m_nfct_cb.config.cb, nfct_evt); - } - - /* Report any other error. */ - err_status &= ~NRF_NFCT_ERROR_FRAMEDELAYTIMEOUT_MASK; - if (err_status) - { - NRFX_LOG_DEBUG("Error (0x%x)", (unsigned int) err_status); - } - - /* Clear error status. */ - nrf_nfct_error_status_clear(NRFX_NFCT_ERROR_STATUS_ALL_MASK); - } - - if (NRFX_NFCT_EVT_ACTIVE(TXFRAMESTART)) - { - nrf_nfct_event_clear(NRF_NFCT_EVENT_TXFRAMESTART); - - if (m_nfct_cb.config.cb != NULL) - { - nrfx_nfct_evt_t nfct_evt; - - nfct_evt.evt_id = NRFX_NFCT_EVT_TX_FRAMESTART; - nfct_evt.params.tx_framestart.tx_data.p_data = nrf_nfct_rxtx_buffer_get(); - nfct_evt.params.tx_framestart.tx_data.data_size = NRFX_NFCT_BITS_TO_BYTES(nrf_nfct_tx_bits_get()); - - m_nfct_cb.config.cb(&nfct_evt); - } - } -} - -#endif // NRFX_CHECK(NRFX_NFCT_ENABLED) diff --git a/modules/nrfx/drivers/src/nrfx_pdm.c b/modules/nrfx/drivers/src/nrfx_pdm.c deleted file mode 100644 index 4500b7d..0000000 --- a/modules/nrfx/drivers/src/nrfx_pdm.c +++ /dev/null @@ -1,370 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include - -#if NRFX_CHECK(NRFX_PDM_ENABLED) - -#include -#include - -#define NRFX_LOG_MODULE PDM -#include - -#define EVT_TO_STR(event) \ - (event == NRF_PDM_EVENT_STARTED ? "NRF_PDM_EVENT_STARTED" : \ - (event == NRF_PDM_EVENT_STOPPED ? "NRF_PDM_EVENT_STOPPED" : \ - (event == NRF_PDM_EVENT_END ? "NRF_PDM_EVENT_END" : \ - "UNKNOWN EVENT"))) - - -/** @brief PDM interface status. */ -typedef enum -{ - NRFX_PDM_STATE_IDLE, - NRFX_PDM_STATE_RUNNING, - NRFX_PDM_STATE_STARTING, - NRFX_PDM_STATE_STOPPING -} nrfx_pdm_state_t; - -/** @brief PDM interface control block.*/ -typedef struct -{ - nrfx_pdm_event_handler_t event_handler; ///< Event handler function pointer. - int16_t * buff_address[2]; ///< Sample buffers. - uint16_t buff_length[2]; ///< Length of the sample buffers. - nrfx_drv_state_t drv_state; ///< Driver state. - volatile nrfx_pdm_state_t op_state; ///< PDM peripheral operation state. - uint8_t active_buffer; ///< Number of currently active buffer. - uint8_t error; ///< Driver error flag. - volatile uint8_t irq_buff_request; ///< Request the next buffer in the ISR. -} nrfx_pdm_cb_t; - -static nrfx_pdm_cb_t m_cb; - - -void nrfx_pdm_irq_handler(void) -{ - if (nrf_pdm_event_check(NRF_PDM_EVENT_STARTED)) - { - nrf_pdm_event_clear(NRF_PDM_EVENT_STARTED); - NRFX_LOG_DEBUG("Event: %s.", EVT_TO_STR(NRF_PDM_EVENT_STARTED)); - - uint8_t finished_buffer = m_cb.active_buffer; - - // Check if the next buffer was set before. - uint8_t next_buffer = (~m_cb.active_buffer) & 0x01; - if (m_cb.buff_address[next_buffer] || - m_cb.op_state == NRFX_PDM_STATE_STARTING) - { - nrfx_pdm_evt_t evt; - evt.error = NRFX_PDM_NO_ERROR; - m_cb.error = 0; - - // Release the full buffer if ready and request the next one. - if (m_cb.op_state == NRFX_PDM_STATE_STARTING) - { - evt.buffer_released = 0; - m_cb.op_state = NRFX_PDM_STATE_RUNNING; - } - else - { - evt.buffer_released = m_cb.buff_address[finished_buffer]; - m_cb.buff_address[finished_buffer] = 0; - m_cb.active_buffer = next_buffer; - } - evt.buffer_requested = true; - m_cb.event_handler(&evt); - } - else - { - // No next buffer available. Report an error. - // Do not request the new buffer as it was already done. - if (m_cb.error == 0) - { - nrfx_pdm_evt_t const evt = { - .buffer_requested = false, - .buffer_released = NULL, - .error = NRFX_PDM_ERROR_OVERFLOW - }; - m_cb.error = 1; - m_cb.event_handler(&evt); - } - } - - if (m_cb.op_state == NRFX_PDM_STATE_STARTING) - { - m_cb.op_state = NRFX_PDM_STATE_RUNNING; - } - } - else if (nrf_pdm_event_check(NRF_PDM_EVENT_STOPPED)) - { - nrf_pdm_event_clear(NRF_PDM_EVENT_STOPPED); - NRFX_LOG_DEBUG("Event: %s.", EVT_TO_STR(NRF_PDM_EVENT_STOPPED)); - nrf_pdm_disable(); - m_cb.op_state = NRFX_PDM_STATE_IDLE; - - // Release the buffers. - nrfx_pdm_evt_t evt; - evt.error = NRFX_PDM_NO_ERROR; - evt.buffer_requested = false; - if (m_cb.buff_address[m_cb.active_buffer]) - { - evt.buffer_released = m_cb.buff_address[m_cb.active_buffer]; - m_cb.buff_address[m_cb.active_buffer] = 0; - m_cb.event_handler(&evt); - } - - uint8_t second_buffer = (~m_cb.active_buffer) & 0x01; - if (m_cb.buff_address[second_buffer]) - { - evt.buffer_released = m_cb.buff_address[second_buffer]; - m_cb.buff_address[second_buffer] = 0; - m_cb.event_handler(&evt); - } - m_cb.active_buffer = 0; - } - - if (m_cb.irq_buff_request) - { - nrfx_pdm_evt_t const evt = - { - .buffer_requested = true, - .buffer_released = NULL, - .error = NRFX_PDM_NO_ERROR, - }; - m_cb.irq_buff_request = 0; - m_cb.event_handler(&evt); - } -} - - -nrfx_err_t nrfx_pdm_init(nrfx_pdm_config_t const * p_config, - nrfx_pdm_event_handler_t event_handler) -{ - NRFX_ASSERT(p_config); - NRFX_ASSERT(event_handler); - nrfx_err_t err_code; - - if (m_cb.drv_state != NRFX_DRV_STATE_UNINITIALIZED) - { - err_code = NRFX_ERROR_INVALID_STATE; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - - if (p_config->gain_l > NRF_PDM_GAIN_MAXIMUM || - p_config->gain_r > NRF_PDM_GAIN_MAXIMUM) - { - err_code = NRFX_ERROR_INVALID_PARAM; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - - m_cb.buff_address[0] = 0; - m_cb.buff_address[1] = 0; - m_cb.active_buffer = 0; - m_cb.error = 0; - m_cb.event_handler = event_handler; - m_cb.op_state = NRFX_PDM_STATE_IDLE; - - nrf_pdm_clock_set(p_config->clock_freq); - nrf_pdm_mode_set(p_config->mode, p_config->edge); - nrf_pdm_gain_set(p_config->gain_l, p_config->gain_r); - - nrf_gpio_cfg_output(p_config->pin_clk); - nrf_gpio_pin_clear(p_config->pin_clk); - nrf_gpio_cfg_input(p_config->pin_din, NRF_GPIO_PIN_NOPULL); - nrf_pdm_psel_connect(p_config->pin_clk, p_config->pin_din); - - nrf_pdm_event_clear(NRF_PDM_EVENT_STARTED); - nrf_pdm_event_clear(NRF_PDM_EVENT_END); - nrf_pdm_event_clear(NRF_PDM_EVENT_STOPPED); - nrf_pdm_int_enable(NRF_PDM_INT_STARTED | NRF_PDM_INT_STOPPED); - NRFX_IRQ_PRIORITY_SET(PDM_IRQn, p_config->interrupt_priority); - NRFX_IRQ_ENABLE(PDM_IRQn); - m_cb.drv_state = NRFX_DRV_STATE_INITIALIZED; - - err_code = NRFX_SUCCESS; - NRFX_LOG_INFO("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; -} - -void nrfx_pdm_uninit(void) -{ - nrf_pdm_disable(); - nrf_pdm_psel_disconnect(); - m_cb.drv_state = NRFX_DRV_STATE_UNINITIALIZED; - NRFX_LOG_INFO("Uninitialized."); -} - -static void pdm_start() -{ - m_cb.drv_state = NRFX_DRV_STATE_POWERED_ON; - nrf_pdm_enable(); - nrf_pdm_event_clear(NRF_PDM_EVENT_STARTED); - nrf_pdm_task_trigger(NRF_PDM_TASK_START); -} - -static void pdm_buf_request() -{ - m_cb.irq_buff_request = 1; - NRFX_IRQ_PENDING_SET(PDM_IRQn); -} - -nrfx_err_t nrfx_pdm_start(void) -{ - NRFX_ASSERT(m_cb.drv_state != NRFX_DRV_STATE_UNINITIALIZED); - nrfx_err_t err_code; - - if (m_cb.op_state != NRFX_PDM_STATE_IDLE) - { - if (m_cb.op_state == NRFX_PDM_STATE_RUNNING) - { - err_code = NRFX_SUCCESS; - NRFX_LOG_INFO("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - err_code = NRFX_ERROR_BUSY; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - - m_cb.op_state = NRFX_PDM_STATE_STARTING; - pdm_buf_request(); - - err_code = NRFX_SUCCESS; - NRFX_LOG_INFO("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; -} - -nrfx_err_t nrfx_pdm_buffer_set(int16_t * buffer, uint16_t buffer_length) -{ - if (m_cb.drv_state == NRFX_DRV_STATE_UNINITIALIZED) - { - return NRFX_ERROR_INVALID_STATE; - } - if (m_cb.op_state == NRFX_PDM_STATE_STOPPING) - { - return NRFX_ERROR_BUSY; - } - if ((buffer == NULL) || (buffer_length > NRFX_PDM_MAX_BUFFER_SIZE)) - { - return NRFX_ERROR_INVALID_PARAM; - } - - nrfx_err_t err_code = NRFX_SUCCESS; - - // Enter the PDM critical section. - NRFX_IRQ_DISABLE(PDM_IRQn); - - uint8_t next_buffer = (~m_cb.active_buffer) & 0x01; - if (m_cb.op_state == NRFX_PDM_STATE_STARTING) - { - next_buffer = 0; - } - - if (m_cb.buff_address[next_buffer]) - { - // Buffer already set. - err_code = NRFX_ERROR_BUSY; - } - else - { - m_cb.buff_address[next_buffer] = buffer; - m_cb.buff_length[next_buffer] = buffer_length; - nrf_pdm_buffer_set((uint32_t *)buffer, buffer_length); - - if (m_cb.drv_state != NRFX_DRV_STATE_POWERED_ON) - { - pdm_start(); - } - } - - NRFX_IRQ_ENABLE(PDM_IRQn); - return err_code; -} - -nrfx_err_t nrfx_pdm_stop(void) -{ - NRFX_ASSERT(m_cb.drv_state != NRFX_DRV_STATE_UNINITIALIZED); - nrfx_err_t err_code; - - if (m_cb.op_state != NRFX_PDM_STATE_RUNNING) - { - if (m_cb.op_state == NRFX_PDM_STATE_IDLE || - m_cb.op_state == NRFX_PDM_STATE_STARTING) - { - nrf_pdm_disable(); - m_cb.op_state = NRFX_PDM_STATE_IDLE; - err_code = NRFX_SUCCESS; - NRFX_LOG_INFO("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - err_code = NRFX_ERROR_BUSY; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - m_cb.drv_state = NRFX_DRV_STATE_INITIALIZED; - m_cb.op_state = NRFX_PDM_STATE_STOPPING; - - nrf_pdm_task_trigger(NRF_PDM_TASK_STOP); - err_code = NRFX_SUCCESS; - NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; -} - -#endif // NRFX_CHECK(NRFX_PDM_ENABLED) diff --git a/modules/nrfx/drivers/src/nrfx_qdec.c b/modules/nrfx/drivers/src/nrfx_qdec.c deleted file mode 100644 index 71bcc5b..0000000 --- a/modules/nrfx/drivers/src/nrfx_qdec.c +++ /dev/null @@ -1,204 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include - -#if NRFX_CHECK(NRFX_QDEC_ENABLED) - -#include -#include - -#define NRFX_LOG_MODULE QDEC -#include - -#define EVT_TO_STR(event) \ - (event == NRF_QDEC_EVENT_SAMPLERDY ? "NRF_QDEC_EVENT_SAMPLERDY" : \ - (event == NRF_QDEC_EVENT_REPORTRDY ? "NRF_QDEC_EVENT_REPORTRDY" : \ - (event == NRF_QDEC_EVENT_ACCOF ? "NRF_QDEC_EVENT_ACCOF" : \ - "UNKNOWN EVENT"))) - - -static nrfx_qdec_event_handler_t m_qdec_event_handler = NULL; -static nrfx_drv_state_t m_state = NRFX_DRV_STATE_UNINITIALIZED; - -void nrfx_qdec_irq_handler(void) -{ - nrfx_qdec_event_t event; - if ( nrf_qdec_event_check(NRF_QDEC_EVENT_SAMPLERDY) && - nrf_qdec_int_enable_check(NRF_QDEC_INT_SAMPLERDY_MASK) ) - { - nrf_qdec_event_clear(NRF_QDEC_EVENT_SAMPLERDY); - NRFX_LOG_DEBUG("Event: %s.", EVT_TO_STR(NRF_QDEC_EVENT_SAMPLERDY)); - - event.type = NRF_QDEC_EVENT_SAMPLERDY; - event.data.sample.value = (int8_t)nrf_qdec_sample_get(); - m_qdec_event_handler(event); - } - - if ( nrf_qdec_event_check(NRF_QDEC_EVENT_REPORTRDY) && - nrf_qdec_int_enable_check(NRF_QDEC_INT_REPORTRDY_MASK) ) - { - nrf_qdec_event_clear(NRF_QDEC_EVENT_REPORTRDY); - NRFX_LOG_DEBUG("Event: %s.", EVT_TO_STR(NRF_QDEC_EVENT_REPORTRDY)); - - event.type = NRF_QDEC_EVENT_REPORTRDY; - - event.data.report.acc = (int16_t)nrf_qdec_accread_get(); - event.data.report.accdbl = (uint16_t)nrf_qdec_accdblread_get(); - m_qdec_event_handler(event); - } - - if ( nrf_qdec_event_check(NRF_QDEC_EVENT_ACCOF) && - nrf_qdec_int_enable_check(NRF_QDEC_INT_ACCOF_MASK) ) - { - nrf_qdec_event_clear(NRF_QDEC_EVENT_ACCOF); - NRFX_LOG_DEBUG("Event: %s.", EVT_TO_STR(NRF_QDEC_EVENT_ACCOF)); - - event.type = NRF_QDEC_EVENT_ACCOF; - m_qdec_event_handler(event); - } -} - - -nrfx_err_t nrfx_qdec_init(nrfx_qdec_config_t const * p_config, - nrfx_qdec_event_handler_t event_handler) -{ - NRFX_ASSERT(p_config); - NRFX_ASSERT(event_handler); - nrfx_err_t err_code; - - if (m_state != NRFX_DRV_STATE_UNINITIALIZED) - { - err_code = NRFX_ERROR_INVALID_STATE; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - - m_qdec_event_handler = event_handler; - - nrf_qdec_sampleper_set(p_config->sampleper); - nrf_gpio_cfg_input(p_config->psela, NRF_GPIO_PIN_NOPULL); - nrf_gpio_cfg_input(p_config->pselb, NRF_GPIO_PIN_NOPULL); - if (p_config->pselled != NRF_QDEC_LED_NOT_CONNECTED) - { - nrf_gpio_cfg_input(p_config->pselled, NRF_GPIO_PIN_NOPULL); - nrf_qdec_ledpre_set(p_config->ledpre); - nrf_qdec_ledpol_set(p_config->ledpol); - } - nrf_qdec_pio_assign(p_config->psela, p_config->pselb, p_config->pselled); - nrf_qdec_shorts_enable(NRF_QDEC_SHORT_REPORTRDY_READCLRACC_MASK); - - if (p_config->dbfen) - { - nrf_qdec_dbfen_enable(); - } - else - { - nrf_qdec_dbfen_disable(); - } - - uint32_t int_mask = NRF_QDEC_INT_ACCOF_MASK; - - if (p_config->reportper != NRF_QDEC_REPORTPER_DISABLED) - { - nrf_qdec_reportper_set(p_config->reportper); - int_mask |= NRF_QDEC_INT_REPORTRDY_MASK; - } - - if (p_config->sample_inten) - { - int_mask |= NRF_QDEC_INT_SAMPLERDY_MASK; - } - - nrf_qdec_int_enable(int_mask); - NRFX_IRQ_PRIORITY_SET(QDEC_IRQn, p_config->interrupt_priority); - NRFX_IRQ_ENABLE(QDEC_IRQn); - - m_state = NRFX_DRV_STATE_INITIALIZED; - - err_code = NRFX_SUCCESS; - NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; -} - -void nrfx_qdec_uninit(void) -{ - NRFX_ASSERT(m_state != NRFX_DRV_STATE_UNINITIALIZED); - nrfx_qdec_disable(); - NRFX_IRQ_DISABLE(QDEC_IRQn); - m_state = NRFX_DRV_STATE_UNINITIALIZED; - NRFX_LOG_INFO("Uninitialized."); -} - -void nrfx_qdec_enable(void) -{ - NRFX_ASSERT(m_state == NRFX_DRV_STATE_INITIALIZED); - nrf_qdec_enable(); - nrf_qdec_task_trigger(NRF_QDEC_TASK_START); - m_state = NRFX_DRV_STATE_POWERED_ON; - NRFX_LOG_INFO("Enabled."); -} - -void nrfx_qdec_disable(void) -{ - NRFX_ASSERT(m_state == NRFX_DRV_STATE_POWERED_ON); - nrf_qdec_task_trigger(NRF_QDEC_TASK_STOP); - nrf_qdec_disable(); - m_state = NRFX_DRV_STATE_INITIALIZED; - NRFX_LOG_INFO("Disabled."); -} - -void nrfx_qdec_accumulators_read(int16_t * p_acc, int16_t * p_accdbl) -{ - NRFX_ASSERT(m_state == NRFX_DRV_STATE_POWERED_ON); - nrf_qdec_task_trigger(NRF_QDEC_TASK_READCLRACC); - - *p_acc = (int16_t)nrf_qdec_accread_get(); - *p_accdbl = (int16_t)nrf_qdec_accdblread_get(); - - NRFX_LOG_DEBUG("Accumulators data, ACC register:"); - NRFX_LOG_HEXDUMP_DEBUG((uint8_t *)p_acc, sizeof(p_acc[0])); - NRFX_LOG_DEBUG("Accumulators data, ACCDBL register:"); - NRFX_LOG_HEXDUMP_DEBUG((uint8_t *)p_accdbl, sizeof(p_accdbl[0])); -} - -#endif // NRFX_CHECK(NRFX_QDEC_ENABLED) diff --git a/modules/nrfx/drivers/src/nrfx_qspi.c b/modules/nrfx/drivers/src/nrfx_qspi.c deleted file mode 100644 index b7c6a3a..0000000 --- a/modules/nrfx/drivers/src/nrfx_qspi.c +++ /dev/null @@ -1,464 +0,0 @@ -/** - * Copyright (c) 2016 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include - -#if NRFX_CHECK(NRFX_QSPI_ENABLED) - -#include -#include - -/** @brief Command byte used to read status register. */ -#define QSPI_STD_CMD_RDSR 0x05 - -/** @brief Byte used to mask status register and retrieve the write-in-progess bit. */ -#define QSPI_MEM_STATUSREG_WIP_Pos 0x01 - -/** @brief Default time used in timeout function. */ -#define QSPI_DEF_WAIT_TIME_US 10 - -/** @brief Default number of tries in timeout function. */ -#define QSPI_DEF_WAIT_ATTEMPTS 100 - -/** - * @brief Macro for initializing a QSPI pin. - * - * QSPI peripheral expects high drive pin strength. - */ -#define QSPI_PIN_INIT(_pin) nrf_gpio_cfg((_pin), \ - NRF_GPIO_PIN_DIR_INPUT, \ - NRF_GPIO_PIN_INPUT_DISCONNECT, \ - NRF_GPIO_PIN_NOPULL, \ - NRF_GPIO_PIN_H0H1, \ - NRF_GPIO_PIN_NOSENSE) - -/** @brief Control block - driver instance local data. */ -typedef struct -{ - nrfx_qspi_handler_t handler; /**< Handler. */ - nrfx_drv_state_t state; /**< Driver state. */ - volatile bool is_busy; /**< Flag indicating that an operation is currently being performed. */ - void * p_context; /**< Driver context used in interrupt. */ -} qspi_control_block_t; - -static qspi_control_block_t m_cb; - -static nrfx_err_t qspi_task_perform(nrf_qspi_task_t task) -{ - // Wait for peripheral - if (m_cb.is_busy) - { - return NRFX_ERROR_BUSY; - } - - nrf_qspi_event_clear(NRF_QSPI, NRF_QSPI_EVENT_READY); - - if (m_cb.handler) - { - m_cb.is_busy = true; - nrf_qspi_int_enable(NRF_QSPI, NRF_QSPI_INT_READY_MASK); - } - - nrf_qspi_task_trigger(NRF_QSPI, task); - - if (m_cb.handler == NULL) - { - while (!nrf_qspi_event_check(NRF_QSPI, NRF_QSPI_EVENT_READY)) - {}; - } - return NRFX_SUCCESS; -} - -static bool qspi_pins_configure(nrf_qspi_pins_t const * p_config) -{ - // Check if the user set meaningful values to struct fields. If not, return false. - if ((p_config->sck_pin == NRF_QSPI_PIN_NOT_CONNECTED) || - (p_config->csn_pin == NRF_QSPI_PIN_NOT_CONNECTED) || - (p_config->io0_pin == NRF_QSPI_PIN_NOT_CONNECTED) || - (p_config->io1_pin == NRF_QSPI_PIN_NOT_CONNECTED)) - { - return false; - } - - QSPI_PIN_INIT(p_config->sck_pin); - QSPI_PIN_INIT(p_config->csn_pin); - QSPI_PIN_INIT(p_config->io0_pin); - QSPI_PIN_INIT(p_config->io1_pin); - if (p_config->io2_pin != NRF_QSPI_PIN_NOT_CONNECTED) - { - QSPI_PIN_INIT(p_config->io2_pin); - } - if (p_config->io3_pin != NRF_QSPI_PIN_NOT_CONNECTED) - { - QSPI_PIN_INIT(p_config->io3_pin); - } - - nrf_qspi_pins_set(NRF_QSPI, p_config); - - return true; -} - -static void qspi_pins_deconfigure(void) -{ - nrf_qspi_pins_t pins; - nrf_qspi_pins_get(NRF_QSPI, &pins); - - nrf_gpio_cfg_default(pins.sck_pin); - nrf_gpio_cfg_default(pins.csn_pin); - nrf_gpio_cfg_default(pins.io0_pin); - nrf_gpio_cfg_default(pins.io1_pin); - if (pins.io2_pin != NRF_QSPI_PIN_NOT_CONNECTED) - { - nrf_gpio_cfg_default(pins.io2_pin); - } - if (pins.io3_pin != NRF_QSPI_PIN_NOT_CONNECTED) - { - nrf_gpio_cfg_default(pins.io3_pin); - } -} - -static nrfx_err_t qspi_ready_wait(void) -{ - bool result; - NRFX_WAIT_FOR(nrf_qspi_event_check(NRF_QSPI, NRF_QSPI_EVENT_READY), - QSPI_DEF_WAIT_ATTEMPTS, - QSPI_DEF_WAIT_TIME_US, - result); - if (!result) - { - return NRFX_ERROR_TIMEOUT; - } - - return NRFX_SUCCESS; -} - -nrfx_err_t nrfx_qspi_init(nrfx_qspi_config_t const * p_config, - nrfx_qspi_handler_t handler, - void * p_context) -{ - NRFX_ASSERT(p_config); - if (m_cb.state != NRFX_DRV_STATE_UNINITIALIZED) - { - return NRFX_ERROR_INVALID_STATE; - } - - if (!qspi_pins_configure(&p_config->pins)) - { - return NRFX_ERROR_INVALID_PARAM; - } - - nrf_qspi_xip_offset_set(NRF_QSPI, p_config->xip_offset); - nrf_qspi_ifconfig0_set(NRF_QSPI, &p_config->prot_if); - nrf_qspi_ifconfig1_set(NRF_QSPI, &p_config->phy_if); - - m_cb.is_busy = false; - m_cb.handler = handler; - m_cb.p_context = p_context; - - /* QSPI interrupt is disabled because the device should be enabled in polling mode (wait for activate - task event ready)*/ - nrf_qspi_int_disable(NRF_QSPI, NRF_QSPI_INT_READY_MASK); - - if (handler) - { - NRFX_IRQ_PRIORITY_SET(QSPI_IRQn, p_config->irq_priority); - NRFX_IRQ_ENABLE(QSPI_IRQn); - } - - m_cb.state = NRFX_DRV_STATE_INITIALIZED; - - nrf_qspi_enable(NRF_QSPI); - - nrf_qspi_event_clear(NRF_QSPI, NRF_QSPI_EVENT_READY); - nrf_qspi_task_trigger(NRF_QSPI, NRF_QSPI_TASK_ACTIVATE); - - // Waiting for the peripheral to activate - - return qspi_ready_wait(); -} - -nrfx_err_t nrfx_qspi_cinstr_xfer(nrf_qspi_cinstr_conf_t const * p_config, - void const * p_tx_buffer, - void * p_rx_buffer) -{ - NRFX_ASSERT(m_cb.state != NRFX_DRV_STATE_UNINITIALIZED); - - if (m_cb.is_busy) - { - return NRFX_ERROR_BUSY; - } - - nrf_qspi_event_clear(NRF_QSPI, NRF_QSPI_EVENT_READY); - /* In some cases, only opcode should be sent. To prevent execution, set function code is - * surrounded by an if. - */ - if (p_tx_buffer) - { - nrf_qspi_cinstrdata_set(NRF_QSPI, p_config->length, p_tx_buffer); - } - - nrf_qspi_int_disable(NRF_QSPI, NRF_QSPI_INT_READY_MASK); - - nrf_qspi_cinstr_transfer_start(NRF_QSPI, p_config); - - if (qspi_ready_wait() == NRFX_ERROR_TIMEOUT) - { - // This timeout should never occur when WIPWAIT is not active, since in this - // case the QSPI peripheral should send the command immediately, without any - // waiting for previous write to complete. - NRFX_ASSERT(p_config->wipwait); - - return NRFX_ERROR_TIMEOUT; - } - nrf_qspi_event_clear(NRF_QSPI, NRF_QSPI_EVENT_READY); - - if (p_rx_buffer) - { - nrf_qspi_cinstrdata_get(NRF_QSPI, p_config->length, p_rx_buffer); - } - - return NRFX_SUCCESS; -} - -nrfx_err_t nrfx_qspi_cinstr_quick_send(uint8_t opcode, - nrf_qspi_cinstr_len_t length, - void const * p_tx_buffer) -{ - nrf_qspi_cinstr_conf_t config = NRFX_QSPI_DEFAULT_CINSTR(opcode, length); - return nrfx_qspi_cinstr_xfer(&config, p_tx_buffer, NULL); -} - -nrfx_err_t nrfx_qspi_lfm_start(nrf_qspi_cinstr_conf_t const * p_config) -{ - NRFX_ASSERT(m_cb.state != NRFX_DRV_STATE_UNINITIALIZED); - NRFX_ASSERT(!(nrf_qspi_cinstr_long_transfer_is_ongoing(NRF_QSPI))); - NRFX_ASSERT(p_config->length == NRF_QSPI_CINSTR_LEN_1B); - - if (m_cb.is_busy) - { - return NRFX_ERROR_BUSY; - } - - nrf_qspi_cinstr_long_transfer_start(NRF_QSPI, p_config); - - if (qspi_ready_wait() == NRFX_ERROR_TIMEOUT) - { - /* In case of error, abort long frame mode */ - nrf_qspi_cinstr_long_transfer_continue(NRF_QSPI, NRF_QSPI_CINSTR_LEN_1B, true); - return NRFX_ERROR_TIMEOUT; - } - - m_cb.is_busy = true; - return NRFX_SUCCESS; -} - -nrfx_err_t nrfx_qspi_lfm_xfer(void const * p_tx_buffer, - void * p_rx_buffer, - size_t transfer_length, - bool finalize) -{ - NRFX_ASSERT(m_cb.state != NRFX_DRV_STATE_UNINITIALIZED); - NRFX_ASSERT(nrf_qspi_cinstr_long_transfer_is_ongoing(NRF_QSPI)); - - nrfx_err_t status = NRFX_SUCCESS; - - /* Perform transfers in packets of 8 bytes. Last transfer may be shorter. */ - nrf_qspi_cinstr_len_t length = NRF_QSPI_CINSTR_LEN_9B; - for (uint32_t curr_byte = 0; curr_byte < transfer_length; curr_byte += 8) - { - uint32_t remaining_bytes = transfer_length - curr_byte; - if (remaining_bytes < 8) - { - length = (nrf_qspi_cinstr_len_t)(remaining_bytes + 1); - } - - if (p_tx_buffer) - { - nrf_qspi_cinstrdata_set(NRF_QSPI, - length, - &((uint8_t const *)p_tx_buffer)[curr_byte]); - } - - nrf_qspi_event_clear(NRF_QSPI, NRF_QSPI_EVENT_READY); - - if (remaining_bytes <= 8) - { - nrf_qspi_cinstr_long_transfer_continue(NRF_QSPI, length, finalize); - } - else - { - nrf_qspi_cinstr_long_transfer_continue(NRF_QSPI, length, false); - } - - if (qspi_ready_wait() == NRFX_ERROR_TIMEOUT) - { - /* In case of error, abort long frame mode */ - nrf_qspi_cinstr_long_transfer_continue(NRF_QSPI, NRF_QSPI_CINSTR_LEN_1B, true); - status = NRFX_ERROR_TIMEOUT; - break; - } - - if (p_rx_buffer) - { - nrf_qspi_cinstrdata_get(NRF_QSPI, - length, - &((uint8_t *)p_rx_buffer)[curr_byte]); - } - } - nrf_qspi_event_clear(NRF_QSPI, NRF_QSPI_EVENT_READY); - - if ((finalize) || (status == NRFX_ERROR_TIMEOUT)) - { - m_cb.is_busy = false; - } - - return status; -} - -nrfx_err_t nrfx_qspi_mem_busy_check(void) -{ - nrfx_err_t ret_code; - uint8_t status_value = 0; - - nrf_qspi_cinstr_conf_t const config = - NRFX_QSPI_DEFAULT_CINSTR(QSPI_STD_CMD_RDSR, - NRF_QSPI_CINSTR_LEN_2B); - ret_code = nrfx_qspi_cinstr_xfer(&config, &status_value, &status_value); - - if (ret_code != NRFX_SUCCESS) - { - return ret_code; - } - - if ((status_value & QSPI_MEM_STATUSREG_WIP_Pos) != 0x00) - { - return NRFX_ERROR_BUSY; - } - - return NRFX_SUCCESS; -} - -void nrfx_qspi_uninit(void) -{ - NRFX_ASSERT(m_cb.state != NRFX_DRV_STATE_UNINITIALIZED); - - if (nrf_qspi_cinstr_long_transfer_is_ongoing(NRF_QSPI)) - { - nrf_qspi_cinstr_long_transfer_continue(NRF_QSPI, NRF_QSPI_CINSTR_LEN_1B, true); - } - - NRFX_IRQ_DISABLE(QSPI_IRQn); - - nrf_qspi_int_disable(NRF_QSPI, NRF_QSPI_INT_READY_MASK); - - nrf_qspi_task_trigger(NRF_QSPI, NRF_QSPI_TASK_DEACTIVATE); - - nrf_qspi_disable(NRF_QSPI); - - nrf_qspi_event_clear(NRF_QSPI, NRF_QSPI_EVENT_READY); - - qspi_pins_deconfigure(); - - m_cb.state = NRFX_DRV_STATE_UNINITIALIZED; -} - -nrfx_err_t nrfx_qspi_write(void const * p_tx_buffer, - size_t tx_buffer_length, - uint32_t dst_address) -{ - NRFX_ASSERT(m_cb.state != NRFX_DRV_STATE_UNINITIALIZED); - NRFX_ASSERT(p_tx_buffer != NULL); - - if (!nrfx_is_in_ram(p_tx_buffer) || !nrfx_is_word_aligned(p_tx_buffer)) - { - return NRFX_ERROR_INVALID_ADDR; - } - - nrf_qspi_write_buffer_set(NRF_QSPI, p_tx_buffer, tx_buffer_length, dst_address); - return qspi_task_perform(NRF_QSPI_TASK_WRITESTART); -} - -nrfx_err_t nrfx_qspi_read(void * p_rx_buffer, - size_t rx_buffer_length, - uint32_t src_address) -{ - NRFX_ASSERT(m_cb.state != NRFX_DRV_STATE_UNINITIALIZED); - NRFX_ASSERT(p_rx_buffer != NULL); - - if (!nrfx_is_in_ram(p_rx_buffer) || !nrfx_is_word_aligned(p_rx_buffer)) - { - return NRFX_ERROR_INVALID_ADDR; - } - - nrf_qspi_read_buffer_set(NRF_QSPI, p_rx_buffer, rx_buffer_length, src_address); - return qspi_task_perform(NRF_QSPI_TASK_READSTART); -} - -nrfx_err_t nrfx_qspi_erase(nrf_qspi_erase_len_t length, - uint32_t start_address) -{ - NRFX_ASSERT(m_cb.state != NRFX_DRV_STATE_UNINITIALIZED); - - if (!nrfx_is_word_aligned((void const *)start_address)) - { - return NRFX_ERROR_INVALID_ADDR; - } - - nrf_qspi_erase_ptr_set(NRF_QSPI, start_address, length); - return qspi_task_perform(NRF_QSPI_TASK_ERASESTART); -} - -nrfx_err_t nrfx_qspi_chip_erase(void) -{ - return nrfx_qspi_erase(NRF_QSPI_ERASE_LEN_ALL, 0); -} - -void nrfx_qspi_irq_handler(void) -{ - // Catch Event ready interrupts - if (nrf_qspi_event_check(NRF_QSPI, NRF_QSPI_EVENT_READY)) - { - m_cb.is_busy = false; - nrf_qspi_event_clear(NRF_QSPI, NRF_QSPI_EVENT_READY); - m_cb.handler(NRFX_QSPI_EVENT_DONE, m_cb.p_context); - } -} - -#endif // NRFX_CHECK(NRFX_QSPI_ENABLED) diff --git a/modules/nrfx/drivers/src/nrfx_spis.c b/modules/nrfx/drivers/src/nrfx_spis.c deleted file mode 100644 index f593ee5..0000000 --- a/modules/nrfx/drivers/src/nrfx_spis.c +++ /dev/null @@ -1,513 +0,0 @@ -/** - * Copyright (c) 2013 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include - -#if NRFX_CHECK(NRFX_SPIS_ENABLED) - -#if !(NRFX_CHECK(NRFX_SPIS0_ENABLED) || \ - NRFX_CHECK(NRFX_SPIS1_ENABLED) || \ - NRFX_CHECK(NRFX_SPIS2_ENABLED) || \ - NRFX_CHECK(NRFX_SPIS3_ENABLED)) -#error "No enabled SPIS instances. Check ." -#endif - -#include -#include "prs/nrfx_prs.h" - -#define NRFX_LOG_MODULE SPIS -#include - -#define EVT_TO_STR(event) \ - (event == NRF_SPIS_EVENT_ACQUIRED ? "NRF_SPIS_EVENT_ACQUIRED" : \ - (event == NRF_SPIS_EVENT_END ? "NRF_SPIS_EVENT_END" : \ - "UNKNOWN ERROR")) - -#define SPISX_LENGTH_VALIDATE(peripheral, drv_inst_idx, rx_len, tx_len) \ - (((drv_inst_idx) == NRFX_CONCAT_3(NRFX_, peripheral, _INST_IDX)) && \ - NRFX_EASYDMA_LENGTH_VALIDATE(peripheral, rx_len, tx_len)) - -#if NRFX_CHECK(NRFX_SPIS0_ENABLED) -#define SPIS0_LENGTH_VALIDATE(...) SPISX_LENGTH_VALIDATE(SPIS0, __VA_ARGS__) -#else -#define SPIS0_LENGTH_VALIDATE(...) 0 -#endif - -#if NRFX_CHECK(NRFX_SPIS1_ENABLED) -#define SPIS1_LENGTH_VALIDATE(...) SPISX_LENGTH_VALIDATE(SPIS1, __VA_ARGS__) -#else -#define SPIS1_LENGTH_VALIDATE(...) 0 -#endif - -#if NRFX_CHECK(NRFX_SPIS2_ENABLED) -#define SPIS2_LENGTH_VALIDATE(...) SPISX_LENGTH_VALIDATE(SPIS2, __VA_ARGS__) -#else -#define SPIS2_LENGTH_VALIDATE(...) 0 -#endif - -#if NRFX_CHECK(NRFX_SPIS3_ENABLED) -#define SPIS3_LENGTH_VALIDATE(...) SPISX_LENGTH_VALIDATE(SPIS3, __VA_ARGS__) -#else -#define SPIS3_LENGTH_VALIDATE(...) 0 -#endif - -#define SPIS_LENGTH_VALIDATE(drv_inst_idx, rx_len, tx_len) \ - (SPIS0_LENGTH_VALIDATE(drv_inst_idx, rx_len, tx_len) || \ - SPIS1_LENGTH_VALIDATE(drv_inst_idx, rx_len, tx_len) || \ - SPIS2_LENGTH_VALIDATE(drv_inst_idx, rx_len, tx_len) || \ - SPIS3_LENGTH_VALIDATE(drv_inst_idx, rx_len, tx_len)) - - -#if NRFX_CHECK(NRFX_SPIS_NRF52_ANOMALY_109_WORKAROUND_ENABLED) -#include -#define USE_DMA_ISSUE_WORKAROUND -// This handler is called by the GPIOTE driver when a falling edge is detected -// on the CSN line. There is no need to do anything here. The handling of the -// interrupt itself provides a protection for DMA transfers. -static void csn_event_handler(nrfx_gpiote_pin_t pin, - nrf_gpiote_polarity_t action) -{ -} -#endif - - -/**@brief States of the SPI transaction state machine. */ -typedef enum -{ - SPIS_STATE_INIT, /**< Initialization state. In this state the module waits for a call to @ref spi_slave_buffers_set. */ - SPIS_BUFFER_RESOURCE_REQUESTED, /**< State where the configuration of the memory buffers, which are to be used in SPI transaction, has started. */ - SPIS_BUFFER_RESOURCE_CONFIGURED, /**< State where the configuration of the memory buffers, which are to be used in SPI transaction, has completed. */ - SPIS_XFER_COMPLETED /**< State where SPI transaction has been completed. */ -} nrfx_spis_state_t; - -/**@brief SPIS control block - driver instance local data. */ -typedef struct -{ - volatile uint32_t tx_buffer_size; //!< SPI slave TX buffer size in bytes. - volatile uint32_t rx_buffer_size; //!< SPI slave RX buffer size in bytes. - nrfx_spis_event_handler_t handler; //!< SPI event handler. - volatile const uint8_t * tx_buffer; //!< SPI slave TX buffer. - volatile uint8_t * rx_buffer; //!< SPI slave RX buffer. - nrfx_drv_state_t state; //!< driver initialization state. - volatile nrfx_spis_state_t spi_state; //!< SPI slave state. - void * p_context; //!< Context set on initialization. -} spis_cb_t; - -static spis_cb_t m_cb[NRFX_SPIS_ENABLED_COUNT]; - -nrfx_err_t nrfx_spis_init(nrfx_spis_t const * const p_instance, - nrfx_spis_config_t const * p_config, - nrfx_spis_event_handler_t event_handler, - void * p_context) -{ - NRFX_ASSERT(p_config); - NRFX_ASSERT(event_handler); - spis_cb_t * p_cb = &m_cb[p_instance->drv_inst_idx]; - nrfx_err_t err_code; - - NRF_SPIS_Type * p_spis = p_instance->p_reg; - - if (p_cb->state != NRFX_DRV_STATE_UNINITIALIZED) - { - err_code = NRFX_ERROR_INVALID_STATE; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - - if ((uint32_t)p_config->mode > (uint32_t)NRF_SPIS_MODE_3) - { - err_code = NRFX_ERROR_INVALID_PARAM; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } -#if NRFX_CHECK(NRFX_PRS_ENABLED) - static nrfx_irq_handler_t const irq_handlers[NRFX_SPIS_ENABLED_COUNT] = { - #if NRFX_CHECK(NRFX_SPIS0_ENABLED) - nrfx_spis_0_irq_handler, - #endif - #if NRFX_CHECK(NRFX_SPIS1_ENABLED) - nrfx_spis_1_irq_handler, - #endif - #if NRFX_CHECK(NRFX_SPIS2_ENABLED) - nrfx_spis_2_irq_handler, - #endif - #if NRFX_CHECK(NRFX_SPIS3_ENABLED) - nrfx_spis_3_irq_handler, - #endif - }; - if (nrfx_prs_acquire(p_spis, - irq_handlers[p_instance->drv_inst_idx]) != NRFX_SUCCESS) - { - err_code = NRFX_ERROR_BUSY; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } -#endif // NRFX_CHECK(NRFX_PRS_ENABLED) - - // Configure the SPI pins for input. - uint32_t mosi_pin; - uint32_t miso_pin; - - if (p_config->miso_pin != NRFX_SPIS_PIN_NOT_USED) - { - nrf_gpio_cfg(p_config->miso_pin, - NRF_GPIO_PIN_DIR_INPUT, - NRF_GPIO_PIN_INPUT_CONNECT, - NRF_GPIO_PIN_NOPULL, - p_config->miso_drive, - NRF_GPIO_PIN_NOSENSE); - miso_pin = p_config->miso_pin; - } - else - { - miso_pin = NRF_SPIS_PIN_NOT_CONNECTED; - } - - if (p_config->mosi_pin != NRFX_SPIS_PIN_NOT_USED) - { - nrf_gpio_cfg(p_config->mosi_pin, - NRF_GPIO_PIN_DIR_INPUT, - NRF_GPIO_PIN_INPUT_CONNECT, - NRF_GPIO_PIN_NOPULL, - NRF_GPIO_PIN_S0S1, - NRF_GPIO_PIN_NOSENSE); - mosi_pin = p_config->mosi_pin; - } - else - { - mosi_pin = NRF_SPIS_PIN_NOT_CONNECTED; - } - - nrf_gpio_cfg(p_config->csn_pin, - NRF_GPIO_PIN_DIR_INPUT, - NRF_GPIO_PIN_INPUT_CONNECT, - p_config->csn_pullup, - NRF_GPIO_PIN_S0S1, - NRF_GPIO_PIN_NOSENSE); - - nrf_gpio_cfg(p_config->sck_pin, - NRF_GPIO_PIN_DIR_INPUT, - NRF_GPIO_PIN_INPUT_CONNECT, - NRF_GPIO_PIN_NOPULL, - NRF_GPIO_PIN_S0S1, - NRF_GPIO_PIN_NOSENSE); - - nrf_spis_pins_set(p_spis, p_config->sck_pin, mosi_pin, miso_pin, p_config->csn_pin); - - nrf_spis_rx_buffer_set(p_spis, NULL, 0); - nrf_spis_tx_buffer_set(p_spis, NULL, 0); - - // Configure SPI mode. - nrf_spis_configure(p_spis, p_config->mode, p_config->bit_order); - - // Configure DEF and ORC characters. - nrf_spis_def_set(p_spis, p_config->def); - nrf_spis_orc_set(p_spis, p_config->orc); - - // Clear possible pending events. - nrf_spis_event_clear(p_spis, NRF_SPIS_EVENT_END); - nrf_spis_event_clear(p_spis, NRF_SPIS_EVENT_ACQUIRED); - - // Enable END_ACQUIRE shortcut. - nrf_spis_shorts_enable(p_spis, NRF_SPIS_SHORT_END_ACQUIRE); - - p_cb->spi_state = SPIS_STATE_INIT; - p_cb->handler = event_handler; - p_cb->p_context = p_context; - -#if defined(USE_DMA_ISSUE_WORKAROUND) - // Configure a GPIOTE channel to generate interrupts on each falling edge - // on the CSN line. Handling of these interrupts will make the CPU active, - // and thus will protect the DMA transfers started by SPIS right after it - // is selected for communication. - // [the GPIOTE driver may be already initialized at this point (by this - // driver when another SPIS instance is used, or by an application code), - // so just ignore the returned value] - (void)nrfx_gpiote_init(); - static nrfx_gpiote_in_config_t const csn_gpiote_config = - NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(true); - nrfx_err_t gpiote_err_code = nrfx_gpiote_in_init(p_config->csn_pin, - &csn_gpiote_config, csn_event_handler); - if (gpiote_err_code != NRFX_SUCCESS) - { - err_code = NRFX_ERROR_INTERNAL; - NRFX_LOG_INFO("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - nrfx_gpiote_in_event_enable(p_config->csn_pin, true); -#endif - - // Enable IRQ. - nrf_spis_int_enable(p_spis, NRF_SPIS_INT_ACQUIRED_MASK | - NRF_SPIS_INT_END_MASK); - NRFX_IRQ_PRIORITY_SET(nrfx_get_irq_number(p_instance->p_reg), - p_config->irq_priority); - NRFX_IRQ_ENABLE(nrfx_get_irq_number(p_instance->p_reg)); - - p_cb->state = NRFX_DRV_STATE_INITIALIZED; - - // Enable SPI slave device. - nrf_spis_enable(p_spis); - - NRFX_LOG_INFO("Initialized."); - return NRFX_SUCCESS; -} - - -void nrfx_spis_uninit(nrfx_spis_t const * const p_instance) -{ - spis_cb_t * p_cb = &m_cb[p_instance->drv_inst_idx]; - NRFX_ASSERT(p_cb->state != NRFX_DRV_STATE_UNINITIALIZED); - - NRF_SPIS_Type * p_spis = p_instance->p_reg; - - #define DISABLE_ALL 0xFFFFFFFF - nrf_spis_disable(p_spis); - NRFX_IRQ_DISABLE(nrfx_get_irq_number(p_instance->p_reg)); - nrf_spis_int_disable(p_spis, DISABLE_ALL); - #undef DISABLE_ALL - -#if NRFX_CHECK(NRFX_PRS_ENABLED) - nrfx_prs_release(p_spis); -#endif - - p_cb->state = NRFX_DRV_STATE_UNINITIALIZED; - NRFX_LOG_INFO("Uninitialized."); -} - - -/**@brief Function for executing the state entry action. */ -static void spis_state_entry_action_execute(NRF_SPIS_Type * p_spis, - spis_cb_t * p_cb) -{ - nrfx_spis_evt_t event; - - switch (p_cb->spi_state) - { - case SPIS_BUFFER_RESOURCE_REQUESTED: - nrf_spis_task_trigger(p_spis, NRF_SPIS_TASK_ACQUIRE); - break; - - case SPIS_BUFFER_RESOURCE_CONFIGURED: - event.evt_type = NRFX_SPIS_BUFFERS_SET_DONE; - event.rx_amount = 0; - event.tx_amount = 0; - - NRFX_ASSERT(p_cb->handler != NULL); - p_cb->handler(&event, p_cb->p_context); - break; - - case SPIS_XFER_COMPLETED: - event.evt_type = NRFX_SPIS_XFER_DONE; - event.rx_amount = nrf_spis_rx_amount_get(p_spis); - event.tx_amount = nrf_spis_tx_amount_get(p_spis); - NRFX_LOG_INFO("Transfer rx_len:%d.", event.rx_amount); - NRFX_LOG_DEBUG("Rx data:"); - NRFX_LOG_HEXDUMP_DEBUG((uint8_t const *)p_cb->rx_buffer, - event.rx_amount * sizeof(p_cb->rx_buffer[0])); - NRFX_ASSERT(p_cb->handler != NULL); - p_cb->handler(&event, p_cb->p_context); - break; - - default: - // No implementation required. - break; - } -} - -/**@brief Function for changing the state of the SPI state machine. - * - * @param[in] p_spis SPIS instance register. - * @param[in] p_cb SPIS instance control block. - * @param[in] new_state State where the state machine transits to. - */ -static void spis_state_change(NRF_SPIS_Type * p_spis, - spis_cb_t * p_cb, - nrfx_spis_state_t new_state) -{ - p_cb->spi_state = new_state; - spis_state_entry_action_execute(p_spis, p_cb); -} - -nrfx_err_t nrfx_spis_buffers_set(nrfx_spis_t const * const p_instance, - uint8_t const * p_tx_buffer, - size_t tx_buffer_length, - uint8_t * p_rx_buffer, - size_t rx_buffer_length) -{ - NRFX_ASSERT(p_tx_buffer != NULL || tx_buffer_length == 0); - NRFX_ASSERT(p_rx_buffer != NULL || rx_buffer_length == 0); - - spis_cb_t * p_cb = &m_cb[p_instance->drv_inst_idx]; - nrfx_err_t err_code; - - if (!SPIS_LENGTH_VALIDATE(p_instance->drv_inst_idx, - rx_buffer_length, - tx_buffer_length)) - { - return NRFX_ERROR_INVALID_LENGTH; - } - - // EasyDMA requires that transfer buffers are placed in Data RAM region; - // signal error if they are not. - if ((p_tx_buffer != NULL && !nrfx_is_in_ram(p_tx_buffer)) || - (p_rx_buffer != NULL && !nrfx_is_in_ram(p_rx_buffer))) - { - err_code = NRFX_ERROR_INVALID_ADDR; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - - switch (p_cb->spi_state) - { - case SPIS_STATE_INIT: - case SPIS_XFER_COMPLETED: - case SPIS_BUFFER_RESOURCE_CONFIGURED: - p_cb->tx_buffer = p_tx_buffer; - p_cb->rx_buffer = p_rx_buffer; - p_cb->tx_buffer_size = tx_buffer_length; - p_cb->rx_buffer_size = rx_buffer_length; - err_code = NRFX_SUCCESS; - - spis_state_change(p_instance->p_reg, p_cb, SPIS_BUFFER_RESOURCE_REQUESTED); - break; - - case SPIS_BUFFER_RESOURCE_REQUESTED: - err_code = NRFX_ERROR_INVALID_STATE; - break; - - default: - // @note: execution of this code path would imply internal error in the design. - err_code = NRFX_ERROR_INTERNAL; - break; - } - - NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; -} - -static void spis_irq_handler(NRF_SPIS_Type * p_spis, spis_cb_t * p_cb) -{ - // @note: as multiple events can be pending for processing, the correct event processing order - // is as follows: - // - SPI semaphore acquired event. - // - SPI transaction complete event. - - // Check for SPI semaphore acquired event. - if (nrf_spis_event_check(p_spis, NRF_SPIS_EVENT_ACQUIRED)) - { - nrf_spis_event_clear(p_spis, NRF_SPIS_EVENT_ACQUIRED); - NRFX_LOG_DEBUG("SPIS: Event: %s.", EVT_TO_STR(NRF_SPIS_EVENT_ACQUIRED)); - - switch (p_cb->spi_state) - { - case SPIS_BUFFER_RESOURCE_REQUESTED: - nrf_spis_tx_buffer_set(p_spis, (uint8_t *)p_cb->tx_buffer, p_cb->tx_buffer_size); - nrf_spis_rx_buffer_set(p_spis, (uint8_t *)p_cb->rx_buffer, p_cb->rx_buffer_size); - - nrf_spis_task_trigger(p_spis, NRF_SPIS_TASK_RELEASE); - - spis_state_change(p_spis, p_cb, SPIS_BUFFER_RESOURCE_CONFIGURED); - break; - - default: - // No implementation required. - break; - } - } - - // Check for SPI transaction complete event. - if (nrf_spis_event_check(p_spis, NRF_SPIS_EVENT_END)) - { - nrf_spis_event_clear(p_spis, NRF_SPIS_EVENT_END); - NRFX_LOG_DEBUG("SPIS: Event: %s.", EVT_TO_STR(NRF_SPIS_EVENT_END)); - - switch (p_cb->spi_state) - { - case SPIS_BUFFER_RESOURCE_CONFIGURED: - spis_state_change(p_spis, p_cb, SPIS_XFER_COMPLETED); - break; - - default: - // No implementation required. - break; - } - } -} - -#if NRFX_CHECK(NRFX_SPIS0_ENABLED) -void nrfx_spis_0_irq_handler(void) -{ - spis_irq_handler(NRF_SPIS0, &m_cb[NRFX_SPIS0_INST_IDX]); -} -#endif - -#if NRFX_CHECK(NRFX_SPIS1_ENABLED) -void nrfx_spis_1_irq_handler(void) -{ - spis_irq_handler(NRF_SPIS1, &m_cb[NRFX_SPIS1_INST_IDX]); -} -#endif - -#if NRFX_CHECK(NRFX_SPIS2_ENABLED) -void nrfx_spis_2_irq_handler(void) -{ - spis_irq_handler(NRF_SPIS2, &m_cb[NRFX_SPIS2_INST_IDX]); -} -#endif - -#if NRFX_CHECK(NRFX_SPIS3_ENABLED) -void nrfx_spis_3_irq_handler(void) -{ - spis_irq_handler(NRF_SPIS3, &m_cb[NRFX_SPIS3_INST_IDX]); -} -#endif - -#endif // NRFX_CHECK(NRFX_SPIS_ENABLED) diff --git a/modules/nrfx/drivers/src/nrfx_swi.c b/modules/nrfx/drivers/src/nrfx_swi.c deleted file mode 100644 index a1e91a7..0000000 --- a/modules/nrfx/drivers/src/nrfx_swi.c +++ /dev/null @@ -1,439 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include - -#if NRFX_CHECK(NRFX_SWI_ENABLED) - -#include - -#define NRFX_LOG_MODULE SWI -#include - - -// NRFX_SWI_RESERVED_MASK - SWIs reserved for use by external modules. -#if NRFX_CHECK(NRFX_PWM_NRF52_ANOMALY_109_WORKAROUND_ENABLED) -#define NRFX_SWI_RESERVED_MASK ((NRFX_SWI_USED) | \ - (1u << NRFX_PWM_NRF52_ANOMALY_109_EGU_INSTANCE)) -#else -#define NRFX_SWI_RESERVED_MASK (NRFX_SWI_USED) -#endif - -// NRFX_SWI_DISABLED_MASK - SWIs excluded from use in . -#if NRFX_CHECK(NRFX_SWI0_DISABLED) -#define NRFX_SWI0_DISABLED_MASK (1u << 0) -#else -#define NRFX_SWI0_DISABLED_MASK 0u -#endif -#if NRFX_CHECK(NRFX_SWI1_DISABLED) -#define NRFX_SWI1_DISABLED_MASK (1u << 1) -#else -#define NRFX_SWI1_DISABLED_MASK 0u -#endif -#if NRFX_CHECK(NRFX_SWI2_DISABLED) -#define NRFX_SWI2_DISABLED_MASK (1u << 2) -#else -#define NRFX_SWI2_DISABLED_MASK 0u -#endif -#if NRFX_CHECK(NRFX_SWI3_DISABLED) -#define NRFX_SWI3_DISABLED_MASK (1u << 3) -#else -#define NRFX_SWI3_DISABLED_MASK 0u -#endif -#if NRFX_CHECK(NRFX_SWI4_DISABLED) -#define NRFX_SWI4_DISABLED_MASK (1u << 4) -#else -#define NRFX_SWI4_DISABLED_MASK 0u -#endif -#if NRFX_CHECK(NRFX_SWI5_DISABLED) -#define NRFX_SWI5_DISABLED_MASK (1u << 5) -#else -#define NRFX_SWI5_DISABLED_MASK 0u -#endif -#define NRFX_SWI_DISABLED_MASK (NRFX_SWI0_DISABLED_MASK | \ - NRFX_SWI1_DISABLED_MASK | \ - NRFX_SWI2_DISABLED_MASK | \ - NRFX_SWI3_DISABLED_MASK | \ - NRFX_SWI4_DISABLED_MASK | \ - NRFX_SWI5_DISABLED_MASK) - -#if (NRFX_SWI_RESERVED_MASK & NRFX_SWI_DISABLED_MASK) -#error "A reserved SWI configured to be disabled. Check and NRFX_SWI_USED." -#endif - -// NRFX_SWI_AVAILABLE_MASK - SWIs available for this module, i.e. present -// in the hardware and neither reserved by external modules nor disabled -// in . -#define NRFX_SWI_PRESENT_MASK ((1u << (SWI_COUNT)) - 1u) -#define NRFX_SWI_AVAILABLE_MASK (NRFX_SWI_PRESENT_MASK & \ - ~(NRFX_SWI_RESERVED_MASK | \ - NRFX_SWI_DISABLED_MASK)) - -#if (NRFX_SWI_AVAILABLE_MASK == 0) -#error "No available SWI instances. Check and NRFX_SWI_USED." -#endif - -#define NRFX_SWI_IS_AVAILABLE(idx) ((NRFX_SWI_AVAILABLE_MASK >> (idx)) & 1u) - -#define NRFX_SWI_FIRST (NRFX_SWI_IS_AVAILABLE(0) ? 0u : \ - (NRFX_SWI_IS_AVAILABLE(1) ? 1u : \ - (NRFX_SWI_IS_AVAILABLE(2) ? 2u : \ - (NRFX_SWI_IS_AVAILABLE(3) ? 3u : \ - (NRFX_SWI_IS_AVAILABLE(4) ? 4u : \ - 5u))))) -#define NRFX_SWI_LAST (NRFX_SWI_IS_AVAILABLE(5) ? 5u : \ - (NRFX_SWI_IS_AVAILABLE(4) ? 4u : \ - (NRFX_SWI_IS_AVAILABLE(3) ? 3u : \ - (NRFX_SWI_IS_AVAILABLE(2) ? 2u : \ - (NRFX_SWI_IS_AVAILABLE(1) ? 1u : \ - 0u))))) - -// NRFX_SWI_EGU_COUNT - number of EGU instances to be used by this module -// (note - if EGU is not present, EGU_COUNT is not defined). -#if NRFX_CHECK(NRFX_EGU_ENABLED) -#define NRFX_SWI_EGU_COUNT EGU_COUNT -#else -#define NRFX_SWI_EGU_COUNT 0 -#endif - -// These flags are needed only for SWIs that have no corresponding EGU unit -// (in EGU such flags are available in hardware). -#if (NRFX_SWI_EGU_COUNT < SWI_COUNT) -static nrfx_swi_flags_t m_swi_flags[SWI_COUNT - NRFX_SWI_EGU_COUNT]; -#endif -static nrfx_swi_handler_t m_swi_handlers[SWI_COUNT]; -static uint8_t m_swi_allocated_mask; - - -static void swi_mark_allocated(nrfx_swi_t swi) -{ - m_swi_allocated_mask |= (1u << swi); -} - -static void swi_mark_unallocated(nrfx_swi_t swi) -{ - m_swi_allocated_mask &= ~(1u << swi); -} - -static bool swi_is_allocated(nrfx_swi_t swi) -{ - return (m_swi_allocated_mask & (1u << swi)); -} - -static bool swi_is_available(nrfx_swi_t swi) -{ - return NRFX_SWI_IS_AVAILABLE(swi); -} - -static IRQn_Type swi_irq_number_get(nrfx_swi_t swi) -{ -#if defined(NRF_SWI) - return (IRQn_Type)(nrfx_get_irq_number(NRF_SWI) + swi); -#elif defined(NRF_SWI0) - return (IRQn_Type)(nrfx_get_irq_number(NRF_SWI0) + swi); -#else - return (IRQn_Type)(nrfx_get_irq_number(NRF_EGU0) + swi); -#endif -} - -static void swi_int_enable(nrfx_swi_t swi) -{ -#if NRFX_SWI_EGU_COUNT - if (swi < NRFX_SWI_EGU_COUNT) - { - NRF_EGU_Type * p_egu = nrfx_swi_egu_instance_get(swi); - NRFX_ASSERT(p_egu != NULL); - nrf_egu_int_enable(p_egu, NRF_EGU_INT_ALL); - - if (m_swi_handlers[swi] == NULL) - { - return; - } - } -#endif - - NRFX_IRQ_ENABLE(swi_irq_number_get(swi)); -} - -static void swi_int_disable(nrfx_swi_t swi) -{ - NRFX_IRQ_DISABLE(swi_irq_number_get(swi)); - -#if NRFX_SWI_EGU_COUNT - if (swi < NRFX_SWI_EGU_COUNT) - { - nrf_egu_int_disable(nrfx_swi_egu_instance_get(swi), NRF_EGU_INT_ALL); - } -#endif -} - -static void swi_handler_setup(nrfx_swi_t swi, - nrfx_swi_handler_t event_handler, - uint32_t irq_priority) -{ - m_swi_handlers[swi] = event_handler; - NRFX_IRQ_PRIORITY_SET(swi_irq_number_get(swi), irq_priority); - swi_int_enable(swi); -} - -static void swi_deallocate(nrfx_swi_t swi) -{ - swi_int_disable(swi); - m_swi_handlers[swi] = NULL; - swi_mark_unallocated(swi); -} - -nrfx_err_t nrfx_swi_alloc(nrfx_swi_t * p_swi, - nrfx_swi_handler_t event_handler, - uint32_t irq_priority) -{ - NRFX_ASSERT(p_swi != NULL); - - nrfx_err_t err_code; - - for (nrfx_swi_t swi = NRFX_SWI_FIRST; swi <= NRFX_SWI_LAST; ++swi) - { - if (swi_is_available(swi)) - { - bool allocated = false; - NRFX_CRITICAL_SECTION_ENTER(); - if (!swi_is_allocated(swi)) - { - swi_mark_allocated(swi); - allocated = true; - } - NRFX_CRITICAL_SECTION_EXIT(); - - if (allocated) - { - swi_handler_setup(swi, event_handler, irq_priority); - - *p_swi = swi; - NRFX_LOG_INFO("SWI channel allocated: %d.", (*p_swi)); - return NRFX_SUCCESS; - } - } - } - - err_code = NRFX_ERROR_NO_MEM; - NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; -} - -bool nrfx_swi_is_allocated(nrfx_swi_t swi) -{ - return swi_is_allocated(swi); -} - -void nrfx_swi_int_disable(nrfx_swi_t swi) -{ - NRFX_ASSERT(swi_is_allocated(swi)); - swi_int_disable(swi); -} - -void nrfx_swi_int_enable(nrfx_swi_t swi) -{ - NRFX_ASSERT(swi_is_allocated(swi)); - swi_int_enable(swi); -} - -void nrfx_swi_free(nrfx_swi_t * p_swi) -{ - NRFX_ASSERT(p_swi != NULL); - nrfx_swi_t swi = *p_swi; - - NRFX_ASSERT(swi_is_allocated(swi)); - swi_deallocate(swi); - - *p_swi = NRFX_SWI_UNALLOCATED; -} - -void nrfx_swi_all_free(void) -{ - for (nrfx_swi_t swi = NRFX_SWI_FIRST; swi <= NRFX_SWI_LAST; ++swi) - { - if (swi_is_allocated(swi)) - { - swi_deallocate(swi); - } - } -} - -void nrfx_swi_trigger(nrfx_swi_t swi, uint8_t flag_number) -{ - NRFX_ASSERT(swi_is_allocated(swi)); - -#if NRFX_SWI_EGU_COUNT - - NRF_EGU_Type * p_egu = nrfx_swi_egu_instance_get(swi); -#if (NRFX_SWI_EGU_COUNT < SWI_COUNT) - if (p_egu == NULL) - { - m_swi_flags[swi - NRFX_SWI_EGU_COUNT] |= (1 << flag_number); - NRFX_IRQ_PENDING_SET(swi_irq_number_get(swi)); - } - else -#endif // (NRFX_SWI_EGU_COUNT < SWI_COUNT) - { - nrf_egu_task_trigger(p_egu, - nrf_egu_task_trigger_get(p_egu, flag_number)); - } - -#else // -> #if !NRFX_SWI_EGU_COUNT - - m_swi_flags[swi - NRFX_SWI_EGU_COUNT] |= (1 << flag_number); - NRFX_IRQ_PENDING_SET(swi_irq_number_get(swi)); - -#endif -} - -#if NRFX_SWI_EGU_COUNT -static void egu_irq_handler(nrfx_swi_t swi, uint8_t egu_channel_count) -{ -#if (NRFX_SWI_FIRST > 0) - NRFX_ASSERT(swi >= NRFX_SWI_FIRST); -#endif - NRFX_ASSERT(swi <= NRFX_SWI_LAST); - nrfx_swi_handler_t handler = m_swi_handlers[swi]; - NRFX_ASSERT(handler != NULL); - - NRF_EGU_Type * p_egu = nrfx_swi_egu_instance_get(swi); - NRFX_ASSERT(p_egu != NULL); - - nrfx_swi_flags_t flags = 0; - for (uint8_t i = 0; i < egu_channel_count; ++i) - { - nrf_egu_event_t egu_event = nrf_egu_event_triggered_get(p_egu, i); - if (nrf_egu_event_check(p_egu, egu_event)) - { - flags |= (1u << i); - nrf_egu_event_clear(p_egu, egu_event); - } - } - - handler(swi, flags); -} -#endif // NRFX_SWI_EGU_COUNT - -#if (NRFX_SWI_EGU_COUNT < SWI_COUNT) -static void swi_irq_handler(nrfx_swi_t swi) -{ -#if (NRFX_SWI_FIRST > 0) - NRFX_ASSERT(swi >= NRFX_SWI_FIRST); -#endif - NRFX_ASSERT(swi <= NRFX_SWI_LAST); - nrfx_swi_handler_t handler = m_swi_handlers[swi]; - NRFX_ASSERT(handler != NULL); - - nrfx_swi_flags_t flags = m_swi_flags[swi - NRFX_SWI_EGU_COUNT]; - m_swi_flags[swi - NRFX_SWI_EGU_COUNT] &= ~flags; - - handler(swi, flags); -} -#endif // (NRFX_SWI_EGU_COUNT < SWI_COUNT) - - -#if NRFX_SWI_IS_AVAILABLE(0) -void nrfx_swi_0_irq_handler(void) -{ -#if (NRFX_SWI_EGU_COUNT > 0) - egu_irq_handler(0, EGU0_CH_NUM); -#else - swi_irq_handler(0); -#endif -} -#endif // NRFX_SWI_IS_AVAILABLE(0) - -#if NRFX_SWI_IS_AVAILABLE(1) -void nrfx_swi_1_irq_handler(void) -{ -#if (NRFX_SWI_EGU_COUNT > 1) - egu_irq_handler(1, EGU1_CH_NUM); -#else - swi_irq_handler(1); -#endif -} -#endif // NRFX_SWI_IS_AVAILABLE(1) - -#if NRFX_SWI_IS_AVAILABLE(2) -void nrfx_swi_2_irq_handler(void) -{ -#if (NRFX_SWI_EGU_COUNT > 2) - egu_irq_handler(2, EGU2_CH_NUM); -#else - swi_irq_handler(2); -#endif -} -#endif // NRFX_SWI_IS_AVAILABLE(2) - -#if NRFX_SWI_IS_AVAILABLE(3) -void nrfx_swi_3_irq_handler(void) -{ -#if (NRFX_SWI_EGU_COUNT > 3) - egu_irq_handler(3, EGU3_CH_NUM); -#else - swi_irq_handler(3); -#endif -} -#endif // NRFX_SWI_IS_AVAILABLE(3) - -#if NRFX_SWI_IS_AVAILABLE(4) -void nrfx_swi_4_irq_handler(void) -{ -#if (NRFX_SWI_EGU_COUNT > 4) - egu_irq_handler(4, EGU4_CH_NUM); -#else - swi_irq_handler(4); -#endif -} -#endif // NRFX_SWI_IS_AVAILABLE(4) - -#if NRFX_SWI_IS_AVAILABLE(5) -void nrfx_swi_5_irq_handler(void) -{ -#if (NRFX_SWI_EGU_COUNT > 5) - egu_irq_handler(5, EGU5_CH_NUM); -#else - swi_irq_handler(5); -#endif -} -#endif // NRFX_SWI_IS_AVAILABLE(5) - -#endif // NRFX_CHECK(NRFX_SWI_ENABLED) diff --git a/modules/nrfx/drivers/src/nrfx_systick.c b/modules/nrfx/drivers/src/nrfx_systick.c deleted file mode 100644 index bdb22b2..0000000 --- a/modules/nrfx/drivers/src/nrfx_systick.c +++ /dev/null @@ -1,170 +0,0 @@ -/** - * Copyright (c) 2016 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ -#include - -#if NRFX_CHECK(NRFX_SYSTICK_ENABLED) -#include - -/** - * @brief Maximum number of ticks to delay - * - * The maximum number of ticks should be much lower than - * Physical maximum count of the SysTick timer. - * It is dictated by the fact that it would be impossible to detect delay - * properly when the timer value warps around the starting point. - */ -#define NRFX_SYSTICK_TICKS_MAX (NRF_SYSTICK_VAL_MASK / 2UL) - -/** - * @brief Number of milliseconds in a second - */ -#define NRFX_SYSTICK_MS (1000UL) - -/** - * @brief Number of microseconds in a second - */ -#define NRFX_SYSTICK_US (1000UL * NRFX_SYSTICK_MS) - -/** - * @brief Number of milliseconds to wait in single loop - * - * Constant used by @ref nrd_drv_systick_delay_ms function - * to split waiting into loops and rest. - * - * It describes the number of milliseconds to wait in single loop. - * - * See @ref nrfx_systick_delay_ms source code for details. - */ -#define NRFX_SYSTICK_MS_STEP (64U) - -/** - * @brief Checks if the given time is in correct range - * - * Function tests given time is not to big for this library. - * Assertion is used for testing. - * - * @param us Time in microseconds to check - */ -#define NRFX_SYSTICK_ASSERT_TIMEOUT(us) \ - NRFX_ASSERT(us <= (NRFX_SYSTICK_TICKS_MAX / ((SystemCoreClock) / NRFX_SYSTICK_US))); - -/** - * @brief Function that converts microseconds to ticks - * - * Function converts from microseconds to CPU ticks. - * - * @param us Number of microseconds - * - * @return Number of ticks - * - * @sa nrfx_systick_ms_tick - */ -static inline uint32_t nrfx_systick_us_tick(uint32_t us) -{ - return us * ((SystemCoreClock) / NRFX_SYSTICK_US); -} - -/** - * @brief Function that converts milliseconds to ticks - * - * Function converts from milliseconds to CPU ticks. - * - * @param us Number of milliseconds - * - * @return Number of ticks - * - * @sa nrfx_systick_us_tick - */ -static inline uint32_t nrfx_systick_ms_tick(uint32_t ms) -{ - return ms * ((SystemCoreClock) / NRFX_SYSTICK_MS); -} - -void nrfx_systick_init(void) -{ - nrf_systick_load_set(NRF_SYSTICK_VAL_MASK); - nrf_systick_csr_set( - NRF_SYSTICK_CSR_CLKSOURCE_CPU | - NRF_SYSTICK_CSR_TICKINT_DISABLE | - NRF_SYSTICK_CSR_ENABLE); -} - -void nrfx_systick_get(nrfx_systick_state_t * p_state) -{ - p_state->time = nrf_systick_val_get(); -} - -bool nrfx_systick_test(nrfx_systick_state_t const * p_state, uint32_t us) -{ - NRFX_SYSTICK_ASSERT_TIMEOUT(us); - - const uint32_t diff = NRF_SYSTICK_VAL_MASK & ((p_state->time) - nrf_systick_val_get()); - return (diff >= nrfx_systick_us_tick(us)); -} - -void nrfx_systick_delay_ticks(uint32_t ticks) -{ - NRFX_ASSERT(ticks <= NRFX_SYSTICK_TICKS_MAX); - - const uint32_t start = nrf_systick_val_get(); - while ((NRF_SYSTICK_VAL_MASK & (start - nrf_systick_val_get())) < ticks) - { - /* Nothing to do */ - } -} - -void nrfx_systick_delay_us(uint32_t us) -{ - NRFX_SYSTICK_ASSERT_TIMEOUT(us); - nrfx_systick_delay_ticks(nrfx_systick_us_tick(us)); -} - -void nrfx_systick_delay_ms(uint32_t ms) -{ - uint32_t n = ms / NRFX_SYSTICK_MS_STEP; - uint32_t r = ms % NRFX_SYSTICK_MS_STEP; - while (0 != (n--)) - { - nrfx_systick_delay_ticks(nrfx_systick_ms_tick(NRFX_SYSTICK_MS_STEP)); - } - nrfx_systick_delay_ticks(nrfx_systick_ms_tick(r)); -} - -#endif // NRFX_CHECK(NRFX_SYSTICK_ENABLED) diff --git a/modules/nrfx/drivers/src/nrfx_temp.c b/modules/nrfx/drivers/src/nrfx_temp.c deleted file mode 100644 index 6ff9051..0000000 --- a/modules/nrfx/drivers/src/nrfx_temp.c +++ /dev/null @@ -1,155 +0,0 @@ -/** - * Copyright (c) 2019 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include - -#if NRFX_CHECK(NRFX_TEMP_ENABLED) - -#include - -#if !defined(USE_WORKAROUND_FOR_TEMP_OFFSET_ANOMALY) && defined(NRF51) -// Enable workaround for nRF51 series anomaly 28 -// (TEMP: Temperature offset value has to be manually loaded to the TEMP module). -#define USE_WORKAROUND_FOR_TEMP_OFFSET_ANOMALY 1 -#endif - -/** @brief Time of one check attempt.*/ -#define NRFX_TEMP_TIME_US 4 - -/** @brief Maximum attempts to check whether conversion passed.*/ -#define NRFX_TEMP_ATTEMPTS 10 - -/** @brief Internal state of TEMP driver. */ -static nrfx_drv_state_t m_temp_state; - -/** @brief Pointer to handler to be called from interrupt routine. */ -static nrfx_temp_data_handler_t m_data_handler; - -nrfx_err_t nrfx_temp_init(nrfx_temp_config_t const * p_config, nrfx_temp_data_handler_t handler) -{ - NRFX_ASSERT(p_config); - - if (m_temp_state != NRFX_DRV_STATE_UNINITIALIZED) - { - return NRFX_ERROR_ALREADY_INITIALIZED; - } - -#if NRFX_CHECK(USE_WORKAROUND_FOR_TEMP_OFFSET_ANOMALY) - *(uint32_t volatile *)0x4000C504 = 0; -#endif - - m_data_handler = handler; - - if (m_data_handler) - { - nrf_temp_int_enable(NRF_TEMP, NRF_TEMP_INT_DATARDY_MASK); - NRFX_IRQ_PRIORITY_SET(TEMP_IRQn, p_config->interrupt_priority); - NRFX_IRQ_ENABLE(TEMP_IRQn); - } - - m_temp_state = NRFX_DRV_STATE_INITIALIZED; - return NRFX_SUCCESS; -} - -void nrfx_temp_uninit(void) -{ - NRFX_ASSERT(m_temp_state == NRFX_DRV_STATE_INITIALIZED); - nrf_temp_task_trigger(NRF_TEMP, NRF_TEMP_TASK_STOP); - - if (m_data_handler) - { - nrf_temp_int_disable(NRF_TEMP, NRF_TEMP_INT_DATARDY_MASK); - NRFX_IRQ_DISABLE(TEMP_IRQn); - } - - m_temp_state = NRFX_DRV_STATE_UNINITIALIZED; -} - -int32_t nrfx_temp_calculate(int32_t raw_measurement) -{ - /* Raw temperature is a 2's complement signed value. Moreover, it is represented - * by 0.25[C] intervals, so division by 4 is needed. To preserve - * fractional part, raw value is multiplied by 100 before division.*/ - - return (raw_measurement * 100) / 4; -} - -nrfx_err_t nrfx_temp_measure(void) -{ - NRFX_ASSERT(m_temp_state == NRFX_DRV_STATE_INITIALIZED); - - nrfx_err_t result = NRFX_SUCCESS; - nrf_temp_event_clear(NRF_TEMP, NRF_TEMP_EVENT_DATARDY); - nrf_temp_task_trigger(NRF_TEMP, NRF_TEMP_TASK_START); - - if (!m_data_handler) - { - bool ev_result; - NRFX_WAIT_FOR(nrf_temp_event_check(NRF_TEMP, NRF_TEMP_EVENT_DATARDY), - NRFX_TEMP_ATTEMPTS, - NRFX_TEMP_TIME_US, - ev_result); - if (!ev_result) - { - result = NRFX_ERROR_INTERNAL; - } - else - { - nrf_temp_event_clear(NRF_TEMP, NRF_TEMP_EVENT_DATARDY); - } - nrf_temp_task_trigger(NRF_TEMP, NRF_TEMP_TASK_STOP); - } - - return result; -} - -void nrfx_temp_irq_handler(void) -{ - NRFX_ASSERT(m_data_handler); - - nrf_temp_task_trigger(NRF_TEMP, NRF_TEMP_TASK_STOP); - nrf_temp_event_clear(NRF_TEMP, NRF_TEMP_EVENT_DATARDY); - - uint32_t raw_temp = nrfx_temp_result_get(); - - m_data_handler(raw_temp); -} - -#endif // NRFX_CHECK(NRFX_TEMP_ENABLED) diff --git a/modules/nrfx/drivers/src/nrfx_twis.c b/modules/nrfx/drivers/src/nrfx_twis.c deleted file mode 100644 index 994e488..0000000 --- a/modules/nrfx/drivers/src/nrfx_twis.c +++ /dev/null @@ -1,857 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include - -#if NRFX_CHECK(NRFX_TWIS_ENABLED) - -#if !(NRFX_CHECK(NRFX_TWIS0_ENABLED) || \ - NRFX_CHECK(NRFX_TWIS1_ENABLED) || \ - NRFX_CHECK(NRFX_TWIS2_ENABLED) || \ - NRFX_CHECK(NRFX_TWIS3_ENABLED)) -#error "No enabled TWIS instances. Check ." -#endif - -#include -#include "prs/nrfx_prs.h" - -#define NRFX_LOG_MODULE TWIS -#include - -#define EVT_TO_STR(event) \ - (event == NRF_TWIS_EVENT_STOPPED ? "NRF_TWIS_EVENT_STOPPED" : \ - (event == NRF_TWIS_EVENT_ERROR ? "NRF_TWIS_EVENT_ERROR" : \ - (event == NRF_TWIS_EVENT_RXSTARTED ? "NRF_TWIS_EVENT_RXSTARTED" : \ - (event == NRF_TWIS_EVENT_TXSTARTED ? "NRF_TWIS_EVENT_TXSTARTED" : \ - (event == NRF_TWIS_EVENT_WRITE ? "NRF_TWIS_EVENT_WRITE" : \ - (event == NRF_TWIS_EVENT_READ ? "NRF_TWIS_EVENT_READ" : \ - "UNKNOWN EVENT")))))) - - -/** - * @brief Actual state of internal state machine - * - * Current substate of powered on state. - */ -typedef enum -{ - NRFX_TWIS_SUBSTATE_IDLE, ///< No ongoing transmission - NRFX_TWIS_SUBSTATE_READ_WAITING, ///< Read request received, waiting for data - NRFX_TWIS_SUBSTATE_READ_PENDING, ///< Reading is actually pending (data sending) - NRFX_TWIS_SUBSTATE_WRITE_WAITING, ///< Write request received, waiting for data buffer - NRFX_TWIS_SUBSTATE_WRITE_PENDING, ///< Writing is actually pending (data receiving) -} nrfx_twis_substate_t; - -// Control block - driver instance local data. -typedef struct -{ - nrfx_twis_event_handler_t ev_handler; - // Internal copy of hardware errors flags merged with specific internal - // driver errors flags. - // This value can be changed in the interrupt and cleared in the main program. - // Always use Atomic load-store when updating this value in main loop. - volatile uint32_t error; - nrfx_drv_state_t state; - volatile nrfx_twis_substate_t substate; - - volatile bool semaphore; -} twis_control_block_t; -static twis_control_block_t m_cb[NRFX_TWIS_ENABLED_COUNT]; - -/** - * @brief Used interrupts mask - * - * Mask for all interrupts used by this library - */ -static const uint32_t m_used_ints_mask = NRF_TWIS_INT_STOPPED_MASK | - NRF_TWIS_INT_ERROR_MASK | - NRF_TWIS_INT_RXSTARTED_MASK | - NRF_TWIS_INT_TXSTARTED_MASK | - NRF_TWIS_INT_WRITE_MASK | - NRF_TWIS_INT_READ_MASK; - -/** - * @brief Clear all events - * - * Function clears all actually pending events - */ -static void nrfx_twis_clear_all_events(NRF_TWIS_Type * const p_reg) -{ - /* Clear all events */ - nrf_twis_event_clear(p_reg, NRF_TWIS_EVENT_STOPPED); - nrf_twis_event_clear(p_reg, NRF_TWIS_EVENT_ERROR); - nrf_twis_event_clear(p_reg, NRF_TWIS_EVENT_RXSTARTED); - nrf_twis_event_clear(p_reg, NRF_TWIS_EVENT_TXSTARTED); - nrf_twis_event_clear(p_reg, NRF_TWIS_EVENT_WRITE); - nrf_twis_event_clear(p_reg, NRF_TWIS_EVENT_READ); -} - -/** - * @brief Reset all the registers to known state - * - * This function clears all registers that requires it to known state. - * TWIS is left disabled after this function. - * All events are cleared. - * @param[out] p_reg TWIS to reset register address - */ -static inline void nrfx_twis_swreset(NRF_TWIS_Type * p_reg) -{ - /* Disable TWIS */ - nrf_twis_disable(p_reg); - - /* Disconnect pins */ - nrf_twis_pins_set(p_reg, ~0U, ~0U); - - /* Disable interrupt global for the instance */ - NRFX_IRQ_DISABLE(nrfx_get_irq_number(p_reg)); - - /* Disable interrupts */ - nrf_twis_int_disable(p_reg, ~0U); -} - -/** - * @brief Configure pin - * - * Function configures selected for work as SDA or SCL. - * @param pin Pin number to configure - */ -static inline void nrfx_twis_config_pin(uint32_t pin, nrf_gpio_pin_pull_t pull) -{ - nrf_gpio_cfg(pin, - NRF_GPIO_PIN_DIR_INPUT, - NRF_GPIO_PIN_INPUT_DISCONNECT, - pull, - NRF_GPIO_PIN_S0D1, - NRF_GPIO_PIN_NOSENSE); -} - -/** - * @brief Auxiliary function for getting event state on right bit possition - * - * This function calls @ref nrf_twis_event_get function but the the result - * is shifted to match INTEN register scheme. - * - * @param[in,out] p_reg TWIS to read event from - * @param ev Event code - * - * @return Selected event state shifted by @ref nrfx_event_to_bitpos - * - * @sa nrf_twis_event_get - * @sa nrfx_event_to_bitpos - */ -static inline uint32_t nrfx_twis_event_bit_get(NRF_TWIS_Type * p_reg, - nrf_twis_event_t ev) -{ - return (uint32_t)nrf_twis_event_get_and_clear(p_reg, ev) << nrfx_event_to_bitpos(ev); -} - -/** - * @brief Auxiliary function for checking event bit inside given flags value - * - * Function used here to check presence of the event inside given flags value. - * It transforms given event to bit possition and then checks if in given variable it is cleared. - * - * @param flags Flags to test - * @param ev Event code - * - * @retval true Flag for selected event is set - * @retval false Flag for selected event is cleared - */ -static inline bool nrfx_twis_check_bit(uint32_t flags, - nrf_twis_event_t ev) -{ - return 0 != (flags & (1U << nrfx_event_to_bitpos(ev))); -} - -/** - * @brief Auxiliary function for clearing event bit in given flags value - * - * Function used to clear selected event bit. - * - * @param flags Flags to process - * @param ev Event code to clear - * - * @return Value @em flags with cleared event bit that matches given @em ev - */ -static inline uint32_t nrfx_twis_clear_bit(uint32_t flags, - nrf_twis_event_t ev) -{ - return flags & ~(1U << nrfx_event_to_bitpos(ev)); -} - -static void call_event_handler(twis_control_block_t const * p_cb, - nrfx_twis_evt_t const * p_evt) -{ - nrfx_twis_event_handler_t handler = p_cb->ev_handler; - if (handler != NULL) - { - handler(p_evt); - } -} - -/** - * @brief Auxiliary function for error processing - * - * Function called when in current substate the event apears and it cannot be processed. - * It should be called also on ERROR event. - * If given @em error parameter has zero value the @ref NRFX_TWIS_ERROR_UNEXPECTED_EVENT - * would be set. - * - * @param p_cb Pointer to the driver instance control block. - * @param evt What error event raport to event handler - * @param error Error flags - */ -static inline void nrfx_twis_process_error(twis_control_block_t * p_cb, - nrfx_twis_evt_type_t evt, - uint32_t error) -{ - if (0 == error) - { - error = NRFX_TWIS_ERROR_UNEXPECTED_EVENT; - } - nrfx_twis_evt_t evdata; - evdata.type = evt; - evdata.data.error = error; - - p_cb->error |= error; - - call_event_handler(p_cb, &evdata); -} - -static void nrfx_twis_state_machine(NRF_TWIS_Type * p_reg, - twis_control_block_t * p_cb) -{ - if (!NRFX_TWIS_NO_SYNC_MODE) - { - /* Exclude parallel processing of this function */ - if (p_cb->semaphore) - { - return; - } - p_cb->semaphore = 1; - } - - /* Event data structure to be passed into event handler */ - nrfx_twis_evt_t evdata; - /* Current substate copy */ - nrfx_twis_substate_t substate = p_cb->substate; - /* Event flags */ - uint32_t ev = 0; - - /* Get all events */ - ev |= nrfx_twis_event_bit_get(p_reg, NRF_TWIS_EVENT_STOPPED); - ev |= nrfx_twis_event_bit_get(p_reg, NRF_TWIS_EVENT_ERROR); - ev |= nrfx_twis_event_bit_get(p_reg, NRF_TWIS_EVENT_RXSTARTED); - ev |= nrfx_twis_event_bit_get(p_reg, NRF_TWIS_EVENT_TXSTARTED); - ev |= nrfx_twis_event_bit_get(p_reg, NRF_TWIS_EVENT_WRITE); - ev |= nrfx_twis_event_bit_get(p_reg, NRF_TWIS_EVENT_READ); - - /* State machine */ - while (0 != ev) - { - switch (substate) - { - case NRFX_TWIS_SUBSTATE_IDLE: - if (nrfx_twis_check_bit(ev, NRF_TWIS_EVENT_STOPPED)) - { - /* Stopped event is always allowed in IDLE state - just ignore */ - ev = nrfx_twis_clear_bit(ev, NRF_TWIS_EVENT_STOPPED); - } - else if (nrfx_twis_check_bit(ev, NRF_TWIS_EVENT_READ)) - { - evdata.type = NRFX_TWIS_EVT_READ_REQ; - if (nrfx_twis_check_bit(ev, NRF_TWIS_EVENT_TXSTARTED)) - { - substate = NRFX_TWIS_SUBSTATE_READ_PENDING; - evdata.data.buf_req = false; - } - else - { - substate = NRFX_TWIS_SUBSTATE_READ_WAITING; - evdata.data.buf_req = true; - } - call_event_handler(p_cb, &evdata); - ev = nrfx_twis_clear_bit(ev, NRF_TWIS_EVENT_READ); - ev = nrfx_twis_clear_bit(ev, NRF_TWIS_EVENT_TXSTARTED); - ev = nrfx_twis_clear_bit(ev, NRF_TWIS_EVENT_WRITE); - ev = nrfx_twis_clear_bit(ev, NRF_TWIS_EVENT_RXSTARTED); - } - else if (nrfx_twis_check_bit(ev, NRF_TWIS_EVENT_WRITE)) - { - evdata.type = NRFX_TWIS_EVT_WRITE_REQ; - if (nrfx_twis_check_bit(ev, NRF_TWIS_EVENT_RXSTARTED)) - { - substate = NRFX_TWIS_SUBSTATE_WRITE_PENDING; - evdata.data.buf_req = false; - } - else - { - substate = NRFX_TWIS_SUBSTATE_WRITE_WAITING; - evdata.data.buf_req = true; - } - call_event_handler(p_cb, &evdata); - ev = nrfx_twis_clear_bit(ev, NRF_TWIS_EVENT_READ); - ev = nrfx_twis_clear_bit(ev, NRF_TWIS_EVENT_TXSTARTED); - ev = nrfx_twis_clear_bit(ev, NRF_TWIS_EVENT_WRITE); - ev = nrfx_twis_clear_bit(ev, NRF_TWIS_EVENT_RXSTARTED); - } - else - { - nrfx_twis_process_error(p_cb, - NRFX_TWIS_EVT_GENERAL_ERROR, - nrf_twis_error_source_get_and_clear(p_reg)); - ev = 0; - } - break; - case NRFX_TWIS_SUBSTATE_READ_WAITING: - if (nrfx_twis_check_bit(ev, NRF_TWIS_EVENT_TXSTARTED) || - nrfx_twis_check_bit(ev, NRF_TWIS_EVENT_WRITE) || - nrfx_twis_check_bit(ev, NRF_TWIS_EVENT_READ) || - nrfx_twis_check_bit(ev, NRF_TWIS_EVENT_STOPPED)) - { - substate = NRFX_TWIS_SUBSTATE_READ_PENDING; - /* Any other bits requires further processing in PENDING substate */ - ev = nrfx_twis_clear_bit(ev, NRF_TWIS_EVENT_TXSTARTED); - } - else - { - nrfx_twis_process_error(p_cb, - NRFX_TWIS_EVT_READ_ERROR, - nrf_twis_error_source_get_and_clear(p_reg)); - substate = NRFX_TWIS_SUBSTATE_IDLE; - ev = 0; - } - break; - case NRFX_TWIS_SUBSTATE_READ_PENDING: - if (nrfx_twis_check_bit(ev, NRF_TWIS_EVENT_WRITE) || - nrfx_twis_check_bit(ev, NRF_TWIS_EVENT_READ) || - nrfx_twis_check_bit(ev, NRF_TWIS_EVENT_STOPPED)) - { - evdata.type = NRFX_TWIS_EVT_READ_DONE; - evdata.data.tx_amount = nrf_twis_tx_amount_get(p_reg); - NRFX_LOG_INFO("Transfer tx_len:%d", evdata.data.tx_amount); - NRFX_LOG_DEBUG("Tx data:"); - NRFX_LOG_HEXDUMP_DEBUG((uint8_t const *)p_reg->TXD.PTR, - evdata.data.tx_amount * sizeof(uint8_t)); - call_event_handler(p_cb, &evdata); - /* Go to idle and repeat the state machine if READ or WRITE events detected. - * This time READ or WRITE would be started */ - substate = NRFX_TWIS_SUBSTATE_IDLE; - ev = nrfx_twis_clear_bit(ev, NRF_TWIS_EVENT_STOPPED); - } - else - { - nrfx_twis_process_error(p_cb, - NRFX_TWIS_EVT_READ_ERROR, - nrf_twis_error_source_get_and_clear(p_reg)); - substate = NRFX_TWIS_SUBSTATE_IDLE; - ev = 0; - } - break; - case NRFX_TWIS_SUBSTATE_WRITE_WAITING: - if (nrfx_twis_check_bit(ev, NRF_TWIS_EVENT_RXSTARTED) || - nrfx_twis_check_bit(ev, NRF_TWIS_EVENT_WRITE) || - nrfx_twis_check_bit(ev, NRF_TWIS_EVENT_READ) || - nrfx_twis_check_bit(ev, NRF_TWIS_EVENT_STOPPED)) - { - substate = NRFX_TWIS_SUBSTATE_WRITE_PENDING; - /* Any other bits requires further processing in PENDING substate */ - ev = nrfx_twis_clear_bit(ev, NRF_TWIS_EVENT_RXSTARTED); - } - else - { - nrfx_twis_process_error(p_cb, - NRFX_TWIS_EVT_WRITE_ERROR, - nrf_twis_error_source_get_and_clear(p_reg)); - substate = NRFX_TWIS_SUBSTATE_IDLE; - ev = 0; - } - break; - case NRFX_TWIS_SUBSTATE_WRITE_PENDING: - if (nrfx_twis_check_bit(ev, NRF_TWIS_EVENT_WRITE) || - nrfx_twis_check_bit(ev, NRF_TWIS_EVENT_READ) || - nrfx_twis_check_bit(ev, NRF_TWIS_EVENT_STOPPED)) - { - evdata.type = NRFX_TWIS_EVT_WRITE_DONE; - evdata.data.rx_amount = nrf_twis_rx_amount_get(p_reg); - call_event_handler(p_cb, &evdata); - /* Go to idle and repeat the state machine if READ or WRITE events detected. - * This time READ or WRITE would be started */ - substate = NRFX_TWIS_SUBSTATE_IDLE; - ev = nrfx_twis_clear_bit(ev, NRF_TWIS_EVENT_STOPPED); - } - else - { - nrfx_twis_process_error(p_cb, - NRFX_TWIS_EVT_WRITE_ERROR, - nrf_twis_error_source_get_and_clear(p_reg)); - substate = NRFX_TWIS_SUBSTATE_IDLE; - ev = 0; - } - break; - default: - substate = NRFX_TWIS_SUBSTATE_IDLE; - /* Do not clear any events and repeat the machine */ - break; - } - } - - p_cb->substate = substate; - if (!NRFX_TWIS_NO_SYNC_MODE) - { - p_cb->semaphore = 0; - } -} - - -static inline void nrfx_twis_preprocess_status(nrfx_twis_t const * p_instance) -{ - if (!NRFX_TWIS_NO_SYNC_MODE) - { - NRF_TWIS_Type * p_reg = p_instance->p_reg; - twis_control_block_t * p_cb = &m_cb[p_instance->drv_inst_idx]; - if (NULL == p_cb->ev_handler) - { - nrfx_twis_state_machine(p_reg, p_cb); - } - } -} - - -/* ------------------------------------------------------------------------- - * Implementation of interface functions - * - */ - - -nrfx_err_t nrfx_twis_init(nrfx_twis_t const * p_instance, - nrfx_twis_config_t const * p_config, - nrfx_twis_event_handler_t event_handler) -{ - NRFX_ASSERT(p_config); - NRFX_ASSERT(p_config->scl != p_config->sda); - nrfx_err_t err_code; - - NRF_TWIS_Type * p_reg = p_instance->p_reg; - twis_control_block_t * p_cb = &m_cb[p_instance->drv_inst_idx]; - - if (p_cb->state != NRFX_DRV_STATE_UNINITIALIZED) - { - err_code = NRFX_ERROR_INVALID_STATE; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - -#if NRFX_CHECK(NRFX_PRS_ENABLED) - static nrfx_irq_handler_t const irq_handlers[NRFX_TWIS_ENABLED_COUNT] = { - #if NRFX_CHECK(NRFX_TWIS0_ENABLED) - nrfx_twis_0_irq_handler, - #endif - #if NRFX_CHECK(NRFX_TWIS1_ENABLED) - nrfx_twis_1_irq_handler, - #endif - #if NRFX_CHECK(NRFX_TWIS2_ENABLED) - nrfx_twis_2_irq_handler, - #endif - #if NRFX_CHECK(NRFX_TWIS3_ENABLED) - nrfx_twis_3_irq_handler, - #endif - }; - if (nrfx_prs_acquire(p_reg, - irq_handlers[p_instance->drv_inst_idx]) != NRFX_SUCCESS) - { - err_code = NRFX_ERROR_BUSY; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } -#endif // NRFX_CHECK(NRFX_PRS_ENABLED) - - if (!NRFX_TWIS_ASSUME_INIT_AFTER_RESET_ONLY) - { - nrfx_twis_swreset(p_reg); - } - - nrfx_twis_config_pin(p_config->scl, p_config->scl_pull); - nrfx_twis_config_pin(p_config->sda, p_config->sda_pull); - - nrf_twis_config_addr_mask_t addr_mask = (nrf_twis_config_addr_mask_t)0; - if (0 == (p_config->addr[0] | p_config->addr[1])) - { - addr_mask = NRF_TWIS_CONFIG_ADDRESS0_MASK; - } - else - { - if (0 != p_config->addr[0]) - { - addr_mask |= NRF_TWIS_CONFIG_ADDRESS0_MASK; - } - if (0 != p_config->addr[1]) - { - addr_mask |= NRF_TWIS_CONFIG_ADDRESS1_MASK; - } - } - - /* Peripheral interrupt configure - * (note - interrupts still needs to be configured in INTEN register. - * This is done in enable function) */ - NRFX_IRQ_PRIORITY_SET(nrfx_get_irq_number(p_reg), - p_config->interrupt_priority); - NRFX_IRQ_ENABLE(nrfx_get_irq_number(p_reg)); - - /* Configure */ - nrf_twis_pins_set (p_reg, p_config->scl, p_config->sda); - nrf_twis_address_set (p_reg, 0, p_config->addr[0]); - nrf_twis_address_set (p_reg, 1, p_config->addr[1]); - nrf_twis_config_address_set(p_reg, addr_mask); - - /* Clear semaphore */ - if (!NRFX_TWIS_NO_SYNC_MODE) - { - p_cb->semaphore = 0; - } - /* Set internal instance variables */ - p_cb->substate = NRFX_TWIS_SUBSTATE_IDLE; - p_cb->ev_handler = event_handler; - p_cb->state = NRFX_DRV_STATE_INITIALIZED; - err_code = NRFX_SUCCESS; - NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; -} - - -void nrfx_twis_uninit(nrfx_twis_t const * p_instance) -{ - NRF_TWIS_Type * p_reg = p_instance->p_reg; - twis_control_block_t * p_cb = &m_cb[p_instance->drv_inst_idx]; - NRFX_ASSERT(p_cb->state != NRFX_DRV_STATE_UNINITIALIZED); - - TWIS_PSEL_Type psel = p_reg->PSEL; - - nrfx_twis_swreset(p_reg); - - /* Clear pins state if */ - if (!(TWIS_PSEL_SCL_CONNECT_Msk & psel.SCL)) - { - nrf_gpio_cfg_default(psel.SCL); - } - if (!(TWIS_PSEL_SDA_CONNECT_Msk & psel.SDA)) - { - nrf_gpio_cfg_default(psel.SDA); - } - -#if NRFX_CHECK(NRFX_PRS_ENABLED) - nrfx_prs_release(p_reg); -#endif - - /* Clear variables */ - p_cb->ev_handler = NULL; - p_cb->state = NRFX_DRV_STATE_UNINITIALIZED; -} - - -void nrfx_twis_enable(nrfx_twis_t const * p_instance) -{ - NRF_TWIS_Type * p_reg = p_instance->p_reg; - twis_control_block_t * p_cb = &m_cb[p_instance->drv_inst_idx]; - NRFX_ASSERT(p_cb->state == NRFX_DRV_STATE_INITIALIZED); - - nrfx_twis_clear_all_events(p_reg); - - /* Enable interrupts */ - if (NULL != p_cb->ev_handler) - { - nrf_twis_int_enable(p_reg, m_used_ints_mask); - } - - nrf_twis_enable(p_reg); - p_cb->error = 0; - p_cb->state = NRFX_DRV_STATE_POWERED_ON; - p_cb->substate = NRFX_TWIS_SUBSTATE_IDLE; -} - - -void nrfx_twis_disable(nrfx_twis_t const * p_instance) -{ - NRF_TWIS_Type * p_reg = p_instance->p_reg; - twis_control_block_t * p_cb = &m_cb[p_instance->drv_inst_idx]; - NRFX_ASSERT(p_cb->state != NRFX_DRV_STATE_UNINITIALIZED); - - nrf_twis_int_disable(p_reg, m_used_ints_mask); - - nrf_twis_disable(p_reg); - p_cb->state = NRFX_DRV_STATE_INITIALIZED; -} - -/* ARM recommends not using the LDREX and STREX instructions in C code. - * This is because the compiler might generate loads and stores between - * LDREX and STREX, potentially clearing the exclusive monitor set by LDREX. - * This recommendation also applies to the byte, halfword, and doubleword - * variants LDREXB, STREXB, LDREXH, STREXH, LDREXD, and STREXD. - * - * This is the reason for the function below to be implemented in assembly. - */ -//lint -save -e578 -#if defined (__CC_ARM ) -static __ASM uint32_t nrfx_twis_error_get_and_clear_internal(uint32_t volatile * perror) -{ - mov r3, r0 - mov r1, #0 -nrfx_twis_error_get_and_clear_internal_try - ldrex r0, [r3] - strex r2, r1, [r3] - cmp r2, r1 /* did this succeed? */ - bne nrfx_twis_error_get_and_clear_internal_try /* no - try again */ - bx lr -} -#elif defined ( __GNUC__ ) -static uint32_t nrfx_twis_error_get_and_clear_internal(uint32_t volatile * perror) -{ - uint32_t ret; - uint32_t temp; - __ASM volatile( - " .syntax unified \n" - "nrfx_twis_error_get_and_clear_internal_try: \n" - " ldrex %[ret], [%[perror]] \n" - " strex %[temp], %[zero], [%[perror]] \n" - " cmp %[temp], %[zero] \n" - " bne nrfx_twis_error_get_and_clear_internal_try \n" - : /* Output */ - [ret]"=&l"(ret), - [temp]"=&l"(temp) - : /* Input */ - [zero]"l"(0), - [perror]"l"(perror) - ); - (void)temp; - return ret; -} -#elif defined ( __ICCARM__ ) -static uint32_t nrfx_twis_error_get_and_clear_internal(uint32_t volatile * perror) -{ - uint32_t ret; - uint32_t temp; - __ASM volatile( - "1: \n" - " ldrex %[ret], [%[perror]] \n" - " strex %[temp], %[zero], [%[perror]] \n" - " cmp %[temp], %[zero] \n" - " bne.n 1b \n" - : /* Output */ - [ret]"=&l"(ret), - [temp]"=&l"(temp) - : /* Input */ - [zero]"l"(0), - [perror]"l"(perror) - ); - (void)temp; - return ret; -} -#else - #error Unknown compiler -#endif -//lint -restore - -uint32_t nrfx_twis_error_get_and_clear(nrfx_twis_t const * p_instance) -{ - nrfx_twis_preprocess_status(p_instance); - /* Make sure that access to error member is atomic - * so there is no bit that is cleared if it is not copied to local variable already. */ - twis_control_block_t * p_cb = &m_cb[p_instance->drv_inst_idx]; - return nrfx_twis_error_get_and_clear_internal(&p_cb->error); -} - - -nrfx_err_t nrfx_twis_tx_prepare(nrfx_twis_t const * p_instance, - void const * p_buf, - size_t size) -{ - nrfx_err_t err_code; - twis_control_block_t const * p_cb = &m_cb[p_instance->drv_inst_idx]; - - /* Check power state*/ - if (p_cb->state != NRFX_DRV_STATE_POWERED_ON) - { - err_code = NRFX_ERROR_INVALID_STATE; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - /* Check data address */ - if (!nrfx_is_in_ram(p_buf)) - { - err_code = NRFX_ERROR_INVALID_ADDR; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - /* Check data size */ - if ((size & TWIS_TXD_MAXCNT_MAXCNT_Msk) != size) - { - err_code = NRFX_ERROR_INVALID_LENGTH; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - - nrf_twis_tx_prepare(p_instance->p_reg, - (uint8_t const *)p_buf, - size); - err_code = NRFX_SUCCESS; - NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; -} - - -nrfx_err_t nrfx_twis_rx_prepare(nrfx_twis_t const * p_instance, - void * p_buf, - size_t size) -{ - nrfx_err_t err_code; - twis_control_block_t const * p_cb = &m_cb[p_instance->drv_inst_idx]; - - /* Check power state*/ - if (p_cb->state != NRFX_DRV_STATE_POWERED_ON) - { - err_code = NRFX_ERROR_INVALID_STATE; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - /* Check data address */ - if (!nrfx_is_in_ram(p_buf)) - { - err_code = NRFX_ERROR_INVALID_ADDR; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - /* Check data size */ - if ((size & TWIS_RXD_MAXCNT_MAXCNT_Msk) != size) - { - err_code = NRFX_ERROR_INVALID_LENGTH; - NRFX_LOG_WARNING("Function: %s, error code: %s.", - __func__, - NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; - } - - nrf_twis_rx_prepare(p_instance->p_reg, - (uint8_t *)p_buf, - size); - err_code = NRFX_SUCCESS; - NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code)); - return err_code; -} - - -bool nrfx_twis_is_busy(nrfx_twis_t const * p_instance) -{ - nrfx_twis_preprocess_status(p_instance); - twis_control_block_t const * p_cb = &m_cb[p_instance->drv_inst_idx]; - return NRFX_TWIS_SUBSTATE_IDLE != p_cb->substate; -} - -bool nrfx_twis_is_waiting_tx_buff(nrfx_twis_t const * p_instance) -{ - nrfx_twis_preprocess_status(p_instance); - twis_control_block_t const * p_cb = &m_cb[p_instance->drv_inst_idx]; - return NRFX_TWIS_SUBSTATE_READ_WAITING == p_cb->substate; -} - -bool nrfx_twis_is_waiting_rx_buff(nrfx_twis_t const * p_instance) -{ - nrfx_twis_preprocess_status(p_instance); - twis_control_block_t const * p_cb = &m_cb[p_instance->drv_inst_idx]; - return NRFX_TWIS_SUBSTATE_WRITE_WAITING == p_cb->substate; -} - -bool nrfx_twis_is_pending_tx(nrfx_twis_t const * p_instance) -{ - nrfx_twis_preprocess_status(p_instance); - twis_control_block_t const * p_cb = &m_cb[p_instance->drv_inst_idx]; - return NRFX_TWIS_SUBSTATE_READ_PENDING == p_cb->substate; -} - -bool nrfx_twis_is_pending_rx(nrfx_twis_t const * p_instance) -{ - nrfx_twis_preprocess_status(p_instance); - twis_control_block_t const * p_cb = &m_cb[p_instance->drv_inst_idx]; - return NRFX_TWIS_SUBSTATE_WRITE_PENDING == p_cb->substate; -} - - -#if NRFX_CHECK(NRFX_TWIS0_ENABLED) -void nrfx_twis_0_irq_handler(void) -{ - nrfx_twis_state_machine(NRF_TWIS0, &m_cb[NRFX_TWIS0_INST_IDX]); -} -#endif - -#if NRFX_CHECK(NRFX_TWIS1_ENABLED) -void nrfx_twis_1_irq_handler(void) -{ - nrfx_twis_state_machine(NRF_TWIS1, &m_cb[NRFX_TWIS1_INST_IDX]); -} -#endif - -#if NRFX_CHECK(NRFX_TWIS2_ENABLED) -void nrfx_twis_2_irq_handler(void) -{ - nrfx_twis_state_machine(NRF_TWIS2, &m_cb[NRFX_TWIS2_INST_IDX]); -} -#endif - -#if NRFX_CHECK(NRFX_TWIS3_ENABLED) -void nrfx_twis_3_irq_handler(void) -{ - nrfx_twis_state_machine(NRF_TWIS3, &m_cb[NRFX_TWIS3_INST_IDX]); -} -#endif - -#endif // NRFX_CHECK(NRFX_TWIS_ENABLED) diff --git a/modules/nrfx/drivers/src/nrfx_usbd.c b/modules/nrfx/drivers/src/nrfx_usbd.c deleted file mode 100644 index 7cab0d3..0000000 --- a/modules/nrfx/drivers/src/nrfx_usbd.c +++ /dev/null @@ -1,2282 +0,0 @@ -/** - * Copyright (c) 2016 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include - -#if NRFX_CHECK(NRFX_USBD_ENABLED) - -#include -#include "nrfx_usbd_errata.h" -#include - -#define NRFX_LOG_MODULE USBD -#include - -#ifndef NRFX_USBD_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 -#endif - -#ifndef NRFX_USBD_STARTED_EV_ENABLE -#define NRFX_USBD_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 -/* 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 -#endif - -#ifndef NRFX_USBD_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 -#endif - -#ifndef NRFX_USBD_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 -#endif - -#ifndef NRFX_USBD_USE_WORKAROUND_FOR_ANOMALY_211 -/* Anomaly 211 - Device remains in SUSPEND too long when host resumes - bus activity (sending SOF packets) without a RESUME condition. */ -#define NRFX_USBD_USE_WORKAROUND_FOR_ANOMALY_211 0 -#endif - -/** - * @defgroup nrfx_usbd_int USB Device driver internal part - * @internal - * @ingroup nrfx_usbd - * - * This part contains auxiliary internal macros, variables and functions. - * @{ - */ - -/** - * @brief Assert endpoint number validity. - * - * Internal macro to be used during program creation in debug mode. - * Generates assertion if endpoint number is not valid. - * - * @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))) \ -); - -/** - * @brief Lowest position of bit for IN endpoint. - * - * The first bit position corresponding to IN endpoint. - * @sa ep2bit bit2ep - */ -#define NRFX_USBD_EPIN_BITPOS_0 0 - -/** - * @brief Lowest position of bit for OUT endpoint. - * - * The first bit position corresponding to OUT endpoint - * @sa ep2bit bit2ep - */ -#define NRFX_USBD_EPOUT_BITPOS_0 16 - -/** - * @brief Input endpoint bits mask. - */ -#define NRFX_USBD_EPIN_BIT_MASK (0xFFFFU << NRFX_USBD_EPIN_BITPOS_0) - -/** - * @brief Output endpoint bits mask. - */ -#define NRFX_USBD_EPOUT_BIT_MASK (0xFFFFU << NRFX_USBD_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))) - -/** - * @brief Auxiliary macro to change EP number into bit position. - * - * This macro is used by @ref ep2bit function but also for statically check - * the bitpos values integrity during compilation. - * - * @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)) - -/** - * @brief Helper macro for creating an endpoint transfer event. - * - * @param[in] name Name of the created transfer event variable. - * @param[in] endpoint Endpoint number. - * @param[in] ep_stat Endpoint state to report. - * - * @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, \ - .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); - - -/** - * @brief Current driver state. - */ -static nrfx_drv_state_t m_drv_state = NRFX_DRV_STATE_UNINITIALIZED; - -/** - * @brief Event handler for the driver. - * - * Event handler that would be called on events. - * - * @note Currently it cannot be null if any interrupt is activated. - */ -static nrfx_usbd_event_handler_t m_event_handler; - -/** - * @brief Detected state of the bus. - * - * Internal state changed in interrupts handling when - * RESUME or SUSPEND event is processed. - * - * Values: - * - true - bus suspended - * - false - ongoing normal communication on the bus - * - * @note This is only the bus state and does not mean that the peripheral is in suspend state. - */ -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. - */ -static const uint32_t m_irq_disabled_in_suspend = - NRF_USBD_INT_ENDEPIN0_MASK | - NRF_USBD_INT_EP0DATADONE_MASK | - NRF_USBD_INT_ENDEPOUT0_MASK | - NRF_USBD_INT_EP0SETUP_MASK | - NRF_USBD_INT_DATAEP_MASK; - -/** - * @brief Direction of last received Setup transfer. - * - * 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; - -/** - * @brief Mark endpoint readiness for DMA transfer. - * - * Bits in this variable are cleared and set in interrupts. - * 1 means that endpoint is ready for DMA transfer. - * 0 means that DMA transfer cannot be performed on selected endpoint. - */ -static uint32_t m_ep_ready; - -/** - * @brief Mark endpoint with prepared data to transfer by DMA. - * - * This variable can be from any place in the code (interrupt or main thread). - * It would be cleared only from USBD interrupt. - * - * Mask prepared USBD data for transmission. - * It is cleared when no more data to transmit left. - */ -static uint32_t m_ep_dma_waiting; - -/** - * @brief Current EasyDMA state. - * - * Single flag, updated only inside interrupts, that marks current EasyDMA state. - * In USBD there is only one DMA channel working in background, and new transfer - * cannot be started when there is ongoing transfer on any other channel. - */ -static bool m_dma_pending; - -/** - * @brief First time enabling after reset. Used in nRF52 errata 223. - */ -static bool m_first_enable = true; - -/** - * @brief The structure that would hold transfer configuration to every endpoint - * - * The structure that holds all the data required by the endpoint to proceed - * with LIST functionality and generate quick callback directly when data - * 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. -} usbd_ep_state_t; - -/** - * @brief The array of transfer configurations for the endpoints. - * - * The status of the transfer on each endpoint. - */ -static struct -{ - usbd_ep_state_t ep_out[NRF_USBD_EPOUT_CNT]; //!< Status for OUT endpoints. - usbd_ep_state_t ep_in [NRF_USBD_EPIN_CNT ]; //!< Status for IN endpoints. -} m_ep_state; - -/** - * @brief Status variables for integrated feeders. - * - * Current status for integrated feeders (IN transfers). - * Integrated feeders are used for default transfers: - * 1. Simple RAM transfer. - * 2. Simple flash transfer. - * 3. RAM transfer with automatic ZLP. - * 4. Flash transfer with automatic ZLP. - */ -nrfx_usbd_transfer_t m_ep_feeder_state[NRF_USBD_EPIN_CNT]; - -/** - * @brief Status variables for integrated consumers. - * - * Current status for integrated consumers. - * Currently one type of transfer is supported: - * 1. Transfer to RAM. - * - * 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]; - - -/** - * @brief Buffer used to send data directly from FLASH. - * - * This is internal buffer that would be used to emulate the possibility - * to transfer data directly from FLASH. - * We do not have to care about the source of data when calling transfer functions. - * - * 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))]; - -/* Early declaration. Documentation above definition. */ -static void usbd_dmareq_process(void); - - -/** - * @brief Change endpoint number to endpoint event code. - * - * @param ep Endpoint number. - * - * @return Connected endpoint event code. - * - * Marker to delete when not required anymore: >> NRFX_USBD_ERRATA_ENABLE <<. - */ -static inline nrf_usbd_event_t nrfx_usbd_ep_to_endevent(nrfx_usbd_ep_t ep) -{ - NRFX_USBD_ASSERT_EP_VALID(ep); - - static const nrf_usbd_event_t epin_endev[] = - { - NRF_USBD_EVENT_ENDEPIN0, - NRF_USBD_EVENT_ENDEPIN1, - NRF_USBD_EVENT_ENDEPIN2, - NRF_USBD_EVENT_ENDEPIN3, - NRF_USBD_EVENT_ENDEPIN4, - NRF_USBD_EVENT_ENDEPIN5, - NRF_USBD_EVENT_ENDEPIN6, - NRF_USBD_EVENT_ENDEPIN7, - NRF_USBD_EVENT_ENDISOIN0 - }; - static const nrf_usbd_event_t epout_endev[] = - { - NRF_USBD_EVENT_ENDEPOUT0, - NRF_USBD_EVENT_ENDEPOUT1, - NRF_USBD_EVENT_ENDEPOUT2, - NRF_USBD_EVENT_ENDEPOUT3, - NRF_USBD_EVENT_ENDEPOUT4, - NRF_USBD_EVENT_ENDEPOUT5, - NRF_USBD_EVENT_ENDEPOUT6, - NRF_USBD_EVENT_ENDEPOUT7, - NRF_USBD_EVENT_ENDISOOUT0 - }; - - return (NRF_USBD_EPIN_CHECK(ep) ? epin_endev : epout_endev)[NRF_USBD_EP_NR_GET(ep)]; -} - - -/** - * @brief Get interrupt mask for selected endpoint. - * - * @param[in] ep Endpoint number. - * - * @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) -{ - NRFX_USBD_ASSERT_EP_VALID(ep); - - static const uint8_t epin_bitpos[] = - { - USBD_INTEN_ENDEPIN0_Pos, - USBD_INTEN_ENDEPIN1_Pos, - USBD_INTEN_ENDEPIN2_Pos, - USBD_INTEN_ENDEPIN3_Pos, - USBD_INTEN_ENDEPIN4_Pos, - USBD_INTEN_ENDEPIN5_Pos, - USBD_INTEN_ENDEPIN6_Pos, - USBD_INTEN_ENDEPIN7_Pos, - USBD_INTEN_ENDISOIN_Pos - }; - static const uint8_t epout_bitpos[] = - { - USBD_INTEN_ENDEPOUT0_Pos, - USBD_INTEN_ENDEPOUT1_Pos, - USBD_INTEN_ENDEPOUT2_Pos, - USBD_INTEN_ENDEPOUT3_Pos, - USBD_INTEN_ENDEPOUT4_Pos, - USBD_INTEN_ENDEPOUT5_Pos, - USBD_INTEN_ENDEPOUT6_Pos, - USBD_INTEN_ENDEPOUT7_Pos, - USBD_INTEN_ENDISOOUT_Pos - }; - - return 1UL << (NRF_USBD_EPIN_CHECK(ep) ? epin_bitpos : epout_bitpos)[NRF_USBD_EP_NR_GET(ep)]; -} - -/** - * @name Integrated feeders and consumers - * - * Internal, default functions for transfer processing. - * @{ - */ - -/** - * @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. - * - * @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) -{ - nrfx_usbd_transfer_t * p_transfer = 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)); - - size_t size = p_transfer->size; - if (size < data_size) - { - NRFX_LOG_DEBUG("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; - } - else - { - p_next->size = data_size; - p_next->p_data = p_transfer->p_data; - size -= data_size; - p_transfer->size = size; - p_transfer->p_data.addr += data_size; - } - return (ep_size == data_size) && (size != 0); -} - -/** - * @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. - * - * @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) -{ - nrfx_usbd_transfer_t * p_transfer = p_context; - NRFX_ASSERT(nrfx_is_in_ram(p_transfer->p_data.tx)); - - size_t tx_size = p_transfer->size; - if (tx_size > ep_size) - { - tx_size = ep_size; - } - - p_next->p_data = p_transfer->p_data; - p_next->size = tx_size; - - p_transfer->size -= tx_size; - p_transfer->p_data.addr += tx_size; - - return (p_transfer->size != 0); -} - -/** - * @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. - * - * @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) -{ - nrfx_usbd_transfer_t * p_transfer = p_context; - NRFX_ASSERT(nrfx_is_in_ram(p_transfer->p_data.tx)); - - size_t tx_size = p_transfer->size; - if (tx_size > ep_size) - { - tx_size = ep_size; - } - - p_next->p_data.tx = (tx_size == 0) ? NULL : p_transfer->p_data.tx; - p_next->size = tx_size; - - p_transfer->size -= tx_size; - p_transfer->p_data.addr += tx_size; - - return (tx_size != 0); -} - -/** - * @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. - * - * @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) -{ - nrfx_usbd_transfer_t * p_transfer = p_context; - NRFX_ASSERT(!nrfx_is_in_ram(p_transfer->p_data.tx)); - - size_t tx_size = p_transfer->size; - void * p_buffer = nrfx_usbd_feeder_buffer_get(); - - if (tx_size > ep_size) - { - tx_size = ep_size; - } - - NRFX_ASSERT(tx_size <= NRFX_USBD_FEEDER_BUFFER_SIZE); - memcpy(p_buffer, (p_transfer->p_data.tx), tx_size); - - p_next->p_data.tx = p_buffer; - p_next->size = tx_size; - - p_transfer->size -= tx_size; - p_transfer->p_data.addr += tx_size; - - return (p_transfer->size != 0); -} - -/** - * @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. - * - * @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) -{ - nrfx_usbd_transfer_t * p_transfer = p_context; - NRFX_ASSERT(!nrfx_is_in_ram(p_transfer->p_data.tx)); - - size_t tx_size = p_transfer->size; - void * p_buffer = nrfx_usbd_feeder_buffer_get(); - - if (tx_size > ep_size) - { - tx_size = ep_size; - } - - NRFX_ASSERT(tx_size <= NRFX_USBD_FEEDER_BUFFER_SIZE); - - if (tx_size != 0) - { - memcpy(p_buffer, (p_transfer->p_data.tx), tx_size); - p_next->p_data.tx = p_buffer; - } - else - { - p_next->p_data.tx = NULL; - } - p_next->size = tx_size; - - p_transfer->size -= tx_size; - p_transfer->p_data.addr += tx_size; - - return (tx_size != 0); -} - -/** @} */ - -/** - * @brief Change Driver endpoint number to HAL endpoint number. - * - * @param ep Driver endpoint identifier. - * - * @return Endpoint identifier in HAL. - * - * @sa nrfx_usbd_ep_from_hal - */ -static inline uint8_t ep_to_hal(nrfx_usbd_ep_t ep) -{ - NRFX_USBD_ASSERT_EP_VALID(ep); - return (uint8_t)ep; -} - -/** - * @brief Generate start task number for selected endpoint index. - * - * @param ep Endpoint number. - * - * @return Task for starting EasyDMA transfer on selected endpoint. - */ -static inline nrf_usbd_task_t task_start_ep(nrfx_usbd_ep_t ep) -{ - NRFX_USBD_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))); -} - -/** - * @brief Access selected endpoint state structure. - * - * Function used to change or just read the state of selected endpoint. - * It is used for internal transmission state. - * - * @param ep Endpoint number. - */ -static inline usbd_ep_state_t* ep_state_access(nrfx_usbd_ep_t ep) -{ - NRFX_USBD_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)); -} - -/** - * @brief Change endpoint number to bit position. - * - * Bit positions are defined the same way as they are placed in DATAEPSTATUS register, - * but bits for endpoint 0 are included. - * - * @param ep Endpoint number. - * - * @return Bit position related to the given endpoint number. - * - * @sa bit2ep - */ -static inline uint8_t ep2bit(nrfx_usbd_ep_t ep) -{ - NRFX_USBD_ASSERT_EP_VALID(ep); - return NRFX_USBD_EP_BITPOS(ep); -} - -/** - * @brief Change bit position to endpoint number. - * - * @param bitpos Bit position. - * - * @return Endpoint number corresponding to given bit position. - * - * @sa ep2bit - */ -static inline nrfx_usbd_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) : NRF_USBD_EPIN(bitpos)); -} - -/** - * @brief Mark that EasyDMA is working. - * - * Internal function to set the flag informing about EasyDMA transfer pending. - * This function is called always just after the EasyDMA transfer is started. - */ -static inline void usbd_dma_pending_set(void) -{ - if (nrfx_usbd_errata_199()) - { - *((volatile uint32_t *)0x40027C1C) = 0x00000082; - } - m_dma_pending = true; -} - -/** - * @brief Mark that EasyDMA is free. - * - * Internal function to clear the flag informing about EasyDMA transfer pending. - * This function is called always just after the finished EasyDMA transfer is detected. - */ -static inline void usbd_dma_pending_clear(void) -{ - if (nrfx_usbd_errata_199()) - { - *((volatile uint32_t *)0x40027C1C) = 0x00000000; - } - m_dma_pending = false; -} - -/** - * @brief Start selected EasyDMA transmission. - * - * This is internal auxiliary function. - * No checking is made if EasyDMA is ready for new transmission. - * - * @param[in] ep Number of endpoint for transmission. - * 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) -{ - nrf_usbd_task_trigger(task_start_ep(ep)); -} - -void nrfx_usbd_isoinconfig_set(nrf_usbd_isoinconfig_t config) -{ - nrf_usbd_isoinconfig_set(config); -} - -nrf_usbd_isoinconfig_t nrfx_usbd_isoinconfig_get(void) -{ - return nrf_usbd_isoinconfig_get(); -} - -/** - * @brief Abort pending transfer on selected endpoint. - * - * @param ep Endpoint number. - * - * @note - * This function locks interrupts that may be costly. - * It is good idea to test if the endpoint is still busy before calling this function: - * @code - (m_ep_dma_waiting & (1U << ep2bit(ep))) - * @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) -{ - NRFX_CRITICAL_SECTION_ENTER(); - - usbd_ep_state_t * p_state = ep_state_access(ep); - - if (NRF_USBD_EPOUT_CHECK(ep)) - { - /* Host -> Device */ - if ((~m_ep_dma_waiting) & (1U << ep2bit(ep))) - { - /* If the bit in m_ep_dma_waiting in cleared - nothing would be - * processed inside transfer processing */ - nrfx_usbd_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; - } - else - { - if(!NRF_USBD_EPISO_CHECK(ep)) - { - /* Workaround: Disarm the endpoint if there is any data buffered. */ - if(ep != NRFX_USBD_EPIN0) - { - *((volatile uint32_t *)(NRF_USBD_BASE + 0x800)) = 0x7B6 + (2u * (NRF_USBD_EP_NR_GET(ep) - 1)); - uint8_t temp = *((volatile uint32_t *)(NRF_USBD_BASE + 0x804)); - temp |= (1U << 1); - *((volatile uint32_t *)(NRF_USBD_BASE + 0x804)) |= temp; - (void)(*((volatile uint32_t *)(NRF_USBD_BASE + 0x804))); - } - else - { - *((volatile uint32_t *)(NRF_USBD_BASE + 0x800)) = 0x7B4; - uint8_t temp = *((volatile uint32_t *)(NRF_USBD_BASE + 0x804)); - temp |= (1U << 2); - *((volatile uint32_t *)(NRF_USBD_BASE + 0x804)) |= temp; - (void)(*((volatile uint32_t *)(NRF_USBD_BASE + 0x804))); - } - } - if ((m_ep_dma_waiting | (~m_ep_ready)) & (1U << ep2bit(ep))) - { - /* Device -> Host */ - m_ep_dma_waiting &= ~(1U << ep2bit(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); - m_event_handler(&evt); - } - } - NRFX_CRITICAL_SECTION_EXIT(); -} - -void nrfx_usbd_ep_abort(nrfx_usbd_ep_t ep) -{ - usbd_ep_abort(ep); -} - - -/** - * @brief Abort all pending endpoints. - * - * Function aborts all pending endpoint transfers. - */ -static void usbd_ep_abort_all(void) -{ - uint32_t ep_waiting = m_ep_dma_waiting | (m_ep_ready & NRFX_USBD_EPOUT_BIT_MASK); - while (0 != ep_waiting) - { - uint8_t bitpos = __CLZ(__RBIT(ep_waiting)); - if (!NRF_USBD_EPISO_CHECK(bit2ep(bitpos))) - { - usbd_ep_abort(bit2ep(bitpos)); - } - ep_waiting &= ~(1U << bitpos); - } - - m_ep_ready = (((1U << NRF_USBD_EPIN_CNT) - 1U) << NRFX_USBD_EPIN_BITPOS_0); -} - -/** - * @brief Force the USBD interrupt into pending state. - * - * This function is used to force USBD interrupt to be processed right now. - * It makes it possible to process all EasyDMA access on one thread priority level. - */ -static inline void usbd_int_rise(void) -{ - NRFX_IRQ_PENDING_SET(USBD_IRQn); -} - -/** - * @name USBD interrupt runtimes. - * - * Interrupt runtimes that would be vectorized using @ref m_isr. - * @{ - */ - -static void ev_usbreset_handler(void) -{ - m_bus_suspend = false; - m_last_setup_dir = NRFX_USBD_EPOUT0; - - const nrfx_usbd_evt_t evt = { - .type = NRFX_USBD_EVT_RESET - }; - - m_event_handler(&evt); -} - -static void ev_started_handler(void) -{ -#if NRFX_USBD_STARTED_EV_ENABLE - // Handler not used by the stack. - // May be used for debugging. -#endif -} - -/** - * @brief Handler for EasyDMA event without endpoint clearing. - * - * This handler would be called when EasyDMA transfer for endpoints that does not require clearing. - * All in endpoints are cleared automatically when new EasyDMA transfer is initialized. - * For endpoint 0 see @ref nrf_usbd_ep0out_dma_handler. - * - * @param[in] ep Endpoint number. - */ -static inline void nrf_usbd_ep0in_dma_handler(void) -{ - const nrfx_usbd_ep_t ep = NRFX_USBD_EPIN0; - NRFX_LOG_DEBUG("USB event: DMA ready IN0"); - usbd_dma_pending_clear(); - - usbd_ep_state_t * p_state = ep_state_access(ep); - if (NRFX_USBD_EP_ABORTED == p_state->status) - { - /* Clear transfer information just in case */ - (void)(NRFX_ATOMIC_FETCH_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)))); - } - else - { - /* Nothing to do */ - } -} - -/** - * @brief Handler for EasyDMA event without endpoint clearing. - * - * This handler would be called when EasyDMA transfer for endpoints that does not require clearing. - * All in endpoints are cleared automatically when new EasyDMA transfer is initialized. - * For endpoint 0 see @ref nrf_usbd_ep0out_dma_handler. - * - * @param[in] ep Endpoint number. - */ -static inline void nrf_usbd_epin_dma_handler(nrfx_usbd_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); - usbd_dma_pending_clear(); - - usbd_ep_state_t * p_state = ep_state_access(ep); - if (NRFX_USBD_EP_ABORTED == p_state->status) - { - /* Clear transfer information just in case */ - (void)(NRFX_ATOMIC_FETCH_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)))); - } - else - { - /* Nothing to do */ - } -} - -/** - * @brief Handler for EasyDMA event from in isochronous endpoint. - */ -static inline void nrf_usbd_epiniso_dma_handler(nrfx_usbd_ep_t ep) -{ - if (NRFX_USBD_ISO_DEBUG) - { - NRFX_LOG_DEBUG("USB event: DMA ready ISOIN: %x", ep); - } - NRFX_ASSERT(NRF_USBD_EPIN_CHECK(ep)); - NRFX_ASSERT(NRF_USBD_EPISO_CHECK(ep)); - usbd_dma_pending_clear(); - - usbd_ep_state_t * p_state = ep_state_access(ep); - if (NRFX_USBD_EP_ABORTED == p_state->status) - { - /* Clear transfer information just in case */ - (void)(NRFX_ATOMIC_FETCH_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)))); - /* 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); - m_event_handler(&evt); - } - else - { - /* Nothing to do */ - } -} - -/** - * @brief Handler for EasyDMA event for OUT endpoint 0. - * - * EP0 OUT have to be cleared automatically in special way - only in the middle of the transfer. - * It cannot be cleared when required transfer is finished because it means the same that accepting the comment. - */ -static inline void nrf_usbd_ep0out_dma_handler(void) -{ - const nrfx_usbd_ep_t ep = NRFX_USBD_EPOUT0; - NRFX_LOG_DEBUG("USB event: DMA ready OUT0"); - usbd_dma_pending_clear(); - - usbd_ep_state_t * p_state = ep_state_access(ep); - if (NRFX_USBD_EP_ABORTED == p_state->status) - { - /* Clear transfer information just in case */ - (void)(NRFX_ATOMIC_FETCH_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)))); - /* 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); - m_event_handler(&evt); - } - else - { - nrfx_usbd_setup_data_clear(); - } -} - -/** - * @brief Handler for EasyDMA event from endpoinpoint that requires clearing. - * - * This handler would be called when EasyDMA transfer for OUT endpoint has been finished. - * - * @param[in] ep Endpoint number. - */ -static inline void nrf_usbd_epout_dma_handler(nrfx_usbd_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); - usbd_dma_pending_clear(); - - usbd_ep_state_t * p_state = ep_state_access(ep); - if (NRFX_USBD_EP_ABORTED == p_state->status) - { - /* Clear transfer information just in case */ - (void)(NRFX_ATOMIC_FETCH_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)))); - /* 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); - m_event_handler(&evt); - } - else - { - /* Nothing to do */ - } - -#if NRFX_USBD_EARLY_DMA_PROCESS - /* Speed up */ - usbd_dmareq_process(); -#endif -} - -/** - * @brief Handler for EasyDMA event from out isochronous endpoint. - */ -static inline void nrf_usbd_epoutiso_dma_handler(nrfx_usbd_ep_t ep) -{ - if (NRFX_USBD_ISO_DEBUG) - { - NRFX_LOG_DEBUG("DMA ready ISOOUT: %x", ep); - } - NRFX_ASSERT(NRF_USBD_EPISO_CHECK(ep)); - usbd_dma_pending_clear(); - - usbd_ep_state_t * p_state = ep_state_access(ep); - if (NRFX_USBD_EP_ABORTED == p_state->status) - { - /* Nothing to do - just ignore */ - } - else if (p_state->handler.consumer == NULL) - { - (void)(NRFX_ATOMIC_FETCH_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); - m_event_handler(&evt); - } - else - { - /* Nothing to do */ - } -} - - -static void ev_dma_epin0_handler(void) { nrf_usbd_ep0in_dma_handler(); } -static void ev_dma_epin1_handler(void) { nrf_usbd_epin_dma_handler(NRFX_USBD_EPIN1 ); } -static void ev_dma_epin2_handler(void) { nrf_usbd_epin_dma_handler(NRFX_USBD_EPIN2 ); } -static void ev_dma_epin3_handler(void) { nrf_usbd_epin_dma_handler(NRFX_USBD_EPIN3 ); } -static void ev_dma_epin4_handler(void) { nrf_usbd_epin_dma_handler(NRFX_USBD_EPIN4 ); } -static void ev_dma_epin5_handler(void) { nrf_usbd_epin_dma_handler(NRFX_USBD_EPIN5 ); } -static void ev_dma_epin6_handler(void) { nrf_usbd_epin_dma_handler(NRFX_USBD_EPIN6 ); } -static void ev_dma_epin7_handler(void) { nrf_usbd_epin_dma_handler(NRFX_USBD_EPIN7 ); } -static void ev_dma_epin8_handler(void) { nrf_usbd_epiniso_dma_handler(NRFX_USBD_EPIN8 ); } - -static void ev_dma_epout0_handler(void) { nrf_usbd_ep0out_dma_handler(); } -static void ev_dma_epout1_handler(void) { nrf_usbd_epout_dma_handler(NRFX_USBD_EPOUT1); } -static void ev_dma_epout2_handler(void) { nrf_usbd_epout_dma_handler(NRFX_USBD_EPOUT2); } -static void ev_dma_epout3_handler(void) { nrf_usbd_epout_dma_handler(NRFX_USBD_EPOUT3); } -static void ev_dma_epout4_handler(void) { nrf_usbd_epout_dma_handler(NRFX_USBD_EPOUT4); } -static void ev_dma_epout5_handler(void) { nrf_usbd_epout_dma_handler(NRFX_USBD_EPOUT5); } -static void ev_dma_epout6_handler(void) { nrf_usbd_epout_dma_handler(NRFX_USBD_EPOUT6); } -static void ev_dma_epout7_handler(void) { nrf_usbd_epout_dma_handler(NRFX_USBD_EPOUT7); } -static void ev_dma_epout8_handler(void) { nrf_usbd_epoutiso_dma_handler(NRFX_USBD_EPOUT8); } - -static void ev_sof_handler(void) -{ - nrfx_usbd_evt_t evt = { - NRFX_USBD_EVT_SOF, - .data = { .sof = { .framecnt = nrf_usbd_framecntr_get() }} - }; - - /* Process isochronous endpoints */ - uint32_t iso_ready_mask = (1U << ep2bit(NRFX_USBD_EPIN8)); - if (nrf_usbd_episoout_size_get(NRFX_USBD_EPOUT8) != NRF_USBD_EPISOOUT_NO_DATA) - { - iso_ready_mask |= (1U << ep2bit(NRFX_USBD_EPOUT8)); - } - m_ep_ready |= iso_ready_mask; - - m_event_handler(&evt); -} - -/** - * @brief React on data transfer finished. - * - * Auxiliary internal function. - * @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) -{ - NRFX_LOG_DEBUG("USBD event: EndpointData: %x", ep); - /* Mark endpoint ready for next DMA access */ - m_ep_ready |= (1U << bitpos); - - if (NRF_USBD_EPIN_CHECK(ep)) - { - /* IN endpoint (Device -> Host) */ - - /* Secure against the race condition that occurs when an IN transfer is interrupted - * by an OUT transaction, which in turn is interrupted by a process with higher priority. - * If the IN events ENDEPIN and EPDATA arrive during that high priority 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(nrfx_usbd_ep_to_endevent(ep))) - { - if (ep != NRFX_USBD_EPIN0) - { - nrf_usbd_epin_dma_handler(ep); - } - else - { - nrf_usbd_ep0in_dma_handler(); - } - } - - if (0 == (m_ep_dma_waiting & (1U << bitpos))) - { - NRFX_LOG_DEBUG("USBD event: EndpointData: In finished"); - /* No more data to be send - transmission finished */ - NRFX_USBD_EP_TRANSFER_EVENT(evt, ep, NRFX_USBD_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"); - /* No buffer prepared - send event to the application */ - NRFX_USBD_EP_TRANSFER_EVENT(evt, ep, NRFX_USBD_EP_WAITING); - m_event_handler(&evt); - } - } -} - -static void ev_setup_data_handler(void) -{ - usbd_ep_data_handler(m_last_setup_dir, ep2bit(m_last_setup_dir)); -} - -static void ev_setup_handler(void) -{ - NRFX_LOG_DEBUG("USBD event: Setup (rt:%.2x r:%.2x v:%.4x i:%.4x l:%u )", - nrf_usbd_setup_bmrequesttype_get(), - nrf_usbd_setup_brequest_get(), - nrf_usbd_setup_wvalue_get(), - nrf_usbd_setup_windex_get(), - nrf_usbd_setup_wlength_get()); - uint8_t bmRequestType = nrf_usbd_setup_bmrequesttype_get(); - - if ((m_ep_dma_waiting | ((~m_ep_ready) & NRFX_USBD_EPIN_BIT_MASK)) - & (1U <handler.feeder) != NULL); - - if (NRF_USBD_EPIN_CHECK(ep)) - { - /* Device -> Host */ - continue_transfer = p_state->handler.feeder( - &transfer, - p_state->p_context, - p_state->max_packet_size); - - if (!continue_transfer) - { - p_state->handler.feeder = NULL; - } - } - else - { - /* Host -> Device */ - const size_t rx_size = nrfx_usbd_epout_size_get(ep); - continue_transfer = p_state->handler.consumer( - &transfer, - p_state->p_context, - p_state->max_packet_size, - rx_size); - - if (transfer.p_data.rx == NULL) - { - /* Dropping transfer - allow processing */ - NRFX_ASSERT(transfer.size == 0); - } - else if (transfer.size < rx_size) - { - NRFX_LOG_DEBUG("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); - m_event_handler(&evt); - /* This endpoint will not be transmitted now, repeat the loop */ - continue; - } - else - { - /* Nothing to do - only check integrity if assertions are enabled */ - NRFX_ASSERT(transfer.size == rx_size); - } - - if (!continue_transfer) - { - p_state->handler.consumer = NULL; - } - } - - 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", - ep, - transfer.size); - } - /* Update number of currently transferred bytes */ - p_state->transfer_cnt += transfer.size; - /* Start transfer to the endpoint buffer */ - nrf_usbd_ep_easydma_set(ep, transfer.p_data.addr, (uint32_t)transfer.size); - - usbd_dma_start(ep); - /* There is a lot of USBD registers that cannot be accessed during EasyDMA transfer. - * This is quick fix to maintain stability of the stack. - * It cost some performance but makes stack stable. */ - while (!nrf_usbd_event_check(nrfx_usbd_ep_to_endevent(ep)) && - !nrf_usbd_event_check(NRF_USBD_EVENT_USBRESET)) - { - /* Empty */ - } - - if (NRFX_USBD_DMAREQ_PROCESS_DEBUG) - { - NRFX_LOG_DEBUG("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"); - } - } -} - -/** - * @brief Wait for a specified eventcause and clear it afterwards. - */ -static inline void usbd_eventcause_wait_and_clear(nrf_usbd_eventcause_mask_t eventcause) -{ - while (0 == (eventcause & nrf_usbd_eventcause_get())) - { - /* Empty loop */ - } - nrf_usbd_eventcause_clear(eventcause); -} - -/** - * @brief Begin errata 171. - */ -static inline void usbd_errata_171_begin(void) -{ - NRFX_CRITICAL_SECTION_ENTER(); - if (*((volatile uint32_t *)(0x4006EC00)) == 0x00000000) - { - *((volatile uint32_t *)(0x4006EC00)) = 0x00009375; - *((volatile uint32_t *)(0x4006EC14)) = 0x000000C0; - *((volatile uint32_t *)(0x4006EC00)) = 0x00009375; - } - else - { - *((volatile uint32_t *)(0x4006EC14)) = 0x000000C0; - } - NRFX_CRITICAL_SECTION_EXIT(); -} - -/** - * @brief End errata 171. - */ -static inline void usbd_errata_171_end(void) -{ - NRFX_CRITICAL_SECTION_ENTER(); - if (*((volatile uint32_t *)(0x4006EC00)) == 0x00000000) - { - *((volatile uint32_t *)(0x4006EC00)) = 0x00009375; - *((volatile uint32_t *)(0x4006EC14)) = 0x00000000; - *((volatile uint32_t *)(0x4006EC00)) = 0x00009375; - } - else - { - *((volatile uint32_t *)(0x4006EC14)) = 0x00000000; - } - NRFX_CRITICAL_SECTION_EXIT(); -} - -/** - * @brief Begin erratas 187 and 211. - */ -static inline void usbd_errata_187_211_begin(void) -{ - NRFX_CRITICAL_SECTION_ENTER(); - if (*((volatile uint32_t *)(0x4006EC00)) == 0x00000000) - { - *((volatile uint32_t *)(0x4006EC00)) = 0x00009375; - *((volatile uint32_t *)(0x4006ED14)) = 0x00000003; - *((volatile uint32_t *)(0x4006EC00)) = 0x00009375; - } - else - { - *((volatile uint32_t *)(0x4006ED14)) = 0x00000003; - } - NRFX_CRITICAL_SECTION_EXIT(); -} - -/** - * @brief End erratas 187 and 211. - */ -static inline void usbd_errata_187_211_end(void) -{ - NRFX_CRITICAL_SECTION_ENTER(); - if (*((volatile uint32_t *)(0x4006EC00)) == 0x00000000) - { - *((volatile uint32_t *)(0x4006EC00)) = 0x00009375; - *((volatile uint32_t *)(0x4006ED14)) = 0x00000000; - *((volatile uint32_t *)(0x4006EC00)) = 0x00009375; - } - else - { - *((volatile uint32_t *)(0x4006ED14)) = 0x00000000; - } - NRFX_CRITICAL_SECTION_EXIT(); -} - -/** - * @brief Enable USBD peripheral. - */ -static void usbd_enable(void) -{ - if (nrfx_usbd_errata_187()) - { - usbd_errata_187_211_begin(); - } - - if (nrfx_usbd_errata_171()) - { - usbd_errata_171_begin(); - } - - /* Enable the peripheral */ - nrf_usbd_enable(); - - /* 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()) - { - usbd_errata_171_end(); - } - - if (nrfx_usbd_errata_187()) - { - usbd_errata_187_211_end(); - } -} -/** @} */ - -/** - * @brief USBD interrupt service routines. - * - */ -static const nrfx_irq_handler_t m_isr[] = -{ - [USBD_INTEN_USBRESET_Pos ] = ev_usbreset_handler, - [USBD_INTEN_STARTED_Pos ] = ev_started_handler, - [USBD_INTEN_ENDEPIN0_Pos ] = ev_dma_epin0_handler, - [USBD_INTEN_ENDEPIN1_Pos ] = ev_dma_epin1_handler, - [USBD_INTEN_ENDEPIN2_Pos ] = ev_dma_epin2_handler, - [USBD_INTEN_ENDEPIN3_Pos ] = ev_dma_epin3_handler, - [USBD_INTEN_ENDEPIN4_Pos ] = ev_dma_epin4_handler, - [USBD_INTEN_ENDEPIN5_Pos ] = ev_dma_epin5_handler, - [USBD_INTEN_ENDEPIN6_Pos ] = ev_dma_epin6_handler, - [USBD_INTEN_ENDEPIN7_Pos ] = ev_dma_epin7_handler, - [USBD_INTEN_EP0DATADONE_Pos] = ev_setup_data_handler, - [USBD_INTEN_ENDISOIN_Pos ] = ev_dma_epin8_handler, - [USBD_INTEN_ENDEPOUT0_Pos ] = ev_dma_epout0_handler, - [USBD_INTEN_ENDEPOUT1_Pos ] = ev_dma_epout1_handler, - [USBD_INTEN_ENDEPOUT2_Pos ] = ev_dma_epout2_handler, - [USBD_INTEN_ENDEPOUT3_Pos ] = ev_dma_epout3_handler, - [USBD_INTEN_ENDEPOUT4_Pos ] = ev_dma_epout4_handler, - [USBD_INTEN_ENDEPOUT5_Pos ] = ev_dma_epout5_handler, - [USBD_INTEN_ENDEPOUT6_Pos ] = ev_dma_epout6_handler, - [USBD_INTEN_ENDEPOUT7_Pos ] = ev_dma_epout7_handler, - [USBD_INTEN_ENDISOOUT_Pos ] = ev_dma_epout8_handler, - [USBD_INTEN_SOF_Pos ] = ev_sof_handler, - [USBD_INTEN_USBEVENT_Pos ] = ev_usbevent_handler, - [USBD_INTEN_EP0SETUP_Pos ] = ev_setup_handler, - [USBD_INTEN_EPDATA_Pos ] = ev_epdata_handler -}; - -/** - * @name Interrupt handlers - * - * @{ - */ -void nrfx_usbd_irq_handler(void) -{ - const uint32_t enabled = nrf_usbd_int_enable_get(); - uint32_t to_process = enabled; - uint32_t active = 0; - - /* Check all enabled interrupts */ - while (to_process) - { - uint8_t event_nr = __CLZ(__RBIT(to_process)); - if (nrf_usbd_event_get_and_clear((nrf_usbd_event_t)nrfx_bitpos_to_event(event_nr))) - { - active |= 1UL << event_nr; - } - to_process &= ~(1UL << event_nr); - } - - /* Process the active interrupts */ - bool setup_active = 0 != (active & NRF_USBD_INT_EP0SETUP_MASK); - active &= ~NRF_USBD_INT_EP0SETUP_MASK; - - while (active) - { - uint8_t event_nr = __CLZ(__RBIT(active)); - m_isr[event_nr](); - active &= ~(1UL << event_nr); - } - usbd_dmareq_process(); - - if (setup_active) - { - m_isr[USBD_INTEN_EP0SETUP_Pos](); - } -} - -/** @} */ -/** @} */ - -nrfx_err_t nrfx_usbd_init(nrfx_usbd_event_handler_t event_handler) -{ - NRFX_ASSERT(event_handler); - - if (m_drv_state != NRFX_DRV_STATE_UNINITIALIZED) - { - return NRFX_ERROR_INVALID_STATE; - } - - m_event_handler = event_handler; - m_drv_state = NRFX_DRV_STATE_INITIALIZED; - - uint8_t n; - for (n = 0; n < NRF_USBD_EPIN_CNT; ++n) - { - nrfx_usbd_ep_t ep = NRFX_USBD_EPIN(n); - nrfx_usbd_ep_max_packet_size_set(ep, NRF_USBD_EPISO_CHECK(ep) ? - (NRFX_USBD_ISOSIZE / 2) : NRFX_USBD_EPSIZE); - usbd_ep_state_t * p_state = ep_state_access(ep); - p_state->status = NRFX_USBD_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); - nrfx_usbd_ep_max_packet_size_set(ep, NRF_USBD_EPISO_CHECK(ep) ? - (NRFX_USBD_ISOSIZE / 2) : NRFX_USBD_EPSIZE); - usbd_ep_state_t * p_state = ep_state_access(ep); - p_state->status = NRFX_USBD_EP_OK; - p_state->handler.consumer = NULL; - p_state->transfer_cnt = 0; - } - - return NRFX_SUCCESS; -} - -void nrfx_usbd_uninit(void) -{ - NRFX_ASSERT(m_drv_state == NRFX_DRV_STATE_INITIALIZED); - - m_event_handler = NULL; - m_drv_state = NRFX_DRV_STATE_UNINITIALIZED; - return; -} - -void nrfx_usbd_enable(void) -{ - NRFX_ASSERT(m_drv_state == NRFX_DRV_STATE_INITIALIZED); - - /* Prepare for READY event receiving */ - nrf_usbd_eventcause_clear(NRF_USBD_EVENTCAUSE_READY_MASK); - - usbd_enable(); - - if (nrfx_usbd_errata_223() && m_first_enable) - { - nrf_usbd_disable(); - - usbd_enable(); - - m_first_enable = false; - } - -#if NRFX_USBD_USE_WORKAROUND_FOR_ANOMALY_211 - if (nrfx_usbd_errata_187() || nrfx_usbd_errata_211()) -#else - if (nrfx_usbd_errata_187()) -#endif - { - usbd_errata_187_211_begin(); - } - - if (nrfx_usbd_errata_166()) - { - *((volatile uint32_t *)(NRF_USBD_BASE + 0x800)) = 0x7E3; - *((volatile uint32_t *)(NRF_USBD_BASE + 0x804)) = 0x40; - __ISB(); - __DSB(); - } - - nrf_usbd_isosplit_set(NRF_USBD_ISOSPLIT_HALF); - - if (NRFX_USBD_CONFIG_ISO_IN_ZLP) - { - nrfx_usbd_isoinconfig_set(NRF_USBD_ISOINCONFIG_ZERODATA); - } - else - { - nrfx_usbd_isoinconfig_set(NRF_USBD_ISOINCONFIG_NORESP); - } - - m_ep_ready = (((1U << NRF_USBD_EPIN_CNT) - 1U) << NRFX_USBD_EPIN_BITPOS_0); - m_ep_dma_waiting = 0; - usbd_dma_pending_clear(); - m_last_setup_dir = NRFX_USBD_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()) -#else - if (nrfx_usbd_errata_187()) -#endif - { - usbd_errata_187_211_end(); - } -} - -void nrfx_usbd_disable(void) -{ - NRFX_ASSERT(m_drv_state != NRFX_DRV_STATE_UNINITIALIZED); - - /* Stop just in case */ - nrfx_usbd_stop(); - - /* Disable all parts */ - nrf_usbd_int_disable(nrf_usbd_int_enable_get()); - nrf_usbd_disable(); - usbd_dma_pending_clear(); - m_drv_state = NRFX_DRV_STATE_INITIALIZED; - -#if NRFX_USBD_USE_WORKAROUND_FOR_ANOMALY_211 - if (nrfx_usbd_errata_211()) - { - usbd_errata_187_211_end(); - } -#endif -} - -void nrfx_usbd_start(bool enable_sof) -{ - NRFX_ASSERT(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 | - NRF_USBD_INT_ENDEPIN0_MASK | - NRF_USBD_INT_EP0DATADONE_MASK | - NRF_USBD_INT_ENDEPOUT0_MASK | - NRF_USBD_INT_USBEVENT_MASK | - NRF_USBD_INT_EP0SETUP_MASK | - NRF_USBD_INT_DATAEP_MASK; - - if (enable_sof) - { - ints_to_enable |= NRF_USBD_INT_SOF_MASK; - } - - /* Enable all required interrupts */ - nrf_usbd_int_enable(ints_to_enable); - - /* Enable interrupt globally */ - NRFX_IRQ_PRIORITY_SET(USBD_IRQn, NRFX_USBD_CONFIG_IRQ_PRIORITY); - NRFX_IRQ_ENABLE(USBD_IRQn); - - /* Enable pullups */ - nrf_usbd_pullup_enable(); -} - -void nrfx_usbd_stop(void) -{ - NRFX_ASSERT(m_drv_state == NRFX_DRV_STATE_POWERED_ON); - - /* Clear interrupt */ - NRFX_IRQ_PENDING_CLEAR(USBD_IRQn); - - if (NRFX_IRQ_IS_ENABLED(USBD_IRQn)) - { - /* Abort transfers */ - usbd_ep_abort_all(); - - /* Disable pullups */ - nrf_usbd_pullup_disable(); - - /* Disable interrupt globally */ - NRFX_IRQ_DISABLE(USBD_IRQn); - - /* Disable all interrupts */ - nrf_usbd_int_disable(~0U); - } -} - -bool nrfx_usbd_is_initialized(void) -{ - return (m_drv_state >= NRFX_DRV_STATE_INITIALIZED); -} - -bool nrfx_usbd_is_enabled(void) -{ - return (m_drv_state >= NRFX_DRV_STATE_POWERED_ON); -} - -bool nrfx_usbd_is_started(void) -{ - return (nrfx_usbd_is_enabled() && NRFX_IRQ_IS_ENABLED(USBD_IRQn)); -} - -bool nrfx_usbd_suspend(void) -{ - bool suspended = false; - - NRFX_CRITICAL_SECTION_ENTER(); - if (m_bus_suspend) - { - usbd_ep_abort_all(); - - if (!(nrf_usbd_eventcause_get() & NRF_USBD_EVENTCAUSE_RESUME_MASK)) - { - nrf_usbd_lowpower_enable(); - if (nrf_usbd_eventcause_get() & NRF_USBD_EVENTCAUSE_RESUME_MASK) - { - nrf_usbd_lowpower_disable(); - } - else - { - suspended = true; - } - } - } - NRFX_CRITICAL_SECTION_EXIT(); - - return suspended; -} - -bool nrfx_usbd_wakeup_req(void) -{ - bool started = false; - - NRFX_CRITICAL_SECTION_ENTER(); - if (m_bus_suspend && nrf_usbd_lowpower_check()) - { - nrf_usbd_lowpower_disable(); - started = true; - - if (nrfx_usbd_errata_171()) - { - if (*((volatile uint32_t *)(0x4006EC00)) == 0x00000000) - { - *((volatile uint32_t *)(0x4006EC00)) = 0x00009375; - *((volatile uint32_t *)(0x4006EC14)) = 0x000000C0; - *((volatile uint32_t *)(0x4006EC00)) = 0x00009375; - } - else - { - *((volatile uint32_t *)(0x4006EC14)) = 0x000000C0; - } - - } - } - NRFX_CRITICAL_SECTION_EXIT(); - - return started; -} - -bool nrfx_usbd_suspend_check(void) -{ - return nrf_usbd_lowpower_check(); -} - -void nrfx_usbd_suspend_irq_config(void) -{ - nrf_usbd_int_disable(m_irq_disabled_in_suspend); -} - -void nrfx_usbd_active_irq_config(void) -{ - nrf_usbd_int_enable(m_irq_disabled_in_suspend); -} - -bool nrfx_usbd_bus_suspend_check(void) -{ - return m_bus_suspend; -} - -void nrfx_usbd_force_bus_wakeup(void) -{ - m_bus_suspend = false; -} - -void nrfx_usbd_ep_max_packet_size_set(nrfx_usbd_ep_t ep, uint16_t size) -{ - /* Only power of 2 size allowed */ - NRFX_ASSERT((size & 0x01) == 0); - /* 0 allowed only for ISO endpoints */ - NRFX_ASSERT((size != 0) || NRF_USBD_EPISO_CHECK(ep)); - /* 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))); - - 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) -{ - 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) -{ - return nrf_usbd_ep_enable_check(ep_to_hal(ep)); -} - -void nrfx_usbd_ep_enable(nrfx_usbd_ep_t ep) -{ - nrf_usbd_int_enable(nrfx_usbd_ep_to_int(ep)); - - if (nrf_usbd_ep_enable_check(ep)) - { - return; - } - nrf_usbd_ep_enable(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); - m_ep_dma_waiting &= ~(1U << ep2bit(ep)); - NRFX_CRITICAL_SECTION_EXIT(); - } -} - -void nrfx_usbd_ep_disable(nrfx_usbd_ep_t ep) -{ - usbd_ep_abort(ep); - nrf_usbd_ep_disable(ep_to_hal(ep)); - nrf_usbd_int_disable(nrfx_usbd_ep_to_int(ep)); -} - -void nrfx_usbd_ep_default_config(void) -{ - nrf_usbd_int_disable( - NRF_USBD_INT_ENDEPIN1_MASK | - NRF_USBD_INT_ENDEPIN2_MASK | - NRF_USBD_INT_ENDEPIN3_MASK | - NRF_USBD_INT_ENDEPIN4_MASK | - NRF_USBD_INT_ENDEPIN5_MASK | - NRF_USBD_INT_ENDEPIN6_MASK | - NRF_USBD_INT_ENDEPIN7_MASK | - NRF_USBD_INT_ENDISOIN0_MASK | - NRF_USBD_INT_ENDEPOUT1_MASK | - NRF_USBD_INT_ENDEPOUT2_MASK | - NRF_USBD_INT_ENDEPOUT3_MASK | - NRF_USBD_INT_ENDEPOUT4_MASK | - NRF_USBD_INT_ENDEPOUT5_MASK | - NRF_USBD_INT_ENDEPOUT6_MASK | - NRF_USBD_INT_ENDEPOUT7_MASK | - NRF_USBD_INT_ENDISOOUT0_MASK - ); - nrf_usbd_int_enable(NRF_USBD_INT_ENDEPIN0_MASK | NRF_USBD_INT_ENDEPOUT0_MASK); - nrf_usbd_ep_all_disable(); -} - -nrfx_err_t nrfx_usbd_ep_transfer( - nrfx_usbd_ep_t ep, - nrfx_usbd_transfer_t const * p_transfer) -{ - nrfx_err_t ret; - const uint8_t ep_bitpos = ep2bit(ep); - NRFX_ASSERT(NULL != p_transfer); - - 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"); - } - } - else if ((m_ep_dma_waiting | ((~m_ep_ready) & NRFX_USBD_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"); - } - } - else - { - usbd_ep_state_t * p_state = ep_state_access(ep); - /* Prepare transfer context and handler description */ - nrfx_usbd_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); - } - } - 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); - } - } - } - 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); - } - } - 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); - } - } - } - } - else - { - p_context = m_ep_consumer_state + NRF_USBD_EP_NR_GET(ep); - NRFX_ASSERT((p_transfer->p_data.rx == NULL) || (nrfx_is_in_ram(p_transfer->p_data.rx))); - p_state->handler.consumer = nrfx_usbd_consumer; - } - *p_context = *p_transfer; - p_state->p_context = p_context; - - p_state->transfer_cnt = 0; - p_state->status = NRFX_USBD_EP_OK; - m_ep_dma_waiting |= 1U << ep_bitpos; - ret = NRFX_SUCCESS; - usbd_int_rise(); - } - NRFX_CRITICAL_SECTION_EXIT(); - 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 ret; - const uint8_t ep_bitpos = ep2bit(ep); - NRFX_ASSERT(NULL != p_handler); - - 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"); - } - } - else if ((m_ep_dma_waiting | ((~m_ep_ready) & NRFX_USBD_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"); - } - } - else - { - /* Transfer can be configured now */ - usbd_ep_state_t * p_state = ep_state_access(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; - 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); - } - usbd_int_rise(); - } - NRFX_CRITICAL_SECTION_EXIT(); - return ret; -} - -void * nrfx_usbd_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) -{ - nrfx_usbd_ep_status_t ret; - - usbd_ep_state_t const * p_state = ep_state_access(ep); - 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(); - return ret; -} - -size_t nrfx_usbd_epout_size_get(nrfx_usbd_ep_t ep) -{ - return nrf_usbd_epout_size_get(ep_to_hal(ep)); -} - -bool nrfx_usbd_ep_is_busy(nrfx_usbd_ep_t ep) -{ - return (0 != ((m_ep_dma_waiting | ((~m_ep_ready) & NRFX_USBD_EPIN_BIT_MASK)) & (1U << ep2bit(ep)))); -} - -void nrfx_usbd_ep_stall(nrfx_usbd_ep_t ep) -{ - NRFX_LOG_DEBUG("USB: EP %x stalled.", ep); - nrf_usbd_ep_stall(ep_to_hal(ep)); -} - -void nrfx_usbd_ep_stall_clear(nrfx_usbd_ep_t ep) -{ - if (NRF_USBD_EPOUT_CHECK(ep) && nrfx_usbd_ep_stall_check(ep)) - { - nrfx_usbd_transfer_out_drop(ep); - } - nrf_usbd_ep_unstall(ep_to_hal(ep)); -} - -bool nrfx_usbd_ep_stall_check(nrfx_usbd_ep_t ep) -{ - return nrf_usbd_ep_is_stall(ep_to_hal(ep)); -} - -void nrfx_usbd_ep_dtoggle_clear(nrfx_usbd_ep_t ep) -{ - nrf_usbd_dtoggle_set(ep, NRF_USBD_DTOGGLE_DATA0); -} - -void nrfx_usbd_setup_get(nrfx_usbd_setup_t * p_setup) -{ - memset(p_setup, 0, sizeof(nrfx_usbd_setup_t)); - p_setup->bmRequestType = nrf_usbd_setup_bmrequesttype_get(); - p_setup->bRequest = nrf_usbd_setup_brequest_get(); - p_setup->wValue = nrf_usbd_setup_wvalue_get(); - p_setup->wIndex = nrf_usbd_setup_windex_get(); - p_setup->wLength = nrf_usbd_setup_wlength_get(); -} - -void nrfx_usbd_setup_data_clear(void) -{ - nrf_usbd_task_trigger(NRF_USBD_TASK_EP0RCVOUT); -} - -void nrfx_usbd_setup_clear(void) -{ - NRFX_LOG_DEBUG(">> ep0status >>"); - nrf_usbd_task_trigger(NRF_USBD_TASK_EP0STATUS); -} - -void nrfx_usbd_setup_stall(void) -{ - NRFX_LOG_DEBUG("Setup stalled."); - nrf_usbd_task_trigger(NRF_USBD_TASK_EP0STALL); -} - -nrfx_usbd_ep_t nrfx_usbd_last_setup_dir_get(void) -{ - return m_last_setup_dir; -} - -void nrfx_usbd_transfer_out_drop(nrfx_usbd_ep_t ep) -{ - NRFX_ASSERT(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(ep); - } - NRFX_CRITICAL_SECTION_EXIT(); -} - -#endif // NRFX_CHECK(NRFX_USBD_ENABLED) diff --git a/modules/nrfx/drivers/src/nrfx_usbd_errata.h b/modules/nrfx/drivers/src/nrfx_usbd_errata.h deleted file mode 100644 index 18bbde3..0000000 --- a/modules/nrfx/drivers/src/nrfx_usbd_errata.h +++ /dev/null @@ -1,93 +0,0 @@ -/** - * Copyright (c) 2016 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#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/modules/nrfx/hal/nrf_adc.h b/modules/nrfx/hal/nrf_adc.h deleted file mode 100644 index 54e8808..0000000 --- a/modules/nrfx/hal/nrf_adc.h +++ /dev/null @@ -1,336 +0,0 @@ -/** - * Copyright (c) 2014 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_ADC_H_ -#define NRF_ADC_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_adc_hal ADC HAL - * @{ - * @ingroup nrf_adc - * @brief Hardware access layer for managing the Analog-to-Digital Converter (ADC) - * peripheral. - */ - -/** @brief ADC interrupts. */ -typedef enum -{ - NRF_ADC_INT_END_MASK = ADC_INTENSET_END_Msk, /**< ADC interrupt on END event. */ -} nrf_adc_int_mask_t; - -/** @brief Resolution of the analog-to-digital converter. */ -typedef enum -{ - NRF_ADC_CONFIG_RES_8BIT = ADC_CONFIG_RES_8bit, /**< 8-bit resolution. */ - NRF_ADC_CONFIG_RES_9BIT = ADC_CONFIG_RES_9bit, /**< 9-bit resolution. */ - NRF_ADC_CONFIG_RES_10BIT = ADC_CONFIG_RES_10bit, /**< 10-bit resolution. */ -} nrf_adc_config_resolution_t; - - -/** @brief Scaling factor of the analog-to-digital conversion. */ -typedef enum -{ - NRF_ADC_CONFIG_SCALING_INPUT_FULL_SCALE = ADC_CONFIG_INPSEL_AnalogInputNoPrescaling, /**< Full scale input. */ - NRF_ADC_CONFIG_SCALING_INPUT_TWO_THIRDS = ADC_CONFIG_INPSEL_AnalogInputTwoThirdsPrescaling, /**< 2/3 scale input. */ - NRF_ADC_CONFIG_SCALING_INPUT_ONE_THIRD = ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling, /**< 1/3 scale input. */ - NRF_ADC_CONFIG_SCALING_SUPPLY_TWO_THIRDS = ADC_CONFIG_INPSEL_SupplyTwoThirdsPrescaling, /**< 2/3 of supply. */ - NRF_ADC_CONFIG_SCALING_SUPPLY_ONE_THIRD = ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling /**< 1/3 of supply. */ -} nrf_adc_config_scaling_t; - - -/** @brief External reference selection of the analog-to-digital converter. */ -typedef enum -{ - NRF_ADC_CONFIG_EXTREFSEL_NONE = ADC_CONFIG_EXTREFSEL_None, /**< Analog reference inputs disabled. */ - NRF_ADC_CONFIG_EXTREFSEL_AREF0 = ADC_CONFIG_EXTREFSEL_AnalogReference0, /**< AREF0 as analog reference. */ - NRF_ADC_CONFIG_EXTREFSEL_AREF1 = ADC_CONFIG_EXTREFSEL_AnalogReference1 /**< AREF1 as analog reference. */ -} nrf_adc_config_extref_t; - -/** @brief Reference selection of the analog-to-digital converter. */ -typedef enum -{ - NRF_ADC_CONFIG_REF_VBG = ADC_CONFIG_REFSEL_VBG, /**< 1.2 V reference. */ - NRF_ADC_CONFIG_REF_SUPPLY_ONE_HALF = ADC_CONFIG_REFSEL_SupplyOneHalfPrescaling, /**< 1/2 of power supply. */ - NRF_ADC_CONFIG_REF_SUPPLY_ONE_THIRD = ADC_CONFIG_REFSEL_SupplyOneThirdPrescaling, /**< 1/3 of power supply. */ - NRF_ADC_CONFIG_REF_EXT = ADC_CONFIG_REFSEL_External /**< External reference. See @ref nrf_adc_config_extref_t for further configuration. */ -} nrf_adc_config_reference_t; - -/** @brief Input selection of the analog-to-digital converter. */ -typedef enum -{ - NRF_ADC_CONFIG_INPUT_DISABLED = ADC_CONFIG_PSEL_Disabled, /**< No input selected. */ - NRF_ADC_CONFIG_INPUT_0 = ADC_CONFIG_PSEL_AnalogInput0, /**< Input 0. */ - NRF_ADC_CONFIG_INPUT_1 = ADC_CONFIG_PSEL_AnalogInput1, /**< Input 1. */ - NRF_ADC_CONFIG_INPUT_2 = ADC_CONFIG_PSEL_AnalogInput2, /**< Input 2. */ - NRF_ADC_CONFIG_INPUT_3 = ADC_CONFIG_PSEL_AnalogInput3, /**< Input 3. */ - NRF_ADC_CONFIG_INPUT_4 = ADC_CONFIG_PSEL_AnalogInput4, /**< Input 4. */ - NRF_ADC_CONFIG_INPUT_5 = ADC_CONFIG_PSEL_AnalogInput5, /**< Input 5. */ - NRF_ADC_CONFIG_INPUT_6 = ADC_CONFIG_PSEL_AnalogInput6, /**< Input 6. */ - NRF_ADC_CONFIG_INPUT_7 = ADC_CONFIG_PSEL_AnalogInput7, /**< Input 7. */ -} nrf_adc_config_input_t; - -/** @brief Analog-to-digital converter tasks. */ -typedef enum -{ - NRF_ADC_TASK_START = offsetof(NRF_ADC_Type, TASKS_START), /**< ADC start sampling task. */ - NRF_ADC_TASK_STOP = offsetof(NRF_ADC_Type, TASKS_STOP) /**< ADC stop sampling task. */ -} nrf_adc_task_t; - -/** @brief Analog-to-digital converter events. */ -typedef enum -{ - NRF_ADC_EVENT_END = offsetof(NRF_ADC_Type, EVENTS_END) /**< End of a conversion event. */ -} nrf_adc_event_t; - -/** @brief Analog-to-digital converter configuration. */ -typedef struct -{ - nrf_adc_config_resolution_t resolution; /**< ADC resolution. */ - nrf_adc_config_scaling_t scaling; /**< ADC scaling factor. */ - nrf_adc_config_reference_t reference; /**< ADC reference. */ - nrf_adc_config_input_t input; /**< ADC input selection. */ - nrf_adc_config_extref_t extref; /**< ADC external reference selection. */ -} nrf_adc_config_t; - -/** @brief Analog-to-digital value type. */ -typedef uint16_t nrf_adc_value_t; - - -/** - * @brief Function for activating the specified ADC task. - * - * @param[in] task Task to be activated. - */ -__STATIC_INLINE void nrf_adc_task_trigger(nrf_adc_task_t task); - -/** - * @brief Function for getting the address of an ADC task register. - * - * @param[in] task ADC task. - * - * @return Address of the specified ADC task. - */ -__STATIC_INLINE uint32_t nrf_adc_task_address_get(nrf_adc_task_t task); - -/** - * @brief Function for retrieving the state of an ADC event. - * - * @param[in] event Event to be checked. - * - * @retval true The event has been generated. - * @retval false The event has not been generated. - */ -__STATIC_INLINE bool nrf_adc_event_check(nrf_adc_event_t event); - -/** - * @brief Function for clearing an ADC event. - * - * @param[in] event Event to clear. - */ -__STATIC_INLINE void nrf_adc_event_clear(nrf_adc_event_t event); - -/** - * @brief Function for getting the address of the specified ADC event register. - * - * @param[in] adc_event ADC event. - * - * @return Address of the specified ADC event. - */ -__STATIC_INLINE uint32_t nrf_adc_event_address_get(nrf_adc_event_t adc_event); - -/** - * @brief Function for enabling the specified interrupts. - * - * @param[in] mask Mask of interrupts to be enabled. - */ -__STATIC_INLINE void nrf_adc_int_enable(uint32_t mask); - -/** - * @brief Function for disabling the specified interrupts. - * - * @param[in] mask Mask of interrupts to be disabled. - */ -__STATIC_INLINE void nrf_adc_int_disable(uint32_t mask); - -/** - * @brief Function for retrieving the state of the specified ADC interrupts. - * - * @param[in] mask Mask of interrupts to be checked. - * - * @retval true All specified interrupts are enabled. - * @retval false At least one of the given interrupts is not enabled. - */ -__STATIC_INLINE bool nrf_adc_int_enable_check(uint32_t mask); - -/** - * @brief Function for checking whether the ADC is busy. - * - * This function checks whether the ADC converter is busy with a conversion. - * - * @retval true The ADC is busy. - * @retval false The ADC is not busy. - */ -__STATIC_INLINE bool nrf_adc_busy_check(void); - -/** @brief Function for enabling the ADC. */ -__STATIC_INLINE void nrf_adc_enable(void); - -/** @brief Function for disabling the ADC. */ -__STATIC_INLINE void nrf_adc_disable(void); - -/** - * @brief Function for checking if the ADC is enabled. - * - * @retval true The ADC is enabled. - * @retval false The ADC is not enabled. - */ -__STATIC_INLINE bool nrf_adc_enable_check(void); - -/** - * @brief Function for retrieving the ADC conversion result. - * - * This function retrieves and returns the last analog-to-digital conversion result. - * - * @return Last conversion result. - */ -__STATIC_INLINE nrf_adc_value_t nrf_adc_result_get(void); - -/** - * @brief Function for initializing the ADC. - * - * This function writes data to ADC's CONFIG register. After the configuration, - * the ADC is in DISABLE state and must be enabled before using it. - * - * @param[in] p_config Configuration parameters. - */ -__STATIC_INLINE void nrf_adc_init(nrf_adc_config_t const * p_config); - - -#ifndef SUPPRESS_INLINE_IMPLEMENTATION - -__STATIC_INLINE void nrf_adc_task_trigger(nrf_adc_task_t task) -{ - *((volatile uint32_t *)((uint8_t *)NRF_ADC + (uint32_t)task)) = 0x1UL; -} - -__STATIC_INLINE uint32_t nrf_adc_task_address_get(nrf_adc_task_t adc_task) -{ - return (uint32_t)((uint8_t *)NRF_ADC + (uint32_t)adc_task); -} - -__STATIC_INLINE bool nrf_adc_event_check(nrf_adc_event_t event) -{ - return (bool)*(volatile uint32_t *)((uint8_t *)NRF_ADC + (uint32_t)event); -} - -__STATIC_INLINE void nrf_adc_event_clear(nrf_adc_event_t event) -{ - *((volatile uint32_t *)((uint8_t *)NRF_ADC + (uint32_t)event)) = 0x0UL; -} - -__STATIC_INLINE uint32_t nrf_adc_event_address_get(nrf_adc_event_t adc_event) -{ - return (uint32_t)((uint8_t *)NRF_ADC + (uint32_t)adc_event); -} - -__STATIC_INLINE void nrf_adc_int_enable(uint32_t mask) -{ - NRF_ADC->INTENSET = mask; -} - -__STATIC_INLINE void nrf_adc_int_disable(uint32_t mask) -{ - NRF_ADC->INTENCLR = mask; -} - -__STATIC_INLINE bool nrf_adc_int_enable_check(uint32_t mask) -{ - return (bool)(NRF_ADC->INTENSET & mask); -} - -__STATIC_INLINE bool nrf_adc_busy_check(void) -{ - return ((NRF_ADC->BUSY & ADC_BUSY_BUSY_Msk) == (ADC_BUSY_BUSY_Busy << ADC_BUSY_BUSY_Pos)); -} - -__STATIC_INLINE void nrf_adc_enable(void) -{ - NRF_ADC->ENABLE = (ADC_ENABLE_ENABLE_Enabled << ADC_ENABLE_ENABLE_Pos); -} - -__STATIC_INLINE void nrf_adc_disable(void) -{ - NRF_ADC->ENABLE = (ADC_ENABLE_ENABLE_Disabled << ADC_ENABLE_ENABLE_Pos); -} - -__STATIC_INLINE bool nrf_adc_enable_check(void) -{ - return (NRF_ADC->ENABLE == (ADC_ENABLE_ENABLE_Enabled << ADC_ENABLE_ENABLE_Pos)); -} - -__STATIC_INLINE nrf_adc_value_t nrf_adc_result_get(void) -{ - return (nrf_adc_value_t)NRF_ADC->RESULT; -} - -__STATIC_INLINE void nrf_adc_init(nrf_adc_config_t const * p_config) -{ - NRF_ADC->CONFIG = - ((p_config->resolution << ADC_CONFIG_RES_Pos) & ADC_CONFIG_RES_Msk) - |((p_config->scaling << ADC_CONFIG_INPSEL_Pos) & ADC_CONFIG_INPSEL_Msk) - |((p_config->reference << ADC_CONFIG_REFSEL_Pos) & ADC_CONFIG_REFSEL_Msk) - |((p_config->input << ADC_CONFIG_PSEL_Pos) & ADC_CONFIG_PSEL_Msk) - |((p_config->extref << ADC_CONFIG_EXTREFSEL_Pos) & ADC_CONFIG_EXTREFSEL_Msk); -} - -#endif // SUPPRESS_INLINE_IMPLEMENTATION -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif /* NRF_ADC_H_ */ diff --git a/modules/nrfx/hal/nrf_comp.h b/modules/nrfx/hal/nrf_comp.h deleted file mode 100644 index 4591fb5..0000000 --- a/modules/nrfx/hal/nrf_comp.h +++ /dev/null @@ -1,474 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_COMP_H_ -#define NRF_COMP_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_comp_hal COMP HAL - * @{ - * @ingroup nrf_comp - * @brief Hardware access layer (HAL) for managing the Comparator (COMP) peripheral. - */ - -/** @brief COMP analog pin selection. */ -typedef enum -{ - NRF_COMP_INPUT_0 = COMP_PSEL_PSEL_AnalogInput0, /*!< AIN0 selected as analog input. */ - NRF_COMP_INPUT_1 = COMP_PSEL_PSEL_AnalogInput1, /*!< AIN1 selected as analog input. */ - NRF_COMP_INPUT_2 = COMP_PSEL_PSEL_AnalogInput2, /*!< AIN2 selected as analog input. */ - NRF_COMP_INPUT_3 = COMP_PSEL_PSEL_AnalogInput3, /*!< AIN3 selected as analog input. */ -#if defined (COMP_PSEL_PSEL_AnalogInput4) || defined (__NRFX_DOXYGEN__) - NRF_COMP_INPUT_4 = COMP_PSEL_PSEL_AnalogInput4, /*!< AIN4 selected as analog input. */ -#endif -#if defined (COMP_PSEL_PSEL_AnalogInput5) || defined (__NRFX_DOXYGEN__) - NRF_COMP_INPUT_5 = COMP_PSEL_PSEL_AnalogInput5, /*!< AIN5 selected as analog input. */ -#endif -#if defined (COMP_PSEL_PSEL_AnalogInput6) || defined (__NRFX_DOXYGEN__) - NRF_COMP_INPUT_6 = COMP_PSEL_PSEL_AnalogInput6, /*!< AIN6 selected as analog input. */ -#endif -#if defined (COMP_PSEL_PSEL_AnalogInput7) || defined (__NRFX_DOXYGEN__) - NRF_COMP_INPUT_7 = COMP_PSEL_PSEL_AnalogInput7, /*!< AIN7 selected as analog input. */ -#endif -#if defined (COMP_PSEL_PSEL_VddDiv2) || defined (__NRFX_DOXYGEN__) - NRF_COMP_VDD_DIV2 = COMP_PSEL_PSEL_VddDiv2, /*!< VDD/2 selected as analog input. */ -#endif -#if defined (COMP_PSEL_PSEL_VddhDiv5) || defined (__NRFX_DOXYGEN__) - NRF_COMP_VDDH_DIV5 = COMP_PSEL_PSEL_VddhDiv5, /*!< VDDH/5 selected as analog input. */ -#endif -} nrf_comp_input_t; - -/** @brief COMP reference selection. */ -typedef enum -{ - NRF_COMP_REF_Int1V2 = COMP_REFSEL_REFSEL_Int1V2, /*!< VREF = internal 1.2 V reference (VDD >= 1.7 V). */ - NRF_COMP_REF_Int1V8 = COMP_REFSEL_REFSEL_Int1V8, /*!< VREF = internal 1.8 V reference (VDD >= VREF + 0.2 V). */ - NRF_COMP_REF_Int2V4 = COMP_REFSEL_REFSEL_Int2V4, /*!< VREF = internal 2.4 V reference (VDD >= VREF + 0.2 V). */ - NRF_COMP_REF_VDD = COMP_REFSEL_REFSEL_VDD, /*!< VREF = VDD. */ - NRF_COMP_REF_ARef = COMP_REFSEL_REFSEL_ARef /*!< VREF = AREF (VDD >= VREF >= AREFMIN). */ -} nrf_comp_ref_t; - -/** @brief COMP external analog reference selection. */ -typedef enum -{ - NRF_COMP_EXT_REF_0 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference0, /*!< Use AIN0 as external analog reference. */ - NRF_COMP_EXT_REF_1 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference1, /*!< Use AIN1 as external analog reference. */ - NRF_COMP_EXT_REF_2 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference2, /*!< Use AIN2 as external analog reference. */ - NRF_COMP_EXT_REF_3 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference3, /*!< Use AIN3 as external analog reference. */ -#if defined (COMP_EXTREFSEL_EXTREFSEL_AnalogReference4) || defined (__NRFX_DOXYGEN__) - NRF_COMP_EXT_REF_4 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference4, /*!< Use AIN4 as external analog reference. */ -#endif -#if defined (COMP_EXTREFSEL_EXTREFSEL_AnalogReference5) || defined (__NRFX_DOXYGEN__) - NRF_COMP_EXT_REF_5 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference5, /*!< Use AIN5 as external analog reference. */ -#endif -#if defined (COMP_EXTREFSEL_EXTREFSEL_AnalogReference6) || defined (__NRFX_DOXYGEN__) - NRF_COMP_EXT_REF_6 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference6, /*!< Use AIN6 as external analog reference. */ -#endif -#if defined (COMP_EXTREFSEL_EXTREFSEL_AnalogReference7) || defined (__NRFX_DOXYGEN__) - NRF_COMP_EXT_REF_7 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference7 /*!< Use AIN7 as external analog reference. */ -#endif -} nrf_comp_ext_ref_t; - -/** @brief COMP THDOWN and THUP values that are used to calculate the threshold voltages VDOWN and VUP. */ -typedef struct -{ - uint8_t th_down; /*!< THDOWN value. */ - uint8_t th_up; /*!< THUP value. */ -} nrf_comp_th_t; - -/** @brief COMP main operation mode. */ -typedef enum -{ - NRF_COMP_MAIN_MODE_SE = COMP_MODE_MAIN_SE, /*!< Single-ended mode. */ - NRF_COMP_MAIN_MODE_Diff = COMP_MODE_MAIN_Diff /*!< Differential mode. */ -} nrf_comp_main_mode_t; - -/** @brief COMP speed and power mode. */ -typedef enum -{ - NRF_COMP_SP_MODE_Low = COMP_MODE_SP_Low, /*!< Low power mode. */ - NRF_COMP_SP_MODE_Normal = COMP_MODE_SP_Normal, /*!< Normal mode. */ - NRF_COMP_SP_MODE_High = COMP_MODE_SP_High /*!< High-speed mode. */ -} nrf_comp_sp_mode_t; - -/** @brief COMP comparator hysteresis. */ -typedef enum -{ - NRF_COMP_HYST_NoHyst = COMP_HYST_HYST_NoHyst, /*!< Comparator hysteresis disabled. */ - NRF_COMP_HYST_50mV = COMP_HYST_HYST_Hyst50mV /*!< Comparator hysteresis enabled. */ -} nrf_comp_hyst_t; - -#if defined (COMP_ISOURCE_ISOURCE_Msk) || defined (__NRFX_DOXYGEN__) -/** @brief COMP current source selection on analog input. */ -typedef enum -{ - NRF_COMP_ISOURCE_Off = COMP_ISOURCE_ISOURCE_Off, /*!< Current source disabled. */ - NRF_COMP_ISOURCE_Ien2uA5 = COMP_ISOURCE_ISOURCE_Ien2mA5, /*!< Current source enabled (+/- 2.5 uA). */ - NRF_COMP_ISOURCE_Ien5uA = COMP_ISOURCE_ISOURCE_Ien5mA, /*!< Current source enabled (+/- 5 uA). */ - NRF_COMP_ISOURCE_Ien10uA = COMP_ISOURCE_ISOURCE_Ien10mA /*!< Current source enabled (+/- 10 uA). */ -} nrf_isource_t; -#endif - -/** @brief COMP tasks. */ -typedef enum -{ - NRF_COMP_TASK_START = offsetof(NRF_COMP_Type, TASKS_START), /*!< COMP start sampling task. */ - NRF_COMP_TASK_STOP = offsetof(NRF_COMP_Type, TASKS_STOP), /*!< COMP stop sampling task. */ - NRF_COMP_TASK_SAMPLE = offsetof(NRF_COMP_Type, TASKS_SAMPLE) /*!< Sample comparator value. */ -} nrf_comp_task_t; - -/** @brief COMP events. */ -typedef enum -{ - NRF_COMP_EVENT_READY = offsetof(NRF_COMP_Type, EVENTS_READY), /*!< COMP is ready and output is valid. */ - NRF_COMP_EVENT_DOWN = offsetof(NRF_COMP_Type, EVENTS_DOWN), /*!< Input voltage crossed the threshold going down. */ - NRF_COMP_EVENT_UP = offsetof(NRF_COMP_Type, EVENTS_UP), /*!< Input voltage crossed the threshold going up. */ - NRF_COMP_EVENT_CROSS = offsetof(NRF_COMP_Type, EVENTS_CROSS) /*!< Input voltage crossed the threshold in any direction. */ -} nrf_comp_event_t; - -/** @brief COMP reference configuration. */ -typedef struct -{ - nrf_comp_ref_t reference; /*!< COMP reference selection. */ - nrf_comp_ext_ref_t external; /*!< COMP external analog reference selection. */ -} nrf_comp_ref_conf_t; - - -/** @brief Function for enabling the COMP peripheral. */ -__STATIC_INLINE void nrf_comp_enable(void); - -/** @brief Function for disabling the COMP peripheral. */ -__STATIC_INLINE void nrf_comp_disable(void); - -/** - * @brief Function for checking if the COMP peripheral is enabled. - * - * @retval true The COMP peripheral is enabled. - * @retval false The COMP peripheral is not enabled. - */ -__STATIC_INLINE bool nrf_comp_enable_check(void); - -/** - * @brief Function for setting the reference source. - * - * @param[in] reference COMP reference selection. - */ -__STATIC_INLINE void nrf_comp_ref_set(nrf_comp_ref_t reference); - -/** - * @brief Function for setting the external analog reference source. - * - * @param[in] ext_ref COMP external analog reference selection. - */ -__STATIC_INLINE void nrf_comp_ext_ref_set(nrf_comp_ext_ref_t ext_ref); - -/** - * @brief Function for setting threshold voltages. - * - * @param[in] threshold COMP VDOWN and VUP thresholds. - */ -__STATIC_INLINE void nrf_comp_th_set(nrf_comp_th_t threshold); - -/** - * @brief Function for setting the main mode. - * - * @param[in] main_mode COMP main operation mode. - */ -__STATIC_INLINE void nrf_comp_main_mode_set(nrf_comp_main_mode_t main_mode); - -/** - * @brief Function for setting the speed mode. - * - * @param[in] speed_mode COMP speed and power mode. - */ -__STATIC_INLINE void nrf_comp_speed_mode_set(nrf_comp_sp_mode_t speed_mode); - -/** - * @brief Function for setting the hysteresis. - * - * @param[in] hyst COMP comparator hysteresis. - */ -__STATIC_INLINE void nrf_comp_hysteresis_set(nrf_comp_hyst_t hyst); - -#if defined (COMP_ISOURCE_ISOURCE_Msk) || defined (__NRFX_DOXYGEN__) -/** - * @brief Function for setting the current source on the analog input. - * - * @param[in] isource COMP current source selection on analog input. - */ -__STATIC_INLINE void nrf_comp_isource_set(nrf_isource_t isource); -#endif - -/** - * @brief Function for selecting the active input of the COMP. - * - * @param[in] input Input to be selected. - */ -__STATIC_INLINE void nrf_comp_input_select(nrf_comp_input_t input); - -/** - * @brief Function for getting the last COMP compare result. - * - * @note If VIN+ == VIN-, the return value depends on the previous result. - * - * @return The last compare result. If 0, then VIN+ < VIN-. If 1, then VIN+ > VIN-. - */ -__STATIC_INLINE uint32_t nrf_comp_result_get(void); - -/** - * @brief Function for enabling interrupts from COMP. - * - * @param[in] mask Mask of interrupts to be enabled. - * - * @sa nrf_comp_int_enable_check - */ -__STATIC_INLINE void nrf_comp_int_enable(uint32_t mask); - -/** - * @brief Function for disabling interrupts from COMP. - * - * @param[in] mask Mask of interrupts to be disabled. - * - * @sa nrf_comp_int_enable_check - */ -__STATIC_INLINE void nrf_comp_int_disable(uint32_t mask); - -/** - * @brief Function for getting the enabled interrupts of COMP. - * - * @param[in] mask Mask of interrupts to be checked. - * - * @retval true At least one interrupt from the specified mask is enabled. - * @retval false No interrupt provided by the specified mask are enabled. - */ -__STATIC_INLINE bool nrf_comp_int_enable_check(uint32_t mask); - -/** - * @brief Function for getting the address of the specified COMP task register. - * - * @param[in] task COMP task. - * - * @return Address of the specified COMP task. - */ -__STATIC_INLINE uint32_t * nrf_comp_task_address_get(nrf_comp_task_t task); - -/** - * @brief Function for getting the address of the specified COMP event register. - * - * @param[in] event COMP event. - * - * @return Address of the specified COMP event. - */ -__STATIC_INLINE uint32_t * nrf_comp_event_address_get(nrf_comp_event_t event); - -/** - * @brief Function for setting COMP shortcuts. - * - * @param[in] mask Mask of shortcuts. - */ -__STATIC_INLINE void nrf_comp_shorts_enable(uint32_t mask); - -/** - * @brief Function for clearing COMP shortcuts by mask. - * - * @param[in] mask Mask of shortcuts. - */ -__STATIC_INLINE void nrf_comp_shorts_disable(uint32_t mask); - -/** - * @brief Function for setting the specified COMP task. - * - * @param[in] task Task to be activated. - */ -__STATIC_INLINE void nrf_comp_task_trigger(nrf_comp_task_t task); - -/** - * @brief Function for clearing the specified COMP event. - * - * @param[in] event COMP event to be cleared. - */ -__STATIC_INLINE void nrf_comp_event_clear(nrf_comp_event_t event); - -/** - * @brief Function for retrieving the state of the UARTE event. - * - * @param[in] event Event to be checked. - * - * @retval true The event has been generated. - * @retval false The event has not been generated. - */ -__STATIC_INLINE bool nrf_comp_event_check(nrf_comp_event_t event); - - -#ifndef SUPPRESS_INLINE_IMPLEMENTATION - -__STATIC_INLINE void nrf_comp_enable(void) -{ - NRF_COMP->ENABLE = (COMP_ENABLE_ENABLE_Enabled << COMP_ENABLE_ENABLE_Pos); -} - -__STATIC_INLINE void nrf_comp_disable(void) -{ - NRF_COMP->ENABLE = (COMP_ENABLE_ENABLE_Disabled << COMP_ENABLE_ENABLE_Pos); -} - -__STATIC_INLINE bool nrf_comp_enable_check(void) -{ - return ((NRF_COMP->ENABLE) & COMP_ENABLE_ENABLE_Enabled); -} - -__STATIC_INLINE void nrf_comp_ref_set(nrf_comp_ref_t reference) -{ - NRF_COMP->REFSEL = (reference << COMP_REFSEL_REFSEL_Pos); -} - -__STATIC_INLINE void nrf_comp_ext_ref_set(nrf_comp_ext_ref_t ext_ref) -{ - NRF_COMP->EXTREFSEL = (ext_ref << COMP_EXTREFSEL_EXTREFSEL_Pos); -} - -__STATIC_INLINE void nrf_comp_th_set(nrf_comp_th_t threshold) -{ - NRF_COMP->TH = - (((uint32_t)threshold.th_down << COMP_TH_THDOWN_Pos) & COMP_TH_THDOWN_Msk) | - (((uint32_t)threshold.th_up << COMP_TH_THUP_Pos) & COMP_TH_THUP_Msk); -} - -__STATIC_INLINE void nrf_comp_main_mode_set(nrf_comp_main_mode_t main_mode) -{ - NRF_COMP->MODE |= (main_mode << COMP_MODE_MAIN_Pos); -} - -__STATIC_INLINE void nrf_comp_speed_mode_set(nrf_comp_sp_mode_t speed_mode) -{ - NRF_COMP->MODE |= (speed_mode << COMP_MODE_SP_Pos); -} - -__STATIC_INLINE void nrf_comp_hysteresis_set(nrf_comp_hyst_t hyst) -{ - NRF_COMP->HYST = (hyst << COMP_HYST_HYST_Pos) & COMP_HYST_HYST_Msk; -} - -#if defined (COMP_ISOURCE_ISOURCE_Msk) -__STATIC_INLINE void nrf_comp_isource_set(nrf_isource_t isource) -{ - NRF_COMP->ISOURCE = (isource << COMP_ISOURCE_ISOURCE_Pos) & COMP_ISOURCE_ISOURCE_Msk; -} -#endif - -__STATIC_INLINE void nrf_comp_input_select(nrf_comp_input_t input) -{ - NRF_COMP->PSEL = ((uint32_t)input << COMP_PSEL_PSEL_Pos); -} - -__STATIC_INLINE uint32_t nrf_comp_result_get(void) -{ - return (uint32_t)NRF_COMP->RESULT; -} - -__STATIC_INLINE void nrf_comp_int_enable(uint32_t mask) -{ - NRF_COMP->INTENSET = mask; -} - -__STATIC_INLINE void nrf_comp_int_disable(uint32_t mask) -{ - NRF_COMP->INTENCLR = mask; -} - -__STATIC_INLINE bool nrf_comp_int_enable_check(uint32_t mask) -{ - return (NRF_COMP->INTENSET & mask); // When read, this register returns the value of INTEN. -} - -__STATIC_INLINE uint32_t * nrf_comp_task_address_get(nrf_comp_task_t task) -{ - return (uint32_t *)((uint8_t *)NRF_COMP + (uint32_t)task); -} - -__STATIC_INLINE uint32_t * nrf_comp_event_address_get(nrf_comp_event_t event) -{ - return (uint32_t *)((uint8_t *)NRF_COMP + (uint32_t)event); -} - -__STATIC_INLINE void nrf_comp_shorts_enable(uint32_t mask) -{ - NRF_COMP->SHORTS |= mask; -} - -__STATIC_INLINE void nrf_comp_shorts_disable(uint32_t mask) -{ - NRF_COMP->SHORTS &= ~mask; -} - -__STATIC_INLINE void nrf_comp_task_trigger(nrf_comp_task_t task) -{ - *( (volatile uint32_t *)( (uint8_t *)NRF_COMP + (uint32_t)task) ) = 1; -} - -__STATIC_INLINE void nrf_comp_event_clear(nrf_comp_event_t event) -{ - *( (volatile uint32_t *)( (uint8_t *)NRF_COMP + (uint32_t)event) ) = 0; -#if __CORTEX_M == 0x04 - volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_COMP + (uint32_t)event)); - (void)dummy; -#endif -} - -__STATIC_INLINE bool nrf_comp_event_check(nrf_comp_event_t event) -{ - return (bool) (*(volatile uint32_t *)( (uint8_t *)NRF_COMP + (uint32_t)event)); -} - -#endif // SUPPRESS_INLINE_IMPLEMENTATION - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif // NRF_COMP_H_ diff --git a/modules/nrfx/hal/nrf_dppi.h b/modules/nrfx/hal/nrf_dppi.h deleted file mode 100644 index 21f1b32..0000000 --- a/modules/nrfx/hal/nrf_dppi.h +++ /dev/null @@ -1,341 +0,0 @@ -/** - * Copyright (c) 2018 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_DPPI_H__ -#define NRF_DPPI_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_dppi_hal DPPI Controller HAL - * @{ - * @ingroup nrf_dppi - * @brief Hardware access layer for managing the Distributed Programmable Peripheral - * Interconnect Controller (DPPIC). - */ - -/** @brief DPPI channel groups. */ -typedef enum -{ - NRF_DPPI_CHANNEL_GROUP0 = 0, /**< Channel group 0. */ - NRF_DPPI_CHANNEL_GROUP1 = 1, /**< Channel group 1. */ - NRF_DPPI_CHANNEL_GROUP2 = 2, /**< Channel group 2. */ - NRF_DPPI_CHANNEL_GROUP3 = 3, /**< Channel group 3. */ - NRF_DPPI_CHANNEL_GROUP4 = 4, /**< Channel group 4. */ - NRF_DPPI_CHANNEL_GROUP5 = 5 /**< Channel group 5. */ -} nrf_dppi_channel_group_t; - -/** @brief DPPI tasks. */ -typedef enum -{ - NRF_DPPI_TASK_CHG0_EN = offsetof(NRF_DPPIC_Type, TASKS_CHG[0].EN), /**< Enable channel group 0. */ - NRF_DPPI_TASK_CHG0_DIS = offsetof(NRF_DPPIC_Type, TASKS_CHG[0].DIS), /**< Disable channel group 0. */ - NRF_DPPI_TASK_CHG1_EN = offsetof(NRF_DPPIC_Type, TASKS_CHG[1].EN), /**< Enable channel group 1. */ - NRF_DPPI_TASK_CHG1_DIS = offsetof(NRF_DPPIC_Type, TASKS_CHG[1].DIS), /**< Disable channel group 1. */ - NRF_DPPI_TASK_CHG2_EN = offsetof(NRF_DPPIC_Type, TASKS_CHG[2].EN), /**< Enable channel group 2. */ - NRF_DPPI_TASK_CHG2_DIS = offsetof(NRF_DPPIC_Type, TASKS_CHG[2].DIS), /**< Disable channel group 2. */ - NRF_DPPI_TASK_CHG3_EN = offsetof(NRF_DPPIC_Type, TASKS_CHG[3].EN), /**< Enable channel group 3. */ - NRF_DPPI_TASK_CHG3_DIS = offsetof(NRF_DPPIC_Type, TASKS_CHG[3].DIS), /**< Disable channel group 3. */ - NRF_DPPI_TASK_CHG4_EN = offsetof(NRF_DPPIC_Type, TASKS_CHG[4].EN), /**< Enable channel group 4. */ - NRF_DPPI_TASK_CHG4_DIS = offsetof(NRF_DPPIC_Type, TASKS_CHG[4].DIS), /**< Disable channel group 4. */ - NRF_DPPI_TASK_CHG5_EN = offsetof(NRF_DPPIC_Type, TASKS_CHG[5].EN), /**< Enable channel group 5. */ - NRF_DPPI_TASK_CHG5_DIS = offsetof(NRF_DPPIC_Type, TASKS_CHG[5].DIS) /**< Disable channel group 5. */ -} nrf_dppi_task_t; - -/** - * @brief Function for activating a DPPI task. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] dppi_task Task to be activated. - */ -__STATIC_INLINE void nrf_dppi_task_trigger(NRF_DPPIC_Type * p_reg, nrf_dppi_task_t dppi_task); - -/** - * @brief Function for getting the address of the specified DPPI task register. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] task Requested task. - * - * @return Address of the specified task register. - */ -__STATIC_INLINE uint32_t nrf_dppi_task_address_get(NRF_DPPIC_Type const * p_reg, - nrf_dppi_task_t task); - -/** - * @brief Function for checking the state of a specific DPPI channel. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] channel Channel to be checked. - * - * @retval true The channel is enabled. - * @retval false The channel is not enabled. - */ -__STATIC_INLINE bool nrf_dppi_channel_check(NRF_DPPIC_Type const * p_reg, uint8_t channel); - -/** - * @brief Function for enabling multiple DPPI channels. - * - * The bits in @c mask value correspond to particular channels. It means that - * writing 1 to bit 0 enables channel 0, writing 1 to bit 1 enables channel 1 etc. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] mask Channel mask. - */ -__STATIC_INLINE void nrf_dppi_channels_enable(NRF_DPPIC_Type * p_reg, uint32_t mask); - -/** - * @brief Function for disabling multiple DPPI channels. - * - * The bits in @c mask value correspond to particular channels. It means that - * writing 1 to bit 0 disables channel 0, writing 1 to bit 1 disables channel 1 etc. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] mask Channel mask. - */ -__STATIC_INLINE void nrf_dppi_channels_disable(NRF_DPPIC_Type * p_reg, uint32_t mask); - -/** - * @brief Function for disabling all DPPI channels. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - */ -__STATIC_INLINE void nrf_dppi_channels_disable_all(NRF_DPPIC_Type * p_reg); - -/** - * @brief Function for setting the subscribe configuration for a given - * DPPI task. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] task Task for which to set the configuration. - * @param[in] channel Channel through which to subscribe events. - */ -__STATIC_INLINE void nrf_dppi_subscribe_set(NRF_DPPIC_Type * p_reg, - nrf_dppi_task_t task, - uint8_t channel); - -/** - * @brief Function for clearing the subscribe configuration for a given - * DPPI task. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] task Task for which to clear the configuration. - */ -__STATIC_INLINE void nrf_dppi_subscribe_clear(NRF_DPPIC_Type * p_reg, nrf_dppi_task_t task); - -/** - * @brief Function for including multiple DPPI channels in a channel group. - * - * @details This function adds all specified channels to the group. - * The bits in @p channel_mask value correspond to particular channels. It means that - * writing 1 to bit 0 includes channel 0, writing 1 to bit 1 includes channel 1 etc. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] channel_mask Channels to be included in the group. - * @param[in] channel_group Channel group. - */ -__STATIC_INLINE void nrf_dppi_channels_include_in_group(NRF_DPPIC_Type * p_reg, - uint32_t channel_mask, - nrf_dppi_channel_group_t channel_group); - -/** - * @brief Function for removing multiple DPPI channels from a channel group. - * - * @details This function removes all specified channels from the group. - * The bits in @c channel_mask value correspond to particular channels. It means that - * writing 1 to bit 0 removes channel 0, writing 1 to bit 1 removes channel 1 etc. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] channel_mask Channels to be removed from the group. - * @param[in] channel_group Channel group. - */ -__STATIC_INLINE void nrf_dppi_channels_remove_from_group(NRF_DPPIC_Type * p_reg, - uint32_t channel_mask, - nrf_dppi_channel_group_t channel_group); - -/** - * @brief Function for removing all DPPI channels from a channel group. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] group Channel group. - */ -__STATIC_INLINE void nrf_dppi_group_clear(NRF_DPPIC_Type * p_reg, - nrf_dppi_channel_group_t group); - -/** - * @brief Function for enabling a channel group. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] group Channel group. - */ -__STATIC_INLINE void nrf_dppi_group_enable(NRF_DPPIC_Type * p_reg, - nrf_dppi_channel_group_t group); - -/** - * @brief Function for disabling a channel group. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] group Channel group. - */ -__STATIC_INLINE void nrf_dppi_group_disable(NRF_DPPIC_Type * p_reg, - nrf_dppi_channel_group_t group); - -/** - * @brief Function for getting the ENABLE task associated with the specified channel group. - * - * @param[in] index Channel group index. - * - * @return Requested ENABLE task. - */ -__STATIC_INLINE nrf_dppi_task_t nrf_dppi_group_enable_task_get(uint8_t index); - -/** - * @brief Function for getting the DISABLE task associated with the specified channel group. - * - * @param[in] index Channel group index. - * - * @return Requested DISABLE task. - */ -__STATIC_INLINE nrf_dppi_task_t nrf_dppi_group_disable_task_get(uint8_t index); - - -#ifndef SUPPRESS_INLINE_IMPLEMENTATION - -__STATIC_INLINE void nrf_dppi_task_trigger(NRF_DPPIC_Type * p_reg, nrf_dppi_task_t dppi_task) -{ - *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) dppi_task)) = 1; -} - -__STATIC_INLINE uint32_t nrf_dppi_task_address_get(NRF_DPPIC_Type const * p_reg, - nrf_dppi_task_t task) -{ - return (uint32_t) ((uint8_t *) p_reg + (uint32_t ) task); -} - -__STATIC_INLINE bool nrf_dppi_channel_check(NRF_DPPIC_Type const * p_reg, uint8_t channel) -{ - return ((p_reg->CHEN & (DPPIC_CHEN_CH0_Enabled << (DPPIC_CHEN_CH0_Pos + channel))) != 0); -} - -__STATIC_INLINE void nrf_dppi_channels_disable_all(NRF_DPPIC_Type * p_reg) -{ - p_reg->CHENCLR = 0xFFFFFFFFuL; -} - -__STATIC_INLINE void nrf_dppi_channels_enable(NRF_DPPIC_Type * p_reg, uint32_t mask) -{ - p_reg->CHENSET = mask; -} - -__STATIC_INLINE void nrf_dppi_channels_disable(NRF_DPPIC_Type * p_reg, uint32_t mask) -{ - p_reg->CHENCLR = mask; -} - -__STATIC_INLINE void nrf_dppi_subscribe_set(NRF_DPPIC_Type * p_reg, - nrf_dppi_task_t task, - uint8_t channel) -{ - *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = - ((uint32_t)channel | DPPIC_SUBSCRIBE_CHG_EN_EN_Msk); -} - -__STATIC_INLINE void nrf_dppi_subscribe_clear(NRF_DPPIC_Type * p_reg, nrf_dppi_task_t task) -{ - *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0; -} - -__STATIC_INLINE void nrf_dppi_channels_include_in_group(NRF_DPPIC_Type * p_reg, - uint32_t channel_mask, - nrf_dppi_channel_group_t channel_group) -{ - p_reg->CHG[(uint32_t) channel_group] = - p_reg->CHG[(uint32_t) channel_group] | (channel_mask); -} - -__STATIC_INLINE void nrf_dppi_channels_remove_from_group(NRF_DPPIC_Type * p_reg, - uint32_t channel_mask, - nrf_dppi_channel_group_t channel_group) -{ - p_reg->CHG[(uint32_t) channel_group] = - p_reg->CHG[(uint32_t) channel_group] & ~(channel_mask); -} - -__STATIC_INLINE void nrf_dppi_group_clear(NRF_DPPIC_Type * p_reg, - nrf_dppi_channel_group_t group) -{ - p_reg->CHG[(uint32_t) group] = 0; -} - -__STATIC_INLINE void nrf_dppi_group_enable(NRF_DPPIC_Type * p_reg, nrf_dppi_channel_group_t group) -{ - p_reg->TASKS_CHG[(uint32_t) group].EN = 1; -} - -__STATIC_INLINE void nrf_dppi_group_disable(NRF_DPPIC_Type * p_reg, - nrf_dppi_channel_group_t group) -{ - p_reg->TASKS_CHG[(uint32_t) group].DIS = 1; -} - -__STATIC_INLINE nrf_dppi_task_t nrf_dppi_group_enable_task_get(uint8_t index) -{ - NRFX_ASSERT(index < NRFX_ARRAY_SIZE(NRF_DPPIC->TASKS_CHG)); - return (nrf_dppi_task_t)NRFX_OFFSETOF(NRF_DPPIC_Type, TASKS_CHG[index].EN); -} - -__STATIC_INLINE nrf_dppi_task_t nrf_dppi_group_disable_task_get(uint8_t index) -{ - NRFX_ASSERT(index < NRFX_ARRAY_SIZE(NRF_DPPIC->TASKS_CHG)); - return (nrf_dppi_task_t)NRFX_OFFSETOF(NRF_DPPIC_Type, TASKS_CHG[index].DIS); -} - -#endif // SUPPRESS_INLINE_IMPLEMENTATION - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif // NRF_DPPIC_H__ diff --git a/modules/nrfx/hal/nrf_i2s.h b/modules/nrfx/hal/nrf_i2s.h deleted file mode 100644 index 743bfd6..0000000 --- a/modules/nrfx/hal/nrf_i2s.h +++ /dev/null @@ -1,621 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_I2S_H__ -#define NRF_I2S_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_i2s_hal I2S HAL - * @{ - * @ingroup nrf_i2s - * @brief Hardware access layer for managing the Inter-IC Sound (I2S) peripheral. - */ - -/** - * @brief This value can be provided as a parameter for the @ref nrf_i2s_pins_set - * function call to specify that the given I2S signal (SDOUT, SDIN, or MCK) - * shall not be connected to a physical pin. - */ -#define NRF_I2S_PIN_NOT_CONNECTED 0xFFFFFFFF - - -/** @brief I2S tasks. */ -typedef enum -{ - NRF_I2S_TASK_START = offsetof(NRF_I2S_Type, TASKS_START), ///< Starts continuous I2S transfer. Also starts the MCK generator if this is enabled. - NRF_I2S_TASK_STOP = offsetof(NRF_I2S_Type, TASKS_STOP) ///< Stops I2S transfer. Also stops the MCK generator. -} nrf_i2s_task_t; - -/** @brief I2S events. */ -typedef enum -{ - NRF_I2S_EVENT_RXPTRUPD = offsetof(NRF_I2S_Type, EVENTS_RXPTRUPD), ///< The RXD.PTR register has been copied to internal double buffers. - NRF_I2S_EVENT_TXPTRUPD = offsetof(NRF_I2S_Type, EVENTS_TXPTRUPD), ///< The TXD.PTR register has been copied to internal double buffers. - NRF_I2S_EVENT_STOPPED = offsetof(NRF_I2S_Type, EVENTS_STOPPED) ///< I2S transfer stopped. -} nrf_i2s_event_t; - -/** @brief I2S interrupts. */ -typedef enum -{ - NRF_I2S_INT_RXPTRUPD_MASK = I2S_INTENSET_RXPTRUPD_Msk, ///< Interrupt on RXPTRUPD event. - NRF_I2S_INT_TXPTRUPD_MASK = I2S_INTENSET_TXPTRUPD_Msk, ///< Interrupt on TXPTRUPD event. - NRF_I2S_INT_STOPPED_MASK = I2S_INTENSET_STOPPED_Msk ///< Interrupt on STOPPED event. -} nrf_i2s_int_mask_t; - -/** @brief I2S modes of operation. */ -typedef enum -{ - NRF_I2S_MODE_MASTER = I2S_CONFIG_MODE_MODE_Master, ///< Master mode. - NRF_I2S_MODE_SLAVE = I2S_CONFIG_MODE_MODE_Slave ///< Slave mode. -} nrf_i2s_mode_t; - -/** @brief I2S master clock generator settings. */ -typedef enum -{ - NRF_I2S_MCK_DISABLED = 0, ///< MCK disabled. -#if defined(I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV2) || defined(__NRFX_DOXYGEN__) - // [conversion to 'int' needed to prevent compilers from complaining - // that the provided value (0x80000000UL) is out of range of "int"] - NRF_I2S_MCK_32MDIV2 = (int)I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV2, ///< 32 MHz / 2 = 16.0 MHz. -#endif -#if defined(I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV3) || defined(__NRFX_DOXYGEN__) - NRF_I2S_MCK_32MDIV3 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV3, ///< 32 MHz / 3 = 10.6666667 MHz. -#endif -#if defined(I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV4) || defined(__NRFX_DOXYGEN__) - NRF_I2S_MCK_32MDIV4 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV4, ///< 32 MHz / 4 = 8.0 MHz. -#endif -#if defined(I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV5) || defined(__NRFX_DOXYGEN__) - NRF_I2S_MCK_32MDIV5 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV5, ///< 32 MHz / 5 = 6.4 MHz. -#endif -#if defined(I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV6) || defined(__NRFX_DOXYGEN__) - NRF_I2S_MCK_32MDIV6 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV6, ///< 32 MHz / 6 = 5.3333333 MHz. -#endif - NRF_I2S_MCK_32MDIV8 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV8, ///< 32 MHz / 8 = 4.0 MHz. - NRF_I2S_MCK_32MDIV10 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV10, ///< 32 MHz / 10 = 3.2 MHz. - NRF_I2S_MCK_32MDIV11 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV11, ///< 32 MHz / 11 = 2.9090909 MHz. - NRF_I2S_MCK_32MDIV15 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV15, ///< 32 MHz / 15 = 2.1333333 MHz. - NRF_I2S_MCK_32MDIV16 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV16, ///< 32 MHz / 16 = 2.0 MHz. - NRF_I2S_MCK_32MDIV21 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV21, ///< 32 MHz / 21 = 1.5238095 MHz. - NRF_I2S_MCK_32MDIV23 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV23, ///< 32 MHz / 23 = 1.3913043 MHz. - NRF_I2S_MCK_32MDIV30 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV30, ///< 32 MHz / 30 = 1.0666667 MHz. - NRF_I2S_MCK_32MDIV31 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV31, ///< 32 MHz / 31 = 1.0322581 MHz. - NRF_I2S_MCK_32MDIV32 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV32, ///< 32 MHz / 32 = 1.0 MHz. - NRF_I2S_MCK_32MDIV42 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV42, ///< 32 MHz / 42 = 0.7619048 MHz. - NRF_I2S_MCK_32MDIV63 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV63, ///< 32 MHz / 63 = 0.5079365 MHz. - NRF_I2S_MCK_32MDIV125 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV125 ///< 32 MHz / 125 = 0.256 MHz. -} nrf_i2s_mck_t; - -/** @brief I2S MCK/LRCK ratios. */ -typedef enum -{ - NRF_I2S_RATIO_32X = I2S_CONFIG_RATIO_RATIO_32X, ///< LRCK = MCK / 32. - NRF_I2S_RATIO_48X = I2S_CONFIG_RATIO_RATIO_48X, ///< LRCK = MCK / 48. - NRF_I2S_RATIO_64X = I2S_CONFIG_RATIO_RATIO_64X, ///< LRCK = MCK / 64. - NRF_I2S_RATIO_96X = I2S_CONFIG_RATIO_RATIO_96X, ///< LRCK = MCK / 96. - NRF_I2S_RATIO_128X = I2S_CONFIG_RATIO_RATIO_128X, ///< LRCK = MCK / 128. - NRF_I2S_RATIO_192X = I2S_CONFIG_RATIO_RATIO_192X, ///< LRCK = MCK / 192. - NRF_I2S_RATIO_256X = I2S_CONFIG_RATIO_RATIO_256X, ///< LRCK = MCK / 256. - NRF_I2S_RATIO_384X = I2S_CONFIG_RATIO_RATIO_384X, ///< LRCK = MCK / 384. - NRF_I2S_RATIO_512X = I2S_CONFIG_RATIO_RATIO_512X ///< LRCK = MCK / 512. -} nrf_i2s_ratio_t; - -/** @brief I2S sample widths. */ -typedef enum -{ - NRF_I2S_SWIDTH_8BIT = I2S_CONFIG_SWIDTH_SWIDTH_8Bit, ///< 8 bit. - NRF_I2S_SWIDTH_16BIT = I2S_CONFIG_SWIDTH_SWIDTH_16Bit, ///< 16 bit. - NRF_I2S_SWIDTH_24BIT = I2S_CONFIG_SWIDTH_SWIDTH_24Bit ///< 24 bit. -} nrf_i2s_swidth_t; - -/** @brief I2S alignments of sample within a frame. */ -typedef enum -{ - NRF_I2S_ALIGN_LEFT = I2S_CONFIG_ALIGN_ALIGN_Left, ///< Left-aligned. - NRF_I2S_ALIGN_RIGHT = I2S_CONFIG_ALIGN_ALIGN_Right ///< Right-aligned. -} nrf_i2s_align_t; - -/** @brief I2S frame formats. */ -typedef enum -{ - NRF_I2S_FORMAT_I2S = I2S_CONFIG_FORMAT_FORMAT_I2S, ///< Original I2S format. - NRF_I2S_FORMAT_ALIGNED = I2S_CONFIG_FORMAT_FORMAT_Aligned ///< Alternate (left-aligned or right-aligned) format. -} nrf_i2s_format_t; - -/** @brief I2S enabled channels. */ -typedef enum -{ - NRF_I2S_CHANNELS_STEREO = I2S_CONFIG_CHANNELS_CHANNELS_Stereo, ///< Stereo. - NRF_I2S_CHANNELS_LEFT = I2S_CONFIG_CHANNELS_CHANNELS_Left, ///< Left only. - NRF_I2S_CHANNELS_RIGHT = I2S_CONFIG_CHANNELS_CHANNELS_Right ///< Right only. -} nrf_i2s_channels_t; - - -/** - * @brief Function for activating the specified I2S task. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] task Task to be activated. - */ -__STATIC_INLINE void nrf_i2s_task_trigger(NRF_I2S_Type * p_reg, - nrf_i2s_task_t task); - -/** - * @brief Function for getting the address of the specified I2S task register. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] task Specified task. - * - * @return Address of the specified task register. - */ -__STATIC_INLINE uint32_t nrf_i2s_task_address_get(NRF_I2S_Type const * p_reg, - nrf_i2s_task_t task); - -/** - * @brief Function for clearing the specified I2S event. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] event Event to clear. - */ -__STATIC_INLINE void nrf_i2s_event_clear(NRF_I2S_Type * p_reg, - nrf_i2s_event_t event); - -/** - * @brief Function for retrieving the state of the I2S event. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] event Event to be checked. - * - * @retval true The event has been generated. - * @retval false The event has not been generated. - */ -__STATIC_INLINE bool nrf_i2s_event_check(NRF_I2S_Type const * p_reg, - nrf_i2s_event_t event); - -/** - * @brief Function for getting the address of the specified I2S event register. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] event Specified event. - * - * @return Address of the specified event register. - */ -__STATIC_INLINE uint32_t nrf_i2s_event_address_get(NRF_I2S_Type const * p_reg, - nrf_i2s_event_t event); - -/** - * @brief Function for enabling specified interrupts. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] mask Mask of interrupts to be enabled. - */ -__STATIC_INLINE void nrf_i2s_int_enable(NRF_I2S_Type * p_reg, uint32_t mask); - -/** - * @brief Function for disabling specified interrupts. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] mask Mask of interrupts to be disabled. - */ -__STATIC_INLINE void nrf_i2s_int_disable(NRF_I2S_Type * p_reg, uint32_t mask); - -/** - * @brief Function for retrieving the state of a given interrupt. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] i2s_int Interrupt to be checked. - * - * @retval true The interrupt is enabled. - * @retval false The interrupt is not enabled. - */ -__STATIC_INLINE bool nrf_i2s_int_enable_check(NRF_I2S_Type const * p_reg, - nrf_i2s_int_mask_t i2s_int); - -/** - * @brief Function for enabling the I2S peripheral. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - */ -__STATIC_INLINE void nrf_i2s_enable(NRF_I2S_Type * p_reg); - -/** - * @brief Function for disabling the I2S peripheral. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - */ -__STATIC_INLINE void nrf_i2s_disable(NRF_I2S_Type * p_reg); - -#if defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__) -/** - * @brief Function for setting the subscribe configuration for a given - * I2S task. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] task Task for which to set the configuration. - * @param[in] channel Channel through which to subscribe events. - */ -__STATIC_INLINE void nrf_i2s_subscribe_set(NRF_I2S_Type * p_reg, - nrf_i2s_task_t task, - uint8_t channel); - -/** - * @brief Function for clearing the subscribe configuration for a given - * I2S task. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] task Task for which to clear the configuration. - */ -__STATIC_INLINE void nrf_i2s_subscribe_clear(NRF_I2S_Type * p_reg, - nrf_i2s_task_t task); - -/** - * @brief Function for setting the publish configuration for a given - * I2S event. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] event Event for which to set the configuration. - * @param[in] channel Channel through which to publish the event. - */ -__STATIC_INLINE void nrf_i2s_publish_set(NRF_I2S_Type * p_reg, - nrf_i2s_event_t event, - uint8_t channel); - -/** - * @brief Function for clearing the publish configuration for a given - * I2S event. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] event Event for which to clear the configuration. - */ -__STATIC_INLINE void nrf_i2s_publish_clear(NRF_I2S_Type * p_reg, - nrf_i2s_event_t event); -#endif // defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__) - -/** - * @brief Function for configuring I2S pins. - * - * Usage of the SDOUT, SDIN, and MCK signals is optional. - * If a given signal is not needed, pass the @ref NRF_I2S_PIN_NOT_CONNECTED - * value instead of its pin number. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] sck_pin SCK pin number. - * @param[in] lrck_pin LRCK pin number. - * @param[in] mck_pin MCK pin number. - * @param[in] sdout_pin SDOUT pin number. - * @param[in] sdin_pin SDIN pin number. - */ -__STATIC_INLINE void nrf_i2s_pins_set(NRF_I2S_Type * p_reg, - uint32_t sck_pin, - uint32_t lrck_pin, - uint32_t mck_pin, - uint32_t sdout_pin, - uint32_t sdin_pin); - -/** - * @brief Function for setting the I2S peripheral configuration. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] mode Mode of operation (master or slave). - * @param[in] format I2S frame format. - * @param[in] alignment Alignment of sample within a frame. - * @param[in] sample_width Sample width. - * @param[in] channels Enabled channels. - * @param[in] mck_setup Master clock generator setup. - * @param[in] ratio MCK/LRCK ratio. - * - * @retval true The configuration has been set successfully. - * @retval false The specified configuration is not allowed. - */ -__STATIC_INLINE bool nrf_i2s_configure(NRF_I2S_Type * p_reg, - nrf_i2s_mode_t mode, - nrf_i2s_format_t format, - nrf_i2s_align_t alignment, - nrf_i2s_swidth_t sample_width, - nrf_i2s_channels_t channels, - nrf_i2s_mck_t mck_setup, - nrf_i2s_ratio_t ratio); - -/** - * @brief Function for setting up the I2S transfer. - * - * This function sets up the RX and TX buffers and enables reception or - * transmission (or both) accordingly. If the transfer in a given direction is not - * required, pass NULL instead of the pointer to the corresponding buffer. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] size Size of the buffers (in 32-bit words). - * @param[in] p_rx_buffer Pointer to the receive buffer. - * Pass NULL to disable reception. - * @param[in] p_tx_buffer Pointer to the transmit buffer. - * Pass NULL to disable transmission. - */ -__STATIC_INLINE void nrf_i2s_transfer_set(NRF_I2S_Type * p_reg, - uint16_t size, - uint32_t * p_rx_buffer, - uint32_t const * p_tx_buffer); - -/** - * @brief Function for setting the pointer to the receive buffer. - * - * @note The size of the buffer can be set only by calling - * @ref nrf_i2s_transfer_set. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] p_buffer Pointer to the receive buffer. - */ -__STATIC_INLINE void nrf_i2s_rx_buffer_set(NRF_I2S_Type * p_reg, - uint32_t * p_buffer); - -/** - * @brief Function for getting the pointer to the receive buffer. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * - * @return Pointer to the receive buffer. - */ -__STATIC_INLINE uint32_t * nrf_i2s_rx_buffer_get(NRF_I2S_Type const * p_reg); - -/** - * @brief Function for setting the pointer to the transmit buffer. - * - * @note The size of the buffer can be set only by calling - * @ref nrf_i2s_transfer_set. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] p_buffer Pointer to the transmit buffer. - */ -__STATIC_INLINE void nrf_i2s_tx_buffer_set(NRF_I2S_Type * p_reg, - uint32_t const * p_buffer); - -/** - * @brief Function for getting the pointer to the transmit buffer. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * - * @return Pointer to the transmit buffer. - */ -__STATIC_INLINE uint32_t * nrf_i2s_tx_buffer_get(NRF_I2S_Type const * p_reg); - - -#ifndef SUPPRESS_INLINE_IMPLEMENTATION - -__STATIC_INLINE void nrf_i2s_task_trigger(NRF_I2S_Type * p_reg, - nrf_i2s_task_t task) -{ - *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task)) = 0x1UL; -} - -__STATIC_INLINE uint32_t nrf_i2s_task_address_get(NRF_I2S_Type const * p_reg, - nrf_i2s_task_t task) -{ - return ((uint32_t)p_reg + (uint32_t)task); -} - -__STATIC_INLINE void nrf_i2s_event_clear(NRF_I2S_Type * p_reg, - nrf_i2s_event_t event) -{ - *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)) = 0x0UL; -#if __CORTEX_M == 0x04 - volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)); - (void)dummy; -#endif -} - -__STATIC_INLINE bool nrf_i2s_event_check(NRF_I2S_Type const * p_reg, - nrf_i2s_event_t event) -{ - return (bool)*(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event); -} - -__STATIC_INLINE uint32_t nrf_i2s_event_address_get(NRF_I2S_Type const * p_reg, - nrf_i2s_event_t event) -{ - return ((uint32_t)p_reg + (uint32_t)event); -} - -__STATIC_INLINE void nrf_i2s_int_enable(NRF_I2S_Type * p_reg, uint32_t mask) -{ - p_reg->INTENSET = mask; -} - -__STATIC_INLINE void nrf_i2s_int_disable(NRF_I2S_Type * p_reg, uint32_t mask) -{ - p_reg->INTENCLR = mask; -} - -__STATIC_INLINE bool nrf_i2s_int_enable_check(NRF_I2S_Type const * p_reg, - nrf_i2s_int_mask_t i2s_int) -{ - return (bool)(p_reg->INTENSET & i2s_int); -} - -__STATIC_INLINE void nrf_i2s_enable(NRF_I2S_Type * p_reg) -{ - p_reg->ENABLE = (I2S_ENABLE_ENABLE_Enabled << I2S_ENABLE_ENABLE_Pos); -} - -__STATIC_INLINE void nrf_i2s_disable(NRF_I2S_Type * p_reg) -{ - p_reg->ENABLE = (I2S_ENABLE_ENABLE_Disabled << I2S_ENABLE_ENABLE_Pos); -} - -#if defined(DPPI_PRESENT) -__STATIC_INLINE void nrf_i2s_subscribe_set(NRF_I2S_Type * p_reg, - nrf_i2s_task_t task, - uint8_t channel) -{ - *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = - ((uint32_t)channel | I2S_SUBSCRIBE_START_EN_Msk); -} - -__STATIC_INLINE void nrf_i2s_subscribe_clear(NRF_I2S_Type * p_reg, - nrf_i2s_task_t task) -{ - *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0; -} - -__STATIC_INLINE void nrf_i2s_publish_set(NRF_I2S_Type * p_reg, - nrf_i2s_event_t event, - uint8_t channel) -{ - *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) event + 0x80uL)) = - ((uint32_t)channel | I2S_PUBLISH_STOPPED_EN_Msk); -} - -__STATIC_INLINE void nrf_i2s_publish_clear(NRF_I2S_Type * p_reg, - nrf_i2s_event_t event) -{ - *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) event + 0x80uL)) = 0; -} -#endif // defined(DPPI_PRESENT) - -__STATIC_INLINE void nrf_i2s_pins_set(NRF_I2S_Type * p_reg, - uint32_t sck_pin, - uint32_t lrck_pin, - uint32_t mck_pin, - uint32_t sdout_pin, - uint32_t sdin_pin) -{ - p_reg->PSEL.SCK = sck_pin; - p_reg->PSEL.LRCK = lrck_pin; - p_reg->PSEL.MCK = mck_pin; - p_reg->PSEL.SDOUT = sdout_pin; - p_reg->PSEL.SDIN = sdin_pin; -} - -__STATIC_INLINE bool nrf_i2s_configure(NRF_I2S_Type * p_reg, - nrf_i2s_mode_t mode, - nrf_i2s_format_t format, - nrf_i2s_align_t alignment, - nrf_i2s_swidth_t sample_width, - nrf_i2s_channels_t channels, - nrf_i2s_mck_t mck_setup, - nrf_i2s_ratio_t ratio) -{ - if (mode == NRF_I2S_MODE_MASTER) - { - // The MCK/LRCK ratio must be a multiple of 2 * sample width. - if (((sample_width == NRF_I2S_SWIDTH_16BIT) && - (ratio == NRF_I2S_RATIO_48X)) - || - ((sample_width == NRF_I2S_SWIDTH_24BIT) && - ((ratio == NRF_I2S_RATIO_32X) || - (ratio == NRF_I2S_RATIO_64X) || - (ratio == NRF_I2S_RATIO_128X) || - (ratio == NRF_I2S_RATIO_256X) || - (ratio == NRF_I2S_RATIO_512X)))) - { - return false; - } - } - - p_reg->CONFIG.MODE = mode; - p_reg->CONFIG.FORMAT = format; - p_reg->CONFIG.ALIGN = alignment; - p_reg->CONFIG.SWIDTH = sample_width; - p_reg->CONFIG.CHANNELS = channels; - p_reg->CONFIG.RATIO = ratio; - - if (mck_setup == NRF_I2S_MCK_DISABLED) - { - p_reg->CONFIG.MCKEN = - (I2S_CONFIG_MCKEN_MCKEN_Disabled << I2S_CONFIG_MCKEN_MCKEN_Pos); - } - else - { - p_reg->CONFIG.MCKFREQ = mck_setup; - p_reg->CONFIG.MCKEN = - (I2S_CONFIG_MCKEN_MCKEN_Enabled << I2S_CONFIG_MCKEN_MCKEN_Pos); - } - - return true; -} - -__STATIC_INLINE void nrf_i2s_transfer_set(NRF_I2S_Type * p_reg, - uint16_t size, - uint32_t * p_buffer_rx, - uint32_t const * p_buffer_tx) -{ - p_reg->RXTXD.MAXCNT = size; - - nrf_i2s_rx_buffer_set(p_reg, p_buffer_rx); - p_reg->CONFIG.RXEN = (p_buffer_rx != NULL) ? 1 : 0; - - nrf_i2s_tx_buffer_set(p_reg, p_buffer_tx); - p_reg->CONFIG.TXEN = (p_buffer_tx != NULL) ? 1 : 0; -} - -__STATIC_INLINE void nrf_i2s_rx_buffer_set(NRF_I2S_Type * p_reg, - uint32_t * p_buffer) -{ - p_reg->RXD.PTR = (uint32_t)p_buffer; -} - -__STATIC_INLINE uint32_t * nrf_i2s_rx_buffer_get(NRF_I2S_Type const * p_reg) -{ - return (uint32_t *)(p_reg->RXD.PTR); -} - -__STATIC_INLINE void nrf_i2s_tx_buffer_set(NRF_I2S_Type * p_reg, - uint32_t const * p_buffer) -{ - p_reg->TXD.PTR = (uint32_t)p_buffer; -} - -__STATIC_INLINE uint32_t * nrf_i2s_tx_buffer_get(NRF_I2S_Type const * p_reg) -{ - return (uint32_t *)(p_reg->TXD.PTR); -} - -#endif // SUPPRESS_INLINE_IMPLEMENTATION - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif // NRF_I2S_H__ diff --git a/modules/nrfx/hal/nrf_lpcomp.h b/modules/nrfx/hal/nrf_lpcomp.h deleted file mode 100644 index 07c5d81..0000000 --- a/modules/nrfx/hal/nrf_lpcomp.h +++ /dev/null @@ -1,411 +0,0 @@ -/** - * Copyright (c) 2014 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_LPCOMP_H_ -#define NRF_LPCOMP_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_lpcomp_hal LPCOMP HAL - * @{ - * @ingroup nrf_lpcomp - * @brief Hardware access layer for managing the Low Power Comparator (LPCOMP) peripheral. - */ - -/** @brief LPCOMP reference selection. */ -typedef enum -{ -#if (LPCOMP_REFSEL_RESOLUTION == 8) || defined(__NRFX_DOXYGEN__) - NRF_LPCOMP_REF_SUPPLY_1_8 = LPCOMP_REFSEL_REFSEL_SupplyOneEighthPrescaling, /**< Use supply with a 1/8 prescaler as reference. */ - NRF_LPCOMP_REF_SUPPLY_2_8 = LPCOMP_REFSEL_REFSEL_SupplyTwoEighthsPrescaling, /**< Use supply with a 2/8 prescaler as reference. */ - NRF_LPCOMP_REF_SUPPLY_3_8 = LPCOMP_REFSEL_REFSEL_SupplyThreeEighthsPrescaling, /**< Use supply with a 3/8 prescaler as reference. */ - NRF_LPCOMP_REF_SUPPLY_4_8 = LPCOMP_REFSEL_REFSEL_SupplyFourEighthsPrescaling, /**< Use supply with a 4/8 prescaler as reference. */ - NRF_LPCOMP_REF_SUPPLY_5_8 = LPCOMP_REFSEL_REFSEL_SupplyFiveEighthsPrescaling, /**< Use supply with a 5/8 prescaler as reference. */ - NRF_LPCOMP_REF_SUPPLY_6_8 = LPCOMP_REFSEL_REFSEL_SupplySixEighthsPrescaling, /**< Use supply with a 6/8 prescaler as reference. */ - NRF_LPCOMP_REF_SUPPLY_7_8 = LPCOMP_REFSEL_REFSEL_SupplySevenEighthsPrescaling, /**< Use supply with a 7/8 prescaler as reference. */ -#elif (LPCOMP_REFSEL_RESOLUTION == 16) || defined(__NRFX_DOXYGEN__) - NRF_LPCOMP_REF_SUPPLY_1_8 = LPCOMP_REFSEL_REFSEL_Ref1_8Vdd, /**< Use supply with a 1/8 prescaler as reference. */ - NRF_LPCOMP_REF_SUPPLY_2_8 = LPCOMP_REFSEL_REFSEL_Ref2_8Vdd, /**< Use supply with a 2/8 prescaler as reference. */ - NRF_LPCOMP_REF_SUPPLY_3_8 = LPCOMP_REFSEL_REFSEL_Ref3_8Vdd, /**< Use supply with a 3/8 prescaler as reference. */ - NRF_LPCOMP_REF_SUPPLY_4_8 = LPCOMP_REFSEL_REFSEL_Ref4_8Vdd, /**< Use supply with a 4/8 prescaler as reference. */ - NRF_LPCOMP_REF_SUPPLY_5_8 = LPCOMP_REFSEL_REFSEL_Ref5_8Vdd, /**< Use supply with a 5/8 prescaler as reference. */ - NRF_LPCOMP_REF_SUPPLY_6_8 = LPCOMP_REFSEL_REFSEL_Ref6_8Vdd, /**< Use supply with a 6/8 prescaler as reference. */ - NRF_LPCOMP_REF_SUPPLY_7_8 = LPCOMP_REFSEL_REFSEL_Ref7_8Vdd, /**< Use supply with a 7/8 prescaler as reference. */ - NRF_LPCOMP_REF_SUPPLY_1_16 = LPCOMP_REFSEL_REFSEL_Ref1_16Vdd, /**< Use supply with a 1/16 prescaler as reference. */ - NRF_LPCOMP_REF_SUPPLY_3_16 = LPCOMP_REFSEL_REFSEL_Ref3_16Vdd, /**< Use supply with a 3/16 prescaler as reference. */ - NRF_LPCOMP_REF_SUPPLY_5_16 = LPCOMP_REFSEL_REFSEL_Ref5_16Vdd, /**< Use supply with a 5/16 prescaler as reference. */ - NRF_LPCOMP_REF_SUPPLY_7_16 = LPCOMP_REFSEL_REFSEL_Ref7_16Vdd, /**< Use supply with a 7/16 prescaler as reference. */ - NRF_LPCOMP_REF_SUPPLY_9_16 = LPCOMP_REFSEL_REFSEL_Ref9_16Vdd, /**< Use supply with a 9/16 prescaler as reference. */ - NRF_LPCOMP_REF_SUPPLY_11_16 = LPCOMP_REFSEL_REFSEL_Ref11_16Vdd, /**< Use supply with a 11/16 prescaler as reference. */ - NRF_LPCOMP_REF_SUPPLY_13_16 = LPCOMP_REFSEL_REFSEL_Ref13_16Vdd, /**< Use supply with a 13/16 prescaler as reference. */ - NRF_LPCOMP_REF_SUPPLY_15_16 = LPCOMP_REFSEL_REFSEL_Ref15_16Vdd, /**< Use supply with a 15/16 prescaler as reference. */ -#endif - NRF_LPCOMP_REF_EXT_REF0 = LPCOMP_REFSEL_REFSEL_ARef | - (LPCOMP_EXTREFSEL_EXTREFSEL_AnalogReference0 << 16), /**< External reference 0. */ - NRF_LPCOMP_CONFIG_REF_EXT_REF1 = LPCOMP_REFSEL_REFSEL_ARef | - (LPCOMP_EXTREFSEL_EXTREFSEL_AnalogReference1 << 16), /**< External reference 1. */ -} nrf_lpcomp_ref_t; - -/** @brief LPCOMP input selection. */ -typedef enum -{ - NRF_LPCOMP_INPUT_0 = LPCOMP_PSEL_PSEL_AnalogInput0, /**< Input 0. */ - NRF_LPCOMP_INPUT_1 = LPCOMP_PSEL_PSEL_AnalogInput1, /**< Input 1. */ - NRF_LPCOMP_INPUT_2 = LPCOMP_PSEL_PSEL_AnalogInput2, /**< Input 2. */ - NRF_LPCOMP_INPUT_3 = LPCOMP_PSEL_PSEL_AnalogInput3, /**< Input 3. */ - NRF_LPCOMP_INPUT_4 = LPCOMP_PSEL_PSEL_AnalogInput4, /**< Input 4. */ - NRF_LPCOMP_INPUT_5 = LPCOMP_PSEL_PSEL_AnalogInput5, /**< Input 5. */ - NRF_LPCOMP_INPUT_6 = LPCOMP_PSEL_PSEL_AnalogInput6, /**< Input 6. */ - NRF_LPCOMP_INPUT_7 = LPCOMP_PSEL_PSEL_AnalogInput7 /**< Input 7. */ -} nrf_lpcomp_input_t; - -/** @brief LPCOMP detection type selection. */ -typedef enum -{ - NRF_LPCOMP_DETECT_CROSS = LPCOMP_ANADETECT_ANADETECT_Cross, /**< Generate ANADETEC on crossing, both upwards and downwards crossing. */ - NRF_LPCOMP_DETECT_UP = LPCOMP_ANADETECT_ANADETECT_Up, /**< Generate ANADETEC on upwards crossing only. */ - NRF_LPCOMP_DETECT_DOWN = LPCOMP_ANADETECT_ANADETECT_Down /**< Generate ANADETEC on downwards crossing only. */ -} nrf_lpcomp_detect_t; - -/** @brief LPCOMP tasks. */ -typedef enum -{ - NRF_LPCOMP_TASK_START = offsetof(NRF_LPCOMP_Type, TASKS_START), /**< LPCOMP start sampling task. */ - NRF_LPCOMP_TASK_STOP = offsetof(NRF_LPCOMP_Type, TASKS_STOP), /**< LPCOMP stop sampling task. */ - NRF_LPCOMP_TASK_SAMPLE = offsetof(NRF_LPCOMP_Type, TASKS_SAMPLE) /**< Sample comparator value. */ -} nrf_lpcomp_task_t; - - -/** @brief LPCOMP events. */ -typedef enum -{ - NRF_LPCOMP_EVENT_READY = offsetof(NRF_LPCOMP_Type, EVENTS_READY), /**< LPCOMP is ready and output is valid. */ - NRF_LPCOMP_EVENT_DOWN = offsetof(NRF_LPCOMP_Type, EVENTS_DOWN), /**< Input voltage crossed the threshold going down. */ - NRF_LPCOMP_EVENT_UP = offsetof(NRF_LPCOMP_Type, EVENTS_UP), /**< Input voltage crossed the threshold going up. */ - NRF_LPCOMP_EVENT_CROSS = offsetof(NRF_LPCOMP_Type, EVENTS_CROSS) /**< Input voltage crossed the threshold in any direction. */ -} nrf_lpcomp_event_t; - -/** @brief LPCOMP shortcut masks. */ -typedef enum -{ - NRF_LPCOMP_SHORT_CROSS_STOP_MASK = LPCOMP_SHORTS_CROSS_STOP_Msk, /*!< Shortcut between CROSS event and STOP task. */ - NRF_LPCOMP_SHORT_UP_STOP_MASK = LPCOMP_SHORTS_UP_STOP_Msk, /*!< Shortcut between UP event and STOP task. */ - NRF_LPCOMP_SHORT_DOWN_STOP_MASK = LPCOMP_SHORTS_DOWN_STOP_Msk, /*!< Shortcut between DOWN event and STOP task. */ - NRF_LPCOMP_SHORT_READY_STOP_MASK = LPCOMP_SHORTS_READY_STOP_Msk, /*!< Shortcut between READY event and STOP task. */ - NRF_LPCOMP_SHORT_READY_SAMPLE_MASK = LPCOMP_SHORTS_READY_SAMPLE_Msk /*!< Shortcut between READY event and SAMPLE task. */ -} nrf_lpcomp_short_mask_t; - -#ifdef LPCOMP_FEATURE_HYST_PRESENT -/** @brief LPCOMP hysteresis. */ -typedef enum -{ - NRF_LPCOMP_HYST_NOHYST = LPCOMP_HYST_HYST_NoHyst, /**< Comparator hysteresis disabled. */ - NRF_LPCOMP_HYST_50mV = LPCOMP_HYST_HYST_Hyst50mV /**< Comparator hysteresis enabled (typically 50 mV). */ -}nrf_lpcomp_hysteresis_t; -#endif // LPCOMP_FEATURE_HYST_PRESENT - -/** @brief LPCOMP configuration. */ -typedef struct -{ - nrf_lpcomp_ref_t reference; /**< LPCOMP reference. */ - nrf_lpcomp_detect_t detection; /**< LPCOMP detection type. */ -#ifdef LPCOMP_FEATURE_HYST_PRESENT - nrf_lpcomp_hysteresis_t hyst; /**< LPCOMP hysteresis. */ -#endif // LPCOMP_FEATURE_HYST_PRESENT -} nrf_lpcomp_config_t; - - -/** Default LPCOMP configuration. */ -#define NRF_LPCOMP_CONFIG_DEFAULT { NRF_LPCOMP_REF_SUPPLY_FOUR_EIGHT, NRF_LPCOMP_DETECT_DOWN } - - -/** - * @brief Function for configuring LPCOMP. - * - * This function powers on LPCOMP and configures it. LPCOMP is in DISABLE state after configuration, - * so it must be enabled before using it. All shorts are inactive, events are cleared, and LPCOMP is stopped. - * - * @param[in] p_config Configuration. - */ -__STATIC_INLINE void nrf_lpcomp_configure(const nrf_lpcomp_config_t * p_config); - -/** - * @brief Function for selecting the LPCOMP input. - * - * This function selects the active input of LPCOMP. - * - * @param[in] input Input to be selected. - */ -__STATIC_INLINE void nrf_lpcomp_input_select(nrf_lpcomp_input_t input); - -/** - * @brief Function for enabling the Low Power Comparator. - * - * This function enables LPCOMP. - */ -__STATIC_INLINE void nrf_lpcomp_enable(void); - -/** - * @brief Function for disabling the Low Power Comparator. - * - * This function disables LPCOMP. - */ -__STATIC_INLINE void nrf_lpcomp_disable(void); - -/** - * @brief Function for getting the last LPCOMP compare result. - * - * @return The last compare result. If 0 then VIN+ < VIN-, if 1 then the opposite. - */ -__STATIC_INLINE uint32_t nrf_lpcomp_result_get(void); - -/** - * @brief Function for enabling interrupts from LPCOMP. - * - * @param[in] int_mask Mask of interrupts to be enabled. - * - * @sa nrf_lpcomp_int_disable - * @sa nrf_lpcomp_int_enable_check - */ -__STATIC_INLINE void nrf_lpcomp_int_enable(uint32_t int_mask); - -/** - * @brief Function for disabling interrupts from LPCOMP. - * - * @param[in] int_mask Mask of interrupts to be disabled. - * - * @sa nrf_lpcomp_int_enable - * @sa nrf_lpcomp_int_enable_check - */ -__STATIC_INLINE void nrf_lpcomp_int_disable(uint32_t int_mask); - -/** - * @brief Function for getting the enabled interrupts of LPCOMP. - * - * @param[in] int_mask Mask of interrupts to be checked. - * - * @retval true Any of interrupts of the specified mask are enabled. - * @retval false None interrupt specified by the mask are enabled. - * - * @sa nrf_lpcomp_int_enable - * @sa nrf_lpcomp_int_disable - */ -__STATIC_INLINE bool nrf_lpcomp_int_enable_check(uint32_t int_mask); - -/** - * @brief Function for getting the address of the specified LPCOMP task register. - * - * @param[in] task LPCOMP task. - * - * @return The address of the specified LPCOMP task. - */ -__STATIC_INLINE uint32_t * nrf_lpcomp_task_address_get(nrf_lpcomp_task_t task); - -/** - * @brief Function for getting the address of the specified LPCOMP event register. - * - * @param[in] event LPCOMP event. - * - * @return The address of the specified LPCOMP event. - */ -__STATIC_INLINE uint32_t * nrf_lpcomp_event_address_get(nrf_lpcomp_event_t event); - -/** - * @brief Function for setting LPCOMP shorts. - * - * @param[in] mask Mask of shortcuts. - */ -__STATIC_INLINE void nrf_lpcomp_shorts_enable(uint32_t mask); - -/** - * @brief Function for clearing LPCOMP shorts by mask. - * - * @param[in] mask Mask of shortcuts. - */ -__STATIC_INLINE void nrf_lpcomp_shorts_disable(uint32_t mask); - -/** - * @brief Function for setting the specified LPCOMP task. - * - * @param[in] task LPCOMP task to be set. - */ -__STATIC_INLINE void nrf_lpcomp_task_trigger(nrf_lpcomp_task_t task); - -/** - * @brief Function for clearing the specified LPCOMP event. - * - * @param[in] event LPCOMP event to be cleared. - */ -__STATIC_INLINE void nrf_lpcomp_event_clear(nrf_lpcomp_event_t event); - -/** - * @brief Function for retrieving the state of the LPCOMP event. - * - * @param[in] event Event to be checked. - * - * @retval true The event has been generated. - * @retval false The event has not been generated. - */ -__STATIC_INLINE bool nrf_lpcomp_event_check(nrf_lpcomp_event_t event); - -#ifndef SUPPRESS_INLINE_IMPLEMENTATION - -__STATIC_INLINE void nrf_lpcomp_configure(const nrf_lpcomp_config_t * p_config) -{ - NRF_LPCOMP->TASKS_STOP = 1; - NRF_LPCOMP->ENABLE = LPCOMP_ENABLE_ENABLE_Disabled << LPCOMP_ENABLE_ENABLE_Pos; - NRF_LPCOMP->REFSEL = - (p_config->reference << LPCOMP_REFSEL_REFSEL_Pos) & LPCOMP_REFSEL_REFSEL_Msk; - - //If external source is choosen extract analog reference index. - if ((p_config->reference & LPCOMP_REFSEL_REFSEL_ARef)==LPCOMP_REFSEL_REFSEL_ARef) - { - uint32_t extref = p_config->reference >> 16; - NRF_LPCOMP->EXTREFSEL = (extref << LPCOMP_EXTREFSEL_EXTREFSEL_Pos) & - LPCOMP_EXTREFSEL_EXTREFSEL_Msk; - } - - NRF_LPCOMP->ANADETECT = - (p_config->detection << LPCOMP_ANADETECT_ANADETECT_Pos) & LPCOMP_ANADETECT_ANADETECT_Msk; -#ifdef LPCOMP_FEATURE_HYST_PRESENT - NRF_LPCOMP->HYST = ((p_config->hyst) << LPCOMP_HYST_HYST_Pos) & LPCOMP_HYST_HYST_Msk; -#endif //LPCOMP_FEATURE_HYST_PRESENT - NRF_LPCOMP->SHORTS = 0; - NRF_LPCOMP->INTENCLR = LPCOMP_INTENCLR_CROSS_Msk | LPCOMP_INTENCLR_UP_Msk | - LPCOMP_INTENCLR_DOWN_Msk | LPCOMP_INTENCLR_READY_Msk; -} - -__STATIC_INLINE void nrf_lpcomp_input_select(nrf_lpcomp_input_t input) -{ - uint32_t lpcomp_enable_state = NRF_LPCOMP->ENABLE; - - NRF_LPCOMP->ENABLE = LPCOMP_ENABLE_ENABLE_Disabled << LPCOMP_ENABLE_ENABLE_Pos; - NRF_LPCOMP->PSEL = - ((uint32_t)input << LPCOMP_PSEL_PSEL_Pos) | (NRF_LPCOMP->PSEL & ~LPCOMP_PSEL_PSEL_Msk); - NRF_LPCOMP->ENABLE = lpcomp_enable_state; -} - -__STATIC_INLINE void nrf_lpcomp_enable(void) -{ - NRF_LPCOMP->ENABLE = LPCOMP_ENABLE_ENABLE_Enabled << LPCOMP_ENABLE_ENABLE_Pos; - NRF_LPCOMP->EVENTS_READY = 0; - NRF_LPCOMP->EVENTS_DOWN = 0; - NRF_LPCOMP->EVENTS_UP = 0; - NRF_LPCOMP->EVENTS_CROSS = 0; -} - -__STATIC_INLINE void nrf_lpcomp_disable(void) -{ - NRF_LPCOMP->ENABLE = LPCOMP_ENABLE_ENABLE_Disabled << LPCOMP_ENABLE_ENABLE_Pos; -} - -__STATIC_INLINE uint32_t nrf_lpcomp_result_get(void) -{ - return (uint32_t)NRF_LPCOMP->RESULT; -} - -__STATIC_INLINE void nrf_lpcomp_int_enable(uint32_t int_mask) -{ - NRF_LPCOMP->INTENSET = int_mask; -} - -__STATIC_INLINE void nrf_lpcomp_int_disable(uint32_t int_mask) -{ - NRF_LPCOMP->INTENCLR = int_mask; -} - -__STATIC_INLINE bool nrf_lpcomp_int_enable_check(uint32_t int_mask) -{ - return (NRF_LPCOMP->INTENSET & int_mask); // when read this register will return the value of INTEN. -} - -__STATIC_INLINE uint32_t * nrf_lpcomp_task_address_get(nrf_lpcomp_task_t task) -{ - return (uint32_t *)((uint8_t *)NRF_LPCOMP + task); -} - -__STATIC_INLINE uint32_t * nrf_lpcomp_event_address_get(nrf_lpcomp_event_t event) -{ - return (uint32_t *)((uint8_t *)NRF_LPCOMP + event); -} - -__STATIC_INLINE void nrf_lpcomp_shorts_enable(uint32_t short_mask) -{ - NRF_LPCOMP->SHORTS |= short_mask; -} - -__STATIC_INLINE void nrf_lpcomp_shorts_disable(uint32_t short_mask) -{ - NRF_LPCOMP->SHORTS &= ~short_mask; -} - -__STATIC_INLINE void nrf_lpcomp_task_trigger(nrf_lpcomp_task_t task) -{ - *( (volatile uint32_t *)( (uint8_t *)NRF_LPCOMP + (uint32_t)task) ) = 1; -} - -__STATIC_INLINE void nrf_lpcomp_event_clear(nrf_lpcomp_event_t event) -{ - *( (volatile uint32_t *)( (uint8_t *)NRF_LPCOMP + (uint32_t)event) ) = 0; -#if __CORTEX_M == 0x04 - volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_LPCOMP + (uint32_t)event)); - (void)dummy; -#endif -} - -__STATIC_INLINE bool nrf_lpcomp_event_check(nrf_lpcomp_event_t event) -{ - return (bool) (*(volatile uint32_t *)( (uint8_t *)NRF_LPCOMP + (uint32_t)event)); -} - -#endif // SUPPRESS_INLINE_IMPLEMENTATION - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif // NRF_LPCOMP_H_ diff --git a/modules/nrfx/hal/nrf_nfct.h b/modules/nrfx/hal/nrf_nfct.h deleted file mode 100644 index 1f2748b..0000000 --- a/modules/nrfx/hal/nrf_nfct.h +++ /dev/null @@ -1,1073 +0,0 @@ -/** - * Copyright (c) 2018 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_NFCT_H__ -#define NRF_NFCT_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_nfct_hal NFCT HAL - * @{ - * @ingroup nrf_nfct - * - * @brief Hardware access layer (HAL) for the Near Field Communication Tag (NFCT) peripheral. - */ - -#define NRF_NFCT_CRC_SIZE 2 /**< CRC size in bytes. */ -#define NRF_NFCT_DISABLE_ALL_INT 0xFFFFFFFF /**< Value to disable all interrupts. */ - -/** @brief NFCT tasks. */ -typedef enum -{ - NRF_NFCT_TASK_ACTIVATE = offsetof(NRF_NFCT_Type, TASKS_ACTIVATE), /**< Activate the NFCT peripheral for the incoming and outgoing frames, change state to activated. */ - NRF_NFCT_TASK_DISABLE = offsetof(NRF_NFCT_Type, TASKS_DISABLE), /**< Disable the NFCT peripheral. */ - NRF_NFCT_TASK_SENSE = offsetof(NRF_NFCT_Type, TASKS_SENSE), /**< Enable the NFC sense field mode, change state to sense mode. */ - NRF_NFCT_TASK_STARTTX = offsetof(NRF_NFCT_Type, TASKS_STARTTX), /**< Start the transmission of an outgoing frame, change state to transmit. */ - NRF_NFCT_TASK_ENABLERXDATA = offsetof(NRF_NFCT_Type, TASKS_ENABLERXDATA), /**< Initialize EasyDMA for receive. */ - NRF_NFCT_TASK_GOIDLE = offsetof(NRF_NFCT_Type, TASKS_GOIDLE), /**< Force state machine to the IDLE state. */ - NRF_NFCT_TASK_GOSLEEP = offsetof(NRF_NFCT_Type, TASKS_GOSLEEP), /**< Force state machine to the SLEEP_A state. */ -} nrf_nfct_task_t; - -/** @brief NFCT events. */ -typedef enum -{ - NRF_NFCT_EVENT_READY = offsetof(NRF_NFCT_Type, EVENTS_READY), /**< The NFCT peripheral is ready to receive and send frames. */ - NRF_NFCT_EVENT_FIELDDETECTED = offsetof(NRF_NFCT_Type, EVENTS_FIELDDETECTED), /**< Remote NFC field is detected. */ - NRF_NFCT_EVENT_FIELDLOST = offsetof(NRF_NFCT_Type, EVENTS_FIELDLOST), /**< Remote NFC field is lost. */ - NRF_NFCT_EVENT_TXFRAMESTART = offsetof(NRF_NFCT_Type, EVENTS_TXFRAMESTART), /**< The start of the first symbol of a transmitted frame. */ - NRF_NFCT_EVENT_TXFRAMEEND = offsetof(NRF_NFCT_Type, EVENTS_TXFRAMEEND), /**< The end of the last transmitted on-air symbol of a frame. */ - NRF_NFCT_EVENT_RXFRAMESTART = offsetof(NRF_NFCT_Type, EVENTS_RXFRAMESTART), /**< The end of the first symbol of a received frame. */ - NRF_NFCT_EVENT_RXFRAMEEND = offsetof(NRF_NFCT_Type, EVENTS_RXFRAMEEND), /**< Received data was checked (CRC, parity) and transferred to RAM, and EasyDMA ended accessing the RX buffer. */ - NRF_NFCT_EVENT_ERROR = offsetof(NRF_NFCT_Type, EVENTS_ERROR), /**< NFC error reported. The ERRORSTATUS register contains details on the source of the error. */ - NRF_NFCT_EVENT_RXERROR = offsetof(NRF_NFCT_Type, EVENTS_RXERROR), /**< NFC RX frame error reported. The FRAMESTATUS.RX register contains details on the source of the error. */ - NRF_NFCT_EVENT_ENDRX = offsetof(NRF_NFCT_Type, EVENTS_ENDRX), /**< RX buffer (as defined by PACKETPTR and MAXLEN) in Data RAM full. */ - NRF_NFCT_EVENT_ENDTX = offsetof(NRF_NFCT_Type, EVENTS_ENDTX), /**< Transmission of data in RAM ended, and EasyDMA ended accessing the TX buffer. */ - NRF_NFCT_EVENT_AUTOCOLRESSTARTED = offsetof(NRF_NFCT_Type, EVENTS_AUTOCOLRESSTARTED), /**< Auto collision resolution process started. */ - NRF_NFCT_EVENT_COLLISION = offsetof(NRF_NFCT_Type, EVENTS_COLLISION), /**< NFC auto collision resolution error reported. */ - NRF_NFCT_EVENT_SELECTED = offsetof(NRF_NFCT_Type, EVENTS_SELECTED), /**< NFC auto collision resolution successfully completed. */ - NRF_NFCT_EVENT_STARTED = offsetof(NRF_NFCT_Type, EVENTS_STARTED), /**< EasyDMA is ready to receive or send frames. */ -} nrf_nfct_event_t; - -/** @brief NFCT shortcuts. */ -typedef enum -{ - NRF_NFCT_SHORT_FIELDDETECTED_ACTIVATE_MASK = NFCT_SHORTS_FIELDDETECTED_ACTIVATE_Msk, /**< Shortcut between the FIELDDETECTED event and the ACTIVATE task. */ - NRF_NFCT_SHORT_FIELDLOST_SENSE_MASK = NFCT_SHORTS_FIELDLOST_SENSE_Msk, /**< Shortcut between the FIELDLOST event and the SENSE task. */ -#if defined(NFCT_SHORTS_TXFRAMEEND_ENABLERXDATA_Msk) || defined(__NRFX_DOXYGEN__) - NRF_NFCT_SHORT_TXFRAMEEND_ENABLERXDATA_MASK = NFCT_SHORTS_TXFRAMEEND_ENABLERXDATA_Msk, /**< Shortcut between the TXFRAMEEND event and the ENABLERXDATA task. */ -#endif // defined(NFCT_SHORTS_TXFRAMEEND_ENABLERXDATA_Msk) || defined(__NRFX_DOXYGEN__) -} nrf_nfct_short_mask_t; - -/** @brief NFCT interrupts. */ -typedef enum -{ - NRF_NFCT_INT_READY_MASK = NFCT_INTEN_READY_Msk, /**< Interrupt on READY event. */ - NRF_NFCT_INT_FIELDDETECTED_MASK = NFCT_INTEN_FIELDDETECTED_Msk, /**< Interrupt on FIELDDETECTED event. */ - NRF_NFCT_INT_FIELDLOST_MASK = NFCT_INTEN_FIELDLOST_Msk, /**< Interrupt on FIELDLOST event. */ - NRF_NFCT_INT_TXFRAMESTART_MASK = NFCT_INTEN_TXFRAMESTART_Msk, /**< Interrupt on TXFRAMESTART event. */ - NRF_NFCT_INT_TXFRAMEEND_MASK = NFCT_INTEN_TXFRAMEEND_Msk, /**< Interrupt on TXFRAMEEND event. */ - NRF_NFCT_INT_RXFRAMESTART_MASK = NFCT_INTEN_RXFRAMESTART_Msk, /**< Interrupt on RXFRAMESTART event. */ - NRF_NFCT_INT_RXFRAMEEND_MASK = NFCT_INTEN_RXFRAMEEND_Msk, /**< Interrupt on RXFRAMEEND event. */ - NRF_NFCT_INT_ERROR_MASK = NFCT_INTEN_ERROR_Msk, /**< Interrupt on ERROR event. */ - NRF_NFCT_INT_RXERROR_MASK = NFCT_INTEN_RXERROR_Msk, /**< Interrupt on RXERROR event. */ - NRF_NFCT_INT_ENDRX_MASK = NFCT_INTEN_ENDRX_Msk, /**< Interrupt on ENDRX event. */ - NRF_NFCT_INT_ENDTX_MASK = NFCT_INTEN_ENDTX_Msk, /**< Interrupt on ENDTX event. */ - NRF_NFCT_INT_AUTOCOLRESSTARTED_MASK = NFCT_INTEN_AUTOCOLRESSTARTED_Msk, /**< Interrupt on AUTOCOLRESSTARTED event. */ - NRF_NFCT_INT_COLLISION_MASK = NFCT_INTEN_COLLISION_Msk, /**< Interrupt on COLLISION event. */ - NRF_NFCT_INT_SELECTED_MASK = NFCT_INTEN_SELECTED_Msk, /**< Interrupt on SELECTED event. */ - NRF_NFCT_INT_STARTED_MASK = NFCT_INTEN_STARTED_Msk, /**< Interrupt on STARTED event. */ -} nrf_nfct_int_mask_t; - -/** @brief NFC error status bit masks. */ -typedef enum -{ - NRF_NFCT_ERROR_FRAMEDELAYTIMEOUT_MASK = NFCT_ERRORSTATUS_FRAMEDELAYTIMEOUT_Msk, /**< Timeout of the Frame Delay Timer (no frame transmission started in the FDT window). */ -#if defined(NFCT_ERRORSTATUS_NFCFIELDTOOSTRONG_Msk) || defined(__NRFX_DOXYGEN__) - NRF_NFCT_ERROR_NFCFIELDTOOSTRONG_MASK = NFCT_ERRORSTATUS_NFCFIELDTOOSTRONG_Msk, /**< Field level is too high at maximum load resistance. */ -#endif // defined(NFCT_ERRORSTATUS_NFCFIELDTOOSTRONG_Msk) || defined(__NRFX_DOXYGEN__) -#if defined(NFCT_ERRORSTATUS_NFCFIELDTOOWEAK_Msk) || defined(__NRFX_DOXYGEN__) - NRF_NFCT_ERROR_NFCFIELDTOOWEAK_MASK = NFCT_ERRORSTATUS_NFCFIELDTOOWEAK_Msk, /**< Field level is too low at minimum load resistance. */ -#endif // defined(NFCT_ERRORSTATUS_NFCFIELDTOOWEAK_Msk) || defined(__NRFX_DOXYGEN__) -} nrf_nfct_error_status_t; - -/** @brief NFC received frame status bit masks. */ -typedef enum -{ - NRF_NFCT_RX_FRAME_STATUS_CRC_MASK = NFCT_FRAMESTATUS_RX_CRCERROR_Msk, /**< CRC status mask. */ - NRF_NFCT_RX_FRAME_STATUS_PARITY_MASK = NFCT_FRAMESTATUS_RX_PARITYSTATUS_Msk, /**< Parity status mask. */ - NRF_NFCT_RX_FRAME_STATUS_OVERRUN_MASK = NFCT_FRAMESTATUS_RX_OVERRUN_Msk, /**< Overrun status mask. */ -} nrf_nfct_rx_frame_status_t; - -#if defined(NFCT_NFCTAGSTATE_NFCTAGSTATE_Msk) || defined(__NRFX_DOXYGEN__) -/** @brief NFC tag state. */ -typedef enum -{ - NRF_NFCT_TAG_STATE_DISABLED = NFCT_NFCTAGSTATE_NFCTAGSTATE_Disabled, /**< Disabled or sensing NFC field. */ - NRF_NFCT_TAG_STATE_RAMP_UP = NFCT_NFCTAGSTATE_NFCTAGSTATE_RampUp, /**< Ramping up. */ - NRF_NFCT_TAG_STATE_IDLE = NFCT_NFCTAGSTATE_NFCTAGSTATE_Idle, /**< Idle. */ - NRF_NFCT_TAG_STATE_RECEIVE = NFCT_NFCTAGSTATE_NFCTAGSTATE_Receive, /**< Receiving data. */ - NRF_NFCT_TAG_STATE_FRAME_DELAY = NFCT_NFCTAGSTATE_NFCTAGSTATE_FrameDelay, /**< Counting Frame Delay Time since the last symbol of the last received frame. */ - NRF_NFCT_TAG_STATE_TRANSMIT = NFCT_NFCTAGSTATE_NFCTAGSTATE_Transmit /**< Transmitting data. */ -} nrf_nfct_tag_state_t; -#endif // defined(NFCT_NFCTAGSTATE_NFCTAGSTATE_Msk) || defined(__NRFX_DOXYGEN__) - -#if defined (NFCT_SLEEPSTATE_SLEEPSTATE_Msk) || defined(__NRFX_DOXYGEN__) -/** - * @brief NFC tag sleep state. - * - * @details Shows the sleep state during automatic collision resolution - * according to the NFC Forum Activity Technical Specification v2.0. - */ -typedef enum -{ - NRF_NFCT_SLEEP_STATE_IDLE = NFCT_SLEEPSTATE_SLEEPSTATE_Idle, /**< 'IDLE' state. */ - NRF_NFCT_SLEEP_STATE_SLEEP_A = NFCT_SLEEPSTATE_SLEEPSTATE_SleepA /**< 'SLEEP_A' state. */ -} nrf_nfct_sleep_state_t; -#endif // defined (NFCT_SLEEPSTATE_SLEEPSTATE_Msk) || defined(__NRFX_DOXYGEN__) - -/** @brief NFC field state bit masks. */ -typedef enum -{ - NRF_NFCT_FIELD_STATE_PRESENT_MASK = NFCT_FIELDPRESENT_FIELDPRESENT_Msk, /**< Field presence mask. */ - NRF_NFCT_FIELD_STATE_LOCK_MASK = NFCT_FIELDPRESENT_LOCKDETECT_Msk /**< Field lock mask. */ -} nrf_nfct_field_state_t; - -/** @brief NFC frame delay mode for data transmission. */ -typedef enum -{ - NRF_NFCT_FRAME_DELAY_MODE_FREERUN = NFCT_FRAMEDELAYMODE_FRAMEDELAYMODE_FreeRun, /**< Frame transmission starts when @ref NRF_NFCT_TASK_STARTTX is set (delay timer is not used). */ - NRF_NFCT_FRAME_DELAY_MODE_WINDOW = NFCT_FRAMEDELAYMODE_FRAMEDELAYMODE_Window, /**< Frame transmission starts in a window between FRAMEDELAYMIN and FRAMEDELAYMAX. */ - NRF_NFCT_FRAME_DELAY_MODE_EXACTVAL = NFCT_FRAMEDELAYMODE_FRAMEDELAYMODE_ExactVal, /**< Frame transmission starts when the delay timer reaches FRAMEDELAYMAX. */ - NRF_NFCT_FRAME_DELAY_MODE_WINDOWGRID = NFCT_FRAMEDELAYMODE_FRAMEDELAYMODE_WindowGrid /**< Frame transmission starts in a bit grid between FRAMEDELAYMIN and FRAMEDELAYMAX. */ -} nrf_nfct_frame_delay_mode_t; - -/** @brief Bit masks for NFC transmission frame configuration. */ -typedef enum -{ - NRF_NFCT_TX_FRAME_CONFIG_PARITY = NFCT_TXD_FRAMECONFIG_PARITY_Msk, /**< Indicates whether parity is added in the transmitted frames. */ - NRF_NFCT_TX_FRAME_CONFIG_DISCARD_START = NFCT_TXD_FRAMECONFIG_DISCARDMODE_Msk, /**< Indicates whether unused bits are discarded at the start or at the end of the transmitted frames. */ - NRF_NFCT_TX_FRAME_CONFIG_SOF = NFCT_TXD_FRAMECONFIG_SOF_Msk, /**< Indicates whether SoF symbol is added in the transmitted frames. */ - NRF_NFCT_TX_FRAME_CONFIG_CRC16 = NFCT_TXD_FRAMECONFIG_CRCMODETX_Msk /**< Indicates whether CRC is added in the transmitted frames. */ -} nrf_nfct_tx_frame_config_t; - -/** @brief Bit masks for NFC reception frame configuration. */ -typedef enum -{ - NRF_NFCT_RX_FRAME_CONFIG_PARITY = NFCT_RXD_FRAMECONFIG_PARITY_Msk, /**< Indicates whether parity is expected in the received frames. */ - NRF_NFCT_RX_FRAME_CONFIG_SOF = NFCT_RXD_FRAMECONFIG_SOF_Msk, /**< Indicates whether SoF symbol is expected in the received frames. */ - NRF_NFCT_RX_FRAME_CONFIG_CRC16 = NFCT_RXD_FRAMECONFIG_CRCMODERX_Msk /**< Indicates whether CRC is expected and checked in the received frames. */ -} nrf_nfct_rx_frame_config_t; - -/** - * @brief 'NFCI1 size' NFC field configuration for the SENS_RES frame according to the NFC Forum - * Digital Protocol Technical Specification. - */ -typedef enum -{ - NRF_NFCT_SENSRES_NFCID1_SIZE_SINGLE = - NFCT_SENSRES_NFCIDSIZE_NFCID1Single << NFCT_SENSRES_NFCIDSIZE_Pos, /**< Single size NFCID1 (4 bytes). */ - NRF_NFCT_SENSRES_NFCID1_SIZE_DOUBLE = - NFCT_SENSRES_NFCIDSIZE_NFCID1Double << NFCT_SENSRES_NFCIDSIZE_Pos, /**< Double size NFCID1 (7 bytes). */ - NRF_NFCT_SENSRES_NFCID1_SIZE_TRIPLE = - NFCT_SENSRES_NFCIDSIZE_NFCID1Triple << NFCT_SENSRES_NFCIDSIZE_Pos, /**< Triple size NFCID1 (10 bytes). */ - NRF_NFCT_SENSRES_NFCID1_SIZE_DEFAULT = - NFCT_SENSRES_NFCIDSIZE_Msk /**< Default size. Use this option to leave NFCID1 size unchanged. */ -} nrf_nfct_sensres_nfcid1_size_t; - -/** - * @brief 'Bit frame SDD' NFC field configuration for the SENS_RES frame according to the NFC - * Forum Digital Protocol Technical Specification. - */ -typedef enum -{ - NRF_NFCT_SENSRES_BIT_FRAME_SDD_00000 = - NFCT_SENSRES_BITFRAMESDD_SDD00000 << NFCT_SENSRES_BITFRAMESDD_Pos, /**< SDD pattern 00000. */ - NRF_NFCT_SENSRES_BIT_FRAME_SDD_00001 = - NFCT_SENSRES_BITFRAMESDD_SDD00001 << NFCT_SENSRES_BITFRAMESDD_Pos, /**< SDD pattern 00001. */ - NRF_NFCT_SENSRES_BIT_FRAME_SDD_00010 = - NFCT_SENSRES_BITFRAMESDD_SDD00010 << NFCT_SENSRES_BITFRAMESDD_Pos, /**< SDD pattern 00010. */ - NRF_NFCT_SENSRES_BIT_FRAME_SDD_00100 = - NFCT_SENSRES_BITFRAMESDD_SDD00100 << NFCT_SENSRES_BITFRAMESDD_Pos, /**< SDD pattern 00100. */ - NRF_NFCT_SENSRES_BIT_FRAME_SDD_01000 = - NFCT_SENSRES_BITFRAMESDD_SDD01000 << NFCT_SENSRES_BITFRAMESDD_Pos, /**< SDD pattern 01000. */ - NRF_NFCT_SENSRES_BIT_FRAME_SDD_10000 = - NFCT_SENSRES_BITFRAMESDD_SDD10000 << NFCT_SENSRES_BITFRAMESDD_Pos /**< SDD pattern 10000. */ -} nrf_nfct_sensres_bit_frame_sdd_t; - -/** - * @brief 'Platofrm Config' NFC field configuration for the SENS_RES frame according to the NFC - * Forum Digital Protocol Technical Specification. - */ -typedef enum -{ - /**< SENS_RES 'Platform Config' field (b4-b1) value for Type 1 Tag platform. */ - NRF_NFCT_SENSRES_PLATFORM_CONFIG_T1T = 6 << NFCT_SENSRES_PLATFCONFIG_Pos, - /**< SENS_RES 'Platform Config' field (b7-b6) value for any platform except Type 1 Tag platform. */ - NRF_NFCT_SENSRES_PLATFORM_CONFIG_OTHER = 0 << NFCT_SENSRES_PLATFCONFIG_Pos -} nrf_nfct_sensres_platform_config_t; - -/** @brief Bit masks for SEL_RES NFC frame configuration. */ -typedef enum -{ - NRF_NFCT_SELRES_CASCADE_MASK = NFCT_SELRES_CASCADE_Msk, /**< SEL_RES Cascade field bit mask. */ - NRF_NFCT_SELRES_PROTOCOL_MASK = NFCT_SELRES_PROTOCOL_Msk /**< SEL_RES Protocol field bit mask. */ -} nrf_nfct_selres_t; - -/** - * @brief Protocol NFC field (bits b7 and b6) configuration for the SEL_RES frame according to - * the NFC Forum Digital Protocol Technical Specification. - */ -typedef enum -{ - NRF_NFCT_SELRES_PROTOCOL_T2T = 0, /**< Type 2 Tag platform. */ - NRF_NFCT_SELRES_PROTOCOL_T4AT = 1, /**< Type 4A Tag platform. */ - NRF_NFCT_SELRES_PROTOCOL_NFCDEP = 2, /**< NFC-DEP Protocol. */ - NRF_NFCT_SELRES_PROTOCOL_NFCDEP_T4AT = 3, /**< NFC-DEP Protocol and Type 4A Tag platform). */ -} nrf_nfct_selres_protocol_t; - -/** - * @brief Function for activating a specific NFCT task. - * - * @param[in] task Task to be activated. - */ -__STATIC_INLINE void nrf_nfct_task_trigger(nrf_nfct_task_t task); - -/** - * @brief Function for returning the address of a specific NFCT task register. - * - * @param[in] task Task. - * - * @return Task address. - */ -__STATIC_INLINE uint32_t nrf_nfct_task_address_get(nrf_nfct_task_t task); - -/** - * @brief Function for clearing a specific event. - * - * @param[in] event Event. - */ -__STATIC_INLINE void nrf_nfct_event_clear(nrf_nfct_event_t event); - -/** - * @brief Function for retrieving the state of the NFCT event. - * - * @param[in] event Event to be checked. - * - * @retval true The event has been generated. - * @retval false The event has not been generated. - */ -__STATIC_INLINE bool nrf_nfct_event_check(nrf_nfct_event_t event); - -/** - * @brief Function for returning the address of a specific NFCT event register. - * - * @param[in] event Event. - * - * @return Address. - */ -__STATIC_INLINE uint32_t nrf_nfct_event_address_get(nrf_nfct_event_t event); - -/** - * @brief Function for enabling selected shortcuts. - * - * @param[in] short_mask Mask of shortcuts. - */ -__STATIC_INLINE void nrf_nfct_shorts_enable(uint32_t short_mask); - -/** - * @brief Function for disabling selected shortcuts. - * - * @param[in] short_mask Mask of shortcuts. - */ -__STATIC_INLINE void nrf_nfct_shorts_disable(uint32_t short_mask); - -/** - * @brief Function for retrieving the enabled shortcuts. - * - * @return Flags of the currently enabled shortcuts. - */ -__STATIC_INLINE uint32_t nrf_nfct_shorts_get(void); - -/** - * @brief Function for setting shortcuts. - * - * @param[in] short_mask Shortcut mask. - */ -__STATIC_INLINE void nrf_nfct_shorts_set(uint32_t short_mask); - -/** - * @brief Function for enabling the selected interrupts. - * - * @param[in] int_mask Interrupt mask. - */ -__STATIC_INLINE void nrf_nfct_int_enable(uint32_t int_mask); - -/** - * @brief Function for retrieving the state of the selected interrupts. - * - * @param[in] int_mask Interrupt mask. - * - * @retval true Any of the selected interrupts is enabled. - * @retval false None of the selected interrupts is enabled. - */ -__STATIC_INLINE bool nrf_nfct_int_enable_check(uint32_t int_mask); - -/** - * @brief Function for retrieving the information about enabled interrupts. - * - * @return The flags of the enabled interrupts. - */ -__STATIC_INLINE uint32_t nrf_nfct_int_enable_get(void); - -/** - * @brief Function for disabling the selected interrupts. - * - * @param[in] int_mask Interrupt mask. - */ -__STATIC_INLINE void nrf_nfct_int_disable(uint32_t int_mask); - -/** - * @brief Function for getting the NFCT error status. - * - * @return The NFCT error status flags, defined in @ref nrf_nfct_error_status_t. - */ -__STATIC_INLINE uint32_t nrf_nfct_error_status_get(void); - -/** - * @brief Function for clearing the NFCT error status. - * - * @param[in] error_flag Error flags to be cleared, defined in @ref nrf_nfct_error_status_t. - */ -__STATIC_INLINE void nrf_nfct_error_status_clear(uint32_t error_flag); - -/** - * @brief Function for getting the NFC frame reception status. - * - * @return The flags of the NFC frame reception status, defined in @ref nrf_nfct_rx_frame_status_t. - */ -__STATIC_INLINE uint32_t nrf_nfct_rx_frame_status_get(void); - -/** - * @brief Function for clearing the NFC frame reception status. - * - * @param[in] framestatus_flags Status flags to be cleared, defined in - * @ref nrf_nfct_rx_frame_status_t. - */ -__STATIC_INLINE void nrf_nfct_rx_frame_status_clear(uint32_t framestatus_flags); - -#if defined(NFCT_NFCTAGSTATE_NFCTAGSTATE_Msk) || defined(__NRFX_DOXYGEN__) -/** - * @brief Function for getting the NFC tag state. - * - * @retval NRF_NFCT_TAG_STATE_DISABLED NFC tag is disabled. - * @retval NRF_NFCT_TAG_STATE_RAMP_UP NFC tag is ramping up. - * @retval NRF_NFCT_TAG_STATE_IDLE NFC tag is activated and idle. - * @retval NRF_NFCT_TAG_STATE_RECEIVE NFC tag is receiving data. - * @retval NRF_NFCT_TAG_STATE_FRAME_DELAY Frame Delay Timer of the NFC tag is counting ticks - * since the last symbol of the last received frame. - * @retval NRF_NFCT_TAG_STATE_TRANSMIT NFC tag is transmitting data. - */ -__STATIC_INLINE nrf_nfct_tag_state_t nrf_nfct_tag_state_get(void); -#endif // defined(NFCT_NFCTAGSTATE_NFCTAGSTATE_Msk) || defined(__NRFX_DOXYGEN__) - -#if defined (NFCT_SLEEPSTATE_SLEEPSTATE_Msk) || defined(__NRFX_DOXYGEN__) -/** - * @brief Function for getting the NFC tag sleep state during the automatic collision resolution. - * - * @details The returned value is the last state before the autimatic collision resolution started. - * - * @retval NRF_NFCT_SLEEP_STATE_IDLE NFC tag was in IDLE state before the automatic - * collision resolution started. - * @retval NRF_NFCT_SLEEP_STATE_SLEEP_A NFC tag was in SLEEP_A state before the automatic - * collision resolution started. - */ -__STATIC_INLINE nrf_nfct_sleep_state_t nrf_nfct_sleep_state_get(void); -#endif // defined (NFCT_SLEEPSTATE_SLEEPSTATE_Msk) || defined(__NRFX_DOXYGEN__) - -/** - * @brief Function for getting the status of the external NFC field detection. - * - * @return The NFC field detection status. Status bits can be checked by using - * @ref nrf_nfct_field_state_t. - */ -__STATIC_INLINE uint8_t nrf_nfct_field_status_get(void); - -/** - * @brief Function for getting the minimum Frame Delay Time value. - * - * @details This is the minimum value for Frame Delay Timer. It controls the shortest time between - * the last symbol of the last received frame and the start of the transmission of a new - * TX frame. - * - * @return The minimum Frame Delay Time value in 13.56-MHz clock ticks. - */ -__STATIC_INLINE uint16_t nrf_nfct_frame_delay_min_get(void); - -/** - * @brief Function for setting the minimum Frame Delay Time value. - * - * @details This is the minimum value for Frame Delay Timer. It controls the shortest time between - * the last symbol of the last received frame and the start of the transmission of a new - * TX frame. - * - * @param[in] frame_delay_min Minimum Frame Delay Time value in 13.56-MHz clock ticks. - */ -__STATIC_INLINE void nrf_nfct_frame_delay_min_set(uint16_t frame_delay_min); - -/** - * @brief Function for getting the maximum Frame Delay Time value. - * - * @details This is the maximum value for Frame Delay Timer. It controls the longest time between - * the last symbol of the last received frame and the start of the transmission of a new - * TX frame. If no transmission starts before the Frame Delay Timer timeout, - * @ref NRF_NFCT_ERROR_FRAMEDELAYTIMEOUT_MASK is set. - * - * @return The maximum Frame Delay Time value in 13.56-MHz clock ticks. - */ -__STATIC_INLINE uint32_t nrf_nfct_frame_delay_max_get(void); - -/** - * @brief Function for setting the maximum Frame Delay Time value. - * - * @details This is the maximum value for Frame Delay Timer. It controls the longest time between - * the last symbol of the last received frame and the start of the transmission of a new - * TX frame. If no transmission starts before the Frame Delay Timer timeout, - * @ref NRF_NFCT_ERROR_FRAMEDELAYTIMEOUT_MASK is set. - * - * @param[in] frame_delay_max Maximum Frame Delay Time value in 13.56-MHz clock ticks. - */ -__STATIC_INLINE void nrf_nfct_frame_delay_max_set(uint32_t frame_delay_max); - -/** - * @brief Function for getting the Frame Delay Mode configuration. - * - * @return The configured Frame Delay Mode. - */ -__STATIC_INLINE nrf_nfct_frame_delay_mode_t nrf_nfct_frame_delay_mode_get(void); - -/** - * @brief Function for setting the NFC Frame Delay Mode configuration. - * - * @param[in] frame_delay_mode Frame Delay Mode configuration. - */ -__STATIC_INLINE void nrf_nfct_frame_delay_mode_set(nrf_nfct_frame_delay_mode_t frame_delay_mode); - -/** - * @brief Function for getting the pointer to the NFCT RX/TX buffer. - * - * @return The configured pointer to the receive or transmit buffer. - */ -__STATIC_INLINE uint8_t * nrf_nfct_rxtx_buffer_get(void); - -/** - * @brief Function for setting the the NFCT RX/TX buffer (address and maximum length). - * - * @note Buffer for the NFC RX/TX data is used by EasyDMA and must be located in RAM. - * - * @param[in] p_rxtx_buf Pointer to the receive or transmit buffer. - * @param[in] max_txrx_len Maximum receive or transmit length in bytes (size of the RAM - * buffer for EasyDMA). - */ -__STATIC_INLINE void nrf_nfct_rxtx_buffer_set(uint8_t * p_rxtx_buf, - uint16_t max_txrx_len); - -/** - * @brief Function for getting the NFCT RX/TX maximum buffer length. - * - * @return The configured maximum receive or transmit length in bytes (size of the RX/TX - * buffer for EasyDMA). - */ -__STATIC_INLINE uint16_t nrf_nfct_max_rxtx_length_get(void); - -/** - * @brief Function for getting the flags for NFC frame transmission configuration. - * - * @return The flags of the NFCT frame transmission configuration, defined in - * @ref nrf_nfct_tx_frame_config_t. - */ -__STATIC_INLINE uint8_t nrf_nfct_tx_frame_config_get(void); - -/** - * @brief Function for setting up the flags of the NFC frame transmission configuration. - * - * @param[in] flags Flags for NFCT TX configuration. Use @ref nrf_nfct_tx_frame_config_t for - * setting. - */ -__STATIC_INLINE void nrf_nfct_tx_frame_config_set(uint8_t flags); - -/** - * @brief Function for getting the length of the configured transmission frame. - * - * @note NFC frames do not have to consist of full bytes only, therefore data amount - * for transmission is configured in number of bits. - * - * @return Number of bits to be sent excluding CRC, parity, SoF, and EoF. - */ -__STATIC_INLINE uint16_t nrf_nfct_tx_bits_get(void); - -/** - * @brief Function for setting up the NFC frame transmission. - * - * @details Set the number of TX bits excluding CRC, parity, SoF, and EoF. - * - * @note Source of data for transmission is set by using @ref nrf_nfct_rxtx_buffer_set. - * @note NFC frames do not have to consist of full bytes only, therefore data amount - * for transmission is configured in number of bits. - * - * @param[in] tx_bits Overall number of bits to be sent. - */ -__STATIC_INLINE void nrf_nfct_tx_bits_set(uint16_t tx_bits); - -/** - * @brief Function for getting the flags of the NFC frame reception configuration. - * - * @return The flags for NFCT frame reception configuration, defined in - * @ref nrf_nfct_rx_frame_config_t. - */ -__STATIC_INLINE uint8_t nrf_nfct_rx_frame_config_get(void); - -/** - * @brief Function for setting up the NFC frame reception. - * - * @note Destination for the received data is set using @ref nrf_nfct_rxtx_buffer_set. - * - * @param[in] flags NFCT RX configuration flags. Use @ref nrf_nfct_rx_frame_config_t for setting - * the desired configuration. - */ -__STATIC_INLINE void nrf_nfct_rx_frame_config_set(uint8_t flags); - -/** - * @brief Function for getting the number of bits received from the NFC poller. - * - * @param[in] crc_excluded Flag for excluding CRC size from calculation. - * - * @return Number of received bits including or excluding CRC, and excluding parity - * and SoF/EoF framing. - */ -__STATIC_INLINE uint16_t nrf_nfct_rx_bits_get(bool crc_excluded); - -/** - * @brief Function for getting the NFCID1 (NFC tag identifier). - * - * @note This function always returns the full configuration of the NFCID1 setting (10 bytes), - * regardless of the NFCID1 size. The NFCID1 size can be configured using - * @ref nrf_nfct_sensres_nfcid1_size_set or @ref nrf_nfct_nfcid1_set. - * - * @param[out] p_nfcid1_buf Pointer to a buffer for the NDFCID1 parameter. - * The NFCID1 values are in little endian order, - * that is: |NFCID1_3RD_LAST|NFCID1_2ND_LAST|NFCID1_LAST|. - * - * @return Configured NFCID1 length - */ -__STATIC_INLINE nrf_nfct_sensres_nfcid1_size_t nrf_nfct_nfcid1_get(uint8_t * p_nfcid1_buf); - -/** - * @brief Function for setting the NFCID1 (NFC tag identifier). - * - * @note This function also configures the NFCIDSIZE field in the SENSRES - * register of the NRF_NFCT peripheral. - * - * @param[in] p_nfcid1_buf Pointer to the buffer with NDFCID1 bytes. - * @param[in] nfcid1_size Size of the NFCID1 in bytes. - */ -__STATIC_INLINE void nrf_nfct_nfcid1_set(uint8_t const * p_nfcid1_buf, - nrf_nfct_sensres_nfcid1_size_t nfcid1_size); - -#if defined (NFCT_AUTOCOLRESCONFIG_MODE_Msk) || defined(__NRFX_DOXYGEN__) -/** - * @brief Function for getting the setting for the automatic collision resolution. - * - * @details The automatic collision resolution mechanism as defined in ISO 14443-3 and NFC Forum - * Digital Protocol Technical Specification 2.0, section 6. - * - * @retval true If automatic collision resolution is enabled. - * @retval false If automatic collision resolution is disabled. - */ -__STATIC_INLINE bool nrf_nfct_autocolres_is_enabled(void); - -/** - * @brief Function for enabling the automatic collision resolution. - * - * @details The automatic collision resolution mechanism as defined in ISO 14443-3 and NFC Forum - * Digital Protocol Technical Specification 2.0, section 6. - */ -__STATIC_INLINE void nrf_nfct_autocolres_enable(void); - -/** - * @brief Function for disabling the automatic collision resolution. - * - * @details The automatic collision resolution mechanism as defined in ISO 14443-3 and NFC Forum - * Digital Protocol Technical Specification 2.0, section 6. - */ -__STATIC_INLINE void nrf_nfct_autocolres_disable(void); -#endif // defined (NFCT_AUTOCOLRESCONFIG_MODE_Msk) || defined(__NRFX_DOXYGEN__) - -/** - * @brief Function for getting the NFCID1 size from the SENS_RES frame configuration. - * - * @details The SENS_RES frame is handled automatically by the NFCT hardware. - * - * @return NFCID1 (tag identifier) size. - */ -__STATIC_INLINE nrf_nfct_sensres_nfcid1_size_t nrf_nfct_sensres_nfcid1_size_get(void); - -/** - * @brief Function for setting the NFCID1 (tag identifier) size.field in the SENS_RES frame - * configuration. - * - * @note The SENS_RES frame is handled automatically by the NFCT hardware. - * - * @param[in] nfcid1_size NFCID1 (tag identifier) size. - * - * @sa nrf_nfct_nfcid1_set() - */ -__STATIC_INLINE void nrf_nfct_sensres_nfcid1_size_set(nrf_nfct_sensres_nfcid1_size_t nfcid1_size); - -/** - * @brief Function for getting the Bit Frame SDD field from the SENS_RES frame configuration. - * - * @details The SENS_RES frame is handled automatically by the NFCT hardware. - * - * @return The Bit Frame SDD field configuration. - */ -__STATIC_INLINE nrf_nfct_sensres_bit_frame_sdd_t nrf_nfct_sensres_bit_frame_sdd_get(void); - -/** - * @brief Function for setting the Bit Frame SDD field in the SENS_RES frame configuration. - * - * @note The SENS_RES frame is handled automatically by the NFCT hardware. - * - * @param[in] bit_frame_sdd The Bit Frame SDD field configuration. - */ -__STATIC_INLINE void nrf_nfct_sensres_bit_frame_sdd_set(nrf_nfct_sensres_bit_frame_sdd_t bit_frame_sdd); - -/** - * @brief Function for getting the Platform Config field from the SENS_RES frame configuration. - * - * @details The SENS_RES frame is handled automatically by the NFCT hardware. - * - * @return The Platform Config field configuration. - */ -__STATIC_INLINE nrf_nfct_sensres_platform_config_t nrf_nfct_sensres_platform_config_get(void); - -/** - * @brief Function for setting the Platform Config field in the SENS_RES frame configuration. - * - * @note The SENS_RES frame is handled automatically by the NFCT hardware. - * - * @param[in] platform_config The Platform Config field configuration. - */ -__STATIC_INLINE void nrf_nfct_sensres_platform_config_set(nrf_nfct_sensres_platform_config_t platform_config); - -/** - * @brief Function for checking the CASCADE bit of the SEL_RES frame. - * - * @details The CASCADE bit in the SEL_RES register is handled automatically by the NFCT hardware - * and indicates the status of the NFCID1 read operation to the NFC poller according to - * the NFC Forum Digital Protocol Speficiation 2.0, section 6.8.2. - * - * @retval true If NFCID1 read procedure is not complete. - * @retval false If NFCID1 read procedure is complete. - */ -__STATIC_INLINE bool nrf_nfct_selsres_cascade_check(void); - -/** - * @brief Function for getting the Protocol field in the SEL_RES frame. - * - * @details The SEL_RES frame is handled automatically by the NFCT hardware. - * - * @return Value of the Protocol field in the SEL_RES frame. - */ -__STATIC_INLINE nrf_nfct_selres_protocol_t nrf_nfct_selsres_protocol_get(void); - -/** - * @brief Function for setting the Protocol field in the SEL_RES frame configuration. - * - * @details The SEL_RES frame is handled automatically by the NFCT hardware. - * - * @param[in] sel_res_protocol Value of the Protocol field in the SEL_RES frame. - */ -__STATIC_INLINE void nrf_nfct_selres_protocol_set(nrf_nfct_selres_protocol_t sel_res_protocol); - -#ifndef SUPPRESS_INLINE_IMPLEMENTATION -__STATIC_INLINE void nrf_nfct_task_trigger(nrf_nfct_task_t task) -{ - *((volatile uint32_t *)((uint8_t *)NRF_NFCT + (uint32_t)task)) = 1UL; -} - -__STATIC_INLINE uint32_t nrf_nfct_task_address_get(nrf_nfct_task_t task) -{ - return (uint32_t)((uint8_t *)NRF_NFCT + (uint32_t)task); -} - -__STATIC_INLINE void nrf_nfct_event_clear(nrf_nfct_event_t event) -{ - *((volatile uint32_t *)((uint8_t *)NRF_NFCT + (uint32_t)event)) = 0UL; - __DSB(); -} - -__STATIC_INLINE bool nrf_nfct_event_check(nrf_nfct_event_t event) -{ - return (bool)*(volatile const uint32_t *)((uint8_t *)NRF_NFCT + (uint32_t)event); -} - -__STATIC_INLINE uint32_t nrf_nfct_event_address_get(nrf_nfct_event_t event) -{ - return (uint32_t)((uint8_t *)NRF_NFCT + (uint32_t)event); -} - -__STATIC_INLINE void nrf_nfct_shorts_enable(uint32_t short_mask) -{ - NRF_NFCT->SHORTS |= short_mask; -} - -__STATIC_INLINE void nrf_nfct_shorts_disable(uint32_t short_mask) -{ - NRF_NFCT->SHORTS &= ~short_mask; -} - -__STATIC_INLINE uint32_t nrf_nfct_shorts_get(void) -{ - return NRF_NFCT->SHORTS; -} - -__STATIC_INLINE void nrf_nfct_shorts_set(uint32_t short_mask) -{ - NRF_NFCT->SHORTS = short_mask; -} - -__STATIC_INLINE void nrf_nfct_int_enable(uint32_t int_mask) -{ - NRF_NFCT->INTENSET = int_mask; -} - -__STATIC_INLINE bool nrf_nfct_int_enable_check(uint32_t int_mask) -{ - return (bool)(NRF_NFCT->INTENSET & int_mask); -} - -__STATIC_INLINE uint32_t nrf_nfct_int_enable_get(void) -{ - return NRF_NFCT->INTENSET; -} - -__STATIC_INLINE void nrf_nfct_int_disable(uint32_t int_mask) -{ - NRF_NFCT->INTENCLR = int_mask; -} - -__STATIC_INLINE uint32_t nrf_nfct_error_status_get(void) -{ - return NRF_NFCT->ERRORSTATUS; -} - -__STATIC_INLINE void nrf_nfct_error_status_clear(uint32_t error_flags) -{ - NRF_NFCT->ERRORSTATUS = error_flags; -} - -__STATIC_INLINE uint32_t nrf_nfct_rx_frame_status_get(void) -{ - return NRF_NFCT->FRAMESTATUS.RX; -} - -__STATIC_INLINE void nrf_nfct_rx_frame_status_clear(uint32_t framestatus_flags) -{ - NRF_NFCT->FRAMESTATUS.RX = framestatus_flags; -} - -#if defined(NFCT_NFCTAGSTATE_NFCTAGSTATE_Msk) || defined(__NRFX_DOXYGEN__) -__STATIC_INLINE nrf_nfct_tag_state_t nrf_nfct_tag_state_get(void) -{ - return (nrf_nfct_tag_state_t)((NRF_NFCT->NFCTAGSTATE & NFCT_NFCTAGSTATE_NFCTAGSTATE_Msk) >> - NFCT_NFCTAGSTATE_NFCTAGSTATE_Pos); -} -#endif // defined(NFCT_NFCTAGSTATE_NFCTAGSTATE_Msk) || defined(__NRFX_DOXYGEN__) - -#if defined (NFCT_SLEEPSTATE_SLEEPSTATE_Msk) || defined(__NRFX_DOXYGEN__) -__STATIC_INLINE nrf_nfct_sleep_state_t nrf_nfct_sleep_state_get(void) -{ - return (nrf_nfct_sleep_state_t)((NRF_NFCT->SLEEPSTATE & NFCT_SLEEPSTATE_SLEEPSTATE_Msk) >> - NFCT_SLEEPSTATE_SLEEPSTATE_Pos); -} -#endif // defined (NFCT_SLEEPSTATE_SLEEPSTATE_Msk) || defined(__NRFX_DOXYGEN__) - -__STATIC_INLINE uint8_t nrf_nfct_field_status_get(void) -{ - return (uint8_t)(NRF_NFCT->FIELDPRESENT); -} - -__STATIC_INLINE uint16_t nrf_nfct_frame_delay_min_get(void) -{ - return (uint16_t)((NRF_NFCT->FRAMEDELAYMIN & NFCT_FRAMEDELAYMIN_FRAMEDELAYMIN_Msk) >> - NFCT_FRAMEDELAYMIN_FRAMEDELAYMIN_Pos); -} - -__STATIC_INLINE void nrf_nfct_frame_delay_min_set(uint16_t frame_delay_min) -{ - NRF_NFCT->FRAMEDELAYMIN = - ((uint32_t)frame_delay_min << NFCT_FRAMEDELAYMIN_FRAMEDELAYMIN_Pos) & - NFCT_FRAMEDELAYMIN_FRAMEDELAYMIN_Msk; -} - -__STATIC_INLINE uint32_t nrf_nfct_frame_delay_max_get(void) -{ - return (NRF_NFCT->FRAMEDELAYMAX & NFCT_FRAMEDELAYMAX_FRAMEDELAYMAX_Msk) >> - NFCT_FRAMEDELAYMAX_FRAMEDELAYMAX_Pos; -} - -__STATIC_INLINE void nrf_nfct_frame_delay_max_set(uint32_t frame_delay_max) -{ - NRF_NFCT->FRAMEDELAYMAX = - ((uint32_t)frame_delay_max << NFCT_FRAMEDELAYMAX_FRAMEDELAYMAX_Pos) & - NFCT_FRAMEDELAYMAX_FRAMEDELAYMAX_Msk; -} - -__STATIC_INLINE nrf_nfct_frame_delay_mode_t nrf_nfct_frame_delay_mode_get(void) -{ - return (nrf_nfct_frame_delay_mode_t)(NRF_NFCT->FRAMEDELAYMODE & - NFCT_FRAMEDELAYMODE_FRAMEDELAYMODE_Msk); -} - -__STATIC_INLINE void nrf_nfct_frame_delay_mode_set(nrf_nfct_frame_delay_mode_t frame_delay_mode) -{ - NRF_NFCT->FRAMEDELAYMODE = (uint32_t)frame_delay_mode; -} - -__STATIC_INLINE uint8_t * nrf_nfct_rxtx_buffer_get(void) -{ - return (uint8_t *)(NRF_NFCT->PACKETPTR); -} - -__STATIC_INLINE void nrf_nfct_rxtx_buffer_set(uint8_t * p_rxtx_buf, - uint16_t max_txrx_len) -{ - NRF_NFCT->PACKETPTR = (uint32_t)p_rxtx_buf; - NRF_NFCT->MAXLEN = ((uint32_t)max_txrx_len << NFCT_MAXLEN_MAXLEN_Pos) & - NFCT_MAXLEN_MAXLEN_Msk; -} - -__STATIC_INLINE uint16_t nrf_nfct_max_rxtx_length_get(void) -{ - return (uint16_t)((NRF_NFCT->MAXLEN & NFCT_MAXLEN_MAXLEN_Msk) >> NFCT_MAXLEN_MAXLEN_Pos); -} - -__STATIC_INLINE uint8_t nrf_nfct_tx_frame_config_get(void) -{ - return (uint8_t)(NRF_NFCT->TXD.FRAMECONFIG); -} - -__STATIC_INLINE void nrf_nfct_tx_frame_config_set(uint8_t flags) -{ - NRF_NFCT->TXD.FRAMECONFIG = flags; -} - -__STATIC_INLINE uint16_t nrf_nfct_tx_bits_get(void) -{ - return (uint16_t)(NRF_NFCT->TXD.AMOUNT & (NFCT_TXD_AMOUNT_TXDATABITS_Msk | - NFCT_TXD_AMOUNT_TXDATABYTES_Msk)); -} - -__STATIC_INLINE void nrf_nfct_tx_bits_set(uint16_t tx_bits) -{ - NRF_NFCT->TXD.AMOUNT = (tx_bits & (NFCT_TXD_AMOUNT_TXDATABITS_Msk | NFCT_TXD_AMOUNT_TXDATABYTES_Msk)); -} - -__STATIC_INLINE uint8_t nrf_nfct_rx_frame_config_get(void) -{ - return (uint8_t)(NRF_NFCT->RXD.FRAMECONFIG); -} - -__STATIC_INLINE void nrf_nfct_rx_frame_config_set(uint8_t flags) -{ - NRF_NFCT->RXD.FRAMECONFIG = flags; -} - -__STATIC_INLINE uint16_t nrf_nfct_rx_bits_get(bool crc_excluded) -{ - uint16_t rx_bits = NRF_NFCT->RXD.AMOUNT & (NFCT_RXD_AMOUNT_RXDATABITS_Msk | - NFCT_RXD_AMOUNT_RXDATABYTES_Msk); - return rx_bits - (crc_excluded ? (8u * NRF_NFCT_CRC_SIZE) : 0); -} - -__STATIC_INLINE nrf_nfct_sensres_nfcid1_size_t nrf_nfct_nfcid1_get(uint8_t * p_nfcid1_buf) -{ - uint32_t nfcid1_last = NRF_NFCT->NFCID1_LAST; - nrf_nfct_sensres_nfcid1_size_t size = - (nrf_nfct_sensres_nfcid1_size_t)(NRF_NFCT->SENSRES & NFCT_SENSRES_NFCIDSIZE_Msk); - - if (size != NRF_NFCT_SENSRES_NFCID1_SIZE_SINGLE) - { - uint32_t nfcid1_2nd_last = NRF_NFCT->NFCID1_2ND_LAST; - - if (size == NRF_NFCT_SENSRES_NFCID1_SIZE_TRIPLE) - { - uint32_t nfcid1_3rd_last = NRF_NFCT->NFCID1_3RD_LAST; - - *p_nfcid1_buf++ = (uint8_t)(nfcid1_3rd_last >> 16UL); - *p_nfcid1_buf++ = (uint8_t)(nfcid1_3rd_last >> 8UL); - *p_nfcid1_buf++ = (uint8_t)(nfcid1_3rd_last >> 0UL); - } - - *p_nfcid1_buf++ = (uint8_t)(nfcid1_2nd_last >> 16UL); - *p_nfcid1_buf++ = (uint8_t)(nfcid1_2nd_last >> 8UL); - *p_nfcid1_buf++ = (uint8_t)(nfcid1_2nd_last >> 0UL); - } - - *p_nfcid1_buf++ = (uint8_t)(nfcid1_last >> 24UL); - *p_nfcid1_buf++ = (uint8_t)(nfcid1_last >> 16UL); - *p_nfcid1_buf++ = (uint8_t)(nfcid1_last >> 8UL); - *p_nfcid1_buf++ = (uint8_t)(nfcid1_last >> 0UL); - - return size; -} - -__STATIC_INLINE void nrf_nfct_nfcid1_set(uint8_t const * p_nfcid1_buf, - nrf_nfct_sensres_nfcid1_size_t nfcid1_size) -{ - nrf_nfct_sensres_nfcid1_size_t size = (nfcid1_size == NRF_NFCT_SENSRES_NFCID1_SIZE_DEFAULT) ? - NRF_NFCT_SENSRES_NFCID1_SIZE_DOUBLE : nfcid1_size; - - if (size != NRF_NFCT_SENSRES_NFCID1_SIZE_SINGLE) - { - if (size == NRF_NFCT_SENSRES_NFCID1_SIZE_TRIPLE) - { - NRF_NFCT->NFCID1_3RD_LAST = ((uint32_t)p_nfcid1_buf[0] << 16UL) | - ((uint32_t)p_nfcid1_buf[1] << 8UL) | - ((uint32_t)p_nfcid1_buf[2] << 0UL); - p_nfcid1_buf += 3UL; - } - NRF_NFCT->NFCID1_2ND_LAST = ((uint32_t)p_nfcid1_buf[0] << 16UL) | - ((uint32_t)p_nfcid1_buf[1] << 8UL) | - ((uint32_t)p_nfcid1_buf[2] << 0UL); - p_nfcid1_buf += 3UL; - } - - NRF_NFCT->NFCID1_LAST = ((uint32_t)p_nfcid1_buf[0] << 24UL) | - ((uint32_t)p_nfcid1_buf[1] << 16UL) | - ((uint32_t)p_nfcid1_buf[2] << 8UL) | - ((uint32_t)p_nfcid1_buf[3] << 0UL); - - NRF_NFCT->SENSRES = ((NRF_NFCT->SENSRES & ~NFCT_SENSRES_NFCIDSIZE_Msk) | - (uint32_t)size); -} - -#if defined (NFCT_AUTOCOLRESCONFIG_MODE_Msk) || defined(__NRFX_DOXYGEN__) -__STATIC_INLINE bool nrf_nfct_autocolres_is_enabled(void) -{ - return (NRF_NFCT->AUTOCOLRESCONFIG & NFCT_AUTOCOLRESCONFIG_MODE_Msk) == - (NFCT_AUTOCOLRESCONFIG_MODE_Enabled << NFCT_AUTOCOLRESCONFIG_MODE_Pos); -} - -__STATIC_INLINE void nrf_nfct_autocolres_enable(void) -{ - NRF_NFCT->AUTOCOLRESCONFIG = - (NRF_NFCT->AUTOCOLRESCONFIG & ~NFCT_AUTOCOLRESCONFIG_MODE_Msk) | - (NFCT_AUTOCOLRESCONFIG_MODE_Enabled << NFCT_AUTOCOLRESCONFIG_MODE_Pos); -} - -__STATIC_INLINE void nrf_nfct_autocolres_disable(void) -{ - NRF_NFCT->AUTOCOLRESCONFIG = - (NRF_NFCT->AUTOCOLRESCONFIG & ~NFCT_AUTOCOLRESCONFIG_MODE_Msk) | - (NFCT_AUTOCOLRESCONFIG_MODE_Disabled << NFCT_AUTOCOLRESCONFIG_MODE_Pos); -} -#endif // defined (NFCT_AUTOCOLRESCONFIG_MODE_Msk) || defined(__NRFX_DOXYGEN__) - -__STATIC_INLINE nrf_nfct_sensres_nfcid1_size_t nrf_nfct_sensres_nfcid1_size_get(void) -{ - return (nrf_nfct_sensres_nfcid1_size_t)(NRF_NFCT->SENSRES & NFCT_SENSRES_NFCIDSIZE_Msk); -} - -__STATIC_INLINE void nrf_nfct_sensres_nfcid1_size_set(nrf_nfct_sensres_nfcid1_size_t nfcid1_size) -{ - NRF_NFCT->SENSRES = ((NRF_NFCT->SENSRES & ~(NFCT_SENSRES_NFCIDSIZE_Msk)) | (uint32_t)nfcid1_size); -} - -__STATIC_INLINE nrf_nfct_sensres_bit_frame_sdd_t nrf_nfct_sensres_bit_frame_sdd_get(void) -{ - return (nrf_nfct_sensres_bit_frame_sdd_t)(NRF_NFCT->SENSRES & NFCT_SENSRES_BITFRAMESDD_Msk); -} - -__STATIC_INLINE void nrf_nfct_sensres_bit_frame_sdd_set(nrf_nfct_sensres_bit_frame_sdd_t bit_frame_sdd) -{ - NRF_NFCT->SENSRES = ((NRF_NFCT->SENSRES & ~(NFCT_SENSRES_BITFRAMESDD_Msk)) | (uint32_t)bit_frame_sdd); -} - -__STATIC_INLINE nrf_nfct_sensres_platform_config_t nrf_nfct_sensres_platform_config_get(void) -{ - return (nrf_nfct_sensres_platform_config_t)(NRF_NFCT->SENSRES & NFCT_SENSRES_PLATFCONFIG_Msk); -} - -__STATIC_INLINE void nrf_nfct_sensres_platform_config_set(nrf_nfct_sensres_platform_config_t platform_config) -{ - NRF_NFCT->SENSRES = ((NRF_NFCT->SENSRES & ~(NFCT_SENSRES_PLATFCONFIG_Msk)) | (uint32_t)platform_config); -} - -__STATIC_INLINE bool nrf_nfct_selsres_cascade_check(void) -{ - return (bool)(NRF_NFCT->SELRES & NFCT_SELRES_CASCADE_Msk); -} - -__STATIC_INLINE nrf_nfct_selres_protocol_t nrf_nfct_selsres_protocol_get(void) -{ - return (nrf_nfct_selres_protocol_t)((NRF_NFCT->SELRES & NFCT_SELRES_PROTOCOL_Msk) >> - NFCT_SELRES_PROTOCOL_Pos); -} - -__STATIC_INLINE void nrf_nfct_selres_protocol_set(nrf_nfct_selres_protocol_t sel_res_protocol) -{ - NRF_NFCT->SELRES = (NRF_NFCT->SELRES & ~NFCT_SELRES_PROTOCOL_Msk) | - ((uint32_t)sel_res_protocol << NFCT_SELRES_PROTOCOL_Pos); -} -#endif /* SUPPRESS_INLINE_IMPLEMENTATION */ - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif /* NRF_NFCT_H__ */ diff --git a/modules/nrfx/hal/nrf_pdm.h b/modules/nrfx/hal/nrf_pdm.h deleted file mode 100644 index 6c2a75b..0000000 --- a/modules/nrfx/hal/nrf_pdm.h +++ /dev/null @@ -1,464 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ -#ifndef NRF_PDM_H_ -#define NRF_PDM_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_pdm_hal PDM HAL - * @{ - * @ingroup nrf_pdm - * @brief Hardware access layer for managing the Pulse Density Modulation (PDM) peripheral. - */ - -/** @brief Minimum value of PDM gain. */ -#define NRF_PDM_GAIN_MINIMUM 0x00 -/** @brief Default value of PDM gain. */ -#define NRF_PDM_GAIN_DEFAULT 0x28 -/** @brief Maximum value of PDM gain. */ -#define NRF_PDM_GAIN_MAXIMUM 0x50 - - -/** @brief PDM gain type. */ -typedef uint8_t nrf_pdm_gain_t; - -/** @brief PDM tasks. */ -typedef enum -{ - NRF_PDM_TASK_START = offsetof(NRF_PDM_Type, TASKS_START), ///< Starts continuous PDM transfer. - NRF_PDM_TASK_STOP = offsetof(NRF_PDM_Type, TASKS_STOP) ///< Stops PDM transfer. -} nrf_pdm_task_t; - -/** @brief PDM events. */ -typedef enum -{ - NRF_PDM_EVENT_STARTED = offsetof(NRF_PDM_Type, EVENTS_STARTED), ///< PDM transfer is started. - NRF_PDM_EVENT_STOPPED = offsetof(NRF_PDM_Type, EVENTS_STOPPED), ///< PDM transfer is finished. - NRF_PDM_EVENT_END = offsetof(NRF_PDM_Type, EVENTS_END) ///< The PDM has written the last sample specified by SAMPLE.MAXCNT (or the last sample after a STOP task has been received) to Data RAM. -} nrf_pdm_event_t; - -/** @brief PDM interrupt masks. */ -typedef enum -{ - NRF_PDM_INT_STARTED = PDM_INTENSET_STARTED_Msk, ///< Interrupt on EVENTS_STARTED event. - NRF_PDM_INT_STOPPED = PDM_INTENSET_STOPPED_Msk, ///< Interrupt on EVENTS_STOPPED event. - NRF_PDM_INT_END = PDM_INTENSET_END_Msk ///< Interrupt on EVENTS_END event. -} nrf_pdm_int_mask_t; - -/** @brief PDM clock frequency. */ -typedef enum -{ - NRF_PDM_FREQ_1000K = PDM_PDMCLKCTRL_FREQ_1000K, ///< PDM_CLK = 1.000 MHz. - NRF_PDM_FREQ_1032K = PDM_PDMCLKCTRL_FREQ_Default, ///< PDM_CLK = 1.032 MHz. - NRF_PDM_FREQ_1067K = PDM_PDMCLKCTRL_FREQ_1067K ///< PDM_CLK = 1.067 MHz. -} nrf_pdm_freq_t; - -/** @brief PDM operation mode. */ -typedef enum -{ - NRF_PDM_MODE_STEREO = PDM_MODE_OPERATION_Stereo, ///< Sample and store one pair (Left + Right) of 16-bit samples per RAM word. - NRF_PDM_MODE_MONO = PDM_MODE_OPERATION_Mono ///< Sample and store two successive Left samples (16 bit each) per RAM word. -} nrf_pdm_mode_t; - -/** @brief PDM sampling mode. */ -typedef enum -{ - NRF_PDM_EDGE_LEFTFALLING = PDM_MODE_EDGE_LeftFalling, ///< Left (or mono) is sampled on falling edge of PDM_CLK. - NRF_PDM_EDGE_LEFTRISING = PDM_MODE_EDGE_LeftRising ///< Left (or mono) is sampled on rising edge of PDM_CLK. -} nrf_pdm_edge_t; - - -/** - * @brief Function for triggering a PDM task. - * - * @param[in] task PDM task. - */ -__STATIC_INLINE void nrf_pdm_task_trigger(nrf_pdm_task_t task); - -/** - * @brief Function for getting the address of a PDM task register. - * - * @param[in] task PDM task. - * - * @return Address of the specified PDM task. - */ -__STATIC_INLINE uint32_t nrf_pdm_task_address_get(nrf_pdm_task_t task); - -/** - * @brief Function for retrieving the state of the PDM event. - * - * @param[in] event Event to be checked. - * - * @retval true The event has been generated. - * @retval false The event has not been generated. - */ -__STATIC_INLINE bool nrf_pdm_event_check(nrf_pdm_event_t event); - -/** - * @brief Function for clearing a PDM event. - * - * @param[in] event PDM event. - */ -__STATIC_INLINE void nrf_pdm_event_clear(nrf_pdm_event_t event); - -/** - * @brief Function for getting the address of a PDM event register. - * - * @param[in] event PDM event. - * - * @return Address of the specified PDM event. - */ -__STATIC_INLINE volatile uint32_t * nrf_pdm_event_address_get(nrf_pdm_event_t event); - -/** - * @brief Function for enabling PDM interrupts. - * - * @param[in] int_mask Mask of interrupts to be enabled. - */ -__STATIC_INLINE void nrf_pdm_int_enable(uint32_t int_mask); - -/** - * @brief Function for retrieving the state of PDM interrupts. - * - * @param[in] int_mask Mask of interrupts to be checked. - * - * @retval true All specified interrupts are enabled. - * @retval false At least one of the given interrupts is not enabled. - */ -__STATIC_INLINE bool nrf_pdm_int_enable_check(uint32_t int_mask); - -/** - * @brief Function for disabling interrupts. - * - * @param[in] int_mask Mask of interrupts to be disabled. - */ -__STATIC_INLINE void nrf_pdm_int_disable(uint32_t int_mask); - -#if defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__) -/** - * @brief Function for setting the subscribe configuration for a given - * PDM task. - * - * @param[in] task Task for which to set the configuration. - * @param[in] channel Channel through which to subscribe events. - */ -__STATIC_INLINE void nrf_pdm_subscribe_set(nrf_pdm_task_t task, - uint8_t channel); - -/** - * @brief Function for clearing the subscribe configuration for a given - * PDM task. - * - * @param[in] task Task for which to clear the configuration. - */ -__STATIC_INLINE void nrf_pdm_subscribe_clear(nrf_pdm_task_t task); - -/** - * @brief Function for setting the publish configuration for a given - * PDM event. - * - * @param[in] event Event for which to set the configuration. - * @param[in] channel Channel through which to publish the event. - */ -__STATIC_INLINE void nrf_pdm_publish_set(nrf_pdm_event_t event, - uint8_t channel); - -/** - * @brief Function for clearing the publish configuration for a given - * PDM event. - * - * @param[in] event Event for which to clear the configuration. - */ -__STATIC_INLINE void nrf_pdm_publish_clear(nrf_pdm_event_t event); -#endif // defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__) - -/** - * @brief Function for enabling the PDM peripheral. - * - * The PDM peripheral must be enabled before use. - */ -__STATIC_INLINE void nrf_pdm_enable(void); - -/** @brief Function for disabling the PDM peripheral. */ -__STATIC_INLINE void nrf_pdm_disable(void); - -/** - * @brief Function for checking if the PDM peripheral is enabled. - * - * @retval true The PDM peripheral is enabled. - * @retval false The PDM peripheral is not enabled. - */ -__STATIC_INLINE bool nrf_pdm_enable_check(void); - -/** - * @brief Function for setting the PDM operation mode. - * - * @param[in] pdm_mode PDM operation mode. - * @param[in] pdm_edge PDM sampling mode. - */ -__STATIC_INLINE void nrf_pdm_mode_set(nrf_pdm_mode_t pdm_mode, nrf_pdm_edge_t pdm_edge); - -/** - * @brief Function for getting the PDM operation mode. - * - * @param[out] p_pdm_mode PDM operation mode. - * @param[out] p_pdm_edge PDM sampling mode. - */ -__STATIC_INLINE void nrf_pdm_mode_get(nrf_pdm_mode_t * p_pdm_mode, nrf_pdm_edge_t * p_pdm_edge); - -/** - * @brief Function for setting the PDM clock frequency. - * - * @param[in] pdm_freq PDM clock frequency. - */ -__STATIC_INLINE void nrf_pdm_clock_set(nrf_pdm_freq_t pdm_freq); - -/** - * @brief Function for getting the PDM clock frequency. - * - * @return PDM clock frequency. - */ -__STATIC_INLINE nrf_pdm_freq_t nrf_pdm_clock_get(void); - -/** - * @brief Function for setting up the PDM pins. - * - * @param[in] psel_clk CLK pin number. - * @param[in] psel_din DIN pin number. - */ -__STATIC_INLINE void nrf_pdm_psel_connect(uint32_t psel_clk, uint32_t psel_din); - -/** @brief Function for disconnecting the PDM pins. */ -__STATIC_INLINE void nrf_pdm_psel_disconnect(void); - -/** - * @brief Function for setting the PDM gain. - * - * @param[in] gain_l Left channel gain. - * @param[in] gain_r Right channel gain. - */ -__STATIC_INLINE void nrf_pdm_gain_set(nrf_pdm_gain_t gain_l, nrf_pdm_gain_t gain_r); - -/** - * @brief Function for getting the PDM gain. - * - * @param[out] p_gain_l Left channel gain. - * @param[out] p_gain_r Right channel gain. - */ -__STATIC_INLINE void nrf_pdm_gain_get(nrf_pdm_gain_t * p_gain_l, nrf_pdm_gain_t * p_gain_r); - -/** - * @brief Function for setting the PDM sample buffer. - * - * The amount of allocated RAM depends on the operation mode. - * - For stereo mode: N 32-bit words. - * - For mono mode: Ceil(N/2) 32-bit words. - * - * @param[in] p_buffer Pointer to the RAM address where samples are to be written with EasyDMA. - * @param[in] num Number of samples to allocate memory for in EasyDMA mode. - */ -__STATIC_INLINE void nrf_pdm_buffer_set(uint32_t * p_buffer, uint32_t num); - -/** - * @brief Function for getting the current PDM sample buffer address. - * - * @return Pointer to the current sample buffer. - */ -__STATIC_INLINE uint32_t * nrf_pdm_buffer_get(void); - -#ifndef SUPPRESS_INLINE_IMPLEMENTATION -__STATIC_INLINE void nrf_pdm_task_trigger(nrf_pdm_task_t task) -{ - *((volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)task)) = 0x1UL; -} - -__STATIC_INLINE uint32_t nrf_pdm_task_address_get(nrf_pdm_task_t task) -{ - return (uint32_t)((uint8_t *)NRF_PDM + (uint32_t)task); -} - -__STATIC_INLINE bool nrf_pdm_event_check(nrf_pdm_event_t event) -{ - return (bool)*(volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)event); -} - -__STATIC_INLINE void nrf_pdm_event_clear(nrf_pdm_event_t event) -{ - *((volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)event)) = 0x0UL; -#if __CORTEX_M == 0x04 - volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)event)); - (void)dummy; -#endif -} - -__STATIC_INLINE volatile uint32_t * nrf_pdm_event_address_get(nrf_pdm_event_t event) -{ - return (volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)event); -} - -__STATIC_INLINE void nrf_pdm_int_enable(uint32_t int_mask) -{ - NRF_PDM->INTENSET = int_mask; -} - -__STATIC_INLINE bool nrf_pdm_int_enable_check(uint32_t int_mask) -{ - return (bool)(NRF_PDM->INTENSET & int_mask); -} - -__STATIC_INLINE void nrf_pdm_int_disable(uint32_t int_mask) -{ - NRF_PDM->INTENCLR = int_mask; -} - -#if defined(DPPI_PRESENT) -__STATIC_INLINE void nrf_pdm_subscribe_set(nrf_pdm_task_t task, - uint8_t channel) -{ - *((volatile uint32_t *) ((uint8_t *) NRF_PDM + (uint32_t) task + 0x80uL)) = - ((uint32_t)channel | PDM_SUBSCRIBE_START_EN_Msk); -} - -__STATIC_INLINE void nrf_pdm_subscribe_clear(nrf_pdm_task_t task) -{ - *((volatile uint32_t *) ((uint8_t *) NRF_PDM + (uint32_t) task + 0x80uL)) = 0; -} - -__STATIC_INLINE void nrf_pdm_publish_set(nrf_pdm_event_t event, - uint8_t channel) -{ - *((volatile uint32_t *) ((uint8_t *) NRF_PDM + (uint32_t) event + 0x80uL)) = - ((uint32_t)channel | PDM_PUBLISH_STARTED_EN_Msk); -} - -__STATIC_INLINE void nrf_pdm_publish_clear(nrf_pdm_event_t event) -{ - *((volatile uint32_t *) ((uint8_t *) NRF_PDM + (uint32_t) event + 0x80uL)) = 0; -} -#endif // defined(DPPI_PRESENT) - -__STATIC_INLINE void nrf_pdm_enable(void) -{ - NRF_PDM->ENABLE = (PDM_ENABLE_ENABLE_Enabled << PDM_ENABLE_ENABLE_Pos); -} - -__STATIC_INLINE void nrf_pdm_disable(void) -{ - NRF_PDM->ENABLE = (PDM_ENABLE_ENABLE_Disabled << PDM_ENABLE_ENABLE_Pos); -} - -__STATIC_INLINE bool nrf_pdm_enable_check(void) -{ - return (NRF_PDM->ENABLE == (PDM_ENABLE_ENABLE_Enabled << PDM_ENABLE_ENABLE_Pos)); -} - -__STATIC_INLINE void nrf_pdm_mode_set(nrf_pdm_mode_t pdm_mode, nrf_pdm_edge_t pdm_edge) -{ - NRF_PDM->MODE = ((pdm_mode << PDM_MODE_OPERATION_Pos) & PDM_MODE_OPERATION_Msk) - | ((pdm_edge << PDM_MODE_EDGE_Pos) & PDM_MODE_EDGE_Msk); -} - -__STATIC_INLINE void nrf_pdm_mode_get(nrf_pdm_mode_t * p_pdm_mode, nrf_pdm_edge_t * p_pdm_edge) -{ - uint32_t mode = NRF_PDM->MODE; - *p_pdm_mode = (nrf_pdm_mode_t)((mode & PDM_MODE_OPERATION_Msk ) >> PDM_MODE_OPERATION_Pos); - *p_pdm_edge = (nrf_pdm_edge_t)((mode & PDM_MODE_EDGE_Msk ) >> PDM_MODE_EDGE_Pos); -} - -__STATIC_INLINE void nrf_pdm_clock_set(nrf_pdm_freq_t pdm_freq) -{ - NRF_PDM->PDMCLKCTRL = ((pdm_freq << PDM_PDMCLKCTRL_FREQ_Pos) & PDM_PDMCLKCTRL_FREQ_Msk); -} - -__STATIC_INLINE nrf_pdm_freq_t nrf_pdm_clock_get(void) -{ - return (nrf_pdm_freq_t) ((NRF_PDM->PDMCLKCTRL << PDM_PDMCLKCTRL_FREQ_Pos) & PDM_PDMCLKCTRL_FREQ_Msk); -} - -__STATIC_INLINE void nrf_pdm_psel_connect(uint32_t psel_clk, uint32_t psel_din) -{ - NRF_PDM->PSEL.CLK = psel_clk; - NRF_PDM->PSEL.DIN = psel_din; -} - -__STATIC_INLINE void nrf_pdm_psel_disconnect(void) -{ - NRF_PDM->PSEL.CLK = ((PDM_PSEL_CLK_CONNECT_Disconnected << PDM_PSEL_CLK_CONNECT_Pos) - & PDM_PSEL_CLK_CONNECT_Msk); - NRF_PDM->PSEL.DIN = ((PDM_PSEL_DIN_CONNECT_Disconnected << PDM_PSEL_DIN_CONNECT_Pos) - & PDM_PSEL_DIN_CONNECT_Msk); -} - -__STATIC_INLINE void nrf_pdm_gain_set(nrf_pdm_gain_t gain_l, nrf_pdm_gain_t gain_r) -{ - NRF_PDM->GAINL = gain_l; - NRF_PDM->GAINR = gain_r; -} - -__STATIC_INLINE void nrf_pdm_gain_get(nrf_pdm_gain_t * p_gain_l, nrf_pdm_gain_t * p_gain_r) -{ - *p_gain_l = NRF_PDM->GAINL; - *p_gain_r = NRF_PDM->GAINR; -} - -__STATIC_INLINE void nrf_pdm_buffer_set(uint32_t * p_buffer, uint32_t num) -{ - NRF_PDM->SAMPLE.PTR = (uint32_t)p_buffer; - NRF_PDM->SAMPLE.MAXCNT = num; -} - -__STATIC_INLINE uint32_t * nrf_pdm_buffer_get(void) -{ - return (uint32_t *)NRF_PDM->SAMPLE.PTR; -} - -#endif // SUPPRESS_INLINE_IMPLEMENTATION -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif // NRF_PDM_H_ diff --git a/modules/nrfx/hal/nrf_qdec.h b/modules/nrfx/hal/nrf_qdec.h deleted file mode 100644 index 912c28a..0000000 --- a/modules/nrfx/hal/nrf_qdec.h +++ /dev/null @@ -1,561 +0,0 @@ -/** - * Copyright (c) 2014 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ -#ifndef NRF_QDEC_H__ -#define NRF_QDEC_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_qdec_hal QDEC HAL - * @{ - * @ingroup nrf_qdec - * @brief Hardware access layer for managing the Quadrature Decoder (QDEC) peripheral. - */ - -/** - * @brief This value can be provided as a parameter for the @ref nrf_qdec_pio_assign - * function call to specify that a LED signal shall not be use by the QDEC and - * connected to a physical pin. - */ -#define NRF_QDEC_LED_NOT_CONNECTED 0xFFFFFFFF - -/** @brief QDEC tasks. */ -typedef enum -{ - NRF_QDEC_TASK_START = offsetof(NRF_QDEC_Type, TASKS_START), /**< Starting the quadrature decoder. */ - NRF_QDEC_TASK_STOP = offsetof(NRF_QDEC_Type, TASKS_STOP), /**< Stopping the quadrature decoder. */ - NRF_QDEC_TASK_READCLRACC = offsetof(NRF_QDEC_Type, TASKS_READCLRACC) /**< Reading and clearing ACC and ACCDBL registers. */ -} nrf_qdec_task_t; - -/** @brief QDEC events. */ -typedef enum -{ - NRF_QDEC_EVENT_SAMPLERDY = offsetof(NRF_QDEC_Type, EVENTS_SAMPLERDY), /**< Event generated for every new sample. */ - NRF_QDEC_EVENT_REPORTRDY = offsetof(NRF_QDEC_Type, EVENTS_REPORTRDY), /**< Event generated for every new report. */ - NRF_QDEC_EVENT_ACCOF = offsetof(NRF_QDEC_Type, EVENTS_ACCOF) /**< Event generated for every accumulator overflow. */ -} nrf_qdec_event_t; - -/** @brief QDEC shortcuts. */ -typedef enum -{ - NRF_QDEC_SHORT_REPORTRDY_READCLRACC_MASK = QDEC_SHORTS_REPORTRDY_READCLRACC_Msk, /**< Shortcut between REPORTRDY event and READCLRACC task. */ - NRF_QDEC_SHORT_SAMPLERDY_STOP_MASK = QDEC_SHORTS_SAMPLERDY_STOP_Msk /**< Shortcut between SAMPLERDY event and STOP task. */ -} nrf_qdec_short_mask_t; - -/** @brief QDEC interrupts. */ -typedef enum -{ - NRF_QDEC_INT_SAMPLERDY_MASK = QDEC_INTENSET_SAMPLERDY_Msk, /**< Mask for enabling or disabling an interrupt on SAMPLERDY event. */ - NRF_QDEC_INT_REPORTRDY_MASK = QDEC_INTENSET_REPORTRDY_Msk, /**< Mask for enabling or disabling an interrupt on REPORTRDY event. */ - NRF_QDEC_INT_ACCOF_MASK = QDEC_INTENSET_ACCOF_Msk /**< Mask for enabling or disabling an interrupt on ACCOF event. */ -} nrf_qdec_int_mask_t; - -/** @brief States of the enable bit. */ -typedef enum -{ - NRF_QDEC_DISABLE = QDEC_ENABLE_ENABLE_Disabled, /**< Mask for disabling the QDEC periperal. When disabled, the QDEC decoder pins are not active. */ - NRF_QDEC_ENABLE = QDEC_ENABLE_ENABLE_Enabled /**< Mask for enabling the QDEC periperal. When enabled, the QDEC pins are active. */ -} nrf_qdec_enable_t; - -/** @brief States of the debounce filter enable bit. */ -typedef enum -{ - NRF_QDEC_DBFEN_DISABLE = QDEC_DBFEN_DBFEN_Disabled, /**< Mask for disabling the debounce filter. */ - NRF_QDEC_DBFEN_ENABLE = QDEC_DBFEN_DBFEN_Enabled /**< Mask for enabling the debounce filter. */ -} nrf_qdec_dbfen_t; - -/** @brief Active LED polarity. */ -typedef enum -{ - NRF_QDEC_LEPOL_ACTIVE_LOW = QDEC_LEDPOL_LEDPOL_ActiveLow, /**< QDEC LED active on output pin low. */ - NRF_QDEC_LEPOL_ACTIVE_HIGH = QDEC_LEDPOL_LEDPOL_ActiveHigh /**< QDEC LED active on output pin high. */ -} nrf_qdec_ledpol_t; - -/** @brief Available sampling periods. */ -typedef enum -{ - NRF_QDEC_SAMPLEPER_128us = QDEC_SAMPLEPER_SAMPLEPER_128us, /**< QDEC sampling period 128 microseconds. */ - NRF_QDEC_SAMPLEPER_256us = QDEC_SAMPLEPER_SAMPLEPER_256us, /**< QDEC sampling period 256 microseconds. */ - NRF_QDEC_SAMPLEPER_512us = QDEC_SAMPLEPER_SAMPLEPER_512us, /**< QDEC sampling period 512 microseconds. */ - NRF_QDEC_SAMPLEPER_1024us = QDEC_SAMPLEPER_SAMPLEPER_1024us, /**< QDEC sampling period 1024 microseconds. */ - NRF_QDEC_SAMPLEPER_2048us = QDEC_SAMPLEPER_SAMPLEPER_2048us, /**< QDEC sampling period 2048 microseconds. */ - NRF_QDEC_SAMPLEPER_4096us = QDEC_SAMPLEPER_SAMPLEPER_4096us, /**< QDEC sampling period 4096 microseconds. */ - NRF_QDEC_SAMPLEPER_8192us = QDEC_SAMPLEPER_SAMPLEPER_8192us, /**< QDEC sampling period 8192 microseconds. */ - NRF_QDEC_SAMPLEPER_16384us = QDEC_SAMPLEPER_SAMPLEPER_16384us /**< QDEC sampling period 16384 microseconds. */ -} nrf_qdec_sampleper_t; - -/** @brief Available report periods. */ -typedef enum -{ -#if defined(QDEC_REPORTPER_REPORTPER_1Smpl) || defined(__NRFX_DOXYGEN__) - NRF_QDEC_REPORTPER_1 = QDEC_REPORTPER_REPORTPER_1Smpl, /**< QDEC report period 1 sample. */ -#endif - NRF_QDEC_REPORTPER_10 = QDEC_REPORTPER_REPORTPER_10Smpl, /**< QDEC report period 10 samples. */ - NRF_QDEC_REPORTPER_40 = QDEC_REPORTPER_REPORTPER_40Smpl, /**< QDEC report period 40 samples. */ - NRF_QDEC_REPORTPER_80 = QDEC_REPORTPER_REPORTPER_80Smpl, /**< QDEC report period 80 samples. */ - NRF_QDEC_REPORTPER_120 = QDEC_REPORTPER_REPORTPER_120Smpl, /**< QDEC report period 120 samples. */ - NRF_QDEC_REPORTPER_160 = QDEC_REPORTPER_REPORTPER_160Smpl, /**< QDEC report period 160 samples. */ - NRF_QDEC_REPORTPER_200 = QDEC_REPORTPER_REPORTPER_200Smpl, /**< QDEC report period 200 samples. */ - NRF_QDEC_REPORTPER_240 = QDEC_REPORTPER_REPORTPER_240Smpl, /**< QDEC report period 240 samples. */ - NRF_QDEC_REPORTPER_280 = QDEC_REPORTPER_REPORTPER_280Smpl, /**< QDEC report period 280 samples. */ - NRF_QDEC_REPORTPER_DISABLED = (QDEC_REPORTPER_REPORTPER_Msk >> QDEC_REPORTPER_REPORTPER_Pos) + 1 /**< QDEC reporting disabled. Deprecated. */ -} nrf_qdec_reportper_t; - -/** @brief Function for enabling QDEC. */ -__STATIC_INLINE void nrf_qdec_enable(void); - -/** @brief Function for disabling QDEC. */ -__STATIC_INLINE void nrf_qdec_disable(void); - -/** - * @brief Function for returning the enable state of QDEC. - * - * @return State of the register. - */ -__STATIC_INLINE uint32_t nrf_qdec_enable_get(void); - -/** - * @brief Function for enabling QDEC interrupts by mask. - * - * @param[in] mask Mask of interrupts to be enabled. - */ -__STATIC_INLINE void nrf_qdec_int_enable(uint32_t mask); - -/** - * @brief Function for disabling QDEC interrupts by mask. - * - * @param[in] mask Mask of interrupts to be disabled. - */ -__STATIC_INLINE void nrf_qdec_int_disable(uint32_t mask); - -/** - * @brief Function for getting the enabled interrupts of the QDEC. - * - * @param[in] mask Mask of interrupts to be checked. - * - * @return Bitfield with enabled interrupts. - */ -__STATIC_INLINE uint32_t nrf_qdec_int_enable_check(nrf_qdec_int_mask_t mask); - -/** @brief Function for enabling the QDEC debouncing filter. */ -__STATIC_INLINE void nrf_qdec_dbfen_enable(void); - -/** @brief Function for disabling the QDEC debouncing filter. */ -__STATIC_INLINE void nrf_qdec_dbfen_disable(void); - -/** - * @brief Function for getting the state of the QDEC debouncing filter. - * - * @retval NRF_QDEC_DBFEN_DISABLE The debouncing filter is disabled. - * @retval NRF_QDEC_DBFEN_ENABLE The debouncing filter is enabled. - */ -__STATIC_INLINE uint32_t nrf_qdec_dbfen_get(void); - -/** - * @brief Function for assigning QDEC pins. - * - * @param[in] psela Pin number. - * @param[in] pselb Pin number. - * @param[in] pselled Pin number. - */ -__STATIC_INLINE void nrf_qdec_pio_assign( uint32_t psela, uint32_t pselb, uint32_t pselled); - -/** - * @brief Function for setting the specified QDEC task. - * - * @param[in] task QDEC task to be triggered. - */ -__STATIC_INLINE void nrf_qdec_task_trigger(nrf_qdec_task_t task); - -/** - * @brief Function for retrieving the address of a QDEC task register. - * - * @param[in] task QDEC task to get its address. - * - * @return Address of the specified QDEC task. - */ -__STATIC_INLINE uint32_t * nrf_qdec_task_address_get(nrf_qdec_task_t task); - -/** - * @brief Function for clearing the specified QDEC event. - * - * @param[in] event QDEC event to be cleared. - */ -__STATIC_INLINE void nrf_qdec_event_clear(nrf_qdec_event_t event); - -/** - * @brief Function for getting the state of the specified QDEC event. - * - * @param[in] event QDEC event to be checked. - * - * @return State of the specified QDEC event. - */ -__STATIC_INLINE uint32_t nrf_qdec_event_check(nrf_qdec_event_t event); - -/** - * @brief Function for retrieving the address of the specified QDEC event register. - * - * @param[in] event QDEC event to get its address. - * - * @return Address of the specified QDEC event. - */ -__STATIC_INLINE uint32_t * nrf_qdec_event_address_get(nrf_qdec_event_t event); - -/** - * @brief Function for setting QDEC shortcuts. - * - * @param[in] mask Mask of QDEC shortcuts to be set. - */ -__STATIC_INLINE void nrf_qdec_shorts_enable(uint32_t mask); - -/** - * @brief Function for clearing shortcuts of the QDEC by mask. - * - * @param[in] mask Mask of QDEC shortcuts to be cleared. - */ -__STATIC_INLINE void nrf_qdec_shorts_disable(uint32_t mask); - -/** - * @brief Function for retrieving value of the sampling period. - * - * @return Sample period @ref nrf_qdec_sampleper_t. - */ -__STATIC_INLINE int32_t nrf_qdec_sampleper_reg_get(void); - -/** - * @brief Function for converting return value of the @p nrf_qdec_sampleper_reg_get() function - * to microseconds. - * - * @param[in] sampleper The sampling period. - * - * @return Period in microseconds. - */ -__STATIC_INLINE uint32_t nrf_qdec_sampleper_to_value(uint32_t sampleper); - -/** - * @brief Function for setting value of the QDEC sampling period. - * - * @param[in] sample_per The sampling period. - */ -__STATIC_INLINE void nrf_qdec_sampleper_set(nrf_qdec_sampleper_t sample_per); - -/** - * @brief Function for retrieving value of the QDEC SAMPLE register. - * - * @return Value of the SAMPLE register. - */ -__STATIC_INLINE int32_t nrf_qdec_sample_get(void); - -/** - * @brief Function for retrieving value of the QDEC ACC register. - * - * @return Value of the ACC register. - */ -__STATIC_INLINE int32_t nrf_qdec_acc_get(void); - -/** - * @brief Function for retrieving value of the QDEC ACCREAD register. - * - * @return Value of the ACCREAD register. - */ -__STATIC_INLINE int32_t nrf_qdec_accread_get(void); - -/** - * @brief Function for retrieving value of the QDEC ACCDBL register. - * - * @return Value of the ACCDBL register. - */ -__STATIC_INLINE uint32_t nrf_qdec_accdbl_get(void); - -/** - * @brief Function for retrieving value of the QDEC ACCDBLREAD register. - * - * @return Value of the ACCDBLREAD register. - */ -__STATIC_INLINE uint32_t nrf_qdec_accdblread_get(void); - -/** - * @brief Function for setting delay time between setting LED active state and start sampling. - * - * @param[in] time_us Delay time (in microseconds) between setting LED active state - * and start sampling. - */ -__STATIC_INLINE void nrf_qdec_ledpre_set(uint32_t time_us); - -/** - * @brief Function for retrieving how long the LED is switched on before sampling. - * - * @return The gap in time in microseconds between switched LED to active state and start sampling. - */ -__STATIC_INLINE uint32_t nrf_qdec_ledpre_get(void); - -/** - * @brief Function for setting the report period (in samples). - * - * @param[in] reportper The number of samples. - */ -__STATIC_INLINE void nrf_qdec_reportper_set(nrf_qdec_reportper_t reportper); - -/** - * @brief Function for retrieving the report period. - * - * @return The report period. - */ -__STATIC_INLINE uint32_t nrf_qdec_reportper_reg_get(void); - -/** - * @brief Function for retrieving the value of QDEC SAMPLEPER register. - * - * @param [in] reportper Reportper to be converted to amount of samples per report. - * - * @return Number of samples per report. - */ -__STATIC_INLINE uint32_t nrf_qdec_reportper_to_value(uint32_t reportper); - -/** - * @brief Function for setting the active level for the LED. - * - * @param[in] pol Level of the active signal of the LED. - */ -__STATIC_INLINE void nrf_qdec_ledpol_set(nrf_qdec_ledpol_t pol); - -/** - * @brief Function for retrieving the active level for the LED. - * - * @return Level of the active signal of the LED. - */ -__STATIC_INLINE uint32_t nrf_qdec_ledpol_get(void); - - -#ifndef SUPPRESS_INLINE_IMPLEMENTATION - -__STATIC_INLINE void nrf_qdec_enable(void) -{ - NRF_QDEC->ENABLE = NRF_QDEC_ENABLE; -} - -__STATIC_INLINE void nrf_qdec_disable(void) -{ - NRF_QDEC->ENABLE = NRF_QDEC_DISABLE; -} - -__STATIC_INLINE uint32_t nrf_qdec_enable_get(void) -{ - return NRF_QDEC->ENABLE; -} - -__STATIC_INLINE void nrf_qdec_int_enable(uint32_t mask) -{ - NRF_QDEC->INTENSET = mask; // writing 0 has no effect -} - -__STATIC_INLINE void nrf_qdec_int_disable(uint32_t mask) -{ - NRF_QDEC->INTENCLR = mask; // writing 0 has no effect -} - -__STATIC_INLINE uint32_t nrf_qdec_int_enable_check(nrf_qdec_int_mask_t mask) -{ - return NRF_QDEC->INTENSET & mask; // when read this register will return the value of INTEN. -} - -__STATIC_INLINE void nrf_qdec_dbfen_enable(void) -{ - NRF_QDEC->DBFEN = NRF_QDEC_DBFEN_ENABLE; -} - -__STATIC_INLINE void nrf_qdec_dbfen_disable(void) -{ - NRF_QDEC->DBFEN = NRF_QDEC_DBFEN_DISABLE; -} - -__STATIC_INLINE uint32_t nrf_qdec_dbfen_get(void) -{ - return NRF_QDEC->DBFEN; -} - -__STATIC_INLINE void nrf_qdec_pio_assign( uint32_t psela, uint32_t pselb, uint32_t pselled) -{ -#if defined(QDEC_PSEL_A_CONNECT_Pos) - NRF_QDEC->PSEL.A = psela; -#else - NRF_QDEC->PSELA = psela; -#endif - -#if defined(QDEC_PSEL_B_CONNECT_Pos) - NRF_QDEC->PSEL.B = pselb; -#else - NRF_QDEC->PSELB = pselb; -#endif - -#if defined(QDEC_PSEL_LED_CONNECT_Pos) - NRF_QDEC->PSEL.LED = pselled; -#else - NRF_QDEC->PSELLED = pselled; -#endif -} - -__STATIC_INLINE void nrf_qdec_task_trigger(nrf_qdec_task_t task) -{ - *( (volatile uint32_t *)( (uint8_t *)NRF_QDEC + (uint32_t)task) ) = 1; -} - -__STATIC_INLINE uint32_t * nrf_qdec_task_address_get(nrf_qdec_task_t task) -{ - return (uint32_t *)( (uint8_t *)NRF_QDEC + (uint32_t)task); -} - -__STATIC_INLINE void nrf_qdec_event_clear(nrf_qdec_event_t event) -{ - *( (volatile uint32_t *)( (uint8_t *)NRF_QDEC + (uint32_t)event) ) = 0; -#if __CORTEX_M == 0x04 - volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_QDEC + event)); - (void)dummy; -#endif -} - -__STATIC_INLINE uint32_t nrf_qdec_event_check(nrf_qdec_event_t event) -{ - return *(volatile uint32_t *)( (uint8_t *)NRF_QDEC + (uint32_t)event); -} - -__STATIC_INLINE uint32_t * nrf_qdec_event_address_get(nrf_qdec_event_t event) -{ - return (uint32_t *)( (uint8_t *)NRF_QDEC + (uint32_t)event); -} - -__STATIC_INLINE void nrf_qdec_shorts_enable(uint32_t mask) -{ - NRF_QDEC->SHORTS |= mask; -} - -__STATIC_INLINE void nrf_qdec_shorts_disable(uint32_t mask) -{ - NRF_QDEC->SHORTS &= ~mask; -} - -__STATIC_INLINE int32_t nrf_qdec_sampleper_reg_get(void) -{ - return NRF_QDEC->SAMPLEPER; -} - -__STATIC_INLINE uint32_t nrf_qdec_sampleper_to_value(uint32_t sampleper) -{ - return (1 << (7 + sampleper)); -} - -__STATIC_INLINE void nrf_qdec_sampleper_set(nrf_qdec_sampleper_t sample_per) -{ - NRF_QDEC->SAMPLEPER = sample_per; -} - -__STATIC_INLINE int32_t nrf_qdec_sample_get(void) -{ - return NRF_QDEC->SAMPLE; -} - -__STATIC_INLINE int32_t nrf_qdec_acc_get(void) -{ - return NRF_QDEC->ACC; -} - -__STATIC_INLINE int32_t nrf_qdec_accread_get(void) -{ - return NRF_QDEC->ACCREAD; -} - -__STATIC_INLINE uint32_t nrf_qdec_accdbl_get(void) -{ - return NRF_QDEC->ACCDBL; -} - -__STATIC_INLINE uint32_t nrf_qdec_accdblread_get(void) -{ - return NRF_QDEC->ACCDBLREAD; -} - -__STATIC_INLINE void nrf_qdec_ledpre_set(uint32_t time_us) -{ - NRF_QDEC->LEDPRE = time_us; -} - -__STATIC_INLINE uint32_t nrf_qdec_ledpre_get(void) -{ - return NRF_QDEC->LEDPRE; -} - -__STATIC_INLINE void nrf_qdec_reportper_set(nrf_qdec_reportper_t reportper) -{ - NRF_QDEC->REPORTPER = reportper; -} - -__STATIC_INLINE uint32_t nrf_qdec_reportper_reg_get(void) -{ - return NRF_QDEC->REPORTPER; -} - -__STATIC_INLINE uint32_t nrf_qdec_reportper_to_value(uint32_t reportper) -{ - return (reportper == NRF_QDEC_REPORTPER_10) ? 10 : reportper * 40; -} - -__STATIC_INLINE void nrf_qdec_ledpol_set(nrf_qdec_ledpol_t pol) -{ - NRF_QDEC->LEDPOL = pol; -} - -__STATIC_INLINE uint32_t nrf_qdec_ledpol_get(void) -{ - return NRF_QDEC->LEDPOL; -} - -#endif // SUPPRESS_INLINE_IMPLEMENTATION - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif // NRF_QDEC_H__ diff --git a/modules/nrfx/hal/nrf_qspi.h b/modules/nrfx/hal/nrf_qspi.h deleted file mode 100644 index 4d2da10..0000000 --- a/modules/nrfx/hal/nrf_qspi.h +++ /dev/null @@ -1,823 +0,0 @@ -/** - * Copyright (c) 2016 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_QSPI_H__ -#define NRF_QSPI_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_qspi_hal QSPI HAL - * @{ - * @ingroup nrf_qspi - * @brief Hardware access layer for managing the QSPI peripheral. - */ - -/** - * @brief This value can be used as a parameter for the @ref nrf_qspi_pins_set - * function to specify that a given QSPI signal (SCK, CSN, IO0, IO1, IO2, or IO3) - * will not be connected to a physical pin. - */ -#define NRF_QSPI_PIN_NOT_CONNECTED 0xFF - -/** @brief Macro for setting proper values to pin registers. */ -#define NRF_QSPI_PIN_VAL(pin) (pin) == NRF_QSPI_PIN_NOT_CONNECTED ? 0xFFFFFFFF : (pin) - - -/** @brief QSPI tasks. */ -typedef enum -{ - NRF_QSPI_TASK_ACTIVATE = offsetof(NRF_QSPI_Type, TASKS_ACTIVATE), /**< Activate the QSPI interface. */ - NRF_QSPI_TASK_READSTART = offsetof(NRF_QSPI_Type, TASKS_READSTART), /**< Start transfer from external flash memory to internal RAM. */ - NRF_QSPI_TASK_WRITESTART = offsetof(NRF_QSPI_Type, TASKS_WRITESTART), /**< Start transfer from internal RAM to external flash memory. */ - NRF_QSPI_TASK_ERASESTART = offsetof(NRF_QSPI_Type, TASKS_ERASESTART), /**< Start external flash memory erase operation. */ - NRF_QSPI_TASK_DEACTIVATE = offsetof(NRF_QSPI_Type, TASKS_DEACTIVATE), /**< Deactivate the QSPI interface. */ -} nrf_qspi_task_t; - -/** @brief QSPI events. */ -typedef enum -{ - NRF_QSPI_EVENT_READY = offsetof(NRF_QSPI_Type, EVENTS_READY) /**< QSPI peripheral is ready after it executes any task. */ -} nrf_qspi_event_t; - -/** @brief QSPI interrupts. */ -typedef enum -{ - NRF_QSPI_INT_READY_MASK = QSPI_INTENSET_READY_Msk /**< Interrupt on READY event. */ -} nrf_qspi_int_mask_t; - -/** @brief QSPI frequency divider values. */ -typedef enum -{ - NRF_QSPI_FREQ_32MDIV1, /**< 32.0 MHz. */ - NRF_QSPI_FREQ_32MDIV2, /**< 16.0 MHz. */ - NRF_QSPI_FREQ_32MDIV3, /**< 10.6 MHz. */ - NRF_QSPI_FREQ_32MDIV4, /**< 8.00 MHz. */ - NRF_QSPI_FREQ_32MDIV5, /**< 6.40 MHz. */ - NRF_QSPI_FREQ_32MDIV6, /**< 5.33 MHz. */ - NRF_QSPI_FREQ_32MDIV7, /**< 4.57 MHz. */ - NRF_QSPI_FREQ_32MDIV8, /**< 4.00 MHz. */ - NRF_QSPI_FREQ_32MDIV9, /**< 3.55 MHz. */ - NRF_QSPI_FREQ_32MDIV10, /**< 3.20 MHz. */ - NRF_QSPI_FREQ_32MDIV11, /**< 2.90 MHz. */ - NRF_QSPI_FREQ_32MDIV12, /**< 2.66 MHz. */ - NRF_QSPI_FREQ_32MDIV13, /**< 2.46 MHz. */ - NRF_QSPI_FREQ_32MDIV14, /**< 2.29 MHz. */ - NRF_QSPI_FREQ_32MDIV15, /**< 2.13 MHz. */ - NRF_QSPI_FREQ_32MDIV16, /**< 2.00 MHz. */ -} nrf_qspi_frequency_t; - -/** @brief Interface configuration for a read operation. */ -typedef enum -{ - NRF_QSPI_READOC_FASTREAD = QSPI_IFCONFIG0_READOC_FASTREAD, /**< Single data line SPI. FAST_READ (opcode 0x0B). */ - NRF_QSPI_READOC_READ2O = QSPI_IFCONFIG0_READOC_READ2O, /**< Dual data line SPI. READ2O (opcode 0x3B). */ - NRF_QSPI_READOC_READ2IO = QSPI_IFCONFIG0_READOC_READ2IO, /**< Dual data line SPI. READ2IO (opcode 0xBB). */ - NRF_QSPI_READOC_READ4O = QSPI_IFCONFIG0_READOC_READ4O, /**< Quad data line SPI. READ4O (opcode 0x6B). */ - NRF_QSPI_READOC_READ4IO = QSPI_IFCONFIG0_READOC_READ4IO /**< Quad data line SPI. READ4IO (opcode 0xEB). */ -} nrf_qspi_readoc_t; - -/** @brief Interface configuration for a write operation. */ -typedef enum -{ - NRF_QSPI_WRITEOC_PP = QSPI_IFCONFIG0_WRITEOC_PP, /**< Single data line SPI. PP (opcode 0x02). */ - NRF_QSPI_WRITEOC_PP2O = QSPI_IFCONFIG0_WRITEOC_PP2O, /**< Dual data line SPI. PP2O (opcode 0xA2). */ - NRF_QSPI_WRITEOC_PP4O = QSPI_IFCONFIG0_WRITEOC_PP4O, /**< Quad data line SPI. PP4O (opcode 0x32). */ - NRF_QSPI_WRITEOC_PP4IO = QSPI_IFCONFIG0_WRITEOC_PP4IO, /**< Quad data line SPI. READ4O (opcode 0x38). */ -} nrf_qspi_writeoc_t; - -/** @brief Interface configuration for addressing mode. */ -typedef enum -{ - NRF_QSPI_ADDRMODE_24BIT = QSPI_IFCONFIG0_ADDRMODE_24BIT, /**< 24-bit addressing. */ - NRF_QSPI_ADDRMODE_32BIT = QSPI_IFCONFIG0_ADDRMODE_32BIT /**< 32-bit addressing. */ -} nrf_qspi_addrmode_t; - -/** @brief QSPI SPI mode. Polarization and phase configuration. */ -typedef enum -{ - NRF_QSPI_MODE_0 = QSPI_IFCONFIG1_SPIMODE_MODE0, /**< Mode 0 (CPOL=0, CPHA=0). */ - NRF_QSPI_MODE_1 = QSPI_IFCONFIG1_SPIMODE_MODE3 /**< Mode 1 (CPOL=1, CPHA=1). */ -} nrf_qspi_spi_mode_t; - -/** @brief Addressing configuration mode. */ -typedef enum -{ - NRF_QSPI_ADDRCONF_MODE_NOINSTR = QSPI_ADDRCONF_MODE_NoInstr, /**< Do not send any instruction. */ - NRF_QSPI_ADDRCONF_MODE_OPCODE = QSPI_ADDRCONF_MODE_Opcode, /**< Send opcode. */ - NRF_QSPI_ADDRCONF_MODE_OPBYTE0 = QSPI_ADDRCONF_MODE_OpByte0, /**< Send opcode, byte0. */ - NRF_QSPI_ADDRCONF_MODE_ALL = QSPI_ADDRCONF_MODE_All /**< Send opcode, byte0, byte1. */ -} nrf_qspi_addrconfig_mode_t; - -/** @brief Erasing data length. */ -typedef enum -{ - NRF_QSPI_ERASE_LEN_4KB = QSPI_ERASE_LEN_LEN_4KB, /**< Erase 4 kB block (flash command 0x20). */ - NRF_QSPI_ERASE_LEN_64KB = QSPI_ERASE_LEN_LEN_64KB, /**< Erase 64 kB block (flash command 0xD8). */ - NRF_QSPI_ERASE_LEN_ALL = QSPI_ERASE_LEN_LEN_All /**< Erase all (flash command 0xC7). */ -} nrf_qspi_erase_len_t; - -/** @brief Custom instruction length. */ -typedef enum -{ - NRF_QSPI_CINSTR_LEN_1B = QSPI_CINSTRCONF_LENGTH_1B, /**< Send opcode only. */ - NRF_QSPI_CINSTR_LEN_2B = QSPI_CINSTRCONF_LENGTH_2B, /**< Send opcode, CINSTRDAT0.BYTE0. */ - NRF_QSPI_CINSTR_LEN_3B = QSPI_CINSTRCONF_LENGTH_3B, /**< Send opcode, CINSTRDAT0.BYTE0 -> CINSTRDAT0.BYTE1. */ - NRF_QSPI_CINSTR_LEN_4B = QSPI_CINSTRCONF_LENGTH_4B, /**< Send opcode, CINSTRDAT0.BYTE0 -> CINSTRDAT0.BYTE2. */ - NRF_QSPI_CINSTR_LEN_5B = QSPI_CINSTRCONF_LENGTH_5B, /**< Send opcode, CINSTRDAT0.BYTE0 -> CINSTRDAT0.BYTE3. */ - NRF_QSPI_CINSTR_LEN_6B = QSPI_CINSTRCONF_LENGTH_6B, /**< Send opcode, CINSTRDAT0.BYTE0 -> CINSTRDAT1.BYTE4. */ - NRF_QSPI_CINSTR_LEN_7B = QSPI_CINSTRCONF_LENGTH_7B, /**< Send opcode, CINSTRDAT0.BYTE0 -> CINSTRDAT1.BYTE5. */ - NRF_QSPI_CINSTR_LEN_8B = QSPI_CINSTRCONF_LENGTH_8B, /**< Send opcode, CINSTRDAT0.BYTE0 -> CINSTRDAT1.BYTE6. */ - NRF_QSPI_CINSTR_LEN_9B = QSPI_CINSTRCONF_LENGTH_9B /**< Send opcode, CINSTRDAT0.BYTE0 -> CINSTRDAT1.BYTE7. */ -} nrf_qspi_cinstr_len_t; - -/** @brief Pin configuration. */ -typedef struct -{ - uint8_t sck_pin; /**< SCK pin number. */ - uint8_t csn_pin; /**< Chip select pin number. */ - uint8_t io0_pin; /**< IO0/MOSI pin number. */ - uint8_t io1_pin; /**< IO1/MISO pin number. */ - uint8_t io2_pin; /**< IO2 pin number (optional). - * Set to @ref NRF_QSPI_PIN_NOT_CONNECTED if this signal is not needed. - */ - uint8_t io3_pin; /**< IO3 pin number (optional). - * Set to @ref NRF_QSPI_PIN_NOT_CONNECTED if this signal is not needed. - */ -} nrf_qspi_pins_t; - -/** @brief Custom instruction configuration. */ -typedef struct -{ - uint8_t opcode; /**< Opcode used in custom instruction transmission. */ - nrf_qspi_cinstr_len_t length; /**< Length of the custom instruction data. */ - bool io2_level; /**< I/O line level during transmission. */ - bool io3_level; /**< I/O line level during transmission. */ - bool wipwait; /**< Wait if a Wait in Progress bit is set in the memory status byte. */ - bool wren; /**< Send write enable before instruction. */ -} nrf_qspi_cinstr_conf_t; - -/** @brief Addressing mode register configuration. See @ref nrf_qspi_addrconfig_set */ -typedef struct -{ - uint8_t opcode; /**< Opcode used to enter the proper addressing mode. */ - uint8_t byte0; /**< Byte following the opcode. */ - uint8_t byte1; /**< Byte following byte0. */ - nrf_qspi_addrconfig_mode_t mode; /**< Extended addresing mode. */ - bool wipwait; /**< Enable or disable waiting for complete operation execution. */ - bool wren; /**< Send write enable before instruction. */ -} nrf_qspi_addrconfig_conf_t; - -/** @brief Structure with QSPI protocol interface configuration. */ -typedef struct -{ - nrf_qspi_readoc_t readoc; /**< Read operation code. */ - nrf_qspi_writeoc_t writeoc; /**< Write operation code. */ - nrf_qspi_addrmode_t addrmode; /**< Addresing mode (24-bit or 32-bit). */ - bool dpmconfig; /**< Enable the Deep Power-down Mode (DPM) feature. */ -} nrf_qspi_prot_conf_t; - -/** @brief QSPI physical interface configuration. */ -typedef struct -{ - uint8_t sck_delay; /**< tSHSL, tWHSL, and tSHWL in number of 16 MHz periods (62.5ns). */ - bool dpmen; /**< Enable the DPM feature. */ - nrf_qspi_spi_mode_t spi_mode; /**< SPI phase and polarization. */ - nrf_qspi_frequency_t sck_freq; /**< SCK frequency given as enum @ref nrf_qspi_frequency_t. */ -} nrf_qspi_phy_conf_t; - - -/** - * @brief Function for activating the specified QSPI task. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] task Task to be activated. - */ -__STATIC_INLINE void nrf_qspi_task_trigger(NRF_QSPI_Type * p_reg, nrf_qspi_task_t task); - -/** - * @brief Function for getting the address of the specified QSPI task register. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] task QSPI task. - * - * @return Address of the specified task register. - */ -__STATIC_INLINE uint32_t nrf_qspi_task_address_get(NRF_QSPI_Type const * p_reg, - nrf_qspi_task_t task); - -/** - * @brief Function for clearing the specified QSPI event. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] event Event to be cleared. - */ -__STATIC_INLINE void nrf_qspi_event_clear(NRF_QSPI_Type * p_reg, nrf_qspi_event_t event); - -/** - * @brief Function for retrieving the state of the QSPI event. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] event Event to be checked. - * - * @retval true The event has been generated. - * @retval false The event has not been generated. - */ -__STATIC_INLINE bool nrf_qspi_event_check(NRF_QSPI_Type const * p_reg, nrf_qspi_event_t event); - -/** - * @brief Function for getting the address of the specified QSPI event register. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] event The specified event. - * - * @return Address of the specified event register. - */ -__STATIC_INLINE uint32_t * nrf_qspi_event_address_get(NRF_QSPI_Type const * p_reg, - nrf_qspi_event_t event); - -/** - * @brief Function for enabling specified interrupts. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] mask Mask of interrupts to be enabled. - */ -__STATIC_INLINE void nrf_qspi_int_enable(NRF_QSPI_Type * p_reg, uint32_t mask); - -/** - * @brief Function for disabling specified interrupts. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] mask Mask of interrupts to be disabled. - */ -__STATIC_INLINE void nrf_qspi_int_disable(NRF_QSPI_Type * p_reg, uint32_t mask); - -/** - * @brief Function for retrieving the state of a given interrupt. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] qspi_int Interrupt to be checked. - * - * @retval true The interrupt is enabled. - * @retval false The interrupt is not enabled. - */ -__STATIC_INLINE bool nrf_qspi_int_enable_check(NRF_QSPI_Type const * p_reg, - nrf_qspi_int_mask_t qspi_int); - -/** - * @brief Function for enabling the QSPI peripheral. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - */ -__STATIC_INLINE void nrf_qspi_enable(NRF_QSPI_Type * p_reg); - -/** - * @brief Function for disabling the QSPI peripheral. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - */ -__STATIC_INLINE void nrf_qspi_disable(NRF_QSPI_Type * p_reg); - -/** - * @brief Function for configuring QSPI pins. - * - * If a given signal is not needed, pass the @ref NRF_QSPI_PIN_NOT_CONNECTED - * value instead of its pin number. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] p_pins Pointer to the pins configuration structure. See @ref nrf_qspi_pins_t. - */ -__STATIC_INLINE void nrf_qspi_pins_set(NRF_QSPI_Type * p_reg, - const nrf_qspi_pins_t * p_pins); - -/** - * @brief Function for getting the currently configured QSPI pins. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[out] p_pins Pointer to the pins configuration structure to be filled with QSPI pins. - */ -__STATIC_INLINE void nrf_qspi_pins_get(NRF_QSPI_Type const * p_reg, - nrf_qspi_pins_t * p_pins); - -/** - * @brief Function for setting the QSPI XIPOFFSET register. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] xip_offset Address offset in the external memory for Execute in Place operation. - */ -__STATIC_INLINE void nrf_qspi_xip_offset_set(NRF_QSPI_Type * p_reg, - uint32_t xip_offset); - -/** - * @brief Function for setting the QSPI IFCONFIG0 register. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] p_config Pointer to the QSPI protocol interface configuration structure. - * See @ref nrf_qspi_prot_conf_t. - */ -__STATIC_INLINE void nrf_qspi_ifconfig0_set(NRF_QSPI_Type * p_reg, - const nrf_qspi_prot_conf_t * p_config); - -/** - * @brief Function for setting the QSPI IFCONFIG1 register. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] p_config Pointer to the QSPI physical interface configuration structure. - * See @ref nrf_qspi_phy_conf_t. - */ -__STATIC_INLINE void nrf_qspi_ifconfig1_set(NRF_QSPI_Type * p_reg, - const nrf_qspi_phy_conf_t * p_config); - -/** - * @brief Function for setting the QSPI ADDRCONF register. - * - * This function must be executed before sending task NRF_QSPI_TASK_ACTIVATE. Data stored in the structure - * is sent during the start of the peripheral. Remember that the reset instruction can set - * addressing mode to default in the memory device. If memory reset is necessary before configuring - * the addressing mode, use custom instruction feature instead of this function. - * Case with reset: Enable the peripheral without setting ADDRCONF register, send reset instructions - * using a custom instruction feature (reset enable and then reset), set proper addressing mode - * using the custom instruction feature. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] p_config Pointer to the addressing mode configuration structure. - * See @ref nrf_qspi_addrconfig_conf_t. -*/ -__STATIC_INLINE void nrf_qspi_addrconfig_set(NRF_QSPI_Type * p_reg, - const nrf_qspi_addrconfig_conf_t * p_config); - -/** - * @brief Function for setting write data into the peripheral register (without starting the process). - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] p_buffer Pointer to the writing buffer. - * @param[in] length Lenght of the writing data. - * @param[in] dest_addr Address in memory to write to. - */ -__STATIC_INLINE void nrf_qspi_write_buffer_set(NRF_QSPI_Type * p_reg, - void const * p_buffer, - uint32_t length, - uint32_t dest_addr); - -/** - * @brief Function for setting read data into the peripheral register (without starting the process). - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[out] p_buffer Pointer to the reading buffer. - * @param[in] length Length of the read data. - * @param[in] src_addr Address in memory to read from. - */ -__STATIC_INLINE void nrf_qspi_read_buffer_set(NRF_QSPI_Type * p_reg, - void * p_buffer, - uint32_t length, - uint32_t src_addr); - -/** - * @brief Function for setting erase data into the peripheral register (without starting the process). - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] erase_addr Start address to erase. Address must have padding set to 4 bytes. - * @param[in] len Size of erasing area. - */ -__STATIC_INLINE void nrf_qspi_erase_ptr_set(NRF_QSPI_Type * p_reg, - uint32_t erase_addr, - nrf_qspi_erase_len_t len); - -/** - * @brief Function for getting the peripheral status register. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * - * @return Peripheral status register. - */ -__STATIC_INLINE uint32_t nrf_qspi_status_reg_get(NRF_QSPI_Type const * p_reg); - -/** - * @brief Function for getting the device status register stored in the peripheral status register. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * - * @return Device status register (lower byte). - */ -__STATIC_INLINE uint8_t nrf_qspi_sreg_get(NRF_QSPI_Type const * p_reg); - -/** - * @brief Function for checking if the peripheral is busy or not. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * - * @retval true The QSPI is busy. - * @retval false The QSPI is ready. - */ -__STATIC_INLINE bool nrf_qspi_busy_check(NRF_QSPI_Type const * p_reg); - -/** - * @brief Function for setting registers sending with custom instruction transmission. - * - * This function can be ommited when using NRF_QSPI_CINSTR_LEN_1B as the length argument - * (sending only opcode without data). - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] length Length of the custom instruction data. - * @param[in] p_tx_data Pointer to the data to send with the custom instruction. - */ -__STATIC_INLINE void nrf_qspi_cinstrdata_set(NRF_QSPI_Type * p_reg, - nrf_qspi_cinstr_len_t length, - void const * p_tx_data); - -/** - * @brief Function for getting data from register after custom instruction transmission. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] length Length of the custom instruction data. - * @param[in] p_rx_data Pointer to the reading buffer. - */ -__STATIC_INLINE void nrf_qspi_cinstrdata_get(NRF_QSPI_Type const * p_reg, - nrf_qspi_cinstr_len_t length, - void * p_rx_data); - -/** - * @brief Function for sending custom instruction to external memory. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] p_config Pointer to the custom instruction configuration structure. - * See @ref nrf_qspi_cinstr_conf_t. - */ - -__STATIC_INLINE void nrf_qspi_cinstr_transfer_start(NRF_QSPI_Type * p_reg, - const nrf_qspi_cinstr_conf_t * p_config); - -/** - * @brief Function for starting a custom instruction long transfer. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] p_config Pointer to the custom instruction configuration structure. - * See @ref nrf_qspi_cinstr_conf_t. - */ -__STATIC_INLINE void nrf_qspi_cinstr_long_transfer_start(NRF_QSPI_Type * p_reg, - const nrf_qspi_cinstr_conf_t * p_config); - -/** - * @brief Function for checking whether a custom instruction long transfer is ongoing. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * - * @retval true Custom instruction long transfer is ongoing. - * @retval false Custom instruction long transfer is not ongoing. - */ -__STATIC_INLINE bool nrf_qspi_cinstr_long_transfer_is_ongoing(NRF_QSPI_Type const * p_reg); - -/** - * @brief Function for continuing a custom instruction long transfer. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] length Length of the custom instruction data. - * @param[in] finalize True if the custom instruction long transfer is to be finalized. - * False if the custom instruction long transfer is to be continued. - */ -__STATIC_INLINE void nrf_qspi_cinstr_long_transfer_continue(NRF_QSPI_Type * p_reg, - nrf_qspi_cinstr_len_t length, - bool finalize); - -#ifndef SUPPRESS_INLINE_IMPLEMENTATION - -__STATIC_INLINE void nrf_qspi_task_trigger(NRF_QSPI_Type * p_reg, nrf_qspi_task_t task) -{ - *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task)) = 0x1UL; -} - -__STATIC_INLINE uint32_t nrf_qspi_task_address_get(NRF_QSPI_Type const * p_reg, - nrf_qspi_task_t task) -{ - return ((uint32_t)p_reg + (uint32_t)task); -} - -__STATIC_INLINE void nrf_qspi_event_clear(NRF_QSPI_Type * p_reg, nrf_qspi_event_t event) -{ - *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)) = 0x0UL; -} - -__STATIC_INLINE bool nrf_qspi_event_check(NRF_QSPI_Type const * p_reg, nrf_qspi_event_t event) -{ - return (bool)*(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event); -} - -__STATIC_INLINE uint32_t * nrf_qspi_event_address_get(NRF_QSPI_Type const * p_reg, - nrf_qspi_event_t event) -{ - return (uint32_t *)((uint8_t *)p_reg + (uint32_t)event); -} - -__STATIC_INLINE void nrf_qspi_int_enable(NRF_QSPI_Type * p_reg, uint32_t mask) -{ - p_reg->INTENSET = mask; -} - -__STATIC_INLINE void nrf_qspi_int_disable(NRF_QSPI_Type * p_reg, uint32_t mask) -{ - p_reg->INTENCLR = mask; -} - -__STATIC_INLINE bool nrf_qspi_int_enable_check(NRF_QSPI_Type const * p_reg, - nrf_qspi_int_mask_t qspi_int) -{ - return (bool)(p_reg->INTENSET & qspi_int); -} - -__STATIC_INLINE void nrf_qspi_enable(NRF_QSPI_Type * p_reg) -{ - p_reg->ENABLE = (QSPI_ENABLE_ENABLE_Enabled << QSPI_ENABLE_ENABLE_Pos); -} - -__STATIC_INLINE void nrf_qspi_disable(NRF_QSPI_Type * p_reg) -{ - // Workaround for nRF52840 anomaly 122: Current consumption is too high. - *(volatile uint32_t *)0x40029054ul = 1ul; - - p_reg->ENABLE = (QSPI_ENABLE_ENABLE_Disabled << QSPI_ENABLE_ENABLE_Pos); -} - -__STATIC_INLINE void nrf_qspi_pins_set(NRF_QSPI_Type * p_reg, const nrf_qspi_pins_t * p_pins) -{ - p_reg->PSEL.SCK = NRF_QSPI_PIN_VAL(p_pins->sck_pin); - p_reg->PSEL.CSN = NRF_QSPI_PIN_VAL(p_pins->csn_pin); - p_reg->PSEL.IO0 = NRF_QSPI_PIN_VAL(p_pins->io0_pin); - p_reg->PSEL.IO1 = NRF_QSPI_PIN_VAL(p_pins->io1_pin); - p_reg->PSEL.IO2 = NRF_QSPI_PIN_VAL(p_pins->io2_pin); - p_reg->PSEL.IO3 = NRF_QSPI_PIN_VAL(p_pins->io3_pin); -} - -__STATIC_INLINE void nrf_qspi_pins_get(NRF_QSPI_Type const * p_reg, - nrf_qspi_pins_t * p_pins) -{ - p_pins->sck_pin = (uint8_t)p_reg->PSEL.SCK; - p_pins->csn_pin = (uint8_t)p_reg->PSEL.CSN; - p_pins->io0_pin = (uint8_t)p_reg->PSEL.IO0; - p_pins->io1_pin = (uint8_t)p_reg->PSEL.IO1; - p_pins->io2_pin = (uint8_t)p_reg->PSEL.IO2; - p_pins->io3_pin = (uint8_t)p_reg->PSEL.IO3; -} - -__STATIC_INLINE void nrf_qspi_xip_offset_set(NRF_QSPI_Type * p_reg, - uint32_t xip_offset) -{ - p_reg->XIPOFFSET = xip_offset; -} - -__STATIC_INLINE void nrf_qspi_ifconfig0_set(NRF_QSPI_Type * p_reg, - const nrf_qspi_prot_conf_t * p_config) -{ - uint32_t config = p_config->readoc; - config |= ((uint32_t)p_config->writeoc) << QSPI_IFCONFIG0_WRITEOC_Pos; - config |= ((uint32_t)p_config->addrmode) << QSPI_IFCONFIG0_ADDRMODE_Pos; - config |= (p_config->dpmconfig ? 1U : 0U ) << QSPI_IFCONFIG0_DPMENABLE_Pos; - - p_reg->IFCONFIG0 = config; -} - -__STATIC_INLINE void nrf_qspi_ifconfig1_set(NRF_QSPI_Type * p_reg, - const nrf_qspi_phy_conf_t * p_config) -{ - // IFCONFIG1 mask for reserved fields in the register. - uint32_t config = p_reg->IFCONFIG1 & 0x00FFFF00; - config |= p_config->sck_delay; - config |= (p_config->dpmen ? 1U : 0U) << QSPI_IFCONFIG1_DPMEN_Pos; - config |= ((uint32_t)(p_config->spi_mode)) << QSPI_IFCONFIG1_SPIMODE_Pos; - config |= ((uint32_t)(p_config->sck_freq)) << QSPI_IFCONFIG1_SCKFREQ_Pos; - - p_reg->IFCONFIG1 = config; -} - -__STATIC_INLINE void nrf_qspi_addrconfig_set(NRF_QSPI_Type * p_reg, - const nrf_qspi_addrconfig_conf_t * p_config) -{ - uint32_t config = p_config->opcode; - config |= ((uint32_t)p_config->byte0) << QSPI_ADDRCONF_BYTE0_Pos; - config |= ((uint32_t)p_config->byte1) << QSPI_ADDRCONF_BYTE1_Pos; - config |= ((uint32_t)(p_config->mode)) << QSPI_ADDRCONF_MODE_Pos; - config |= (p_config->wipwait ? 1U : 0U) << QSPI_ADDRCONF_WIPWAIT_Pos; - config |= (p_config->wren ? 1U : 0U) << QSPI_ADDRCONF_WREN_Pos; - - p_reg->ADDRCONF = config; -} - -__STATIC_INLINE void nrf_qspi_write_buffer_set(NRF_QSPI_Type * p_reg, - void const * p_buffer, - uint32_t length, - uint32_t dest_addr) -{ - p_reg->WRITE.DST = dest_addr; - p_reg->WRITE.SRC = (uint32_t) p_buffer; - p_reg->WRITE.CNT = length; -} - -__STATIC_INLINE void nrf_qspi_read_buffer_set(NRF_QSPI_Type * p_reg, - void * p_buffer, - uint32_t length, - uint32_t src_addr) -{ - p_reg->READ.SRC = src_addr; - p_reg->READ.DST = (uint32_t) p_buffer; - p_reg->READ.CNT = length; -} - -__STATIC_INLINE void nrf_qspi_erase_ptr_set(NRF_QSPI_Type * p_reg, - uint32_t erase_addr, - nrf_qspi_erase_len_t len) -{ - p_reg->ERASE.PTR = erase_addr; - p_reg->ERASE.LEN = len; -} - -__STATIC_INLINE uint32_t nrf_qspi_status_reg_get(NRF_QSPI_Type const * p_reg) -{ - return p_reg->STATUS; -} - -__STATIC_INLINE uint8_t nrf_qspi_sreg_get(NRF_QSPI_Type const * p_reg) -{ - return (uint8_t)(p_reg->STATUS & QSPI_STATUS_SREG_Msk) >> QSPI_STATUS_SREG_Pos; -} - -__STATIC_INLINE bool nrf_qspi_busy_check(NRF_QSPI_Type const * p_reg) -{ - return ((p_reg->STATUS & QSPI_STATUS_READY_Msk) >> - QSPI_STATUS_READY_Pos) == QSPI_STATUS_READY_BUSY; -} - -__STATIC_INLINE void nrf_qspi_cinstrdata_set(NRF_QSPI_Type * p_reg, - nrf_qspi_cinstr_len_t length, - void const * p_tx_data) -{ - uint32_t reg = 0; - uint8_t const *p_tx_data_8 = (uint8_t const *) p_tx_data; - - // Load custom instruction. - switch (length) - { - case NRF_QSPI_CINSTR_LEN_9B: - reg |= ((uint32_t)p_tx_data_8[7]) << QSPI_CINSTRDAT1_BYTE7_Pos; - /* fall-through */ - case NRF_QSPI_CINSTR_LEN_8B: - reg |= ((uint32_t)p_tx_data_8[6]) << QSPI_CINSTRDAT1_BYTE6_Pos; - /* fall-through */ - case NRF_QSPI_CINSTR_LEN_7B: - reg |= ((uint32_t)p_tx_data_8[5]) << QSPI_CINSTRDAT1_BYTE5_Pos; - /* fall-through */ - case NRF_QSPI_CINSTR_LEN_6B: - reg |= ((uint32_t)p_tx_data_8[4]); - p_reg->CINSTRDAT1 = reg; - reg = 0; - /* fall-through */ - case NRF_QSPI_CINSTR_LEN_5B: - reg |= ((uint32_t)p_tx_data_8[3]) << QSPI_CINSTRDAT0_BYTE3_Pos; - /* fall-through */ - case NRF_QSPI_CINSTR_LEN_4B: - reg |= ((uint32_t)p_tx_data_8[2]) << QSPI_CINSTRDAT0_BYTE2_Pos; - /* fall-through */ - case NRF_QSPI_CINSTR_LEN_3B: - reg |= ((uint32_t)p_tx_data_8[1]) << QSPI_CINSTRDAT0_BYTE1_Pos; - /* fall-through */ - case NRF_QSPI_CINSTR_LEN_2B: - reg |= ((uint32_t)p_tx_data_8[0]); - p_reg->CINSTRDAT0 = reg; - /* fall-through */ - case NRF_QSPI_CINSTR_LEN_1B: - /* Send only opcode. Case to avoid compiler warnings. */ - break; - default: - break; - } -} - -__STATIC_INLINE void nrf_qspi_cinstrdata_get(NRF_QSPI_Type const * p_reg, - nrf_qspi_cinstr_len_t length, - void * p_rx_data) -{ - uint8_t *p_rx_data_8 = (uint8_t *) p_rx_data; - - uint32_t reg1 = p_reg->CINSTRDAT1; - uint32_t reg0 = p_reg->CINSTRDAT0; - switch (length) - { - case NRF_QSPI_CINSTR_LEN_9B: - p_rx_data_8[7] = (uint8_t)(reg1 >> QSPI_CINSTRDAT1_BYTE7_Pos); - /* fall-through */ - case NRF_QSPI_CINSTR_LEN_8B: - p_rx_data_8[6] = (uint8_t)(reg1 >> QSPI_CINSTRDAT1_BYTE6_Pos); - /* fall-through */ - case NRF_QSPI_CINSTR_LEN_7B: - p_rx_data_8[5] = (uint8_t)(reg1 >> QSPI_CINSTRDAT1_BYTE5_Pos); - /* fall-through */ - case NRF_QSPI_CINSTR_LEN_6B: - p_rx_data_8[4] = (uint8_t)(reg1); - /* fall-through */ - case NRF_QSPI_CINSTR_LEN_5B: - p_rx_data_8[3] = (uint8_t)(reg0 >> QSPI_CINSTRDAT0_BYTE3_Pos); - /* fall-through */ - case NRF_QSPI_CINSTR_LEN_4B: - p_rx_data_8[2] = (uint8_t)(reg0 >> QSPI_CINSTRDAT0_BYTE2_Pos); - /* fall-through */ - case NRF_QSPI_CINSTR_LEN_3B: - p_rx_data_8[1] = (uint8_t)(reg0 >> QSPI_CINSTRDAT0_BYTE1_Pos); - /* fall-through */ - case NRF_QSPI_CINSTR_LEN_2B: - p_rx_data_8[0] = (uint8_t)(reg0); - /* fall-through */ - case NRF_QSPI_CINSTR_LEN_1B: - /* Send only opcode. Case to avoid compiler warnings. */ - break; - default: - break; - } -} - -__STATIC_INLINE void nrf_qspi_cinstr_transfer_start(NRF_QSPI_Type * p_reg, - const nrf_qspi_cinstr_conf_t * p_config) -{ - p_reg->CINSTRCONF = (((uint32_t)p_config->opcode << QSPI_CINSTRCONF_OPCODE_Pos) | - ((uint32_t)p_config->length << QSPI_CINSTRCONF_LENGTH_Pos) | - ((uint32_t)p_config->io2_level << QSPI_CINSTRCONF_LIO2_Pos) | - ((uint32_t)p_config->io3_level << QSPI_CINSTRCONF_LIO3_Pos) | - ((uint32_t)p_config->wipwait << QSPI_CINSTRCONF_WIPWAIT_Pos) | - ((uint32_t)p_config->wren << QSPI_CINSTRCONF_WREN_Pos)); -} - -__STATIC_INLINE void nrf_qspi_cinstr_long_transfer_start(NRF_QSPI_Type * p_reg, - const nrf_qspi_cinstr_conf_t * p_config) -{ - p_reg->CINSTRCONF = (((uint32_t)p_config->opcode << QSPI_CINSTRCONF_OPCODE_Pos) | - ((uint32_t)p_config->length << QSPI_CINSTRCONF_LENGTH_Pos) | - ((uint32_t)p_config->io2_level << QSPI_CINSTRCONF_LIO2_Pos) | - ((uint32_t)p_config->io3_level << QSPI_CINSTRCONF_LIO3_Pos) | - ((uint32_t)p_config->wipwait << QSPI_CINSTRCONF_WIPWAIT_Pos) | - ((uint32_t)p_config->wren << QSPI_CINSTRCONF_WREN_Pos) | - (QSPI_CINSTRCONF_LFEN_Msk)); -} - -__STATIC_INLINE bool nrf_qspi_cinstr_long_transfer_is_ongoing(NRF_QSPI_Type const * p_reg) -{ - return (bool)((p_reg->CINSTRCONF & (QSPI_CINSTRCONF_LFEN_Msk | QSPI_CINSTRCONF_LFSTOP_Msk)) - == QSPI_CINSTRCONF_LFEN_Msk); -} - -__STATIC_INLINE void nrf_qspi_cinstr_long_transfer_continue(NRF_QSPI_Type * p_reg, - nrf_qspi_cinstr_len_t length, - bool finalize) -{ - uint32_t mask = (((uint32_t)length << QSPI_CINSTRCONF_LENGTH_Pos) | (QSPI_CINSTRCONF_LFEN_Msk)); - mask |= (finalize ? QSPI_CINSTRCONF_LFSTOP_Msk : 0); - - p_reg->CINSTRCONF = mask; -} - -#endif // SUPPRESS_INLINE_IMPLEMENTATION - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif // NRF_QSPI_H__ diff --git a/modules/nrfx/hal/nrf_spis.h b/modules/nrfx/hal/nrf_spis.h deleted file mode 100644 index aa22fa3..0000000 --- a/modules/nrfx/hal/nrf_spis.h +++ /dev/null @@ -1,628 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_SPIS_H__ -#define NRF_SPIS_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_spis_hal SPIS HAL - * @{ - * @ingroup nrf_spis - * @brief Hardware access layer for managing the SPIS peripheral. - */ - -/** - * @brief This value can be used as a parameter for the @ref nrf_spis_pins_set - * function to specify that a given SPI signal (SCK, MOSI, or MISO) - * shall not be connected to a physical pin. - */ -#define NRF_SPIS_PIN_NOT_CONNECTED 0xFFFFFFFF - - -/** @brief SPIS tasks. */ -typedef enum -{ - NRF_SPIS_TASK_ACQUIRE = offsetof(NRF_SPIS_Type, TASKS_ACQUIRE), ///< Acquire SPI semaphore. - NRF_SPIS_TASK_RELEASE = offsetof(NRF_SPIS_Type, TASKS_RELEASE), ///< Release SPI semaphore, enabling the SPI slave to acquire it. -} nrf_spis_task_t; - -/** @brief SPIS events. */ -typedef enum -{ - NRF_SPIS_EVENT_END = offsetof(NRF_SPIS_Type, EVENTS_END), ///< Granted transaction completed. - NRF_SPIS_EVENT_ACQUIRED = offsetof(NRF_SPIS_Type, EVENTS_ACQUIRED) ///< Semaphore acquired. -} nrf_spis_event_t; - -/** @brief SPIS shortcuts. */ -typedef enum -{ - NRF_SPIS_SHORT_END_ACQUIRE = SPIS_SHORTS_END_ACQUIRE_Msk ///< Shortcut between END event and ACQUIRE task. -} nrf_spis_short_mask_t; - -/** @brief SPIS interrupts. */ -typedef enum -{ - NRF_SPIS_INT_END_MASK = SPIS_INTENSET_END_Msk, ///< Interrupt on END event. - NRF_SPIS_INT_ACQUIRED_MASK = SPIS_INTENSET_ACQUIRED_Msk ///< Interrupt on ACQUIRED event. -} nrf_spis_int_mask_t; - -/** @brief SPI modes. */ -typedef enum -{ - NRF_SPIS_MODE_0, ///< SCK active high, sample on leading edge of clock. - NRF_SPIS_MODE_1, ///< SCK active high, sample on trailing edge of clock. - NRF_SPIS_MODE_2, ///< SCK active low, sample on leading edge of clock. - NRF_SPIS_MODE_3 ///< SCK active low, sample on trailing edge of clock. -} nrf_spis_mode_t; - -/** @brief SPI bit orders. */ -typedef enum -{ - NRF_SPIS_BIT_ORDER_MSB_FIRST = SPIS_CONFIG_ORDER_MsbFirst, ///< Most significant bit shifted out first. - NRF_SPIS_BIT_ORDER_LSB_FIRST = SPIS_CONFIG_ORDER_LsbFirst ///< Least significant bit shifted out first. -} nrf_spis_bit_order_t; - -/** @brief SPI semaphore status. */ -typedef enum -{ - NRF_SPIS_SEMSTAT_FREE = 0, ///< Semaphore is free. - NRF_SPIS_SEMSTAT_CPU = 1, ///< Semaphore is assigned to the CPU. - NRF_SPIS_SEMSTAT_SPIS = 2, ///< Semaphore is assigned to the SPI slave. - NRF_SPIS_SEMSTAT_CPUPENDING = 3 ///< Semaphore is assigned to the SPI, but a handover to the CPU is pending. -} nrf_spis_semstat_t; - -/** @brief SPIS status. */ -typedef enum -{ - NRF_SPIS_STATUS_OVERREAD = SPIS_STATUS_OVERREAD_Msk, ///< TX buffer over-read detected and prevented. - NRF_SPIS_STATUS_OVERFLOW = SPIS_STATUS_OVERFLOW_Msk ///< RX buffer overflow detected and prevented. -} nrf_spis_status_mask_t; - - -/** - * @brief Function for activating the specified SPIS task. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] task Task to be activated. - */ -__STATIC_INLINE void nrf_spis_task_trigger(NRF_SPIS_Type * p_reg, - nrf_spis_task_t task); - -/** - * @brief Function for getting the address of the specified SPIS task register. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] task The specified task. - * - * @return Address of the specified task register. - */ -__STATIC_INLINE uint32_t nrf_spis_task_address_get(NRF_SPIS_Type const * p_reg, - nrf_spis_task_t task); - -/** - * @brief Function for clearing the specified SPIS event. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] event Event to be cleared. - */ -__STATIC_INLINE void nrf_spis_event_clear(NRF_SPIS_Type * p_reg, - nrf_spis_event_t event); - -/** - * @brief Function for retrieving the state of the SPIS event. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] event Event to be checked. - * - * @retval true The event has been generated. - * @retval false The event has not been generated. - */ -__STATIC_INLINE bool nrf_spis_event_check(NRF_SPIS_Type const * p_reg, - nrf_spis_event_t event); - -/** - * @brief Function for getting the address of the specified SPIS event register. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] event The specified event. - * - * @return Address of the specified event register. - */ -__STATIC_INLINE uint32_t nrf_spis_event_address_get(NRF_SPIS_Type const * p_reg, - nrf_spis_event_t event); - -/** - * @brief Function for enabling the specified shortcuts. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] mask Shortcuts to be enabled. - */ -__STATIC_INLINE void nrf_spis_shorts_enable(NRF_SPIS_Type * p_reg, - uint32_t mask); - -/** - * @brief Function for disabling the specified shortcuts. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] mask Shortcuts to be disabled. - */ -__STATIC_INLINE void nrf_spis_shorts_disable(NRF_SPIS_Type * p_reg, - uint32_t mask); - -/** - * @brief Function for enabling the specified interrupts. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] mask Mask of interrupts to be enabled. - */ -__STATIC_INLINE void nrf_spis_int_enable(NRF_SPIS_Type * p_reg, - uint32_t mask); - -/** - * @brief Function for disabling the specified interrupts. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] mask Mask of interrupts to be disabled. - */ -__STATIC_INLINE void nrf_spis_int_disable(NRF_SPIS_Type * p_reg, - uint32_t mask); - -/** - * @brief Function for retrieving the state of a given interrupt. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] spis_int Interrupt to be checked. - * - * @retval true The interrupt is enabled. - * @retval false The interrupt is not enabled. - */ -__STATIC_INLINE bool nrf_spis_int_enable_check(NRF_SPIS_Type const * p_reg, - nrf_spis_int_mask_t spis_int); - -#if defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__) -/** - * @brief Function for setting the subscribe configuration for a given - * SPIS task. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] task Task for which to set the configuration. - * @param[in] channel Channel through which to subscribe events. - */ -__STATIC_INLINE void nrf_spis_subscribe_set(NRF_SPIS_Type * p_reg, - nrf_spis_task_t task, - uint8_t channel); - -/** - * @brief Function for clearing the subscribe configuration for a given - * SPIS task. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] task Task for which to clear the configuration. - */ -__STATIC_INLINE void nrf_spis_subscribe_clear(NRF_SPIS_Type * p_reg, - nrf_spis_task_t task); - -/** - * @brief Function for setting the publish configuration for a given - * SPIS event. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] event Event for which to set the configuration. - * @param[in] channel Channel through which to publish the event. - */ -__STATIC_INLINE void nrf_spis_publish_set(NRF_SPIS_Type * p_reg, - nrf_spis_event_t event, - uint8_t channel); - -/** - * @brief Function for clearing the publish configuration for a given - * SPIS event. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] event Event for which to clear the configuration. - */ -__STATIC_INLINE void nrf_spis_publish_clear(NRF_SPIS_Type * p_reg, - nrf_spis_event_t event); -#endif // defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__) - -/** - * @brief Function for enabling the SPIS peripheral. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - */ -__STATIC_INLINE void nrf_spis_enable(NRF_SPIS_Type * p_reg); - -/** - * @brief Function for disabling the SPIS peripheral. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - */ -__STATIC_INLINE void nrf_spis_disable(NRF_SPIS_Type * p_reg); - -/** - * @brief Function for retrieving the SPIS semaphore status. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * - * @returns Current semaphore status. - */ -__STATIC_INLINE nrf_spis_semstat_t nrf_spis_semaphore_status_get(NRF_SPIS_Type * p_reg); - -/** - * @brief Function for retrieving the SPIS status. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * - * @returns Current SPIS status. - */ -__STATIC_INLINE nrf_spis_status_mask_t nrf_spis_status_get(NRF_SPIS_Type * p_reg); - -/** - * @brief Function for configuring SPIS pins. - * - * If a given signal is not needed, pass the @ref NRF_SPIS_PIN_NOT_CONNECTED - * value instead of its pin number. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] sck_pin SCK pin number. - * @param[in] mosi_pin MOSI pin number. - * @param[in] miso_pin MISO pin number. - * @param[in] csn_pin CSN pin number. - */ -__STATIC_INLINE void nrf_spis_pins_set(NRF_SPIS_Type * p_reg, - uint32_t sck_pin, - uint32_t mosi_pin, - uint32_t miso_pin, - uint32_t csn_pin); - -/** - * @brief Function for setting the transmit buffer. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] p_buffer Pointer to the buffer that contains the data to send. - * @param[in] length Maximum number of data bytes to transmit. - */ -__STATIC_INLINE void nrf_spis_tx_buffer_set(NRF_SPIS_Type * p_reg, - uint8_t const * p_buffer, - size_t length); - -/** - * @brief Function for setting the receive buffer. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] p_buffer Pointer to the buffer for received data. - * @param[in] length Maximum number of data bytes to receive. - */ -__STATIC_INLINE void nrf_spis_rx_buffer_set(NRF_SPIS_Type * p_reg, - uint8_t * p_buffer, - size_t length); - -/** - * @brief Function for getting the number of bytes transmitted - * in the last granted transaction. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * - * @returns Number of bytes transmitted. - */ -__STATIC_INLINE size_t nrf_spis_tx_amount_get(NRF_SPIS_Type const * p_reg); - -/** - * @brief Function for getting the number of bytes received - * in the last granted transaction. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * - * @returns Number of bytes received. - */ -__STATIC_INLINE size_t nrf_spis_rx_amount_get(NRF_SPIS_Type const * p_reg); - -/** - * @brief Function for setting the SPI configuration. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] spi_mode SPI mode. - * @param[in] spi_bit_order SPI bit order. - */ -__STATIC_INLINE void nrf_spis_configure(NRF_SPIS_Type * p_reg, - nrf_spis_mode_t spi_mode, - nrf_spis_bit_order_t spi_bit_order); - -/** - * @brief Function for setting the default character. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] def Default character that is clocked out in case of - * an overflow of the RXD buffer. - */ -__STATIC_INLINE void nrf_spis_def_set(NRF_SPIS_Type * p_reg, - uint8_t def); - -/** - * @brief Function for setting the over-read character. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] orc Over-read character that is clocked out in case of - * an over-read of the TXD buffer. - */ -__STATIC_INLINE void nrf_spis_orc_set(NRF_SPIS_Type * p_reg, - uint8_t orc); - - -#ifndef SUPPRESS_INLINE_IMPLEMENTATION - -__STATIC_INLINE void nrf_spis_task_trigger(NRF_SPIS_Type * p_reg, - nrf_spis_task_t task) -{ - *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task)) = 0x1UL; -} - -__STATIC_INLINE uint32_t nrf_spis_task_address_get(NRF_SPIS_Type const * p_reg, - nrf_spis_task_t task) -{ - return (uint32_t)p_reg + (uint32_t)task; -} - -__STATIC_INLINE void nrf_spis_event_clear(NRF_SPIS_Type * p_reg, - nrf_spis_event_t event) -{ - *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)) = 0x0UL; -#if __CORTEX_M == 0x04 - volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)); - (void)dummy; -#endif -} - -__STATIC_INLINE bool nrf_spis_event_check(NRF_SPIS_Type const * p_reg, - nrf_spis_event_t event) -{ - return (bool)*(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event); -} - -__STATIC_INLINE uint32_t nrf_spis_event_address_get(NRF_SPIS_Type const * p_reg, - nrf_spis_event_t event) -{ - return (uint32_t)p_reg + (uint32_t)event; -} - -__STATIC_INLINE void nrf_spis_shorts_enable(NRF_SPIS_Type * p_reg, - uint32_t mask) -{ - p_reg->SHORTS |= mask; -} - -__STATIC_INLINE void nrf_spis_shorts_disable(NRF_SPIS_Type * p_reg, - uint32_t mask) -{ - p_reg->SHORTS &= ~(mask); -} - -__STATIC_INLINE void nrf_spis_int_enable(NRF_SPIS_Type * p_reg, - uint32_t mask) -{ - p_reg->INTENSET = mask; -} - -__STATIC_INLINE void nrf_spis_int_disable(NRF_SPIS_Type * p_reg, - uint32_t mask) -{ - p_reg->INTENCLR = mask; -} - -__STATIC_INLINE bool nrf_spis_int_enable_check(NRF_SPIS_Type const * p_reg, - nrf_spis_int_mask_t spis_int) -{ - return (bool)(p_reg->INTENSET & spis_int); -} - -#if defined(DPPI_PRESENT) -__STATIC_INLINE void nrf_spis_subscribe_set(NRF_SPIS_Type * p_reg, - nrf_spis_task_t task, - uint8_t channel) -{ - *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = - ((uint32_t)channel | SPIS_SUBSCRIBE_ACQUIRE_EN_Msk); -} - -__STATIC_INLINE void nrf_spis_subscribe_clear(NRF_SPIS_Type * p_reg, - nrf_spis_task_t task) -{ - *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0; -} - -__STATIC_INLINE void nrf_spis_publish_set(NRF_SPIS_Type * p_reg, - nrf_spis_event_t event, - uint8_t channel) -{ - *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) event + 0x80uL)) = - ((uint32_t)channel | SPIS_PUBLISH_END_EN_Msk); -} - -__STATIC_INLINE void nrf_spis_publish_clear(NRF_SPIS_Type * p_reg, - nrf_spis_event_t event) -{ - *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) event + 0x80uL)) = 0; -} -#endif // defined(DPPI_PRESENT) - -__STATIC_INLINE void nrf_spis_enable(NRF_SPIS_Type * p_reg) -{ - p_reg->ENABLE = (SPIS_ENABLE_ENABLE_Enabled << SPIS_ENABLE_ENABLE_Pos); -} - -__STATIC_INLINE void nrf_spis_disable(NRF_SPIS_Type * p_reg) -{ - p_reg->ENABLE = (SPIS_ENABLE_ENABLE_Disabled << SPIS_ENABLE_ENABLE_Pos); -} - -__STATIC_INLINE nrf_spis_semstat_t nrf_spis_semaphore_status_get(NRF_SPIS_Type * p_reg) -{ - return (nrf_spis_semstat_t) ((p_reg->SEMSTAT & SPIS_SEMSTAT_SEMSTAT_Msk) - >> SPIS_SEMSTAT_SEMSTAT_Pos); -} - -__STATIC_INLINE nrf_spis_status_mask_t nrf_spis_status_get(NRF_SPIS_Type * p_reg) -{ - return (nrf_spis_status_mask_t) p_reg->STATUS; -} - -__STATIC_INLINE void nrf_spis_pins_set(NRF_SPIS_Type * p_reg, - uint32_t sck_pin, - uint32_t mosi_pin, - uint32_t miso_pin, - uint32_t csn_pin) -{ -#if defined (NRF51) - p_reg->PSELSCK = sck_pin; - p_reg->PSELMOSI = mosi_pin; - p_reg->PSELMISO = miso_pin; - p_reg->PSELCSN = csn_pin; -#else - p_reg->PSEL.SCK = sck_pin; - p_reg->PSEL.MOSI = mosi_pin; - p_reg->PSEL.MISO = miso_pin; - p_reg->PSEL.CSN = csn_pin; -#endif -} - -__STATIC_INLINE void nrf_spis_tx_buffer_set(NRF_SPIS_Type * p_reg, - uint8_t const * p_buffer, - size_t length) -{ -#if defined (NRF51) - p_reg->TXDPTR = (uint32_t)p_buffer; - p_reg->MAXTX = length; -#else - p_reg->TXD.PTR = (uint32_t)p_buffer; - p_reg->TXD.MAXCNT = length; -#endif -} - -__STATIC_INLINE void nrf_spis_rx_buffer_set(NRF_SPIS_Type * p_reg, - uint8_t * p_buffer, - size_t length) -{ -#if defined (NRF51) - p_reg->RXDPTR = (uint32_t)p_buffer; - p_reg->MAXRX = length; -#else - p_reg->RXD.PTR = (uint32_t)p_buffer; - p_reg->RXD.MAXCNT = length; -#endif -} - -__STATIC_INLINE size_t nrf_spis_tx_amount_get(NRF_SPIS_Type const * p_reg) -{ -#if defined (NRF51) - return p_reg->AMOUNTTX; -#else - return p_reg->TXD.AMOUNT; -#endif -} - -__STATIC_INLINE size_t nrf_spis_rx_amount_get(NRF_SPIS_Type const * p_reg) -{ -#if defined (NRF51) - return p_reg->AMOUNTRX; -#else - return p_reg->RXD.AMOUNT; -#endif -} - -__STATIC_INLINE void nrf_spis_configure(NRF_SPIS_Type * p_reg, - nrf_spis_mode_t spi_mode, - nrf_spis_bit_order_t spi_bit_order) -{ - uint32_t config = (spi_bit_order == NRF_SPIS_BIT_ORDER_MSB_FIRST ? - SPIS_CONFIG_ORDER_MsbFirst : SPIS_CONFIG_ORDER_LsbFirst); - - switch (spi_mode) - { - default: - case NRF_SPIS_MODE_0: - config |= (SPIS_CONFIG_CPOL_ActiveHigh << SPIS_CONFIG_CPOL_Pos) | - (SPIS_CONFIG_CPHA_Leading << SPIS_CONFIG_CPHA_Pos); - break; - - case NRF_SPIS_MODE_1: - config |= (SPIS_CONFIG_CPOL_ActiveHigh << SPIS_CONFIG_CPOL_Pos) | - (SPIS_CONFIG_CPHA_Trailing << SPIS_CONFIG_CPHA_Pos); - break; - - case NRF_SPIS_MODE_2: - config |= (SPIS_CONFIG_CPOL_ActiveLow << SPIS_CONFIG_CPOL_Pos) | - (SPIS_CONFIG_CPHA_Leading << SPIS_CONFIG_CPHA_Pos); - break; - - case NRF_SPIS_MODE_3: - config |= (SPIS_CONFIG_CPOL_ActiveLow << SPIS_CONFIG_CPOL_Pos) | - (SPIS_CONFIG_CPHA_Trailing << SPIS_CONFIG_CPHA_Pos); - break; - } - p_reg->CONFIG = config; -} - -__STATIC_INLINE void nrf_spis_orc_set(NRF_SPIS_Type * p_reg, - uint8_t orc) -{ - p_reg->ORC = orc; -} - -__STATIC_INLINE void nrf_spis_def_set(NRF_SPIS_Type * p_reg, - uint8_t def) -{ - p_reg->DEF = def; -} - -#endif // SUPPRESS_INLINE_IMPLEMENTATION - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif // NRF_SPIS_H__ diff --git a/modules/nrfx/hal/nrf_systick.h b/modules/nrfx/hal/nrf_systick.h deleted file mode 100644 index ce3c9bd..0000000 --- a/modules/nrfx/hal/nrf_systick.h +++ /dev/null @@ -1,189 +0,0 @@ -/** - * Copyright (c) 2016 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_SYSTICK_H__ -#define NRF_SYSTICK_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_systick_hal SYSTICK HAL - * @{ - * @ingroup nrf_systick - * @brief Hardware access layer (HAL) for managing the SYSTICK peripheral. - * - * SYSTICK is a peripheral designed by ARM. - * This means that it does not feature the typical Nordic interface with Tasks and Events. - * - * Its usage is limited here to the implementation of simple delays. - * Moreover, keep in mind that this timer will be stopped when CPU is sleeping - * (WFE/WFI instruction is successfully executed). - */ - -/** - * @brief Mask of usable bits in the SysTick value. - */ -#define NRF_SYSTICK_VAL_MASK SysTick_VAL_CURRENT_Msk - -/** - * @brief Flags used by SysTick configuration. - * - * @sa nrf_systick_csr_set - * @sa nrf_systick_csr_get - */ -typedef enum { - NRF_SYSTICK_CSR_COUNTFLAG_MASK = SysTick_CTRL_COUNTFLAG_Msk, /**< Status flag: Returns 1 if timer counted to 0 since the last read of this register. */ - - NRF_SYSTICK_CSR_CLKSOURCE_MASK = SysTick_CTRL_CLKSOURCE_Msk, /**< Configuration bit: Select the SysTick clock source. */ - NRF_SYSTICK_CSR_CLKSOURCE_REF = 0U << SysTick_CTRL_CLKSOURCE_Pos, /**< Configuration value: Select reference clock. */ - NRF_SYSTICK_CSR_CLKSOURCE_CPU = 1U << SysTick_CTRL_CLKSOURCE_Pos, /**< Configuration value: Select CPU clock. */ - - NRF_SYSTICK_CSR_TICKINT_MASK = SysTick_CTRL_TICKINT_Msk, /**< Configuration bit: Enables SysTick exception request. */ - NRF_SYSTICK_CSR_TICKINT_ENABLE = 1U << SysTick_CTRL_TICKINT_Pos, /**< Configuration value: Counting down to zero does not assert the SysTick exception request. */ - NRF_SYSTICK_CSR_TICKINT_DISABLE = 0U << SysTick_CTRL_TICKINT_Pos, /**< Configuration value: Counting down to zero to asserts the SysTick exception request. */ - - NRF_SYSTICK_CSR_ENABLE_MASK = SysTick_CTRL_ENABLE_Msk, /**< Configuration bit: Enable the SysTick timer. */ - NRF_SYSTICK_CSR_ENABLE = 1U << SysTick_CTRL_ENABLE_Pos, /**< Configuration value: Counter enabled. */ - NRF_SYSTICK_CSR_DISABLE = 0U << SysTick_CTRL_ENABLE_Pos /**< Configuration value: Counter disabled. */ -} nrf_systick_csr_flags_t; - -/** - * @brief Function for getting Configuration and Status Register. - * - * @note The @ref NRF_SYSTICK_CSR_COUNTFLAG_MASK value is cleared when CSR register is read. - * @return Values composed by @ref nrf_systick_csr_flags_t. - */ -__STATIC_INLINE uint32_t nrf_systick_csr_get(void); - -/** - * @brief Function for setting Configuration and Status Register. - * - * @param[in] val The value composed from @ref nrf_systick_csr_flags_t. - */ -__STATIC_INLINE void nrf_systick_csr_set(uint32_t val); - -/** - * @brief Function for getting the current reload value. - * - * @return The reload register value. - */ -__STATIC_INLINE uint32_t nrf_systick_load_get(void); - -/** - * @brief Function for configuring the reload value. - * - * @param[in] val The value to be set in the reload register. - */ -__STATIC_INLINE void nrf_systick_load_set(uint32_t val); - -/** - * @brief Function for reading the SysTick current value. - * - * @return The current SysTick value - * @sa NRF_SYSTICK_VAL_MASK - */ -__STATIC_INLINE uint32_t nrf_systick_val_get(void); - -/** - * @brief Function for clearing the SysTick current value. - * - * @note The SysTick does not allow setting current value. - * Any write to VAL register would clear the timer. - */ -__STATIC_INLINE void nrf_systick_val_clear(void); - -/** - * @brief Function for reading the calibration register. - * - * @return The calibration register value. - */ -__STATIC_INLINE uint32_t nrf_systick_calib_get(void); - - -#ifndef SUPPRESS_INLINE_IMPLEMENTATION - -__STATIC_INLINE uint32_t nrf_systick_csr_get(void) -{ - return SysTick->CTRL; -} - -__STATIC_INLINE void nrf_systick_csr_set(uint32_t val) -{ - SysTick->CTRL = val; -} - -__STATIC_INLINE uint32_t nrf_systick_load_get(void) -{ - return SysTick->LOAD; -} - -__STATIC_INLINE void nrf_systick_load_set(uint32_t val) -{ - SysTick->LOAD = val; -} - -__STATIC_INLINE uint32_t nrf_systick_val_get(void) -{ - return SysTick->VAL; -} - -__STATIC_INLINE void nrf_systick_val_clear(void) -{ - SysTick->VAL = 0; -} - -__STATIC_INLINE uint32_t nrf_systick_calib_get(void) -{ - return SysTick->CALIB; -} - -#endif /* SUPPRESS_INLINE_IMPLEMENTATION */ - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif /* NRF_SYSTICK_H__ */ diff --git a/modules/nrfx/hal/nrf_temp.h b/modules/nrfx/hal/nrf_temp.h deleted file mode 100644 index e4845b1..0000000 --- a/modules/nrfx/hal/nrf_temp.h +++ /dev/null @@ -1,274 +0,0 @@ -/** - * Copyright (c) 2012 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_TEMP_H__ -#define NRF_TEMP_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** -* @defgroup nrf_temp_hal_deprecated TEMP HAL (deprecated) -* @{ -* @ingroup nrf_temp -* @brief Temperature module init and read functions. -*/ - -/** @brief Workaround specific define - sign mask.*/ -#define MASK_SIGN (0x00000200UL) - -/** @brief Workaround specific define - sign extension mask.*/ -#define MASK_SIGN_EXTENSION (0xFFFFFC00UL) - -/** - * @brief Function for preparing the TEMP module for temperature measurement. - * - * This function initializes the TEMP module and writes to the hidden configuration register. - */ -static __INLINE void nrf_temp_init(void) -{ - /**@note Workaround for PAN_028 rev2.0A anomaly 31 - TEMP: Temperature offset value has to be manually loaded to the TEMP module */ - *(uint32_t *) 0x4000C504 = 0; -} - -/** - * @brief Function for reading temperature measurement. - * - * The function reads the 10-bit 2's complement value and transforms it to a 32-bit 2's complement value. - */ -static __INLINE int32_t nrf_temp_read(void) -{ - /**@note Workaround for PAN_028 rev2.0A anomaly 28 - TEMP: Negative measured values are not represented correctly */ - return ((NRF_TEMP->TEMP & MASK_SIGN) != 0) ? - (int32_t)(NRF_TEMP->TEMP | MASK_SIGN_EXTENSION) : (NRF_TEMP->TEMP); -} - -/** @} */ - -/** -* @defgroup nrf_temp_hal TEMP HAL -* @{ -* @ingroup nrf_temp -* @brief Hardware access layer for managing the Temperature sensor (TEMP). -*/ - -/** @brief TEMP tasks. */ -typedef enum -{ - NRF_TEMP_TASK_START = offsetof(NRF_TEMP_Type, TASKS_START), /**< Start temperature measurement. */ - NRF_TEMP_TASK_STOP = offsetof(NRF_TEMP_Type, TASKS_STOP) /**< Stop temperature measurement. */ -} nrf_temp_task_t; - -/** @brief TEMP events. */ -typedef enum -{ - NRF_TEMP_EVENT_DATARDY = offsetof(NRF_TEMP_Type, EVENTS_DATARDY) /**< Temperature measurement complete, data ready. */ -} nrf_temp_event_t; - -/** @brief TEMP interrupts. */ -typedef enum -{ - NRF_TEMP_INT_DATARDY_MASK = TEMP_INTENSET_DATARDY_Msk /**< Interrupt on DATARDY event. */ -} nrf_temp_int_mask_t; - -/** - * @brief Function for enabling specified interrupts. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] mask Mask of interrupts to be enabled. - */ -__STATIC_INLINE void nrf_temp_int_enable(NRF_TEMP_Type * p_reg, uint32_t mask); - -/** - * @brief Function for disabling specified interrupts. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] mask Mask of interrupts to be disabled. - */ -__STATIC_INLINE void nrf_temp_int_disable(NRF_TEMP_Type * p_reg, uint32_t mask); - -/** - * @brief Function for retrieving the state of a given interrupt. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] temp_int Interrupt to be checked. - * - * @retval true The interrupt is enabled. - * @retval false The interrupt is not enabled. - */ -__STATIC_INLINE bool nrf_temp_int_enable_check(NRF_TEMP_Type const * p_reg, - nrf_temp_int_mask_t temp_int); - -/** - * @brief Function for getting the address of the specified TEMP task register. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] task Requested task. - * - * @return Address of the requested task register. - */ -__STATIC_INLINE uint32_t nrf_temp_task_address_get(NRF_TEMP_Type const * p_reg, - nrf_temp_task_t task); - -/** - * @brief Function for activating the specified TEMP task. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] task Task to be activated. - */ -__STATIC_INLINE void nrf_temp_task_trigger(NRF_TEMP_Type * p_reg, nrf_temp_task_t task); - -/** - * @brief Function for getting the address of the specified TEMP event register. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] event Requested event. - * - * @return Address of the requested event register. - */ -__STATIC_INLINE uint32_t nrf_temp_event_address_get(NRF_TEMP_Type const * p_reg, - nrf_temp_event_t event); - -/** - * @brief Function for clearing the specified TEMP event. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] event Event to clear. - */ -__STATIC_INLINE void nrf_temp_event_clear(NRF_TEMP_Type * p_reg, nrf_temp_event_t event); - -/** - * @brief Function for getting the state of a specific event. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] event Event to be checked. - * - * @retval true The event has been generated. - * @retval false The event has not been generated. - */ -__STATIC_INLINE bool nrf_temp_event_check(NRF_TEMP_Type const * p_reg, nrf_temp_event_t event); - -/** - * @brief Function for getting the result of temperature measurement. - * - * @note Returned value is in 2's complement format, 0.25 °C steps - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * - * @return Temperature value register contents. - */ -__STATIC_INLINE int32_t nrf_temp_result_get(NRF_TEMP_Type const * p_reg); - -#ifndef SUPPRESS_INLINE_IMPLEMENTATION - -__STATIC_INLINE void nrf_temp_int_enable(NRF_TEMP_Type * p_reg, uint32_t mask) -{ - p_reg->INTENSET = mask; -} - -__STATIC_INLINE void nrf_temp_int_disable(NRF_TEMP_Type * p_reg, uint32_t mask) -{ - p_reg->INTENCLR = mask; -} - -__STATIC_INLINE bool nrf_temp_int_enable_check(NRF_TEMP_Type const * p_reg, - nrf_temp_int_mask_t temp_int) -{ - return (bool)(p_reg->INTENSET & temp_int); -} - -__STATIC_INLINE uint32_t nrf_temp_task_address_get(NRF_TEMP_Type const * p_reg, - nrf_temp_task_t task) -{ - return (uint32_t)((uint8_t *)p_reg + (uint32_t)task); -} - -__STATIC_INLINE void nrf_temp_task_trigger(NRF_TEMP_Type * p_reg, nrf_temp_task_t task) -{ - *(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task) = 1; -} - -__STATIC_INLINE uint32_t nrf_temp_event_address_get(NRF_TEMP_Type const * p_reg, - nrf_temp_event_t event) -{ - return (uint32_t)((uint8_t *)p_reg + (uint32_t)event); -} - -__STATIC_INLINE void nrf_temp_event_clear(NRF_TEMP_Type * p_reg, nrf_temp_event_t event) -{ - *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)) = 0; -#if __CORTEX_M == 0x04 - volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)); - (void)dummy; -#endif -} - -__STATIC_INLINE bool nrf_temp_event_check(NRF_TEMP_Type const * p_reg, nrf_temp_event_t event) -{ - return (bool)*((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)); -} - -__STATIC_INLINE int32_t nrf_temp_result_get(NRF_TEMP_Type const * p_reg) -{ - int32_t raw_measurement = p_reg->TEMP; - -#if defined(NRF51) - /* Apply workaround for the nRF51 series anomaly 28 - TEMP: Negative measured values are not represented correctly. */ - if ((raw_measurement & 0x00000200) != 0) - { - raw_measurement |= 0xFFFFFC00UL; - } -#endif - - return raw_measurement; -} - -#endif - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif // NRF_TEMP_H__ diff --git a/modules/nrfx/hal/nrf_twis.h b/modules/nrfx/hal/nrf_twis.h deleted file mode 100644 index 7bc358b..0000000 --- a/modules/nrfx/hal/nrf_twis.h +++ /dev/null @@ -1,745 +0,0 @@ -/** - * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_TWIS_H__ -#define NRF_TWIS_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_twis_hal TWIS HAL - * @{ - * @ingroup nrf_twis - * @brief Hardware access layer for managing the Two Wire Interface Slave with EasyDMA - * (TWIS) peripheral. - */ - -/** @brief TWIS tasks. */ -typedef enum -{ - NRF_TWIS_TASK_STOP = offsetof(NRF_TWIS_Type, TASKS_STOP), /**< Stop TWIS transaction. */ - NRF_TWIS_TASK_SUSPEND = offsetof(NRF_TWIS_Type, TASKS_SUSPEND), /**< Suspend TWIS transaction. */ - NRF_TWIS_TASK_RESUME = offsetof(NRF_TWIS_Type, TASKS_RESUME), /**< Resume TWIS transaction. */ - NRF_TWIS_TASK_PREPARERX = offsetof(NRF_TWIS_Type, TASKS_PREPARERX), /**< Prepare the TWIS slave to respond to a write command. */ - NRF_TWIS_TASK_PREPARETX = offsetof(NRF_TWIS_Type, TASKS_PREPARETX) /**< Prepare the TWIS slave to respond to a read command. */ -} nrf_twis_task_t; - -/** @brief TWIS events. */ -typedef enum -{ - NRF_TWIS_EVENT_STOPPED = offsetof(NRF_TWIS_Type, EVENTS_STOPPED), /**< TWIS stopped. */ - NRF_TWIS_EVENT_ERROR = offsetof(NRF_TWIS_Type, EVENTS_ERROR), /**< TWIS error. */ - NRF_TWIS_EVENT_RXSTARTED = offsetof(NRF_TWIS_Type, EVENTS_RXSTARTED), /**< Receive sequence started. */ - NRF_TWIS_EVENT_TXSTARTED = offsetof(NRF_TWIS_Type, EVENTS_TXSTARTED), /**< Transmit sequence started. */ - NRF_TWIS_EVENT_WRITE = offsetof(NRF_TWIS_Type, EVENTS_WRITE), /**< Write command received. */ - NRF_TWIS_EVENT_READ = offsetof(NRF_TWIS_Type, EVENTS_READ) /**< Read command received. */ -} nrf_twis_event_t; - -/** @brief TWIS shortcuts. */ -typedef enum -{ - NRF_TWIS_SHORT_WRITE_SUSPEND_MASK = TWIS_SHORTS_WRITE_SUSPEND_Msk, /**< Shortcut between WRITE event and SUSPEND task. */ - NRF_TWIS_SHORT_READ_SUSPEND_MASK = TWIS_SHORTS_READ_SUSPEND_Msk, /**< Shortcut between READ event and SUSPEND task. */ -} nrf_twis_short_mask_t; - -/** @brief TWIS interrupts. */ -typedef enum -{ - NRF_TWIS_INT_STOPPED_MASK = TWIS_INTEN_STOPPED_Msk, /**< Interrupt on STOPPED event. */ - NRF_TWIS_INT_ERROR_MASK = TWIS_INTEN_ERROR_Msk, /**< Interrupt on ERROR event. */ - NRF_TWIS_INT_RXSTARTED_MASK = TWIS_INTEN_RXSTARTED_Msk, /**< Interrupt on RXSTARTED event. */ - NRF_TWIS_INT_TXSTARTED_MASK = TWIS_INTEN_TXSTARTED_Msk, /**< Interrupt on TXSTARTED event. */ - NRF_TWIS_INT_WRITE_MASK = TWIS_INTEN_WRITE_Msk, /**< Interrupt on WRITE event. */ - NRF_TWIS_INT_READ_MASK = TWIS_INTEN_READ_Msk, /**< Interrupt on READ event. */ -} nrf_twis_int_mask_t; - -/** @brief TWIS error source. */ -typedef enum -{ - NRF_TWIS_ERROR_OVERFLOW = TWIS_ERRORSRC_OVERFLOW_Msk, /**< RX buffer overflow detected, and prevented. */ - NRF_TWIS_ERROR_DATA_NACK = TWIS_ERRORSRC_DNACK_Msk, /**< NACK sent after receiving a data byte. */ - NRF_TWIS_ERROR_OVERREAD = TWIS_ERRORSRC_OVERREAD_Msk /**< TX buffer over-read detected, and prevented. */ -} nrf_twis_error_t; - -/** @brief TWIS address matching configuration. */ -typedef enum -{ - NRF_TWIS_CONFIG_ADDRESS0_MASK = TWIS_CONFIG_ADDRESS0_Msk, /**< Enable or disable address matching on ADDRESS[0]. */ - NRF_TWIS_CONFIG_ADDRESS1_MASK = TWIS_CONFIG_ADDRESS1_Msk, /**< Enable or disable address matching on ADDRESS[1]. */ - NRF_TWIS_CONFIG_ADDRESS01_MASK = TWIS_CONFIG_ADDRESS0_Msk | TWIS_CONFIG_ADDRESS1_Msk /**< Enable both address matching. */ -} nrf_twis_config_addr_mask_t; - -/** - * @brief Variable type to hold the amount of data for EasyDMA. - * - * Variable of the minimum size that can hold the amount of data to transfer. - * - * @note Defined to make it simple to change if EasyDMA is updated to support more data in - * the future devices. - */ -typedef uint8_t nrf_twis_amount_t; - -/** - * @brief Smallest variable type to hold the TWI address. - * - * Variable of the minimum size that can hold a single TWI address. - * - * @note Defined to make it simple to change if the new TWI supports for example - * 10 bit addressing mode. - */ -typedef uint8_t nrf_twis_address_t; - - -/** - * @brief Function for activating the specified TWIS task. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] task Task to be activated. - */ -__STATIC_INLINE void nrf_twis_task_trigger(NRF_TWIS_Type * p_reg, nrf_twis_task_t task); - -/** - * @brief Function for returning the address of the specified TWIS task register. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] task The specified task. - * - * @return Task address. - */ -__STATIC_INLINE uint32_t nrf_twis_task_address_get(NRF_TWIS_Type const * p_reg, - nrf_twis_task_t task); - -/** - * @brief Function for clearing the specified event. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] event The specified event. - */ -__STATIC_INLINE void nrf_twis_event_clear(NRF_TWIS_Type * p_reg, - nrf_twis_event_t event); - -/** - * @brief Function for retrieving the state of the TWIS event. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] event Event to be checked. - * - * @retval true The event has been generated. - * @retval false The event has not been generated. - */ -__STATIC_INLINE bool nrf_twis_event_check(NRF_TWIS_Type const * p_reg, - nrf_twis_event_t event); - -/** - * @brief Function for getting and clearing the state of the specified event. - * - * This function checks the state of the event and clears it. - * - * @param[in,out] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] event Event. - * - * @retval true The event was set. - * @retval false The event was not set. - */ -__STATIC_INLINE bool nrf_twis_event_get_and_clear(NRF_TWIS_Type * p_reg, - nrf_twis_event_t event); - -/** - * @brief Function for returning the address of the specified TWIS event register. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] event Event. - * - * @return Address. - */ -__STATIC_INLINE uint32_t nrf_twis_event_address_get(NRF_TWIS_Type const * p_reg, - nrf_twis_event_t event); - -/** - * @brief Function for setting a shortcut. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] mask Mask of shortcuts to be enabled. - */ -__STATIC_INLINE void nrf_twis_shorts_enable(NRF_TWIS_Type * p_reg, uint32_t mask); - -/** - * @brief Function for clearing shortcuts. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] mask Mask of shortcuts to be disabled. - */ -__STATIC_INLINE void nrf_twis_shorts_disable(NRF_TWIS_Type * p_reg, uint32_t mask); - -/** - * @brief Function for getting the shorts mask. - * - * Function returns shorts register. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * - * @return Flags of currently enabled shortcuts - */ -__STATIC_INLINE uint32_t nrf_twis_shorts_get(NRF_TWIS_Type const * p_reg); - -/** - * @brief Function for enabling the specified interrupts. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] mask Mask of interrupts to be enabled. - */ -__STATIC_INLINE void nrf_twis_int_enable(NRF_TWIS_Type * p_reg, uint32_t mask); - -/** - * @brief Function for retrieving the state of the specified interrupts. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] mask Mask of interrupts to be checked. - * - * @retval true Any of the specified interrupts is enabled. - * @retval false None of the specified interrupts is enabled. - */ -__STATIC_INLINE bool nrf_twis_int_enable_check(NRF_TWIS_Type const * p_reg, uint32_t mask); - -/** - * @brief Function for disabling the specified interrupts. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] mask Mask of interrupts to be disabled. - */ -__STATIC_INLINE void nrf_twis_int_disable(NRF_TWIS_Type * p_reg, uint32_t mask); - -#if defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__) -/** - * @brief Function for setting the subscribe configuration for a given - * TWIS task. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] task Task for which to set the configuration. - * @param[in] channel Channel through which to subscribe events. - */ -__STATIC_INLINE void nrf_twis_subscribe_set(NRF_TWIS_Type * p_reg, - nrf_twis_task_t task, - uint8_t channel); - -/** - * @brief Function for clearing the subscribe configuration for a given - * TWIS task. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] task Task for which to clear the configuration. - */ -__STATIC_INLINE void nrf_twis_subscribe_clear(NRF_TWIS_Type * p_reg, - nrf_twis_task_t task); - -/** - * @brief Function for setting the publish configuration for a given - * TWIS event. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] event Event for which to set the configuration. - * @param[in] channel Channel through which to publish the event. - */ -__STATIC_INLINE void nrf_twis_publish_set(NRF_TWIS_Type * p_reg, - nrf_twis_event_t event, - uint8_t channel); - -/** - * @brief Function for clearing the publish configuration for a given - * TWIS event. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] event Event for which to clear the configuration. - */ -__STATIC_INLINE void nrf_twis_publish_clear(NRF_TWIS_Type * p_reg, - nrf_twis_event_t event); -#endif // defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__) - -/** - * @brief Function for retrieving and clearing the TWIS error source. - * - * @attention Error sources are cleared after read. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * - * @return Error source mask with values from @ref nrf_twis_error_t. - */ -__STATIC_INLINE uint32_t nrf_twis_error_source_get_and_clear(NRF_TWIS_Type * const p_reg); - -/** - * @brief Function for getting information about which of the addresses matched. - * - * Function returns index in the address table - * that points to the address that already matched. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * - * @return Index of matched address. - */ -__STATIC_INLINE uint_fast8_t nrf_twis_match_get(NRF_TWIS_Type const * p_reg); - -/** - * @brief Function for enabling TWIS. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - */ -__STATIC_INLINE void nrf_twis_enable(NRF_TWIS_Type * p_reg); - -/** - * @brief Function for disabling TWIS. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - */ -__STATIC_INLINE void nrf_twis_disable(NRF_TWIS_Type * p_reg); - -/** - * @brief Function for configuring TWIS pins. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] scl SCL pin number. - * @param[in] sda SDA pin number. - */ -__STATIC_INLINE void nrf_twis_pins_set(NRF_TWIS_Type * p_reg, uint32_t scl, uint32_t sda); - -/** - * @brief Function for setting the receive buffer. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] p_buf Pointer to the buffer for received data. - * @param[in] length Maximum number of data bytes to receive. - */ -__STATIC_INLINE void nrf_twis_rx_buffer_set(NRF_TWIS_Type * p_reg, - uint8_t * p_buf, - size_t length); - -/** - * @brief Function that prepares TWIS for receiving - * - * This function sets receive buffer and then sets NRF_TWIS_TASK_PREPARERX task. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] p_buf Pointer to the buffer for received data. - * @param[in] length Maximum number of data bytes to receive. - */ -__STATIC_INLINE void nrf_twis_rx_prepare(NRF_TWIS_Type * p_reg, - uint8_t * p_buf, - size_t length); - -/** - * @brief Function for getting number of bytes received in the last transaction. - * - * @param[in] p_reg TWIS instance. - * - * @return Amount of bytes received. - * */ -__STATIC_INLINE size_t nrf_twis_rx_amount_get(NRF_TWIS_Type const * p_reg); - -/** - * @brief Function for setting the transmit buffer. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] p_buf Pointer to the buffer with data to send. - * @param[in] length Maximum number of data bytes to transmit. - */ -__STATIC_INLINE void nrf_twis_tx_buffer_set(NRF_TWIS_Type * p_reg, - uint8_t const * p_buf, - size_t length); - -/** - * @brief Function for preparing TWIS for transmitting. - * - * This function sets transmit buffer and then sets NRF_TWIS_TASK_PREPARETX task. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] p_buf Pointer to the buffer with data to send. - * @param[in] length Maximum number of data bytes to transmit. - */ -__STATIC_INLINE void nrf_twis_tx_prepare(NRF_TWIS_Type * p_reg, - uint8_t const * p_buf, - size_t length); - -/** - * @brief Function for getting the number of bytes transmitted in the last transaction. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * - * @return Amount of bytes transmitted. - */ -__STATIC_INLINE size_t nrf_twis_tx_amount_get(NRF_TWIS_Type const * p_reg); - -/** - * @brief Function for setting the slave address. - * - * Function sets the selected address for this TWI interface. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] n Index of address to be set. - * @param[in] addr Addres to be set. - * - * @sa nrf_twis_config_address_set - * @sa nrf_twis_config_address_get - */ -__STATIC_INLINE void nrf_twis_address_set(NRF_TWIS_Type * p_reg, - uint_fast8_t n, - nrf_twis_address_t addr); - -/** - * @brief Function for retrieving configured slave address. - * - * Function gets the selected address for this TWI interface. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] n Index of address to get. - * - * @return Configured slave address. - */ -__STATIC_INLINE nrf_twis_address_t nrf_twis_address_get(NRF_TWIS_Type const * p_reg, - uint_fast8_t n); - -/** - * @brief Function for setting the device address configuration. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] addr_mask Mask of address indexes of what device should answer to. - * - * @sa nrf_twis_address_set - */ -__STATIC_INLINE void nrf_twis_config_address_set(NRF_TWIS_Type * p_reg, - nrf_twis_config_addr_mask_t addr_mask); - -/** - * @brief Function for retrieving the device address configuration. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * - * @return Mask of address indexes of what device should answer to. - */ -__STATIC_INLINE nrf_twis_config_addr_mask_t nrf_twis_config_address_get( - NRF_TWIS_Type const * p_reg); - -/** - * @brief Function for setting the over-read character. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] orc Over-read character. Character clocked out in case of - * over-read of the TXD buffer. - */ -__STATIC_INLINE void nrf_twis_orc_set(NRF_TWIS_Type * p_reg, - uint8_t orc); - -/** - * @brief Function for setting the over-read character. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * - * @return Over-read character configured for selected instance. - */ -__STATIC_INLINE uint8_t nrf_twis_orc_get(NRF_TWIS_Type const * p_reg); - - -/** @} */ /* End of nrf_twis_hal */ - -#ifndef SUPPRESS_INLINE_IMPLEMENTATION - -/* ------------------------------------------------------------------------------------------------ - * Internal functions - */ - -/** - * @internal - * @brief Internal function for getting task or event register address. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] offset Offset of the register from the beginning of the instance. - * - * @attention Offset must be modulo 4 value. In other case, hardware fault can occur. - * @return Pointer to the register. - */ -__STATIC_INLINE volatile uint32_t* nrf_twis_getRegPtr(NRF_TWIS_Type const * p_reg, uint32_t offset) -{ - return (volatile uint32_t*)((uint8_t *)p_reg + (uint32_t)offset); -} - -/** - * @internal - * @brief Internal function for getting task/event register address - constant version. - * - * @param[in] p_reg Pointer to the structure of registers of the peripheral. - * @param[in] offset Offset of the register from the beginning of the instance. - * - * @attention Offset must be modulo 4 value. In other case, hardware fault can occur. - * @return Pointer to the register. - */ -__STATIC_INLINE volatile const uint32_t* nrf_twis_getRegPtr_c(NRF_TWIS_Type const * p_reg, - uint32_t offset) -{ - return (volatile const uint32_t*)((uint8_t *)p_reg + (uint32_t)offset); -} - - -/* ------------------------------------------------------------------------------------------------ - * Interface functions definitions - */ - - -__STATIC_INLINE void nrf_twis_task_trigger(NRF_TWIS_Type * p_reg, nrf_twis_task_t task) -{ - *(nrf_twis_getRegPtr(p_reg, (uint32_t)task)) = 1UL; -} - -__STATIC_INLINE uint32_t nrf_twis_task_address_get(NRF_TWIS_Type const * p_reg, - nrf_twis_task_t task) -{ - return (uint32_t)nrf_twis_getRegPtr_c(p_reg, (uint32_t)task); -} - -__STATIC_INLINE void nrf_twis_event_clear(NRF_TWIS_Type * p_reg, nrf_twis_event_t event) -{ - *(nrf_twis_getRegPtr(p_reg, (uint32_t)event)) = 0UL; -#if __CORTEX_M == 0x04 - volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)); - (void)dummy; -#endif -} - -__STATIC_INLINE bool nrf_twis_event_check(NRF_TWIS_Type const * p_reg, nrf_twis_event_t event) -{ - return (bool)*nrf_twis_getRegPtr_c(p_reg, (uint32_t)event); -} - -__STATIC_INLINE bool nrf_twis_event_get_and_clear(NRF_TWIS_Type * p_reg, nrf_twis_event_t event) -{ - bool ret = nrf_twis_event_check(p_reg, event); - if (ret) - { - nrf_twis_event_clear(p_reg, event); - } - return ret; -} - -__STATIC_INLINE uint32_t nrf_twis_event_address_get(NRF_TWIS_Type const * p_reg, - nrf_twis_event_t event) -{ - return (uint32_t)nrf_twis_getRegPtr_c(p_reg, (uint32_t)event); -} - -__STATIC_INLINE void nrf_twis_shorts_enable(NRF_TWIS_Type * p_reg, uint32_t mask) -{ - p_reg->SHORTS |= mask; -} - -__STATIC_INLINE void nrf_twis_shorts_disable(NRF_TWIS_Type * p_reg, uint32_t mask) -{ - if (~0U == mask) - { - /* Optimized version for "disable all" */ - p_reg->SHORTS = 0; - } - else - { - p_reg->SHORTS &= ~mask; - } -} - -__STATIC_INLINE uint32_t nrf_twis_shorts_get(NRF_TWIS_Type const * p_reg) -{ - return p_reg->SHORTS; -} - -__STATIC_INLINE void nrf_twis_int_enable(NRF_TWIS_Type * p_reg, uint32_t mask) -{ - p_reg->INTENSET = mask; -} - -__STATIC_INLINE bool nrf_twis_int_enable_check(NRF_TWIS_Type const * p_reg, uint32_t mask) -{ - return (bool)(p_reg->INTENSET & mask); -} - -__STATIC_INLINE void nrf_twis_int_disable(NRF_TWIS_Type * const p_reg, uint32_t mask) -{ - p_reg->INTENCLR = mask; -} - -#if defined(DPPI_PRESENT) -__STATIC_INLINE void nrf_twis_subscribe_set(NRF_TWIS_Type * p_reg, - nrf_twis_task_t task, - uint8_t channel) -{ - *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = - ((uint32_t)channel | TWIS_SUBSCRIBE_STOP_EN_Msk); -} - -__STATIC_INLINE void nrf_twis_subscribe_clear(NRF_TWIS_Type * p_reg, - nrf_twis_task_t task) -{ - *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0; -} - -__STATIC_INLINE void nrf_twis_publish_set(NRF_TWIS_Type * p_reg, - nrf_twis_event_t event, - uint8_t channel) -{ - *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) event + 0x80uL)) = - ((uint32_t)channel | TWIS_PUBLISH_STOPPED_EN_Msk); -} - -__STATIC_INLINE void nrf_twis_publish_clear(NRF_TWIS_Type * p_reg, - nrf_twis_event_t event) -{ - *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) event + 0x80uL)) = 0; -} -#endif // defined(DPPI_PRESENT) - -__STATIC_INLINE uint32_t nrf_twis_error_source_get_and_clear(NRF_TWIS_Type * p_reg) -{ - uint32_t ret = p_reg->ERRORSRC; - p_reg->ERRORSRC = ret; - return ret; -} - -__STATIC_INLINE uint_fast8_t nrf_twis_match_get(NRF_TWIS_Type const * p_reg) -{ - return (uint_fast8_t)p_reg->MATCH; -} - -__STATIC_INLINE void nrf_twis_enable(NRF_TWIS_Type * p_reg) -{ - p_reg->ENABLE = (TWIS_ENABLE_ENABLE_Enabled << TWIS_ENABLE_ENABLE_Pos); -} - -__STATIC_INLINE void nrf_twis_disable(NRF_TWIS_Type * p_reg) -{ - p_reg->ENABLE = (TWIS_ENABLE_ENABLE_Disabled << TWIS_ENABLE_ENABLE_Pos); -} - -__STATIC_INLINE void nrf_twis_pins_set(NRF_TWIS_Type * p_reg, uint32_t scl, uint32_t sda) -{ - p_reg->PSEL.SCL = scl; - p_reg->PSEL.SDA = sda; -} - -__STATIC_INLINE void nrf_twis_rx_buffer_set(NRF_TWIS_Type * p_reg, - uint8_t * p_buf, - size_t length) -{ - p_reg->RXD.PTR = (uint32_t)p_buf; - p_reg->RXD.MAXCNT = length; -} - -__STATIC_INLINE void nrf_twis_rx_prepare(NRF_TWIS_Type * p_reg, - uint8_t * p_buf, - size_t length) -{ - nrf_twis_rx_buffer_set(p_reg, p_buf, length); - nrf_twis_task_trigger(p_reg, NRF_TWIS_TASK_PREPARERX); -} - -__STATIC_INLINE size_t nrf_twis_rx_amount_get(NRF_TWIS_Type const * p_reg) -{ - return p_reg->RXD.AMOUNT; -} - -__STATIC_INLINE void nrf_twis_tx_buffer_set(NRF_TWIS_Type * p_reg, - uint8_t const * p_buf, - size_t length) -{ - p_reg->TXD.PTR = (uint32_t)p_buf; - p_reg->TXD.MAXCNT = length; -} - -__STATIC_INLINE void nrf_twis_tx_prepare(NRF_TWIS_Type * p_reg, - uint8_t const * p_buf, - size_t length) -{ - nrf_twis_tx_buffer_set(p_reg, p_buf, length); - nrf_twis_task_trigger(p_reg, NRF_TWIS_TASK_PREPARETX); -} - -__STATIC_INLINE size_t nrf_twis_tx_amount_get(NRF_TWIS_Type const * p_reg) -{ - return p_reg->TXD.AMOUNT; -} - -__STATIC_INLINE void nrf_twis_address_set(NRF_TWIS_Type * p_reg, - uint_fast8_t n, - nrf_twis_address_t addr) -{ - p_reg->ADDRESS[n] = addr; -} - -__STATIC_INLINE nrf_twis_address_t nrf_twis_address_get(NRF_TWIS_Type const * p_reg, uint_fast8_t n) -{ - return (nrf_twis_address_t)p_reg->ADDRESS[n]; -} -__STATIC_INLINE void nrf_twis_config_address_set(NRF_TWIS_Type * p_reg, - nrf_twis_config_addr_mask_t addr_mask) -{ - /* This is the only configuration in TWIS - just write it without masking */ - p_reg->CONFIG = addr_mask; -} - -__STATIC_INLINE nrf_twis_config_addr_mask_t nrf_twis_config_address_get(NRF_TWIS_Type const * p_reg) -{ - return (nrf_twis_config_addr_mask_t)(p_reg->CONFIG & TWIS_ADDRESS_ADDRESS_Msk); -} - -__STATIC_INLINE void nrf_twis_orc_set(NRF_TWIS_Type * p_reg, uint8_t orc) -{ - p_reg->ORC = orc; -} - -__STATIC_INLINE uint8_t nrf_twis_orc_get(NRF_TWIS_Type const * p_reg) -{ - return (uint8_t)p_reg->ORC; -} - -#endif /* SUPPRESS_INLINE_IMPLEMENTATION */ - - -#ifdef __cplusplus -} -#endif - -#endif /* NRF_TWIS_H__ */ diff --git a/modules/nrfx/hal/nrf_usbd.h b/modules/nrfx/hal/nrf_usbd.h deleted file mode 100644 index 8385d52..0000000 --- a/modules/nrfx/hal/nrf_usbd.h +++ /dev/null @@ -1,1396 +0,0 @@ -/** - * Copyright (c) 2017 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef NRF_USBD_H__ -#define NRF_USBD_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_usbd_hal USBD HAL - * @{ - * @ingroup nrf_usbd - * @brief Hardware access layer for managing the Universal Serial Bus Device (USBD) - * peripheral. - */ - -/** @brief USBD tasks. */ -typedef enum -{ - NRF_USBD_TASK_STARTEPIN0 = offsetof(NRF_USBD_Type, TASKS_STARTEPIN[0] ), /**< Captures the EPIN[0].PTR, EPIN[0].MAXCNT, and EPIN[0].CONFIG registers values, and enables control endpoint IN 0 to respond to traffic from host. */ - NRF_USBD_TASK_STARTEPIN1 = offsetof(NRF_USBD_Type, TASKS_STARTEPIN[1] ), /**< Captures the EPIN[1].PTR, EPIN[1].MAXCNT, and EPIN[1].CONFIG registers values, and enables data endpoint IN 1 to respond to traffic from host. */ - NRF_USBD_TASK_STARTEPIN2 = offsetof(NRF_USBD_Type, TASKS_STARTEPIN[2] ), /**< Captures the EPIN[2].PTR, EPIN[2].MAXCNT, and EPIN[2].CONFIG registers values, and enables data endpoint IN 2 to respond to traffic from host. */ - NRF_USBD_TASK_STARTEPIN3 = offsetof(NRF_USBD_Type, TASKS_STARTEPIN[3] ), /**< Captures the EPIN[3].PTR, EPIN[3].MAXCNT, and EPIN[3].CONFIG registers values, and enables data endpoint IN 3 to respond to traffic from host. */ - NRF_USBD_TASK_STARTEPIN4 = offsetof(NRF_USBD_Type, TASKS_STARTEPIN[4] ), /**< Captures the EPIN[4].PTR, EPIN[4].MAXCNT, and EPIN[4].CONFIG registers values, and enables data endpoint IN 4 to respond to traffic from host. */ - NRF_USBD_TASK_STARTEPIN5 = offsetof(NRF_USBD_Type, TASKS_STARTEPIN[5] ), /**< Captures the EPIN[5].PTR, EPIN[5].MAXCNT, and EPIN[5].CONFIG registers values, and enables data endpoint IN 5 to respond to traffic from host. */ - NRF_USBD_TASK_STARTEPIN6 = offsetof(NRF_USBD_Type, TASKS_STARTEPIN[6] ), /**< Captures the EPIN[6].PTR, EPIN[6].MAXCNT, and EPIN[6].CONFIG registers values, and enables data endpoint IN 6 to respond to traffic from host. */ - NRF_USBD_TASK_STARTEPIN7 = offsetof(NRF_USBD_Type, TASKS_STARTEPIN[7] ), /**< Captures the EPIN[7].PTR, EPIN[7].MAXCNT, and EPIN[7].CONFIG registers values, and enables data endpoint IN 7 to respond to traffic from host. */ - NRF_USBD_TASK_STARTISOIN = offsetof(NRF_USBD_Type, TASKS_STARTISOIN ), /**< Captures the ISOIN.PTR, ISOIN.MAXCNT, and ISOIN.CONFIG registers values, and enables sending data on ISO endpoint 8. */ - NRF_USBD_TASK_STARTEPOUT0 = offsetof(NRF_USBD_Type, TASKS_STARTEPOUT[0]), /**< Captures the EPOUT[0].PTR, EPOUT[0].MAXCNT, and EPOUT[0].CONFIG registers values, and enables control endpoint 0 to respond to traffic from host. */ - NRF_USBD_TASK_STARTEPOUT1 = offsetof(NRF_USBD_Type, TASKS_STARTEPOUT[1]), /**< Captures the EPOUT[1].PTR, EPOUT[1].MAXCNT, and EPOUT[1].CONFIG registers values, and enables data endpoint 1 to respond to traffic from host. */ - NRF_USBD_TASK_STARTEPOUT2 = offsetof(NRF_USBD_Type, TASKS_STARTEPOUT[2]), /**< Captures the EPOUT[2].PTR, EPOUT[2].MAXCNT, and EPOUT[2].CONFIG registers values, and enables data endpoint 2 to respond to traffic from host. */ - NRF_USBD_TASK_STARTEPOUT3 = offsetof(NRF_USBD_Type, TASKS_STARTEPOUT[3]), /**< Captures the EPOUT[3].PTR, EPOUT[3].MAXCNT, and EPOUT[3].CONFIG registers values, and enables data endpoint 3 to respond to traffic from host. */ - NRF_USBD_TASK_STARTEPOUT4 = offsetof(NRF_USBD_Type, TASKS_STARTEPOUT[4]), /**< Captures the EPOUT[4].PTR, EPOUT[4].MAXCNT, and EPOUT[4].CONFIG registers values, and enables data endpoint 4 to respond to traffic from host. */ - NRF_USBD_TASK_STARTEPOUT5 = offsetof(NRF_USBD_Type, TASKS_STARTEPOUT[5]), /**< Captures the EPOUT[5].PTR, EPOUT[5].MAXCNT, and EPOUT[5].CONFIG registers values, and enables data endpoint 5 to respond to traffic from host. */ - NRF_USBD_TASK_STARTEPOUT6 = offsetof(NRF_USBD_Type, TASKS_STARTEPOUT[6]), /**< Captures the EPOUT[6].PTR, EPOUT[6].MAXCNT, and EPOUT[6].CONFIG registers values, and enables data endpoint 6 to respond to traffic from host. */ - NRF_USBD_TASK_STARTEPOUT7 = offsetof(NRF_USBD_Type, TASKS_STARTEPOUT[7]), /**< Captures the EPOUT[7].PTR, EPOUT[7].MAXCNT, and EPOUT[7].CONFIG registers values, and enables data endpoint 7 to respond to traffic from host. */ - NRF_USBD_TASK_STARTISOOUT = offsetof(NRF_USBD_Type, TASKS_STARTISOOUT ), /**< Captures the ISOOUT.PTR, ISOOUT.MAXCNT, and ISOOUT.CONFIG registers values, and enables receiving of data on ISO endpoint 8. */ - NRF_USBD_TASK_EP0RCVOUT = offsetof(NRF_USBD_Type, TASKS_EP0RCVOUT ), /**< Allows OUT data stage on the control endpoint 0. */ - NRF_USBD_TASK_EP0STATUS = offsetof(NRF_USBD_Type, TASKS_EP0STATUS ), /**< Allows status stage on the control endpoint 0. */ - NRF_USBD_TASK_EP0STALL = offsetof(NRF_USBD_Type, TASKS_EP0STALL ), /**< STALLs data and status stage on the control endpoint 0. */ - NRF_USBD_TASK_DRIVEDPDM = offsetof(NRF_USBD_Type, TASKS_DPDMDRIVE ), /**< Forces D+ and D-lines to the state defined in the DPDMVALUE register. */ - NRF_USBD_TASK_NODRIVEDPDM = offsetof(NRF_USBD_Type, TASKS_DPDMNODRIVE ), /**< Stops forcing D+ and D- lines to any state (USB engine takes control). */ -}nrf_usbd_task_t; - -/** @brief USBD events. */ -typedef enum -{ - NRF_USBD_EVENT_USBRESET = offsetof(NRF_USBD_Type, EVENTS_USBRESET ), /**< Signals that a USB reset condition is detected on the USB lines. */ - NRF_USBD_EVENT_STARTED = offsetof(NRF_USBD_Type, EVENTS_STARTED ), /**< Confirms that the EPIN[n].PTR, EPIN[n].MAXCNT, EPIN[n].CONFIG, or EPOUT[n].PTR, EPOUT[n].MAXCNT, and EPOUT[n].CONFIG registers have been captured on all endpoints reported in the EPSTATUS register. */ - NRF_USBD_EVENT_ENDEPIN0 = offsetof(NRF_USBD_Type, EVENTS_ENDEPIN[0] ), /**< The whole EPIN[0] buffer has been consumed. The RAM buffer can be accessed safely by software. */ - NRF_USBD_EVENT_ENDEPIN1 = offsetof(NRF_USBD_Type, EVENTS_ENDEPIN[1] ), /**< The whole EPIN[1] buffer has been consumed. The RAM buffer can be accessed safely by software. */ - NRF_USBD_EVENT_ENDEPIN2 = offsetof(NRF_USBD_Type, EVENTS_ENDEPIN[2] ), /**< The whole EPIN[2] buffer has been consumed. The RAM buffer can be accessed safely by software. */ - NRF_USBD_EVENT_ENDEPIN3 = offsetof(NRF_USBD_Type, EVENTS_ENDEPIN[3] ), /**< The whole EPIN[3] buffer has been consumed. The RAM buffer can be accessed safely by software. */ - NRF_USBD_EVENT_ENDEPIN4 = offsetof(NRF_USBD_Type, EVENTS_ENDEPIN[4] ), /**< The whole EPIN[4] buffer has been consumed. The RAM buffer can be accessed safely by software. */ - NRF_USBD_EVENT_ENDEPIN5 = offsetof(NRF_USBD_Type, EVENTS_ENDEPIN[5] ), /**< The whole EPIN[5] buffer has been consumed. The RAM buffer can be accessed safely by software. */ - NRF_USBD_EVENT_ENDEPIN6 = offsetof(NRF_USBD_Type, EVENTS_ENDEPIN[6] ), /**< The whole EPIN[6] buffer has been consumed. The RAM buffer can be accessed safely by software. */ - NRF_USBD_EVENT_ENDEPIN7 = offsetof(NRF_USBD_Type, EVENTS_ENDEPIN[7] ), /**< The whole EPIN[7] buffer has been consumed. The RAM buffer can be accessed safely by software. */ - NRF_USBD_EVENT_EP0DATADONE = offsetof(NRF_USBD_Type, EVENTS_EP0DATADONE), /**< An acknowledged data transfer has taken place on the control endpoint. */ - NRF_USBD_EVENT_ENDISOIN0 = offsetof(NRF_USBD_Type, EVENTS_ENDISOIN ), /**< The whole ISOIN buffer has been consumed. The RAM buffer can be accessed safely by software. */ - NRF_USBD_EVENT_ENDEPOUT0 = offsetof(NRF_USBD_Type, EVENTS_ENDEPOUT[0]), /**< The whole EPOUT[0] buffer has been consumed. The RAM buffer can be accessed safely by software. */ - NRF_USBD_EVENT_ENDEPOUT1 = offsetof(NRF_USBD_Type, EVENTS_ENDEPOUT[1]), /**< The whole EPOUT[1] buffer has been consumed. The RAM buffer can be accessed safely by software. */ - NRF_USBD_EVENT_ENDEPOUT2 = offsetof(NRF_USBD_Type, EVENTS_ENDEPOUT[2]), /**< The whole EPOUT[2] buffer has been consumed. The RAM buffer can be accessed safely by software. */ - NRF_USBD_EVENT_ENDEPOUT3 = offsetof(NRF_USBD_Type, EVENTS_ENDEPOUT[3]), /**< The whole EPOUT[3] buffer has been consumed. The RAM buffer can be accessed safely by software. */ - NRF_USBD_EVENT_ENDEPOUT4 = offsetof(NRF_USBD_Type, EVENTS_ENDEPOUT[4]), /**< The whole EPOUT[4] buffer has been consumed. The RAM buffer can be accessed safely by software. */ - NRF_USBD_EVENT_ENDEPOUT5 = offsetof(NRF_USBD_Type, EVENTS_ENDEPOUT[5]), /**< The whole EPOUT[5] buffer has been consumed. The RAM buffer can be accessed safely by software. */ - NRF_USBD_EVENT_ENDEPOUT6 = offsetof(NRF_USBD_Type, EVENTS_ENDEPOUT[6]), /**< The whole EPOUT[6] buffer has been consumed. The RAM buffer can be accessed safely by software. */ - NRF_USBD_EVENT_ENDEPOUT7 = offsetof(NRF_USBD_Type, EVENTS_ENDEPOUT[7]), /**< The whole EPOUT[7] buffer has been consumed. The RAM buffer can be accessed safely by software. */ - NRF_USBD_EVENT_ENDISOOUT0 = offsetof(NRF_USBD_Type, EVENTS_ENDISOOUT ), /**< The whole ISOOUT buffer has been consumed. The RAM buffer can be accessed safely by software. */ - NRF_USBD_EVENT_SOF = offsetof(NRF_USBD_Type, EVENTS_SOF ), /**< Signals that a SOF (start of frame) condition has been detected on the USB lines. */ - NRF_USBD_EVENT_USBEVENT = offsetof(NRF_USBD_Type, EVENTS_USBEVENT ), /**< An event or an error not covered by the specified events has occurred, check EVENTCAUSE register to find the cause. */ - NRF_USBD_EVENT_EP0SETUP = offsetof(NRF_USBD_Type, EVENTS_EP0SETUP ), /**< A valid SETUP token has been received (and acknowledged) on the control endpoint. */ - NRF_USBD_EVENT_DATAEP = offsetof(NRF_USBD_Type, EVENTS_EPDATA ), /**< A data transfer has occurred on a data endpoint, indicated by the EPDATASTATUS register. */ -}nrf_usbd_event_t; - -/** @brief USBD shorts. */ -typedef enum -{ - NRF_USBD_SHORT_EP0DATADONE_STARTEPIN0_MASK = USBD_SHORTS_EP0DATADONE_STARTEPIN0_Msk , /**< Shortcut between EP0DATADONE event and STARTEPIN0 task. */ - NRF_USBD_SHORT_EP0DATADONE_STARTEPOUT0_MASK = USBD_SHORTS_EP0DATADONE_STARTEPOUT0_Msk, /**< Shortcut between EP0DATADONE event and STARTEPOUT0 task. */ - NRF_USBD_SHORT_EP0DATADONE_EP0STATUS_MASK = USBD_SHORTS_EP0DATADONE_EP0STATUS_Msk , /**< Shortcut between EP0DATADONE event and EP0STATUS task. */ - NRF_USBD_SHORT_ENDEPOUT0_EP0STATUS_MASK = USBD_SHORTS_ENDEPOUT0_EP0STATUS_Msk , /**< Shortcut between ENDEPOUT[0] event and EP0STATUS task. */ - NRF_USBD_SHORT_ENDEPOUT0_EP0RCVOUT_MASK = USBD_SHORTS_ENDEPOUT0_EP0RCVOUT_Msk , /**< Shortcut between ENDEPOUT[0] event and EP0RCVOUT task. */ -}nrf_usbd_short_mask_t; - -/** @brief USBD interrupts. */ -typedef enum -{ - NRF_USBD_INT_USBRESET_MASK = USBD_INTEN_USBRESET_Msk , /**< Enable or disable interrupt for USBRESET event. */ - NRF_USBD_INT_STARTED_MASK = USBD_INTEN_STARTED_Msk , /**< Enable or disable interrupt for STARTED event. */ - NRF_USBD_INT_ENDEPIN0_MASK = USBD_INTEN_ENDEPIN0_Msk , /**< Enable or disable interrupt for ENDEPIN[0] event. */ - NRF_USBD_INT_ENDEPIN1_MASK = USBD_INTEN_ENDEPIN1_Msk , /**< Enable or disable interrupt for ENDEPIN[1] event. */ - NRF_USBD_INT_ENDEPIN2_MASK = USBD_INTEN_ENDEPIN2_Msk , /**< Enable or disable interrupt for ENDEPIN[2] event. */ - NRF_USBD_INT_ENDEPIN3_MASK = USBD_INTEN_ENDEPIN3_Msk , /**< Enable or disable interrupt for ENDEPIN[3] event. */ - NRF_USBD_INT_ENDEPIN4_MASK = USBD_INTEN_ENDEPIN4_Msk , /**< Enable or disable interrupt for ENDEPIN[4] event. */ - NRF_USBD_INT_ENDEPIN5_MASK = USBD_INTEN_ENDEPIN5_Msk , /**< Enable or disable interrupt for ENDEPIN[5] event. */ - NRF_USBD_INT_ENDEPIN6_MASK = USBD_INTEN_ENDEPIN6_Msk , /**< Enable or disable interrupt for ENDEPIN[6] event. */ - NRF_USBD_INT_ENDEPIN7_MASK = USBD_INTEN_ENDEPIN7_Msk , /**< Enable or disable interrupt for ENDEPIN[7] event. */ - NRF_USBD_INT_EP0DATADONE_MASK = USBD_INTEN_EP0DATADONE_Msk, /**< Enable or disable interrupt for EP0DATADONE event. */ - NRF_USBD_INT_ENDISOIN0_MASK = USBD_INTEN_ENDISOIN_Msk , /**< Enable or disable interrupt for ENDISOIN[0] event. */ - NRF_USBD_INT_ENDEPOUT0_MASK = USBD_INTEN_ENDEPOUT0_Msk , /**< Enable or disable interrupt for ENDEPOUT[0] event. */ - NRF_USBD_INT_ENDEPOUT1_MASK = USBD_INTEN_ENDEPOUT1_Msk , /**< Enable or disable interrupt for ENDEPOUT[1] event. */ - NRF_USBD_INT_ENDEPOUT2_MASK = USBD_INTEN_ENDEPOUT2_Msk , /**< Enable or disable interrupt for ENDEPOUT[2] event. */ - NRF_USBD_INT_ENDEPOUT3_MASK = USBD_INTEN_ENDEPOUT3_Msk , /**< Enable or disable interrupt for ENDEPOUT[3] event. */ - NRF_USBD_INT_ENDEPOUT4_MASK = USBD_INTEN_ENDEPOUT4_Msk , /**< Enable or disable interrupt for ENDEPOUT[4] event. */ - NRF_USBD_INT_ENDEPOUT5_MASK = USBD_INTEN_ENDEPOUT5_Msk , /**< Enable or disable interrupt for ENDEPOUT[5] event. */ - NRF_USBD_INT_ENDEPOUT6_MASK = USBD_INTEN_ENDEPOUT6_Msk , /**< Enable or disable interrupt for ENDEPOUT[6] event. */ - NRF_USBD_INT_ENDEPOUT7_MASK = USBD_INTEN_ENDEPOUT7_Msk , /**< Enable or disable interrupt for ENDEPOUT[7] event. */ - NRF_USBD_INT_ENDISOOUT0_MASK = USBD_INTEN_ENDISOOUT_Msk , /**< Enable or disable interrupt for ENDISOOUT[0] event. */ - NRF_USBD_INT_SOF_MASK = USBD_INTEN_SOF_Msk , /**< Enable or disable interrupt for SOF event. */ - NRF_USBD_INT_USBEVENT_MASK = USBD_INTEN_USBEVENT_Msk , /**< Enable or disable interrupt for USBEVENT event. */ - NRF_USBD_INT_EP0SETUP_MASK = USBD_INTEN_EP0SETUP_Msk , /**< Enable or disable interrupt for EP0SETUP event. */ - NRF_USBD_INT_DATAEP_MASK = USBD_INTEN_EPDATA_Msk , /**< Enable or disable interrupt for EPDATA event. */ -}nrf_usbd_int_mask_t; - - -/** - * @brief Function for activating the specified USBD task. - * - * @param[in] task Task to be activated. - */ -__STATIC_INLINE void nrf_usbd_task_trigger(nrf_usbd_task_t task); - -/** - * @brief Function for returning the address of the specified USBD task register. - * - * @param task Task. - * - * @return Task address. - */ -__STATIC_INLINE uint32_t nrf_usbd_task_address_get(nrf_usbd_task_t task); - -/** - * @brief Function for clearing the specified event. - * - * @param event Event. - */ -__STATIC_INLINE void nrf_usbd_event_clear(nrf_usbd_event_t event); - -/** - * @brief Function for retrieving the state of the USBD event. - * - * @param[in] event Event to be checked. - * - * @retval true The event has been generated. - * @retval false The event has not been generated. - */ -__STATIC_INLINE bool nrf_usbd_event_check(nrf_usbd_event_t event); - -/** - * @brief Function for getting and clearing the state of the specified event. - * - * This function checks the state of the event and clears it. - * - * @param event Event. - * - * @retval true The event was set. - * @retval false The event was not set. - */ -__STATIC_INLINE bool nrf_usbd_event_get_and_clear(nrf_usbd_event_t event); - -/** - * @brief Function for returning the address of the specified USBD event register. - * - * @param event Event. - * - * @return Address. - */ -__STATIC_INLINE uint32_t nrf_usbd_event_address_get(nrf_usbd_event_t event); - -/** - * @brief Function for setting shortcuts. - * - * @param mask Shortcut mask. - */ -__STATIC_INLINE void nrf_usbd_shorts_enable(uint32_t mask); - -/** - * @brief Function for clearing shortcuts. - * - * @param mask Shortcut mask. - */ -__STATIC_INLINE void nrf_usbd_shorts_disable(uint32_t mask); - -/** - * @brief Function for getting the shortcut mask. - * - * Function returns shortcut register. - * - * @return Flags of the currently enabled shortcuts. - */ -__STATIC_INLINE uint32_t nrf_usbd_shorts_get(void); - -/** - * @brief Function for enabling the selected interrupts. - * - * @param mask Mask of interrupts to be enabled. - */ -__STATIC_INLINE void nrf_usbd_int_enable(uint32_t mask); - -/** - * @brief Function for retrieving the state of the selected interrupts. - * - * @param mask Mask of interrupts to be checked. - * - * @retval true Any of selected interrupts is enabled. - * @retval false None of selected interrupts is enabled. - */ -__STATIC_INLINE bool nrf_usbd_int_enable_check(uint32_t mask); - -/** - * @brief Function for retrieving the information about the enabled interrupts. - * - * @return The flags of the enabled interrupts. - */ -__STATIC_INLINE uint32_t nrf_usbd_int_enable_get(void); - -/** - * @brief Function for disabling the selected interrupts. - * - * @param mask Mask of interrupts to be disabled. - */ -__STATIC_INLINE void nrf_usbd_int_disable(uint32_t mask); - - -/** @} */ /* End of nrf_usbd_hal */ - - -#ifndef SUPPRESS_INLINE_IMPLEMENTATION - -/* ------------------------------------------------------------------------------------------------ - * Internal functions - */ - -/** - * @internal - * @brief Internal function for getting the register address of task or event. - * - * @param[in] offset Offset of the register from the beginning of the instance. - * - * @attention The offset must be aligned to 4. In other case, hardware fault can occur. - * @return Pointer to the register. - */ -__STATIC_INLINE volatile uint32_t* nrf_usbd_getRegPtr(uint32_t offset) -{ - return (volatile uint32_t*)(((uint8_t *)NRF_USBD) + (uint32_t)offset); -} - -/** - * @internal - * @brief Internal function for getting the register address of task or event - constant version. - * - * @param[in] offset Offset of the register from the beginning of the instance. - * - * @attention The offset must be aligned to 4. In other case, hardware fault can occur. - * @return Pointer to the register. - */ -__STATIC_INLINE volatile const uint32_t* nrf_usbd_getRegPtr_c(uint32_t offset) -{ - return (volatile const uint32_t*)(((uint8_t *)NRF_USBD) + (uint32_t)offset); -} - -/* ------------------------------------------------------------------------------------------------ - * Interface functions definitions - */ - -void nrf_usbd_task_trigger(nrf_usbd_task_t task) -{ - *(nrf_usbd_getRegPtr((uint32_t)task)) = 1UL; - __ISB(); - __DSB(); -} - -uint32_t nrf_usbd_task_address_get(nrf_usbd_task_t task) -{ - return (uint32_t)nrf_usbd_getRegPtr_c((uint32_t)task); -} - -void nrf_usbd_event_clear(nrf_usbd_event_t event) -{ - *(nrf_usbd_getRegPtr((uint32_t)event)) = 0UL; - __ISB(); - __DSB(); -} - -bool nrf_usbd_event_check(nrf_usbd_event_t event) -{ - return (bool)*nrf_usbd_getRegPtr_c((uint32_t)event); -} - -bool nrf_usbd_event_get_and_clear(nrf_usbd_event_t event) -{ - bool ret = nrf_usbd_event_check(event); - if (ret) - { - nrf_usbd_event_clear(event); - } - return ret; -} - -uint32_t nrf_usbd_event_address_get(nrf_usbd_event_t event) -{ - return (uint32_t)nrf_usbd_getRegPtr_c((uint32_t)event); -} - -void nrf_usbd_shorts_enable(uint32_t mask) -{ - NRF_USBD->SHORTS |= mask; -} - -void nrf_usbd_shorts_disable(uint32_t mask) -{ - if (~0U == mask) - { - /* Optimized version for "disable all" */ - NRF_USBD->SHORTS = 0; - } - else - { - NRF_USBD->SHORTS &= ~mask; - } -} - -uint32_t nrf_usbd_shorts_get(void) -{ - return NRF_USBD->SHORTS; -} - -void nrf_usbd_int_enable(uint32_t mask) -{ - NRF_USBD->INTENSET = mask; -} - -bool nrf_usbd_int_enable_check(uint32_t mask) -{ - return !!(NRF_USBD->INTENSET & mask); -} - -uint32_t nrf_usbd_int_enable_get(void) -{ - return NRF_USBD->INTENSET; -} - -void nrf_usbd_int_disable(uint32_t mask) -{ - NRF_USBD->INTENCLR = mask; -} - -#endif /* SUPPRESS_INLINE_IMPLEMENTATION */ - -/* ------------------------------------------------------------------------------------------------ - * End of automatically generated part - * ------------------------------------------------------------------------------------------------ - */ -/** - * @addtogroup nrf_usbd_hal - * @{ - */ - -/** - * @brief Frame counter size. - * - * The number of counts that can be fitted into frame counter. - */ -#define NRF_USBD_FRAMECNTR_SIZE \ - ( (USBD_FRAMECNTR_FRAMECNTR_Msk >> USBD_FRAMECNTR_FRAMECNTR_Pos) + 1UL ) -#ifndef USBD_FRAMECNTR_FRAMECNTR_Msk -#error USBD_FRAMECNTR_FRAMECNTR_Msk should be changed into USBD_FRAMECNTR_FRAMECNTR_Msk -#endif - -/** - * @brief First isochronous endpoint number. - * - * The number of the first isochronous endpoint. - */ -#define NRF_USBD_EPISO_FIRST 8 - -/** - * @brief Total number of IN endpoints. - * - * Total number of IN endpoint (including ISOCHRONOUS). - */ -#define NRF_USBD_EPIN_CNT 9 - -/** - * @brief Total number of OUT endpoints. - * - * Total number of OUT endpoint (including ISOCHRONOUS). - */ -#define NRF_USBD_EPOUT_CNT 9 - -/** @brief Mask of the direction bit in an endpoint number. */ -#define NRF_USBD_EP_DIR_Msk (1U << 7) - -/** @brief The value of direction bit for the IN endpoint direction. */ -#define NRF_USBD_EP_DIR_IN (1U << 7) - -/** @brief The value of direction bit for the OUT endpoint direction. */ -#define NRF_USBD_EP_DIR_OUT (0U << 7) - -/** - * @brief Macro for making the IN endpoint identifier from endpoint number. - * - * Macro that sets direction bit to make IN endpoint. - * @param[in] epnr Endpoint number. - * @return IN Endpoint identifier. - */ -#define NRF_USBD_EPIN(epnr) (((uint8_t)(epnr)) | NRF_USBD_EP_DIR_IN) - -/** - * @brief Macro for making the OUT endpoint identifier from endpoint number. - * - * Macro that sets direction bit to make OUT endpoint. - * @param[in] epnr Endpoint number. - * @return OUT Endpoint identifier. - */ -#define NRF_USBD_EPOUT(epnr) (((uint8_t)(epnr)) | NRF_USBD_EP_DIR_OUT) - -/** - * @brief Macro for extracting the endpoint number from the specified endpoint identifier. - * - * Macro that strips out the information about endpoint direction. - * - * @param[in] ep Endpoint identifier. - * - * @return Endpoint number. - */ -#define NRF_USBD_EP_NR_GET(ep) ((uint8_t)(((uint8_t)(ep)) & 0xFU)) - -/** - * @brief Macro for checking the endpoint direction. - * - * This macro checks if the specified endpoint has the IN direction. - * - * @param ep Endpoint identifier. - * - * @retval true The endpoint direction is IN. - * @retval false The endpoint direction is OUT. - */ -#define NRF_USBD_EPIN_CHECK(ep) ( (((uint8_t)(ep)) & NRF_USBD_EP_DIR_Msk) == NRF_USBD_EP_DIR_IN ) - -/** - * @brief Macro for checking endpoint direction. - * - * This macro checks if given endpoint has OUT direction. - * - * @param ep Endpoint identifier - * - * @retval true The endpoint direction is OUT - * @retval false The endpoint direction is IN - */ -#define NRF_USBD_EPOUT_CHECK(ep) ( (((uint8_t)(ep)) & NRF_USBD_EP_DIR_Msk) == NRF_USBD_EP_DIR_OUT ) - -/** - * @brief Macro for checking if endpoint is isochronous. - * - * @param ep It can be endpoint identifier or just endpoint number to be checked. - * - * @retval true The endpoint is isochronous type. - * @retval false The endpoint is bulk of interrupt type. - */ -#define NRF_USBD_EPISO_CHECK(ep) (NRF_USBD_EP_NR_GET(ep) >= NRF_USBD_EPISO_FIRST) - -/** - * @brief Macro for checking if given number is valid endpoint number. - * - * @param ep Endpoint number to be checked. - * - * @retval true The endpoint is valid. - * @retval false The endpoint is not valid. - */ -#define NRF_USBD_EP_VALIDATE(ep) ( \ - (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 Not isochronous data frame received. - * - * Special value returned by @ref nrf_usbd_episoout_size_get function that means that - * data frame was not received at all. - * This allows differentiate between situations when zero size data comes or no data comes at all - * on isochronous endpoint. - */ -#define NRF_USBD_EPISOOUT_NO_DATA ((size_t)(-1)) - -/** @brief EVENTCAUSE register bit masks. */ -typedef enum -{ - NRF_USBD_EVENTCAUSE_ISOOUTCRC_MASK = USBD_EVENTCAUSE_ISOOUTCRC_Msk, /**< CRC error was detected on isochronous OUT endpoint 8. */ - NRF_USBD_EVENTCAUSE_SUSPEND_MASK = USBD_EVENTCAUSE_SUSPEND_Msk, /**< Signals that the USB lines have been seen idle long enough for the device to enter suspend. */ - NRF_USBD_EVENTCAUSE_RESUME_MASK = USBD_EVENTCAUSE_RESUME_Msk, /**< Signals that a RESUME condition (K state or activity restart) has been detected on the USB lines. */ - NRF_USBD_EVENTCAUSE_WUREQ_MASK = USBD_EVENTCAUSE_USBWUALLOWED_Msk, /**< The USBD peripheral has exited Low Power mode. */ - NRF_USBD_EVENTCAUSE_READY_MASK = USBD_EVENTCAUSE_READY_Msk, /**< MAC is ready for normal operation, rised few us after USBD enabling. */ -}nrf_usbd_eventcause_mask_t; - -/** @brief DPDMVALUE register. */ -typedef enum -{ - /** Generate RESUME signal. Signal is generated for 50 us or 5 ms, - * depending on bus state. */ - NRF_USBD_DPDMVALUE_RESUME = USBD_DPDMVALUE_STATE_Resume, - /** D+ Forced high, D- forced low (J state) */ - NRF_USBD_DPDMVALUE_J = USBD_DPDMVALUE_STATE_J, - /** D+ Forced low, D- forced high (K state) */ - NRF_USBD_DPMVALUE_K = USBD_DPDMVALUE_STATE_K -}nrf_usbd_dpdmvalue_t; - -/** @brief Data toggle value or operation. */ -typedef enum -{ - NRF_USBD_DTOGGLE_NOP = USBD_DTOGGLE_VALUE_Nop, /**< No operation - do not change the current data toggle on the selected endpoint. */ - NRF_USBD_DTOGGLE_DATA0 = USBD_DTOGGLE_VALUE_Data0,/**< Data toggle is DATA0 on the selected endpoint. */ - NRF_USBD_DTOGGLE_DATA1 = USBD_DTOGGLE_VALUE_Data1 /**< Data toggle is DATA1 on the selected endpoint. */ -}nrf_usbd_dtoggle_t; - -/** @brief EPSTATUS bit masks. */ -typedef enum -{ - NRF_USBD_EPSTATUS_EPIN0_MASK = USBD_EPSTATUS_EPIN0_Msk, - NRF_USBD_EPSTATUS_EPIN1_MASK = USBD_EPSTATUS_EPIN1_Msk, - NRF_USBD_EPSTATUS_EPIN2_MASK = USBD_EPSTATUS_EPIN2_Msk, - NRF_USBD_EPSTATUS_EPIN3_MASK = USBD_EPSTATUS_EPIN3_Msk, - NRF_USBD_EPSTATUS_EPIN4_MASK = USBD_EPSTATUS_EPIN4_Msk, - NRF_USBD_EPSTATUS_EPIN5_MASK = USBD_EPSTATUS_EPIN5_Msk, - NRF_USBD_EPSTATUS_EPIN6_MASK = USBD_EPSTATUS_EPIN6_Msk, - NRF_USBD_EPSTATUS_EPIN7_MASK = USBD_EPSTATUS_EPIN7_Msk, - - NRF_USBD_EPSTATUS_EPOUT0_MASK = USBD_EPSTATUS_EPOUT0_Msk, - NRF_USBD_EPSTATUS_EPOUT1_MASK = USBD_EPSTATUS_EPOUT1_Msk, - NRF_USBD_EPSTATUS_EPOUT2_MASK = USBD_EPSTATUS_EPOUT2_Msk, - NRF_USBD_EPSTATUS_EPOUT3_MASK = USBD_EPSTATUS_EPOUT3_Msk, - NRF_USBD_EPSTATUS_EPOUT4_MASK = USBD_EPSTATUS_EPOUT4_Msk, - NRF_USBD_EPSTATUS_EPOUT5_MASK = USBD_EPSTATUS_EPOUT5_Msk, - NRF_USBD_EPSTATUS_EPOUT6_MASK = USBD_EPSTATUS_EPOUT6_Msk, - NRF_USBD_EPSTATUS_EPOUT7_MASK = USBD_EPSTATUS_EPOUT7_Msk, -}nrf_usbd_epstatus_mask_t; - -/** @brief DATAEPSTATUS bit masks. */ -typedef enum -{ - NRF_USBD_EPDATASTATUS_EPIN1_MASK = USBD_EPDATASTATUS_EPIN1_Msk, - NRF_USBD_EPDATASTATUS_EPIN2_MASK = USBD_EPDATASTATUS_EPIN2_Msk, - NRF_USBD_EPDATASTATUS_EPIN3_MASK = USBD_EPDATASTATUS_EPIN3_Msk, - NRF_USBD_EPDATASTATUS_EPIN4_MASK = USBD_EPDATASTATUS_EPIN4_Msk, - NRF_USBD_EPDATASTATUS_EPIN5_MASK = USBD_EPDATASTATUS_EPIN5_Msk, - NRF_USBD_EPDATASTATUS_EPIN6_MASK = USBD_EPDATASTATUS_EPIN6_Msk, - NRF_USBD_EPDATASTATUS_EPIN7_MASK = USBD_EPDATASTATUS_EPIN7_Msk, - - NRF_USBD_EPDATASTATUS_EPOUT1_MASK = USBD_EPDATASTATUS_EPOUT1_Msk, - NRF_USBD_EPDATASTATUS_EPOUT2_MASK = USBD_EPDATASTATUS_EPOUT2_Msk, - NRF_USBD_EPDATASTATUS_EPOUT3_MASK = USBD_EPDATASTATUS_EPOUT3_Msk, - NRF_USBD_EPDATASTATUS_EPOUT4_MASK = USBD_EPDATASTATUS_EPOUT4_Msk, - NRF_USBD_EPDATASTATUS_EPOUT5_MASK = USBD_EPDATASTATUS_EPOUT5_Msk, - NRF_USBD_EPDATASTATUS_EPOUT6_MASK = USBD_EPDATASTATUS_EPOUT6_Msk, - NRF_USBD_EPDATASTATUS_EPOUT7_MASK = USBD_EPDATASTATUS_EPOUT7_Msk, -}nrf_usbd_dataepstatus_mask_t; - -/** @brief ISOSPLIT configurations. */ -typedef enum -{ - NRF_USBD_ISOSPLIT_ONEDIR = USBD_ISOSPLIT_SPLIT_OneDir, /**< Full buffer dedicated to either ISO IN or OUT. */ - NRF_USBD_ISOSPLIT_HALF = USBD_ISOSPLIT_SPLIT_HalfIN, /**< Buffer divided in half. */ -}nrf_usbd_isosplit_t; - -/** @brief ISOINCONFIG configurations. */ -typedef enum -{ - NRF_USBD_ISOINCONFIG_NORESP = USBD_ISOINCONFIG_RESPONSE_NoResp, /**< Endpoint does not respond to an ISO IN token when no data is ready. */ - NRF_USBD_ISOINCONFIG_ZERODATA = USBD_ISOINCONFIG_RESPONSE_ZeroData, /**< Endpoint responds with a zero-length data packet to an ISO IN token when no data is ready. */ -}nrf_usbd_isoinconfig_t; - -/** @brief Function for enabling the USBD. */ -__STATIC_INLINE void nrf_usbd_enable(void); - -/** @brief Function for disabling the USBD. */ -__STATIC_INLINE void nrf_usbd_disable(void); - -/** - * @brief Function for getting the EVENTCAUSE register. - * - * @return Flag values defined in @ref nrf_usbd_eventcause_mask_t. - */ -__STATIC_INLINE uint32_t nrf_usbd_eventcause_get(void); - -/** - * @brief Function for clearing the EVENTCAUSE flags. - * - * @param flags Flags defined in @ref nrf_usbd_eventcause_mask_t. - */ -__STATIC_INLINE void nrf_usbd_eventcause_clear(uint32_t flags); - -/** - * @brief Function for getting the EVENTCAUSE register and clearing flags that are set. - * - * The safest way to return current EVENTCAUSE register. - * All the flags that are returned would be cleared inside EVENTCAUSE register. - * - * @return Flag values defined in @ref nrf_usbd_eventcause_mask_t - */ -__STATIC_INLINE uint32_t nrf_usbd_eventcause_get_and_clear(void); - -/** - * @brief Function for getting the HALTEDEPIN register value. - * - * @note Use this function for the response for GetStatus() request to endpoint. - * To check whether the endpoint is stalled in the code, use @ref nrf_usbd_ep_is_stall. - * - * @param ep Endpoint number with IN or OUT flag. - * - * @return The value of the HALTEDEPIN or HALTEDOUT register for the selected endpoint. - */ -__STATIC_INLINE uint32_t nrf_usbd_haltedep(uint8_t ep); - -/** - * @brief Function for checking whether the selected endpoint is stalled. - * - * Function to be used as a syntax sweeter for @ref nrf_usbd_haltedep. - * - * Also as the isochronous endpoint cannot be halted - it returns always false - * if isochronous endpoint is checked. - * - * @param ep Endpoint number with IN or OUT flag. - * - * @retval true The endpoint is halted. - * @retval false The endpoint is not halted. - */ -__STATIC_INLINE bool nrf_usbd_ep_is_stall(uint8_t ep); - -/** - * @brief Function for getting EPSTATUS register value. - * - * @return Flag values defined in @ref nrf_usbd_epstatus_mask_t. - */ -__STATIC_INLINE uint32_t nrf_usbd_epstatus_get(void); - -/** - * @brief Function for clearing EPSTATUS register value. - * - * @param flags Flags defined in @ref nrf_usbd_epstatus_mask_t. - */ -__STATIC_INLINE void nrf_usbd_epstatus_clear(uint32_t flags); - -/** - * @brief Function for getting and clearing EPSTATUS register value. - * - * Function clears all flags in register set before returning its value. - * - * @return Flag values defined in @ref nrf_usbd_epstatus_mask_t. - */ -__STATIC_INLINE uint32_t nrf_usbd_epstatus_get_and_clear(void); - -/** - * @brief Function for getting DATAEPSTATUS register value. - * - * @return Flag values defined in @ref nrf_usbd_dataepstatus_mask_t. - */ -__STATIC_INLINE uint32_t nrf_usbd_epdatastatus_get(void); - -/** - * @brief Function for clearing DATAEPSTATUS register value. - * - * @param flags Flags defined in @ref nrf_usbd_dataepstatus_mask_t. - */ -__STATIC_INLINE void nrf_usbd_epdatastatus_clear(uint32_t flags); - -/** - * @brief Function for getting and clearing DATAEPSTATUS register value. - * - * Function clears all flags in register set before returning its value. - * @return Flag values defined in @ref nrf_usbd_dataepstatus_mask_t. - */ -__STATIC_INLINE uint32_t nrf_usbd_epdatastatus_get_and_clear(void); - -/** - * @name Setup command frame functions. - * - * Functions for setting up command frame part access. - * @{ - */ - /** - * @brief Function for reading BMREQUESTTYPE - part of the SETUP packet. - * - * @return Value of BREQUESTTYPE on the last received SETUP frame. - */ - __STATIC_INLINE uint8_t nrf_usbd_setup_bmrequesttype_get(void); - - /** - * @brief Function for reading BMREQUEST - part of the SETUP packet. - * - * @return Value of BREQUEST on the last received SETUP frame. - */ - __STATIC_INLINE uint8_t nrf_usbd_setup_brequest_get(void); - - /** - * @brief Function for reading WVALUE - part of the SETUP packet. - * - * @return Value of WVALUE on the last received SETUP frame. - */ - __STATIC_INLINE uint16_t nrf_usbd_setup_wvalue_get(void); - - /** - * @brief Function for reading WINDEX - part of the SETUP packet. - * - * @return Value of WINDEX on the last received SETUP frame. - */ - __STATIC_INLINE uint16_t nrf_usbd_setup_windex_get(void); - - /** - * @brief Function for reading WLENGTH - part of the SETUP packet. - * - * @return Value of WLENGTH on the last received SETUP frame. - */ - __STATIC_INLINE uint16_t nrf_usbd_setup_wlength_get(void); -/** @} */ - -/** - * @brief Function for getting the number of received bytes on the selected endpoint. - * - * @note This function can be used on bulk, interrupt, and isochronous endpoints. - * @note For the function that returns different value for the ISOOUT zero - * transfer or no transfer at all, see the @ref nrf_usbd_episoout_size_get - * function. This function will return 0 for both cases. - * - * @param ep Endpoint identifier. - * - * @return Number of received bytes. - */ -__STATIC_INLINE size_t nrf_usbd_epout_size_get(uint8_t ep); - -/** - * @brief Function for getting number of the received bytes on isochronous endpoint. - * - * @param ep Endpoint identifier, must be an isochronous OUT endpoint. - * - * @return Number of bytes received or @ref NRF_USBD_EPISOOUT_NO_DATA. - */ -__STATIC_INLINE size_t nrf_usbd_episoout_size_get(uint8_t ep); - -/** - * @brief Function for clearing OUT endpoint to accept any new incoming traffic. - * - * @param ep ep Endpoint identifier. Only OUT interrupt/bulk endpoints are accepted. - */ -__STATIC_INLINE void nrf_usbd_epout_clear(uint8_t ep); - -/** @brief Function for enabling the USB pullup. */ -__STATIC_INLINE void nrf_usbd_pullup_enable(void); - -/** @brief Function for disabling the USB pullup. */ -__STATIC_INLINE void nrf_usbd_pullup_disable(void); - -/** - * @brief Function for returning the current the USB pullup state. - * - * @retval true The USB pullup is enabled. - * @retval false The USB pullup is disabled. - */ -__STATIC_INLINE bool nrf_usbd_pullup_check(void); - -/** - * @brief Function for configuring the value to be forced on the bus on the DRIVEDPDM task. - * - * The selected state will be forced on the bus when @ref NRF_USBD_TASK_DRIVEDPDM is set. - * The state will be removed from the bus on @ref NRF_USBD_TASK_NODRIVEDPDM and - * the control will be returned to the USBD peripheral. - * @param val State to be set. - */ -__STATIC_INLINE void nrf_usbd_dpdmvalue_set(nrf_usbd_dpdmvalue_t val); - -/** - * @brief Function for setting the data toggle. - * - * Configuration of the current state of data toggling. - * @param ep Endpoint number with the information about its direction. - * @param op Operation to execute. - */ -__STATIC_INLINE void nrf_usbd_dtoggle_set(uint8_t ep, nrf_usbd_dtoggle_t op); - -/** - * @brief Function for getting the data toggle. - * - * Get the current state of data toggling. - * - * @param ep Endpoint number to return the information about current data toggling. - * - * @retval NRF_USBD_DTOGGLE_DATA0 Data toggle is DATA0 on selected endpoint. - * @retval NRF_USBD_DTOGGLE_DATA1 Data toggle is DATA1 on selected endpoint. - */ -__STATIC_INLINE nrf_usbd_dtoggle_t nrf_usbd_dtoggle_get(uint8_t ep); - -/** - * @brief Function for checking whether the endpoint is enabled. - * - * @param ep Endpoint ID to be checked. - * - * @retval true Endpoint is enabled. - * @retval false Endpoint is disabled. - */ -__STATIC_INLINE bool nrf_usbd_ep_enable_check(uint8_t ep); - -/** - * @brief Function for enabling the selected endpoint. - * - * The enabled endpoint responds for the tokens on the USB bus. - * - * @param ep Endpoint ID to be enabled. - */ -__STATIC_INLINE void nrf_usbd_ep_enable(uint8_t ep); - -/** - * @brief Function for disabling the selected endpoint. - * - * The disabled endpoint does not respond for the tokens on the USB bus. - * - * @param ep Endpoint ID to be disabled. - */ -__STATIC_INLINE void nrf_usbd_ep_disable(uint8_t ep); - -/** - * @brief Function for disabling all endpoints. - * - * An auxiliary function to disable all aviable endpoints. - * It leaves only EP0 IN and OUT enabled. - */ -__STATIC_INLINE void nrf_usbd_ep_all_disable(void); - -/** - * @brief Function for stalling the selected endpoint. - * - * @note This function cannot be called on isochronous endpoint. - * - * @param ep Endpoint identifier. - */ -__STATIC_INLINE void nrf_usbd_ep_stall(uint8_t ep); - -/** - * @brief Function for unstalling the selected endpoint. - * - * @note This function cannot be called on isochronous endpoint. - * - * @param ep Endpoint identifier - */ -__STATIC_INLINE void nrf_usbd_ep_unstall(uint8_t ep); - -/** - * @brief Function for configuring the isochronous buffer splitting. - * - * This function configures isochronous buffer splitting between IN and OUT endpoints. - * - * @param split Required configuration. - */ -__STATIC_INLINE void nrf_usbd_isosplit_set(nrf_usbd_isosplit_t split); - -/** - * @brief Function for getting the isochronous buffer splitting configuration. - * - * This function gets the current isochronous buffer splitting configuration. - * - * @return Current configuration. - */ -__STATIC_INLINE nrf_usbd_isosplit_t nrf_usbd_isosplit_get(void); - -/** - * @brief Function for getting current frame counter. - * - * @return Current frame counter. - */ -__STATIC_INLINE uint32_t nrf_usbd_framecntr_get(void); - -/** - * @brief Function for entering into the USB low power mode. - * - * After this function is called, the clock source from the USBD is disconnected internally. - * After this function is called, most of the USBD registers cannot be accessed anymore. - * - * @sa nrf_usbd_lowpower_disable - * @sa nrf_usbd_lowpower_check - */ -__STATIC_INLINE void nrf_usbd_lowpower_enable(void); - -/** - * @brief Function for exiting from the USB low power mode. - * - * After this function is called, the clock source for the USBD is connected internally. - * The @ref NRF_USBD_EVENTCAUSE_WUREQ_MASK event will be generated and - * then the USBD registers can be accessed. - * - * @sa nrf_usbd_lowpower_enable - * @sa nrf_usbd_lowpower_check - */ -__STATIC_INLINE void nrf_usbd_lowpower_disable(void); - -/** - * @brief Function for checking the state of the low power mode. - * - * @retval true The USBD is in low power mode. - * @retval false The USBD is not in low power mode. - */ -__STATIC_INLINE bool nrf_usbd_lowpower_check(void); - -/** - * @brief Function for configuring ISO IN endpoint response to an IN token when no data is ready to be sent. - * - * @param config Required configuration. - */ -__STATIC_INLINE void nrf_usbd_isoinconfig_set(nrf_usbd_isoinconfig_t config); - -/** - * @brief Function for getting the cofiguration of ISO IN endpoint response to an IN token when no data is ready to be sent. - * - * @return Current configuration. - */ -__STATIC_INLINE nrf_usbd_isoinconfig_t nrf_usbd_isoinconfig_get(void); - -/** - * @brief Function for configuring the EasyDMA channel. - * - * Configures EasyDMA for the transfer. - * - * @param ep Endpoint identifier (with direction). - * @param ptr Pointer to the data. - * @param maxcnt Number of bytes to transfer. - */ -__STATIC_INLINE void nrf_usbd_ep_easydma_set(uint8_t ep, uint32_t ptr, uint32_t maxcnt); - -/** - * @brief Function for getting number of transferred bytes. - * - * This function gets the number of transferred bytes in the last transaction. - * - * @param ep Endpoint identifier. - * - * @return The content of the AMOUNT register. - */ -__STATIC_INLINE uint32_t nrf_usbd_ep_amount_get(uint8_t ep); - - -#ifndef SUPPRESS_INLINE_IMPLEMENTATION - -void nrf_usbd_enable(void) -{ -#ifdef NRF_FPGA_IMPLEMENTATION - *(volatile uint32_t *)0x400005F4 = 3; - __ISB(); - __DSB(); - *(volatile uint32_t *)0x400005F0 = 3; - __ISB(); - __DSB(); -#endif - - NRF_USBD->ENABLE = USBD_ENABLE_ENABLE_Enabled << USBD_ENABLE_ENABLE_Pos; - __ISB(); - __DSB(); -} - -void nrf_usbd_disable(void) -{ - NRF_USBD->ENABLE = USBD_ENABLE_ENABLE_Disabled << USBD_ENABLE_ENABLE_Pos; - __ISB(); - __DSB(); -} - -uint32_t nrf_usbd_eventcause_get(void) -{ - return NRF_USBD->EVENTCAUSE; -} - -void nrf_usbd_eventcause_clear(uint32_t flags) -{ - NRF_USBD->EVENTCAUSE = flags; - __ISB(); - __DSB(); -} - -uint32_t nrf_usbd_eventcause_get_and_clear(void) -{ - uint32_t ret; - ret = nrf_usbd_eventcause_get(); - nrf_usbd_eventcause_clear(ret); - __ISB(); - __DSB(); - return ret; -} - -uint32_t nrf_usbd_haltedep(uint8_t ep) -{ - uint8_t epnr = NRF_USBD_EP_NR_GET(ep); - if (NRF_USBD_EPIN_CHECK(ep)) - { - NRFX_ASSERT(epnr < NRFX_ARRAY_SIZE(NRF_USBD->HALTED.EPIN)); - return NRF_USBD->HALTED.EPIN[epnr]; - } - else - { - NRFX_ASSERT(epnr < NRFX_ARRAY_SIZE(NRF_USBD->HALTED.EPOUT)); - return NRF_USBD->HALTED.EPOUT[epnr]; - } -} - -bool nrf_usbd_ep_is_stall(uint8_t ep) -{ - if (NRF_USBD_EPISO_CHECK(ep)) - return false; - return USBD_HALTED_EPOUT_GETSTATUS_Halted == nrf_usbd_haltedep(ep); -} - -uint32_t nrf_usbd_epstatus_get(void) -{ - return NRF_USBD->EPSTATUS; -} - -void nrf_usbd_epstatus_clear(uint32_t flags) -{ - NRF_USBD->EPSTATUS = flags; - __ISB(); - __DSB(); -} - -uint32_t nrf_usbd_epstatus_get_and_clear(void) -{ - uint32_t ret; - ret = nrf_usbd_epstatus_get(); - nrf_usbd_epstatus_clear(ret); - return ret; -} - -uint32_t nrf_usbd_epdatastatus_get(void) -{ - return NRF_USBD->EPDATASTATUS; -} - -void nrf_usbd_epdatastatus_clear(uint32_t flags) -{ - NRF_USBD->EPDATASTATUS = flags; - __ISB(); - __DSB(); -} - -uint32_t nrf_usbd_epdatastatus_get_and_clear(void) -{ - uint32_t ret; - ret = nrf_usbd_epdatastatus_get(); - nrf_usbd_epdatastatus_clear(ret); - return ret; -} - -uint8_t nrf_usbd_setup_bmrequesttype_get(void) -{ - return (uint8_t)(NRF_USBD->BMREQUESTTYPE); -} - -uint8_t nrf_usbd_setup_brequest_get(void) -{ - return (uint8_t)(NRF_USBD->BREQUEST); -} - -uint16_t nrf_usbd_setup_wvalue_get(void) -{ - const uint16_t val = NRF_USBD->WVALUEL; - return (uint16_t)(val | ((NRF_USBD->WVALUEH) << 8)); -} - -uint16_t nrf_usbd_setup_windex_get(void) -{ - const uint16_t val = NRF_USBD->WINDEXL; - return (uint16_t)(val | ((NRF_USBD->WINDEXH) << 8)); -} - -uint16_t nrf_usbd_setup_wlength_get(void) -{ - const uint16_t val = NRF_USBD->WLENGTHL; - return (uint16_t)(val | ((NRF_USBD->WLENGTHH) << 8)); -} - -size_t nrf_usbd_epout_size_get(uint8_t ep) -{ - NRFX_ASSERT(NRF_USBD_EP_VALIDATE(ep)); - NRFX_ASSERT(NRF_USBD_EPOUT_CHECK(ep)); - if (NRF_USBD_EPISO_CHECK(ep)) - { - size_t size_isoout = NRF_USBD->SIZE.ISOOUT; - if ((size_isoout & USBD_SIZE_ISOOUT_ZERO_Msk) == (USBD_SIZE_ISOOUT_ZERO_ZeroData << USBD_SIZE_ISOOUT_ZERO_Pos)) - { - size_isoout = 0; - } - return size_isoout; - } - - NRFX_ASSERT(NRF_USBD_EP_NR_GET(ep) < NRFX_ARRAY_SIZE(NRF_USBD->SIZE.EPOUT)); - return NRF_USBD->SIZE.EPOUT[NRF_USBD_EP_NR_GET(ep)]; -} - -size_t nrf_usbd_episoout_size_get(uint8_t ep) -{ - NRFX_ASSERT(NRF_USBD_EP_VALIDATE(ep)); - NRFX_ASSERT(NRF_USBD_EPOUT_CHECK(ep)); - NRFX_ASSERT(NRF_USBD_EPISO_CHECK(ep)); - - size_t size_isoout = NRF_USBD->SIZE.ISOOUT; - if (size_isoout == 0) - { - size_isoout = NRF_USBD_EPISOOUT_NO_DATA; - } - else if ((size_isoout & USBD_SIZE_ISOOUT_ZERO_Msk) == (USBD_SIZE_ISOOUT_ZERO_ZeroData << USBD_SIZE_ISOOUT_ZERO_Pos)) - { - size_isoout = 0; - } - return size_isoout; -} - -void nrf_usbd_epout_clear(uint8_t ep) -{ - NRFX_ASSERT(NRF_USBD_EPOUT_CHECK(ep) && (NRF_USBD_EP_NR_GET(ep) < NRFX_ARRAY_SIZE(NRF_USBD->SIZE.EPOUT))); - NRF_USBD->SIZE.EPOUT[NRF_USBD_EP_NR_GET(ep)] = 0; - __ISB(); - __DSB(); -} - -void nrf_usbd_pullup_enable(void) -{ - NRF_USBD->USBPULLUP = USBD_USBPULLUP_CONNECT_Enabled << USBD_USBPULLUP_CONNECT_Pos; - __ISB(); - __DSB(); -} - -void nrf_usbd_pullup_disable(void) -{ - NRF_USBD->USBPULLUP = USBD_USBPULLUP_CONNECT_Disabled << USBD_USBPULLUP_CONNECT_Pos; - __ISB(); - __DSB(); -} - -bool nrf_usbd_pullup_check(void) -{ - return NRF_USBD->USBPULLUP == (USBD_USBPULLUP_CONNECT_Enabled << USBD_USBPULLUP_CONNECT_Pos); -} - -void nrf_usbd_dpdmvalue_set(nrf_usbd_dpdmvalue_t val) -{ - NRF_USBD->DPDMVALUE = ((uint32_t)val) << USBD_DPDMVALUE_STATE_Pos; -} - -void nrf_usbd_dtoggle_set(uint8_t ep, nrf_usbd_dtoggle_t op) -{ - NRFX_ASSERT(NRF_USBD_EP_VALIDATE(ep)); - NRFX_ASSERT(!NRF_USBD_EPISO_CHECK(ep)); - NRF_USBD->DTOGGLE = ep | (NRF_USBD_DTOGGLE_NOP << USBD_DTOGGLE_VALUE_Pos); - __DSB(); - NRF_USBD->DTOGGLE = ep | (op << USBD_DTOGGLE_VALUE_Pos); - __ISB(); - __DSB(); -} - -nrf_usbd_dtoggle_t nrf_usbd_dtoggle_get(uint8_t ep) -{ - uint32_t retval; - /* Select the endpoint to read */ - NRF_USBD->DTOGGLE = ep | (NRF_USBD_DTOGGLE_NOP << USBD_DTOGGLE_VALUE_Pos); - retval = ((NRF_USBD->DTOGGLE) & USBD_DTOGGLE_VALUE_Msk) >> USBD_DTOGGLE_VALUE_Pos; - return (nrf_usbd_dtoggle_t)retval; -} - -bool nrf_usbd_ep_enable_check(uint8_t ep) -{ - NRFX_ASSERT(NRF_USBD_EP_VALIDATE(ep)); - uint8_t epnr = NRF_USBD_EP_NR_GET(ep); - - if (NRF_USBD_EPIN_CHECK(ep)) - { - return 0 != (NRF_USBD->EPINEN & (1UL << epnr)); - } - else - { - return 0 != (NRF_USBD->EPOUTEN & (1UL << epnr)); - } -} - -void nrf_usbd_ep_enable(uint8_t ep) -{ - NRFX_ASSERT(NRF_USBD_EP_VALIDATE(ep)); - uint8_t epnr = NRF_USBD_EP_NR_GET(ep); - - if (NRF_USBD_EPIN_CHECK(ep)) - { - NRF_USBD->EPINEN |= 1UL << epnr; - } - else - { - NRF_USBD->EPOUTEN |= 1UL << epnr; - } - __ISB(); - __DSB(); -} - -void nrf_usbd_ep_disable(uint8_t ep) -{ - NRFX_ASSERT(NRF_USBD_EP_VALIDATE(ep)); - uint8_t epnr = NRF_USBD_EP_NR_GET(ep); - - if (NRF_USBD_EPIN_CHECK(ep)) - { - NRF_USBD->EPINEN &= ~(1UL << epnr); - } - else - { - NRF_USBD->EPOUTEN &= ~(1UL << epnr); - } - __ISB(); - __DSB(); -} - -void nrf_usbd_ep_all_disable(void) -{ - NRF_USBD->EPINEN = USBD_EPINEN_IN0_Enable << USBD_EPINEN_IN0_Pos; - NRF_USBD->EPOUTEN = USBD_EPOUTEN_OUT0_Enable << USBD_EPOUTEN_OUT0_Pos; - __ISB(); - __DSB(); -} - -void nrf_usbd_ep_stall(uint8_t ep) -{ - NRFX_ASSERT(!NRF_USBD_EPISO_CHECK(ep)); - NRF_USBD->EPSTALL = (USBD_EPSTALL_STALL_Stall << USBD_EPSTALL_STALL_Pos) | ep; - __ISB(); - __DSB(); -} - -void nrf_usbd_ep_unstall(uint8_t ep) -{ - NRFX_ASSERT(!NRF_USBD_EPISO_CHECK(ep)); - NRF_USBD->EPSTALL = (USBD_EPSTALL_STALL_UnStall << USBD_EPSTALL_STALL_Pos) | ep; - __ISB(); - __DSB(); -} - -void nrf_usbd_isosplit_set(nrf_usbd_isosplit_t split) -{ - NRF_USBD->ISOSPLIT = split << USBD_ISOSPLIT_SPLIT_Pos; -} - -nrf_usbd_isosplit_t nrf_usbd_isosplit_get(void) -{ - return (nrf_usbd_isosplit_t) - (((NRF_USBD->ISOSPLIT) & USBD_ISOSPLIT_SPLIT_Msk) >> USBD_ISOSPLIT_SPLIT_Pos); -} - -uint32_t nrf_usbd_framecntr_get(void) -{ - return NRF_USBD->FRAMECNTR; -} - -void nrf_usbd_lowpower_enable(void) -{ - NRF_USBD->LOWPOWER = USBD_LOWPOWER_LOWPOWER_LowPower << USBD_LOWPOWER_LOWPOWER_Pos; -} - -void nrf_usbd_lowpower_disable(void) -{ - NRF_USBD->LOWPOWER = USBD_LOWPOWER_LOWPOWER_ForceNormal << USBD_LOWPOWER_LOWPOWER_Pos; -} - -bool nrf_usbd_lowpower_check(void) -{ - return (NRF_USBD->LOWPOWER != (USBD_LOWPOWER_LOWPOWER_ForceNormal << USBD_LOWPOWER_LOWPOWER_Pos)); -} - -void nrf_usbd_isoinconfig_set(nrf_usbd_isoinconfig_t config) -{ - NRF_USBD->ISOINCONFIG = ((uint32_t)config) << USBD_ISOINCONFIG_RESPONSE_Pos; -} - -nrf_usbd_isoinconfig_t nrf_usbd_isoinconfig_get(void) -{ - return (nrf_usbd_isoinconfig_t) - (((NRF_USBD->ISOINCONFIG) & USBD_ISOINCONFIG_RESPONSE_Msk) >> USBD_ISOINCONFIG_RESPONSE_Pos); -} - -void nrf_usbd_ep_easydma_set(uint8_t ep, uint32_t ptr, uint32_t maxcnt) -{ - if (NRF_USBD_EPIN_CHECK(ep)) - { - if (NRF_USBD_EPISO_CHECK(ep)) - { - NRF_USBD->ISOIN.PTR = ptr; - NRF_USBD->ISOIN.MAXCNT = maxcnt; - } - else - { - uint8_t epnr = NRF_USBD_EP_NR_GET(ep); - NRFX_ASSERT(epnr < NRFX_ARRAY_SIZE(NRF_USBD->EPIN)); - NRF_USBD->EPIN[epnr].PTR = ptr; - NRF_USBD->EPIN[epnr].MAXCNT = maxcnt; - } - } - else - { - if (NRF_USBD_EPISO_CHECK(ep)) - { - NRF_USBD->ISOOUT.PTR = ptr; - NRF_USBD->ISOOUT.MAXCNT = maxcnt; - } - else - { - uint8_t epnr = NRF_USBD_EP_NR_GET(ep); - NRFX_ASSERT(epnr < NRFX_ARRAY_SIZE(NRF_USBD->EPOUT)); - NRF_USBD->EPOUT[epnr].PTR = ptr; - NRF_USBD->EPOUT[epnr].MAXCNT = maxcnt; - } - } -} - -uint32_t nrf_usbd_ep_amount_get(uint8_t ep) -{ - uint32_t ret; - - if (NRF_USBD_EPIN_CHECK(ep)) - { - if (NRF_USBD_EPISO_CHECK(ep)) - { - ret = NRF_USBD->ISOIN.AMOUNT; - } - else - { - uint8_t epnr = NRF_USBD_EP_NR_GET(ep); - NRFX_ASSERT(epnr < NRFX_ARRAY_SIZE(NRF_USBD->EPOUT)); - ret = NRF_USBD->EPIN[epnr].AMOUNT; - } - } - else - { - if (NRF_USBD_EPISO_CHECK(ep)) - { - ret = NRF_USBD->ISOOUT.AMOUNT; - } - else - { - uint8_t epnr = NRF_USBD_EP_NR_GET(ep); - NRFX_ASSERT(epnr < NRFX_ARRAY_SIZE(NRF_USBD->EPOUT)); - ret = NRF_USBD->EPOUT[epnr].AMOUNT; - } - } - - return ret; -} - -#endif /* SUPPRESS_INLINE_IMPLEMENTATION */ - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif /* NRF_USBD_H__ */