Skip to main content

DedicatedGpioInputBundle

Struct DedicatedGpioInputBundle 

Source
pub struct DedicatedGpioInputBundle<'lt> { /* private fields */ }
Expand description

A bundle of dedicated GPIO input drivers.

An input bundle precomputes a channel mask from one or more DedicatedGpioInput drivers. This lets you read multiple dedicated input channels with a single low-level read (see DedicatedGpioInputBundle::levels).

Attaching a driver does not change any pin state. The bundle only stores a channel mask; it does not own pins or remember which GPIOs were connected.

§Relationship to pins

Dedicated input channels are fed by GPIO pins that were connected when creating DedicatedGpioInput. The bundle operates on channels, not individual pins: each bit in the returned mask corresponds to a dedicated input channel.

If you later reconfigure a GPIO pin (e.g. connect it to a different peripheral input), that changes what the channel reads. The bundle does not prevent such reconfiguration.

§Examples

use esp_hal::gpio::{
    Input,
    InputConfig,
    dedicated::{DedicatedGpio, DedicatedGpioInput, DedicatedGpioInputBundle},
};

// Create channels:
let channels = DedicatedGpio::new(peripherals.GPIO_DEDICATED);

// Create input drivers for two channels:
let p0 = Input::new(peripherals.GPIO0, InputConfig::default());
let p1 = Input::new(peripherals.GPIO1, InputConfig::default());
let in0 = DedicatedGpioInput::new(channels.channel0, p0);
let in1 = DedicatedGpioInput::new(channels.channel1, p1);

// Build a bundle that reads channels 0 and 1:
let mut bundle = DedicatedGpioInputBundle::new();
bundle.enable_input(&in0).enable_input(&in1);

// Read both channels at once:
let bits = bundle.levels();
// bit 0 -> channel 0, bit 1 -> channel 1, ...

Implementations§

Source§

impl<'lt> DedicatedGpioInputBundle<'lt>

Source

pub fn new() -> Self

Creates a new, empty dedicated GPIO input bundle.

A bundle is a logical grouping of one or more DedicatedGpioInput drivers. Internally, it stores a precomputed channel mask which allows reading multiple dedicated input channels efficiently.

The returned bundle initially contains no channels. Add inputs using Self::enable_input.

§Notes
  • Creating a bundle does not configure any hardware by itself.
Source

pub fn mask(&self) -> u32

Returns the channel mask of this bundle.

Each bit corresponds to one dedicated GPIO channel:

  • bit 0 -> channel 0
  • bit 1 -> channel 1

A bit is set to 1 if that channel is currently included in the bundle.

§Example

use esp_hal::gpio::{
    Input,
    InputConfig,
    dedicated::{DedicatedGpio, DedicatedGpioInput, DedicatedGpioInputBundle},
};

let channels = DedicatedGpio::new(peripherals.GPIO_DEDICATED);
let in0 = DedicatedGpioInput::new(
    channels.channel0,
    Input::new(peripherals.GPIO0, InputConfig::default()),
);
let in2 = DedicatedGpioInput::new(
    channels.channel2,
    Input::new(peripherals.GPIO2, InputConfig::default()),
);

let mut bundle = DedicatedGpioInputBundle::new();
bundle.enable_input(&in0).enable_input(&in2);

let mask = bundle.mask(); // bit 0 -> ch0, bit 2 -> ch2, ...
// For this bundle: mask == 0b0000_0101 (channels 0 and 2).
Source

pub fn enable_input<'d>( &mut self, inp: &'lt DedicatedGpioInput<'d>, ) -> &mut Self

Attaches (enables) an already-configured dedicated input driver to this bundle. After enabling, you will be able to read the input channels of inp via this bundle.

This method logically borrows the provided DedicatedGpioInput for the lifetime 'lt. Multiple bundles may borrow the same input driver at the same time. Check examples in the module-level documentation for more.

§Notes
  • This function does not change any input state.
Source

pub fn disable_input<'d>( &mut self, inp: &'lt DedicatedGpioInput<'d>, ) -> &mut Self

Disables a dedicated input driver in this bundle.

This updates the internal mask by clearing the channel bit(s) of inp. After disabling, future bundle operations will no longer touch those channels.

§Notes
  • This does not affect inp itself. It only changes which channels future bundle operations will touch.
  • This does not end the lifetime-based borrow of inp. Even after disabling, inp still cannot be moved or dropped while this bundle exists.
  • You can re-enable it later via Self::enable_input.
Source

pub fn levels(&self) -> u32

Reads the current state of the channels included by this bundle.

For channels outside the bundle mask, the corresponding bits are always 0.

§Example

If the bundle mask is 0b0000_1011 (channels 0, 1, and 3), then levels() will only contain bits 0, 1, and 3, regardless of the state of other channels.

Source

pub fn all_high(&self) -> bool

Returns true if all channels in this bundle are currently high.

Source

pub fn all_low(&self) -> bool

Returns true if all channels in this bundle are currently low.

Trait Implementations§

Source§

impl<'lt> Default for DedicatedGpioInputBundle<'lt>

Available on crate feature unstable only.
Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<'lt> Freeze for DedicatedGpioInputBundle<'lt>

§

impl<'lt> RefUnwindSafe for DedicatedGpioInputBundle<'lt>

§

impl<'lt> Send for DedicatedGpioInputBundle<'lt>

§

impl<'lt> Sync for DedicatedGpioInputBundle<'lt>

§

impl<'lt> Unpin for DedicatedGpioInputBundle<'lt>

§

impl<'lt> UnsafeUnpin for DedicatedGpioInputBundle<'lt>

§

impl<'lt> UnwindSafe for DedicatedGpioInputBundle<'lt>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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> Same for T

Source§

type Output = T

Should always be Self
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.