test_usb_mock_hid.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /*
  7. This header contains bare-bone mock implementations of some device classes in order to test various layers of the USB
  8. Host stack.
  9. */
  10. #pragma once
  11. #include <stdint.h>
  12. #include <stdbool.h>
  13. #include "esp_assert.h"
  14. #include "usb/usb_types_ch9.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. // ---------------------------------------------------- HID Mouse ------------------------------------------------------
  19. /*
  20. Note: The mock HID mouse tests require that USB low speed mouse be connected. The mouse should...
  21. - Be implement the HID with standard report format used by mice
  22. - It's configuration 1 should have the following endpoint
  23. ------------------ Configuration Descriptor -------------------
  24. bLength : 0x09 (9 bytes)
  25. bDescriptorType : 0x02 (Configuration Descriptor)
  26. wTotalLength : 0x003B (59 bytes)
  27. bNumInterfaces : 0x02 (2 Interfaces)
  28. bConfigurationValue : 0x01 (Configuration 1)
  29. iConfiguration : 0x00 (No String Descriptor)
  30. bmAttributes : 0xA0
  31. D7: Reserved, set 1 : 0x01
  32. D6: Self Powered : 0x00 (no)
  33. D5: Remote Wakeup : 0x01 (yes)
  34. D4..0: Reserved, set 0 : 0x00
  35. MaxPower : 0x32 (100 mA)
  36. Data (HexDump) : 09 02 3B 00 02 01 00 A0 32 09 04 00 00 01 03 01
  37. 02 00 09 21 00 02 00 01 22 4D 00 07 05 81 03 08
  38. 00 0A 09 04 01 00 01 03 01 01 00 09 21 00 02 00
  39. 01 22 31 00 07 05 82 03 08 00 0A
  40. ---------------- Interface Descriptor -----------------
  41. bLength : 0x09 (9 bytes)
  42. bDescriptorType : 0x04 (Interface Descriptor)
  43. bInterfaceNumber : 0x00
  44. bAlternateSetting : 0x00
  45. bNumEndpoints : 0x01 (1 Endpoint)
  46. bInterfaceClass : 0x03 (HID - Human Interface Device)
  47. bInterfaceSubClass : 0x01 (Boot Interface)
  48. bInterfaceProtocol : 0x02 (Mouse)
  49. iInterface : 0x00 (No String Descriptor)
  50. Data (HexDump) : 09 04 00 00 01 03 01 02 00
  51. ------------------- HID Descriptor --------------------
  52. bLength : 0x09 (9 bytes)
  53. bDescriptorType : 0x21 (HID Descriptor)
  54. bcdHID : 0x0200 (HID Version 2.00)
  55. bCountryCode : 0x00 (00 = not localized)
  56. bNumDescriptors : 0x01
  57. Data (HexDump) : 09 21 00 02 00 01 22 4D 00
  58. Descriptor 1:
  59. bDescriptorType : 0x22 (Class=Report)
  60. wDescriptorLength : 0x004D (77 bytes)
  61. Error reading descriptor : ERROR_INVALID_PARAMETER (due to a obscure limitation of the Win32 USB API, see UsbTreeView.txt)
  62. ----------------- Endpoint Descriptor -----------------
  63. bLength : 0x07 (7 bytes)
  64. bDescriptorType : 0x05 (Endpoint Descriptor)
  65. bEndpointAddress : 0x81 (Direction=IN EndpointID=1)
  66. bmAttributes : 0x03 (TransferType=Interrupt)
  67. wMaxPacketSize : 0x0008
  68. bInterval : 0x0A (10 ms)
  69. Data (HexDump) : 07 05 81 03 08 00 0A
  70. If you're using another mice with different endpoints, modify the endpoint descriptor below
  71. */
  72. extern const usb_ep_desc_t mock_hid_mouse_in_ep_desc;
  73. #define MOCK_HID_MOUSE_DEV_ID_VENDOR 0x03F0
  74. #define MOCK_HID_MOUSE_DEV_ID_PRODUCT 0x1198
  75. #define MOCK_HID_MOUSE_DEV_DFLT_EP_MPS 8
  76. #define MOCK_HID_MOUSE_INTF_NUMBER 0
  77. #define MOCK_HID_MOUSE_INTF_ALT_SETTING 0
  78. #define MOCK_HID_MOUSE_INTR_IN_EP_ADDR 0x81
  79. #define MOCK_HID_MOUSE_INTR_IN_MPS 8
  80. typedef union {
  81. struct {
  82. uint32_t left_button: 1;
  83. uint32_t right_button: 1;
  84. uint32_t middle_button: 1;
  85. uint32_t reserved5: 5;
  86. uint8_t x_movement;
  87. uint8_t y_movement;
  88. } __attribute__((packed));
  89. uint8_t val[3];
  90. } mock_hid_mouse_report_t;
  91. ESP_STATIC_ASSERT(sizeof(mock_hid_mouse_report_t) == 3, "Size of HID mouse report incorrect");
  92. void mock_hid_process_report(mock_hid_mouse_report_t *report, int iter);
  93. #ifdef __cplusplus
  94. }
  95. #endif