Add at_commands.rs
This commit is contained in:
parent
a361d64c5f
commit
ad86af1b74
47
src/at_commands.rs
Normal file
47
src/at_commands.rs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
use core::fmt::Write;
|
||||||
|
use esp_hal::{Blocking, delay::Delay, gpio::Output, uart::Uart};
|
||||||
|
|
||||||
|
pub struct ATCommands<'a, 'd> {
|
||||||
|
pub rst: Output<'a>,
|
||||||
|
pub pwr_key: Output<'a>,
|
||||||
|
pub uart: Uart<'d, Blocking>,
|
||||||
|
pub delay: Delay,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, 'd> ATCommands<'a, 'd> {
|
||||||
|
pub fn init(&mut self) {
|
||||||
|
self.pwr_key.set_low();
|
||||||
|
self.delay.delay_millis(1_000);
|
||||||
|
self.pwr_key.set_high();
|
||||||
|
self.delay.delay_millis(1_000);
|
||||||
|
|
||||||
|
self.rst.set_low();
|
||||||
|
self.delay.delay_millis(1_000);
|
||||||
|
self.rst.set_high();
|
||||||
|
self.delay.delay_millis(1_000);
|
||||||
|
|
||||||
|
self.pwr_key.set_low();
|
||||||
|
self.delay.delay_millis(1_000);
|
||||||
|
self.pwr_key.set_high();
|
||||||
|
self.delay.delay_millis(1_000);
|
||||||
|
|
||||||
|
log::info!("ATCommands Ready!");
|
||||||
|
self.delay.delay_millis(1_000);
|
||||||
|
|
||||||
|
let mut buffer = [0u8; 1024];
|
||||||
|
let length = self.uart.read(&mut buffer).unwrap();
|
||||||
|
log::info!("text: {:?}", str::from_utf8(&buffer[..length]));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn test(&mut self) {
|
||||||
|
self.uart.flush().unwrap();
|
||||||
|
self.delay.delay_millis(250);
|
||||||
|
self.uart.write_str("ATI\r").unwrap();
|
||||||
|
self.uart.flush().unwrap();
|
||||||
|
self.delay.delay_millis(500);
|
||||||
|
log::info!("Wrote command");
|
||||||
|
let mut buffer = [0u8; 1024];
|
||||||
|
let length = self.uart.read(&mut buffer).unwrap();
|
||||||
|
log::info!("text: {:?}", str::from_utf8(&buffer[..length]));
|
||||||
|
}
|
||||||
|
}
|
||||||
56
src/main.rs
56
src/main.rs
@ -10,6 +10,8 @@
|
|||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
|
|
||||||
use alloc::str;
|
use alloc::str;
|
||||||
|
use embedded_hal::delay::DelayNs;
|
||||||
|
use esp_alloc::export::enumset::EnumSet;
|
||||||
use esp_hal::{
|
use esp_hal::{
|
||||||
clock::CpuClock,
|
clock::CpuClock,
|
||||||
delay::Delay,
|
delay::Delay,
|
||||||
@ -23,12 +25,14 @@ use esp_hal::{
|
|||||||
use esp_backtrace as _;
|
use esp_backtrace as _;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
at_commands::ATCommands,
|
||||||
display::{Display, Position, Rgb565, SetAddressMode},
|
display::{Display, Position, Rgb565, SetAddressMode},
|
||||||
font::FontRenderer,
|
font::FontRenderer,
|
||||||
};
|
};
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
|
mod at_commands;
|
||||||
mod display;
|
mod display;
|
||||||
mod font;
|
mod font;
|
||||||
|
|
||||||
@ -109,30 +113,10 @@ fn main() -> ! {
|
|||||||
|
|
||||||
font_renderer.render(&mut display, "Hello World!", Position::new(70, 220));
|
font_renderer.render(&mut display, "Hello World!", Position::new(70, 220));
|
||||||
|
|
||||||
let test_delay = Delay::new();
|
let sim_rst = Output::new(peripherals.GPIO15, Level::High, OutputConfig::default());
|
||||||
|
let sim_pwr_key = Output::new(peripherals.GPIO33, Level::High, OutputConfig::default());
|
||||||
|
|
||||||
let mut sim_rst = Output::new(peripherals.GPIO15, Level::High, OutputConfig::default());
|
let uart = Uart::new(
|
||||||
let mut pwr_key = Output::new(peripherals.GPIO33, Level::High, OutputConfig::default());
|
|
||||||
|
|
||||||
pwr_key.set_low();
|
|
||||||
test_delay.delay_millis(1_000);
|
|
||||||
pwr_key.set_high();
|
|
||||||
test_delay.delay_millis(1_000);
|
|
||||||
|
|
||||||
sim_rst.set_low();
|
|
||||||
test_delay.delay_millis(1_000);
|
|
||||||
sim_rst.set_high();
|
|
||||||
test_delay.delay_millis(1_000);
|
|
||||||
|
|
||||||
pwr_key.set_low();
|
|
||||||
test_delay.delay_millis(1_000);
|
|
||||||
pwr_key.set_high();
|
|
||||||
test_delay.delay_millis(1_000);
|
|
||||||
|
|
||||||
log::info!("Ready!");
|
|
||||||
test_delay.delay_millis(1_000);
|
|
||||||
|
|
||||||
let mut uart = Uart::new(
|
|
||||||
peripherals.UART2,
|
peripherals.UART2,
|
||||||
uart::Config::default()
|
uart::Config::default()
|
||||||
.with_baudrate(115200)
|
.with_baudrate(115200)
|
||||||
@ -144,25 +128,15 @@ fn main() -> ! {
|
|||||||
.with_rx(peripherals.GPIO16)
|
.with_rx(peripherals.GPIO16)
|
||||||
.with_tx(peripherals.GPIO17);
|
.with_tx(peripherals.GPIO17);
|
||||||
|
|
||||||
uart.flush().unwrap();
|
let mut at_commands = ATCommands {
|
||||||
test_delay.delay_millis(250);
|
rst: sim_rst,
|
||||||
uart.write_str("ATI\r").unwrap();
|
pwr_key: sim_pwr_key,
|
||||||
uart.flush().unwrap();
|
uart,
|
||||||
test_delay.delay_millis(250);
|
delay: Delay::new(),
|
||||||
log::info!("Wrote command");
|
};
|
||||||
let mut buffer = [0u8; 1024];
|
|
||||||
let length = uart.read(&mut buffer).unwrap();
|
|
||||||
log::info!("text: {:?}", str::from_utf8(&buffer[..length]));
|
|
||||||
|
|
||||||
uart.flush().unwrap();
|
at_commands.init();
|
||||||
test_delay.delay_millis(250);
|
at_commands.test();
|
||||||
uart.write_str("ATI\r").unwrap();
|
|
||||||
uart.flush().unwrap();
|
|
||||||
test_delay.delay_millis(250);
|
|
||||||
log::info!("Wrote command");
|
|
||||||
let mut buffer = [0u8; 1024];
|
|
||||||
let length = uart.read(&mut buffer).unwrap();
|
|
||||||
log::info!("text: {:?}", str::from_utf8(&buffer[..length]));
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let delay_start = Instant::now();
|
let delay_start = Instant::now();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user