mirror of
https://github.com/laanwj/k210-sdk-stuff.git
synced 2024-11-24 02:16:18 +04:00
rust: Add uart-passthrough
This commit is contained in:
parent
f046ca6066
commit
a9b7ed1a43
@ -125,6 +125,13 @@ The amount of pressure applied determines the radius of the state change.
|
||||
|
||||
[README](rust/game-of-life/README.md)
|
||||
|
||||
rust/uart-passthrough
|
||||
---------------------
|
||||
|
||||
Pass through UART from host to the ESP8285 WIFI chip.
|
||||
|
||||
[README](rust/uart-passthrough/README.md)
|
||||
|
||||
ROM re'ing
|
||||
===========
|
||||
|
||||
|
@ -4,6 +4,7 @@ members = [
|
||||
"mandelbrot",
|
||||
"game-of-life",
|
||||
"accelerometer",
|
||||
"uart-passthrough",
|
||||
]
|
||||
|
||||
[patch.crates-io]
|
||||
|
8
rust/uart-passthrough/.cargo/config
Normal file
8
rust/uart-passthrough/.cargo/config
Normal file
@ -0,0 +1,8 @@
|
||||
[target.riscv64gc-unknown-none-elf]
|
||||
rustflags = [
|
||||
"-C", "link-arg=-Tmemory.x",
|
||||
"-C", "link-arg=-Tlink.x",
|
||||
]
|
||||
|
||||
[build]
|
||||
target = "riscv64gc-unknown-none-elf"
|
2
rust/uart-passthrough/.gitignore
vendored
Normal file
2
rust/uart-passthrough/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/target
|
||||
**/*.rs.bk
|
12
rust/uart-passthrough/Cargo.toml
Normal file
12
rust/uart-passthrough/Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "uart-passthrough"
|
||||
version = "0.1.0"
|
||||
authors = ["W.J. van der Laan <laanwj@protonmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
nb = "0.1.1"
|
||||
riscv-rt = "0.5.0"
|
||||
k210-hal = "0.1.0"
|
||||
riscv = "0.5"
|
||||
k210-shared = { path = "../k210-shared" }
|
6
rust/uart-passthrough/README.md
Normal file
6
rust/uart-passthrough/README.md
Normal file
@ -0,0 +1,6 @@
|
||||
# `uart-passthrough`
|
||||
|
||||
Pass through UART from host to the ESP8285 WIFI chip.
|
||||
|
||||
Any input from the host is forwarded to the ESP8285, and any input from the ESP8285
|
||||
is forwarded to the host. Currently only supports a fixed baudrate of 115200.
|
41
rust/uart-passthrough/src/main.rs
Normal file
41
rust/uart-passthrough/src/main.rs
Normal file
@ -0,0 +1,41 @@
|
||||
#![allow(dead_code)]
|
||||
#![allow(non_snake_case)]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use k210_hal::pac;
|
||||
use k210_hal::prelude::*;
|
||||
use k210_shared::board::def::io;
|
||||
use k210_shared::soc::fpioa;
|
||||
use k210_shared::soc::sysctl;
|
||||
use nb::block;
|
||||
use riscv_rt::entry;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let p = pac::Peripherals::take().unwrap();
|
||||
let clocks = k210_hal::clock::Clocks::new();
|
||||
|
||||
// Configure UARTHS (→host)
|
||||
let serial = p.UARTHS.constrain(115_200.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 as u8, fpioa::function::UART1_TX);
|
||||
fpioa::set_function(io::WIFI_TX as u8, fpioa::function::UART1_RX);
|
||||
let wifi_serial = p.UART1.constrain(115_200.bps(), &clocks);
|
||||
let (mut wtx, mut wrx) = wifi_serial.split();
|
||||
|
||||
// Relay characters between UARTs
|
||||
loop {
|
||||
if let Ok(ch) = wrx.read() {
|
||||
let _res = block!(tx.write(ch));
|
||||
}
|
||||
if let Ok(ch) = rx.read() {
|
||||
let _res = block!(wtx.write(ch));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user