first commit

This commit is contained in:
jack
2026-04-04 15:32:51 +08:00
commit a862314d94
34 changed files with 10253 additions and 0 deletions

41
ec_i2c_scan.sh Executable file
View File

@@ -0,0 +1,41 @@
#!/bin/bash
# ec_i2c_scan.sh - 用 ectool i2cxfer 扫描 EC 各 I2C port 上的设备
# 用法: ECTOOL=/path/to/ectool-cec sudo ./ec_i2c_scan.sh [port1 port2 ...]
# 不传 port 时默认扫 port 0~7。必须用 Chromium 的 ectool-cec系统 ectool 无 i2cxfer。
set -e
ECTOOL=/home/jack/bin/ectool-cec
# 默认用 ectool-cec系统 ectool 不支持 i2cxfer
if [ -z "$ECTOOL" ]; then
for candidate in ectool-cec ./ectool-cec "$HOME/bin/ectool-cec"; do
if command -v "$candidate" >/dev/null 2>&1 || [ -x "$candidate" ]; then
ECTOOL="$candidate"
break
fi
done
fi
ECTOOL="${ECTOOL:-ectool-cec}"
PORTS="${*:-0 1 2 3 4 5 6 7}"
if ! command -v "$ECTOOL" >/dev/null 2>&1 && ! [ -x "$ECTOOL" ]; then
echo "未找到 ectool-cec需 Chromium EC 的 ectool系统 ectool 无 i2cxfer。请设置 ECTOOL"
echo " ECTOOL=/home/jack/bin/ectool-cec sudo $0"
exit 1
fi
# 7bit 地址范围0x00-0x07 保留0x78-0x7f 多为 10bit
for port in $PORTS; do
found=""
for addr in $(seq 8 119); do
hexaddr=$(printf "0x%02x" "$addr")
if "$ECTOOL" i2cxfer "$port" "$hexaddr" 1 >/dev/null 2>&1; then
found="$found $hexaddr"
fi
done
if [ -n "$found" ]; then
echo "EC I2C port $port:$found"
else
echo "EC I2C port $port: (无设备)"
fi
done