GPIO API
The ALP SDK GPIO driver provides a CMSIS-Driver compatible interface for configuring and controlling general-purpose I/O pins across all E1M modules.
Header
#include "alp_gpio.h"
Initialization
#include "alp_gpio.h"
/* Get the GPIO driver instance for port 0 */
ALP_GPIO_Driver_t *gpio = ALP_GPIO_GetDriver(0);
/* Initialize the driver */
gpio->Initialize(NULL);
gpio->PowerControl(ALP_POWER_FULL);
Pin Configuration
/* Configure pin 5 as push-pull output */
gpio->SetDirection(5, ALP_GPIO_DIR_OUTPUT);
gpio->SetOutputMode(5, ALP_GPIO_OUTPUT_PUSH_PULL);
/* Configure pin 8 as input with internal pull-up */
gpio->SetDirection(8, ALP_GPIO_DIR_INPUT);
gpio->SetPullResistor(8, ALP_GPIO_PULL_UP);
Digital Output
/* Set pin 5 high */
gpio->SetValue(5, 1);
/* Set pin 5 low */
gpio->SetValue(5, 0);
/* Toggle pin 5 */
gpio->ToggleValue(5);
Digital Input
uint32_t value = gpio->GetValue(8);
if (value) {
/* Pin 8 is high */
} else {
/* Pin 8 is low */
}
Interrupts
void pin8_callback(uint32_t pin, uint32_t event)
{
/* Handle rising edge on pin 8 */
}
gpio->SetInterrupt(8, ALP_GPIO_IRQ_RISING_EDGE, pin8_callback);
gpio->EnableInterrupt(8);
/* Later, disable the interrupt */
gpio->DisableInterrupt(8);
API Reference
Functions
| Function | Description |
|---|---|
ALP_GPIO_GetDriver() | Get driver instance for a GPIO port |
Initialize() | Initialize the GPIO driver |
Uninitialize() | De-initialize and release resources |
PowerControl() | Set power state (off, low-power, full) |
SetDirection() | Configure a pin as input or output |
SetOutputMode() | Set output type (push-pull or open-drain) |
SetPullResistor() | Configure internal pull-up or pull-down |
SetValue() | Write a digital value to an output pin |
GetValue() | Read the current value of a pin |
ToggleValue() | Toggle the output state of a pin |
SetInterrupt() | Configure edge/level interrupt and callback |
EnableInterrupt() | Enable interrupt on a pin |
DisableInterrupt() | Disable interrupt on a pin |
Enumerations
| Enum | Values |
|---|---|
ALP_GPIO_DIR_* | INPUT, OUTPUT |
ALP_GPIO_OUTPUT_* | PUSH_PULL, OPEN_DRAIN |
ALP_GPIO_PULL_* | NONE, UP, DOWN |
ALP_GPIO_IRQ_* | RISING_EDGE, FALLING_EDGE, BOTH_EDGES, HIGH_LEVEL, LOW_LEVEL |
Pin Mapping
See the Pinout page for physical pin assignments on each E1M module.