# i2cutil

## 用量

``````i2cutil read <device> <address> [<address>...]
i2cutil list
i2cutil ping
i2cutil help
``````

## 指令

``````i2cutil read <device> <address> [<address>...]
``````

### write

``````i2cutil write <device> <address> [<address>...] <data> [<data>...]
``````

### 交易

``````i2cutil transact <device> (r <bytes>|w <address> [<address>...] [<data>...])...
``````

### 轉儲

``````i2cutil dump <device> <start> <count>
``````

### list

``````i2cutil list
``````

### 連線偵測 (ping)

``````i2cutil ping
``````

### 說明

``````i2cutil help
``````

## 範例

### 讀取一位元組

``````\$ i2cutil read 4 0x20
``````

### 讀取三個位元組

``````\$ i2cutil transact 4 w 0x20 r 3
``````

### 從地址 0x10 開始傾印九個暫存器

``````\$ i2cutil dump pmic 0x10 9
0x10: 0x00
0x11: 0x00
0x12: 0x00
0x13: 0x00
0x14: 0x00
0x15: 0x00
0x16: 0x00
0x17: 0x00
0x18: 0x00
``````

### 從多位元組位址讀取一位元組

``````\$ i2cutil read 4 0x20 0x3D
``````

### 使用 devfs 節點路徑讀取 1 個位元組

``````\$ i2cutil read /dev/class/i2c/004 0x20 0x3D
``````

### 使用裝置易記的名稱讀取 1 個位元組

``````\$ i2cutil list
378: temp_sensor
379: (ANONYMOUS)
380: humidity_sensor
381: pmic
\$ i2cutil read temp_sensor 0x20 0x3D
``````

### 寫入一位元組

``````\$ i2cutil write 3 0x2C 0x12
``````

### 使用 devfs 節點路徑寫入兩個位元組

``````\$ i2cutil write /dev/class/i2c/003 0x2C 0x12 0x1B
``````

### 對所有 I2C 裝置執行連線偵測 (ping)

``````\$ i2cutil ping
/dev/class/i2c/821: OK
/dev/class/i2c/822: OK
/dev/class/i2c/823: OK
/dev/class/i2c/824: OK
Error ZX_ERR_TIMED_OUT
/dev/class/i2c/825: ERROR
``````

### 列出所有 I2C 裝置

``````\$ i2cutil list
378: temp_sensor
379: (ANONYMOUS)
380: humidity_sensor
381: pmic
``````

## 附註

### 原始碼

`i2cutil` 的原始碼：`//src/devices/i2c/bin/i2cutil.cc`

[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"缺少我需要的資訊" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"過於複雜/步驟過多" },{ "type": "thumb-down", "id": "outOfDate", "label":"過時" },{ "type": "thumb-down", "id": "translationIssue", "label":"翻譯問題" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"示例/程式碼問題" },{ "type": "thumb-down", "id": "otherDown", "label":"其他" }]
[{ "type": "thumb-up", "id": "easyToUnderstand", "label":"容易理解" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"確實解決了我的問題" },{ "type": "thumb-up", "id": "otherUp", "label":"其他" }]
{"lastModified": "\u4e0a\u6b21\u66f4\u65b0\u6642\u9593\uff1a2024-08-29 (\u4e16\u754c\u6a19\u6e96\u6642\u9593)\u3002"}