InstalledProgram

Struct InstalledProgram 

Source
pub struct InstalledProgram<P> { /* private fields */ }
Expand description

Handle to a program that was placed in the PIO’s instruction memory.

Objects of this type can be reused for multiple state machines of the same PIO block to save memory if multiple state machines are supposed to perform the same function (for example, if one PIO block is used to implement multiple I2C busses).

PIO::uninstall(program) can be used to free the space occupied by the program once it is no longer used.

§Examples

use rp235x_hal::{self as hal, pio::PIOBuilder, pio::PIOExt};
let mut peripherals = hal::pac::Peripherals::take().unwrap();
let (mut pio, sm0, _, _, _) = peripherals.PIO0.split(&mut peripherals.RESETS);
// Install a program in instruction memory.
let program = pio_proc::pio_asm!(
    ".wrap_target",
    "set pins, 1 [31]",
    "set pins, 0 [31]",
    ".wrap"
)
.program;
let installed = pio.install(&program).unwrap();
// Configure a state machine to use the program.
let (sm, rx, tx) = PIOBuilder::from_installed_program(installed).build(sm0);
// Uninitialize the state machine again, freeing the program.
let (sm, installed) = sm.uninit(rx, tx);
// Uninstall the program to free instruction memory.
pio.uninstall(installed);

§Safety

Objects of this type can outlive their PIO object. If the PIO block is reinitialized, the API does not prevent the user from calling uninstall() when the PIO block does not actually hold the program anymore. The user must therefore make sure that uninstall() is only called on the PIO object which was used to install the program.

let (mut pio, sm0, sm1, sm2, sm3) = pac.PIO0.split(&mut pac.RESETS);
// Install a program in instruction memory.
let installed = pio.install(&program).unwrap();
// Reinitialize PIO.
let pio0 = pio.free(sm0, sm1, sm2, sm3);
let (mut pio, _, _, _, _) = pio0.split(&mut pac.RESETS);
// Do not do the following, the program is not in instruction memory anymore!
pio.uninstall(installed);

Implementations§

Source§

impl<P> InstalledProgram<P>
where P: PIOExt,

Source

pub fn set_wrap( self, wrap: Wrap, ) -> Result<InstalledProgram<P>, InstalledProgram<P>>

Change the source and/or target for automatic program wrapping.

This replaces the current wrap bounds with a new set. This can be useful if you are running multiple state machines with the same program but using different wrap bounds.

§Returns
  • Ok containing a new program with the provided wrap bounds
  • Err containing the old program if the provided wrap was invalid (outside the bounds of the program length)
Source

pub fn wrap_target(&self) -> u8

Get the wrap target (entry point) of the installed program.

Source

pub fn offset(&self) -> u8

Get the offset the program is installed at.

Source

pub unsafe fn share(&self) -> InstalledProgram<P>

Clones this program handle so that it can be executed by two state machines at the same time.

§Safety

This function is marked as unsafe because, once this function has been called, the resulting handle can be used to call PIO::uninstall() while the program is still running.

The user has to make sure to call PIO::uninstall() only once and only after all state machines using the program have been uninitialized.

Trait Implementations§

Source§

impl<P> Debug for InstalledProgram<P>
where P: Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<P> Freeze for InstalledProgram<P>

§

impl<P> RefUnwindSafe for InstalledProgram<P>
where P: RefUnwindSafe,

§

impl<P> Send for InstalledProgram<P>
where P: Send,

§

impl<P> Sync for InstalledProgram<P>
where P: Sync,

§

impl<P> Unpin for InstalledProgram<P>
where P: Unpin,

§

impl<P> UnwindSafe for InstalledProgram<P>
where P: 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.