1 use core::ptr::{read_volatile, write_volatile}; 2 use core::mem::uninitialized; 3 use core::ops::{BitAnd, BitOr, Not}; 4 5 use super::io::Io; 6 7 #[repr(packed)] 8 pub struct Mmio<T> { 9 value: T, 10 } 11 12 impl<T> Mmio<T> { 13 /// Create a new Mmio without initializing new() -> Self14 pub fn new() -> Self { 15 Mmio { 16 value: unsafe { uninitialized() } 17 } 18 } 19 } 20 21 impl<T> Io for Mmio<T> where T: Copy + PartialEq + BitAnd<Output = T> + BitOr<Output = T> + Not<Output = T> { 22 type Value = T; 23 read(&self) -> T24 fn read(&self) -> T { 25 unsafe { read_volatile(&self.value) } 26 } 27 write(&mut self, value: T)28 fn write(&mut self, value: T) { 29 unsafe { write_volatile(&mut self.value, value) }; 30 } 31 } 32