Skip to content

Commit

Permalink
fix for IDF5+ESP32S3
Browse files Browse the repository at this point in the history
  • Loading branch information
lovyan03 committed Feb 14, 2023
1 parent 424f9d1 commit 35ef5ff
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 35 deletions.
9 changes: 2 additions & 7 deletions src/M5GFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <esp_log.h>
#include <driver/i2c.h>
#include <soc/efuse_reg.h>
#include <soc/gpio_reg.h>

#include "lgfx/v1/panel/Panel_ILI9342.hpp"
#include "lgfx/v1/panel/Panel_ST7735.hpp"
Expand Down Expand Up @@ -306,7 +307,7 @@ namespace m5gfx
*(volatile uint32_t*)GPIO_FUNC35_OUT_SEL_CFG_REG = flg ? 0x43 : 0x100;
if (flg == false)
{ // CS low の場合はD/Cとして扱うためGPIO出力を有効にする;
*(volatile uint32_t*)GPIO_ENABLE1_W1TS_REG = (0x1 << (GPIO_NUM_35 - 32));
*(volatile uint32_t*)GPIO_ENABLE1_W1TS_REG = (0x1 << (GPIO_NUM_35 & 31));
}
}
};
Expand Down Expand Up @@ -965,7 +966,6 @@ namespace m5gfx
cfg.pin_int = GPIO_NUM_36;
cfg.pin_sda = GPIO_NUM_21;
cfg.pin_scl = GPIO_NUM_22;
cfg.i2c_addr = 0x14;
#ifdef _M5EPD_H_
cfg.i2c_port = I2C_NUM_0;
#else
Expand All @@ -979,11 +979,6 @@ namespace m5gfx
cfg.offset_rotation = 1;
cfg.bus_shared = false;
t->config(cfg);
if (!t->init())
{
cfg.i2c_addr = 0x5D; // addr change (0x14 or 0x5D)
t->config(cfg);
}
_panel_last->touch(t);
}
goto init_clear;
Expand Down
4 changes: 2 additions & 2 deletions src/lgfx/v1/panel/Panel_M5HDMI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,9 @@ namespace lgfx

{
auto bus_cfg = reinterpret_cast<lgfx::Bus_SPI*>(_bus)->config();
_pin_backup_t backup_sclk[] = { (gpio_num_t)bus_cfg.pin_sclk, (gpio_num_t)bus_cfg.pin_mosi, (gpio_num_t)bus_cfg.pin_miso };
_pin_backup_t backup_pins[] = { (gpio_num_t)bus_cfg.pin_sclk, (gpio_num_t)bus_cfg.pin_mosi, (gpio_num_t)bus_cfg.pin_miso };
LOAD_FPGA fpga(bus_cfg.pin_sclk, bus_cfg.pin_mosi, bus_cfg.pin_miso, _cfg.pin_cs);
for (auto &bup : backup_sclk) { bup.restore(); }
for (auto &bup : backup_pins) { bup.restore(); }
}
if (!Panel_Device::init(false)) { return false; }

Expand Down
64 changes: 38 additions & 26 deletions src/lgfx/v1/touch/Touch_GT911.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,45 +62,57 @@ namespace lgfx
lgfx::gpio_lo(_cfg.pin_rst);
lgfx::delay(1);
lgfx::gpio_hi(_cfg.pin_rst);
lgfx::delay(1);
}

if (_cfg.pin_int >= 0)
{
lgfx::lgfxPinMode(_cfg.pin_int, pin_mode_t::input);
}

_inited = lgfx::i2c::init(_cfg.i2c_port, _cfg.pin_sda, _cfg.pin_scl).has_value() && _writeBytes(gt911cmd_getdata, 3);

if (_inited)
for (int retry = 6; retry; --retry)
{
uint8_t buf[] = { 0x80, 0x56, 0x00 };
_writeBytes(buf, 3);
_writeReadBytes(buf, 2, &buf[2], 1);
_refresh_rate = 5 + (buf[2] & 0x0F);
/*
if (lgfx::i2c::init(_cfg.i2c_port, _cfg.pin_sda, _cfg.pin_scl).has_value() && _writeBytes(gt911cmd_getdata, 3))
{
uint8_t writedata[4] = { 0x80, 0x40 };
uint8_t readdata[193] = {0};
writeReadBytes(writedata, 2, readdata, 193);
uint32_t addr = 0x8040;
for (int i = 0; i < 12; ++i) {
Serial.printf("%04x:" , addr);
for (int j = 0; j < 4; ++j) {
for (int k = 0; k < 4; ++k) {
int l = i * 16 + j * 4 + k;
Serial.printf("%02x ", readdata[l]);
}
Serial.print(" ");
}
Serial.println();
addr += 16;
_inited = true;
uint8_t buf[] = { 0x80, 0x56, 0x00 };
_writeBytes(buf, 3);
_writeReadBytes(buf, 2, &buf[2], 1);
_refresh_rate = 5 + (buf[2] & 0x0F);
return true;
}
lgfx::delay(1);
if (_cfg.i2c_addr == default_addr_1) {
_cfg.i2c_addr = default_addr_2;
} else if (_cfg.i2c_addr == default_addr_2) {
_cfg.i2c_addr == default_addr_1;
}
}
return false;
}

/*
void debug_regdump(void)
{
uint8_t writedata[4] = { 0x80, 0x40 };
uint8_t readdata[193] = {0};
writeReadBytes(writedata, 2, readdata, 193);
uint32_t addr = 0x8040;
for (int i = 0; i < 12; ++i) {
Serial.printf("%04x:" , addr);
for (int j = 0; j < 4; ++j) {
for (int k = 0; k < 4; ++k) {
int l = i * 16 + j * 4 + k;
Serial.printf("%02x ", readdata[l]);
}
Serial.print(" ");
}
//*/
Serial.println();
addr += 16;
}
return _inited;
}
//*/

void Touch_GT911::wakeup(void)
{
Expand Down
4 changes: 4 additions & 0 deletions src/lgfx/v1/touch/Touch_GT911.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ namespace lgfx

struct Touch_GT911 : public ITouch
{
static constexpr const uint8_t default_addr_1 = 0x14;
static constexpr const uint8_t default_addr_2 = 0x5D;

Touch_GT911(void)
{
_cfg.i2c_addr = default_addr_1;
_cfg.x_min = 0;
_cfg.x_max = 2047;
_cfg.y_min = 0;
Expand Down

0 comments on commit 35ef5ff

Please sign in to comment.