Mercurial > hg > beaglert
comparison core/I2c_Codec.cpp @ 169:94751ad27fd6
Added method to set PGA per each channel
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Mon, 28 Dec 2015 03:17:22 +0100 |
parents | 8ff5668bbbad |
children | e63563507edd |
comparison
equal
deleted
inserted
replaced
159:1e7db6610600 | 169:94751ad27fd6 |
---|---|
88 return 1; | 88 return 1; |
89 if(writeRegister(0x0D, 0x00)) // Headset / button press register A: disabled | 89 if(writeRegister(0x0D, 0x00)) // Headset / button press register A: disabled |
90 return 1; | 90 return 1; |
91 if(writeRegister(0x0E, 0x00)) // Headset / button press register B: disabled | 91 if(writeRegister(0x0E, 0x00)) // Headset / button press register B: disabled |
92 return 1; | 92 return 1; |
93 if(writeRegister(0x0F, 0x20)) // Left ADC PGA gain control: not muted; 0x20 = 16dB | 93 if(setPga(16, 0)) // Left ADC PGA gain control: not muted; 16dB |
94 return 1; | 94 return 1; |
95 if(writeRegister(0x10, 0x20)) // Right ADC PGA gain control: not muted; 0x20 = 16dB | 95 if(setPga(16, 1)) // Right ADC PGA gain control: not muted; 16dB |
96 return 1; | 96 return 1; |
97 | 97 // if(writeRegister(0x0F, 0b01000000)) // Left ADC PGA gain control: not muted; 0x20 = 16dB |
98 // return 1; | |
99 // if(writeRegister(0x10, 0b0)) // Right ADC PGA gain control: not muted; 0x20 = 16dB | |
100 // return 1; | |
98 if(writeRegister(0x25, 0xC0)) // DAC power/driver register: DAC power on (left and right) | 101 if(writeRegister(0x25, 0xC0)) // DAC power/driver register: DAC power on (left and right) |
99 return 1; | 102 return 1; |
100 if(writeRegister(0x26, 0x04)) // High power output driver register: Enable short circuit protection | 103 if(writeRegister(0x26, 0x04)) // High power output driver register: Enable short circuit protection |
101 return 1; | 104 return 1; |
102 if(writeRegister(0x28, 0x02)) // High power output stage register: disable soft stepping | 105 if(writeRegister(0x28, 0x02)) // High power output stage register: disable soft stepping |
218 // f_{S(ref)} = (PLLCLK_IN × K × R)/(2048 × P) | 221 // f_{S(ref)} = (PLLCLK_IN × K × R)/(2048 × P) |
219 float k = ((double)(newSamplingRate * pllP * 2048.0f/(float)pllR)) / PLLCLK_IN ; | 222 float k = ((double)(newSamplingRate * pllP * 2048.0f/(float)pllR)) / PLLCLK_IN ; |
220 return (setPllK(k)); | 223 return (setPllK(k)); |
221 } | 224 } |
222 | 225 |
226 | |
223 short unsigned int I2c_Codec::getPllJ(){ | 227 short unsigned int I2c_Codec::getPllJ(){ |
224 return pllJ; | 228 return pllJ; |
225 } | 229 } |
226 unsigned int I2c_Codec::getPllD(){ | 230 unsigned int I2c_Codec::getPllD(){ |
227 return pllD; | 231 return pllD; |
245 long int PLLCLK_IN=12000000; | 249 long int PLLCLK_IN=12000000; |
246 // f_{S(ref)} = (PLLCLK_IN × K × R)/(2048 × P) | 250 // f_{S(ref)} = (PLLCLK_IN × K × R)/(2048 × P) |
247 float fs = (PLLCLK_IN/2048.0f) * getPllK()*pllR/(float)pllP; | 251 float fs = (PLLCLK_IN/2048.0f) * getPllK()*pllR/(float)pllP; |
248 return fs; | 252 return fs; |
249 } | 253 } |
254 | |
255 int I2c_Codec::setPga(float newGain, unsigned short int channel){ | |
256 unsigned short int reg; | |
257 if(channel == 0) | |
258 reg = 0x0F; | |
259 else if(channel == 1) | |
260 reg = 0x10; | |
261 else | |
262 return 1; // error, wrong channel | |
263 if(newGain > 59.5) | |
264 return 2; // error, gain out of range | |
265 unsigned short int value; | |
266 if(newGain < 0) | |
267 value = 0b10000000; // PGA is muted | |
268 else { | |
269 // gain is adjustable from 0 to 59.5dB in steps of 0.5dB between 0x0 and 0x7f. | |
270 // Values between 0b01110111 and 0b01111111 are clipped to 59.5dB | |
271 value = (int)(newGain * 2 + 0.5) & 0x7f; | |
272 } | |
273 printf("channel: %d, gain: %f, value: 0x%x, reg: 0x%x\n", channel, newGain, value, reg); | |
274 int ret = writeRegister(reg, value); | |
275 printf("ret: %d\n", ret); | |
276 return ret; | |
277 } | |
278 | |
250 // Set the volume of the DAC output | 279 // Set the volume of the DAC output |
251 int I2c_Codec::setDACVolume(int halfDbSteps) | 280 int I2c_Codec::setDACVolume(int halfDbSteps) |
252 { | 281 { |
253 dacVolumeHalfDbs = halfDbSteps; | 282 dacVolumeHalfDbs = halfDbSteps; |
254 if(running) | 283 if(running) |
255 return writeDACVolumeRegisters(false); | 284 return writeDACVolumeRegisters(false); |
256 | 285 |
257 return 0; | 286 return 0; |
258 } | 287 } |
259 | 288 |
260 // Set the volume of the DAC output | 289 // Set the volume of the ADC input |
261 int I2c_Codec::setADCVolume(int halfDbSteps) | 290 int I2c_Codec::setADCVolume(int halfDbSteps) |
262 { | 291 { |
263 adcVolumeHalfDbs = halfDbSteps; | 292 adcVolumeHalfDbs = halfDbSteps; |
264 if(running) | 293 if(running) |
265 return writeADCVolumeRegisters(false); | 294 return writeADCVolumeRegisters(false); |