-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUSB.ino
66 lines (57 loc) · 1.71 KB
/
USB.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <ESP32-USB-Soft-Host.h>
#define DP_P0 16 // Pin "RX2" en el ESP32 DEVKIT V1, conectar al pin D+ del conector USB
#define DM_P0 17 // Pin "TX2" en el ESP32 DEVKIT V1, conectar al pin D- del conector USB
#define LED 2 // LED azul integrado en el ESP32 DEVKIT V1
usb_pins_config_t USB_Pins_Config =
{
DP_P0, DM_P0,
-1, -1,
-1, -1,
-1, -1
};
static void my_USB_DetectCB(uint8_t usbNum, void * dev)
{
sDevDesc *device = (sDevDesc*)dev;
Serial.printf("New device detected on USB#%d\n", usbNum);
Serial.printf("Vendor ID: 0x%04x, Product ID: 0x%04x\n", device->idVendor, device->idProduct);
}
/*static void my_USB_PrintCB(uint8_t usbNum, uint8_t byte_depth, uint8_t* data, uint8_t data_len)
{
Serial.print("Received data: ");
for(int i = 0; i < data_len; i++)
{
Serial.printf("0x%02x ", data[i]);
}
Serial.println();
}*/
static void my_USB_PrintCB(uint8_t usbNum, uint8_t byte_depth, uint8_t* data, uint8_t data_len)
{
digitalWrite(LED, 1);
Serial.print("Received data: ");
for(int i = 0; i < data_len; i++)
{
for(int bit = 7; bit >= 0; bit--)
{
Serial.print((data[i] >> bit) & 0x01);
}
Serial.print(" ");
}
Serial.println();
digitalWrite(LED, 0);
}
void setup()
{
pinMode(LED, OUTPUT);
Serial.begin(9600);
delay(5000);
Serial.println("Initializing USB Host");
USH.setOnConfigDescCB(Default_USB_ConfigDescCB);
USH.setOnIfaceDescCb(Default_USB_IfaceDescCb);
USH.setOnHIDDevDescCb(Default_USB_HIDDevDescCb);
USH.setOnEPDescCb(Default_USB_EPDescCb);
USH.init(USB_Pins_Config, my_USB_DetectCB, my_USB_PrintCB);
}
void loop()
{
// Nada que hacer en el loop principal - las tareas principales se realizan en segundo plano, en el núcleo #1 del ESP
}