需求:
RK3288 Android6 UNIK 需要增加餐盘和摄像头的固定映射关系
方法:
将餐盘层号和usb的设备号绑定,即固定usb口,创建固定名称的usb设备文件
kernel
From 03f90bb48715fe4da182d1ddbff884fe258f74cf Mon Sep 17 00:00:00 2001
From: liangji <[email protected]>
Date: Wed, 22 Feb 2023 15:32:09 +0800
Subject: [PATCH 1/2] feat: support unik cam usb number 7 8 9 10
Change-Id: I9465cfa6b9348bb7df85b4ae194eba7690a8ae2a
Signed-off-by: liangji <[email protected]>
---
arch/arm/boot/dts/rk3288-tb_8846.dts | 4 ++--
drivers/media/usb/uvc/uvc_driver.c | 6 ++++++
drivers/media/v4l2-core/v4l2-dev.c | 17 +++++++++++++++++
drivers/usb/core/hub.c | 19 +++++++++++++++++++
include/linux/usb.h | 1 +
include/media/v4l2-dev.h | 1 +
6 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/arch/arm/boot/dts/rk3288-tb_8846.dts b/arch/arm/boot/dts/rk3288-tb_8846.dts
index c4fcd7d..d19b39f 100644
--- a/arch/arm/boot/dts/rk3288-tb_8846.dts
+++ b/arch/arm/boot/dts/rk3288-tb_8846.dts
@@ -509,7 +509,7 @@
status = "okay";
ilitek@41 {
- //status = "disabled";
+ status = "disabled";
compatible = "tchip,ilitek";
reg = <0x41>;
ilitek,irq-gpio = <&gpio7 GPIO_A6 IRQ_TYPE_EDGE_FALLING>;
@@ -567,7 +567,7 @@
timing4 : 10.1"LVDS1280x800;
timing5 : 12.3"eDP1920x720;
*/
- native-mode = <&timing0>;
+ native-mode = <&timing4>;
};
&rk_screen {
diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
index 8ca9769..2eaf433 100644
--- a/drivers/media/usb/uvc/uvc_driver.c
+++ b/drivers/media/usb/uvc/uvc_driver.c
@@ -1737,6 +1737,12 @@ static int uvc_register_video(struct uvc_device *dev,
stream->vdev = vdev;
video_set_drvdata(vdev, stream);
+ //keenon liangji add
+ vdev->hw_portnum = dev->udev->hw_portnum;
+ printk("vdev_hw_portnum = %d\n", vdev->hw_portnum);
+
+ //keenon liangji add end
+
ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
if (ret < 0) {
uvc_printk(KERN_ERR, "Failed to register video device (%d).\n",
diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
index ad53e63..931b7f8 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -844,6 +844,23 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
/* Pick a device node number */
mutex_lock(&videodev_lock);
+
+ //keenon liangji add
+
+ printk("dxq portnum=%d\n", vdev->hw_portnum);
+ if(vdev->vfl_type == VFL_TYPE_GRABBER) {
+ if(7 == vdev->hw_portnum) {
+ nr = 7;
+ }else if(8 == vdev->hw_portnum) {
+ nr = 8;
+ }else if(9 == vdev->hw_portnum) {
+ nr = 9;
+ }else if(10 == vdev->hw_portnum) {
+ nr = 10;
+ }
+ }
+ //keenon liangji add end
+
nr = devnode_find(vdev, nr == -1 ? 0 : nr, minor_cnt);
if (nr == minor_cnt)
nr = devnode_find(vdev, 0, minor_cnt);
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 59f11c6..61586ef 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -2148,6 +2148,25 @@ static void show_string(struct usb_device *udev, char *id, char *string)
static void announce_device(struct usb_device *udev)
{
+ //keenon liangji add
+ udev->hw_portnum=0;
+ //printk("kobject_name(&udev->dev->kobj)=%s\n", kobject_name(&(udev->dev.kobj)));
+ if(!strcmp("1-1.3", kobject_name(&(udev->dev.kobj)))){
+ udev->hw_portnum=7;
+ }else if(!strcmp("1-1.1", kobject_name(&(udev->dev.kobj)))){
+ udev->hw_portnum=10;
+ }
+ else if(!strcmp("1-1.4", kobject_name(&(udev->dev.kobj)))){
+ udev->hw_portnum=9;
+ }
+ else if(!strcmp("3-1", kobject_name(&(udev->dev.kobj)))){
+ udev->hw_portnum=8;
+ }
+
+
+
+ //printk("udev->hw_portnum=%d\n", udev->hw_portnum);
+ //keenon liangji add end
dev_info(&udev->dev, "New USB device found, idVendor=%04x, idProduct=%04x\n",
le16_to_cpu(udev->descriptor.idVendor),
le16_to_cpu(udev->descriptor.idProduct));
diff --git a/include/linux/usb.h b/include/linux/usb.h
index 28bd3a8..95ae6f4 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -554,6 +554,7 @@ struct usb_device {
unsigned short bus_mA;
u8 portnum;
+ u8 hw_portnum;
u8 level;
unsigned can_submit:1;
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index 95d1c91..8e7e7a0 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -126,6 +126,7 @@ struct video_device
struct list_head fh_list; /* List of struct v4l2_fh */
int debug; /* Activates debug level*/
+ int hw_portnum; /*usb hw port*/
/* Video standard vars */
v4l2_std_id tvnorms; /* Supported tv norms */
--
2.7.4
hardware
From e9f8a5d1c7f3873b2bb4abafbf4f3e5c984cf875 Mon Sep 17 00:00:00 2001
From: liangji <[email protected]>
Date: Wed, 22 Feb 2023 15:34:00 +0800
Subject: [PATCH] feat: support unik cam_layer
Change-Id: Iab5b9a81fd7716761bb83a31bf818aa56f5f07d7
Signed-off-by: liangji <[email protected]>
---
rockchip/camera/CameraHal/CameraHal_Module.cpp | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/rockchip/camera/CameraHal/CameraHal_Module.cpp b/rockchip/camera/CameraHal/CameraHal_Module.cpp
index 4760f49..c2d2d0b 100755
--- a/rockchip/camera/CameraHal/CameraHal_Module.cpp
+++ b/rockchip/camera/CameraHal/CameraHal_Module.cpp
@@ -753,6 +753,11 @@ int camera_get_number_of_cameras(void)
sprintf(cam_num, "%d", i);
strcat(cam_sys,cam_num);
strcat(cam_sys,"/index");
+
+ //keenon liangji add
+ camInfoTmp[cam_cnt].facing_info.facing = -1;
+ //keenon liangji add end
+
FILE* ifp;
ifp = fopen(cam_sys, "r");
if (ifp == NULL){
@@ -775,7 +780,7 @@ int camera_get_number_of_cameras(void)
if (fd < 0) {
LOGE("Open %s failed! strr: %s",cam_path,strerror(errno));
break;
- }
+ }
LOGD("Open %s success!",cam_path);
memset(&capability, 0, sizeof(struct v4l2_capability));
@@ -790,14 +795,19 @@ int camera_get_number_of_cameras(void)
rk_cam_total_info* pNewCamInfo = new rk_cam_total_info();
memset(camInfoTmp[cam_cnt].device_path,0x00, sizeof(camInfoTmp[cam_cnt].device_path));
strcat(camInfoTmp[cam_cnt].device_path,cam_path);
+ //keenon liangji add
+ camInfoTmp[cam_cnt].facing_info.facing = i;
+ //keenon liangji add end
memset(camInfoTmp[cam_cnt].fival_list,0x00, sizeof(camInfoTmp[cam_cnt].fival_list));
memcpy(camInfoTmp[cam_cnt].driver,capability.driver, sizeof(camInfoTmp[cam_cnt].driver));
camInfoTmp[cam_cnt].version = capability.version;
+ /*
if (strstr((char*)&capability.card[0], "front") != NULL) {
camInfoTmp[cam_cnt].facing_info.facing = CAMERA_FACING_FRONT;
} else {
camInfoTmp[cam_cnt].facing_info.facing = CAMERA_FACING_BACK;
- }
+ }
+ */
ptr = strstr((char*)&capability.card[0],"-");
if (ptr != NULL) {
ptr++;
@@ -975,6 +985,7 @@ int camera_get_number_of_cameras(void)
}
else//cif soc camera
{
+
int i=0;
int fps;
int crop_w, crop_h;
@@ -1123,6 +1134,7 @@ int camera_get_number_of_cameras(void)
//memcpy(&gCamInfos[1], &camInfoTmp[1], sizeof(rk_cam_info_t));
for(int i=0;i<CAMERAS_SUPPORT_MAX;i++){
memcpy(&gCamInfos[i], &camInfoTmp[i], sizeof(rk_cam_info_t));
+
}
@@ -1326,6 +1338,9 @@ int camera_get_camera_info(int camera_id, struct camera_info *info)
fp = -1;
}
+ //keenon liangji add
+ info->facing = gCamInfos[camera_id].facing_info.facing;
+ //keenon liangji add end
info->facing = gCamInfos[camera_id].facing_info.facing;
if (strstr(process_name,"com.skype.rover")) {
info->orientation = (info->facing == CAMERA_FACING_BACK)? CONFIG_CAMERA_BACK_ORIENTATION_SKYPE : CONFIG_CAMERA_FRONT_ORIENTATION_SKYPE;
@@ -1335,9 +1350,12 @@ int camera_get_camera_info(int camera_id, struct camera_info *info)
#else
info->facing = gCamInfos[camera_id].facing_info.facing;
info->orientation = gCamInfos[camera_id].facing_info.orientation;
+ //keenon liangji add
+ info->facing = gCamInfos[camera_id].facing_info.facing;
+ //keenon liangji add end
+
#endif
end:
- LOGD("%s(%d): camera_%d facing(%d), orientation(%d)",__FUNCTION__,__LINE__,camera_id,info->facing,info->orientation);
return rv;
}
#if CONFIG_AUTO_DETECT_FRAMERATE
--
2.7.4
framework/base
From 07167c5056f586b92942c72f0ea59db529a64559 Mon Sep 17 00:00:00 2001
From: liangji <[email protected]>
Date: Wed, 22 Feb 2023 15:36:00 +0800
Subject: [PATCH 1/3] feat: support get cam_layer of unik
Change-Id: I5ef475f716666764c25796e9f60fb9377d360b2a
Signed-off-by: liangji <[email protected]>
---
api/current.txt | 1 +
api/system-current.txt | 1 +
.../android/hardware/camera2/CameraManager.java | 50 ++++++++++++++++++++++
3 files changed, 52 insertions(+)
diff --git a/api/current.txt b/api/current.txt
index 541794a..21f187a 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -13358,6 +13358,7 @@ package android.hardware.camera2 {
public final class CameraManager {
method public android.hardware.camera2.CameraCharacteristics getCameraCharacteristics(java.lang.String) throws android.hardware.camera2.CameraAccessException;
method public java.lang.String[] getCameraIdList() throws android.hardware.camera2.CameraAccessException;
+ method public int getCameraInfo(int) throws android.hardware.camera2.CameraAccessException;
method public void openCamera(java.lang.String, android.hardware.camera2.CameraDevice.StateCallback, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
method public void registerAvailabilityCallback(android.hardware.camera2.CameraManager.AvailabilityCallback, android.os.Handler);
method public void registerTorchCallback(android.hardware.camera2.CameraManager.TorchCallback, android.os.Handler);
diff --git a/api/system-current.txt b/api/system-current.txt
index 7c4e0de..9f77759 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -13700,6 +13700,7 @@ package android.hardware.camera2 {
public final class CameraManager {
method public android.hardware.camera2.CameraCharacteristics getCameraCharacteristics(java.lang.String) throws android.hardware.camera2.CameraAccessException;
method public java.lang.String[] getCameraIdList() throws android.hardware.camera2.CameraAccessException;
+ method public int getCameraInfo(int) throws android.hardware.camera2.CameraAccessException;
method public void openCamera(java.lang.String, android.hardware.camera2.CameraDevice.StateCallback, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
method public void registerAvailabilityCallback(android.hardware.camera2.CameraManager.AvailabilityCallback, android.os.Handler);
method public void registerTorchCallback(android.hardware.camera2.CameraManager.TorchCallback, android.os.Handler);
diff --git a/core/java/android/hardware/camera2/CameraManager.java b/core/java/android/hardware/camera2/CameraManager.java
index 1fcfaca..b21e085 100644
--- a/core/java/android/hardware/camera2/CameraManager.java
+++ b/core/java/android/hardware/camera2/CameraManager.java
@@ -188,6 +188,51 @@ public final class CameraManager {
}
/**
+ * keenon liangji add getCameraInfo()
+ * parameters is 0, 1, 2, 3
+ *
+ */
+ @RequiresPermission(android.Manifest.permission.CAMERA)
+ public int getCameraInfo(@NonNull int id)
+ throws CameraAccessException {
+ //keenon liangji add
+ int cam_layer = 0;
+ ICameraService cameraService = CameraManagerGlobal.get().getCameraService();
+ if (cameraService == null) {
+ throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED,
+ "Camera service is currently unavailable");
+ }
+ try{
+ // Legacy backwards compatibility path; build static info from the camera
+ // parameters
+ String[] outParameters = new String[1];
+
+ cameraService.getLegacyParameters(id, /*out*/outParameters);
+ String parameters = outParameters[0];
+
+ CameraInfo info = new CameraInfo();
+ cameraService.getCameraInfo(id, /*out*/info);
+
+ cam_layer = info.info.facing;
+
+ // Normal path: Get the camera characteristics directly from the camera service
+
+
+ } catch (CameraRuntimeException e) {
+ throw e.asChecked();
+ } catch (RemoteException e) {
+ // Camera service died - act as if the camera was disconnected
+ throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED,
+ "Camera service is currently unavailable", e);
+ }
+
+ return cam_layer;
+
+ }
+
+
+
+ /**
* Remove a previously-added callback; the callback will no longer receive torch mode status
* callbacks.
*
@@ -292,6 +337,7 @@ public final class CameraManager {
throws CameraAccessException {
CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
CameraDevice device = null;
+
try {
synchronized (mLock) {
@@ -318,6 +364,7 @@ public final class CameraManager {
CameraAccessException.CAMERA_DISCONNECTED,
"Camera service is currently unavailable");
}
+
cameraService.connectDevice(callbacks, id,
mContext.getOpPackageName(), USE_CALLING_UID, holder);
cameraUser = ICameraDeviceUser.Stub.asInterface(holder.getBinder());
@@ -371,6 +418,7 @@ public final class CameraManager {
} catch (CameraRuntimeException e) {
throw e.asChecked();
}
+
return device;
}
@@ -607,6 +655,7 @@ public final class CameraManager {
* <p>In case of errors connecting to the camera service, will return an empty list.</p>
*/
private ArrayList<String> getOrCreateDeviceIdListLocked() throws CameraAccessException {
+
if (mDeviceIdList == null) {
int numCameras = 0;
ICameraService cameraService = CameraManagerGlobal.get().getCameraService();
@@ -663,6 +712,7 @@ public final class CameraManager {
}
mDeviceIdList = deviceIdList;
}
+
return mDeviceIdList;
}
--
2.7.4
From eb6ab6fedb3404f1e2ee977d26caab0f0f27ed03 Mon Sep 17 00:00:00 2001
From: liangji <[email protected]>
Date: Fri, 24 Feb 2023 11:12:11 +0800
Subject: [PATCH 3/3] improvement: update api for get remap for camera
Change-Id: Id662e7164ac51091a8336e2af0f7ea6f78a93340
Signed-off-by: liangji <[email protected]>
---
api/current.txt | 3 +-
api/system-current.txt | 3 +-
.../android/hardware/camera2/CameraManager.java | 52 +++++++++++++++++++++-
3 files changed, 55 insertions(+), 3 deletions(-)
diff --git a/api/current.txt b/api/current.txt
index eb080b0..19b35f7 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -13358,7 +13358,8 @@ package android.hardware.camera2 {
public final class CameraManager {
method public android.hardware.camera2.CameraCharacteristics getCameraCharacteristics(java.lang.String) throws android.hardware.camera2.CameraAccessException;
method public java.lang.String[] getCameraIdList() throws android.hardware.camera2.CameraAccessException;
- method public int getCameraInfo(int) throws android.hardware.camera2.CameraAccessException;
+ method public android.util.ArrayMap<java.lang.Integer, java.lang.Integer> getCameraIdReMap() throws android.hardware.camera2.CameraAccessException;
+ method public int getCameraInfo(java.lang.String) throws android.hardware.camera2.CameraAccessException;
method public void openCamera(java.lang.String, android.hardware.camera2.CameraDevice.StateCallback, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
method public void registerAvailabilityCallback(android.hardware.camera2.CameraManager.AvailabilityCallback, android.os.Handler);
method public void registerTorchCallback(android.hardware.camera2.CameraManager.TorchCallback, android.os.Handler);
diff --git a/api/system-current.txt b/api/system-current.txt
index 84fb497..09fcae3 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -13700,7 +13700,8 @@ package android.hardware.camera2 {
public final class CameraManager {
method public android.hardware.camera2.CameraCharacteristics getCameraCharacteristics(java.lang.String) throws android.hardware.camera2.CameraAccessException;
method public java.lang.String[] getCameraIdList() throws android.hardware.camera2.CameraAccessException;
- method public int getCameraInfo(int) throws android.hardware.camera2.CameraAccessException;
+ method public android.util.ArrayMap<java.lang.Integer, java.lang.Integer> getCameraIdReMap() throws android.hardware.camera2.CameraAccessException;
+ method public int getCameraInfo(java.lang.String) throws android.hardware.camera2.CameraAccessException;
method public void openCamera(java.lang.String, android.hardware.camera2.CameraDevice.StateCallback, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
method public void registerAvailabilityCallback(android.hardware.camera2.CameraManager.AvailabilityCallback, android.os.Handler);
method public void registerTorchCallback(android.hardware.camera2.CameraManager.TorchCallback, android.os.Handler);
diff --git a/core/java/android/hardware/camera2/CameraManager.java b/core/java/android/hardware/camera2/CameraManager.java
index b21e085..89bf3aa 100644
--- a/core/java/android/hardware/camera2/CameraManager.java
+++ b/core/java/android/hardware/camera2/CameraManager.java
@@ -187,16 +187,55 @@ public final class CameraManager {
CameraManagerGlobal.get().registerTorchCallback(callback, handler);
}
+
+ /*
+ * keenon liangji add getCameraIdReMap()
+ *
+ */
+ @RequiresPermission(android.Manifest.permission.CAMERA)
+ public ArrayMap<Integer, Integer> getCameraIdReMap()
+ throws CameraAccessException {
+
+ int ret = 0;
+ ArrayMap<Integer, Integer> map = new ArrayMap<Integer, Integer>();
+ Log.w(TAG, "liangji getCameraIdReMap");
+ String[] camlist = getCameraIdList();
+
+ for (String id : camlist) {
+ int id_int;
+ try{
+ id_int = Integer.parseInt(id);
+ }
+ catch(NumberFormatException e){
+ id_int = 0;
+ }
+
+ Log.w(TAG, "liangji getCameraIdReMap add id = "+ id +" id_int = "+ id_int);
+ map.put(id_int, getCameraInfo(id));
+ }
+
+ return map;
+ }
+
+
/**
* keenon liangji add getCameraInfo()
* parameters is 0, 1, 2, 3
*
*/
@RequiresPermission(android.Manifest.permission.CAMERA)
- public int getCameraInfo(@NonNull int id)
+ public int getCameraInfo(@NonNull String cameraId)
throws CameraAccessException {
//keenon liangji add
int cam_layer = 0;
+ int id;
+ try{
+ id = Integer.parseInt(cameraId);
+ }
+ catch(NumberFormatException e){
+ id = 0;
+ }
+
ICameraService cameraService = CameraManagerGlobal.get().getCameraService();
if (cameraService == null) {
throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED,
@@ -338,6 +377,7 @@ public final class CameraManager {
CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
CameraDevice device = null;
+ Log.w(TAG, "liangji openCameraDeviceUserAsync");
try {
synchronized (mLock) {
@@ -419,6 +459,15 @@ public final class CameraManager {
throw e.asChecked();
}
+ //keenon liangji add
+ Log.w(TAG, "liangji getCameraIdReMap in openCamera ");
+
+ ArrayMap<Integer, Integer> map = getCameraIdReMap();
+ System.out.println("0:" + map.get("0"));
+ Log.w(TAG, "liangji getCameraIdReMap in openCamera over and map size = "+ map.size());
+
+ //Log.w(TAG, "liangji getCameraIdList "+ temp[0] + ":" + temp[1]);
+ //keenon liangji end
return device;
}
@@ -656,6 +705,7 @@ public final class CameraManager {
*/
private ArrayList<String> getOrCreateDeviceIdListLocked() throws CameraAccessException {
+ Log.w(TAG, "liangji getCameraIdList");
if (mDeviceIdList == null) {
int numCameras = 0;
ICameraService cameraService = CameraManagerGlobal.get().getCameraService();
--
2.7.4