st7735-rs

This is a library for displays using the ST7735 driver. Documentation is available here.

Display example

Currently, there is support for using hardware SPI as well as software SPI to communicate to the display. Note that using hardware SPI is much faster and recommended to be used if supported by the connecting device.

The driver also provides a simple graphics library which currently supports drawing the following shapes: * Rectangles (filled and border only) * Circles (filled and border only) * Lines (horizontal, vertical, and diagonal) * Text (characters)

Usage

To use the crate please add the following to your Cargo.toml:

[dependencies] st7735 = "0.1.0"

Please refer to /examples for more examples.

```rust extern crate st7735; use st7735::color::{Color, DefaultColor}; use st7735::fonts::font57::Font57; use st7735::Orientation; use st7735::ST7734;

let mut display = ST7734::newwithspi("/dev/spidev0.0", 25); display.clearscreen(); display.setorientation(&Orientation::Portrait); let colorred = Color::fromdefault(DefaultColor::Red); display.drawhorizontalline(0, 128, 20, &colorred); display.drawhorizontalline(0, 128, 140, &colorred); display.drawrect(30, 30, 60, 70, &Color::fromdefault(DefaultColor::Blue)); ```

Connecting the Display

I tested this create using a Raspberry Pi model A and a SainSmart 1.8" TFT LCD Display with the following wiring for SPI:

| Raspberry Pi | Display | | ----------------- | ------- | | GND (Pin 6) | CS | | GPIO 25 (Pin 22) | RS/DC | | GPIO 10 (Pin 19) | SDA | | GPIO 11 (Pin 23) | SCL | | GND (Pin 6) | GND | | 5V (Pin 2) | VCC |

When using the software SPI with other pins or even in the hardware SPI case it might be necessary to explicitly give permission to access GPIOs on the Raspberry Pi:

echo "25" > /sys/class/gpio/export sudo sh -c 'echo out > /sys/class/gpio/gpio25/direction'

Building

To build this crate on the target platform (for example a Raspberry Pi) you can simply run cargo build if cargo is installed.

To build this crate on a platform used for development that is not the target platform (for example macOS), I recommend using crosstool-ng which will install the necessary toolchains. To build the crate for a Raspberry Pi model A run:

cargo build --target=arm-unknown-linux-gnueabi

For more details about installing required tools and setting up everything to build this crate, I wrote a more elaborate blog post about setting up Rust for embedded system programming on macOS.

Roadmap

Resources

This crate is based on the series Add a TFT Display to the Raspberry Pi by Bruce E. Hall and the Adafruit-ST7735-Library .

Contributing

Contributions are always welcome! Feel free to fork the repository and create pull-requests.

License

MIT