Browse Source

Added more control functions

dds
MickMad 9 years ago
parent
commit
8d6deefaa2
2 changed files with 56 additions and 20 deletions
  1. +42
    -9
      control_ak4558.cpp
  2. +14
    -11
      control_ak4558.h

+ 42
- 9
control_ak4558.cpp View File

// registers[AK4558_CTRL_1] |= AK4558_DIF1 | AK4558_DIF0; // registers[AK4558_CTRL_1] |= AK4558_DIF1 | AK4558_DIF0;
// //
// after manipulation, we can write the entire register value on the CODEC // after manipulation, we can write the entire register value on the CODEC
unsigned int n = 0;
unit8_t n = 0;
Wire.requestFrom(AK4558_I2C_ADDR,10); Wire.requestFrom(AK4558_I2C_ADDR,10);
while(Wire.available()) { while(Wire.available()) {
#if AK4558_SERIAL_DEBUG > 0 #if AK4558_SERIAL_DEBUG > 0
void AudioControlAK4558::readConfig(void) void AudioControlAK4558::readConfig(void)
{ {
// reads registers values // reads registers values
unsigned int n = 0;
char c = 0;
unit8_t n = 0;
unit8_t c = 0;
Wire.requestFrom(AK4558_I2C_ADDR, 10); Wire.requestFrom(AK4558_I2C_ADDR, 10);
while(Wire.available()) { while(Wire.available()) {
Serial.print("Register "); Serial.print("Register ");
#if AK4558_SERIAL_DEBUG > 0 #if AK4558_SERIAL_DEBUG > 0
Serial.println("AK4558: Enable device - Done"); Serial.println("AK4558: Enable device - Done");
#endif #endif
write(AK4558_ROUT_VOL,255); //dummy write to last register to reset address counter to 0
return true; return true;
} }


return true; return true;
} }


bool AudioControlAK4558:volume(float n)
unsigned char AudioControlAK4558::convertVolume(float vol)
{
// Convert float (range 0.0-1.0) to unsigned char (range 0x00-0xFF)
uint8_t temp = vol>>22;
return temp;
}

bool AudioControlAK4558::volume(float n)
{ {
// Set DAC output volume // Set DAC output volume
registers[AK4558_LOUT_VOL] = 255;
registers[AK4558_ROUT_VOL] = 255;
unit8_t vol = convertVolume(n);
registers[AK4558_LOUT_VOL] = vol;
registers[AK4558_ROUT_VOL] = vol;
Wire.beginTransmission(AK4558_I2C_ADDR); Wire.beginTransmission(AK4558_I2C_ADDR);
Wire.write(AK4558_LOUT_VOL); Wire.write(AK4558_LOUT_VOL);
Wire.write(registers[AK4558_LOUT_VOL]); Wire.write(registers[AK4558_LOUT_VOL]);
Wire.write(registers[AK4558_ROUT_VOL]); Wire.write(registers[AK4558_ROUT_VOL]);
Wire.endTransmission();
#if AK4558_SERIAL_DEBUG > 0 #if AK4558_SERIAL_DEBUG > 0
Serial.print("AK4558: LOUT_VOL set to "); Serial.print("AK4558: LOUT_VOL set to ");
Serial.println(registers[AK4558_LOUT_VOL], BIN); Serial.println(registers[AK4558_LOUT_VOL], BIN);
Serial.print("AK4558: ROUT_VOL set to ");
Serial.println(registers[AK4558_ROUT_VOL], BIN);
#endif #endif
return (Wire.endTransmission(true)==0); return (Wire.endTransmission(true)==0);
}

bool AudioControlAK4558:::volumeLeft(float n)
{
// Set DAC left output volume
unit8_t vol = convertVolume(n);
registers[AK4558_LOUT_VOL] = vol;
bool ret = write(AK4558_LOUT_VOL, registers[AK4558_LOUT_VOL]);
#if AK4558_SERIAL_DEBUG > 0
Serial.print("AK4558: LOUT_VOL set to ");
Serial.println(registers[AK4558_LOUT_VOL], BIN);
#endif
return ret;
}

bool AudioControlAK4558::volumeRight(float n)
{
// Set DAC right output volume
unit8_t vol = convertVolume(n);
registers[AK4558_ROUT_VOL] = vol;
write(AK4558_EOUT_VOL, registers[AK4558_ROUT_VOL]);
#if AK4558_SERIAL_DEBUG > 0
Serial.print("AK4558: ROUT_VOL set to ");
Serial.println(registers[AK4558_ROUT_VOL], BIN);
#endif
return ret;
} }

+ 14
- 11
control_ak4558.h View File

class AudioControlAK4558 : public AudioControl class AudioControlAK4558 : public AudioControl
{ {
public: public:
bool enable(void); //enables the CODEC, does not power up ADC nor DAC (use enableIn() and enableOut() for selective power up)
bool enableIn(void);
bool enableOut(void);
bool disable(void) { return (disableIn()&&disableOut()); }
bool disableIn(void);
bool disableOut(void);
bool volume(float n);
bool inputLevel(float n) { return false; }
bool inputSelect(int n) { return false; }
protected:
unsigned int registers[10];
bool enable(void); //enables the CODEC, does not power up ADC nor DAC (use enableIn() and enableOut() for selective power up)
bool enableIn(void); //powers up ADC
bool enableOut(void); //powers up DAC
bool disable(void) { return (disableIn()&&disableOut()); } //powers down ADC/DAC
bool disableIn(void); //powers down ADC
bool disableOut(void); //powers down DAC
bool volume(float n); //sets LOUT/ROUT volume to n (range 0.0 - 1.0)
bool volumeLeft(float n); //sets LOUT volume to n (range 0.0 - 1.0)
bool volumeRight(float n); //sets ROUT volume to n (range 0.0 - 1.0)
bool inputLevel(float n) { return false; } //not supported by AK4558
bool inputSelect(int n); {return false; } //sets inputs to mono left, mono right, stereo (default stereo), not yet implemented
private:
unit8_t registers[10];
void initConfig(void); void initConfig(void);
void readConfig(void); void readConfig(void);
bool write(unsigned int reg, unsigned int val); bool write(unsigned int reg, unsigned int val);
unit8_t convertVolume(float vol);
}; };


#endif #endif

Loading…
Cancel
Save