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
4 years ago
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||
|
//
|
||
|
// Copyright (c) 2020 Andre Richter <andre.o.richter@gmail.com>
|
||
|
|
||
|
//! Common device driver code.
|
||
|
|
||
|
use core::{marker::PhantomData, ops};
|
||
|
|
||
4 years ago
|
//--------------------------------------------------------------------------------------------------
|
||
|
// Public Definitions
|
||
|
//--------------------------------------------------------------------------------------------------
|
||
|
|
||
4 years ago
|
pub struct MMIODerefWrapper<T> {
|
||
4 years ago
|
start_addr: usize,
|
||
4 years ago
|
phantom: PhantomData<T>,
|
||
|
}
|
||
|
|
||
4 years ago
|
//--------------------------------------------------------------------------------------------------
|
||
|
// Public Code
|
||
|
//--------------------------------------------------------------------------------------------------
|
||
|
|
||
4 years ago
|
impl<T> MMIODerefWrapper<T> {
|
||
|
/// Create an instance.
|
||
4 years ago
|
pub const unsafe fn new(start_addr: usize) -> Self {
|
||
4 years ago
|
Self {
|
||
4 years ago
|
start_addr,
|
||
4 years ago
|
phantom: PhantomData,
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl<T> ops::Deref for MMIODerefWrapper<T> {
|
||
|
type Target = T;
|
||
|
|
||
|
fn deref(&self) -> &Self::Target {
|
||
4 years ago
|
unsafe { &*(self.start_addr as *const _) }
|
||
4 years ago
|
}
|
||
|
}
|