Skip to content

Commit

Permalink
restart if speaker driver is disabled for any reason (#732)
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

* restart if speaker driver is disabled for any reason
  • Loading branch information
plasticchris authored Jan 27, 2017
1 parent bc608e9 commit 27535ce
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions kitsune/i2c_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ int32_t set_volume(int v, unsigned int dly) {
static bool codec_muted = true;
void codec_watchdog() {
unsigned char cmd[2];
bool overcurrent, spkr_off;
if( !codec_muted && xSemaphoreTakeRecursive(i2c_smphr, 0)) {

codec_set_book(0);
Expand All @@ -735,22 +736,31 @@ void codec_watchdog() {
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]);
uint8_t b0p0r44 = cmd[1];
if( b0p0r44 ) {
LOGW("B0_P0_R44 %x\n",b0p0r44);
}
overcurrent = b0p0r44 & 0xC0;

if( cmd[1] & 0xC0 ) {
LOGE("overcurrent\n",cmd[1]);

codec_set_book(0);
codec_set_page(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] = 0;
I2C_IF_Write(Codec_addr, cmd, 1, 1);
I2C_IF_Read(Codec_addr, &cmd[1], 1);
uint8_t b0p1r45 = cmd[1];
spkr_off = b0p1r45 == 4;

if( overcurrent ) {
LOGE("overcurrent\n");
}
if( spkr_off ) {
LOGE("spkrdisabled\n");
LOGW("B0_P1_R45 %x\n",b0p1r45);
}
if( overcurrent || spkr_off ) {
LOGW("restart codec\n");
cmd[0] = 45;
cmd[1] = 6;
I2C_IF_Write(Codec_addr, cmd, 2, 1);
Expand Down

0 comments on commit 27535ce

Please sign in to comment.