2022-10-06 17:16:54 -04:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "usb/usb_types_ch9.h"
|
2024-05-06 17:17:16 -04:00
|
|
|
#include "mock_hid.h"
|
2022-10-06 17:16:54 -04:00
|
|
|
|
|
|
|
// ---------------------------------------------------- HID Mouse ------------------------------------------------------
|
|
|
|
|
|
|
|
const usb_ep_desc_t mock_hid_mouse_in_ep_desc = {
|
|
|
|
.bLength = sizeof(usb_ep_desc_t),
|
|
|
|
.bDescriptorType = USB_B_DESCRIPTOR_TYPE_ENDPOINT,
|
2024-05-06 17:17:16 -04:00
|
|
|
.bEndpointAddress = MOCK_HID_MOUSE_INTR_IN_EP_ADDR, // EP 1 IN
|
2022-10-06 17:16:54 -04:00
|
|
|
.bmAttributes = USB_BM_ATTRIBUTES_XFER_INT,
|
|
|
|
.wMaxPacketSize = MOCK_HID_MOUSE_INTR_IN_MPS,
|
2024-05-06 17:17:16 -04:00
|
|
|
.bInterval = 10, // Interval of 10ms
|
2022-10-06 17:16:54 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
void mock_hid_process_report(mock_hid_mouse_report_t *report, int iter)
|
|
|
|
{
|
|
|
|
static int x_pos = 0;
|
|
|
|
static int y_pos = 0;
|
2024-05-06 17:17:16 -04:00
|
|
|
// Update X position
|
|
|
|
if (report->x_movement & 0x80) { // Positive movement
|
2022-10-06 17:16:54 -04:00
|
|
|
x_pos += report->x_movement & 0x7F;
|
2024-05-06 17:17:16 -04:00
|
|
|
} else { // Negative movement
|
2022-10-06 17:16:54 -04:00
|
|
|
x_pos -= report->x_movement & 0x7F;
|
|
|
|
}
|
2024-05-06 17:17:16 -04:00
|
|
|
// Update Y position
|
|
|
|
if (report->y_movement & 0x80) { // Positive movement
|
2022-10-06 17:16:54 -04:00
|
|
|
y_pos += report->y_movement & 0x7F;
|
2024-05-06 17:17:16 -04:00
|
|
|
} else { // Negative movement
|
2022-10-06 17:16:54 -04:00
|
|
|
y_pos -= report->y_movement & 0x7F;
|
|
|
|
}
|
|
|
|
printf("\rX:%d\tY:%d\tIter: %d\n", x_pos, y_pos, iter);
|
|
|
|
}
|