#usb #bindings #embedded

lufa-rs

Rust bindings and utility macros for the LUFA library

1 unstable release

Uses new Rust 2024

0.1.0 Aug 24, 2025

#1910 in Hardware support

MIT license

2MB
30K SLoC

C 28K SLoC // 0.2% comments C# 872 SLoC // 0.2% comments Rust 406 SLoC // 0.2% comments .NET Resource 372 SLoC // 0.5% comments GNU Style Assembly 303 SLoC // 0.3% comments Python 105 SLoC // 0.4% comments XSL 8 SLoC // 0.5% comments

Contains (Windows DLL, 160KB) libusb0.dll, (Windows DLL, 77KB) libusb0.dll, (DOS exe, 110KB) libusb0.sys, (Windows DLL, 68KB) libusb0_x86.dll, (Windows DLL, 95KB) Hid.Win32.dll, (DOS exe, 53KB) libusb0.sys and 5 more.

lufa-rs

This crate provides Rust raw bindings for the LUFA (Lightweight USB Framework for AVRs) library. It also contains some utility functions and macros to easily create HID (Human Interface Device) applications.

Installation

Add to your Cargo.toml file:

[dependencies]
lufa-rs = "0.1"

Usage

LUFA needs some environment variables to be set for the build process. You can set them in your .cargo/config file:

[env]
F_CPU="16000000"
ARCH="ARCH_AVR8"
BOARD="BOARD_USBKEY"
MMCU="atmega32u4"
LUFA_CONFIG_PATH = { value = ".", relative = true }

A LUFAConfig.h file needs to be present in the LUFA_CONFIG_PATH directory. See LUFA devices examples or rust-keyboard to create one.

Then you can use the library in your project:

use core::arch::asm;
use lufa_rs::{USB_Init, USB_USBTask};

fn main() {
    // USB initialization before enabling interrupts
    unsafe {
        USB_Init();
    }
    // Other initialization code, then enabling interrupts
    unsafe {
        asm!("sei");
    }
    // Your main loop
    loop {
        // Your code
        unsafe {
            USB_USBTask();
        }
    }
}

Some extern functions must be implemented for the library to work correctly. See any LUFA example for details.

Examples

LUFA demos can be found in the LUFA repository.

See the rust-keyboard repository for usage cases. The library is used here

Contribution

Contributions are welcome! Open an issue or a pull request.

License

This project is licensed under the MIT License.

Dependencies