-
Notifications
You must be signed in to change notification settings - Fork 441
/
Copy pathM5Stack.cpp
94 lines (78 loc) · 2.07 KB
/
M5Stack.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// 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"
M5Stack::M5Stack() : isInited(0) {
}
void M5Stack::begin(bool LCDEnable, bool SDEnable, bool SerialEnable, bool I2CEnable) {
// Correct init once
if (isInited == true) {
return;
} else {
isInited = true;
}
for (auto gpio : (const uint8_t[]){18, 19, 23}) {
*(volatile uint32_t*)(GPIO_PIN_MUX_REG[gpio]) |= FUN_DRV_M;
gpio_pulldown_dis((gpio_num_t)gpio);
gpio_pullup_en((gpio_num_t)gpio);
}
// UART
if (SerialEnable == true) {
Serial.begin(115200);
Serial.flush();
delay(50);
Serial.println("M5Stack initializing...");
}
// TF Card
if (SDEnable == true) {
SD.begin(TFCARD_CS_PIN, SPI, 40000000);
}
// LCD INIT
if (LCDEnable == true) {
Lcd.begin();
}
// TONE
// Speaker.begin();
// Set wakeup button
Power.setWakeupButton(BUTTON_A_PIN);
// I2C init
if (I2CEnable == true) {
Wire.begin(21, 22);
}
if (SerialEnable == true) {
Serial.println("OK");
}
// if use M5GO button, need set gpio15 OD or PP mode to avoid affecting the
// wifi signal
pinMode(15, OUTPUT_OPEN_DRAIN);
}
void M5Stack::update() {
// Button update
BtnA.read();
BtnB.read();
BtnC.read();
// Speaker update
Speaker.update();
}
/**
* Function has been move to Power class.(for compatibility)
* This name will be removed in a future release.
*/
void M5Stack::setPowerBoostKeepOn(bool en) {
M5.Power.setPowerBoostKeepOn(en);
}
/**
* Function has been move to Power class.(for compatibility)
* This name will be removed in a future release.
*/
void M5Stack::setWakeupButton(uint8_t button) {
M5.Power.setWakeupButton(button);
}
/**
* Function has been move to Power class.(for compatibility)
* This name will be removed in a future release.
*/
void M5Stack::powerOFF() {
M5.Power.deepSleep();
}
M5Stack M5;