GPIO controller class.
More...
|
| #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.
|
| |
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.
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():
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.
◆ pbl_gpio_port
| 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
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. |
◆ PBL_GPIO
| #define PBL_GPIO |
( |
|
_port, |
|
|
|
_pin, |
|
|
|
_flags |
|
) |
| {.port = (_port), .pin = (_pin), .flags = (_flags)} |
Initializer for a struct pbl_gpio.
- Parameters
-
| _port | Port. |
| _pin | Pin number on the port. |
| _flags | Wiring 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:
#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
-
◆ PBL_GPIO_INPUT
| #define PBL_GPIO_INPUT (1U << 4) |
◆ 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
◆ PBL_GPIO_OUTPUT_HIGH
◆ PBL_GPIO_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
◆ PBL_GPIO_PORT_INIT
| #define PBL_GPIO_PORT_INIT |
( |
|
sym, |
|
|
|
_name, |
|
|
|
_init, |
|
|
|
_parent, |
|
|
|
_ops, |
|
|
|
_num_pins, |
|
|
|
_intc |
|
) |
| |
Value: { \
.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
-
| sym | Symbol of the port instance, with its state defined by PBL_DEVICE_STATE_DEFINE(). |
| _name | Name. |
| _init | Device init function, or NULL. |
| _parent | Parent device, or NULL. |
| _ops | Driver operations. |
| _num_pins | Number of pins. |
| _intc | Interrupt controller of the pins, or NULL. |
◆ PBL_GPIO_PULL_DOWN
| #define PBL_GPIO_PULL_DOWN (1U << 2) |
◆ PBL_GPIO_PULL_UP
| #define PBL_GPIO_PULL_UP (1U << 1) |
◆ pbl_gpio_configure()
| int pbl_gpio_configure |
( |
const struct pbl_gpio * |
gpio, |
|
|
uint32_t |
flags |
|
) |
| |
Configure a pin.
- Parameters
-
| gpio | Pin, on a ready port. |
| flags | Configuration 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
-
- 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
-
- 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
-
- 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
-
| gpio | Pin. |
| active | True 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
-
| gpio | Pin. |
| level | True for high. |
- Returns
- 0 or a negative errno.
◆ pbl_gpio_to_irq()
Get the interrupt line of a pin.
- Parameters
-
| gpio | Pin. |
| type | Trigger type, physical. |
| [out] | spec | Line. |
- Returns
- 0, or
-ENOTSUP if the port cannot interrupt.
◆ pbl_gpio_port_class