1010#include < esp_log.h>
1111#include < driver/i2c.h>
1212#include < soc/efuse_reg.h>
13+ #include < soc/gpio_reg.h>
1314
1415#include " lgfx/v1/panel/Panel_ILI9342.hpp"
1516#include " lgfx/v1/panel/Panel_ST7735.hpp"
@@ -306,7 +307,7 @@ namespace m5gfx
306307 *(volatile uint32_t *)GPIO_FUNC35_OUT_SEL_CFG_REG = flg ? 0x43 : 0x100 ;
307308 if (flg == false )
308309 { // CS low の場合はD/Cとして扱うためGPIO出力を有効にする;
309- *(volatile uint32_t *)GPIO_ENABLE1_W1TS_REG = (0x1 << (GPIO_NUM_35 - 32 ));
310+ *(volatile uint32_t *)GPIO_ENABLE1_W1TS_REG = (0x1 << (GPIO_NUM_35 & 31 ));
310311 }
311312 }
312313 };
@@ -370,6 +371,27 @@ namespace m5gfx
370371 }
371372 };
372373
374+ struct Light_M5AtomS3 : public lgfx ::Light_PWM
375+ {
376+ Light_M5AtomS3 (void )
377+ {
378+ auto cfg = config ();
379+ // / The backlight of AtomS3 does not light up if the PWM cycle is too fast.
380+ cfg.freq = 240 ;
381+ cfg.pin_bl = GPIO_NUM_16;
382+ cfg.pwm_channel = 7 ;
383+ config (cfg);
384+ }
385+
386+ void setBrightness (uint8_t brightness) override
387+ {
388+ if (brightness)
389+ {
390+ brightness = brightness - (brightness >> 3 ) + 31 ;
391+ }
392+ Light_PWM::setBrightness (brightness);
393+ }
394+ };
373395
374396
375397#endif
@@ -944,7 +966,6 @@ namespace m5gfx
944966 cfg.pin_int = GPIO_NUM_36;
945967 cfg.pin_sda = GPIO_NUM_21;
946968 cfg.pin_scl = GPIO_NUM_22;
947- cfg.i2c_addr = 0x14 ;
948969#ifdef _M5EPD_H_
949970 cfg.i2c_port = I2C_NUM_0;
950971#else
@@ -958,11 +979,6 @@ namespace m5gfx
958979 cfg.offset_rotation = 1 ;
959980 cfg.bus_shared = false ;
960981 t->config (cfg);
961- if (!t->init ())
962- {
963- cfg.i2c_addr = 0x5D ; // addr change (0x14 or 0x5D)
964- t->config (cfg);
965- }
966982 _panel_last->touch (t);
967983 }
968984 goto init_clear;
@@ -1023,7 +1039,7 @@ namespace m5gfx
10231039 p->config (cfg);
10241040 }
10251041 _panel_last.reset (p);
1026- _set_pwm_backlight (GPIO_NUM_16, 7 , 240 ); // / AtomS3LCDのバックライトはPWM周期が速いと点灯しない ;
1042+ _set_backlight ( new Light_M5AtomS3 ()) ;
10271043
10281044 goto init_clear;
10291045 }
@@ -1113,7 +1129,7 @@ namespace m5gfx
11131129 void M5GFX::progressBar (int x, int y, int w, int h, uint8_t val)
11141130 {
11151131 drawRect (x, y, w, h, 0x09F1 );
1116- fillRect (x + 1 , y + 1 , w * (((float )val) / 100.0 ), h - 1 , 0x09F1 );
1132+ fillRect (x + 1 , y + 1 , w * (((float )val) / 100 .0f ), h - 1 , 0x09F1 );
11171133 }
11181134
11191135 void M5GFX::pushState (void )
0 commit comments