Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ pub mod mini_uart;
pub mod pwm;
pub mod qa7_control;
pub mod timer;
pub mod v3d;
34 changes: 34 additions & 0 deletions src/v3d.rs
Original file line number Diff line number Diff line change
@@ -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<u32>; 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);
}
}