MT6785平台默认LED的控制方式是硬件控制,如果要在preloader和lk中操作LED就要将LED切换到软件控制,下面以MTK MT6785平台为例,添加LED驱动。
preloader阶段添加LED驱动
1.在preloader阶段的配置选项custom/k85v1_64/k85v1_64.mk中添加一个新的配置项
MT6360_RGBLED=yes
2.在preloader阶段的编译选项platform/mt6785/feature.mak中添加宏定义控制
ifeq ($(strip "$(MT6360_RGBLED)"),"yes")
C_OPTION += -DMT6360_RGBLED
endif
3.在preloader的驱动目录platform/mt6785/src/drivers/makefile添加新文件编译支持
ifeq ("$(MT6360_RGBLED)","yes")
MOD_SRC += mt6360_rgbled.c
endif
4.编写驱动源代码platform/mt6785/src/drivers/mt6360_rgbled.c
#include <i2c.h>
#include "pal_log.h"
#define RGB_EN_RG 0x80
#define ISINK1_CHRIND_EN_MASK 0x80
#define ISINK1_CHRIND_EN_SHIFT 7
#define ISINK1_CHRIND_EN_SEL_MASK 0x8
#define ISINK1_CHRIND_EN_SEL_SHIFT 3
#define RGB1_ISINK_RG 0x81
static struct mt_i2c_t i2c = {
.id = I2C5,
.addr = 0x34,
.mode = FS_MODE,
.speed = 400,
.pushpull = true,
};
void mt6360_enable_isink1(void){
...
}
void mt6360_disable_isink1(void){
...
}
void mt6360_restore_isink1_auto_mode(void){
...
}
5.驱动源码编写完毕,提供三个操作函数头文件
提供三个操作函数,打开/关闭led灯和将LED切换到软件控制,下面再头文件目录下添加如下用户接口头文件,platform/mt6785/src/drivers/inc/mt6360_rgbled.h内容如下:
#ifndef _MT6360_RGBLED_H
#define _MT6360_RGBLED_H
extern void mt6360_enable_isink1(void);
extern void mt6360_disable_isink1(void);
extern void mt6360_restore_isink1_auto_mode(void);
#endif /* _MT6360_RGBLED_H */
6.使用实例:
a #include "mt6360_rgbled.h"
b 调用函数
lk阶段添加LED驱动
1.在lk阶段的配置选项 project/k85v1_64.mk中添加一个新的配置项
MTK_MT6360_RGBLED_SUPPORT := yes
2.在lk阶段的编译选项platform/mt6785/rules.mk中添加宏定义控制和文件编译控制
ifeq ($(MTK_MT6360_RGBLED_SUPPORT),yes)
OBJS += $(LOCAL_DIR)/mt6360_rgbled.o
DEFINES += MTK_MT6360_RGBLED_SUPPORT
endif
3.编写驱动源代码platform/mt6785/mt6360_rgbled.c
#include <platform/errno.h>
#include <platform/mt_i2c.h>
#include <printf.h>
#include <string.h>
#define RGB_EN_RG 0x80
#define ISINK1_CHRIND_EN_MASK 0x80
#define ISINK1_CHRIND_EN_SHIFT 7
#define ISINK1_CHRIND_EN_SEL_MASK 0x8
#define ISINK1_CHRIND_EN_SEL_SHIFT 3
#define RGB1_ISINK_RG 0x81
#define ISINK1_CHRIND_DIM_MODE_MASK 0xC0
#define ISINK1_CHRIND_DIM_MODE_SHIFT 6
#define ISINK1_CHRIND_CUR_SEL_MASK 0xF
#define ISINK1_CHRIND_CUR_SEL_SHIFT 0
#define RGB1_DIM_RG 0x85
#define RGB1_2_Freq_RG 0x89
#define ISINK1_CHRIND_DIM_FSEL_MASK 0XE0
#define ISINK1_CHRIND_DIM_FSEL_SHIFT 5
/* ========================= */
/* I2C operations */
/* ========================= */
static struct mt_i2c_t i2c = {
.id = I2C5,
.addr = 0x34,
.mode = FS_MODE,
.speed = 400,
.pushpull = true,
};
.......
4.驱动源码编写完毕,提供三个操作函数头文件
提供三个操作函数,打开/关闭led灯和将LED切换到软件控制,下面再头文件目录下添加如下用户接口头文件,platform/mt6785/include/platform/mt6360_rgbled.h内容如下:
#ifndef __MT6360_RGBLED_H
#define __MT6360_RGBLED_H
extern void mt6360_enable_isink1_flash(void);
extern void mt6360_disable_isink1(void);
extern void mt6360_set_isink1_on(void);
#endif /* __MT6360_RGBLED_H */
6.使用实例:
a #include "mt6360_rgbled.h"
b 调用函数