dcuddeback / libusb-rs

A safe Rust wrapper for libusb.
MIT License
199 stars 64 forks source link

no_std support? #14

Closed spamwax closed 7 years ago

spamwax commented 7 years ago

Is it possible to use this crate for embedded devices, ex, for targeting ARM chipsets?

kevinmehall commented 7 years ago

It depends on libusb, so only works on platforms where libusb is supported. So embedded Linux on ARM, yes, but not bare-metal Cortex-M microcontrollers.

spamwax commented 7 years ago

thanks for info. are there any usb crates for bare-metal chips?

kevinmehall commented 7 years ago

Not yet that I know of. Are you looking to implement a USB host or device, and on what microcontroller model?

spamwax commented 7 years ago

I am trying to implement a USB device, specifically want to use stmf32 as the driver for a keyboard. Goal is build the keyboard firmware from scratch so I can better learn Rust and embedded software dev in general. I know that there are C/C++ based keyboard firmware projects for that chip but I want to see if this can be done without C/C++ My first guess was that take one of the implementation of the usb device from that project and port it to Rust.

oberien commented 7 years ago

I reversed parts of the firmware of STM32L100 R8T6 to write Linux drivers for my Logitech G910. I don't know about your particular chip, but for the STM32L series the way you handle USB packets is by reading and writing from static mapped addresses. There is an address space for USB control information containing USB registers and another space for the actual USB packet data. Libusb-rs works completely differently as it relies on libusb, which is not applicable for your SoC.

I'd suggest the following approaches:

dcuddeback commented 7 years ago

@spamwax As @kevinmehall explained, libusb is a C library that interacts with the host OS. It wouldn't be possible to compile it without an OS and C runtime, so I'm not sure if there'd be any value in supporting no_std for this crate.