Vs1003

Struct Vs1003 

Source
pub struct Vs1003<State, T: Vs1003Peripherals> { /* private fields */ }
Expand description

High level interface for the VS1003 audio codec

Implementations§

Source§

impl<T: Vs1003Peripherals> Vs1003<NotInitialized, T>

Source

pub fn new(peripherals: T) -> Self

Create the interface

Source§

impl<State, T: Vs1003Peripherals> Vs1003<State, T>

Source

pub fn reset_initialize( self, delay: &mut impl DelayNs, xtali: KilohertzU32, base_multiplier: ClockMultiplier, wma_boost: ClockBoost, ) -> Result<Vs1003<Initialized, T>, ModeChangeError<T>>

Reset the VS1003 and initialize it’s clock settings. Per datasheet the device supports clock rates between 12 and 13 MHz, however the configuration registers allow range 8.001 MHz - 270.14 MHz.

The datasheet also notes that the a minimum clock of 12.228 MHz is needed to support the maximum sampling frequency od 48kHz.

Note: before executing this method the SCI clock speed must be set lower than clki / 4. After executing this method the clock speed may be increased base_multiplier times.

§Blocking

This method may block for up to 50ms, assuming that delay.delay_us(10) blocks for 10us and a reasonable SPI clock speed.

§Panics

This method will panic in the provided clock frequency is outside of legal range for VS1003.

Source

pub fn is_busy(&mut self) -> Result<bool, T::Error>

Proxy for pac::Vs1003::is_busy. Returns true when the device cannot accept commands.

Source

pub fn sci(&mut self) -> &mut Vs1003<Vs1003Interface<T::TSci, T::TDreq>>

Get the SCI interface to allow custom configuration of the device

Source§

impl<T: Vs1003Peripherals> Vs1003<Initialized, T>

Source

pub fn begin_adpcm_recording( self, delay: &mut impl DelayNs, sample_rate: HertzU32, input: RecordingInput, gain: RecordingGain, filter: RecordingFilter, ) -> Result<Vs1003<AdpcmRecording, T>, ModeChangeError<T>>

Enter the ADPCM recording mode of the device.

In this mode the device will sample the input at provided rate and encode it as ADPCM

The actual sample rate may differ from requested due to divider resolution.

§Blocking

This method may block for up to 25ms, assuming that delay.delay_us(10) blocks for 10us and a reasonable SPI clock speed.

§Panics

This call will panic if the requested rate is higher than can be achieved with the configured clock. The maximum achievable rate is CLKI / 1024.

This

Source

pub fn send_data(&mut self, buffer: &[u8]) -> Result<usize, T::Error>

Write audio file data to the device. This will send as much data as the device will accept and return the number of bytes written.

If DREQ is low on entry then returns Error::Busy

Source

pub fn into_errored_state(self) -> Vs1003<Errored, T>

Changes the typestate to errored. Can be useful for simplification of retry loops.

Source§

impl<T: Vs1003Peripherals> Vs1003<AdpcmRecording, T>

Source

pub fn into_errored_state(self) -> Vs1003<Errored, T>

Changes the typestate to errored. Can be useful for simplification of retry loops.

Source

pub fn get_ready_sample_count(&mut self) -> Result<usize, T::Error>

Checks how many samples are ready to be read.

The internal buffer has size of 1024 words, so that is the maximum value you can read. The datasheet recommends to not attempt reading if you see a value >= 896 to avoid block aliasing.

Source

pub fn read_samples( &mut self, delay: &mut impl DelayNs, buffer: &mut [u16], ) -> Result<usize, T::Error>

Read however many samples the device has into the buffer. Returns the number of words read.

If you convert these sample to u8 buffers later then remeber that they need to be stored as big endian i.e. 0x1234 => 0x12 0x34 as these are not raw 16-bit samples, but rather 4, 4-bit values stored as one.

Delay is needed to have an upper bound when waiting for DREQ signal.

It is advised to always read whole blocks (128 words), so that you do not loose block synchronization. It is much better to drop a block as the compression scheme relies on blocks.

The device always puts whole blocks into the buffer.

Source

pub fn read_samples_bytes( &mut self, delay: &mut impl DelayNs, buffer: &mut [u8], ) -> Result<usize, T::Error>

Same as Self::read_samples, but takes a u8 buffer instead of u16. Returns the number of bytes read (always a multiple of 2).

See the other method for additional information.

Trait Implementations§

Source§

impl<State: Debug, T: Debug + Vs1003Peripherals> Debug for Vs1003<State, T>
where T::TSci: Debug, T::TDreq: Debug, T::TSdi: Debug, T::TRst: Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<State, T> Freeze for Vs1003<State, T>

§

impl<State, T> RefUnwindSafe for Vs1003<State, T>

§

impl<State, T> Send for Vs1003<State, T>

§

impl<State, T> Sync for Vs1003<State, T>

§

impl<State, T> Unpin for Vs1003<State, T>

§

impl<State, T> UnwindSafe for Vs1003<State, T>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.