Files
M5Stack/src/M5Stack.cpp
T

87 lines
1.7 KiB
C++
Raw Normal View History

2017-04-28 21:53:40 +08:00
// Copyright (c) M5Stack. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include "M5Stack.h"
2018-08-08 11:41:46 +08:00
M5Stack::M5Stack() : isInited(0) {
}
2017-04-28 21:53:40 +08:00
2019-04-12 10:41:12 +09:00
void M5Stack::begin(bool LCDEnable, bool SDEnable, bool SerialEnable, bool I2CEnable) {
// Correct init once
if (isInited == true) {
return;
} else {
isInited = true;
}
2017-04-28 21:53:40 +08:00
2019-04-12 10:41:12 +09:00
// UART
if (SerialEnable == true) {
Serial.begin(115200);
Serial.flush();
delay(50);
Serial.print("M5Stack initializing...");
}
2017-06-05 09:26:37 +08:00
2019-04-12 10:41:12 +09:00
// LCD INIT
if (LCDEnable == true) {
Lcd.begin();
}
2017-09-25 19:47:37 +08:00
2019-04-12 10:41:12 +09:00
// TF Card
if (SDEnable == true) {
SD.begin(TFCARD_CS_PIN, SPI, 40000000);
}
2017-09-25 19:47:37 +08:00
2019-04-12 10:41:12 +09:00
// TONE
// Speaker.begin();
2017-09-27 19:40:43 +08:00
2019-04-12 10:41:12 +09:00
// Set wakeup button
Power.setWakeupButton(BUTTON_A_PIN);
2018-08-08 11:41:46 +08:00
2019-04-12 10:41:12 +09:00
// I2C init
if (I2CEnable == true) {
Wire.begin(21, 22);
}
2018-08-08 11:41:46 +08:00
2019-04-12 10:41:12 +09:00
if (SerialEnable == true) {
Serial.println("OK");
}
2020-04-14 11:03:48 +08:00
// if use M5GO button, need set gpio15 OD or PP mode to avoid affecting the wifi signal
pinMode(15, OUTPUT_OPEN_DRAIN);
2017-04-28 21:53:40 +08:00
}
2017-07-16 16:27:27 +08:00
void M5Stack::update() {
2019-04-12 10:41:12 +09:00
//Button update
BtnA.read();
BtnB.read();
BtnC.read();
2017-04-28 21:53:40 +08:00
2019-04-12 10:41:12 +09:00
//Speaker update
Speaker.update();
2017-06-05 09:26:37 +08:00
}
2019-03-04 15:57:10 +09:00
/**
* Function has been move to Power class.(for compatibility)
* This name will be removed in a future release.
*/
2019-04-12 10:41:12 +09:00
void M5Stack::setPowerBoostKeepOn(bool en) {
M5.Power.setPowerBoostKeepOn(en);
2018-07-10 11:35:09 +08:00
}
2019-03-04 15:57:10 +09:00
/**
* Function has been move to Power class.(for compatibility)
* This name will be removed in a future release.
*/
2017-09-25 19:47:37 +08:00
void M5Stack::setWakeupButton(uint8_t button) {
2019-04-12 10:41:12 +09:00
M5.Power.setWakeupButton(button);
2017-09-25 19:47:37 +08:00
}
2019-03-04 15:57:10 +09:00
/**
* Function has been move to Power class.(for compatibility)
* This name will be removed in a future release.
*/
2017-09-25 19:47:37 +08:00
void M5Stack::powerOFF() {
2019-04-12 10:41:12 +09:00
M5.Power.deepSleep();
2017-09-25 19:47:37 +08:00
}
2017-10-11 17:09:55 +08:00
M5Stack M5;