Crates.io | ac4490 |
lib.rs | ac4490 |
version | 0.3.0 |
source | src |
created_at | 2024-08-18 03:03:28.834063 |
updated_at | 2024-08-18 08:44:02.828291 |
description | Rust driver for the Ezurio / Laird / Aerocomm AC4490 transceiver |
homepage | |
repository | |
max_upload_size | |
id | 1342282 |
size | 99,161 |
This is a driver for Ezurio's (previously Laird, previously Aerocomm) AC4490 transceiver. The driver is interface-agnostic and so can be used with embedded or desktop applications.
View the docs here.
For a device using embassy_stm32::usart::Uart
:
struct MyDeviceInterface(Uart<'static, embassy_stm32::mode::Async>);
impl DeviceInterface for MyDeviceInterface {
async fn write(&mut self, data: &[u8]) -> Result<(), ac4490::Error> {
self.0.write(data).await.map_err(|_| ac4490::Error::WriteError)
}
async fn read(&mut self, data: &mut [u8]) -> Result<(), ac4490::Error> {
self.0.read(data).await.map_err(|_| ac4490::Error::ReadError)
}
}
// ...
let usart6 = usart::Uart::new(
p.USART6,
p.PC7,
p.PC6,
Irqs,
p.GPDMA1_CH0,
p.GPDMA1_CH1,
uart_config,
)
.expect("Failed to initialize USART6");
// Init AC4490
let mut ac4490 = AC4490::new(
Ac4490UartInterface(usart6)
);
For a device using serialport::SerialPort
:
use ac4490::DeviceInterface;
use serialport::SerialPort;
struct SerialPortDeviceInterface(Box<dyn serialport::SerialPort>);
impl DeviceInterface for SerialPortDeviceInterface {
async fn write(&mut self, data: &[u8]) -> std::result::Result<(), ac4490::Error> {
self.0.write_all(data).map_err(|_| ac4490::Error::WriteError)?;
Ok(())
}
async fn read(&mut self, buf: &mut [u8]) -> std::result::Result<(), ac4490::Error> {
self.0.read(buf).map_err(|_| ac4490::Error::ReadError)?;
Ok(())
}
}
async fn main() -> Result<()> {
let port = serialport::new("/dev/ttyUSB0", 9600).open()?;
let mut transceiver = AC4490::new(SerialPortDeviceInterface(port));
Ok(())
}