Skip to content

Commit

Permalink
fix(demo): use new uart api
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed Apr 30, 2024
1 parent 194ae21 commit 76871f6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
5 changes: 3 additions & 2 deletions examples/ch32v305/src/bin/rcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ async fn main(spawner: Spawner) -> ! {
pll_src: PllSource::HSE,
pll: Some(Pll {
prediv: PllPreDiv::DIV1,
mul: PllMul::MUL12, // 12 * 12 = max 144MHz
// use MUL16 to overclock to 192MHz
// 12 * 12 = max 144MHz
// use MUL16 to overclock to 192MHz
mul: PllMul::MUL12,
}),
sys: Sysclk::PLL,
..Default::default()
Expand Down
3 changes: 2 additions & 1 deletion examples/ch32v305/src/bin/spi-lcd-st7735-cube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,9 @@ async fn main(_spawner: Spawner) -> ! {
let _miso = p.PB14;
let mosi = p.PB15;

let dc = p.PA5;
let rst = p.PC6;
let dc = p.PB7;
// let dc = p.PB7;

// let led = p.PB8;
let mut led = Output::new(p.PC9, Level::Low, Default::default());
Expand Down
25 changes: 13 additions & 12 deletions examples/ch32v305/src/bin/uart_echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,24 @@ async fn main(spawner: Spawner) -> ! {

let mut cfg = usart::Config::default();
cfg.baudrate = 115200;
let mut uart = Uart::new(p.USART3, p.PB10, p.PB11, cfg).unwrap();
let mut uart = Uart::new_blocking(p.USART3, p.PB11, p.PB10, cfg).unwrap();

uart.blocking_write(b"Init ok\r\n");

// FIXME: no time slice for embassy executor
let mut buf = [0u8; 1];
loop {
// Timer::after_millis(2000).await;
while let Ok(b) = nb::block!(uart.nb_read()) {
if b == b'\r' {
uart.blocking_write(b"\r\n");
} else {
uart.blocking_write(&[b]);
}
}
uart.blocking_read(&mut buf).unwrap();

led.toggle();
if buf[0] >= b'a' && buf[0] <= b'z' {
buf[0] -= 32;
}

//uart.blocking_write(b"Hello from serial\r\n");
// println!("fuck");
if buf[0] == b'\r' {
uart.blocking_write(b"\r\n").unwrap();
led.toggle();
} else {
uart.blocking_write(&buf).unwrap();
}
}
}
2 changes: 1 addition & 1 deletion examples/ch32v305/src/bin/uart_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn main(spawner: Spawner) -> ! {
spawner.spawn(blink(p.PC9.degrade())).unwrap();

let cfg = usart::Config::default();
let mut uart = UartTx::new(p.USART3, p.PB10, cfg).unwrap();
let mut uart = UartTx::new_blocking(p.USART3, p.PB10, cfg).unwrap();

loop {
Timer::after_millis(2000).await;
Expand Down

0 comments on commit 76871f6

Please sign in to comment.