From 1bb24a30df9b35ae0cdacf03670ae63283333e2b Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:33:53 +0900 Subject: [PATCH 01/12] Fixed the problem that the operation of TwoWire suddenly became strange when using it together with Arduino TwoWire on ESP32S3 --- README.md | 2 ++ src/lgfx/v1/platforms/esp32/Bus_SPI.cpp | 2 +- src/lgfx/v1/platforms/esp32/common.cpp | 14 +++++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8413f59..cd831d8 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Supported device ---------------- - M5Stack ( Basic / Gray / GO / Fire ) - M5Stack Core2 +- M5Stack CoreS3 / CoreS3SE - M5Stack CoreInk - M5Stick C - M5Stick C Plus @@ -23,6 +24,7 @@ Supported device - M5Dial - M5DinMeter - M5Cardputer +- M5VAMeter - UnitOLED - UnitMiniOLED - UnitLCD diff --git a/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp b/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp index 4d3368c..2aa114b 100644 --- a/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp +++ b/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp @@ -22,7 +22,7 @@ Original Source: /// ESP32-S3をターゲットにした際にREG_SPI_BASEが定義されていなかったので応急処置 ; #if defined ( CONFIG_IDF_TARGET_ESP32S3 ) - #if ( ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 3, 0) ) + #if !defined( REG_SPI_BASE ) #define REG_SPI_BASE(i) (DR_REG_SPI1_BASE + (((i)>1) ? (((i)* 0x1000) + 0x20000) : (((~(i)) & 1)* 0x1000 ))) #endif #elif defined ( CONFIG_IDF_TARGET_ESP32 ) || !defined ( CONFIG_IDF_TARGET ) diff --git a/src/lgfx/v1/platforms/esp32/common.cpp b/src/lgfx/v1/platforms/esp32/common.cpp index 1a46efa..81b384a 100644 --- a/src/lgfx/v1/platforms/esp32/common.cpp +++ b/src/lgfx/v1/platforms/esp32/common.cpp @@ -775,6 +775,7 @@ namespace lgfx if (fifo_reg == ®[i]) { continue; } reg[i] = _reg_store[i]; } + updateDev(dev); } void setPins(i2c_dev_t* dev, gpio_num_t scl, gpio_num_t sda) @@ -862,10 +863,6 @@ namespace lgfx gpio_set_direction(scl_io, GPIO_MODE_OUTPUT_OD); delayMicroseconds(I2C_CLR_BUS_HALF_PERIOD_US); - auto mod = getPeriphModule(i2c_port); - // ESP-IDF環境でperiph_module_disableを使うと、後でenableできなくなる問題が起きたためコメントアウト; - //periph_module_disable(mod); - // SDAがHIGHになるまでSTOP送出を繰り返す。; int i = 0; do @@ -879,9 +876,10 @@ namespace lgfx gpio_set_level(sda_io, 1); delayMicroseconds(I2C_CLR_BUS_HALF_PERIOD_US); } while (!gpio_get_level(sda_io) && (i++ < I2C_CLR_BUS_SCL_NUM)); - periph_module_enable(mod); + #if !defined (CONFIG_IDF_TARGET_ESP32C3) /// ESP32C3で periph_module_reset を使用すると以後通信不能になる問題が起きたため分岐; + auto mod = getPeriphModule(i2c_port); periph_module_reset(mod); #endif i2c_set_pin((i2c_port_t)i2c_port, sda_io, scl_io, gpio_pullup_t::GPIO_PULLUP_ENABLE, gpio_pullup_t::GPIO_PULLUP_ENABLE, I2C_MODE_MASTER); @@ -1005,6 +1003,9 @@ namespace lgfx #endif #endif #endif +#else + auto mod = getPeriphModule(i2c_port); + periph_module_disable(mod); #endif if ((int)i2c_context[i2c_port].pin_scl >= 0) { @@ -1074,6 +1075,9 @@ namespace lgfx #else twowire->begin((int)i2c_context[i2c_port].pin_sda, (int)i2c_context[i2c_port].pin_scl); #endif +#else + auto mod = getPeriphModule(i2c_port); + periph_module_enable(mod); #endif i2c_context[i2c_port].initialized = true; From 1da133c6f6a4a4ddabb515084da08cdb092ff48c Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Wed, 12 Jun 2024 21:15:35 +0900 Subject: [PATCH 02/12] improve autodetect for CoreS3 / CoreS3SE --- src/M5GFX.cpp | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/src/M5GFX.cpp b/src/M5GFX.cpp index 7ec726b..a7e4050 100644 --- a/src/M5GFX.cpp +++ b/src/M5GFX.cpp @@ -325,6 +325,7 @@ namespace m5gfx static constexpr int32_t i2c_freq = 400000; static constexpr int_fast16_t aw9523_i2c_addr = 0x58; // AW9523B static constexpr int_fast16_t axp_i2c_addr = 0x34; // AXP2101 + static constexpr int_fast16_t gc0308_i2c_addr = 0x21; // GC0308 static constexpr int_fast16_t i2c_port = I2C_NUM_1; static constexpr int_fast16_t i2c_sda = GPIO_NUM_12; static constexpr int_fast16_t i2c_scl = GPIO_NUM_11; @@ -1183,7 +1184,8 @@ namespace m5gfx m5gfx::i2c::writeRegister8(i2c_port, aw9523_i2c_addr, 0x12, 0b11111111); // LEDMODE_P0 m5gfx::i2c::writeRegister8(i2c_port, aw9523_i2c_addr, 0x13, 0b11111111); // LEDMODE_P1 m5gfx::i2c::writeRegister8(i2c_port, axp_i2c_addr, 0x90, 0xBF); // LDOS ON/OFF control 0 - m5gfx::i2c::writeRegister8(i2c_port, axp_i2c_addr, 0x95, 0x28); // ALDO3 set to 3.3v // for TF card slot + m5gfx::i2c::writeRegister8(i2c_port, axp_i2c_addr, 0x94, 33 - 5); // ALDO3 set to 3.3v // for GC0308 Camera + m5gfx::i2c::writeRegister8(i2c_port, axp_i2c_addr, 0x95, 33 - 5); // ALDO4 set to 3.3v // for TF card slot bus_cfg.pin_mosi = GPIO_NUM_37; bus_cfg.pin_miso = GPIO_NUM_35; @@ -1199,31 +1201,14 @@ namespace m5gfx id = _read_panel_id(bus_spi, GPIO_NUM_3); if ((id & 0xFF) == 0xE3) { // check panel (ILI9342) - gpio::pin_backup_t backup_pins[] = { GPIO_NUM_38, GPIO_NUM_45, GPIO_NUM_46 }; - auto result = lgfx::gpio::command( - (const uint8_t[]) { - lgfx::gpio::command_mode_input_pulldown, GPIO_NUM_38, // CoreS3 = CAM_HREF - lgfx::gpio::command_mode_input_pulldown, GPIO_NUM_45, // CoreS3 = CAM_PCLK - lgfx::gpio::command_mode_input_pulldown, GPIO_NUM_46, // CoreS3 = CAM_VSYNC - lgfx::gpio::command_mode_input_pullup , GPIO_NUM_38, - lgfx::gpio::command_read , GPIO_NUM_38, - lgfx::gpio::command_mode_input_pullup , GPIO_NUM_45, - lgfx::gpio::command_read , GPIO_NUM_45, - lgfx::gpio::command_mode_input_pullup , GPIO_NUM_46, - lgfx::gpio::command_read , GPIO_NUM_46, - lgfx::gpio::command_end - } - ); - for (auto &bup : backup_pins) { bup.restore(); } - - // In "CoreS3", even if GPIO38,45,46 are set to Input_pullup, LOW is output. - // This characteristic can be used to distinguish between the two models. board = board_t::board_M5StackCoreS3; - if (result == 0b111) { + // Camera GC0308 check (not found == M5StackCoreS3SE) + auto chk_gc = lgfx::i2c::readRegister8(i2c_port, gc0308_i2c_addr, 0x00, i2c_freq); + if (chk_gc .has_value() && chk_gc .value() == 0x9b) { + ESP_LOGW(LIBRARY_NAME, "[Autodetect] board_M5StackCoreS3"); + } else { board = board_M5StackCoreS3SE; ESP_LOGW(LIBRARY_NAME, "[Autodetect] board_M5StackCoreS3SE"); - } else { - ESP_LOGW(LIBRARY_NAME, "[Autodetect] board_M5StackCoreS3"); } bus_cfg.freq_write = 40000000; bus_cfg.freq_read = 16000000; From a3e8d38214fe107fc09493dfb50fd43aa67c8f20 Mon Sep 17 00:00:00 2001 From: dianjixz Date: Tue, 23 Jul 2024 14:36:55 +0800 Subject: [PATCH 03/12] [fix] freambuff compile error This commit adds following: * add board_FrameBuffer = 512 * Add compilation conditions for SDL and sdl. * Fix the release code for the framebuffer device. --- src/lgfx/boards.hpp | 2 ++ src/lgfx/v1/platforms/common.hpp | 6 +++--- src/lgfx/v1/platforms/device.hpp | 2 +- src/lgfx/v1/platforms/framebuffer/Panel_fb.cpp | 6 +----- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/lgfx/boards.hpp b/src/lgfx/boards.hpp index 4f701f3..86e5110 100644 --- a/src/lgfx/boards.hpp +++ b/src/lgfx/boards.hpp @@ -52,6 +52,8 @@ namespace lgfx // This should not be changed to "m5gfx" , board_M5UnitRCA , board_M5ModuleDisplay , board_M5ModuleRCA + + , board_FrameBuffer = 512 }; } using namespace boards; diff --git a/src/lgfx/v1/platforms/common.hpp b/src/lgfx/v1/platforms/common.hpp index 4789dd6..edd5d5e 100644 --- a/src/lgfx/v1/platforms/common.hpp +++ b/src/lgfx/v1/platforms/common.hpp @@ -49,15 +49,15 @@ Original Source: #include "arduino_default/common.hpp" -#elif __has_include() || __has_include() +#elif (__has_include() || __has_include()) && !defined(LGFX_LINUX_FB) #include "sdl/common.hpp" -#elif __has_include() +#elif __has_include() && !defined(LGFX_LINUX_FB) #include "opencv/common.hpp" -#elif defined (__linux__) +#elif defined (__linux__) && defined(LGFX_LINUX_FB) #include "framebuffer/common.hpp" diff --git a/src/lgfx/v1/platforms/device.hpp b/src/lgfx/v1/platforms/device.hpp index 84f33b9..7bc2bd8 100644 --- a/src/lgfx/v1/platforms/device.hpp +++ b/src/lgfx/v1/platforms/device.hpp @@ -93,7 +93,7 @@ Original Source: #include "arduino_default/Bus_SPI.hpp" -#elif __has_include() || __has_include() +#elif (__has_include() || __has_include()) && !defined(LGFX_LINUX_FB) #include "sdl/Bus_I2C.hpp" #include "sdl/Panel_sdl.hpp" diff --git a/src/lgfx/v1/platforms/framebuffer/Panel_fb.cpp b/src/lgfx/v1/platforms/framebuffer/Panel_fb.cpp index 48f4416..3b02f25 100644 --- a/src/lgfx/v1/platforms/framebuffer/Panel_fb.cpp +++ b/src/lgfx/v1/platforms/framebuffer/Panel_fb.cpp @@ -89,15 +89,11 @@ namespace lgfx { // unmap fb file from memory munmap(_fbp, _screensize); - // reset the display mode - if (ioctl(_fbfd, FBIOPUT_VSCREENINFO, &_fix_info)) { - printf("Error re-setting variable information.\n"); - } // close fb file close(_fbfd); memset(&_fix_info, 0, sizeof(_fix_info)); - memset(&_var_info, 0, sizeof(_fix_info)); + memset(&_var_info, 0, sizeof(_var_info)); } Panel_fb::Panel_fb(void) : Panel_Device(), _fbp(nullptr) From f21ff90736486810db8aa9cda9c8ded1f9d2a31f Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Mon, 12 Aug 2024 10:40:24 +0900 Subject: [PATCH 04/12] add pushImageARGB function ( for argb8888_t* / bgra8888_t* ) --- src/lgfx/v1/LGFXBase.cpp | 10 ++++----- src/lgfx/v1/LGFXBase.hpp | 28 ++++++++++++++++++++++++++ src/lgfx/v1/LGFX_Sprite.hpp | 6 ++++++ src/lgfx/v1/misc/common_function.cpp | 8 +++++++- src/lgfx/v1/misc/pixelcopy.hpp | 6 +++--- src/lgfx/v1/platforms/esp32/common.cpp | 7 +++++-- 6 files changed, 54 insertions(+), 11 deletions(-) diff --git a/src/lgfx/v1/LGFXBase.cpp b/src/lgfx/v1/LGFXBase.cpp index 2b3a7d7..2f132e0 100644 --- a/src/lgfx/v1/LGFXBase.cpp +++ b/src/lgfx/v1/LGFXBase.cpp @@ -1125,7 +1125,7 @@ namespace lgfx for( int ys=0;ys 16) { if (dst_depth == rgb888_3Byte) { - pc_post.fp_copy = pixelcopy_t::blend_rgb_fast; + pc_post.fp_copy = pixelcopy_t::blend_rgb_fast; } else { - pc_post.fp_copy = pixelcopy_t::blend_rgb_fast; + pc_post.fp_copy = pixelcopy_t::blend_rgb_fast; } } else { if (dst_depth == rgb565_2Byte) { - pc_post.fp_copy = pixelcopy_t::blend_rgb_fast; + pc_post.fp_copy = pixelcopy_t::blend_rgb_fast; } else { // src_depth == rgb332_1Byte: - pc_post.fp_copy = pixelcopy_t::blend_rgb_fast; + pc_post.fp_copy = pixelcopy_t::blend_rgb_fast; } } push_image_affine_aa(matrix, pc, &pc_post); diff --git a/src/lgfx/v1/LGFXBase.hpp b/src/lgfx/v1/LGFXBase.hpp index 979fec8..ec96117 100644 --- a/src/lgfx/v1/LGFXBase.hpp +++ b/src/lgfx/v1/LGFXBase.hpp @@ -564,6 +564,34 @@ namespace lgfx LGFX_INLINE_T void pushGrayscaleImageRotateZoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const uint8_t* image, color_depth_t depth, const T& forecolor, const T& backcolor) { push_grayimage_rotate_zoom(dst_x, dst_y, src_x, src_y, angle, zoom_x, zoom_y, w, h, image, depth, convert_to_rgb888(forecolor), convert_to_rgb888(backcolor)); } LGFX_INLINE_T void pushGrayscaleImageAffine(const float matrix[6], int32_t w, int32_t h, const uint8_t* image, color_depth_t depth, const T& forecolor, const T& backcolor) { push_grayimage_affine(matrix, w, h, image, depth, convert_to_rgb888(forecolor), convert_to_rgb888(backcolor)); } +//---------------------------------------------------------------------------- + + // T == bgra8888_t or argb8888_t + template + void pushImageARGB(int32_t x, int32_t y, int32_t w, int32_t h, const T* data) + { + auto pc = create_pc(data); + if (pc.dst_bits > 16) { + if (pc.dst_depth == rgb888_3Byte) { + pc.fp_copy = pixelcopy_t::blend_rgb_fast; + } else { + pc.fp_copy = pixelcopy_t::blend_rgb_fast; + } + } else { + if (pc.dst_depth == rgb565_2Byte) { + pc.fp_copy = pixelcopy_t::blend_rgb_fast; + } else { // src_depth == rgb332_1Byte: + pc.fp_copy = pixelcopy_t::blend_rgb_fast; + } + } + pc.src_bitwidth = w; + pc.src_width = w; + pc.src_height = h; + startWrite(); + _panel->writeImageARGB(x, y, w, h, &pc); + endWrite(); + } + //---------------------------------------------------------------------------- /// read RGB565 16bit color diff --git a/src/lgfx/v1/LGFX_Sprite.hpp b/src/lgfx/v1/LGFX_Sprite.hpp index 58210b5..44f3ebc 100644 --- a/src/lgfx/v1/LGFX_Sprite.hpp +++ b/src/lgfx/v1/LGFX_Sprite.hpp @@ -201,6 +201,12 @@ namespace lgfx return createFromBmp(&data); } + bool createFromBmpFile(const char *path) + { + auto data = _create_data_wrapper(); + return create_from_bmp_file(data, path); + } + template bool createFromBmpFile(T &fs, const char *path) { diff --git a/src/lgfx/v1/misc/common_function.cpp b/src/lgfx/v1/misc/common_function.cpp index 6ef28f4..ffd264b 100644 --- a/src/lgfx/v1/misc/common_function.cpp +++ b/src/lgfx/v1/misc/common_function.cpp @@ -11,7 +11,13 @@ namespace lgfx void memset_multi(uint8_t* buf, uint32_t c, size_t size, size_t length) { - if (size == 1 || ((c & 0xFF) == ((c >> 8) & 0xFF) && (size == 2 || ((c & 0xFF) == ((c >> 16) & 0xFF))))) + if (size == 1 + || ( (c & 0xFF) == ((c >> 8) & 0xFF) + && ( size == 2 + || ( (c & 0xFF) == ((c >> 16) & 0xFF) + && ( size == 3 + || ( (c & 0xFF) == ((c >> 24) & 0xFF) + )))))) { memset(buf, c, size * length); return; diff --git a/src/lgfx/v1/misc/pixelcopy.hpp b/src/lgfx/v1/misc/pixelcopy.hpp index 6a4147e..fa7a46f 100644 --- a/src/lgfx/v1/misc/pixelcopy.hpp +++ b/src/lgfx/v1/misc/pixelcopy.hpp @@ -449,13 +449,13 @@ namespace lgfx return last; } - template + template static uint32_t blend_rgb_fast(void* __restrict dst, uint32_t index, uint32_t last, pixelcopy_t* __restrict param) { auto d = static_cast(dst); auto src_x32_add = param->src_x32_add; auto src_y32_add = param->src_y32_add; - auto s = static_cast(param->src_data); + auto s = static_cast(param->src_data); for (;;) { uint32_t i = param->src_x + param->src_y * param->src_bitwidth; uint_fast16_t a = s[i].a; @@ -463,7 +463,7 @@ namespace lgfx { if (a == 255) { - d[index].set(s[i].r, s[i].g, s[i].b); + d[index].set(s[i].R8(), s[i].G8(), s[i].B8()); param->src_x32 += src_x32_add; param->src_y32 += src_y32_add; if (++index == last) return last; diff --git a/src/lgfx/v1/platforms/esp32/common.cpp b/src/lgfx/v1/platforms/esp32/common.cpp index 81b384a..ffd53fe 100644 --- a/src/lgfx/v1/platforms/esp32/common.cpp +++ b/src/lgfx/v1/platforms/esp32/common.cpp @@ -36,7 +36,10 @@ Original Source: #include #include #if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)) - #include + //#include + #if __has_include() + #include + #endif #else #if __has_include () #include @@ -669,7 +672,7 @@ namespace lgfx static i2c_dev_t* getDev(int num) { -#if SOC_I2C_NUM == 1 +#if SOC_I2C_NUM == 1 || defined CONFIG_IDF_TARGET_ESP32C6 return &I2C0; #else return num == 0 ? &I2C0 : &I2C1; From 613c548f1297740c7066df5e1d86fe09f776e961 Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Tue, 13 Aug 2024 08:14:28 +0900 Subject: [PATCH 05/12] rename pushImageARGB to pushAlphaImage --- src/lgfx/v1/LGFXBase.cpp | 21 +++++++++++++++++++++ src/lgfx/v1/LGFXBase.hpp | 15 ++++++++------- src/lgfx/v1/panel/Panel_Device.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/lgfx/v1/LGFXBase.cpp b/src/lgfx/v1/LGFXBase.cpp index 2f132e0..ac61661 100644 --- a/src/lgfx/v1/LGFXBase.cpp +++ b/src/lgfx/v1/LGFXBase.cpp @@ -1441,6 +1441,27 @@ namespace lgfx endWrite(); } + void LGFXBase::pushAlphaImage(int32_t x, int32_t y, int32_t w, int32_t h, pixelcopy_t *param) + { + uint32_t x_mask = 7 >> (param->src_bits >> 1); + param->src_bitwidth = (w + x_mask) & (~x_mask); + + int32_t dx=0, dw=w; + if (0 < _clip_l - x) { dx = _clip_l - x; dw -= dx; x = _clip_l; } + + if (_adjust_width(x, dx, dw, _clip_l, _clip_r - _clip_l + 1)) return; + param->src_x32 = param->src_x32_add * dx; + + int32_t dy=0, dh=h; + if (0 < _clip_t - y) { dy = _clip_t - y; dh -= dy; y = _clip_t; } + if (_adjust_width(y, dy, dh, _clip_t, _clip_b - _clip_t + 1)) return; + param->src_y = dy; + + startWrite(); + _panel->writeImageARGB(x, y, dw, dh, param); + endWrite(); + } + void LGFXBase::make_rotation_matrix(float* result, float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y) { float rad = fmodf(angle, 360) * deg_to_rad; diff --git a/src/lgfx/v1/LGFXBase.hpp b/src/lgfx/v1/LGFXBase.hpp index ec96117..a20369e 100644 --- a/src/lgfx/v1/LGFXBase.hpp +++ b/src/lgfx/v1/LGFXBase.hpp @@ -568,9 +568,13 @@ namespace lgfx // T == bgra8888_t or argb8888_t template - void pushImageARGB(int32_t x, int32_t y, int32_t w, int32_t h, const T* data) + void pushAlphaImage(int32_t x, int32_t y, int32_t w, int32_t h, const T* data) { auto pc = create_pc(data); + + // not support 1, 2, 4, and palette mode. + if (pc.dst_bits < 8 || this->hasPalette()) { return; } + if (pc.dst_bits > 16) { if (pc.dst_depth == rgb888_3Byte) { pc.fp_copy = pixelcopy_t::blend_rgb_fast; @@ -584,14 +588,11 @@ namespace lgfx pc.fp_copy = pixelcopy_t::blend_rgb_fast; } } - pc.src_bitwidth = w; - pc.src_width = w; - pc.src_height = h; - startWrite(); - _panel->writeImageARGB(x, y, w, h, &pc); - endWrite(); + pushAlphaImage(x, y, w, h, &pc); } + void pushAlphaImage(int32_t x, int32_t y, int32_t w, int32_t h, pixelcopy_t *param); + //---------------------------------------------------------------------------- /// read RGB565 16bit color diff --git a/src/lgfx/v1/panel/Panel_Device.cpp b/src/lgfx/v1/panel/Panel_Device.cpp index f8c7c6b..f876716 100644 --- a/src/lgfx/v1/panel/Panel_Device.cpp +++ b/src/lgfx/v1/panel/Panel_Device.cpp @@ -178,7 +178,30 @@ namespace lgfx } //---------------------------------------------------------------------------- + void Panel_Device::writeImageARGB(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param) + { + auto src_x = param->src_x; + auto bytes = param->dst_bits >> 3; + pixelcopy_t pc_read(nullptr, _write_depth, _read_depth); + pixelcopy_t pc_write(nullptr, _write_depth, _write_depth); + for (;;) + { + uint8_t* dmabuf = _bus->getDMABuffer((w+1) * bytes); + pc_write.src_data = dmabuf; + readRect(x, y, w, 1, dmabuf, &pc_read); + { + param->fp_copy(dmabuf, 0, w, param); + pc_write.src_x = 0; + writeImage(x, y, w, 1, &pc_write, true); + } + if (!--h) return; + param->src_x = src_x; + param->src_y++; + ++y; + } + } +#if 0 void Panel_Device::writeImageARGB(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param) { auto src_x = param->src_x; @@ -237,6 +260,7 @@ namespace lgfx ++y; } } +#endif void Panel_Device::copyRect(uint_fast16_t dst_x, uint_fast16_t dst_y, uint_fast16_t w, uint_fast16_t h, uint_fast16_t src_x, uint_fast16_t src_y) { From ad30566086a7344d3558b53155beffaf6ca549c8 Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Thu, 22 Aug 2024 14:59:16 +0900 Subject: [PATCH 06/12] Fixed an issue where the CS pin would operate unintentionally when using a device that delegates CS control to an SPI peripheral at the same time as the M5GFX. --- src/lgfx/v1/platforms/esp32/Bus_SPI.cpp | 22 +++++++++++++++++++++- src/lgfx/v1/platforms/esp32/common.cpp | 21 ++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp b/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp index 2aa114b..33f480d 100644 --- a/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp +++ b/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp @@ -209,7 +209,27 @@ namespace lgfx } auto spi_mode = _cfg.spi_mode; - uint32_t pin = (spi_mode & 2) ? SPI_CK_IDLE_EDGE : 0; + uint32_t pin = 0 +#if defined ( SPI_CS0_DIS ) + | SPI_CS0_DIS +#endif +#if defined ( SPI_CS1_DIS ) + | SPI_CS1_DIS +#endif +#if defined ( SPI_CS2_DIS ) + | SPI_CS2_DIS +#endif +#if defined ( SPI_CS3_DIS ) + | SPI_CS3_DIS +#endif +#if defined ( SPI_CS4_DIS ) + | SPI_CS4_DIS +#endif +#if defined ( SPI_CS5_DIS ) + | SPI_CS5_DIS +#endif + ; + if (spi_mode & 2) pin = SPI_CK_IDLE_EDGE; if (_cfg.use_lock) spi::beginTransaction(_cfg.spi_host); diff --git a/src/lgfx/v1/platforms/esp32/common.cpp b/src/lgfx/v1/platforms/esp32/common.cpp index ffd53fe..ff7f771 100644 --- a/src/lgfx/v1/platforms/esp32/common.cpp +++ b/src/lgfx/v1/platforms/esp32/common.cpp @@ -580,7 +580,26 @@ namespace lgfx uint32_t user = SPI_USR_MOSI | SPI_USR_MISO | SPI_DOUTDIN; if (spi_mode == 1 || spi_mode == 2) user |= SPI_CK_OUT_EDGE; - uint32_t pin = 0; + uint32_t pin = 0 +#if defined ( SPI_CS0_DIS ) + | SPI_CS0_DIS +#endif +#if defined ( SPI_CS1_DIS ) + | SPI_CS1_DIS +#endif +#if defined ( SPI_CS2_DIS ) + | SPI_CS2_DIS +#endif +#if defined ( SPI_CS3_DIS ) + | SPI_CS3_DIS +#endif +#if defined ( SPI_CS4_DIS ) + | SPI_CS4_DIS +#endif +#if defined ( SPI_CS5_DIS ) + | SPI_CS5_DIS +#endif + ; if (spi_mode & 2) pin = SPI_CK_IDLE_EDGE; beginTransaction(spi_host); From 36286ec135bf3f159c80ed21a37ca55ab8c83bd1 Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Fri, 30 Aug 2024 18:39:43 +0900 Subject: [PATCH 07/12] Fixed an issue where the CS pin would operate unintentionally when using a device that delegates CS control to an SPI peripheral at the same time as the M5GFX. --- src/lgfx/v1/platforms/esp32/Bus_SPI.cpp | 4 ++-- src/lgfx/v1/platforms/esp32/common.cpp | 12 +++--------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp b/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp index 33f480d..15c5070 100644 --- a/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp +++ b/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp @@ -209,7 +209,8 @@ namespace lgfx } auto spi_mode = _cfg.spi_mode; - uint32_t pin = 0 + uint32_t pin = (spi_mode & 2) ? SPI_CK_IDLE_EDGE : 0; + pin = pin #if defined ( SPI_CS0_DIS ) | SPI_CS0_DIS #endif @@ -229,7 +230,6 @@ namespace lgfx | SPI_CS5_DIS #endif ; - if (spi_mode & 2) pin = SPI_CK_IDLE_EDGE; if (_cfg.use_lock) spi::beginTransaction(_cfg.spi_host); diff --git a/src/lgfx/v1/platforms/esp32/common.cpp b/src/lgfx/v1/platforms/esp32/common.cpp index ff7f771..019899d 100644 --- a/src/lgfx/v1/platforms/esp32/common.cpp +++ b/src/lgfx/v1/platforms/esp32/common.cpp @@ -580,7 +580,8 @@ namespace lgfx uint32_t user = SPI_USR_MOSI | SPI_USR_MISO | SPI_DOUTDIN; if (spi_mode == 1 || spi_mode == 2) user |= SPI_CK_OUT_EDGE; - uint32_t pin = 0 + uint32_t pin = (spi_mode & 2) ? SPI_CK_IDLE_EDGE : 0; + pin = pin #if defined ( SPI_CS0_DIS ) | SPI_CS0_DIS #endif @@ -600,7 +601,6 @@ namespace lgfx | SPI_CS5_DIS #endif ; - if (spi_mode & 2) pin = SPI_CK_IDLE_EDGE; beginTransaction(spi_host); @@ -630,13 +630,7 @@ namespace lgfx void endTransaction(int spi_host, int spi_cs) { - if (_spi_dev_handle[spi_host]) { -#if defined (ARDUINO) // Arduino ESP32 - spiEndTransaction(_spi_handle[spi_host]); -#else // ESP-IDF - spi_device_release_bus(_spi_dev_handle[spi_host]); -#endif - } + endTransaction(spi_host); gpio_hi(spi_cs); } From 4206084da89865d0895a9ebe04f2476a5051b9b5 Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Fri, 30 Aug 2024 18:40:32 +0900 Subject: [PATCH 08/12] add AtomS3R --- src/M5GFX.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++- src/lgfx/boards.hpp | 1 + 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/M5GFX.cpp b/src/M5GFX.cpp index a7e4050..72ac72d 100644 --- a/src/M5GFX.cpp +++ b/src/M5GFX.cpp @@ -425,6 +425,25 @@ namespace m5gfx } }; + struct Light_M5StackAtomS3R : public lgfx::ILight + { + bool init(uint8_t brightness) override + { + lgfx::i2c::writeRegister8(i2c_port, 48, 0x00, 0b01000000, 0, i2c_freq); + delay(1); + lgfx::i2c::writeRegister8(i2c_port, 48, 0x08, 0b00000001, 0, i2c_freq); + lgfx::i2c::writeRegister8(i2c_port, 48, 0x70, 0b00000000, 0, i2c_freq); + + setBrightness(brightness); + return true; + } + + void setBrightness(uint8_t brightness) override + { + lgfx::i2c::writeRegister8(i2c_port, 48, 0x0e, brightness, 0, i2c_freq); + } + }; + #endif __attribute__ ((unused)) @@ -1239,7 +1258,7 @@ namespace m5gfx { _pin_reset(GPIO_NUM_34, use_reset); // LCD RST bus_cfg.pin_mosi = GPIO_NUM_21; - bus_cfg.pin_miso = GPIO_NUM_13; + bus_cfg.pin_miso = (gpio_num_t)-1; //GPIO_NUM_NC; bus_cfg.pin_sclk = GPIO_NUM_17; bus_cfg.pin_dc = GPIO_NUM_33; bus_cfg.spi_mode = 0; @@ -1278,6 +1297,50 @@ namespace m5gfx bus_spi->release(); } + if (board == 0 || board == board_t::board_M5AtomS3R) + { + _pin_reset(GPIO_NUM_48, use_reset); // LCD RST + bus_cfg.pin_mosi = GPIO_NUM_21; + bus_cfg.pin_miso = (gpio_num_t)-1; //GPIO_NUM_NC; + bus_cfg.pin_sclk = GPIO_NUM_15; + bus_cfg.pin_dc = GPIO_NUM_42; + bus_cfg.spi_mode = 0; + bus_cfg.spi_3wire = true; + bus_spi->config(bus_cfg); + bus_spi->init(); + id = _read_panel_id(bus_spi, GPIO_NUM_14); + if ((id & 0xFFFFFF) == 0x079100) + { // check panel (GC9107) + board = board_t::board_M5AtomS3R; + ESP_LOGW(LIBRARY_NAME, "[Autodetect] board_M5AtomS3R"); + bus_spi->release(); + bus_cfg.spi_host = SPI3_HOST; + bus_cfg.freq_write = 40000000; + bus_cfg.freq_read = 16000000; + bus_spi->config(bus_cfg); + bus_spi->init(); + auto p = new Panel_GC9107(); + p->bus(bus_spi); + { + auto cfg = p->config(); + cfg.pin_cs = GPIO_NUM_14; + cfg.pin_rst = GPIO_NUM_48; + cfg.panel_width = 128; + cfg.panel_height = 128; + cfg.offset_y = 32; + cfg.readable = false; + cfg.bus_shared = false; + p->config(cfg); + } + _panel_last.reset(p); + _set_backlight(new Light_M5StackAtomS3R()); + + goto init_clear; + } + lgfx::pinMode(GPIO_NUM_48, lgfx::pin_mode_t::input); // LCD RST + bus_spi->release(); + } + if (board == 0 || board == board_t::board_M5Dial) { _pin_reset(GPIO_NUM_8, use_reset); // LCD RST @@ -1571,6 +1634,7 @@ namespace m5gfx case board_M5Tough: title = "M5Tough"; break; case board_M5Station: title = "M5Station"; break; case board_M5AtomS3: title = "M5AtomS3"; break; + case board_M5AtomS3R: title = "M5AtomS3R"; break; case board_M5Dial: title = "M5Dial"; break; case board_M5Cardputer: title = "M5Cardputer"; break; case board_M5DinMeter: title = "M5DinMeter"; break; @@ -1582,6 +1646,7 @@ namespace m5gfx switch (board) { case board_M5AtomS3: + case board_M5AtomS3R: w = 128; h = 128; break; diff --git a/src/lgfx/boards.hpp b/src/lgfx/boards.hpp index 86e5110..104d525 100644 --- a/src/lgfx/boards.hpp +++ b/src/lgfx/boards.hpp @@ -24,6 +24,7 @@ namespace lgfx // This should not be changed to "m5gfx" , board_M5AirQ , board_M5VAMeter , board_M5StackCoreS3SE + , board_M5AtomS3R /// non display boards , board_M5Atom = 128 From 079136c4a37f3481b7a28ffcd15bc1c093f558ed Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Sun, 1 Sep 2024 14:39:00 +0900 Subject: [PATCH 09/12] fix compile error --- src/M5GFX.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/M5GFX.cpp b/src/M5GFX.cpp index 72ac72d..3e22cb3 100644 --- a/src/M5GFX.cpp +++ b/src/M5GFX.cpp @@ -429,8 +429,9 @@ namespace m5gfx { bool init(uint8_t brightness) override { + lgfx::i2c::init(i2c_port, GPIO_NUM_45, GPIO_NUM_0); lgfx::i2c::writeRegister8(i2c_port, 48, 0x00, 0b01000000, 0, i2c_freq); - delay(1); + lgfx::delay(1); lgfx::i2c::writeRegister8(i2c_port, 48, 0x08, 0b00000001, 0, i2c_freq); lgfx::i2c::writeRegister8(i2c_port, 48, 0x70, 0b00000000, 0, i2c_freq); From 7236318c1b0804b997c9ec8539abf12632638cc5 Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Mon, 2 Sep 2024 16:23:02 +0900 Subject: [PATCH 10/12] Improved i2c stability. --- src/lgfx/v1/platforms/esp32/common.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/lgfx/v1/platforms/esp32/common.cpp b/src/lgfx/v1/platforms/esp32/common.cpp index 019899d..b6511a0 100644 --- a/src/lgfx/v1/platforms/esp32/common.cpp +++ b/src/lgfx/v1/platforms/esp32/common.cpp @@ -937,9 +937,8 @@ namespace lgfx #else uint32_t us_limit = (dev->scl_high_period.period + dev->scl_low_period.period + 16 ) * (1 + dev->status_reg.tx_fifo_cnt); #endif - if (i2c_context[i2c_port].wait_ack_stage == 2) { - us_limit += 1024; - } + us_limit += 512 << i2c_context[i2c_port].wait_ack_stage; + do { taskYIELD(); @@ -977,6 +976,7 @@ namespace lgfx i2c_set_cmd(dev, 0, i2c_cmd_stop, 0); i2c_set_cmd(dev, 1, i2c_cmd_end, 0); static constexpr uint32_t intmask_ = I2C_ACK_ERR_INT_RAW_M | I2C_TIME_OUT_INT_RAW_M | I2C_END_DETECT_INT_RAW_M | I2C_ARBITRATION_LOST_INT_RAW_M | I2C_TRANS_COMPLETE_INT_RAW_M; + updateDev(dev); dev->int_clr.val = intmask_; dev->ctr.trans_start = 1; uint32_t ms = lgfx::millis(); @@ -1410,19 +1410,19 @@ namespace lgfx dev->int_clr.val = intmask; dev->ctr.trans_start = 1; + uint32_t us = lgfx::micros(); + taskYIELD(); + int delayus = ((us_limit + 2) >> 2) - (lgfx::micros() - us); + if (delayus > 0) { + delayMicroseconds(delayus); + } do { - uint32_t us = lgfx::micros(); - taskYIELD(); - us = lgfx::micros() - us; - int delayus = ((us_limit + 2) >> 2) - us; - if (delayus > 0) { - delayMicroseconds(delayus); - } + us = lgfx::micros(); do { taskYIELD(); - } while (0 == getRxFifoCount(dev) && !(dev->int_raw.val & intmask) && ((lgfx::micros() - us) <= us_limit + 1024)); + } while ((len>>1) >= getRxFifoCount(dev) && !(dev->int_raw.val & intmask) && ((lgfx::micros() - us) <= us_limit + 1024)); if (0 == getRxFifoCount(dev)) { @@ -1433,7 +1433,7 @@ namespace lgfx i2c_context[i2c_port].wait_ack_stage = 0; return res; } - *readdata++ = *fifo_addr; //dev->fifo_data.data; + *readdata++ = *fifo_addr; } while (--len); } while (length); From b9ee9f02c0b6cac753375c0fe0d66a8c8884f89b Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Fri, 13 Sep 2024 10:35:30 +0900 Subject: [PATCH 11/12] tweak autodetect order for AtomS3R --- src/M5GFX.cpp | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/M5GFX.cpp b/src/M5GFX.cpp index 3e22cb3..e45b26d 100644 --- a/src/M5GFX.cpp +++ b/src/M5GFX.cpp @@ -1255,22 +1255,22 @@ namespace m5gfx lgfx::i2c::release(i2c_port); } - if (board == 0 || board == board_t::board_M5AtomS3) + if (board == 0 || board == board_t::board_M5AtomS3R) { - _pin_reset(GPIO_NUM_34, use_reset); // LCD RST + _pin_reset(GPIO_NUM_48, use_reset); // LCD RST bus_cfg.pin_mosi = GPIO_NUM_21; bus_cfg.pin_miso = (gpio_num_t)-1; //GPIO_NUM_NC; - bus_cfg.pin_sclk = GPIO_NUM_17; - bus_cfg.pin_dc = GPIO_NUM_33; + bus_cfg.pin_sclk = GPIO_NUM_15; + bus_cfg.pin_dc = GPIO_NUM_42; bus_cfg.spi_mode = 0; bus_cfg.spi_3wire = true; bus_spi->config(bus_cfg); bus_spi->init(); - id = _read_panel_id(bus_spi, GPIO_NUM_15); + id = _read_panel_id(bus_spi, GPIO_NUM_14); if ((id & 0xFFFFFF) == 0x079100) { // check panel (GC9107) - board = board_t::board_M5AtomS3; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] board_M5AtomS3"); + board = board_t::board_M5AtomS3R; + ESP_LOGW(LIBRARY_NAME, "[Autodetect] board_M5AtomS3R"); bus_spi->release(); bus_cfg.spi_host = SPI3_HOST; bus_cfg.freq_write = 40000000; @@ -1281,16 +1281,17 @@ namespace m5gfx p->bus(bus_spi); { auto cfg = p->config(); - cfg.pin_cs = GPIO_NUM_15; - cfg.pin_rst = GPIO_NUM_34; + cfg.pin_cs = GPIO_NUM_14; + cfg.pin_rst = GPIO_NUM_48; cfg.panel_width = 128; cfg.panel_height = 128; cfg.offset_y = 32; cfg.readable = false; + cfg.bus_shared = false; p->config(cfg); } _panel_last.reset(p); - _set_pwm_backlight(GPIO_NUM_16, 7, 256, false, 48); + _set_backlight(new Light_M5StackAtomS3R()); goto init_clear; } @@ -1298,22 +1299,22 @@ namespace m5gfx bus_spi->release(); } - if (board == 0 || board == board_t::board_M5AtomS3R) + if (board == 0 || board == board_t::board_M5AtomS3) { - _pin_reset(GPIO_NUM_48, use_reset); // LCD RST + _pin_reset(GPIO_NUM_34, use_reset); // LCD RST bus_cfg.pin_mosi = GPIO_NUM_21; bus_cfg.pin_miso = (gpio_num_t)-1; //GPIO_NUM_NC; - bus_cfg.pin_sclk = GPIO_NUM_15; - bus_cfg.pin_dc = GPIO_NUM_42; + bus_cfg.pin_sclk = GPIO_NUM_17; + bus_cfg.pin_dc = GPIO_NUM_33; bus_cfg.spi_mode = 0; bus_cfg.spi_3wire = true; bus_spi->config(bus_cfg); bus_spi->init(); - id = _read_panel_id(bus_spi, GPIO_NUM_14); + id = _read_panel_id(bus_spi, GPIO_NUM_15); if ((id & 0xFFFFFF) == 0x079100) { // check panel (GC9107) - board = board_t::board_M5AtomS3R; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] board_M5AtomS3R"); + board = board_t::board_M5AtomS3; + ESP_LOGW(LIBRARY_NAME, "[Autodetect] board_M5AtomS3"); bus_spi->release(); bus_cfg.spi_host = SPI3_HOST; bus_cfg.freq_write = 40000000; @@ -1324,17 +1325,16 @@ namespace m5gfx p->bus(bus_spi); { auto cfg = p->config(); - cfg.pin_cs = GPIO_NUM_14; - cfg.pin_rst = GPIO_NUM_48; + cfg.pin_cs = GPIO_NUM_15; + cfg.pin_rst = GPIO_NUM_34; cfg.panel_width = 128; cfg.panel_height = 128; cfg.offset_y = 32; cfg.readable = false; - cfg.bus_shared = false; p->config(cfg); } _panel_last.reset(p); - _set_backlight(new Light_M5StackAtomS3R()); + _set_pwm_backlight(GPIO_NUM_16, 7, 256, false, 48); goto init_clear; } From f882faf3da3e0f09811e6f7c22cceac9a4855c86 Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Sat, 21 Sep 2024 07:29:28 +0900 Subject: [PATCH 12/12] rising version 0.1.17 --- library.json | 2 +- library.properties | 2 +- src/lgfx/v1/gitTagVersion.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library.json b/library.json index 48bc732..2c7b534 100644 --- a/library.json +++ b/library.json @@ -10,7 +10,7 @@ "type": "git", "url": "https://github.com/m5stack/M5GFX.git" }, - "version": "0.1.16", + "version": "0.1.17", "frameworks": ["arduino", "espidf", "*"], "platforms": ["espressif32", "native"], "headers": "M5GFX.h" diff --git a/library.properties b/library.properties index f5bcabd..117efd2 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=M5GFX -version=0.1.16 +version=0.1.17 author=M5Stack maintainer=M5Stack sentence=Library for M5Stack All Display diff --git a/src/lgfx/v1/gitTagVersion.h b/src/lgfx/v1/gitTagVersion.h index 1bfee16..277f024 100644 --- a/src/lgfx/v1/gitTagVersion.h +++ b/src/lgfx/v1/gitTagVersion.h @@ -1,4 +1,4 @@ #define LGFX_VERSION_MAJOR 1 #define LGFX_VERSION_MINOR 1 -#define LGFX_VERSION_PATCH 16 +#define LGFX_VERSION_PATCH 17 #define LOVYANGFX_VERSION F( LGFX_VERSION_MAJOR "." LGFX_VERSION_MINOR "." LGFX_VERSION_PATCH )