-
Notifications
You must be signed in to change notification settings - Fork 215
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
Add usb-device support to atmega32u4 #40
Comments
Yes, definitely! Though I don't have much experience with low-level USB so it'll take some time ... If anyone else wants to take a stab at it, please go for it! |
Hey, I'm trying to bring up the USB hardware, based on the LUFA and Teensy libraries. However, I can't seem to get the
|
Never mind. I was paying attention to the bits being set, not the bits being cleared. The following, less readable, version enumerates correctly:
|
I think you misunderstood how dp.PLL.pllcsr.write(|w| w.pindiv().set_bit()); // usb 16 mhz clock source
dp.PLL.pllcsr.write(|w| w.plle().set_bit()); // enable PLL only
For initialization, option 1 is usually the right choice and when modifying a single field, option 2. Keep in mind that option 1 will compile to 1 or 2 instructions while option 2 will become a read-modify-write cycle (about 4 instructions and not preemption-safe). Related: If you use For more details on this, take a look at the official |
Hello I am trying to implement usb-device for the atmega32u4. One problem apart from my lack of usb knowledge is that the usb-device crate uses |
Can you try adding this to your target json spec? "max-atomic-width": 16, |
Yes, now it builds. |
Hey @lperlaki. I know you said it isn't tested, but I was curious if you had any example code or tips on getting this working? |
@lperlaki Hello, I would like to help too! |
Hello @ExplodingWaffle , @wusyong |
Sure thing! I'll see anything I can help. |
Just as a short note: Using https://github.com/mvirkkunen/usb-device will not work at the moment because this crate uses trait objects which are currently still miscompiled by LLVM (on the AVR target). I'm not sure how much sense there is in hacking a custom solution in the meantime... |
I'm working on a usb-device implementation for atsam4 (https://github.com/atsam-rs/atsam4-hal). This hardware is a lot closer to AVR than the existing usb-device implementations. Hoping to have some code pushed in the next week or two. While I don't have time to specifically work on avr rust things I am quite familiar the USB devices (https://github.com/kiibohd/controller/) and I don't mind giving advice and helping work through issues. |
FWIW, with the latest working compiler version (2021-01-07), even before hitting the trait object problems, we're hitting a miscompilation related to enums. I have not yet tracked it down entirely, but this also blocks integration of usb-device for the time being. |
are trait objects still broken on avr? |
@TheButlah Yes, here are the relevant issues that I know of - these fixes are necessary to be able to use the
|
I almost have a working implementation; still some features missing and plenty of cleanup before it's ready to submit, but we're close! https://github.com/agausmann/rust-avr-usb I've gotten usb-device to send device & configuration descriptors; now I just need a way to reconcile usb-device's out-of-order endpoint allocation (ep0 last) with the ATmega's requirement that endpoints be allocated in-order. I'll probably implement a table sort of like what LUFA has but more tailored to internal use. Another thing on my to-do list is attach/detach detection for self-powered devices; just waiting on hardware to arrive to test that. |
I've done a bit of cleanup and actually refactored it into two separate projects:
usbd-hid now works - sort of. It is recognized by Linux as an HID device but it seems to have trouble sending reports. |
Great work @agausmann ! Is your crate ready for publishing? Also, may I recommend you add your lib to https://github.com/rust-embedded-community/usb-device so that it's easier for people to find? I'm going to attempt to use this for a midi device today. |
I'm not quite sure about publishing yet. You can always add it as a git dependency: atmega-usbd = { git = "https://github.com/agausmann/atmega-usbd.git" } |
Just want to put out a PSA - I haven't worked with atmega+USB in a while, and I don't think I can spend much time on it for the foreseeable future. I'll still try to keep up with basic maintenance of my repositories, but it's difficult for me to allocate time to review and test PRs. Long-term, I think someone else should take over, if there are any development milestones that you want to meet (like publishing on crates.io, or avr-hal integration). @Rahix If you're willing, can I add you as a collaborator? |
@agausmann, sorry for the late reply :( I guess this serves to demonstrate that I'm also not really in the best position regarding maintenance duties... In any case, I'd suggest that maybe we move This would of course also mean that I will then take care of maintenance for the future. What do you think of it? |
Sure, you have my blessing to do whatever you want with the code. Its license is 0BSD for that reason |
@Rahix I can take a stab at the implementation if you can explain here what that would look like to you as I have limited experience with all these low level systems. Specifically where code should lie and what abstractions should take place at each level from generic down to board-specific setup. |
Ok there's my take on an implementation let me know what you think |
Do you plan to support https://github.com/mvirkkunen/usb-device on atmega32u4? It would validate the usb-device abstraction and would allow to use rust to implement USB keyboard on most QMK compatible keyboards.
The text was updated successfully, but these errors were encountered: