Rust language bindings for ev3dev
Notice
To use this project with the BrickPi platform the corresponding feature has to be enabled. The features ev3, brickpi and brickpi3 are mutual exclusive.
[]
= { ="0.13.0" default-features=false, features=["brickpi"] }
Usage
extern crate ev3dev_lang_rust;
use Ev3Result;
use ;
use ColorSensor;
There is a template repository that contains all the required configurations for cross-compilation and performance/binary-size optimizations for this "Hello World" example.
Supported features
- Motors:
LargeMotor[lego-ev3-l-motor,lego-nxt-motor]MediumMotor[lego-ev3-m-motor]TachoMotor: Useful wrapper aroundLargeMotorandMediumMotorto make common functions easier to use
- Sensors:
ColorSensor[lego-ev3-color]CompassSensor[ht-nxt-compass]GyroSensor[lego-ev3-gyro]InfraredSensor[lego-ev3-ir]IrSeekerSensor[ht-nxt-ir-seek-v2]LightSensor[lego-nxt-light]TouchSensor[lego-ev3-touch,lego-nxt-touch]UltrasonicSensor[lego-ev3-us,lego-nxt-us]
- Utility
Button: Provides access to the integrated buttons on the ev3 brickLed: Provides access to the integrated led's on the ev3 brickPowerSupply: Provides access to the power supply informationScreen: Provides access to the integrated display of the ev3 bricksound: Provides access to the integrated speakers of the ev3 brick
Cross compilation for the ev3 robot - using musl toolchain
-
Install the
armv5te-musltoolchain -
Create
.cargo/config.tomlwith the following content[] = "armv5te-unknown-linux-musleabi" [] = "rust-lld" -
Build binary
The
--releaseflag is optional. However, it can speed up the execution time by a factor of 30. The target binary is now intarget/armv5te-unknown-linux-musleabi/release/{application_name}.
Cross compilation for the ev3 robot - using docker
If you need to cross compile other dependencies (eg. openssl or paho-mqtt) it is much easier to use a complete cross compile toolchain. For this you can use the provided docker image pixix4/ev3dev-rust:latest.
-
Setup a docker environment
-
Create
.cargo/config.tomlwith the following content[] = "armv5te-unknown-linux-gnueabi" [] = "/usr/bin/arm-linux-gnueabi-gcc" -
Build binary
The
--releaseflag is optional. However, it can speed up the execution time by a factor of 30. The target binary is now intarget/armv5te-unknown-linux-gnueabi/release/{application_name}.If you do this you will notice that each build gets stuck at
Updating crates.io indexfor a long time. To speed up this step you can use the vendoring mechanic of cargo.Execute the above command and add this additional config to
.cargo/config.[] = "vendored-sources" [] = "vendor"
Optimize binary size
-
Enable "fat" link time optimizations and strip debug symbols: By default rust only performs lto for each crate individually. To enable global lto (which result in a much more aggressive dead code elimination) add the following additional config to your
Cargo.toml. This also removes additional debug symbols from the binary. With this you can reduce the binary size of the "Hello World" example by more than 90%.[] = true = "debuginfo"The strip option requires rust
1.59.0. If you are using an older version you can do this manually with docker:# Run in interactive docker shell # Run directly (e.g. via Makefile)
Editor support
If you have problems with code completion or inline documentation with rust analyzer it may help to enable to following settings:
(Example from VSCode settings.json)
Docs.rs documentation
To build the complete documentation (including the screen feature) use:
RUSTDOCFLAGS="--cfg docsrs"