use crate::sealed::Sealed;
#[derive(Debug, Clone, Copy)]
pub struct Master;
#[derive(Debug, Clone, Copy)]
pub struct Slave;
#[derive(Debug, Clone, Copy)]
pub struct Transmit;
#[derive(Debug, Clone, Copy)]
pub struct Receive;
#[derive(Debug, Clone, Copy)]
pub struct Data16Channel16;
#[derive(Debug, Clone, Copy)]
pub struct Data16Channel32;
#[derive(Debug, Clone, Copy)]
pub struct Data24Channel32;
#[derive(Debug, Clone, Copy)]
pub struct Data32Channel32;
#[derive(Debug, Clone, Copy)]
pub struct Philips;
#[derive(Debug, Clone, Copy)]
pub struct Msb;
#[derive(Debug, Clone, Copy)]
pub struct Lsb;
#[derive(Debug, Clone, Copy)]
pub struct PcmShortSync;
#[derive(Debug, Clone, Copy)]
pub struct PcmLongSync;
#[derive(Debug, Clone, Copy)]
pub struct Main;
#[derive(Debug, Clone, Copy)]
pub struct Ext;
impl Sealed for Master {}
impl Sealed for Slave {}
impl Sealed for Transmit {}
impl Sealed for Receive {}
impl Sealed for Data16Channel16 {}
impl Sealed for Data16Channel32 {}
impl Sealed for Data24Channel32 {}
impl Sealed for Data32Channel32 {}
impl Sealed for Philips {}
impl Sealed for Msb {}
impl Sealed for Lsb {}
impl Sealed for PcmShortSync {}
impl Sealed for PcmLongSync {}
impl Sealed for Main {}
impl Sealed for Ext {}
pub trait Direction: Sealed {
const VALUE: crate::driver::TransmitOrReceive;
}
impl Direction for Transmit {
const VALUE: crate::driver::TransmitOrReceive = crate::driver::TransmitOrReceive::Transmit;
}
impl Direction for Receive {
const VALUE: crate::driver::TransmitOrReceive = crate::driver::TransmitOrReceive::Receive;
}
pub trait Data16: Sealed {}
impl Data16 for Data16Channel16 {}
impl Data16 for Data16Channel32 {}
pub trait DataFormat: Sealed {
const VALUE: crate::driver::DataFormat;
type AudioFrame: Default;
}
macro_rules! impl_data_format{
($(($marker:ident,$audio_frame:ty)),*) => {
$(
impl DataFormat for $marker {
const VALUE: crate::driver::DataFormat = crate::driver::DataFormat::$marker;
type AudioFrame = $audio_frame;
}
)*
};
}
impl_data_format!(
(Data16Channel16, (i16, i16)),
(Data16Channel32, (i16, i16)),
(Data24Channel32, (i32, i32)),
(Data32Channel32, (i32, i32))
);
pub trait I2sStandard: Sealed {
const VALUE: crate::driver::I2sStandard;
const WS_START_LEVEL: bool;
}
macro_rules! impl_i2s_standard{
($(($marker:ident,$ws_start_level:literal)),*) => {
$(
impl I2sStandard for $marker {
const VALUE: crate::driver::I2sStandard = crate::driver::I2sStandard::$marker;
const WS_START_LEVEL: bool = $ws_start_level;
}
)*
};
}
impl_i2s_standard!(
(Philips, false),
(Msb, true),
(Lsb, true),
(PcmShortSync, true),
(PcmLongSync, true)
);
pub trait ChannelFlag: I2sStandard + Sealed {}
impl ChannelFlag for Philips {}
impl ChannelFlag for Msb {}
impl ChannelFlag for Lsb {}
pub trait NoChannelFlag: I2sStandard + Sealed {}
impl NoChannelFlag for PcmShortSync {}
impl NoChannelFlag for PcmLongSync {}