202 lines
3.7 KiB
C
202 lines
3.7 KiB
C
#include "NUC100Series.h"
|
|
|
|
#include <gpio.h>
|
|
#include <stdint.h>
|
|
|
|
#define UDA1341_ADDR 0x14
|
|
|
|
|
|
|
|
#define UDA1341_REG_DATA0 (UDA1341_ADDR + 0)
|
|
#define UDA1341_REG_DATA1 (UDA1341_ADDR + 1)
|
|
|
|
#define UDA1341_REG_STATUS (UDA1341_ADDR + 2)
|
|
|
|
|
|
#define UDA134X_EXTADDR_PREFIX 0xA0
|
|
#define UDA134X_EXTDATA_PREFIX 0xE0
|
|
#define UDA134X_EA000 0
|
|
#define UDA134X_EA001 1
|
|
#define UDA134X_EA010 2
|
|
#define UDA134X_EA011 3
|
|
#define UDA134X_EA100 4
|
|
#define UDA134X_EA101 5
|
|
#define UDA134X_EA110 6
|
|
#define UDA134X_EA111 7
|
|
|
|
|
|
/* status control *//*UDA1341???????*/
|
|
|
|
#define STAT0 (0x00) /*??8????????,0???0,1???1*/
|
|
|
|
#define STAT0_RST (1 << 6) /*set reset bit*/
|
|
|
|
#define STAT0_SC_MASK (3 << 4)
|
|
|
|
#define STAT0_SC_512FS (0 << 4) /*set system clock 512fs*/
|
|
|
|
#define STAT0_SC_384FS (1 << 4) /*set system clock 384fs*/
|
|
|
|
|
|
#define STAT0_SC_256FS (2 << 4) /*set system clock 256fs*/
|
|
|
|
#define STAT0_IF_MASK (7 << 1)
|
|
|
|
#define STAT0_IF_I2S (0 << 1) /*set the function of i2s*/
|
|
|
|
#define STAT0_IF_LSB16 (1 << 1) /*LSB-justified 16 bits*/
|
|
|
|
#define STAT0_IF_LSB18 (2 << 1) /*LSB-justified 18 bits*/
|
|
|
|
#define STAT0_IF_LSB20 (3 << 1) /*LSB-justified 20 bits*/
|
|
|
|
#define STAT0_IF_MSB (4 << 1) /*MSB-justified*/
|
|
|
|
/*LSB-justified 16 bits input and MSB-justified output*/
|
|
|
|
#define STAT0_IF_LSB16MSB (5 << 1)
|
|
|
|
/*LSB-justified 18 bits input and MSB-justified output*/
|
|
|
|
#define STAT0_IF_LSB18MSB (6 << 1)
|
|
|
|
/*LSB-justified 20 bits input and MSB-justified output*/
|
|
|
|
#define STAT0_IF_LSB20MSB (7 << 1)
|
|
|
|
|
|
#define STAT0_DC_FILTER (1 << 0)/*?DC??*/
|
|
|
|
#define STAT0_DC_NO_FILTER (0 << 0) /*??DC??*/
|
|
|
|
|
|
#define STAT1 (0x80) /*status control set model 1*/
|
|
|
|
#define STAT1_DAC_GAIN (1 << 6) /* gain of DAC */
|
|
|
|
#define STAT1_ADC_GAIN (1 << 5) /* gain of ADC */
|
|
|
|
#define STAT1_ADC_POL (1 << 4) /* polarity of ADC */
|
|
|
|
#define STAT1_DAC_POL (1 << 3) /* polarity of DAC */
|
|
|
|
#define STAT1_DBL_SPD (1 << 2) /* double speed playback */
|
|
|
|
#define STAT1_ADC_ON (1 << 1) /* ADC powered */
|
|
|
|
#define STAT1_DAC_ON (1 << 0) /* DAC powered */
|
|
|
|
|
|
|
|
/* data0 direct control */
|
|
|
|
#define DATA0 (0x00) /*model 0 volume control*/
|
|
|
|
#define DATA0_VOLUME_MASK (0x3f)
|
|
|
|
#define DATA0_VOLUME(x) (x)
|
|
|
|
|
|
#define DATA1 (0x40)
|
|
|
|
#define DATA1_BASS(x) ((x) << 2)
|
|
|
|
#define DATA1_BASS_MASK (15 << 2)
|
|
|
|
#define DATA1_TREBLE(x) ((x))
|
|
|
|
#define DATA1_TREBLE_MASK (3)
|
|
|
|
|
|
#define DATA2 (0x80)
|
|
|
|
#define DATA2_PEAKAFTER (0x1 << 5)
|
|
|
|
#define DATA2_DEEMP_NONE (0x0 << 3)
|
|
|
|
#define DATA2_DEEMP_32KHz (0x1 << 3)
|
|
|
|
#define DATA2_DEEMP_44KHz (0x2 << 3)
|
|
|
|
#define DATA2_DEEMP_48KHz (0x3 << 3)
|
|
|
|
#define DATA2_MUTE (0x1 << 2)
|
|
|
|
#define DATA2_FILTER_FLAT (0x0 << 0)
|
|
|
|
#define DATA2_FILTER_MIN (0x1 << 0)
|
|
|
|
#define DATA2_FILTER_MAX (0x3 << 0)
|
|
|
|
/* data0 extend control */
|
|
|
|
#define EXTADDR(n) (0xc0 | (n))
|
|
|
|
#define EXTDATA(d) (0xe0 | (d))
|
|
|
|
|
|
|
|
#define EXT0 0
|
|
|
|
#define EXT0_CH1_GAIN(x) (x)
|
|
|
|
#define EXT1 1
|
|
|
|
#define EXT1_CH2_GAIN(x) (x)
|
|
|
|
#define EXT2 2
|
|
|
|
#define EXT2_MIC_GAIN_MASK (7 << 2)
|
|
|
|
#define EXT2_MIC_GAIN(x) ((x) << 2)
|
|
|
|
#define EXT2_MIXMODE_DOUBLEDIFF (0)
|
|
|
|
#define EXT2_MIXMODE_CH1 (1)
|
|
|
|
#define EXT2_MIXMODE_CH2 (2)
|
|
|
|
#define EXT2_MIXMODE_MIX (3)
|
|
|
|
#define EXT4 4
|
|
|
|
#define EXT4_AGC_ENABLE (1 << 4)
|
|
|
|
#define EXT4_INPUT_GAIN_MASK (3)
|
|
|
|
#define EXT4_INPUT_GAIN(x) ((x) & 3)
|
|
|
|
#define EXT5 5
|
|
|
|
#define EXT5_INPUT_GAIN(x) ((x) >> 2)
|
|
|
|
#define EXT6 6
|
|
|
|
#define EXT6_AGC_CONSTANT_MASK (7 << 2)
|
|
|
|
#define EXT6_AGC_CONSTANT(x) ((x) << 2)
|
|
|
|
#define EXT6_AGC_LEVEL_MASK (3)
|
|
|
|
#define EXT6_AGC_LEVEL(x) (x)
|
|
|
|
|
|
#define AUDIO_FMT_MASK (AFMT_S16_LE)
|
|
|
|
#define AUDIO_FMT_DEFAULT (AFMT_S16_LE)
|
|
|
|
|
|
|
|
#define AUDIO_CHANNELS_DEFAULT 2
|
|
|
|
#define AUDIO_RATE_DEFAULT 44100
|
|
|
|
|
|
|
|
#define AUDIO_NBFRAGS_DEFAULT 8
|
|
|
|
#define AUDIO_FRAGSIZE_DEFAULT 8192
|
|
|
|
int read_data(int8_t addr);
|
|
|
|
int set_data(int8_t addr,int8_t data); |