Bug 9205

Summary: Add functionality to the formfactor to check for keyboard and/or touchscreen
Product: [Build System, Metadata & Runtime] OE-Core Reporter: Saul Wold <sgw>
Component: configurationAssignee: Jianxun Zhang <jianxun.zhang>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: Medium    
Version: 2.2   
Target Milestone: 2.2   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: New (Never tested)
Verified: Documentation change: Don't know
Bug Depends on:    
Bug Blocks: 6362    
Attachments:
Description Flags
machconfig supports USBHID keyboard and touchscreen
none
machconfig supports USBHID keyboard and touchscreen
none
Patch submitted to meta-intel
none
Patch submitted to meta-intel [V2] none

Description Saul Wold 2016-03-03 15:53:13 UTC
Use some runtime checking in the formfactor's config script in order to determine if a keyboard or touchscreen exist.

It could be something like: lsusb | grep -i keyboard, but there will be edge cases so additional framework would be required around this.
Comment 1 Jianxun Zhang 2016-03-08 00:49:09 UTC
Saul,
I suggest to have another discussion with you for this ticket because I am not very clear about what we want to achieve at this point from the description:

() Could we have a concrete use case for this feature? For example, is it for dynamic switching between a soft keyboard and any physical board in matchbox GUI?

() Do we have a formfactor config script in OE or BSP layers already?

I vaguely feel we could have to dig more in "framework" beyond a single line with grep, but really need your input first.

Thanks lot!
Comment 2 Saul Wold 2016-03-09 23:08:02 UTC
> () Could we have a concrete use case for this feature? For example, is it for 
dynamic switching between a soft keyboard
>  and any physical board in matchbox GUI?
This is for initial detection of keyboard vs use of softkeyboard, it is not 
meand for Dynamic Switching.

> () Do we have a formfactor config script in OE or BSP layers already?
The original script is part of OE-Core in the meta/recipes-bsp/formfactor

> I vaguely feel we could have to dig more in "framework" beyond a single line 
with grep, but really need your input first.
Comment 3 Jianxun Zhang 2016-03-28 22:46:48 UTC
Saul,

I got some data for a solution but also with its limitation and some assumptions. Let me know you if you agree to move forward based on these info.

ASSUMPTION:
() Only USB keyboard and touchscreen devices compliant with USB HID class are going to be supported. Devices designed not on USB bus are not supported. If you think USB HID cannot cover all devices you need, stop reading here.

() The config script MUST be run as root. Information of device usage (keyboard, mouse, touch screen.. etc) packed in HID report descriptor is not available once driver is _binded_ to interface. To get info a, _unbind_ operation must be performed with root permission via sysfs, regardless usb tools you want to call in the config script.

Unbinding will lose device functionality until another _bind_ is issued to kernel. This period should be very short when just getting descriptors so it shouldn't cause any problem to user.

PROBLEM:
There are two properties in matchbox cannot be mapped with any fields USB HID spec: HAVE_KEYBOARD_PORTRAIT and HAVE_KEYBOARD_LANDSCAPE. They seem to define the launching behavior of matchbox. I am not sure if they are really related to physical keyboard's existence, or merely as preference of UI style. (Checking matchbox expert is another option). I also assume what we should patch is the variable HAVE_KEYBOARD in config script.

POSSIBLE SOLUTION:
If you agree the above assumptions/limitations, I think I have a way to query device usage in config script by calling usbhid-dump. lsusb requires multiple steps to search, bind/unbind HID devices. usbhid-dump is much more straightforward for our purpose and I have figured out how to extract usage byte from its hex dump.

Document carrying info about HAVE_KEYBOARD and HAVE_TOUCHSCREEN should be updated with runtime-checking change.

Let me know your thoughts.

Thanks
Comment 4 Jianxun Zhang 2016-03-29 23:21:24 UTC
The above solution based (also limited) on USB will miss input devices on other buses like PS/2 keyboard/mouse on i8042 controller in real world. My lenovo X220 laptop device has both a USB-HID compliant touch screen and a physical keyboard on i8042. We will need a consolidated solution or querying extra bus types to cover all of these devices.
Comment 5 Jianxun Zhang 2016-03-30 19:30:17 UTC
Created attachment 3073 [details]
machconfig supports USBHID keyboard and touchscreen

Saul,
I attached a crafted machconfig supporting USBHID keyboard and touchscreen. It could miss some cases when grep output from usbhid-dump. But it should be good for a prototype test:

() flash a USB stick with a sato-sdk image (mine is built for intel-corei7-64). No extra patch or change in build

() mount usb stick to your host and copy attached machconfig to /etc/formfactor/

() maybe you need to add exec permission on new copied file (?)

() sync and eject usb stick, now it is ready to test

() Boot it up on target, expected results are:

If you don't plug generic USB keyboard, terminal app in GUI will show up soft keypad. It should not show keypad if there is a USB keyboard connected when boot.

If you have a USB touchscreen connected to target when boot, cursor on GUI will not be shown. Otherwise, a mouse cursor should appear on screen. (I tested on a Lenovo X220 which has a USB touch screen)
Comment 6 Saul Wold 2016-04-06 21:43:54 UTC
I think we can focus on USB type of devices and not worry so much about legacy 
devices.

Will this work with devices like the Logitech Unifing device which can talk 
with both Keyboards and mice.

We also might need to consider BT type of keyboard or mouse, but that can be 
for later.
Comment 7 Jianxun Zhang 2016-04-11 23:11:44 UTC
Saul,
Thanks to let me know our short-term decision. Just some thoughts for your comment.

() I am not sure BT input devices because these wireless gadgets may not be so "permanently available" as wired ones in embedded world. You may want to look a true real auto-switching for this part.

() Just a clarification for mice. I don't think I see its support in config script. Does poky have a HAVE_MOUSE variable?

() Based on descriptors of Logitech device you sent to me, it seems to still have two standalone input devices instead of a device with two usages indicated in spec. We could have uncovered corner cases but I don't have such combo device either. We can fix this later though.

I will refactor the patch for robustness and submit it.

Thanks!
Comment 8 Jianxun Zhang 2016-04-12 23:55:37 UTC
Created attachment 3122 [details]
machconfig supports USBHID keyboard and touchscreen

upload a refactored version
Comment 9 Jianxun Zhang 2016-04-15 21:02:02 UTC
Created attachment 3128 [details]
Patch submitted to meta-intel

This patch (V1) has been submitted to mailing list meta-intel.
Comment 10 Jianxun Zhang 2016-06-08 16:55:45 UTC
Created attachment 3220 [details]
Patch submitted to meta-intel [V2]

Submitted V2 to meta-intel mailing list to address sudo issue.
Comment 11 Jianxun Zhang 2016-06-24 23:07:42 UTC
http://git.yoctoproject.org/cgit/cgit.cgi/meta-intel/commit/?id=eaadd02702da260cea0cb0728374ba0216f1336e

Patch has been merged to meta-intel today.

For validation (sato image):
() build sato image with common x86 machines in meta-intel, like intel-corei7-64. (Note if you choose other machines, they may have a formfactor config that will override this change by design.)

Boot device into matchbox GUI and open "Terminal" application.
() Keyboard
If you boot device without any USB HID device connected, the softkeypad shall be shown.
If you boot device with a USB HID keyboard connected, the softkeypad shall NOT be shown.

() Touch screen. You will need a machine that has an USB HID touchscreen connected, like Lenovo X220 or X230.
Follow the same procedure to build sato and boot device into GUI. The mouse cursor shall not appear since touchscreen exists (This is my understanding). For devices without USB HID touch screen, mouse cursor shall work as usual.