项目作者: chegewara

项目描述 :
ESP32S2 native USB library. Implemented few common classes, like MIDI, CDC, HID or DFU (update).
高级语言: C++
项目地址: git://github.com/chegewara/EspTinyUSB.git
创建时间: 2020-07-18T14:07:12Z
项目社区:https://github.com/chegewara/EspTinyUSB

开源协议:MIT License

下载


New version

New version of library, compatible with esp-idf (after cleanup) can be find here:

https://github.com/chegewara/esp32-usb-v2

Description

Library allows to build USB class devices and to make it usable with minimal effort:

  • CDC, communication device class,
  • MSC, mass storage class,
  • HID, human interface device class: keyboard, mouse, gamepad, generic IN/OUT,
  • MIDI, musical instrument digital interface class,
  • DFU, device firmware update class,
  • WebUSB, its using vendor class to show webusb usage.

Hardware

To use native USB we need to connect pins 19 and 20 to usb cable or with similar connectors:

How to

Library allows to set all values in standard USB device like:

  • manufacturer
  • product name
  • serial number
  • revision
  • VID and PID
  1. ANYusb device; // any USB class like HID, MSC, CDC
  2. device.manufacturer(char*);
  3. device.product(char*); // product name
  4. device.serial(char*); // serial number SN
  5. device.revision(uint16_t); // product revison
  6. device.deviceID(uint16_t VID, uint16_t PID);
  7. device.deviceID(uint16_t* VID, uint16_t* PID);

Default EP numbers

In case of using more than 1 USB class in 1 device please make sure there is no conflict between EP numbers and eventuallu use setBaseEP:

  • CDC - EP1 and EP2,
  • HID - keyboard - EP2, mouse - EP3,
  • MSC - EP4,
  • WebUSB - EP4,
  • MIDI - EP5
  • DFU - not required

Contributions

Issues and PRs are welcome.

USB host (WIP)

I have some basic implementation of USB host which i decided to add. This is still experimental version as i dont know what tpe of design to implement (events or callbacks).

Here is log from MSC host reading files from pendrive:

  1. [ 960][I][test.ino:86] client_event_callback(): device speed: USB_SPEED_FULL, device address: 1, max ep_ctrl size: 64, config: 1
  2. EP num: 1/2, len: 32, address: 0x81, EP max size: 64, dir: IN
  3. EP num: 2/2, len: 32, address: 0x02, EP max size: 64, dir: OUT
  4. capacity_cb: block_size: 512, block_count: 60948479
  5. inquiry_cb
  6. [ 1038][I][test.ino:221] write_test(): File written
  7. [ 1049][I][test.ino:149] read_test(): /msc/README.txt
  8. [ 1051][I][test.ino:159] read_test(): Hello World!
  9. [ 1055][I][test.ino:205] read_test(): Found file : /msc/fanet_module.pdf (735686 bytes)
  10. [ 1056][I][test.ino:205] read_test(): Found file : /msc/06639_datasheet.pdf (205240 bytes)
  11. [ 1063][I][test.ino:205] read_test(): Found file : /msc/Bluetooth_5-FINAL.pdf (2100903 bytes)
  12. [ 1072][I][test.ino:205] read_test(): Found file : /msc/USB-Basics-USB-2.0-.pdf (113669 bytes)
  13. [ 1080][I][test.ino:205] read_test(): Found file : /msc/DS_SX1280-1_V2.2.book.pdf (197260 bytes)
  14. [ 1096][I][test.ino:205] read_test(): Found file : /msc/USB-Basics-USB-2.0- (1).pdf (113669 bytes)
  15. [ 1102][I][test.ino:205] read_test(): Found file : /msc/USB---Enumeration-States.pdf (29098 bytes)
  16. [ 1110][I][test.ino:205] read_test(): Found file : /msc/USB---Protocol---bits4device.pdf (1022853 bytes)
  17. [ 1125][I][test.ino:205] read_test(): Found file : /msc/esp32-s2_technical_reference_manual_en.pdf (6769251 bytes)
  18. [ 1132][I][test.ino:205] read_test(): Found file : /msc/cd00167594-stm32-microcontroller-system-memory-boot-mode-stmicroelectronics.pdf (4613315 bytes)
  19. [ 1146][I][test.ino:205] read_test(): Found file : /msc/USB Complete The Developer's Guide 4th Ed.pdf (6936935 bytes)
  20. [ 1161][I][test.ino:205] read_test(): Found file : /msc/USB Mass Storage Designing and Programming Devices and Embedded Hosts.pdf (3360734 bytes)
  21. [ 1173][I][test.ino:205] read_test(): Found file : /msc/README.txt (13 bytes)
  22. [ 1181][I][test.ino:233] write_test(): Renaming file
  23. [ 1212][I][test.ino:240] write_test(): Reading file
  24. [ 1225][I][test.ino:254] write_test(): Read from file /msc/README1.txt: 'Hello World!'
  25. [ 1233][E][test.ino:145] read_test(): Failed to open file
  26. [ 1237][I][test.ino:205] read_test(): Found file : /msc/fanet_module.pdf (735686 bytes)
  27. [ 1238][I][test.ino:205] read_test(): Found file : /msc/06639_datasheet.pdf (205240 bytes)
  28. [ 1245][I][test.ino:205] read_test(): Found file : /msc/Bluetooth_5-FINAL.pdf (2100903 bytes)
  29. [ 1253][I][test.ino:205] read_test(): Found file : /msc/USB-Basics-USB-2.0-.pdf (113669 bytes)
  30. [ 1262][I][test.ino:205] read_test(): Found file : /msc/DS_SX1280-1_V2.2.book.pdf (197260 bytes)
  31. [ 1278][I][test.ino:205] read_test(): Found file : /msc/USB-Basics-USB-2.0- (1).pdf (113669 bytes)
  32. [ 1284][I][test.ino:205] read_test(): Found file : /msc/USB---Enumeration-States.pdf (29098 bytes)
  33. [ 1292][I][test.ino:205] read_test(): Found file : /msc/USB---Protocol---bits4device.pdf (1022853 bytes)
  34. [ 1307][I][test.ino:205] read_test(): Found file : /msc/esp32-s2_technical_reference_manual_en.pdf (6769251 bytes)
  35. [ 1314][I][test.ino:205] read_test(): Found file : /msc/cd00167594-stm32-microcontroller-system-memory-boot-mode-stmicroelectronics.pdf (4613315 bytes)
  36. [ 1327][I][test.ino:205] read_test(): Found file : /msc/USB Complete The Developer's Guide 4th Ed.pdf (6936935 bytes)
  37. [ 1342][I][test.ino:205] read_test(): Found file : /msc/USB Mass Storage Designing and Programming Devices and Embedded Hosts.pdf (3360734 bytes)
  38. [ 1352][I][test.ino:205] read_test(): Found file : /msc/README1.txt (13 bytes)
  39. [ 1352][I][test.ino:289] setup(): storage used: 26329088/31189319680