10 #if RUUVI_NRF5_SDK15_GPIO_INTERRUPT_ENABLED
18 #include "nrf_drv_gpiote.h"
22 static uint8_t max_interrupts = 0;
26 const uint16_t interrupt_table_size)
43 ret_code_t err_code = NRF_SUCCESS;
45 if (!nrf_drv_gpiote_is_init())
47 err_code = nrf_drv_gpiote_init();
50 pin_event_handlers = interrupt_table;
51 max_interrupts = interrupt_table_size;
57 if (0 == max_interrupts) {
return RD_SUCCESS; }
59 pin_event_handlers = NULL;
66 return (0 != max_interrupts);
69 static void in_pin_handler (
const nrf_drv_gpiote_pin_t pin,
70 const nrf_gpiote_polarity_t action)
72 if (max_interrupts <= pin) {
return; }
77 if (NULL != pin_event_handlers[pin])
81 case NRF_GPIOTE_POLARITY_LOTOHI:
85 case NRF_GPIOTE_POLARITY_HITOLO:
97 event.pin = nrf_to_ruuvi_pin (pin);
98 (pin_event_handlers[pin]) (event);
121 uint8_t nrf_pin = ruuvi_to_nrf_pin_map (pin);
125 ret_code_t nrf_code = NRF_SUCCESS;
126 nrf_gpiote_polarity_t polarity = NRF_GPIOTE_POLARITY_TOGGLE;
127 nrf_gpio_pin_pull_t pull = NRF_GPIO_PIN_NOPULL;
132 polarity = NRF_GPIOTE_POLARITY_TOGGLE;
136 polarity = NRF_GPIOTE_POLARITY_LOTOHI;
140 polarity = NRF_GPIOTE_POLARITY_HITOLO;
150 pull = NRF_GPIO_PIN_NOPULL;
154 pull = NRF_GPIO_PIN_PULLUP;
158 pull = NRF_GPIO_PIN_PULLDOWN;
167 nrf_drv_gpiote_in_config_t in_config =
170 .hi_accuracy =
false,
174 pin_event_handlers[nrf_pin] = handler;
175 nrf_code |= nrf_drv_gpiote_in_init (nrf_pin, &in_config, in_pin_handler);
176 nrf_drv_gpiote_in_event_enable (nrf_pin,
true);
189 uint8_t nrf_pin = ruuvi_to_nrf_pin_map (pin);
191 if (NULL != pin_event_handlers && NULL != pin_event_handlers[nrf_pin])
193 nrf_drv_gpiote_in_event_disable (nrf_pin);
194 nrf_drv_gpiote_in_uninit (nrf_pin);
195 pin_event_handlers[nrf_pin] = NULL;
#define RD_ERROR_INVALID_PARAM
Invalid Parameter.
#define RD_ERROR_NULL
Null Pointer.
uint32_t rd_status_t
bitfield for representing errors
rd_status_t ruuvi_nrf5_sdk15_to_ruuvi_error(const ret_code_t error)
convert nrf5 sdk15 error code into Ruuvi error code.
#define RD_SUCCESS
Internal Error.
#define RD_ERROR_INVALID_STATE
Invalid state, operation disallowed in this state.
ri_gpio_slope_t
Enable implementation selected by application.
rd_status_t ri_gpio_interrupt_enable(const ri_gpio_id_t pin, const ri_gpio_slope_t slope, const ri_gpio_mode_t mode, const ri_gpio_interrupt_fp_t handler)
Enable interrupt on a pin.
bool ri_gpio_is_init(void)
return true if GPIO is init, false otherwise.
rd_status_t ri_gpio_interrupt_init(ri_gpio_interrupt_fp_t *const interrupt_table, const uint16_t max_interrupts)
Initialize interrupt functionality to GPIO. Takes address of interrupt table as a pointer to avoid ty...
void(* ri_gpio_interrupt_fp_t)(const ri_gpio_evt_t)
rd_status_t ri_gpio_interrupt_uninit(void)
Uninitialize interrupt functionality of GPIO.
rd_status_t ri_gpio_interrupt_disable(const ri_gpio_id_t pin)
Disable interrupt on a pin.
bool ri_gpio_interrupt_is_init(void)
Check if interrupt module is initialized.
rd_status_t ri_gpio_read(const ri_gpio_id_t pin, ri_gpio_state_t *const p_state)
Read state of a pin of a port into bool high If there are several ports the platform driver must impl...
Header to enable and disable module compilation.
uint16_t ri_gpio_id_t
port<<8 + pin
#define RI_GPIO_ID_UNUSED
Enable implementation selected by application.
@ RI_GPIO_MODE_INPUT_PULLUP
Input, can be read. Pulled up by internal resistor, value depends on IC.
@ RI_GPIO_MODE_INPUT_NOPULL
Input, can be read. No pull resistors.
@ RI_GPIO_MODE_INPUT_PULLDOWN
Input, can be read. Pulled dpwn by internal resistor, value depends on IC.
ri_gpio_state_t
States of GPIO pins.
@ RI_GPIO_LOW
GPIO electrically low.
ri_gpio_slope_t slope
ri_gpio_slope_t slope of event