Remove redundant legacy files and definition of PACKED

* The following v14.2 files are removed from nrfx/legacy:
  nrf_drv_clock.h
  nrf_drv_common.h
  nrf_drv_gpiote.h
  nrf_drv_spi.h
  nrf_drv_twi.h
  nrf_drv_uarth.h
* Remove unneeded references to "nrfx_glue.h" and "nrf_drv_common.h"
* Remove the definition of PACKED from app_util_platform.h (already defined
  in mbed_toolchain.h)
pull/10652/head
RFulchiero 2019-03-14 17:39:35 -05:00 committed by desmond.chen
parent 69879bd382
commit 3343022f70
10 changed files with 1 additions and 2529 deletions

View File

@ -39,10 +39,8 @@
#include "us_ticker_api.h"
#include "common_rtc.h"
#include "app_util.h"
#include "nrf_drv_common.h"
#include "lp_ticker_api.h"
#include "mbed_critical.h"
#include "nrfx_glue.h"
#if defined(NRF52_PAN_20)
/* Macro for testing if the SoftDevice is active, regardless of whether the
@ -186,7 +184,7 @@ void common_rtc_free()
{
nrf_rtc_task_trigger(COMMON_RTC_INSTANCE, NRF_RTC_TASK_STOP);
nrf_rtc_int_disable(COMMON_RTC_INSTANCE, LP_TICKER_INT_MASK);
NVIC_DisableIRQ(nrf_drv_get_IRQn(COMMON_RTC_INSTANCE));
NVIC_DisableIRQ(nrfx_get_irq_number(COMMON_RTC_INSTANCE));
m_common_rtc_enabled = false;
}

View File

@ -45,7 +45,6 @@
#include "nrf_atfifo.h"
#include "app_util_platform.h"
#include "pinmap_ex.h"
#include "nrfx_glue.h"
#include "nrfx_gpiote.h"
#include "nrfx_ppi.h"
#include "PeripheralPins.h"

View File

@ -43,7 +43,6 @@
#include "app_util_platform.h"
#include "nrfx_common.h"
#include "mbed_critical.h"
#include "nrfx_glue.h"
bool us_ticker_initialized = false;

View File

@ -146,10 +146,8 @@ typedef enum
#endif // __CORTEX_M == 0x04
#if defined ( __CC_ARM )
#define PACKED(TYPE) __packed TYPE
#define PACKED_STRUCT PACKED(struct)
#elif defined ( __GNUC__ )
#define PACKED __attribute__((packed))
#define PACKED_STRUCT struct PACKED
#elif defined (__ICCARM__)
#define PACKED_STRUCT __packed struct

View File

@ -1,297 +0,0 @@
/**
* Copyright (c) 2016 - 2018, 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_CLOCK_H__
#define NRF_DRV_CLOCK_H__
#include <nrfx_clock.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup nrf_drv_clock Clock driver - legacy layer
* @{
* @ingroup nrf_clock
*
* @brief Layer providing compatibility with the former API.
*/
/**
* @brief Clock events.
*/
typedef enum
{
NRF_DRV_CLOCK_EVT_HFCLK_STARTED, ///< HFCLK has been started.
NRF_DRV_CLOCK_EVT_LFCLK_STARTED, ///< LFCLK has been started.
NRF_DRV_CLOCK_EVT_CAL_DONE, ///< Calibration is done.
NRF_DRV_CLOCK_EVT_CAL_ABORTED, ///< Calibration has been aborted.
} nrf_drv_clock_evt_type_t;
/**
* @brief Clock event handler.
*
* @param[in] event Event.
*/
typedef void (*nrf_drv_clock_event_handler_t)(nrf_drv_clock_evt_type_t event);
// Forward declaration of the nrf_drv_clock_handler_item_t type.
typedef struct nrf_drv_clock_handler_item_s nrf_drv_clock_handler_item_t;
struct nrf_drv_clock_handler_item_s
{
nrf_drv_clock_handler_item_t * p_next; ///< A pointer to the next handler that should be called when the clock is started.
nrf_drv_clock_event_handler_t event_handler; ///< Function to be called when the clock is started.
};
/**
* @brief Function for checking if driver is already initialized
*
* @retval true Driver is initialized
* @retval false Driver is uninitialized
*/
bool nrf_drv_clock_init_check(void);
/**
* @brief Function for initializing the nrf_drv_clock module.
*
* After initialization, the module is in power off state (clocks are not requested).
*
* @retval NRF_SUCCESS If the procedure was successful.
* @retval NRF_ERROR_MODULE_ALREADY_INITIALIZED If the driver was already initialized.
*/
ret_code_t nrf_drv_clock_init(void);
/**
* @brief Function for uninitializing the clock module.
*
*/
void nrf_drv_clock_uninit(void);
/**
* @brief Function for requesting the LFCLK.
*
* The low-frequency clock can be requested by different modules
* or contexts. The driver ensures that the clock will be started only when it is requested
* the first time. If the clock is not ready but it was already started, the handler item that is
* provided as an input parameter is added to the list of handlers that will be notified
* when the clock is started. If the clock is already enabled, user callback is called from the
* current context.
*
* The first request will start the selected LFCLK source. If an event handler is
* provided, it will be called once the LFCLK is started. If the LFCLK was already started at this
* time, the event handler will be called from the context of this function. Additionally,
* the @ref nrf_drv_clock_lfclk_is_running function can be polled to check if the clock has started.
*
* @note When a SoftDevice is enabled, the LFCLK is always running and the driver cannot control it.
*
* @note The handler item provided by the user cannot be an automatic variable.
*
* @param[in] p_handler_item A pointer to the event handler structure.
*/
void nrf_drv_clock_lfclk_request(nrf_drv_clock_handler_item_t * p_handler_item);
/**
* @brief Function for releasing the LFCLK.
*
* If there are no more requests, the LFCLK source will be stopped.
*
* @note When a SoftDevice is enabled, the LFCLK is always running.
*/
void nrf_drv_clock_lfclk_release(void);
/**
* @brief Function for checking the LFCLK state.
*
* @retval true If the LFCLK is running.
* @retval false If the LFCLK is not running.
*/
bool nrf_drv_clock_lfclk_is_running(void);
/**
* @brief Function for requesting the high-accuracy source HFCLK.
*
* The high-accuracy source
* can be requested by different modules or contexts. The driver ensures that the high-accuracy
* clock will be started only when it is requested the first time. If the clock is not ready
* but it was already started, the handler item that is provided as an input parameter is added
* to the list of handlers that will be notified when the clock is started.
*
* If an event handler is provided, it will be called once the clock is started. If the clock was already
* started at this time, the event handler will be called from the context of this function. Additionally,
* the @ref nrf_drv_clock_hfclk_is_running function can be polled to check if the clock has started.
*
* @note If a SoftDevice is running, the clock is managed by the SoftDevice and all requests are handled by
* the SoftDevice. This function cannot be called from all interrupt priority levels in that case.
* @note The handler item provided by the user cannot be an automatic variable.
*
* @param[in] p_handler_item A pointer to the event handler structure.
*/
void nrf_drv_clock_hfclk_request(nrf_drv_clock_handler_item_t * p_handler_item);
/**
* @brief Function for releasing the high-accuracy source HFCLK.
*
* If there are no more requests, the high-accuracy source will be released.
*/
void nrf_drv_clock_hfclk_release(void);
/**
* @brief Function for checking the HFCLK state.
*
* @retval true If the HFCLK is running (for \nRFXX XTAL source).
* @retval false If the HFCLK is not running.
*/
bool nrf_drv_clock_hfclk_is_running(void);
/**
* @brief Function for starting a single calibration process.
*
* This function can also delay the start of calibration by a user-specified value. The delay will use
* a low-power timer that is part of the CLOCK module. @ref nrf_drv_clock_is_calibrating can be called to
* check if calibration is still in progress. If a handler is provided, the user can be notified when
* calibration is completed. The ext calibration can be started from the handler context.
*
* The calibration process consists of three phases:
* - Delay (optional)
* - Requesting the high-accuracy HFCLK
* - Hardware-supported calibration
*
* @param[in] delay Time after which the calibration will be started (in 0.25 s units).
* @param[in] handler NULL or user function to be called when calibration is completed or aborted.
*
* @retval NRF_SUCCESS If the procedure was successful.
* @retval NRF_ERROR_FORBIDDEN If a SoftDevice is present or the selected LFCLK source is not an RC oscillator.
* @retval NRF_ERROR_INVALID_STATE If the low-frequency clock is off.
* @retval NRF_ERROR_BUSY If calibration is in progress.
*/
ret_code_t nrf_drv_clock_calibration_start(uint8_t delay, nrf_drv_clock_event_handler_t handler);
/**
* @brief Function for aborting calibration.
*
* This function aborts on-going calibration. If calibration was started, it cannot be stopped. If a handler
* was provided by @ref nrf_drv_clock_calibration_start, this handler will be called once
* aborted calibration is completed. @ref nrf_drv_clock_is_calibrating can also be used to check
* if the system is calibrating.
*
* @retval NRF_SUCCESS If the procedure was successful.
* @retval NRF_ERROR_FORBIDDEN If a SoftDevice is present or the selected LFCLK source is not an RC oscillator.
*/
ret_code_t nrf_drv_clock_calibration_abort(void);
/**
* @brief Function for checking if calibration is in progress.
*
* This function indicates that the system is
* in calibration if it is in any of the calibration process phases (see @ref nrf_drv_clock_calibration_start).
*
* @param[out] p_is_calibrating True if calibration is in progress, false if not.
*
* @retval NRF_SUCCESS If the procedure was successful.
* @retval NRF_ERROR_FORBIDDEN If a SoftDevice is present or the selected LFCLK source is not an RC oscillator.
*/
ret_code_t nrf_drv_clock_is_calibrating(bool * p_is_calibrating);
/**@brief Function for returning a requested task address for the clock driver module.
*
* @param[in] task One of the peripheral tasks.
*
* @return Task address.
*/
__STATIC_INLINE uint32_t nrf_drv_clock_ppi_task_addr(nrf_clock_task_t task);
/**@brief Function for returning a requested event address for the clock driver module.
*
* @param[in] event One of the peripheral events.
*
* @return Event address.
*/
__STATIC_INLINE uint32_t nrf_drv_clock_ppi_event_addr(nrf_clock_event_t event);
#ifdef SOFTDEVICE_PRESENT
/**
* @brief Function called by the SoftDevice handler if an @ref NRF_SOC_EVTS event is received from the SoftDevice.
*
* @param[in] evt_id One of NRF_SOC_EVTS values.
*/
void nrf_drv_clock_on_soc_event(uint32_t evt_id);
/**
* @brief Function called by the SoftDevice handler when the SoftDevice has been enabled.
*
* This function is called just after the SoftDevice has been properly enabled.
* Its main purpose is to mark that LFCLK has been requested by SD.
*/
void nrf_drv_clock_on_sd_enable(void);
/**
* @brief Function called by the SoftDevice handler when the SoftDevice has been disabled.
*
* This function is called just after the SoftDevice has been properly disabled.
* It has two purposes:
* 1. Releases the LFCLK from the SD.
* 2. Reinitializes an interrupt after the SD releases POWER_CLOCK_IRQ.
*/
void nrf_drv_clock_on_sd_disable(void);
#endif
/**
*@}
**/
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
__STATIC_INLINE uint32_t nrf_drv_clock_ppi_task_addr(nrf_clock_task_t task)
{
return nrf_clock_task_address_get(task);
}
__STATIC_INLINE uint32_t nrf_drv_clock_ppi_event_addr(nrf_clock_event_t event)
{
return nrf_clock_event_address_get(event);
}
#endif //SUPPRESS_INLINE_IMPLEMENTATION
#ifdef __cplusplus
}
#endif
#endif // NRF_DRV_CLOCK_H__

View File

@ -1,63 +0,0 @@
/**
* Copyright (c) 2015 - 2018, 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_COMMON_H__
#define NRF_DRV_COMMON_H__
#include <nrfx.h>
#ifdef __cplusplus
extern "C" {
#endif
#define INTERRUPT_PRIORITY_VALIDATION(pri) STATIC_ASSERT(INTERRUPT_PRIORITY_IS_VALID((pri)))
#define INTERRUPT_PRIORITY_ASSERT(pri) ASSERT(INTERRUPT_PRIORITY_IS_VALID((pri)))
#define nrf_drv_irq_handler_t nrfx_irq_handler_t
#define nrf_drv_bitpos_to_event nrfx_bitpos_to_event
#define nrf_drv_event_to_bitpos nrfx_event_to_bitpos
#define nrf_drv_get_IRQn nrfx_get_irq_number
#define nrf_drv_is_in_RAM nrfx_is_in_ram
#ifdef __cplusplus
}
#endif
#endif // NRF_DRV_COMMON_H__

View File

@ -1,139 +0,0 @@
/**
* Copyright (c) 2015 - 2018, 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_GPIOTE_H__
#define NRF_DRV_GPIOTE_H__
#include <nrfx_gpiote.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup nrf_drv_gpiote GPIOTE driver - legacy layer
* @{
* @ingroup nrf_gpiote
* @brief Layer providing compatibility with the former API.
*/
/** @brief Type definition for forwarding the new implementation. */
typedef nrfx_gpiote_in_config_t nrf_drv_gpiote_in_config_t;
/** @brief Type definition for forwarding the new implementation. */
typedef nrfx_gpiote_pin_t nrf_drv_gpiote_pin_t;
/** @brief Type definition for forwarding the new implementation. */
typedef nrfx_gpiote_out_config_t nrf_drv_gpiote_out_config_t;
/** @brief Type definition for forwarding the new implementation. */
typedef nrfx_gpiote_evt_handler_t nrf_drv_gpiote_evt_handler_t;
/** @brief Macro for forwarding the new implementation. */
#define GPIOTE_CONFIG_IN_SENSE_LOTOHI NRFX_GPIOTE_CONFIG_IN_SENSE_LOTOHI
/** @brief Macro for forwarding the new implementation. */
#define GPIOTE_CONFIG_IN_SENSE_HITOLO NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO
/** @brief Macro for forwarding the new implementation. */
#define GPIOTE_CONFIG_IN_SENSE_TOGGLE NRFX_GPIOTE_CONFIG_IN_SENSE_TOGGLE
/** @brief Macro for forwarding the new implementation. */
#define GPIOTE_RAW_CONFIG_IN_SENSE_LOTOHI NRFX_GPIOTE_RAW_CONFIG_IN_SENSE_LOTOHI
/** @brief Macro for forwarding the new implementation. */
#define GPIOTE_RAW_CONFIG_IN_SENSE_HITOLO NRFX_GPIOTE_RAW_CONFIG_IN_SENSE_HITOLO
/** @brief Macro for forwarding the new implementation. */
#define GPIOTE_RAW_CONFIG_IN_SENSE_TOGGLE NRFX_GPIOTE_RAW_CONFIG_IN_SENSE_TOGGLE
/** @brief Macro for forwarding the new implementation. */
#define GPIOTE_CONFIG_OUT_SIMPLE NRFX_GPIOTE_CONFIG_OUT_SIMPLE
/** @brief Macro for forwarding the new implementation. */
#define GPIOTE_CONFIG_OUT_TASK_LOW NRFX_GPIOTE_CONFIG_OUT_TASK_LOW
/** @brief Macro for forwarding the new implementation. */
#define GPIOTE_CONFIG_OUT_TASK_HIGH NRFX_GPIOTE_CONFIG_OUT_TASK_HIGH
/** @brief Macro for forwarding the new implementation. */
#define GPIOTE_CONFIG_OUT_TASK_TOGGLE NRFX_GPIOTE_CONFIG_OUT_TASK_TOGGLE
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_init nrfx_gpiote_init
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_is_init nrfx_gpiote_is_init
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_uninit nrfx_gpiote_uninit
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_out_init nrfx_gpiote_out_init
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_out_uninit nrfx_gpiote_out_uninit
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_out_set nrfx_gpiote_out_set
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_out_clear nrfx_gpiote_out_clear
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_out_toggle nrfx_gpiote_out_toggle
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_out_task_enable nrfx_gpiote_out_task_enable
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_out_task_disable nrfx_gpiote_out_task_disable
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_out_task_addr_get nrfx_gpiote_out_task_addr_get
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_in_init nrfx_gpiote_in_init
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_in_uninit nrfx_gpiote_in_uninit
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_in_event_enable nrfx_gpiote_in_event_enable
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_in_event_disable nrfx_gpiote_in_event_disable
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_in_is_set nrfx_gpiote_in_is_set
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_in_event_addr_get nrfx_gpiote_in_event_addr_get
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_set_task_addr_get nrfx_gpiote_set_task_addr_get
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_clr_task_addr_get nrfx_gpiote_clr_task_addr_get
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_out_task_force nrfx_gpiote_out_task_force
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_out_task_trigger nrfx_gpiote_out_task_trigger
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_set_task_trigger nrfx_gpiote_set_task_trigger
/** @brief Macro for forwarding the new implementation. */
#define nrf_drv_gpiote_clr_task_trigger nrfx_gpiote_clr_task_trigger
/** @} */
#ifdef __cplusplus
}
#endif
#endif //NRF_DRV_GPIOTE_H__

View File

@ -1,644 +0,0 @@
/**
* Copyright (c) 2015 - 2018, 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_SPI_H__
#define NRF_DRV_SPI_H__
#include <nrfx.h>
// Needed for Mbed
#ifdef SPI0_ENABLED
#define SPI0_INCR SPI0_ENABLED
#else
#define SPI0_INCR 0
#endif
#ifdef SPI1_ENABLED
#define SPI1_INCR SPI1_ENABLED
#else
#define SPI1_INCR 0
#endif
#ifdef SPI2_ENABLED
#define SPI2_INCR SPI2_ENABLED
#else
#define SPI2_INCR 0
#endif
#ifdef SPI3_ENABLED
#define SPI3_INCR SPI3_ENABLED
#else
#define SPI3_INCR 0
#endif
#define ENABLED_SPI_COUNT (SPI0_INCR + SPI1_INCR + SPI2_INCR + SPI3_INCR)
#ifdef SPIM_PRESENT
#include <nrfx_spim.h>
#else
// Compilers (at least the smart ones) will remove the SPIM related code
// (blocks starting with "if (NRF_DRV_SPI_USE_SPIM)") when it is not used,
// but to perform the compilation they need the following definitions.
#define nrfx_spim_init(...) 0
#define nrfx_spim_uninit(...)
#define nrfx_spim_start_task_get(...) 0
#define nrfx_spim_end_event_get(...) 0
#define nrfx_spim_abort(...)
#endif
#ifdef SPI_PRESENT
#include <nrfx_spi.h>
#else
// Compilers (at least the smart ones) will remove the SPI related code
// (blocks starting with "if (NRF_DRV_SPI_USE_SPI)") when it is not used,
// but to perform the compilation they need the following definitions.
#define nrfx_spi_init(...) 0
#define nrfx_spi_uninit(...)
#define nrfx_spi_start_task_get(...) 0
#define nrfx_spi_end_event_get(...) 0
#define nrfx_spi_abort(...)
// This part is for old modules that use directly SPI HAL definitions
// (to make them compilable for chips that have only SPIM).
#define NRF_SPI_FREQ_125K NRF_SPIM_FREQ_125K
#define NRF_SPI_FREQ_250K NRF_SPIM_FREQ_250K
#define NRF_SPI_FREQ_500K NRF_SPIM_FREQ_500K
#define NRF_SPI_FREQ_1M NRF_SPIM_FREQ_1M
#define NRF_SPI_FREQ_2M NRF_SPIM_FREQ_2M
#define NRF_SPI_FREQ_4M NRF_SPIM_FREQ_4M
#define NRF_SPI_FREQ_8M NRF_SPIM_FREQ_8M
#define NRF_SPI_MODE_0 NRF_SPIM_MODE_0
#define NRF_SPI_MODE_1 NRF_SPIM_MODE_1
#define NRF_SPI_MODE_2 NRF_SPIM_MODE_2
#define NRF_SPI_MODE_3 NRF_SPIM_MODE_3
#define NRF_SPI_BIT_ORDER_MSB_FIRST NRF_SPIM_BIT_ORDER_MSB_FIRST
#define NRF_SPI_BIT_ORDER_LSB_FIRST NRF_SPIM_BIT_ORDER_LSB_FIRST
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup nrf_drv_spi SPI master driver
* @{
* @ingroup nrf_spi
* @brief Layer providing compatibility with the former API.
*/
/**
* @brief SPI master driver instance data structure.
*/
typedef struct
{
uint8_t inst_idx;
union
{
#ifdef SPIM_PRESENT
nrfx_spim_t spim;
#endif
#ifdef SPI_PRESENT
nrfx_spi_t spi;
#endif
} u;
bool use_easy_dma;
} nrf_drv_spi_t;
/**
* @brief Macro for creating an SPI master driver instance.
*/
#define NRF_DRV_SPI_INSTANCE(id) NRF_DRV_SPI_INSTANCE_(id)
#define NRF_DRV_SPI_INSTANCE_(id) NRF_DRV_SPI_INSTANCE_ ## id
#if NRFX_CHECK(NRFX_SPIM0_ENABLED)
#define NRF_DRV_SPI_INSTANCE_0 \
{ 0, { .spim = NRFX_SPIM_INSTANCE(0) }, true }
#elif NRFX_CHECK(NRFX_SPI0_ENABLED)
#define NRF_DRV_SPI_INSTANCE_0 \
{ 0, { .spi = NRFX_SPI_INSTANCE(0) }, false }
#endif
#if NRFX_CHECK(NRFX_SPIM1_ENABLED)
#define NRF_DRV_SPI_INSTANCE_1 \
{ 1, { .spim = NRFX_SPIM_INSTANCE(1) }, true }
#elif NRFX_CHECK(NRFX_SPI1_ENABLED)
#define NRF_DRV_SPI_INSTANCE_1 \
{ 1, { .spi = NRFX_SPI_INSTANCE(1) }, false }
#endif
#if NRFX_CHECK(NRFX_SPIM2_ENABLED)
#define NRF_DRV_SPI_INSTANCE_2 \
{ 2, { .spim = NRFX_SPIM_INSTANCE(2) }, true }
#elif NRFX_CHECK(NRFX_SPI2_ENABLED)
#define NRF_DRV_SPI_INSTANCE_2 \
{ 2, { .spi = NRFX_SPI_INSTANCE(2) }, false }
#endif
/**
* @brief This value can be provided instead of a pin number for signals MOSI,
* MISO, and Slave Select to specify that the given signal is not used and
* therefore does not need to be connected to a pin.
*/
#define NRF_DRV_SPI_PIN_NOT_USED 0xFF
/**
* @brief SPI data rates.
*/
typedef enum
{
NRF_DRV_SPI_FREQ_125K = NRF_SPI_FREQ_125K, ///< 125 kbps.
NRF_DRV_SPI_FREQ_250K = NRF_SPI_FREQ_250K, ///< 250 kbps.
NRF_DRV_SPI_FREQ_500K = NRF_SPI_FREQ_500K, ///< 500 kbps.
NRF_DRV_SPI_FREQ_1M = NRF_SPI_FREQ_1M, ///< 1 Mbps.
NRF_DRV_SPI_FREQ_2M = NRF_SPI_FREQ_2M, ///< 2 Mbps.
NRF_DRV_SPI_FREQ_4M = NRF_SPI_FREQ_4M, ///< 4 Mbps.
NRF_DRV_SPI_FREQ_8M = NRF_SPI_FREQ_8M ///< 8 Mbps.
} nrf_drv_spi_frequency_t;
/**
* @brief SPI modes.
*/
typedef enum
{
NRF_DRV_SPI_MODE_0 = NRF_SPI_MODE_0, ///< SCK active high, sample on leading edge of clock.
NRF_DRV_SPI_MODE_1 = NRF_SPI_MODE_1, ///< SCK active high, sample on trailing edge of clock.
NRF_DRV_SPI_MODE_2 = NRF_SPI_MODE_2, ///< SCK active low, sample on leading edge of clock.
NRF_DRV_SPI_MODE_3 = NRF_SPI_MODE_3 ///< SCK active low, sample on trailing edge of clock.
} nrf_drv_spi_mode_t;
/**
* @brief SPI bit orders.
*/
typedef enum
{
NRF_DRV_SPI_BIT_ORDER_MSB_FIRST = NRF_SPI_BIT_ORDER_MSB_FIRST, ///< Most significant bit shifted out first.
NRF_DRV_SPI_BIT_ORDER_LSB_FIRST = NRF_SPI_BIT_ORDER_LSB_FIRST ///< Least significant bit shifted out first.
} nrf_drv_spi_bit_order_t;
/**
* @brief SPI master driver instance configuration structure.
*/
typedef struct
{
uint8_t sck_pin; ///< SCK pin number.
uint8_t mosi_pin; ///< MOSI pin number (optional).
/**< Set to @ref NRF_DRV_SPI_PIN_NOT_USED
* if this signal is not needed. */
uint8_t miso_pin; ///< MISO pin number (optional).
/**< Set to @ref NRF_DRV_SPI_PIN_NOT_USED
* if this signal is not needed. */
uint8_t ss_pin; ///< Slave Select pin number (optional).
/**< Set to @ref NRF_DRV_SPI_PIN_NOT_USED
* if this signal is not needed. The driver
* supports only active low for this signal.
* If the signal should be active high,
* it must be controlled externally. */
uint8_t irq_priority; ///< Interrupt priority.
uint8_t orc; ///< Over-run character.
/**< This character is used when all bytes from the TX buffer are sent,
but the transfer continues due to RX. */
nrf_drv_spi_frequency_t frequency; ///< SPI frequency.
nrf_drv_spi_mode_t mode; ///< SPI mode.
nrf_drv_spi_bit_order_t bit_order; ///< SPI bit order.
} nrf_drv_spi_config_t;
/**
* @brief SPI master instance default configuration.
*/
#define NRF_DRV_SPI_DEFAULT_CONFIG \
{ \
.sck_pin = NRF_DRV_SPI_PIN_NOT_USED, \
.mosi_pin = NRF_DRV_SPI_PIN_NOT_USED, \
.miso_pin = NRF_DRV_SPI_PIN_NOT_USED, \
.ss_pin = NRF_DRV_SPI_PIN_NOT_USED, \
.irq_priority = SPI_DEFAULT_CONFIG_IRQ_PRIORITY, \
.orc = 0xFF, \
.frequency = NRF_DRV_SPI_FREQ_4M, \
.mode = NRF_DRV_SPI_MODE_0, \
.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST, \
}
#define NRF_DRV_SPI_FLAG_TX_POSTINC (1UL << 0) /**< TX buffer address incremented after transfer. */
#define NRF_DRV_SPI_FLAG_RX_POSTINC (1UL << 1) /**< RX buffer address incremented after transfer. */
#define NRF_DRV_SPI_FLAG_NO_XFER_EVT_HANDLER (1UL << 2) /**< Interrupt after each transfer is suppressed, and the event handler is not called. */
#define NRF_DRV_SPI_FLAG_HOLD_XFER (1UL << 3) /**< Set up the transfer but do not start it. */
#define NRF_DRV_SPI_FLAG_REPEATED_XFER (1UL << 4) /**< Flag indicating that the transfer will be executed multiple times. */
/**
* @brief Single transfer descriptor structure.
*/
typedef struct
{
uint8_t const * p_tx_buffer; ///< Pointer to TX buffer.
uint8_t tx_length; ///< TX buffer length.
uint8_t * p_rx_buffer; ///< Pointer to RX buffer.
uint8_t rx_length; ///< RX buffer length.
}nrf_drv_spi_xfer_desc_t;
/**
* @brief Macro for setting up single transfer descriptor.
*
* This macro is for internal use only.
*/
#define NRF_DRV_SPI_SINGLE_XFER(p_tx, tx_len, p_rx, rx_len) \
{ \
.p_tx_buffer = (uint8_t const *)(p_tx), \
.tx_length = (tx_len), \
.p_rx_buffer = (p_rx), \
.rx_length = (rx_len), \
}
/**
* @brief Macro for setting duplex TX RX transfer.
*/
#define NRF_DRV_SPI_XFER_TRX(p_tx_buf, tx_length, p_rx_buf, rx_length) \
NRF_DRV_SPI_SINGLE_XFER(p_tx_buf, tx_length, p_rx_buf, rx_length)
/**
* @brief Macro for setting TX transfer.
*/
#define NRF_DRV_SPI_XFER_TX(p_buf, length) \
NRF_DRV_SPI_SINGLE_XFER(p_buf, length, NULL, 0)
/**
* @brief Macro for setting RX transfer.
*/
#define NRF_DRV_SPI_XFER_RX(p_buf, length) \
NRF_DRV_SPI_SINGLE_XFER(NULL, 0, p_buf, length)
/**
* @brief SPI master driver event types, passed to the handler routine provided
* during initialization.
*/
typedef enum
{
NRF_DRV_SPI_EVENT_DONE, ///< Transfer done.
} nrf_drv_spi_evt_type_t;
typedef struct
{
nrf_drv_spi_evt_type_t type; ///< Event type.
union
{
nrf_drv_spi_xfer_desc_t done; ///< Event data for DONE event.
} data;
} nrf_drv_spi_evt_t;
/**
* @brief SPI master driver event handler type.
*/
typedef void (* nrf_drv_spi_evt_handler_t)(nrf_drv_spi_evt_t const * p_event,
void * p_context);
/**
* @brief Function for initializing the SPI master driver instance.
*
* This function configures and enables the specified peripheral.
*
* @note MISO pin has pull down enabled.
*
* @param[in] p_instance Pointer to the driver instance structure.
* @param[in] p_config Pointer to the structure with the initial configuration.
*
* @param handler Event handler provided by the user. If NULL, transfers
* will be performed in blocking mode.
* @param p_context Context passed to event handler.
*
* @retval NRF_SUCCESS If initialization was successful.
* @retval NRF_ERROR_INVALID_STATE If the driver was 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.
*/
ret_code_t nrf_drv_spi_init(nrf_drv_spi_t const * const p_instance,
nrf_drv_spi_config_t const * p_config,
nrf_drv_spi_evt_handler_t handler,
void * p_context);
/**
* @brief Function for uninitializing the SPI master driver instance.
*
* @note Configuration of pins is kept.
*
* @param[in] p_instance Pointer to the driver instance structure.
*/
__STATIC_INLINE
void nrf_drv_spi_uninit(nrf_drv_spi_t const * const p_instance);
/**
* @brief Function for starting the SPI data transfer.
*
* If an event handler was provided in the @ref nrf_drv_spi_init call, this function
* returns immediately and the handler is called when the transfer is done.
* Otherwise, the transfer is performed in blocking mode, which means that this function
* returns when the transfer is finished.
*
* @note Peripherals using EasyDMA (for example, SPIM) require the transfer buffers
* to be placed in the Data RAM region. If they are not and an SPIM instance is
* used, this function will fail with the error code NRF_ERROR_INVALID_ADDR.
*
* @param[in] p_instance Pointer to the driver instance structure.
* @param[in] p_tx_buffer Pointer to the transmit buffer. Can be NULL
* if there is nothing to send.
* @param tx_buffer_length Length of the transmit buffer.
* @param[in] p_rx_buffer Pointer to the receive buffer. Can be NULL
* if there is nothing to receive.
* @param rx_buffer_length Length of the receive buffer.
*
* @retval NRF_SUCCESS If the operation was successful.
* @retval NRF_ERROR_BUSY If a previously started transfer has not finished
* yet.
* @retval NRF_ERROR_INVALID_ADDR If the provided buffers are not placed in the Data
* RAM region.
*/
__STATIC_INLINE
ret_code_t nrf_drv_spi_transfer(nrf_drv_spi_t const * const p_instance,
uint8_t const * p_tx_buffer,
uint8_t tx_buffer_length,
uint8_t * p_rx_buffer,
uint8_t rx_buffer_length);
/**
* @brief Function for starting the SPI data transfer with additional option flags.
*
* Function enables customizing the transfer by using option flags.
*
* Additional options are provided using the flags parameter:
*
* - @ref NRF_DRV_SPI_FLAG_TX_POSTINC and @ref NRF_DRV_SPI_FLAG_RX_POSTINC<span></span>:
* Post-incrementation of buffer addresses. Supported only by SPIM.
* - @ref NRF_DRV_SPI_FLAG_HOLD_XFER<span></span>: Driver is not starting the transfer. Use this
* flag if the transfer is triggered externally by PPI. Supported only by SPIM. Use
* @ref nrf_drv_spi_start_task_get to get the address of the start task.
* - @ref NRF_DRV_SPI_FLAG_NO_XFER_EVT_HANDLER<span></span>: No user event handler after transfer
* completion. This also means no interrupt at the end of the transfer. Supported only by SPIM.
* If @ref NRF_DRV_SPI_FLAG_NO_XFER_EVT_HANDLER is used, the driver does not set the instance into
* busy state, so you must ensure that the next transfers are set up when SPIM is not active.
* @ref nrf_drv_spi_end_event_get function can be used to detect end of transfer. Option can be used
* together with @ref NRF_DRV_SPI_FLAG_REPEATED_XFER to prepare a sequence of SPI transfers
* without interruptions.
* - @ref NRF_DRV_SPI_FLAG_REPEATED_XFER<span></span>: Prepare for repeated transfers. You can set
* up a number of transfers that will be triggered externally (for example by PPI). An example is
* a TXRX transfer with the options @ref NRF_DRV_SPI_FLAG_RX_POSTINC,
* @ref NRF_DRV_SPI_FLAG_NO_XFER_EVT_HANDLER, and @ref NRF_DRV_SPI_FLAG_REPEATED_XFER. After the
* transfer is set up, a set of transfers can be triggered by PPI that will read, for example,
* the same register of an external component and put it into a RAM buffer without any interrupts.
* @ref nrf_drv_spi_end_event_get can be used to get the address of the END event, which can be
* used to count the number of transfers. If @ref NRF_DRV_SPI_FLAG_REPEATED_XFER is used,
* the driver does not set the instance into busy state, so you must ensure that the next
* transfers are set up when SPIM is not active. Supported only by SPIM.
* @note Function is intended to be used only in non-blocking mode.
*
* @param p_instance Pointer to the driver instance structure.
* @param p_xfer_desc Pointer to the transfer descriptor.
* @param flags Transfer options (0 for default settings).
*
* @retval NRF_SUCCESS If the procedure was successful.
* @retval NRF_ERROR_BUSY If the driver is not ready for a new transfer.
* @retval NRF_ERROR_NOT_SUPPORTED If the provided parameters are not supported.
* @retval NRF_ERROR_INVALID_ADDR If the provided buffers are not placed in the Data
* RAM region.
*/
__STATIC_INLINE
ret_code_t nrf_drv_spi_xfer(nrf_drv_spi_t const * const p_instance,
nrf_drv_spi_xfer_desc_t const * p_xfer_desc,
uint32_t flags);
/**
* @brief Function for returning the address of a SPIM start task.
*
* This function should be used if @ref nrf_drv_spi_xfer was called with the flag @ref NRF_DRV_SPI_FLAG_HOLD_XFER.
* In that case, the transfer is not started by the driver, but it must be started externally by PPI.
*
* @param[in] p_instance Pointer to the driver instance structure.
*
* @return Start task address.
*/
__STATIC_INLINE
uint32_t nrf_drv_spi_start_task_get(nrf_drv_spi_t const * p_instance);
/**
* @brief Function for returning the address of a END SPIM event.
*
* A END event can be used to detect the end of a transfer if the @ref NRF_DRV_SPI_FLAG_NO_XFER_EVT_HANDLER
* option is used.
*
* @param[in] p_instance Pointer to the driver instance structure.
*
* @return END event address.
*/
__STATIC_INLINE
uint32_t nrf_drv_spi_end_event_get(nrf_drv_spi_t const * p_instance);
/**
* @brief Function for aborting ongoing transfer.
*
* @param[in] p_instance Pointer to the driver instance structure.
*/
__STATIC_INLINE
void nrf_drv_spi_abort(nrf_drv_spi_t const * p_instance);
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
#if defined(SPI_PRESENT) && !defined(SPIM_PRESENT)
#define NRF_DRV_SPI_WITH_SPI
#elif !defined(SPI_PRESENT) && defined(SPIM_PRESENT)
#define NRF_DRV_SPI_WITH_SPIM
#else
#if (NRFX_CHECK(SPI0_ENABLED) && NRFX_CHECK(SPI0_USE_EASY_DMA)) || \
(NRFX_CHECK(SPI1_ENABLED) && NRFX_CHECK(SPI1_USE_EASY_DMA)) || \
(NRFX_CHECK(SPI2_ENABLED) && NRFX_CHECK(SPI2_USE_EASY_DMA))
#define NRF_DRV_SPI_WITH_SPIM
#endif
#if (NRFX_CHECK(SPI0_ENABLED) && !NRFX_CHECK(SPI0_USE_EASY_DMA)) || \
(NRFX_CHECK(SPI1_ENABLED) && !NRFX_CHECK(SPI1_USE_EASY_DMA)) || \
(NRFX_CHECK(SPI2_ENABLED) && !NRFX_CHECK(SPI2_USE_EASY_DMA))
#define NRF_DRV_SPI_WITH_SPI
#endif
#endif
#if defined(NRF_DRV_SPI_WITH_SPIM) && defined(NRF_DRV_SPI_WITH_SPI)
#define NRF_DRV_SPI_USE_SPIM (p_instance->use_easy_dma)
#elif defined(NRF_DRV_SPI_WITH_SPIM)
#define NRF_DRV_SPI_USE_SPIM true
#else
#define NRF_DRV_SPI_USE_SPIM false
#endif
#define NRF_DRV_SPI_USE_SPI (!NRF_DRV_SPI_USE_SPIM)
__STATIC_INLINE
void nrf_drv_spi_uninit(nrf_drv_spi_t const * p_instance)
{
if (NRF_DRV_SPI_USE_SPIM)
{
nrfx_spim_uninit(&p_instance->u.spim);
}
else if (NRF_DRV_SPI_USE_SPI)
{
nrfx_spi_uninit(&p_instance->u.spi);
}
}
__STATIC_INLINE
ret_code_t nrf_drv_spi_transfer(nrf_drv_spi_t const * const p_instance,
uint8_t const * p_tx_buffer,
uint8_t tx_buffer_length,
uint8_t * p_rx_buffer,
uint8_t rx_buffer_length)
{
ret_code_t result = 0;
if (NRF_DRV_SPI_USE_SPIM)
{
#ifdef SPIM_PRESENT
nrfx_spim_xfer_desc_t const spim_xfer_desc =
{
.p_tx_buffer = p_tx_buffer,
.tx_length = tx_buffer_length,
.p_rx_buffer = p_rx_buffer,
.rx_length = rx_buffer_length,
};
result = nrfx_spim_xfer(&p_instance->u.spim, &spim_xfer_desc, 0);
#endif
}
else if (NRF_DRV_SPI_USE_SPI)
{
#ifdef SPI_PRESENT
nrfx_spi_xfer_desc_t const spi_xfer_desc =
{
.p_tx_buffer = p_tx_buffer,
.tx_length = tx_buffer_length,
.p_rx_buffer = p_rx_buffer,
.rx_length = rx_buffer_length,
};
result = nrfx_spi_xfer(&p_instance->u.spi, &spi_xfer_desc, 0);
#endif
}
return result;
}
__STATIC_INLINE
ret_code_t nrf_drv_spi_xfer(nrf_drv_spi_t const * const p_instance,
nrf_drv_spi_xfer_desc_t const * p_xfer_desc,
uint32_t flags)
{
ret_code_t result = 0;
if (NRF_DRV_SPI_USE_SPIM)
{
#ifdef SPIM_PRESENT
nrfx_spim_xfer_desc_t const spim_xfer_desc =
{
.p_tx_buffer = p_xfer_desc->p_tx_buffer,
.tx_length = p_xfer_desc->tx_length,
.p_rx_buffer = p_xfer_desc->p_rx_buffer,
.rx_length = p_xfer_desc->rx_length,
};
result = nrfx_spim_xfer(&p_instance->u.spim, &spim_xfer_desc, flags);
#endif
}
else if (NRF_DRV_SPI_USE_SPI)
{
#ifdef SPI_PRESENT
nrfx_spi_xfer_desc_t const spi_xfer_desc =
{
.p_tx_buffer = p_xfer_desc->p_tx_buffer,
.tx_length = p_xfer_desc->tx_length,
.p_rx_buffer = p_xfer_desc->p_rx_buffer,
.rx_length = p_xfer_desc->rx_length,
};
result = nrfx_spi_xfer(&p_instance->u.spi, &spi_xfer_desc, flags);
#endif
}
return result;
}
__STATIC_INLINE
uint32_t nrf_drv_spi_start_task_get(nrf_drv_spi_t const * p_instance)
{
uint32_t result = 0;
if (NRF_DRV_SPI_USE_SPIM)
{
result = nrfx_spim_start_task_get(&p_instance->u.spim);
}
else if (NRF_DRV_SPI_USE_SPI)
{
NRFX_ASSERT(false); // not supported
result = 0;
}
return result;
}
__STATIC_INLINE
uint32_t nrf_drv_spi_end_event_get(nrf_drv_spi_t const * p_instance)
{
uint32_t result = 0;
if (NRF_DRV_SPI_USE_SPIM)
{
result = nrfx_spim_end_event_get(&p_instance->u.spim);
}
else if (NRF_DRV_SPI_USE_SPI)
{
NRFX_ASSERT(false); // not supported
result = 0;
}
return result;
}
__STATIC_INLINE
void nrf_drv_spi_abort(nrf_drv_spi_t const * p_instance)
{
if (NRF_DRV_SPI_USE_SPIM)
{
nrfx_spim_abort(&p_instance->u.spim);
}
else if (NRF_DRV_SPI_USE_SPI)
{
nrfx_spi_abort(&p_instance->u.spi);
}
}
#endif // SUPPRESS_INLINE_IMPLEMENTATION
/** @} */
#ifdef __cplusplus
}
#endif
#endif // NRF_DRV_SPI_H__

View File

@ -1,708 +0,0 @@
/**
* Copyright (c) 2015 - 2018, 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_TWI_H__
#define NRF_DRV_TWI_H__
#include <nrfx.h>
// needed for Mbed
#ifdef TWI0_ENABLED
#define TWI0_INCR TWI0_ENABLED
#else
#define TWI0_INCR 0
#endif
#ifdef TWI1_ENABLED
#define TWI1_INCR TWI1_ENABLED
#else
#define TWI1_INCR 0
#endif
#define ENABLED_TWI_COUNT (TWI0_INCR + TWI1_INCR)
// end needed for Mbed
#ifdef TWIM_PRESENT
#include <nrfx_twim.h>
#else
// Compilers (at least the smart ones) will remove the TWIM related code
// (blocks starting with "if (NRF_DRV_TWI_USE_TWIM)") when it is not used,
// but to perform the compilation they need the following definitions.
#define nrfx_twim_init(...) 0
#define nrfx_twim_uninit(...)
#define nrfx_twim_enable(...)
#define nrfx_twim_disable(...)
#define nrfx_twim_tx(...) 0
#define nrfx_twim_rx(...) 0
#define nrfx_twim_is_busy(...) 0
#define nrfx_twim_start_task_get(...) 0
#define nrfx_twim_stopped_event_get(...) 0
#endif
#ifdef TWI_PRESENT
#include <nrfx_twi.h>
#else
// Compilers (at least the smart ones) will remove the TWI related code
// (blocks starting with "if (NRF_DRV_TWI_USE_TWI)") when it is not used,
// but to perform the compilation they need the following definitions.
#define nrfx_twi_init(...) 0
#define nrfx_twi_uninit(...)
#define nrfx_twi_enable(...)
#define nrfx_twi_disable(...)
#define nrfx_twi_tx(...) 0
#define nrfx_twi_rx(...) 0
#define nrfx_twi_is_busy(...) 0
#define nrfx_twi_data_count_get(...) 0
#define nrfx_twi_stopped_event_get(...) 0
// This part is for old modules that use directly TWI HAL definitions
// (to make them compilable for chips that have only TWIM).
#define NRF_TWI_ERROR_ADDRESS_NACK NRF_TWIM_ERROR_ADDRESS_NACK
#define NRF_TWI_ERROR_DATA_NACK NRF_TWIM_ERROR_DATA_NACK
#define NRF_TWI_FREQ_100K NRF_TWIM_FREQ_100K
#define NRF_TWI_FREQ_250K NRF_TWIM_FREQ_250K
#define NRF_TWI_FREQ_400K NRF_TWIM_FREQ_400K
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup nrf_drv_twi TWI driver - legacy layer
* @{
* @ingroup nrf_twi
* @brief Layer providing compatibility with the former API.
*/
/**
* @brief Structure for the TWI master driver instance.
*/
typedef struct
{
uint8_t inst_idx;
union
{
#ifdef TWIM_PRESENT
nrfx_twim_t twim;
#endif
#ifdef TWI_PRESENT
nrfx_twi_t twi;
#endif
} u;
bool use_easy_dma;
} nrf_drv_twi_t;
/**
* @brief Macro for creating a TWI master driver instance.
*/
// Mbed - need these
//#define NRF_TWIM0_ENABLED 1
//#define NRF_TWIM1_ENABLED 1
#define NRF_DRV_TWI_INSTANCE(id) NRF_DRV_TWI_INSTANCE_(id)
#define NRF_DRV_TWI_INSTANCE_(id) NRF_DRV_TWI_INSTANCE_ ## id
#if NRFX_CHECK(NRFX_TWIM0_ENABLED)
#define NRF_DRV_TWI_INSTANCE_0 \
{ 0, { .twim = NRFX_TWIM_INSTANCE(0) }, true }
#elif NRFX_CHECK(NRFX_TWI0_ENABLED)
#define NRF_DRV_TWI_INSTANCE_0 \
{ 0, { .twi = NRFX_TWI_INSTANCE(0) }, false }
#endif
#if NRFX_CHECK(NRFX_TWIM1_ENABLED)
#define NRF_DRV_TWI_INSTANCE_1 \
{ 1, { .twim = NRFX_TWIM_INSTANCE(1) }, true }
#elif NRFX_CHECK(NRFX_TWI1_ENABLED)
#define NRF_DRV_TWI_INSTANCE_1 \
{ 1, { .twi = NRFX_TWI_INSTANCE(1) }, false }
#endif
/**
* @brief TWI master clock frequency.
*/
typedef enum
{
NRF_DRV_TWI_FREQ_100K = NRF_TWI_FREQ_100K , ///< 100 kbps.
NRF_DRV_TWI_FREQ_250K = NRF_TWI_FREQ_250K , ///< 250 kbps.
NRF_DRV_TWI_FREQ_400K = NRF_TWI_FREQ_400K ///< 400 kbps.
} nrf_drv_twi_frequency_t;
/**
* @brief Structure for the TWI master driver instance configuration.
*/
typedef struct
{
uint32_t scl; ///< SCL pin number.
uint32_t sda; ///< SDA pin number.
nrf_drv_twi_frequency_t frequency; ///< TWI frequency.
uint8_t interrupt_priority; ///< Interrupt priority.
bool clear_bus_init; ///< Clear bus during init.
bool hold_bus_uninit; ///< Hold pull up state on gpio pins after uninit.
} nrf_drv_twi_config_t;
/**
* @brief TWI master driver instance default configuration.
*/
#define NRF_DRV_TWI_DEFAULT_CONFIG \
{ \
.frequency = (nrf_drv_twi_frequency_t)TWI_DEFAULT_CONFIG_FREQUENCY, \
.scl = 31, \
.sda = 31, \
.interrupt_priority = TWI_DEFAULT_CONFIG_IRQ_PRIORITY, \
.clear_bus_init = TWI_DEFAULT_CONFIG_CLR_BUS_INIT, \
.hold_bus_uninit = TWI_DEFAULT_CONFIG_HOLD_BUS_UNINIT, \
}
#define NRF_DRV_TWI_FLAG_TX_POSTINC (1UL << 0) /**< TX buffer address incremented after transfer. */
#define NRF_DRV_TWI_FLAG_RX_POSTINC (1UL << 1) /**< RX buffer address incremented after transfer. */
#define NRF_DRV_TWI_FLAG_NO_XFER_EVT_HANDLER (1UL << 2) /**< Interrupt after each transfer is suppressed, and the event handler is not called. */
#define NRF_DRV_TWI_FLAG_HOLD_XFER (1UL << 3) /**< Set up the transfer but do not start it. */
#define NRF_DRV_TWI_FLAG_REPEATED_XFER (1UL << 4) /**< Flag indicating that the transfer will be executed multiple times. */
#define NRF_DRV_TWI_FLAG_TX_NO_STOP (1UL << 5) /**< Flag indicating that the TX transfer will not end with a stop condition. */
/**
* @brief TWI master driver event types.
*/
typedef enum
{
NRF_DRV_TWI_EVT_DONE, ///< Transfer completed event.
NRF_DRV_TWI_EVT_ADDRESS_NACK, ///< Error event: NACK received after sending the address.
NRF_DRV_TWI_EVT_DATA_NACK ///< Error event: NACK received after sending a data byte.
} nrf_drv_twi_evt_type_t;
/**
* @brief TWI master driver transfer types.
*/
typedef enum
{
NRF_DRV_TWI_XFER_TX, ///< TX transfer.
NRF_DRV_TWI_XFER_RX, ///< RX transfer.
NRF_DRV_TWI_XFER_TXRX, ///< TX transfer followed by RX transfer with repeated start.
NRF_DRV_TWI_XFER_TXTX ///< TX transfer followed by TX transfer with repeated start.
} nrf_drv_twi_xfer_type_t;
/**
* @brief Structure for a TWI transfer descriptor.
*/
typedef struct
{
nrf_drv_twi_xfer_type_t type; ///< Type of transfer.
uint8_t address; ///< Slave address.
uint8_t primary_length; ///< Number of bytes transferred.
uint8_t secondary_length; ///< Number of bytes transferred.
uint8_t * p_primary_buf; ///< Pointer to transferred data.
uint8_t * p_secondary_buf; ///< Pointer to transferred data.
} nrf_drv_twi_xfer_desc_t;
/**@brief Macro for setting the TX transfer descriptor. */
#define NRF_DRV_TWI_XFER_DESC_TX(addr, p_data, length) \
{ \
.type = NRF_DRV_TWI_XFER_TX, \
.address = addr, \
.primary_length = length, \
.p_primary_buf = p_data, \
}
/**@brief Macro for setting the RX transfer descriptor. */
#define NRF_DRV_TWI_XFER_DESC_RX(addr, p_data, length) \
{ \
.type = NRF_DRV_TWI_XFER_RX, \
.address = addr, \
.primary_length = length, \
.p_primary_buf = p_data, \
}
/**@brief Macro for setting the TXRX transfer descriptor. */
#define NRF_DRV_TWI_XFER_DESC_TXRX(addr, p_tx, tx_len, p_rx, rx_len) \
{ \
.type = NRF_DRV_TWI_XFER_TXRX, \
.address = addr, \
.primary_length = tx_len, \
.secondary_length = rx_len, \
.p_primary_buf = p_tx, \
.p_secondary_buf = p_rx, \
}
/**@brief Macro for setting the TXTX transfer descriptor. */
#define NRF_DRV_TWI_XFER_DESC_TXTX(addr, p_tx, tx_len, p_tx2, tx_len2) \
{ \
.type = NRF_DRV_TWI_XFER_TXTX, \
.address = addr, \
.primary_length = tx_len, \
.secondary_length = tx_len2, \
.p_primary_buf = p_tx, \
.p_secondary_buf = p_tx2, \
}
/**
* @brief Structure for a TWI event.
*/
typedef struct
{
nrf_drv_twi_evt_type_t type; ///< Event type.
nrf_drv_twi_xfer_desc_t xfer_desc; ///< Transfer details.
} nrf_drv_twi_evt_t;
/**
* @brief TWI event handler prototype.
*/
typedef void (* nrf_drv_twi_evt_handler_t)(nrf_drv_twi_evt_t const * p_event,
void * p_context);
/**
* @brief Function for initializing the TWI driver instance.
*
* @param[in] p_instance Pointer to the driver instance structure.
* @param[in] p_config Initial configuration.
* @param[in] event_handler Event handler provided by the user. If NULL, blocking mode is enabled.
* @param[in] p_context Context passed to event handler.
*
* @retval NRF_SUCCESS If initialization was successful.
* @retval NRF_ERROR_INVALID_STATE If the driver is in invalid state.
* @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.
*/
ret_code_t nrf_drv_twi_init(nrf_drv_twi_t const * p_instance,
nrf_drv_twi_config_t const * p_config,
nrf_drv_twi_evt_handler_t event_handler,
void * p_context);
/**
* @brief Function for uninitializing the TWI instance.
*
* @param[in] p_instance Pointer to the driver instance structure.
*/
__STATIC_INLINE
void nrf_drv_twi_uninit(nrf_drv_twi_t const * p_instance);
/**
* @brief Function for enabling the TWI instance.
*
* @param[in] p_instance Pointer to the driver instance structure.
*/
__STATIC_INLINE
void nrf_drv_twi_enable(nrf_drv_twi_t const * p_instance);
/**
* @brief Function for disabling the TWI instance.
*
* @param[in] p_instance Pointer to the driver instance structure.
*/
__STATIC_INLINE
void nrf_drv_twi_disable(nrf_drv_twi_t const * p_instance);
/**
* @brief Function for sending data to a TWI slave.
*
* The transmission will be stopped when an error occurs. If a transfer is ongoing,
* the function returns the error code @ref NRF_ERROR_BUSY.
*
* @param[in] p_instance Pointer to the driver instance structure.
* @param[in] address Address of a specific slave device (only 7 LSB).
* @param[in] p_data Pointer to a transmit buffer.
* @param[in] length Number of bytes to send.
* @param[in] no_stop If set, the stop condition is not generated on the bus
* after the transfer has completed successfully (allowing
* for a repeated start in the next transfer).
*
* @retval NRF_SUCCESS If the procedure was successful.
* @retval NRF_ERROR_BUSY If the driver is not ready for a new transfer.
* @retval NRF_ERROR_INTERNAL If an error was detected by hardware.
* @retval NRF_ERROR_INVALID_ADDR If the EasyDMA is used and memory adress in not in RAM.
* @retval NRF_ERROR_DRV_TWI_ERR_ANACK If NACK received after sending the address in polling mode.
* @retval NRF_ERROR_DRV_TWI_ERR_DNACK If NACK received after sending a data byte in polling mode.
*/
__STATIC_INLINE
ret_code_t nrf_drv_twi_tx(nrf_drv_twi_t const * p_instance,
uint8_t address,
uint8_t const * p_data,
uint8_t length,
bool no_stop);
/**
* @brief Function for reading data from a TWI slave.
*
* The transmission will be stopped when an error occurs. If a transfer is ongoing,
* the function returns the error code @ref NRF_ERROR_BUSY.
*
* @param[in] p_instance Pointer to the driver instance structure.
* @param[in] address Address of a specific slave device (only 7 LSB).
* @param[in] p_data Pointer to a receive buffer.
* @param[in] length Number of bytes to be received.
*
* @retval NRF_SUCCESS If the procedure was successful.
* @retval NRF_ERROR_BUSY If the driver is not ready for a new transfer.
* @retval NRF_ERROR_INTERNAL If an error was detected by hardware.
* @retval NRF_ERROR_DRV_TWI_ERR_OVERRUN If the unread data was replaced by new data
* @retval NRF_ERROR_DRV_TWI_ERR_ANACK If NACK received after sending the address in polling mode.
* @retval NRF_ERROR_DRV_TWI_ERR_DNACK If NACK received after sending a data byte in polling mode.
*/
__STATIC_INLINE
ret_code_t nrf_drv_twi_rx(nrf_drv_twi_t const * p_instance,
uint8_t address,
uint8_t * p_data,
uint8_t length);
/**
* @brief Function for preparing a TWI transfer.
*
* The following transfer types can be configured (@ref nrf_drv_twi_xfer_desc_t::type):
* - @ref NRF_DRV_TWI_XFER_TXRX<span></span>: Write operation followed by a read operation (without STOP condition in between).
* - @ref NRF_DRV_TWI_XFER_TXTX<span></span>: Write operation followed by a write operation (without STOP condition in between).
* - @ref NRF_DRV_TWI_XFER_TX<span></span>: Write operation (with or without STOP condition).
* - @ref NRF_DRV_TWI_XFER_RX<span></span>: Read operation (with STOP condition).
*
* Additional options are provided using the flags parameter:
* - @ref NRF_DRV_TWI_FLAG_TX_POSTINC and @ref NRF_DRV_TWI_FLAG_RX_POSTINC<span></span>: Post-incrementation of buffer addresses. Supported only by TWIM.
* - @ref NRF_DRV_TWI_FLAG_NO_XFER_EVT_HANDLER<span></span>: No user event handler after transfer completion. In most cases, this also means no interrupt at the end of the transfer.
* - @ref NRF_DRV_TWI_FLAG_HOLD_XFER<span></span>: Driver is not starting the transfer. Use this flag if the transfer is triggered externally by PPI. Supported only by TWIM.
* Use @ref nrf_drv_twi_start_task_get to get the address of the start task.
* - @ref NRF_DRV_TWI_FLAG_REPEATED_XFER<span></span>: Prepare for repeated transfers. You can set up a number of transfers that will be triggered externally (for example by PPI).
* An example is a TXRX transfer with the options @ref NRF_DRV_TWI_FLAG_RX_POSTINC, @ref NRF_DRV_TWI_FLAG_NO_XFER_EVT_HANDLER, and @ref NRF_DRV_TWI_FLAG_REPEATED_XFER.
* After the transfer is set up, a set of transfers can be triggered by PPI that will read, for example, the same register of an
* external component and put it into a RAM buffer without any interrupts. @ref nrf_drv_twi_stopped_event_get can be used to get the
* address of the STOPPED event, which can be used to count the number of transfers. If @ref NRF_DRV_TWI_FLAG_REPEATED_XFER is used,
* the driver does not set the driver instance into busy state, so you must ensure that the next transfers are set up
* when TWIM is not active. Supported only by TWIM.
* - @ref NRF_DRV_TWI_FLAG_TX_NO_STOP<span></span>: No stop condition after TX transfer.
*
* @note
* Some flag combinations are invalid:
* - @ref NRF_DRV_TWI_FLAG_TX_NO_STOP with @ref nrf_drv_twi_xfer_desc_t::type different than @ref NRF_DRV_TWI_XFER_TX
* - @ref NRF_DRV_TWI_FLAG_REPEATED_XFER with @ref nrf_drv_twi_xfer_desc_t::type set to @ref NRF_DRV_TWI_XFER_TXTX
*
* If @ref nrf_drv_twi_xfer_desc_t::type is set to @ref NRF_DRV_TWI_XFER_TX and the @ref NRF_DRV_TWI_FLAG_TX_NO_STOP and @ref NRF_DRV_TWI_FLAG_REPEATED_XFER
* flags are set, two tasks must be used to trigger a transfer: TASKS_RESUME followed by TASKS_STARTTX. If no stop condition is generated,
* TWIM is in SUSPENDED state. Therefore, it must be resumed before the transfer can be started.
*
* @note
* This function should be used only if the instance is configured to work in non-blocking mode. If the function is used in blocking mode, the driver asserts.
* @note If you are using this function with TWI, the only supported flag is @ref NRF_DRV_TWI_FLAG_TX_NO_STOP. All other flags require TWIM.
*
* @param[in] p_instance Pointer to the driver instance structure.
* @param[in] p_xfer_desc Pointer to the transfer descriptor.
* @param[in] flags Transfer options (0 for default settings).
*
* @retval NRF_SUCCESS If the procedure was successful.
* @retval NRF_ERROR_BUSY If the driver is not ready for a new transfer.
* @retval NRF_ERROR_NOT_SUPPORTED If the provided parameters are not supported.
* @retval NRF_ERROR_INTERNAL If an error was detected by hardware.
* @retval NRF_ERROR_INVALID_ADDR If the EasyDMA is used and memory adress in not in RAM
* @retval NRF_ERROR_DRV_TWI_ERR_OVERRUN If the unread data was replaced by new data (TXRX and RX)
* @retval NRF_ERROR_DRV_TWI_ERR_ANACK If NACK received after sending the address.
* @retval NRF_ERROR_DRV_TWI_ERR_DNACK If NACK received after sending a data byte.
*/
__STATIC_INLINE
ret_code_t nrf_drv_twi_xfer(nrf_drv_twi_t const * p_instance,
nrf_drv_twi_xfer_desc_t const * p_xfer_desc,
uint32_t flags);
/**
* @brief Function for checking the TWI driver state.
*
* @param[in] p_instance TWI instance.
*
* @retval true If the TWI driver is currently busy performing a transfer.
* @retval false If the TWI driver is ready for a new transfer.
*/
__STATIC_INLINE
bool nrf_drv_twi_is_busy(nrf_drv_twi_t const * p_instance);
/**
* @brief Function for getting the transferred data count.
*
* This function provides valid results only in legacy mode.
*
* @param[in] p_instance Pointer to the driver instance structure.
*
* @return Data count.
*/
__STATIC_INLINE
uint32_t nrf_drv_twi_data_count_get(nrf_drv_twi_t const * const p_instance);
/**
* @brief Function for returning the address of a TWI/TWIM start task.
*
* This function should be used if @ref nrf_drv_twi_xfer was called with the flag @ref NRF_DRV_TWI_FLAG_HOLD_XFER.
* In that case, the transfer is not started by the driver, but it must be started externally by PPI.
*
* @param[in] p_instance Pointer to the driver instance structure.
* @param[in] xfer_type Transfer type used in the last call of the @ref nrf_drv_twi_xfer function.
*
* @return Start task address (TX or RX) depending on the value of xfer_type.
*/
__STATIC_INLINE
uint32_t nrf_drv_twi_start_task_get(nrf_drv_twi_t const * p_instance, nrf_drv_twi_xfer_type_t xfer_type);
/**
* @brief Function for returning the address of a STOPPED TWI/TWIM event.
*
* A STOPPED event can be used to detect the end of a transfer if the @ref NRF_DRV_TWI_FLAG_NO_XFER_EVT_HANDLER
* option is used.
*
* @param[in] p_instance Pointer to the driver instance structure.
*
* @return STOPPED event address.
*/
__STATIC_INLINE
uint32_t nrf_drv_twi_stopped_event_get(nrf_drv_twi_t const * p_instance);
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
#if defined(TWI_PRESENT) && !defined(TWIM_PRESENT)
#define NRF_DRV_TWI_WITH_TWI
#elif !defined(TWI_PRESENT) && defined(TWIM_PRESENT)
#define NRF_DRV_TWI_WITH_TWIM
#else
#if (NRFX_CHECK(TWI0_ENABLED) && NRFX_CHECK(TWI0_USE_EASY_DMA)) || \
(NRFX_CHECK(TWI1_ENABLED) && NRFX_CHECK(TWI1_USE_EASY_DMA))
#define NRF_DRV_TWI_WITH_TWIM
#endif
#if (NRFX_CHECK(TWI0_ENABLED) && !NRFX_CHECK(TWI0_USE_EASY_DMA)) || \
(NRFX_CHECK(TWI1_ENABLED) && !NRFX_CHECK(TWI1_USE_EASY_DMA))
#define NRF_DRV_TWI_WITH_TWI
#endif
#endif
#if defined(NRF_DRV_TWI_WITH_TWIM) && defined(NRF_DRV_TWI_WITH_TWI)
#define NRF_DRV_TWI_USE_TWIM (p_instance->use_easy_dma)
#elif defined(NRF_DRV_TWI_WITH_TWIM)
#define NRF_DRV_TWI_USE_TWIM true
#else
#define NRF_DRV_TWI_USE_TWIM false
#endif
#define NRF_DRV_TWI_USE_TWI (!NRF_DRV_TWI_USE_TWIM)
__STATIC_INLINE
void nrf_drv_twi_uninit(nrf_drv_twi_t const * p_instance)
{
if (NRF_DRV_TWI_USE_TWIM)
{
nrfx_twim_uninit(&p_instance->u.twim);
}
else if (NRF_DRV_TWI_USE_TWI)
{
nrfx_twi_uninit(&p_instance->u.twi);
}
}
__STATIC_INLINE
void nrf_drv_twi_enable(nrf_drv_twi_t const * p_instance)
{
if (NRF_DRV_TWI_USE_TWIM)
{
nrfx_twim_enable(&p_instance->u.twim);
}
else if (NRF_DRV_TWI_USE_TWI)
{
nrfx_twi_enable(&p_instance->u.twi);
}
}
__STATIC_INLINE
void nrf_drv_twi_disable(nrf_drv_twi_t const * p_instance)
{
if (NRF_DRV_TWI_USE_TWIM)
{
nrfx_twim_disable(&p_instance->u.twim);
}
else if (NRF_DRV_TWI_USE_TWI)
{
nrfx_twi_disable(&p_instance->u.twi);
}
}
__STATIC_INLINE
ret_code_t nrf_drv_twi_tx(nrf_drv_twi_t const * p_instance,
uint8_t address,
uint8_t const * p_data,
uint8_t length,
bool no_stop)
{
ret_code_t result = 0;
if (NRF_DRV_TWI_USE_TWIM)
{
result = nrfx_twim_tx(&p_instance->u.twim,
address, p_data, length, no_stop);
}
else if (NRF_DRV_TWI_USE_TWI)
{
result = nrfx_twi_tx(&p_instance->u.twi,
address, p_data, length, no_stop);
}
return result;
}
__STATIC_INLINE
ret_code_t nrf_drv_twi_rx(nrf_drv_twi_t const * p_instance,
uint8_t address,
uint8_t * p_data,
uint8_t length)
{
ret_code_t result = 0;
if (NRF_DRV_TWI_USE_TWIM)
{
result = nrfx_twim_rx(&p_instance->u.twim,
address, p_data, length);
}
else if (NRF_DRV_TWI_USE_TWI)
{
result = nrfx_twi_rx(&p_instance->u.twi,
address, p_data, length);
}
return result;
}
__STATIC_INLINE
ret_code_t nrf_drv_twi_xfer(nrf_drv_twi_t const * p_instance,
nrf_drv_twi_xfer_desc_t const * p_xfer_desc,
uint32_t flags)
{
ret_code_t result = 0;
if (NRF_DRV_TWI_USE_TWIM)
{
#ifdef TWIM_PRESENT
nrfx_twim_xfer_desc_t const twim_xfer_desc =
{
.type = (nrfx_twim_xfer_type_t)p_xfer_desc->type,
.address = p_xfer_desc->address,
.primary_length = p_xfer_desc->primary_length,
.secondary_length = p_xfer_desc->secondary_length,
.p_primary_buf = p_xfer_desc->p_primary_buf,
.p_secondary_buf = p_xfer_desc->p_secondary_buf,
};
result = nrfx_twim_xfer(&p_instance->u.twim, &twim_xfer_desc, flags);
#endif
}
else if (NRF_DRV_TWI_USE_TWI)
{
#ifdef TWI_PRESENT
nrfx_twi_xfer_desc_t const twi_xfer_desc =
{
.type = (nrfx_twi_xfer_type_t)p_xfer_desc->type,
.address = p_xfer_desc->address,
.primary_length = p_xfer_desc->primary_length,
.secondary_length = p_xfer_desc->secondary_length,
.p_primary_buf = p_xfer_desc->p_primary_buf,
.p_secondary_buf = p_xfer_desc->p_secondary_buf,
};
result = nrfx_twi_xfer(&p_instance->u.twi, &twi_xfer_desc, flags);
#endif
}
return result;
}
__STATIC_INLINE
bool nrf_drv_twi_is_busy(nrf_drv_twi_t const * p_instance)
{
bool result = 0;
if (NRF_DRV_TWI_USE_TWIM)
{
result = nrfx_twim_is_busy(&p_instance->u.twim);
}
else if (NRF_DRV_TWI_USE_TWI)
{
result = nrfx_twi_is_busy(&p_instance->u.twi);
}
return result;
}
__STATIC_INLINE
uint32_t nrf_drv_twi_data_count_get(nrf_drv_twi_t const * const p_instance)
{
uint32_t result = 0;
if (NRF_DRV_TWI_USE_TWIM)
{
NRFX_ASSERT(false); // not supported
result = 0;
}
else if (NRF_DRV_TWI_USE_TWI)
{
result = nrfx_twi_data_count_get(&p_instance->u.twi);
}
return result;
}
__STATIC_INLINE
uint32_t nrf_drv_twi_start_task_get(nrf_drv_twi_t const * p_instance,
nrf_drv_twi_xfer_type_t xfer_type)
{
uint32_t result = 0;
if (NRF_DRV_TWI_USE_TWIM)
{
result = nrfx_twim_start_task_get(&p_instance->u.twim,
(nrfx_twim_xfer_type_t)xfer_type);
}
else if (NRF_DRV_TWI_USE_TWI)
{
NRFX_ASSERT(false); // not supported
result = 0;
}
return result;
}
__STATIC_INLINE
uint32_t nrf_drv_twi_stopped_event_get(nrf_drv_twi_t const * p_instance)
{
uint32_t result = 0;
if (NRF_DRV_TWI_USE_TWIM)
{
result = nrfx_twim_stopped_event_get(&p_instance->u.twim);
}
else if (NRF_DRV_TWI_USE_TWI)
{
result = nrfx_twi_stopped_event_get(&p_instance->u.twi);
}
return result;
}
#endif // SUPPRESS_INLINE_IMPLEMENTATION
/** @} */
#ifdef __cplusplus
}
#endif
#endif // NRF_DRV_TWI_H__

View File

@ -1,671 +0,0 @@
/**
* Copyright (c) 2015 - 2018, 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_UART_H__
#define NRF_DRV_UART_H__
#include <nrfx.h>
// Needed for Mbed
#ifndef UART1_ENABLED
#define UART1_ENABLED 0
#endif
#ifndef UART0_ENABLED
#define UART0_ENABLED 0
#endif
#define UART0_INSTANCE_INDEX 0
#define UART1_INSTANCE_INDEX UART0_ENABLED
#define UART_ENABLED_COUNT UART0_ENABLED + UART1_ENABLED
#if defined(UARTE_PRESENT) && NRFX_CHECK(NRFX_UARTE_ENABLED)
#define NRF_DRV_UART_WITH_UARTE
#endif
#if defined(UART_PRESENT) && NRFX_CHECK(NRFX_UART_ENABLED)
#define NRF_DRV_UART_WITH_UART
#endif
#if defined(NRF_DRV_UART_WITH_UARTE)
#include <nrfx_uarte.h>
#define NRF_DRV_UART_CREATE_UARTE(id) \
.uarte = NRFX_UARTE_INSTANCE(id),
#else
// Compilers (at least the smart ones) will remove the UARTE related code
// (blocks starting with "if (NRF_DRV_UART_USE_UARTE)") when it is not used,
// but to perform the compilation they need the following definitions.
#define nrfx_uarte_init(...) 0
#define nrfx_uarte_uninit(...)
#define nrfx_uarte_task_address_get(...) 0
#define nrfx_uarte_event_address_get(...) 0
#define nrfx_uarte_tx(...) 0
#define nrfx_uarte_tx_in_progress(...) 0
#define nrfx_uarte_tx_abort(...)
#define nrfx_uarte_rx(...) 0
#define nrfx_uarte_rx_ready(...) 0
#define nrfx_uarte_rx_abort(...)
#define nrfx_uarte_errorsrc_get(...) 0
#define NRF_DRV_UART_CREATE_UARTE(id)
#endif
// Mbed - needed to build
#define NRF_DRV_UART_WITH_UART
#if defined(NRF_DRV_UART_WITH_UART)
#include <nrfx_uart.h>
#define NRF_DRV_UART_CREATE_UART(id) \
.uart = NRFX_UART_INSTANCE(id),
#else
// Compilers (at least the smart ones) will remove the UART related code
// (blocks starting with "if (NRF_DRV_UART_USE_UART)") when it is not used,
// but to perform the compilation they need the following definitions.
#define nrfx_uart_init(...) 0
#define nrfx_uart_uninit(...)
#define nrfx_uart_task_address_get(...) 0
#define nrfx_uart_event_address_get(...) 0
#define nrfx_uart_tx(...) 0
#define nrfx_uart_tx_in_progress(...) 0
#define nrfx_uart_tx_abort(...)
#define nrfx_uart_rx(...) 0
#define nrfx_uart_rx_enable(...)
#define nrfx_uart_rx_disable(...)
#define nrfx_uart_rx_ready(...) 0
#define nrfx_uart_rx_abort(...)
#define nrfx_uart_errorsrc_get(...) 0
#define NRF_DRV_UART_CREATE_UART(id)
// This part is for old modules that use directly UART HAL definitions
// (to make them compilable for chips that have only UARTE).
#define NRF_UART_BAUDRATE_1200 NRF_UARTE_BAUDRATE_1200
#define NRF_UART_BAUDRATE_2400 NRF_UARTE_BAUDRATE_2400
#define NRF_UART_BAUDRATE_4800 NRF_UARTE_BAUDRATE_4800
#define NRF_UART_BAUDRATE_9600 NRF_UARTE_BAUDRATE_9600
#define NRF_UART_BAUDRATE_14400 NRF_UARTE_BAUDRATE_14400
#define NRF_UART_BAUDRATE_19200 NRF_UARTE_BAUDRATE_19200
#define NRF_UART_BAUDRATE_28800 NRF_UARTE_BAUDRATE_28800
#define NRF_UART_BAUDRATE_38400 NRF_UARTE_BAUDRATE_38400
#define NRF_UART_BAUDRATE_57600 NRF_UARTE_BAUDRATE_57600
#define NRF_UART_BAUDRATE_76800 NRF_UARTE_BAUDRATE_76800
#define NRF_UART_BAUDRATE_115200 NRF_UARTE_BAUDRATE_115200
#define NRF_UART_BAUDRATE_230400 NRF_UARTE_BAUDRATE_230400
#define NRF_UART_BAUDRATE_250000 NRF_UARTE_BAUDRATE_250000
#define NRF_UART_BAUDRATE_460800 NRF_UARTE_BAUDRATE_460800
#define NRF_UART_BAUDRATE_921600 NRF_UARTE_BAUDRATE_921600
#define NRF_UART_BAUDRATE_1000000 NRF_UARTE_BAUDRATE_1000000
typedef nrf_uarte_baudrate_t nrf_uart_baudrate_t;
#define NRF_UART_ERROR_OVERRUN_MASK NRF_UARTE_ERROR_OVERRUN_MASK
#define NRF_UART_ERROR_PARITY_MASK NRF_UARTE_ERROR_PARITY_MASK
#define NRF_UART_ERROR_FRAMING_MASK NRF_UARTE_ERROR_PARITY_MASK
#define NRF_UART_ERROR_BREAK_MASK NRF_UARTE_ERROR_BREAK_MASK
typedef nrf_uarte_error_mask_t nrf_uart_error_mask_t;
#define NRF_UART_HWFC_DISABLED NRF_UARTE_HWFC_DISABLED
#define NRF_UART_HWFC_ENABLED NRF_UARTE_HWFC_ENABLED
typedef nrf_uarte_hwfc_t nrf_uart_hwfc_t;
#define NRF_UART_PARITY_EXCLUDED NRF_UARTE_PARITY_EXCLUDED
#define NRF_UART_PARITY_INCLUDED NRF_UARTE_PARITY_INCLUDED
typedef nrf_uarte_parity_t nrf_uart_parity_t;
typedef nrf_uarte_task_t nrf_uart_task_t;
typedef nrf_uarte_event_t nrf_uart_event_t;
#define NRF_UART_PSEL_DISCONNECTED NRF_UARTE_PSEL_DISCONNECTED
#define nrf_uart_event_clear(...)
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup nrf_drv_uart UART driver - legacy layer
* @{
* @ingroup nrf_uart
* @brief Layer providing compatibility with the former API.
*/
/**
* @brief Structure for the UART driver instance.
*/
typedef struct
{
uint8_t inst_idx;
#if defined(NRF_DRV_UART_WITH_UARTE)
nrfx_uarte_t uarte;
#endif
#if defined(NRF_DRV_UART_WITH_UART)
nrfx_uart_t uart;
#endif
} nrf_drv_uart_t;
/**
* @brief Macro for creating an UART driver instance.
*/
#define NRF_DRV_UART_INSTANCE(id) \
{ \
.inst_idx = id, \
NRF_DRV_UART_CREATE_UARTE(id) \
NRF_DRV_UART_CREATE_UART(id) \
}
/**
* @brief Types of UART driver events.
*/
typedef enum
{
NRF_DRV_UART_EVT_TX_DONE, ///< Requested TX transfer completed.
NRF_DRV_UART_EVT_RX_DONE, ///< Requested RX transfer completed.
NRF_DRV_UART_EVT_ERROR, ///< Error reported by UART peripheral.
} nrf_drv_uart_evt_type_t;
/**@brief Structure for UART configuration. */
typedef struct
{
uint32_t pseltxd; ///< TXD pin number.
uint32_t pselrxd; ///< RXD pin number.
uint32_t pselcts; ///< CTS pin number.
uint32_t pselrts; ///< RTS pin number.
void * p_context; ///< Context passed to interrupt handler.
nrf_uart_hwfc_t hwfc; ///< Flow control configuration.
nrf_uart_parity_t parity; ///< Parity configuration.
nrf_uart_baudrate_t baudrate; ///< Baudrate.
uint8_t interrupt_priority; ///< Interrupt priority.
#if defined(NRF_DRV_UART_WITH_UARTE) && defined(NRF_DRV_UART_WITH_UART)
bool use_easy_dma;
#endif
} nrf_drv_uart_config_t;
#if defined(NRF_DRV_UART_WITH_UARTE) && defined(NRF_DRV_UART_WITH_UART)
extern uint8_t nrf_drv_uart_use_easy_dma[];
#define NRF_DRV_UART_DEFAULT_CONFIG_USE_EASY_DMA .use_easy_dma = true,
#else
#define NRF_DRV_UART_DEFAULT_CONFIG_USE_EASY_DMA
#endif
/**@brief UART default configuration. */
#define NRF_DRV_UART_DEFAULT_CONFIG \
{ \
.pseltxd = NRF_UART_PSEL_DISCONNECTED, \
.pselrxd = NRF_UART_PSEL_DISCONNECTED, \
.pselcts = NRF_UART_PSEL_DISCONNECTED, \
.pselrts = NRF_UART_PSEL_DISCONNECTED, \
.p_context = NULL, \
.hwfc = (nrf_uart_hwfc_t)UART_DEFAULT_CONFIG_HWFC, \
.parity = (nrf_uart_parity_t)UART_DEFAULT_CONFIG_PARITY, \
.baudrate = (nrf_uart_baudrate_t)UART_DEFAULT_CONFIG_BAUDRATE, \
.interrupt_priority = UART_DEFAULT_CONFIG_IRQ_PRIORITY, \
NRF_DRV_UART_DEFAULT_CONFIG_USE_EASY_DMA \
}
/**@brief Structure for UART transfer completion event. */
typedef struct
{
uint8_t * p_data; ///< Pointer to memory used for transfer.
uint8_t bytes; ///< Number of bytes transfered.
} nrf_drv_uart_xfer_evt_t;
/**@brief Structure for UART error event. */
typedef struct
{
nrf_drv_uart_xfer_evt_t rxtx; ///< Transfer details includes number of bytes transfered.
uint32_t error_mask;///< Mask of error flags that generated the event.
} nrf_drv_uart_error_evt_t;
/**@brief Structure for UART event. */
typedef struct
{
nrf_drv_uart_evt_type_t type; ///< Event type.
union
{
nrf_drv_uart_xfer_evt_t rxtx; ///< Data provided for transfer completion events.
nrf_drv_uart_error_evt_t error;///< Data provided for error event.
} data;
} nrf_drv_uart_event_t;
/**
* @brief UART interrupt event handler.
*
* @param[in] p_event Pointer to event structure. Event is allocated on the stack so it is available
* only within the context of the event handler.
* @param[in] p_context Context passed to interrupt handler, set on initialization.
*/
typedef void (*nrf_uart_event_handler_t)(nrf_drv_uart_event_t * p_event, void * p_context);
/**
* @brief Function for initializing the UART driver.
*
* This function configures and enables UART. After this function GPIO pins are controlled by UART.
*
* @param[in] p_instance Pointer to the driver instance structure.
* @param[in] p_config Initial configuration.
* @param[in] event_handler Event handler provided by the user. If not provided driver works in
* blocking mode.
*
* @retval NRFX_SUCCESS If initialization was successful.
* @retval NRFX_ERROR_INVALID_STATE If driver is already initialized.
*/
ret_code_t nrf_drv_uart_init(nrf_drv_uart_t const * p_instance,
nrf_drv_uart_config_t const * p_config,
nrf_uart_event_handler_t event_handler);
/**
* @brief Function for uninitializing the UART driver.
* @param[in] p_instance Pointer to the driver instance structure.
*/
__STATIC_INLINE
void nrf_drv_uart_uninit(nrf_drv_uart_t const * p_instance);
/**
* @brief Function for getting the address of a specific UART task.
*
* @param[in] p_instance Pointer to the driver instance structure.
* @param[in] task Task.
*
* @return Task address.
*/
__STATIC_INLINE
uint32_t nrf_drv_uart_task_address_get(nrf_drv_uart_t const * p_instance,
nrf_uart_task_t task);
/**
* @brief Function for getting the address of a specific UART event.
*
* @param[in] p_instance Pointer to the driver instance structure.
* @param[in] event Event.
*
* @return Event address.
*/
__STATIC_INLINE
uint32_t nrf_drv_uart_event_address_get(nrf_drv_uart_t const * p_instance,
nrf_uart_event_t event);
/**
* @brief Function for sending data over UART.
*
* If an event handler was provided in nrf_drv_uart_init() call, this function
* returns immediately and the handler is called when the transfer is done.
* Otherwise, the transfer is performed in blocking mode, i.e. this function
* returns when the transfer is finished. Blocking mode is not using interrupt so
* there is no context switching inside the function.
*
* @note Peripherals using EasyDMA (i.e. UARTE) require that the transfer buffers
* are placed in the Data RAM region. If they are not and UARTE instance is
* used, this function will fail with error code NRFX_ERROR_INVALID_ADDR.
*
* @param[in] p_instance Pointer to the driver instance structure.
* @param[in] p_data Pointer to data.
* @param[in] length Number of bytes to send.
*
* @retval NRFX_SUCCESS If initialization was successful.
* @retval NRFX_ERROR_BUSY If driver is already transferring.
* @retval NRFX_ERROR_FORBIDDEN If the transfer was aborted from a different context
* (blocking mode only, also see @ref nrf_drv_uart_rx_disable).
* @retval NRFX_ERROR_INVALID_ADDR If p_data does not point to RAM buffer (UARTE only).
*/
__STATIC_INLINE
ret_code_t nrf_drv_uart_tx(nrf_drv_uart_t const * p_instance,
uint8_t const * const p_data,
uint8_t length);
/**
* @brief Function for checking if UART is currently transmitting.
*
* @param[in] p_instance Pointer to the driver instance structure.
*
* @retval true If UART is transmitting.
* @retval false If UART is not transmitting.
*/
__STATIC_INLINE
bool nrf_drv_uart_tx_in_progress(nrf_drv_uart_t const * p_instance);
/**
* @brief Function for aborting any ongoing transmission.
* @note @ref NRF_DRV_UART_EVT_TX_DONE event will be generated in non-blocking mode. Event will
* contain number of bytes sent until abort was called. If Easy DMA is not used event will be
* called from the function context. If Easy DMA is used it will be called from UART interrupt
* context.
*
* @param[in] p_instance Pointer to the driver instance structure.
*/
__STATIC_INLINE
void nrf_drv_uart_tx_abort(nrf_drv_uart_t const * p_instance);
/**
* @brief Function for receiving data over UART.
*
* If an event handler was provided in the nrf_drv_uart_init() call, this function
* returns immediately and the handler is called when the transfer is done.
* Otherwise, the transfer is performed in blocking mode, i.e. this function
* returns when the transfer is finished. Blocking mode is not using interrupt so
* there is no context switching inside the function.
* The receive buffer pointer is double buffered in non-blocking mode. The secondary
* buffer can be set immediately after starting the transfer and will be filled
* when the primary buffer is full. The double buffering feature allows
* receiving data continuously.
*
* @note Peripherals using EasyDMA (i.e. UARTE) require that the transfer buffers
* are placed in the Data RAM region. If they are not and UARTE driver instance
* is used, this function will fail with error code NRFX_ERROR_INVALID_ADDR.
*
* @param[in] p_instance Pointer to the driver instance structure.
* @param[in] p_data Pointer to data.
* @param[in] length Number of bytes to receive.
*
* @retval NRFX_SUCCESS If initialization was successful.
* @retval NRFX_ERROR_BUSY If the driver is already receiving
* (and the secondary buffer has already been set
* in non-blocking mode).
* @retval NRFX_ERROR_FORBIDDEN If the transfer was aborted from a different context
* (blocking mode only, also see @ref nrf_drv_uart_rx_disable).
* @retval NRFX_ERROR_INTERNAL If UART peripheral reported an error.
* @retval NRFX_ERROR_INVALID_ADDR If p_data does not point to RAM buffer (UARTE only).
*/
__STATIC_INLINE
ret_code_t nrf_drv_uart_rx(nrf_drv_uart_t const * p_instance,
uint8_t * p_data,
uint8_t length);
/**
* @brief Function for testing the receiver state in blocking mode.
*
* @param[in] p_instance Pointer to the driver instance structure.
*
* @retval true If the receiver has at least one byte of data to get.
* @retval false If the receiver is empty.
*/
__STATIC_INLINE
bool nrf_drv_uart_rx_ready(nrf_drv_uart_t const * p_instance);
/**
* @brief Function for enabling the receiver.
*
* UART has a 6-byte-long RX FIFO and it is used to store incoming data. If a user does not call the
* UART receive function before the FIFO is filled, an overrun error will appear. Enabling the receiver
* without specifying an RX buffer is supported only in UART mode (without Easy DMA). The receiver must be
* explicitly closed by the user @sa nrf_drv_uart_rx_disable. This function asserts if the mode is wrong.
*
* @param[in] p_instance Pointer to the driver instance structure.
*/
__STATIC_INLINE
void nrf_drv_uart_rx_enable(nrf_drv_uart_t const * p_instance);
/**
* @brief Function for disabling the receiver.
*
* This function must be called to close the receiver after it has been explicitly enabled by
* @sa nrf_drv_uart_rx_enable. The feature is supported only in UART mode (without Easy DMA). The function
* asserts if mode is wrong.
*
* @param[in] p_instance Pointer to the driver instance structure.
*/
__STATIC_INLINE
void nrf_drv_uart_rx_disable(nrf_drv_uart_t const * p_instance);
/**
* @brief Function for aborting any ongoing reception.
* @note @ref NRF_DRV_UART_EVT_RX_DONE event will be generated in non-blocking mode. The event will
* contain the number of bytes received until abort was called. The event is called from UART interrupt
* context.
*
* @param[in] p_instance Pointer to the driver instance structure.
*/
__STATIC_INLINE
void nrf_drv_uart_rx_abort(nrf_drv_uart_t const * p_instance);
/**
* @brief Function for reading error source mask. Mask contains values from @ref nrf_uart_error_mask_t.
* @note Function should be used in blocking mode only. In case of non-blocking mode, an error event is
* generated. Function clears error sources after reading.
*
* @param[in] p_instance Pointer to the driver instance structure.
*
* @retval Mask of reported errors.
*/
__STATIC_INLINE
uint32_t nrf_drv_uart_errorsrc_get(nrf_drv_uart_t const * p_instance);
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
#if defined(NRF_DRV_UART_WITH_UARTE) && defined(NRF_DRV_UART_WITH_UART)
#define NRF_DRV_UART_USE_UARTE (nrf_drv_uart_use_easy_dma[p_instance->inst_idx])
#elif defined(NRF_DRV_UART_WITH_UARTE)
#define NRF_DRV_UART_USE_UARTE true
#else
#define NRF_DRV_UART_USE_UARTE false
#endif
#define NRF_DRV_UART_USE_UART (!NRF_DRV_UART_USE_UARTE)
__STATIC_INLINE
void nrf_drv_uart_uninit(nrf_drv_uart_t const * p_instance)
{
if (NRF_DRV_UART_USE_UARTE)
{
nrfx_uarte_uninit(&p_instance->uarte);
}
else if (NRF_DRV_UART_USE_UART)
{
nrfx_uart_uninit(&p_instance->uart);
}
}
__STATIC_INLINE
uint32_t nrf_drv_uart_task_address_get(nrf_drv_uart_t const * p_instance,
nrf_uart_task_t task)
{
uint32_t result = 0;
if (NRF_DRV_UART_USE_UARTE)
{
result = nrfx_uarte_task_address_get(&p_instance->uarte,
(nrf_uarte_task_t)task);
}
else if (NRF_DRV_UART_USE_UART)
{
result = nrfx_uart_task_address_get(&p_instance->uart, task);
}
return result;
}
__STATIC_INLINE
uint32_t nrf_drv_uart_event_address_get(nrf_drv_uart_t const * p_instance,
nrf_uart_event_t event)
{
uint32_t result = 0;
if (NRF_DRV_UART_USE_UARTE)
{
result = nrfx_uarte_event_address_get(&p_instance->uarte,
(nrf_uarte_event_t)event);
}
else if (NRF_DRV_UART_USE_UART)
{
result = nrfx_uart_event_address_get(&p_instance->uart, event);
}
return result;
}
__STATIC_INLINE
ret_code_t nrf_drv_uart_tx(nrf_drv_uart_t const * p_instance,
uint8_t const * p_data,
uint8_t length)
{
uint32_t result = 0;
if (NRF_DRV_UART_USE_UARTE)
{
result = nrfx_uarte_tx(&p_instance->uarte,
p_data,
length);
}
else if (NRF_DRV_UART_USE_UART)
{
result = nrfx_uart_tx(&p_instance->uart,
p_data,
length);
}
return result;
}
__STATIC_INLINE
bool nrf_drv_uart_tx_in_progress(nrf_drv_uart_t const * p_instance)
{
bool result = 0;
if (NRF_DRV_UART_USE_UARTE)
{
result = nrfx_uarte_tx_in_progress(&p_instance->uarte);
}
else if (NRF_DRV_UART_USE_UART)
{
result = nrfx_uart_tx_in_progress(&p_instance->uart);
}
return result;
}
__STATIC_INLINE
void nrf_drv_uart_tx_abort(nrf_drv_uart_t const * p_instance)
{
if (NRF_DRV_UART_USE_UARTE)
{
nrfx_uarte_tx_abort(&p_instance->uarte);
}
else if (NRF_DRV_UART_USE_UART)
{
nrfx_uart_tx_abort(&p_instance->uart);
}
}
__STATIC_INLINE
ret_code_t nrf_drv_uart_rx(nrf_drv_uart_t const * p_instance,
uint8_t * p_data,
uint8_t length)
{
uint32_t result = 0;
if (NRF_DRV_UART_USE_UARTE)
{
result = nrfx_uarte_rx(&p_instance->uarte,
p_data,
length);
}
else if (NRF_DRV_UART_USE_UART)
{
result = nrfx_uart_rx(&p_instance->uart,
p_data,
length);
}
return result;
}
__STATIC_INLINE
bool nrf_drv_uart_rx_ready(nrf_drv_uart_t const * p_instance)
{
bool result = 0;
if (NRF_DRV_UART_USE_UARTE)
{
result = nrfx_uarte_rx_ready(&p_instance->uarte);
}
else if (NRF_DRV_UART_USE_UART)
{
result = nrfx_uart_rx_ready(&p_instance->uart);
}
return result;
}
__STATIC_INLINE
void nrf_drv_uart_rx_enable(nrf_drv_uart_t const * p_instance)
{
if (NRF_DRV_UART_USE_UARTE)
{
NRFX_ASSERT(false); // not supported
}
else if (NRF_DRV_UART_USE_UART)
{
nrfx_uart_rx_enable(&p_instance->uart);
}
}
__STATIC_INLINE
void nrf_drv_uart_rx_disable(nrf_drv_uart_t const * p_instance)
{
if (NRF_DRV_UART_USE_UARTE)
{
NRFX_ASSERT(false); // not supported
}
else if (NRF_DRV_UART_USE_UART)
{
nrfx_uart_rx_disable(&p_instance->uart);
}
}
__STATIC_INLINE
void nrf_drv_uart_rx_abort(nrf_drv_uart_t const * p_instance)
{
if (NRF_DRV_UART_USE_UARTE)
{
nrfx_uarte_rx_abort(&p_instance->uarte);
}
else if (NRF_DRV_UART_USE_UART)
{
nrfx_uart_rx_abort(&p_instance->uart);
}
}
__STATIC_INLINE
uint32_t nrf_drv_uart_errorsrc_get(nrf_drv_uart_t const * p_instance)
{
uint32_t result = 0;
if (NRF_DRV_UART_USE_UARTE)
{
result = nrfx_uarte_errorsrc_get(&p_instance->uarte);
}
else if (NRF_DRV_UART_USE_UART)
{
nrf_uart_event_clear(p_instance->uart.p_reg, NRF_UART_EVENT_ERROR);
result = nrfx_uart_errorsrc_get(&p_instance->uart);
}
return result;
}
#endif // SUPPRESS_INLINE_IMPLEMENTATION
/** @} */
#ifdef __cplusplus
}
#endif
#endif // NRF_DRV_UART_H__