Skip to content

Commit 6f8ae9d

Browse files
committed
into_mode
1 parent f74efe5 commit 6f8ae9d

File tree

7 files changed

+53
-58
lines changed

7 files changed

+53
-58
lines changed

src/adc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ macro_rules! adc_hal {
249249
/// Returns the largest possible sample value for the current settings
250250
pub fn max_sample(&self) -> u16 {
251251
match self.align {
252-
Align::Left => u16::max_value(),
252+
Align::Left => u16::MAX,
253253
Align::Right => (1 << 12) - 1,
254254
}
255255
}

src/gpio.rs

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@
2626
//! - **Dynamic**: Pin mode is selected at runtime. See changing configurations for more details
2727
//! - Input
2828
//! - **PullUp**: Input connected to high with a weak pull-up resistor. Will be high when nothing
29-
//! is connected
29+
//! is connected
3030
//! - **PullDown**: Input connected to ground with a weak pull-down resistor. Will be low when nothing
31-
//! is connected
31+
//! is connected
3232
//! - **Floating**: Input not pulled to high or low. Will be undefined when nothing is connected
3333
//! - Output
3434
//! - **PushPull**: Output which either drives the pin high or low
3535
//! - **OpenDrain**: Output which leaves the gate floating, or pulls it to ground in drain
36-
//! mode. Can be used as an input in the `open` configuration
36+
//! mode. Can be used as an input in the `open` configuration
3737
//! - **Debugger**: Some pins start out being used by the debugger. A pin in this mode can only be
38-
//! used if the [JTAG peripheral has been turned off](#accessing-pa15-pb3-and-pb14).
38+
//! used if the [JTAG peripheral has been turned off](#accessing-pa15-pb3-and-pb14).
3939
//!
4040
//! ## Changing modes
4141
//! The simplest way to change the pin mode is to use the `into_<mode>` functions. These return a
@@ -215,7 +215,7 @@ mod sealed {
215215
}
216216

217217
use sealed::Interruptable;
218-
use sealed::PinMode;
218+
pub(crate) use sealed::PinMode;
219219

220220
impl<MODE> Interruptable for Input<MODE> {}
221221
impl Interruptable for Dynamic {}
@@ -639,43 +639,38 @@ where
639639
/// pin.
640640
#[inline]
641641
pub fn into_alternate_push_pull(
642-
mut self,
642+
self,
643643
cr: &mut <Self as HL>::Cr,
644644
) -> Pin<P, N, Alternate<PushPull>> {
645-
self.mode::<Alternate<PushPull>>(cr);
646-
Pin::new()
645+
self.into_mode(cr)
647646
}
648647

649648
/// Configures the pin to operate as an alternate function open-drain output
650649
/// pin.
651650
#[inline]
652651
pub fn into_alternate_open_drain(
653-
mut self,
652+
self,
654653
cr: &mut <Self as HL>::Cr,
655654
) -> Pin<P, N, Alternate<OpenDrain>> {
656-
self.mode::<Alternate<OpenDrain>>(cr);
657-
Pin::new()
655+
self.into_mode(cr)
658656
}
659657

660658
/// Configures the pin to operate as a floating input pin
661659
#[inline]
662-
pub fn into_floating_input(mut self, cr: &mut <Self as HL>::Cr) -> Pin<P, N, Input<Floating>> {
663-
self.mode::<Input<Floating>>(cr);
664-
Pin::new()
660+
pub fn into_floating_input(self, cr: &mut <Self as HL>::Cr) -> Pin<P, N, Input<Floating>> {
661+
self.into_mode(cr)
665662
}
666663

667664
/// Configures the pin to operate as a pulled down input pin
668665
#[inline]
669-
pub fn into_pull_down_input(mut self, cr: &mut <Self as HL>::Cr) -> Pin<P, N, Input<PullDown>> {
670-
self.mode::<Input<PullDown>>(cr);
671-
Pin::new()
666+
pub fn into_pull_down_input(self, cr: &mut <Self as HL>::Cr) -> Pin<P, N, Input<PullDown>> {
667+
self.into_mode(cr)
672668
}
673669

674670
/// Configures the pin to operate as a pulled up input pin
675671
#[inline]
676-
pub fn into_pull_up_input(mut self, cr: &mut <Self as HL>::Cr) -> Pin<P, N, Input<PullUp>> {
677-
self.mode::<Input<PullUp>>(cr);
678-
Pin::new()
672+
pub fn into_pull_up_input(self, cr: &mut <Self as HL>::Cr) -> Pin<P, N, Input<PullUp>> {
673+
self.into_mode(cr)
679674
}
680675

681676
/// Configures the pin to operate as an open-drain output pin.
@@ -694,8 +689,7 @@ where
694689
initial_state: PinState,
695690
) -> Pin<P, N, Output<OpenDrain>> {
696691
self._set_state(initial_state);
697-
self.mode::<Output<OpenDrain>>(cr);
698-
Pin::new()
692+
self.into_mode(cr)
699693
}
700694

701695
/// Configures the pin to operate as an push-pull output pin.
@@ -714,26 +708,23 @@ where
714708
initial_state: PinState,
715709
) -> Pin<P, N, Output<PushPull>> {
716710
self._set_state(initial_state);
717-
self.mode::<Output<PushPull>>(cr);
718-
Pin::new()
711+
self.into_mode(cr)
719712
}
720713

721714
/// Configures the pin to operate as an push-pull output pin.
722715
/// The state will not be changed.
723716
#[inline]
724717
pub fn into_push_pull_output_with_current_state(
725-
mut self,
718+
self,
726719
cr: &mut <Self as HL>::Cr,
727720
) -> Pin<P, N, Output<PushPull>> {
728-
self.mode::<Output<PushPull>>(cr);
729-
Pin::new()
721+
self.into_mode(cr)
730722
}
731723

732724
/// Configures the pin to operate as an analog input pin
733725
#[inline]
734-
pub fn into_analog(mut self, cr: &mut <Self as HL>::Cr) -> Pin<P, N, Analog> {
735-
self.mode::<Analog>(cr);
736-
Pin::new()
726+
pub fn into_analog(self, cr: &mut <Self as HL>::Cr) -> Pin<P, N, Analog> {
727+
self.into_mode(cr)
737728
}
738729

739730
/// Configures the pin as a pin that can change between input
@@ -977,6 +968,12 @@ where
977968
(r_bits & !(0b1111 << Self::OFFSET)) | (bits << Self::OFFSET)
978969
});
979970
}
971+
972+
#[inline]
973+
pub(crate) fn into_mode<MODE: PinMode>(mut self, cr: &mut <Self as HL>::Cr) -> Pin<P, N, MODE> {
974+
self.mode::<MODE>(cr);
975+
Pin::new()
976+
}
980977
}
981978

982979
gpio!(GPIOA, gpioa, PAx, 'A', [

src/qei.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
NOTE: In some cases you need to specify remap you need, especially for TIM2
55
(see [Alternate function remapping](super::timer)):
66
*/
7-
use core::u16;
8-
97
use core::marker::PhantomData;
108

119
#[cfg(any(feature = "stm32f100", feature = "stm32f103", feature = "connectivity",))]

src/rcc/enable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ bus! {
184184
TIM11 => (APB2, 21),
185185
}
186186

187-
#[cfg(any(feature = "stm32f103"))] // feature = "stm32f102"
187+
#[cfg(feature = "stm32f103")] // feature = "stm32f102"
188188
bus! {
189189
USB => (APB1, 23),
190190
}

src/serial.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -759,13 +759,13 @@ macro_rules! serialdma {
759759

760760
atomic::compiler_fence(Ordering::Release);
761761

762-
self.channel.ch().cr.modify(|_, w| { w
763-
.mem2mem() .clear_bit()
764-
.pl() .medium()
765-
.msize() .bits8()
766-
.psize() .bits8()
767-
.circ() .set_bit()
768-
.dir() .clear_bit()
762+
self.channel.ch().cr.modify(|_, w| {
763+
w.mem2mem().clear_bit();
764+
w.pl().medium();
765+
w.msize().bits8();
766+
w.psize().bits8();
767+
w.circ().set_bit();
768+
w.dir().clear_bit()
769769
});
770770

771771
self.start();
@@ -787,13 +787,13 @@ macro_rules! serialdma {
787787
self.channel.set_transfer_length(len);
788788

789789
atomic::compiler_fence(Ordering::Release);
790-
self.channel.ch().cr.modify(|_, w| { w
791-
.mem2mem() .clear_bit()
792-
.pl() .medium()
793-
.msize() .bits8()
794-
.psize() .bits8()
795-
.circ() .clear_bit()
796-
.dir() .clear_bit()
790+
self.channel.ch().cr.modify(|_, w| {
791+
w.mem2mem().clear_bit();
792+
w.pl().medium();
793+
w.msize().bits8();
794+
w.psize().bits8();
795+
w.circ().clear_bit();
796+
w.dir().clear_bit()
797797
});
798798
self.start();
799799

@@ -817,13 +817,13 @@ macro_rules! serialdma {
817817

818818
atomic::compiler_fence(Ordering::Release);
819819

820-
self.channel.ch().cr.modify(|_, w| { w
821-
.mem2mem() .clear_bit()
822-
.pl() .medium()
823-
.msize() .bits8()
824-
.psize() .bits8()
825-
.circ() .clear_bit()
826-
.dir() .set_bit()
820+
self.channel.ch().cr.modify(|_, w| {
821+
w.mem2mem().clear_bit();
822+
w.pl().medium();
823+
w.msize().bits8();
824+
w.psize().bits8();
825+
w.circ().clear_bit();
826+
w.dir().set_bit()
827827
});
828828
self.start();
829829

src/spi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ where
500500
// disable SS output
501501
spi.cr2.write(|w| w.ssoe().clear_bit());
502502

503-
let br = match SPI::clock(&clocks) / freq {
503+
let br = match SPI::clock(clocks) / freq {
504504
0 => unreachable!(),
505505
1..=2 => 0b000,
506506
3..=5 => 0b001,

src/timer/pwm_input.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ impl Timer<TIM4> {
160160
/// Courtesy of @TeXitoi (https://github.com/stm32-rs/stm32f1xx-hal/pull/10#discussion_r259535503)
161161
fn compute_arr_presc(freq: u32, clock: u32) -> (u16, u16) {
162162
if freq == 0 {
163-
return (core::u16::MAX, core::u16::MAX);
163+
return (u16::MAX, u16::MAX);
164164
}
165-
let presc = clock / freq.saturating_mul(core::u16::MAX as u32 + 1);
165+
let presc = clock / freq.saturating_mul(u16::MAX as u32 + 1);
166166
let arr = clock / freq.saturating_mul(presc + 1);
167167
(core::cmp::max(1, arr as u16), presc as u16)
168168
}

0 commit comments

Comments
 (0)