123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- #ifndef NRF_CSENSE_H__
- #define NRF_CSENSE_H__
- #include <stdint.h>
- #include "nrf.h"
- #include "sdk_errors.h"
- #include "app_timer.h"
- #include "nrf_drv_csense.h"
- #include "nrf_csense_macros.h"
- #include "app_util.h"
- #define NRF_CSENSE_GET_INSTANCE_ID(instance) (&instance)
- #define NRF_CSENSE_BUTTON_DEF(name, p1) NRF_CSENSE_INTERNAL_BUTTON_DEF(name, p1)
- #define NRF_CSENSE_SLIDER_2_DEF(name, steps_no, p1, p2) NRF_CSENSE_INTERNAL_SLIDER_2_DEF(name, steps_no, p1, p2)
- #define NRF_CSENSE_SLIDER_3_DEF(name, steps_no, p1, p2, p3) NRF_CSENSE_INTERNAL_SLIDER_3_DEF(name, steps_no, p1, p2, p3)
- #define NRF_CSENSE_SLIDER_4_DEF(name, steps_no, p1, p2, p3, p4) NRF_CSENSE_INTERNAL_SLIDER_4_DEF(name, steps_no, p1, p2, p3, p4)
- #define NRF_CSENSE_SLIDER_5_DEF(name, steps_no, p1, p2, p3, p4, p5) NRF_CSENSE_INTERNAL_SLIDER_5_DEF(name, steps_no, p1, p2, p3, p4, p5)
- #define NRF_CSENSE_WHEEL_3_DEF(name, steps_no, p1, p2, p3) NRF_CSENSE_INTERNAL_WHEEL_3_DEF(name, steps_no, p1, p2, p3)
- #define NRF_CSENSE_WHEEL_4_DEF(name, steps_no, p1, p2, p3, p4) NRF_CSENSE_INTERNAL_WHEEL_4_DEF(name, steps_no, p1, p2, p3, p4)
- #define NRF_CSENSE_WHEEL_5_DEF(name, steps_no, p1, p2, p3, p4, p5) NRF_CSENSE_INTERNAL_WHEEL_5_DEF(name, steps_no, p1, p2, p3, p4, p5)
-
- typedef struct nrf_csense_instance_s nrf_csense_instance_t;
-
- typedef struct nrf_csense_pad_s nrf_csense_pad_t;
-
- typedef struct
- {
- uint16_t max_value;
- uint16_t min_value;
- }nrf_csense_min_max_t;
-
- struct nrf_csense_instance_s
- {
- nrf_csense_instance_t * p_next_instance;
- nrf_csense_pad_t * p_nrf_csense_pad;
- nrf_csense_min_max_t * min_max;
- uint16_t steps;
- uint8_t number_of_pads;
- bool is_active;
- bool is_touched;
- void * p_context;
- };
-
- struct nrf_csense_pad_s
- {
- nrf_csense_pad_t * p_next_pad;
- uint16_t threshold;
- uint8_t pad_index;
- uint8_t analog_input_number;
- };
- typedef enum
- {
- NRF_CSENSE_BTN_EVT_PRESSED,
- NRF_CSENSE_BTN_EVT_RELEASED,
- NRF_CSENSE_SLIDER_EVT_PRESSED,
- NRF_CSENSE_SLIDER_EVT_RELEASED,
- NRF_CSENSE_SLIDER_EVT_DRAGGED,
- }nrf_csense_evt_type_t;
- typedef struct
- {
- uint16_t step;
- } nrf_csense_slider_evt_t;
- typedef union
- {
- nrf_csense_slider_evt_t slider;
- } nrf_csense_evt_param_t;
- typedef struct
- {
- nrf_csense_evt_type_t nrf_csense_evt_type;
- nrf_csense_instance_t * p_instance;
- nrf_csense_evt_param_t params;
- }nrf_csense_evt_t;
- typedef void (* nrf_csense_event_handler_t)(nrf_csense_evt_t * p_evt);
- __STATIC_INLINE void nrf_csense_instance_context_set(nrf_csense_instance_t * const p_instance, void * p_context)
- {
- p_instance->p_context = p_context;
- }
- ret_code_t nrf_csense_init(nrf_csense_event_handler_t event_handler, uint32_t ticks);
- ret_code_t nrf_csense_uninit(void);
- ret_code_t nrf_csense_add(nrf_csense_instance_t * const p_instance);
- ret_code_t nrf_csense_enable(nrf_csense_instance_t * const p_instance);
- ret_code_t nrf_csense_disable(nrf_csense_instance_t * const p_instance);
- ret_code_t nrf_csense_ticks_set(uint32_t ticks);
- ret_code_t nrf_csense_steps_set(nrf_csense_instance_t * const p_instance, uint16_t steps);
- #endif
|