# HG changeset patch # User Giulio Moro # Date 1437615431 -3600 # Node ID c44fa102d02b20bb94d64a14b87fc326d34b4d94 # Parent ef9392d077a47b194d8ad7d4fbfa5d2e8d987e58 Added methods to I2c_Codec to interact with the PLL diff -r ef9392d077a4 -r c44fa102d02b core/I2c_Codec.cpp --- a/core/I2c_Codec.cpp Thu Jul 23 02:36:49 2015 +0100 +++ b/core/I2c_Codec.cpp Thu Jul 23 02:37:11 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) {