项目背景:
项目使用树莓派和触摸屏搭建一套系统,刚开始一切正常,但有一次发现触摸屏的触摸功能失效了,当时以为是浏览器死机了,于是重启,功能恢复;后来又出现功能失效,当时正好ssh连接了,用 top 查看,资源还是很富裕的,那么排除浏览器死机了,连接鼠标后,鼠标正常使用,再次使用触摸功能,还是失效。
问题排查:
分析一,使用xinput 查看,发现触摸功能失效时比正常时少了2个设备:
$ xinput list
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ SEM USB Keyboard id=9 [slave pointer (2)]
⎜ ↳ PixArt Dell MS116 USB Optical Mouse id=10 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ adc-keys id=6 [slave keyboard (3)]
↳ gpio-keys id=7 [slave keyboard (3)]
↳ SEM USB Keyboard id=8 [slave keyboard (3)]
↳ SEM USB Keyboard id=11 [slave keyboard (3)]
$ xinput list
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ SEM USB Keyboard id=9 [slave pointer (2)]
⎜ ↳ PixArt Dell MS116 USB Optical Mouse id=10 [slave pointer (2)]
⎜ ↳ WingCool Inc. TouchScreen id=12 [slave pointer (2)]
⎜ ↳ WingCool Inc. TouchScreen id=13 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ adc-keys id=6 [slave keyboard (3)]
↳ gpio-keys id=7 [slave keyboard (3)]
↳ SEM USB Keyboard id=8 [slave keyboard (3)]
↳ SEM USB Keyboard id=11 [slave keyboard (3)]
设备少了,那么就去恢复,我们尝试了从重启驱动来恢复,但是失败了,因为设备没有,驱动重启也是没有用的。
分析二,liunx系统的节电处理,会将长期不交互的usb设备挂起(断电),从而设备丢失
后来,分别联系了屏幕和树莓派的厂家,屏幕的功能正常(在windows下测试一直正常),又联系了树莓派的买家和厂家,厂家说他们之前也遇到过一起类似的情况,liunx下打印机长时间连接失效了,后来分析是系统的节电处理,给usb设备断电了,但是具体的解决方法厂家人员没有提供,后来几经查找,发现一下方法可以解决问题:
查看usb设备,找出对应的屏幕信息
sudo lsusb -v
得到如下信息:
Bus 003 Device 010: ID 27c6:0529
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 0
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x27c6
idProduct 0x0529
bcdDevice 1.02
iManufacturer 1 WingCool Inc.
iProduct 2 TouchScreen
iSerial 3 9LQ0172005164
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 0x005b
bNumInterfaces 3
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
(Bus Powered)
MaxPower 200mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 0
bInterfaceProtocol 0
iInterface 0
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.10
bCountryCode 0 Not supported
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 691
Report Descriptors:
** UNAVAILABLE **
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 1
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 0
bInterfaceProtocol 0
iInterface 0
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.10
bCountryCode 33 US
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 38
Report Descriptors:
** UNAVAILABLE **
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 1
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 2
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 0
bInterfaceProtocol 0
iInterface 0
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.10
bCountryCode 0 Not supported
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 80
Report Descriptors:
** UNAVAILABLE **
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 1
can't get debug descriptor: Resource temporarily unavailable
Device Status: 0x0000
(Bus Powered)
从中提取对应的设备id和产品id,以备后用:
idVendor 0x27c6
idProduct 0x0529
在命令终端中,现在输入以下命令:
sudo vim /etc/udev/rules.d/usb-power.rules
添加如下内容:
# Microsoft Corp. Wheel Mouse Optical
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="27c6", ATTR{idProduct}=="0529", TEST=="power/control", ATTR{power/control}="on"
请注意:虽然lsusb报告带有 0x前缀的十六进制供应商和产品 ID,但语法udev rules不允许前导,0x即使 ID 号仍以十六进制指定。我的 usb-power.rules文件只有一行注释和一行代码。
重启并检查
$ cat /sys/bus/usb/devices/usb8/8-1/power/control
on
再次检查,usb未断电,屏幕功能正常。