use esp_hal::dma::DmaDescriptor;
use esp_hal::dma::DmaTxBuffer;
use esp_hal::dma::Preparation;
#[cfg(feature = "iram")]
use esp_hal::ram;
use crate::framebuffer::FrameBuffer;
pub(crate) struct CircularBcmBuf {
descriptors: &'static mut [DmaDescriptor],
desc_count: usize,
}
impl CircularBcmBuf {
pub(crate) fn new(
descriptors: &'static mut [DmaDescriptor],
fb: &'static impl FrameBuffer,
) -> Self {
let planes = super::planes_from_fb(fb);
let plane_count = fb.plane_count();
let total_descs = crate::dma_descriptor_count(plane_count, planes[0].1);
debug_assert!(
descriptors.len() >= total_descs,
"not enough DMA descriptors: have {}, need {}",
descriptors.len(),
total_descs,
);
let ring_start = descriptors.as_mut_ptr();
super::fill_full_chain(
&mut descriptors[..total_descs],
&planes,
plane_count,
total_descs,
ring_start,
);
Self {
descriptors,
desc_count: total_descs,
}
}
pub(crate) fn descriptors_ptr(&self) -> *mut DmaDescriptor {
self.descriptors.as_ptr() as *mut DmaDescriptor
}
pub(crate) fn desc_count(&self) -> usize {
self.desc_count
}
}
unsafe impl Send for CircularBcmBuf {}
unsafe impl DmaTxBuffer for CircularBcmBuf {
type View = Self;
type Final = Self;
#[cfg_attr(feature = "iram", ram)]
fn prepare(&mut self) -> Preparation {
super::make_preparation(self.descriptors)
}
fn into_view(self) -> Self::View {
self
}
fn from_view(view: Self::View) -> Self::Final {
view
}
}