From 00589b1a4c3b5d79942df8d37e625e7ee87a3fe2 Mon Sep 17 00:00:00 2001 From: Zhouqi Jiang Date: Thu, 26 Sep 2024 12:02:25 +0800 Subject: [PATCH 1/2] [rust] add documents for print macros, remove default members Signed-off-by: Zhouqi Jiang --- Cargo.toml | 1 - rust/src/macros.rs | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3c32010a..7887abb8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,3 @@ members = [ "rust/xtask", "board/100ask-d1-h-rs", ] -default-members = ["rust/xtask"] diff --git a/rust/src/macros.rs b/rust/src/macros.rs index d0422ed4..325bad22 100644 --- a/rust/src/macros.rs +++ b/rust/src/macros.rs @@ -10,6 +10,7 @@ pub struct Pads<'a> { }; } +/// Prints to the standard output. #[macro_export] macro_rules! print { ($($arg:tt)*) => { @@ -17,6 +18,7 @@ macro_rules! print { } } +/// Prints to the standard output, with a newline. #[macro_export] macro_rules! println { () => ($crate::print!("\r\n")); From 2f654b506d06a39f3c2e8fcdb08a41a03d8a0403 Mon Sep 17 00:00:00 2001 From: RenXiao Date: Thu, 26 Sep 2024 16:41:16 +0800 Subject: [PATCH 2/2] [rust] redesign the intermediate function signature generated by syterkit::entry Signed-off-by: RenXiao Tested-by: DongQing --- board/100ask-d1-h-rs/src/bin/hello-world.rs | 2 +- board/100ask-d1-h-rs/src/bin/init-dram.rs | 2 +- board/100ask-d1-h-rs/src/bin/led-lightup.rs | 2 +- board/100ask-d1-h-rs/src/main.rs | 2 +- rust/macros/src/lib.rs | 21 ++++++++------------- 5 files changed, 12 insertions(+), 17 deletions(-) diff --git a/board/100ask-d1-h-rs/src/bin/hello-world.rs b/board/100ask-d1-h-rs/src/bin/hello-world.rs index afef07b6..5b183594 100644 --- a/board/100ask-d1-h-rs/src/bin/hello-world.rs +++ b/board/100ask-d1-h-rs/src/bin/hello-world.rs @@ -5,6 +5,6 @@ use panic_halt as _; use syterkit::{entry, println, Clocks, Peripherals}; #[entry] -fn main(p: Peripherals, c: Clocks) { +fn main(_p: Peripherals, _c: Clocks) { println!("Hello World!"); } diff --git a/board/100ask-d1-h-rs/src/bin/init-dram.rs b/board/100ask-d1-h-rs/src/bin/init-dram.rs index 00d7dca5..571bee45 100644 --- a/board/100ask-d1-h-rs/src/bin/init-dram.rs +++ b/board/100ask-d1-h-rs/src/bin/init-dram.rs @@ -5,7 +5,7 @@ use panic_halt as _; use syterkit::{entry, mctl, println, Clocks, Peripherals}; #[entry] -fn main(p: Peripherals, c: Clocks) { +fn main(_p: Peripherals, _c: Clocks) { println!("DDR Init"); let ram_size = mctl::init(); println!("{}M 🐏", ram_size); diff --git a/board/100ask-d1-h-rs/src/bin/led-lightup.rs b/board/100ask-d1-h-rs/src/bin/led-lightup.rs index c7cb40d3..8443a5b9 100644 --- a/board/100ask-d1-h-rs/src/bin/led-lightup.rs +++ b/board/100ask-d1-h-rs/src/bin/led-lightup.rs @@ -6,7 +6,7 @@ use panic_halt as _; use syterkit::{entry, Clocks, Peripherals}; #[entry] -fn main(p: Peripherals, c: Clocks) { +fn main(p: Peripherals, _c: Clocks) { // light up led let mut pb5 = p.gpio.pb5.into_output(); pb5.set_high().unwrap(); diff --git a/board/100ask-d1-h-rs/src/main.rs b/board/100ask-d1-h-rs/src/main.rs index e5f31f65..0197d57d 100644 --- a/board/100ask-d1-h-rs/src/main.rs +++ b/board/100ask-d1-h-rs/src/main.rs @@ -5,7 +5,7 @@ use panic_halt as _; use syterkit::{clock_dump, entry, println, show_banner, Clocks, Peripherals}; #[entry] -fn main(p: Peripherals, c: Clocks) { +fn main(p: Peripherals, _c: Clocks) { // Display the bootloader banner. show_banner(); diff --git a/rust/macros/src/lib.rs b/rust/macros/src/lib.rs index 408f8fb2..e4e5b83d 100644 --- a/rust/macros/src/lib.rs +++ b/rust/macros/src/lib.rs @@ -77,23 +77,18 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { quote!( #[export_name = "main"] pub fn main() { - 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) } + let (allwinner_rt_p, c) = ::syterkit::allwinner_rt::__rom_init_params(); + let (p, uart0, tx, rx) = ::syterkit::Peripherals::configure_uart0(allwinner_rt_p); + let mut serial = ::syterkit::allwinner_hal::uart::Serial::new(uart0, (tx, rx), ::syterkit::allwinner_hal::uart::Config::default(), &c, &p.ccu); + unsafe { + *::syterkit::CONSOLE.lock() = Some(::syterkit::SyterKitConsole { inner: serial }) + }; + unsafe { __syterkit_macros__main(p, c) } } #[allow(non_snake_case)] #[inline] #(#attrs)* - #unsafety fn __syterkit_macros__main( - #args, - __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 = ::syterkit::allwinner_hal::uart::Serial::new(__uart0, (__tx, __rx), ::syterkit::allwinner_hal::uart::Config::default(), &c, &p.ccu); - unsafe { - *::syterkit::CONSOLE.lock() = Some(::syterkit::SyterKitConsole { inner: __serial }) - }; + #unsafety fn __syterkit_macros__main(#args) #ret { #(#stmts)* } )