Skip to content

Commit c063173

Browse files
authored
refactor: format code and remove dependency onmemoffset (#19)
* style: format code and adjust indentation Signed-off-by: Longbing Zheng <1211998648@qq.com> * build(deps): remove dependency on memoffset Signed-off-by: Longbing Zheng <1211998648@qq.com> --------- Signed-off-by: Longbing Zheng <1211998648@qq.com>
2 parents 3853475 + 58677ea commit c063173

File tree

9 files changed

+37
-29
lines changed

9 files changed

+37
-29
lines changed

allwinner-hal/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ plic = "0.0.2"
2626
embedded-sdmmc = "0.8.1"
2727

2828
[dev-dependencies]
29-
memoffset = "0.8"
3029

3130
[features]
3231
default = ["d1"]

allwinner-hal/src/ccu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ mod tests {
812812
AxiFactorN, CpuAxiConfig, CpuClockSource, DramBusGating, DramClock, DramClockSource,
813813
FactorP, MbusClock, PeriFactorN, RegisterBlock,
814814
};
815-
use memoffset::offset_of;
815+
use core::mem::offset_of;
816816
#[test]
817817
fn offset_ccu() {
818818
assert_eq!(offset_of!(RegisterBlock, pll_cpu_control), 0x0);

allwinner-hal/src/com.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl RegisterBlock {
102102
#[cfg(test)]
103103
mod tests {
104104
use super::RegisterBlock;
105-
use memoffset::offset_of;
105+
use core::mem::offset_of;
106106
#[test]
107107
fn offset_com() {
108108
assert_eq!(offset_of!(RegisterBlock, tmr), 0x0c);

allwinner-hal/src/gpio/register.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub struct PioPow {
5555
#[cfg(test)]
5656
mod tests {
5757
use super::{Eint, PioPow, Port, RegisterBlock};
58-
use memoffset::offset_of;
58+
use core::mem::offset_of;
5959

6060
#[test]
6161
fn offset_gpio() {

allwinner-hal/src/phy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl RegisterBlock {
129129
#[cfg(test)]
130130
mod tests {
131131
use super::{Datx8, RegisterBlock};
132-
use memoffset::offset_of;
132+
use core::mem::offset_of;
133133
#[test]
134134
fn offset_phy() {
135135
assert_eq!(offset_of!(RegisterBlock, lp3mr11), 0x2c);

allwinner-hal/src/smhc/register.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ mod tests {
10541054
Interrupt, InterruptMask, InterruptStateMasked, InterruptStateRaw, NewTimingSet,
10551055
NtsTimingPhase, RegisterBlock, Status, TimeOut, TransferDirection,
10561056
};
1057-
use memoffset::offset_of;
1057+
use core::mem::offset_of;
10581058
#[test]
10591059
fn offset_smhc() {
10601060
assert_eq!(offset_of!(RegisterBlock, global_control), 0x0);

allwinner-hal/src/spi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ impl<SPI: AsRef<RegisterBlock>, const I: usize, PINS: Pins<I>> embedded_hal::spi
479479
#[cfg(test)]
480480
mod tests {
481481
use super::RegisterBlock;
482-
use memoffset::offset_of;
482+
use core::mem::offset_of;
483483
#[test]
484484
fn offset_spi0() {
485485
assert_eq!(offset_of!(RegisterBlock, ier), 0x10);

allwinner-hal/src/uart.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ impl UartStatus {
380380
#[cfg(test)]
381381
mod tests {
382382
use super::RegisterBlock;
383-
use memoffset::offset_of;
383+
use core::mem::offset_of;
384384
#[test]
385385
fn offset_uart() {
386386
assert_eq!(offset_of!(RegisterBlock, usr), 0x7c);

allwinner-rt/src/macros.rs

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
11
macro_rules! soc {
2-
($($(#[$doc:meta])* pub struct $Ty: ident => $paddr: expr_2021$(, $DerefTy: ty)+;)+) => {
2+
(
33
$(
4-
$(#[$doc])*
5-
#[allow(non_camel_case_types)]
6-
pub struct $Ty {
7-
_private: (),
8-
}
9-
$(
10-
impl core::ops::Deref for $Ty {
11-
type Target = $DerefTy;
12-
#[inline(always)]
13-
fn deref(&self) -> &Self::Target {
14-
unsafe { &*($paddr as *const _) }
15-
}
16-
}
17-
impl core::convert::AsRef<$DerefTy> for $Ty {
18-
#[inline(always)]
19-
fn as_ref(&self) -> &$DerefTy {
20-
unsafe { &*($paddr as *const _) }
21-
}
22-
}
23-
)+
4+
$(#[$doc:meta])*
5+
pub struct $Ty:ident => $paddr:expr_2021
6+
$(, $DerefTy:ty)+ ;
7+
)+
8+
) => {
9+
$(
10+
$(#[$doc])*
11+
#[allow(non_camel_case_types)]
12+
pub struct $Ty {
13+
_private: (),
14+
}
15+
16+
$(
17+
impl core::ops::Deref for $Ty {
18+
type Target = $DerefTy;
19+
20+
#[inline(always)]
21+
fn deref(&self) -> &Self::Target {
22+
unsafe { &*($paddr as *const _) }
23+
}
24+
}
25+
26+
impl core::convert::AsRef<$DerefTy> for $Ty {
27+
#[inline(always)]
28+
fn as_ref(&self) -> &$DerefTy {
29+
unsafe { &*($paddr as *const _) }
30+
}
31+
}
32+
)+
2433
)+
2534
};
2635
}

0 commit comments

Comments
 (0)