Skip to main content

DataFormat

Enum DataFormat 

Source
pub enum DataFormat {
    Data32Channel32,
    Data32Channel24,
    Data32Channel16,
    Data32Channel8,
    Data16Channel16,
    Data16Channel8,
    Data8Channel8,
}
Expand description

Supported I2S data formats.

Each format defines two dimensions:

  • Data{X} (on-wire slot width): The number of bit-clock (BCLK) cycles allocated to each channel slot on the physical line (Self::data_bits). This determines the BCLK frequency (BCLK = sample_rate * channels * data_bits) and the time duration of each channel slot.
  • Channel{Y} (in-memory sample width): The number of active audio data bits per sample transferred to or from memory via DMA (Self::channel_bits).

§In-Memory Representation

In the DMA memory buffer, samples are stored with a size corresponding to Channel{Y}:

  • 32-bit (Channel32): 4 bytes per sample (e.g. i32 / u32).
  • 24-bit (Channel24): 3 bytes per sample (packed 24-bit PCM).
  • 16-bit (Channel16): 2 bytes per sample (e.g. i16 / u16).
  • 8-bit (Channel8): 1 byte per sample (e.g. i8 / u8).

§On-Wire Representation and Padding

On the physical I2S lines, each channel occupies Data{X} clock cycles:

  • When X == Y (e.g. Data16Channel16, Data32Channel32), the entire slot carries sample data with no padding.
  • When X > Y (e.g. Data32Channel16), the Y-bit sample occupies Y bits of the X-bit slot on the wire, and the remaining X - Y bits are padded or discarded according to Alignment:
    • Alignment::Left (default):
      • TX: The Y sample bits are transmitted first (MSB-aligned within the slot), followed by X - Y zero bits.
      • RX: The first Y bits from the wire are captured into memory; trailing bits in the slot are discarded.
    • Alignment::Right:
      • TX: X - Y zero bits are transmitted first, followed by the Y sample bits (LSB-aligned within the slot).
      • RX: The leading X - Y bits are discarded; the last Y bits of the slot are captured into memory.

Note: In this driver’s naming scheme, Data{X} refers to the on-wire slot width, and Channel{Y} refers to the in-memory sample data width. (This differs from some datasheets where the on-wire slot is called “slot width” or “channel width”, and the sample size is called “data width”.)

Variants§

§

Data32Channel32

32-bit on-wire slot width (32 BCLK cycles) and 32-bit in-memory sample width (4 bytes per sample).

§

Data32Channel24

32-bit on-wire slot width (32 BCLK cycles) and 24-bit in-memory sample width (3 bytes packed per sample).

In TX, 24-bit samples from memory are padded to 32 bits on the wire according to Alignment. In RX, 24 bits are extracted from each 32-bit slot on the wire into memory.

§

Data32Channel16

32-bit on-wire slot width (32 BCLK cycles) and 16-bit in-memory sample width (2 bytes per sample).

In TX, 16-bit samples from memory are padded to 32 bits on the wire according to Alignment. In RX, 16 bits are extracted from each 32-bit slot on the wire into memory.

§

Data32Channel8

32-bit on-wire slot width (32 BCLK cycles) and 8-bit in-memory sample width (1 byte per sample).

In TX, 8-bit samples from memory are padded to 32 bits on the wire according to Alignment. In RX, 8 bits are extracted from each 32-bit slot on the wire into memory.

§

Data16Channel16

16-bit on-wire slot width (16 BCLK cycles) and 16-bit in-memory sample width (2 bytes per sample).

§

Data16Channel8

16-bit on-wire slot width (16 BCLK cycles) and 8-bit in-memory sample width (1 byte per sample).

In TX, 8-bit samples from memory are padded to 16 bits on the wire according to Alignment. In RX, 8 bits are extracted from each 16-bit slot on the wire into memory.

§

Data8Channel8

8-bit on-wire slot width (8 BCLK cycles) and 8-bit in-memory sample width (1 byte per sample).

Implementations§

Source§

impl DataFormat

Source

pub fn data_bits(&self) -> u8

Returns the on-wire slot width in bits (number of BCLK cycles per channel slot).

Source

pub fn channel_bits(&self) -> u8

Returns the in-memory sample width in bits (active audio data bits per sample transferred via DMA).

Trait Implementations§

Source§

impl Clone for DataFormat

Available on crate feature unstable only.
Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable)§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for DataFormat

Available on crate feature unstable only.
Source§

impl Debug for DataFormat

Available on crate feature unstable only.
Source§

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

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

impl Eq for DataFormat

Available on crate feature unstable only.
Source§

impl Hash for DataFormat

Available on crate feature unstable only.
Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given [Hasher]. Read more
1.3.0§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given [Hasher]. Read more
Source§

impl PartialEq for DataFormat

Available on crate feature unstable only.
Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable)§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DataFormat

Available on crate feature unstable only.

Auto Trait Implementations§

§

impl Freeze for DataFormat

§

impl RefUnwindSafe for DataFormat

§

impl Send for DataFormat

§

impl Sync for DataFormat

§

impl Unpin for DataFormat

§

impl UnsafeUnpin for DataFormat

§

impl UnwindSafe for DataFormat

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,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.