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
4444public:
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
0 commit comments