PebbleOS v4.47.0-512-g5285d4236
Loading...
Searching...
No Matches

GPIO controller class. More...

Modules

 nPM1300 GPIO
 GPIO port over the five GPIOs of the nPM1300, a cell of nPM1300.
 
 nRF5 GPIO
 GPIO ports of the nRF5 SoCs.
 
 QEMU GPIO
 GPIO port of the QEMU GPIO peripheral.
 
 SF32LB GPIO
 GPIO ports of the SF32LB SoCs.
 

Data Structures

struct  pbl_gpio_port_ops
 Port driver operations. More...
 
struct  pbl_gpio_port
 A GPIO controller. More...
 
struct  pbl_gpio
 A pin as wired on the board. More...
 

Macros

#define PBL_GPIO_PORT_INIT(sym, _name, _init, _parent, _ops, _num_pins, _intc)
 Initializer for a struct pbl_gpio_port.
 
#define PBL_GPIO_DT_FLAGS(f)
 Pin flags from the flags cell of a devicetree GPIO specifier.
 
#define PBL_GPIO(_port, _pin, _flags)   {.port = (_port), .pin = (_pin), .flags = (_flags)}
 Initializer for a struct pbl_gpio.
 

Functions

static bool pbl_gpio_is_connected (const struct pbl_gpio *gpio)
 Check whether a pin is connected.
 
int pbl_gpio_configure (const struct pbl_gpio *gpio, uint32_t flags)
 Configure a pin.
 
int pbl_gpio_get (const struct pbl_gpio *gpio)
 Read the logical level of a pin.
 
int pbl_gpio_set (const struct pbl_gpio *gpio, bool active)
 Drive the logical level of a pin.
 
int pbl_gpio_get_raw (const struct pbl_gpio *gpio)
 Read the physical level of a pin.
 
int pbl_gpio_set_raw (const struct pbl_gpio *gpio, bool level)
 Drive the physical level of a pin.
 
int pbl_gpio_to_irq (const struct pbl_gpio *gpio, uint32_t type, struct pbl_irq_spec *spec)
 Get the interrupt line of a pin.
 

Variables

const struct pbl_device_class pbl_gpio_port_class
 Class of the GPIO ports.
 

Wiring flags

Describe the pin as routed on the board, stored in struct pbl_gpio.

#define PBL_GPIO_ACTIVE_LOW   (1U << 0)
 The pin is active when low.
 
#define PBL_GPIO_PULL_UP   (1U << 1)
 Enable the pull-up.
 
#define PBL_GPIO_PULL_DOWN   (1U << 2)
 Enable the pull-down.
 
#define PBL_GPIO_OPEN_DRAIN   (1U << 3)
 Drive the output low only.
 

Configuration flags

Passed to pbl_gpio_configure(), OR'ed with the wiring flags.

#define PBL_GPIO_INPUT   (1U << 4)
 Input.
 
#define PBL_GPIO_OUTPUT   (1U << 5)
 Output, keeping the current level.
 
#define PBL_GPIO_OUTPUT_INIT_LOW   (1U << 6)
 Physical initial level low.
 
#define PBL_GPIO_OUTPUT_INIT_HIGH   (1U << 7)
 Physical initial level high.
 
#define PBL_GPIO_OUTPUT_INIT_LOGICAL   (1U << 8)
 The initial level is logical: inverted on an active-low pin.
 
#define PBL_GPIO_OUTPUT_LOW   (PBL_GPIO_OUTPUT | PBL_GPIO_OUTPUT_INIT_LOW)
 Output, physically low.
 
#define PBL_GPIO_OUTPUT_HIGH   (PBL_GPIO_OUTPUT | PBL_GPIO_OUTPUT_INIT_HIGH)
 Output, physically high.
 
#define PBL_GPIO_OUTPUT_INACTIVE   (PBL_GPIO_OUTPUT_LOW | PBL_GPIO_OUTPUT_INIT_LOGICAL)
 Output, inactive.
 
#define PBL_GPIO_OUTPUT_ACTIVE   (PBL_GPIO_OUTPUT_HIGH | PBL_GPIO_OUTPUT_INIT_LOGICAL)
 Output, active.
 

Detailed Description

GPIO controller class.

A GPIO controller, an SoC port or a peripheral with GPIOs on it, is a struct pbl_gpio_port device. A pin is a struct pbl_gpio: port, pin number and wiring flags (polarity, pulls, open drain), so callers deal in logical levels.

static const struct pbl_gpio s_reset = PBL_GPIO(&dt_gpio1, 28, PBL_GPIO_ACTIVE_LOW);
pbl_gpio_set(&s_reset, false);
bool active = pbl_gpio_get(&dev->int_gpio) > 0;
A pin as wired on the board.
Definition gpio.h:142
int pbl_gpio_set(const struct pbl_gpio *gpio, bool active)
Drive the logical level of a pin.
#define PBL_GPIO_ACTIVE_LOW
The pin is active when low.
Definition gpio.h:50
#define PBL_GPIO_INPUT
Input.
Definition gpio.h:65
int pbl_gpio_get(const struct pbl_gpio *gpio)
Read the logical level of a pin.
#define PBL_GPIO(_port, _pin, _flags)
Initializer for a struct pbl_gpio.
Definition gpio.h:158
#define PBL_GPIO_OUTPUT_ACTIVE
Output, active.
Definition gpio.h:82
int pbl_gpio_configure(const struct pbl_gpio *gpio, uint32_t flags)
Configure a pin.

A port that can interrupt has a child interrupt controller whose line numbers are the pin numbers. Drivers whose pin is described as a GPIO, such as buttons, get its line with pbl_gpio_to_irq():

struct pbl_irq_spec irq;
pbl_intc_request(&irq, prv_handler, dev);
int pbl_gpio_to_irq(const struct pbl_gpio *gpio, uint32_t type, struct pbl_irq_spec *spec)
Get the interrupt line of a pin.
An interrupt line, as used by a consumer.
Definition intc.h:130
#define PBL_IRQ_TYPE_EDGE_BOTH
Both edges.
Definition intc.h:50
int pbl_intc_request(const struct pbl_irq_spec *spec, pbl_intc_handler_t handler, void *arg)
Install the handler of a line and set its trigger type.

Data Structure Documentation

◆ pbl_gpio_port

struct pbl_gpio_port

A GPIO controller.

Data Fields
struct pbl_device dev Device.
const struct pbl_intc * intc Interrupt controller of the pins, NULL if the port cannot interrupt.
uint8_t num_pins Number of pins.
const struct pbl_gpio_port_ops * ops Driver operations.

◆ pbl_gpio

struct pbl_gpio

A pin as wired on the board.

Data Fields
uint8_t flags Wiring flags.
uint8_t pin Pin number on the port.
const struct pbl_gpio_port * port Port, NULL if not connected.

Macro Definition Documentation

◆ PBL_GPIO

#define PBL_GPIO (   _port,
  _pin,
  _flags 
)    {.port = (_port), .pin = (_pin), .flags = (_flags)}

Initializer for a struct pbl_gpio.

Parameters
_portPort.
_pinPin number on the port.
_flagsWiring flags.

◆ PBL_GPIO_ACTIVE_LOW

#define PBL_GPIO_ACTIVE_LOW   (1U << 0)

The pin is active when low.

◆ PBL_GPIO_DT_FLAGS

#define PBL_GPIO_DT_FLAGS (   f)
Value:
((((f) & 0x1U) ? PBL_GPIO_ACTIVE_LOW : 0U) | \
((((f) & 0x6U) == 0x6U) ? PBL_GPIO_OPEN_DRAIN : 0U) | (((f) & 0x10U) ? PBL_GPIO_PULL_UP : 0U) | \
(((f) & 0x20U) ? PBL_GPIO_PULL_DOWN : 0U))
#define PBL_GPIO_PULL_DOWN
Enable the pull-down.
Definition gpio.h:54
#define PBL_GPIO_OPEN_DRAIN
Drive the output low only.
Definition gpio.h:56
#define PBL_GPIO_PULL_UP
Enable the pull-up.
Definition gpio.h:52

Pin flags from the flags cell of a devicetree GPIO specifier.

Parameters
fFlags, those of <dt-bindings/gpio/gpio.h>.

◆ PBL_GPIO_INPUT

#define PBL_GPIO_INPUT   (1U << 4)

Input.

◆ PBL_GPIO_OPEN_DRAIN

#define PBL_GPIO_OPEN_DRAIN   (1U << 3)

Drive the output low only.

◆ PBL_GPIO_OUTPUT

#define PBL_GPIO_OUTPUT   (1U << 5)

Output, keeping the current level.

◆ PBL_GPIO_OUTPUT_ACTIVE

#define PBL_GPIO_OUTPUT_ACTIVE   (PBL_GPIO_OUTPUT_HIGH | PBL_GPIO_OUTPUT_INIT_LOGICAL)

Output, active.

◆ PBL_GPIO_OUTPUT_HIGH

#define PBL_GPIO_OUTPUT_HIGH   (PBL_GPIO_OUTPUT | PBL_GPIO_OUTPUT_INIT_HIGH)

Output, physically high.

◆ PBL_GPIO_OUTPUT_INACTIVE

#define PBL_GPIO_OUTPUT_INACTIVE   (PBL_GPIO_OUTPUT_LOW | PBL_GPIO_OUTPUT_INIT_LOGICAL)

Output, inactive.

◆ PBL_GPIO_OUTPUT_INIT_HIGH

#define PBL_GPIO_OUTPUT_INIT_HIGH   (1U << 7)

Physical initial level high.

◆ PBL_GPIO_OUTPUT_INIT_LOGICAL

#define PBL_GPIO_OUTPUT_INIT_LOGICAL   (1U << 8)

The initial level is logical: inverted on an active-low pin.

◆ PBL_GPIO_OUTPUT_INIT_LOW

#define PBL_GPIO_OUTPUT_INIT_LOW   (1U << 6)

Physical initial level low.

◆ PBL_GPIO_OUTPUT_LOW

#define PBL_GPIO_OUTPUT_LOW   (PBL_GPIO_OUTPUT | PBL_GPIO_OUTPUT_INIT_LOW)

Output, physically low.

◆ PBL_GPIO_PORT_INIT

#define PBL_GPIO_PORT_INIT (   sym,
  _name,
  _init,
  _parent,
  _ops,
  _num_pins,
  _intc 
)
Value:
{ \
.dev = PBL_DEVICE_INIT_CLASS(sym, _name, _init, _parent, &pbl_gpio_port_class), \
.ops = (_ops), \
.num_pins = (_num_pins), \
.intc = (_intc), \
}
#define PBL_DEVICE_INIT_CLASS(sym, _name, _init, _parent, _cls)
Initializer for the struct pbl_device of device instance sym, in class _cls.
Definition device.h:153
const struct pbl_device_class pbl_gpio_port_class
Class of the GPIO ports.

Initializer for a struct pbl_gpio_port.

Parameters
symSymbol of the port instance, with its state defined by PBL_DEVICE_STATE_DEFINE().
_nameName.
_initDevice init function, or NULL.
_parentParent device, or NULL.
_opsDriver operations.
_num_pinsNumber of pins.
_intcInterrupt controller of the pins, or NULL.

◆ PBL_GPIO_PULL_DOWN

#define PBL_GPIO_PULL_DOWN   (1U << 2)

Enable the pull-down.

◆ PBL_GPIO_PULL_UP

#define PBL_GPIO_PULL_UP   (1U << 1)

Enable the pull-up.

Function Documentation

◆ pbl_gpio_configure()

int pbl_gpio_configure ( const struct pbl_gpio *  gpio,
uint32_t  flags 
)

Configure a pin.

Parameters
gpioPin, on a ready port.
flagsConfiguration flags, OR'ed with the pin's wiring flags.
Returns
0, -EINVAL if the pin is not on the port, or another negative errno.

◆ pbl_gpio_get()

int pbl_gpio_get ( const struct pbl_gpio *  gpio)

Read the logical level of a pin.

Parameters
gpioPin.
Returns
1 if active, 0 if not, or a negative errno.

◆ pbl_gpio_get_raw()

int pbl_gpio_get_raw ( const struct pbl_gpio *  gpio)

Read the physical level of a pin.

Parameters
gpioPin.
Returns
1 if high, 0 if low, or a negative errno.

◆ pbl_gpio_is_connected()

static bool pbl_gpio_is_connected ( const struct pbl_gpio *  gpio)
inlinestatic

Check whether a pin is connected.

Parameters
gpioPin.
Returns
True if the pin has a port.

References pbl_gpio::port.

◆ pbl_gpio_set()

int pbl_gpio_set ( const struct pbl_gpio *  gpio,
bool  active 
)

Drive the logical level of a pin.

Parameters
gpioPin.
activeTrue to activate.
Returns
0 or a negative errno.

◆ pbl_gpio_set_raw()

int pbl_gpio_set_raw ( const struct pbl_gpio *  gpio,
bool  level 
)

Drive the physical level of a pin.

Parameters
gpioPin.
levelTrue for high.
Returns
0 or a negative errno.

◆ pbl_gpio_to_irq()

int pbl_gpio_to_irq ( const struct pbl_gpio *  gpio,
uint32_t  type,
struct pbl_irq_spec *  spec 
)

Get the interrupt line of a pin.

Parameters
gpioPin.
typeTrigger type, physical.
[out]specLine.
Returns
0, or -ENOTSUP if the port cannot interrupt.

Variable Documentation

◆ pbl_gpio_port_class

const struct pbl_device_class pbl_gpio_port_class
extern

Class of the GPIO ports.