Skip to content

Commit

Permalink
Merge pull request #1 from m5stack/develop
Browse files Browse the repository at this point in the history
0.0.2
  • Loading branch information
lovyan03 authored May 30, 2021
2 parents 2a936cd + 6d9c361 commit e069f9e
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 33 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "git",
"url": "https://github.com/m5stack/M5GFX"
},
"version": "0.0.1",
"version": "0.0.2",
"framework": "arduino",
"platforms": "espressif32"
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=M5GFX
version=0.0.1
version=0.0.2
author=M5Stack
maintainer=lovyan03<[email protected]>
sentence=Library for M5Stack All Display
Expand Down
5 changes: 5 additions & 0 deletions src/M5GFX.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#if defined (ESP32) || defined (CONFIG_IDF_TARGET_ESP32) || defined (CONFIG_IDF_TARGET_ESP32S2) || defined (ESP_PLATFORM)

#include "M5GFX.h"

#include "lgfx/v1/panel/Panel_ILI9342.hpp"
Expand Down Expand Up @@ -540,6 +542,7 @@ namespace m5gfx
// AXP192_LDO2 = LCD PWR
// AXP192_DC3 = LCD BL
// AXP192_IO4 = LCD RST

if (use_reset) lgfx::i2c::registerWrite8(axp_i2c_port, axp_i2c_addr, 0x96, 0, ~0x02, axp_i2c_freq); // GPIO4 LOW (LCD RST)
lgfx::i2c::registerWrite8(axp_i2c_port, axp_i2c_addr, 0x28, 0xF0, ~0, axp_i2c_freq); // set LDO2 3300mv // LCD PWR
lgfx::i2c::registerWrite8(axp_i2c_port, axp_i2c_addr, 0x12, 0x06, ~0, axp_i2c_freq); // LDO2 and DC3 enable (DC3 = LCD BL)
Expand Down Expand Up @@ -642,3 +645,5 @@ ESP_LOGI("nvs_board","_board:%d", board);
}

}

#endif
7 changes: 5 additions & 2 deletions src/M5GFX.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#include <FS.h>
#endif

/// Use of std::min instead of macro definitions is recommended.
#ifdef min
#undef min
#endif

#ifdef setFont
#undef setFont
#endif
Expand Down Expand Up @@ -189,5 +194,3 @@ using namespace m5gfx::ili9341_colors;
using namespace m5gfx::tft_command;
using M5GFX = m5gfx::M5GFX;
using M5Canvas = m5gfx::M5Canvas;

#undef LGFX_NS
9 changes: 7 additions & 2 deletions src/lgfx/utility/lgfx_tjpgd.c
Original file line number Diff line number Diff line change
Expand Up @@ -827,9 +827,14 @@ JRESULT lgfx_jd_prepare (
ofs = 2;

for (;;) {
if (infunc(jd, seg, 4) != 4) return JDR_INP;
uint_fast16_t len = LDB_WORD(seg + 2) - 2; /* Length field */
if (infunc(jd, seg, 1) != 1) return JDR_INP;
if (seg[0] != 0xFF) return JDR_FMT1; /* Check a JPEG marker */
do
{
if (infunc(jd, &seg[1], 1) != 1) return JDR_INP;
} while (seg[1] == 0xFF);
if (infunc(jd, &seg[2], 2) != 2) return JDR_INP;
uint_fast16_t len = LDB_WORD(seg + 2) - 2; /* Length field */
ofs += 4 + len; /* Number of bytes loaded */

switch (seg[1]) { /* Marker */
Expand Down
5 changes: 3 additions & 2 deletions src/lgfx/v1/LGFXBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2850,7 +2850,7 @@ namespace lgfx
static Panel_NULL nullobj;
_panel = (nullptr == panel)
? &nullobj
: reinterpret_cast<IPanel*>(panel);
: panel;
}

bool LGFX_Device::init_impl(bool use_reset, bool use_clear)
Expand All @@ -2862,7 +2862,7 @@ namespace lgfx
setBaseColor(TFT_WHITE);
setTextColor(TFT_BLACK, TFT_WHITE);
}
if (_panel->init(use_reset))
if (getPanel()->init(use_reset))
{
startWrite();
invertDisplay(_panel->getInvert());
Expand All @@ -2875,6 +2875,7 @@ namespace lgfx
setPivot(width()>>1, height()>>1);
endWrite();
setBrightness(_brightness);
getPanel()->initTouch();
return true;
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/lgfx/v1/LGFXBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1142,11 +1142,10 @@ namespace lgfx
inline std::uint8_t getBrightness(void) const { return _brightness; }

inline ITouch* touch(void) const { return _panel ? panel()->touch() : nullptr; }
inline void convertRawXY(std::int32_t *x, std::int32_t *y) { panel()->convertRawXY(x, y); }
std::uint_fast8_t getTouchRaw(touch_point_t *tp, std::uint_fast8_t number = 0) { return panel()->getTouchRaw(tp, number); }
std::uint_fast8_t getTouch(touch_point_t *tp, std::uint_fast8_t number = 0) { return panel()->getTouch(tp, number); }
inline void convertRawXY(std::int32_t *x, std::int32_t *y) { panel()->convertRawXY(x, y); }

touch_point_t getTouch(std::uint_fast8_t number = 0)
touch_point_t getTouch(std::int_fast8_t number = 0)
{
touch_point_t res;
getTouch(&res, number);
Expand Down
1 change: 0 additions & 1 deletion src/lgfx/v1/LGFX_Sprite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ namespace lgfx

void beginTransaction(void) override {}
void endTransaction(void) override {}
bool init(bool use_reset) override { return true; }
void setInvert(bool invert) override {}
void setSleep(bool flg_sleep) override {}
void setPowerSave(bool flg_partial) override {}
Expand Down
1 change: 0 additions & 1 deletion src/lgfx/v1/Panel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ namespace lgfx

virtual void beginTransaction(void) = 0;
virtual void endTransaction(void) = 0;
virtual bool init(bool use_reset) = 0;

virtual void setBrightness(std::uint8_t brightness) {};

Expand Down
13 changes: 9 additions & 4 deletions src/lgfx/v1/panel/Panel_Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ namespace lgfx
{
_light->init(0);
}
if (_touch)
{
_touch->init();
}
if (use_reset)
{
reset();
Expand All @@ -75,6 +71,15 @@ namespace lgfx
return true;
}

bool Panel_Device::initTouch(void)
{
if (_touch)
{
return _touch->init();
}
return false;
}

void Panel_Device::initDMA(void)
{
_bus->initDMA();
Expand Down
8 changes: 5 additions & 3 deletions src/lgfx/v1/panel/Panel_Device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,16 @@ namespace lgfx
const config_t& config(void) const { return _cfg; }
void config(const config_t& cfg) { _cfg = cfg; }

virtual bool init(bool use_reset);
virtual bool initTouch(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; }
IBus* bus(void) const { return _bus; }


void setLight(ILight* light) { _light = light; }
void light(ILight* light) { _light = light; }
ILight* getLight(void) const { return _light; }
Expand All @@ -138,7 +140,6 @@ namespace lgfx
bool isReadable(void) const override { return _cfg.readable; }
bool isBusShared(void) const override { return _cfg.bus_shared; }

bool init(bool use_reset) override;
void initDMA(void) override;
void waitDMA(void) override;
bool dmaBusy(void) override;
Expand Down Expand Up @@ -207,9 +208,10 @@ namespace lgfx
void initBus(void) override {}
void releaseBus(void) override {}

bool init(bool use_reset) override { return false; }

void beginTransaction(void) override {}
void endTransaction(void) override {}
bool init(bool use_reset) override { return false; }

color_depth_t setColorDepth(color_depth_t depth) override { return depth; }

Expand Down
2 changes: 2 additions & 0 deletions src/lgfx/v1/platforms/esp32/Bus_Parallel8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ namespace lgfx
#define SAFE_I2S_FIFO_WR_REG(i) (0x3FF4F000 + ((i)*0x1E000))
#define SAFE_I2S_FIFO_RD_REG(i) (0x3FF4F004 + ((i)*0x1E000))

static constexpr std::size_t CACHE_THRESH = 256;

static constexpr std::uint32_t _conf_reg_default = I2S_TX_MSB_RIGHT | I2S_TX_RIGHT_FIRST | I2S_RX_RIGHT_FIRST;
static constexpr std::uint32_t _conf_reg_start = _conf_reg_default | I2S_TX_START;
static constexpr std::uint32_t _conf_reg_reset = _conf_reg_default | I2S_TX_RESET;
Expand Down
1 change: 0 additions & 1 deletion src/lgfx/v1/platforms/esp32/Bus_Parallel8.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ namespace lgfx
private:

static constexpr std::size_t CACHE_SIZE = 260;
static constexpr std::size_t CACHE_THRESH = 256;
// static constexpr std::size_t CACHE_SIZE = 68;
// static constexpr std::size_t CACHE_THRESH = 64;

Expand Down
23 changes: 12 additions & 11 deletions src/lgfx/v1/platforms/esp32/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,15 +486,13 @@ namespace lgfx
cpp::result<void, error_t> init(int i2c_port, int pin_sda, int pin_scl)
{
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);
}

auto dev = (i2c_port == 0) ? &I2C0 : &I2C1;
i2c_context[i2c_port].save_reg(dev);
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);
i2c_context[i2c_port].load_reg(dev);

return {};
}
Expand All @@ -503,11 +501,14 @@ namespace lgfx
{
if (i2c_port >= I2C_NUM_MAX) { return cpp::fail(error_t::invalid_arg); }

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;
if (i2c_context[i2c_port].pin_scl >= 0 || i2c_context[i2c_port].pin_sda >= 0)
{
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
3 changes: 2 additions & 1 deletion src/lgfx/v1/touch/Touch_FT5x06.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace lgfx
std::uint8_t tmp[2] = { 0 };
_inited = _write_reg(0x00, 0x00)
&& _read_reg(FT5x06_VENDID_REG, tmp, 1)
&& _write_reg(FT5x06_INTMODE_REG, 0x00) // INT Polling mode
&& tmp[0]
;

Expand All @@ -70,7 +71,7 @@ namespace lgfx
lgfx::pinMode(_cfg.pin_int, pin_mode_t::input_pullup);
}

return true;
return _check_init();
}

void Touch_FT5x06::wakeup(void)
Expand Down

0 comments on commit e069f9e

Please sign in to comment.