一、sensor路径
vendor/mediateck/propri
sensor校准:
加速度校准
adb shell "echo 1 > /sys/bus/platform/drivers/gsensor/test_cali"
adb shell cat /mnt/vendor/nvcfg/sensor/acc_cali.json
adb shell cat /mnt/vendor/nvcfg/sensor/acc_bias.json
光感校准:
adb shell cat /mnt/vendor/nvcfg/sensor/als_cali.json
抓scp log:
adb shell "while true; do cat /dev/scp;done"
单刷scp:
adb reboot bootloader
fastboot flash scp_a scp.img
fastboot reboot
单编scp
编译命令后加scp.img
地磁软磁参数根据NFC区分:
1、dtsi中添加节点,不同项目配置不同节点
例:#include "mag_sensor.dtsi"
&mag_sensor_info{
support_nfc=<1>;
status="okay";
}
2、地磁驱动中添加节点magnfcinfo来识别识别支持NFC
DEVICE_ATTR(magnfcinfo,0644,mag_show_nfcinfo, NULL);
static struct addtribute *mag_attributes[]={
&dev_attr_magnfcinfo.attr,
NULL
}
读取dtsi,实现是否支持NFC
static uint32_t maghub_get_nfcinfo(void){
int ret;
struct device_node *nfc_node = NULL;
uint32_t is_support_nfc = 0;
nfc_node = of_find_compatible_node(NULL, NULL, "mag,mag_sensor_info");
if(nfc_node == NULL){
pr_err("can not find mag,mag_sensor_info from dtsi \n")
return MAG_USE_DEFAULT;
}
ret = of_property_read(nfc_node, "has_nfc", &is_support_nfc){
pr_err("%s, get has_nfc node fail \n", __func__);
return MAG_USE_DEFAULT;
}
pr_info("%s, has_nfc=%d\n", __func__, (is_support_nfc==1)?1:0);
return is_support_nfc;
}
实现:mag_show_nfcinfo
static ssize_t mag_show_nfcinfo(struct device *dev, struct device_attribute *attr, char *buf){
struct mag_context *cxt = NULL;
if(dev===NULL || attr==NULL || budd == NULL){
pr_err("mag_show_nfcinfo fail \n")
return -1;
}
cxt = mag_context_obj;
return snprintf(buf, PAGE_SIZE, "%d\n", cxt->mag_ctl.is_support_nfc);
}
3、将软磁参数文件放到手机指定目录;
chipset/prebuilt/odm/mtk/mt6768/POL/POL.mk
SENSORS_ODM_COPY_FILES := \
$(LOCAL_PATH)/mag/memsic_nfc.txt:etc/memsic_nfc.txt \
$(LOCAL_PATH)/mag/memsic_nonfc.txt:etc/memsic_nonfc.txt
4、地磁校准库添加读写软磁参数文件
#define HAS_NFC_FILE
#define SOFTPARA_NFC
#define SOFTPARA_NO_NFC
static int check_nfc_config(void){
FILE*fp = NULL;
char buf[8]= {0};
fp = fopen(HAS_NFC_FILE , "r")
if(!fp){
ALGOE("%s open nfc config file %s failed \n", __FUNCTION__, HAS_NFC_FILE );
return -1;
}
if (fgets(buf, sizeof(buf),fp) ==NULL){
ALGOE("%s fgets nfc config file %s failed \n", __FUNCTION__, HAS_NFC_FILE );
fclose(fp);
return -1;
}
fclose(fp);
if (!strncmp(buf, "1", 1)){
return MAG_HAS_NFC;
}else if(!strncmp(buf, "0", 1)){
return MAG_NO_NFC;
}else{
return MAG_USE_DEFAULT;
}
}
inf ReadSoftpara_FromFIle(float *para){
int fd;
inf n;
char buf[SOFTPARA_SIZE];
int ret;
int has_nfc = MAG_USE_DEFAULT;
has_nfc = check_nfc_config();
if (has_nfc == MAG_HAS_NFC){
fd = open(SOFTPARA_NFC, O_RDONLY);
}else if(has_nfc == MAG_NO_NFC){
fd = open(SOFTPARA_NO_NFC, O_RDONLY);
}else{
return 0;
}
if(fd == -1){
return 0
}
n = read(fc, buf, SOFTPARA_SIZE);
if(n <= 0){
close(fd);
return 0;
}
ret = sscanf_s(buf, "%f %f %f %f %f %f %f %f %f\r\n", ¶[0], ¶[1], ¶[2], ¶[3], ¶[4], ¶[5], ¶[6], ¶[7], ¶[8]);
if(ret < 0 ){
close(fd)
return 0;
}
close(fd);
return ret;
}
5、添加地磁库libakl.so
文件:vendor/mediatek/proprietary/hardware/sensor/sensor-1.0/Android.mk
内容:LOCAL_SHARED_LIBRARIES := \
libmemsic \
libakl
include $(LOCAL_PATH)/../../algorithm/akm/Android.mk
文件:vendor/mediatek/proprietary/hardware/sensor/sensor-1.0/algorithm/Android.mk
内容:include $(call all-named-subdir-makefiles, calibration memsic akm)
文件:vendor/mediatek/proprietary/hardware/sensor/sensor-1.0/algorithm/akm/Android.mk
内容:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libakl
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_OWNER := mtk
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_SRC_FILES := lib/libakl.so
LOCAL_MODULE_SUFFIX := .so
LOCAL_MULTILIB := 32
LOCAL_SHARED_LIBRARIES := libc++ libc libdl liblog libm
include $(BUILD_PREBUILT)
include $(CLEAR_VARS)
LOCAL_MODULE := libakl
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_OWNER := mtk
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_SRC_FILES := lib64/libakl.so
LOCAL_MODULE_SUFFIX := .so
LOCAL_MULTILIB := 64
LOCAL_SHARED_LIBRARIES := libc++ libc libdl liblog libm
include $(BUILD_PREBUILT)
6、LCD亮度传值给SCP
文件:kernel-4.19/drivers/misc/mediatek/leds/mt6768/mtk_leds.c
内容:case MT65XX_LED_MODE_CUST_BLS_PWM:
send_sensor_scp_brightness(level);
文件:kernel-4.19/drivers/misc/mediatek/scp/cm4/v01/scp_helper.c
内容:void send_sensor_scp_brightness(int brightness)
{
struct als_para_t *als_priv = get_sensor_share_mem_addr(SHR_MEM_TYPE_ALS);
if (als_priv == NULL){
return;
}
als_priv->lcd_brightness = (int32_t)brightness;
}