Skip to content

Commit 1609ad0

Browse files
More warning fixes
1 parent d7ce73a commit 1609ad0

19 files changed

+92
-48
lines changed

src/drivers/aes.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl<'a, Size: KeySize> Aes<'a, Size> {
162162

163163
fn one_block(&self, block: &mut Block<Self>) {
164164
// needs to be word-aligned
165-
let aligned_block: Aligned<A4, Block<Self>> = Aligned(block.clone());
165+
let aligned_block: Aligned<A4, Block<Self>> = Aligned(*block);
166166
let addr: u32 = &aligned_block as *const _ as _;
167167

168168
self.memaddr.write(|w| unsafe { w.bits(addr) });
@@ -182,12 +182,12 @@ impl<'a, Size: KeySize> Aes<'a, Size> {
182182

183183
// the `block-cipher` traits
184184

185-
impl<'a, Size: KeySize> BlockCipher for Aes<'a, Size> {
185+
impl<Size: KeySize> BlockCipher for Aes<'_, Size> {
186186
type BlockSize = U16;
187187
type ParBlocks = U1;
188188
}
189189

190-
impl<'a, Size: KeySize> BlockEncrypt for Aes<'a, Size> {
190+
impl<Size: KeySize> BlockEncrypt for Aes<'_, Size> {
191191
fn encrypt_block(&self, block: &mut Block<Self>) {
192192
// unfortunate implementation detail
193193
if self.cryptcfg.read().aesdecrypt().is_decrypt() {
@@ -197,7 +197,7 @@ impl<'a, Size: KeySize> BlockEncrypt for Aes<'a, Size> {
197197
}
198198
}
199199

200-
impl<'a, Size: KeySize> BlockDecrypt for Aes<'a, Size> {
200+
impl<Size: KeySize> BlockDecrypt for Aes<'_, Size> {
201201
fn decrypt_block(&self, block: &mut Block<Self>) {
202202
// unfortunate implementation detail
203203
if self.cryptcfg.read().aesdecrypt().is_encrypt() {
@@ -210,12 +210,12 @@ impl<'a, Size: KeySize> BlockDecrypt for Aes<'a, Size> {
210210
impl<Size: KeySize> core::ops::Deref for Aes<'_, Size> {
211211
type Target = Hashcrypt<Enabled>;
212212
fn deref(&self) -> &Self::Target {
213-
&self.inner
213+
self.inner
214214
}
215215
}
216216

217217
impl<Size: KeySize> core::ops::DerefMut for Aes<'_, Size> {
218218
fn deref_mut(&mut self) -> &mut Self::Target {
219-
&mut self.inner
219+
self.inner
220220
}
221221
}

src/drivers/clocks.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
///!* API to configure the clocks.
2-
///!
3-
///! This is very incomplete (e.g., no support for PLL clocks).
4-
///! It is also likely buggy, and more complex than needed
5-
///!
6-
///! It is currently used to prepare for using the USBFSD and
7-
///! Flexcomm peripherals.
1+
//!* API to configure the clocks.
2+
//!
3+
//! This is very incomplete (e.g., no support for PLL clocks).
4+
//! It is also likely buggy, and more complex than needed
5+
//!
6+
//! It is currently used to prepare for using the USBFSD and
7+
//! Flexcomm peripherals.
88
use core::{cmp::min, convert::TryFrom};
99
use embedded_time::rate::Extensions;
1010

@@ -114,6 +114,9 @@ pub struct Pll {
114114

115115
impl Pll {
116116
// allow user to override if they know better...
117+
/// # Safety
118+
///
119+
/// Input values must be valid for PLL
117120
pub unsafe fn new(n: u8, m: u16, p: u8) -> Pll {
118121
// UM 4.6.6.3.2
119122
let selp = min((m >> 2) + 1, 31) as u8;
@@ -441,6 +444,9 @@ impl ClockRequirements {
441444
}
442445

443446
/// Same as above, but allows clock to be changed after an initial configuration.
447+
///
448+
/// # Safety
449+
///
444450
/// This is unsafe because it's up to the developer to ensure the new configuration is okay for
445451
/// the device peripherals being used.
446452
pub unsafe fn reconfigure(self, _clocks: Clocks, pmc: &mut Pmc, syscon: &mut Syscon) -> Clocks {

src/drivers/i2c.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub mod prelude {
1919

2020
/// I2C error
2121
#[derive(Debug)]
22+
#[non_exhaustive]
2223
pub enum Error {
2324
/// Bus error (catch-all)
2425
Bus,
@@ -30,9 +31,6 @@ pub enum Error {
3031
NackData,
3132
/// Start/Stop error
3233
StartStop,
33-
34-
#[doc(hidden)]
35-
_Extensible,
3634
}
3735

3836
pub type Result<T> = core::result::Result<T, Error>;

src/drivers/pins.rs

+6
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ macro_rules! pins {
118118
Self::set_all_released();
119119
}
120120

121+
/// # Safety
122+
///
123+
/// Steals the PIN, must not be called if the PIN is already owned
121124
pub unsafe fn steal() -> Self {
122125
Self {
123126
$(
@@ -185,6 +188,9 @@ macro_rules! pins {
185188
unsafe { PIN_TAKEN[$port][$number] = false; }
186189
}
187190

191+
/// # Safety
192+
///
193+
/// Steals the PIN, must not be called if the PIN is already owned
188194
pub unsafe fn steal() -> Pin<Self, $default_state_ty> {
189195
PIN_TAKEN[$port][$number] = true;
190196
Pin {

src/drivers/pwm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ where
8080

8181
fn enable(&mut self, channel: Self::Channel) {
8282
match channel {
83-
0 | 1 | 2 => {}
83+
0..=2 => {}
8484
_ => {
8585
panic!("Cannot use channel outside 0-2 for PWM.");
8686
}

src/drivers/rng.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ impl rand_core::RngCore for Rng<init_state::Enabled> {
4141
}
4242

4343
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> {
44-
Ok(self.fill_bytes(dest))
44+
self.fill_bytes(dest);
45+
Ok(())
4546
}
4647
}
4748

src/drivers/serial.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub mod config;
1919

2020
/// Serial error
2121
#[derive(Debug)]
22+
#[non_exhaustive]
2223
pub enum Error {
2324
/// Framing error
2425
Framing,
@@ -28,8 +29,6 @@ pub enum Error {
2829
Overrun,
2930
/// Parity check error
3031
Parity,
31-
#[doc(hidden)]
32-
_Extensible,
3332
}
3433

3534
// /// Interrupt event
@@ -101,7 +100,7 @@ where
101100
pub fn new(usart: USART, pins: PINS, config: config::Config) -> Self {
102101
use self::config::*;
103102

104-
let speed: Hertz = config.speed.into();
103+
let speed: Hertz = config.speed;
105104
let speed: u32 = speed.0;
106105

107106
usart

src/drivers/sha.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl<Size: OutputSize> Sha<'_, Size> {
127127
// relevant code is ~line 800 in fsl_hashcrypt.c
128128
fn process_block(peripheral: &mut Hashcrypt<Enabled>, input: &GenericArray<u8, BlockSize>) {
129129
// input must be word-aligned
130-
let input: Aligned<A4, GenericArray<u8, BlockSize>> = Aligned(input.clone());
130+
let input: Aligned<A4, GenericArray<u8, BlockSize>> = Aligned(*input);
131131
let addr: u32 = &input[0] as *const _ as _;
132132
assert_eq!(addr & 0x3, 0);
133133
while peripheral.raw.status.read().waiting().is_not_waiting() {

src/drivers/spi.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
///! There are 8 "normal" SPIs and on high-speed SPI.
2-
///! The high-speed SPI is tied to Flexcomm8, which it does not
3-
///! share with any other peripherals.
4-
///!
5-
///! SPI3, SPI4, and this high-speed SPI8 have 4 possible chip selects,
6-
///! whereas the others have two.
7-
///
8-
///
1+
//! There are 8 "normal" SPIs and on high-speed SPI.
2+
//! The high-speed SPI is tied to Flexcomm8, which it does not
3+
//! share with any other peripherals.
4+
//!
5+
//! SPI3, SPI4, and this high-speed SPI8 have 4 possible chip selects,
6+
//! whereas the others have two.
7+
98
use core::marker::PhantomData;
109

1110
use crate::time::Hertz;
@@ -29,15 +28,14 @@ pub mod prelude {
2928
/// SPI error
3029
/// TODO: Use the actual ones from the chip
3130
#[derive(Debug)]
31+
#[non_exhaustive]
3232
pub enum Error {
3333
/// Overrun occurred
3434
Overrun,
3535
/// Mode fault occurred
3636
ModeFault,
3737
/// CRC error
3838
Crc,
39-
#[doc(hidden)]
40-
_Extensible,
4139
}
4240

4341
pub type Result<T> = nb::Result<T, Error>;

src/drivers/touch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ where
287287

288288
/// For debugging
289289
pub(crate) fn get_results<'a>(&self) -> &'a mut [u32] {
290-
return unsafe { &mut RESULTS };
290+
unsafe { &mut RESULTS }
291291
}
292292

293293
/// Used after an edge is detected to prevent the same

src/drivers/usbd.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ where
8383
*endpoint = mem::MaybeUninit::new(Endpoint::<USB>::new(i as u8));
8484
}
8585

86-
unsafe { mem::transmute::<_, [Endpoint<USB>; NUM_ENDPOINTS]>(endpoints) }
86+
unsafe {
87+
mem::transmute::<
88+
[mem::MaybeUninit<Endpoint<USB>>; NUM_ENDPOINTS],
89+
[Endpoint<USB>; NUM_ENDPOINTS],
90+
>(endpoints)
91+
}
8792
},
8893
};
8994

src/drivers/usbd/endpoint.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ where
289289
let nbytes = epl.eps[i].ep_out[0].read().nbytes::<USB>().bits() as usize;
290290

291291
// let count = min((out_buf.capacity() - nbytes) as usize, buf.len());
292-
let count = (out_buf.capacity() - nbytes) as usize;
292+
let count = out_buf.capacity() - nbytes;
293293

294294
out_buf.read(&mut buf[..count]);
295295

@@ -347,7 +347,7 @@ where
347347
} else {
348348
let out_buf = self.out_buf.as_ref().unwrap().borrow(cs);
349349
let nbytes = epl.eps[0].ep_out[0].read().nbytes::<USB>().bits() as usize;
350-
let count = min((out_buf.capacity() - nbytes) as usize, buf.len());
350+
let count = min(out_buf.capacity() - nbytes, buf.len());
351351

352352
out_buf.read(&mut buf[..count]);
353353

src/drivers/usbd/endpoint_registers.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ pub fn attach() -> Option<Instance> {
7979
}
8080

8181
/// Does not zero the memory
82+
///
83+
/// # Safety
84+
///
85+
/// Steals the registers instance, must not be called if
86+
/// the registers are owned somewhere
8287
pub unsafe fn steal() -> Instance {
8388
ENDPOINT_REGISTERS_ATTACHED = true;
8489
Instance {
@@ -595,15 +600,15 @@ pub mod epr {
595600
pub fn addroff<USB: Usb<init_state::Enabled>>(&self) -> ADDROFFR {
596601
let field = AddrOffField::from(USB::SPEED);
597602
ADDROFFR {
598-
bits: ((self.bits >> field.offset) & field.mask as u32) as u16,
603+
bits: ((self.bits >> field.offset) & field.mask) as u16,
599604
}
600605
}
601606
#[doc = "Bits 16:25 - Endpoint buffer NBytes while in full speed operation, or bits 11:25 for high speed operation."]
602607
#[inline]
603608
pub fn nbytes<USB: Usb<init_state::Enabled>>(&self) -> NBYTESR {
604609
let field = NbytesField::from(USB::SPEED);
605610
NBYTESR {
606-
bits: ((self.bits >> field.offset) & field.mask as u32) as u16,
611+
bits: ((self.bits >> field.offset) & field.mask) as u16,
607612
}
608613
}
609614
#[doc = "Bit 26 - Endpoint type"]
@@ -671,6 +676,8 @@ pub mod epr {
671676
W { bits: 1 << 30 }
672677
}
673678
#[doc = r"Writes raw bits to the register"]
679+
#[doc = r"# Safety"]
680+
#[doc = r"Bit value must be valid"]
674681
#[inline]
675682
pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
676683
self.bits = bits;

src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,10 @@ impl Peripherals {
449449
// }
450450

451451
#[cfg(not(feature = "rtic-peripherals"))]
452+
/// # Safety
453+
///
454+
/// Steals peripherals, must not be used if one of the peripherals
455+
/// is already owned
452456
pub unsafe fn steal() -> Self {
453457
Self::from((raw::Peripherals::steal(), raw::CorePeripherals::steal()))
454458
}

src/peripherals/pfr.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,10 @@ pub struct Pfr<State = init_state::Unknown> {
242242
}
243243
impl<State> Pfr<State> {
244244
fn bootloader_api_tree() -> &'static mut BootloaderTree {
245-
unsafe { core::mem::transmute(0x130010f0u32 as *const ()) }
245+
#[allow(clippy::transmute_ptr_to_ref)]
246+
unsafe {
247+
core::mem::transmute(0x130010f0u32 as *const ())
248+
}
246249
}
247250
fn check_error(err: u32) -> Result<(), u32> {
248251
if err == 0 {
@@ -252,6 +255,12 @@ impl<State> Pfr<State> {
252255
}
253256
}
254257
}
258+
259+
impl Default for Pfr {
260+
fn default() -> Self {
261+
Self::new()
262+
}
263+
}
255264
impl Pfr {
256265
pub fn new() -> Self {
257266
Self {
@@ -290,7 +299,7 @@ impl Pfr<init_state::Enabled> {
290299
// heprintln!("cfpa:").ok();
291300
// dump_hex!(cfpa_bytes, 512);
292301

293-
let cmpa: &Cmpa = unsafe { core::mem::transmute(cmpa_bytes.as_ptr()) };
302+
let cmpa: &Cmpa = unsafe { &*(cmpa_bytes.as_ptr() as *const _) };
294303

295304
Ok(*cmpa)
296305
}
@@ -308,6 +317,7 @@ impl Pfr<init_state::Enabled> {
308317
/// - Immediately after CFPA is updated, this method returns the latest CFPA data.
309318
/// - After boot/reset, this method will potentially return expected old versions of CFPA.
310319
/// - There is a pattern of how to increment VERSION to result in this method returning old CFPA versions or not which is impractical.
320+
///
311321
/// It's almost like there is some other cfpa page storage not documented and this bootrom method mismanages the VERSION.
312322
pub fn read_cfpa_with_bootrom(&mut self) -> Result<Cfpa, u32> {
313323
let mut cfpa_bytes = [0u8; 512];
@@ -322,7 +332,7 @@ impl Pfr<init_state::Enabled> {
322332
// heprintln!("cfpa:").ok();
323333
// dump_hex!(cfpa_bytes, 512);
324334

325-
let cfpa: &Cfpa = unsafe { core::mem::transmute(cfpa_bytes.as_ptr()) };
335+
let cfpa: &Cfpa = unsafe { &*(cfpa_bytes.as_ptr() as *const _) };
326336

327337
Ok(*cfpa)
328338
}
@@ -350,7 +360,7 @@ impl Pfr<init_state::Enabled> {
350360
copy_nonoverlapping(cfpa_ptr, cfpa_bytes.as_mut_ptr(), 128);
351361
}
352362

353-
let cfpa: &Cfpa = unsafe { core::mem::transmute(cfpa_bytes.as_ptr()) };
363+
let cfpa: &Cfpa = unsafe { &*(cfpa_bytes.as_ptr() as *const _) };
354364

355365
Ok(*cfpa)
356366
}
@@ -363,7 +373,7 @@ impl Pfr<init_state::Enabled> {
363373
copy_nonoverlapping(CFPA_PTR, cfpa_bytes.as_mut_ptr(), 128);
364374
}
365375

366-
let cfpa: &Cfpa = unsafe { core::mem::transmute(cfpa_bytes.as_ptr()) };
376+
let cfpa: &Cfpa = unsafe { &*(cfpa_bytes.as_ptr() as *const _) };
367377

368378
Ok(*cfpa)
369379
}
@@ -376,7 +386,7 @@ impl Pfr<init_state::Enabled> {
376386
copy_nonoverlapping(CFPA_PTR, cfpa_bytes.as_mut_ptr(), 128);
377387
}
378388

379-
let cfpa: &Cfpa = unsafe { core::mem::transmute(cfpa_bytes.as_ptr()) };
389+
let cfpa: &Cfpa = unsafe { &*(cfpa_bytes.as_ptr() as *const _) };
380390

381391
Ok(*cfpa)
382392
}

src/peripherals/pmc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl Pmc {
4949

5050
/// Check if peripheral is powered
5151
pub fn is_powered<P: PowerControl>(&self, peripheral: &P) -> bool {
52-
peripheral.is_powered(&self)
52+
peripheral.is_powered(self)
5353
}
5454
}
5555

0 commit comments

Comments
 (0)