Loading...
Searching...
No Matches

Peripheral GPIO Low-Level API. More...

Detailed Description

Peripheral GPIO Low-Level API.

Author
Gunar Schorcht gunar.nosp@m.@sch.nosp@m.orcht.nosp@m..net
Marian Buschsieweke maria.nosp@m.n.bu.nosp@m.schsi.nosp@m.ewek.nosp@m.e@ovg.nosp@m.u.de
Warning
This API is not stable yet and intended for internal use only as of now.

Definition in file gpio_ll.h.

#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include "architecture.h"
#include "periph/gpio.h"
#include "periph_cpu.h"
#include "gpio_ll_arch.h"
+ Include dependency graph for gpio_ll.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

union  gpio_conf_minimal
 Public members of gpio_conf_t More...
 

Macros

#define GPIO_PORT_UNDEF   UINTPTR_MAX
 Magic "undefined GPIO port" value.
 
#define GPIO_PORT_NUMBERING_ALPHABETIC   implementation_specific
 Indicates whether GPIO ports are enumerated alphabetically (1) or numerically (0).
 
#define GPIO_PORT_0   implementation_specific
 Get the gpio_port_t value of the port labeled 0.
 
#define GPIO_PULL_NUMOF
 The number of distinct supported pull resistor strengths.
 
#define GPIO_DRIVE_NUMOF
 The number of distinct supported drive strengths.
 
#define GPIO_SLEW_NUMOF
 The number of distinct supported slew rates.
 

Typedefs

typedef uintptr_t gpio_port_t
 GPIO port type.
 

Enumerations

enum  gpio_state_t {
  GPIO_OUTPUT_PUSH_PULL , GPIO_OUTPUT_OPEN_DRAIN , GPIO_OUTPUT_OPEN_SOURCE , GPIO_INPUT ,
  GPIO_USED_BY_PERIPHERAL , GPIO_DISCONNECT
}
 Enumeration of GPIO states (direction) More...
 
enum  gpio_pull_t { GPIO_FLOATING , GPIO_PULL_UP , GPIO_PULL_DOWN , GPIO_PULL_KEEP }
 Enumeration of pull resistor configurations. More...
 
enum  gpio_pull_strength_t { GPIO_PULL_WEAKEST , GPIO_PULL_WEAK , GPIO_PULL_STRONG , GPIO_PULL_STRONGEST }
 Enumeration of pull resistor values. More...
 
enum  gpio_drive_strength_t { GPIO_DRIVE_WEAKEST , GPIO_DRIVE_WEAK , GPIO_DRIVE_STRONG , GPIO_DRIVE_STRONGEST }
 Enumeration of drive strength options. More...
 
enum  gpio_slew_t { GPIO_SLEW_SLOWEST , GPIO_SLEW_SLOW , GPIO_SLEW_FAST , GPIO_SLEW_FASTEST }
 Enumeration of slew rate settings. More...
 

Functions

gpio_port_t gpio_port (uword_t num)
 Get the gpio_port_t value of the port number num.
 
uword_t gpio_port_num (gpio_port_t port)
 Get the number of the GPIO port port refers to.
 
static bool is_gpio_port_num_valid (uint_fast8_t num)
 Check if the given number is a valid argument for gpio_port.
 
int gpio_ll_init (gpio_port_t port, uint8_t pin, gpio_conf_t conf)
 Initialize the given GPIO pin as specified.
 
gpio_conf_t gpio_ll_query_conf (gpio_port_t port, uint8_t pin)
 Retrieve the current configuration of a GPIO pin.
 
void gpio_ll_print_conf_common (const gpio_conf_t conf)
 INTERNAL, use gpio_ll_print_conf instead.
 
void gpio_ll_print_conf (const gpio_conf_t conf)
 Utility function to print a given GPIO configuration to stdio.
 
static uword_t gpio_ll_read (gpio_port_t port)
 Get the current input value of all GPIO pins of the given port as bitmask.
 
static uword_t gpio_ll_read_output (gpio_port_t port)
 Get the current output value of all GPIO pins of the given port as bitmask.
 
static void gpio_ll_set (gpio_port_t port, uword_t mask)
 Perform an reg |= mask operation on the I/O register of the port.
 
static void gpio_ll_clear (gpio_port_t port, uword_t mask)
 Perform an reg &= ~mask operation on the I/O register of the port.
 
static void gpio_ll_toggle (gpio_port_t port, uword_t mask)
 Perform an reg ^= mask operation on the I/O register of the port.
 
static uword_t gpio_ll_prepare_write_all_outputs (gpio_port_t port, uword_t value)
 Same as gpio_ll_prepare_write(port, UWORD_MAX, value), but faster.
 
static uword_t gpio_ll_prepare_write (gpio_port_t port, uword_t mask, uword_t value)
 Helper to use gpio_ll_write side-effect free.
 
static uword_t gpio_ll_prepare_switch_dir (uword_t mask)
 Prepare bitmask for use with gpio_ll_switch_dir_output and gpio_ll_switch_dir_input.
 
static void gpio_ll_switch_dir_output (gpio_port_t port, uword_t pins)
 Turn GPIO pins specified by pins (obtained from gpio_ll_prepare_switch_dir) to outputs.
 
static void gpio_ll_switch_dir_input (gpio_port_t port, uword_t pins)
 Turn GPIO pins specified by pins (obtained from gpio_ll_prepare_switch_dir) to inputs.
 
static void gpio_ll_write (gpio_port_t port, uword_t state)
 Perform a masked write operation on the I/O register of the port.
 
static gpio_port_t gpio_get_port (gpio_t pin)
 Extract the gpio_port_t from a gpio_t
 
static uint8_t gpio_get_pin_num (gpio_t pin)
 Extract the pin number from a gpio_t
 
static gpio_port_t gpio_port_pack_addr (void *addr)
 Pack a pointer into a gpio_port_t.
 
static void * gpio_port_unpack_addr (gpio_port_t port)
 Extract a data pointer that was packed by gpio_port_pack_addr.
 

Variables

typedef gpio_conf_t
 GPIO pin configuration.
 

GPIO port aliases for alphabetic enumeration

#define GPIO_PORT_A   GPIO_PORT_0
 Alias of ref GPIO_PORT_0
 
#define GPIO_PORT_B   GPIO_PORT_1
 Alias of ref GPIO_PORT_1
 
#define GPIO_PORT_C   GPIO_PORT_2
 Alias of ref GPIO_PORT_2
 
#define GPIO_PORT_D   GPIO_PORT_3
 Alias of ref GPIO_PORT_3
 
#define GPIO_PORT_E   GPIO_PORT_4
 Alias of ref GPIO_PORT_4
 
#define GPIO_PORT_F   GPIO_PORT_5
 Alias of ref GPIO_PORT_5
 
#define GPIO_PORT_G   GPIO_PORT_6
 Alias of ref GPIO_PORT_6
 
#define GPIO_PORT_H   GPIO_PORT_7
 Alias of ref GPIO_PORT_7
 
#define GPIO_PORT_I   GPIO_PORT_8
 Alias of ref GPIO_PORT_8
 
#define GPIO_PORT_J   GPIO_PORT_9
 Alias of ref GPIO_PORT_9
 
#define GPIO_PORT_K   GPIO_PORT_10
 Alias of ref GPIO_PORT_10
 
#define GPIO_PORT_L   GPIO_PORT_11
 Alias of ref GPIO_PORT_11
 
#define GPIO_PORT_M   GPIO_PORT_12
 Alias of ref GPIO_PORT_12
 
#define GPIO_PORT_N   GPIO_PORT_13
 Alias of ref GPIO_PORT_13
 
#define GPIO_PORT_O   GPIO_PORT_14
 Alias of ref GPIO_PORT_14
 
#define GPIO_PORT_P   GPIO_PORT_15
 Alias of ref GPIO_PORT_15
 

Commonly used GPIO LL configuration presets

Warning
These are not available in C++

C++ requires initializers to be provided in declaration order and contain explicit initialization for each and every field. However, the actual layout and the number of members of gpio_conf_t depends on the implementation, so that implementations can expose advanced features such as pull strength, driver strength, skew rate, mux settings, etc. The API mandates that those extra fields will have a sane default value when implicitly initialized with 0, as done here in C.

This doesn't work in C++, unless multiplying the maintenance burden by the number of implementations by having each implementation provide this by hand. This is not acceptable.

static const gpio_conf_t gpio_ll_in
 A standard configuration for a generic floating input pin.
 
static const gpio_conf_t gpio_ll_in_pd
 A standard configuration for a generic input pin with pull down resistor.
 
static const gpio_conf_t gpio_ll_in_pu
 A standard configuration for a generic input pin with pull up resistor.
 
static const gpio_conf_t gpio_ll_in_pk
 A standard configuration for a generic input pin with pull resistor to keep signal at bus level.
 
static const gpio_conf_t gpio_ll_out
 A standard configuration for a generic push-pull output pin.
 
static const gpio_conf_t gpio_ll_od
 A standard configuration for a generic floating open drain output.
 
static const gpio_conf_t gpio_ll_od_pu
 A standard configuration for a generic open drain output with pull up.