Skip to content

Commit 3cb2102

Browse files
author
Dániel Buga
committed
Stylistic updates, add from_bits
1 parent 513ffd4 commit 3cb2102

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/register/fpscr.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ pub enum RMode {
2121
}
2222

2323
impl Fpscr {
24+
/// Creates a `Fspcr` value from raw bits.
25+
#[inline]
26+
pub fn from_bits(bits: u32) -> Self {
27+
Self { bits }
28+
}
29+
2430
/// Returns the contents of the register as raw bits
2531
#[inline]
2632
pub fn bits(self) -> u32 {
@@ -118,6 +124,7 @@ impl Fpscr {
118124
}
119125

120126
/// Read the FPSCR register
127+
#[inline]
121128
pub fn read() -> Fpscr {
122129
match () {
123130
#[cfg(all(cortex_m, feature = "inline-asm"))]
@@ -126,16 +133,15 @@ pub fn read() -> Fpscr {
126133
unsafe {
127134
llvm_asm!("vmrs $0, fpscr" : "=r"(r) ::: "volatile");
128135
}
129-
Fpscr { bits: r }
136+
Fpscr::from_bits(r)
130137
}
131138

132139
#[cfg(all(cortex_m, not(feature = "inline-asm")))]
133140
() => unsafe {
134141
extern "C" {
135142
fn __get_FPSCR() -> u32;
136143
}
137-
138-
Fpscr { bits: __get_FPSCR() }
144+
Fpscr::from_bits(__get_FPSCR())
139145
},
140146

141147
#[cfg(not(cortex_m))]
@@ -144,23 +150,23 @@ pub fn read() -> Fpscr {
144150
}
145151

146152
/// Set the value of the FPSCR register
147-
pub unsafe fn write(value: u32) {
153+
#[inline]
154+
pub unsafe fn write(_fspcr: Fpscr) {
148155
match () {
149156
#[cfg(all(cortex_m, feature = "inline-asm"))]
150157
() => {
151-
unsafe {
152-
llvm_asm!("vmsr fpscr, $0" :: "r"(value) :: "volatile");
153-
}
158+
let bits = _fspcr.bits();
159+
llvm_asm!("vmsr fpscr, $0" :: "r"(bits) :: "volatile");
154160
}
155161

156162
#[cfg(all(cortex_m, not(feature = "inline-asm")))]
157-
() => unsafe {
163+
() => {
158164
extern "C" {
159-
fn __set_FPSCR(value: u32);
165+
fn __set_FPSCR(bits: u32);
160166
}
161167

162-
__set_FPSCR(value);
163-
},
168+
__set_FPSCR(_fspcr.bits());
169+
}
164170

165171
#[cfg(not(cortex_m))]
166172
() => unimplemented!(),

0 commit comments

Comments
 (0)