The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
TARGET_SDT51822B/TOOLCHAIN_IAR/nrf_saadc.h@172:65be27845400, 2019-02-20 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Feb 20 20:53:29 2019 +0000
- Revision:
- 172:65be27845400
- Parent:
- 171:3a7713b1edbc
mbed library release version 165
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 143:86740a56073b | 1 | /* |
AnnaBridge | 143:86740a56073b | 2 | * Copyright (c) 2015 Nordic Semiconductor ASA |
AnnaBridge | 143:86740a56073b | 3 | * All rights reserved. |
AnnaBridge | 143:86740a56073b | 4 | * |
AnnaBridge | 143:86740a56073b | 5 | * Redistribution and use in source and binary forms, with or without modification, |
AnnaBridge | 143:86740a56073b | 6 | * are permitted provided that the following conditions are met: |
AnnaBridge | 143:86740a56073b | 7 | * |
AnnaBridge | 143:86740a56073b | 8 | * 1. Redistributions of source code must retain the above copyright notice, this list |
AnnaBridge | 143:86740a56073b | 9 | * of conditions and the following disclaimer. |
AnnaBridge | 143:86740a56073b | 10 | * |
AnnaBridge | 143:86740a56073b | 11 | * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA |
AnnaBridge | 143:86740a56073b | 12 | * integrated circuit in a product or a software update for such product, must reproduce |
AnnaBridge | 143:86740a56073b | 13 | * the above copyright notice, this list of conditions and the following disclaimer in |
AnnaBridge | 143:86740a56073b | 14 | * the documentation and/or other materials provided with the distribution. |
AnnaBridge | 143:86740a56073b | 15 | * |
AnnaBridge | 143:86740a56073b | 16 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be |
AnnaBridge | 143:86740a56073b | 17 | * used to endorse or promote products derived from this software without specific prior |
AnnaBridge | 143:86740a56073b | 18 | * written permission. |
AnnaBridge | 143:86740a56073b | 19 | * |
AnnaBridge | 143:86740a56073b | 20 | * 4. This software, with or without modification, must only be used with a |
AnnaBridge | 143:86740a56073b | 21 | * Nordic Semiconductor ASA integrated circuit. |
AnnaBridge | 143:86740a56073b | 22 | * |
AnnaBridge | 143:86740a56073b | 23 | * 5. Any software provided in binary or object form under this license must not be reverse |
AnnaBridge | 143:86740a56073b | 24 | * engineered, decompiled, modified and/or disassembled. |
AnnaBridge | 143:86740a56073b | 25 | * |
AnnaBridge | 143:86740a56073b | 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
AnnaBridge | 143:86740a56073b | 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
AnnaBridge | 143:86740a56073b | 28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
AnnaBridge | 143:86740a56073b | 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
AnnaBridge | 143:86740a56073b | 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
AnnaBridge | 143:86740a56073b | 31 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
AnnaBridge | 143:86740a56073b | 32 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
AnnaBridge | 143:86740a56073b | 33 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
AnnaBridge | 143:86740a56073b | 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
AnnaBridge | 143:86740a56073b | 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
AnnaBridge | 143:86740a56073b | 36 | * |
AnnaBridge | 143:86740a56073b | 37 | */ |
AnnaBridge | 143:86740a56073b | 38 | |
AnnaBridge | 143:86740a56073b | 39 | |
AnnaBridge | 143:86740a56073b | 40 | |
AnnaBridge | 143:86740a56073b | 41 | #ifndef NRF_SAADC_H_ |
AnnaBridge | 143:86740a56073b | 42 | #define NRF_SAADC_H_ |
AnnaBridge | 143:86740a56073b | 43 | |
AnnaBridge | 143:86740a56073b | 44 | #ifdef NRF52 |
AnnaBridge | 143:86740a56073b | 45 | |
AnnaBridge | 143:86740a56073b | 46 | /** |
AnnaBridge | 143:86740a56073b | 47 | * @defgroup nrf_saadc_hal SAADC HAL |
AnnaBridge | 143:86740a56073b | 48 | * @{ |
AnnaBridge | 143:86740a56073b | 49 | * @ingroup nrf_saadc |
AnnaBridge | 143:86740a56073b | 50 | * |
AnnaBridge | 143:86740a56073b | 51 | * @brief @tagAPI52 Hardware access layer for accessing the SAADC peripheral. |
AnnaBridge | 143:86740a56073b | 52 | */ |
AnnaBridge | 143:86740a56073b | 53 | |
AnnaBridge | 143:86740a56073b | 54 | #include <stdbool.h> |
AnnaBridge | 143:86740a56073b | 55 | #include <stddef.h> |
AnnaBridge | 143:86740a56073b | 56 | #include "nrf.h" |
AnnaBridge | 143:86740a56073b | 57 | #include "nrf_assert.h" |
AnnaBridge | 143:86740a56073b | 58 | |
AnnaBridge | 143:86740a56073b | 59 | |
AnnaBridge | 143:86740a56073b | 60 | |
AnnaBridge | 143:86740a56073b | 61 | #define NRF_SAADC_CHANNEL_COUNT 8 |
AnnaBridge | 143:86740a56073b | 62 | |
AnnaBridge | 143:86740a56073b | 63 | /** |
AnnaBridge | 143:86740a56073b | 64 | * @brief Resolution of the analog-to-digital converter. |
AnnaBridge | 143:86740a56073b | 65 | */ |
AnnaBridge | 143:86740a56073b | 66 | typedef enum |
AnnaBridge | 143:86740a56073b | 67 | { |
AnnaBridge | 143:86740a56073b | 68 | NRF_SAADC_RESOLUTION_8BIT = SAADC_RESOLUTION_VAL_8bit, ///< 8 bit resolution. |
AnnaBridge | 143:86740a56073b | 69 | NRF_SAADC_RESOLUTION_10BIT = SAADC_RESOLUTION_VAL_10bit, ///< 10 bit resolution. |
AnnaBridge | 143:86740a56073b | 70 | NRF_SAADC_RESOLUTION_12BIT = SAADC_RESOLUTION_VAL_12bit, ///< 12 bit resolution. |
AnnaBridge | 143:86740a56073b | 71 | NRF_SAADC_RESOLUTION_14BIT = SAADC_RESOLUTION_VAL_14bit ///< 14 bit resolution. |
AnnaBridge | 143:86740a56073b | 72 | } nrf_saadc_resolution_t; |
AnnaBridge | 143:86740a56073b | 73 | |
AnnaBridge | 143:86740a56073b | 74 | |
AnnaBridge | 143:86740a56073b | 75 | /** |
AnnaBridge | 143:86740a56073b | 76 | * @brief Input selection for the analog-to-digital converter. |
AnnaBridge | 143:86740a56073b | 77 | */ |
AnnaBridge | 143:86740a56073b | 78 | typedef enum |
AnnaBridge | 143:86740a56073b | 79 | { |
AnnaBridge | 143:86740a56073b | 80 | NRF_SAADC_INPUT_DISABLED = SAADC_CH_PSELP_PSELP_NC, ///< Not connected. |
AnnaBridge | 143:86740a56073b | 81 | NRF_SAADC_INPUT_AIN0 = SAADC_CH_PSELP_PSELP_AnalogInput0, ///< Analog input 0 (AIN0). |
AnnaBridge | 143:86740a56073b | 82 | NRF_SAADC_INPUT_AIN1 = SAADC_CH_PSELP_PSELP_AnalogInput1, ///< Analog input 1 (AIN1). |
AnnaBridge | 143:86740a56073b | 83 | NRF_SAADC_INPUT_AIN2 = SAADC_CH_PSELP_PSELP_AnalogInput2, ///< Analog input 2 (AIN2). |
AnnaBridge | 143:86740a56073b | 84 | NRF_SAADC_INPUT_AIN3 = SAADC_CH_PSELP_PSELP_AnalogInput3, ///< Analog input 3 (AIN3). |
AnnaBridge | 143:86740a56073b | 85 | NRF_SAADC_INPUT_AIN4 = SAADC_CH_PSELP_PSELP_AnalogInput4, ///< Analog input 4 (AIN4). |
AnnaBridge | 143:86740a56073b | 86 | NRF_SAADC_INPUT_AIN5 = SAADC_CH_PSELP_PSELP_AnalogInput5, ///< Analog input 5 (AIN5). |
AnnaBridge | 143:86740a56073b | 87 | NRF_SAADC_INPUT_AIN6 = SAADC_CH_PSELP_PSELP_AnalogInput6, ///< Analog input 6 (AIN6). |
AnnaBridge | 143:86740a56073b | 88 | NRF_SAADC_INPUT_AIN7 = SAADC_CH_PSELP_PSELP_AnalogInput7, ///< Analog input 7 (AIN7). |
AnnaBridge | 143:86740a56073b | 89 | NRF_SAADC_INPUT_VDD = SAADC_CH_PSELP_PSELP_VDD ///< VDD as input. |
AnnaBridge | 143:86740a56073b | 90 | } nrf_saadc_input_t; |
AnnaBridge | 143:86740a56073b | 91 | |
AnnaBridge | 143:86740a56073b | 92 | |
AnnaBridge | 143:86740a56073b | 93 | /** |
AnnaBridge | 143:86740a56073b | 94 | * @brief Analog-to-digital converter oversampling mode. |
AnnaBridge | 143:86740a56073b | 95 | */ |
AnnaBridge | 143:86740a56073b | 96 | typedef enum |
AnnaBridge | 143:86740a56073b | 97 | { |
AnnaBridge | 143:86740a56073b | 98 | NRF_SAADC_OVERSAMPLE_DISABLED = SAADC_OVERSAMPLE_OVERSAMPLE_Bypass, ///< No oversampling. |
AnnaBridge | 143:86740a56073b | 99 | NRF_SAADC_OVERSAMPLE_2X = SAADC_OVERSAMPLE_OVERSAMPLE_Over2x, ///< Oversample 2x. |
AnnaBridge | 143:86740a56073b | 100 | NRF_SAADC_OVERSAMPLE_4X = SAADC_OVERSAMPLE_OVERSAMPLE_Over4x, ///< Oversample 4x. |
AnnaBridge | 143:86740a56073b | 101 | NRF_SAADC_OVERSAMPLE_8X = SAADC_OVERSAMPLE_OVERSAMPLE_Over8x, ///< Oversample 8x. |
AnnaBridge | 143:86740a56073b | 102 | NRF_SAADC_OVERSAMPLE_16X = SAADC_OVERSAMPLE_OVERSAMPLE_Over16x, ///< Oversample 16x. |
AnnaBridge | 143:86740a56073b | 103 | NRF_SAADC_OVERSAMPLE_32X = SAADC_OVERSAMPLE_OVERSAMPLE_Over32x, ///< Oversample 32x. |
AnnaBridge | 143:86740a56073b | 104 | NRF_SAADC_OVERSAMPLE_64X = SAADC_OVERSAMPLE_OVERSAMPLE_Over64x, ///< Oversample 64x. |
AnnaBridge | 143:86740a56073b | 105 | NRF_SAADC_OVERSAMPLE_128X = SAADC_OVERSAMPLE_OVERSAMPLE_Over128x, ///< Oversample 128x. |
AnnaBridge | 143:86740a56073b | 106 | NRF_SAADC_OVERSAMPLE_256X = SAADC_OVERSAMPLE_OVERSAMPLE_Over256x ///< Oversample 256x. |
AnnaBridge | 143:86740a56073b | 107 | } nrf_saadc_oversample_t; |
AnnaBridge | 143:86740a56073b | 108 | |
AnnaBridge | 143:86740a56073b | 109 | |
AnnaBridge | 143:86740a56073b | 110 | /** |
AnnaBridge | 143:86740a56073b | 111 | * @brief Analog-to-digital converter channel resistor control. |
AnnaBridge | 143:86740a56073b | 112 | */ |
AnnaBridge | 143:86740a56073b | 113 | typedef enum |
AnnaBridge | 143:86740a56073b | 114 | { |
AnnaBridge | 143:86740a56073b | 115 | NRF_SAADC_RESISTOR_DISABLED = SAADC_CH_CONFIG_RESP_Bypass, ///< Bypass resistor ladder. |
AnnaBridge | 143:86740a56073b | 116 | NRF_SAADC_RESISTOR_PULLDOWN = SAADC_CH_CONFIG_RESP_Pulldown, ///< Pull-down to GND. |
AnnaBridge | 143:86740a56073b | 117 | NRF_SAADC_RESISTOR_PULLUP = SAADC_CH_CONFIG_RESP_Pullup, ///< Pull-up to VDD. |
AnnaBridge | 143:86740a56073b | 118 | NRF_SAADC_RESISTOR_VDD1_2 = SAADC_CH_CONFIG_RESP_VDD1_2 ///< Set input at VDD/2. |
AnnaBridge | 143:86740a56073b | 119 | } nrf_saadc_resistor_t; |
AnnaBridge | 143:86740a56073b | 120 | |
AnnaBridge | 143:86740a56073b | 121 | |
AnnaBridge | 143:86740a56073b | 122 | /** |
AnnaBridge | 143:86740a56073b | 123 | * @brief Gain factor of the analog-to-digital converter input. |
AnnaBridge | 143:86740a56073b | 124 | */ |
AnnaBridge | 143:86740a56073b | 125 | typedef enum |
AnnaBridge | 143:86740a56073b | 126 | { |
AnnaBridge | 143:86740a56073b | 127 | NRF_SAADC_GAIN1_6 = SAADC_CH_CONFIG_GAIN_Gain1_6, ///< Gain factor 1/6. |
AnnaBridge | 143:86740a56073b | 128 | NRF_SAADC_GAIN1_5 = SAADC_CH_CONFIG_GAIN_Gain1_5, ///< Gain factor 1/5. |
AnnaBridge | 143:86740a56073b | 129 | NRF_SAADC_GAIN1_4 = SAADC_CH_CONFIG_GAIN_Gain1_4, ///< Gain factor 1/4. |
AnnaBridge | 143:86740a56073b | 130 | NRF_SAADC_GAIN1_3 = SAADC_CH_CONFIG_GAIN_Gain1_3, ///< Gain factor 1/3. |
AnnaBridge | 143:86740a56073b | 131 | NRF_SAADC_GAIN1_2 = SAADC_CH_CONFIG_GAIN_Gain1_2, ///< Gain factor 1/2. |
AnnaBridge | 143:86740a56073b | 132 | NRF_SAADC_GAIN1 = SAADC_CH_CONFIG_GAIN_Gain1, ///< Gain factor 1. |
AnnaBridge | 143:86740a56073b | 133 | NRF_SAADC_GAIN2 = SAADC_CH_CONFIG_GAIN_Gain2, ///< Gain factor 2. |
AnnaBridge | 143:86740a56073b | 134 | NRF_SAADC_GAIN4 = SAADC_CH_CONFIG_GAIN_Gain4, ///< Gain factor 4. |
AnnaBridge | 143:86740a56073b | 135 | } nrf_saadc_gain_t; |
AnnaBridge | 143:86740a56073b | 136 | |
AnnaBridge | 143:86740a56073b | 137 | |
AnnaBridge | 143:86740a56073b | 138 | /** |
AnnaBridge | 143:86740a56073b | 139 | * @brief Reference selection for the analog-to-digital converter. |
AnnaBridge | 143:86740a56073b | 140 | */ |
AnnaBridge | 143:86740a56073b | 141 | typedef enum |
AnnaBridge | 143:86740a56073b | 142 | { |
AnnaBridge | 143:86740a56073b | 143 | NRF_SAADC_REFERENCE_INTERNAL = SAADC_CH_CONFIG_REFSEL_Internal, ///< Internal reference (0.6 V). |
AnnaBridge | 143:86740a56073b | 144 | NRF_SAADC_REFERENCE_VDD4 = SAADC_CH_CONFIG_REFSEL_VDD1_4 ///< VDD/4 as reference. |
AnnaBridge | 143:86740a56073b | 145 | } nrf_saadc_reference_t; |
AnnaBridge | 143:86740a56073b | 146 | |
AnnaBridge | 143:86740a56073b | 147 | |
AnnaBridge | 143:86740a56073b | 148 | /** |
AnnaBridge | 143:86740a56073b | 149 | * @brief Analog-to-digital converter acquisition time. |
AnnaBridge | 143:86740a56073b | 150 | */ |
AnnaBridge | 143:86740a56073b | 151 | typedef enum |
AnnaBridge | 143:86740a56073b | 152 | { |
AnnaBridge | 143:86740a56073b | 153 | NRF_SAADC_ACQTIME_3US = SAADC_CH_CONFIG_TACQ_3us, ///< 3 us. |
AnnaBridge | 143:86740a56073b | 154 | NRF_SAADC_ACQTIME_5US = SAADC_CH_CONFIG_TACQ_5us, ///< 5 us. |
AnnaBridge | 143:86740a56073b | 155 | NRF_SAADC_ACQTIME_10US = SAADC_CH_CONFIG_TACQ_10us, ///< 10 us. |
AnnaBridge | 143:86740a56073b | 156 | NRF_SAADC_ACQTIME_15US = SAADC_CH_CONFIG_TACQ_15us, ///< 15 us. |
AnnaBridge | 143:86740a56073b | 157 | NRF_SAADC_ACQTIME_20US = SAADC_CH_CONFIG_TACQ_20us, ///< 20 us. |
AnnaBridge | 143:86740a56073b | 158 | NRF_SAADC_ACQTIME_40US = SAADC_CH_CONFIG_TACQ_40us ///< 40 us. |
AnnaBridge | 143:86740a56073b | 159 | } nrf_saadc_acqtime_t; |
AnnaBridge | 143:86740a56073b | 160 | |
AnnaBridge | 143:86740a56073b | 161 | |
AnnaBridge | 143:86740a56073b | 162 | /** |
AnnaBridge | 143:86740a56073b | 163 | * @brief Analog-to-digital converter channel mode. |
AnnaBridge | 143:86740a56073b | 164 | */ |
AnnaBridge | 143:86740a56073b | 165 | typedef enum |
AnnaBridge | 143:86740a56073b | 166 | { |
AnnaBridge | 143:86740a56073b | 167 | NRF_SAADC_MODE_SINGLE_ENDED = SAADC_CH_CONFIG_MODE_SE, ///< Single ended, PSELN will be ignored, negative input to ADC shorted to GND. |
AnnaBridge | 143:86740a56073b | 168 | NRF_SAADC_MODE_DIFFERENTIAL = SAADC_CH_CONFIG_MODE_Diff ///< Differential mode. |
AnnaBridge | 143:86740a56073b | 169 | } nrf_saadc_mode_t; |
AnnaBridge | 143:86740a56073b | 170 | |
AnnaBridge | 143:86740a56073b | 171 | |
AnnaBridge | 143:86740a56073b | 172 | /** |
AnnaBridge | 143:86740a56073b | 173 | * @brief Analog-to-digital converter tasks. |
AnnaBridge | 143:86740a56073b | 174 | */ |
AnnaBridge | 143:86740a56073b | 175 | typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */ |
AnnaBridge | 143:86740a56073b | 176 | { |
AnnaBridge | 143:86740a56073b | 177 | NRF_SAADC_TASK_START = offsetof(NRF_SAADC_Type, TASKS_START), ///< Start the ADC and prepare the result buffer in RAM. |
AnnaBridge | 143:86740a56073b | 178 | NRF_SAADC_TASK_SAMPLE = offsetof(NRF_SAADC_Type, TASKS_SAMPLE), ///< Take one ADC sample. If scan is enabled, all channels are sampled. |
AnnaBridge | 143:86740a56073b | 179 | NRF_SAADC_TASK_STOP = offsetof(NRF_SAADC_Type, TASKS_STOP), ///< Stop the ADC and terminate any on-going conversion. |
AnnaBridge | 143:86740a56073b | 180 | NRF_SAADC_TASK_CALIBRATEOFFSET = offsetof(NRF_SAADC_Type, TASKS_CALIBRATEOFFSET), ///< Starts offset auto-calibration. |
AnnaBridge | 143:86740a56073b | 181 | } nrf_saadc_task_t; |
AnnaBridge | 143:86740a56073b | 182 | |
AnnaBridge | 143:86740a56073b | 183 | |
AnnaBridge | 143:86740a56073b | 184 | /** |
AnnaBridge | 143:86740a56073b | 185 | * @brief Analog-to-digital converter events. |
AnnaBridge | 143:86740a56073b | 186 | */ |
AnnaBridge | 143:86740a56073b | 187 | typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */ |
AnnaBridge | 143:86740a56073b | 188 | { |
AnnaBridge | 143:86740a56073b | 189 | NRF_SAADC_EVENT_STARTED = offsetof(NRF_SAADC_Type, EVENTS_STARTED), ///< The ADC has started. |
AnnaBridge | 143:86740a56073b | 190 | NRF_SAADC_EVENT_END = offsetof(NRF_SAADC_Type, EVENTS_END), ///< The ADC has filled up the result buffer. |
AnnaBridge | 143:86740a56073b | 191 | NRF_SAADC_EVENT_CALIBRATEDONE = offsetof(NRF_SAADC_Type, EVENTS_CALIBRATEDONE), ///< Calibration is complete. |
AnnaBridge | 143:86740a56073b | 192 | NRF_SAADC_EVENT_STOPPED = offsetof(NRF_SAADC_Type, EVENTS_STOPPED), ///< The ADC has stopped. |
AnnaBridge | 143:86740a56073b | 193 | NRF_SAADC_EVENT_CH0_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[0].LIMITH), ///< Last result is equal or above CH[0].LIMIT.HIGH. |
AnnaBridge | 143:86740a56073b | 194 | NRF_SAADC_EVENT_CH0_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[0].LIMITL), ///< Last result is equal or below CH[0].LIMIT.LOW. |
AnnaBridge | 143:86740a56073b | 195 | NRF_SAADC_EVENT_CH1_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[1].LIMITH), ///< Last result is equal or above CH[1].LIMIT.HIGH. |
AnnaBridge | 143:86740a56073b | 196 | NRF_SAADC_EVENT_CH1_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[1].LIMITL), ///< Last result is equal or below CH[1].LIMIT.LOW. |
AnnaBridge | 143:86740a56073b | 197 | NRF_SAADC_EVENT_CH2_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[2].LIMITH), ///< Last result is equal or above CH[2].LIMIT.HIGH. |
AnnaBridge | 143:86740a56073b | 198 | NRF_SAADC_EVENT_CH2_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[2].LIMITL), ///< Last result is equal or below CH[2].LIMIT.LOW. |
AnnaBridge | 143:86740a56073b | 199 | NRF_SAADC_EVENT_CH3_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[3].LIMITH), ///< Last result is equal or above CH[3].LIMIT.HIGH. |
AnnaBridge | 143:86740a56073b | 200 | NRF_SAADC_EVENT_CH3_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[3].LIMITL), ///< Last result is equal or below CH[3].LIMIT.LOW. |
AnnaBridge | 143:86740a56073b | 201 | NRF_SAADC_EVENT_CH4_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[4].LIMITH), ///< Last result is equal or above CH[4].LIMIT.HIGH. |
AnnaBridge | 143:86740a56073b | 202 | NRF_SAADC_EVENT_CH4_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[4].LIMITL), ///< Last result is equal or below CH[4].LIMIT.LOW. |
AnnaBridge | 143:86740a56073b | 203 | NRF_SAADC_EVENT_CH5_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[5].LIMITH), ///< Last result is equal or above CH[5].LIMIT.HIGH. |
AnnaBridge | 143:86740a56073b | 204 | NRF_SAADC_EVENT_CH5_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[5].LIMITL), ///< Last result is equal or below CH[5].LIMIT.LOW. |
AnnaBridge | 143:86740a56073b | 205 | NRF_SAADC_EVENT_CH6_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[6].LIMITH), ///< Last result is equal or above CH[6].LIMIT.HIGH. |
AnnaBridge | 143:86740a56073b | 206 | NRF_SAADC_EVENT_CH6_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[6].LIMITL), ///< Last result is equal or below CH[6].LIMIT.LOW. |
AnnaBridge | 143:86740a56073b | 207 | NRF_SAADC_EVENT_CH7_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[7].LIMITH), ///< Last result is equal or above CH[7].LIMIT.HIGH. |
AnnaBridge | 143:86740a56073b | 208 | NRF_SAADC_EVENT_CH7_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[7].LIMITL) ///< Last result is equal or below CH[7].LIMIT.LOW. |
AnnaBridge | 143:86740a56073b | 209 | } nrf_saadc_event_t; |
AnnaBridge | 143:86740a56073b | 210 | |
AnnaBridge | 143:86740a56073b | 211 | |
AnnaBridge | 143:86740a56073b | 212 | /** |
AnnaBridge | 143:86740a56073b | 213 | * @brief Analog-to-digital converter interrupt masks. |
AnnaBridge | 143:86740a56073b | 214 | */ |
AnnaBridge | 143:86740a56073b | 215 | typedef enum |
AnnaBridge | 143:86740a56073b | 216 | { |
AnnaBridge | 143:86740a56073b | 217 | NRF_SAADC_INT_STARTED = SAADC_INTENSET_STARTED_Msk, ///< Interrupt on EVENTS_STARTED event. |
AnnaBridge | 143:86740a56073b | 218 | NRF_SAADC_INT_END = SAADC_INTENSET_END_Msk, ///< Interrupt on EVENTS_END event. |
AnnaBridge | 143:86740a56073b | 219 | NRF_SAADC_INT_STOPPED = SAADC_INTENSET_STOPPED_Msk, ///< Interrupt on EVENTS_STOPPED event. |
AnnaBridge | 143:86740a56073b | 220 | NRF_SAADC_INT_CH0LIMITH = SAADC_INTENSET_CH0LIMITH_Msk, ///< Interrupt on EVENTS_CH[0].LIMITH event. |
AnnaBridge | 143:86740a56073b | 221 | NRF_SAADC_INT_CH0LIMITL = SAADC_INTENSET_CH0LIMITL_Msk, ///< Interrupt on EVENTS_CH[0].LIMITL event. |
AnnaBridge | 143:86740a56073b | 222 | NRF_SAADC_INT_CH1LIMITH = SAADC_INTENSET_CH1LIMITH_Msk, ///< Interrupt on EVENTS_CH[1].LIMITH event. |
AnnaBridge | 143:86740a56073b | 223 | NRF_SAADC_INT_CH1LIMITL = SAADC_INTENSET_CH1LIMITL_Msk, ///< Interrupt on EVENTS_CH[1].LIMITL event. |
AnnaBridge | 143:86740a56073b | 224 | NRF_SAADC_INT_CH2LIMITH = SAADC_INTENSET_CH2LIMITH_Msk, ///< Interrupt on EVENTS_CH[2].LIMITH event. |
AnnaBridge | 143:86740a56073b | 225 | NRF_SAADC_INT_CH2LIMITL = SAADC_INTENSET_CH2LIMITL_Msk, ///< Interrupt on EVENTS_CH[2].LIMITL event. |
AnnaBridge | 143:86740a56073b | 226 | NRF_SAADC_INT_CH3LIMITH = SAADC_INTENSET_CH3LIMITH_Msk, ///< Interrupt on EVENTS_CH[3].LIMITH event. |
AnnaBridge | 143:86740a56073b | 227 | NRF_SAADC_INT_CH3LIMITL = SAADC_INTENSET_CH3LIMITL_Msk, ///< Interrupt on EVENTS_CH[3].LIMITL event. |
AnnaBridge | 143:86740a56073b | 228 | NRF_SAADC_INT_CH4LIMITH = SAADC_INTENSET_CH4LIMITH_Msk, ///< Interrupt on EVENTS_CH[4].LIMITH event. |
AnnaBridge | 143:86740a56073b | 229 | NRF_SAADC_INT_CH4LIMITL = SAADC_INTENSET_CH4LIMITL_Msk, ///< Interrupt on EVENTS_CH[4].LIMITL event. |
AnnaBridge | 143:86740a56073b | 230 | NRF_SAADC_INT_CH5LIMITH = SAADC_INTENSET_CH5LIMITH_Msk, ///< Interrupt on EVENTS_CH[5].LIMITH event. |
AnnaBridge | 143:86740a56073b | 231 | NRF_SAADC_INT_CH5LIMITL = SAADC_INTENSET_CH5LIMITL_Msk, ///< Interrupt on EVENTS_CH[5].LIMITL event. |
AnnaBridge | 143:86740a56073b | 232 | NRF_SAADC_INT_CH6LIMITH = SAADC_INTENSET_CH6LIMITH_Msk, ///< Interrupt on EVENTS_CH[6].LIMITH event. |
AnnaBridge | 143:86740a56073b | 233 | NRF_SAADC_INT_CH6LIMITL = SAADC_INTENSET_CH6LIMITL_Msk, ///< Interrupt on EVENTS_CH[6].LIMITL event. |
AnnaBridge | 143:86740a56073b | 234 | NRF_SAADC_INT_CH7LIMITH = SAADC_INTENSET_CH7LIMITH_Msk, ///< Interrupt on EVENTS_CH[7].LIMITH event. |
AnnaBridge | 143:86740a56073b | 235 | NRF_SAADC_INT_CH7LIMITL = SAADC_INTENSET_CH7LIMITL_Msk, ///< Interrupt on EVENTS_CH[7].LIMITL event. |
AnnaBridge | 143:86740a56073b | 236 | NRF_SAADC_INT_ALL = 0x7FFFFFFFUL ///< Mask of all interrupts. |
AnnaBridge | 143:86740a56073b | 237 | } nrf_saadc_int_mask_t; |
AnnaBridge | 143:86740a56073b | 238 | |
AnnaBridge | 143:86740a56073b | 239 | |
AnnaBridge | 143:86740a56073b | 240 | /** |
AnnaBridge | 143:86740a56073b | 241 | * @brief Analog-to-digital converter value limit type. |
AnnaBridge | 143:86740a56073b | 242 | */ |
AnnaBridge | 143:86740a56073b | 243 | typedef enum |
AnnaBridge | 143:86740a56073b | 244 | { |
AnnaBridge | 143:86740a56073b | 245 | NRF_SAADC_LIMIT_LOW = 0, |
AnnaBridge | 143:86740a56073b | 246 | NRF_SAADC_LIMIT_HIGH = 1 |
AnnaBridge | 143:86740a56073b | 247 | } nrf_saadc_limit_t; |
AnnaBridge | 143:86740a56073b | 248 | |
AnnaBridge | 143:86740a56073b | 249 | |
AnnaBridge | 143:86740a56073b | 250 | typedef int16_t nrf_saadc_value_t; ///< Type of a single ADC conversion result. |
AnnaBridge | 143:86740a56073b | 251 | |
AnnaBridge | 143:86740a56073b | 252 | |
AnnaBridge | 143:86740a56073b | 253 | /** |
AnnaBridge | 143:86740a56073b | 254 | * @brief Analog-to-digital converter configuration structure. |
AnnaBridge | 143:86740a56073b | 255 | */ |
AnnaBridge | 143:86740a56073b | 256 | typedef struct |
AnnaBridge | 143:86740a56073b | 257 | { |
AnnaBridge | 143:86740a56073b | 258 | nrf_saadc_resolution_t resolution; |
AnnaBridge | 143:86740a56073b | 259 | nrf_saadc_oversample_t oversample; |
AnnaBridge | 143:86740a56073b | 260 | nrf_saadc_value_t * buffer; |
AnnaBridge | 143:86740a56073b | 261 | uint32_t buffer_size; |
AnnaBridge | 143:86740a56073b | 262 | } nrf_saadc_config_t; |
AnnaBridge | 143:86740a56073b | 263 | |
AnnaBridge | 143:86740a56073b | 264 | |
AnnaBridge | 143:86740a56073b | 265 | /** |
AnnaBridge | 143:86740a56073b | 266 | * @brief Analog-to-digital converter channel configuration structure. |
AnnaBridge | 143:86740a56073b | 267 | */ |
AnnaBridge | 143:86740a56073b | 268 | typedef struct |
AnnaBridge | 143:86740a56073b | 269 | { |
AnnaBridge | 143:86740a56073b | 270 | nrf_saadc_resistor_t resistor_p; |
AnnaBridge | 143:86740a56073b | 271 | nrf_saadc_resistor_t resistor_n; |
AnnaBridge | 143:86740a56073b | 272 | nrf_saadc_gain_t gain; |
AnnaBridge | 143:86740a56073b | 273 | nrf_saadc_reference_t reference; |
AnnaBridge | 143:86740a56073b | 274 | nrf_saadc_acqtime_t acq_time; |
AnnaBridge | 143:86740a56073b | 275 | nrf_saadc_mode_t mode; |
AnnaBridge | 143:86740a56073b | 276 | nrf_saadc_input_t pin_p; |
AnnaBridge | 143:86740a56073b | 277 | nrf_saadc_input_t pin_n; |
AnnaBridge | 143:86740a56073b | 278 | } nrf_saadc_channel_config_t; |
AnnaBridge | 143:86740a56073b | 279 | |
AnnaBridge | 143:86740a56073b | 280 | |
AnnaBridge | 143:86740a56073b | 281 | /** |
AnnaBridge | 143:86740a56073b | 282 | * @brief Function for triggering a specific SAADC task. |
AnnaBridge | 143:86740a56073b | 283 | * |
AnnaBridge | 143:86740a56073b | 284 | * @param[in] saadc_task SAADC task. |
AnnaBridge | 143:86740a56073b | 285 | */ |
AnnaBridge | 143:86740a56073b | 286 | __STATIC_INLINE void nrf_saadc_task_trigger(nrf_saadc_task_t saadc_task) |
AnnaBridge | 143:86740a56073b | 287 | { |
AnnaBridge | 143:86740a56073b | 288 | *((volatile uint32_t *)((uint8_t *)NRF_SAADC + (uint32_t)saadc_task)) = 0x1UL; |
AnnaBridge | 143:86740a56073b | 289 | } |
AnnaBridge | 143:86740a56073b | 290 | |
AnnaBridge | 143:86740a56073b | 291 | |
AnnaBridge | 143:86740a56073b | 292 | /** |
AnnaBridge | 143:86740a56073b | 293 | * @brief Function for getting the address of a specific SAADC task register. |
AnnaBridge | 143:86740a56073b | 294 | * |
AnnaBridge | 143:86740a56073b | 295 | * @param[in] saadc_task SAADC task. |
AnnaBridge | 143:86740a56073b | 296 | * |
AnnaBridge | 143:86740a56073b | 297 | * @return Address of the specified SAADC task. |
AnnaBridge | 143:86740a56073b | 298 | */ |
AnnaBridge | 143:86740a56073b | 299 | __STATIC_INLINE uint32_t nrf_saadc_task_address_get(nrf_saadc_task_t saadc_task) |
AnnaBridge | 143:86740a56073b | 300 | { |
AnnaBridge | 143:86740a56073b | 301 | return (uint32_t)((uint8_t *)NRF_SAADC + (uint32_t)saadc_task); |
AnnaBridge | 143:86740a56073b | 302 | } |
AnnaBridge | 143:86740a56073b | 303 | |
AnnaBridge | 143:86740a56073b | 304 | |
AnnaBridge | 143:86740a56073b | 305 | /** |
AnnaBridge | 143:86740a56073b | 306 | * @brief Function for getting the state of a specific SAADC event. |
AnnaBridge | 143:86740a56073b | 307 | * |
AnnaBridge | 143:86740a56073b | 308 | * @param[in] saadc_event SAADC event. |
AnnaBridge | 143:86740a56073b | 309 | * |
AnnaBridge | 143:86740a56073b | 310 | * @return State of the specified SAADC event. |
AnnaBridge | 143:86740a56073b | 311 | */ |
AnnaBridge | 143:86740a56073b | 312 | __STATIC_INLINE bool nrf_saadc_event_check(nrf_saadc_event_t saadc_event) |
AnnaBridge | 143:86740a56073b | 313 | { |
AnnaBridge | 143:86740a56073b | 314 | return (bool)*(volatile uint32_t *)((uint8_t *)NRF_SAADC + (uint32_t)saadc_event); |
AnnaBridge | 143:86740a56073b | 315 | } |
AnnaBridge | 143:86740a56073b | 316 | |
AnnaBridge | 143:86740a56073b | 317 | |
AnnaBridge | 143:86740a56073b | 318 | /** |
AnnaBridge | 143:86740a56073b | 319 | * @brief Function for clearing the specific SAADC event. |
AnnaBridge | 143:86740a56073b | 320 | * |
AnnaBridge | 143:86740a56073b | 321 | * @param[in] saadc_event SAADC event. |
AnnaBridge | 143:86740a56073b | 322 | */ |
AnnaBridge | 143:86740a56073b | 323 | __STATIC_INLINE void nrf_saadc_event_clear(nrf_saadc_event_t saadc_event) |
AnnaBridge | 143:86740a56073b | 324 | { |
AnnaBridge | 143:86740a56073b | 325 | *((volatile uint32_t *)((uint8_t *)NRF_SAADC + (uint32_t)saadc_event)) = 0x0UL; |
AnnaBridge | 143:86740a56073b | 326 | } |
AnnaBridge | 143:86740a56073b | 327 | |
AnnaBridge | 143:86740a56073b | 328 | |
AnnaBridge | 143:86740a56073b | 329 | /** |
AnnaBridge | 143:86740a56073b | 330 | * @brief Function for getting the address of a specific SAADC event register. |
AnnaBridge | 143:86740a56073b | 331 | * |
AnnaBridge | 143:86740a56073b | 332 | * @param[in] saadc_event SAADC event. |
AnnaBridge | 143:86740a56073b | 333 | * |
AnnaBridge | 143:86740a56073b | 334 | * @return Address of the specified SAADC event. |
AnnaBridge | 143:86740a56073b | 335 | */ |
AnnaBridge | 143:86740a56073b | 336 | __STATIC_INLINE volatile uint32_t * nrf_saadc_event_address_get(nrf_saadc_event_t saadc_event) |
AnnaBridge | 143:86740a56073b | 337 | { |
AnnaBridge | 143:86740a56073b | 338 | return (volatile uint32_t *)((uint8_t *)NRF_SAADC + (uint32_t)saadc_event); |
AnnaBridge | 143:86740a56073b | 339 | } |
AnnaBridge | 143:86740a56073b | 340 | |
AnnaBridge | 143:86740a56073b | 341 | |
AnnaBridge | 143:86740a56073b | 342 | /** |
AnnaBridge | 143:86740a56073b | 343 | * @brief Function for getting the address of a specific SAADC limit event register. |
AnnaBridge | 143:86740a56073b | 344 | * |
AnnaBridge | 143:86740a56073b | 345 | * @param[in] channel Channel number. |
AnnaBridge | 143:86740a56073b | 346 | * @param[in] limit_type Low limit or high limit. |
AnnaBridge | 143:86740a56073b | 347 | * |
AnnaBridge | 143:86740a56073b | 348 | * @return Address of the specified SAADC limit event. |
AnnaBridge | 143:86740a56073b | 349 | */ |
AnnaBridge | 143:86740a56073b | 350 | __STATIC_INLINE volatile uint32_t * nrf_saadc_event_limit_address_get(uint8_t channel, nrf_saadc_limit_t limit_type) |
AnnaBridge | 143:86740a56073b | 351 | { |
AnnaBridge | 143:86740a56073b | 352 | ASSERT(channel < NRF_SAADC_CHANNEL_COUNT); |
AnnaBridge | 143:86740a56073b | 353 | if (limit_type == NRF_SAADC_LIMIT_HIGH) |
AnnaBridge | 143:86740a56073b | 354 | { |
AnnaBridge | 143:86740a56073b | 355 | return &NRF_SAADC->EVENTS_CH[channel].LIMITH; |
AnnaBridge | 143:86740a56073b | 356 | } |
AnnaBridge | 143:86740a56073b | 357 | else |
AnnaBridge | 143:86740a56073b | 358 | { |
AnnaBridge | 143:86740a56073b | 359 | return &NRF_SAADC->EVENTS_CH[channel].LIMITL; |
AnnaBridge | 143:86740a56073b | 360 | } |
AnnaBridge | 143:86740a56073b | 361 | } |
AnnaBridge | 143:86740a56073b | 362 | |
AnnaBridge | 143:86740a56073b | 363 | |
AnnaBridge | 143:86740a56073b | 364 | /** |
AnnaBridge | 143:86740a56073b | 365 | * @brief Function for getting the SAADC channel monitoring limit events. |
AnnaBridge | 143:86740a56073b | 366 | * |
AnnaBridge | 143:86740a56073b | 367 | * @param[in] channel Channel number. |
AnnaBridge | 143:86740a56073b | 368 | * @param[in] limit_type Low limit or high limit. |
AnnaBridge | 143:86740a56073b | 369 | */ |
AnnaBridge | 143:86740a56073b | 370 | __STATIC_INLINE nrf_saadc_event_t nrf_saadc_event_limit_get(uint8_t channel, nrf_saadc_limit_t limit_type) |
AnnaBridge | 143:86740a56073b | 371 | { |
AnnaBridge | 143:86740a56073b | 372 | if (limit_type == NRF_SAADC_LIMIT_HIGH) |
AnnaBridge | 143:86740a56073b | 373 | { |
AnnaBridge | 143:86740a56073b | 374 | return (nrf_saadc_event_t)( (uint32_t) NRF_SAADC_EVENT_CH0_LIMITH + |
AnnaBridge | 143:86740a56073b | 375 | (uint32_t) (NRF_SAADC_EVENT_CH1_LIMITH - NRF_SAADC_EVENT_CH0_LIMITH) |
AnnaBridge | 143:86740a56073b | 376 | * (uint32_t) channel ); |
AnnaBridge | 143:86740a56073b | 377 | } |
AnnaBridge | 143:86740a56073b | 378 | else |
AnnaBridge | 143:86740a56073b | 379 | { |
AnnaBridge | 143:86740a56073b | 380 | return (nrf_saadc_event_t)( (uint32_t) NRF_SAADC_EVENT_CH0_LIMITL + |
AnnaBridge | 143:86740a56073b | 381 | (uint32_t) (NRF_SAADC_EVENT_CH1_LIMITL - NRF_SAADC_EVENT_CH0_LIMITL) |
AnnaBridge | 143:86740a56073b | 382 | * (uint32_t) channel ); |
AnnaBridge | 143:86740a56073b | 383 | } |
AnnaBridge | 143:86740a56073b | 384 | } |
AnnaBridge | 143:86740a56073b | 385 | |
AnnaBridge | 143:86740a56073b | 386 | |
AnnaBridge | 143:86740a56073b | 387 | /** |
AnnaBridge | 143:86740a56073b | 388 | * @brief Function for configuring the input pins for a specific SAADC channel. |
AnnaBridge | 143:86740a56073b | 389 | * |
AnnaBridge | 143:86740a56073b | 390 | * @param[in] channel Channel number. |
AnnaBridge | 143:86740a56073b | 391 | * @param[in] pselp Positive input. |
AnnaBridge | 143:86740a56073b | 392 | * @param[in] pseln Negative input. Set to NRF_SAADC_INPUT_DISABLED in single ended mode. |
AnnaBridge | 143:86740a56073b | 393 | */ |
AnnaBridge | 143:86740a56073b | 394 | __STATIC_INLINE void nrf_saadc_channel_input_set(uint8_t channel, |
AnnaBridge | 143:86740a56073b | 395 | nrf_saadc_input_t pselp, |
AnnaBridge | 143:86740a56073b | 396 | nrf_saadc_input_t pseln) |
AnnaBridge | 143:86740a56073b | 397 | { |
AnnaBridge | 143:86740a56073b | 398 | NRF_SAADC->CH[channel].PSELN = pseln; |
AnnaBridge | 143:86740a56073b | 399 | NRF_SAADC->CH[channel].PSELP = pselp; |
AnnaBridge | 143:86740a56073b | 400 | } |
AnnaBridge | 143:86740a56073b | 401 | |
AnnaBridge | 143:86740a56073b | 402 | |
AnnaBridge | 143:86740a56073b | 403 | /** |
AnnaBridge | 143:86740a56073b | 404 | * @brief Function for setting the SAADC channel monitoring limits. |
AnnaBridge | 143:86740a56073b | 405 | * |
AnnaBridge | 143:86740a56073b | 406 | * @param[in] channel Channel number. |
AnnaBridge | 143:86740a56073b | 407 | * @param[in] low Low limit. |
AnnaBridge | 143:86740a56073b | 408 | * @param[in] high High limit. |
AnnaBridge | 143:86740a56073b | 409 | */ |
AnnaBridge | 143:86740a56073b | 410 | __STATIC_INLINE void nrf_saadc_channel_limits_set(uint8_t channel, int16_t low, int16_t high) |
AnnaBridge | 143:86740a56073b | 411 | { |
AnnaBridge | 143:86740a56073b | 412 | NRF_SAADC->CH[channel].LIMIT = ( |
AnnaBridge | 143:86740a56073b | 413 | (((uint32_t) low << SAADC_CH_LIMIT_LOW_Pos) & SAADC_CH_LIMIT_LOW_Msk) |
AnnaBridge | 143:86740a56073b | 414 | | (((uint32_t) high << SAADC_CH_LIMIT_HIGH_Pos) & SAADC_CH_LIMIT_HIGH_Msk)); |
AnnaBridge | 143:86740a56073b | 415 | } |
AnnaBridge | 143:86740a56073b | 416 | |
AnnaBridge | 143:86740a56073b | 417 | |
AnnaBridge | 143:86740a56073b | 418 | /** |
AnnaBridge | 143:86740a56073b | 419 | * @brief Function for enabling specified SAADC interrupts. |
AnnaBridge | 143:86740a56073b | 420 | * |
AnnaBridge | 143:86740a56073b | 421 | * @param[in] saadc_int_mask Interrupt(s) to enable. |
AnnaBridge | 143:86740a56073b | 422 | */ |
AnnaBridge | 143:86740a56073b | 423 | __STATIC_INLINE void nrf_saadc_int_enable(uint32_t saadc_int_mask) |
AnnaBridge | 143:86740a56073b | 424 | { |
AnnaBridge | 143:86740a56073b | 425 | NRF_SAADC->INTENSET = saadc_int_mask; |
AnnaBridge | 143:86740a56073b | 426 | } |
AnnaBridge | 143:86740a56073b | 427 | |
AnnaBridge | 143:86740a56073b | 428 | |
AnnaBridge | 143:86740a56073b | 429 | /** |
AnnaBridge | 143:86740a56073b | 430 | * @brief Function for retrieving the state of specified SAADC interrupts. |
AnnaBridge | 143:86740a56073b | 431 | * |
AnnaBridge | 143:86740a56073b | 432 | * @param[in] saadc_int_mask Interrupt(s) to check. |
AnnaBridge | 143:86740a56073b | 433 | * |
AnnaBridge | 143:86740a56073b | 434 | * @retval true If all specified interrupts are enabled. |
AnnaBridge | 143:86740a56073b | 435 | * @retval false If at least one of the given interrupts is not enabled. |
AnnaBridge | 143:86740a56073b | 436 | */ |
AnnaBridge | 143:86740a56073b | 437 | __STATIC_INLINE bool nrf_saadc_int_enable_check(uint32_t saadc_int_mask) |
AnnaBridge | 143:86740a56073b | 438 | { |
AnnaBridge | 143:86740a56073b | 439 | return (bool)(NRF_SAADC->INTENSET & saadc_int_mask); |
AnnaBridge | 143:86740a56073b | 440 | } |
AnnaBridge | 143:86740a56073b | 441 | |
AnnaBridge | 143:86740a56073b | 442 | |
AnnaBridge | 143:86740a56073b | 443 | /** |
AnnaBridge | 143:86740a56073b | 444 | * @brief Function for disabling specified interrupts. |
AnnaBridge | 143:86740a56073b | 445 | * |
AnnaBridge | 143:86740a56073b | 446 | * @param saadc_int_mask Interrupt(s) to disable. |
AnnaBridge | 143:86740a56073b | 447 | */ |
AnnaBridge | 143:86740a56073b | 448 | __STATIC_INLINE void nrf_saadc_int_disable(uint32_t saadc_int_mask) |
AnnaBridge | 143:86740a56073b | 449 | { |
AnnaBridge | 143:86740a56073b | 450 | NRF_SAADC->INTENCLR = saadc_int_mask; |
AnnaBridge | 143:86740a56073b | 451 | } |
AnnaBridge | 143:86740a56073b | 452 | |
AnnaBridge | 143:86740a56073b | 453 | |
AnnaBridge | 143:86740a56073b | 454 | /** |
AnnaBridge | 143:86740a56073b | 455 | * @brief Function for generating masks for SAADC channel limit interrupts. |
AnnaBridge | 143:86740a56073b | 456 | * |
AnnaBridge | 143:86740a56073b | 457 | * @param[in] channel SAADC channel number. |
AnnaBridge | 143:86740a56073b | 458 | * @param[in] limit_type Limit type. |
AnnaBridge | 143:86740a56073b | 459 | * |
AnnaBridge | 143:86740a56073b | 460 | * @returns Interrupt mask. |
AnnaBridge | 143:86740a56073b | 461 | */ |
AnnaBridge | 143:86740a56073b | 462 | __STATIC_INLINE uint32_t nrf_saadc_limit_int_get(uint8_t channel, nrf_saadc_limit_t limit_type) |
AnnaBridge | 143:86740a56073b | 463 | { |
AnnaBridge | 143:86740a56073b | 464 | ASSERT(channel < NRF_SAADC_CHANNEL_COUNT); |
AnnaBridge | 143:86740a56073b | 465 | uint32_t mask = (limit_type == NRF_SAADC_LIMIT_LOW) ? NRF_SAADC_INT_CH0LIMITL : NRF_SAADC_INT_CH0LIMITH; |
AnnaBridge | 143:86740a56073b | 466 | return mask << (channel * 2); |
AnnaBridge | 143:86740a56073b | 467 | } |
AnnaBridge | 143:86740a56073b | 468 | |
AnnaBridge | 143:86740a56073b | 469 | |
AnnaBridge | 143:86740a56073b | 470 | /** |
AnnaBridge | 143:86740a56073b | 471 | * @brief Function for checking whether the SAADC is busy. |
AnnaBridge | 143:86740a56073b | 472 | * |
AnnaBridge | 143:86740a56073b | 473 | * This function checks whether the analog-to-digital converter is busy with a conversion. |
AnnaBridge | 143:86740a56073b | 474 | * |
AnnaBridge | 143:86740a56073b | 475 | * @retval true If the SAADC is busy. |
AnnaBridge | 143:86740a56073b | 476 | * @retval false If the SAADC is not busy. |
AnnaBridge | 143:86740a56073b | 477 | */ |
AnnaBridge | 143:86740a56073b | 478 | __STATIC_INLINE bool nrf_saadc_busy_check(void) |
AnnaBridge | 143:86740a56073b | 479 | { |
AnnaBridge | 143:86740a56073b | 480 | //return ((NRF_SAADC->STATUS & SAADC_STATUS_STATUS_Msk) == SAADC_STATUS_STATUS_Msk); |
AnnaBridge | 143:86740a56073b | 481 | //simplified for performance |
AnnaBridge | 143:86740a56073b | 482 | return NRF_SAADC->STATUS; |
AnnaBridge | 143:86740a56073b | 483 | } |
AnnaBridge | 143:86740a56073b | 484 | |
AnnaBridge | 143:86740a56073b | 485 | |
AnnaBridge | 143:86740a56073b | 486 | /** |
AnnaBridge | 143:86740a56073b | 487 | * @brief Function for enabling the SAADC. |
AnnaBridge | 143:86740a56073b | 488 | * |
AnnaBridge | 143:86740a56073b | 489 | * The analog-to-digital converter must be enabled before use. |
AnnaBridge | 143:86740a56073b | 490 | */ |
AnnaBridge | 143:86740a56073b | 491 | __STATIC_INLINE void nrf_saadc_enable(void) |
AnnaBridge | 143:86740a56073b | 492 | { |
AnnaBridge | 143:86740a56073b | 493 | NRF_SAADC->ENABLE = (SAADC_ENABLE_ENABLE_Enabled << SAADC_ENABLE_ENABLE_Pos); |
AnnaBridge | 143:86740a56073b | 494 | } |
AnnaBridge | 143:86740a56073b | 495 | |
AnnaBridge | 143:86740a56073b | 496 | |
AnnaBridge | 143:86740a56073b | 497 | /** |
AnnaBridge | 143:86740a56073b | 498 | * @brief Function for disabling the SAADC. |
AnnaBridge | 143:86740a56073b | 499 | */ |
AnnaBridge | 143:86740a56073b | 500 | __STATIC_INLINE void nrf_saadc_disable(void) |
AnnaBridge | 143:86740a56073b | 501 | { |
AnnaBridge | 143:86740a56073b | 502 | NRF_SAADC->ENABLE = (SAADC_ENABLE_ENABLE_Disabled << SAADC_ENABLE_ENABLE_Pos); |
AnnaBridge | 143:86740a56073b | 503 | } |
AnnaBridge | 143:86740a56073b | 504 | |
AnnaBridge | 143:86740a56073b | 505 | |
AnnaBridge | 143:86740a56073b | 506 | /** |
AnnaBridge | 143:86740a56073b | 507 | * @brief Function for checking if the SAADC is enabled. |
AnnaBridge | 143:86740a56073b | 508 | * |
AnnaBridge | 143:86740a56073b | 509 | * @retval true If the SAADC is enabled. |
AnnaBridge | 143:86740a56073b | 510 | * @retval false If the SAADC is not enabled. |
AnnaBridge | 143:86740a56073b | 511 | */ |
AnnaBridge | 143:86740a56073b | 512 | __STATIC_INLINE bool nrf_saadc_enable_check(void) |
AnnaBridge | 143:86740a56073b | 513 | { |
AnnaBridge | 143:86740a56073b | 514 | //simplified for performance |
AnnaBridge | 143:86740a56073b | 515 | return NRF_SAADC->ENABLE; |
AnnaBridge | 143:86740a56073b | 516 | } |
AnnaBridge | 143:86740a56073b | 517 | |
AnnaBridge | 143:86740a56073b | 518 | |
AnnaBridge | 143:86740a56073b | 519 | /** |
AnnaBridge | 143:86740a56073b | 520 | * @brief Function for initializing the SAADC result buffer. |
AnnaBridge | 143:86740a56073b | 521 | * |
AnnaBridge | 143:86740a56073b | 522 | * @param[in] buffer Pointer to the result buffer. |
AnnaBridge | 143:86740a56073b | 523 | * @param[in] num Size of buffer in words. |
AnnaBridge | 143:86740a56073b | 524 | */ |
AnnaBridge | 143:86740a56073b | 525 | __STATIC_INLINE void nrf_saadc_buffer_init(nrf_saadc_value_t * buffer, uint32_t num) |
AnnaBridge | 143:86740a56073b | 526 | { |
AnnaBridge | 143:86740a56073b | 527 | NRF_SAADC->RESULT.PTR = (uint32_t)buffer; |
AnnaBridge | 143:86740a56073b | 528 | NRF_SAADC->RESULT.MAXCNT = num; |
AnnaBridge | 143:86740a56073b | 529 | } |
AnnaBridge | 143:86740a56073b | 530 | |
AnnaBridge | 143:86740a56073b | 531 | /** |
AnnaBridge | 143:86740a56073b | 532 | * @brief Function for getting the number of buffer words transferred since last START operation. |
AnnaBridge | 143:86740a56073b | 533 | * |
AnnaBridge | 143:86740a56073b | 534 | * @returns Number of words transferred. |
AnnaBridge | 143:86740a56073b | 535 | */ |
AnnaBridge | 143:86740a56073b | 536 | __STATIC_INLINE uint16_t nrf_saadc_amount_get(void) |
AnnaBridge | 143:86740a56073b | 537 | { |
AnnaBridge | 143:86740a56073b | 538 | return NRF_SAADC->RESULT.AMOUNT; |
AnnaBridge | 143:86740a56073b | 539 | } |
AnnaBridge | 143:86740a56073b | 540 | |
AnnaBridge | 143:86740a56073b | 541 | |
AnnaBridge | 143:86740a56073b | 542 | /** |
AnnaBridge | 143:86740a56073b | 543 | * @brief Function for setting the SAADC sample resolution. |
AnnaBridge | 143:86740a56073b | 544 | * |
AnnaBridge | 143:86740a56073b | 545 | * @param[in] resolution Bit resolution. |
AnnaBridge | 143:86740a56073b | 546 | */ |
AnnaBridge | 143:86740a56073b | 547 | __STATIC_INLINE void nrf_saadc_resolution_set(nrf_saadc_resolution_t resolution) |
AnnaBridge | 143:86740a56073b | 548 | { |
AnnaBridge | 143:86740a56073b | 549 | NRF_SAADC->RESOLUTION = resolution; |
AnnaBridge | 143:86740a56073b | 550 | } |
AnnaBridge | 143:86740a56073b | 551 | |
AnnaBridge | 143:86740a56073b | 552 | |
AnnaBridge | 143:86740a56073b | 553 | /** |
AnnaBridge | 143:86740a56073b | 554 | * @brief Function for configuring the oversampling feature. |
AnnaBridge | 143:86740a56073b | 555 | * |
AnnaBridge | 143:86740a56073b | 556 | * @param[in] oversample Oversampling mode. |
AnnaBridge | 143:86740a56073b | 557 | */ |
AnnaBridge | 143:86740a56073b | 558 | __STATIC_INLINE void nrf_saadc_oversample_set(nrf_saadc_oversample_t oversample) |
AnnaBridge | 143:86740a56073b | 559 | { |
AnnaBridge | 143:86740a56073b | 560 | NRF_SAADC->OVERSAMPLE = oversample; |
AnnaBridge | 143:86740a56073b | 561 | } |
AnnaBridge | 143:86740a56073b | 562 | |
AnnaBridge | 143:86740a56073b | 563 | /** |
AnnaBridge | 143:86740a56073b | 564 | * @brief Function for getting the oversampling feature configuration. |
AnnaBridge | 143:86740a56073b | 565 | * |
AnnaBridge | 143:86740a56073b | 566 | * @return Oversampling configuration. |
AnnaBridge | 143:86740a56073b | 567 | */ |
AnnaBridge | 143:86740a56073b | 568 | __STATIC_INLINE nrf_saadc_oversample_t nrf_saadc_oversample_get(void) |
AnnaBridge | 143:86740a56073b | 569 | { |
AnnaBridge | 143:86740a56073b | 570 | return (nrf_saadc_oversample_t)NRF_SAADC->OVERSAMPLE; |
AnnaBridge | 143:86740a56073b | 571 | } |
AnnaBridge | 143:86740a56073b | 572 | |
AnnaBridge | 143:86740a56073b | 573 | /** |
AnnaBridge | 143:86740a56073b | 574 | * @brief Function for initializing the SAADC channel. |
AnnaBridge | 143:86740a56073b | 575 | * |
AnnaBridge | 143:86740a56073b | 576 | * @param[in] channel Channel number. |
AnnaBridge | 143:86740a56073b | 577 | * @param[in] config Pointer to the channel configuration structure. |
AnnaBridge | 143:86740a56073b | 578 | */ |
AnnaBridge | 143:86740a56073b | 579 | void nrf_saadc_channel_init(uint8_t channel, nrf_saadc_channel_config_t const * const config); |
AnnaBridge | 143:86740a56073b | 580 | |
AnnaBridge | 143:86740a56073b | 581 | /** |
AnnaBridge | 143:86740a56073b | 582 | *@} |
AnnaBridge | 143:86740a56073b | 583 | **/ |
AnnaBridge | 143:86740a56073b | 584 | |
AnnaBridge | 143:86740a56073b | 585 | #endif // NRF52 |
AnnaBridge | 143:86740a56073b | 586 | |
AnnaBridge | 143:86740a56073b | 587 | #endif /* NRF_SAADC_H_ */ |