蓝牙开发杰理开发AD6973 使用 PB2 作为 LED 控制的 IO 口
MTAD6973 使用 PB2 作为 LED 控制的 IO 口
通常情况下,PB2 是用于第二个内置触摸功能的 IO 口,当前芯片的 SDK 将 PB2 配置为入耳检测的 IO 口。
用户可通过调整宏定义来开启或关闭入耳检测功能。
在一个抄板项目中,LED 控制被分配到了 PB2。在完成 LED 配置后,实际并无灯效输出。
其原因是:系统设备初始化时,先初始化了 LED,但随后又将 PB2 重新设置为上拉输入模式,导致 LED 功能失效。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| static void board_devices_init(void) { #if TCFG_PWMLED_ENABLE pwm_led_init(&pwm_led_data); #endif
gpio_set_direction(IO_PORTB_02, 1); gpio_set_pull_up(IO_PORTB_02, 1);
}
|
解决方案
修改 board_devices_init() 函数,将入耳检测相关的代码放在条件编译块内:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| static void board_devices_init(void) { #if TCFG_PWMLED_ENABLE pwm_led_init(&pwm_led_data); #endif
#if (TCFG_IOKEY_ENABLE || TCFG_ADKEY_ENABLE) key_driver_init(); #endif
#if TCFG_LP_EARTCH_KEY_ENABLE gpio_set_direction(IO_PORTB_02, 1); gpio_set_pull_up(IO_PORTB_02, 1); #endif
#if TCFG_UART_KEY_ENABLE extern int uart_key_init(void); uart_key_init(); #endif
#if TCFG_LP_TOUCH_KEY_ENABLE lp_touch_key_init(&lp_touch_key_config); #endif }
|