#![no_std] #![no_main] #![feature(type_alias_impl_trait)] mod modem; use esp_backtrace as _; use esp_println::println; use hal::{ clock::ClockControl, Delay, embassy::{self, executor::Executor}, gpio::IO, peripherals::{Peripherals, UART1}, prelude::*, prelude::entry, timer::TimerGroup, Uart, uart::{ config::{ Config, DataBits, Parity, StopBits, }, TxRxPins, }, }; use esp_hal_common::{UartRx, UartTx}; use atat::{ asynch::{ AtatClient, Client, }, AtatIngress, Buffers, DefaultDigester, Ingress, }; use static_cell::StaticCell; const READ_BUF_SIZE: usize = 64; const INGRESS_BUF_SIZE: usize = 1024; const URC_CAPACITY: usize = 128; const URC_SUBSCRIBERS: usize = 3; #[embassy_executor::task] async fn ingress_task( mut ingress: Ingress< 'static, DefaultDigester, modem::Urc, INGRESS_BUF_SIZE, URC_CAPACITY, URC_SUBSCRIBERS, >, mut rx: UartRx<'static, UART1>) { println!("reading in ingress_task..."); ingress.read_from(&mut rx).await; } #[embassy_executor::task] async fn test_send(mut client: Client<'static, UartTx<'static, UART1>, INGRESS_BUF_SIZE>) { println!("sending a single message (GetManufacturerId)"); client.send(&modem::GetManufacturerId).await.ok(); } #[entry] fn main() -> ! { let peripherals = Peripherals::take(); let mut system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let mut delay = Delay::new(&clocks); let timer_group0 = TimerGroup::new( peripherals.TIMG0, &clocks, &mut system.peripheral_clock_control, ); embassy::init(&clocks, timer_group0.timer0); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); // Power on the LilyGo A7670E module. let mut power = io.pins.gpio4.into_push_pull_output(); power.set_high().ok(); for i in 0..15 { println!("waiting {} seconds ...", 15 - i); delay.delay_ms(1000u32); } let modem_uart_pins = TxRxPins::new_tx_rx( io.pins.gpio26.into_push_pull_output(), io.pins.gpio27.into_floating_input(), ); let config = Config { baudrate: 115200, data_bits: DataBits::DataBits8, parity: Parity::ParityNone, stop_bits: StopBits::STOP1, }; // UART interface for the GSM modem let mut uart = Uart::new_with_config( peripherals.UART1, config, Some(modem_uart_pins), &clocks, &mut system.peripheral_clock_control, ); uart.set_rx_fifo_full_threshold(READ_BUF_SIZE as u16).unwrap(); let (tx, rx) = uart.split(); static BUFFERS: Buffers = Buffers::::new(); let digester = DefaultDigester::::default() .with_custom_success(|buf| { println!("digested:\n{:?}", buf); Ok((buf, buf.len())) }); let (ingress, client) = BUFFERS.split( tx, digester, atat::Config::default() ); println!("Starting embassy executor ..."); static CELL: StaticCell = StaticCell::new(); let executor = CELL.init(Executor::new()); executor.run(|spawner| { let _ = spawner.spawn(ingress_task(ingress, rx)); let _ = spawner.spawn(test_send(client)); }); }