#![no_std]
#![allow(async_fn_in_trait)]
#![warn(missing_docs)]
pub use embassy_time::Duration;
pub mod at;
pub mod bus;
pub mod config;
pub mod error;
pub mod net;
pub mod sync;
pub mod types;
pub mod util;
pub mod wifi;
#[cfg(feature = "mission-t01")]
pub mod advanced;
#[cfg(feature = "mission-t01")]
pub mod http;
#[cfg(feature = "mission-t01")]
pub mod mqtt;
#[cfg(feature = "mission-t01")]
pub mod power;
#[cfg(feature = "mission-t01")]
pub mod tls;
pub use config::Config;
pub use error::{Error, Result};
pub use types::*;
#[cfg(feature = "mission-t01")]
use at::processor::AtProcessor;
#[cfg(feature = "mission-t01")]
use embedded_hal::digital::OutputPin;
#[cfg(feature = "mission-t01")]
use embedded_hal_async::spi::SpiDevice;
#[cfg(feature = "mission-t01")]
pub struct Driver<SPI, CS>
where
SPI: SpiDevice + 'static,
CS: OutputPin + 'static,
{
spi: &'static sync::TmMutex<SpiTransport<SPI, CS>>,
processor: &'static AtProcessor,
wifi: &'static wifi::WiFiManager,
network: &'static net::NetworkDevice,
tls: &'static tls::TlsManager,
config: Config,
}
#[cfg(feature = "mission-t01")]
impl<SPI, CS> Driver<SPI, CS>
where
SPI: SpiDevice + 'static,
CS: OutputPin + 'static,
{
pub fn new(
spi: &'static sync::TmMutex<SpiTransport<SPI, CS>>,
processor: &'static AtProcessor,
wifi: &'static wifi::WiFiManager,
network: &'static net::NetworkDevice,
tls: &'static tls::TlsManager,
config: Config,
) -> Self {
Self {
spi,
processor,
wifi,
network,
tls,
config,
}
}
pub async fn init_wifi(&self, mode: WiFiMode) -> Result<()> {
self.wifi.init(self.spi, mode).await
}
pub async fn wifi_scan(&self) -> Result<ScanResults> {
self.wifi.scan(self.spi).await
}
pub async fn wifi_connect(&self, ssid: &str, password: &str) -> Result<()> {
let result = self.wifi.connect(self.spi, ssid, password).await;
if result.is_ok() {
self.network.set_link_state(true);
}
result
}
pub async fn wifi_connect_with_retry(
&self,
ssid: &str,
password: &str,
max_attempts: u8,
) -> Result<()> {
util::retry_with_backoff(
max_attempts,
Duration::from_secs(1),
Duration::from_secs(10),
|| async { self.wifi_connect(ssid, password).await },
)
.await
}
pub async fn wifi_disconnect(&self) -> Result<()> {
let result = self.wifi.disconnect(self.spi).await;
self.network.set_link_state(false);
result
}
pub async fn get_ip_config(&self) -> Result<IpConfig> {
self.wifi.get_ip_config(self.spi).await
}
pub async fn get_mac(&self) -> Result<MacAddress> {
self.wifi.get_mac(self.spi).await
}
pub async fn get_wifi_state(&self) -> WiFiState {
self.wifi.get_state().await
}
pub fn network_device(&self) -> &NetworkDevice {
self.network
}
pub fn tls_manager(&self) -> &tls::TlsManager {
self.tls
}
pub fn mqtt_client(&self, link_id: u8) -> mqtt::MqttClient {
mqtt::MqttClient::new(link_id, self.processor, self.config.command_timeout)
}
pub fn http_client(&self) -> http::HttpClient {
http::HttpClient::new(self.network, self.processor, self.config.command_timeout)
}
pub fn dns_resolver(&self) -> advanced::DnsResolver {
advanced::DnsResolver::new(self.processor, self.config.command_timeout)
}
pub fn sntp_client(&self) -> advanced::SntpClient {
advanced::SntpClient::new(self.processor, self.config.command_timeout)
}
pub fn ping(&self) -> advanced::Ping {
advanced::Ping::new(self.processor, self.config.command_timeout)
}
pub fn power_manager(&self) -> power::PowerManager {
power::PowerManager::new(self.processor, self.config.command_timeout)
}
pub async fn get_connection_status(&self) -> Result<net::device::ConnectionStatus> {
self.network
.get_connection_status(self.spi, self.config.command_timeout)
.await
}
pub fn processor(&self) -> &AtProcessor {
self.processor
}
pub async fn run_rx_task(&'static self) {
self.processor.rx_task(self.spi).await
}
pub async fn run_ipd_task(&'static self) {
self.network.ipd_processor_task().await
}
}
#[macro_export]
macro_rules! make_static {
($val:expr) => {{
static STATIC_CELL: static_cell::StaticCell<_> = static_cell::StaticCell::new();
#[deny(unused_attributes)]
let x = STATIC_CELL.uninit().write($val);
x
}};
($ty:ty) => {{
static STATIC_CELL: static_cell::StaticCell<$ty> = static_cell::StaticCell::new();
STATIC_CELL.uninit()
}};
}
pub use at::{AtCommand, AtResponse};
pub use bus::SpiTransport;
#[cfg(feature = "mission-t01")]
pub use http::{HttpClient, HttpMethod, HttpRequest, HttpResponse};
#[cfg(feature = "mission-t01")]
pub use mqtt::{MqttClient, MqttConfig, MqttMessage};
#[cfg(feature = "mission-t01")]
pub use net::NetworkDevice;
#[cfg(feature = "mission-t01")]
pub use sync::TmMutex;
#[cfg(feature = "mission-t01")]
pub use tls::{CertificateType, TlsManager};
#[cfg(feature = "mission-t01")]
pub use wifi::WiFiManager;
#[cfg(feature = "mission-t02")]
pub use net::{
new_driver, Capabilities, Medium, PacketBuf, RxToken, SpiFrameHeader, St67w611Device,
St67w611Runner, St67w611Transport, State, TrafficType, TxToken, MTU,
};