Struct gpio_cdev::Chip [−][src]
pub struct Chip { /* fields omitted */ }
Expand description
A GPIO Chip maps to the actual device driver instance in hardware that one interacts with to interact with individual GPIOs. Often these chips map to IP chunks on an SoC but could also be enumerated within the kernel via something like a PCI or USB bus.
The Linux kernel itself enumerates GPIO character devices at two paths:
/dev/gpiochipN
/sys/bus/gpiochipN
It is best not to assume that a device will always be enumerated in the same order (especially if it is connected via a bus). In order to reliably find the correct chip, there are a few approaches that one could reasonably take:
- Create a udev rule that will match attributes of the device and setup a symlink to the device.
- Iterate over all available chips using the
chips()
call to find the device with matching criteria. - For simple cases, just using the enumerated path is fine (demo work). This is discouraged for production.
Implementations
Open the GPIO Chip at the provided path (e.g. /dev/gpiochip<N>
)
A functional name for this GPIO chip, such as a product number. Might be an empty string.
As an example, the SoC GPIO chip on a Raspberry Pi is “pinctrl-bcm2835”
The number of lines/pins indexable through this chip
Not all of these may be usable depending on how the hardware is configured/muxed.
Get a handle to the GPIO line at a given offset
The actual physical line corresponding to a given offset is completely dependent on how the driver/hardware for the chip works as well as the associated board layout.
For a device like the NXP i.mx6 SoC GPIO controller there
are several banks of GPIOs with each bank containing 32
GPIOs. For this hardware and driver something like
GPIO2_5
would map to offset 37.
Get a handle to multiple GPIO line at a given offsets
The group of lines can be manipulated simultaneously.
Get a handle to all the GPIO lines on the chip
The group of lines can be manipulated simultaneously.
pub fn lines(&self) -> LineIteratorⓘNotable traits for LineIteratorimpl Iterator for LineIterator type Item = Line;
pub fn lines(&self) -> LineIteratorⓘNotable traits for LineIteratorimpl Iterator for LineIterator type Item = Line;
impl Iterator for LineIterator type Item = Line;
Get an interator over all lines that can be potentially access for this chip.