C void sample_xl9535_detect_task(void *param) { GPIO_ReturnCode ret = 0; UINT32 value = 0; OSA_STATUS status = OS_SUCCESS; UINT32 flag_value = 0; unsigned char RegAddr = 0; unsigned char RegWriteValue = 0; unsigned char RegReadValue0 = 0; unsigned char RegReadValue1 = 0; UINT8 down_en = 0; UINT8 up_en = 0; UINT8 sig_en = 0; UINT8 mul_en = 0; UINT8 read_en = 0; UINT8 de_en = 0; UINT8 ck_en = 0; UINT8 sim_en = 0; UINT8 gnss_en = 0; UINT8 nb_en = 0; UINT8 fourg_en = 0;
//初始化i2c总线 ret = drv_xl9535_i2c_init(); sample_xl9535_catstudio_printf("ql_i2c_init ret %d", ret);
//上电后,读xl9535 io扩展芯片的8个寄存器,测试用 RegAddr = 0x00; ret = drv_xl9535_i2c_read(&RegAddr, &RegReadValue0); sample_xl9535_catstudio_printf("read reg 00 i2c value=0x%x, ret=%d\n", RegReadValue0, ret); RegAddr = 0x01; ret = drv_xl9535_i2c_read(&RegAddr, &RegReadValue0); sample_xl9535_catstudio_printf("read reg 01 i2c value=0x%x, ret=%d\n", RegReadValue0, ret); RegAddr = 0x02; ret = drv_xl9535_i2c_read(&RegAddr, &RegReadValue0); sample_xl9535_catstudio_printf("read reg 02 i2c value=0x%x, ret=%d\n", RegReadValue0, ret); RegAddr = 0x03; ret = drv_xl9535_i2c_read(&RegAddr, &RegReadValue0); sample_xl9535_catstudio_printf("read reg 03 i2c value=0x%x, ret=%d\n", RegReadValue0, ret); RegAddr = 0x04; ret = drv_xl9535_i2c_read(&RegAddr, &RegReadValue0); sample_xl9535_catstudio_printf("read reg 04 i2c value=0x%x, ret=%d\n", RegReadValue0, ret); RegAddr = 0x05; ret = drv_xl9535_i2c_read(&RegAddr, &RegReadValue0); sample_xl9535_catstudio_printf("read reg 05 i2c value=0x%x, ret=%d\n", RegReadValue0, ret); RegAddr = 0x06; ret = drv_xl9535_i2c_read(&RegAddr, &RegReadValue0); sample_xl9535_catstudio_printf("read reg 06 i2c value=0x%x, ret=%d\n", RegReadValue0, ret); RegAddr = 0x07; ret = drv_xl9535_i2c_read(&RegAddr, &RegReadValue0); sample_xl9535_catstudio_printf("read reg 07 i2c value=0x%x, ret=%d\n", RegReadValue0, ret);
//等1s OSATaskSleep(1 * 200);
//初始化xl0535 io扩展芯片的06 07寄存器,设置所有的io都是输入 RegAddr = 0x06; RegWriteValue = 0xFF; ret = drv_xl9535_i2c_write(&RegAddr, &RegReadValue0); sample_xl9535_catstudio_printf("write i2c value=0x%x, ret=%d\n", RegWriteValue, ret); RegAddr = 0x07; RegWriteValue = 0xFF; ret = drv_xl9535_i2c_write(&RegAddr, &RegReadValue0); sample_xl9535_catstudio_printf("write i2c value=0x%x, ret=%d\n", RegWriteValue, ret); while(1) { // sample_xl9535_catstudio_printf("sample_xl9535_detect_task\r\n"); status = OSAFlagWait(sample_xl9535_int_detect_flg_ref, 0x01, OSA_FLAG_OR_CLEAR, &flag_value, OSA_SUSPEND);
//红豆版,设置了边沿,但是还是会上升沿,下降沿都触发,所以会执行两次 if(flag_value & 0x01) { RegAddr = 0x00; //ret = ql_i2c_read(i2c_no, SAMPLE_I2C_SLAVE_ADDR, RegAddr, &RegReadValue0, 1); ret = drv_xl9535_i2c_read(&RegAddr, &RegReadValue0); // sample_xl9535_catstudio_printf("read reg 00 i2c value=0x%x, ret=%d\n", RegReadValue0, ret); RegAddr = 0x01; //ret = ql_i2c_read(i2c_no, SAMPLE_I2C_SLAVE_ADDR, RegAddr, &RegReadValue0, 1); ret = drv_xl9535_i2c_read(&RegAddr, &RegReadValue1); // sample_xl9535_catstudio_printf("read reg 01 i2c value=0x%x, ret=%d\n", RegReadValue1, ret);
//寄存器值非默认值,表示有io输入,否则表示是上升沿中断 if(RegReadValue0 != 0xff || RegReadValue1 != 0x07) { event_ticks = OSAGetTicks(); int_status = 0;
//判断是那个IO这里使用寄存器值判断,后续可以改为根据位判断 if(RegReadValue1 == DRV_XL9535_BUTTON_DOWN_EN) { // sample_xl9535_catstudio_printf("down int"); down_en = 1; } else if(RegReadValue1 == DRV_XL9535_BUTTON_UP_EN) { // sample_xl9535_catstudio_printf("up int"); up_en = 1; } else if(RegReadValue1 == DRV_XL9535_BUTTON_SIG_EN) { // sample_xl9535_catstudio_printf("sig int"); sig_en = 1; } else if(RegReadValue0 == DRV_XL9535_BUTTON_MUL_EN) { // sample_xl9535_catstudio_printf("mul int"); mul_en = 1; } else if(RegReadValue0 == DRV_XL9535_BUTTON_READ_EN) { // sample_xl9535_catstudio_printf("read int"); read_en = 1; } else if(RegReadValue0 == DRV_XL9535_BUTTON_DE_EN) { // sample_xl9535_catstudio_printf("de int"); de_en = 1; } else if(RegReadValue0 == DRV_XL9535_BUTTON_CK_EN) { // sample_xl9535_catstudio_printf("ck int"); ck_en = 1; } else if(RegReadValue0 == DRV_XL9535_BUTTON_SIM_EN) { // sample_xl9535_catstudio_printf("sim int"); sim_en = 1; } else if(RegReadValue0 == DRV_XL9535_BUTTON_GNSS_EN) { // sample_xl9535_catstudio_printf("gnss int"); gnss_en = 1; } else if(RegReadValue0 == DRV_XL9535_BUTTON_NB_EN) { // sample_xl9535_catstudio_printf("nb int"); nb_en = 1; } else if(RegReadValue0 == DRV_XL9535_BUTTON_4G_EN) { // sample_xl9535_catstudio_printf("4g int"); fourg_en = 1; } } else { if(int_status == 0) { UINT32 keep_ticks = OSAGetTicks() - event_ticks; if(keep_ticks > 20) { //检测到某个IO被按下后,可以在这里,或者发送信号,消息等去其它任务执行相应操作 // sample_xl9535_catstudio_printf("keep_ticks:%d, event_ticks:%d", keep_ticks, event_ticks); if(down_en == 1) { sample_xl9535_catstudio_printf("down en"); } else if(up_en == 1) { sample_xl9535_catstudio_printf("up en"); } else if(sig_en == 1) { sample_xl9535_catstudio_printf("sig en"); } else if(mul_en == 1) { sample_xl9535_catstudio_printf("mul en"); } else if(read_en == 1) { sample_xl9535_catstudio_printf("read en"); } else if(de_en == 1) { sample_xl9535_catstudio_printf("de en"); } else if(ck_en == 1) { sample_xl9535_catstudio_printf("ck en"); } else if(sim_en == 1) { sample_xl9535_catstudio_printf("sim en"); } else if(gnss_en == 1) { sample_xl9535_catstudio_printf("gnss en"); } else if(nb_en == 1) { sample_xl9535_catstudio_printf("nb en"); } else if(fourg_en == 1) { sample_xl9535_catstudio_printf("4g en"); } } down_en = 0; up_en = 0; sig_en = 0; mul_en = 0; read_en = 0; de_en = 0; ck_en = 0; sim_en = 0; gnss_en = 0; nb_en = 0; fourg_en = 0; } int_status = 1; } } } } |
文章评论(0条评论)
登录后参与讨论