earbud 工程配置 LED
1、修改“av_headset_config.h”,修改需要的LED数量
工程默认使用的是 HAVE_3_LEDS 这个宏,可以 “av_headset_config.h” 搜索这个宏,定位到需要修改的地方。
下面将这个宏附近的上下文贴出来,此处主要是增加了 HAVE_NO_LED 和 HAVE_2_LEDS ,默认只有1和3,由于我只需要用到2个LED,就增加一个宏即可。
#if defined(HAVE_NO_LED)
#define appConfigNumberOfLeds() (0)
/*! PIO to control LED0 */
#define appConfigLed0Pio() (0)
/*! PIO to control LED1 (not used) */
#define appConfigLed1Pio() (0)
/*! PIO to control LED2 (not used) */
#define appConfigLed2Pio() (0)
#elif defined(HAVE_1_LED)
/*! The number of LEDs av_headset_led will control. If one LED is configured,
it will use appConfigLed0Pio(), if two LEDs are configured it will use
appConfigLed0Pio() and appConfigLed1Pio() etc. */
#define appConfigNumberOfLeds() (1)
/*! PIO to control LED0 */
#define appConfigLed0Pio() CHIP_LED_0_PIO
/*! PIO to control LED1 (not used) */
#define appConfigLed1Pio() (0)
/*! PIO to control LED2 (not used) */
#define appConfigLed2Pio() (0)
/* 注意:此处是增加的内容 */
#elif defined(HAVE_2_LEDS)
/* The number of LEDs av_headset_led will control. */
#define appConfigNumberOfLeds() (2)
/*! PIO to control LED0 */
#define appConfigLed0Pio() CHIP_LED_0_PIO
/*! PIO to control LED1 */
#define appConfigLed1Pio() CHIP_LED_1_PIO
/*! PIO to control LED2 */
#define appConfigLed2Pio() (0)
#elif defined(HAVE_3_LEDS)
/* The number of LEDs av_headset_led will control. */
#define appConfigNumberOfLeds() (3)
/*! PIO to control LED0 */
#define appConfigLed0Pio() CHIP_LED_0_PIO
/*! PIO to control LED1 */
#define appConfigLed1Pio() CHIP_LED_1_PIO
/*! PIO to control LED2 */
#define appConfigLed2Pio() CHIP_LED_2_PIO
#else
#error LED config not correctly defined.
#endif
之后要在工程属性中修改一下,使用新定义的值。
2、修改 “av_headset_ui.c” ,修改 LED 的状态
以修改2个 LED 为例,修改使用2个LED时的定义,并且增加颜色组合。
#if (appConfigNumberOfLeds() == 3)
#define LED_0_STATE (1 << 0)
#define LED_1_STATE (1 << 1)
#define LED_2_STATE (1 << 2)
#elif (appConfigNumberOfLeds() == 2)
/* We only have 2 LED so map all control to the same LED */
#define LED_0_STATE (1 << 0)
#define LED_1_STATE (1 << 1)
#define LED_2_STATE (1 << 1)
#else
/* We only have 1 LED so map all control to the same LED */
#define LED_0_STATE (1 << 0)
#define LED_1_STATE (1 << 0)
#define LED_2_STATE (1 << 0)
#endif
#define LED_RED (LED_0_STATE)
#define LED_BLUE (LED_1_STATE)
#define LED_GREEN (LED_2_STATE)
#define LED_WHITE (LED_0_STATE | LED_1_STATE | LED_2_STATE)
#define LED_PURPLE (LED_RED | LED_BLUE)
3、LED 事件状态
在“av_headset_ui.c”文件中,刚才的宏定义下方,就是定义 LED 事件的地方,可参考工程原有代码的写法来改写。