Arduino VS1053
Loading...
Searching...
No Matches
Classes | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
arduino_vs1053::VS1053 Class Reference

Main class for controlling VS1053 and VS1003 modules. More...

#include <VS1053Driver.h>

Public Member Functions

 VS1053 (uint8_t _cs_pin, uint8_t _dcs_pin, uint8_t _dreq_pin, uint8_t _reset_pin=-1, VS1053_SPI *_p_spi=nullptr)
 Constructor which allows a custom reset pin.
 
 VS1053 (uint8_t _cs_pin, uint8_t _dcs_pin, uint8_t _dreq_pin, uint8_t _reset_pin, SPIClass &_p_spi)
 Constructor which allows a custom reset pin and a Arduino SPI object.
 
bool begin ()
 Begin operation. Sets pins correctly, and prepares SPI bus.
 
bool beginOutput ()
 Prepares for regular output in decoding mode - (note that this method is also is calling begin())
 
void startSong ()
 Prepare to start playing. Call this each time a new song starts.
 
void writeAudio (uint8_t *data, size_t len)
 Play a chunk of data. Copies the data to the chip. Blocks until complete - also supports serial midi.
 
void playChunk (uint8_t *data, size_t len)
 Legacy method - Play a chunk of data. Copies the data to the chip. Blocks until complete.
 
void stopSong ()
 Finish playing a song. Call this after the last playChunk call.
 
void setVolume (uint8_t vol)
 Set the player volume.Level from 0-100, higher is louder.
 
void setBalance (int8_t balance)
 Adjusting the left and right volume balance, higher to enhance the right side, lower to enhance the left side.
 
void setTone (uint8_t *rtone)
 Set the player baas/treble, 4 nibbles for treble gain/freq and bass gain/freq.
 
uint8_t getVolume ()
 Get the currenet volume setting, higher is louder.
 
int8_t getBalance ()
 Get the currenet balance setting (-100..100)
 
void printDetails (const char *header)
 Print configuration details to serial output.
 
void softReset ()
 Do a soft reset.
 
void hardReset ()
 Do a hardware reset.
 
bool testComm (const char *header)
 Test communication with module.
 
void adjustRate (long ppm2)
 Fine tune the data rate. More...
 
void streamModeOn ()
 Streaming Mode On. More...
 
void streamModeOff ()
 Default: Streaming Mode Off.
 
void switchToMp3Mode ()
 An optional switch preventing the module starting up in MIDI mode. More...
 
void disableI2sOut ()
 disable I2S output; this is the default state
 
void enableI2sOut (VS1053_I2S_RATE i2sRate=VS1053_I2S_RATE_48_KHZ)
 enable I2S output (GPIO4=LRCLK/WSEL; GPIO5=MCLK; GPIO6=SCLK/BCLK; GPIO7=SDATA/DOUT)
 
bool isChipConnected ()
 Checks whether the VS1053 chip is connected and is able to exchange data to the ESP. More...
 
uint16_t getChipVersion ()
 gets Version of the VLSI chip being used More...
 
uint16_t getDecodedTime ()
 Provides SCI_DECODE_TIME register value. More...
 
void clearDecodedTime ()
 Clears SCI_DECODE_TIME register (sets 0x00) More...
 
void loadUserCode (const unsigned short *plugin, unsigned short plugin_size)
 Load a patch or plugin to fix bugs and/or extend functionality. More...
 
void loadDefaultVs1053Patches ()
 Loads the latest generic firmware patch. More...
 
uint8_t treble ()
 Provides the treble amplitude value.
 
void setTreble (uint8_t value)
 Sets the treble amplitude value (range 0 to 100)
 
uint8_t bass ()
 Provides the Bass amplitude value.
 
void setBass (uint8_t value)
 Sets the bass amplitude value (range 0 to 100)
 
void setTrebleFrequencyLimit (uint16_t value)
 Sets the treble frequency limit in hz (range 0 to 15000)
 
void setBassFrequencyLimit (uint16_t value)
 Sets the bass frequency limit in hz (range 0 to 15000)
 
bool setEarSpeaker (VS1053_EARSPEAKER value)
 Activate the ear speaker mode.
 
void end ()
 Stops the recording of sound - and resets the module. More...
 
bool beginMidi ()
 Starts the MIDI output processing.
 
void sendMidiMessage (uint8_t cmd, uint8_t data1, uint8_t data2)
 performs a MIDI command More...
 
bool beginInput (VS1053Recording &opt)
 Starts the recording of sound as WAV data.
 
size_t available ()
 Provides the number of bytes which are available in the read buffer.
 
size_t readBytes (uint8_t *data, size_t len)
 Provides the audio data as WAV. More...
 
uint16_t readRegister (uint8_t _reg) const
 Reads a register value.
 
void writeRegister (uint8_t _reg, uint16_t _value) const
 Writes to VS10xx's SCI (serial command interface) SPI bus.
 

Public Attributes

const uint8_t SCI_MODE = 0x0
 
const uint8_t SCI_STATUS = 0x1
 
const uint8_t SCI_BASS = 0x2
 
const uint8_t SCI_CLOCKF = 0x3
 
const uint8_t SCI_DECODE_TIME = 0x4
 
const uint8_t SCI_AUDATA = 0x5
 
const uint8_t SCI_WRAM = 0x6
 
const uint8_t SCI_WRAMADDR = 0x7
 
const uint8_t SCI_AIADDR = 0xA
 
const uint8_t SCI_VOL = 0xB
 
const uint8_t SCI_AICTRL0 = 0xC
 
const uint8_t SCI_AICTRL1 = 0xD
 
const uint8_t SCI_AICTRL2 = 0xE
 
const uint8_t SCI_AICTRL3 = 0xF
 
const uint8_t SCI_num_registers = 0xF
 
const uint8_t SCI_HDAT0 = 0x8
 
const uint8_t SCI_HDAT1 = 0x9
 
const uint8_t SM_SDINEW = 11
 
const uint8_t SM_RESET = 2
 
const uint8_t SM_CANCEL = 3
 
const uint8_t SM_TESTS = 5
 
const uint8_t SM_LINE1 = 14
 
const uint8_t SM_STREAM = 6
 
const uint8_t SM_ADPCM = 12
 
const uint16_t ADDR_REG_GPIO_DDR_RW = 0xc017
 
const uint16_t ADDR_REG_GPIO_VAL_R = 0xc018
 
const uint16_t ADDR_REG_GPIO_ODATA_RW = 0xc019
 
const uint16_t ADDR_REG_I2S_CONFIG_RW = 0xc040
 
const uint16_t INT_ENABLE = 0xC01A
 
const uint16_t SC_MULT_53_35X = 0x8000
 
const uint16_t SC_ADD_53_10X = 0x0800
 
const uint16_t SC_EAR_SPEAKER_LO = 0x0010
 
const uint16_t SC_EAR_SPEAKER_HI = 0x0080
 

Protected Member Functions

void await_data_request () const
 
void control_mode_on () const
 
void control_mode_off () const
 
void data_mode_on () const
 
void data_mode_off () const
 
void sdi_send_buffer (uint8_t *data, size_t len)
 
void sdi_send_fillers (size_t length)
 
void wram_write (uint16_t address, uint16_t data)
 
uint16_t wram_read (uint16_t address)
 
bool begin_input_vs1053 (VS1053Recording &opt)
 
bool begin_input_vs1003 (VS1053Recording &opt)
 
void set_flag (uint16_t &value, uint16_t flag, bool active)
 

Protected Attributes

uint8_t cs_pin
 
uint8_t dcs_pin
 
uint8_t dreq_pin
 
uint8_t curvol
 
int16_t reset_pin = -1
 
int8_t curbalance = 0
 
const uint8_t vs1053_chunk_size = 32
 
VS1053_SPIp_spi = nullptr
 
uint8_t endFillByte
 
VS1053Equilizer equilizer
 
VS1053_MODE mode
 
uint16_t chip_version = -1
 
uint8_t channels_multiplier = 1
 

Detailed Description

Main class for controlling VS1053 and VS1003 modules.

Member Function Documentation

◆ adjustRate()

void arduino_vs1053::VS1053::adjustRate ( long  ppm2)

Fine tune the data rate.

Fine tune the data rate

◆ streamModeOn()

void arduino_vs1053::VS1053::streamModeOn ( )

Streaming Mode On.

VLSI datasheet: "SM_STREAM activates VS1053b’s stream mode. In this mode, data should be sent with as even intervals as possible and preferable in blocks of less than 512 bytes, and VS1053b makes every attempt to keep its input buffer half full by changing its playback speed up to 5%. For best quality sound, the average speed error should be within 0.5%, the bitrate should not exceed 160 kbit/s and VBR should not be used. For details, see Application Notes for VS10XX. This mode only works with MP3 and WAV files."

◆ switchToMp3Mode()

void arduino_vs1053::VS1053::switchToMp3Mode ( )

An optional switch preventing the module starting up in MIDI mode.

An optional switch. Most VS1053 modules will start up in MIDI mode. The result is that there is no audio when playing MP3. You can modify the board, but there is a more elegant way without soldering. No side effects for boards which do not need this switch. It means you can call it just in case.

Read more here: http://www.bajdi.com/lcsoft-vs1053-mp3-module/#comment-33773

◆ isChipConnected()

bool arduino_vs1053::VS1053::isChipConnected ( )

Checks whether the VS1053 chip is connected and is able to exchange data to the ESP.

A lightweight method to check if VS1053 is correctly wired up (power supply and connection to SPI interface).

Returns
true if the chip is wired up correctly

◆ getChipVersion()

uint16_t arduino_vs1053::VS1053::getChipVersion ( )

gets Version of the VLSI chip being used

get the Version Number for the VLSI chip VLSI datasheet: 0 for VS1001, 1 for VS1011, 2 for VS1002, 3 for VS1003, 4 for VS1053 and VS8053, 5 for VS1033, 7 for VS1103, and 6 for VS1063.

◆ getDecodedTime()

uint16_t arduino_vs1053::VS1053::getDecodedTime ( )

Provides SCI_DECODE_TIME register value.

Provides current decoded time in full seconds (from SCI_DECODE_TIME register value)

When decoding correct data, current decoded time is shown in SCI_DECODE_TIME register in full seconds. The user may change the value of this register. In that case the new value should be written twice to make absolutely certain that the change is not overwritten by the firmware. A write to SCI_DECODE_TIME also resets the byteRate calculation.

SCI_DECODE_TIME is reset at every hardware and software reset. It is no longer cleared when decoding of a file ends to allow the decode time to proceed automatically with looped files and with seamless playback of multiple files. With fast playback (see the playSpeed extra parameter) the decode time also counts faster. Some codecs (WMA and Ogg Vorbis) can also indicate the absolute play position, see the positionMsec extra parameter in section 10.11.

See also
VS1053b Datasheet (1.31) / 9.6.5 SCI_DECODE_TIME (RW)
Returns
current decoded time in full seconds

◆ clearDecodedTime()

void arduino_vs1053::VS1053::clearDecodedTime ( )

Clears SCI_DECODE_TIME register (sets 0x00)

Clears decoded time (sets SCI_DECODE_TIME register to 0x00)

The user may change the value of this register. In that case the new value should be written twice to make absolutely certain that the change is not overwritten by the firmware. A write to SCI_DECODE_TIME also resets the byteRate calculation.

◆ loadUserCode()

void arduino_vs1053::VS1053::loadUserCode ( const unsigned short *  plugin,
unsigned short  plugin_size 
)

Load a patch or plugin to fix bugs and/or extend functionality.

Load a patch or plugin

Patches can be found on the VLSI Website http://www.vlsi.fi/en/support/software/vs10xxpatches.html

Please note that loadUserCode only works for compressed plugins (file ending .plg). To include them, rename them to file ending .h Please also note that, in order to avoid multiple definitions, if you are using more than one patch, it is necessary to rename the name of the array plugin[] and the name of PLUGIN_SIZE to names of your choice. example: after renaming plugin[] to plugin_myname[] and PLUGIN_SIZE to PLUGIN_MYNAME_SIZE the method is called by loadUserCode(plugin_myname, PLUGIN_MYNAME_SIZE) It is also possible to just rename the array plugin[] to a name of your choice example: after renaming plugin[] to plugin_myname[]
the method is called by loadUserCode(plugin_myname, sizeof(plugin_myname)/sizeof(plugin_myname[0]))

◆ loadDefaultVs1053Patches()

void arduino_vs1053::VS1053::loadDefaultVs1053Patches ( )

Loads the latest generic firmware patch.

Load the latest generic firmware patch

◆ end()

void arduino_vs1053::VS1053::end ( )

Stops the recording of sound - and resets the module.

Stops the recording of sound.

◆ sendMidiMessage()

void arduino_vs1053::VS1053::sendMidiMessage ( uint8_t  cmd,
uint8_t  data1,
uint8_t  data2 
)

performs a MIDI command

send a MIDI message

a MIDI message ranges from 1 byte to three bytes the first byte consists of 4 command bits and 4 channel bits

based on talkMIDI function in MP3_Shield_RealtimeMIDI demo by Matthias Neeracher, which is based on Nathan Seidle's Sparkfun Electronics example

◆ readBytes()

size_t arduino_vs1053::VS1053::readBytes ( uint8_t *  data,
size_t  len 
)

Provides the audio data as WAV.

Provides the audio data as PCM data.


The documentation for this class was generated from the following files: