Files
Loongson_2k0300_SmartCar/vl53l0x_setup.sh
T

33 lines
1.0 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# VL53L0X 激光测距初始化脚本
# GPIO 50=SCL, GPIO 51=SDA -> I2C2_SCL[1]/I2C2_SDA[1]
echo "[VL53L0X] === 检查/初始化激光测距 ==="
# 1. 检查设备节点是否已存在
if [ -c /dev/stmvl53l0x_ranging ]; then
echo "[VL53L0X] /dev/stmvl53l0x_ranging 已存在"
else
echo "[VL53L0X] /dev/stmvl53l0x_ranging 不存在,尝试加载驱动..."
modprobe stmvl53l0x 2>/dev/null || modprobe vl53l0x 2>/dev/null
if [ ! -c /dev/stmvl53l0x_ranging ]; then
echo "[VL53L0X] 驱动未加载,需要检查内核配置或设备树"
fi
fi
# 2. 设置 GPIO 50/51 为 I2C 功能(尝试通过 debugfs pinctrl
PINMUX=/sys/kernel/debug/pinctrl/zx296718-pinctrl
if [ -d "$PINMUX" ]; then
echo "[VL53L0X] pinctrl debugfs 可用: $PINMUX"
ls "$PINMUX"/
else
echo "[VL53L0X] pinctrl debugfs 不可用"
fi
# 3. 最终确认
if [ -c /dev/stmvl53l0x_ranging ]; then
echo "[VL53L0X] OK — 设备就绪,可以使用"
else
echo "[VL53L0X] FAIL — 需要先配置内核/设备树中的 I2C 引脚复用"
fi