Struct esp_idf_svc::hal::i2s::config::TdmSlotConfig

source ·
pub struct TdmSlotConfig { /* private fields */ }
Expand description

TDM mode slot configuration.

To create a slot configuration, use TdmSlotConfig::philips_slot_default, TdmSlotConfig::pcm_short_slot_default, TdmSlotConfig::pcm_long_slot_default, or TdmSlotConfig::msb_slot_default, then customize it as needed.

In TDM mode, WS (word select, sometimes called LRCLK or left/right clock) becomes a frame synchronization signal that signals the first slot of a frame. The two sides of the TDM link must agree on the number of channels, data bit width, and frame synchronization pattern; this cannot be determined by examining the signal itself.

The Philips default pulls the WS line low one BCK period before the first data bit of the first slot is sent and holds it low for 50% of the frame.

TDM Philips FrameBCLKWSDIN / DOUTMSBLSBMSBLSBMSBLSBMSBLSBMSBFirst (Left) SlotsSecond (Right) Slotsbit shiftSlot 1Slot 2Slot nSlot n+1

MSB (most-significant bit) mode is similar to Philips mode, except the WS line is pulled low at the same time the first data bit of the first slot is sent. It is held low for 50% of the frame.

TDM MSB FrameBCLKWSDIN / DOUTMSBLSBMSBLSBMSBLSBMSBLSBMSBFirst (Left) SlotsSecond (Right) SlotsSlot 1Slot 2Slot nSlot n+1

PCM (pulse-code modulation) short mode pulls the WS line high one BCK period before the first data bit of the first slot is sent, keeps it high for one BCK, then pulls it low for the remainder of the frame. TDM PCM Short FrameBCLKWSDIN / DOUTMSBLSBMSBLSBMSBFramebit shiftSlot 1Slot n PCM long mode pulls the WS line high one BCK period before the first data bit of the first slot is sent, keeps it high until just before the last data bit of the first slot is sent, then pulls it low for the remainder of the frame. TDM PCM Long FrameBCLKWSDIN / DOUTMSBLSBMSBLSBMSBFramebit shiftSlot 1Slot n

Diagrams from ESP-IDF Programming Guide; rendered by Wavedrom.

Implementations§

source§

impl TdmSlotConfig

source

pub fn data_bit_width(self, data_bit_width: DataBitWidth) -> TdmSlotConfig

Update the data bit width on this TDM slot configuration.

source

pub fn slot_bit_width(self, slot_bit_width: SlotBitWidth) -> TdmSlotConfig

Update the slot bit width on this TDM slot configuration.

This is normally set to SlotBitWidth::Auto to match [data_bit_width][TdmSlotConfig::data_bit_width()].

source

pub fn slot_mask(self, slot_mask: TdmSlotMask) -> TdmSlotConfig

Update the slot mask on this TDM slot configuration.

source

pub fn ws_width(self, ws_width: u32) -> TdmSlotConfig

Update the word select signal width on this TDM slot configuration.

This sets the number of bits to keep the word select signal active at the start of each frame. If this is set to 0 (TDM_AUTO_WS_WIDTH), the word select signal will be kept active for half of the frame.

source

pub fn ws_polarity(self, ws_polarity: bool) -> TdmSlotConfig

Update the word select signal polarity on this TDM slot configuration.

Setting this to true will make the word select (WS) signal active high at the start (PCM modes). Setting this to false will make the WS signal active low at the start (Philips and MSB modes).

source

pub fn bit_shift(self, bit_shift: bool) -> TdmSlotConfig

Update the bit shift flag on this TDM slot configuration.

Setting this to true will activate the word select (WS) signal lone BCK period before the first data bit of the first slot is sent (Philips and PCM modes). Setting this to false will activate the WS signal at the same time the first data bit of the first slot is sent (MSB mode).

source

pub fn left_align(self, left_align: bool) -> TdmSlotConfig

Update the left-alignment flag on this TDM slot configuration.

This only has an effect when [slot_bit_width][TdmSlotMask::slot_bit_width()] is greater than [data_bit_width][TdmSlotMask::data_bit_width()]. Setting this to true will left-align the data in the slot and fill the right-most bits (usually the least-significant bits) with zeros. Setting this to false will right-align the data in the slot and fill the left-most bits (usually the most-significant bits) with zeros.

source

pub fn big_endian(self, big_endian: bool) -> TdmSlotConfig

Update the big-endian flag on this TDM slot configuration.

This affects the interpretation of the data when [data_bit_width][TdmSlotMask::data_bit_width()] is greater than 8. Setting this to true will interpret the data as big-endian. Setting this to false will interpret the data as little-endian (the default, and the native endian-ness of all ESP32 microcontrollers).

source

pub fn bit_order_lsb(self, bit_order_lsb: bool) -> TdmSlotConfig

Update the LSB-first flag on this TDM slot configuration.

Setting this to true will transmit data LSB-first (no known modes do this). Setting this to false will transmit data MSB-first (the default for all known modes).

source

pub fn skip_mask(self, skip_mask: bool) -> TdmSlotConfig

Update the skip mask flag on this TDM slot configuration.

Setting this to true will ignore [slot_mask][TdmSlotMask::slot_mask()] and transmit all slots. Setting this to false will respect the slot mask.

source

pub fn total_slots(self, total_slots: u32) -> TdmSlotConfig

Update the total number of slots on this TDM slot configuration.

Setting this to 0 (TDM_AUTO_SLOT_NUM) will automatically set the total number of slots to the the number of active slots in [slot_mask][TdmSlotMask::slot_mask()].

source

pub fn philips_slot_default( bits_per_sample: DataBitWidth, slot_mask: TdmSlotMask, ) -> TdmSlotConfig

Configure in Philips format with the active slots enabled by the specified mask.

source

pub fn msb_slot_default( bits_per_sample: DataBitWidth, slot_mask: TdmSlotMask, ) -> TdmSlotConfig

Configure in MSB format with the active slots enabled by the specified mask.

source

pub fn pcm_short_slot_default( bits_per_sample: DataBitWidth, slot_mask: TdmSlotMask, ) -> TdmSlotConfig

Configure in PCM (short) format with the active slots enabled by the specified mask.

source

pub fn pcm_long_slot_default( bits_per_sample: DataBitWidth, slot_mask: TdmSlotMask, ) -> TdmSlotConfig

Configure in PCM (long) format with the active slots enabled by the specified mask.

Trait Implementations§

source§

impl Clone for TdmSlotConfig

source§

fn clone(&self) -> TdmSlotConfig

Returns a copy of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for TdmSlotConfig

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl PartialEq for TdmSlotConfig

source§

fn eq(&self, other: &TdmSlotConfig) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for TdmSlotConfig

source§

impl Eq for TdmSlotConfig

source§

impl StructuralPartialEq for TdmSlotConfig

Auto Trait Implementations§

§

impl Freeze for TdmSlotConfig

§

impl RefUnwindSafe for TdmSlotConfig

§

impl Send for TdmSlotConfig

§

impl Sync for TdmSlotConfig

§

impl Unpin for TdmSlotConfig

§

impl UnwindSafe for TdmSlotConfig

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<T> CloneToUninit for T
where T: Copy,

§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.