stm32/spi: add support for all word sizes.

Co-Authored-By: anton smeenk <asmeenk@planet.nl>
This commit is contained in:
Dario Nieuwenhuis
2023-04-18 20:56:23 +02:00
parent a673b9aa29
commit 2080d8bb6d
6 changed files with 197 additions and 140 deletions

View File

@ -21,6 +21,8 @@ pub use gpdma::*;
#[cfg(dmamux)]
mod dmamux;
pub mod word;
use core::mem;
use embassy_cortex_m::interrupt::Priority;
@ -36,53 +38,6 @@ enum Dir {
PeripheralToMemory,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum WordSize {
OneByte,
TwoBytes,
FourBytes,
}
impl WordSize {
pub fn bytes(&self) -> usize {
match self {
Self::OneByte => 1,
Self::TwoBytes => 2,
Self::FourBytes => 4,
}
}
}
mod word_sealed {
pub trait Word {}
}
pub trait Word: word_sealed::Word {
fn bits() -> WordSize;
}
impl word_sealed::Word for u8 {}
impl Word for u8 {
fn bits() -> WordSize {
WordSize::OneByte
}
}
impl word_sealed::Word for u16 {}
impl Word for u16 {
fn bits() -> WordSize {
WordSize::TwoBytes
}
}
impl word_sealed::Word for u32 {}
impl Word for u32 {
fn bits() -> WordSize {
WordSize::FourBytes
}
}
pub struct NoDma;
impl_peripheral!(NoDma);