Eliminate the use of volatile-register crate
See related issue
https://github.com/rust-embedded/volatile-register/issues/10
Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: I395de4a119d5471297f0d39480e390f506e575b0
diff --git a/src/lib.rs b/src/lib.rs
index e58a839..cd2a7e6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -7,7 +7,10 @@
#![no_std]
-use core::{marker::PhantomData, ops::Deref};
+use core::{
+ marker::PhantomData,
+ ops::{Deref, DerefMut},
+};
use spin::mutex::Mutex;
@@ -21,7 +24,7 @@
}
impl UART0 {
- pub const PTR: *const PL011Registers = 0x1c09_0000 as *const _;
+ pub const PTR: *mut PL011Registers = 0x1c09_0000 as *mut _;
}
impl Deref for UART0 {
@@ -33,6 +36,13 @@
}
}
+impl DerefMut for UART0 {
+ #[inline(always)]
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ unsafe { &mut *Self::PTR }
+ }
+}
+
unsafe impl Send for UART0 {}
/// UART1 - PL011
@@ -41,7 +51,7 @@
}
impl UART1 {
- pub const PTR: *const PL011Registers = 0x1c0a_0000 as *const _;
+ pub const PTR: *mut PL011Registers = 0x1c0a_0000 as *mut _;
}
impl Deref for UART1 {
@@ -53,6 +63,13 @@
}
}
+impl DerefMut for UART1 {
+ #[inline(always)]
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ unsafe { &mut *Self::PTR }
+ }
+}
+
unsafe impl Send for UART1 {}
/// UART2 - PL011
@@ -61,7 +78,7 @@
}
impl UART2 {
- pub const PTR: *const PL011Registers = 0x1c0b_0000 as *const _;
+ pub const PTR: *mut PL011Registers = 0x1c0b_0000 as *mut _;
}
impl Deref for UART2 {
@@ -73,6 +90,13 @@
}
}
+impl DerefMut for UART2 {
+ #[inline(always)]
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ unsafe { &mut *Self::PTR }
+ }
+}
+
unsafe impl Send for UART2 {}
/// UART3 - PL011
@@ -81,7 +105,7 @@
}
impl UART3 {
- pub const PTR: *const PL011Registers = 0x1c0c_0000 as *const _;
+ pub const PTR: *mut PL011Registers = 0x1c0c_0000 as *mut _;
}
impl Deref for UART3 {
@@ -93,6 +117,13 @@
}
}
+impl DerefMut for UART3 {
+ #[inline(always)]
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ unsafe { &mut *Self::PTR }
+ }
+}
+
unsafe impl Send for UART3 {}
/// Watchdog - SP805
@@ -102,7 +133,7 @@
}
impl WATCHDOG {
- pub const PTR: *const SP805Registers = 0x1c0f_0000 as *const _;
+ pub const PTR: *mut SP805Registers = 0x1c0f_0000 as *mut _;
}
impl Deref for WATCHDOG {
@@ -114,6 +145,13 @@
}
}
+impl DerefMut for WATCHDOG {
+ #[inline(always)]
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ unsafe { &mut *Self::PTR }
+ }
+}
+
unsafe impl Send for WATCHDOG {}
/// GIC Distributor
@@ -123,7 +161,7 @@
}
impl GICD {
- pub const PTR: *const GICDRegisters = 0x2f00_0000 as *const _;
+ pub const PTR: *mut GICDRegisters = 0x2f00_0000 as *mut _;
}
impl Deref for GICD {
@@ -135,6 +173,13 @@
}
}
+impl DerefMut for GICD {
+ #[inline(always)]
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ unsafe { &mut *Self::PTR }
+ }
+}
+
unsafe impl Send for GICD {}
static PERIPHERALS_TAKEN: Mutex<bool> = Mutex::new(false);