Crates.io | wishbone-bridge |
lib.rs | wishbone-bridge |
version | 1.1.0 |
source | src |
created_at | 2020-07-06 13:26:57.413621 |
updated_at | 2020-11-05 00:59:46.176875 |
description | A library to control Wishbone devices |
homepage | |
repository | https://github.com/litex-hub/wishbone-utils |
max_upload_size | |
id | 261958 |
size | 108,873 |
This crate enables writing code in Rust to manipulate a device via a Wishbone bridge. Various bridges may be specified, depending on the bridge type you need.
Supported bridges include:
As an example, there is a kind of device that has a USB bridge with a small random number generator at address 0xf001_7000. This device has a simple API:
1
to 0xf001_7000 to enable the device0xf001_7008
is 1
there is data available0xf001_7004
We can turn this into a command that reads from this RNG and prints to stdout:
use std::io::{self, Write};
use wishbone_bridge::{UsbBridge, BridgeError};
fn main() -> Result<(), BridgeError> {
let stdout = io::stdout();
let mut handle = stdout.lock();
// Create a configuration object with a USB bridge that
// connects to a device with the product ID of 0x5bf0.
let bridge = UsbBridge::new().pid(0x5bf0).create()?;
// Enable the oscillator. Note that this address may change,
// so consult the `csr.csv` for your device.
bridge.poke(0xf001_7000, 1)?;
loop {
// Wait until the `Ready` flag is `1`
while bridge.peek(0xf001_7008)? & 1 == 0 {}
// Read the random word and write it to stdout
handle
.write_all(&bridge.peek(0xf001_7004)?.to_le_bytes())
.unwrap();
}
}
It is then possible to run this with cargo run | hexdump -C
to
produce an endless stream of random numbers.
Support for all bridges is enabled by default, however you may enable only certain bridges using cargo features.
For example, to enable only the "usb" bridge, add the following to your Cargo.toml
:
[dependencies]
wishbone-bridge = { version = "1", default-features = false, features = ["usb"] }
This will result in a faster build, but you will only have access to the UsbBridge
.