Skip to content

Commit 283f638

Browse files
authored
Merge pull request #22 from m5stack/develop
0.0.13
2 parents 9230e2a + 5c31905 commit 283f638

File tree

16 files changed

+438
-245
lines changed

16 files changed

+438
-245
lines changed

examples/Basic/AnalogMeter/AnalogMeter.ino

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ M5GFX display;
1313
//M5UnitLCD display ( 21, 22, 400000 ); // SDA, SCL, FREQ
1414

1515
//#include <M5AtomDisplay.h>
16-
//M5AtomDisplay display;
16+
//M5AtomDisplay display; // default setting
17+
//M5AtomDisplay display ( 320, 180 ); // width, height
1718

1819

1920
static constexpr float deg_to_rad = 0.017453292519943295769236907684886;
@@ -178,11 +179,10 @@ void setup(void)
178179

179180
void loop(void)
180181
{
181-
if (updateTime <= millis())
182+
auto msec = millis();
183+
if (updateTime <= msec)
182184
{
183-
updateTime = millis() + LOOP_PERIOD;
184-
185-
d += 4; if (d >= 360) d = 0;
185+
d = (msec >> 3) % 360;
186186

187187
// Create a Sine wave for testing
188188
value[0] = 50 + roundf(50 * sinf((d + 0) * deg_to_rad));
@@ -196,6 +196,7 @@ void loop(void)
196196

197197
if (!display.displayBusy())
198198
{
199+
updateTime = msec + LOOP_PERIOD;
199200
//unsigned long t = millis();
200201
display.startWrite();
201202
plotPointer();

examples/Basic/SpinTile/SpinTile.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ M5GFX display;
1010
//M5UnitLCD display; // default setting
1111
//M5UnitLCD display ( 21, 22, 400000 ); // SDA, SCL, FREQ
1212

13-
// #include <M5AtomDisplay.h>
14-
// M5AtomDisplay display;
13+
//#include <M5AtomDisplay.h>
14+
//M5AtomDisplay display; // default setting
15+
//M5AtomDisplay display ( 320, 180 ); // width, height
1516

1617
static constexpr const int qsintab[256]={
1718
0x8000,0x80c9,0x8192,0x825b,0x8324,0x83ee,0x84b7,0x8580,
@@ -189,4 +190,3 @@ void loop(void)
189190
p_dyx = dyx;
190191
p_dyy = dyy;
191192
}
192-

examples/Basic/TextLogScroll/TextLogScroll.ino

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ M5GFX display;
1111
//M5UnitLCD display ( 21, 22, 400000 ); // SDA, SCL, FREQ
1212

1313
//#include <M5AtomDisplay.h>
14-
//M5AtomDisplay display;
15-
16-
M5Canvas canvas(&display);
14+
//M5AtomDisplay display; // default setting
15+
//M5AtomDisplay display ( 320, 180 ); // width, height
1716

1817
static constexpr char text0[] = "hello world";
1918
static constexpr char text1[] = "this";
@@ -25,6 +24,9 @@ static constexpr char text6[] = "scroll";
2524
static constexpr char text7[] = "sample";
2625
static constexpr const char* text[] = { text0, text1, text2, text3, text4, text5, text6, text7 };
2726

27+
//*
28+
/// Example of using canvas
29+
M5Canvas canvas(&display);
2830
void setup(void)
2931
{
3032
display.begin();
@@ -54,3 +56,34 @@ void loop(void)
5456
canvas.pushSprite(0, 0);
5557
++count;
5658
}
59+
60+
/*/
61+
62+
/// Example without canvas
63+
void setup(void)
64+
{
65+
display.begin();
66+
67+
if (display.isEPD())
68+
{
69+
display.setEpdMode(epd_mode_t::epd_fastest);
70+
display.invertDisplay(true);
71+
display.clear(TFT_BLACK);
72+
}
73+
if (display.width() < display.height())
74+
{
75+
display.setRotation(display.getRotation() ^ 1);
76+
}
77+
78+
display.setTextSize((float)display.width() / 160);
79+
display.setTextScroll(true);
80+
}
81+
82+
void loop(void)
83+
{
84+
static int count = 0;
85+
86+
display.printf("%04d:%s\r\n", count, text[count & 7]);
87+
++count;
88+
}
89+
//*/

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"type": "git",
1111
"url": "https://github.com/m5stack/M5GFX.git"
1212
},
13-
"version": "0.0.12",
13+
"version": "0.0.13",
1414
"framework": "arduino",
1515
"platforms": "espressif32",
1616
"headers": "M5GFX.h"

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.12
2+
version=0.0.13
33
author=M5Stack
44
maintainer=M5Stack
55
sentence=Library for M5Stack All Display

src/M5AtomDisplay.h

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

10+
#include "lgfx/v1/panel/Panel_M5HDMI.hpp"
11+
#include "M5GFX.h"
12+
1013
#include <sdkconfig.h>
1114
#include <esp_efuse.h>
1215
#include <soc/efuse_reg.h>
1316

14-
#include "M5GFX.h"
15-
#include "lgfx/v1/panel/Panel_M5HDMI.hpp"
16-
1717
#ifndef M5ATOMDISPLAY_LOGICAL_WIDTH
1818
#define M5ATOMDISPLAY_LOGICAL_WIDTH 1280
1919
#endif
2020
#ifndef M5ATOMDISPLAY_LOGICAL_HEIGHT
2121
#define M5ATOMDISPLAY_LOGICAL_HEIGHT 720
2222
#endif
2323
#ifndef M5ATOMDISPLAY_REFRESH_RATE
24-
#define M5ATOMDISPLAY_REFRESH_RATE 60.0f
24+
#define M5ATOMDISPLAY_REFRESH_RATE 0.0f
2525
#endif
2626
#ifndef M5ATOMDISPLAY_OUTPUT_WIDTH
2727
#define M5ATOMDISPLAY_OUTPUT_WIDTH 0
@@ -43,8 +43,6 @@ class M5AtomDisplay : public lgfx::LGFX_Device
4343

4444
public:
4545

46-
m5gfx::board_t getBoard(void) const { return m5gfx::board_t::board_M5AtomDisplay; }
47-
4846
M5AtomDisplay( uint16_t logical_width = M5ATOMDISPLAY_LOGICAL_WIDTH
4947
, uint16_t logical_height = M5ATOMDISPLAY_LOGICAL_HEIGHT
5048
, float refresh_rate = M5ATOMDISPLAY_REFRESH_RATE
@@ -54,8 +52,7 @@ class M5AtomDisplay : public lgfx::LGFX_Device
5452
, uint_fast8_t scale_h = M5ATOMDISPLAY_SCALE_H
5553
)
5654
{
57-
#if defined (CONFIG_IDF_TARGET_ESP32)
58-
55+
#if !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32)
5956
static constexpr int i2c_port = 1;
6057
static constexpr int i2c_sda = 25;
6158
static constexpr int i2c_scl = 21;
@@ -67,6 +64,7 @@ class M5AtomDisplay : public lgfx::LGFX_Device
6764
? 23 // for ATOM Lite / Matrix
6865
: 5 // for ATOM PSRAM
6966
;
67+
7068
{
7169
auto cfg = _bus_instance.config();
7270
cfg.freq_write = 80000000;
@@ -99,99 +97,45 @@ class M5AtomDisplay : public lgfx::LGFX_Device
9997
}
10098

10199
{
102-
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; }
107-
108-
if (output_width)
109-
{
110-
if (output_width > RANGE_MAX) { output_width = RANGE_MAX; }
111-
if (logical_width > output_width) { logical_width = output_width; }
112-
}
113-
if (output_height)
114-
{
115-
if (output_height > RANGE_MAX) { output_height = RANGE_MAX; }
116-
if (logical_height > output_height) { logical_height = output_height; }
117-
}
118-
119-
if (logical_width == 0)
120-
{
121-
if (logical_height == 0)
122-
{
123-
logical_width = 1280;
124-
logical_height = 720;
125-
}
126-
else
127-
{
128-
logical_width = (logical_height << 4) / 9;
129-
}
130-
}
131-
else
132-
if (logical_height == 0)
133-
{
134-
logical_height = (logical_width * 9) >> 4;
135-
}
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;
140-
141-
if (output_width == 0 && output_height == 0 && scale_w == 0 && scale_h == 0)
142-
{
143-
scale_w = 1;
144-
scale_h = 1;
145-
for (int scale = 2; scale <= SCALE_MAX; ++scale)
146-
{
147-
uint32_t scale_height = scale * logical_height;
148-
uint32_t scale_width = scale * logical_width;
149-
uint32_t total = scale_width * scale_height;
150-
if (scale_width > 1920 || scale_height > 1920 || total > limit) { break; }
151-
scale_w = scale;
152-
scale_h = scale;
153-
}
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; }
158-
}
159-
else
160-
{
161-
if (scale_h == 0)
162-
{
163-
scale_h = output_height / logical_height;
164-
}
165-
if (scale_h > SCALE_MAX) { scale_h = SCALE_MAX; }
166-
while (logical_height * scale_h > output_height) { --scale_h; }
167-
168-
if (scale_w == 0)
169-
{
170-
scale_w = output_width / logical_width;
171-
}
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)
174-
{
175-
w = output_width / --scale_w;
176-
}
177-
}
178-
179100
auto cfg = _panel_instance.config();
180-
cfg.memory_width = output_width ;
181-
cfg.memory_height = output_height ;
182-
cfg.panel_width = logical_width ;
183-
cfg.panel_height = logical_height;
184-
cfg.offset_x = (output_width / scale_w - logical_width ) >> 1;
185-
cfg.offset_y = (output_height / scale_h - logical_height) >> 1;
186-
cfg.offset_rotation = 0;
187-
cfg.pin_cs = spi_cs;
101+
cfg.pin_cs = spi_cs;
188102
cfg.readable = false;
189103
cfg.bus_shared = false;
190-
191-
_panel_instance.config(cfg, scale_w, scale_h, refresh_rate);
104+
_panel_instance.config(cfg);
192105
}
193-
setPanel(&_panel_instance);
194106
#endif
107+
lgfx::Panel_M5HDMI::config_resolution_t cfg_reso;
108+
cfg_reso.logical_width = logical_width;
109+
cfg_reso.logical_height = logical_height;
110+
cfg_reso.refresh_rate = refresh_rate;
111+
cfg_reso.output_width = output_width;
112+
cfg_reso.output_height = output_height;
113+
cfg_reso.scale_w = scale_w;
114+
cfg_reso.scale_h = scale_h;
115+
_panel_instance.config_resolution(cfg_reso);
116+
117+
setPanel(&_panel_instance);
118+
_board = lgfx::board_t::board_M5AtomDisplay;
119+
}
120+
121+
bool setResolution( uint16_t logical_width = M5ATOMDISPLAY_LOGICAL_WIDTH
122+
, uint16_t logical_height = M5ATOMDISPLAY_LOGICAL_HEIGHT
123+
, float refresh_rate = M5ATOMDISPLAY_REFRESH_RATE
124+
, uint16_t output_width = M5ATOMDISPLAY_OUTPUT_WIDTH
125+
, uint16_t output_height = M5ATOMDISPLAY_OUTPUT_HEIGHT
126+
, uint_fast8_t scale_w = M5ATOMDISPLAY_SCALE_W
127+
, uint_fast8_t scale_h = M5ATOMDISPLAY_SCALE_H
128+
)
129+
{
130+
return _panel_instance.setResolution
131+
( logical_width
132+
, logical_height
133+
, refresh_rate
134+
, output_width
135+
, output_height
136+
, scale_w
137+
, scale_h
138+
);
195139
}
196140
};
197141

src/M5GFX.h

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -132,37 +132,6 @@ namespace m5gfx
132132
static constexpr int TFT_SLPOUT = 0x11;
133133
}
134134

135-
namespace boards
136-
{
137-
enum board_t
138-
{ board_unknown
139-
, board_Non_Panel
140-
, board_M5Stack
141-
, board_M5StackCore2
142-
, board_M5StickC
143-
, board_M5StickCPlus
144-
, board_M5StackCoreInk
145-
, board_M5Paper
146-
, board_M5Tough
147-
, board_M5Station
148-
149-
/// non display boards
150-
, board_M5Atom
151-
, board_M5ATOM = board_M5Atom
152-
, board_M5Camera
153-
, board_M5TimerCam
154-
, board_M5StampPico
155-
, board_M5StampC3
156-
157-
/// external displays
158-
, board_M5AtomDisplay
159-
, board_M5ATOMDisplay = board_M5AtomDisplay
160-
, board_M5UnitLCD
161-
, board_M5UnitOLED
162-
};
163-
}
164-
using board_t = boards::board_t;
165-
166135
class M5GFX : public lgfx::LGFX_Device
167136
{
168137
friend m5::M5Unified;
@@ -181,7 +150,6 @@ namespace m5gfx
181150
lgfx::Panel_Device* _panel_last;
182151
lgfx::ILight* _light_last;
183152
lgfx::ITouch* _touch_last;
184-
board_t _board;
185153
std::vector<DisplayState> _displayStateStack;
186154

187155
bool init_impl(bool use_reset, bool use_clear) override;
@@ -200,8 +168,6 @@ namespace m5gfx
200168

201169
static M5GFX* getInstance(void) { return _instance; }
202170

203-
inline board_t getBoard(void) const { return _board; }
204-
205171
void clearDisplay(int32_t color = TFT_BLACK) { fillScreen(color); }
206172
void progressBar(int x, int y, int w, int h, uint8_t val);
207173
void pushState(void);
@@ -218,6 +184,32 @@ namespace m5gfx
218184
{
219185
pushImage(x, y, w, h, (const rgb565_t*)data, transparent);
220186
}
187+
188+
bool setResolution( uint16_t logical_width = 0
189+
, uint16_t logical_height = 0
190+
, float refresh_rate = 0
191+
, uint16_t output_width = 0
192+
, uint16_t output_height = 0
193+
, uint_fast8_t scale_w = 0
194+
, uint_fast8_t scale_h = 0
195+
)
196+
{
197+
#ifdef __M5GFX_M5ATOMDISPLAY__
198+
if (getBoard() == board_t::board_M5AtomDisplay)
199+
{
200+
return ((Panel_M5HDMI*)panel())->setResolution
201+
( logical_width
202+
, logical_height
203+
, refresh_rate
204+
, output_width
205+
, output_height
206+
, scale_w
207+
, scale_h
208+
);
209+
}
210+
#endif
211+
return false;
212+
}
221213
};
222214

223215

0 commit comments

Comments
 (0)