Mercurial > hg > beaglert
diff core/I2c_Codec.cpp @ 108:3068421c0737 ultra-staging
Merged default into ultra-staging
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Tue, 18 Aug 2015 00:35:15 +0100 |
parents | c44fa102d02b |
children | e24c531220ee |
line wrap: on
line diff
--- a/core/I2c_Codec.cpp Mon Jun 08 01:07:48 2015 +0100 +++ b/core/I2c_Codec.cpp Tue Aug 18 00:35:15 2015 +0100 @@ -117,6 +117,44 @@ return 0; } +//set the numerator multiplier for the PLL +int I2c_Codec::setPllK(float k){ + short unsigned int j=(int)k; + unsigned int d=(k-j+0.5)*10000; //fractionary part, between 0 and 9999 + if(setPllJ(j)>0) + return 1; + if(setPllD(d)>0) + return 2; + return 0; +} + + +//set integer part of the numerator mutliplier of the PLL +int I2c_Codec::setPllJ(short unsigned int j){ + if(j>=64 || j<1){ + return 1; + } + if(writeRegister(0x04, j<<2)){ // PLL register B: j<<2 + printf("I2C error while writing PLL j: %d", j); + return 1; + } + return 0; +} + +//set fractional part(between 0 and 9999) of the numerator mutliplier of the PLL +int I2c_Codec::setPllD(unsigned int d){ + if(d<0 || d>9999) + return 1; + if(writeRegister(0x05, (d>>6)&255)){ // PLL register C: part 1 : 8 most significant bytes of a 14bit integer + printf("I2C error while writing PLL d part 1 : %d", d); + return 1; + } + if(writeRegister(0x06, (d<<2)&255)){ // PLL register D: D=5264, part 2 + printf("I2C error while writing PLL d part 2 : %d", d); + return 1; + } + return 0; +} // Set the volume of the DAC output int I2c_Codec::setDACVolume(int halfDbSteps) {