10 releases

new 0.1.9 Oct 29, 2024
0.1.8 Oct 19, 2024
0.1.7 Aug 16, 2024
0.1.6 May 11, 2024
0.1.1 Oct 30, 2023

#219 in Hardware support

Download history 89/week @ 2024-07-08 39/week @ 2024-07-15 20/week @ 2024-07-22 18/week @ 2024-07-29 16/week @ 2024-08-05 179/week @ 2024-08-12 87/week @ 2024-08-19 14/week @ 2024-08-26 92/week @ 2024-09-02 55/week @ 2024-09-09 40/week @ 2024-09-16 20/week @ 2024-09-23 21/week @ 2024-09-30 42/week @ 2024-10-07 152/week @ 2024-10-14 71/week @ 2024-10-21

287 downloads per month

MIT license

52KB
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:

Running the i2cdetect example

$ cargo run -v --example i2cdetect --features lua54

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- 1a -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         

Dependencies

~3.5–9.5MB
~103K SLoC