From f7242e99f0d1315cb5707627696443f3fc0715f7 Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Sat, 2 Oct 2021 17:48:39 +0900 Subject: [PATCH 1/3] raising version 0.0.8 --- library.json | 2 +- library.properties | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library.json b/library.json index 65ddc75..c9e0ffd 100644 --- a/library.json +++ b/library.json @@ -10,7 +10,7 @@ "type": "git", "url": "https://github.com/m5stack/M5GFX.git" }, - "version": "0.0.7", + "version": "0.0.8", "framework": "arduino", "platforms": "espressif32" } diff --git a/library.properties b/library.properties index 18e3575..c29a4e9 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ name=M5GFX -version=0.0.7 +version=0.0.8 author=M5Stack maintainer=M5Stack sentence=Library for M5Stack All Display -paragraph=M5Stack, M5Stack Core2, M5Stack CoreInk, M5StickC, M5StickC-Plus, M5Paper, Unit OLED, See more on http://M5Stack.com +paragraph=M5Stack, M5Stack Core2, M5Stack CoreInk, M5StickC, M5StickC-Plus, M5Paper, M5Tough, M5Station, Unit OLED, Unit LCD, See more on http://M5Stack.com category=Display url=https://github.com/m5stack/M5GFX.git architectures=esp32 From c38809240999e473b3b5f0488286ec5de5be15dd Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Sat, 2 Oct 2021 17:50:58 +0900 Subject: [PATCH 2/3] Add support M5Station, and tweak autodetect sequence. --- src/M5GFX.cpp | 353 +++++++++++++++++++++++++++++--------------------- src/M5GFX.h | 1 + 2 files changed, 203 insertions(+), 151 deletions(-) diff --git a/src/M5GFX.cpp b/src/M5GFX.cpp index 261443d..1c6be37 100644 --- a/src/M5GFX.cpp +++ b/src/M5GFX.cpp @@ -92,7 +92,7 @@ namespace m5gfx } }; - struct Light_M5StackTough : public lgfx::ILight + struct Light_M5Tough : public lgfx::ILight { bool init(std::uint8_t brightness) override { @@ -290,6 +290,9 @@ namespace m5gfx static std::uint32_t _read_panel_id(lgfx::Bus_SPI* bus, std::int32_t pin_cs, std::uint32_t cmd = 0x04, std::uint8_t dummy_read_bit = 1) // 0x04 = RDDID command { bus->beginTransaction(); + _pin_level(pin_cs, true); + bus->writeCommand(0, 8); + bus->wait(); _pin_level(pin_cs, false); bus->writeCommand(cmd, 8); if (dummy_read_bit) bus->writeData(0, dummy_read_bit); // dummy read bit @@ -423,9 +426,203 @@ namespace m5gfx std::uint32_t id; + /// AXP192の有無を最初に判定し、分岐する。 + if (board == 0 + || board == board_t::board_M5StickC + || board == board_t::board_M5StickCPlus + || board == board_t::board_M5Station + || board == board_t::board_M5StackCore2 + || board == board_t::board_M5Tough) + { + // I2C addr 0x34 = AXP192 + lgfx::i2c::init(axp_i2c_port, axp_i2c_sda, axp_i2c_scl); + if (lgfx::i2c::readRegister8(axp_i2c_port, axp_i2c_addr, 0x03, 400000) == 0x03) // AXP192 found + { + if (board == 0 || board == board_t::board_M5StickC || board == board_t::board_M5StickCPlus) + { + bus_cfg.pin_mosi = 15; + bus_cfg.pin_miso = 14; + bus_cfg.pin_sclk = 13; + bus_cfg.pin_dc = 23; + bus_cfg.spi_3wire = true; + _bus_spi.config(bus_cfg); + _bus_spi.init(); + _pin_reset(18, use_reset); // LCD RST + id = _read_panel_id(&_bus_spi, 5); + if ((id & 0xFF) == 0x85) + { // check panel (ST7789) + board = board_t::board_M5StickCPlus; + ESP_LOGW(LIBRARY_NAME, "[Autodetect] M5StickCPlus"); + bus_cfg.freq_write = 40000000; + bus_cfg.freq_read = 15000000; + _bus_spi.config(bus_cfg); + auto p = new Panel_M5StickCPlus(); + p->bus(&_bus_spi); + _panel_last = p; + _set_backlight(new Light_M5StickC()); + goto init_clear; + } + if ((id & 0xFF) == 0x7C) + { // check panel (ST7735) + board = board_t::board_M5StickC; + ESP_LOGW(LIBRARY_NAME, "[Autodetect] M5StickC"); + bus_cfg.freq_write = 27000000; + bus_cfg.freq_read = 14000000; + _bus_spi.config(bus_cfg); + auto p = new Panel_M5StickC(); + p->bus(&_bus_spi); + _panel_last = p; + _set_backlight(new Light_M5StickC()); + goto init_clear; + } + lgfx::pinMode(18, lgfx::pin_mode_t::input); // LCD RST + lgfx::pinMode( 5, lgfx::pin_mode_t::input); // LCD CS + _bus_spi.release(); + } + + if (board == 0 || board == board_t::board_M5Station) + { + bus_cfg.pin_mosi = 23; + bus_cfg.pin_miso = -1; + bus_cfg.pin_sclk = 18; + bus_cfg.pin_dc = 19; + bus_cfg.spi_3wire = true; + _bus_spi.config(bus_cfg); + _bus_spi.init(); + _pin_reset(15, use_reset); // LCD RST; + + id = _read_panel_id(&_bus_spi, 5); + if ((id & 0xFF) == 0x85) + { // ST7789 + ESP_LOGW(LIBRARY_NAME, "[Autodetect] M5Station"); + board = board_t::board_M5Station; + + bus_cfg.freq_write = 40000000; + bus_cfg.freq_read = 15000000; + _bus_spi.config(bus_cfg); + + auto p = new Panel_M5StickCPlus(); + { + auto cfg = p->config(); + cfg.pin_rst = 15; + p->config(cfg); + p->setRotation(1); + } + p->bus(&_bus_spi); + _panel_last = p; + /// M5StationのバックライトはM5Toughと同じ + _set_backlight(new Light_M5Tough()); + goto init_clear; + } + _bus_spi.release(); + lgfx::pinMode( 5, lgfx::pin_mode_t::input); // LCD CS + lgfx::pinMode(15, lgfx::pin_mode_t::input); // LCD RST + } + + if (board == 0 || board == board_t::board_M5StackCore2 || board == board_t::board_M5Tough) + { + if (lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x95, 0x84, 0x72, axp_i2c_freq)) // GPIO4 enable + { + // AXP192_LDO2 = LCD PWR + // AXP192_IO4 = LCD RST + // AXP192_DC3 = LCD BL (Core2) + // AXP192_LDO3 = LCD BL (Tough) + // AXP192_IO1 = TP RST (Tough) + lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x28, 0xF0, ~0, axp_i2c_freq); // set LDO2 3300mv // LCD PWR + lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x12, 0x04, ~0, axp_i2c_freq); // LDO2 enable + lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x95, 0x84, 0x72, axp_i2c_freq); // GPIO4 enable + if (use_reset) lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x96, 0, ~0x02, axp_i2c_freq); // GPIO4 LOW (LCD RST) + lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x96, 0x02, ~0, axp_i2c_freq); // GPIO4 HIGH (LCD RST) + + ets_delay_us(128); // AXP 起動後、LCDがアクセス可能になるまで少し待機 + + bus_cfg.pin_mosi = 23; + bus_cfg.pin_miso = 38; + bus_cfg.pin_sclk = 18; + bus_cfg.pin_dc = 15; + bus_cfg.spi_3wire = true; + _bus_spi.config(bus_cfg); + _bus_spi.init(); + + _pin_level( 4, true); // TF card CS + id = _read_panel_id(&_bus_spi, 5); + if ((id & 0xFF) == 0xE3) + { // ILI9342c + bus_cfg.freq_write = 40000000; + bus_cfg.freq_read = 16000000; + _bus_spi.config(bus_cfg); + + auto p = new Panel_M5StackCore2(); + p->bus(&_bus_spi); + _panel_last = p; + + // Check exists touch controller for Core2 + if (lgfx::i2c::readRegister8(axp_i2c_port, 0x38, 0, 400000).has_value()) + { + ESP_LOGW(LIBRARY_NAME, "[Autodetect] M5StackCore2"); + board = board_t::board_M5StackCore2; + + _set_backlight(new Light_M5StackCore2()); + + auto t = new lgfx::Touch_FT5x06(); + _touch_last = t; + auto cfg = t->config(); + cfg.pin_int = 39; // INT pin number + cfg.pin_sda = 21; // I2C SDA pin number + cfg.pin_scl = 22; // I2C SCL pin number + cfg.i2c_addr = 0x38; // I2C device addr + cfg.i2c_port = I2C_NUM_1;// I2C port number + cfg.freq = 400000; // I2C freq + cfg.x_min = 0; + cfg.x_max = 319; + cfg.y_min = 0; + cfg.y_max = 279; + t->config(cfg); + p->touch(t); + float affine[6] = { 1, 0, 0, 0, 1, 0 }; + p->setCalibrateAffine(affine); + } + else + { + // AXP192のGPIO1 = タッチコントローラRST + lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x92, 0, 0xF8, axp_i2c_freq); // GPIO1 OpenDrain + lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x94, 0, ~0x02, axp_i2c_freq); // GPIO1 LOW (TOUCH RST) + + ESP_LOGW(LIBRARY_NAME, "[Autodetect] M5Tough"); + board = board_t::board_M5Tough; + + _set_backlight(new Light_M5Tough()); + + auto t = new Touch_M5Tough(); + _touch_last = t; + auto cfg = t->config(); + cfg.pin_int = 39; // INT pin number + cfg.pin_sda = 21; // I2C SDA pin number + cfg.pin_scl = 22; // I2C SCL pin number + cfg.i2c_addr = 0x2E; // I2C device addr + cfg.i2c_port = I2C_NUM_1;// I2C port number + cfg.freq = 400000; // I2C freq + cfg.x_min = 0; + cfg.x_max = 319; + cfg.y_min = 0; + cfg.y_max = 239; + t->config(cfg); + p->touch(t); + lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x94, 0x02, ~0, axp_i2c_freq); // GPIO1 HIGH (TOUCH RST) + } + + goto init_clear; + } + lgfx::pinMode( 4, lgfx::pin_mode_t::input); // TF card CS + lgfx::pinMode( 5, lgfx::pin_mode_t::input); // LCD CS + _bus_spi.release(); + } + } + } + } + if (board == 0 || board == board_t::board_M5Stack) { - _pin_level(14, true); // LCD CS; bus_cfg.pin_mosi = 23; bus_cfg.pin_miso = 19; bus_cfg.pin_sclk = 18; @@ -455,58 +652,14 @@ namespace m5gfx goto init_clear; } _bus_spi.release(); - lgfx::pinMode(33, lgfx::pin_mode_t::input); // LCD RST + lgfx::pinMode( 4, lgfx::pin_mode_t::input); // M5Stack and LoLinD32 TF card CS lgfx::pinMode(14, lgfx::pin_mode_t::input); // LCD CS - lgfx::pinMode( 4, lgfx::pin_mode_t::input); // M5Stack TF card CS - } - - - if (board == 0 || board == board_t::board_M5StickC || board == board_t::board_M5StickCPlus) - { - bus_cfg.pin_mosi = 15; - bus_cfg.pin_miso = 14; - bus_cfg.pin_sclk = 13; - bus_cfg.pin_dc = 23; - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - _pin_reset(18, use_reset); // LCD RST - id = _read_panel_id(&_bus_spi, 5); - if ((id & 0xFF) == 0x85) - { // check panel (ST7789) - board = board_t::board_M5StickCPlus; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] M5StickCPlus"); - bus_cfg.freq_write = 40000000; - bus_cfg.freq_read = 15000000; - _bus_spi.config(bus_cfg); - auto p = new Panel_M5StickCPlus(); - p->bus(&_bus_spi); - _panel_last = p; - _set_backlight(new Light_M5StickC()); - goto init_clear; - } - if ((id & 0xFF) == 0x7C) - { // check panel (ST7735) - board = board_t::board_M5StickC; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] M5StickC"); - bus_cfg.freq_write = 27000000; - bus_cfg.freq_read = 14000000; - _bus_spi.config(bus_cfg); - auto p = new Panel_M5StickC(); - p->bus(&_bus_spi); - _panel_last = p; - _set_backlight(new Light_M5StickC()); - goto init_clear; - } - lgfx::pinMode(18, lgfx::pin_mode_t::input); // LCD RST - lgfx::pinMode( 5, lgfx::pin_mode_t::input); // LCD CS - _bus_spi.release(); + lgfx::pinMode(33, lgfx::pin_mode_t::input); // LCD RST } - if (board == 0 || board == board_t::board_M5StackCoreInk) { - _pin_reset( 0, true); // EPDがDeepSleepしていると自動認識に失敗するためRST制御は必須とする + _pin_reset( 0, true); // EPDがDeepSleepしていると自動認識に失敗するためRST制御は必須とする bus_cfg.pin_mosi = 23; bus_cfg.pin_miso = 34; bus_cfg.pin_sclk = 18; @@ -647,108 +800,6 @@ namespace m5gfx lgfx::pinMode(23, lgfx::pin_mode_t::input); // RST } - - if (board == 0 || board == board_t::board_M5StackCore2 || board == board_t::board_M5Tough) - { - lgfx::i2c::init(axp_i2c_port, axp_i2c_sda, axp_i2c_scl); - // I2C addr 0x34 = AXP192 - if (lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x95, 0x84, 0x72, axp_i2c_freq)) // GPIO4 enable - { - // AXP192_LDO2 = LCD PWR - // AXP192_IO4 = LCD RST - // AXP192_DC3 = LCD BL (Core2) - // AXP192_LDO3 = LCD BL (Tough) - // AXP192_IO1 = TP RST (Tough) - if (use_reset) lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x96, 0, ~0x02, axp_i2c_freq); // GPIO4 LOW (LCD RST) - lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x28, 0xF0, ~0, axp_i2c_freq); // set LDO2 3300mv // LCD PWR - lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x12, 0x04, ~0, axp_i2c_freq); // LDO2 enable - lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x96, 0x02, ~0, axp_i2c_freq); // GPIO4 HIGH (LCD RST) - - ets_delay_us(128); // AXP 起動後、LCDがアクセス可能になるまで少し待機 - - bus_cfg.pin_mosi = 23; - bus_cfg.pin_miso = 38; - bus_cfg.pin_sclk = 18; - bus_cfg.pin_dc = 15; - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - - _pin_level( 4, true); // TF card CS - id = _read_panel_id(&_bus_spi, 5); - if ((id & 0xFF) == 0xE3) - { // ILI9342c - bus_cfg.freq_write = 40000000; - bus_cfg.freq_read = 16000000; - _bus_spi.config(bus_cfg); - - auto p = new Panel_M5StackCore2(); - p->bus(&_bus_spi); - _panel_last = p; - - // Check exists touch controller for Core2 - if (lgfx::i2c::readRegister8(I2C_NUM_1, 0x38, 0, 400000).has_value()) - { - ESP_LOGW(LIBRARY_NAME, "[Autodetect] M5StackCore2"); - board = board_t::board_M5StackCore2; - - _set_backlight(new Light_M5StackCore2()); - - auto t = new lgfx::Touch_FT5x06(); - _touch_last = t; - auto cfg = t->config(); - cfg.pin_int = 39; // INT pin number - cfg.pin_sda = 21; // I2C SDA pin number - cfg.pin_scl = 22; // I2C SCL pin number - cfg.i2c_addr = 0x38; // I2C device addr - cfg.i2c_port = I2C_NUM_1;// I2C port number - cfg.freq = 400000; // I2C freq - cfg.x_min = 0; - cfg.x_max = 319; - cfg.y_min = 0; - cfg.y_max = 279; - t->config(cfg); - p->touch(t); - float affine[6] = { 1, 0, 0, 0, 1, 0 }; - p->setCalibrateAffine(affine); - } - else - { - // AXP192のGPIO1 = タッチコントローラRST - lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x92, 0, 0xF8, axp_i2c_freq); // GPIO1 OpenDrain - lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x94, 0, ~0x02, axp_i2c_freq); // GPIO1 LOW (TOUCH RST) - - ESP_LOGW(LIBRARY_NAME, "[Autodetect] M5Tough"); - board = board_t::board_M5Tough; - - _set_backlight(new Light_M5StackTough()); - - auto t = new Touch_M5Tough(); - _touch_last = t; - auto cfg = t->config(); - cfg.pin_int = 39; // INT pin number - cfg.pin_sda = 21; // I2C SDA pin number - cfg.pin_scl = 22; // I2C SCL pin number - cfg.i2c_addr = 0x2E; // I2C device addr - cfg.i2c_port = I2C_NUM_1;// I2C port number - cfg.freq = 400000; // I2C freq - cfg.x_min = 0; - cfg.x_max = 319; - cfg.y_min = 0; - cfg.y_max = 239; - t->config(cfg); - p->touch(t); - lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x94, 0x02, ~0, axp_i2c_freq); // GPIO1 HIGH (TOUCH RST) - } - - goto init_clear; - } - lgfx::pinMode( 4, lgfx::pin_mode_t::input); // TF card CS - lgfx::pinMode( 5, lgfx::pin_mode_t::input); // LCD CS - _bus_spi.release(); - } - } - board = board_t::board_unknown; init_clear: diff --git a/src/M5GFX.h b/src/M5GFX.h index 675a862..4ffa4f1 100644 --- a/src/M5GFX.h +++ b/src/M5GFX.h @@ -146,6 +146,7 @@ namespace m5gfx , board_M5ATOM , board_M5Camera , board_M5TimerCam + , board_M5Station }; } using board_t = boards::board_t; From 2be45dedcd3253c7c46c7072d96aaf46f149238e Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Sat, 9 Oct 2021 14:47:50 +0900 Subject: [PATCH 3/3] update: LovyanGFX --- src/M5GFX.h | 9 +- src/lgfx/Fonts/IPA/lgfx_font_japan.h | 7 ++ src/lgfx/Fonts/efont/lgfx_efont_cn.h | 8 ++ src/lgfx/Fonts/efont/lgfx_efont_ja.h | 8 ++ src/lgfx/Fonts/efont/lgfx_efont_kr.h | 8 ++ src/lgfx/Fonts/efont/lgfx_efont_tw.h | 8 ++ src/lgfx/utility/lgfx_qrcode.c | 33 +++-- src/lgfx/utility/lgfx_tjpgd.c | 2 + src/lgfx/utility/lgfx_tjpgd.h | 16 +-- src/lgfx/utility/pgmspace.h | 157 ++++++++++++------------ src/lgfx/utility/result.hpp | 37 +++--- src/lgfx/v1/LGFX_Sprite.hpp | 2 +- src/lgfx/v1/Touch.hpp | 2 +- src/lgfx/v1/gitTagVersion.h | 2 +- src/lgfx/v1/panel/Panel_ILI948x.hpp | 6 +- src/lgfx/v1/platforms/common.hpp | 2 + src/lgfx/v1/platforms/device.hpp | 1 + src/lgfx/v1/platforms/esp32/Bus_SPI.cpp | 16 ++- src/lgfx/v1/platforms/esp32/common.cpp | 7 +- src/lgfx/v1/platforms/samd51/common.cpp | 2 +- src/lgfx/v1/platforms/stm32/Bus_SPI.cpp | 16 ++- src/lgfx/v1/platforms/stm32/Bus_SPI.hpp | 7 +- 22 files changed, 214 insertions(+), 142 deletions(-) diff --git a/src/M5GFX.h b/src/M5GFX.h index 4ffa4f1..a9082d9 100644 --- a/src/M5GFX.h +++ b/src/M5GFX.h @@ -9,14 +9,6 @@ #include #endif -/// Use of std::min and std::max instead of macro definitions is recommended. -#ifdef min -#undef min -#endif -#ifdef max -#undef max -#endif - #ifdef setFont #undef setFont #endif @@ -28,6 +20,7 @@ #include "lgfx/v1/lgfx_filesystem_support.hpp" #include "lgfx/v1/LGFXBase.hpp" #include "lgfx/v1/LGFX_Sprite.hpp" +#include "lgfx/v1/LGFX_Button.hpp" #include diff --git a/src/lgfx/Fonts/IPA/lgfx_font_japan.h b/src/lgfx/Fonts/IPA/lgfx_font_japan.h index 855757f..f0e07fa 100644 --- a/src/lgfx/Fonts/IPA/lgfx_font_japan.h +++ b/src/lgfx/Fonts/IPA/lgfx_font_japan.h @@ -3,6 +3,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + extern const uint8_t lgfx_font_japan_mincho_8[]; extern const uint8_t lgfx_font_japan_mincho_12[]; extern const uint8_t lgfx_font_japan_mincho_16[]; @@ -40,5 +44,8 @@ extern const uint8_t lgfx_font_japan_gothic_p_32[]; extern const uint8_t lgfx_font_japan_gothic_p_36[]; extern const uint8_t lgfx_font_japan_gothic_p_40[]; +#ifdef __cplusplus +} +#endif /* __cplusplus */ #endif diff --git a/src/lgfx/Fonts/efont/lgfx_efont_cn.h b/src/lgfx/Fonts/efont/lgfx_efont_cn.h index 4ee727c..619145a 100644 --- a/src/lgfx/Fonts/efont/lgfx_efont_cn.h +++ b/src/lgfx/Fonts/efont/lgfx_efont_cn.h @@ -1,6 +1,10 @@ #include #define U8G2_USE_LARGE_FONTS +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + extern const uint8_t lgfx_efont_cn_10[]; extern const uint8_t lgfx_efont_cn_10_b[]; extern const uint8_t lgfx_efont_cn_10_bi[]; @@ -21,3 +25,7 @@ extern const uint8_t lgfx_efont_cn_24[]; extern const uint8_t lgfx_efont_cn_24_b[]; extern const uint8_t lgfx_efont_cn_24_bi[]; extern const uint8_t lgfx_efont_cn_24_i[]; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ diff --git a/src/lgfx/Fonts/efont/lgfx_efont_ja.h b/src/lgfx/Fonts/efont/lgfx_efont_ja.h index ef04ee9..fc1f64f 100644 --- a/src/lgfx/Fonts/efont/lgfx_efont_ja.h +++ b/src/lgfx/Fonts/efont/lgfx_efont_ja.h @@ -1,6 +1,10 @@ #include #define U8G2_USE_LARGE_FONTS +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + extern const uint8_t lgfx_efont_ja_10[]; extern const uint8_t lgfx_efont_ja_10_b[]; extern const uint8_t lgfx_efont_ja_10_bi[]; @@ -21,3 +25,7 @@ extern const uint8_t lgfx_efont_ja_24[]; extern const uint8_t lgfx_efont_ja_24_b[]; extern const uint8_t lgfx_efont_ja_24_bi[]; extern const uint8_t lgfx_efont_ja_24_i[]; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ diff --git a/src/lgfx/Fonts/efont/lgfx_efont_kr.h b/src/lgfx/Fonts/efont/lgfx_efont_kr.h index fb7b093..4dff9f9 100644 --- a/src/lgfx/Fonts/efont/lgfx_efont_kr.h +++ b/src/lgfx/Fonts/efont/lgfx_efont_kr.h @@ -1,6 +1,10 @@ #include #define U8G2_USE_LARGE_FONTS +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + extern const uint8_t lgfx_efont_kr_10[]; extern const uint8_t lgfx_efont_kr_10_b[]; extern const uint8_t lgfx_efont_kr_10_bi[]; @@ -21,3 +25,7 @@ extern const uint8_t lgfx_efont_kr_24[]; extern const uint8_t lgfx_efont_kr_24_b[]; extern const uint8_t lgfx_efont_kr_24_bi[]; extern const uint8_t lgfx_efont_kr_24_i[]; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ diff --git a/src/lgfx/Fonts/efont/lgfx_efont_tw.h b/src/lgfx/Fonts/efont/lgfx_efont_tw.h index 3ac8a83..3985b02 100644 --- a/src/lgfx/Fonts/efont/lgfx_efont_tw.h +++ b/src/lgfx/Fonts/efont/lgfx_efont_tw.h @@ -1,6 +1,10 @@ #include #define U8G2_USE_LARGE_FONTS +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + extern const uint8_t lgfx_efont_tw_10[]; extern const uint8_t lgfx_efont_tw_10_b[]; extern const uint8_t lgfx_efont_tw_10_bi[]; @@ -21,3 +25,7 @@ extern const uint8_t lgfx_efont_tw_24[]; extern const uint8_t lgfx_efont_tw_24_b[]; extern const uint8_t lgfx_efont_tw_24_bi[]; extern const uint8_t lgfx_efont_tw_24_i[]; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ diff --git a/src/lgfx/utility/lgfx_qrcode.c b/src/lgfx/utility/lgfx_qrcode.c index 7f9618f..084b0d9 100644 --- a/src/lgfx/utility/lgfx_qrcode.c +++ b/src/lgfx/utility/lgfx_qrcode.c @@ -40,6 +40,17 @@ #include #include +#if __has_include() +#include +#else +#include +#define alloca _alloca +#endif + +#ifdef max +#undef max +#endif + //#pragma mark - Error Correction Lookup tables #if LOCK_VERSION == 0 @@ -91,8 +102,7 @@ static const uint16_t NUM_RAW_DATA_MODULES = 567; static int max(int a, int b) { - if (a > b) { return a; } - return b; + return (a > b) ? a : b; } /* @@ -417,7 +427,7 @@ static void drawFunctionPatterns(BitBucket *modules, BitBucket *isFunction, uint } uint_fast8_t alignPositionIndex = alignCount - 1; - uint8_t alignPosition[alignCount]; + uint8_t* alignPosition = (uint8_t*)alloca(alignCount); alignPosition[0] = 6; @@ -715,10 +725,10 @@ static bool performErrorCorrection(uint8_t version, uint8_t ecc, BitBucket *data uint8_t shortDataBlockLen = shortBlockLen - blockEccLen; - uint8_t result[data->capacityBytes]; - memset(result, 0, sizeof(result)); - - uint8_t coeff[blockEccLen]; + uint8_t* result = (uint8_t*)alloca(data->capacityBytes); + memset(result, 0, data->capacityBytes); + + uint8_t* coeff = (uint8_t*)alloca(blockEccLen); rs_init(blockEccLen, coeff); uint16_t offset = 0; @@ -804,9 +814,10 @@ int8_t lgfx_qrcode_initBytes(QRCode *qrcode, uint8_t *modules, uint8_t version, #endif struct BitBucket codewords; - uint8_t codewordBytes[bb_getBufferSizeBytes(moduleCount)]; - bb_initBuffer(&codewords, codewordBytes, (int32_t)sizeof(codewordBytes)); - + int32_t codewordLen = bb_getBufferSizeBytes(moduleCount); + uint8_t* codewordBytes = (uint8_t*)alloca(codewordLen); + bb_initBuffer(&codewords, codewordBytes, codewordLen); + // Place the data code words into the buffer int8_t mode = encodeDataCodewords(&codewords, data, length, version); @@ -829,7 +840,7 @@ int8_t lgfx_qrcode_initBytes(QRCode *qrcode, uint8_t *modules, uint8_t version, bb_initGrid(&modulesGrid, modules, size); BitBucket isFunctionGrid; - uint8_t isFunctionGridBytes[bb_getGridSizeBytes(size)]; + uint8_t* isFunctionGridBytes = (uint8_t*)alloca(bb_getGridSizeBytes(size)); bb_initGrid(&isFunctionGrid, isFunctionGridBytes, size); // Draw function patterns, draw all codewords, do masking diff --git a/src/lgfx/utility/lgfx_tjpgd.c b/src/lgfx/utility/lgfx_tjpgd.c index 4098107..fe13470 100644 --- a/src/lgfx/utility/lgfx_tjpgd.c +++ b/src/lgfx/utility/lgfx_tjpgd.c @@ -131,7 +131,9 @@ static inline int32_t BYTECLIP ( /* Output 4x4 bayer pattern table */ /*---------------------------------------------*/ +#if JD_BAYER static const int_fast8_t Bayer[16] = { 0, 4, 1, 5,-2, 2,-1, 3, 1, 5, 0, 4,-1, 3,-2, 2}; +#endif /*-----------------------------------------------------------------------*/ diff --git a/src/lgfx/utility/lgfx_tjpgd.h b/src/lgfx/utility/lgfx_tjpgd.h index f4376c3..d96bfe0 100644 --- a/src/lgfx/utility/lgfx_tjpgd.h +++ b/src/lgfx/utility/lgfx_tjpgd.h @@ -25,14 +25,14 @@ extern "C" { #endif -#if defined(_WIN32) /* Main development platform */ -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef short int16_t; -typedef unsigned long uint32_t; -typedef long int32_t; -#else -#include "stdint.h" +#if __has_include () + #include +#elif defined(_WIN32) /* Main development platform */ + typedef unsigned char uint8_t; + typedef unsigned short uint16_t; + typedef short int16_t; + typedef unsigned long uint32_t; + typedef long int32_t; #endif /* Error code */ diff --git a/src/lgfx/utility/pgmspace.h b/src/lgfx/utility/pgmspace.h index debcec4..08a4b59 100644 --- a/src/lgfx/utility/pgmspace.h +++ b/src/lgfx/utility/pgmspace.h @@ -1,76 +1,81 @@ -/*----------------------------------------------------------------------------/ - Lovyan GFX - Graphics library for embedded devices. - -Original Source: - https://github.com/lovyan03/LovyanGFX/ - -Licence: - [BSD](https://github.com/lovyan03/LovyanGFX/blob/master/license.txt) - -Author: - [lovyan03](https://twitter.com/lovyan03) - -Contributors: - [ciniml](https://github.com/ciniml) - [mongonta0716](https://github.com/mongonta0716) - [tobozo](https://github.com/tobozo) -/----------------------------------------------------------------------------*/ -#ifndef __LGFX_PGMSPACE_H__ -#define __LGFX_PGMSPACE_H__ - -#if defined ( ARDUINO ) && !defined ( pgm_read_byte ) - #if __has_include() - #include - #elif __has_include() || defined(__AVR__) - #include - #else - #include - #endif -#endif -#if !defined ( pgm_read_byte ) - #define pgm_read_byte(addr) (*(const uint8_t *)((uintptr_t)addr)) - #define pgm_read_word(addr) (*(const uint16_t *)((uintptr_t)addr)) - #define pgm_read_dword(addr) (*(const uint32_t *)((uintptr_t)addr)) -#endif - -/// for not ESP8266 -#if !defined ( pgm_read_dword_with_offset ) - #if defined (__SAMD21__) - #define pgm_read_word_unaligned(addr) (uint16_t) \ - ( *(const uint8_t *)((uintptr_t)addr) \ - | *(const uint8_t *)((uintptr_t)addr+1) << 8 ) - #define pgm_read_3byte_unaligned(addr) (uint32_t) \ - ( *(const uint8_t *)((uintptr_t)addr) \ - | *(const uint8_t *)((uintptr_t)addr+1) << 8 \ - | *(const uint8_t *)((uintptr_t)addr+2) << 16 ) - #define pgm_read_dword_unaligned(addr) (uint32_t) \ - ( *(const uint8_t *)((uintptr_t)addr) \ - | *(const uint8_t *)((uintptr_t)addr+1) << 8 \ - | *(const uint8_t *)((uintptr_t)addr+2) << 16 \ - | *(const uint8_t *)((uintptr_t)addr+3) << 24 ) - #else - #define pgm_read_word_unaligned(addr) (*(const uint16_t *)((uintptr_t)addr)) - #define pgm_read_dword_unaligned(addr) (*(const uint32_t *)((uintptr_t)addr)) - #endif -#endif - -#if !defined ( pgm_read_3byte_unaligned ) - #define pgm_read_3byte_unaligned(addr) (pgm_read_dword_unaligned(addr) & 0xFFFFFFu) -#endif - -#if defined (__SAMD21__) || defined ( ESP8266 ) - static inline void write_3byte_unaligned(void* addr, uint32_t value) - { - reinterpret_cast(addr)[0] = value; - reinterpret_cast(addr)[1] = value >> 8; - reinterpret_cast(addr)[2] = value >> 16; - } -#else - static inline void write_3byte_unaligned(void* addr, uint32_t value) - { - reinterpret_cast(addr)[0] = value; - reinterpret_cast(addr)[2] = value >> 16; - } -#endif - -#endif +/*----------------------------------------------------------------------------/ + Lovyan GFX - Graphics library for embedded devices. + +Original Source: + https://github.com/lovyan03/LovyanGFX/ + +Licence: + [BSD](https://github.com/lovyan03/LovyanGFX/blob/master/license.txt) + +Author: + [lovyan03](https://twitter.com/lovyan03) + +Contributors: + [ciniml](https://github.com/ciniml) + [mongonta0716](https://github.com/mongonta0716) + [tobozo](https://github.com/tobozo) +/----------------------------------------------------------------------------*/ +#ifndef __LGFX_PGMSPACE_H__ +#define __LGFX_PGMSPACE_H__ + +#if defined ( ARDUINO ) && !defined ( pgm_read_byte ) + #if __has_include() + #include + #elif __has_include() || defined(__AVR__) + #include + #else + #include + #endif +#endif +#if !defined ( pgm_read_byte ) + #define pgm_read_byte(addr) (*(const uint8_t *)((uintptr_t)addr)) + #define pgm_read_word(addr) (*(const uint16_t *)((uintptr_t)addr)) + #define pgm_read_dword(addr) (*(const uint32_t *)((uintptr_t)addr)) + #define pgm_read_ptr(addr) (*(void * const *)(addr)) +#endif + +/// for not ESP8266 +#if !defined ( pgm_read_dword_with_offset ) + #if defined (__SAMD21__) + #define pgm_read_word_unaligned(addr) (uint16_t) \ + ( *(const uint8_t *)((uintptr_t)addr) \ + | *(const uint8_t *)((uintptr_t)addr+1) << 8 ) + #define pgm_read_3byte_unaligned(addr) (uint32_t) \ + ( *(const uint8_t *)((uintptr_t)addr) \ + | *(const uint8_t *)((uintptr_t)addr+1) << 8 \ + | *(const uint8_t *)((uintptr_t)addr+2) << 16 ) + #define pgm_read_dword_unaligned(addr) (uint32_t) \ + ( *(const uint8_t *)((uintptr_t)addr) \ + | *(const uint8_t *)((uintptr_t)addr+1) << 8 \ + | *(const uint8_t *)((uintptr_t)addr+2) << 16 \ + | *(const uint8_t *)((uintptr_t)addr+3) << 24 ) + #else + #define pgm_read_word_unaligned(addr) (*(const uint16_t *)((uintptr_t)addr)) + #define pgm_read_dword_unaligned(addr) (*(const uint32_t *)((uintptr_t)addr)) + #endif +#endif + +#if !defined ( pgm_read_3byte_unaligned ) + #define pgm_read_3byte_unaligned(addr) (pgm_read_dword_unaligned(addr) & 0xFFFFFFu) +#endif + +#if defined (__SAMD21__) || defined ( ESP8266 ) + static inline void write_3byte_unaligned(void* addr, uint32_t value) + { + reinterpret_cast(addr)[0] = value; + reinterpret_cast(addr)[1] = value >> 8; + reinterpret_cast(addr)[2] = value >> 16; + } +#else + static inline void write_3byte_unaligned(void* addr, uint32_t value) + { + reinterpret_cast(addr)[0] = value; + reinterpret_cast(addr)[2] = value >> 16; + } +#endif + +#ifndef PROGMEM +#define PROGMEM +#endif + +#endif diff --git a/src/lgfx/utility/result.hpp b/src/lgfx/utility/result.hpp index 96243f7..de1ce5f 100644 --- a/src/lgfx/utility/result.hpp +++ b/src/lgfx/utility/result.hpp @@ -32,17 +32,18 @@ #ifndef RESULT_RESULT_HPP #define RESULT_RESULT_HPP -#include // std::size_t +#include "../internal/memory.h" // std::address_of + +#include // size_t #include // std::enable_if, std::is_constructible, etc #include // placement-new -#include // std::address_of #include // std::reference_wrapper, std::invoke #include // std::in_place_t, std::forward #include // std::initializer_list #include // std::string (for exception message) #if defined(RESULT_EXCEPTIONS_DISABLED) -# include // std::fprintf, stderr +# include // std::fprintf, stderr #else # include // std::logic_error #endif @@ -69,21 +70,21 @@ # define RESULT_INLINE_VISIBILITY #endif -// [[clang::warn_unused_result]] is more full-featured than gcc's variant, since -// it supports being applied to class objects. -#if __cplusplus >= 201703L -# define RESULT_NODISCARD [[nodiscard]] -# define RESULT_WARN_UNUSED [[nodiscard]] -#elif defined(__clang__) && ((__clang_major__ > 3) || ((__clang_major__ == 3) && (__clang_minor__ >= 9))) -# define RESULT_NODISCARD [[clang::warn_unused_result]] -# define RESULT_WARN_UNUSED [[clang::warn_unused_result]] -#elif defined(__GNUC__) -# define RESULT_NODISCARD -# define RESULT_WARN_UNUSED [[gnu::warn_unused_result]] -#else +// // [[clang::warn_unused_result]] is more full-featured than gcc's variant, since +// // it supports being applied to class objects. +// #if __cplusplus >= 201703L +// # define RESULT_NODISCARD [[nodiscard]] +// # define RESULT_WARN_UNUSED [[nodiscard]] +// #elif defined(__clang__) && ((__clang_major__ > 3) || ((__clang_major__ == 3) && (__clang_minor__ >= 9))) +// # define RESULT_NODISCARD [[clang::warn_unused_result]] +// # define RESULT_WARN_UNUSED [[clang::warn_unused_result]] +// #elif defined(__GNUC__) +// # define RESULT_NODISCARD +// # define RESULT_WARN_UNUSED [[gnu::warn_unused_result]] +// #else # define RESULT_WARN_UNUSED # define RESULT_NODISCARD -#endif +// #endif #if defined(RESULT_NAMESPACE) # define RESULT_NAMESPACE_INTERNAL RESULT_NAMESPACE @@ -3432,7 +3433,7 @@ namespace std { template struct hash<::RESULT_NS_IMPL::result> { - auto operator()(const RESULT_NS_IMPL::result& x) const -> std::size_t + auto operator()(const RESULT_NS_IMPL::result& x) const -> size_t { if (x.has_value()) { return std::hash{}(*x) + 1; // add '1' to differentiate from error case @@ -3444,7 +3445,7 @@ namespace std { template struct hash<::RESULT_NS_IMPL::result> { - auto operator()(const RESULT_NS_IMPL::result& x) const -> std::size_t + auto operator()(const RESULT_NS_IMPL::result& x) const -> size_t { if (x.has_value()) { return 0; diff --git a/src/lgfx/v1/LGFX_Sprite.hpp b/src/lgfx/v1/LGFX_Sprite.hpp index 3844bcf..dbb3862 100644 --- a/src/lgfx/v1/LGFX_Sprite.hpp +++ b/src/lgfx/v1/LGFX_Sprite.hpp @@ -444,7 +444,7 @@ namespace lgfx uint32_t seekOffset = bmpdata.bfOffBits; uint_fast16_t bpp = bmpdata.biBitCount; // 24 bcBitCount 24=RGB24bit setColorDepth(bpp < 32 ? bpp : 24); - int32_t w = bmpdata.biWidth; + uint32_t w = bmpdata.biWidth; int32_t h = bmpdata.biHeight; // bcHeight Image height (pixels) if (!createSprite(w, h)) return false; diff --git a/src/lgfx/v1/Touch.hpp b/src/lgfx/v1/Touch.hpp index 15e976e..aa08517 100644 --- a/src/lgfx/v1/Touch.hpp +++ b/src/lgfx/v1/Touch.hpp @@ -56,7 +56,6 @@ namespace lgfx int16_t pin_sclk; int16_t pin_mosi; int16_t pin_miso; - int16_t pin_cs; }; struct { @@ -66,6 +65,7 @@ namespace lgfx int16_t i2c_addr; }; }; + int16_t pin_cs = -1; }; virtual ~ITouch(void) = default; diff --git a/src/lgfx/v1/gitTagVersion.h b/src/lgfx/v1/gitTagVersion.h index b3c520b..44621fb 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 0 -#define LGFX_VERSION_PATCH 3 +#define LGFX_VERSION_PATCH 4 #define LOVYANGFX_VERSION F( LGFX_VERSION_MAJOR "." LGFX_VERSION_MINOR "." LGFX_VERSION_PATCH ) diff --git a/src/lgfx/v1/panel/Panel_ILI948x.hpp b/src/lgfx/v1/panel/Panel_ILI948x.hpp index 50bce85..049fbe5 100644 --- a/src/lgfx/v1/panel/Panel_ILI948x.hpp +++ b/src/lgfx/v1/panel/Panel_ILI948x.hpp @@ -65,9 +65,9 @@ namespace lgfx static constexpr uint8_t list0[] = { CMD_SLPOUT , 0+CMD_INIT_DELAY, 120, // Exit sleep mode - CMD_PWSET , 3, 0x07, 0x40, 0x1D, - CMD_VMCTR , 3, 0x00, 0x18, 0x13, - CMD_PWSETN , 2, 0x01, 0x11, + CMD_PWSET , 3, 0x07, 0x42, 0x18, + CMD_VMCTR , 3, 0x00, 0x07, 0x10, + CMD_PWSETN , 2, 0x01, 0x02, CMD_PNLDRV , 5, 0x10, 0x3B, 0x00, 0x02, 0x11, CMD_FRMCTR , 1, 0x03, CMD_GMCTR ,12, 0x00, 0x44, 0x06, 0x44, 0x0A, 0x08, diff --git a/src/lgfx/v1/platforms/common.hpp b/src/lgfx/v1/platforms/common.hpp index c29dcbb..131723e 100644 --- a/src/lgfx/v1/platforms/common.hpp +++ b/src/lgfx/v1/platforms/common.hpp @@ -55,6 +55,8 @@ Original Source: #endif +#include "../../utility/result.hpp" + namespace lgfx { inline namespace v1 diff --git a/src/lgfx/v1/platforms/device.hpp b/src/lgfx/v1/platforms/device.hpp index 82ea472..b502859 100644 --- a/src/lgfx/v1/platforms/device.hpp +++ b/src/lgfx/v1/platforms/device.hpp @@ -62,6 +62,7 @@ Original Source: #elif defined (STM32F2xx) || defined (STM32F4xx) || defined (STM32F7xx) #include "stm32/Bus_SPI.hpp" +#include "stm32/Panel_LTDC.hpp" #elif defined (ARDUINO_ARCH_SPRESENSE) diff --git a/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp b/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp index c432945..a5ce213 100644 --- a/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp +++ b/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp @@ -94,16 +94,24 @@ namespace lgfx return _inited; } + static void gpio_reset(size_t pin) + { + if (pin >= GPIO_NUM_MAX) return; + gpio_reset_pin( (gpio_num_t)pin); + gpio_matrix_out((gpio_num_t)pin, 0x100, 0, 0); + gpio_matrix_in( (gpio_num_t)pin, 0x100, 0 ); + } + void Bus_SPI::release(void) { //ESP_LOGI("LGFX","Bus_SPI::release"); - pinMode(_cfg.pin_dc , pin_mode_t::input); - pinMode(_cfg.pin_mosi, pin_mode_t::input); - pinMode(_cfg.pin_miso, pin_mode_t::input); - pinMode(_cfg.pin_sclk, pin_mode_t::input); if (!_inited) return; _inited = false; spi::release(_cfg.spi_host); + gpio_reset(_cfg.pin_dc ); + gpio_reset(_cfg.pin_mosi); + gpio_reset(_cfg.pin_miso); + gpio_reset(_cfg.pin_sclk); } void Bus_SPI::beginTransaction(void) diff --git a/src/lgfx/v1/platforms/esp32/common.cpp b/src/lgfx/v1/platforms/esp32/common.cpp index f0fcda6..70c916e 100644 --- a/src/lgfx/v1/platforms/esp32/common.cpp +++ b/src/lgfx/v1/platforms/esp32/common.cpp @@ -634,7 +634,12 @@ namespace lgfx cpp::result init(int i2c_port, int pin_sda, int pin_scl) { - if (i2c_port >= I2C_NUM_MAX) { return cpp::fail(error_t::invalid_arg); } + if ((i2c_port >= I2C_NUM_MAX) + || ((uint32_t)pin_scl >= GPIO_NUM_MAX) + || ((uint32_t)pin_sda >= GPIO_NUM_MAX)) + { + return cpp::fail(error_t::invalid_arg); + } auto dev = getDev(i2c_port); i2c_context[i2c_port].save_reg(dev); release(i2c_port); diff --git a/src/lgfx/v1/platforms/samd51/common.cpp b/src/lgfx/v1/platforms/samd51/common.cpp index 2f83ced..a518bd1 100644 --- a/src/lgfx/v1/platforms/samd51/common.cpp +++ b/src/lgfx/v1/platforms/samd51/common.cpp @@ -303,7 +303,7 @@ namespace lgfx } }; - static constexpr sercom_data_t sercom_data[] = { + static const sercom_data_t sercom_data[] = { { (uintptr_t)SERCOM0, SERCOM0_GCLK_ID_CORE, SERCOM0_GCLK_ID_SLOW, SERCOM0_DMAC_ID_TX, SERCOM0_DMAC_ID_RX }, { (uintptr_t)SERCOM1, SERCOM1_GCLK_ID_CORE, SERCOM1_GCLK_ID_SLOW, SERCOM1_DMAC_ID_TX, SERCOM1_DMAC_ID_RX }, { (uintptr_t)SERCOM2, SERCOM2_GCLK_ID_CORE, SERCOM2_GCLK_ID_SLOW, SERCOM2_DMAC_ID_TX, SERCOM2_DMAC_ID_RX }, diff --git a/src/lgfx/v1/platforms/stm32/Bus_SPI.cpp b/src/lgfx/v1/platforms/stm32/Bus_SPI.cpp index f601ecd..c70f3e6 100644 --- a/src/lgfx/v1/platforms/stm32/Bus_SPI.cpp +++ b/src/lgfx/v1/platforms/stm32/Bus_SPI.cpp @@ -54,7 +54,7 @@ namespace lgfx } } - void Bus_SPI::init(void) + bool Bus_SPI::init(void) { lgfx::pinMode(_cfg.pin_dc, pin_mode_t::output); @@ -85,8 +85,8 @@ namespace lgfx if (HAL_DMA_Init(&_dmaHal) != HAL_OK) { // Init DMA with settings - for (;;) {}; - return; // error + // for (;;) {}; + // return; // error }; if (_cfg.spi_port == SPI1) @@ -100,6 +100,8 @@ namespace lgfx __HAL_LINKDMA(&_spiHal, hdmatx, _dmaHal); // Attach DMA engine to SPI peripheral //*/ + + return true; } void Bus_SPI::release(void) @@ -141,9 +143,9 @@ namespace lgfx return _cfg.spi_port->SR & SPI_SR_BSY; } - void Bus_SPI::writeCommand(uint32_t data, uint_fast8_t bit_length) + bool Bus_SPI::writeCommand(uint32_t data, uint_fast8_t bit_length) { - if (0 == (bit_length >>= 3)) return; + if (0 == (bit_length >>= 3)) { return true; } auto spidr = reinterpret_cast(&_cfg.spi_port->DR); auto spisr = &_cfg.spi_port->SR; dc_control(false); @@ -154,6 +156,7 @@ namespace lgfx do {} while (!(*spisr & sr_mask)); *spidr = data; } + return true; } void Bus_SPI::writeData(uint32_t data, uint_fast8_t bit_length) @@ -282,13 +285,14 @@ namespace lgfx return res; } - void Bus_SPI::readBytes(uint8_t* dst, uint32_t length, bool use_dma) + bool Bus_SPI::readBytes(uint8_t* dst, uint32_t length, bool use_dma) { do { dst[0] = SPI.transfer(0); ++dst; } while (--length); + return true; } void Bus_SPI::readPixels(void* dst, pixelcopy_t* param, uint32_t length) diff --git a/src/lgfx/v1/platforms/stm32/Bus_SPI.hpp b/src/lgfx/v1/platforms/stm32/Bus_SPI.hpp index 29fad29..62de14e 100644 --- a/src/lgfx/v1/platforms/stm32/Bus_SPI.hpp +++ b/src/lgfx/v1/platforms/stm32/Bus_SPI.hpp @@ -53,7 +53,7 @@ namespace lgfx bus_type_t busType(void) const override { return bus_type_t::bus_spi; } - void init(void) override; + bool init(void) override; void release(void) override; void beginTransaction(void) override; @@ -61,7 +61,8 @@ namespace lgfx void wait(void) override; bool busy(void) const override; - void writeCommand(uint32_t data, uint_fast8_t bit_length) override; + void flush(void) override {} + bool writeCommand(uint32_t data, uint_fast8_t bit_length) override; void writeData(uint32_t data, uint_fast8_t bit_length) override; void writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t count) override; void writePixels(pixelcopy_t* param, uint32_t length) override; @@ -75,7 +76,7 @@ namespace lgfx void beginRead(void) override; void endRead(void) override; uint32_t readData(uint_fast8_t bit_length) override; - void readBytes(uint8_t* dst, uint32_t length, bool use_dma) override; + bool readBytes(uint8_t* dst, uint32_t length, bool use_dma) override; void readPixels(void* dst, pixelcopy_t* param, uint32_t length) override; private: