Struct gpio_cdev::Chip [−][src]
pub struct Chip { /* fields omitted */ }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.
Methods
impl Chip[src]
impl Chippub fn new<P: AsRef<Path>>(path: P) -> Result<Chip>[src]
pub fn new<P: AsRef<Path>>(path: P) -> Result<Chip>Open the GPIO Chip at the provided path (e.g. /dev/gpiochip<N>)
pub fn path(&self) -> &Path[src]
pub fn path(&self) -> &PathGet the fs path of this character device (e.g. /dev/gpiochipN)
pub fn name(&self) -> &str[src]
pub fn name(&self) -> &strThe name of the device driving this GPIO chip in the kernel
pub fn label(&self) -> &str[src]
pub fn label(&self) -> &strA 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"
pub fn num_lines(&self) -> u32[src]
pub fn num_lines(&self) -> u32The number of lines/pins indexable through this chip
Not all of these may be usable depending on how the hardware is configured/muxed.
pub fn get_line(&mut self, offset: u32) -> Result<Line>[src]
pub fn get_line(&mut self, offset: u32) -> Result<Line>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.
ⓘImportant traits for LineIteratorpub fn lines(&self) -> LineIterator[src]
pub fn lines(&self) -> LineIteratorGet an interator over all lines that can be potentially access for this chip.