Explorar el Código

SGTL5000 default line levels to 1.3Vp-p & add input gain functions

dds
PaulStoffregen hace 10 años
padre
commit
f1f88f8a5b
Se han modificado 3 ficheros con 61 adiciones y 12 borrados
  1. +51
    -5
      control_sgtl5000.cpp
  2. +8
    -7
      control_sgtl5000.h
  3. +2
    -0
      keywords.txt

+ 51
- 5
control_sgtl5000.cpp Ver fichero

@@ -502,26 +502,24 @@

bool AudioControlSGTL5000::enable(void)
{
//unsigned int n;

muted = true;
Wire.begin();
delay(5);
//Serial.print("chip ID = ");
//delay(5);
//n = read(CHIP_ID);
//unsigned int n = read(CHIP_ID);
//Serial.println(n, HEX);

write(CHIP_ANA_POWER, 0x4060); // VDDD is externally driven with 1.8V
write(CHIP_LINREG_CTRL, 0x006C); // VDDA & VDDIO both over 3.1V
write(CHIP_REF_CTRL, 0x01F2); // VAG=1.575, normal ramp, +12.5% bias current
write(CHIP_LINE_OUT_CTRL, 0x0322); // LO_VAGCNTRL=1.65V, OUT_CURRENT=0.36mA
write(CHIP_LINE_OUT_CTRL, 0x0F22); // LO_VAGCNTRL=1.65V, OUT_CURRENT=0.54mA
write(CHIP_SHORT_CTRL, 0x4446); // allow up to 125mA
write(CHIP_ANA_CTRL, 0x0137); // enable zero cross detectors
write(CHIP_ANA_POWER, 0x40FF); // power up: lineout, hp, adc, dac
write(CHIP_DIG_POWER, 0x0073); // power up all digital stuff
delay(400);
write(CHIP_LINE_OUT_VOL, 0x1515); // default approx 2 volts peak-to-peak
write(CHIP_LINE_OUT_VOL, 0x1D1D); // default approx 1.3 volts peak-to-peak
write(CHIP_CLK_CTRL, 0x0004); // 44.1 kHz, 256*Fs
write(CHIP_I2S_CTRL, 0x0130); // SCLK=32*Fs, 16bit, I2S format
// default signal routing is ok?
@@ -602,6 +600,54 @@ bool AudioControlSGTL5000::volume(float left, float right)
return write(CHIP_ANA_HP_CTRL, m);
}

bool AudioControlSGTL5000::micGain(unsigned int dB)
{
unsigned int preamp_gain, input_gain;

if (dB >= 40) {
preamp_gain = 3;
dB -= 40;
} else if (dB >= 30) {
preamp_gain = 2;
dB -= 30;
} else if (dB >= 20) {
preamp_gain = 1;
dB -= 20;
} else {
preamp_gain = 0;
}
input_gain = (dB * 2) / 3;
if (input_gain > 15) input_gain = 15;

return write(CHIP_MIC_CTRL, 0x0170 | preamp_gain)
&& write(CHIP_ANA_ADC_CTRL, (input_gain << 4) | input_gain);
}

// CHIP_ANA_ADC_CTRL
// Actual measured full-scale peak-to-peak sine wave input for max signal
// 0: 3.12 Volts p-p
// 1: 2.63 Volts p-p
// 2: 2.22 Volts p-p
// 3: 1.87 Volts p-p
// 4: 1.58 Volts p-p
// 5: 1.33 Volts p-p
// 6: 1.11 Volts p-p
// 7: 0.94 Volts p-p
// 8: 0.79 Volts p-p
// 9: 0.67 Volts p-p
// 10: 0.56 Volts p-p
// 11: 0.48 Volts p-p
// 12: 0.40 Volts p-p
// 13: 0.34 Volts p-p
// 14: 0.29 Volts p-p
// 15: 0.24 Volts p-p
bool AudioControlSGTL5000::lineInLevel(uint8_t left, uint8_t right)
{
if (left > 15) left = 15;
if (right > 15) right = 15;
return write(CHIP_ANA_ADC_CTRL, (left << 4) | right);
}

// CHIP_LINE_OUT_VOL
// Actual measured full-scale peak-to-peak sine wave output voltage:
// 0-12: output has clipping

+ 8
- 7
control_sgtl5000.h Ver fichero

@@ -46,21 +46,22 @@ public:
bool unmuteLineout(void) { return write(0x0024, ana_ctrl & ~(1<<8)); }
bool inputSelect(int n) {
if (n == AUDIO_INPUT_LINEIN) {
return write(0x0024, ana_ctrl | (1<<2));
return write(0x0020, 0x055) // +7.5dB gain (1.3Vp-p full scale)
&& write(0x0024, ana_ctrl | (1<<2)); // enable linein
} else if (n == AUDIO_INPUT_MIC) {
//return write(0x002A, 0x0172) && write(0x0024, ana_ctrl & ~(1<<2));
return write(0x002A, 0x0173) && write(0x0024, ana_ctrl & ~(1<<2)); // +40dB
return write(0x002A, 0x0173) // mic preamp gain = +40dB
&& write(0x0020, 0x088) // input gain +12dB (is this enough?)
&& write(0x0024, ana_ctrl & ~(1<<2)); // enable mic
} else {
return false;
}
}
//bool inputLinein(void) { return write(0x0024, ana_ctrl | (1<<2)); }
//bool inputMic(void) { return write(0x002A, 0x0172) && write(0x0024, ana_ctrl & ~(1<<2)); }

unsigned short route(uint8_t i2s_out, uint8_t dac, uint8_t dap, uint8_t dap_mix);
unsigned short route(uint8_t i2s_out, uint8_t dac, uint8_t dap) { return route(i2s_out,dac,dap,0); }
bool volume(float left, float right);
unsigned short micGain(unsigned int n) { return modify(0x002A, n&3, 3); }
bool micGain(unsigned int dB);
bool lineInLevel(uint8_t n) { return lineInLevel(n, n); }
bool lineInLevel(uint8_t left, uint8_t right);
unsigned short lineOutLevel(uint8_t n);
unsigned short lineOutLevel(uint8_t left, uint8_t right);
unsigned short dacVolume(float n);

+ 2
- 0
keywords.txt Ver fichero

@@ -70,6 +70,8 @@ unmuteHeadphone KEYWORD2
muteLineout KEYWORD2
unmuteLineout KEYWORD2
micGain KEYWORD2
lineInLevel KEYWORD2
lineOutLevel KEYWORD2
lo_lvl KEYWORD2
dac_vol KEYWORD2
dap_mix_enable KEYWORD2

Cargando…
Cancelar
Guardar