esp-hal/hil-test/tests/uart_tx_rx.rs
Sergio Gasquez Arcos c88dbefff8
Avoid using nb::Result as a return type (#2882)
* feat: Avoid using nb::Result in spi

* feat: Avoid using nb::Result in hmac

* feat: Avoid using nb::Result in sha

* feat: Avoid using nb::Result in usb_serial_jtag

* feat: Avoid using nb::Result in adc::read_oneshot

* feat: Avoid using nb::Result in rsa::ready

* feat: Avoid using nb::Result in timer::wait

* feat: Avoid using nb in uart and twai. Udpate examples and tests to avoid using block!

* feat: Block on sha calls, remove Option<> results

* feat: Block on hmac calls, remove Option<> results

* fix: Clippy lints

* feat: Block on spi calls, remove Option<> results

* feat: Block on timer calls, remove Option<> results

* feat: Block on twai calls, remove Option<> results

* docs: Fix wait docstring

* feat: Remove embedded_hal_nb traits

* feat: Block on uart calls, remove Option<> results

* feat: Remove nb stuff from usb_serial_jtag

* feat: Block on rsa calls, remove Option<> results

* feat: Clippy lints

* feat: Make read_bytes return how many bytes it read from the fifo and fix docs/tests

* fix: run_test_periodic_timer test

* feat: Only remove nb from stabilizing drivers

* feat: Remove unused functions

* feat: Remove emnbedded-hal-nb

* test: Adapt tests

* docs: Update changelog and migration

* test: Adapt tests

* docs: Update migration guide

* docs: Update migration

Co-authored-by: Dániel Buga <bugadani@gmail.com>

* docs: Update changelog and migration guide

* feat: Make `write_bytes` return an Result

---------

Co-authored-by: Dániel Buga <bugadani@gmail.com>
2025-01-17 15:46:20 +00:00

66 lines
1.4 KiB
Rust

//! UART TX/RX Test
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% FEATURES: unstable
#![no_std]
#![no_main]
use esp_hal::{
uart::{self, UartRx, UartTx},
Blocking,
};
use hil_test as _;
struct Context {
rx: UartRx<'static, Blocking>,
tx: UartTx<'static, Blocking>,
}
#[cfg(test)]
#[embedded_test::tests(default_timeout = 3)]
mod tests {
use super::*;
#[init]
fn init() -> Context {
let peripherals = esp_hal::init(esp_hal::Config::default());
let (rx, tx) = hil_test::common_test_pins!(peripherals);
let tx = UartTx::new(peripherals.UART0, uart::Config::default())
.unwrap()
.with_tx(tx);
let rx = UartRx::new(peripherals.UART1, uart::Config::default())
.unwrap()
.with_rx(rx);
Context { rx, tx }
}
#[test]
fn test_send_receive(mut ctx: Context) {
let byte = [0x42];
ctx.tx.flush();
ctx.tx.write_bytes(&byte).unwrap();
let mut buf = [0u8; 1];
ctx.rx.read_bytes(&mut buf).unwrap();
assert_eq!(buf[0], 0x42);
}
#[test]
fn test_send_receive_bytes(mut ctx: Context) {
let bytes = [0x42, 0x43, 0x44];
let mut buf = [0u8; 3];
ctx.tx.flush();
ctx.tx.write_bytes(&bytes).unwrap();
ctx.rx.read_bytes(&mut buf).unwrap();
assert_eq!(buf, bytes);
}
}