vscodec.h
Go to the documentation of this file.00001 #ifndef _DEV_VSCODEC_H_
00002 #define _DEV_VSCODEC_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include <cfg/audio.h>
00043 #include <sys/device.h>
00044
00045 #include <stdint.h>
00046
00047
00048 #if defined(AUDIO_VS1001K)
00049 #define AUDIO0_VS1001K
00050 #elif defined(AUDIO_VS1011E)
00051 #define AUDIO0_VS1011E
00052 #elif defined(AUDIO_VS1002D)
00053 #define AUDIO0_VS1002D
00054 #elif defined(AUDIO_VS1003B)
00055 #define AUDIO0_VS1003B
00056 #elif defined(AUDIO_VS1033C)
00057 #define AUDIO0_VS1033C
00058 #elif defined(AUDIO_VS1053B)
00059 #define AUDIO0_VS1053B
00060 #elif defined(AUDIO_VSAUTO)
00061 #define AUDIO0_VSAUTO
00062 #endif
00063
00064
00065
00066
00067 #if defined(AUDIO0_VS1001K)
00068 #include <dev/vs1001.h>
00069 #elif defined(AUDIO0_VS1002D)
00070 #include <dev/vs1002.h>
00071 #elif defined(AUDIO0_VS1003B)
00072 #include <dev/vs1003.h>
00073 #elif defined(AUDIO0_VS1011E)
00074 #include <dev/vs1011.h>
00075 #elif defined(AUDIO0_VS1033C)
00076 #include <dev/vs1033.h>
00077 #elif defined(AUDIO0_VS1053B)
00078 #include <dev/vs1053.h>
00079 #elif !defined(AUDIO0_VSAUTO)
00080 #define AUDIO0_VSAUTO
00081 #endif
00082
00092
00093
00094 #ifndef AUDIO0_DAC_MIN_GAIN
00095 #define AUDIO0_DAC_MIN_GAIN -127
00096 #endif
00097 #ifndef AUDIO0_DAC_MAX_GAIN
00098 #define AUDIO0_DAC_MAX_GAIN 0
00099 #endif
00100
00101
00102 #ifndef AUDIO_DAC_MIN_GAIN
00103 #define AUDIO_DAC_MIN_GAIN AUDIO0_DAC_MIN_GAIN
00104 #endif
00105 #ifndef AUDIO_DAC_MAX_GAIN
00106 #define AUDIO_DAC_MAX_GAIN AUDIO0_DAC_MAX_GAIN
00107 #endif
00108
00109
00110
00111
00112
00113 #define AUDIO_SETWRITETIMEOUT 0x010d
00114 #define AUDIO_GETWRITETIMEOUT 0x010e
00115
00117 #define AUDIO_PLAY 0x3001
00118
00119 #define AUDIO_CANCEL 0x3002
00120 #define AUDIO_GET_STATUS 0x3003
00121 #define AUDIO_GET_PLAYGAIN 0x3004
00122 #define AUDIO_SET_PLAYGAIN 0x3005
00123 #define AUDIO_GET_PBSIZE 0x3006
00124 #define AUDIO_SET_PBSIZE 0x3007
00125 #define AUDIO_GET_PBLEVEL 0x3008
00126 #define AUDIO_GET_PBWLOW 0x3009
00127 #define AUDIO_SET_PBWLOW 0x300A
00128 #define AUDIO_GET_PBWHIGH 0x300B
00129 #define AUDIO_SET_PBWHIGH 0x300C
00130 #define AUDIO_BEEP 0x300F
00131
00132 #define AUDIO_GET_DECINFO 0x3010
00133
00134 #define AUDIO_GET_DECCAPS 0x3011
00135
00136 #define AUDIO_GET_DECFMTS 0x3012
00137
00138 #define AUDIO_SET_DECFMTS 0x3013
00139
00140 #define AUDIO_GET_CODINFO 0x3014
00141
00142 #define AUDIO_GET_CODCAPS 0x3015
00143
00144 #define AUDIO_GET_CODFMTS 0x3016
00145
00146 #define AUDIO_SET_CODFMTS 0x3017
00147
00148 #define AUDIO_GET_MIDINFO 0x3018
00149
00150 #define AUDIO_GET_MIDCAPS 0x3019
00151
00152
00153
00154
00155
00156 #define VS_OPCODE_READ 3
00157 #define VS_OPCODE_WRITE 2
00158
00159
00163
00166 #define VS_MODE_REG 0
00167
00168 #define VS_SM_DIFF 0x0001
00169
00178 #if VS_HAS_SM_LAYER12
00179 #define VS_SM_LAYER12 0x0002
00180 #endif
00181
00193 #if VS_HAS_SM_FFWD
00194 #define VS_SM_FFWD 0x0002
00195 #endif
00196
00201 #define VS_SM_RESET 0x0004
00202
00203
00215 #if VS_HAS_SM_MP12
00216 #define VS_SM_MP12 0x0008
00217 #endif
00218
00227 #if VS_HAS_SM_OUTOFWAV
00228 #define VS_SM_OUTOFWAV 0x0008
00229 #endif
00230
00240 #if VS_HAS_SM_CANCEL
00241 #define VS_SM_CANCEL 0x0008
00242 #endif
00243
00255 #if VS_HAS_SM_PDOWN
00256 #define VS_SM_PDOWN 0x0010
00257 #endif
00258
00261 #if VS_HAS_SM_EARSPEAKER
00262 #define VS_SM_EARSPEAKER_LO 0x0010
00263 #define VS_SM_SPATIAL_OFF 0
00264 #define VS_SM_SPATIAL_MINIMAL VS_SM_EARSPEAKER_LO
00265 #define VS_SM_SPATIAL_NORMAL VS_SM_EARSPEAKER_HI
00266 #define VS_SM_SPATIAL_EXTREME (VS_SM_EARSPEAKER_LO | VS_SM_EARSPEAKER_LO)
00267 #endif
00268
00279 #if VS_HAS_SM_DAC
00280 #define VS_SM_DAC 0x0020
00281 #endif
00282
00287 #if VS_HAS_SM_TESTS
00288 #define VS_SM_TESTS 0x0020
00289 #endif
00290
00301 #if VS_HAS_SM_DACMONO
00302 #define VS_SM_DACMONO 0x0040
00303 #endif
00304
00316 #if VS_HAS_SM_STREAM
00317 #define VS_SM_STREAM 0x0040
00318 #endif
00319
00324 #if VS_HAS_SM_BASS
00325 #define VS_SM_BASS 0x0080
00326 #endif
00327
00328 #if VS_HAS_SM_EARSPEAKER
00329 #define VS_SM_EARSPEAKER_HI 0x0080
00330 #endif
00331
00337 #define VS_SM_DACT 0x0100
00338
00344 #define VS_SM_BITORD 0x0200
00345
00350 #define VS_SM_SDIORD 0x0200
00351
00359 #if VS_HAS_SM_IBMODE
00360 #define VS_SM_IBMODE 0x0400
00361 #endif
00362
00364 #if VS_HAS_SM_SDISHARE
00365 #define VS_SM_SDISHARE 0x0400
00366 #endif
00367
00375 #if VS_HAS_SM_IBCLK
00376 #define VS_SM_IBCLK 0x0800
00377 #endif
00378
00385 #if VS_HAS_SM_SDINEW
00386 #define VS_SM_SDINEW 0x0800
00387 #endif
00388
00393 #if VS_HAS_SM_ADPCM
00394 #define VS_SM_ADPCM 0x1000
00395 #endif
00396
00405 #if VS_HAS_SM_ADPCM_HP
00406 #define VS_SM_ADPCM_HP 0x2000
00407 #endif
00408
00416 #if VS_HAS_SM_LINE_IN
00417 #define VS_SM_LINE_IN 0x4000
00418 #endif
00419
00427 #if VS_HAS_SM_CLK_RANGE
00428 #define VS_SM_CLK_RANGE 0x8000
00429 #endif
00430
00436
00439 #define VS_STATUS_REG 1
00440
00449 #if VS_HAS_SS_AVOL
00450 #define VS_SS_AVOL 0x0003
00451
00452 #define VS_SS_AVOL_LSB 0
00453 #endif
00454
00463 #if VS_HAS_SS_VREF_1_65
00464 #define VS_SS_VREF_1_65 0x0001
00465 #endif
00466
00483 #if VS_HAS_SS_AD_CLOCK
00484 #define VS_SS_AD_CLOCK 0x0002
00485 #endif
00486
00491 #define VS_SS_APDOWM1 0x0004
00492
00503 #define VS_SS_APDOWN2 0x0008
00504
00515 #define VS_SS_VER 0x00F0
00516
00517 #define VS_SS_VER_LSB 4
00518
00519 #define VS1001_SS_VER 0
00520 #define VS1011_SS_VER 1
00521 #define VS1011E_SS_VER 2
00522 #define VS1002_SS_VER 2
00523 #define VS1003_SS_VER 3
00524 #define VS1053_SS_VER 4
00525 #define VS1033_SS_VER 5
00526 #define VS1103_SS_VER 7
00527
00534 #if VS_HAS_SS_VCM_DISABLE
00535 #define VS_SS_VCM_DISABLE 0x0400
00536 #endif
00537
00542 #if VS_HAS_SS_VCM_OVERLOAD
00543 #define VS_SS_VCM_OVERLOAD 0x0800
00544 #endif
00545
00555 #if VS_HAS_SS_SWING
00556 #define VS_SS_SWING 0x7000
00557 #define VS_SS_SWING_LSB 12
00558 #define VS_SS_SWING_NORMAL 0
00559 #define VS_SS_SWING_MAX 2
00560 #endif
00561
00567 #if VS_HAS_SS_DO_NOT_JUMP
00568 #define VS_SS_DO_NOT_JUMP 0x8000
00569 #endif
00570
00576
00582 #if VS_HAS_INT_FCTLH_REG
00583 #define VS_INT_FCTLH_REG 2
00584 #endif
00585
00591
00600 #if VS_HAS_BASS_REG
00601 #define VS_BASS_REG 2
00602
00612 #define VS_SB_FREQLIMIT 0x000F
00613
00614 #define VS_SB_FREQLIMIT_LSB 0
00615
00620 #define VS_SB_AMPLITUDE 0x00F0
00621
00622 #define VS_SB_AMPLITUDE_LSB 4
00623
00628 #define VS_ST_FREQLIMIT 0x0F00
00629
00630 #define VS_ST_FREQLIMIT_LSB 8
00631
00636 #define VS_ST_AMPLITUDE 0xF000
00637
00638 #define VS_ST_AMPLITUDE_LSB 12
00639 #endif
00640
00645
00648 #define VS_CLOCKF_REG 3
00649
00660 #if VS_HAS_SC_FREQ
00661 #define VS_SC_FREQ 0x7FFF
00662
00663 #define VS_SC_FREQ_LSB 0
00664 #endif
00665
00673 #if VS_HAS_SC_X3FREQ
00674 #define VS_SC_X3FREQ 0x07FF
00675 #endif
00676
00683 #if VS_HAS_SC_ADD
00684 #define VS_SC_ADD 0x1800
00685 #define VS_SC_ADD_NONE 0x0000
00686 #define VS_SC_ADD_1_0 0x0800
00687 #define VS_SC_ADD_1_5 0x1000
00688 #define VS_SC_ADD_2_0 0x1800
00689 #endif
00690
00696 #if VS_HAS_SC_MULT
00697 #define VS_SC_MULT 0xE000
00698 #define VS_SC_MULT_1_0 0x0000
00699 #define VS_SC_MULT_2_0 0x2000
00700 #define VS_SC_MULT_2_5 0x4000
00701 #define VS_SC_MULT_3_0 0x6000
00702 #define VS_SC_MULT_3_5 0x8000
00703 #define VS_SC_MULT_4_0 0xA000
00704 #define VS_SC_MULT_4_5 0xC000
00705 #define VS_SC_MULT_5_0 0xE000
00706 #endif
00707
00712 #if VS_HAS_CF_DOUBLER
00713 #define VS_CF_DOUBLER 0x8000
00714 #endif
00715
00721
00731 #define VS_DECODE_TIME_REG 4
00732
00737
00743 #define VS_AUDATA_REG 5
00744
00750 #if VS_HAS_AD_STEREO_BIT0
00751 #define VS_AD_STEREO 0x0001
00752 #else
00753 #define VS_AD_STEREO 0x8000
00754 #endif
00755
00764 #if VS_HAS_AD_SAMRATE
00765 #if VS_HAS_AD_STEREO_BIT0
00766 #define VS_AD_SAMRATE 0xFFFE
00767
00768 #define VS_AD_SAMRATE_LSB 1
00769 #else
00770 #define VS_AD_SAMRATE 0x7FFF
00771 #define VS_AD_SAMRATE_LSB 0
00772 #endif
00773 #endif
00774
00777 #if VS_HAS_AD_BITRATE
00778 #define VS_AD_BITRATE 0x01FF
00779 #define VS_AD_BITRATE_LSB 0
00780 #endif
00781
00784 #if VS_HAS_AD_SAMRATE_IDX
00785 #define VS_AD_SAMRATE_IDX 0x1E00
00786 #define VS_AD_SAMRATE_IDX_LSB 9
00787
00788 #define VS_AD_SAMRATE_44100 1
00789 #define VS_AD_SAMRATE_48000 2
00790 #define VS_AD_SAMRATE_32000 3
00791 #define VS_AD_SAMRATE_22050 4
00792 #define VS_AD_SAMRATE_24000 5
00793 #define VS_AD_SAMRATE_16000 6
00794 #define VS_AD_SAMRATE_11025 7
00795 #define VS_AD_SAMRATE_12000 8
00796 #define VS_AD_SAMRATE_8000 9
00797 #endif
00798
00804
00810 #define VS_WRAM_REG 6
00811
00816
00822 #define VS_WRAMADDR_REG 7
00823
00828
00839 #if VS_HAS_HDAT0_REG
00840 #define VS_HDAT0_REG 8
00841
00842 #define VS_HDAT0_EMPHAS 0x0003
00843 #define VS_HDAT0_EMPHAS_LSB 0
00844
00845 #define VS_HDAT0_EMPHAS_NONE 0
00846 #define VS_HDAT0_EMPHAS_5015 1
00847 #define VS_HDAT0_EMPHAS_J17 3
00848
00849 #define VS_HDAT0_ORIGIN 0x0004
00850
00851 #define VS_HDAT0_COPY 0x0008
00852
00853 #define VS_HDAT0_EXT 0x0030
00854
00855 #define VS_HDAT0_MODE 0x00C0
00856 #define VS_HDAT0_MODE_LSB 6
00857
00858 #define VS_HDAT0_MODE_STEREO 0
00859 #define VS_HDAT0_MODE_JSTEREO 1
00860 #define VS_HDAT0_MODE_DUAL 2
00861 #define VS_HDAT0_MODE_MONO 3
00862
00863 #define VS_HDAT0_PRIV 0x0100
00864
00865 #define VS_HDAT0_PAD 0x0200
00866
00867 #define VS_HDAT0_SAMRATE 0x0C00
00868 #define VS_HDAT0_SAMRATE_LSB 10
00869
00870 #define VS_HDAT0_SAMRATE_11B 0
00871 #define VS_HDAT0_SAMRATE_12B 1
00872 #define VS_HDAT0_SAMRATE_8B 2
00873
00874 #define VS_HDAT0_BITRATE 0xF000
00875 #endif
00876
00881
00884 #if VS_HAS_IN0_REG
00885 #define VS_IN0_REG 8
00886 #endif
00887
00892
00898 #if VS_HAS_HDAT1_REG
00899 #define VS_HDAT1_REG 9
00900
00901 #define VS_HDAT1_PROT 0x0001
00902 #define VS_HDAT1_LAYER 0x0006
00903 #define VS_HDAT1_ID 0x0018
00904
00905 #define VS_HDAT1_SYNC 0xFFE0
00906 #define VS_HDAT1_WAV 0x7665
00907 #define VS_HDAT1_AAC_ADTS 0x4154
00908 #define VS_HDAT1_AAC_ADIF 0x4144
00909 #define VS_HDAT1_AAC_MP4 0x4D34
00910 #define VS_HDAT1_WMA 0x574D
00911 #define VS_HDAT1_MIDI 0x4D54
00912 #define VS_HDAT1_OGG 0x4F67
00913
00914 #endif
00915
00920
00923 #if VS_HAS_IN1_REG
00924 #define VS_IN1_REG 9
00925 #endif
00926
00933
00936 #define VS_AIADDR_REG 10
00937
00942
00957 #define VS_VOL_REG 11
00958
00963 #define VS_VOL_RIGHT 0x00FF
00964
00966 #define VS_VOL_RIGHT_LSB 0
00967
00972 #define VS_VOL_LEFT 0xFF00
00973
00975 #define VS_VOL_LEFT_LSB 8
00976
00977 #define VS_VOL_MAX 0x0000
00978 #define VS_VOL_MIN 0xFEFE
00979 #define VS_VOL_OFF 0xFFFF
00980
00985
00990 #if VS_HAS_MIXERVOL_REG
00991 #define VS_MIXERVOL_REG 12
00992 #define VS_SMV_GAIN1 0x001F
00993 #define VS_SMV_GAIN2 0x03E0
00994 #define VS_SMV_GAIN3 0x7C00
00995 #define VS_SMV_ACTIVE 0x8000
00996 #endif
00997
01002
01007 #if VS_HAS_ADPCMRECCTL_REG
01008 #define VS_ADPCMRECCTL_REG 13
01009 #define VS_SARC_GAIN4 0x003F
01010 #define VS_SARC_MANUALGAIN 0x0040
01011 #define VS_SARC_OUTOFADPCM 0x0080
01012 #endif
01013
01018
01024 #if VS_HAS_AICTRL0_REG
01025 #define VS_AICTRL0_REG 12
01026 #endif
01027
01032 #if VS_HAS_AICTRL_REG
01033 #define VS_AICTRL_REG 13
01034 #endif
01035
01040 #if VS_HAS_AICTRL1_REG
01041 #define VS_AICTRL1_REG 13
01042 #endif
01043
01047 #if VS_HAS_AICTRL2_REG
01048 #define VS_AICTRL2_REG 14
01049 #endif
01050
01054 #if VS_HAS_AICTRL3_REG
01055 #define VS_AICTRL3_REG 15
01056 #endif
01057
01060
01061
01062
01063 #ifndef VS_FLUSH_BYTES
01064 #define VS_FLUSH_BYTES 2048
01065 #endif
01066
01067
01068
01069
01070 #define CODEC_STATUS_IDLE 0
01071 #define CODEC_STATUS_PLAYING 1
01072
01073
01074
01075
01076 #ifdef __GNUC__
01077 typedef struct __attribute__((packed)) {
01078 uint16_t vshi_no_crc:1;
01079 uint16_t vshi_layer:2;
01080 uint16_t vshi_id:2;
01081 uint16_t vshi_syncword:11;
01082
01083 uint16_t vshi_emphasis:2;
01084 uint16_t vshi_original:1;
01085 uint16_t vshi_copyright:1;
01086 uint16_t vshi_extension:2;
01087 uint16_t vshi_mode:2;
01088 uint16_t vshi_private_bit:1;
01089 uint16_t vshi_pad_bit:1;
01090 uint16_t vshi_sample_rate:2;
01091 uint16_t vshi_bitrate:4;
01092 } VS_HEADERINFO;
01093 #endif
01094
01095 #ifndef VSCODEC_CMD_TIMEOUT
01096
01097 #define VSCODEC_CMD_TIMEOUT NUT_WAIT_INFINITE
01098 #endif
01099
01103 typedef struct _VSDCB {
01104 int dcb_pbstat;
01105 uint32_t dcb_scmd;
01106 int dcb_rvol;
01107 int dcb_lvol;
01108 uint16_t dcb_sinefreq;
01109 uint32_t dcb_pbwlo;
01110 uint32_t dcb_pbwhi;
01111 uint32_t dcb_wtmo;
01112 HANDLE dcb_bufque;
01113 HANDLE dcb_feedme;
01114 uint16_t dcb_codec_ver;
01115 char dcb_codec_rev;
01116 int (*dcb_isready)(void);
01117 int (*dcb_sendcmd)(void *, size_t);
01118 int (*dcb_senddata)(CONST uint8_t *, size_t);
01119 } VSDCB;
01120
01121 #ifndef VSCODEC_DATA_CHUNK_SIZE
01122
01123 #define VSCODEC_DATA_CHUNK_SIZE 32
01124 #endif
01125
01126 extern uint8_t zero_chunk[VSCODEC_DATA_CHUNK_SIZE];
01127
01128 extern NUTDEVICE devVsCodec;
01129 extern NUTDEVICE devSpiVsCodec0;
01130
01133 __BEGIN_DECLS
01134
01135 extern int VsCodecWaitReady(NUTDEVICE *dev, uint32_t tmo);
01136 extern uint16_t VsCodecReg(NUTDEVICE *dev, uint_fast8_t op, uint_fast8_t reg, uint_fast16_t val);
01137 extern uint16_t VsCodecMode(NUTDEVICE *dev, uint_fast16_t flags, uint_fast16_t mask);
01138 extern int VsDecoderSetVolume(NUTDEVICE *dev, int left, int right);
01139 extern uint16_t VsCodecBeep(NUTDEVICE *dev, uint16_t fsin);
01140 extern int VsDecoderBufferInit(NUTDEVICE *dev, uint32_t size);
01141 extern int VsCodecIOCtl(NUTDEVICE * dev, int req, void *conf);
01142 extern int VsCodecWrite(NUTFILE * nfp, CONST void *data, int len);
01143 NUTFILE *VsCodecOpen(NUTDEVICE * dev, CONST char *name, int mode, int acc);
01144 extern int VsCodecClose(NUTFILE * nfp);
01145
01146 #ifdef __HARVARD_ARCH__
01147 extern int VsCodecWrite_P(NUTFILE * nfp, PGM_P buffer, int len);
01148 #endif
01149
01150 extern void FeederThread(void *arg) __attribute__ ((noreturn));
01151
01152 __END_DECLS
01153
01154
01155 #endif