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<T, H> PinGroup<HCons<H, T>>
impl<T, H> PinGroup<HCons<H, T>>
Source§impl<H, T> PinGroup<HCons<H, T>>
impl<H, T> PinGroup<HCons<H, T>>
Sourcepub fn read(&self) -> u32
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 |Sourcepub fn set(&mut self, state: PinState)
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.
Sourcepub fn set_u32(&mut self, state: u32)
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.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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