Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB HOST implementation on teensy 4.1 #6527

Closed
fadh3r opened this issue Jun 28, 2022 · 4 comments · Fixed by #8155
Closed

USB HOST implementation on teensy 4.1 #6527

fadh3r opened this issue Jun 28, 2022 · 4 comments · Fixed by #8155

Comments

@fadh3r
Copy link

fadh3r commented Jun 28, 2022

I can't get data through endpoint of usb host implementation
Where is my mistake?

this is my code:

import usb_host
import usb.core
import sys
import board
import digitalio
import microcontroller
import time
import array

#INIT USB WITH POSITIVE AND NEGATIVE PINS
if hasattr(board, "USB_HOST_POWER"):
    d = digitalio.DigitalInOut(board.USB_HOST_POWER)
    d.switch_to_output(value=True)
    print("USB power on")


h = usb_host.Port(board.USB_HOST_DP, board.USB_HOST_DM)

#FIND VMETER
vmeter = usb.core.find(idVendor=0x16d0, idProduct=0x0668)
print(vmeter.manufacturer, vmeter.product)

if vmeter.is_kernel_driver_active(0):
    vmeter.detach_kernel_driver(0)


buf = array.array('b', [0] * 64)

while True:
    try:
        count = vmeter.read(0x82, buf)
        # bEndpointAddress 0x82 IN Endpoint 2
        # bEndpointAddress 0x01 OUT Endpoint 1
    except usb.core.USBTimeoutError:
        continue

    print(buf)
    print(count)
    time.sleep(.01)

I'm getting right device manufacturer and product names,
but my "buf" is always empty and "count" of read bytes is always 14...

array("b", [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
14

I also tried 7 and 8 version of CircuitPython and different usb devices...

@fadh3r fadh3r changed the title add ability to get "USB-MIDI Event Packets" for USB HOST implementation problem with USB HOST implementation Jun 28, 2022
@fadh3r fadh3r changed the title problem with USB HOST implementation problem with USB HOST implementation on teensy 4.1 Jun 28, 2022
@fadh3r fadh3r changed the title problem with USB HOST implementation on teensy 4.1 USB HOST implementation on teensy 4.1 Jun 28, 2022
@tannewt tannewt added the bug label Jun 28, 2022
@tannewt
Copy link
Member

tannewt commented Jun 28, 2022

read isn't implemented yet. :-) I mentioned it here: #6125

I should have had it raise an error. Sorry!

I thought I'd get back to it quickly but didn't. I switched off of it while waiting for a TinyUSB API to call.

Would you like to try and add it? It shouldn't be too hard now that TinyUSB has an API for it. (I haven't looked at specifics though.)

@tannewt tannewt added this to the Long term milestone Jun 28, 2022
@tannewt tannewt added the usb label Jun 28, 2022
@fadh3r
Copy link
Author

fadh3r commented Jun 29, 2022

Thanks for answer, Scott!
Sure, I want to try to add it. But can you give me brief insight into right direction, please?
Do I need build new circuitpython for my teensy, or I can just add TinyUSB library to my project and write some glue?

@tannewt
Copy link
Member

tannewt commented Jun 29, 2022

Sure, I want to try to add it. But can you give me brief insight into right direction, please?

Yup! Happy to. Join us on discord if you haven't yet too. There is a #circuitpython-dev channel where we can help you get over any bumps. https://adafru.it/discord

Do I need build new circuitpython for my teensy, or I can just add TinyUSB library to my project and write some glue?
Yes, you'll need to build your own CircuitPython. I think the steps are:

  1. Upgrade the lib/tinyusb submodule to the latest commit to get the newest USB Host API. You may need to update the existing calls too.
  2. Add calls into the TinyUSB API into the shared-module/usb/core/Device.c source file. It is in shared-module because it'll work on all ports that have the usb_host module and use TinyUSB.

If you hit any snags, jump on Discord and we'd be happy to try and help.

@fadh3r
Copy link
Author

fadh3r commented Jun 30, 2022

Thanks, Scott!
I'm done with successful build of custom CircuitPython and now I'm trying to understand architecture of api calls for required changes, and this looks like few sleepless nights))

jepler pushed a commit to jepler/circuitpython that referenced this issue Jul 8, 2023
Connects up read, write and ctrl_transfer to TinyUSB. USB Host
support is available on iMX RT and RP2040.

Fixes adafruit#6527 (imx) and fixes adafruit#5986 (rp2).
tannewt added a commit that referenced this issue Jul 11, 2023
Connects up read, write and ctrl_transfer to TinyUSB. USB Host
support is available on iMX RT and RP2040.

Fixes #6527 (imx) and fixes #5986 (rp2).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants