diff --git a/src/lib.rs b/src/lib.rs index cb07700..4ee29a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,3 +17,4 @@ pub mod mini_uart; pub mod pwm; pub mod qa7_control; pub mod timer; +pub mod v3d; \ No newline at end of file diff --git a/src/v3d.rs b/src/v3d.rs new file mode 100644 index 0000000..68356fb --- /dev/null +++ b/src/v3d.rs @@ -0,0 +1,34 @@ +use crate::addr::IO_BASE; +use volatile::{Volatile}; + +/// The base address for the `MU` registers. +const V3D_BASE: usize = IO_BASE + 0xC00000; + +#[repr(C)] +#[allow(non_snake_case)] +struct Registers { + pub regs: [Volatile; 969] +} + +pub struct V3d { + registers: &'static mut Registers, +} + +impl V3d { + /// Returns a new instance of `Mailbox`. + #[inline] + pub fn new() -> V3d { + V3d { + registers: unsafe { &mut *(V3D_BASE as *mut Registers) }, + } + } + + pub fn read(&self, pos: usize) -> u32 { + self.registers.regs[pos].read() + } + + pub fn write(&mut self, pos: usize, data: u32) { + self.registers.regs[pos] + .write(data); + } +}