Comments (6)
I have tried to edit the panel for ST7796. As the following is worked for me.
//-----------------------------------
// [Panel_ST7796.hpp]
//-----------------------------------
#ifndef LGFX_PANEL_ST7796_HPP_
#define LGFX_PANEL_ST7796_HPP_
#include "PanelIlitekCommon.hpp"
namespace lgfx
{
struct Panel_ST7796 : public PanelIlitekCommon
{
Panel_ST7796(void)
{
panel_width = memory_width = 320;
panel_height = memory_height = 480;
freq_write = 40000000;
freq_read = 20000000;
freq_fill = 40000000;
read_depth = rgb888_3Byte;
write_depth = rgb888_3Byte;
spi_mode = 0;
spi_mode_read = 0;
len_dummy_read_pixel = 8;
spi_read = true;
spi_3wire = false;
pwm_ch_bl = 0;
backlight_level = true;
invert = false;
rgb_order = false;
offset_x = 0;
offset_y = 0;
rotation = 3;
offset_rotation = 0;
}
protected:
struct CMD : public CommandCommon
{
static constexpr std::uint8_t FRMCTR1 = 0xB1;
static constexpr std::uint8_t FRMCTR2 = 0xB2;
static constexpr std::uint8_t FRMCTR3 = 0xB3;
static constexpr std::uint8_t INVCTR = 0xB4;
static constexpr std::uint8_t DFUNCTR = 0xB6;
static constexpr std::uint8_t ETMOD = 0xB7;
static constexpr std::uint8_t PWCTR1 = 0xC0;
static constexpr std::uint8_t PWCTR2 = 0xC1;
static constexpr std::uint8_t PWCTR3 = 0xC2;
static constexpr std::uint8_t PWCTR4 = 0xC3;
static constexpr std::uint8_t PWCTR5 = 0xC4;
static constexpr std::uint8_t VMCTR = 0xC5;
static constexpr std::uint8_t GMCTRP1 = 0xE0; // Positive Gamma Correction
static constexpr std::uint8_t GMCTRN1 = 0xE1; // Negative Gamma Correction
static constexpr std::uint8_t DOCA = 0xE8; // Display Output Ctrl Adjust
static constexpr std::uint8_t CSCON = 0xF0; // Command Set Control
};
const std::uint8_t* getInitCommands(std::uint8_t listno) const override {
static constexpr std::uint8_t list0[] = {
CMD::SWRESET, CMD_INIT_DELAY, 120,
CMD::SLPOUT, CMD_INIT_DELAY, 120,
CMD::CSCON, 1, 0xC3, // Enable extension command 2 partI
CMD::CSCON, 1, 0x96, // Enable extension command 2 partII
CommandCommon::MADCTL, 1, 0x48, //X-Mirror, Top-Left to right-Buttom, RGB
CommandCommon::COLMOD, 1, 0x55, //Control interface color format set to 16
CMD::INVCTR, 1, 0x01, //1-dot inversion
CMD::DFUNCTR, 3, 0x80, //Display Function Control //Bypass
0x02, //Source Output Scan from S1 to S960, Gate Output scan from G1 to G480, scan cycle=2
0x3B, //LCD Drive Line=8*(59+1)
CMD::DOCA, 8, 0x40,
0x8A,
0x00,
0x00,
0x29, //Source eqaulizing period time= 22.5 us
0x19, //Timing for "Gate start"=25 (Tclk)
0xA5, //Timing for "Gate End"=37 (Tclk), Gate driver EQ function ON
0x33,
CMD::PWCTR2, 1, 0x06, //Power control2 //VAP(GVDD)=3.85+( vcom+vcom offset), VAN(GVCL)=-3.85+( vcom+vcom offset)
CMD::PWCTR3, 1, 0xA7, //Power control 3 //Source driving current level=low, Gamma driving current level=High
CMD::VMCTR, 1+CMD_INIT_DELAY, 0x18, 120, //VCOM Control //VCOM=0.9
CMD::GMCTRP1,14, 0xF0, 0x09, 0x0B, 0x06, 0x04, 0x15, 0x2F,
0x54, 0x42, 0x3C, 0x17, 0x14, 0x18, 0x1B,
CMD::GMCTRN1,14+CMD_INIT_DELAY,
0xE0, 0x09, 0x0B, 0x06, 0x04, 0x03, 0x2B,
0x43, 0x42, 0x3B, 0x16, 0x14, 0x17, 0x1B,
120,
CMD::CSCON, 1, 0x3C, //Command Set control // Disable extension command 2 partI
CMD::CSCON, 1, 0x69, //Command Set control // Disable extension command 2 partII
0xFF,0xFF, // end
};
static constexpr std::uint8_t list1[] = {
CMD::SLPOUT, CMD_INIT_DELAY, 120, // Exit sleep mode
CMD::DISPON, CMD_INIT_DELAY, 20, // Set display on
0xFF,0xFF, // end
};
switch (listno) {
case 0: return list0;
case 1: return list1;
default: return nullptr;
}
}
std::uint8_t getMadCtl(std::uint8_t r) const override {
static constexpr std::uint8_t madctl_table[] = {
MAD_MX|MAD_MH ,
MAD_MV ,
MAD_MY|MAD_ML,
MAD_MV|MAD_MX|MAD_MY|MAD_MH|MAD_ML,
MAD_MX|MAD_MH|MAD_MY|MAD_ML,
MAD_MV|MAD_MX|MAD_MH ,
0,
MAD_MV| MAD_MY|MAD_ML,
};
r = ((r + offset_rotation) & 3) | ((r & 4) ^ (offset_rotation & 4));
return madctl_table[r];
}
std::uint8_t getColMod(std::uint8_t) const override { return RGB666_3BYTE; }
};
}
#endif
If you have any points for the better for cleaning up ,
do you mind for suggestion ?
Thank you.
from lovyangfx.
@BlynkGO
Thank you for your work !
I ordered the ST7796 today and it seems to take about two weeks to arrive.
It will be a little while before I get to try that, but I will consider this suggestion as soon as possible.
I'm reading the specsheet now.
I want to check a few things before I merge it.
Confirmation 1:
Need to override "getColMod" ?
If the ST7796 supports 16-bit color mode, do not need to override getColMod.
Remove the override and use setColorDepth(16) and try to draw something.
If the drawing seems strange, need to override "getColMod".
Confirmation 2:
Does the read pixel sample work correctly?
"examples/Test/test_readpixel/test_readpixel.ino"
If it works correctly, the test pattern will move as it deforms.
If the settings are not correct, the colors will be wrong or collapsed.
In that case, you may need to adjust "len_dummy_read_pixel" and "freq_read".
The following settings are described in user code, not in the panel structure.
spi_read = true;
spi_3wire = false;
pwm_ch_bl = 0;
backlight_level = true;
invert = false;
rgb_order = false;
offset_x = 0;
offset_y = 0;
rotation = 3;
offset_rotation = 0;
from lovyangfx.
@BlynkGO
Perhaps you need to use SPIClass beginTransaction(); and endTransaction(); function.
The same goes for startWrite() and endWrite() of LovyanGFX.
These must be called properly to use the SPI only when necessary.
from lovyangfx.
@lovyan03
Thank you for the suggestion.
By your suggestion,
I have just removed the user-panel structure and getColMod(..)
as the following
#ifndef LGFX_PANEL_ST7796_HPP_
#define LGFX_PANEL_ST7796_HPP_
#include "PanelIlitekCommon.hpp"
namespace lgfx
{
struct Panel_ST7796 : public PanelIlitekCommon
{
Panel_ST7796(void)
{
panel_width = memory_width = 320;
panel_height = memory_height = 480;
freq_write = 40000000;
freq_read = 20000000;
freq_fill = 40000000;
read_depth = rgb888_3Byte;
write_depth = rgb888_3Byte;
}
protected:
struct CMD : public CommandCommon
{
static constexpr std::uint8_t FRMCTR1 = 0xB1;
static constexpr std::uint8_t FRMCTR2 = 0xB2;
static constexpr std::uint8_t FRMCTR3 = 0xB3;
static constexpr std::uint8_t INVCTR = 0xB4;
static constexpr std::uint8_t DFUNCTR = 0xB6;
static constexpr std::uint8_t ETMOD = 0xB7;
static constexpr std::uint8_t PWCTR1 = 0xC0;
static constexpr std::uint8_t PWCTR2 = 0xC1;
static constexpr std::uint8_t PWCTR3 = 0xC2;
static constexpr std::uint8_t PWCTR4 = 0xC3;
static constexpr std::uint8_t PWCTR5 = 0xC4;
static constexpr std::uint8_t VMCTR = 0xC5;
static constexpr std::uint8_t GMCTRP1 = 0xE0; // Positive Gamma Correction
static constexpr std::uint8_t GMCTRN1 = 0xE1; // Negative Gamma Correction
static constexpr std::uint8_t DOCA = 0xE8; // Display Output Ctrl Adjust
static constexpr std::uint8_t CSCON = 0xF0; // Command Set Control
};
const std::uint8_t* getInitCommands(std::uint8_t listno) const override {
static constexpr std::uint8_t list0[] = {
CMD::SWRESET, CMD_INIT_DELAY, 120,
CMD::SLPOUT, CMD_INIT_DELAY, 120,
CMD::CSCON, 1, 0xC3, // Enable extension command 2 partI
CMD::CSCON, 1, 0x96, // Enable extension command 2 partII
CommandCommon::MADCTL, 1, 0x48, //X-Mirror, Top-Left to right-Buttom, RGB
CommandCommon::COLMOD, 1, 0x55, //Control interface color format set to 16
CMD::INVCTR, 1, 0x01, //1-dot inversion
CMD::DFUNCTR, 3, 0x80, //Display Function Control //Bypass
0x02, //Source Output Scan from S1 to S960, Gate Output scan from G1 to G480, scan cycle=2
0x3B, //LCD Drive Line=8*(59+1)
CMD::DOCA, 8, 0x40,
0x8A,
0x00,
0x00,
0x29, //Source eqaulizing period time= 22.5 us
0x19, //Timing for "Gate start"=25 (Tclk)
0xA5, //Timing for "Gate End"=37 (Tclk), Gate driver EQ function ON
0x33,
CMD::PWCTR2, 1, 0x06, //Power control2 //VAP(GVDD)=3.85+( vcom+vcom offset), VAN(GVCL)=-3.85+( vcom+vcom offset)
CMD::PWCTR3, 1, 0xA7, //Power control 3 //Source driving current level=low, Gamma driving current level=High
CMD::VMCTR, 1+CMD_INIT_DELAY, 0x18, 120, //VCOM Control //VCOM=0.9
CMD::GMCTRP1,14, 0xF0, 0x09, 0x0B, 0x06, 0x04, 0x15, 0x2F,
0x54, 0x42, 0x3C, 0x17, 0x14, 0x18, 0x1B,
CMD::GMCTRN1,14+CMD_INIT_DELAY,
0xE0, 0x09, 0x0B, 0x06, 0x04, 0x03, 0x2B,
0x43, 0x42, 0x3B, 0x16, 0x14, 0x17, 0x1B,
120,
CMD::CSCON, 1, 0x3C, //Command Set control // Disable extension command 2 partI
CMD::CSCON, 1, 0x69, //Command Set control // Disable extension command 2 partII
0xFF,0xFF, // end
};
static constexpr std::uint8_t list1[] = {
CMD::SLPOUT, CMD_INIT_DELAY, 120, // Exit sleep mode
CMD::DISPON, CMD_INIT_DELAY, 20, // Set display on
0xFF,0xFF, // end
};
switch (listno) {
case 0: return list0;
case 1: return list1;
default: return nullptr;
}
}
std::uint8_t getMadCtl(std::uint8_t r) const override {
static constexpr std::uint8_t madctl_table[] = {
MAD_MX|MAD_MH ,
MAD_MV ,
MAD_MY|MAD_ML,
MAD_MV|MAD_MX|MAD_MY|MAD_MH|MAD_ML,
MAD_MX|MAD_MH|MAD_MY|MAD_ML,
MAD_MV|MAD_MX|MAD_MH ,
0,
MAD_MV| MAD_MY|MAD_ML,
};
r = ((r + offset_rotation) & 3) | ((r & 4) ^ (offset_rotation & 4));
return madctl_table[r];
}
};
}
#endif
And then tested by the example examples/Test/test_readpixel/test_readpixel.ino
.
The result as the following
Does the result display correctly?
By the way, do you mind to add a API for returning spi_t*
function to the library?
such as
__attribute__ ((always_inline)) inline spi_t* getSPIHandle(void) const { return _spi_handle; }
I would like to use the same spi_handle for the touch interface.
Thank you.
from lovyangfx.
@BlynkGO
thankyou !
Yes, that's correct for the test_readpixel display, but it should move down from there, transforming into a triangle.
Make sure the color does not change or darken at that time.
Please be patient, I have plans to support touchscreens.
getSPIHandle needs to be decided carefully as exposing it will interfere with ESP-IDF compatibility, but probabry you can simply use the SPI class.
from lovyangfx.
@lovyan03
I tried by the Arduino's SPI class for the touch interface last night.
When after call SPI.begin(....);
, the touch interface can use,
however the spi from LovyanGFX is stop. can't display other thing anymore.
I recreated the touch interface by using the LovyanGFX's spi_handle,
it's fine for both TFT and touch interface.
Waiting for LovyanGFX come with touch interface in the next version.
Thank you very much.
from lovyangfx.
Related Issues (20)
- drawEllipseとfillEllipseの、rxとryの一方だけが0のときの挙動について HOT 2
- Freeze using tft.getTouch(...) with a FT5x06 I2C capacitive touch screen HOT 3
- I need support for the CYD board (cheap yellow display) ESP32-2432S028R HOT 8
- Lilygo AMOLED series HOT 20
- Support for MakerFab 2.1 inch round MaTouch ESP32-S3 based controller HOT 3
- LilyGo AMOLED Series HOT 1
- Expose XPT2046 ability to measure VBAT HOT 4
- Endianness Inconsistency HOT 2
- Failing to build after updating platformio HOT 2
- Help me , ST7735S cannot drive 80*160 screen normally
- Color Inversion Not Working Correctly with ST7789 Display. HOT 2
- build error with cross-compiler when using SDL2 HOT 6
- Add M5Stack_Fire HOT 1
- Support for ESP32-S3-Box v3 HOT 35
- Screen tearing when using a Makerfabs Matouch 4.0" 480x480 parallel LCD screen HOT 7
- Support ST7701s IPS TFT 5 inch 854x480 RGB+SPI With ESP32-S3 HOT 15
- ST7789 cannot get it to work HOT 3
- tft.getTouch(&touchX, &touchY); freeze loop() HOT 1
- Support for 4.3" RGB Interface HOT 2
- Shimering effect with SSD1963 HOT 15
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lovyangfx.