From ee2c7ef140c70689edc91dc7e97b11857c8eb243 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 14 Jan 2024 19:22:37 +0800 Subject: [PATCH] format xous-pio --- libs/xous-pio/src/pio_tests/mod.rs | 43 +++++++++++++----------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/libs/xous-pio/src/pio_tests/mod.rs b/libs/xous-pio/src/pio_tests/mod.rs index b305384c0..e2ca51b34 100644 --- a/libs/xous-pio/src/pio_tests/mod.rs +++ b/libs/xous-pio/src/pio_tests/mod.rs @@ -1,10 +1,10 @@ +pub mod adder; pub mod i2c; +pub mod nec; pub mod spi; pub mod units; -pub mod adder; -pub mod nec; -#[cfg(not(any(target_os="xous", feature="rp2040")))] +#[cfg(not(any(target_os = "xous", feature = "rp2040")))] mod duart { pub const UART_DOUT: utralib::Register = utralib::Register::new(0, 0xff); pub const UART_DOUT_DOUT: utralib::Field = utralib::Field::new(8, 0, UART_DOUT); @@ -16,35 +16,32 @@ mod duart { pub const HW_DUART_BASE: usize = 0x4004_2000; } -#[cfg(not(any(target_os="xous", feature="rp2040")))] +#[cfg(not(any(target_os = "xous", feature = "rp2040")))] use utralib::CSR; -#[cfg(not(any(target_os="xous", feature="rp2040")))] -pub struct Uart { -} -#[cfg(not(any(target_os="xous", feature="rp2040")))] +#[cfg(not(any(target_os = "xous", feature = "rp2040")))] +pub struct Uart {} +#[cfg(not(any(target_os = "xous", feature = "rp2040")))] impl Uart { fn put_digit(&mut self, d: u8) { let nyb = d & 0xF; - let c = if nyb < 10 { - nyb + 0x30 - } else { - nyb + 0x61 - 10 - }; + let c = if nyb < 10 { nyb + 0x30 } else { nyb + 0x61 - 10 }; assert!(c >= 0x30, "conversion failed!"); self.putc(c); } + pub fn put_hex(&mut self, c: u8) { self.put_digit(c >> 4); self.put_digit(c & 0xF); } - pub fn newline(&mut self) { - self.putc(0xd); - } + + pub fn newline(&mut self) { self.putc(0xd); } + pub fn print_hex_word(&mut self, word: u32) { for &byte in word.to_be_bytes().iter() { self.put_hex(byte); } } + pub fn putc(&self, c: u8) { let base = duart::HW_DUART_BASE as *mut u32; let mut uart = CSR::new(base); @@ -57,7 +54,7 @@ impl Uart { } uart.wfo(duart::UART_DOUT_DOUT, c as u32); - #[cfg(feature="arty")] + #[cfg(feature = "arty")] self.putc_litex(c); } @@ -66,23 +63,21 @@ impl Uart { self.putc(c); } } - } -#[cfg(not(any(target_os="xous", feature="rp2040")))] -pub fn setup_reporting(_rep_adr: *mut u32) { -} +#[cfg(not(any(target_os = "xous", feature = "rp2040")))] +pub fn setup_reporting(_rep_adr: *mut u32) {} pub fn report_api(d: u32) { - #[cfg(not(any(target_os="xous", feature="rp2040")))] + #[cfg(not(any(target_os = "xous", feature = "rp2040")))] { let mut uart = Uart {}; uart.print_hex_word(d); uart.newline(); } - #[cfg(target_os="xous")] + #[cfg(target_os = "xous")] log::info!("report: 0x{:x}", d); - #[cfg(feature="rp2040")] + #[cfg(feature = "rp2040")] defmt::info!("report: 0x{:x}", d); }