test_ite_keyboard.py 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #!/bin/env python3
  2. # SPDX-License-Identifier: GPL-2.0
  3. # -*- coding: utf-8 -*-
  4. #
  5. # Copyright (c) 2020 Benjamin Tissoires <benjamin.tissoires@gmail.com>
  6. # Copyright (c) 2020 Red Hat, Inc.
  7. #
  8. from .test_keyboard import ArrayKeyboard, TestArrayKeyboard
  9. from hidtools.util import BusType
  10. import libevdev
  11. import logging
  12. logger = logging.getLogger("hidtools.test.ite-keyboard")
  13. KERNEL_MODULE = ("itetech", "hid_ite")
  14. class KbdData(object):
  15. pass
  16. # The ITE keyboards have an issue regarding the Wifi key:
  17. # nothing comes in when pressing the key, but we get a null
  18. # event on the key release.
  19. # This test covers this case.
  20. class ITEKeyboard(ArrayKeyboard):
  21. # fmt: off
  22. report_descriptor = [
  23. 0x06, 0x85, 0xff, # Usage Page (Vendor Usage Page 0xff85)
  24. 0x09, 0x95, # Usage (Vendor Usage 0x95) 3
  25. 0xa1, 0x01, # Collection (Application) 5
  26. 0x85, 0x5a, # .Report ID (90) 7
  27. 0x09, 0x01, # .Usage (Vendor Usage 0x01) 9
  28. 0x15, 0x00, # .Logical Minimum (0) 11
  29. 0x26, 0xff, 0x00, # .Logical Maximum (255) 13
  30. 0x75, 0x08, # .Report Size (8) 16
  31. 0x95, 0x10, # .Report Count (16) 18
  32. 0xb1, 0x00, # .Feature (Data,Arr,Abs) 20
  33. 0xc0, # End Collection 22
  34. 0x05, 0x01, # Usage Page (Generic Desktop) 23
  35. 0x09, 0x06, # Usage (Keyboard) 25
  36. 0xa1, 0x01, # Collection (Application) 27
  37. 0x85, 0x01, # .Report ID (1) 29
  38. 0x75, 0x01, # .Report Size (1) 31
  39. 0x95, 0x08, # .Report Count (8) 33
  40. 0x05, 0x07, # .Usage Page (Keyboard) 35
  41. 0x19, 0xe0, # .Usage Minimum (224) 37
  42. 0x29, 0xe7, # .Usage Maximum (231) 39
  43. 0x15, 0x00, # .Logical Minimum (0) 41
  44. 0x25, 0x01, # .Logical Maximum (1) 43
  45. 0x81, 0x02, # .Input (Data,Var,Abs) 45
  46. 0x95, 0x01, # .Report Count (1) 47
  47. 0x75, 0x08, # .Report Size (8) 49
  48. 0x81, 0x03, # .Input (Cnst,Var,Abs) 51
  49. 0x95, 0x05, # .Report Count (5) 53
  50. 0x75, 0x01, # .Report Size (1) 55
  51. 0x05, 0x08, # .Usage Page (LEDs) 57
  52. 0x19, 0x01, # .Usage Minimum (1) 59
  53. 0x29, 0x05, # .Usage Maximum (5) 61
  54. 0x91, 0x02, # .Output (Data,Var,Abs) 63
  55. 0x95, 0x01, # .Report Count (1) 65
  56. 0x75, 0x03, # .Report Size (3) 67
  57. 0x91, 0x03, # .Output (Cnst,Var,Abs) 69
  58. 0x95, 0x06, # .Report Count (6) 71
  59. 0x75, 0x08, # .Report Size (8) 73
  60. 0x15, 0x00, # .Logical Minimum (0) 75
  61. 0x26, 0xff, 0x00, # .Logical Maximum (255) 77
  62. 0x05, 0x07, # .Usage Page (Keyboard) 80
  63. 0x19, 0x00, # .Usage Minimum (0) 82
  64. 0x2a, 0xff, 0x00, # .Usage Maximum (255) 84
  65. 0x81, 0x00, # .Input (Data,Arr,Abs) 87
  66. 0xc0, # End Collection 89
  67. 0x05, 0x0c, # Usage Page (Consumer Devices) 90
  68. 0x09, 0x01, # Usage (Consumer Control) 92
  69. 0xa1, 0x01, # Collection (Application) 94
  70. 0x85, 0x02, # .Report ID (2) 96
  71. 0x19, 0x00, # .Usage Minimum (0) 98
  72. 0x2a, 0x3c, 0x02, # .Usage Maximum (572) 100
  73. 0x15, 0x00, # .Logical Minimum (0) 103
  74. 0x26, 0x3c, 0x02, # .Logical Maximum (572) 105
  75. 0x75, 0x10, # .Report Size (16) 108
  76. 0x95, 0x01, # .Report Count (1) 110
  77. 0x81, 0x00, # .Input (Data,Arr,Abs) 112
  78. 0xc0, # End Collection 114
  79. 0x05, 0x01, # Usage Page (Generic Desktop) 115
  80. 0x09, 0x0c, # Usage (Wireless Radio Controls) 117
  81. 0xa1, 0x01, # Collection (Application) 119
  82. 0x85, 0x03, # .Report ID (3) 121
  83. 0x15, 0x00, # .Logical Minimum (0) 123
  84. 0x25, 0x01, # .Logical Maximum (1) 125
  85. 0x09, 0xc6, # .Usage (Wireless Radio Button) 127
  86. 0x95, 0x01, # .Report Count (1) 129
  87. 0x75, 0x01, # .Report Size (1) 131
  88. 0x81, 0x06, # .Input (Data,Var,Rel) 133
  89. 0x75, 0x07, # .Report Size (7) 135
  90. 0x81, 0x03, # .Input (Cnst,Var,Abs) 137
  91. 0xc0, # End Collection 139
  92. 0x05, 0x88, # Usage Page (Vendor Usage Page 0x88) 140
  93. 0x09, 0x01, # Usage (Vendor Usage 0x01) 142
  94. 0xa1, 0x01, # Collection (Application) 144
  95. 0x85, 0x04, # .Report ID (4) 146
  96. 0x19, 0x00, # .Usage Minimum (0) 148
  97. 0x2a, 0xff, 0xff, # .Usage Maximum (65535) 150
  98. 0x15, 0x00, # .Logical Minimum (0) 153
  99. 0x26, 0xff, 0xff, # .Logical Maximum (65535) 155
  100. 0x75, 0x08, # .Report Size (8) 158
  101. 0x95, 0x02, # .Report Count (2) 160
  102. 0x81, 0x02, # .Input (Data,Var,Abs) 162
  103. 0xc0, # End Collection 164
  104. 0x05, 0x01, # Usage Page (Generic Desktop) 165
  105. 0x09, 0x80, # Usage (System Control) 167
  106. 0xa1, 0x01, # Collection (Application) 169
  107. 0x85, 0x05, # .Report ID (5) 171
  108. 0x19, 0x81, # .Usage Minimum (129) 173
  109. 0x29, 0x83, # .Usage Maximum (131) 175
  110. 0x15, 0x00, # .Logical Minimum (0) 177
  111. 0x25, 0x01, # .Logical Maximum (1) 179
  112. 0x95, 0x08, # .Report Count (8) 181
  113. 0x75, 0x01, # .Report Size (1) 183
  114. 0x81, 0x02, # .Input (Data,Var,Abs) 185
  115. 0xc0, # End Collection 187
  116. ]
  117. # fmt: on
  118. def __init__(
  119. self,
  120. rdesc=report_descriptor,
  121. name=None,
  122. input_info=(BusType.USB, 0x06CB, 0x2968),
  123. ):
  124. super().__init__(rdesc, name, input_info)
  125. def event(self, keys, reportID=None, application=None):
  126. application = application or "Keyboard"
  127. return super().event(keys, reportID, application)
  128. class TestITEKeyboard(TestArrayKeyboard):
  129. kernel_modules = [KERNEL_MODULE]
  130. def create_device(self):
  131. return ITEKeyboard()
  132. def test_wifi_key(self):
  133. uhdev = self.uhdev
  134. syn_event = self.syn_event
  135. # the following sends a 'release' event on the Wifi key.
  136. # the kernel is supposed to translate this into Wifi key
  137. # down and up
  138. r = [0x03, 0x00]
  139. uhdev.call_input_event(r)
  140. expected = [syn_event]
  141. expected.append(libevdev.InputEvent(libevdev.EV_KEY.KEY_RFKILL, 1))
  142. events = uhdev.next_sync_events()
  143. self.debug_reports([r], uhdev, events)
  144. self.assertInputEventsIn(expected, events)
  145. expected = [syn_event]
  146. expected.append(libevdev.InputEvent(libevdev.EV_KEY.KEY_RFKILL, 0))
  147. # the kernel sends the two down/up key events in a batch, no need to
  148. # call events = uhdev.next_sync_events()
  149. self.debug_reports([], uhdev, events)
  150. self.assertInputEventsIn(expected, events)