PinGroup

Struct PinGroup 

Source
pub struct PinGroup<T = HNil>(/* private fields */);
Expand description

A group of pins to be controlled together and guaranty single cycle control of several pins.

use rp235x_hal::{
    self as hal,
    gpio::{bank0::Gpio12, Pin, PinGroup, PinState, Pins},
    sio::Sio,
};

let mut peripherals = hal::pac::Peripherals::take().unwrap();
let sio = Sio::new(peripherals.SIO);
let pins = Pins::new(
    peripherals.IO_BANK0,
    peripherals.PADS_BANK0,
    sio.gpio_bank0,
    &mut peripherals.RESETS,
);

let group = PinGroup::new();
let group = group.add_pin(pins.gpio0.into_pull_up_input());
let mut group = group.add_pin(pins.gpio4.into_push_pull_output_in_state(PinState::High));

defmt!("Group's state is: {}", group.read());
group.toggle();
defmt!("Group's state is: {}", group.read());

Implementations§

Source§

impl PinGroup

Source

pub fn new() -> PinGroup

Creates an empty pin group.

Source

pub fn add_pin<P, C>(self, pin: P) -> PinGroup<HCons<P, HNil>>
where C: SioConfig, P: AnyPin<Function = FunctionSio<C>>, <P as AnyPin>::Id: TypeLevelPinId,

Add a pin to the group.

Source§

impl<T, H> PinGroup<HCons<H, T>>
where <H as AnyPin>::Id: TypeLevelPinId, H: AnyPin,

Source

pub fn add_pin<C, P>(self, pin: P) -> PinGroup<HCons<P, HCons<H, T>>>
where C: SioConfig, P: AnyPin<Function = FunctionSio<C>>, <P as AnyPin>::Id: TypeLevelPinId<Bank = <<H as AnyPin>::Id as TypeLevelPinId>::Bank>,

Add a pin to the group.

Source

pub fn remove_pin<P, Index>( self, ) -> (P, PinGroup<<HCons<H, T> as Plucker<P, Index>>::Remainder>)
where HCons<H, T>: Plucker<P, Index>,

Pluck a pin from the group.

Source§

impl<H, T> PinGroup<HCons<H, T>>
where HCons<H, T>: ReadPinHList + WritePinHList, H: AnyPin,

Source

pub fn read(&self) -> u32

Read the whole group at once.

The returned value is a bit field where each pin populates its own index. Therefore, there might be “holes” in the value. Unoccupied bits will always read as 0.

For example, if the group contains Gpio1 and Gpio3, a read may yield:

0b0000_0000__0000_0000__0000_0000__0000_1010
                         This is Gpio3  ↑↑↑
                     Gpio2 is not used   ||
                         This is Gpio1    |
Source

pub fn set(&mut self, state: PinState)

Write this set of pins all at the same time.

This only affects output pins. Input pins in the set are ignored.

Source

pub fn set_u32(&mut self, state: u32)

Set this set of pins to the state given in a single operation.

The state passed in must be a mask where each bit corresponds to a gpio.

For example, if the group contains Gpio1 and Gpio3, a read may yield:

0b0000_0000__0000_0000__0000_0000__0000_1010
                         This is Gpio3  ↑↑↑
                     Gpio2 is not used   ||
                         This is Gpio1    |

State corresponding to bins not in this group are ignored.

Source

pub fn toggle(&mut self)

Toggles this set of pins all at the same time.

This only affects output pins. Input pins in the set are ignored.

Trait Implementations§

Source§

impl Default for PinGroup

Source§

fn default() -> PinGroup

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for PinGroup<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for PinGroup<T>
where T: RefUnwindSafe,

§

impl<T> Send for PinGroup<T>
where T: Send,

§

impl<T> Sync for PinGroup<T>
where T: Sync,

§

impl<T> Unpin for PinGroup<T>
where T: Unpin,

§

impl<T> UnwindSafe for PinGroup<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<Choices> CoproductSubsetter<CNil, HNil> for Choices

Source§

type Remainder = Choices

Source§

fn subset( self, ) -> Result<CNil, <Choices as CoproductSubsetter<CNil, HNil>>::Remainder>

Extract a subset of the possible types in a coproduct (or get the remaining possibilities) 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 T
where 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U, I> LiftInto<U, I> for T
where U: LiftFrom<T, I>,

Source§

fn lift_into(self) -> U

Performs the indexed conversion.
Source§

impl<Source> Sculptor<HNil, HNil> for Source

Source§

type Remainder = Source

Source§

fn sculpt(self) -> (HNil, <Source as Sculptor<HNil, HNil>>::Remainder)

Consumes the current HList and returns an HList with the requested shape. Read more
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.