reflow-firmware2.0/src/printer.rs

34 lines
710 B
Rust
Raw Normal View History

2018-08-19 14:05:43 +02:00
use hcl::platform::usart;
use hcl::platform::dma;
use hcl::platform::PeripheralRef;
use hcl::platform::Location;
use hcl::dma::*;
use alloc::vec::Vec;
2018-08-28 21:17:26 +02:00
pub struct UsartPrinter<Addr>
where Addr: hcl::platform::Location
{
usart: PeripheralRef<usart::USART, Addr>,
2018-08-19 14:05:43 +02:00
}
2018-08-28 21:17:26 +02:00
impl<Addr> UsartPrinter<Addr>
where Addr: hcl::platform::Location
{
2018-08-19 14:05:43 +02:00
pub fn init(usart: PeripheralRef<usart::USART, Addr>) -> UsartPrinter<Addr> {
2018-08-28 21:17:26 +02:00
UsartPrinter { usart: usart }
2018-08-19 14:05:43 +02:00
}
pub fn print(&mut self, data: Vec<u8>) -> () {
for byte in data {
self.usart.clear_tx_complete();
self.usart.set_data(byte.into());
2018-08-28 21:17:26 +02:00
while !self.usart.tx_complete() {}
2018-08-19 14:05:43 +02:00
}
}
}