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(num)   implementation_specific
 Get the gpio_port_t value of the port identified by num.
 
#define GPIO_PORT_NUM(port)   implementation_specific
 Get the number of the GPIO port belonging to the given gpio_port_t value.
 
#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

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 void gpio_ll_switch_dir_output (gpio_port_t port, uword_t outputs)
 Turn GPIO pins specified by the bitmask outputs to outputs.
 
static void gpio_ll_switch_dir_input (gpio_port_t port, uword_t inputs)
 Turn GPIO pins specified by the bitmask inputs 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.
 

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.