ni-fpga-rs is a set of Rust libraries I have been working on-and-off on for the past year for interfacing with NI FPGAs - like the one on the roboRIO!
Examples
The main (ni-fpga) library provides a simple interface for reading and writing to FPGA registers.
use ni_fpga::Session;
fn main() -> Result<(), ni_fpga::Error> {
let session = Session::open(
"/boot/user.lvbitx",
"264D0BA312FF00B741D4742415E1D470",
"RIO0",
)?;
// Register locations vary by FPGA image
println!("Input voltage: {:?}", session.read::<u16>(99174)?);
Ok(())
}
A separate (ni-fpga-macros) library provides derive macros for Clusters (FPGA structs) and Enums.
use ni_fpga::Session;
use ni_fpga_macros::Cluster;
#[derive(Cluster)]
struct LEDs {
comm: u8,
mode: u8,
rsl: bool,
}
fn main() -> Result<(), ni_fpga::Error> {
let session = Session::open(
"/boot/user.lvbitx",
"264D0BA312FF00B741D4742415E1D470",
"RIO0",
)?;
// Blink the mode LED on and off repeatedly
loop {
let mut leds: LEDs = session.read(98320)?;
leds.mode = 1 - leds.mode;
session.write(98320, &leds)?;
std::thread::sleep(std::time::Duration::from_secs(1));
}
Ok(())
}
Why build this?
I want to program an FRC robot in Rust! I intend to implement the embedded-hal traits for the roboRIO, and these libraries are the first step in that effort.
Contributing
Releasing 1.0.0 means that I’m ready to show this project to the world and that I’m fairly comfortable with its APIs. The project is still a long ways from being feature-complete.
If you also want to program a robot in Rust, please check out ni-fpga-rs and first-rust-competition on GitHub. In particular, I need help with:
- Creating an automated testing strategy
- Handling fixed-point numeric types
- Improving documentation
- Adding support for IRQs and FIFOs (see NI API reference)
Contributions can also be as simple as playing with the library on your own roboRIO and reporting bugs. DM me if you need guidance in setting up the examples.
Thanks for reading!