diff --git a/kitsune/i2c_cmd.c b/kitsune/i2c_cmd.c index 35a3ab1f..fc618c29 100644 --- a/kitsune/i2c_cmd.c +++ b/kitsune/i2c_cmd.c @@ -722,6 +722,43 @@ int32_t set_volume(int v, unsigned int dly) { } +static bool codec_muted = true; +void codec_watchdog() { + unsigned char cmd[2]; + if( !codec_muted && xSemaphoreTakeRecursive(i2c_smphr, 0)) { + + codec_set_book(0); + codec_set_page(0); + + cmd[0] = 44; + cmd[1] = 0; + I2C_IF_Write(Codec_addr, cmd, 1, 1); + I2C_IF_Read(Codec_addr, &cmd[1], 1); + + if( cmd[1] ) { + LOGE("B0_P0_R44 %x\n",cmd[1]); + } + + if( cmd[1] & 0xC0 ) { + LOGE("overcurrent\n",cmd[1]); + + codec_set_book(0); + codec_set_page(1); + + cmd[0] = 45; + cmd[1] = 0; + I2C_IF_Write(Codec_addr, cmd, 1, 1); + I2C_IF_Read(Codec_addr, &cmd[1], 1); + LOGE("B0_P1_R45 %x\n",cmd[1]); + + cmd[0] = 45; + cmd[1] = 6; + I2C_IF_Write(Codec_addr, cmd, 2, 1); + } + + xSemaphoreGiveRecursive(i2c_smphr); + } +} int cmd_codec(int argc, char *argv[]) { unsigned char cmd[2]; @@ -888,6 +925,7 @@ void codec_mute_spkr(void) cmd[1] = 0x00; I2C_IF_Write(Codec_addr, cmd, 2, send_stop); + codec_muted = true; xSemaphoreGiveRecursive(i2c_smphr); } @@ -907,9 +945,10 @@ void codec_unmute_spkr(void) if( xSemaphoreTakeRecursive(i2c_smphr, 100)) { cmd[0] = 48; - cmd[1] = (SPK_VOLUME_12dB << 4); + cmd[1] = (SPK_VOLUME_6dB << 4); I2C_IF_Write(Codec_addr, cmd, 2, send_stop); + codec_muted = false; xSemaphoreGiveRecursive(i2c_smphr); } diff --git a/kitsune/main/main.c b/kitsune/main/main.c index 24b4ef54..0f0c98c9 100644 --- a/kitsune/main/main.c +++ b/kitsune/main/main.c @@ -308,6 +308,7 @@ void nwp_reset_thread(void* unused) { #endif extern bool disable_net_timeout; bool check_button(); +void codec_watchdog(); void watchdog_thread(void* unused) { #ifdef NWP_WATCHDOG_TIMEOUT int last_nwp_reset_time = 0; @@ -333,6 +334,7 @@ void watchdog_thread(void* unused) { last_nwp_reset_time = xTaskGetTickCount(); } #endif + codec_watchdog(); MAP_WatchdogIntClear(WDT_BASE); //clear wdt vTaskDelay(1000); }