Skip to content

Commit

Permalink
Fixed an error when coexisting with M5Stack.h library.
Browse files Browse the repository at this point in the history
  • Loading branch information
lovyan03 committed May 28, 2021
1 parent b0d7647 commit 2a936cd
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 21 deletions.
10 changes: 4 additions & 6 deletions src/M5GFX.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include <FS.h>
#endif

#ifdef setFont
#undef setFont
#endif

#define LGFX_USE_V1
#include "lgfx/v1/gitTagVersion.h"
#include "lgfx/v1/platforms/device.hpp"
Expand Down Expand Up @@ -186,10 +190,4 @@ using namespace m5gfx::tft_command;
using M5GFX = m5gfx::M5GFX;
using M5Canvas = m5gfx::M5Canvas;

// For compatibility
using TFT_eSPI = m5gfx::M5GFX;

// For compatibility
using TFT_eSprite = m5gfx::M5Canvas;

#undef LGFX_NS
5 changes: 5 additions & 0 deletions src/lgfx/v1/LGFXBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2840,6 +2840,11 @@ namespace lgfx
panel()->initBus();
};

void LGFX_Device::releaseBus(void)
{
panel()->releaseBus();
};

void LGFX_Device::setPanel(Panel_Device* panel)
{
static Panel_NULL nullobj;
Expand Down
1 change: 1 addition & 0 deletions src/lgfx/v1/LGFXBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,7 @@ namespace lgfx
bool begin(void) { return init_impl(true , true); };
bool init_without_reset(void) { return init_impl(false, false); };
void initBus(void);
void releaseBus(void);
void setPanel(Panel_Device* panel);

void setEpdMode(epd_mode_t epd_mode) { _panel->setEpdMode(epd_mode); }
Expand Down
5 changes: 5 additions & 0 deletions src/lgfx/v1/panel/Panel_Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ namespace lgfx
_bus->init();
}

void Panel_Device::releaseBus(void)
{
_bus->release();
}

bool Panel_Device::init(bool use_reset)
{
_bus->init();
Expand Down
6 changes: 5 additions & 1 deletion src/lgfx/v1/panel/Panel_Device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ namespace lgfx
const config_t& config(void) const { return _cfg; }
void config(const config_t& cfg) { _cfg = cfg; }

void initBus(void);
virtual void initBus(void);
virtual void releaseBus(void);
void setBus(IBus* bus);
void bus(IBus* bus) { setBus(bus); };
IBus* getBus(void) const { return _bus; }
Expand Down Expand Up @@ -203,6 +204,9 @@ namespace lgfx
{
Panel_NULL(void) = default;

void initBus(void) override {}
void releaseBus(void) override {}

void beginTransaction(void) override {}
void endTransaction(void) override {}
bool init(bool use_reset) override { return false; }
Expand Down
28 changes: 15 additions & 13 deletions src/lgfx/v1/panel/Panel_SSD1306.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ namespace lgfx
return false;
}

_bus->beginRead();
std::uint8_t buf;
bool res = _bus->readBytes(&buf, 1, true);
_bus->endTransaction();

if (!res)
{
return false;
}

startWrite(true);

for (std::size_t i = 0; auto cmds = getInitCommands(i); i++)
Expand Down Expand Up @@ -397,20 +407,12 @@ namespace lgfx
return false;
}

_bus->beginRead();
std::uint8_t buf;
bool res = _bus->readBytes(&buf, 1, true);
_bus->endTransaction();

if (res)
{
startWrite(true);
_bus->writeCommand(CMD_SETMULTIPLEX | (((_cfg.panel_width-1) & 0x7F) << 8), 16);
_bus->writeCommand(CMD_SETDISPLAYOFFSET | ((uint8_t)(-_cfg.offset_x) << 8), 16);
endWrite();
}
startWrite(true);
_bus->writeCommand(CMD_SETMULTIPLEX | (((_cfg.panel_width-1) & 0x7F) << 8), 16);
_bus->writeCommand(CMD_SETDISPLAYOFFSET | ((uint8_t)(-_cfg.offset_x) << 8), 16);
endWrite();

return res;
return true;
}

void Panel_SH110x::beginTransaction(void)
Expand Down
10 changes: 9 additions & 1 deletion src/lgfx/v1/platforms/esp32/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,11 @@ namespace lgfx
{
if (i2c_port >= I2C_NUM_MAX) { return cpp::fail(error_t::invalid_arg); }

if (i2c_context[i2c_port].pin_scl >= 0 || i2c_context[i2c_port].pin_sda >= 0)
{
release(i2c_port);
}

i2c_context[i2c_port].pin_scl = (gpio_num_t)pin_scl;
i2c_context[i2c_port].pin_sda = (gpio_num_t)pin_sda;
i2c_stop(i2c_port);
Expand All @@ -501,6 +506,8 @@ namespace lgfx
periph_module_disable(i2c_port == 0 ? PERIPH_I2C0_MODULE : PERIPH_I2C1_MODULE);
pinMode(i2c_context[i2c_port].pin_scl, pin_mode_t::input);
pinMode(i2c_context[i2c_port].pin_sda, pin_mode_t::input);
i2c_context[i2c_port].pin_scl = (gpio_num_t)-1;
i2c_context[i2c_port].pin_sda = (gpio_num_t)-1;

return {};
}
Expand Down Expand Up @@ -701,7 +708,8 @@ namespace lgfx
{
len = ((length-1) & 63) + 1;
length -= len;
if (!i2c_wait(i2c_port))
res = i2c_wait(i2c_port);
if (res.has_error())
{
ESP_LOGE("LGFX", "i2c read error : ack wait");
break;
Expand Down

0 comments on commit 2a936cd

Please sign in to comment.