Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose qemu_crate macro. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 13 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use core::fmt;
use core::marker::PhantomData;
use core::ops::Deref;
use cortex_m::interrupt;
pub use cortex_m::interrupt;
use embedded_hal::serial;
use nb;
use volatile_register::{RO, RW, WO};
Expand Down Expand Up @@ -278,6 +278,8 @@ impl<T> serial::Write<u8> for PL011<T>
}
}

/// Create a new UART
#[macro_export]
macro_rules! create_uart {
(
$(#[$attr:meta])* struct $uart:ident,
Expand All @@ -286,20 +288,20 @@ macro_rules! create_uart {
) => {
$(#[$attr])*
pub struct $uart {
_marker: PhantomData<*const ()>,
_marker: core::marker::PhantomData<*const ()>,
}
impl detail::ConstRegBlockPtr<PL011_Regs> for $uart {
impl $crate::detail::ConstRegBlockPtr<$crate::PL011_Regs> for $uart {
/// returns a pointer to the register block
fn ptr() -> *const PL011_Regs {
fn ptr() -> *const $crate::PL011_Regs {
$addr as *const _
}
}
unsafe impl Send for $uart {}
impl Deref for $uart {
type Target = PL011_Regs;
impl core::ops::Deref for $uart {
type Target = $crate::PL011_Regs;
#[inline(always)]
fn deref(&self) -> &Self::Target {
use crate::detail::ConstRegBlockPtr;
use $crate::detail::ConstRegBlockPtr;
unsafe {&* $uart::ptr()}
}
}
Expand All @@ -309,7 +311,7 @@ macro_rules! create_uart {
///
/// Can only be taken once. If taken again returns None
pub fn take() -> Option<Self> {
interrupt::free(|_| {
$crate::interrupt::free(|_| {
if unsafe {$global} {
None
} else {
Expand All @@ -322,7 +324,7 @@ macro_rules! create_uart {
/// Should not be needed if properly passing around the uart
pub unsafe fn steal() -> Self {
$global = true;
$uart {_marker : PhantomData}
$uart {_marker: core::marker::PhantomData }
}
}
}
Expand All @@ -344,7 +346,8 @@ create_uart!(
struct UART4,
UART4_TAKEN, 0x4000_f000);

mod detail {
/// Implementation details for register block.
pub mod detail {
/// Trait to indicate that the following type always points to a fixed hardware resource
///
/// This trait is used since there is a uniqe type for each UART
Expand Down