-
Notifications
You must be signed in to change notification settings - Fork 196
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
Showing
1 changed file
with
52 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//! A simple example of how to read from the ESP-IDF console | ||
use esp_idf_hal::gpio::AnyIOPin; | ||
use esp_idf_svc::hal::peripherals::Peripherals; | ||
use esp_idf_svc::hal::uart::UartDriver; | ||
use esp_idf_svc::io::vfs::BlockingStdIo; | ||
use esp_idf_svc::sys::EspError; | ||
|
||
use std::io::Write; | ||
|
||
fn main() -> Result<(), EspError> { | ||
esp_idf_svc::sys::link_patches(); | ||
esp_idf_svc::log::EspLogger::initialize_default(); | ||
|
||
// NOTE: This example assumes that the console configuration is not altered by the user | ||
// by using non-default `CONFIG_ESP_CONSOLE_*` settings in `sdkconfig.defaults` | ||
// | ||
// The default configuration is: | ||
// - UART0 | ||
// - 115200 baud rate | ||
// - 8N1 | ||
// - RTS/CTS disabled | ||
// - No flow control | ||
// - The default TX/RX pins for UART0 (1 & 3 for ESP32, 17 & 16 for ESP32-S2 and so on.) | ||
|
||
let peripherals = Peripherals::take()?; | ||
|
||
let uart_driver = UartDriver::new( | ||
peripherals.uart0, | ||
// Change this to the correct UART0 TX pin for your MCU if you are not using esp32 | ||
peripherals.pins.gpio1, | ||
// Change this to the correct UART0 RX pin for your MCU if you are not using esp32 | ||
peripherals.pins.gpio3, | ||
Option::<AnyIOPin>::None, | ||
Option::<AnyIOPin>::None, | ||
&Default::default(), | ||
)?; | ||
|
||
// Keep it around till the end of your program | ||
// If you drop it, the console will go back to non-blocking UART mode | ||
let _blocking_io = BlockingStdIo::uart(uart_driver)?; | ||
|
||
loop { | ||
print!("Enter a message: "); | ||
std::io::stdout().flush().unwrap(); | ||
|
||
let mut buffer = String::new(); | ||
std::io::stdin().read_line(&mut buffer).unwrap(); | ||
|
||
println!("You entered: {}", buffer); | ||
} | ||
} |