diff --git a/rust/Cargo.toml b/rust/Cargo.toml index a021e88..9694544 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -14,4 +14,4 @@ members = [ [patch.crates-io] riscv-rt = { git = "https://github.com/rust-embedded/riscv-rt.git", rev = "e9bb7e0964aea781f1121cee82dd55098a4b43e8"} k210-pac = { git = "https://github.com/riscv-rust/k210-pac.git", rev = "e2473456cd72198867056b80d408ad0a40edb969"} -k210-hal = { git = "https://github.com/riscv-rust/k210-hal.git", rev = "25c4e12af65f6e0d3e68c0c9227ad7f444f90e3e" } +k210-hal = { git = "https://github.com/riscv-rust/k210-hal.git", rev = "b83e843c19a2f0bc4eb7f56322ae844818709298" } diff --git a/rust/accelerometer/src/main.rs b/rust/accelerometer/src/main.rs index 639929a..6c1a692 100644 --- a/rust/accelerometer/src/main.rs +++ b/rust/accelerometer/src/main.rs @@ -4,7 +4,7 @@ #![no_std] #![no_main] -use k210_hal::pac; +use k210_hal::Peripherals; use k210_hal::prelude::*; use k210_hal::stdout::Stdout; use k210_shared::board::def::{io,DISP_WIDTH,DISP_HEIGHT,MSA300_SLV_ADDR,MSA300_ADDR_BITS,MSA300_CLK}; @@ -56,14 +56,14 @@ fn sample_cirle(x: i32, y: i32, cx: i32, cy: i32, r: i32, rr: i32) -> bool { #[entry] fn main() -> ! { - let p = pac::Peripherals::take().unwrap(); + let p = Peripherals::take().unwrap(); let clocks = k210_hal::clock::Clocks::new(); usleep(200000); // Configure UART - let serial = p.UARTHS.constrain(115_200.bps(), &clocks); + let serial = p.UARTHS.configure((p.pins.pin5, p.pins.pin4), 115_200.bps(), &clocks); let (mut tx, _) = serial.split(); let mut stdout = Stdout(&mut tx); diff --git a/rust/dvp-ov/src/main.rs b/rust/dvp-ov/src/main.rs index 9bed08d..14e678b 100644 --- a/rust/dvp-ov/src/main.rs +++ b/rust/dvp-ov/src/main.rs @@ -4,7 +4,7 @@ #![no_std] #![no_main] -use k210_hal::pac; +use k210_hal::Peripherals; use k210_hal::prelude::*; use k210_hal::stdout::Stdout; use k210_shared::board::def::{io,DISP_WIDTH,DISP_HEIGHT}; @@ -58,13 +58,13 @@ fn io_init() { #[entry] fn main() -> ! { - let p = pac::Peripherals::take().unwrap(); + let p = Peripherals::take().unwrap(); let clocks = k210_hal::clock::Clocks::new(); usleep(200000); // Configure UART - let serial = p.UARTHS.constrain(115_200.bps(), &clocks); + let serial = p.UARTHS.configure((p.pins.pin5, p.pins.pin4), 115_200.bps(), &clocks); let (mut tx, _) = serial.split(); let mut stdout = Stdout(&mut tx); diff --git a/rust/game-of-life/src/main.rs b/rust/game-of-life/src/main.rs index df38220..5e3c031 100644 --- a/rust/game-of-life/src/main.rs +++ b/rust/game-of-life/src/main.rs @@ -4,7 +4,7 @@ #![no_std] #![no_main] -use k210_hal::pac; +use k210_hal::Peripherals; use k210_hal::prelude::*; use k210_hal::stdout::Stdout; use k210_shared::board::def::{io,DISP_WIDTH,DISP_HEIGHT,NS2009_SLV_ADDR,NS2009_CAL,NS2009_ADDR_BITS,NS2009_CLK}; @@ -139,14 +139,14 @@ pub static BLOCK_SPRITE: [[u32; 4];8] = [ #[entry] fn main() -> ! { - let p = pac::Peripherals::take().unwrap(); + let p = Peripherals::take().unwrap(); let clocks = k210_hal::clock::Clocks::new(); usleep(200000); // Configure UART - let serial = p.UARTHS.constrain(115_200.bps(), &clocks); + let serial = p.UARTHS.configure((p.pins.pin5, p.pins.pin4), 115_200.bps(), &clocks); let (mut tx, _) = serial.split(); let mut stdout = Stdout(&mut tx); diff --git a/rust/glyph-mapping/src/main.rs b/rust/glyph-mapping/src/main.rs index bd06e9c..da4b5bd 100644 --- a/rust/glyph-mapping/src/main.rs +++ b/rust/glyph-mapping/src/main.rs @@ -6,7 +6,7 @@ use k210_console::console::{Console, ScreenImage}; use k210_console::cp437_8x8::GLYPH_BY_FILL; -use k210_hal::pac; +use k210_hal::Peripherals; use k210_hal::prelude::*; use k210_hal::stdout::Stdout; use k210_shared::board::def::{io,DISP_WIDTH,DISP_HEIGHT}; @@ -68,13 +68,13 @@ fn io_init() { #[entry] fn main() -> ! { - let p = pac::Peripherals::take().unwrap(); + let p = Peripherals::take().unwrap(); let clocks = k210_hal::clock::Clocks::new(); usleep(200000); // Configure UART - let serial = p.UARTHS.constrain(115_200.bps(), &clocks); + let serial = p.UARTHS.configure((p.pins.pin5, p.pins.pin4), 115_200.bps(), &clocks); let (mut tx, _) = serial.split(); let mut stdout = Stdout(&mut tx); diff --git a/rust/k210-console/src/main.rs b/rust/k210-console/src/main.rs index bf5d5ee..43109c4 100644 --- a/rust/k210-console/src/main.rs +++ b/rust/k210-console/src/main.rs @@ -6,7 +6,7 @@ mod lfsr; -use k210_hal::pac; +use k210_hal::Peripherals; use k210_hal::prelude::*; use k210_hal::stdout::Stdout; use k210_shared::board::def::io; @@ -44,7 +44,7 @@ fn io_set_power() { #[entry] fn main() -> ! { - let p = pac::Peripherals::take().unwrap(); + let p = Peripherals::take().unwrap(); // Configure clocks (TODO) let clocks = k210_hal::clock::Clocks::new(); @@ -53,7 +53,7 @@ fn main() -> ! { usleep(200000); // Configure UART - let serial = p.UARTHS.constrain(115_200.bps(), &clocks); + let serial = p.UARTHS.configure((p.pins.pin5, p.pins.pin4), 115_200.bps(), &clocks); let (mut tx, _) = serial.split(); let mut stdout = Stdout(&mut tx); diff --git a/rust/k210-shared/src/panic.rs b/rust/k210-shared/src/panic.rs index 9ed5aa9..b38915d 100644 --- a/rust/k210-shared/src/panic.rs +++ b/rust/k210-shared/src/panic.rs @@ -1,5 +1,5 @@ /** Panic handler: based on ARM panic-itm */ -use k210_hal::pac; +use k210_hal::Peripherals; use k210_hal::prelude::*; use k210_hal::stdout::Stdout; use core::panic::PanicInfo; @@ -10,9 +10,9 @@ use core::sync::atomic::{self, Ordering}; fn panic(info: &PanicInfo) -> ! { // Stealing all peripherals, re-initializing the clocks and serial seems overkill here, but // also, can we really know the state? - let p = unsafe { pac::Peripherals::steal() }; + let p = unsafe { Peripherals::steal() }; let clocks = k210_hal::clock::Clocks::new(); - let serial = p.UARTHS.constrain(115_200.bps(), &clocks); + let serial = p.UARTHS.configure((p.pins.pin5, p.pins.pin4), 115_200.bps(), &clocks); let (mut tx, _) = serial.split(); let mut stdout = Stdout(&mut tx); writeln!(stdout, "{}", info).unwrap(); diff --git a/rust/mandelbrot/src/main.rs b/rust/mandelbrot/src/main.rs index be93e1a..0a80c74 100644 --- a/rust/mandelbrot/src/main.rs +++ b/rust/mandelbrot/src/main.rs @@ -6,7 +6,7 @@ mod palette; -use k210_hal::pac; +use k210_hal::Peripherals; use k210_hal::prelude::*; use k210_hal::stdout::Stdout; use k210_shared::board::def::{io,DISP_WIDTH,DISP_HEIGHT}; @@ -53,7 +53,7 @@ fn mandelbrot(cx: f32, cy: f32, iterations: u32) -> u32 { #[entry] fn main() -> ! { - let p = pac::Peripherals::take().unwrap(); + let p = Peripherals::take().unwrap(); // Configure clocks (TODO) let clocks = k210_hal::clock::Clocks::new(); @@ -61,7 +61,7 @@ fn main() -> ! { usleep(200000); // Configure UART - let serial = p.UARTHS.constrain(115_200.bps(), &clocks); + let serial = p.UARTHS.configure((p.pins.pin5, p.pins.pin4), 115_200.bps(), &clocks); let (mut tx, _) = serial.split(); let mut stdout = Stdout(&mut tx); diff --git a/rust/rgbcontrol/src/main.rs b/rust/rgbcontrol/src/main.rs index bbd0992..8ff50bb 100644 --- a/rust/rgbcontrol/src/main.rs +++ b/rust/rgbcontrol/src/main.rs @@ -5,7 +5,7 @@ #![no_main] use core::cmp::{min,max}; -use k210_hal::pac; +use k210_hal::Peripherals; use k210_hal::prelude::*; use k210_hal::stdout::Stdout; use k210_shared::board::def::{ @@ -67,12 +67,12 @@ fn color_from_xy(x: u16, y: u16, v: f32) -> (f32, f32, f32) { #[entry] fn main() -> ! { - let p = pac::Peripherals::take().unwrap(); + let p = Peripherals::take().unwrap(); let clocks = k210_hal::clock::Clocks::new(); usleep(200000); - let serial = p.UARTHS.constrain(115_200.bps(), &clocks); + let serial = p.UARTHS.configure((p.pins.pin5, p.pins.pin4), 115_200.bps(), &clocks); let (mut tx, _) = serial.split(); let mut stdout = Stdout(&mut tx); diff --git a/rust/uart-passthrough/src/main.rs b/rust/uart-passthrough/src/main.rs index 71f3666..ed8c1fa 100644 --- a/rust/uart-passthrough/src/main.rs +++ b/rust/uart-passthrough/src/main.rs @@ -4,8 +4,9 @@ #![no_std] #![no_main] -use k210_hal::pac; +use k210_hal::Peripherals; use k210_hal::prelude::*; +use k210_hal::serial::Serial; use k210_shared::board::def::io; use k210_shared::soc::fpioa; use k210_shared::soc::gpio; @@ -19,23 +20,21 @@ const DEFAULT_BAUD: u32 = 115_200; #[entry] fn main() -> ! { - let p = pac::Peripherals::take().unwrap(); + let p = Peripherals::take().unwrap(); let clocks = k210_hal::clock::Clocks::new(); // Configure UARTHS (→host) - let mut serial = p.UARTHS.constrain(DEFAULT_BAUD.bps(), &clocks); + let mut serial = p.UARTHS.configure((p.pins.pin5, p.pins.pin4), DEFAULT_BAUD.bps(), &clocks); let (mut tx, mut rx) = serial.split(); // Configure UART1 (→WIFI) sysctl::clock_enable(sysctl::clock::UART1); sysctl::reset(sysctl::reset::UART1); - fpioa::set_function(io::WIFI_RX, fpioa::function::UART1_TX); - fpioa::set_function(io::WIFI_TX, fpioa::function::UART1_RX); fpioa::set_function(io::WIFI_EN, fpioa::function::GPIOHS8); fpioa::set_io_pull(io::WIFI_EN, fpioa::pull::DOWN); gpiohs::set_pin(8, true); gpiohs::set_direction(8, gpio::direction::OUTPUT); - let mut wifi_serial = p.UART1.constrain(DEFAULT_BAUD.bps(), &clocks); + let mut wifi_serial = p.UART1.configure((p.pins.pin7, p.pins.pin6), DEFAULT_BAUD.bps(), &clocks); let (mut wtx, mut wrx) = wifi_serial.split(); // Relay characters between UARTs @@ -44,7 +43,8 @@ fn main() -> ! { // OOB restores safe baudrate for UARTHS, to be sure we're able to recover from // sync failures let mut rate = DEFAULT_BAUD; - serial = rx.join(tx).free().constrain(rate.bps(), &clocks); + let (userial, pins) = Serial::join(tx, rx).free(); + serial = userial.configure(pins, rate.bps(), &clocks); let s = serial.split(); tx = s.0; rx = s.1; @@ -55,8 +55,9 @@ fn main() -> ! { d.iter_mut().for_each(|x| { *x = block!(rx.read()).unwrap() }); rate = (d[0] as u32) | ((d[1] as u32) << 8) | ((d[2] as u32) << 16) | ((d[3] as u32) << 24); - // re-constrain UARTHS at new rate - serial = rx.join(tx).free().constrain(rate.bps(), &clocks); + // re-configure UARTHS at new rate + let (userial, pins) = Serial::join(tx, rx).free(); + serial = userial.configure(pins, rate.bps(), &clocks); let s = serial.split(); tx = s.0; rx = s.1; @@ -68,8 +69,9 @@ fn main() -> ! { } _ => {} } - // re-constrain UART1 - wifi_serial = wrx.join(wtx).free().constrain(rate.bps(), &clocks); + // re-configure UART1 + let (wifi_userial, wifi_pins) = Serial::join(wtx, wrx).free(); + wifi_serial = wifi_userial.configure(wifi_pins, rate.bps(), &clocks); let s = wifi_serial.split(); wtx = s.0; wrx = s.1; diff --git a/rust/weather/src/main.rs b/rust/weather/src/main.rs index d9694d7..2c97265 100644 --- a/rust/weather/src/main.rs +++ b/rust/weather/src/main.rs @@ -9,7 +9,7 @@ use embedded_hal::serial; use esp8266at::handler::{NetworkEvent, SerialNetworkHandler}; use esp8266at::response::{parse, ConnectionType, ParseResult}; use esp8266at::traits::{self, Write}; -use k210_hal::pac; +use k210_hal::Peripherals; use k210_hal::prelude::*; use k210_hal::stdout::Stdout; use k210_shared::board::def::io; @@ -82,27 +82,25 @@ fn io_init() { #[entry] fn main() -> ! { - let p = pac::Peripherals::take().unwrap(); + let p = Peripherals::take().unwrap(); let clocks = k210_hal::clock::Clocks::new(); usleep(200000); io_init(); // Configure UARTHS (→host) - let serial = p.UARTHS.constrain(DEFAULT_BAUD.bps(), &clocks); + let serial = p.UARTHS.configure((p.pins.pin5, p.pins.pin4), DEFAULT_BAUD.bps(), &clocks); let (mut tx, mut _rx) = serial.split(); let mut debug = Stdout(&mut tx); // Configure UART1 (→WIFI) sysctl::clock_enable(sysctl::clock::UART1); sysctl::reset(sysctl::reset::UART1); - fpioa::set_function(io::WIFI_RX, fpioa::function::UART1_TX); - fpioa::set_function(io::WIFI_TX, fpioa::function::UART1_RX); fpioa::set_function(io::WIFI_EN, fpioa::function::GPIOHS8); fpioa::set_io_pull(io::WIFI_EN, fpioa::pull::DOWN); gpiohs::set_pin(8, true); gpiohs::set_direction(8, gpio::direction::OUTPUT); - let wifi_serial = p.UART1.constrain(DEFAULT_BAUD.bps(), &clocks); + let wifi_serial = p.UART1.configure((p.pins.pin7, p.pins.pin6), DEFAULT_BAUD.bps(), &clocks); let (mut wtx, mut wrx) = wifi_serial.split(); let mut wa = WriteAdapter::new(&mut wtx);