123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- #ifndef APP_GPIOTE_H__
- #define APP_GPIOTE_H__
- #include <stdint.h>
- #include <stdbool.h>
- #include "nrf.h"
- #include "nrf_drv_gpiote.h"
- #include "app_error.h"
- #include "app_util.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define GPIOTE_USER_NODE_SIZE ((4*sizeof(uint32_t)*GPIO_COUNT)+8)
- #define APP_GPIOTE_BUF_SIZE(MAX_USERS) ((MAX_USERS) * GPIOTE_USER_NODE_SIZE)
- typedef uint8_t app_gpiote_user_id_t;
- typedef void (*app_gpiote_event_handler_t)(uint32_t const * p_event_pins_low_to_high,
- uint32_t const * p_event_pins_high_to_low);
- typedef void (*app_gpiote_input_event_handler_t)(void);
- #pragma pack(push, 1)
- typedef struct
- {
-
- uint32_t pin_number : VBITS(NRF_GPIO_PIN_MAP(GPIO_COUNT - 1, 31));
-
- nrf_gpiote_polarity_t sense : 2;
- } app_gpiote_user_pin_config_t;
- STATIC_ASSERT(NRF_GPIOTE_POLARITY_LOTOHI <= 3);
- STATIC_ASSERT(NRF_GPIOTE_POLARITY_HITOLO <= 3);
- STATIC_ASSERT(NRF_GPIOTE_POLARITY_TOGGLE <= 3);
- #pragma pack(pop)
-
- #define APP_GPIOTE_INIT(MAX_USERS) \
- do \
- { \
- static uint32_t app_gpiote_buf[CEIL_DIV(APP_GPIOTE_BUF_SIZE(MAX_USERS), sizeof(uint32_t))];\
- uint32_t ERR_CODE = app_gpiote_init((MAX_USERS), app_gpiote_buf); \
- APP_ERROR_CHECK(ERR_CODE); \
- } while (0)
- uint32_t app_gpiote_init(uint8_t max_users, void * p_buffer);
- uint32_t app_gpiote_user_register(app_gpiote_user_id_t * p_user_id,
- uint32_t const * p_pins_low_to_high_mask,
- uint32_t const * p_pins_high_to_low_mask,
- app_gpiote_event_handler_t event_handler);
- uint32_t app_gpiote_user_register_ex(app_gpiote_user_id_t * p_user_id,
- app_gpiote_user_pin_config_t const * p_pins_config,
- size_t pin_count,
- app_gpiote_event_handler_t event_handler);
- uint32_t app_gpiote_user_enable(app_gpiote_user_id_t user_id);
- uint32_t app_gpiote_user_disable(app_gpiote_user_id_t user_id);
- uint32_t app_gpiote_pins_state_get(app_gpiote_user_id_t user_id, uint32_t * p_pins);
- #ifdef __cplusplus
- }
- #endif
- #endif
|