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

How to add USB support? #1304

Open
IceBlizz6 opened this issue Mar 8, 2024 · 6 comments
Open

How to add USB support? #1304

IceBlizz6 opened this issue Mar 8, 2024 · 6 comments

Comments

@IceBlizz6
Copy link

Love the blog, finished the PS/2 keyboard support.
Also gone through 3rd edition of what you have so far.

I really want to attempt USB support for keyboard but it seems challenging.
Looked at several USB libraries already.

usb-device crate seems to assume that i already have an object of UsbBus,
some examples for micro-controllers seems to get this from HAL crates, i did not find anything for x86 architecture.

Tried to ask around in the rust discord,
Was pointed to xhci, and then from there was told that i needed to initialize PCI.
I don't really know where to continue or what crate to use from here.

Would you be able to point me in the right direction and give an overview of which parts here would need to be implemented by me and which parts i could just take from existing crates?

@bjorn3
Copy link
Contributor

bjorn3 commented Mar 8, 2024

https://wiki.osdev.org/Pci has a fair bit of information on how to work with PCI. The pci-types crate can be useful too for interacting with the PCI configuration space.

@IceBlizz6
Copy link
Author

https://docs.rs/usb-device/latest/usb_device/device/index.html

// Create the device-specific USB peripheral driver. The exact name and arguments are device
// specific, so check the documentation for your device driver crate.
let usb_bus = device_specific_usb::UsbBus::new(...);

Example looks like this from usb_device crate.

Is it possible to pass something in here?

If i have to use pci-types crate then give an example of how i would use it?

@bjorn3
Copy link
Contributor

bjorn3 commented Mar 9, 2024

Is it possible to pass something in here?

You did have to implement the UsbBus trait yourself I think. I'm not familiar with how USB or the usb_device crates work, so I can't help you with that.

If i have to use pci-types crate then give an example of how i would use it?

This is what Redox OS uses: https://gitlab.redox-os.org/redox-os/drivers/-/blob/master/pcid/src/main.rs?ref_type=heads It is fairly messy IMO and it has to deal with the PCI interfacing running in a different process from the actual PCI drivers.

Hermit may be a better learning source: https://github.com/hermit-os/kernel/blob/main/src/arch/x86_64/kernel/pci.rs

@kennystrawnmusic
Copy link
Contributor

Well USB depends on xHCI, so that needs to be set up first. Here's an example of that.

@IceBlizz6
Copy link
Author

IceBlizz6 commented Mar 10, 2024

Thank you for the links,
i'll take a closer look at this tomorrow if i can find the time.
If you got anything more then feel free to add it here.

I'm starting to understand why the guide went with PS/2 keyboard support.
Is there a guide planned for USB keyboard later though?
maybe i'll figure out a setup that could be used in a future guide.

@boredcoder411
Copy link

boredcoder411 commented Aug 4, 2024

Did you figure it out in the end? I am currently developing a FAT32 driver and it would be nice to have disk support to actually see if it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants