From 03bfd901f8188761c7454725d026a0b5b675de2f Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Sun, 27 Sep 2020 11:49:02 +0800 Subject: [PATCH] lib: fix `no_std` compiling Add a conditional check to enable `no_std` if the target_os is "none". Signed-off-by: Sean Cross --- src/lib.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9fb74b7..306ac5d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ -use std::convert::TryInto; +#![cfg_attr(target_os = "none", no_std)] +use core::convert::TryInto; pub struct Register { /// Offset of this register within this CSR offset: usize, @@ -78,7 +79,7 @@ pub struct CSR { impl CSR where - T: std::convert::TryFrom + std::convert::TryInto + std::default::Default, + T: core::convert::TryFrom + core::convert::TryInto + core::default::Default, { pub fn new(base: *mut T) -> Self { CSR { base } @@ -131,11 +132,11 @@ mod tests { #[test] fn compile_check() { use super::*; - let mut audio = CSR::new(0x0000_0000 as *mut u32); + let mut audio = CSR::new(0x1000_0000 as *mut u32); audio.r(pac::audio::RX_CTL_ENABLE); audio.rw(pac::audio::RX_CTL_RESET, 1); - let mut uart = CSR::new(0x0001_0000 as *mut u8); + let mut uart = CSR::new(0x1001_0000 as *mut u8); uart.ow(pac::uart::RXTX_RXTX, b'a'); assert_ne!(uart.r(pac::uart::TXFULL_TXFULL), 1);