1. sensorhub 3.0架构介绍
2. 驱动移植
2.1 SCP侧驱动移植
- 添加工程配置
路径:vendor/mediatek/proprietary/tinysys/scp/project/RV55_A/mt6789/tb8781p1_64/
文件:project.mk
CFG_AK7323_SUPPORT = yes
CFG_LSM6DSO_SUPPORT = yes
- 添加驱动所需dts信息
//路径:vendor/mediatek/proprietary/tinysys/scp/project/RV55_A/mt6789/tb8781p1_64/sensor/
//文件:dts.c
#ifdef CFG_LSM6DSO_SUPPORT
{ .key = "name", .string = "lsm6dso_ois"}, /* 与驱动中解析dts保持一致 */
{ .key = "bus_id", .u8 = 1}, /* SPI总线 */
{ .key = "direction", .u8 = 0},
{ .key = "eint_num", .u8 = 2},
#endif
#ifdef CFG_AK7323_SUPPORT
{ .key = "name", .string = "ak7323_ois"},
{ .key = "bus_id", .u8 = 0}, /* i2c总线*/
{ .key = "slave_addr", .u8 = 0x00}, /* broadcast */
{ .key = "slave_addr_x", .u8 = 0x6c}, /* X axis */
{ .key = "slave_addr_y", .u8 = 0x6d}, /* Y axis */
{ .key = "direction", .u8 = 0},
#endif
- 添加驱动文件
//路径:vendor/mediatek/proprietary/tinysys/scp/middleware/sensorhub/drivers/physical/ois
//文件:ak7323_ois.c/lsm6dso_ois.c/ois_subdev.c
- 添加驱动编译选项
//路径:vendor/mediatek/proprietary/tinysys/scp/project/RV55_A/mt6789/platform/features/
//文件:sensorhub.mk
ifeq ($(CFG_AK7323_SUPPORT),yes)
INCLUDES += $(ALGO_DIR)/ois/akm/include //编译算法库时头文件
AW_LIB_FILES += $(ALGO_DIR)/ois/akm/src/akm_algo_ois.c //编译算法库时源文件
INCLUDES += $(ALGO_DIR)/ois/akm //算法库引用头文件目录
LIBFLAGS += -L$(ALGO_DIR)/ois/akm -lakm_ois //算法库路径,且算法库名称为akm_ois.a
C_FILES += $(PHYSICAL_DRV_DIR)/ois/lsm6dso_ois.c
C_FILES += $(PHYSICAL_DRV_DIR)/ois/ois_subdev.c
C_FILES += $(PHYSICAL_DRV_DIR)/ois/ak7323_ois.c
endif
- 配置overlay(本例子不需要配置)
#define OVERLAY_SECTION_OIS \
OVERLAY_ONE_OBJECT(lsm6dso, lsm6dso)
#ifdef OVERLAY_SECTION_OIS
#define OVERLAY0 OVERLAY_SECTION_OIS
#endif
2.2 kernel侧配置
3. 算法库编译及移植
按照以下编译和移植算法后,在文件中引用算法库头文件即可调用内部接口
- 添加算法库文件
//路径:vendor/mediatek/proprietary/tinysys/scp/middleware/sensorhub/algos/RV55_A/ois/akm/src/
//文件:akm_algo_ois.c
├── akm //创建目录
│ ├── include //创建头文件目录
│ │ └── akm_algo_ois.h
│ ├── libakm_ois.a //编译后生成的库文件
│ └── src //创建源文件目录
│ └── akm_algo_ois.c
- 添加编译算法库选项
//路径:vendor/mediatek/proprietary/tinysys/scp/project/RV55_A/mt6789/platform/features/
//文件:sensorhub.mk
ifeq ($(CFG_AK7323_SUPPORT),yes)
INCLUDES += $(ALGO_DIR)/ois/akm/include
AKM_LIB_FILES += $(ALGO_DIR)/ois/akm/src/akm_algo_ois.c
endif
- 修改编译库文件
diff --git a/vendor/mediatek/proprietary/tinysys/scp/build/config.mk b/vendor/mediatek/proprietary/tinysys/scp/build/config.mk
index 63960866664..859aa7cc90c 100644
--- a/vendor/mediatek/proprietary/tinysys/scp/build/config.mk
+++ b/vendor/mediatek/proprietary/tinysys/scp/build/config.mk
@@ -120,7 +120,9 @@ $(PROCESSOR).ASM2_FILE := $(SCP_BIN_STEM).asm2
$(PROCESSOR).RELF_FILE := $(SCP_BIN_STEM).relf
$(PROCESSOR).IMG_HDR_CFG := $(SCP_BUILT_DIR)/img_hdr_$(notdir $(SCP_BIN_STEM)).cfg
$(PROCESSOR)_DRAM.IMG_HDR_CFG := $(SCP_BUILT_DIR)/img_hdr_$(notdir $(SCP_BIN_STEM))_dram.cfg
-
+$(PROCESSOR).STATIC_LIB := $(SCP_MIDDLEWARE_DIR)/sensorhub/algos/$(PROCESSOR)/ois/akm/libakm_ois.a
# ESL-specific outputs
$(PROCESSOR).ESL_AP_LINK_LD := $(SCP_BUILT_DIR)/link.ap.ld
$(PROCESSOR).ESL_MCU0_LINK_LD := $(SCP_BUILT_DIR)/link.mcu0.ld
@@ -202,6 +204,11 @@ S_OBJS := $(sort $(S_FILES:%.S=$(SCP_BUILT_DIR)/%.o))
OBJS += $(sort $(C_OBJS) $(S_OBJS))
$(OBJS): $($(PROCESSOR).TINYSYS_CONFIG_H)
+AKM_LIB_FILES := $(patsubst ./%,%,$(AKM_LIB_FILES))
+AKM_LIB_OBJS := $(sort $(AKM_LIB_FILES:%.c=$(SCP_BUILT_DIR)/%.o))
+$(AKM_LIB_OBJS): $($(PROCESSOR).TINYSYS_CONFIG_H)
# Set dependency
DEPS += $(sort $(filter-out %.P,$(MAKEFILE_LIST)))
@@ -229,7 +236,14 @@ $(S_OBJS): PRIVATE_CFLAGS := $(CFLAGS)
$(S_OBJS): PRIVATE_INCLUDES := $(INCLUDES)
$(S_OBJS): $(SCP_BUILT_DIR)/%.o: %.S
$(compile-c-or-s-to-o)
-
+$(AKM_LIB_OBJS): PRIVATE_BUILD_TAG := $(TINYSYS_SCP)
+$(AKM_LIB_OBJS): PRIVATE_CC := $(CC)
+$(AKM_LIB_OBJS): PRIVATE_CFLAGS := $(CFLAGS)
+$(AKM_LIB_OBJS): PRIVATE_INCLUDES := $(INCLUDES)
+$(AKM_LIB_OBJS): $(SCP_BUILT_DIR)/%.o: %.c
+ $(compile-c-or-s-to-o)
# Generate header file that contains all config options and its values
.PHONY: configheader
configheader: $($(PROCESSOR).TINYSYS_CONFIG_H)
@@ -242,7 +256,10 @@ $($(PROCESSOR).TINYSYS_CONFIG_H):
$(OBJS): $(DEPS)
-include $(OBJS:.o=.P)
-
+$(AKM_LIB_OBJS):$(DEPS)
+-include $(AKM_LIB_OBJS:.o=.P)
###########################################################
## Processor-based SCP build targets
###########################################################
@@ -301,6 +318,12 @@ $($(PROCESSOR).ELF_FILE): PRIVATE_RVXX_CPU := $(RVXX_CPU)
$($(PROCESSOR).ELF_FILE): PRIVATE_OBJS := $(OBJS)
$($(PROCESSOR).ELF_FILE): PRIVATE_LINK_LD := $($(PROCESSOR).LINK_LD)
$($(PROCESSOR).ELF_FILE): $(OBJS)
+AKM_LIB_COMPILE := yes
+ifeq ($(AKM_LIB_COMPILE), yes)
+$($(PROCESSOR).ELF_FILE): $($(PROCESSOR).STATIC_LIB)
+endif
$($(PROCESSOR).ELF_FILE): $(MY_LIBFLAGS_SEARCH_FILE)
$($(PROCESSOR).ELF_FILE): $($(PROCESSOR).LINK_LD) $(DEPS)
@echo '$(TINYSYS_SCP): ELF $@'
@@ -314,7 +337,16 @@ $($(PROCESSOR).ELF_FILE): $($(PROCESSOR).LINK_LD) $(DEPS)
ifneq ($(CFG_UBSAN_SUPPORT),yes)
$(hide)PLATFORM=$(PRIVATE_PLATFORM) $(MCHECK) -d SCP $(SCP_SETTING_INI) $(PRIVATE_MAP_FILE)
endif
-
+ifeq ($(AKM_LIB_COMPILE), yes)
+$($(PROCESSOR).STATIC_LIB): PRIVATE_CC := $(CC)
+$($(PROCESSOR).STATIC_LIB): PRIVATE_CFLAGS := $(CFLAGS)
+$($(PROCESSOR).STATIC_LIB): PRIVATE_INCLUDES := $(INCLUDES)
+$($(PROCESSOR).STATIC_LIB): $(AKM_LIB_OBJS)
+ @echo '-------------------AKM_LIB $@-------------------'
+ $(AR) -r $@ $^
+endif
$($(PROCESSOR).LINK_LD): PRIVATE_CC := $(CC)
$($(PROCESSOR).LINK_LD): PRIVATE_CFLAGS := $(CFLAGS)
$($(PROCESSOR).LINK_LD): PRIVATE_INCLUDES := $(INCLUDES)
4. 多个sensor之间的调用
- 开机先加载lsm6dso模块,初始化subdev,比如
MODULE_DECLARE(lsm6dso_ois, vice, lsm6dso_ois_init);
- 再初始化ak7323模块,比如
LATE_DECLARE(ak7323, vice, ak7323_init);
- ak7323模块中先通过全局变量获取subdev的指针,然后调用lsm6dso的接口
5. log抓取
MTK平台开机过程中的SCP相关log会存在buf里面,所以开机后也可以通过脚本抓取开机过程log
adb wait-for-device
adb root
adb remount
adb shell "echo 1 > /sys/class/misc/scp/scp_mobile_log"
adb shell "while true; do cat /dev/scp | grep -E 'ak7323|lsm6dso';done"
pause
- 使用平台自身带软件debuglog工具
打开开关,关机,重启手机,关机开关,软件会提示log所在路径,push出来后将内部几个scp相关log导出即可。