MT6765 android上层获取VCM lens位置
一般摄像头的VCM 自动对焦,对lens的寄存器自动写入位置值,也有些上层APP 应用需要获取VCM lens的位置进行界面信息显示。APP 应用需要获取VCM lens的位置值,需要读取节点值与开放selinux权限。
本文以为DW9714为例,简单说下上层如何获取lens位置.
1 定义lens
ProjectConfig.mk:
CUSTOM_HAL_LENS = dw9714af
CUSTOM_HAL_MAIN_LENS = dw9714af
k62v1_64_bsp_defconfig:
CONFIG_MTK_LENS_DW9714AF_SUPPORT=y
2 驱动调用
lens_info.h
定义模域与控制指令值
#define AF_MAGIC 'A'
#define AFIOC_T_GETPOS _IOR(AF_MAGIC, 18, u32)
main_lens.c
lens列表中找到DW9714AF.
stAF_DrvList g_stAF_DrvList[MAX_NUM_OF_LENS]
IOCOTRL:
static long AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
......
default:
if (g_pstAF_CurDrv)
i4RetValue = g_pstAF_CurDrv->pAF_Ioctl(
a_pstFile, a_u4Command, a_u4Param);
break;
}
g_pstAF_CurDrv->pAF_Ioctl调用DW9714的
long DW9714AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
......
/×添加读取位置代码×/
case AFIOC_T_GETPOS:
{
int value;
printk("DW9714AF_DRV AFIOC_T_GETPOS:%d\n\n",a_u4Param);
spin_lock(g_pAF_SpinLock);
value = g_u4CurrPosition; // 假设这是你的获取节点值的函数
spin_unlock(g_pAF_SpinLock);
if (copy_to_user((int __user *)a_u4Param, &value, sizeof(value))) {
return -EFAULT;
}
}
......
}
3 节点权限开启与selinux权限开放给对应APP
alps/device/mediatek/mt6765/ueventd.mt6765.emmc.rc:
/dev/MAINAF 0777 root root
alps/device/mediatek/mt6765/ueventd.mt6765.ufs.rc:
/dev/MAINAF 0777 root root
alps/device/mediatek/sepolicy/basic/non_plat/file_contexts:
/dev/MAINAF u:object_r:supercam_device:s0
./mediatek/sepolicy/basic/non_plat/untrusted_app.te:
allow untrusted_app supercam_device:chr_file { open read write ioctl};
4 编写JNI接口
int readvalue(void)
{
MAINAFint fd = open("/dev/
", O_RDONLY); // 打开设备文件
if (fd < 0) {
perror("Failed to open device");
}
int value;
AFIOC_T_GETPOSif (ioctl(fd,
, &value) == -1) {
perror("Failed to perform IOCTL");
close(fd);
}
printf("Node value: %d\n", value);
close(fd);
}