123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- #ifndef NRF_ADC_H_
- #define NRF_ADC_H_
- #include <nrfx.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef enum
- {
- NRF_ADC_INT_END_MASK = ADC_INTENSET_END_Msk,
- } nrf_adc_int_mask_t;
- typedef enum
- {
- NRF_ADC_CONFIG_RES_8BIT = ADC_CONFIG_RES_8bit,
- NRF_ADC_CONFIG_RES_9BIT = ADC_CONFIG_RES_9bit,
- NRF_ADC_CONFIG_RES_10BIT = ADC_CONFIG_RES_10bit,
- } nrf_adc_config_resolution_t;
- typedef enum
- {
- NRF_ADC_CONFIG_SCALING_INPUT_FULL_SCALE = ADC_CONFIG_INPSEL_AnalogInputNoPrescaling,
- NRF_ADC_CONFIG_SCALING_INPUT_TWO_THIRDS = ADC_CONFIG_INPSEL_AnalogInputTwoThirdsPrescaling,
- NRF_ADC_CONFIG_SCALING_INPUT_ONE_THIRD = ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling,
- NRF_ADC_CONFIG_SCALING_SUPPLY_TWO_THIRDS = ADC_CONFIG_INPSEL_SupplyTwoThirdsPrescaling,
- NRF_ADC_CONFIG_SCALING_SUPPLY_ONE_THIRD = ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling
- } nrf_adc_config_scaling_t;
- typedef enum
- {
- NRF_ADC_CONFIG_EXTREFSEL_NONE = ADC_CONFIG_EXTREFSEL_None,
- NRF_ADC_CONFIG_EXTREFSEL_AREF0 = ADC_CONFIG_EXTREFSEL_AnalogReference0,
- NRF_ADC_CONFIG_EXTREFSEL_AREF1 = ADC_CONFIG_EXTREFSEL_AnalogReference1
- } nrf_adc_config_extref_t;
- typedef enum
- {
- NRF_ADC_CONFIG_REF_VBG = ADC_CONFIG_REFSEL_VBG,
- NRF_ADC_CONFIG_REF_SUPPLY_ONE_HALF = ADC_CONFIG_REFSEL_SupplyOneHalfPrescaling,
- NRF_ADC_CONFIG_REF_SUPPLY_ONE_THIRD = ADC_CONFIG_REFSEL_SupplyOneThirdPrescaling,
- NRF_ADC_CONFIG_REF_EXT = ADC_CONFIG_REFSEL_External
- } nrf_adc_config_reference_t;
- typedef enum
- {
- NRF_ADC_CONFIG_INPUT_DISABLED = ADC_CONFIG_PSEL_Disabled,
- NRF_ADC_CONFIG_INPUT_0 = ADC_CONFIG_PSEL_AnalogInput0,
- NRF_ADC_CONFIG_INPUT_1 = ADC_CONFIG_PSEL_AnalogInput1,
- NRF_ADC_CONFIG_INPUT_2 = ADC_CONFIG_PSEL_AnalogInput2,
- NRF_ADC_CONFIG_INPUT_3 = ADC_CONFIG_PSEL_AnalogInput3,
- NRF_ADC_CONFIG_INPUT_4 = ADC_CONFIG_PSEL_AnalogInput4,
- NRF_ADC_CONFIG_INPUT_5 = ADC_CONFIG_PSEL_AnalogInput5,
- NRF_ADC_CONFIG_INPUT_6 = ADC_CONFIG_PSEL_AnalogInput6,
- NRF_ADC_CONFIG_INPUT_7 = ADC_CONFIG_PSEL_AnalogInput7,
- } nrf_adc_config_input_t;
- typedef enum
- {
- NRF_ADC_TASK_START = offsetof(NRF_ADC_Type, TASKS_START),
- NRF_ADC_TASK_STOP = offsetof(NRF_ADC_Type, TASKS_STOP)
- } nrf_adc_task_t;
- typedef enum
- {
- NRF_ADC_EVENT_END = offsetof(NRF_ADC_Type, EVENTS_END)
- } nrf_adc_event_t;
- typedef struct
- {
- nrf_adc_config_resolution_t resolution;
- nrf_adc_config_scaling_t scaling;
- nrf_adc_config_reference_t reference;
- nrf_adc_config_input_t input;
- nrf_adc_config_extref_t extref;
- } nrf_adc_config_t;
- typedef uint16_t nrf_adc_value_t;
- __STATIC_INLINE void nrf_adc_task_trigger(nrf_adc_task_t task);
- __STATIC_INLINE uint32_t nrf_adc_task_address_get(nrf_adc_task_t task);
- __STATIC_INLINE bool nrf_adc_event_check(nrf_adc_event_t event);
- __STATIC_INLINE void nrf_adc_event_clear(nrf_adc_event_t event);
- __STATIC_INLINE uint32_t nrf_adc_event_address_get(nrf_adc_event_t adc_event);
- __STATIC_INLINE void nrf_adc_int_enable(uint32_t mask);
- __STATIC_INLINE void nrf_adc_int_disable(uint32_t mask);
- __STATIC_INLINE bool nrf_adc_int_enable_check(uint32_t mask);
- __STATIC_INLINE bool nrf_adc_busy_check(void);
- __STATIC_INLINE void nrf_adc_enable(void);
- __STATIC_INLINE void nrf_adc_disable(void);
- __STATIC_INLINE bool nrf_adc_enable_check(void);
- __STATIC_INLINE nrf_adc_value_t nrf_adc_result_get(void);
- __STATIC_INLINE void nrf_adc_init(nrf_adc_config_t const * p_config);
- #ifndef SUPPRESS_INLINE_IMPLEMENTATION
- __STATIC_INLINE void nrf_adc_task_trigger(nrf_adc_task_t task)
- {
- *((volatile uint32_t *)((uint8_t *)NRF_ADC + (uint32_t)task)) = 0x1UL;
- }
- __STATIC_INLINE uint32_t nrf_adc_task_address_get(nrf_adc_task_t adc_task)
- {
- return (uint32_t)((uint8_t *)NRF_ADC + (uint32_t)adc_task);
- }
- __STATIC_INLINE bool nrf_adc_event_check(nrf_adc_event_t event)
- {
- return (bool)*(volatile uint32_t *)((uint8_t *)NRF_ADC + (uint32_t)event);
- }
- __STATIC_INLINE void nrf_adc_event_clear(nrf_adc_event_t event)
- {
- *((volatile uint32_t *)((uint8_t *)NRF_ADC + (uint32_t)event)) = 0x0UL;
- }
- __STATIC_INLINE uint32_t nrf_adc_event_address_get(nrf_adc_event_t adc_event)
- {
- return (uint32_t)((uint8_t *)NRF_ADC + (uint32_t)adc_event);
- }
- __STATIC_INLINE void nrf_adc_int_enable(uint32_t mask)
- {
- NRF_ADC->INTENSET = mask;
- }
- __STATIC_INLINE void nrf_adc_int_disable(uint32_t mask)
- {
- NRF_ADC->INTENCLR = mask;
- }
- __STATIC_INLINE bool nrf_adc_int_enable_check(uint32_t mask)
- {
- return (bool)(NRF_ADC->INTENSET & mask);
- }
- __STATIC_INLINE bool nrf_adc_busy_check(void)
- {
- return ((NRF_ADC->BUSY & ADC_BUSY_BUSY_Msk) == (ADC_BUSY_BUSY_Busy << ADC_BUSY_BUSY_Pos));
- }
- __STATIC_INLINE void nrf_adc_enable(void)
- {
- NRF_ADC->ENABLE = (ADC_ENABLE_ENABLE_Enabled << ADC_ENABLE_ENABLE_Pos);
- }
- __STATIC_INLINE void nrf_adc_disable(void)
- {
- NRF_ADC->ENABLE = (ADC_ENABLE_ENABLE_Disabled << ADC_ENABLE_ENABLE_Pos);
- }
- __STATIC_INLINE bool nrf_adc_enable_check(void)
- {
- return (NRF_ADC->ENABLE == (ADC_ENABLE_ENABLE_Enabled << ADC_ENABLE_ENABLE_Pos));
- }
- __STATIC_INLINE nrf_adc_value_t nrf_adc_result_get(void)
- {
- return (nrf_adc_value_t)NRF_ADC->RESULT;
- }
- __STATIC_INLINE void nrf_adc_init(nrf_adc_config_t const * p_config)
- {
- NRF_ADC->CONFIG =
- ((p_config->resolution << ADC_CONFIG_RES_Pos) & ADC_CONFIG_RES_Msk)
- |((p_config->scaling << ADC_CONFIG_INPSEL_Pos) & ADC_CONFIG_INPSEL_Msk)
- |((p_config->reference << ADC_CONFIG_REFSEL_Pos) & ADC_CONFIG_REFSEL_Msk)
- |((p_config->input << ADC_CONFIG_PSEL_Pos) & ADC_CONFIG_PSEL_Msk)
- |((p_config->extref << ADC_CONFIG_EXTREFSEL_Pos) & ADC_CONFIG_EXTREFSEL_Msk);
- }
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif
|