use super::serial::SerialPeripheral;
use super::traits::Peripheral;
use crate::error::Result;
use crate::tools::Tool;
use async_trait::async_trait;
const NUCLEO_DEFAULT_BAUD: u32 = 115_200;
pub struct NucleoPeripheral {
inner: SerialPeripheral,
}
impl NucleoPeripheral {
pub fn new(path: &str, board: &str) -> Result<Self> {
let inner = SerialPeripheral::connect_to(path, board, NUCLEO_DEFAULT_BAUD)?;
Ok(Self { inner })
}
pub fn f401re(path: &str) -> Result<Self> {
Self::new(path, "nucleo-f401re")
}
pub fn f411re(path: &str) -> Result<Self> {
Self::new(path, "nucleo-f411re")
}
}
#[async_trait]
impl Peripheral for NucleoPeripheral {
fn name(&self) -> &str {
self.inner.name()
}
fn board_type(&self) -> &str {
self.inner.board_type()
}
async fn connect(&mut self) -> Result<()> {
self.inner.connect().await
}
async fn disconnect(&mut self) -> Result<()> {
self.inner.disconnect().await
}
async fn health_check(&self) -> bool {
self.inner.health_check().await
}
fn tools(&self) -> Vec<Box<dyn Tool>> {
self.inner.tools()
}
}