Merge pull request #58 from nmori/master

modify : Document follows current M5.Power class
This commit is contained in:
LiHuashen
2019-05-05 13:40:29 +08:00
committed by GitHub
12 changed files with 2818 additions and 672 deletions
+3 -1
View File
@@ -7,7 +7,9 @@
|**[System](en/api/system)** | **[Speaker](en/api/speaker)** |
|**[LCD](en/api/lcd)** | **[Button](en/api/button)** |
|**[IMU Sensor(MPU9250)](en/api/mpu9250)** | **[TF Card](en/api/tf)** |
|**[Power](en/api/power)** |
|**[Power](en/api/power)** |**[I/O](en/api/gpio)** |
|**[I2C Communication](en/api/commutil)** | |
## M5StickC
+216
View File
@@ -0,0 +1,216 @@
# I2C
This is a class to control M5Stack's Grove-A port (I2C).
I2C communication needs to be initialized in advance by M5.Begin().
## writeCommand()
**Syntax:**
<mark>bool writeCommand(uint8_t address, uint8_t subAddress);</mark>
**Description:**
Write to the specified address.
Used when there are no parameters.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| address | <code>uint8_t</code> |Slave Address |
| subAddress | <code>uint8_t</code> |function address |
**Function return value**
| Value |Description |
| --- | --- |
|true|Write success|
|false|Write failure|
## writeByte()
**Syntax:**
<mark>bool writeByte(uint8_t address, uint8_t subAddress, uint8_t data);</mark>
**Description:**
Write to the specified address.
Used when there is one parameter.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| address | <code>uint8_t</code> |Slave Address |
| subAddress | <code>uint8_t</code> |function address |
| data | <code>uint8_t</code> |parameter |
**Function return value**
| Value |Description |
| --- | --- |
|true|Write success|
|false|Write failure|
## writeBytes()
**Syntax:**
<mark> bool writeBytes(uint8_t address, uint8_t subAddress, uint8_t *data,uint8_t length);</mark>
**Description:**
Write to the specified address.
Use when there are multiple parameters.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| address | <code>uint8_t</code> |Slave Address |
| subAddress | <code>uint8_t</code> |function address |
| data | <code>uint8_t *</code> | top of data memory |
| length | <code>uint8_t</code> | length of data |
**Function return value**
| Value |Description |
| --- | --- |
|true|Write success|
|false|Write failure|
## readByte()
**Syntax:**
<mark> bool readByte(uint8_t address, uint8_t *result);</mark>
**Description:**
Read from the specified address.
It is used when there is no data to send before reading and the response is 1 byte.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| address | <code>uint8_t</code> |Slave Address |
| result | <code>uint8_t *</code> | stored memory |
**Function return value**
| Value |Description |
| --- | --- |
|true|Read success|
|false|Read failure|
## readByte()
**Syntax:**
<mark>bool readByte(uint8_t address, uint8_t subAddress,uint8_t *result);</mark>
**Description:**
Read from the specified address.
It is used when the data to be sent before reading is only the functional address and the response is 1 byte.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| address | <code>uint8_t</code> |Slave Address |
| subAddress | <code>uint8_t</code> |function address |
| result | <code>uint8_t *</code> |stored memory|
**Function return value**
| Value |Description |
| --- | --- |
|true|Read success|
|false|Read failure|
## readBytes()
**Syntax:**
<mark>bool readBytes(uint8_t address, uint8_t count,uint8_t * dest);</mark>
**Description:**
Read from the specified address.
Use when there is no data to send before reading and there are multiple responses.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| address | <code>uint8_t</code> |Slave Address |
| count | <code>uint8_t</code> | Length of request bytes |
| result | <code>uint8_t *</code> |stored memory|
**Function return value**
| Value |Description |
| --- | --- |
|true|Read success|
|false|Read failure|
## readBytes()
**Syntax:**
<mark>bool readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t * dest);</mark>
**Description:**
Read from the specified address.
It is used when the data to be sent before reading is only the functional address and there are multiple responses.
**Function argument**
| argument |Typer |Description |
| --- | --- | --- |
| address | <code>uint8_t</code> |Slave Address |
| subAddress | <code>uint8_t</code> |Addresress |
| count | <code>uint8_t</code> | Length of request bytes |
| result | <code>uint8_t *</code> |stored memory|
**Function return value**
| Value |Description |
| --- | --- |
|true|Read success|
|false|Read failure|
## scanID()
**Syntax:**
<mark>bool readBytes(bool *result);</mark>
**Description:**
Perform device presence check on I2C bus.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| result | <code>bool *</code> |stored memory(128bytes) |
**Function return value**
| Value |Description |
| --- | --- |
|true|Read success|
|false|Read failure|
**Example of use;**
```arduino
bool result[0x80];
M5.I2C.scanID(&result[0]);
```
+309 -21
View File
@@ -1,21 +1,309 @@
# GPIO {docsify-ignore-all}
*Refer to GPIO API of [Arduino](http://www.arduino.cc)*
### digitalRead
> uint32 digitalRead(uint8 pin);
Read the value of `pin`
| Param | Type | Description |
| --- | --- | --- |
| pin | <code>uint8</code> | the number of pin |
Return:
digital level(0/1)
**Example**
```arduino
uint32_t pin21_data;
pin21_data = digitalRead(21);
```
# I/O (GPIO/ADC/DAC/PWM)
*Refer to Arduino API of [Arduino](http://www.arduino.cc)*
*For the sake of convenience, I will focus on things that are closely related to M5Stack*
*M5STACK PIN allocation:*
| pin No | Name |allocation|
| --- | --- | --- |
| 0 | G0 |downloader |
| 1 | T1 |UART |
| 2 | G2 |Side terminal (except M5FIRE),M5-BUS|
| 3 | R1 |UART |
| 4 | G4 |TF|
| 5 | G5 |Side terminal (except M5FIRE),M5-BUS|
| 6 | G6 |SDIO |
| 7 | G7 |SDIO |
| 8 | G8 |SDIO |
| 9 | G9 |SDIO |
| 10 | G10 |SDIO |
| 11 | G11 |SDIO |
| 12 | G12 |LCD |
| 13 | G13 |LCD |
| 14 | G14 |LCD |
| 15 | G15 |LCD |
| 16 | R2 |UART |
| 17 | T2 |UART |
| 18 | G18 |TF,Top terminal(SCK),M5-BUS|
| 19 | G19 |TF,Top terminal(MISO),M5-BUS|
| 21 | G21 |GROVE-A(SDA)|
| 22 | G22 |GROVE-A(SCL)|
| 23 | G23 |TF,Top terminal(MOSI)|
| 25 | G25 |Speaker,Side terminal (except M5FIRE),M5-BUS|
| 26 | G26 |Side terminal (except M5FIRE),M5-BUS|
| 27 | G27 |LCD |
| 32 | G32 |LCD BackLight |
| 33 | G33 |LCD |
| 34 | G34 |None |
| 35 | G35 |Side terminal (except M5FIRE)|
| 36 | G36 |Side terminal (except M5FIRE)|
| 37 | G37 |Button C|
| 38 | G38 |Button B|
| 39 | G39 |Button A|
## digitalRead()
**Syntax:**
<mark>int digitalRead(uint8_t pin);</mark>
**Description:**
Reads the state of the terminal.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| pin | <code>uint8</code> |Pin No |
**Function return value:**
Pin input state(0/1)
**Note**
1)If the pin mode is not set to INPUT, the correct result will not be returned.
2)If there are other circuits in the control line, they will be affected.
**Example of use;**
```arduino
uint32_t pin21_data;
pin21_data = digitalRead(21);
```
## digitalWrite()
**Syntax:**
<mark>void digitalWrite(uint8_t pin, uint8_t val);</mark>
**Description:**
Writes the state of the terminal.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| pin | <code>uint8</code> |pin No |
| val | <code>uint8</code> |出力状態(0/1) |
**Function return value:**
None.
**Note**
1)If the pin mode is not set to OUTPUT, the correct result will not be returned.
2)If there are other circuits in the control line, please note it as it may be physically damaged.
**Example of use;**
```arduino
digitalWrite(2,1);
```
## pinMode()
**Syntax:**
<mark>void pinMode(uint8_t pin, uint8_t mode);</mark>
**Description:**
Set terminal input / output mode.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| pin | <code>uint8</code> |pin No |
| mode | <code>uint8</code> |INPUT,OUTPUT,INPUT_PULLUPのいずれか|
**Function return value:**
None.
**Note**
If there are other circuits on the bus, please note that there is a possibility of physical damage.
For example, when the speaker (G25) terminal is set to INPUT mode, the current flowing to the speaker causes the main unit to generate heat.
Make sure that the operations are correct as there is a risk of damage.
**Example of use;**
```arduino
pinMode(2,INPUT);
```
## analogRead()
**Syntax:**
<mark>uint16_t analogRead(uint8_t pin);</mark>
**Description:**
Reads the value of the analog terminal.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| pin | <code>uint8</code> |pin No |
**Function return value:**
Read result. The maximum value of the response is determined by analogSetWidth ().
**Note**
G35 and G36 can be used in M5Stack.
**Example of use;**
```arduino
uint16_t ret;
ret=analogRead(35);
```
## dacWrite()
**Syntax:**
<mark>void dacWrite(uint8_t pin, uint8_t value);</mark>
**Description:**
Output command to analog terminal.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| pin | <code>uint8</code> |pin No |
| value | <code>uint8</code> |set output voltage |
**Function return value:**
None.。
**Note**
G25 and G26 can be used in M5Stack.
**Example of use;**
```arduino
dacWrite(25,0x40);
```
## ledcSetup()
**Syntax:**
<mark>double ledcSetup(uint8_t channel, double freq, uint8_t resolution_bits);</mark>
**Description:**
Set the duty output
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| channel | <code>uint8</code> |channel (015) |
| freq | <code>double</code> |frequency (Hz) |
| resolution_bits | <code>uint8_t</code> |Number of full scale bits for duty indication |
**Function return value:**
Actual output frequency.
**Note**
Channel and GPIO port numbers are not identical.
It is good to recognize that it is a number to memorize the setting.
## ledcAttachPin()
**Syntax:**
<mark>void ledcAttachPin(uint8_t pin, uint8_t chan);</mark>
**Description:**
Specify the port to output.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| pin | <code>uint8_t</code> |pin No) |
| chan | <code>uint8_t</code> |Channel(015) |
**Function return value:**
None.
## ledcWrite()
**Syntax:**
<mark>void ledcWrite(uint8_t chan, uint32_t duty);</mark>
**Description:**
Output with the specified duty value.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| chan | <code>uint8_t</code> |Channel(015) |
| duty | <code>uint32_t</code> |Duty |
**Function return value:**
None.
**Note**
The unit of duty depends on the bit scale set at initialization.
When specifying with 8 bits, specifying 0xFF results in 100% output.
## ledcDetachPin()
**Syntax:**
<mark>void ledcDetachPin(uint8_t pin);</mark>
**Description:**
Release the assigned port and stop the output.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| pin | <code>uint8_t</code> |pin No) |
**Function return value:**
None.
+418 -209
View File
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -7,7 +7,8 @@
|**[システム](ja/api/system)** | **[スピーカー](ja/api/speaker)** |
|**[LCD 画面表示](ja/api/lcd)** | **[ボタン](ja/api/button)** |
|**[IMUセンサー(MPU9250)](ja/api/mpu9250)** | **[TFカード(SDカード)](ja/api/tf)** |
|**[電源](ja/api/power)** | |
|**[電源](ja/api/power)** |**[I/O](ja/api/gpio)** |
|**[I2C通信](ja/api/commutil)** | |
## M5StickC
+215
View File
@@ -0,0 +1,215 @@
# I2C
M5StackのGrove-Aポート(I2C)を制御するクラスです。
あらかじめ M5.Begin()でI2C通信が初期化されている必要があります。
## writeCommand()
**構文:**
<mark>bool writeCommand(uint8_t address, uint8_t subAddress);</mark>
**説明:**
指定のアドレスに書きこみます。
パラメータがない場合に使います。
**引数**
| 引数 |型 |説明 |
| --- | --- | --- |
| address | <code>uint8_t</code> |スレーブアドレス |
| subAddress | <code>uint8_t</code> |機能アドレス |
**戻り値:**
| 値 |説明 |
| --- | --- |
|true|送信成功。|
|false|送信失敗。|
## writeByte()
**構文:**
<mark>bool writeByte(uint8_t address, uint8_t subAddress, uint8_t data);</mark>
**説明:**
指定のアドレスに書きこみます。
パラメータ1つある場合に使います。
**引数**
| 引数 |型 |説明 |
| --- | --- | --- |
| address | <code>uint8_t</code> |スレーブアドレス |
| subAddress | <code>uint8_t</code> |機能アドレス |
| data | <code>uint8_t</code> |パラメータ |
**戻り値:**
| 値 |説明 |
| --- | --- |
|true|送信成功。|
|false|送信失敗。|
## writeBytes()
**構文:**
<mark> bool writeBytes(uint8_t address, uint8_t subAddress, uint8_t *data,uint8_t length);</mark>
**説明:**
指定のアドレスに書きこみます。
パラメータが複数ある場合に使います。
**引数**
| 引数 |型 |説明 |
| --- | --- | --- |
| address | <code>uint8_t</code> |スレーブアドレス |
| subAddress | <code>uint8_t</code> |機能アドレス |
| data | <code>uint8_t *</code> |パラメータ配列の先頭 |
| length | <code>uint8_t</code> |パラメータ長 |
**戻り値:**
| 値 |説明 |
| --- | --- |
|true|送信成功。|
|false|送信失敗。|
## readByte()
**構文:**
<mark> bool readByte(uint8_t address, uint8_t *result);</mark>
**説明:**
指定のアドレスから読み込みます。
読み込み前に送信するデータがなく、返答が1バイトの場合に使います。
**引数**
| 引数 |型 |説明 |
| --- | --- | --- |
| address | <code>uint8_t</code> |スレーブアドレス |
| result | <code>uint8_t *</code> |結果格納先 |
**戻り値:**
| 値 |説明 |
| --- | --- |
|true|読込成功。|
|false|読込失敗。|
## readByte()
**構文:**
<mark>bool readByte(uint8_t address, uint8_t subAddress,uint8_t *result);</mark>
**説明:**
指定のアドレスから読み込みます。
読み込み前に送信するデータが機能アドレスのみで、返答が1バイトの場合に使います。
**引数**
| 引数 |型 |説明 |
| --- | --- | --- |
| address | <code>uint8_t</code> |スレーブアドレス |
| subAddress | <code>uint8_t</code> |機能アドレス |
| result | <code>uint8_t *</code> |結果格納先 |
**戻り値:**
| 値 |説明 |
| --- | --- |
|true|読込成功。|
|false|読込失敗。|
## readBytes()
**構文:**
<mark>bool readBytes(uint8_t address, uint8_t count,uint8_t * dest);</mark>
**説明:**
指定のアドレスから読み込みます。
読み込み前に送信するデータがなく、返答が複数ある場合に使います。
**引数**
| 引数 |型 |説明 |
| --- | --- | --- |
| address | <code>uint8_t</code> |スレーブアドレス |
| count | <code>uint8_t</code> |要求バイト数 |
| result | <code>uint8_t *</code> |結果格納先 |
**戻り値:**
| 値 |説明 |
| --- | --- |
|true|読込成功。|
|false|読込失敗。|
## readBytes()
**構文:**
<mark>bool readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t * dest);</mark>
**説明:**
指定のアドレスから読み込みます。
読み込み前に送信するデータが機能アドレスのみで、返答が複数ある場合に使います。
**引数**
| 引数 |型 |説明 |
| --- | --- | --- |
| address | <code>uint8_t</code> |スレーブアドレス |
| subAddress | <code>uint8_t</code> |機能アドレス |
| count | <code>uint8_t</code> |要求バイト数 |
| result | <code>uint8_t *</code> |結果格納先 |
**戻り値:**
| 値 |説明 |
| --- | --- |
|true|読込成功。|
|false|読込失敗。|
## scanID()
**構文:**
<mark>bool readBytes(bool *result);</mark>
**説明:**
I2Cバス上のデバイス存在確認をおこないます。
**引数**
| 引数 |型 |説明 |
| --- | --- | --- |
| result | <code>bool *</code> |結果格納先 (128バイト) |
**戻り値:**
| 値 |説明 |
| --- | --- |
|true|読込成功。|
|false|読込失敗。|
**使用例;**
```arduino
bool result[0x80];
M5.I2C.scanID(&result[0]);
```
+311 -23
View File
@@ -1,23 +1,311 @@
# GPIO {docsify-ignore-all}
*Refer to GPIO API of [Arduino](http://www.arduino.cc)*
### <mark>digitalRead</mark>
> uint32 digitalRead(uint8 pin);
Read the value of `pin`
| Param | Type | Description |
| --- | --- | --- |
| pin | <code>uint8</code> | the number of pin |
Return:
digital level(0/1)
**Example**
```arduino
uint32_t pin21_data;
pin21_data = digitalRead(21);
```
# I/O (GPIO/ADC/DAC/PWM)
*詳しくは [Arduino](http://www.arduino.cc) の マニュアルを見てください*
*便宜上、M5Stackに関連の深いものに絞って説明します*
**M5STACK割り当て:**
| pin番号 | 名称 |割り当て先|
| --- | --- | --- |
| 0 | G0 |ダウンローダ |
| 1 | T1 |UART |
| 2 | G2 |側面端子(M5FIREを除く),M5-BUS|
| 3 | R1 |UART |
| 4 | G4 |TF|
| 5 | G5 |側面端子(M5FIREを除く),M5-BUS|
| 6 | G6 |SDIO |
| 7 | G7 |SDIO |
| 8 | G8 |SDIO |
| 9 | G9 |SDIO |
| 10 | G10 |SDIO |
| 11 | G11 |SDIO |
| 12 | G12 |LCD |
| 13 | G13 |LCD |
| 14 | G14 |LCD |
| 15 | G15 |LCD |
| 16 | R2 |UART |
| 17 | T2 |UART |
| 18 | G18 |TF,上面端子(SCK),M5-BUS|
| 19 | G19 |TF,上面端子(MISO),M5-BUS|
| 21 | G21 |GROVE-A(SDA)|
| 22 | G22 |GROVE-A(SCL)|
| 23 | G23 |TF,上面端子(MOSI)|
| 25 | G25 |スピーカ,側面端子(M5FIREを除く),M5-BUS|
| 26 | G26 |側面端子(M5FIREを除く),M5-BUS|
| 27 | G27 |LCD |
| 32 | G32 |LCDバックライト |
| 33 | G33 |LCD |
| 34 | G34 |なし |
| 35 | G35 |側面端子(M5FIREを除く)|
| 36 | G36 |側面端子(M5FIREを除く)|
| 37 | G37 |Cボタン|
| 38 | G38 |Bボタン|
| 39 | G39 |Aボタン|
## digitalRead()
**構文:**
<mark>int digitalRead(uint8_t pin);</mark>
**説明:**
端子の状態を読み取ります。
**引数**
| 引数 |型 |説明 |
| --- | --- | --- |
| pin | <code>uint8</code> |ピン番号 |
**戻り値:**
ピンの電圧入力状態(0/1)
**注意**
1)ピンモードがINPUTになっていない場合は正しい結果を返しません。
2)バスに他の回路がある場合、その影響を受けます。
**使用例;**
```arduino
uint32_t pin21_data;
pin21_data = digitalRead(21);
```
## digitalWrite()
**構文:**
<mark>void digitalWrite(uint8_t pin, uint8_t val);</mark>
**説明:**
端子の状態を書き込みます。
**引数**
| 引数 |型 |説明 |
| --- | --- | --- |
| pin | <code>uint8</code> |ピン番号 |
| val | <code>uint8</code> |出力状態(0/1) |
**戻り値:**
なし
**注意**
1)ピンモードがOUTPUTになっていない場合は正しい結果を返しません。
2)バスに他の回路がある場合、物理的に破損する可能性があるため、注意してください。
**使用例;**
```arduino
digitalWrite(2,1);
```
## pinMode()
**構文:**
<mark>void pinMode(uint8_t pin, uint8_t mode);</mark>
**説明:**
端子の入出力モードを設定します
**引数**
| 引数 |型 |説明 |
| --- | --- | --- |
| pin | <code>uint8</code> |ピン番号 |
| mode | <code>uint8</code> |INPUT,OUTPUT,INPUT_PULLUPのいずれか|
**戻り値:**
なし
**注意**
バスに他の回路がある場合、物理的に破損する可能性があるため、注意してください。
例えば、スピーカ(G25)端子をINPUTモードにすると、スピーカへ流れる電流により本体が発熱します。
故障の恐れがあるため、指示内容が正しいことを確認してください。
**使用例;**
```arduino
pinMode(2,INPUT);
```
## analogRead()
**構文:**
<mark>uint16_t analogRead(uint8_t pin);</mark>
**説明:**
アナログ端子の値を読み取ります。
**引数**
| 引数 |型 |説明 |
| --- | --- | --- |
| pin | <code>uint8</code> |ピン番号 |
**戻り値:**
読み取り結果。返答の最大値はanalogSetWidth()で決定します。
**注意**
M5StackではG35,G36が使用できます。
**使用例;**
```arduino
uint16_t ret;
ret=analogRead(35);
```
## dacWrite()
**構文:**
<mark>void dacWrite(uint8_t pin, uint8_t value);</mark>
**説明:**
アナログ端子に出力指示をします。
**引数**
| 引数 |型 |説明 |
| --- | --- | --- |
| pin | <code>uint8</code> |ピン番号 |
| value | <code>uint8</code> |出力指示電圧 |
**戻り値:**
なし。
**注意**
M5StackではG25,G26が使用できます。
**使用例;**
```arduino
dacWrite(25,0x40);
```
## ledcSetup()
**構文:**
<mark>double ledcSetup(uint8_t channel, double freq, uint8_t resolution_bits);</mark>
**説明:**
デューティ出力設定をします
**引数**
| 引数 |型 |説明 |
| --- | --- | --- |
| channel | <code>uint8</code> |チャネル(015) |
| freq | <code>double</code> |周波数(Hz) |
| resolution_bits | <code>uint8_t</code> |デューティ指示のフルスケールビット数 |
**戻り値:**
実際の出力周波数。
**注意**
チャンネルとGPIOポート番号は同一ではありません。
設定を記憶するための番号だと認識するとよいでしょう。
## ledcAttachPin()
**構文:**
<mark>void ledcAttachPin(uint8_t pin, uint8_t chan);</mark>
**説明:**
出力するポートを指定します。
**引数**
| 引数 |型 |説明 |
| --- | --- | --- |
| pin | <code>uint8_t</code> |ピン番号) |
| chan | <code>uint8_t</code> |チャネル(015) |
**戻り値:**
なし
## ledcWrite()
**構文:**
<mark>void ledcWrite(uint8_t chan, uint32_t duty);</mark>
**説明:**
指定したデューティ値で出力します。
**引数**
| 引数 |型 |説明 |
| --- | --- | --- |
| chan | <code>uint8_t</code> |チャネル(015) |
| duty | <code>uint32_t</code> |デューティ |
**戻り値:**
なし
**注意**
デューティの単位は、初期化時に設定したビットスケールに依存します。
8ビットで指示していた場合は 0xFF を指定すると100%出力になります。
## ledcDetachPin()
**構文:**
<mark>void ledcDetachPin(uint8_t pin);</mark>
**説明:**
割り当てたポートを解放し、出力をやめます。
**引数**
| 引数 |型 |説明 |
| --- | --- | --- |
| pin | <code>uint8_t</code> |ピン番号) |
**戻り値:**
なし
+409 -209
View File
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -7,7 +7,8 @@
|**[System](zh_CN/api/system)** | **[喇叭](zh_CN/api/speaker)** |
|**[LCD 屏](zh_CN/api/lcd)** | **[按键](zh_CN/api/button)** |
|**[MPU9250](zh_CN/api/mpu9250)** | **[TF 卡](zh_CN/api/tf)** |
|**[Power](zh_CN/api/power)** |
|**[电源管理](zh_CN/api/power)** |**[I/O](zh_CN/api/gpio)** |
|**[I2C 沟通](zh_CN/api/commutil)** | |
<!-- <table>
<tr>
+215
View File
@@ -0,0 +1,215 @@
# I2C
这是一个控制M5Stack的Grove-A端口(I2C)的类。
需要通过M5.Begin()预先初始化I2C通信。
## writeCommand()
**構文:**
<mark>bool writeCommand(uint8_t address, uint8_t subAddress);</mark>
**功能:**
写入指定的地址。
没有参数时使用。
**参数**
| 参数 |型 |功能 |
| --- | --- | --- |
| address | <code>uint8_t</code> |奴隶地址 |
| subAddress | <code>uint8_t</code> |功能地址 |
**返回值:**
| 値 |功能 |
| --- | --- |
|true|发送成功。|
|false|发送失败。|
## writeByte()
**構文:**
<mark>bool writeByte(uint8_t address, uint8_t subAddress, uint8_t data);</mark>
**功能:**
写入指定的地址。
有一个参数时使用。
**参数**
| 参数 |型 |功能 |
| --- | --- | --- |
| address | <code>uint8_t</code> |奴隶地址 |
| subAddress | <code>uint8_t</code> |功能地址 |
| data | <code>uint8_t</code> |参数 |
**返回值:**
| 値 |功能 |
| --- | --- |
|true|发送成功。|
|false|发送失败。|
## writeBytes()
**構文:**
<mark> bool writeBytes(uint8_t address, uint8_t subAddress, uint8_t *data,uint8_t length);</mark>
**功能:**
写入指定的地址。
在有多个参数时使用。
**参数**
| 参数 |型 |功能 |
| --- | --- | --- |
| address | <code>uint8_t</code> |奴隶地址 |
| subAddress | <code>uint8_t</code> |功能地址 |
| data | <code>uint8_t *</code> |参数数组的开头 |
| length | <code>uint8_t</code> |参数长度 |
**返回值:**
| 値 |功能 |
| --- | --- |
|true|发送成功。|
|false|发送失败。|
## readByte()
**構文:**
<mark> bool readByte(uint8_t address, uint8_t *result);</mark>
**功能:**
从指定的地址读取。
在读取之前没有数据要发送且响应为1个字节时使用。
**参数**
| 参数 |型 |功能 |
| --- | --- | --- |
| address | <code>uint8_t</code> |奴隶地址 |
| result | <code>uint8_t *</code> |结果存储目的地 |
**返回值:**
| 値 |功能 |
| --- | --- |
|true|阅读成功。|
|false|读取失败。|
## readByte()
**構文:**
<mark>bool readByte(uint8_t address, uint8_t subAddress,uint8_t *result);</mark>
**功能:**
从指定的地址读取。
当读取前发送的数据仅为功能地址且响应为1个字节时使用。
**参数**
| 参数 |型 |功能 |
| --- | --- | --- |
| address | <code>uint8_t</code> |奴隶地址 |
| subAddress | <code>uint8_t</code> |功能地址 |
| result | <code>uint8_t *</code> |结果存储目的地 |
**返回值:**
| 値 |功能 |
| --- | --- |
|true|阅读成功。|
|false|读取失败。|
## readBytes()
**構文:**
<mark>bool readBytes(uint8_t address, uint8_t count,uint8_t * dest);</mark>
**功能:**
从指定的地址读取。
在加载之前没有数据要发送且有多个响应时使用。
**参数**
| 参数 |型 |功能 |
| --- | --- | --- |
| address | <code>uint8_t</code> |奴隶地址 |
| count | <code>uint8_t</code> |请求的字节数 |
| result | <code>uint8_t *</code> |结果存储目的地 |
**返回值:**
| 値 |功能 |
| --- | --- |
|true|阅读成功。|
|false|读取失败。|
## readBytes()
**構文:**
<mark>bool readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t * dest);</mark>
**功能:**
从指定的地址读取。
当在读取之前要发送的数据仅是功能地址并且存在多个响应时使用它。
**参数**
| 参数 |型 |功能 |
| --- | --- | --- |
| address | <code>uint8_t</code> |奴隶地址 |
| subAddress | <code>uint8_t</code> |功能地址 |
| count | <code>uint8_t</code> |请求的字节数 |
| result | <code>uint8_t *</code> |结果存储目的地 |
**返回值:**
| 値 |功能 |
| --- | --- |
|true|阅读成功。|
|false|读取失败。|
## scanID()
**構文:**
<mark>bool readBytes(bool *result);</mark>
**功能:**
在I2C总线上执行设备存在检查。
**参数**
| 参数 |型 |功能 |
| --- | --- | --- |
| result | <code>bool *</code> |结果存储目标(128字节) |
**返回值:**
| 値 |功能 |
| --- | --- |
|true|阅读成功。|
|false|读取失败。|
**使用示例;**
```arduino
bool result[0x80];
M5.I2C.scanID(&result[0]);
```
+307
View File
@@ -0,0 +1,307 @@
# I/O (GPIO/ADC/DAC/PWM)
*Refer to Arduino API of [Arduino](http://www.arduino.cc)*
*为方便起见,我将专注于与M5Stack 密切相关的事情*
**M5STACK 引脚排列:**
| pin No | Name |allocation|
| --- | --- | --- |
| 0 | G0 |downloader |
| 1 | T1 |UART |
| 2 | G2 |Side terminal (except M5FIRE),M5-BUS|
| 3 | R1 |UART |
| 4 | G4 |TF|
| 5 | G5 |Side terminal (except M5FIRE),M5-BUS|
| 6 | G6 |SDIO |
| 7 | G7 |SDIO |
| 8 | G8 |SDIO |
| 9 | G9 |SDIO |
| 10 | G10 |SDIO |
| 11 | G11 |SDIO |
| 12 | G12 |LCD |
| 13 | G13 |LCD |
| 14 | G14 |LCD |
| 15 | G15 |LCD |
| 16 | R2 |UART |
| 17 | T2 |UART |
| 18 | G18 |TF,Top terminal(SCK),M5-BUS|
| 19 | G19 |TF,Top terminal(MISO),M5-BUS|
| 21 | G21 |GROVE-A(SDA)|
| 22 | G22 |GROVE-A(SCL)|
| 23 | G23 |TF,Top terminal(MOSI)|
| 25 | G25 |Speaker,Side terminal (except M5FIRE),M5-BUS|
| 26 | G26 |Side terminal (except M5FIRE),M5-BUS|
| 27 | G27 |LCD |
| 32 | G32 |LCD BackLight |
| 33 | G33 |LCD |
| 34 | G34 |None |
| 35 | G35 |Side terminal (except M5FIRE)|
| 36 | G36 |Side terminal (except M5FIRE)|
| 37 | G37 |Button C|
| 38 | G38 |Button B|
| 39 | G39 |Button A|
## digitalRead()
**構文:**
<mark>int digitalRead(uint8_t pin);</mark>
**功能:**
读取终端的状态。
**参数**
| 参数 |型 |功能 |
| --- | --- | --- |
| pin | <code>uint8</code> |Pin No |
**返回值:**
引脚输入状态(0/1
**注意**
1)如果引脚模式未设置为INPUT,则不会返回正确的结果。
2)如果控制线中有其他电路,它们将受到影响。
**使用示例;**
```arduino
uint32_t pin21_data;
pin21_data = digitalRead(21);
```
## digitalWrite()
**構文:**
<mark>void digitalWrite(uint8_t pin, uint8_t val);</mark>
**功能:**
指示终端的输出
**参数**
| 参数 |型 |功能 |
| --- | --- | --- |
| pin | <code>uint8</code> |pin No |
| val | <code>uint8</code> |输出状态(0/1) |
**返回值:**
无。
**注意**
1)如果终端模式未设置为OUTPUT,则不会返回正确的结果。
2)请注意,如果控制线中有其他电路,则可能会造成物理损坏。
**使用示例;**
```arduino
digitalWrite(2,1);
```
## pinMode()
**構文:**
<mark>void pinMode(uint8_t pin, uint8_t mode);</mark>
**功能:**
设置终端输入/输出模式。
**参数**
| 参数 |型 |功能 |
| --- | --- | --- |
| pin | <code>uint8</code> |pin No |
| mode | <code>uint8</code> |INPUT,OUTPUT,INPUT_PULLUP 的任何一个|
**返回值:**
无。
**注意**
如果总线上有其他电路,请注意可能存在物理损坏。
例如,当扬声器(G25)端子设置为INPUT模式时,流向扬声器的电流使主单元产生热量。
确保操作正确,因为存在损坏风险。
**使用示例;**
```arduino
pinMode(2,INPUT);
```
## analogRead()
**構文:**
<mark>uint16_t analogRead(uint8_t pin);</mark>
**功能:**
读取模拟终端的值。
**参数**
| 参数 |型 |功能 |
| --- | --- | --- |
| pin | <code>uint8</code> |pin No |
**返回值:**
阅读结果。响应的最大值由analogSetWidth()确定。
**注意**
G35和G36可用于M5Stack。
**使用示例;**
```arduino
uint16_t ret;
ret=analogRead(35);
```
## dacWrite()
**構文:**
<mark>void dacWrite(uint8_t pin, uint8_t value);</mark>
**功能:**
输出命令到模拟端子。
**参数**
| 参数 |型 |功能 |
| --- | --- | --- |
| pin | <code>uint8</code> |pin No |
| value | <code>uint8</code> |设定输出电压 |
**返回值:**
无。。
**注意**
G25和G26可用于M5Stack。
**使用示例;**
```arduino
dacWrite(25,0x40);
```
## ledcSetup()
**構文:**
<mark>double ledcSetup(uint8_t channel, double freq, uint8_t resolution_bits);</mark>
**功能:**
设置占空比输出
**参数**
| 参数 |型 |功能 |
| --- | --- | --- |
| channel | <code>uint8</code> |channel (015) |
| freq | <code>double</code> |frequency (Hz) |
| resolution_bits | <code>uint8_t</code> |占空比指示的满量程位数|
**返回值:**
Actual output frequency.
**注意**
通道和GPIO端口号不相同。
它应该被识别为用于存储设置的数字。
## ledcAttachPin()
**構文:**
<mark>void ledcAttachPin(uint8_t pin, uint8_t chan);</mark>
**功能:**
Specify the port to output.
**参数**
| 参数 |型 |功能 |
| --- | --- | --- |
| pin | <code>uint8_t</code> |pin No) |
| chan | <code>uint8_t</code> |渠道(015) |
**返回值:**
无。
## ledcWrite()
**構文:**
<mark>void ledcWrite(uint8_t chan, uint32_t duty);</mark>
**功能:**
输出具有指定的占空比值
**参数**
| 参数 |型 |功能 |
| --- | --- | --- |
| chan | <code>uint8_t</code> |渠道(015) |
| duty | <code>uint32_t</code> |比 |
**返回值:**
无。
**注意**
占空比取决于初始化时设置的位比例。
使用8位指定时,指定0xFF会导致100%输出。
## ledcDetachPin()
**構文:**
<mark>void ledcDetachPin(uint8_t pin);</mark>
**功能:**
释放指定的端口并停止输出。
**参数**
| 参数 |型 |功能 |
| --- | --- | --- |
| pin | <code>uint8_t</code> |pin No |
**返回值:**
无。
+411 -207
View File
File diff suppressed because it is too large Load Diff