test_usb_mock_hid.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <inttypes.h>
  7. #include <stdbool.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include "usb/usb_types_ch9.h"
  11. #include "test_usb_mock_hid.h"
  12. // ---------------------------------------------------- HID Mouse ------------------------------------------------------
  13. const usb_ep_desc_t mock_hid_mouse_in_ep_desc = {
  14. .bLength = sizeof(usb_ep_desc_t),
  15. .bDescriptorType = USB_B_DESCRIPTOR_TYPE_ENDPOINT,
  16. .bEndpointAddress = MOCK_HID_MOUSE_INTR_IN_EP_ADDR, //EP 1 IN
  17. .bmAttributes = USB_BM_ATTRIBUTES_XFER_INT,
  18. .wMaxPacketSize = MOCK_HID_MOUSE_INTR_IN_MPS,
  19. .bInterval = 10, //Interval of 10ms
  20. };
  21. void mock_hid_process_report(mock_hid_mouse_report_t *report, int iter)
  22. {
  23. static int x_pos = 0;
  24. static int y_pos = 0;
  25. //Update X position
  26. if (report->x_movement & 0x80) { //Positive movement
  27. x_pos += report->x_movement & 0x7F;
  28. } else { //Negative movement
  29. x_pos -= report->x_movement & 0x7F;
  30. }
  31. //Update Y position
  32. if (report->y_movement & 0x80) { //Positive movement
  33. y_pos += report->y_movement & 0x7F;
  34. } else { //Negative movement
  35. y_pos -= report->y_movement & 0x7F;
  36. }
  37. printf("\rX:%d\tY:%d\tIter: %d\n", x_pos, y_pos, iter);
  38. }