diff --git a/README.md b/README.md index d9f324c..753ead3 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,10 @@ Supported device - M5Tough - M5Station - M5ATOMS3 +- M5Dial +- M5DinMeter +- M5Capsule +- M5Cardputer - UnitOLED - UnitMiniOLED - UnitLCD diff --git a/examples/Basic/AnalogMeter/AnalogMeter.ino b/examples/Basic/AnalogMeter/AnalogMeter.ino index 56e3dc4..f678610 100644 --- a/examples/Basic/AnalogMeter/AnalogMeter.ino +++ b/examples/Basic/AnalogMeter/AnalogMeter.ino @@ -12,6 +12,10 @@ M5GFX display; //M5UnitLCD display; // default setting //M5UnitLCD display ( 21, 22, 400000 ); // SDA, SCL, FREQ +//#include +//M5UnitGLASS2 display; // default setting +//M5UnitGLASS2 display ( 21, 22, 400000 ); // SDA, SCL, FREQ + //#include //M5AtomDisplay display; // default setting //M5AtomDisplay display ( 320, 180 ); // width, height diff --git a/examples/Basic/BarGraph/BarGraph.ino b/examples/Basic/BarGraph/BarGraph.ino index 8fcf923..32a91ac 100644 --- a/examples/Basic/BarGraph/BarGraph.ino +++ b/examples/Basic/BarGraph/BarGraph.ino @@ -10,6 +10,10 @@ M5GFX display; //M5UnitLCD display; // default setting //M5UnitLCD display ( 21, 22, 400000 ); // SDA, SCL, FREQ +//#include +//M5UnitGLASS2 display; // default setting +//M5UnitGLASS2 display ( 21, 22, 400000 ); // SDA, SCL, FREQ + // #include // M5AtomDisplay display; diff --git a/examples/Basic/GameOfLife/GameOfLife.ino b/examples/Basic/GameOfLife/GameOfLife.ino index f39ddd8..7107a15 100644 --- a/examples/Basic/GameOfLife/GameOfLife.ino +++ b/examples/Basic/GameOfLife/GameOfLife.ino @@ -15,6 +15,10 @@ M5GFX display; //M5UnitLCD display; // default setting //M5UnitLCD display ( 21, 22, 400000 ); // SDA, SCL, FREQ +//#include +//M5UnitGLASS2 display; // default setting +//M5UnitGLASS2 display ( 21, 22, 400000 ); // SDA, SCL, FREQ + //#include //M5AtomDisplay display; diff --git a/examples/Basic/LongTextScroll/LongTextScroll.ino b/examples/Basic/LongTextScroll/LongTextScroll.ino index 5c8f2ba..e904c99 100644 --- a/examples/Basic/LongTextScroll/LongTextScroll.ino +++ b/examples/Basic/LongTextScroll/LongTextScroll.ino @@ -10,6 +10,10 @@ M5GFX display; //M5UnitLCD display; // default setting //M5UnitLCD display ( 21, 22, 400000 ); // SDA, SCL, FREQ +//#include +//M5UnitGLASS2 display; // default setting +//M5UnitGLASS2 display ( 21, 22, 400000 ); // SDA, SCL, FREQ + //#include //M5AtomDisplay display; diff --git a/examples/Basic/ScrollGraph/ScrollGraph.ino b/examples/Basic/ScrollGraph/ScrollGraph.ino index cc7bbfd..91f4ea3 100644 --- a/examples/Basic/ScrollGraph/ScrollGraph.ino +++ b/examples/Basic/ScrollGraph/ScrollGraph.ino @@ -13,6 +13,10 @@ M5GFX display; //M5UnitLCD display; // default setting //M5UnitLCD display ( 21, 22, 400000 ); // SDA, SCL, FREQ +//#include +//M5UnitGLASS2 display; // default setting +//M5UnitGLASS2 display ( 21, 22, 400000 ); // SDA, SCL, FREQ + //#include //M5AtomDisplay display; diff --git a/examples/Basic/SpinTile/SpinTile.ino b/examples/Basic/SpinTile/SpinTile.ino index f7a7d2f..3a902c1 100644 --- a/examples/Basic/SpinTile/SpinTile.ino +++ b/examples/Basic/SpinTile/SpinTile.ino @@ -10,6 +10,10 @@ M5GFX display; //M5UnitLCD display; // default setting //M5UnitLCD display ( 21, 22, 400000 ); // SDA, SCL, FREQ +//#include +//M5UnitGLASS2 display; // default setting +//M5UnitGLASS2 display ( 21, 22, 400000 ); // SDA, SCL, FREQ + //#include //M5AtomDisplay display; // default setting //M5AtomDisplay display ( 320, 180 ); // width, height diff --git a/examples/Basic/TextLogScroll/TextLogScroll.ino b/examples/Basic/TextLogScroll/TextLogScroll.ino index 1c64f35..49dc4c0 100644 --- a/examples/Basic/TextLogScroll/TextLogScroll.ino +++ b/examples/Basic/TextLogScroll/TextLogScroll.ino @@ -10,6 +10,10 @@ M5GFX display; //M5UnitLCD display; // default setting //M5UnitLCD display ( 21, 22, 400000 ); // SDA, SCL, FREQ +//#include +//M5UnitGLASS2 display; // default setting +//M5UnitGLASS2 display ( 21, 22, 400000 ); // SDA, SCL, FREQ + //#include //M5AtomDisplay display; // default setting //M5AtomDisplay display ( 320, 180 ); // width, height diff --git a/examples/Basic/drawImageData/drawImageData.ino b/examples/Basic/drawImageData/drawImageData.ino index 4d4b8cf..482fe25 100644 --- a/examples/Basic/drawImageData/drawImageData.ino +++ b/examples/Basic/drawImageData/drawImageData.ino @@ -18,6 +18,10 @@ M5GFX display; //M5UnitLCD display; // default setting //M5UnitLCD display ( 21, 22, 400000 ); // SDA, SCL, FREQ +//#include +//M5UnitGLASS2 display; // default setting +//M5UnitGLASS2 display ( 21, 22, 400000 ); // SDA, SCL, FREQ + //#include //M5AtomDisplay display; diff --git a/library.json b/library.json index f0432d1..d5617e9 100644 --- a/library.json +++ b/library.json @@ -10,7 +10,7 @@ "type": "git", "url": "https://github.com/m5stack/M5GFX.git" }, - "version": "0.1.9", + "version": "0.1.10", "frameworks": ["arduino", "espidf", "*"], "platforms": ["espressif32", "native"], "headers": "M5GFX.h" diff --git a/library.properties b/library.properties index af9268d..5752035 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=M5GFX -version=0.1.9 +version=0.1.10 author=M5Stack maintainer=M5Stack sentence=Library for M5Stack All Display diff --git a/src/M5AtomDisplay.h b/src/M5AtomDisplay.h index 84e9d61..a3d21d8 100644 --- a/src/M5AtomDisplay.h +++ b/src/M5AtomDisplay.h @@ -100,6 +100,8 @@ class M5AtomDisplay : public M5GFX return true; } +#if !defined (CONFIG_IDF_TARGET_ESP32C3) + #if defined (SDL_h_) auto p = new lgfx::Panel_sdl(); if (!p) { @@ -230,6 +232,8 @@ class M5AtomDisplay : public M5GFX #endif setPanel(p); _panel_last.reset(p); +#endif + if (lgfx::LGFX_Device::init_impl(use_reset, use_clear)) { return true; diff --git a/src/M5GFX.cpp b/src/M5GFX.cpp index 4e37ed4..5022212 100644 --- a/src/M5GFX.cpp +++ b/src/M5GFX.cpp @@ -1316,6 +1316,7 @@ namespace m5gfx cfg.panel_height = 240; cfg.offset_x = 52; cfg.offset_y = 40; + cfg.offset_rotation = 2; cfg.readable = true; cfg.invert = true; p->config(cfg); @@ -1329,6 +1330,52 @@ namespace m5gfx bus_spi->release(); } + if (board == 0 || board == board_t::board_M5Cardputer) + { + bus_cfg.pin_mosi = GPIO_NUM_35; + bus_cfg.pin_miso = GPIO_NUM_NC; + bus_cfg.pin_sclk = GPIO_NUM_36; + bus_cfg.pin_dc = GPIO_NUM_34; + bus_cfg.spi_mode = 0; + bus_cfg.spi_3wire = true; + bus_spi->config(bus_cfg); + bus_spi->init(); + _pin_reset(GPIO_NUM_33, use_reset); // LCD RST + id = _read_panel_id(bus_spi, GPIO_NUM_37); + if ((id & 0xFF) == 0x81) + { // check panel (ST7789V2) + board = board_t::board_M5Cardputer; + ESP_LOGW(LIBRARY_NAME, "[Autodetect] board_M5Cardputer"); + 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_ST7789(); + p->bus(bus_spi); + { + auto cfg = p->config(); + cfg.pin_cs = GPIO_NUM_37; + cfg.pin_rst = GPIO_NUM_33; + cfg.panel_width = 135; + cfg.panel_height = 240; + cfg.offset_x = 52; + cfg.offset_y = 40; + cfg.offset_rotation = 0; + cfg.readable = true; + cfg.invert = true; + p->config(cfg); + } + _panel_last.reset(p); + _set_pwm_backlight(GPIO_NUM_38, 7, 256, false, 16); + + goto init_clear; + } + lgfx::pinMode(GPIO_NUM_33, lgfx::pin_mode_t::input); // LCD RST + bus_spi->release(); + } + #endif board = board_t::board_unknown; diff --git a/src/M5GFX.h b/src/M5GFX.h index 4f8f377..4c395a0 100644 --- a/src/M5GFX.h +++ b/src/M5GFX.h @@ -1,7 +1,8 @@ // Copyright (c) M5Stack. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#pragma once +#ifndef __M5GFX_H__ +#define __M5GFX_H__ // If you want to use a set of functions to handle SD/SPIFFS/HTTP, // please include ,, before @@ -255,3 +256,9 @@ using namespace m5gfx::tft_command; using M5GFX = m5gfx::M5GFX; using M5Canvas = m5gfx::M5Canvas; using RGBColor = m5gfx::bgr888_t; + +#endif + +#ifdef USE_M5_FONT_CREATOR +using EncodeRange = lgfx::EncodeRange; +#endif diff --git a/src/M5ModuleDisplay.h b/src/M5ModuleDisplay.h index 0c2398e..3de1084 100644 --- a/src/M5ModuleDisplay.h +++ b/src/M5ModuleDisplay.h @@ -100,6 +100,8 @@ class M5ModuleDisplay : public M5GFX return true; } +#if !defined (CONFIG_IDF_TARGET_ESP32C3) + #if defined (SDL_h_) auto p = new lgfx::Panel_sdl(); if (!p) { @@ -227,6 +229,8 @@ class M5ModuleDisplay : public M5GFX #endif setPanel(p); _panel_last.reset(p); +#endif + if (lgfx::LGFX_Device::init_impl(use_reset, use_clear)) { return true; diff --git a/src/M5UnitGLASS.h b/src/M5UnitGLASS.h index cd9e5c5..2e1fe5f 100644 --- a/src/M5UnitGLASS.h +++ b/src/M5UnitGLASS.h @@ -68,9 +68,13 @@ class M5UnitGLASS : public M5GFX #if defined (SDL_h_) M5UnitGLASS(const config_t &cfg) - { } + { + setup(cfg.pin_sda, cfg.pin_scl, cfg.i2c_freq, cfg.i2c_port, cfg.i2c_addr); + } M5UnitGLASS(uint8_t pin_sda = M5UNITGLASS_SDA, uint8_t pin_scl = M5UNITGLASS_SCL, uint32_t i2c_freq = M5UNITGLASS_FREQ, int8_t i2c_port = -1, uint8_t i2c_addr = M5UNITGLASS_ADDR) - { } + { + setup(pin_sda, pin_scl, i2c_freq, i2c_port, i2c_addr); + } using lgfx::LGFX_Device::init; bool init(uint8_t pin_sda, uint8_t pin_scl, uint32_t i2c_freq = M5UNITGLASS_FREQ, int8_t i2c_port = -1, uint8_t i2c_addr = M5UNITGLASS_ADDR) @@ -79,7 +83,9 @@ class M5UnitGLASS : public M5GFX } void setup(uint8_t pin_sda = M5UNITGLASS_SDA, uint8_t pin_scl = M5UNITGLASS_SCL, uint32_t i2c_freq = M5UNITGLASS_FREQ, int8_t i2c_port = -1, uint8_t i2c_addr = M5UNITGLASS_ADDR) - { } + { + _board = lgfx::board_t::board_M5UnitGLASS; + } bool init_impl(bool use_reset, bool use_clear) { diff --git a/src/M5UnitGLASS2.h b/src/M5UnitGLASS2.h index e0a9955..12af1a7 100644 --- a/src/M5UnitGLASS2.h +++ b/src/M5UnitGLASS2.h @@ -68,9 +68,13 @@ class M5UnitGLASS2 : public M5GFX #if defined (SDL_h_) M5UnitGLASS2(const config_t &cfg) - { } + { + setup(cfg.pin_sda, cfg.pin_scl, cfg.i2c_freq, cfg.i2c_port, cfg.i2c_addr); + } M5UnitGLASS2(uint8_t pin_sda = M5UNITGLASS2_SDA, uint8_t pin_scl = M5UNITGLASS2_SCL, uint32_t i2c_freq = M5UNITGLASS2_FREQ, int8_t i2c_port = -1, uint8_t i2c_addr = M5UNITGLASS2_ADDR) - { } + { + setup(pin_sda, pin_scl, i2c_freq, i2c_port, i2c_addr); + } using lgfx::LGFX_Device::init; bool init(uint8_t pin_sda, uint8_t pin_scl, uint32_t i2c_freq = M5UNITGLASS2_FREQ, int8_t i2c_port = -1, uint8_t i2c_addr = M5UNITGLASS2_ADDR) @@ -79,7 +83,9 @@ class M5UnitGLASS2 : public M5GFX } void setup(uint8_t pin_sda = M5UNITGLASS2_SDA, uint8_t pin_scl = M5UNITGLASS2_SCL, uint32_t i2c_freq = M5UNITGLASS2_FREQ, int8_t i2c_port = -1, uint8_t i2c_addr = M5UNITGLASS2_ADDR) - { } + { + _board = lgfx::board_t::board_M5UnitGLASS2; + } bool init_impl(bool use_reset, bool use_clear) { diff --git a/src/M5UnitLCD.h b/src/M5UnitLCD.h index f01fe5d..5eae630 100644 --- a/src/M5UnitLCD.h +++ b/src/M5UnitLCD.h @@ -68,9 +68,13 @@ class M5UnitLCD : public M5GFX #if defined (SDL_h_) M5UnitLCD(const config_t &cfg) - { } + { + setup(cfg.pin_sda, cfg.pin_scl, cfg.i2c_freq, cfg.i2c_port, cfg.i2c_addr); + } M5UnitLCD(uint8_t pin_sda = M5UNITLCD_SDA, uint8_t pin_scl = M5UNITLCD_SCL, uint32_t i2c_freq = M5UNITLCD_FREQ, int8_t i2c_port = -1, uint8_t i2c_addr = M5UNITLCD_ADDR) - { } + { + setup(pin_sda, pin_scl, i2c_freq, i2c_port, i2c_addr); + } using lgfx::LGFX_Device::init; bool init(uint8_t pin_sda, uint8_t pin_scl, uint32_t i2c_freq = M5UNITLCD_FREQ, int8_t i2c_port = -1, uint8_t i2c_addr = M5UNITLCD_ADDR) @@ -79,7 +83,9 @@ class M5UnitLCD : public M5GFX } void setup(uint8_t pin_sda = M5UNITLCD_SDA, uint8_t pin_scl = M5UNITLCD_SCL, uint32_t i2c_freq = M5UNITLCD_FREQ, int8_t i2c_port = -1, uint8_t i2c_addr = M5UNITLCD_ADDR) - { } + { + _board = lgfx::board_t::board_M5UnitLCD; + } bool init_impl(bool use_reset, bool use_clear) { diff --git a/src/M5UnitMiniOLED.h b/src/M5UnitMiniOLED.h index 6c305ff..bf5cd18 100644 --- a/src/M5UnitMiniOLED.h +++ b/src/M5UnitMiniOLED.h @@ -68,9 +68,13 @@ class M5UnitMiniOLED : public M5GFX #if defined (SDL_h_) M5UnitMiniOLED(const config_t &cfg) - { } + { + setup(cfg.pin_sda, cfg.pin_scl, cfg.i2c_freq, cfg.i2c_port, cfg.i2c_addr); + } M5UnitMiniOLED(uint8_t pin_sda = M5UNITMINIOLED_SDA, uint8_t pin_scl = M5UNITMINIOLED_SCL, uint32_t i2c_freq = M5UNITMINIOLED_FREQ, int8_t i2c_port = -1, uint8_t i2c_addr = M5UNITMINIOLED_ADDR) - { } + { + setup(pin_sda, pin_scl, i2c_freq, i2c_port, i2c_addr); + } using lgfx::LGFX_Device::init; bool init(uint8_t pin_sda, uint8_t pin_scl, uint32_t i2c_freq = M5UNITMINIOLED_FREQ, int8_t i2c_port = -1, uint8_t i2c_addr = M5UNITMINIOLED_ADDR) @@ -79,7 +83,9 @@ class M5UnitMiniOLED : public M5GFX } void setup(uint8_t pin_sda = M5UNITMINIOLED_SDA, uint8_t pin_scl = M5UNITMINIOLED_SCL, uint32_t i2c_freq = M5UNITMINIOLED_FREQ, int8_t i2c_port = -1, uint8_t i2c_addr = M5UNITMINIOLED_ADDR) - { } + { + _board = lgfx::board_t::board_M5UnitMiniOLED; + } bool init_impl(bool use_reset, bool use_clear) { diff --git a/src/M5UnitOLED.h b/src/M5UnitOLED.h index f531f2e..5307a55 100644 --- a/src/M5UnitOLED.h +++ b/src/M5UnitOLED.h @@ -68,9 +68,13 @@ class M5UnitOLED : public M5GFX #if defined (SDL_h_) M5UnitOLED(const config_t &cfg) - { } + { + setup(cfg.pin_sda, cfg.pin_scl, cfg.i2c_freq, cfg.i2c_port, cfg.i2c_addr); + } M5UnitOLED(uint8_t pin_sda = M5UNITOLED_SDA, uint8_t pin_scl = M5UNITOLED_SCL, uint32_t i2c_freq = M5UNITOLED_FREQ, int8_t i2c_port = -1, uint8_t i2c_addr = M5UNITOLED_ADDR) - { } + { + setup(pin_sda, pin_scl, i2c_freq, i2c_port, i2c_addr); + } using lgfx::LGFX_Device::init; bool init(uint8_t pin_sda, uint8_t pin_scl, uint32_t i2c_freq = M5UNITOLED_FREQ, int8_t i2c_port = -1, uint8_t i2c_addr = M5UNITOLED_ADDR) @@ -79,7 +83,9 @@ class M5UnitOLED : public M5GFX } void setup(uint8_t pin_sda = M5UNITOLED_SDA, uint8_t pin_scl = M5UNITOLED_SCL, uint32_t i2c_freq = M5UNITOLED_FREQ, int8_t i2c_port = -1, uint8_t i2c_addr = M5UNITOLED_ADDR) - { } + { + _board = lgfx::board_t::board_M5UnitOLED; + } bool init_impl(bool use_reset, bool use_clear) { diff --git a/src/lgfx/boards.hpp b/src/lgfx/boards.hpp index ca6dc39..bdcf2db 100644 --- a/src/lgfx/boards.hpp +++ b/src/lgfx/boards.hpp @@ -35,6 +35,7 @@ namespace lgfx // This should not be changed to "m5gfx" , board_M5AtomS3Lite , board_M5AtomS3U , board_M5Capsule + , board_M5Cardputer /// external displays , board_M5AtomDisplay = 192 diff --git a/src/lgfx/v1/gitTagVersion.h b/src/lgfx/v1/gitTagVersion.h index 25adeac..39764c8 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 9 +#define LGFX_VERSION_PATCH 10 #define LOVYANGFX_VERSION F( LGFX_VERSION_MAJOR "." LGFX_VERSION_MINOR "." LGFX_VERSION_PATCH ) diff --git a/src/lgfx/v1/panel/Panel_GC9A01.hpp b/src/lgfx/v1/panel/Panel_GC9A01.hpp index 3f50bf7..bc21aa5 100644 --- a/src/lgfx/v1/panel/Panel_GC9A01.hpp +++ b/src/lgfx/v1/panel/Panel_GC9A01.hpp @@ -139,9 +139,8 @@ namespace lgfx 0x74, 7, 0x10, 0x68, 0x80, 0x00, 0x00, 0x4E, 0x00, 0x98, 2, 0x3e, 0x07, 0x35, 1, 0x00, // Tearing Effect Line ON - 0x21, 0, 0x11, 0+CMD_INIT_DELAY, 120, - 0x29, 0+CMD_INIT_DELAY, 20, + 0x29, 0, 0xFF,0xFF, // end }; switch (listno) { @@ -187,9 +186,8 @@ namespace lgfx 0xC7, 1, 0x18, 0xF0, 14, 0x1F,0x28,0x04,0x3E,0x2A,0x2E,0x20,0x00,0x0C,0x06,0x00,0x1C,0x1F,0x0f, 0xF1, 14, 0X00,0X2D,0X2F,0X3C,0X6F,0X1C,0X0B,0X00,0X00,0X00,0X07,0X0D,0X11,0X0f, - 0x21, 0+CMD_INIT_DELAY, 120, 0x11, 0+CMD_INIT_DELAY, 120, - 0x29, 0+CMD_INIT_DELAY, 120, + 0x29, 0, 0xFF,0xFF, // end }; switch (listno) { diff --git a/src/lgfx/v1/panel/Panel_M5HDMI.cpp b/src/lgfx/v1/panel/Panel_M5HDMI.cpp index f82360b..e23beda 100644 --- a/src/lgfx/v1/panel/Panel_M5HDMI.cpp +++ b/src/lgfx/v1/panel/Panel_M5HDMI.cpp @@ -469,6 +469,7 @@ namespace lgfx bool Panel_M5HDMI::init(bool use_reset) { ESP_LOGI(TAG, "i2c port:%d sda:%d scl:%d", _HDMI_Trans_config.i2c_port, _HDMI_Trans_config.pin_sda, _HDMI_Trans_config.pin_scl); + lgfx::i2c::init(_HDMI_Trans_config.i2c_port, _HDMI_Trans_config.pin_sda, _HDMI_Trans_config.pin_scl); HDMI_Trans driver(_HDMI_Trans_config); @@ -875,6 +876,7 @@ namespace lgfx { if ((_last_cmd & ~7) == CMD_WRITE_RAW) { + _bus->wait(); cs_control(true); _total_send = 0; _last_cmd = 0; @@ -900,7 +902,6 @@ namespace lgfx { if ((_last_cmd & ~7) == CMD_WRITE_RAW) { - _last_cmd = 0; _total_send = 0; _bus->beginRead(); diff --git a/src/lgfx/v1/panel/Panel_SSD1306.cpp b/src/lgfx/v1/panel/Panel_SSD1306.cpp index 4b11012..4a490e8 100644 --- a/src/lgfx/v1/panel/Panel_SSD1306.cpp +++ b/src/lgfx/v1/panel/Panel_SSD1306.cpp @@ -136,11 +136,11 @@ namespace lgfx { x = xs; uint32_t idx = x + (y >> 3) * _cfg.panel_width; - auto btbl = &Bayer[_bayer_offset + ((y & 3) << 2)]; + auto btbl = &Bayer[((y + (_bayer_offset >> 2)) & 3) << 2]; uint32_t mask = 1 << (y&7); do { - bool flg = 256 <= value + btbl[x & 3]; + bool flg = 256 <= value + btbl[(x + _bayer_offset) & 3]; if (flg) _buf[idx] |= mask; else _buf[idx] &= ~ mask; ++idx; @@ -240,7 +240,7 @@ namespace lgfx _rotate_pos(x, y); uint32_t idx = x + (y >> 3) * _cfg.panel_width; uint32_t mask = 1 << (y&7); - bool flg = 256 <= value + Bayer[_bayer_offset + ((x & 3) | (y & 3) << 2)]; + bool flg = 256 <= value + Bayer[ + (((x + _bayer_offset) & 3) | ((y + (_bayer_offset >> 2)) & 3) << 2)]; if (flg) _buf[idx] |= mask; else _buf[idx] &= ~mask; } diff --git a/src/lgfx/v1/platforms/esp32/common.cpp b/src/lgfx/v1/platforms/esp32/common.cpp index c0b513c..3e71dcf 100644 --- a/src/lgfx/v1/platforms/esp32/common.cpp +++ b/src/lgfx/v1/platforms/esp32/common.cpp @@ -29,6 +29,9 @@ Original Source: #include #include +#include +#include + #include #include #include @@ -712,6 +715,19 @@ namespace lgfx }; cpp::result state; + SemaphoreHandle_t mtx = nullptr; + + void lock(uint32_t msec = portMAX_DELAY) { + if (mtx == nullptr) { + mtx = xSemaphoreCreateMutex(); + } + xSemaphoreTake(mtx, msec); + } + + void unlock(void) { + xSemaphoreGive(mtx); + } + gpio_num_t pin_scl = (gpio_num_t)-1; gpio_num_t pin_sda = (gpio_num_t)-1; uint8_t wait_ack_stage = 0; // 0:Not waiting. / 1:Waiting after addressing. / 2:Waiting during data transmission. @@ -806,7 +822,8 @@ namespace lgfx cmd_val |= (1 << 10); // ACK_VALUE (set NACK) } #if defined (CONFIG_IDF_TARGET_ESP32S3) - #if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 2) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0)) + #if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 3) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0)) \ + || (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 1) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)) (&dev->comd[0])[index].val = cmd_val; #else (&dev->comd0)[index].val = cmd_val; @@ -953,6 +970,7 @@ namespace lgfx { i2c_context[i2c_port].state = i2c_context_t::state_t::state_disconnect; } + i2c_context[i2c_port].unlock(); } return res; } @@ -1210,6 +1228,7 @@ namespace lgfx //ESP_LOGI("LGFX", "i2c::beginTransaction : port:%d / addr:%02x / freq:%d / rw:%d", i2c_port, i2c_addr, freq, read); auto dev = getDev(i2c_port); + i2c_context[i2c_port].lock(); #if defined ( CONFIG_IDF_TARGET_ESP32C3 ) || defined ( CONFIG_IDF_TARGET_ESP32S3 ) if (dev->sr.bus_busy) diff --git a/src/lgfx/v1/touch/Touch_CST816S.cpp b/src/lgfx/v1/touch/Touch_CST816S.cpp index 7d19243..8cc6caa 100644 --- a/src/lgfx/v1/touch/Touch_CST816S.cpp +++ b/src/lgfx/v1/touch/Touch_CST816S.cpp @@ -17,8 +17,7 @@ Original Source: /----------------------------------------------------------------------------*/ // CST816 info from here... -// https://github.com/lupyuen/hynitron_i2c_cst0xxse/blob/master/cst0xx_common.h -// https://blog.csdn.net/Distance_98/article/details/126408819 +// https://www.waveshare.com/w/upload/c/c2/CST816S_register_declaration.pdf #include "Touch_CST816S.hpp" @@ -58,7 +57,14 @@ namespace lgfx uint8_t tmp[3] = { 0 }; _inited = _write_reg(0x00, 0x00) && _read_reg(CST816S_CHIPID_REG, tmp, 3); - // _write_reg(0xFA, 0b00000101); // レジスタ0xFAはINTピンの動作設定に関与すると思われる。 + +// CST816SのINT機能には問題があり、LOWパルス出力期間中のタッチ精度が顕著に劣化する。 +// 0xFAレジスタを0x40とすると接触中に定期的にINTパルスを発生できる。 +// また、0xEDを操作するとパルスの長さを変更できるが、これらを併用するとタッチ性能が顕著に劣化する。 +// _write_reg(0xFA, 0x40); // 0x40 = 触れている間、連続的にINTパルスを発生する。 + + _write_reg(0xFA, 0x20); // 0x20 = 変化を検出したときINTパルスを発生する。 + _write_reg(0xED, 20); // INT LOW パルス長さ 20 == 2 msec // ESP_LOGV("LGFX","CST816S id:%02x %02x %02x", tmp[0], tmp[1], tmp[2]); return _inited; } @@ -78,14 +84,14 @@ namespace lgfx } if (_cfg.pin_int >= 0) - { // intピンのプルアップ処理を行うが、「触れている間 LOW」の設定方法が不明のため、このピンを使用していない。 + { // intピンのプルアップ処理を行うが、「触れている間 LOW」の設定方法がないため使用していない。 // GPIO割込みを使用すれば良いが、Arduinoに依存せず解決する必要があるため、対応を保留する。 lgfx::pinMode(_cfg.pin_int, pin_mode_t::input_pullup); } lgfx::i2c::init(_cfg.i2c_port, _cfg.pin_sda, _cfg.pin_scl).has_value(); // 画面に触れていない時、I2C通信でCST816が見つからない事がある。 - // CST816S の正確な仕様を確認することができていないが恐らく省電力モード中は通信応答しないものと思われる。 + // CST816S は恐らく省電力モード中はI2Cでの通信に応答しないものと思われる。 // 通信の成否による初期化の成否の判定ができないため、ひとまず true を返す。 return true; } @@ -122,19 +128,39 @@ namespace lgfx { if (!_inited && !_check_init()) return 0; - if (count > max_touch_points) { count = max_touch_points; } + // if (count > max_touch_points) { count = max_touch_points; } + + uint32_t msec = lgfx::millis(); + uint32_t diff_msec = msec - _last_update; + + if (diff_msec < 10 && _wait_cycle) + { + --_wait_cycle; + if (_cfg.pin_int < 0 || gpio_in(_cfg.pin_int)) { + return 0; + } + } + _last_update = msec; - uint8_t readdata[8]; + uint8_t readdata[6]; int retry = 3; do { + // I2Cでの応答が得られない場合は触れていないものとして扱う。 if (!_read_reg(0x02, readdata, 6)) { - return 0; + count = 0; + break; } count = readdata[0]; } while ((count > 1 || readdata[5] != 0x10) && --retry); - if (retry && count) + if (!retry) + { + count = 0; + } + _wait_cycle = count ? 0 : 16; + + if (count) { // ESP_LOGV("CST816S", "%02x %02x %02x %02x %02x %02x %02x %02x %d %d", // readdata[0], readdata[1], readdata[2], readdata[3], diff --git a/src/lgfx/v1/touch/Touch_CST816S.hpp b/src/lgfx/v1/touch/Touch_CST816S.hpp index 4293bcd..df54c5e 100644 --- a/src/lgfx/v1/touch/Touch_CST816S.hpp +++ b/src/lgfx/v1/touch/Touch_CST816S.hpp @@ -59,6 +59,8 @@ namespace lgfx { max_touch_points = 1 }; + uint32_t _last_update = 0; + uint8_t _wait_cycle = 0; bool _check_init(void); bool _write_reg(uint8_t reg, uint8_t val);