test_ite_keyboard.py 9.4 KB

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