diff --git a/src/adc.rs b/src/adc.rs index 5691c29b..67ac6dfa 100644 --- a/src/adc.rs +++ b/src/adc.rs @@ -249,7 +249,7 @@ macro_rules! adc_hal { /// Returns the largest possible sample value for the current settings pub fn max_sample(&self) -> u16 { match self.align { - Align::Left => u16::max_value(), + Align::Left => u16::MAX, Align::Right => (1 << 12) - 1, } } diff --git a/src/gpio.rs b/src/gpio.rs index 4a4a5d5c..546f45cc 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -26,16 +26,16 @@ //! - **Dynamic**: Pin mode is selected at runtime. See changing configurations for more details //! - Input //! - **PullUp**: Input connected to high with a weak pull-up resistor. Will be high when nothing -//! is connected +//! is connected //! - **PullDown**: Input connected to ground with a weak pull-down resistor. Will be low when nothing -//! is connected +//! is connected //! - **Floating**: Input not pulled to high or low. Will be undefined when nothing is connected //! - Output //! - **PushPull**: Output which either drives the pin high or low //! - **OpenDrain**: Output which leaves the gate floating, or pulls it to ground in drain -//! mode. Can be used as an input in the `open` configuration +//! mode. Can be used as an input in the `open` configuration //! - **Debugger**: Some pins start out being used by the debugger. A pin in this mode can only be -//! used if the [JTAG peripheral has been turned off](#accessing-pa15-pb3-and-pb14). +//! used if the [JTAG peripheral has been turned off](#accessing-pa15-pb3-and-pb14). //! //! ## Changing modes //! The simplest way to change the pin mode is to use the `into_` functions. These return a @@ -215,7 +215,7 @@ mod sealed { } use sealed::Interruptable; -use sealed::PinMode; +pub(crate) use sealed::PinMode; impl Interruptable for Input {} impl Interruptable for Dynamic {} @@ -639,43 +639,38 @@ where /// pin. #[inline] pub fn into_alternate_push_pull( - mut self, + self, cr: &mut ::Cr, ) -> Pin> { - self.mode::>(cr); - Pin::new() + self.into_mode(cr) } /// Configures the pin to operate as an alternate function open-drain output /// pin. #[inline] pub fn into_alternate_open_drain( - mut self, + self, cr: &mut ::Cr, ) -> Pin> { - self.mode::>(cr); - Pin::new() + self.into_mode(cr) } /// Configures the pin to operate as a floating input pin #[inline] - pub fn into_floating_input(mut self, cr: &mut ::Cr) -> Pin> { - self.mode::>(cr); - Pin::new() + pub fn into_floating_input(self, cr: &mut ::Cr) -> Pin> { + self.into_mode(cr) } /// Configures the pin to operate as a pulled down input pin #[inline] - pub fn into_pull_down_input(mut self, cr: &mut ::Cr) -> Pin> { - self.mode::>(cr); - Pin::new() + pub fn into_pull_down_input(self, cr: &mut ::Cr) -> Pin> { + self.into_mode(cr) } /// Configures the pin to operate as a pulled up input pin #[inline] - pub fn into_pull_up_input(mut self, cr: &mut ::Cr) -> Pin> { - self.mode::>(cr); - Pin::new() + pub fn into_pull_up_input(self, cr: &mut ::Cr) -> Pin> { + self.into_mode(cr) } /// Configures the pin to operate as an open-drain output pin. @@ -694,8 +689,7 @@ where initial_state: PinState, ) -> Pin> { self._set_state(initial_state); - self.mode::>(cr); - Pin::new() + self.into_mode(cr) } /// Configures the pin to operate as an push-pull output pin. @@ -714,26 +708,23 @@ where initial_state: PinState, ) -> Pin> { self._set_state(initial_state); - self.mode::>(cr); - Pin::new() + self.into_mode(cr) } /// Configures the pin to operate as an push-pull output pin. /// The state will not be changed. #[inline] pub fn into_push_pull_output_with_current_state( - mut self, + self, cr: &mut ::Cr, ) -> Pin> { - self.mode::>(cr); - Pin::new() + self.into_mode(cr) } /// Configures the pin to operate as an analog input pin #[inline] - pub fn into_analog(mut self, cr: &mut ::Cr) -> Pin { - self.mode::(cr); - Pin::new() + pub fn into_analog(self, cr: &mut ::Cr) -> Pin { + self.into_mode(cr) } /// Configures the pin as a pin that can change between input @@ -977,6 +968,12 @@ where (r_bits & !(0b1111 << Self::OFFSET)) | (bits << Self::OFFSET) }); } + + #[inline] + pub(crate) fn into_mode(mut self, cr: &mut ::Cr) -> Pin { + self.mode::(cr); + Pin::new() + } } gpio!(GPIOA, gpioa, PAx, 'A', [ diff --git a/src/qei.rs b/src/qei.rs index 85ca7a5d..bf7af2a3 100644 --- a/src/qei.rs +++ b/src/qei.rs @@ -4,8 +4,6 @@ NOTE: In some cases you need to specify remap you need, especially for TIM2 (see [Alternate function remapping](super::timer)): */ -use core::u16; - use core::marker::PhantomData; #[cfg(any(feature = "stm32f100", feature = "stm32f103", feature = "connectivity",))] diff --git a/src/rcc/enable.rs b/src/rcc/enable.rs index 3c1de238..c6218145 100644 --- a/src/rcc/enable.rs +++ b/src/rcc/enable.rs @@ -184,7 +184,7 @@ bus! { TIM11 => (APB2, 21), } -#[cfg(any(feature = "stm32f103"))] // feature = "stm32f102" +#[cfg(feature = "stm32f103")] // feature = "stm32f102" bus! { USB => (APB1, 23), } diff --git a/src/serial.rs b/src/serial.rs index 9647fb0b..cd2384d8 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -759,13 +759,13 @@ macro_rules! serialdma { atomic::compiler_fence(Ordering::Release); - self.channel.ch().cr.modify(|_, w| { w - .mem2mem() .clear_bit() - .pl() .medium() - .msize() .bits8() - .psize() .bits8() - .circ() .set_bit() - .dir() .clear_bit() + self.channel.ch().cr.modify(|_, w| { + w.mem2mem().clear_bit(); + w.pl().medium(); + w.msize().bits8(); + w.psize().bits8(); + w.circ().set_bit(); + w.dir().clear_bit() }); self.start(); @@ -787,13 +787,13 @@ macro_rules! serialdma { self.channel.set_transfer_length(len); atomic::compiler_fence(Ordering::Release); - self.channel.ch().cr.modify(|_, w| { w - .mem2mem() .clear_bit() - .pl() .medium() - .msize() .bits8() - .psize() .bits8() - .circ() .clear_bit() - .dir() .clear_bit() + self.channel.ch().cr.modify(|_, w| { + w.mem2mem().clear_bit(); + w.pl().medium(); + w.msize().bits8(); + w.psize().bits8(); + w.circ().clear_bit(); + w.dir().clear_bit() }); self.start(); @@ -817,13 +817,13 @@ macro_rules! serialdma { atomic::compiler_fence(Ordering::Release); - self.channel.ch().cr.modify(|_, w| { w - .mem2mem() .clear_bit() - .pl() .medium() - .msize() .bits8() - .psize() .bits8() - .circ() .clear_bit() - .dir() .set_bit() + self.channel.ch().cr.modify(|_, w| { + w.mem2mem().clear_bit(); + w.pl().medium(); + w.msize().bits8(); + w.psize().bits8(); + w.circ().clear_bit(); + w.dir().set_bit() }); self.start(); diff --git a/src/spi.rs b/src/spi.rs index 95fe72ae..8843e9cc 100644 --- a/src/spi.rs +++ b/src/spi.rs @@ -500,7 +500,7 @@ where // disable SS output spi.cr2.write(|w| w.ssoe().clear_bit()); - let br = match SPI::clock(&clocks) / freq { + let br = match SPI::clock(clocks) / freq { 0 => unreachable!(), 1..=2 => 0b000, 3..=5 => 0b001, diff --git a/src/timer/pwm_input.rs b/src/timer/pwm_input.rs index f6b3c78a..d20e4701 100644 --- a/src/timer/pwm_input.rs +++ b/src/timer/pwm_input.rs @@ -160,9 +160,9 @@ impl Timer { /// Courtesy of @TeXitoi (https://github.com/stm32-rs/stm32f1xx-hal/pull/10#discussion_r259535503) fn compute_arr_presc(freq: u32, clock: u32) -> (u16, u16) { if freq == 0 { - return (core::u16::MAX, core::u16::MAX); + return (u16::MAX, u16::MAX); } - let presc = clock / freq.saturating_mul(core::u16::MAX as u32 + 1); + let presc = clock / freq.saturating_mul(u16::MAX as u32 + 1); let arr = clock / freq.saturating_mul(presc + 1); (core::cmp::max(1, arr as u16), presc as u16) }