Skip to content

Commit 101deb4

Browse files
authored
Merge pull request #530 from BartMassey-upstream/nrf-hal-common-nits
fixed clippy and rustfmt warnings in nrf-hal-common
2 parents c1a1671 + 3b3a4ef commit 101deb4

File tree

13 files changed

+68
-47
lines changed

13 files changed

+68
-47
lines changed

nrf-hal-common/src/ccm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl Ccm {
241241

242242
// Shortcut, CCM won't encrypt packet with empty payloads, it will just copy the header
243243
if payload_len == 0 {
244-
(&mut cipher_packet[..HEADER_SIZE]).copy_from_slice(&clear_packet[..HEADER_SIZE]);
244+
cipher_packet[..HEADER_SIZE].copy_from_slice(&clear_packet[..HEADER_SIZE]);
245245
return Ok(());
246246
}
247247

@@ -367,7 +367,7 @@ impl Ccm {
367367

368368
// Shortcut, CCM won't decrypt packet with empty payloads, it will just copy the header
369369
if payload_len == 0 {
370-
(&mut clear_packet[..HEADER_SIZE]).copy_from_slice(&cipher_packet[..HEADER_SIZE]);
370+
clear_packet[..HEADER_SIZE].copy_from_slice(&cipher_packet[..HEADER_SIZE]);
371371
return Ok(());
372372
}
373373

nrf-hal-common/src/gpio.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub enum Port {
4141
/// Port 0, available on all nRF52 and nRF51 MCUs.
4242
Port0,
4343
/// Port 0 Secure, available on nRF53
44-
#[cfg(any(feature = "5340-app"))]
44+
#[cfg(feature = "5340-app")]
4545
Port0Secure,
4646
/// Port 1, only available on some nRF52 MCUs and nRF5340.
4747
#[cfg(any(feature = "52833", feature = "52840", feature = "5340-net"))]
@@ -91,7 +91,7 @@ impl<MODE> Pin<MODE> {
9191
fn new(port: Port, pin: u8) -> Self {
9292
let port_bits = match port {
9393
Port::Port0 => 0x00,
94-
#[cfg(any(feature = "5340-app"))]
94+
#[cfg(feature = "5340-app")]
9595
Port::Port0Secure => 0x20,
9696
#[cfg(any(feature = "52833", feature = "52840", feature = "5340-net"))]
9797
Port::Port1 => 0x20,
@@ -102,6 +102,11 @@ impl<MODE> Pin<MODE> {
102102
}
103103
}
104104

105+
/// Construct a GPIO directly from port selection bits.
106+
///
107+
/// # Safety
108+
///
109+
/// Must be called with valid `psel_bits`.
105110
pub unsafe fn from_psel_bits(psel_bits: u32) -> Self {
106111
Self {
107112
pin_port: psel_bits as u8,
@@ -143,7 +148,7 @@ impl<MODE> Pin<MODE> {
143148
}
144149
}
145150

146-
#[cfg(any(feature = "5340-app"))]
151+
#[cfg(feature = "5340-app")]
147152
{
148153
if self.pin_port & 0x20 == 0 {
149154
Port::Port0

nrf-hal-common/src/gpiote.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,16 @@ impl<'a> GpioteChannel<'_> {
121121
/// Configures the channel as an event input with associated pin.
122122
pub fn input_pin<P: GpioteInputPin>(&'a self, pin: &'a P) -> GpioteChannelEvent<'a, P> {
123123
GpioteChannelEvent {
124-
gpiote: &self.gpiote,
125-
pin: pin,
124+
gpiote: self.gpiote,
125+
pin,
126126
channel: self.channel,
127127
}
128128
}
129129
/// Configures the channel as a task output with associated pin.
130130
pub fn output_pin<P: GpioteOutputPin>(&'a self, pin: P) -> GpioteTask<'a, P> {
131131
GpioteTask {
132-
gpiote: &self.gpiote,
133-
pin: pin,
132+
gpiote: self.gpiote,
133+
pin,
134134
channel: self.channel,
135135
task_out_polarity: TaskOutPolarity::Toggle,
136136
}
@@ -220,7 +220,7 @@ pub struct GpioteChannelEvent<'a, P: GpioteInputPin> {
220220
channel: usize,
221221
}
222222

223-
impl<'a, P: GpioteInputPin> GpioteChannelEvent<'_, P> {
223+
impl<P: GpioteInputPin> GpioteChannelEvent<'_, P> {
224224
/// Generates event on falling edge.
225225
pub fn hi_to_lo(&self) -> &Self {
226226
config_channel_event_pin(self.gpiote, self.channel, self.pin, EventPolarity::HiToLo);
@@ -284,7 +284,7 @@ pub struct GpiotePortEvent<'a, P: GpioteInputPin> {
284284
pin: &'a P,
285285
}
286286

287-
impl<'a, P: GpioteInputPin> GpiotePortEvent<'_, P> {
287+
impl<P: GpioteInputPin> GpiotePortEvent<'_, P> {
288288
/// Generates event on pin low.
289289
pub fn low(&self) {
290290
config_port_event_pin(self.pin, PortEventSense::Low);
@@ -325,7 +325,7 @@ pub struct GpioteTask<'a, P: GpioteOutputPin> {
325325
task_out_polarity: TaskOutPolarity,
326326
}
327327

328-
impl<'a, P: GpioteOutputPin> GpioteTask<'_, P> {
328+
impl<P: GpioteOutputPin> GpioteTask<'_, P> {
329329
/// Sets initial task output pin state to high.
330330
pub fn init_high(&self) {
331331
config_channel_task_pin(

nrf-hal-common/src/i2s.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,11 @@ impl I2S {
365365
}
366366

367367
/// Sets the receive buffer RAM start address.
368+
///
369+
/// # Safety
370+
///
371+
/// `addr` must be the address of writeable static memory of
372+
/// sufficient size to hold the specified receive buffer.
368373
#[inline(always)]
369374
pub unsafe fn set_rx_ptr(&self, addr: u32) -> Result<(), Error> {
370375
if (addr as usize) < SRAM_LOWER || (addr as usize) > SRAM_UPPER {
@@ -375,6 +380,11 @@ impl I2S {
375380
}
376381

377382
/// Sets the size (in 32bit words) of the receive and transmit buffers.
383+
///
384+
/// # Safety
385+
///
386+
/// `n_32bit` must be no longer than the DMA buffer pointed to
387+
/// by this struct.
378388
#[inline(always)]
379389
pub unsafe fn set_buffersize(&self, n_32bit: u32) -> Result<(), Error> {
380390
if n_32bit > MAX_DMA_MAXCNT {

nrf-hal-common/src/ieee802154.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ impl<'c> Radio<'c> {
458458
/// ensure the `packet` buffer is allocated in RAM, which is required by the RADIO peripheral
459459
// NOTE we do NOT check the address of `packet` because the mutable reference ensures it's
460460
// allocated in RAM
461+
#[allow(clippy::result_unit_err)]
461462
pub fn try_send(&mut self, packet: &mut Packet) -> Result<(), ()> {
462463
// enable radio to perform cca
463464
self.put_in_rx_mode();
@@ -779,6 +780,12 @@ pub struct Packet {
779780
}
780781

781782
// See figure 124 in nRF52840-PS
783+
impl Default for Packet {
784+
fn default() -> Self {
785+
Self::new()
786+
}
787+
}
788+
782789
impl Packet {
783790
// for indexing purposes
784791
const PHY_HDR: usize = 0;
@@ -812,6 +819,7 @@ impl Packet {
812819
}
813820

814821
/// Returns the size of this packet's payload
822+
#[allow(clippy::len_without_is_empty)]
815823
pub fn len(&self) -> u8 {
816824
self.buffer[Self::PHY_HDR] - Self::CRC
817825
}

nrf-hal-common/src/nvmc.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ use embedded_storage::nor_flash::{
1616
ErrorType, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash,
1717
};
1818

19-
type WORD = u32;
20-
const WORD_SIZE: usize = core::mem::size_of::<WORD>();
19+
const WORD_SIZE: usize = core::mem::size_of::<u32>();
2120
const PAGE_SIZE: usize = 4 * 1024;
2221

2322
/// Interface to an NVMC instance.
@@ -162,7 +161,7 @@ where
162161

163162
fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> {
164163
let offset = offset as usize;
165-
if bytes.len() > self.capacity() || offset as usize > self.capacity() - bytes.len() {
164+
if bytes.len() > self.capacity() || offset > self.capacity() - bytes.len() {
166165
return Err(NvmcError::OutOfBounds);
167166
}
168167
if offset % WORD_SIZE != 0 || bytes.len() % WORD_SIZE != 0 {

nrf-hal-common/src/pwm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ where
541541
/// Loads the given sequence buffers and optionally (re-)starts sequence playback.
542542
/// Returns a `PemSeq`, containing `Pwm<T>` and the buffers.
543543
#[allow(unused_mut)]
544+
#[allow(clippy::type_complexity)]
544545
pub fn load<B0, B1>(
545546
mut self,
546547
seq0_buffer: Option<B0>,

nrf-hal-common/src/saadc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ impl Saadc {
106106

107107
/// Sample channel `PIN` for the configured ADC acquisition time in differential input mode.
108108
/// Note that this is a blocking operation.
109+
#[allow(clippy::result_unit_err)]
109110
pub fn read_channel<PIN: Channel>(&mut self, _pin: &mut PIN) -> Result<i16, ()> {
110111
match PIN::channel() {
111112
0 => self.0.ch[0].pselp.write(|w| w.pselp().analog_input0()),

nrf-hal-common/src/spim.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ where
388388
// the iterators.
389389
let txi = tx_buffer
390390
.chunks(EASY_DMA_SIZE)
391-
.map(|chunk| DmaSlice::from_slice(chunk))
391+
.map(DmaSlice::from_slice)
392392
.chain(repeat_with(DmaSlice::null));
393393
let rxi = rx_buffer
394394
.chunks_mut(EASY_DMA_SIZE)

nrf-hal-common/src/spis.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ where
356356
/// The buffers must be located in RAM.
357357
/// Returns a value that represents the in-progress DMA transfer.
358358
#[allow(unused_mut)]
359+
#[allow(clippy::type_complexity)]
359360
pub fn transfer_split<TxW, RxW, TxB, RxB>(
360361
mut self,
361362
tx_buffer: TxB,

0 commit comments

Comments
 (0)