Skip to content

Commit df89ac6

Browse files
committed
add M5Unified and M5GFX
1 parent f7f3a99 commit df89ac6

File tree

296 files changed

+1483487
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

296 files changed

+1483487
-0
lines changed
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#include <mpy_m5unified.h>
2+
3+
#define MAKE_METHOD_V(prefix, func, arg_min, arg_max) extern mp_obj_t prefix##_##func(size_t,const mp_obj_t*); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( prefix##_##func##_obj, arg_min, arg_max, prefix##_##func );
4+
#define MAKE_METHOD_0(prefix, func) extern mp_obj_t prefix##_##func(mp_obj_t ); STATIC MP_DEFINE_CONST_FUN_OBJ_1( prefix##_##func##_obj, prefix##_##func );
5+
#define MAKE_METHOD_1(prefix, func) extern mp_obj_t prefix##_##func(mp_obj_t,mp_obj_t ); STATIC MP_DEFINE_CONST_FUN_OBJ_2( prefix##_##func##_obj, prefix##_##func );
6+
#define MAKE_METHOD_2(prefix, func) extern mp_obj_t prefix##_##func(mp_obj_t,mp_obj_t,mp_obj_t); STATIC MP_DEFINE_CONST_FUN_OBJ_3( prefix##_##func##_obj, prefix##_##func );
7+
8+
#define MAKE_TABLE( prefix, func ) \
9+
{ MP_ROM_QSTR(MP_QSTR_##func), MP_ROM_PTR(&prefix##_##func##_obj) }
10+
11+
//-------- GFX common wrapper
12+
MAKE_METHOD_0( gfx, width );
13+
MAKE_METHOD_0( gfx, height );
14+
MAKE_METHOD_0( gfx, getRotation );
15+
MAKE_METHOD_0( gfx, getColorDepth );
16+
MAKE_METHOD_1( gfx, setRotation );
17+
MAKE_METHOD_1( gfx, setColorDepth );
18+
MAKE_METHOD_1( gfx, print );
19+
MAKE_METHOD_2( gfx, setCursor );
20+
MAKE_METHOD_V( gfx, fillScreen , 1, 2 );
21+
MAKE_METHOD_V( gfx, drawPixel , 3, 4 );
22+
MAKE_METHOD_V( gfx, drawCircle , 4, 5 );
23+
MAKE_METHOD_V( gfx, fillCircle , 4, 5 );
24+
MAKE_METHOD_V( gfx, drawLine , 5, 6 );
25+
MAKE_METHOD_V( gfx, drawRect , 5, 6 );
26+
MAKE_METHOD_V( gfx, fillRect , 5, 6 );
27+
MAKE_METHOD_V( gfx, printf , 2, 32);
28+
MAKE_METHOD_V( gfx, newCanvas , 3, 5 );
29+
30+
#define TABLE_PARTS_GFX_BASE \
31+
MAKE_TABLE( gfx, drawCircle ), \
32+
MAKE_TABLE( gfx, drawLine ), \
33+
MAKE_TABLE( gfx, drawPixel ), \
34+
MAKE_TABLE( gfx, drawRect ), \
35+
MAKE_TABLE( gfx, fillCircle ), \
36+
MAKE_TABLE( gfx, fillRect ), \
37+
MAKE_TABLE( gfx, fillScreen ), \
38+
MAKE_TABLE( gfx, getColorDepth), \
39+
MAKE_TABLE( gfx, getRotation ), \
40+
MAKE_TABLE( gfx, height ), \
41+
MAKE_TABLE( gfx, newCanvas ), \
42+
MAKE_TABLE( gfx, print ), \
43+
MAKE_TABLE( gfx, printf ), \
44+
MAKE_TABLE( gfx, setColorDepth), \
45+
MAKE_TABLE( gfx, setCursor ), \
46+
MAKE_TABLE( gfx, setRotation ), \
47+
MAKE_TABLE( gfx, width ), \
48+
{ MP_ROM_QSTR(MP_QSTR_BLACK ), MP_ROM_INT( 0x000000 ) }, \
49+
{ MP_ROM_QSTR(MP_QSTR_NAVY ), MP_ROM_INT( 0x000080 ) }, \
50+
{ MP_ROM_QSTR(MP_QSTR_DARKGREEN ), MP_ROM_INT( 0x008000 ) }, \
51+
{ MP_ROM_QSTR(MP_QSTR_DARKCYAN ), MP_ROM_INT( 0x008080 ) }, \
52+
{ MP_ROM_QSTR(MP_QSTR_MAROON ), MP_ROM_INT( 0x800000 ) }, \
53+
{ MP_ROM_QSTR(MP_QSTR_PURPLE ), MP_ROM_INT( 0x800080 ) }, \
54+
{ MP_ROM_QSTR(MP_QSTR_OLIVE ), MP_ROM_INT( 0x808000 ) }, \
55+
{ MP_ROM_QSTR(MP_QSTR_LIGHTGREY ), MP_ROM_INT( 0xC0C0C0 ) }, \
56+
{ MP_ROM_QSTR(MP_QSTR_DARKGREY ), MP_ROM_INT( 0x808080 ) }, \
57+
{ MP_ROM_QSTR(MP_QSTR_BLUE ), MP_ROM_INT( 0x0000FF ) }, \
58+
{ MP_ROM_QSTR(MP_QSTR_GREEN ), MP_ROM_INT( 0x00FF00 ) }, \
59+
{ MP_ROM_QSTR(MP_QSTR_CYAN ), MP_ROM_INT( 0x00FFFF ) }, \
60+
{ MP_ROM_QSTR(MP_QSTR_RED ), MP_ROM_INT( 0xFF0000 ) }, \
61+
{ MP_ROM_QSTR(MP_QSTR_MAGENTA ), MP_ROM_INT( 0xFF00FF ) }, \
62+
{ MP_ROM_QSTR(MP_QSTR_YELLOW ), MP_ROM_INT( 0xFFFF00 ) }, \
63+
{ MP_ROM_QSTR(MP_QSTR_WHITE ), MP_ROM_INT( 0xFFFFFF ) }, \
64+
{ MP_ROM_QSTR(MP_QSTR_ORANGE ), MP_ROM_INT( 0xFFA500 ) }, \
65+
{ MP_ROM_QSTR(MP_QSTR_GREENYELLOW), MP_ROM_INT( 0xADFF2F ) }, \
66+
{ MP_ROM_QSTR(MP_QSTR_PINK ), MP_ROM_INT( 0xFFC0CB ) }
67+
68+
//-------- GFX device wrapper
69+
MAKE_METHOD_0( gfx, startWrite );
70+
MAKE_METHOD_0( gfx, endWrite );
71+
72+
STATIC const mp_rom_map_elem_t gfxdevice_member_table[] = {
73+
TABLE_PARTS_GFX_BASE ,
74+
MAKE_TABLE( gfx, startWrite ),
75+
MAKE_TABLE( gfx, endWrite ),
76+
};
77+
STATIC MP_DEFINE_CONST_DICT(gfxdevice_member, gfxdevice_member_table);
78+
const mp_obj_type_t gfxdevice_type = {
79+
{ &mp_type_type },
80+
.locals_dict = (mp_obj_dict_t *)&gfxdevice_member,
81+
};
82+
83+
//-------- GFX canvas wrapper
84+
MAKE_METHOD_0( gfx, delete );
85+
MAKE_METHOD_2( gfx, push );
86+
87+
STATIC const mp_rom_map_elem_t gfxcanvas_member_table[] = {
88+
TABLE_PARTS_GFX_BASE ,
89+
MAKE_TABLE( gfx, delete),
90+
MAKE_TABLE( gfx, push),
91+
};
92+
STATIC MP_DEFINE_CONST_DICT(gfxcanvas_member, gfxcanvas_member_table);
93+
const mp_obj_type_t gfxcanvas_type = {
94+
{ &mp_type_type },
95+
.flags = MP_TYPE_FLAG_IS_SUBCLASSED,
96+
.locals_dict = (mp_obj_dict_t *)&gfxcanvas_member,
97+
};
98+
99+
//-------- Button wrapper
100+
MAKE_METHOD_0( btn, isHolding );
101+
MAKE_METHOD_0( btn, isPressed );
102+
MAKE_METHOD_0( btn, isReleased );
103+
MAKE_METHOD_0( btn, wasChangePressed );
104+
MAKE_METHOD_0( btn, wasClicked );
105+
MAKE_METHOD_0( btn, wasHold );
106+
MAKE_METHOD_0( btn, wasPressed );
107+
MAKE_METHOD_0( btn, wasReleased );
108+
MAKE_METHOD_0( btn, lastChange );
109+
MAKE_METHOD_1( btn, pressedFor );
110+
MAKE_METHOD_1( btn, releasedFor );
111+
MAKE_METHOD_1( btn, setDebounceThresh);
112+
MAKE_METHOD_1( btn, setHoldThresh );
113+
114+
STATIC const mp_rom_map_elem_t btn_member_table[] = {
115+
MAKE_TABLE( btn, isHolding ),
116+
MAKE_TABLE( btn, isPressed ),
117+
MAKE_TABLE( btn, isReleased ),
118+
MAKE_TABLE( btn, wasChangePressed ),
119+
MAKE_TABLE( btn, wasClicked ),
120+
MAKE_TABLE( btn, wasHold ),
121+
MAKE_TABLE( btn, wasPressed ),
122+
MAKE_TABLE( btn, wasReleased ),
123+
MAKE_TABLE( btn, lastChange ),
124+
MAKE_TABLE( btn, pressedFor ),
125+
MAKE_TABLE( btn, releasedFor ),
126+
MAKE_TABLE( btn, setDebounceThresh),
127+
MAKE_TABLE( btn, setHoldThresh ),
128+
};
129+
130+
STATIC MP_DEFINE_CONST_DICT(btn_member, btn_member_table);
131+
const mp_obj_type_t btn_type = {
132+
{ &mp_type_type },
133+
.locals_dict = (mp_obj_dict_t *)&btn_member,
134+
};
135+
136+
137+
//-------- M5 wrapper
138+
139+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(m5_begin_obj, m5_begin);
140+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(m5_update_obj, m5_update);
141+
142+
STATIC const mp_rom_map_elem_t m5_globals_table[] = {
143+
{ MP_ROM_QSTR(MP_QSTR___name__ ), MP_ROM_QSTR(MP_QSTR_m5) },
144+
{ MP_ROM_QSTR(MP_QSTR_begin ), MP_ROM_PTR(&m5_begin_obj) },
145+
{ MP_ROM_QSTR(MP_QSTR_update ), MP_ROM_PTR(&m5_update_obj) },
146+
{ MP_ROM_QSTR(MP_QSTR_btnA ), MP_OBJ_FROM_PTR(&m5_btnA) },
147+
{ MP_ROM_QSTR(MP_QSTR_btnB ), MP_OBJ_FROM_PTR(&m5_btnB) },
148+
{ MP_ROM_QSTR(MP_QSTR_btnC ), MP_OBJ_FROM_PTR(&m5_btnC) },
149+
{ MP_ROM_QSTR(MP_QSTR_btnPWR ), MP_OBJ_FROM_PTR(&m5_btnPWR) },
150+
{ MP_ROM_QSTR(MP_QSTR_btnEXT ), MP_OBJ_FROM_PTR(&m5_btnEXT) },
151+
{ MP_ROM_QSTR(MP_QSTR_display ), MP_OBJ_FROM_PTR(&m5_display) },
152+
{ MP_ROM_QSTR(MP_QSTR_lcd ), MP_OBJ_FROM_PTR(&m5_display) },
153+
};
154+
155+
STATIC MP_DEFINE_CONST_DICT(mp_module_m5_globals, m5_globals_table);
156+
157+
// Define module object.
158+
const mp_obj_module_t m5m5unified_user_cmodule = {
159+
.base = { &mp_type_module },
160+
.globals = (mp_obj_dict_t *)&mp_module_m5_globals,
161+
};
162+
163+
164+
MP_REGISTER_MODULE(MP_QSTR_m5, m5m5unified_user_cmodule, MODULE_M5UNIFIED_ENABLED);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
add_library(usermod_M5UNIFIED INTERFACE)
2+
3+
target_sources(usermod_M5UNIFIED INTERFACE
4+
${CMAKE_CURRENT_LIST_DIR}/m5unified.c
5+
)
6+
7+
target_include_directories(usermod_M5UNIFIED INTERFACE
8+
${CMAKE_CURRENT_LIST_DIR}
9+
)
10+
11+
target_compile_definitions(usermod_M5UNIFIED INTERFACE
12+
MODULE_M5UNIFIED_ENABLED=1
13+
ESP_PLATFORM=1 # Very important
14+
)
15+
16+
target_link_libraries(usermod INTERFACE usermod_M5UNIFIED)
17+
18+
set_source_files_properties(
19+
${CMAKE_CURRENT_LIST_DIR}/m5unified.c
20+
PROPERTIES COMPILE_FLAGS
21+
"-Wno-discarded-qualifiers -Wno-implicit-int"
22+
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
set(COMPONENT_ADD_INCLUDEDIRS
2+
src
3+
)
4+
file(GLOB SRCS
5+
src/*.cpp
6+
src/lgfx/Fonts/efont/*.c
7+
src/lgfx/Fonts/IPA/*.c
8+
src/lgfx/utility/*.c
9+
src/lgfx/v1/*.cpp
10+
src/lgfx/v1/misc/*.cpp
11+
src/lgfx/v1/panel/*.cpp
12+
src/lgfx/v1/platforms/esp32/*.cpp
13+
src/lgfx/v1/platforms/esp32c3/*.cpp
14+
src/lgfx/v1/touch/*.cpp
15+
)
16+
set(COMPONENT_SRCS ${SRCS})
17+
set(COMPONENT_REQUIRES nvs_flash efuse)
18+
19+
register_component()
20+

m5stack/libs/m5unified/M5GFX/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 M5Stack
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# M5GFX
2+
3+
Graphics library for M5Stack series
4+
5+
Support framework
6+
----------------
7+
- ESP-IDF
8+
- Arduino for ESP32
9+
10+
11+
Support device
12+
----------------
13+
- M5Stack ( Basic / Gray / GO / Fire )
14+
- M5Stack Core2
15+
- M5Stack CoreInk
16+
- M5Stick C
17+
- M5Stick C Plus
18+
- M5Paper
19+
- M5Tough
20+
- M5Station
21+
- UnitOLED
22+
- UnitLCD
23+
- [AtomDisplay](docs/ATOMDisplay.md)
24+
25+
26+
License
27+
----------------
28+
M5GFX : [MIT](LICENSE)
29+
LovyanGFX : [FreeBSD](https://github.com/lovyan03/LovyanGFX/blob/master/license.txt) lovyan03
30+
TJpgDec : [original](src/lgfx/utility/lgfx_tjpgd.c) ChaN
31+
Pngle : [MIT](https://github.com/kikuchan/pngle/blob/master/LICENSE) kikuchan
32+
QRCode : [MIT](https://github.com/ricmoo/QRCode/blob/master/LICENSE.txt) Richard Moore and Nayuki
33+
result : [MIT](https://github.com/bitwizeshift/result/blob/master/LICENSE) Matthew Rodusek
34+
GFX font and GLCD font : [2-clause BSD](https://github.com/adafruit/Adafruit-GFX-Library/blob/master/license.txt) Adafruit Industries
35+
Font 2,4,6,7,8 : [FreeBSD](https://github.com/Bodmer/TFT_eSPI/blob/master/license.txt) Bodmer
36+
converted IPA font : [IPA Font License](src/lgfx/Fonts/IPA/IPA_Font_License_Agreement_v1.0.txt) IPA
37+
efont : [3-clause BSD](src/lgfx/Fonts/efont/COPYRIGHT.txt) The Electronic Font Open Laboratory
38+
TomThumb font : [3-clause BSD](src/lgfx/Fonts/GFXFF/TomThumb.h) Brian J. Swetland / Vassilii Khachaturov / Dan Marks
39+
40+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#
2+
# Main Makefile. This is basically the same as a component makefile.
3+
#
4+
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
5+
6+
COMPONENT_SRCDIRS := src
7+
COMPONENT_ADD_INCLUDEDIRS := src

0 commit comments

Comments
 (0)