trellis 0.2.1

Rust library to talk with the Adafruit Trellis

Build Status Coverage Status License

Adafruit Trellis Library for Rust

This is a pure Rust port of the Adafruit Trellis Python and Adafruit Trellis C++ libraries.


The documentation for the current version can be found here: Rust Trellis Documentation


To see what using the library looks like, let's have a look at the example program from the project. The example program turns the LED on or off if the corresponding button on the Trellis is pressed.

fn main() {
    let pi_dev = RaspberryPiBPlus::new();

    let mut trellis = Trellis::new(Box::new(pi_dev));

    trellis.set_led(Col::A, Row::R0);

    let cb = Box::new(|trellis:&mut Trellis, evt:ButtonEvent| {
        if evt.buttons_pressed.len() > 0 {
            println!("pressed button {:?}", evt);
        for button in evt.buttons_pressed {
            if trellis.is_led_set(button.col, button.row) {
                trellis.clear_led(button.col, button.row);
            } else {
                trellis.set_led(button.col, button.row);
        return false;

You first need to create a concrete host device the Trellis is connected to. Since I only own a Raspberry Pi 2 B+ this is the only one that comes with the library. Implementing you own device should be straightforward with RaspberryPiBPlus as a basis.

You can now create a new Trellis with new and the previously create host device object. Before you interact with the Trellis you have to call init (exactly once).

After init you can now manipulate the LED states with calls to set_led and clear_led. The current LED state can be queried with is_led_set. The LEDs are addressed in rows (from R0 to R3) and columns (from A to D). The addressing layout is as follows:

[..................]----- (cables)

After manipulating the LED state you have to write the state to the device with a call to write_display. This will turn the LEDs on the Trellis on/off according to the previously set LED state.

For reading the button state you can register a callback function on the button_evt_loop function. Note that this functions does only terminate if the supplied callback function returns true. The button state is constantly queried in the button_evt_loop with a resolution of 30ms (currently fixed).

The callback function will receive a list of pressed buttons in the EventButton object. The function will receive the button press event only once, regardless how long the button is pressed by the user.