Skip to content

Commit db75219

Browse files
authored
Merge pull request #74 from Neotron-Compute/fix-ref-cast
Remove the reference cast for SPI.
2 parents fe15e07 + 0b945f9 commit db75219

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

neotron-bmc-pico/src/spi.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,19 @@ impl<const RXC: usize, const TXC: usize> SpiPeripheral<RXC, TXC> {
221221
fn raw_read(&mut self) -> u8 {
222222
// PAC only supports 16-bit read, but that pops two bytes off the FIFO.
223223
// So force an 8-bit read.
224-
unsafe { core::ptr::read_volatile(&self.dev.dr as *const _ as *const u8) }
224+
let spi_dr_ptr = self.dev.dr.as_ptr() as *mut u8;
225+
// Safety: we own the SPI device
226+
unsafe { spi_dr_ptr.read_volatile() }
225227
}
226228

227229
fn raw_write(&mut self, data: u8) {
228230
// PAC only supports 16-bit read, but that pushes two bytes onto the FIFO.
229231
// So force an 8-bit write.
230-
unsafe { core::ptr::write_volatile(&self.dev.dr as *const _ as *mut u8, data) }
232+
let spi_dr_ptr = self.dev.dr.as_ptr() as *mut u8;
233+
// Safety: we own the SPI device
234+
unsafe {
235+
spi_dr_ptr.write_volatile(data);
236+
}
231237
}
232238

233239
/// Get a slice of data received so far.

0 commit comments

Comments
 (0)