adafruit / Adafruit_Blinka

Add CircuitPython hardware API and libraries to MicroPython & CPython devices
https://learn.adafruit.com/circuitpython-on-raspberrypi-linux
MIT License
439 stars 328 forks source link

Does not work with MicroPython and Raspberry Pi Pico #643

Closed cbmeeks closed 1 year ago

cbmeeks commented 1 year ago

I cannot get even the simplest program to build using the usb_hid module and a Raspberry Pi Pico.

I have uploaded the Adafruit-Blinka and other dependencies to the Pico. But even this simple program fails:

import time

import board
import digitalio
import usb_hid

Removing 'usb_hid' builds fine (granted, it doesn't actually DO anything but no errors).

The error reported is:

Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
  File "/lib/usb_hid.py", line 14, in <module>
ImportError: no module named 'typing'

When I try to install the typing module, Thonny complains it isn't a MicroPython module. Installing it anyway fails when I try and run because 'typing' is simply too large to fit on the Pico from what I understand.

Any ideas on how to fix this?

Neradoc commented 1 year ago

USB HID in Blinka is not implemented for Micropython, it's only implemented for Raspberry Pi OS, using gadget mode (available on the Pi Zero and Pi 4), which is why it doesn't bother to try/except the typing import. (Micropython ignores type hints).

For it to be supported on MP it would require HID support at the Micropython level, and implementing a version of the module that uses it. I believe it is an option in Micropython to compile for the pico with complete USB support, but maybe HID is only supported on the pyboard. https://docs.micropython.org/en/latest/library/pyb.USB_HID.html

cbmeeks commented 1 year ago

Oh, I was going by this tutorial and just noticed he is using Circuit Python and not MicroPython.

https://tutorial.cytron.io/2021/02/16/keyboard-emulator-using-raspberry-pi-pico-maker-pi-pico-and-circuitpython/

So I guess that's my mistake the whole time. I'm new to Python on these devices. :-)

cbmeeks commented 1 year ago

Example works with CircuitPython. So I guess this can close. Thanks.

Miner34dev commented 11 months ago

Do you think it can be fixed by removing any use of typing in usb_hid.py?