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+
1639class 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
0 commit comments