Skip to content

Commit 0ffa14c

Browse files
authored
Merge pull request #703 from stm32-rs/ptr
as_ptr
2 parents 4144b1d + ec14df3 commit 0ffa14c

File tree

9 files changed

+22
-22
lines changed

9 files changed

+22
-22
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10-
- Added an example to show how to do DMA with UART (Rx only) [#698]
11-
- Updated `synopsys-usb-otg` to `0.4.0`
1210
### Added
1311

1412
- Added an example to show how to do DMA with UART (Rx only) [#698]
1513

1614
### Changed
1715

1816
- bump embedded-hal to `1.0-rc2`
17+
- Use `as_ptr` for register address casting
18+
- Updated `synopsys-usb-otg` to `0.4.0`
1919

2020
### Fixed
2121

src/adc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ macro_rules! adc {
848848

849849
/// Returns the address of the ADC data register. Primarily useful for configuring DMA.
850850
pub fn data_register_address(&mut self) -> u32 {
851-
&self.adc_reg.dr as *const _ as u32
851+
self.adc_reg.dr.as_ptr() as u32
852852
}
853853

854854
/// Configure a channel for sampling.
@@ -1017,7 +1017,7 @@ macro_rules! adc {
10171017
unsafe impl PeriAddress for Adc<pac::$adc_type> {
10181018
#[inline(always)]
10191019
fn address(&self) -> u32 {
1020-
&self.adc_reg.dr as *const _ as u32
1020+
self.adc_reg.dr.as_ptr() as u32
10211021
}
10221022

10231023
type MemSize = u16;

src/dma/traits.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ macro_rules! address {
288288
unsafe impl PeriAddress for $peripheral {
289289
#[inline(always)]
290290
fn address(&self) -> u32 {
291-
&self.$register as *const _ as u32
291+
self.$register.as_ptr() as u32
292292
}
293293

294294
type MemSize = $size;
@@ -384,14 +384,14 @@ pub struct AES_OUT(());
384384
#[cfg(feature = "aes")]
385385
unsafe impl PeriAddress for AES_IN {
386386
fn address(&self) -> u32 {
387-
unsafe { &(*pac::AES::ptr()).dinr as *const _ as u32 }
387+
unsafe { (*pac::AES::ptr()).dinr.as_ptr() as u32 }
388388
}
389389
type MemSize = u32;
390390
}
391391
#[cfg(feature = "aes")]
392392
unsafe impl PeriAddress for AES_OUT {
393393
fn address(&self) -> u32 {
394-
unsafe { &(*pac::AES::ptr()).doutr as *const _ as u32 }
394+
unsafe { (*pac::AES::ptr()).doutr.as_ptr() as u32 }
395395
}
396396
type MemSize = u32;
397397
}
@@ -404,14 +404,14 @@ pub struct CRYP_OUT(());
404404
#[cfg(feature = "cryp")]
405405
unsafe impl PeriAddress for CRYP_IN {
406406
fn address(&self) -> u32 {
407-
unsafe { &(*pac::CRYP::ptr()).din as *const _ as u32 }
407+
unsafe { (*pac::CRYP::ptr()).din.as_ptr() as u32 }
408408
}
409409
type MemSize = u32;
410410
}
411411
#[cfg(feature = "cryp")]
412412
unsafe impl PeriAddress for CRYP_OUT {
413413
fn address(&self) -> u32 {
414-
unsafe { &(*pac::CRYP::ptr()).dout as *const _ as u32 }
414+
unsafe { (*pac::CRYP::ptr()).dout.as_ptr() as u32 }
415415
}
416416
type MemSize = u32;
417417
}

src/dma/traits/f4.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ mod dfsdm1 {
390390
unsafe impl<const F: u8> PeriAddress for FLT<DFSDM1, F> {
391391
#[inline(always)]
392392
fn address(&self) -> u32 {
393-
unsafe { &(*DFSDM1::ptr()).flt[F as usize].rdatar as *const _ as u32 }
393+
unsafe { (*DFSDM1::ptr()).flt[F as usize].rdatar.as_ptr() as u32 }
394394
}
395395
396396
type MemSize = u32;
@@ -412,7 +412,7 @@ dma_map!(
412412
unsafe impl<const F: u8> PeriAddress for FLT<pac::DFSDM2, F> {
413413
#[inline(always)]
414414
fn address(&self) -> u32 {
415-
unsafe { &(*DFSDM2::ptr()).flt[F as usize].rdatar as *const _ as u32 }
415+
unsafe { (*DFSDM2::ptr()).flt[F as usize].rdatar.as_ptr() as u32 }
416416
}
417417
418418
type MemSize = u32;
@@ -484,7 +484,7 @@ mod sai1 {
484484
unsafe impl<const C: u8> PeriAddress for SAICH<SAI1, C> {
485485
#[inline(always)]
486486
fn address(&self) -> u32 {
487-
unsafe { &(*SAI1::ptr()).ch[C as usize].dr as *const _ as u32 }
487+
unsafe { (*SAI1::ptr()).ch[C as usize].dr.as_ptr() as u32 }
488488
}
489489

490490
type MemSize = u32;
@@ -501,7 +501,7 @@ dma_map!(
501501
unsafe impl<const C: u8> PeriAddress for SAICH<pac::SAI2, C> {
502502
#[inline(always)]
503503
fn address(&self) -> u32 {
504-
unsafe { &(*pac::SAI2::ptr()).ch[C as usize].dr as *const _ as u32 }
504+
unsafe { (*pac::SAI2::ptr()).ch[C as usize].dr.as_ptr() as u32 }
505505
}
506506

507507
type MemSize = u32;

src/i2c/dma.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ pub struct Rx<I2C> {
890890
unsafe impl<I2C: Instance> PeriAddress for Rx<I2C> {
891891
#[inline(always)]
892892
fn address(&self) -> u32 {
893-
unsafe { &(*I2C::ptr()).dr as *const _ as u32 }
893+
unsafe { (*I2C::ptr()).dr.as_ptr() as u32 }
894894
}
895895

896896
type MemSize = u8;
@@ -899,7 +899,7 @@ unsafe impl<I2C: Instance> PeriAddress for Rx<I2C> {
899899
unsafe impl<I2C: Instance> PeriAddress for Tx<I2C> {
900900
#[inline(always)]
901901
fn address(&self) -> u32 {
902-
unsafe { &(*I2C::ptr()).dr as *const _ as u32 }
902+
unsafe { (*I2C::ptr()).dr.as_ptr() as u32 }
903903
}
904904

905905
type MemSize = u8;

src/rtc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,9 @@ impl<CS> Rtc<CS> {
589589

590590
// TODO: remove unsafe after PAC update
591591
let tr = &self.regs.tstr;
592-
let tr = unsafe { (*(tr as *const _ as *const TR)).read() };
592+
let tr = unsafe { (*(tr.as_ptr() as *const TR)).read() };
593593
let dr = &self.regs.tsdr;
594-
let dr = unsafe { (*(dr as *const _ as *const DR)).read() };
594+
let dr = unsafe { (*(dr.as_ptr() as *const DR)).read() };
595595
let dry = self.regs.dr.read();
596596
let seconds = decode_seconds(&tr);
597597
let minutes = decode_minutes(&tr);

src/serial/uart_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ macro_rules! uartCommon {
315315
}
316316

317317
fn peri_address(&self) -> u32 {
318-
&self.dr as *const _ as u32
318+
self.dr.as_ptr() as u32
319319
}
320320
}
321321
};

src/spi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ impl<SPI: Instance> DmaBuilder<SPI> {
899899
unsafe impl<SPI: Instance> PeriAddress for Rx<SPI> {
900900
#[inline(always)]
901901
fn address(&self) -> u32 {
902-
unsafe { &(*SPI::ptr()).dr as *const _ as u32 }
902+
unsafe { (*SPI::ptr()).dr.as_ptr() as u32 }
903903
}
904904

905905
type MemSize = u8;
@@ -913,7 +913,7 @@ unsafe impl<SPI, STREAM, const CHANNEL: u8> DMASet<STREAM, CHANNEL, PeripheralTo
913913
unsafe impl<SPI: Instance> PeriAddress for Tx<SPI> {
914914
#[inline(always)]
915915
fn address(&self) -> u32 {
916-
unsafe { &(*SPI::ptr()).dr as *const _ as u32 }
916+
unsafe { (*SPI::ptr()).dr.as_ptr() as u32 }
917917
}
918918

919919
type MemSize = u8;

src/timer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ macro_rules! hal {
567567
unsafe impl<const C: u8> PeriAddress for CCR<$TIM, C> {
568568
#[inline(always)]
569569
fn address(&self) -> u32 {
570-
&self.0.ccr[C as usize] as *const _ as u32
570+
self.0.ccr[C as usize].as_ptr() as u32
571571
}
572572

573573
type MemSize = $bits;
@@ -589,7 +589,7 @@ macro_rules! with_dmar {
589589
unsafe impl PeriAddress for DMAR<$TIM> {
590590
#[inline(always)]
591591
fn address(&self) -> u32 {
592-
&self.0.dmar as *const _ as u32
592+
self.0.dmar.as_ptr() as u32
593593
}
594594

595595
type MemSize = $memsize;

0 commit comments

Comments
 (0)