53 #include "nrfx_gpiote.h" 55 #include "hal/nrf_gpio.h" 57 #define PIN_TO_PORT(pin) (pin >> 5) 58 #define PIN_TO_NUM(pin) (pin & 0x1F) 72 port = PIN_TO_PORT(pin);
81 if(!nrfx_gpiote_is_init()) {
82 nrfx_gpiote_init(NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY);
90 nrfx_gpiote_in_config_t gpiote_config = {
95 uint32_t pin_number = NRF_GPIO_PIN_MAP(port, pin);
97 tmp = cfg & GPIO_HAL_PIN_CFG_EDGE_BOTH;
98 if(tmp == GPIO_HAL_PIN_CFG_EDGE_NONE) {
99 gpiote_config.sense = GPIOTE_CONFIG_POLARITY_None;
100 }
else if(tmp == GPIO_HAL_PIN_CFG_EDGE_RISING) {
101 gpiote_config.sense = NRF_GPIOTE_POLARITY_LOTOHI;
102 }
else if(tmp == GPIO_HAL_PIN_CFG_EDGE_FALLING) {
103 gpiote_config.sense = NRF_GPIOTE_POLARITY_HITOLO;
104 }
else if(tmp == GPIO_HAL_PIN_CFG_EDGE_BOTH) {
105 gpiote_config.sense = NRF_GPIOTE_POLARITY_TOGGLE;
108 tmp = cfg & GPIO_HAL_PIN_CFG_PULL_MASK;
109 if(tmp == GPIO_HAL_PIN_CFG_PULL_NONE) {
110 gpiote_config.pull = NRF_GPIO_PIN_NOPULL;
111 }
else if(tmp == GPIO_HAL_PIN_CFG_PULL_DOWN) {
112 gpiote_config.pull = NRF_GPIO_PIN_PULLDOWN;
113 }
else if(tmp == GPIO_HAL_PIN_CFG_PULL_UP) {
114 gpiote_config.pull = NRF_GPIO_PIN_PULLUP;
119 tmp = cfg & GPIO_HAL_PIN_CFG_INT_MASK;
120 if(tmp == GPIO_HAL_PIN_CFG_INT_DISABLE) {
121 nrfx_gpiote_in_event_disable(pin_number);
122 }
else if(tmp == GPIO_HAL_PIN_CFG_INT_ENABLE) {
123 nrfx_gpiote_in_event_enable(pin_number,
true);
133 GPIO_HAL_PIN_CFG_EDGE_NONE |
134 GPIO_HAL_PIN_CFG_INT_DISABLE;
135 nrf_gpio_pin_pull_t pull;
136 nrf_gpiote_polarity_t polarity;
138 pin_number = NRF_GPIO_PIN_MAP(port, pin);
141 if(nrf_gpio_pin_dir_get(pin_number) == NRF_GPIO_PIN_DIR_OUTPUT) {
150 for(i = 0; i < GPIOTE_CH_NUM; i++) {
151 if(nrf_gpiote_event_pin_get(NRF_GPIOTE, i) == pin_number) {
152 polarity = nrf_gpiote_event_polarity_get(NRF_GPIOTE, i);
154 if(polarity == NRF_GPIOTE_POLARITY_LOTOHI) {
155 cfg |= GPIO_HAL_PIN_CFG_EDGE_BOTH;
156 }
else if(polarity == NRF_GPIOTE_POLARITY_HITOLO) {
157 cfg |= GPIO_HAL_PIN_CFG_EDGE_BOTH;
158 }
else if(polarity == NRF_GPIOTE_POLARITY_TOGGLE) {
159 cfg |= GPIO_HAL_PIN_CFG_EDGE_BOTH;
162 pull = nrf_gpio_pin_pull_get(pin_number);
164 if(pull == NRF_GPIO_PIN_PULLDOWN) {
165 cfg |= GPIO_HAL_PIN_CFG_PULL_DOWN;
166 }
else if(pull == NRF_GPIO_PIN_PULLUP) {
167 cfg |= GPIO_HAL_PIN_CFG_PULL_UP;
170 if(nrf_gpiote_int_enable_check(NRF_GPIOTE, 1 << i)) {
171 cfg |= GPIO_HAL_PIN_CFG_INT_ENABLE;
184 return (uint8_t)nrf_gpio_pin_read(NRF_GPIO_PIN_MAP(port, pin));
190 NRF_GPIO_Type *gpio_regs[GPIO_COUNT] = GPIO_REG_LIST;
192 if(port >= GPIO_COUNT) {
196 nrf_gpio_port_out_set(gpio_regs[port], pins);
202 NRF_GPIO_Type *gpio_regs[GPIO_COUNT] = GPIO_REG_LIST;
204 if(port >= GPIO_COUNT) {
208 nrf_gpio_port_out_clear(gpio_regs[port], pins);
214 if(port >= GPIO_COUNT) {
217 gpio_hal_arch_write_pins(port, pins, ~gpio_hal_arch_read_pins(port, pins));
223 NRF_GPIO_Type *gpio_regs[GPIO_COUNT] = GPIO_REG_LIST;
225 if(port >= GPIO_COUNT) {
229 return nrf_gpio_port_in_read(gpio_regs[port]);
236 NRF_GPIO_Type *gpio_regs[GPIO_COUNT] = GPIO_REG_LIST;
238 if(port >= GPIO_COUNT) {
242 nrf_gpio_port_out_write(gpio_regs[port], value);
static void pin_event_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
GPIO event handler.
void gpio_hal_arch_init(void)
Perform architecture specific gpio initaliaztion.
void gpio_hal_arch_port_set_pins(gpio_hal_port_t port, gpio_hal_pin_mask_t pins)
Set multiple pins to logical high.
void gpio_hal_arch_port_clear_pins(gpio_hal_port_t port, gpio_hal_pin_mask_t pins)
Clear multiple pins to logical low.
uint8_t gpio_hal_arch_port_read_pin(gpio_hal_port_t port, gpio_hal_pin_t pin)
Read a GPIO pin.
uint8_t gpio_hal_port_t
A data structure that represents ports.
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.
uint8_t gpio_hal_pin_t
GPIO pin number representation.
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.
uint32_t gpio_hal_pin_mask_t
GPIO pin mask representation.
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.
#define gpio_hal_pin_to_mask(pin)
Convert a pin to a pin mask.
Header file for the GPIO HAL.
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.
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.