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>
impl<T: Vs1003Peripherals> Vs1003<NotInitialized, T>
Source§impl<State, T: Vs1003Peripherals> Vs1003<State, T>
impl<State, T: Vs1003Peripherals> Vs1003<State, T>
Sourcepub fn reset_initialize(
self,
delay: &mut impl DelayNs,
xtali: KilohertzU32,
base_multiplier: ClockMultiplier,
wma_boost: ClockBoost,
) -> Result<Vs1003<Initialized, T>, ModeChangeError<T>>
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§impl<T: Vs1003Peripherals> Vs1003<Initialized, T>
impl<T: Vs1003Peripherals> Vs1003<Initialized, T>
Sourcepub fn begin_adpcm_recording(
self,
delay: &mut impl DelayNs,
sample_rate: HertzU32,
input: RecordingInput,
gain: RecordingGain,
filter: RecordingFilter,
) -> Result<Vs1003<AdpcmRecording, T>, ModeChangeError<T>>
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
Sourcepub fn send_data(&mut self, buffer: &[u8]) -> Result<usize, T::Error>
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
Sourcepub fn into_errored_state(self) -> Vs1003<Errored, T>
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>
impl<T: Vs1003Peripherals> Vs1003<AdpcmRecording, T>
Sourcepub fn into_errored_state(self) -> Vs1003<Errored, T>
pub fn into_errored_state(self) -> Vs1003<Errored, T>
Changes the typestate to errored. Can be useful for simplification of retry loops.
Sourcepub fn get_ready_sample_count(&mut self) -> Result<usize, T::Error>
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.
Sourcepub fn read_samples(
&mut self,
delay: &mut impl DelayNs,
buffer: &mut [u16],
) -> Result<usize, T::Error>
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.
Sourcepub fn read_samples_bytes(
&mut self,
delay: &mut impl DelayNs,
buffer: &mut [u8],
) -> Result<usize, T::Error>
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.