Skip to content

Commit

Permalink
Merge pull request #131 from luojia65/luojia65/refactor
Browse files Browse the repository at this point in the history
[rust] refactor, move common rust parts from 100ask-d1-h to rust module
  • Loading branch information
luojia65 authored Sep 25, 2024
2 parents 8baa3e5 + 6869e85 commit 8751b29
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[alias]
xtask = "run --package xtask --release --"
xtask = "run --package syterkit-xtask --release --"
make = "xtask make"
flash = "xtask flash"
42 changes: 25 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[workspace]
resolver = "2"
members = [
"rust",
"rust/macros",
"rust/xtask",
"board/100ask-d1-h-rs",
"board/100ask-d1-h-rs/macros",
"board/100ask-d1-h-rs/xtask",
]
default-members = ["board/100ask-d1-h-rs/xtask"]
default-members = ["rust/xtask"]
20 changes: 4 additions & 16 deletions board/100ask-d1-h-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,17 @@ cargo-features = ["per-package-target"]

[package]
name = "syterkit-100ask-d1-h"
version = "0.1.0"
version = "0.0.0"
edition = "2021"
default-target = "riscv64imac-unknown-none-elf"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
naked-function = "0.1.5"
panic-halt = "0.2.0"
allwinner-hal = { git = "https://github.com/rustsbi/allwinner-hal" }
allwinner-rt = { git = "https://github.com/rustsbi/allwinner-hal" }
embedded-hal = "1.0.0"
embedded-io = "0.6.1"
spin = "0.9"
syterkit-macros = { path = "macros" }
syterkit = { path = "../../rust" }

[lib]
name = "syterkit_100ask_d1_h"
[[bin]]
name = "syterkit-100ask-d1-h"
test = false
bench = false

Expand All @@ -37,8 +30,3 @@ bench = false
name = "led-lightup"
test = false
bench = false

[features]
default = ["nezha"]
nezha = []
lichee = []
2 changes: 1 addition & 1 deletion board/100ask-d1-h-rs/src/bin/hello-world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![no_main]

use panic_halt as _;
use syterkit_100ask_d1_h::{entry, println, Clocks, Peripherals};
use syterkit::{entry, println, Clocks, Peripherals};

#[entry]
fn main(p: Peripherals, c: Clocks) {
Expand Down
3 changes: 2 additions & 1 deletion board/100ask-d1-h-rs/src/bin/init-dram.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#![no_std]
#![no_main]

use panic_halt as _;
use syterkit_100ask_d1_h::{entry, mctl, println, Clocks, Peripherals};
use syterkit::{entry, mctl, println, Clocks, Peripherals};

#[entry]
fn main(p: Peripherals, c: Clocks) {
Expand Down
2 changes: 1 addition & 1 deletion board/100ask-d1-h-rs/src/bin/led-lightup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use embedded_hal::digital::{InputPin, OutputPin};
use panic_halt as _;
use syterkit_100ask_d1_h::{entry, Clocks, Peripherals};
use syterkit::{entry, Clocks, Peripherals};

#[entry]
fn main(p: Peripherals, c: Clocks) {
Expand Down
11 changes: 11 additions & 0 deletions board/100ask-d1-h-rs/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![no_std]
#![no_main]

use panic_halt as _;
use syterkit::{entry, println, Clocks, Peripherals};

#[entry]
fn main(p: Peripherals, c: Clocks) {
println!("Welcome to SyterKit 100ask-d1-h package!");
println!("Please refer to each files in `bin` path for examples.");
}
28 changes: 28 additions & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cargo-features = ["per-package-target"]

[package]
name = "syterkit"
version = "0.0.0"
edition = "2021"
default-target = "riscv64imac-unknown-none-elf"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
naked-function = "0.1.5"
allwinner-hal = { git = "https://github.com/rustsbi/allwinner-hal" }
allwinner-rt = { git = "https://github.com/rustsbi/allwinner-hal" }
embedded-hal = "1.0.0"
embedded-io = "0.6.1"
spin = "0.9"
syterkit-macros = { path = "macros" }

[lib]
name = "syterkit"
test = false
bench = false

[features]
default = ["nezha"]
nezha = []
lichee = []
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,22 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
quote!(
#[export_name = "main"]
pub fn main() {
let (p, c) = ::allwinner_rt::__rom_init_params();
let (__p, __uart0, __tx, __rx) = ::syterkit_100ask_d1_h::Peripherals::configure_uart0(p);
let (p, c) = ::syterkit::allwinner_rt::__rom_init_params();
let (__p, __uart0, __tx, __rx) = ::syterkit::Peripherals::configure_uart0(p);
unsafe { __syterkit_macros__main(__p, c, __uart0, __tx, __rx) }
}
#[allow(non_snake_case)]
#[inline]
#(#attrs)*
#unsafety fn __syterkit_macros__main(
#args,
__uart0: ::allwinner_rt::soc::d1::UART0,
__tx: ::allwinner_hal::gpio::Function<'static, 'B', 8, 6>,
__rx: ::allwinner_hal::gpio::Function<'static, 'B', 9, 6>
__uart0: ::syterkit::allwinner_rt::soc::d1::UART0,
__tx: ::syterkit::allwinner_hal::gpio::Function<'static, 'B', 8, 6>,
__rx: ::syterkit::allwinner_hal::gpio::Function<'static, 'B', 9, 6>
) #ret {
let mut __serial = ::allwinner_hal::uart::Serial::new(__uart0, (__tx, __rx), ::allwinner_hal::uart::Config::default(), &c, &p.ccu);
let mut __serial = ::syterkit::allwinner_hal::uart::Serial::new(__uart0, (__tx, __rx), ::syterkit::allwinner_hal::uart::Config::default(), &c, &p.ccu);
unsafe {
*::syterkit_100ask_d1_h::CONSOLE.lock() = Some(::syterkit_100ask_d1_h::SyterKitConsole { inner: __serial })
*::syterkit::CONSOLE.lock() = Some(::syterkit::SyterKitConsole { inner: __serial })
};
#(#stmts)*
}
Expand Down
4 changes: 4 additions & 0 deletions board/100ask-d1-h-rs/src/lib.rs → rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,7 @@ impl_gpio_pins! {
pg17: ('G', 17, Disabled);
pg18: ('G', 18, Disabled);
}

// macro internal code.
#[doc(hidden)]
pub use {allwinner_hal, allwinner_rt};
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "xtask"
name = "syterkit-xtask"
version = "0.1.0"
edition = "2021"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ fn xtask_build_d1_flash_bt0(env: &Env, bin: &str) {
trace!("found cargo at {}", cargo);
let mut command = Command::new(cargo);
command.current_dir(project_root());
trace!("cargo current dir: {:?}", project_root());
command.arg("build");
command.arg("-p");
command.arg("syterkit-100ask-d1-h");
Expand Down Expand Up @@ -265,7 +266,7 @@ fn find_binutils_prefix_or_fail() -> &'static str {
fn project_root() -> PathBuf {
Path::new(&env!("CARGO_MANIFEST_DIR"))
.ancestors()
.nth(3)
.nth(2)
.unwrap()
.to_path_buf()
}
Expand Down

0 comments on commit 8751b29

Please sign in to comment.