00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "global.h"
00023 #include "i2c.h"
00024 #include "at91sam7s64.h"
00025 #include "processor.h"
00026 #include "aic23b.h"
00027
00028
00029 signed short SinTable256_16[] = {
00030 0, 804, 1608, 2410, 3212, 4011, 4808, 5602,
00031 6393, 7179, 7962, 8739, 9512, 10278, 11039, 11793,
00032 12539, 13279, 14010, 14732, 15446, 16151, 16846, 17530,
00033 18204, 18868, 19519, 20159, 20787, 21403, 22005, 22594,
00034 23170, 23731, 24279, 24811, 25329, 25832, 26319, 26790,
00035 27245, 27683, 28105, 28510, 28898, 29268, 29621, 29956,
00036 30273, 30571, 30852, 31113, 31356, 31580, 31785, 31971,
00037 32137, 32285, 32412, 32521, 32609, 32678, 32728, 32757,
00038 32767, 32757, 32728, 32678, 32609, 32521, 32412, 32285,
00039 32137, 31971, 31785, 31580, 31356, 31113, 30852, 30571,
00040 30273, 29956, 29621, 29268, 28898, 28510, 28105, 27683,
00041 27245, 26790, 26319, 25832, 25329, 24811, 24279, 23731,
00042 23170, 22594, 22005, 21403, 20787, 20159, 19519, 18868,
00043 18204, 17530, 16846, 16151, 15446, 14732, 14010, 13279,
00044 12539, 11793, 11039, 10278, 9512, 8739, 7962, 7179,
00045 6393, 5602, 4808, 4011, 3212, 2410, 1608, 804,
00046 0, -804, -1608, -2410, -3212, -4011, -4808, -5602,
00047 -6393, -7179, -7962, -8739, -9512, -10278, -11039, -11793,
00048 -12539, -13279, -14010, -14732, -15446, -16151, -16846, -17530,
00049 -18204, -18868, -19519, -20159, -20787, -21403, -22005, -22594,
00050 -23170, -23731, -24279, -24811, -25329, -25832, -26319, -26790,
00051 -27245, -27683, -28105, -28510, -28898, -29268, -29621, -29956,
00052 -30273, -30571, -30852, -31113, -31356, -31580, -31785, -31971,
00053 -32137, -32285, -32412, -32521, -32609, -32678, -32728, -32757,
00054 -32767, -32757, -32728, -32678, -32609, -32521, -32412, -32285,
00055 -32137, -31971, -31785, -31580, -31356, -31113, -30852, -30571,
00056 -30273, -29956, -29621, -29268, -28898, -28510, -28105, -27683,
00057 -27245, -26790, -26319, -25832, -25329, -24811, -24279, -23731,
00058 -23170, -22594, -22005, -21403, -20787, -20159, -19519, -18868,
00059 -18204, -17530, -16846, -16151, -15446, -14732, -14010, -13279,
00060 -12539, -11793, -11039, -10278, -9512, -8739, -7962, -7179,
00061 -6393, -5602, -4808, -4011, -3212, -2410, -1608, -804,
00062 };
00063
00064
00065 void aicInit(void)
00066 {
00067 i2cInit();
00068
00069 aicWriteReg(AIC_REG_RESET);
00070 aicWriteReg(AIC_REG_POWERDOWN | BIT(AIC_PD_MIC));
00071 aicWriteReg(AIC_REG_ANALOG_PATH | BIT(AIC_AP_DAC));
00072 aicWriteReg(AIC_REG_DIGITAL_PATH | BIT(AIC_DP_DEEMP1));
00073
00074
00075 aicSetVolumeHp(5);
00076 }
00077
00078 int aicWriteReg(u16 regdata)
00079 {
00080 u08 packet[2];
00081 packet[0] = regdata>>8;
00082 packet[1] = regdata;
00083 if(i2cMasterSend(AIC_I2C_ADDR>>1, 2, packet) == I2C_OK)
00084 return TRUE;
00085 else
00086 return FALSE;
00087 }
00088
00089 void aicSetVolumeLineIn(u08 volume)
00090 {
00091
00092 volume = MIN(volume,31);
00093 volume &= 0x001F;
00094
00095 aicWriteReg(AIC_REG_VOL_LINEIN_LEFT |
00096 volume | BIT(AIC_VLIL_LIM) | BIT(AIC_VLIL_LRS));
00097 }
00098
00099 void aicSetVolumeHp(u08 volume)
00100 {
00101
00102 volume += 0x30;
00103
00104 volume = MIN(volume,127);
00105 volume &= 0x007F;
00106
00107 aicWriteReg(AIC_REG_VOL_HP_LEFT |
00108 volume | BIT(AIC_VHPL_LZC) | BIT(AIC_VHPL_LRS));
00109 }
00110
00111 void aicDigitalEnable(void)
00112 {
00113
00114 aicWriteReg(AIC_REG_INTERFACE_FORMAT|
00115 BIT(AIC_IF_MS)|
00116 AIC_IF_16BIT|
00117 AIC_IF_MSBL);
00118
00119
00120 aicWriteReg(AIC_REG_SAMPLE_RATE |
00121 BIT(AIC_SR_CLKIN) | BIT(AIC_SR_CLKOUT) | AIC_SR_18432_48KHZ);
00122
00123
00124 aicWriteReg(AIC_REG_DIGITAL_IF_ACT | 0x01);
00125 }