diff --git a/docs/en/api.md b/docs/en/api.md index fced5af3..6ae59513 100644 --- a/docs/en/api.md +++ b/docs/en/api.md @@ -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)** | | diff --git a/docs/en/api/commutil.md b/docs/en/api/commutil.md index 8b20a16f..bac0a7ef 100644 --- a/docs/en/api/commutil.md +++ b/docs/en/api/commutil.md @@ -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]); +``` diff --git a/docs/en/api/gpio.md b/docs/en/api/gpio.md index de868a6b..0b57d019 100644 --- a/docs/en/api/gpio.md +++ b/docs/en/api/gpio.md @@ -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 | uint8 | the number of pin | - -Return: - digital level(0/1) - -**Example** -```arduino -uint32_t pin21_data; -pin21_data = digitalRead(21); -``` \ No newline at end of file +# 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:** + +int digitalRead(uint8_t pin); + +**Description:** + +Reads the state of the terminal. + +**Function argument** + +| Function argument |Type |Description | +| --- | --- | --- | +| pin | uint8 |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:** + +void digitalWrite(uint8_t pin, uint8_t val); + +**Description:** + +Writes the state of the terminal. + +**Function argument** + +| Function argument |Type |Description | +| --- | --- | --- | +| pin | uint8 |pin No | +| val | uint8 |出力状態(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:** + +void pinMode(uint8_t pin, uint8_t mode); + +**Description:** + +Set terminal input / output mode. + +**Function argument** + +| Function argument |Type |Description | +| --- | --- | --- | +| pin | uint8 |pin No | +| mode | uint8 |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:** +uint16_t analogRead(uint8_t pin); + +**Description:** + +Reads the value of the analog terminal. + +**Function argument** + +| Function argument |Type |Description | +| --- | --- | --- | +| pin | uint8 |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:** + +void dacWrite(uint8_t pin, uint8_t value); + +**Description:** + +Output command to analog terminal. + +**Function argument** + +| Function argument |Type |Description | +| --- | --- | --- | +| pin | uint8 |pin No | +| value | uint8 |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:** + +double ledcSetup(uint8_t channel, double freq, uint8_t resolution_bits); + +**Description:** + +Set the duty output + +**Function argument** + +| Function argument |Type |Description | +| --- | --- | --- | +| channel | uint8 |channel (0~15) | +| freq | double |frequency (Hz) | +| resolution_bits | uint8_t |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:** + +void ledcAttachPin(uint8_t pin, uint8_t chan); + +**Description:** + +Specify the port to output. + +**Function argument** + +| Function argument |Type |Description | +| --- | --- | --- | +| pin | uint8_t |pin No) | +| chan | uint8_t |Channel(0~15) | + +**Function return value:** + +None. + + +## ledcWrite() + +**Syntax:** + +void ledcWrite(uint8_t chan, uint32_t duty); + +**Description:** + +Output with the specified duty value. + +**Function argument** + +| Function argument |Type |Description | +| --- | --- | --- | +| chan | uint8_t |Channel(0~15) | +| duty | uint32_t |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:** + +void ledcDetachPin(uint8_t pin); + +**Description:** + +Release the assigned port and stop the output. + +**Function argument** + +| Function argument |Type |Description | +| --- | --- | --- | +| pin | uint8_t |pin No) | + + +**Function return value:** + +None. diff --git a/docs/ja/api.md b/docs/ja/api.md index 04789ebb..d03e9d68 100644 --- a/docs/ja/api.md +++ b/docs/ja/api.md @@ -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 diff --git a/docs/ja/api/commutil.md b/docs/ja/api/commutil.md index e5a73427..092c933d 100644 --- a/docs/ja/api/commutil.md +++ b/docs/ja/api/commutil.md @@ -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]); +``` diff --git a/docs/ja/api/gpio.md b/docs/ja/api/gpio.md index 0861063d..42e19332 100644 --- a/docs/ja/api/gpio.md +++ b/docs/ja/api/gpio.md @@ -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() **構文:** - uint32 digitalRead(uint8 pin); + +int digitalRead(uint8_t pin); **説明:** -端子の状態を読み取ります。` +端子の状態を読み取ります。 **引数** @@ -18,11 +60,252 @@ | --- | --- | --- | | pin | uint8 |ピン番号 | -戻り値: - ピンの電圧入力状態(0/1) +**戻り値:** + +ピンの電圧入力状態(0/1) + +**注意** + +1)ピンモードがINPUTになっていない場合は正しい結果を返しません。 + +2)バスに他の回路がある場合、その影響を受けます。 **使用例;** ```arduino uint32_t pin21_data; pin21_data = digitalRead(21); -``` \ No newline at end of file +``` + +## digitalWrite() + +**構文:** + +void digitalWrite(uint8_t pin, uint8_t val); + +**説明:** + +端子の状態を書き込みます。 + +**引数** + +| 引数 |型 |説明 | +| --- | --- | --- | +| pin | uint8 |ピン番号 | +| val | uint8 |出力状態(0/1) | + +**戻り値:** + +なし + +**注意** + +1)ピンモードがOUTPUTになっていない場合は正しい結果を返しません。 + +2)バスに他の回路がある場合、物理的に破損する可能性があるため、注意してください。 + + +**使用例;** + +```arduino +digitalWrite(2,1); +``` + +## pinMode() + +**構文:** + +void pinMode(uint8_t pin, uint8_t mode); + +**説明:** + +端子の入出力モードを設定します + +**引数** + +| 引数 |型 |説明 | +| --- | --- | --- | +| pin | uint8 |ピン番号 | +| mode | uint8 |INPUT,OUTPUT,INPUT_PULLUPのいずれか| + +**戻り値:** + +なし + +**注意** + +バスに他の回路がある場合、物理的に破損する可能性があるため、注意してください。 + +例えば、スピーカ(G25)端子をINPUTモードにすると、スピーカへ流れる電流により本体が発熱します。 + +故障の恐れがあるため、指示内容が正しいことを確認してください。 + +**使用例;** + +```arduino +pinMode(2,INPUT); +``` + +## analogRead() + +**構文:** +uint16_t analogRead(uint8_t pin); + +**説明:** + +アナログ端子の値を読み取ります。 + +**引数** + +| 引数 |型 |説明 | +| --- | --- | --- | +| pin | uint8 |ピン番号 | + +**戻り値:** + +読み取り結果。返答の最大値はanalogSetWidth()で決定します。 + +**注意** + +M5StackではG35,G36が使用できます。 + +**使用例;** + +```arduino +uint16_t ret; +ret=analogRead(35); +``` + +## dacWrite() + +**構文:** + +void dacWrite(uint8_t pin, uint8_t value); + +**説明:** + +アナログ端子に出力指示をします。 + +**引数** + +| 引数 |型 |説明 | +| --- | --- | --- | +| pin | uint8 |ピン番号 | +| value | uint8 |出力指示電圧 | + +**戻り値:** + +なし。 + +**注意** + +M5StackではG25,G26が使用できます。 + +**使用例;** + +```arduino +dacWrite(25,0x40); +``` + +## ledcSetup() + +**構文:** + +double ledcSetup(uint8_t channel, double freq, uint8_t resolution_bits); + +**説明:** + +デューティ出力設定をします + +**引数** + +| 引数 |型 |説明 | +| --- | --- | --- | +| channel | uint8 |チャネル(0~15) | +| freq | double |周波数(Hz) | +| resolution_bits | uint8_t |デューティ指示のフルスケールビット数 | + +**戻り値:** + +実際の出力周波数。 + +**注意** + +チャンネルとGPIOポート番号は同一ではありません。 + +設定を記憶するための番号だと認識するとよいでしょう。 + + + +## ledcAttachPin() + +**構文:** + +void ledcAttachPin(uint8_t pin, uint8_t chan); + +**説明:** + +出力するポートを指定します。 + +**引数** + +| 引数 |型 |説明 | +| --- | --- | --- | +| pin | uint8_t |ピン番号) | +| chan | uint8_t |チャネル(0~15) | + +**戻り値:** + +なし + + + + +## ledcWrite() + +**構文:** + +void ledcWrite(uint8_t chan, uint32_t duty); + +**説明:** + +指定したデューティ値で出力します。 + +**引数** + +| 引数 |型 |説明 | +| --- | --- | --- | +| chan | uint8_t |チャネル(0~15) | +| duty | uint32_t |デューティ | + +**戻り値:** + +なし + +**注意** + +デューティの単位は、初期化時に設定したビットスケールに依存します。 + +8ビットで指示していた場合は 0xFF を指定すると100%出力になります。 + + + +## ledcDetachPin() + +**構文:** + +void ledcDetachPin(uint8_t pin); + +**説明:** + +割り当てたポートを解放し、出力をやめます。 + +**引数** + +| 引数 |型 |説明 | +| --- | --- | --- | +| pin | uint8_t |ピン番号) | + + +**戻り値:** + +なし diff --git a/docs/zh_CN/api.md b/docs/zh_CN/api.md index 46829f1f..0c5f1a93 100644 --- a/docs/zh_CN/api.md +++ b/docs/zh_CN/api.md @@ -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)** | |