Update LovyanGFX driver

This commit is contained in:
fvanroie 2021-10-18 11:36:50 +02:00
parent 382537ec6d
commit 87831daf6e
2 changed files with 95 additions and 27 deletions

View File

@ -6,6 +6,35 @@
namespace dev {
static void _pin_level(int_fast16_t pin, bool level)
{
lgfx::pinMode(pin, lgfx::pin_mode_t::output);
if(level)
lgfx::gpio_hi(pin);
else
lgfx::gpio_lo(pin);
}
static uint32_t _read_panel_id(lgfx::Bus_SPI* bus, int32_t pin_cs, uint32_t cmd = 0x04,
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
bus->beginRead();
uint32_t res = bus->readData(32);
bus->endTransaction();
_pin_level(pin_cs, true);
LOG_VERBOSE(TAG_DRVR, "[Autodetect] read cmd:%u = %u", cmd, res);
LOG_VERBOSE(TAG_DRVR, "[Autodetect] read cmd:%02x = %08x", cmd, res);
return res;
}
void LovyanGfx::init(int w, int h)
{
#ifdef USE_DMA_TO_TFT
@ -14,6 +43,33 @@ void LovyanGfx::init(int w, int h)
int dma_channel = 1; // Set the DMA channel (1 or 2. 0=disable)
#endif
uint32_t tft_driver = 0;
#ifdef ST7796_DRIVER
tft_driver = 0x7796;
#endif
#ifdef ILI9481_DRIVER
tft_driver = 0x9481;
#endif
#ifdef ILI9341_DRIVER
tft_driver = 0x9481;
#endif
#ifdef ILI9488_DRIVER
tft_driver = 0x9488;
#endif
if (tft_driver == 0x9341)
tft._panel_instance = new lgfx::Panel_ILI9341();
else if (tft_driver == 0x9481)
tft._panel_instance = new lgfx::Panel_ILI9481();
else if (tft_driver == 0x9488)
tft._panel_instance = new lgfx::Panel_ILI9488();
else if (tft_driver == 0x7796)
tft._panel_instance = new lgfx::Panel_ST7796();
{ // バス制御の設定を行います。
auto bus = (lgfx::v1::Bus_SPI*)tft._bus_instance;
auto cfg = bus->config(); // バス設定用の構造体を取得します。
@ -29,30 +85,35 @@ void LovyanGfx::init(int w, int h)
cfg.pin_miso = TFT_MISO; // SPIのMISOピン番号を設定 (-1 = disable)
cfg.pin_dc = TFT_DC; // SPIのD/Cピン番号を設定 (-1 = disable)
bus->config(cfg); // 設定値をバスに反映します。
tft._panel_instance.setBus(bus); // バスをパネルにセットします。
bus->init();
_read_panel_id(bus, TFT_CS, 0x00);
_read_panel_id(bus, TFT_CS, 0x04);
_read_panel_id(bus, TFT_CS, 0x09);
_read_panel_id(bus, TFT_CS, 0xBF);
tft._panel_instance->setBus(bus); // バスをパネルにセットします。
}
{ // 表示パネル制御の設定を行います。
auto cfg = tft._panel_instance.config(); // 表示パネル設定用の構造体を取得します。
cfg.pin_cs = TFT_CS; // CSが接続されているピン番号 (-1 = disable)
cfg.pin_rst = TFT_RST; // RSTが接続されているピン番号 (-1 = disable)
cfg.pin_busy = -1; // BUSYが接続されているピン番号 (-1 = disable)
cfg.memory_width = w; // ドライバICがサポートしている最大の幅
cfg.memory_height = h; // ドライバICがサポートしている最大の高さ
cfg.panel_width = w; // 実際に表示可能な幅
cfg.panel_height = h; // 実際に表示可能な高さ
cfg.offset_x = 0; // パネルのX方向オフセット量
cfg.offset_y = 0; // パネルのY方向オフセット量
cfg.offset_rotation = 0; // 回転方向の値のオフセット 0~7 (4~7は上下反転)
{ // 表示パネル制御の設定を行います。
auto cfg = tft._panel_instance->config(); // 表示パネル設定用の構造体を取得します。
cfg.pin_cs = TFT_CS; // CSが接続されているピン番号 (-1 = disable)
cfg.pin_rst = TFT_RST; // RSTが接続されているピン番号 (-1 = disable)
cfg.pin_busy = -1; // BUSYが接続されているピン番号 (-1 = disable)
cfg.memory_width = w; // ドライバICがサポートしている最大の幅
cfg.memory_height = h; // ドライバICがサポートしている最大の高さ
cfg.panel_width = w; // 実際に表示可能な幅
cfg.panel_height = h; // 実際に表示可能な高さ
cfg.offset_x = 0; // パネルのX方向オフセット量
cfg.offset_y = 0; // パネルのY方向オフセット量
cfg.offset_rotation = 0; // 回転方向の値のオフセット 0~7 (4~7は上下反転)
cfg.dummy_read_pixel = 8; // ピクセル読出し前のダミーリードのビット数
cfg.dummy_read_bits = 1; // ピクセル以外のデータ読出し前のダミーリードのビット数
cfg.readable = false; // データ読出しが可能な場合 trueに設定
cfg.invert = true; // パネルの明暗が反転してしまう場合 trueに設定
cfg.readable = true; // データ読出しが可能な場合 trueに設定
cfg.invert = false; // パネルの明暗が反転してしまう場合 trueに設定
cfg.rgb_order = false; // パネルの赤と青が入れ替わってしまう場合 trueに設定
cfg.dlen_16bit = false; // データ長を16bit単位で送信するパネルの場合 trueに設定
cfg.bus_shared = true; // SDカードとバスを共有している場合 trueに設定(drawJpgFile等でバス制御を行います)
tft._panel_instance.config(cfg);
tft._panel_instance->config(cfg);
}
{ // バックライト制御の設定を行います。(必要なければ削除)
@ -64,7 +125,7 @@ void LovyanGfx::init(int w, int h)
cfg.pwm_channel = 0; // 使用するPWMのチャンネル番号
tft._light_instance.config(cfg);
tft._panel_instance.setLight(&tft._light_instance); // バックライトをパネルにセットします。
tft._panel_instance->setLight(&tft._light_instance); // バックライトをパネルにセットします。
}
{ // タッチスクリーン制御の設定を行います。(必要なければ削除)
@ -76,16 +137,22 @@ void LovyanGfx::init(int w, int h)
cfg.pin_int = -1; // INTが接続されているピン番号
cfg.bus_shared = true; // 画面と共通のバスを使用している場合 trueを設定
cfg.offset_rotation = 0; // 表示とタッチの向きのが一致しない場合の調整 0~7の値で設定
cfg.spi_host = VSPI_HOST; // 使用するSPIを選択 (HSPI_HOST or VSPI_HOST)
cfg.freq = SPI_TOUCH_FREQUENCY; // SPIクロックを設定
cfg.pin_sclk = TFT_SCLK; // SCLKが接続されているピン番号
cfg.pin_mosi = TFT_MOSI; // MOSIが接続されているピン番号
cfg.pin_miso = TFT_MISO; // MISOが接続されているピン番号
cfg.pin_cs = TOUCH_CS; // CSが接続されているピン番号
cfg.spi_host = VSPI_HOST; // 使用するSPIを選択 (HSPI_HOST or VSPI_HOST)
cfg.pin_sclk = TFT_SCLK; // SCLKが接続されているピン番号
cfg.pin_mosi = TFT_MOSI; // MOSIが接続されているピン番号
cfg.pin_miso = TFT_MISO; // MISOが接続されているピン番号
#ifdef TOUCH_CS
cfg.pin_cs = TOUCH_CS; // CSが接続されているピン番号
cfg.freq = SPI_TOUCH_FREQUENCY; // SPIクロックを設定
#else
cfg.pin_sda = TOUCH_SDA;
cfg.pin_scl = TOUCH_SCL;
cfg.freq = I2C_TOUCH_FREQUENCY; // SPIクロックを設定
#endif
tft._touch_instance.config(cfg);
tft._panel_instance.setTouch(&tft._touch_instance); // タッチスクリーンをパネルにセットします。
tft._panel_instance->setTouch(&tft._touch_instance); // タッチスクリーンをパネルにセットします。
}
tft.setPanel(&tft._panel_instance); // 使用するパネルをセットします。
tft.setPanel(tft._panel_instance); // 使用するパネルをセットします。
/* TFT init */
tft.begin();
@ -111,7 +178,7 @@ void LovyanGfx::show_info()
}
{
auto cfg = tft._panel_instance.config(); // バス設定用の構造体を取得します。
auto cfg = tft._panel_instance->config(); // バス設定用の構造体を取得します。
tftPinInfo(F("TFT_CS"), cfg.pin_cs);
tftPinInfo(F("TFT_RST"), cfg.pin_rst);
}

View File

@ -24,7 +24,8 @@
namespace dev {
class LGFX : public lgfx::LGFX_Device {
public:
lgfx::Panel_ILI9488 _panel_instance;
// lgfx::Panel_ILI9481 _panel_instance;
lgfx::Panel_LCD* _panel_instance;
lgfx::IBus* _bus_instance; // SPIバスのインスタンス
lgfx::Light_PWM _light_instance;
lgfx::Touch_XPT2046 _touch_instance;