From 8c7d40b08bd44415bf08e0ee7b97b4015cf50e65 Mon Sep 17 00:00:00 2001 From: watson8544 <854410664@qq.com> Date: Mon, 8 Apr 2019 23:36:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh_CN/api/axp192_m5stickc.md | 100 +++++++++++++++++++ docs/zh_CN/api/sh200q_m5stickc.md | 95 ++++++++++++++++++ docs/zh_CN/api/system_m5stickc.md | 157 ++++++++++++++++++++++++++++++ 3 files changed, 352 insertions(+) create mode 100644 docs/zh_CN/api/axp192_m5stickc.md create mode 100644 docs/zh_CN/api/sh200q_m5stickc.md create mode 100644 docs/zh_CN/api/system_m5stickc.md diff --git a/docs/zh_CN/api/axp192_m5stickc.md b/docs/zh_CN/api/axp192_m5stickc.md new file mode 100644 index 00000000..e6e5b9c3 --- /dev/null +++ b/docs/zh_CN/api/axp192_m5stickc.md @@ -0,0 +1,100 @@ +# AXP192 + +*AXP192 是一款高度集成的电源系统管理芯片。* + +## begin() + +**函数原型:** + +void begin(void); + +**功能:初始化 AXP192 芯片。** + +**例程:** +```arduino +#include + +void setup(){ + M5.begin(); //By default, "M5.begin()" will initialize AXP192 chip + Serial.begin(115200); +} +``` + +## ScreenBreath() + +**函数原型:** + +void ScreenBreath(uint8_t brightness); + +**功能:改变 AXP192 芯片的LDO3输出电压。** + +| 参数 | 描述 | +| --- | --- | +| brightness | TFT 的背光 ( 数值范围:7-15 ) | + +**例程:** +```arduino +#include + +void setup(){ + M5.begin(); //By default, "M5.begin()" will initialize AXP192 chip + Serial.begin(115200); + M5.Axp.ScreenBreath(7); +} +``` + +## GetVbatData() + +**函数原型:** + +uint16_t GetVbatData(void); + +**功能:获取电池电压值。** + +**例程:** +```arduino +#include + +double vbat = 0.0; + +void setup(){ + M5.begin(); //By default, "M5.begin()" will initialize AXP192 chip + Serial.begin(115200); + M5.Lcd.fillScreen(BLACK); +} + +void loop(){ + vbat = M5.Axp.GetVbatData() * 1.1 / 1000; + M5.Lcd.setCursor(0, 0, 1); + M5.Lcd.printf("vbat:%.3fV\r\n",vbat); + delay(500); +} +``` + +## GetIchargeData() + +**函数原型:** + +uint16_t GetIchargeData(void); + +**功能:获取电池充电电流值。** + +**例程:** +```arduino +#include + +int charge; + +void setup(){ + M5.begin(); //By default, "M5.begin()" will initialize AXP192 chip + Serial.begin(115200); + M5.Lcd.fillScreen(BLACK); +} + +void loop(){ + charge = M5.Axp.GetIchargeData() / 2; + M5.Lcd.setCursor(0, 0, 1); + M5.Lcd.printf("icharge:%dmA\r\n",charge); + delay(500); +} +``` \ No newline at end of file diff --git a/docs/zh_CN/api/sh200q_m5stickc.md b/docs/zh_CN/api/sh200q_m5stickc.md new file mode 100644 index 00000000..647ec6fe --- /dev/null +++ b/docs/zh_CN/api/sh200q_m5stickc.md @@ -0,0 +1,95 @@ +# SH200Q + +*SH200Q 是一款 6 轴 IMU 芯片,包括测量 X, Y, Z 三个方向角速度值的陀螺仪和测量 X, Y, Z 三个方向加速度的加速度计。* + +## Init() + +**函数原型:** + +void Init(); + +**功能:初始化 SH200Q 芯片。** + +**例程:** +```arduino +#include + +void setup(){ + uint8_t c; + + M5.begin(); + Serial.begin(115200); + + M5.IMU.Init(); + IMU.readByte(SH200I_ADDRESS, SH200I_WHOAMI, 1, c); + Serial.print("SH200Q "); Serial.print("I AM "); Serial.print(c, HEX); +} +``` + +## getGyroData() + +**函数原型:** + +void getGyroData(int16_t* gx, int16_t* gy, int16_t* gz); + +**功能:获取 SH200Q 芯片的三轴陀螺仪数据。** + +**例程:** +```arduino +#include + +int16_t gyroX, gyroY, gyroZ; + +void setup(){ + uint8_t c; + + M5.begin(); + Serial.begin(115200); + + M5.IMU.Init(); +} + +void loop(){ + M5.IMU.getGyroData(&gyroX,&gyroY,&gyroZ); + + M5.Lcd.setCursor(0, 30); + M5.Lcd.printf("%.2f %.2f %.2f ", ((float) gyroX) * M5.IMU.gRes, ((float) gyroY) * M5.IMU.gRes,((float) gyroZ) * M5.IMU.gRes); + M5.Lcd.setCursor(140, 30); + M5.Lcd.print("mg"); + delay(500); +} +``` + +## getAccelData() + +**函数原型:** + +void getAccelData(int16_t* ax, int16_t* ay, int16_t* az); + +**功能:获取 SH200Q 芯片的三轴加速度计数据。** + +**例程:** +```arduino +#include + +int16_t accX, accY, accZ; + +void setup(){ + uint8_t c; + + M5.begin(); + Serial.begin(115200); + + M5.IMU.Init(); +} + +void loop(){ + M5.IMU.getAccelData(&accX,&accY,&accZ); + + M5.Lcd.setCursor(0, 45); + M5.Lcd.printf("%.2f %.2f %.2f ",((float) accX) * M5.IMU.aRes,((float) accY) * M5.IMU.aRes, ((float) accZ) * M5.IMU.aRes); + M5.Lcd.setCursor(140, 45); + M5.Lcd.print("o/s"); + delay(500); +} +``` \ No newline at end of file diff --git a/docs/zh_CN/api/system_m5stickc.md b/docs/zh_CN/api/system_m5stickc.md new file mode 100644 index 00000000..1a10b10a --- /dev/null +++ b/docs/zh_CN/api/system_m5stickc.md @@ -0,0 +1,157 @@ +# 系统函数 + +## begin() + +**函数原型:** + +void begin(bool LCDEnable=true, bool SDEnable=true, bool SerialEnable=true,bool I2CEnable=false); + + + +**功能:清串口缓冲区,设置串口波特率为 115200;初始化 LCD;初始化 SD 卡;初始化 I2C;设置按键 A 是睡眠唤醒按键。** + +**函数实现** + +```arduino +void M5Stack::begin(bool LCDEnable, bool SDEnable, bool SerialEnable,bool I2CEnable) { + + // Correct init once + if (isInited) return; + else isInited = true; + + // UART + if (SerialEnable) { + Serial.begin(115200); + Serial.flush(); + delay(50); + Serial.print("M5Stack initializing..."); + } + + // LCD INIT + if (LCDEnable) { + Lcd.begin(); + } + + // TF Card + if (SDEnable) { + SD.begin(TFCARD_CS_PIN, SPI, 40000000); + } + + // TONE + // Speaker.begin(); + + // Set wakeup button + Power.setWakeupButton(BUTTON_A_PIN); + + // I2C init + if(I2CEnable) + { + Wire.begin(21, 22); + } + + if (SerialEnable) { + Serial.println("OK"); + } +} + +void M5Stack::update() { + + //Button update + BtnA.read(); + BtnB.read(); + BtnC.read(); + + //Speaker update + Speaker.update(); +} + +``` + +**例程** + +```arduino +#include + +void setup() { + M5.begin(); +} +``` + +## update() + +**函数原型:** + +void update(); + + + +**功能:读取按键 A, B, C 的状态。** + +**函数实现** + +```arduino +void M5Stack::update() { + + //Button update + BtnA.read(); + BtnB.read(); + BtnC.read(); + + //Speaker update + Speaker.update(); +} +``` + +**例程** + +```arduino +#include + +void setup() { + M5.begin(); +} + +void loop() { + M5.update(); +} +``` + +## powerOFF() + +!> 不推荐使用:请使用Power::deepSleep() + +**函数原型:** + +void powerOFF(); + + + +**功能:系统进入深度睡眠状态。** + +**函数实现** + +```arduino +void M5Stack::powerOFF() { + M5.Power.deepSleep(); +} +``` + +**例程** + +```arduino +#include + +void setup() { + M5.begin(); + M5.Lcd.println("This is software power off demo"); + M5.Lcd.println("Press the button A to power off."); + M5.setWakeupButton(BUTTON_A_PIN); +} + +void loop() { + M5.update(); + if (M5.BtnA.wasPressed()) { + M5.powerOFF(); + } +} +``` \ No newline at end of file