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.

84 lines
2.9KB

  1. /* $FreeBSD$ */
  2. /*-
  3. * SPDX-License-Identifier: BSD-2-Clause-NetBSD
  4. *
  5. * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  6. * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
  7. * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. */
  30. #ifndef _HID_H_
  31. #define _HID_H_
  32. #include <dev/usb/usb.h>
  33. #include <dev/usb/usbdi.h>
  34. #include <dev/usb/usbhid.h>
  35. /* Declare parent SYSCTL USB node. */
  36. #ifdef SYSCTL_DECL
  37. SYSCTL_DECL(_hw_hid);
  38. #endif
  39. #define HID_IN_POLLING_MODE_FUNC() hid_in_polling_mode()
  40. #define HID_IN_POLLING_MODE_VALUE() (SCHEDULER_STOPPED() || kdb_active)
  41. /*
  42. * Walk through all HID items hi belonging Top Level Collection #tidx
  43. */
  44. #define HID_TLC_FOREACH_ITEM(hd, hi, tidx) \
  45. for (uint8_t _iter_##tidx = 0; hid_get_item((hd), (hi));) \
  46. if ((_iter_##tidx += \
  47. (((hi)->kind == hid_endcollection && \
  48. (hi)->collevel == 0) ? 1 : 0)) == (tidx))
  49. typedef usb_size_t hid_size_t;
  50. struct hid_absinfo {
  51. int32_t min;
  52. int32_t max;
  53. int32_t res;
  54. };
  55. /* OpenBSD/NetBSD compat shim */
  56. static __inline uint32_t
  57. hid_get_udata(const uint8_t *buf, usb_size_t len, struct hid_location *loc)
  58. {
  59. return (hid_get_data_unsigned(buf, len, loc));
  60. }
  61. /*
  62. * hid_report_size_1 is a port of userland hid_report_size() from usbhid(3)
  63. * to kernel. XXX: to be renamed back to hid_report_size()
  64. */
  65. int hid_report_size_1(const void *buf, hid_size_t len, enum hid_kind k,
  66. uint8_t id);
  67. int hid_tlc_locate(const void *desc, hid_size_t size, int32_t u,
  68. enum hid_kind k, uint8_t tlc_index, uint8_t index,
  69. struct hid_location *loc, uint32_t *flags, uint8_t *id,
  70. struct hid_absinfo *ai);
  71. int hid_in_polling_mode(void);
  72. #endif /* _HID_H_ */