#![macro_use]
use embassy_hal_internal::{impl_peripheral, Peripheral};
mod dma;
pub use dma::*;
mod util;
pub(crate) use util::*;
pub(crate) mod ringbuffer;
pub mod word;
pub use crate::_generated::Request;
pub(crate) trait SealedChannel {
fn id(&self) -> u8;
}
pub(crate) trait ChannelInterrupt {
#[cfg_attr(not(feature = "rt"), allow(unused))]
unsafe fn on_irq();
}
#[allow(private_bounds)]
pub trait Channel: SealedChannel + Peripheral<P = Self> + Into<AnyChannel> + 'static {
#[inline]
fn degrade(self) -> AnyChannel {
AnyChannel { id: self.id() }
}
}
pub struct AnyChannel {
pub(crate) id: u8,
}
impl_peripheral!(AnyChannel);
impl AnyChannel {
fn info(&self) -> ChannelInfo {
ChannelInfo { dma: crate::pac::DMAC1, num: self.id as _ }
}
}
impl SealedChannel for AnyChannel {
fn id(&self) -> u8 {
self.id
}
}
macro_rules! dma_channel_impl {
($channel_peri:ident, $index:expr) => {
impl crate::dma::SealedChannel for crate::peripherals::$channel_peri {
fn id(&self) -> u8 {
$index
}
}
impl crate::dma::ChannelInterrupt for crate::peripherals::$channel_peri {
unsafe fn on_irq() {
crate::dma::AnyChannel { id: $index }.on_irq();
}
}
impl crate::dma::Channel for crate::peripherals::$channel_peri {}
impl From<crate::peripherals::$channel_peri> for crate::dma::AnyChannel {
fn from(x: crate::peripherals::$channel_peri) -> Self {
crate::dma::Channel::degrade(x)
}
}
};
}
impl Channel for AnyChannel {}
use crate::_generated::CHANNEL_COUNT;
static STATE: [dma::ChannelState; CHANNEL_COUNT] = [dma::ChannelState::NEW; CHANNEL_COUNT];
pub(crate) unsafe fn init(cs: critical_section::CriticalSection) {
dma::init(cs);
}
pub struct NoDma;
impl_peripheral!(NoDma);