1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#![no_std]
extern crate alloc;
use alloc::format;
use alloc::sync::Arc;
use embedded_hal::serial;
use nb::block;
use spin::Mutex;
use unmp::link::{Driver, Link};
struct Client<T: serial::Write<u8> + Send + 'static> {
serial: Mutex<T>,
}
impl<T> Driver for Client<T>
where
T: serial::Write<u8> + Send + 'static,
{
fn send(&self, buf: &[u8]) {
let mut serial = self.serial.lock();
for res in buf {
block!(serial.write(*res)).ok();
}
}
}
pub fn start<T>(name: &str, serial: T) -> Link
where
T: serial::Write<u8> + Send + 'static,
{
let driver = Arc::new(Client {
serial: Mutex::new(serial),
});
let link = Link::new(&format!("Serial({})", name), driver);
return link;
}