Functions for General Purpose I/O (GPIO) access to leds, buttons, etc.
All functions use a GPIO number from 0..NUM_PINS_SWITCHBOX-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 SWB_BTN0..SWB_BTN3 and SWB_SW0..SWB_SW1.
- The LED library uses 0..3 or LED0..LED1 for green LEDs whereas GPIO uses SWB_LD0..SWB_LD3. It uses 0..1 or COLOR_LED0..COLOR_LED1 and the three color components (RGB) whereas GPIO uses SWB_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 SWB_A0..SWB_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 pin_t pin, const gpio_direction_t dir)
Set the GPIO pin as in input or output.
void gpio_set_level(const pin_t pin, const gpio_level_t level)
Set the level of the output GPIO pin. If the pin is configured as input, this function does nothing.
@ SWB_LD0
LED output pins.
void sleep_msec(int msec)
Wait for msec milliseconds.
void pynq_destroy(void)
Reset and destroy the switchbox and GPIO of the PYNQ.
◆ gpio_t
For backwards compatibility. Map gpio_t to the pin_t type.
Definition at line 102 of file gpio.h.
◆ gpio_direction_t
Enumerate the direction state (input/output) of the pin
Enumerator |
---|
GPIO_DIR_INPUT | The GPIO pin is an input.
|
GPIO_DIR_OUTPUT | The GPIO pin is an output.
|
Definition at line 81 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 91 of file gpio.h.
◆ gpio_destroy()
void gpio_destroy |
( |
void |
| ) |
|
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 GPIO 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 GPIO pin.
- Parameters
-
pin | The GPIO pin to read it state. |
- Returns
- the output level of pin using enum gpio_level_t.
- 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 |
| ) |
|
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 GPIO pins.
Definition at line 62 of file gpio.c.
◆ gpio_reset_pin()
void gpio_reset_pin |
( |
const pin_t |
pin | ) |
|
Function is currently a no-op placeholder for arduino compatibility.
- Parameters
-
pin | The GPIO pin to reset. |
- 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 GPIO pin as in input or output.
- Parameters
-
pin | The GPIO 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 GPIO pin. If the pin is configured as input, this function does nothing.
- Parameters
-
pin | The GPIO 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.