Giter Site home page Giter Site logo

sdima1357 / esp32_usb_soft_host Goto Github PK

View Code? Open in Web Editor NEW
400.0 400.0 48.0 2.05 MB

ESP32 software USB host through general IO pins. We can connect up to 4 USB-LS HID (keyboard mouse joystick) devices simultaneously.

License: GNU Affero General Public License v3.0

Makefile 0.59% C 98.77% CMake 0.64%
board emulators esp32 esp32c3 espressif iot retrocomputing retrogaming risc-v usb usb-hid usb-host xtensa

esp32_usb_soft_host's People

Contributors

sdima1357 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

esp32_usb_soft_host's Issues

USB Mouse

Is it possible to get X and Y data from a USB Mouse?

Does it work with USB 2.0 keyboards ?

Hi,
I'm building an e-ink typewriter based on Inkplate 6 (just like the picowriter project) and just bought a USB 2.0 keyboard for that.
It's a Motospeed CK62 - was the cheapest mecanical 61 keys keyboard I found - and the manual says that it's a "USB Full Speed 2.0, support up to 1000Hz true reporting rate" whatever that means...
Do you think it could work with your software implementation ?
If so, if I understand, I would just have to buy one of those adapters and plug it into GPIO pins on the board, right ?
Thanks,
Andréas

Is ESP32 S2/S3 support realistic?

Hi and million thanks for your awesome library 👍

An idea came up while I was playing with an ESP32-C3 and esp32-arduino-lib-builder to produce a package with memory protection disabled, and accidentally built for ESP32 S2/S3 too.

Although S2/S3 already have builtin USB support, this support is limited to either host or device role, but what if esp32_usb_soft_host is used along with tinyUSB acting as a device?

I chose to focus on ESP32S2/esp32_usb_soft_host alone, I don't have a broken out ESP32-S3 and tinyUSB considerations can wait.

Adapting the code was mostly adding || defined CONFIG_IDF_TARGET_ESP32S2 to #if CONFIG_IDF_TARGET_* conditional blocks and assigning pins.

However checkPins() detection fails, and now the doubt is there 🤔

Some thoughts:

  • not sure what value to assign to BLINK_GPIO, tried the builtin led pin, scl pin, random pins and got not change
  • not sure if cpu_ll_enable_cycle_count(); is needed in function usb_process(), enabling/disabling produces no change
  • using the makeOpcodes() from ESP32 works fine, maybe ESP32S2 wants different opcodes

(In the event the situation is realistic)
Possible use cases of an ESP32S2 using esp32_usb_soft_host/tinyUSB and acting both as host+device:

  • Gaming: DIY dongle for joypad/joystick auto fire + programming
  • Security research: HID MITM keylogger, mouselogger, injector, etc
  • ...

So here's my question:

Is it a xxx limitation prevents yyy feature situation or is it worth researching further?

Thanks again for creating this project, it brought hours of fun ❤️

USB Host not working - only getting `Nack`s

Latest main doesn't seem to work on my ESP32:

esp32_usb_soft_host/usb_test$ git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean
esp32_usb_soft_host/usb_test$ idf.py set-target esp32
...

esp32_usb_soft_host/usb_test$ idf.py flash monitor
...
<several warnings, see below>
...
Hello world end!
b=0x4008ba0c
a=0x3ffafadc
c=0x3ffafb3c
setDelay =0x400d4d1c
0x400d4d1c: setDelay at esp32_usb_soft_host/usb_test/build/../main/usb_host.c:163

pins 16 17 is OK!
READ_BOTH_PINS = 0000
READ_BOTH_PINS = 0000
READ_BOTH_PINS = 0000
READ_BOTH_PINS = 0000
cpu freq = 160 MHz
TIME_MULT = 77 
D=   0 4800 bits in 1935.000000 uSec 2.480620 MHz  6 ticks in 2.418750 uS
D= 126 4800 bits in 5651.000000 uSec 0.849407 MHz  6 ticks in 7.063750 uS
D=  63 4800 bits in 3751.000000 uSec 1.279659 MHz  6 ticks in 4.688750 uS
D=  31 4800 bits in 2801.000000 uSec 1.713674 MHz  6 ticks in 3.501250 uS
D=  47 4800 bits in 3271.000000 uSec 1.467441 MHz  6 ticks in 4.088750 uS
D=  39 4800 bits in 3031.000000 uSec 1.583636 MHz  6 ticks in 3.788750 uS
D=  43 4800 bits in 3161.000000 uSec 1.518507 MHz  6 ticks in 3.951250 uS
D=  45 4800 bits in 3210.000000 uSec 1.495327 MHz  6 ticks in 4.012500 uS
D=  44 4800 bits in 3181.000000 uSec 1.508959 MHz  6 ticks in 3.976250 uS
D=  44 4800 bits in 3191.000000 uSec 1.504231 MHz  6 ticks in 3.988750 uS
TRANSMIT_TIME_DELAY = 46 time = 3.988750 error = -0.281250% 
pins -1 -1 is Errors !
pins -1 -1 is Errors !
pins -1 -1 is Errors !
USB0: Ack = 0 Nack = 0 00 pcurrent->cb_Cmd = 0  state = 0 epCount = 0
USB0: Ack = 0 Nack = 44 02 pcurrent->cb_Cmd = 2  state = 3 epCount = 0
USB0: Ack = 0 Nack = 268 02 pcurrent->cb_Cmd = 1  state = 3 epCount = 0
USB0: Ack = 0 Nack = 372 00 pcurrent->cb_Cmd = 0  state = 0 epCount = 0
USB0: Ack = 0 Nack = 372 00 pcurrent->cb_Cmd = 0  state = 0 epCount = 0
USB0: Ack = 0 Nack = 536 02 pcurrent->cb_Cmd = 2  state = 2 epCount = 0
USB0: Ack = 0 Nack = 760 02 pcurrent->cb_Cmd = 2  state = 2 epCount = 0
USB0: Ack = 0 Nack = 764 00 pcurrent->cb_Cmd = 0  state = 0 epCount = 0

I tried with a couple different USB devices and none of them worked - kept seeing only Nacks.
Any pointers on how to troubleshoot this?


I did see a lot of warnings, many about unused var, discarding volatile, and packed attribute being ignored:

[1011/1026] Building C object esp-idf/main/CMakeFiles/__idf_main.dir/usb_test.c.obj
In file included from ../main/usb_test.c:32:
../main/usb_host.h:47:1: warning: 'packed' attribute ignored [-Wattributes]
 } sDevDesc;
 ^
../main/usb_host.h:59:1: warning: 'packed' attribute ignored [-Wattributes]
 } sCfgDesc;
 ^
...
../main/usb_test.c: In function 'kscan0':
../main/usb_test.c:67:10: warning: unused variable 'unum' [-Wunused-variable]
      int unum= msg.src / 4;
          ^~~~
[1016/1026] Building C object esp-idf/main/CMakeFiles/__idf_main.dir/usb_host.c.obj
In file included from ../main/usb_host.c:22:
...
../main/usb_host.c:102:7: warning: initialization discards 'volatile' qualifier from pointer target type [-Wdiscarded-qualifiers]
      {&GPIO.out_w1tc,&GPIO.out_w1ts},
       ^
../main/usb_host.c:102:22: warning: initialization discards 'volatile' qualifier from pointer target type [-Wdiscarded-qualifiers]
      {&GPIO.out_w1tc,&GPIO.out_w1ts},
                      ^
...
../main/usb_host.c: In function 'parseImmed':
../main/usb_host.c:342:15: warning: unused variable 'sIntfCount' [-Wunused-variable]
 static int    sIntfCount   = 0;
               ^~~~~~~~~~
../main/usb_host.c:341:15: warning: unused variable 'cfgCount' [-Wunused-variable]
 static int    cfgCount   = 0;
               ^~~~~~~~
...

I tried replacing __packed with __attribute__((packed)) which made those warnings go away, but still to no avail.

Is it possible to support USB2.0 fullspeed?

Thanks to the excellent work first, it works great with legacy mouse and keyboards which have a 8-Bytes endpoint 0, but it fails when connected to a gaming keyboard with 64-Bytes endpoint 0, no device got enumerated. Is it possible to upgrade the fullspeed support? I guess it will fix the problem.

What is maximum speed?

Hey! Thank you for awesome library! What is the maximum possible speed (approximately)?

Invalid USB Packets

Thanks for this development. I have implemented your host using tobozo's arduino wrapper. As noted there, although separately quite plausible, the data for x and y are strangely inconsistent. But perhaps their apparent plausibility is misleading.

I note and respect your disclaimer re hardware debugging. I also note that I am a hobbyist rather than professional. Notwithstanding this, I'll ask a couple of questions but understand if to answer would be out of scope.

Having read the pins as you've done with PulseView, USB packets are shown to be invalid. Picture below (I can't attach the .sr file).

The setup reports "New device detected on USB#0". It also reports bDeviceClass = 0x00 and similar for each of bDeviceSubClass & bDeviceProtocol. I'll put all similar data reported from the setup below.

The mouse is labelled NextTech, model: XM5245. The main 12 pin chip is labelled: A582: 2147FS524.
Am I right in understanding that all mice are LS? How can I confirm that this one is? I've done the testing with only slight modifications to tobozo's USB_Test example.

I'd be grateful for any suggestions as to how to proceed.

desc.bcdUSB = 0x0110
desc.bDeviceClass = 0x00
desc.bDeviceSubClass = 0x00
desc.bDeviceProtocol = 0x00
desc.bMaxPacketSize0 = 0x08
desc.idVendor = 0x30fa
desc.idProduct = 0x0300
desc.bcdDevice = 0x0100
desc.iManufacturer = 0x00
desc.iProduct = 0x01
desc.iSerialNumber = 0x00
desc.bNumConfigurations = 0x01

202210033 sr

USB Host MIDI ?

Thank you sdima1357 for the great work.
Is there any chance for a MIDI class driver to be developed ?
Thank you.

A bit confused by the example

When I plug in a USB keyboard the 3 leds do come on and off briefly, which is a good sign.
But curious what this demo is doing, because it does not report any data when keys are pressed.

Is it possible to use USB from my UPS to attach it to PC via WIFI ?

I have a UPS that I want to monitor.
Where the UPS is, there is no computer to do this.
The UPS has a USB port.
Is there any way I can use ESP32 (ESP32-WROOM-32D) with this project.
To connect UPS to ESP32 with USB.
To connect the ESP32 to a wireless network.
On a computer that is in the local network to monitor this UPS.

usb printer

It may be interesting to talk to printer with this, but you mentioned only HIDs. Could it talk to printer?

Game pad support?

Hello,

I am new to circuits and arduino so I am sorry if these are dump/simple questions.

I am trying to use a esp32 adafruit feather to turn a wired usb gamepad into a wireless one for pc. I have the gamepad to bluetooth part (https://github.com/lemmingDev/ESP32-BLE-Gamepad) but I need to get the usb gamepad to be readable to that code. Would your code work or partly work for that?

Does your board provide +5v?

its hard to see in the picture but is your board providing a +5v to the USB power pins? all the esp32 boards I can find don't have a 5v pin to supply output, and I tired using an external 5v power supply but nothing seems to happen at all. All the keyboards I have tried don't even try to light up.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.