add nrfx to core
This commit is contained in:
1 parent
65a803bfb5
commit
3d462274a8
111 files changed
+91131
No files matched your search
@@ -0,0 +1,83 @@
|
||||
# Changelog
|
||||
All notable changes to this project are documented in this file.
|
||||
|
||||
## [Unreleased]
|
||||
### Fixed
|
||||
- Fixed starting TWIM TXRX transfer after preceding transfer was without stop condition.
|
||||
|
||||
## [1.1.0] - 2018-06-15
|
||||
### Added
|
||||
- Implemented workaround for nRF52832 and nRF52840 anomaly 194 in the I2S driver.
|
||||
- Implemented workaround for nRF52840 anomaly 195 in the SPIM driver.
|
||||
- Added HALs for CCM, ECB, and RADIO.
|
||||
- Extended HALs for GPIO, PPI, SAADC, and USBD.
|
||||
- Added support for external LFCLK sources.
|
||||
|
||||
### Changed
|
||||
- Corrected handling of transfer lengths in the TWI driver.
|
||||
- Updated MDK to version 8.17.0.
|
||||
|
||||
### Fixed
|
||||
- Fixed logging in the PPI driver.
|
||||
- Fixed SPIM interrupt definition for nRF52810.
|
||||
- Fixed Slave Select configuration in the SPIM driver.
|
||||
- Corrected default settings for NRF_SPIM3.
|
||||
- Fixed a typo in the UARTE TXDRDY event definition.
|
||||
- Corrected the TIMEOUT event clearing in the WDT interrupt handler.
|
||||
|
||||
## [1.0.0] - 2018-03-21
|
||||
### Added
|
||||
- Added the NRFX_WAIT_FOR macro to improve the time-out functionality in QSPI and SAADC drivers.
|
||||
- Added glue layer macros for checking and modifying the pending status of interrupts.
|
||||
- Added new enumeration values for interrupts and events in the UARTE HAL.
|
||||
- Implemented workarounds for nRF52 anomalies 192 and 201 in the CLOCK driver.
|
||||
- Implemented workaround for nRF52840 anomaly 122 in the QSPI driver.
|
||||
- Implemented workaround for nRF52840 anomaly 198 in the SPIM driver.
|
||||
|
||||
### Changed
|
||||
- Updated MDK to 8.16.0.
|
||||
- Extended input pin configuration in the GPIOTE driver.
|
||||
- Unified the way of checking if a required event handler was provided. Now, all drivers do it with assertions.
|
||||
- Changed the RNG bias correction configuration option to be enabled by default.
|
||||
- Refactored the ADC driver and HAL.
|
||||
- Corrected assertions in the TIMER driver to make it usable in debug version with PPI.
|
||||
- Improved buffer handling in the I2S driver. The API of the driver has been sligthly modified.
|
||||
- Enhanced SPIS driver API: added the "p_context" parameter, allowed NULL pointers for zero-length buffers.
|
||||
|
||||
### Fixed
|
||||
- Fixed result value casting in the TEMP HAL.
|
||||
- Fixed types of conversion result and buffer size in the ADC HAL and driver.
|
||||
- Fixed time-out in the SAADC driver in abort function.
|
||||
|
||||
## [0.8.0] - 2017-12-20
|
||||
### Added
|
||||
- Added XIP support in the QSPI driver.
|
||||
- Implemented Errata 132 in the CLOCK driver.
|
||||
- Added function for checking if a TIMER instance is enabled.
|
||||
- Added extended SPIM support.
|
||||
|
||||
### Changed
|
||||
- Updated MDK to 8.15.0. Introduced Segger Embedded Studio startup files.
|
||||
- Updated drivers: COMP, PWM, QDEC, SAADC, SPIS, TIMER, TWI, TWIS.
|
||||
- Changed the type used for transfer lengths to 'size_t' in drivers: SPI, SPIM, SPIS, TWI, TWIM, TWIS, UART, UARTE. Introduced checking of EasyDMA transfers limits.
|
||||
- Updated HALs: COMP, NVMC, UART, UARTE, USBD.
|
||||
- Updated template files and documentation of configuration options.
|
||||
|
||||
### Fixed
|
||||
- Fixed TWI and TWIM drivers so that they now support GPIOs from all ports.
|
||||
- Fixed definitions related to compare channels in the TIMER HAL.
|
||||
|
||||
### Removed
|
||||
- Removed the possibility of passing NULL instead of configuration to get default settings during drivers initialization.
|
||||
- Removed support for UART1 and PRS box #5.
|
||||
|
||||
## [0.7.0] - 2017-10-20
|
||||
### Added
|
||||
- This CHANGELOG.md file.
|
||||
- README.md file with simple description and explanations.
|
||||
- HAL for: ADC, CLOCK, COMP, ECB, EGU, GPIO, GPIOTE, I2S, LPCOMP, NVMC, PDM, POWER, PPI, PWM, QDEC, QSPI, RNG, RTC, SAADC, SPI, SPIM, SPIS, ARM(R) SysTick, TEMP, TIMER, TWI, TWIM, TWIS, UART, UARTE, USBD, WDT.
|
||||
- Drivers for: ADC, CLOCK, COMP, GPIOTE, I2S, LPCOMP, PDM, POWER, PWM, QDEC, QSPI, RNG, RTC, SAADC, SPI, SPIM, SPIS, ARM(R) SysTick, TIMER, TWI, TWIM, TWIS, UART, UARTE, WDT.
|
||||
- Allocators for: PPI, SWI/EGU.
|
||||
- MDK in version 8.14.0.
|
||||
- Offline documentation for every added driver and simple integration description.
|
||||
- Template integration files.
|
||||
@@ -0,0 +1,29 @@
|
||||
Copyright (c) 2017 - 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 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 the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from this
|
||||
software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
# nrfx
|
||||
|
||||
## Overview
|
||||
|
||||
nrfx is an extract from the nRF5 SDK that contains solely the drivers for
|
||||
peripherals present in Nordic SoCs, for convenience complemented with the MDK
|
||||
package containing required structures and bitfields definitions, startup
|
||||
files etc.
|
||||
|
||||
## Supported SoCs
|
||||
|
||||
* nRF51 Series
|
||||
* nRF52810
|
||||
* nRF52832
|
||||
* nRF52840
|
||||
|
||||
## Directories
|
||||
|
||||
```
|
||||
.
|
||||
├── doc # Project documentation files
|
||||
├── drivers # nrfx drivers files
|
||||
│ └── include # nrfx drivers headers
|
||||
│ └── src # nrfx drivers sources
|
||||
├── hal # Hardware Access Layer files
|
||||
├── mdk # Nordic MDK files
|
||||
├── soc # Nordic SoC related files
|
||||
└── templates # Templates of nrfx integration files
|
||||
```
|
||||
|
||||
## Generating documentation
|
||||
|
||||
nrfx documentation is availabe in the `doc\html` folder of the release package.
|
||||
|
||||
You can also generate documentation yourself from the source code. To do it, install doxygen
|
||||
and run one of the scripts: `generate_html_doc.bat` or `generate_html_doc.sh`. Generated
|
||||
documentation will be stored in the `doc\html` directory. Use `index.html` to open it.
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_BITMASK_H
|
||||
#define NRF_BITMASK_H
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_bitmask Bitmask module
|
||||
* @{
|
||||
* @ingroup nrfx
|
||||
* @brief Bitmask managing module.
|
||||
*/
|
||||
|
||||
#define BITMASK_BYTE_GET(abs_bit) ((abs_bit)/8)
|
||||
#define BITMASK_RELBIT_GET(abs_bit) ((abs_bit) & 0x00000007)
|
||||
|
||||
/**
|
||||
* Function for checking if bit in the multi-byte bit mask is set.
|
||||
*
|
||||
* @param bit Bit index.
|
||||
* @param p_mask A pointer to mask with bit fields.
|
||||
*
|
||||
* @return 0 if bit is not set, positive value otherwise.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_bitmask_bit_is_set(uint32_t bit, void const * p_mask)
|
||||
{
|
||||
uint8_t const * p_mask8 = (uint8_t const *)p_mask;
|
||||
uint32_t byte_idx = BITMASK_BYTE_GET(bit);
|
||||
bit = BITMASK_RELBIT_GET(bit);
|
||||
return (1 << bit) & p_mask8[byte_idx];
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for setting a bit in the multi-byte bit mask.
|
||||
*
|
||||
* @param bit Bit index.
|
||||
* @param p_mask A pointer to mask with bit fields.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_bitmask_bit_set(uint32_t bit, void * p_mask)
|
||||
{
|
||||
uint8_t * p_mask8 = (uint8_t *)p_mask;
|
||||
uint32_t byte_idx = BITMASK_BYTE_GET(bit);
|
||||
bit = BITMASK_RELBIT_GET(bit);
|
||||
p_mask8[byte_idx] |= (1 << bit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for clearing a bit in the multi-byte bit mask.
|
||||
*
|
||||
* @param bit Bit index.
|
||||
* @param p_mask A pointer to mask with bit fields.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_bitmask_bit_clear(uint32_t bit, void * p_mask)
|
||||
{
|
||||
uint8_t * p_mask8 = (uint8_t *)p_mask;
|
||||
uint32_t byte_idx = BITMASK_BYTE_GET(bit);
|
||||
bit = BITMASK_RELBIT_GET(bit);
|
||||
p_mask8[byte_idx] &= ~(1 << bit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for performing bitwise OR operation on two multi-byte bit masks.
|
||||
*
|
||||
* @param p_mask1 A pointer to the first bit mask.
|
||||
* @param p_mask2 A pointer to the second bit mask.
|
||||
* @param p_out_mask A pointer to the output bit mask.
|
||||
* @param length Length of output mask in bytes.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_bitmask_masks_or(void const * p_mask1,
|
||||
void const * p_mask2,
|
||||
void * p_out_mask,
|
||||
uint32_t length)
|
||||
{
|
||||
uint8_t const * p_mask8_1 = (uint8_t const *)p_mask1;
|
||||
uint8_t const * p_mask8_2 = (uint8_t const *)p_mask2;
|
||||
uint8_t * p_mask8_out = (uint8_t *)p_out_mask;
|
||||
uint32_t i;
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
p_mask8_out[i] = p_mask8_1[i] | p_mask8_2[i];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for performing bitwise AND operation on two multi-byte bit masks.
|
||||
*
|
||||
* @param p_mask1 A pointer to the first bit mask.
|
||||
* @param p_mask2 A pointer to the second bit mask.
|
||||
* @param p_out_mask A pointer to the output bit mask.
|
||||
* @param length Length of output mask in bytes.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_bitmask_masks_and(void const * p_mask1,
|
||||
void const * p_mask2,
|
||||
void * p_out_mask,
|
||||
uint32_t length)
|
||||
{
|
||||
uint8_t const * p_mask8_1 = (uint8_t const *)p_mask1;
|
||||
uint8_t const * p_mask8_2 = (uint8_t const *)p_mask2;
|
||||
uint8_t * p_mask8_out = (uint8_t *)p_out_mask;
|
||||
uint32_t i;
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
p_mask8_out[i] = p_mask8_1[i] & p_mask8_2[i];
|
||||
}
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_BITMASK_H
|
||||
@@ -0,0 +1,286 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 <nrfx.h>
|
||||
#include <hal/nrf_adc.h>
|
||||
|
||||
#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 Analog-to-digital converter driver DONE event.
|
||||
*/
|
||||
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 Analog-to-digital converter driver SAMPLE event.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrf_adc_value_t sample; ///< Converted sample.
|
||||
} nrfx_adc_sample_evt_t;
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter 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;
|
||||
} 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 \
|
||||
} \
|
||||
}
|
||||
|
||||
// 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 initial configuration.
|
||||
* @param[in] event_handler Event handler provided by the user.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If 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.
|
||||
*/
|
||||
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).
|
||||
*/
|
||||
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 should be placed. Unless NULL is
|
||||
* provided, the function is blocking.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If conversion was successful.
|
||||
* @retval NRFX_ERROR_BUSY If 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 If conversion was successful.
|
||||
* @retval NRFX_ERROR_BUSY If 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 If the ADC is busy.
|
||||
* @retval false If 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__
|
||||
@@ -0,0 +1,214 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_CLOCK_H__
|
||||
#define NRFX_CLOCK_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
#include <hal/nrf_clock.h>
|
||||
#include <nrfx_power_clock.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrfx_clock CLOCK driver
|
||||
* @{
|
||||
* @ingroup nrf_clock
|
||||
* @brief CLOCK peripheral driver.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Clock events.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRFX_CLOCK_EVT_HFCLK_STARTED, ///< HFCLK has been started.
|
||||
NRFX_CLOCK_EVT_LFCLK_STARTED, ///< LFCLK has been started.
|
||||
NRFX_CLOCK_EVT_CTTO, ///< Calibration timeout.
|
||||
NRFX_CLOCK_EVT_CAL_DONE ///< Calibration has been done.
|
||||
} nrfx_clock_evt_type_t;
|
||||
|
||||
/**
|
||||
* @brief Clock event handler.
|
||||
*
|
||||
* @param[in] event Event.
|
||||
*/
|
||||
typedef void (*nrfx_clock_event_handler_t)(nrfx_clock_evt_type_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for initializing internal structures in the nrfx_clock module.
|
||||
*
|
||||
* After initialization, the module is in power off state (clocks are not started).
|
||||
*
|
||||
* @param[in] event_handler Event handler provided by the user.
|
||||
* Must not be NULL.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the procedure was successful.
|
||||
* @retval NRFX_ERROR_ALREADY_INITIALIZED If the driver was already initialized.
|
||||
*/
|
||||
nrfx_err_t nrfx_clock_init(nrfx_clock_event_handler_t event_handler);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling interrupts in the clock module.
|
||||
*/
|
||||
void nrfx_clock_enable(void);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling interrupts in the clock module.
|
||||
*/
|
||||
void nrfx_clock_disable(void);
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing the clock module.
|
||||
*/
|
||||
void nrfx_clock_uninit(void);
|
||||
|
||||
/**
|
||||
* @brief Function for starting the LFCLK.
|
||||
*/
|
||||
void nrfx_clock_lfclk_start(void);
|
||||
|
||||
/**
|
||||
* @brief Function for stoping the LFCLK.
|
||||
*/
|
||||
void nrfx_clock_lfclk_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the LFCLK state.
|
||||
*
|
||||
* @retval true If the LFCLK is running.
|
||||
* @retval false If the LFCLK is not running.
|
||||
*/
|
||||
__STATIC_INLINE bool nrfx_clock_lfclk_is_running(void);
|
||||
|
||||
/**
|
||||
* @brief Function for starting the high-accuracy source HFCLK.
|
||||
*/
|
||||
void nrfx_clock_hfclk_start(void);
|
||||
|
||||
/**
|
||||
* @brief Function for stoping external high-accuracy source HFCLK.
|
||||
*/
|
||||
void nrfx_clock_hfclk_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the HFCLK state.
|
||||
*
|
||||
* @retval true If the HFCLK is running (XTAL source).
|
||||
* @retval false If the HFCLK is not running.
|
||||
*/
|
||||
__STATIC_INLINE bool nrfx_clock_hfclk_is_running(void);
|
||||
|
||||
/**
|
||||
* @brief Function for starting calibration of internal LFCLK.
|
||||
*
|
||||
* This function starts the calibration process. The process cannot be aborted. LFCLK and HFCLK
|
||||
* must be running before this function is called.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the procedure was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the low-frequency of high-frequency clock is off.
|
||||
* @retval NRFX_ERROR_BUSY If calibration is in progress.
|
||||
*/
|
||||
nrfx_err_t nrfx_clock_calibration_start(void);
|
||||
|
||||
/**
|
||||
* @brief Function for checking if calibration is in progress.
|
||||
*
|
||||
* This function indicates that the system is in calibration phase.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the procedure was successful.
|
||||
* @retval NRFX_ERROR_BUSY If calibration is in progress.
|
||||
*/
|
||||
nrfx_err_t nrfx_clock_is_calibrating(void);
|
||||
|
||||
/**
|
||||
* @brief Function for starting calibration timer.
|
||||
* @param interval Time after which the CTTO event and interrupt will be generated (in 0.25 s units).
|
||||
*/
|
||||
void nrfx_clock_calibration_timer_start(uint8_t interval);
|
||||
|
||||
/**
|
||||
* @brief Function for stoping calibration timer.
|
||||
*/
|
||||
void nrfx_clock_calibration_timer_stop(void);
|
||||
|
||||
/**@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 nrfx_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 nrfx_clock_ppi_event_addr(nrf_clock_event_t event);
|
||||
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
__STATIC_INLINE uint32_t nrfx_clock_ppi_task_addr(nrf_clock_task_t task)
|
||||
{
|
||||
return nrf_clock_task_address_get(task);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrfx_clock_ppi_event_addr(nrf_clock_event_t event)
|
||||
{
|
||||
return nrf_clock_event_address_get(event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrfx_clock_hfclk_is_running(void)
|
||||
{
|
||||
return nrf_clock_hf_is_running(NRF_CLOCK_HFCLK_HIGH_ACCURACY);
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrfx_clock_lfclk_is_running(void)
|
||||
{
|
||||
return nrf_clock_lf_is_running();
|
||||
}
|
||||
#endif //SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
|
||||
void nrfx_clock_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRFX_CLOCK_H__
|
||||
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 <nrfx.h>
|
||||
#include <hal/nrf_comp.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrfx_comp COMP driver
|
||||
* @{
|
||||
* @ingroup nrf_comp
|
||||
* @brief Comparator (COMP) peripheral driver.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Macro to convert 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, \
|
||||
.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, \
|
||||
.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 initial configuration.
|
||||
* @param[in] event_handler Event handler provided by the user.
|
||||
* Must not be NULL.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver has already been initialized.
|
||||
* @retval NRFX_ERROR_BUSY If 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 should be built as
|
||||
* 'or' of elements from @ref nrfx_comp_evt_en_mask_t.
|
||||
* @param[in] comp_shorts_mask Mask of shorts to be enabled. This parameter should be built as
|
||||
* '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 If the input voltage is below the threshold (VIN+ < VIN-).
|
||||
* @retval 1 If 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__
|
||||
@@ -0,0 +1,414 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_GPIOTE_H__
|
||||
#define NRFX_GPIOTE_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
#include <hal/nrf_gpiote.h>
|
||||
#include <hal/nrf_gpio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrfx_gpiote GPIOTE driver
|
||||
* @{
|
||||
* @ingroup nrf_gpiote
|
||||
* @brief GPIOTE peripheral driver.
|
||||
*/
|
||||
|
||||
/**@brief Input pin configuration. */
|
||||
typedef struct
|
||||
{
|
||||
nrf_gpiote_polarity_t sense; /**< Transition that triggers interrupt. */
|
||||
nrf_gpio_pin_pull_t pull; /**< Pulling mode. */
|
||||
bool is_watcher : 1; /**< True when the input pin is tracking an output pin. */
|
||||
bool hi_accuracy : 1; /**< True when high accuracy (IN_EVENT) is used. */
|
||||
bool skip_gpio_setup : 1; /**< Do not change GPIO configuration */
|
||||
} nrfx_gpiote_in_config_t;
|
||||
|
||||
/**@brief Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect low-to-high transition.
|
||||
* @details Set hi_accu to true to use IN_EVENT. */
|
||||
#define NRFX_GPIOTE_CONFIG_IN_SENSE_LOTOHI(hi_accu) \
|
||||
{ \
|
||||
.is_watcher = false, \
|
||||
.hi_accuracy = hi_accu, \
|
||||
.pull = NRF_GPIO_PIN_NOPULL, \
|
||||
.sense = NRF_GPIOTE_POLARITY_LOTOHI, \
|
||||
}
|
||||
|
||||
/**@brief Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect high-to-low transition.
|
||||
* @details Set hi_accu to true to use IN_EVENT. */
|
||||
#define NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(hi_accu) \
|
||||
{ \
|
||||
.is_watcher = false, \
|
||||
.hi_accuracy = hi_accu, \
|
||||
.pull = NRF_GPIO_PIN_NOPULL, \
|
||||
.sense = NRF_GPIOTE_POLARITY_HITOLO, \
|
||||
}
|
||||
|
||||
/**@brief Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect any change on the pin.
|
||||
* @details Set hi_accu to true to use IN_EVENT.*/
|
||||
#define NRFX_GPIOTE_CONFIG_IN_SENSE_TOGGLE(hi_accu) \
|
||||
{ \
|
||||
.is_watcher = false, \
|
||||
.hi_accuracy = hi_accu, \
|
||||
.pull = NRF_GPIO_PIN_NOPULL, \
|
||||
.sense = NRF_GPIOTE_POLARITY_TOGGLE, \
|
||||
}
|
||||
|
||||
/**@brief Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect low-to-high transition.
|
||||
* @details Set hi_accu to true to use IN_EVENT.
|
||||
* @note This macro prepares configuration that skips GPIO setup. */
|
||||
#define NRFX_GPIOTE_RAW_CONFIG_IN_SENSE_LOTOHI(hi_accu) \
|
||||
{ \
|
||||
.is_watcher = false, \
|
||||
.hi_accuracy = hi_accu, \
|
||||
.pull = NRF_GPIO_PIN_NOPULL, \
|
||||
.sense = NRF_GPIOTE_POLARITY_LOTOHI, \
|
||||
.skip_gpio_setup = true, \
|
||||
}
|
||||
|
||||
/**@brief Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect high-to-low transition.
|
||||
* @details Set hi_accu to true to use IN_EVENT.
|
||||
* @note This macro prepares configuration that skips GPIO setup. */
|
||||
#define NRFX_GPIOTE_RAW_CONFIG_IN_SENSE_HITOLO(hi_accu) \
|
||||
{ \
|
||||
.is_watcher = false, \
|
||||
.hi_accuracy = hi_accu, \
|
||||
.pull = NRF_GPIO_PIN_NOPULL, \
|
||||
.sense = NRF_GPIOTE_POLARITY_HITOLO, \
|
||||
.skip_gpio_setup = true, \
|
||||
}
|
||||
|
||||
/**@brief Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect any change on the pin.
|
||||
* @details Set hi_accu to true to use IN_EVENT.
|
||||
* @note This macro prepares configuration that skips GPIO setup. */
|
||||
#define NRFX_GPIOTE_RAW_CONFIG_IN_SENSE_TOGGLE(hi_accu) \
|
||||
{ \
|
||||
.is_watcher = false, \
|
||||
.hi_accuracy = hi_accu, \
|
||||
.pull = NRF_GPIO_PIN_NOPULL, \
|
||||
.sense = NRF_GPIOTE_POLARITY_TOGGLE, \
|
||||
.skip_gpio_setup = true, \
|
||||
}
|
||||
|
||||
|
||||
/**@brief Output pin configuration. */
|
||||
typedef struct
|
||||
{
|
||||
nrf_gpiote_polarity_t action; /**< Configuration of the pin task. */
|
||||
nrf_gpiote_outinit_t init_state; /**< Initial state of the output pin. */
|
||||
bool task_pin; /**< True if the pin is controlled by a GPIOTE task. */
|
||||
} nrfx_gpiote_out_config_t;
|
||||
|
||||
/**@brief Macro for configuring a pin to use as output. GPIOTE is not used for the pin. */
|
||||
#define NRFX_GPIOTE_CONFIG_OUT_SIMPLE(init_high) \
|
||||
{ \
|
||||
.init_state = init_high ? NRF_GPIOTE_INITIAL_VALUE_HIGH : NRF_GPIOTE_INITIAL_VALUE_LOW, \
|
||||
.task_pin = false, \
|
||||
}
|
||||
|
||||
/**@brief Macro for configuring a pin to use the GPIO OUT TASK to change the state from high to low.
|
||||
* @details The task will clear the pin. Therefore, the pin is set initially. */
|
||||
#define NRFX_GPIOTE_CONFIG_OUT_TASK_LOW \
|
||||
{ \
|
||||
.init_state = NRF_GPIOTE_INITIAL_VALUE_HIGH, \
|
||||
.task_pin = true, \
|
||||
.action = NRF_GPIOTE_POLARITY_HITOLO, \
|
||||
}
|
||||
|
||||
/**@brief Macro for configuring a pin to use the GPIO OUT TASK to change the state from low to high.
|
||||
* @details The task will set the pin. Therefore, the pin is cleared initially. */
|
||||
#define NRFX_GPIOTE_CONFIG_OUT_TASK_HIGH \
|
||||
{ \
|
||||
.init_state = NRF_GPIOTE_INITIAL_VALUE_LOW, \
|
||||
.task_pin = true, \
|
||||
.action = NRF_GPIOTE_POLARITY_LOTOHI, \
|
||||
}
|
||||
|
||||
/**@brief Macro for configuring a pin to use the GPIO OUT TASK to toggle the pin state.
|
||||
* @details The initial pin state must be provided. */
|
||||
#define NRFX_GPIOTE_CONFIG_OUT_TASK_TOGGLE(init_high) \
|
||||
{ \
|
||||
.init_state = init_high ? NRF_GPIOTE_INITIAL_VALUE_HIGH : NRF_GPIOTE_INITIAL_VALUE_LOW, \
|
||||
.task_pin = true, \
|
||||
.action = NRF_GPIOTE_POLARITY_TOGGLE, \
|
||||
}
|
||||
|
||||
/** @brief Pin. */
|
||||
typedef uint32_t nrfx_gpiote_pin_t;
|
||||
|
||||
/**
|
||||
* @brief Pin event handler prototype.
|
||||
*
|
||||
* @param pin Pin that triggered this event.
|
||||
* @param action Action that lead to triggering this event.
|
||||
*/
|
||||
typedef void (*nrfx_gpiote_evt_handler_t)(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action);
|
||||
|
||||
/**
|
||||
* @brief Function for initializing the GPIOTE module.
|
||||
*
|
||||
* @details Only static configuration is supported to prevent the shared
|
||||
* resource being customized by the initiator.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver was already initialized.
|
||||
*/
|
||||
nrfx_err_t nrfx_gpiote_init(void);
|
||||
|
||||
/**
|
||||
* @brief Function for checking if the GPIOTE module is initialized.
|
||||
*
|
||||
* @details The GPIOTE module is a shared module. Therefore, you should check if
|
||||
* the module is already initialized and skip initialization if it is.
|
||||
*
|
||||
* @retval true If the module is already initialized.
|
||||
* @retval false If the module is not initialized.
|
||||
*/
|
||||
bool nrfx_gpiote_is_init(void);
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing the GPIOTE module.
|
||||
*/
|
||||
void nrfx_gpiote_uninit(void);
|
||||
|
||||
/**
|
||||
* @brief Function for initializing a GPIOTE output pin.
|
||||
* @details The output pin can be controlled by the CPU or by PPI. The initial
|
||||
* configuration specifies which mode is used. If PPI mode is used, the driver
|
||||
* attempts to allocate one of the available GPIOTE channels. If no channel is
|
||||
* available, an error is returned.
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
* @param[in] p_config Initial configuration.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver is not initialized or the pin is already used.
|
||||
* @retval NRFX_ERROR_NO_MEM If no GPIOTE channel is available.
|
||||
*/
|
||||
nrfx_err_t nrfx_gpiote_out_init(nrfx_gpiote_pin_t pin,
|
||||
nrfx_gpiote_out_config_t const * p_config);
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing a GPIOTE output pin.
|
||||
* @details The driver frees the GPIOTE channel if the output pin was using one.
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
*/
|
||||
void nrfx_gpiote_out_uninit(nrfx_gpiote_pin_t pin);
|
||||
|
||||
/**
|
||||
* @brief Function for setting a GPIOTE output pin.
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
*/
|
||||
void nrfx_gpiote_out_set(nrfx_gpiote_pin_t pin);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a GPIOTE output pin.
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
*/
|
||||
void nrfx_gpiote_out_clear(nrfx_gpiote_pin_t pin);
|
||||
|
||||
/**
|
||||
* @brief Function for toggling a GPIOTE output pin.
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
*/
|
||||
void nrfx_gpiote_out_toggle(nrfx_gpiote_pin_t pin);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling a GPIOTE output pin task.
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
*/
|
||||
void nrfx_gpiote_out_task_enable(nrfx_gpiote_pin_t pin);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling a GPIOTE output pin task.
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
*/
|
||||
void nrfx_gpiote_out_task_disable(nrfx_gpiote_pin_t pin);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a configurable GPIOTE task.
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
*
|
||||
* @return Address of OUT task.
|
||||
*/
|
||||
uint32_t nrfx_gpiote_out_task_addr_get(nrfx_gpiote_pin_t pin);
|
||||
|
||||
#if defined(GPIOTE_FEATURE_SET_PRESENT) || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Function for getting the address of a configurable GPIOTE task.
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
*
|
||||
* @return Address of SET task.
|
||||
*/
|
||||
uint32_t nrfx_gpiote_set_task_addr_get(nrfx_gpiote_pin_t pin);
|
||||
#endif // defined(GPIOTE_FEATURE_SET_PRESENT) || defined(__NRFX_DOXYGEN__)
|
||||
|
||||
#if defined(GPIOTE_FEATURE_CLR_PRESENT) || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Function for getting the address of a configurable GPIOTE task.
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
*
|
||||
* @return Address of CLR task.
|
||||
*/
|
||||
uint32_t nrfx_gpiote_clr_task_addr_get(nrfx_gpiote_pin_t pin);
|
||||
#endif // defined(GPIOTE_FEATURE_CLR_PRESENT) || defined(__NRFX_DOXYGEN__)
|
||||
|
||||
/**
|
||||
* @brief Function for initializing a GPIOTE input pin.
|
||||
* @details The input pin can act in two ways:
|
||||
* - lower accuracy but low power (high frequency clock not needed)
|
||||
* - higher accuracy (high frequency clock required)
|
||||
*
|
||||
* The initial configuration specifies which mode is used.
|
||||
* If high-accuracy mode is used, the driver attempts to allocate one
|
||||
* of the available GPIOTE channels. If no channel is
|
||||
* available, an error is returned.
|
||||
* In low accuracy mode SENSE feature is used. In this case only one active pin
|
||||
* can be detected at a time. It can be worked around by setting all of the used
|
||||
* low accuracy pins to toggle mode.
|
||||
* For more information about SENSE functionality, refer to Product Specification.
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
* @param[in] p_config Initial configuration.
|
||||
* @param[in] evt_handler User function to be called when the configured transition occurs.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver is not initialized or the pin is already used.
|
||||
* @retval NRFX_ERROR_NO_MEM If no GPIOTE channel is available.
|
||||
*/
|
||||
nrfx_err_t nrfx_gpiote_in_init(nrfx_gpiote_pin_t pin,
|
||||
nrfx_gpiote_in_config_t const * p_config,
|
||||
nrfx_gpiote_evt_handler_t evt_handler);
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing a GPIOTE input pin.
|
||||
* @details The driver frees the GPIOTE channel if the input pin was using one.
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
*/
|
||||
void nrfx_gpiote_in_uninit(nrfx_gpiote_pin_t pin);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling sensing of a GPIOTE input pin.
|
||||
*
|
||||
* @details If the input pin is configured as high-accuracy pin, the function
|
||||
* enables an IN_EVENT. Otherwise, the function enables the GPIO sense mechanism.
|
||||
* Note that a PORT event is shared between multiple pins, therefore the
|
||||
* interrupt is always enabled.
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
* @param[in] int_enable True to enable the interrupt. Always valid for a high-accuracy pin.
|
||||
*/
|
||||
void nrfx_gpiote_in_event_enable(nrfx_gpiote_pin_t pin, bool int_enable);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling a GPIOTE input pin.
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
*/
|
||||
void nrfx_gpiote_in_event_disable(nrfx_gpiote_pin_t pin);
|
||||
|
||||
/**
|
||||
* @brief Function for checking if a GPIOTE input pin is set.
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
*
|
||||
* @retval true If the input pin is set.
|
||||
* @retval false If the input pin is not set.
|
||||
*/
|
||||
bool nrfx_gpiote_in_is_set(nrfx_gpiote_pin_t pin);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a GPIOTE input pin event.
|
||||
* @details If the pin is configured to use low-accuracy mode, the address of the PORT event is returned.
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
*/
|
||||
uint32_t nrfx_gpiote_in_event_addr_get(nrfx_gpiote_pin_t pin);
|
||||
|
||||
/**
|
||||
* @brief Function for forcing a specific state on the pin configured as task.
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
* @param[in] state Pin state.
|
||||
*/
|
||||
void nrfx_gpiote_out_task_force(nrfx_gpiote_pin_t pin, uint8_t state);
|
||||
|
||||
/**
|
||||
* @brief Function for triggering the task OUT manually.
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
*/
|
||||
void nrfx_gpiote_out_task_trigger(nrfx_gpiote_pin_t pin);
|
||||
|
||||
#if defined(GPIOTE_FEATURE_SET_PRESENT) || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Function for triggering the task SET manually.
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
*/
|
||||
void nrfx_gpiote_set_task_trigger(nrfx_gpiote_pin_t pin);
|
||||
#endif // defined(GPIOTE_FEATURE_SET_PRESENT) || defined(__NRFX_DOXYGEN__)
|
||||
|
||||
#if defined(GPIOTE_FEATURE_CLR_PRESENT) || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Function for triggering the task CLR manually.
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
*/
|
||||
void nrfx_gpiote_clr_task_trigger(nrfx_gpiote_pin_t pin);
|
||||
#endif // defined(GPIOTE_FEATURE_CLR_PRESENT) || defined(__NRFX_DOXYGEN__)
|
||||
|
||||
|
||||
void nrfx_gpiote_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRFX_GPIOTE_H__
|
||||
@@ -0,0 +1,245 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 <nrfx.h>
|
||||
#include <hal/nrf_i2s.h>
|
||||
|
||||
#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;
|
||||
uint32_t const * p_tx_buffer;
|
||||
} 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 should provide buffers that are to be used in the next
|
||||
* part of the transfer. A call to @ref nrfx_i2s_next_buffers_set should
|
||||
* be done before the currently used buffers are completely processed
|
||||
* (i.e. 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 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 (i.e. buffers pointers)
|
||||
* should 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 access 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 initial configuration.
|
||||
* @param[in] handler Data handler provided by the user. Must not be NULL.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver was already initialized.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If 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
|
||||
* should 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 If the operation was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If a transfer was already started or
|
||||
* the driver has not been initialized.
|
||||
* @retval NRFX_ERROR_INVALID_ADDR If 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 should 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__
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 <nrfx.h>
|
||||
#include <hal/nrf_lpcomp.h>
|
||||
|
||||
#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 initial configuration.
|
||||
* @param[in] event_handler Event handler provided by the user.
|
||||
* Must not be NULL.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver has already been initialized.
|
||||
* @retval NRFX_ERROR_BUSY If 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__
|
||||
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 <nrfx.h>
|
||||
#include <hal/nrf_pdm.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrfx_pdm PDM driver
|
||||
* @{
|
||||
* @ingroup nrf_pdm
|
||||
* @brief Pulse Density Modulation (PDM) peripheral driver.
|
||||
*/
|
||||
|
||||
|
||||
#define NRFX_PDM_MAX_BUFFER_SIZE 32767
|
||||
|
||||
|
||||
/**
|
||||
* @brief PDM error type.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRFX_PDM_NO_ERROR = 0,
|
||||
NRFX_PDM_ERROR_OVERFLOW = 1
|
||||
} 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 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 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 initial configuration.
|
||||
* @param[in] event_handler Event handler provided by the user. Cannot be NULL.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver is already initialized.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If 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 If the PDM interface is enabled.
|
||||
* @retval false If the PDM interface is disabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrfx_pdm_enable_check(void)
|
||||
{
|
||||
return nrf_pdm_enable_check();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function for starting PDM sampling.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If sampling was started successfully or was already in progress.
|
||||
* @retval NRFX_ERROR_BUSY If a previous start/stop operation is in progress.
|
||||
*/
|
||||
nrfx_err_t nrfx_pdm_start(void);
|
||||
|
||||
/**
|
||||
* @brief Function for stopping 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 If sampling was stopped successfully or was already stopped before.
|
||||
* @retval NRFX_ERROR_BUSY If a 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 If the buffer was applied successfully.
|
||||
* @retval NRFX_ERROR_BUSY If the buffer was already supplied or the peripheral is currently being stopped.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver was not initialized.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If 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__
|
||||
@@ -0,0 +1,373 @@
|
||||
/*
|
||||
* Copyright (c) 2017 - 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_POWER_H__
|
||||
#define NRFX_POWER_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
#include <hal/nrf_power.h>
|
||||
#include <nrfx_power_clock.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrfx_power POWER driver
|
||||
* @{
|
||||
* @ingroup nrf_power
|
||||
* @brief POWER peripheral driver.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Power mode possible configurations
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRFX_POWER_MODE_CONSTLAT, /**< Constant latency mode */
|
||||
NRFX_POWER_MODE_LOWPWR /**< Low power mode */
|
||||
}nrfx_power_mode_t;
|
||||
|
||||
#if NRF_POWER_HAS_SLEEPEVT || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Events from power system
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRFX_POWER_SLEEP_EVT_ENTER, /**< CPU entered WFI/WFE sleep
|
||||
*
|
||||
* Keep in mind that if this interrupt is enabled,
|
||||
* it means that CPU was waken up just after WFI by this interrupt.
|
||||
*/
|
||||
NRFX_POWER_SLEEP_EVT_EXIT /**< CPU exited WFI/WFE sleep */
|
||||
}nrfx_power_sleep_evt_t;
|
||||
#endif /* NRF_POWER_HAS_SLEEPEVT */
|
||||
|
||||
#if NRF_POWER_HAS_USBREG || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Events from USB power system
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRFX_POWER_USB_EVT_DETECTED, /**< USB power detected on the connector (plugged in). */
|
||||
NRFX_POWER_USB_EVT_REMOVED, /**< USB power removed from the connector. */
|
||||
NRFX_POWER_USB_EVT_READY /**< USB power regulator ready. */
|
||||
}nrfx_power_usb_evt_t;
|
||||
|
||||
/**
|
||||
* @brief USB power state
|
||||
*
|
||||
* The single enumerator that holds all data about current state of USB
|
||||
* related POWER.
|
||||
*
|
||||
* Organized this way that higher power state has higher numeric value
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRFX_POWER_USB_STATE_DISCONNECTED, /**< No power on USB lines detected */
|
||||
NRFX_POWER_USB_STATE_CONNECTED, /**< The USB power is detected, but USB power regulator is not ready */
|
||||
NRFX_POWER_USB_STATE_READY /**< From the power point of view USB is ready for working */
|
||||
}nrfx_power_usb_state_t;
|
||||
#endif /* NRF_POWER_HAS_USBREG */
|
||||
|
||||
/**
|
||||
* @name Callback types
|
||||
*
|
||||
* Defined types of callback functions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Event handler for power failure warning
|
||||
*/
|
||||
typedef void (*nrfx_power_pofwarn_event_handler_t)(void);
|
||||
|
||||
#if NRF_POWER_HAS_SLEEPEVT || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Event handler for entering/exiting sleep
|
||||
*
|
||||
* @param event Event type
|
||||
*/
|
||||
typedef void (*nrfx_power_sleep_event_handler_t)(nrfx_power_sleep_evt_t event);
|
||||
#endif
|
||||
|
||||
#if NRF_POWER_HAS_USBREG || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Event handler for USB related power events
|
||||
*
|
||||
* @param event Event type
|
||||
*/
|
||||
typedef void (*nrfx_power_usb_event_handler_t)(nrfx_power_usb_evt_t event);
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @brief General power configuration
|
||||
*
|
||||
* Parameters required to initialize power driver.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/**
|
||||
* @brief Enable main DCDC regulator
|
||||
*
|
||||
* This bit only informs the driver that elements for DCDC regulator
|
||||
* are installed and regulator can be used.
|
||||
* The regulator would be enabled or disabled automatically
|
||||
* by the hardware, basing on current power requirement.
|
||||
*/
|
||||
bool dcdcen:1;
|
||||
|
||||
#if NRF_POWER_HAS_VDDH || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Enable HV DCDC regulator
|
||||
*
|
||||
* This bit only informs the driver that elements for DCDC regulator
|
||||
* are installed and regulator can be used.
|
||||
* The regulator would be enabled or disabled automatically
|
||||
* by the hardware, basing on current power requirement.
|
||||
*/
|
||||
bool dcdcenhv: 1;
|
||||
#endif
|
||||
}nrfx_power_config_t;
|
||||
|
||||
/**
|
||||
* @brief The configuration for power failure comparator
|
||||
*
|
||||
* Configuration used to enable and configure power failure comparator
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrfx_power_pofwarn_event_handler_t handler; //!< Event handler
|
||||
nrf_power_pof_thr_t thr; //!< Threshold for power failure detection
|
||||
#if NRF_POWER_HAS_VDDH || defined(__NRFX_DOXYGEN__)
|
||||
nrf_power_pof_thrvddh_t thrvddh; //!< Threshold for power failure detection on VDDH pin
|
||||
#endif
|
||||
}nrfx_power_pofwarn_config_t;
|
||||
|
||||
#if NRF_POWER_HAS_SLEEPEVT || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief The configuration of sleep event processing
|
||||
*
|
||||
* Configuration used to enable and configure sleep event handling
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrfx_power_sleep_event_handler_t handler; //!< Event handler
|
||||
bool en_enter:1; //!< Enable event on sleep entering
|
||||
bool en_exit :1; //!< Enable event on sleep exiting
|
||||
}nrfx_power_sleepevt_config_t;
|
||||
#endif
|
||||
|
||||
#if NRF_POWER_HAS_USBREG || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief The configuration of USB related power events
|
||||
*
|
||||
* Configuration used to enable and configure USB power event handling
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrfx_power_usb_event_handler_t handler; //!< Event processing
|
||||
}nrfx_power_usbevt_config_t;
|
||||
#endif /* NRF_POWER_HAS_USBREG */
|
||||
|
||||
/**
|
||||
* @brief Function for getting the handler of the power failure comparator.
|
||||
* @return Handler of the power failure comparator.
|
||||
*/
|
||||
nrfx_power_pofwarn_event_handler_t nrfx_power_pof_handler_get(void);
|
||||
|
||||
#if NRF_POWER_HAS_USBREG || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Function for getting the handler of the USB power.
|
||||
* @return Handler of the USB power.
|
||||
*/
|
||||
nrfx_power_usb_event_handler_t nrfx_power_usb_handler_get(void);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Initialize power module driver
|
||||
*
|
||||
* Enabled power module driver would process all the interrupts from power system.
|
||||
*
|
||||
* @param[in] p_config Pointer to the structure with initial configuration.
|
||||
*
|
||||
* @retval NRFX_SUCCESS Successfully initialized.
|
||||
* @retval NRFX_ERROR_ALREADY_INITIALIZED Module was already initialized.
|
||||
*/
|
||||
nrfx_err_t nrfx_power_init(nrfx_power_config_t const * p_config);
|
||||
|
||||
/**
|
||||
* @brief Unintialize power module driver
|
||||
*
|
||||
* Disables all the interrupt handling in the module.
|
||||
*
|
||||
* @sa nrfx_power_init
|
||||
*/
|
||||
void nrfx_power_uninit(void);
|
||||
|
||||
/**
|
||||
* @brief Initialize power failure comparator
|
||||
*
|
||||
* Configures the power failure comparator. This function does not setup and enable it.
|
||||
* Those steps can be done with functions @ref nrfx_power_pof_enable and @ref nrfx_power_pof_disable
|
||||
* or with Softdevice API (when Softdevice is using).
|
||||
*
|
||||
* @param[in] p_config Configuration with values and event handler.
|
||||
* If event handler is set to NULL, interrupt would be disabled.
|
||||
*/
|
||||
void nrfx_power_pof_init(nrfx_power_pofwarn_config_t const * p_config);
|
||||
|
||||
/**
|
||||
* @brief Enable power failure comparator
|
||||
* Sets and enables interrupt of the power failure comparator. This functions cannot be using
|
||||
* when Softdevice is enabled. If event handler set in init function is set to NULL, interrupt
|
||||
* would be disabled.
|
||||
*
|
||||
* @param[in] p_config Configuration with values and event handler.
|
||||
*/
|
||||
void nrfx_power_pof_enable(nrfx_power_pofwarn_config_t const * p_config);
|
||||
|
||||
/**
|
||||
* @brief Disable the power failure comparator
|
||||
*
|
||||
* Disables the power failure comparator interrupt.
|
||||
*/
|
||||
void nrfx_power_pof_disable(void);
|
||||
|
||||
/**
|
||||
* @brief Clear the power failure comparator settings
|
||||
*
|
||||
* Clears the settings of the power failure comparator.
|
||||
*/
|
||||
void nrfx_power_pof_uninit(void);
|
||||
|
||||
#if NRF_POWER_HAS_SLEEPEVT || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Initialize sleep entering and exiting events processing
|
||||
*
|
||||
* Configures and setups the sleep event processing.
|
||||
*
|
||||
* @param[in] p_config Configuration with values and event handler.
|
||||
*
|
||||
* @sa nrfx_power_sleepevt_uninit
|
||||
*
|
||||
*/
|
||||
void nrfx_power_sleepevt_init(nrfx_power_sleepevt_config_t const * p_config);
|
||||
|
||||
/**
|
||||
* @brief Enable sleep entering and exiting events processing
|
||||
*
|
||||
* @param[in] p_config Configuration with values and event handler.
|
||||
*/
|
||||
void nrfx_power_sleepevt_enable(nrfx_power_sleepevt_config_t const * p_config);
|
||||
|
||||
/**
|
||||
* @brief Disable sleep entering and exiting events processing
|
||||
*/
|
||||
void nrfx_power_sleepevt_disable(void);
|
||||
|
||||
/**
|
||||
* @brief Uninitialize sleep entering and exiting events processing
|
||||
*
|
||||
* @sa nrfx_power_sleepevt_init
|
||||
*/
|
||||
void nrfx_power_sleepevt_uninit(void);
|
||||
#endif /* NRF_POWER_HAS_SLEEPEVT */
|
||||
|
||||
#if NRF_POWER_HAS_USBREG || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Initialize USB power event processing
|
||||
*
|
||||
* Configures and setups the USB power event processing.
|
||||
*
|
||||
* @param[in] p_config Configuration with values and event handler.
|
||||
*
|
||||
* @sa nrfx_power_usbevt_uninit
|
||||
*/
|
||||
void nrfx_power_usbevt_init(nrfx_power_usbevt_config_t const * p_config);
|
||||
|
||||
/**
|
||||
* @brief Enable USB power event processing
|
||||
*/
|
||||
void nrfx_power_usbevt_enable(void);
|
||||
|
||||
/**
|
||||
* @brief Disable USB power event processing
|
||||
*/
|
||||
void nrfx_power_usbevt_disable(void);
|
||||
|
||||
/**
|
||||
* @brief Uninitalize USB power event processing
|
||||
*
|
||||
* @sa nrfx_power_usbevt_init
|
||||
*/
|
||||
void nrfx_power_usbevt_uninit(void);
|
||||
|
||||
/**
|
||||
* @brief Get the status of USB power
|
||||
*
|
||||
* @return Current USB power status
|
||||
*/
|
||||
__STATIC_INLINE nrfx_power_usb_state_t nrfx_power_usbstatus_get(void);
|
||||
|
||||
#endif /* NRF_POWER_HAS_USBREG */
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
#if NRF_POWER_HAS_USBREG
|
||||
__STATIC_INLINE nrfx_power_usb_state_t nrfx_power_usbstatus_get(void)
|
||||
{
|
||||
uint32_t status = nrf_power_usbregstatus_get();
|
||||
if(0 == (status & NRF_POWER_USBREGSTATUS_VBUSDETECT_MASK))
|
||||
{
|
||||
return NRFX_POWER_USB_STATE_DISCONNECTED;
|
||||
}
|
||||
if(0 == (status & NRF_POWER_USBREGSTATUS_OUTPUTRDY_MASK))
|
||||
{
|
||||
return NRFX_POWER_USB_STATE_CONNECTED;
|
||||
}
|
||||
return NRFX_POWER_USB_STATE_READY;
|
||||
}
|
||||
#endif /* NRF_POWER_HAS_USBREG */
|
||||
|
||||
#endif /* SUPPRESS_INLINE_IMPLEMENTATION */
|
||||
|
||||
|
||||
void nrfx_power_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRFX_POWER_H__ */
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_POWER_CLOCK_H__
|
||||
#define NRFX_POWER_CLOCK_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
__STATIC_INLINE void nrfx_power_clock_irq_init(void);
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
__STATIC_INLINE void nrfx_power_clock_irq_init(void)
|
||||
{
|
||||
uint8_t priority;
|
||||
#if NRFX_CHECK(NRFX_POWER_ENABLED) && NRFX_CHECK(NRFX_CLOCK_ENABLED)
|
||||
#if NRFX_POWER_CONFIG_IRQ_PRIORITY != NRFX_CLOCK_CONFIG_IRQ_PRIORITY
|
||||
#error "IRQ priority for POWER and CLOCK have to be the same. Check <nrfx_config.h>."
|
||||
#endif
|
||||
priority = NRFX_POWER_CONFIG_IRQ_PRIORITY;
|
||||
#elif NRFX_CHECK(NRFX_POWER_ENABLED)
|
||||
priority = NRFX_POWER_CONFIG_IRQ_PRIORITY;
|
||||
#elif NRFX_CHECK(NRFX_CLOCK_ENABLED)
|
||||
priority = NRFX_CLOCK_CONFIG_IRQ_PRIORITY;
|
||||
#endif
|
||||
|
||||
if (!NRFX_IRQ_IS_ENABLED(POWER_CLOCK_IRQn))
|
||||
{
|
||||
NRFX_IRQ_PRIORITY_SET(POWER_CLOCK_IRQn, priority);
|
||||
NRFX_IRQ_ENABLE(POWER_CLOCK_IRQn);
|
||||
}
|
||||
}
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
|
||||
#if NRFX_CHECK(NRFX_POWER_ENABLED) && NRFX_CHECK(NRFX_CLOCK_ENABLED)
|
||||
void nrfx_power_clock_irq_handler(void);
|
||||
#elif NRFX_CHECK(NRFX_POWER_ENABLED)
|
||||
#define nrfx_power_irq_handler nrfx_power_clock_irq_handler
|
||||
#elif NRFX_CHECK(NRFX_CLOCK_ENABLED)
|
||||
#define nrfx_clock_irq_handler nrfx_power_clock_irq_handler
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRFX_POWER_CLOCK_H__
|
||||
@@ -0,0 +1,318 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_PPI_H__
|
||||
#define NRFX_PPI_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
#include <hal/nrf_ppi.h>
|
||||
|
||||
/**
|
||||
* @defgroup nrfx_ppi PPI allocator
|
||||
* @{
|
||||
* @ingroup nrf_ppi
|
||||
* @brief Programmable Peripheral Interconnect (PPI) allocator.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef NRFX_PPI_CHANNELS_USED
|
||||
#define NRFX_PPI_CHANNELS_USED 0
|
||||
#endif
|
||||
|
||||
#ifndef NRFX_PPI_GROUPS_USED
|
||||
#define NRFX_PPI_GROUPS_USED 0
|
||||
#endif
|
||||
|
||||
#if PPI_CH_NUM > 16
|
||||
#define NRFX_PPI_ALL_APP_CHANNELS_MASK ((uint32_t)0xFFFFFFFFuL & ~(NRFX_PPI_CHANNELS_USED)) /**< All PPI channels available to the application. */
|
||||
#define NRFX_PPI_PROG_APP_CHANNELS_MASK ((uint32_t)0x000FFFFFuL & ~(NRFX_PPI_CHANNELS_USED)) /**< Programmable PPI channels available to the application. */
|
||||
#else
|
||||
#define NRFX_PPI_ALL_APP_CHANNELS_MASK ((uint32_t)0xFFF0FFFFuL & ~(NRFX_PPI_CHANNELS_USED)) /**< All PPI channels available to the application. */
|
||||
#define NRFX_PPI_PROG_APP_CHANNELS_MASK ((uint32_t)0x0000FFFFuL & ~(NRFX_PPI_CHANNELS_USED)) /**< Programmable PPI channels available to the application. */
|
||||
#endif
|
||||
|
||||
#define NRFX_PPI_ALL_APP_GROUPS_MASK (((1uL << PPI_GROUP_NUM) - 1) & ~(NRFX_PPI_GROUPS_USED)) /**< All PPI groups available to the application. */
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing the PPI module.
|
||||
*
|
||||
* This function disables all channels and clears the channel groups.
|
||||
*/
|
||||
void nrfx_ppi_free_all(void);
|
||||
|
||||
/**
|
||||
* @brief Function for allocating a PPI channel.
|
||||
* @details This function allocates the first unused PPI channel.
|
||||
*
|
||||
* @param[out] p_channel Pointer to the PPI channel that has been allocated.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully allocated.
|
||||
* @retval NRFX_ERROR_NO_MEM If there is no available channel to be used.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_channel_alloc(nrf_ppi_channel_t * p_channel);
|
||||
|
||||
/**
|
||||
* @brief Function for freeing a PPI channel.
|
||||
* @details This function also disables the chosen channel.
|
||||
*
|
||||
* @param[in] channel PPI channel to be freed.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully freed.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the channel is not user-configurable.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_channel_free(nrf_ppi_channel_t channel);
|
||||
|
||||
/**
|
||||
* @brief Function for assigning task and event endpoints to the PPI channel.
|
||||
*
|
||||
* @param[in] channel PPI channel to be assigned endpoints.
|
||||
* @param[in] eep Event endpoint address.
|
||||
* @param[in] tep Task endpoint address.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully assigned.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the channel is not allocated for the user.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the channel is not user-configurable.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_channel_assign(nrf_ppi_channel_t channel, uint32_t eep, uint32_t tep);
|
||||
|
||||
/**
|
||||
* @brief Function for assigning or clearing fork endpoint to the PPI channel.
|
||||
*
|
||||
* @param[in] channel PPI channel to be assigned endpoints.
|
||||
* @param[in] fork_tep Fork task endpoint address or 0 to clear.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully assigned.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the channel is not allocated for the user.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the channel is not user-configurable.
|
||||
* @retval NRFX_ERROR_NOT_SUPPORTED If function is not supported.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_channel_fork_assign(nrf_ppi_channel_t channel, uint32_t fork_tep);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling a PPI channel.
|
||||
*
|
||||
* @param[in] channel PPI channel to be enabled.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully enabled.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the user-configurable channel is not allocated.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the channel cannot be enabled by the user.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_channel_enable(nrf_ppi_channel_t channel);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling a PPI channel.
|
||||
*
|
||||
* @param[in] channel PPI channel to be disabled.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully disabled.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the user-configurable channel is not allocated.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the channel cannot be disabled by the user.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_channel_disable(nrf_ppi_channel_t channel);
|
||||
|
||||
/**
|
||||
* @brief Function for allocating a PPI channel group.
|
||||
* @details This function allocates the first unused PPI group.
|
||||
*
|
||||
* @param[out] p_group Pointer to the PPI channel group that has been allocated.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel group was successfully allocated.
|
||||
* @retval NRFX_ERROR_NO_MEM If there is no available channel group to be used.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_group_alloc(nrf_ppi_channel_group_t * p_group);
|
||||
|
||||
/**
|
||||
* @brief Function for freeing a PPI channel group.
|
||||
* @details This function also disables the chosen group.
|
||||
*
|
||||
* @param[in] group PPI channel group to be freed.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel group was successfully freed.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the channel group is not user-configurable.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_group_free(nrf_ppi_channel_group_t group);
|
||||
|
||||
/**
|
||||
* @brief Compute a channel mask for NRF_PPI registers.
|
||||
*
|
||||
* @param[in] channel Channel number to transform to a mask.
|
||||
*
|
||||
* @retval Channel mask.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_ppi_channel_to_mask(nrf_ppi_channel_t channel)
|
||||
{
|
||||
return (1uL << (uint32_t) channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function for including multiple PPI channels in a channel group.
|
||||
*
|
||||
* @param[in] channel_mask PPI channels to be added.
|
||||
* @param[in] group Channel group in which to include the channels.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channels was successfully included.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If group is not an application group or channels are not an
|
||||
* application channels.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If group is not an allocated group.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_channels_include_in_group(uint32_t channel_mask,
|
||||
nrf_ppi_channel_group_t group);
|
||||
|
||||
/**
|
||||
* @brief Function for including a PPI channel in a channel group.
|
||||
*
|
||||
* @param[in] channel PPI channel to be added.
|
||||
* @param[in] group Channel group in which to include the channel.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully included.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If group is not an application group or channel is not an
|
||||
* application channel.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If group is not an allocated group.
|
||||
*/
|
||||
__STATIC_INLINE nrfx_err_t nrfx_ppi_channel_include_in_group(nrf_ppi_channel_t channel,
|
||||
nrf_ppi_channel_group_t group)
|
||||
{
|
||||
return nrfx_ppi_channels_include_in_group(nrfx_ppi_channel_to_mask(channel), group);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function for removing multiple PPI channels from a channel group.
|
||||
*
|
||||
* @param[in] channel_mask PPI channels to be removed.
|
||||
* @param[in] group Channel group from which to remove the channels.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully removed.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If group is not an application group or channels are not an
|
||||
* application channels.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If group is not an allocated group.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_channels_remove_from_group(uint32_t channel_mask,
|
||||
nrf_ppi_channel_group_t group);
|
||||
|
||||
/**
|
||||
* @brief Function for removing a PPI channel from a channel group.
|
||||
*
|
||||
* @param[in] channel PPI channel to be removed.
|
||||
* @param[in] group Channel group from which to remove the channel.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully removed.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If group is not an application group or channel is not an
|
||||
* application channel.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If group is not an allocated group.
|
||||
*/
|
||||
__STATIC_INLINE nrfx_err_t nrfx_ppi_channel_remove_from_group(nrf_ppi_channel_t channel,
|
||||
nrf_ppi_channel_group_t group)
|
||||
{
|
||||
return nrfx_ppi_channels_remove_from_group(nrfx_ppi_channel_to_mask(channel), group);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a PPI channel group.
|
||||
*
|
||||
* @param[in] group Channel group to be cleared.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the group was successfully cleared.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If group is not an application group.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If group is not an allocated group.
|
||||
*/
|
||||
__STATIC_INLINE nrfx_err_t nrfx_ppi_group_clear(nrf_ppi_channel_group_t group)
|
||||
{
|
||||
return nrfx_ppi_channels_remove_from_group(NRFX_PPI_ALL_APP_CHANNELS_MASK, group);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function for enabling a PPI channel group.
|
||||
*
|
||||
* @param[in] group Channel group to be enabled.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the group was successfully enabled.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If group is not an application group.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If group is not an allocated group.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_group_enable(nrf_ppi_channel_group_t group);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling a PPI channel group.
|
||||
*
|
||||
* @param[in] group Channel group to be disabled.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the group was successfully disabled.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If group is not an application group.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If group is not an allocated group.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_group_disable(nrf_ppi_channel_group_t group);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a PPI task.
|
||||
*
|
||||
* @param[in] task Task.
|
||||
*
|
||||
* @retval Task address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_ppi_task_addr_get(nrf_ppi_task_t task)
|
||||
{
|
||||
return (uint32_t) nrf_ppi_task_address_get(task);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a PPI group enable task.
|
||||
*
|
||||
* @param[in] group PPI channel group
|
||||
*
|
||||
* @retval Task address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_ppi_task_addr_group_enable_get(nrf_ppi_channel_group_t group)
|
||||
{
|
||||
return (uint32_t) nrf_ppi_task_group_enable_address_get(group);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a PPI group enable task.
|
||||
*
|
||||
* @param[in] group PPI channel group
|
||||
*
|
||||
* @retval Task address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_ppi_task_addr_group_disable_get(nrf_ppi_channel_group_t group)
|
||||
{
|
||||
return (uint32_t) nrf_ppi_task_group_disable_address_get(group);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRFX_PPI_H__
|
||||
@@ -0,0 +1,488 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_PWM_H__
|
||||
#define NRFX_PWM_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
#include <hal/nrf_pwm.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrfx_pwm PWM driver
|
||||
* @{
|
||||
* @ingroup nrf_pwm
|
||||
* @brief Pulse Width Modulation (PWM) peripheral driver.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief PWM driver instance data structure.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
NRF_PWM_Type * p_registers; ///< Pointer to the structure with PWM peripheral instance registers.
|
||||
uint8_t drv_inst_idx; ///< Driver instance index.
|
||||
} nrfx_pwm_t;
|
||||
|
||||
/**
|
||||
* @brief Macro for creating a PWM driver instance.
|
||||
*/
|
||||
#define NRFX_PWM_INSTANCE(id) \
|
||||
{ \
|
||||
.p_registers = NRFX_CONCAT_2(NRF_PWM, id), \
|
||||
.drv_inst_idx = NRFX_CONCAT_3(NRFX_PWM, id, _INST_IDX), \
|
||||
}
|
||||
|
||||
enum {
|
||||
#if NRFX_CHECK(NRFX_PWM0_ENABLED)
|
||||
NRFX_PWM0_INST_IDX,
|
||||
#endif
|
||||
#if NRFX_CHECK(NRFX_PWM1_ENABLED)
|
||||
NRFX_PWM1_INST_IDX,
|
||||
#endif
|
||||
#if NRFX_CHECK(NRFX_PWM2_ENABLED)
|
||||
NRFX_PWM2_INST_IDX,
|
||||
#endif
|
||||
#if NRFX_CHECK(NRFX_PWM3_ENABLED)
|
||||
NRFX_PWM3_INST_IDX,
|
||||
#endif
|
||||
NRFX_PWM_ENABLED_COUNT
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This value can be provided instead of a pin number for any channel
|
||||
* to specify that its output is not used and therefore does not need
|
||||
* to be connected to a pin.
|
||||
*/
|
||||
#define NRFX_PWM_PIN_NOT_USED 0xFF
|
||||
|
||||
/**
|
||||
* @brief This value can be added to a pin number to inverse its polarity
|
||||
* (set idle state = 1).
|
||||
*/
|
||||
#define NRFX_PWM_PIN_INVERTED 0x80
|
||||
|
||||
/**
|
||||
* @brief PWM driver configuration structure.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t output_pins[NRF_PWM_CHANNEL_COUNT]; ///< Pin numbers for individual output channels (optional).
|
||||
/**< Use @ref NRFX_PWM_PIN_NOT_USED
|
||||
* if a given output channel is not needed. */
|
||||
uint8_t irq_priority; ///< Interrupt priority.
|
||||
nrf_pwm_clk_t base_clock; ///< Base clock frequency.
|
||||
nrf_pwm_mode_t count_mode; ///< Operating mode of the pulse generator counter.
|
||||
uint16_t top_value; ///< Value up to which the pulse generator counter counts.
|
||||
nrf_pwm_dec_load_t load_mode; ///< Mode of loading sequence data from RAM.
|
||||
nrf_pwm_dec_step_t step_mode; ///< Mode of advancing the active sequence.
|
||||
} nrfx_pwm_config_t;
|
||||
|
||||
/**
|
||||
* @brief PWM driver default configuration.
|
||||
*/
|
||||
#define NRFX_PWM_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.output_pins = { NRFX_PWM_DEFAULT_CONFIG_OUT0_PIN, \
|
||||
NRFX_PWM_DEFAULT_CONFIG_OUT1_PIN, \
|
||||
NRFX_PWM_DEFAULT_CONFIG_OUT2_PIN, \
|
||||
NRFX_PWM_DEFAULT_CONFIG_OUT3_PIN }, \
|
||||
.irq_priority = NRFX_PWM_DEFAULT_CONFIG_IRQ_PRIORITY, \
|
||||
.base_clock = (nrf_pwm_clk_t)NRFX_PWM_DEFAULT_CONFIG_BASE_CLOCK, \
|
||||
.count_mode = (nrf_pwm_mode_t)NRFX_PWM_DEFAULT_CONFIG_COUNT_MODE, \
|
||||
.top_value = NRFX_PWM_DEFAULT_CONFIG_TOP_VALUE, \
|
||||
.load_mode = (nrf_pwm_dec_load_t)NRFX_PWM_DEFAULT_CONFIG_LOAD_MODE, \
|
||||
.step_mode = (nrf_pwm_dec_step_t)NRFX_PWM_DEFAULT_CONFIG_STEP_MODE, \
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief PWM flags providing additional playback options.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRFX_PWM_FLAG_STOP = 0x01, /**< When the requested playback is finished,
|
||||
the peripheral should be stopped.
|
||||
@note The STOP task is triggered when
|
||||
the last value of the final sequence is
|
||||
loaded from RAM, and the peripheral stops
|
||||
at the end of the current PWM period.
|
||||
For sequences with configured repeating
|
||||
of duty cycle values, this might result in
|
||||
less than the requested number of repeats
|
||||
of the last value. */
|
||||
NRFX_PWM_FLAG_LOOP = 0x02, /**< When the requested playback is finished,
|
||||
it should be started from the beginning.
|
||||
This flag is ignored if used together
|
||||
with @ref NRFX_PWM_FLAG_STOP.
|
||||
@note The playback restart is done via a
|
||||
shortcut configured in the PWM peripheral.
|
||||
This shortcut triggers the proper starting
|
||||
task when the final value of previous
|
||||
playback is read from RAM and applied to
|
||||
the pulse generator counter.
|
||||
When this mechanism is used together with
|
||||
the @ref NRF_PWM_STEP_TRIGGERED mode,
|
||||
the playback restart will occur right
|
||||
after switching to the final value (this
|
||||
final value will be played only once). */
|
||||
NRFX_PWM_FLAG_SIGNAL_END_SEQ0 = 0x04, /**< The event handler should be
|
||||
called when the last value
|
||||
from sequence 0 is loaded. */
|
||||
NRFX_PWM_FLAG_SIGNAL_END_SEQ1 = 0x08, /**< The event handler should be
|
||||
called when the last value
|
||||
from sequence 1 is loaded. */
|
||||
NRFX_PWM_FLAG_NO_EVT_FINISHED = 0x10, /**< The playback finished event
|
||||
(enabled by default) should be
|
||||
suppressed. */
|
||||
NRFX_PWM_FLAG_START_VIA_TASK = 0x80, /**< The playback should not be
|
||||
started directly by the called
|
||||
function. Instead, the function
|
||||
should only prepare it and
|
||||
return the address of the task
|
||||
to be triggered to start the
|
||||
playback. */
|
||||
} nrfx_pwm_flag_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief PWM driver event type.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRFX_PWM_EVT_FINISHED, ///< Sequence playback finished.
|
||||
NRFX_PWM_EVT_END_SEQ0, /**< End of sequence 0 reached. Its data can be
|
||||
safely modified now. */
|
||||
NRFX_PWM_EVT_END_SEQ1, /**< End of sequence 1 reached. Its data can be
|
||||
safely modified now. */
|
||||
NRFX_PWM_EVT_STOPPED, ///< The PWM peripheral has been stopped.
|
||||
} nrfx_pwm_evt_type_t;
|
||||
|
||||
/**
|
||||
* @brief PWM driver event handler type.
|
||||
*/
|
||||
typedef void (* nrfx_pwm_handler_t)(nrfx_pwm_evt_type_t event_type);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for initializing the PWM driver.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_config Pointer to the structure with initial configuration.
|
||||
*
|
||||
* @param[in] handler Event handler provided by the user. If NULL is passed
|
||||
* instead, event notifications are not done and PWM
|
||||
* interrupts are disabled.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver was already initialized.
|
||||
*/
|
||||
nrfx_err_t nrfx_pwm_init(nrfx_pwm_t const * const p_instance,
|
||||
nrfx_pwm_config_t const * p_config,
|
||||
nrfx_pwm_handler_t handler);
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing the PWM driver.
|
||||
*
|
||||
* If any sequence playback is in progress, it is stopped immediately.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_pwm_uninit(nrfx_pwm_t const * const p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for starting a single sequence playback.
|
||||
*
|
||||
* To take advantage of the looping mechanism in the PWM peripheral, both
|
||||
* sequences must be used (single sequence can be played back only once by
|
||||
* the peripheral). Therefore, the provided sequence is internally set and
|
||||
* played back as both sequence 0 and sequence 1. Consequently, if end of
|
||||
* sequence notifications are required, events for both sequences should be
|
||||
* used (that means that both the @ref NRFX_PWM_FLAG_SIGNAL_END_SEQ0 flag
|
||||
* and the @ref NRFX_PWM_FLAG_SIGNAL_END_SEQ1 flag should be specified and
|
||||
* the @ref NRFX_PWM_EVT_END_SEQ0 event and the @ref NRFX_PWM_EVT_END_SEQ1
|
||||
* event should be handled in the same way).
|
||||
*
|
||||
* Use the @ref NRFX_PWM_FLAG_START_VIA_TASK flag if you want the playback
|
||||
* to be only prepared by this function, and you want to start it later by
|
||||
* triggering a task (using PPI for instance). The function will then return
|
||||
* the address of the task to be triggered.
|
||||
*
|
||||
* @note The array containing the duty cycle values for the specified sequence
|
||||
* must be in RAM and cannot be allocated on stack.
|
||||
* For detailed information, see @ref nrf_pwm_sequence_t.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_sequence Sequence to be played back.
|
||||
* @param[in] playback_count Number of playbacks to be performed (must not be 0).
|
||||
* @param[in] flags Additional options. Pass any combination of
|
||||
* @ref nrfx_pwm_flag_t "playback flags", or 0
|
||||
* for default settings.
|
||||
*
|
||||
* @return Address of the task to be triggered to start the playback if the @ref
|
||||
* NRFX_PWM_FLAG_START_VIA_TASK flag was used, 0 otherwise.
|
||||
*/
|
||||
uint32_t nrfx_pwm_simple_playback(nrfx_pwm_t const * const p_instance,
|
||||
nrf_pwm_sequence_t const * p_sequence,
|
||||
uint16_t playback_count,
|
||||
uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Function for starting a two-sequence playback.
|
||||
*
|
||||
* Use the @ref NRFX_PWM_FLAG_START_VIA_TASK flag if you want the playback
|
||||
* to be only prepared by this function, and you want to start it later by
|
||||
* triggering a task (using PPI for instance). The function will then return
|
||||
* the address of the task to be triggered.
|
||||
*
|
||||
* @note The array containing the duty cycle values for the specified sequence
|
||||
* must be in RAM and cannot be allocated on stack.
|
||||
* For detailed information, see @ref nrf_pwm_sequence_t.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_sequence_0 First sequence to be played back.
|
||||
* @param[in] p_sequence_1 Second sequence to be played back.
|
||||
* @param[in] playback_count Number of playbacks to be performed (must not be 0).
|
||||
* @param[in] flags Additional options. Pass any combination of
|
||||
* @ref nrfx_pwm_flag_t "playback flags", or 0
|
||||
* for default settings.
|
||||
*
|
||||
* @return Address of the task to be triggered to start the playback if the @ref
|
||||
* NRFX_PWM_FLAG_START_VIA_TASK flag was used, 0 otherwise.
|
||||
*/
|
||||
uint32_t nrfx_pwm_complex_playback(nrfx_pwm_t const * const p_instance,
|
||||
nrf_pwm_sequence_t const * p_sequence_0,
|
||||
nrf_pwm_sequence_t const * p_sequence_1,
|
||||
uint16_t playback_count,
|
||||
uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Function for advancing the active sequence.
|
||||
*
|
||||
* This function only applies to @ref NRF_PWM_STEP_TRIGGERED mode.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrfx_pwm_step(nrfx_pwm_t const * const p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for stopping the sequence playback.
|
||||
*
|
||||
* The playback is stopped at the end of the current PWM period.
|
||||
* This means that if the active sequence is configured to repeat each duty
|
||||
* cycle value for a certain number of PWM periods, the last played value
|
||||
* might appear on the output less times than requested.
|
||||
*
|
||||
* @note This function can be instructed to wait until the playback is stopped
|
||||
* (by setting @p wait_until_stopped to true). Note that, depending on
|
||||
* the length of the PMW period, this might take a significant amount of
|
||||
* time. Alternatively, the @ref nrfx_pwm_is_stopped function can be
|
||||
* used to poll the status, or the @ref NRFX_PWM_EVT_STOPPED event can
|
||||
* be used to get the notification when the playback is stopped, provided
|
||||
* the event handler is defined.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] wait_until_stopped If true, the function will not return until
|
||||
* the playback is stopped.
|
||||
*
|
||||
* @retval true If the PWM peripheral is stopped.
|
||||
* @retval false If the PWM peripheral is not stopped.
|
||||
*/
|
||||
bool nrfx_pwm_stop(nrfx_pwm_t const * const p_instance,
|
||||
bool wait_until_stopped);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the status of the PWM peripheral.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*
|
||||
* @retval true If the PWM peripheral is stopped.
|
||||
* @retval false If the PWM peripheral is not stopped.
|
||||
*/
|
||||
bool nrfx_pwm_is_stopped(nrfx_pwm_t const * const p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for updating the sequence data during playback.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] seq_id Identifier of the sequence (0 or 1).
|
||||
* @param[in] p_sequence Pointer to the new sequence definition.
|
||||
*/
|
||||
__STATIC_INLINE void nrfx_pwm_sequence_update(
|
||||
nrfx_pwm_t const * const p_instance,
|
||||
uint8_t seq_id,
|
||||
nrf_pwm_sequence_t const * p_sequence);
|
||||
|
||||
/**
|
||||
* @brief Function for updating the pointer to the duty cycle values
|
||||
* in the specified sequence during playback.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] seq_id Identifier of the sequence (0 or 1).
|
||||
* @param[in] values New pointer to the duty cycle values.
|
||||
*/
|
||||
__STATIC_INLINE void nrfx_pwm_sequence_values_update(nrfx_pwm_t const * const p_instance,
|
||||
uint8_t seq_id,
|
||||
nrf_pwm_values_t values);
|
||||
|
||||
/**
|
||||
* @brief Function for updating the number of duty cycle values
|
||||
* in the specified sequence during playback.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] seq_id Identifier of the sequence (0 or 1).
|
||||
* @param[in] length New number of the duty cycle values.
|
||||
*/
|
||||
__STATIC_INLINE void nrfx_pwm_sequence_length_update(nrfx_pwm_t const * const p_instance,
|
||||
uint8_t seq_id,
|
||||
uint16_t length);
|
||||
|
||||
/**
|
||||
* @brief Function for updating the number of repeats for duty cycle values
|
||||
* in specified sequence during playback.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] seq_id Identifier of the sequence (0 or 1).
|
||||
* @param[in] repeats New number of repeats.
|
||||
*/
|
||||
__STATIC_INLINE void nrfx_pwm_sequence_repeats_update(nrfx_pwm_t const * const p_instance,
|
||||
uint8_t seq_id,
|
||||
uint32_t repeats);
|
||||
|
||||
/**
|
||||
* @brief Function for updating the additional delay after the specified
|
||||
* sequence during playback.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] seq_id Identifier of the sequence (0 or 1).
|
||||
* @param[in] end_delay New end delay value (in PWM periods).
|
||||
*/
|
||||
__STATIC_INLINE void nrfx_pwm_sequence_end_delay_update(nrfx_pwm_t const * const p_instance,
|
||||
uint8_t seq_id,
|
||||
uint32_t end_delay);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a specified PWM task that can
|
||||
* be used in PPI module.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] task Requested task.
|
||||
*
|
||||
* @return Task address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_pwm_task_address_get(nrfx_pwm_t const * const p_instance,
|
||||
nrf_pwm_task_t task);
|
||||
|
||||
/**@brief Function for returning the address of a specified PWM event that can
|
||||
* be used in PPI module.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] event Requested event.
|
||||
*
|
||||
* @return Event address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_pwm_event_address_get(nrfx_pwm_t const * const p_instance,
|
||||
nrf_pwm_event_t event);
|
||||
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
__STATIC_INLINE void nrfx_pwm_step(nrfx_pwm_t const * const p_instance)
|
||||
{
|
||||
nrf_pwm_task_trigger(p_instance->p_registers, NRF_PWM_TASK_NEXTSTEP);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrfx_pwm_sequence_update(nrfx_pwm_t const * const p_instance,
|
||||
uint8_t seq_id,
|
||||
nrf_pwm_sequence_t const * p_sequence)
|
||||
{
|
||||
nrf_pwm_sequence_set(p_instance->p_registers, seq_id, p_sequence);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrfx_pwm_sequence_values_update(nrfx_pwm_t const * const p_instance,
|
||||
uint8_t seq_id,
|
||||
nrf_pwm_values_t values)
|
||||
{
|
||||
nrf_pwm_seq_ptr_set(p_instance->p_registers, seq_id, values.p_raw);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrfx_pwm_sequence_length_update(nrfx_pwm_t const * const p_instance,
|
||||
uint8_t seq_id,
|
||||
uint16_t length)
|
||||
{
|
||||
nrf_pwm_seq_cnt_set(p_instance->p_registers, seq_id, length);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrfx_pwm_sequence_repeats_update(nrfx_pwm_t const * const p_instance,
|
||||
uint8_t seq_id,
|
||||
uint32_t repeats)
|
||||
{
|
||||
nrf_pwm_seq_refresh_set(p_instance->p_registers, seq_id, repeats);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrfx_pwm_sequence_end_delay_update(nrfx_pwm_t const * const p_instance,
|
||||
uint8_t seq_id,
|
||||
uint32_t end_delay)
|
||||
{
|
||||
nrf_pwm_seq_end_delay_set(p_instance->p_registers, seq_id, end_delay);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrfx_pwm_task_address_get(nrfx_pwm_t const * const p_instance,
|
||||
nrf_pwm_task_t task)
|
||||
{
|
||||
return nrf_pwm_task_address_get(p_instance->p_registers, task);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrfx_pwm_event_address_get(nrfx_pwm_t const * const p_instance,
|
||||
nrf_pwm_event_t event)
|
||||
{
|
||||
return nrf_pwm_event_address_get(p_instance->p_registers, event);
|
||||
}
|
||||
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
|
||||
void nrfx_pwm_0_irq_handler(void);
|
||||
void nrfx_pwm_1_irq_handler(void);
|
||||
void nrfx_pwm_2_irq_handler(void);
|
||||
void nrfx_pwm_3_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRFX_PWM_H__
|
||||
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 <nrfx.h>
|
||||
#include <hal/nrf_qdec.h>
|
||||
|
||||
#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, \
|
||||
.interrupt_priority = NRFX_QDEC_CONFIG_IRQ_PRIORITY, \
|
||||
.dbfen = NRFX_QDEC_CONFIG_DBFEN, \
|
||||
.sample_inten = NRFX_QDEC_CONFIG_SAMPLE_INTEN \
|
||||
}
|
||||
|
||||
/**@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;
|
||||
union
|
||||
{
|
||||
nrfx_qdec_sample_data_evt_t sample; /**< Sample event data. */
|
||||
nrfx_qdec_report_data_evt_t report; /**< Report event data. */
|
||||
} 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 initial configuration.
|
||||
* @param[in] event_handler Event handler provided by the user.
|
||||
* Must not be NULL.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If 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 QDEC.
|
||||
* @note Function asserts if module is not enabled.
|
||||
* @note Accumulators are cleared after reading.
|
||||
*
|
||||
* @param[out] p_acc Pointer to store accumulated transitions.
|
||||
* @param[out] p_accdbl Pointer to store accumulated double transitions.
|
||||
*/
|
||||
void nrfx_qdec_accumulators_read(int16_t * p_acc, int16_t * p_accdbl);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a specific 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 a specific 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__
|
||||
@@ -0,0 +1,288 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 <nrfx.h>
|
||||
#include <hal/nrf_qspi.h>
|
||||
|
||||
#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; /**< Pins 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, \
|
||||
}, \
|
||||
.irq_priority = (uint8_t)NRFX_QSPI_CONFIG_IRQ_PRIORITY, \
|
||||
.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_freq = (nrf_qspi_frequency_t)NRFX_QSPI_CONFIG_FREQUENCY, \
|
||||
.sck_delay = (uint8_t)NRFX_QSPI_CONFIG_SCK_DELAY, \
|
||||
.spi_mode = (nrf_qspi_spi_mode_t)NRFX_QSPI_CONFIG_MODE, \
|
||||
.dpmen = false \
|
||||
}, \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QSPI custom instruction helper with 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 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 interrupt handler.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_TIMEOUT If the peripheral cannot connect with external memory.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver was already initialized.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If 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 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 still runs and
|
||||
* until operation data is still 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 If the operation was successful (blocking mode) or operation
|
||||
* was commissioned (handler mode).
|
||||
* @retval NRFX_ERROR_BUSY If the driver currently handles another operation.
|
||||
* @retval NRFX_ERROR_INVALID_ADDR If the provided buffer is not placed in the Data RAM region.
|
||||
*/
|
||||
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 still runs and
|
||||
* until operation data is still 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 If the operation was successful (blocking mode) or operation
|
||||
* was commissioned (handler mode).
|
||||
* @retval NRFX_ERROR_BUSY If the driver currently handles other operation.
|
||||
* @retval NRFX_ERROR_INVALID_ADDR If the provided buffer is not placed in the Data RAM region.
|
||||
*/
|
||||
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 still runs and
|
||||
* until operation data is still 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 If the operation was successful (blocking mode) or operation
|
||||
* was commissioned (handler mode).
|
||||
* @retval NRFX_ERROR_BUSY If 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 If the operation was successful (blocking mode) or operation
|
||||
* was commissioned (handler mode).
|
||||
* @retval NRFX_ERROR_BUSY If 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 If the driver and memory are ready to handle a new operation.
|
||||
* @retval NRFX_ERROR_BUSY If 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 If the operation was successful.
|
||||
* @retval NRFX_ERROR_TIMEOUT If the external memory is busy or there are connection issues.
|
||||
* @retval NRFX_ERROR_BUSY If 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 If the operation was successful.
|
||||
* @retval NRFX_ERROR_BUSY If 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);
|
||||
|
||||
|
||||
void nrfx_qspi_irq_handler(void);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRFX_QSPI_H__
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_RNG_H__
|
||||
#define NRFX_RNG_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
#include <hal/nrf_rng.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrfx_rng RNG driver
|
||||
* @{
|
||||
* @ingroup nrf_rng
|
||||
* @brief Random Number Generator (RNG) peripheral driver.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Struct for RNG configuration.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
bool error_correction : 1; /**< Error correction flag. */
|
||||
uint8_t interrupt_priority; /**< interrupt priority */
|
||||
} nrfx_rng_config_t;
|
||||
|
||||
/**
|
||||
* @brief RNG default configuration.
|
||||
* Basic usage:
|
||||
* @code
|
||||
* nrfx_rng_config_t config = NRFX_RNG_DEFAULT_CONFIG;
|
||||
* if (nrfx_rng_init(&config, handler)
|
||||
* { ...
|
||||
* @endcode
|
||||
*/
|
||||
#define NRFX_RNG_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.error_correction = NRFX_RNG_CONFIG_ERROR_CORRECTION, \
|
||||
.interrupt_priority = NRFX_RNG_CONFIG_IRQ_PRIORITY, \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RNG driver event handler type.
|
||||
*/
|
||||
typedef void (* nrfx_rng_evt_handler_t)(uint8_t rng_data);
|
||||
|
||||
/**
|
||||
* @brief Function for initializing the nrfx_rng module.
|
||||
*
|
||||
* @param[in] p_config Pointer to the structure with initial configuration.
|
||||
* @param[in] handler Event handler provided by the user. Must not be NULL.
|
||||
*
|
||||
* @retval NRFX_SUCCESS Driver was successfully initialized.
|
||||
* @retval NRFX_ERROR_ALREADY_INITIALIZED Driver was already initialized.
|
||||
*/
|
||||
nrfx_err_t nrfx_rng_init(nrfx_rng_config_t const * p_config, nrfx_rng_evt_handler_t handler);
|
||||
|
||||
/**
|
||||
* @brief Function for starting the random value generation.
|
||||
*
|
||||
* Function enables interrupts in perihperal and start them.
|
||||
*/
|
||||
void nrfx_rng_start(void);
|
||||
|
||||
/**
|
||||
* @brief Function for stoping the random value generation.
|
||||
*
|
||||
* Function disables interrupts in perihperal and stop generation of new random values.
|
||||
*/
|
||||
void nrfx_rng_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing the nrfx_rng module.
|
||||
*/
|
||||
void nrfx_rng_uninit(void);
|
||||
|
||||
|
||||
void nrfx_rng_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRFX_RNG_H__
|
||||
@@ -0,0 +1,360 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_RTC_H__
|
||||
#define NRFX_RTC_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
#include <hal/nrf_rtc.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrfx_rtc RTC driver
|
||||
* @{
|
||||
* @ingroup nrf_rtc
|
||||
* @brief Real Timer Counter (RTC) peripheral driver.
|
||||
*/
|
||||
|
||||
/**@brief Macro to convert microseconds into ticks. */
|
||||
#define NRFX_RTC_US_TO_TICKS(us,freq) (((us) * (freq)) / 1000000U)
|
||||
|
||||
/**@brief RTC driver interrupt types. */
|
||||
typedef enum
|
||||
{
|
||||
NRFX_RTC_INT_COMPARE0 = 0, /**< Interrupt from COMPARE0 event. */
|
||||
NRFX_RTC_INT_COMPARE1 = 1, /**< Interrupt from COMPARE1 event. */
|
||||
NRFX_RTC_INT_COMPARE2 = 2, /**< Interrupt from COMPARE2 event. */
|
||||
NRFX_RTC_INT_COMPARE3 = 3, /**< Interrupt from COMPARE3 event. */
|
||||
NRFX_RTC_INT_TICK = 4, /**< Interrupt from TICK event. */
|
||||
NRFX_RTC_INT_OVERFLOW = 5 /**< Interrupt from OVERFLOW event. */
|
||||
} nrfx_rtc_int_type_t;
|
||||
|
||||
/**@brief RTC driver instance structure. */
|
||||
typedef struct
|
||||
{
|
||||
NRF_RTC_Type * p_reg; /**< Pointer to instance register set. */
|
||||
IRQn_Type irq; /**< Instance IRQ ID. */
|
||||
uint8_t instance_id; /**< Instance index. */
|
||||
uint8_t cc_channel_count; /**< Number of capture/compare channels. */
|
||||
} nrfx_rtc_t;
|
||||
|
||||
/**@brief Macro for creating RTC driver instance.*/
|
||||
#define NRFX_RTC_INSTANCE(id) \
|
||||
{ \
|
||||
.p_reg = NRFX_CONCAT_2(NRF_RTC, id), \
|
||||
.irq = NRFX_CONCAT_3(RTC, id, _IRQn), \
|
||||
.instance_id = NRFX_CONCAT_3(NRFX_RTC, id, _INST_IDX), \
|
||||
.cc_channel_count = NRF_RTC_CC_CHANNEL_COUNT(id), \
|
||||
}
|
||||
|
||||
enum {
|
||||
#if NRFX_CHECK(NRFX_RTC0_ENABLED)
|
||||
NRFX_RTC0_INST_IDX,
|
||||
#endif
|
||||
#if NRFX_CHECK(NRFX_RTC1_ENABLED)
|
||||
NRFX_RTC1_INST_IDX,
|
||||
#endif
|
||||
#if NRFX_CHECK(NRFX_RTC2_ENABLED)
|
||||
NRFX_RTC2_INST_IDX,
|
||||
#endif
|
||||
NRFX_RTC_ENABLED_COUNT
|
||||
};
|
||||
|
||||
/**@brief RTC driver instance configuration structure. */
|
||||
typedef struct
|
||||
{
|
||||
uint16_t prescaler; /**< Prescaler. */
|
||||
uint8_t interrupt_priority; /**< Interrupt priority. */
|
||||
uint8_t tick_latency; /**< Maximum length of interrupt handler in ticks (max 7.7 ms). */
|
||||
bool reliable; /**< Reliable mode flag. */
|
||||
} nrfx_rtc_config_t;
|
||||
|
||||
/**@brief RTC instance default configuration. */
|
||||
#define NRFX_RTC_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.prescaler = RTC_FREQ_TO_PRESCALER(NRFX_RTC_DEFAULT_CONFIG_FREQUENCY), \
|
||||
.interrupt_priority = NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY, \
|
||||
.reliable = NRFX_RTC_DEFAULT_CONFIG_RELIABLE, \
|
||||
.tick_latency = NRFX_RTC_US_TO_TICKS(NRFX_RTC_MAXIMUM_LATENCY_US, \
|
||||
NRFX_RTC_DEFAULT_CONFIG_FREQUENCY), \
|
||||
}
|
||||
|
||||
/**@brief RTC driver instance handler type. */
|
||||
typedef void (*nrfx_rtc_handler_t)(nrfx_rtc_int_type_t int_type);
|
||||
|
||||
/**@brief Function for initializing the RTC driver instance.
|
||||
*
|
||||
* After initialization, the instance is in power off state.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_config Pointer to the structure with initial configuration.
|
||||
* @param[in] handler Event handler provided by the user.
|
||||
* Must not be NULL.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If successfully initialized.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the instance is already initialized.
|
||||
*/
|
||||
nrfx_err_t nrfx_rtc_init(nrfx_rtc_t const * const p_instance,
|
||||
nrfx_rtc_config_t const * p_config,
|
||||
nrfx_rtc_handler_t handler);
|
||||
|
||||
/**@brief Function for uninitializing the RTC driver instance.
|
||||
*
|
||||
* After uninitialization, the instance is in idle state. The hardware should return to the state
|
||||
* before initialization. The function asserts if the instance is in idle state.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_rtc_uninit(nrfx_rtc_t const * const p_instance);
|
||||
|
||||
/**@brief Function for enabling the RTC driver instance.
|
||||
*
|
||||
* @note Function asserts if instance is enabled.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_rtc_enable(nrfx_rtc_t const * const p_instance);
|
||||
|
||||
/**@brief Function for disabling the RTC driver instance.
|
||||
*
|
||||
* @note Function asserts if instance is disabled.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_rtc_disable(nrfx_rtc_t const * const p_instance);
|
||||
|
||||
/**@brief Function for setting a compare channel.
|
||||
*
|
||||
* The function asserts if the instance is not initialized or if the channel parameter is
|
||||
* wrong. The function powers on the instance if the instance was in power off state.
|
||||
*
|
||||
* The driver is not entering a critical section when configuring RTC, which means that it can be
|
||||
* preempted for a certain amount of time. When the driver was preempted and the value to be set
|
||||
* is short in time, there is a risk that the driver sets a compare value that is
|
||||
* behind. If RTCn_CONFIG_RELIABLE is 1 for the given instance, the Reliable mode handles that case.
|
||||
* However, to detect if the requested value is behind, this mode makes the following assumptions:
|
||||
* - The maximum preemption time in ticks (8 - bit value) is known and is less than 7.7 ms
|
||||
* (for prescaler = 0, RTC frequency 32 kHz).
|
||||
* - The requested absolute compare value is not bigger than (0x00FFFFFF) - tick_latency. It is
|
||||
* the user's responsibility to ensure that.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] channel One of the instance's channels.
|
||||
* @param[in] val Absolute value to be set in the compare register.
|
||||
* @param[in] enable_irq True to enable the interrupt. False to disable the interrupt.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the procedure was successful.
|
||||
* @retval NRFX_ERROR_TIMEOUT If the compare was not set because the request value is behind the current counter
|
||||
* value. This error can only be reported if RTCn_CONFIG_RELIABLE = 1.
|
||||
*/
|
||||
nrfx_err_t nrfx_rtc_cc_set(nrfx_rtc_t const * const p_instance,
|
||||
uint32_t channel,
|
||||
uint32_t val,
|
||||
bool enable_irq);
|
||||
|
||||
/**@brief Function for disabling a channel.
|
||||
*
|
||||
* This function disables channel events and channel interrupts. The function asserts if the instance is not
|
||||
* initialized or if the channel parameter is wrong.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] channel One of the instance's channels.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the procedure was successful.
|
||||
* @retval NRFX_ERROR_TIMEOUT If an interrupt was pending on the requested channel.
|
||||
*/
|
||||
nrfx_err_t nrfx_rtc_cc_disable(nrfx_rtc_t const * const p_instance, uint32_t channel);
|
||||
|
||||
/**@brief Function for enabling tick.
|
||||
*
|
||||
* This function enables the tick event and optionally the interrupt. The function asserts if the instance is not
|
||||
* powered on.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] enable_irq True to enable the interrupt. False to disable the interrupt.
|
||||
*/
|
||||
void nrfx_rtc_tick_enable(nrfx_rtc_t const * const p_instance, bool enable_irq);
|
||||
|
||||
/**@brief Function for disabling tick.
|
||||
*
|
||||
* This function disables the tick event and interrupt.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_rtc_tick_disable(nrfx_rtc_t const * const p_instance);
|
||||
|
||||
/**@brief Function for enabling overflow.
|
||||
*
|
||||
* This function enables the overflow event and optionally the interrupt. The function asserts if the instance is
|
||||
* not powered on.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] enable_irq True to enable the interrupt. False to disable the interrupt.
|
||||
*/
|
||||
void nrfx_rtc_overflow_enable(nrfx_rtc_t const * const p_instance, bool enable_irq);
|
||||
|
||||
/**@brief Function for disabling overflow.
|
||||
*
|
||||
* This function disables the overflow event and interrupt.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_rtc_overflow_disable(nrfx_rtc_t const * const p_instance);
|
||||
|
||||
/**@brief Function for getting the maximum relative ticks value that can be set in the compare channel.
|
||||
*
|
||||
* When a stack (for example SoftDevice) is used and it occupies high priority interrupts,
|
||||
* the application code can be interrupted at any moment for a certain period of time.
|
||||
* If Reliable mode is enabled, the provided maximum latency is taken into account
|
||||
* and the return value is smaller than the RTC counter resolution.
|
||||
* If Reliable mode is disabled, the return value equals the counter resolution.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*
|
||||
* @retval ticks Maximum ticks value.
|
||||
*/
|
||||
uint32_t nrfx_rtc_max_ticks_get(nrfx_rtc_t const * const p_instance);
|
||||
|
||||
/**@brief Function for disabling all instance interrupts.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_mask Pointer to the location where the mask is filled.
|
||||
*/
|
||||
__STATIC_INLINE void nrfx_rtc_int_disable(nrfx_rtc_t const * const p_instance,
|
||||
uint32_t * p_mask);
|
||||
|
||||
/**@brief Function for enabling instance interrupts.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] mask Mask of interrupts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrfx_rtc_int_enable(nrfx_rtc_t const * const p_instance, uint32_t mask);
|
||||
|
||||
/**@brief Function for retrieving the current counter value.
|
||||
*
|
||||
* This function asserts if the instance is not powered on or if p_val is NULL.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*
|
||||
* @retval value Counter value.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_rtc_counter_get(nrfx_rtc_t const * const p_instance);
|
||||
|
||||
/**@brief Function for clearing the counter value.
|
||||
*
|
||||
* This function asserts if the instance is not powered on.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrfx_rtc_counter_clear(nrfx_rtc_t const * const p_instance);
|
||||
|
||||
/**@brief Function for returning a requested task address for the RTC driver instance.
|
||||
*
|
||||
* This function asserts if the output pointer is NULL. The task address can be used by the PPI module.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the instance.
|
||||
* @param[in] task One of the peripheral tasks.
|
||||
*
|
||||
* @retval Address of task register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_rtc_task_address_get(nrfx_rtc_t const * const p_instance,
|
||||
nrf_rtc_task_t task);
|
||||
|
||||
/**@brief Function for returning a requested event address for the RTC driver instance.
|
||||
*
|
||||
* This function asserts if the output pointer is NULL. The event address can be used by the PPI module.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] event One of the peripheral events.
|
||||
*
|
||||
* @retval Address of event register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_rtc_event_address_get(nrfx_rtc_t const * const p_instance,
|
||||
nrf_rtc_event_t event);
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
__STATIC_INLINE void nrfx_rtc_int_disable(nrfx_rtc_t const * const p_instance,
|
||||
uint32_t * p_mask)
|
||||
{
|
||||
*p_mask = nrf_rtc_int_get(p_instance->p_reg);
|
||||
nrf_rtc_int_disable(p_instance->p_reg, NRF_RTC_INT_TICK_MASK |
|
||||
NRF_RTC_INT_OVERFLOW_MASK |
|
||||
NRF_RTC_INT_COMPARE0_MASK |
|
||||
NRF_RTC_INT_COMPARE1_MASK |
|
||||
NRF_RTC_INT_COMPARE2_MASK |
|
||||
NRF_RTC_INT_COMPARE3_MASK);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrfx_rtc_int_enable(nrfx_rtc_t const * const p_instance, uint32_t mask)
|
||||
{
|
||||
nrf_rtc_int_enable(p_instance->p_reg, mask);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrfx_rtc_counter_get(nrfx_rtc_t const * const p_instance)
|
||||
{
|
||||
return nrf_rtc_counter_get(p_instance->p_reg);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrfx_rtc_counter_clear(nrfx_rtc_t const * const p_instance)
|
||||
{
|
||||
nrf_rtc_task_trigger(p_instance->p_reg, NRF_RTC_TASK_CLEAR);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrfx_rtc_task_address_get(nrfx_rtc_t const * const p_instance,
|
||||
nrf_rtc_task_t task)
|
||||
{
|
||||
return nrf_rtc_task_address_get(p_instance->p_reg, task);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrfx_rtc_event_address_get(nrfx_rtc_t const * const p_instance,
|
||||
nrf_rtc_event_t event)
|
||||
{
|
||||
return nrf_rtc_event_address_get(p_instance->p_reg, event);
|
||||
}
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
|
||||
void nrfx_rtc_0_irq_handler(void);
|
||||
void nrfx_rtc_1_irq_handler(void);
|
||||
void nrfx_rtc_2_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRFX_RTC_H__
|
||||
@@ -0,0 +1,317 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_SAADC_H__
|
||||
#define NRFX_SAADC_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
#include <hal/nrf_saadc.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrfx_saadc SAADC driver
|
||||
* @{
|
||||
* @ingroup nrf_saadc
|
||||
* @brief Successive Approximation Analog-to-Digital Converter (SAADC) peripheral driver.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Value that should be set as high limit to disable limit detection.
|
||||
*/
|
||||
#define NRFX_SAADC_LIMITH_DISABLED (2047)
|
||||
/**
|
||||
* @brief Value that should be set as low limit to disable limit detection.
|
||||
*/
|
||||
#define NRFX_SAADC_LIMITL_DISABLED (-2048)
|
||||
|
||||
/**
|
||||
* @brief Macro for setting @ref nrfx_saadc_config_t to default settings.
|
||||
*/
|
||||
#define NRFX_SAADC_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.resolution = (nrf_saadc_resolution_t)NRFX_SAADC_CONFIG_RESOLUTION, \
|
||||
.oversample = (nrf_saadc_oversample_t)NRFX_SAADC_CONFIG_OVERSAMPLE, \
|
||||
.interrupt_priority = NRFX_SAADC_CONFIG_IRQ_PRIORITY, \
|
||||
.low_power_mode = NRFX_SAADC_CONFIG_LP_MODE \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Macro for setting @ref nrf_saadc_channel_config_t to default settings
|
||||
* in single ended mode.
|
||||
*
|
||||
* @param PIN_P Analog input.
|
||||
*/
|
||||
#define NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(PIN_P) \
|
||||
{ \
|
||||
.resistor_p = NRF_SAADC_RESISTOR_DISABLED, \
|
||||
.resistor_n = NRF_SAADC_RESISTOR_DISABLED, \
|
||||
.gain = NRF_SAADC_GAIN1_6, \
|
||||
.reference = NRF_SAADC_REFERENCE_INTERNAL, \
|
||||
.acq_time = NRF_SAADC_ACQTIME_10US, \
|
||||
.mode = NRF_SAADC_MODE_SINGLE_ENDED, \
|
||||
.burst = NRF_SAADC_BURST_DISABLED, \
|
||||
.pin_p = (nrf_saadc_input_t)(PIN_P), \
|
||||
.pin_n = NRF_SAADC_INPUT_DISABLED \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Macro for setting @ref nrf_saadc_channel_config_t to default settings
|
||||
* in differential mode.
|
||||
*
|
||||
* @param PIN_P Positive analog input.
|
||||
* @param PIN_N Negative analog input.
|
||||
*/
|
||||
#define NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_DIFFERENTIAL(PIN_P, PIN_N) \
|
||||
{ \
|
||||
.resistor_p = NRF_SAADC_RESISTOR_DISABLED, \
|
||||
.resistor_n = NRF_SAADC_RESISTOR_DISABLED, \
|
||||
.gain = NRF_SAADC_GAIN1_6, \
|
||||
.reference = NRF_SAADC_REFERENCE_INTERNAL, \
|
||||
.acq_time = NRF_SAADC_ACQTIME_10US, \
|
||||
.mode = NRF_SAADC_MODE_DIFFERENTIAL, \
|
||||
.pin_p = (nrf_saadc_input_t)(PIN_P), \
|
||||
.pin_n = (nrf_saadc_input_t)(PIN_N) \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter driver configuration structure.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrf_saadc_resolution_t resolution; ///< Resolution configuration.
|
||||
nrf_saadc_oversample_t oversample; ///< Oversampling configuration.
|
||||
uint8_t interrupt_priority; ///< Interrupt priority.
|
||||
bool low_power_mode; ///< Indicates if low power mode is active.
|
||||
} nrfx_saadc_config_t;
|
||||
|
||||
/**
|
||||
* @brief Driver event types.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRFX_SAADC_EVT_DONE, ///< Event generated when the buffer is filled with samples.
|
||||
NRFX_SAADC_EVT_LIMIT, ///< Event generated after one of the limits is reached.
|
||||
NRFX_SAADC_EVT_CALIBRATEDONE ///< Event generated when the calibration is complete.
|
||||
} nrfx_saadc_evt_type_t;
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter driver done event data.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrf_saadc_value_t * p_buffer; ///< Pointer to buffer with converted samples.
|
||||
uint16_t size; ///< Number of samples in the buffer.
|
||||
} nrfx_saadc_done_evt_t;
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter driver limit event data.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t channel; ///< Channel on which the limit was detected.
|
||||
nrf_saadc_limit_t limit_type; ///< Type of limit detected.
|
||||
} nrfx_saadc_limit_evt_t;
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter driver event structure.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrfx_saadc_evt_type_t type; ///< Event type.
|
||||
union
|
||||
{
|
||||
nrfx_saadc_done_evt_t done; ///< Data for @ref NRFX_SAADC_EVT_DONE event.
|
||||
nrfx_saadc_limit_evt_t limit; ///< Data for @ref NRFX_SAADC_EVT_LIMIT event.
|
||||
} data;
|
||||
} nrfx_saadc_evt_t;
|
||||
|
||||
/**
|
||||
* @brief ADC event handler.
|
||||
*
|
||||
* @param[in] p_event Pointer to an ADC event. The event structure is allocated on
|
||||
* the stack, so it is valid only within the context of
|
||||
* the event handler.
|
||||
*/
|
||||
typedef void (* nrfx_saadc_event_handler_t)(nrfx_saadc_evt_t const * p_event);
|
||||
|
||||
/**
|
||||
* @brief Function for initializing the SAADC.
|
||||
*
|
||||
* @param[in] p_config Pointer to the structure with initial configuration.
|
||||
* @param[in] event_handler Event handler provided by the user.
|
||||
* Must not be NULL.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver is already initialized.
|
||||
*/
|
||||
nrfx_err_t nrfx_saadc_init(nrfx_saadc_config_t const * p_config,
|
||||
nrfx_saadc_event_handler_t event_handler);
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing the SAADC.
|
||||
*
|
||||
* This function stops all ongoing conversions and disables all channels.
|
||||
*/
|
||||
void nrfx_saadc_uninit(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a SAMPLE SAADC task.
|
||||
*
|
||||
* @return Task address.
|
||||
*/
|
||||
uint32_t nrfx_saadc_sample_task_get(void);
|
||||
|
||||
/**
|
||||
* @brief Function for initializing an SAADC channel.
|
||||
*
|
||||
* This function configures and enables the channel.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the ADC was not initialized.
|
||||
* @retval NRFX_ERROR_NO_MEM If the specified channel was already allocated.
|
||||
*/
|
||||
nrfx_err_t nrfx_saadc_channel_init(uint8_t channel,
|
||||
nrf_saadc_channel_config_t const * const p_config);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing an SAADC channel.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If uninitialization was successful.
|
||||
* @retval NRFX_ERROR_BUSY If the ADC is busy.
|
||||
*/
|
||||
nrfx_err_t nrfx_saadc_channel_uninit(uint8_t channel);
|
||||
|
||||
/**
|
||||
* @brief Function for starting SAADC sampling.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If ADC sampling was triggered.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If ADC is in idle state.
|
||||
*/
|
||||
nrfx_err_t nrfx_saadc_sample(void);
|
||||
|
||||
/**
|
||||
* @brief Blocking function for executing a single ADC conversion.
|
||||
*
|
||||
* This function selects the desired input, starts a single conversion,
|
||||
* waits for it to finish, and returns the result.
|
||||
*
|
||||
* The function will fail if ADC is busy.
|
||||
*
|
||||
* @param[in] channel Channel.
|
||||
* @param[out] p_value Pointer to the location where the result should be placed.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If conversion was successful.
|
||||
* @retval NRFX_ERROR_BUSY If the ADC driver is busy.
|
||||
*/
|
||||
nrfx_err_t nrfx_saadc_sample_convert(uint8_t channel, nrf_saadc_value_t * p_value);
|
||||
|
||||
/**
|
||||
* @brief Function for issuing conversion of data to the buffer.
|
||||
*
|
||||
* This function is non-blocking. The application is notified about filling the buffer by the event
|
||||
* handler. Conversion will be done on all enabled channels. If the ADC is in idle state, the
|
||||
* function will set up Easy DMA for the conversion. The ADC will be ready for sampling and wait for
|
||||
* the SAMPLE task. It can be triggered manually by the @ref nrfx_saadc_sample function or by PPI
|
||||
* using the @ref NRF_SAADC_TASK_SAMPLE task. If one buffer is already set and the conversion is
|
||||
* ongoing, calling this function will result in queuing the given buffer. The driver will start
|
||||
* filling the issued buffer when the first one is completed. If the function is called again before
|
||||
* the first buffer is filled or calibration is in progress, it will return with error.
|
||||
*
|
||||
* @param[in] buffer Result buffer.
|
||||
* @param[in] size Buffer size in words.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If conversion was successful.
|
||||
* @retval NRFX_ERROR_BUSY If the driver already has two buffers set or calibration is in progress.
|
||||
*/
|
||||
nrfx_err_t nrfx_saadc_buffer_convert(nrf_saadc_value_t * buffer, uint16_t size);
|
||||
|
||||
/**
|
||||
* @brief Function for triggering the ADC offset calibration.
|
||||
*
|
||||
* This function is non-blocking. The application is notified about completion by the event handler.
|
||||
* Calibration will also trigger DONE and RESULTDONE events.
|
||||
*
|
||||
* The function will fail if ADC is busy or calibration is already in progress.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If calibration was started successfully.
|
||||
* @retval NRFX_ERROR_BUSY If the ADC driver is busy.
|
||||
*/
|
||||
nrfx_err_t nrfx_saadc_calibrate_offset(void);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the SAADC state.
|
||||
*
|
||||
* @retval true If the ADC is busy.
|
||||
* @retval false If the ADC is ready.
|
||||
*/
|
||||
bool nrfx_saadc_is_busy(void);
|
||||
|
||||
/**
|
||||
* @brief Function for aborting ongoing and buffered conversions.
|
||||
* @note @ref NRFX_SAADC_EVT_DONE event will be generated if there is a conversion in progress.
|
||||
* Event will contain number of words in the sample buffer.
|
||||
*/
|
||||
void nrfx_saadc_abort(void);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the SAADC channel limits.
|
||||
* When limits are enabled and the result exceeds the defined bounds, the limit handler
|
||||
* function is called.
|
||||
*
|
||||
* @param[in] channel SAADC channel number.
|
||||
* @param[in] limit_low Lower limit (valid values from @ref NRFX_SAADC_LIMITL_DISABLED to
|
||||
* @ref NRFX_SAADC_LIMITH_DISABLED). Conversion results below this value will
|
||||
* trigger the handler function. Set to @ref NRFX_SAADC_LIMITL_DISABLED
|
||||
* to disable this limit.
|
||||
* @param[in] limit_high Upper limit (valid values from @ref NRFX_SAADC_LIMITL_DISABLED to
|
||||
* @ref NRFX_SAADC_LIMITH_DISABLED). Conversion results above this value will
|
||||
* trigger the handler function. Set to @ref NRFX_SAADC_LIMITH_DISABLED
|
||||
* to disable this limit.
|
||||
*/
|
||||
void nrfx_saadc_limits_set(uint8_t channel, int16_t limit_low, int16_t limit_high);
|
||||
|
||||
|
||||
void nrfx_saadc_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRFX_SAADC_H__
|
||||
|
||||
@@ -0,0 +1,264 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_SPI_H__
|
||||
#define NRFX_SPI_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
#include <hal/nrf_spi.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrfx_spi SPI driver
|
||||
* @{
|
||||
* @ingroup nrf_spi
|
||||
* @brief SPI peripheral driver.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief SPI master driver instance data structure.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
NRF_SPI_Type * p_reg; ///< Pointer to a structure with SPI registers.
|
||||
uint8_t drv_inst_idx; ///< Driver instance index.
|
||||
} nrfx_spi_t;
|
||||
|
||||
enum {
|
||||
#if NRFX_CHECK(NRFX_SPI0_ENABLED)
|
||||
NRFX_SPI0_INST_IDX,
|
||||
#endif
|
||||
#if NRFX_CHECK(NRFX_SPI1_ENABLED)
|
||||
NRFX_SPI1_INST_IDX,
|
||||
#endif
|
||||
#if NRFX_CHECK(NRFX_SPI2_ENABLED)
|
||||
NRFX_SPI2_INST_IDX,
|
||||
#endif
|
||||
NRFX_SPI_ENABLED_COUNT
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Macro for creating an SPI master driver instance.
|
||||
*/
|
||||
#define NRFX_SPI_INSTANCE(id) \
|
||||
{ \
|
||||
.p_reg = NRFX_CONCAT_2(NRF_SPI, id), \
|
||||
.drv_inst_idx = NRFX_CONCAT_3(NRFX_SPI, id, _INST_IDX), \
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 NRFX_SPI_PIN_NOT_USED 0xFF
|
||||
|
||||
/**
|
||||
* @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 NRFX_SPI_PIN_NOT_USED
|
||||
* if this signal is not needed. */
|
||||
uint8_t miso_pin; ///< MISO pin number (optional).
|
||||
/**< Set to @ref NRFX_SPI_PIN_NOT_USED
|
||||
* if this signal is not needed. */
|
||||
uint8_t ss_pin; ///< Slave Select pin number (optional).
|
||||
/**< Set to @ref NRFX_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_spi_frequency_t frequency; ///< SPI frequency.
|
||||
nrf_spi_mode_t mode; ///< SPI mode.
|
||||
nrf_spi_bit_order_t bit_order; ///< SPI bit order.
|
||||
} nrfx_spi_config_t;
|
||||
|
||||
/**
|
||||
* @brief SPI master instance default configuration.
|
||||
*/
|
||||
#define NRFX_SPI_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.sck_pin = NRFX_SPI_PIN_NOT_USED, \
|
||||
.mosi_pin = NRFX_SPI_PIN_NOT_USED, \
|
||||
.miso_pin = NRFX_SPI_PIN_NOT_USED, \
|
||||
.ss_pin = NRFX_SPI_PIN_NOT_USED, \
|
||||
.irq_priority = NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY, \
|
||||
.orc = 0xFF, \
|
||||
.frequency = NRF_SPI_FREQ_4M, \
|
||||
.mode = NRF_SPI_MODE_0, \
|
||||
.bit_order = NRF_SPI_BIT_ORDER_MSB_FIRST, \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Single transfer descriptor structure.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t const * p_tx_buffer; ///< Pointer to TX buffer.
|
||||
size_t tx_length; ///< TX buffer length.
|
||||
uint8_t * p_rx_buffer; ///< Pointer to RX buffer.
|
||||
size_t rx_length; ///< RX buffer length.
|
||||
} nrfx_spi_xfer_desc_t;
|
||||
|
||||
/**
|
||||
* @brief Macro for setting up single transfer descriptor.
|
||||
*
|
||||
* This macro is for internal use only.
|
||||
*/
|
||||
#define NRFX_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 NRFX_SPI_XFER_TRX(p_tx_buf, tx_length, p_rx_buf, rx_length) \
|
||||
NRFX_SPI_SINGLE_XFER(p_tx_buf, tx_length, p_rx_buf, rx_length)
|
||||
|
||||
/**
|
||||
* @brief Macro for setting TX transfer.
|
||||
*/
|
||||
#define NRFX_SPI_XFER_TX(p_buf, length) \
|
||||
NRFX_SPI_SINGLE_XFER(p_buf, length, NULL, 0)
|
||||
|
||||
/**
|
||||
* @brief Macro for setting RX transfer.
|
||||
*/
|
||||
#define NRFX_SPI_XFER_RX(p_buf, length) \
|
||||
NRFX_SPI_SINGLE_XFER(NULL, 0, p_buf, length)
|
||||
|
||||
/**
|
||||
* @brief SPI master driver event types, passed to the handler routine provided
|
||||
* during initialization.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRFX_SPI_EVENT_DONE, ///< Transfer done.
|
||||
} nrfx_spi_evt_type_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
nrfx_spi_evt_type_t type; ///< Event type.
|
||||
nrfx_spi_xfer_desc_t xfer_desc; ///< Transfer details.
|
||||
} nrfx_spi_evt_t;
|
||||
|
||||
/**
|
||||
* @brief SPI master driver event handler type.
|
||||
*/
|
||||
typedef void (* nrfx_spi_evt_handler_t)(nrfx_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.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_config Pointer to the structure with 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 NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver was already initialized.
|
||||
* @retval NRFX_ERROR_BUSY If some other peripheral with the same
|
||||
* instance ID is already in use. This is
|
||||
* possible only if @ref nrfx_prs module
|
||||
* is enabled.
|
||||
*/
|
||||
nrfx_err_t nrfx_spi_init(nrfx_spi_t const * const p_instance,
|
||||
nrfx_spi_config_t const * p_config,
|
||||
nrfx_spi_evt_handler_t handler,
|
||||
void * p_context);
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing the SPI master driver instance.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_spi_uninit(nrfx_spi_t const * const p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for starting the SPI data transfer.
|
||||
*
|
||||
* If an event handler was provided in the @ref nrfx_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.
|
||||
*
|
||||
* @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).
|
||||
* Currently, no additional flags are available.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the procedure was successful.
|
||||
* @retval NRFX_ERROR_BUSY If the driver is not ready for a new transfer.
|
||||
* @retval NRFX_ERROR_NOT_SUPPORTED If the provided parameters are not supported.
|
||||
*/
|
||||
nrfx_err_t nrfx_spi_xfer(nrfx_spi_t const * const p_instance,
|
||||
nrfx_spi_xfer_desc_t const * p_xfer_desc,
|
||||
uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Function for aborting ongoing transfer.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_spi_abort(nrfx_spi_t const * p_instance);
|
||||
|
||||
|
||||
void nrfx_spi_0_irq_handler(void);
|
||||
void nrfx_spi_1_irq_handler(void);
|
||||
void nrfx_spi_2_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRFX_SPI_H__
|
||||
@@ -0,0 +1,387 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_SPIM_H__
|
||||
#define NRFX_SPIM_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
#include <hal/nrf_spim.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrfx_spim SPIM driver
|
||||
* @{
|
||||
* @ingroup nrf_spim
|
||||
* @brief SPIM peripheral driver.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief SPIM master driver instance data structure.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
NRF_SPIM_Type * p_reg; ///< Pointer to a structure with SPIM registers.
|
||||
uint8_t drv_inst_idx; ///< Driver instance index.
|
||||
} nrfx_spim_t;
|
||||
|
||||
enum {
|
||||
#if NRFX_CHECK(NRFX_SPIM0_ENABLED)
|
||||
NRFX_SPIM0_INST_IDX,
|
||||
#endif
|
||||
#if NRFX_CHECK(NRFX_SPIM1_ENABLED)
|
||||
NRFX_SPIM1_INST_IDX,
|
||||
#endif
|
||||
#if NRFX_CHECK(NRFX_SPIM2_ENABLED)
|
||||
NRFX_SPIM2_INST_IDX,
|
||||
#endif
|
||||
#if NRFX_CHECK(NRFX_SPIM3_ENABLED)
|
||||
NRFX_SPIM3_INST_IDX,
|
||||
#endif
|
||||
NRFX_SPIM_ENABLED_COUNT
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Macro for creating an SPIM master driver instance.
|
||||
*/
|
||||
#define NRFX_SPIM_INSTANCE(id) \
|
||||
{ \
|
||||
.p_reg = NRFX_CONCAT_2(NRF_SPIM, id), \
|
||||
.drv_inst_idx = NRFX_CONCAT_3(NRFX_SPIM, id, _INST_IDX), \
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 NRFX_SPIM_PIN_NOT_USED 0xFF
|
||||
|
||||
/**
|
||||
* @brief SPIM 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 NRFX_SPIM_PIN_NOT_USED
|
||||
* if this signal is not needed. */
|
||||
uint8_t miso_pin; ///< MISO pin number (optional).
|
||||
/**< Set to @ref NRFX_SPIM_PIN_NOT_USED
|
||||
* if this signal is not needed. */
|
||||
uint8_t ss_pin; ///< Slave Select pin number (optional).
|
||||
/**< Set to @ref NRFX_SPIM_PIN_NOT_USED
|
||||
* if this signal is not needed. */
|
||||
bool ss_active_high; ///< Polarity of the Slave Select pin during transmission.
|
||||
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_spim_frequency_t frequency; ///< SPI frequency.
|
||||
nrf_spim_mode_t mode; ///< SPI mode.
|
||||
nrf_spim_bit_order_t bit_order; ///< SPI bit order.
|
||||
#if NRFX_CHECK(NRFX_SPIM_EXTENDED_ENABLED) || defined(__NRFX_DOXYGEN__)
|
||||
uint8_t dcx_pin; ///< D/CX pin number (optional).
|
||||
uint8_t rx_delay; ///< Sample delay for input serial data on MISO.
|
||||
/**< The value specifies the delay, in number of 64 MHz clock cycles
|
||||
* (15.625 ns), from the the sampling edge of SCK (leading edge for
|
||||
* CONFIG.CPHA = 0, trailing edge for CONFIG.CPHA = 1) until
|
||||
* the input serial data is sampled.*/
|
||||
bool use_hw_ss; ///< Indication to use software or hardware controlled Slave Select pin.
|
||||
uint8_t ss_duration; ///< Slave Select duration before and after transmission.
|
||||
/**< Minimum duration between the edge of CSN and the edge of SCK and minimum
|
||||
* duration of CSN must stay inactive between transactions.
|
||||
* The value is specified in number of 64 MHz clock cycles (15.625 ns).
|
||||
* Supported only for hardware controlled Slave Select.*/
|
||||
#endif
|
||||
} nrfx_spim_config_t;
|
||||
|
||||
#if NRFX_CHECK(NRFX_SPIM_EXTENDED_ENABLED) || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief SPIM master instance extended default configuration.
|
||||
*/
|
||||
#define NRFX_SPIM_DEFAULT_EXTENDED_CONFIG \
|
||||
.dcx_pin = NRFX_SPIM_PIN_NOT_USED, \
|
||||
.rx_delay = 0x02, \
|
||||
.ss_duration = 0x02, \
|
||||
.use_hw_ss = false,
|
||||
#else
|
||||
#define NRFX_SPIM_DEFAULT_EXTENDED_CONFIG
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief SPIM master instance default configuration.
|
||||
*/
|
||||
#define NRFX_SPIM_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.sck_pin = NRFX_SPIM_PIN_NOT_USED, \
|
||||
.mosi_pin = NRFX_SPIM_PIN_NOT_USED, \
|
||||
.miso_pin = NRFX_SPIM_PIN_NOT_USED, \
|
||||
.ss_pin = NRFX_SPIM_PIN_NOT_USED, \
|
||||
.ss_active_high = false, \
|
||||
.irq_priority = NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY, \
|
||||
.orc = 0xFF, \
|
||||
.frequency = NRF_SPIM_FREQ_4M, \
|
||||
.mode = NRF_SPIM_MODE_0, \
|
||||
.bit_order = NRF_SPIM_BIT_ORDER_MSB_FIRST, \
|
||||
NRFX_SPIM_DEFAULT_EXTENDED_CONFIG \
|
||||
}
|
||||
|
||||
#define NRFX_SPIM_FLAG_TX_POSTINC (1UL << 0) /**< TX buffer address incremented after transfer. */
|
||||
#define NRFX_SPIM_FLAG_RX_POSTINC (1UL << 1) /**< RX buffer address incremented after transfer. */
|
||||
#define NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER (1UL << 2) /**< Interrupt after each transfer is suppressed, and the event handler is not called. */
|
||||
#define NRFX_SPIM_FLAG_HOLD_XFER (1UL << 3) /**< Set up the transfer but do not start it. */
|
||||
#define NRFX_SPIM_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.
|
||||
size_t tx_length; ///< TX buffer length.
|
||||
uint8_t * p_rx_buffer; ///< Pointer to RX buffer.
|
||||
size_t rx_length; ///< RX buffer length.
|
||||
} nrfx_spim_xfer_desc_t;
|
||||
|
||||
/**
|
||||
* @brief Macro for setting up single transfer descriptor.
|
||||
*
|
||||
* This macro is for internal use only.
|
||||
*/
|
||||
#define NRFX_SPIM_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 NRFX_SPIM_XFER_TRX(p_tx_buf, tx_length, p_rx_buf, rx_length) \
|
||||
NRFX_SPIM_SINGLE_XFER(p_tx_buf, tx_length, p_rx_buf, rx_length)
|
||||
|
||||
/**
|
||||
* @brief Macro for setting TX transfer.
|
||||
*/
|
||||
#define NRFX_SPIM_XFER_TX(p_buf, length) \
|
||||
NRFX_SPIM_SINGLE_XFER(p_buf, length, NULL, 0)
|
||||
|
||||
/**
|
||||
* @brief Macro for setting RX transfer.
|
||||
*/
|
||||
#define NRFX_SPIM_XFER_RX(p_buf, length) \
|
||||
NRFX_SPIM_SINGLE_XFER(NULL, 0, p_buf, length)
|
||||
|
||||
/**
|
||||
* @brief SPIM master driver event types, passed to the handler routine provided
|
||||
* during initialization.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRFX_SPIM_EVENT_DONE, ///< Transfer done.
|
||||
} nrfx_spim_evt_type_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
nrfx_spim_evt_type_t type; ///< Event type.
|
||||
nrfx_spim_xfer_desc_t xfer_desc; ///< Transfer details.
|
||||
} nrfx_spim_evt_t;
|
||||
|
||||
/**
|
||||
* @brief SPIM master driver event handler type.
|
||||
*/
|
||||
typedef void (* nrfx_spim_evt_handler_t)(nrfx_spim_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.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_config Pointer to the structure with 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 NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver was already initialized.
|
||||
* @retval NRFX_ERROR_BUSY If 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_NOT_SUPPORTED If requested configuration is not supported
|
||||
* by the SPIM instance.
|
||||
*/
|
||||
nrfx_err_t nrfx_spim_init(nrfx_spim_t const * const p_instance,
|
||||
nrfx_spim_config_t const * p_config,
|
||||
nrfx_spim_evt_handler_t handler,
|
||||
void * p_context);
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing the SPI master driver instance.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_spim_uninit(nrfx_spim_t const * const p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for starting the SPI data transfer.
|
||||
*
|
||||
* Additional options are provided using the @c flags parameter:
|
||||
*
|
||||
* - @ref NRFX_SPIM_FLAG_TX_POSTINC and @ref NRFX_SPIM_FLAG_RX_POSTINC<span></span>:
|
||||
* Post-incrementation of buffer addresses. Supported only by SPIM.
|
||||
* - @ref NRFX_SPIM_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 nrfx_spim_start_task_get to get the address of the start task.
|
||||
* - @ref NRFX_SPIM_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 NRFX_SPIM_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 nrfx_spim_end_event_get function can be used to detect end of transfer. Option can be used
|
||||
* together with @ref NRFX_SPIM_FLAG_REPEATED_XFER to prepare a sequence of SPI transfers
|
||||
* without interruptions.
|
||||
* - @ref NRFX_SPIM_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 NRFX_SPIM_FLAG_RX_POSTINC,
|
||||
* @ref NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER, and @ref NRFX_SPIM_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 nrfx_spim_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 NRFX_SPIM_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 Peripherals using EasyDMA (including SPIM) 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 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 NRFX_SUCCESS If the procedure was successful.
|
||||
* @retval NRFX_ERROR_BUSY If the driver is not ready for a new transfer.
|
||||
* @retval NRFX_ERROR_NOT_SUPPORTED If the provided parameters are not supported.
|
||||
* @retval NRFX_ERROR_INVALID_ADDR If the provided buffers are not placed in the Data
|
||||
* RAM region.
|
||||
*/
|
||||
nrfx_err_t nrfx_spim_xfer(nrfx_spim_t const * const p_instance,
|
||||
nrfx_spim_xfer_desc_t const * p_xfer_desc,
|
||||
uint32_t flags);
|
||||
|
||||
#if NRFX_CHECK(NRFX_SPIM_EXTENDED_ENABLED) || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Function for starting the SPI data transfer with DCX control.
|
||||
*
|
||||
* See @ref nrfx_spim_xfer for description of additional options of transfer
|
||||
* provided by the @c flags parameter.
|
||||
*
|
||||
* @note Peripherals that use EasyDMA (including SPIM) 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 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).
|
||||
* @param cmd_length Length of the command bytes preceding the data
|
||||
* bytes. The DCX line will be low during transmission
|
||||
* of command bytes and high during transmission of data bytes.
|
||||
* Maximum value available for dividing the transmitted bytes
|
||||
* into command bytes and data bytes is @ref NRF_SPIM_DCX_CNT_ALL_CMD - 1.
|
||||
* The @ref NRF_SPIM_DCX_CNT_ALL_CMD value passed as the
|
||||
* @c cmd_length parameter causes all transmitted bytes
|
||||
* to be marked as command bytes.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the procedure was successful.
|
||||
* @retval NRFX_ERROR_BUSY If the driver is not ready for a new transfer.
|
||||
* @retval NRFX_ERROR_NOT_SUPPORTED If the provided parameters are not supported.
|
||||
* @retval NRFX_ERROR_INVALID_ADDR If the provided buffers are not placed in the Data
|
||||
* RAM region.
|
||||
*/
|
||||
nrfx_err_t nrfx_spim_xfer_dcx(nrfx_spim_t const * const p_instance,
|
||||
nrfx_spim_xfer_desc_t const * p_xfer_desc,
|
||||
uint32_t flags,
|
||||
uint8_t cmd_length);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a SPIM start task.
|
||||
*
|
||||
* This function should be used if @ref nrfx_spim_xfer was called with the flag @ref NRFX_SPIM_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.
|
||||
*/
|
||||
uint32_t nrfx_spim_start_task_get(nrfx_spim_t const * p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a END SPIM event.
|
||||
*
|
||||
* The END event can be used to detect the end of a transfer
|
||||
* if the @ref NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER option is used.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*
|
||||
* @return END event address.
|
||||
*/
|
||||
uint32_t nrfx_spim_end_event_get(nrfx_spim_t const * p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for aborting ongoing transfer.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_spim_abort(nrfx_spim_t const * p_instance);
|
||||
|
||||
|
||||
void nrfx_spim_0_irq_handler(void);
|
||||
void nrfx_spim_1_irq_handler(void);
|
||||
void nrfx_spim_2_irq_handler(void);
|
||||
void nrfx_spim_3_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRFX_SPIM_H__
|
||||
@@ -0,0 +1,241 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 <nrfx.h>
|
||||
#include <hal/nrf_spis.h>
|
||||
#include <hal/nrf_gpio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrfx_spis SPI slave driver
|
||||
* @{
|
||||
* @ingroup nrf_spis
|
||||
* @brief SPI Slave peripheral driver.
|
||||
*/
|
||||
|
||||
/** @brief SPI slave driver instance data structure. */
|
||||
typedef struct
|
||||
{
|
||||
NRF_SPIS_Type * p_reg; //!< Pointer to a structure with SPIS registers.
|
||||
uint8_t drv_inst_idx; //!< Driver instance index.
|
||||
} nrfx_spis_t;
|
||||
|
||||
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
|
||||
NRFX_SPIS_ENABLED_COUNT
|
||||
};
|
||||
|
||||
/** @brief Macro for creating an SPI slave driver instance. */
|
||||
#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 SPI slave instance default configuration. */
|
||||
#define NRFX_SPIS_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.sck_pin = NRFX_SPIS_PIN_NOT_USED, \
|
||||
.mosi_pin = NRFX_SPIS_PIN_NOT_USED, \
|
||||
.miso_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 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 If the initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the instance is already initialized.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If an invalid parameter is supplied.
|
||||
* @retval NRFX_ERROR_BUSY If 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. Note that 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 should 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 If the operation was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the operation failed because the SPI slave device is in an incorrect state.
|
||||
* @retval NRFX_ERROR_INVALID_ADDR If the provided buffers are not placed in the Data
|
||||
* RAM region.
|
||||
* @retval NRFX_ERROR_INVALID_LENGTH If provided lengths exceed the EasyDMA limits for the peripheral.
|
||||
* @retval NRFX_ERROR_INTERNAL If 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);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRFX_SPIS_H__
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 <nrfx.h>
|
||||
|
||||
#if NRFX_CHECK(NRFX_EGU_ENABLED)
|
||||
#include <hal/nrf_egu.h>
|
||||
#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.
|
||||
*
|
||||
* @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 If the SWI was successfully allocated.
|
||||
* @retval NRFX_ERROR_NO_MEM If 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 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 If the SWI instance is allocated.
|
||||
* @retval false Otherwise.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @returns 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) * (NRF_EGU1_BASE - NRF_EGU0_BASE);
|
||||
return (NRF_EGU_Type *)(NRF_EGU0_BASE + offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function for returning the EGU trigger task address.
|
||||
*
|
||||
* @param[in] swi SWI instance.
|
||||
* @param[in] channel Number of the EGU channel.
|
||||
*
|
||||
* @returns Address of 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.
|
||||
*
|
||||
* @returns Address of 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__
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 <nrfx.h>
|
||||
#include <hal/nrf_systick.h>
|
||||
|
||||
#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-bits wide.
|
||||
* It means that it overflows around 4 times per second and around 250 ms
|
||||
* would be the highest supported time in the library.
|
||||
* But it would be really hard to detect if overflow was generated without
|
||||
* using interrupts. For safety we would limit the maximum delay range by half.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @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 Configure and start the timer
|
||||
*
|
||||
* Function configures SysTick as a free-running timer without interrupt.
|
||||
*/
|
||||
void nrfx_systick_init(void);
|
||||
|
||||
/**
|
||||
* @brief Get current SysTick state
|
||||
*
|
||||
* Function gets 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 Test if specified time is up in relation to remembered state
|
||||
*
|
||||
* @param[in] p_state Remembered state set by @ref nrfx_systick_get
|
||||
* @param[in] us Required time-out.
|
||||
*
|
||||
* @retval true If current time is higher than specified state plus given time-out.
|
||||
* @retval false If current time is lower than specified state plus given time-out
|
||||
*/
|
||||
bool nrfx_systick_test(nrfx_systick_state_t const * p_state, uint32_t us);
|
||||
|
||||
/**
|
||||
* @brief Blocking delay in CPU ticks
|
||||
*
|
||||
* @param[in] ticks Number of CPU ticks to delay.
|
||||
*/
|
||||
void nrfx_systick_delay_ticks(uint32_t ticks);
|
||||
|
||||
/**
|
||||
* @brief Blocking delay in us
|
||||
*
|
||||
* @param[in] us Number of microseconds to delay.
|
||||
*/
|
||||
void nrfx_systick_delay_us(uint32_t us);
|
||||
|
||||
/**
|
||||
* @brief Blocking delay in ms
|
||||
*
|
||||
* This delay function removes the limits of the highest possible delay value.
|
||||
*
|
||||
* @param[in] ms Number of milliseconds to delay.
|
||||
*/
|
||||
void nrfx_systick_delay_ms(uint32_t ms);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRFX_SYSTICK_H__ */
|
||||
@@ -0,0 +1,404 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_TIMER_H__
|
||||
#define NRFX_TIMER_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
#include <hal/nrf_timer.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrfx_timer Timer driver
|
||||
* @{
|
||||
* @ingroup nrf_timer
|
||||
* @brief TIMER peripheral driver.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Timer driver instance data structure.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
NRF_TIMER_Type * p_reg; ///< Pointer to the structure with TIMER peripheral instance registers.
|
||||
uint8_t instance_id; ///< Driver instance index.
|
||||
uint8_t cc_channel_count; ///< Number of capture/compare channels.
|
||||
} nrfx_timer_t;
|
||||
|
||||
/**
|
||||
* @brief Macro for creating a timer driver instance.
|
||||
*/
|
||||
#define NRFX_TIMER_INSTANCE(id) \
|
||||
{ \
|
||||
.p_reg = NRFX_CONCAT_2(NRF_TIMER, id), \
|
||||
.instance_id = NRFX_CONCAT_3(NRFX_TIMER, id, _INST_IDX), \
|
||||
.cc_channel_count = NRF_TIMER_CC_CHANNEL_COUNT(id), \
|
||||
}
|
||||
|
||||
enum {
|
||||
#if NRFX_CHECK(NRFX_TIMER0_ENABLED)
|
||||
NRFX_TIMER0_INST_IDX,
|
||||
#endif
|
||||
#if NRFX_CHECK(NRFX_TIMER1_ENABLED)
|
||||
NRFX_TIMER1_INST_IDX,
|
||||
#endif
|
||||
#if NRFX_CHECK(NRFX_TIMER2_ENABLED)
|
||||
NRFX_TIMER2_INST_IDX,
|
||||
#endif
|
||||
#if NRFX_CHECK(NRFX_TIMER3_ENABLED)
|
||||
NRFX_TIMER3_INST_IDX,
|
||||
#endif
|
||||
#if NRFX_CHECK(NRFX_TIMER4_ENABLED)
|
||||
NRFX_TIMER4_INST_IDX,
|
||||
#endif
|
||||
NRFX_TIMER_ENABLED_COUNT
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Timer driver instance configuration structure.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrf_timer_frequency_t frequency; ///< Frequency.
|
||||
nrf_timer_mode_t mode; ///< Mode of operation.
|
||||
nrf_timer_bit_width_t bit_width; ///< Bit width.
|
||||
uint8_t interrupt_priority; ///< Interrupt priority.
|
||||
void * p_context; ///< Context passed to interrupt handler.
|
||||
} nrfx_timer_config_t;
|
||||
|
||||
/**
|
||||
* @brief Timer driver instance default configuration.
|
||||
*/
|
||||
#define NRFX_TIMER_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.frequency = (nrf_timer_frequency_t)NRFX_TIMER_DEFAULT_CONFIG_FREQUENCY,\
|
||||
.mode = (nrf_timer_mode_t)NRFX_TIMER_DEFAULT_CONFIG_MODE, \
|
||||
.bit_width = (nrf_timer_bit_width_t)NRFX_TIMER_DEFAULT_CONFIG_BIT_WIDTH,\
|
||||
.interrupt_priority = NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY, \
|
||||
.p_context = NULL \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Timer driver event handler type.
|
||||
*
|
||||
* @param[in] event_type Timer event.
|
||||
* @param[in] p_context General purpose parameter set during initialization of
|
||||
* the timer. This parameter can be used to pass
|
||||
* additional information to the handler function, for
|
||||
* example, the timer ID.
|
||||
*/
|
||||
typedef void (* nrfx_timer_event_handler_t)(nrf_timer_event_t event_type,
|
||||
void * p_context);
|
||||
|
||||
/**
|
||||
* @brief Function for initializing the timer.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_config Pointer to the structure with initial configuration.
|
||||
* @param[in] timer_event_handler Event handler provided by the user.
|
||||
* Must not be NULL.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the instance is already initialized.
|
||||
*/
|
||||
nrfx_err_t nrfx_timer_init(nrfx_timer_t const * const p_instance,
|
||||
nrfx_timer_config_t const * p_config,
|
||||
nrfx_timer_event_handler_t timer_event_handler);
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing the timer.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_timer_uninit(nrfx_timer_t const * const p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for turning on the timer.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_timer_enable(nrfx_timer_t const * const p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for turning off the timer.
|
||||
*
|
||||
* Note that the timer will allow to enter the lowest possible SYSTEM_ON state
|
||||
* only after this function is called.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_timer_disable(nrfx_timer_t const * const p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the timer state.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*
|
||||
* @return True if timer is enabled, false otherwise.
|
||||
*/
|
||||
bool nrfx_timer_is_enabled(nrfx_timer_t const * const p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for pausing the timer.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_timer_pause(nrfx_timer_t const * const p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for resuming the timer.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_timer_resume(nrfx_timer_t const * const p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing the timer.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_timer_clear(nrfx_timer_t const * const p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for incrementing the timer.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_timer_increment(nrfx_timer_t const * const p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a specific timer task.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] timer_task Timer task.
|
||||
*
|
||||
* @return Task address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_timer_task_address_get(nrfx_timer_t const * const p_instance,
|
||||
nrf_timer_task_t timer_task);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a specific timer capture task.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] channel Capture channel number.
|
||||
*
|
||||
* @return Task address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_timer_capture_task_address_get(nrfx_timer_t const * const p_instance,
|
||||
uint32_t channel);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a specific timer event.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] timer_event Timer event.
|
||||
*
|
||||
* @return Event address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_timer_event_address_get(nrfx_timer_t const * const p_instance,
|
||||
nrf_timer_event_t timer_event);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a specific timer compare event.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] channel Compare channel number.
|
||||
*
|
||||
* @return Event address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_timer_compare_event_address_get(nrfx_timer_t const * const p_instance,
|
||||
uint32_t channel);
|
||||
|
||||
/**
|
||||
* @brief Function for capturing the timer value.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] cc_channel Capture channel number.
|
||||
*
|
||||
* @return Captured value.
|
||||
*/
|
||||
uint32_t nrfx_timer_capture(nrfx_timer_t const * const p_instance,
|
||||
nrf_timer_cc_channel_t cc_channel);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the capture value from a specific channel.
|
||||
*
|
||||
* Use this function to read channel values when PPI is used for capturing.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] cc_channel Capture channel number.
|
||||
*
|
||||
* @return Captured value.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_timer_capture_get(nrfx_timer_t const * const p_instance,
|
||||
nrf_timer_cc_channel_t cc_channel);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the timer channel in compare mode.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] cc_channel Compare channel number.
|
||||
* @param[in] cc_value Compare value.
|
||||
* @param[in] enable_int Enable or disable the interrupt for the compare channel.
|
||||
*/
|
||||
void nrfx_timer_compare(nrfx_timer_t const * const p_instance,
|
||||
nrf_timer_cc_channel_t cc_channel,
|
||||
uint32_t cc_value,
|
||||
bool enable_int);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the timer channel in extended compare mode.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] cc_channel Compare channel number.
|
||||
* @param[in] cc_value Compare value.
|
||||
* @param[in] timer_short_mask Shortcut between the compare event on the channel
|
||||
* and the timer task (STOP or CLEAR).
|
||||
* @param[in] enable_int Enable or disable the interrupt for the compare
|
||||
* channel.
|
||||
*/
|
||||
void nrfx_timer_extended_compare(nrfx_timer_t const * const p_instance,
|
||||
nrf_timer_cc_channel_t cc_channel,
|
||||
uint32_t cc_value,
|
||||
nrf_timer_short_mask_t timer_short_mask,
|
||||
bool enable_int);
|
||||
|
||||
/**
|
||||
* @brief Function for converting time in microseconds to timer ticks.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] time_us Time in microseconds.
|
||||
*
|
||||
* @return Number of ticks.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_timer_us_to_ticks(nrfx_timer_t const * const p_instance,
|
||||
uint32_t time_us);
|
||||
|
||||
/**
|
||||
* @brief Function for converting time in milliseconds to timer ticks.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] time_ms Time in milliseconds.
|
||||
*
|
||||
* @return Number of ticks.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_timer_ms_to_ticks(nrfx_timer_t const * const p_instance,
|
||||
uint32_t time_ms);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling timer compare interrupt.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] channel Compare channel.
|
||||
*/
|
||||
void nrfx_timer_compare_int_enable(nrfx_timer_t const * const p_instance,
|
||||
uint32_t channel);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling timer compare interrupt.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] channel Compare channel.
|
||||
*/
|
||||
void nrfx_timer_compare_int_disable(nrfx_timer_t const * const p_instance,
|
||||
uint32_t channel);
|
||||
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
__STATIC_INLINE uint32_t nrfx_timer_task_address_get(nrfx_timer_t const * const p_instance,
|
||||
nrf_timer_task_t timer_task)
|
||||
{
|
||||
return (uint32_t)nrf_timer_task_address_get(p_instance->p_reg, timer_task);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrfx_timer_capture_task_address_get(nrfx_timer_t const * const p_instance,
|
||||
uint32_t channel)
|
||||
{
|
||||
NRFX_ASSERT(channel < p_instance->cc_channel_count);
|
||||
return (uint32_t)nrf_timer_task_address_get(p_instance->p_reg,
|
||||
nrf_timer_capture_task_get(channel));
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrfx_timer_event_address_get(nrfx_timer_t const * const p_instance,
|
||||
nrf_timer_event_t timer_event)
|
||||
{
|
||||
return (uint32_t)nrf_timer_event_address_get(p_instance->p_reg, timer_event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrfx_timer_compare_event_address_get(nrfx_timer_t const * const p_instance,
|
||||
uint32_t channel)
|
||||
{
|
||||
NRFX_ASSERT(channel < p_instance->cc_channel_count);
|
||||
return (uint32_t)nrf_timer_event_address_get(p_instance->p_reg,
|
||||
nrf_timer_compare_event_get(channel));
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrfx_timer_capture_get(nrfx_timer_t const * const p_instance,
|
||||
nrf_timer_cc_channel_t cc_channel)
|
||||
{
|
||||
return nrf_timer_cc_read(p_instance->p_reg, cc_channel);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrfx_timer_us_to_ticks(nrfx_timer_t const * const p_instance,
|
||||
uint32_t timer_us)
|
||||
{
|
||||
return nrf_timer_us_to_ticks(timer_us, nrf_timer_frequency_get(p_instance->p_reg));
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrfx_timer_ms_to_ticks(nrfx_timer_t const * const p_instance,
|
||||
uint32_t timer_ms)
|
||||
{
|
||||
return nrf_timer_ms_to_ticks(timer_ms, nrf_timer_frequency_get(p_instance->p_reg));
|
||||
}
|
||||
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
|
||||
void nrfx_timer_0_irq_handler(void);
|
||||
void nrfx_timer_1_irq_handler(void);
|
||||
void nrfx_timer_2_irq_handler(void);
|
||||
void nrfx_timer_3_irq_handler(void);
|
||||
void nrfx_timer_4_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRFX_TIMER_H__
|
||||
|
||||
@@ -0,0 +1,359 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_TWI_H__
|
||||
#define NRFX_TWI_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
#include <hal/nrf_twi.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrfx_twi TWI driver
|
||||
* @{
|
||||
* @ingroup nrf_twi
|
||||
* @brief TWI peripheral driver.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Structure for the TWI master driver instance.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
NRF_TWI_Type * p_twi; ///< Pointer to a structure with TWI registers.
|
||||
uint8_t drv_inst_idx; ///< Driver instance index.
|
||||
} nrfx_twi_t;
|
||||
|
||||
/**
|
||||
* @brief Macro for creating a TWI master driver instance.
|
||||
*/
|
||||
#define NRFX_TWI_INSTANCE(id) \
|
||||
{ \
|
||||
.p_twi = NRFX_CONCAT_2(NRF_TWI, id), \
|
||||
.drv_inst_idx = NRFX_CONCAT_3(NRFX_TWI, id, _INST_IDX), \
|
||||
}
|
||||
|
||||
enum {
|
||||
#if NRFX_CHECK(NRFX_TWI0_ENABLED)
|
||||
NRFX_TWI0_INST_IDX,
|
||||
#endif
|
||||
#if NRFX_CHECK(NRFX_TWI1_ENABLED)
|
||||
NRFX_TWI1_INST_IDX,
|
||||
#endif
|
||||
NRFX_TWI_ENABLED_COUNT
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Structure for the TWI master driver instance configuration.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t scl; ///< SCL pin number.
|
||||
uint32_t sda; ///< SDA pin number.
|
||||
nrf_twi_frequency_t frequency; ///< TWI frequency.
|
||||
uint8_t interrupt_priority; ///< Interrupt priority.
|
||||
bool hold_bus_uninit; ///< Hold pull up state on gpio pins after uninit.
|
||||
} nrfx_twi_config_t;
|
||||
|
||||
/**
|
||||
* @brief TWI master driver instance default configuration.
|
||||
*/
|
||||
#define NRFX_TWI_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.frequency = (nrf_twi_frequency_t)NRFX_TWI_DEFAULT_CONFIG_FREQUENCY, \
|
||||
.scl = 31, \
|
||||
.sda = 31, \
|
||||
.interrupt_priority = NRFX_TWI_DEFAULT_CONFIG_IRQ_PRIORITY, \
|
||||
.hold_bus_uninit = NRFX_TWI_DEFAULT_CONFIG_HOLD_BUS_UNINIT, \
|
||||
}
|
||||
|
||||
#define NRFX_TWI_FLAG_NO_XFER_EVT_HANDLER (1UL << 2) /**< Interrupt after each transfer is suppressed, and the event handler is not called. */
|
||||
#define NRFX_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
|
||||
{
|
||||
NRFX_TWI_EVT_DONE, ///< Transfer completed event.
|
||||
NRFX_TWI_EVT_ADDRESS_NACK, ///< Error event: NACK received after sending the address.
|
||||
NRFX_TWI_EVT_DATA_NACK ///< Error event: NACK received after sending a data byte.
|
||||
} nrfx_twi_evt_type_t;
|
||||
|
||||
/**
|
||||
* @brief TWI master driver transfer types.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRFX_TWI_XFER_TX, ///< TX transfer.
|
||||
NRFX_TWI_XFER_RX, ///< RX transfer.
|
||||
NRFX_TWI_XFER_TXRX, ///< TX transfer followed by RX transfer with repeated start.
|
||||
NRFX_TWI_XFER_TXTX ///< TX transfer followed by TX transfer with repeated start.
|
||||
} nrfx_twi_xfer_type_t;
|
||||
|
||||
/**
|
||||
* @brief Structure for a TWI transfer descriptor.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrfx_twi_xfer_type_t type; ///< Type of transfer.
|
||||
uint8_t address; ///< Slave address.
|
||||
size_t primary_length; ///< Number of bytes transferred.
|
||||
size_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.
|
||||
} nrfx_twi_xfer_desc_t;
|
||||
|
||||
|
||||
/**@brief Macro for setting the TX transfer descriptor. */
|
||||
#define NRFX_TWI_XFER_DESC_TX(addr, p_data, length) \
|
||||
{ \
|
||||
.type = NRFX_TWI_XFER_TX, \
|
||||
.address = addr, \
|
||||
.primary_length = length, \
|
||||
.p_primary_buf = p_data, \
|
||||
}
|
||||
|
||||
/**@brief Macro for setting the RX transfer descriptor. */
|
||||
#define NRFX_TWI_XFER_DESC_RX(addr, p_data, length) \
|
||||
{ \
|
||||
.type = NRFX_TWI_XFER_RX, \
|
||||
.address = addr, \
|
||||
.primary_length = length, \
|
||||
.p_primary_buf = p_data, \
|
||||
}
|
||||
|
||||
/**@brief Macro for setting the TXRX transfer descriptor. */
|
||||
#define NRFX_TWI_XFER_DESC_TXRX(addr, p_tx, tx_len, p_rx, rx_len) \
|
||||
{ \
|
||||
.type = NRFX_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 NRFX_TWI_XFER_DESC_TXTX(addr, p_tx, tx_len, p_tx2, tx_len2) \
|
||||
{ \
|
||||
.type = NRFX_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
|
||||
{
|
||||
nrfx_twi_evt_type_t type; ///< Event type.
|
||||
nrfx_twi_xfer_desc_t xfer_desc; ///< Transfer details.
|
||||
} nrfx_twi_evt_t;
|
||||
|
||||
/**
|
||||
* @brief TWI event handler prototype.
|
||||
*/
|
||||
typedef void (* nrfx_twi_evt_handler_t)(nrfx_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 Pointer to the structure with 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 NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver is in invalid state.
|
||||
* @retval NRFX_ERROR_BUSY If some other peripheral with the same
|
||||
* instance ID is already in use. This is
|
||||
* possible only if @ref nrfx_prs module
|
||||
* is enabled.
|
||||
*/
|
||||
nrfx_err_t nrfx_twi_init(nrfx_twi_t const * p_instance,
|
||||
nrfx_twi_config_t const * p_config,
|
||||
nrfx_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.
|
||||
*/
|
||||
void nrfx_twi_uninit(nrfx_twi_t const * p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling the TWI instance.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_twi_enable(nrfx_twi_t const * p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling the TWI instance.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_twi_disable(nrfx_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 NRFX_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 NRFX_SUCCESS If the procedure was successful.
|
||||
* @retval NRFX_ERROR_BUSY If the driver is not ready for a new transfer.
|
||||
* @retval NRFX_ERROR_INTERNAL If an error was detected by hardware.
|
||||
* @retval NRFX_ERROR_DRV_TWI_ERR_ANACK If NACK received after sending the address in polling mode.
|
||||
* @retval NRFX_ERROR_DRV_TWI_ERR_DNACK If NACK received after sending a data byte in polling mode.
|
||||
*/
|
||||
nrfx_err_t nrfx_twi_tx(nrfx_twi_t const * p_instance,
|
||||
uint8_t address,
|
||||
uint8_t const * p_data,
|
||||
size_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 NRFX_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 NRFX_SUCCESS If the procedure was successful.
|
||||
* @retval NRFX_ERROR_BUSY If the driver is not ready for a new transfer.
|
||||
* @retval NRFX_ERROR_INTERNAL If an error was detected by hardware.
|
||||
* @retval NRFX_ERROR_DRV_TWI_ERR_OVERRUN If the unread data was replaced by new data
|
||||
* @retval NRFX_ERROR_DRV_TWI_ERR_ANACK If NACK received after sending the address in polling mode.
|
||||
* @retval NRFX_ERROR_DRV_TWI_ERR_DNACK If NACK received after sending a data byte in polling mode.
|
||||
*/
|
||||
nrfx_err_t nrfx_twi_rx(nrfx_twi_t const * p_instance,
|
||||
uint8_t address,
|
||||
uint8_t * p_data,
|
||||
size_t length);
|
||||
|
||||
/**
|
||||
* @brief Function for preparing a TWI transfer.
|
||||
*
|
||||
* The following transfer types can be configured (@ref nrfx_twi_xfer_desc_t::type):
|
||||
* - @ref NRFX_TWI_XFER_TXRX<span></span>: Write operation followed by a read operation (without STOP condition in between).
|
||||
* - @ref NRFX_TWI_XFER_TXTX<span></span>: Write operation followed by a write operation (without STOP condition in between).
|
||||
* - @ref NRFX_TWI_XFER_TX<span></span>: Write operation (with or without STOP condition).
|
||||
* - @ref NRFX_TWI_XFER_RX<span></span>: Read operation (with STOP condition).
|
||||
*
|
||||
* @note TXRX and TXTX transfers are supported only in non-blocking mode.
|
||||
*
|
||||
* Additional options are provided using the flags parameter:
|
||||
* - @ref NRFX_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 NRFX_TWI_FLAG_TX_NO_STOP<span></span>: No stop condition after TX transfer.
|
||||
*
|
||||
* @note
|
||||
* Some flag combinations are invalid:
|
||||
* - @ref NRFX_TWI_FLAG_TX_NO_STOP with @ref nrfx_twi_xfer_desc_t::type different than @ref NRFX_TWI_XFER_TX
|
||||
*
|
||||
* @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 NRFX_SUCCESS If the procedure was successful.
|
||||
* @retval NRFX_ERROR_BUSY If the driver is not ready for a new transfer.
|
||||
* @retval NRFX_ERROR_NOT_SUPPORTED If the provided parameters are not supported.
|
||||
* @retval NRFX_ERROR_INTERNAL If an error was detected by hardware.
|
||||
* @retval NRFX_ERROR_DRV_TWI_ERR_OVERRUN If the unread data was replaced by new data (TXRX and RX)
|
||||
* @retval NRFX_ERROR_DRV_TWI_ERR_ANACK If NACK received after sending the address.
|
||||
* @retval NRFX_ERROR_DRV_TWI_ERR_DNACK If NACK received after sending a data byte.
|
||||
*/
|
||||
nrfx_err_t nrfx_twi_xfer(nrfx_twi_t const * p_instance,
|
||||
nrfx_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.
|
||||
*/
|
||||
bool nrfx_twi_is_busy(nrfx_twi_t const * p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the transferred data count.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*
|
||||
* @return Data count.
|
||||
*/
|
||||
size_t nrfx_twi_data_count_get(nrfx_twi_t const * const p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a STOPPED TWI event.
|
||||
*
|
||||
* A STOPPED event can be used to detect the end of a transfer if the @ref NRFX_TWI_FLAG_NO_XFER_EVT_HANDLER
|
||||
* option is used.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*
|
||||
* @return STOPPED event address.
|
||||
*/
|
||||
uint32_t nrfx_twi_stopped_event_get(nrfx_twi_t const * p_instance);
|
||||
|
||||
void nrfx_twi_0_irq_handler(void);
|
||||
void nrfx_twi_1_irq_handler(void);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRFX_TWI_H__
|
||||
@@ -0,0 +1,399 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_TWIM_H__
|
||||
#define NRFX_TWIM_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
#include <hal/nrf_twim.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrfx_twim TWIM driver
|
||||
* @{
|
||||
* @ingroup nrf_twim
|
||||
* @brief TWIM peripheral driver.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Structure for the TWI master driver instance.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
NRF_TWIM_Type * p_twim; ///< Pointer to a structure with TWIM registers.
|
||||
uint8_t drv_inst_idx; ///< Driver instance index.
|
||||
} nrfx_twim_t;
|
||||
|
||||
/**
|
||||
* @brief Macro for creating a TWI master driver instance.
|
||||
*/
|
||||
#define NRFX_TWIM_INSTANCE(id) \
|
||||
{ \
|
||||
.p_twim = NRFX_CONCAT_2(NRF_TWIM, id), \
|
||||
.drv_inst_idx = NRFX_CONCAT_3(NRFX_TWIM, id, _INST_IDX), \
|
||||
}
|
||||
|
||||
enum {
|
||||
#if NRFX_CHECK(NRFX_TWIM0_ENABLED)
|
||||
NRFX_TWIM0_INST_IDX,
|
||||
#endif
|
||||
#if NRFX_CHECK(NRFX_TWIM1_ENABLED)
|
||||
NRFX_TWIM1_INST_IDX,
|
||||
#endif
|
||||
NRFX_TWIM_ENABLED_COUNT
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Structure for the TWI master driver instance configuration.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t scl; ///< SCL pin number.
|
||||
uint32_t sda; ///< SDA pin number.
|
||||
nrf_twim_frequency_t frequency; ///< TWIM frequency.
|
||||
uint8_t interrupt_priority; ///< Interrupt priority.
|
||||
bool hold_bus_uninit; ///< Hold pull up state on gpio pins after uninit.
|
||||
} nrfx_twim_config_t;
|
||||
|
||||
/**
|
||||
* @brief TWI master driver instance default configuration.
|
||||
*/
|
||||
#define NRFX_TWIM_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.frequency = (nrf_twim_frequency_t)NRFX_TWIM_DEFAULT_CONFIG_FREQUENCY, \
|
||||
.scl = 31, \
|
||||
.sda = 31, \
|
||||
.interrupt_priority = NRFX_TWIM_DEFAULT_CONFIG_IRQ_PRIORITY, \
|
||||
.hold_bus_uninit = NRFX_TWIM_DEFAULT_CONFIG_HOLD_BUS_UNINIT, \
|
||||
}
|
||||
|
||||
#define NRFX_TWIM_FLAG_TX_POSTINC (1UL << 0) /**< TX buffer address incremented after transfer. */
|
||||
#define NRFX_TWIM_FLAG_RX_POSTINC (1UL << 1) /**< RX buffer address incremented after transfer. */
|
||||
#define NRFX_TWIM_FLAG_NO_XFER_EVT_HANDLER (1UL << 2) /**< Interrupt after each transfer is suppressed, and the event handler is not called. */
|
||||
#define NRFX_TWIM_FLAG_HOLD_XFER (1UL << 3) /**< Set up the transfer but do not start it. */
|
||||
#define NRFX_TWIM_FLAG_REPEATED_XFER (1UL << 4) /**< Flag indicating that the transfer will be executed multiple times. */
|
||||
#define NRFX_TWIM_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
|
||||
{
|
||||
NRFX_TWIM_EVT_DONE, ///< Transfer completed event.
|
||||
NRFX_TWIM_EVT_ADDRESS_NACK, ///< Error event: NACK received after sending the address.
|
||||
NRFX_TWIM_EVT_DATA_NACK ///< Error event: NACK received after sending a data byte.
|
||||
} nrfx_twim_evt_type_t;
|
||||
|
||||
/**
|
||||
* @brief TWI master driver transfer types.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRFX_TWIM_XFER_TX, ///< TX transfer.
|
||||
NRFX_TWIM_XFER_RX, ///< RX transfer.
|
||||
NRFX_TWIM_XFER_TXRX, ///< TX transfer followed by RX transfer with repeated start.
|
||||
NRFX_TWIM_XFER_TXTX ///< TX transfer followed by TX transfer with repeated start.
|
||||
} nrfx_twim_xfer_type_t;
|
||||
|
||||
/**
|
||||
* @brief Structure for a TWI transfer descriptor.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrfx_twim_xfer_type_t type; ///< Type of transfer.
|
||||
uint8_t address; ///< Slave address.
|
||||
size_t primary_length; ///< Number of bytes transferred.
|
||||
size_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.
|
||||
} nrfx_twim_xfer_desc_t;
|
||||
|
||||
|
||||
/**@brief Macro for setting the TX transfer descriptor. */
|
||||
#define NRFX_TWIM_XFER_DESC_TX(addr, p_data, length) \
|
||||
{ \
|
||||
.type = NRFX_TWIM_XFER_TX, \
|
||||
.address = addr, \
|
||||
.primary_length = length, \
|
||||
.p_primary_buf = p_data, \
|
||||
}
|
||||
|
||||
/**@brief Macro for setting the RX transfer descriptor. */
|
||||
#define NRFX_TWIM_XFER_DESC_RX(addr, p_data, length) \
|
||||
{ \
|
||||
.type = NRFX_TWIM_XFER_RX, \
|
||||
.address = addr, \
|
||||
.primary_length = length, \
|
||||
.p_primary_buf = p_data, \
|
||||
}
|
||||
|
||||
/**@brief Macro for setting the TXRX transfer descriptor. */
|
||||
#define NRFX_TWIM_XFER_DESC_TXRX(addr, p_tx, tx_len, p_rx, rx_len) \
|
||||
{ \
|
||||
.type = NRFX_TWIM_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 NRFX_TWIM_XFER_DESC_TXTX(addr, p_tx, tx_len, p_tx2, tx_len2) \
|
||||
{ \
|
||||
.type = NRFX_TWIM_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
|
||||
{
|
||||
nrfx_twim_evt_type_t type; ///< Event type.
|
||||
nrfx_twim_xfer_desc_t xfer_desc; ///< Transfer details.
|
||||
} nrfx_twim_evt_t;
|
||||
|
||||
/**
|
||||
* @brief TWI event handler prototype.
|
||||
*/
|
||||
typedef void (* nrfx_twim_evt_handler_t)(nrfx_twim_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 Pointer to the structure with 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 NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver is in invalid state.
|
||||
* @retval NRFX_ERROR_BUSY If some other peripheral with the same
|
||||
* instance ID is already in use. This is
|
||||
* possible only if @ref nrfx_prs module
|
||||
* is enabled.
|
||||
*/
|
||||
nrfx_err_t nrfx_twim_init(nrfx_twim_t const * p_instance,
|
||||
nrfx_twim_config_t const * p_config,
|
||||
nrfx_twim_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.
|
||||
*/
|
||||
void nrfx_twim_uninit(nrfx_twim_t const * p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling the TWI instance.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_twim_enable(nrfx_twim_t const * p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling the TWI instance.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_twim_disable(nrfx_twim_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 NRFX_ERROR_BUSY.
|
||||
*
|
||||
* @note Peripherals using EasyDMA (including TWIM) 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] 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. Maximum possible length is
|
||||
* dependent on the used SoC (see the MAXCNT register
|
||||
* description in the Product Specification). The driver
|
||||
* checks it with assertion.
|
||||
* @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 NRFX_SUCCESS If the procedure was successful.
|
||||
* @retval NRFX_ERROR_BUSY If the driver is not ready for a new transfer.
|
||||
* @retval NRFX_ERROR_INTERNAL If an error was detected by hardware.
|
||||
* @retval NRFX_ERROR_INVALID_ADDR If the provided buffer is not placed in the Data RAM region.
|
||||
* @retval NRFX_ERROR_DRV_TWI_ERR_ANACK If NACK received after sending the address in polling mode.
|
||||
* @retval NRFX_ERROR_DRV_TWI_ERR_DNACK If NACK received after sending a data byte in polling mode.
|
||||
*/
|
||||
nrfx_err_t nrfx_twim_tx(nrfx_twim_t const * p_instance,
|
||||
uint8_t address,
|
||||
uint8_t const * p_data,
|
||||
size_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 NRFX_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. Maximum possible length
|
||||
* is dependent on the used SoC (see the MAXCNT register
|
||||
* description in the Product Specification). The driver
|
||||
* checks it with assertion.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the procedure was successful.
|
||||
* @retval NRFX_ERROR_BUSY If the driver is not ready for a new transfer.
|
||||
* @retval NRFX_ERROR_INTERNAL If an error was detected by hardware.
|
||||
* @retval NRFX_ERROR_DRV_TWI_ERR_ANACK If NACK received after sending the address in polling mode.
|
||||
* @retval NRFX_ERROR_DRV_TWI_ERR_DNACK If NACK received after sending a data byte in polling mode.
|
||||
*/
|
||||
nrfx_err_t nrfx_twim_rx(nrfx_twim_t const * p_instance,
|
||||
uint8_t address,
|
||||
uint8_t * p_data,
|
||||
size_t length);
|
||||
|
||||
/**
|
||||
* @brief Function for preparing a TWI transfer.
|
||||
*
|
||||
* The following transfer types can be configured (@ref nrfx_twim_xfer_desc_t::type):
|
||||
* - @ref NRFX_TWIM_XFER_TXRX<span></span>: Write operation followed by a read operation (without STOP condition in between).
|
||||
* - @ref NRFX_TWIM_XFER_TXTX<span></span>: Write operation followed by a write operation (without STOP condition in between).
|
||||
* - @ref NRFX_TWIM_XFER_TX<span></span>: Write operation (with or without STOP condition).
|
||||
* - @ref NRFX_TWIM_XFER_RX<span></span>: Read operation (with STOP condition).
|
||||
*
|
||||
* @note TXRX and TXTX transfers are supported only in non-blocking mode.
|
||||
*
|
||||
* Additional options are provided using the flags parameter:
|
||||
* - @ref NRFX_TWIM_FLAG_TX_POSTINC and @ref NRFX_TWIM_FLAG_RX_POSTINC<span></span>: Post-incrementation of buffer addresses. Supported only by TWIM.
|
||||
* - @ref NRFX_TWIM_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 NRFX_TWIM_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 nrfx_twim_start_task_get to get the address of the start task.
|
||||
* - @ref NRFX_TWIM_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 NRFX_TWIM_FLAG_RX_POSTINC, @ref NRFX_TWIM_FLAG_NO_XFER_EVT_HANDLER, and @ref NRFX_TWIM_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 nrfx_twim_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 NRFX_TWIM_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 NRFX_TWIM_FLAG_TX_NO_STOP<span></span>: No stop condition after TX transfer.
|
||||
*
|
||||
* @note
|
||||
* Some flag combinations are invalid:
|
||||
* - @ref NRFX_TWIM_FLAG_TX_NO_STOP with @ref nrfx_twim_xfer_desc_t::type different than @ref NRFX_TWIM_XFER_TX
|
||||
* - @ref NRFX_TWIM_FLAG_REPEATED_XFER with @ref nrfx_twim_xfer_desc_t::type set to @ref NRFX_TWIM_XFER_TXTX
|
||||
*
|
||||
* If @ref nrfx_twim_xfer_desc_t::type is set to @ref NRFX_TWIM_XFER_TX and the @ref NRFX_TWIM_FLAG_TX_NO_STOP and @ref NRFX_TWIM_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 Peripherals using EasyDMA (including TWIM) 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_xfer_desc Pointer to the transfer descriptor.
|
||||
* @param[in] flags Transfer options (0 for default settings).
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the procedure was successful.
|
||||
* @retval NRFX_ERROR_BUSY If the driver is not ready for a new transfer.
|
||||
* @retval NRFX_ERROR_NOT_SUPPORTED If the provided parameters are not supported.
|
||||
* @retval NRFX_ERROR_INTERNAL If an error was detected by hardware.
|
||||
* @retval NRFX_ERROR_INVALID_ADDR If the provided buffers are not placed in the Data RAM region.
|
||||
* @retval NRFX_ERROR_DRV_TWI_ERR_ANACK If NACK received after sending the address.
|
||||
* @retval NRFX_ERROR_DRV_TWI_ERR_DNACK If NACK received after sending a data byte.
|
||||
*/
|
||||
nrfx_err_t nrfx_twim_xfer(nrfx_twim_t const * p_instance,
|
||||
nrfx_twim_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.
|
||||
*/
|
||||
bool nrfx_twim_is_busy(nrfx_twim_t const * p_instance);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a TWIM start task.
|
||||
*
|
||||
* This function should be used if @ref nrfx_twim_xfer was called with the flag @ref NRFX_TWIM_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 nrfx_twim_xfer function.
|
||||
*
|
||||
* @return Start task address (TX or RX) depending on the value of xfer_type.
|
||||
*/
|
||||
uint32_t nrfx_twim_start_task_get(nrfx_twim_t const * p_instance, nrfx_twim_xfer_type_t xfer_type);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a STOPPED TWIM event.
|
||||
*
|
||||
* A STOPPED event can be used to detect the end of a transfer if the @ref NRFX_TWIM_FLAG_NO_XFER_EVT_HANDLER
|
||||
* option is used.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*
|
||||
* @return STOPPED event address.
|
||||
*/
|
||||
uint32_t nrfx_twim_stopped_event_get(nrfx_twim_t const * p_instance);
|
||||
|
||||
|
||||
void nrfx_twim_0_irq_handler(void);
|
||||
void nrfx_twim_1_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRFX_TWIM_H__
|
||||
@@ -0,0 +1,396 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 <nrfx.h>
|
||||
#include <hal/nrf_twis.h>
|
||||
#include <hal/nrf_gpio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrfx_twis TWIS driver
|
||||
* @{
|
||||
* @ingroup nrf_twis
|
||||
* @brief Two Wire Slave interface (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; ///< Driver instance index.
|
||||
} nrfx_twis_t;
|
||||
|
||||
enum {
|
||||
#if NRFX_CHECK(NRFX_TWIS0_ENABLED)
|
||||
NRFX_TWIS0_INST_IDX,
|
||||
#endif
|
||||
#if NRFX_CHECK(NRFX_TWIS1_ENABLED)
|
||||
NRFX_TWIS1_INST_IDX,
|
||||
#endif
|
||||
NRFX_TWIS_ENABLED_COUNT
|
||||
};
|
||||
|
||||
/**
|
||||
* @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 has 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 has 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
|
||||
* We could 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;
|
||||
} 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 set.
|
||||
} nrfx_twis_config_t;
|
||||
|
||||
/**
|
||||
* @brief Generate default configuration for TWIS driver instance.
|
||||
*/
|
||||
#define NRFX_TWIS_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.addr = { NRFX_TWIS_DEFAULT_CONFIG_ADDR0, \
|
||||
NRFX_TWIS_DEFAULT_CONFIG_ADDR1 }, \
|
||||
.scl = 31, \
|
||||
.scl_pull = (nrf_gpio_pin_pull_t)NRFX_TWIS_DEFAULT_CONFIG_SCL_PULL, \
|
||||
.sda = 31, \
|
||||
.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 TWIS driver.
|
||||
* @attention After driver initialization enable it by @ref nrfx_twis_enable.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @attention @em p_instance has to be global object.
|
||||
* It would be used by interrupts so make it sure that object
|
||||
* would not be destroyed when function is leaving.
|
||||
* @param[in] p_config Pointer to the structure with initial configuration.
|
||||
* @param[in] event_handler Event handler provided by the user.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver is already initialized.
|
||||
* @retval NRFX_ERROR_BUSY If 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 initializes the peripheral and resets all registers to default values.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @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,
|
||||
* selected pins would not be reset to default configuration.
|
||||
*/
|
||||
void nrfx_twis_uninit(nrfx_twis_t const * p_instance);
|
||||
|
||||
/**
|
||||
* @brief Enable TWIS instance.
|
||||
*
|
||||
* This function enables TWIS instance.
|
||||
* Function defined if there is needs 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 Disable TWIS instance.
|
||||
*
|
||||
* Disabling TWIS instance 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 Get and clear last error flags.
|
||||
*
|
||||
* Function gets information about errors.
|
||||
* This is also the only possibility to exit from error substate of the internal state machine.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @return Error flags defined in @ref nrfx_twis_error_t.
|
||||
* @attention
|
||||
* This function clears error state and flags.
|
||||
*/
|
||||
uint32_t nrfx_twis_error_get_and_clear(nrfx_twis_t const * p_instance);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Prepare data for sending.
|
||||
*
|
||||
* This function should be used in response for @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.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_buf Transmission buffer.
|
||||
* @attention Transmission buffer has to be placed in RAM.
|
||||
* @param size Maximum number of bytes that master may read from buffer given.
|
||||
*
|
||||
* @retval NRFX_SUCCESS Preparation finished properly.
|
||||
* @retval NRFX_ERROR_INVALID_ADDR Given @em p_buf is not placed inside the RAM.
|
||||
* @retval NRFX_ERROR_INVALID_LENGTH Wrong value in @em size parameter.
|
||||
* @retval NRFX_ERROR_INVALID_STATE Module 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 Get number of transmitted bytes.
|
||||
*
|
||||
* Function returns number of bytes sent.
|
||||
* This function may 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 Prepare data for receiving
|
||||
*
|
||||
* This function should be used in response for @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 will fail with the error code NRFX_ERROR_INVALID_ADDR.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_buf Buffer that would be filled with received data.
|
||||
* @attention Receiving buffer has to be placed in RAM.
|
||||
* @param size Size of the buffer (maximum amount of data to receive).
|
||||
*
|
||||
* @retval NRFX_SUCCESS Preparation finished properly.
|
||||
* @retval NRFX_ERROR_INVALID_ADDR Given @em p_buf is not placed inside the RAM.
|
||||
* @retval NRFX_ERROR_INVALID_LENGTH Wrong value in @em size parameter.
|
||||
* @retval NRFX_ERROR_INVALID_STATE Module 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 Get number of received bytes.
|
||||
*
|
||||
* Function returns number of bytes received.
|
||||
* This function may 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 checks if driver is busy right now.
|
||||
*
|
||||
* Actual driver substate is tested.
|
||||
* If 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 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 checks if driver is waiting for tx buffer.
|
||||
*
|
||||
* If this function returns true, it means that 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 Driver waits for @ref nrfx_twis_tx_prepare.
|
||||
* @retval false Driver is not in the state where it waits for preparing tx buffer.
|
||||
*/
|
||||
bool nrfx_twis_is_waiting_tx_buff(nrfx_twis_t const * p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function checks if driver is waiting for rx buffer.
|
||||
*
|
||||
* If this function returns true, it means that driver is staled expecting
|
||||
* of the @ref nrfx_twis_rx_prepare function call.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*
|
||||
* @retval true Driver waits for @ref nrfx_twis_rx_prepare.
|
||||
* @retval false Driver is not in the state where it waits for preparing rx buffer.
|
||||
*/
|
||||
bool nrfx_twis_is_waiting_rx_buff(nrfx_twis_t const * p_instance);
|
||||
|
||||
/**
|
||||
* @brief Check if driver is sending data.
|
||||
*
|
||||
* If this function returns true, it means that there is ongoing output transmission.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*
|
||||
* @retval true There is ongoing output transmission.
|
||||
* @retval false Driver is in other state.
|
||||
*/
|
||||
bool nrfx_twis_is_pending_tx(nrfx_twis_t const * p_instance);
|
||||
|
||||
/**
|
||||
* @brief Check if driver is receiving data.
|
||||
*
|
||||
* If this function returns true, it means that there is ongoing input transmission.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*
|
||||
* @retval true There is ongoing input transmission.
|
||||
* @retval false 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);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRFX_TWIS_H__
|
||||
@@ -0,0 +1,356 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_UART_H__
|
||||
#define NRFX_UART_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
#include <hal/nrf_uart.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrfx_uart UART driver
|
||||
* @{
|
||||
* @ingroup nrf_uart
|
||||
* @brief UART peripheral driver.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief UART driver instance data structure.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
NRF_UART_Type * p_reg; ///< Pointer to a structure with UART registers.
|
||||
uint8_t drv_inst_idx; ///< Driver instance index.
|
||||
} nrfx_uart_t;
|
||||
|
||||
enum {
|
||||
#if NRFX_CHECK(NRFX_UART0_ENABLED)
|
||||
NRFX_UART0_INST_IDX,
|
||||
#endif
|
||||
NRFX_UART_ENABLED_COUNT
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Macro for creating a UART driver instance.
|
||||
*/
|
||||
#define NRFX_UART_INSTANCE(id) \
|
||||
{ \
|
||||
.p_reg = NRFX_CONCAT_2(NRF_UART, id), \
|
||||
.drv_inst_idx = NRFX_CONCAT_3(NRFX_UART, id, _INST_IDX), \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Types of UART driver events.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRFX_UART_EVT_TX_DONE, ///< Requested TX transfer completed.
|
||||
NRFX_UART_EVT_RX_DONE, ///< Requested RX transfer completed.
|
||||
NRFX_UART_EVT_ERROR, ///< Error reported by UART peripheral.
|
||||
} nrfx_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.
|
||||
} nrfx_uart_config_t;
|
||||
|
||||
/**
|
||||
* @brief UART default configuration.
|
||||
*/
|
||||
#define NRFX_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)NRFX_UART_DEFAULT_CONFIG_HWFC, \
|
||||
.parity = (nrf_uart_parity_t)NRFX_UART_DEFAULT_CONFIG_PARITY, \
|
||||
.baudrate = (nrf_uart_baudrate_t)NRFX_UART_DEFAULT_CONFIG_BAUDRATE, \
|
||||
.interrupt_priority = NRFX_UART_DEFAULT_CONFIG_IRQ_PRIORITY, \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Structure for UART transfer completion event.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t * p_data; ///< Pointer to memory used for transfer.
|
||||
uint32_t bytes; ///< Number of bytes transfered.
|
||||
} nrfx_uart_xfer_evt_t;
|
||||
|
||||
/**
|
||||
* @brief Structure for UART error event.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrfx_uart_xfer_evt_t rxtx; ///< Transfer details includes number of bytes transferred.
|
||||
uint32_t error_mask; ///< Mask of error flags that generated the event.
|
||||
} nrfx_uart_error_evt_t;
|
||||
|
||||
/**
|
||||
* @brief Structure for UART event.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrfx_uart_evt_type_t type; ///< Event type.
|
||||
union
|
||||
{
|
||||
nrfx_uart_xfer_evt_t rxtx; ///< Data provided for transfer completion events.
|
||||
nrfx_uart_error_evt_t error; ///< Data provided for error event.
|
||||
} data;
|
||||
} nrfx_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 (*nrfx_uart_event_handler_t)(nrfx_uart_event_t const * 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 Pointer to the structure with 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.
|
||||
* @retval NRFX_ERROR_BUSY If some other peripheral with the same
|
||||
* instance ID is already in use. This is
|
||||
* possible only if @ref nrfx_prs module
|
||||
* is enabled.
|
||||
*/
|
||||
nrfx_err_t nrfx_uart_init(nrfx_uart_t const * p_instance,
|
||||
nrfx_uart_config_t const * p_config,
|
||||
nrfx_uart_event_handler_t event_handler);
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing the UART driver.
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_uart_uninit(nrfx_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 nrfx_uart_task_address_get(nrfx_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 nrfx_uart_event_address_get(nrfx_uart_t const * p_instance,
|
||||
nrf_uart_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for sending data over UART.
|
||||
*
|
||||
* If an event handler was provided in nrfx_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.
|
||||
*
|
||||
* @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).
|
||||
*/
|
||||
nrfx_err_t nrfx_uart_tx(nrfx_uart_t const * p_instance,
|
||||
uint8_t const * p_data,
|
||||
size_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.
|
||||
*/
|
||||
bool nrfx_uart_tx_in_progress(nrfx_uart_t const * p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for aborting any ongoing transmission.
|
||||
* @note @ref NRFX_UART_EVT_TX_DONE event will be generated in non-blocking mode.
|
||||
* It will contain number of bytes sent until abort was called. The event
|
||||
* handler will be called from the function context.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_uart_tx_abort(nrfx_uart_t const * p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for receiving data over UART.
|
||||
*
|
||||
* If an event handler was provided in the nrfx_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.
|
||||
*
|
||||
* @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 nrfx_uart_rx_disable).
|
||||
* @retval NRFX_ERROR_INTERNAL If UART peripheral reported an error.
|
||||
*/
|
||||
nrfx_err_t nrfx_uart_rx(nrfx_uart_t const * p_instance,
|
||||
uint8_t * p_data,
|
||||
size_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.
|
||||
*/
|
||||
bool nrfx_uart_rx_ready(nrfx_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. The receiver must be
|
||||
* explicitly closed by the user @sa nrfx_uart_rx_disable.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_uart_rx_enable(nrfx_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 nrfx_uart_rx_enable.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_uart_rx_disable(nrfx_uart_t const * p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for aborting any ongoing reception.
|
||||
* @note @ref NRFX_UART_EVT_TX_DONE event will be generated in non-blocking mode.
|
||||
* It will contain number of bytes received until abort was called. The event
|
||||
* handler will be called from the UART interrupt context.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_uart_rx_abort(nrfx_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.
|
||||
*/
|
||||
uint32_t nrfx_uart_errorsrc_get(nrfx_uart_t const * p_instance);
|
||||
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
__STATIC_INLINE uint32_t nrfx_uart_task_address_get(nrfx_uart_t const * p_instance,
|
||||
nrf_uart_task_t task)
|
||||
{
|
||||
return nrf_uart_task_address_get(p_instance->p_reg, task);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrfx_uart_event_address_get(nrfx_uart_t const * p_instance,
|
||||
nrf_uart_event_t event)
|
||||
{
|
||||
return nrf_uart_event_address_get(p_instance->p_reg, event);
|
||||
}
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
|
||||
void nrfx_uart_0_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRFX_UART_H__
|
||||
@@ -0,0 +1,354 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_UARTE_H__
|
||||
#define NRFX_UARTE_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
#include <hal/nrf_uarte.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrfx_uarte UARTE driver
|
||||
* @{
|
||||
* @ingroup nrf_uarte
|
||||
* @brief UARTE peripheral driver.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Structure for the UARTE driver instance.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
NRF_UARTE_Type * p_reg; ///< Pointer to a structure with UARTE registers.
|
||||
uint8_t drv_inst_idx; ///< Driver instance index.
|
||||
} nrfx_uarte_t;
|
||||
|
||||
enum {
|
||||
#if NRFX_CHECK(NRFX_UARTE0_ENABLED)
|
||||
NRFX_UARTE0_INST_IDX,
|
||||
#endif
|
||||
#if NRFX_CHECK(NRFX_UARTE1_ENABLED)
|
||||
NRFX_UARTE1_INST_IDX,
|
||||
#endif
|
||||
NRFX_UARTE_ENABLED_COUNT
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Macro for creating a UARTE driver instance.
|
||||
*/
|
||||
#define NRFX_UARTE_INSTANCE(id) \
|
||||
{ \
|
||||
.p_reg = NRFX_CONCAT_2(NRF_UARTE, id), \
|
||||
.drv_inst_idx = NRFX_CONCAT_3(NRFX_UARTE, id, _INST_IDX), \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Types of UARTE driver events.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRFX_UARTE_EVT_TX_DONE, ///< Requested TX transfer completed.
|
||||
NRFX_UARTE_EVT_RX_DONE, ///< Requested RX transfer completed.
|
||||
NRFX_UARTE_EVT_ERROR, ///< Error reported by UART peripheral.
|
||||
} nrfx_uarte_evt_type_t;
|
||||
|
||||
/**
|
||||
* @brief Structure for UARTE 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_uarte_hwfc_t hwfc; ///< Flow control configuration.
|
||||
nrf_uarte_parity_t parity; ///< Parity configuration.
|
||||
nrf_uarte_baudrate_t baudrate; ///< Baudrate.
|
||||
uint8_t interrupt_priority; ///< Interrupt priority.
|
||||
} nrfx_uarte_config_t;
|
||||
|
||||
/**
|
||||
* @brief UARTE default configuration.
|
||||
*/
|
||||
#define NRFX_UARTE_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.pseltxd = NRF_UARTE_PSEL_DISCONNECTED, \
|
||||
.pselrxd = NRF_UARTE_PSEL_DISCONNECTED, \
|
||||
.pselcts = NRF_UARTE_PSEL_DISCONNECTED, \
|
||||
.pselrts = NRF_UARTE_PSEL_DISCONNECTED, \
|
||||
.p_context = NULL, \
|
||||
.hwfc = (nrf_uarte_hwfc_t)NRFX_UARTE_DEFAULT_CONFIG_HWFC, \
|
||||
.parity = (nrf_uarte_parity_t)NRFX_UARTE_DEFAULT_CONFIG_PARITY, \
|
||||
.baudrate = (nrf_uarte_baudrate_t)NRFX_UARTE_DEFAULT_CONFIG_BAUDRATE, \
|
||||
.interrupt_priority = NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY, \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Structure for UARTE transfer completion event.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t * p_data; ///< Pointer to memory used for transfer.
|
||||
uint8_t bytes; ///< Number of bytes transfered.
|
||||
} nrfx_uarte_xfer_evt_t;
|
||||
|
||||
/**
|
||||
* @brief Structure for UARTE error event.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrfx_uarte_xfer_evt_t rxtx; ///< Transfer details includes number of bytes transferred.
|
||||
uint32_t error_mask; ///< Mask of error flags that generated the event.
|
||||
} nrfx_uarte_error_evt_t;
|
||||
|
||||
/**
|
||||
* @brief Structure for UARTE event.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrfx_uarte_evt_type_t type; ///< Event type.
|
||||
union
|
||||
{
|
||||
nrfx_uarte_xfer_evt_t rxtx; ///< Data provided for transfer completion events.
|
||||
nrfx_uarte_error_evt_t error; ///< Data provided for error event.
|
||||
} data;
|
||||
} nrfx_uarte_event_t;
|
||||
|
||||
/**
|
||||
* @brief UARTE 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 (*nrfx_uarte_event_handler_t)(nrfx_uarte_event_t const * p_event,
|
||||
void * p_context);
|
||||
|
||||
/**
|
||||
* @brief Function for initializing the UARTE driver.
|
||||
*
|
||||
* This function configures and enables UARTE. After this function GPIO pins are controlled by UARTE.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_config Pointer to the structure with 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.
|
||||
* @retval NRFX_ERROR_BUSY If some other peripheral with the same
|
||||
* instance ID is already in use. This is
|
||||
* possible only if @ref nrfx_prs module
|
||||
* is enabled.
|
||||
*/
|
||||
nrfx_err_t nrfx_uarte_init(nrfx_uarte_t const * p_instance,
|
||||
nrfx_uarte_config_t const * p_config,
|
||||
nrfx_uarte_event_handler_t event_handler);
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing the UARTE driver.
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_uarte_uninit(nrfx_uarte_t const * p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific UARTE task.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] task Task.
|
||||
*
|
||||
* @return Task address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_uarte_task_address_get(nrfx_uarte_t const * p_instance,
|
||||
nrf_uarte_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific UARTE event.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] event Event.
|
||||
*
|
||||
* @return Event address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_uarte_event_address_get(nrfx_uarte_t const * p_instance,
|
||||
nrf_uarte_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for sending data over UARTE.
|
||||
*
|
||||
* If an event handler was provided in nrfx_uarte_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 (including UARTE) 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_data Pointer to data.
|
||||
* @param[in] length Number of bytes to send. Maximum possible length is
|
||||
* dependent on the used SoC (see the MAXCNT register
|
||||
* description in the Product Specification). The driver
|
||||
* checks it with assertion.
|
||||
*
|
||||
* @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).
|
||||
* @retval NRFX_ERROR_INVALID_ADDR If p_data does not point to RAM buffer.
|
||||
*/
|
||||
nrfx_err_t nrfx_uarte_tx(nrfx_uarte_t const * p_instance,
|
||||
uint8_t const * p_data,
|
||||
size_t length);
|
||||
|
||||
/**
|
||||
* @brief Function for checking if UARTE is currently transmitting.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*
|
||||
* @retval true If UARTE is transmitting.
|
||||
* @retval false If UARTE is not transmitting.
|
||||
*/
|
||||
bool nrfx_uarte_tx_in_progress(nrfx_uarte_t const * p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for aborting any ongoing transmission.
|
||||
* @note @ref NRFX_UARTE_EVT_TX_DONE event will be generated in non-blocking mode.
|
||||
* It will contain number of bytes sent until abort was called. The event
|
||||
* handler will be called from UARTE interrupt context.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_uarte_tx_abort(nrfx_uarte_t const * p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for receiving data over UARTE.
|
||||
*
|
||||
* If an event handler was provided in the nrfx_uarte_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 (including UARTE) 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_data Pointer to data.
|
||||
* @param[in] length Number of bytes to receive. Maximum possible length is
|
||||
* dependent on the used SoC (see the MAXCNT register
|
||||
* description in the Product Specification). The driver
|
||||
* checks it with assertion.
|
||||
*
|
||||
* @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).
|
||||
* @retval NRFX_ERROR_INTERNAL If UARTE peripheral reported an error.
|
||||
* @retval NRFX_ERROR_INVALID_ADDR If p_data does not point to RAM buffer.
|
||||
*/
|
||||
nrfx_err_t nrfx_uarte_rx(nrfx_uarte_t const * p_instance,
|
||||
uint8_t * p_data,
|
||||
size_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.
|
||||
*/
|
||||
bool nrfx_uarte_rx_ready(nrfx_uarte_t const * p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for aborting any ongoing reception.
|
||||
* @note @ref NRFX_UARTE_EVT_RX_DONE event will be generated in non-blocking mode.
|
||||
* It will contain number of bytes received until abort was called. The event
|
||||
* handler will be called from UARTE interrupt context.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_uarte_rx_abort(nrfx_uarte_t const * p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for reading error source mask. Mask contains values from @ref nrf_uarte_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.
|
||||
*/
|
||||
uint32_t nrfx_uarte_errorsrc_get(nrfx_uarte_t const * p_instance);
|
||||
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
__STATIC_INLINE uint32_t nrfx_uarte_task_address_get(nrfx_uarte_t const * p_instance,
|
||||
nrf_uarte_task_t task)
|
||||
{
|
||||
return nrf_uarte_task_address_get(p_instance->p_reg, task);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrfx_uarte_event_address_get(nrfx_uarte_t const * p_instance,
|
||||
nrf_uarte_event_t event)
|
||||
{
|
||||
return nrf_uarte_event_address_get(p_instance->p_reg, event);
|
||||
}
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
|
||||
void nrfx_uarte_0_irq_handler(void);
|
||||
void nrfx_uarte_1_irq_handler(void);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRFX_UARTE_H__
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_WDT_H__
|
||||
#define NRFX_WDT_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
#include <hal/nrf_wdt.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrfx_wdt WDT driver
|
||||
* @{
|
||||
* @ingroup nrf_wdt
|
||||
* @brief Watchdog Timer (WDT) peripheral driver.
|
||||
*/
|
||||
|
||||
/**@brief Struct for WDT initialization. */
|
||||
typedef struct
|
||||
{
|
||||
nrf_wdt_behaviour_t behaviour; /**< WDT behaviour when CPU in sleep/halt mode. */
|
||||
uint32_t reload_value; /**< WDT reload value in ms. */
|
||||
uint8_t interrupt_priority; /**< WDT interrupt priority */
|
||||
} nrfx_wdt_config_t;
|
||||
|
||||
/**@brief WDT event handler function type. */
|
||||
typedef void (*nrfx_wdt_event_handler_t)(void);
|
||||
|
||||
/**@brief WDT channel id type. */
|
||||
typedef nrf_wdt_rr_register_t nrfx_wdt_channel_id;
|
||||
|
||||
#define NRFX_WDT_DEAFULT_CONFIG \
|
||||
{ \
|
||||
.behaviour = (nrf_wdt_behaviour_t)NRFX_WDT_CONFIG_BEHAVIOUR, \
|
||||
.reload_value = NRFX_WDT_CONFIG_RELOAD_VALUE, \
|
||||
.interrupt_priority = NRFX_WDT_CONFIG_IRQ_PRIORITY, \
|
||||
}
|
||||
/**
|
||||
* @brief This function initializes watchdog.
|
||||
*
|
||||
* @param[in] p_config Pointer to the structure with initial configuration.
|
||||
* @param[in] wdt_event_handler Event handler provided by the user.
|
||||
* Must not be NULL.
|
||||
*
|
||||
* @return NRFX_SUCCESS on success, otherwise an error code.
|
||||
*/
|
||||
nrfx_err_t nrfx_wdt_init(nrfx_wdt_config_t const * p_config,
|
||||
nrfx_wdt_event_handler_t wdt_event_handler);
|
||||
|
||||
/**
|
||||
* @brief This function allocate watchdog channel.
|
||||
*
|
||||
* @note This function can not be called after nrfx_wdt_start(void).
|
||||
*
|
||||
* @param[out] p_channel_id ID of granted channel.
|
||||
*
|
||||
* @return NRFX_SUCCESS on success, otherwise an error code.
|
||||
*/
|
||||
nrfx_err_t nrfx_wdt_channel_alloc(nrfx_wdt_channel_id * p_channel_id);
|
||||
|
||||
/**
|
||||
* @brief This function starts watchdog.
|
||||
*
|
||||
* @note After calling this function the watchdog is started, so the user needs to feed all allocated
|
||||
* watchdog channels to avoid reset. At least one watchdog channel has to be allocated.
|
||||
*/
|
||||
void nrfx_wdt_enable(void);
|
||||
|
||||
/**
|
||||
* @brief This function feeds the watchdog.
|
||||
*
|
||||
* @details Function feeds all allocated watchdog channels.
|
||||
*/
|
||||
void nrfx_wdt_feed(void);
|
||||
|
||||
/**
|
||||
* @brief This function feeds the invidual watchdog channel.
|
||||
*
|
||||
* @param[in] channel_id ID of watchdog channel.
|
||||
*/
|
||||
void nrfx_wdt_channel_feed(nrfx_wdt_channel_id channel_id);
|
||||
|
||||
/**@brief Function for returning a requested task address for the wdt driver module.
|
||||
*
|
||||
* @param[in] task One of the peripheral tasks.
|
||||
*
|
||||
* @retval Task address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_wdt_ppi_task_addr(nrf_wdt_task_t task)
|
||||
{
|
||||
return nrf_wdt_task_address_get(task);
|
||||
}
|
||||
|
||||
/**@brief Function for returning a requested event address for the wdt driver module.
|
||||
*
|
||||
* @param[in] event One of the peripheral events.
|
||||
*
|
||||
* @retval Event address
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_wdt_ppi_event_addr(nrf_wdt_event_t event)
|
||||
{
|
||||
return nrf_wdt_event_address_get(event);
|
||||
}
|
||||
|
||||
|
||||
void nrfx_wdt_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,276 @@
|
||||
/*
|
||||
* Copyright (c) 2017 - 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_COMMON_H__
|
||||
#define NRFX_COMMON_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <nrf.h>
|
||||
#include <nrf_peripherals.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrfx_common Common module
|
||||
* @{
|
||||
* @ingroup nrfx
|
||||
* @brief Common module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Macro for checking if the specified identifier is defined and it has
|
||||
* a non-zero value.
|
||||
*
|
||||
* Normally, preprocessors treat all undefined identifiers as having the value
|
||||
* zero. However, some tools, like static code analyzers, may issue a warning
|
||||
* when such identifier is evaluated. This macro gives the possibility to suppress
|
||||
* such warnings only in places where this macro is used for evaluation, not in
|
||||
* the whole analyzed code.
|
||||
*/
|
||||
#define NRFX_CHECK(module_enabled) (module_enabled)
|
||||
|
||||
/**
|
||||
* @brief Macro for concatenating two tokens in macro expansion.
|
||||
*
|
||||
* @note This macro is expanded in two steps so that tokens given as macros
|
||||
* themselves are fully expanded before they are merged.
|
||||
*
|
||||
* @param p1 First token.
|
||||
* @param p2 Second token.
|
||||
*
|
||||
* @return The two tokens merged into one, unless they cannot together form
|
||||
* a valid token (in such case, the preprocessor issues a warning and
|
||||
* does not perform the concatenation).
|
||||
*
|
||||
* @sa NRFX_CONCAT_3
|
||||
*/
|
||||
#define NRFX_CONCAT_2(p1, p2) NRFX_CONCAT_2_(p1, p2)
|
||||
/**
|
||||
* @brief Internal macro used by @ref NRFX_CONCAT_2 to perform the expansion
|
||||
* in two steps.
|
||||
*/
|
||||
#define NRFX_CONCAT_2_(p1, p2) p1 ## p2
|
||||
|
||||
/**
|
||||
* @brief Macro for concatenating three tokens in macro expansion.
|
||||
*
|
||||
* @note This macro is expanded in two steps so that tokens given as macros
|
||||
* themselves are fully expanded before they are merged.
|
||||
*
|
||||
* @param p1 First token.
|
||||
* @param p2 Second token.
|
||||
* @param p3 Third token.
|
||||
*
|
||||
* @return The three tokens merged into one, unless they cannot together form
|
||||
* a valid token (in such case, the preprocessor issues a warning and
|
||||
* does not perform the concatenation).
|
||||
*
|
||||
* @sa NRFX_CONCAT_2
|
||||
*/
|
||||
#define NRFX_CONCAT_3(p1, p2, p3) NRFX_CONCAT_3_(p1, p2, p3)
|
||||
/**
|
||||
* @brief Internal macro used by @ref NRFX_CONCAT_3 to perform the expansion
|
||||
* in two steps.
|
||||
*/
|
||||
#define NRFX_CONCAT_3_(p1, p2, p3) p1 ## p2 ## p3
|
||||
|
||||
/**@brief Macro for performing rounded integer division (as opposed to
|
||||
* truncating the result).
|
||||
*
|
||||
* @param a Numerator.
|
||||
* @param b Denominator.
|
||||
*
|
||||
* @return Rounded (integer) result of dividing @c a by @c b.
|
||||
*/
|
||||
#define NRFX_ROUNDED_DIV(a, b) (((a) + ((b) / 2)) / (b))
|
||||
|
||||
/**@brief Macro for checking if given lengths of EasyDMA transfers do not exceed
|
||||
* the limit of the specified peripheral.
|
||||
*
|
||||
* @param peripheral Peripheral to check the lengths against.
|
||||
* @param length1 First length to be checked.
|
||||
* @param length2 Second length to be checked (pass 0 if not needed).
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
#define NRFX_EASYDMA_LENGTH_VALIDATE(peripheral, length1, length2) \
|
||||
(((length1) < (1U << NRFX_CONCAT_2(peripheral, _EASYDMA_MAXCNT_SIZE))) && \
|
||||
((length2) < (1U << NRFX_CONCAT_2(peripheral, _EASYDMA_MAXCNT_SIZE))))
|
||||
|
||||
/**@brief Macro for waiting until condition is met.
|
||||
*
|
||||
* @param[in] condition Condition to meet.
|
||||
* @param[in] attempts Maximum number of condition checks. Must not be 0.
|
||||
* @param[in] delay_us Delay between consecutive checks, in microseconds.
|
||||
* @param[out] result Boolean variable to store the result of the wait process.
|
||||
* Set to true if the condition is met or false otherwise.
|
||||
*/
|
||||
#define NRFX_WAIT_FOR(condition, attempts, delay_us, result) \
|
||||
do { \
|
||||
result = false; \
|
||||
uint32_t remaining_attempts = (attempts); \
|
||||
do { \
|
||||
if (condition) \
|
||||
{ \
|
||||
result = true; \
|
||||
break; \
|
||||
} \
|
||||
NRFX_DELAY_US(delay_us); \
|
||||
} while (--remaining_attempts); \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* @brief Macro for getting the interrupt number assigned to a specific
|
||||
* peripheral.
|
||||
*
|
||||
* In Nordic SoCs the IRQ number assigned to a peripheral is equal to the ID
|
||||
* of this peripheral, and there is a direct relationship between this ID and
|
||||
* the peripheral base address, i.e. the address of a fixed block of 0x1000
|
||||
* bytes of address space assigned to this peripheral.
|
||||
* See the chapter "Peripheral interface" (sections "Peripheral ID" and
|
||||
* "Interrupts") in the product specification of a given SoC.
|
||||
*
|
||||
* @param[in] base_addr Peripheral base address or pointer.
|
||||
*
|
||||
* @return Interrupt number associated with the specified peripheral.
|
||||
*/
|
||||
#define NRFX_IRQ_NUMBER_GET(base_addr) (uint8_t)((uint32_t)(base_addr) >> 12)
|
||||
|
||||
/**
|
||||
* @brief IRQ handler type.
|
||||
*/
|
||||
typedef void (* nrfx_irq_handler_t)(void);
|
||||
|
||||
/**
|
||||
* @brief Driver state.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRFX_DRV_STATE_UNINITIALIZED, ///< Uninitialized.
|
||||
NRFX_DRV_STATE_INITIALIZED, ///< Initialized but powered off.
|
||||
NRFX_DRV_STATE_POWERED_ON, ///< Initialized and powered on.
|
||||
} nrfx_drv_state_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for checking if an object is placed in the Data RAM region.
|
||||
*
|
||||
* Several peripherals (the ones using EasyDMA) require the transfer buffers
|
||||
* to be placed in the Data RAM region. This function can be used to check if
|
||||
* this condition is met.
|
||||
*
|
||||
* @param[in] p_object Pointer to an object whose location is to be checked.
|
||||
*
|
||||
* @retval true If the pointed object is located in the Data RAM region.
|
||||
* @retval false Otherwise.
|
||||
*/
|
||||
__STATIC_INLINE bool nrfx_is_in_ram(void const * p_object);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the interrupt number for a specific peripheral.
|
||||
*
|
||||
* @param[in] p_reg Peripheral base pointer.
|
||||
*
|
||||
* @return Interrupt number associated with the pointed peripheral.
|
||||
*/
|
||||
__STATIC_INLINE IRQn_Type nrfx_get_irq_number(void const * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for converting an INTEN register bit position to the
|
||||
* corresponding event identifier.
|
||||
*
|
||||
* The event identifier is the offset between the event register address and
|
||||
* the peripheral base address, and is equal (thus, can be directly cast) to
|
||||
* the corresponding value of the enumerated type from HAL (nrf_*_event_t).
|
||||
|
||||
* @param bit INTEN register bit position.
|
||||
*
|
||||
* @return Event identifier.
|
||||
*
|
||||
* @sa nrfx_event_to_bitpos
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_bitpos_to_event(uint32_t bit);
|
||||
|
||||
/**
|
||||
* @brief Function for converting an event identifier to the corresponding
|
||||
* INTEN register bit position.
|
||||
*
|
||||
* The event identifier is the offset between the event register address and
|
||||
* the peripheral base address, and is equal (thus, can be directly cast) to
|
||||
* the corresponding value of the enumerated type from HAL (nrf_*_event_t).
|
||||
*
|
||||
* @param event Event identifier.
|
||||
*
|
||||
* @return INTEN register bit position.
|
||||
*
|
||||
* @sa nrfx_bitpos_to_event
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_event_to_bitpos(uint32_t event);
|
||||
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
__STATIC_INLINE bool nrfx_is_in_ram(void const * p_object)
|
||||
{
|
||||
return ((((uint32_t)p_object) & 0xE0000000u) == 0x20000000u);
|
||||
}
|
||||
|
||||
__STATIC_INLINE IRQn_Type nrfx_get_irq_number(void const * p_reg)
|
||||
{
|
||||
return (IRQn_Type)NRFX_IRQ_NUMBER_GET(p_reg);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrfx_bitpos_to_event(uint32_t bit)
|
||||
{
|
||||
static const uint32_t event_reg_offset = 0x100u;
|
||||
return event_reg_offset + (bit * sizeof(uint32_t));
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrfx_event_to_bitpos(uint32_t event)
|
||||
{
|
||||
static const uint32_t event_reg_offset = 0x100u;
|
||||
return (event - event_reg_offset) / sizeof(uint32_t);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRFX_COMMON_H__
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2017 - 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_ERRORS_H__
|
||||
#define NRFX_ERRORS_H__
|
||||
|
||||
#if !NRFX_CHECK(NRFX_CUSTOM_ERROR_CODES)
|
||||
|
||||
/**
|
||||
* @defgroup nrfx_error_codes Global Error Codes
|
||||
* @{
|
||||
* @ingroup nrfx
|
||||
*
|
||||
* @brief Global error codes definitions.
|
||||
*/
|
||||
|
||||
#define NRFX_ERROR_BASE_NUM 0x0BAD0000
|
||||
#define NRFX_ERROR_DRIVERS_BASE_NUM (NRFX_ERROR_BASE_NUM + 0x10000)
|
||||
|
||||
/** @brief Enumerated type for error codes. */
|
||||
typedef enum {
|
||||
NRFX_SUCCESS = (NRFX_ERROR_BASE_NUM + 0), ///< Operation performed successfully.
|
||||
NRFX_ERROR_INTERNAL = (NRFX_ERROR_BASE_NUM + 1), ///< Internal error.
|
||||
NRFX_ERROR_NO_MEM = (NRFX_ERROR_BASE_NUM + 2), ///< No memory for operation.
|
||||
NRFX_ERROR_NOT_SUPPORTED = (NRFX_ERROR_BASE_NUM + 3), ///< Not supported.
|
||||
NRFX_ERROR_INVALID_PARAM = (NRFX_ERROR_BASE_NUM + 4), ///< Invalid parameter.
|
||||
NRFX_ERROR_INVALID_STATE = (NRFX_ERROR_BASE_NUM + 5), ///< Invalid state, operation disallowed in this state.
|
||||
NRFX_ERROR_INVALID_LENGTH = (NRFX_ERROR_BASE_NUM + 6), ///< Invalid length.
|
||||
NRFX_ERROR_TIMEOUT = (NRFX_ERROR_BASE_NUM + 7), ///< Operation timed out.
|
||||
NRFX_ERROR_FORBIDDEN = (NRFX_ERROR_BASE_NUM + 8), ///< Operation is forbidden.
|
||||
NRFX_ERROR_NULL = (NRFX_ERROR_BASE_NUM + 9), ///< Null pointer.
|
||||
NRFX_ERROR_INVALID_ADDR = (NRFX_ERROR_BASE_NUM + 10), ///< Bad memory address.
|
||||
NRFX_ERROR_BUSY = (NRFX_ERROR_BASE_NUM + 11), ///< Busy.
|
||||
NRFX_ERROR_ALREADY_INITIALIZED = (NRFX_ERROR_BASE_NUM + 12), ///< Module already initialized.
|
||||
|
||||
NRFX_ERROR_DRV_TWI_ERR_OVERRUN = (NRFX_ERROR_DRIVERS_BASE_NUM + 0), ///< TWI error: Overrun.
|
||||
NRFX_ERROR_DRV_TWI_ERR_ANACK = (NRFX_ERROR_DRIVERS_BASE_NUM + 1), ///< TWI error: Address not acknowledged.
|
||||
NRFX_ERROR_DRV_TWI_ERR_DNACK = (NRFX_ERROR_DRIVERS_BASE_NUM + 2) ///< TWI error: Data not acknowledged.
|
||||
} nrfx_err_t;
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif // !NRFX_CHECK(NRFX_CUSTOM_ERROR_CODES)
|
||||
|
||||
#endif // NRFX_ERRORS_H__
|
||||
@@ -0,0 +1,339 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 <nrfx.h>
|
||||
|
||||
#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
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
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. */
|
||||
/*lint -restore*/
|
||||
} nrf_adc_task_t;
|
||||
|
||||
/** @brief Analog-to-digital converter events. */
|
||||
typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
NRF_ADC_EVENT_END = offsetof(NRF_ADC_Type, EVENTS_END) /**< End of a conversion event. */
|
||||
/*lint -restore*/
|
||||
} 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 a specific ADC task.
|
||||
*
|
||||
* @param[in] task Task to activate.
|
||||
*/
|
||||
__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 checking the state of an ADC event.
|
||||
*
|
||||
* @param[in] event Event to check.
|
||||
*
|
||||
* @retval true If the event is set.
|
||||
* @retval false If the event is not set.
|
||||
*/
|
||||
__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 a specific 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] int_mask Interrupts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_adc_int_enable(uint32_t int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling the specified interrupts.
|
||||
*
|
||||
* @param[in] int_mask Interrupts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_adc_int_disable(uint32_t int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of the specified ADC interrupts.
|
||||
*
|
||||
* @param[in] int_mask Interrupts to check.
|
||||
*
|
||||
* @retval true If all specified interrupts are enabled.
|
||||
* @retval false If at least one of the given interrupts is not enabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_adc_int_enable_check(uint32_t int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for checking whether the ADC is busy.
|
||||
*
|
||||
* This function checks whether the ADC converter is busy with a conversion.
|
||||
*
|
||||
* @retval true If the ADC is busy.
|
||||
* @retval false If 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 If the ADC is enabled.
|
||||
* @retval false If 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 int_mask)
|
||||
{
|
||||
NRF_ADC->INTENSET = int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_adc_int_disable(uint32_t int_mask)
|
||||
{
|
||||
NRF_ADC->INTENCLR = int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_adc_int_enable_check(uint32_t int_mask)
|
||||
{
|
||||
return (bool)(NRF_ADC->INTENSET & int_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_ */
|
||||
@@ -0,0 +1,497 @@
|
||||
/*
|
||||
* Copyright (c) 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_CCM_H__
|
||||
#define NRF_CCM_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_ccm_hal AES CCM HAL
|
||||
* @{
|
||||
* @ingroup nrf_ccm
|
||||
* @brief Hardware access layer for managing the AES CCM peripheral.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief CCM tasks.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
NRF_CCM_TASK_KSGEN = offsetof(NRF_CCM_Type, TASKS_KSGEN), ///< Start generation of key-stream.
|
||||
NRF_CCM_TASK_CRYPT = offsetof(NRF_CCM_Type, TASKS_CRYPT), ///< Start encryption/decryption.
|
||||
NRF_CCM_TASK_STOP = offsetof(NRF_CCM_Type, TASKS_STOP), ///< Stop encryption/decryption.
|
||||
#if defined(CCM_RATEOVERRIDE_RATEOVERRIDE_Pos) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_CCM_TASK_RATEOVERRIDE = offsetof(NRF_CCM_Type, TASKS_RATEOVERRIDE), ///< Override DATARATE setting in MODE register.
|
||||
#endif
|
||||
/*lint -restore*/
|
||||
} nrf_ccm_task_t;
|
||||
|
||||
/**
|
||||
* @brief CCM events.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
NRF_CCM_EVENT_ENDKSGEN = offsetof(NRF_CCM_Type, EVENTS_ENDKSGEN), ///< Keystream generation complete.
|
||||
NRF_CCM_EVENT_ENDCRYPT = offsetof(NRF_CCM_Type, EVENTS_ENDCRYPT), ///< Encrypt/decrypt complete.
|
||||
NRF_CCM_EVENT_ERROR = offsetof(NRF_CCM_Type, EVENTS_ERROR), ///< CCM error event.
|
||||
/*lint -restore*/
|
||||
} nrf_ccm_event_t;
|
||||
|
||||
/**
|
||||
* @brief CCM interrupts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_CCM_INT_ENDKSGEN_MASK = CCM_INTENSET_ENDKSGEN_Msk, ///< Interrupt on ENDKSGEN event.
|
||||
NRF_CCM_INT_ENDCRYPT_MASK = CCM_INTENSET_ENDCRYPT_Msk, ///< Interrupt on ENDCRYPT event.
|
||||
NRF_CCM_INT_ERROR_MASK = CCM_INTENSET_ERROR_Msk, ///< Interrupt on ERROR event.
|
||||
} nrf_ccm_int_mask_t;
|
||||
|
||||
/**
|
||||
* @brief CCM modes of operation.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_CCM_MODE_ENCRYPTION = CCM_MODE_MODE_Encryption, ///< Encryption mode.
|
||||
NRF_CCM_MODE_DECRYPTION = CCM_MODE_MODE_Decryption, ///< Decryption mode.
|
||||
} nrf_ccm_mode_t;
|
||||
|
||||
#if defined(CCM_MODE_DATARATE_Pos) || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief CCM data rates.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_CCM_DATARATE_1M = CCM_MODE_DATARATE_1Mbit, ///< 1 Mbps.
|
||||
NRF_CCM_DATARATE_2M = CCM_MODE_DATARATE_2Mbit, ///< 2 Mbps.
|
||||
#if defined(CCM_MODE_DATARATE_125Kbps) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_CCM_DATARATE_125K = CCM_MODE_DATARATE_125Kbps, ///< 125 Kbps.
|
||||
#endif
|
||||
#if defined(CCM_MODE_DATARATE_500Kbps) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_CCM_DATARATE_500K = CCM_MODE_DATARATE_500Kbps, ///< 500 Kbps.
|
||||
#endif
|
||||
} nrf_ccm_datarate_t;
|
||||
#endif // defined(CCM_MODE_DATARATE_Pos) || defined(__NRFX_DOXYGEN__)
|
||||
|
||||
#if defined(CCM_MODE_LENGTH_Pos) || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief CCM packet length options.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_CCM_LENGTH_DEFAULT = CCM_MODE_LENGTH_Default, ///< Default length.
|
||||
NRF_CCM_LENGTH_EXTENDED = CCM_MODE_LENGTH_Extended, ///< Extended length.
|
||||
} nrf_ccm_length_t;
|
||||
#endif // defined(CCM_MODE_LENGTH_Pos) || defined(__NRFX_DOXYGEN__)
|
||||
|
||||
/**
|
||||
* @brief CCM configuration.
|
||||
*/
|
||||
typedef struct {
|
||||
nrf_ccm_mode_t mode;
|
||||
#if defined(CCM_MODE_DATARATE_Pos) || defined(__NRFX_DOXYGEN__)
|
||||
nrf_ccm_datarate_t datarate;
|
||||
#endif
|
||||
#if defined(CCM_MODE_LENGTH_Pos) || defined(__NRFX_DOXYGEN__)
|
||||
nrf_ccm_length_t length;
|
||||
#endif
|
||||
} nrf_ccm_config_t;
|
||||
|
||||
/**
|
||||
* @brief Function for activating a specific CCM task.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] task Task to activate.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ccm_task_trigger(NRF_CCM_Type * p_reg,
|
||||
nrf_ccm_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific CCM task register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] task Requested task.
|
||||
*
|
||||
* @return Address of the specified task register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_ccm_task_address_get(NRF_CCM_Type const * p_reg,
|
||||
nrf_ccm_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a specific CCM event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] event Event to clear.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ccm_event_clear(NRF_CCM_Type * p_reg,
|
||||
nrf_ccm_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the state of a specific CCM event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] event Event to check.
|
||||
*
|
||||
* @retval true If the event is set.
|
||||
* @retval false If the event is not set.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_ccm_event_check(NRF_CCM_Type const * p_reg,
|
||||
nrf_ccm_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific CCM event register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] event Requested event.
|
||||
*
|
||||
* @return Address of the specified event register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_ccm_event_address_get(NRF_CCM_Type const * p_reg,
|
||||
nrf_ccm_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling specified interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] mask Interrupts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ccm_int_enable(NRF_CCM_Type * p_reg, uint32_t mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling specified interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] mask Interrupts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ccm_int_disable(NRF_CCM_Type * p_reg, uint32_t mask);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of a given interrupt.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] ccm_int Interrupt to check.
|
||||
*
|
||||
* @retval true If the interrupt is enabled.
|
||||
* @retval false If the interrupt is not enabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_ccm_int_enable_check(NRF_CCM_Type const * p_reg,
|
||||
nrf_ccm_int_mask_t ccm_int);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling the CCM peripheral.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ccm_enable(NRF_CCM_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling the CCM peripheral.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ccm_disable(NRF_CCM_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the CCM peripheral configuration.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] p_config Pointer to the structure with configuration to be set.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ccm_configure(NRF_CCM_Type * p_reg,
|
||||
nrf_ccm_config_t const * p_config);
|
||||
|
||||
#if defined(CCM_MAXPACKETSIZE_MAXPACKETSIZE_Pos) || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Function for setting the length of key-stream generated
|
||||
* when the packet length is configured as extended.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] size Maximum length of the key-stream.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ccm_maxpacketsize_set(NRF_CCM_Type * p_reg,
|
||||
uint8_t size);
|
||||
#endif // defined(CCM_MAXPACKETSIZE_MAXPACKETSIZE_Pos) || defined(__NRFX_DOXYGEN__)
|
||||
|
||||
/**
|
||||
* @brief Function for getting the MIC check result.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*
|
||||
* @retval true If the MIC check passed.
|
||||
* @retval false If the MIC check failed.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_ccm_micstatus_get(NRF_CCM_Type const * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the pointer to the data structure
|
||||
* holding the AES key and the CCM NONCE vector.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] p_data Pointer to the data structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ccm_cnfptr_set(NRF_CCM_Type * p_reg,
|
||||
uint32_t const * p_data);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the pointer to the data structure
|
||||
* holding the AES key and the CCM NONCE vector.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*
|
||||
* @return Pointer to the data structure.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_ccm_cnfptr_get(NRF_CCM_Type const * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the input data pointer.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] p_data Input data pointer.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ccm_inptr_set(NRF_CCM_Type * p_reg,
|
||||
uint32_t const * p_data);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the input data pointer.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*
|
||||
* @return Input data pointer.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_ccm_inptr_get(NRF_CCM_Type const * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the output data pointer.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] p_data Output data pointer.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ccm_outptr_set(NRF_CCM_Type * p_reg,
|
||||
uint32_t const * p_data);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the output data pointer.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*
|
||||
* @return Output data pointer.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_ccm_outptr_get(NRF_CCM_Type const * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the pointer to the scratch area used for
|
||||
* temporary storage.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] p_area Pointer to the scratch area.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ccm_scratchptr_set(NRF_CCM_Type * p_reg,
|
||||
uint32_t const * p_area);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the pointer to the scratch area.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*
|
||||
* @return Pointer to the scratch area.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_ccm_stratchptr_get(NRF_CCM_Type const * p_reg);
|
||||
|
||||
#if defined(CCM_RATEOVERRIDE_RATEOVERRIDE_Pos) || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Function for setting the data rate override value.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] datarate Override value to be applied when the RATEOVERRIDE task
|
||||
* is triggered.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ccm_datarate_override_set(NRF_CCM_Type * p_reg,
|
||||
nrf_ccm_datarate_t datarate);
|
||||
#endif // defined(CCM_RATEOVERRIDE_RATEOVERRIDE_Pos) || defined(__NRFX_DOXYGEN__)
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
__STATIC_INLINE void nrf_ccm_task_trigger(NRF_CCM_Type * p_reg,
|
||||
nrf_ccm_task_t task)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task)) = 0x1UL;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_ccm_task_address_get(NRF_CCM_Type const * p_reg,
|
||||
nrf_ccm_task_t task)
|
||||
{
|
||||
return ((uint32_t)p_reg + (uint32_t)task);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ccm_event_clear(NRF_CCM_Type * p_reg,
|
||||
nrf_ccm_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_ccm_event_check(NRF_CCM_Type const * p_reg,
|
||||
nrf_ccm_event_t event)
|
||||
{
|
||||
return (bool)*(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_ccm_event_address_get(NRF_CCM_Type const * p_reg,
|
||||
nrf_ccm_event_t event)
|
||||
{
|
||||
return ((uint32_t)p_reg + (uint32_t)event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ccm_int_enable(NRF_CCM_Type * p_reg, uint32_t mask)
|
||||
{
|
||||
p_reg->INTENSET = mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ccm_int_disable(NRF_CCM_Type * p_reg, uint32_t mask)
|
||||
{
|
||||
p_reg->INTENCLR = mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_ccm_int_enable_check(NRF_CCM_Type const * p_reg,
|
||||
nrf_ccm_int_mask_t ccm_int)
|
||||
{
|
||||
return (bool)(p_reg->INTENSET & ccm_int);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ccm_enable(NRF_CCM_Type * p_reg)
|
||||
{
|
||||
p_reg->ENABLE = (CCM_ENABLE_ENABLE_Enabled << CCM_ENABLE_ENABLE_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ccm_disable(NRF_CCM_Type * p_reg)
|
||||
{
|
||||
p_reg->ENABLE = (CCM_ENABLE_ENABLE_Disabled << CCM_ENABLE_ENABLE_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ccm_configure(NRF_CCM_Type * p_reg,
|
||||
nrf_ccm_config_t const * p_config)
|
||||
{
|
||||
p_reg->MODE = (((uint32_t)p_config->mode << CCM_MODE_MODE_Pos) |
|
||||
#if defined(CCM_MODE_DATARATE_Pos)
|
||||
((uint32_t)p_config->datarate << CCM_MODE_DATARATE_Pos) |
|
||||
#endif
|
||||
#if defined(CCM_MODE_LENGTH_Pos)
|
||||
((uint32_t)p_config->length << CCM_MODE_LENGTH_Pos) |
|
||||
#endif
|
||||
0);
|
||||
}
|
||||
|
||||
#if defined(CCM_MAXPACKETSIZE_MAXPACKETSIZE_Pos)
|
||||
__STATIC_INLINE void nrf_ccm_maxpacketsize_set(NRF_CCM_Type * p_reg,
|
||||
uint8_t size)
|
||||
{
|
||||
NRFX_ASSERT((size >= 0x1B) && (size <= 0xFB));
|
||||
|
||||
p_reg->MAXPACKETSIZE = size;
|
||||
}
|
||||
#endif // defined(CCM_MAXPACKETSIZE_MAXPACKETSIZE_Pos)
|
||||
|
||||
__STATIC_INLINE bool nrf_ccm_micstatus_get(NRF_CCM_Type const * p_reg)
|
||||
{
|
||||
return (bool)(p_reg->MICSTATUS);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ccm_cnfptr_set(NRF_CCM_Type * p_reg,
|
||||
uint32_t const * p_data)
|
||||
{
|
||||
p_reg->CNFPTR = (uint32_t)p_data;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_ccm_cnfptr_get(NRF_CCM_Type const * p_reg)
|
||||
{
|
||||
return (uint32_t *)(p_reg->CNFPTR);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ccm_inptr_set(NRF_CCM_Type * p_reg,
|
||||
uint32_t const * p_data)
|
||||
{
|
||||
p_reg->INPTR = (uint32_t)p_data;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_ccm_inptr_get(NRF_CCM_Type const * p_reg)
|
||||
{
|
||||
return (uint32_t *)(p_reg->INPTR);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ccm_outptr_set(NRF_CCM_Type * p_reg,
|
||||
uint32_t const * p_data)
|
||||
{
|
||||
p_reg->OUTPTR = (uint32_t)p_data;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_ccm_outptr_get(NRF_CCM_Type const * p_reg)
|
||||
{
|
||||
return (uint32_t *)(p_reg->OUTPTR);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ccm_scratchptr_set(NRF_CCM_Type * p_reg,
|
||||
uint32_t const * p_area)
|
||||
{
|
||||
p_reg->SCRATCHPTR = (uint32_t)p_area;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_ccm_stratchptr_get(NRF_CCM_Type const * p_reg)
|
||||
{
|
||||
return (uint32_t *)(p_reg->SCRATCHPTR);
|
||||
}
|
||||
|
||||
#if defined(CCM_RATEOVERRIDE_RATEOVERRIDE_Pos)
|
||||
__STATIC_INLINE void nrf_ccm_datarate_override_set(NRF_CCM_Type * p_reg,
|
||||
nrf_ccm_datarate_t datarate)
|
||||
{
|
||||
p_reg->RATEOVERRIDE = ((uint32_t)datarate << CCM_RATEOVERRIDE_RATEOVERRIDE_Pos);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_CCM_H__
|
||||
@@ -0,0 +1,411 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_CLOCK_H__
|
||||
#define NRF_CLOCK_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_clock_hal Clock HAL
|
||||
* @{
|
||||
* @ingroup nrf_clock
|
||||
* @brief Hardware access layer for managing the CLOCK peripheral.
|
||||
*
|
||||
* This code can be used to managing low-frequency clock (LFCLK) and the high-frequency clock
|
||||
* (HFCLK) settings.
|
||||
*/
|
||||
|
||||
#define NRF_CLOCK_TASK_TRIGGER (1UL)
|
||||
#define NRF_CLOCK_EVENT_CLEAR (0UL)
|
||||
|
||||
#if defined(NRF52810_XXAA) || \
|
||||
defined(NRF52832_XXAA) || defined(NRF52832_XXAB) || \
|
||||
defined(NRF52840_XXAA)
|
||||
// Enable support for external LFCLK sources. Read more in the Product Specification.
|
||||
#define NRF_CLOCK_USE_EXTERNAL_LFCLK_SOURCES
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Low-frequency clock sources.
|
||||
* @details Used by LFCLKSRC, LFCLKSTAT, and LFCLKSRCCOPY registers.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_CLOCK_LFCLK_RC = CLOCK_LFCLKSRC_SRC_RC, /**< Internal 32 kHz RC oscillator. */
|
||||
NRF_CLOCK_LFCLK_Xtal = CLOCK_LFCLKSRC_SRC_Xtal, /**< External 32 kHz crystal. */
|
||||
NRF_CLOCK_LFCLK_Synth = CLOCK_LFCLKSRC_SRC_Synth, /**< Internal 32 kHz synthesizer from HFCLK system clock. */
|
||||
#if defined(NRF_CLOCK_USE_EXTERNAL_LFCLK_SOURCES) || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* External 32 kHz low swing signal. Used only with the LFCLKSRC register.
|
||||
* For the others @ref NRF_CLOCK_LFCLK_Xtal is returned for this setting.
|
||||
*/
|
||||
NRF_CLOCK_LFCLK_Xtal_Low_Swing = (CLOCK_LFCLKSRC_SRC_Xtal |
|
||||
(CLOCK_LFCLKSRC_EXTERNAL_Enabled << CLOCK_LFCLKSRC_EXTERNAL_Pos)),
|
||||
/**
|
||||
* External 32 kHz full swing signal. Used only with the LFCLKSRC register.
|
||||
* For the others @ref NRF_CLOCK_LFCLK_Xtal is returned for this setting.
|
||||
*/
|
||||
NRF_CLOCK_LFCLK_Xtal_Full_Swing = (CLOCK_LFCLKSRC_SRC_Xtal |
|
||||
(CLOCK_LFCLKSRC_BYPASS_Enabled << CLOCK_LFCLKSRC_BYPASS_Pos) |
|
||||
(CLOCK_LFCLKSRC_EXTERNAL_Enabled << CLOCK_LFCLKSRC_EXTERNAL_Pos)),
|
||||
#endif // defined(NRF_CLOCK_USE_EXTERNAL_LFCLK_SOURCES) || defined(__NRFX_DOXYGEN__)
|
||||
} nrf_clock_lfclk_t;
|
||||
|
||||
/**
|
||||
* @brief High-frequency clock sources.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_CLOCK_HFCLK_LOW_ACCURACY = CLOCK_HFCLKSTAT_SRC_RC, /**< Internal 16 MHz RC oscillator. */
|
||||
NRF_CLOCK_HFCLK_HIGH_ACCURACY = CLOCK_HFCLKSTAT_SRC_Xtal /**< External 16 MHz/32 MHz crystal oscillator. */
|
||||
} nrf_clock_hfclk_t;
|
||||
|
||||
/**
|
||||
* @brief Trigger status of task LFCLKSTART/HFCLKSTART.
|
||||
* @details Used by LFCLKRUN and HFCLKRUN registers.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_CLOCK_START_TASK_NOT_TRIGGERED = CLOCK_LFCLKRUN_STATUS_NotTriggered, /**< Task LFCLKSTART/HFCLKSTART has not been triggered. */
|
||||
NRF_CLOCK_START_TASK_TRIGGERED = CLOCK_LFCLKRUN_STATUS_Triggered /**< Task LFCLKSTART/HFCLKSTART has been triggered. */
|
||||
} nrf_clock_start_task_status_t;
|
||||
|
||||
/**
|
||||
* @brief Interrupts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_CLOCK_INT_HF_STARTED_MASK = CLOCK_INTENSET_HFCLKSTARTED_Msk, /**< Interrupt on HFCLKSTARTED event. */
|
||||
NRF_CLOCK_INT_LF_STARTED_MASK = CLOCK_INTENSET_LFCLKSTARTED_Msk, /**< Interrupt on LFCLKSTARTED event. */
|
||||
NRF_CLOCK_INT_DONE_MASK = CLOCK_INTENSET_DONE_Msk, /**< Interrupt on DONE event. */
|
||||
NRF_CLOCK_INT_CTTO_MASK = CLOCK_INTENSET_CTTO_Msk /**< Interrupt on CTTO event. */
|
||||
} nrf_clock_int_mask_t;
|
||||
|
||||
/**
|
||||
* @brief Tasks.
|
||||
*
|
||||
* @details The NRF_CLOCK_TASK_LFCLKSTOP task cannot be set when the low-frequency clock is not running.
|
||||
* The NRF_CLOCK_TASK_HFCLKSTOP task cannot be set when the high-frequency clock is not running.
|
||||
*/
|
||||
typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
|
||||
{
|
||||
NRF_CLOCK_TASK_HFCLKSTART = offsetof(NRF_CLOCK_Type, TASKS_HFCLKSTART), /**< Start HFCLK clock source.*/
|
||||
NRF_CLOCK_TASK_HFCLKSTOP = offsetof(NRF_CLOCK_Type, TASKS_HFCLKSTOP), /**< Stop HFCLK clock source.*/
|
||||
NRF_CLOCK_TASK_LFCLKSTART = offsetof(NRF_CLOCK_Type, TASKS_LFCLKSTART), /**< Start LFCLK clock source.*/
|
||||
NRF_CLOCK_TASK_LFCLKSTOP = offsetof(NRF_CLOCK_Type, TASKS_LFCLKSTOP), /**< Stop LFCLK clock source.*/
|
||||
NRF_CLOCK_TASK_CAL = offsetof(NRF_CLOCK_Type, TASKS_CAL), /**< Start calibration of LFCLK RC oscillator.*/
|
||||
NRF_CLOCK_TASK_CTSTART = offsetof(NRF_CLOCK_Type, TASKS_CTSTART), /**< Start calibration timer.*/
|
||||
NRF_CLOCK_TASK_CTSTOP = offsetof(NRF_CLOCK_Type, TASKS_CTSTOP) /**< Stop calibration timer.*/
|
||||
} nrf_clock_task_t; /*lint -restore */
|
||||
|
||||
/**
|
||||
* @brief Events.
|
||||
*/
|
||||
typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
|
||||
{
|
||||
NRF_CLOCK_EVENT_HFCLKSTARTED = offsetof(NRF_CLOCK_Type, EVENTS_HFCLKSTARTED), /**< HFCLK oscillator started.*/
|
||||
NRF_CLOCK_EVENT_LFCLKSTARTED = offsetof(NRF_CLOCK_Type, EVENTS_LFCLKSTARTED), /**< LFCLK oscillator started.*/
|
||||
NRF_CLOCK_EVENT_DONE = offsetof(NRF_CLOCK_Type, EVENTS_DONE), /**< Calibration of LFCLK RC oscillator completed.*/
|
||||
NRF_CLOCK_EVENT_CTTO = offsetof(NRF_CLOCK_Type, EVENTS_CTTO) /**< Calibration timer time-out.*/
|
||||
} nrf_clock_event_t; /*lint -restore */
|
||||
|
||||
/**
|
||||
* @brief Function for enabling a specific interrupt.
|
||||
*
|
||||
* @param[in] int_mask Interrupt.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_clock_int_enable(uint32_t int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling a specific interrupt.
|
||||
*
|
||||
* @param[in] int_mask Interrupt.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_clock_int_disable(uint32_t int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of a specific interrupt.
|
||||
*
|
||||
* @param[in] int_mask Interrupt.
|
||||
*
|
||||
* @retval true If the interrupt is enabled.
|
||||
* @retval false If the interrupt is not enabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_clock_int_enable_check(nrf_clock_int_mask_t int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the address of a specific task.
|
||||
* @details This function can be used by the PPI module.
|
||||
*
|
||||
* @param[in] task Task.
|
||||
*
|
||||
* @return Address of the requested task register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_clock_task_address_get(nrf_clock_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for setting a specific task.
|
||||
*
|
||||
* @param[in] task Task.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_clock_task_trigger(nrf_clock_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the address of a specific event.
|
||||
* @details This function can be used by the PPI module.
|
||||
*
|
||||
* @param[in] event Event.
|
||||
*
|
||||
* @return Address of the requested event register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_clock_event_address_get(nrf_clock_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a specific event.
|
||||
*
|
||||
* @param[in] event Event.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_clock_event_clear(nrf_clock_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of a specific event.
|
||||
*
|
||||
* @param[in] event Event.
|
||||
*
|
||||
* @retval true If the event is set.
|
||||
* @retval false If the event is not set.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_clock_event_check(nrf_clock_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for changing the low-frequency clock source.
|
||||
* @details This function cannot be called when the low-frequency clock is running.
|
||||
*
|
||||
* @param[in] source New low-frequency clock source.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_clock_lf_src_set(nrf_clock_lfclk_t source);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the selected source for the low-frequency clock.
|
||||
*
|
||||
* @retval NRF_CLOCK_LFCLK_RC If the internal 32 kHz RC oscillator is the selected source for the low-frequency clock.
|
||||
* @retval NRF_CLOCK_LFCLK_Xtal If an external 32 kHz crystal oscillator is the selected source for the low-frequency clock.
|
||||
* @retval NRF_CLOCK_LFCLK_Synth If the internal 32 kHz synthesizer from the HFCLK is the selected source for the low-frequency clock.
|
||||
*/
|
||||
__STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_src_get(void);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the active source of the low-frequency clock.
|
||||
*
|
||||
* @retval NRF_CLOCK_LFCLK_RC If the internal 32 kHz RC oscillator is the active source of the low-frequency clock.
|
||||
* @retval NRF_CLOCK_LFCLK_Xtal If an external 32 kHz crystal oscillator is the active source of the low-frequency clock.
|
||||
* @retval NRF_CLOCK_LFCLK_Synth If the internal 32 kHz synthesizer from the HFCLK is the active source of the low-frequency clock.
|
||||
*/
|
||||
__STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_actv_src_get(void);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the clock source for the LFCLK clock when the task LKCLKSTART is triggered.
|
||||
*
|
||||
* @retval NRF_CLOCK_LFCLK_RC If the internal 32 kHz RC oscillator is running and generating the LFCLK clock.
|
||||
* @retval NRF_CLOCK_LFCLK_Xtal If an external 32 kHz crystal oscillator is running and generating the LFCLK clock.
|
||||
* @retval NRF_CLOCK_LFCLK_Synth If the internal 32 kHz synthesizer from the HFCLK is running and generating the LFCLK clock.
|
||||
*/
|
||||
__STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_srccopy_get(void);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of the LFCLK clock.
|
||||
*
|
||||
* @retval false If the LFCLK clock is not running.
|
||||
* @retval true If the LFCLK clock is running.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_clock_lf_is_running(void);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the trigger status of the task LFCLKSTART.
|
||||
*
|
||||
* @retval NRF_CLOCK_START_TASK_NOT_TRIGGERED If the task LFCLKSTART has not been triggered.
|
||||
* @retval NRF_CLOCK_START_TASK_TRIGGERED If the task LFCLKSTART has been triggered.
|
||||
*/
|
||||
__STATIC_INLINE nrf_clock_start_task_status_t nrf_clock_lf_start_task_status_get(void);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the active source of the high-frequency clock.
|
||||
*
|
||||
* @retval NRF_CLOCK_HFCLK_LOW_ACCURACY If the internal 16 MHz RC oscillator is the active source of the high-frequency clock.
|
||||
* @retval NRF_CLOCK_HFCLK_HIGH_ACCURACY If an external 16 MHz/32 MHz crystal oscillator is the active source of the high-frequency clock.
|
||||
*/
|
||||
__STATIC_INLINE nrf_clock_hfclk_t nrf_clock_hf_src_get(void);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of the HFCLK clock.
|
||||
*
|
||||
* @param[in] clk_src Clock source to be checked.
|
||||
*
|
||||
* @retval false If the HFCLK clock is not running.
|
||||
* @retval true If the HFCLK clock is running.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_clock_hf_is_running(nrf_clock_hfclk_t clk_src);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the trigger status of the task HFCLKSTART.
|
||||
*
|
||||
* @retval NRF_CLOCK_START_TASK_NOT_TRIGGERED If the task HFCLKSTART has not been triggered.
|
||||
* @retval NRF_CLOCK_START_TASK_TRIGGERED If the task HFCLKSTART has been triggered.
|
||||
*/
|
||||
__STATIC_INLINE nrf_clock_start_task_status_t nrf_clock_hf_start_task_status_get(void);
|
||||
|
||||
/**
|
||||
* @brief Function for changing the calibration timer interval.
|
||||
*
|
||||
* @param[in] interval New calibration timer interval in 0.25 s resolution (range: 0.25 seconds to 31.75 seconds).
|
||||
*/
|
||||
__STATIC_INLINE void nrf_clock_cal_timer_timeout_set(uint32_t interval);
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
__STATIC_INLINE void nrf_clock_int_enable(uint32_t int_mask)
|
||||
{
|
||||
NRF_CLOCK->INTENSET = int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_clock_int_disable(uint32_t int_mask)
|
||||
{
|
||||
NRF_CLOCK->INTENCLR = int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_clock_int_enable_check(nrf_clock_int_mask_t int_mask)
|
||||
{
|
||||
return (bool)(NRF_CLOCK->INTENCLR & int_mask);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_clock_task_address_get(nrf_clock_task_t task)
|
||||
{
|
||||
return ((uint32_t )NRF_CLOCK + task);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_clock_task_trigger(nrf_clock_task_t task)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)NRF_CLOCK + task)) = NRF_CLOCK_TASK_TRIGGER;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_clock_event_address_get(nrf_clock_event_t event)
|
||||
{
|
||||
return ((uint32_t)NRF_CLOCK + event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_clock_event_clear(nrf_clock_event_t event)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)NRF_CLOCK + event)) = NRF_CLOCK_EVENT_CLEAR;
|
||||
#if __CORTEX_M == 0x04
|
||||
volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_CLOCK + event));
|
||||
(void)dummy;
|
||||
#endif
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_clock_event_check(nrf_clock_event_t event)
|
||||
{
|
||||
return (bool)*((volatile uint32_t *)((uint8_t *)NRF_CLOCK + event));
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_clock_lf_src_set(nrf_clock_lfclk_t source)
|
||||
{
|
||||
NRF_CLOCK->LFCLKSRC = (uint32_t)(source);
|
||||
}
|
||||
|
||||
__STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_src_get(void)
|
||||
{
|
||||
return (nrf_clock_lfclk_t)(NRF_CLOCK->LFCLKSRC);
|
||||
}
|
||||
|
||||
__STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_actv_src_get(void)
|
||||
{
|
||||
return (nrf_clock_lfclk_t)((NRF_CLOCK->LFCLKSTAT &
|
||||
CLOCK_LFCLKSTAT_SRC_Msk) >> CLOCK_LFCLKSTAT_SRC_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_srccopy_get(void)
|
||||
{
|
||||
return (nrf_clock_lfclk_t)((NRF_CLOCK->LFCLKSRCCOPY &
|
||||
CLOCK_LFCLKSRCCOPY_SRC_Msk) >> CLOCK_LFCLKSRCCOPY_SRC_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_clock_lf_is_running(void)
|
||||
{
|
||||
return ((NRF_CLOCK->LFCLKSTAT &
|
||||
CLOCK_LFCLKSTAT_STATE_Msk) >> CLOCK_LFCLKSTAT_STATE_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE nrf_clock_start_task_status_t nrf_clock_lf_start_task_status_get(void)
|
||||
{
|
||||
return (nrf_clock_start_task_status_t)((NRF_CLOCK->LFCLKRUN &
|
||||
CLOCK_LFCLKRUN_STATUS_Msk) >>
|
||||
CLOCK_LFCLKRUN_STATUS_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE nrf_clock_hfclk_t nrf_clock_hf_src_get(void)
|
||||
{
|
||||
return (nrf_clock_hfclk_t)((NRF_CLOCK->HFCLKSTAT &
|
||||
CLOCK_HFCLKSTAT_SRC_Msk) >> CLOCK_HFCLKSTAT_SRC_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_clock_hf_is_running(nrf_clock_hfclk_t clk_src)
|
||||
{
|
||||
return (NRF_CLOCK->HFCLKSTAT & (CLOCK_HFCLKSTAT_STATE_Msk | CLOCK_HFCLKSTAT_SRC_Msk)) ==
|
||||
(CLOCK_HFCLKSTAT_STATE_Msk | (clk_src << CLOCK_HFCLKSTAT_SRC_Pos));
|
||||
}
|
||||
|
||||
__STATIC_INLINE nrf_clock_start_task_status_t nrf_clock_hf_start_task_status_get(void)
|
||||
{
|
||||
return (nrf_clock_start_task_status_t)((NRF_CLOCK->HFCLKRUN &
|
||||
CLOCK_HFCLKRUN_STATUS_Msk) >>
|
||||
CLOCK_HFCLKRUN_STATUS_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_clock_cal_timer_timeout_set(uint32_t interval)
|
||||
{
|
||||
NRF_CLOCK->CTIV = ((interval << CLOCK_CTIV_CTIV_Pos) & CLOCK_CTIV_CTIV_Msk);
|
||||
}
|
||||
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_CLOCK_H__
|
||||
@@ -0,0 +1,500 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_comp_hal COMP HAL
|
||||
* @{
|
||||
* @ingroup nrf_comp
|
||||
* @brief Hardware access layer for managing the Comparator (COMP) peripheral.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @enum nrf_comp_input_t
|
||||
* @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. */
|
||||
NRF_COMP_INPUT_4 = COMP_PSEL_PSEL_AnalogInput4, /*!< AIN4 selected as analog input. */
|
||||
NRF_COMP_INPUT_5 = COMP_PSEL_PSEL_AnalogInput5, /*!< AIN5 selected as analog input. */
|
||||
NRF_COMP_INPUT_6 = COMP_PSEL_PSEL_AnalogInput6, /*!< AIN6 selected as analog input. */
|
||||
#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
|
||||
}nrf_comp_input_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_comp_ref_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;
|
||||
|
||||
/**
|
||||
* @enum nrf_comp_ext_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_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;
|
||||
|
||||
/**
|
||||
* @enum nrf_comp_main_mode_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;
|
||||
|
||||
/**
|
||||
* @enum nrf_comp_sp_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;
|
||||
|
||||
/**
|
||||
* @enum nrf_comp_hyst_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
|
||||
|
||||
/**
|
||||
* @enum nrf_comp_task_t
|
||||
* @brief COMP tasks.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
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. */
|
||||
/*lint -restore*/
|
||||
}nrf_comp_task_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_comp_event_t
|
||||
* @brief COMP events.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
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. */
|
||||
/*lint -restore*/
|
||||
}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 If the COMP peripheral is enabled.
|
||||
* @retval false If 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.
|
||||
*
|
||||
* @return The last compare result. If 0, then VIN+ < VIN-. If 1, then VIN+ > VIN-.
|
||||
*
|
||||
* @note If VIN+ == VIN-, the return value depends on the previous result.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_comp_result_get(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for enabling interrupts from COMP.
|
||||
*
|
||||
* @param[in] comp_int_mask Mask of interrupts to be enabled.
|
||||
*
|
||||
* @sa nrf_comp_int_enable_check()
|
||||
*/
|
||||
__STATIC_INLINE void nrf_comp_int_enable(uint32_t comp_int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling interrupts from COMP.
|
||||
*
|
||||
* @param[in] comp_int_mask Mask of interrupts to be disabled.
|
||||
*
|
||||
* @sa nrf_comp_int_enable_check()
|
||||
*/
|
||||
__STATIC_INLINE void nrf_comp_int_disable(uint32_t comp_int_mask);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting the enabled interrupts of COMP.
|
||||
*
|
||||
* @param[in] comp_int_mask Mask of interrupts to be checked.
|
||||
*
|
||||
* @retval true If any interrupts of the specified mask are enabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_comp_int_enable_check(uint32_t comp_int_mask);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific COMP task register.
|
||||
*
|
||||
* @param[in] comp_task COMP task.
|
||||
*
|
||||
* @return Address of the specified COMP task.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_comp_task_address_get(nrf_comp_task_t comp_task);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific COMP event register.
|
||||
*
|
||||
* @param[in] comp_event COMP event.
|
||||
*
|
||||
* @return Address of the specified COMP event.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_comp_event_address_get(nrf_comp_event_t comp_event);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for setting COMP shorts.
|
||||
*
|
||||
* @param[in] comp_short_mask COMP shorts by mask.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_comp_shorts_enable(uint32_t comp_short_mask);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for clearing COMP shorts by mask.
|
||||
*
|
||||
* @param[in] comp_short_mask COMP shorts to be cleared.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_comp_shorts_disable(uint32_t comp_short_mask);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for setting a specific COMP task.
|
||||
*
|
||||
* @param[in] comp_task COMP task to be set.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_comp_task_trigger(nrf_comp_task_t comp_task);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a specific COMP event.
|
||||
*
|
||||
* @param[in] comp_event COMP event to be cleared.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_comp_event_clear(nrf_comp_event_t comp_event);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting the state of a specific COMP event.
|
||||
*
|
||||
* @retval true If the specified COMP event is active.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_comp_event_check(nrf_comp_event_t comp_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 =
|
||||
((threshold.th_down << COMP_TH_THDOWN_Pos) & COMP_TH_THDOWN_Msk) |
|
||||
((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 comp_int_mask)
|
||||
{
|
||||
NRF_COMP->INTENSET = comp_int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_comp_int_disable(uint32_t comp_int_mask)
|
||||
{
|
||||
NRF_COMP->INTENCLR = comp_int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_comp_int_enable_check(uint32_t comp_int_mask)
|
||||
{
|
||||
return (NRF_COMP->INTENSET & comp_int_mask); // when read this register will return the value of INTEN.
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_comp_task_address_get(nrf_comp_task_t comp_task)
|
||||
{
|
||||
return (uint32_t *)((uint8_t *)NRF_COMP + (uint32_t)comp_task);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_comp_event_address_get(nrf_comp_event_t comp_event)
|
||||
{
|
||||
return (uint32_t *)((uint8_t *)NRF_COMP + (uint32_t)comp_event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_comp_shorts_enable(uint32_t comp_short_mask)
|
||||
{
|
||||
NRF_COMP->SHORTS |= comp_short_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_comp_shorts_disable(uint32_t comp_short_mask)
|
||||
{
|
||||
NRF_COMP->SHORTS &= ~comp_short_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_comp_task_trigger(nrf_comp_task_t comp_task)
|
||||
{
|
||||
*( (volatile uint32_t *)( (uint8_t *)NRF_COMP + comp_task) ) = 1;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_comp_event_clear(nrf_comp_event_t comp_event)
|
||||
{
|
||||
*( (volatile uint32_t *)( (uint8_t *)NRF_COMP + (uint32_t)comp_event) ) = 0;
|
||||
#if __CORTEX_M == 0x04
|
||||
volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_COMP + (uint32_t)comp_event));
|
||||
(void)dummy;
|
||||
#endif
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_comp_event_check(nrf_comp_event_t comp_event)
|
||||
{
|
||||
return (bool) (*(volatile uint32_t *)( (uint8_t *)NRF_COMP + comp_event));
|
||||
}
|
||||
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_COMP_H_
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2012 - 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
|
||||
*/
|
||||
|
||||
//lint -e438
|
||||
|
||||
#include <nrfx.h>
|
||||
#include "nrf_ecb.h"
|
||||
#include <string.h>
|
||||
|
||||
static uint8_t ecb_data[48]; ///< ECB data structure for RNG peripheral to access.
|
||||
static uint8_t* ecb_key; ///< Key: Starts at ecb_data
|
||||
static uint8_t* ecb_cleartext; ///< Cleartext: Starts at ecb_data + 16 bytes.
|
||||
static uint8_t* ecb_ciphertext; ///< Ciphertext: Starts at ecb_data + 32 bytes.
|
||||
|
||||
bool nrf_ecb_init(void)
|
||||
{
|
||||
ecb_key = ecb_data;
|
||||
ecb_cleartext = ecb_data + 16;
|
||||
ecb_ciphertext = ecb_data + 32;
|
||||
|
||||
NRF_ECB->ECBDATAPTR = (uint32_t)ecb_data;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool nrf_ecb_crypt(uint8_t * dest_buf, const uint8_t * src_buf)
|
||||
{
|
||||
uint32_t counter = 0x1000000;
|
||||
if (src_buf != ecb_cleartext)
|
||||
{
|
||||
memcpy(ecb_cleartext,src_buf,16);
|
||||
}
|
||||
NRF_ECB->EVENTS_ENDECB = 0;
|
||||
NRF_ECB->TASKS_STARTECB = 1;
|
||||
while (NRF_ECB->EVENTS_ENDECB == 0)
|
||||
{
|
||||
counter--;
|
||||
if (counter == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
NRF_ECB->EVENTS_ENDECB = 0;
|
||||
if (dest_buf != ecb_ciphertext)
|
||||
{
|
||||
memcpy(dest_buf,ecb_ciphertext,16);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void nrf_ecb_set_key(const uint8_t * key)
|
||||
{
|
||||
memcpy(ecb_key,key,16);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,287 @@
|
||||
/*
|
||||
* Copyright (c) 2012 - 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_ECB_H__
|
||||
#define NRF_ECB_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_ecb_drv AES ECB encryption driver
|
||||
* @{
|
||||
* @ingroup nrf_ecb
|
||||
* @brief Driver for the AES Electronic Code Book (ECB) peripheral.
|
||||
*
|
||||
* To encrypt data, the peripheral must first be powered on
|
||||
* using @ref nrf_ecb_init. Next, the key must be set using @ref nrf_ecb_set_key.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Function for initializing and powering on the ECB peripheral.
|
||||
*
|
||||
* This function allocates memory for the ECBDATAPTR.
|
||||
* @retval true If initialization was successful.
|
||||
* @retval false If powering on failed.
|
||||
*/
|
||||
bool nrf_ecb_init(void);
|
||||
|
||||
/**
|
||||
* @brief Function for encrypting 16-byte data using current key.
|
||||
*
|
||||
* This function avoids unnecessary copying of data if the parameters point to the
|
||||
* correct locations in the ECB data structure.
|
||||
*
|
||||
* @param dst Result of encryption, 16 bytes will be written.
|
||||
* @param src Source with 16-byte data to be encrypted.
|
||||
*
|
||||
* @retval true If the encryption operation completed.
|
||||
* @retval false If the encryption operation did not complete.
|
||||
*/
|
||||
bool nrf_ecb_crypt(uint8_t * dst, const uint8_t * src);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the key to be used for encryption.
|
||||
*
|
||||
* @param key Pointer to the key. 16 bytes will be read.
|
||||
*/
|
||||
void nrf_ecb_set_key(const uint8_t * key);
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup nrf_ecb_hal AES ECB encryption HAL
|
||||
* @{
|
||||
* @ingroup nrf_ecb
|
||||
* @brief Hardware access layer for managing the AES Electronic Codebook (ECB) peripheral.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief ECB tasks.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30 -esym(628,__INTADDR__)*/
|
||||
NRF_ECB_TASK_STARTECB = offsetof(NRF_ECB_Type, TASKS_STARTECB), /**< Task for starting ECB block encryption. */
|
||||
NRF_ECB_TASK_STOPECB = offsetof(NRF_ECB_Type, TASKS_STOPECB), /**< Task for stopping ECB block encryption. */
|
||||
/*lint -restore*/
|
||||
} nrf_ecb_task_t;
|
||||
|
||||
/**
|
||||
* @brief ECB events.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
NRF_ECB_EVENT_ENDECB = offsetof(NRF_ECB_Type, EVENTS_ENDECB), /**< ECB block encrypt complete. */
|
||||
NRF_ECB_EVENT_ERRORECB = offsetof(NRF_ECB_Type, EVENTS_ERRORECB), /**< ECB block encrypt aborted because of a STOPECB task or due to an error. */
|
||||
/*lint -restore*/
|
||||
} nrf_ecb_event_t;
|
||||
|
||||
/**
|
||||
* @brief ECB interrupts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_ECB_INT_ENDECB_MASK = ECB_INTENSET_ENDECB_Msk, ///< Interrupt on ENDECB event.
|
||||
NRF_ECB_INT_ERRORECB_MASK = ECB_INTENSET_ERRORECB_Msk, ///< Interrupt on ERRORECB event.
|
||||
} nrf_ecb_int_mask_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for activating a specific ECB task.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral register structure.
|
||||
* @param[in] task Task to activate.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ecb_task_trigger(NRF_ECB_Type * p_reg, nrf_ecb_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific ECB task register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral register structure.
|
||||
* @param[in] task Requested task.
|
||||
*
|
||||
* @return Address of the specified task register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_ecb_task_address_get(NRF_ECB_Type const * p_reg,
|
||||
nrf_ecb_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a specific ECB event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral register structure.
|
||||
* @param[in] event Event to clear.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ecb_event_clear(NRF_ECB_Type * p_reg, nrf_ecb_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the state of a specific ECB event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral register structure.
|
||||
* @param[in] event Event to check.
|
||||
*
|
||||
* @retval true If the event is set.
|
||||
* @retval false If the event is not set.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_ecb_event_check(NRF_ECB_Type const * p_reg, nrf_ecb_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific ECB event register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral register structure.
|
||||
* @param[in] event Requested event.
|
||||
*
|
||||
* @return Address of the specified event register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_ecb_event_address_get(NRF_ECB_Type const * p_reg,
|
||||
nrf_ecb_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling specified interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral register structure.
|
||||
* @param[in] mask Interrupts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ecb_int_enable(NRF_ECB_Type * p_reg, uint32_t mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling specified interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral register structure.
|
||||
* @param[in] mask Interrupts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ecb_int_disable(NRF_ECB_Type * p_reg, uint32_t mask);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of a given interrupt.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral register structure.
|
||||
* @param[in] ecb_int Interrupt to check.
|
||||
*
|
||||
* @retval true If the interrupt is enabled.
|
||||
* @retval false If the interrupt is not enabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_ecb_int_enable_check(NRF_ECB_Type const * p_reg,
|
||||
nrf_ecb_int_mask_t ecb_int);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the pointer to the ECB data buffer.
|
||||
*
|
||||
* @note The buffer has to be placed in the Data RAM region.
|
||||
* For description of the data structure in this buffer, see the Product Specification.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral register structure.
|
||||
* @param[in] p_buffer Pointer to the ECB data buffer.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ecb_data_pointer_set(NRF_ECB_Type * p_reg, void const * p_buffer);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the pointer to the ECB data buffer.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral register structure.
|
||||
*
|
||||
* @return Pointer to the ECB data buffer.
|
||||
*/
|
||||
__STATIC_INLINE void * nrf_ecb_data_pointer_get(NRF_ECB_Type const * p_reg);
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
__STATIC_INLINE void nrf_ecb_task_trigger(NRF_ECB_Type * p_reg, nrf_ecb_task_t task)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task)) = 0x1UL;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_ecb_task_address_get(NRF_ECB_Type const * p_reg,
|
||||
nrf_ecb_task_t task)
|
||||
{
|
||||
return ((uint32_t)p_reg + (uint32_t)task);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ecb_event_clear(NRF_ECB_Type * p_reg, nrf_ecb_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_ecb_event_check(NRF_ECB_Type const * p_reg, nrf_ecb_event_t event)
|
||||
{
|
||||
return (bool)*(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_ecb_event_address_get(NRF_ECB_Type const * p_reg,
|
||||
nrf_ecb_event_t event)
|
||||
{
|
||||
return ((uint32_t)p_reg + (uint32_t)event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ecb_int_enable(NRF_ECB_Type * p_reg, uint32_t mask)
|
||||
{
|
||||
p_reg->INTENSET = mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ecb_int_disable(NRF_ECB_Type * p_reg, uint32_t mask)
|
||||
{
|
||||
p_reg->INTENCLR = mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_ecb_int_enable_check(NRF_ECB_Type const * p_reg,
|
||||
nrf_ecb_int_mask_t ecb_int)
|
||||
{
|
||||
return (bool)(p_reg->INTENSET & ecb_int);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ecb_data_pointer_set(NRF_ECB_Type * p_reg, void const * p_buffer)
|
||||
{
|
||||
p_reg->ECBDATAPTR = (uint32_t)p_buffer;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void * nrf_ecb_data_pointer_get(NRF_ECB_Type const * p_reg)
|
||||
{
|
||||
return (void *)(p_reg->ECBDATAPTR);
|
||||
}
|
||||
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_ECB_H__
|
||||
|
||||
@@ -0,0 +1,380 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_EGU_H__
|
||||
#define NRF_EGU_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_egu_hal EGU HAL
|
||||
* @{
|
||||
* @ingroup nrf_swi_egu
|
||||
* @brief Hardware access layer for managing the Event Generator Unit (EGU) peripheral.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @enum nrf_egu_task_t
|
||||
* @brief EGU tasks.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30 -esym(628,__INTADDR__)*/
|
||||
NRF_EGU_TASK_TRIGGER0 = offsetof(NRF_EGU_Type, TASKS_TRIGGER[0]), /**< Trigger 0 for triggering the corresponding TRIGGERED[0] event. */
|
||||
NRF_EGU_TASK_TRIGGER1 = offsetof(NRF_EGU_Type, TASKS_TRIGGER[1]), /**< Trigger 1 for triggering the corresponding TRIGGERED[1] event. */
|
||||
NRF_EGU_TASK_TRIGGER2 = offsetof(NRF_EGU_Type, TASKS_TRIGGER[2]), /**< Trigger 2 for triggering the corresponding TRIGGERED[2] event. */
|
||||
NRF_EGU_TASK_TRIGGER3 = offsetof(NRF_EGU_Type, TASKS_TRIGGER[3]), /**< Trigger 3 for triggering the corresponding TRIGGERED[3] event. */
|
||||
NRF_EGU_TASK_TRIGGER4 = offsetof(NRF_EGU_Type, TASKS_TRIGGER[4]), /**< Trigger 4 for triggering the corresponding TRIGGERED[4] event. */
|
||||
NRF_EGU_TASK_TRIGGER5 = offsetof(NRF_EGU_Type, TASKS_TRIGGER[5]), /**< Trigger 5 for triggering the corresponding TRIGGERED[5] event. */
|
||||
NRF_EGU_TASK_TRIGGER6 = offsetof(NRF_EGU_Type, TASKS_TRIGGER[6]), /**< Trigger 6 for triggering the corresponding TRIGGERED[6] event. */
|
||||
NRF_EGU_TASK_TRIGGER7 = offsetof(NRF_EGU_Type, TASKS_TRIGGER[7]), /**< Trigger 7 for triggering the corresponding TRIGGERED[7] event. */
|
||||
NRF_EGU_TASK_TRIGGER8 = offsetof(NRF_EGU_Type, TASKS_TRIGGER[8]), /**< Trigger 8 for triggering the corresponding TRIGGERED[8] event. */
|
||||
NRF_EGU_TASK_TRIGGER9 = offsetof(NRF_EGU_Type, TASKS_TRIGGER[9]), /**< Trigger 9 for triggering the corresponding TRIGGERED[9] event. */
|
||||
NRF_EGU_TASK_TRIGGER10 = offsetof(NRF_EGU_Type, TASKS_TRIGGER[10]), /**< Trigger 10 for triggering the corresponding TRIGGERED[10] event. */
|
||||
NRF_EGU_TASK_TRIGGER11 = offsetof(NRF_EGU_Type, TASKS_TRIGGER[11]), /**< Trigger 11 for triggering the corresponding TRIGGERED[11] event. */
|
||||
NRF_EGU_TASK_TRIGGER12 = offsetof(NRF_EGU_Type, TASKS_TRIGGER[12]), /**< Trigger 12 for triggering the corresponding TRIGGERED[12] event. */
|
||||
NRF_EGU_TASK_TRIGGER13 = offsetof(NRF_EGU_Type, TASKS_TRIGGER[13]), /**< Trigger 13 for triggering the corresponding TRIGGERED[13] event. */
|
||||
NRF_EGU_TASK_TRIGGER14 = offsetof(NRF_EGU_Type, TASKS_TRIGGER[14]), /**< Trigger 14 for triggering the corresponding TRIGGERED[14] event. */
|
||||
NRF_EGU_TASK_TRIGGER15 = offsetof(NRF_EGU_Type, TASKS_TRIGGER[15]) /**< Trigger 15 for triggering the corresponding TRIGGERED[15] event. */
|
||||
/*lint -restore*/
|
||||
} nrf_egu_task_t;
|
||||
|
||||
|
||||
/**
|
||||
* @enum nrf_egu_event_t
|
||||
* @brief EGU events.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30 -esym(628,__INTADDR__)*/
|
||||
NRF_EGU_EVENT_TRIGGERED0 = offsetof(NRF_EGU_Type, EVENTS_TRIGGERED[0]), /**< Event number 0 generated by triggering the corresponding TRIGGER[0] task. */
|
||||
NRF_EGU_EVENT_TRIGGERED1 = offsetof(NRF_EGU_Type, EVENTS_TRIGGERED[1]), /**< Event number 1 generated by triggering the corresponding TRIGGER[1] task. */
|
||||
NRF_EGU_EVENT_TRIGGERED2 = offsetof(NRF_EGU_Type, EVENTS_TRIGGERED[2]), /**< Event number 2 generated by triggering the corresponding TRIGGER[2] task. */
|
||||
NRF_EGU_EVENT_TRIGGERED3 = offsetof(NRF_EGU_Type, EVENTS_TRIGGERED[3]), /**< Event number 3 generated by triggering the corresponding TRIGGER[3] task. */
|
||||
NRF_EGU_EVENT_TRIGGERED4 = offsetof(NRF_EGU_Type, EVENTS_TRIGGERED[4]), /**< Event number 4 generated by triggering the corresponding TRIGGER[4] task. */
|
||||
NRF_EGU_EVENT_TRIGGERED5 = offsetof(NRF_EGU_Type, EVENTS_TRIGGERED[5]), /**< Event number 5 generated by triggering the corresponding TRIGGER[5] task. */
|
||||
NRF_EGU_EVENT_TRIGGERED6 = offsetof(NRF_EGU_Type, EVENTS_TRIGGERED[6]), /**< Event number 6 generated by triggering the corresponding TRIGGER[6] task. */
|
||||
NRF_EGU_EVENT_TRIGGERED7 = offsetof(NRF_EGU_Type, EVENTS_TRIGGERED[7]), /**< Event number 7 generated by triggering the corresponding TRIGGER[7] task. */
|
||||
NRF_EGU_EVENT_TRIGGERED8 = offsetof(NRF_EGU_Type, EVENTS_TRIGGERED[8]), /**< Event number 8 generated by triggering the corresponding TRIGGER[8] task. */
|
||||
NRF_EGU_EVENT_TRIGGERED9 = offsetof(NRF_EGU_Type, EVENTS_TRIGGERED[9]), /**< Event number 9 generated by triggering the corresponding TRIGGER[9] task. */
|
||||
NRF_EGU_EVENT_TRIGGERED10 = offsetof(NRF_EGU_Type, EVENTS_TRIGGERED[10]), /**< Event number 10 generated by triggering the corresponding TRIGGER[10] task. */
|
||||
NRF_EGU_EVENT_TRIGGERED11 = offsetof(NRF_EGU_Type, EVENTS_TRIGGERED[11]), /**< Event number 11 generated by triggering the corresponding TRIGGER[11] task. */
|
||||
NRF_EGU_EVENT_TRIGGERED12 = offsetof(NRF_EGU_Type, EVENTS_TRIGGERED[12]), /**< Event number 12 generated by triggering the corresponding TRIGGER[12] task. */
|
||||
NRF_EGU_EVENT_TRIGGERED13 = offsetof(NRF_EGU_Type, EVENTS_TRIGGERED[13]), /**< Event number 13 generated by triggering the corresponding TRIGGER[13] task. */
|
||||
NRF_EGU_EVENT_TRIGGERED14 = offsetof(NRF_EGU_Type, EVENTS_TRIGGERED[14]), /**< Event number 14 generated by triggering the corresponding TRIGGER[14] task. */
|
||||
NRF_EGU_EVENT_TRIGGERED15 = offsetof(NRF_EGU_Type, EVENTS_TRIGGERED[15]) /**< Event number 15 generated by triggering the corresponding TRIGGER[15] task. */
|
||||
/*lint -restore*/
|
||||
} nrf_egu_event_t;
|
||||
|
||||
|
||||
/**
|
||||
* @enum nrf_egu_int_mask_t
|
||||
* @brief EGU interrupts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_EGU_INT_TRIGGERED0 = EGU_INTENSET_TRIGGERED0_Msk, /**< Interrupt on EVENTS_TRIGGERED[0] event. */
|
||||
NRF_EGU_INT_TRIGGERED1 = EGU_INTENSET_TRIGGERED1_Msk, /**< Interrupt on EVENTS_TRIGGERED[1] event. */
|
||||
NRF_EGU_INT_TRIGGERED2 = EGU_INTENSET_TRIGGERED2_Msk, /**< Interrupt on EVENTS_TRIGGERED[2] event. */
|
||||
NRF_EGU_INT_TRIGGERED3 = EGU_INTENSET_TRIGGERED3_Msk, /**< Interrupt on EVENTS_TRIGGERED[3] event. */
|
||||
NRF_EGU_INT_TRIGGERED4 = EGU_INTENSET_TRIGGERED4_Msk, /**< Interrupt on EVENTS_TRIGGERED[4] event. */
|
||||
NRF_EGU_INT_TRIGGERED5 = EGU_INTENSET_TRIGGERED5_Msk, /**< Interrupt on EVENTS_TRIGGERED[5] event. */
|
||||
NRF_EGU_INT_TRIGGERED6 = EGU_INTENSET_TRIGGERED6_Msk, /**< Interrupt on EVENTS_TRIGGERED[6] event. */
|
||||
NRF_EGU_INT_TRIGGERED7 = EGU_INTENSET_TRIGGERED7_Msk, /**< Interrupt on EVENTS_TRIGGERED[7] event. */
|
||||
NRF_EGU_INT_TRIGGERED8 = EGU_INTENSET_TRIGGERED8_Msk, /**< Interrupt on EVENTS_TRIGGERED[8] event. */
|
||||
NRF_EGU_INT_TRIGGERED9 = EGU_INTENSET_TRIGGERED9_Msk, /**< Interrupt on EVENTS_TRIGGERED[9] event. */
|
||||
NRF_EGU_INT_TRIGGERED10 = EGU_INTENSET_TRIGGERED10_Msk, /**< Interrupt on EVENTS_TRIGGERED[10] event. */
|
||||
NRF_EGU_INT_TRIGGERED11 = EGU_INTENSET_TRIGGERED11_Msk, /**< Interrupt on EVENTS_TRIGGERED[11] event. */
|
||||
NRF_EGU_INT_TRIGGERED12 = EGU_INTENSET_TRIGGERED12_Msk, /**< Interrupt on EVENTS_TRIGGERED[12] event. */
|
||||
NRF_EGU_INT_TRIGGERED13 = EGU_INTENSET_TRIGGERED13_Msk, /**< Interrupt on EVENTS_TRIGGERED[13] event. */
|
||||
NRF_EGU_INT_TRIGGERED14 = EGU_INTENSET_TRIGGERED14_Msk, /**< Interrupt on EVENTS_TRIGGERED[14] event. */
|
||||
NRF_EGU_INT_TRIGGERED15 = EGU_INTENSET_TRIGGERED15_Msk, /**< Interrupt on EVENTS_TRIGGERED[15] event. */
|
||||
NRF_EGU_INT_ALL = 0xFFFFuL
|
||||
} nrf_egu_int_mask_t;
|
||||
|
||||
/**@brief Function for getting max channel number of given EGU.
|
||||
*
|
||||
* @param NRF_EGUx EGU instance.
|
||||
*
|
||||
* @returns number of available channels.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_egu_channel_count(NRF_EGU_Type * NRF_EGUx);
|
||||
|
||||
/**
|
||||
* @brief Function for triggering a specific EGU task.
|
||||
*
|
||||
* @param NRF_EGUx EGU instance.
|
||||
* @param egu_task EGU task.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_egu_task_trigger(NRF_EGU_Type * NRF_EGUx, nrf_egu_task_t egu_task);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a specific EGU task register.
|
||||
*
|
||||
* @param NRF_EGUx EGU instance.
|
||||
* @param egu_task EGU task.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_egu_task_address_get(NRF_EGU_Type * NRF_EGUx,
|
||||
nrf_egu_task_t egu_task);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a specific EGU TRIGGER task register.
|
||||
*
|
||||
* @param NRF_EGUx EGU instance.
|
||||
* @param channel Channel number.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_egu_task_trigger_address_get(NRF_EGU_Type * NRF_EGUx,
|
||||
uint8_t channel);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the specific EGU TRIGGER task.
|
||||
*
|
||||
* @param NRF_EGUx EGU instance.
|
||||
* @param channel Channel number.
|
||||
*/
|
||||
__STATIC_INLINE nrf_egu_task_t nrf_egu_task_trigger_get(NRF_EGU_Type * NRF_EGUx, uint8_t channel);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the state of a specific EGU event.
|
||||
*
|
||||
* @param NRF_EGUx EGU instance.
|
||||
* @param egu_event EGU event to check.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_egu_event_check(NRF_EGU_Type * NRF_EGUx,
|
||||
nrf_egu_event_t egu_event);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a specific EGU event.
|
||||
*
|
||||
* @param NRF_EGUx EGU instance.
|
||||
* @param egu_event EGU event to clear.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_egu_event_clear(NRF_EGU_Type * NRF_EGUx,
|
||||
nrf_egu_event_t egu_event);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a specific EGU event register.
|
||||
*
|
||||
* @param NRF_EGUx EGU instance.
|
||||
* @param egu_event EGU event.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_egu_event_address_get(NRF_EGU_Type * NRF_EGUx,
|
||||
nrf_egu_event_t egu_event);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a specific EGU TRIGGERED event register.
|
||||
*
|
||||
* @param NRF_EGUx EGU instance.
|
||||
* @param channel Channel number.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_egu_event_triggered_address_get(NRF_EGU_Type * NRF_EGUx,
|
||||
uint8_t channel);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the specific EGU TRIGGERED event.
|
||||
*
|
||||
* @param NRF_EGUx EGU instance.
|
||||
* @param channel Channel number.
|
||||
*/
|
||||
__STATIC_INLINE nrf_egu_event_t nrf_egu_event_triggered_get(NRF_EGU_Type * NRF_EGUx,
|
||||
uint8_t channel);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling one or more specific EGU interrupts.
|
||||
*
|
||||
* @param NRF_EGUx EGU instance.
|
||||
* @param egu_int_mask Interrupts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_egu_int_enable(NRF_EGU_Type * NRF_EGUx, uint32_t egu_int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of one or more EGU interrupts.
|
||||
*
|
||||
* @param NRF_EGUx EGU instance.
|
||||
* @param egu_int_mask Interrupts to check.
|
||||
*
|
||||
* @retval true If all of the specified interrupts are enabled.
|
||||
* @retval false If at least one of the specified interrupts is disabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_egu_int_enable_check(NRF_EGU_Type * NRF_EGUx, uint32_t egu_int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling one or more specific EGU interrupts.
|
||||
*
|
||||
* @param NRF_EGUx EGU instance.
|
||||
* @param egu_int_mask Interrupts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_egu_int_disable(NRF_EGU_Type * NRF_EGUx, uint32_t egu_int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving one or more specific EGU interrupts.
|
||||
*
|
||||
* @param NRF_EGUx EGU instance.
|
||||
* @param channel Channel number.
|
||||
*
|
||||
* @returns EGU interrupt mask.
|
||||
*/
|
||||
__STATIC_INLINE nrf_egu_int_mask_t nrf_egu_int_get(NRF_EGU_Type * NRF_EGUx, uint8_t channel);
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_egu_channel_count(NRF_EGU_Type * NRF_EGUx)
|
||||
{
|
||||
if (NRF_EGUx == NRF_EGU0){
|
||||
return EGU0_CH_NUM;
|
||||
}
|
||||
if (NRF_EGUx == NRF_EGU1){
|
||||
return EGU1_CH_NUM;
|
||||
}
|
||||
#if EGU_COUNT > 2
|
||||
if (NRF_EGUx == NRF_EGU2){
|
||||
return EGU2_CH_NUM;
|
||||
}
|
||||
if (NRF_EGUx == NRF_EGU3){
|
||||
return EGU3_CH_NUM;
|
||||
}
|
||||
if (NRF_EGUx == NRF_EGU4){
|
||||
return EGU4_CH_NUM;
|
||||
}
|
||||
if (NRF_EGUx == NRF_EGU5){
|
||||
return EGU5_CH_NUM;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_egu_task_trigger(NRF_EGU_Type * NRF_EGUx, nrf_egu_task_t egu_task)
|
||||
{
|
||||
NRFX_ASSERT(NRF_EGUx);
|
||||
*((volatile uint32_t *)((uint8_t *)NRF_EGUx + (uint32_t)egu_task)) = 0x1UL;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_egu_task_address_get(NRF_EGU_Type * NRF_EGUx,
|
||||
nrf_egu_task_t egu_task)
|
||||
{
|
||||
NRFX_ASSERT(NRF_EGUx);
|
||||
return (uint32_t *)((uint8_t *)NRF_EGUx + (uint32_t)egu_task);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_egu_task_trigger_address_get(NRF_EGU_Type * NRF_EGUx,
|
||||
uint8_t channel)
|
||||
{
|
||||
NRFX_ASSERT(NRF_EGUx);
|
||||
NRFX_ASSERT(channel < nrf_egu_channel_count(NRF_EGUx));
|
||||
return (uint32_t*)&NRF_EGUx->TASKS_TRIGGER[channel];
|
||||
}
|
||||
|
||||
__STATIC_INLINE nrf_egu_task_t nrf_egu_task_trigger_get(NRF_EGU_Type * NRF_EGUx, uint8_t channel)
|
||||
{
|
||||
NRFX_ASSERT(NRF_EGUx);
|
||||
NRFX_ASSERT(channel < nrf_egu_channel_count(NRF_EGUx));
|
||||
return (nrf_egu_task_t)((uint32_t) NRF_EGU_TASK_TRIGGER0 + (channel * sizeof(uint32_t)));
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_egu_event_check(NRF_EGU_Type * NRF_EGUx,
|
||||
nrf_egu_event_t egu_event)
|
||||
{
|
||||
NRFX_ASSERT(NRF_EGUx);
|
||||
return (bool)*(volatile uint32_t *)((uint8_t *)NRF_EGUx + (uint32_t)egu_event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_egu_event_clear(NRF_EGU_Type * NRF_EGUx,
|
||||
nrf_egu_event_t egu_event)
|
||||
{
|
||||
NRFX_ASSERT(NRF_EGUx);
|
||||
*((volatile uint32_t *)((uint8_t *)NRF_EGUx + (uint32_t)egu_event)) = 0x0UL;
|
||||
#if __CORTEX_M == 0x04
|
||||
volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_EGUx + (uint32_t)egu_event));
|
||||
(void)dummy;
|
||||
#endif
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_egu_event_address_get(NRF_EGU_Type * NRF_EGUx,
|
||||
nrf_egu_event_t egu_event)
|
||||
{
|
||||
NRFX_ASSERT(NRF_EGUx);
|
||||
return (uint32_t *)((uint8_t *)NRF_EGUx + (uint32_t)egu_event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_egu_event_triggered_address_get(NRF_EGU_Type * NRF_EGUx,
|
||||
uint8_t channel)
|
||||
{
|
||||
NRFX_ASSERT(NRF_EGUx);
|
||||
NRFX_ASSERT(channel < nrf_egu_channel_count(NRF_EGUx));
|
||||
return (uint32_t*)&NRF_EGUx->EVENTS_TRIGGERED[channel];
|
||||
}
|
||||
|
||||
__STATIC_INLINE nrf_egu_event_t nrf_egu_event_triggered_get(NRF_EGU_Type * NRF_EGUx,
|
||||
uint8_t channel)
|
||||
{
|
||||
NRFX_ASSERT(NRF_EGUx);
|
||||
NRFX_ASSERT(channel < nrf_egu_channel_count(NRF_EGUx));
|
||||
return (nrf_egu_event_t)((uint32_t) NRF_EGU_EVENT_TRIGGERED0 + (channel * sizeof(uint32_t)));
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_egu_int_enable(NRF_EGU_Type * NRF_EGUx, uint32_t egu_int_mask)
|
||||
{
|
||||
NRFX_ASSERT(NRF_EGUx);
|
||||
NRF_EGUx->INTENSET = egu_int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_egu_int_enable_check(NRF_EGU_Type * NRF_EGUx, uint32_t egu_int_mask)
|
||||
{
|
||||
NRFX_ASSERT(NRF_EGUx);
|
||||
return (bool)(NRF_EGUx->INTENSET & egu_int_mask);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_egu_int_disable(NRF_EGU_Type * NRF_EGUx, uint32_t egu_int_mask)
|
||||
{
|
||||
NRFX_ASSERT(NRF_EGUx);
|
||||
NRF_EGUx->INTENCLR = egu_int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE nrf_egu_int_mask_t nrf_egu_int_get(NRF_EGU_Type * NRF_EGUx, uint8_t channel)
|
||||
{
|
||||
NRFX_ASSERT(NRF_EGUx);
|
||||
NRFX_ASSERT(channel < nrf_egu_channel_count(NRF_EGUx));
|
||||
return (nrf_egu_int_mask_t)((uint32_t) (EGU_INTENSET_TRIGGERED0_Msk << channel));
|
||||
}
|
||||
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,794 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_GPIO_H__
|
||||
#define NRF_GPIO_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_gpio_hal GPIO HAL
|
||||
* @{
|
||||
* @ingroup nrf_gpio
|
||||
* @brief Hardware access layer for managing the GPIO peripheral.
|
||||
*/
|
||||
|
||||
#if (GPIO_COUNT == 1)
|
||||
#define NUMBER_OF_PINS (P0_PIN_NUM)
|
||||
#define GPIO_REG_LIST {NRF_GPIO}
|
||||
#elif (GPIO_COUNT == 2)
|
||||
#define NUMBER_OF_PINS (P0_PIN_NUM + P1_PIN_NUM)
|
||||
#define GPIO_REG_LIST {NRF_P0, NRF_P1}
|
||||
#else
|
||||
#error "Not supported."
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief Macro for mapping port and pin numbers to values understandable for nrf_gpio functions.
|
||||
*/
|
||||
#define NRF_GPIO_PIN_MAP(port, pin) (((port) << 5) | ((pin) & 0x1F))
|
||||
|
||||
/**
|
||||
* @brief Pin direction definitions.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_GPIO_PIN_DIR_INPUT = GPIO_PIN_CNF_DIR_Input, ///< Input.
|
||||
NRF_GPIO_PIN_DIR_OUTPUT = GPIO_PIN_CNF_DIR_Output ///< Output.
|
||||
} nrf_gpio_pin_dir_t;
|
||||
|
||||
/**
|
||||
* @brief Connection of input buffer.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_GPIO_PIN_INPUT_CONNECT = GPIO_PIN_CNF_INPUT_Connect, ///< Connect input buffer.
|
||||
NRF_GPIO_PIN_INPUT_DISCONNECT = GPIO_PIN_CNF_INPUT_Disconnect ///< Disconnect input buffer.
|
||||
} nrf_gpio_pin_input_t;
|
||||
|
||||
/**
|
||||
* @brief Enumerator used for selecting the pin to be pulled down or up at the time of pin configuration.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_GPIO_PIN_NOPULL = GPIO_PIN_CNF_PULL_Disabled, ///< Pin pull-up resistor disabled.
|
||||
NRF_GPIO_PIN_PULLDOWN = GPIO_PIN_CNF_PULL_Pulldown, ///< Pin pull-down resistor enabled.
|
||||
NRF_GPIO_PIN_PULLUP = GPIO_PIN_CNF_PULL_Pullup, ///< Pin pull-up resistor enabled.
|
||||
} nrf_gpio_pin_pull_t;
|
||||
|
||||
/**
|
||||
* @brief Enumerator used for selecting output drive mode.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_GPIO_PIN_S0S1 = GPIO_PIN_CNF_DRIVE_S0S1, ///< !< Standard '0', standard '1'.
|
||||
NRF_GPIO_PIN_H0S1 = GPIO_PIN_CNF_DRIVE_H0S1, ///< !< High-drive '0', standard '1'.
|
||||
NRF_GPIO_PIN_S0H1 = GPIO_PIN_CNF_DRIVE_S0H1, ///< !< Standard '0', high-drive '1'.
|
||||
NRF_GPIO_PIN_H0H1 = GPIO_PIN_CNF_DRIVE_H0H1, ///< !< High drive '0', high-drive '1'.
|
||||
NRF_GPIO_PIN_D0S1 = GPIO_PIN_CNF_DRIVE_D0S1, ///< !< Disconnect '0' standard '1'.
|
||||
NRF_GPIO_PIN_D0H1 = GPIO_PIN_CNF_DRIVE_D0H1, ///< !< Disconnect '0', high-drive '1'.
|
||||
NRF_GPIO_PIN_S0D1 = GPIO_PIN_CNF_DRIVE_S0D1, ///< !< Standard '0', disconnect '1'.
|
||||
NRF_GPIO_PIN_H0D1 = GPIO_PIN_CNF_DRIVE_H0D1, ///< !< High-drive '0', disconnect '1'.
|
||||
} nrf_gpio_pin_drive_t;
|
||||
|
||||
/**
|
||||
* @brief Enumerator used for selecting the pin to sense high or low level on the pin input.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_GPIO_PIN_NOSENSE = GPIO_PIN_CNF_SENSE_Disabled, ///< Pin sense level disabled.
|
||||
NRF_GPIO_PIN_SENSE_LOW = GPIO_PIN_CNF_SENSE_Low, ///< Pin sense low level.
|
||||
NRF_GPIO_PIN_SENSE_HIGH = GPIO_PIN_CNF_SENSE_High, ///< Pin sense high level.
|
||||
} nrf_gpio_pin_sense_t;
|
||||
|
||||
/**
|
||||
* @brief Function for configuring the GPIO pin range as output pins with normal drive strength.
|
||||
* This function can be used to configure pin range as simple output with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases).
|
||||
*
|
||||
* @param pin_range_start Specifies the start number (inclusive) in the range of pin numbers to be configured (allowed values 0-30).
|
||||
*
|
||||
* @param pin_range_end Specifies the end number (inclusive) in the range of pin numbers to be configured (allowed values 0-30).
|
||||
*
|
||||
* @note For configuring only one pin as output, use @ref nrf_gpio_cfg_output.
|
||||
* Sense capability on the pin is disabled and input is disconnected from the buffer as the pins are configured as output.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_range_cfg_output(uint32_t pin_range_start, uint32_t pin_range_end);
|
||||
|
||||
/**
|
||||
* @brief Function for configuring the GPIO pin range as input pins with given initial value set, hiding inner details.
|
||||
* This function can be used to configure pin range as simple input.
|
||||
*
|
||||
* @param pin_range_start Specifies the start number (inclusive) in the range of pin numbers to be configured (allowed values 0-30).
|
||||
*
|
||||
* @param pin_range_end Specifies the end number (inclusive) in the range of pin numbers to be configured (allowed values 0-30).
|
||||
*
|
||||
* @param pull_config State of the pin range pull resistor (no pull, pulled down, or pulled high).
|
||||
*
|
||||
* @note For configuring only one pin as input, use @ref nrf_gpio_cfg_input.
|
||||
* Sense capability on the pin is disabled and input is connected to buffer so that the GPIO->IN register is readable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_range_cfg_input(uint32_t pin_range_start,
|
||||
uint32_t pin_range_end,
|
||||
nrf_gpio_pin_pull_t pull_config);
|
||||
|
||||
/**
|
||||
* @brief Pin configuration function.
|
||||
*
|
||||
* The main pin configuration function.
|
||||
* This function allows to set any aspect in PIN_CNF register.
|
||||
* @param pin_number Specifies the pin number.
|
||||
* @param dir Pin direction.
|
||||
* @param input Connect or disconnect the input buffer.
|
||||
* @param pull Pull configuration.
|
||||
* @param drive Drive configuration.
|
||||
* @param sense Pin sensing mechanism.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_cfg(
|
||||
uint32_t pin_number,
|
||||
nrf_gpio_pin_dir_t dir,
|
||||
nrf_gpio_pin_input_t input,
|
||||
nrf_gpio_pin_pull_t pull,
|
||||
nrf_gpio_pin_drive_t drive,
|
||||
nrf_gpio_pin_sense_t sense);
|
||||
|
||||
/**
|
||||
* @brief Function for configuring the given GPIO pin number as output, hiding inner details.
|
||||
* This function can be used to configure a pin as simple output with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases).
|
||||
*
|
||||
* @param pin_number Specifies the pin number.
|
||||
*
|
||||
* @note Sense capability on the pin is disabled and input is disconnected from the buffer as the pins are configured as output.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_cfg_output(uint32_t pin_number);
|
||||
|
||||
/**
|
||||
* @brief Function for configuring the given GPIO pin number as input, hiding inner details.
|
||||
* This function can be used to configure a pin as simple input.
|
||||
*
|
||||
* @param pin_number Specifies the pin number.
|
||||
* @param pull_config State of the pin range pull resistor (no pull, pulled down, or pulled high).
|
||||
*
|
||||
* @note Sense capability on the pin is disabled and input is connected to buffer so that the GPIO->IN register is readable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config);
|
||||
|
||||
/**
|
||||
* @brief Function for resetting pin configuration to its default state.
|
||||
*
|
||||
* @param pin_number Specifies the pin number.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_cfg_default(uint32_t pin_number);
|
||||
|
||||
/**
|
||||
* @brief Function for configuring the given GPIO pin number as a watcher. Only input is connected.
|
||||
*
|
||||
* @param pin_number Specifies the pin number.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_cfg_watcher(uint32_t pin_number);
|
||||
|
||||
/**
|
||||
* @brief Function for disconnecting input for the given GPIO.
|
||||
*
|
||||
* @param pin_number Specifies the pin number.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_input_disconnect(uint32_t pin_number);
|
||||
|
||||
/**
|
||||
* @brief Function for configuring the given GPIO pin number as input, hiding inner details.
|
||||
* This function can be used to configure pin range as simple input.
|
||||
* Sense capability on the pin is configurable and input is connected to buffer so that the GPIO->IN register is readable.
|
||||
*
|
||||
* @param pin_number Specifies the pin number.
|
||||
* @param pull_config State of the pin pull resistor (no pull, pulled down, or pulled high).
|
||||
* @param sense_config Sense level of the pin (no sense, sense low, or sense high).
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_cfg_sense_input(uint32_t pin_number,
|
||||
nrf_gpio_pin_pull_t pull_config,
|
||||
nrf_gpio_pin_sense_t sense_config);
|
||||
|
||||
/**
|
||||
* @brief Function for configuring sense level for the given GPIO.
|
||||
*
|
||||
* @param pin_number Specifies the pin number.
|
||||
* @param sense_config Sense configuration.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_cfg_sense_set(uint32_t pin_number, nrf_gpio_pin_sense_t sense_config);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the direction for a GPIO pin.
|
||||
*
|
||||
* @param pin_number Specifies the pin number for which to set the direction.
|
||||
*
|
||||
* @param direction Specifies the direction.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_pin_dir_set(uint32_t pin_number, nrf_gpio_pin_dir_t direction);
|
||||
|
||||
/**
|
||||
* @brief Function for setting a GPIO pin.
|
||||
*
|
||||
* Note that the pin must be configured as an output for this function to have any effect.
|
||||
*
|
||||
* @param pin_number Specifies the pin number to set.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_pin_set(uint32_t pin_number);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a GPIO pin.
|
||||
*
|
||||
* Note that the pin must be configured as an output for this
|
||||
* function to have any effect.
|
||||
*
|
||||
* @param pin_number Specifies the pin number to clear.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_pin_clear(uint32_t pin_number);
|
||||
|
||||
/**
|
||||
* @brief Function for toggling a GPIO pin.
|
||||
*
|
||||
* Note that the pin must be configured as an output for this
|
||||
* function to have any effect.
|
||||
*
|
||||
* @param pin_number Specifies the pin number to toggle.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_pin_toggle(uint32_t pin_number);
|
||||
|
||||
/**
|
||||
* @brief Function for writing a value to a GPIO pin.
|
||||
*
|
||||
* Note that the pin must be configured as an output for this
|
||||
* function to have any effect.
|
||||
*
|
||||
* @param pin_number Specifies the pin number to write.
|
||||
*
|
||||
* @param value Specifies the value to be written to the pin.
|
||||
* @arg 0 Clears the pin.
|
||||
* @arg >=1 Sets the pin.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_pin_write(uint32_t pin_number, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Function for reading the input level of a GPIO pin.
|
||||
*
|
||||
* Note that the pin must have input connected for the value
|
||||
* returned from this function to be valid.
|
||||
*
|
||||
* @param pin_number Specifies the pin number to read.
|
||||
*
|
||||
* @return 0 if the pin input level is low. Positive value if the pin is high.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_gpio_pin_read(uint32_t pin_number);
|
||||
|
||||
/**
|
||||
* @brief Function for reading the output level of a GPIO pin.
|
||||
*
|
||||
* @param pin_number Specifies the pin number to read.
|
||||
*
|
||||
* @return 0 if the pin output level is low. Positive value if pin output is high.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_gpio_pin_out_read(uint32_t pin_number);
|
||||
|
||||
/**
|
||||
* @brief Function for reading the sense configuration of a GPIO pin.
|
||||
*
|
||||
* @param pin_number Specifies the pin number to read.
|
||||
*
|
||||
* @retval Sense configuration.
|
||||
*/
|
||||
__STATIC_INLINE nrf_gpio_pin_sense_t nrf_gpio_pin_sense_get(uint32_t pin_number);
|
||||
|
||||
/**
|
||||
* @brief Function for reading the direction configuration of a GPIO pin.
|
||||
*
|
||||
* @param pin_number Specifies the pin number to read.
|
||||
*
|
||||
* @retval Direction configuration.
|
||||
*/
|
||||
__STATIC_INLINE nrf_gpio_pin_dir_t nrf_gpio_pin_dir_get(uint32_t pin_number);
|
||||
|
||||
/**
|
||||
* @brief Function for setting output direction on selected pins on a given port.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param out_mask Mask specifying the pins to set as output.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_port_dir_output_set(NRF_GPIO_Type * p_reg, uint32_t out_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for setting input direction on selected pins on a given port.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param in_mask Mask specifying the pins to set as input.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_port_dir_input_set(NRF_GPIO_Type * p_reg, uint32_t in_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for writing the direction configuration of GPIO pins in a given port.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param dir_mask Mask specifying the direction of pins. Bit set means that the given pin is configured as output.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_port_dir_write(NRF_GPIO_Type * p_reg, uint32_t dir_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for reading the direction configuration of a GPIO port.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*
|
||||
* @retval Pin configuration of the current direction settings. Bit set means that the given pin is configured as output.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_gpio_port_dir_read(NRF_GPIO_Type const * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for reading the input signals of GPIO pins on a given port.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*
|
||||
* @retval Port input values.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_gpio_port_in_read(NRF_GPIO_Type const * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for reading the output signals of GPIO pins of a given port.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*
|
||||
* @retval Port output values.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_gpio_port_out_read(NRF_GPIO_Type const * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for writing the GPIO pins output on a given port.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param value Output port mask.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_port_out_write(NRF_GPIO_Type * p_reg, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Function for setting high level on selected GPIO pins of a given port.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param set_mask Mask with pins to set as logical high level.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_port_out_set(NRF_GPIO_Type * p_reg, uint32_t set_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for setting low level on selected GPIO pins of a given port.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param clr_mask Mask with pins to set as logical low level.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_port_out_clear(NRF_GPIO_Type * p_reg, uint32_t clr_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for reading pins state of multiple consecutive ports.
|
||||
*
|
||||
* @param start_port Index of the first port to read.
|
||||
* @param length Number of ports to read.
|
||||
* @param p_masks Pointer to output array where port states will be stored.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_ports_read(uint32_t start_port, uint32_t length, uint32_t * p_masks);
|
||||
|
||||
#if defined(GPIO_DETECTMODE_DETECTMODE_LDETECT) || defined(__NRF_DOXYGEN__)
|
||||
/**
|
||||
* @brief Function for reading latch state of multiple consecutive ports.
|
||||
*
|
||||
* @param start_port Index of the first port to read.
|
||||
* @param length Number of ports to read.
|
||||
* @param p_masks Pointer to output array where latch states will be stored.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_latches_read(uint32_t start_port, uint32_t length,
|
||||
uint32_t * p_masks);
|
||||
|
||||
/**
|
||||
* @brief Function for reading latch state of single pin.
|
||||
*
|
||||
* @param pin_number Pin number.
|
||||
* @return 0 if latch is not set. Positive value otherwise.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_gpio_pin_latch_get(uint32_t pin_number);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing latch state of a single pin.
|
||||
*
|
||||
* @param pin_number Pin number.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpio_pin_latch_clear(uint32_t pin_number);
|
||||
#endif
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/**
|
||||
* @brief Function for extracting port and relative pin number from absolute pin number.
|
||||
*
|
||||
* @param[inout] Pointer to absolute pin number which is overriden by relative to port pin number.
|
||||
*
|
||||
* @return Pointer to port register set.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE NRF_GPIO_Type * nrf_gpio_pin_port_decode(uint32_t * p_pin)
|
||||
{
|
||||
NRFX_ASSERT(*p_pin < NUMBER_OF_PINS);
|
||||
#if (GPIO_COUNT == 1)
|
||||
// The oldest definition case
|
||||
return NRF_GPIO;
|
||||
#else
|
||||
if (*p_pin < P0_PIN_NUM)
|
||||
{
|
||||
return NRF_P0;
|
||||
}
|
||||
else
|
||||
{
|
||||
*p_pin = *p_pin & (P0_PIN_NUM - 1);
|
||||
return NRF_P1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_range_cfg_output(uint32_t pin_range_start, uint32_t pin_range_end)
|
||||
{
|
||||
/*lint -e{845} // A zero has been given as right argument to operator '|'" */
|
||||
for (; pin_range_start <= pin_range_end; pin_range_start++)
|
||||
{
|
||||
nrf_gpio_cfg_output(pin_range_start);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_range_cfg_input(uint32_t pin_range_start,
|
||||
uint32_t pin_range_end,
|
||||
nrf_gpio_pin_pull_t pull_config)
|
||||
{
|
||||
/*lint -e{845} // A zero has been given as right argument to operator '|'" */
|
||||
for (; pin_range_start <= pin_range_end; pin_range_start++)
|
||||
{
|
||||
nrf_gpio_cfg_input(pin_range_start, pull_config);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_cfg(
|
||||
uint32_t pin_number,
|
||||
nrf_gpio_pin_dir_t dir,
|
||||
nrf_gpio_pin_input_t input,
|
||||
nrf_gpio_pin_pull_t pull,
|
||||
nrf_gpio_pin_drive_t drive,
|
||||
nrf_gpio_pin_sense_t sense)
|
||||
{
|
||||
NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
|
||||
|
||||
reg->PIN_CNF[pin_number] = ((uint32_t)dir << GPIO_PIN_CNF_DIR_Pos)
|
||||
| ((uint32_t)input << GPIO_PIN_CNF_INPUT_Pos)
|
||||
| ((uint32_t)pull << GPIO_PIN_CNF_PULL_Pos)
|
||||
| ((uint32_t)drive << GPIO_PIN_CNF_DRIVE_Pos)
|
||||
| ((uint32_t)sense << GPIO_PIN_CNF_SENSE_Pos);
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_cfg_output(uint32_t pin_number)
|
||||
{
|
||||
nrf_gpio_cfg(
|
||||
pin_number,
|
||||
NRF_GPIO_PIN_DIR_OUTPUT,
|
||||
NRF_GPIO_PIN_INPUT_DISCONNECT,
|
||||
NRF_GPIO_PIN_NOPULL,
|
||||
NRF_GPIO_PIN_S0S1,
|
||||
NRF_GPIO_PIN_NOSENSE);
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config)
|
||||
{
|
||||
nrf_gpio_cfg(
|
||||
pin_number,
|
||||
NRF_GPIO_PIN_DIR_INPUT,
|
||||
NRF_GPIO_PIN_INPUT_CONNECT,
|
||||
pull_config,
|
||||
NRF_GPIO_PIN_S0S1,
|
||||
NRF_GPIO_PIN_NOSENSE);
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_cfg_default(uint32_t pin_number)
|
||||
{
|
||||
nrf_gpio_cfg(
|
||||
pin_number,
|
||||
NRF_GPIO_PIN_DIR_INPUT,
|
||||
NRF_GPIO_PIN_INPUT_DISCONNECT,
|
||||
NRF_GPIO_PIN_NOPULL,
|
||||
NRF_GPIO_PIN_S0S1,
|
||||
NRF_GPIO_PIN_NOSENSE);
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_cfg_watcher(uint32_t pin_number)
|
||||
{
|
||||
NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
|
||||
/*lint -e{845} // A zero has been given as right argument to operator '|'" */
|
||||
uint32_t cnf = reg->PIN_CNF[pin_number] & ~GPIO_PIN_CNF_INPUT_Msk;
|
||||
|
||||
reg->PIN_CNF[pin_number] = cnf | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos);
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_input_disconnect(uint32_t pin_number)
|
||||
{
|
||||
NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
|
||||
/*lint -e{845} // A zero has been given as right argument to operator '|'" */
|
||||
uint32_t cnf = reg->PIN_CNF[pin_number] & ~GPIO_PIN_CNF_INPUT_Msk;
|
||||
|
||||
reg->PIN_CNF[pin_number] = cnf | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos);
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_cfg_sense_input(uint32_t pin_number,
|
||||
nrf_gpio_pin_pull_t pull_config,
|
||||
nrf_gpio_pin_sense_t sense_config)
|
||||
{
|
||||
nrf_gpio_cfg(
|
||||
pin_number,
|
||||
NRF_GPIO_PIN_DIR_INPUT,
|
||||
NRF_GPIO_PIN_INPUT_CONNECT,
|
||||
pull_config,
|
||||
NRF_GPIO_PIN_S0S1,
|
||||
sense_config);
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_cfg_sense_set(uint32_t pin_number, nrf_gpio_pin_sense_t sense_config)
|
||||
{
|
||||
NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
|
||||
|
||||
/*lint -e{845} // A zero has been given as right argument to operator '|'" */
|
||||
reg->PIN_CNF[pin_number] &= ~GPIO_PIN_CNF_SENSE_Msk;
|
||||
reg->PIN_CNF[pin_number] |= (sense_config << GPIO_PIN_CNF_SENSE_Pos);
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_pin_dir_set(uint32_t pin_number, nrf_gpio_pin_dir_t direction)
|
||||
{
|
||||
if (direction == NRF_GPIO_PIN_DIR_INPUT)
|
||||
{
|
||||
nrf_gpio_cfg(
|
||||
pin_number,
|
||||
NRF_GPIO_PIN_DIR_INPUT,
|
||||
NRF_GPIO_PIN_INPUT_CONNECT,
|
||||
NRF_GPIO_PIN_NOPULL,
|
||||
NRF_GPIO_PIN_S0S1,
|
||||
NRF_GPIO_PIN_NOSENSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
|
||||
reg->DIRSET = (1UL << pin_number);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_pin_set(uint32_t pin_number)
|
||||
{
|
||||
NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
|
||||
|
||||
nrf_gpio_port_out_set(reg, 1UL << pin_number);
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_pin_clear(uint32_t pin_number)
|
||||
{
|
||||
NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
|
||||
|
||||
nrf_gpio_port_out_clear(reg, 1UL << pin_number);
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_pin_toggle(uint32_t pin_number)
|
||||
{
|
||||
NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
|
||||
uint32_t pins_state = reg->OUT;
|
||||
|
||||
reg->OUTSET = (~pins_state & (1UL << pin_number));
|
||||
reg->OUTCLR = (pins_state & (1UL << pin_number));
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_pin_write(uint32_t pin_number, uint32_t value)
|
||||
{
|
||||
if (value == 0)
|
||||
{
|
||||
nrf_gpio_pin_clear(pin_number);
|
||||
}
|
||||
else
|
||||
{
|
||||
nrf_gpio_pin_set(pin_number);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_gpio_pin_read(uint32_t pin_number)
|
||||
{
|
||||
NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
|
||||
|
||||
return ((nrf_gpio_port_in_read(reg) >> pin_number) & 1UL);
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_gpio_pin_out_read(uint32_t pin_number)
|
||||
{
|
||||
NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
|
||||
|
||||
return ((nrf_gpio_port_out_read(reg) >> pin_number) & 1UL);
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE nrf_gpio_pin_sense_t nrf_gpio_pin_sense_get(uint32_t pin_number)
|
||||
{
|
||||
NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
|
||||
|
||||
return (nrf_gpio_pin_sense_t)((reg->PIN_CNF[pin_number] &
|
||||
GPIO_PIN_CNF_SENSE_Msk) >> GPIO_PIN_CNF_SENSE_Pos);
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE nrf_gpio_pin_dir_t nrf_gpio_pin_dir_get(uint32_t pin_number)
|
||||
{
|
||||
NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
|
||||
|
||||
return (nrf_gpio_pin_dir_t)((reg->PIN_CNF[pin_number] &
|
||||
GPIO_PIN_CNF_DIR_Msk) >> GPIO_PIN_CNF_DIR_Pos);
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_port_dir_output_set(NRF_GPIO_Type * p_reg, uint32_t out_mask)
|
||||
{
|
||||
p_reg->DIRSET = out_mask;
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_port_dir_input_set(NRF_GPIO_Type * p_reg, uint32_t in_mask)
|
||||
{
|
||||
p_reg->DIRCLR = in_mask;
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_port_dir_write(NRF_GPIO_Type * p_reg, uint32_t value)
|
||||
{
|
||||
p_reg->DIR = value;
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_gpio_port_dir_read(NRF_GPIO_Type const * p_reg)
|
||||
{
|
||||
return p_reg->DIR;
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_gpio_port_in_read(NRF_GPIO_Type const * p_reg)
|
||||
{
|
||||
return p_reg->IN;
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_gpio_port_out_read(NRF_GPIO_Type const * p_reg)
|
||||
{
|
||||
return p_reg->OUT;
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_port_out_write(NRF_GPIO_Type * p_reg, uint32_t value)
|
||||
{
|
||||
p_reg->OUT = value;
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_port_out_set(NRF_GPIO_Type * p_reg, uint32_t set_mask)
|
||||
{
|
||||
p_reg->OUTSET = set_mask;
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_port_out_clear(NRF_GPIO_Type * p_reg, uint32_t clr_mask)
|
||||
{
|
||||
p_reg->OUTCLR = clr_mask;
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_ports_read(uint32_t start_port, uint32_t length, uint32_t * p_masks)
|
||||
{
|
||||
NRF_GPIO_Type * gpio_regs[GPIO_COUNT] = GPIO_REG_LIST;
|
||||
|
||||
NRFX_ASSERT(start_port + length <= GPIO_COUNT);
|
||||
uint32_t i;
|
||||
|
||||
for (i = start_port; i < (start_port + length); i++)
|
||||
{
|
||||
*p_masks = nrf_gpio_port_in_read(gpio_regs[i]);
|
||||
p_masks++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef GPIO_DETECTMODE_DETECTMODE_LDETECT
|
||||
__STATIC_INLINE void nrf_gpio_latches_read(uint32_t start_port, uint32_t length, uint32_t * p_masks)
|
||||
{
|
||||
NRF_GPIO_Type * gpio_regs[GPIO_COUNT] = GPIO_REG_LIST;
|
||||
uint32_t i;
|
||||
|
||||
for (i = start_port; i < (start_port + length); i++)
|
||||
{
|
||||
*p_masks = gpio_regs[i]->LATCH;
|
||||
p_masks++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_gpio_pin_latch_get(uint32_t pin_number)
|
||||
{
|
||||
NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
|
||||
|
||||
return (reg->LATCH & (1 << pin_number)) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_gpio_pin_latch_clear(uint32_t pin_number)
|
||||
{
|
||||
NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
|
||||
|
||||
reg->LATCH = (1 << pin_number);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_GPIO_H__
|
||||
@@ -0,0 +1,419 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_GPIOTE_H__
|
||||
#define NRF_GPIOTE_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_gpiote_hal GPIOTE HAL
|
||||
* @{
|
||||
* @ingroup nrf_gpiote
|
||||
* @brief Hardware access layer for managing the GPIOTE peripheral.
|
||||
*/
|
||||
|
||||
#ifdef GPIOTE_CONFIG_PORT_Msk
|
||||
#define GPIOTE_CONFIG_PORT_PIN_Msk (GPIOTE_CONFIG_PORT_Msk | GPIOTE_CONFIG_PSEL_Msk)
|
||||
#else
|
||||
#define GPIOTE_CONFIG_PORT_PIN_Msk GPIOTE_CONFIG_PSEL_Msk
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @enum nrf_gpiote_polarity_t
|
||||
* @brief Polarity for the GPIOTE channel.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_GPIOTE_POLARITY_LOTOHI = GPIOTE_CONFIG_POLARITY_LoToHi, ///< Low to high.
|
||||
NRF_GPIOTE_POLARITY_HITOLO = GPIOTE_CONFIG_POLARITY_HiToLo, ///< High to low.
|
||||
NRF_GPIOTE_POLARITY_TOGGLE = GPIOTE_CONFIG_POLARITY_Toggle ///< Toggle.
|
||||
} nrf_gpiote_polarity_t;
|
||||
|
||||
|
||||
/**
|
||||
* @enum nrf_gpiote_outinit_t
|
||||
* @brief Initial output value for the GPIOTE channel.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_GPIOTE_INITIAL_VALUE_LOW = GPIOTE_CONFIG_OUTINIT_Low, ///< Low to high.
|
||||
NRF_GPIOTE_INITIAL_VALUE_HIGH = GPIOTE_CONFIG_OUTINIT_High ///< High to low.
|
||||
} nrf_gpiote_outinit_t;
|
||||
|
||||
/**
|
||||
* @brief Tasks.
|
||||
*/
|
||||
typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
|
||||
{
|
||||
NRF_GPIOTE_TASKS_OUT_0 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[0]), /**< Out task 0.*/
|
||||
NRF_GPIOTE_TASKS_OUT_1 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[1]), /**< Out task 1.*/
|
||||
NRF_GPIOTE_TASKS_OUT_2 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[2]), /**< Out task 2.*/
|
||||
NRF_GPIOTE_TASKS_OUT_3 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[3]), /**< Out task 3.*/
|
||||
#if (GPIOTE_CH_NUM > 4) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_GPIOTE_TASKS_OUT_4 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[4]), /**< Out task 4.*/
|
||||
NRF_GPIOTE_TASKS_OUT_5 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[5]), /**< Out task 5.*/
|
||||
NRF_GPIOTE_TASKS_OUT_6 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[6]), /**< Out task 6.*/
|
||||
NRF_GPIOTE_TASKS_OUT_7 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[7]), /**< Out task 7.*/
|
||||
#endif
|
||||
#if defined(GPIOTE_FEATURE_SET_PRESENT) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_GPIOTE_TASKS_SET_0 = offsetof(NRF_GPIOTE_Type, TASKS_SET[0]), /**< Set task 0.*/
|
||||
NRF_GPIOTE_TASKS_SET_1 = offsetof(NRF_GPIOTE_Type, TASKS_SET[1]), /**< Set task 1.*/
|
||||
NRF_GPIOTE_TASKS_SET_2 = offsetof(NRF_GPIOTE_Type, TASKS_SET[2]), /**< Set task 2.*/
|
||||
NRF_GPIOTE_TASKS_SET_3 = offsetof(NRF_GPIOTE_Type, TASKS_SET[3]), /**< Set task 3.*/
|
||||
NRF_GPIOTE_TASKS_SET_4 = offsetof(NRF_GPIOTE_Type, TASKS_SET[4]), /**< Set task 4.*/
|
||||
NRF_GPIOTE_TASKS_SET_5 = offsetof(NRF_GPIOTE_Type, TASKS_SET[5]), /**< Set task 5.*/
|
||||
NRF_GPIOTE_TASKS_SET_6 = offsetof(NRF_GPIOTE_Type, TASKS_SET[6]), /**< Set task 6.*/
|
||||
NRF_GPIOTE_TASKS_SET_7 = offsetof(NRF_GPIOTE_Type, TASKS_SET[7]), /**< Set task 7.*/
|
||||
#endif
|
||||
#if defined(GPIOTE_FEATURE_CLR_PRESENT) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_GPIOTE_TASKS_CLR_0 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[0]), /**< Clear task 0.*/
|
||||
NRF_GPIOTE_TASKS_CLR_1 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[1]), /**< Clear task 1.*/
|
||||
NRF_GPIOTE_TASKS_CLR_2 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[2]), /**< Clear task 2.*/
|
||||
NRF_GPIOTE_TASKS_CLR_3 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[3]), /**< Clear task 3.*/
|
||||
NRF_GPIOTE_TASKS_CLR_4 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[4]), /**< Clear task 4.*/
|
||||
NRF_GPIOTE_TASKS_CLR_5 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[5]), /**< Clear task 5.*/
|
||||
NRF_GPIOTE_TASKS_CLR_6 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[6]), /**< Clear task 6.*/
|
||||
NRF_GPIOTE_TASKS_CLR_7 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[7]), /**< Clear task 7.*/
|
||||
#endif
|
||||
/*lint -restore*/
|
||||
} nrf_gpiote_tasks_t;
|
||||
|
||||
/**
|
||||
* @brief Events.
|
||||
*/
|
||||
typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
|
||||
{
|
||||
NRF_GPIOTE_EVENTS_IN_0 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[0]), /**< In event 0.*/
|
||||
NRF_GPIOTE_EVENTS_IN_1 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[1]), /**< In event 1.*/
|
||||
NRF_GPIOTE_EVENTS_IN_2 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[2]), /**< In event 2.*/
|
||||
NRF_GPIOTE_EVENTS_IN_3 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[3]), /**< In event 3.*/
|
||||
#if (GPIOTE_CH_NUM > 4) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_GPIOTE_EVENTS_IN_4 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[4]), /**< In event 4.*/
|
||||
NRF_GPIOTE_EVENTS_IN_5 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[5]), /**< In event 5.*/
|
||||
NRF_GPIOTE_EVENTS_IN_6 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[6]), /**< In event 6.*/
|
||||
NRF_GPIOTE_EVENTS_IN_7 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[7]), /**< In event 7.*/
|
||||
#endif
|
||||
NRF_GPIOTE_EVENTS_PORT = offsetof(NRF_GPIOTE_Type, EVENTS_PORT), /**< Port event.*/
|
||||
/*lint -restore*/
|
||||
} nrf_gpiote_events_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_gpiote_int_t
|
||||
* @brief GPIOTE interrupts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_GPIOTE_INT_IN0_MASK = GPIOTE_INTENSET_IN0_Msk, /**< GPIOTE interrupt from IN0. */
|
||||
NRF_GPIOTE_INT_IN1_MASK = GPIOTE_INTENSET_IN1_Msk, /**< GPIOTE interrupt from IN1. */
|
||||
NRF_GPIOTE_INT_IN2_MASK = GPIOTE_INTENSET_IN2_Msk, /**< GPIOTE interrupt from IN2. */
|
||||
NRF_GPIOTE_INT_IN3_MASK = GPIOTE_INTENSET_IN3_Msk, /**< GPIOTE interrupt from IN3. */
|
||||
#if (GPIOTE_CH_NUM > 4) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_GPIOTE_INT_IN4_MASK = GPIOTE_INTENSET_IN4_Msk, /**< GPIOTE interrupt from IN4. */
|
||||
NRF_GPIOTE_INT_IN5_MASK = GPIOTE_INTENSET_IN5_Msk, /**< GPIOTE interrupt from IN5. */
|
||||
NRF_GPIOTE_INT_IN6_MASK = GPIOTE_INTENSET_IN6_Msk, /**< GPIOTE interrupt from IN6. */
|
||||
NRF_GPIOTE_INT_IN7_MASK = GPIOTE_INTENSET_IN7_Msk, /**< GPIOTE interrupt from IN7. */
|
||||
#endif
|
||||
NRF_GPIOTE_INT_PORT_MASK = (int)GPIOTE_INTENSET_PORT_Msk, /**< GPIOTE interrupt from PORT event. */
|
||||
} nrf_gpiote_int_t;
|
||||
|
||||
#define NRF_GPIOTE_INT_IN_MASK (NRF_GPIOTE_INT_IN0_MASK | NRF_GPIOTE_INT_IN1_MASK |\
|
||||
NRF_GPIOTE_INT_IN2_MASK | NRF_GPIOTE_INT_IN3_MASK)
|
||||
#if (GPIOTE_CH_NUM > 4)
|
||||
#undef NRF_GPIOTE_INT_IN_MASK
|
||||
#define NRF_GPIOTE_INT_IN_MASK (NRF_GPIOTE_INT_IN0_MASK | NRF_GPIOTE_INT_IN1_MASK |\
|
||||
NRF_GPIOTE_INT_IN2_MASK | NRF_GPIOTE_INT_IN3_MASK |\
|
||||
NRF_GPIOTE_INT_IN4_MASK | NRF_GPIOTE_INT_IN5_MASK |\
|
||||
NRF_GPIOTE_INT_IN6_MASK | NRF_GPIOTE_INT_IN7_MASK)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Function for activating a specific GPIOTE task.
|
||||
*
|
||||
* @param[in] task Task.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpiote_task_set(nrf_gpiote_tasks_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific GPIOTE task.
|
||||
*
|
||||
* @param[in] task Task.
|
||||
*
|
||||
* @returns Address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_gpiote_task_addr_get(nrf_gpiote_tasks_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the state of a specific GPIOTE event.
|
||||
*
|
||||
* @param[in] event Event.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_gpiote_event_is_set(nrf_gpiote_events_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a specific GPIOTE event.
|
||||
*
|
||||
* @param[in] event Event.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpiote_event_clear(nrf_gpiote_events_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific GPIOTE event.
|
||||
*
|
||||
* @param[in] event Event.
|
||||
*
|
||||
* @return Address
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_gpiote_event_addr_get(nrf_gpiote_events_t event);
|
||||
|
||||
/**@brief Function for enabling interrupts.
|
||||
*
|
||||
* @param[in] mask Interrupt mask to be enabled.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpiote_int_enable(uint32_t mask);
|
||||
|
||||
/**@brief Function for disabling interrupts.
|
||||
*
|
||||
* @param[in] mask Interrupt mask to be disabled.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpiote_int_disable(uint32_t mask);
|
||||
|
||||
/**@brief Function for checking if interrupts are enabled.
|
||||
*
|
||||
* @param[in] mask Mask of interrupt flags to check.
|
||||
*
|
||||
* @return Mask with enabled interrupts.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_gpiote_int_is_enabled(uint32_t mask);
|
||||
|
||||
/**@brief Function for enabling a GPIOTE event.
|
||||
*
|
||||
* @param[in] idx Task-Event index.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpiote_event_enable(uint32_t idx);
|
||||
|
||||
/**@brief Function for disabling a GPIOTE event.
|
||||
*
|
||||
* @param[in] idx Task-Event index.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpiote_event_disable(uint32_t idx);
|
||||
|
||||
/**@brief Function for configuring a GPIOTE event.
|
||||
*
|
||||
* @param[in] idx Task-Event index.
|
||||
* @param[in] pin Pin associated with event.
|
||||
* @param[in] polarity Transition that should generate an event.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpiote_event_configure(uint32_t idx, uint32_t pin,
|
||||
nrf_gpiote_polarity_t polarity);
|
||||
|
||||
/**@brief Function for getting the pin associated with a GPIOTE event.
|
||||
*
|
||||
* @param[in] idx Task-Event index.
|
||||
*
|
||||
* @return Pin number.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_gpiote_event_pin_get(uint32_t idx);
|
||||
|
||||
/**@brief Function for getting the polarity associated with a GPIOTE event.
|
||||
*
|
||||
* @param[in] idx Task-Event index.
|
||||
*
|
||||
* @return Polarity.
|
||||
*/
|
||||
__STATIC_INLINE nrf_gpiote_polarity_t nrf_gpiote_event_polarity_get(uint32_t idx);
|
||||
|
||||
/**@brief Function for enabling a GPIOTE task.
|
||||
*
|
||||
* @param[in] idx Task-Event index.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpiote_task_enable(uint32_t idx);
|
||||
|
||||
/**@brief Function for disabling a GPIOTE task.
|
||||
*
|
||||
* @param[in] idx Task-Event index.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpiote_task_disable(uint32_t idx);
|
||||
|
||||
/**@brief Function for configuring a GPIOTE task.
|
||||
* @note Function is not configuring mode field so task is disabled after this function is called.
|
||||
*
|
||||
* @param[in] idx Task-Event index.
|
||||
* @param[in] pin Pin associated with event.
|
||||
* @param[in] polarity Transition that should generate an event.
|
||||
* @param[in] init_val Initial value of the pin.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpiote_task_configure(uint32_t idx, uint32_t pin,
|
||||
nrf_gpiote_polarity_t polarity,
|
||||
nrf_gpiote_outinit_t init_val);
|
||||
|
||||
/**@brief Function for forcing a specific state on the pin connected to GPIOTE.
|
||||
*
|
||||
* @param[in] idx Task-Event index.
|
||||
* @param[in] init_val Pin state.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpiote_task_force(uint32_t idx, nrf_gpiote_outinit_t init_val);
|
||||
|
||||
/**@brief Function for resetting a GPIOTE task event configuration to the default state.
|
||||
*
|
||||
* @param[in] idx Task-Event index.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_gpiote_te_default(uint32_t idx);
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
__STATIC_INLINE void nrf_gpiote_task_set(nrf_gpiote_tasks_t task)
|
||||
{
|
||||
*(__IO uint32_t *)((uint32_t)NRF_GPIOTE + task) = 0x1UL;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_gpiote_task_addr_get(nrf_gpiote_tasks_t task)
|
||||
{
|
||||
return ((uint32_t)NRF_GPIOTE + task);
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_gpiote_event_is_set(nrf_gpiote_events_t event)
|
||||
{
|
||||
return (*(uint32_t *)nrf_gpiote_event_addr_get(event) == 0x1UL) ? true : false;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_gpiote_event_clear(nrf_gpiote_events_t event)
|
||||
{
|
||||
*(uint32_t *)nrf_gpiote_event_addr_get(event) = 0;
|
||||
#if __CORTEX_M == 0x04
|
||||
volatile uint32_t dummy = *((volatile uint32_t *)nrf_gpiote_event_addr_get(event));
|
||||
(void)dummy;
|
||||
#endif
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_gpiote_event_addr_get(nrf_gpiote_events_t event)
|
||||
{
|
||||
return ((uint32_t)NRF_GPIOTE + event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_gpiote_int_enable(uint32_t mask)
|
||||
{
|
||||
NRF_GPIOTE->INTENSET = mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_gpiote_int_disable(uint32_t mask)
|
||||
{
|
||||
NRF_GPIOTE->INTENCLR = mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_gpiote_int_is_enabled(uint32_t mask)
|
||||
{
|
||||
return (NRF_GPIOTE->INTENSET & mask);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_gpiote_event_enable(uint32_t idx)
|
||||
{
|
||||
NRF_GPIOTE->CONFIG[idx] |= GPIOTE_CONFIG_MODE_Event;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_gpiote_event_disable(uint32_t idx)
|
||||
{
|
||||
NRF_GPIOTE->CONFIG[idx] &= ~GPIOTE_CONFIG_MODE_Event;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_gpiote_event_configure(uint32_t idx, uint32_t pin, nrf_gpiote_polarity_t polarity)
|
||||
{
|
||||
NRF_GPIOTE->CONFIG[idx] &= ~(GPIOTE_CONFIG_PORT_PIN_Msk | GPIOTE_CONFIG_POLARITY_Msk);
|
||||
NRF_GPIOTE->CONFIG[idx] |= ((pin << GPIOTE_CONFIG_PSEL_Pos) & GPIOTE_CONFIG_PORT_PIN_Msk) |
|
||||
((polarity << GPIOTE_CONFIG_POLARITY_Pos) & GPIOTE_CONFIG_POLARITY_Msk);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_gpiote_event_pin_get(uint32_t idx)
|
||||
{
|
||||
return ((NRF_GPIOTE->CONFIG[idx] & GPIOTE_CONFIG_PORT_PIN_Msk) >> GPIOTE_CONFIG_PSEL_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE nrf_gpiote_polarity_t nrf_gpiote_event_polarity_get(uint32_t idx)
|
||||
{
|
||||
return (nrf_gpiote_polarity_t)((NRF_GPIOTE->CONFIG[idx] & GPIOTE_CONFIG_POLARITY_Msk) >> GPIOTE_CONFIG_POLARITY_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_gpiote_task_enable(uint32_t idx)
|
||||
{
|
||||
uint32_t final_config = NRF_GPIOTE->CONFIG[idx] | GPIOTE_CONFIG_MODE_Task;
|
||||
#ifdef NRF51
|
||||
/* Workaround for the OUTINIT PAN. When nrf_gpiote_task_config() is called a glitch happens
|
||||
on the GPIO if the GPIO in question is already assigned to GPIOTE and the pin is in the
|
||||
correct state in GPIOTE but not in the OUT register. */
|
||||
/* Configure channel to not existing, not connected to the pin, and configure as a tasks that will set it to proper level */
|
||||
NRF_GPIOTE->CONFIG[idx] = final_config | (((31) << GPIOTE_CONFIG_PSEL_Pos) & GPIOTE_CONFIG_PORT_PIN_Msk);
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
#endif
|
||||
NRF_GPIOTE->CONFIG[idx] = final_config;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_gpiote_task_disable(uint32_t idx)
|
||||
{
|
||||
NRF_GPIOTE->CONFIG[idx] &= ~GPIOTE_CONFIG_MODE_Task;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_gpiote_task_configure(uint32_t idx, uint32_t pin,
|
||||
nrf_gpiote_polarity_t polarity,
|
||||
nrf_gpiote_outinit_t init_val)
|
||||
{
|
||||
NRF_GPIOTE->CONFIG[idx] &= ~(GPIOTE_CONFIG_PORT_PIN_Msk |
|
||||
GPIOTE_CONFIG_POLARITY_Msk |
|
||||
GPIOTE_CONFIG_OUTINIT_Msk);
|
||||
|
||||
NRF_GPIOTE->CONFIG[idx] |= ((pin << GPIOTE_CONFIG_PSEL_Pos) & GPIOTE_CONFIG_PORT_PIN_Msk) |
|
||||
((polarity << GPIOTE_CONFIG_POLARITY_Pos) & GPIOTE_CONFIG_POLARITY_Msk) |
|
||||
((init_val << GPIOTE_CONFIG_OUTINIT_Pos) & GPIOTE_CONFIG_OUTINIT_Msk);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_gpiote_task_force(uint32_t idx, nrf_gpiote_outinit_t init_val)
|
||||
{
|
||||
NRF_GPIOTE->CONFIG[idx] = (NRF_GPIOTE->CONFIG[idx] & ~GPIOTE_CONFIG_OUTINIT_Msk)
|
||||
| ((init_val << GPIOTE_CONFIG_OUTINIT_Pos) & GPIOTE_CONFIG_OUTINIT_Msk);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_gpiote_te_default(uint32_t idx)
|
||||
{
|
||||
NRF_GPIOTE->CONFIG[idx] = 0;
|
||||
}
|
||||
#endif //SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,548 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 <nrfx.h>
|
||||
|
||||
#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 a 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
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
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.
|
||||
/*lint -restore*/
|
||||
} nrf_i2s_task_t;
|
||||
|
||||
/**
|
||||
* @brief I2S events.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
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.
|
||||
/*lint -restore*/
|
||||
} 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.
|
||||
// [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.
|
||||
NRF_I2S_MCK_32MDIV3 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV3, ///< 32 MHz / 3 = 10.6666667 MHz.
|
||||
NRF_I2S_MCK_32MDIV4 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV4, ///< 32 MHz / 4 = 8.0 MHz.
|
||||
NRF_I2S_MCK_32MDIV5 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV5, ///< 32 MHz / 5 = 6.4 MHz.
|
||||
NRF_I2S_MCK_32MDIV6 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV6, ///< 32 MHz / 6 = 5.3333333 MHz.
|
||||
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_32MDIV31 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV31, ///< 32 MHz / 31 = 1.0322581 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- 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 a specific I2S task.
|
||||
*
|
||||
* @param[in] p_i2s I2S instance.
|
||||
* @param[in] task Task to activate.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_i2s_task_trigger(NRF_I2S_Type * p_i2s,
|
||||
nrf_i2s_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific I2S task register.
|
||||
*
|
||||
* @param[in] p_i2s I2S instance.
|
||||
* @param[in] task Requested task.
|
||||
*
|
||||
* @return Address of the specified task register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_i2s_task_address_get(NRF_I2S_Type const * p_i2s,
|
||||
nrf_i2s_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a specific I2S event.
|
||||
*
|
||||
* @param[in] p_i2s I2S instance.
|
||||
* @param[in] event Event to clear.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_i2s_event_clear(NRF_I2S_Type * p_i2s,
|
||||
nrf_i2s_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the state of a specific I2S event.
|
||||
*
|
||||
* @param[in] p_i2s I2S instance.
|
||||
* @param[in] event Event to check.
|
||||
*
|
||||
* @retval true If the event is set.
|
||||
* @retval false If the event is not set.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_i2s_event_check(NRF_I2S_Type const * p_i2s,
|
||||
nrf_i2s_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific I2S event register.
|
||||
*
|
||||
* @param[in] p_i2s I2S instance.
|
||||
* @param[in] event Requested event.
|
||||
*
|
||||
* @return Address of the specified event register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_i2s_event_address_get(NRF_I2S_Type const * p_i2s,
|
||||
nrf_i2s_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling specified interrupts.
|
||||
*
|
||||
* @param[in] p_i2s I2S instance.
|
||||
* @param[in] mask Interrupts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_i2s_int_enable(NRF_I2S_Type * p_i2s, uint32_t mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling specified interrupts.
|
||||
*
|
||||
* @param[in] p_i2s I2S instance.
|
||||
* @param[in] mask Interrupts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_i2s_int_disable(NRF_I2S_Type * p_i2s, uint32_t mask);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of a given interrupt.
|
||||
*
|
||||
* @param[in] p_i2s I2S instance.
|
||||
* @param[in] i2s_int Interrupt to check.
|
||||
*
|
||||
* @retval true If the interrupt is enabled.
|
||||
* @retval false If the interrupt is not enabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_i2s_int_enable_check(NRF_I2S_Type const * p_i2s,
|
||||
nrf_i2s_int_mask_t i2s_int);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling the I2S peripheral.
|
||||
*
|
||||
* @param[in] p_i2s I2S instance.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_i2s_enable(NRF_I2S_Type * p_i2s);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling the I2S peripheral.
|
||||
*
|
||||
* @param[in] p_i2s I2S instance.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_i2s_disable(NRF_I2S_Type * p_i2s);
|
||||
|
||||
/**
|
||||
* @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_i2s I2S instance.
|
||||
* @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_i2s,
|
||||
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_i2s I2S instance.
|
||||
* @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 If the configuration has been set successfully.
|
||||
* @retval false If the requested configuration is not allowed.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_i2s_configure(NRF_I2S_Type * p_i2s,
|
||||
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 and/or
|
||||
* transmission accordingly. If the transfer in a given direction is not
|
||||
* required, pass NULL instead of the pointer to the corresponding buffer.
|
||||
*
|
||||
* @param[in] p_i2s I2S instance.
|
||||
* @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_i2s,
|
||||
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_i2s I2S instance.
|
||||
* @param[in] p_buffer Pointer to the receive buffer.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_i2s_rx_buffer_set(NRF_I2S_Type * p_i2s,
|
||||
uint32_t * p_buffer);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the pointer to the receive buffer.
|
||||
*
|
||||
* @param[in] p_i2s I2S instance.
|
||||
*
|
||||
* @return Pointer to the receive buffer.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_i2s_rx_buffer_get(NRF_I2S_Type const * p_i2s);
|
||||
|
||||
/**
|
||||
* @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_i2s I2S instance.
|
||||
* @param[in] p_buffer Pointer to the transmit buffer.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_i2s_tx_buffer_set(NRF_I2S_Type * p_i2s,
|
||||
uint32_t const * p_buffer);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the pointer to the transmit buffer.
|
||||
*
|
||||
* @param[in] p_i2s I2S instance.
|
||||
*
|
||||
* @return Pointer to the transmit buffer.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_i2s_tx_buffer_get(NRF_I2S_Type const * p_i2s);
|
||||
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
__STATIC_INLINE void nrf_i2s_task_trigger(NRF_I2S_Type * p_i2s,
|
||||
nrf_i2s_task_t task)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)p_i2s + (uint32_t)task)) = 0x1UL;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_i2s_task_address_get(NRF_I2S_Type const * p_i2s,
|
||||
nrf_i2s_task_t task)
|
||||
{
|
||||
return ((uint32_t)p_i2s + (uint32_t)task);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_i2s_event_clear(NRF_I2S_Type * p_i2s,
|
||||
nrf_i2s_event_t event)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)p_i2s + (uint32_t)event)) = 0x0UL;
|
||||
#if __CORTEX_M == 0x04
|
||||
volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)p_i2s + (uint32_t)event));
|
||||
(void)dummy;
|
||||
#endif
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_i2s_event_check(NRF_I2S_Type const * p_i2s,
|
||||
nrf_i2s_event_t event)
|
||||
{
|
||||
return (bool)*(volatile uint32_t *)((uint8_t *)p_i2s + (uint32_t)event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_i2s_event_address_get(NRF_I2S_Type const * p_i2s,
|
||||
nrf_i2s_event_t event)
|
||||
{
|
||||
return ((uint32_t)p_i2s + (uint32_t)event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_i2s_int_enable(NRF_I2S_Type * p_i2s, uint32_t mask)
|
||||
{
|
||||
p_i2s->INTENSET = mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_i2s_int_disable(NRF_I2S_Type * p_i2s, uint32_t mask)
|
||||
{
|
||||
p_i2s->INTENCLR = mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_i2s_int_enable_check(NRF_I2S_Type const * p_i2s,
|
||||
nrf_i2s_int_mask_t i2s_int)
|
||||
{
|
||||
return (bool)(p_i2s->INTENSET & i2s_int);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_i2s_enable(NRF_I2S_Type * p_i2s)
|
||||
{
|
||||
p_i2s->ENABLE = (I2S_ENABLE_ENABLE_Enabled << I2S_ENABLE_ENABLE_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_i2s_disable(NRF_I2S_Type * p_i2s)
|
||||
{
|
||||
p_i2s->ENABLE = (I2S_ENABLE_ENABLE_Disabled << I2S_ENABLE_ENABLE_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_i2s_pins_set(NRF_I2S_Type * p_i2s,
|
||||
uint32_t sck_pin,
|
||||
uint32_t lrck_pin,
|
||||
uint32_t mck_pin,
|
||||
uint32_t sdout_pin,
|
||||
uint32_t sdin_pin)
|
||||
{
|
||||
p_i2s->PSEL.SCK = sck_pin;
|
||||
p_i2s->PSEL.LRCK = lrck_pin;
|
||||
p_i2s->PSEL.MCK = mck_pin;
|
||||
p_i2s->PSEL.SDOUT = sdout_pin;
|
||||
p_i2s->PSEL.SDIN = sdin_pin;
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_i2s_configure(NRF_I2S_Type * p_i2s,
|
||||
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 shall 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_i2s->CONFIG.MODE = mode;
|
||||
p_i2s->CONFIG.FORMAT = format;
|
||||
p_i2s->CONFIG.ALIGN = alignment;
|
||||
p_i2s->CONFIG.SWIDTH = sample_width;
|
||||
p_i2s->CONFIG.CHANNELS = channels;
|
||||
p_i2s->CONFIG.RATIO = ratio;
|
||||
|
||||
if (mck_setup == NRF_I2S_MCK_DISABLED)
|
||||
{
|
||||
p_i2s->CONFIG.MCKEN =
|
||||
(I2S_CONFIG_MCKEN_MCKEN_Disabled << I2S_CONFIG_MCKEN_MCKEN_Pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
p_i2s->CONFIG.MCKFREQ = mck_setup;
|
||||
p_i2s->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_i2s,
|
||||
uint16_t size,
|
||||
uint32_t * p_buffer_rx,
|
||||
uint32_t const * p_buffer_tx)
|
||||
{
|
||||
p_i2s->RXTXD.MAXCNT = size;
|
||||
|
||||
nrf_i2s_rx_buffer_set(p_i2s, p_buffer_rx);
|
||||
p_i2s->CONFIG.RXEN = (p_buffer_rx != NULL) ? 1 : 0;
|
||||
|
||||
nrf_i2s_tx_buffer_set(p_i2s, p_buffer_tx);
|
||||
p_i2s->CONFIG.TXEN = (p_buffer_tx != NULL) ? 1 : 0;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_i2s_rx_buffer_set(NRF_I2S_Type * p_i2s,
|
||||
uint32_t * p_buffer)
|
||||
{
|
||||
p_i2s->RXD.PTR = (uint32_t)p_buffer;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_i2s_rx_buffer_get(NRF_I2S_Type const * p_i2s)
|
||||
{
|
||||
return (uint32_t *)(p_i2s->RXD.PTR);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_i2s_tx_buffer_set(NRF_I2S_Type * p_i2s,
|
||||
uint32_t const * p_buffer)
|
||||
{
|
||||
p_i2s->TXD.PTR = (uint32_t)p_buffer;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_i2s_tx_buffer_get(NRF_I2S_Type const * p_i2s)
|
||||
{
|
||||
return (uint32_t *)(p_i2s->TXD.PTR);
|
||||
}
|
||||
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_I2S_H__
|
||||
@@ -0,0 +1,403 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 <nrfx.h>
|
||||
|
||||
#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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @enum nrf_lpcomp_ref_t
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* @enum nrf_lpcomp_input_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;
|
||||
|
||||
/**
|
||||
* @enum nrf_lpcomp_detect_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;
|
||||
|
||||
/**
|
||||
* @enum nrf_lpcomp_task_t
|
||||
* @brief LPCOMP tasks.
|
||||
*/
|
||||
typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
|
||||
{
|
||||
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; /*lint -restore*/
|
||||
|
||||
|
||||
/**
|
||||
* @enum nrf_lpcomp_event_t
|
||||
* @brief LPCOMP events.
|
||||
*/
|
||||
typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
|
||||
{
|
||||
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; /*lint -restore*/
|
||||
|
||||
/**
|
||||
* @enum nrf_lpcomp_short_mask_t
|
||||
* @brief LPCOMP shorts masks.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_LPCOMP_SHORT_CROSS_STOP_MASK = LPCOMP_SHORTS_CROSS_STOP_Msk, /*!< Short between CROSS event and STOP task. */
|
||||
NRF_LPCOMP_SHORT_UP_STOP_MASK = LPCOMP_SHORTS_UP_STOP_Msk, /*!< Short between UP event and STOP task. */
|
||||
NRF_LPCOMP_SHORT_DOWN_STOP_MASK = LPCOMP_SHORTS_DOWN_STOP_Msk, /*!< Short between DOWN event and STOP task. */
|
||||
NRF_LPCOMP_SHORT_READY_STOP_MASK = LPCOMP_SHORTS_READY_STOP_Msk, /*!< Short between READY event and STOP task. */
|
||||
NRF_LPCOMP_SHORT_READY_SAMPLE_MASK = LPCOMP_SHORTS_READY_SAMPLE_Msk /*!< Short between READY event and SAMPLE task. */
|
||||
} nrf_lpcomp_short_mask_t;
|
||||
|
||||
#ifdef LPCOMP_FEATURE_HYST_PRESENT
|
||||
/**
|
||||
* @enum nrf_lpcomp_hysteresis_t
|
||||
* @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 (typ. 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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for enabling the Low Power Comparator.
|
||||
*
|
||||
* This function enables LPCOMP.
|
||||
*
|
||||
*/
|
||||
__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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for disabling the Low Power Comparator.
|
||||
*
|
||||
* This function disables LPCOMP.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_lpcomp_disable(void)
|
||||
{
|
||||
NRF_LPCOMP->ENABLE = LPCOMP_ENABLE_ENABLE_Disabled << LPCOMP_ENABLE_ENABLE_Pos;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
return (uint32_t)NRF_LPCOMP->RESULT;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for enabling interrupts from LPCOMP.
|
||||
*
|
||||
* @param[in] lpcomp_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 lpcomp_int_mask)
|
||||
{
|
||||
NRF_LPCOMP->INTENSET = lpcomp_int_mask;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for disabling interrupts from LPCOMP.
|
||||
*
|
||||
* @param[in] lpcomp_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 lpcomp_int_mask)
|
||||
{
|
||||
NRF_LPCOMP->INTENCLR = lpcomp_int_mask;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting the enabled interrupts of LPCOMP.
|
||||
*
|
||||
* @param[in] lpcomp_int_mask Mask of interrupts to be checked.
|
||||
*
|
||||
* @retval true If any of interrupts of the specified mask are enabled.
|
||||
*
|
||||
* @sa nrf_lpcomp_int_enable()
|
||||
* @sa nrf_lpcomp_int_disable()
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_lpcomp_int_enable_check(uint32_t lpcomp_int_mask)
|
||||
{
|
||||
return (NRF_LPCOMP->INTENSET & lpcomp_int_mask); // when read this register will return the value of INTEN.
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific LPCOMP task register.
|
||||
*
|
||||
* @param[in] lpcomp_task LPCOMP task.
|
||||
*
|
||||
* @return The address of the specified LPCOMP task.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_lpcomp_task_address_get(nrf_lpcomp_task_t lpcomp_task)
|
||||
{
|
||||
return (uint32_t *)((uint8_t *)NRF_LPCOMP + lpcomp_task);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific LPCOMP event register.
|
||||
*
|
||||
* @param[in] lpcomp_event LPCOMP event.
|
||||
*
|
||||
* @return The address of the specified LPCOMP event.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_lpcomp_event_address_get(nrf_lpcomp_event_t lpcomp_event)
|
||||
{
|
||||
return (uint32_t *)((uint8_t *)NRF_LPCOMP + lpcomp_event);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for setting LPCOMP shorts.
|
||||
*
|
||||
* @param[in] lpcomp_short_mask LPCOMP shorts by mask.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_lpcomp_shorts_enable(uint32_t lpcomp_short_mask)
|
||||
{
|
||||
NRF_LPCOMP->SHORTS |= lpcomp_short_mask;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for clearing LPCOMP shorts by mask.
|
||||
*
|
||||
* @param[in] lpcomp_short_mask LPCOMP shorts to be cleared.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_lpcomp_shorts_disable(uint32_t lpcomp_short_mask)
|
||||
{
|
||||
NRF_LPCOMP->SHORTS &= ~lpcomp_short_mask;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for setting a specific LPCOMP task.
|
||||
*
|
||||
* @param[in] lpcomp_task LPCOMP task to be set.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_lpcomp_task_trigger(nrf_lpcomp_task_t lpcomp_task)
|
||||
{
|
||||
*( (volatile uint32_t *)( (uint8_t *)NRF_LPCOMP + lpcomp_task) ) = 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a specific LPCOMP event.
|
||||
*
|
||||
* @param[in] lpcomp_event LPCOMP event to be cleared.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_lpcomp_event_clear(nrf_lpcomp_event_t lpcomp_event)
|
||||
{
|
||||
*( (volatile uint32_t *)( (uint8_t *)NRF_LPCOMP + lpcomp_event) ) = 0;
|
||||
#if __CORTEX_M == 0x04
|
||||
volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_LPCOMP + lpcomp_event));
|
||||
(void)dummy;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting the state of a specific LPCOMP event.
|
||||
*
|
||||
* @retval true If the specified LPCOMP event is active.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_lpcomp_event_check(nrf_lpcomp_event_t lpcomp_event)
|
||||
{
|
||||
return (bool) (*(volatile uint32_t *)( (uint8_t *)NRF_LPCOMP + lpcomp_event));
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRF_LPCOMP_H_ */
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (c) 2012 - 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
|
||||
*/
|
||||
/**
|
||||
*@file
|
||||
*@brief NMVC driver implementation
|
||||
*/
|
||||
|
||||
#include <nrfx.h>
|
||||
#include "nrf_nvmc.h"
|
||||
|
||||
static inline void wait_for_flash_ready(void)
|
||||
{
|
||||
while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {;}
|
||||
}
|
||||
|
||||
void nrf_nvmc_page_erase(uint32_t address)
|
||||
{
|
||||
// Enable erase.
|
||||
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Een;
|
||||
__ISB();
|
||||
__DSB();
|
||||
|
||||
// Erase the page
|
||||
NRF_NVMC->ERASEPAGE = address;
|
||||
wait_for_flash_ready();
|
||||
|
||||
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
|
||||
__ISB();
|
||||
__DSB();
|
||||
}
|
||||
|
||||
|
||||
void nrf_nvmc_write_byte(uint32_t address, uint8_t value)
|
||||
{
|
||||
uint32_t byte_shift = address & (uint32_t)0x03;
|
||||
uint32_t address32 = address & ~byte_shift; // Address to the word this byte is in.
|
||||
uint32_t value32 = (*(uint32_t*)address32 & ~((uint32_t)0xFF << (byte_shift << (uint32_t)3)));
|
||||
value32 = value32 + ((uint32_t)value << (byte_shift << 3));
|
||||
|
||||
// Enable write.
|
||||
NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos);
|
||||
__ISB();
|
||||
__DSB();
|
||||
|
||||
*(uint32_t*)address32 = value32;
|
||||
wait_for_flash_ready();
|
||||
|
||||
NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);
|
||||
__ISB();
|
||||
__DSB();
|
||||
}
|
||||
|
||||
void nrf_nvmc_write_word(uint32_t address, uint32_t value)
|
||||
{
|
||||
// Enable write.
|
||||
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen;
|
||||
__ISB();
|
||||
__DSB();
|
||||
|
||||
*(uint32_t*)address = value;
|
||||
wait_for_flash_ready();
|
||||
|
||||
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
|
||||
__ISB();
|
||||
__DSB();
|
||||
}
|
||||
|
||||
void nrf_nvmc_write_bytes(uint32_t address, const uint8_t * src, uint32_t num_bytes)
|
||||
{
|
||||
uint32_t i;
|
||||
for (i = 0; i < num_bytes; i++)
|
||||
{
|
||||
nrf_nvmc_write_byte(address + i,src[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void nrf_nvmc_write_words(uint32_t address, const uint32_t * src, uint32_t num_words)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
// Enable write.
|
||||
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen;
|
||||
__ISB();
|
||||
__DSB();
|
||||
|
||||
for (i = 0; i < num_words; i++)
|
||||
{
|
||||
((uint32_t*)address)[i] = src[i];
|
||||
wait_for_flash_ready();
|
||||
}
|
||||
|
||||
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
|
||||
__ISB();
|
||||
__DSB();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (c) 2012 - 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_NVMC_H__
|
||||
#define NRF_NVMC_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup nrf_nvmc_hal NVMC HAL
|
||||
* @{
|
||||
* @ingroup nrf_nvmc
|
||||
* @brief Hardware access layer for managing the Non-Volatile Memory Controller (NVMC) peripheral.
|
||||
*
|
||||
* This driver allows writing to the non-volatile memory (NVM) regions
|
||||
* of the chip. In order to write to NVM the controller must be powered
|
||||
* on and the relevant page must be erased.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Erase a page in flash. This is required before writing to any
|
||||
* address in the page.
|
||||
*
|
||||
* @param address Start address of the page.
|
||||
*/
|
||||
void nrf_nvmc_page_erase(uint32_t address);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Write a single byte to flash.
|
||||
*
|
||||
* The function reads the word containing the byte, and then
|
||||
* rewrites the entire word.
|
||||
*
|
||||
* @param address Address to write to.
|
||||
* @param value Value to write.
|
||||
*/
|
||||
void nrf_nvmc_write_byte(uint32_t address , uint8_t value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Write a 32-bit word to flash.
|
||||
* @param address Address to write to.
|
||||
* @param value Value to write.
|
||||
*/
|
||||
void nrf_nvmc_write_word(uint32_t address, uint32_t value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Write consecutive bytes to flash.
|
||||
*
|
||||
* @param address Address to write to.
|
||||
* @param src Pointer to data to copy from.
|
||||
* @param num_bytes Number of bytes in src to write.
|
||||
*/
|
||||
void nrf_nvmc_write_bytes(uint32_t address, const uint8_t * src, uint32_t num_bytes);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Write consecutive words to flash.
|
||||
*
|
||||
* @param address Address to write to.
|
||||
* @param src Pointer to data to copy from.
|
||||
* @param num_words Number of words in src to write.
|
||||
*/
|
||||
void nrf_nvmc_write_words(uint32_t address, const uint32_t * src, uint32_t num_words);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_NVMC_H__
|
||||
@@ -0,0 +1,378 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 <nrfx.h>
|
||||
|
||||
#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.
|
||||
*/
|
||||
|
||||
#define NRF_PDM_GAIN_MINIMUM 0x00
|
||||
#define NRF_PDM_GAIN_DEFAULT 0x28
|
||||
#define NRF_PDM_GAIN_MAXIMUM 0x50
|
||||
|
||||
typedef uint8_t nrf_pdm_gain_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief PDM tasks.
|
||||
*/
|
||||
typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
|
||||
{
|
||||
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 /*lint -save -e30 -esym(628,__INTADDR__) */
|
||||
{
|
||||
NRF_PDM_EVENT_STARTED = offsetof(NRF_PDM_Type, EVENTS_STARTED), ///< PDM transfer has started.
|
||||
NRF_PDM_EVENT_STOPPED = offsetof(NRF_PDM_Type, EVENTS_STOPPED), ///< PDM transfer has 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] pdm_task PDM task.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pdm_task_trigger(nrf_pdm_task_t pdm_task)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)pdm_task)) = 0x1UL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a PDM task register.
|
||||
*
|
||||
* @param[in] pdm_task PDM task.
|
||||
*
|
||||
* @return Address of the specified PDM task.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_pdm_task_address_get(nrf_pdm_task_t pdm_task)
|
||||
{
|
||||
return (uint32_t)((uint8_t *)NRF_PDM + (uint32_t)pdm_task);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting the state of a PDM event.
|
||||
*
|
||||
* @param[in] pdm_event PDM event.
|
||||
*
|
||||
* @return State of the specified PDM event.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_pdm_event_check(nrf_pdm_event_t pdm_event)
|
||||
{
|
||||
return (bool)*(volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)pdm_event);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a PDM event.
|
||||
*
|
||||
* @param[in] pdm_event PDM event.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pdm_event_clear(nrf_pdm_event_t pdm_event)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)pdm_event)) = 0x0UL;
|
||||
#if __CORTEX_M == 0x04
|
||||
volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)pdm_event));
|
||||
(void)dummy;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a PDM event register.
|
||||
*
|
||||
* @param[in] pdm_event PDM event.
|
||||
*
|
||||
* @return Address of the specified PDM event.
|
||||
*/
|
||||
__STATIC_INLINE volatile uint32_t * nrf_pdm_event_address_get(nrf_pdm_event_t pdm_event)
|
||||
{
|
||||
return (volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)pdm_event);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for enabling PDM interrupts.
|
||||
*
|
||||
* @param[in] pdm_int_mask Interrupts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pdm_int_enable(uint32_t pdm_int_mask)
|
||||
{
|
||||
NRF_PDM->INTENSET = pdm_int_mask;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of PDM interrupts.
|
||||
*
|
||||
* @param[in] pdm_int_mask Interrupts to check.
|
||||
*
|
||||
* @retval true If all specified interrupts are enabled.
|
||||
* @retval false If at least one of the given interrupts is not enabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_pdm_int_enable_check(uint32_t pdm_int_mask)
|
||||
{
|
||||
return (bool)(NRF_PDM->INTENSET & pdm_int_mask);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for disabling interrupts.
|
||||
*
|
||||
* @param pdm_int_mask Interrupts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pdm_int_disable(uint32_t pdm_int_mask)
|
||||
{
|
||||
NRF_PDM->INTENCLR = pdm_int_mask;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for enabling the PDM peripheral.
|
||||
*
|
||||
* The PDM peripheral must be enabled before use.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pdm_enable(void)
|
||||
{
|
||||
NRF_PDM->ENABLE = (PDM_ENABLE_ENABLE_Enabled << PDM_ENABLE_ENABLE_Pos);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for disabling the PDM peripheral.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pdm_disable(void)
|
||||
{
|
||||
NRF_PDM->ENABLE = (PDM_ENABLE_ENABLE_Disabled << PDM_ENABLE_ENABLE_Pos);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for checking if the PDM peripheral is enabled.
|
||||
*
|
||||
* @retval true If the PDM peripheral is enabled.
|
||||
* @retval false If the PDM peripheral is not enabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_pdm_enable_check(void)
|
||||
{
|
||||
return (NRF_PDM->ENABLE == (PDM_ENABLE_ENABLE_Enabled << PDM_ENABLE_ENABLE_Pos));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
NRF_PDM->MODE = ((pdm_mode << PDM_MODE_OPERATION_Pos) & PDM_MODE_OPERATION_Msk)
|
||||
| ((pdm_edge << PDM_MODE_EDGE_Pos) & PDM_MODE_EDGE_Msk);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
NRF_PDM->PDMCLKCTRL = ((pdm_freq << PDM_PDMCLKCTRL_FREQ_Pos) & PDM_PDMCLKCTRL_FREQ_Msk);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting the PDM clock frequency.
|
||||
*/
|
||||
__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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
NRF_PDM->PSEL.CLK = psel_clk;
|
||||
NRF_PDM->PSEL.DIN = psel_din;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function for disconnecting the PDM pins.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pdm_psel_disconnect()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
NRF_PDM->GAINL = gain_l;
|
||||
NRF_PDM->GAINR = 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)
|
||||
{
|
||||
*p_gain_l = NRF_PDM->GAINL;
|
||||
*p_gain_r = NRF_PDM->GAINR;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for setting the PDM sample buffer.
|
||||
*
|
||||
* @param[in] p_buffer Pointer to the RAM address where samples should be written with EasyDMA.
|
||||
* @param[in] num Number of samples to allocate memory for in EasyDMA mode.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
__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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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()
|
||||
{
|
||||
return (uint32_t *)NRF_PDM->SAMPLE.PTR;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRF_PDM_H_ */
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,484 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_PPI_H__
|
||||
#define NRF_PPI_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_ppi_hal PPI HAL
|
||||
* @{
|
||||
* @ingroup nrf_ppi
|
||||
* @brief Hardware access layer for managing the Programmable Peripheral Interconnect (PPI)
|
||||
* channels.
|
||||
*/
|
||||
|
||||
#define NRF_PPI_TASK_SET (1UL)
|
||||
|
||||
/**
|
||||
* @enum nrf_ppi_channel_t
|
||||
* @brief PPI channels.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_PPI_CHANNEL0 = PPI_CHEN_CH0_Pos, /**< Channel 0. */
|
||||
NRF_PPI_CHANNEL1 = PPI_CHEN_CH1_Pos, /**< Channel 1. */
|
||||
NRF_PPI_CHANNEL2 = PPI_CHEN_CH2_Pos, /**< Channel 2. */
|
||||
NRF_PPI_CHANNEL3 = PPI_CHEN_CH3_Pos, /**< Channel 3. */
|
||||
NRF_PPI_CHANNEL4 = PPI_CHEN_CH4_Pos, /**< Channel 4. */
|
||||
NRF_PPI_CHANNEL5 = PPI_CHEN_CH5_Pos, /**< Channel 5. */
|
||||
NRF_PPI_CHANNEL6 = PPI_CHEN_CH6_Pos, /**< Channel 6. */
|
||||
NRF_PPI_CHANNEL7 = PPI_CHEN_CH7_Pos, /**< Channel 7. */
|
||||
NRF_PPI_CHANNEL8 = PPI_CHEN_CH8_Pos, /**< Channel 8. */
|
||||
NRF_PPI_CHANNEL9 = PPI_CHEN_CH9_Pos, /**< Channel 9. */
|
||||
NRF_PPI_CHANNEL10 = PPI_CHEN_CH10_Pos, /**< Channel 10. */
|
||||
NRF_PPI_CHANNEL11 = PPI_CHEN_CH11_Pos, /**< Channel 11. */
|
||||
NRF_PPI_CHANNEL12 = PPI_CHEN_CH12_Pos, /**< Channel 12. */
|
||||
NRF_PPI_CHANNEL13 = PPI_CHEN_CH13_Pos, /**< Channel 13. */
|
||||
NRF_PPI_CHANNEL14 = PPI_CHEN_CH14_Pos, /**< Channel 14. */
|
||||
NRF_PPI_CHANNEL15 = PPI_CHEN_CH15_Pos, /**< Channel 15. */
|
||||
#if (PPI_CH_NUM > 16) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_PPI_CHANNEL16 = PPI_CHEN_CH16_Pos, /**< Channel 16. */
|
||||
NRF_PPI_CHANNEL17 = PPI_CHEN_CH17_Pos, /**< Channel 17. */
|
||||
NRF_PPI_CHANNEL18 = PPI_CHEN_CH18_Pos, /**< Channel 18. */
|
||||
NRF_PPI_CHANNEL19 = PPI_CHEN_CH19_Pos, /**< Channel 19. */
|
||||
#endif
|
||||
NRF_PPI_CHANNEL20 = PPI_CHEN_CH20_Pos, /**< Channel 20. */
|
||||
NRF_PPI_CHANNEL21 = PPI_CHEN_CH21_Pos, /**< Channel 21. */
|
||||
NRF_PPI_CHANNEL22 = PPI_CHEN_CH22_Pos, /**< Channel 22. */
|
||||
NRF_PPI_CHANNEL23 = PPI_CHEN_CH23_Pos, /**< Channel 23. */
|
||||
NRF_PPI_CHANNEL24 = PPI_CHEN_CH24_Pos, /**< Channel 24. */
|
||||
NRF_PPI_CHANNEL25 = PPI_CHEN_CH25_Pos, /**< Channel 25. */
|
||||
NRF_PPI_CHANNEL26 = PPI_CHEN_CH26_Pos, /**< Channel 26. */
|
||||
NRF_PPI_CHANNEL27 = PPI_CHEN_CH27_Pos, /**< Channel 27. */
|
||||
NRF_PPI_CHANNEL28 = PPI_CHEN_CH28_Pos, /**< Channel 28. */
|
||||
NRF_PPI_CHANNEL29 = PPI_CHEN_CH29_Pos, /**< Channel 29. */
|
||||
NRF_PPI_CHANNEL30 = PPI_CHEN_CH30_Pos, /**< Channel 30. */
|
||||
NRF_PPI_CHANNEL31 = PPI_CHEN_CH31_Pos /**< Channel 31. */
|
||||
} nrf_ppi_channel_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_ppi_channel_group_t
|
||||
* @brief PPI channel groups.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_PPI_CHANNEL_GROUP0 = 0, /**< Channel group 0. */
|
||||
NRF_PPI_CHANNEL_GROUP1 = 1, /**< Channel group 1. */
|
||||
NRF_PPI_CHANNEL_GROUP2 = 2, /**< Channel group 2. */
|
||||
NRF_PPI_CHANNEL_GROUP3 = 3, /**< Channel group 3. */
|
||||
#if (PPI_GROUP_NUM > 4) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_PPI_CHANNEL_GROUP4 = 4, /**< Channel group 4. */
|
||||
NRF_PPI_CHANNEL_GROUP5 = 5 /**< Channel group 5. */
|
||||
#endif
|
||||
} nrf_ppi_channel_group_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_ppi_channel_include_t
|
||||
* @brief Definition of which PPI channels belong to a group.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_PPI_CHANNEL_EXCLUDE = PPI_CHG_CH0_Excluded, /**< Channel excluded from a group. */
|
||||
NRF_PPI_CHANNEL_INCLUDE = PPI_CHG_CH0_Included /**< Channel included in a group. */
|
||||
} nrf_ppi_channel_include_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_ppi_channel_enable_t
|
||||
* @brief Definition if a PPI channel is enabled.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_PPI_CHANNEL_DISABLED = PPI_CHEN_CH0_Disabled, /**< Channel disabled. */
|
||||
NRF_PPI_CHANNEL_ENABLED = PPI_CHEN_CH0_Enabled /**< Channel enabled. */
|
||||
} nrf_ppi_channel_enable_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_ppi_task_t
|
||||
* @brief PPI tasks.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30 -esym(628,__INTADDR__)*/
|
||||
NRF_PPI_TASK_CHG0_EN = offsetof(NRF_PPI_Type, TASKS_CHG[0].EN), /**< Task for enabling channel group 0 */
|
||||
NRF_PPI_TASK_CHG0_DIS = offsetof(NRF_PPI_Type, TASKS_CHG[0].DIS), /**< Task for disabling channel group 0 */
|
||||
NRF_PPI_TASK_CHG1_EN = offsetof(NRF_PPI_Type, TASKS_CHG[1].EN), /**< Task for enabling channel group 1 */
|
||||
NRF_PPI_TASK_CHG1_DIS = offsetof(NRF_PPI_Type, TASKS_CHG[1].DIS), /**< Task for disabling channel group 1 */
|
||||
NRF_PPI_TASK_CHG2_EN = offsetof(NRF_PPI_Type, TASKS_CHG[2].EN), /**< Task for enabling channel group 2 */
|
||||
NRF_PPI_TASK_CHG2_DIS = offsetof(NRF_PPI_Type, TASKS_CHG[2].DIS), /**< Task for disabling channel group 2 */
|
||||
NRF_PPI_TASK_CHG3_EN = offsetof(NRF_PPI_Type, TASKS_CHG[3].EN), /**< Task for enabling channel group 3 */
|
||||
NRF_PPI_TASK_CHG3_DIS = offsetof(NRF_PPI_Type, TASKS_CHG[3].DIS), /**< Task for disabling channel group 3 */
|
||||
#if (PPI_GROUP_NUM > 4) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_PPI_TASK_CHG4_EN = offsetof(NRF_PPI_Type, TASKS_CHG[4].EN), /**< Task for enabling channel group 4 */
|
||||
NRF_PPI_TASK_CHG4_DIS = offsetof(NRF_PPI_Type, TASKS_CHG[4].DIS), /**< Task for disabling channel group 4 */
|
||||
NRF_PPI_TASK_CHG5_EN = offsetof(NRF_PPI_Type, TASKS_CHG[5].EN), /**< Task for enabling channel group 5 */
|
||||
NRF_PPI_TASK_CHG5_DIS = offsetof(NRF_PPI_Type, TASKS_CHG[5].DIS) /**< Task for disabling channel group 5 */
|
||||
#endif
|
||||
/*lint -restore*/
|
||||
} nrf_ppi_task_t;
|
||||
|
||||
/**
|
||||
* @brief Function for enabling a given PPI channel.
|
||||
*
|
||||
* @details This function enables only one channel.
|
||||
*
|
||||
* @param[in] channel Channel to enable.
|
||||
*
|
||||
* */
|
||||
__STATIC_INLINE void nrf_ppi_channel_enable(nrf_ppi_channel_t channel);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling a given PPI channel.
|
||||
*
|
||||
* @details This function disables only one channel.
|
||||
*
|
||||
* @param[in] channel Channel to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ppi_channel_disable(nrf_ppi_channel_t channel);
|
||||
|
||||
/**
|
||||
* @brief Function for checking if a given PPI channel is enabled.
|
||||
*
|
||||
* @details This function checks only one channel.
|
||||
*
|
||||
* @param[in] channel Channel to check.
|
||||
*
|
||||
* @retval NRF_PPI_CHANNEL_ENABLED If the channel is enabled.
|
||||
* @retval NRF_PPI_CHANNEL_DISABLED If the channel is not enabled.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE nrf_ppi_channel_enable_t nrf_ppi_channel_enable_get(nrf_ppi_channel_t channel);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling all PPI channels.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ppi_channel_disable_all(void);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling multiple PPI channels.
|
||||
*
|
||||
* @param[in] mask Channel mask.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ppi_channels_enable(uint32_t mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling multiple PPI channels.
|
||||
*
|
||||
* @param[in] mask Channel mask.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ppi_channels_disable(uint32_t mask);
|
||||
|
||||
/**
|
||||
* @brief Function for setting up event and task endpoints for a given PPI channel.
|
||||
*
|
||||
* @param[in] eep Event register address.
|
||||
*
|
||||
* @param[in] tep Task register address.
|
||||
*
|
||||
* @param[in] channel Channel to which the given endpoints are assigned.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ppi_channel_endpoint_setup(nrf_ppi_channel_t channel,
|
||||
uint32_t eep,
|
||||
uint32_t tep);
|
||||
|
||||
#if defined(PPI_FEATURE_FORKS_PRESENT) || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Function for setting up task endpoint for a given PPI fork.
|
||||
*
|
||||
* @param[in] fork_tep Task register address.
|
||||
*
|
||||
* @param[in] channel Channel to which the given fork endpoint is assigned.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ppi_fork_endpoint_setup(nrf_ppi_channel_t channel,
|
||||
uint32_t fork_tep);
|
||||
|
||||
/**
|
||||
* @brief Function for setting up event and task endpoints for a given PPI channel and fork.
|
||||
*
|
||||
* @param[in] eep Event register address.
|
||||
*
|
||||
* @param[in] tep Task register address.
|
||||
*
|
||||
* @param[in] fork_tep Fork task register address (register value).
|
||||
*
|
||||
* @param[in] channel Channel to which the given endpoints are assigned.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ppi_channel_and_fork_endpoint_setup(nrf_ppi_channel_t channel,
|
||||
uint32_t eep,
|
||||
uint32_t tep,
|
||||
uint32_t fork_tep);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Function for including a PPI channel in a channel group.
|
||||
*
|
||||
* @details This function adds only one channel to the group.
|
||||
*
|
||||
* @param[in] channel Channel to be included in the group.
|
||||
*
|
||||
* @param[in] channel_group Channel group.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ppi_channel_include_in_group(nrf_ppi_channel_t channel,
|
||||
nrf_ppi_channel_group_t channel_group);
|
||||
|
||||
/**
|
||||
* @brief Function for including multiple PPI channels in a channel group.
|
||||
*
|
||||
* @details This function adds all specified channels to the group.
|
||||
*
|
||||
* @param[in] channel_mask Channels to be included in the group.
|
||||
*
|
||||
* @param[in] channel_group Channel group.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ppi_channels_include_in_group(uint32_t channel_mask,
|
||||
nrf_ppi_channel_group_t channel_group);
|
||||
|
||||
/**
|
||||
* @brief Function for removing a PPI channel from a channel group.
|
||||
*
|
||||
* @details This function removes only one channel from the group.
|
||||
*
|
||||
* @param[in] channel Channel to be removed from the group.
|
||||
*
|
||||
* @param[in] channel_group Channel group.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ppi_channel_remove_from_group(nrf_ppi_channel_t channel,
|
||||
nrf_ppi_channel_group_t channel_group);
|
||||
|
||||
/**
|
||||
* @brief Function for removing multiple PPI channels from a channel group.
|
||||
*
|
||||
* @details This function removes all specified channels from the group.
|
||||
*
|
||||
* @param[in] channel_mask Channels to be removed from the group.
|
||||
*
|
||||
* @param[in] channel_group Channel group.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ppi_channels_remove_from_group(uint32_t channel_mask,
|
||||
nrf_ppi_channel_group_t channel_group);
|
||||
|
||||
/**
|
||||
* @brief Function for removing all PPI channels from a channel group.
|
||||
*
|
||||
* @param[in] group Channel group.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ppi_channel_group_clear(nrf_ppi_channel_group_t group);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling a channel group.
|
||||
*
|
||||
* @param[in] group Channel group.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ppi_group_enable(nrf_ppi_channel_group_t group);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling a channel group.
|
||||
*
|
||||
* @param[in] group Channel group.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ppi_group_disable(nrf_ppi_channel_group_t group);
|
||||
|
||||
/**
|
||||
* @brief Function for setting a PPI task.
|
||||
*
|
||||
* @param[in] ppi_task PPI task to set.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_ppi_task_trigger(nrf_ppi_task_t ppi_task);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a specific PPI task register.
|
||||
*
|
||||
* @param[in] ppi_task PPI task.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_ppi_task_address_get(nrf_ppi_task_t ppi_task);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the PPI enable task address of a specific group.
|
||||
*
|
||||
* @param[in] group PPI group.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_ppi_task_group_enable_address_get(nrf_ppi_channel_group_t group);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the PPI disable task address of a specific group.
|
||||
*
|
||||
* @param[in] group PPI group.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_ppi_task_group_disable_address_get(nrf_ppi_channel_group_t group);
|
||||
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
__STATIC_INLINE void nrf_ppi_channel_enable(nrf_ppi_channel_t channel)
|
||||
{
|
||||
NRF_PPI->CHENSET = PPI_CHENSET_CH0_Set << ((uint32_t) channel);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ppi_channel_disable(nrf_ppi_channel_t channel)
|
||||
{
|
||||
NRF_PPI->CHENCLR = PPI_CHENCLR_CH0_Clear << ((uint32_t) channel);
|
||||
}
|
||||
|
||||
__STATIC_INLINE nrf_ppi_channel_enable_t nrf_ppi_channel_enable_get(nrf_ppi_channel_t channel)
|
||||
{
|
||||
if (NRF_PPI->CHEN & (PPI_CHEN_CH0_Msk << ((uint32_t) channel)))
|
||||
{
|
||||
return NRF_PPI_CHANNEL_ENABLED;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NRF_PPI_CHANNEL_DISABLED;
|
||||
}
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ppi_channel_disable_all(void)
|
||||
{
|
||||
NRF_PPI->CHENCLR = ((uint32_t)0xFFFFFFFFuL);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ppi_channels_enable(uint32_t mask)
|
||||
{
|
||||
NRF_PPI->CHENSET = mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ppi_channels_disable(uint32_t mask)
|
||||
{
|
||||
NRF_PPI->CHENCLR = mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ppi_channel_endpoint_setup(nrf_ppi_channel_t channel,
|
||||
uint32_t eep,
|
||||
uint32_t tep)
|
||||
{
|
||||
NRF_PPI->CH[(uint32_t) channel].EEP = eep;
|
||||
NRF_PPI->CH[(uint32_t) channel].TEP = tep;
|
||||
}
|
||||
|
||||
#if defined(PPI_FEATURE_FORKS_PRESENT)
|
||||
|
||||
__STATIC_INLINE void nrf_ppi_fork_endpoint_setup(nrf_ppi_channel_t channel,
|
||||
uint32_t fork_tep)
|
||||
{
|
||||
NRF_PPI->FORK[(uint32_t) channel].TEP = fork_tep;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ppi_channel_and_fork_endpoint_setup(nrf_ppi_channel_t channel,
|
||||
uint32_t eep,
|
||||
uint32_t tep,
|
||||
uint32_t fork_tep)
|
||||
{
|
||||
nrf_ppi_channel_endpoint_setup(channel, eep, tep);
|
||||
nrf_ppi_fork_endpoint_setup(channel, fork_tep);
|
||||
}
|
||||
#endif
|
||||
|
||||
__STATIC_INLINE void nrf_ppi_channel_include_in_group(nrf_ppi_channel_t channel,
|
||||
nrf_ppi_channel_group_t channel_group)
|
||||
{
|
||||
NRF_PPI->CHG[(uint32_t) channel_group] =
|
||||
NRF_PPI->CHG[(uint32_t) channel_group] | (PPI_CHG_CH0_Included << ((uint32_t) channel));
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ppi_channels_include_in_group(uint32_t channel_mask,
|
||||
nrf_ppi_channel_group_t channel_group)
|
||||
{
|
||||
NRF_PPI->CHG[(uint32_t) channel_group] =
|
||||
NRF_PPI->CHG[(uint32_t) channel_group] | (channel_mask);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ppi_channel_remove_from_group(nrf_ppi_channel_t channel,
|
||||
nrf_ppi_channel_group_t channel_group)
|
||||
{
|
||||
NRF_PPI->CHG[(uint32_t) channel_group] =
|
||||
NRF_PPI->CHG[(uint32_t) channel_group] & ~(PPI_CHG_CH0_Included << ((uint32_t) channel));
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ppi_channels_remove_from_group(uint32_t channel_mask,
|
||||
nrf_ppi_channel_group_t channel_group)
|
||||
{
|
||||
NRF_PPI->CHG[(uint32_t) channel_group] =
|
||||
NRF_PPI->CHG[(uint32_t) channel_group] & ~(channel_mask);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ppi_channel_group_clear(nrf_ppi_channel_group_t group)
|
||||
{
|
||||
NRF_PPI->CHG[(uint32_t) group] = 0;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ppi_group_enable(nrf_ppi_channel_group_t group)
|
||||
{
|
||||
NRF_PPI->TASKS_CHG[(uint32_t) group].EN = NRF_PPI_TASK_SET;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ppi_group_disable(nrf_ppi_channel_group_t group)
|
||||
{
|
||||
NRF_PPI->TASKS_CHG[(uint32_t) group].DIS = NRF_PPI_TASK_SET;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_ppi_task_trigger(nrf_ppi_task_t ppi_task)
|
||||
{
|
||||
*((volatile uint32_t *) ((uint8_t *) NRF_PPI_BASE + (uint32_t) ppi_task)) = NRF_PPI_TASK_SET;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_ppi_task_address_get(nrf_ppi_task_t ppi_task)
|
||||
{
|
||||
return (uint32_t *) ((uint8_t *) NRF_PPI_BASE + (uint32_t) ppi_task);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_ppi_task_group_enable_address_get(nrf_ppi_channel_group_t group)
|
||||
{
|
||||
return (uint32_t *) &NRF_PPI->TASKS_CHG[(uint32_t) group].EN;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_ppi_task_group_disable_address_get(nrf_ppi_channel_group_t group)
|
||||
{
|
||||
return (uint32_t *) &NRF_PPI->TASKS_CHG[(uint32_t) group].DIS;
|
||||
}
|
||||
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_PPI_H__
|
||||
@@ -0,0 +1,685 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_PWM_H__
|
||||
#define NRF_PWM_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_pwm_hal PWM HAL
|
||||
* @{
|
||||
* @ingroup nrf_pwm
|
||||
* @brief Hardware access layer for managing the Pulse Width Modulation (PWM) peripheral.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This value can be provided as a parameter for the @ref nrf_pwm_pins_set
|
||||
* function call to specify that a given output channel shall not be
|
||||
* connected to a physical pin.
|
||||
*/
|
||||
#define NRF_PWM_PIN_NOT_CONNECTED 0xFFFFFFFF
|
||||
|
||||
/**
|
||||
* @brief Number of channels in each Pointer to the peripheral registers structure.
|
||||
*/
|
||||
#define NRF_PWM_CHANNEL_COUNT 4
|
||||
|
||||
|
||||
/**
|
||||
* @brief PWM tasks.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
NRF_PWM_TASK_STOP = offsetof(NRF_PWM_Type, TASKS_STOP), ///< Stops PWM pulse generation on all channels at the end of the current PWM period, and stops the sequence playback.
|
||||
NRF_PWM_TASK_SEQSTART0 = offsetof(NRF_PWM_Type, TASKS_SEQSTART[0]), ///< Starts playback of sequence 0.
|
||||
NRF_PWM_TASK_SEQSTART1 = offsetof(NRF_PWM_Type, TASKS_SEQSTART[1]), ///< Starts playback of sequence 1.
|
||||
NRF_PWM_TASK_NEXTSTEP = offsetof(NRF_PWM_Type, TASKS_NEXTSTEP) ///< Steps by one value in the current sequence if the decoder is set to @ref NRF_PWM_STEP_TRIGGERED mode.
|
||||
/*lint -restore*/
|
||||
} nrf_pwm_task_t;
|
||||
|
||||
/**
|
||||
* @brief PWM events.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
NRF_PWM_EVENT_STOPPED = offsetof(NRF_PWM_Type, EVENTS_STOPPED), ///< Response to STOP task, emitted when PWM pulses are no longer generated.
|
||||
NRF_PWM_EVENT_SEQSTARTED0 = offsetof(NRF_PWM_Type, EVENTS_SEQSTARTED[0]), ///< First PWM period started on sequence 0.
|
||||
NRF_PWM_EVENT_SEQSTARTED1 = offsetof(NRF_PWM_Type, EVENTS_SEQSTARTED[1]), ///< First PWM period started on sequence 1.
|
||||
NRF_PWM_EVENT_SEQEND0 = offsetof(NRF_PWM_Type, EVENTS_SEQEND[0]), ///< Emitted at the end of every sequence 0 when its last value has been read from RAM.
|
||||
NRF_PWM_EVENT_SEQEND1 = offsetof(NRF_PWM_Type, EVENTS_SEQEND[1]), ///< Emitted at the end of every sequence 1 when its last value has been read from RAM.
|
||||
NRF_PWM_EVENT_PWMPERIODEND = offsetof(NRF_PWM_Type, EVENTS_PWMPERIODEND), ///< Emitted at the end of each PWM period.
|
||||
NRF_PWM_EVENT_LOOPSDONE = offsetof(NRF_PWM_Type, EVENTS_LOOPSDONE) ///< Concatenated sequences have been played the requested number of times.
|
||||
/*lint -restore*/
|
||||
} nrf_pwm_event_t;
|
||||
|
||||
/**
|
||||
* @brief PWM interrupts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_PWM_INT_STOPPED_MASK = PWM_INTENSET_STOPPED_Msk, ///< Interrupt on STOPPED event.
|
||||
NRF_PWM_INT_SEQSTARTED0_MASK = PWM_INTENSET_SEQSTARTED0_Msk, ///< Interrupt on SEQSTARTED[0] event.
|
||||
NRF_PWM_INT_SEQSTARTED1_MASK = PWM_INTENSET_SEQSTARTED1_Msk, ///< Interrupt on SEQSTARTED[1] event.
|
||||
NRF_PWM_INT_SEQEND0_MASK = PWM_INTENSET_SEQEND0_Msk, ///< Interrupt on SEQEND[0] event.
|
||||
NRF_PWM_INT_SEQEND1_MASK = PWM_INTENSET_SEQEND1_Msk, ///< Interrupt on SEQEND[1] event.
|
||||
NRF_PWM_INT_PWMPERIODEND_MASK = PWM_INTENSET_PWMPERIODEND_Msk, ///< Interrupt on PWMPERIODEND event.
|
||||
NRF_PWM_INT_LOOPSDONE_MASK = PWM_INTENSET_LOOPSDONE_Msk ///< Interrupt on LOOPSDONE event.
|
||||
} nrf_pwm_int_mask_t;
|
||||
|
||||
/**
|
||||
* @brief PWM shortcuts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_PWM_SHORT_SEQEND0_STOP_MASK = PWM_SHORTS_SEQEND0_STOP_Msk, ///< Shortcut between SEQEND[0] event and STOP task.
|
||||
NRF_PWM_SHORT_SEQEND1_STOP_MASK = PWM_SHORTS_SEQEND1_STOP_Msk, ///< Shortcut between SEQEND[1] event and STOP task.
|
||||
NRF_PWM_SHORT_LOOPSDONE_SEQSTART0_MASK = PWM_SHORTS_LOOPSDONE_SEQSTART0_Msk, ///< Shortcut between LOOPSDONE event and SEQSTART[0] task.
|
||||
NRF_PWM_SHORT_LOOPSDONE_SEQSTART1_MASK = PWM_SHORTS_LOOPSDONE_SEQSTART1_Msk, ///< Shortcut between LOOPSDONE event and SEQSTART[1] task.
|
||||
NRF_PWM_SHORT_LOOPSDONE_STOP_MASK = PWM_SHORTS_LOOPSDONE_STOP_Msk ///< Shortcut between LOOPSDONE event and STOP task.
|
||||
} nrf_pwm_short_mask_t;
|
||||
|
||||
/**
|
||||
* @brief PWM modes of operation.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_PWM_MODE_UP = PWM_MODE_UPDOWN_Up, ///< Up counter (edge-aligned PWM duty cycle).
|
||||
NRF_PWM_MODE_UP_AND_DOWN = PWM_MODE_UPDOWN_UpAndDown, ///< Up and down counter (center-aligned PWM duty cycle).
|
||||
} nrf_pwm_mode_t;
|
||||
|
||||
/**
|
||||
* @brief PWM base clock frequencies.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_PWM_CLK_16MHz = PWM_PRESCALER_PRESCALER_DIV_1, ///< 16 MHz / 1 = 16 MHz.
|
||||
NRF_PWM_CLK_8MHz = PWM_PRESCALER_PRESCALER_DIV_2, ///< 16 MHz / 2 = 8 MHz.
|
||||
NRF_PWM_CLK_4MHz = PWM_PRESCALER_PRESCALER_DIV_4, ///< 16 MHz / 4 = 4 MHz.
|
||||
NRF_PWM_CLK_2MHz = PWM_PRESCALER_PRESCALER_DIV_8, ///< 16 MHz / 8 = 2 MHz.
|
||||
NRF_PWM_CLK_1MHz = PWM_PRESCALER_PRESCALER_DIV_16, ///< 16 MHz / 16 = 1 MHz.
|
||||
NRF_PWM_CLK_500kHz = PWM_PRESCALER_PRESCALER_DIV_32, ///< 16 MHz / 32 = 500 kHz.
|
||||
NRF_PWM_CLK_250kHz = PWM_PRESCALER_PRESCALER_DIV_64, ///< 16 MHz / 64 = 250 kHz.
|
||||
NRF_PWM_CLK_125kHz = PWM_PRESCALER_PRESCALER_DIV_128 ///< 16 MHz / 128 = 125 kHz.
|
||||
} nrf_pwm_clk_t;
|
||||
|
||||
/**
|
||||
* @brief PWM decoder load modes.
|
||||
*
|
||||
* The selected mode determines how the sequence data is read from RAM and
|
||||
* spread to the compare registers.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_PWM_LOAD_COMMON = PWM_DECODER_LOAD_Common, ///< 1st half word (16-bit) used in all PWM channels (0-3).
|
||||
NRF_PWM_LOAD_GROUPED = PWM_DECODER_LOAD_Grouped, ///< 1st half word (16-bit) used in channels 0 and 1; 2nd word in channels 2 and 3.
|
||||
NRF_PWM_LOAD_INDIVIDUAL = PWM_DECODER_LOAD_Individual, ///< 1st half word (16-bit) used in channel 0; 2nd in channel 1; 3rd in channel 2; 4th in channel 3.
|
||||
NRF_PWM_LOAD_WAVE_FORM = PWM_DECODER_LOAD_WaveForm ///< 1st half word (16-bit) used in channel 0; 2nd in channel 1; ... ; 4th as the top value for the pulse generator counter.
|
||||
} nrf_pwm_dec_load_t;
|
||||
|
||||
/**
|
||||
* @brief PWM decoder next step modes.
|
||||
*
|
||||
* The selected mode determines when the next value from the active sequence
|
||||
* is loaded.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_PWM_STEP_AUTO = PWM_DECODER_MODE_RefreshCount, ///< Automatically after the current value is played and repeated the requested number of times.
|
||||
NRF_PWM_STEP_TRIGGERED = PWM_DECODER_MODE_NextStep ///< When the @ref NRF_PWM_TASK_NEXTSTEP task is triggered.
|
||||
} nrf_pwm_dec_step_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Type used for defining duty cycle values for a sequence
|
||||
* loaded in @ref NRF_PWM_LOAD_COMMON mode.
|
||||
*/
|
||||
typedef uint16_t nrf_pwm_values_common_t;
|
||||
|
||||
/**
|
||||
* @brief Structure for defining duty cycle values for a sequence
|
||||
* loaded in @ref NRF_PWM_LOAD_GROUPED mode.
|
||||
*/
|
||||
typedef struct {
|
||||
uint16_t group_0; ///< Duty cycle value for group 0 (channels 0 and 1).
|
||||
uint16_t group_1; ///< Duty cycle value for group 1 (channels 2 and 3).
|
||||
} nrf_pwm_values_grouped_t;
|
||||
|
||||
/**
|
||||
* @brief Structure for defining duty cycle values for a sequence
|
||||
* loaded in @ref NRF_PWM_LOAD_INDIVIDUAL mode.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t channel_0; ///< Duty cycle value for channel 0.
|
||||
uint16_t channel_1; ///< Duty cycle value for channel 1.
|
||||
uint16_t channel_2; ///< Duty cycle value for channel 2.
|
||||
uint16_t channel_3; ///< Duty cycle value for channel 3.
|
||||
} nrf_pwm_values_individual_t;
|
||||
|
||||
/**
|
||||
* @brief Structure for defining duty cycle values for a sequence
|
||||
* loaded in @ref NRF_PWM_LOAD_WAVE_FORM mode.
|
||||
*/
|
||||
typedef struct {
|
||||
uint16_t channel_0; ///< Duty cycle value for channel 0.
|
||||
uint16_t channel_1; ///< Duty cycle value for channel 1.
|
||||
uint16_t channel_2; ///< Duty cycle value for channel 2.
|
||||
uint16_t counter_top; ///< Top value for the pulse generator counter.
|
||||
} nrf_pwm_values_wave_form_t;
|
||||
|
||||
/**
|
||||
* @brief Union grouping pointers to arrays of duty cycle values applicable to
|
||||
* various loading modes.
|
||||
*/
|
||||
typedef union {
|
||||
nrf_pwm_values_common_t const * p_common; ///< Pointer to be used in @ref NRF_PWM_LOAD_COMMON mode.
|
||||
nrf_pwm_values_grouped_t const * p_grouped; ///< Pointer to be used in @ref NRF_PWM_LOAD_GROUPED mode.
|
||||
nrf_pwm_values_individual_t const * p_individual; ///< Pointer to be used in @ref NRF_PWM_LOAD_INDIVIDUAL mode.
|
||||
nrf_pwm_values_wave_form_t const * p_wave_form; ///< Pointer to be used in @ref NRF_PWM_LOAD_WAVE_FORM mode.
|
||||
uint16_t const * p_raw; ///< Pointer providing raw access to the values.
|
||||
} nrf_pwm_values_t;
|
||||
|
||||
/**
|
||||
* @brief Structure for defining a sequence of PWM duty cycles.
|
||||
*
|
||||
* When the sequence is set (by a call to @ref nrf_pwm_sequence_set), the
|
||||
* provided duty cycle values are not copied. The @p values pointer is stored
|
||||
* in the peripheral's internal register, and the values are loaded from RAM
|
||||
* during the sequence playback. Therefore, you must ensure that the values
|
||||
* do not change before and during the sequence playback (for example,
|
||||
* the values cannot be placed in a local variable that is allocated on stack).
|
||||
* If the sequence is played in a loop and the values should be updated
|
||||
* before the next iteration, it is safe to modify them when the corresponding
|
||||
* event signaling the end of sequence occurs (@ref NRF_PWM_EVENT_SEQEND0
|
||||
* or @ref NRF_PWM_EVENT_SEQEND1, respectively).
|
||||
*
|
||||
* @note The @p repeats and @p end_delay values (which are written to the
|
||||
* SEQ[n].REFRESH and SEQ[n].ENDDELAY registers in the peripheral,
|
||||
* respectively) are ignored at the end of a complex sequence
|
||||
* playback, indicated by the LOOPSDONE event.
|
||||
* See the @linkProductSpecification52 for more information.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrf_pwm_values_t values; ///< Pointer to an array with duty cycle values. This array must be in Data RAM.
|
||||
/**< This field is defined as an union of pointers
|
||||
* to provide a convenient way to define duty
|
||||
* cycle values in various loading modes
|
||||
* (see @ref nrf_pwm_dec_load_t).
|
||||
* In each value, the most significant bit (15)
|
||||
* determines the polarity of the output and the
|
||||
* others (14-0) compose the 15-bit value to be
|
||||
* compared with the pulse generator counter. */
|
||||
uint16_t length; ///< Number of 16-bit values in the array pointed by @p values.
|
||||
uint32_t repeats; ///< Number of times that each duty cycle should be repeated (after being played once). Ignored in @ref NRF_PWM_STEP_TRIGGERED mode.
|
||||
uint32_t end_delay; ///< Additional time (in PWM periods) that the last duty cycle is to be kept after the sequence is played. Ignored in @ref NRF_PWM_STEP_TRIGGERED mode.
|
||||
} nrf_pwm_sequence_t;
|
||||
|
||||
/**
|
||||
* @brief Helper macro for calculating the number of 16-bit values in specified
|
||||
* array of duty cycle values.
|
||||
*/
|
||||
#define NRF_PWM_VALUES_LENGTH(array) (sizeof(array) / sizeof(uint16_t))
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for activating a specific PWM task.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] task Task to activate.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pwm_task_trigger(NRF_PWM_Type * p_reg,
|
||||
nrf_pwm_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific PWM task register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] task Requested task.
|
||||
*
|
||||
* @return Address of the specified task register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_pwm_task_address_get(NRF_PWM_Type const * p_reg,
|
||||
nrf_pwm_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a specific PWM event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] event Event to clear.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pwm_event_clear(NRF_PWM_Type * p_reg,
|
||||
nrf_pwm_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the state of a specific PWM event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] event Event to check.
|
||||
*
|
||||
* @retval true If the event is set.
|
||||
* @retval false If the event is not set.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_pwm_event_check(NRF_PWM_Type const * p_reg,
|
||||
nrf_pwm_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific PWM event register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] event Requested event.
|
||||
*
|
||||
* @return Address of the specified event register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_pwm_event_address_get(NRF_PWM_Type const * p_reg,
|
||||
nrf_pwm_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling specified shortcuts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] pwm_shorts_mask Shortcuts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pwm_shorts_enable(NRF_PWM_Type * p_reg,
|
||||
uint32_t pwm_shorts_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling specified shortcuts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] pwm_shorts_mask Shortcuts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pwm_shorts_disable(NRF_PWM_Type * p_reg,
|
||||
uint32_t pwm_shorts_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the configuration of PWM shortcuts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] pwm_shorts_mask Shortcuts configuration to set.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pwm_shorts_set(NRF_PWM_Type * p_reg,
|
||||
uint32_t pwm_shorts_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling specified interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] pwm_int_mask Interrupts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pwm_int_enable(NRF_PWM_Type * p_reg,
|
||||
uint32_t pwm_int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling specified interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] pwm_int_mask Interrupts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pwm_int_disable(NRF_PWM_Type * p_reg,
|
||||
uint32_t pwm_int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the configuration of PWM interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] pwm_int_mask Interrupts configuration to set.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pwm_int_set(NRF_PWM_Type * p_reg,
|
||||
uint32_t pwm_int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of a given interrupt.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] pwm_int Interrupt to check.
|
||||
*
|
||||
* @retval true If the interrupt is enabled.
|
||||
* @retval false If the interrupt is not enabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_pwm_int_enable_check(NRF_PWM_Type const * p_reg,
|
||||
nrf_pwm_int_mask_t pwm_int);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling the PWM peripheral.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pwm_enable(NRF_PWM_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling the PWM peripheral.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pwm_disable(NRF_PWM_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for assigning pins to PWM output channels.
|
||||
*
|
||||
* Usage of all PWM output channels is optional. If a given channel is not
|
||||
* needed, pass the @ref NRF_PWM_PIN_NOT_CONNECTED value instead of its pin
|
||||
* number.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] out_pins Array with pin numbers for individual PWM output channels.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pwm_pins_set(NRF_PWM_Type * p_reg,
|
||||
uint32_t out_pins[NRF_PWM_CHANNEL_COUNT]);
|
||||
|
||||
/**
|
||||
* @brief Function for configuring the PWM peripheral.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] base_clock Base clock frequency.
|
||||
* @param[in] mode Operating mode of the pulse generator counter.
|
||||
* @param[in] top_value Value up to which the pulse generator counter counts.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pwm_configure(NRF_PWM_Type * p_reg,
|
||||
nrf_pwm_clk_t base_clock,
|
||||
nrf_pwm_mode_t mode,
|
||||
uint16_t top_value);
|
||||
|
||||
/**
|
||||
* @brief Function for defining a sequence of PWM duty cycles.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] seq_id Identifier of the sequence (0 or 1).
|
||||
* @param[in] p_seq Pointer to the sequence definition.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pwm_sequence_set(NRF_PWM_Type * p_reg,
|
||||
uint8_t seq_id,
|
||||
nrf_pwm_sequence_t const * p_seq);
|
||||
|
||||
/**
|
||||
* @brief Function for modifying the pointer to the duty cycle values
|
||||
* in the specified sequence.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] seq_id Identifier of the sequence (0 or 1).
|
||||
* @param[in] p_values Pointer to an array with duty cycle values.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pwm_seq_ptr_set(NRF_PWM_Type * p_reg,
|
||||
uint8_t seq_id,
|
||||
uint16_t const * p_values);
|
||||
|
||||
/**
|
||||
* @brief Function for modifying the total number of duty cycle values
|
||||
* in the specified sequence.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] seq_id Identifier of the sequence (0 or 1).
|
||||
* @param[in] length Number of duty cycle values.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pwm_seq_cnt_set(NRF_PWM_Type * p_reg,
|
||||
uint8_t seq_id,
|
||||
uint16_t length);
|
||||
|
||||
/**
|
||||
* @brief Function for modifying the additional number of PWM periods spent
|
||||
* on each duty cycle value in the specified sequence.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] seq_id Identifier of the sequence (0 or 1).
|
||||
* @param[in] refresh Number of additional PWM periods for each duty cycle value.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pwm_seq_refresh_set(NRF_PWM_Type * p_reg,
|
||||
uint8_t seq_id,
|
||||
uint32_t refresh);
|
||||
|
||||
/**
|
||||
* @brief Function for modifying the additional time added after the sequence
|
||||
* is played.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] seq_id Identifier of the sequence (0 or 1).
|
||||
* @param[in] end_delay Number of PWM periods added at the end of the sequence.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pwm_seq_end_delay_set(NRF_PWM_Type * p_reg,
|
||||
uint8_t seq_id,
|
||||
uint32_t end_delay);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the mode of loading sequence data from RAM
|
||||
* and advancing the sequence.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] dec_load Mode of loading sequence data from RAM.
|
||||
* @param[in] dec_step Mode of advancing the active sequence.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pwm_decoder_set(NRF_PWM_Type * p_reg,
|
||||
nrf_pwm_dec_load_t dec_load,
|
||||
nrf_pwm_dec_step_t dec_step);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the number of times the sequence playback
|
||||
* should be performed.
|
||||
*
|
||||
* This function applies to two-sequence playback (concatenated sequence 0 and 1).
|
||||
* A single sequence can be played back only once.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] loop_count Number of times to perform the sequence playback.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_pwm_loop_set(NRF_PWM_Type * p_reg,
|
||||
uint16_t loop_count);
|
||||
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
__STATIC_INLINE void nrf_pwm_task_trigger(NRF_PWM_Type * p_reg,
|
||||
nrf_pwm_task_t task)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task)) = 0x1UL;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_pwm_task_address_get(NRF_PWM_Type const * p_reg,
|
||||
nrf_pwm_task_t task)
|
||||
{
|
||||
return ((uint32_t)p_reg + (uint32_t)task);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_pwm_event_clear(NRF_PWM_Type * p_reg,
|
||||
nrf_pwm_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_pwm_event_check(NRF_PWM_Type const * p_reg,
|
||||
nrf_pwm_event_t event)
|
||||
{
|
||||
return (bool)*(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_pwm_event_address_get(NRF_PWM_Type const * p_reg,
|
||||
nrf_pwm_event_t event)
|
||||
{
|
||||
return ((uint32_t)p_reg + (uint32_t)event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_pwm_shorts_enable(NRF_PWM_Type * p_reg,
|
||||
uint32_t pwm_shorts_mask)
|
||||
{
|
||||
p_reg->SHORTS |= pwm_shorts_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_pwm_shorts_disable(NRF_PWM_Type * p_reg,
|
||||
uint32_t pwm_shorts_mask)
|
||||
{
|
||||
p_reg->SHORTS &= ~(pwm_shorts_mask);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_pwm_shorts_set(NRF_PWM_Type * p_reg,
|
||||
uint32_t pwm_shorts_mask)
|
||||
{
|
||||
p_reg->SHORTS = pwm_shorts_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_pwm_int_enable(NRF_PWM_Type * p_reg,
|
||||
uint32_t pwm_int_mask)
|
||||
{
|
||||
p_reg->INTENSET = pwm_int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_pwm_int_disable(NRF_PWM_Type * p_reg,
|
||||
uint32_t pwm_int_mask)
|
||||
{
|
||||
p_reg->INTENCLR = pwm_int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_pwm_int_set(NRF_PWM_Type * p_reg,
|
||||
uint32_t pwm_int_mask)
|
||||
{
|
||||
p_reg->INTEN = pwm_int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_pwm_int_enable_check(NRF_PWM_Type const * p_reg,
|
||||
nrf_pwm_int_mask_t pwm_int)
|
||||
{
|
||||
return (bool)(p_reg->INTENSET & pwm_int);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_pwm_enable(NRF_PWM_Type * p_reg)
|
||||
{
|
||||
p_reg->ENABLE = (PWM_ENABLE_ENABLE_Enabled << PWM_ENABLE_ENABLE_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_pwm_disable(NRF_PWM_Type * p_reg)
|
||||
{
|
||||
p_reg->ENABLE = (PWM_ENABLE_ENABLE_Disabled << PWM_ENABLE_ENABLE_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_pwm_pins_set(NRF_PWM_Type * p_reg,
|
||||
uint32_t out_pins[NRF_PWM_CHANNEL_COUNT])
|
||||
{
|
||||
uint8_t i;
|
||||
for (i = 0; i < NRF_PWM_CHANNEL_COUNT; ++i)
|
||||
{
|
||||
p_reg->PSEL.OUT[i] = out_pins[i];
|
||||
}
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_pwm_configure(NRF_PWM_Type * p_reg,
|
||||
nrf_pwm_clk_t base_clock,
|
||||
nrf_pwm_mode_t mode,
|
||||
uint16_t top_value)
|
||||
{
|
||||
NRFX_ASSERT(top_value <= PWM_COUNTERTOP_COUNTERTOP_Msk);
|
||||
|
||||
p_reg->PRESCALER = base_clock;
|
||||
p_reg->MODE = mode;
|
||||
p_reg->COUNTERTOP = top_value;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_pwm_sequence_set(NRF_PWM_Type * p_reg,
|
||||
uint8_t seq_id,
|
||||
nrf_pwm_sequence_t const * p_seq)
|
||||
{
|
||||
NRFX_ASSERT(p_seq != NULL);
|
||||
|
||||
nrf_pwm_seq_ptr_set( p_reg, seq_id, p_seq->values.p_raw);
|
||||
nrf_pwm_seq_cnt_set( p_reg, seq_id, p_seq->length);
|
||||
nrf_pwm_seq_refresh_set( p_reg, seq_id, p_seq->repeats);
|
||||
nrf_pwm_seq_end_delay_set(p_reg, seq_id, p_seq->end_delay);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_pwm_seq_ptr_set(NRF_PWM_Type * p_reg,
|
||||
uint8_t seq_id,
|
||||
uint16_t const * p_values)
|
||||
{
|
||||
NRFX_ASSERT(seq_id <= 1);
|
||||
NRFX_ASSERT(p_values != NULL);
|
||||
p_reg->SEQ[seq_id].PTR = (uint32_t)p_values;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_pwm_seq_cnt_set(NRF_PWM_Type * p_reg,
|
||||
uint8_t seq_id,
|
||||
uint16_t length)
|
||||
{
|
||||
NRFX_ASSERT(seq_id <= 1);
|
||||
NRFX_ASSERT(length != 0);
|
||||
NRFX_ASSERT(length <= PWM_SEQ_CNT_CNT_Msk);
|
||||
p_reg->SEQ[seq_id].CNT = length;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_pwm_seq_refresh_set(NRF_PWM_Type * p_reg,
|
||||
uint8_t seq_id,
|
||||
uint32_t refresh)
|
||||
{
|
||||
NRFX_ASSERT(seq_id <= 1);
|
||||
NRFX_ASSERT(refresh <= PWM_SEQ_REFRESH_CNT_Msk);
|
||||
p_reg->SEQ[seq_id].REFRESH = refresh;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_pwm_seq_end_delay_set(NRF_PWM_Type * p_reg,
|
||||
uint8_t seq_id,
|
||||
uint32_t end_delay)
|
||||
{
|
||||
NRFX_ASSERT(seq_id <= 1);
|
||||
NRFX_ASSERT(end_delay <= PWM_SEQ_ENDDELAY_CNT_Msk);
|
||||
p_reg->SEQ[seq_id].ENDDELAY = end_delay;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_pwm_decoder_set(NRF_PWM_Type * p_reg,
|
||||
nrf_pwm_dec_load_t dec_load,
|
||||
nrf_pwm_dec_step_t dec_step)
|
||||
{
|
||||
p_reg->DECODER = ((uint32_t)dec_load << PWM_DECODER_LOAD_Pos) |
|
||||
((uint32_t)dec_step << PWM_DECODER_MODE_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_pwm_loop_set(NRF_PWM_Type * p_reg,
|
||||
uint16_t loop_count)
|
||||
{
|
||||
p_reg->LOOP = loop_count;
|
||||
}
|
||||
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_PWM_H__
|
||||
|
||||
@@ -0,0 +1,486 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 <nrfx.h>
|
||||
|
||||
#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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @enum nrf_qdec_task_t
|
||||
* @brief QDEC tasks.
|
||||
*/
|
||||
typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
|
||||
{
|
||||
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;
|
||||
|
||||
/**
|
||||
* @enum nrf_qdec_event_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; /*lint -restore */
|
||||
|
||||
/**
|
||||
* @enum nrf_qdec_short_mask_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;
|
||||
|
||||
/**
|
||||
* @enum nrf_qdec_int_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;
|
||||
|
||||
/**
|
||||
* @enum nrf_qdec_enable_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;
|
||||
|
||||
|
||||
/**
|
||||
* @enum nrf_qdec_dbfen_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;
|
||||
|
||||
/**
|
||||
* @enum nrf_qdec_ledpol_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;
|
||||
|
||||
|
||||
/**
|
||||
* @enum nrf_qdec_sampleper_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;
|
||||
|
||||
/**
|
||||
* @enum nrf_qdec_reportper_t
|
||||
* @brief Available report periods.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
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 reporting disabled. */
|
||||
} nrf_qdec_reportper_t;
|
||||
|
||||
/**
|
||||
* @brief Function for enabling QDEC.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_qdec_enable(void)
|
||||
{
|
||||
NRF_QDEC->ENABLE = NRF_QDEC_ENABLE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for disabling QDEC.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_qdec_disable(void)
|
||||
{
|
||||
NRF_QDEC->ENABLE = NRF_QDEC_DISABLE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for returning the enable state of QDEC.
|
||||
* @return State of the register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_qdec_enable_get(void)
|
||||
{
|
||||
return NRF_QDEC->ENABLE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for enabling QDEC interrupts by mask.
|
||||
* @param[in] qdec_int_mask Sources of the interrupts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_qdec_int_enable(uint32_t qdec_int_mask)
|
||||
{
|
||||
NRF_QDEC->INTENSET = qdec_int_mask; // writing 0 has no effect
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for disabling QDEC interrupts by mask.
|
||||
* @param[in] qdec_int_mask Sources of the interrupts to disable.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_qdec_int_disable(uint32_t qdec_int_mask)
|
||||
{
|
||||
NRF_QDEC->INTENCLR = qdec_int_mask; // writing 0 has no effect
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting the enabled interrupts of the QDEC.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_qdec_int_enable_check(nrf_qdec_int_mask_t qdec_int_mask)
|
||||
{
|
||||
return NRF_QDEC->INTENSET & qdec_int_mask; // when read this register will return the value of INTEN.
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for enabling the debouncing filter of the QED.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_qdec_dbfen_enable(void)
|
||||
{
|
||||
NRF_QDEC->DBFEN = NRF_QDEC_DBFEN_ENABLE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for disabling the debouncing filter of the QED.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_qdec_dbfen_disable(void)
|
||||
{
|
||||
NRF_QDEC->DBFEN = NRF_QDEC_DBFEN_DISABLE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting the state of the QDEC's debouncing filter.
|
||||
* @retval NRF_QDEC_DBFEN_DISABLE If the debouncing filter is disabled.
|
||||
* @retval NRF_QDEC_DBFEN_ENABLE If the debouncing filter is enabled.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_qdec_dbfen_get(void)
|
||||
{
|
||||
return NRF_QDEC->DBFEN;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
NRF_QDEC->PSELA = psela;
|
||||
NRF_QDEC->PSELB = pselb;
|
||||
NRF_QDEC->PSELLED = pselled;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function for setting a specific QDEC task.
|
||||
* @param[in] qdec_task QDEC task to be set.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_qdec_task_trigger(nrf_qdec_task_t qdec_task)
|
||||
{
|
||||
*( (volatile uint32_t *)( (uint8_t *)NRF_QDEC + qdec_task) ) = 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the address of a QDEC task register.
|
||||
* @param[in] qdec_task QDEC task.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_qdec_task_address_get(nrf_qdec_task_t qdec_task)
|
||||
{
|
||||
return (uint32_t *)( (uint8_t *)NRF_QDEC + qdec_task);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a specific QDEC event.
|
||||
* @param[in] qdec_event QDEC event to clear.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_qdec_event_clear(nrf_qdec_event_t qdec_event)
|
||||
{
|
||||
*( (volatile uint32_t *)( (uint8_t *)NRF_QDEC + qdec_event) ) = 0;
|
||||
#if __CORTEX_M == 0x04
|
||||
volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_QDEC + qdec_event));
|
||||
(void)dummy;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of a specific QDEC event.
|
||||
* @return State of the QDEC event.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_qdec_event_check(nrf_qdec_event_t qdec_event)
|
||||
{
|
||||
return *(volatile uint32_t *)( (uint8_t *)NRF_QDEC + qdec_event);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the address of a specific QDEC event register.
|
||||
* @param[in] qdec_event QDEC event.
|
||||
* @return Address of the specified QDEC event.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_qdec_event_address_get(nrf_qdec_event_t qdec_event)
|
||||
{
|
||||
return (uint32_t *)( (uint8_t *)NRF_QDEC + qdec_event);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for setting QDEC shortcuts.
|
||||
* @param[in] qdec_short_mask QDEC shortcut by mask.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_qdec_shorts_enable(uint32_t qdec_short_mask)
|
||||
{
|
||||
NRF_QDEC->SHORTS |= qdec_short_mask;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for clearing shortcuts of the QDEC by mask.
|
||||
* @param[in] qdec_short_mask QDEC shortcute to be cleared.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_qdec_shorts_disable(uint32_t qdec_short_mask)
|
||||
{
|
||||
NRF_QDEC->SHORTS &= ~qdec_short_mask;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the value of QDEC's SAMPLEPER register.
|
||||
* @return Value of the SAMPLEPER register.
|
||||
*/
|
||||
__STATIC_INLINE int32_t nrf_qdec_sampleper_reg_get(void)
|
||||
{
|
||||
return NRF_QDEC->SAMPLEPER;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for converting the value of QDEC's SAMPLE PERIOD to microseconds.
|
||||
* @retval sampling period in microseconds.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_qdec_sampleper_to_value(uint32_t sampleper)
|
||||
{
|
||||
return (1 << (7 + sampleper));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function for setting the value of QDEC's SAMPLEPER register.
|
||||
* @param[in] sample_per Sampling period.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_qdec_sampleper_set(nrf_qdec_sampleper_t sample_per)
|
||||
{
|
||||
NRF_QDEC->SAMPLEPER = sample_per;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the value of QDEC's SAMPLE register.
|
||||
* @return Value of the SAMPLE register.
|
||||
*/
|
||||
__STATIC_INLINE int32_t nrf_qdec_sample_get(void)
|
||||
{
|
||||
return NRF_QDEC->SAMPLE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the value of QDEC's ACC register.
|
||||
* @return Value of the ACC register.
|
||||
*/
|
||||
__STATIC_INLINE int32_t nrf_qdec_acc_get(void)
|
||||
{
|
||||
return NRF_QDEC->ACC;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the value of QDEC's ACCREAD register.
|
||||
* @return Value of the ACCREAD register.
|
||||
*/
|
||||
__STATIC_INLINE int32_t nrf_qdec_accread_get(void)
|
||||
{
|
||||
return NRF_QDEC->ACCREAD;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the value of QDEC's ACCDBL register.
|
||||
* @return Value of the ACCDBL register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_qdec_accdbl_get(void)
|
||||
{
|
||||
return NRF_QDEC->ACCDBL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the value of QDEC's ACCDBLREAD register.
|
||||
* @return Value of the ACCDBLREAD register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_qdec_accdblread_get(void)
|
||||
{
|
||||
return NRF_QDEC->ACCDBLREAD;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for setting how long the LED is switched on before sampling.
|
||||
* @param[in] time_us Time (in microseconds) how long the LED is switched on before sampling.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_qdec_ledpre_set(uint32_t time_us)
|
||||
{
|
||||
NRF_QDEC->LEDPRE = time_us;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving how long the LED is switched on before sampling.
|
||||
* @retval time_us Time (in microseconds) how long the LED is switched on before sampling.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_qdec_ledpre_get(void)
|
||||
{
|
||||
return NRF_QDEC->LEDPRE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for setting the report period (in samples).
|
||||
* @param[in] reportper Number of samples.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_qdec_reportper_set(nrf_qdec_reportper_t reportper)
|
||||
{
|
||||
NRF_QDEC->REPORTPER = reportper;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the report period.
|
||||
* @retval reportper Number of samples as encoded in the register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_qdec_reportper_reg_get(void)
|
||||
{
|
||||
return NRF_QDEC->REPORTPER;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the value of QDEC's SAMPLEPER register.
|
||||
* @param [in] reportper Reportper to be converted to amount of samples per report.
|
||||
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_qdec_reportper_to_value(uint32_t reportper)
|
||||
{
|
||||
return (reportper == NRF_QDEC_REPORTPER_10) ? 10 : reportper * 40;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for setting the active level for the LED.
|
||||
* @param[in] pol Active level for the LED.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_qdec_ledpol_set(nrf_qdec_ledpol_t pol)
|
||||
{
|
||||
NRF_QDEC->LEDPOL = pol;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the active level for the LED.
|
||||
* @return Active level for the LED.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_qdec_ledpol_get(void)
|
||||
{
|
||||
return NRF_QDEC->LEDPOL;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,769 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 <nrfx.h>
|
||||
|
||||
#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
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
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. */
|
||||
/*lint -restore*/
|
||||
} nrf_qspi_task_t;
|
||||
|
||||
/**
|
||||
* @brief QSPI events.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
NRF_QSPI_EVENT_READY = offsetof(NRF_QSPI_Type, EVENTS_READY) /**< QSPI peripheral is ready after it executes any task. */
|
||||
/*lint -restore*/
|
||||
} 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 Pins 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 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/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 a specific QSPI task.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral register structure.
|
||||
* @param[in] task Task to activate.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_qspi_task_trigger(NRF_QSPI_Type * p_reg, nrf_qspi_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific QSPI task register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral register structure.
|
||||
* @param[in] task Requested 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 a specific QSPI event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral register structure.
|
||||
* @param[in] qspi_event Event to clear.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_qspi_event_clear(NRF_QSPI_Type * p_reg, nrf_qspi_event_t qspi_event);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the state of a specific SPI event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral register structure.
|
||||
* @param[in] qspi_event Event to check.
|
||||
*
|
||||
* @retval true If the event is set.
|
||||
* @retval false If the event is not set.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_qspi_event_check(NRF_QSPI_Type const * p_reg, nrf_qspi_event_t qspi_event);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific QSPI event register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral register structure.
|
||||
* @param[in] qspi_event Requested 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 qspi_event);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling specified interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral register structure.
|
||||
* @param[in] qspi_int_mask Interrupts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_qspi_int_enable(NRF_QSPI_Type * p_reg, uint32_t qspi_int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling specified interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral register structure.
|
||||
* @param[in] qspi_int_mask Interrupts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_qspi_int_disable(NRF_QSPI_Type * p_reg, uint32_t qspi_int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of a given interrupt.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral register structure.
|
||||
* @param[in] qspi_int Interrupt to check.
|
||||
*
|
||||
* @retval true If the interrupt is enabled.
|
||||
* @retval false If 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 peripheral register structure.
|
||||
*/
|
||||
__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 peripheral register structure.
|
||||
*/
|
||||
__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 peripheral register structure.
|
||||
* @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 setting the QSPI XIPOFFSET register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral register structure.
|
||||
* @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 peripheral register structure.
|
||||
* @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 peripheral register structure.
|
||||
* @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.
|
||||
*
|
||||
* 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 peripheral register structure.
|
||||
* @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 peripheral register structure.
|
||||
* @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 peripheral register structure.
|
||||
* @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 peripheral register structure.
|
||||
* @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 peripheral register structure.
|
||||
*
|
||||
* @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 peripheral register structure.
|
||||
*
|
||||
* @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 peripheral register structure.
|
||||
*
|
||||
* @retval true If QSPI is busy.
|
||||
* @retval false If 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 peripheral register structure.
|
||||
* @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 peripheral register structure.
|
||||
* @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 peripheral register structure.
|
||||
* @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);
|
||||
|
||||
#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 qspi_event)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)qspi_event)) = 0x0UL;
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_qspi_event_check(NRF_QSPI_Type const * p_reg, nrf_qspi_event_t qspi_event)
|
||||
{
|
||||
return (bool)*(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)qspi_event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_qspi_event_address_get(NRF_QSPI_Type const * p_reg,
|
||||
nrf_qspi_event_t qspi_event)
|
||||
{
|
||||
return (uint32_t *)((uint8_t *)p_reg + (uint32_t)qspi_event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_qspi_int_enable(NRF_QSPI_Type * p_reg, uint32_t qspi_int_mask)
|
||||
{
|
||||
p_reg->INTENSET = qspi_int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_qspi_int_disable(NRF_QSPI_Type * p_reg, uint32_t qspi_int_mask)
|
||||
{
|
||||
p_reg->INTENCLR = qspi_int_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)
|
||||
{
|
||||
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_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 reg = p_reg->CINSTRDAT1;
|
||||
switch (length)
|
||||
{
|
||||
case NRF_QSPI_CINSTR_LEN_9B:
|
||||
p_rx_data_8[7] = (uint8_t)(reg >> QSPI_CINSTRDAT1_BYTE7_Pos);
|
||||
/* fall-through */
|
||||
case NRF_QSPI_CINSTR_LEN_8B:
|
||||
p_rx_data_8[6] = (uint8_t)(reg >> QSPI_CINSTRDAT1_BYTE6_Pos);
|
||||
/* fall-through */
|
||||
case NRF_QSPI_CINSTR_LEN_7B:
|
||||
p_rx_data_8[5] = (uint8_t)(reg >> QSPI_CINSTRDAT1_BYTE5_Pos);
|
||||
/* fall-through */
|
||||
case NRF_QSPI_CINSTR_LEN_6B:
|
||||
p_rx_data_8[4] = (uint8_t)(reg);
|
||||
/* fall-through */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
reg = p_reg->CINSTRDAT0;
|
||||
switch (length)
|
||||
{
|
||||
case NRF_QSPI_CINSTR_LEN_5B:
|
||||
p_rx_data_8[3] = (uint8_t)(reg >> QSPI_CINSTRDAT0_BYTE3_Pos);
|
||||
/* fall-through */
|
||||
case NRF_QSPI_CINSTR_LEN_4B:
|
||||
p_rx_data_8[2] = (uint8_t)(reg >> QSPI_CINSTRDAT0_BYTE2_Pos);
|
||||
/* fall-through */
|
||||
case NRF_QSPI_CINSTR_LEN_3B:
|
||||
p_rx_data_8[1] = (uint8_t)(reg >> QSPI_CINSTRDAT0_BYTE1_Pos);
|
||||
/* fall-through */
|
||||
case NRF_QSPI_CINSTR_LEN_2B:
|
||||
p_rx_data_8[0] = (uint8_t)(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_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));
|
||||
}
|
||||
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_QSPI_H__
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,265 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_RNG_H__
|
||||
#define NRF_RNG_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_rng_hal RNG HAL
|
||||
* @{
|
||||
* @ingroup nrf_rng
|
||||
* @brief Hardware access layer for managing the Random Number Generator (RNG) peripheral.
|
||||
*/
|
||||
|
||||
#define NRF_RNG_TASK_SET (1UL)
|
||||
#define NRF_RNG_EVENT_CLEAR (0UL)
|
||||
/**
|
||||
* @enum nrf_rng_task_t
|
||||
* @brief RNG tasks.
|
||||
*/
|
||||
typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
|
||||
{
|
||||
NRF_RNG_TASK_START = offsetof(NRF_RNG_Type, TASKS_START), /**< Start the random number generator. */
|
||||
NRF_RNG_TASK_STOP = offsetof(NRF_RNG_Type, TASKS_STOP) /**< Stop the random number generator. */
|
||||
} nrf_rng_task_t; /*lint -restore */
|
||||
|
||||
/**
|
||||
* @enum nrf_rng_event_t
|
||||
* @brief RNG events.
|
||||
*/
|
||||
typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
|
||||
{
|
||||
NRF_RNG_EVENT_VALRDY = offsetof(NRF_RNG_Type, EVENTS_VALRDY) /**< New random number generated event. */
|
||||
} nrf_rng_event_t; /*lint -restore */
|
||||
|
||||
/**
|
||||
* @enum nrf_rng_int_mask_t
|
||||
* @brief RNG interrupts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_RNG_INT_VALRDY_MASK = RNG_INTENSET_VALRDY_Msk /**< Mask for enabling or disabling an interrupt on VALRDY event. */
|
||||
} nrf_rng_int_mask_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_rng_short_mask_t
|
||||
* @brief Types of RNG shortcuts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_RNG_SHORT_VALRDY_STOP_MASK = RNG_SHORTS_VALRDY_STOP_Msk /**< Mask for setting shortcut between EVENT_VALRDY and TASK_STOP. */
|
||||
} nrf_rng_short_mask_t;
|
||||
|
||||
/**
|
||||
* @brief Function for enabling interrupts.
|
||||
*
|
||||
* @param[in] rng_int_mask Mask of interrupts.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_rng_int_enable(uint32_t rng_int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling interrupts.
|
||||
*
|
||||
* @param[in] rng_int_mask Mask of interrupts.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_rng_int_disable(uint32_t rng_int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the state of a specific interrupt.
|
||||
*
|
||||
* @param[in] rng_int_mask Interrupt.
|
||||
*
|
||||
* @retval true If the interrupt is not enabled.
|
||||
* @retval false If the interrupt is enabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_rng_int_get(nrf_rng_int_mask_t rng_int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific task.
|
||||
*
|
||||
* This function can be used by the PPI module.
|
||||
*
|
||||
* @param[in] rng_task Task.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_rng_task_address_get(nrf_rng_task_t rng_task);
|
||||
|
||||
/**
|
||||
* @brief Function for setting a specific task.
|
||||
*
|
||||
* @param[in] rng_task Task.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_rng_task_trigger(nrf_rng_task_t rng_task);
|
||||
|
||||
/**
|
||||
* @brief Function for getting address of a specific event.
|
||||
*
|
||||
* This function can be used by the PPI module.
|
||||
*
|
||||
* @param[in] rng_event Event.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_rng_event_address_get(nrf_rng_event_t rng_event);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a specific event.
|
||||
*
|
||||
* @param[in] rng_event Event.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_rng_event_clear(nrf_rng_event_t rng_event);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the state of a specific event.
|
||||
*
|
||||
* @param[in] rng_event Event.
|
||||
*
|
||||
* @retval true If the event is not set.
|
||||
* @retval false If the event is set.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_rng_event_get(nrf_rng_event_t rng_event);
|
||||
|
||||
/**
|
||||
* @brief Function for setting shortcuts.
|
||||
*
|
||||
* @param[in] rng_short_mask Mask of shortcuts.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_rng_shorts_enable(uint32_t rng_short_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing shortcuts.
|
||||
*
|
||||
* @param[in] rng_short_mask Mask of shortcuts.
|
||||
*
|
||||
*/
|
||||
__STATIC_INLINE void nrf_rng_shorts_disable(uint32_t rng_short_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the previously generated random value.
|
||||
*
|
||||
* @return Previously generated random value.
|
||||
*/
|
||||
__STATIC_INLINE uint8_t nrf_rng_random_value_get(void);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling digital error correction.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_rng_error_correction_enable(void);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling digital error correction.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_rng_error_correction_disable(void);
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
__STATIC_INLINE void nrf_rng_int_enable(uint32_t rng_int_mask)
|
||||
{
|
||||
NRF_RNG->INTENSET = rng_int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_rng_int_disable(uint32_t rng_int_mask)
|
||||
{
|
||||
NRF_RNG->INTENCLR = rng_int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_rng_int_get(nrf_rng_int_mask_t rng_int_mask)
|
||||
{
|
||||
return (bool)(NRF_RNG->INTENCLR & rng_int_mask);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_rng_task_address_get(nrf_rng_task_t rng_task)
|
||||
{
|
||||
return (uint32_t *)((uint8_t *)NRF_RNG + rng_task);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_rng_task_trigger(nrf_rng_task_t rng_task)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)NRF_RNG + rng_task)) = NRF_RNG_TASK_SET;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_rng_event_address_get(nrf_rng_event_t rng_event)
|
||||
{
|
||||
return (uint32_t *)((uint8_t *)NRF_RNG + rng_event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_rng_event_clear(nrf_rng_event_t rng_event)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)NRF_RNG + rng_event)) = NRF_RNG_EVENT_CLEAR;
|
||||
#if __CORTEX_M == 0x04
|
||||
volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_RNG + rng_event));
|
||||
(void)dummy;
|
||||
#endif
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_rng_event_get(nrf_rng_event_t rng_event)
|
||||
{
|
||||
return (bool) * ((volatile uint32_t *)((uint8_t *)NRF_RNG + rng_event));
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_rng_shorts_enable(uint32_t rng_short_mask)
|
||||
{
|
||||
NRF_RNG->SHORTS |= rng_short_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_rng_shorts_disable(uint32_t rng_short_mask)
|
||||
{
|
||||
NRF_RNG->SHORTS &= ~rng_short_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint8_t nrf_rng_random_value_get(void)
|
||||
{
|
||||
return (uint8_t)(NRF_RNG->VALUE & RNG_VALUE_VALUE_Msk);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_rng_error_correction_enable(void)
|
||||
{
|
||||
NRF_RNG->CONFIG |= RNG_CONFIG_DERCEN_Msk;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_rng_error_correction_disable(void)
|
||||
{
|
||||
NRF_RNG->CONFIG &= ~RNG_CONFIG_DERCEN_Msk;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRF_RNG_H__ */
|
||||
@@ -0,0 +1,321 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_RTC_H
|
||||
#define NRF_RTC_H
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_rtc_hal RTC HAL
|
||||
* @{
|
||||
* @ingroup nrf_rtc
|
||||
* @brief Hardware access layer for managing the Real Time Counter (RTC) peripheral.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Macro for getting the number of compare channels available
|
||||
* in a given RTC instance.
|
||||
*/
|
||||
|
||||
#define NRF_RTC_CC_CHANNEL_COUNT(id) NRFX_CONCAT_3(RTC, id, _CC_NUM)
|
||||
|
||||
#define RTC_INPUT_FREQ 32768 /**< Input frequency of the RTC instance. */
|
||||
|
||||
/**
|
||||
* @brief Macro for converting expected frequency to prescaler setting.
|
||||
*/
|
||||
#define RTC_FREQ_TO_PRESCALER(FREQ) (uint16_t)(((RTC_INPUT_FREQ) / (FREQ)) - 1)
|
||||
|
||||
/**< Macro for wrapping values to RTC capacity. */
|
||||
#define RTC_WRAP(val) ((val) & RTC_COUNTER_COUNTER_Msk)
|
||||
|
||||
#define RTC_CHANNEL_INT_MASK(ch) ((uint32_t)(NRF_RTC_INT_COMPARE0_MASK) << (ch))
|
||||
#define RTC_CHANNEL_EVENT_ADDR(ch) (nrf_rtc_event_t)((NRF_RTC_EVENT_COMPARE_0) + (ch) * sizeof(uint32_t))
|
||||
/**
|
||||
* @enum nrf_rtc_task_t
|
||||
* @brief RTC tasks.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
NRF_RTC_TASK_START = offsetof(NRF_RTC_Type,TASKS_START), /**< Start. */
|
||||
NRF_RTC_TASK_STOP = offsetof(NRF_RTC_Type,TASKS_STOP), /**< Stop. */
|
||||
NRF_RTC_TASK_CLEAR = offsetof(NRF_RTC_Type,TASKS_CLEAR), /**< Clear. */
|
||||
NRF_RTC_TASK_TRIGGER_OVERFLOW = offsetof(NRF_RTC_Type,TASKS_TRIGOVRFLW),/**< Trigger overflow. */
|
||||
/*lint -restore*/
|
||||
} nrf_rtc_task_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_rtc_event_t
|
||||
* @brief RTC events.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
NRF_RTC_EVENT_TICK = offsetof(NRF_RTC_Type,EVENTS_TICK), /**< Tick event. */
|
||||
NRF_RTC_EVENT_OVERFLOW = offsetof(NRF_RTC_Type,EVENTS_OVRFLW), /**< Overflow event. */
|
||||
NRF_RTC_EVENT_COMPARE_0 = offsetof(NRF_RTC_Type,EVENTS_COMPARE[0]), /**< Compare 0 event. */
|
||||
NRF_RTC_EVENT_COMPARE_1 = offsetof(NRF_RTC_Type,EVENTS_COMPARE[1]), /**< Compare 1 event. */
|
||||
NRF_RTC_EVENT_COMPARE_2 = offsetof(NRF_RTC_Type,EVENTS_COMPARE[2]), /**< Compare 2 event. */
|
||||
NRF_RTC_EVENT_COMPARE_3 = offsetof(NRF_RTC_Type,EVENTS_COMPARE[3]) /**< Compare 3 event. */
|
||||
/*lint -restore*/
|
||||
} nrf_rtc_event_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_rtc_int_t
|
||||
* @brief RTC interrupts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_RTC_INT_TICK_MASK = RTC_INTENSET_TICK_Msk, /**< RTC interrupt from tick event. */
|
||||
NRF_RTC_INT_OVERFLOW_MASK = RTC_INTENSET_OVRFLW_Msk, /**< RTC interrupt from overflow event. */
|
||||
NRF_RTC_INT_COMPARE0_MASK = RTC_INTENSET_COMPARE0_Msk, /**< RTC interrupt from compare event on channel 0. */
|
||||
NRF_RTC_INT_COMPARE1_MASK = RTC_INTENSET_COMPARE1_Msk, /**< RTC interrupt from compare event on channel 1. */
|
||||
NRF_RTC_INT_COMPARE2_MASK = RTC_INTENSET_COMPARE2_Msk, /**< RTC interrupt from compare event on channel 2. */
|
||||
NRF_RTC_INT_COMPARE3_MASK = RTC_INTENSET_COMPARE3_Msk /**< RTC interrupt from compare event on channel 3. */
|
||||
} nrf_rtc_int_t;
|
||||
|
||||
/**@brief Function for setting a compare value for a channel.
|
||||
*
|
||||
* @param[in] p_rtc Pointer to the peripheral registers structure.
|
||||
* @param[in] ch Channel.
|
||||
* @param[in] cc_val Compare value to set.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_rtc_cc_set(NRF_RTC_Type * p_rtc, uint32_t ch, uint32_t cc_val);
|
||||
|
||||
/**@brief Function for returning the compare value for a channel.
|
||||
*
|
||||
* @param[in] p_rtc Pointer to the peripheral registers structure.
|
||||
* @param[in] ch Channel.
|
||||
*
|
||||
* @return COMPARE[ch] value.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_rtc_cc_get(NRF_RTC_Type * p_rtc, uint32_t ch);
|
||||
|
||||
/**@brief Function for enabling interrupts.
|
||||
*
|
||||
* @param[in] p_rtc Pointer to the peripheral registers structure.
|
||||
* @param[in] mask Interrupt mask to be enabled.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_rtc_int_enable(NRF_RTC_Type * p_rtc, uint32_t mask);
|
||||
|
||||
/**@brief Function for disabling interrupts.
|
||||
*
|
||||
* @param[in] p_rtc Pointer to the peripheral registers structure.
|
||||
* @param[in] mask Interrupt mask to be disabled.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_rtc_int_disable(NRF_RTC_Type * p_rtc, uint32_t mask);
|
||||
|
||||
/**@brief Function for checking if interrupts are enabled.
|
||||
*
|
||||
* @param[in] p_rtc Pointer to the peripheral registers structure.
|
||||
* @param[in] mask Mask of interrupt flags to check.
|
||||
*
|
||||
* @return Mask with enabled interrupts.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_rtc_int_is_enabled(NRF_RTC_Type * p_rtc, uint32_t mask);
|
||||
|
||||
/**@brief Function for returning the status of currently enabled interrupts.
|
||||
*
|
||||
* @param[in] p_rtc Pointer to the peripheral registers structure.
|
||||
*
|
||||
* @return Value in INTEN register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_rtc_int_get(NRF_RTC_Type * p_rtc);
|
||||
|
||||
/**@brief Function for checking if an event is pending.
|
||||
*
|
||||
* @param[in] p_rtc Pointer to the peripheral registers structure.
|
||||
* @param[in] event Address of the event.
|
||||
*
|
||||
* @return Mask of pending events.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_rtc_event_pending(NRF_RTC_Type * p_rtc, nrf_rtc_event_t event);
|
||||
|
||||
/**@brief Function for clearing an event.
|
||||
*
|
||||
* @param[in] p_rtc Pointer to the peripheral registers structure.
|
||||
* @param[in] event Event to clear.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_rtc_event_clear(NRF_RTC_Type * p_rtc, nrf_rtc_event_t event);
|
||||
|
||||
/**@brief Function for returning a counter value.
|
||||
*
|
||||
* @param[in] p_rtc Pointer to the peripheral registers structure.
|
||||
*
|
||||
* @return Counter value.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_rtc_counter_get(NRF_RTC_Type * p_rtc);
|
||||
|
||||
/**@brief Function for setting a prescaler value.
|
||||
*
|
||||
* @param[in] p_rtc Pointer to the peripheral registers structure.
|
||||
* @param[in] val Value to set the prescaler to.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_rtc_prescaler_set(NRF_RTC_Type * p_rtc, uint32_t val);
|
||||
|
||||
/**@brief Function for returning the address of an event.
|
||||
*
|
||||
* @param[in] p_rtc Pointer to the peripheral registers structure.
|
||||
* @param[in] event Requested event.
|
||||
*
|
||||
* @return Address of the requested event register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_rtc_event_address_get(NRF_RTC_Type * p_rtc, nrf_rtc_event_t event);
|
||||
|
||||
/**@brief Function for returning the address of a task.
|
||||
*
|
||||
* @param[in] p_rtc Pointer to the peripheral registers structure.
|
||||
* @param[in] task Requested task.
|
||||
*
|
||||
* @return Address of the requested task register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_rtc_task_address_get(NRF_RTC_Type * p_rtc, nrf_rtc_task_t task);
|
||||
|
||||
/**@brief Function for starting a task.
|
||||
*
|
||||
* @param[in] p_rtc Pointer to the peripheral registers structure.
|
||||
* @param[in] task Requested task.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_rtc_task_trigger(NRF_RTC_Type * p_rtc, nrf_rtc_task_t task);
|
||||
|
||||
/**@brief Function for enabling events.
|
||||
*
|
||||
* @param[in] p_rtc Pointer to the peripheral registers structure.
|
||||
* @param[in] mask Mask of event flags to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_rtc_event_enable(NRF_RTC_Type * p_rtc, uint32_t mask);
|
||||
|
||||
/**@brief Function for disabling an event.
|
||||
*
|
||||
* @param[in] p_rtc Pointer to the peripheral registers structure.
|
||||
* @param[in] event Requested event.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_rtc_event_disable(NRF_RTC_Type * p_rtc, uint32_t event);
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
__STATIC_INLINE void nrf_rtc_cc_set(NRF_RTC_Type * p_rtc, uint32_t ch, uint32_t cc_val)
|
||||
{
|
||||
p_rtc->CC[ch] = cc_val;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_rtc_cc_get(NRF_RTC_Type * p_rtc, uint32_t ch)
|
||||
{
|
||||
return p_rtc->CC[ch];
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_rtc_int_enable(NRF_RTC_Type * p_rtc, uint32_t mask)
|
||||
{
|
||||
p_rtc->INTENSET = mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_rtc_int_disable(NRF_RTC_Type * p_rtc, uint32_t mask)
|
||||
{
|
||||
p_rtc->INTENCLR = mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_rtc_int_is_enabled(NRF_RTC_Type * p_rtc, uint32_t mask)
|
||||
{
|
||||
return (p_rtc->INTENSET & mask);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_rtc_int_get(NRF_RTC_Type * p_rtc)
|
||||
{
|
||||
return p_rtc->INTENSET;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_rtc_event_pending(NRF_RTC_Type * p_rtc, nrf_rtc_event_t event)
|
||||
{
|
||||
return *(volatile uint32_t *)((uint8_t *)p_rtc + (uint32_t)event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_rtc_event_clear(NRF_RTC_Type * p_rtc, nrf_rtc_event_t event)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)p_rtc + (uint32_t)event)) = 0;
|
||||
#if __CORTEX_M == 0x04
|
||||
volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)p_rtc + (uint32_t)event));
|
||||
(void)dummy;
|
||||
#endif
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_rtc_counter_get(NRF_RTC_Type * p_rtc)
|
||||
{
|
||||
return p_rtc->COUNTER;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_rtc_prescaler_set(NRF_RTC_Type * p_rtc, uint32_t val)
|
||||
{
|
||||
NRFX_ASSERT(val <= (RTC_PRESCALER_PRESCALER_Msk >> RTC_PRESCALER_PRESCALER_Pos));
|
||||
p_rtc->PRESCALER = val;
|
||||
}
|
||||
__STATIC_INLINE uint32_t rtc_prescaler_get(NRF_RTC_Type * p_rtc)
|
||||
{
|
||||
return p_rtc->PRESCALER;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_rtc_event_address_get(NRF_RTC_Type * p_rtc, nrf_rtc_event_t event)
|
||||
{
|
||||
return (uint32_t)p_rtc + event;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_rtc_task_address_get(NRF_RTC_Type * p_rtc, nrf_rtc_task_t task)
|
||||
{
|
||||
return (uint32_t)p_rtc + task;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_rtc_task_trigger(NRF_RTC_Type * p_rtc, nrf_rtc_task_t task)
|
||||
{
|
||||
*(__IO uint32_t *)((uint32_t)p_rtc + task) = 1;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_rtc_event_enable(NRF_RTC_Type * p_rtc, uint32_t mask)
|
||||
{
|
||||
p_rtc->EVTENSET = mask;
|
||||
}
|
||||
__STATIC_INLINE void nrf_rtc_event_disable(NRF_RTC_Type * p_rtc, uint32_t mask)
|
||||
{
|
||||
p_rtc->EVTENCLR = mask;
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRF_RTC_H */
|
||||
@@ -0,0 +1,644 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_SAADC_H_
|
||||
#define NRF_SAADC_H_
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_saadc_hal SAADC HAL
|
||||
* @{
|
||||
* @ingroup nrf_saadc
|
||||
* @brief Hardware access layer for managing the SAADC peripheral.
|
||||
*/
|
||||
|
||||
#define NRF_SAADC_CHANNEL_COUNT 8
|
||||
|
||||
/**
|
||||
* @brief Resolution of the analog-to-digital converter.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_SAADC_RESOLUTION_8BIT = SAADC_RESOLUTION_VAL_8bit, ///< 8 bit resolution.
|
||||
NRF_SAADC_RESOLUTION_10BIT = SAADC_RESOLUTION_VAL_10bit, ///< 10 bit resolution.
|
||||
NRF_SAADC_RESOLUTION_12BIT = SAADC_RESOLUTION_VAL_12bit, ///< 12 bit resolution.
|
||||
NRF_SAADC_RESOLUTION_14BIT = SAADC_RESOLUTION_VAL_14bit ///< 14 bit resolution.
|
||||
} nrf_saadc_resolution_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Input selection for the analog-to-digital converter.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_SAADC_INPUT_DISABLED = SAADC_CH_PSELP_PSELP_NC, ///< Not connected.
|
||||
NRF_SAADC_INPUT_AIN0 = SAADC_CH_PSELP_PSELP_AnalogInput0, ///< Analog input 0 (AIN0).
|
||||
NRF_SAADC_INPUT_AIN1 = SAADC_CH_PSELP_PSELP_AnalogInput1, ///< Analog input 1 (AIN1).
|
||||
NRF_SAADC_INPUT_AIN2 = SAADC_CH_PSELP_PSELP_AnalogInput2, ///< Analog input 2 (AIN2).
|
||||
NRF_SAADC_INPUT_AIN3 = SAADC_CH_PSELP_PSELP_AnalogInput3, ///< Analog input 3 (AIN3).
|
||||
NRF_SAADC_INPUT_AIN4 = SAADC_CH_PSELP_PSELP_AnalogInput4, ///< Analog input 4 (AIN4).
|
||||
NRF_SAADC_INPUT_AIN5 = SAADC_CH_PSELP_PSELP_AnalogInput5, ///< Analog input 5 (AIN5).
|
||||
NRF_SAADC_INPUT_AIN6 = SAADC_CH_PSELP_PSELP_AnalogInput6, ///< Analog input 6 (AIN6).
|
||||
NRF_SAADC_INPUT_AIN7 = SAADC_CH_PSELP_PSELP_AnalogInput7, ///< Analog input 7 (AIN7).
|
||||
NRF_SAADC_INPUT_VDD = SAADC_CH_PSELP_PSELP_VDD ///< VDD as input.
|
||||
} nrf_saadc_input_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter oversampling mode.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_SAADC_OVERSAMPLE_DISABLED = SAADC_OVERSAMPLE_OVERSAMPLE_Bypass, ///< No oversampling.
|
||||
NRF_SAADC_OVERSAMPLE_2X = SAADC_OVERSAMPLE_OVERSAMPLE_Over2x, ///< Oversample 2x.
|
||||
NRF_SAADC_OVERSAMPLE_4X = SAADC_OVERSAMPLE_OVERSAMPLE_Over4x, ///< Oversample 4x.
|
||||
NRF_SAADC_OVERSAMPLE_8X = SAADC_OVERSAMPLE_OVERSAMPLE_Over8x, ///< Oversample 8x.
|
||||
NRF_SAADC_OVERSAMPLE_16X = SAADC_OVERSAMPLE_OVERSAMPLE_Over16x, ///< Oversample 16x.
|
||||
NRF_SAADC_OVERSAMPLE_32X = SAADC_OVERSAMPLE_OVERSAMPLE_Over32x, ///< Oversample 32x.
|
||||
NRF_SAADC_OVERSAMPLE_64X = SAADC_OVERSAMPLE_OVERSAMPLE_Over64x, ///< Oversample 64x.
|
||||
NRF_SAADC_OVERSAMPLE_128X = SAADC_OVERSAMPLE_OVERSAMPLE_Over128x, ///< Oversample 128x.
|
||||
NRF_SAADC_OVERSAMPLE_256X = SAADC_OVERSAMPLE_OVERSAMPLE_Over256x ///< Oversample 256x.
|
||||
} nrf_saadc_oversample_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter channel resistor control.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_SAADC_RESISTOR_DISABLED = SAADC_CH_CONFIG_RESP_Bypass, ///< Bypass resistor ladder.
|
||||
NRF_SAADC_RESISTOR_PULLDOWN = SAADC_CH_CONFIG_RESP_Pulldown, ///< Pull-down to GND.
|
||||
NRF_SAADC_RESISTOR_PULLUP = SAADC_CH_CONFIG_RESP_Pullup, ///< Pull-up to VDD.
|
||||
NRF_SAADC_RESISTOR_VDD1_2 = SAADC_CH_CONFIG_RESP_VDD1_2 ///< Set input at VDD/2.
|
||||
} nrf_saadc_resistor_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Gain factor of the analog-to-digital converter input.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_SAADC_GAIN1_6 = SAADC_CH_CONFIG_GAIN_Gain1_6, ///< Gain factor 1/6.
|
||||
NRF_SAADC_GAIN1_5 = SAADC_CH_CONFIG_GAIN_Gain1_5, ///< Gain factor 1/5.
|
||||
NRF_SAADC_GAIN1_4 = SAADC_CH_CONFIG_GAIN_Gain1_4, ///< Gain factor 1/4.
|
||||
NRF_SAADC_GAIN1_3 = SAADC_CH_CONFIG_GAIN_Gain1_3, ///< Gain factor 1/3.
|
||||
NRF_SAADC_GAIN1_2 = SAADC_CH_CONFIG_GAIN_Gain1_2, ///< Gain factor 1/2.
|
||||
NRF_SAADC_GAIN1 = SAADC_CH_CONFIG_GAIN_Gain1, ///< Gain factor 1.
|
||||
NRF_SAADC_GAIN2 = SAADC_CH_CONFIG_GAIN_Gain2, ///< Gain factor 2.
|
||||
NRF_SAADC_GAIN4 = SAADC_CH_CONFIG_GAIN_Gain4, ///< Gain factor 4.
|
||||
} nrf_saadc_gain_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Reference selection for the analog-to-digital converter.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_SAADC_REFERENCE_INTERNAL = SAADC_CH_CONFIG_REFSEL_Internal, ///< Internal reference (0.6 V).
|
||||
NRF_SAADC_REFERENCE_VDD4 = SAADC_CH_CONFIG_REFSEL_VDD1_4 ///< VDD/4 as reference.
|
||||
} nrf_saadc_reference_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter acquisition time.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_SAADC_ACQTIME_3US = SAADC_CH_CONFIG_TACQ_3us, ///< 3 us.
|
||||
NRF_SAADC_ACQTIME_5US = SAADC_CH_CONFIG_TACQ_5us, ///< 5 us.
|
||||
NRF_SAADC_ACQTIME_10US = SAADC_CH_CONFIG_TACQ_10us, ///< 10 us.
|
||||
NRF_SAADC_ACQTIME_15US = SAADC_CH_CONFIG_TACQ_15us, ///< 15 us.
|
||||
NRF_SAADC_ACQTIME_20US = SAADC_CH_CONFIG_TACQ_20us, ///< 20 us.
|
||||
NRF_SAADC_ACQTIME_40US = SAADC_CH_CONFIG_TACQ_40us ///< 40 us.
|
||||
} nrf_saadc_acqtime_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter channel mode.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_SAADC_MODE_SINGLE_ENDED = SAADC_CH_CONFIG_MODE_SE, ///< Single ended, PSELN will be ignored, negative input to ADC shorted to GND.
|
||||
NRF_SAADC_MODE_DIFFERENTIAL = SAADC_CH_CONFIG_MODE_Diff ///< Differential mode.
|
||||
} nrf_saadc_mode_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter channel burst mode.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_SAADC_BURST_DISABLED = SAADC_CH_CONFIG_BURST_Disabled, ///< Burst mode is disabled (normal operation).
|
||||
NRF_SAADC_BURST_ENABLED = SAADC_CH_CONFIG_BURST_Enabled ///< Burst mode is enabled. SAADC takes 2^OVERSAMPLE number of samples as fast as it can, and sends the average to Data RAM.
|
||||
} nrf_saadc_burst_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter tasks.
|
||||
*/
|
||||
typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
|
||||
{
|
||||
NRF_SAADC_TASK_START = offsetof(NRF_SAADC_Type, TASKS_START), ///< Start the ADC and prepare the result buffer in RAM.
|
||||
NRF_SAADC_TASK_SAMPLE = offsetof(NRF_SAADC_Type, TASKS_SAMPLE), ///< Take one ADC sample. If scan is enabled, all channels are sampled.
|
||||
NRF_SAADC_TASK_STOP = offsetof(NRF_SAADC_Type, TASKS_STOP), ///< Stop the ADC and terminate any on-going conversion.
|
||||
NRF_SAADC_TASK_CALIBRATEOFFSET = offsetof(NRF_SAADC_Type, TASKS_CALIBRATEOFFSET), ///< Starts offset auto-calibration.
|
||||
} nrf_saadc_task_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter events.
|
||||
*/
|
||||
typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
|
||||
{
|
||||
NRF_SAADC_EVENT_STARTED = offsetof(NRF_SAADC_Type, EVENTS_STARTED), ///< The ADC has started.
|
||||
NRF_SAADC_EVENT_END = offsetof(NRF_SAADC_Type, EVENTS_END), ///< The ADC has filled up the result buffer.
|
||||
NRF_SAADC_EVENT_DONE = offsetof(NRF_SAADC_Type, EVENTS_DONE), ///< A conversion task has been completed.
|
||||
NRF_SAADC_EVENT_RESULTDONE = offsetof(NRF_SAADC_Type, EVENTS_RESULTDONE), ///< A result is ready to get transferred to RAM.
|
||||
NRF_SAADC_EVENT_CALIBRATEDONE = offsetof(NRF_SAADC_Type, EVENTS_CALIBRATEDONE), ///< Calibration is complete.
|
||||
NRF_SAADC_EVENT_STOPPED = offsetof(NRF_SAADC_Type, EVENTS_STOPPED), ///< The ADC has stopped.
|
||||
NRF_SAADC_EVENT_CH0_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[0].LIMITH), ///< Last result is equal or above CH[0].LIMIT.HIGH.
|
||||
NRF_SAADC_EVENT_CH0_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[0].LIMITL), ///< Last result is equal or below CH[0].LIMIT.LOW.
|
||||
NRF_SAADC_EVENT_CH1_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[1].LIMITH), ///< Last result is equal or above CH[1].LIMIT.HIGH.
|
||||
NRF_SAADC_EVENT_CH1_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[1].LIMITL), ///< Last result is equal or below CH[1].LIMIT.LOW.
|
||||
NRF_SAADC_EVENT_CH2_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[2].LIMITH), ///< Last result is equal or above CH[2].LIMIT.HIGH.
|
||||
NRF_SAADC_EVENT_CH2_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[2].LIMITL), ///< Last result is equal or below CH[2].LIMIT.LOW.
|
||||
NRF_SAADC_EVENT_CH3_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[3].LIMITH), ///< Last result is equal or above CH[3].LIMIT.HIGH.
|
||||
NRF_SAADC_EVENT_CH3_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[3].LIMITL), ///< Last result is equal or below CH[3].LIMIT.LOW.
|
||||
NRF_SAADC_EVENT_CH4_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[4].LIMITH), ///< Last result is equal or above CH[4].LIMIT.HIGH.
|
||||
NRF_SAADC_EVENT_CH4_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[4].LIMITL), ///< Last result is equal or below CH[4].LIMIT.LOW.
|
||||
NRF_SAADC_EVENT_CH5_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[5].LIMITH), ///< Last result is equal or above CH[5].LIMIT.HIGH.
|
||||
NRF_SAADC_EVENT_CH5_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[5].LIMITL), ///< Last result is equal or below CH[5].LIMIT.LOW.
|
||||
NRF_SAADC_EVENT_CH6_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[6].LIMITH), ///< Last result is equal or above CH[6].LIMIT.HIGH.
|
||||
NRF_SAADC_EVENT_CH6_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[6].LIMITL), ///< Last result is equal or below CH[6].LIMIT.LOW.
|
||||
NRF_SAADC_EVENT_CH7_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[7].LIMITH), ///< Last result is equal or above CH[7].LIMIT.HIGH.
|
||||
NRF_SAADC_EVENT_CH7_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[7].LIMITL) ///< Last result is equal or below CH[7].LIMIT.LOW.
|
||||
} nrf_saadc_event_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter interrupt masks.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_SAADC_INT_STARTED = SAADC_INTENSET_STARTED_Msk, ///< Interrupt on EVENTS_STARTED event.
|
||||
NRF_SAADC_INT_END = SAADC_INTENSET_END_Msk, ///< Interrupt on EVENTS_END event.
|
||||
NRF_SAADC_INT_DONE = SAADC_INTENSET_DONE_Msk, ///< Interrupt on EVENTS_DONE event.
|
||||
NRF_SAADC_INT_RESULTDONE = SAADC_INTENSET_RESULTDONE_Msk, ///< Interrupt on EVENTS_RESULTDONE event.
|
||||
NRF_SAADC_INT_CALIBRATEDONE = SAADC_INTENSET_CALIBRATEDONE_Msk, ///< Interrupt on EVENTS_CALIBRATEDONE event.
|
||||
NRF_SAADC_INT_STOPPED = SAADC_INTENSET_STOPPED_Msk, ///< Interrupt on EVENTS_STOPPED event.
|
||||
NRF_SAADC_INT_CH0LIMITH = SAADC_INTENSET_CH0LIMITH_Msk, ///< Interrupt on EVENTS_CH[0].LIMITH event.
|
||||
NRF_SAADC_INT_CH0LIMITL = SAADC_INTENSET_CH0LIMITL_Msk, ///< Interrupt on EVENTS_CH[0].LIMITL event.
|
||||
NRF_SAADC_INT_CH1LIMITH = SAADC_INTENSET_CH1LIMITH_Msk, ///< Interrupt on EVENTS_CH[1].LIMITH event.
|
||||
NRF_SAADC_INT_CH1LIMITL = SAADC_INTENSET_CH1LIMITL_Msk, ///< Interrupt on EVENTS_CH[1].LIMITL event.
|
||||
NRF_SAADC_INT_CH2LIMITH = SAADC_INTENSET_CH2LIMITH_Msk, ///< Interrupt on EVENTS_CH[2].LIMITH event.
|
||||
NRF_SAADC_INT_CH2LIMITL = SAADC_INTENSET_CH2LIMITL_Msk, ///< Interrupt on EVENTS_CH[2].LIMITL event.
|
||||
NRF_SAADC_INT_CH3LIMITH = SAADC_INTENSET_CH3LIMITH_Msk, ///< Interrupt on EVENTS_CH[3].LIMITH event.
|
||||
NRF_SAADC_INT_CH3LIMITL = SAADC_INTENSET_CH3LIMITL_Msk, ///< Interrupt on EVENTS_CH[3].LIMITL event.
|
||||
NRF_SAADC_INT_CH4LIMITH = SAADC_INTENSET_CH4LIMITH_Msk, ///< Interrupt on EVENTS_CH[4].LIMITH event.
|
||||
NRF_SAADC_INT_CH4LIMITL = SAADC_INTENSET_CH4LIMITL_Msk, ///< Interrupt on EVENTS_CH[4].LIMITL event.
|
||||
NRF_SAADC_INT_CH5LIMITH = SAADC_INTENSET_CH5LIMITH_Msk, ///< Interrupt on EVENTS_CH[5].LIMITH event.
|
||||
NRF_SAADC_INT_CH5LIMITL = SAADC_INTENSET_CH5LIMITL_Msk, ///< Interrupt on EVENTS_CH[5].LIMITL event.
|
||||
NRF_SAADC_INT_CH6LIMITH = SAADC_INTENSET_CH6LIMITH_Msk, ///< Interrupt on EVENTS_CH[6].LIMITH event.
|
||||
NRF_SAADC_INT_CH6LIMITL = SAADC_INTENSET_CH6LIMITL_Msk, ///< Interrupt on EVENTS_CH[6].LIMITL event.
|
||||
NRF_SAADC_INT_CH7LIMITH = SAADC_INTENSET_CH7LIMITH_Msk, ///< Interrupt on EVENTS_CH[7].LIMITH event.
|
||||
NRF_SAADC_INT_CH7LIMITL = SAADC_INTENSET_CH7LIMITL_Msk, ///< Interrupt on EVENTS_CH[7].LIMITL event.
|
||||
NRF_SAADC_INT_ALL = 0x7FFFFFFFUL ///< Mask of all interrupts.
|
||||
} nrf_saadc_int_mask_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter value limit type.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_SAADC_LIMIT_LOW = 0,
|
||||
NRF_SAADC_LIMIT_HIGH = 1
|
||||
} nrf_saadc_limit_t;
|
||||
|
||||
|
||||
typedef int16_t nrf_saadc_value_t; ///< Type of a single ADC conversion result.
|
||||
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter configuration structure.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrf_saadc_resolution_t resolution;
|
||||
nrf_saadc_oversample_t oversample;
|
||||
nrf_saadc_value_t * buffer;
|
||||
uint32_t buffer_size;
|
||||
} nrf_saadc_config_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter channel configuration structure.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrf_saadc_resistor_t resistor_p;
|
||||
nrf_saadc_resistor_t resistor_n;
|
||||
nrf_saadc_gain_t gain;
|
||||
nrf_saadc_reference_t reference;
|
||||
nrf_saadc_acqtime_t acq_time;
|
||||
nrf_saadc_mode_t mode;
|
||||
nrf_saadc_burst_t burst;
|
||||
nrf_saadc_input_t pin_p;
|
||||
nrf_saadc_input_t pin_n;
|
||||
} nrf_saadc_channel_config_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for triggering a specific SAADC task.
|
||||
*
|
||||
* @param[in] saadc_task SAADC task.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_saadc_task_trigger(nrf_saadc_task_t saadc_task)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)NRF_SAADC + (uint32_t)saadc_task)) = 0x1UL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific SAADC task register.
|
||||
*
|
||||
* @param[in] saadc_task SAADC task.
|
||||
*
|
||||
* @return Address of the specified SAADC task.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_saadc_task_address_get(nrf_saadc_task_t saadc_task)
|
||||
{
|
||||
return (uint32_t)((uint8_t *)NRF_SAADC + (uint32_t)saadc_task);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting the state of a specific SAADC event.
|
||||
*
|
||||
* @param[in] saadc_event SAADC event.
|
||||
*
|
||||
* @return State of the specified SAADC event.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_saadc_event_check(nrf_saadc_event_t saadc_event)
|
||||
{
|
||||
return (bool)*(volatile uint32_t *)((uint8_t *)NRF_SAADC + (uint32_t)saadc_event);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for clearing the specific SAADC event.
|
||||
*
|
||||
* @param[in] saadc_event SAADC event.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_saadc_event_clear(nrf_saadc_event_t saadc_event)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)NRF_SAADC + (uint32_t)saadc_event)) = 0x0UL;
|
||||
#if __CORTEX_M == 0x04
|
||||
volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_SAADC + (uint32_t)saadc_event));
|
||||
(void)dummy;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific SAADC event register.
|
||||
*
|
||||
* @param[in] saadc_event SAADC event.
|
||||
*
|
||||
* @return Address of the specified SAADC event.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_saadc_event_address_get(nrf_saadc_event_t saadc_event)
|
||||
{
|
||||
return (uint32_t )((uint8_t *)NRF_SAADC + (uint32_t)saadc_event);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific SAADC limit event register.
|
||||
*
|
||||
* @param[in] channel Channel number.
|
||||
* @param[in] limit_type Low limit or high limit.
|
||||
*
|
||||
* @return Address of the specified SAADC limit event.
|
||||
*/
|
||||
__STATIC_INLINE volatile uint32_t * nrf_saadc_event_limit_address_get(uint8_t channel, nrf_saadc_limit_t limit_type)
|
||||
{
|
||||
NRFX_ASSERT(channel < NRF_SAADC_CHANNEL_COUNT);
|
||||
if (limit_type == NRF_SAADC_LIMIT_HIGH)
|
||||
{
|
||||
return &NRF_SAADC->EVENTS_CH[channel].LIMITH;
|
||||
}
|
||||
else
|
||||
{
|
||||
return &NRF_SAADC->EVENTS_CH[channel].LIMITL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting the SAADC channel monitoring limit events.
|
||||
*
|
||||
* @param[in] channel Channel number.
|
||||
* @param[in] limit_type Low limit or high limit.
|
||||
*/
|
||||
__STATIC_INLINE nrf_saadc_event_t nrf_saadc_event_limit_get(uint8_t channel, nrf_saadc_limit_t limit_type)
|
||||
{
|
||||
if (limit_type == NRF_SAADC_LIMIT_HIGH)
|
||||
{
|
||||
return (nrf_saadc_event_t)( (uint32_t) NRF_SAADC_EVENT_CH0_LIMITH +
|
||||
(uint32_t) (NRF_SAADC_EVENT_CH1_LIMITH - NRF_SAADC_EVENT_CH0_LIMITH)
|
||||
* (uint32_t) channel );
|
||||
}
|
||||
else
|
||||
{
|
||||
return (nrf_saadc_event_t)( (uint32_t) NRF_SAADC_EVENT_CH0_LIMITL +
|
||||
(uint32_t) (NRF_SAADC_EVENT_CH1_LIMITL - NRF_SAADC_EVENT_CH0_LIMITL)
|
||||
* (uint32_t) channel );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for configuring the input pins for a specific SAADC channel.
|
||||
*
|
||||
* @param[in] channel Channel number.
|
||||
* @param[in] pselp Positive input.
|
||||
* @param[in] pseln Negative input. Set to NRF_SAADC_INPUT_DISABLED in single ended mode.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_saadc_channel_input_set(uint8_t channel,
|
||||
nrf_saadc_input_t pselp,
|
||||
nrf_saadc_input_t pseln)
|
||||
{
|
||||
NRF_SAADC->CH[channel].PSELN = pseln;
|
||||
NRF_SAADC->CH[channel].PSELP = pselp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for configuring the positive input pin for a specific SAADC channel.
|
||||
*
|
||||
* @param[in] channel Channel number.
|
||||
* @param[in] pselp Positive input.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_saadc_channel_pos_input_set(uint8_t channel,
|
||||
nrf_saadc_input_t pselp)
|
||||
{
|
||||
NRF_SAADC->CH[channel].PSELP = pselp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for setting the SAADC channel monitoring limits.
|
||||
*
|
||||
* @param[in] channel Channel number.
|
||||
* @param[in] low Low limit.
|
||||
* @param[in] high High limit.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_saadc_channel_limits_set(uint8_t channel, int16_t low, int16_t high)
|
||||
{
|
||||
NRF_SAADC->CH[channel].LIMIT = (
|
||||
(((uint32_t) low << SAADC_CH_LIMIT_LOW_Pos) & SAADC_CH_LIMIT_LOW_Msk)
|
||||
| (((uint32_t) high << SAADC_CH_LIMIT_HIGH_Pos) & SAADC_CH_LIMIT_HIGH_Msk));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for enabling specified SAADC interrupts.
|
||||
*
|
||||
* @param[in] saadc_int_mask Interrupt(s) to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_saadc_int_enable(uint32_t saadc_int_mask)
|
||||
{
|
||||
NRF_SAADC->INTENSET = saadc_int_mask;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of specified SAADC interrupts.
|
||||
*
|
||||
* @param[in] saadc_int_mask Interrupt(s) to check.
|
||||
*
|
||||
* @retval true If all specified interrupts are enabled.
|
||||
* @retval false If at least one of the given interrupts is not enabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_saadc_int_enable_check(uint32_t saadc_int_mask)
|
||||
{
|
||||
return (bool)(NRF_SAADC->INTENSET & saadc_int_mask);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for disabling specified interrupts.
|
||||
*
|
||||
* @param saadc_int_mask Interrupt(s) to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_saadc_int_disable(uint32_t saadc_int_mask)
|
||||
{
|
||||
NRF_SAADC->INTENCLR = saadc_int_mask;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for generating masks for SAADC channel limit interrupts.
|
||||
*
|
||||
* @param[in] channel SAADC channel number.
|
||||
* @param[in] limit_type Limit type.
|
||||
*
|
||||
* @returns Interrupt mask.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_saadc_limit_int_get(uint8_t channel, nrf_saadc_limit_t limit_type)
|
||||
{
|
||||
NRFX_ASSERT(channel < NRF_SAADC_CHANNEL_COUNT);
|
||||
uint32_t mask = (limit_type == NRF_SAADC_LIMIT_LOW) ? NRF_SAADC_INT_CH0LIMITL : NRF_SAADC_INT_CH0LIMITH;
|
||||
return mask << (channel * 2);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for checking whether the SAADC is busy.
|
||||
*
|
||||
* This function checks whether the analog-to-digital converter is busy with a conversion.
|
||||
*
|
||||
* @retval true If the SAADC is busy.
|
||||
* @retval false If the SAADC is not busy.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_saadc_busy_check(void)
|
||||
{
|
||||
//return ((NRF_SAADC->STATUS & SAADC_STATUS_STATUS_Msk) == SAADC_STATUS_STATUS_Msk);
|
||||
//simplified for performance
|
||||
return NRF_SAADC->STATUS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for enabling the SAADC.
|
||||
*
|
||||
* The analog-to-digital converter must be enabled before use.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_saadc_enable(void)
|
||||
{
|
||||
NRF_SAADC->ENABLE = (SAADC_ENABLE_ENABLE_Enabled << SAADC_ENABLE_ENABLE_Pos);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for disabling the SAADC.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_saadc_disable(void)
|
||||
{
|
||||
NRF_SAADC->ENABLE = (SAADC_ENABLE_ENABLE_Disabled << SAADC_ENABLE_ENABLE_Pos);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for checking if the SAADC is enabled.
|
||||
*
|
||||
* @retval true If the SAADC is enabled.
|
||||
* @retval false If the SAADC is not enabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_saadc_enable_check(void)
|
||||
{
|
||||
//simplified for performance
|
||||
return NRF_SAADC->ENABLE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for initializing the SAADC result buffer.
|
||||
*
|
||||
* @param[in] p_buffer Pointer to the result buffer.
|
||||
* @param[in] size Size of the buffer (in 16-bit samples).
|
||||
*/
|
||||
__STATIC_INLINE void nrf_saadc_buffer_init(nrf_saadc_value_t * p_buffer,
|
||||
uint32_t size)
|
||||
{
|
||||
NRF_SAADC->RESULT.PTR = (uint32_t)p_buffer;
|
||||
NRF_SAADC->RESULT.MAXCNT = size;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for setting the SAADC result buffer pointer.
|
||||
*
|
||||
* @param[in] p_buffer Pointer to the result buffer.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_saadc_buffer_pointer_set(nrf_saadc_value_t * p_buffer)
|
||||
{
|
||||
NRF_SAADC->RESULT.PTR = (uint32_t)p_buffer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting the SAADC result buffer pointer.
|
||||
*
|
||||
* @return Pointer to the result buffer.
|
||||
*/
|
||||
__STATIC_INLINE nrf_saadc_value_t * nrf_saadc_buffer_pointer_get(void)
|
||||
{
|
||||
return (nrf_saadc_value_t *)NRF_SAADC->RESULT.PTR;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting the number of samples written to the result
|
||||
* buffer since the previous START task.
|
||||
*
|
||||
* @returns Number of 16-bit samples written to the buffer.
|
||||
*/
|
||||
__STATIC_INLINE uint16_t nrf_saadc_amount_get(void)
|
||||
{
|
||||
return NRF_SAADC->RESULT.AMOUNT;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for setting the SAADC sample resolution.
|
||||
*
|
||||
* @param[in] resolution Bit resolution.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_saadc_resolution_set(nrf_saadc_resolution_t resolution)
|
||||
{
|
||||
NRF_SAADC->RESOLUTION = resolution;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for configuring the oversampling feature.
|
||||
*
|
||||
* @param[in] oversample Oversampling mode.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_saadc_oversample_set(nrf_saadc_oversample_t oversample)
|
||||
{
|
||||
NRF_SAADC->OVERSAMPLE = oversample;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function for getting the oversampling feature configuration.
|
||||
*
|
||||
* @return Oversampling configuration.
|
||||
*/
|
||||
__STATIC_INLINE nrf_saadc_oversample_t nrf_saadc_oversample_get(void)
|
||||
{
|
||||
return (nrf_saadc_oversample_t)NRF_SAADC->OVERSAMPLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function for initializing the SAADC channel.
|
||||
*
|
||||
* @param[in] channel Channel number.
|
||||
* @param[in] config Pointer to the channel configuration structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_saadc_channel_init(uint8_t channel,
|
||||
nrf_saadc_channel_config_t const * const config)
|
||||
{
|
||||
NRF_SAADC->CH[channel].CONFIG =
|
||||
((config->resistor_p << SAADC_CH_CONFIG_RESP_Pos) & SAADC_CH_CONFIG_RESP_Msk)
|
||||
| ((config->resistor_n << SAADC_CH_CONFIG_RESN_Pos) & SAADC_CH_CONFIG_RESN_Msk)
|
||||
| ((config->gain << SAADC_CH_CONFIG_GAIN_Pos) & SAADC_CH_CONFIG_GAIN_Msk)
|
||||
| ((config->reference << SAADC_CH_CONFIG_REFSEL_Pos) & SAADC_CH_CONFIG_REFSEL_Msk)
|
||||
| ((config->acq_time << SAADC_CH_CONFIG_TACQ_Pos) & SAADC_CH_CONFIG_TACQ_Msk)
|
||||
| ((config->mode << SAADC_CH_CONFIG_MODE_Pos) & SAADC_CH_CONFIG_MODE_Msk)
|
||||
| ((config->burst << SAADC_CH_CONFIG_BURST_Pos) & SAADC_CH_CONFIG_BURST_Msk);
|
||||
nrf_saadc_channel_input_set(channel, config->pin_p, config->pin_n);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRF_SAADC_H_ */
|
||||
@@ -0,0 +1,360 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_SPI_H__
|
||||
#define NRF_SPI_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_spi_hal SPI HAL
|
||||
* @{
|
||||
* @ingroup nrf_spi
|
||||
* @brief Hardware access layer for managing the SPI peripheral.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This value can be used as a parameter for the @ref nrf_spi_pins_set
|
||||
* function to specify that a given SPI signal (SCK, MOSI, or MISO)
|
||||
* shall not be connected to a physical pin.
|
||||
*/
|
||||
#define NRF_SPI_PIN_NOT_CONNECTED 0xFFFFFFFF
|
||||
|
||||
|
||||
/**
|
||||
* @brief SPI events.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
NRF_SPI_EVENT_READY = offsetof(NRF_SPI_Type, EVENTS_READY) ///< TXD byte sent and RXD byte received.
|
||||
/*lint -restore*/
|
||||
} nrf_spi_event_t;
|
||||
|
||||
/**
|
||||
* @brief SPI interrupts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_SPI_INT_READY_MASK = SPI_INTENSET_READY_Msk, ///< Interrupt on READY event.
|
||||
NRF_SPI_ALL_INTS_MASK = SPI_INTENSET_READY_Msk ///< All SPI interrupts.
|
||||
} nrf_spi_int_mask_t;
|
||||
|
||||
/**
|
||||
* @brief SPI data rates.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_SPI_FREQ_125K = SPI_FREQUENCY_FREQUENCY_K125, ///< 125 kbps.
|
||||
NRF_SPI_FREQ_250K = SPI_FREQUENCY_FREQUENCY_K250, ///< 250 kbps.
|
||||
NRF_SPI_FREQ_500K = SPI_FREQUENCY_FREQUENCY_K500, ///< 500 kbps.
|
||||
NRF_SPI_FREQ_1M = SPI_FREQUENCY_FREQUENCY_M1, ///< 1 Mbps.
|
||||
NRF_SPI_FREQ_2M = SPI_FREQUENCY_FREQUENCY_M2, ///< 2 Mbps.
|
||||
NRF_SPI_FREQ_4M = SPI_FREQUENCY_FREQUENCY_M4, ///< 4 Mbps.
|
||||
// [conversion to 'int' needed to prevent compilers from complaining
|
||||
// that the provided value (0x80000000UL) is out of range of "int"]
|
||||
NRF_SPI_FREQ_8M = (int)SPI_FREQUENCY_FREQUENCY_M8 ///< 8 Mbps.
|
||||
} nrf_spi_frequency_t;
|
||||
|
||||
/**
|
||||
* @brief SPI modes.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_SPI_MODE_0, ///< SCK active high, sample on leading edge of clock.
|
||||
NRF_SPI_MODE_1, ///< SCK active high, sample on trailing edge of clock.
|
||||
NRF_SPI_MODE_2, ///< SCK active low, sample on leading edge of clock.
|
||||
NRF_SPI_MODE_3 ///< SCK active low, sample on trailing edge of clock.
|
||||
} nrf_spi_mode_t;
|
||||
|
||||
/**
|
||||
* @brief SPI bit orders.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_SPI_BIT_ORDER_MSB_FIRST = SPI_CONFIG_ORDER_MsbFirst, ///< Most significant bit shifted out first.
|
||||
NRF_SPI_BIT_ORDER_LSB_FIRST = SPI_CONFIG_ORDER_LsbFirst ///< Least significant bit shifted out first.
|
||||
} nrf_spi_bit_order_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a specific SPI event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spi_event Event to clear.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spi_event_clear(NRF_SPI_Type * p_reg,
|
||||
nrf_spi_event_t spi_event);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the state of a specific SPI event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spi_event Event to check.
|
||||
*
|
||||
* @retval true If the event is set.
|
||||
* @retval false If the event is not set.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_spi_event_check(NRF_SPI_Type * p_reg,
|
||||
nrf_spi_event_t spi_event);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific SPI event register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spi_event Requested event.
|
||||
*
|
||||
* @return Address of the specified event register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_spi_event_address_get(NRF_SPI_Type * p_reg,
|
||||
nrf_spi_event_t spi_event);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling specified interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spi_int_mask Interrupts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spi_int_enable(NRF_SPI_Type * p_reg,
|
||||
uint32_t spi_int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling specified interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spi_int_mask Interrupts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spi_int_disable(NRF_SPI_Type * p_reg,
|
||||
uint32_t spi_int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of a given interrupt.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spi_int Interrupt to check.
|
||||
*
|
||||
* @retval true If the interrupt is enabled.
|
||||
* @retval false If the interrupt is not enabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_spi_int_enable_check(NRF_SPI_Type * p_reg,
|
||||
nrf_spi_int_mask_t spi_int);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling the SPI peripheral.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spi_enable(NRF_SPI_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling the SPI peripheral.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spi_disable(NRF_SPI_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for configuring SPI pins.
|
||||
*
|
||||
* If a given signal is not needed, pass the @ref NRF_SPI_PIN_NOT_CONNECTED
|
||||
* value instead of its pin number.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] sck_pin SCK pin number.
|
||||
* @param[in] mosi_pin MOSI pin number.
|
||||
* @param[in] miso_pin MISO pin number.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spi_pins_set(NRF_SPI_Type * p_reg,
|
||||
uint32_t sck_pin,
|
||||
uint32_t mosi_pin,
|
||||
uint32_t miso_pin);
|
||||
|
||||
/**
|
||||
* @brief Function for writing data to the SPI transmitter register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] data TX data to send.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spi_txd_set(NRF_SPI_Type * p_reg, uint8_t data);
|
||||
|
||||
/**
|
||||
* @brief Function for reading data from the SPI receiver register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*
|
||||
* @return RX data received.
|
||||
*/
|
||||
__STATIC_INLINE uint8_t nrf_spi_rxd_get(NRF_SPI_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the SPI master data rate.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] frequency SPI frequency.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spi_frequency_set(NRF_SPI_Type * p_reg,
|
||||
nrf_spi_frequency_t frequency);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the SPI configuration.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spi_mode SPI mode.
|
||||
* @param[in] spi_bit_order SPI bit order.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spi_configure(NRF_SPI_Type * p_reg,
|
||||
nrf_spi_mode_t spi_mode,
|
||||
nrf_spi_bit_order_t spi_bit_order);
|
||||
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
__STATIC_INLINE void nrf_spi_event_clear(NRF_SPI_Type * p_reg,
|
||||
nrf_spi_event_t spi_event)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)spi_event)) = 0x0UL;
|
||||
#if __CORTEX_M == 0x04
|
||||
volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)spi_event));
|
||||
(void)dummy;
|
||||
#endif
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_spi_event_check(NRF_SPI_Type * p_reg,
|
||||
nrf_spi_event_t spi_event)
|
||||
{
|
||||
return (bool)*(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)spi_event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_spi_event_address_get(NRF_SPI_Type * p_reg,
|
||||
nrf_spi_event_t spi_event)
|
||||
{
|
||||
return (uint32_t *)((uint8_t *)p_reg + (uint32_t)spi_event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spi_int_enable(NRF_SPI_Type * p_reg,
|
||||
uint32_t spi_int_mask)
|
||||
{
|
||||
p_reg->INTENSET = spi_int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spi_int_disable(NRF_SPI_Type * p_reg,
|
||||
uint32_t spi_int_mask)
|
||||
{
|
||||
p_reg->INTENCLR = spi_int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_spi_int_enable_check(NRF_SPI_Type * p_reg,
|
||||
nrf_spi_int_mask_t spi_int)
|
||||
{
|
||||
return (bool)(p_reg->INTENSET & spi_int);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spi_enable(NRF_SPI_Type * p_reg)
|
||||
{
|
||||
p_reg->ENABLE = (SPI_ENABLE_ENABLE_Enabled << SPI_ENABLE_ENABLE_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spi_disable(NRF_SPI_Type * p_reg)
|
||||
{
|
||||
p_reg->ENABLE = (SPI_ENABLE_ENABLE_Disabled << SPI_ENABLE_ENABLE_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spi_pins_set(NRF_SPI_Type * p_reg,
|
||||
uint32_t sck_pin,
|
||||
uint32_t mosi_pin,
|
||||
uint32_t miso_pin)
|
||||
{
|
||||
p_reg->PSELSCK = sck_pin;
|
||||
p_reg->PSELMOSI = mosi_pin;
|
||||
p_reg->PSELMISO = miso_pin;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spi_txd_set(NRF_SPI_Type * p_reg, uint8_t data)
|
||||
{
|
||||
p_reg->TXD = data;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint8_t nrf_spi_rxd_get(NRF_SPI_Type * p_reg)
|
||||
{
|
||||
return p_reg->RXD;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spi_frequency_set(NRF_SPI_Type * p_reg,
|
||||
nrf_spi_frequency_t frequency)
|
||||
{
|
||||
p_reg->FREQUENCY = frequency;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spi_configure(NRF_SPI_Type * p_reg,
|
||||
nrf_spi_mode_t spi_mode,
|
||||
nrf_spi_bit_order_t spi_bit_order)
|
||||
{
|
||||
uint32_t config = (spi_bit_order == NRF_SPI_BIT_ORDER_MSB_FIRST ?
|
||||
SPI_CONFIG_ORDER_MsbFirst : SPI_CONFIG_ORDER_LsbFirst);
|
||||
switch (spi_mode)
|
||||
{
|
||||
default:
|
||||
case NRF_SPI_MODE_0:
|
||||
config |= (SPI_CONFIG_CPOL_ActiveHigh << SPI_CONFIG_CPOL_Pos) |
|
||||
(SPI_CONFIG_CPHA_Leading << SPI_CONFIG_CPHA_Pos);
|
||||
break;
|
||||
|
||||
case NRF_SPI_MODE_1:
|
||||
config |= (SPI_CONFIG_CPOL_ActiveHigh << SPI_CONFIG_CPOL_Pos) |
|
||||
(SPI_CONFIG_CPHA_Trailing << SPI_CONFIG_CPHA_Pos);
|
||||
break;
|
||||
|
||||
case NRF_SPI_MODE_2:
|
||||
config |= (SPI_CONFIG_CPOL_ActiveLow << SPI_CONFIG_CPOL_Pos) |
|
||||
(SPI_CONFIG_CPHA_Leading << SPI_CONFIG_CPHA_Pos);
|
||||
break;
|
||||
|
||||
case NRF_SPI_MODE_3:
|
||||
config |= (SPI_CONFIG_CPOL_ActiveLow << SPI_CONFIG_CPOL_Pos) |
|
||||
(SPI_CONFIG_CPHA_Trailing << SPI_CONFIG_CPHA_Pos);
|
||||
break;
|
||||
}
|
||||
p_reg->CONFIG = config;
|
||||
}
|
||||
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_SPI_H__
|
||||
@@ -0,0 +1,727 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_SPIM_H__
|
||||
#define NRF_SPIM_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_spim_hal SPIM HAL
|
||||
* @{
|
||||
* @ingroup nrf_spim
|
||||
* @brief Hardware access layer for managing the SPIM peripheral.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This value can be used as a parameter for the @ref nrf_spim_pins_set
|
||||
* function to specify that a given SPI signal (SCK, MOSI, or MISO)
|
||||
* shall not be connected to a physical pin.
|
||||
*/
|
||||
#define NRF_SPIM_PIN_NOT_CONNECTED 0xFFFFFFFF
|
||||
|
||||
#if defined(SPIM_DCXCNT_DCXCNT_Msk) || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief This value specified in the DCX line configuration causes this line
|
||||
* to be set low during whole transmission (all transmitted bytes are
|
||||
* marked as command bytes). Any lower value causes the DCX line to be
|
||||
* switched from low to high after this number of bytes is transmitted
|
||||
* (all remaining bytes are marked as data bytes).
|
||||
*/
|
||||
#define NRF_SPIM_DCX_CNT_ALL_CMD 0xF
|
||||
#endif
|
||||
|
||||
#define NRF_SPIM_HW_CSN_PRESENT \
|
||||
(NRFX_CHECK(SPIM0_FEATURE_HARDWARE_CSN_PRESENT) || \
|
||||
NRFX_CHECK(SPIM1_FEATURE_HARDWARE_CSN_PRESENT) || \
|
||||
NRFX_CHECK(SPIM2_FEATURE_HARDWARE_CSN_PRESENT) || \
|
||||
NRFX_CHECK(SPIM3_FEATURE_HARDWARE_CSN_PRESENT))
|
||||
|
||||
/**
|
||||
* @brief SPIM tasks.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
NRF_SPIM_TASK_START = offsetof(NRF_SPIM_Type, TASKS_START), ///< Start SPI transaction.
|
||||
NRF_SPIM_TASK_STOP = offsetof(NRF_SPIM_Type, TASKS_STOP), ///< Stop SPI transaction.
|
||||
NRF_SPIM_TASK_SUSPEND = offsetof(NRF_SPIM_Type, TASKS_SUSPEND), ///< Suspend SPI transaction.
|
||||
NRF_SPIM_TASK_RESUME = offsetof(NRF_SPIM_Type, TASKS_RESUME) ///< Resume SPI transaction.
|
||||
/*lint -restore*/
|
||||
} nrf_spim_task_t;
|
||||
|
||||
/**
|
||||
* @brief SPIM events.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
NRF_SPIM_EVENT_STOPPED = offsetof(NRF_SPIM_Type, EVENTS_STOPPED), ///< SPI transaction has stopped.
|
||||
NRF_SPIM_EVENT_ENDRX = offsetof(NRF_SPIM_Type, EVENTS_ENDRX), ///< End of RXD buffer reached.
|
||||
NRF_SPIM_EVENT_END = offsetof(NRF_SPIM_Type, EVENTS_END), ///< End of RXD buffer and TXD buffer reached.
|
||||
NRF_SPIM_EVENT_ENDTX = offsetof(NRF_SPIM_Type, EVENTS_ENDTX), ///< End of TXD buffer reached.
|
||||
NRF_SPIM_EVENT_STARTED = offsetof(NRF_SPIM_Type, EVENTS_STARTED) ///< Transaction started.
|
||||
/*lint -restore*/
|
||||
} nrf_spim_event_t;
|
||||
|
||||
/**
|
||||
* @brief SPIM shortcuts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_SPIM_SHORT_END_START_MASK = SPIM_SHORTS_END_START_Msk, ///< Shortcut between END event and START task.
|
||||
NRF_SPIM_ALL_SHORTS_MASK = SPIM_SHORTS_END_START_Msk ///< All SPIM shortcuts.
|
||||
} nrf_spim_short_mask_t;
|
||||
|
||||
/**
|
||||
* @brief SPIM interrupts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_SPIM_INT_STOPPED_MASK = SPIM_INTENSET_STOPPED_Msk, ///< Interrupt on STOPPED event.
|
||||
NRF_SPIM_INT_ENDRX_MASK = SPIM_INTENSET_ENDRX_Msk, ///< Interrupt on ENDRX event.
|
||||
NRF_SPIM_INT_END_MASK = SPIM_INTENSET_END_Msk, ///< Interrupt on END event.
|
||||
NRF_SPIM_INT_ENDTX_MASK = SPIM_INTENSET_ENDTX_Msk, ///< Interrupt on ENDTX event.
|
||||
NRF_SPIM_INT_STARTED_MASK = SPIM_INTENSET_STARTED_Msk, ///< Interrupt on STARTED event.
|
||||
NRF_SPIM_ALL_INTS_MASK = SPIM_INTENSET_STOPPED_Msk |
|
||||
SPIM_INTENSET_ENDRX_Msk |
|
||||
SPIM_INTENSET_END_Msk |
|
||||
SPIM_INTENSET_ENDTX_Msk |
|
||||
SPIM_INTENSET_STARTED_Msk ///< All SPIM interrupts.
|
||||
} nrf_spim_int_mask_t;
|
||||
|
||||
/**
|
||||
* @brief SPI master data rates.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_SPIM_FREQ_125K = SPIM_FREQUENCY_FREQUENCY_K125, ///< 125 kbps.
|
||||
NRF_SPIM_FREQ_250K = SPIM_FREQUENCY_FREQUENCY_K250, ///< 250 kbps.
|
||||
NRF_SPIM_FREQ_500K = SPIM_FREQUENCY_FREQUENCY_K500, ///< 500 kbps.
|
||||
NRF_SPIM_FREQ_1M = SPIM_FREQUENCY_FREQUENCY_M1, ///< 1 Mbps.
|
||||
NRF_SPIM_FREQ_2M = SPIM_FREQUENCY_FREQUENCY_M2, ///< 2 Mbps.
|
||||
NRF_SPIM_FREQ_4M = SPIM_FREQUENCY_FREQUENCY_M4, ///< 4 Mbps.
|
||||
// [conversion to 'int' needed to prevent compilers from complaining
|
||||
// that the provided value (0x80000000UL) is out of range of "int"]
|
||||
NRF_SPIM_FREQ_8M = (int)SPIM_FREQUENCY_FREQUENCY_M8, ///< 8 Mbps.
|
||||
#if defined(SPIM_FREQUENCY_FREQUENCY_M16) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_SPIM_FREQ_16M = SPIM_FREQUENCY_FREQUENCY_M16, ///< 16 Mbps.
|
||||
#endif
|
||||
#if defined(SPIM_FREQUENCY_FREQUENCY_M32) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_SPIM_FREQ_32M = SPIM_FREQUENCY_FREQUENCY_M32 ///< 32 Mbps.
|
||||
#endif
|
||||
} nrf_spim_frequency_t;
|
||||
|
||||
/**
|
||||
* @brief SPI modes.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_SPIM_MODE_0, ///< SCK active high, sample on leading edge of clock.
|
||||
NRF_SPIM_MODE_1, ///< SCK active high, sample on trailing edge of clock.
|
||||
NRF_SPIM_MODE_2, ///< SCK active low, sample on leading edge of clock.
|
||||
NRF_SPIM_MODE_3 ///< SCK active low, sample on trailing edge of clock.
|
||||
} nrf_spim_mode_t;
|
||||
|
||||
/**
|
||||
* @brief SPI bit orders.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_SPIM_BIT_ORDER_MSB_FIRST = SPIM_CONFIG_ORDER_MsbFirst, ///< Most significant bit shifted out first.
|
||||
NRF_SPIM_BIT_ORDER_LSB_FIRST = SPIM_CONFIG_ORDER_LsbFirst ///< Least significant bit shifted out first.
|
||||
} nrf_spim_bit_order_t;
|
||||
|
||||
#if (NRF_SPIM_HW_CSN_PRESENT) || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief SPI CSN pin polarity.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_SPIM_CSN_POL_LOW = SPIM_CSNPOL_CSNPOL_LOW, ///< Active low (idle state high).
|
||||
NRF_SPIM_CSN_POL_HIGH = SPIM_CSNPOL_CSNPOL_HIGH ///< Active high (idle state low).
|
||||
} nrf_spim_csn_pol_t;
|
||||
#endif // (NRF_SPIM_HW_CSN_PRESENT) || defined(__NRFX_DOXYGEN__)
|
||||
|
||||
/**
|
||||
* @brief Function for activating a specific SPIM task.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spim_task Task to activate.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_task_trigger(NRF_SPIM_Type * p_reg,
|
||||
nrf_spim_task_t spim_task);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific SPIM task register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spim_task Requested task.
|
||||
*
|
||||
* @return Address of the specified task register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_spim_task_address_get(NRF_SPIM_Type * p_reg,
|
||||
nrf_spim_task_t spim_task);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a specific SPIM event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spim_event Event to clear.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_event_clear(NRF_SPIM_Type * p_reg,
|
||||
nrf_spim_event_t spim_event);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the state of a specific SPIM event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spim_event Event to check.
|
||||
*
|
||||
* @retval true If the event is set.
|
||||
* @retval false If the event is not set.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_spim_event_check(NRF_SPIM_Type * p_reg,
|
||||
nrf_spim_event_t spim_event);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific SPIM event register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spim_event Requested event.
|
||||
*
|
||||
* @return Address of the specified event register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_spim_event_address_get(NRF_SPIM_Type * p_reg,
|
||||
nrf_spim_event_t spim_event);
|
||||
/**
|
||||
* @brief Function for enabling specified shortcuts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spim_shorts_mask Shortcuts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_shorts_enable(NRF_SPIM_Type * p_reg,
|
||||
uint32_t spim_shorts_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling specified shortcuts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spim_shorts_mask Shortcuts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_shorts_disable(NRF_SPIM_Type * p_reg,
|
||||
uint32_t spim_shorts_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for getting shorts setting.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_spim_shorts_get(NRF_SPIM_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling specified interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spim_int_mask Interrupts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_int_enable(NRF_SPIM_Type * p_reg,
|
||||
uint32_t spim_int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling specified interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spim_int_mask Interrupts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_int_disable(NRF_SPIM_Type * p_reg,
|
||||
uint32_t spim_int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of a given interrupt.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spim_int Interrupt to check.
|
||||
*
|
||||
* @retval true If the interrupt is enabled.
|
||||
* @retval false If the interrupt is not enabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_spim_int_enable_check(NRF_SPIM_Type * p_reg,
|
||||
nrf_spim_int_mask_t spim_int);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling the SPIM peripheral.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_enable(NRF_SPIM_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling the SPIM peripheral.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_disable(NRF_SPIM_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for configuring SPIM pins.
|
||||
*
|
||||
* If a given signal is not needed, pass the @ref NRF_SPIM_PIN_NOT_CONNECTED
|
||||
* value instead of its pin number.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] sck_pin SCK pin number.
|
||||
* @param[in] mosi_pin MOSI pin number.
|
||||
* @param[in] miso_pin MISO pin number.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_pins_set(NRF_SPIM_Type * p_reg,
|
||||
uint32_t sck_pin,
|
||||
uint32_t mosi_pin,
|
||||
uint32_t miso_pin);
|
||||
|
||||
#if (NRF_SPIM_HW_CSN_PRESENT) || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Function for configuring the SPIM hardware CSN pin.
|
||||
*
|
||||
* If this signal is not needed, pass the @ref NRF_SPIM_PIN_NOT_CONNECTED
|
||||
* value instead of its pin number.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] pin CSN pin number.
|
||||
* @param[in] polarity CSN pin polarity.
|
||||
* @param[in] duration Minimum duration between the edge of CSN and the edge of SCK
|
||||
* and minimum duration of CSN must stay unselected between transactions.
|
||||
* The value is specified in number of 64 MHz clock cycles (15.625 ns).
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_csn_configure(NRF_SPIM_Type * p_reg,
|
||||
uint32_t pin,
|
||||
nrf_spim_csn_pol_t polarity,
|
||||
uint32_t duration);
|
||||
#endif // (NRF_SPIM_HW_CSN_PRESENT) || defined(__NRFX_DOXYGEN__)
|
||||
|
||||
#if defined(SPIM_PSELDCX_CONNECT_Msk) || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Function for configuring the SPIM DCX pin.
|
||||
*
|
||||
* If this signal is not needed, pass the @ref NRF_SPIM_PIN_NOT_CONNECTED
|
||||
* value instead of its pin number.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] dcx_pin DCX pin number.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_dcx_pin_set(NRF_SPIM_Type * p_reg,
|
||||
uint32_t dcx_pin);
|
||||
|
||||
/**
|
||||
* @brief Function for configuring the number of command bytes.
|
||||
*
|
||||
* Maximum value available for dividing the transmitted bytes into command
|
||||
* bytes and data bytes is @ref NRF_SPIM_DCX_CNT_ALL_CMD - 1.
|
||||
* The @ref NRF_SPIM_DCX_CNT_ALL_CMD value passed as the @c count parameter
|
||||
* causes all transmitted bytes to be marked as command bytes.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] count Number of command bytes preceding the data bytes.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_dcx_cnt_set(NRF_SPIM_Type * p_reg,
|
||||
uint32_t count);
|
||||
#endif // defined(SPIM_PSELDCX_CONNECT_Msk) || defined(__NRFX_DOXYGEN__)
|
||||
|
||||
#if defined(SPIM_IFTIMING_RXDELAY_RXDELAY_Msk) || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Function for configuring the extended SPIM interface.
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param rxdelay Sample delay for input serial data on MISO,
|
||||
* specified in 64 MHz clock cycles (15.625 ns) from the sampling edge of SCK.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_iftiming_set(NRF_SPIM_Type * p_reg,
|
||||
uint32_t rxdelay);
|
||||
#endif // defined(SPIM_IFTIMING_RXDELAY_RXDELAY_Msk) || defined(__NRFX_DOXYGEN__)
|
||||
|
||||
#if defined(SPIM_STALLSTAT_RX_Msk) || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Function for clearing stall status for RX EasyDMA RAM accesses.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_stallstat_rx_clear(NRF_SPIM_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for getting stall status for RX EasyDMA RAM accesses.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*
|
||||
* @return Stall status of RX EasyDMA RAM accesses.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_spim_stallstat_rx_get(NRF_SPIM_Type * p_reg);
|
||||
#endif // defined(SPIM_STALLSTAT_RX_Msk) || defined(__NRFX_DOXYGEN__)
|
||||
|
||||
#if defined(SPIM_STALLSTAT_TX_Msk) || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Function for clearing stall status for TX EasyDMA RAM accesses.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_stallstat_tx_clear(NRF_SPIM_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for getting stall status for TX EasyDMA RAM accesses.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*
|
||||
* @return Stall status of TX EasyDMA RAM accesses.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_spim_stallstat_tx_get(NRF_SPIM_Type * p_reg);
|
||||
#endif // defined(SPIM_STALLSTAT_TX_Msk) || defined(__NRFX_DOXYGEN__)
|
||||
|
||||
/**
|
||||
* @brief Function for setting the SPI master data rate.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] frequency SPI frequency.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_frequency_set(NRF_SPIM_Type * p_reg,
|
||||
nrf_spim_frequency_t frequency);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the transmit buffer.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] p_buffer Pointer to the buffer with data to send.
|
||||
* @param[in] length Maximum number of data bytes to transmit.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_tx_buffer_set(NRF_SPIM_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 peripheral registers structure.
|
||||
* @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_spim_rx_buffer_set(NRF_SPIM_Type * p_reg,
|
||||
uint8_t * p_buffer,
|
||||
size_t length);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the SPI configuration.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spi_mode SPI mode.
|
||||
* @param[in] spi_bit_order SPI bit order.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_configure(NRF_SPIM_Type * p_reg,
|
||||
nrf_spim_mode_t spi_mode,
|
||||
nrf_spim_bit_order_t spi_bit_order);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the over-read character.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] orc Over-read character that is clocked out in case of
|
||||
* an over-read of the TXD buffer.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_orc_set(NRF_SPIM_Type * p_reg,
|
||||
uint8_t orc);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling the TX list feature.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_tx_list_enable(NRF_SPIM_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling the TX list feature.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_tx_list_disable(NRF_SPIM_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling the RX list feature.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_rx_list_enable(NRF_SPIM_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling the RX list feature.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spim_rx_list_disable(NRF_SPIM_Type * p_reg);
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
__STATIC_INLINE void nrf_spim_task_trigger(NRF_SPIM_Type * p_reg,
|
||||
nrf_spim_task_t spim_task)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)spim_task)) = 0x1UL;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_spim_task_address_get(NRF_SPIM_Type * p_reg,
|
||||
nrf_spim_task_t spim_task)
|
||||
{
|
||||
return (uint32_t)((uint8_t *)p_reg + (uint32_t)spim_task);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spim_event_clear(NRF_SPIM_Type * p_reg,
|
||||
nrf_spim_event_t spim_event)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)spim_event)) = 0x0UL;
|
||||
#if __CORTEX_M == 0x04
|
||||
volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)spim_event));
|
||||
(void)dummy;
|
||||
#endif
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_spim_event_check(NRF_SPIM_Type * p_reg,
|
||||
nrf_spim_event_t spim_event)
|
||||
{
|
||||
return (bool)*(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)spim_event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_spim_event_address_get(NRF_SPIM_Type * p_reg,
|
||||
nrf_spim_event_t spim_event)
|
||||
{
|
||||
return (uint32_t)((uint8_t *)p_reg + (uint32_t)spim_event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spim_shorts_enable(NRF_SPIM_Type * p_reg,
|
||||
uint32_t spim_shorts_mask)
|
||||
{
|
||||
p_reg->SHORTS |= spim_shorts_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spim_shorts_disable(NRF_SPIM_Type * p_reg,
|
||||
uint32_t spim_shorts_mask)
|
||||
{
|
||||
p_reg->SHORTS &= ~(spim_shorts_mask);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_spim_shorts_get(NRF_SPIM_Type * p_reg)
|
||||
{
|
||||
return p_reg->SHORTS;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spim_int_enable(NRF_SPIM_Type * p_reg,
|
||||
uint32_t spim_int_mask)
|
||||
{
|
||||
p_reg->INTENSET = spim_int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spim_int_disable(NRF_SPIM_Type * p_reg,
|
||||
uint32_t spim_int_mask)
|
||||
{
|
||||
p_reg->INTENCLR = spim_int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_spim_int_enable_check(NRF_SPIM_Type * p_reg,
|
||||
nrf_spim_int_mask_t spim_int)
|
||||
{
|
||||
return (bool)(p_reg->INTENSET & spim_int);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spim_enable(NRF_SPIM_Type * p_reg)
|
||||
{
|
||||
p_reg->ENABLE = (SPIM_ENABLE_ENABLE_Enabled << SPIM_ENABLE_ENABLE_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spim_disable(NRF_SPIM_Type * p_reg)
|
||||
{
|
||||
p_reg->ENABLE = (SPIM_ENABLE_ENABLE_Disabled << SPIM_ENABLE_ENABLE_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spim_pins_set(NRF_SPIM_Type * p_reg,
|
||||
uint32_t sck_pin,
|
||||
uint32_t mosi_pin,
|
||||
uint32_t miso_pin)
|
||||
{
|
||||
p_reg->PSEL.SCK = sck_pin;
|
||||
p_reg->PSEL.MOSI = mosi_pin;
|
||||
p_reg->PSEL.MISO = miso_pin;
|
||||
}
|
||||
|
||||
#if (NRF_SPIM_HW_CSN_PRESENT)
|
||||
__STATIC_INLINE void nrf_spim_csn_configure(NRF_SPIM_Type * p_reg,
|
||||
uint32_t pin,
|
||||
nrf_spim_csn_pol_t polarity,
|
||||
uint32_t duration)
|
||||
{
|
||||
p_reg->PSEL.CSN = pin;
|
||||
p_reg->CSNPOL = polarity;
|
||||
p_reg->IFTIMING.CSNDUR = duration;
|
||||
}
|
||||
#endif // defined(NRF_SPIM_HW_CSN_PRESENT)
|
||||
|
||||
#if defined(SPIM_PSELDCX_CONNECT_Msk)
|
||||
__STATIC_INLINE void nrf_spim_dcx_pin_set(NRF_SPIM_Type * p_reg,
|
||||
uint32_t dcx_pin)
|
||||
{
|
||||
p_reg->PSELDCX = dcx_pin;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spim_dcx_cnt_set(NRF_SPIM_Type * p_reg,
|
||||
uint32_t dcx_cnt)
|
||||
{
|
||||
p_reg->DCXCNT = dcx_cnt;
|
||||
}
|
||||
#endif // defined(SPIM_PSELDCX_CONNECT_Msk)
|
||||
|
||||
#if defined(SPIM_IFTIMING_RXDELAY_RXDELAY_Msk)
|
||||
__STATIC_INLINE void nrf_spim_iftiming_set(NRF_SPIM_Type * p_reg,
|
||||
uint32_t rxdelay)
|
||||
{
|
||||
p_reg->IFTIMING.RXDELAY = rxdelay;
|
||||
}
|
||||
#endif // defined(SPIM_IFTIMING_RXDELAY_RXDELAY_Msk)
|
||||
|
||||
#if defined(SPIM_STALLSTAT_RX_Msk)
|
||||
__STATIC_INLINE void nrf_spim_stallstat_rx_clear(NRF_SPIM_Type * p_reg)
|
||||
{
|
||||
p_reg->STALLSTAT &= ~(SPIM_STALLSTAT_RX_Msk);
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_spim_stallstat_rx_get(NRF_SPIM_Type * p_reg)
|
||||
{
|
||||
return (p_reg->STALLSTAT & SPIM_STALLSTAT_RX_Msk) != 0;
|
||||
}
|
||||
#endif // defined(SPIM_STALLSTAT_RX_Msk)
|
||||
|
||||
#if defined(SPIM_STALLSTAT_TX_Msk)
|
||||
__STATIC_INLINE void nrf_spim_stallstat_tx_clear(NRF_SPIM_Type * p_reg)
|
||||
{
|
||||
p_reg->STALLSTAT &= ~(SPIM_STALLSTAT_TX_Msk);
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_spim_stallstat_tx_get(NRF_SPIM_Type * p_reg)
|
||||
{
|
||||
return (p_reg->STALLSTAT & SPIM_STALLSTAT_TX_Msk) != 0;
|
||||
}
|
||||
#endif // defined(SPIM_STALLSTAT_TX_Msk)
|
||||
|
||||
__STATIC_INLINE void nrf_spim_frequency_set(NRF_SPIM_Type * p_reg,
|
||||
nrf_spim_frequency_t frequency)
|
||||
{
|
||||
p_reg->FREQUENCY = frequency;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spim_tx_buffer_set(NRF_SPIM_Type * p_reg,
|
||||
uint8_t const * p_buffer,
|
||||
size_t length)
|
||||
{
|
||||
p_reg->TXD.PTR = (uint32_t)p_buffer;
|
||||
p_reg->TXD.MAXCNT = length;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spim_rx_buffer_set(NRF_SPIM_Type * p_reg,
|
||||
uint8_t * p_buffer,
|
||||
size_t length)
|
||||
{
|
||||
p_reg->RXD.PTR = (uint32_t)p_buffer;
|
||||
p_reg->RXD.MAXCNT = length;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spim_configure(NRF_SPIM_Type * p_reg,
|
||||
nrf_spim_mode_t spi_mode,
|
||||
nrf_spim_bit_order_t spi_bit_order)
|
||||
{
|
||||
uint32_t config = (spi_bit_order == NRF_SPIM_BIT_ORDER_MSB_FIRST ?
|
||||
SPIM_CONFIG_ORDER_MsbFirst : SPIM_CONFIG_ORDER_LsbFirst);
|
||||
switch (spi_mode)
|
||||
{
|
||||
default:
|
||||
case NRF_SPIM_MODE_0:
|
||||
config |= (SPIM_CONFIG_CPOL_ActiveHigh << SPIM_CONFIG_CPOL_Pos) |
|
||||
(SPIM_CONFIG_CPHA_Leading << SPIM_CONFIG_CPHA_Pos);
|
||||
break;
|
||||
|
||||
case NRF_SPIM_MODE_1:
|
||||
config |= (SPIM_CONFIG_CPOL_ActiveHigh << SPIM_CONFIG_CPOL_Pos) |
|
||||
(SPIM_CONFIG_CPHA_Trailing << SPIM_CONFIG_CPHA_Pos);
|
||||
break;
|
||||
|
||||
case NRF_SPIM_MODE_2:
|
||||
config |= (SPIM_CONFIG_CPOL_ActiveLow << SPIM_CONFIG_CPOL_Pos) |
|
||||
(SPIM_CONFIG_CPHA_Leading << SPIM_CONFIG_CPHA_Pos);
|
||||
break;
|
||||
|
||||
case NRF_SPIM_MODE_3:
|
||||
config |= (SPIM_CONFIG_CPOL_ActiveLow << SPIM_CONFIG_CPOL_Pos) |
|
||||
(SPIM_CONFIG_CPHA_Trailing << SPIM_CONFIG_CPHA_Pos);
|
||||
break;
|
||||
}
|
||||
p_reg->CONFIG = config;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spim_orc_set(NRF_SPIM_Type * p_reg,
|
||||
uint8_t orc)
|
||||
{
|
||||
p_reg->ORC = orc;
|
||||
}
|
||||
|
||||
|
||||
__STATIC_INLINE void nrf_spim_tx_list_enable(NRF_SPIM_Type * p_reg)
|
||||
{
|
||||
p_reg->TXD.LIST = 1;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spim_tx_list_disable(NRF_SPIM_Type * p_reg)
|
||||
{
|
||||
p_reg->TXD.LIST = 0;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spim_rx_list_enable(NRF_SPIM_Type * p_reg)
|
||||
{
|
||||
p_reg->RXD.LIST = 1;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spim_rx_list_disable(NRF_SPIM_Type * p_reg)
|
||||
{
|
||||
p_reg->RXD.LIST = 0;
|
||||
}
|
||||
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_SPIM_H__
|
||||
@@ -0,0 +1,562 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 <nrfx.h>
|
||||
|
||||
#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
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
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.
|
||||
/*lint -restore*/
|
||||
} nrf_spis_task_t;
|
||||
|
||||
/**
|
||||
* @brief SPIS events.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
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.
|
||||
/*lint -restore*/
|
||||
} 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 a specific SPIS task.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spis_task Task to activate.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spis_task_trigger(NRF_SPIS_Type * p_reg,
|
||||
nrf_spis_task_t spis_task);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific SPIS task register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spis_task Requested 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 spis_task);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a specific SPIS event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spis_event Event to clear.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spis_event_clear(NRF_SPIS_Type * p_reg,
|
||||
nrf_spis_event_t spis_event);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the state of a specific SPIS event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spis_event Event to check.
|
||||
*
|
||||
* @retval true If the event is set.
|
||||
* @retval false If the event is not set.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_spis_event_check(NRF_SPIS_Type const * p_reg,
|
||||
nrf_spis_event_t spis_event);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific SPIS event register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spis_event Requested 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 spis_event);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling specified shortcuts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spis_shorts_mask Shortcuts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spis_shorts_enable(NRF_SPIS_Type * p_reg,
|
||||
uint32_t spis_shorts_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling specified shortcuts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spis_shorts_mask Shortcuts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spis_shorts_disable(NRF_SPIS_Type * p_reg,
|
||||
uint32_t spis_shorts_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling specified interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spis_int_mask Interrupts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spis_int_enable(NRF_SPIS_Type * p_reg,
|
||||
uint32_t spis_int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling specified interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spis_int_mask Interrupts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_spis_int_disable(NRF_SPIS_Type * p_reg,
|
||||
uint32_t spis_int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of a given interrupt.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] spis_int Interrupt to check.
|
||||
*
|
||||
* @retval true If the interrupt is enabled.
|
||||
* @retval false If 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);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling the SPIS peripheral.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__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 peripheral registers structure.
|
||||
*/
|
||||
__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 peripheral registers structure.
|
||||
*
|
||||
* @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 peripheral registers structure.
|
||||
*
|
||||
* @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 peripheral registers structure.
|
||||
* @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 peripheral registers structure.
|
||||
* @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 peripheral registers structure.
|
||||
* @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 peripheral registers structure.
|
||||
*
|
||||
* @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 peripheral registers structure.
|
||||
*
|
||||
* @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 peripheral registers structure.
|
||||
* @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 peripheral registers structure.
|
||||
* @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 peripheral registers structure.
|
||||
* @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 spis_task)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)spis_task)) = 0x1UL;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_spis_task_address_get(NRF_SPIS_Type const * p_reg,
|
||||
nrf_spis_task_t spis_task)
|
||||
{
|
||||
return (uint32_t)p_reg + (uint32_t)spis_task;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spis_event_clear(NRF_SPIS_Type * p_reg,
|
||||
nrf_spis_event_t spis_event)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)spis_event)) = 0x0UL;
|
||||
#if __CORTEX_M == 0x04
|
||||
volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)spis_event));
|
||||
(void)dummy;
|
||||
#endif
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_spis_event_check(NRF_SPIS_Type const * p_reg,
|
||||
nrf_spis_event_t spis_event)
|
||||
{
|
||||
return (bool)*(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)spis_event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_spis_event_address_get(NRF_SPIS_Type const * p_reg,
|
||||
nrf_spis_event_t spis_event)
|
||||
{
|
||||
return (uint32_t)p_reg + (uint32_t)spis_event;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spis_shorts_enable(NRF_SPIS_Type * p_reg,
|
||||
uint32_t spis_shorts_mask)
|
||||
{
|
||||
p_reg->SHORTS |= spis_shorts_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spis_shorts_disable(NRF_SPIS_Type * p_reg,
|
||||
uint32_t spis_shorts_mask)
|
||||
{
|
||||
p_reg->SHORTS &= ~(spis_shorts_mask);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spis_int_enable(NRF_SPIS_Type * p_reg,
|
||||
uint32_t spis_int_mask)
|
||||
{
|
||||
p_reg->INTENSET = spis_int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_spis_int_disable(NRF_SPIS_Type * p_reg,
|
||||
uint32_t spis_int_mask)
|
||||
{
|
||||
p_reg->INTENCLR = spis_int_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);
|
||||
}
|
||||
|
||||
__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__
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_systick_hal SYSTICK HAL
|
||||
* @{
|
||||
* @ingroup nrf_systick
|
||||
* @brief Hardware access layer for managing the SYSTICK peripheral.
|
||||
*
|
||||
* SYSTICK is ARM peripheral, not Nordic design.
|
||||
* It means that it has no Nordic-typical interface with Tasks and Events.
|
||||
*
|
||||
* Its usage is limited here to implement simple delays.
|
||||
* Also keep in mind that this timer would 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 Get Configuration and Status Register
|
||||
*
|
||||
* @return Values composed by @ref nrf_systick_csr_flags_t.
|
||||
* @note The @ref NRF_SYSTICK_CSR_COUNTFLAG_MASK value is cleared when CSR register is read.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_systick_csr_get(void);
|
||||
|
||||
/**
|
||||
* @brief Set 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 Get the current reload value.
|
||||
*
|
||||
* @return The reload register value.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_systick_load_get(void);
|
||||
|
||||
/**
|
||||
* @brief Configure the reload value.
|
||||
*
|
||||
* @param[in] val The value to set in the reload register.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_systick_load_set(uint32_t val);
|
||||
|
||||
/**
|
||||
* @brief Read the SysTick current value
|
||||
*
|
||||
* @return The current SysTick value
|
||||
* @sa NRF_SYSTICK_VAL_MASK
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_systick_val_get(void);
|
||||
|
||||
/**
|
||||
* @brief Clear 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 Read 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__ */
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2012 - 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_temp_hal TEMP HAL
|
||||
* @{
|
||||
* @ingroup nrf_temp temperature_example
|
||||
* @brief Temperature module init and read functions.
|
||||
*/
|
||||
|
||||
#define MASK_SIGN (0x00000200UL)
|
||||
#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);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,625 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_TIMER_H__
|
||||
#define NRF_TIMER_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_timer_hal TIMER HAL
|
||||
* @{
|
||||
* @ingroup nrf_timer
|
||||
* @brief Hardware access layer for managing the TIMER peripheral.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Macro for validating the correctness of the BIT_WIDTH setting.
|
||||
*/
|
||||
|
||||
#define TIMER_MAX_SIZE(id) NRFX_CONCAT_3(TIMER, id, _MAX_SIZE)
|
||||
|
||||
#define TIMER_BIT_WIDTH_MAX(id, bit_width) \
|
||||
(TIMER_MAX_SIZE(id) == 8 ? (bit_width == NRF_TIMER_BIT_WIDTH_8) : \
|
||||
(TIMER_MAX_SIZE(id) == 16 ? (bit_width == NRF_TIMER_BIT_WIDTH_8) || \
|
||||
(bit_width == NRF_TIMER_BIT_WIDTH_16) : \
|
||||
(TIMER_MAX_SIZE(id) == 24 ? (bit_width == NRF_TIMER_BIT_WIDTH_8) || \
|
||||
(bit_width == NRF_TIMER_BIT_WIDTH_16) || \
|
||||
(bit_width == NRF_TIMER_BIT_WIDTH_24) : \
|
||||
(TIMER_MAX_SIZE(id) == 32 ? (bit_width == NRF_TIMER_BIT_WIDTH_8) || \
|
||||
(bit_width == NRF_TIMER_BIT_WIDTH_16) || \
|
||||
(bit_width == NRF_TIMER_BIT_WIDTH_24) || \
|
||||
(bit_width == NRF_TIMER_BIT_WIDTH_32) : \
|
||||
false))))
|
||||
|
||||
#if TIMER_COUNT > 3
|
||||
#define NRF_TIMER_IS_BIT_WIDTH_VALID(p_reg, bit_width) ( \
|
||||
((p_reg == NRF_TIMER0) && (TIMER_BIT_WIDTH_MAX(0, bit_width))) \
|
||||
|| ((p_reg == NRF_TIMER1) && (TIMER_BIT_WIDTH_MAX(1, bit_width))) \
|
||||
|| ((p_reg == NRF_TIMER2) && (TIMER_BIT_WIDTH_MAX(2, bit_width))) \
|
||||
|| ((p_reg == NRF_TIMER3) && (TIMER_BIT_WIDTH_MAX(3, bit_width))) \
|
||||
|| ((p_reg == NRF_TIMER4) && (TIMER_BIT_WIDTH_MAX(4, bit_width))) )
|
||||
|
||||
#else
|
||||
#define NRF_TIMER_IS_BIT_WIDTH_VALID(p_reg, bit_width) ( \
|
||||
((p_reg == NRF_TIMER0) && TIMER_BIT_WIDTH_MAX(0, bit_width)) \
|
||||
|| ((p_reg == NRF_TIMER1) && TIMER_BIT_WIDTH_MAX(1, bit_width)) \
|
||||
|| ((p_reg == NRF_TIMER2) && TIMER_BIT_WIDTH_MAX(2, bit_width)) )
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Macro for getting the number of capture/compare channels available
|
||||
* in a given timer instance.
|
||||
*/
|
||||
#define NRF_TIMER_CC_CHANNEL_COUNT(id) NRFX_CONCAT_3(TIMER, id, _CC_NUM)
|
||||
|
||||
/**
|
||||
* @brief Timer tasks.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30 -esym(628,__INTADDR__)*/
|
||||
NRF_TIMER_TASK_START = offsetof(NRF_TIMER_Type, TASKS_START), ///< Task for starting the timer.
|
||||
NRF_TIMER_TASK_STOP = offsetof(NRF_TIMER_Type, TASKS_STOP), ///< Task for stopping the timer.
|
||||
NRF_TIMER_TASK_COUNT = offsetof(NRF_TIMER_Type, TASKS_COUNT), ///< Task for incrementing the timer (in counter mode).
|
||||
NRF_TIMER_TASK_CLEAR = offsetof(NRF_TIMER_Type, TASKS_CLEAR), ///< Task for resetting the timer value.
|
||||
NRF_TIMER_TASK_SHUTDOWN = offsetof(NRF_TIMER_Type, TASKS_SHUTDOWN), ///< Task for powering off the timer.
|
||||
NRF_TIMER_TASK_CAPTURE0 = offsetof(NRF_TIMER_Type, TASKS_CAPTURE[0]), ///< Task for capturing the timer value on channel 0.
|
||||
NRF_TIMER_TASK_CAPTURE1 = offsetof(NRF_TIMER_Type, TASKS_CAPTURE[1]), ///< Task for capturing the timer value on channel 1.
|
||||
NRF_TIMER_TASK_CAPTURE2 = offsetof(NRF_TIMER_Type, TASKS_CAPTURE[2]), ///< Task for capturing the timer value on channel 2.
|
||||
NRF_TIMER_TASK_CAPTURE3 = offsetof(NRF_TIMER_Type, TASKS_CAPTURE[3]), ///< Task for capturing the timer value on channel 3.
|
||||
#if defined(TIMER_INTENSET_COMPARE4_Msk) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_TIMER_TASK_CAPTURE4 = offsetof(NRF_TIMER_Type, TASKS_CAPTURE[4]), ///< Task for capturing the timer value on channel 4.
|
||||
#endif
|
||||
#if defined(TIMER_INTENSET_COMPARE5_Msk) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_TIMER_TASK_CAPTURE5 = offsetof(NRF_TIMER_Type, TASKS_CAPTURE[5]), ///< Task for capturing the timer value on channel 5.
|
||||
#endif
|
||||
/*lint -restore*/
|
||||
} nrf_timer_task_t;
|
||||
|
||||
/**
|
||||
* @brief Timer events.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
NRF_TIMER_EVENT_COMPARE0 = offsetof(NRF_TIMER_Type, EVENTS_COMPARE[0]), ///< Event from compare channel 0.
|
||||
NRF_TIMER_EVENT_COMPARE1 = offsetof(NRF_TIMER_Type, EVENTS_COMPARE[1]), ///< Event from compare channel 1.
|
||||
NRF_TIMER_EVENT_COMPARE2 = offsetof(NRF_TIMER_Type, EVENTS_COMPARE[2]), ///< Event from compare channel 2.
|
||||
NRF_TIMER_EVENT_COMPARE3 = offsetof(NRF_TIMER_Type, EVENTS_COMPARE[3]), ///< Event from compare channel 3.
|
||||
#if defined(TIMER_INTENSET_COMPARE4_Msk) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_TIMER_EVENT_COMPARE4 = offsetof(NRF_TIMER_Type, EVENTS_COMPARE[4]), ///< Event from compare channel 4.
|
||||
#endif
|
||||
#if defined(TIMER_INTENSET_COMPARE5_Msk) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_TIMER_EVENT_COMPARE5 = offsetof(NRF_TIMER_Type, EVENTS_COMPARE[5]), ///< Event from compare channel 5.
|
||||
#endif
|
||||
/*lint -restore*/
|
||||
} nrf_timer_event_t;
|
||||
|
||||
/**
|
||||
* @brief Types of timer shortcuts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_TIMER_SHORT_COMPARE0_STOP_MASK = TIMER_SHORTS_COMPARE0_STOP_Msk, ///< Shortcut for stopping the timer based on compare 0.
|
||||
NRF_TIMER_SHORT_COMPARE1_STOP_MASK = TIMER_SHORTS_COMPARE1_STOP_Msk, ///< Shortcut for stopping the timer based on compare 1.
|
||||
NRF_TIMER_SHORT_COMPARE2_STOP_MASK = TIMER_SHORTS_COMPARE2_STOP_Msk, ///< Shortcut for stopping the timer based on compare 2.
|
||||
NRF_TIMER_SHORT_COMPARE3_STOP_MASK = TIMER_SHORTS_COMPARE3_STOP_Msk, ///< Shortcut for stopping the timer based on compare 3.
|
||||
#if defined(TIMER_INTENSET_COMPARE4_Msk) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_TIMER_SHORT_COMPARE4_STOP_MASK = TIMER_SHORTS_COMPARE4_STOP_Msk, ///< Shortcut for stopping the timer based on compare 4.
|
||||
#endif
|
||||
#if defined(TIMER_INTENSET_COMPARE5_Msk) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_TIMER_SHORT_COMPARE5_STOP_MASK = TIMER_SHORTS_COMPARE5_STOP_Msk, ///< Shortcut for stopping the timer based on compare 5.
|
||||
#endif
|
||||
NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK = TIMER_SHORTS_COMPARE0_CLEAR_Msk, ///< Shortcut for clearing the timer based on compare 0.
|
||||
NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK = TIMER_SHORTS_COMPARE1_CLEAR_Msk, ///< Shortcut for clearing the timer based on compare 1.
|
||||
NRF_TIMER_SHORT_COMPARE2_CLEAR_MASK = TIMER_SHORTS_COMPARE2_CLEAR_Msk, ///< Shortcut for clearing the timer based on compare 2.
|
||||
NRF_TIMER_SHORT_COMPARE3_CLEAR_MASK = TIMER_SHORTS_COMPARE3_CLEAR_Msk, ///< Shortcut for clearing the timer based on compare 3.
|
||||
#if defined(TIMER_INTENSET_COMPARE4_Msk) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_TIMER_SHORT_COMPARE4_CLEAR_MASK = TIMER_SHORTS_COMPARE4_CLEAR_Msk, ///< Shortcut for clearing the timer based on compare 4.
|
||||
#endif
|
||||
#if defined(TIMER_INTENSET_COMPARE5_Msk) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_TIMER_SHORT_COMPARE5_CLEAR_MASK = TIMER_SHORTS_COMPARE5_CLEAR_Msk, ///< Shortcut for clearing the timer based on compare 5.
|
||||
#endif
|
||||
} nrf_timer_short_mask_t;
|
||||
|
||||
/**
|
||||
* @brief Timer modes.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_TIMER_MODE_TIMER = TIMER_MODE_MODE_Timer, ///< Timer mode: timer.
|
||||
NRF_TIMER_MODE_COUNTER = TIMER_MODE_MODE_Counter, ///< Timer mode: counter.
|
||||
#if defined(TIMER_MODE_MODE_LowPowerCounter) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_TIMER_MODE_LOW_POWER_COUNTER = TIMER_MODE_MODE_LowPowerCounter, ///< Timer mode: low-power counter.
|
||||
#endif
|
||||
} nrf_timer_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Timer bit width.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_TIMER_BIT_WIDTH_8 = TIMER_BITMODE_BITMODE_08Bit, ///< Timer bit width 8 bit.
|
||||
NRF_TIMER_BIT_WIDTH_16 = TIMER_BITMODE_BITMODE_16Bit, ///< Timer bit width 16 bit.
|
||||
NRF_TIMER_BIT_WIDTH_24 = TIMER_BITMODE_BITMODE_24Bit, ///< Timer bit width 24 bit.
|
||||
NRF_TIMER_BIT_WIDTH_32 = TIMER_BITMODE_BITMODE_32Bit ///< Timer bit width 32 bit.
|
||||
} nrf_timer_bit_width_t;
|
||||
|
||||
/**
|
||||
* @brief Timer prescalers.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_TIMER_FREQ_16MHz = 0, ///< Timer frequency 16 MHz.
|
||||
NRF_TIMER_FREQ_8MHz, ///< Timer frequency 8 MHz.
|
||||
NRF_TIMER_FREQ_4MHz, ///< Timer frequency 4 MHz.
|
||||
NRF_TIMER_FREQ_2MHz, ///< Timer frequency 2 MHz.
|
||||
NRF_TIMER_FREQ_1MHz, ///< Timer frequency 1 MHz.
|
||||
NRF_TIMER_FREQ_500kHz, ///< Timer frequency 500 kHz.
|
||||
NRF_TIMER_FREQ_250kHz, ///< Timer frequency 250 kHz.
|
||||
NRF_TIMER_FREQ_125kHz, ///< Timer frequency 125 kHz.
|
||||
NRF_TIMER_FREQ_62500Hz, ///< Timer frequency 62500 Hz.
|
||||
NRF_TIMER_FREQ_31250Hz ///< Timer frequency 31250 Hz.
|
||||
} nrf_timer_frequency_t;
|
||||
|
||||
/**
|
||||
* @brief Timer capture/compare channels.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_TIMER_CC_CHANNEL0 = 0, ///< Timer capture/compare channel 0.
|
||||
NRF_TIMER_CC_CHANNEL1, ///< Timer capture/compare channel 1.
|
||||
NRF_TIMER_CC_CHANNEL2, ///< Timer capture/compare channel 2.
|
||||
NRF_TIMER_CC_CHANNEL3, ///< Timer capture/compare channel 3.
|
||||
#if defined(TIMER_INTENSET_COMPARE4_Msk) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_TIMER_CC_CHANNEL4, ///< Timer capture/compare channel 4.
|
||||
#endif
|
||||
#if defined(TIMER_INTENSET_COMPARE5_Msk) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_TIMER_CC_CHANNEL5, ///< Timer capture/compare channel 5.
|
||||
#endif
|
||||
} nrf_timer_cc_channel_t;
|
||||
|
||||
/**
|
||||
* @brief Timer interrupts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_TIMER_INT_COMPARE0_MASK = TIMER_INTENSET_COMPARE0_Msk, ///< Timer interrupt from compare event on channel 0.
|
||||
NRF_TIMER_INT_COMPARE1_MASK = TIMER_INTENSET_COMPARE1_Msk, ///< Timer interrupt from compare event on channel 1.
|
||||
NRF_TIMER_INT_COMPARE2_MASK = TIMER_INTENSET_COMPARE2_Msk, ///< Timer interrupt from compare event on channel 2.
|
||||
NRF_TIMER_INT_COMPARE3_MASK = TIMER_INTENSET_COMPARE3_Msk, ///< Timer interrupt from compare event on channel 3.
|
||||
#if defined(TIMER_INTENSET_COMPARE4_Msk) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_TIMER_INT_COMPARE4_MASK = TIMER_INTENSET_COMPARE4_Msk, ///< Timer interrupt from compare event on channel 4.
|
||||
#endif
|
||||
#if defined(TIMER_INTENSET_COMPARE5_Msk) || defined(__NRFX_DOXYGEN__)
|
||||
NRF_TIMER_INT_COMPARE5_MASK = TIMER_INTENSET_COMPARE5_Msk, ///< Timer interrupt from compare event on channel 5.
|
||||
#endif
|
||||
} nrf_timer_int_mask_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for activating a specific timer task.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] task Task to activate.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_timer_task_trigger(NRF_TIMER_Type * p_reg,
|
||||
nrf_timer_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific timer task register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] task Requested task.
|
||||
*
|
||||
* @return Address of the specified task register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_timer_task_address_get(NRF_TIMER_Type * p_reg,
|
||||
nrf_timer_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a specific timer event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] event Event to clear.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_timer_event_clear(NRF_TIMER_Type * p_reg,
|
||||
nrf_timer_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the state of a specific timer event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] event Event to check.
|
||||
*
|
||||
* @retval true If the event is set.
|
||||
* @retval false If the event is not set.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_timer_event_check(NRF_TIMER_Type * p_reg,
|
||||
nrf_timer_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific timer event register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] event Requested event.
|
||||
*
|
||||
* @return Address of the specified event register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_timer_event_address_get(NRF_TIMER_Type * p_reg,
|
||||
nrf_timer_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling specified shortcuts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] timer_shorts_mask Shortcuts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_timer_shorts_enable(NRF_TIMER_Type * p_reg,
|
||||
uint32_t timer_shorts_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling specified shortcuts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] timer_shorts_mask Shortcuts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_timer_shorts_disable(NRF_TIMER_Type * p_reg,
|
||||
uint32_t timer_shorts_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling specified interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] timer_int_mask Interrupts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_timer_int_enable(NRF_TIMER_Type * p_reg,
|
||||
uint32_t timer_int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling specified interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] timer_int_mask Interrupts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_timer_int_disable(NRF_TIMER_Type * p_reg,
|
||||
uint32_t timer_int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of a given interrupt.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] timer_int Interrupt to check.
|
||||
*
|
||||
* @retval true If the interrupt is enabled.
|
||||
* @retval false If the interrupt is not enabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_timer_int_enable_check(NRF_TIMER_Type * p_reg,
|
||||
uint32_t timer_int);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the timer mode.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] mode Timer mode.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_timer_mode_set(NRF_TIMER_Type * p_reg,
|
||||
nrf_timer_mode_t mode);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the timer mode.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*
|
||||
* @return Timer mode.
|
||||
*/
|
||||
__STATIC_INLINE nrf_timer_mode_t nrf_timer_mode_get(NRF_TIMER_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the timer bit width.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] bit_width Timer bit width.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_timer_bit_width_set(NRF_TIMER_Type * p_reg,
|
||||
nrf_timer_bit_width_t bit_width);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the timer bit width.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*
|
||||
* @return Timer bit width.
|
||||
*/
|
||||
__STATIC_INLINE nrf_timer_bit_width_t nrf_timer_bit_width_get(NRF_TIMER_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the timer frequency.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] frequency Timer frequency.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_timer_frequency_set(NRF_TIMER_Type * p_reg,
|
||||
nrf_timer_frequency_t frequency);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the timer frequency.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*
|
||||
* @return Timer frequency.
|
||||
*/
|
||||
__STATIC_INLINE nrf_timer_frequency_t nrf_timer_frequency_get(NRF_TIMER_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for writing the capture/compare register for a specified channel.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] cc_channel Requested capture/compare channel.
|
||||
* @param[in] cc_value Value to write to the capture/compare register.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_timer_cc_write(NRF_TIMER_Type * p_reg,
|
||||
nrf_timer_cc_channel_t cc_channel,
|
||||
uint32_t cc_value);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the capture/compare value for a specified channel.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] cc_channel Requested capture/compare channel.
|
||||
*
|
||||
* @return Value from the requested capture/compare register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_timer_cc_read(NRF_TIMER_Type * p_reg,
|
||||
nrf_timer_cc_channel_t cc_channel);
|
||||
|
||||
/**
|
||||
* @brief Function for getting a specific timer capture task.
|
||||
*
|
||||
* @param[in] channel Capture channel.
|
||||
*
|
||||
* @return Capture task.
|
||||
*/
|
||||
__STATIC_INLINE nrf_timer_task_t nrf_timer_capture_task_get(uint32_t channel);
|
||||
|
||||
/**
|
||||
* @brief Function for getting a specific timer compare event.
|
||||
*
|
||||
* @param[in] channel Compare channel.
|
||||
*
|
||||
* @return Compare event.
|
||||
*/
|
||||
__STATIC_INLINE nrf_timer_event_t nrf_timer_compare_event_get(uint32_t channel);
|
||||
|
||||
/**
|
||||
* @brief Function for getting a specific timer compare interrupt.
|
||||
*
|
||||
* @param[in] channel Compare channel.
|
||||
*
|
||||
* @return Compare interrupt.
|
||||
*/
|
||||
__STATIC_INLINE nrf_timer_int_mask_t nrf_timer_compare_int_get(uint32_t channel);
|
||||
|
||||
/**
|
||||
* @brief Function for calculating the number of timer ticks for a given time
|
||||
* (in microseconds) and timer frequency.
|
||||
*
|
||||
* @param[in] time_us Time in microseconds.
|
||||
* @param[in] frequency Timer frequency.
|
||||
*
|
||||
* @return Number of timer ticks.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_timer_us_to_ticks(uint32_t time_us,
|
||||
nrf_timer_frequency_t frequency);
|
||||
|
||||
/**
|
||||
* @brief Function for calculating the number of timer ticks for a given time
|
||||
* (in milliseconds) and timer frequency.
|
||||
*
|
||||
* @param[in] time_ms Time in milliseconds.
|
||||
* @param[in] frequency Timer frequency.
|
||||
*
|
||||
* @return Number of timer ticks.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_timer_ms_to_ticks(uint32_t time_ms,
|
||||
nrf_timer_frequency_t frequency);
|
||||
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
__STATIC_INLINE void nrf_timer_task_trigger(NRF_TIMER_Type * p_reg,
|
||||
nrf_timer_task_t task)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task)) = 0x1UL;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_timer_task_address_get(NRF_TIMER_Type * p_reg,
|
||||
nrf_timer_task_t task)
|
||||
{
|
||||
return (uint32_t *)((uint8_t *)p_reg + (uint32_t)task);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_timer_event_clear(NRF_TIMER_Type * p_reg,
|
||||
nrf_timer_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_timer_event_check(NRF_TIMER_Type * p_reg,
|
||||
nrf_timer_event_t event)
|
||||
{
|
||||
return (bool)*(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_timer_event_address_get(NRF_TIMER_Type * p_reg,
|
||||
nrf_timer_event_t event)
|
||||
{
|
||||
return (uint32_t *)((uint8_t *)p_reg + (uint32_t)event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_timer_shorts_enable(NRF_TIMER_Type * p_reg,
|
||||
uint32_t timer_shorts_mask)
|
||||
{
|
||||
p_reg->SHORTS |= timer_shorts_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_timer_shorts_disable(NRF_TIMER_Type * p_reg,
|
||||
uint32_t timer_shorts_mask)
|
||||
{
|
||||
p_reg->SHORTS &= ~(timer_shorts_mask);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_timer_int_enable(NRF_TIMER_Type * p_reg,
|
||||
uint32_t timer_int_mask)
|
||||
{
|
||||
p_reg->INTENSET = timer_int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_timer_int_disable(NRF_TIMER_Type * p_reg,
|
||||
uint32_t timer_int_mask)
|
||||
{
|
||||
p_reg->INTENCLR = timer_int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_timer_int_enable_check(NRF_TIMER_Type * p_reg,
|
||||
uint32_t timer_int)
|
||||
{
|
||||
return (bool)(p_reg->INTENSET & timer_int);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_timer_mode_set(NRF_TIMER_Type * p_reg,
|
||||
nrf_timer_mode_t mode)
|
||||
{
|
||||
p_reg->MODE = (p_reg->MODE & ~TIMER_MODE_MODE_Msk) |
|
||||
((mode << TIMER_MODE_MODE_Pos) & TIMER_MODE_MODE_Msk);
|
||||
}
|
||||
|
||||
__STATIC_INLINE nrf_timer_mode_t nrf_timer_mode_get(NRF_TIMER_Type * p_reg)
|
||||
{
|
||||
return (nrf_timer_mode_t)(p_reg->MODE);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_timer_bit_width_set(NRF_TIMER_Type * p_reg,
|
||||
nrf_timer_bit_width_t bit_width)
|
||||
{
|
||||
p_reg->BITMODE = (p_reg->BITMODE & ~TIMER_BITMODE_BITMODE_Msk) |
|
||||
((bit_width << TIMER_BITMODE_BITMODE_Pos) &
|
||||
TIMER_BITMODE_BITMODE_Msk);
|
||||
}
|
||||
|
||||
__STATIC_INLINE nrf_timer_bit_width_t nrf_timer_bit_width_get(NRF_TIMER_Type * p_reg)
|
||||
{
|
||||
return (nrf_timer_bit_width_t)(p_reg->BITMODE);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_timer_frequency_set(NRF_TIMER_Type * p_reg,
|
||||
nrf_timer_frequency_t frequency)
|
||||
{
|
||||
p_reg->PRESCALER = (p_reg->PRESCALER & ~TIMER_PRESCALER_PRESCALER_Msk) |
|
||||
((frequency << TIMER_PRESCALER_PRESCALER_Pos) &
|
||||
TIMER_PRESCALER_PRESCALER_Msk);
|
||||
}
|
||||
|
||||
__STATIC_INLINE nrf_timer_frequency_t nrf_timer_frequency_get(NRF_TIMER_Type * p_reg)
|
||||
{
|
||||
return (nrf_timer_frequency_t)(p_reg->PRESCALER);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_timer_cc_write(NRF_TIMER_Type * p_reg,
|
||||
nrf_timer_cc_channel_t cc_channel,
|
||||
uint32_t cc_value)
|
||||
{
|
||||
p_reg->CC[cc_channel] = cc_value;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_timer_cc_read(NRF_TIMER_Type * p_reg,
|
||||
nrf_timer_cc_channel_t cc_channel)
|
||||
{
|
||||
return (uint32_t)p_reg->CC[cc_channel];
|
||||
}
|
||||
|
||||
__STATIC_INLINE nrf_timer_task_t nrf_timer_capture_task_get(uint32_t channel)
|
||||
{
|
||||
return (nrf_timer_task_t)
|
||||
((uint32_t)NRF_TIMER_TASK_CAPTURE0 + (channel * sizeof(uint32_t)));
|
||||
}
|
||||
|
||||
__STATIC_INLINE nrf_timer_event_t nrf_timer_compare_event_get(uint32_t channel)
|
||||
{
|
||||
return (nrf_timer_event_t)
|
||||
((uint32_t)NRF_TIMER_EVENT_COMPARE0 + (channel * sizeof(uint32_t)));
|
||||
}
|
||||
|
||||
__STATIC_INLINE nrf_timer_int_mask_t nrf_timer_compare_int_get(uint32_t channel)
|
||||
{
|
||||
return (nrf_timer_int_mask_t)
|
||||
((uint32_t)NRF_TIMER_INT_COMPARE0_MASK << channel);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_timer_us_to_ticks(uint32_t time_us,
|
||||
nrf_timer_frequency_t frequency)
|
||||
{
|
||||
// The "frequency" parameter here is actually the prescaler value, and the
|
||||
// timer runs at the following frequency: f = 16 MHz / 2^prescaler.
|
||||
uint32_t prescaler = (uint32_t)frequency;
|
||||
NRFX_ASSERT(time_us <= (UINT32_MAX / 16UL));
|
||||
return ((time_us * 16UL) >> prescaler);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_timer_ms_to_ticks(uint32_t time_ms,
|
||||
nrf_timer_frequency_t frequency)
|
||||
{
|
||||
// The "frequency" parameter here is actually the prescaler value, and the
|
||||
// timer runs at the following frequency: f = 16000 kHz / 2^prescaler.
|
||||
uint32_t prescaler = (uint32_t)frequency;
|
||||
NRFX_ASSERT(time_ms <= (UINT32_MAX / 16000UL));
|
||||
return ((time_ms * 16000UL) >> prescaler);
|
||||
}
|
||||
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_TIMER_H__
|
||||
@@ -0,0 +1,442 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_TWI_H__
|
||||
#define NRF_TWI_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_twi_hal TWI HAL
|
||||
* @{
|
||||
* @ingroup nrf_twi
|
||||
* @brief Hardware access layer for managing the TWI peripheral.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief TWI tasks.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
NRF_TWI_TASK_STARTRX = offsetof(NRF_TWI_Type, TASKS_STARTRX), ///< Start TWI receive sequence.
|
||||
NRF_TWI_TASK_STARTTX = offsetof(NRF_TWI_Type, TASKS_STARTTX), ///< Start TWI transmit sequence.
|
||||
NRF_TWI_TASK_STOP = offsetof(NRF_TWI_Type, TASKS_STOP), ///< Stop TWI transaction.
|
||||
NRF_TWI_TASK_SUSPEND = offsetof(NRF_TWI_Type, TASKS_SUSPEND), ///< Suspend TWI transaction.
|
||||
NRF_TWI_TASK_RESUME = offsetof(NRF_TWI_Type, TASKS_RESUME) ///< Resume TWI transaction.
|
||||
/*lint -restore*/
|
||||
} nrf_twi_task_t;
|
||||
|
||||
/**
|
||||
* @brief TWI events.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
NRF_TWI_EVENT_STOPPED = offsetof(NRF_TWI_Type, EVENTS_STOPPED), ///< TWI stopped.
|
||||
NRF_TWI_EVENT_RXDREADY = offsetof(NRF_TWI_Type, EVENTS_RXDREADY), ///< TWI RXD byte received.
|
||||
NRF_TWI_EVENT_TXDSENT = offsetof(NRF_TWI_Type, EVENTS_TXDSENT), ///< TWI TXD byte sent.
|
||||
NRF_TWI_EVENT_ERROR = offsetof(NRF_TWI_Type, EVENTS_ERROR), ///< TWI error.
|
||||
NRF_TWI_EVENT_BB = offsetof(NRF_TWI_Type, EVENTS_BB), ///< TWI byte boundary, generated before each byte that is sent or received.
|
||||
NRF_TWI_EVENT_SUSPENDED = offsetof(NRF_TWI_Type, EVENTS_SUSPENDED) ///< TWI entered the suspended state.
|
||||
/*lint -restore*/
|
||||
} nrf_twi_event_t;
|
||||
|
||||
/**
|
||||
* @brief TWI shortcuts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_TWI_SHORT_BB_SUSPEND_MASK = TWI_SHORTS_BB_SUSPEND_Msk, ///< Shortcut between BB event and SUSPEND task.
|
||||
NRF_TWI_SHORT_BB_STOP_MASK = TWI_SHORTS_BB_STOP_Msk, ///< Shortcut between BB event and STOP task.
|
||||
NRF_TWI_ALL_SHORTS_MASK = TWI_SHORTS_BB_SUSPEND_Msk |
|
||||
TWI_SHORTS_BB_STOP_Msk ///< All TWI shortcuts.
|
||||
} nrf_twi_short_mask_t;
|
||||
|
||||
/**
|
||||
* @brief TWI interrupts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_TWI_INT_STOPPED_MASK = TWI_INTENSET_STOPPED_Msk, ///< Interrupt on STOPPED event.
|
||||
NRF_TWI_INT_RXDREADY_MASK = TWI_INTENSET_RXDREADY_Msk, ///< Interrupt on RXDREADY event.
|
||||
NRF_TWI_INT_TXDSENT_MASK = TWI_INTENSET_TXDSENT_Msk, ///< Interrupt on TXDSENT event.
|
||||
NRF_TWI_INT_ERROR_MASK = TWI_INTENSET_ERROR_Msk, ///< Interrupt on ERROR event.
|
||||
NRF_TWI_INT_BB_MASK = TWI_INTENSET_BB_Msk, ///< Interrupt on BB event.
|
||||
NRF_TWI_INT_SUSPENDED_MASK = TWI_INTENSET_SUSPENDED_Msk, ///< Interrupt on SUSPENDED event.
|
||||
NRF_TWI_ALL_INTS_MASK = TWI_INTENSET_STOPPED_Msk |
|
||||
TWI_INTENSET_RXDREADY_Msk |
|
||||
TWI_INTENSET_TXDSENT_Msk |
|
||||
TWI_INTENSET_ERROR_Msk |
|
||||
TWI_INTENSET_BB_Msk |
|
||||
TWI_INTENSET_SUSPENDED_Msk ///< All TWI interrupts.
|
||||
} nrf_twi_int_mask_t;
|
||||
|
||||
/**
|
||||
* @brief TWI error source.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_TWI_ERROR_ADDRESS_NACK = TWI_ERRORSRC_ANACK_Msk, ///< NACK received after sending the address.
|
||||
NRF_TWI_ERROR_DATA_NACK = TWI_ERRORSRC_DNACK_Msk, ///< NACK received after sending a data byte.
|
||||
NRF_TWI_ERROR_OVERRUN = TWI_ERRORSRC_OVERRUN_Msk ///< Overrun error.
|
||||
/**< A new byte was received before the previous byte was read
|
||||
* from the RXD register (previous data is lost). */
|
||||
} nrf_twi_error_t;
|
||||
|
||||
/**
|
||||
* @brief TWI master clock frequency.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_TWI_FREQ_100K = TWI_FREQUENCY_FREQUENCY_K100, ///< 100 kbps.
|
||||
NRF_TWI_FREQ_250K = TWI_FREQUENCY_FREQUENCY_K250, ///< 250 kbps.
|
||||
NRF_TWI_FREQ_400K = TWI_FREQUENCY_FREQUENCY_K400 ///< 400 kbps.
|
||||
} nrf_twi_frequency_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for activating a specific TWI task.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] task Task to activate.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twi_task_trigger(NRF_TWI_Type * p_reg,
|
||||
nrf_twi_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific TWI task register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] task Requested task.
|
||||
*
|
||||
* @return Address of the specified task register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_twi_task_address_get(NRF_TWI_Type * p_reg,
|
||||
nrf_twi_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a specific TWI event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] event Event to clear.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twi_event_clear(NRF_TWI_Type * p_reg,
|
||||
nrf_twi_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the state of a specific event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] event Event to check.
|
||||
*
|
||||
* @retval true If the event is set.
|
||||
* @retval false If the event is not set.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_twi_event_check(NRF_TWI_Type * p_reg,
|
||||
nrf_twi_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific TWI event register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] event Requested event.
|
||||
*
|
||||
* @return Address of the specified event register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_twi_event_address_get(NRF_TWI_Type * p_reg,
|
||||
nrf_twi_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling specified shortcuts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] shorts_mask Shortcuts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twi_shorts_enable(NRF_TWI_Type * p_reg,
|
||||
uint32_t shorts_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling specified shortcuts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] shorts_mask Shortcuts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twi_shorts_disable(NRF_TWI_Type * p_reg,
|
||||
uint32_t shorts_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling specified interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] int_mask Interrupts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twi_int_enable(NRF_TWI_Type * p_reg,
|
||||
uint32_t int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling specified interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] int_mask Interrupts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twi_int_disable(NRF_TWI_Type * p_reg,
|
||||
uint32_t int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of a given interrupt.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] int_mask Interrupt to check.
|
||||
*
|
||||
* @retval true If the interrupt is enabled.
|
||||
* @retval false If the interrupt is not enabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_twi_int_enable_check(NRF_TWI_Type * p_reg,
|
||||
nrf_twi_int_mask_t int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling the TWI peripheral.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twi_enable(NRF_TWI_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling the TWI peripheral.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twi_disable(NRF_TWI_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for configuring TWI pins.
|
||||
*
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] scl_pin SCL pin number.
|
||||
* @param[in] sda_pin SDA pin number.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twi_pins_set(NRF_TWI_Type * p_reg,
|
||||
uint32_t scl_pin,
|
||||
uint32_t sda_pin);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the TWI master clock frequency.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] frequency TWI frequency.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twi_frequency_set(NRF_TWI_Type * p_reg,
|
||||
nrf_twi_frequency_t frequency);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the TWI error source.
|
||||
*
|
||||
* The error flags are cleared after reading.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*
|
||||
* @return Mask with error source flags.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_twi_errorsrc_get_and_clear(NRF_TWI_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the address to be used in TWI transfers.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] address Address to be used in transfers.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twi_address_set(NRF_TWI_Type * p_reg, uint8_t address);
|
||||
|
||||
/**
|
||||
* @brief Function for reading data received by TWI.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*
|
||||
* @return Received data.
|
||||
*/
|
||||
__STATIC_INLINE uint8_t nrf_twi_rxd_get(NRF_TWI_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for writing data to be transmitted by TWI.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] data Data to be transmitted.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twi_txd_set(NRF_TWI_Type * p_reg, uint8_t data);
|
||||
|
||||
__STATIC_INLINE void nrf_twi_shorts_set(NRF_TWI_Type * p_reg,
|
||||
uint32_t shorts_mask);
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
__STATIC_INLINE void nrf_twi_task_trigger(NRF_TWI_Type * p_reg,
|
||||
nrf_twi_task_t task)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task)) = 0x1UL;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_twi_task_address_get(NRF_TWI_Type * p_reg,
|
||||
nrf_twi_task_t task)
|
||||
{
|
||||
return (uint32_t *)((uint8_t *)p_reg + (uint32_t)task);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twi_event_clear(NRF_TWI_Type * p_reg,
|
||||
nrf_twi_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_twi_event_check(NRF_TWI_Type * p_reg,
|
||||
nrf_twi_event_t event)
|
||||
{
|
||||
return (bool)*(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_twi_event_address_get(NRF_TWI_Type * p_reg,
|
||||
nrf_twi_event_t event)
|
||||
{
|
||||
return (uint32_t *)((uint8_t *)p_reg + (uint32_t)event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twi_shorts_enable(NRF_TWI_Type * p_reg,
|
||||
uint32_t shorts_mask)
|
||||
{
|
||||
p_reg->SHORTS |= shorts_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twi_shorts_disable(NRF_TWI_Type * p_reg,
|
||||
uint32_t shorts_mask)
|
||||
{
|
||||
p_reg->SHORTS &= ~(shorts_mask);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twi_int_enable(NRF_TWI_Type * p_reg,
|
||||
uint32_t int_mask)
|
||||
{
|
||||
p_reg->INTENSET = int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twi_int_disable(NRF_TWI_Type * p_reg,
|
||||
uint32_t int_mask)
|
||||
{
|
||||
p_reg->INTENCLR = int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_twi_int_enable_check(NRF_TWI_Type * p_reg,
|
||||
nrf_twi_int_mask_t int_mask)
|
||||
{
|
||||
return (bool)(p_reg->INTENSET & int_mask);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twi_enable(NRF_TWI_Type * p_reg)
|
||||
{
|
||||
p_reg->ENABLE = (TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twi_disable(NRF_TWI_Type * p_reg)
|
||||
{
|
||||
p_reg->ENABLE = (TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twi_pins_set(NRF_TWI_Type * p_reg,
|
||||
uint32_t scl_pin,
|
||||
uint32_t sda_pin)
|
||||
{
|
||||
#if defined(TWI_PSEL_SCL_CONNECT_Pos)
|
||||
p_reg->PSEL.SCL = scl_pin;
|
||||
#else
|
||||
p_reg->PSELSCL = scl_pin;
|
||||
#endif
|
||||
|
||||
#if defined(TWI_PSEL_SDA_CONNECT_Pos)
|
||||
p_reg->PSEL.SDA = sda_pin;
|
||||
#else
|
||||
p_reg->PSELSDA = sda_pin;
|
||||
#endif
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twi_frequency_set(NRF_TWI_Type * p_reg,
|
||||
nrf_twi_frequency_t frequency)
|
||||
{
|
||||
p_reg->FREQUENCY = frequency;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_twi_errorsrc_get_and_clear(NRF_TWI_Type * p_reg)
|
||||
{
|
||||
uint32_t error_source = p_reg->ERRORSRC;
|
||||
|
||||
// [error flags are cleared by writing '1' on their position]
|
||||
p_reg->ERRORSRC = error_source;
|
||||
|
||||
return error_source;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twi_address_set(NRF_TWI_Type * p_reg, uint8_t address)
|
||||
{
|
||||
p_reg->ADDRESS = address;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint8_t nrf_twi_rxd_get(NRF_TWI_Type * p_reg)
|
||||
{
|
||||
return (uint8_t)p_reg->RXD;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twi_txd_set(NRF_TWI_Type * p_reg, uint8_t data)
|
||||
{
|
||||
p_reg->TXD = data;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twi_shorts_set(NRF_TWI_Type * p_reg,
|
||||
uint32_t shorts_mask)
|
||||
{
|
||||
p_reg->SHORTS = shorts_mask;
|
||||
}
|
||||
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_TWI_H__
|
||||
@@ -0,0 +1,513 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_TWIM_H__
|
||||
#define NRF_TWIM_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_twim_hal TWIM HAL
|
||||
* @{
|
||||
* @ingroup nrf_twim
|
||||
* @brief Hardware access layer for managing the TWIM peripheral.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief TWIM tasks.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
NRF_TWIM_TASK_STARTRX = offsetof(NRF_TWIM_Type, TASKS_STARTRX), ///< Start TWI receive sequence.
|
||||
NRF_TWIM_TASK_STARTTX = offsetof(NRF_TWIM_Type, TASKS_STARTTX), ///< Start TWI transmit sequence.
|
||||
NRF_TWIM_TASK_STOP = offsetof(NRF_TWIM_Type, TASKS_STOP), ///< Stop TWI transaction.
|
||||
NRF_TWIM_TASK_SUSPEND = offsetof(NRF_TWIM_Type, TASKS_SUSPEND), ///< Suspend TWI transaction.
|
||||
NRF_TWIM_TASK_RESUME = offsetof(NRF_TWIM_Type, TASKS_RESUME) ///< Resume TWI transaction.
|
||||
/*lint -restore*/
|
||||
} nrf_twim_task_t;
|
||||
|
||||
/**
|
||||
* @brief TWIM events.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
NRF_TWIM_EVENT_STOPPED = offsetof(NRF_TWIM_Type, EVENTS_STOPPED), ///< TWI stopped.
|
||||
NRF_TWIM_EVENT_ERROR = offsetof(NRF_TWIM_Type, EVENTS_ERROR), ///< TWI error.
|
||||
NRF_TWIM_EVENT_SUSPENDED = 0x148, ///< TWI suspended.
|
||||
NRF_TWIM_EVENT_RXSTARTED = offsetof(NRF_TWIM_Type, EVENTS_RXSTARTED), ///< Receive sequence started.
|
||||
NRF_TWIM_EVENT_TXSTARTED = offsetof(NRF_TWIM_Type, EVENTS_TXSTARTED), ///< Transmit sequence started.
|
||||
NRF_TWIM_EVENT_LASTRX = offsetof(NRF_TWIM_Type, EVENTS_LASTRX), ///< Byte boundary, starting to receive the last byte.
|
||||
NRF_TWIM_EVENT_LASTTX = offsetof(NRF_TWIM_Type, EVENTS_LASTTX) ///< Byte boundary, starting to transmit the last byte.
|
||||
/*lint -restore*/
|
||||
} nrf_twim_event_t;
|
||||
|
||||
/**
|
||||
* @brief TWIM shortcuts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_TWIM_SHORT_LASTTX_STARTRX_MASK = TWIM_SHORTS_LASTTX_STARTRX_Msk, ///< Shortcut between LASTTX event and STARTRX task.
|
||||
NRF_TWIM_SHORT_LASTTX_SUSPEND_MASK = TWIM_SHORTS_LASTTX_SUSPEND_Msk, ///< Shortcut between LASTTX event and SUSPEND task.
|
||||
NRF_TWIM_SHORT_LASTTX_STOP_MASK = TWIM_SHORTS_LASTTX_STOP_Msk, ///< Shortcut between LASTTX event and STOP task.
|
||||
NRF_TWIM_SHORT_LASTRX_STARTTX_MASK = TWIM_SHORTS_LASTRX_STARTTX_Msk, ///< Shortcut between LASTRX event and STARTTX task.
|
||||
NRF_TWIM_SHORT_LASTRX_STOP_MASK = TWIM_SHORTS_LASTRX_STOP_Msk, ///< Shortcut between LASTRX event and STOP task.
|
||||
NRF_TWIM_ALL_SHORTS_MASK = TWIM_SHORTS_LASTTX_STARTRX_Msk |
|
||||
TWIM_SHORTS_LASTTX_SUSPEND_Msk |
|
||||
TWIM_SHORTS_LASTTX_STOP_Msk |
|
||||
TWIM_SHORTS_LASTRX_STARTTX_Msk |
|
||||
TWIM_SHORTS_LASTRX_STOP_Msk ///< All TWIM shortcuts.
|
||||
} nrf_twim_short_mask_t;
|
||||
|
||||
/**
|
||||
* @brief TWIM interrupts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_TWIM_INT_STOPPED_MASK = TWIM_INTENSET_STOPPED_Msk, ///< Interrupt on STOPPED event.
|
||||
NRF_TWIM_INT_ERROR_MASK = TWIM_INTENSET_ERROR_Msk, ///< Interrupt on ERROR event.
|
||||
NRF_TWIM_INT_SUSPENDED_MASK = TWIM_INTENSET_SUSPENDED_Msk, ///< Interrupt on SUSPENDED event.
|
||||
NRF_TWIM_INT_RXSTARTED_MASK = TWIM_INTENSET_RXSTARTED_Msk, ///< Interrupt on RXSTARTED event.
|
||||
NRF_TWIM_INT_TXSTARTED_MASK = TWIM_INTENSET_TXSTARTED_Msk, ///< Interrupt on TXSTARTED event.
|
||||
NRF_TWIM_INT_LASTRX_MASK = TWIM_INTENSET_LASTRX_Msk, ///< Interrupt on LASTRX event.
|
||||
NRF_TWIM_INT_LASTTX_MASK = TWIM_INTENSET_LASTTX_Msk, ///< Interrupt on LASTTX event.
|
||||
NRF_TWIM_ALL_INTS_MASK = TWIM_INTENSET_STOPPED_Msk |
|
||||
TWIM_INTENSET_ERROR_Msk |
|
||||
TWIM_INTENSET_SUSPENDED_Msk |
|
||||
TWIM_INTENSET_RXSTARTED_Msk |
|
||||
TWIM_INTENSET_TXSTARTED_Msk |
|
||||
TWIM_INTENSET_LASTRX_Msk |
|
||||
TWIM_INTENSET_LASTTX_Msk ///< Interrupt on LASTTX event.
|
||||
} nrf_twim_int_mask_t;
|
||||
|
||||
/**
|
||||
* @brief TWIM master clock frequency.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_TWIM_FREQ_100K = TWIM_FREQUENCY_FREQUENCY_K100, ///< 100 kbps.
|
||||
NRF_TWIM_FREQ_250K = TWIM_FREQUENCY_FREQUENCY_K250, ///< 250 kbps.
|
||||
NRF_TWIM_FREQ_400K = TWIM_FREQUENCY_FREQUENCY_K400 ///< 400 kbps.
|
||||
} nrf_twim_frequency_t;
|
||||
|
||||
/**
|
||||
* @brief TWIM error source.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_TWIM_ERROR_ADDRESS_NACK = TWIM_ERRORSRC_ANACK_Msk, ///< NACK received after sending the address.
|
||||
NRF_TWIM_ERROR_DATA_NACK = TWIM_ERRORSRC_DNACK_Msk ///< NACK received after sending a data byte.
|
||||
} nrf_twim_error_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for activating a specific TWIM task.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] task Task to activate.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twim_task_trigger(NRF_TWIM_Type * p_reg,
|
||||
nrf_twim_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific TWIM task register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] task Requested task.
|
||||
*
|
||||
* @return Address of the specified task register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_twim_task_address_get(NRF_TWIM_Type * p_reg,
|
||||
nrf_twim_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a specific TWIM event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] event Event to clear.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twim_event_clear(NRF_TWIM_Type * p_reg,
|
||||
nrf_twim_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the state of a specific TWIM event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] event Event to check.
|
||||
*
|
||||
* @retval true If the event is set.
|
||||
* @retval false If the event is not set.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_twim_event_check(NRF_TWIM_Type * p_reg,
|
||||
nrf_twim_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a specific TWIM event register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] event Requested event.
|
||||
*
|
||||
* @return Address of the specified event register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t * nrf_twim_event_address_get(NRF_TWIM_Type * p_reg,
|
||||
nrf_twim_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling specified shortcuts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] shorts_mask Shortcuts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twim_shorts_enable(NRF_TWIM_Type * p_reg,
|
||||
uint32_t shorts_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling specified shortcuts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] shorts_mask Shortcuts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twim_shorts_disable(NRF_TWIM_Type * p_reg,
|
||||
uint32_t shorts_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling specified interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] int_mask Interrupts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twim_int_enable(NRF_TWIM_Type * p_reg,
|
||||
uint32_t int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling specified interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] int_mask Interrupts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twim_int_disable(NRF_TWIM_Type * p_reg,
|
||||
uint32_t int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the state of a given interrupt.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] int_mask Interrupt to check.
|
||||
*
|
||||
* @retval true If the interrupt is enabled.
|
||||
* @retval false If the interrupt is not enabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_twim_int_enable_check(NRF_TWIM_Type * p_reg,
|
||||
nrf_twim_int_mask_t int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling the TWIM peripheral.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twim_enable(NRF_TWIM_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling the TWIM peripheral.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twim_disable(NRF_TWIM_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for configuring TWI pins.
|
||||
*
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] scl_pin SCL pin number.
|
||||
* @param[in] sda_pin SDA pin number.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twim_pins_set(NRF_TWIM_Type * p_reg,
|
||||
uint32_t scl_pin,
|
||||
uint32_t sda_pin);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the TWI master clock frequency.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] frequency TWI frequency.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twim_frequency_set(NRF_TWIM_Type * p_reg,
|
||||
nrf_twim_frequency_t frequency);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the TWI error source.
|
||||
*
|
||||
* The error flags are cleared after reading.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*
|
||||
* @return Mask with error source flags.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_twim_errorsrc_get_and_clear(NRF_TWIM_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the address to be used in TWI transfers.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] address Address to be used in transfers.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twim_address_set(NRF_TWIM_Type * p_reg,
|
||||
uint8_t address);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the transmit buffer.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] p_buffer Pointer to the buffer with data to send.
|
||||
* @param[in] length Maximum number of data bytes to transmit.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twim_tx_buffer_set(NRF_TWIM_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 peripheral registers structure.
|
||||
* @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_twim_rx_buffer_set(NRF_TWIM_Type * p_reg,
|
||||
uint8_t * p_buffer,
|
||||
size_t length);
|
||||
|
||||
__STATIC_INLINE void nrf_twim_shorts_set(NRF_TWIM_Type * p_reg,
|
||||
uint32_t shorts_mask);
|
||||
|
||||
__STATIC_INLINE size_t nrf_twim_txd_amount_get(NRF_TWIM_Type * p_reg);
|
||||
|
||||
__STATIC_INLINE size_t nrf_twim_rxd_amount_get(NRF_TWIM_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling the TX list feature.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twim_tx_list_enable(NRF_TWIM_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling the TX list feature.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twim_tx_list_disable(NRF_TWIM_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling the RX list feature.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twim_rx_list_enable(NRF_TWIM_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling the RX list feature.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twim_rx_list_disable(NRF_TWIM_Type * p_reg);
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
__STATIC_INLINE void nrf_twim_task_trigger(NRF_TWIM_Type * p_reg,
|
||||
nrf_twim_task_t task)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task)) = 0x1UL;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_twim_task_address_get(NRF_TWIM_Type * p_reg,
|
||||
nrf_twim_task_t task)
|
||||
{
|
||||
return (uint32_t *)((uint8_t *)p_reg + (uint32_t)task);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twim_event_clear(NRF_TWIM_Type * p_reg,
|
||||
nrf_twim_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_twim_event_check(NRF_TWIM_Type * p_reg,
|
||||
nrf_twim_event_t event)
|
||||
{
|
||||
return (bool)*(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t * nrf_twim_event_address_get(NRF_TWIM_Type * p_reg,
|
||||
nrf_twim_event_t event)
|
||||
{
|
||||
return (uint32_t *)((uint8_t *)p_reg + (uint32_t)event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twim_shorts_enable(NRF_TWIM_Type * p_reg,
|
||||
uint32_t shorts_mask)
|
||||
{
|
||||
p_reg->SHORTS |= shorts_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twim_shorts_disable(NRF_TWIM_Type * p_reg,
|
||||
uint32_t shorts_mask)
|
||||
{
|
||||
p_reg->SHORTS &= ~(shorts_mask);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twim_int_enable(NRF_TWIM_Type * p_reg,
|
||||
uint32_t int_mask)
|
||||
{
|
||||
p_reg->INTENSET = int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twim_int_disable(NRF_TWIM_Type * p_reg,
|
||||
uint32_t int_mask)
|
||||
{
|
||||
p_reg->INTENCLR = int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_twim_int_enable_check(NRF_TWIM_Type * p_reg,
|
||||
nrf_twim_int_mask_t int_mask)
|
||||
{
|
||||
return (bool)(p_reg->INTENSET & int_mask);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twim_enable(NRF_TWIM_Type * p_reg)
|
||||
{
|
||||
p_reg->ENABLE = (TWIM_ENABLE_ENABLE_Enabled << TWIM_ENABLE_ENABLE_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twim_disable(NRF_TWIM_Type * p_reg)
|
||||
{
|
||||
p_reg->ENABLE = (TWIM_ENABLE_ENABLE_Disabled << TWIM_ENABLE_ENABLE_Pos);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twim_pins_set(NRF_TWIM_Type * p_reg,
|
||||
uint32_t scl_pin,
|
||||
uint32_t sda_pin)
|
||||
{
|
||||
p_reg->PSEL.SCL = scl_pin;
|
||||
p_reg->PSEL.SDA = sda_pin;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twim_frequency_set(NRF_TWIM_Type * p_reg,
|
||||
nrf_twim_frequency_t frequency)
|
||||
{
|
||||
p_reg->FREQUENCY = frequency;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_twim_errorsrc_get_and_clear(NRF_TWIM_Type * p_reg)
|
||||
{
|
||||
uint32_t error_source = p_reg->ERRORSRC;
|
||||
|
||||
// [error flags are cleared by writing '1' on their position]
|
||||
p_reg->ERRORSRC = error_source;
|
||||
|
||||
return error_source;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twim_address_set(NRF_TWIM_Type * p_reg,
|
||||
uint8_t address)
|
||||
{
|
||||
p_reg->ADDRESS = address;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twim_tx_buffer_set(NRF_TWIM_Type * p_reg,
|
||||
uint8_t const * p_buffer,
|
||||
size_t length)
|
||||
{
|
||||
p_reg->TXD.PTR = (uint32_t)p_buffer;
|
||||
p_reg->TXD.MAXCNT = length;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twim_rx_buffer_set(NRF_TWIM_Type * p_reg,
|
||||
uint8_t * p_buffer,
|
||||
size_t length)
|
||||
{
|
||||
p_reg->RXD.PTR = (uint32_t)p_buffer;
|
||||
p_reg->RXD.MAXCNT = length;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twim_shorts_set(NRF_TWIM_Type * p_reg,
|
||||
uint32_t shorts_mask)
|
||||
{
|
||||
p_reg->SHORTS = shorts_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE size_t nrf_twim_txd_amount_get(NRF_TWIM_Type * p_reg)
|
||||
{
|
||||
return p_reg->TXD.AMOUNT;
|
||||
}
|
||||
|
||||
__STATIC_INLINE size_t nrf_twim_rxd_amount_get(NRF_TWIM_Type * p_reg)
|
||||
{
|
||||
return p_reg->RXD.AMOUNT;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twim_tx_list_enable(NRF_TWIM_Type * p_reg)
|
||||
{
|
||||
p_reg->TXD.LIST = 1;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twim_tx_list_disable(NRF_TWIM_Type * p_reg)
|
||||
{
|
||||
p_reg->TXD.LIST = 0;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twim_rx_list_enable(NRF_TWIM_Type * p_reg)
|
||||
{
|
||||
p_reg->RXD.LIST = 1;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_twim_rx_list_disable(NRF_TWIM_Type * p_reg)
|
||||
{
|
||||
p_reg->RXD.LIST = 0;
|
||||
}
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_TWIM_H__
|
||||
@@ -0,0 +1,693 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 <nrfx.h>
|
||||
|
||||
#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
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
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 */
|
||||
/*lint -restore*/
|
||||
} nrf_twis_task_t;
|
||||
|
||||
/**
|
||||
* @brief TWIS events
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
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 */
|
||||
/*lint -restore*/
|
||||
} 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 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 would be updated to support more data in
|
||||
* the future devices to.
|
||||
*/
|
||||
typedef uint8_t nrf_twis_amount_t;
|
||||
|
||||
/**
|
||||
* @brief Smallest variable type to hold TWI address
|
||||
*
|
||||
* Variable of the minimum size that can hold single TWI address.
|
||||
*
|
||||
* @note
|
||||
* Defined to make it simple to change if new TWI would support for example
|
||||
* 10 bit addressing mode.
|
||||
*/
|
||||
typedef uint8_t nrf_twis_address_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for activating a specific TWIS task.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param task Task.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twis_task_trigger(NRF_TWIS_Type * const p_reg, nrf_twis_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a specific TWIS task register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param task Task.
|
||||
*
|
||||
* @return Task address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_twis_task_address_get(
|
||||
NRF_TWIS_Type const * const p_reg,
|
||||
nrf_twis_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a specific event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param event Event.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twis_event_clear(
|
||||
NRF_TWIS_Type * const p_reg,
|
||||
nrf_twis_event_t event);
|
||||
/**
|
||||
* @brief Function for returning the state of a specific event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param event Event.
|
||||
*
|
||||
* @retval true If the event is set.
|
||||
* @retval false If the event is not set.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_twis_event_check(
|
||||
NRF_TWIS_Type const * const p_reg,
|
||||
nrf_twis_event_t event);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for getting and clearing the state of specific event
|
||||
*
|
||||
* This function checks the state of the event and clears it.
|
||||
* @param[in,out] p_reg Pointer to the peripheral registers structure.
|
||||
* @param event Event.
|
||||
*
|
||||
* @retval true If the event was set.
|
||||
* @retval false If the event was not set.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_twis_event_get_and_clear(
|
||||
NRF_TWIS_Type * const p_reg,
|
||||
nrf_twis_event_t event);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a specific TWIS event register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param event Event.
|
||||
*
|
||||
* @return Address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_twis_event_address_get(
|
||||
NRF_TWIS_Type const * const p_reg,
|
||||
nrf_twis_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for setting a shortcut.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param short_mask Shortcuts mask.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twis_shorts_enable(NRF_TWIS_Type * const p_reg, uint32_t short_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing shortcuts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param short_mask Shortcuts mask.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twis_shorts_disable(NRF_TWIS_Type * const p_reg, uint32_t short_mask);
|
||||
|
||||
/**
|
||||
* @brief Get the shorts mask
|
||||
*
|
||||
* Function returns shorts register.
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @return Flags of currently enabled shortcuts
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_twis_shorts_get(NRF_TWIS_Type * const p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling selected interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param int_mask Interrupts mask.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twis_int_enable(NRF_TWIS_Type * const p_reg, uint32_t int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of selected interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param int_mask Interrupts mask.
|
||||
*
|
||||
* @retval true If any of selected interrupts is enabled.
|
||||
* @retval false If none of selected interrupts is enabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_twis_int_enable_check(NRF_TWIS_Type const * const p_reg, uint32_t int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling selected interrupts.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param int_mask Interrupts mask.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twis_int_disable(NRF_TWIS_Type * const p_reg, uint32_t int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving and clearing the TWIS error source.
|
||||
*
|
||||
* @attention Error sources are cleared after read.
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @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 Get information which of addresses matched
|
||||
*
|
||||
* Function returns index in the address table
|
||||
* that points to the address that already matched.
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @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 peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twis_enable(NRF_TWIS_Type * const p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling TWIS.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twis_disable(NRF_TWIS_Type * const p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for configuring TWIS pins.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param scl SCL pin number.
|
||||
* @param sda SDA pin number.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twis_pins_set(NRF_TWIS_Type * const p_reg, uint32_t scl, uint32_t sda);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the receive buffer.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param p_buf Pointer to the buffer for received data.
|
||||
* @param length Maximum number of data bytes to receive.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twis_rx_buffer_set(
|
||||
NRF_TWIS_Type * const p_reg,
|
||||
uint8_t * p_buf,
|
||||
nrf_twis_amount_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 peripheral registers structure.
|
||||
* @param p_buf Pointer to the buffer for received data.
|
||||
* @param length Maximum number of data bytes to receive.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twis_rx_prepare(
|
||||
NRF_TWIS_Type * const p_reg,
|
||||
uint8_t * p_buf,
|
||||
nrf_twis_amount_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 nrf_twis_amount_t nrf_twis_rx_amount_get(NRF_TWIS_Type const * const p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the transmit buffer.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param p_buf Pointer to the buffer with data to send.
|
||||
* @param length Maximum number of data bytes to transmit.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twis_tx_buffer_set(
|
||||
NRF_TWIS_Type * const p_reg,
|
||||
uint8_t const * p_buf,
|
||||
nrf_twis_amount_t length);
|
||||
|
||||
/**
|
||||
* @brief Function that prepares TWIS for transmitting
|
||||
*
|
||||
* This function sets transmit buffer and then sets NRF_TWIS_TASK_PREPARETX task.
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param p_buf Pointer to the buffer with data to send.
|
||||
* @param length Maximum number of data bytes to transmit.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twis_tx_prepare(
|
||||
NRF_TWIS_Type * const p_reg,
|
||||
uint8_t const * p_buf,
|
||||
nrf_twis_amount_t length);
|
||||
|
||||
/**
|
||||
* @brief Function for getting number of bytes transmitted in the last transaction.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @return Amount of bytes transmitted.
|
||||
*/
|
||||
__STATIC_INLINE nrf_twis_amount_t nrf_twis_tx_amount_get(NRF_TWIS_Type const * const p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for setting slave address
|
||||
*
|
||||
* Function sets the selected address for this TWI interface.
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param n Index of address to set
|
||||
* @param addr Addres to set
|
||||
* @sa nrf_twis_config_address_set
|
||||
* @sa nrf_twis_config_address_get
|
||||
*/
|
||||
__STATIC_INLINE void nrf_twis_address_set(
|
||||
NRF_TWIS_Type * const 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 peripheral registers structure.
|
||||
* @param n Index of address to get
|
||||
*/
|
||||
__STATIC_INLINE nrf_twis_address_t nrf_twis_address_get(
|
||||
NRF_TWIS_Type const * const p_reg,
|
||||
uint_fast8_t n);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the device address configuration.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param 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 * const 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 peripheral registers structure.
|
||||
*
|
||||
* @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 * const p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the over-read character.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @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 * const p_reg,
|
||||
uint8_t orc);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the over-read character.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*
|
||||
* @return Over-read character configured for selected instance.
|
||||
*/
|
||||
__STATIC_INLINE uint8_t nrf_twis_orc_get(NRF_TWIS_Type const * const p_reg);
|
||||
|
||||
|
||||
/** @} */ /* End of nrf_twis_hal */
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Internal functions
|
||||
*/
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @brief Internal function for getting task/event register address
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @oaram offset Offset of the register from the instance beginning
|
||||
*
|
||||
* @attention offset has to be modulo 4 value. In other case we can get hardware fault.
|
||||
* @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 peripheral registers structure.
|
||||
* @oaram offset Offset of the register from the instance beginning
|
||||
*
|
||||
* @attention offset has to be modulo 4 value. In other case we can get hardware fault.
|
||||
* @return Pointer to the register
|
||||
*/
|
||||
__STATIC_INLINE volatile const uint32_t* nrf_twis_getRegPtr_c(NRF_TWIS_Type const * const p_reg, uint32_t offset)
|
||||
{
|
||||
return (volatile const uint32_t*)((uint8_t *)p_reg + (uint32_t)offset);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Interface functions definitions
|
||||
*/
|
||||
|
||||
|
||||
void nrf_twis_task_trigger(NRF_TWIS_Type * const p_reg, nrf_twis_task_t task)
|
||||
{
|
||||
*(nrf_twis_getRegPtr(p_reg, (uint32_t)task)) = 1UL;
|
||||
}
|
||||
|
||||
uint32_t nrf_twis_task_address_get(
|
||||
NRF_TWIS_Type const * const p_reg,
|
||||
nrf_twis_task_t task)
|
||||
{
|
||||
return (uint32_t)nrf_twis_getRegPtr_c(p_reg, (uint32_t)task);
|
||||
}
|
||||
|
||||
void nrf_twis_event_clear(
|
||||
NRF_TWIS_Type * const 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
|
||||
}
|
||||
|
||||
bool nrf_twis_event_check(
|
||||
NRF_TWIS_Type const * const p_reg,
|
||||
nrf_twis_event_t event)
|
||||
{
|
||||
return (bool)*nrf_twis_getRegPtr_c(p_reg, (uint32_t)event);
|
||||
}
|
||||
|
||||
bool nrf_twis_event_get_and_clear(
|
||||
NRF_TWIS_Type * const 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;
|
||||
}
|
||||
|
||||
uint32_t nrf_twis_event_address_get(
|
||||
NRF_TWIS_Type const * const p_reg,
|
||||
nrf_twis_event_t event)
|
||||
{
|
||||
return (uint32_t)nrf_twis_getRegPtr_c(p_reg, (uint32_t)event);
|
||||
}
|
||||
|
||||
void nrf_twis_shorts_enable(NRF_TWIS_Type * const p_reg, uint32_t short_mask)
|
||||
{
|
||||
p_reg->SHORTS |= short_mask;
|
||||
}
|
||||
|
||||
void nrf_twis_shorts_disable(NRF_TWIS_Type * const p_reg, uint32_t short_mask)
|
||||
{
|
||||
if (~0U == short_mask)
|
||||
{
|
||||
/* Optimized version for "disable all" */
|
||||
p_reg->SHORTS = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
p_reg->SHORTS &= ~short_mask;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t nrf_twis_shorts_get(NRF_TWIS_Type * const p_reg)
|
||||
{
|
||||
return p_reg->SHORTS;
|
||||
}
|
||||
|
||||
void nrf_twis_int_enable(NRF_TWIS_Type * const p_reg, uint32_t int_mask)
|
||||
{
|
||||
p_reg->INTENSET = int_mask;
|
||||
}
|
||||
|
||||
bool nrf_twis_int_enable_check(NRF_TWIS_Type const * const p_reg, uint32_t int_mask)
|
||||
{
|
||||
return (bool)(p_reg->INTENSET & int_mask);
|
||||
}
|
||||
|
||||
void nrf_twis_int_disable(NRF_TWIS_Type * const p_reg, uint32_t int_mask)
|
||||
{
|
||||
p_reg->INTENCLR = int_mask;
|
||||
}
|
||||
|
||||
uint32_t nrf_twis_error_source_get_and_clear(NRF_TWIS_Type * const p_reg)
|
||||
{
|
||||
uint32_t ret = p_reg->ERRORSRC;
|
||||
p_reg->ERRORSRC = ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint_fast8_t nrf_twis_match_get(NRF_TWIS_Type const * p_reg)
|
||||
{
|
||||
return (uint_fast8_t)p_reg->MATCH;
|
||||
}
|
||||
|
||||
void nrf_twis_enable(NRF_TWIS_Type * const p_reg)
|
||||
{
|
||||
p_reg->ENABLE = (TWIS_ENABLE_ENABLE_Enabled << TWIS_ENABLE_ENABLE_Pos);
|
||||
}
|
||||
|
||||
void nrf_twis_disable(NRF_TWIS_Type * const p_reg)
|
||||
{
|
||||
p_reg->ENABLE = (TWIS_ENABLE_ENABLE_Disabled << TWIS_ENABLE_ENABLE_Pos);
|
||||
}
|
||||
|
||||
void nrf_twis_pins_set(NRF_TWIS_Type * const p_reg, uint32_t scl, uint32_t sda)
|
||||
{
|
||||
p_reg->PSEL.SCL = scl;
|
||||
p_reg->PSEL.SDA = sda;
|
||||
}
|
||||
|
||||
void nrf_twis_rx_buffer_set(
|
||||
NRF_TWIS_Type * const p_reg,
|
||||
uint8_t * p_buf,
|
||||
nrf_twis_amount_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 * const p_reg,
|
||||
uint8_t * p_buf,
|
||||
nrf_twis_amount_t length)
|
||||
{
|
||||
nrf_twis_rx_buffer_set(p_reg, p_buf, length);
|
||||
nrf_twis_task_trigger(p_reg, NRF_TWIS_TASK_PREPARERX);
|
||||
}
|
||||
|
||||
nrf_twis_amount_t nrf_twis_rx_amount_get(NRF_TWIS_Type const * const p_reg)
|
||||
{
|
||||
return (nrf_twis_amount_t)p_reg->RXD.AMOUNT;
|
||||
}
|
||||
|
||||
void nrf_twis_tx_buffer_set(
|
||||
NRF_TWIS_Type * const p_reg,
|
||||
uint8_t const * p_buf,
|
||||
nrf_twis_amount_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 * const p_reg,
|
||||
uint8_t const * p_buf,
|
||||
nrf_twis_amount_t length)
|
||||
{
|
||||
nrf_twis_tx_buffer_set(p_reg, p_buf, length);
|
||||
nrf_twis_task_trigger(p_reg, NRF_TWIS_TASK_PREPARETX);
|
||||
}
|
||||
|
||||
nrf_twis_amount_t nrf_twis_tx_amount_get(NRF_TWIS_Type const * const p_reg)
|
||||
{
|
||||
return (nrf_twis_amount_t)p_reg->TXD.AMOUNT;
|
||||
}
|
||||
|
||||
void nrf_twis_address_set(
|
||||
NRF_TWIS_Type * const p_reg,
|
||||
uint_fast8_t n,
|
||||
nrf_twis_address_t addr)
|
||||
{
|
||||
p_reg->ADDRESS[n] = addr;
|
||||
}
|
||||
|
||||
nrf_twis_address_t nrf_twis_address_get(
|
||||
NRF_TWIS_Type const * const p_reg,
|
||||
uint_fast8_t n)
|
||||
{
|
||||
return (nrf_twis_address_t)p_reg->ADDRESS[n];
|
||||
}
|
||||
void nrf_twis_config_address_set(
|
||||
NRF_TWIS_Type * const 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;
|
||||
}
|
||||
|
||||
nrf_twis_config_addr_mask_t nrf_twis_config_address_get(NRF_TWIS_Type const * const p_reg)
|
||||
{
|
||||
return (nrf_twis_config_addr_mask_t)(p_reg->CONFIG & TWIS_ADDRESS_ADDRESS_Msk);
|
||||
}
|
||||
|
||||
void nrf_twis_orc_set(
|
||||
NRF_TWIS_Type * const p_reg,
|
||||
uint8_t orc)
|
||||
{
|
||||
p_reg->ORC = orc;
|
||||
}
|
||||
|
||||
uint8_t nrf_twis_orc_get(NRF_TWIS_Type const * const p_reg)
|
||||
{
|
||||
return (uint8_t)p_reg->ORC;
|
||||
}
|
||||
|
||||
#endif /* SUPPRESS_INLINE_IMPLEMENTATION */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRF_TWIS_H__ */
|
||||
@@ -0,0 +1,517 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_UART_H__
|
||||
#define NRF_UART_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_uart_hal UART HAL
|
||||
* @{
|
||||
* @ingroup nrf_uart
|
||||
* @brief Hardware access layer for managing the UART peripheral.
|
||||
*/
|
||||
|
||||
#define NRF_UART_PSEL_DISCONNECTED 0xFFFFFFFF
|
||||
|
||||
/**
|
||||
* @enum nrf_uart_task_t
|
||||
* @brief UART tasks.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30 -esym(628,__INTADDR__)*/
|
||||
NRF_UART_TASK_STARTRX = offsetof(NRF_UART_Type, TASKS_STARTRX), /**< Task for starting reception. */
|
||||
NRF_UART_TASK_STOPRX = offsetof(NRF_UART_Type, TASKS_STOPRX), /**< Task for stopping reception. */
|
||||
NRF_UART_TASK_STARTTX = offsetof(NRF_UART_Type, TASKS_STARTTX), /**< Task for starting transmission. */
|
||||
NRF_UART_TASK_STOPTX = offsetof(NRF_UART_Type, TASKS_STOPTX), /**< Task for stopping transmission. */
|
||||
NRF_UART_TASK_SUSPEND = offsetof(NRF_UART_Type, TASKS_SUSPEND), /**< Task for suspending UART. */
|
||||
/*lint -restore*/
|
||||
} nrf_uart_task_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_uart_event_t
|
||||
* @brief UART events.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
NRF_UART_EVENT_CTS = offsetof(NRF_UART_Type, EVENTS_CTS), /**< Event from CTS line activation. */
|
||||
NRF_UART_EVENT_NCTS = offsetof(NRF_UART_Type, EVENTS_NCTS), /**< Event from CTS line deactivation. */
|
||||
NRF_UART_EVENT_RXDRDY = offsetof(NRF_UART_Type, EVENTS_RXDRDY),/**< Event from data ready in RXD. */
|
||||
NRF_UART_EVENT_TXDRDY = offsetof(NRF_UART_Type, EVENTS_TXDRDY),/**< Event from data sent from TXD. */
|
||||
NRF_UART_EVENT_ERROR = offsetof(NRF_UART_Type, EVENTS_ERROR), /**< Event from error detection. */
|
||||
NRF_UART_EVENT_RXTO = offsetof(NRF_UART_Type, EVENTS_RXTO) /**< Event from receiver timeout. */
|
||||
/*lint -restore*/
|
||||
} nrf_uart_event_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_uart_int_mask_t
|
||||
* @brief UART interrupts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
NRF_UART_INT_MASK_CTS = UART_INTENCLR_CTS_Msk, /**< CTS line activation interrupt. */
|
||||
NRF_UART_INT_MASK_NCTS = UART_INTENCLR_NCTS_Msk, /**< CTS line deactivation interrupt. */
|
||||
NRF_UART_INT_MASK_RXDRDY = UART_INTENCLR_RXDRDY_Msk, /**< Data ready in RXD interrupt. */
|
||||
NRF_UART_INT_MASK_TXDRDY = UART_INTENCLR_TXDRDY_Msk, /**< Data sent from TXD interrupt. */
|
||||
NRF_UART_INT_MASK_ERROR = UART_INTENCLR_ERROR_Msk, /**< Error detection interrupt. */
|
||||
NRF_UART_INT_MASK_RXTO = UART_INTENCLR_RXTO_Msk /**< Receiver timeout interrupt. */
|
||||
/*lint -restore*/
|
||||
} nrf_uart_int_mask_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_uart_baudrate_t
|
||||
* @brief Baudrates supported by UART.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_UART_BAUDRATE_1200 = UART_BAUDRATE_BAUDRATE_Baud1200, /**< 1200 baud. */
|
||||
NRF_UART_BAUDRATE_2400 = UART_BAUDRATE_BAUDRATE_Baud2400, /**< 2400 baud. */
|
||||
NRF_UART_BAUDRATE_4800 = UART_BAUDRATE_BAUDRATE_Baud4800, /**< 4800 baud. */
|
||||
NRF_UART_BAUDRATE_9600 = UART_BAUDRATE_BAUDRATE_Baud9600, /**< 9600 baud. */
|
||||
NRF_UART_BAUDRATE_14400 = UART_BAUDRATE_BAUDRATE_Baud14400, /**< 14400 baud. */
|
||||
NRF_UART_BAUDRATE_19200 = UART_BAUDRATE_BAUDRATE_Baud19200, /**< 19200 baud. */
|
||||
NRF_UART_BAUDRATE_28800 = UART_BAUDRATE_BAUDRATE_Baud28800, /**< 28800 baud. */
|
||||
NRF_UART_BAUDRATE_31250 = UART_BAUDRATE_BAUDRATE_Baud31250, /**< 31250 baud. */
|
||||
NRF_UART_BAUDRATE_38400 = UART_BAUDRATE_BAUDRATE_Baud38400, /**< 38400 baud. */
|
||||
NRF_UART_BAUDRATE_56000 = UART_BAUDRATE_BAUDRATE_Baud56000, /**< 56000 baud. */
|
||||
NRF_UART_BAUDRATE_57600 = UART_BAUDRATE_BAUDRATE_Baud57600, /**< 57600 baud. */
|
||||
NRF_UART_BAUDRATE_76800 = UART_BAUDRATE_BAUDRATE_Baud76800, /**< 76800 baud. */
|
||||
NRF_UART_BAUDRATE_115200 = UART_BAUDRATE_BAUDRATE_Baud115200, /**< 115200 baud. */
|
||||
NRF_UART_BAUDRATE_230400 = UART_BAUDRATE_BAUDRATE_Baud230400, /**< 230400 baud. */
|
||||
NRF_UART_BAUDRATE_250000 = UART_BAUDRATE_BAUDRATE_Baud250000, /**< 250000 baud. */
|
||||
NRF_UART_BAUDRATE_460800 = UART_BAUDRATE_BAUDRATE_Baud460800, /**< 460800 baud. */
|
||||
NRF_UART_BAUDRATE_921600 = UART_BAUDRATE_BAUDRATE_Baud921600, /**< 921600 baud. */
|
||||
NRF_UART_BAUDRATE_1000000 = UART_BAUDRATE_BAUDRATE_Baud1M, /**< 1000000 baud. */
|
||||
} nrf_uart_baudrate_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_uart_error_mask_t
|
||||
* @brief Types of UART error masks.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_UART_ERROR_OVERRUN_MASK = UART_ERRORSRC_OVERRUN_Msk, /**< Overrun error. */
|
||||
NRF_UART_ERROR_PARITY_MASK = UART_ERRORSRC_PARITY_Msk, /**< Parity error. */
|
||||
NRF_UART_ERROR_FRAMING_MASK = UART_ERRORSRC_FRAMING_Msk, /**< Framing error. */
|
||||
NRF_UART_ERROR_BREAK_MASK = UART_ERRORSRC_BREAK_Msk, /**< Break error. */
|
||||
} nrf_uart_error_mask_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_uart_parity_t
|
||||
* @brief Types of UART parity modes.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_UART_PARITY_EXCLUDED = UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos, /**< Parity excluded. */
|
||||
NRF_UART_PARITY_INCLUDED = UART_CONFIG_PARITY_Included << UART_CONFIG_PARITY_Pos, /**< Parity included. */
|
||||
} nrf_uart_parity_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_uart_hwfc_t
|
||||
* @brief Types of UART flow control modes.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_UART_HWFC_DISABLED = UART_CONFIG_HWFC_Disabled, /**< HW flow control disabled. */
|
||||
NRF_UART_HWFC_ENABLED = UART_CONFIG_HWFC_Enabled, /**< HW flow control enabled. */
|
||||
} nrf_uart_hwfc_t;
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a specific UART event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] event Event to clear.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uart_event_clear(NRF_UART_Type * p_reg, nrf_uart_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the state of a specific UART event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] event Event to check.
|
||||
*
|
||||
* @retval True if event is set, False otherwise.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_uart_event_check(NRF_UART_Type * p_reg, nrf_uart_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a specific UART event register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] event Desired event.
|
||||
*
|
||||
* @retval Address of specified event register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_uart_event_address_get(NRF_UART_Type * p_reg,
|
||||
nrf_uart_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling a specific interrupt.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param int_mask Interrupts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uart_int_enable(NRF_UART_Type * p_reg, uint32_t int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of a given interrupt.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param int_mask Mask of interrupt to check.
|
||||
*
|
||||
* @retval true If the interrupt is enabled.
|
||||
* @retval false If the interrupt is not enabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_uart_int_enable_check(NRF_UART_Type * p_reg, uint32_t int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling specific interrupts.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param int_mask Interrupts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uart_int_disable(NRF_UART_Type * p_reg, uint32_t int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for getting error source mask. Function is clearing error source flags after reading.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @return Mask with error source flags.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_uart_errorsrc_get_and_clear(NRF_UART_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling UART.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uart_enable(NRF_UART_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling UART.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uart_disable(NRF_UART_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for configuring TX/RX pins.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param pseltxd TXD pin number.
|
||||
* @param pselrxd RXD pin number.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uart_txrx_pins_set(NRF_UART_Type * p_reg, uint32_t pseltxd, uint32_t pselrxd);
|
||||
|
||||
/**
|
||||
* @brief Function for disconnecting TX/RX pins.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uart_txrx_pins_disconnect(NRF_UART_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for getting TX pin.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_uart_tx_pin_get(NRF_UART_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for getting RX pin.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_uart_rx_pin_get(NRF_UART_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for getting RTS pin.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_uart_rts_pin_get(NRF_UART_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for getting CTS pin.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_uart_cts_pin_get(NRF_UART_Type * p_reg);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for configuring flow control pins.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param pselrts RTS pin number.
|
||||
* @param pselcts CTS pin number.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uart_hwfc_pins_set(NRF_UART_Type * p_reg,
|
||||
uint32_t pselrts,
|
||||
uint32_t pselcts);
|
||||
|
||||
/**
|
||||
* @brief Function for disconnecting flow control pins.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uart_hwfc_pins_disconnect(NRF_UART_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for reading RX data.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @return Received byte.
|
||||
*/
|
||||
__STATIC_INLINE uint8_t nrf_uart_rxd_get(NRF_UART_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for setting Tx data.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param txd Byte.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uart_txd_set(NRF_UART_Type * p_reg, uint8_t txd);
|
||||
|
||||
/**
|
||||
* @brief Function for starting an UART task.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param task Task.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uart_task_trigger(NRF_UART_Type * p_reg, nrf_uart_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a specific task register.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param task Task.
|
||||
*
|
||||
* @return Task address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_uart_task_address_get(NRF_UART_Type * p_reg, nrf_uart_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for configuring UART.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param hwfc Hardware flow control. Enabled if true.
|
||||
* @param parity Parity. Included if true.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uart_configure(NRF_UART_Type * p_reg,
|
||||
nrf_uart_parity_t parity,
|
||||
nrf_uart_hwfc_t hwfc);
|
||||
|
||||
/**
|
||||
* @brief Function for setting UART baudrate.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param baudrate Baudrate.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uart_baudrate_set(NRF_UART_Type * p_reg, nrf_uart_baudrate_t baudrate);
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
__STATIC_INLINE void nrf_uart_event_clear(NRF_UART_Type * p_reg, nrf_uart_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_uart_event_check(NRF_UART_Type * p_reg, nrf_uart_event_t event)
|
||||
{
|
||||
return (bool)*(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_uart_event_address_get(NRF_UART_Type * p_reg,
|
||||
nrf_uart_event_t event)
|
||||
{
|
||||
return (uint32_t)((uint8_t *)p_reg + (uint32_t)event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uart_int_enable(NRF_UART_Type * p_reg, uint32_t int_mask)
|
||||
{
|
||||
p_reg->INTENSET = int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_uart_int_enable_check(NRF_UART_Type * p_reg, uint32_t int_mask)
|
||||
{
|
||||
return (bool)(p_reg->INTENSET & int_mask);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uart_int_disable(NRF_UART_Type * p_reg, uint32_t int_mask)
|
||||
{
|
||||
p_reg->INTENCLR = int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_uart_errorsrc_get_and_clear(NRF_UART_Type * p_reg)
|
||||
{
|
||||
uint32_t errsrc_mask = p_reg->ERRORSRC;
|
||||
p_reg->ERRORSRC = errsrc_mask;
|
||||
return errsrc_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uart_enable(NRF_UART_Type * p_reg)
|
||||
{
|
||||
p_reg->ENABLE = UART_ENABLE_ENABLE_Enabled;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uart_disable(NRF_UART_Type * p_reg)
|
||||
{
|
||||
p_reg->ENABLE = UART_ENABLE_ENABLE_Disabled;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uart_txrx_pins_set(NRF_UART_Type * p_reg, uint32_t pseltxd, uint32_t pselrxd)
|
||||
{
|
||||
#if defined(UART_PSEL_RXD_CONNECT_Pos)
|
||||
p_reg->PSEL.RXD = pselrxd;
|
||||
#else
|
||||
p_reg->PSELRXD = pselrxd;
|
||||
#endif
|
||||
#if defined(UART_PSEL_TXD_CONNECT_Pos)
|
||||
p_reg->PSEL.TXD = pseltxd;
|
||||
#else
|
||||
p_reg->PSELTXD = pseltxd;
|
||||
#endif
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uart_txrx_pins_disconnect(NRF_UART_Type * p_reg)
|
||||
{
|
||||
nrf_uart_txrx_pins_set(p_reg, NRF_UART_PSEL_DISCONNECTED, NRF_UART_PSEL_DISCONNECTED);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_uart_tx_pin_get(NRF_UART_Type * p_reg)
|
||||
{
|
||||
#if defined(UART_PSEL_TXD_CONNECT_Pos)
|
||||
return p_reg->PSEL.TXD;
|
||||
#else
|
||||
return p_reg->PSELTXD;
|
||||
#endif
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_uart_rx_pin_get(NRF_UART_Type * p_reg)
|
||||
{
|
||||
#if defined(UART_PSEL_RXD_CONNECT_Pos)
|
||||
return p_reg->PSEL.RXD;
|
||||
#else
|
||||
return p_reg->PSELRXD;
|
||||
#endif
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_uart_rts_pin_get(NRF_UART_Type * p_reg)
|
||||
{
|
||||
#if defined(UART_PSEL_RTS_CONNECT_Pos)
|
||||
return p_reg->PSEL.RTS;
|
||||
#else
|
||||
return p_reg->PSELRTS;
|
||||
#endif
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_uart_cts_pin_get(NRF_UART_Type * p_reg)
|
||||
{
|
||||
#if defined(UART_PSEL_RTS_CONNECT_Pos)
|
||||
return p_reg->PSEL.CTS;
|
||||
#else
|
||||
return p_reg->PSELCTS;
|
||||
#endif
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uart_hwfc_pins_set(NRF_UART_Type * p_reg, uint32_t pselrts, uint32_t pselcts)
|
||||
{
|
||||
#if defined(UART_PSEL_RTS_CONNECT_Pos)
|
||||
p_reg->PSEL.RTS = pselrts;
|
||||
#else
|
||||
p_reg->PSELRTS = pselrts;
|
||||
#endif
|
||||
|
||||
#if defined(UART_PSEL_RTS_CONNECT_Pos)
|
||||
p_reg->PSEL.CTS = pselcts;
|
||||
#else
|
||||
p_reg->PSELCTS = pselcts;
|
||||
#endif
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uart_hwfc_pins_disconnect(NRF_UART_Type * p_reg)
|
||||
{
|
||||
nrf_uart_hwfc_pins_set(p_reg, NRF_UART_PSEL_DISCONNECTED, NRF_UART_PSEL_DISCONNECTED);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint8_t nrf_uart_rxd_get(NRF_UART_Type * p_reg)
|
||||
{
|
||||
return p_reg->RXD;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uart_txd_set(NRF_UART_Type * p_reg, uint8_t txd)
|
||||
{
|
||||
p_reg->TXD = txd;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uart_task_trigger(NRF_UART_Type * p_reg, nrf_uart_task_t task)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task)) = 0x1UL;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_uart_task_address_get(NRF_UART_Type * p_reg, nrf_uart_task_t task)
|
||||
{
|
||||
return (uint32_t)p_reg + (uint32_t)task;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uart_configure(NRF_UART_Type * p_reg,
|
||||
nrf_uart_parity_t parity,
|
||||
nrf_uart_hwfc_t hwfc)
|
||||
{
|
||||
p_reg->CONFIG = (uint32_t)parity | (uint32_t)hwfc;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uart_baudrate_set(NRF_UART_Type * p_reg, nrf_uart_baudrate_t baudrate)
|
||||
{
|
||||
p_reg->BAUDRATE = baudrate;
|
||||
}
|
||||
#endif //SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //NRF_UART_H__
|
||||
@@ -0,0 +1,570 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_UARTE_H__
|
||||
#define NRF_UARTE_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define NRF_UARTE_PSEL_DISCONNECTED 0xFFFFFFFF
|
||||
|
||||
/**
|
||||
* @defgroup nrf_uarte_hal UARTE HAL
|
||||
* @{
|
||||
* @ingroup nrf_uarte
|
||||
* @brief Hardware access layer for managing the UARTE peripheral.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @enum nrf_uarte_task_t
|
||||
* @brief UARTE tasks.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
NRF_UARTE_TASK_STARTRX = offsetof(NRF_UARTE_Type, TASKS_STARTRX), ///< Start UART receiver.
|
||||
NRF_UARTE_TASK_STOPRX = offsetof(NRF_UARTE_Type, TASKS_STOPRX), ///< Stop UART receiver.
|
||||
NRF_UARTE_TASK_STARTTX = offsetof(NRF_UARTE_Type, TASKS_STARTTX), ///< Start UART transmitter.
|
||||
NRF_UARTE_TASK_STOPTX = offsetof(NRF_UARTE_Type, TASKS_STOPTX), ///< Stop UART transmitter.
|
||||
NRF_UARTE_TASK_FLUSHRX = offsetof(NRF_UARTE_Type, TASKS_FLUSHRX) ///< Flush RX FIFO in RX buffer.
|
||||
/*lint -restore*/
|
||||
} nrf_uarte_task_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_uarte_event_t
|
||||
* @brief UARTE events.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
NRF_UARTE_EVENT_CTS = offsetof(NRF_UARTE_Type, EVENTS_CTS), ///< CTS is activated.
|
||||
NRF_UARTE_EVENT_NCTS = offsetof(NRF_UARTE_Type, EVENTS_NCTS), ///< CTS is deactivated.
|
||||
NRF_UARTE_EVENT_RXDRDY = offsetof(NRF_UARTE_Type, EVENTS_RXDRDY), ///< Data received in RXD (but potentially not yet transferred to Data RAM).
|
||||
NRF_UARTE_EVENT_ENDRX = offsetof(NRF_UARTE_Type, EVENTS_ENDRX), ///< Receive buffer is filled up.
|
||||
NRF_UARTE_EVENT_TXDRDY = offsetof(NRF_UARTE_Type, EVENTS_TXDRDY), ///< Data sent from TXD.
|
||||
NRF_UARTE_EVENT_ENDTX = offsetof(NRF_UARTE_Type, EVENTS_ENDTX), ///< Last TX byte transmitted.
|
||||
NRF_UARTE_EVENT_ERROR = offsetof(NRF_UARTE_Type, EVENTS_ERROR), ///< Error detected.
|
||||
NRF_UARTE_EVENT_RXTO = offsetof(NRF_UARTE_Type, EVENTS_RXTO), ///< Receiver timeout.
|
||||
NRF_UARTE_EVENT_RXSTARTED = offsetof(NRF_UARTE_Type, EVENTS_RXSTARTED), ///< Receiver has started.
|
||||
NRF_UARTE_EVENT_TXSTARTED = offsetof(NRF_UARTE_Type, EVENTS_TXSTARTED), ///< Transmitter has started.
|
||||
NRF_UARTE_EVENT_TXSTOPPED = offsetof(NRF_UARTE_Type, EVENTS_TXSTOPPED) ///< Transmitted stopped.
|
||||
/*lint -restore*/
|
||||
} nrf_uarte_event_t;
|
||||
|
||||
/**
|
||||
* @brief Types of UARTE shortcuts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_UARTE_SHORT_ENDRX_STARTRX = UARTE_SHORTS_ENDRX_STARTRX_Msk, ///< Shortcut between ENDRX event and STARTRX task.
|
||||
NRF_UARTE_SHORT_ENDRX_STOPRX = UARTE_SHORTS_ENDRX_STOPRX_Msk ///< Shortcut between ENDRX event and STOPRX task.
|
||||
} nrf_uarte_short_t;
|
||||
|
||||
|
||||
/**
|
||||
* @enum nrf_uarte_int_mask_t
|
||||
* @brief UARTE interrupts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_UARTE_INT_CTS_MASK = UARTE_INTENSET_CTS_Msk, ///< Interrupt on CTS event.
|
||||
NRF_UARTE_INT_NCTS_MASK = UARTE_INTENSET_NCTS_Msk, ///< Interrupt on NCTS event.
|
||||
NRF_UARTE_INT_RXDRDY_MASK = UARTE_INTENSET_RXDRDY_Msk, ///< Interrupt on RXDRDY event.
|
||||
NRF_UARTE_INT_ENDRX_MASK = UARTE_INTENSET_ENDRX_Msk, ///< Interrupt on ENDRX event.
|
||||
NRF_UARTE_INT_TXDRDY_MASK = UARTE_INTENSET_TXDRDY_Msk, ///< Interrupt on TXDRDY event.
|
||||
NRF_UARTE_INT_ENDTX_MASK = UARTE_INTENSET_ENDTX_Msk, ///< Interrupt on ENDTX event.
|
||||
NRF_UARTE_INT_ERROR_MASK = UARTE_INTENSET_ERROR_Msk, ///< Interrupt on ERROR event.
|
||||
NRF_UARTE_INT_RXTO_MASK = UARTE_INTENSET_RXTO_Msk, ///< Interrupt on RXTO event.
|
||||
NRF_UARTE_INT_RXSTARTED_MASK = UARTE_INTENSET_RXSTARTED_Msk, ///< Interrupt on RXSTARTED event.
|
||||
NRF_UARTE_INT_TXSTARTED_MASK = UARTE_INTENSET_TXSTARTED_Msk, ///< Interrupt on TXSTARTED event.
|
||||
NRF_UARTE_INT_TXSTOPPED_MASK = UARTE_INTENSET_TXSTOPPED_Msk ///< Interrupt on TXSTOPPED event.
|
||||
} nrf_uarte_int_mask_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_uarte_baudrate_t
|
||||
* @brief Baudrates supported by UARTE.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_UARTE_BAUDRATE_1200 = UARTE_BAUDRATE_BAUDRATE_Baud1200, ///< 1200 baud.
|
||||
NRF_UARTE_BAUDRATE_2400 = UARTE_BAUDRATE_BAUDRATE_Baud2400, ///< 2400 baud.
|
||||
NRF_UARTE_BAUDRATE_4800 = UARTE_BAUDRATE_BAUDRATE_Baud4800, ///< 4800 baud.
|
||||
NRF_UARTE_BAUDRATE_9600 = UARTE_BAUDRATE_BAUDRATE_Baud9600, ///< 9600 baud.
|
||||
NRF_UARTE_BAUDRATE_14400 = UARTE_BAUDRATE_BAUDRATE_Baud14400, ///< 14400 baud.
|
||||
NRF_UARTE_BAUDRATE_19200 = UARTE_BAUDRATE_BAUDRATE_Baud19200, ///< 19200 baud.
|
||||
NRF_UARTE_BAUDRATE_28800 = UARTE_BAUDRATE_BAUDRATE_Baud28800, ///< 28800 baud.
|
||||
NRF_UARTE_BAUDRATE_31250 = UARTE_BAUDRATE_BAUDRATE_Baud31250, ///< 31250 baud.
|
||||
NRF_UARTE_BAUDRATE_38400 = UARTE_BAUDRATE_BAUDRATE_Baud38400, ///< 38400 baud.
|
||||
NRF_UARTE_BAUDRATE_56000 = UARTE_BAUDRATE_BAUDRATE_Baud56000, ///< 56000 baud.
|
||||
NRF_UARTE_BAUDRATE_57600 = UARTE_BAUDRATE_BAUDRATE_Baud57600, ///< 57600 baud.
|
||||
NRF_UARTE_BAUDRATE_76800 = UARTE_BAUDRATE_BAUDRATE_Baud76800, ///< 76800 baud.
|
||||
NRF_UARTE_BAUDRATE_115200 = UARTE_BAUDRATE_BAUDRATE_Baud115200, ///< 115200 baud.
|
||||
NRF_UARTE_BAUDRATE_230400 = UARTE_BAUDRATE_BAUDRATE_Baud230400, ///< 230400 baud.
|
||||
NRF_UARTE_BAUDRATE_250000 = UARTE_BAUDRATE_BAUDRATE_Baud250000, ///< 250000 baud.
|
||||
NRF_UARTE_BAUDRATE_460800 = UARTE_BAUDRATE_BAUDRATE_Baud460800, ///< 460800 baud.
|
||||
NRF_UARTE_BAUDRATE_921600 = UARTE_BAUDRATE_BAUDRATE_Baud921600, ///< 921600 baud.
|
||||
NRF_UARTE_BAUDRATE_1000000 = UARTE_BAUDRATE_BAUDRATE_Baud1M ///< 1000000 baud.
|
||||
} nrf_uarte_baudrate_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_uarte_error_mask_t
|
||||
* @brief Types of UARTE error masks.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_UARTE_ERROR_OVERRUN_MASK = UARTE_ERRORSRC_OVERRUN_Msk, ///< Overrun error.
|
||||
NRF_UARTE_ERROR_PARITY_MASK = UARTE_ERRORSRC_PARITY_Msk, ///< Parity error.
|
||||
NRF_UARTE_ERROR_FRAMING_MASK = UARTE_ERRORSRC_FRAMING_Msk, ///< Framing error.
|
||||
NRF_UARTE_ERROR_BREAK_MASK = UARTE_ERRORSRC_BREAK_Msk ///< Break error.
|
||||
} nrf_uarte_error_mask_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_uarte_parity_t
|
||||
* @brief Types of UARTE parity modes.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_UARTE_PARITY_EXCLUDED = UARTE_CONFIG_PARITY_Excluded << UARTE_CONFIG_PARITY_Pos, ///< Parity excluded.
|
||||
NRF_UARTE_PARITY_INCLUDED = UARTE_CONFIG_PARITY_Included << UARTE_CONFIG_PARITY_Pos ///< Parity included.
|
||||
} nrf_uarte_parity_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_uarte_hwfc_t
|
||||
* @brief Types of UARTE flow control modes.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_UARTE_HWFC_DISABLED = UARTE_CONFIG_HWFC_Disabled << UARTE_CONFIG_HWFC_Pos, ///< HW flow control disabled.
|
||||
NRF_UARTE_HWFC_ENABLED = UARTE_CONFIG_HWFC_Enabled << UARTE_CONFIG_HWFC_Pos ///< HW flow control enabled.
|
||||
} nrf_uarte_hwfc_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a specific UARTE event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] event Event to clear.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uarte_event_clear(NRF_UARTE_Type * p_reg, nrf_uarte_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the state of a specific UARTE event.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] event Event to check.
|
||||
*
|
||||
* @retval True if event is set, False otherwise.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_uarte_event_check(NRF_UARTE_Type * p_reg, nrf_uarte_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a specific UARTE event register.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @param[in] event Desired event.
|
||||
*
|
||||
* @retval Address of specified event register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_uarte_event_address_get(NRF_UARTE_Type * p_reg,
|
||||
nrf_uarte_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling UARTE shortcuts.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param shorts_mask Shortcuts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uarte_shorts_enable(NRF_UARTE_Type * p_reg, uint32_t shorts_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling UARTE shortcuts.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param shorts_mask Shortcuts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uarte_shorts_disable(NRF_UARTE_Type * p_reg, uint32_t shorts_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling UARTE interrupts.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param int_mask Interrupts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uarte_int_enable(NRF_UARTE_Type * p_reg, uint32_t int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of a given interrupt.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param int_mask Mask of interrupt to check.
|
||||
*
|
||||
* @retval true If the interrupt is enabled.
|
||||
* @retval false If the interrupt is not enabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_uarte_int_enable_check(NRF_UARTE_Type * p_reg, nrf_uarte_int_mask_t int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling specific interrupts.
|
||||
*
|
||||
* @param p_reg Instance.
|
||||
* @param int_mask Interrupts to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uarte_int_disable(NRF_UARTE_Type * p_reg, uint32_t int_mask);
|
||||
|
||||
/**
|
||||
* @brief Function for getting error source mask. Function is clearing error source flags after reading.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @return Mask with error source flags.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_uarte_errorsrc_get_and_clear(NRF_UARTE_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling UARTE.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uarte_enable(NRF_UARTE_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling UARTE.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uarte_disable(NRF_UARTE_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for configuring TX/RX pins.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param pseltxd TXD pin number.
|
||||
* @param pselrxd RXD pin number.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uarte_txrx_pins_set(NRF_UARTE_Type * p_reg, uint32_t pseltxd, uint32_t pselrxd);
|
||||
|
||||
/**
|
||||
* @brief Function for disconnecting TX/RX pins.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uarte_txrx_pins_disconnect(NRF_UARTE_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for getting TX pin.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_uarte_tx_pin_get(NRF_UARTE_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for getting RX pin.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_uarte_rx_pin_get(NRF_UARTE_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for getting RTS pin.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_uarte_rts_pin_get(NRF_UARTE_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for getting CTS pin.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_uarte_cts_pin_get(NRF_UARTE_Type * p_reg);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for configuring flow control pins.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param pselrts RTS pin number.
|
||||
* @param pselcts CTS pin number.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uarte_hwfc_pins_set(NRF_UARTE_Type * p_reg,
|
||||
uint32_t pselrts,
|
||||
uint32_t pselcts);
|
||||
|
||||
/**
|
||||
* @brief Function for disconnecting flow control pins.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uarte_hwfc_pins_disconnect(NRF_UARTE_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for starting an UARTE task.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param task Task.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uarte_task_trigger(NRF_UARTE_Type * p_reg, nrf_uarte_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a specific task register.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param task Task.
|
||||
*
|
||||
* @return Task address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_uarte_task_address_get(NRF_UARTE_Type * p_reg, nrf_uarte_task_t task);
|
||||
|
||||
/**
|
||||
* @brief Function for configuring UARTE.
|
||||
*
|
||||
* @param p_reg Pointer to the peripheral registers structure.
|
||||
* @param hwfc Hardware flow control. Enabled if true.
|
||||
* @param parity Parity. Included if true.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uarte_configure(NRF_UARTE_Type * p_reg,
|
||||
nrf_uarte_parity_t parity,
|
||||
nrf_uarte_hwfc_t hwfc);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for setting UARTE baudrate.
|
||||
*
|
||||
* @param p_reg Instance.
|
||||
* @param baudrate Baudrate.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uarte_baudrate_set(NRF_UARTE_Type * p_reg, nrf_uarte_baudrate_t baudrate);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the transmit buffer.
|
||||
*
|
||||
* @param[in] p_reg Instance.
|
||||
* @param[in] p_buffer Pointer to the buffer with data to send.
|
||||
* @param[in] length Maximum number of data bytes to transmit.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_uarte_tx_buffer_set(NRF_UARTE_Type * p_reg,
|
||||
uint8_t const * p_buffer,
|
||||
size_t length);
|
||||
|
||||
/**
|
||||
* @brief Function for getting number of bytes transmitted in the last transaction.
|
||||
*
|
||||
* @param[in] p_reg Instance.
|
||||
*
|
||||
* @retval Amount of bytes transmitted.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_uarte_tx_amount_get(NRF_UARTE_Type * p_reg);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the receive buffer.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
* @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_uarte_rx_buffer_set(NRF_UARTE_Type * p_reg,
|
||||
uint8_t * p_buffer,
|
||||
size_t length);
|
||||
|
||||
/**
|
||||
* @brief Function for getting number of bytes received in the last transaction.
|
||||
*
|
||||
* @param[in] p_reg Pointer to the peripheral registers structure.
|
||||
*
|
||||
* @retval Amount of bytes received.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_uarte_rx_amount_get(NRF_UARTE_Type * p_reg);
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
__STATIC_INLINE void nrf_uarte_event_clear(NRF_UARTE_Type * p_reg, nrf_uarte_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_uarte_event_check(NRF_UARTE_Type * p_reg, nrf_uarte_event_t event)
|
||||
{
|
||||
return (bool)*(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_uarte_event_address_get(NRF_UARTE_Type * p_reg,
|
||||
nrf_uarte_event_t event)
|
||||
{
|
||||
return (uint32_t)((uint8_t *)p_reg + (uint32_t)event);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uarte_shorts_enable(NRF_UARTE_Type * p_reg, uint32_t shorts_mask)
|
||||
{
|
||||
p_reg->SHORTS |= shorts_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uarte_shorts_disable(NRF_UARTE_Type * p_reg, uint32_t shorts_mask)
|
||||
{
|
||||
p_reg->SHORTS &= ~(shorts_mask);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uarte_int_enable(NRF_UARTE_Type * p_reg, uint32_t int_mask)
|
||||
{
|
||||
p_reg->INTENSET = int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_uarte_int_enable_check(NRF_UARTE_Type * p_reg, nrf_uarte_int_mask_t int_mask)
|
||||
{
|
||||
return (bool)(p_reg->INTENSET & int_mask);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uarte_int_disable(NRF_UARTE_Type * p_reg, uint32_t int_mask)
|
||||
{
|
||||
p_reg->INTENCLR = int_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_uarte_errorsrc_get_and_clear(NRF_UARTE_Type * p_reg)
|
||||
{
|
||||
uint32_t errsrc_mask = p_reg->ERRORSRC;
|
||||
p_reg->ERRORSRC = errsrc_mask;
|
||||
return errsrc_mask;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uarte_enable(NRF_UARTE_Type * p_reg)
|
||||
{
|
||||
p_reg->ENABLE = UARTE_ENABLE_ENABLE_Enabled;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uarte_disable(NRF_UARTE_Type * p_reg)
|
||||
{
|
||||
p_reg->ENABLE = UARTE_ENABLE_ENABLE_Disabled;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uarte_txrx_pins_set(NRF_UARTE_Type * p_reg, uint32_t pseltxd, uint32_t pselrxd)
|
||||
{
|
||||
p_reg->PSEL.TXD = pseltxd;
|
||||
p_reg->PSEL.RXD = pselrxd;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uarte_txrx_pins_disconnect(NRF_UARTE_Type * p_reg)
|
||||
{
|
||||
nrf_uarte_txrx_pins_set(p_reg, NRF_UARTE_PSEL_DISCONNECTED, NRF_UARTE_PSEL_DISCONNECTED);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_uarte_tx_pin_get(NRF_UARTE_Type * p_reg)
|
||||
{
|
||||
return p_reg->PSEL.TXD;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_uarte_rx_pin_get(NRF_UARTE_Type * p_reg)
|
||||
{
|
||||
return p_reg->PSEL.RXD;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_uarte_rts_pin_get(NRF_UARTE_Type * p_reg)
|
||||
{
|
||||
return p_reg->PSEL.RTS;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_uarte_cts_pin_get(NRF_UARTE_Type * p_reg)
|
||||
{
|
||||
return p_reg->PSEL.CTS;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uarte_hwfc_pins_set(NRF_UARTE_Type * p_reg, uint32_t pselrts, uint32_t pselcts)
|
||||
{
|
||||
p_reg->PSEL.RTS = pselrts;
|
||||
p_reg->PSEL.CTS = pselcts;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uarte_hwfc_pins_disconnect(NRF_UARTE_Type * p_reg)
|
||||
{
|
||||
nrf_uarte_hwfc_pins_set(p_reg, NRF_UARTE_PSEL_DISCONNECTED, NRF_UARTE_PSEL_DISCONNECTED);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uarte_task_trigger(NRF_UARTE_Type * p_reg, nrf_uarte_task_t task)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task)) = 0x1UL;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_uarte_task_address_get(NRF_UARTE_Type * p_reg, nrf_uarte_task_t task)
|
||||
{
|
||||
return (uint32_t)p_reg + (uint32_t)task;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uarte_configure(NRF_UARTE_Type * p_reg,
|
||||
nrf_uarte_parity_t parity,
|
||||
nrf_uarte_hwfc_t hwfc)
|
||||
{
|
||||
p_reg->CONFIG = (uint32_t)parity | (uint32_t)hwfc;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uarte_baudrate_set(NRF_UARTE_Type * p_reg, nrf_uarte_baudrate_t baudrate)
|
||||
{
|
||||
p_reg->BAUDRATE = baudrate;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uarte_tx_buffer_set(NRF_UARTE_Type * p_reg,
|
||||
uint8_t const * p_buffer,
|
||||
size_t length)
|
||||
{
|
||||
p_reg->TXD.PTR = (uint32_t)p_buffer;
|
||||
p_reg->TXD.MAXCNT = length;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_uarte_tx_amount_get(NRF_UARTE_Type * p_reg)
|
||||
{
|
||||
return p_reg->TXD.AMOUNT;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_uarte_rx_buffer_set(NRF_UARTE_Type * p_reg,
|
||||
uint8_t * p_buffer,
|
||||
size_t length)
|
||||
{
|
||||
p_reg->RXD.PTR = (uint32_t)p_buffer;
|
||||
p_reg->RXD.MAXCNT = length;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_uarte_rx_amount_get(NRF_UARTE_Type * p_reg)
|
||||
{
|
||||
return p_reg->RXD.AMOUNT;
|
||||
}
|
||||
#endif //SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //NRF_UARTE_H__
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,324 @@
|
||||
/*
|
||||
* 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 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 the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_WDT_H__
|
||||
#define NRF_WDT_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_wdt_hal WDT HAL
|
||||
* @{
|
||||
* @ingroup nrf_wdt
|
||||
* @brief Hardware access layer for managing the Watchdog Timer (WDT) peripheral.
|
||||
*/
|
||||
|
||||
#define NRF_WDT_CHANNEL_NUMBER 0x8UL
|
||||
#define NRF_WDT_RR_VALUE 0x6E524635UL /* Fixed value, shouldn't be modified.*/
|
||||
|
||||
#define NRF_WDT_TASK_SET 1UL
|
||||
#define NRF_WDT_EVENT_CLEAR 0UL
|
||||
|
||||
/**
|
||||
* @enum nrf_wdt_task_t
|
||||
* @brief WDT tasks.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30 -esym(628,__INTADDR__)*/
|
||||
NRF_WDT_TASK_START = offsetof(NRF_WDT_Type, TASKS_START), /**< Task for starting WDT. */
|
||||
/*lint -restore*/
|
||||
} nrf_wdt_task_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_wdt_event_t
|
||||
* @brief WDT events.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*lint -save -e30*/
|
||||
NRF_WDT_EVENT_TIMEOUT = offsetof(NRF_WDT_Type, EVENTS_TIMEOUT), /**< Event from WDT time-out. */
|
||||
/*lint -restore*/
|
||||
} nrf_wdt_event_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_wdt_behaviour_t
|
||||
* @brief WDT behavior in CPU SLEEP or HALT mode.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_WDT_BEHAVIOUR_RUN_SLEEP = WDT_CONFIG_SLEEP_Msk, /**< WDT will run when CPU is in SLEEP mode. */
|
||||
NRF_WDT_BEHAVIOUR_RUN_HALT = WDT_CONFIG_HALT_Msk, /**< WDT will run when CPU is in HALT mode. */
|
||||
NRF_WDT_BEHAVIOUR_RUN_SLEEP_HALT = WDT_CONFIG_SLEEP_Msk | WDT_CONFIG_HALT_Msk, /**< WDT will run when CPU is in SLEEP or HALT mode. */
|
||||
NRF_WDT_BEHAVIOUR_PAUSE_SLEEP_HALT = 0, /**< WDT will be paused when CPU is in SLEEP or HALT mode. */
|
||||
} nrf_wdt_behaviour_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_wdt_rr_register_t
|
||||
* @brief WDT reload request registers.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_WDT_RR0 = 0, /**< Reload request register 0. */
|
||||
NRF_WDT_RR1, /**< Reload request register 1. */
|
||||
NRF_WDT_RR2, /**< Reload request register 2. */
|
||||
NRF_WDT_RR3, /**< Reload request register 3. */
|
||||
NRF_WDT_RR4, /**< Reload request register 4. */
|
||||
NRF_WDT_RR5, /**< Reload request register 5. */
|
||||
NRF_WDT_RR6, /**< Reload request register 6. */
|
||||
NRF_WDT_RR7 /**< Reload request register 7. */
|
||||
} nrf_wdt_rr_register_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_wdt_int_mask_t
|
||||
* @brief WDT interrupts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_WDT_INT_TIMEOUT_MASK = WDT_INTENSET_TIMEOUT_Msk, /**< WDT interrupt from time-out event. */
|
||||
} nrf_wdt_int_mask_t;
|
||||
|
||||
/**
|
||||
* @brief Function for configuring the watchdog behavior when the CPU is sleeping or halted.
|
||||
*
|
||||
* @param behaviour Watchdog behavior when CPU is in SLEEP or HALT mode.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_wdt_behaviour_set(nrf_wdt_behaviour_t behaviour)
|
||||
{
|
||||
NRF_WDT->CONFIG = behaviour;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for starting the watchdog.
|
||||
*
|
||||
* @param[in] task Task.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_wdt_task_trigger(nrf_wdt_task_t task)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)NRF_WDT + task)) = NRF_WDT_TASK_SET;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for clearing the WDT event.
|
||||
*
|
||||
* @param[in] event Event.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_wdt_event_clear(nrf_wdt_event_t event)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)NRF_WDT + (uint32_t)event)) = NRF_WDT_EVENT_CLEAR;
|
||||
#if __CORTEX_M == 0x04
|
||||
volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_WDT + (uint32_t)event));
|
||||
(void)dummy;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of the WDT event.
|
||||
*
|
||||
* @param[in] event Event.
|
||||
*
|
||||
* @retval true If the event is set.
|
||||
* @retval false If the event is not set.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_wdt_event_check(nrf_wdt_event_t event)
|
||||
{
|
||||
return (bool)*((volatile uint32_t *)((uint8_t *)NRF_WDT + event));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for enabling a specific interrupt.
|
||||
*
|
||||
* @param[in] int_mask Interrupt.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_wdt_int_enable(uint32_t int_mask)
|
||||
{
|
||||
NRF_WDT->INTENSET = int_mask;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the state of given interrupt.
|
||||
*
|
||||
* @param[in] int_mask Interrupt.
|
||||
*
|
||||
* @retval true Interrupt is enabled.
|
||||
* @retval false Interrupt is not enabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_wdt_int_enable_check(uint32_t int_mask)
|
||||
{
|
||||
return (bool)(NRF_WDT->INTENSET & int_mask);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for disabling a specific interrupt.
|
||||
*
|
||||
* @param[in] int_mask Interrupt.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_wdt_int_disable(uint32_t int_mask)
|
||||
{
|
||||
NRF_WDT->INTENCLR = int_mask;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a specific WDT task register.
|
||||
*
|
||||
* @param[in] task Task.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_wdt_task_address_get(nrf_wdt_task_t task)
|
||||
{
|
||||
return ((uint32_t)NRF_WDT + task);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a specific WDT event register.
|
||||
*
|
||||
* @param[in] event Event.
|
||||
*
|
||||
* @retval address of requested event register
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_wdt_event_address_get(nrf_wdt_event_t event)
|
||||
{
|
||||
return ((uint32_t)NRF_WDT + event);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the watchdog status.
|
||||
*
|
||||
* @retval true If the watchdog is started.
|
||||
* @retval false If the watchdog is not started.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_wdt_started(void)
|
||||
{
|
||||
return (bool)(NRF_WDT->RUNSTATUS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the watchdog reload request status.
|
||||
*
|
||||
* @param[in] rr_register Reload request register to check.
|
||||
*
|
||||
* @retval true If a reload request is running.
|
||||
* @retval false If no reload request is running.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_wdt_request_status(nrf_wdt_rr_register_t rr_register)
|
||||
{
|
||||
return (bool)(((NRF_WDT->REQSTATUS) >> rr_register) & 0x1UL);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for setting the watchdog reload value.
|
||||
*
|
||||
* @param[in] reload_value Watchdog counter initial value.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_wdt_reload_value_set(uint32_t reload_value)
|
||||
{
|
||||
NRF_WDT->CRV = reload_value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the watchdog reload value.
|
||||
*
|
||||
* @retval Reload value.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_wdt_reload_value_get(void)
|
||||
{
|
||||
return (uint32_t)NRF_WDT->CRV;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for enabling a specific reload request register.
|
||||
*
|
||||
* @param[in] rr_register Reload request register to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_wdt_reload_request_enable(nrf_wdt_rr_register_t rr_register)
|
||||
{
|
||||
NRF_WDT->RREN |= 0x1UL << rr_register;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for disabling a specific reload request register.
|
||||
*
|
||||
* @param[in] rr_register Reload request register to disable.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_wdt_reload_request_disable(nrf_wdt_rr_register_t rr_register)
|
||||
{
|
||||
NRF_WDT->RREN &= ~(0x1UL << rr_register);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the status of a specific reload request register.
|
||||
*
|
||||
* @param[in] rr_register Reload request register to check.
|
||||
*
|
||||
* @retval true If the reload request register is enabled.
|
||||
* @retval false If the reload request register is not enabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_wdt_reload_request_is_enabled(nrf_wdt_rr_register_t rr_register)
|
||||
{
|
||||
return (bool)(NRF_WDT->RREN & (0x1UL << rr_register));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for setting a specific reload request register.
|
||||
*
|
||||
* @param[in] rr_register Reload request register to set.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_wdt_reload_request_set(nrf_wdt_rr_register_t rr_register)
|
||||
{
|
||||
NRF_WDT->RR[rr_register] = NRF_WDT_RR_VALUE;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2010 - 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 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.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, 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 _COMPILER_ABSTRACTION_H
|
||||
#define _COMPILER_ABSTRACTION_H
|
||||
|
||||
/*lint ++flb "Enter library region" */
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
|
||||
#ifndef __ASM
|
||||
#define __ASM __asm
|
||||
#endif
|
||||
|
||||
#ifndef __INLINE
|
||||
#define __INLINE __inline
|
||||
#endif
|
||||
|
||||
#ifndef __WEAK
|
||||
#define __WEAK __weak
|
||||
#endif
|
||||
|
||||
#ifndef __ALIGN
|
||||
#define __ALIGN(n) __align(n)
|
||||
#endif
|
||||
|
||||
#ifndef __PACKED
|
||||
#define __PACKED __packed
|
||||
#endif
|
||||
|
||||
#define GET_SP() __current_sp()
|
||||
|
||||
#elif defined ( __ICCARM__ )
|
||||
|
||||
#ifndef __ASM
|
||||
#define __ASM __asm
|
||||
#endif
|
||||
|
||||
#ifndef __INLINE
|
||||
#define __INLINE inline
|
||||
#endif
|
||||
|
||||
#ifndef __WEAK
|
||||
#define __WEAK __weak
|
||||
#endif
|
||||
|
||||
#ifndef __ALIGN
|
||||
#define STRING_PRAGMA(x) _Pragma(#x)
|
||||
#define __ALIGN(n) STRING_PRAGMA(data_alignment = n)
|
||||
#endif
|
||||
|
||||
#ifndef __PACKED
|
||||
#define __PACKED __packed
|
||||
#endif
|
||||
|
||||
#define GET_SP() __get_SP()
|
||||
|
||||
#elif defined ( __GNUC__ )
|
||||
|
||||
#ifndef __ASM
|
||||
#define __ASM __asm
|
||||
#endif
|
||||
|
||||
#ifndef __INLINE
|
||||
#define __INLINE inline
|
||||
#endif
|
||||
|
||||
#ifndef __WEAK
|
||||
#define __WEAK __attribute__((weak))
|
||||
#endif
|
||||
|
||||
#ifndef __ALIGN
|
||||
#define __ALIGN(n) __attribute__((aligned(n)))
|
||||
#endif
|
||||
|
||||
#ifndef __PACKED
|
||||
#define __PACKED __attribute__((packed))
|
||||
#endif
|
||||
|
||||
#define GET_SP() gcc_current_sp()
|
||||
|
||||
static inline unsigned int gcc_current_sp(void)
|
||||
{
|
||||
register unsigned sp __ASM("sp");
|
||||
return sp;
|
||||
}
|
||||
|
||||
#elif defined ( __TASKING__ )
|
||||
|
||||
#ifndef __ASM
|
||||
#define __ASM __asm
|
||||
#endif
|
||||
|
||||
#ifndef __INLINE
|
||||
#define __INLINE inline
|
||||
#endif
|
||||
|
||||
#ifndef __WEAK
|
||||
#define __WEAK __attribute__((weak))
|
||||
#endif
|
||||
|
||||
#ifndef __ALIGN
|
||||
#define __ALIGN(n) __align(n)
|
||||
#endif
|
||||
|
||||
/* Not defined for TASKING. */
|
||||
#ifndef __PACKED
|
||||
#define __PACKED
|
||||
#endif
|
||||
|
||||
#define GET_SP() __get_MSP()
|
||||
|
||||
#endif
|
||||
|
||||
/*lint --flb "Leave library region" */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2010 - 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 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.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, 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_H
|
||||
#define NRF_H
|
||||
|
||||
/* MDK version */
|
||||
#define MDK_MAJOR_VERSION 8
|
||||
#define MDK_MINOR_VERSION 17
|
||||
#define MDK_MICRO_VERSION 0
|
||||
|
||||
/* Redefine "old" too-generic name NRF52 to NRF52832_XXAA to keep backwards compatibility. */
|
||||
#if defined (NRF52)
|
||||
#ifndef NRF52832_XXAA
|
||||
#define NRF52832_XXAA
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Define NRF52_SERIES for common use in nRF52 series devices. Only if not previously defined. */
|
||||
#if defined (NRF52810_XXAA) || defined (NRF52832_XXAA) || defined (NRF52832_XXAB) || defined (NRF52840_XXAA)
|
||||
#ifndef NRF52_SERIES
|
||||
#define NRF52_SERIES
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(_WIN32)
|
||||
/* Do not include nrf specific files when building for PC host */
|
||||
#elif defined(__unix)
|
||||
/* Do not include nrf specific files when building for PC host */
|
||||
#elif defined(__APPLE__)
|
||||
/* Do not include nrf specific files when building for PC host */
|
||||
#else
|
||||
|
||||
/* Device selection for device includes. */
|
||||
#if defined (NRF51)
|
||||
#include "nrf51.h"
|
||||
#include "nrf51_bitfields.h"
|
||||
#include "nrf51_deprecated.h"
|
||||
|
||||
#elif defined (NRF52810_XXAA)
|
||||
#include "nrf52810.h"
|
||||
#include "nrf52810_bitfields.h"
|
||||
#include "nrf51_to_nrf52810.h"
|
||||
#include "nrf52_to_nrf52810.h"
|
||||
#elif defined (NRF52832_XXAA) || defined (NRF52832_XXAB)
|
||||
#include "nrf52.h"
|
||||
#include "nrf52_bitfields.h"
|
||||
#include "nrf51_to_nrf52.h"
|
||||
#include "nrf52_name_change.h"
|
||||
#elif defined (NRF52840_XXAA)
|
||||
#include "nrf52840.h"
|
||||
#include "nrf52840_bitfields.h"
|
||||
#include "nrf51_to_nrf52840.h"
|
||||
#include "nrf52_to_nrf52840.h"
|
||||
|
||||
#else
|
||||
#error "Device must be defined. See nrf.h."
|
||||
#endif /* NRF51, NRF52810_XXAA, NRF52832_XXAA, NRF52832_XXAB, NRF52840_XXAA */
|
||||
|
||||
#include "compiler_abstraction.h"
|
||||
|
||||
#endif /* _WIN32 || __unix || __APPLE__ */
|
||||
|
||||
#endif /* NRF_H */
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2010 - 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 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.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, 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.
|
||||
|
||||
*/
|
||||
|
||||
/* This file is deprecated */
|
||||
#ifndef _NRF51422_PERIPHERALS_H
|
||||
#define _NRF51422_PERIPHERALS_H
|
||||
|
||||
|
||||
/* Power Peripheral */
|
||||
#define POWER_PRESENT
|
||||
#define POWER_COUNT 1
|
||||
|
||||
#define POWER_FEATURE_RAMON_REGISTERS_PRESENT
|
||||
|
||||
/* Software Interrupts */
|
||||
#define SWI_PRESENT
|
||||
#define SWI_COUNT 6
|
||||
|
||||
/* GPIO */
|
||||
#define GPIO_PRESENT
|
||||
#define GPIO_COUNT 1
|
||||
|
||||
#define P0_PIN_NUM 32
|
||||
|
||||
/* MPU and BPROT */
|
||||
#define BPROT_PRESENT
|
||||
|
||||
#define BPROT_REGIONS_SIZE 4096
|
||||
#define BPROT_REGIONS_NUM 64
|
||||
|
||||
/* Radio */
|
||||
#define RADIO_PRESENT
|
||||
#define RADIO_COUNT 1
|
||||
|
||||
/* Accelerated Address Resolver */
|
||||
#define AAR_PRESENT
|
||||
#define AAR_COUNT 1
|
||||
|
||||
#define AAR_MAX_IRK_NUM 8
|
||||
|
||||
/* AES Electronic CodeBook mode encryption */
|
||||
#define ECB_PRESENT
|
||||
#define ECB_COUNT 1
|
||||
|
||||
/* AES CCM mode encryption */
|
||||
#define CCM_PRESENT
|
||||
#define CCM_COUNT 1
|
||||
|
||||
/* Peripheral to Peripheral Interconnect */
|
||||
#define PPI_PRESENT
|
||||
#define PPI_COUNT 1
|
||||
|
||||
#define PPI_CH_NUM 16
|
||||
#define PPI_FIXED_CH_NUM 12
|
||||
#define PPI_GROUP_NUM 4
|
||||
|
||||
/* Timer/Counter */
|
||||
#define TIMER_PRESENT
|
||||
#define TIMER_COUNT 3
|
||||
|
||||
#define TIMER0_MAX_SIZE 32
|
||||
#define TIMER1_MAX_SIZE 16
|
||||
#define TIMER2_MAX_SIZE 16
|
||||
|
||||
#define TIMER0_CC_NUM 4
|
||||
#define TIMER1_CC_NUM 4
|
||||
#define TIMER2_CC_NUM 4
|
||||
|
||||
/* Real Time Counter */
|
||||
#define RTC_PRESENT
|
||||
#define RTC_COUNT 2
|
||||
|
||||
#define RTC0_CC_NUM 3
|
||||
#define RTC1_CC_NUM 4
|
||||
|
||||
/* RNG */
|
||||
#define RNG_PRESENT
|
||||
#define RNG_COUNT 1
|
||||
|
||||
/* Watchdog Timer */
|
||||
#define WDT_PRESENT
|
||||
#define WDT_COUNT 1
|
||||
|
||||
/* Temperature Sensor */
|
||||
#define TEMP_PRESENT
|
||||
#define TEMP_COUNT 1
|
||||
|
||||
/* Serial Peripheral Interface Master */
|
||||
#define SPI_PRESENT
|
||||
#define SPI_COUNT 2
|
||||
|
||||
/* Serial Peripheral Interface Slave with DMA */
|
||||
#define SPIS_PRESENT
|
||||
#define SPIS_COUNT 1
|
||||
|
||||
#define SPIS1_EASYDMA_MAXCNT_SIZE 8
|
||||
|
||||
/* Two Wire Interface Master */
|
||||
#define TWI_PRESENT
|
||||
#define TWI_COUNT 2
|
||||
|
||||
/* Universal Asynchronous Receiver-Transmitter */
|
||||
#define UART_PRESENT
|
||||
#define UART_COUNT 1
|
||||
|
||||
/* Quadrature Decoder */
|
||||
#define QDEC_PRESENT
|
||||
#define QDEC_COUNT 1
|
||||
|
||||
/* Analog to Digital Converter */
|
||||
#define ADC_PRESENT
|
||||
#define ADC_COUNT 1
|
||||
|
||||
/* GPIO Tasks and Events */
|
||||
#define GPIOTE_PRESENT
|
||||
#define GPIOTE_COUNT 1
|
||||
|
||||
#define GPIOTE_CH_NUM 4
|
||||
|
||||
/* Low Power Comparator */
|
||||
#define LPCOMP_PRESENT
|
||||
#define LPCOMP_COUNT 1
|
||||
|
||||
#define LPCOMP_REFSEL_RESOLUTION 8
|
||||
|
||||
|
||||
#endif // _NRF51422_PERIPHERALS_H
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2010 - 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 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.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, 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.
|
||||
|
||||
*/
|
||||
|
||||
/* This file is deprecated */
|
||||
#ifndef _NRF51801_PERIPHERALS_H
|
||||
#define _NRF51801_PERIPHERALS_H
|
||||
|
||||
|
||||
/* Power Peripheral */
|
||||
#define POWER_PRESENT
|
||||
#define POWER_COUNT 1
|
||||
|
||||
#define POWER_FEATURE_RAMON_REGISTERS_PRESENT
|
||||
|
||||
/* Software Interrupts */
|
||||
#define SWI_PRESENT
|
||||
#define SWI_COUNT 6
|
||||
|
||||
/* GPIO */
|
||||
#define GPIO_PRESENT
|
||||
#define GPIO_COUNT 1
|
||||
|
||||
#define P0_PIN_NUM 32
|
||||
|
||||
/* MPU and BPROT */
|
||||
#define BPROT_PRESENT
|
||||
|
||||
#define BPROT_REGIONS_SIZE 4096
|
||||
#define BPROT_REGIONS_NUM 64
|
||||
|
||||
/* Radio */
|
||||
#define RADIO_PRESENT
|
||||
#define RADIO_COUNT 1
|
||||
|
||||
/* Accelerated Address Resolver */
|
||||
#define AAR_PRESENT
|
||||
#define AAR_COUNT 1
|
||||
|
||||
#define AAR_MAX_IRK_NUM 8
|
||||
|
||||
/* AES Electronic CodeBook mode encryption */
|
||||
#define ECB_PRESENT
|
||||
#define ECB_COUNT 1
|
||||
|
||||
/* AES CCM mode encryption */
|
||||
#define CCM_PRESENT
|
||||
#define CCM_COUNT 1
|
||||
|
||||
/* Peripheral to Peripheral Interconnect */
|
||||
#define PPI_PRESENT
|
||||
#define PPI_COUNT 1
|
||||
|
||||
#define PPI_CH_NUM 16
|
||||
#define PPI_FIXED_CH_NUM 12
|
||||
#define PPI_GROUP_NUM 4
|
||||
|
||||
/* Timer/Counter */
|
||||
#define TIMER_PRESENT
|
||||
#define TIMER_COUNT 3
|
||||
|
||||
#define TIMER0_MAX_SIZE 32
|
||||
#define TIMER1_MAX_SIZE 16
|
||||
#define TIMER2_MAX_SIZE 16
|
||||
|
||||
#define TIMER0_CC_NUM 4
|
||||
#define TIMER1_CC_NUM 4
|
||||
#define TIMER2_CC_NUM 4
|
||||
|
||||
/* Real Time Counter */
|
||||
#define RTC_PRESENT
|
||||
#define RTC_COUNT 2
|
||||
|
||||
#define RTC0_CC_NUM 3
|
||||
#define RTC1_CC_NUM 4
|
||||
|
||||
/* RNG */
|
||||
#define RNG_PRESENT
|
||||
#define RNG_COUNT 1
|
||||
|
||||
/* Watchdog Timer */
|
||||
#define WDT_PRESENT
|
||||
#define WDT_COUNT 1
|
||||
|
||||
/* Temperature Sensor */
|
||||
#define TEMP_PRESENT
|
||||
#define TEMP_COUNT 1
|
||||
|
||||
/* Serial Peripheral Interface Master */
|
||||
#define SPI_PRESENT
|
||||
#define SPI_COUNT 2
|
||||
|
||||
/* Serial Peripheral Interface Slave with DMA */
|
||||
#define SPIS_PRESENT
|
||||
#define SPIS_COUNT 1
|
||||
|
||||
#define SPIS1_EASYDMA_MAXCNT_SIZE 8
|
||||
|
||||
/* Two Wire Interface Master */
|
||||
#define TWI_PRESENT
|
||||
#define TWI_COUNT 2
|
||||
|
||||
/* Universal Asynchronous Receiver-Transmitter */
|
||||
#define UART_PRESENT
|
||||
#define UART_COUNT 1
|
||||
|
||||
/* Quadrature Decoder */
|
||||
#define QDEC_PRESENT
|
||||
#define QDEC_COUNT 1
|
||||
|
||||
/* Analog to Digital Converter */
|
||||
#define ADC_PRESENT
|
||||
#define ADC_COUNT 1
|
||||
|
||||
/* GPIO Tasks and Events */
|
||||
#define GPIOTE_PRESENT
|
||||
#define GPIOTE_COUNT 1
|
||||
|
||||
#define GPIOTE_CH_NUM 4
|
||||
|
||||
/* Low Power Comparator */
|
||||
#define LPCOMP_PRESENT
|
||||
#define LPCOMP_COUNT 1
|
||||
|
||||
#define LPCOMP_REFSEL_RESOLUTION 8
|
||||
|
||||
|
||||
#endif // _NRF51801_PERIPHERALS_H
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2010 - 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 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.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, 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.
|
||||
|
||||
*/
|
||||
|
||||
/* This file is deprecated */
|
||||
#ifndef _NRF51802_PERIPHERALS_H
|
||||
#define _NRF51802_PERIPHERALS_H
|
||||
|
||||
|
||||
/* Power Peripheral */
|
||||
#define POWER_PRESENT
|
||||
#define POWER_COUNT 1
|
||||
|
||||
#define POWER_FEATURE_RAMON_REGISTERS_PRESENT
|
||||
|
||||
/* Software Interrupts */
|
||||
#define SWI_PRESENT
|
||||
#define SWI_COUNT 6
|
||||
|
||||
/* GPIO */
|
||||
#define GPIO_PRESENT
|
||||
#define GPIO_COUNT 1
|
||||
|
||||
#define P0_PIN_NUM 32
|
||||
|
||||
/* MPU and BPROT */
|
||||
#define BPROT_PRESENT
|
||||
|
||||
#define BPROT_REGIONS_SIZE 4096
|
||||
#define BPROT_REGIONS_NUM 64
|
||||
|
||||
/* Radio */
|
||||
#define RADIO_PRESENT
|
||||
#define RADIO_COUNT 1
|
||||
|
||||
/* Accelerated Address Resolver */
|
||||
#define AAR_PRESENT
|
||||
#define AAR_COUNT 1
|
||||
|
||||
#define AAR_MAX_IRK_NUM 8
|
||||
|
||||
/* AES Electronic CodeBook mode encryption */
|
||||
#define ECB_PRESENT
|
||||
#define ECB_COUNT 1
|
||||
|
||||
/* AES CCM mode encryption */
|
||||
#define CCM_PRESENT
|
||||
#define CCM_COUNT 1
|
||||
|
||||
/* Peripheral to Peripheral Interconnect */
|
||||
#define PPI_PRESENT
|
||||
#define PPI_COUNT 1
|
||||
|
||||
#define PPI_CH_NUM 16
|
||||
#define PPI_FIXED_CH_NUM 12
|
||||
#define PPI_GROUP_NUM 4
|
||||
|
||||
/* Timer/Counter */
|
||||
#define TIMER_PRESENT
|
||||
#define TIMER_COUNT 3
|
||||
|
||||
#define TIMER0_MAX_SIZE 32
|
||||
#define TIMER1_MAX_SIZE 16
|
||||
#define TIMER2_MAX_SIZE 16
|
||||
|
||||
#define TIMER0_CC_NUM 4
|
||||
#define TIMER1_CC_NUM 4
|
||||
#define TIMER2_CC_NUM 4
|
||||
|
||||
/* Real Time Counter */
|
||||
#define RTC_PRESENT
|
||||
#define RTC_COUNT 2
|
||||
|
||||
#define RTC0_CC_NUM 3
|
||||
#define RTC1_CC_NUM 4
|
||||
|
||||
/* RNG */
|
||||
#define RNG_PRESENT
|
||||
#define RNG_COUNT 1
|
||||
|
||||
/* Watchdog Timer */
|
||||
#define WDT_PRESENT
|
||||
#define WDT_COUNT 1
|
||||
|
||||
/* Temperature Sensor */
|
||||
#define TEMP_PRESENT
|
||||
#define TEMP_COUNT 1
|
||||
|
||||
/* Serial Peripheral Interface Master */
|
||||
#define SPI_PRESENT
|
||||
#define SPI_COUNT 2
|
||||
|
||||
/* Serial Peripheral Interface Slave with DMA */
|
||||
#define SPIS_PRESENT
|
||||
#define SPIS_COUNT 1
|
||||
|
||||
#define SPIS1_EASYDMA_MAXCNT_SIZE 8
|
||||
|
||||
/* Two Wire Interface Master */
|
||||
#define TWI_PRESENT
|
||||
#define TWI_COUNT 2
|
||||
|
||||
/* Universal Asynchronous Receiver-Transmitter */
|
||||
#define UART_PRESENT
|
||||
#define UART_COUNT 1
|
||||
|
||||
/* Quadrature Decoder */
|
||||
#define QDEC_PRESENT
|
||||
#define QDEC_COUNT 1
|
||||
|
||||
/* Analog to Digital Converter */
|
||||
#define ADC_PRESENT
|
||||
#define ADC_COUNT 1
|
||||
|
||||
/* GPIO Tasks and Events */
|
||||
#define GPIOTE_PRESENT
|
||||
#define GPIOTE_COUNT 1
|
||||
|
||||
#define GPIOTE_CH_NUM 4
|
||||
|
||||
/* Low Power Comparator */
|
||||
#define LPCOMP_PRESENT
|
||||
#define LPCOMP_COUNT 1
|
||||
|
||||
#define LPCOMP_REFSEL_RESOLUTION 8
|
||||
|
||||
|
||||
#endif // _NRF51802_PERIPHERALS_H
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2010 - 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 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.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, 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.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/* This file is deprecated */
|
||||
#ifndef _NRF51822_PERIPHERALS_H
|
||||
#define _NRF51822_PERIPHERALS_H
|
||||
|
||||
|
||||
/* Power Peripheral */
|
||||
#define POWER_PRESENT
|
||||
#define POWER_COUNT 1
|
||||
|
||||
#define POWER_FEATURE_RAMON_REGISTERS_PRESENT
|
||||
|
||||
/* Software Interrupts */
|
||||
#define SWI_PRESENT
|
||||
#define SWI_COUNT 6
|
||||
|
||||
/* GPIO */
|
||||
#define GPIO_PRESENT
|
||||
#define GPIO_COUNT 1
|
||||
|
||||
#define P0_PIN_NUM 32
|
||||
|
||||
/* MPU and BPROT */
|
||||
#define BPROT_PRESENT
|
||||
|
||||
#define BPROT_REGIONS_SIZE 4096
|
||||
#define BPROT_REGIONS_NUM 64
|
||||
|
||||
/* Radio */
|
||||
#define RADIO_PRESENT
|
||||
#define RADIO_COUNT 1
|
||||
|
||||
/* Accelerated Address Resolver */
|
||||
#define AAR_PRESENT
|
||||
#define AAR_COUNT 1
|
||||
|
||||
#define AAR_MAX_IRK_NUM 8
|
||||
|
||||
/* AES Electronic CodeBook mode encryption */
|
||||
#define ECB_PRESENT
|
||||
#define ECB_COUNT 1
|
||||
|
||||
/* AES CCM mode encryption */
|
||||
#define CCM_PRESENT
|
||||
#define CCM_COUNT 1
|
||||
|
||||
/* Peripheral to Peripheral Interconnect */
|
||||
#define PPI_PRESENT
|
||||
#define PPI_COUNT 1
|
||||
|
||||
#define PPI_CH_NUM 16
|
||||
#define PPI_FIXED_CH_NUM 12
|
||||
#define PPI_GROUP_NUM 4
|
||||
|
||||
/* Timer/Counter */
|
||||
#define TIMER_PRESENT
|
||||
#define TIMER_COUNT 3
|
||||
|
||||
#define TIMER0_MAX_SIZE 32
|
||||
#define TIMER1_MAX_SIZE 16
|
||||
#define TIMER2_MAX_SIZE 16
|
||||
|
||||
#define TIMER0_CC_NUM 4
|
||||
#define TIMER1_CC_NUM 4
|
||||
#define TIMER2_CC_NUM 4
|
||||
|
||||
/* Real Time Counter */
|
||||
#define RTC_PRESENT
|
||||
#define RTC_COUNT 2
|
||||
|
||||
#define RTC0_CC_NUM 3
|
||||
#define RTC1_CC_NUM 4
|
||||
|
||||
/* RNG */
|
||||
#define RNG_PRESENT
|
||||
#define RNG_COUNT 1
|
||||
|
||||
/* Watchdog Timer */
|
||||
#define WDT_PRESENT
|
||||
#define WDT_COUNT 1
|
||||
|
||||
/* Temperature Sensor */
|
||||
#define TEMP_PRESENT
|
||||
#define TEMP_COUNT 1
|
||||
|
||||
/* Serial Peripheral Interface Master */
|
||||
#define SPI_PRESENT
|
||||
#define SPI_COUNT 2
|
||||
|
||||
/* Serial Peripheral Interface Slave with DMA */
|
||||
#define SPIS_PRESENT
|
||||
#define SPIS_COUNT 1
|
||||
|
||||
#define SPIS1_EASYDMA_MAXCNT_SIZE 8
|
||||
|
||||
/* Two Wire Interface Master */
|
||||
#define TWI_PRESENT
|
||||
#define TWI_COUNT 2
|
||||
|
||||
/* Universal Asynchronous Receiver-Transmitter */
|
||||
#define UART_PRESENT
|
||||
#define UART_COUNT 1
|
||||
|
||||
/* Quadrature Decoder */
|
||||
#define QDEC_PRESENT
|
||||
#define QDEC_COUNT 1
|
||||
|
||||
/* Analog to Digital Converter */
|
||||
#define ADC_PRESENT
|
||||
#define ADC_COUNT 1
|
||||
|
||||
/* GPIO Tasks and Events */
|
||||
#define GPIOTE_PRESENT
|
||||
#define GPIOTE_COUNT 1
|
||||
|
||||
#define GPIOTE_CH_NUM 4
|
||||
|
||||
/* Low Power Comparator */
|
||||
#define LPCOMP_PRESENT
|
||||
#define LPCOMP_COUNT 1
|
||||
|
||||
#define LPCOMP_REFSEL_RESOLUTION 8
|
||||
|
||||
|
||||
#endif // _NRF51822_PERIPHERALS_H
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2010 - 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 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.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, 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.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/* This file is deprecated */
|
||||
#ifndef _NRF51824_PERIPHERALS_H
|
||||
#define _NRF51824_PERIPHERALS_H
|
||||
|
||||
|
||||
/* Power Peripheral */
|
||||
#define POWER_PRESENT
|
||||
#define POWER_COUNT 1
|
||||
|
||||
#define POWER_FEATURE_RAMON_REGISTERS_PRESENT
|
||||
|
||||
/* Software Interrupts */
|
||||
#define SWI_PRESENT
|
||||
#define SWI_COUNT 6
|
||||
|
||||
/* GPIO */
|
||||
#define GPIO_PRESENT
|
||||
#define GPIO_COUNT 1
|
||||
|
||||
#define P0_PIN_NUM 32
|
||||
|
||||
/* MPU and BPROT */
|
||||
#define BPROT_PRESENT
|
||||
|
||||
#define BPROT_REGIONS_SIZE 4096
|
||||
#define BPROT_REGIONS_NUM 64
|
||||
|
||||
/* Radio */
|
||||
#define RADIO_PRESENT
|
||||
#define RADIO_COUNT 1
|
||||
|
||||
/* Accelerated Address Resolver */
|
||||
#define AAR_PRESENT
|
||||
#define AAR_COUNT 1
|
||||
|
||||
#define AAR_MAX_IRK_NUM 8
|
||||
|
||||
/* AES Electronic CodeBook mode encryption */
|
||||
#define ECB_PRESENT
|
||||
#define ECB_COUNT 1
|
||||
|
||||
/* AES CCM mode encryption */
|
||||
#define CCM_PRESENT
|
||||
#define CCM_COUNT 1
|
||||
|
||||
/* Peripheral to Peripheral Interconnect */
|
||||
#define PPI_PRESENT
|
||||
#define PPI_COUNT 1
|
||||
|
||||
#define PPI_CH_NUM 16
|
||||
#define PPI_FIXED_CH_NUM 12
|
||||
#define PPI_GROUP_NUM 4
|
||||
|
||||
/* Timer/Counter */
|
||||
#define TIMER_PRESENT
|
||||
#define TIMER_COUNT 3
|
||||
|
||||
#define TIMER0_MAX_SIZE 32
|
||||
#define TIMER1_MAX_SIZE 16
|
||||
#define TIMER2_MAX_SIZE 16
|
||||
|
||||
#define TIMER0_CC_NUM 4
|
||||
#define TIMER1_CC_NUM 4
|
||||
#define TIMER2_CC_NUM 4
|
||||
|
||||
/* Real Time Counter */
|
||||
#define RTC_PRESENT
|
||||
#define RTC_COUNT 2
|
||||
|
||||
#define RTC0_CC_NUM 3
|
||||
#define RTC1_CC_NUM 4
|
||||
|
||||
/* RNG */
|
||||
#define RNG_PRESENT
|
||||
#define RNG_COUNT 1
|
||||
|
||||
/* Watchdog Timer */
|
||||
#define WDT_PRESENT
|
||||
#define WDT_COUNT 1
|
||||
|
||||
/* Temperature Sensor */
|
||||
#define TEMP_PRESENT
|
||||
#define TEMP_COUNT 1
|
||||
|
||||
/* Serial Peripheral Interface Master */
|
||||
#define SPI_PRESENT
|
||||
#define SPI_COUNT 2
|
||||
|
||||
/* Serial Peripheral Interface Slave with DMA */
|
||||
#define SPIS_PRESENT
|
||||
#define SPIS_COUNT 1
|
||||
|
||||
#define SPIS1_EASYDMA_MAXCNT_SIZE 8
|
||||
|
||||
/* Two Wire Interface Master */
|
||||
#define TWI_PRESENT
|
||||
#define TWI_COUNT 2
|
||||
|
||||
/* Universal Asynchronous Receiver-Transmitter */
|
||||
#define UART_PRESENT
|
||||
#define UART_COUNT 1
|
||||
|
||||
/* Quadrature Decoder */
|
||||
#define QDEC_PRESENT
|
||||
#define QDEC_COUNT 1
|
||||
|
||||
/* Analog to Digital Converter */
|
||||
#define ADC_PRESENT
|
||||
#define ADC_COUNT 1
|
||||
|
||||
/* GPIO Tasks and Events */
|
||||
#define GPIOTE_PRESENT
|
||||
#define GPIOTE_COUNT 1
|
||||
|
||||
#define GPIOTE_CH_NUM 4
|
||||
|
||||
/* Low Power Comparator */
|
||||
#define LPCOMP_PRESENT
|
||||
#define LPCOMP_COUNT 1
|
||||
|
||||
#define LPCOMP_REFSEL_RESOLUTION 8
|
||||
|
||||
|
||||
#endif // _NRF51824_PERIPHERALS_H
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,446 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2010 - 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 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.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, 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 NRF51_DEPRECATED_H
|
||||
#define NRF51_DEPRECATED_H
|
||||
|
||||
/*lint ++flb "Enter library region */
|
||||
|
||||
/* This file is given to prevent your SW from not compiling with the updates made to nrf51.h and
|
||||
* nrf51_bitfields.h. The macros defined in this file were available previously. Do not use these
|
||||
* macros on purpose. Use the ones defined in nrf51.h and nrf51_bitfields.h instead.
|
||||
*/
|
||||
|
||||
/* NVMC */
|
||||
/* The register ERASEPROTECTEDPAGE is called ERASEPCR0 in the documentation. */
|
||||
#define ERASEPROTECTEDPAGE ERASEPCR0
|
||||
|
||||
|
||||
/* LPCOMP */
|
||||
/* The interrupt ISR was renamed. Adding old name to the macros. */
|
||||
#define LPCOMP_COMP_IRQHandler LPCOMP_IRQHandler
|
||||
#define LPCOMP_COMP_IRQn LPCOMP_IRQn
|
||||
/* Corrected typo in RESULT register. */
|
||||
#define LPCOMP_RESULT_RESULT_Bellow LPCOMP_RESULT_RESULT_Below
|
||||
|
||||
|
||||
/* MPU */
|
||||
/* The field MPU.PERR0.LPCOMP_COMP was renamed. Added into deprecated in case somebody was using the macros defined for it. */
|
||||
#define MPU_PERR0_LPCOMP_COMP_Pos MPU_PERR0_LPCOMP_Pos
|
||||
#define MPU_PERR0_LPCOMP_COMP_Msk MPU_PERR0_LPCOMP_Msk
|
||||
#define MPU_PERR0_LPCOMP_COMP_InRegion1 MPU_PERR0_LPCOMP_InRegion1
|
||||
#define MPU_PERR0_LPCOMP_COMP_InRegion0 MPU_PERR0_LPCOMP_InRegion0
|
||||
|
||||
|
||||
/* POWER */
|
||||
/* The field POWER.RAMON.OFFRAM3 was eliminated. Added into deprecated in case somebody was using the macros defined for it. */
|
||||
#define POWER_RAMON_OFFRAM3_Pos (19UL)
|
||||
#define POWER_RAMON_OFFRAM3_Msk (0x1UL << POWER_RAMON_OFFRAM3_Pos)
|
||||
#define POWER_RAMON_OFFRAM3_RAM3Off (0UL)
|
||||
#define POWER_RAMON_OFFRAM3_RAM3On (1UL)
|
||||
/* The field POWER.RAMON.OFFRAM2 was eliminated. Added into deprecated in case somebody was using the macros defined for it. */
|
||||
#define POWER_RAMON_OFFRAM2_Pos (18UL)
|
||||
#define POWER_RAMON_OFFRAM2_Msk (0x1UL << POWER_RAMON_OFFRAM2_Pos)
|
||||
#define POWER_RAMON_OFFRAM2_RAM2Off (0UL)
|
||||
#define POWER_RAMON_OFFRAM2_RAM2On (1UL)
|
||||
/* The field POWER.RAMON.ONRAM3 was eliminated. Added into deprecated in case somebody was using the macros defined for it. */
|
||||
#define POWER_RAMON_ONRAM3_Pos (3UL)
|
||||
#define POWER_RAMON_ONRAM3_Msk (0x1UL << POWER_RAMON_ONRAM3_Pos)
|
||||
#define POWER_RAMON_ONRAM3_RAM3Off (0UL)
|
||||
#define POWER_RAMON_ONRAM3_RAM3On (1UL)
|
||||
/* The field POWER.RAMON.ONRAM2 was eliminated. Added into deprecated in case somebody was using the macros defined for it. */
|
||||
#define POWER_RAMON_ONRAM2_Pos (2UL)
|
||||
#define POWER_RAMON_ONRAM2_Msk (0x1UL << POWER_RAMON_ONRAM2_Pos)
|
||||
#define POWER_RAMON_ONRAM2_RAM2Off (0UL)
|
||||
#define POWER_RAMON_ONRAM2_RAM2On (1UL)
|
||||
|
||||
|
||||
/* RADIO */
|
||||
/* The enumerated value RADIO.TXPOWER.TXPOWER.Neg40dBm was renamed. Added into deprecated with the new macro name. */
|
||||
#define RADIO_TXPOWER_TXPOWER_Neg40dBm RADIO_TXPOWER_TXPOWER_Neg30dBm
|
||||
/* The name of the field SKIPADDR was corrected. Old macros added for compatibility. */
|
||||
#define RADIO_CRCCNF_SKIP_ADDR_Pos RADIO_CRCCNF_SKIPADDR_Pos
|
||||
#define RADIO_CRCCNF_SKIP_ADDR_Msk RADIO_CRCCNF_SKIPADDR_Msk
|
||||
#define RADIO_CRCCNF_SKIP_ADDR_Include RADIO_CRCCNF_SKIPADDR_Include
|
||||
#define RADIO_CRCCNF_SKIP_ADDR_Skip RADIO_CRCCNF_SKIPADDR_Skip
|
||||
/* The name of the field PLLLOCK was corrected. Old macros added for compatibility. */
|
||||
#define RADIO_TEST_PLL_LOCK_Pos RADIO_TEST_PLLLOCK_Pos
|
||||
#define RADIO_TEST_PLL_LOCK_Msk RADIO_TEST_PLLLOCK_Msk
|
||||
#define RADIO_TEST_PLL_LOCK_Disabled RADIO_TEST_PLLLOCK_Disabled
|
||||
#define RADIO_TEST_PLL_LOCK_Enabled RADIO_TEST_PLLLOCK_Enabled
|
||||
/* The name of the field CONSTCARRIER was corrected. Old macros added for compatibility. */
|
||||
#define RADIO_TEST_CONST_CARRIER_Pos RADIO_TEST_CONSTCARRIER_Pos
|
||||
#define RADIO_TEST_CONST_CARRIER_Msk RADIO_TEST_CONSTCARRIER_Msk
|
||||
#define RADIO_TEST_CONST_CARRIER_Disabled RADIO_TEST_CONSTCARRIER_Disabled
|
||||
#define RADIO_TEST_CONST_CARRIER_Enabled RADIO_TEST_CONSTCARRIER_Enabled
|
||||
|
||||
|
||||
/* FICR */
|
||||
/* The registers FICR.SIZERAMBLOCK0, FICR.SIZERAMBLOCK1, FICR.SIZERAMBLOCK2 and FICR.SIZERAMBLOCK3 were renamed into an array. */
|
||||
#define SIZERAMBLOCK0 SIZERAMBLOCKS
|
||||
#define SIZERAMBLOCK1 SIZERAMBLOCKS
|
||||
#define SIZERAMBLOCK2 SIZERAMBLOCK[2] /*!< Note that this macro will disapear when SIZERAMBLOCK array is eliminated. SIZERAMBLOCK is a deprecated array. */
|
||||
#define SIZERAMBLOCK3 SIZERAMBLOCK[3] /*!< Note that this macro will disapear when SIZERAMBLOCK array is eliminated. SIZERAMBLOCK is a deprecated array. */
|
||||
/* The registers FICR.DEVICEID0 and FICR.DEVICEID1 were renamed into an array. */
|
||||
#define DEVICEID0 DEVICEID[0]
|
||||
#define DEVICEID1 DEVICEID[1]
|
||||
/* The registers FICR.ER0, FICR.ER1, FICR.ER2 and FICR.ER3 were renamed into an array. */
|
||||
#define ER0 ER[0]
|
||||
#define ER1 ER[1]
|
||||
#define ER2 ER[2]
|
||||
#define ER3 ER[3]
|
||||
/* The registers FICR.IR0, FICR.IR1, FICR.IR2 and FICR.IR3 were renamed into an array. */
|
||||
#define IR0 IR[0]
|
||||
#define IR1 IR[1]
|
||||
#define IR2 IR[2]
|
||||
#define IR3 IR[3]
|
||||
/* The registers FICR.DEVICEADDR0 and FICR.DEVICEADDR1 were renamed into an array. */
|
||||
#define DEVICEADDR0 DEVICEADDR[0]
|
||||
#define DEVICEADDR1 DEVICEADDR[1]
|
||||
|
||||
|
||||
/* PPI */
|
||||
/* The tasks PPI.TASKS_CHGxEN and PPI.TASKS_CHGxDIS were renamed into an array of structs. */
|
||||
#define TASKS_CHG0EN TASKS_CHG[0].EN
|
||||
#define TASKS_CHG0DIS TASKS_CHG[0].DIS
|
||||
#define TASKS_CHG1EN TASKS_CHG[1].EN
|
||||
#define TASKS_CHG1DIS TASKS_CHG[1].DIS
|
||||
#define TASKS_CHG2EN TASKS_CHG[2].EN
|
||||
#define TASKS_CHG2DIS TASKS_CHG[2].DIS
|
||||
#define TASKS_CHG3EN TASKS_CHG[3].EN
|
||||
#define TASKS_CHG3DIS TASKS_CHG[3].DIS
|
||||
/* The registers PPI.CHx_EEP and PPI.CHx_TEP were renamed into an array of structs. */
|
||||
#define CH0_EEP CH[0].EEP
|
||||
#define CH0_TEP CH[0].TEP
|
||||
#define CH1_EEP CH[1].EEP
|
||||
#define CH1_TEP CH[1].TEP
|
||||
#define CH2_EEP CH[2].EEP
|
||||
#define CH2_TEP CH[2].TEP
|
||||
#define CH3_EEP CH[3].EEP
|
||||
#define CH3_TEP CH[3].TEP
|
||||
#define CH4_EEP CH[4].EEP
|
||||
#define CH4_TEP CH[4].TEP
|
||||
#define CH5_EEP CH[5].EEP
|
||||
#define CH5_TEP CH[5].TEP
|
||||
#define CH6_EEP CH[6].EEP
|
||||
#define CH6_TEP CH[6].TEP
|
||||
#define CH7_EEP CH[7].EEP
|
||||
#define CH7_TEP CH[7].TEP
|
||||
#define CH8_EEP CH[8].EEP
|
||||
#define CH8_TEP CH[8].TEP
|
||||
#define CH9_EEP CH[9].EEP
|
||||
#define CH9_TEP CH[9].TEP
|
||||
#define CH10_EEP CH[10].EEP
|
||||
#define CH10_TEP CH[10].TEP
|
||||
#define CH11_EEP CH[11].EEP
|
||||
#define CH11_TEP CH[11].TEP
|
||||
#define CH12_EEP CH[12].EEP
|
||||
#define CH12_TEP CH[12].TEP
|
||||
#define CH13_EEP CH[13].EEP
|
||||
#define CH13_TEP CH[13].TEP
|
||||
#define CH14_EEP CH[14].EEP
|
||||
#define CH14_TEP CH[14].TEP
|
||||
#define CH15_EEP CH[15].EEP
|
||||
#define CH15_TEP CH[15].TEP
|
||||
/* The registers PPI.CHG0, PPI.CHG1, PPI.CHG2 and PPI.CHG3 were renamed into an array. */
|
||||
#define CHG0 CHG[0]
|
||||
#define CHG1 CHG[1]
|
||||
#define CHG2 CHG[2]
|
||||
#define CHG3 CHG[3]
|
||||
/* All bitfield macros for the CHGx registers therefore changed name. */
|
||||
#define PPI_CHG0_CH15_Pos PPI_CHG_CH15_Pos
|
||||
#define PPI_CHG0_CH15_Msk PPI_CHG_CH15_Msk
|
||||
#define PPI_CHG0_CH15_Excluded PPI_CHG_CH15_Excluded
|
||||
#define PPI_CHG0_CH15_Included PPI_CHG_CH15_Included
|
||||
#define PPI_CHG0_CH14_Pos PPI_CHG_CH14_Pos
|
||||
#define PPI_CHG0_CH14_Msk PPI_CHG_CH14_Msk
|
||||
#define PPI_CHG0_CH14_Excluded PPI_CHG_CH14_Excluded
|
||||
#define PPI_CHG0_CH14_Included PPI_CHG_CH14_Included
|
||||
#define PPI_CHG0_CH13_Pos PPI_CHG_CH13_Pos
|
||||
#define PPI_CHG0_CH13_Msk PPI_CHG_CH13_Msk
|
||||
#define PPI_CHG0_CH13_Excluded PPI_CHG_CH13_Excluded
|
||||
#define PPI_CHG0_CH13_Included PPI_CHG_CH13_Included
|
||||
#define PPI_CHG0_CH12_Pos PPI_CHG_CH12_Pos
|
||||
#define PPI_CHG0_CH12_Msk PPI_CHG_CH12_Msk
|
||||
#define PPI_CHG0_CH12_Excluded PPI_CHG_CH12_Excluded
|
||||
#define PPI_CHG0_CH12_Included PPI_CHG_CH12_Included
|
||||
#define PPI_CHG0_CH11_Pos PPI_CHG_CH11_Pos
|
||||
#define PPI_CHG0_CH11_Msk PPI_CHG_CH11_Msk
|
||||
#define PPI_CHG0_CH11_Excluded PPI_CHG_CH11_Excluded
|
||||
#define PPI_CHG0_CH11_Included PPI_CHG_CH11_Included
|
||||
#define PPI_CHG0_CH10_Pos PPI_CHG_CH10_Pos
|
||||
#define PPI_CHG0_CH10_Msk PPI_CHG_CH10_Msk
|
||||
#define PPI_CHG0_CH10_Excluded PPI_CHG_CH10_Excluded
|
||||
#define PPI_CHG0_CH10_Included PPI_CHG_CH10_Included
|
||||
#define PPI_CHG0_CH9_Pos PPI_CHG_CH9_Pos
|
||||
#define PPI_CHG0_CH9_Msk PPI_CHG_CH9_Msk
|
||||
#define PPI_CHG0_CH9_Excluded PPI_CHG_CH9_Excluded
|
||||
#define PPI_CHG0_CH9_Included PPI_CHG_CH9_Included
|
||||
#define PPI_CHG0_CH8_Pos PPI_CHG_CH8_Pos
|
||||
#define PPI_CHG0_CH8_Msk PPI_CHG_CH8_Msk
|
||||
#define PPI_CHG0_CH8_Excluded PPI_CHG_CH8_Excluded
|
||||
#define PPI_CHG0_CH8_Included PPI_CHG_CH8_Included
|
||||
#define PPI_CHG0_CH7_Pos PPI_CHG_CH7_Pos
|
||||
#define PPI_CHG0_CH7_Msk PPI_CHG_CH7_Msk
|
||||
#define PPI_CHG0_CH7_Excluded PPI_CHG_CH7_Excluded
|
||||
#define PPI_CHG0_CH7_Included PPI_CHG_CH7_Included
|
||||
#define PPI_CHG0_CH6_Pos PPI_CHG_CH6_Pos
|
||||
#define PPI_CHG0_CH6_Msk PPI_CHG_CH6_Msk
|
||||
#define PPI_CHG0_CH6_Excluded PPI_CHG_CH6_Excluded
|
||||
#define PPI_CHG0_CH6_Included PPI_CHG_CH6_Included
|
||||
#define PPI_CHG0_CH5_Pos PPI_CHG_CH5_Pos
|
||||
#define PPI_CHG0_CH5_Msk PPI_CHG_CH5_Msk
|
||||
#define PPI_CHG0_CH5_Excluded PPI_CHG_CH5_Excluded
|
||||
#define PPI_CHG0_CH5_Included PPI_CHG_CH5_Included
|
||||
#define PPI_CHG0_CH4_Pos PPI_CHG_CH4_Pos
|
||||
#define PPI_CHG0_CH4_Msk PPI_CHG_CH4_Msk
|
||||
#define PPI_CHG0_CH4_Excluded PPI_CHG_CH4_Excluded
|
||||
#define PPI_CHG0_CH4_Included PPI_CHG_CH4_Included
|
||||
#define PPI_CHG0_CH3_Pos PPI_CHG_CH3_Pos
|
||||
#define PPI_CHG0_CH3_Msk PPI_CHG_CH3_Msk
|
||||
#define PPI_CHG0_CH3_Excluded PPI_CHG_CH3_Excluded
|
||||
#define PPI_CHG0_CH3_Included PPI_CHG_CH3_Included
|
||||
#define PPI_CHG0_CH2_Pos PPI_CHG_CH2_Pos
|
||||
#define PPI_CHG0_CH2_Msk PPI_CHG_CH2_Msk
|
||||
#define PPI_CHG0_CH2_Excluded PPI_CHG_CH2_Excluded
|
||||
#define PPI_CHG0_CH2_Included PPI_CHG_CH2_Included
|
||||
#define PPI_CHG0_CH1_Pos PPI_CHG_CH1_Pos
|
||||
#define PPI_CHG0_CH1_Msk PPI_CHG_CH1_Msk
|
||||
#define PPI_CHG0_CH1_Excluded PPI_CHG_CH1_Excluded
|
||||
#define PPI_CHG0_CH1_Included PPI_CHG_CH1_Included
|
||||
#define PPI_CHG0_CH0_Pos PPI_CHG_CH0_Pos
|
||||
#define PPI_CHG0_CH0_Msk PPI_CHG_CH0_Msk
|
||||
#define PPI_CHG0_CH0_Excluded PPI_CHG_CH0_Excluded
|
||||
#define PPI_CHG0_CH0_Included PPI_CHG_CH0_Included
|
||||
#define PPI_CHG1_CH15_Pos PPI_CHG_CH15_Pos
|
||||
#define PPI_CHG1_CH15_Msk PPI_CHG_CH15_Msk
|
||||
#define PPI_CHG1_CH15_Excluded PPI_CHG_CH15_Excluded
|
||||
#define PPI_CHG1_CH15_Included PPI_CHG_CH15_Included
|
||||
#define PPI_CHG1_CH14_Pos PPI_CHG_CH14_Pos
|
||||
#define PPI_CHG1_CH14_Msk PPI_CHG_CH14_Msk
|
||||
#define PPI_CHG1_CH14_Excluded PPI_CHG_CH14_Excluded
|
||||
#define PPI_CHG1_CH14_Included PPI_CHG_CH14_Included
|
||||
#define PPI_CHG1_CH13_Pos PPI_CHG_CH13_Pos
|
||||
#define PPI_CHG1_CH13_Msk PPI_CHG_CH13_Msk
|
||||
#define PPI_CHG1_CH13_Excluded PPI_CHG_CH13_Excluded
|
||||
#define PPI_CHG1_CH13_Included PPI_CHG_CH13_Included
|
||||
#define PPI_CHG1_CH12_Pos PPI_CHG_CH12_Pos
|
||||
#define PPI_CHG1_CH12_Msk PPI_CHG_CH12_Msk
|
||||
#define PPI_CHG1_CH12_Excluded PPI_CHG_CH12_Excluded
|
||||
#define PPI_CHG1_CH12_Included PPI_CHG_CH12_Included
|
||||
#define PPI_CHG1_CH11_Pos PPI_CHG_CH11_Pos
|
||||
#define PPI_CHG1_CH11_Msk PPI_CHG_CH11_Msk
|
||||
#define PPI_CHG1_CH11_Excluded PPI_CHG_CH11_Excluded
|
||||
#define PPI_CHG1_CH11_Included PPI_CHG_CH11_Included
|
||||
#define PPI_CHG1_CH10_Pos PPI_CHG_CH10_Pos
|
||||
#define PPI_CHG1_CH10_Msk PPI_CHG_CH10_Msk
|
||||
#define PPI_CHG1_CH10_Excluded PPI_CHG_CH10_Excluded
|
||||
#define PPI_CHG1_CH10_Included PPI_CHG_CH10_Included
|
||||
#define PPI_CHG1_CH9_Pos PPI_CHG_CH9_Pos
|
||||
#define PPI_CHG1_CH9_Msk PPI_CHG_CH9_Msk
|
||||
#define PPI_CHG1_CH9_Excluded PPI_CHG_CH9_Excluded
|
||||
#define PPI_CHG1_CH9_Included PPI_CHG_CH9_Included
|
||||
#define PPI_CHG1_CH8_Pos PPI_CHG_CH8_Pos
|
||||
#define PPI_CHG1_CH8_Msk PPI_CHG_CH8_Msk
|
||||
#define PPI_CHG1_CH8_Excluded PPI_CHG_CH8_Excluded
|
||||
#define PPI_CHG1_CH8_Included PPI_CHG_CH8_Included
|
||||
#define PPI_CHG1_CH7_Pos PPI_CHG_CH7_Pos
|
||||
#define PPI_CHG1_CH7_Msk PPI_CHG_CH7_Msk
|
||||
#define PPI_CHG1_CH7_Excluded PPI_CHG_CH7_Excluded
|
||||
#define PPI_CHG1_CH7_Included PPI_CHG_CH7_Included
|
||||
#define PPI_CHG1_CH6_Pos PPI_CHG_CH6_Pos
|
||||
#define PPI_CHG1_CH6_Msk PPI_CHG_CH6_Msk
|
||||
#define PPI_CHG1_CH6_Excluded PPI_CHG_CH6_Excluded
|
||||
#define PPI_CHG1_CH6_Included PPI_CHG_CH6_Included
|
||||
#define PPI_CHG1_CH5_Pos PPI_CHG_CH5_Pos
|
||||
#define PPI_CHG1_CH5_Msk PPI_CHG_CH5_Msk
|
||||
#define PPI_CHG1_CH5_Excluded PPI_CHG_CH5_Excluded
|
||||
#define PPI_CHG1_CH5_Included PPI_CHG_CH5_Included
|
||||
#define PPI_CHG1_CH4_Pos PPI_CHG_CH4_Pos
|
||||
#define PPI_CHG1_CH4_Msk PPI_CHG_CH4_Msk
|
||||
#define PPI_CHG1_CH4_Excluded PPI_CHG_CH4_Excluded
|
||||
#define PPI_CHG1_CH4_Included PPI_CHG_CH4_Included
|
||||
#define PPI_CHG1_CH3_Pos PPI_CHG_CH3_Pos
|
||||
#define PPI_CHG1_CH3_Msk PPI_CHG_CH3_Msk
|
||||
#define PPI_CHG1_CH3_Excluded PPI_CHG_CH3_Excluded
|
||||
#define PPI_CHG1_CH3_Included PPI_CHG_CH3_Included
|
||||
#define PPI_CHG1_CH2_Pos PPI_CHG_CH2_Pos
|
||||
#define PPI_CHG1_CH2_Msk PPI_CHG_CH2_Msk
|
||||
#define PPI_CHG1_CH2_Excluded PPI_CHG_CH2_Excluded
|
||||
#define PPI_CHG1_CH2_Included PPI_CHG_CH2_Included
|
||||
#define PPI_CHG1_CH1_Pos PPI_CHG_CH1_Pos
|
||||
#define PPI_CHG1_CH1_Msk PPI_CHG_CH1_Msk
|
||||
#define PPI_CHG1_CH1_Excluded PPI_CHG_CH1_Excluded
|
||||
#define PPI_CHG1_CH1_Included PPI_CHG_CH1_Included
|
||||
#define PPI_CHG1_CH0_Pos PPI_CHG_CH0_Pos
|
||||
#define PPI_CHG1_CH0_Msk PPI_CHG_CH0_Msk
|
||||
#define PPI_CHG1_CH0_Excluded PPI_CHG_CH0_Excluded
|
||||
#define PPI_CHG1_CH0_Included PPI_CHG_CH0_Included
|
||||
#define PPI_CHG2_CH15_Pos PPI_CHG_CH15_Pos
|
||||
#define PPI_CHG2_CH15_Msk PPI_CHG_CH15_Msk
|
||||
#define PPI_CHG2_CH15_Excluded PPI_CHG_CH15_Excluded
|
||||
#define PPI_CHG2_CH15_Included PPI_CHG_CH15_Included
|
||||
#define PPI_CHG2_CH14_Pos PPI_CHG_CH14_Pos
|
||||
#define PPI_CHG2_CH14_Msk PPI_CHG_CH14_Msk
|
||||
#define PPI_CHG2_CH14_Excluded PPI_CHG_CH14_Excluded
|
||||
#define PPI_CHG2_CH14_Included PPI_CHG_CH14_Included
|
||||
#define PPI_CHG2_CH13_Pos PPI_CHG_CH13_Pos
|
||||
#define PPI_CHG2_CH13_Msk PPI_CHG_CH13_Msk
|
||||
#define PPI_CHG2_CH13_Excluded PPI_CHG_CH13_Excluded
|
||||
#define PPI_CHG2_CH13_Included PPI_CHG_CH13_Included
|
||||
#define PPI_CHG2_CH12_Pos PPI_CHG_CH12_Pos
|
||||
#define PPI_CHG2_CH12_Msk PPI_CHG_CH12_Msk
|
||||
#define PPI_CHG2_CH12_Excluded PPI_CHG_CH12_Excluded
|
||||
#define PPI_CHG2_CH12_Included PPI_CHG_CH12_Included
|
||||
#define PPI_CHG2_CH11_Pos PPI_CHG_CH11_Pos
|
||||
#define PPI_CHG2_CH11_Msk PPI_CHG_CH11_Msk
|
||||
#define PPI_CHG2_CH11_Excluded PPI_CHG_CH11_Excluded
|
||||
#define PPI_CHG2_CH11_Included PPI_CHG_CH11_Included
|
||||
#define PPI_CHG2_CH10_Pos PPI_CHG_CH10_Pos
|
||||
#define PPI_CHG2_CH10_Msk PPI_CHG_CH10_Msk
|
||||
#define PPI_CHG2_CH10_Excluded PPI_CHG_CH10_Excluded
|
||||
#define PPI_CHG2_CH10_Included PPI_CHG_CH10_Included
|
||||
#define PPI_CHG2_CH9_Pos PPI_CHG_CH9_Pos
|
||||
#define PPI_CHG2_CH9_Msk PPI_CHG_CH9_Msk
|
||||
#define PPI_CHG2_CH9_Excluded PPI_CHG_CH9_Excluded
|
||||
#define PPI_CHG2_CH9_Included PPI_CHG_CH9_Included
|
||||
#define PPI_CHG2_CH8_Pos PPI_CHG_CH8_Pos
|
||||
#define PPI_CHG2_CH8_Msk PPI_CHG_CH8_Msk
|
||||
#define PPI_CHG2_CH8_Excluded PPI_CHG_CH8_Excluded
|
||||
#define PPI_CHG2_CH8_Included PPI_CHG_CH8_Included
|
||||
#define PPI_CHG2_CH7_Pos PPI_CHG_CH7_Pos
|
||||
#define PPI_CHG2_CH7_Msk PPI_CHG_CH7_Msk
|
||||
#define PPI_CHG2_CH7_Excluded PPI_CHG_CH7_Excluded
|
||||
#define PPI_CHG2_CH7_Included PPI_CHG_CH7_Included
|
||||
#define PPI_CHG2_CH6_Pos PPI_CHG_CH6_Pos
|
||||
#define PPI_CHG2_CH6_Msk PPI_CHG_CH6_Msk
|
||||
#define PPI_CHG2_CH6_Excluded PPI_CHG_CH6_Excluded
|
||||
#define PPI_CHG2_CH6_Included PPI_CHG_CH6_Included
|
||||
#define PPI_CHG2_CH5_Pos PPI_CHG_CH5_Pos
|
||||
#define PPI_CHG2_CH5_Msk PPI_CHG_CH5_Msk
|
||||
#define PPI_CHG2_CH5_Excluded PPI_CHG_CH5_Excluded
|
||||
#define PPI_CHG2_CH5_Included PPI_CHG_CH5_Included
|
||||
#define PPI_CHG2_CH4_Pos PPI_CHG_CH4_Pos
|
||||
#define PPI_CHG2_CH4_Msk PPI_CHG_CH4_Msk
|
||||
#define PPI_CHG2_CH4_Excluded PPI_CHG_CH4_Excluded
|
||||
#define PPI_CHG2_CH4_Included PPI_CHG_CH4_Included
|
||||
#define PPI_CHG2_CH3_Pos PPI_CHG_CH3_Pos
|
||||
#define PPI_CHG2_CH3_Msk PPI_CHG_CH3_Msk
|
||||
#define PPI_CHG2_CH3_Excluded PPI_CHG_CH3_Excluded
|
||||
#define PPI_CHG2_CH3_Included PPI_CHG_CH3_Included
|
||||
#define PPI_CHG2_CH2_Pos PPI_CHG_CH2_Pos
|
||||
#define PPI_CHG2_CH2_Msk PPI_CHG_CH2_Msk
|
||||
#define PPI_CHG2_CH2_Excluded PPI_CHG_CH2_Excluded
|
||||
#define PPI_CHG2_CH2_Included PPI_CHG_CH2_Included
|
||||
#define PPI_CHG2_CH1_Pos PPI_CHG_CH1_Pos
|
||||
#define PPI_CHG2_CH1_Msk PPI_CHG_CH1_Msk
|
||||
#define PPI_CHG2_CH1_Excluded PPI_CHG_CH1_Excluded
|
||||
#define PPI_CHG2_CH1_Included PPI_CHG_CH1_Included
|
||||
#define PPI_CHG2_CH0_Pos PPI_CHG_CH0_Pos
|
||||
#define PPI_CHG2_CH0_Msk PPI_CHG_CH0_Msk
|
||||
#define PPI_CHG2_CH0_Excluded PPI_CHG_CH0_Excluded
|
||||
#define PPI_CHG2_CH0_Included PPI_CHG_CH0_Included
|
||||
#define PPI_CHG3_CH15_Pos PPI_CHG_CH15_Pos
|
||||
#define PPI_CHG3_CH15_Msk PPI_CHG_CH15_Msk
|
||||
#define PPI_CHG3_CH15_Excluded PPI_CHG_CH15_Excluded
|
||||
#define PPI_CHG3_CH15_Included PPI_CHG_CH15_Included
|
||||
#define PPI_CHG3_CH14_Pos PPI_CHG_CH14_Pos
|
||||
#define PPI_CHG3_CH14_Msk PPI_CHG_CH14_Msk
|
||||
#define PPI_CHG3_CH14_Excluded PPI_CHG_CH14_Excluded
|
||||
#define PPI_CHG3_CH14_Included PPI_CHG_CH14_Included
|
||||
#define PPI_CHG3_CH13_Pos PPI_CHG_CH13_Pos
|
||||
#define PPI_CHG3_CH13_Msk PPI_CHG_CH13_Msk
|
||||
#define PPI_CHG3_CH13_Excluded PPI_CHG_CH13_Excluded
|
||||
#define PPI_CHG3_CH13_Included PPI_CHG_CH13_Included
|
||||
#define PPI_CHG3_CH12_Pos PPI_CHG_CH12_Pos
|
||||
#define PPI_CHG3_CH12_Msk PPI_CHG_CH12_Msk
|
||||
#define PPI_CHG3_CH12_Excluded PPI_CHG_CH12_Excluded
|
||||
#define PPI_CHG3_CH12_Included PPI_CHG_CH12_Included
|
||||
#define PPI_CHG3_CH11_Pos PPI_CHG_CH11_Pos
|
||||
#define PPI_CHG3_CH11_Msk PPI_CHG_CH11_Msk
|
||||
#define PPI_CHG3_CH11_Excluded PPI_CHG_CH11_Excluded
|
||||
#define PPI_CHG3_CH11_Included PPI_CHG_CH11_Included
|
||||
#define PPI_CHG3_CH10_Pos PPI_CHG_CH10_Pos
|
||||
#define PPI_CHG3_CH10_Msk PPI_CHG_CH10_Msk
|
||||
#define PPI_CHG3_CH10_Excluded PPI_CHG_CH10_Excluded
|
||||
#define PPI_CHG3_CH10_Included PPI_CHG_CH10_Included
|
||||
#define PPI_CHG3_CH9_Pos PPI_CHG_CH9_Pos
|
||||
#define PPI_CHG3_CH9_Msk PPI_CHG_CH9_Msk
|
||||
#define PPI_CHG3_CH9_Excluded PPI_CHG_CH9_Excluded
|
||||
#define PPI_CHG3_CH9_Included PPI_CHG_CH9_Included
|
||||
#define PPI_CHG3_CH8_Pos PPI_CHG_CH8_Pos
|
||||
#define PPI_CHG3_CH8_Msk PPI_CHG_CH8_Msk
|
||||
#define PPI_CHG3_CH8_Excluded PPI_CHG_CH8_Excluded
|
||||
#define PPI_CHG3_CH8_Included PPI_CHG_CH8_Included
|
||||
#define PPI_CHG3_CH7_Pos PPI_CHG_CH7_Pos
|
||||
#define PPI_CHG3_CH7_Msk PPI_CHG_CH7_Msk
|
||||
#define PPI_CHG3_CH7_Excluded PPI_CHG_CH7_Excluded
|
||||
#define PPI_CHG3_CH7_Included PPI_CHG_CH7_Included
|
||||
#define PPI_CHG3_CH6_Pos PPI_CHG_CH6_Pos
|
||||
#define PPI_CHG3_CH6_Msk PPI_CHG_CH6_Msk
|
||||
#define PPI_CHG3_CH6_Excluded PPI_CHG_CH6_Excluded
|
||||
#define PPI_CHG3_CH6_Included PPI_CHG_CH6_Included
|
||||
#define PPI_CHG3_CH5_Pos PPI_CHG_CH5_Pos
|
||||
#define PPI_CHG3_CH5_Msk PPI_CHG_CH5_Msk
|
||||
#define PPI_CHG3_CH5_Excluded PPI_CHG_CH5_Excluded
|
||||
#define PPI_CHG3_CH5_Included PPI_CHG_CH5_Included
|
||||
#define PPI_CHG3_CH4_Pos PPI_CHG_CH4_Pos
|
||||
#define PPI_CHG3_CH4_Msk PPI_CHG_CH4_Msk
|
||||
#define PPI_CHG3_CH4_Excluded PPI_CHG_CH4_Excluded
|
||||
#define PPI_CHG3_CH4_Included PPI_CHG_CH4_Included
|
||||
#define PPI_CHG3_CH3_Pos PPI_CHG_CH3_Pos
|
||||
#define PPI_CHG3_CH3_Msk PPI_CHG_CH3_Msk
|
||||
#define PPI_CHG3_CH3_Excluded PPI_CHG_CH3_Excluded
|
||||
#define PPI_CHG3_CH3_Included PPI_CHG_CH3_Included
|
||||
#define PPI_CHG3_CH2_Pos PPI_CHG_CH2_Pos
|
||||
#define PPI_CHG3_CH2_Msk PPI_CHG_CH2_Msk
|
||||
#define PPI_CHG3_CH2_Excluded PPI_CHG_CH2_Excluded
|
||||
#define PPI_CHG3_CH2_Included PPI_CHG_CH2_Included
|
||||
#define PPI_CHG3_CH1_Pos PPI_CHG_CH1_Pos
|
||||
#define PPI_CHG3_CH1_Msk PPI_CHG_CH1_Msk
|
||||
#define PPI_CHG3_CH1_Excluded PPI_CHG_CH1_Excluded
|
||||
#define PPI_CHG3_CH1_Included PPI_CHG_CH1_Included
|
||||
#define PPI_CHG3_CH0_Pos PPI_CHG_CH0_Pos
|
||||
#define PPI_CHG3_CH0_Msk PPI_CHG_CH0_Msk
|
||||
#define PPI_CHG3_CH0_Excluded PPI_CHG_CH0_Excluded
|
||||
#define PPI_CHG3_CH0_Included PPI_CHG_CH0_Included
|
||||
|
||||
/* SPIS */
|
||||
/* nRF51 devices do not have an SPIS0, only SPIS1. SPIS0_EASYDMA_MAXCNT_SIZE was therefore renamed. */
|
||||
#define SPIS0_EASYDMA_MAXCNT_SIZE SPIS1_EASYDMA_MAXCNT_SIZE
|
||||
|
||||
|
||||
|
||||
/*lint --flb "Leave library region" */
|
||||
|
||||
#endif /* NRF51_DEPRECATED_H */
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2010 - 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 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.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, 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 _NRF51_PERIPHERALS_H
|
||||
#define _NRF51_PERIPHERALS_H
|
||||
|
||||
|
||||
/* Power Peripheral */
|
||||
#define POWER_PRESENT
|
||||
#define POWER_COUNT 1
|
||||
|
||||
#define POWER_FEATURE_RAMON_REGISTERS_PRESENT
|
||||
|
||||
/* Software Interrupts */
|
||||
#define SWI_PRESENT
|
||||
#define SWI_COUNT 6
|
||||
|
||||
/* GPIO */
|
||||
#define GPIO_PRESENT
|
||||
#define GPIO_COUNT 1
|
||||
|
||||
#define P0_PIN_NUM 32
|
||||
|
||||
/* MPU and BPROT */
|
||||
#define BPROT_PRESENT
|
||||
|
||||
#define BPROT_REGIONS_SIZE 4096
|
||||
#define BPROT_REGIONS_NUM 64
|
||||
|
||||
/* Radio */
|
||||
#define RADIO_PRESENT
|
||||
#define RADIO_COUNT 1
|
||||
|
||||
/* Accelerated Address Resolver */
|
||||
#define AAR_PRESENT
|
||||
#define AAR_COUNT 1
|
||||
|
||||
#define AAR_MAX_IRK_NUM 8
|
||||
|
||||
/* AES Electronic CodeBook mode encryption */
|
||||
#define ECB_PRESENT
|
||||
#define ECB_COUNT 1
|
||||
|
||||
/* AES CCM mode encryption */
|
||||
#define CCM_PRESENT
|
||||
#define CCM_COUNT 1
|
||||
|
||||
/* Peripheral to Peripheral Interconnect */
|
||||
#define PPI_PRESENT
|
||||
#define PPI_COUNT 1
|
||||
|
||||
#define PPI_CH_NUM 16
|
||||
#define PPI_FIXED_CH_NUM 12
|
||||
#define PPI_GROUP_NUM 4
|
||||
|
||||
/* Timer/Counter */
|
||||
#define TIMER_PRESENT
|
||||
#define TIMER_COUNT 3
|
||||
|
||||
#define TIMER0_MAX_SIZE 32
|
||||
#define TIMER1_MAX_SIZE 16
|
||||
#define TIMER2_MAX_SIZE 16
|
||||
|
||||
#define TIMER0_CC_NUM 4
|
||||
#define TIMER1_CC_NUM 4
|
||||
#define TIMER2_CC_NUM 4
|
||||
|
||||
/* Real Time Counter */
|
||||
#define RTC_PRESENT
|
||||
#define RTC_COUNT 2
|
||||
|
||||
#define RTC0_CC_NUM 3
|
||||
#define RTC1_CC_NUM 4
|
||||
|
||||
/* RNG */
|
||||
#define RNG_PRESENT
|
||||
#define RNG_COUNT 1
|
||||
|
||||
/* Watchdog Timer */
|
||||
#define WDT_PRESENT
|
||||
#define WDT_COUNT 1
|
||||
|
||||
/* Temperature Sensor */
|
||||
#define TEMP_PRESENT
|
||||
#define TEMP_COUNT 1
|
||||
|
||||
/* Serial Peripheral Interface Master */
|
||||
#define SPI_PRESENT
|
||||
#define SPI_COUNT 2
|
||||
|
||||
/* Serial Peripheral Interface Slave with DMA */
|
||||
#define SPIS_PRESENT
|
||||
#define SPIS_COUNT 1
|
||||
|
||||
#define SPIS1_EASYDMA_MAXCNT_SIZE 8
|
||||
|
||||
/* Two Wire Interface Master */
|
||||
#define TWI_PRESENT
|
||||
#define TWI_COUNT 2
|
||||
|
||||
/* Universal Asynchronous Receiver-Transmitter */
|
||||
#define UART_PRESENT
|
||||
#define UART_COUNT 1
|
||||
|
||||
/* Quadrature Decoder */
|
||||
#define QDEC_PRESENT
|
||||
#define QDEC_COUNT 1
|
||||
|
||||
/* Analog to Digital Converter */
|
||||
#define ADC_PRESENT
|
||||
#define ADC_COUNT 1
|
||||
|
||||
/* GPIO Tasks and Events */
|
||||
#define GPIOTE_PRESENT
|
||||
#define GPIOTE_COUNT 1
|
||||
|
||||
#define GPIOTE_CH_NUM 4
|
||||
|
||||
/* Low Power Comparator */
|
||||
#define LPCOMP_PRESENT
|
||||
#define LPCOMP_COUNT 1
|
||||
|
||||
#define LPCOMP_REFSEL_RESOLUTION 8
|
||||
|
||||
|
||||
#endif // _NRF51_PERIPHERALS_H
|
||||
@@ -0,0 +1,954 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2010 - 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 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.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, 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 NRF51_TO_NRF52_H
|
||||
#define NRF51_TO_NRF52_H
|
||||
|
||||
/*lint ++flb "Enter library region */
|
||||
|
||||
/* This file is given to prevent your SW from not compiling with the name changes between nRF51 and nRF52 devices.
|
||||
* It redefines the old nRF51 names into the new ones as long as the functionality is still supported. If the
|
||||
* functionality is gone, there old names are not defined, so compilation will fail. Note that also includes macros
|
||||
* from the nrf51_deprecated.h file. */
|
||||
|
||||
|
||||
/* IRQ */
|
||||
/* Several peripherals have been added to several indexes. Names of IRQ handlers and IRQ numbers have changed. */
|
||||
#define UART0_IRQHandler UARTE0_UART0_IRQHandler
|
||||
#define SPI0_TWI0_IRQHandler SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler
|
||||
#define SPI1_TWI1_IRQHandler SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler
|
||||
#define ADC_IRQHandler SAADC_IRQHandler
|
||||
#define LPCOMP_IRQHandler COMP_LPCOMP_IRQHandler
|
||||
#define SWI0_IRQHandler SWI0_EGU0_IRQHandler
|
||||
#define SWI1_IRQHandler SWI1_EGU1_IRQHandler
|
||||
#define SWI2_IRQHandler SWI2_EGU2_IRQHandler
|
||||
#define SWI3_IRQHandler SWI3_EGU3_IRQHandler
|
||||
#define SWI4_IRQHandler SWI4_EGU4_IRQHandler
|
||||
#define SWI5_IRQHandler SWI5_EGU5_IRQHandler
|
||||
|
||||
#define UART0_IRQn UARTE0_UART0_IRQn
|
||||
#define SPI0_TWI0_IRQn SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn
|
||||
#define SPI1_TWI1_IRQn SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn
|
||||
#define ADC_IRQn SAADC_IRQn
|
||||
#define LPCOMP_IRQn COMP_LPCOMP_IRQn
|
||||
#define SWI0_IRQn SWI0_EGU0_IRQn
|
||||
#define SWI1_IRQn SWI1_EGU1_IRQn
|
||||
#define SWI2_IRQn SWI2_EGU2_IRQn
|
||||
#define SWI3_IRQn SWI3_EGU3_IRQn
|
||||
#define SWI4_IRQn SWI4_EGU4_IRQn
|
||||
#define SWI5_IRQn SWI5_EGU5_IRQn
|
||||
|
||||
|
||||
/* UICR */
|
||||
/* Register RBPCONF was renamed to APPROTECT. */
|
||||
#define RBPCONF APPROTECT
|
||||
|
||||
#define UICR_RBPCONF_PALL_Pos UICR_APPROTECT_PALL_Pos
|
||||
#define UICR_RBPCONF_PALL_Msk UICR_APPROTECT_PALL_Msk
|
||||
#define UICR_RBPCONF_PALL_Enabled UICR_APPROTECT_PALL_Enabled
|
||||
#define UICR_RBPCONF_PALL_Disabled UICR_APPROTECT_PALL_Disabled
|
||||
|
||||
|
||||
/* GPIO */
|
||||
/* GPIO port was renamed to P0. */
|
||||
#define NRF_GPIO NRF_P0
|
||||
#define NRF_GPIO_BASE NRF_P0_BASE
|
||||
|
||||
|
||||
/* QDEC */
|
||||
/* The registers PSELA, PSELB and PSELLED were restructured into a struct. */
|
||||
#define PSELLED PSEL.LED
|
||||
#define PSELA PSEL.A
|
||||
#define PSELB PSEL.B
|
||||
|
||||
|
||||
/* SPIS */
|
||||
/* The registers PSELSCK, PSELMISO, PSELMOSI, PSELCSN were restructured into a struct. */
|
||||
#define PSELSCK PSEL.SCK
|
||||
#define PSELMISO PSEL.MISO
|
||||
#define PSELMOSI PSEL.MOSI
|
||||
#define PSELCSN PSEL.CSN
|
||||
|
||||
/* The registers RXDPTR, MAXRX, AMOUNTRX were restructured into a struct */
|
||||
#define RXDPTR RXD.PTR
|
||||
#define MAXRX RXD.MAXCNT
|
||||
#define AMOUNTRX RXD.AMOUNT
|
||||
|
||||
#define SPIS_MAXRX_MAXRX_Pos SPIS_RXD_MAXCNT_MAXCNT_Pos
|
||||
#define SPIS_MAXRX_MAXRX_Msk SPIS_RXD_MAXCNT_MAXCNT_Msk
|
||||
|
||||
#define SPIS_AMOUNTRX_AMOUNTRX_Pos SPIS_RXD_AMOUNT_AMOUNT_Pos
|
||||
#define SPIS_AMOUNTRX_AMOUNTRX_Msk SPIS_RXD_AMOUNT_AMOUNT_Msk
|
||||
|
||||
/* The registers TXDPTR, MAXTX, AMOUNTTX were restructured into a struct */
|
||||
#define TXDPTR TXD.PTR
|
||||
#define MAXTX TXD.MAXCNT
|
||||
#define AMOUNTTX TXD.AMOUNT
|
||||
|
||||
#define SPIS_MAXTX_MAXTX_Pos SPIS_TXD_MAXCNT_MAXCNT_Pos
|
||||
#define SPIS_MAXTX_MAXTX_Msk SPIS_TXD_MAXCNT_MAXCNT_Msk
|
||||
|
||||
#define SPIS_AMOUNTTX_AMOUNTTX_Pos SPIS_TXD_AMOUNT_AMOUNT_Pos
|
||||
#define SPIS_AMOUNTTX_AMOUNTTX_Msk SPIS_TXD_AMOUNT_AMOUNT_Msk
|
||||
|
||||
|
||||
/* MPU */
|
||||
/* Part of MPU module was renamed BPROT, while the rest was eliminated. */
|
||||
#define NRF_MPU NRF_BPROT
|
||||
|
||||
/* Register DISABLEINDEBUG macros were affected. */
|
||||
#define MPU_DISABLEINDEBUG_DISABLEINDEBUG_Pos BPROT_DISABLEINDEBUG_DISABLEINDEBUG_Pos
|
||||
#define MPU_DISABLEINDEBUG_DISABLEINDEBUG_Msk BPROT_DISABLEINDEBUG_DISABLEINDEBUG_Msk
|
||||
#define MPU_DISABLEINDEBUG_DISABLEINDEBUG_Enabled BPROT_DISABLEINDEBUG_DISABLEINDEBUG_Enabled
|
||||
#define MPU_DISABLEINDEBUG_DISABLEINDEBUG_Disabled BPROT_DISABLEINDEBUG_DISABLEINDEBUG_Disabled
|
||||
|
||||
/* Registers PROTENSET0 and PROTENSET1 were affected and renamed as CONFIG0 and CONFIG1. */
|
||||
#define PROTENSET0 CONFIG0
|
||||
#define PROTENSET1 CONFIG1
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG63_Pos BPROT_CONFIG1_REGION63_Pos
|
||||
#define MPU_PROTENSET1_PROTREG63_Msk BPROT_CONFIG1_REGION63_Msk
|
||||
#define MPU_PROTENSET1_PROTREG63_Disabled BPROT_CONFIG1_REGION63_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG63_Enabled BPROT_CONFIG1_REGION63_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG63_Set BPROT_CONFIG1_REGION63_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG62_Pos BPROT_CONFIG1_REGION62_Pos
|
||||
#define MPU_PROTENSET1_PROTREG62_Msk BPROT_CONFIG1_REGION62_Msk
|
||||
#define MPU_PROTENSET1_PROTREG62_Disabled BPROT_CONFIG1_REGION62_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG62_Enabled BPROT_CONFIG1_REGION62_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG62_Set BPROT_CONFIG1_REGION62_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG61_Pos BPROT_CONFIG1_REGION61_Pos
|
||||
#define MPU_PROTENSET1_PROTREG61_Msk BPROT_CONFIG1_REGION61_Msk
|
||||
#define MPU_PROTENSET1_PROTREG61_Disabled BPROT_CONFIG1_REGION61_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG61_Enabled BPROT_CONFIG1_REGION61_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG61_Set BPROT_CONFIG1_REGION61_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG60_Pos BPROT_CONFIG1_REGION60_Pos
|
||||
#define MPU_PROTENSET1_PROTREG60_Msk BPROT_CONFIG1_REGION60_Msk
|
||||
#define MPU_PROTENSET1_PROTREG60_Disabled BPROT_CONFIG1_REGION60_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG60_Enabled BPROT_CONFIG1_REGION60_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG60_Set BPROT_CONFIG1_REGION60_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG59_Pos BPROT_CONFIG1_REGION59_Pos
|
||||
#define MPU_PROTENSET1_PROTREG59_Msk BPROT_CONFIG1_REGION59_Msk
|
||||
#define MPU_PROTENSET1_PROTREG59_Disabled BPROT_CONFIG1_REGION59_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG59_Enabled BPROT_CONFIG1_REGION59_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG59_Set BPROT_CONFIG1_REGION59_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG58_Pos BPROT_CONFIG1_REGION58_Pos
|
||||
#define MPU_PROTENSET1_PROTREG58_Msk BPROT_CONFIG1_REGION58_Msk
|
||||
#define MPU_PROTENSET1_PROTREG58_Disabled BPROT_CONFIG1_REGION58_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG58_Enabled BPROT_CONFIG1_REGION58_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG58_Set BPROT_CONFIG1_REGION58_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG57_Pos BPROT_CONFIG1_REGION57_Pos
|
||||
#define MPU_PROTENSET1_PROTREG57_Msk BPROT_CONFIG1_REGION57_Msk
|
||||
#define MPU_PROTENSET1_PROTREG57_Disabled BPROT_CONFIG1_REGION57_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG57_Enabled BPROT_CONFIG1_REGION57_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG57_Set BPROT_CONFIG1_REGION57_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG56_Pos BPROT_CONFIG1_REGION56_Pos
|
||||
#define MPU_PROTENSET1_PROTREG56_Msk BPROT_CONFIG1_REGION56_Msk
|
||||
#define MPU_PROTENSET1_PROTREG56_Disabled BPROT_CONFIG1_REGION56_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG56_Enabled BPROT_CONFIG1_REGION56_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG56_Set BPROT_CONFIG1_REGION56_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG55_Pos BPROT_CONFIG1_REGION55_Pos
|
||||
#define MPU_PROTENSET1_PROTREG55_Msk BPROT_CONFIG1_REGION55_Msk
|
||||
#define MPU_PROTENSET1_PROTREG55_Disabled BPROT_CONFIG1_REGION55_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG55_Enabled BPROT_CONFIG1_REGION55_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG55_Set BPROT_CONFIG1_REGION55_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG54_Pos BPROT_CONFIG1_REGION54_Pos
|
||||
#define MPU_PROTENSET1_PROTREG54_Msk BPROT_CONFIG1_REGION54_Msk
|
||||
#define MPU_PROTENSET1_PROTREG54_Disabled BPROT_CONFIG1_REGION54_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG54_Enabled BPROT_CONFIG1_REGION54_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG54_Set BPROT_CONFIG1_REGION54_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG53_Pos BPROT_CONFIG1_REGION53_Pos
|
||||
#define MPU_PROTENSET1_PROTREG53_Msk BPROT_CONFIG1_REGION53_Msk
|
||||
#define MPU_PROTENSET1_PROTREG53_Disabled BPROT_CONFIG1_REGION53_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG53_Enabled BPROT_CONFIG1_REGION53_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG53_Set BPROT_CONFIG1_REGION53_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG52_Pos BPROT_CONFIG1_REGION52_Pos
|
||||
#define MPU_PROTENSET1_PROTREG52_Msk BPROT_CONFIG1_REGION52_Msk
|
||||
#define MPU_PROTENSET1_PROTREG52_Disabled BPROT_CONFIG1_REGION52_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG52_Enabled BPROT_CONFIG1_REGION52_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG52_Set BPROT_CONFIG1_REGION52_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG51_Pos BPROT_CONFIG1_REGION51_Pos
|
||||
#define MPU_PROTENSET1_PROTREG51_Msk BPROT_CONFIG1_REGION51_Msk
|
||||
#define MPU_PROTENSET1_PROTREG51_Disabled BPROT_CONFIG1_REGION51_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG51_Enabled BPROT_CONFIG1_REGION51_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG51_Set BPROT_CONFIG1_REGION51_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG50_Pos BPROT_CONFIG1_REGION50_Pos
|
||||
#define MPU_PROTENSET1_PROTREG50_Msk BPROT_CONFIG1_REGION50_Msk
|
||||
#define MPU_PROTENSET1_PROTREG50_Disabled BPROT_CONFIG1_REGION50_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG50_Enabled BPROT_CONFIG1_REGION50_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG50_Set BPROT_CONFIG1_REGION50_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG49_Pos BPROT_CONFIG1_REGION49_Pos
|
||||
#define MPU_PROTENSET1_PROTREG49_Msk BPROT_CONFIG1_REGION49_Msk
|
||||
#define MPU_PROTENSET1_PROTREG49_Disabled BPROT_CONFIG1_REGION49_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG49_Enabled BPROT_CONFIG1_REGION49_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG49_Set BPROT_CONFIG1_REGION49_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG48_Pos BPROT_CONFIG1_REGION48_Pos
|
||||
#define MPU_PROTENSET1_PROTREG48_Msk BPROT_CONFIG1_REGION48_Msk
|
||||
#define MPU_PROTENSET1_PROTREG48_Disabled BPROT_CONFIG1_REGION48_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG48_Enabled BPROT_CONFIG1_REGION48_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG48_Set BPROT_CONFIG1_REGION48_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG47_Pos BPROT_CONFIG1_REGION47_Pos
|
||||
#define MPU_PROTENSET1_PROTREG47_Msk BPROT_CONFIG1_REGION47_Msk
|
||||
#define MPU_PROTENSET1_PROTREG47_Disabled BPROT_CONFIG1_REGION47_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG47_Enabled BPROT_CONFIG1_REGION47_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG47_Set BPROT_CONFIG1_REGION47_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG46_Pos BPROT_CONFIG1_REGION46_Pos
|
||||
#define MPU_PROTENSET1_PROTREG46_Msk BPROT_CONFIG1_REGION46_Msk
|
||||
#define MPU_PROTENSET1_PROTREG46_Disabled BPROT_CONFIG1_REGION46_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG46_Enabled BPROT_CONFIG1_REGION46_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG46_Set BPROT_CONFIG1_REGION46_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG45_Pos BPROT_CONFIG1_REGION45_Pos
|
||||
#define MPU_PROTENSET1_PROTREG45_Msk BPROT_CONFIG1_REGION45_Msk
|
||||
#define MPU_PROTENSET1_PROTREG45_Disabled BPROT_CONFIG1_REGION45_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG45_Enabled BPROT_CONFIG1_REGION45_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG45_Set BPROT_CONFIG1_REGION45_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG44_Pos BPROT_CONFIG1_REGION44_Pos
|
||||
#define MPU_PROTENSET1_PROTREG44_Msk BPROT_CONFIG1_REGION44_Msk
|
||||
#define MPU_PROTENSET1_PROTREG44_Disabled BPROT_CONFIG1_REGION44_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG44_Enabled BPROT_CONFIG1_REGION44_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG44_Set BPROT_CONFIG1_REGION44_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG43_Pos BPROT_CONFIG1_REGION43_Pos
|
||||
#define MPU_PROTENSET1_PROTREG43_Msk BPROT_CONFIG1_REGION43_Msk
|
||||
#define MPU_PROTENSET1_PROTREG43_Disabled BPROT_CONFIG1_REGION43_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG43_Enabled BPROT_CONFIG1_REGION43_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG43_Set BPROT_CONFIG1_REGION43_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG42_Pos BPROT_CONFIG1_REGION42_Pos
|
||||
#define MPU_PROTENSET1_PROTREG42_Msk BPROT_CONFIG1_REGION42_Msk
|
||||
#define MPU_PROTENSET1_PROTREG42_Disabled BPROT_CONFIG1_REGION42_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG42_Enabled BPROT_CONFIG1_REGION42_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG42_Set BPROT_CONFIG1_REGION42_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG41_Pos BPROT_CONFIG1_REGION41_Pos
|
||||
#define MPU_PROTENSET1_PROTREG41_Msk BPROT_CONFIG1_REGION41_Msk
|
||||
#define MPU_PROTENSET1_PROTREG41_Disabled BPROT_CONFIG1_REGION41_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG41_Enabled BPROT_CONFIG1_REGION41_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG41_Set BPROT_CONFIG1_REGION41_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG40_Pos BPROT_CONFIG1_REGION40_Pos
|
||||
#define MPU_PROTENSET1_PROTREG40_Msk BPROT_CONFIG1_REGION40_Msk
|
||||
#define MPU_PROTENSET1_PROTREG40_Disabled BPROT_CONFIG1_REGION40_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG40_Enabled BPROT_CONFIG1_REGION40_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG40_Set BPROT_CONFIG1_REGION40_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG39_Pos BPROT_CONFIG1_REGION39_Pos
|
||||
#define MPU_PROTENSET1_PROTREG39_Msk BPROT_CONFIG1_REGION39_Msk
|
||||
#define MPU_PROTENSET1_PROTREG39_Disabled BPROT_CONFIG1_REGION39_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG39_Enabled BPROT_CONFIG1_REGION39_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG39_Set BPROT_CONFIG1_REGION39_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG38_Pos BPROT_CONFIG1_REGION38_Pos
|
||||
#define MPU_PROTENSET1_PROTREG38_Msk BPROT_CONFIG1_REGION38_Msk
|
||||
#define MPU_PROTENSET1_PROTREG38_Disabled BPROT_CONFIG1_REGION38_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG38_Enabled BPROT_CONFIG1_REGION38_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG38_Set BPROT_CONFIG1_REGION38_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG37_Pos BPROT_CONFIG1_REGION37_Pos
|
||||
#define MPU_PROTENSET1_PROTREG37_Msk BPROT_CONFIG1_REGION37_Msk
|
||||
#define MPU_PROTENSET1_PROTREG37_Disabled BPROT_CONFIG1_REGION37_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG37_Enabled BPROT_CONFIG1_REGION37_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG37_Set BPROT_CONFIG1_REGION37_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG36_Pos BPROT_CONFIG1_REGION36_Pos
|
||||
#define MPU_PROTENSET1_PROTREG36_Msk BPROT_CONFIG1_REGION36_Msk
|
||||
#define MPU_PROTENSET1_PROTREG36_Disabled BPROT_CONFIG1_REGION36_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG36_Enabled BPROT_CONFIG1_REGION36_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG36_Set BPROT_CONFIG1_REGION36_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG35_Pos BPROT_CONFIG1_REGION35_Pos
|
||||
#define MPU_PROTENSET1_PROTREG35_Msk BPROT_CONFIG1_REGION35_Msk
|
||||
#define MPU_PROTENSET1_PROTREG35_Disabled BPROT_CONFIG1_REGION35_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG35_Enabled BPROT_CONFIG1_REGION35_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG35_Set BPROT_CONFIG1_REGION35_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG34_Pos BPROT_CONFIG1_REGION34_Pos
|
||||
#define MPU_PROTENSET1_PROTREG34_Msk BPROT_CONFIG1_REGION34_Msk
|
||||
#define MPU_PROTENSET1_PROTREG34_Disabled BPROT_CONFIG1_REGION34_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG34_Enabled BPROT_CONFIG1_REGION34_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG34_Set BPROT_CONFIG1_REGION34_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG33_Pos BPROT_CONFIG1_REGION33_Pos
|
||||
#define MPU_PROTENSET1_PROTREG33_Msk BPROT_CONFIG1_REGION33_Msk
|
||||
#define MPU_PROTENSET1_PROTREG33_Disabled BPROT_CONFIG1_REGION33_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG33_Enabled BPROT_CONFIG1_REGION33_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG33_Set BPROT_CONFIG1_REGION33_Enabled
|
||||
|
||||
#define MPU_PROTENSET1_PROTREG32_Pos BPROT_CONFIG1_REGION32_Pos
|
||||
#define MPU_PROTENSET1_PROTREG32_Msk BPROT_CONFIG1_REGION32_Msk
|
||||
#define MPU_PROTENSET1_PROTREG32_Disabled BPROT_CONFIG1_REGION32_Disabled
|
||||
#define MPU_PROTENSET1_PROTREG32_Enabled BPROT_CONFIG1_REGION32_Enabled
|
||||
#define MPU_PROTENSET1_PROTREG32_Set BPROT_CONFIG1_REGION32_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG31_Pos BPROT_CONFIG0_REGION31_Pos
|
||||
#define MPU_PROTENSET0_PROTREG31_Msk BPROT_CONFIG0_REGION31_Msk
|
||||
#define MPU_PROTENSET0_PROTREG31_Disabled BPROT_CONFIG0_REGION31_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG31_Enabled BPROT_CONFIG0_REGION31_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG31_Set BPROT_CONFIG0_REGION31_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG30_Pos BPROT_CONFIG0_REGION30_Pos
|
||||
#define MPU_PROTENSET0_PROTREG30_Msk BPROT_CONFIG0_REGION30_Msk
|
||||
#define MPU_PROTENSET0_PROTREG30_Disabled BPROT_CONFIG0_REGION30_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG30_Enabled BPROT_CONFIG0_REGION30_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG30_Set BPROT_CONFIG0_REGION30_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG29_Pos BPROT_CONFIG0_REGION29_Pos
|
||||
#define MPU_PROTENSET0_PROTREG29_Msk BPROT_CONFIG0_REGION29_Msk
|
||||
#define MPU_PROTENSET0_PROTREG29_Disabled BPROT_CONFIG0_REGION29_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG29_Enabled BPROT_CONFIG0_REGION29_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG29_Set BPROT_CONFIG0_REGION29_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG28_Pos BPROT_CONFIG0_REGION28_Pos
|
||||
#define MPU_PROTENSET0_PROTREG28_Msk BPROT_CONFIG0_REGION28_Msk
|
||||
#define MPU_PROTENSET0_PROTREG28_Disabled BPROT_CONFIG0_REGION28_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG28_Enabled BPROT_CONFIG0_REGION28_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG28_Set BPROT_CONFIG0_REGION28_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG27_Pos BPROT_CONFIG0_REGION27_Pos
|
||||
#define MPU_PROTENSET0_PROTREG27_Msk BPROT_CONFIG0_REGION27_Msk
|
||||
#define MPU_PROTENSET0_PROTREG27_Disabled BPROT_CONFIG0_REGION27_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG27_Enabled BPROT_CONFIG0_REGION27_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG27_Set BPROT_CONFIG0_REGION27_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG26_Pos BPROT_CONFIG0_REGION26_Pos
|
||||
#define MPU_PROTENSET0_PROTREG26_Msk BPROT_CONFIG0_REGION26_Msk
|
||||
#define MPU_PROTENSET0_PROTREG26_Disabled BPROT_CONFIG0_REGION26_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG26_Enabled BPROT_CONFIG0_REGION26_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG26_Set BPROT_CONFIG0_REGION26_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG25_Pos BPROT_CONFIG0_REGION25_Pos
|
||||
#define MPU_PROTENSET0_PROTREG25_Msk BPROT_CONFIG0_REGION25_Msk
|
||||
#define MPU_PROTENSET0_PROTREG25_Disabled BPROT_CONFIG0_REGION25_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG25_Enabled BPROT_CONFIG0_REGION25_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG25_Set BPROT_CONFIG0_REGION25_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG24_Pos BPROT_CONFIG0_REGION24_Pos
|
||||
#define MPU_PROTENSET0_PROTREG24_Msk BPROT_CONFIG0_REGION24_Msk
|
||||
#define MPU_PROTENSET0_PROTREG24_Disabled BPROT_CONFIG0_REGION24_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG24_Enabled BPROT_CONFIG0_REGION24_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG24_Set BPROT_CONFIG0_REGION24_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG23_Pos BPROT_CONFIG0_REGION23_Pos
|
||||
#define MPU_PROTENSET0_PROTREG23_Msk BPROT_CONFIG0_REGION23_Msk
|
||||
#define MPU_PROTENSET0_PROTREG23_Disabled BPROT_CONFIG0_REGION23_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG23_Enabled BPROT_CONFIG0_REGION23_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG23_Set BPROT_CONFIG0_REGION23_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG22_Pos BPROT_CONFIG0_REGION22_Pos
|
||||
#define MPU_PROTENSET0_PROTREG22_Msk BPROT_CONFIG0_REGION22_Msk
|
||||
#define MPU_PROTENSET0_PROTREG22_Disabled BPROT_CONFIG0_REGION22_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG22_Enabled BPROT_CONFIG0_REGION22_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG22_Set BPROT_CONFIG0_REGION22_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG21_Pos BPROT_CONFIG0_REGION21_Pos
|
||||
#define MPU_PROTENSET0_PROTREG21_Msk BPROT_CONFIG0_REGION21_Msk
|
||||
#define MPU_PROTENSET0_PROTREG21_Disabled BPROT_CONFIG0_REGION21_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG21_Enabled BPROT_CONFIG0_REGION21_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG21_Set BPROT_CONFIG0_REGION21_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG20_Pos BPROT_CONFIG0_REGION20_Pos
|
||||
#define MPU_PROTENSET0_PROTREG20_Msk BPROT_CONFIG0_REGION20_Msk
|
||||
#define MPU_PROTENSET0_PROTREG20_Disabled BPROT_CONFIG0_REGION20_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG20_Enabled BPROT_CONFIG0_REGION20_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG20_Set BPROT_CONFIG0_REGION20_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG19_Pos BPROT_CONFIG0_REGION19_Pos
|
||||
#define MPU_PROTENSET0_PROTREG19_Msk BPROT_CONFIG0_REGION19_Msk
|
||||
#define MPU_PROTENSET0_PROTREG19_Disabled BPROT_CONFIG0_REGION19_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG19_Enabled BPROT_CONFIG0_REGION19_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG19_Set BPROT_CONFIG0_REGION19_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG18_Pos BPROT_CONFIG0_REGION18_Pos
|
||||
#define MPU_PROTENSET0_PROTREG18_Msk BPROT_CONFIG0_REGION18_Msk
|
||||
#define MPU_PROTENSET0_PROTREG18_Disabled BPROT_CONFIG0_REGION18_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG18_Enabled BPROT_CONFIG0_REGION18_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG18_Set BPROT_CONFIG0_REGION18_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG17_Pos BPROT_CONFIG0_REGION17_Pos
|
||||
#define MPU_PROTENSET0_PROTREG17_Msk BPROT_CONFIG0_REGION17_Msk
|
||||
#define MPU_PROTENSET0_PROTREG17_Disabled BPROT_CONFIG0_REGION17_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG17_Enabled BPROT_CONFIG0_REGION17_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG17_Set BPROT_CONFIG0_REGION17_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG16_Pos BPROT_CONFIG0_REGION16_Pos
|
||||
#define MPU_PROTENSET0_PROTREG16_Msk BPROT_CONFIG0_REGION16_Msk
|
||||
#define MPU_PROTENSET0_PROTREG16_Disabled BPROT_CONFIG0_REGION16_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG16_Enabled BPROT_CONFIG0_REGION16_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG16_Set BPROT_CONFIG0_REGION16_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG15_Pos BPROT_CONFIG0_REGION15_Pos
|
||||
#define MPU_PROTENSET0_PROTREG15_Msk BPROT_CONFIG0_REGION15_Msk
|
||||
#define MPU_PROTENSET0_PROTREG15_Disabled BPROT_CONFIG0_REGION15_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG15_Enabled BPROT_CONFIG0_REGION15_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG15_Set BPROT_CONFIG0_REGION15_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG14_Pos BPROT_CONFIG0_REGION14_Pos
|
||||
#define MPU_PROTENSET0_PROTREG14_Msk BPROT_CONFIG0_REGION14_Msk
|
||||
#define MPU_PROTENSET0_PROTREG14_Disabled BPROT_CONFIG0_REGION14_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG14_Enabled BPROT_CONFIG0_REGION14_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG14_Set BPROT_CONFIG0_REGION14_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG13_Pos BPROT_CONFIG0_REGION13_Pos
|
||||
#define MPU_PROTENSET0_PROTREG13_Msk BPROT_CONFIG0_REGION13_Msk
|
||||
#define MPU_PROTENSET0_PROTREG13_Disabled BPROT_CONFIG0_REGION13_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG13_Enabled BPROT_CONFIG0_REGION13_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG13_Set BPROT_CONFIG0_REGION13_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG12_Pos BPROT_CONFIG0_REGION12_Pos
|
||||
#define MPU_PROTENSET0_PROTREG12_Msk BPROT_CONFIG0_REGION12_Msk
|
||||
#define MPU_PROTENSET0_PROTREG12_Disabled BPROT_CONFIG0_REGION12_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG12_Enabled BPROT_CONFIG0_REGION12_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG12_Set BPROT_CONFIG0_REGION12_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG11_Pos BPROT_CONFIG0_REGION11_Pos
|
||||
#define MPU_PROTENSET0_PROTREG11_Msk BPROT_CONFIG0_REGION11_Msk
|
||||
#define MPU_PROTENSET0_PROTREG11_Disabled BPROT_CONFIG0_REGION11_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG11_Enabled BPROT_CONFIG0_REGION11_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG11_Set BPROT_CONFIG0_REGION11_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG10_Pos BPROT_CONFIG0_REGION10_Pos
|
||||
#define MPU_PROTENSET0_PROTREG10_Msk BPROT_CONFIG0_REGION10_Msk
|
||||
#define MPU_PROTENSET0_PROTREG10_Disabled BPROT_CONFIG0_REGION10_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG10_Enabled BPROT_CONFIG0_REGION10_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG10_Set BPROT_CONFIG0_REGION10_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG9_Pos BPROT_CONFIG0_REGION9_Pos
|
||||
#define MPU_PROTENSET0_PROTREG9_Msk BPROT_CONFIG0_REGION9_Msk
|
||||
#define MPU_PROTENSET0_PROTREG9_Disabled BPROT_CONFIG0_REGION9_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG9_Enabled BPROT_CONFIG0_REGION9_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG9_Set BPROT_CONFIG0_REGION9_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG8_Pos BPROT_CONFIG0_REGION8_Pos
|
||||
#define MPU_PROTENSET0_PROTREG8_Msk BPROT_CONFIG0_REGION8_Msk
|
||||
#define MPU_PROTENSET0_PROTREG8_Disabled BPROT_CONFIG0_REGION8_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG8_Enabled BPROT_CONFIG0_REGION8_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG8_Set BPROT_CONFIG0_REGION8_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG7_Pos BPROT_CONFIG0_REGION7_Pos
|
||||
#define MPU_PROTENSET0_PROTREG7_Msk BPROT_CONFIG0_REGION7_Msk
|
||||
#define MPU_PROTENSET0_PROTREG7_Disabled BPROT_CONFIG0_REGION7_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG7_Enabled BPROT_CONFIG0_REGION7_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG7_Set BPROT_CONFIG0_REGION7_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG6_Pos BPROT_CONFIG0_REGION6_Pos
|
||||
#define MPU_PROTENSET0_PROTREG6_Msk BPROT_CONFIG0_REGION6_Msk
|
||||
#define MPU_PROTENSET0_PROTREG6_Disabled BPROT_CONFIG0_REGION6_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG6_Enabled BPROT_CONFIG0_REGION6_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG6_Set BPROT_CONFIG0_REGION6_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG5_Pos BPROT_CONFIG0_REGION5_Pos
|
||||
#define MPU_PROTENSET0_PROTREG5_Msk BPROT_CONFIG0_REGION5_Msk
|
||||
#define MPU_PROTENSET0_PROTREG5_Disabled BPROT_CONFIG0_REGION5_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG5_Enabled BPROT_CONFIG0_REGION5_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG5_Set BPROT_CONFIG0_REGION5_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG4_Pos BPROT_CONFIG0_REGION4_Pos
|
||||
#define MPU_PROTENSET0_PROTREG4_Msk BPROT_CONFIG0_REGION4_Msk
|
||||
#define MPU_PROTENSET0_PROTREG4_Disabled BPROT_CONFIG0_REGION4_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG4_Enabled BPROT_CONFIG0_REGION4_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG4_Set BPROT_CONFIG0_REGION4_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG3_Pos BPROT_CONFIG0_REGION3_Pos
|
||||
#define MPU_PROTENSET0_PROTREG3_Msk BPROT_CONFIG0_REGION3_Msk
|
||||
#define MPU_PROTENSET0_PROTREG3_Disabled BPROT_CONFIG0_REGION3_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG3_Enabled BPROT_CONFIG0_REGION3_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG3_Set BPROT_CONFIG0_REGION3_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG2_Pos BPROT_CONFIG0_REGION2_Pos
|
||||
#define MPU_PROTENSET0_PROTREG2_Msk BPROT_CONFIG0_REGION2_Msk
|
||||
#define MPU_PROTENSET0_PROTREG2_Disabled BPROT_CONFIG0_REGION2_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG2_Enabled BPROT_CONFIG0_REGION2_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG2_Set BPROT_CONFIG0_REGION2_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG1_Pos BPROT_CONFIG0_REGION1_Pos
|
||||
#define MPU_PROTENSET0_PROTREG1_Msk BPROT_CONFIG0_REGION1_Msk
|
||||
#define MPU_PROTENSET0_PROTREG1_Disabled BPROT_CONFIG0_REGION1_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG1_Enabled BPROT_CONFIG0_REGION1_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG1_Set BPROT_CONFIG0_REGION1_Enabled
|
||||
|
||||
#define MPU_PROTENSET0_PROTREG0_Pos BPROT_CONFIG0_REGION0_Pos
|
||||
#define MPU_PROTENSET0_PROTREG0_Msk BPROT_CONFIG0_REGION0_Msk
|
||||
#define MPU_PROTENSET0_PROTREG0_Disabled BPROT_CONFIG0_REGION0_Disabled
|
||||
#define MPU_PROTENSET0_PROTREG0_Enabled BPROT_CONFIG0_REGION0_Enabled
|
||||
#define MPU_PROTENSET0_PROTREG0_Set BPROT_CONFIG0_REGION0_Enabled
|
||||
|
||||
|
||||
/* From nrf51_deprecated.h */
|
||||
|
||||
/* NVMC */
|
||||
/* The register ERASEPROTECTEDPAGE changed name to ERASEPCR0 in the documentation. */
|
||||
#define ERASEPROTECTEDPAGE ERASEPCR0
|
||||
|
||||
|
||||
/* IRQ */
|
||||
/* COMP module was eliminated. Adapted to nrf52 headers. */
|
||||
#define LPCOMP_COMP_IRQHandler COMP_LPCOMP_IRQHandler
|
||||
#define LPCOMP_COMP_IRQn COMP_LPCOMP_IRQn
|
||||
|
||||
|
||||
/* REFSEL register redefined enumerated values and added some more. */
|
||||
#define LPCOMP_REFSEL_REFSEL_SupplyOneEighthPrescaling LPCOMP_REFSEL_REFSEL_Ref1_8Vdd
|
||||
#define LPCOMP_REFSEL_REFSEL_SupplyTwoEighthsPrescaling LPCOMP_REFSEL_REFSEL_Ref2_8Vdd
|
||||
#define LPCOMP_REFSEL_REFSEL_SupplyThreeEighthsPrescaling LPCOMP_REFSEL_REFSEL_Ref3_8Vdd
|
||||
#define LPCOMP_REFSEL_REFSEL_SupplyFourEighthsPrescaling LPCOMP_REFSEL_REFSEL_Ref4_8Vdd
|
||||
#define LPCOMP_REFSEL_REFSEL_SupplyFiveEighthsPrescaling LPCOMP_REFSEL_REFSEL_Ref5_8Vdd
|
||||
#define LPCOMP_REFSEL_REFSEL_SupplySixEighthsPrescaling LPCOMP_REFSEL_REFSEL_Ref6_8Vdd
|
||||
#define LPCOMP_REFSEL_REFSEL_SupplySevenEighthsPrescaling LPCOMP_REFSEL_REFSEL_Ref7_8Vdd
|
||||
|
||||
|
||||
/* RADIO */
|
||||
/* The name of the field SKIPADDR was corrected. Old macros added for compatibility. */
|
||||
#define RADIO_CRCCNF_SKIP_ADDR_Pos RADIO_CRCCNF_SKIPADDR_Pos
|
||||
#define RADIO_CRCCNF_SKIP_ADDR_Msk RADIO_CRCCNF_SKIPADDR_Msk
|
||||
#define RADIO_CRCCNF_SKIP_ADDR_Include RADIO_CRCCNF_SKIPADDR_Include
|
||||
#define RADIO_CRCCNF_SKIP_ADDR_Skip RADIO_CRCCNF_SKIPADDR_Skip
|
||||
|
||||
|
||||
/* FICR */
|
||||
/* The registers FICR.DEVICEID0 and FICR.DEVICEID1 were renamed into an array. */
|
||||
#define DEVICEID0 DEVICEID[0]
|
||||
#define DEVICEID1 DEVICEID[1]
|
||||
|
||||
/* The registers FICR.ER0, FICR.ER1, FICR.ER2 and FICR.ER3 were renamed into an array. */
|
||||
#define ER0 ER[0]
|
||||
#define ER1 ER[1]
|
||||
#define ER2 ER[2]
|
||||
#define ER3 ER[3]
|
||||
|
||||
/* The registers FICR.IR0, FICR.IR1, FICR.IR2 and FICR.IR3 were renamed into an array. */
|
||||
#define IR0 IR[0]
|
||||
#define IR1 IR[1]
|
||||
#define IR2 IR[2]
|
||||
#define IR3 IR[3]
|
||||
|
||||
/* The registers FICR.DEVICEADDR0 and FICR.DEVICEADDR1 were renamed into an array. */
|
||||
#define DEVICEADDR0 DEVICEADDR[0]
|
||||
#define DEVICEADDR1 DEVICEADDR[1]
|
||||
|
||||
|
||||
/* PPI */
|
||||
/* The tasks PPI.TASKS_CHGxEN and PPI.TASKS_CHGxDIS were renamed into an array of structs. */
|
||||
#define TASKS_CHG0EN TASKS_CHG[0].EN
|
||||
#define TASKS_CHG0DIS TASKS_CHG[0].DIS
|
||||
#define TASKS_CHG1EN TASKS_CHG[1].EN
|
||||
#define TASKS_CHG1DIS TASKS_CHG[1].DIS
|
||||
#define TASKS_CHG2EN TASKS_CHG[2].EN
|
||||
#define TASKS_CHG2DIS TASKS_CHG[2].DIS
|
||||
#define TASKS_CHG3EN TASKS_CHG[3].EN
|
||||
#define TASKS_CHG3DIS TASKS_CHG[3].DIS
|
||||
|
||||
/* The registers PPI.CHx_EEP and PPI.CHx_TEP were renamed into an array of structs. */
|
||||
#define CH0_EEP CH[0].EEP
|
||||
#define CH0_TEP CH[0].TEP
|
||||
#define CH1_EEP CH[1].EEP
|
||||
#define CH1_TEP CH[1].TEP
|
||||
#define CH2_EEP CH[2].EEP
|
||||
#define CH2_TEP CH[2].TEP
|
||||
#define CH3_EEP CH[3].EEP
|
||||
#define CH3_TEP CH[3].TEP
|
||||
#define CH4_EEP CH[4].EEP
|
||||
#define CH4_TEP CH[4].TEP
|
||||
#define CH5_EEP CH[5].EEP
|
||||
#define CH5_TEP CH[5].TEP
|
||||
#define CH6_EEP CH[6].EEP
|
||||
#define CH6_TEP CH[6].TEP
|
||||
#define CH7_EEP CH[7].EEP
|
||||
#define CH7_TEP CH[7].TEP
|
||||
#define CH8_EEP CH[8].EEP
|
||||
#define CH8_TEP CH[8].TEP
|
||||
#define CH9_EEP CH[9].EEP
|
||||
#define CH9_TEP CH[9].TEP
|
||||
#define CH10_EEP CH[10].EEP
|
||||
#define CH10_TEP CH[10].TEP
|
||||
#define CH11_EEP CH[11].EEP
|
||||
#define CH11_TEP CH[11].TEP
|
||||
#define CH12_EEP CH[12].EEP
|
||||
#define CH12_TEP CH[12].TEP
|
||||
#define CH13_EEP CH[13].EEP
|
||||
#define CH13_TEP CH[13].TEP
|
||||
#define CH14_EEP CH[14].EEP
|
||||
#define CH14_TEP CH[14].TEP
|
||||
#define CH15_EEP CH[15].EEP
|
||||
#define CH15_TEP CH[15].TEP
|
||||
|
||||
/* The registers PPI.CHG0, PPI.CHG1, PPI.CHG2 and PPI.CHG3 were renamed into an array. */
|
||||
#define CHG0 CHG[0]
|
||||
#define CHG1 CHG[1]
|
||||
#define CHG2 CHG[2]
|
||||
#define CHG3 CHG[3]
|
||||
|
||||
/* All bitfield macros for the CHGx registers therefore changed name. */
|
||||
#define PPI_CHG0_CH15_Pos PPI_CHG_CH15_Pos
|
||||
#define PPI_CHG0_CH15_Msk PPI_CHG_CH15_Msk
|
||||
#define PPI_CHG0_CH15_Excluded PPI_CHG_CH15_Excluded
|
||||
#define PPI_CHG0_CH15_Included PPI_CHG_CH15_Included
|
||||
|
||||
#define PPI_CHG0_CH14_Pos PPI_CHG_CH14_Pos
|
||||
#define PPI_CHG0_CH14_Msk PPI_CHG_CH14_Msk
|
||||
#define PPI_CHG0_CH14_Excluded PPI_CHG_CH14_Excluded
|
||||
#define PPI_CHG0_CH14_Included PPI_CHG_CH14_Included
|
||||
|
||||
#define PPI_CHG0_CH13_Pos PPI_CHG_CH13_Pos
|
||||
#define PPI_CHG0_CH13_Msk PPI_CHG_CH13_Msk
|
||||
#define PPI_CHG0_CH13_Excluded PPI_CHG_CH13_Excluded
|
||||
#define PPI_CHG0_CH13_Included PPI_CHG_CH13_Included
|
||||
|
||||
#define PPI_CHG0_CH12_Pos PPI_CHG_CH12_Pos
|
||||
#define PPI_CHG0_CH12_Msk PPI_CHG_CH12_Msk
|
||||
#define PPI_CHG0_CH12_Excluded PPI_CHG_CH12_Excluded
|
||||
#define PPI_CHG0_CH12_Included PPI_CHG_CH12_Included
|
||||
|
||||
#define PPI_CHG0_CH11_Pos PPI_CHG_CH11_Pos
|
||||
#define PPI_CHG0_CH11_Msk PPI_CHG_CH11_Msk
|
||||
#define PPI_CHG0_CH11_Excluded PPI_CHG_CH11_Excluded
|
||||
#define PPI_CHG0_CH11_Included PPI_CHG_CH11_Included
|
||||
|
||||
#define PPI_CHG0_CH10_Pos PPI_CHG_CH10_Pos
|
||||
#define PPI_CHG0_CH10_Msk PPI_CHG_CH10_Msk
|
||||
#define PPI_CHG0_CH10_Excluded PPI_CHG_CH10_Excluded
|
||||
#define PPI_CHG0_CH10_Included PPI_CHG_CH10_Included
|
||||
|
||||
#define PPI_CHG0_CH9_Pos PPI_CHG_CH9_Pos
|
||||
#define PPI_CHG0_CH9_Msk PPI_CHG_CH9_Msk
|
||||
#define PPI_CHG0_CH9_Excluded PPI_CHG_CH9_Excluded
|
||||
#define PPI_CHG0_CH9_Included PPI_CHG_CH9_Included
|
||||
|
||||
#define PPI_CHG0_CH8_Pos PPI_CHG_CH8_Pos
|
||||
#define PPI_CHG0_CH8_Msk PPI_CHG_CH8_Msk
|
||||
#define PPI_CHG0_CH8_Excluded PPI_CHG_CH8_Excluded
|
||||
#define PPI_CHG0_CH8_Included PPI_CHG_CH8_Included
|
||||
|
||||
#define PPI_CHG0_CH7_Pos PPI_CHG_CH7_Pos
|
||||
#define PPI_CHG0_CH7_Msk PPI_CHG_CH7_Msk
|
||||
#define PPI_CHG0_CH7_Excluded PPI_CHG_CH7_Excluded
|
||||
#define PPI_CHG0_CH7_Included PPI_CHG_CH7_Included
|
||||
|
||||
#define PPI_CHG0_CH6_Pos PPI_CHG_CH6_Pos
|
||||
#define PPI_CHG0_CH6_Msk PPI_CHG_CH6_Msk
|
||||
#define PPI_CHG0_CH6_Excluded PPI_CHG_CH6_Excluded
|
||||
#define PPI_CHG0_CH6_Included PPI_CHG_CH6_Included
|
||||
|
||||
#define PPI_CHG0_CH5_Pos PPI_CHG_CH5_Pos
|
||||
#define PPI_CHG0_CH5_Msk PPI_CHG_CH5_Msk
|
||||
#define PPI_CHG0_CH5_Excluded PPI_CHG_CH5_Excluded
|
||||
#define PPI_CHG0_CH5_Included PPI_CHG_CH5_Included
|
||||
|
||||
#define PPI_CHG0_CH4_Pos PPI_CHG_CH4_Pos
|
||||
#define PPI_CHG0_CH4_Msk PPI_CHG_CH4_Msk
|
||||
#define PPI_CHG0_CH4_Excluded PPI_CHG_CH4_Excluded
|
||||
#define PPI_CHG0_CH4_Included PPI_CHG_CH4_Included
|
||||
|
||||
#define PPI_CHG0_CH3_Pos PPI_CHG_CH3_Pos
|
||||
#define PPI_CHG0_CH3_Msk PPI_CHG_CH3_Msk
|
||||
#define PPI_CHG0_CH3_Excluded PPI_CHG_CH3_Excluded
|
||||
#define PPI_CHG0_CH3_Included PPI_CHG_CH3_Included
|
||||
|
||||
#define PPI_CHG0_CH2_Pos PPI_CHG_CH2_Pos
|
||||
#define PPI_CHG0_CH2_Msk PPI_CHG_CH2_Msk
|
||||
#define PPI_CHG0_CH2_Excluded PPI_CHG_CH2_Excluded
|
||||
#define PPI_CHG0_CH2_Included PPI_CHG_CH2_Included
|
||||
|
||||
#define PPI_CHG0_CH1_Pos PPI_CHG_CH1_Pos
|
||||
#define PPI_CHG0_CH1_Msk PPI_CHG_CH1_Msk
|
||||
#define PPI_CHG0_CH1_Excluded PPI_CHG_CH1_Excluded
|
||||
#define PPI_CHG0_CH1_Included PPI_CHG_CH1_Included
|
||||
|
||||
#define PPI_CHG0_CH0_Pos PPI_CHG_CH0_Pos
|
||||
#define PPI_CHG0_CH0_Msk PPI_CHG_CH0_Msk
|
||||
#define PPI_CHG0_CH0_Excluded PPI_CHG_CH0_Excluded
|
||||
#define PPI_CHG0_CH0_Included PPI_CHG_CH0_Included
|
||||
|
||||
#define PPI_CHG1_CH15_Pos PPI_CHG_CH15_Pos
|
||||
#define PPI_CHG1_CH15_Msk PPI_CHG_CH15_Msk
|
||||
#define PPI_CHG1_CH15_Excluded PPI_CHG_CH15_Excluded
|
||||
#define PPI_CHG1_CH15_Included PPI_CHG_CH15_Included
|
||||
|
||||
#define PPI_CHG1_CH14_Pos PPI_CHG_CH14_Pos
|
||||
#define PPI_CHG1_CH14_Msk PPI_CHG_CH14_Msk
|
||||
#define PPI_CHG1_CH14_Excluded PPI_CHG_CH14_Excluded
|
||||
#define PPI_CHG1_CH14_Included PPI_CHG_CH14_Included
|
||||
|
||||
#define PPI_CHG1_CH13_Pos PPI_CHG_CH13_Pos
|
||||
#define PPI_CHG1_CH13_Msk PPI_CHG_CH13_Msk
|
||||
#define PPI_CHG1_CH13_Excluded PPI_CHG_CH13_Excluded
|
||||
#define PPI_CHG1_CH13_Included PPI_CHG_CH13_Included
|
||||
|
||||
#define PPI_CHG1_CH12_Pos PPI_CHG_CH12_Pos
|
||||
#define PPI_CHG1_CH12_Msk PPI_CHG_CH12_Msk
|
||||
#define PPI_CHG1_CH12_Excluded PPI_CHG_CH12_Excluded
|
||||
#define PPI_CHG1_CH12_Included PPI_CHG_CH12_Included
|
||||
|
||||
#define PPI_CHG1_CH11_Pos PPI_CHG_CH11_Pos
|
||||
#define PPI_CHG1_CH11_Msk PPI_CHG_CH11_Msk
|
||||
#define PPI_CHG1_CH11_Excluded PPI_CHG_CH11_Excluded
|
||||
#define PPI_CHG1_CH11_Included PPI_CHG_CH11_Included
|
||||
|
||||
#define PPI_CHG1_CH10_Pos PPI_CHG_CH10_Pos
|
||||
#define PPI_CHG1_CH10_Msk PPI_CHG_CH10_Msk
|
||||
#define PPI_CHG1_CH10_Excluded PPI_CHG_CH10_Excluded
|
||||
#define PPI_CHG1_CH10_Included PPI_CHG_CH10_Included
|
||||
|
||||
#define PPI_CHG1_CH9_Pos PPI_CHG_CH9_Pos
|
||||
#define PPI_CHG1_CH9_Msk PPI_CHG_CH9_Msk
|
||||
#define PPI_CHG1_CH9_Excluded PPI_CHG_CH9_Excluded
|
||||
#define PPI_CHG1_CH9_Included PPI_CHG_CH9_Included
|
||||
|
||||
#define PPI_CHG1_CH8_Pos PPI_CHG_CH8_Pos
|
||||
#define PPI_CHG1_CH8_Msk PPI_CHG_CH8_Msk
|
||||
#define PPI_CHG1_CH8_Excluded PPI_CHG_CH8_Excluded
|
||||
#define PPI_CHG1_CH8_Included PPI_CHG_CH8_Included
|
||||
|
||||
#define PPI_CHG1_CH7_Pos PPI_CHG_CH7_Pos
|
||||
#define PPI_CHG1_CH7_Msk PPI_CHG_CH7_Msk
|
||||
#define PPI_CHG1_CH7_Excluded PPI_CHG_CH7_Excluded
|
||||
#define PPI_CHG1_CH7_Included PPI_CHG_CH7_Included
|
||||
|
||||
#define PPI_CHG1_CH6_Pos PPI_CHG_CH6_Pos
|
||||
#define PPI_CHG1_CH6_Msk PPI_CHG_CH6_Msk
|
||||
#define PPI_CHG1_CH6_Excluded PPI_CHG_CH6_Excluded
|
||||
#define PPI_CHG1_CH6_Included PPI_CHG_CH6_Included
|
||||
|
||||
#define PPI_CHG1_CH5_Pos PPI_CHG_CH5_Pos
|
||||
#define PPI_CHG1_CH5_Msk PPI_CHG_CH5_Msk
|
||||
#define PPI_CHG1_CH5_Excluded PPI_CHG_CH5_Excluded
|
||||
#define PPI_CHG1_CH5_Included PPI_CHG_CH5_Included
|
||||
|
||||
#define PPI_CHG1_CH4_Pos PPI_CHG_CH4_Pos
|
||||
#define PPI_CHG1_CH4_Msk PPI_CHG_CH4_Msk
|
||||
#define PPI_CHG1_CH4_Excluded PPI_CHG_CH4_Excluded
|
||||
#define PPI_CHG1_CH4_Included PPI_CHG_CH4_Included
|
||||
|
||||
#define PPI_CHG1_CH3_Pos PPI_CHG_CH3_Pos
|
||||
#define PPI_CHG1_CH3_Msk PPI_CHG_CH3_Msk
|
||||
#define PPI_CHG1_CH3_Excluded PPI_CHG_CH3_Excluded
|
||||
#define PPI_CHG1_CH3_Included PPI_CHG_CH3_Included
|
||||
|
||||
#define PPI_CHG1_CH2_Pos PPI_CHG_CH2_Pos
|
||||
#define PPI_CHG1_CH2_Msk PPI_CHG_CH2_Msk
|
||||
#define PPI_CHG1_CH2_Excluded PPI_CHG_CH2_Excluded
|
||||
#define PPI_CHG1_CH2_Included PPI_CHG_CH2_Included
|
||||
|
||||
#define PPI_CHG1_CH1_Pos PPI_CHG_CH1_Pos
|
||||
#define PPI_CHG1_CH1_Msk PPI_CHG_CH1_Msk
|
||||
#define PPI_CHG1_CH1_Excluded PPI_CHG_CH1_Excluded
|
||||
#define PPI_CHG1_CH1_Included PPI_CHG_CH1_Included
|
||||
|
||||
#define PPI_CHG1_CH0_Pos PPI_CHG_CH0_Pos
|
||||
#define PPI_CHG1_CH0_Msk PPI_CHG_CH0_Msk
|
||||
#define PPI_CHG1_CH0_Excluded PPI_CHG_CH0_Excluded
|
||||
#define PPI_CHG1_CH0_Included PPI_CHG_CH0_Included
|
||||
|
||||
#define PPI_CHG2_CH15_Pos PPI_CHG_CH15_Pos
|
||||
#define PPI_CHG2_CH15_Msk PPI_CHG_CH15_Msk
|
||||
#define PPI_CHG2_CH15_Excluded PPI_CHG_CH15_Excluded
|
||||
#define PPI_CHG2_CH15_Included PPI_CHG_CH15_Included
|
||||
|
||||
#define PPI_CHG2_CH14_Pos PPI_CHG_CH14_Pos
|
||||
#define PPI_CHG2_CH14_Msk PPI_CHG_CH14_Msk
|
||||
#define PPI_CHG2_CH14_Excluded PPI_CHG_CH14_Excluded
|
||||
#define PPI_CHG2_CH14_Included PPI_CHG_CH14_Included
|
||||
|
||||
#define PPI_CHG2_CH13_Pos PPI_CHG_CH13_Pos
|
||||
#define PPI_CHG2_CH13_Msk PPI_CHG_CH13_Msk
|
||||
#define PPI_CHG2_CH13_Excluded PPI_CHG_CH13_Excluded
|
||||
#define PPI_CHG2_CH13_Included PPI_CHG_CH13_Included
|
||||
|
||||
#define PPI_CHG2_CH12_Pos PPI_CHG_CH12_Pos
|
||||
#define PPI_CHG2_CH12_Msk PPI_CHG_CH12_Msk
|
||||
#define PPI_CHG2_CH12_Excluded PPI_CHG_CH12_Excluded
|
||||
#define PPI_CHG2_CH12_Included PPI_CHG_CH12_Included
|
||||
|
||||
#define PPI_CHG2_CH11_Pos PPI_CHG_CH11_Pos
|
||||
#define PPI_CHG2_CH11_Msk PPI_CHG_CH11_Msk
|
||||
#define PPI_CHG2_CH11_Excluded PPI_CHG_CH11_Excluded
|
||||
#define PPI_CHG2_CH11_Included PPI_CHG_CH11_Included
|
||||
|
||||
#define PPI_CHG2_CH10_Pos PPI_CHG_CH10_Pos
|
||||
#define PPI_CHG2_CH10_Msk PPI_CHG_CH10_Msk
|
||||
#define PPI_CHG2_CH10_Excluded PPI_CHG_CH10_Excluded
|
||||
#define PPI_CHG2_CH10_Included PPI_CHG_CH10_Included
|
||||
|
||||
#define PPI_CHG2_CH9_Pos PPI_CHG_CH9_Pos
|
||||
#define PPI_CHG2_CH9_Msk PPI_CHG_CH9_Msk
|
||||
#define PPI_CHG2_CH9_Excluded PPI_CHG_CH9_Excluded
|
||||
#define PPI_CHG2_CH9_Included PPI_CHG_CH9_Included
|
||||
|
||||
#define PPI_CHG2_CH8_Pos PPI_CHG_CH8_Pos
|
||||
#define PPI_CHG2_CH8_Msk PPI_CHG_CH8_Msk
|
||||
#define PPI_CHG2_CH8_Excluded PPI_CHG_CH8_Excluded
|
||||
#define PPI_CHG2_CH8_Included PPI_CHG_CH8_Included
|
||||
|
||||
#define PPI_CHG2_CH7_Pos PPI_CHG_CH7_Pos
|
||||
#define PPI_CHG2_CH7_Msk PPI_CHG_CH7_Msk
|
||||
#define PPI_CHG2_CH7_Excluded PPI_CHG_CH7_Excluded
|
||||
#define PPI_CHG2_CH7_Included PPI_CHG_CH7_Included
|
||||
|
||||
#define PPI_CHG2_CH6_Pos PPI_CHG_CH6_Pos
|
||||
#define PPI_CHG2_CH6_Msk PPI_CHG_CH6_Msk
|
||||
#define PPI_CHG2_CH6_Excluded PPI_CHG_CH6_Excluded
|
||||
#define PPI_CHG2_CH6_Included PPI_CHG_CH6_Included
|
||||
|
||||
#define PPI_CHG2_CH5_Pos PPI_CHG_CH5_Pos
|
||||
#define PPI_CHG2_CH5_Msk PPI_CHG_CH5_Msk
|
||||
#define PPI_CHG2_CH5_Excluded PPI_CHG_CH5_Excluded
|
||||
#define PPI_CHG2_CH5_Included PPI_CHG_CH5_Included
|
||||
|
||||
#define PPI_CHG2_CH4_Pos PPI_CHG_CH4_Pos
|
||||
#define PPI_CHG2_CH4_Msk PPI_CHG_CH4_Msk
|
||||
#define PPI_CHG2_CH4_Excluded PPI_CHG_CH4_Excluded
|
||||
#define PPI_CHG2_CH4_Included PPI_CHG_CH4_Included
|
||||
|
||||
#define PPI_CHG2_CH3_Pos PPI_CHG_CH3_Pos
|
||||
#define PPI_CHG2_CH3_Msk PPI_CHG_CH3_Msk
|
||||
#define PPI_CHG2_CH3_Excluded PPI_CHG_CH3_Excluded
|
||||
#define PPI_CHG2_CH3_Included PPI_CHG_CH3_Included
|
||||
|
||||
#define PPI_CHG2_CH2_Pos PPI_CHG_CH2_Pos
|
||||
#define PPI_CHG2_CH2_Msk PPI_CHG_CH2_Msk
|
||||
#define PPI_CHG2_CH2_Excluded PPI_CHG_CH2_Excluded
|
||||
#define PPI_CHG2_CH2_Included PPI_CHG_CH2_Included
|
||||
|
||||
#define PPI_CHG2_CH1_Pos PPI_CHG_CH1_Pos
|
||||
#define PPI_CHG2_CH1_Msk PPI_CHG_CH1_Msk
|
||||
#define PPI_CHG2_CH1_Excluded PPI_CHG_CH1_Excluded
|
||||
#define PPI_CHG2_CH1_Included PPI_CHG_CH1_Included
|
||||
|
||||
#define PPI_CHG2_CH0_Pos PPI_CHG_CH0_Pos
|
||||
#define PPI_CHG2_CH0_Msk PPI_CHG_CH0_Msk
|
||||
#define PPI_CHG2_CH0_Excluded PPI_CHG_CH0_Excluded
|
||||
#define PPI_CHG2_CH0_Included PPI_CHG_CH0_Included
|
||||
|
||||
#define PPI_CHG3_CH15_Pos PPI_CHG_CH15_Pos
|
||||
#define PPI_CHG3_CH15_Msk PPI_CHG_CH15_Msk
|
||||
#define PPI_CHG3_CH15_Excluded PPI_CHG_CH15_Excluded
|
||||
#define PPI_CHG3_CH15_Included PPI_CHG_CH15_Included
|
||||
|
||||
#define PPI_CHG3_CH14_Pos PPI_CHG_CH14_Pos
|
||||
#define PPI_CHG3_CH14_Msk PPI_CHG_CH14_Msk
|
||||
#define PPI_CHG3_CH14_Excluded PPI_CHG_CH14_Excluded
|
||||
#define PPI_CHG3_CH14_Included PPI_CHG_CH14_Included
|
||||
|
||||
#define PPI_CHG3_CH13_Pos PPI_CHG_CH13_Pos
|
||||
#define PPI_CHG3_CH13_Msk PPI_CHG_CH13_Msk
|
||||
#define PPI_CHG3_CH13_Excluded PPI_CHG_CH13_Excluded
|
||||
#define PPI_CHG3_CH13_Included PPI_CHG_CH13_Included
|
||||
|
||||
#define PPI_CHG3_CH12_Pos PPI_CHG_CH12_Pos
|
||||
#define PPI_CHG3_CH12_Msk PPI_CHG_CH12_Msk
|
||||
#define PPI_CHG3_CH12_Excluded PPI_CHG_CH12_Excluded
|
||||
#define PPI_CHG3_CH12_Included PPI_CHG_CH12_Included
|
||||
|
||||
#define PPI_CHG3_CH11_Pos PPI_CHG_CH11_Pos
|
||||
#define PPI_CHG3_CH11_Msk PPI_CHG_CH11_Msk
|
||||
#define PPI_CHG3_CH11_Excluded PPI_CHG_CH11_Excluded
|
||||
#define PPI_CHG3_CH11_Included PPI_CHG_CH11_Included
|
||||
|
||||
#define PPI_CHG3_CH10_Pos PPI_CHG_CH10_Pos
|
||||
#define PPI_CHG3_CH10_Msk PPI_CHG_CH10_Msk
|
||||
#define PPI_CHG3_CH10_Excluded PPI_CHG_CH10_Excluded
|
||||
#define PPI_CHG3_CH10_Included PPI_CHG_CH10_Included
|
||||
|
||||
#define PPI_CHG3_CH9_Pos PPI_CHG_CH9_Pos
|
||||
#define PPI_CHG3_CH9_Msk PPI_CHG_CH9_Msk
|
||||
#define PPI_CHG3_CH9_Excluded PPI_CHG_CH9_Excluded
|
||||
#define PPI_CHG3_CH9_Included PPI_CHG_CH9_Included
|
||||
|
||||
#define PPI_CHG3_CH8_Pos PPI_CHG_CH8_Pos
|
||||
#define PPI_CHG3_CH8_Msk PPI_CHG_CH8_Msk
|
||||
#define PPI_CHG3_CH8_Excluded PPI_CHG_CH8_Excluded
|
||||
#define PPI_CHG3_CH8_Included PPI_CHG_CH8_Included
|
||||
|
||||
#define PPI_CHG3_CH7_Pos PPI_CHG_CH7_Pos
|
||||
#define PPI_CHG3_CH7_Msk PPI_CHG_CH7_Msk
|
||||
#define PPI_CHG3_CH7_Excluded PPI_CHG_CH7_Excluded
|
||||
#define PPI_CHG3_CH7_Included PPI_CHG_CH7_Included
|
||||
|
||||
#define PPI_CHG3_CH6_Pos PPI_CHG_CH6_Pos
|
||||
#define PPI_CHG3_CH6_Msk PPI_CHG_CH6_Msk
|
||||
#define PPI_CHG3_CH6_Excluded PPI_CHG_CH6_Excluded
|
||||
#define PPI_CHG3_CH6_Included PPI_CHG_CH6_Included
|
||||
|
||||
#define PPI_CHG3_CH5_Pos PPI_CHG_CH5_Pos
|
||||
#define PPI_CHG3_CH5_Msk PPI_CHG_CH5_Msk
|
||||
#define PPI_CHG3_CH5_Excluded PPI_CHG_CH5_Excluded
|
||||
#define PPI_CHG3_CH5_Included PPI_CHG_CH5_Included
|
||||
|
||||
#define PPI_CHG3_CH4_Pos PPI_CHG_CH4_Pos
|
||||
#define PPI_CHG3_CH4_Msk PPI_CHG_CH4_Msk
|
||||
#define PPI_CHG3_CH4_Excluded PPI_CHG_CH4_Excluded
|
||||
#define PPI_CHG3_CH4_Included PPI_CHG_CH4_Included
|
||||
|
||||
#define PPI_CHG3_CH3_Pos PPI_CHG_CH3_Pos
|
||||
#define PPI_CHG3_CH3_Msk PPI_CHG_CH3_Msk
|
||||
#define PPI_CHG3_CH3_Excluded PPI_CHG_CH3_Excluded
|
||||
#define PPI_CHG3_CH3_Included PPI_CHG_CH3_Included
|
||||
|
||||
#define PPI_CHG3_CH2_Pos PPI_CHG_CH2_Pos
|
||||
#define PPI_CHG3_CH2_Msk PPI_CHG_CH2_Msk
|
||||
#define PPI_CHG3_CH2_Excluded PPI_CHG_CH2_Excluded
|
||||
#define PPI_CHG3_CH2_Included PPI_CHG_CH2_Included
|
||||
|
||||
#define PPI_CHG3_CH1_Pos PPI_CHG_CH1_Pos
|
||||
#define PPI_CHG3_CH1_Msk PPI_CHG_CH1_Msk
|
||||
#define PPI_CHG3_CH1_Excluded PPI_CHG_CH1_Excluded
|
||||
#define PPI_CHG3_CH1_Included PPI_CHG_CH1_Included
|
||||
|
||||
#define PPI_CHG3_CH0_Pos PPI_CHG_CH0_Pos
|
||||
#define PPI_CHG3_CH0_Msk PPI_CHG_CH0_Msk
|
||||
#define PPI_CHG3_CH0_Excluded PPI_CHG_CH0_Excluded
|
||||
#define PPI_CHG3_CH0_Included PPI_CHG_CH0_Included
|
||||
|
||||
|
||||
|
||||
|
||||
/*lint --flb "Leave library region" */
|
||||
|
||||
#endif /* NRF51_TO_NRF52_H */
|
||||
|
||||
@@ -0,0 +1,523 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2010 - 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 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.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, 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 NRF51_TO_NRF52810_H
|
||||
#define NRF51_TO_NRF52810_H
|
||||
|
||||
/*lint ++flb "Enter library region */
|
||||
|
||||
/* This file is given to prevent your SW from not compiling with the name changes between nRF51 and nRF52840 devices.
|
||||
* It redefines the old nRF51 names into the new ones as long as the functionality is still supported. If the
|
||||
* functionality is gone, there old names are not defined, so compilation will fail. Note that also includes macros
|
||||
* from the nrf51_deprecated.h file. */
|
||||
|
||||
|
||||
/* Differences between latest nRF51 headers and nRF52810 headers. */
|
||||
|
||||
/* IRQ */
|
||||
/* Several peripherals have been added to several indexes. Names of IRQ handlers and IRQ numbers have changed. */
|
||||
#define SWI0_IRQHandler SWI0_EGU0_IRQHandler
|
||||
#define SWI1_IRQHandler SWI1_EGU1_IRQHandler
|
||||
|
||||
#define SWI0_IRQn SWI0_EGU0_IRQn
|
||||
#define SWI1_IRQn SWI1_EGU1_IRQn
|
||||
|
||||
|
||||
/* UICR */
|
||||
/* Register RBPCONF was renamed to APPROTECT. */
|
||||
#define RBPCONF APPROTECT
|
||||
|
||||
#define UICR_RBPCONF_PALL_Pos UICR_APPROTECT_PALL_Pos
|
||||
#define UICR_RBPCONF_PALL_Msk UICR_APPROTECT_PALL_Msk
|
||||
#define UICR_RBPCONF_PALL_Enabled UICR_APPROTECT_PALL_Enabled
|
||||
#define UICR_RBPCONF_PALL_Disabled UICR_APPROTECT_PALL_Disabled
|
||||
|
||||
|
||||
/* GPIO */
|
||||
/* GPIO port was renamed to P0. */
|
||||
#define NRF_GPIO NRF_P0
|
||||
#define NRF_GPIO_BASE NRF_P0_BASE
|
||||
|
||||
|
||||
/* QDEC */
|
||||
/* The registers PSELA, PSELB and PSELLED were restructured into a struct. */
|
||||
#define PSELLED PSEL.LED
|
||||
#define PSELA PSEL.A
|
||||
#define PSELB PSEL.B
|
||||
|
||||
|
||||
/* SPIS */
|
||||
/* The registers PSELSCK, PSELMISO, PSELMOSI, PSELCSN were restructured into a struct. */
|
||||
#define PSELSCK PSEL.SCK
|
||||
#define PSELMISO PSEL.MISO
|
||||
#define PSELMOSI PSEL.MOSI
|
||||
#define PSELCSN PSEL.CSN
|
||||
|
||||
/* The registers RXDPTR, MAXRX, AMOUNTRX were restructured into a struct */
|
||||
#define RXDPTR RXD.PTR
|
||||
#define MAXRX RXD.MAXCNT
|
||||
#define AMOUNTRX RXD.AMOUNT
|
||||
|
||||
#define SPIS_MAXRX_MAXRX_Pos SPIS_RXD_MAXCNT_MAXCNT_Pos
|
||||
#define SPIS_MAXRX_MAXRX_Msk SPIS_RXD_MAXCNT_MAXCNT_Msk
|
||||
|
||||
#define SPIS_AMOUNTRX_AMOUNTRX_Pos SPIS_RXD_AMOUNT_AMOUNT_Pos
|
||||
#define SPIS_AMOUNTRX_AMOUNTRX_Msk SPIS_RXD_AMOUNT_AMOUNT_Msk
|
||||
|
||||
/* The registers TXDPTR, MAXTX, AMOUNTTX were restructured into a struct */
|
||||
#define TXDPTR TXD.PTR
|
||||
#define MAXTX TXD.MAXCNT
|
||||
#define AMOUNTTX TXD.AMOUNT
|
||||
|
||||
#define SPIS_MAXTX_MAXTX_Pos SPIS_TXD_MAXCNT_MAXCNT_Pos
|
||||
#define SPIS_MAXTX_MAXTX_Msk SPIS_TXD_MAXCNT_MAXCNT_Msk
|
||||
|
||||
#define SPIS_AMOUNTTX_AMOUNTTX_Pos SPIS_TXD_AMOUNT_AMOUNT_Pos
|
||||
#define SPIS_AMOUNTTX_AMOUNTTX_Msk SPIS_TXD_AMOUNT_AMOUNT_Msk
|
||||
|
||||
|
||||
/* From nrf51_deprecated.h. Several macros changed in different versions of nRF52 headers. By defining the following, any code written for any version of nRF52 headers will still compile. */
|
||||
|
||||
/* NVMC */
|
||||
/* The register ERASEPROTECTEDPAGE changed name to ERASEPCR0 in the documentation. */
|
||||
#define ERASEPROTECTEDPAGE ERASEPCR0
|
||||
|
||||
|
||||
/* RADIO */
|
||||
/* The name of the field SKIPADDR was corrected. Old macros added for compatibility. */
|
||||
#define RADIO_CRCCNF_SKIP_ADDR_Pos RADIO_CRCCNF_SKIPADDR_Pos
|
||||
#define RADIO_CRCCNF_SKIP_ADDR_Msk RADIO_CRCCNF_SKIPADDR_Msk
|
||||
#define RADIO_CRCCNF_SKIP_ADDR_Include RADIO_CRCCNF_SKIPADDR_Include
|
||||
#define RADIO_CRCCNF_SKIP_ADDR_Skip RADIO_CRCCNF_SKIPADDR_Skip
|
||||
|
||||
|
||||
/* FICR */
|
||||
/* The registers FICR.DEVICEID0 and FICR.DEVICEID1 were renamed into an array. */
|
||||
#define DEVICEID0 DEVICEID[0]
|
||||
#define DEVICEID1 DEVICEID[1]
|
||||
|
||||
/* The registers FICR.ER0, FICR.ER1, FICR.ER2 and FICR.ER3 were renamed into an array. */
|
||||
#define ER0 ER[0]
|
||||
#define ER1 ER[1]
|
||||
#define ER2 ER[2]
|
||||
#define ER3 ER[3]
|
||||
|
||||
/* The registers FICR.IR0, FICR.IR1, FICR.IR2 and FICR.IR3 were renamed into an array. */
|
||||
#define IR0 IR[0]
|
||||
#define IR1 IR[1]
|
||||
#define IR2 IR[2]
|
||||
#define IR3 IR[3]
|
||||
|
||||
/* The registers FICR.DEVICEADDR0 and FICR.DEVICEADDR1 were renamed into an array. */
|
||||
#define DEVICEADDR0 DEVICEADDR[0]
|
||||
#define DEVICEADDR1 DEVICEADDR[1]
|
||||
|
||||
|
||||
/* PPI */
|
||||
/* The tasks PPI.TASKS_CHGxEN and PPI.TASKS_CHGxDIS were renamed into an array of structs. */
|
||||
#define TASKS_CHG0EN TASKS_CHG[0].EN
|
||||
#define TASKS_CHG0DIS TASKS_CHG[0].DIS
|
||||
#define TASKS_CHG1EN TASKS_CHG[1].EN
|
||||
#define TASKS_CHG1DIS TASKS_CHG[1].DIS
|
||||
#define TASKS_CHG2EN TASKS_CHG[2].EN
|
||||
#define TASKS_CHG2DIS TASKS_CHG[2].DIS
|
||||
#define TASKS_CHG3EN TASKS_CHG[3].EN
|
||||
#define TASKS_CHG3DIS TASKS_CHG[3].DIS
|
||||
|
||||
/* The registers PPI.CHx_EEP and PPI.CHx_TEP were renamed into an array of structs. */
|
||||
#define CH0_EEP CH[0].EEP
|
||||
#define CH0_TEP CH[0].TEP
|
||||
#define CH1_EEP CH[1].EEP
|
||||
#define CH1_TEP CH[1].TEP
|
||||
#define CH2_EEP CH[2].EEP
|
||||
#define CH2_TEP CH[2].TEP
|
||||
#define CH3_EEP CH[3].EEP
|
||||
#define CH3_TEP CH[3].TEP
|
||||
#define CH4_EEP CH[4].EEP
|
||||
#define CH4_TEP CH[4].TEP
|
||||
#define CH5_EEP CH[5].EEP
|
||||
#define CH5_TEP CH[5].TEP
|
||||
#define CH6_EEP CH[6].EEP
|
||||
#define CH6_TEP CH[6].TEP
|
||||
#define CH7_EEP CH[7].EEP
|
||||
#define CH7_TEP CH[7].TEP
|
||||
#define CH8_EEP CH[8].EEP
|
||||
#define CH8_TEP CH[8].TEP
|
||||
#define CH9_EEP CH[9].EEP
|
||||
#define CH9_TEP CH[9].TEP
|
||||
#define CH10_EEP CH[10].EEP
|
||||
#define CH10_TEP CH[10].TEP
|
||||
#define CH11_EEP CH[11].EEP
|
||||
#define CH11_TEP CH[11].TEP
|
||||
#define CH12_EEP CH[12].EEP
|
||||
#define CH12_TEP CH[12].TEP
|
||||
#define CH13_EEP CH[13].EEP
|
||||
#define CH13_TEP CH[13].TEP
|
||||
#define CH14_EEP CH[14].EEP
|
||||
#define CH14_TEP CH[14].TEP
|
||||
#define CH15_EEP CH[15].EEP
|
||||
#define CH15_TEP CH[15].TEP
|
||||
|
||||
/* The registers PPI.CHG0, PPI.CHG1, PPI.CHG2 and PPI.CHG3 were renamed into an array. */
|
||||
#define CHG0 CHG[0]
|
||||
#define CHG1 CHG[1]
|
||||
#define CHG2 CHG[2]
|
||||
#define CHG3 CHG[3]
|
||||
|
||||
/* All bitfield macros for the CHGx registers therefore changed name. */
|
||||
#define PPI_CHG0_CH15_Pos PPI_CHG_CH15_Pos
|
||||
#define PPI_CHG0_CH15_Msk PPI_CHG_CH15_Msk
|
||||
#define PPI_CHG0_CH15_Excluded PPI_CHG_CH15_Excluded
|
||||
#define PPI_CHG0_CH15_Included PPI_CHG_CH15_Included
|
||||
|
||||
#define PPI_CHG0_CH14_Pos PPI_CHG_CH14_Pos
|
||||
#define PPI_CHG0_CH14_Msk PPI_CHG_CH14_Msk
|
||||
#define PPI_CHG0_CH14_Excluded PPI_CHG_CH14_Excluded
|
||||
#define PPI_CHG0_CH14_Included PPI_CHG_CH14_Included
|
||||
|
||||
#define PPI_CHG0_CH13_Pos PPI_CHG_CH13_Pos
|
||||
#define PPI_CHG0_CH13_Msk PPI_CHG_CH13_Msk
|
||||
#define PPI_CHG0_CH13_Excluded PPI_CHG_CH13_Excluded
|
||||
#define PPI_CHG0_CH13_Included PPI_CHG_CH13_Included
|
||||
|
||||
#define PPI_CHG0_CH12_Pos PPI_CHG_CH12_Pos
|
||||
#define PPI_CHG0_CH12_Msk PPI_CHG_CH12_Msk
|
||||
#define PPI_CHG0_CH12_Excluded PPI_CHG_CH12_Excluded
|
||||
#define PPI_CHG0_CH12_Included PPI_CHG_CH12_Included
|
||||
|
||||
#define PPI_CHG0_CH11_Pos PPI_CHG_CH11_Pos
|
||||
#define PPI_CHG0_CH11_Msk PPI_CHG_CH11_Msk
|
||||
#define PPI_CHG0_CH11_Excluded PPI_CHG_CH11_Excluded
|
||||
#define PPI_CHG0_CH11_Included PPI_CHG_CH11_Included
|
||||
|
||||
#define PPI_CHG0_CH10_Pos PPI_CHG_CH10_Pos
|
||||
#define PPI_CHG0_CH10_Msk PPI_CHG_CH10_Msk
|
||||
#define PPI_CHG0_CH10_Excluded PPI_CHG_CH10_Excluded
|
||||
#define PPI_CHG0_CH10_Included PPI_CHG_CH10_Included
|
||||
|
||||
#define PPI_CHG0_CH9_Pos PPI_CHG_CH9_Pos
|
||||
#define PPI_CHG0_CH9_Msk PPI_CHG_CH9_Msk
|
||||
#define PPI_CHG0_CH9_Excluded PPI_CHG_CH9_Excluded
|
||||
#define PPI_CHG0_CH9_Included PPI_CHG_CH9_Included
|
||||
|
||||
#define PPI_CHG0_CH8_Pos PPI_CHG_CH8_Pos
|
||||
#define PPI_CHG0_CH8_Msk PPI_CHG_CH8_Msk
|
||||
#define PPI_CHG0_CH8_Excluded PPI_CHG_CH8_Excluded
|
||||
#define PPI_CHG0_CH8_Included PPI_CHG_CH8_Included
|
||||
|
||||
#define PPI_CHG0_CH7_Pos PPI_CHG_CH7_Pos
|
||||
#define PPI_CHG0_CH7_Msk PPI_CHG_CH7_Msk
|
||||
#define PPI_CHG0_CH7_Excluded PPI_CHG_CH7_Excluded
|
||||
#define PPI_CHG0_CH7_Included PPI_CHG_CH7_Included
|
||||
|
||||
#define PPI_CHG0_CH6_Pos PPI_CHG_CH6_Pos
|
||||
#define PPI_CHG0_CH6_Msk PPI_CHG_CH6_Msk
|
||||
#define PPI_CHG0_CH6_Excluded PPI_CHG_CH6_Excluded
|
||||
#define PPI_CHG0_CH6_Included PPI_CHG_CH6_Included
|
||||
|
||||
#define PPI_CHG0_CH5_Pos PPI_CHG_CH5_Pos
|
||||
#define PPI_CHG0_CH5_Msk PPI_CHG_CH5_Msk
|
||||
#define PPI_CHG0_CH5_Excluded PPI_CHG_CH5_Excluded
|
||||
#define PPI_CHG0_CH5_Included PPI_CHG_CH5_Included
|
||||
|
||||
#define PPI_CHG0_CH4_Pos PPI_CHG_CH4_Pos
|
||||
#define PPI_CHG0_CH4_Msk PPI_CHG_CH4_Msk
|
||||
#define PPI_CHG0_CH4_Excluded PPI_CHG_CH4_Excluded
|
||||
#define PPI_CHG0_CH4_Included PPI_CHG_CH4_Included
|
||||
|
||||
#define PPI_CHG0_CH3_Pos PPI_CHG_CH3_Pos
|
||||
#define PPI_CHG0_CH3_Msk PPI_CHG_CH3_Msk
|
||||
#define PPI_CHG0_CH3_Excluded PPI_CHG_CH3_Excluded
|
||||
#define PPI_CHG0_CH3_Included PPI_CHG_CH3_Included
|
||||
|
||||
#define PPI_CHG0_CH2_Pos PPI_CHG_CH2_Pos
|
||||
#define PPI_CHG0_CH2_Msk PPI_CHG_CH2_Msk
|
||||
#define PPI_CHG0_CH2_Excluded PPI_CHG_CH2_Excluded
|
||||
#define PPI_CHG0_CH2_Included PPI_CHG_CH2_Included
|
||||
|
||||
#define PPI_CHG0_CH1_Pos PPI_CHG_CH1_Pos
|
||||
#define PPI_CHG0_CH1_Msk PPI_CHG_CH1_Msk
|
||||
#define PPI_CHG0_CH1_Excluded PPI_CHG_CH1_Excluded
|
||||
#define PPI_CHG0_CH1_Included PPI_CHG_CH1_Included
|
||||
|
||||
#define PPI_CHG0_CH0_Pos PPI_CHG_CH0_Pos
|
||||
#define PPI_CHG0_CH0_Msk PPI_CHG_CH0_Msk
|
||||
#define PPI_CHG0_CH0_Excluded PPI_CHG_CH0_Excluded
|
||||
#define PPI_CHG0_CH0_Included PPI_CHG_CH0_Included
|
||||
|
||||
#define PPI_CHG1_CH15_Pos PPI_CHG_CH15_Pos
|
||||
#define PPI_CHG1_CH15_Msk PPI_CHG_CH15_Msk
|
||||
#define PPI_CHG1_CH15_Excluded PPI_CHG_CH15_Excluded
|
||||
#define PPI_CHG1_CH15_Included PPI_CHG_CH15_Included
|
||||
|
||||
#define PPI_CHG1_CH14_Pos PPI_CHG_CH14_Pos
|
||||
#define PPI_CHG1_CH14_Msk PPI_CHG_CH14_Msk
|
||||
#define PPI_CHG1_CH14_Excluded PPI_CHG_CH14_Excluded
|
||||
#define PPI_CHG1_CH14_Included PPI_CHG_CH14_Included
|
||||
|
||||
#define PPI_CHG1_CH13_Pos PPI_CHG_CH13_Pos
|
||||
#define PPI_CHG1_CH13_Msk PPI_CHG_CH13_Msk
|
||||
#define PPI_CHG1_CH13_Excluded PPI_CHG_CH13_Excluded
|
||||
#define PPI_CHG1_CH13_Included PPI_CHG_CH13_Included
|
||||
|
||||
#define PPI_CHG1_CH12_Pos PPI_CHG_CH12_Pos
|
||||
#define PPI_CHG1_CH12_Msk PPI_CHG_CH12_Msk
|
||||
#define PPI_CHG1_CH12_Excluded PPI_CHG_CH12_Excluded
|
||||
#define PPI_CHG1_CH12_Included PPI_CHG_CH12_Included
|
||||
|
||||
#define PPI_CHG1_CH11_Pos PPI_CHG_CH11_Pos
|
||||
#define PPI_CHG1_CH11_Msk PPI_CHG_CH11_Msk
|
||||
#define PPI_CHG1_CH11_Excluded PPI_CHG_CH11_Excluded
|
||||
#define PPI_CHG1_CH11_Included PPI_CHG_CH11_Included
|
||||
|
||||
#define PPI_CHG1_CH10_Pos PPI_CHG_CH10_Pos
|
||||
#define PPI_CHG1_CH10_Msk PPI_CHG_CH10_Msk
|
||||
#define PPI_CHG1_CH10_Excluded PPI_CHG_CH10_Excluded
|
||||
#define PPI_CHG1_CH10_Included PPI_CHG_CH10_Included
|
||||
|
||||
#define PPI_CHG1_CH9_Pos PPI_CHG_CH9_Pos
|
||||
#define PPI_CHG1_CH9_Msk PPI_CHG_CH9_Msk
|
||||
#define PPI_CHG1_CH9_Excluded PPI_CHG_CH9_Excluded
|
||||
#define PPI_CHG1_CH9_Included PPI_CHG_CH9_Included
|
||||
|
||||
#define PPI_CHG1_CH8_Pos PPI_CHG_CH8_Pos
|
||||
#define PPI_CHG1_CH8_Msk PPI_CHG_CH8_Msk
|
||||
#define PPI_CHG1_CH8_Excluded PPI_CHG_CH8_Excluded
|
||||
#define PPI_CHG1_CH8_Included PPI_CHG_CH8_Included
|
||||
|
||||
#define PPI_CHG1_CH7_Pos PPI_CHG_CH7_Pos
|
||||
#define PPI_CHG1_CH7_Msk PPI_CHG_CH7_Msk
|
||||
#define PPI_CHG1_CH7_Excluded PPI_CHG_CH7_Excluded
|
||||
#define PPI_CHG1_CH7_Included PPI_CHG_CH7_Included
|
||||
|
||||
#define PPI_CHG1_CH6_Pos PPI_CHG_CH6_Pos
|
||||
#define PPI_CHG1_CH6_Msk PPI_CHG_CH6_Msk
|
||||
#define PPI_CHG1_CH6_Excluded PPI_CHG_CH6_Excluded
|
||||
#define PPI_CHG1_CH6_Included PPI_CHG_CH6_Included
|
||||
|
||||
#define PPI_CHG1_CH5_Pos PPI_CHG_CH5_Pos
|
||||
#define PPI_CHG1_CH5_Msk PPI_CHG_CH5_Msk
|
||||
#define PPI_CHG1_CH5_Excluded PPI_CHG_CH5_Excluded
|
||||
#define PPI_CHG1_CH5_Included PPI_CHG_CH5_Included
|
||||
|
||||
#define PPI_CHG1_CH4_Pos PPI_CHG_CH4_Pos
|
||||
#define PPI_CHG1_CH4_Msk PPI_CHG_CH4_Msk
|
||||
#define PPI_CHG1_CH4_Excluded PPI_CHG_CH4_Excluded
|
||||
#define PPI_CHG1_CH4_Included PPI_CHG_CH4_Included
|
||||
|
||||
#define PPI_CHG1_CH3_Pos PPI_CHG_CH3_Pos
|
||||
#define PPI_CHG1_CH3_Msk PPI_CHG_CH3_Msk
|
||||
#define PPI_CHG1_CH3_Excluded PPI_CHG_CH3_Excluded
|
||||
#define PPI_CHG1_CH3_Included PPI_CHG_CH3_Included
|
||||
|
||||
#define PPI_CHG1_CH2_Pos PPI_CHG_CH2_Pos
|
||||
#define PPI_CHG1_CH2_Msk PPI_CHG_CH2_Msk
|
||||
#define PPI_CHG1_CH2_Excluded PPI_CHG_CH2_Excluded
|
||||
#define PPI_CHG1_CH2_Included PPI_CHG_CH2_Included
|
||||
|
||||
#define PPI_CHG1_CH1_Pos PPI_CHG_CH1_Pos
|
||||
#define PPI_CHG1_CH1_Msk PPI_CHG_CH1_Msk
|
||||
#define PPI_CHG1_CH1_Excluded PPI_CHG_CH1_Excluded
|
||||
#define PPI_CHG1_CH1_Included PPI_CHG_CH1_Included
|
||||
|
||||
#define PPI_CHG1_CH0_Pos PPI_CHG_CH0_Pos
|
||||
#define PPI_CHG1_CH0_Msk PPI_CHG_CH0_Msk
|
||||
#define PPI_CHG1_CH0_Excluded PPI_CHG_CH0_Excluded
|
||||
#define PPI_CHG1_CH0_Included PPI_CHG_CH0_Included
|
||||
|
||||
#define PPI_CHG2_CH15_Pos PPI_CHG_CH15_Pos
|
||||
#define PPI_CHG2_CH15_Msk PPI_CHG_CH15_Msk
|
||||
#define PPI_CHG2_CH15_Excluded PPI_CHG_CH15_Excluded
|
||||
#define PPI_CHG2_CH15_Included PPI_CHG_CH15_Included
|
||||
|
||||
#define PPI_CHG2_CH14_Pos PPI_CHG_CH14_Pos
|
||||
#define PPI_CHG2_CH14_Msk PPI_CHG_CH14_Msk
|
||||
#define PPI_CHG2_CH14_Excluded PPI_CHG_CH14_Excluded
|
||||
#define PPI_CHG2_CH14_Included PPI_CHG_CH14_Included
|
||||
|
||||
#define PPI_CHG2_CH13_Pos PPI_CHG_CH13_Pos
|
||||
#define PPI_CHG2_CH13_Msk PPI_CHG_CH13_Msk
|
||||
#define PPI_CHG2_CH13_Excluded PPI_CHG_CH13_Excluded
|
||||
#define PPI_CHG2_CH13_Included PPI_CHG_CH13_Included
|
||||
|
||||
#define PPI_CHG2_CH12_Pos PPI_CHG_CH12_Pos
|
||||
#define PPI_CHG2_CH12_Msk PPI_CHG_CH12_Msk
|
||||
#define PPI_CHG2_CH12_Excluded PPI_CHG_CH12_Excluded
|
||||
#define PPI_CHG2_CH12_Included PPI_CHG_CH12_Included
|
||||
|
||||
#define PPI_CHG2_CH11_Pos PPI_CHG_CH11_Pos
|
||||
#define PPI_CHG2_CH11_Msk PPI_CHG_CH11_Msk
|
||||
#define PPI_CHG2_CH11_Excluded PPI_CHG_CH11_Excluded
|
||||
#define PPI_CHG2_CH11_Included PPI_CHG_CH11_Included
|
||||
|
||||
#define PPI_CHG2_CH10_Pos PPI_CHG_CH10_Pos
|
||||
#define PPI_CHG2_CH10_Msk PPI_CHG_CH10_Msk
|
||||
#define PPI_CHG2_CH10_Excluded PPI_CHG_CH10_Excluded
|
||||
#define PPI_CHG2_CH10_Included PPI_CHG_CH10_Included
|
||||
|
||||
#define PPI_CHG2_CH9_Pos PPI_CHG_CH9_Pos
|
||||
#define PPI_CHG2_CH9_Msk PPI_CHG_CH9_Msk
|
||||
#define PPI_CHG2_CH9_Excluded PPI_CHG_CH9_Excluded
|
||||
#define PPI_CHG2_CH9_Included PPI_CHG_CH9_Included
|
||||
|
||||
#define PPI_CHG2_CH8_Pos PPI_CHG_CH8_Pos
|
||||
#define PPI_CHG2_CH8_Msk PPI_CHG_CH8_Msk
|
||||
#define PPI_CHG2_CH8_Excluded PPI_CHG_CH8_Excluded
|
||||
#define PPI_CHG2_CH8_Included PPI_CHG_CH8_Included
|
||||
|
||||
#define PPI_CHG2_CH7_Pos PPI_CHG_CH7_Pos
|
||||
#define PPI_CHG2_CH7_Msk PPI_CHG_CH7_Msk
|
||||
#define PPI_CHG2_CH7_Excluded PPI_CHG_CH7_Excluded
|
||||
#define PPI_CHG2_CH7_Included PPI_CHG_CH7_Included
|
||||
|
||||
#define PPI_CHG2_CH6_Pos PPI_CHG_CH6_Pos
|
||||
#define PPI_CHG2_CH6_Msk PPI_CHG_CH6_Msk
|
||||
#define PPI_CHG2_CH6_Excluded PPI_CHG_CH6_Excluded
|
||||
#define PPI_CHG2_CH6_Included PPI_CHG_CH6_Included
|
||||
|
||||
#define PPI_CHG2_CH5_Pos PPI_CHG_CH5_Pos
|
||||
#define PPI_CHG2_CH5_Msk PPI_CHG_CH5_Msk
|
||||
#define PPI_CHG2_CH5_Excluded PPI_CHG_CH5_Excluded
|
||||
#define PPI_CHG2_CH5_Included PPI_CHG_CH5_Included
|
||||
|
||||
#define PPI_CHG2_CH4_Pos PPI_CHG_CH4_Pos
|
||||
#define PPI_CHG2_CH4_Msk PPI_CHG_CH4_Msk
|
||||
#define PPI_CHG2_CH4_Excluded PPI_CHG_CH4_Excluded
|
||||
#define PPI_CHG2_CH4_Included PPI_CHG_CH4_Included
|
||||
|
||||
#define PPI_CHG2_CH3_Pos PPI_CHG_CH3_Pos
|
||||
#define PPI_CHG2_CH3_Msk PPI_CHG_CH3_Msk
|
||||
#define PPI_CHG2_CH3_Excluded PPI_CHG_CH3_Excluded
|
||||
#define PPI_CHG2_CH3_Included PPI_CHG_CH3_Included
|
||||
|
||||
#define PPI_CHG2_CH2_Pos PPI_CHG_CH2_Pos
|
||||
#define PPI_CHG2_CH2_Msk PPI_CHG_CH2_Msk
|
||||
#define PPI_CHG2_CH2_Excluded PPI_CHG_CH2_Excluded
|
||||
#define PPI_CHG2_CH2_Included PPI_CHG_CH2_Included
|
||||
|
||||
#define PPI_CHG2_CH1_Pos PPI_CHG_CH1_Pos
|
||||
#define PPI_CHG2_CH1_Msk PPI_CHG_CH1_Msk
|
||||
#define PPI_CHG2_CH1_Excluded PPI_CHG_CH1_Excluded
|
||||
#define PPI_CHG2_CH1_Included PPI_CHG_CH1_Included
|
||||
|
||||
#define PPI_CHG2_CH0_Pos PPI_CHG_CH0_Pos
|
||||
#define PPI_CHG2_CH0_Msk PPI_CHG_CH0_Msk
|
||||
#define PPI_CHG2_CH0_Excluded PPI_CHG_CH0_Excluded
|
||||
#define PPI_CHG2_CH0_Included PPI_CHG_CH0_Included
|
||||
|
||||
#define PPI_CHG3_CH15_Pos PPI_CHG_CH15_Pos
|
||||
#define PPI_CHG3_CH15_Msk PPI_CHG_CH15_Msk
|
||||
#define PPI_CHG3_CH15_Excluded PPI_CHG_CH15_Excluded
|
||||
#define PPI_CHG3_CH15_Included PPI_CHG_CH15_Included
|
||||
|
||||
#define PPI_CHG3_CH14_Pos PPI_CHG_CH14_Pos
|
||||
#define PPI_CHG3_CH14_Msk PPI_CHG_CH14_Msk
|
||||
#define PPI_CHG3_CH14_Excluded PPI_CHG_CH14_Excluded
|
||||
#define PPI_CHG3_CH14_Included PPI_CHG_CH14_Included
|
||||
|
||||
#define PPI_CHG3_CH13_Pos PPI_CHG_CH13_Pos
|
||||
#define PPI_CHG3_CH13_Msk PPI_CHG_CH13_Msk
|
||||
#define PPI_CHG3_CH13_Excluded PPI_CHG_CH13_Excluded
|
||||
#define PPI_CHG3_CH13_Included PPI_CHG_CH13_Included
|
||||
|
||||
#define PPI_CHG3_CH12_Pos PPI_CHG_CH12_Pos
|
||||
#define PPI_CHG3_CH12_Msk PPI_CHG_CH12_Msk
|
||||
#define PPI_CHG3_CH12_Excluded PPI_CHG_CH12_Excluded
|
||||
#define PPI_CHG3_CH12_Included PPI_CHG_CH12_Included
|
||||
|
||||
#define PPI_CHG3_CH11_Pos PPI_CHG_CH11_Pos
|
||||
#define PPI_CHG3_CH11_Msk PPI_CHG_CH11_Msk
|
||||
#define PPI_CHG3_CH11_Excluded PPI_CHG_CH11_Excluded
|
||||
#define PPI_CHG3_CH11_Included PPI_CHG_CH11_Included
|
||||
|
||||
#define PPI_CHG3_CH10_Pos PPI_CHG_CH10_Pos
|
||||
#define PPI_CHG3_CH10_Msk PPI_CHG_CH10_Msk
|
||||
#define PPI_CHG3_CH10_Excluded PPI_CHG_CH10_Excluded
|
||||
#define PPI_CHG3_CH10_Included PPI_CHG_CH10_Included
|
||||
|
||||
#define PPI_CHG3_CH9_Pos PPI_CHG_CH9_Pos
|
||||
#define PPI_CHG3_CH9_Msk PPI_CHG_CH9_Msk
|
||||
#define PPI_CHG3_CH9_Excluded PPI_CHG_CH9_Excluded
|
||||
#define PPI_CHG3_CH9_Included PPI_CHG_CH9_Included
|
||||
|
||||
#define PPI_CHG3_CH8_Pos PPI_CHG_CH8_Pos
|
||||
#define PPI_CHG3_CH8_Msk PPI_CHG_CH8_Msk
|
||||
#define PPI_CHG3_CH8_Excluded PPI_CHG_CH8_Excluded
|
||||
#define PPI_CHG3_CH8_Included PPI_CHG_CH8_Included
|
||||
|
||||
#define PPI_CHG3_CH7_Pos PPI_CHG_CH7_Pos
|
||||
#define PPI_CHG3_CH7_Msk PPI_CHG_CH7_Msk
|
||||
#define PPI_CHG3_CH7_Excluded PPI_CHG_CH7_Excluded
|
||||
#define PPI_CHG3_CH7_Included PPI_CHG_CH7_Included
|
||||
|
||||
#define PPI_CHG3_CH6_Pos PPI_CHG_CH6_Pos
|
||||
#define PPI_CHG3_CH6_Msk PPI_CHG_CH6_Msk
|
||||
#define PPI_CHG3_CH6_Excluded PPI_CHG_CH6_Excluded
|
||||
#define PPI_CHG3_CH6_Included PPI_CHG_CH6_Included
|
||||
|
||||
#define PPI_CHG3_CH5_Pos PPI_CHG_CH5_Pos
|
||||
#define PPI_CHG3_CH5_Msk PPI_CHG_CH5_Msk
|
||||
#define PPI_CHG3_CH5_Excluded PPI_CHG_CH5_Excluded
|
||||
#define PPI_CHG3_CH5_Included PPI_CHG_CH5_Included
|
||||
|
||||
#define PPI_CHG3_CH4_Pos PPI_CHG_CH4_Pos
|
||||
#define PPI_CHG3_CH4_Msk PPI_CHG_CH4_Msk
|
||||
#define PPI_CHG3_CH4_Excluded PPI_CHG_CH4_Excluded
|
||||
#define PPI_CHG3_CH4_Included PPI_CHG_CH4_Included
|
||||
|
||||
#define PPI_CHG3_CH3_Pos PPI_CHG_CH3_Pos
|
||||
#define PPI_CHG3_CH3_Msk PPI_CHG_CH3_Msk
|
||||
#define PPI_CHG3_CH3_Excluded PPI_CHG_CH3_Excluded
|
||||
#define PPI_CHG3_CH3_Included PPI_CHG_CH3_Included
|
||||
|
||||
#define PPI_CHG3_CH2_Pos PPI_CHG_CH2_Pos
|
||||
#define PPI_CHG3_CH2_Msk PPI_CHG_CH2_Msk
|
||||
#define PPI_CHG3_CH2_Excluded PPI_CHG_CH2_Excluded
|
||||
#define PPI_CHG3_CH2_Included PPI_CHG_CH2_Included
|
||||
|
||||
#define PPI_CHG3_CH1_Pos PPI_CHG_CH1_Pos
|
||||
#define PPI_CHG3_CH1_Msk PPI_CHG_CH1_Msk
|
||||
#define PPI_CHG3_CH1_Excluded PPI_CHG_CH1_Excluded
|
||||
#define PPI_CHG3_CH1_Included PPI_CHG_CH1_Included
|
||||
|
||||
#define PPI_CHG3_CH0_Pos PPI_CHG_CH0_Pos
|
||||
#define PPI_CHG3_CH0_Msk PPI_CHG_CH0_Msk
|
||||
#define PPI_CHG3_CH0_Excluded PPI_CHG_CH0_Excluded
|
||||
#define PPI_CHG3_CH0_Included PPI_CHG_CH0_Included
|
||||
|
||||
|
||||
|
||||
|
||||
/*lint --flb "Leave library region" */
|
||||
|
||||
#endif /* NRF51_TO_NRF52810_H */
|
||||
|
||||
@@ -0,0 +1,569 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2010 - 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 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.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, 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 NRF51_TO_NRF52840_H
|
||||
#define NRF51_TO_NRF52840_H
|
||||
|
||||
/*lint ++flb "Enter library region */
|
||||
|
||||
/* This file is given to prevent your SW from not compiling with the name changes between nRF51 and nRF52840 devices.
|
||||
* It redefines the old nRF51 names into the new ones as long as the functionality is still supported. If the
|
||||
* functionality is gone, there old names are not defined, so compilation will fail. Note that also includes macros
|
||||
* from the nrf51_deprecated.h file. */
|
||||
|
||||
|
||||
/* IRQ */
|
||||
/* Several peripherals have been added to several indexes. Names of IRQ handlers and IRQ numbers have changed. */
|
||||
#define UART0_IRQHandler UARTE0_UART0_IRQHandler
|
||||
#define SPI0_TWI0_IRQHandler SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler
|
||||
#define SPI1_TWI1_IRQHandler SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler
|
||||
#define ADC_IRQHandler SAADC_IRQHandler
|
||||
#define LPCOMP_IRQHandler COMP_LPCOMP_IRQHandler
|
||||
#define SWI0_IRQHandler SWI0_EGU0_IRQHandler
|
||||
#define SWI1_IRQHandler SWI1_EGU1_IRQHandler
|
||||
#define SWI2_IRQHandler SWI2_EGU2_IRQHandler
|
||||
#define SWI3_IRQHandler SWI3_EGU3_IRQHandler
|
||||
#define SWI4_IRQHandler SWI4_EGU4_IRQHandler
|
||||
#define SWI5_IRQHandler SWI5_EGU5_IRQHandler
|
||||
|
||||
#define UART0_IRQn UARTE0_UART0_IRQn
|
||||
#define SPI0_TWI0_IRQn SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn
|
||||
#define SPI1_TWI1_IRQn SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn
|
||||
#define ADC_IRQn SAADC_IRQn
|
||||
#define LPCOMP_IRQn COMP_LPCOMP_IRQn
|
||||
#define SWI0_IRQn SWI0_EGU0_IRQn
|
||||
#define SWI1_IRQn SWI1_EGU1_IRQn
|
||||
#define SWI2_IRQn SWI2_EGU2_IRQn
|
||||
#define SWI3_IRQn SWI3_EGU3_IRQn
|
||||
#define SWI4_IRQn SWI4_EGU4_IRQn
|
||||
#define SWI5_IRQn SWI5_EGU5_IRQn
|
||||
|
||||
|
||||
/* UICR */
|
||||
/* Register RBPCONF was renamed to APPROTECT. */
|
||||
#define RBPCONF APPROTECT
|
||||
|
||||
#define UICR_RBPCONF_PALL_Pos UICR_APPROTECT_PALL_Pos
|
||||
#define UICR_RBPCONF_PALL_Msk UICR_APPROTECT_PALL_Msk
|
||||
#define UICR_RBPCONF_PALL_Enabled UICR_APPROTECT_PALL_Enabled
|
||||
#define UICR_RBPCONF_PALL_Disabled UICR_APPROTECT_PALL_Disabled
|
||||
|
||||
|
||||
/* GPIO */
|
||||
/* GPIO port was renamed to P0. */
|
||||
#define NRF_GPIO NRF_P0
|
||||
#define NRF_GPIO_BASE NRF_P0_BASE
|
||||
|
||||
|
||||
/* QDEC */
|
||||
/* The registers PSELA, PSELB and PSELLED were restructured into a struct. */
|
||||
#define PSELLED PSEL.LED
|
||||
#define PSELA PSEL.A
|
||||
#define PSELB PSEL.B
|
||||
|
||||
|
||||
/* SPIS */
|
||||
/* The registers PSELSCK, PSELMISO, PSELMOSI, PSELCSN were restructured into a struct. */
|
||||
#define PSELSCK PSEL.SCK
|
||||
#define PSELMISO PSEL.MISO
|
||||
#define PSELMOSI PSEL.MOSI
|
||||
#define PSELCSN PSEL.CSN
|
||||
|
||||
/* The registers RXDPTR, MAXRX, AMOUNTRX were restructured into a struct */
|
||||
#define RXDPTR RXD.PTR
|
||||
#define MAXRX RXD.MAXCNT
|
||||
#define AMOUNTRX RXD.AMOUNT
|
||||
|
||||
#define SPIS_MAXRX_MAXRX_Pos SPIS_RXD_MAXCNT_MAXCNT_Pos
|
||||
#define SPIS_MAXRX_MAXRX_Msk SPIS_RXD_MAXCNT_MAXCNT_Msk
|
||||
|
||||
#define SPIS_AMOUNTRX_AMOUNTRX_Pos SPIS_RXD_AMOUNT_AMOUNT_Pos
|
||||
#define SPIS_AMOUNTRX_AMOUNTRX_Msk SPIS_RXD_AMOUNT_AMOUNT_Msk
|
||||
|
||||
/* The registers TXDPTR, MAXTX, AMOUNTTX were restructured into a struct */
|
||||
#define TXDPTR TXD.PTR
|
||||
#define MAXTX TXD.MAXCNT
|
||||
#define AMOUNTTX TXD.AMOUNT
|
||||
|
||||
#define SPIS_MAXTX_MAXTX_Pos SPIS_TXD_MAXCNT_MAXCNT_Pos
|
||||
#define SPIS_MAXTX_MAXTX_Msk SPIS_TXD_MAXCNT_MAXCNT_Msk
|
||||
|
||||
#define SPIS_AMOUNTTX_AMOUNTTX_Pos SPIS_TXD_AMOUNT_AMOUNT_Pos
|
||||
#define SPIS_AMOUNTTX_AMOUNTTX_Msk SPIS_TXD_AMOUNT_AMOUNT_Msk
|
||||
|
||||
|
||||
/* UART */
|
||||
/* The registers PSELRTS, PSELTXD, PSELCTS, PSELRXD were restructured into a struct. */
|
||||
#define PSELRTS PSEL.RTS
|
||||
#define PSELTXD PSEL.TXD
|
||||
#define PSELCTS PSEL.CTS
|
||||
#define PSELRXD PSEL.RXD
|
||||
|
||||
/* TWI */
|
||||
/* The registers PSELSCL, PSELSDA were restructured into a struct. */
|
||||
#define PSELSCL PSEL.SCL
|
||||
#define PSELSDA PSEL.SDA
|
||||
|
||||
|
||||
|
||||
/* From nrf51_deprecated.h */
|
||||
|
||||
/* NVMC */
|
||||
/* The register ERASEPROTECTEDPAGE changed name to ERASEPCR0 in the documentation. */
|
||||
#define ERASEPROTECTEDPAGE ERASEPCR0
|
||||
|
||||
|
||||
/* IRQ */
|
||||
/* COMP module was eliminated. Adapted to nrf52840 headers. */
|
||||
#define LPCOMP_COMP_IRQHandler COMP_LPCOMP_IRQHandler
|
||||
#define LPCOMP_COMP_IRQn COMP_LPCOMP_IRQn
|
||||
|
||||
|
||||
/* REFSEL register redefined enumerated values and added some more. */
|
||||
#define LPCOMP_REFSEL_REFSEL_SupplyOneEighthPrescaling LPCOMP_REFSEL_REFSEL_Ref1_8Vdd
|
||||
#define LPCOMP_REFSEL_REFSEL_SupplyTwoEighthsPrescaling LPCOMP_REFSEL_REFSEL_Ref2_8Vdd
|
||||
#define LPCOMP_REFSEL_REFSEL_SupplyThreeEighthsPrescaling LPCOMP_REFSEL_REFSEL_Ref3_8Vdd
|
||||
#define LPCOMP_REFSEL_REFSEL_SupplyFourEighthsPrescaling LPCOMP_REFSEL_REFSEL_Ref4_8Vdd
|
||||
#define LPCOMP_REFSEL_REFSEL_SupplyFiveEighthsPrescaling LPCOMP_REFSEL_REFSEL_Ref5_8Vdd
|
||||
#define LPCOMP_REFSEL_REFSEL_SupplySixEighthsPrescaling LPCOMP_REFSEL_REFSEL_Ref6_8Vdd
|
||||
#define LPCOMP_REFSEL_REFSEL_SupplySevenEighthsPrescaling LPCOMP_REFSEL_REFSEL_Ref7_8Vdd
|
||||
|
||||
|
||||
/* RADIO */
|
||||
/* The name of the field SKIPADDR was corrected. Old macros added for compatibility. */
|
||||
#define RADIO_CRCCNF_SKIP_ADDR_Pos RADIO_CRCCNF_SKIPADDR_Pos
|
||||
#define RADIO_CRCCNF_SKIP_ADDR_Msk RADIO_CRCCNF_SKIPADDR_Msk
|
||||
#define RADIO_CRCCNF_SKIP_ADDR_Include RADIO_CRCCNF_SKIPADDR_Include
|
||||
#define RADIO_CRCCNF_SKIP_ADDR_Skip RADIO_CRCCNF_SKIPADDR_Skip
|
||||
|
||||
|
||||
/* FICR */
|
||||
/* The registers FICR.DEVICEID0 and FICR.DEVICEID1 were renamed into an array. */
|
||||
#define DEVICEID0 DEVICEID[0]
|
||||
#define DEVICEID1 DEVICEID[1]
|
||||
|
||||
/* The registers FICR.ER0, FICR.ER1, FICR.ER2 and FICR.ER3 were renamed into an array. */
|
||||
#define ER0 ER[0]
|
||||
#define ER1 ER[1]
|
||||
#define ER2 ER[2]
|
||||
#define ER3 ER[3]
|
||||
|
||||
/* The registers FICR.IR0, FICR.IR1, FICR.IR2 and FICR.IR3 were renamed into an array. */
|
||||
#define IR0 IR[0]
|
||||
#define IR1 IR[1]
|
||||
#define IR2 IR[2]
|
||||
#define IR3 IR[3]
|
||||
|
||||
/* The registers FICR.DEVICEADDR0 and FICR.DEVICEADDR1 were renamed into an array. */
|
||||
#define DEVICEADDR0 DEVICEADDR[0]
|
||||
#define DEVICEADDR1 DEVICEADDR[1]
|
||||
|
||||
|
||||
/* PPI */
|
||||
/* The tasks PPI.TASKS_CHGxEN and PPI.TASKS_CHGxDIS were renamed into an array of structs. */
|
||||
#define TASKS_CHG0EN TASKS_CHG[0].EN
|
||||
#define TASKS_CHG0DIS TASKS_CHG[0].DIS
|
||||
#define TASKS_CHG1EN TASKS_CHG[1].EN
|
||||
#define TASKS_CHG1DIS TASKS_CHG[1].DIS
|
||||
#define TASKS_CHG2EN TASKS_CHG[2].EN
|
||||
#define TASKS_CHG2DIS TASKS_CHG[2].DIS
|
||||
#define TASKS_CHG3EN TASKS_CHG[3].EN
|
||||
#define TASKS_CHG3DIS TASKS_CHG[3].DIS
|
||||
|
||||
/* The registers PPI.CHx_EEP and PPI.CHx_TEP were renamed into an array of structs. */
|
||||
#define CH0_EEP CH[0].EEP
|
||||
#define CH0_TEP CH[0].TEP
|
||||
#define CH1_EEP CH[1].EEP
|
||||
#define CH1_TEP CH[1].TEP
|
||||
#define CH2_EEP CH[2].EEP
|
||||
#define CH2_TEP CH[2].TEP
|
||||
#define CH3_EEP CH[3].EEP
|
||||
#define CH3_TEP CH[3].TEP
|
||||
#define CH4_EEP CH[4].EEP
|
||||
#define CH4_TEP CH[4].TEP
|
||||
#define CH5_EEP CH[5].EEP
|
||||
#define CH5_TEP CH[5].TEP
|
||||
#define CH6_EEP CH[6].EEP
|
||||
#define CH6_TEP CH[6].TEP
|
||||
#define CH7_EEP CH[7].EEP
|
||||
#define CH7_TEP CH[7].TEP
|
||||
#define CH8_EEP CH[8].EEP
|
||||
#define CH8_TEP CH[8].TEP
|
||||
#define CH9_EEP CH[9].EEP
|
||||
#define CH9_TEP CH[9].TEP
|
||||
#define CH10_EEP CH[10].EEP
|
||||
#define CH10_TEP CH[10].TEP
|
||||
#define CH11_EEP CH[11].EEP
|
||||
#define CH11_TEP CH[11].TEP
|
||||
#define CH12_EEP CH[12].EEP
|
||||
#define CH12_TEP CH[12].TEP
|
||||
#define CH13_EEP CH[13].EEP
|
||||
#define CH13_TEP CH[13].TEP
|
||||
#define CH14_EEP CH[14].EEP
|
||||
#define CH14_TEP CH[14].TEP
|
||||
#define CH15_EEP CH[15].EEP
|
||||
#define CH15_TEP CH[15].TEP
|
||||
|
||||
/* The registers PPI.CHG0, PPI.CHG1, PPI.CHG2 and PPI.CHG3 were renamed into an array. */
|
||||
#define CHG0 CHG[0]
|
||||
#define CHG1 CHG[1]
|
||||
#define CHG2 CHG[2]
|
||||
#define CHG3 CHG[3]
|
||||
|
||||
/* All bitfield macros for the CHGx registers therefore changed name. */
|
||||
#define PPI_CHG0_CH15_Pos PPI_CHG_CH15_Pos
|
||||
#define PPI_CHG0_CH15_Msk PPI_CHG_CH15_Msk
|
||||
#define PPI_CHG0_CH15_Excluded PPI_CHG_CH15_Excluded
|
||||
#define PPI_CHG0_CH15_Included PPI_CHG_CH15_Included
|
||||
|
||||
#define PPI_CHG0_CH14_Pos PPI_CHG_CH14_Pos
|
||||
#define PPI_CHG0_CH14_Msk PPI_CHG_CH14_Msk
|
||||
#define PPI_CHG0_CH14_Excluded PPI_CHG_CH14_Excluded
|
||||
#define PPI_CHG0_CH14_Included PPI_CHG_CH14_Included
|
||||
|
||||
#define PPI_CHG0_CH13_Pos PPI_CHG_CH13_Pos
|
||||
#define PPI_CHG0_CH13_Msk PPI_CHG_CH13_Msk
|
||||
#define PPI_CHG0_CH13_Excluded PPI_CHG_CH13_Excluded
|
||||
#define PPI_CHG0_CH13_Included PPI_CHG_CH13_Included
|
||||
|
||||
#define PPI_CHG0_CH12_Pos PPI_CHG_CH12_Pos
|
||||
#define PPI_CHG0_CH12_Msk PPI_CHG_CH12_Msk
|
||||
#define PPI_CHG0_CH12_Excluded PPI_CHG_CH12_Excluded
|
||||
#define PPI_CHG0_CH12_Included PPI_CHG_CH12_Included
|
||||
|
||||
#define PPI_CHG0_CH11_Pos PPI_CHG_CH11_Pos
|
||||
#define PPI_CHG0_CH11_Msk PPI_CHG_CH11_Msk
|
||||
#define PPI_CHG0_CH11_Excluded PPI_CHG_CH11_Excluded
|
||||
#define PPI_CHG0_CH11_Included PPI_CHG_CH11_Included
|
||||
|
||||
#define PPI_CHG0_CH10_Pos PPI_CHG_CH10_Pos
|
||||
#define PPI_CHG0_CH10_Msk PPI_CHG_CH10_Msk
|
||||
#define PPI_CHG0_CH10_Excluded PPI_CHG_CH10_Excluded
|
||||
#define PPI_CHG0_CH10_Included PPI_CHG_CH10_Included
|
||||
|
||||
#define PPI_CHG0_CH9_Pos PPI_CHG_CH9_Pos
|
||||
#define PPI_CHG0_CH9_Msk PPI_CHG_CH9_Msk
|
||||
#define PPI_CHG0_CH9_Excluded PPI_CHG_CH9_Excluded
|
||||
#define PPI_CHG0_CH9_Included PPI_CHG_CH9_Included
|
||||
|
||||
#define PPI_CHG0_CH8_Pos PPI_CHG_CH8_Pos
|
||||
#define PPI_CHG0_CH8_Msk PPI_CHG_CH8_Msk
|
||||
#define PPI_CHG0_CH8_Excluded PPI_CHG_CH8_Excluded
|
||||
#define PPI_CHG0_CH8_Included PPI_CHG_CH8_Included
|
||||
|
||||
#define PPI_CHG0_CH7_Pos PPI_CHG_CH7_Pos
|
||||
#define PPI_CHG0_CH7_Msk PPI_CHG_CH7_Msk
|
||||
#define PPI_CHG0_CH7_Excluded PPI_CHG_CH7_Excluded
|
||||
#define PPI_CHG0_CH7_Included PPI_CHG_CH7_Included
|
||||
|
||||
#define PPI_CHG0_CH6_Pos PPI_CHG_CH6_Pos
|
||||
#define PPI_CHG0_CH6_Msk PPI_CHG_CH6_Msk
|
||||
#define PPI_CHG0_CH6_Excluded PPI_CHG_CH6_Excluded
|
||||
#define PPI_CHG0_CH6_Included PPI_CHG_CH6_Included
|
||||
|
||||
#define PPI_CHG0_CH5_Pos PPI_CHG_CH5_Pos
|
||||
#define PPI_CHG0_CH5_Msk PPI_CHG_CH5_Msk
|
||||
#define PPI_CHG0_CH5_Excluded PPI_CHG_CH5_Excluded
|
||||
#define PPI_CHG0_CH5_Included PPI_CHG_CH5_Included
|
||||
|
||||
#define PPI_CHG0_CH4_Pos PPI_CHG_CH4_Pos
|
||||
#define PPI_CHG0_CH4_Msk PPI_CHG_CH4_Msk
|
||||
#define PPI_CHG0_CH4_Excluded PPI_CHG_CH4_Excluded
|
||||
#define PPI_CHG0_CH4_Included PPI_CHG_CH4_Included
|
||||
|
||||
#define PPI_CHG0_CH3_Pos PPI_CHG_CH3_Pos
|
||||
#define PPI_CHG0_CH3_Msk PPI_CHG_CH3_Msk
|
||||
#define PPI_CHG0_CH3_Excluded PPI_CHG_CH3_Excluded
|
||||
#define PPI_CHG0_CH3_Included PPI_CHG_CH3_Included
|
||||
|
||||
#define PPI_CHG0_CH2_Pos PPI_CHG_CH2_Pos
|
||||
#define PPI_CHG0_CH2_Msk PPI_CHG_CH2_Msk
|
||||
#define PPI_CHG0_CH2_Excluded PPI_CHG_CH2_Excluded
|
||||
#define PPI_CHG0_CH2_Included PPI_CHG_CH2_Included
|
||||
|
||||
#define PPI_CHG0_CH1_Pos PPI_CHG_CH1_Pos
|
||||
#define PPI_CHG0_CH1_Msk PPI_CHG_CH1_Msk
|
||||
#define PPI_CHG0_CH1_Excluded PPI_CHG_CH1_Excluded
|
||||
#define PPI_CHG0_CH1_Included PPI_CHG_CH1_Included
|
||||
|
||||
#define PPI_CHG0_CH0_Pos PPI_CHG_CH0_Pos
|
||||
#define PPI_CHG0_CH0_Msk PPI_CHG_CH0_Msk
|
||||
#define PPI_CHG0_CH0_Excluded PPI_CHG_CH0_Excluded
|
||||
#define PPI_CHG0_CH0_Included PPI_CHG_CH0_Included
|
||||
|
||||
#define PPI_CHG1_CH15_Pos PPI_CHG_CH15_Pos
|
||||
#define PPI_CHG1_CH15_Msk PPI_CHG_CH15_Msk
|
||||
#define PPI_CHG1_CH15_Excluded PPI_CHG_CH15_Excluded
|
||||
#define PPI_CHG1_CH15_Included PPI_CHG_CH15_Included
|
||||
|
||||
#define PPI_CHG1_CH14_Pos PPI_CHG_CH14_Pos
|
||||
#define PPI_CHG1_CH14_Msk PPI_CHG_CH14_Msk
|
||||
#define PPI_CHG1_CH14_Excluded PPI_CHG_CH14_Excluded
|
||||
#define PPI_CHG1_CH14_Included PPI_CHG_CH14_Included
|
||||
|
||||
#define PPI_CHG1_CH13_Pos PPI_CHG_CH13_Pos
|
||||
#define PPI_CHG1_CH13_Msk PPI_CHG_CH13_Msk
|
||||
#define PPI_CHG1_CH13_Excluded PPI_CHG_CH13_Excluded
|
||||
#define PPI_CHG1_CH13_Included PPI_CHG_CH13_Included
|
||||
|
||||
#define PPI_CHG1_CH12_Pos PPI_CHG_CH12_Pos
|
||||
#define PPI_CHG1_CH12_Msk PPI_CHG_CH12_Msk
|
||||
#define PPI_CHG1_CH12_Excluded PPI_CHG_CH12_Excluded
|
||||
#define PPI_CHG1_CH12_Included PPI_CHG_CH12_Included
|
||||
|
||||
#define PPI_CHG1_CH11_Pos PPI_CHG_CH11_Pos
|
||||
#define PPI_CHG1_CH11_Msk PPI_CHG_CH11_Msk
|
||||
#define PPI_CHG1_CH11_Excluded PPI_CHG_CH11_Excluded
|
||||
#define PPI_CHG1_CH11_Included PPI_CHG_CH11_Included
|
||||
|
||||
#define PPI_CHG1_CH10_Pos PPI_CHG_CH10_Pos
|
||||
#define PPI_CHG1_CH10_Msk PPI_CHG_CH10_Msk
|
||||
#define PPI_CHG1_CH10_Excluded PPI_CHG_CH10_Excluded
|
||||
#define PPI_CHG1_CH10_Included PPI_CHG_CH10_Included
|
||||
|
||||
#define PPI_CHG1_CH9_Pos PPI_CHG_CH9_Pos
|
||||
#define PPI_CHG1_CH9_Msk PPI_CHG_CH9_Msk
|
||||
#define PPI_CHG1_CH9_Excluded PPI_CHG_CH9_Excluded
|
||||
#define PPI_CHG1_CH9_Included PPI_CHG_CH9_Included
|
||||
|
||||
#define PPI_CHG1_CH8_Pos PPI_CHG_CH8_Pos
|
||||
#define PPI_CHG1_CH8_Msk PPI_CHG_CH8_Msk
|
||||
#define PPI_CHG1_CH8_Excluded PPI_CHG_CH8_Excluded
|
||||
#define PPI_CHG1_CH8_Included PPI_CHG_CH8_Included
|
||||
|
||||
#define PPI_CHG1_CH7_Pos PPI_CHG_CH7_Pos
|
||||
#define PPI_CHG1_CH7_Msk PPI_CHG_CH7_Msk
|
||||
#define PPI_CHG1_CH7_Excluded PPI_CHG_CH7_Excluded
|
||||
#define PPI_CHG1_CH7_Included PPI_CHG_CH7_Included
|
||||
|
||||
#define PPI_CHG1_CH6_Pos PPI_CHG_CH6_Pos
|
||||
#define PPI_CHG1_CH6_Msk PPI_CHG_CH6_Msk
|
||||
#define PPI_CHG1_CH6_Excluded PPI_CHG_CH6_Excluded
|
||||
#define PPI_CHG1_CH6_Included PPI_CHG_CH6_Included
|
||||
|
||||
#define PPI_CHG1_CH5_Pos PPI_CHG_CH5_Pos
|
||||
#define PPI_CHG1_CH5_Msk PPI_CHG_CH5_Msk
|
||||
#define PPI_CHG1_CH5_Excluded PPI_CHG_CH5_Excluded
|
||||
#define PPI_CHG1_CH5_Included PPI_CHG_CH5_Included
|
||||
|
||||
#define PPI_CHG1_CH4_Pos PPI_CHG_CH4_Pos
|
||||
#define PPI_CHG1_CH4_Msk PPI_CHG_CH4_Msk
|
||||
#define PPI_CHG1_CH4_Excluded PPI_CHG_CH4_Excluded
|
||||
#define PPI_CHG1_CH4_Included PPI_CHG_CH4_Included
|
||||
|
||||
#define PPI_CHG1_CH3_Pos PPI_CHG_CH3_Pos
|
||||
#define PPI_CHG1_CH3_Msk PPI_CHG_CH3_Msk
|
||||
#define PPI_CHG1_CH3_Excluded PPI_CHG_CH3_Excluded
|
||||
#define PPI_CHG1_CH3_Included PPI_CHG_CH3_Included
|
||||
|
||||
#define PPI_CHG1_CH2_Pos PPI_CHG_CH2_Pos
|
||||
#define PPI_CHG1_CH2_Msk PPI_CHG_CH2_Msk
|
||||
#define PPI_CHG1_CH2_Excluded PPI_CHG_CH2_Excluded
|
||||
#define PPI_CHG1_CH2_Included PPI_CHG_CH2_Included
|
||||
|
||||
#define PPI_CHG1_CH1_Pos PPI_CHG_CH1_Pos
|
||||
#define PPI_CHG1_CH1_Msk PPI_CHG_CH1_Msk
|
||||
#define PPI_CHG1_CH1_Excluded PPI_CHG_CH1_Excluded
|
||||
#define PPI_CHG1_CH1_Included PPI_CHG_CH1_Included
|
||||
|
||||
#define PPI_CHG1_CH0_Pos PPI_CHG_CH0_Pos
|
||||
#define PPI_CHG1_CH0_Msk PPI_CHG_CH0_Msk
|
||||
#define PPI_CHG1_CH0_Excluded PPI_CHG_CH0_Excluded
|
||||
#define PPI_CHG1_CH0_Included PPI_CHG_CH0_Included
|
||||
|
||||
#define PPI_CHG2_CH15_Pos PPI_CHG_CH15_Pos
|
||||
#define PPI_CHG2_CH15_Msk PPI_CHG_CH15_Msk
|
||||
#define PPI_CHG2_CH15_Excluded PPI_CHG_CH15_Excluded
|
||||
#define PPI_CHG2_CH15_Included PPI_CHG_CH15_Included
|
||||
|
||||
#define PPI_CHG2_CH14_Pos PPI_CHG_CH14_Pos
|
||||
#define PPI_CHG2_CH14_Msk PPI_CHG_CH14_Msk
|
||||
#define PPI_CHG2_CH14_Excluded PPI_CHG_CH14_Excluded
|
||||
#define PPI_CHG2_CH14_Included PPI_CHG_CH14_Included
|
||||
|
||||
#define PPI_CHG2_CH13_Pos PPI_CHG_CH13_Pos
|
||||
#define PPI_CHG2_CH13_Msk PPI_CHG_CH13_Msk
|
||||
#define PPI_CHG2_CH13_Excluded PPI_CHG_CH13_Excluded
|
||||
#define PPI_CHG2_CH13_Included PPI_CHG_CH13_Included
|
||||
|
||||
#define PPI_CHG2_CH12_Pos PPI_CHG_CH12_Pos
|
||||
#define PPI_CHG2_CH12_Msk PPI_CHG_CH12_Msk
|
||||
#define PPI_CHG2_CH12_Excluded PPI_CHG_CH12_Excluded
|
||||
#define PPI_CHG2_CH12_Included PPI_CHG_CH12_Included
|
||||
|
||||
#define PPI_CHG2_CH11_Pos PPI_CHG_CH11_Pos
|
||||
#define PPI_CHG2_CH11_Msk PPI_CHG_CH11_Msk
|
||||
#define PPI_CHG2_CH11_Excluded PPI_CHG_CH11_Excluded
|
||||
#define PPI_CHG2_CH11_Included PPI_CHG_CH11_Included
|
||||
|
||||
#define PPI_CHG2_CH10_Pos PPI_CHG_CH10_Pos
|
||||
#define PPI_CHG2_CH10_Msk PPI_CHG_CH10_Msk
|
||||
#define PPI_CHG2_CH10_Excluded PPI_CHG_CH10_Excluded
|
||||
#define PPI_CHG2_CH10_Included PPI_CHG_CH10_Included
|
||||
|
||||
#define PPI_CHG2_CH9_Pos PPI_CHG_CH9_Pos
|
||||
#define PPI_CHG2_CH9_Msk PPI_CHG_CH9_Msk
|
||||
#define PPI_CHG2_CH9_Excluded PPI_CHG_CH9_Excluded
|
||||
#define PPI_CHG2_CH9_Included PPI_CHG_CH9_Included
|
||||
|
||||
#define PPI_CHG2_CH8_Pos PPI_CHG_CH8_Pos
|
||||
#define PPI_CHG2_CH8_Msk PPI_CHG_CH8_Msk
|
||||
#define PPI_CHG2_CH8_Excluded PPI_CHG_CH8_Excluded
|
||||
#define PPI_CHG2_CH8_Included PPI_CHG_CH8_Included
|
||||
|
||||
#define PPI_CHG2_CH7_Pos PPI_CHG_CH7_Pos
|
||||
#define PPI_CHG2_CH7_Msk PPI_CHG_CH7_Msk
|
||||
#define PPI_CHG2_CH7_Excluded PPI_CHG_CH7_Excluded
|
||||
#define PPI_CHG2_CH7_Included PPI_CHG_CH7_Included
|
||||
|
||||
#define PPI_CHG2_CH6_Pos PPI_CHG_CH6_Pos
|
||||
#define PPI_CHG2_CH6_Msk PPI_CHG_CH6_Msk
|
||||
#define PPI_CHG2_CH6_Excluded PPI_CHG_CH6_Excluded
|
||||
#define PPI_CHG2_CH6_Included PPI_CHG_CH6_Included
|
||||
|
||||
#define PPI_CHG2_CH5_Pos PPI_CHG_CH5_Pos
|
||||
#define PPI_CHG2_CH5_Msk PPI_CHG_CH5_Msk
|
||||
#define PPI_CHG2_CH5_Excluded PPI_CHG_CH5_Excluded
|
||||
#define PPI_CHG2_CH5_Included PPI_CHG_CH5_Included
|
||||
|
||||
#define PPI_CHG2_CH4_Pos PPI_CHG_CH4_Pos
|
||||
#define PPI_CHG2_CH4_Msk PPI_CHG_CH4_Msk
|
||||
#define PPI_CHG2_CH4_Excluded PPI_CHG_CH4_Excluded
|
||||
#define PPI_CHG2_CH4_Included PPI_CHG_CH4_Included
|
||||
|
||||
#define PPI_CHG2_CH3_Pos PPI_CHG_CH3_Pos
|
||||
#define PPI_CHG2_CH3_Msk PPI_CHG_CH3_Msk
|
||||
#define PPI_CHG2_CH3_Excluded PPI_CHG_CH3_Excluded
|
||||
#define PPI_CHG2_CH3_Included PPI_CHG_CH3_Included
|
||||
|
||||
#define PPI_CHG2_CH2_Pos PPI_CHG_CH2_Pos
|
||||
#define PPI_CHG2_CH2_Msk PPI_CHG_CH2_Msk
|
||||
#define PPI_CHG2_CH2_Excluded PPI_CHG_CH2_Excluded
|
||||
#define PPI_CHG2_CH2_Included PPI_CHG_CH2_Included
|
||||
|
||||
#define PPI_CHG2_CH1_Pos PPI_CHG_CH1_Pos
|
||||
#define PPI_CHG2_CH1_Msk PPI_CHG_CH1_Msk
|
||||
#define PPI_CHG2_CH1_Excluded PPI_CHG_CH1_Excluded
|
||||
#define PPI_CHG2_CH1_Included PPI_CHG_CH1_Included
|
||||
|
||||
#define PPI_CHG2_CH0_Pos PPI_CHG_CH0_Pos
|
||||
#define PPI_CHG2_CH0_Msk PPI_CHG_CH0_Msk
|
||||
#define PPI_CHG2_CH0_Excluded PPI_CHG_CH0_Excluded
|
||||
#define PPI_CHG2_CH0_Included PPI_CHG_CH0_Included
|
||||
|
||||
#define PPI_CHG3_CH15_Pos PPI_CHG_CH15_Pos
|
||||
#define PPI_CHG3_CH15_Msk PPI_CHG_CH15_Msk
|
||||
#define PPI_CHG3_CH15_Excluded PPI_CHG_CH15_Excluded
|
||||
#define PPI_CHG3_CH15_Included PPI_CHG_CH15_Included
|
||||
|
||||
#define PPI_CHG3_CH14_Pos PPI_CHG_CH14_Pos
|
||||
#define PPI_CHG3_CH14_Msk PPI_CHG_CH14_Msk
|
||||
#define PPI_CHG3_CH14_Excluded PPI_CHG_CH14_Excluded
|
||||
#define PPI_CHG3_CH14_Included PPI_CHG_CH14_Included
|
||||
|
||||
#define PPI_CHG3_CH13_Pos PPI_CHG_CH13_Pos
|
||||
#define PPI_CHG3_CH13_Msk PPI_CHG_CH13_Msk
|
||||
#define PPI_CHG3_CH13_Excluded PPI_CHG_CH13_Excluded
|
||||
#define PPI_CHG3_CH13_Included PPI_CHG_CH13_Included
|
||||
|
||||
#define PPI_CHG3_CH12_Pos PPI_CHG_CH12_Pos
|
||||
#define PPI_CHG3_CH12_Msk PPI_CHG_CH12_Msk
|
||||
#define PPI_CHG3_CH12_Excluded PPI_CHG_CH12_Excluded
|
||||
#define PPI_CHG3_CH12_Included PPI_CHG_CH12_Included
|
||||
|
||||
#define PPI_CHG3_CH11_Pos PPI_CHG_CH11_Pos
|
||||
#define PPI_CHG3_CH11_Msk PPI_CHG_CH11_Msk
|
||||
#define PPI_CHG3_CH11_Excluded PPI_CHG_CH11_Excluded
|
||||
#define PPI_CHG3_CH11_Included PPI_CHG_CH11_Included
|
||||
|
||||
#define PPI_CHG3_CH10_Pos PPI_CHG_CH10_Pos
|
||||
#define PPI_CHG3_CH10_Msk PPI_CHG_CH10_Msk
|
||||
#define PPI_CHG3_CH10_Excluded PPI_CHG_CH10_Excluded
|
||||
#define PPI_CHG3_CH10_Included PPI_CHG_CH10_Included
|
||||
|
||||
#define PPI_CHG3_CH9_Pos PPI_CHG_CH9_Pos
|
||||
#define PPI_CHG3_CH9_Msk PPI_CHG_CH9_Msk
|
||||
#define PPI_CHG3_CH9_Excluded PPI_CHG_CH9_Excluded
|
||||
#define PPI_CHG3_CH9_Included PPI_CHG_CH9_Included
|
||||
|
||||
#define PPI_CHG3_CH8_Pos PPI_CHG_CH8_Pos
|
||||
#define PPI_CHG3_CH8_Msk PPI_CHG_CH8_Msk
|
||||
#define PPI_CHG3_CH8_Excluded PPI_CHG_CH8_Excluded
|
||||
#define PPI_CHG3_CH8_Included PPI_CHG_CH8_Included
|
||||
|
||||
#define PPI_CHG3_CH7_Pos PPI_CHG_CH7_Pos
|
||||
#define PPI_CHG3_CH7_Msk PPI_CHG_CH7_Msk
|
||||
#define PPI_CHG3_CH7_Excluded PPI_CHG_CH7_Excluded
|
||||
#define PPI_CHG3_CH7_Included PPI_CHG_CH7_Included
|
||||
|
||||
#define PPI_CHG3_CH6_Pos PPI_CHG_CH6_Pos
|
||||
#define PPI_CHG3_CH6_Msk PPI_CHG_CH6_Msk
|
||||
#define PPI_CHG3_CH6_Excluded PPI_CHG_CH6_Excluded
|
||||
#define PPI_CHG3_CH6_Included PPI_CHG_CH6_Included
|
||||
|
||||
#define PPI_CHG3_CH5_Pos PPI_CHG_CH5_Pos
|
||||
#define PPI_CHG3_CH5_Msk PPI_CHG_CH5_Msk
|
||||
#define PPI_CHG3_CH5_Excluded PPI_CHG_CH5_Excluded
|
||||
#define PPI_CHG3_CH5_Included PPI_CHG_CH5_Included
|
||||
|
||||
#define PPI_CHG3_CH4_Pos PPI_CHG_CH4_Pos
|
||||
#define PPI_CHG3_CH4_Msk PPI_CHG_CH4_Msk
|
||||
#define PPI_CHG3_CH4_Excluded PPI_CHG_CH4_Excluded
|
||||
#define PPI_CHG3_CH4_Included PPI_CHG_CH4_Included
|
||||
|
||||
#define PPI_CHG3_CH3_Pos PPI_CHG_CH3_Pos
|
||||
#define PPI_CHG3_CH3_Msk PPI_CHG_CH3_Msk
|
||||
#define PPI_CHG3_CH3_Excluded PPI_CHG_CH3_Excluded
|
||||
#define PPI_CHG3_CH3_Included PPI_CHG_CH3_Included
|
||||
|
||||
#define PPI_CHG3_CH2_Pos PPI_CHG_CH2_Pos
|
||||
#define PPI_CHG3_CH2_Msk PPI_CHG_CH2_Msk
|
||||
#define PPI_CHG3_CH2_Excluded PPI_CHG_CH2_Excluded
|
||||
#define PPI_CHG3_CH2_Included PPI_CHG_CH2_Included
|
||||
|
||||
#define PPI_CHG3_CH1_Pos PPI_CHG_CH1_Pos
|
||||
#define PPI_CHG3_CH1_Msk PPI_CHG_CH1_Msk
|
||||
#define PPI_CHG3_CH1_Excluded PPI_CHG_CH1_Excluded
|
||||
#define PPI_CHG3_CH1_Included PPI_CHG_CH1_Included
|
||||
|
||||
#define PPI_CHG3_CH0_Pos PPI_CHG_CH0_Pos
|
||||
#define PPI_CHG3_CH0_Msk PPI_CHG_CH0_Msk
|
||||
#define PPI_CHG3_CH0_Excluded PPI_CHG_CH0_Excluded
|
||||
#define PPI_CHG3_CH0_Included PPI_CHG_CH0_Included
|
||||
|
||||
|
||||
|
||||
|
||||
/*lint --flb "Leave library region" */
|
||||
|
||||
#endif /* NRF51_TO_NRF52840_H */
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2010 - 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 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.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, 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 _NRF52810_PERIPHERALS_H
|
||||
#define _NRF52810_PERIPHERALS_H
|
||||
|
||||
|
||||
/* Power Peripheral */
|
||||
#define POWER_PRESENT
|
||||
#define POWER_COUNT 1
|
||||
|
||||
#define POWER_FEATURE_RAM_REGISTERS_PRESENT
|
||||
#define POWER_FEATURE_RAM_REGISTERS_COUNT 3
|
||||
|
||||
/* Systick timer */
|
||||
#define SYSTICK_PRESENT
|
||||
#define SYSTICK_COUNT 1
|
||||
|
||||
/* Software Interrupts */
|
||||
#define SWI_PRESENT
|
||||
#define SWI_COUNT 6
|
||||
|
||||
/* GPIO */
|
||||
#define GPIO_PRESENT
|
||||
#define GPIO_COUNT 1
|
||||
|
||||
#define P0_PIN_NUM 32
|
||||
|
||||
/* MPU and BPROT */
|
||||
#define BPROT_PRESENT
|
||||
|
||||
#define BPROT_REGIONS_SIZE 4096
|
||||
#define BPROT_REGIONS_NUM 48
|
||||
|
||||
/* Radio */
|
||||
#define RADIO_PRESENT
|
||||
#define RADIO_COUNT 1
|
||||
|
||||
#define RADIO_EASYDMA_MAXCNT_SIZE 8
|
||||
|
||||
/* Accelerated Address Resolver */
|
||||
#define AAR_PRESENT
|
||||
#define AAR_COUNT 1
|
||||
|
||||
#define AAR_MAX_IRK_NUM 16
|
||||
|
||||
/* AES Electronic CodeBook mode encryption */
|
||||
#define ECB_PRESENT
|
||||
#define ECB_COUNT 1
|
||||
|
||||
/* AES CCM mode encryption */
|
||||
#define CCM_PRESENT
|
||||
#define CCM_COUNT 1
|
||||
|
||||
/* Peripheral to Peripheral Interconnect */
|
||||
#define PPI_PRESENT
|
||||
#define PPI_COUNT 1
|
||||
|
||||
#define PPI_CH_NUM 20
|
||||
#define PPI_FIXED_CH_NUM 12
|
||||
#define PPI_GROUP_NUM 6
|
||||
#define PPI_FEATURE_FORKS_PRESENT
|
||||
|
||||
/* Event Generator Unit */
|
||||
#define EGU_PRESENT
|
||||
#define EGU_COUNT 2
|
||||
|
||||
#define EGU0_CH_NUM 16
|
||||
#define EGU1_CH_NUM 16
|
||||
|
||||
/* Timer/Counter */
|
||||
#define TIMER_PRESENT
|
||||
#define TIMER_COUNT 3
|
||||
|
||||
#define TIMER0_MAX_SIZE 32
|
||||
#define TIMER1_MAX_SIZE 32
|
||||
#define TIMER2_MAX_SIZE 32
|
||||
|
||||
#define TIMER0_CC_NUM 4
|
||||
#define TIMER1_CC_NUM 4
|
||||
#define TIMER2_CC_NUM 4
|
||||
|
||||
/* Real Time Counter */
|
||||
#define RTC_PRESENT
|
||||
#define RTC_COUNT 2
|
||||
|
||||
#define RTC0_CC_NUM 3
|
||||
#define RTC1_CC_NUM 4
|
||||
|
||||
/* RNG */
|
||||
#define RNG_PRESENT
|
||||
#define RNG_COUNT 1
|
||||
|
||||
/* Watchdog Timer */
|
||||
#define WDT_PRESENT
|
||||
#define WDT_COUNT 1
|
||||
|
||||
/* Temperature Sensor */
|
||||
#define TEMP_PRESENT
|
||||
#define TEMP_COUNT 1
|
||||
|
||||
/* Serial Peripheral Interface Master with DMA */
|
||||
#define SPIM_PRESENT
|
||||
#define SPIM_COUNT 1
|
||||
|
||||
#define SPIM0_MAX_DATARATE 8
|
||||
|
||||
#define SPIM0_FEATURE_HARDWARE_CSN_PRESENT 0
|
||||
|
||||
#define SPIM0_FEATURE_DCX_PRESENT 0
|
||||
|
||||
#define SPIM0_FEATURE_RXDELAY_PRESENT 0
|
||||
|
||||
#define SPIM0_EASYDMA_MAXCNT_SIZE 10
|
||||
|
||||
/* Serial Peripheral Interface Slave with DMA*/
|
||||
#define SPIS_PRESENT
|
||||
#define SPIS_COUNT 1
|
||||
|
||||
#define SPIS0_EASYDMA_MAXCNT_SIZE 10
|
||||
|
||||
/* Two Wire Interface Master with DMA */
|
||||
#define TWIM_PRESENT
|
||||
#define TWIM_COUNT 1
|
||||
|
||||
#define TWIM0_EASYDMA_MAXCNT_SIZE 10
|
||||
|
||||
/* Two Wire Interface Slave with DMA */
|
||||
#define TWIS_PRESENT
|
||||
#define TWIS_COUNT 1
|
||||
|
||||
#define TWIS0_EASYDMA_MAXCNT_SIZE 10
|
||||
|
||||
/* Universal Asynchronous Receiver-Transmitter with DMA */
|
||||
#define UARTE_PRESENT
|
||||
#define UARTE_COUNT 1
|
||||
|
||||
#define UARTE0_EASYDMA_MAXCNT_SIZE 10
|
||||
|
||||
/* Quadrature Decoder */
|
||||
#define QDEC_PRESENT
|
||||
#define QDEC_COUNT 1
|
||||
|
||||
/* Successive Approximation Analog to Digital Converter */
|
||||
#define SAADC_PRESENT
|
||||
#define SAADC_COUNT 1
|
||||
|
||||
#define SAADC_EASYDMA_MAXCNT_SIZE 15
|
||||
|
||||
#define SAADC_CH_NUM 8
|
||||
|
||||
/* GPIO Tasks and Events */
|
||||
#define GPIOTE_PRESENT
|
||||
#define GPIOTE_COUNT 1
|
||||
|
||||
#define GPIOTE_CH_NUM 8
|
||||
|
||||
#define GPIOTE_FEATURE_SET_PRESENT
|
||||
#define GPIOTE_FEATURE_CLR_PRESENT
|
||||
|
||||
/* Comparator */
|
||||
#define COMP_PRESENT
|
||||
#define COMP_COUNT 1
|
||||
|
||||
/* Pulse Width Modulator */
|
||||
#define PWM_PRESENT
|
||||
#define PWM_COUNT 1
|
||||
|
||||
#define PWM0_CH_NUM 4
|
||||
|
||||
#define PWM0_EASYDMA_MAXCNT_SIZE 15
|
||||
|
||||
/* Pulse Density Modulator */
|
||||
#define PDM_PRESENT
|
||||
#define PDM_COUNT 1
|
||||
|
||||
#define PDM_EASYDMA_MAXCNT_SIZE 15
|
||||
|
||||
|
||||
#endif // _NRF52810_PERIPHERALS_H
|
||||
@@ -0,0 +1,276 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2010 - 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 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.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, 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 _NRF52832_PERIPHERALS_H
|
||||
#define _NRF52832_PERIPHERALS_H
|
||||
|
||||
|
||||
/* Power Peripheral */
|
||||
#define POWER_PRESENT
|
||||
#define POWER_COUNT 1
|
||||
|
||||
#define POWER_FEATURE_RAM_REGISTERS_PRESENT
|
||||
#define POWER_FEATURE_RAM_REGISTERS_COUNT 8
|
||||
|
||||
/* Floating Point Unit */
|
||||
#define FPU_PRESENT
|
||||
#define FPU_COUNT 1
|
||||
|
||||
/* Systick timer */
|
||||
#define SYSTICK_PRESENT
|
||||
#define SYSTICK_COUNT 1
|
||||
|
||||
/* Software Interrupts */
|
||||
#define SWI_PRESENT
|
||||
#define SWI_COUNT 6
|
||||
|
||||
/* Memory Watch Unit */
|
||||
#define MWU_PRESENT
|
||||
#define MWU_COUNT 1
|
||||
|
||||
/* GPIO */
|
||||
#define GPIO_PRESENT
|
||||
#define GPIO_COUNT 1
|
||||
|
||||
#define P0_PIN_NUM 32
|
||||
|
||||
/* MPU and BPROT */
|
||||
#define BPROT_PRESENT
|
||||
|
||||
#define BPROT_REGIONS_SIZE 4096
|
||||
#define BPROT_REGIONS_NUM 128
|
||||
|
||||
/* Radio */
|
||||
#define RADIO_PRESENT
|
||||
#define RADIO_COUNT 1
|
||||
|
||||
#define RADIO_EASYDMA_MAXCNT_SIZE 8
|
||||
|
||||
/* Accelerated Address Resolver */
|
||||
#define AAR_PRESENT
|
||||
#define AAR_COUNT 1
|
||||
|
||||
#define AAR_MAX_IRK_NUM 16
|
||||
|
||||
/* AES Electronic CodeBook mode encryption */
|
||||
#define ECB_PRESENT
|
||||
#define ECB_COUNT 1
|
||||
|
||||
/* AES CCM mode encryption */
|
||||
#define CCM_PRESENT
|
||||
#define CCM_COUNT 1
|
||||
|
||||
/* NFC Tag */
|
||||
#define NFCT_PRESENT
|
||||
#define NFCT_COUNT 1
|
||||
|
||||
#define NFCT_EASYDMA_MAXCNT_SIZE 9
|
||||
|
||||
/* Peripheral to Peripheral Interconnect */
|
||||
#define PPI_PRESENT
|
||||
#define PPI_COUNT 1
|
||||
|
||||
#define PPI_CH_NUM 20
|
||||
#define PPI_FIXED_CH_NUM 12
|
||||
#define PPI_GROUP_NUM 6
|
||||
#define PPI_FEATURE_FORKS_PRESENT
|
||||
|
||||
/* Event Generator Unit */
|
||||
#define EGU_PRESENT
|
||||
#define EGU_COUNT 6
|
||||
|
||||
#define EGU0_CH_NUM 16
|
||||
#define EGU1_CH_NUM 16
|
||||
#define EGU2_CH_NUM 16
|
||||
#define EGU3_CH_NUM 16
|
||||
#define EGU4_CH_NUM 16
|
||||
#define EGU5_CH_NUM 16
|
||||
|
||||
/* Timer/Counter */
|
||||
#define TIMER_PRESENT
|
||||
#define TIMER_COUNT 5
|
||||
|
||||
#define TIMER0_MAX_SIZE 32
|
||||
#define TIMER1_MAX_SIZE 32
|
||||
#define TIMER2_MAX_SIZE 32
|
||||
#define TIMER3_MAX_SIZE 32
|
||||
#define TIMER4_MAX_SIZE 32
|
||||
|
||||
#define TIMER0_CC_NUM 4
|
||||
#define TIMER1_CC_NUM 4
|
||||
#define TIMER2_CC_NUM 4
|
||||
#define TIMER3_CC_NUM 6
|
||||
#define TIMER4_CC_NUM 6
|
||||
|
||||
/* Real Time Counter */
|
||||
#define RTC_PRESENT
|
||||
#define RTC_COUNT 3
|
||||
|
||||
#define RTC0_CC_NUM 3
|
||||
#define RTC1_CC_NUM 4
|
||||
#define RTC2_CC_NUM 4
|
||||
|
||||
/* RNG */
|
||||
#define RNG_PRESENT
|
||||
#define RNG_COUNT 1
|
||||
|
||||
/* Watchdog Timer */
|
||||
#define WDT_PRESENT
|
||||
#define WDT_COUNT 1
|
||||
|
||||
/* Temperature Sensor */
|
||||
#define TEMP_PRESENT
|
||||
#define TEMP_COUNT 1
|
||||
|
||||
/* Serial Peripheral Interface Master */
|
||||
#define SPI_PRESENT
|
||||
#define SPI_COUNT 3
|
||||
|
||||
/* Serial Peripheral Interface Master with DMA */
|
||||
#define SPIM_PRESENT
|
||||
#define SPIM_COUNT 3
|
||||
|
||||
#define SPIM0_MAX_DATARATE 8
|
||||
#define SPIM1_MAX_DATARATE 8
|
||||
#define SPIM2_MAX_DATARATE 8
|
||||
|
||||
#define SPIM0_FEATURE_HARDWARE_CSN_PRESENT 0
|
||||
#define SPIM1_FEATURE_HARDWARE_CSN_PRESENT 0
|
||||
#define SPIM2_FEATURE_HARDWARE_CSN_PRESENT 0
|
||||
|
||||
#define SPIM0_FEATURE_DCX_PRESENT 0
|
||||
#define SPIM1_FEATURE_DCX_PRESENT 0
|
||||
#define SPIM2_FEATURE_DCX_PRESENT 0
|
||||
|
||||
#define SPIM0_FEATURE_RXDELAY_PRESENT 0
|
||||
#define SPIM1_FEATURE_RXDELAY_PRESENT 0
|
||||
#define SPIM2_FEATURE_RXDELAY_PRESENT 0
|
||||
|
||||
#define SPIM0_EASYDMA_MAXCNT_SIZE 8
|
||||
#define SPIM1_EASYDMA_MAXCNT_SIZE 8
|
||||
#define SPIM2_EASYDMA_MAXCNT_SIZE 8
|
||||
|
||||
/* Serial Peripheral Interface Slave with DMA*/
|
||||
#define SPIS_PRESENT
|
||||
#define SPIS_COUNT 3
|
||||
|
||||
#define SPIS0_EASYDMA_MAXCNT_SIZE 8
|
||||
#define SPIS1_EASYDMA_MAXCNT_SIZE 8
|
||||
#define SPIS2_EASYDMA_MAXCNT_SIZE 8
|
||||
|
||||
/* Two Wire Interface Master */
|
||||
#define TWI_PRESENT
|
||||
#define TWI_COUNT 2
|
||||
|
||||
/* Two Wire Interface Master with DMA */
|
||||
#define TWIM_PRESENT
|
||||
#define TWIM_COUNT 2
|
||||
|
||||
#define TWIM0_EASYDMA_MAXCNT_SIZE 8
|
||||
#define TWIM1_EASYDMA_MAXCNT_SIZE 8
|
||||
|
||||
/* Two Wire Interface Slave with DMA */
|
||||
#define TWIS_PRESENT
|
||||
#define TWIS_COUNT 2
|
||||
|
||||
#define TWIS0_EASYDMA_MAXCNT_SIZE 8
|
||||
#define TWIS1_EASYDMA_MAXCNT_SIZE 8
|
||||
|
||||
/* Universal Asynchronous Receiver-Transmitter */
|
||||
#define UART_PRESENT
|
||||
#define UART_COUNT 1
|
||||
|
||||
/* Universal Asynchronous Receiver-Transmitter with DMA */
|
||||
#define UARTE_PRESENT
|
||||
#define UARTE_COUNT 1
|
||||
|
||||
#define UARTE0_EASYDMA_MAXCNT_SIZE 8
|
||||
|
||||
/* Quadrature Decoder */
|
||||
#define QDEC_PRESENT
|
||||
#define QDEC_COUNT 1
|
||||
|
||||
/* Successive Approximation Analog to Digital Converter */
|
||||
#define SAADC_PRESENT
|
||||
#define SAADC_COUNT 1
|
||||
|
||||
#define SAADC_EASYDMA_MAXCNT_SIZE 15
|
||||
|
||||
#define SAADC_CH_NUM 8
|
||||
|
||||
/* GPIO Tasks and Events */
|
||||
#define GPIOTE_PRESENT
|
||||
#define GPIOTE_COUNT 1
|
||||
|
||||
#define GPIOTE_CH_NUM 8
|
||||
|
||||
#define GPIOTE_FEATURE_SET_PRESENT
|
||||
#define GPIOTE_FEATURE_CLR_PRESENT
|
||||
|
||||
/* Low Power Comparator */
|
||||
#define LPCOMP_PRESENT
|
||||
#define LPCOMP_COUNT 1
|
||||
|
||||
#define LPCOMP_REFSEL_RESOLUTION 16
|
||||
|
||||
#define LPCOMP_FEATURE_HYST_PRESENT
|
||||
|
||||
/* Comparator */
|
||||
#define COMP_PRESENT
|
||||
#define COMP_COUNT 1
|
||||
|
||||
/* Pulse Width Modulator */
|
||||
#define PWM_PRESENT
|
||||
#define PWM_COUNT 3
|
||||
|
||||
#define PWM0_CH_NUM 4
|
||||
#define PWM1_CH_NUM 4
|
||||
#define PWM2_CH_NUM 4
|
||||
|
||||
#define PWM0_EASYDMA_MAXCNT_SIZE 15
|
||||
#define PWM1_EASYDMA_MAXCNT_SIZE 15
|
||||
#define PWM2_EASYDMA_MAXCNT_SIZE 15
|
||||
|
||||
/* Pulse Density Modulator */
|
||||
#define PDM_PRESENT
|
||||
#define PDM_COUNT 1
|
||||
|
||||
#define PDM_EASYDMA_MAXCNT_SIZE 15
|
||||
|
||||
/* Inter-IC Sound Interface */
|
||||
#define I2S_PRESENT
|
||||
#define I2S_COUNT 1
|
||||
|
||||
#define I2S_EASYDMA_MAXCNT_SIZE 14
|
||||
|
||||
|
||||
#endif // _NRF52832_PERIPHERALS_H
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,301 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2010 - 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 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.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, 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 _NRF52840_PERIPHERALS_H
|
||||
#define _NRF52840_PERIPHERALS_H
|
||||
|
||||
|
||||
/* Power Peripheral */
|
||||
#define POWER_PRESENT
|
||||
#define POWER_COUNT 1
|
||||
|
||||
#define POWER_FEATURE_RAM_REGISTERS_PRESENT
|
||||
#define POWER_FEATURE_RAM_REGISTERS_COUNT 9
|
||||
|
||||
#define POWER_FEATURE_VDDH_PRESENT
|
||||
|
||||
/* Floating Point Unit */
|
||||
#define FPU_PRESENT
|
||||
#define FPU_COUNT 1
|
||||
|
||||
/* Systick timer */
|
||||
#define SYSTICK_PRESENT
|
||||
#define SYSTICK_COUNT 1
|
||||
|
||||
/* Software Interrupts */
|
||||
#define SWI_PRESENT
|
||||
#define SWI_COUNT 6
|
||||
|
||||
/* Memory Watch Unit */
|
||||
#define MWU_PRESENT
|
||||
#define MWU_COUNT 1
|
||||
|
||||
/* GPIO */
|
||||
#define GPIO_PRESENT
|
||||
#define GPIO_COUNT 2
|
||||
|
||||
#define P0_PIN_NUM 32
|
||||
#define P1_PIN_NUM 16
|
||||
|
||||
/* ACL */
|
||||
#define ACL_PRESENT
|
||||
|
||||
#define ACL_REGIONS_COUNT 8
|
||||
|
||||
/* Radio */
|
||||
#define RADIO_PRESENT
|
||||
#define RADIO_COUNT 1
|
||||
|
||||
#define RADIO_EASYDMA_MAXCNT_SIZE 8
|
||||
|
||||
/* Accelerated Address Resolver */
|
||||
#define AAR_PRESENT
|
||||
#define AAR_COUNT 1
|
||||
|
||||
#define AAR_MAX_IRK_NUM 16
|
||||
|
||||
/* AES Electronic CodeBook mode encryption */
|
||||
#define ECB_PRESENT
|
||||
#define ECB_COUNT 1
|
||||
|
||||
/* AES CCM mode encryption */
|
||||
#define CCM_PRESENT
|
||||
#define CCM_COUNT 1
|
||||
|
||||
/* NFC Tag */
|
||||
#define NFCT_PRESENT
|
||||
#define NFCT_COUNT 1
|
||||
|
||||
#define NFCT_EASYDMA_MAXCNT_SIZE 9
|
||||
|
||||
/* Peripheral to Peripheral Interconnect */
|
||||
#define PPI_PRESENT
|
||||
#define PPI_COUNT 1
|
||||
|
||||
#define PPI_CH_NUM 20
|
||||
#define PPI_FIXED_CH_NUM 12
|
||||
#define PPI_GROUP_NUM 6
|
||||
#define PPI_FEATURE_FORKS_PRESENT
|
||||
|
||||
/* Event Generator Unit */
|
||||
#define EGU_PRESENT
|
||||
#define EGU_COUNT 6
|
||||
|
||||
#define EGU0_CH_NUM 16
|
||||
#define EGU1_CH_NUM 16
|
||||
#define EGU2_CH_NUM 16
|
||||
#define EGU3_CH_NUM 16
|
||||
#define EGU4_CH_NUM 16
|
||||
#define EGU5_CH_NUM 16
|
||||
|
||||
/* Timer/Counter */
|
||||
#define TIMER_PRESENT
|
||||
#define TIMER_COUNT 5
|
||||
|
||||
#define TIMER0_MAX_SIZE 32
|
||||
#define TIMER1_MAX_SIZE 32
|
||||
#define TIMER2_MAX_SIZE 32
|
||||
#define TIMER3_MAX_SIZE 32
|
||||
#define TIMER4_MAX_SIZE 32
|
||||
|
||||
#define TIMER0_CC_NUM 4
|
||||
#define TIMER1_CC_NUM 4
|
||||
#define TIMER2_CC_NUM 4
|
||||
#define TIMER3_CC_NUM 6
|
||||
#define TIMER4_CC_NUM 6
|
||||
|
||||
/* Real Time Counter */
|
||||
#define RTC_PRESENT
|
||||
#define RTC_COUNT 3
|
||||
|
||||
#define RTC0_CC_NUM 3
|
||||
#define RTC1_CC_NUM 4
|
||||
#define RTC2_CC_NUM 4
|
||||
|
||||
/* RNG */
|
||||
#define RNG_PRESENT
|
||||
#define RNG_COUNT 1
|
||||
|
||||
/* Watchdog Timer */
|
||||
#define WDT_PRESENT
|
||||
#define WDT_COUNT 1
|
||||
|
||||
/* Temperature Sensor */
|
||||
#define TEMP_PRESENT
|
||||
#define TEMP_COUNT 1
|
||||
|
||||
/* Serial Peripheral Interface Master */
|
||||
#define SPI_PRESENT
|
||||
#define SPI_COUNT 3
|
||||
|
||||
/* Serial Peripheral Interface Master with DMA */
|
||||
#define SPIM_PRESENT
|
||||
#define SPIM_COUNT 4
|
||||
|
||||
#define SPIM0_MAX_DATARATE 8
|
||||
#define SPIM1_MAX_DATARATE 8
|
||||
#define SPIM2_MAX_DATARATE 8
|
||||
#define SPIM3_MAX_DATARATE 32
|
||||
|
||||
#define SPIM0_FEATURE_HARDWARE_CSN_PRESENT 0
|
||||
#define SPIM1_FEATURE_HARDWARE_CSN_PRESENT 0
|
||||
#define SPIM2_FEATURE_HARDWARE_CSN_PRESENT 0
|
||||
#define SPIM3_FEATURE_HARDWARE_CSN_PRESENT 1
|
||||
|
||||
#define SPIM0_FEATURE_DCX_PRESENT 0
|
||||
#define SPIM1_FEATURE_DCX_PRESENT 0
|
||||
#define SPIM2_FEATURE_DCX_PRESENT 0
|
||||
#define SPIM3_FEATURE_DCX_PRESENT 1
|
||||
|
||||
#define SPIM0_FEATURE_RXDELAY_PRESENT 0
|
||||
#define SPIM1_FEATURE_RXDELAY_PRESENT 0
|
||||
#define SPIM2_FEATURE_RXDELAY_PRESENT 0
|
||||
#define SPIM3_FEATURE_RXDELAY_PRESENT 1
|
||||
|
||||
#define SPIM0_EASYDMA_MAXCNT_SIZE 16
|
||||
#define SPIM1_EASYDMA_MAXCNT_SIZE 16
|
||||
#define SPIM2_EASYDMA_MAXCNT_SIZE 16
|
||||
#define SPIM3_EASYDMA_MAXCNT_SIZE 16
|
||||
|
||||
/* Serial Peripheral Interface Slave with DMA*/
|
||||
#define SPIS_PRESENT
|
||||
#define SPIS_COUNT 3
|
||||
|
||||
#define SPIS0_EASYDMA_MAXCNT_SIZE 16
|
||||
#define SPIS1_EASYDMA_MAXCNT_SIZE 16
|
||||
#define SPIS2_EASYDMA_MAXCNT_SIZE 16
|
||||
|
||||
/* Two Wire Interface Master */
|
||||
#define TWI_PRESENT
|
||||
#define TWI_COUNT 2
|
||||
|
||||
/* Two Wire Interface Master with DMA */
|
||||
#define TWIM_PRESENT
|
||||
#define TWIM_COUNT 2
|
||||
|
||||
#define TWIM0_EASYDMA_MAXCNT_SIZE 16
|
||||
#define TWIM1_EASYDMA_MAXCNT_SIZE 16
|
||||
|
||||
/* Two Wire Interface Slave with DMA */
|
||||
#define TWIS_PRESENT
|
||||
#define TWIS_COUNT 2
|
||||
|
||||
#define TWIS0_EASYDMA_MAXCNT_SIZE 16
|
||||
#define TWIS1_EASYDMA_MAXCNT_SIZE 16
|
||||
|
||||
/* Universal Asynchronous Receiver-Transmitter */
|
||||
#define UART_PRESENT
|
||||
#define UART_COUNT 1
|
||||
|
||||
/* Universal Asynchronous Receiver-Transmitter with DMA */
|
||||
#define UARTE_PRESENT
|
||||
#define UARTE_COUNT 2
|
||||
|
||||
#define UARTE0_EASYDMA_MAXCNT_SIZE 16
|
||||
#define UARTE1_EASYDMA_MAXCNT_SIZE 16
|
||||
|
||||
/* Quadrature Decoder */
|
||||
#define QDEC_PRESENT
|
||||
#define QDEC_COUNT 1
|
||||
|
||||
/* Successive Approximation Analog to Digital Converter */
|
||||
#define SAADC_PRESENT
|
||||
#define SAADC_COUNT 1
|
||||
|
||||
#define SAADC_EASYDMA_MAXCNT_SIZE 15
|
||||
|
||||
#define SAADC_CH_NUM 8
|
||||
|
||||
/* GPIO Tasks and Events */
|
||||
#define GPIOTE_PRESENT
|
||||
#define GPIOTE_COUNT 1
|
||||
|
||||
#define GPIOTE_CH_NUM 8
|
||||
|
||||
#define GPIOTE_FEATURE_SET_PRESENT
|
||||
#define GPIOTE_FEATURE_CLR_PRESENT
|
||||
|
||||
/* Low Power Comparator */
|
||||
#define LPCOMP_PRESENT
|
||||
#define LPCOMP_COUNT 1
|
||||
|
||||
#define LPCOMP_REFSEL_RESOLUTION 16
|
||||
|
||||
#define LPCOMP_FEATURE_HYST_PRESENT
|
||||
|
||||
/* Comparator */
|
||||
#define COMP_PRESENT
|
||||
#define COMP_COUNT 1
|
||||
|
||||
/* Pulse Width Modulator */
|
||||
#define PWM_PRESENT
|
||||
#define PWM_COUNT 4
|
||||
|
||||
#define PWM0_CH_NUM 4
|
||||
#define PWM1_CH_NUM 4
|
||||
#define PWM2_CH_NUM 4
|
||||
#define PWM3_CH_NUM 4
|
||||
|
||||
#define PWM0_EASYDMA_MAXCNT_SIZE 15
|
||||
#define PWM1_EASYDMA_MAXCNT_SIZE 15
|
||||
#define PWM2_EASYDMA_MAXCNT_SIZE 15
|
||||
#define PWM3_EASYDMA_MAXCNT_SIZE 15
|
||||
|
||||
/* Pulse Density Modulator */
|
||||
#define PDM_PRESENT
|
||||
#define PDM_COUNT 1
|
||||
|
||||
#define PDM_EASYDMA_MAXCNT_SIZE 15
|
||||
|
||||
/* Inter-IC Sound Interface */
|
||||
#define I2S_PRESENT
|
||||
#define I2S_COUNT 1
|
||||
|
||||
#define I2S_EASYDMA_MAXCNT_SIZE 14
|
||||
|
||||
/* Universal Serial Bus Device */
|
||||
#define USBD_PRESENT
|
||||
#define USBD_COUNT 1
|
||||
|
||||
#define USBD_EASYDMA_MAXCNT_SIZE 7
|
||||
|
||||
/* ARM TrustZone Cryptocell 310 */
|
||||
#define CRYPTOCELL_PRESENT
|
||||
#define CRYPTOCELL_COUNT 1
|
||||
|
||||
/* Quad SPI */
|
||||
#define QSPI_PRESENT
|
||||
#define QSPI_COUNT 1
|
||||
|
||||
#define QSPI_EASYDMA_MAXCNT_SIZE 20
|
||||
|
||||
#endif // _NRF52840_PERIPHERALS_H
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2010 - 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 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.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, 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 NRF52_NAME_CHANGE_H
|
||||
#define NRF52_NAME_CHANGE_H
|
||||
|
||||
/*lint ++flb "Enter library region */
|
||||
|
||||
/* This file is given to prevent your SW from not compiling with the updates made to nrf52.h and
|
||||
* nrf52_bitfields.h. The macros defined in this file were available previously. Do not use these
|
||||
* macros on purpose. Use the ones defined in nrf52.h and nrf52_bitfields.h instead.
|
||||
*/
|
||||
|
||||
/* I2S */
|
||||
/* Several enumerations changed case. Adding old macros to keep compilation compatibility. */
|
||||
#define I2S_ENABLE_ENABLE_DISABLE I2S_ENABLE_ENABLE_Disabled
|
||||
#define I2S_ENABLE_ENABLE_ENABLE I2S_ENABLE_ENABLE_Enabled
|
||||
#define I2S_CONFIG_MODE_MODE_MASTER I2S_CONFIG_MODE_MODE_Master
|
||||
#define I2S_CONFIG_MODE_MODE_SLAVE I2S_CONFIG_MODE_MODE_Slave
|
||||
#define I2S_CONFIG_RXEN_RXEN_DISABLE I2S_CONFIG_RXEN_RXEN_Disabled
|
||||
#define I2S_CONFIG_RXEN_RXEN_ENABLE I2S_CONFIG_RXEN_RXEN_Enabled
|
||||
#define I2S_CONFIG_TXEN_TXEN_DISABLE I2S_CONFIG_TXEN_TXEN_Disabled
|
||||
#define I2S_CONFIG_TXEN_TXEN_ENABLE I2S_CONFIG_TXEN_TXEN_Enabled
|
||||
#define I2S_CONFIG_MCKEN_MCKEN_DISABLE I2S_CONFIG_MCKEN_MCKEN_Disabled
|
||||
#define I2S_CONFIG_MCKEN_MCKEN_ENABLE I2S_CONFIG_MCKEN_MCKEN_Enabled
|
||||
#define I2S_CONFIG_SWIDTH_SWIDTH_8BIT I2S_CONFIG_SWIDTH_SWIDTH_8Bit
|
||||
#define I2S_CONFIG_SWIDTH_SWIDTH_16BIT I2S_CONFIG_SWIDTH_SWIDTH_16Bit
|
||||
#define I2S_CONFIG_SWIDTH_SWIDTH_24BIT I2S_CONFIG_SWIDTH_SWIDTH_24Bit
|
||||
#define I2S_CONFIG_ALIGN_ALIGN_LEFT I2S_CONFIG_ALIGN_ALIGN_Left
|
||||
#define I2S_CONFIG_ALIGN_ALIGN_RIGHT I2S_CONFIG_ALIGN_ALIGN_Right
|
||||
#define I2S_CONFIG_FORMAT_FORMAT_ALIGNED I2S_CONFIG_FORMAT_FORMAT_Aligned
|
||||
#define I2S_CONFIG_CHANNELS_CHANNELS_STEREO I2S_CONFIG_CHANNELS_CHANNELS_Stereo
|
||||
#define I2S_CONFIG_CHANNELS_CHANNELS_LEFT I2S_CONFIG_CHANNELS_CHANNELS_Left
|
||||
#define I2S_CONFIG_CHANNELS_CHANNELS_RIGHT I2S_CONFIG_CHANNELS_CHANNELS_Right
|
||||
|
||||
/* LPCOMP */
|
||||
/* Corrected typo in RESULT register. */
|
||||
#define LPCOMP_RESULT_RESULT_Bellow LPCOMP_RESULT_RESULT_Below
|
||||
|
||||
/*lint --flb "Leave library region" */
|
||||
|
||||
#endif /* NRF52_NAME_CHANGE_H */
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2010 - 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 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.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, 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 NRF52_TO_NRF52810_H
|
||||
#define NRF52_TO_NRF52810_H
|
||||
|
||||
/*lint ++flb "Enter library region */
|
||||
|
||||
/* This file is given to prevent your SW from not compiling with the name changes between nRF51 or nRF52832 and nRF52810 devices.
|
||||
* It redefines the old nRF51 or nRF52832 names into the new ones as long as the functionality is still supported. If the
|
||||
* functionality is gone, there old names are not defined, so compilation will fail. Note that also includes macros
|
||||
* from the nrf52_namechange.h file. */
|
||||
|
||||
/* Differences between latest nRF52 headers and nRF52810 headers. */
|
||||
|
||||
/* Interrupt service routines handlers. Note that handlers SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler and
|
||||
SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler are not redefined since functionality is not equivalent. */
|
||||
#define UARTE0_UART0_IRQHandler UARTE0_IRQHandler
|
||||
#define COMP_LPCOMP_IRQHandler COMP_IRQHandler
|
||||
#define SWI2_EGU2_IRQHandler SWI2_IRQHandler
|
||||
#define SWI3_EGU3_IRQHandler SWI3_IRQHandler
|
||||
#define SWI4_EGU4_IRQHandler SWI4_IRQHandler
|
||||
#define SWI5_EGU5_IRQHandler SWI5_IRQHandler
|
||||
|
||||
/* Interrupt service routines index. Note that indexes SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn and
|
||||
SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn are not redefined since functionality is not equivalent. */
|
||||
#define UARTE0_UART0_IRQn UARTE0_IRQn
|
||||
#define COMP_LPCOMP_IRQn COMP_IRQn
|
||||
#define SWI2_EGU2_IRQn SWI2_IRQn
|
||||
#define SWI3_EGU3_IRQn SWI3_IRQn
|
||||
#define SWI4_EGU4_IRQn SWI4_IRQn
|
||||
#define SWI5_EGU5_IRQn SWI5_IRQn
|
||||
|
||||
|
||||
/* From nrf52_name_change.h. Several macros changed in different versions of nRF52 headers. By defining the following, any code written for any version of nRF52 headers will still compile. */
|
||||
|
||||
/* I2S */
|
||||
/* Several enumerations changed case. Adding old macros to keep compilation compatibility. */
|
||||
#define I2S_ENABLE_ENABLE_DISABLE I2S_ENABLE_ENABLE_Disabled
|
||||
#define I2S_ENABLE_ENABLE_ENABLE I2S_ENABLE_ENABLE_Enabled
|
||||
#define I2S_CONFIG_MODE_MODE_MASTER I2S_CONFIG_MODE_MODE_Master
|
||||
#define I2S_CONFIG_MODE_MODE_SLAVE I2S_CONFIG_MODE_MODE_Slave
|
||||
#define I2S_CONFIG_RXEN_RXEN_DISABLE I2S_CONFIG_RXEN_RXEN_Disabled
|
||||
#define I2S_CONFIG_RXEN_RXEN_ENABLE I2S_CONFIG_RXEN_RXEN_Enabled
|
||||
#define I2S_CONFIG_TXEN_TXEN_DISABLE I2S_CONFIG_TXEN_TXEN_Disabled
|
||||
#define I2S_CONFIG_TXEN_TXEN_ENABLE I2S_CONFIG_TXEN_TXEN_Enabled
|
||||
#define I2S_CONFIG_MCKEN_MCKEN_DISABLE I2S_CONFIG_MCKEN_MCKEN_Disabled
|
||||
#define I2S_CONFIG_MCKEN_MCKEN_ENABLE I2S_CONFIG_MCKEN_MCKEN_Enabled
|
||||
#define I2S_CONFIG_SWIDTH_SWIDTH_8BIT I2S_CONFIG_SWIDTH_SWIDTH_8Bit
|
||||
#define I2S_CONFIG_SWIDTH_SWIDTH_16BIT I2S_CONFIG_SWIDTH_SWIDTH_16Bit
|
||||
#define I2S_CONFIG_SWIDTH_SWIDTH_24BIT I2S_CONFIG_SWIDTH_SWIDTH_24Bit
|
||||
#define I2S_CONFIG_ALIGN_ALIGN_LEFT I2S_CONFIG_ALIGN_ALIGN_Left
|
||||
#define I2S_CONFIG_ALIGN_ALIGN_RIGHT I2S_CONFIG_ALIGN_ALIGN_Right
|
||||
#define I2S_CONFIG_FORMAT_FORMAT_ALIGNED I2S_CONFIG_FORMAT_FORMAT_Aligned
|
||||
#define I2S_CONFIG_CHANNELS_CHANNELS_STEREO I2S_CONFIG_CHANNELS_CHANNELS_Stereo
|
||||
#define I2S_CONFIG_CHANNELS_CHANNELS_LEFT I2S_CONFIG_CHANNELS_CHANNELS_Left
|
||||
#define I2S_CONFIG_CHANNELS_CHANNELS_RIGHT I2S_CONFIG_CHANNELS_CHANNELS_Right
|
||||
|
||||
/* LPCOMP */
|
||||
/* Corrected typo in RESULT register. */
|
||||
#define LPCOMP_RESULT_RESULT_Bellow LPCOMP_RESULT_RESULT_Below
|
||||
|
||||
|
||||
/*lint --flb "Leave library region" */
|
||||
|
||||
#endif /* NRF51_TO_NRF52810_H */
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2010 - 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 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.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, 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 NRF52_TO_NRF52840_H
|
||||
#define NRF52_TO_NRF52840_H
|
||||
|
||||
/*lint ++flb "Enter library region */
|
||||
|
||||
/* This file is given to prevent your SW from not compiling with the name changes between nRF51 or nRF52832 and nRF52840 devices.
|
||||
* It redefines the old nRF51 or nRF52832 names into the new ones as long as the functionality is still supported. If the
|
||||
* functionality is gone, there old names are not defined, so compilation will fail. Note that also includes macros
|
||||
* from the nrf52_namechange.h file. */
|
||||
|
||||
/* Differences between latest nRF52 headers and nRF52840 headers. */
|
||||
|
||||
/* UART */
|
||||
/* The registers PSELRTS, PSELTXD, PSELCTS, PSELRXD were restructured into a struct. */
|
||||
#define PSELRTS PSEL.RTS
|
||||
#define PSELTXD PSEL.TXD
|
||||
#define PSELCTS PSEL.CTS
|
||||
#define PSELRXD PSEL.RXD
|
||||
|
||||
/* TWI */
|
||||
/* The registers PSELSCL, PSELSDA were restructured into a struct. */
|
||||
#define PSELSCL PSEL.SCL
|
||||
#define PSELSDA PSEL.SDA
|
||||
|
||||
|
||||
/* LPCOMP */
|
||||
/* The hysteresis control enumerated values has changed name for nRF52840 devices. */
|
||||
#define LPCOMP_HYST_HYST_NoHyst LPCOMP_HYST_HYST_Disabled
|
||||
#define LPCOMP_HYST_HYST_Hyst50mV LPCOMP_HYST_HYST_Enabled
|
||||
|
||||
|
||||
/* From nrf52_name_change.h. Several macros changed in different versions of nRF52 headers. By defining the following, any code written for any version of nRF52 headers will still compile. */
|
||||
|
||||
/* I2S */
|
||||
/* Several enumerations changed case. Adding old macros to keep compilation compatibility. */
|
||||
#define I2S_ENABLE_ENABLE_DISABLE I2S_ENABLE_ENABLE_Disabled
|
||||
#define I2S_ENABLE_ENABLE_ENABLE I2S_ENABLE_ENABLE_Enabled
|
||||
#define I2S_CONFIG_MODE_MODE_MASTER I2S_CONFIG_MODE_MODE_Master
|
||||
#define I2S_CONFIG_MODE_MODE_SLAVE I2S_CONFIG_MODE_MODE_Slave
|
||||
#define I2S_CONFIG_RXEN_RXEN_DISABLE I2S_CONFIG_RXEN_RXEN_Disabled
|
||||
#define I2S_CONFIG_RXEN_RXEN_ENABLE I2S_CONFIG_RXEN_RXEN_Enabled
|
||||
#define I2S_CONFIG_TXEN_TXEN_DISABLE I2S_CONFIG_TXEN_TXEN_Disabled
|
||||
#define I2S_CONFIG_TXEN_TXEN_ENABLE I2S_CONFIG_TXEN_TXEN_Enabled
|
||||
#define I2S_CONFIG_MCKEN_MCKEN_DISABLE I2S_CONFIG_MCKEN_MCKEN_Disabled
|
||||
#define I2S_CONFIG_MCKEN_MCKEN_ENABLE I2S_CONFIG_MCKEN_MCKEN_Enabled
|
||||
#define I2S_CONFIG_SWIDTH_SWIDTH_8BIT I2S_CONFIG_SWIDTH_SWIDTH_8Bit
|
||||
#define I2S_CONFIG_SWIDTH_SWIDTH_16BIT I2S_CONFIG_SWIDTH_SWIDTH_16Bit
|
||||
#define I2S_CONFIG_SWIDTH_SWIDTH_24BIT I2S_CONFIG_SWIDTH_SWIDTH_24Bit
|
||||
#define I2S_CONFIG_ALIGN_ALIGN_LEFT I2S_CONFIG_ALIGN_ALIGN_Left
|
||||
#define I2S_CONFIG_ALIGN_ALIGN_RIGHT I2S_CONFIG_ALIGN_ALIGN_Right
|
||||
#define I2S_CONFIG_FORMAT_FORMAT_ALIGNED I2S_CONFIG_FORMAT_FORMAT_Aligned
|
||||
#define I2S_CONFIG_CHANNELS_CHANNELS_STEREO I2S_CONFIG_CHANNELS_CHANNELS_Stereo
|
||||
#define I2S_CONFIG_CHANNELS_CHANNELS_LEFT I2S_CONFIG_CHANNELS_CHANNELS_Left
|
||||
#define I2S_CONFIG_CHANNELS_CHANNELS_RIGHT I2S_CONFIG_CHANNELS_CHANNELS_Right
|
||||
|
||||
/* LPCOMP */
|
||||
/* Corrected typo in RESULT register. */
|
||||
#define LPCOMP_RESULT_RESULT_Bellow LPCOMP_RESULT_RESULT_Below
|
||||
|
||||
|
||||
/*lint --flb "Leave library region" */
|
||||
|
||||
#endif /* NRF51_TO_NRF52840_H */
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2010 - 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 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.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, 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_PERIPHERALS_H__
|
||||
#define NRF_PERIPHERALS_H__
|
||||
|
||||
/*lint ++flb "Enter library region */
|
||||
|
||||
#if defined(_WIN32)
|
||||
/* Do not include nrf specific files when building for PC host */
|
||||
#elif defined(__unix)
|
||||
/* Do not include nrf specific files when building for PC host */
|
||||
#elif defined(__APPLE__)
|
||||
/* Do not include nrf specific files when building for PC host */
|
||||
#else
|
||||
|
||||
#if defined(NRF51)
|
||||
#include "nrf51_peripherals.h"
|
||||
|
||||
#elif defined(NRF52810_XXAA)
|
||||
#include "nrf52810_peripherals.h"
|
||||
#elif defined(NRF52832_XXAA) || defined(NRF52832_XXAB)
|
||||
#include "nrf52832_peripherals.h"
|
||||
#elif defined(NRF52840_XXAA)
|
||||
#include "nrf52840_peripherals.h"
|
||||
|
||||
#else
|
||||
#error "Device must be defined. See nrf.h."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*lint --flb "Leave library region" */
|
||||
|
||||
#endif // NRF_PERIPHERALS_H__
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2010 - 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 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.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, 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.
|
||||
|
||||
*/
|
||||
|
||||
/* Configure stack size, stack alignement and heap size with a header file instead of project settings or modification of Nordic provided assembler files. Modify this file as needed. */
|
||||
|
||||
/* In order to make use this file,
|
||||
1. For Keil uVision IDE, in the Options for Target -> Asm tab, define symbol __STARTUP_CONFIG and use the additional assembler option --cpreproc in Misc Control text box.
|
||||
2. For GCC compiling, add extra assembly option -D__STARTUP_CONFIG.
|
||||
3. For IAR Embedded Workbench define symbol __STARTUP_CONFIG in the Assembler options and define symbol __STARTUP_CONFIG=1 in the linker options.
|
||||
*/
|
||||
|
||||
/* This file is a template and should be copied to the project directory. */
|
||||
|
||||
/* Define size of stack. Size must be multiple of 4. */
|
||||
#define __STARTUP_CONFIG_STACK_SIZE 0x1000
|
||||
|
||||
/* Define alignement of stack. Alignment will be 2 to the power of __STARTUP_CONFIG_STACK_ALIGNEMENT. Since calling convention requires that the stack is aligned to 8-bytes when a function is called, the minimum __STARTUP_CONFIG_STACK_ALIGNEMENT is therefore 3. */
|
||||
#define __STARTUP_CONFIG_STACK_ALIGNEMENT 3
|
||||
|
||||
/* Define size of heap. Size must be multiple of 4. */
|
||||
#define __STARTUP_CONFIG_HEAP_SIZE 0x1000
|
||||
|
||||
@@ -0,0 +1,377 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2009-2018 ARM Limited. All rights reserved.
|
||||
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
NOTICE: This file has been modified by Nordic Semiconductor ASA.
|
||||
|
||||
*/
|
||||
|
||||
#ifdef NRF52832_XXAA
|
||||
|
||||
/* NOTE: Template files (including this one) are application specific and therefore expected to
|
||||
be copied into the application project folder prior to its use! */
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "nrf.h"
|
||||
#include "system_nrf52.h"
|
||||
|
||||
/*lint ++flb "Enter library region" */
|
||||
|
||||
#define __SYSTEM_CLOCK_64M (64000000UL)
|
||||
|
||||
static bool errata_12(void);
|
||||
static bool errata_16(void);
|
||||
static bool errata_31(void);
|
||||
static bool errata_32(void);
|
||||
static bool errata_36(void);
|
||||
static bool errata_37(void);
|
||||
static bool errata_57(void);
|
||||
static bool errata_66(void);
|
||||
static bool errata_108(void);
|
||||
static bool errata_136(void);
|
||||
static bool errata_182(void);
|
||||
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK_64M;
|
||||
#elif defined ( __ICCARM__ )
|
||||
__root uint32_t SystemCoreClock = __SYSTEM_CLOCK_64M;
|
||||
#elif defined ( __GNUC__ )
|
||||
uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK_64M;
|
||||
#endif
|
||||
|
||||
void SystemCoreClockUpdate(void)
|
||||
{
|
||||
SystemCoreClock = __SYSTEM_CLOCK_64M;
|
||||
}
|
||||
|
||||
void SystemInit(void)
|
||||
{
|
||||
/* Enable SWO trace functionality. If ENABLE_SWO is not defined, SWO pin will be used as GPIO (see Product
|
||||
Specification to see which one). */
|
||||
#if defined (ENABLE_SWO)
|
||||
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
||||
NRF_CLOCK->TRACECONFIG |= CLOCK_TRACECONFIG_TRACEMUX_Serial << CLOCK_TRACECONFIG_TRACEMUX_Pos;
|
||||
NRF_P0->PIN_CNF[18] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
|
||||
#endif
|
||||
|
||||
/* Enable Trace functionality. If ENABLE_TRACE is not defined, TRACE pins will be used as GPIOs (see Product
|
||||
Specification to see which ones). */
|
||||
#if defined (ENABLE_TRACE)
|
||||
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
||||
NRF_CLOCK->TRACECONFIG |= CLOCK_TRACECONFIG_TRACEMUX_Parallel << CLOCK_TRACECONFIG_TRACEMUX_Pos;
|
||||
NRF_P0->PIN_CNF[14] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
|
||||
NRF_P0->PIN_CNF[15] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
|
||||
NRF_P0->PIN_CNF[16] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
|
||||
NRF_P0->PIN_CNF[18] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
|
||||
NRF_P0->PIN_CNF[20] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
|
||||
#endif
|
||||
|
||||
/* Workaround for Errata 12 "COMP: Reference ladder not correctly calibrated" found at the Errata document
|
||||
for your device located at https://infocenter.nordicsemi.com/ */
|
||||
if (errata_12()){
|
||||
*(volatile uint32_t *)0x40013540 = (*(uint32_t *)0x10000324 & 0x00001F00) >> 8;
|
||||
}
|
||||
|
||||
/* Workaround for Errata 16 "System: RAM may be corrupt on wakeup from CPU IDLE" found at the Errata document
|
||||
for your device located at https://infocenter.nordicsemi.com/ */
|
||||
if (errata_16()){
|
||||
*(volatile uint32_t *)0x4007C074 = 3131961357ul;
|
||||
}
|
||||
|
||||
/* Workaround for Errata 31 "CLOCK: Calibration values are not correctly loaded from FICR at reset" found at the Errata document
|
||||
for your device located at https://infocenter.nordicsemi.com/ */
|
||||
if (errata_31()){
|
||||
*(volatile uint32_t *)0x4000053C = ((*(volatile uint32_t *)0x10000244) & 0x0000E000) >> 13;
|
||||
}
|
||||
|
||||
/* Workaround for Errata 32 "DIF: Debug session automatically enables TracePort pins" found at the Errata document
|
||||
for your device located at https://infocenter.nordicsemi.com/ */
|
||||
if (errata_32()){
|
||||
CoreDebug->DEMCR &= ~CoreDebug_DEMCR_TRCENA_Msk;
|
||||
}
|
||||
|
||||
/* Workaround for Errata 36 "CLOCK: Some registers are not reset when expected" found at the Errata document
|
||||
for your device located at https://infocenter.nordicsemi.com/ */
|
||||
if (errata_36()){
|
||||
NRF_CLOCK->EVENTS_DONE = 0;
|
||||
NRF_CLOCK->EVENTS_CTTO = 0;
|
||||
NRF_CLOCK->CTIV = 0;
|
||||
}
|
||||
|
||||
/* Workaround for Errata 37 "RADIO: Encryption engine is slow by default" found at the Errata document
|
||||
for your device located at https://infocenter.nordicsemi.com/ */
|
||||
if (errata_37()){
|
||||
*(volatile uint32_t *)0x400005A0 = 0x3;
|
||||
}
|
||||
|
||||
/* Workaround for Errata 57 "NFCT: NFC Modulation amplitude" found at the Errata document
|
||||
for your device located at https://infocenter.nordicsemi.com/ */
|
||||
if (errata_57()){
|
||||
*(volatile uint32_t *)0x40005610 = 0x00000005;
|
||||
*(volatile uint32_t *)0x40005688 = 0x00000001;
|
||||
*(volatile uint32_t *)0x40005618 = 0x00000000;
|
||||
*(volatile uint32_t *)0x40005614 = 0x0000003F;
|
||||
}
|
||||
|
||||
/* Workaround for Errata 66 "TEMP: Linearity specification not met with default settings" found at the Errata document
|
||||
for your device located at https://infocenter.nordicsemi.com/ */
|
||||
if (errata_66()){
|
||||
NRF_TEMP->A0 = NRF_FICR->TEMP.A0;
|
||||
NRF_TEMP->A1 = NRF_FICR->TEMP.A1;
|
||||
NRF_TEMP->A2 = NRF_FICR->TEMP.A2;
|
||||
NRF_TEMP->A3 = NRF_FICR->TEMP.A3;
|
||||
NRF_TEMP->A4 = NRF_FICR->TEMP.A4;
|
||||
NRF_TEMP->A5 = NRF_FICR->TEMP.A5;
|
||||
NRF_TEMP->B0 = NRF_FICR->TEMP.B0;
|
||||
NRF_TEMP->B1 = NRF_FICR->TEMP.B1;
|
||||
NRF_TEMP->B2 = NRF_FICR->TEMP.B2;
|
||||
NRF_TEMP->B3 = NRF_FICR->TEMP.B3;
|
||||
NRF_TEMP->B4 = NRF_FICR->TEMP.B4;
|
||||
NRF_TEMP->B5 = NRF_FICR->TEMP.B5;
|
||||
NRF_TEMP->T0 = NRF_FICR->TEMP.T0;
|
||||
NRF_TEMP->T1 = NRF_FICR->TEMP.T1;
|
||||
NRF_TEMP->T2 = NRF_FICR->TEMP.T2;
|
||||
NRF_TEMP->T3 = NRF_FICR->TEMP.T3;
|
||||
NRF_TEMP->T4 = NRF_FICR->TEMP.T4;
|
||||
}
|
||||
|
||||
/* Workaround for Errata 108 "RAM: RAM content cannot be trusted upon waking up from System ON Idle or System OFF mode" found at the Errata document
|
||||
for your device located at https://infocenter.nordicsemi.com/ */
|
||||
if (errata_108()){
|
||||
*(volatile uint32_t *)0x40000EE4 = *(volatile uint32_t *)0x10000258 & 0x0000004F;
|
||||
}
|
||||
|
||||
/* Workaround for Errata 136 "System: Bits in RESETREAS are set when they should not be" found at the Errata document
|
||||
for your device located at https://infocenter.nordicsemi.com/ */
|
||||
if (errata_136()){
|
||||
if (NRF_POWER->RESETREAS & POWER_RESETREAS_RESETPIN_Msk){
|
||||
NRF_POWER->RESETREAS = ~POWER_RESETREAS_RESETPIN_Msk;
|
||||
}
|
||||
}
|
||||
|
||||
/* Workaround for Errata 182 "RADIO: Fixes for anomalies #102, #106, and #107 do not take effect" found at the Errata document
|
||||
for your device located at https://infocenter.nordicsemi.com/ */
|
||||
if (errata_182()){
|
||||
*(volatile uint32_t *) 0x4000173C |= (0x1 << 10);
|
||||
}
|
||||
|
||||
/* Enable the FPU if the compiler used floating point unit instructions. __FPU_USED is a MACRO defined by the
|
||||
* compiler. Since the FPU consumes energy, remember to disable FPU use in the compiler if floating point unit
|
||||
* operations are not used in your code. */
|
||||
#if (__FPU_USED == 1)
|
||||
SCB->CPACR |= (3UL << 20) | (3UL << 22);
|
||||
__DSB();
|
||||
__ISB();
|
||||
#endif
|
||||
|
||||
/* Configure NFCT pins as GPIOs if NFCT is not to be used in your code. If CONFIG_NFCT_PINS_AS_GPIOS is not defined,
|
||||
two GPIOs (see Product Specification to see which ones) will be reserved for NFC and will not be available as
|
||||
normal GPIOs. */
|
||||
#if defined (CONFIG_NFCT_PINS_AS_GPIOS)
|
||||
if ((NRF_UICR->NFCPINS & UICR_NFCPINS_PROTECT_Msk) == (UICR_NFCPINS_PROTECT_NFC << UICR_NFCPINS_PROTECT_Pos)){
|
||||
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
|
||||
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
|
||||
NRF_UICR->NFCPINS &= ~UICR_NFCPINS_PROTECT_Msk;
|
||||
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
|
||||
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
|
||||
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Configure GPIO pads as pPin Reset pin if Pin Reset capabilities desired. If CONFIG_GPIO_AS_PINRESET is not
|
||||
defined, pin reset will not be available. One GPIO (see Product Specification to see which one) will then be
|
||||
reserved for PinReset and not available as normal GPIO. */
|
||||
#if defined (CONFIG_GPIO_AS_PINRESET)
|
||||
if (((NRF_UICR->PSELRESET[0] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos)) ||
|
||||
((NRF_UICR->PSELRESET[1] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos))){
|
||||
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
|
||||
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
|
||||
NRF_UICR->PSELRESET[0] = 21;
|
||||
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
|
||||
NRF_UICR->PSELRESET[1] = 21;
|
||||
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
|
||||
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
|
||||
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
#endif
|
||||
|
||||
SystemCoreClockUpdate();
|
||||
}
|
||||
|
||||
|
||||
static bool errata_12(void)
|
||||
{
|
||||
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)){
|
||||
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30){
|
||||
return true;
|
||||
}
|
||||
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x40){
|
||||
return true;
|
||||
}
|
||||
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x50){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool errata_16(void)
|
||||
{
|
||||
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)){
|
||||
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool errata_31(void)
|
||||
{
|
||||
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)){
|
||||
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30){
|
||||
return true;
|
||||
}
|
||||
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x40){
|
||||
return true;
|
||||
}
|
||||
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x50){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool errata_32(void)
|
||||
{
|
||||
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)){
|
||||
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool errata_36(void)
|
||||
{
|
||||
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)){
|
||||
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30){
|
||||
return true;
|
||||
}
|
||||
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x40){
|
||||
return true;
|
||||
}
|
||||
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x50){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool errata_37(void)
|
||||
{
|
||||
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)){
|
||||
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool errata_57(void)
|
||||
{
|
||||
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)){
|
||||
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool errata_66(void)
|
||||
{
|
||||
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)){
|
||||
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x50){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static bool errata_108(void)
|
||||
{
|
||||
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)){
|
||||
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30){
|
||||
return true;
|
||||
}
|
||||
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x40){
|
||||
return true;
|
||||
}
|
||||
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x50){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static bool errata_136(void)
|
||||
{
|
||||
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)){
|
||||
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30){
|
||||
return true;
|
||||
}
|
||||
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x40){
|
||||
return true;
|
||||
}
|
||||
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x50){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static bool errata_182(void)
|
||||
{
|
||||
if (*(uint32_t *)0x10000130ul == 0x6ul){
|
||||
if (*(uint32_t *)0x10000134ul == 0x6ul){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*lint --flb "Leave library region" */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2009-2018 ARM Limited. All rights reserved.
|
||||
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
NOTICE: This file has been modified by Nordic Semiconductor ASA.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef SYSTEM_NRF52_H
|
||||
#define SYSTEM_NRF52_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */
|
||||
|
||||
/**
|
||||
* Initialize the system
|
||||
*
|
||||
* @param none
|
||||
* @return none
|
||||
*
|
||||
* @brief Setup the microcontroller system.
|
||||
* Initialize the System and update the SystemCoreClock variable.
|
||||
*/
|
||||
extern void SystemInit (void);
|
||||
|
||||
/**
|
||||
* Update SystemCoreClock variable
|
||||
*
|
||||
* @param none
|
||||
* @return none
|
||||
*
|
||||
* @brief Updates the SystemCoreClock with current core Clock
|
||||
* retrieved from cpu registers.
|
||||
*/
|
||||
extern void SystemCoreClockUpdate (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SYSTEM_NRF52_H */
|
||||
Loaded 100 of 111 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user