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.

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?

UserRevisionLine numberNew contents of line
Kojto 148:fd96258d940d 1 /*
Kojto 148:fd96258d940d 2 * Copyright (c) 2014 Nordic Semiconductor ASA
Kojto 148:fd96258d940d 3 * All rights reserved.
Kojto 148:fd96258d940d 4 *
Kojto 148:fd96258d940d 5 * Redistribution and use in source and binary forms, with or without modification,
Kojto 148:fd96258d940d 6 * are permitted provided that the following conditions are met:
Kojto 148:fd96258d940d 7 *
Kojto 148:fd96258d940d 8 * 1. Redistributions of source code must retain the above copyright notice, this list
Kojto 148:fd96258d940d 9 * of conditions and the following disclaimer.
Kojto 148:fd96258d940d 10 *
Kojto 148:fd96258d940d 11 * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
Kojto 148:fd96258d940d 12 * integrated circuit in a product or a software update for such product, must reproduce
Kojto 148:fd96258d940d 13 * the above copyright notice, this list of conditions and the following disclaimer in
Kojto 148:fd96258d940d 14 * the documentation and/or other materials provided with the distribution.
Kojto 148:fd96258d940d 15 *
Kojto 148:fd96258d940d 16 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
Kojto 148:fd96258d940d 17 * used to endorse or promote products derived from this software without specific prior
Kojto 148:fd96258d940d 18 * written permission.
Kojto 148:fd96258d940d 19 *
Kojto 148:fd96258d940d 20 * 4. This software, with or without modification, must only be used with a
Kojto 148:fd96258d940d 21 * Nordic Semiconductor ASA integrated circuit.
Kojto 148:fd96258d940d 22 *
Kojto 148:fd96258d940d 23 * 5. Any software provided in binary or object form under this license must not be reverse
Kojto 148:fd96258d940d 24 * engineered, decompiled, modified and/or disassembled.
Kojto 148:fd96258d940d 25 *
Kojto 148:fd96258d940d 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
Kojto 148:fd96258d940d 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Kojto 148:fd96258d940d 28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Kojto 148:fd96258d940d 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
Kojto 148:fd96258d940d 30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Kojto 148:fd96258d940d 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Kojto 148:fd96258d940d 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
Kojto 148:fd96258d940d 33 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Kojto 148:fd96258d940d 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Kojto 148:fd96258d940d 35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kojto 148:fd96258d940d 36 *
Kojto 148:fd96258d940d 37 */
Kojto 148:fd96258d940d 38
Kojto 148:fd96258d940d 39
Kojto 148:fd96258d940d 40 #ifndef NRF_ADC_H_
Kojto 148:fd96258d940d 41 #define NRF_ADC_H_
Kojto 148:fd96258d940d 42
Kojto 148:fd96258d940d 43 /**
Kojto 148:fd96258d940d 44 * @defgroup nrf_adc_hal ADC HAL
Kojto 148:fd96258d940d 45 * @{
Kojto 148:fd96258d940d 46 * @ingroup nrf_adc
Kojto 148:fd96258d940d 47 * @brief @tagAPI51 Hardware access layer for managing the analog-to-digital converter (ADC).
Kojto 148:fd96258d940d 48 */
Kojto 148:fd96258d940d 49
Kojto 148:fd96258d940d 50 #include <stdbool.h>
Kojto 148:fd96258d940d 51 #include <stddef.h>
Kojto 148:fd96258d940d 52
Kojto 148:fd96258d940d 53 #include "nrf.h"
Kojto 148:fd96258d940d 54
Kojto 148:fd96258d940d 55 #ifndef NRF52
Kojto 148:fd96258d940d 56 /**
Kojto 148:fd96258d940d 57 * @enum nrf_adc_config_resolution_t
Kojto 148:fd96258d940d 58 * @brief Resolution of the analog-to-digital converter.
Kojto 148:fd96258d940d 59 */
Kojto 148:fd96258d940d 60
Kojto 148:fd96258d940d 61 /**
Kojto 148:fd96258d940d 62 * @brief ADC interrupts.
Kojto 148:fd96258d940d 63 */
Kojto 148:fd96258d940d 64 typedef enum
Kojto 148:fd96258d940d 65 {
Kojto 148:fd96258d940d 66 NRF_ADC_INT_END_MASK = ADC_INTENSET_END_Msk, /**< ADC interrupt on END event. */
Kojto 148:fd96258d940d 67 } nrf_adc_int_mask_t;
Kojto 148:fd96258d940d 68
Kojto 148:fd96258d940d 69 typedef enum
Kojto 148:fd96258d940d 70 {
Kojto 148:fd96258d940d 71 NRF_ADC_CONFIG_RES_8BIT = ADC_CONFIG_RES_8bit, /**< 8 bit resolution. */
Kojto 148:fd96258d940d 72 NRF_ADC_CONFIG_RES_9BIT = ADC_CONFIG_RES_9bit, /**< 9 bit resolution. */
Kojto 148:fd96258d940d 73 NRF_ADC_CONFIG_RES_10BIT = ADC_CONFIG_RES_10bit, /**< 10 bit resolution. */
Kojto 148:fd96258d940d 74 } nrf_adc_config_resolution_t;
Kojto 148:fd96258d940d 75
Kojto 148:fd96258d940d 76
Kojto 148:fd96258d940d 77 /**
Kojto 148:fd96258d940d 78 * @enum nrf_adc_config_scaling_t
Kojto 148:fd96258d940d 79 * @brief Scaling factor of the analog-to-digital conversion.
Kojto 148:fd96258d940d 80 */
Kojto 148:fd96258d940d 81 typedef enum
Kojto 148:fd96258d940d 82 {
Kojto 148:fd96258d940d 83 NRF_ADC_CONFIG_SCALING_INPUT_FULL_SCALE = ADC_CONFIG_INPSEL_AnalogInputNoPrescaling, /**< Full scale input. */
Kojto 148:fd96258d940d 84 NRF_ADC_CONFIG_SCALING_INPUT_TWO_THIRDS = ADC_CONFIG_INPSEL_AnalogInputTwoThirdsPrescaling, /**< 2/3 scale input. */
Kojto 148:fd96258d940d 85 NRF_ADC_CONFIG_SCALING_INPUT_ONE_THIRD = ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling, /**< 1/3 scale input. */
Kojto 148:fd96258d940d 86 NRF_ADC_CONFIG_SCALING_SUPPLY_TWO_THIRDS = ADC_CONFIG_INPSEL_SupplyTwoThirdsPrescaling, /**< 2/3 of supply. */
Kojto 148:fd96258d940d 87 NRF_ADC_CONFIG_SCALING_SUPPLY_ONE_THIRD = ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling /**< 1/3 of supply. */
Kojto 148:fd96258d940d 88 } nrf_adc_config_scaling_t;
Kojto 148:fd96258d940d 89
Kojto 148:fd96258d940d 90 /**
Kojto 148:fd96258d940d 91 * @enum nrf_adc_config_reference_t
Kojto 148:fd96258d940d 92 * @brief Reference selection of the analog-to-digital converter.
Kojto 148:fd96258d940d 93 */
Kojto 148:fd96258d940d 94 typedef enum
Kojto 148:fd96258d940d 95 {
Kojto 148:fd96258d940d 96 NRF_ADC_CONFIG_REF_VBG = ADC_CONFIG_REFSEL_VBG, /**< 1.2 V reference. */
Kojto 148:fd96258d940d 97 NRF_ADC_CONFIG_REF_SUPPLY_ONE_HALF = ADC_CONFIG_REFSEL_SupplyOneHalfPrescaling, /**< 1/2 of power supply. */
Kojto 148:fd96258d940d 98 NRF_ADC_CONFIG_REF_SUPPLY_ONE_THIRD = ADC_CONFIG_REFSEL_SupplyOneThirdPrescaling, /**< 1/3 of power supply. */
Kojto 148:fd96258d940d 99 NRF_ADC_CONFIG_REF_EXT_REF0 = ADC_CONFIG_REFSEL_External |
Kojto 148:fd96258d940d 100 ADC_CONFIG_EXTREFSEL_AnalogReference0 <<
Kojto 148:fd96258d940d 101 ADC_CONFIG_EXTREFSEL_Pos, /**< External reference 0. */
Kojto 148:fd96258d940d 102 NRF_ADC_CONFIG_REF_EXT_REF1 = ADC_CONFIG_REFSEL_External |
Kojto 148:fd96258d940d 103 ADC_CONFIG_EXTREFSEL_AnalogReference1 << ADC_CONFIG_EXTREFSEL_Pos, /**< External reference 0. */
Kojto 148:fd96258d940d 104 } nrf_adc_config_reference_t;
Kojto 148:fd96258d940d 105
Kojto 148:fd96258d940d 106 /**
Kojto 148:fd96258d940d 107 * @enum nrf_adc_config_input_t
Kojto 148:fd96258d940d 108 * @brief Input selection of the analog-to-digital converter.
Kojto 148:fd96258d940d 109 */
Kojto 148:fd96258d940d 110 typedef enum
Kojto 148:fd96258d940d 111 {
Kojto 148:fd96258d940d 112 NRF_ADC_CONFIG_INPUT_DISABLED = ADC_CONFIG_PSEL_Disabled, /**< No input selected. */
Kojto 148:fd96258d940d 113 NRF_ADC_CONFIG_INPUT_0 = ADC_CONFIG_PSEL_AnalogInput0, /**< Input 0. */
Kojto 148:fd96258d940d 114 NRF_ADC_CONFIG_INPUT_1 = ADC_CONFIG_PSEL_AnalogInput1, /**< Input 1. */
Kojto 148:fd96258d940d 115 NRF_ADC_CONFIG_INPUT_2 = ADC_CONFIG_PSEL_AnalogInput2, /**< Input 2. */
Kojto 148:fd96258d940d 116 NRF_ADC_CONFIG_INPUT_3 = ADC_CONFIG_PSEL_AnalogInput3, /**< Input 3. */
Kojto 148:fd96258d940d 117 NRF_ADC_CONFIG_INPUT_4 = ADC_CONFIG_PSEL_AnalogInput4, /**< Input 4. */
Kojto 148:fd96258d940d 118 NRF_ADC_CONFIG_INPUT_5 = ADC_CONFIG_PSEL_AnalogInput5, /**< Input 5. */
Kojto 148:fd96258d940d 119 NRF_ADC_CONFIG_INPUT_6 = ADC_CONFIG_PSEL_AnalogInput6, /**< Input 6. */
Kojto 148:fd96258d940d 120 NRF_ADC_CONFIG_INPUT_7 = ADC_CONFIG_PSEL_AnalogInput7, /**< Input 7. */
Kojto 148:fd96258d940d 121 } nrf_adc_config_input_t;
Kojto 148:fd96258d940d 122
Kojto 148:fd96258d940d 123 /**
Kojto 148:fd96258d940d 124 * @enum nrf_adc_task_t
Kojto 148:fd96258d940d 125 * @brief Analog-to-digital converter tasks.
Kojto 148:fd96258d940d 126 */
Kojto 148:fd96258d940d 127 typedef enum
Kojto 148:fd96258d940d 128 {
Kojto 148:fd96258d940d 129 /*lint -save -e30*/
Kojto 148:fd96258d940d 130 NRF_ADC_TASK_START = offsetof(NRF_ADC_Type, TASKS_START), /**< ADC start sampling task. */
Kojto 148:fd96258d940d 131 NRF_ADC_TASK_STOP = offsetof(NRF_ADC_Type, TASKS_STOP) /**< ADC stop sampling task. */
Kojto 148:fd96258d940d 132 /*lint -restore*/
Kojto 148:fd96258d940d 133 } nrf_adc_task_t;
Kojto 148:fd96258d940d 134
Kojto 148:fd96258d940d 135 /**
Kojto 148:fd96258d940d 136 * @enum nrf_adc_event_t
Kojto 148:fd96258d940d 137 * @brief Analog-to-digital converter events.
Kojto 148:fd96258d940d 138 */
Kojto 148:fd96258d940d 139 typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
Kojto 148:fd96258d940d 140 {
Kojto 148:fd96258d940d 141 /*lint -save -e30*/
Kojto 148:fd96258d940d 142 NRF_ADC_EVENT_END = offsetof(NRF_ADC_Type, EVENTS_END) /**< End of conversion event. */
Kojto 148:fd96258d940d 143 /*lint -restore*/
Kojto 148:fd96258d940d 144 } nrf_adc_event_t;
Kojto 148:fd96258d940d 145
Kojto 148:fd96258d940d 146 /**@brief Analog-to-digital converter configuration. */
Kojto 148:fd96258d940d 147 typedef struct
Kojto 148:fd96258d940d 148 {
Kojto 148:fd96258d940d 149 nrf_adc_config_resolution_t resolution; /**< ADC resolution. */
Kojto 148:fd96258d940d 150 nrf_adc_config_scaling_t scaling; /**< ADC scaling factor. */
Kojto 148:fd96258d940d 151 nrf_adc_config_reference_t reference; /**< ADC reference. */
Kojto 148:fd96258d940d 152 } nrf_adc_config_t;
Kojto 148:fd96258d940d 153
Kojto 148:fd96258d940d 154 /** Default ADC configuration. */
Kojto 148:fd96258d940d 155 #define NRF_ADC_CONFIG_DEFAULT { NRF_ADC_CONFIG_RES_10BIT, \
Kojto 148:fd96258d940d 156 NRF_ADC_CONFIG_SCALING_INPUT_ONE_THIRD, \
Kojto 148:fd96258d940d 157 NRF_ADC_CONFIG_REF_VBG }
Kojto 148:fd96258d940d 158
Kojto 148:fd96258d940d 159 /**
Kojto 148:fd96258d940d 160 * @brief Function for configuring ADC.
Kojto 148:fd96258d940d 161 *
Kojto 148:fd96258d940d 162 * This function powers on the analog-to-digital converter and configures it.
Kojto 148:fd96258d940d 163 * After the configuration, the ADC is in DISABLE state and must be
Kojto 148:fd96258d940d 164 * enabled before using it.
Kojto 148:fd96258d940d 165 *
Kojto 148:fd96258d940d 166 * @param[in] config Configuration parameters.
Kojto 148:fd96258d940d 167 */
Kojto 148:fd96258d940d 168 void nrf_adc_configure(nrf_adc_config_t * config);
Kojto 148:fd96258d940d 169
Kojto 148:fd96258d940d 170 /**
Kojto 148:fd96258d940d 171 * @brief Blocking function for executing a single ADC conversion.
Kojto 148:fd96258d940d 172 *
Kojto 148:fd96258d940d 173 * This function selects the desired input, starts a single conversion,
Kojto 148:fd96258d940d 174 * waits for it to finish, and returns the result.
Kojto 148:fd96258d940d 175 * After the input is selected, the analog-to-digital converter
Kojto 148:fd96258d940d 176 * is left in STOP state.
Kojto 148:fd96258d940d 177 * The function does not check if the ADC is initialized and powered.
Kojto 148:fd96258d940d 178 *
Kojto 148:fd96258d940d 179 * @param[in] input Input to be selected.
Kojto 148:fd96258d940d 180 *
Kojto 148:fd96258d940d 181 * @return Conversion result.
Kojto 148:fd96258d940d 182 */
Kojto 148:fd96258d940d 183 int32_t nrf_adc_convert_single(nrf_adc_config_input_t input);
Kojto 148:fd96258d940d 184
Kojto 148:fd96258d940d 185 /**
Kojto 148:fd96258d940d 186 * @brief Function for selecting ADC input.
Kojto 148:fd96258d940d 187 *
Kojto 148:fd96258d940d 188 * This function selects the active input of ADC. Ensure that
Kojto 148:fd96258d940d 189 * the ADC is powered on and in IDLE state before calling this function.
Kojto 148:fd96258d940d 190 *
Kojto 148:fd96258d940d 191 * @param[in] input Input to be selected.
Kojto 148:fd96258d940d 192 */
Kojto 148:fd96258d940d 193 __STATIC_INLINE void nrf_adc_input_select(nrf_adc_config_input_t input)
Kojto 148:fd96258d940d 194 {
Kojto 148:fd96258d940d 195 NRF_ADC->CONFIG =
Kojto 148:fd96258d940d 196 ((uint32_t)input << ADC_CONFIG_PSEL_Pos) | (NRF_ADC->CONFIG & ~ADC_CONFIG_PSEL_Msk);
Kojto 148:fd96258d940d 197
Kojto 148:fd96258d940d 198 if (input != NRF_ADC_CONFIG_INPUT_DISABLED)
Kojto 148:fd96258d940d 199 {
Kojto 148:fd96258d940d 200 NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled << ADC_ENABLE_ENABLE_Pos;
Kojto 148:fd96258d940d 201 }
Kojto 148:fd96258d940d 202 else
Kojto 148:fd96258d940d 203 {
Kojto 148:fd96258d940d 204 NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Disabled << ADC_ENABLE_ENABLE_Pos;
Kojto 148:fd96258d940d 205 }
Kojto 148:fd96258d940d 206 }
Kojto 148:fd96258d940d 207
Kojto 148:fd96258d940d 208
Kojto 148:fd96258d940d 209 /**
Kojto 148:fd96258d940d 210 * @brief Function for retrieving the ADC conversion result.
Kojto 148:fd96258d940d 211 *
Kojto 148:fd96258d940d 212 * This function retrieves and returns the last analog-to-digital conversion result.
Kojto 148:fd96258d940d 213 *
Kojto 148:fd96258d940d 214 * @return Last conversion result.
Kojto 148:fd96258d940d 215 */
Kojto 148:fd96258d940d 216 __STATIC_INLINE int32_t nrf_adc_result_get(void)
Kojto 148:fd96258d940d 217 {
Kojto 148:fd96258d940d 218 return (int32_t)NRF_ADC->RESULT;
Kojto 148:fd96258d940d 219 }
Kojto 148:fd96258d940d 220
Kojto 148:fd96258d940d 221
Kojto 148:fd96258d940d 222 /**
Kojto 148:fd96258d940d 223 * @brief Function for checking whether the ADC is busy.
Kojto 148:fd96258d940d 224 *
Kojto 148:fd96258d940d 225 * This function checks whether the analog-to-digital converter is busy with a conversion.
Kojto 148:fd96258d940d 226 *
Kojto 148:fd96258d940d 227 * @retval true If the ADC is busy.
Kojto 148:fd96258d940d 228 * @retval false If the ADC is not busy.
Kojto 148:fd96258d940d 229 */
Kojto 148:fd96258d940d 230 __STATIC_INLINE bool nrf_adc_is_busy(void)
Kojto 148:fd96258d940d 231 {
Kojto 148:fd96258d940d 232 return ( (NRF_ADC->BUSY & ADC_BUSY_BUSY_Msk) == ADC_BUSY_BUSY_Msk);
Kojto 148:fd96258d940d 233 }
Kojto 148:fd96258d940d 234
Kojto 148:fd96258d940d 235 /**
Kojto 148:fd96258d940d 236 * @brief Function for getting the ADC's enabled interrupts.
Kojto 148:fd96258d940d 237 *
Kojto 148:fd96258d940d 238 * @param[in] mask Mask of interrupts to check.
Kojto 148:fd96258d940d 239 *
Kojto 148:fd96258d940d 240 * @return State of the interrupts selected by the mask.
Kojto 148:fd96258d940d 241 *
Kojto 148:fd96258d940d 242 * @sa nrf_adc_int_enable()
Kojto 148:fd96258d940d 243 * @sa nrf_adc_int_disable()
Kojto 148:fd96258d940d 244 */
Kojto 148:fd96258d940d 245 __STATIC_INLINE uint32_t nrf_adc_int_get(uint32_t mask)
Kojto 148:fd96258d940d 246 {
Kojto 148:fd96258d940d 247 return (NRF_ADC->INTENSET & mask); // when read this register will return the value of INTEN.
Kojto 148:fd96258d940d 248 }
Kojto 148:fd96258d940d 249
Kojto 148:fd96258d940d 250
Kojto 148:fd96258d940d 251 /**
Kojto 148:fd96258d940d 252 * @brief Function for starting conversion.
Kojto 148:fd96258d940d 253 *
Kojto 148:fd96258d940d 254 * @sa nrf_adc_stop()
Kojto 148:fd96258d940d 255 *
Kojto 148:fd96258d940d 256 */
Kojto 148:fd96258d940d 257 __STATIC_INLINE void nrf_adc_start(void)
Kojto 148:fd96258d940d 258 {
Kojto 148:fd96258d940d 259 NRF_ADC->TASKS_START = 1;
Kojto 148:fd96258d940d 260 }
Kojto 148:fd96258d940d 261
Kojto 148:fd96258d940d 262
Kojto 148:fd96258d940d 263 /**
Kojto 148:fd96258d940d 264 * @brief Function for stopping conversion.
Kojto 148:fd96258d940d 265 *
Kojto 148:fd96258d940d 266 * If the analog-to-digital converter is in inactive state, power consumption is reduced.
Kojto 148:fd96258d940d 267 *
Kojto 148:fd96258d940d 268 * @sa nrf_adc_start()
Kojto 148:fd96258d940d 269 *
Kojto 148:fd96258d940d 270 */
Kojto 148:fd96258d940d 271 __STATIC_INLINE void nrf_adc_stop(void)
Kojto 148:fd96258d940d 272 {
Kojto 148:fd96258d940d 273 NRF_ADC->TASKS_STOP = 1;
Kojto 148:fd96258d940d 274 }
Kojto 148:fd96258d940d 275
Kojto 148:fd96258d940d 276
Kojto 148:fd96258d940d 277 /**
Kojto 148:fd96258d940d 278 * @brief Function for checking if the requested ADC conversion has ended.
Kojto 148:fd96258d940d 279 *
Kojto 148:fd96258d940d 280 * @retval true If the task has finished.
Kojto 148:fd96258d940d 281 * @retval false If the task is still running.
Kojto 148:fd96258d940d 282 */
Kojto 148:fd96258d940d 283 __STATIC_INLINE bool nrf_adc_conversion_finished(void)
Kojto 148:fd96258d940d 284 {
Kojto 148:fd96258d940d 285 return ((bool)NRF_ADC->EVENTS_END);
Kojto 148:fd96258d940d 286 }
Kojto 148:fd96258d940d 287
Kojto 148:fd96258d940d 288 /**
Kojto 148:fd96258d940d 289 * @brief Function for clearing the conversion END event.
Kojto 148:fd96258d940d 290 */
Kojto 148:fd96258d940d 291 __STATIC_INLINE void nrf_adc_conversion_event_clean(void)
Kojto 148:fd96258d940d 292 {
Kojto 148:fd96258d940d 293 NRF_ADC->EVENTS_END = 0;
Kojto 148:fd96258d940d 294 }
Kojto 148:fd96258d940d 295
Kojto 148:fd96258d940d 296 /**
Kojto 148:fd96258d940d 297 * @brief Function for getting the address of an ADC task register.
Kojto 148:fd96258d940d 298 *
Kojto 148:fd96258d940d 299 * @param[in] adc_task ADC task.
Kojto 148:fd96258d940d 300 *
Kojto 148:fd96258d940d 301 * @return Address of the specified ADC task.
Kojto 148:fd96258d940d 302 */
Kojto 148:fd96258d940d 303 __STATIC_INLINE uint32_t nrf_adc_task_address_get(nrf_adc_task_t adc_task);
Kojto 148:fd96258d940d 304
Kojto 148:fd96258d940d 305 /**
Kojto 148:fd96258d940d 306 * @brief Function for getting the address of a specific ADC event register.
Kojto 148:fd96258d940d 307 *
Kojto 148:fd96258d940d 308 * @param[in] adc_event ADC event.
Kojto 148:fd96258d940d 309 *
Kojto 148:fd96258d940d 310 * @return Address of the specified ADC event.
Kojto 148:fd96258d940d 311 */
Kojto 148:fd96258d940d 312 __STATIC_INLINE uint32_t nrf_adc_event_address_get(nrf_adc_event_t adc_event);
Kojto 148:fd96258d940d 313
Kojto 148:fd96258d940d 314 /**
Kojto 148:fd96258d940d 315 * @brief Function for setting the CONFIG register in ADC.
Kojto 148:fd96258d940d 316 *
Kojto 148:fd96258d940d 317 * @param[in] configuration Value to be written to the CONFIG register.
Kojto 148:fd96258d940d 318 */
Kojto 148:fd96258d940d 319 __STATIC_INLINE void nrf_adc_config_set(uint32_t configuration);
Kojto 148:fd96258d940d 320
Kojto 148:fd96258d940d 321 /**
Kojto 148:fd96258d940d 322 * @brief Function for clearing an ADC event.
Kojto 148:fd96258d940d 323 *
Kojto 148:fd96258d940d 324 * @param[in] event Event to clear.
Kojto 148:fd96258d940d 325 */
Kojto 148:fd96258d940d 326 __STATIC_INLINE void nrf_adc_event_clear(nrf_adc_event_t event);
Kojto 148:fd96258d940d 327
Kojto 148:fd96258d940d 328 /**
Kojto 148:fd96258d940d 329 * @brief Function for checking state of an ADC event.
Kojto 148:fd96258d940d 330 *
Kojto 148:fd96258d940d 331 * @param[in] event Event to check.
Kojto 148:fd96258d940d 332 *
Kojto 148:fd96258d940d 333 * @retval true If the event is set.
Kojto 148:fd96258d940d 334 * @retval false If the event is not set.
Kojto 148:fd96258d940d 335 */
Kojto 148:fd96258d940d 336 __STATIC_INLINE bool nrf_adc_event_check(nrf_adc_event_t event);
Kojto 148:fd96258d940d 337
Kojto 148:fd96258d940d 338 /**
Kojto 148:fd96258d940d 339 * @brief Function for enabling specified interrupts.
Kojto 148:fd96258d940d 340 *
Kojto 148:fd96258d940d 341 * @param[in] int_mask Interrupts to enable.
Kojto 148:fd96258d940d 342 */
Kojto 148:fd96258d940d 343 __STATIC_INLINE void nrf_adc_int_enable(uint32_t int_mask);
Kojto 148:fd96258d940d 344
Kojto 148:fd96258d940d 345 /**
Kojto 148:fd96258d940d 346 * @brief Function for disabling specified interrupts.
Kojto 148:fd96258d940d 347 *
Kojto 148:fd96258d940d 348 * @param[in] int_mask Interrupts to disable.
Kojto 148:fd96258d940d 349 */
Kojto 148:fd96258d940d 350 __STATIC_INLINE void nrf_adc_int_disable(uint32_t int_mask);
Kojto 148:fd96258d940d 351
Kojto 148:fd96258d940d 352 /**
Kojto 148:fd96258d940d 353 * @brief Function for retrieving the state of a given interrupt.
Kojto 148:fd96258d940d 354 *
Kojto 148:fd96258d940d 355 * @param[in] int_mask Interrupt to check.
Kojto 148:fd96258d940d 356 *
Kojto 148:fd96258d940d 357 * @retval true If the interrupt is enabled.
Kojto 148:fd96258d940d 358 * @retval false If the interrupt is not enabled.
Kojto 148:fd96258d940d 359 */
Kojto 148:fd96258d940d 360 __STATIC_INLINE bool nrf_adc_int_enable_check(nrf_adc_int_mask_t int_mask);
Kojto 148:fd96258d940d 361
Kojto 148:fd96258d940d 362 /**
Kojto 148:fd96258d940d 363 * @brief Function for activating a specific ADC task.
Kojto 148:fd96258d940d 364 *
Kojto 148:fd96258d940d 365 * @param[in] task Task to activate.
Kojto 148:fd96258d940d 366 */
Kojto 148:fd96258d940d 367 __STATIC_INLINE void nrf_adc_task_trigger(nrf_adc_task_t task);
Kojto 148:fd96258d940d 368
Kojto 148:fd96258d940d 369 /**
Kojto 148:fd96258d940d 370 * @brief Function for enabling ADC.
Kojto 148:fd96258d940d 371 *
Kojto 148:fd96258d940d 372 */
Kojto 148:fd96258d940d 373 __STATIC_INLINE void nrf_adc_enable(void);
Kojto 148:fd96258d940d 374
Kojto 148:fd96258d940d 375 /**
Kojto 148:fd96258d940d 376 * @brief Function for disabling ADC.
Kojto 148:fd96258d940d 377 *
Kojto 148:fd96258d940d 378 */
Kojto 148:fd96258d940d 379 __STATIC_INLINE void nrf_adc_disable(void);
Kojto 148:fd96258d940d 380
Kojto 148:fd96258d940d 381 #ifndef SUPPRESS_INLINE_IMPLEMENTATION
Kojto 148:fd96258d940d 382
Kojto 148:fd96258d940d 383 __STATIC_INLINE uint32_t nrf_adc_task_address_get(nrf_adc_task_t adc_task)
Kojto 148:fd96258d940d 384 {
Kojto 148:fd96258d940d 385 return (uint32_t)((uint8_t *)NRF_ADC + adc_task);
Kojto 148:fd96258d940d 386 }
Kojto 148:fd96258d940d 387
Kojto 148:fd96258d940d 388 __STATIC_INLINE uint32_t nrf_adc_event_address_get(nrf_adc_event_t adc_event)
Kojto 148:fd96258d940d 389 {
Kojto 148:fd96258d940d 390 return (uint32_t)((uint8_t *)NRF_ADC + adc_event);
Kojto 148:fd96258d940d 391 }
Kojto 148:fd96258d940d 392
Kojto 148:fd96258d940d 393 __STATIC_INLINE void nrf_adc_config_set(uint32_t configuration)
Kojto 148:fd96258d940d 394 {
Kojto 148:fd96258d940d 395 NRF_ADC->CONFIG = configuration;
Kojto 148:fd96258d940d 396 }
Kojto 148:fd96258d940d 397
Kojto 148:fd96258d940d 398 __STATIC_INLINE void nrf_adc_event_clear(nrf_adc_event_t event)
Kojto 148:fd96258d940d 399 {
Kojto 148:fd96258d940d 400 *((volatile uint32_t *)((uint8_t *)NRF_ADC + (uint32_t)event)) = 0x0UL;
Kojto 148:fd96258d940d 401 }
Kojto 148:fd96258d940d 402
Kojto 148:fd96258d940d 403 __STATIC_INLINE bool nrf_adc_event_check(nrf_adc_event_t event)
Kojto 148:fd96258d940d 404 {
Kojto 148:fd96258d940d 405 return (bool)*(volatile uint32_t *)((uint8_t *)NRF_ADC + (uint32_t)event);
Kojto 148:fd96258d940d 406 }
Kojto 148:fd96258d940d 407
Kojto 148:fd96258d940d 408 __STATIC_INLINE void nrf_adc_int_enable(uint32_t int_mask)
Kojto 148:fd96258d940d 409 {
Kojto 148:fd96258d940d 410 NRF_ADC->INTENSET = int_mask;
Kojto 148:fd96258d940d 411 }
Kojto 148:fd96258d940d 412
Kojto 148:fd96258d940d 413 __STATIC_INLINE void nrf_adc_int_disable(uint32_t int_mask)
Kojto 148:fd96258d940d 414 {
Kojto 148:fd96258d940d 415 NRF_ADC->INTENCLR = int_mask;
Kojto 148:fd96258d940d 416 }
Kojto 148:fd96258d940d 417
Kojto 148:fd96258d940d 418 __STATIC_INLINE bool nrf_adc_int_enable_check(nrf_adc_int_mask_t int_mask)
Kojto 148:fd96258d940d 419 {
Kojto 148:fd96258d940d 420 return (bool)(NRF_ADC->INTENSET & int_mask);
Kojto 148:fd96258d940d 421 }
Kojto 148:fd96258d940d 422
Kojto 148:fd96258d940d 423 __STATIC_INLINE void nrf_adc_task_trigger(nrf_adc_task_t task)
Kojto 148:fd96258d940d 424 {
Kojto 148:fd96258d940d 425 *((volatile uint32_t *)((uint8_t *)NRF_ADC + (uint32_t)task)) = 0x1UL;
Kojto 148:fd96258d940d 426 }
Kojto 148:fd96258d940d 427
Kojto 148:fd96258d940d 428 __STATIC_INLINE void nrf_adc_enable(void)
Kojto 148:fd96258d940d 429 {
Kojto 148:fd96258d940d 430 NRF_ADC->ENABLE = 1;
Kojto 148:fd96258d940d 431 }
Kojto 148:fd96258d940d 432
Kojto 148:fd96258d940d 433 __STATIC_INLINE void nrf_adc_disable(void)
Kojto 148:fd96258d940d 434 {
Kojto 148:fd96258d940d 435 NRF_ADC->ENABLE = 0;
Kojto 148:fd96258d940d 436 }
Kojto 148:fd96258d940d 437 #endif
Kojto 148:fd96258d940d 438 #endif /* NRF52 */
Kojto 148:fd96258d940d 439 /**
Kojto 148:fd96258d940d 440 *@}
Kojto 148:fd96258d940d 441 **/
Kojto 148:fd96258d940d 442
Kojto 148:fd96258d940d 443 #endif /* NRF_ADC_H_ */