RK3288 添加USB转虚拟串口设备

时间:2021-03-26 16:14:26

在系统开启并有日志打印的前提下,插入USB设备,就会打印USB设备和虚拟串口信息。

打印信息如下:

供应商ID(VID):idVendor=1234,产品ID(PID): idProduct=5678

Product、Manufacturer、SerialNumber,这三项暂时用不到。

ttyACM0:虚拟出来的串口,也有可能是ttySx、ttyGSx(x为0/1/2/3......)

[ 99.373774] usb 3-1.3: new full-speed USB device number 3 using usb20_host
[ 99.473868] usb 3-1.3: New USB device found, idVendor=1234, idProduct=5678
[ 99.473970] usb 3-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 99.473997] usb 3-1.3: Product: USBKey Module
[ 99.474016] usb 3-1.3: Manufacturer: USBKey Chip
[ 99.474033] usb 3-1.3: SerialNumber: 202730041341
[ 99.483763] cdc_acm 3-1.3:1.0: This device cannot do calls on its own. It is not a modem.
[ 99.491455] cdc_acm 3-1.3:1.0: ttyACM0: USB ACM device

 

先手动测试此虚拟串口能否使用(以虚拟串口的扫描枪为例)

$ adb shell
// 查看虚拟的串口是否存在
root@xxx:/ # ls /dev/ttyACM0
ls /dev/ttyACM0
/dev/ttyACM0
// 如果不是 root 权限,此时使用 su 获取 root 权限
// 修改此虚拟串口为最高权限
root@xxx:/ # chmod 777 /dev/ttyACM0
chmod 777 /dev/ttyACM0
root@xxx:/ # cat dev/ttyACM0
cat dev/ttyACM0
// 开始扫码
DS610018C18021
DS610018C18021

 

确定虚拟串口可以使用,将设备添加到代码中。

同时添加了ttyACM0-3,为了防止插入多个设备而导致虚拟串口变动。

将VID和PID添加到数组 option_ids[] 中。USB_DEVICE(VID, PID)

diff --git a/device/rockchip/common/ueventd.rockchip.rc b/device/rockchip/common/ueventd.rockchip.rc
old mode 100644
new mode 100755
index 34f7ad1..d82fad3
--- a/device/rockchip/common/ueventd.rockchip.rc
+++ b/device/rockchip/common/ueventd.rockchip.rc
@@ -116,3 +116,8 @@
 /dev/i2c-2               0660   system          system
 /dev/i2c-3               0660   system          system
 /dev/i2c-4               0660   system          system
+
+/dev/ttyACM0                     0666   system          system
+/dev/ttyACM1                     0666   system          system
+/dev/ttyACM2                     0666   system          system
+/dev/ttyACM3                     0666   system          system
diff --git a/kernel/drivers/usb/serial/option.c b/kernel/drivers/usb/serial/option.c
index e7ecdc3..9f1a6b6 100755
--- a/kernel/drivers/usb/serial/option.c
+++ b/kernel/drivers/usb/serial/option.c
@@ -1766,6 +1766,8 @@ static const struct usb_device_id option_ids[] = {
        
        {USB_DEVICE(0x0E8D,0x00A5)},
        {USB_DEVICE(0x05C6,0x9025)},
+       {USB_DEVICE(0x1234,0x5678)},//扫描枪
        
        { } /* Terminating entry */
 };