Skip to content

Commit 062d493

Browse files
authored
Merge pull request #501 from stm32-rs/as_ptr
REG::as_ptr
2 parents 01a6d0c + 2fd2b36 commit 062d493

File tree

3 files changed

+20
-38
lines changed

3 files changed

+20
-38
lines changed

src/adc.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -745,10 +745,8 @@ macro_rules! adcdma {
745745
// NOTE(unsafe) We own the buffer now and we won't call other `&mut` on it
746746
// until the end of the transfer.
747747
let (ptr, len) = unsafe { buffer.write_buffer() };
748-
self.channel.set_peripheral_address(
749-
unsafe { &(*<$ADCX>::ptr()).dr as *const _ as u32 },
750-
false,
751-
);
748+
self.channel
749+
.set_peripheral_address(unsafe { (*<$ADCX>::ptr()).dr.as_ptr() as u32 }, false);
752750
self.channel.set_memory_address(ptr as u32, true);
753751
self.channel.set_transfer_length(len);
754752

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

src/serial.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ macro_rules! inst {
120120
$(
121121
impl Instance for $USARTX {
122122
fn ptr() -> *const uart_base::RegisterBlock {
123-
<$USARTX>::ptr() as *const _
123+
<$USARTX>::ptr()
124124
}
125125
}
126126
)+
@@ -753,10 +753,8 @@ macro_rules! serialdma {
753753
// NOTE(unsafe) We own the buffer now and we won't call other `&mut` on it
754754
// until the end of the transfer.
755755
let (ptr, len) = unsafe { buffer.write_buffer() };
756-
self.channel.set_peripheral_address(
757-
unsafe { &(*$USARTX::ptr()).dr as *const _ as u32 },
758-
false,
759-
);
756+
self.channel
757+
.set_peripheral_address(unsafe { (*$USARTX::ptr()).dr.as_ptr() as u32 }, false);
760758
self.channel.set_memory_address(ptr as u32, true);
761759
self.channel.set_transfer_length(len);
762760

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

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

819-
self.channel.set_peripheral_address(
820-
unsafe { &(*$USARTX::ptr()).dr as *const _ as u32 },
821-
false,
822-
);
815+
self.channel
816+
.set_peripheral_address(unsafe { (*$USARTX::ptr()).dr.as_ptr() as u32 }, false);
823817

824818
self.channel.set_memory_address(ptr as u32, true);
825819
self.channel.set_transfer_length(len);

src/spi.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ where
379379
fn read_data_reg(&mut self) -> FrameSize {
380380
// NOTE(read_volatile) read only 1 byte (the svd2rust API only allows
381381
// reading a half-word)
382-
unsafe { ptr::read_volatile(&self.spi.dr as *const _ as *const FrameSize) }
382+
unsafe { ptr::read_volatile(ptr::addr_of!(self.spi.dr) as *const FrameSize) }
383383
}
384384

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

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

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

895-
self.rxchannel.set_peripheral_address(
896-
unsafe { &(*<$SPIi>::ptr()).dr as *const _ as u32 },
897-
false,
898-
);
891+
self.rxchannel
892+
.set_peripheral_address(unsafe { (*<$SPIi>::ptr()).dr.as_ptr() as u32 }, false);
899893
self.rxchannel.set_memory_address(rxptr as u32, true);
900894
self.rxchannel.set_transfer_length(rxlen);
901895

902-
self.txchannel.set_peripheral_address(
903-
unsafe { &(*<$SPIi>::ptr()).dr as *const _ as u32 },
904-
false,
905-
);
896+
self.txchannel
897+
.set_peripheral_address(unsafe { (*<$SPIi>::ptr()).dr.as_ptr() as u32 }, false);
906898
self.txchannel.set_memory_address(txptr as u32, true);
907899
self.txchannel.set_transfer_length(txlen);
908900

0 commit comments

Comments
 (0)