anx/gpio.h) lets you configure, read, and write any of the 20 available GPIO pins on the ANX dev module. Whether you are toggling an LED, sampling a button, or bit-banging a custom protocol, every digital I/O operation goes through this API. All functions return anx_err_t so you can handle configuration errors consistently alongside the rest of your application code.
Include
Add the GPIO header to any source file that performs digital I/O operations:You still need
#include "anx/anx.h" as the first include in your file. anx/gpio.h depends on the common types defined there.Direction Configuration
Configure a pin as either an input or an output before performing any read or write operations on it. Callinganx_gpio_read() on a pin configured as output, or anx_gpio_write() on a pin configured as input, returns ANX_ERR_INVALID_ARG.
anx_gpio_set_direction()
Sets the direction of a GPIO pin.
GPIO number in the range 0–33. Refer to the ANX dev module pinout diagram for the physical pin mapping.
Pin direction. Use
ANX_GPIO_INPUT to configure the pin as a high-impedance input, or ANX_GPIO_OUTPUT to drive it as a push-pull output.ANX_OK on success. ANX_ERR_INVALID_ARG if pin is out of range or dir is not a valid anx_gpio_dir_t value.gpio_direction.c
Pull Resistor Configuration
Enable an internal pull-up or pull-down resistor on any input pin to avoid leaving it floating. Always callanx_gpio_set_direction() before calling anx_gpio_set_pull().
anx_gpio_set_pull()
Configures the internal pull resistor for a GPIO pin.
GPIO number in the range 0–33.
Pull resistor mode. Choose from:
ANX_GPIO_PULL_NONE— no pull resistor (pin floats when disconnected)ANX_GPIO_PULL_UP— internal pull-up to VCCANX_GPIO_PULL_DOWN— internal pull-down to GND
ANX_OK on success. ANX_ERR_INVALID_ARG if pin is out of range or pull is not a valid value.Reading and Writing
anx_gpio_write()
Drives a GPIO output pin high or low.
GPIO number in the range 0–33. The pin must already be configured as
ANX_GPIO_OUTPUT.Output level:
1 to drive the pin high (VCC), 0 to drive it low (GND).ANX_OK on success. ANX_ERR_INVALID_ARG if the pin is not configured as an output or the pin number is out of range.anx_gpio_read()
Samples the current logic level of a GPIO input pin.
GPIO number in the range 0–33. The pin must already be configured as
ANX_GPIO_INPUT.1 if the pin is high, 0 if the pin is low. Returns 0 on error (check anx_gpio_set_direction() was called first).gpio_blink.c
Interrupts
Attach an interrupt handler to a GPIO input pin to react to level changes without polling. ANX OS calls the handler from an interrupt context, so keep the function as short as possible.anx_gpio_attach_interrupt()
Attaches an ISR callback to a GPIO pin.
GPIO number in the range 0–33. The pin must already be configured as
ANX_GPIO_INPUT.The edge or edges that fire the interrupt:
ANX_GPIO_TRIGGER_RISING— fires when the pin transitions from low to highANX_GPIO_TRIGGER_FALLING— fires when the pin transitions from high to lowANX_GPIO_TRIGGER_BOTH— fires on both rising and falling edges
A pointer to your ISR callback function. The function signature must be
void handler(void *arg).ANX_OK on success. ANX_ERR_INVALID_ARG if the pin is not configured as input, the pin number is out of range, or handler is NULL.gpio_interrupt.c