vs10xx.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. #ifndef _DEV_VS10XX_H_
  2. #define _DEV_VS10XX_H_
  3. /*
  4. * Copyright (C) 2001-2007 by egnite Software GmbH. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*
  35. * $Log$
  36. * Revision 1.3 2009/01/17 11:26:47 haraldkipp
  37. * Getting rid of two remaining BSD types in favor of stdint.
  38. * Replaced 'u_int' by 'unsinged int' and 'uptr_t' by 'uintptr_t'.
  39. *
  40. * Revision 1.2 2008/08/11 06:59:59 haraldkipp
  41. * BSD types replaced by stdint types (feature request #1282721).
  42. *
  43. * Revision 1.1 2007/04/12 08:59:55 haraldkipp
  44. * VS10XX decoder support added.
  45. *
  46. */
  47. #include <cfg/audio.h>
  48. #include <sys/types.h>
  49. #include <stdint.h>
  50. /*!
  51. * \file dev/vs10xx.h
  52. * \brief Network interface controller definitions.
  53. */
  54. /*!
  55. * \addtogroup xgVs10xx
  56. */
  57. /*@{*/
  58. /*
  59. * Instruction opcodes.
  60. */
  61. #define VS_OPCODE_READ 3
  62. #define VS_OPCODE_WRITE 2
  63. /*!
  64. * \name Mode Control Register
  65. */
  66. /* ------------------------------------------------------------- */
  67. /*@{*/
  68. /*! \brief Register index. */
  69. #define VS_MODE_REG 0
  70. /*! \brief Left channel inverted. */
  71. #define VS_SM_DIFF 0x0001
  72. /*! \brief Allow MPEG Layers I & II.
  73. *
  74. * Determines whether it is allowed to decode MPEG 1 and 2 Layers I and II
  75. * in addition to Layer III. If you enable Layer I and Layer II decoding,
  76. * you are liable for any patent issues that may arise. Joint licensing of
  77. * MPEG 1.0 / 2.0 Layer III does not cover all patents pertaining to
  78. * Layers I and II.
  79. */
  80. #define VS_SM_LAYER12 0x0002
  81. /*! \brief VS1001K fast forward.
  82. *
  83. * By setting this bit, the player starts to accept data at a high speed, and
  84. * just decodes the audio headers silently without playing any audio data.
  85. * This can be used to fast-forward data with safe landing.
  86. * Register \ref VS_DECODE_TIME_REG is updated during a fast-forward just as
  87. * normal.
  88. *
  89. * Note, that this bit is available on the VS1001K only and is used as MPEG
  90. * Layer I & II enable on other members of the VS10xx family.
  91. */
  92. #define VS_SM_FFWD 0x0002
  93. /*! \brief Soft reset.
  94. *
  95. * Bit is cleared automatically.
  96. */
  97. #define VS_SM_RESET 0x0004
  98. /*! \brief VS1001 MPEG Layers I & II enable.
  99. *
  100. * May not work reliable due to firmware problems.
  101. *
  102. * If you enable Layer I and Layer II decoding, you are liable for any patent
  103. * issues that may arise.
  104. */
  105. #define VS_SM_MP12 0x0008
  106. /*! \brief Jump out of wave decoding.
  107. *
  108. * Set this bit to stop WAV, WMA and MIDI file playing before the end of
  109. * the file has been reached. Continue sending zeros for WAV and more data
  110. * for MIDI and WMA until this bit is cleared again.
  111. *
  112. * Not available on the VS1001K.
  113. */
  114. #define VS_SM_OUTOFWAV 0x0008
  115. /*! \brief Power down.
  116. *
  117. * During powerdown, no audio is played and no SDI operations are performed.
  118. * It is recommended to set \ref VS_VOL_REG to 0xFFFF before setting this
  119. * bit.
  120. *
  121. * For best power down efficiency, activate hardware reset.
  122. *
  123. * Not available on the VS1011. Although defined, this is not implemented
  124. * in the VS1001K firmware.
  125. */
  126. #define VS_SM_PDOWN 0x0010
  127. /*! \brief VS1001K unknown function. */
  128. #define VS_SM_DAC 0x0020
  129. /*! \brief Allow SDI tests.
  130. *
  131. * Not required for the VS1001K, where tests are enabled by default.
  132. */
  133. #define VS_SM_TESTS 0x0020
  134. /*! \brief VS1001K unknown function. */
  135. #define VS_SM_DACMONO 0x0040
  136. /*! \brief Stream mode.
  137. *
  138. * When stream mode is activated, data should be sent with as even
  139. * intervals as possible (and preferable with data blocks of less
  140. * than 512 bytes). The decoder makes every attempt to keep its input
  141. * buffer half full by changing its playback speed upto 5%. For best
  142. * quality sound, the average speed error should be within 0.5%, the
  143. * bitrate should not exceed 160 kbit/s and VBR should not be used.
  144. *
  145. * Not available on the VS1001K.
  146. */
  147. #define VS_SM_STREAM 0x0040
  148. /*! \brief VS1001K bass/treble enhancer. */
  149. #define VS_SM_BASS 0x0080
  150. /*! \brief Active edge of the data clock.
  151. *
  152. * If clear data is read at the rising edge, and if set data is read
  153. * at the falling edge.
  154. */
  155. #define VS_SM_DACT 0x0100
  156. /*! \brief . */
  157. #define VS_SM_BYTEORD 0x0200
  158. /*! \brief SDI most significant bit last.
  159. *
  160. * Bytes are, however, still sent in default order.
  161. */
  162. #define VS_SM_SDIORD 0x0200
  163. /*! \brief VS1001K master mode.
  164. *
  165. * Untested and not recommended.
  166. */
  167. #define VS_SM_IBMODE 0x0400
  168. /*! \brief Share SPI chip select. */
  169. #define VS_SM_SDISHARE 0x0400
  170. /*! \brief VS1001K master mode clock speed.
  171. *
  172. * Untested and not recommended.
  173. */
  174. #define VS_SM_IBCLK 0x0800
  175. /*! \brief VS1002 native SDI mode.
  176. *
  177. * Default is 0 on the VS1011E and 1 on the VS1002.
  178. *
  179. * Not available on the VS1001K.
  180. */
  181. #define VS_SM_SDINEW 0x0800
  182. /*! \brief ADPCM recording.
  183. *
  184. * Available on VS1033.
  185. */
  186. #define VS_SM_ADPCM 0x1000
  187. /*! \brief ADPCM high pass filter.
  188. *
  189. * If set at the same time as \ref VS_SM_ADPCM and \ref VS_SM_RESET,
  190. * ADPCM mode will start with a high-pass filter. This may help
  191. * intelligibility of speech when there is lots of background noise.
  192. *
  193. * Available on VS1033.
  194. */
  195. #define VS_SM_ADPCM_HP 0x2000
  196. /*! \brief ADPCM recording selector.
  197. *
  198. * Used to select the input for ADPCM recording. If cleared, microphone
  199. * input is used. If set to 1, LINEIN is used instead.
  200. *
  201. * Available on VS1033.
  202. */
  203. #define VS_SM_LINE_IN 0x4000
  204. /*! \brief Input clock range.
  205. *
  206. * Activates a clock divider at the XTAL input. Should be set as soon
  207. * as possible after a chip reset.
  208. *
  209. * Available on VS1033.
  210. */
  211. #define VS_SM_CLK_RANGE 0x8000
  212. /*@}*/
  213. /*!
  214. * \name Status Register
  215. */
  216. /*@{*/
  217. /* ------------------------------------------------------------- */
  218. /*! \brief Register index. */
  219. #define VS_STATUS_REG 1
  220. /*! \brief Internal analog volume control mask.
  221. *
  222. * These bits is meant to be used by the internal firmware only.
  223. *
  224. * - 0 for 0 dB
  225. * - 1 for -6 dB
  226. * - 3 for -12 dB
  227. */
  228. #define VS_SS_AVOL 0x0003
  229. /*! \brief Internal analog volume control LSB. */
  230. #define VS_SS_AVOL_LSB 0
  231. /*! \brief Internal analog power down.
  232. *
  233. * This bit is meant to be used by the internal firmware only.
  234. */
  235. #define VS_SS_APDOWM1 0x0004
  236. /*! \brief Analog driver power down.
  237. *
  238. * This bit is typically controlled by the internal firmware. However,
  239. * if the application wants to power down the decoder with a minimum
  240. * power-off transient, this bit should be set to 1 a few milliseconds
  241. * before activating reset.
  242. */
  243. #define VS_SS_APDOWN2 0x0008
  244. /*! \brief Version mask.
  245. *
  246. * - 0 for VS1001
  247. * - 1 for VS1011
  248. * - 2 for VS1002 and VS1011E, see \ref VS_SM_SDINEW
  249. * - 3 for VS1003
  250. */
  251. #define VS_SS_VER 0x0070
  252. /*! \brief Version LSB. */
  253. #define VS_SS_VER_LSB 4
  254. /*@}*/
  255. /*!
  256. * \name VS1001 internal frequency control register.
  257. */
  258. /* ------------------------------------------------------------- */
  259. /*@{*/
  260. /*! \brief Register index.
  261. *
  262. * Use only on older chip revisions?
  263. */
  264. #define VS_INT_FCTLH_REG 2
  265. /*@}*/
  266. /*!
  267. * \name Bass/Treble Enhancer Register
  268. */
  269. /* ------------------------------------------------------------- */
  270. /*@{*/
  271. /*! \brief Register index.
  272. *
  273. * For the VS1001K see \ref VS_SM_BASS.
  274. */
  275. #define VS_BASS_REG 2
  276. /*! \brief Bass enhancer lower limit frequency mask.
  277. *
  278. * Specified in 10 Hz steps.
  279. */
  280. #define VS_SB_FREQLIMIT 0x000F
  281. /*! \brief Lower limit frequency LSB. */
  282. #define VS_SB_FREQLIMIT_LSB 0
  283. /*! \brief Bass enhancement mask.
  284. *
  285. * Bass enhancement in 1 dB steps, or disabled when zero.
  286. */
  287. #define VS_SB_AMPLITUDE 0x00F0
  288. /*! \brief Bass enhancement LSB. */
  289. #define VS_SB_AMPLITUDE_LSB 4
  290. /*! \brief Treble control lower limit frequency mask.
  291. *
  292. * Specified in 1 kHz steps.
  293. */
  294. #define VS_ST_FREQLIMIT 0x000F
  295. /*! \brief Lower limit frequency LSB. */
  296. #define VS_ST_FREQLIMIT_LSB 0
  297. /*! \brief Treble control mask.
  298. *
  299. * Treble control in 1.5 dB steps, or disabled when zero.
  300. */
  301. #define VS_ST_AMPLITUDE 0x00F0
  302. /*! \brief Bass enhancement LSB. */
  303. #define VS_ST_AMPLITUDE_LSB 4
  304. /*@}*/
  305. /*!
  306. * \name Clock Frequency and Multiplier Register
  307. */
  308. /* ------------------------------------------------------------- */
  309. /*@{*/
  310. /*! \brief Register index. */
  311. #define VS_CLOCKF_REG 3
  312. /*! \brief Clock frequency mask.
  313. *
  314. * Should be set to crystal clock divided by 2000, if the clock
  315. * is not 24.576 MHz.
  316. *
  317. * Used for the VS1001, VS1011 and VS1002.
  318. */
  319. #define VS_SC_FREQ 0x7FFF
  320. /*! \brief VS1003/VS1033 clock frequency mask.
  321. *
  322. * Should be set to crystal clock divided by 4000, if the clock
  323. * is not 12.288 MHz.
  324. *
  325. * Used for the VS1003 and VS1033.
  326. */
  327. #define VS_SC_X3FREQ 0x07FF
  328. /*! \brief Clock frequency LSB. */
  329. #define VS_SC_FREQ_LSB 0
  330. /*! \brief Allowed multiplier addition.
  331. *
  332. * Used for WMA decoding with the VS1003 and VS1033.
  333. */
  334. #define VS_SC_ADD 0x1800
  335. /*! \brief Clock multiplier.
  336. *
  337. * Used for the VS1003 and VS1033.
  338. */
  339. #define VS_SC_MULT 0xE000
  340. /*! \brief Clock doubler enable.
  341. *
  342. * Used for the VS1001, VS1011 and VS1002.
  343. */
  344. #define VS_CF_DOUBLER 0x8000
  345. /*@}*/
  346. /*!
  347. * \name Decode Time Register
  348. */
  349. /* ------------------------------------------------------------- */
  350. /*@{*/
  351. /*! \brief Register index.
  352. *
  353. * This read-only register contains the decode time in full seconds or
  354. * zero after resetting the decoder.
  355. */
  356. #define VS_DECODE_TIME_REG 4
  357. /*@}*/
  358. /*!
  359. * \name Miscellaneous Audio Data Register
  360. */
  361. /* ------------------------------------------------------------- */
  362. /*@{*/
  363. /*! \brief Register index.
  364. *
  365. * Usage on the VS1001K differs.
  366. */
  367. #define VS_AUDATA_REG 5
  368. /*! \brief Stereo flag.
  369. *
  370. * Set to 1 for stereo and 0 for mono. Read-only.
  371. */
  372. #define VS_AD_STEREO 0x0001
  373. /*! \brief Current sampling rate mask.
  374. *
  375. * Value is sample rate divided by 2. Writing to this register will
  376. * change the sample rate on the run.
  377. */
  378. #define VS_AD_SRATE 0xFFFE
  379. /*! \brief Crystal clock LSB. */
  380. #define VS_AD_SRATE_LSB 1
  381. /*@}*/
  382. /*!
  383. * \name RAM Read/Write Register
  384. */
  385. /* ------------------------------------------------------------- */
  386. /*@{*/
  387. /*! \brief Register index.
  388. *
  389. * Used to upload application programs and data to instruction and data RAM.
  390. */
  391. #define VS_WRAM_REG 6
  392. /*@}*/
  393. /*!
  394. * \name RAM Read/Write Base Address Register
  395. */
  396. /* ------------------------------------------------------------- */
  397. /*@{*/
  398. /*! \brief Register index.
  399. *
  400. * Used to upload application programs and data to instruction and data RAM.
  401. */
  402. #define VS_WRAMADDR_REG 7
  403. /*@}*/
  404. /*!
  405. * \name Stream Header Data Register 0
  406. */
  407. /* ------------------------------------------------------------- */
  408. /*@{*/
  409. /*! \brief Register index.
  410. *
  411. * Not available in the VS1103.
  412. */
  413. #define VS_HDAT0_REG 8
  414. /*@}*/
  415. /*!
  416. * \name VS1103 Input Register 0
  417. */
  418. /* ------------------------------------------------------------- */
  419. /*@{*/
  420. /*! \brief Register index. */
  421. #define VS_IN0_REG 8
  422. /*@}*/
  423. /*!
  424. * \name Stream Header Data Register 1
  425. */
  426. /* ------------------------------------------------------------- */
  427. /*@{*/
  428. /*! \brief Register index.
  429. *
  430. * Not available in the VS1103.
  431. */
  432. #define VS_HDAT1_REG 9
  433. /*@}*/
  434. /*!
  435. * \name VS1103 Input Register 1
  436. */
  437. /* ------------------------------------------------------------- */
  438. /*@{*/
  439. /*! \brief Register index. */
  440. #define VS_IN1_REG 9
  441. /*@}*/
  442. /*!
  443. * \name Application Start Address Register
  444. *
  445. * Used to activate previously uploaded application programs.
  446. */
  447. /* ------------------------------------------------------------- */
  448. /*@{*/
  449. /*! \brief Register index. */
  450. #define VS_AIADDR_REG 10
  451. /*@}*/
  452. /*!
  453. * \name Volume Control Register
  454. */
  455. /* ------------------------------------------------------------- */
  456. /*@{*/
  457. /*! \brief Register index. */
  458. #define VS_VOL_REG 11
  459. /*! \brief Right channel volume mask.
  460. *
  461. * Attenuation is given in 0.5 dB steps or 255 for mute.
  462. */
  463. #define VS_VOL_RIGHT 0x00FF
  464. /*! \brief Right channel volume LSB. */
  465. #define VS_VOL_RIGHT_LSB 0
  466. /*! \brief Right channel volume mask.
  467. *
  468. * Attenuation is given in 0.5 dB steps or 255 for mute.
  469. */
  470. #define VS_VOL_LEFT 0xFF00
  471. /*! \brief Right channel volume LSB. */
  472. #define VS_VOL_LEFT_LSB 8
  473. /*@}*/
  474. /*!
  475. * \name VS1103 Mixer Volume Register
  476. */
  477. /* ------------------------------------------------------------- */
  478. /*@{*/
  479. /*! \brief Register index.
  480. *
  481. */
  482. #define VS_MIXERVOL_REG 12
  483. #define VS_SMV_GAIN1 0x001F
  484. #define VS_SMV_GAIN2 0x03E0
  485. #define VS_SMV_GAIN3 0x7C00
  486. #define VS_SMV_ACTIVE 0x8000
  487. /*@}*/
  488. /*!
  489. * \name VS1103 IMA ADPCM Record Control Register
  490. */
  491. /* ------------------------------------------------------------- */
  492. /*@{*/
  493. /*! \brief Register index.
  494. *
  495. */
  496. #define VS_ADPCMRECCTL_REG 13
  497. #define VS_SARC_GAIN4 0x003F
  498. #define VS_SARC_MANUALGAIN 0x0040
  499. #define VS_SARC_OUTOFADPCM 0x0080
  500. /*@}*/
  501. /*!
  502. * \name Application Control Registers
  503. */
  504. /* ------------------------------------------------------------- */
  505. /*@{*/
  506. /*! \brief Application register 0 index.
  507. *
  508. * Do not use with VS1001. Also used for mixer volume on the VS1103.
  509. */
  510. #define VS_AICTRL0_REG 12
  511. /*! \brief VS1001K application register 0 index.
  512. *
  513. * A second register is available at VS_AICTRL0_REG + 1.
  514. */
  515. #define VS_AICTRL_REG 13
  516. /*! \brief Application register 1 index.
  517. *
  518. * Register 0 on the VS1001. Also used for IMA ADPCM record control in
  519. * the VS1103.
  520. */
  521. #define VS_AICTRL1_REG 13
  522. /*! \brief Application register 2 index.
  523. *
  524. * Register 1 on the VS1001.
  525. */
  526. #define VS_AICTRL2_REG 14
  527. /*! \brief Application register 3 index.
  528. *
  529. * Do not use with VS1001.
  530. */
  531. #define VS_AICTRL3_REG 15
  532. /*@}*/
  533. /*
  534. * Bytes needed to flush internal VS buffer (size of VS interbal buffer)
  535. */
  536. #define VS_FLUSH_BYTES 2048
  537. /*
  538. * Status of the decoder
  539. */
  540. #define VS_STATUS_STOPPED 0
  541. #define VS_STATUS_RUNNING 1
  542. #define VS_STATUS_EOF 2
  543. #define VS_STATUS_EMPTY 4
  544. /*
  545. * Header info filled by VsGetHeaderInfo.
  546. */
  547. #ifdef __GNUC__
  548. typedef struct NUT_PACKED_TYPE {
  549. uint16_t vshi_no_crc:1;
  550. uint16_t vshi_layer:2;
  551. uint16_t vshi_id:2;
  552. uint16_t vshi_syncword:11;
  553. uint16_t vshi_emphasis:2;
  554. uint16_t vshi_original:1;
  555. uint16_t vshi_copyright:1;
  556. uint16_t vshi_extension:2;
  557. uint16_t vshi_mode:2;
  558. uint16_t vshi_private_bit:1;
  559. uint16_t vshi_pad_bit:1;
  560. uint16_t vshi_sample_rate:2;
  561. uint16_t vshi_bitrate:4;
  562. } VS_HEADERINFO;
  563. #endif
  564. extern int VsPlayerInit(void);
  565. extern int VsPlayerReset(uint16_t mode);
  566. extern int VsPlayerSetMode(uint16_t mode);
  567. extern int VsPlayerKick(void);
  568. extern int VsPlayerStop(void);
  569. extern int VsPlayerFlush(void);
  570. extern ureg_t VsPlayerInterrupts(ureg_t enable);
  571. extern ureg_t VsPlayerThrottle(ureg_t on);
  572. extern uint16_t VsPlayTime(void);
  573. extern unsigned int VsGetStatus(void);
  574. #ifdef __GNUC__
  575. extern int VsGetHeaderInfo(VS_HEADERINFO *vshi);
  576. #endif
  577. extern uint16_t VsMemoryTest(void);
  578. extern int VsSetVolume(ureg_t left, ureg_t right);
  579. extern int VsBeep(uint8_t fsin, uint8_t ms);
  580. /*@}*/
  581. #endif