Skip to content

Commit d932203

Browse files
committed
fix: resolve clippy warnings for nightly-2025-07-20
- Elide explicit lifetimes where possible ('a -> '_) - Add #[must_use] attributes to pure functions - Add backticks in doc comments for doc_markdown lint - Use u32::from() instead of 'as u32' for lossless casts - Use is_multiple_of() instead of modulo comparison - Add numeric underscores for readability (115200 -> 115_200) - Remove unused variables in main.rs - Allow cast_possible_truncation for UART RBR read - Allow static_mut_refs in test fixtures - Remove needless continue statements
1 parent 0f0e0b5 commit d932203

33 files changed

+139
-81
lines changed

src/astdebug.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use embedded_io::Write;
66
pub fn print_array_u32(uart: &mut UartController<'_>, data: &[u32]) {
77
let bytes_per_line = 0x4;
88
for (i, dw) in data.iter().enumerate() {
9-
if i % bytes_per_line == 0 {
9+
if i.is_multiple_of(bytes_per_line) {
1010
writeln!(uart, "\r").unwrap();
1111
} else {
1212
write!(uart, " ").unwrap();
@@ -19,7 +19,7 @@ pub fn print_array_u32(uart: &mut UartController<'_>, data: &[u32]) {
1919
pub fn print_array_u8(uart: &mut UartController<'_>, data: &[u8]) {
2020
let bytes_per_line = 0x8;
2121
for (i, b) in data.iter().enumerate() {
22-
if i % bytes_per_line == 0 {
22+
if i.is_multiple_of(bytes_per_line) {
2323
writeln!(uart, "\r").unwrap();
2424
} else {
2525
write!(uart, " ").unwrap();
@@ -34,7 +34,7 @@ pub fn print_reg_u8(uart: &mut UartController<'_>, reg_base: usize, size: usize)
3434
let scu_bytes: &[u8] = unsafe { core::slice::from_raw_parts(reg_base as *const u8, size) };
3535

3636
for (i, b) in scu_bytes.iter().enumerate() {
37-
if i % bytes_per_line == 0 {
37+
if i.is_multiple_of(bytes_per_line) {
3838
writeln!(uart, "\r").unwrap();
3939
} else {
4040
write!(uart, ", ").unwrap();
@@ -50,7 +50,7 @@ pub fn print_reg_u32(uart: &mut UartController<'_>, reg_base: usize, size: usize
5050
unsafe { core::slice::from_raw_parts(reg_base as *const u32, size / 4) };
5151

5252
for (i, word) in reg_words.iter().enumerate() {
53-
if i % words_per_line == 0 {
53+
if i.is_multiple_of(words_per_line) {
5454
writeln!(uart, "\r\n[{:08x}]:", reg_base + i * 4).unwrap(); // Print base address
5555
} else {
5656
write!(uart, ", ").unwrap();

src/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl<'a> UartLogger<'a> {
9797
}
9898
}
9999

100-
impl<'a> Logger for UartLogger<'a> {
100+
impl Logger for UartLogger<'_> {
101101
fn debug(&mut self, msg: &str) {
102102
writeln!(self.uart, "{msg}").ok();
103103
write!(self.uart, "\r").ok();

src/i2c/ast1060_i2c.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1789,7 +1789,7 @@ impl<'a, I2C: Instance, I2CT: I2CTarget, L: Logger> Ast1060I2c<'a, I2C, I2CT, L>
17891789
match &mut prev_op {
17901790
Operation::Read(rb) => self.read(addr, rb)?,
17911791
Operation::Write(wb) => self.write(addr, wb)?,
1792-
};
1792+
}
17931793
prev_op = op;
17941794
}
17951795
}

src/i2c_core/constants.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
//!
2525
//! - **i2cm18**: Command register - write all command bits here
2626
//! - **i2cm14**: Status register - read status, write to clear interrupts
27-
//! - **i2cc08**: Byte data register for byte mode (tx_byte_buffer, rx_byte_buffer)
28-
//! - **i2cc0c**: Buffer size register for buffer mode (tx_data_byte_count, rx_pool_buffer_size)
27+
//! - **i2cc08**: Byte data register for byte mode (`tx_byte_buffer`, `rx_byte_buffer`)
28+
//! - **i2cc0c**: Buffer size register for buffer mode (`tx_data_byte_count`, `rx_pool_buffer_size`)
2929
3030
/// HPLL frequency (1 `GHz`)
3131
pub const HPLL_FREQ: u32 = 1_000_000_000;
@@ -46,7 +46,7 @@ pub const I2C_FAST_PLUS_MODE_HZ: u32 = 1_000_000;
4646
pub const BUFFER_MODE_SIZE: usize = 32;
4747

4848
/// I2C buffer size register value
49-
/// Reference: ast1060_i2c.rs:97
49+
/// Reference: `ast1060_i2c.rs:97`
5050
pub const I2C_BUF_SIZE: u8 = 0x20;
5151

5252
/// Default timeout in microseconds

src/i2c_core/global.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use ast1060_pac;
4747
/// # Reference
4848
///
4949
/// See original implementation in:
50-
/// - `aspeed-rust/src/i2c/ast1060_i2c.rs:320-360` - Global init with I2CGLOBAL_INIT guard
50+
/// - `aspeed-rust/src/i2c/ast1060_i2c.rs:320-360` - Global init with `I2CGLOBAL_INIT` guard
5151
/// - `aspeed-rust/src/i2c/ast1060_i2c.rs:347-360` - Clock divider configuration comments
5252
///
5353
/// # Safety

src/i2c_core/hal_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl Error for I2cError {
102102
}
103103

104104
/// Associates the `I2cError` type with `Ast1060I2c` for embedded-hal trait implementations.
105-
impl<'a> ErrorType for Ast1060I2c<'a> {
105+
impl ErrorType for Ast1060I2c<'_> {
106106
type Error = I2cError;
107107
}
108108

@@ -147,7 +147,7 @@ impl<'a> ErrorType for Ast1060I2c<'a> {
147147
/// i2c.write_read(0x52, &[0xA0], &mut buffer)?;
148148
/// # Ok::<(), aspeed_ddk::i2c_core::error::I2cError>(())
149149
/// ```
150-
impl<'a> I2c<SevenBitAddress> for Ast1060I2c<'a> {
150+
impl I2c<SevenBitAddress> for Ast1060I2c<'_> {
151151
/// Writes data to an I2C slave device.
152152
///
153153
/// # Arguments

src/i2c_core/master.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@
1414
//!
1515
//! - **i2cm18** (Master Command Register): All command bits written here
1616
//! - Command: `PKT_EN | pkt_addr(addr) | START_CMD | TX/RX_CMD | BUFF_EN | STOP_CMD`
17-
//! - Reference: ast1060_i2c.rs:1024 and ast1060_i2c.rs:1107
17+
//! - Reference: `ast1060_i2c.rs:1024` and `ast1060_i2c.rs:1107`
1818
//!
1919
//! - **i2cc08** (Byte Buffer Register): TX/RX byte data for byte mode
20-
//! - `tx_byte_buffer()`: Write byte to transmit (ast1060_i2c.rs:1101)
21-
//! - `rx_byte_buffer()`: Read received byte (ast1060_i2c.rs:790)
20+
//! - `tx_byte_buffer()`: Write byte to transmit (`ast1060_i2c.rs:1101`)
21+
//! - `rx_byte_buffer()`: Read received byte (`ast1060_i2c.rs:790`)
2222
//!
2323
//! - **i2cc0c** (Buffer Size Register): Buffer sizes for buffer mode
24-
//! - `tx_data_byte_count()`: Set TX count (ast1060_i2c.rs:1089)
25-
//! - `rx_pool_buffer_size()`: Set RX size (ast1060_i2c.rs:1011)
24+
//! - `tx_data_byte_count()`: Set TX count (`ast1060_i2c.rs:1089`)
25+
//! - `rx_pool_buffer_size()`: Set RX size (`ast1060_i2c.rs:1011`)
2626
//!
2727
//! - **i2cm14** (Interrupt Status Register): Read status, write-to-clear
28-
//! - Reference: ast1060_i2c.rs:849-870 (aspeed_i2c_master_irq)
28+
//! - Reference: `ast1060_i2c.rs:849-870` (`aspeed_i2c_master_irq`)
2929
3030
use super::{constants, controller::Ast1060I2c, error::I2cError, types::I2cXferMode};
3131

32-
impl<'a> Ast1060I2c<'a> {
32+
impl Ast1060I2c<'_> {
3333
/// Write bytes to an I2C device
3434
pub fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), I2cError> {
3535
if bytes.is_empty() {
@@ -193,7 +193,7 @@ impl<'a> Ast1060I2c<'a> {
193193
/// Uses hardware buffer for efficient multi-byte transfers.
194194
/// Single transaction model: START+addr on first chunk only,
195195
/// subsequent chunks continue the transaction without re-addressing.
196-
/// Reference: ast1060_i2c.rs do_i2cm_tx() continuation logic
196+
/// Reference: `ast1060_i2c.rs` `do_i2cm_tx()` continuation logic
197197
fn write_buffer_mode(&mut self, addr: u8, bytes: &[u8]) -> Result<(), I2cError> {
198198
let total_len = bytes.len();
199199
let mut offset = 0;
@@ -272,7 +272,7 @@ impl<'a> Ast1060I2c<'a> {
272272
/// Uses hardware buffer for efficient multi-byte transfers.
273273
/// Single transaction model: START+addr on first chunk only,
274274
/// subsequent chunks continue the transaction without re-addressing.
275-
/// Reference: ast1060_i2c.rs do_i2cm_rx() lines 762-810
275+
/// Reference: `ast1060_i2c.rs` `do_i2cm_rx()` lines 762-810
276276
fn read_buffer_mode(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), I2cError> {
277277
let total_len = buffer.len();
278278
let mut offset = 0;

src/i2c_core/recovery.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
use super::{constants, controller::Ast1060I2c, error::I2cError};
66

7-
impl<'a> Ast1060I2c<'a> {
7+
impl Ast1060I2c<'_> {
88
/// Recover the I2C bus from stuck condition
99
pub fn recover_bus(&mut self) -> Result<(), I2cError> {
1010
// Disable master and slave functionality

src/i2c_core/slave.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl SlaveBuffer {
112112
}
113113
}
114114

115-
impl<'a> Ast1060I2c<'a> {
115+
impl Ast1060I2c<'_> {
116116
/// Configure the controller for slave mode
117117
pub fn configure_slave(&mut self, config: &SlaveConfig) -> Result<(), I2cError> {
118118
// Ensure master mode is disabled first
@@ -269,6 +269,7 @@ impl<'a> Ast1060I2c<'a> {
269269
self.copy_to_buffer(&data[..to_write])?;
270270

271271
// Set transfer length
272+
#[allow(clippy::cast_possible_truncation)]
272273
self.regs()
273274
.i2cc0c()
274275
.write(|w| unsafe { w.tx_data_byte_count().bits(to_write as u8 - 1) });
@@ -296,6 +297,7 @@ impl<'a> Ast1060I2c<'a> {
296297
}
297298

298299
/// Handle slave mode interrupt
300+
#[allow(clippy::too_many_lines)]
299301
pub fn handle_slave_interrupt(&mut self) -> Option<SlaveEvent> {
300302
let status = self.regs().i2cs24().read().bits();
301303

@@ -413,15 +415,15 @@ impl<'a> Ast1060I2c<'a> {
413415
}
414416
} else {
415417
//byte irq
416-
let mut cmd: u32 = constants::AST_I2CS_ACTIVE_ALL;
418+
let cmd: u32 = constants::AST_I2CS_ACTIVE_ALL;
417419

418420
if status
419421
== constants::AST_I2CS_SLAVE_MATCH
420422
| constants::AST_I2CS_RX_DONE
421423
| constants::AST_I2CS_WAIT_RX_DMA
422424
{
423425
// S: Sw|D
424-
let byte_data = self.regs().i2cc08().read().rx_byte_buffer().bits();
426+
let _byte_data = self.regs().i2cc08().read().rx_byte_buffer().bits();
425427
self.regs().i2cs28().write(|w| unsafe { w.bits(cmd) });
426428
self.regs().i2cs24().write(|w| unsafe { w.bits(status) });
427429
self.regs().i2cs24().read().bits();
@@ -439,7 +441,7 @@ impl<'a> Ast1060I2c<'a> {
439441
| constants::AST_I2CS_STOP
440442
{
441443
// S: Sw|D|P
442-
let byte_data = self.regs().i2cc08().read().rx_byte_buffer().bits();
444+
let _byte_data = self.regs().i2cc08().read().rx_byte_buffer().bits();
443445
self.regs().i2cs28().write(|w| unsafe { w.bits(cmd) });
444446
self.regs().i2cs24().write(|w| unsafe { w.bits(status) });
445447
return Some(SlaveEvent::WriteRequest);
@@ -453,7 +455,7 @@ impl<'a> Ast1060I2c<'a> {
453455
{
454456
// S: Sr|D
455457
// received one byte
456-
let byte_data = self.regs().i2cc08().read().rx_byte_buffer().bits();
458+
let _byte_data = self.regs().i2cc08().read().rx_byte_buffer().bits();
457459
return Some(SlaveEvent::DataSent { len: 1 });
458460
} else if status == constants::AST_I2CS_TX_ACK | constants::AST_I2CS_WAIT_TX_DMA {
459461
// S: tD
@@ -474,9 +476,8 @@ impl<'a> Ast1060I2c<'a> {
474476
self.regs().i2cs28().write(|w| unsafe { w.bits(cmd) });
475477
self.regs().i2cs24().write(|w| unsafe { w.bits(status) });
476478
return Some(SlaveEvent::Stop);
477-
} else {
478-
// TODO byte slave sts
479479
}
480+
// TODO byte slave sts
480481
}
481482
None
482483
}

src/i2c_core/transfer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use super::{constants, controller::Ast1060I2c, error::I2cError, types::I2cXferMode};
1010

1111
#[allow(dead_code)]
12-
impl<'a> Ast1060I2c<'a> {
12+
impl Ast1060I2c<'_> {
1313
/// Start a transfer (common setup for byte/buffer modes)
1414
///
1515
/// Note: Currently unused - byte/buffer mode functions in master.rs

0 commit comments

Comments
 (0)