Skip to main content

PinScript

Struct PinScript 

Source
pub struct PinScript { /* private fields */ }
Expand description

A GPIO line that records the levels it is driven to and answers reads from a script.

Driving the pin appends to driven. Reading it returns the next scripted level, or the level it was last driven to once the script is used up, so a line that is only ever an output never runs dry.

§Examples

use pamoja_hal::digital::{InputPin, OutputPin, PinState};
use pamoja_hal::script::PinScript;

let mut pin = PinScript::new([PinState::Low, PinState::High]);
pin.set_high()?;
pin.set_low()?;
assert_eq!(pin.driven(), [PinState::High, PinState::Low]);
assert!(pin.is_low()?);
assert!(pin.is_high()?);

Implementations§

Source§

impl PinScript

Source

pub fn new(inputs: impl IntoIterator<Item = PinState>) -> PinScript

Creates a released (high) line whose reads answer inputs in order.

§Arguments
  • inputs - the levels each read returns, in order.
§Returns

The scripted pin.

Source

pub fn driven(&self) -> &[PinState]

Returns every level the pin was driven to, oldest first.

§Returns

The levels set through OutputPin.

Source

pub fn level(&self) -> PinState

Returns the level the pin was last driven to.

§Returns

The current output level.

Source

pub fn remaining(&self) -> usize

Reports how many scripted input levels remain unread.

§Returns

The number of reads the script still answers.

Trait Implementations§

Source§

impl Clone for PinScript

Source§

fn clone(&self) -> PinScript

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PinScript

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for PinScript

Source§

fn default() -> Self

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

impl ErrorType for PinScript

Source§

type Error = Infallible

Error type
Source§

impl InputPin for PinScript

Source§

fn is_high(&mut self) -> Result<bool, Self::Error>

Is the input pin high?
Source§

fn is_low(&mut self) -> Result<bool, Self::Error>

Is the input pin low?
Source§

impl OutputPin for PinScript

Source§

fn set_low(&mut self) -> Result<(), Self::Error>

Drives the pin low. Read more
Source§

fn set_high(&mut self) -> Result<(), Self::Error>

Drives the pin high. Read more
§

fn set_state(&mut self, state: PinState) -> Result<(), Self::Error>

Drives the pin high or low depending on the provided value. Read more
Source§

impl StatefulOutputPin for PinScript

Source§

fn is_set_high(&mut self) -> Result<bool, Self::Error>

Is the pin in drive high mode? Read more
Source§

fn is_set_low(&mut self) -> Result<bool, Self::Error>

Is the pin in drive low mode? Read more
§

fn toggle(&mut self) -> Result<(), Self::Error>

Toggle pin output.

Auto Trait Implementations§

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.