void checkWM8805()
{
previousMillis_3 = millis();
SPDSTAT = ReadRegister(wm8805, 12);
SR = ReadRegister(wm8805, 16);
srt = (SR &= B00001111);
switch (srt) {
case B0001:
Serial.println("not indicated");
break;
case B0011:
/////Serial.println("32 kHz");
if (strType != "32 kHz") {
strType = "32 kHz";
Serial.println(strType);
screenCurrent(); }
break;
case B1110:
///Serial.println("192 kHz");
if (strType != "192 kHz") {
strType = "192 kHz";
Serial.println(strType);
screenCurrent(); }
break;
case B1010:
///Serial.println("96 kHz");
if (strType != "96 kHz") {
strType = "96 kHz";
Serial.println(strType);
screenCurrent(); }
break;
case B0010:
///Serial.println("48 kHz");
if (strType != "48 kHz") {
strType = "48 kHz";
Serial.println(strType);
screenCurrent(); }
break;
case B0110:
///Serial.println("24 kHz");
if (strType != "24 kHz") {
strType = "24 kHz";
Serial.println(strType);
screenCurrent(); }
break;
case B1100:
///Serial.println("176.4 kHz");
if (strType != "176.4 kHz") {
strType = "176.4 kHz";
Serial.println(strType);
screenCurrent(); }
break;
case B1000:
///Serial.println("88.2 kHz");
if (strType != "88.2 kHz") {
strType = "88.2 kHz";
Serial.println(strType);
screenCurrent(); }
break;
case B0000:
if (SPDSTAT == 80) {
///Serial.println("88.2 kHz");
if (strType != "88.2 kHz") {
strType = "88.2 kHz";
Serial.println(strType);
screenCurrent(); }
break;
}
if (SPDSTAT == 4) {
///Serial.println("176.4 kHz");
if (strType != "176.4 kHz") {
strType = "176.4 kHz";
Serial.println(strType);
screenCurrent(); }
break;
}
if (SPDSTAT == 64) {
///Serial.println("192 kHz");
if (strType != "192 kHz") {
strType = "192 kHz";
Serial.println(strType);
screenCurrent(); }
break;
}
else {
///Serial.println("44.1 kHz");
if (strType != "44.1 kHz") {
strType = "44.1 kHz";
Serial.println(strType);
screenCurrent(); }
}
break;
}
uint8_t INTSTAT = ReadRegister(wm8805, 11); // poll (and clear) interrupt register;
uint8_t SPDSTAT = ReadRegister(wm8805, 12);
uint8_t SampleRate = (SPDSTAT >> 4) & 0x07;
if (INTSTAT != 0 || SampleRate != SampleRateOld) {
// If something has changed do a screen refresh.
Serial.print("INTSTAT:");Serial.println(INTSTAT,HEX);
Serial.print("SPDSTAT:");Serial.println(SPDSTAT,HEX);
Serial.print("Sample rate:");
switch (SampleRate) {
case 0x03:
///Serial.println("32 kHz");
if (strType != "32 kHz") {
///strType = "32 kHz";
///Serial.println(strType);
///screenCurrent();
}
break;
case 0x02:
///Serial.println("44/48 kHz");
if (strType != "44/48 kHz") {
///strType = "44/48 kHz";
///Serial.println(strType);
///screenCurrent();
}
break;
case 0x01:
///Serial.println("88/96 kHz");
if (strType != "88/96 kHz") {
///strType = "88/96 kHz";
///Serial.println(strType);
///screenCurrent();
}
break;
case 0x00:
///Serial.println("192 kHz");
if (strType != "192 kHz") {
////strType = "192 kHz";
///Serial.println(strType);
///screenCurrent();
}
break;
default:
///Serial.println("Unlocked");
if (strType != "Unlocked") {
strType = "Unlocked";
Serial.println(strType);
screenCurrent();
}
break;
}
SampleRateOld = SampleRate;
}
if (SampleRate & 0x04) {
strType = "Unlocked";
screenCurrent();
// If this is unlocked then try and switch around normal and 192khz mode
// until it locks. That is kinda hackish but it seems to work.
if (toggle) {
Serial.println("trying 192 kHz mode...");
///strType = "Unlocked";
///screenCurrent();
WriteRegister(wm8805, 6, 8); // set PLL_N to 8
WriteRegister(wm8805, 5, 12); // set PLL_K to 0C49BA (0C)
WriteRegister(wm8805, 4, 73); // set PLL_K to 0C49BA (49)
WriteRegister(wm8805, 3, 186); // set PLL_K to 0C49BA (BA)
WriteRegister(wm8805, 29, 1); // This might not be needed set SPD_192K_EN to 1
toggle = 0;
} else {
Serial.println("trying normal mode...");
////strType = "Unlocked";
WriteRegister(wm8805, 6, 7); // set PLL_N to 7
WriteRegister(wm8805, 5, 54); // set PLL_K to 36FD21 (36)
WriteRegister(wm8805, 4, 253); // set PLL_K to 36FD21 (FD)
WriteRegister(wm8805, 3, 33); // set PLL_K to 36FD21 (21)
WriteRegister(wm8805, 29, 0); // This might not be needed set SPD_192K_EN to 0
toggle = 1;
} // if toggle
delay(100); // Give some time for WM8805 to lock
}
}