6 releases

0.1.5 Mar 9, 2024
0.1.4 Feb 18, 2024
0.1.3 Dec 16, 2023
0.1.1 Oct 30, 2023

#271 in Hardware support

Download history 38/week @ 2024-01-15 145/week @ 2024-01-29 133/week @ 2024-02-12 52/week @ 2024-02-19 46/week @ 2024-02-26 145/week @ 2024-03-04 79/week @ 2024-03-11 65/week @ 2024-03-18 25/week @ 2024-03-25 62/week @ 2024-04-01

316 downloads per month

MIT license

51KB
1.5K SLoC

mlua-periphery

A Rust-native implementation of lua-periphery for mlua.

License Arch Lua

From lua-periphery:

lua-periphery is a library for GPIO, LED, PWM, SPI, I2C, MMIO, and Serial peripheral I/O interface access in userspace Linux. It is useful in embedded Linux environments (including Raspberry Pi, BeagleBone, etc. platforms) for interfacing with external peripherals.

Using Python or C? Check out the python-periphery and c-periphery projects.

Installing

Add to your Rust project using one of MLua's features: [lua51, lua52, lua53, lua54, luajit, luajit52].

$ cargo add mlua-periphery --features luajit

Using

use mlua::Lua;

let lua = Lua::new();
mlua_periphery::preload(&lua);
let script = r#"
    local LED = require('periphery.LED')
    local led = LED('led0')
    return led:read(), led.brightness, led.max_brightness
"#;
let (value, brightness, max_brightness): (bool, u32, u32) = lua.load(script).eval()?;

Testing

An integration_tests.rs file exists in each submodule and demonstrates:

Dependencies

~3.5–5.5MB
~93K SLoC