vscodec.h 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339
  1. #ifndef _DEV_VSCODEC_H_
  2. #define _DEV_VSCODEC_H_
  3. /*
  4. * Copyright (C) 2009 by egnite GmbH
  5. * Copyright (C) 2001-2007 by egnite Software GmbH
  6. *
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. *
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * 3. Neither the name of the copyright holders nor the names of
  19. * contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  29. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  30. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  31. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  32. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33. * SUCH DAMAGE.
  34. *
  35. * For additional information see http://www.ethernut.de/
  36. */
  37. /*
  38. * $Id: vscodec.h 4937 2013-01-22 11:38:42Z haraldkipp $
  39. */
  40. #include <cfg/audio.h>
  41. #include <sys/device.h>
  42. #include <stdint.h>
  43. /* For backward compatibility. */
  44. #if defined(AUDIO_VS1001K)
  45. #define AUDIO0_VS1001K
  46. #elif defined(AUDIO_VS1011E)
  47. #define AUDIO0_VS1011E
  48. #elif defined(AUDIO_VS1002D)
  49. #define AUDIO0_VS1002D
  50. #elif defined(AUDIO_VS1003B)
  51. #define AUDIO0_VS1003B
  52. #elif defined(AUDIO_VS1033C)
  53. #define AUDIO0_VS1033C
  54. #elif defined(AUDIO_VS1053B)
  55. #define AUDIO0_VS1053B
  56. #elif defined(AUDIO_VS1063A)
  57. #define AUDIO0_VS1063A
  58. #elif defined(AUDIO_VSAUTO)
  59. #define AUDIO0_VSAUTO
  60. #endif
  61. /*
  62. ** Include codec features.
  63. */
  64. #if defined(AUDIO0_VS1001K)
  65. #include <dev/vs1001.h>
  66. #elif defined(AUDIO0_VS1002D)
  67. #include <dev/vs1002.h>
  68. #elif defined(AUDIO0_VS1003B)
  69. #include <dev/vs1003.h>
  70. #elif defined(AUDIO0_VS1011E)
  71. #include <dev/vs1011.h>
  72. #elif defined(AUDIO0_VS1033C)
  73. #include <dev/vs1033.h>
  74. #elif defined(AUDIO0_VS1053B)
  75. #include <dev/vs1053.h>
  76. #elif defined(AUDIO0_VS1063A)
  77. #include <dev/vs1063.h>
  78. #elif !defined(AUDIO0_VSAUTO)
  79. #define AUDIO0_VSAUTO
  80. #endif
  81. /*!
  82. * \file dev/vscodec.h
  83. * \brief VLSI decoder definitions.
  84. */
  85. /*!
  86. * \addtogroup xgVsCodec
  87. */
  88. /*@{*/
  89. /* DAC min/max gain in dB. */
  90. #ifndef AUDIO0_DAC_MIN_GAIN
  91. #define AUDIO0_DAC_MIN_GAIN -127
  92. #endif
  93. #ifndef AUDIO0_DAC_MAX_GAIN
  94. #define AUDIO0_DAC_MAX_GAIN 0
  95. #endif
  96. /* Backward compatibility, still used. */
  97. #ifndef AUDIO_DAC_MIN_GAIN
  98. #define AUDIO_DAC_MIN_GAIN AUDIO0_DAC_MIN_GAIN
  99. #endif
  100. #ifndef AUDIO_DAC_MAX_GAIN
  101. #define AUDIO_DAC_MAX_GAIN AUDIO0_DAC_MAX_GAIN
  102. #endif
  103. /* Audio decoder treble anhancement limits */
  104. #ifndef AUDIO_DAC_MAX_TREB
  105. #define AUDIO_DAC_MAX_TREB 8 /* VLSI1053 limits */
  106. #endif
  107. #ifndef AUDIO_DAC_MAX_TFIN
  108. #define AUDIO_DAC_MAX_TFIN 15 /* VLSI1053 limits */
  109. #endif
  110. #ifndef AUDIO_DAC_MAX_BASS
  111. #define AUDIO_DAC_MAX_BASS 15 /* VLSI1053 limits */
  112. #endif
  113. #ifndef AUDIO_DAC_MAX_BFIN
  114. #define AUDIO_DAC_MAX_BFIN 15 /* VLSI1053 limits */
  115. #endif
  116. /*
  117. * I/O control codes.
  118. */
  119. #define AUDIO_SETWRITETIMEOUT 0x010d
  120. #define AUDIO_GETWRITETIMEOUT 0x010e
  121. /*! \brief Immediately start playing. */
  122. #define AUDIO_PLAY 0x3001
  123. /*! \brief Immediately stop playing and discard buffer. */
  124. #define AUDIO_CANCEL 0x3002
  125. #define AUDIO_GET_STATUS 0x3003
  126. #define AUDIO_GET_PLAYGAIN 0x3004
  127. #define AUDIO_SET_PLAYGAIN 0x3005
  128. #define AUDIO_GET_PBSIZE 0x3006
  129. #define AUDIO_SET_PBSIZE 0x3007
  130. #define AUDIO_GET_PBLEVEL 0x3008
  131. #define AUDIO_GET_PBWLOW 0x3009
  132. #define AUDIO_SET_PBWLOW 0x300A
  133. #define AUDIO_GET_PBWHIGH 0x300B
  134. #define AUDIO_SET_PBWHIGH 0x300C
  135. #define AUDIO_BEEP 0x300F
  136. /*! \brief Retrieve decoder information. */
  137. #define AUDIO_GET_DECINFO 0x3010
  138. /*! \brief Retrieve decoder capabilities. */
  139. #define AUDIO_GET_DECCAPS 0x3011
  140. /*! \brief Retrieve decoder formats. */
  141. #define AUDIO_GET_DECFMTS 0x3012
  142. #define AUDIO_FMT_PLUGIN 0x00000001
  143. #define AUDIO_FMT_WAV_PCM 0x00000002
  144. #define AUDIO_FMT_WAV_ADPCM 0x00000004
  145. #define AUDIO_FMT_WAV_IMA_ADPCM 0x00000008
  146. #define AUDIO_FMT_VORBIS 0x00000100
  147. #define AUDIO_FMT_MPEG1_L1 0x00001000
  148. #define AUDIO_FMT_MPEG1_L2 0x00002000
  149. #define AUDIO_FMT_MPEG1_L3 0x00004000
  150. #define AUDIO_FMT_MPEG2_AAC 0x00010000
  151. #define AUDIO_FMT_MPEG4_AAC 0x00020000
  152. #define AUDIO_FMT_WMA_V2 0x00100000
  153. #define AUDIO_FMT_WMA_V7 0x00200000
  154. #define AUDIO_FMT_WMA_V8 0x00400000
  155. #define AUDIO_FMT_WMA_V9 0x00800000
  156. /*! \brief Enable or disable specific decoder formats. */
  157. #define AUDIO_SET_DECFMTS 0x3013
  158. /*! \brief Retrieve encoder information. */
  159. #define AUDIO_GET_CODINFO 0x3014
  160. /*! \brief Retrieve encoder capabilities. */
  161. #define AUDIO_GET_CODCAPS 0x3015
  162. /*! \brief Retrieve encoder formats. */
  163. #define AUDIO_GET_CODFMTS 0x3016
  164. /*! \brief Enable or disable specific encoder formats. */
  165. #define AUDIO_SET_CODFMTS 0x3017
  166. /*! \brief Retrieve midi information. */
  167. #define AUDIO_GET_MIDINFO 0x3018
  168. /*! \brief Retrieve midi capabilities. */
  169. #define AUDIO_GET_MIDCAPS 0x3019
  170. #define AUDIO_FMT_GMIDI1 0x00000001
  171. #define AUDIO_FMT_GMIDI2 0x00000002
  172. #define AUDIO_FMT_SPMIDI0 0x00000004
  173. /*! \brief Set audio enhancement treble value. */
  174. #define AUDIO_SET_TREB 0x301a
  175. /*! \brief Get audio enhancement treble value. */
  176. #define AUDIO_GET_TREB 0x301b
  177. /*! \brief Set audio enhancement treble frequency. */
  178. #define AUDIO_SET_TFIN 0x301c
  179. /*! \brief Get audio enhancement treble frequency. */
  180. #define AUDIO_GET_TFIN 0x301d
  181. /*! \brief Set audio enhancement bass value. */
  182. #define AUDIO_SET_BASS 0x301e
  183. /*! \brief Get audio enhancement bass value. */
  184. #define AUDIO_GET_BASS 0x301f
  185. /*! \brief Set audio enhancement bass frequency. */
  186. #define AUDIO_SET_BFIN 0x3020
  187. /*! \brief Get audio enhancement bass frequency. */
  188. #define AUDIO_GET_BFIN 0x3021
  189. /*! \brief Upload plug-in. */
  190. #define AUDIO_PLUGIN_UPLOAD 0x3030
  191. /*! \brief Enable interrupts. */
  192. #define AUDIO_IRQ_ENABLE 0x3031
  193. /*! \brief Set internal clock. */
  194. #define AUDIO_SET_ICLOCK 0x3032
  195. /*! \brief Upload into WRAM. */
  196. #define AUDIO_WRITE_CMEM 0x3038
  197. /*! \brief Set parametric x. */
  198. #define AUDIO_SET_PARAMX 0x3040
  199. /*! \brief Get parametric x. */
  200. #define AUDIO_GET_PARAMX 0x3041
  201. #define VSP4_CHIP_ID_OFF 0x00
  202. #define VSP4_VERSION_OFF 0x02
  203. #define VSP4_CONFIG1_OFF 0x03
  204. #define VSP4_PLAY_SPEED_OFF 0x04
  205. #define VSP4_BIT_RATE_PER_100_OFF 0x05
  206. #define VSP4_END_FILL_BYTE_OFF 0x06
  207. #define VSP4_RATE_TUNE_OFF 0x07
  208. #define VSP4_PLAY_MODE_OFF 0x09
  209. #define VSP4_SAMPLE_COUNTER_OFF 0x0a
  210. #define VSP4_VU_METER_OFF 0x0c
  211. #define VSP4_AD_MIXER_GAIN_OFF 0x0d
  212. #define VSP4_AD_MIXER_CONFIG_OFF 0x0e
  213. #define VSP4_PCM_MIXER_RATE_OFF 0x0f
  214. #define VSP4_PCM_MIXER_FREE_OFF 0x10
  215. #define VSP4_PCM_MIXER_VOL_OFF 0x11
  216. #define VSP4_EQ5_PARAMS_OFF(i) (0x12 + (i))
  217. #define VSP4_EQ5_UPDATED_OFF 0x1c
  218. #define VSP4_SPEED_SHIFTER_OFF 0x1d
  219. #define VSP4_EAR_SPEAKER_LEVEL_OFF 0x1e
  220. #define VSP4_SDI_FREE_OFF 0x1f
  221. #define VSP4_AUDIO_FILL_OFF 0x20
  222. #define VSP4_LATEST_SOF_OFF 0x25
  223. #define VSP4_POSITION_MSEC_OFF 0x27
  224. #define VSP4_RESYNC_OFF 0x29
  225. #define VSP4_ENC_TX_UART_DIV_OFF 0x2a
  226. #define VSP4_ENC_TX_UART_BYTE_SPEED_OFF 0x2b
  227. #define VSP4_ENC_TX_PAUSE_GPIO_OFF 0x2c
  228. #define VSP4_ENC_SEC_ADAPT_MULTIPLIER_OFF 0x2d
  229. #define VSP4_ENC_CHANNEL_MAX_OFF 0x3c
  230. #define VSP4_ENC_SERIAL_NUMBER_OFF 0x3e
  231. #define VSP4_WMA_CUR_PACKET_SIZE_OFF 0x2a
  232. #define VSP4_WMA_PACKET_SIZE_OFF 0x2c
  233. #define VSP4_AAC_SCE_FOUND_MASK_OFF 0x2a
  234. #define VSP4_AAC_CPE_FOUND_MASK_OFF 0x2b
  235. #define VSP4_AAC_LFE_FOUND_MASK_OFF 0x2c
  236. #define VSP4_AAC_PLAY_SELECT_OFF 0x2d
  237. #define VSP4_AAC_DYN_COMPRESS_OFF 0x2e
  238. #define VSP4_AAC_DYN_BOOST_OFF 0x2f
  239. #define VSP4_AAC_SBR_AND_PS_STATUS_OFF 0x30
  240. #define VSP4_AAC_SBR_PS_FLAGS_OFF 0x31
  241. #define VSP4_VORBIS_GAIN_OFF 0x2a
  242. #define VS_PLAYMODE_MONO_OUTPUT_ON ox0001
  243. #define VS_PLAYMODE_PAUSE_ON 0x0002
  244. #define VS_PLAYMODE_VUMETER_ON 0x0004
  245. #define VS_PLAYMODE_ADMIXER_ON 0x0008
  246. #define VS_PLAYMODE_PCMMIXER_ON 0x0010
  247. #define VS_PLAYMODE_EQ5_ON 0x0020
  248. #define VS_PLAYMODE_SPEEDSHIFTER_ON 0x0040
  249. typedef struct _VS_PLUGIN_INFO VS_PLUGIN_INFO;
  250. struct _VS_PLUGIN_INFO {
  251. size_t vsplg_size;
  252. const uint16_t *vsplg_data;
  253. };
  254. typedef struct _VS_WRAM_DATA VS_WRAM_DATA;
  255. struct _VS_WRAM_DATA {
  256. uint16_t vswd_addr;
  257. uint16_t vswd_size;
  258. uint16_t *vswd_data;
  259. };
  260. typedef struct _VS_PARAMX_INFO VS_PARAMX_INFO;
  261. struct _VS_PARAMX_INFO {
  262. uint16_t vspx_offs;
  263. uint16_t vspx_data;
  264. };
  265. /*
  266. * Instruction opcodes.
  267. */
  268. #define VS_OPCODE_READ 3
  269. #define VS_OPCODE_WRITE 2
  270. /*!
  271. * \name Mode Control Register
  272. */
  273. /* ------------------------------------------------------------- */
  274. /*@{*/
  275. /*! \brief Register index. */
  276. #define VS_MODE_REG 0
  277. /*! \brief Left channel inverted. */
  278. #define VS_SM_DIFF 0x0001
  279. /*! \brief Allow MPEG Layers I & II.
  280. *
  281. * Determines whether it is allowed to decode MPEG 1 and 2 Layers I and II
  282. * in addition to Layer III. If you enable Layer I and Layer II decoding,
  283. * you are liable for any patent issues that may arise. Joint licensing of
  284. * MPEG 1.0 / 2.0 Layer III does not cover all patents pertaining to
  285. * Layers I and II.
  286. */
  287. #if VS_HAS_SM_LAYER12
  288. #define VS_SM_LAYER12 0x0002
  289. #endif
  290. /*! \brief VS1001K fast forward.
  291. *
  292. * By setting this bit, the player starts to accept data at a high speed, and
  293. * just decodes the audio headers silently without playing any audio data.
  294. * This can be used to fast-forward data with safe landing.
  295. * Register \ref VS_DECODE_TIME_REG is updated during a fast-forward just as
  296. * normal.
  297. *
  298. * Note, that this bit is available on the VS1001K only and is used as MPEG
  299. * Layer I & II enable on other members of the VS10xx family.
  300. */
  301. #if VS_HAS_SM_FFWD
  302. #define VS_SM_FFWD 0x0002
  303. #endif
  304. /*! \brief Soft reset.
  305. *
  306. * Bit is cleared automatically.
  307. */
  308. #define VS_SM_RESET 0x0004
  309. /*! \brief VS1001 MPEG Layers I & II enable.
  310. *
  311. * This bit is marked unused in later VS1001 datasheet versions and may
  312. * not work due to firmware problems.
  313. *
  314. * Note, that this bit was available on the VS1001K only and is used as
  315. * a cancel flag on other members of the VS10xx family.
  316. *
  317. * If you enable Layer I and Layer II decoding, you are liable for any
  318. * patent issues that may arise.
  319. */
  320. #if VS_HAS_SM_MP12
  321. #define VS_SM_MP12 0x0008
  322. #endif
  323. /*! \brief Jump out of wave decoding.
  324. *
  325. * Set this bit to stop WAV, WMA and MIDI file playing before the end of
  326. * the file has been reached. Continue sending zeros for WAV and more data
  327. * for MIDI and WMA until this bit is cleared again.
  328. *
  329. * Not available on the VS1001K.
  330. */
  331. #if VS_HAS_SM_OUTOFWAV
  332. #define VS_SM_OUTOFWAV 0x0008
  333. #endif
  334. /*! \brief Stop decoding in the middle.
  335. *
  336. * Set this bit to stop decoding a in the middle, and continue sending
  337. * data honouring DREQ. When this flag is detected by a codec, it will
  338. * stop decoding and discard stream buffer content. The flag is cleared
  339. * automatically and SCI HDAT1 will also be cleared.
  340. *
  341. * Available on the VS1053.
  342. */
  343. #if VS_HAS_SM_CANCEL
  344. #define VS_SM_CANCEL 0x0008
  345. #endif
  346. /*! \brief Power down.
  347. *
  348. * During powerdown, no audio is played and no SDI operations are performed.
  349. * It is recommended to set \ref VS_VOL_REG to 0xFFFF before setting this
  350. * bit.
  351. *
  352. * For best power down efficiency, activate hardware reset.
  353. *
  354. * Not available on the VS1011. Although defined, this is not implemented
  355. * in the VS1001K firmware.
  356. */
  357. #if VS_HAS_SM_PDOWN
  358. #define VS_SM_PDOWN 0x0010
  359. #endif
  360. /*! \brief EarSpeaker spatial processing.
  361. */
  362. #if VS_HAS_SM_EARSPEAKER
  363. #define VS_SM_EARSPEAKER_LO 0x0010
  364. #define VS_SM_SPATIAL_OFF 0
  365. #define VS_SM_SPATIAL_MINIMAL VS_SM_EARSPEAKER_LO
  366. #define VS_SM_SPATIAL_NORMAL VS_SM_EARSPEAKER_HI
  367. #define VS_SM_SPATIAL_EXTREME (VS_SM_EARSPEAKER_LO | VS_SM_EARSPEAKER_LO)
  368. #endif
  369. /*! \brief VS1001K DAC mode.
  370. *
  371. * 16-bit DAC mode if set, MP3 mode otherwise.
  372. *
  373. * This bit is marked unused in later VS1001 datasheet versions and may
  374. * not work due to firmware problems.
  375. *
  376. * Note, that this bit was available on the VS1001 only and is used as
  377. * a test mode flag on other members of the VS10xx family.
  378. */
  379. #if VS_HAS_SM_DAC
  380. #define VS_SM_DAC 0x0020
  381. #endif
  382. /*! \brief Allow SDI tests.
  383. *
  384. * Not required for the VS1001K, where tests are enabled by default.
  385. */
  386. #if VS_HAS_SM_TESTS
  387. #define VS_SM_TESTS 0x0020
  388. #endif
  389. /*! \brief VS1001K DAC mono mode.
  390. *
  391. * DAC mono mode if set, stereo mode otherwise.
  392. *
  393. * This bit is marked unused in later VS1001 datasheet versions and may
  394. * not work due to firmware problems.
  395. *
  396. * Note, that this bit was available on the VS1001 only and is used as
  397. * a streaming mode flag on other members of the VS10xx family.
  398. */
  399. #if VS_HAS_SM_DACMONO
  400. #define VS_SM_DACMONO 0x0040
  401. #endif
  402. /*! \brief Stream mode.
  403. *
  404. * When stream mode is activated, data should be sent with as even
  405. * intervals as possible (and preferable with data blocks of less
  406. * than 512 bytes). The decoder makes every attempt to keep its input
  407. * buffer half full by changing its playback speed upto 5%. For best
  408. * quality sound, the average speed error should be within 0.5%, the
  409. * bitrate should not exceed 160 kbit/s and VBR should not be used.
  410. *
  411. * Not available on the VS1001K.
  412. */
  413. #if VS_HAS_SM_STREAM
  414. #define VS_SM_STREAM 0x0040
  415. #endif
  416. /*! \brief VS1001K bass/treble enhancer.
  417. *
  418. * When set, this bit turns on the built-in bass and treble enhancer.
  419. */
  420. #if VS_HAS_SM_BASS
  421. #define VS_SM_BASS 0x0080
  422. #endif
  423. #if VS_HAS_SM_EARSPEAKER
  424. #define VS_SM_EARSPEAKER_HI 0x0080
  425. #endif
  426. /*! \brief Active edge of the data clock.
  427. *
  428. * If clear data is read at the rising edge, and if set data is read
  429. * at the falling edge.
  430. */
  431. #define VS_SM_DACT 0x0100
  432. /*! \brief Data bus bit order.
  433. *
  434. * When clear the most significant bit is sent first, which is the default.
  435. * This register bit has no effect on the SCI bus.
  436. */
  437. #define VS_SM_BITORD 0x0200
  438. /*! \brief SDI most significant bit last.
  439. *
  440. * Same as \ref VS_SM_BITORD.
  441. */
  442. #define VS_SM_SDIORD 0x0200
  443. /*! \brief VS1001K master mode.
  444. *
  445. * Untested and not recommended.
  446. *
  447. * Note, that this bit is available on the VS1001 only and is used as
  448. * a chip select mode flag on other members of the VS10xx family.
  449. */
  450. #if VS_HAS_SM_IBMODE
  451. #define VS_SM_IBMODE 0x0400
  452. #endif
  453. /*! \brief Share SPI chip select. */
  454. #if VS_HAS_SM_SDISHARE
  455. #define VS_SM_SDISHARE 0x0400
  456. #endif
  457. /*! \brief VS1001K master mode clock speed.
  458. *
  459. * Untested and not recommended.
  460. *
  461. * Note, that this bit is available on the VS1001 only and is used as
  462. * an SDI mode flag on other members of the VS10xx family.
  463. */
  464. #if VS_HAS_SM_IBCLK
  465. #define VS_SM_IBCLK 0x0800
  466. #endif
  467. /*! \brief VS1002 native SDI mode.
  468. *
  469. * Default is 0 on the VS1011E and 1 on the VS1002.
  470. *
  471. * Not available on the VS1001K.
  472. */
  473. #if VS_HAS_SM_SDINEW
  474. #define VS_SM_SDINEW 0x0800
  475. #endif
  476. /*! \brief ADPCM recording.
  477. *
  478. * Available on VS1033 and VS1053.
  479. */
  480. #if VS_HAS_SM_ADPCM
  481. #define VS_SM_ADPCM 0x1000
  482. #define VS_SM_ENCODE 0x1000
  483. #endif
  484. /*! \brief ADPCM high pass filter.
  485. *
  486. * If set at the same time as \ref VS_SM_ADPCM and \ref VS_SM_RESET,
  487. * ADPCM mode will start with a high-pass filter. This may help
  488. * intelligibility of speech when there is lots of background noise.
  489. *
  490. * Available on VS1033.
  491. */
  492. #if VS_HAS_SM_ADPCM_HP
  493. #define VS_SM_ADPCM_HP 0x2000
  494. #endif
  495. /*! \brief ADPCM recording selector.
  496. *
  497. * Used to select the input for ADPCM recording. If cleared, microphone
  498. * input is used. If set to 1, LINEIN is used instead.
  499. *
  500. * Available on VS1033 and VS1053.
  501. */
  502. #if VS_HAS_SM_LINE_IN
  503. #define VS_SM_LINE_IN 0x4000
  504. #define VS_SM_LINE1 0x4000
  505. #endif
  506. /*! \brief Input clock range.
  507. *
  508. * Activates a clock divider at the XTAL input. Should be set as soon
  509. * as possible after a chip reset.
  510. *
  511. * Available on VS1033 and VS1053.
  512. */
  513. #if VS_HAS_SM_CLK_RANGE
  514. #define VS_SM_CLK_RANGE 0x8000
  515. #endif
  516. /*@}*/
  517. /*!
  518. * \name Status Register
  519. */
  520. /*@{*/
  521. /* ------------------------------------------------------------- */
  522. /*! \brief Register index.
  523. */
  524. #define VS_STATUS_REG 1
  525. /*! \brief Internal analog volume control mask.
  526. *
  527. * These bits is meant to be used by the internal firmware only.
  528. *
  529. * - 0 for 0 dB
  530. * - 1 for -6 dB
  531. * - 3 for -12 dB
  532. */
  533. #if VS_HAS_SS_AVOL
  534. #define VS_SS_AVOL 0x0003
  535. /*! \brief Internal analog volume control LSB. */
  536. #define VS_SS_AVOL_LSB 0
  537. #endif
  538. /*! \brief Reference voltage selection.
  539. *
  540. * If AVDD is at least higher than 3.3V, then this bit can be set to
  541. * select 1.65V reference voltage to increase the analog output swing.
  542. *
  543. * See \ref VS_SS_AD_CLOCK for more information about using this bit
  544. * with the VS1053b.
  545. */
  546. #if VS_HAS_SS_VREF_1_65
  547. #define VS_SS_VREF_1_65 0x0001
  548. #endif
  549. /*! \brief AD clock divider.
  550. *
  551. * This bit can be set to divide the AD modulator frequency by 2.
  552. *
  553. * Due to a firmware bug in VS1053b, volume calculation routine clears
  554. * \ref VS_SS_AD_CLOCK and \ref VS_SS_VREF_1_65 bits. Write to
  555. * \ref VS_STATUS_REG or \ref VS_VOL_REG as well as sample rate change
  556. * with bass enhancer or treble control actived, causes the volume
  557. * calculation routine to be called.
  558. *
  559. * As a workaround you can write to \ref VS_STATUS_REG through
  560. * \ref VS_WRAMADDR_REG and \ref VS_WRAM_REG after each volume change.
  561. * Write 0xC001 to \ref VS_WRAMADDR_REG, then write the value to
  562. * \ref VS_WRAM_REG. However, the difference in performance between the
  563. * modes is not significant, so it is easier to just use the default mode.
  564. */
  565. #if VS_HAS_SS_AD_CLOCK
  566. #define VS_SS_AD_CLOCK 0x0002
  567. #endif
  568. /*! \brief Internal analog power down.
  569. *
  570. * This bit is meant to be used by the internal firmware only.
  571. */
  572. #define VS_SS_APDOWM1 0x0004
  573. /*! \brief Analog driver power down.
  574. *
  575. * This bit is typically controlled by the internal firmware. However,
  576. * if the application wants to power down the VS1001 and VS1011 with a
  577. * minimum power-off transient, this bit should be set to 1 a few
  578. * milliseconds before activating reset.
  579. *
  580. * With newer chips set the volume register to 0xFFFF a few
  581. * milliseconds before reset.
  582. */
  583. #define VS_SS_APDOWN2 0x0008
  584. /*! \brief Version mask.
  585. *
  586. * - 0 for VS1001
  587. * - 1 for VS1011
  588. * - 2 for VS1002 and VS1011E, see \ref VS_SM_SDINEW
  589. * - 3 for VS1003
  590. * - 4 for VS1053
  591. * - 5 for VS1033
  592. * - 7 for VS1103
  593. */
  594. #define VS_SS_VER 0x00F0
  595. /*! \brief Version LSB. */
  596. #define VS_SS_VER_LSB 4
  597. #define VS1001_SS_VER 0
  598. #define VS1011_SS_VER 1
  599. #define VS1011E_SS_VER 2
  600. #define VS1002_SS_VER 2
  601. #define VS1003_SS_VER 3
  602. #define VS1053_SS_VER 4
  603. #define VS1033_SS_VER 5
  604. #define VS1063_SS_VER 6
  605. #define VS1103_SS_VER 7
  606. /*! \brief GBUF overload detection.
  607. *
  608. * Some chips contain a GBUF protection circuit, which disconnects the
  609. * GBUF driver when too much current is drawn, indicating a short-circuit
  610. * to ground. This bit is high while the overload is detected.
  611. */
  612. #if VS_HAS_SS_VCM_DISABLE
  613. #define VS_SS_VCM_DISABLE 0x0400
  614. #endif
  615. /*! \brief GBUF overload indicator.
  616. *
  617. * Set this bit to disable the GBUF protection circuit.
  618. */
  619. #if VS_HAS_SS_VCM_OVERLOAD
  620. #define VS_SS_VCM_OVERLOAD 0x0800
  621. #endif
  622. /*! \brief Increase DAC swing.
  623. *
  624. * Allows to go above the 0 dB volume setting in 0.5 db steps. Although
  625. * the range of the register bits offer up to 7 steps (+3.5 db), higher
  626. * settings than 2 cause the DAC modulator to be overdriven and should
  627. * not be used.
  628. *
  629. * Useful with I2S to control the amount of headroom.
  630. */
  631. #if VS_HAS_SS_SWING
  632. #define VS_SS_SWING 0x7000
  633. #define VS_SS_SWING_LSB 12
  634. #define VS_SS_SWING_NORMAL 0
  635. #define VS_SS_SWING_MAX 2
  636. #endif
  637. /*! \brief Header in decode indicator.
  638. *
  639. * Set when WAV, Ogg Vorbis, WMA, MP4, or AAC-ADIF header is being decoded
  640. * and jumping to another location in the file is not allowed.
  641. */
  642. #if VS_HAS_SS_DO_NOT_JUMP
  643. #define VS_SS_DO_NOT_JUMP 0x8000
  644. #endif
  645. /*@}*/
  646. /*!
  647. * \name VS1001 internal frequency control register.
  648. */
  649. /* ------------------------------------------------------------- */
  650. /*@{*/
  651. /*! \brief Register index.
  652. *
  653. * Used only on older chip revisions?
  654. */
  655. #if VS_HAS_INT_FCTLH_REG
  656. #define VS_INT_FCTLH_REG 2
  657. #endif
  658. /*@}*/
  659. /*!
  660. * \name Bass/Treble Enhancer Register
  661. */
  662. /* ------------------------------------------------------------- */
  663. /*@{*/
  664. /*! \brief Register index.
  665. *
  666. * On some earlier chips, audio interrupts may be missed when writing
  667. * to this register.
  668. *
  669. * For the VS1001K see \ref VS_SM_BASS.
  670. */
  671. #if VS_HAS_BASS_REG
  672. #define VS_BASS_REG 2
  673. /*! \brief Bass enhancer lower limit frequency mask.
  674. *
  675. * Specified in 10 Hz steps.
  676. *
  677. * The bass enhancer is a powerful bass boosting DSP algorithm, which
  678. * tries to take the most out of the user's earphones without causing
  679. * clipping.
  680. *
  681. */
  682. #define VS_SB_FREQLIMIT 0x000F
  683. /*! \brief Lower limit frequency LSB. */
  684. #define VS_SB_FREQLIMIT_LSB 0
  685. /*! \brief Bass enhancement mask.
  686. *
  687. * Bass enhancement in 1 dB steps, or disabled when zero.
  688. */
  689. #define VS_SB_AMPLITUDE 0x00F0
  690. /*! \brief Bass enhancement LSB. */
  691. #define VS_SB_AMPLITUDE_LSB 4
  692. /*! \brief Treble control lower limit frequency mask.
  693. *
  694. * Specified in 1 kHz steps.
  695. */
  696. #define VS_ST_FREQLIMIT 0x0F00
  697. /*! \brief Lower limit frequency LSB. */
  698. #define VS_ST_FREQLIMIT_LSB 8
  699. /*! \brief Treble control mask.
  700. *
  701. * Treble control in 1.5 dB steps, or disabled when zero.
  702. */
  703. #define VS_ST_AMPLITUDE 0xF000
  704. /*! \brief Bass enhancement LSB. */
  705. #define VS_ST_AMPLITUDE_LSB 12
  706. #endif
  707. /*@}*/
  708. /*!
  709. * \name Clock Frequency and Multiplier Register
  710. */
  711. /* ------------------------------------------------------------- */
  712. /*@{*/
  713. /*! \brief Register index. */
  714. #define VS_CLOCKF_REG 3
  715. /*! \brief Clock frequency mask.
  716. *
  717. * Should be set to crystal clock divided by 2000, if the clock is not
  718. * 24.576 MHz.
  719. *
  720. * Must be set before beginning decoding MP3 data. Otherwise the sample
  721. * rate will not be set correctly.
  722. *
  723. * Used for the VS1001, VS1011 and VS1002.
  724. */
  725. #if VS_HAS_SC_FREQ
  726. #define VS_SC_FREQ 0x7FFF
  727. /*! \brief Clock frequency LSB. */
  728. #define VS_SC_FREQ_LSB 0
  729. #endif
  730. /*! \brief VS1003/VS1033 clock frequency mask.
  731. *
  732. * Should be set to crystal clock divided by 4000, if the clock
  733. * is not 12.288 MHz.
  734. *
  735. * Used for the VS1003, VS1033 and VS1053.
  736. */
  737. #if VS_HAS_SC_X3FREQ
  738. #define VS_SC_X3FREQ 0x07FF
  739. #endif
  740. /*! \brief Allowed multiplier addition.
  741. *
  742. * Used for WMA decoding with the VS1003, VS1033 and VS1053.
  743. *
  744. * Summand 0.5 is not available on the VS1053.
  745. */
  746. #if VS_HAS_SC_ADD
  747. #define VS_SC_ADD 0x1800
  748. #define VS_SC_ADD_NONE 0x0000
  749. #if VS_HAS_SC_ADD2
  750. #define VS_SC_ADD_1_0 0x0800
  751. #define VS_SC_ADD_1_5 0x1000
  752. #define VS_SC_ADD_2_0 0x1800
  753. #else
  754. #define VS_SC_ADD_0_5 0x0800
  755. #define VS_SC_ADD_1_0 0x1000
  756. #define VS_SC_ADD_1_5 0x1800
  757. #endif
  758. #endif
  759. /*! \brief Clock multiplier.
  760. *
  761. * Available on the VS1003, VS1033 and VS1053. However, multiplier 1.5
  762. * is not available on the VS1053.
  763. */
  764. #if VS_HAS_SC_MULT
  765. #define VS_SC_MULT 0xE000
  766. #define VS_SC_MULT_1_0 0x0000
  767. #if VS_HAS_SC_MULT5
  768. #define VS_SC_MULT_2_0 0x2000
  769. #define VS_SC_MULT_2_5 0x4000
  770. #define VS_SC_MULT_3_0 0x6000
  771. #define VS_SC_MULT_3_5 0x8000
  772. #define VS_SC_MULT_4_0 0xA000
  773. #define VS_SC_MULT_4_5 0xC000
  774. #define VS_SC_MULT_5_0 0xE000
  775. #else
  776. #define VS_SC_MULT_1_5 0x2000
  777. #define VS_SC_MULT_2_0 0x4000
  778. #define VS_SC_MULT_2_5 0x6000
  779. #define VS_SC_MULT_3_0 0x8000
  780. #define VS_SC_MULT_3_5 0xA000
  781. #define VS_SC_MULT_4_0 0xC000
  782. #define VS_SC_MULT_4_5 0xE000
  783. #endif
  784. #endif
  785. /*! \brief Clock doubler enable.
  786. *
  787. * Used for the VS1001, VS1011 and VS1002.
  788. */
  789. #if VS_HAS_CF_DOUBLER
  790. #define VS_CF_DOUBLER 0x8000
  791. #endif
  792. /*@}*/
  793. /*!
  794. * \name Decode Time Register
  795. */
  796. /* ------------------------------------------------------------- */
  797. /*@{*/
  798. /*! \brief Register index.
  799. *
  800. * This register contains the decode time in full seconds or zero after
  801. * resetting the decoder.
  802. *
  803. * The user may change the value of this register. However, in that case
  804. * the new value should be written twice.
  805. */
  806. #define VS_DECODE_TIME_REG 4
  807. /*@}*/
  808. /*!
  809. * \name Miscellaneous Audio Data Register
  810. */
  811. /* ------------------------------------------------------------- */
  812. /*@{*/
  813. /*! \brief Register index.
  814. *
  815. * Usage on the VS1001K differs.
  816. */
  817. #define VS_AUDATA_REG 5
  818. /*! \brief Stereo flag.
  819. *
  820. * 1 for stereo and 0 for mono. Read-only.
  821. *
  822. * On the VS1001K the most significant bit is used as a stereo indicator.
  823. */
  824. #if VS_HAS_AD_STEREO_BIT0
  825. #define VS_AD_STEREO 0x0001
  826. #else
  827. #define VS_AD_STEREO 0x8000
  828. #endif
  829. /*! \brief Current sampling rate mask.
  830. *
  831. * Value is sample rate divided by 2. Writing to this register will
  832. * change the sample rate on the run.
  833. *
  834. * To reduce the digital power consumption when idle, you can set
  835. * a low sample rate.
  836. */
  837. #if VS_HAS_AD_SAMRATE
  838. #if VS_HAS_AD_STEREO_BIT0
  839. #define VS_AD_SAMRATE 0xFFFE
  840. /*! \brief Crystal clock LSB. */
  841. #define VS_AD_SAMRATE_LSB 1
  842. #else
  843. #define VS_AD_SAMRATE 0x7FFF
  844. #define VS_AD_SAMRATE_LSB 0
  845. #endif
  846. #endif
  847. /*! \brief Current bit rate mask.
  848. */
  849. #if VS_HAS_AD_BITRATE
  850. #define VS_AD_BITRATE 0x01FF
  851. #define VS_AD_BITRATE_LSB 0
  852. #endif
  853. /*! \brief Current sampling rate index mask.
  854. */
  855. #if VS_HAS_AD_SAMRATE_IDX
  856. #define VS_AD_SAMRATE_IDX 0x1E00
  857. #define VS_AD_SAMRATE_IDX_LSB 9
  858. #define VS_AD_SAMRATE_44100 1
  859. #define VS_AD_SAMRATE_48000 2
  860. #define VS_AD_SAMRATE_32000 3
  861. #define VS_AD_SAMRATE_22050 4
  862. #define VS_AD_SAMRATE_24000 5
  863. #define VS_AD_SAMRATE_16000 6
  864. #define VS_AD_SAMRATE_11025 7
  865. #define VS_AD_SAMRATE_12000 8
  866. #define VS_AD_SAMRATE_8000 9
  867. #endif
  868. /*@}*/
  869. /*!
  870. * \name RAM Read/Write Register
  871. */
  872. /* ------------------------------------------------------------- */
  873. /*@{*/
  874. /*! \brief Register index.
  875. *
  876. * Used to upload application programs and data to instruction and data RAM.
  877. */
  878. #define VS_WRAM_REG 6
  879. /*@}*/
  880. /*!
  881. * \name RAM Read/Write Base Address Register
  882. */
  883. /* ------------------------------------------------------------- */
  884. /*@{*/
  885. /*! \brief Register index.
  886. *
  887. * Used to upload application programs and data to instruction and data RAM.
  888. */
  889. #define VS_WRAMADDR_REG 7
  890. /*@}*/
  891. /*!
  892. * \name Stream Header Data Register 0
  893. */
  894. /* ------------------------------------------------------------- */
  895. /*@{*/
  896. /*! \brief Register index.
  897. *
  898. * For WAV, AAC, WMA and MIDI data, the register contains the (average)
  899. * data rate measured in bytes per second.
  900. *
  901. * For MP3 streams, the register contains MP3 header information.
  902. *
  903. * Not available in the VS1103.
  904. */
  905. #if VS_HAS_HDAT0_REG
  906. #define VS_HDAT0_REG 8
  907. #define VS_HDAT0_EMPHAS 0x0003
  908. #define VS_HDAT0_EMPHAS_LSB 0
  909. #define VS_HDAT0_EMPHAS_NONE 0
  910. #define VS_HDAT0_EMPHAS_5015 1
  911. #define VS_HDAT0_EMPHAS_J17 3
  912. #define VS_HDAT0_ORIGIN 0x0004
  913. #define VS_HDAT0_COPY 0x0008
  914. #define VS_HDAT0_EXT 0x0030
  915. #define VS_HDAT0_MODE 0x00C0
  916. #define VS_HDAT0_MODE_LSB 6
  917. #define VS_HDAT0_MODE_STEREO 0
  918. #define VS_HDAT0_MODE_JSTEREO 1
  919. #define VS_HDAT0_MODE_DUAL 2
  920. #define VS_HDAT0_MODE_MONO 3
  921. #define VS_HDAT0_PRIV 0x0100
  922. #define VS_HDAT0_PAD 0x0200
  923. #define VS_HDAT0_SAMRATE 0x0C00
  924. #define VS_HDAT0_SAMRATE_LSB 10
  925. #define VS_HDAT0_SAMRATE_11B 0
  926. #define VS_HDAT0_SAMRATE_12B 1
  927. #define VS_HDAT0_SAMRATE_8B 2
  928. #define VS_HDAT0_BITRATE 0xF000
  929. #endif
  930. /*@}*/
  931. /*!
  932. * \name VS1103 Input Register 0
  933. */
  934. /* ------------------------------------------------------------- */
  935. /*@{*/
  936. /*! \brief Register index. */
  937. #if VS_HAS_IN0_REG
  938. #define VS_IN0_REG 8
  939. #endif
  940. /*@}*/
  941. /*!
  942. * \name Stream Header Data Register 1
  943. */
  944. /* ------------------------------------------------------------- */
  945. /*@{*/
  946. /*! \brief Register index.
  947. *
  948. * Not available in the VS1103.
  949. */
  950. #if VS_HAS_HDAT1_REG
  951. #define VS_HDAT1_REG 9
  952. #define VS_HDAT1_PROT 0x0001
  953. #define VS_HDAT1_LAYER 0x0006
  954. #define VS_HDAT1_ID 0x0018
  955. #define VS_HDAT1_SYNC 0xFFE0
  956. #define VS_HDAT1_WAV 0x7665
  957. #define VS_HDAT1_AAC_ADTS 0x4154
  958. #define VS_HDAT1_AAC_ADIF 0x4144
  959. #define VS_HDAT1_AAC_MP4 0x4D34
  960. #define VS_HDAT1_WMA 0x574D
  961. #define VS_HDAT1_MIDI 0x4D54
  962. #define VS_HDAT1_OGG 0x4F67
  963. #endif
  964. /*@}*/
  965. /*!
  966. * \name VS1103 Input Register 1
  967. */
  968. /* ------------------------------------------------------------- */
  969. /*@{*/
  970. /*! \brief Register index. */
  971. #if VS_HAS_IN1_REG
  972. #define VS_IN1_REG 9
  973. #endif
  974. /*@}*/
  975. /*!
  976. * \name Application Start Address Register
  977. *
  978. * Used to activate previously uploaded application programs.
  979. */
  980. /* ------------------------------------------------------------- */
  981. /*@{*/
  982. /*! \brief Register index. */
  983. #define VS_AIADDR_REG 10
  984. /*@}*/
  985. /*!
  986. * \name Volume Control Register
  987. */
  988. /* ------------------------------------------------------------- */
  989. /*@{*/
  990. /*! \brief Register index.
  991. *
  992. * After hardware reset, volume is at maximum value. Software reset does
  993. * not change volume settings.
  994. *
  995. * Setting this register to \ref VS_VOL_OFF will put the chip in analog
  996. * power down mode.
  997. *
  998. * On some earlier chips, audio interrupts may be missed when writing
  999. * to this register. This will not happen on the VS1053, where volume
  1000. * changes are delayed until the next batch of samples are sent to the
  1001. * audio FIFO.
  1002. */
  1003. #define VS_VOL_REG 11
  1004. /*! \brief Right channel volume mask.
  1005. *
  1006. * Attenuation is given in 0.5 dB steps or 255 for mute.
  1007. */
  1008. #define VS_VOL_RIGHT 0x00FF
  1009. /*! \brief Right channel volume LSB. */
  1010. #define VS_VOL_RIGHT_LSB 0
  1011. /*! \brief Right channel volume mask.
  1012. *
  1013. * Attenuation is given in 0.5 dB steps or 255 for mute.
  1014. */
  1015. #define VS_VOL_LEFT 0xFF00
  1016. /*! \brief Right channel volume LSB. */
  1017. #define VS_VOL_LEFT_LSB 8
  1018. #define VS_VOL_MAX 0x0000
  1019. #define VS_VOL_MIN 0xFEFE
  1020. #define VS_VOL_OFF 0xFFFF
  1021. /*@}*/
  1022. /*!
  1023. * \name VS1103 Mixer Volume Register
  1024. */
  1025. /* ------------------------------------------------------------- */
  1026. /*@{*/
  1027. /*! \brief Register index.
  1028. *
  1029. */
  1030. #if VS_HAS_MIXERVOL_REG
  1031. #define VS_MIXERVOL_REG 12
  1032. #define VS_SMV_GAIN1 0x001F
  1033. #define VS_SMV_GAIN2 0x03E0
  1034. #define VS_SMV_GAIN3 0x7C00
  1035. #define VS_SMV_ACTIVE 0x8000
  1036. #endif
  1037. /*@}*/
  1038. /*!
  1039. * \name VS1103 IMA ADPCM Record Control Register
  1040. */
  1041. /* ------------------------------------------------------------- */
  1042. /*@{*/
  1043. /*! \brief Register index.
  1044. *
  1045. */
  1046. #if VS_HAS_ADPCMRECCTL_REG
  1047. #define VS_ADPCMRECCTL_REG 13
  1048. #define VS_SARC_GAIN4 0x003F
  1049. #define VS_SARC_MANUALGAIN 0x0040
  1050. #define VS_SARC_OUTOFADPCM 0x0080
  1051. #endif
  1052. /*@}*/
  1053. /*!
  1054. * \name Application Control Registers
  1055. */
  1056. /* ------------------------------------------------------------- */
  1057. /*@{*/
  1058. /*! \brief Application register 0 index.
  1059. *
  1060. * Do not use with VS1001. Also used for mixer volume on the VS1103.
  1061. */
  1062. #if VS_HAS_AICTRL0_REG
  1063. #define VS_AICTRL0_REG 12
  1064. #endif
  1065. /*! \brief VS1001K application register 0 index.
  1066. *
  1067. * A second register is available at VS_AICTRL_REG + 1.
  1068. */
  1069. #if VS_HAS_AICTRL_REG
  1070. #define VS_AICTRL_REG 13
  1071. #endif
  1072. /*! \brief Application register 1 index.
  1073. *
  1074. * Register 0 on the VS1001. Also used for IMA ADPCM record control in
  1075. * the VS1103.
  1076. */
  1077. #if VS_HAS_AICTRL1_REG
  1078. #define VS_AICTRL1_REG 13
  1079. #endif
  1080. /*! \brief Application register 2 index.
  1081. *
  1082. * Register 1 on the VS1001.
  1083. */
  1084. #if VS_HAS_AICTRL2_REG
  1085. #define VS_AICTRL2_REG 14
  1086. #endif
  1087. /*! \brief Application register 3 index.
  1088. *
  1089. * Do not use with VS1001.
  1090. */
  1091. #if VS_HAS_AICTRL3_REG
  1092. #define VS_AICTRL3_REG 15
  1093. #define VS_AICTRL3_STEREO 0
  1094. #define VS_AICTRL3_DUALCHANNEL 1
  1095. #define VS_AICTRL3_LEFT 2
  1096. #define VS_AICTRL3_RIGHT 3
  1097. #define VS_AICTRL3_MONOMIX 4
  1098. #define VS_ENCMODE_ADPCM 0x0000
  1099. #define VS_ENCMODE_LPCM 0x0010
  1100. #define VS_ENCMODE_G711_ULAW 0x0020
  1101. #define VS_ENCMODE_G711_ALAW 0x0030
  1102. #define VS_ENCMODE_G722 0x0040
  1103. #define VS_ENCMODE_OGGVORBIS 0x0050
  1104. #define VS_ENCMODE_MP3 0x0060
  1105. #define VS_AICTRL3_CODECMODE 0x8000
  1106. #define VS_AICTRL3_ENABLEAEC 0x4000
  1107. #define VS_AICTRL3_ENABLEUART 0x2000
  1108. #endif
  1109. /*@}*/
  1110. /*
  1111. * Bytes needed to flush internal VS buffer (size of VS internal buffer)
  1112. */
  1113. #ifndef VS_FLUSH_BYTES
  1114. #define VS_FLUSH_BYTES 2048
  1115. #endif
  1116. /*
  1117. * Status of the decoder
  1118. */
  1119. #define CODEC_STATUS_IDLE 0
  1120. #define CODEC_STATUS_PLAYING 1
  1121. #define CODEC_STATUS_RECORDING 2
  1122. /*
  1123. * Header info filled by VsGetHeaderInfo.
  1124. */
  1125. #ifdef __GNUC__
  1126. typedef struct NUT_PACKED_TYPE {
  1127. uint16_t vshi_no_crc:1;
  1128. uint16_t vshi_layer:2;
  1129. uint16_t vshi_id:2;
  1130. uint16_t vshi_syncword:11;
  1131. uint16_t vshi_emphasis:2;
  1132. uint16_t vshi_original:1;
  1133. uint16_t vshi_copyright:1;
  1134. uint16_t vshi_extension:2;
  1135. uint16_t vshi_mode:2;
  1136. uint16_t vshi_private_bit:1;
  1137. uint16_t vshi_pad_bit:1;
  1138. uint16_t vshi_sample_rate:2;
  1139. uint16_t vshi_bitrate:4;
  1140. } VS_HEADERINFO;
  1141. #endif
  1142. #ifndef VSCODEC_CMD_TIMEOUT
  1143. /*! \brief Minimum time in milliseconds to held hardware reset low. */
  1144. #define VSCODEC_CMD_TIMEOUT NUT_WAIT_INFINITE
  1145. #endif
  1146. /*!
  1147. * \brief Internal codec control block.
  1148. */
  1149. typedef struct _VSDCB {
  1150. int dcb_pbstat; /*!< \brief Playback status. */
  1151. uint32_t dcb_scmd; /*!< \brief Requested command flags, see VSREQ_ flags. */
  1152. int dcb_rvol; /*!< \brief Volume of right channel. */
  1153. int dcb_lvol; /*!< \brief Volume of left channel. */
  1154. int dcb_treb; /*!< \brief Treble enhancement *1.5dB. */
  1155. int dcb_tfin; /*!< \brief Treble limit frequency *1000Hz. */
  1156. int dcb_bass; /*!< \brief Bass enhancement *1dB. */
  1157. int dcb_bfin; /*!< \brief Bass limit frequency *10Hz. */
  1158. uint16_t dcb_sinefreq; /*!< \brief Requested beep frequency. */
  1159. uint32_t dcb_pbwlo; /*!< \brief Playback buffer low watermark. */
  1160. uint32_t dcb_pbwhi; /*!< \brief Playback buffer high watermark. */
  1161. uint32_t dcb_wtmo; /*!< \brief Write timeout. */
  1162. uint32_t dcb_rtmo; /*!< \brief Read timeout. */
  1163. HANDLE dcb_bufque; /*!< \brief Buffer change event. */
  1164. HANDLE dcb_feedme; /*!< \brief Decoder hungry event. */
  1165. uint16_t dcb_codec_ver; /*!< \brief Chip version, 1001, 1002, 1053 etc. */
  1166. char dcb_codec_rev; /*!< \brief Chip revision character. */
  1167. uint32_t dcb_dec_caps; /*!< \brief Decoder capabilities. */
  1168. uint32_t dcb_cod_caps; /*!< \brief Encoder capabilities. */
  1169. uint32_t dcb_midi_caps; /*!< \brief MIDI capabilities. */
  1170. uint32_t dcb_cod_mode; /*!< \brief Encoder mode. */
  1171. int (*dcb_isready)(void);
  1172. int (*dcb_sendcmd)(void *, size_t);
  1173. int (*dcb_senddata)(const uint8_t *, size_t);
  1174. int (*dcb_control)(int req, void *conf);
  1175. int (*dcb_recvdata)(void *, size_t);
  1176. } VSDCB;
  1177. #ifndef VSCODEC_DATA_CHUNK_SIZE
  1178. /*! \brief Number of data bytes we can send without checking DREQ. */
  1179. #define VSCODEC_DATA_CHUNK_SIZE 32
  1180. #endif
  1181. extern uint8_t zero_chunk[VSCODEC_DATA_CHUNK_SIZE];
  1182. extern NUTDEVICE devVsCodec;
  1183. extern NUTDEVICE devSpiVsCodec0;
  1184. /*@}*/
  1185. extern int VsCodecWaitReady(NUTDEVICE *dev, uint32_t tmo);
  1186. extern uint16_t VsCodecReg(NUTDEVICE *dev, uint_fast8_t op, uint_fast8_t reg, uint_fast16_t val);
  1187. extern uint16_t VsCodecMode(NUTDEVICE *dev, uint_fast16_t flags, uint_fast16_t mask);
  1188. extern int VsDecoderSetVolume(NUTDEVICE *dev, int left, int right);
  1189. extern int VsDecoderSetBass(NUTDEVICE *dev, int treb, int tfin, int bass, int bfin);
  1190. extern uint16_t VsCodecBeep(NUTDEVICE *dev, uint16_t fsin);
  1191. extern int VsDecoderBufferInit(NUTDEVICE *dev, uint32_t size);
  1192. extern int VsCodecIOCtl(NUTDEVICE * dev, int req, void *conf);
  1193. extern int VsCodecRead(NUTFILE * nfp, void *data, int len);
  1194. extern int VsCodecWrite(NUTFILE * nfp, const void *data, int len);
  1195. NUTFILE *VsCodecOpen(NUTDEVICE * dev, const char *name, int mode, int acc);
  1196. extern int VsCodecClose(NUTFILE * nfp);
  1197. #ifdef __HARVARD_ARCH__
  1198. extern int VsCodecWrite_P(NUTFILE * nfp, PGM_P buffer, int len);
  1199. #endif
  1200. extern void FeederThread(void *arg) __attribute__ ((noreturn));
  1201. #endif