123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- #ifndef NRFX_COMP_H__
- #define NRFX_COMP_H__
- #include <nrfx.h>
- #include <hal/nrf_comp.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define NRFX_VOLTAGE_THRESHOLD_TO_INT(vol, ref) \
- (uint8_t)(((vol) > ((ref) / 64)) ? (NRFX_ROUNDED_DIV((vol) * 64,(ref)) - 1) : 0)
- typedef void (* nrfx_comp_event_handler_t)(nrf_comp_event_t event);
- typedef enum
- {
- NRFX_COMP_SHORT_STOP_AFTER_CROSS_EVT = COMP_SHORTS_CROSS_STOP_Msk,
- NRFX_COMP_SHORT_STOP_AFTER_UP_EVT = COMP_SHORTS_UP_STOP_Msk,
- NRFX_COMP_SHORT_STOP_AFTER_DOWN_EVT = COMP_SHORTS_DOWN_STOP_Msk
- } nrfx_comp_short_mask_t;
- typedef enum
- {
- NRFX_COMP_EVT_EN_CROSS_MASK = COMP_INTENSET_CROSS_Msk,
- NRFX_COMP_EVT_EN_UP_MASK = COMP_INTENSET_UP_Msk,
- NRFX_COMP_EVT_EN_DOWN_MASK = COMP_INTENSET_DOWN_Msk,
- NRFX_COMP_EVT_EN_READY_MASK = COMP_INTENSET_READY_Msk
- } nrfx_comp_evt_en_mask_t;
- typedef struct
- {
- nrf_comp_ref_t reference;
- nrf_comp_ext_ref_t ext_ref;
- nrf_comp_main_mode_t main_mode;
- nrf_comp_th_t threshold;
- nrf_comp_sp_mode_t speed_mode;
- nrf_comp_hyst_t hyst;
- #if defined (COMP_ISOURCE_ISOURCE_Msk) || defined (__NRFX_DOXYGEN__)
- nrf_isource_t isource;
- #endif
- nrf_comp_input_t input;
- uint8_t interrupt_priority;
- } nrfx_comp_config_t;
- #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) \
- }
- #if defined (COMP_ISOURCE_ISOURCE_Msk) || defined (__NRFX_DOXYGEN__)
- #define NRFX_COMP_DEFAULT_CONFIG(_input) \
- { \
- .reference = (nrf_comp_ref_t)NRFX_COMP_CONFIG_REF, \
- .ext_ref = NRF_COMP_EXT_REF_0, \
- .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, \
- .ext_ref = NRF_COMP_EXT_REF_0, \
- .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
- nrfx_err_t nrfx_comp_init(nrfx_comp_config_t const * p_config,
- nrfx_comp_event_handler_t event_handler);
- void nrfx_comp_uninit(void);
- void nrfx_comp_pin_select(nrf_comp_input_t psel);
- void nrfx_comp_start(uint32_t comp_evt_en_mask, uint32_t comp_shorts_mask);
- void nrfx_comp_stop(void);
- uint32_t nrfx_comp_sample(void);
- __STATIC_INLINE uint32_t nrfx_comp_task_address_get(nrf_comp_task_t task)
- {
- return (uint32_t)nrf_comp_task_address_get(task);
- }
- __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
|