You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
Rust
39 lines
1.1 KiB
Rust
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
//
|
|
// Copyright (c) 2020-2021 Andre Richter <andre.o.richter@gmail.com>
|
|
|
|
//! Common device driver code.
|
|
|
|
use core::{marker::PhantomData, ops};
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
// Public Definitions
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
pub struct MMIODerefWrapper<T> {
|
|
start_addr: usize,
|
|
phantom: PhantomData<fn() -> T>,
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
// Public Code
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
impl<T> MMIODerefWrapper<T> {
|
|
/// Create an instance.
|
|
pub const unsafe fn new(start_addr: usize) -> Self {
|
|
Self {
|
|
start_addr,
|
|
phantom: PhantomData,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<T> ops::Deref for MMIODerefWrapper<T> {
|
|
type Target = T;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
unsafe { &*(self.start_addr as *const _) }
|
|
}
|
|
}
|