Skip to content

Commit

Permalink
Merge pull request #84 from m5stack/develop
Browse files Browse the repository at this point in the history
0.1.13
  • Loading branch information
lovyan03 authored Mar 4, 2024
2 parents 7d13394 + 75c1977 commit 5342c2b
Show file tree
Hide file tree
Showing 31 changed files with 248,051 additions and 13,927 deletions.
12 changes: 10 additions & 2 deletions examples/PlatformIO_SDL/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ https://docs.m5stack.com/ja/quick_start/m5unified/intro_vscode
https://docs.platformio.org/en/latest/platforms/native.html#installation

#### for Windows
follow the [MSYS2](https://www.msys2.org/) installation guide and add the following paths to the `PATH` system environment variable:
follow the [MSYS2](https://www.msys2.org/) installation guide .
Run the following command on msys2 to install gcc and gdb .
``` msys2
pacman -S mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-gdb
```

Add the following paths to the `PATH` system environment variable:
```
C:\msys64\mingw64\bin
C:\msys64\ucrt64\bin
Expand Down Expand Up @@ -41,7 +47,7 @@ xcode-select --install

Go to the [SDL repository on github and obtain the release package (SDL2-devel-x.x.x-mingw.zip).](https://github.com/libsdl-org/SDL/releases)

Unzip the zip file and copy the following four files to `C:\msys64\mingw64`
Unzip the zip file and copy the following four files to `C:\msys64\ucrt64`

- share
- bin
Expand Down Expand Up @@ -71,6 +77,8 @@ Open the `PlatformIO_SDL` folder containing this document in PlatformIO.

Click on the ![PlatformIO](img_pio.png) icon on the left side of the screen.
Click `PROJECT TASKS` -> `native` -> `General` -> `Upload`
※ If you are using arm processor, use `native_arm` instead of `native` (e.g. M1mac)

![execute](img_00.png)

※ The window may start up with the window hidden behind. Check the task tray.
Expand Down
10 changes: 10 additions & 0 deletions examples/PlatformIO_SDL/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,18 @@ build_type = debug
build_flags = -O0 -xc++ -std=c++14 -lSDL2
-I"/usr/local/include/SDL2" ; for intel mac homebrew SDL2
-L"/usr/local/lib" ; for intel mac homebrew SDL2
-DM5GFX_SHOW_FRAME ; Display frame image.
-DM5GFX_BACK_COLOR=0x222222u ; Color outside the frame image

[env:native_arm]
platform = native
build_type = debug
build_flags = -O0 -xc++ -std=c++14 -lSDL2
-arch arm64 ; for arm mac
-I"${sysenv.HOMEBREW_PREFIX}/include/SDL2" ; for arm mac homebrew SDL2
-L"${sysenv.HOMEBREW_PREFIX}/lib" ; for arm mac homebrew SDL2
-DM5GFX_SHOW_FRAME ; Display frame image.
-DM5GFX_BACK_COLOR=0x222222u ; Color outside the frame image

[env:native_StickCPlus]
extends = native
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "git",
"url": "https://github.com/m5stack/M5GFX.git"
},
"version": "0.1.12",
"version": "0.1.13",
"frameworks": ["arduino", "espidf", "*"],
"platforms": ["espressif32", "native"],
"headers": "M5GFX.h"
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=M5GFX
version=0.1.12
version=0.1.13
author=M5Stack
maintainer=M5Stack
sentence=Library for M5Stack All Display
Expand Down
132 changes: 90 additions & 42 deletions src/M5GFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#if defined ( ESP_PLATFORM )

#include <cstdint>
#include <sdkconfig.h>
#include <nvs.h>
#include <esp_log.h>
Expand All @@ -26,6 +27,7 @@
#else

#include "lgfx/v1/platforms/sdl/Panel_sdl.hpp"
#include "picture_frame/picture_frame.h"

#endif

Expand All @@ -41,6 +43,16 @@ namespace m5gfx
}

#if defined ( ESP_PLATFORM )

void i2c_write_register8_array(int_fast16_t i2c_port, uint_fast8_t i2c_addr, const uint8_t* reg_data_mask, uint32_t freq)
{
while (reg_data_mask[0] != 0xFF || reg_data_mask[1] != 0xFF || reg_data_mask[2] != 0xFF)
{
lgfx::i2c::writeRegister8(i2c_port, i2c_addr, reg_data_mask[0], reg_data_mask[1], reg_data_mask[2], freq);
reg_data_mask += 3;
}
}

#if !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32)
static constexpr std::int32_t axp_i2c_freq = 400000;
static constexpr std::uint_fast8_t axp_i2c_addr = 0x34;
Expand Down Expand Up @@ -823,44 +835,66 @@ namespace m5gfx

if (axp_exists && (board == 0 || board == board_t::board_M5StackCore2 || board == board_t::board_M5Tough))
{
if (axp_exists == 192) { // AXP192
// fore Core2 1st gen (AXP192)
// AXP192_LDO2 = LCD PWR
// AXP192_IO4 = LCD RST
// AXP192_DC3 = LCD BL (Core2)
// AXP192_LDO3 = LCD BL (Tough)
// AXP192_IO1 = TP RST (Tough)
lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x95, 0x84, 0x72, axp_i2c_freq); // GPIO4 enable
lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x28, 0xF0, ~0, axp_i2c_freq); // set LDO2 3300mv // LCD PWR
lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x12, 0x04, ~0, axp_i2c_freq); // LDO2 enable
lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x92, 0x00, 0xF8, axp_i2c_freq); // GPIO1 OpenDrain (M5Tough TOUCH)
if (use_reset)
{
lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x96, 0, ~0x02, axp_i2c_freq); // GPIO4 LOW (LCD RST)
lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x94, 0, ~0x02, axp_i2c_freq); // GPIO1 LOW (M5Tough TOUCH RST)
lgfx::delay(1);
}
lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x96, 0x02, ~0, axp_i2c_freq); // GPIO4 HIGH (LCD RST)
lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x94, 0x02, ~0, axp_i2c_freq); // GPIO1 HIGH (M5Tough TOUCH RST)
} else if (axp_exists == 2101) { // AXP2101
static constexpr uint8_t reg_data_axp192_first[] = {
0x95, 0x84, 0x72, // GPIO4 enable
0x28, 0xF0, 0xFF, // set LDO2 3300mv // LCD PWR
0x12, 0x04, 0xFF, // LDO2 enable
0x92, 0x00, 0xF8, // GPIO1 OpenDrain (M5Tough TOUCH)
0xFF, 0xFF, 0xFF,
};
static constexpr uint8_t reg_data_axp192_reset[] = {
0x96, 0x00, 0xFD, // GPIO4 LOW (LCD RST)
0x94, 0x00, 0xFD, // GPIO1 LOW (M5Tough TOUCH RST)
0xFF, 0xFF, 0xFF,
};
static constexpr uint8_t reg_data_axp192_second[] = {
0x96, 0x02, 0xFF, // GPIO4 HIGH (LCD RST)
0x94, 0x02, 0xFF, // GPIO1 HIGH (M5Tough TOUCH RST)
0xFF, 0xFF, 0xFF,
};

// for Core2 v1.1 (AXP2101)
// ALDO2 == LCD+TOUCH RST
// ALDO3 == SPK EN
// ALDO4 == TF, TP, LCD PWR
// BLDO1 == LCD BL
// BLDO2 == Boost EN
// DLDO1 == Vibration Motor
lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x90, 0x08, 0x7B, axp_i2c_freq); // ALDO4 ON / ALDO3 OFF, DLDO1 OFF
lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x80, 0x05, 0xFF, axp_i2c_freq); // DCDC1 + DCDC3 ON
lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x82, 0x12, 0x00, axp_i2c_freq); // DCDC1 3.3V
lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x84, 0x6A, 0x00, axp_i2c_freq); // DCDC3 3.3V
if (use_reset) {
lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x90, 0, ~0x02, axp_i2c_freq); // ALDO2 OFF
lgfx::delay(1);
}
lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x90, 0x02, ~0, axp_i2c_freq); // ALDO2 ON
static constexpr uint8_t reg_data_axp2101_first[] = {
0x90, 0x08, 0x7B, // ALDO4 ON / ALDO3 OFF, DLDO1 OFF
0x80, 0x05, 0xFF, // DCDC1 + DCDC3 ON
0x82, 0x12, 0x00, // DCDC1 3.3V
0x84, 0x6A, 0x00, // DCDC3 3.3V
0xFF, 0xFF, 0xFF,
};
static constexpr uint8_t reg_data_axp2101_reset[] = {
0x90, 0x00, 0xFD, // ALDO2 OFF
0xFF, 0xFF, 0xFF,
};
static constexpr uint8_t reg_data_axp2101_second[] = {
0x90, 0x02, 0xFF, // ALDO2 ON
0xFF, 0xFF, 0xFF,
};

_pin_level(GPIO_NUM_5, true);

bool isAxp192 = axp_exists == 192;

i2c_write_register8_array(axp_i2c_port, axp_i2c_addr, isAxp192 ? reg_data_axp192_first : reg_data_axp2101_first, axp_i2c_freq);
if (use_reset) {
i2c_write_register8_array(axp_i2c_port, axp_i2c_addr, isAxp192 ? reg_data_axp192_reset : reg_data_axp2101_reset, axp_i2c_freq);
lgfx::delay(1);
}
{
_pin_level(GPIO_NUM_5, true);
i2c_write_register8_array(axp_i2c_port, axp_i2c_addr, isAxp192 ? reg_data_axp192_second : reg_data_axp2101_second, axp_i2c_freq);
lgfx::delay(1);

{
bus_cfg.pin_mosi = GPIO_NUM_23;
bus_cfg.pin_miso = GPIO_NUM_38;
bus_cfg.pin_sclk = GPIO_NUM_18;
Expand Down Expand Up @@ -893,10 +927,10 @@ namespace m5gfx
board = board_t::board_M5StackCore2;

ILight* light = nullptr;
if (axp_exists == 2101) {
light = new Light_M5StackCore2_AXP2101();
} else {
if (isAxp192) {
light = new Light_M5StackCore2();
} else {
light = new Light_M5StackCore2_AXP2101();
}
_set_backlight(light);

Expand Down Expand Up @@ -1308,8 +1342,8 @@ namespace m5gfx
bus_spi->config(bus_cfg);
bus_spi->init();
id = _read_panel_id(bus_spi, GPIO_NUM_7);
if ((id & 0xFF) == 0x85)
{ // check panel (ST7789)
if ((id & 0xFF) == 0x81)
{ // check panel (ST7789V2)
board = board_t::board_M5DinMeter;
ESP_LOGW(LIBRARY_NAME, "[Autodetect] board_M5DinMeter");
bus_spi->release();
Expand Down Expand Up @@ -1540,8 +1574,11 @@ namespace m5gfx
h = 240;
break;

case board_M5Stack:
case board_M5StackCore2:
pnl_cfg.offset_rotation = 3;
r = 1;
break;
case board_M5Stack:
case board_M5StackCoreS3:
pnl_cfg.offset_rotation = 3;
r = 1;
Expand All @@ -1556,16 +1593,23 @@ namespace m5gfx
break;
}

#if defined (M5GFX_ROTATION)
{
if (M5GFX_ROTATION & 1)
{
auto t = w;
w = h;
h = t;
}
pnl_cfg.offset_rotation = ((pnl_cfg.offset_rotation + M5GFX_ROTATION) & 3)
+ ((pnl_cfg.offset_rotation ^ M5GFX_ROTATION) & 4);
// #if defined (M5GFX_ROTATION)
// {
// if (M5GFX_ROTATION & 1)
// {
// auto t = w;
// w = h;
// h = t;
// }
// pnl_cfg.offset_rotation = ((pnl_cfg.offset_rotation + M5GFX_ROTATION) & 3)
// + ((pnl_cfg.offset_rotation ^ M5GFX_ROTATION) & 4);
// }
// #endif

#if defined (M5GFX_SHOW_FRAME)
auto pf = getPictureFrame(board);
if (pf) {
p->setFrameImage(pf->img, pf->w, pf->h, pf->x, pf->y);
}
#endif

Expand All @@ -1576,6 +1620,11 @@ namespace m5gfx
pnl_cfg.bus_shared = false;
p->config(pnl_cfg);
p->setScaling(scale, scale);

#if defined (M5GFX_ROTATION)
p->setFrameRotation(M5GFX_ROTATION);
#endif

p->setRotation(r);

auto t = new lgfx::Touch_sdl();
Expand Down Expand Up @@ -1629,5 +1678,4 @@ namespace m5gfx
_cursor_x = s.cursor_x;
_cursor_y = s.cursor_y;
}

}
Loading

0 comments on commit 5342c2b

Please sign in to comment.