Architeuthis-Flux / Jumperless

A jumperless breadboard
Other
738 stars 36 forks source link

Continously sample ADCs and expose samples via a USB Interrupt endpoint #28

Closed nilclass closed 4 months ago

nilclass commented 4 months ago

~DO NOT MERGE YET~ see comments below

This works (sort of), but it's not great. It would be better if we could define a custom vendor interrupt endpoint, instead of using the HID one, because HID interfaces are normally claimed by an operating system driver, making it harder to use them from host code. At least that's what I'm struggling with right now :)

I had to comment out the initADC call, so other parts of the code that do analog reads may no longer work properly. We should fix that before merging these changes.

nilclass commented 4 months ago

Update: I managed to implement a custom USB interface instead. It uses the same underlying principle as the HID interface (a USB interrupt endpoint, that is polled by the host to get the data), but it's marked as vendor specific, so the host operating system will not get in the way of using it.

The counterpart of this code is the new dump-measurements command in jlctl.

Technically it's possible with tinyusb to implement class drivers within the application by implementing the global usbd_app_driver_get_cb function. However, the pico SDK already defines that function to implement their reset-via-usb magic. So instead I copied the Adafruit USB library (which contains tinyusb) and implemented the class driver there.

nilclass commented 4 months ago

I had to comment out the initADC call, so other parts of the code that do analog reads may no longer work properly. We should fix that before merging these changes.

There was only one occurrence of analogRead, which I replaced. So unless there is some other way in which the ADCs are used somewhere, this should be ok now.