1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #include "port.h"
- #include "mousepipe.h"
- #if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
- #include "esp32-hal-log.h"
- #else
- #include "esp_log.h"
- #endif
- #include "parse_hid.h"
- #define DEVICE_ADDRESS 2
- USBHostMouse port(2);
- extern void parse_hid_report_map(uint8_t *map, size_t size);
- void usbh_mouse_device_ready()
- {
- port.setIdle();
- port.getHidReportMap();
- }
- void ctrl_pipe_cb(ext_pipe_event_msg_t event, usb_irp_t *irp)
- {
- Serial.printf("CTRL EVENT: 0x%x\n", event);
- if (event == 0xA206)
- {
- port.inpipe->inData();
- }
- }
- static void hid_datain_cb(ext_pipe_event_msg_t event, usb_irp_t *irp)
- {
- switch (event)
- {
- case HCD_PIPE_EVENT_IRP_DONE:
- ESP_LOGD("Pipe cdc: ", "XFER status: %d, num bytes: %d, actual bytes: %d", irp->status, irp->num_bytes, irp->actual_num_bytes);
-
- ESP_LOGI("", "HID REPORT ID: %d", irp->data_buffer[0]);
- ESP_LOGI("", "Mouse buttons: %d", irp->data_buffer[1]);
- ESP_LOGI("", "X axis(raw bytes): %i", (int8_t)irp->data_buffer[2]);
- ESP_LOGI("", "Y axis(raw bytes): %i", (int8_t)irp->data_buffer[4]);
- ESP_LOGI("", "Mouse wheel: %i\n", (int8_t)irp->data_buffer[5]);
-
-
-
-
- break;
- }
- }
- void port_cb(port_event_msg_t msg, USBHostPort *port)
- {
- Serial.printf("PORT EVENT: 0x%x\n", msg.port_event);
- }
- void setup()
- {
- Serial.begin(115200);
- if(port.init()){
- port.onPortEvent(port_cb);
- port.onControlEvent(ctrl_pipe_cb);
- port.onDataIn(hid_datain_cb);
- }
- }
- void loop()
- {
- delay(1000);
-
-
-
-
- }
|