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_VS1011E)
00070 #include <dev/vs1011.h>
00071 #elif defined(AUDIO0_VS1053B)
00072 #include <dev/vs1053.h>
00073 #elif !defined(AUDIO0_VSAUTO)
00074 #define AUDIO0_VSAUTO
00075 #endif
00076
00086
00087
00088 #ifndef AUDIO0_DAC_MIN_GAIN
00089 #define AUDIO0_DAC_MIN_GAIN -127
00090 #endif
00091 #ifndef AUDIO0_DAC_MAX_GAIN
00092 #define AUDIO0_DAC_MAX_GAIN 0
00093 #endif
00094
00095
00096 #ifndef AUDIO_DAC_MIN_GAIN
00097 #define AUDIO_DAC_MIN_GAIN AUDIO0_DAC_MIN_GAIN
00098 #endif
00099 #ifndef AUDIO_DAC_MAX_GAIN
00100 #define AUDIO_DAC_MAX_GAIN AUDIO0_DAC_MAX_GAIN
00101 #endif
00102
00103
00104
00105
00106
00107 #define AUDIO_SETWRITETIMEOUT 0x010d
00108 #define AUDIO_GETWRITETIMEOUT 0x010e
00109
00111 #define AUDIO_PLAY 0x3001
00112
00113 #define AUDIO_CANCEL 0x3002
00114 #define AUDIO_GET_STATUS 0x3003
00115 #define AUDIO_GET_PLAYGAIN 0x3004
00116 #define AUDIO_SET_PLAYGAIN 0x3005
00117 #define AUDIO_GET_PBSIZE 0x3006
00118 #define AUDIO_SET_PBSIZE 0x3007
00119 #define AUDIO_GET_PBLEVEL 0x3008
00120 #define AUDIO_GET_PBWLOW 0x3009
00121 #define AUDIO_SET_PBWLOW 0x300A
00122 #define AUDIO_GET_PBWHIGH 0x300B
00123 #define AUDIO_SET_PBWHIGH 0x300C
00124 #define AUDIO_BEEP 0x300F
00125
00126 #define AUDIO_GET_DECINFO 0x3010
00127
00128 #define AUDIO_GET_DECCAPS 0x3011
00129
00130 #define AUDIO_GET_DECFMTS 0x3012
00131
00132 #define AUDIO_SET_DECFMTS 0x3013
00133
00134 #define AUDIO_GET_CODINFO 0x3014
00135
00136 #define AUDIO_GET_CODCAPS 0x3015
00137
00138 #define AUDIO_GET_CODFMTS 0x3016
00139
00140 #define AUDIO_SET_CODFMTS 0x3017
00141
00142 #define AUDIO_GET_MIDINFO 0x3018
00143
00144 #define AUDIO_GET_MIDCAPS 0x3019
00145
00146
00147
00148
00149
00150 #define VS_OPCODE_READ 3
00151 #define VS_OPCODE_WRITE 2
00152
00153
00157
00160 #define VS_MODE_REG 0
00161
00162 #define VS_SM_DIFF 0x0001
00163
00172 #if VS_HAS_SM_LAYER12
00173 #define VS_SM_LAYER12 0x0002
00174 #endif
00175
00187 #if VS_HAS_SM_FFWD
00188 #define VS_SM_FFWD 0x0002
00189 #endif
00190
00195 #define VS_SM_RESET 0x0004
00196
00197
00209 #if VS_HAS_SM_MP12
00210 #define VS_SM_MP12 0x0008
00211 #endif
00212
00221 #if VS_HAS_SM_OUTOFWAV
00222 #define VS_SM_OUTOFWAV 0x0008
00223 #endif
00224
00234 #if VS_HAS_SM_CANCEL
00235 #define VS_SM_CANCEL 0x0008
00236 #endif
00237
00249 #if VS_HAS_SM_PDOWN
00250 #define VS_SM_PDOWN 0x0010
00251 #endif
00252
00255 #if VS_HAS_SM_EARSPEAKER
00256 #define VS_SM_EARSPEAKER_LO 0x0010
00257 #define VS_SM_SPATIAL_OFF 0
00258 #define VS_SM_SPATIAL_MINIMAL VS_SM_EARSPEAKER_LO
00259 #define VS_SM_SPATIAL_NORMAL VS_SM_EARSPEAKER_HI
00260 #define VS_SM_SPATIAL_EXTREME (VS_SM_EARSPEAKER_LO | VS_SM_EARSPEAKER_LO)
00261 #endif
00262
00273 #if VS_HAS_SM_DAC
00274 #define VS_SM_DAC 0x0020
00275 #endif
00276
00281 #if VS_HAS_SM_TESTS
00282 #define VS_SM_TESTS 0x0020
00283 #endif
00284
00295 #if VS_HAS_SM_DACMONO
00296 #define VS_SM_DACMONO 0x0040
00297 #endif
00298
00310 #if VS_HAS_SM_STREAM
00311 #define VS_SM_STREAM 0x0040
00312 #endif
00313
00318 #if VS_HAS_SM_BASS
00319 #define VS_SM_BASS 0x0080
00320 #endif
00321
00322 #if VS_HAS_SM_EARSPEAKER
00323 #define VS_SM_EARSPEAKER_HI 0x0080
00324 #endif
00325
00331 #define VS_SM_DACT 0x0100
00332
00338 #define VS_SM_BITORD 0x0200
00339
00344 #define VS_SM_SDIORD 0x0200
00345
00353 #if VS_HAS_SM_IBMODE
00354 #define VS_SM_IBMODE 0x0400
00355 #endif
00356
00358 #if VS_HAS_SM_SDISHARE
00359 #define VS_SM_SDISHARE 0x0400
00360 #endif
00361
00369 #if VS_HAS_SM_IBCLK
00370 #define VS_SM_IBCLK 0x0800
00371 #endif
00372
00379 #if VS_HAS_SM_SDINEW
00380 #define VS_SM_SDINEW 0x0800
00381 #endif
00382
00387 #if VS_HAS_SM_ADPCM
00388 #define VS_SM_ADPCM 0x1000
00389 #endif
00390
00399 #if VS_HAS_SM_ADPCM_HP
00400 #define VS_SM_ADPCM_HP 0x2000
00401 #endif
00402
00410 #if VS_HAS_SM_LINE_IN
00411 #define VS_SM_LINE_IN 0x4000
00412 #endif
00413
00421 #if VS_HAS_SM_CLK_RANGE
00422 #define VS_SM_CLK_RANGE 0x8000
00423 #endif
00424
00430
00433 #define VS_STATUS_REG 1
00434
00443 #if VS_HAS_SS_AVOL
00444 #define VS_SS_AVOL 0x0003
00445
00446 #define VS_SS_AVOL_LSB 0
00447 #endif
00448
00457 #if VS_HAS_SS_VREF_1_65
00458 #define VS_SS_VREF_1_65 0x0001
00459 #endif
00460
00477 #if VS_HAS_SS_AD_CLOCK
00478 #define VS_SS_AD_CLOCK 0x0002
00479 #endif
00480
00485 #define VS_SS_APDOWM1 0x0004
00486
00497 #define VS_SS_APDOWN2 0x0008
00498
00509 #define VS_SS_VER 0x00F0
00510
00511 #define VS_SS_VER_LSB 4
00512
00513 #define VS1001_SS_VER 0
00514 #define VS1011_SS_VER 1
00515 #define VS1011E_SS_VER 2
00516 #define VS1002_SS_VER 2
00517 #define VS1003_SS_VER 3
00518 #define VS1053_SS_VER 4
00519 #define VS1033_SS_VER 5
00520 #define VS1103_SS_VER 7
00521
00528 #if VS_HAS_SS_VCM_DISABLE
00529 #define VS_SS_VCM_DISABLE 0x0400
00530 #endif
00531
00536 #if VS_HAS_SS_VCM_OVERLOAD
00537 #define VS_SS_VCM_OVERLOAD 0x0800
00538 #endif
00539
00549 #if VS_HAS_SS_SWING
00550 #define VS_SS_SWING 0x7000
00551 #define VS_SS_SWING_LSB 12
00552 #define VS_SS_SWING_NORMAL 0
00553 #define VS_SS_SWING_MAX 2
00554 #endif
00555
00561 #if VS_HAS_SS_DO_NOT_JUMP
00562 #define VS_SS_DO_NOT_JUMP 0x8000
00563 #endif
00564
00570
00576 #if VS_HAS_INT_FCTLH_REG
00577 #define VS_INT_FCTLH_REG 2
00578 #endif
00579
00585
00594 #if VS_HAS_BASS_REG
00595 #define VS_BASS_REG 2
00596
00606 #define VS_SB_FREQLIMIT 0x000F
00607
00608 #define VS_SB_FREQLIMIT_LSB 0
00609
00614 #define VS_SB_AMPLITUDE 0x00F0
00615
00616 #define VS_SB_AMPLITUDE_LSB 4
00617
00622 #define VS_ST_FREQLIMIT 0x0F00
00623
00624 #define VS_ST_FREQLIMIT_LSB 8
00625
00630 #define VS_ST_AMPLITUDE 0xF000
00631
00632 #define VS_ST_AMPLITUDE_LSB 12
00633 #endif
00634
00639
00642 #define VS_CLOCKF_REG 3
00643
00654 #if VS_HAS_SC_FREQ
00655 #define VS_SC_FREQ 0x7FFF
00656
00657 #define VS_SC_FREQ_LSB 0
00658 #endif
00659
00667 #if VS_HAS_SC_X3FREQ
00668 #define VS_SC_X3FREQ 0x07FF
00669 #endif
00670
00677 #if VS_HAS_SC_ADD
00678 #define VS_SC_ADD 0x1800
00679 #define VS_SC_ADD_NONE 0x0000
00680 #define VS_SC_ADD_1_0 0x0800
00681 #define VS_SC_ADD_1_5 0x1000
00682 #define VS_SC_ADD_2_0 0x1800
00683 #endif
00684
00690 #if VS_HAS_SC_MULT
00691 #define VS_SC_MULT 0xE000
00692 #define VS_SC_MULT_1_0 0x0000
00693 #define VS_SC_MULT_2_0 0x2000
00694 #define VS_SC_MULT_2_5 0x4000
00695 #define VS_SC_MULT_3_0 0x6000
00696 #define VS_SC_MULT_3_5 0x8000
00697 #define VS_SC_MULT_4_0 0xA000
00698 #define VS_SC_MULT_4_5 0xC000
00699 #define VS_SC_MULT_5_0 0xE000
00700 #endif
00701
00706 #if VS_HAS_CF_DOUBLER
00707 #define VS_CF_DOUBLER 0x8000
00708 #endif
00709
00715
00725 #define VS_DECODE_TIME_REG 4
00726
00731
00737 #define VS_AUDATA_REG 5
00738
00744 #if VS_HAS_AD_STEREO_BIT0
00745 #define VS_AD_STEREO 0x0001
00746 #else
00747 #define VS_AD_STEREO 0x8000
00748 #endif
00749
00758 #if VS_HAS_AD_SAMRATE
00759 #if VS_HAS_AD_STEREO_BIT0
00760 #define VS_AD_SAMRATE 0xFFFE
00761
00762 #define VS_AD_SAMRATE_LSB 1
00763 #else
00764 #define VS_AD_SAMRATE 0x7FFF
00765 #define VS_AD_SAMRATE_LSB 0
00766 #endif
00767 #endif
00768
00771 #if VS_HAS_AD_BITRATE
00772 #define VS_AD_BITRATE 0x01FF
00773 #define VS_AD_BITRATE_LSB 0
00774 #endif
00775
00778 #if VS_HAS_AD_SAMRATE_IDX
00779 #define VS_AD_SAMRATE_IDX 0x1E00
00780 #define VS_AD_SAMRATE_IDX_LSB 9
00781
00782 #define VS_AD_SAMRATE_44100 1
00783 #define VS_AD_SAMRATE_48000 2
00784 #define VS_AD_SAMRATE_32000 3
00785 #define VS_AD_SAMRATE_22050 4
00786 #define VS_AD_SAMRATE_24000 5
00787 #define VS_AD_SAMRATE_16000 6
00788 #define VS_AD_SAMRATE_11025 7
00789 #define VS_AD_SAMRATE_12000 8
00790 #define VS_AD_SAMRATE_8000 9
00791 #endif
00792
00798
00804 #define VS_WRAM_REG 6
00805
00810
00816 #define VS_WRAMADDR_REG 7
00817
00822
00833 #if VS_HAS_HDAT0_REG
00834 #define VS_HDAT0_REG 8
00835
00836 #define VS_HDAT0_EMPHAS 0x0003
00837 #define VS_HDAT0_EMPHAS_LSB 0
00838
00839 #define VS_HDAT0_EMPHAS_NONE 0
00840 #define VS_HDAT0_EMPHAS_5015 1
00841 #define VS_HDAT0_EMPHAS_J17 3
00842
00843 #define VS_HDAT0_ORIGIN 0x0004
00844
00845 #define VS_HDAT0_COPY 0x0008
00846
00847 #define VS_HDAT0_EXT 0x0030
00848
00849 #define VS_HDAT0_MODE 0x00C0
00850 #define VS_HDAT0_MODE_LSB 6
00851
00852 #define VS_HDAT0_MODE_STEREO 0
00853 #define VS_HDAT0_MODE_JSTEREO 1
00854 #define VS_HDAT0_MODE_DUAL 2
00855 #define VS_HDAT0_MODE_MONO 3
00856
00857 #define VS_HDAT0_PRIV 0x0100
00858
00859 #define VS_HDAT0_PAD 0x0200
00860
00861 #define VS_HDAT0_SAMRATE 0x0C00
00862 #define VS_HDAT0_SAMRATE_LSB 10
00863
00864 #define VS_HDAT0_SAMRATE_11B 0
00865 #define VS_HDAT0_SAMRATE_12B 1
00866 #define VS_HDAT0_SAMRATE_8B 2
00867
00868 #define VS_HDAT0_BITRATE 0xF000
00869 #endif
00870
00875
00878 #if VS_HAS_IN0_REG
00879 #define VS_IN0_REG 8
00880 #endif
00881
00886
00892 #if VS_HAS_HDAT1_REG
00893 #define VS_HDAT1_REG 9
00894
00895 #define VS_HDAT1_PROT 0x0001
00896 #define VS_HDAT1_LAYER 0x0006
00897 #define VS_HDAT1_ID 0x0018
00898
00899 #define VS_HDAT1_SYNC 0xFFE0
00900 #define VS_HDAT1_WAV 0x7665
00901 #define VS_HDAT1_AAC_ADTS 0x4154
00902 #define VS_HDAT1_AAC_ADIF 0x4144
00903 #define VS_HDAT1_AAC_MP4 0x4D34
00904 #define VS_HDAT1_WMA 0x574D
00905 #define VS_HDAT1_MIDI 0x4D54
00906 #define VS_HDAT1_OGG 0x4F67
00907
00908 #endif
00909
00914
00917 #if VS_HAS_IN1_REG
00918 #define VS_IN1_REG 9
00919 #endif
00920
00927
00930 #define VS_AIADDR_REG 10
00931
00936
00951 #define VS_VOL_REG 11
00952
00957 #define VS_VOL_RIGHT 0x00FF
00958
00960 #define VS_VOL_RIGHT_LSB 0
00961
00966 #define VS_VOL_LEFT 0xFF00
00967
00969 #define VS_VOL_LEFT_LSB 8
00970
00971 #define VS_VOL_MAX 0x0000
00972 #define VS_VOL_MIN 0xFEFE
00973 #define VS_VOL_OFF 0xFFFF
00974
00979
00984 #if VS_HAS_MIXERVOL_REG
00985 #define VS_MIXERVOL_REG 12
00986 #define VS_SMV_GAIN1 0x001F
00987 #define VS_SMV_GAIN2 0x03E0
00988 #define VS_SMV_GAIN3 0x7C00
00989 #define VS_SMV_ACTIVE 0x8000
00990 #endif
00991
00996
01001 #if VS_HAS_ADPCMRECCTL_REG
01002 #define VS_ADPCMRECCTL_REG 13
01003 #define VS_SARC_GAIN4 0x003F
01004 #define VS_SARC_MANUALGAIN 0x0040
01005 #define VS_SARC_OUTOFADPCM 0x0080
01006 #endif
01007
01012
01018 #if VS_HAS_AICTRL0_REG
01019 #define VS_AICTRL0_REG 12
01020 #endif
01021
01026 #if VS_HAS_AICTRL_REG
01027 #define VS_AICTRL_REG 13
01028 #endif
01029
01034 #if VS_HAS_AICTRL1_REG
01035 #define VS_AICTRL1_REG 13
01036 #endif
01037
01041 #if VS_HAS_AICTRL2_REG
01042 #define VS_AICTRL2_REG 14
01043 #endif
01044
01048 #if VS_HAS_AICTRL3_REG
01049 #define VS_AICTRL3_REG 15
01050 #endif
01051
01054
01055
01056
01057 #ifndef VS_FLUSH_BYTES
01058 #define VS_FLUSH_BYTES 2048
01059 #endif
01060
01061
01062
01063
01064 #define CODEC_STATUS_IDLE 0
01065 #define CODEC_STATUS_PLAYING 1
01066
01067
01068
01069
01070 #ifdef __GNUC__
01071 typedef struct __attribute__((packed)) {
01072 uint16_t vshi_no_crc:1;
01073 uint16_t vshi_layer:2;
01074 uint16_t vshi_id:2;
01075 uint16_t vshi_syncword:11;
01076
01077 uint16_t vshi_emphasis:2;
01078 uint16_t vshi_original:1;
01079 uint16_t vshi_copyright:1;
01080 uint16_t vshi_extension:2;
01081 uint16_t vshi_mode:2;
01082 uint16_t vshi_private_bit:1;
01083 uint16_t vshi_pad_bit:1;
01084 uint16_t vshi_sample_rate:2;
01085 uint16_t vshi_bitrate:4;
01086 } VS_HEADERINFO;
01087 #endif
01088
01089 #ifndef VSCODEC_CMD_TIMEOUT
01090
01091 #define VSCODEC_CMD_TIMEOUT NUT_WAIT_INFINITE
01092 #endif
01093
01097 typedef struct _VSDCB {
01098 int dcb_pbstat;
01099 uint32_t dcb_scmd;
01100 int dcb_rvol;
01101 int dcb_lvol;
01102 uint16_t dcb_sinefreq;
01103 uint32_t dcb_pbwlo;
01104 uint32_t dcb_pbwhi;
01105 uint32_t dcb_wtmo;
01106 HANDLE dcb_bufque;
01107 HANDLE dcb_feedme;
01108 uint16_t dcb_codec_ver;
01109 char dcb_codec_rev;
01110 int (*dcb_isready)(void);
01111 int (*dcb_sendcmd)(void *, size_t);
01112 int (*dcb_senddata)(CONST uint8_t *, size_t);
01113 } VSDCB;
01114
01115 #ifndef VSCODEC_DATA_CHUNK_SIZE
01116
01117 #define VSCODEC_DATA_CHUNK_SIZE 32
01118 #endif
01119
01120 extern uint8_t zero_chunk[VSCODEC_DATA_CHUNK_SIZE];
01121
01122 extern NUTDEVICE devVsCodec;
01123 extern NUTDEVICE devSpiVsCodec0;
01124
01127 __BEGIN_DECLS
01128
01129 extern int VsCodecWaitReady(NUTDEVICE *dev, uint32_t tmo);
01130 extern uint16_t VsCodecReg(NUTDEVICE *dev, uint_fast8_t op, uint_fast8_t reg, uint_fast16_t val);
01131 extern uint16_t VsCodecMode(NUTDEVICE *dev, uint_fast16_t flags, uint_fast16_t mask);
01132 extern int VsDecoderSetVolume(NUTDEVICE *dev, int left, int right);
01133 extern uint16_t VsCodecBeep(NUTDEVICE *dev, uint16_t fsin);
01134 extern int VsDecoderBufferInit(NUTDEVICE *dev, uint32_t size);
01135 extern int VsCodecIOCtl(NUTDEVICE * dev, int req, void *conf);
01136 extern int VsCodecWrite(NUTFILE * nfp, CONST void *data, int len);
01137 NUTFILE *VsCodecOpen(NUTDEVICE * dev, CONST char *name, int mode, int acc);
01138 extern int VsCodecClose(NUTFILE * nfp);
01139
01140 #ifdef __HARVARD_ARCH__
01141 extern int VsCodecWrite_P(NUTFILE * nfp, PGM_P buffer, int len);
01142 #endif
01143
01144 extern void FeederThread(void *arg) __attribute__ ((noreturn));
01145
01146 __END_DECLS
01147
01148
01149 #endif