rust: Dependency bump k210-hal

Peripherals moved to pac, UARTS take the pins to use and internally
configure sysctl.
This commit is contained in:
Wladimir J. van der Laan 2019-07-03 18:24:12 +00:00
parent 02f1e24258
commit d4b2b6bbbd
11 changed files with 42 additions and 42 deletions

View File

@ -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" }

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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();

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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);