Rust language bindings for ev3dev
Notice
Currently this project is not compatible with the BrickPi platform.
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 aroundLargeMotor
andMediumMotor
to 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
Ev3Button
: 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-musl
toolchain -
Create
.cargo/config.toml
with the following content[] = "armv5te-unknown-linux-musleabi" [] = "rust-lld"
-
Build binary
The
--release
flag 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.toml
with the following content[] = "armv5te-unknown-linux-gnueabi" [] = "/usr/bin/arm-linux-gnueabi-gcc"
-
Build binary
The
--release
flag 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 index
for 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
)