123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474 |
- #ifndef NRF_COMP_H_
- #define NRF_COMP_H_
- #include <nrfx.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef enum
- {
- NRF_COMP_INPUT_0 = COMP_PSEL_PSEL_AnalogInput0,
- NRF_COMP_INPUT_1 = COMP_PSEL_PSEL_AnalogInput1,
- NRF_COMP_INPUT_2 = COMP_PSEL_PSEL_AnalogInput2,
- NRF_COMP_INPUT_3 = COMP_PSEL_PSEL_AnalogInput3,
- #if defined (COMP_PSEL_PSEL_AnalogInput4) || defined (__NRFX_DOXYGEN__)
- NRF_COMP_INPUT_4 = COMP_PSEL_PSEL_AnalogInput4,
- #endif
- #if defined (COMP_PSEL_PSEL_AnalogInput5) || defined (__NRFX_DOXYGEN__)
- NRF_COMP_INPUT_5 = COMP_PSEL_PSEL_AnalogInput5,
- #endif
- #if defined (COMP_PSEL_PSEL_AnalogInput6) || defined (__NRFX_DOXYGEN__)
- NRF_COMP_INPUT_6 = COMP_PSEL_PSEL_AnalogInput6,
- #endif
- #if defined (COMP_PSEL_PSEL_AnalogInput7) || defined (__NRFX_DOXYGEN__)
- NRF_COMP_INPUT_7 = COMP_PSEL_PSEL_AnalogInput7,
- #endif
- #if defined (COMP_PSEL_PSEL_VddDiv2) || defined (__NRFX_DOXYGEN__)
- NRF_COMP_VDD_DIV2 = COMP_PSEL_PSEL_VddDiv2,
- #endif
- #if defined (COMP_PSEL_PSEL_VddhDiv5) || defined (__NRFX_DOXYGEN__)
- NRF_COMP_VDDH_DIV5 = COMP_PSEL_PSEL_VddhDiv5,
- #endif
- } nrf_comp_input_t;
- typedef enum
- {
- NRF_COMP_REF_Int1V2 = COMP_REFSEL_REFSEL_Int1V2,
- NRF_COMP_REF_Int1V8 = COMP_REFSEL_REFSEL_Int1V8,
- NRF_COMP_REF_Int2V4 = COMP_REFSEL_REFSEL_Int2V4,
- NRF_COMP_REF_VDD = COMP_REFSEL_REFSEL_VDD,
- NRF_COMP_REF_ARef = COMP_REFSEL_REFSEL_ARef
- } nrf_comp_ref_t;
- typedef enum
- {
- NRF_COMP_EXT_REF_0 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference0,
- NRF_COMP_EXT_REF_1 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference1,
- NRF_COMP_EXT_REF_2 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference2,
- NRF_COMP_EXT_REF_3 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference3,
- #if defined (COMP_EXTREFSEL_EXTREFSEL_AnalogReference4) || defined (__NRFX_DOXYGEN__)
- NRF_COMP_EXT_REF_4 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference4,
- #endif
- #if defined (COMP_EXTREFSEL_EXTREFSEL_AnalogReference5) || defined (__NRFX_DOXYGEN__)
- NRF_COMP_EXT_REF_5 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference5,
- #endif
- #if defined (COMP_EXTREFSEL_EXTREFSEL_AnalogReference6) || defined (__NRFX_DOXYGEN__)
- NRF_COMP_EXT_REF_6 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference6,
- #endif
- #if defined (COMP_EXTREFSEL_EXTREFSEL_AnalogReference7) || defined (__NRFX_DOXYGEN__)
- NRF_COMP_EXT_REF_7 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference7
- #endif
- } nrf_comp_ext_ref_t;
- typedef struct
- {
- uint8_t th_down;
- uint8_t th_up;
- } nrf_comp_th_t;
- typedef enum
- {
- NRF_COMP_MAIN_MODE_SE = COMP_MODE_MAIN_SE,
- NRF_COMP_MAIN_MODE_Diff = COMP_MODE_MAIN_Diff
- } nrf_comp_main_mode_t;
- typedef enum
- {
- NRF_COMP_SP_MODE_Low = COMP_MODE_SP_Low,
- NRF_COMP_SP_MODE_Normal = COMP_MODE_SP_Normal,
- NRF_COMP_SP_MODE_High = COMP_MODE_SP_High
- } nrf_comp_sp_mode_t;
- typedef enum
- {
- NRF_COMP_HYST_NoHyst = COMP_HYST_HYST_NoHyst,
- NRF_COMP_HYST_50mV = COMP_HYST_HYST_Hyst50mV
- } nrf_comp_hyst_t;
- #if defined (COMP_ISOURCE_ISOURCE_Msk) || defined (__NRFX_DOXYGEN__)
- typedef enum
- {
- NRF_COMP_ISOURCE_Off = COMP_ISOURCE_ISOURCE_Off,
- NRF_COMP_ISOURCE_Ien2uA5 = COMP_ISOURCE_ISOURCE_Ien2mA5,
- NRF_COMP_ISOURCE_Ien5uA = COMP_ISOURCE_ISOURCE_Ien5mA,
- NRF_COMP_ISOURCE_Ien10uA = COMP_ISOURCE_ISOURCE_Ien10mA
- } nrf_isource_t;
- #endif
- typedef enum
- {
- NRF_COMP_TASK_START = offsetof(NRF_COMP_Type, TASKS_START),
- NRF_COMP_TASK_STOP = offsetof(NRF_COMP_Type, TASKS_STOP),
- NRF_COMP_TASK_SAMPLE = offsetof(NRF_COMP_Type, TASKS_SAMPLE)
- } nrf_comp_task_t;
- typedef enum
- {
- NRF_COMP_EVENT_READY = offsetof(NRF_COMP_Type, EVENTS_READY),
- NRF_COMP_EVENT_DOWN = offsetof(NRF_COMP_Type, EVENTS_DOWN),
- NRF_COMP_EVENT_UP = offsetof(NRF_COMP_Type, EVENTS_UP),
- NRF_COMP_EVENT_CROSS = offsetof(NRF_COMP_Type, EVENTS_CROSS)
- } nrf_comp_event_t;
- typedef struct
- {
- nrf_comp_ref_t reference;
- nrf_comp_ext_ref_t external;
- } nrf_comp_ref_conf_t;
- __STATIC_INLINE void nrf_comp_enable(void);
- __STATIC_INLINE void nrf_comp_disable(void);
- __STATIC_INLINE bool nrf_comp_enable_check(void);
- __STATIC_INLINE void nrf_comp_ref_set(nrf_comp_ref_t reference);
- __STATIC_INLINE void nrf_comp_ext_ref_set(nrf_comp_ext_ref_t ext_ref);
- __STATIC_INLINE void nrf_comp_th_set(nrf_comp_th_t threshold);
- __STATIC_INLINE void nrf_comp_main_mode_set(nrf_comp_main_mode_t main_mode);
- __STATIC_INLINE void nrf_comp_speed_mode_set(nrf_comp_sp_mode_t speed_mode);
- __STATIC_INLINE void nrf_comp_hysteresis_set(nrf_comp_hyst_t hyst);
- #if defined (COMP_ISOURCE_ISOURCE_Msk) || defined (__NRFX_DOXYGEN__)
- __STATIC_INLINE void nrf_comp_isource_set(nrf_isource_t isource);
- #endif
- __STATIC_INLINE void nrf_comp_input_select(nrf_comp_input_t input);
- __STATIC_INLINE uint32_t nrf_comp_result_get(void);
- __STATIC_INLINE void nrf_comp_int_enable(uint32_t mask);
- __STATIC_INLINE void nrf_comp_int_disable(uint32_t mask);
- __STATIC_INLINE bool nrf_comp_int_enable_check(uint32_t mask);
- __STATIC_INLINE uint32_t * nrf_comp_task_address_get(nrf_comp_task_t task);
- __STATIC_INLINE uint32_t * nrf_comp_event_address_get(nrf_comp_event_t event);
- __STATIC_INLINE void nrf_comp_shorts_enable(uint32_t mask);
- __STATIC_INLINE void nrf_comp_shorts_disable(uint32_t mask);
- __STATIC_INLINE void nrf_comp_task_trigger(nrf_comp_task_t task);
- __STATIC_INLINE void nrf_comp_event_clear(nrf_comp_event_t event);
- __STATIC_INLINE bool nrf_comp_event_check(nrf_comp_event_t 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 =
- (((uint32_t)threshold.th_down << COMP_TH_THDOWN_Pos) & COMP_TH_THDOWN_Msk) |
- (((uint32_t)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 mask)
- {
- NRF_COMP->INTENSET = mask;
- }
- __STATIC_INLINE void nrf_comp_int_disable(uint32_t mask)
- {
- NRF_COMP->INTENCLR = mask;
- }
- __STATIC_INLINE bool nrf_comp_int_enable_check(uint32_t mask)
- {
- return (NRF_COMP->INTENSET & mask);
- }
- __STATIC_INLINE uint32_t * nrf_comp_task_address_get(nrf_comp_task_t task)
- {
- return (uint32_t *)((uint8_t *)NRF_COMP + (uint32_t)task);
- }
- __STATIC_INLINE uint32_t * nrf_comp_event_address_get(nrf_comp_event_t event)
- {
- return (uint32_t *)((uint8_t *)NRF_COMP + (uint32_t)event);
- }
- __STATIC_INLINE void nrf_comp_shorts_enable(uint32_t mask)
- {
- NRF_COMP->SHORTS |= mask;
- }
- __STATIC_INLINE void nrf_comp_shorts_disable(uint32_t mask)
- {
- NRF_COMP->SHORTS &= ~mask;
- }
- __STATIC_INLINE void nrf_comp_task_trigger(nrf_comp_task_t task)
- {
- *( (volatile uint32_t *)( (uint8_t *)NRF_COMP + (uint32_t)task) ) = 1;
- }
- __STATIC_INLINE void nrf_comp_event_clear(nrf_comp_event_t event)
- {
- *( (volatile uint32_t *)( (uint8_t *)NRF_COMP + (uint32_t)event) ) = 0;
- #if __CORTEX_M == 0x04
- volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_COMP + (uint32_t)event));
- (void)dummy;
- #endif
- }
- __STATIC_INLINE bool nrf_comp_event_check(nrf_comp_event_t event)
- {
- return (bool) (*(volatile uint32_t *)( (uint8_t *)NRF_COMP + (uint32_t)event));
- }
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif
|