diff options
| author | Grant Miller <[email protected]> | 2023-08-06 15:00:39 -0500 |
|---|---|---|
| committer | Grant Miller <[email protected]> | 2023-08-06 15:00:39 -0500 |
| commit | d49f40dd5c9480376484bd024aabc3651bde105e (patch) | |
| tree | c14dd6980372687f0ec4cb5210ed5a8da000c48a /embassy-stm32/src | |
| parent | 477a90b8e3a3de107fe4bd7297c00bc569575846 (diff) | |
embassy-stm32: Misc clippy fixes
Diffstat (limited to 'embassy-stm32/src')
| -rw-r--r-- | embassy-stm32/src/can/bxcan.rs | 4 | ||||
| -rw-r--r-- | embassy-stm32/src/dma/ringbuffer.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/flash/common.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/gpio.rs | 27 | ||||
| -rw-r--r-- | embassy-stm32/src/i2c/v1.rs | 15 | ||||
| -rw-r--r-- | embassy-stm32/src/spi/mod.rs | 12 | ||||
| -rw-r--r-- | embassy-stm32/src/timer/complementary_pwm.rs | 5 | ||||
| -rw-r--r-- | embassy-stm32/src/usart/ringbuffered.rs | 9 | ||||
| -rw-r--r-- | embassy-stm32/src/wdg/mod.rs | 12 |
9 files changed, 42 insertions, 46 deletions
diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs index a3e3ec860..fb223e4a9 100644 --- a/embassy-stm32/src/can/bxcan.rs +++ b/embassy-stm32/src/can/bxcan.rs | |||
| @@ -271,7 +271,7 @@ impl<'d, T: Instance> Can<'d, T> { | |||
| 271 | } else { | 271 | } else { |
| 272 | let stid = (rir.stid() & 0x7FF) as u32; | 272 | let stid = (rir.stid() & 0x7FF) as u32; |
| 273 | let exid = rir.exid() & 0x3FFFF; | 273 | let exid = rir.exid() & 0x3FFFF; |
| 274 | let id = (stid << 18) | (exid as u32); | 274 | let id = (stid << 18) | (exid); |
| 275 | Id::from(ExtendedId::new_unchecked(id)) | 275 | Id::from(ExtendedId::new_unchecked(id)) |
| 276 | }; | 276 | }; |
| 277 | let data_len = fifo.rdtr().read().dlc() as usize; | 277 | let data_len = fifo.rdtr().read().dlc() as usize; |
| @@ -383,7 +383,7 @@ impl<'d, T: Instance> Can<'d, T> { | |||
| 383 | let sjw = 1; | 383 | let sjw = 1; |
| 384 | 384 | ||
| 385 | // Pack into BTR register values | 385 | // Pack into BTR register values |
| 386 | Some((sjw - 1) << 24 | (bs1 as u32 - 1) << 16 | (bs2 as u32 - 1) << 20 | (prescaler as u32 - 1)) | 386 | Some((sjw - 1) << 24 | (bs1 as u32 - 1) << 16 | (bs2 as u32 - 1) << 20 | (prescaler - 1)) |
| 387 | } | 387 | } |
| 388 | 388 | ||
| 389 | pub fn split<'c>(&'c self) -> (CanTx<'c, 'd, T>, CanRx<'c, 'd, T>) { | 389 | pub fn split<'c>(&'c self) -> (CanTx<'c, 'd, T>, CanRx<'c, 'd, T>) { |
diff --git a/embassy-stm32/src/dma/ringbuffer.rs b/embassy-stm32/src/dma/ringbuffer.rs index 945c7508c..6ce59e455 100644 --- a/embassy-stm32/src/dma/ringbuffer.rs +++ b/embassy-stm32/src/dma/ringbuffer.rs | |||
| @@ -356,7 +356,7 @@ mod tests { | |||
| 356 | pub fn new(len: usize) -> Self { | 356 | pub fn new(len: usize) -> Self { |
| 357 | Self { | 357 | Self { |
| 358 | requests: cell::RefCell::new(vec![]), | 358 | requests: cell::RefCell::new(vec![]), |
| 359 | len: len, | 359 | len, |
| 360 | } | 360 | } |
| 361 | } | 361 | } |
| 362 | 362 | ||
diff --git a/embassy-stm32/src/flash/common.rs b/embassy-stm32/src/flash/common.rs index 16c511295..8acad1c7c 100644 --- a/embassy-stm32/src/flash/common.rs +++ b/embassy-stm32/src/flash/common.rs | |||
| @@ -147,7 +147,7 @@ pub(super) unsafe fn erase_sector_unlocked(sector: &FlashSector) -> Result<(), E | |||
| 147 | 147 | ||
| 148 | let _on_drop = OnDrop::new(|| family::lock()); | 148 | let _on_drop = OnDrop::new(|| family::lock()); |
| 149 | 149 | ||
| 150 | family::blocking_erase_sector(§or) | 150 | family::blocking_erase_sector(sector) |
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | pub(super) unsafe fn erase_sector_with_critical_section(sector: &FlashSector) -> Result<(), Error> { | 153 | pub(super) unsafe fn erase_sector_with_critical_section(sector: &FlashSector) -> Result<(), Error> { |
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index 0cc269cfd..268ba042b 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs | |||
| @@ -777,12 +777,14 @@ mod eh02 { | |||
| 777 | 777 | ||
| 778 | #[inline] | 778 | #[inline] |
| 779 | fn set_high(&mut self) -> Result<(), Self::Error> { | 779 | fn set_high(&mut self) -> Result<(), Self::Error> { |
| 780 | Ok(self.set_high()) | 780 | self.set_high(); |
| 781 | Ok(()) | ||
| 781 | } | 782 | } |
| 782 | 783 | ||
| 783 | #[inline] | 784 | #[inline] |
| 784 | fn set_low(&mut self) -> Result<(), Self::Error> { | 785 | fn set_low(&mut self) -> Result<(), Self::Error> { |
| 785 | Ok(self.set_low()) | 786 | self.set_low(); |
| 787 | Ok(()) | ||
| 786 | } | 788 | } |
| 787 | } | 789 | } |
| 788 | 790 | ||
| @@ -803,7 +805,8 @@ mod eh02 { | |||
| 803 | type Error = Infallible; | 805 | type Error = Infallible; |
| 804 | #[inline] | 806 | #[inline] |
| 805 | fn toggle(&mut self) -> Result<(), Self::Error> { | 807 | fn toggle(&mut self) -> Result<(), Self::Error> { |
| 806 | Ok(self.toggle()) | 808 | self.toggle(); |
| 809 | Ok(()) | ||
| 807 | } | 810 | } |
| 808 | } | 811 | } |
| 809 | 812 | ||
| @@ -812,12 +815,14 @@ mod eh02 { | |||
| 812 | 815 | ||
| 813 | #[inline] | 816 | #[inline] |
| 814 | fn set_high(&mut self) -> Result<(), Self::Error> { | 817 | fn set_high(&mut self) -> Result<(), Self::Error> { |
| 815 | Ok(self.set_high()) | 818 | self.set_high(); |
| 819 | Ok(()) | ||
| 816 | } | 820 | } |
| 817 | 821 | ||
| 818 | #[inline] | 822 | #[inline] |
| 819 | fn set_low(&mut self) -> Result<(), Self::Error> { | 823 | fn set_low(&mut self) -> Result<(), Self::Error> { |
| 820 | Ok(self.set_low()) | 824 | self.set_low(); |
| 825 | Ok(()) | ||
| 821 | } | 826 | } |
| 822 | } | 827 | } |
| 823 | 828 | ||
| @@ -838,7 +843,8 @@ mod eh02 { | |||
| 838 | type Error = Infallible; | 843 | type Error = Infallible; |
| 839 | #[inline] | 844 | #[inline] |
| 840 | fn toggle(&mut self) -> Result<(), Self::Error> { | 845 | fn toggle(&mut self) -> Result<(), Self::Error> { |
| 841 | Ok(self.toggle()) | 846 | self.toggle(); |
| 847 | Ok(()) | ||
| 842 | } | 848 | } |
| 843 | } | 849 | } |
| 844 | 850 | ||
| @@ -861,12 +867,14 @@ mod eh02 { | |||
| 861 | 867 | ||
| 862 | #[inline] | 868 | #[inline] |
| 863 | fn set_high(&mut self) -> Result<(), Self::Error> { | 869 | fn set_high(&mut self) -> Result<(), Self::Error> { |
| 864 | Ok(self.set_high()) | 870 | self.set_high(); |
| 871 | Ok(()) | ||
| 865 | } | 872 | } |
| 866 | 873 | ||
| 867 | #[inline] | 874 | #[inline] |
| 868 | fn set_low(&mut self) -> Result<(), Self::Error> { | 875 | fn set_low(&mut self) -> Result<(), Self::Error> { |
| 869 | Ok(self.set_low()) | 876 | self.set_low(); |
| 877 | Ok(()) | ||
| 870 | } | 878 | } |
| 871 | } | 879 | } |
| 872 | 880 | ||
| @@ -887,7 +895,8 @@ mod eh02 { | |||
| 887 | type Error = Infallible; | 895 | type Error = Infallible; |
| 888 | #[inline] | 896 | #[inline] |
| 889 | fn toggle(&mut self) -> Result<(), Self::Error> { | 897 | fn toggle(&mut self) -> Result<(), Self::Error> { |
| 890 | Ok(self.toggle()) | 898 | self.toggle(); |
| 899 | Ok(()) | ||
| 891 | } | 900 | } |
| 892 | } | 901 | } |
| 893 | } | 902 | } |
diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs index e5254a8cd..618d85af2 100644 --- a/embassy-stm32/src/i2c/v1.rs +++ b/embassy-stm32/src/i2c/v1.rs | |||
| @@ -21,21 +21,12 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl | |||
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | #[non_exhaustive] | 23 | #[non_exhaustive] |
| 24 | #[derive(Copy, Clone)] | 24 | #[derive(Copy, Clone, Default)] |
| 25 | pub struct Config { | 25 | pub struct Config { |
| 26 | pub sda_pullup: bool, | 26 | pub sda_pullup: bool, |
| 27 | pub scl_pullup: bool, | 27 | pub scl_pullup: bool, |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | impl Default for Config { | ||
| 31 | fn default() -> Self { | ||
| 32 | Self { | ||
| 33 | sda_pullup: false, | ||
| 34 | scl_pullup: false, | ||
| 35 | } | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | pub struct State {} | 30 | pub struct State {} |
| 40 | 31 | ||
| 41 | impl State { | 32 | impl State { |
| @@ -90,7 +81,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 90 | //reg.set_anfoff(false); | 81 | //reg.set_anfoff(false); |
| 91 | }); | 82 | }); |
| 92 | 83 | ||
| 93 | let timings = Timings::new(T::frequency(), freq.into()); | 84 | let timings = Timings::new(T::frequency(), freq); |
| 94 | 85 | ||
| 95 | T::regs().cr2().modify(|reg| { | 86 | T::regs().cr2().modify(|reg| { |
| 96 | reg.set_freq(timings.freq); | 87 | reg.set_freq(timings.freq); |
| @@ -461,7 +452,7 @@ impl Timings { | |||
| 461 | let speed = speed.0; | 452 | let speed = speed.0; |
| 462 | let clock = i2cclk.0; | 453 | let clock = i2cclk.0; |
| 463 | let freq = clock / 1_000_000; | 454 | let freq = clock / 1_000_000; |
| 464 | assert!(freq >= 2 && freq <= 50); | 455 | assert!((2..=50).contains(&freq)); |
| 465 | 456 | ||
| 466 | // Configure bus frequency into I2C peripheral | 457 | // Configure bus frequency into I2C peripheral |
| 467 | let trise = if speed <= 100_000 { | 458 | let trise = if speed <= 100_000 { |
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index bbc7c3b91..e2bc8d7f2 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs | |||
| @@ -223,7 +223,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 223 | 223 | ||
| 224 | let pclk = T::frequency(); | 224 | let pclk = T::frequency(); |
| 225 | let freq = config.frequency; | 225 | let freq = config.frequency; |
| 226 | let br = compute_baud_rate(pclk, freq.into()); | 226 | let br = compute_baud_rate(pclk, freq); |
| 227 | 227 | ||
| 228 | let cpha = config.raw_phase(); | 228 | let cpha = config.raw_phase(); |
| 229 | let cpol = config.raw_polarity(); | 229 | let cpol = config.raw_polarity(); |
| @@ -331,7 +331,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 331 | 331 | ||
| 332 | let pclk = T::frequency(); | 332 | let pclk = T::frequency(); |
| 333 | let freq = config.frequency; | 333 | let freq = config.frequency; |
| 334 | let br = compute_baud_rate(pclk, freq.into()); | 334 | let br = compute_baud_rate(pclk, freq); |
| 335 | 335 | ||
| 336 | #[cfg(any(spi_v1, spi_f1, spi_v2))] | 336 | #[cfg(any(spi_v1, spi_f1, spi_v2))] |
| 337 | T::REGS.cr1().modify(|w| { | 337 | T::REGS.cr1().modify(|w| { |
| @@ -447,7 +447,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 447 | where | 447 | where |
| 448 | Tx: TxDma<T>, | 448 | Tx: TxDma<T>, |
| 449 | { | 449 | { |
| 450 | if data.len() == 0 { | 450 | if data.is_empty() { |
| 451 | return Ok(()); | 451 | return Ok(()); |
| 452 | } | 452 | } |
| 453 | 453 | ||
| @@ -481,7 +481,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 481 | Tx: TxDma<T>, | 481 | Tx: TxDma<T>, |
| 482 | Rx: RxDma<T>, | 482 | Rx: RxDma<T>, |
| 483 | { | 483 | { |
| 484 | if data.len() == 0 { | 484 | if data.is_empty() { |
| 485 | return Ok(()); | 485 | return Ok(()); |
| 486 | } | 486 | } |
| 487 | 487 | ||
| @@ -843,7 +843,7 @@ fn transfer_word<W: Word>(regs: Regs, tx_word: W) -> Result<W, Error> { | |||
| 843 | spin_until_rx_ready(regs)?; | 843 | spin_until_rx_ready(regs)?; |
| 844 | 844 | ||
| 845 | let rx_word = unsafe { ptr::read_volatile(regs.rx_ptr()) }; | 845 | let rx_word = unsafe { ptr::read_volatile(regs.rx_ptr()) }; |
| 846 | return Ok(rx_word); | 846 | Ok(rx_word) |
| 847 | } | 847 | } |
| 848 | 848 | ||
| 849 | mod eh02 { | 849 | mod eh02 { |
| @@ -978,7 +978,7 @@ mod word_impl { | |||
| 978 | impl_word!(u16, vals::Dff::SIXTEENBIT); | 978 | impl_word!(u16, vals::Dff::SIXTEENBIT); |
| 979 | } | 979 | } |
| 980 | 980 | ||
| 981 | #[cfg(any(spi_v2))] | 981 | #[cfg(spi_v2)] |
| 982 | mod word_impl { | 982 | mod word_impl { |
| 983 | use super::*; | 983 | use super::*; |
| 984 | 984 | ||
diff --git a/embassy-stm32/src/timer/complementary_pwm.rs b/embassy-stm32/src/timer/complementary_pwm.rs index 48cb610f1..acd67048d 100644 --- a/embassy-stm32/src/timer/complementary_pwm.rs +++ b/embassy-stm32/src/timer/complementary_pwm.rs | |||
| @@ -186,9 +186,8 @@ fn compute_dead_time_value(value: u16) -> (Ckd, u8) { | |||
| 186 | error = this_error; | 186 | error = this_error; |
| 187 | } | 187 | } |
| 188 | 188 | ||
| 189 | match error { | 189 | if error == 0 { |
| 190 | 0 => break, | 190 | break; |
| 191 | _ => {} | ||
| 192 | } | 191 | } |
| 193 | } | 192 | } |
| 194 | 193 | ||
diff --git a/embassy-stm32/src/usart/ringbuffered.rs b/embassy-stm32/src/usart/ringbuffered.rs index 71077c070..b0e626df6 100644 --- a/embassy-stm32/src/usart/ringbuffered.rs +++ b/embassy-stm32/src/usart/ringbuffered.rs | |||
| @@ -19,7 +19,7 @@ impl<'d, T: BasicInstance, RxDma: super::RxDma<T>> UartRx<'d, T, RxDma> { | |||
| 19 | /// without the possibility of loosing bytes. The `dma_buf` is a buffer registered to the | 19 | /// without the possibility of loosing bytes. The `dma_buf` is a buffer registered to the |
| 20 | /// DMA controller, and must be sufficiently large, such that it will not overflow. | 20 | /// DMA controller, and must be sufficiently large, such that it will not overflow. |
| 21 | pub fn into_ring_buffered(self, dma_buf: &'d mut [u8]) -> RingBufferedUartRx<'d, T, RxDma> { | 21 | pub fn into_ring_buffered(self, dma_buf: &'d mut [u8]) -> RingBufferedUartRx<'d, T, RxDma> { |
| 22 | assert!(dma_buf.len() > 0 && dma_buf.len() <= 0xFFFF); | 22 | assert!(!dma_buf.is_empty() && dma_buf.len() <= 0xFFFF); |
| 23 | 23 | ||
| 24 | let request = self.rx_dma.request(); | 24 | let request = self.rx_dma.request(); |
| 25 | let opts = Default::default(); | 25 | let opts = Default::default(); |
| @@ -111,10 +111,9 @@ impl<'d, T: BasicInstance, RxDma: super::RxDma<T>> RingBufferedUartRx<'d, T, RxD | |||
| 111 | let r = T::regs(); | 111 | let r = T::regs(); |
| 112 | 112 | ||
| 113 | // Start background receive if it was not already started | 113 | // Start background receive if it was not already started |
| 114 | match r.cr3().read().dmar() { | 114 | if !r.cr3().read().dmar() { |
| 115 | false => self.start()?, | 115 | self.start()?; |
| 116 | _ => {} | 116 | } |
| 117 | }; | ||
| 118 | 117 | ||
| 119 | check_for_errors(clear_idle_flag(T::regs()))?; | 118 | check_for_errors(clear_idle_flag(T::regs()))?; |
| 120 | 119 | ||
diff --git a/embassy-stm32/src/wdg/mod.rs b/embassy-stm32/src/wdg/mod.rs index eafd03364..c7c2694e0 100644 --- a/embassy-stm32/src/wdg/mod.rs +++ b/embassy-stm32/src/wdg/mod.rs | |||
| @@ -60,9 +60,7 @@ impl<'d, T: Instance> IndependentWatchdog<'d, T> { | |||
| 60 | rl | 60 | rl |
| 61 | ); | 61 | ); |
| 62 | 62 | ||
| 63 | IndependentWatchdog { | 63 | IndependentWatchdog { wdg: PhantomData } |
| 64 | wdg: PhantomData::default(), | ||
| 65 | } | ||
| 66 | } | 64 | } |
| 67 | 65 | ||
| 68 | pub fn unleash(&mut self) { | 66 | pub fn unleash(&mut self) { |
| @@ -104,16 +102,16 @@ mod tests { | |||
| 104 | assert_eq!(512_000, get_timeout_us(4, MAX_RL)); | 102 | assert_eq!(512_000, get_timeout_us(4, MAX_RL)); |
| 105 | 103 | ||
| 106 | assert_eq!(8_000, get_timeout_us(256, 0)); | 104 | assert_eq!(8_000, get_timeout_us(256, 0)); |
| 107 | assert_eq!(32768_000, get_timeout_us(256, MAX_RL)); | 105 | assert_eq!(32_768_000, get_timeout_us(256, MAX_RL)); |
| 108 | 106 | ||
| 109 | assert_eq!(8000_000, get_timeout_us(64, 3999)); | 107 | assert_eq!(8_000_000, get_timeout_us(64, 3999)); |
| 110 | } | 108 | } |
| 111 | 109 | ||
| 112 | #[test] | 110 | #[test] |
| 113 | fn can_compute_reload_value() { | 111 | fn can_compute_reload_value() { |
| 114 | assert_eq!(0xFFF, reload_value(4, 512_000)); | 112 | assert_eq!(0xFFF, reload_value(4, 512_000)); |
| 115 | assert_eq!(0xFFF, reload_value(256, 32768_000)); | 113 | assert_eq!(0xFFF, reload_value(256, 32_768_000)); |
| 116 | 114 | ||
| 117 | assert_eq!(3999, reload_value(64, 8000_000)); | 115 | assert_eq!(3999, reload_value(64, 8_000_000)); |
| 118 | } | 116 | } |
| 119 | } | 117 | } |
