[][src]Struct gpio_cdev::Chip

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:

  1. /dev/gpiochipN
  2. /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:

  1. Create a udev rule that will match attributes of the device and setup a symlink to the device.
  2. Iterate over all available chips using the chips() call to find the device with matching criteria.
  3. For simple cases, just using the enumerated path is fine (demo work). This is discouraged for production.

Methods

impl Chip[src]

pub fn new<P: AsRef<Path>>(path: P) -> Result<Chip>[src]

Open the GPIO Chip at the provided path (e.g. /dev/gpiochip<N>)

pub fn path(&self) -> &Path[src]

Get the fs path of this character device (e.g. /dev/gpiochipN)

pub fn name(&self) -> &str[src]

The name of the device driving this GPIO chip in the kernel

pub fn label(&self) -> &str[src]

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"

pub fn num_lines(&self) -> u32[src]

The 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]

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.

pub fn get_lines(&mut self, offsets: &[u32]) -> Result<Lines>[src]

Get a handle to multiple GPIO line at a given offsets

The group of lines can be manipulated simultaneously.

pub fn get_all_lines(&mut self) -> Result<Lines>[src]

Get a handle to all the GPIO lines on the chip

The group of lines can be manipulated simultaneously.

Important traits for LineIterator
pub fn lines(&self) -> LineIterator[src]

Get an interator over all lines that can be potentially access for this chip.

Trait Implementations

impl Debug for Chip[src]

Auto Trait Implementations

impl Send for Chip

impl Sync for Chip

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]