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,
impl<P> InstalledProgram<P>where
P: PIOExt,
Sourcepub fn set_wrap(
self,
wrap: Wrap,
) -> Result<InstalledProgram<P>, InstalledProgram<P>>
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
Sourcepub fn wrap_target(&self) -> u8
pub fn wrap_target(&self) -> u8
Get the wrap target (entry point) of the installed program.
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§
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> 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
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>
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>
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