mirror of
https://github.com/m5stack/lv_m5_emulator.git
synced 2026-05-20 11:19:24 -07:00
Initial commit
This commit is contained in:
+168
@@ -0,0 +1,168 @@
|
||||
---
|
||||
Language: Cpp
|
||||
BasedOnStyle: Google
|
||||
AccessModifierOffset: -1
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveMacros: true
|
||||
AlignConsecutiveAssignments: true
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: false
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: WithoutElse
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
AfterControlStatement: false
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 120
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DeriveLineEnding: true
|
||||
DerivePointerAlignment: true
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IncludeBlocks: Regroup
|
||||
IncludeCategories:
|
||||
- Regex: '^<ext/.*\.h>'
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
- Regex: '^<.*\.h>'
|
||||
Priority: 1
|
||||
SortPriority: 0
|
||||
- Regex: '^<.*'
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
- Regex: '.*'
|
||||
Priority: 3
|
||||
SortPriority: 0
|
||||
IncludeIsMainRegex: '([-_](test|unittest))?$'
|
||||
IncludeIsMainSourceRegex: ''
|
||||
IndentCaseLabels: true
|
||||
IndentGotoLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Never
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 1
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 200
|
||||
PointerAlignment: Left
|
||||
RawStringFormats:
|
||||
- Language: Cpp
|
||||
Delimiters:
|
||||
- cc
|
||||
- CC
|
||||
- cpp
|
||||
- Cpp
|
||||
- CPP
|
||||
- 'c++'
|
||||
- 'C++'
|
||||
CanonicalDelimiter: ''
|
||||
BasedOnStyle: google
|
||||
- Language: TextProto
|
||||
Delimiters:
|
||||
- pb
|
||||
- PB
|
||||
- proto
|
||||
- PROTO
|
||||
EnclosingFunctions:
|
||||
- EqualsProto
|
||||
- EquivToProto
|
||||
- PARSE_PARTIAL_TEXT_PROTO
|
||||
- PARSE_TEST_PROTO
|
||||
- PARSE_TEXT_PROTO
|
||||
- ParseTextOrDie
|
||||
- ParseTextProtoOrDie
|
||||
CanonicalDelimiter: ''
|
||||
BasedOnStyle: google
|
||||
ReflowComments: true
|
||||
SortIncludes: false
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 2
|
||||
SpacesInAngles: false
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
SpaceBeforeSquareBrackets: false
|
||||
Standard: Auto
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TabWidth: 4
|
||||
UseCRLF: false
|
||||
UseTab: Never
|
||||
...
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
.pio
|
||||
.vscode
|
||||
|
||||
.DS_Store
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 M5Stack
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,89 @@
|
||||
# Running the M5Stack LVGL device emulator via PlatformIO
|
||||
|
||||
:warning: Currently only tested on MacOS.
|
||||
|
||||
Now it is more convenient to design [LVGL](https://github.com/lvgl/lvgl) UI on PC,
|
||||
which can reduce the time wasted in flash the firmware.
|
||||
Using [M5GFX](https://github.com/m5stack/M5GFX), we can ensure that the display
|
||||
effect on the PC side is consistent with that of the device.
|
||||
Now we have also added a picture of the device shell as the border background,
|
||||
which can better simulate the display effect on the device side.
|
||||
|
||||

|
||||
|
||||
## How to install & use demo
|
||||
|
||||
### Install Visual Studio Code
|
||||
|
||||
https://code.visualstudio.com/ - follow instructions there, if you don't have
|
||||
vscode yet.
|
||||
|
||||
|
||||
### Install SDL drivers
|
||||
|
||||
**Linux (Ubuntu, Debian, ...)**
|
||||
|
||||
Use one of options below:
|
||||
|
||||
```sh
|
||||
# 64 bits
|
||||
sudo apt-get install libsdl2-dev
|
||||
```
|
||||
|
||||
```sh
|
||||
# 32 bits
|
||||
sudo apt-get install gcc-multilib g++-multilib libsdl2-dev:i386
|
||||
```
|
||||
|
||||
Note:
|
||||
|
||||
- Use 32-bits build for more correct memory stat info.
|
||||
- If you have conflicts on `libsdl2-dev:i386` install, remove 64-bits version
|
||||
and dependencies first.
|
||||
|
||||
**MacOS**
|
||||
|
||||
Use [Homebrew](https://brew.sh/):
|
||||
|
||||
```sh
|
||||
brew install sdl2
|
||||
```
|
||||
Note:
|
||||
On MacOS you need to include (uncomment in provided example platformio.ini file) these lines in your platformio.ini file to import the drivers:
|
||||
```
|
||||
; SDL2 includes
|
||||
!find /opt/homebrew/Cellar/sdl2 -name "include" | sed "s/^/-I /"
|
||||
!find /opt/homebrew/Cellar/sdl2 -name "libSDL2.a" | xargs dirname | sed "s/^/-L /"
|
||||
```
|
||||
|
||||
**Windows**
|
||||
|
||||
Use [MSYS2](https://www.msys2.org/)
|
||||
|
||||
```sh
|
||||
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-SDL2
|
||||
```
|
||||
|
||||
Add the path to your Mingw-w64 `bin` folder to the Windows PATH environment
|
||||
variable (usually `C:\msys64\mingw64\bin`). See [instruction, 4](https://code.visualstudio.com/docs/cpp/config-mingw#_prerequisites).
|
||||
|
||||
|
||||
### Install flasher drivers (optional)
|
||||
|
||||
If you plan to upload firmware & debug hardware, read notes in PlatformIO
|
||||
[install docs](http://docs.platformio.org/en/latest/installation.html#troubleshooting).
|
||||
|
||||
|
||||
### Build/Run
|
||||
|
||||
1. Clone this repository or download as zip.
|
||||
2. In vscode, open folder via `File` -> `Open Folder...` menu.
|
||||
- If you do it first time - agree, when it suggests to install PlatformIO
|
||||
plugin, and wait when PlatformIO then install build tools and package
|
||||
dependencies.
|
||||
|
||||
To build/execute, on PlafomIO tab expand desired env and click target:
|
||||
|
||||
<img src="support/pio_explorer.png" width="60%">
|
||||
|
||||
Note, for emulator env `upload` also executes compiled binary.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.5 MiB |
@@ -0,0 +1,39 @@
|
||||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the usual convention is to give header files names that end with `.h'.
|
||||
It is most portable to use only letters, digits, dashes, and underscores in
|
||||
header file names, and at most one dot.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
#ifdef LVGL_USE_V8
|
||||
#include "lv_conf_v8.h"
|
||||
#elif LVGL_USE_V9
|
||||
#include "lv_conf_v9.h"
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+46
@@ -0,0 +1,46 @@
|
||||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into executable file.
|
||||
|
||||
The source code of each library should be placed in a an own separate directory
|
||||
("lib/your_library_name/[here are source files]").
|
||||
|
||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- README --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
and a contents of `src/main.c`:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[platformio]
|
||||
default_envs = emulator_Core
|
||||
|
||||
[env]
|
||||
build_flags =
|
||||
-std=c++17
|
||||
-I include
|
||||
-I src/utility
|
||||
|
||||
; LVGL
|
||||
-D LV_CONF_INCLUDE_SIMPLE
|
||||
-D LV_LVGL_H_INCLUDE_SIMPLE
|
||||
-D LVGL_USE_V8=1
|
||||
-D LVGL_USE_V9=0 ; not yet supported
|
||||
|
||||
-l SDL2
|
||||
; SDL2 includes, uncomment the next two lines on MAC OS if you intalled sdl via homebrew
|
||||
!find /opt/homebrew/Cellar/sdl2 -name "include" | sed "s/^/-I /"
|
||||
!find /opt/homebrew/Cellar/sdl2 -name "libSDL2.a" | xargs dirname | sed "s/^/-L /"
|
||||
lib_deps =
|
||||
https://github.com/m5stack/M5GFX#develop
|
||||
lvgl=https://github.com/lvgl/lvgl/archive/refs/tags/v8.3.0.zip
|
||||
; lvgl=https://github.com/lvgl/lvgl/archive/refs/tags/v9.0.0.zip ; not yet supported
|
||||
lib_archive = false
|
||||
|
||||
|
||||
[env:emulator_Core]
|
||||
platform = native@^1.2.1
|
||||
extra_scripts = support/sdl2_build_extra.py
|
||||
build_type = debug
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
-D M5GFX_SHOW_FRAME
|
||||
-D M5GFX_SCALE=1
|
||||
-D M5GFX_ROTATION=0
|
||||
-D M5GFX_BOARD=board_M5Stack
|
||||
build_src_filter =
|
||||
+<*>
|
||||
+<../.pio/libdeps/emulator_Core/lvgl/demos>
|
||||
|
||||
|
||||
[env:emulator_Core2]
|
||||
platform = native@^1.2.1
|
||||
extra_scripts = support/sdl2_build_extra.py
|
||||
build_type = debug
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
-D M5GFX_SHOW_FRAME
|
||||
-D M5GFX_SCALE=1
|
||||
-D M5GFX_ROTATION=0
|
||||
-D M5GFX_BOARD=board_M5StackCore2
|
||||
build_src_filter =
|
||||
+<*>
|
||||
+<../.pio/libdeps/emulator_Core2/lvgl/demos>
|
||||
|
||||
|
||||
[env:emulator_CoreS3]
|
||||
platform = native@^1.2.1
|
||||
extra_scripts = support/sdl2_build_extra.py
|
||||
build_type = debug
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
-D M5GFX_SHOW_FRAME
|
||||
-D M5GFX_SCALE=1
|
||||
-D M5GFX_ROTATION=0
|
||||
-D M5GFX_BOARD=board_M5StackCoreS3
|
||||
build_src_filter =
|
||||
+<*>
|
||||
+<../.pio/libdeps/emulator_CoreS3/lvgl/demos>
|
||||
|
||||
|
||||
[env:emulator_StickCPlus]
|
||||
platform = native@^1.2.1
|
||||
extra_scripts = support/sdl2_build_extra.py
|
||||
build_type = debug
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
-D M5GFX_SHOW_FRAME
|
||||
-D M5GFX_SCALE=1
|
||||
-D M5GFX_ROTATION=0
|
||||
-D M5GFX_BOARD=board_M5StickCPlus
|
||||
build_src_filter =
|
||||
+<*>
|
||||
+<../.pio/libdeps/emulator_StickCPlus/lvgl/demos>
|
||||
|
||||
|
||||
[env:emulator_StickCPlus2]
|
||||
platform = native@^1.2.1
|
||||
extra_scripts = support/sdl2_build_extra.py
|
||||
build_type = debug
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
-D M5GFX_SHOW_FRAME
|
||||
-D M5GFX_SCALE=1
|
||||
-D M5GFX_ROTATION=0
|
||||
-D M5GFX_BOARD=board_M5StickCPlus2
|
||||
build_src_filter =
|
||||
+<*>
|
||||
+<../.pio/libdeps/emulator_StickCPlus2/lvgl/demos>
|
||||
@@ -0,0 +1,24 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "lvgl_port_m5stack.hpp"
|
||||
|
||||
extern void user_app(void);
|
||||
|
||||
M5GFX gfx;
|
||||
|
||||
void setup(void) {
|
||||
gfx.init();
|
||||
|
||||
lvgl_port_init(gfx);
|
||||
|
||||
user_app();
|
||||
}
|
||||
|
||||
void loop(void) {
|
||||
#if defined(ARDUINO) && defined(ESP_PLATFORM)
|
||||
delay(10);
|
||||
#elif !defined(ARDUINO) && (__has_include(<SDL2/SDL.h>) || __has_include(<SDL.h>))
|
||||
usleep(10 * 000);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "lvgl.h"
|
||||
#include "demos/lv_demos.h"
|
||||
|
||||
void user_app(void) {
|
||||
lv_demo_widgets();
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
#include "lvgl_port_m5stack.hpp"
|
||||
|
||||
#if defined(ARDUINO) && defined(ESP_PLATFORM)
|
||||
static SemaphoreHandle_t xGuiSemaphore;
|
||||
#elif !defined(ARDUINO) && (__has_include(<SDL2/SDL.h>) || __has_include(<SDL.h>))
|
||||
static SDL_mutex *xGuiMutex;
|
||||
#endif
|
||||
|
||||
#ifndef LV_BUFFER_LINE
|
||||
#define LV_BUFFER_LINE (gfx.height() / 2)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static void lvgl_flush_cb(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) {
|
||||
M5GFX &gfx = *(M5GFX *)disp->user_data;
|
||||
int w = (area->x2 - area->x1 + 1);
|
||||
int h = (area->y2 - area->y1 + 1);
|
||||
|
||||
gfx.startWrite();
|
||||
gfx.setAddrWindow(area->x1, area->y1, w, h);
|
||||
gfx.writePixels((lgfx::rgb565_t *)&color_p->full, w * h);
|
||||
// gfx.writePixels((lgfx::swap565_t *)&color_p->full, w * h); // swap red and blue
|
||||
gfx.endWrite();
|
||||
lv_disp_flush_ready(disp);
|
||||
}
|
||||
|
||||
static void lvgl_read_cb(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) {
|
||||
M5GFX &gfx = *(M5GFX *)indev_driver->user_data;
|
||||
uint16_t touchX, touchY;
|
||||
|
||||
bool touched = gfx.getTouch(&touchX, &touchY);
|
||||
if (!touched) {
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
} else {
|
||||
data->state = LV_INDEV_STATE_PR;
|
||||
data->point.x = touchX;
|
||||
data->point.y = touchY;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(ARDUINO) && defined(ESP_PLATFORM)
|
||||
static void lvgl_tick_timer(void *arg) {
|
||||
(void)arg;
|
||||
lv_tick_inc(10);
|
||||
}
|
||||
static void lvgl_rtos_task(void *pvParameter) {
|
||||
(void)pvParameter;
|
||||
xGuiSemaphore = xSemaphoreCreateMutex();
|
||||
while (1) {
|
||||
if (pdTRUE == xSemaphoreTake(xGuiSemaphore, portMAX_DELAY)) {
|
||||
lv_timer_handler();
|
||||
xSemaphoreGive(xGuiSemaphore);
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
}
|
||||
#elif !defined(ARDUINO) && (__has_include(<SDL2/SDL.h>) || __has_include(<SDL.h>))
|
||||
static uint32_t lvgl_tick_timer(uint32_t interval, void *param) {
|
||||
(void)interval;
|
||||
(void)param;
|
||||
lv_tick_inc(10);
|
||||
return 10;
|
||||
}
|
||||
|
||||
static int lvgl_sdl_thread(void *data) {
|
||||
(void)data;
|
||||
xGuiMutex = SDL_CreateMutex();
|
||||
while (1) {
|
||||
if (SDL_LockMutex(xGuiMutex) == 0) {
|
||||
lv_timer_handler();
|
||||
SDL_UnlockMutex(xGuiMutex);
|
||||
}
|
||||
SDL_Delay(10);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void lvgl_port_init(M5GFX &gfx) {
|
||||
lv_init();
|
||||
|
||||
static lv_disp_draw_buf_t *draw_buf = (lv_disp_draw_buf_t *)malloc(sizeof(lv_disp_draw_buf_t));
|
||||
#if defined(ARDUINO) && defined(ESP_PLATFORM)
|
||||
#if defined(BOARD_HAS_PSRAM)
|
||||
static lv_color_t *buf1 =
|
||||
(lv_color_t *)heap_caps_malloc(gfx.width() * LV_BUFFER_LINE * sizeof(lv_color_t), MALLOC_CAP_SPIRAM);
|
||||
static lv_color_t *buf2 =
|
||||
(lv_color_t *)heap_caps_malloc(gfx.width() * LV_BUFFER_LINE * sizeof(lv_color_t), MALLOC_CAP_SPIRAM);
|
||||
lv_disp_draw_buf_init(&draw_buf, buf1, buf2, gfx.width() * LV_BUFFER_LINE);
|
||||
#else
|
||||
static lv_color_t *buf1 = (lv_color_t *)malloc(gfx.width() * LV_BUFFER_LINE * sizeof(lv_color_t));
|
||||
lv_disp_draw_buf_init(&draw_buf, buf1, NULL, gfx.width() * LV_BUFFER_LINE);
|
||||
#endif
|
||||
#elif !defined(ARDUINO) && (__has_include(<SDL2/SDL.h>) || __has_include(<SDL.h>))
|
||||
static lv_color_t *buf1 = (lv_color_t *)malloc(gfx.width() * LV_BUFFER_LINE * sizeof(lv_color_t));
|
||||
static lv_color_t *buf2 = (lv_color_t *)malloc(gfx.width() * LV_BUFFER_LINE * sizeof(lv_color_t));
|
||||
lv_disp_draw_buf_init(draw_buf, buf1, buf2, gfx.width() * LV_BUFFER_LINE);
|
||||
#endif
|
||||
|
||||
static lv_disp_drv_t disp_drv;
|
||||
lv_disp_drv_init(&disp_drv);
|
||||
disp_drv.hor_res = gfx.width();
|
||||
disp_drv.ver_res = gfx.height();
|
||||
disp_drv.flush_cb = lvgl_flush_cb;
|
||||
disp_drv.draw_buf = draw_buf;
|
||||
disp_drv.user_data = &gfx;
|
||||
lv_disp_drv_register(&disp_drv);
|
||||
|
||||
static lv_indev_drv_t indev_drv;
|
||||
lv_indev_drv_init(&indev_drv);
|
||||
indev_drv.type = LV_INDEV_TYPE_POINTER;
|
||||
indev_drv.read_cb = lvgl_read_cb;
|
||||
indev_drv.user_data = &gfx;
|
||||
lv_indev_t *indev = lv_indev_drv_register(&indev_drv);
|
||||
|
||||
#if defined(ARDUINO) && defined(ESP_PLATFORM)
|
||||
const esp_timer_create_args_t periodic_timer_args = {.callback = &lvgl_tick_timer, .name = "lvgl_tick_timer"};
|
||||
esp_timer_handle_t periodic_timer;
|
||||
ESP_ERROR_CHECK(esp_timer_create(&periodic_timer_args, &periodic_timer));
|
||||
ESP_ERROR_CHECK(esp_timer_start_periodic(periodic_timer, LV_TICK_PERIOD_MS * 1000));
|
||||
xTaskCreate(lv_task_handler, "lv_task", 4096, NULL, 1, NULL);
|
||||
#elif !defined(ARDUINO) && (__has_include(<SDL2/SDL.h>) || __has_include(<SDL.h>))
|
||||
SDL_AddTimer(10, lvgl_tick_timer, NULL);
|
||||
SDL_CreateThread(lvgl_sdl_thread, "lvgl_sdl_thread", NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
void lvgl_port_lock(void) {
|
||||
#if defined(ARDUINO) && defined(ESP_PLATFORM)
|
||||
xSemaphoreTake(xGuiSemaphore, portMAX_DELAY);
|
||||
#elif !defined(ARDUINO) && (__has_include(<SDL2/SDL.h>) || __has_include(<SDL.h>))
|
||||
SDL_LockMutex(xGuiMutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
void lvgl_port_unlock(void) {
|
||||
#if defined(ARDUINO) && defined(ESP_PLATFORM)
|
||||
xSemaphoreGive(xGuiSemaphore);
|
||||
#elif !defined(ARDUINO) && (__has_include(<SDL2/SDL.h>) || __has_include(<SDL.h>))
|
||||
SDL_UnlockMutex(xGuiMutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef __LVGL_PORT_M5STACK_HPP__
|
||||
#define __LVGL_PORT_M5STACK_HPP__
|
||||
|
||||
#if defined(ARDUINO)
|
||||
#include <Arduino.h>
|
||||
#endif
|
||||
#include <M5GFX.h>
|
||||
#include "lvgl.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void lvgl_port_init(M5GFX &gfx);
|
||||
void lvgl_port_lock(void);
|
||||
void lvgl_port_unlock(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __LVGL_PORT_M5STACK_HPP__
|
||||
@@ -0,0 +1,21 @@
|
||||
#include <M5GFX.h>
|
||||
#if defined(SDL_h_)
|
||||
|
||||
void setup(void);
|
||||
void loop(void);
|
||||
|
||||
__attribute__((weak)) int user_func(bool *running) {
|
||||
setup();
|
||||
do {
|
||||
loop();
|
||||
} while (*running);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int, char **) {
|
||||
// The second argument is effective for step execution with breakpoints.
|
||||
// You can specify the time in milliseconds to perform slow execution that ensures screen updates.
|
||||
return lgfx::Panel_sdl::main(user_func, 128);
|
||||
}
|
||||
|
||||
#endif
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 220 KiB |
@@ -0,0 +1,26 @@
|
||||
Import("env", "projenv")
|
||||
|
||||
for e in [ env, projenv ]:
|
||||
# If compiler uses `-m32`, propagate it to linker.
|
||||
# Add via script, because `-Wl,-m32` does not work.
|
||||
if "-m32" in e['CCFLAGS']:
|
||||
e.Append(LINKFLAGS = ["-m32"])
|
||||
|
||||
exec_name = "${BUILD_DIR}/${PROGNAME}${PROGSUFFIX}"
|
||||
|
||||
# Override unused "upload" to execute compiled binary
|
||||
from SCons.Script import AlwaysBuild
|
||||
AlwaysBuild(env.Alias("upload", exec_name, exec_name))
|
||||
|
||||
# Add custom target to explorer
|
||||
env.AddTarget(
|
||||
name = "execute",
|
||||
dependencies = exec_name,
|
||||
actions = exec_name,
|
||||
title = "Execute",
|
||||
description = "Build and execute",
|
||||
group="General"
|
||||
)
|
||||
|
||||
#print('=====================================')
|
||||
#print(env.Dump())
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
|
||||
This directory is intended for PlatformIO Test Runner and project tests.
|
||||
|
||||
Unit Testing is a software testing method by which individual units of
|
||||
source code, sets of one or more MCU program modules together with associated
|
||||
control data, usage procedures, and operating procedures, are tested to
|
||||
determine whether they are fit for use. Unit testing finds problems early
|
||||
in the development cycle.
|
||||
|
||||
More information about PlatformIO Unit Testing:
|
||||
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
||||
Reference in New Issue
Block a user