intel_spi/
mmio.rs

1// SPDX-License-Identifier: MIT
2
3use core::ops::{BitAnd, BitOr, Not};
4use core::ptr;
5
6use super::io::Io;
7
8#[repr(packed)]
9pub struct Mmio<T> {
10    value: T
11}
12
13impl<T> Io for Mmio<T> where T: Copy + PartialEq + BitAnd<Output = T> + BitOr<Output = T> + Not<Output = T> {
14    type Value = T;
15
16    fn read(&self) -> T {
17        let raw = ptr::addr_of!(self.value);
18        unsafe { raw.read_volatile() }
19    }
20
21    fn write(&mut self, value: T) {
22        let raw = ptr::addr_of_mut!(self.value);
23        unsafe { raw.write_volatile(value) };
24    }
25}