【已解决】BP3L 的IO中断初始化

蓝牙 BLE设备、蓝牙 MESH设备、蓝牙 Beacon设备、Sub-G设备等


Post Reply
13482367102
Posts: 7

void Exti_Init(void)
{
TUYA_GPIO_IRQ_T EXTI_InitStructure;
TUYA_GPIO_IRQ_T OCP_InitStructure;

Code: Select all

EXTI_InitStructure.mode = TUYA_GPIO_IRQ_FALL;
EXTI_InitStructure.cb = Exti_ISR;
tal_gpio_irq_init(TUYA_GPIO_NUM_3, &EXTI_InitStructure);
tal_mysource_debug("TUYA_GPIO_NUM_3 Exti_Init \n");

OCP_InitStructure.mode = TUYA_GPIO_IRQ_FALL;
OCP_InitStructure.cb = Exti_IRQHandler;
tal_gpio_irq_init(TUYA_GPIO_NUM_14, &OCP_InitStructure);
tal_mysource_debug("TUYA_GPIO_NUM_14 Exti_Init \n");

}
// 管脚中断函数
void Exti_ISR(void)
{
// set key flag
hal_timer_set(AP_TIMER_ID_6, 1000);
tal_gpio_irq_disable(TUYA_GPIO_NUM_3); // close the gpio interrupt
tal_mysource_debug("tuya ble key ok!\n");
}
void Exti_IRQHandler(void)
{

Code: Select all

 tal_gpio_irq_disable(TUYA_GPIO_NUM_14);
 hal_pwm_stop();
 OutputRetry_Timeout = OutputRetry_Timeset;
 tal_mysource_debug("timer6 with OCP_protect !\n");

}
按下KEY(GPIO 3)按键按下出现[0000000055 TUYA D][my_source.c:186] timer6 with OCP_protect !

User avatar
joey_nobug
Posts: 145

Re: BP3L 的IO中断初始化

你好,你这个是 mesh 的 SDK 还是 BLE 的 SDK

Talk is cheap, show me the code.
User avatar
joey_nobug
Posts: 145

Re: BP3L 的IO中断初始化

你好,这个跟 kernal 中 tkl_gpio.c 实现方式有关,考虑到 phy6222 平台资源的问题,kernal 中未记录不同中断引脚的回调函数,只使用一个回调函数同时将触发中断的 gpio_pin 作为入参传递进来。所以在同时是用多个 gpio 中断时,业务层注册同一个 gpio 中断回调函数,在函数内根据入参引脚号来做不同的业务逻辑。

另外目前线上版本 sdk 中需做如下修改:
mesh sdk 中 tkl_gpio.c 中 将入参修改为 kernal 定义的类型,BLE sdk 也可参考此改动

Code: Select all

void phy6222_gpio_posedge(gpio_pin_e pin, gpio_polarity_e type){
    TUYA_GPIO_NUM_E gpio_num = phy6222_gpio_to_tkl_gpio(pin);
    if(NULL != hal_gpio_irq_cb){
        hal_gpio_irq_cb(&gpio_num);
    }
}

void phy6222_gpio_negedge(gpio_pin_e pin, gpio_polarity_e type){
    TUYA_GPIO_NUM_E gpio_num = phy6222_gpio_to_tkl_gpio(pin);
    if(NULL != hal_gpio_irq_cb){
        hal_gpio_irq_cb(&gpio_num);
    }
}
Talk is cheap, show me the code.
13482367102
Posts: 7

Re: BP3L 的IO中断初始化

好的,谢谢

User avatar
joey_nobug
Posts: 145

Re: BP3L 的IO中断初始化

针对你前面的问题,我们发现线上 SDK 有个错误要处理下:
tkl_gpio.c 中 phy6222_gpio_to_tkl_gpio 转换函数作如下修改

Code: Select all

TUYA_GPIO_NUM_E phy6222_gpio_to_tkl_gpio(gpio_pin_e gpio_phy6222){
    TUYA_GPIO_NUM_E pin_id;
    for(int i = 0; i < (sizeof(tkl_gpio_list)/sizeof(tkl_gpio_list[0])); i++){
        if(gpio_phy6222 == tkl_gpio_list[i]){
            pin_id = (TUYA_GPIO_NUM_E)i;
            return pin_id;
        }
    }

return TUYA_GPIO_NUM_MAX;
}
Talk is cheap, show me the code.
13482367102
Posts: 7

Re: BP3L 的IO中断初始化

void Exti_3Handler(void)
{
// set key flag

Code: Select all

//   hal_timer_set(AP_TIMER_ID_6, 5000);
tal_sw_timer_create(SW_100ms_TimerID_ISR, NULL, &SW_100ms_TimerID);
tal_sw_timer_start(SW_100ms_TimerID, 1000, TAL_TIMER_ONCE);
tal_gpio_irq_disable(TUYA_GPIO_NUM_3); // close the gpio interrupt
tal_mysource_debug("tuya ble key ok!\n");

}
void Exti_14Handler(void)
{
hal_pwm_stop_channel(PWM_CH2);
tal_gpio_irq_disable(TUYA_GPIO_NUM_14);
hal_pwm_stop();
OutputRetry_Timeout = OutputRetry_Timeset;
tal_mysource_debug("timer6 with OCP_protect !\n");
}
void Exti_IRQHandler(void)
{
if(tal_gpio_read(TUYA_GPIO_NUM_14,TUYA_GPIO_LEVEL_LOW))
{
Exti_14Handler();

Code: Select all

	}else 
	 if(tal_gpio_read(TUYA_GPIO_NUM_3,TUYA_GPIO_LEVEL_LOW))
	{
		Exti_3Handler();
	}

}
为啥修改之后按键按下还是会出现
[0000000020 TUYA D][my_source.c:191] timer6 with OCP_protect !

NICE
Posts: 100

Re: BP3L 的IO中断初始化

你好,问题解决了吗?

wt呃呃
Posts: 142

Re: BP3L 的IO中断初始化

你好,已解决

Post Reply