Files
Power-off-analysis/i2c_scan.sh
2026-04-04 15:32:51 +08:00

24 lines
549 B
Bash
Executable File
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/bash
# i2c_scan_all.sh - 扫描当前系统所有 I2C 总线上的设备
set -e
if ! command -v i2cdetect >/dev/null 2>&1; then
echo "未找到 i2cdetect请先安装 i2c-tools"
echo " sudo apt install i2c-tools"
exit 1
fi
echo "列出 I2C 总线:"
i2cdetect -l
echo
buses=$(i2cdetect -l | awk '{print $1}' | sed 's/i2c-//')
for bus in $buses; do
echo "==============================="
echo "扫描 I2C bus $bus (/dev/i2c-$bus)"
echo "==============================="
i2cdetect -y "$bus"
echo
done