From bf905b3e07f58ce3f61651d55e4351f694b5d395 Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Sun, 12 Jul 2020 09:50:50 +0900 Subject: [PATCH 01/19] bugfix: readRect with rgb565_t, rgb888_t --- src/lgfx/LGFXBase.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lgfx/LGFXBase.hpp b/src/lgfx/LGFXBase.hpp index 0ef8b57c..8a58bb5f 100644 --- a/src/lgfx/LGFXBase.hpp +++ b/src/lgfx/LGFXBase.hpp @@ -261,6 +261,10 @@ namespace lgfx void readRect( std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, T* data) { pixelcopy_t p(nullptr, get_depth::value, _read_conv.depth, false, _palette); + if (std::is_same::value || std::is_same::value) { + p.no_convert = false; + p.fp_copy = pixelcopy_t::get_fp_normalcopy_dst(_read_conv.depth); + } if (p.fp_copy==nullptr) { p.fp_copy = pixelcopy_t::get_fp_normalcopy_dst(_read_conv.depth); } read_rect(x, y, w, h, data, &p); } From 6e630c179194f4d27fd3989bd727d63b73f698d3 Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Sun, 12 Jul 2020 09:52:16 +0900 Subject: [PATCH 02/19] update: jpeg decode speed up. --- src/lgfx/lgfx_common.hpp | 4 ++-- src/lgfx/utility/lgfx_tjpgd.c | 35 ++++++++++++++++++----------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/lgfx/lgfx_common.hpp b/src/lgfx/lgfx_common.hpp index a2c51c98..2da173b7 100644 --- a/src/lgfx/lgfx_common.hpp +++ b/src/lgfx/lgfx_common.hpp @@ -144,7 +144,7 @@ namespace lgfx __attribute__ ((always_inline)) inline static std::uint8_t color332(std::uint8_t r, std::uint8_t g, std::uint8_t b) { return (r >> 5) << 5 | (g >> 5) << 2 | b >> 6; } __attribute__ ((always_inline)) inline static std::uint16_t color565(std::uint8_t r, std::uint8_t g, std::uint8_t b) { return (r >> 3) <<11 | (g >> 2) << 5 | b >> 3; } __attribute__ ((always_inline)) inline static std::uint32_t color888(std::uint8_t r, std::uint8_t g, std::uint8_t b) { return r << 16 | g << 8 | b; } - __attribute__ ((always_inline)) inline static std::uint16_t swap565( std::uint8_t r, std::uint8_t g, std::uint8_t b) { return ((b >> 3) << 8) | ((g >> 2) << 13) | ((g >> 5) | ((r>>3)<<3)); } + __attribute__ ((always_inline)) inline static std::uint16_t swap565( std::uint8_t r, std::uint8_t g, std::uint8_t b) { r >>= 3; r = (r << 3) + (g >> 5); return r | (((g >> 2) << 5) | (b >> 3)) << 8; } __attribute__ ((always_inline)) inline static std::uint32_t swap888( std::uint8_t r, std::uint8_t g, std::uint8_t b) { return (b << 16) | (g << 8) | r; } __attribute__ ((always_inline)) inline static std::uint16_t getSwap16(std::uint16_t c) { return __builtin_bswap16(c); } @@ -672,7 +672,7 @@ namespace lgfx //inline swap565_t::operator bgr888_t() const { return operator rgb565_t(); } inline rgb332_t& rgb332_t::operator=(const rgb565_t& rhs) { raw = ((rhs.r<<3)&0xE0) | ((rhs.g>>1)&0x1C) | (rhs.b>>3); return *this; } - inline rgb332_t& rgb332_t::operator=(const swap565_t& rhs) { raw = ((rhs.r<<3)&0xE0) | (rhs.gh<<2) | (rhs.b>>3); return *this; } + inline rgb332_t& rgb332_t::operator=(const swap565_t& rhs) { raw = ((rhs.r<<3)&0xE0) | ((rhs.gh<<2) + (rhs.b>>3)); return *this; } inline rgb332_t& rgb332_t::operator=(const bgr666_t& rhs) { raw = ((rhs.r<<2)&0xE0) | ((rhs.g>>1)&0x1C) | (rhs.b>>4); return *this; } inline rgb332_t& rgb332_t::operator=(const rgb888_t& rhs) { raw = color332(rhs.r, rhs.g, rhs.b); return *this; } inline rgb332_t& rgb332_t::operator=(const bgr888_t& rhs) { raw = color332(rhs.r, rhs.g, rhs.b); return *this; } diff --git a/src/lgfx/utility/lgfx_tjpgd.c b/src/lgfx/utility/lgfx_tjpgd.c index 853a49d8..6d649cba 100644 --- a/src/lgfx/utility/lgfx_tjpgd.c +++ b/src/lgfx/utility/lgfx_tjpgd.c @@ -251,32 +251,33 @@ static int32_t bitext ( /* >=0: extracted data, <0: error code */ uint_fast8_t nbit /* Number of bits to extract (1 to 11) */ ) { - uint8_t *dp, *dpend; - uint_fast8_t msk, s, shift; + uint8_t *dp; + uint_fast8_t msk, shift; uint32_t v; - msk = jd->dmsk; dp = jd->dptr; dpend = jd->dpend; - s = *dp; v = 0; + msk = jd->dmsk; dp = jd->dptr; + v = 0; for (;;) { if (!msk) { /* Next byte? */ - msk = 8; /* Read from MSB */ + uint8_t *dpend = jd->dpend; if (++dp == dpend) { /* No input data is available, re-fill input buffer */ dp = jd->inbuf; /* Top of input buffer */ jd->dpend = dpend = dp + jd->infunc(jd, dp, JD_SZBUF); if (dp == dpend) return 0 - (int32_t)JDR_INP; /* Err: read error or wrong stream termination */ } - s = *dp; /* Get next data byte */ - if (s == 0xFF) { /* Is start of flag sequence? */ + if (*dp == 0xff) { /* Is start of flag sequence? */ if (++dp == dpend) { /* No input data is available, re-fill input buffer */ dp = jd->inbuf; /* Top of input buffer */ jd->dpend = dpend = dp + jd->infunc(jd, dp, JD_SZBUF); if (dp == dpend) return 0 - (int32_t)JDR_INP; /* Err: read error or wrong stream termination */ } if (*dp != 0) return 0 - (int32_t)JDR_FMT1; /* Err: unexpected flag is detected (may be collapted data) */ - *dp = s; /* The flag is a data 0xFF */ + *dp = 0xff; /* The flag is a data 0xFF */ } + msk = 8; /* Read from MSB */ } + uint_fast8_t s = *dp; /* Get next data byte */ if (msk >= nbit) { msk -= nbit; jd->dmsk = msk; jd->dptr = dp; @@ -300,32 +301,33 @@ static int32_t huffext ( /* >=0: decoded data, <0: error code */ const uint8_t* hdata /* Pointer to the data table */ ) { - uint8_t *dp, *dpend; - uint_fast8_t msk, s, bl; + uint8_t *dp; + uint_fast8_t msk, bl; uint32_t v; - msk = jd->dmsk; dp = jd->dptr; dpend = jd->dpend; - s = *dp; v = 0; + msk = jd->dmsk; dp = jd->dptr; + v = 0; bl = 16; /* Max code length */ for (;;) { if (!msk) { /* Next byte? */ - msk = 8; /* Read from MSB */ + uint8_t *dpend = jd->dpend; if (++dp == dpend) { /* No input data is available, re-fill input buffer */ dp = jd->inbuf; /* Top of input buffer */ jd->dpend = dpend = dp + jd->infunc(jd, dp, JD_SZBUF); if (dp == dpend) return 0 - (int32_t)JDR_INP; /* Err: read error or wrong stream termination */ } - s = *dp; /* Get next data byte */ - if (s == 0xFF) { /* Is start of flag sequence? */ + if (*dp == 0xff) { /* Is start of flag sequence? */ if (++dp == dpend) { /* No input data is available, re-fill input buffer */ dp = jd->inbuf; /* Top of input buffer */ jd->dpend = dpend = dp + jd->infunc(jd, dp, JD_SZBUF); if (dp == dpend) return 0 - (int32_t)JDR_INP; /* Err: read error or wrong stream termination */ } if (*dp != 0) return 0 - (int32_t)JDR_FMT1; /* Err: unexpected flag is detected (may be collapted data) */ - *dp = s; /* The flag is a data 0xFF */ + *dp = 0xff; /* The flag is a data 0xFF */ } + msk = 8; /* Read from MSB */ } + uint_fast8_t s = *dp; /* Get next data byte */ do { v = (v << 1) + ((s >> (--msk)) & 1); /* Get a bit */ size_t nd = *++hbits; @@ -636,7 +638,6 @@ static JRESULT mcu_output ( #else yy = py[ix]; /* Get Y component */ #endif - /* Convert YCbCr to RGB */ rgb24[ix*3 ] = BYTECLIP(yy + rr); rgb24[ix*3+1] = BYTECLIP(yy - gg); From c3e18056b1c219984b388f53c2ad938444564b6a Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Sun, 12 Jul 2020 14:36:55 +0900 Subject: [PATCH 03/19] bugfix --- examples/Sprite/MovingIcons/Alert.h | 5 +---- examples/Sprite/MovingIcons/Close.h | 5 +---- examples/Sprite/MovingIcons/Info.h | 5 +---- examples/Sprite/MovingIcons/MovingIcons.ino | 2 +- 4 files changed, 4 insertions(+), 13 deletions(-) diff --git a/examples/Sprite/MovingIcons/Alert.h b/examples/Sprite/MovingIcons/Alert.h index d52ec0e4..c4a9a2e3 100644 --- a/examples/Sprite/MovingIcons/Alert.h +++ b/examples/Sprite/MovingIcons/Alert.h @@ -1,11 +1,8 @@ -// We need this header file to use FLASH as storage with PROGMEM directive: -#include - // Icon width and height const uint16_t alertWidth = 32; const uint16_t alertHeight = 32; -const unsigned short alert[1024] PROGMEM={ +static constexpr unsigned short alert[1024] ={ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0840,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 0, 32 pixels 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x1080,0xAC66,0xEDE8,0xFE69,0xC4C6,0x2901,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 1, 64 pixels 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xBCC6,0xFE68,0xFE68,0xFE6A,0xFE68,0xEDE8,0x18A1,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 2, 96 pixels diff --git a/examples/Sprite/MovingIcons/Close.h b/examples/Sprite/MovingIcons/Close.h index 34d4282d..b30078cb 100644 --- a/examples/Sprite/MovingIcons/Close.h +++ b/examples/Sprite/MovingIcons/Close.h @@ -1,11 +1,8 @@ -// We need this header file to use FLASH as storage with PROGMEM directive: -#include - // Icon width and height const uint16_t closeWidth = 32; const uint16_t closeHeight = 32; -const unsigned short closeX[1024] PROGMEM={ +static constexpr unsigned short closeX[1024] ={ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x30C3,0x4124,0x61C7,0x61C7,0x4124,0x30E3,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 0, 32 pixels 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x48E3,0xA249,0xEB8E,0xFCB2,0xFD14,0xFD75,0xFD96,0xFD34,0xFCF3,0xEBEF,0xA28A,0x4904,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 1, 64 pixels 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x58E3,0xC228,0xFC10,0xFD34,0xFE18,0xFE59,0xFE79,0xFE9A,0xFE9A,0xFE9A,0xFE9A,0xFE59,0xFD75,0xFC51,0xC28A,0x5904,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 2, 96 pixels diff --git a/examples/Sprite/MovingIcons/Info.h b/examples/Sprite/MovingIcons/Info.h index 5a57f4aa..63b3541b 100644 --- a/examples/Sprite/MovingIcons/Info.h +++ b/examples/Sprite/MovingIcons/Info.h @@ -1,11 +1,8 @@ -// We need this header file to use FLASH as storage with PROGMEM directive: -#include - // Icon width and height const uint16_t infoWidth = 32; const uint16_t infoHeight = 32; -const unsigned short info[1024] PROGMEM={ +static constexpr unsigned short info[1024] ={ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 0, 32 pixels 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0861,0x4A69,0x8C71,0xA514,0xBDF7,0xBDF7,0xA514,0x8C71,0x4A69,0x0861,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 1, 64 pixels 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x39E7,0x9CF3,0xEF7D,0xF79E,0xFFDF,0xFFDF,0xFFDF,0xFFDF,0xFFDF,0xFFDF,0xF79E,0xEF7D,0x9CF3,0x39E7,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 2, 96 pixels diff --git a/examples/Sprite/MovingIcons/MovingIcons.ino b/examples/Sprite/MovingIcons/MovingIcons.ino index 01f0f74a..ace8385c 100644 --- a/examples/Sprite/MovingIcons/MovingIcons.ino +++ b/examples/Sprite/MovingIcons/MovingIcons.ino @@ -125,7 +125,7 @@ void loop(void) if (y == 0) { sprites[flip].setCursor(0,0); - sprites[flip].setTextFont(4); + sprites[flip].setFont(&fonts::Font4); sprites[flip].setTextColor(0xFFFFFFU); sprites[flip].printf("obj:%d fps:%d", obj_count, fps); } From 7a12ef527f4d6f5da36d52b469ae3979544de794 Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Sun, 12 Jul 2020 14:42:49 +0900 Subject: [PATCH 04/19] bugfix --- examples/Sprite/MovingIcons/MovingIcons.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Sprite/MovingIcons/MovingIcons.ino b/examples/Sprite/MovingIcons/MovingIcons.ino index ace8385c..867faec5 100644 --- a/examples/Sprite/MovingIcons/MovingIcons.ino +++ b/examples/Sprite/MovingIcons/MovingIcons.ino @@ -133,7 +133,7 @@ void loop(void) if (y + sprite_height > tft_height) { len = (tft_height - y) * tft_width; } - lcd.pushPixelsDMA(sprites[flip].getBuffer(), len); + lcd.pushPixelsDMA((uint16_t*)sprites[flip].getBuffer(), len); } ++frame_count; From 66df8ca2a9002960519ec2855259f323cf51cccb Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Sun, 12 Jul 2020 17:43:58 +0900 Subject: [PATCH 05/19] add english comment. --- .../HowToUse/2_spi_setting/2_spi_setting.ino | 81 ++++++++++++++----- 1 file changed, 60 insertions(+), 21 deletions(-) diff --git a/examples/HowToUse/2_spi_setting/2_spi_setting.ino b/examples/HowToUse/2_spi_setting/2_spi_setting.ino index 7993fb20..a72ca522 100644 --- a/examples/HowToUse/2_spi_setting/2_spi_setting.ino +++ b/examples/HowToUse/2_spi_setting/2_spi_setting.ino @@ -1,34 +1,48 @@ +// How to set up the SPI with LovyanGFX // LovyanGFX SPIバスおよび使用パネルの設定を伴う使い方 -// ヘッダをincludeします。 -#include +#include -// SPI設定用の構造体を用意します。 -// 構造体の名称 "LGFX_Config" は変更しても構いませんが、 -// 構造体の各メンバ変数の名前と型は例の通りにしてください。 +// Create a structure for SPI configuration +// SPI設定用の構造体を作成します。 // for ESP32 struct LGFX_Config { +// You can change the name of the structure from "LGFX_Config" +// But do not change the name and type of the members. +// 構造体の名称 "LGFX_Config" は変更しても構いませんが、 +// 構造体の各メンバ変数の名前と型は例の通りにしてください。 + + // Select the type of SPI (VSPI_HOST or HSPI_HOST) // 使用するSPIを VSPI_HOST または HSPI_HOST で設定します。 static constexpr spi_host_device_t spi_host = VSPI_HOST; + // Set the DMA channel number (1 or 2) + // If you don't want to use DMA, omit it or set it to 0. // 使用するDMAチャンネルを 1か2で設定します。 // 使用しない場合は省略するか0を設定します。 static constexpr int dma_channel = 1; + // Set the SPI SCLK pin number // SPIのSCLKのピン番号を設定します。 static constexpr int spi_sclk = 18; + // Set the SPI MOSI pin number // SPIのMOSIのピン番号を設定します。 static constexpr int spi_mosi = 23; + // Set the SPI MISO pin number + // If you share the SPI bus with an SD card, be sure to set up MISO as well. + // If you don't want to use MISO, omit it or set it to -1. // SPIのMISOのピン番号を設定します。 // SDカード等と共通のSPIバスを使う場合はMISOも必ず設定してください。 // 使わない場合は省略するか-1を設定します。 static constexpr int spi_miso = 19; + // Set the data length of SPI communication. + // If you want to use the LCD for RPi, set it to 16. // SPI通信のデータ長を指定します。 // RaspberryPi用のLCD等を使用する場合に16を指定します。 // 省略時は 8 です。大抵のパネルは8ですので、基本的には省略してください。 @@ -40,7 +54,7 @@ struct LGFX_Config struct LGFX_Config { // 使用するSPIのSERCOM番号を設定します。 - static constexpr int sercom_index = 7; + static constexpr int sercom_index = 5; // SERCOMのクロックソースを設定します。 // -1を指定した場合、クロックソースを設定せずに動作しますので別途設定を行ってください。 @@ -49,21 +63,24 @@ struct LGFX_Config // 上記で設定したクロックソースの動作周波数を設定します。 // Harmony等で行った設定値をそのまま設定してください。 static constexpr int sercom_clkfreq = 120000000; +//static constexpr int sercom_clkfreq = F_CPU; // Seeeduino環境ではF_CPU定数でCPUクロック値が利用できます。 + +// SAMD51でのピン番号の設定はArduino向けの番号ではなく、SAMD51のポート+ピン番号で設定します。 // SPIのSCLKのピン番号を設定します。 PORTA=0x000 / PORTB=0x100 / PORTC=0x200 / PORTD=0x300… - static constexpr int spi_sclk = 0x0100 | 20; // PORTB 20 (PORTB=0x0100) + static constexpr int spi_sclk = 0x0100 | 3; // PORTB 3 (PORTB=0x0100) // SPIのMOSIのピン番号を設定します。 - static constexpr int spi_mosi = 0x0100 | 19; // PORTB 19 (PORTB=0x0100) + static constexpr int spi_mosi = 0x0100 | 2; // PORTB 2 (PORTB=0x0100) // SPIのMISOのピン番号を設定します。 - static constexpr int spi_miso = 0x0100 | 18; // PORTB 18 (PORTB=0x0100) + static constexpr int spi_miso = 0x0100 | 0; // PORTB 0 (PORTB=0x0100) // SPIで使用するTX Padを設定します。 - static constexpr SercomSpiTXPad pad_mosi = SPI_PAD_3_SCK_1; // PAD_SPI3_TX; + static constexpr SercomSpiTXPad pad_mosi = SPI_PAD_0_SCK_1; // PAD_SPI0_TX; // SPIで使用するRX Padを設定します。 - static constexpr SercomRXPad pad_miso = SERCOM_RX_PAD_2; // PAD_SPI3_RX; + static constexpr SercomRXPad pad_miso = SERCOM_RX_PAD_2; // PAD_SPI0_RX; // SPI通信のデータ長を指定します。 // RaspberryPi用のLCD等を使用する場合に16を指定します。 @@ -72,11 +89,12 @@ struct LGFX_Config }; //*/ - +// Create an LGFX_SPI instance with the configuration structure you just created as a template argument. // 用意した設定用の構造体を、LGFX_SPIクラスにテンプレート引数として設定し、インスタンスを作成します。 static lgfx::LGFX_SPI lcd; +// Create an instance of the Panel class. Comment out the description of the panel you want to use. // Panelクラスのインスタンスを作成します。使用するパネルにあった記述をコメントアウトしてください。 //static lgfx::Panel_HX8357B panel; //static lgfx::Panel_HX8357D panel; @@ -93,102 +111,123 @@ static lgfx::Panel_ILI9342 panel; void setup(void) { - +// Assign various setting values to the panel class. // パネルクラスに各種設定値を代入していきます。 -// (LCD一体型製品のパネルクラスを選択した場合は、 -// 製品に合った初期値が設定されているので設定は不要です) + // Set the SPI clock for normal write operation. // 通常動作時のSPIクロックを設定します。 // ESP32のSPIは80MHzを整数で割った値のみ使用可能です。 // 設定した値に一番近い設定可能な値が使用されます。 panel.freq_write = 20000000; + // Set the SPI clock for fill write operation. + // It may work even if you set the clock higher than freq_write. // 単色の塗り潰し処理時のSPIクロックを設定します。 // 基本的にはfreq_writeと同じ値を設定しますが、 // より高い値を設定しても動作する場合があります。 panel.freq_fill = 27000000; + // Set the SPI clock for read operation. // LCDから画素データを読取る際のSPIクロックを設定します。 panel.freq_read = 16000000; + // Set the SPI mode. (0~3) // SPI通信モードを0~3から設定します。 panel.spi_mode = 0; + // Set the SPI mode when read operation. (0~3) // データ読み取り時のSPI通信モードを0~3から設定します。 panel.spi_mode_read = 0; + // Sets the number of dummy bits for pixel readout. // 画素読出し時のダミービット数を設定します。 // 画素読出しでビットずれが起きる場合に調整してください。 panel.len_dummy_read_pixel = 8; - // データの読取りが可能なパネルの場合はtrueを、不可の場合はfalseを設定します。 + // Set the readability of the data. If reading of the data is not possible, set false. + // データの読取りの可否を設定します。読取り不可の場合はfalseを設定します。 // ※ CSピンのないST7789等はfalseにしてください。 // 省略時はtrueになります。 panel.spi_read = true; + // Set to "true" for a panel that uses MOSI pins to read data. // データの読取りMOSIピンで行うパネルの場合はtrueを設定します。 // 省略時はfalseになります。 panel.spi_3wire = false; + // Set the SPI CS pin number. // LCDのCSを接続したピン番号を設定します。 // 使わない場合は省略するか-1を設定します。 panel.spi_cs = 14; - // LCDのDCを接続したピン番号を設定します。 + // Set the SPI D/C pin number. + // LCDのD/Cを接続したピン番号を設定します。 panel.spi_dc = 27; + // Set the reset pin number. // LCDのRSTを接続したピン番号を設定します。 // 使わない場合は省略するか-1を設定します。 panel.gpio_rst = 33; + // Set the backlight pin number. // LCDのバックライトを接続したピン番号を設定します。 // 使わない場合は省略するか-1を設定します。 panel.gpio_bl = 32; + // Set the backlight control PWM channel number. // バックライト使用時、輝度制御に使用するPWMチャンネル番号を設定します。 // PWM輝度制御を使わない場合は省略するか-1を設定します。 panel.pwm_ch_bl = 7; + // Set the backlight level (rue=turns on HIGH / false=turns on LOW) // バックライト点灯時の出力レベルがローかハイかを設定します。 // 省略時は true。true=HIGHで点灯 / false=LOWで点灯になります。 panel.backlight_level = true; + // Set the panel color inversion. // invertDisplayの初期値を設定します。trueを設定すると反転します。 // 省略時は false。画面の色が反転している場合は設定を変更してください。 panel.invert = false; + // Set the RGB/BGR color order. // パネルの色順がを設定します。 RGB=true / BGR=false // 省略時はfalse。赤と青が入れ替わっている場合は設定を変更してください。 panel.rgb_order = false; - // LCDコントローラのメモリ上のピクセル数(幅と高さ)を設定します。 + // Set the internal memory size of the LCD driver. + // LCDドライバチップ内のメモリサイズ(幅と高さ)を設定します。 // 設定が合っていない場合、setRotationを使用した際の座標がずれます。 // (例:ST7735は 132x162 / 128x160 / 132x132 の3通りが存在します) panel.memory_width = 320; panel.memory_height = 240; + // Set the size of the pixels that can be displayed on the LCD panel. // パネルが実際に表示可能なピクセル数(幅と高さ)を設定します。 // 省略時はパネルクラスのデフォルト値が使用されます。 panel.panel_width = 320; panel.panel_height = 240; + // Set the number of offset pixels. // パネルのオフセット量を設定します。 // 省略時はパネルクラスのデフォルト値が使用されます。 panel.offset_x = 0; panel.offset_y = 0; + // Set the default rotation number. // setRotationの初期化直後の値を設定します。 panel.rotation = 0; + // Set the number of rotation offset number. // setRotationを使用した時の向きを変更したい場合、offset_rotationを設定します。 // setRotation(0)での向きを 1の時の向きにしたい場合、 1を設定します。 panel.offset_rotation = 0; - - // 設定を終えたら、LGFXのsetPanel関数でパネルのポインタを渡します。 + // After setting up, you can pass the panel pointer to the lcd.setPanel function. + // 設定を終えたら、lcdのsetPanel関数でパネルのポインタを渡します。 lcd.setPanel(&panel); - // SPIバスの初期化とパネルの初期化を実行すると使用可能になります。 + // Initializing the SPI bus and panel will make it available. + // SPIバスとパネルの初期化を実行すると使用可能になります。 lcd.init(); From 839a6e74a58ffe8b0c4b1c2231f4d2a61cde8e46 Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Sun, 12 Jul 2020 22:49:18 +0900 Subject: [PATCH 06/19] bugfix: Crash when certain angles were specified for pushRotate and pushRotateZoom. --- src/lgfx/LGFXBase.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/lgfx/LGFXBase.cpp b/src/lgfx/LGFXBase.cpp index cea6c1f3..87c9e064 100644 --- a/src/lgfx/LGFXBase.cpp +++ b/src/lgfx/LGFXBase.cpp @@ -1059,7 +1059,7 @@ namespace lgfx std::int32_t scale_w = w << FP_SCALE; std::int32_t xs1 = (cos_x < 0 ? - scale_w : 1) - cos_x; std::int32_t xs2 = (cos_x < 0 ? 0 : (1 - scale_w)) - cos_x; - if (cos_x == 0) cos_x = 1; +// if (cos_x == 0) cos_x = 1; cos_x = -cos_x; std::int32_t sin_y = round(sin_f / zoom_y); @@ -1069,7 +1069,7 @@ namespace lgfx std::int32_t scale_h = h << FP_SCALE; std::int32_t ys1 = (sin_y < 0 ? - scale_h : 1) - sin_y; std::int32_t ys2 = (sin_y < 0 ? 0 : (1 - scale_h)) - sin_y; - if (sin_y == 0) sin_y = 1; +// if (sin_y == 0) sin_y = 1; sin_y = -sin_y; std::int32_t cl = _clip_l; @@ -1080,21 +1080,22 @@ namespace lgfx std::int32_t left = cl; std::int32_t right = cr; xstart += sin_x; - //if (cos_x != 0) + if (cos_x != 0) { std::int32_t tmp = (xstart + xs1) / cos_x; if (left < tmp) left = tmp; - tmp = (xstart + xs2) / cos_x; if (right > tmp) right = tmp; + tmp = (xstart + xs2) / cos_x; if (right > tmp) right = tmp; } ystart += cos_y; - //if (sin_y != 0) + if (sin_y != 0) { std::int32_t tmp = (ystart + ys1) / sin_y; if (left < tmp) left = tmp; - tmp = (ystart + ys2) / sin_y; if (right > tmp) right = tmp; + tmp = (ystart + ys2) / sin_y; if (right > tmp) right = tmp; } if (left < right) { - param->src_x32 = xstart - left * cos_x; + std::int32_t x32 = xstart - left * cos_x; std::int32_t y32 = ystart - left * sin_y; - if (y32 >= 0) { + if (x32 >= 0 && y32 >= 0) { + param->src_x32 = x32; param->src_y32 = y32; pushImage_impl(left, min_y, right - left, 1, param, true); } From ce502a6a6727657884f927cb858b63ed5e06f5e3 Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Sun, 12 Jul 2020 23:46:28 +0900 Subject: [PATCH 07/19] bugfix: Crash when certain angles were specified for pushRotate and pushRotateZoom. --- src/lgfx/LGFXBase.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lgfx/LGFXBase.cpp b/src/lgfx/LGFXBase.cpp index 87c9e064..f3fdedd0 100644 --- a/src/lgfx/LGFXBase.cpp +++ b/src/lgfx/LGFXBase.cpp @@ -1092,12 +1092,12 @@ namespace lgfx tmp = (ystart + ys2) / sin_y; if (right > tmp) right = tmp; } if (left < right) { - std::int32_t x32 = xstart - left * cos_x; - std::int32_t y32 = ystart - left * sin_y; - if (x32 >= 0 && y32 >= 0) { - param->src_x32 = x32; - param->src_y32 = y32; - pushImage_impl(left, min_y, right - left, 1, param, true); + param->src_x32 = xstart - left * cos_x; + if (param->src_x < param->src_width) { + param->src_y32 = ystart - left * sin_y; + if (param->src_y < h) { + pushImage_impl(left, min_y, right - left, 1, param, true); + } } } } while (++min_y != max_y); From 648666fae34b43488ea537600ad10a7b2fed4f60 Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Mon, 13 Jul 2020 18:07:04 +0900 Subject: [PATCH 08/19] bugfix. --- src/lgfx/platforms/samd51_common.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lgfx/platforms/samd51_common.hpp b/src/lgfx/platforms/samd51_common.hpp index 25cdc3b4..7f99ce79 100644 --- a/src/lgfx/platforms/samd51_common.hpp +++ b/src/lgfx/platforms/samd51_common.hpp @@ -6,6 +6,7 @@ #include #ifdef ARDUINO #include +#include #else #include From beb2f460396ed4c4de1f24c576e19019e7ab897c Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Fri, 17 Jul 2020 16:39:03 +0900 Subject: [PATCH 09/19] update: Speed up drawJpg. --- src/lgfx/platforms/LGFX_SPI_ESP32.hpp | 42 ++++++++++++++++----------- src/lgfx/utility/lgfx_tjpgd.c | 30 ++++++++++--------- 2 files changed, 41 insertions(+), 31 deletions(-) diff --git a/src/lgfx/platforms/LGFX_SPI_ESP32.hpp b/src/lgfx/platforms/LGFX_SPI_ESP32.hpp index a50b591e..81caeaf3 100644 --- a/src/lgfx/platforms/LGFX_SPI_ESP32.hpp +++ b/src/lgfx/platforms/LGFX_SPI_ESP32.hpp @@ -749,6 +749,7 @@ namespace lgfx auto fp_copy = param->fp_copy; std::int32_t xr = (x + w) - 1; + std::int32_t whb = w * h * bytes; if (param->transp == ~0) { if (param->no_convert) { setWindow_impl(x, y, xr, y + h - 1); @@ -761,20 +762,19 @@ namespace lgfx _setup_dma_desc_links(src, w * bytes, h, param->src_width * bytes); } dc_h(); - set_write_len(w * h * bytes << 3); + set_write_len(whb << 3); *reg(SPI_DMA_OUT_LINK_REG(_spi_port)) = SPI_OUTLINK_START | ((int)(&_dmadesc[0]) & 0xFFFFF); spi_dma_transfer_active(_dma_channel); exec_spi(); return; } if (param->src_width == w) { - std::int32_t len = w * h * bytes; - if (_dma_channel && !use_dma && (64 < len) && (len <= 1024)) { - auto buf = get_dmabuffer(len); - memcpy(buf, src, len); - write_bytes(buf, len, true); + if (_dma_channel && !use_dma && (64 < whb) && (whb <= 1024)) { + auto buf = get_dmabuffer(whb); + memcpy(buf, src, whb); + write_bytes(buf, whb, true); } else { - write_bytes(src, len, use_dma); + write_bytes(src, whb, use_dma); } } else { auto add = param->src_width * bytes; @@ -784,17 +784,25 @@ namespace lgfx } while (--h); } } else - if (_dma_channel && use_dma) { - auto buf = get_dmabuffer(w * bytes); - fp_copy(buf, 0, w, param); - setWindow_impl(x, y, xr, y + h - 1); - write_bytes(buf, w * bytes, use_dma); - while (--h) { - param->src_x = src_x; - param->src_y++; - buf = get_dmabuffer(w * bytes); + if (_dma_channel && (64 < whb)) { + if (param->src_width == w && (whb <= 1024)) { + auto buf = get_dmabuffer(whb); + fp_copy(buf, 0, w * h, param); + setWindow_impl(x, y, xr, y + h - 1); + write_bytes(buf, whb, true); + } else { + std::int32_t wb = w * bytes; + auto buf = get_dmabuffer(wb); fp_copy(buf, 0, w, param); - write_bytes(buf, w * bytes, use_dma); + setWindow_impl(x, y, xr, y + h - 1); + write_bytes(buf, wb, true); + while (--h) { + param->src_x = src_x; + param->src_y++; + buf = get_dmabuffer(wb); + fp_copy(buf, 0, w, param); + write_bytes(buf, wb, true); + } } } else { setWindow_impl(x, y, xr, y + h - 1); diff --git a/src/lgfx/utility/lgfx_tjpgd.c b/src/lgfx/utility/lgfx_tjpgd.c index 6d649cba..d79397bb 100644 --- a/src/lgfx/utility/lgfx_tjpgd.c +++ b/src/lgfx/utility/lgfx_tjpgd.c @@ -334,15 +334,16 @@ static int32_t huffext ( /* >=0: decoded data, <0: error code */ if (nd) { do { /* Search the code word in this bit length */ ++hdata; - } while (v != *++hcode && --nd); /* Matched? */ - if (nd) { /* Matched? */ - jd->dmsk = msk; jd->dptr = dp; - return *hdata; /* Return the decoded data */ - } + if (v == *++hcode) goto huffext_match; /* Matched? */ + } while (--nd); } if (!--bl) return 0 - (int32_t)JDR_FMT1; /* Err: code not found (may be collapted data) */ } while (msk); } +huffext_match: + jd->dmsk = msk; + jd->dptr = dp; + return *hdata; /* Return the decoded data */ } @@ -623,9 +624,9 @@ static JRESULT mcu_output ( ix = 0; do { do { - size_t idx = ix >> ixshift; - cb = (pc[idx] - 128); /* Get Cb/Cr component and restore right level */ - cr = (pc[idx + 64] - 128); + cb = (pc[ 0] - 128); /* Get Cb/Cr component and restore right level */ + cr = (pc[64] - 128); + ++pc; /* Convert CbCr to RGB */ uint_fast16_t rr = ((int32_t)(1.402 * (1<> FP_SHIFT; @@ -634,19 +635,20 @@ static JRESULT mcu_output ( uint_fast16_t bb = ((int32_t)(1.772 * (1<> FP_SHIFT; do { #if JD_BAYER - yy = py[ix] + btbl[ix & 3]; /* Get Y component */ + yy = *py + btbl[ix & 3]; /* Get Y component */ #else - yy = py[ix]; /* Get Y component */ + yy = *py; /* Get Y component */ #endif + ++py; /* Convert YCbCr to RGB */ - rgb24[ix*3 ] = BYTECLIP(yy + rr); - rgb24[ix*3+1] = BYTECLIP(yy - gg); - rgb24[ix*3+2] = BYTECLIP(yy + bb); + rgb24[0] = BYTECLIP(yy + rr); + rgb24[1] = BYTECLIP(yy - gg); + rgb24[2] = BYTECLIP(yy + bb); + rgb24 += 3; } while (++ix & ixshift); } while (ix & 7); py += 64 - 8; /* Jump to next block if double block heigt */ } while (ix != mx); - rgb24 += ix * 3; } while (++iy < my); /* Descale the MCU rectangular if needed */ From c13c9179b67bb2a306f8923a58b741e425737ac5 Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Fri, 17 Jul 2020 23:33:02 +0900 Subject: [PATCH 10/19] add dmaBusy --- src/lgfx/LGFXBase.hpp | 2 ++ src/lgfx/LGFX_Sprite.hpp | 1 + src/lgfx/platforms/LGFX_SPI_ESP32.hpp | 5 +++++ src/lgfx/platforms/LGFX_SPI_SAMD51.hpp | 5 +++++ 4 files changed, 13 insertions(+) diff --git a/src/lgfx/LGFXBase.hpp b/src/lgfx/LGFXBase.hpp index 8a58bb5f..6236ea6d 100644 --- a/src/lgfx/LGFXBase.hpp +++ b/src/lgfx/LGFXBase.hpp @@ -141,6 +141,7 @@ namespace lgfx __attribute__ ((always_inline)) inline void endTransaction(void) { endTransaction_impl(); } __attribute__ ((always_inline)) inline void initDMA(void) { } // TFT_eSPI compatible __attribute__ ((always_inline)) inline void waitDMA(void) { waitDMA_impl(); } + __attribute__ ((always_inline)) inline bool dmaBusy(void) { return dmaBusy_impl(); } __attribute__ ((always_inline)) inline void setWindow(std::int32_t xs, std::int32_t ys, std::int32_t xe, std::int32_t ye) { setWindow_impl(xs, ys, xe, ye); } void setSPIShared(bool shared) { _spi_shared = shared; } @@ -521,6 +522,7 @@ namespace lgfx virtual void beginTransaction_impl(void) = 0; virtual void endTransaction_impl(void) = 0; virtual void waitDMA_impl(void) = 0; + virtual bool dmaBusy_impl(void) = 0; virtual void pushPixelsDMA_impl(const void* data, std::int32_t length) = 0; virtual void drawPixel_impl(std::int32_t x, std::int32_t y) = 0; diff --git a/src/lgfx/LGFX_Sprite.hpp b/src/lgfx/LGFX_Sprite.hpp index 7f3fc365..a3484560 100644 --- a/src/lgfx/LGFX_Sprite.hpp +++ b/src/lgfx/LGFX_Sprite.hpp @@ -789,6 +789,7 @@ return; void beginTransaction_impl(void) override {} void endTransaction_impl(void) override {} void waitDMA_impl(void) override {} + bool dmaBusy_impl(void) override { return false; } inline std::int32_t ptr_advance(std::int32_t length = 1) { if ((_xptr += length) > _xe) { diff --git a/src/lgfx/platforms/LGFX_SPI_ESP32.hpp b/src/lgfx/platforms/LGFX_SPI_ESP32.hpp index a50b591e..87a91ac4 100644 --- a/src/lgfx/platforms/LGFX_SPI_ESP32.hpp +++ b/src/lgfx/platforms/LGFX_SPI_ESP32.hpp @@ -468,6 +468,11 @@ namespace lgfx #endif } + bool dmaBusy_impl(void) override + { + return *reg(SPI_CMD_REG(_spi_port)) & SPI_USR; + } + void waitDMA_impl(void) override { wait_spi(); diff --git a/src/lgfx/platforms/LGFX_SPI_SAMD51.hpp b/src/lgfx/platforms/LGFX_SPI_SAMD51.hpp index 26f3be71..401c871f 100644 --- a/src/lgfx/platforms/LGFX_SPI_SAMD51.hpp +++ b/src/lgfx/platforms/LGFX_SPI_SAMD51.hpp @@ -636,6 +636,11 @@ void disableSPI() cs_h(); } + bool dmaBusy_impl(void) override + { + return _need_wait && (_sercom->SPI.INTFLAG.bit.TXC == 0); + } + void waitDMA_impl(void) override { wait_spi(); From 84adb4770766dbc536c0efc3c49f53f28290e817 Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Sat, 18 Jul 2020 10:41:23 +0900 Subject: [PATCH 11/19] update: Adjusting the initialization function of SPI_DMA. --- src/lgfx/LGFXBase.hpp | 3 ++- src/lgfx/LGFX_Sprite.hpp | 1 + src/lgfx/platforms/LGFX_SPI_ESP32.hpp | 12 ++++++++++-- src/lgfx/platforms/LGFX_SPI_SAMD51.hpp | 10 ++++++---- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/lgfx/LGFXBase.hpp b/src/lgfx/LGFXBase.hpp index 6236ea6d..796296d2 100644 --- a/src/lgfx/LGFXBase.hpp +++ b/src/lgfx/LGFXBase.hpp @@ -139,7 +139,7 @@ namespace lgfx __attribute__ ((always_inline)) inline void beginTransaction(void) { beginTransaction_impl(); } __attribute__ ((always_inline)) inline void endTransaction(void) { endTransaction_impl(); } - __attribute__ ((always_inline)) inline void initDMA(void) { } // TFT_eSPI compatible + __attribute__ ((always_inline)) inline void initDMA(void) { initDMA_impl(); } __attribute__ ((always_inline)) inline void waitDMA(void) { waitDMA_impl(); } __attribute__ ((always_inline)) inline bool dmaBusy(void) { return dmaBusy_impl(); } __attribute__ ((always_inline)) inline void setWindow(std::int32_t xs, std::int32_t ys, std::int32_t xe, std::int32_t ye) { setWindow_impl(xs, ys, xe, ye); } @@ -521,6 +521,7 @@ namespace lgfx virtual void beginTransaction_impl(void) = 0; virtual void endTransaction_impl(void) = 0; + virtual void initDMA_impl(void) = 0; virtual void waitDMA_impl(void) = 0; virtual bool dmaBusy_impl(void) = 0; virtual void pushPixelsDMA_impl(const void* data, std::int32_t length) = 0; diff --git a/src/lgfx/LGFX_Sprite.hpp b/src/lgfx/LGFX_Sprite.hpp index a3484560..b284e77d 100644 --- a/src/lgfx/LGFX_Sprite.hpp +++ b/src/lgfx/LGFX_Sprite.hpp @@ -788,6 +788,7 @@ return; void beginTransaction_impl(void) override {} void endTransaction_impl(void) override {} + void initDMA_impl(void) override {} void waitDMA_impl(void) override {} bool dmaBusy_impl(void) override { return false; } diff --git a/src/lgfx/platforms/LGFX_SPI_ESP32.hpp b/src/lgfx/platforms/LGFX_SPI_ESP32.hpp index c9c9b4fa..16918283 100644 --- a/src/lgfx/platforms/LGFX_SPI_ESP32.hpp +++ b/src/lgfx/platforms/LGFX_SPI_ESP32.hpp @@ -468,9 +468,12 @@ namespace lgfx #endif } - bool dmaBusy_impl(void) override + void initDMA_impl(void) override { - return *reg(SPI_CMD_REG(_spi_port)) & SPI_USR; + if (_dma_channel) { + periph_module_reset( PERIPH_SPI_DMA_MODULE ); + _next_dma_reset = false; + } } void waitDMA_impl(void) override @@ -478,6 +481,11 @@ namespace lgfx wait_spi(); } + bool dmaBusy_impl(void) override + { + return *reg(SPI_CMD_REG(_spi_port)) & SPI_USR; + } + void setWindow_impl(std::int32_t xs, std::int32_t ys, std::int32_t xe, std::int32_t ye) override { if (_fill_mode) { diff --git a/src/lgfx/platforms/LGFX_SPI_SAMD51.hpp b/src/lgfx/platforms/LGFX_SPI_SAMD51.hpp index 401c871f..07e48ab4 100644 --- a/src/lgfx/platforms/LGFX_SPI_SAMD51.hpp +++ b/src/lgfx/platforms/LGFX_SPI_SAMD51.hpp @@ -636,16 +636,18 @@ void disableSPI() cs_h(); } - bool dmaBusy_impl(void) override - { - return _need_wait && (_sercom->SPI.INTFLAG.bit.TXC == 0); - } + void initDMA_impl(void) override {} void waitDMA_impl(void) override { wait_spi(); } + bool dmaBusy_impl(void) override + { + return _need_wait && (_sercom->SPI.INTFLAG.bit.TXC == 0); + } + void setWindow_impl(std::int32_t xs, std::int32_t ys, std::int32_t xe, std::int32_t ye) override { if (_fill_mode) { From f4dc80313c8adc7ba9c1fdaf4c00104328fae168 Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Sun, 19 Jul 2020 22:05:17 +0900 Subject: [PATCH 12/19] fix examples for ILI9488 --- .../Sprite/MovingCircles/MovingCircles.ino | 3 +- examples/Sprite/MovingIcons/MovingIcons.ino | 41 ++++++++++--------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/examples/Sprite/MovingCircles/MovingCircles.ino b/examples/Sprite/MovingCircles/MovingCircles.ino index 7709b02e..446fe354 100644 --- a/examples/Sprite/MovingCircles/MovingCircles.ino +++ b/examples/Sprite/MovingCircles/MovingCircles.ino @@ -70,6 +70,7 @@ void setup(void) sprite_height = (lcd_height + 2) / 3; for (std::uint32_t i = 0; i < 2; ++i) { + sprites[i].setColorDepth(lcd.getColorDepth()); sprites[i].createSprite(lcd_width, sprite_height); sprites[i].setFont(&fonts::Font2); } @@ -102,7 +103,7 @@ void loop(void) sprites[flip].setTextColor(TFT_WHITE); sprites[flip].printf("obj:%d fps:%d", obj_count, fps); } - std::int32_t len = sprites[flip].bufferLength() >> 1; + std::uint32_t len = sprite_height * lcd_width; if (y + sprite_height > lcd_height) { len = (lcd_height - y) * lcd_width; } diff --git a/examples/Sprite/MovingIcons/MovingIcons.ino b/examples/Sprite/MovingIcons/MovingIcons.ino index 867faec5..e8f43a93 100644 --- a/examples/Sprite/MovingIcons/MovingIcons.ino +++ b/examples/Sprite/MovingIcons/MovingIcons.ino @@ -10,8 +10,8 @@ static uint32_t sec, psec; static size_t fps = 0, frame_count = 0; -static uint32_t tft_width ; -static uint32_t tft_height; +static uint32_t lcd_width ; +static uint32_t lcd_height; struct obj_info_t { int_fast16_t x; @@ -31,16 +31,16 @@ struct obj_info_t { if (x < 0) { x = 0; if (dx < 0) dx = - dx; - } else if (x >= tft_width) { - x = tft_width -1; + } else if (x >= lcd_width) { + x = lcd_width -1; if (dx > 0) dx = - dx; } y += dy; if (y < 0) { y = 0; if (dy < 0) dy = - dy; - } else if (y >= tft_height) { - y = tft_height - 1; + } else if (y >= lcd_height) { + y = lcd_height - 1; if (dy > 0) dy = - dy; } z += dz; @@ -71,14 +71,14 @@ void setup(void) lcd.init(); - tft_width = lcd.width(); - tft_height = lcd.height(); + lcd_width = lcd.width(); + lcd_height = lcd.height(); obj_info_t *a; for (size_t i = 0; i < obj_count; ++i) { a = &objects[i]; a->img = i % 3; - a->x = random(tft_width); - a->y = random(tft_height); + a->x = random(lcd_width); + a->y = random(lcd_height); a->dx = random(1, 4) * (i & 1 ? 1 : -1); a->dy = random(1, 4) * (i & 2 ? 1 : -1); a->dr = random(1, 4) * (i & 2 ? 1 : -1); @@ -87,9 +87,12 @@ void setup(void) a->dz = (float)(random(1, 10)) / 100; } - sprite_height = (tft_height + 2) / 3; - sprites[0].createSprite(tft_width, sprite_height); - sprites[1].createSprite(tft_width, sprite_height); + sprite_height = (lcd_height + 2) / 3; + for (std::uint32_t i = 0; i < 2; ++i) + { + sprites[i].setColorDepth(lcd.getColorDepth()); + sprites[i].createSprite(lcd_width, sprite_height); + } icons[0].createSprite(infoWidth, infoHeight); icons[1].createSprite(alertWidth, alertHeight); @@ -104,7 +107,7 @@ void setup(void) icons[2].pushImage(0, 0, closeWidth, closeHeight, closeX); lcd.startWrite(); - lcd.setAddrWindow(0, 0, tft_width, tft_height); + lcd.setAddrWindow(0, 0, lcd_width, lcd_height); } void loop(void) @@ -115,7 +118,7 @@ void loop(void) for (int i = 0; i != obj_count; i++) { objects[i].move(); } - for (int_fast16_t y = 0; y < tft_height; y += sprite_height) { + for (int_fast16_t y = 0; y < lcd_height; y += sprite_height) { flip = flip ? 0 : 1; sprites[flip].clear(); for (size_t i = 0; i != obj_count; i++) { @@ -129,11 +132,11 @@ void loop(void) sprites[flip].setTextColor(0xFFFFFFU); sprites[flip].printf("obj:%d fps:%d", obj_count, fps); } - size_t len = sprites[flip].bufferLength() >> 1; - if (y + sprite_height > tft_height) { - len = (tft_height - y) * tft_width; + size_t len = sprite_height * lcd_width; + if (y + sprite_height > lcd_height) { + len = (lcd_height - y) * lcd_width; } - lcd.pushPixelsDMA((uint16_t*)sprites[flip].getBuffer(), len); + lcd.pushPixelsDMA(sprites[flip].getBuffer(), len); } ++frame_count; From 011026bce6340d33d45e7fc892a811d4416ac0df Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Mon, 20 Jul 2020 07:15:19 +0900 Subject: [PATCH 13/19] fix examples for ILI9488 --- examples/Sprite/CollisionCircles/CollisionCircles.ino | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/Sprite/CollisionCircles/CollisionCircles.ino b/examples/Sprite/CollisionCircles/CollisionCircles.ino index 8e110c6c..162ff93a 100644 --- a/examples/Sprite/CollisionCircles/CollisionCircles.ino +++ b/examples/Sprite/CollisionCircles/CollisionCircles.ino @@ -243,9 +243,12 @@ void setup(void) lcd.begin(); lcd.setBrightness(160); lcd.startWrite(); + if (lcd.width() < lcd.height()) lcd.setRotation(lcd.getRotation() ^ 1); auto lcd_width = lcd.width(); auto lcd_height = lcd.height(); + if (lcd_width > 320) lcd_width = 320; + if (lcd_height > 240) lcd_height = 240; for (std::uint32_t i = 0; i < 2; ++i) { From f8fd58ad0f5278b0445185ff31ac231afd2b5d6b Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Mon, 20 Jul 2020 15:48:24 +0900 Subject: [PATCH 14/19] fix examples for ILI9488 --- .../Sprite/MovingCircles/MovingCircles.ino | 26 +++++++++++++------ examples/Sprite/MovingIcons/MovingIcons.ino | 21 +++++++++++---- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/examples/Sprite/MovingCircles/MovingCircles.ino b/examples/Sprite/MovingCircles/MovingCircles.ino index 446fe354..a3f828fd 100644 --- a/examples/Sprite/MovingCircles/MovingCircles.ino +++ b/examples/Sprite/MovingCircles/MovingCircles.ino @@ -47,13 +47,13 @@ static int_fast16_t sprite_height; void setup(void) { - lcd.init(); - #if defined(ARDUINO_M5Stick_C) AXP192 axp; axp.begin(); #endif + lcd.init(); + lcd_width = lcd.width(); lcd_height = lcd.height(); obj_info_t *a; @@ -67,12 +67,22 @@ void setup(void) a->r = 8 + (i & 0x07); } - sprite_height = (lcd_height + 2) / 3; - for (std::uint32_t i = 0; i < 2; ++i) - { - sprites[i].setColorDepth(lcd.getColorDepth()); - sprites[i].createSprite(lcd_width, sprite_height); - sprites[i].setFont(&fonts::Font2); + uint32_t div = 2; + for (;;) { + sprite_height = (lcd_height + div - 1) / div; + bool fail = false; + for (std::uint32_t i = 0; !fail && i < 2; ++i) + { + sprites[i].setColorDepth(lcd.getColorDepth()); + sprites[i].setFont(&fonts::Font2); + fail = !sprites[i].createSprite(lcd_width, sprite_height); + } + if (!fail) break; + for (std::uint32_t i = 0; i < 2; ++i) + { + sprites[i].deleteSprite(); + } + ++div; } lcd.startWrite(); lcd.setAddrWindow(0, 0, lcd_width, lcd_height); diff --git a/examples/Sprite/MovingIcons/MovingIcons.ino b/examples/Sprite/MovingIcons/MovingIcons.ino index e8f43a93..7be17eeb 100644 --- a/examples/Sprite/MovingIcons/MovingIcons.ino +++ b/examples/Sprite/MovingIcons/MovingIcons.ino @@ -87,11 +87,22 @@ void setup(void) a->dz = (float)(random(1, 10)) / 100; } - sprite_height = (lcd_height + 2) / 3; - for (std::uint32_t i = 0; i < 2; ++i) - { - sprites[i].setColorDepth(lcd.getColorDepth()); - sprites[i].createSprite(lcd_width, sprite_height); + uint32_t div = 2; + for (;;) { + sprite_height = (lcd_height + div - 1) / div; + bool fail = false; + for (std::uint32_t i = 0; !fail && i < 2; ++i) + { + sprites[i].setColorDepth(lcd.getColorDepth()); + sprites[i].setFont(&fonts::Font2); + fail = !sprites[i].createSprite(lcd_width, sprite_height); + } + if (!fail) break; + for (std::uint32_t i = 0; i < 2; ++i) + { + sprites[i].deleteSprite(); + } + ++div; } icons[0].createSprite(infoWidth, infoHeight); From 97e4e01204daff8ed4fc86291fa1b4f3f5d65132 Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Mon, 20 Jul 2020 16:11:09 +0900 Subject: [PATCH 15/19] fix examples for ILI9488 --- .../CollisionCircles/CollisionCircles.ino | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/examples/Sprite/CollisionCircles/CollisionCircles.ino b/examples/Sprite/CollisionCircles/CollisionCircles.ino index 162ff93a..923ab44d 100644 --- a/examples/Sprite/CollisionCircles/CollisionCircles.ino +++ b/examples/Sprite/CollisionCircles/CollisionCircles.ino @@ -247,16 +247,47 @@ void setup(void) auto lcd_width = lcd.width(); auto lcd_height = lcd.height(); - if (lcd_width > 320) lcd_width = 320; - if (lcd_height > 240) lcd_height = 240; for (std::uint32_t i = 0; i < 2; ++i) { - _sprites[i].setColorDepth(8); - _sprites[i].createSprite(lcd_width, lcd_height); _sprites[i].setTextSize(2); - _sprites[i].setTextFont(&fonts::Font0); + _sprites[i].setColorDepth(8); + } + + bool fail = false; + for (std::uint32_t i = 0; !fail && i < 2; ++i) + { + fail = !_sprites[i].createSprite(lcd_width, lcd_height); + } + + if (fail) + { + fail = false; + for (std::uint32_t i = 0; !fail && i < 2; ++i) + { + _sprites[i].setPsram(true); + fail = !_sprites[i].createSprite(lcd_width, lcd_height); + } + + if (fail) + { + fail = false; + if (lcd_width > 320) lcd_width = 320; + if (lcd_height > 240) lcd_height = 240; + + for (std::uint32_t i = 0; !fail && i < 2; ++i) + { + _sprites[i].setPsram(true); + fail = !_sprites[i].createSprite(lcd_width, lcd_height); + } + if (fail) + { + lcd.print("createSprite fail..."); + delay(3000); + } + } } + _width = lcd_width << SHIFTSIZE; _height = lcd_height << SHIFTSIZE; From 7ee47645c8c75530aa3991451b15ba44d67e8c0d Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Mon, 20 Jul 2020 21:43:47 +0900 Subject: [PATCH 16/19] add: support M5StickCPlus ( untested ) --- src/config/LGFX_Config_M5StickC.hpp | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/config/LGFX_Config_M5StickC.hpp b/src/config/LGFX_Config_M5StickC.hpp index 10779c41..a172a380 100644 --- a/src/config/LGFX_Config_M5StickC.hpp +++ b/src/config/LGFX_Config_M5StickC.hpp @@ -22,6 +22,41 @@ class LGFX : public lgfx::LGFX_SPI setPanel(&panel); } + + void initPanel(void) override + { + if (!_panel) return; + _panel->init(); + lgfx::LGFX_SPI::initPanel(); + + std::uint32_t id = readPanelID(); + if (id != 0xf0897c) { // check panel (ST7735 or ST7789) + ESP_LOGI("LovyanGFX", "[Autodetect] Using Panel_ST7789"); + + static lgfx::Panel_ST7789 panel; + panel.spi_3wire = true; + panel.invert = true; + panel.spi_cs = 5; + panel.spi_dc = 23; + panel.gpio_rst = 18; + panel.freq_write = 80000000; + panel.freq_read = 16000000; + panel.freq_fill = 80000000; + panel.spi_mode_read = 1; + panel.len_dummy_read_pixel = 16; + panel.panel_width = 135; + panel.panel_height = 240; + panel.offset_x = 52; + panel.offset_y = 40; + panel.offset_rotation = 2; + + setPanel(&panel); + lgfx::LGFX_SPI::initPanel(); + } else { + ESP_LOGI("LovyanGFX", "[Autodetect] Using Panel_ST7735"); + } + } + }; #endif From ddc4100c1b0e7af810316bd9c733df4f74f29831 Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Wed, 22 Jul 2020 11:14:22 +0900 Subject: [PATCH 17/19] fix: M5StickC+ --- src/config/LGFX_Config_M5StickC.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/config/LGFX_Config_M5StickC.hpp b/src/config/LGFX_Config_M5StickC.hpp index a172a380..ceda1fa4 100644 --- a/src/config/LGFX_Config_M5StickC.hpp +++ b/src/config/LGFX_Config_M5StickC.hpp @@ -48,7 +48,6 @@ class LGFX : public lgfx::LGFX_SPI panel.panel_height = 240; panel.offset_x = 52; panel.offset_y = 40; - panel.offset_rotation = 2; setPanel(&panel); lgfx::LGFX_SPI::initPanel(); From 0ab7f4a7ccb57319ef49f30f752224c6ae8a0606 Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Wed, 22 Jul 2020 20:46:44 +0900 Subject: [PATCH 18/19] update: M5StickC panel settings moved to the configuration file --- src/config/LGFX_Config_M5StickC.hpp | 61 ++++++++++++++++++++++------- src/lgfx/panel/Panel_ST7735.hpp | 25 ------------ 2 files changed, 46 insertions(+), 40 deletions(-) diff --git a/src/config/LGFX_Config_M5StickC.hpp b/src/config/LGFX_Config_M5StickC.hpp index ceda1fa4..6d2fad0e 100644 --- a/src/config/LGFX_Config_M5StickC.hpp +++ b/src/config/LGFX_Config_M5StickC.hpp @@ -11,6 +11,51 @@ namespace lgfx static constexpr int spi_miso = 14; static constexpr int spi_sclk = 13; }; + + struct Panel_M5StickC : public Panel_ST7735S + { + Panel_M5StickC() { + spi_3wire = true; + invert = true; + spi_cs = 5; + spi_dc = 23; + gpio_rst = 18; + panel_width = 80; + panel_height = 160; + offset_x = 26; + offset_y = 1; + offset_rotation = 2; + } + protected: + const std::uint8_t* getInitCommands(std::uint8_t listno) const override { + static constexpr std::uint8_t list[] = { + CMD::GAMMASET, 1, 0x08, // Gamma set, curve 4 + 0xFF,0xFF, // end + }; + if (listno == 2) return list; + return Panel_ST7735S::getInitCommands(listno); + } + }; + + struct Panel_M5StickCPlus: public Panel_ST7789 + { + Panel_M5StickCPlus() { + spi_3wire = true; + invert = true; + spi_cs = 5; + spi_dc = 23; + gpio_rst = 18; + freq_write = 80000000; + freq_read = 16000000; + freq_fill = 80000000; + spi_mode_read = 1; + len_dummy_read_pixel = 16; + panel_width = 135; + panel_height = 240; + offset_x = 52; + offset_y = 40; + } + }; } class LGFX : public lgfx::LGFX_SPI @@ -33,21 +78,7 @@ class LGFX : public lgfx::LGFX_SPI if (id != 0xf0897c) { // check panel (ST7735 or ST7789) ESP_LOGI("LovyanGFX", "[Autodetect] Using Panel_ST7789"); - static lgfx::Panel_ST7789 panel; - panel.spi_3wire = true; - panel.invert = true; - panel.spi_cs = 5; - panel.spi_dc = 23; - panel.gpio_rst = 18; - panel.freq_write = 80000000; - panel.freq_read = 16000000; - panel.freq_fill = 80000000; - panel.spi_mode_read = 1; - panel.len_dummy_read_pixel = 16; - panel.panel_width = 135; - panel.panel_height = 240; - panel.offset_x = 52; - panel.offset_y = 40; + static lgfx::Panel_M5StickCPlus panel; setPanel(&panel); lgfx::LGFX_SPI::initPanel(); diff --git a/src/lgfx/panel/Panel_ST7735.hpp b/src/lgfx/panel/Panel_ST7735.hpp index 15f63f92..0bcf6b83 100644 --- a/src/lgfx/panel/Panel_ST7735.hpp +++ b/src/lgfx/panel/Panel_ST7735.hpp @@ -167,31 +167,6 @@ namespace lgfx }; #if defined(ESP32) || (CONFIG_IDF_TARGET_ESP32) - struct Panel_M5StickC : public Panel_ST7735S - { - Panel_M5StickC() { - spi_3wire = true; - invert = true; - spi_cs = 5; - spi_dc = 23; - gpio_rst = 18; - panel_width = 80; - panel_height = 160; - offset_x = 26; - offset_y = 1; - offset_rotation = 2; - } - protected: - const std::uint8_t* getInitCommands(std::uint8_t listno) const override { - static constexpr std::uint8_t list[] = { - CMD::GAMMASET, 1, 0x08, // Gamma set, curve 4 - 0xFF,0xFF, // end - }; - if (listno == 2) return list; - return Panel_ST7735S::getInitCommands(listno); - } - }; - struct Panel_TTGO_TS : public Panel_ST7735S { Panel_TTGO_TS(void) { From cdd01078440a13b4cb33f5371c3d63e89d8c30af Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Wed, 22 Jul 2020 21:00:45 +0900 Subject: [PATCH 19/19] 0.1.16 --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index 9bd48fc1..44e6f5d3 100644 --- a/library.json +++ b/library.json @@ -11,7 +11,7 @@ "type": "git", "url": "https://github.com/lovyan03/LovyanGFX" }, - "version": "0.1.15", + "version": "0.1.16", "framework": "arduino, espidf", "platforms": "espressif32, atmelsam", "build": { diff --git a/library.properties b/library.properties index bf102c24..82ec0455 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=LovyanGFX -version=0.1.15 +version=0.1.16 author=lovyan03 maintainer=Lovyan <42724151+lovyan03@users.noreply.github.com> sentence=LCD Graphics driver for ESP32 and SAMD51