From 2579b3e76133e0c3b5b1c54706e8ed84b1636f8d Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Wed, 20 Mar 2024 21:01:14 +0900 Subject: [PATCH 1/5] Fixed wrong behavior when drawEllipse and fillEllipse width is 0 ( #544 ) --- src/lgfx/v1/LGFXBase.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lgfx/v1/LGFXBase.cpp b/src/lgfx/v1/LGFXBase.cpp index d4809938..294559bd 100644 --- a/src/lgfx/v1/LGFXBase.cpp +++ b/src/lgfx/v1/LGFXBase.cpp @@ -342,11 +342,11 @@ namespace lgfx void LGFXBase::drawEllipse(int32_t x, int32_t y, int32_t rx, int32_t ry) { if (ry == 0) { - drawFastHLine(x - rx, y, (ry << 2) + 1); + drawFastHLine(x - rx, y, (rx << 1) + 1); return; } if (rx == 0) { - drawFastVLine(x, y - ry, (rx << 2) + 1); + drawFastVLine(x, y - ry, (ry << 1) + 1); return; } if (rx < 0 || ry < 0) return; @@ -391,11 +391,11 @@ namespace lgfx void LGFXBase::fillEllipse(int32_t x, int32_t y, int32_t rx, int32_t ry) { if (ry == 0) { - drawFastHLine(x - rx, y, (ry << 2) + 1); + drawFastHLine(x - rx, y, (rx << 1) + 1); return; } if (rx == 0) { - drawFastVLine(x, y - ry, (rx << 2) + 1); + drawFastVLine(x, y - ry, (ry << 1) + 1); return; } if (rx < 0 || ry < 0) return; From 0e5268796883273da26119c11fc82fa6f23f941e Mon Sep 17 00:00:00 2001 From: lsdlsd88 Date: Sat, 6 Apr 2024 18:32:23 +0200 Subject: [PATCH 2/5] Update Panel_ILI9341 to add new variant ILI9341_2 (#551) --- src/lgfx/v1/panel/Panel_ILI9341.hpp | 73 ++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/src/lgfx/v1/panel/Panel_ILI9341.hpp b/src/lgfx/v1/panel/Panel_ILI9341.hpp index 2270f014..650ba2b7 100644 --- a/src/lgfx/v1/panel/Panel_ILI9341.hpp +++ b/src/lgfx/v1/panel/Panel_ILI9341.hpp @@ -25,14 +25,19 @@ namespace lgfx { //---------------------------------------------------------------------------- - struct Panel_ILI9341 : public Panel_LCD + struct Panel_ILI9341_Base : public Panel_LCD { - Panel_ILI9341(void) + Panel_ILI9341_Base(void) { _cfg.memory_width = _cfg.panel_width = 240; _cfg.memory_height = _cfg.panel_height = 320; } + }; + +//---------------------------------------------------------------------------- + struct Panel_ILI9341 : public Panel_ILI9341_Base + { protected: static constexpr uint8_t CMD_FRMCTR1 = 0xB1; @@ -88,5 +93,69 @@ namespace lgfx }; //---------------------------------------------------------------------------- + + + struct Panel_ILI9341_2 : public Panel_ILI9341_Base + { + protected: + + static constexpr uint8_t CMD_FRMCTR1 = 0xB1; + static constexpr uint8_t CMD_FRMCTR2 = 0xB2; + static constexpr uint8_t CMD_FRMCTR3 = 0xB3; + static constexpr uint8_t CMD_INVCTR = 0xB4; + static constexpr uint8_t CMD_DFUNCTR = 0xB6; + static constexpr uint8_t CMD_PWCTR1 = 0xC0; + static constexpr uint8_t CMD_PWCTR2 = 0xC1; + static constexpr uint8_t CMD_PWCTR3 = 0xC2; + static constexpr uint8_t CMD_PWCTR4 = 0xC3; + static constexpr uint8_t CMD_PWCTR5 = 0xC4; + static constexpr uint8_t CMD_VMCTR1 = 0xC5; + static constexpr uint8_t CMD_VMCTR2 = 0xC7; + static constexpr uint8_t CMD_GMCTRP1 = 0x0; // Positive Gamma Correction (E0h) + static constexpr uint8_t CMD_GMCTRN1 = 0x0; // Negative Gamma Correction (E1h) + static constexpr uint8_t CMD_RDINDEX = 0xD9; // ili9341 + static constexpr uint8_t CMD_IDXRD = 0xDD; // ILI9341 only, indexed control register read + + const uint8_t* getInitCommands(uint8_t listno) const override + { + static constexpr uint8_t list0[] = + { + 0xEF , 3, 0x03,0x80,0x02, + 0xCF , 3, 0x00,0xC1,0x30, + 0xED , 4, 0x64,0x03,0x12,0x81, + 0xE8 , 3, 0x85,0x00,0x78, + 0xCB , 5, 0x39,0x2C,0x00,0x34,0x02, + 0xF7 , 1, 0x20, + 0xEA , 2, 0x00,0x00, + CMD_PWCTR1, 1, 0x10, + CMD_PWCTR2, 1, 0x00, + CMD_VMCTR1, 2, 0x30,0x30, + CMD_VMCTR2, 1, 0xB7, + 0x3A , 1, 0x55, + 0x36 , 1, 0x08, + CMD_FRMCTR1, 2, 0x00,0x1A, + 0xF2 , 1, 0x00, + + CMD_GAMMASET,1, 0x01, // Gamma set, curve 1 + CMD_GMCTRP1,15, 0x0F,0x2A,0x28,0x08,0x0E,0x08,0x54,0xA9,0x43,0x0A,0x0F,0x00,0x00,0x00,0x00, + CMD_GMCTRN1,15, 0x00,0x15,0x17,0x07,0x11,0x06,0x2B,0x56,0x3C,0x05,0x10,0x0F,0x3F,0x3F,0x0F, + CMD_DFUNCTR, 3, 0x08,0x82,0x27, + 0x2B , 4, 0x00,0x00,0x01,0x3F, + 0x2A , 4, 0x00,0x00,0x00,0x3F, + CMD_SLPOUT , 0+CMD_INIT_DELAY, 120, // Exit sleep mode + CMD_IDMOFF , 0, + CMD_DISPON , 0+CMD_INIT_DELAY, 100, + 0xFF,0xFF, // end + }; + switch (listno) + { + case 0: return list0; + default: return nullptr; + } + } + }; + +//---------------------------------------------------------------------------- + } } From c4391883b842ab49dbe57782c1ea70057f09dd39 Mon Sep 17 00:00:00 2001 From: tobozo Date: Sat, 6 Apr 2024 18:33:46 +0200 Subject: [PATCH 3/5] raised sdk versions for esp8266 --- .github/workflows/PlatformioBuild.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/PlatformioBuild.yml b/.github/workflows/PlatformioBuild.yml index 459ceecd..aa591db5 100644 --- a/.github/workflows/PlatformioBuild.yml +++ b/.github/workflows/PlatformioBuild.yml @@ -57,9 +57,9 @@ jobs: - board: m5stack-core-esp32 - board: m5stack-core2 - board: m5stack-cores3 - - { board: esp8266, platform-version: 3.0.0, ... } - - { board: esp8266, platform-version: 3.1.0, ... } - - { board: esp8266, platform-version: 3.2.0, ... } + - { board: esp8266, platform-version: 4.2.1, ... } + - { board: esp8266, platform-version: 4.2.0, ... } + - { board: esp8266, platform-version: 4.1.0, ... } - { board: seeed_wio_terminal, platform-version: default, ... } - { board: adafruit_pybadge_m4, platform-version: default, ... } - { board: pico, platform-version: default, ... } From a0e0d14df3f6d24e589b77adb524cc3a75dbf8fa Mon Sep 17 00:00:00 2001 From: tobozo Date: Sat, 6 Apr 2024 19:01:48 +0200 Subject: [PATCH 4/5] added latest sdk versions --- .../Test/build_test/platformio_esp8266.ini | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/examples/Test/build_test/platformio_esp8266.ini b/examples/Test/build_test/platformio_esp8266.ini index a4c5289a..1369a33e 100644 --- a/examples/Test/build_test/platformio_esp8266.ini +++ b/examples/Test/build_test/platformio_esp8266.ini @@ -11,18 +11,26 @@ platform = espressif8266@3.1.0 [esp8266_3_2_0] platform = espressif8266@3.2.0 +[esp8266_4_1_0] +platform = espressif8266@4.1.0 + +[esp8266_4_2_0] +platform = espressif8266@4.2.0 + +[esp8266_4_2_1] +platform = espressif8266@4.2.1 + [env:esp8266] -[env:esp8266-3_0_0] -platform = ${esp8266_3_0_0.platform} +[env:esp8266-4_1_0] +platform = ${esp8266_4_1_0.platform} board = d1_mini -[env:esp8266-3_1_0] -platform = ${esp8266_3_1_0.platform} +[env:esp8266-4_2_0] +platform = ${esp8266_4_2_0.platform} board = d1_mini -[env:esp8266-3_2_0] -platform = ${esp8266_3_2_0.platform} +[env:esp8266-4_2_1] +platform = ${esp8266_4_2_1.platform} board = d1_mini - From 0e474e2f1a85f55a90804ef0c741d30d10496f62 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Wed, 24 Apr 2024 01:14:46 -0500 Subject: [PATCH 5/5] Portduino/Native: arduino_default SPI and I2C enhancements (#557) * Add basic support for I2C touchscreens on arduino_default * Add quirk for platforms that can't continue an I2C read * Add configurable SPI device to arduino_default BUS_SPI * Use more appropriate define for PORTDUINO --- .../v1/platforms/arduino_default/Bus_SPI.cpp | 37 ++++---- .../v1/platforms/arduino_default/Bus_SPI.hpp | 4 +- .../v1/platforms/arduino_default/common.cpp | 87 ++++++++++++++++++- src/lgfx/v1/touch/Touch_FT5x06.cpp | 4 + 4 files changed, 114 insertions(+), 18 deletions(-) diff --git a/src/lgfx/v1/platforms/arduino_default/Bus_SPI.cpp b/src/lgfx/v1/platforms/arduino_default/Bus_SPI.cpp index eb39fd30..4035ae0a 100644 --- a/src/lgfx/v1/platforms/arduino_default/Bus_SPI.cpp +++ b/src/lgfx/v1/platforms/arduino_default/Bus_SPI.cpp @@ -50,14 +50,19 @@ namespace lgfx { dc_h(); pinMode(_cfg.pin_dc, pin_mode_t::output); - //SPI.pins(_cfg.pin_sclk, _cfg.pin_miso, _cfg.pin_mosi, -1); - SPI.begin(); + //PrivateSPI->pins(_cfg.pin_sclk, _cfg.pin_miso, _cfg.pin_mosi, -1); + PrivateSPI->begin(); return true; } void Bus_SPI::release(void) { - SPI.end(); + PrivateSPI->end(); + } + + void Bus_SPI::spi_device(HardwareSPI *newSPI) + { + PrivateSPI = newSPI; } void Bus_SPI::beginTransaction(void) @@ -65,26 +70,26 @@ namespace lgfx dc_h(); //SPISettings setting(_cfg.freq_write, BitOrder::MSBFIRST, _cfg.spi_mode, true); SPISettings setting(_cfg.freq_write, MSBFIRST, _cfg.spi_mode); - SPI.beginTransaction(setting); + PrivateSPI->beginTransaction(setting); } void Bus_SPI::endTransaction(void) { - SPI.endTransaction(); + PrivateSPI->endTransaction(); dc_h(); } void Bus_SPI::beginRead(void) { - SPI.endTransaction(); + PrivateSPI->endTransaction(); //SPISettings setting(_cfg.freq_read, BitOrder::MSBFIRST, _cfg.spi_mode, false); SPISettings setting(_cfg.freq_read, MSBFIRST, _cfg.spi_mode); - SPI.beginTransaction(setting); + PrivateSPI->beginTransaction(setting); } void Bus_SPI::endRead(void) { - SPI.endTransaction(); + PrivateSPI->endTransaction(); beginTransaction(); } @@ -100,14 +105,14 @@ namespace lgfx bool Bus_SPI::writeCommand(uint32_t data, uint_fast8_t bit_length) { dc_l(); - SPI.transfer((uint8_t*)&data, bit_length >> 3); + PrivateSPI->transfer((uint8_t*)&data, bit_length >> 3); dc_h(); return true; } void Bus_SPI::writeData(uint32_t data, uint_fast8_t bit_length) { - SPI.transfer((uint8_t*)&data, bit_length >> 3); + PrivateSPI->transfer((uint8_t*)&data, bit_length >> 3); } void Bus_SPI::writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t length) @@ -116,7 +121,7 @@ namespace lgfx auto bytes = bit_length >> 3; do { - SPI.send(reinterpret_cast(&data), bytes); + PrivateSPI->send(reinterpret_cast(&data), bytes); } while (--length); /*/ const uint8_t dst_bytes = bit_length >> 3; @@ -137,7 +142,7 @@ namespace lgfx fillpos += fillpos; } - SPI.transfer(buf, len * dst_bytes); + PrivateSPI->transfer(buf, len * dst_bytes); } while (length -= len); //*/ } @@ -153,7 +158,7 @@ namespace lgfx if (limit <= 32) limit <<= 1; auto buf = _flip_buffer.getBuffer(len * dst_bytes); param->fp_copy(buf, 0, len, param); - SPI.transfer(buf, len * dst_bytes); + PrivateSPI->transfer(buf, len * dst_bytes); } while (length -= len); } @@ -161,7 +166,7 @@ namespace lgfx { if (dc) dc_h(); else dc_l(); - SPI.transfer(const_cast(data), length); + PrivateSPI->transfer(const_cast(data), length); if (!dc) dc_h(); } @@ -173,7 +178,7 @@ namespace lgfx int idx = 0; do { - res |= SPI.transfer(0) << idx; + res |= PrivateSPI->transfer(0) << idx; idx += 8; } while (--bit_length); return res; @@ -183,7 +188,7 @@ namespace lgfx { do { - dst[0] = SPI.transfer(0); + dst[0] = PrivateSPI->transfer(0); ++dst; } while (--length); return true; diff --git a/src/lgfx/v1/platforms/arduino_default/Bus_SPI.hpp b/src/lgfx/v1/platforms/arduino_default/Bus_SPI.hpp index f9e4f027..40de089d 100644 --- a/src/lgfx/v1/platforms/arduino_default/Bus_SPI.hpp +++ b/src/lgfx/v1/platforms/arduino_default/Bus_SPI.hpp @@ -52,6 +52,7 @@ namespace lgfx bool init(void) override; void release(void) override; + void spi_device(HardwareSPI *newSPI); void beginTransaction(void) override; void endTransaction(void) override; @@ -76,7 +77,7 @@ namespace lgfx bool readBytes(uint8_t* dst, uint32_t length, bool use_dma) override; void readPixels(void* dst, pixelcopy_t* param, uint32_t length) override; - private: + protected: __attribute__ ((always_inline)) inline void dc_h(void) { gpio_hi(_cfg.pin_dc); @@ -85,6 +86,7 @@ namespace lgfx gpio_lo(_cfg.pin_dc); } + HardwareSPI *PrivateSPI = &SPI; config_t _cfg; FlipBuffer _flip_buffer; bool _need_wait; diff --git a/src/lgfx/v1/platforms/arduino_default/common.cpp b/src/lgfx/v1/platforms/arduino_default/common.cpp index 2e8db8b2..5237a127 100644 --- a/src/lgfx/v1/platforms/arduino_default/common.cpp +++ b/src/lgfx/v1/platforms/arduino_default/common.cpp @@ -79,9 +79,93 @@ namespace lgfx //---------------------------------------------------------------------------- - /// unimplemented. + namespace i2c { +#ifdef TwoWire_h + cpp::result init(int i2c_port, int pin_sda, int pin_scl) { Wire.begin(); return {};} + cpp::result release(int i2c_port) { Wire.end(); return {};} + cpp::result restart(int i2c_port, int i2c_addr, uint32_t freq, bool read) { Wire.endTransmission(true); Wire.beginTransmission(i2c_addr); return {};} + cpp::result beginTransaction(int i2c_port, int i2c_addr, uint32_t freq, bool read) { Wire.beginTransmission(i2c_addr); return {};} + cpp::result endTransaction(int i2c_port) { Wire.endTransmission(true); return {};} + cpp::result writeBytes(int i2c_port, const uint8_t *data, size_t length) { Wire.write(data, length); return {};} + cpp::result readBytes(int i2c_port, uint8_t *data, size_t length) + { + Wire.readBytes((char *)data, (size_t)length); + /* + printf("0x"); + for (int i=0; i< length; i++) { + printf("%02x ", data[i]); + } + printf("\n"); + */ + return {}; + } + cpp::result readBytes(int i2c_port, uint8_t *data, size_t length, bool last_nack) + { + Wire.readBytes((char *)data, (size_t)length); + /* + printf("0x"); + for (int i=0; i< length; i++) { + printf("%02x ", data[i]); + } + printf("\n"); + */ + return {}; + } + + cpp::result transactionWrite(int i2c_port, int addr, const uint8_t *writedata, uint8_t writelen, uint32_t freq) { + cpp::result res; + if ((res = beginTransaction(i2c_port, addr, freq, false)).has_value() && (res = writeBytes(i2c_port, writedata, writelen)).has_value()) + { + res = endTransaction(i2c_port); + } + return res; + } + + cpp::result transactionRead(int i2c_port, int addr, uint8_t *readdata, uint8_t readlen, uint32_t freq) { + cpp::result res; + if ((res = beginTransaction(i2c_port, addr, freq, false)).has_value() && (res = readBytes(i2c_port, readdata, readlen)).has_value()) + { + res = endTransaction(i2c_port); + } + return res; + } + + cpp::result transactionWriteRead(int i2c_port, int addr, const uint8_t *writedata, uint8_t writelen, uint8_t *readdata, size_t readlen, uint32_t freq) { + cpp::result res; + if ((res = beginTransaction(i2c_port, addr, freq, false)).has_value() && (res = writeBytes(i2c_port, writedata, writelen)).has_value() && + (res = restart(i2c_port, addr, freq, false)).has_value() && (res = readBytes(i2c_port, readdata, readlen)).has_value()) + { + res = endTransaction(i2c_port); + } + return res; + } + + cpp::result readRegister8(int i2c_port, int addr, uint8_t reg, uint32_t freq) { + auto res = transactionWriteRead(i2c_port, addr, ®, 1, ®, 1, freq); + if (res.has_value()) + { + return reg; + } + return cpp::fail(res.error()); + } + + cpp::result writeRegister8(int i2c_port, int addr, uint8_t reg, uint8_t data, uint8_t mask, uint32_t freq) { + uint8_t tmp[2] = {reg, data}; + if (mask != 0) + { + auto res = transactionWriteRead(i2c_port, addr, ®, 1, &tmp[1], 1, freq); + if (res.has_error()) + { + return res; + } + tmp[1] = (tmp[1] & mask) | data; + } + return transactionWrite(i2c_port, addr, tmp, 2, freq); + } + + #else cpp::result init(int i2c_port, int pin_sda, int pin_scl) { return cpp::fail(error_t::unknown_err); } cpp::result release(int i2c_port) { return cpp::fail(error_t::unknown_err); } cpp::result restart(int i2c_port, int i2c_addr, uint32_t freq, bool read) { return cpp::fail(error_t::unknown_err); } @@ -99,6 +183,7 @@ namespace lgfx cpp::result readRegister8(int i2c_port, int addr, uint8_t reg, uint32_t freq) { return cpp::fail(error_t::unknown_err); } cpp::result writeRegister8(int i2c_port, int addr, uint8_t reg, uint8_t data, uint8_t mask, uint32_t freq) { return cpp::fail(error_t::unknown_err); } +#endif } //---------------------------------------------------------------------------- diff --git a/src/lgfx/v1/touch/Touch_FT5x06.cpp b/src/lgfx/v1/touch/Touch_FT5x06.cpp index 3194be21..2fdbaff6 100644 --- a/src/lgfx/v1/touch/Touch_FT5x06.cpp +++ b/src/lgfx/v1/touch/Touch_FT5x06.cpp @@ -117,6 +117,10 @@ if (_inited) uint_fast8_t points = std::min(max_touch_points, readdata[0] & 0x0Fu); if (points) { +#ifdef PORTDUINO_LINUX_HARDWARE + readdata[1] = 0x03; + lgfx::i2c::writeBytes(_cfg.i2c_port, &readdata[1], 1); +#endif if (lgfx::i2c::readBytes(_cfg.i2c_port, &readdata[1], points * 6 - 2)) { res = points * 6 - 1;