物理sensor就是实体sensor,现实存在的、从硬件直接获取数据的sensor。
常见的物理sensor有:加速度acceleration、陀螺仪gyroscope、地磁magnetic、接近光proximity light、光感light、sar(specific absorption rate)、霍尔hall、气压计pressure等
以A器件lis2dw12为例
bp侧在adsp_proc/ssc/sensors/下新建文件夹lis2dw12
mkdir lisdw12
cd lisdw12
移植三方源码src于文件夹adsp_proc/ssc/sensors/lis2dw12内(有些FAE提供的源码会将.h文件放于inc里)
新建文件夹build
mkdir build
cd build
在adsp_proc/ssc/sensors/lis2dw12/build/ 下添加sns_lis2dw12.scons文件(可以生成目标文件,部分FAE不提供,可参照以下进行修改添加)
#====================================================================
#
# LIS2DW12 sensor implementation
#
# GENERAL DESCRIPTION
# build script
#
# Copyright (c) 2022 - LIS2DW12 CO.,LTD.
# All Rights Reserved.
# Confidential and Proprietary - LIS2DW12 CO.,LTD.
#
#====================================================================
Import('env')
import os, inspect
if ('SSC_TARGET_HEXAGON_MDSP' in env['CPPDEFINES']):
Return()
lis2dw12_island_enable = False
if 'SNS_ISLAND_INCLUDE_LIS2DW12' in env:
lis2dw12_island_enable = True
clean_pack_list = []
if 'USES_SSC_STATIC_LIB_BUILDER' in env:
if ('SSC_TARGET_HEXAGON' in env['CPPDEFINES']):
env.AddSSCSU(inspect.getfile(inspect.currentframe()),
register_func_name = "sns_register_lis2dw12",
binary_lib = False,
clean_pack_list = clean_pack_list,
cflags = ['-Wno-sign-compare', '-Wno-enum-compare'],
add_island_files = lis2dw12_island_enable,
registration_cnt = 1,
diag_ssid = "MSG_SSID_SNS_SENSOR_EXT")
adsp_proc/ssc/chipset/sdm439/por.py中添加物理器件的编译,添加sns_lis2dw12
if "YES" == os.getenv('BUILD_FOR_ALPHA'):
include_sensor_vendor_libs.extend(['sns_pah_common', 'sns_wrist_pedometer','sns_wrist_tilt', 'sns_arw',
'sns_t1000', 'sns_mir3da', 'sns_lis2dw12'])
else:
注意:取消编译时不可直接注释掉器件,比如 /* , ‘sns_lis2dw12’ */ ,这会导致所有sensor驱动都挂载不上。
在adsp_proc/ssc_api/pb/里添加.proto协议文件(文件由FAE提供)
./build_modem.sh build adsp
或
./build_modem_projectname.sh adsp
生成的文件在adsp_proc/obj/xxx/xxx/system/etc/firmware/里
将该目录下所有文件push到机器的/firmware/image/里
可以用一下脚本文件 adsp_push.bat
adb root
adb wait-for-device
adb remount
adb wait-for-device
adb shell mount -o rw,remount /firmware
::adb shell rm /firmware/image/adsp*
adb push adsp\. /firmware/image
::adb shell rm /persist/sensors/sns.reg
adb shell sync
adb wait-for-device
adb reboot
其中,adsp文件夹与adsp_push.bat同目录,且adsp文件夹内为从adsp_proc/obj/xxx/xxx/system/etc/firmware/复制的全部文件
在vendor/qcom/proprietary/commonsys-intf/sensors-see/ssc/proto/添加.proto协议文件
在vendor/qcom/proprietary/sensors-see/sensors-hal/sensors/添加.cpp文件(通常由Qcom提供)
在vendor/qcom/proprietary/sensors-see/sensors-hal/framework/sensors_qti.h 添加sensor type
在vendor/qcom/proprietary/commonsys-intf/sensors-see/ssc/proto/ Makefile.am 添加.proto协议文件的编译
export LC_ALL=C
source build/envsetup.sh
lunch
make sensors.ssc
编译生成out/target/product/project/vendor/lib/sensors.ssc.so,push到机器里
在vendor/qcom/proprietary/sensors-see/registry/config/msm8937里添加三方json文件sdm429w_lis2dw12_0.json
修改json文件使之适配
编写脚本文件json_push.bat
adb root
adb wait-for-device
adb remount
adb wait-for-device
adb shell rm -rf persist/sensors/registry/registry/
adb shell mkdir persist/sensors/registry/registry
adb push json\. /vendor/etc/sensors/config/
::adb shell sync
adb reboot
pause
其中,json文件夹与json_push.bat同目录,且json文件夹内为修改好的json文件
adb shell dumpsys sensorservice
或者
adb shell ssc_sensor_info
工厂版本打开mmi单项测试,加速度测试,看是否有值
用户版本下载sensorlist.apk,看是否有值
查看设备上/firmware/image/下是否存在adsp.b00~adsp.b31,adsp.mdt,adspr.jsn,adspua.jsn
设备成功加载固件时,将有如下log打印(搜索lpss\slpi)
subsys-pil-tz ab00000.qcom,lpass: adsp: loading from 0x0000000053800000 to 0x0000000055600000
subsys-pil-tz ab00000.qcom,lpass: adsp: Brought out of reset
subsys-pil-tz ab00000.qcom,lpass: Subsystem error monitoring/handling services are up
subsys-pil-tz ab00000.qcom,lpass: adsp: Power/Clock ready interrupt received
vendor/lib/hw/android.hardware.sensors@1.0-impl.so
vendor/lib64/hw/android.hardware.sensors@1.0-impl.so
vendor/lib/sensors.ssc.so
vendor/lib64/sensors.ssc.so
cat vendor/etc/sensors/hals.conf
sensors.ssc.so
ps -A | grep sensor
system 866 1 12698780 9068 binder_thread_read 0 S android.hardware.sensors@2.0-service.multihal //sensor hal hidl
system 919 1 12350792 3640 binder_thread_read 0 S vendor.qti.hardware.sensorscalibrate@1.0-service //sensor cal hidl
system 978 1 12439180 2568 __arm64_sys_nanosleep 0 S sensors.qti //sensor daemon
system 995 1 0 06:50:23 ? 00:00:00 adsprpcd sensorspd //sensors rpcd daemon,adsp sensor通过此daemon访问json和注册表文件
json文件:vendor/etc/sensors/config
注册表文件:mnt/vendor/persist/sensors/registry/registry
如果注册表文件中没有相应的器件注册表,需要对json文件进行配置,修改json文件后需要将注册表文件全部删除然后reboot重新生成,否则可能失效。
android log里搜索"sensors-hal|sensors.qti|android.hardware.sensors|sscrpcd|adsprpcd|SensorService"
sensor daemon启动:
sensors.qti: set_log_level:509, log_level set: 2
sensors.qti: main:549, sensors daemon starting
sensor hidl 启动:
vendor.xxx.hardware.sensors@1.2-service: Loaded library from sensors.ssc.so
/vendor/bin/hw/android.hardware.sensors@1.0-service: HAL specifies version 1.4, but does not implement set_operation_mode()
sensors-hal: wait_for_mandatory_sensors:518, some mandatory sensors not available yet, will wait for 8 seconds...
sensors-hal: discover_sensors:673, suid discovery time = 0.051625s
sensors-hal: get_sensors_list:367, num_sensors=39
sensorservice启动:
SensorService: nuSensorService starting...
设备中查看mnt/vendor/persist/sensors/sensors_list.txt中有哪些sensor
adb shell “echo c > /proc/sysrq-trigge”