34 lines
710 B
Rust
34 lines
710 B
Rust
|
|
use hcl::platform::usart;
|
|
use hcl::platform::dma;
|
|
use hcl::platform::PeripheralRef;
|
|
use hcl::platform::Location;
|
|
use hcl::dma::*;
|
|
|
|
use alloc::vec::Vec;
|
|
|
|
|
|
|
|
|
|
pub struct UsartPrinter<Addr>
|
|
where Addr: hcl::platform::Location
|
|
{
|
|
usart: PeripheralRef<usart::USART, Addr>,
|
|
}
|
|
|
|
impl<Addr> UsartPrinter<Addr>
|
|
where Addr: hcl::platform::Location
|
|
{
|
|
pub fn init(usart: PeripheralRef<usart::USART, Addr>) -> UsartPrinter<Addr> {
|
|
UsartPrinter { usart: usart }
|
|
}
|
|
|
|
pub fn print(&mut self, data: Vec<u8>) -> () {
|
|
for byte in data {
|
|
self.usart.clear_tx_complete();
|
|
self.usart.set_data(byte.into());
|
|
while !self.usart.tx_complete() {}
|
|
}
|
|
}
|
|
}
|