You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
4.4KB

  1. #-
  2. # Copyright (c) 2019 Vladimir Kondratyev
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions
  6. # are met:
  7. # 1. Redistributions of source code must retain the above copyright
  8. # notice, this list of conditions and the following disclaimer.
  9. # 2. Redistributions in binary form must reproduce the above copyright
  10. # notice, this list of conditions and the following disclaimer in the
  11. # documentation and/or other materials provided with the distribution.
  12. #
  13. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  14. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  16. # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  17. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  18. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  19. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  20. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  22. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  23. # SUCH DAMAGE.
  24. #
  25. # $FreeBSD$
  26. #
  27. #include <sys/bus.h>
  28. #include "hidbus.h"
  29. INTERFACE hid;
  30. # Interrupts interface
  31. #
  32. # Allocate memory and initialise interrupt transfers.
  33. # This function can sleep or block waiting for resources to become available.
  34. # intr callback function which is called if input data is available.
  35. # context is the private softc pointer, which will be used to callback.
  36. # mtx is the private mutex protecting the transfer structure and the softc.
  37. # This function returns zero upon success. A non-zero return value indicates
  38. # failure.
  39. #
  40. METHOD void intr_setup {
  41. device_t dev;
  42. struct mtx *lock;
  43. hid_intr_t intr;
  44. void *context;
  45. };
  46. #
  47. # Release all allocated resources associated with interrupt transfers.
  48. # This function can sleep waiting for transfers to complete.
  49. # It is not allowed to call this function from the interrupt callback.
  50. #
  51. METHOD void intr_unsetup {
  52. device_t dev;
  53. };
  54. #
  55. # Start the interrupt transfers if not already started. This function is always
  56. # non-blocking and must be called with the so-called private USB mutex locked.
  57. #
  58. METHOD int intr_start {
  59. device_t dev;
  60. };
  61. #
  62. # Stop the interrupt transfers if not already stopped. This function is always
  63. # non-blocking and must be called with the so-called private USB mutex locked.
  64. #
  65. METHOD int intr_stop {
  66. device_t dev;
  67. };
  68. #
  69. # The following function gets called from the HID keyboard driver
  70. # when the system has paniced.
  71. #
  72. METHOD void intr_poll {
  73. device_t dev;
  74. };
  75. # HID interface
  76. #
  77. # Read out an report descriptor from the HID device.
  78. #
  79. METHOD int get_report_descr {
  80. device_t dev;
  81. void **data;
  82. uint16_t *len;
  83. };
  84. #
  85. # Get input data from the device. Data should be read in chunks
  86. # of the size prescribed by the report descriptor.
  87. #
  88. METHOD int read {
  89. device_t dev;
  90. void *data;
  91. uint16_t maxlen;
  92. uint16_t *actlen;
  93. };
  94. #
  95. # Send data to the device. Data should be written in
  96. # chunks of the size prescribed by the report descriptor.
  97. #
  98. METHOD int write {
  99. device_t dev;
  100. void *data;
  101. uint16_t len;
  102. };
  103. #
  104. # Get a report from the device without waiting for data on the interrupt.
  105. # Copies a maximum of len bytes of the report data into the memory specified
  106. # by data. Upon return actlen is set to the number of bytes copied. The type
  107. # field indicates which report is requested. It should be HID_INPUT_REPORT,
  108. # HID_OUTPUT_REPORT, or HID_FEATURE_REPORT. This call may fail if the device
  109. # does not support this feature.
  110. #
  111. METHOD int get_report {
  112. device_t dev;
  113. void *data;
  114. uint16_t maxlen;
  115. uint16_t *actlen;
  116. uint8_t type;
  117. uint8_t id;
  118. };
  119. #
  120. # Set a report in the device. The type field indicates which report is to be
  121. # set. It should be HID_INPUT_REPORT, HID_OUTPUT_REPORT, or HID_FEATURE_REPORT.
  122. # The value of the report is specified by the data and the len fields.
  123. # This call may fail if the device does not support this feature.
  124. #
  125. METHOD int set_report {
  126. device_t dev;
  127. void *data;
  128. uint16_t len;
  129. uint8_t type;
  130. uint8_t id;
  131. };
  132. #
  133. # Set duration between input reports (in mSec).
  134. #
  135. METHOD int set_idle {
  136. device_t dev;
  137. uint16_t duration;
  138. uint8_t id;
  139. };
  140. #
  141. # Switch between the boot protocol and the report protocol (or vice versa).
  142. #
  143. METHOD int set_protocol {
  144. device_t dev;
  145. uint16_t protocol;
  146. };