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 76871f6 commit 54e0861
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion examples/ch32v307/src/bin/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async fn main(spawner: Spawner) -> ! {
let p = hal::init(config);
hal::embassy::init();

let mut delay = Delay;
let delay = Delay;

let mut adc = hal::adc::Adc::new(p.ADC1, Default::default());

Expand Down
6 changes: 3 additions & 3 deletions examples/ch32v307/src/bin/rcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ async fn blink(pin: AnyPin, interval_ms: u64) {
#[embassy_executor::main(entry = "qingke_rt::entry")]
async fn main(spawner: Spawner) -> ! {
hal::debug::SDIPrint::enable();
let config = hal::Config {
rcc: hal::rcc::Config::SYSCLK_FREQ_144MHZ_HSE,
};
let mut config = hal::Config::default();
config.rcc = hal::rcc::Config::SYSCLK_FREQ_144MHZ_HSE;

let p = hal::init(config);
hal::embassy::init();

Expand Down
2 changes: 1 addition & 1 deletion examples/ch32v307/src/bin/uart.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.PA0.degrade())).unwrap();

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

loop {
Timer::after_millis(2000).await;
Expand Down
25 changes: 13 additions & 12 deletions examples/ch32v307/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 = 1000000;
let mut uart = Uart::new(p.USART1, p.PA9, p.PA10, cfg).unwrap();
let mut uart = Uart::new_blocking(p.USART1, p.PA10, p.PA9, 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();
}
}
}

0 comments on commit 54e0861

Please sign in to comment.