Skip to content

Commit

Permalink
Reduce output driver, watch codec status bits (#731)
Browse files Browse the repository at this point in the history
* six db

* watchdog: add check for codec overcurrent

* fixup: check only top bits

* more debug data, always reset
  • Loading branch information
plasticchris authored Jan 27, 2017
1 parent 1aa0fe8 commit bc608e9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
41 changes: 40 additions & 1 deletion kitsune/i2c_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
2 changes: 2 additions & 0 deletions kitsune/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down

0 comments on commit bc608e9

Please sign in to comment.