Replace size_align_u32() with next_multiple_of()
Currently next_multiple_of() is behinged a Feature gate: int_rounding. See https://github.com/rust-lang/rust/issues/88581 But it seems that this function is stablized in rust 1.73. See https://github.com/rust-lang/rust/pull/94455 Currently Embassy is still using nightly for many other unstable features. So I do see an issue to use this function.
This commit is contained in:
		| @@ -95,11 +95,6 @@ pub struct ADIN1110<SPI> { | |||||||
|     crc: bool, |     crc: bool, | ||||||
| } | } | ||||||
|  |  | ||||||
| /// Round size up the N u32; |  | ||||||
| pub(crate) fn size_align_u32(size: u32) -> u32 { |  | ||||||
|     (size + 3) & 0xFFFF_FFFC |  | ||||||
| } |  | ||||||
|  |  | ||||||
| impl<SPI: SpiDevice> ADIN1110<SPI> { | impl<SPI: SpiDevice> ADIN1110<SPI> { | ||||||
|     pub fn new(spi: SPI, crc: bool) -> Self { |     pub fn new(spi: SPI, crc: bool) -> Self { | ||||||
|         Self { spi, crc } |         Self { spi, crc } | ||||||
| @@ -192,14 +187,12 @@ impl<SPI: SpiDevice> ADIN1110<SPI> { | |||||||
|         let mut tx_buf = Vec::<u8, 16>::new(); |         let mut tx_buf = Vec::<u8, 16>::new(); | ||||||
|  |  | ||||||
|         // Size of the frame, also includes the appednded header. |         // Size of the frame, also includes the appednded header. | ||||||
|         let packet_size = self.read_reg(sr::RX_FSIZE).await?; |         let packet_size = self.read_reg(sr::RX_FSIZE).await? as usize; | ||||||
|  |  | ||||||
|         // Packet read of write to the MAC packet buffer must be a multipul of 4! |         // Packet read of write to the MAC packet buffer must be a multipul of 4! | ||||||
|         let read_size = size_align_u32(packet_size); |         let read_size = packet_size.next_multiple_of(4); | ||||||
|  |  | ||||||
|         if packet_size < u32::try_from(FRAME_HEADER_LEN + FSC_LEN).unwrap() |         if packet_size < (FRAME_HEADER_LEN + FSC_LEN) || read_size > packet.len() { | ||||||
|             || read_size > u32::try_from(packet.len()).unwrap() |  | ||||||
|         { |  | ||||||
|             return Err(AdinError::PACKET_TOO_BIG); |             return Err(AdinError::PACKET_TOO_BIG); | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -836,18 +829,6 @@ mod tests { | |||||||
|         spi.done(); |         spi.done(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     #[test] |  | ||||||
|     fn align_size() { |  | ||||||
|         assert_eq!(size_align_u32(1), 4); |  | ||||||
|         assert_eq!(size_align_u32(2), 4); |  | ||||||
|         assert_eq!(size_align_u32(3), 4); |  | ||||||
|         assert_eq!(size_align_u32(4), 4); |  | ||||||
|         assert_eq!(size_align_u32(5), 8); |  | ||||||
|         assert_eq!(size_align_u32(6), 8); |  | ||||||
|         assert_eq!(size_align_u32(7), 8); |  | ||||||
|         assert_eq!(size_align_u32(8), 8); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     //     #[test] |     //     #[test] | ||||||
|     //     fn write_packet_to_fifo_less_64b_with_crc() { |     //     fn write_packet_to_fifo_less_64b_with_crc() { | ||||||
|     //         // Configure expectations |     //         // Configure expectations | ||||||
| @@ -1224,10 +1205,9 @@ mod tests { | |||||||
|         // Packet FCS |         // Packet FCS | ||||||
|         spi_packet.extend_from_slice(&[147, 149, 213, 68]).unwrap(); |         spi_packet.extend_from_slice(&[147, 149, 213, 68]).unwrap(); | ||||||
|  |  | ||||||
|         let spi_packet_len = u32::try_from(spi_packet.len()).unwrap(); |  | ||||||
|  |  | ||||||
|         // SPI HEADER Padding of u32 |         // SPI HEADER Padding of u32 | ||||||
|         for _ in spi_packet_len..size_align_u32(spi_packet_len) { |         let spi_packet_len = spi_packet.len(); | ||||||
|  |         for _ in spi_packet_len..spi_packet_len.next_multiple_of(4) { | ||||||
|             spi_packet.push(0x00).unwrap(); |             spi_packet.push(0x00).unwrap(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user