From: John Melton G0ORX Date: Tue, 8 Dec 2020 16:48:56 +0000 (+0000) Subject: Fix i2c_controller switch interrupts X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/file/readonly?a=commitdiff_plain;h=cf64a3ce2474f7c9241b12038357bdff3d4a13ae;p=pihpsdr.git Fix i2c_controller switch interrupts --- diff --git a/i2c_controller.c b/i2c_controller.c index 12a7c71..f06ca5c 100644 --- a/i2c_controller.c +++ b/i2c_controller.c @@ -181,16 +181,48 @@ static int i2c_init() { continue; } - v=PUSHR | PUSHP | PUSHD | RINC | RDEC /*| RMAX | RMIN | INT_2*/; - //g_print("%s: write interrupt config %02X\n",__FUNCTION__, v&0xFF); - if(i2c_smbus_write_byte_data(fd,REG_INTCONF,v&0xFF)<0) { - g_print("%s: counter CMINB1 config failed: %s\n",__FUNCTION__,g_strerror(errno)); - encoder[i].enabled=FALSE; + + int int_config=0; + if(encoder[i].gp1_enabled) { + g_print("%s: encoder %d (0x%02X) GP1 enabled\n",__FUNCTION__,i,encoder[i].address); + v=GP_IN | GP_PULL_EN | GP_INT_NE; + int_config=INT_2; + } else { + g_print("%s: encoder %d (0x%02X) GP1 not enabled\n",__FUNCTION__,i,encoder[i].address); + v=GP_IN | GP_PULL_EN | GP_INT_DI; + } + if(i2c_smbus_write_byte_data(fd, REG_GP1CONF, v&0xFF)<0) { + g_print("%s: counter REG_GP1CONF config failed: %s\n",__FUNCTION__,g_strerror(errno)); + continue; + } + if(encoder[i].gp2_enabled) { + g_print("%s: encoder %d (0x%02X) GP2 enabled\n",__FUNCTION__,i,encoder[i].address); + v=GP_IN | GP_PULL_EN | GP_INT_NE; + int_config=INT_2; + } else { + g_print("%s: encoder %d (0x%02X) GP2 not enabled\n",__FUNCTION__,i,encoder[i].address); + v=GP_IN | GP_PULL_EN | GP_INT_DI; + } + if(i2c_smbus_write_byte_data(fd, REG_GP2CONF, v&0xFF)<0) { + g_print("%s: counter REG_GP2CONF config failed: %s\n",__FUNCTION__,g_strerror(errno)); + continue; + } + if(encoder[i].gp3_enabled) { + g_print("%s: encoder %d (0x%02X) GP3 enabled\n",__FUNCTION__,i,encoder[i].address); + v=GP_IN | GP_PULL_EN | GP_INT_NE; + int_config=INT_2; + } else { + g_print("%s: encoder %d (0x%02X) GP3 not enabled\n",__FUNCTION__,i,encoder[i].address); + v=GP_IN | GP_PULL_EN | GP_INT_DI; + } + if(i2c_smbus_write_byte_data(fd, REG_GP3CONF, v&0xFF)<0) { + g_print("%s: counter REG_GP3CONF config failed: %s\n",__FUNCTION__,g_strerror(errno)); continue; } - //g_print("%s: write interrupt config %02X\n",__FUNCTION__, v&0xFF); - if(i2c_smbus_write_byte_data(fd,REG_INTCONF,v&0xFF)<0) { + int_config=PUSHR | PUSHP | PUSHD | RINC | RDEC /*| RMAX | RMIN | INT_2*/; + //g_print("%s: write interrupt config %02X\n",__FUNCTION__, int_config&0xFF); + if(i2c_smbus_write_byte_data(fd,REG_INTCONF,int_config&0xFF)<0) { g_print("%s: counter CMINB1 config failed: %s\n",__FUNCTION__,g_strerror(errno)); encoder[i].enabled=FALSE; continue;