Appiko
gpio_level_handler.c
1 
19 #include "gpio_level_handler.h"
20 #include "hal_gpio.h"
21 
22 #if ISR_MANAGER == 1
23 #include "isr_manager.h"
24 #endif
25 
26 #define GPIO_BUFFER_SIZE 4
27 
28 gpio_level_cfg cfg_buffer[GPIO_BUFFER_SIZE];
29 uint32_t gpio_len;
30 
31 void gpio_level_init(gpio_level_cfg * cfg, uint32_t cfg_num, uint32_t irq_priority)
32 {
33  if(cfg_num == 0)
34  {
35  NRF_GPIOTE->EVENTS_PORT = 0;
36 
37  NRF_GPIOTE->INTENCLR = GPIOTE_INTENCLR_PORT_Enabled << GPIOTE_INTENCLR_PORT_Pos;
38 
39  NVIC_ClearPendingIRQ(GPIOTE_IRQn);
40  NVIC_DisableIRQ(GPIOTE_IRQn);
41 
43 
44  return ;
45  }
46 
47  uint32_t i;
48  for(i = 0; i<cfg_num; i++)
49  {
50  cfg_buffer[i] = *(cfg + i);
51 
52  hal_gpio_cfg((cfg + i)->pin_num,
53  GPIO_PIN_CNF_DIR_Input,
54  GPIO_PIN_CNF_INPUT_Connect,
55  (cfg + i)->pull_cfg,
56  GPIO_PIN_CNF_DRIVE_S0S1,
57  ((cfg + i)->trigger_on_high)
58  ?GPIO_PIN_CNF_SENSE_High:GPIO_PIN_CNF_SENSE_Low );
59  }
60  gpio_len = cfg_num;
61 
62  NRF_GPIO->DETECTMODE = GPIO_DETECTMODE_DETECTMODE_LDETECT << GPIO_DETECTMODE_DETECTMODE_Pos;
63  NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Enabled << GPIOTE_INTENSET_PORT_Pos;
64 
65  NVIC_ClearPendingIRQ(GPIOTE_IRQn);
66  NVIC_SetPriority(GPIOTE_IRQn, irq_priority);
67  NVIC_EnableIRQ(GPIOTE_IRQn);
68 
69 }
70 #if ISR_HADNLER == 1
71 void gpio_level_handler_gpiote_Handler ()
72 #else
73 void GPIOTE_IRQHandler(void)
74 #endif
75 {
76  NRF_GPIOTE->EVENTS_PORT = 0;
77  (void) NRF_GPIOTE->EVENTS_PORT;
78 
79  uint32_t i;
80  for(i = 0; i<gpio_len; i++)
81  {
82  uint32_t pin_num = cfg_buffer[i].pin_num;
83  if(NRF_GPIO->LATCH & (1 << pin_num))
84  {
85  uint32_t pin_val = hal_gpio_pin_read(pin_num);
86  uint32_t level_checked = cfg_buffer[i].trigger_on_high;
87 
88  NRF_GPIO->LATCH = (1 << pin_num);
89  cfg_buffer[i].handler((pin_val == level_checked));
90  }
91  }
92 }
The configuration parameter for each of the GPIO pin that is being configured in the GPIO level handl...
void GPIOTE_IRQHandler()
Definition: main.c:192
bool trigger_on_high
the nrf bitfields header file
uint32_t pin_num
this pin is at the specified level
void gpio_level_init(gpio_level_cfg *cfg, uint32_t cfg_num, uint32_t irq_priority)
Initializes the GPIO level handler module by taking in the the configurations of all the GPIOs that n...