GPIO Driver
Overview
GPIO (General Purpose Input/Output) provides digital I/O capabilities for external device control and signal reading.
Functional Description
Multiple GPIO channels with input/output modes
Configurable pull-up/pull-down resistors
Interrupt support (rising/falling/both edges)
Wake-up source for low power modes
Pin multiplexing for peripheral functions
Configurable drive strength
Low power retention support
External LDO and clock pin control
Development Guide
Initialization - Call bk_gpio_driver_init() before any GPIO operations - Configure GPIO mode: bk_gpio_enable_output() or bk_gpio_enable_input() - Set pull-up/pull-down as needed
Basic Operations - Output: bk_gpio_set_output_high/low(), bk_gpio_get_input() - Input: bk_gpio_get_input() - Configuration: bk_gpio_set_config()
Interrupt Handling - Set interrupt type: bk_gpio_set_interrupt_type() - Register ISR: bk_gpio_register_isr() - Enable interrupt: bk_gpio_enable_interrupt()
Wake-up Configuration - Set wake-up source: bk_gpio_set_wakeup_source() - Configure interrupt type for wake-up
Notes
Ensure driver initialization before GPIO operations
Match pin multiplexing with hardware design
Consider electrical characteristics and drive strength
Use proper pull-up/pull-down for input signals
API Reference
bk_gpio_driver_init() - Initialize GPIO driver
bk_gpio_enable_output/input() - Configure GPIO mode
bk_gpio_set_output_high/low() - Control output state
bk_gpio_get_input() - Read input state
bk_gpio_pull_up/down() - Configure pull resistors
bk_gpio_set_interrupt_type() - Set interrupt trigger
bk_gpio_register_isr() - Register interrupt handler
bk_gpio_set_wakeup_source() - Configure wake-up
bk_gpio_low_power_keep_status() - Low power retention
Examples
Basic GPIO control:
bk_gpio_driver_init();
bk_gpio_enable_output(GPIO_0);
bk_gpio_set_output_high(GPIO_0);
bk_gpio_enable_input(GPIO_1);
bk_gpio_pull_up(GPIO_1);
uint32_t state = bk_gpio_get_input(GPIO_1);
Interrupt handling:
static void gpio_isr(gpio_id_t id) {
printf("GPIO %d interrupt\n", id);
bk_gpio_clear_interrupt(id);
}
bk_gpio_set_interrupt_type(GPIO_2, GPIO_INT_TYPE_FALLING_EDGE);
bk_gpio_register_isr(GPIO_2, gpio_isr);
bk_gpio_enable_interrupt(GPIO_2);
Wake-up configuration:
bk_gpio_set_interrupt_type(GPIO_3, GPIO_INT_TYPE_FALLING_EDGE);
bk_gpio_set_wakeup_source(GPIO_3);
// System will wake up on GPIO_3 falling edge
FAQs
GPIO state incorrect: Check mode configuration and pull settings
Interrupt not triggered: Verify interrupt type and enable status
Wake-up failed: Check wake-up source configuration
Error Codes
BK_ERR_GPIO_CHAN_ID: Invalid GPIO channel
BK_ERR_GPIO_NOT_INPUT_MODE: Not in input mode for read/interrupt operations
BK_ERR_GPIO_INVALID_INT_TYPE: Invalid interrupt type