Skip to content

Commit 9c0f239

Browse files
committed
Add M5Stack CoreS3
1 parent ce128bd commit 9c0f239

File tree

4 files changed

+144
-0
lines changed

4 files changed

+144
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#-------------------------------------------------------------
2+
- Specialized driver for M5CoreS3 using AXP2101 and AW9523
3+
-------------------------------------------------------------#
4+
class M5CoreS3 : AXP2102
5+
def init()
6+
super(self).init()
7+
8+
if self.wire
9+
10+
# From https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/Power_Class.cpp#L61
11+
# M5.In_I2C.bitOn(aw9523_i2c_addr, 0x03, 0b10000000, i2c_freq); // SY7088 BOOST_EN
12+
var aw9523 = I2C_Driver("AW9523", 0x58)
13+
aw9523.write8(0x03, aw9523.read8(0x03) | 0x80) # SY7088 BOOST_EN
14+
15+
# From https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/Power_Class.cpp#L62
16+
# _pmic = Power_Class::pmic_t::pmic_axp2101;
17+
# Axp2101.begin();
18+
# static constexpr std::uint8_t reg_data_array[] =
19+
# { 0x90, 0xBF // LDOS ON/OFF control 0
20+
# , 0x92, 18 -5 // ALDO1 set to 1.8v // for AW88298
21+
# , 0x93, 33 -5 // ALDO2 set to 3.3v // for ES7210
22+
# , 0x94, 33 -5 // ALDO3 set to 3.3v // for camera
23+
# , 0x95, 33 -5 // ALDO3 set to 3.3v // for TF card slot
24+
# , 0x27, 0x00 // PowerKey Hold=1sec / PowerOff=4sec
25+
# , 0x69, 0x11 // CHGLED setting
26+
# , 0x10, 0x30 // PMU common config
27+
# , 0x30, 0x0F // ADC enabled (for voltage measurement)
28+
# };
29+
self.write8(0x90, 0xBF) # LDOS ON/OFF control 0
30+
self.write8(0x92, 18 -5) # ALDO1 set to 1.8v // for AW88298
31+
self.write8(0x93, 33 -5) # ALDO2 set to 3.3v // for ES7210
32+
self.write8(0x94, 33 -5) # ALDO3 set to 3.3v // for camera
33+
self.write8(0x95, 33 -5) # ALDO4 set to 3.3v // for TF card slot
34+
self.write8(0x27, 0x00) # PowerKey Hold=1sec / PowerOff=4sec
35+
self.write8(0x69, 0x11) # CHGLED setting
36+
self.write8(0x10, 0x30) # PMU common config
37+
self.write8(0x30, 0x0F) # ADC enabled (for voltage measurement)
38+
39+
var chk_aw = aw9523.read8(0x10)
40+
if chk_aw == 0x23
41+
var result = 0
42+
var reg0x02 = (result == 0) ? 0x07 : 0x05;
43+
var reg0x03 = (result == 0) ? 0x83 : 0x03;
44+
aw9523.write8(0x02, aw9523.read8(0x02) | reg0x02) # port0 output ctrl
45+
aw9523.write8(0x03, aw9523.read8(0x03) | reg0x03) # port1 output ctrl
46+
aw9523.write8(0x04, 0x18) # CONFIG_P0
47+
aw9523.write8(0x05, 0x0C) # CONFIG_P1
48+
aw9523.write8(0x11, 0x10) # GCR P0 port is Push-Pull mode.
49+
aw9523.write8(0x12, 0xFF) # LEDMODE_P0
50+
aw9523.write8(0x13, 0xFF) # LEDMODE_P1
51+
52+
# aw9523.write8(0x03, aw9523.read8(0x03) & ~0x02) # LCD_RST)
53+
# delay(10)
54+
# aw9523.write8(0x03, aw9523.read8(0x03) | 0x02) # LCD_RST)
55+
end
56+
57+
tasmota.add_driver(self)
58+
end
59+
end
60+
61+
# set LCD backlight voltage on DLDO1
62+
def set_lcd_voltage(voltage)
63+
if (voltage < 2500) voltage = 2500 end
64+
if (voltage > 3300) voltage = 3300 end
65+
self.set_dldo_voltage(0, voltage) # 0=DLD01
66+
end
67+
68+
# Speaker enable
69+
def set_speaker_enable(state)
70+
self.set_ldo_voltage(2, state ? 3300 : 0) # 2 = ALDO3
71+
end
72+
73+
# Dimmer in percentage
74+
def set_displaydimmer(x)
75+
var v = tasmota.scale_uint(x, 0, 100, 2500, 3300)
76+
self.set_lcd_voltage(v)
77+
end
78+
79+
# respond to display events
80+
def display(cmd, idx, payload, raw)
81+
if cmd == "dim" || cmd == "power"
82+
self.set_displaydimmer(idx)
83+
end
84+
end
85+
86+
end
87+
88+
return M5CoreS3()
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
:H,ILI9342,320,240,16,SPI,2,3,36,37,35,-1,-1,-1,40
2+
:S,2,1,3,0,100,100
3+
:B,60,0
4+
:I
5+
EF,3,03,80,02
6+
CF,3,00,C1,30
7+
ED,4,64,03,12,81
8+
E8,3,85,00,78
9+
CB,5,39,2C,00,34,02
10+
F7,1,20
11+
EA,2,00,00
12+
C0,1,23
13+
C1,1,10
14+
C5,2,3e,28
15+
C7,1,86
16+
36,1,48
17+
37,1,00
18+
3A,1,55
19+
B1,2,00,18
20+
B6,3,08,82,27
21+
F2,1,00
22+
26,1,01
23+
E0,0F,0F,31,2B,0C,0E,08,4E,F1,37,07,10,03,0E,09,00
24+
E1,0F,00,0E,14,03,11,07,31,C1,48,08,0F,0C,31,36,0F
25+
21,80
26+
11,80
27+
29,80
28+
:o,28
29+
:O,29
30+
:A,2A,2B,2C,16
31+
:R,36
32+
:0,08,00,00,00
33+
:1,A8,00,00,84
34+
:2,C8,00,00,02
35+
:3,68,00,00,85
36+
:i,21,20
37+
:UTI,FT6336U,I2,38,-1,-1
38+
RD A0
39+
CP 02
40+
RTF
41+
RT
42+
:UTT
43+
RDM 00 16
44+
MV 2 1
45+
RT
46+
:UTX
47+
MV 3 2
48+
RT
49+
:UTY
50+
MV 5 2
51+
RT
52+
#
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Template {"NAME":"M5Stack Core S3","GPIO":[1,1,1,6210,6720,1,1,1,1,1,1,609,641,1,1,0,0,1,1,0,0,0,0,0,673,737,705,0,0,0,0,0,1,1,0,0,0,0],"FLAG":0,"BASE":1}
2+
Module 0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import AXP2102
2+
import M5CoreS3

0 commit comments

Comments
 (0)