#vl53l1x #driver #port #stm #sensors #hardware #uld

不依赖std vl53l1x-uld

VL53L1X的ULD驱动库源代码移植

3个稳定版本

2.0.1 2023年12月7日
2.0.0 2022年11月29日
1.0.0 2022年5月20日

嵌入式开发中排名第255

每月下载量26

MIT许可协议

54KB
948 代码行

build docs crates.io

vl53l1x-uld

此crate是将STM VL53L1X IMG009驱动程序移植到原生Rust的库。

最小示例

以下是用此驱动程序的最小示例。其他更复杂的示例可以在examples文件夹中找到。

use vl53l1x_uld::{self, VL53L1X, IOVoltage, RangeStatus};

// Create hardware specific I2C instance.
let i2c = ...;
// Create sensor with default address. 
let mut vl = VL53L1X::new(i2c, vl53l1x_uld::DEFAULT_ADDRESS);

const ERR : &str = "Failed to communicate";

// Check if the sensor id is correct.
if (vl.get_sensor_id().expect(ERR) == 0xEACC)
{
    // Initialize the sensor before any usage.
    // Set the voltage of the IO pins to be 2.8 volts
    vl.init(IOVoltage::Volt2_8).expect(ERR);

    // Start a ranging operation, needed to retrieve a distance
    vl.start_ranging().expect(ERR);

    // Wait until distance data is ready to be read.
    while !vl.is_data_ready().expect(ERR) {}

    // Check if distance measurement is valid.
    if (vl.get_range_status().expect(ERR) == RangeStatus::Valid)
    {
        // Retrieve measured distance.
        let distance = vl.get_distance().expect(ERR);
    }
}

依赖项

~1MB
~28K SLoC