Functions for General Purpose I/O (GPIO) access to leds, buttons, (analog) pins, etc.
All functions use the IO pin number (io_t) from 0..IO_NUM_PINS-1.
The LED and button libraries are built on top of this library, but do not expose the full functionality of this library. Use this library when that is required. Also see the I/O switchbox (switchbox.h) and pin mapping (pinmap.h).
In particular, be aware that the numbering used in the high-level libraries is different from the underlying GPIO numbering.
- The button library uses 0..3 or BUTTON0..BUTTON3, and 0..1 or SWITCH0..SWITCH1, whereas GPIO uses IO_BTN0..IO_BTN3 and IO_SW0..IO_SW1.
- The LED library uses 0..3 or LED0..LED1 for green LEDs whereas GPIO uses IO_LD0..IO_LD3. It uses 0..1 or COLOR_LED0..COLOR_LED1 and the three color components (RGB) whereas GPIO uses IO_LD4/5R/G/B.
- The PWM library uses 0..5 or PWM0..PWM5, whereas GPIO uses SWB_PWM0..SWB_PWM5.
- The UART library uses 0..1 or UART0..UART1, whereas GPIO uses SWB_UART0..SWB_UART1.
- The ADC library is slightly different. It uses ADC0..ADC5 (these are non-consecutive numbers), whereas GPIO uses IO_A0..IO_A5 (which are consecutive).
An example of using this library to turn LED0 on:
int main (void)
{
return EXIT_SUCCESS;
}
void gpio_set_direction(const io_t pin, const gpio_direction_t dir)
Set the IO pin as in input or output.
void gpio_set_level(const io_t pin, const gpio_level_t level)
Set the level of the output IO pin. If the pin is configured as input, this function does nothing.
gpio_level_t gpio_get_level(const io_t pin)
Return the level of the IO pin.
@ IO_A0
Analog input pins (Arduino header).
void sleep_msec(int msec)
Wait for msec milliseconds.
void pynq_destroy(void)
Reset and destroy the switchbox and GPIO of the PYNQ.
◆ gpio_direction_t
Enumerate the direction state (input/output) of the pin
Enumerator |
---|
GPIO_DIR_INPUT | The IO pin is an input.
|
GPIO_DIR_OUTPUT | The IO pin is an output.
|
Definition at line 88 of file gpio.h.
◆ gpio_level_t
Enumerate the signal level.
Enumerator |
---|
GPIO_LEVEL_LOW | A low signal
|
GPIO_LEVEL_HIGH | A high signal
|
Definition at line 98 of file gpio.h.
◆ gpio_destroy()
void gpio_destroy |
( |
void |
| ) |
|
|
extern |
De-initialize the GPIO library. This releases the memory map and memory allocated by gpio_init.
Definition at line 47 of file gpio.c.
◆ gpio_get_direction()
Returns the direction the set pin is initialized in.
- Parameters
-
pin | The IO pin to read the direction set in the shared memory system on the ARM processor. |
- Warning
- Fails with program exit when pin is outside valid range.
Definition at line 95 of file gpio.c.
◆ gpio_get_level()
Return the level of the IO pin.
- Parameters
-
pin | The IO pin to read it state. |
- Returns
- the output level of pin.
- Warning
- Fails with program exit when pin is outside valid range.
Definition at line 118 of file gpio.c.
◆ gpio_init()
Initializes the GPIO library.
Definition at line 40 of file gpio.c.
◆ gpio_is_initialized()
bool gpio_is_initialized |
( |
void |
| ) |
|
|
extern |
Check if gpio library is initialized.
- Returns
- true if initialize, false if not.
Definition at line 35 of file gpio.c.
◆ gpio_reset()
Reset all IO pins.
Definition at line 62 of file gpio.c.
◆ gpio_reset_pin()
void gpio_reset_pin |
( |
const io_t |
pin | ) |
|
|
extern |
Function is currently a no-op placeholder for arduino compatibility.
- Parameters
-
- Warning
- Fails with program exit when LEDs were not initialized with the correct mode.
Definition at line 55 of file gpio.c.
◆ gpio_set_direction()
Set the IO pin as in input or output.
- Parameters
-
pin | The IO pin to modify direction for. |
direction | The direction to set on the pin. |
- Warning
- Fails with program exit when pin or direction is outside valid range.
Definition at line 81 of file gpio.c.
◆ gpio_set_level()
Set the level of the output IO pin. If the pin is configured as input, this function does nothing.
- Parameters
-
pin | The IO pin to modify direction for. |
level | The level to set on the pin. |
- Warning
- Fails with program exit when pin is outside valid range.
Definition at line 104 of file gpio.c.