esp-hal/hil-test/tests/uart_async.rs
Dániel Buga 571760884b
Update our time driver for upcoming embassy changes (#2701)
* Add a timer-driven task

* Spawn another timer

* Log

* foo

* Do not access current time on each schedule

* Update generic queue

* Minimize alarm priorities

* Point to github with patches

* Fix build without any queue impl selected

* Remove explicit generic-queue features

* Define cfgs, fix calling something uninitialized

* Clean up RefCell+generic queue

* Fix arg order

* Feature

* Fix single integrated-timer queue

* Fix next expiration when arming

* Add note

* Adjust impl to latest changes

* Local patch

* Refactor the refactor refactor

* Track the timer item's owner

* Clear owner on dequeue

* Clean up

* Point at the right branch

* Fix panic message

* Hide private function

* Remove integrated-timer references

* Point at upstream embassy

* Configure via esp-config

* Document, clean up, fix

* Hack

* Remove patches

* Update config separator, test the complex variant

* Undo esp-config hack

* Remove trouble example, update edge-net

* Update test deps

* Document

* Update bt-hci.

* Fix generic queue

* Fix panic message

* Fix UB

* Fix rebase

* Resolve UB

* Avoid mutable reference in interrupt executor

---------

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2025-01-14 16:17:58 +00:00

52 lines
1.1 KiB
Rust

//! UART Test
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% FEATURES: unstable embassy
#![no_std]
#![no_main]
use esp_hal::{
uart::{self, Uart},
Async,
};
use hil_test as _;
struct Context {
uart: Uart<'static, Async>,
}
#[cfg(test)]
#[embedded_test::tests(default_timeout = 3, executor = hil_test::Executor::new())]
mod tests {
use super::*;
#[init]
async fn init() -> Context {
let peripherals = esp_hal::init(esp_hal::Config::default());
let (rx, tx) = hil_test::common_test_pins!(peripherals);
let uart = Uart::new(peripherals.UART0, uart::Config::default())
.unwrap()
.with_tx(tx)
.with_rx(rx)
.into_async();
Context { uart }
}
#[test]
async fn test_send_receive(mut ctx: Context) {
const SEND: &[u8] = b"Hello ESP32";
let mut buf = [0u8; SEND.len()];
ctx.uart.flush_async().await.unwrap();
ctx.uart.write_async(&SEND).await.unwrap();
ctx.uart.flush_async().await.unwrap();
ctx.uart.read_async(&mut buf[..]).await.unwrap();
assert_eq!(&buf[..], SEND);
}
}