-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2c9d14
commit c362b51
Showing
3 changed files
with
82 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//! UART Test | ||
//! | ||
//! Folowing pins are used: | ||
//! RX GPIO5 | ||
//! TX GPIP6 | ||
//! | ||
//! Connect TX (GPIO6) and RX (GPIO5) pins. | ||
|
||
#![no_std] | ||
#![no_main] | ||
|
||
use hil_test::esp_hal::{ | ||
clock::ClockControl, | ||
peripherals::{Peripherals, UART0}, | ||
prelude::*, | ||
timer::TimerGroup, | ||
uart::{ | ||
config::{Config, DataBits, Parity, StopBits}, | ||
TxRxPins, | ||
}, | ||
Uart, IO, | ||
}; | ||
use nb::block; | ||
|
||
struct Context { | ||
uart: Uart<'static, UART0>, | ||
} | ||
|
||
impl Context { | ||
pub fn init() -> Self { | ||
let peripherals = Peripherals::take(); | ||
let system = peripherals.SYSTEM.split(); | ||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); | ||
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); | ||
let pins = TxRxPins::new_tx_rx( | ||
io.pins.gpio6.into_push_pull_output(), | ||
io.pins.gpio5.into_floating_input(), | ||
); | ||
let config = Config { | ||
baudrate: 115200, | ||
data_bits: DataBits::DataBits8, | ||
parity: Parity::ParityNone, | ||
stop_bits: StopBits::STOP1, | ||
}; | ||
|
||
let mut uart = Uart::new_with_config(peripherals.UART0, config, Some(pins), &clocks); | ||
|
||
Context { uart } | ||
} | ||
} | ||
|
||
#[embedded_test::tests] | ||
mod tests { | ||
use defmt::{assert_eq, unwrap}; | ||
|
||
use super::*; | ||
|
||
#[init] | ||
fn init() -> Context { | ||
Context::init() | ||
} | ||
|
||
#[test] | ||
fn test_send_receive(mut ctx: Context) { | ||
ctx.uart.write(0x42).ok(); | ||
let read = block!(ctx.uart.read()); | ||
assert_eq!(read, Ok(0x42)); | ||
} | ||
} |