Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix more clippy warnings #515

Merged
merged 3 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion examples/dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ fn main() -> ! {
value.as_mut_ptr().write(rng.gen().unwrap());
}
}
unsafe { SOURCE_BUFFER.assume_init_mut() }
#[allow(static_mut_refs)] // TODO: Fix this
unsafe {
SOURCE_BUFFER.assume_init_mut()
}
};
// Save a copy on the stack so we can check it later
let source_buffer_cloned = *source_buffer;
Expand Down Expand Up @@ -102,6 +105,7 @@ fn main() -> ! {
while !transfer.get_transfer_complete_flag() {}

// Now the target memory is actually initialised
#[allow(static_mut_refs)] // TODO: Fix this
let target_buffer: &'static mut [u32; 20] =
unsafe { TARGET_BUFFER.assume_init_mut() };

Expand Down
2 changes: 2 additions & 0 deletions examples/ethernet-nucleo-h743zi2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ fn main() -> ! {

let mac_addr = smoltcp::wire::EthernetAddress::from_bytes(&MAC_ADDRESS);
let (_eth_dma, eth_mac) = unsafe {
#[allow(static_mut_refs)] // TODO: Fix this
DES_RING.write(ethernet::DesRing::new());

ethernet::new(
Expand All @@ -131,6 +132,7 @@ fn main() -> ! {
rmii_txd0,
rmii_txd1,
),
#[allow(static_mut_refs)] // TODO: Fix this
DES_RING.assume_init_mut(),
mac_addr,
ccdr.peripheral.ETH1MAC,
Expand Down
4 changes: 4 additions & 0 deletions examples/ethernet-rtic-nucleo-h723zg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ mod app {

let mac_addr = smoltcp::wire::EthernetAddress::from_bytes(&MAC_ADDRESS);
let (eth_dma, eth_mac) = unsafe {
#[allow(static_mut_refs)] // TODO: Fix this
DES_RING.write(ethernet::DesRing::new());

ethernet::new(
Expand All @@ -181,6 +182,7 @@ mod app {
rmii_txd0,
rmii_txd1,
),
#[allow(static_mut_refs)] // TODO: Fix this
DES_RING.assume_init_mut(),
mac_addr,
ccdr.peripheral.ETH1MAC,
Expand All @@ -198,6 +200,7 @@ mod app {

// unsafe: mutable reference to static storage, we only do this once
let store = unsafe {
#[allow(static_mut_refs)] // TODO: Fix this
let store_ptr = STORE.as_mut_ptr();

// Initialise the socket_storage field. Using `write` instead of
Expand All @@ -208,6 +211,7 @@ mod app {

// Now that all fields are initialised we can safely use
// assume_init_mut to return a mutable reference to STORE
#[allow(static_mut_refs)] // TODO: Fix this
STORE.assume_init_mut()
};

Expand Down
4 changes: 4 additions & 0 deletions examples/ethernet-rtic-stm32h735g-dk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ mod app {

let mac_addr = smoltcp::wire::EthernetAddress::from_bytes(&MAC_ADDRESS);
let (eth_dma, eth_mac) = unsafe {
#[allow(static_mut_refs)] // TODO: Fix this
DES_RING.write(ethernet::DesRing::new());

ethernet::new(
Expand All @@ -175,6 +176,7 @@ mod app {
rmii_txd0,
rmii_txd1,
),
#[allow(static_mut_refs)] // TODO: Fix this
DES_RING.assume_init_mut(),
mac_addr,
ccdr.peripheral.ETH1MAC,
Expand All @@ -192,6 +194,7 @@ mod app {

// unsafe: mutable reference to static storage, we only do this once
let store = unsafe {
#[allow(static_mut_refs)] // TODO: Fix this
let store_ptr = STORE.as_mut_ptr();

// Initialise the socket_storage field. Using `write` instead of
Expand All @@ -202,6 +205,7 @@ mod app {

// Now that all fields are initialised we can safely use
// assume_init_mut to return a mutable reference to STORE
#[allow(static_mut_refs)] // TODO: Fix this
STORE.assume_init_mut()
};

Expand Down
4 changes: 4 additions & 0 deletions examples/ethernet-rtic-stm32h747i-disco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ mod app {

let mac_addr = smoltcp::wire::EthernetAddress::from_bytes(&MAC_ADDRESS);
let (eth_dma, eth_mac) = unsafe {
#[allow(static_mut_refs)] // TODO: Fix this
DES_RING.write(ethernet::DesRing::new());

ethernet::new(
Expand All @@ -185,6 +186,7 @@ mod app {
rmii_txd0,
rmii_txd1,
),
#[allow(static_mut_refs)] // TODO: Fix this
DES_RING.assume_init_mut(),
mac_addr,
ccdr.peripheral.ETH1MAC,
Expand All @@ -202,6 +204,7 @@ mod app {

// unsafe: mutable reference to static storage, we only do this once
let store = unsafe {
#[allow(static_mut_refs)] // TODO: Fix this
let store_ptr = STORE.as_mut_ptr();

// Initialise the socket_storage field. Using `write` instead of
Expand All @@ -212,6 +215,7 @@ mod app {

// Now that all fields are initialised we can safely use
// assume_init_mut to return a mutable reference to STORE
#[allow(static_mut_refs)] // TODO: Fix this
STORE.assume_init_mut()
};

Expand Down
2 changes: 2 additions & 0 deletions examples/ethernet-stm32h747i-disco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ fn main() -> ! {

let mac_addr = smoltcp::wire::EthernetAddress::from_bytes(&MAC_ADDRESS);
let (_eth_dma, eth_mac) = unsafe {
#[allow(static_mut_refs)] // TODO: Fix this
DES_RING.write(ethernet::DesRing::new());

ethernet::new(
Expand All @@ -104,6 +105,7 @@ fn main() -> ! {
rmii_txd0,
rmii_txd1,
),
#[allow(static_mut_refs)] // TODO: Fix this
DES_RING.assume_init_mut(),
mac_addr,
ccdr.peripheral.ETH1MAC,
Expand Down
6 changes: 5 additions & 1 deletion examples/i2c4_bdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ fn main() -> ! {
Transfer::init(
streams.0,
i2c,
unsafe { BUFFER.assume_init_mut() },
#[allow(static_mut_refs)] // TODO: Fix this
unsafe {
BUFFER.assume_init_mut()
},
None,
config,
);
Expand Down Expand Up @@ -136,6 +139,7 @@ fn I2C4_EV() {
info!("I2C transfer complete!");

// Look at BUFFER, which we expect to be initialised
#[allow(static_mut_refs)] // TODO: Fix this
let buffer: &'static [u8; 10] = unsafe { BUFFER.assume_init_mut() };

assert_eq!(buffer[0], 0xBE);
Expand Down
6 changes: 5 additions & 1 deletion examples/mdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ fn main() -> ! {
value.as_mut_ptr().write(0x11223344u32);
}
}
unsafe { SOURCE_BUFFER.assume_init_mut() }
#[allow(static_mut_refs)] // TODO: Fix this
unsafe {
SOURCE_BUFFER.assume_init_mut()
}
};

//
Expand Down Expand Up @@ -118,6 +121,7 @@ fn main() -> ! {
//

// Reset source buffer
#[allow(static_mut_refs)] // TODO: Fix this
let source_buffer = unsafe { SOURCE_BUFFER.assume_init_mut() };
*source_buffer = [0xAABBCCDD; 200];

Expand Down
7 changes: 6 additions & 1 deletion examples/mdma_bursts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ fn main() -> ! {
value.as_mut_ptr().write(0x11223344u32);
}
}
unsafe { SOURCE_BUFFER.assume_init_mut() }
#[allow(static_mut_refs)] // TODO: Fix this
unsafe {
SOURCE_BUFFER.assume_init_mut()
}
};

// NOTE(unsafe): TARGET_BUFFER must also be initialised to prevent undefined
Expand All @@ -92,8 +95,10 @@ fn main() -> ! {
let mut transfer: Transfer<_, _, MemoryToMemory<u32>, _, _> = {
// unsafe: Both source and destination live at least as long as this
// transfer
#[allow(static_mut_refs)] // TODO: Fix this
let source: &'static mut [u32; 200] =
unsafe { SOURCE_BUFFER.assume_init_mut() };
#[allow(static_mut_refs)] // TODO: Fix this
let target: &'static mut [u32; 200] =
unsafe { TARGET_BUFFER.assume_init_mut() }; // uninitialised memory

Expand Down
7 changes: 7 additions & 0 deletions examples/sai_dma_passthru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ fn main() -> ! {
dma::dma::StreamsTuple::new(dp.DMA1, ccdr.peripheral.DMA1);

// dma1 stream 0
#[allow(static_mut_refs)] // TODO: Fix this
let tx_buffer: &'static mut [u32; DMA_BUFFER_LENGTH] =
unsafe { TX_BUFFER.assume_init_mut() }; // uninitialised memory
let dma_config = dma::dma::DmaConfig::default()
Expand All @@ -128,6 +129,7 @@ fn main() -> ! {
);

// dma1 stream 1
#[allow(static_mut_refs)] // TODO: Fix this
let rx_buffer: &'static mut [u32; DMA_BUFFER_LENGTH] =
unsafe { RX_BUFFER.assume_init_mut() }; // uninitialised memory
let dma_config = dma_config
Expand Down Expand Up @@ -179,6 +181,7 @@ fn main() -> ! {
static mut TRANSFER_DMA1_STR1: MaybeUninit<Option<TransferDma1Str1>> =
MaybeUninit::uninit();
unsafe {
#[allow(static_mut_refs)] // TODO: Fix this
TRANSFER_DMA1_STR1.write(None);
}

Expand Down Expand Up @@ -220,6 +223,7 @@ fn main() -> ! {
>;

unsafe {
#[allow(static_mut_refs)] // TODO: Fix this
TRANSFER_DMA1_STR1.write(Some(dma1_str1)); // drops previous None
info!(
"{:?}, {:?}",
Expand All @@ -230,13 +234,16 @@ fn main() -> ! {

#[interrupt]
fn DMA1_STR1() {
#[allow(static_mut_refs)] // TODO: Fix this
let tx_buffer: &'static mut [u32; DMA_BUFFER_LENGTH] =
unsafe { TX_BUFFER.assume_init_mut() };
#[allow(static_mut_refs)] // TODO: Fix this
let rx_buffer: &'static mut [u32; DMA_BUFFER_LENGTH] =
unsafe { RX_BUFFER.assume_init_mut() };

let stereo_block_length = tx_buffer.len() / 2;

#[allow(static_mut_refs)] // TODO: Fix this
if let Some(transfer) = unsafe { TRANSFER_DMA1_STR1.assume_init_mut() }
{
let skip = if transfer.get_half_transfer_flag() {
Expand Down
5 changes: 4 additions & 1 deletion examples/serial-dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ fn main() -> ! {
value.as_mut_ptr().write(i as u8 + 96); // 0x60, 0x61, 0x62...
}
}
unsafe { SHORT_BUFFER.assume_init_mut() }
#[allow(static_mut_refs)] // TODO: Fix this
unsafe {
SHORT_BUFFER.assume_init_mut()
}
};
// view u32 buffer as u8. Endianess is undefined (little-endian on STM32H7)
let long_buffer: &'static mut [u8; 0x2_0010] = {
Expand Down
5 changes: 4 additions & 1 deletion examples/spi-dma-rtic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ mod app {
}
}

unsafe { BUFFER.assume_init_mut() }
#[allow(static_mut_refs)] // TODO: Fix this
unsafe {
BUFFER.assume_init_mut()
}
};

let streams = hal::dma::dma::StreamsTuple::new(
Expand Down
5 changes: 4 additions & 1 deletion examples/spi-dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ fn main() -> ! {
value.as_mut_ptr().write(i as u8 + 96); // 0x60, 0x61, 0x62...
}
}
unsafe { SHORT_BUFFER.assume_init_mut() }
#[allow(static_mut_refs)] // TODO: Fix this
unsafe {
SHORT_BUFFER.assume_init_mut()
}
};
// view u32 buffer as u8. Endianess is undefined (little-endian on STM32H7)
let long_buffer: &'static mut [u8; 0x2_0010] = {
Expand Down
2 changes: 2 additions & 0 deletions examples/usb_passthrough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ fn main() -> ! {
}

// Port 1
#[allow(static_mut_refs)] // TODO: Fix this
let usb1_bus = UsbBus::new(usb1, unsafe { EP_MEMORY_1.assume_init_mut() });
let mut serial1 = usbd_serial::SerialPort::new(&usb1_bus);
let mut usb1_dev =
Expand All @@ -102,6 +103,7 @@ fn main() -> ! {
.build();

// Port 2
#[allow(static_mut_refs)] // TODO: Fix this
let usb2_bus = UsbBus::new(usb2, unsafe { EP_MEMORY_2.assume_init_mut() });
let mut serial2 = usbd_serial::SerialPort::new(&usb2_bus);
let mut usb2_dev =
Expand Down
8 changes: 7 additions & 1 deletion examples/usb_phy_serial_interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,17 @@ unsafe fn main() -> ! {
}
}

USB_BUS_ALLOCATOR = Some(UsbBus::new(usb, USB_MEMORY_1.assume_init_mut()));
#[allow(static_mut_refs)] // TODO: Fix this
{
USB_BUS_ALLOCATOR =
Some(UsbBus::new(usb, USB_MEMORY_1.assume_init_mut()));
}

#[allow(static_mut_refs)] // TODO: Fix this
let usb_serial =
usbd_serial::SerialPort::new(USB_BUS_ALLOCATOR.as_ref().unwrap());

#[allow(static_mut_refs)] // TODO: Fix this
let usb_dev = UsbDeviceBuilder::new(
USB_BUS_ALLOCATOR.as_ref().unwrap(),
UsbVidPid(VID, PID),
Expand Down
1 change: 1 addition & 0 deletions examples/usb_rtic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ mod app {
}

// Now we may assume that EP_MEMORY is initialised
#[allow(static_mut_refs)] // TODO: Fix this
let usb_bus = cortex_m::singleton!(
: usb_device::class_prelude::UsbBusAllocator<UsbBus<USB1>> =
UsbBus::new(usb, unsafe { EP_MEMORY.assume_init_mut() })
Expand Down
1 change: 1 addition & 0 deletions examples/usb_serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ fn main() -> ! {
}

// Now we may assume that EP_MEMORY is initialised
#[allow(static_mut_refs)] // TODO: Fix this
let usb_bus = UsbBus::new(usb, unsafe { EP_MEMORY.assume_init_mut() });

let mut serial = usbd_serial::SerialPort::new(&usb_bus);
Expand Down
10 changes: 5 additions & 5 deletions src/dsi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub struct DsiPllConfig {
}

impl DsiPllConfig {
/// # Safety: TODO
pub unsafe fn manual(ndiv: u8, idf: u8, odf: u8, eckdiv: u8) -> Self {
DsiPllConfig {
ndiv,
Expand Down Expand Up @@ -408,11 +409,10 @@ impl DsiHost {
});

// Color coding for the host
let lpe = match dsi_config.color_coding_host {
ColorCoding::EighteenBitsConfig1 => true,
ColorCoding::EighteenBitsConfig2 => true,
_ => false,
};
let lpe = matches!(
dsi_config.color_coding_host,
ColorCoding::EighteenBitsConfig1 | ColorCoding::EighteenBitsConfig2
);
dsi.lcolcr.modify(|_, w| unsafe {
w.lpe()
.bit(lpe) // loosely packed: 18bits
Expand Down
Loading