Skip to content

Commit f8342cc

Browse files
committed
Replace size_align_u32() with next_multiple_of()
Currently next_multiple_of() is behinged a Feature gate: int_rounding. See rust-lang/rust#88581 But it seems that this function is stablized in rust 1.73. See rust-lang/rust#94455 Currently Embassy is still using nightly for many other unstable features. So I do see an issue to use this function.
1 parent 27d68d1 commit f8342cc

File tree

1 file changed

+5
-25
lines changed
  • embassy-net-adin1110/src

1 file changed

+5
-25
lines changed

embassy-net-adin1110/src/lib.rs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ pub struct ADIN1110<SPI> {
9595
crc: bool,
9696
}
9797

98-
/// Round size up the N u32;
99-
pub(crate) fn size_align_u32(size: u32) -> u32 {
100-
(size + 3) & 0xFFFF_FFFC
101-
}
102-
10398
impl<SPI: SpiDevice> ADIN1110<SPI> {
10499
pub fn new(spi: SPI, crc: bool) -> Self {
105100
Self { spi, crc }
@@ -192,14 +187,12 @@ impl<SPI: SpiDevice> ADIN1110<SPI> {
192187
let mut tx_buf = Vec::<u8, 16>::new();
193188

194189
// Size of the frame, also includes the appednded header.
195-
let packet_size = self.read_reg(sr::RX_FSIZE).await?;
190+
let packet_size = self.read_reg(sr::RX_FSIZE).await? as usize;
196191

197192
// Packet read of write to the MAC packet buffer must be a multipul of 4!
198-
let read_size = size_align_u32(packet_size);
193+
let read_size = packet_size.next_multiple_of(4);
199194

200-
if packet_size < u32::try_from(FRAME_HEADER_LEN + FSC_LEN).unwrap()
201-
|| read_size > u32::try_from(packet.len()).unwrap()
202-
{
195+
if packet_size < (FRAME_HEADER_LEN + FSC_LEN) || read_size > packet.len() {
203196
return Err(AdinError::PACKET_TOO_BIG);
204197
}
205198

@@ -836,18 +829,6 @@ mod tests {
836829
spi.done();
837830
}
838831

839-
#[test]
840-
fn align_size() {
841-
assert_eq!(size_align_u32(1), 4);
842-
assert_eq!(size_align_u32(2), 4);
843-
assert_eq!(size_align_u32(3), 4);
844-
assert_eq!(size_align_u32(4), 4);
845-
assert_eq!(size_align_u32(5), 8);
846-
assert_eq!(size_align_u32(6), 8);
847-
assert_eq!(size_align_u32(7), 8);
848-
assert_eq!(size_align_u32(8), 8);
849-
}
850-
851832
// #[test]
852833
// fn write_packet_to_fifo_less_64b_with_crc() {
853834
// // Configure expectations
@@ -1224,10 +1205,9 @@ mod tests {
12241205
// Packet FCS
12251206
spi_packet.extend_from_slice(&[147, 149, 213, 68]).unwrap();
12261207

1227-
let spi_packet_len = u32::try_from(spi_packet.len()).unwrap();
1228-
12291208
// SPI HEADER Padding of u32
1230-
for _ in spi_packet_len..size_align_u32(spi_packet_len) {
1209+
let spi_packet_len = spi_packet.len();
1210+
for _ in spi_packet_len..spi_packet_len.next_multiple_of(4) {
12311211
spi_packet.push(0x00).unwrap();
12321212
}
12331213

0 commit comments

Comments
 (0)