From 4db944ad4e1096202f673cd85ddd3e6bcfa0f662 Mon Sep 17 00:00:00 2001 From: Mathias Gottschlag Date: Fri, 1 Oct 2021 18:41:10 +0200 Subject: [PATCH] pio: Fix clippy warnings and examples in doc comments. --- rp2040-hal/src/pio.rs | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/rp2040-hal/src/pio.rs b/rp2040-hal/src/pio.rs index 998db63..8b87d9f 100644 --- a/rp2040-hal/src/pio.rs +++ b/rp2040-hal/src/pio.rs @@ -11,6 +11,7 @@ pub trait PIOExt: core::ops::Deref + SubsystemReset + Sized { /// Create a new PIO wrapper and split the state machines into individual objects. + #[allow(clippy::type_complexity)] // Required for symmetry with PIO::free(). fn split( self, resets: &mut pac::RESETS, @@ -188,8 +189,7 @@ impl PIO

{ { self.pio.instr_mem[i + offset].write(|w| unsafe { w.bits(instr as u32) }) } - self.used_instruction_space = - self.used_instruction_space | (((1 << p.code.len()) - 1) << offset); + self.used_instruction_space |= ((1 << p.code.len()) - 1) << offset; Ok(InstalledProgram { offset: offset as u8, length: p.code.len() as u8, @@ -205,7 +205,7 @@ impl PIO

{ /// Removes the specified program from instruction memory, freeing the allocated space. pub fn uninstall(&mut self, p: InstalledProgram

) { let instr_mask = ((1 << p.length as u32) - 1) << p.offset as u32; - self.used_instruction_space = self.used_instruction_space & !instr_mask; + self.used_instruction_space &= !instr_mask; } } @@ -220,12 +220,22 @@ impl PIO

{ /// /// # Examples /// -/// ``` -/// let (mut pio, sm0, _, _, _) = pac.PIO0.split(&mut pac.RESETS); +/// ```no_run +/// use rp2040_hal::{pac, pio::PIOBuilder, pio::PIOExt}; +/// let mut peripherals = 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!( +/// 32, +/// ".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) = rp2040_hal::pio::PIOBuilder::from_program(installed).build(sm0); +/// let (sm, rx, tx) = PIOBuilder::from_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. @@ -239,7 +249,7 @@ impl PIO

{ /// 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. /// -/// ``` +/// ```ignore /// 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(); @@ -530,7 +540,7 @@ impl StateMachine { }); } pin += 1; - pins = pins >> 1; + pins >>= 1; } // We modified PINCTRL, yet the program assumes a certain configuration, so restore the // previous value. @@ -554,7 +564,7 @@ impl StateMachine<(P, SM), Stopped> { /// /// # Example /// - /// ``` + /// ```ignore /// sm0.synchronize_with(sm1).and_with(sm2); /// ``` pub fn synchronize_with<'sm, SM2: StateMachineIndex>( @@ -1151,6 +1161,7 @@ impl PIOBuilder

{ } /// Build the config and deploy it to a StateMachine. + #[allow(clippy::type_complexity)] // The return type cannot really be simplified. pub fn build( self, mut sm: UninitStateMachine<(P, SM)>, @@ -1268,7 +1279,7 @@ impl PIOBuilder

{ }; ( StateMachine { - sm: sm, + sm, program: self.program, _phantom: core::marker::PhantomData, },