Skip to content

Commit 9fdd678

Browse files
authored
Merge pull request #32 from luojia65/refactor/chip-rt
refactor(hal): move chip specific features from `hal` crate into `rt` crate
2 parents 8d59be4 + ce8e08c commit 9fdd678

File tree

28 files changed

+1436
-1276
lines changed

28 files changed

+1436
-1276
lines changed

allwinner-hal/Cargo.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,3 @@ uart16550 = "0.0.1"
2525
plic = "0.0.2"
2626
embedded-sdmmc = "0.9.0"
2727
log = "0.4"
28-
29-
[dev-dependencies]
30-
31-
[features]
32-
default = ["d1"]
33-
# D1-like chips: D1-H, D1s, F133.
34-
d1 = []

allwinner-hal/src/ccu.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,6 @@ pub use pll::{PllCpuControl, PllDdrControl, PllPeri0Control};
1111
pub use register::*;
1212
pub use source::{CpuClockSource, DramClockSource, SmhcClockSource, SpiClockSource};
1313

14-
use embedded_time::rate::Hertz;
15-
16-
/// Clock configuration on current SoC.
17-
#[derive(Debug)]
18-
pub struct Clocks {
19-
/// PSI clock frequency.
20-
pub psi: Hertz,
21-
/// Advanced Peripheral Bus 1 clock frequency.
22-
pub apb1: Hertz,
23-
}
24-
2514
/// Peripheral that have clock reset feature in CCU.
2615
pub trait ClockReset {
2716
/// Assert reset signal.

allwinner-hal/src/gpio/flex_pad.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use core::marker::PhantomData;
2+
3+
use super::Function;
4+
5+
pub struct FlexPad<'a> {
6+
_base: PhantomData<&'a super::RegisterBlock>,
7+
}
8+
9+
impl<'a, const P: char, const N: u8, const F: u8> From<Function<'a, P, N, F>> for FlexPad<'a> {
10+
#[inline]
11+
fn from(value: Function<'a, P, N, F>) -> Self {
12+
let _ = value;
13+
FlexPad { _base: PhantomData }
14+
}
15+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Allwinner GPIO controller.
22
mod eint;
3+
mod flex_pad;
34
mod function;
45
mod input;
56
mod mode;
@@ -8,6 +9,7 @@ mod pad_ext;
89
mod register;
910

1011
pub use eint::{EintPad, Event};
12+
pub use flex_pad::FlexPad;
1113
pub use function::Function;
1214
pub use input::Input;
1315
pub use output::Output;

allwinner-hal/src/lib.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,3 @@ pub mod prelude {
3131
};
3232
pub use embedded_io::{Read as _, Write as _};
3333
}
34-
35-
#[allow(unused)]
36-
macro_rules! impl_pins_trait {
37-
($(($p: expr_2021, $i: expr_2021, $f: expr_2021): $Trait: ty;)+) => {
38-
$(
39-
impl<'a> $Trait for $crate::gpio::Function<'a, $p, $i, $f> {}
40-
)+
41-
};
42-
}
43-
44-
/// SoC configurations on peripherals and interrupt contexts.
45-
pub mod wafer {
46-
pub mod d1;
47-
}

allwinner-hal/src/smhc.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! SD/MMC Host Controller peripheral.
22
33
mod register;
4+
use embedded_time::rate::Hertz;
45
pub use register::*;
56
mod pad;
67
pub use pad::*;
@@ -32,3 +33,7 @@ pub enum SdCardError {
3233
Unknown,
3334
UnexpectedResponse(u8, u128),
3435
}
36+
37+
pub trait Clock {
38+
fn smhc_clock(&self) -> Hertz;
39+
}

allwinner-hal/src/smhc/pad.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
use crate::gpio::FlexPad;
2+
13
/// Clock signal pad.
2-
pub trait Clk {}
4+
pub trait IntoClk<'a> {
5+
fn into_smhc_clk(self) -> FlexPad<'a>;
6+
}
37

48
/// Command signal pad.
5-
pub trait Cmd {}
9+
pub trait IntoCmd<'a> {
10+
fn into_smhc_cmd(self) -> FlexPad<'a>;
11+
}
612

713
/// Data input and output pad.
814
///
915
/// This is documented in the User Manual as `D[3:0]`.
10-
pub trait Data<const I: usize> {}
16+
pub trait IntoData<'a, const I: usize> {
17+
fn into_smhc_data(self) -> FlexPad<'a>;
18+
}

allwinner-hal/src/smhc/structure.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use super::{
44
AccessMode, BlockSize, BusWidth, CardType, Command, RegisterBlock, TransferDirection,
55
},
66
};
7-
use crate::ccu::{self, Clocks, SmhcClockSource};
7+
use crate::{
8+
ccu::{self, SmhcClockSource},
9+
smhc::Clock,
10+
};
811
use core::arch::asm;
912
use embedded_sdmmc::{Block, BlockDevice, BlockIdx};
1013

@@ -181,12 +184,12 @@ impl<SMHC: AsRef<RegisterBlock>, PADS> Smhc<SMHC, PADS> {
181184
pub fn new<const SMHC_IDX: usize>(
182185
smhc: SMHC,
183186
pads: PADS,
184-
clocks: &Clocks,
187+
clock: impl Clock,
185188
ccu: &ccu::RegisterBlock,
186189
) -> Self {
187190
let divider = 2;
188191
let (factor_n, factor_m) =
189-
ccu::calculate_best_peripheral_factors_nm(clocks.psi.0, 20_000_000);
192+
ccu::calculate_best_peripheral_factors_nm(clock.smhc_clock().0, 20_000_000);
190193
unsafe {
191194
smhc.as_ref()
192195
.clock_control

0 commit comments

Comments
 (0)