Struct gpio_cdev::Chip

source ·
pub struct Chip { /* private fields */ }
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:

  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.

Implementations§

source§

impl Chip

source

pub fn new<P: AsRef<Path>>(path: P) -> Result<Self, Error>

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

source

pub fn path(&self) -> &Path

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

source

pub fn name(&self) -> &str

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

source

pub fn label(&self) -> &str

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”

source

pub fn num_lines(&self) -> u32

The number of lines/pins indexable through this chip

Not all of these may be usable depending on how the hardware is configured/muxed.

source

pub fn get_line(&mut self, offset: u32) -> Result<Line, Error>

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.

source

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

Get a handle to multiple GPIO line at a given offsets

The group of lines can be manipulated simultaneously.

source

pub fn get_all_lines(&mut self) -> Result<Lines, Error>

Get a handle to all the GPIO lines on the chip

The group of lines can be manipulated simultaneously.

source

pub fn lines(&self) -> LineIterator

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

Trait Implementations§

source§

impl Debug for Chip

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Chip

§

impl Send for Chip

§

impl Sync for Chip

§

impl Unpin for Chip

§

impl UnwindSafe for Chip

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.