Nut/OS  4.10.3
API Reference
VLSI VS Driver
Collaboration diagram for VLSI VS Driver:

Data Structures

struct  _VS_PLUGIN_INFO
struct  VS_HEADERINFO
struct  _VSDCB
 Internal codec control block. More...

Defines

#define AUDIO0_DAC_MIN_GAIN   -127
#define AUDIO0_DAC_MAX_GAIN   0
#define AUDIO_DAC_MIN_GAIN   AUDIO0_DAC_MIN_GAIN
#define AUDIO_DAC_MAX_GAIN   AUDIO0_DAC_MAX_GAIN
#define AUDIO_DAC_MAX_TREB   8
#define AUDIO_DAC_MAX_TFIN   15
#define AUDIO_DAC_MAX_BASS   15
#define AUDIO_DAC_MAX_BFIN   15
#define AUDIO_SETWRITETIMEOUT   0x010d
#define AUDIO_GETWRITETIMEOUT   0x010e
#define AUDIO_PLAY   0x3001
 Immediately start playing.
#define AUDIO_CANCEL   0x3002
 Immediately stop playing and discard buffer.
#define AUDIO_GET_STATUS   0x3003
#define AUDIO_GET_PLAYGAIN   0x3004
#define AUDIO_SET_PLAYGAIN   0x3005
#define AUDIO_GET_PBSIZE   0x3006
#define AUDIO_SET_PBSIZE   0x3007
#define AUDIO_GET_PBLEVEL   0x3008
#define AUDIO_GET_PBWLOW   0x3009
#define AUDIO_SET_PBWLOW   0x300A
#define AUDIO_GET_PBWHIGH   0x300B
#define AUDIO_SET_PBWHIGH   0x300C
#define AUDIO_BEEP   0x300F
#define AUDIO_GET_DECINFO   0x3010
 Retrieve decoder information.
#define AUDIO_GET_DECCAPS   0x3011
 Retrieve decoder capabilities.
#define AUDIO_GET_DECFMTS   0x3012
 Retrieve decoder formats.
#define AUDIO_FMT_PLUGIN   0x00000001
#define AUDIO_FMT_WAV_PCM   0x00000002
#define AUDIO_FMT_WAV_ADPCM   0x00000004
#define AUDIO_FMT_WAV_IMA_ADPCM   0x00000008
#define AUDIO_FMT_VORBIS   0x00000100
#define AUDIO_FMT_MPEG1_L1   0x00001000
#define AUDIO_FMT_MPEG1_L2   0x00002000
#define AUDIO_FMT_MPEG1_L3   0x00004000
#define AUDIO_FMT_MPEG2_AAC   0x00010000
#define AUDIO_FMT_MPEG4_AAC   0x00020000
#define AUDIO_FMT_WMA_V2   0x00100000
#define AUDIO_FMT_WMA_V7   0x00200000
#define AUDIO_FMT_WMA_V8   0x00400000
#define AUDIO_FMT_WMA_V9   0x00800000
#define AUDIO_SET_DECFMTS   0x3013
 Enable or disable specific decoder formats.
#define AUDIO_GET_CODINFO   0x3014
 Retrieve encoder information.
#define AUDIO_GET_CODCAPS   0x3015
 Retrieve encoder capabilities.
#define AUDIO_GET_CODFMTS   0x3016
 Retrieve encoder formats.
#define AUDIO_SET_CODFMTS   0x3017
 Enable or disable specific encoder formats.
#define AUDIO_GET_MIDINFO   0x3018
 Retrieve midi information.
#define AUDIO_GET_MIDCAPS   0x3019
 Retrieve midi capabilities.
#define AUDIO_FMT_GMIDI1   0x00000001
#define AUDIO_FMT_GMIDI2   0x00000002
#define AUDIO_FMT_SPMIDI0   0x00000004
#define AUDIO_SET_TREB   0x301a
 Set audio enhancement treble value.
#define AUDIO_GET_TREB   0x301b
 Get audio enhancement treble value.
#define AUDIO_SET_TFIN   0x301c
 Set audio enhancement treble frequency.
#define AUDIO_GET_TFIN   0x301d
 Get audio enhancement treble frequency.
#define AUDIO_SET_BASS   0x301e
 Set audio enhancement bass value.
#define AUDIO_GET_BASS   0x301f
 Get audio enhancement bass value.
#define AUDIO_SET_BFIN   0x3020
 Set audio enhancement bass frequency.
#define AUDIO_GET_BFIN   0x3021
 Get audio enhancement bass frequency.
#define AUDIO_PLUGIN_UPLOAD   0x3030
 Upload plug-in.
#define AUDIO_IRQ_ENABLE   0x3031
 Enable interrupts.
#define AUDIO_SET_ICLOCK   0x3032
 Set internal clock.
#define VS_OPCODE_READ   3
#define VS_OPCODE_WRITE   2
#define VS_FLUSH_BYTES   2048
 Application register 0 index.
#define CODEC_STATUS_IDLE   0
#define CODEC_STATUS_PLAYING   1
#define CODEC_STATUS_RECORDING   2
#define VSCODEC_CMD_TIMEOUT   NUT_WAIT_INFINITE
 Minimum time in milliseconds to held hardware reset low.
#define VSCODEC_DATA_CHUNK_SIZE   32
 Number of data bytes we can send without checking DREQ.
#define AUDIO_VS1001K
#define VS10XX_FREQ   12288000UL
 Decoder crystal frequency.
#define VS10XX_HWRST_DURATION   1
 Minimum time in milliseconds to held hardware reset low.
#define VS10XX_HWRST_RECOVER   4
 Milliseconds to wait after hardware reset.
#define VS10XX_SWRST_RECOVER   2
 Milliseconds to wait after software reset.
#define VS10XX_SCI_MODE   0
#define VS10XX_SCI_RATE   (VS10XX_FREQ / 6)
#define VS10XX_SDI_MODE   0
#define VS10XX_SDI_RATE   (VS10XX_FREQ / 6)
#define VSREQ_PLAY   0x00000001
#define VSREQ_CANCEL   0x00000002
#define VSREQ_BEEP   0x00000004

Typedefs

typedef struct _VS_PLUGIN_INFO VS_PLUGIN_INFO
typedef struct _VSDCB VSDCB
 Internal codec control block.
typedef struct _VSDCB VSDCB

Functions

int VsCodecWaitReady (NUTDEVICE *dev, uint32_t tmo)
 Wait until codec is ready.
uint16_t VsCodecReg (NUTDEVICE *dev, uint_fast8_t op, uint_fast8_t reg, uint_fast16_t val)
uint16_t VsCodecMode (NUTDEVICE *dev, uint_fast16_t flags, uint_fast16_t mask)
 Read and modify VLSI audio codec mode flags.
int VsDecoderSetVolume (NUTDEVICE *dev, int left, int right)
 Set volume.
int VsDecoderSetBass (NUTDEVICE *dev, int treb, int tfin, int bass, int bfin)
 Set Bass.
uint16_t VsCodecBeep (NUTDEVICE *dev, uint16_t fsin)
 Start or stop sine wave beeper.
int VsDecoderBufferInit (NUTDEVICE *dev, uint32_t size)
void FeederThread (void *arg)
int VsCodecIOCtl (NUTDEVICE *dev, int req, void *conf)
 Handle I/O controls for audio codec.
int VsCodecRead (NUTFILE *nfp, void *data, int len)
 Read from the encoder.
int VsCodecWrite (NUTFILE *nfp, CONST void *data, int len)
 Write to decoder.
int VsCodecWrite_P (NUTFILE *nfp, PGM_P buffer, int len)
 Write program data to decoder.
NUTFILEVsCodecOpen (NUTDEVICE *dev, CONST char *name, int mode, int acc)
int VsCodecClose (NUTFILE *nfp)

Variables

uint8_t zero_chunk [VSCODEC_DATA_CHUNK_SIZE]
NUTDEVICE devVsCodec
 VS10XX device information structure.
NUTDEVICE devSpiVsCodec0
uint8_t zero_chunk [VSCODEC_DATA_CHUNK_SIZE]
NUTDEVICE devVsCodec
 VS10XX device information structure.

Mode Control Register

#define VS_MODE_REG   0
 Register index.
#define VS_SM_DIFF   0x0001
 Left channel inverted.
#define VS_SM_RESET   0x0004
 Allow MPEG Layers I & II.
#define VS_SM_DACT   0x0100
 VS1001 MPEG Layers I & II enable.
#define VS_SM_BITORD   0x0200
 Data bus bit order.
#define VS_SM_SDIORD   0x0200
 SDI most significant bit last.

Status Register

VS1001K master mode.

Untested and not recommended.

Note, that this bit is available on the VS1001 only and is used as a chip select mode flag on other members of the VS10xx family.

Share SPI chip select.

VS1001K master mode clock speed.

Untested and not recommended.

Note, that this bit is available on the VS1001 only and is used as an SDI mode flag on other members of the VS10xx family.

VS1002 native SDI mode.

Default is 0 on the VS1011E and 1 on the VS1002.

Not available on the VS1001K.

ADPCM recording.

Available on VS1033 and VS1053.

ADPCM high pass filter.

If set at the same time as VS_SM_ADPCM and VS_SM_RESET, ADPCM mode will start with a high-pass filter. This may help intelligibility of speech when there is lots of background noise.

Available on VS1033.

ADPCM recording selector.

Used to select the input for ADPCM recording. If cleared, microphone input is used. If set to 1, LINEIN is used instead.

Available on VS1033 and VS1053.

Input clock range.

Activates a clock divider at the XTAL input. Should be set as soon as possible after a chip reset.

Available on VS1033 and VS1053.

#define VS_STATUS_REG   1
 Register index.
#define VS_SS_APDOWM1   0x0004
 Internal analog volume control mask.
#define VS_SS_APDOWN2   0x0008
 Analog driver power down.
#define VS_SS_VER   0x00F0
 Version mask.
#define VS_SS_VER_LSB   4
 Version LSB.
#define VS1001_SS_VER   0
#define VS1011_SS_VER   1
#define VS1011E_SS_VER   2
#define VS1002_SS_VER   2
#define VS1003_SS_VER   3
#define VS1053_SS_VER   4
#define VS1033_SS_VER   5
#define VS1103_SS_VER   7

Clock Frequency and Multiplier Register

Register index.

On some earlier chips, audio interrupts may be missed when writing to this register.

For the VS1001K see VS_SM_BASS.

#define VS_CLOCKF_REG   3
 Register index.

Decode Time Register

Clock frequency mask.

Should be set to crystal clock divided by 2000, if the clock is not 24.576 MHz.

Must be set before beginning decoding MP3 data. Otherwise the sample rate will not be set correctly.

Used for the VS1001, VS1011 and VS1002.

VS1003/VS1033 clock frequency mask.

Should be set to crystal clock divided by 4000, if the clock is not 12.288 MHz.

Used for the VS1003, VS1033 and VS1053.

Allowed multiplier addition.

Used for WMA decoding with the VS1003, VS1033 and VS1053.

Summand 0.5 is not available on the VS1053.

Clock multiplier.

Available on the VS1003, VS1033 and VS1053. However, multiplier 1.5 is not available on the VS1053.

Clock doubler enable.

Used for the VS1001, VS1011 and VS1002.

#define VS_DECODE_TIME_REG   4
 Register index.

Miscellaneous Audio Data Register

#define VS_AUDATA_REG   5
 Register index.
#define VS_AD_STEREO   0x8000
 Stereo flag.

RAM Read/Write Register

Current sampling rate mask.

Value is sample rate divided by 2. Writing to this register will change the sample rate on the run.

To reduce the digital power consumption when idle, you can set a low sample rate.

Current bit rate mask.

Current sampling rate index mask.

#define VS_WRAM_REG   6
 Register index.

RAM Read/Write Base Address Register

#define VS_WRAMADDR_REG   7
 Register index.

Application Start Address Register

Register index.

Used to activate previously uploaded application programs.

#define VS_AIADDR_REG   10
 Register index.

Volume Control Register

#define VS_VOL_REG   11
 Register index.
#define VS_VOL_RIGHT   0x00FF
 Right channel volume mask.
#define VS_VOL_RIGHT_LSB   0
 Right channel volume LSB.
#define VS_VOL_LEFT   0xFF00
 Right channel volume mask.
#define VS_VOL_LEFT_LSB   8
 Right channel volume LSB.
#define VS_VOL_MAX   0x0000
#define VS_VOL_MIN   0xFEFE
#define VS_VOL_OFF   0xFFFF

Internal Command Flags

#define VSREQ_PLAY   0x00000001
 Force immediate player start.
#define VSREQ_CANCEL   0x00000002
 Force immediate player stop.
#define VSREQ_VOLUPD   0x00000004
 Volume update.
#define VSREQ_AUDIOE   0x00000008
 Audio enhancement update.
#define VSREQ_BEEP   0x00000010
 Sine wave test.
#define VSREQ_RECORD   0x00000020
 Start recording.

Define Documentation

#define AUDIO0_DAC_MIN_GAIN   -127

Definition at line 95 of file vscodec.h.

#define AUDIO0_DAC_MAX_GAIN   0

Definition at line 98 of file vscodec.h.

#define AUDIO_DAC_MIN_GAIN   AUDIO0_DAC_MIN_GAIN

Definition at line 103 of file vscodec.h.

#define AUDIO_DAC_MAX_GAIN   AUDIO0_DAC_MAX_GAIN

Definition at line 106 of file vscodec.h.

#define AUDIO_DAC_MAX_TREB   8

Definition at line 111 of file vscodec.h.

Referenced by VsDecoderSetBass().

#define AUDIO_DAC_MAX_TFIN   15

Definition at line 115 of file vscodec.h.

Referenced by VsDecoderSetBass().

#define AUDIO_DAC_MAX_BASS   15

Definition at line 119 of file vscodec.h.

Referenced by VsDecoderSetBass().

#define AUDIO_DAC_MAX_BFIN   15

Definition at line 123 of file vscodec.h.

Referenced by VsDecoderSetBass().

#define AUDIO_SETWRITETIMEOUT   0x010d

Definition at line 129 of file vscodec.h.

#define AUDIO_GETWRITETIMEOUT   0x010e

Definition at line 130 of file vscodec.h.

#define AUDIO_PLAY   0x3001

Immediately start playing.

Definition at line 133 of file vscodec.h.

#define AUDIO_CANCEL   0x3002

Immediately stop playing and discard buffer.

Definition at line 135 of file vscodec.h.

#define AUDIO_GET_STATUS   0x3003

Definition at line 136 of file vscodec.h.

#define AUDIO_GET_PLAYGAIN   0x3004

Definition at line 137 of file vscodec.h.

#define AUDIO_SET_PLAYGAIN   0x3005

Definition at line 138 of file vscodec.h.

#define AUDIO_GET_PBSIZE   0x3006

Definition at line 139 of file vscodec.h.

#define AUDIO_SET_PBSIZE   0x3007

Definition at line 140 of file vscodec.h.

#define AUDIO_GET_PBLEVEL   0x3008

Definition at line 141 of file vscodec.h.

#define AUDIO_GET_PBWLOW   0x3009

Definition at line 142 of file vscodec.h.

#define AUDIO_SET_PBWLOW   0x300A

Definition at line 143 of file vscodec.h.

#define AUDIO_GET_PBWHIGH   0x300B

Definition at line 144 of file vscodec.h.

#define AUDIO_SET_PBWHIGH   0x300C

Definition at line 145 of file vscodec.h.

#define AUDIO_BEEP   0x300F

Definition at line 146 of file vscodec.h.

#define AUDIO_GET_DECINFO   0x3010

Retrieve decoder information.

Definition at line 148 of file vscodec.h.

#define AUDIO_GET_DECCAPS   0x3011

Retrieve decoder capabilities.

Definition at line 150 of file vscodec.h.

#define AUDIO_GET_DECFMTS   0x3012

Retrieve decoder formats.

Definition at line 152 of file vscodec.h.

#define AUDIO_FMT_PLUGIN   0x00000001

Definition at line 153 of file vscodec.h.

#define AUDIO_FMT_WAV_PCM   0x00000002

Definition at line 154 of file vscodec.h.

#define AUDIO_FMT_WAV_ADPCM   0x00000004

Definition at line 155 of file vscodec.h.

#define AUDIO_FMT_WAV_IMA_ADPCM   0x00000008

Definition at line 156 of file vscodec.h.

Referenced by VsCodecOpen().

#define AUDIO_FMT_VORBIS   0x00000100

Definition at line 157 of file vscodec.h.

Referenced by VsCodecOpen(), and VsCodecRead().

#define AUDIO_FMT_MPEG1_L1   0x00001000

Definition at line 158 of file vscodec.h.

#define AUDIO_FMT_MPEG1_L2   0x00002000

Definition at line 159 of file vscodec.h.

#define AUDIO_FMT_MPEG1_L3   0x00004000

Definition at line 160 of file vscodec.h.

#define AUDIO_FMT_MPEG2_AAC   0x00010000

Definition at line 161 of file vscodec.h.

#define AUDIO_FMT_MPEG4_AAC   0x00020000

Definition at line 162 of file vscodec.h.

#define AUDIO_FMT_WMA_V2   0x00100000

Definition at line 163 of file vscodec.h.

#define AUDIO_FMT_WMA_V7   0x00200000

Definition at line 164 of file vscodec.h.

#define AUDIO_FMT_WMA_V8   0x00400000

Definition at line 165 of file vscodec.h.

#define AUDIO_FMT_WMA_V9   0x00800000

Definition at line 166 of file vscodec.h.

#define AUDIO_SET_DECFMTS   0x3013

Enable or disable specific decoder formats.

Definition at line 169 of file vscodec.h.

#define AUDIO_GET_CODINFO   0x3014

Retrieve encoder information.

Definition at line 171 of file vscodec.h.

#define AUDIO_GET_CODCAPS   0x3015

Retrieve encoder capabilities.

Definition at line 173 of file vscodec.h.

#define AUDIO_GET_CODFMTS   0x3016

Retrieve encoder formats.

Definition at line 175 of file vscodec.h.

#define AUDIO_SET_CODFMTS   0x3017

Enable or disable specific encoder formats.

Definition at line 177 of file vscodec.h.

#define AUDIO_GET_MIDINFO   0x3018

Retrieve midi information.

Definition at line 179 of file vscodec.h.

#define AUDIO_GET_MIDCAPS   0x3019

Retrieve midi capabilities.

Definition at line 181 of file vscodec.h.

#define AUDIO_FMT_GMIDI1   0x00000001

Definition at line 182 of file vscodec.h.

#define AUDIO_FMT_GMIDI2   0x00000002

Definition at line 183 of file vscodec.h.

#define AUDIO_FMT_SPMIDI0   0x00000004

Definition at line 184 of file vscodec.h.

#define AUDIO_SET_TREB   0x301a

Set audio enhancement treble value.

Definition at line 186 of file vscodec.h.

Referenced by VsCodecIOCtl().

#define AUDIO_GET_TREB   0x301b

Get audio enhancement treble value.

Definition at line 188 of file vscodec.h.

#define AUDIO_SET_TFIN   0x301c

Set audio enhancement treble frequency.

Definition at line 190 of file vscodec.h.

Referenced by VsCodecIOCtl().

#define AUDIO_GET_TFIN   0x301d

Get audio enhancement treble frequency.

Definition at line 192 of file vscodec.h.

#define AUDIO_SET_BASS   0x301e

Set audio enhancement bass value.

Definition at line 194 of file vscodec.h.

Referenced by VsCodecIOCtl().

#define AUDIO_GET_BASS   0x301f

Get audio enhancement bass value.

Definition at line 196 of file vscodec.h.

#define AUDIO_SET_BFIN   0x3020

Set audio enhancement bass frequency.

Definition at line 198 of file vscodec.h.

Referenced by VsCodecIOCtl().

#define AUDIO_GET_BFIN   0x3021

Get audio enhancement bass frequency.

Definition at line 200 of file vscodec.h.

#define AUDIO_PLUGIN_UPLOAD   0x3030

Upload plug-in.

Definition at line 203 of file vscodec.h.

Referenced by VsCodecIOCtl().

#define AUDIO_IRQ_ENABLE   0x3031

Enable interrupts.

Definition at line 206 of file vscodec.h.

Referenced by VsCodecOpen().

#define AUDIO_SET_ICLOCK   0x3032

Set internal clock.

Definition at line 209 of file vscodec.h.

#define VS_OPCODE_READ   3

Definition at line 221 of file vscodec.h.

#define VS_OPCODE_WRITE   2

Definition at line 222 of file vscodec.h.

#define VS_MODE_REG   0

Register index.

Definition at line 230 of file vscodec.h.

#define VS_SM_DIFF   0x0001

Left channel inverted.

Definition at line 232 of file vscodec.h.

#define VS_SM_RESET   0x0004

Allow MPEG Layers I & II.

Determines whether it is allowed to decode MPEG 1 and 2 Layers I and II in addition to Layer III. If you enable Layer I and Layer II decoding, you are liable for any patent issues that may arise. Joint licensing of MPEG 1.0 / 2.0 Layer III does not cover all patents pertaining to Layers I and II.

VS1001K fast forward.

By setting this bit, the player starts to accept data at a high speed, and just decodes the audio headers silently without playing any audio data. This can be used to fast-forward data with safe landing. Register VS_DECODE_TIME_REG is updated during a fast-forward just as normal.

Note, that this bit is available on the VS1001K only and is used as MPEG Layer I & II enable on other members of the VS10xx family.

Soft reset.

Bit is cleared automatically.

Definition at line 265 of file vscodec.h.

#define VS_SM_DACT   0x0100

VS1001 MPEG Layers I & II enable.

This bit is marked unused in later VS1001 datasheet versions and may not work due to firmware problems.

Note, that this bit was available on the VS1001K only and is used as a cancel flag on other members of the VS10xx family.

If you enable Layer I and Layer II decoding, you are liable for any patent issues that may arise.

Jump out of wave decoding.

Set this bit to stop WAV, WMA and MIDI file playing before the end of the file has been reached. Continue sending zeros for WAV and more data for MIDI and WMA until this bit is cleared again.

Not available on the VS1001K.

Stop decoding in the middle.

Set this bit to stop decoding a in the middle, and continue sending data honouring DREQ. When this flag is detected by a codec, it will stop decoding and discard stream buffer content. The flag is cleared automatically and SCI HDAT1 will also be cleared.

Available on the VS1053.

Power down.

During powerdown, no audio is played and no SDI operations are performed. It is recommended to set VS_VOL_REG to 0xFFFF before setting this bit.

For best power down efficiency, activate hardware reset.

Not available on the VS1011. Although defined, this is not implemented in the VS1001K firmware.

EarSpeaker spatial processing.

VS1001K DAC mode.

16-bit DAC mode if set, MP3 mode otherwise.

This bit is marked unused in later VS1001 datasheet versions and may not work due to firmware problems.

Note, that this bit was available on the VS1001 only and is used as a test mode flag on other members of the VS10xx family.

Allow SDI tests.

Not required for the VS1001K, where tests are enabled by default.

VS1001K DAC mono mode.

DAC mono mode if set, stereo mode otherwise.

This bit is marked unused in later VS1001 datasheet versions and may not work due to firmware problems.

Note, that this bit was available on the VS1001 only and is used as a streaming mode flag on other members of the VS10xx family.

Stream mode.

When stream mode is activated, data should be sent with as even intervals as possible (and preferable with data blocks of less than 512 bytes). The decoder makes every attempt to keep its input buffer half full by changing its playback speed upto 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.

Not available on the VS1001K.

VS1001K bass/treble enhancer.

When set, this bit turns on the built-in bass and treble enhancer.

Active edge of the data clock.

If clear data is read at the rising edge, and if set data is read at the falling edge.

Definition at line 401 of file vscodec.h.

#define VS_SM_BITORD   0x0200

Data bus bit order.

When clear the most significant bit is sent first, which is the default. This register bit has no effect on the SCI bus.

Definition at line 408 of file vscodec.h.

#define VS_SM_SDIORD   0x0200

SDI most significant bit last.

Same as VS_SM_BITORD.

Definition at line 414 of file vscodec.h.

#define VS_STATUS_REG   1

Register index.

Definition at line 503 of file vscodec.h.

#define VS_SS_APDOWM1   0x0004

Internal analog volume control mask.

These bits is meant to be used by the internal firmware only.

  • 0 for 0 dB
  • 1 for -6 dB
  • 3 for -12 dB

Reference voltage selection.

If AVDD is at least higher than 3.3V, then this bit can be set to select 1.65V reference voltage to increase the analog output swing.

See VS_SS_AD_CLOCK for more information about using this bit with the VS1053b.

AD clock divider.

This bit can be set to divide the AD modulator frequency by 2.

Due to a firmware bug in VS1053b, volume calculation routine clears VS_SS_AD_CLOCK and VS_SS_VREF_1_65 bits. Write to VS_STATUS_REG or VS_VOL_REG as well as sample rate change with bass enhancer or treble control actived, causes the volume calculation routine to be called.

As a workaround you can write to VS_STATUS_REG through VS_WRAMADDR_REG and VS_WRAM_REG after each volume change. Write 0xC001 to VS_WRAMADDR_REG, then write the value to VS_WRAM_REG. However, the difference in performance between the modes is not significant, so it is easier to just use the default mode.

Internal analog power down.

This bit is meant to be used by the internal firmware only.

Definition at line 555 of file vscodec.h.

#define VS_SS_APDOWN2   0x0008

Analog driver power down.

This bit is typically controlled by the internal firmware. However, if the application wants to power down the VS1001 and VS1011 with a minimum power-off transient, this bit should be set to 1 a few milliseconds before activating reset.

With newer chips set the volume register to 0xFFFF a few milliseconds before reset.

Definition at line 567 of file vscodec.h.

#define VS_SS_VER   0x00F0

Version mask.

  • 0 for VS1001
  • 1 for VS1011
  • 2 for VS1002 and VS1011E, see VS_SM_SDINEW
  • 3 for VS1003
  • 4 for VS1053
  • 5 for VS1033
  • 7 for VS1103

Definition at line 579 of file vscodec.h.

#define VS_SS_VER_LSB   4

Version LSB.

Definition at line 581 of file vscodec.h.

#define VS1001_SS_VER   0

Definition at line 583 of file vscodec.h.

#define VS1011_SS_VER   1

Definition at line 584 of file vscodec.h.

#define VS1011E_SS_VER   2

Definition at line 585 of file vscodec.h.

#define VS1002_SS_VER   2

Definition at line 586 of file vscodec.h.

#define VS1003_SS_VER   3

Definition at line 587 of file vscodec.h.

#define VS1053_SS_VER   4

Definition at line 588 of file vscodec.h.

#define VS1033_SS_VER   5

Definition at line 589 of file vscodec.h.

#define VS1103_SS_VER   7

Definition at line 590 of file vscodec.h.

#define VS_CLOCKF_REG   3

Register index.

Definition at line 712 of file vscodec.h.

#define VS_DECODE_TIME_REG   4

Register index.

This register contains the decode time in full seconds or zero after resetting the decoder.

The user may change the value of this register. However, in that case the new value should be written twice.

Definition at line 811 of file vscodec.h.

#define VS_AUDATA_REG   5

Register index.

Usage on the VS1001K differs.

Definition at line 823 of file vscodec.h.

#define VS_AD_STEREO   0x8000

Stereo flag.

1 for stereo and 0 for mono. Read-only.

On the VS1001K the most significant bit is used as a stereo indicator.

Definition at line 833 of file vscodec.h.

#define VS_WRAM_REG   6

Register index.

Used to upload application programs and data to instruction and data RAM.

Definition at line 890 of file vscodec.h.

#define VS_WRAMADDR_REG   7

Register index.

Used to upload application programs and data to instruction and data RAM.

Definition at line 902 of file vscodec.h.

#define VS_AIADDR_REG   10

Register index.

Definition at line 1016 of file vscodec.h.

#define VS_VOL_REG   11

Register index.

After hardware reset, volume is at maximum value. Software reset does not change volume settings.

Setting this register to VS_VOL_OFF will put the chip in analog power down mode.

On some earlier chips, audio interrupts may be missed when writing to this register. This will not happen on the VS1053, where volume changes are delayed until the next batch of samples are sent to the audio FIFO.

Definition at line 1037 of file vscodec.h.

#define VS_VOL_RIGHT   0x00FF

Right channel volume mask.

Attenuation is given in 0.5 dB steps or 255 for mute.

Definition at line 1043 of file vscodec.h.

#define VS_VOL_RIGHT_LSB   0

Right channel volume LSB.

Definition at line 1046 of file vscodec.h.

#define VS_VOL_LEFT   0xFF00

Right channel volume mask.

Attenuation is given in 0.5 dB steps or 255 for mute.

Definition at line 1052 of file vscodec.h.

#define VS_VOL_LEFT_LSB   8

Right channel volume LSB.

Definition at line 1055 of file vscodec.h.

#define VS_VOL_MAX   0x0000

Definition at line 1057 of file vscodec.h.

#define VS_VOL_MIN   0xFEFE

Definition at line 1058 of file vscodec.h.

#define VS_VOL_OFF   0xFFFF

Definition at line 1059 of file vscodec.h.

#define VS_FLUSH_BYTES   2048

Application register 0 index.

Do not use with VS1001. Also used for mixer volume on the VS1103.

VS1001K application register 0 index.

A second register is available at VS_AICTRL_REG + 1.

Application register 1 index.

Register 0 on the VS1001. Also used for IMA ADPCM record control in the VS1103.

Application register 2 index.

Register 1 on the VS1001.

Application register 3 index.

Do not use with VS1001.

Definition at line 1144 of file vscodec.h.

#define CODEC_STATUS_IDLE   0

Definition at line 1150 of file vscodec.h.

#define CODEC_STATUS_PLAYING   1

Definition at line 1151 of file vscodec.h.

#define CODEC_STATUS_RECORDING   2

Definition at line 1152 of file vscodec.h.

Referenced by FeederThread().

#define VSCODEC_CMD_TIMEOUT   NUT_WAIT_INFINITE

Minimum time in milliseconds to held hardware reset low.

Definition at line 1178 of file vscodec.h.

Referenced by VsCodecReg().

#define VSCODEC_DATA_CHUNK_SIZE   32

Number of data bytes we can send without checking DREQ.

Definition at line 1214 of file vscodec.h.

#define VSREQ_PLAY   0x00000001

Force immediate player start.

Definition at line 60 of file spi_vscodec.c.

Referenced by FeederThread(), and VsCodecIOCtl().

#define VSREQ_CANCEL   0x00000002

Force immediate player stop.

Definition at line 62 of file spi_vscodec.c.

Referenced by FeederThread(), and VsCodecIOCtl().

#define VSREQ_VOLUPD   0x00000004

Volume update.

Definition at line 64 of file spi_vscodec.c.

Referenced by FeederThread(), and VsCodecIOCtl().

#define VSREQ_AUDIOE   0x00000008

Audio enhancement update.

Definition at line 66 of file spi_vscodec.c.

Referenced by FeederThread(), and VsCodecIOCtl().

#define VSREQ_BEEP   0x00000010

Sine wave test.

Definition at line 68 of file spi_vscodec.c.

Referenced by FeederThread(), and VsCodecIOCtl().

#define VSREQ_RECORD   0x00000020

Start recording.

Definition at line 70 of file spi_vscodec.c.

Referenced by FeederThread(), and VsCodecRead().

#define AUDIO_VS1001K

Definition at line 93 of file vscodec.c.

#define VS10XX_FREQ   12288000UL

Decoder crystal frequency.

Definition at line 98 of file vscodec.c.

#define VS10XX_HWRST_DURATION   1

Minimum time in milliseconds to held hardware reset low.

Definition at line 103 of file vscodec.c.

#define VS10XX_HWRST_RECOVER   4

Milliseconds to wait after hardware reset.

Definition at line 108 of file vscodec.c.

#define VS10XX_SWRST_RECOVER   2

Milliseconds to wait after software reset.

Definition at line 113 of file vscodec.c.

#define VS10XX_SCI_MODE   0

Definition at line 117 of file vscodec.c.

#define VS10XX_SCI_RATE   (VS10XX_FREQ / 6)

Definition at line 121 of file vscodec.c.

#define VS10XX_SDI_MODE   0

Definition at line 125 of file vscodec.c.

#define VS10XX_SDI_RATE   (VS10XX_FREQ / 6)

Definition at line 129 of file vscodec.c.

#define VSREQ_PLAY   0x00000001

Definition at line 263 of file vscodec.c.

Referenced by FeederThread().

#define VSREQ_CANCEL   0x00000002

Definition at line 264 of file vscodec.c.

Referenced by FeederThread().

#define VSREQ_BEEP   0x00000004

Definition at line 265 of file vscodec.c.

Referenced by FeederThread().


Typedef Documentation

Definition at line 211 of file vscodec.h.

typedef struct _VSDCB VSDCB

Internal codec control block.

typedef struct _VSDCB VSDCB

Function Documentation

int VsCodecWaitReady ( NUTDEVICE dev,
uint32_t  tmo 
)

Wait until codec is ready.

Parameters:
devSepcifies the codec device.
tmoMaximum number of milliseconds to wait.
Returns:
0 on success, -1 on time out.

Definition at line 85 of file spi_vscodec.c.

References _VSDCB::dcb_feedme, _VSDCB::dcb_isready, _NUTDEVICE::dev_dcb, and NutEventWait().

Referenced by FeederThread(), and VsCodecReg().

Here is the call graph for this function:

uint16_t VsCodecReg ( NUTDEVICE dev,
uint_fast8_t  op,
uint_fast8_t  reg,
uint_fast16_t  val 
)

Definition at line 110 of file spi_vscodec.c.

References _VSDCB::dcb_sendcmd, _NUTDEVICE::dev_dcb, VSCODEC_CMD_TIMEOUT, and VsCodecWaitReady().

Referenced by FeederThread(), VsCodecMode(), VsDecoderSetBass(), and VsDecoderSetVolume().

Here is the call graph for this function:

uint16_t VsCodecMode ( NUTDEVICE dev,
uint_fast16_t  flags,
uint_fast16_t  mask 
)

Read and modify VLSI audio codec mode flags.

Set both, flags and mask to zero to read the flags without change.

Parameters:
devSpecifies the audio codec device.
flagsMode flags to set. All other flags are disabled, if they appear in the mask.
maskMode flags to update. All other flags are left unchanged.
Returns:
Previous mode flags.

Definition at line 141 of file spi_vscodec.c.

References NutSleep(), VS_MODE_REG, VS_OPCODE_READ, VS_OPCODE_WRITE, VS_SM_RESET, and VsCodecReg().

Referenced by FeederThread(), VsCodecBeep(), and VsCodecOpen().

Here is the call graph for this function:

int VsDecoderSetVolume ( NUTDEVICE dev,
int  left,
int  right 
)

Set volume.

Parameters:
devSpecifies the audio codec device.
leftLeft channel gain in db.
rightRight channel gain in db.
Returns:
Always 0.

Definition at line 168 of file spi_vscodec.c.

References AUDIO_DAC_MAX_GAIN, AUDIO_DAC_MIN_GAIN, _VSDCB::dcb_lvol, _VSDCB::dcb_rvol, _NUTDEVICE::dev_dcb, VS_OPCODE_WRITE, VS_VOL_LEFT_LSB, VS_VOL_REG, VS_VOL_RIGHT_LSB, and VsCodecReg().

Referenced by FeederThread().

Here is the call graph for this function:

int VsDecoderSetBass ( NUTDEVICE dev,
int  treb,
int  tfin,
int  bass,
int  bfin 
)

Set Bass.

Parameters:
devSpecifies the audio codec device.
trebTreble amplitude x 1.5dB.
tsetTreble frequency limit x 1000Hz
bassBass amplitude x 1dB.
bsetBass frequency limit x 10Hz
Returns:
Always 0.

Definition at line 202 of file spi_vscodec.c.

References AUDIO_DAC_MAX_BASS, AUDIO_DAC_MAX_BFIN, AUDIO_DAC_MAX_TFIN, AUDIO_DAC_MAX_TREB, _VSDCB::dcb_bass, _VSDCB::dcb_bfin, _VSDCB::dcb_tfin, _VSDCB::dcb_treb, _NUTDEVICE::dev_dcb, VS_BASS_REG, VS_OPCODE_WRITE, VS_SB_AMPLITUDE_LSB, VS_SB_FREQLIMIT_LSB, VS_ST_AMPLITUDE_LSB, VS_ST_FREQLIMIT_LSB, and VsCodecReg().

Referenced by FeederThread().

Here is the call graph for this function:

uint16_t VsCodecBeep ( NUTDEVICE dev,
uint16_t  fsin 
)

Start or stop sine wave beeper.

Old, VS1001 compatible routine, which supports a limit number of frequencies only. It will try to find the best value.

Parameters:
devSpecifies the audio codec device.
fsinFrequency, or 0 to switch beeper off.
Returns:
Actual frequency set.

Definition at line 251 of file spi_vscodec.c.

References CONST, _VSDCB::dcb_senddata, _NUTDEVICE::dev_dcb, VS_SM_RESET, VS_SM_TESTS, and VsCodecMode().

Referenced by FeederThread().

Here is the call graph for this function:

int VsDecoderBufferInit ( NUTDEVICE dev,
uint32_t  size 
)

Definition at line 315 of file spi_vscodec.c.

References CODEC_STATUS_IDLE, _VSDCB::dcb_pbstat, _VSDCB::dcb_pbwhi, _VSDCB::dcb_pbwlo, _NUTDEVICE::dev_dcb, NutSegBufAvailable(), and NutSegBufInit().

Referenced by VsCodecIOCtl().

Here is the call graph for this function:

int VsCodecIOCtl ( NUTDEVICE dev,
int  req,
void *  conf 
)

Handle I/O controls for audio codec.

Parameters:
devSpecifies the audio codec device.
  • AUDIO_PLAY Force playback start, even if the buffer level is too lower.
  • AUDIO_CANCEL Cancel playback and discard all buffered data.
  • AUDIO_GET_STATUS Sets an int to 1 if the player is running, 0 if idle.
  • AUDIO_GET_PLAYGAIN Sets an int to the current playback gain, 0..-127.
  • AUDIO_SET_PLAYGAIN Reads the requested playback gain from an int, 0..-127.
  • AUDIO_GET_PBSIZE Sets an unsigned long with the size of the playback buffer.
  • AUDIO_SET_PBSIZE Sets the size the playback buffer using an unsigned long.
  • AUDIO_GET_PBLEVEL Sets an unsigned long with the number of bytes in the playback buffer.
  • AUDIO_GET_PBWLOW Sets an unsigned long with the low watermark of the playback buffer.
  • AUDIO_SET_PBWLOW Sets the low watermark (unsigned long) of the playback buffer.
  • AUDIO_GET_PBWHIGH Sets an unsigned long with the high watermark of the playback buffer.
  • AUDIO_SET_PBWHIGH Sets the high watermark (unsigned long) of the playback buffer.
  • AUDIO_BEEP Plays a short sine wave beep.
Returns:
0 on success, -1 otherwise.

Definition at line 577 of file spi_vscodec.c.

References AUDIO_BEEP, AUDIO_CANCEL, AUDIO_GET_CODCAPS, AUDIO_GET_CODINFO, AUDIO_GET_DECCAPS, AUDIO_GET_DECINFO, AUDIO_GET_MIDCAPS, AUDIO_GET_MIDINFO, AUDIO_GET_PBLEVEL, AUDIO_GET_PBSIZE, AUDIO_GET_PBWHIGH, AUDIO_GET_PBWLOW, AUDIO_GET_PLAYGAIN, AUDIO_GET_STATUS, AUDIO_GETWRITETIMEOUT, AUDIO_PLAY, AUDIO_PLUGIN_UPLOAD, AUDIO_SET_BASS, AUDIO_SET_BFIN, AUDIO_SET_PBSIZE, AUDIO_SET_PBWHIGH, AUDIO_SET_PBWLOW, AUDIO_SET_PLAYGAIN, AUDIO_SET_TFIN, AUDIO_SET_TREB, AUDIO_SETWRITETIMEOUT, CODEC_STATUS_IDLE, CODEC_STATUS_PLAYING, _VSDCB::dcb_bass, _VSDCB::dcb_bfin, _VSDCB::dcb_cod_caps, _VSDCB::dcb_control, _VSDCB::dcb_dec_caps, _VSDCB::dcb_feedme, _VSDCB::dcb_lvol, _VSDCB::dcb_midi_caps, _VSDCB::dcb_pbstat, _VSDCB::dcb_pbwhi, _VSDCB::dcb_pbwlo, _VSDCB::dcb_rvol, _VSDCB::dcb_scmd, _VSDCB::dcb_sinefreq, _VSDCB::dcb_tfin, _VSDCB::dcb_treb, _VSDCB::dcb_wtmo, _NUTDEVICE::dev_dcb, NutEventPost(), NutSegBufAvailable(), NutSegBufUsed(), VsDecoderBufferInit(), VSREQ_AUDIOE, VSREQ_BEEP, VSREQ_CANCEL, VSREQ_PLAY, and VSREQ_VOLUPD.

Referenced by VsCodecOpen().

Here is the call graph for this function:

int VsCodecRead ( NUTFILE nfp,
void *  data,
int  len 
)

Read from the encoder.

Parameters:
nfpPointer to a NUTFILE structure, obtained by a previous call to VsCodecOpen().
dataPointer to the data buffer. If NULL, the buffered data will be flushed.
lenNumber of bytes to read. If 0, all buffered data will be flushed.
Returns:
Number of characters sent. If a read timeout had been set, then this may be less than the specified length.

Definition at line 746 of file spi_vscodec.c.

References AUDIO_FMT_VORBIS, CODEC_STATUS_IDLE, CODEC_STATUS_PLAYING, _VSDCB::dcb_bufque, _VSDCB::dcb_cod_mode, _VSDCB::dcb_feedme, _VSDCB::dcb_pbstat, _VSDCB::dcb_rtmo, _VSDCB::dcb_scmd, _NUTDEVICE::dev_dcb, memcpy(), _NUTFILE::nf_dev, NutEventPost(), NutEventWait(), NutSegBufReadLast(), NutSegBufReadRequest(), and VSREQ_RECORD.

Here is the call graph for this function:

int VsCodecWrite ( NUTFILE nfp,
CONST void *  data,
int  len 
)

Write to decoder.

Parameters:
nfpPointer to a NUTFILE structure, obtained by a previous call to VsCodecOpen().
dataPointer to the data buffer. If NULL, the buffered data will be flushed.
lenNumber of bytes that are available in the buffer. If 0, all buffered data will be flushed.
Returns:
Number of characters sent. If a write timeout had been set, then this may be less than the specified length.

Definition at line 809 of file spi_vscodec.c.

References CONST, _VSDCB::dcb_bufque, _VSDCB::dcb_feedme, _VSDCB::dcb_wtmo, _NUTDEVICE::dev_dcb, memcpy(), _NUTFILE::nf_dev, NutEventPost(), NutEventWait(), NutSegBufWriteLast(), and NutSegBufWriteRequest().

Here is the call graph for this function:

int VsCodecWrite_P ( NUTFILE nfp,
PGM_P  buffer,
int  len 
)

Write program data to decoder.

Similar to VsCodecWrite() except that the data is expected in program memory.

This function is implemented for CPUs with Harvard Architecture only.

This function is called by the low level output routines of the C runtime library, using the _NUTDEVICE::dev_write_P entry.

Parameters:
nfpPointer to a NUTFILE structure, obtained by a previous call to VsCodecOpen().
bufferPointer to the data in program space. If zero, then the output buffer will be flushed.
lenNumber of bytes to write.
Returns:
The number of bytes written. A return value of -1 indicates an error. Currently this function is not implemented and always returns -1.

Definition at line 868 of file spi_vscodec.c.

NUTFILE* VsCodecOpen ( NUTDEVICE dev,
CONST char *  name,
int  mode,
int  acc 
)
int VsCodecClose ( NUTFILE nfp)

Definition at line 916 of file spi_vscodec.c.

References _VSDCB::dcb_wtmo, _NUTDEVICE::dev_dcb, free(), and _NUTFILE::nf_dev.

Here is the call graph for this function:


Variable Documentation

uint8_t zero_chunk[VSCODEC_DATA_CHUNK_SIZE]

Definition at line 75 of file spi_vscodec.c.

VS10XX device information structure.

An application must pass a pointer to this structure to NutRegisterDevice() before using this driver.

The device is named audio0.

Definition at line 917 of file vscodec.c.

uint8_t zero_chunk[VSCODEC_DATA_CHUNK_SIZE]

Definition at line 75 of file spi_vscodec.c.

Initial value:
 {
    0,              
    {'a', 'u', 'd', 'i', 'o', '0', 0, 0, 0},    
    IFTYP_CHAR,     
    0,              
    0,              
    0,              
    &dcb,           
    VsInit,         
    VsIOCtl,        
    NULL,           
    VsWrite,        

    VsWrite_P,      

    VsOpen,         
    VsClose,        
    NULL            
}

VS10XX device information structure.

An application must pass a pointer to this structure to NutRegisterDevice() before using this driver.

The device is named audio0.

Definition at line 917 of file vscodec.c.