ac4490

Crates.ioac4490
lib.rsac4490
version0.3.0
sourcesrc
created_at2024-08-18 03:03:28.834063
updated_at2024-08-18 08:44:02.828291
descriptionRust driver for the Ezurio / Laird / Aerocomm AC4490 transceiver
homepage
repository
max_upload_size
id1342282
size99,161
- (gdyr)

documentation

README

ac4490-rs

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.

Quick start

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(())
} 

Commit count: 0

cargo fmt