Kajatin / jetson-gpio-rust

A Rust port of NVIDIA's Python library for controlling GPIO pins on select Jetson devices
MIT License
4 stars 2 forks source link

jetson-gpio-rust

A Rust port of NVIDIA's Python library for controlling GPIO pins on select Jetson devices. It is based on the jetson-gpio Python library.

Find the crate on crates.io.

Getting started

The usage of this crate is very similar to the Python library. The main difference is that the Python library uses a global GPIO object, while this crate uses a GPIO struct. This means that you need to create a GPIO struct before you can use it. The GPIO struct is created using the new method.

use jetson_gpio::{GPIO, Direction, Level, Mode};

let mut gpio = GPIO::new();
gpio.setmode(Mode::BOARD).unwrap();

gpio.setup(vec![7, 11], Direction::OUT, Some(Level::LOW)).unwrap();
gpio.output(vec![7, 11], vec![Level::HIGH, Level::HIGH]).unwrap();

gpio.cleanup(None).unwrap();

This example sets up two pins as outputs and sets them to an initial LOW value. It then sets the pins to HIGH and finally cleans up the GPIO pins. The unwrap method is used to unwrap the Result returned by the methods. If an error occurs, the program will panic (you should handle the error properly in your code 🤓).

Start using this crate by adding the following to your Cargo.toml file:

[dependencies]
jetson_gpio = { version = "0.1.1" }

Pin numbering mode

Just like in the Python library, you must specify the pin numbering mode before you can use the GPIO pins. The pin numbering mode can be set using the setmode method. The pin numbering mode can be one of the following:

Using this library, you can configure GPIO pins as either inputs or outputs. You can also read the current value of an input pin or set the value of an output pin.

Crate support

This crate is tested on the following Jetson devices:

This crate is under development and it currently only supports a subset of the functionality provided by the Python library. Currently supported boards:

Supported pin numbering modes:

Only GPIO pins without events are supported.

License

This crate is licensed under the MIT license. See the LICENSE file for more information.

Contributing

Contributions are welcome! Please open an issue or a pull request on the GitHub repository if you have any questions or suggestions.


TODO

Currently, this crate only supports a subset of the functionality provided by the Python library. The following features are planned: