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/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/M5GFX.cpp b/src/M5GFX.cpp index 7ec726b..e45b26d 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; @@ -424,6 +425,26 @@ namespace m5gfx } }; + struct Light_M5StackAtomS3R : public lgfx::ILight + { + 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); + 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); + + setBrightness(brightness); + return true; + } + + void setBrightness(uint8_t brightness) override + { + lgfx::i2c::writeRegister8(i2c_port, 48, 0x0e, brightness, 0, i2c_freq); + } + }; + #endif __attribute__ ((unused)) @@ -1183,7 +1204,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 +1221,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; @@ -1250,11 +1255,55 @@ namespace m5gfx lgfx::i2c::release(i2c_port); } + 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_M5AtomS3) { _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; @@ -1586,6 +1635,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; @@ -1597,6 +1647,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 4f701f3..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 @@ -52,6 +53,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/LGFXBase.cpp b/src/lgfx/v1/LGFXBase.cpp index 2b3a7d7..ac61661 100644 --- a/src/lgfx/v1/LGFXBase.cpp +++ b/src/lgfx/v1/LGFXBase.cpp @@ -1125,7 +1125,7 @@ namespace lgfx for( int ys=0;ys> (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; @@ -1510,15 +1531,15 @@ namespace lgfx else if (pc_post.dst_bits > 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..a20369e 100644 --- a/src/lgfx/v1/LGFXBase.hpp +++ b/src/lgfx/v1/LGFXBase.hpp @@ -564,6 +564,35 @@ 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 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; + } 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; + } + } + 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/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/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 ) 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/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) { 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/esp32/Bus_SPI.cpp b/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp index 4d3368c..15c5070 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 ) @@ -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 = (spi_mode & 2) ? SPI_CK_IDLE_EDGE : 0; + pin = pin +#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 (_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 1a46efa..b6511a0 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 @@ -577,8 +580,27 @@ 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; - if (spi_mode & 2) pin = SPI_CK_IDLE_EDGE; + uint32_t pin = (spi_mode & 2) ? SPI_CK_IDLE_EDGE : 0; + pin = pin +#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 + ; beginTransaction(spi_host); @@ -608,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); } @@ -669,7 +685,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; @@ -775,6 +791,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 +879,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 +892,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); @@ -923,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(); @@ -963,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(); @@ -1005,6 +1019,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 +1091,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; @@ -1390,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)) { @@ -1413,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); 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)