Skip to content

Commit

Permalink
REG::as_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Oct 5, 2024
1 parent 01a6d0c commit 2fd2b36
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 38 deletions.
12 changes: 4 additions & 8 deletions src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,10 +745,8 @@ macro_rules! adcdma {
// NOTE(unsafe) We own the buffer now and we won't call other `&mut` on it
// until the end of the transfer.
let (ptr, len) = unsafe { buffer.write_buffer() };
self.channel.set_peripheral_address(
unsafe { &(*<$ADCX>::ptr()).dr as *const _ as u32 },
false,
);
self.channel
.set_peripheral_address(unsafe { (*<$ADCX>::ptr()).dr.as_ptr() as u32 }, false);
self.channel.set_memory_address(ptr as u32, true);
self.channel.set_transfer_length(len);

Expand Down Expand Up @@ -784,10 +782,8 @@ macro_rules! adcdma {
// NOTE(unsafe) We own the buffer now and we won't call other `&mut` on it
// until the end of the transfer.
let (ptr, len) = unsafe { buffer.write_buffer() };
self.channel.set_peripheral_address(
unsafe { &(*<$ADCX>::ptr()).dr as *const _ as u32 },
false,
);
self.channel
.set_peripheral_address(unsafe { (*<$ADCX>::ptr()).dr.as_ptr() as u32 }, false);
self.channel.set_memory_address(ptr as u32, true);
self.channel.set_transfer_length(len);

Expand Down
20 changes: 7 additions & 13 deletions src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ macro_rules! inst {
$(
impl Instance for $USARTX {
fn ptr() -> *const uart_base::RegisterBlock {
<$USARTX>::ptr() as *const _
<$USARTX>::ptr()
}
}
)+
Expand Down Expand Up @@ -753,10 +753,8 @@ macro_rules! serialdma {
// NOTE(unsafe) We own the buffer now and we won't call other `&mut` on it
// until the end of the transfer.
let (ptr, len) = unsafe { buffer.write_buffer() };
self.channel.set_peripheral_address(
unsafe { &(*$USARTX::ptr()).dr as *const _ as u32 },
false,
);
self.channel
.set_peripheral_address(unsafe { (*$USARTX::ptr()).dr.as_ptr() as u32 }, false);
self.channel.set_memory_address(ptr as u32, true);
self.channel.set_transfer_length(len);

Expand Down Expand Up @@ -785,10 +783,8 @@ macro_rules! serialdma {
// NOTE(unsafe) We own the buffer now and we won't call other `&mut` on it
// until the end of the transfer.
let (ptr, len) = unsafe { buffer.write_buffer() };
self.channel.set_peripheral_address(
unsafe { &(*$USARTX::ptr()).dr as *const _ as u32 },
false,
);
self.channel
.set_peripheral_address(unsafe { (*$USARTX::ptr()).dr.as_ptr() as u32 }, false);
self.channel.set_memory_address(ptr as u32, true);
self.channel.set_transfer_length(len);

Expand Down Expand Up @@ -816,10 +812,8 @@ macro_rules! serialdma {
// until the end of the transfer.
let (ptr, len) = unsafe { buffer.read_buffer() };

self.channel.set_peripheral_address(
unsafe { &(*$USARTX::ptr()).dr as *const _ as u32 },
false,
);
self.channel
.set_peripheral_address(unsafe { (*$USARTX::ptr()).dr.as_ptr() as u32 }, false);

self.channel.set_memory_address(ptr as u32, true);
self.channel.set_transfer_length(len);
Expand Down
26 changes: 9 additions & 17 deletions src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ where
fn read_data_reg(&mut self) -> FrameSize {
// NOTE(read_volatile) read only 1 byte (the svd2rust API only allows
// reading a half-word)
unsafe { ptr::read_volatile(&self.spi.dr as *const _ as *const FrameSize) }
unsafe { ptr::read_volatile(ptr::addr_of!(self.spi.dr) as *const FrameSize) }
}

fn write_data_reg(&mut self, data: FrameSize) {
Expand Down Expand Up @@ -807,10 +807,8 @@ macro_rules! spi_dma {
// NOTE(unsafe) We own the buffer now and we won't call other `&mut` on it
// until the end of the transfer.
let (ptr, len) = unsafe { buffer.write_buffer() };
self.channel.set_peripheral_address(
unsafe { &(*<$SPIi>::ptr()).dr as *const _ as u32 },
false,
);
self.channel
.set_peripheral_address(unsafe { (*<$SPIi>::ptr()).dr.as_ptr() as u32 }, false);
self.channel.set_memory_address(ptr as u32, true);
self.channel.set_transfer_length(len);

Expand Down Expand Up @@ -844,10 +842,8 @@ macro_rules! spi_dma {
// NOTE(unsafe) We own the buffer now and we won't call other `&mut` on it
// until the end of the transfer.
let (ptr, len) = unsafe { buffer.read_buffer() };
self.channel.set_peripheral_address(
unsafe { &(*<$SPIi>::ptr()).dr as *const _ as u32 },
false,
);
self.channel
.set_peripheral_address(unsafe { (*<$SPIi>::ptr()).dr.as_ptr() as u32 }, false);
self.channel.set_memory_address(ptr as u32, true);
self.channel.set_transfer_length(len);

Expand Down Expand Up @@ -892,17 +888,13 @@ macro_rules! spi_dma {
panic!("receive and send buffer lengths do not match!");
}

self.rxchannel.set_peripheral_address(
unsafe { &(*<$SPIi>::ptr()).dr as *const _ as u32 },
false,
);
self.rxchannel
.set_peripheral_address(unsafe { (*<$SPIi>::ptr()).dr.as_ptr() as u32 }, false);
self.rxchannel.set_memory_address(rxptr as u32, true);
self.rxchannel.set_transfer_length(rxlen);

self.txchannel.set_peripheral_address(
unsafe { &(*<$SPIi>::ptr()).dr as *const _ as u32 },
false,
);
self.txchannel
.set_peripheral_address(unsafe { (*<$SPIi>::ptr()).dr.as_ptr() as u32 }, false);
self.txchannel.set_memory_address(txptr as u32, true);
self.txchannel.set_transfer_length(txlen);

Expand Down

0 comments on commit 2fd2b36

Please sign in to comment.