use core::marker::PhantomData;
use core::ptr::NonNull;
use crate::access::{self, Access};
use crate::integers::Integer;
#[cfg(doc)]
use crate::access::{ReadOnly, ReadWrite, WriteOnly};
#[cfg(doc)]
use crate::RegMap;
pub struct Reg<'a, T, A> {
ptr: NonNull<T>,
_ref: PhantomData<&'a T>,
_acs: PhantomData<A>,
}
impl<'a, T: Integer, A: Access> Reg<'a, T, A> {
#[doc(hidden)]
#[allow(non_snake_case)]
#[inline]
pub const unsafe fn __MACRO_ONLY__from_ptr(ptr: *mut T) -> Self {
Self::from_nonnull(NonNull::new_unchecked(ptr))
}
#[inline]
pub(crate) const unsafe fn from_nonnull(ptr: NonNull<T>) -> Self {
Self {
ptr,
_ref: PhantomData,
_acs: PhantomData,
}
}
#[inline]
pub const fn as_ptr(&self) -> *mut T {
self.ptr.as_ptr()
}
#[inline]
pub fn read(&self) -> T
where
A: access::Readable,
{
unsafe { self.ptr.read_volatile() }
}
#[inline]
pub fn write(&self, val: T)
where
A: access::Writable,
{
unsafe { self.ptr.write_volatile(val) }
}
}
pub unsafe trait RegMapPtr<'a>: Sized + 'a {
type RegMap;
unsafe fn from_nonnull(ptr: NonNull<Self::RegMap>) -> Self;
unsafe fn from_ptr(ptr: *mut Self::RegMap) -> Self;
fn from_mut(reg: &'a mut Self::RegMap) -> Self;
fn as_ptr(&self) -> *mut Self::RegMap;
}