mirror of
https://github.com/m5stack/m5-docs.git
synced 2026-05-20 10:23:01 -07:00
Add: write documents around I/O.
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@
|
||||
|**[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)** |[GPIO](en/api/gpio)** |
|
||||
|**[Power](en/api/power)** |**[I/O](en/api/gpio)** |
|
||||
|**[I2C Communication](en/api/commutil)** | |
|
||||
|
||||
|
||||
|
||||
@@ -208,4 +208,9 @@ Perform device presence check on I2C bus.
|
||||
|true|Read success|
|
||||
|false|Read failure|
|
||||
|
||||
**Example of use;**
|
||||
|
||||
```arduino
|
||||
bool result[0x80];
|
||||
M5.I2C.scanID(&result[0]);
|
||||
```
|
||||
|
||||
+309
-21
@@ -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 (0~15) |
|
||||
| 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(0~15) |
|
||||
|
||||
**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(0~15) |
|
||||
| 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.
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
|**[システム](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)** |[GPIO](ja/api/gpio)** |
|
||||
|**[電源](ja/api/power)** |**[I/O](ja/api/gpio)** |
|
||||
|**[I2C通信](ja/api/commutil)** | |
|
||||
|
||||
## M5StickC
|
||||
|
||||
@@ -23,6 +23,7 @@ M5StackのGrove-Aポート(I2C)を制御するクラスです。
|
||||
**戻り値:**
|
||||
|
||||
| 値 |説明 |
|
||||
| --- | --- |
|
||||
|true|送信成功。|
|
||||
|false|送信失敗。|
|
||||
|
||||
@@ -205,4 +206,10 @@ I2Cバス上のデバイス存在確認をおこないます。
|
||||
|true|読込成功。|
|
||||
|false|読込失敗。|
|
||||
|
||||
**使用例;**
|
||||
|
||||
```arduino
|
||||
bool result[0x80];
|
||||
M5.I2C.scanID(&result[0]);
|
||||
```
|
||||
|
||||
|
||||
+291
-8
@@ -1,16 +1,58 @@
|
||||
# GPIO {docsify-ignore-all}
|
||||
# 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ボタン|
|
||||
|
||||
|
||||
|
||||
*詳しくは [Arduino](http://www.arduino.cc) の GPIOマニュアルを見てください*
|
||||
## digitalRead()
|
||||
|
||||
**構文:**
|
||||
<mark> uint32 digitalRead(uint8 pin);</mark>
|
||||
|
||||
<mark>int digitalRead(uint8_t pin);</mark>
|
||||
|
||||
**説明:**
|
||||
|
||||
端子の状態を読み取ります。`
|
||||
端子の状態を読み取ります。
|
||||
|
||||
**引数**
|
||||
|
||||
@@ -18,11 +60,252 @@
|
||||
| --- | --- | --- |
|
||||
| pin | <code>uint8</code> |ピン番号 |
|
||||
|
||||
戻り値:
|
||||
ピンの電圧入力状態(0/1)
|
||||
**戻り値:**
|
||||
|
||||
ピンの電圧入力状態(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> |チャネル(0~15) |
|
||||
| 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> |チャネル(0~15) |
|
||||
|
||||
**戻り値:**
|
||||
|
||||
なし
|
||||
|
||||
|
||||
|
||||
|
||||
## ledcWrite()
|
||||
|
||||
**構文:**
|
||||
|
||||
<mark>void ledcWrite(uint8_t chan, uint32_t duty);</mark>
|
||||
|
||||
**説明:**
|
||||
|
||||
指定したデューティ値で出力します。
|
||||
|
||||
**引数**
|
||||
|
||||
| 引数 |型 |説明 |
|
||||
| --- | --- | --- |
|
||||
| chan | <code>uint8_t</code> |チャネル(0~15) |
|
||||
| duty | <code>uint32_t</code> |デューティ |
|
||||
|
||||
**戻り値:**
|
||||
|
||||
なし
|
||||
|
||||
**注意**
|
||||
|
||||
デューティの単位は、初期化時に設定したビットスケールに依存します。
|
||||
|
||||
8ビットで指示していた場合は 0xFF を指定すると100%出力になります。
|
||||
|
||||
|
||||
|
||||
## ledcDetachPin()
|
||||
|
||||
**構文:**
|
||||
|
||||
<mark>void ledcDetachPin(uint8_t pin);</mark>
|
||||
|
||||
**説明:**
|
||||
|
||||
割り当てたポートを解放し、出力をやめます。
|
||||
|
||||
**引数**
|
||||
|
||||
| 引数 |型 |説明 |
|
||||
| --- | --- | --- |
|
||||
| pin | <code>uint8_t</code> |ピン番号) |
|
||||
|
||||
|
||||
**戻り値:**
|
||||
|
||||
なし
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
|**[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)** |
|
||||
|**[电源管理](zh_CN/api/power)** |[GPIO](zh_CN/api/gpio)** |
|
||||
|**[电源管理](zh_CN/api/power)** |**[I/O](zh_CN/api/gpio)** |
|
||||
|**[I2C 沟通](zh_CN/api/commutil)** | |
|
||||
|
||||
<!-- <table>
|
||||
|
||||
@@ -206,4 +206,10 @@
|
||||
|false|读取失败。|
|
||||
|
||||
|
||||
**使用示例;**
|
||||
|
||||
```arduino
|
||||
bool result[0x80];
|
||||
M5.I2C.scanID(&result[0]);
|
||||
```
|
||||
|
||||
|
||||
+307
-21
@@ -1,21 +1,307 @@
|
||||
# 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)*
|
||||
|
||||
*为方便起见,我将专注于与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 (0~15) |
|
||||
| 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> |渠道(0~15) |
|
||||
|
||||
**返回值:**
|
||||
|
||||
无。
|
||||
|
||||
|
||||
## ledcWrite()
|
||||
|
||||
**構文:**
|
||||
|
||||
<mark>void ledcWrite(uint8_t chan, uint32_t duty);</mark>
|
||||
|
||||
**功能:**
|
||||
|
||||
输出具有指定的占空比值
|
||||
|
||||
**参数**
|
||||
|
||||
| 参数 |型 |功能 |
|
||||
| --- | --- | --- |
|
||||
| chan | <code>uint8_t</code> |渠道(0~15) |
|
||||
| duty | <code>uint32_t</code> |比 |
|
||||
|
||||
**返回值:**
|
||||
|
||||
无。
|
||||
|
||||
**注意**
|
||||
|
||||
占空比取决于初始化时设置的位比例。
|
||||
|
||||
使用8位指定时,指定0xFF会导致100%输出。
|
||||
|
||||
|
||||
## ledcDetachPin()
|
||||
|
||||
**構文:**
|
||||
|
||||
<mark>void ledcDetachPin(uint8_t pin);</mark>
|
||||
|
||||
**功能:**
|
||||
|
||||
释放指定的端口并停止输出。
|
||||
|
||||
**参数**
|
||||
|
||||
| 参数 |型 |功能 |
|
||||
| --- | --- | --- |
|
||||
| pin | <code>uint8_t</code> |pin No |
|
||||
|
||||
|
||||
**返回值:**
|
||||
|
||||
无。
|
||||
|
||||
Reference in New Issue
Block a user