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), theY-bit sample occupiesYbits of theX-bit slot on the wire, and the remainingX - Ybits are padded or discarded according toAlignment:Alignment::Left(default):- TX: The
Ysample bits are transmitted first (MSB-aligned within the slot), followed byX - Yzero bits. - RX: The first
Ybits from the wire are captured into memory; trailing bits in the slot are discarded.
- TX: The
Alignment::Right:- TX:
X - Yzero bits are transmitted first, followed by theYsample bits (LSB-aligned within the slot). - RX: The leading
X - Ybits are discarded; the lastYbits of the slot are captured into memory.
- TX:
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
impl DataFormat
Sourcepub fn data_bits(&self) -> u8
pub fn data_bits(&self) -> u8
Returns the on-wire slot width in bits (number of BCLK cycles per channel slot).
Sourcepub fn channel_bits(&self) -> u8
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.
impl Clone for DataFormat
unstable only.Source§fn clone(&self) -> DataFormat
fn clone(&self) -> DataFormat
1.0.0 (const: unstable)§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for DataFormat
unstable only.Source§impl Debug for DataFormat
Available on crate feature unstable only.
impl Debug for DataFormat
unstable only.impl Eq for DataFormat
unstable only.Source§impl Hash for DataFormat
Available on crate feature unstable only.
impl Hash for DataFormat
unstable only.Source§impl PartialEq for DataFormat
Available on crate feature unstable only.
impl PartialEq for DataFormat
unstable only.impl StructuralPartialEq for DataFormat
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 Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)