Skip to content

Commit 9230e2a

Browse files
authored
Merge pull request #21 from m5stack/develop
0.0.12
2 parents 8b88b8f + 23b4232 commit 9230e2a

23 files changed

+450
-273
lines changed

docs/ATOMDisplay.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ Sample Code:
2424
M5AtomDisplay display;
2525
2626
27-
// Set the resolution in the argument (width, height). default : 1280, 720.
28-
// 引数で解像度(幅,高さ)を設定できます。 省略時は 1280, 720
27+
// Set the resolution in the argument (width, height, refresh rate). default : 1280, 720, 60 .
28+
// The value of width x height x refresh rate must be within 55,296,000.
29+
// If the display does not match the supported resolution or frequency of the display, it will not be displayed correctly.
30+
31+
// 引数で解像度(幅,高さ,リフレッシュレート)を設定できます。 省略時は 1280, 720, 60
32+
// 幅 × 高さ × リフレッシュレート の値が 55,296,000 以下である必要があります。
33+
// また、ディスプレイが指定の解像度や周波数に対応していない場合は正しく表示されません。
2934
30-
// M5AtomDisplay display( 480, 1920);
3135
// M5AtomDisplay display(1920, 480);
3236
// M5AtomDisplay display(1280, 720);
3337
// M5AtomDisplay display(1024, 768);
@@ -47,22 +51,26 @@ M5AtomDisplay display;
4751
// M5AtomDisplay display( 160, 80);
4852
// M5AtomDisplay display( 80, 160);
4953
// M5AtomDisplay display( 80, 80);
54+
// M5AtomDisplay display( 480, 1920);
55+
56+
// M5AtomDisplay display(1920, 1080, 24);
57+
// M5AtomDisplay display(1920, 960, 30);
5058
5159
5260
// Depending on the supported resolution of the display, it may not be displayed correctly.
53-
// You may be able to display it by setting the resolution (width and height) to be output to the display with the arguments 3 and 4.
54-
// You can also set the scaling factor for width and height with arguments 5 and 6.
61+
// You may be able to display it by setting the resolution (width and height) to be output to the display with the arguments 4 and 5.
62+
// You can also set the scaling factor for width and height with arguments 6 and 7.
5563
// If the enlarged resolution is less than the output resolution, there will be a gap around the perimeter of the screen.
5664
// ディスプレイの対応解像度によっては正しく表示できない場合があります。
57-
// 引数3と4でディスプレイに出力する解像度(幅,高さ)を設定することで表示できる場合があります。
58-
// また、引数5と6で幅と高さの拡大倍率を設定できます
65+
// 引数4と5でディスプレイに出力する解像度(幅,高さ)を設定することで表示できる場合があります。
66+
// また、引数6と7で幅と高さの拡大倍率を設定できます
5967
// なお拡大後の解像度が出力解像度に満たない場合、画面外周に隙間が生じます。
6068
61-
// M5AtomDisplay display ( 512, 384, 1280, 800, 2, 2 );
69+
// M5AtomDisplay display ( 512, 384, 60, 1280, 800, 2, 2 );
6270
6371
// ※ The width scaling factor must be a number that is divisible by the width of the output resolution.
6472
// ※ 幅の拡大倍率は、出力解像度の幅を割り切れる数である必要があります。
65-
// ex: M5AtomDisplay display ( 400, 250, 1280, 800, 3, 3 );
73+
// ex: M5AtomDisplay display ( 400, 250, 60, 1280, 800, 3, 3 );
6674
// In this example, 1280 is not divisible by 3, so the horizontal scaling factor will be changed to 2.
6775
// この例は 1280 を 3で割り切れないため、横方向の拡大倍率は2に変更されます。
6876

library.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"type": "git",
1111
"url": "https://github.com/m5stack/M5GFX.git"
1212
},
13-
"version": "0.0.11",
13+
"version": "0.0.12",
1414
"framework": "arduino",
15-
"platforms": "espressif32"
15+
"platforms": "espressif32",
16+
"headers": "M5GFX.h"
1617
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=M5GFX
2-
version=0.0.11
2+
version=0.0.12
33
author=M5Stack
44
maintainer=M5Stack
55
sentence=Library for M5Stack All Display

src/M5AtomDisplay.h

Lines changed: 66 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,35 @@
77
// #include <SPIFFS.h>
88
// #include <HTTPClient.h>
99

10+
#include <sdkconfig.h>
1011
#include <esp_efuse.h>
1112
#include <soc/efuse_reg.h>
1213

1314
#include "M5GFX.h"
1415
#include "lgfx/v1/panel/Panel_M5HDMI.hpp"
1516

17+
#ifndef M5ATOMDISPLAY_LOGICAL_WIDTH
18+
#define M5ATOMDISPLAY_LOGICAL_WIDTH 1280
19+
#endif
20+
#ifndef M5ATOMDISPLAY_LOGICAL_HEIGHT
21+
#define M5ATOMDISPLAY_LOGICAL_HEIGHT 720
22+
#endif
23+
#ifndef M5ATOMDISPLAY_REFRESH_RATE
24+
#define M5ATOMDISPLAY_REFRESH_RATE 60.0f
25+
#endif
26+
#ifndef M5ATOMDISPLAY_OUTPUT_WIDTH
27+
#define M5ATOMDISPLAY_OUTPUT_WIDTH 0
28+
#endif
29+
#ifndef M5ATOMDISPLAY_OUTPUT_HEIGHT
30+
#define M5ATOMDISPLAY_OUTPUT_HEIGHT 0
31+
#endif
32+
#ifndef M5ATOMDISPLAY_SCALE_W
33+
#define M5ATOMDISPLAY_SCALE_W 0
34+
#endif
35+
#ifndef M5ATOMDISPLAY_SCALE_H
36+
#define M5ATOMDISPLAY_SCALE_H 0
37+
#endif
38+
1639
class M5AtomDisplay : public lgfx::LGFX_Device
1740
{
1841
lgfx::Panel_M5HDMI _panel_instance;
@@ -22,8 +45,17 @@ class M5AtomDisplay : public lgfx::LGFX_Device
2245

2346
m5gfx::board_t getBoard(void) const { return m5gfx::board_t::board_M5AtomDisplay; }
2447

25-
M5AtomDisplay(uint16_t logical_width = 0, uint16_t logical_height = 0, uint16_t output_width = 0, uint16_t output_height = 0, uint_fast8_t x_scale = 0, uint_fast8_t y_scale = 0)
48+
M5AtomDisplay( uint16_t logical_width = M5ATOMDISPLAY_LOGICAL_WIDTH
49+
, uint16_t logical_height = M5ATOMDISPLAY_LOGICAL_HEIGHT
50+
, float refresh_rate = M5ATOMDISPLAY_REFRESH_RATE
51+
, uint16_t output_width = M5ATOMDISPLAY_OUTPUT_WIDTH
52+
, uint16_t output_height = M5ATOMDISPLAY_OUTPUT_HEIGHT
53+
, uint_fast8_t scale_w = M5ATOMDISPLAY_SCALE_W
54+
, uint_fast8_t scale_h = M5ATOMDISPLAY_SCALE_H
55+
)
2656
{
57+
#if defined (CONFIG_IDF_TARGET_ESP32)
58+
2759
static constexpr int i2c_port = 1;
2860
static constexpr int i2c_sda = 25;
2961
static constexpr int i2c_scl = 21;
@@ -68,15 +100,19 @@ class M5AtomDisplay : public lgfx::LGFX_Device
68100

69101
{
70102
static constexpr int SCALE_MAX = 16;
103+
static constexpr int RANGE_MAX = 2048;
104+
105+
if (refresh_rate < 8.0f) { refresh_rate = 8.0f; }
106+
if (refresh_rate > 256.0f) { refresh_rate = 256.0f; }
71107

72108
if (output_width)
73109
{
74-
if (output_width > 1920) { output_width = 1920; }
110+
if (output_width > RANGE_MAX) { output_width = RANGE_MAX; }
75111
if (logical_width > output_width) { logical_width = output_width; }
76112
}
77113
if (output_height)
78114
{
79-
if (output_height > 1920) { output_height = 1920; }
115+
if (output_height > RANGE_MAX) { output_height = RANGE_MAX; }
80116
if (logical_height > output_height) { logical_height = output_height; }
81117
}
82118

@@ -97,40 +133,46 @@ class M5AtomDisplay : public lgfx::LGFX_Device
97133
{
98134
logical_height = (logical_width * 9) >> 4;
99135
}
136+
if (logical_width > RANGE_MAX) { logical_width = RANGE_MAX; }
137+
if (logical_height > RANGE_MAX) { logical_height = RANGE_MAX; }
138+
139+
int limit = 55296000 / refresh_rate;
100140

101-
if (output_width == 0 && output_height == 0 && x_scale == 0 && y_scale == 0)
141+
if (output_width == 0 && output_height == 0 && scale_w == 0 && scale_h == 0)
102142
{
103-
x_scale = 1;
104-
y_scale = 1;
143+
scale_w = 1;
144+
scale_h = 1;
105145
for (int scale = 2; scale <= SCALE_MAX; ++scale)
106146
{
107147
uint32_t scale_height = scale * logical_height;
108148
uint32_t scale_width = scale * logical_width;
109149
uint32_t total = scale_width * scale_height;
110-
if (scale_width > 1920 || scale_height > 1920 || total >= 1024000) { break; }
111-
x_scale = scale;
112-
y_scale = scale;
150+
if (scale_width > 1920 || scale_height > 1920 || total > limit) { break; }
151+
scale_w = scale;
152+
scale_h = scale;
113153
}
114-
output_width = x_scale * logical_width;
115-
output_height = y_scale * logical_height;
154+
output_width = scale_w * logical_width;
155+
output_height = scale_h * logical_height;
156+
if (output_height & 1) { output_height++; }
157+
if ((output_width & 1) && (scale_w & 1)) { output_width += scale_w; }
116158
}
117159
else
118160
{
119-
if (y_scale == 0)
161+
if (scale_h == 0)
120162
{
121-
y_scale = output_height / logical_height;
163+
scale_h = output_height / logical_height;
122164
}
123-
if (y_scale > SCALE_MAX) { y_scale = SCALE_MAX; }
124-
while (logical_height * y_scale > output_height) { --y_scale; }
165+
if (scale_h > SCALE_MAX) { scale_h = SCALE_MAX; }
166+
while (logical_height * scale_h > output_height) { --scale_h; }
125167

126-
if (x_scale == 0)
168+
if (scale_w == 0)
127169
{
128-
x_scale = output_width / logical_width;
170+
scale_w = output_width / logical_width;
129171
}
130-
uint32_t w = output_width / x_scale;
131-
while (x_scale > SCALE_MAX || w * x_scale != output_width || logical_width * x_scale > output_width)
172+
uint32_t w = output_width / scale_w;
173+
while (scale_w > SCALE_MAX || w * scale_w != output_width || logical_width * scale_w > output_width)
132174
{
133-
w = output_width / --x_scale;
175+
w = output_width / --scale_w;
134176
}
135177
}
136178

@@ -139,16 +181,17 @@ class M5AtomDisplay : public lgfx::LGFX_Device
139181
cfg.memory_height = output_height ;
140182
cfg.panel_width = logical_width ;
141183
cfg.panel_height = logical_height;
142-
cfg.offset_x = (output_width / x_scale - logical_width ) >> 1;
143-
cfg.offset_y = (output_height / y_scale - logical_height) >> 1;
184+
cfg.offset_x = (output_width / scale_w - logical_width ) >> 1;
185+
cfg.offset_y = (output_height / scale_h - logical_height) >> 1;
144186
cfg.offset_rotation = 0;
145187
cfg.pin_cs = spi_cs;
146188
cfg.readable = false;
147189
cfg.bus_shared = false;
148190

149-
_panel_instance.config(cfg);
191+
_panel_instance.config(cfg, scale_w, scale_h, refresh_rate);
150192
}
151193
setPanel(&_panel_instance);
194+
#endif
152195
}
153196
};
154197

src/M5GFX.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// Copyright (c) M5Stack. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
#if defined (ESP32) || defined (CONFIG_IDF_TARGET_ESP32) || defined (CONFIG_IDF_TARGET_ESP32S2) || defined (ESP_PLATFORM)
5-
4+
#include <sdkconfig.h>
65
#include "M5GFX.h"
76

87
#include "lgfx/v1/panel/Panel_ILI9342.hpp"
@@ -16,20 +15,22 @@
1615
#include <nvs.h>
1716
#include <esp_log.h>
1817
#include <driver/i2c.h>
18+
#include <esp_efuse.h>
1919
#include <soc/efuse_reg.h>
2020

2121
namespace m5gfx
2222
{
2323
static constexpr char LIBRARY_NAME[] = "M5GFX";
2424

25+
M5GFX* M5GFX::_instance = nullptr;
26+
27+
#if !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32)
2528
static constexpr std::int32_t axp_i2c_freq = 400000;
2629
static constexpr std::uint_fast8_t axp_i2c_addr = 0x34;
2730
static constexpr std::int_fast16_t axp_i2c_port = I2C_NUM_1;
2831
static constexpr std::int_fast16_t axp_i2c_sda = 21;
2932
static constexpr std::int_fast16_t axp_i2c_scl = 22;
3033

31-
M5GFX* M5GFX::_instance = nullptr;
32-
3334
struct Panel_M5Stack : public lgfx::Panel_ILI9342
3435
{
3536
Panel_M5Stack(void)
@@ -260,11 +261,6 @@ namespace m5gfx
260261
}
261262
};
262263

263-
M5GFX::M5GFX(void) : LGFX_Device()
264-
{
265-
if (_instance == nullptr) _instance = this;
266-
}
267-
268264
static void _pin_level(std::int_fast16_t pin, bool level)
269265
{
270266
lgfx::pinMode(pin, lgfx::pin_mode_t::output);
@@ -309,13 +305,11 @@ namespace m5gfx
309305
return res;
310306
}
311307

312-
static std::uint32_t _get_chip_ver_pkg(void)
313-
{
314-
std::uint32_t res = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_VER_PKG);
315-
#if defined ( EFUSE_RD_CHIP_VER_PKG_4BIT )
316-
res |= REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_VER_PKG_4BIT) << 3;
317308
#endif
318-
return res;
309+
310+
M5GFX::M5GFX(void) : LGFX_Device()
311+
{
312+
if (_instance == nullptr) _instance = this;
319313
}
320314

321315
void M5GFX::_set_backlight(lgfx::ILight* bl)
@@ -423,6 +417,7 @@ namespace m5gfx
423417

424418
board_t M5GFX::autodetect(bool use_reset, board_t board)
425419
{
420+
#if !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32)
426421
auto bus_cfg = _bus_spi.config();
427422

428423
panel(nullptr);
@@ -452,7 +447,7 @@ namespace m5gfx
452447

453448
std::uint32_t id;
454449

455-
std::uint32_t pkg_ver = _get_chip_ver_pkg();
450+
std::uint32_t pkg_ver = esp_efuse_get_pkg_ver();
456451

457452
if (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4) /// check PICO-D4 (M5StickC,CPlus,T,T2 / CoreInk / ATOM )
458453
{
@@ -843,9 +838,10 @@ namespace m5gfx
843838
}
844839

845840
}
841+
#endif
846842

847843
board = board_t::board_unknown;
848-
844+
goto init_clear;
849845
init_clear:
850846

851847
ESP_LOGI("nvs_board","_board:%d", board);
@@ -885,5 +881,3 @@ ESP_LOGI("nvs_board","_board:%d", board);
885881
}
886882

887883
}
888-
889-
#endif

src/M5GFX.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,19 @@ namespace m5gfx
144144
, board_M5StackCoreInk
145145
, board_M5Paper
146146
, board_M5Tough
147-
, board_M5ATOM
147+
, board_M5Station
148+
149+
/// non display boards
150+
, board_M5Atom
151+
, board_M5ATOM = board_M5Atom
148152
, board_M5Camera
149153
, board_M5TimerCam
150-
, board_M5Station
154+
, board_M5StampPico
155+
, board_M5StampC3
156+
157+
/// external displays
151158
, board_M5AtomDisplay
159+
, board_M5ATOMDisplay = board_M5AtomDisplay
152160
, board_M5UnitLCD
153161
, board_M5UnitOLED
154162
};
@@ -229,3 +237,4 @@ using namespace m5gfx::ili9341_colors;
229237
using namespace m5gfx::tft_command;
230238
using M5GFX = m5gfx::M5GFX;
231239
using M5Canvas = m5gfx::M5Canvas;
240+
using RGBColor = m5gfx::bgr888_t;

src/M5UnitLCD.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
#include <Arduino.h>
1414
static constexpr std::uint8_t M5_UNIT_LCD_SDA = SDA;
1515
static constexpr std::uint8_t M5_UNIT_LCD_SCL = SCL;
16+
#elif defined (ESP_PLATFORM)
17+
#include <sdkconfig.h>
18+
#if defined (CONFIG_IDF_TARGET_ESP32C3)
19+
static constexpr std::uint8_t M5_UNIT_LCD_SDA = 1;
20+
static constexpr std::uint8_t M5_UNIT_LCD_SCL = 0;
21+
#else
22+
static constexpr std::uint8_t M5_UNIT_LCD_SDA = 21;
23+
static constexpr std::uint8_t M5_UNIT_LCD_SCL = 22;
24+
#endif
1625
#else
1726
static constexpr std::uint8_t M5_UNIT_LCD_SDA = 21;
1827
static constexpr std::uint8_t M5_UNIT_LCD_SCL = 22;

src/M5UnitOLED.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
#include <Arduino.h>
1414
static constexpr std::uint8_t M5_UNIT_OLED_SDA = SDA;
1515
static constexpr std::uint8_t M5_UNIT_OLED_SCL = SCL;
16+
#elif defined (ESP_PLATFORM)
17+
#include <sdkconfig.h>
18+
#if defined (CONFIG_IDF_TARGET_ESP32C3)
19+
static constexpr std::uint8_t M5_UNIT_OLED_SDA = 1;
20+
static constexpr std::uint8_t M5_UNIT_OLED_SCL = 0;
21+
#else
22+
static constexpr std::uint8_t M5_UNIT_OLED_SDA = 21;
23+
static constexpr std::uint8_t M5_UNIT_OLED_SCL = 22;
24+
#endif
1625
#else
1726
static constexpr std::uint8_t M5_UNIT_OLED_SDA = 21;
1827
static constexpr std::uint8_t M5_UNIT_OLED_SCL = 22;

src/lgfx/Fonts/Ascii24x48.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
//
2222
/************************************************************************************/
2323

24-
const unsigned char FontLib24x48[] = {
24+
PROGMEM const unsigned char FontLib24x48[] = {
2525

2626
/* 0x00 [ ] [ 0 ] */
2727
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0 commit comments

Comments
 (0)