42 #include "nrfx_gpiote.h" 48 #define PIN_TO_PORT(pin) (pin >> 5) 49 #define PIN_TO_NUM(pin) (pin & 0x1F) 52 pin_event_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
57 port = PIN_TO_PORT(pin);
66 if(!nrfx_gpiote_is_init()) {
75 nrfx_gpiote_in_config_t gpiote_config = {
80 uint32_t pin_number = NRF_GPIO_PIN_MAP(port, pin);;
82 tmp = cfg & GPIO_HAL_PIN_CFG_EDGE_BOTH;
83 if(tmp == GPIO_HAL_PIN_CFG_EDGE_NONE) {
84 gpiote_config.sense = GPIOTE_CONFIG_POLARITY_None;
85 }
else if(tmp == GPIO_HAL_PIN_CFG_EDGE_RISING) {
86 gpiote_config.sense = NRF_GPIOTE_POLARITY_LOTOHI;
87 }
else if(tmp == GPIO_HAL_PIN_CFG_EDGE_FALLING) {
88 gpiote_config.sense = NRF_GPIOTE_POLARITY_HITOLO;
89 }
else if(tmp == GPIO_HAL_PIN_CFG_EDGE_BOTH) {
90 gpiote_config.sense = NRF_GPIOTE_POLARITY_TOGGLE;
93 tmp = cfg & GPIO_HAL_PIN_CFG_PULL_MASK;
94 if(tmp == GPIO_HAL_PIN_CFG_PULL_NONE) {
95 gpiote_config.pull = NRF_GPIO_PIN_NOPULL;
96 }
else if(tmp == GPIO_HAL_PIN_CFG_PULL_DOWN) {
97 gpiote_config.pull = NRF_GPIO_PIN_PULLDOWN;
98 }
else if(tmp == GPIO_HAL_PIN_CFG_PULL_UP) {
99 gpiote_config.pull = NRF_GPIO_PIN_PULLUP;
102 nrfx_gpiote_in_init(pin_number, &gpiote_config, pin_event_handler);
104 tmp = cfg & GPIO_HAL_PIN_CFG_INT_MASK;
105 if(tmp == GPIO_HAL_PIN_CFG_INT_DISABLE) {
106 nrfx_gpiote_in_event_disable(pin_number);
107 }
else if(tmp == GPIO_HAL_PIN_CFG_INT_ENABLE) {
108 nrfx_gpiote_in_event_enable(pin_number,
true);
118 GPIO_HAL_PIN_CFG_EDGE_NONE |
119 GPIO_HAL_PIN_CFG_INT_DISABLE;
120 nrf_gpio_pin_pull_t pull;
121 nrf_gpiote_polarity_t polarity;
123 pin_number = NRF_GPIO_PIN_MAP(port, pin);
126 if(nrf_gpio_pin_dir_get(pin_number) == NRF_GPIO_PIN_DIR_OUTPUT) {
135 for(i = 0; i < GPIOTE_CH_NUM; i++) {
136 if(nrf_gpiote_event_pin_get(i) == pin_number) {
137 polarity = nrf_gpiote_event_polarity_get(i);
139 if(polarity == NRF_GPIOTE_POLARITY_LOTOHI) {
140 cfg |= GPIO_HAL_PIN_CFG_EDGE_BOTH;
141 }
else if(polarity == NRF_GPIOTE_POLARITY_HITOLO) {
142 cfg |= GPIO_HAL_PIN_CFG_EDGE_BOTH;
143 }
else if(polarity == NRF_GPIOTE_POLARITY_TOGGLE) {
144 cfg |= GPIO_HAL_PIN_CFG_EDGE_BOTH;
147 pull = nrf_gpio_pin_pull_get(pin_number);
149 if(pull == NRF_GPIO_PIN_PULLDOWN) {
150 cfg |= GPIO_HAL_PIN_CFG_PULL_DOWN;
151 }
else if(pull == NRF_GPIO_PIN_PULLUP) {
152 cfg |= GPIO_HAL_PIN_CFG_PULL_UP;
155 if(nrf_gpiote_int_is_enabled(1 << i)) {
156 cfg |= GPIO_HAL_PIN_CFG_INT_ENABLE;
168 return (uint8_t)nrf_gpio_pin_read(NRF_GPIO_PIN_MAP(port, pin));
174 NRF_GPIO_Type *gpio_regs[GPIO_COUNT] = GPIO_REG_LIST;
176 if(port >= GPIO_COUNT) {
180 nrf_gpio_port_out_set(gpio_regs[port], pins);
186 NRF_GPIO_Type *gpio_regs[GPIO_COUNT] = GPIO_REG_LIST;
188 if(port >= GPIO_COUNT) {
192 nrf_gpio_port_out_clear(gpio_regs[port], pins);
198 if(port >= GPIO_COUNT) {
201 gpio_hal_arch_write_pins(port, pins, ~gpio_hal_arch_read_pins(port, pins));
207 NRF_GPIO_Type *gpio_regs[GPIO_COUNT] = GPIO_REG_LIST;
209 if(port >= GPIO_COUNT) {
213 return nrf_gpio_port_in_read(gpio_regs[port]);
220 NRF_GPIO_Type *gpio_regs[GPIO_COUNT] = GPIO_REG_LIST;
222 if(port >= GPIO_COUNT) {
226 nrf_gpio_port_out_write(gpio_regs[port], value);
void gpio_hal_arch_init(void)
Perform architecture specific gpio initaliaztion.
void gpio_hal_arch_port_toggle_pins(gpio_hal_port_t port, gpio_hal_pin_mask_t pins)
Toggle multiple pins.
gpio_hal_pin_cfg_t gpio_hal_arch_port_pin_cfg_get(gpio_hal_port_t port, gpio_hal_pin_t pin)
Read the configuration of a GPIO pin.
void gpio_hal_arch_port_write_pins(gpio_hal_port_t port, gpio_hal_pin_mask_t pins, gpio_hal_pin_mask_t value)
Write multiple pins.
void gpio_hal_arch_port_set_pins(gpio_hal_port_t port, gpio_hal_pin_mask_t pins)
Set multiple pins to logical high.
uint8_t gpio_hal_port_t
A data structure that represents ports.
uint8_t gpio_hal_pin_t
GPIO pin number representation.
uint32_t gpio_hal_pin_mask_t
GPIO pin mask representation.
gpio_hal_pin_mask_t gpio_hal_arch_port_read_pins(gpio_hal_port_t port, gpio_hal_pin_mask_t pins)
Read multiple pins.
uint8_t gpio_hal_arch_port_read_pin(gpio_hal_port_t port, gpio_hal_pin_t pin)
Read a GPIO pin.
#define gpio_hal_pin_to_mask(pin)
Convert a pin to a pin mask.
Header file for the GPIO HAL.
void gpio_hal_arch_port_clear_pins(gpio_hal_port_t port, gpio_hal_pin_mask_t pins)
Clear multiple pins to logical low.
void gpio_hal_event_handler(gpio_hal_port_t port, gpio_hal_pin_mask_t pins)
The platform-independent GPIO event handler.
uint32_t gpio_hal_pin_cfg_t
GPIO pin configuration.
void gpio_hal_arch_port_pin_cfg_set(gpio_hal_port_t port, gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg)
Configure a gpio pin.