-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: add nezha-d1 example package
Signed-off-by: Zhouqi Jiang <[email protected]>
- Loading branch information
Showing
6 changed files
with
64 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "nezha-d1-example" | ||
version = "0.1.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
allwinner-hal = { path = "../.." } | ||
allwinner-rt = { path = "../../allwinner-rt" } | ||
panic-halt = "0.2.0" | ||
embedded-io = "0.6.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
println!("cargo:rustc-link-arg=-Tallwinner-rt.ld"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use allwinner_hal::uart::{Config, Serial}; | ||
use allwinner_rt::{entry, Clocks, Peripherals}; | ||
use embedded_io::{Read, Write}; | ||
use panic_halt as _; | ||
|
||
#[entry] | ||
fn main(p: Peripherals, c: Clocks) { | ||
let tx = p.gpio.pb8.into_function::<7>(); | ||
let rx = p.gpio.pb9.into_function::<7>(); | ||
let mut serial = Serial::new(p.uart0, (tx, rx), Config::default(), &c, &p.ccu); | ||
|
||
writeln!(serial, "Hello World!").ok(); | ||
|
||
let mut buf = [0u8; 64]; | ||
let mut cur = 0; | ||
|
||
writeln!(serial, "Please input your name (maximum 64 bytes):").unwrap(); | ||
write!(serial, "> ").unwrap(); | ||
loop { | ||
let mut ch = 0u8; | ||
let _len = serial.read(core::slice::from_mut(&mut ch)).unwrap(); | ||
if ch == b'\r' || ch == b'\n' { | ||
break; | ||
} | ||
buf[cur] = ch; | ||
cur += 1; | ||
if cur > buf.len() { | ||
break; | ||
} | ||
} | ||
|
||
let name = core::str::from_utf8(&buf).unwrap(); | ||
writeln!(serial, "Hello, {}!", name).unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#![no_std] |