增加api

This commit is contained in:
watson8544
2019-04-08 23:36:40 +08:00
parent 8b49a0a36f
commit 8c7d40b08b
3 changed files with 352 additions and 0 deletions
+100
View File
@@ -0,0 +1,100 @@
# AXP192
*AXP192 是一款高度集成的电源系统管理芯片。*
## begin()
**函数原型:**
<mark>void begin(void);</mark>
**功能:初始化 AXP192 芯片。**
**例程:**
```arduino
#include <M5StackC.h>
void setup(){
M5.begin(); //By default, "M5.begin()" will initialize AXP192 chip
Serial.begin(115200);
}
```
## ScreenBreath()
**函数原型:**
<mark>void ScreenBreath(uint8_t brightness);</mark>
**功能:改变 AXP192 芯片的LDO3输出电压。**
| 参数 | 描述 |
| --- | --- |
| brightness | TFT 的背光 ( 数值范围:7-15 ) |
**例程:**
```arduino
#include <M5StackC.h>
void setup(){
M5.begin(); //By default, "M5.begin()" will initialize AXP192 chip
Serial.begin(115200);
M5.Axp.ScreenBreath(7);
}
```
## GetVbatData()
**函数原型:**
<mark>uint16_t GetVbatData(void);</mark>
**功能:获取电池电压值。**
**例程:**
```arduino
#include <M5StackC.h>
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()
**函数原型:**
<mark>uint16_t GetIchargeData(void);</mark>
**功能:获取电池充电电流值。**
**例程:**
```arduino
#include <M5StackC.h>
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);
}
```
+95
View File
@@ -0,0 +1,95 @@
# SH200Q
*SH200Q 是一款 6 轴 IMU 芯片,包括测量 X, Y, Z 三个方向角速度值的陀螺仪和测量 X, Y, Z 三个方向加速度的加速度计。*
## Init()
**函数原型:**
<mark>void Init();</mark>
**功能:初始化 SH200Q 芯片。**
**例程:**
```arduino
#include <M5StackC.h>
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()
**函数原型:**
<mark>void getGyroData(int16_t* gx, int16_t* gy, int16_t* gz);</mark>
**功能:获取 SH200Q 芯片的三轴陀螺仪数据。**
**例程:**
```arduino
#include <M5StackC.h>
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()
**函数原型:**
<mark>void getAccelData(int16_t* ax, int16_t* ay, int16_t* az);</mark>
**功能:获取 SH200Q 芯片的三轴加速度计数据。**
**例程:**
```arduino
#include <M5StackC.h>
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);
}
```
+157
View File
@@ -0,0 +1,157 @@
# 系统函数
## begin()
**函数原型:**
<mark>void begin(bool LCDEnable=true, bool SDEnable=true, bool SerialEnable=true,bool I2CEnable=false);</mark>
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**功能:清串口缓冲区,设置串口波特率为 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 <M5Stack.h>
void setup() {
M5.begin();
}
```
## update()
**函数原型:**
<mark>void update();</mark>
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**功能:读取按键 A, B, C 的状态。**
**函数实现**
```arduino
void M5Stack::update() {
//Button update
BtnA.read();
BtnB.read();
BtnC.read();
//Speaker update
Speaker.update();
}
```
**例程**
```arduino
#include <M5Stack.h>
void setup() {
M5.begin();
}
void loop() {
M5.update();
}
```
## powerOFF()
!> 不推荐使用:请使用Power::deepSleep()
**函数原型:**
<mark>void powerOFF();</mark>
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**功能:系统进入深度睡眠状态。**
**函数实现**
```arduino
void M5Stack::powerOFF() {
M5.Power.deepSleep();
}
```
**例程**
```arduino
#include <M5Stack.h>
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();
}
}
```