Skip to content

Commit

Permalink
Merge pull request #49 from m5stack/develop
Browse files Browse the repository at this point in the history
0.1.6
  • Loading branch information
lovyan03 authored Apr 27, 2023
2 parents 70d59d7 + 7016dc8 commit 5495e8f
Show file tree
Hide file tree
Showing 24 changed files with 299 additions and 112 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.git"
},
"version": "0.1.5",
"version": "0.1.6",
"frameworks": ["arduino", "espidf"],
"platforms": "espressif32",
"headers": "M5GFX.h"
Expand Down
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.1.5
version=0.1.6
author=M5Stack
maintainer=M5Stack
sentence=Library for M5Stack All Display
Expand Down
32 changes: 16 additions & 16 deletions src/M5GFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ namespace m5gfx
bus->endTransaction();
_pin_level(pin_cs, true);

ESP_LOGD(LIBRARY_NAME, "[Autodetect] read cmd:%02lx = %08lx", cmd, res);
ESP_LOGD(LIBRARY_NAME, "[Autodetect] read cmd:%02" PRIx32 " = %08" PRIx32, cmd, res);
return res;
}

Expand Down Expand Up @@ -509,39 +509,39 @@ namespace m5gfx

if (0 == nvs_board)
{
#if defined ( ARDUINO_M5Stack_Core_ESP32 ) || defined ( ARDUINO_M5STACK_FIRE )
#if defined ( ARDUINO_M5STACK_CORE_ESP32 ) || defined ( ARDUINO_M5STACK_FIRE ) || defined ( ARDUINO_M5Stack_Core_ESP32 )

nvs_board = board_t::board_M5Stack;

#elif defined ( ARDUINO_M5STACK_Core2 )
#elif defined ( ARDUINO_M5STACK_CORE2 ) || defined ( ARDUINO_M5STACK_Core2 )

nvs_board = board_t::board_M5StackCore2;

#elif defined ( ARDUINO_M5Stick_C )
#elif defined ( ARDUINO_M5STICK_C ) || defined ( ARDUINO_M5Stick_C )

nvs_board = board_t::board_M5StickC;

#elif defined ( ARDUINO_M5Stick_C_Plus )
#elif defined ( ARDUINO_M5STICK_C_PLUS ) || defined ( ARDUINO_M5Stick_C_Plus )

nvs_board = board_t::board_M5StickCPlus;

#elif defined ( ARDUINO_M5Stack_CoreInk )
#elif defined ( ARDUINO_M5STACK_COREINK ) || defined ( ARDUINO_M5Stack_CoreInk )

nvs_board = board_t::board_M5StackCoreInk;

#elif defined ( ARDUINO_M5STACK_Paper )
#elif defined ( ARDUINO_M5STACK_PAPER ) || defined ( ARDUINO_M5STACK_Paper )

nvs_board = board_t::board_M5Paper;

#elif defined ( ARDUINO_M5STACK_TOUGH )

nvs_board = board_t::board_M5Tough;

#elif defined ( ARDUINO_M5Stack_ATOM )
#elif defined ( ARDUINO_M5STACK_ATOM ) || defined ( ARDUINO_M5Stack_ATOM )

nvs_board = board_t::board_M5Atom;

//#elif defined ( ARDUINO_M5Stack_Timer_CAM )
//#elif defined ( ARDUINO_M5STACK_TIMER_CAM ) || defined ( ARDUINO_M5Stack_Timer_CAM )
#endif
}

Expand All @@ -552,11 +552,11 @@ namespace m5gfx
{
if (retry == 1) use_reset = true;
board = autodetect(use_reset, board);
//ESP_LOGD(LIBRARY_NAME,"autodetect board:%d", board);
//ESP_LOGD(LIBRARY_NAME,"autodetect board:%" PRIu32, board);
} while (board_t::board_unknown == board && --retry >= 0);
_board = board;

#if defined ( ARDUINO_M5Stack_ATOM )
#if defined ( ARDUINO_M5STACK_ATOM ) || defined ( ARDUINO_M5Stack_ATOM )

if (board == board_t::board_unknown || board == board_t::board_M5Atom)
{
Expand All @@ -571,7 +571,7 @@ namespace m5gfx

if (nvs_board != board) {
if (0 == nvs_open(LIBRARY_NAME, NVS_READWRITE, &nvs_handle)) {
ESP_LOGI(LIBRARY_NAME, "[Autodetect] save to NVS : board:%d", board);
ESP_LOGI(LIBRARY_NAME, "[Autodetect] save to NVS : board:%" PRIu32, board);
nvs_set_u32(nvs_handle, NVS_KEY, board);
nvs_close(nvs_handle);
}
Expand Down Expand Up @@ -600,7 +600,7 @@ namespace m5gfx
std::uint32_t id;

std::uint32_t pkg_ver = m5gfx::get_pkg_ver();
// ESP_LOGD(LIBRARY_NAME, "pkg_ver : %02x", pkg_ver);
// ESP_LOGD(LIBRARY_NAME, "pkg_ver : %02" PRIx32, pkg_ver);

if (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4) /// check PICO-D4 (M5StickC,CPlus,T,T2 / CoreInk / ATOM )
{
Expand Down Expand Up @@ -1005,7 +1005,7 @@ namespace m5gfx
std::uint32_t id;

// std::uint32_t pkg_ver = m5gfx::get_pkg_ver();
// ESP_LOGE("DEBUG","pkg_ver:%02x", pkg_ver);
// ESP_LOGE("DEBUG","pkg_ver:%02" PRIx32, pkg_ver);

if (board == 0 || board == board_t::board_M5AtomS3)
{
Expand Down Expand Up @@ -1054,8 +1054,8 @@ namespace m5gfx
{
lgfx::i2c::init(i2c_port, i2c_sda, i2c_scl);

// ESP_LOGI("DEBUG","AW 0x10 :%02x ", lgfx::i2c::readRegister8(i2c_port, aw9523_i2c_addr, 0x10, 400000).value());
// ESP_LOGI("DEBUG","AXP0x03 :%02x ", lgfx::i2c::readRegister8(i2c_port, axp_i2c_addr, 0x03, 400000).value());
// ESP_LOGI("DEBUG","AW 0x10 :%02" PRIx32, lgfx::i2c::readRegister8(i2c_port, aw9523_i2c_addr, 0x10, 400000).value());
// ESP_LOGI("DEBUG","AXP0x03 :%02" PRIx32, lgfx::i2c::readRegister8(i2c_port, axp_i2c_addr, 0x03, 400000).value());

auto chk_axp = lgfx::i2c::readRegister8(i2c_port, axp_i2c_addr, 0x03, i2c_freq);
if (chk_axp.has_value() && chk_axp.value() == 0x4A)
Expand Down
1 change: 1 addition & 0 deletions src/lgfx/v1/Bus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ namespace lgfx
virtual void endRead(void) = 0;
virtual uint32_t readData(uint_fast8_t bit_length) = 0;
virtual bool readBytes(uint8_t* dst, uint32_t length, bool use_dma = false) = 0;
virtual bool readBytes(uint8_t* dst, uint32_t length, bool use_dma, bool last_nack) { return readBytes(dst, length, use_dma); }
virtual void readPixels(void* dst, pixelcopy_t* pc, uint32_t length) = 0;
};

Expand Down
4 changes: 2 additions & 2 deletions src/lgfx/v1/LGFXBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1361,10 +1361,10 @@ namespace lgfx
if (left < right)
{
pc->src_x32 = iA[2] + left * iA[0];
if (static_cast<uint32_t>(pc->src_x) < pc->src_width)
if (static_cast<uint32_t>(pc->src_x) < static_cast<uint32_t>(pc->src_width))
{
pc->src_y32 = iA[5] + left * iA[3];
if (static_cast<uint32_t>(pc->src_y) < pc->src_height)
if (static_cast<uint32_t>(pc->src_y) < static_cast<uint32_t>(pc->src_height))
{
pc->src_x32_add = iA[0];
pc->src_y32_add = iA[3];
Expand Down
1 change: 1 addition & 0 deletions src/lgfx/v1/LGFX_Sprite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ namespace lgfx
setColorDepth(_write_conv.depth);
}

LGFX_INLINE LovyanGFX* getParent(void) const { return _parent; }
LGFX_INLINE void* getBuffer(void) const { return _panel_sprite.getBuffer(); }
uint32_t bufferLength(void) const { return _panel_sprite.bufferLength(); }

Expand Down
2 changes: 1 addition & 1 deletion src/lgfx/v1/gitTagVersion.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define LGFX_VERSION_MAJOR 1
#define LGFX_VERSION_MINOR 1
#define LGFX_VERSION_PATCH 5
#define LGFX_VERSION_PATCH 6
#define LOVYANGFX_VERSION F( LGFX_VERSION_MAJOR "." LGFX_VERSION_MINOR "." LGFX_VERSION_PATCH )
8 changes: 4 additions & 4 deletions src/lgfx/v1/misc/pixelcopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ namespace lgfx
, dst_depth ( dst_depth_ )
, src_data ( src_data_ )
, palette ( src_palette_)
, src_mask ( (1 << src_bits) - 1 )
, dst_mask ( (1 << dst_bits) - 1 )
, src_mask ( (1 << (src_depth_ & color_depth_t::bit_mask)) - 1 )
, dst_mask ( (1 << (dst_depth_ & color_depth_t::bit_mask)) - 1 )
, no_convert( src_depth_ == dst_depth_ )
{
if (dst_palette_ || dst_bits < 8) {
Expand Down Expand Up @@ -135,10 +135,10 @@ namespace lgfx
{
uint32_t alp = 0;
uint32_t x = src_x32 >> FP_SCALE;
if (x < param->src_width)
if (x < static_cast<uint32_t>(param->src_width))
{
uint32_t y = src_y32 >> FP_SCALE;
if (y < param->src_height)
if (y < static_cast<uint32_t>(param->src_height))
{
uint32_t i = (x + y * src_bitwidth) * src_bits;
alp = k * ((pgm_read_byte(&s[i >> 3]) >> (-((int32_t)i + src_bits) & 7)) & param->src_mask);
Expand Down
18 changes: 12 additions & 6 deletions src/lgfx/v1/misc/pixelcopy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,10 @@ namespace lgfx

int32_t x = param->src_x;
int32_t y = param->src_y;
if (param->src_x == param->src_xe && param->src_y == param->src_ye && static_cast<uint32_t>(param->src_x) < src_width && static_cast<uint32_t>(param->src_y) < src_height)
if (param->src_x == param->src_xe
&& param->src_y == param->src_ye
&& static_cast<uint32_t>(param->src_x) < static_cast<uint32_t>(src_width)
&& static_cast<uint32_t>(param->src_y) < static_cast<uint32_t>(src_height))
{
uint32_t i = (x + y * src_bitwidth) * src_bits;
uint32_t raw = (s[i >> 3] >> (-(int32_t)(i + src_bits) & 7)) & src_mask;
Expand All @@ -308,8 +311,8 @@ namespace lgfx
{
uint32_t rate = rate_x * rate_y;
argb[4] += rate;
if (static_cast<uint32_t>(y) < src_height
&& static_cast<uint32_t>(x) < src_width)
if (static_cast<uint32_t>(y) < static_cast<uint32_t>(src_height)
&& static_cast<uint32_t>(x) < static_cast<uint32_t>(src_width))
{
uint32_t k = (i + x) * src_bits;
uint32_t raw = (s[k >> 3] >> (-(int32_t)(k + src_bits) & 7)) & src_mask;
Expand Down Expand Up @@ -376,7 +379,10 @@ namespace lgfx
int32_t x = param->src_x;
int32_t y = param->src_y;
auto color = &s[x + y * src_width];
if (param->src_x == param->src_xe && param->src_y == param->src_ye && static_cast<uint32_t>(param->src_x) < src_width && static_cast<uint32_t>(param->src_y) < src_height)
if (param->src_x == param->src_xe
&& param->src_y == param->src_ye
&& static_cast<uint32_t>(param->src_x) < static_cast<uint32_t>(src_width)
&& static_cast<uint32_t>(param->src_y) < static_cast<uint32_t>(src_height))
{
if (!(*color == param->transp))
{
Expand All @@ -397,8 +403,8 @@ namespace lgfx
{
uint32_t rate = rate_x * rate_y;
argb[4] += rate;
if (static_cast<uint32_t>(y) < src_height
&& static_cast<uint32_t>(x) < src_width
if (static_cast<uint32_t>(y) < static_cast<uint32_t>(src_height)
&& static_cast<uint32_t>(x) < static_cast<uint32_t>(src_width)
&& !(*color == param->transp))
{
if (std::is_same<TSrc, argb8888_t>::value) { rate *= color->A8(); }
Expand Down
16 changes: 14 additions & 2 deletions src/lgfx/v1/panel/Panel_FrameBufferBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ namespace lgfx
uint_fast16_t ye = _ye;
uint_fast16_t x = _xpos;
uint_fast16_t y = _ypos;
// const size_t bits = _write_bits;
const size_t bytes = _write_bits >> 3;
// auto k = _bitwidth * bits >> 3;

uint_fast8_t r = _internal_rotation;
Expand All @@ -207,7 +207,10 @@ namespace lgfx
uint_fast16_t linelength;
do {
linelength = std::min<uint_fast16_t>(xe - x + 1, length);
param->fp_copy(_lines_buffer[y], x, x + linelength, param);
auto ptr = &_lines_buffer[y][x * bytes];
param->fp_copy(ptr, 0, linelength, param);
cacheWriteBack(ptr, bytes * linelength);

if ((x += linelength) > xe)
{
x = xs;
Expand Down Expand Up @@ -242,6 +245,7 @@ namespace lgfx
}
else
{
int w = abs((int)(xe - xs)) + 1;
do
{
param->fp_copy(_lines_buffer[y], x, x + 1, param);
Expand All @@ -252,6 +256,7 @@ namespace lgfx
else
{
x = xs;
cacheWriteBack(&_lines_buffer[y][x], bytes * w);
y = (y != ye) ? (y + ay) : ys;
}
} while (--length);
Expand All @@ -277,6 +282,7 @@ namespace lgfx
do
{
memcpy(&_lines_buffer[y][x], src, w);
cacheWriteBack(&_lines_buffer[y][x], w);
src += sw;
} while (++y != h);
return;
Expand All @@ -290,6 +296,7 @@ namespace lgfx
}
uint32_t sx32 = param->src_x32;
uint32_t sy32 = param->src_y32;
uint_fast8_t bytes = _write_bits >> 3;
h += y;
do
{
Expand All @@ -299,6 +306,8 @@ namespace lgfx
&& end != (pos = param->fp_skip( pos, end, param)));
param->src_x32 = (sx32 += nextx);
param->src_y32 = (sy32 += nexty);
auto ptr = &_lines_buffer[y][x * bytes];
cacheWriteBack(ptr, bytes * end);
} while (++y != h);
}

Expand All @@ -316,9 +325,11 @@ namespace lgfx
uint32_t pos = x;
uint32_t end = pos + w;
h += y;
uint_fast16_t wbytes = (w * _write_bits) >> 3;
do
{
param->fp_copy(_lines_buffer[y], pos, end, param);
cacheWriteBack(&_lines_buffer[y][pos], wbytes);
param->src_x32 = (sx32 += nextx);
param->src_y32 = (sy32 += nexty);
} while (++y < h);
Expand Down Expand Up @@ -409,6 +420,7 @@ namespace lgfx
uint8_t* dst = &_lines_buffer[dst_y + pos][dst_x * bytes];
memcpy(buf, src, len);
memcpy(dst, buf, len);
cacheWriteBack(dst, len);
pos += add;
} while (--h);
}
Expand Down
14 changes: 9 additions & 5 deletions src/lgfx/v1/panel/Panel_M5UnitGLASS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace lgfx
{
_bus->endTransaction();
_bus->beginRead();
connected = _bus->readBytes(&res, 1);
connected = _bus->readBytes(&res, 1, false, true);
}
_bus->endTransaction();
} while (!connected && --retry >= 0);
Expand Down Expand Up @@ -140,7 +140,7 @@ namespace lgfx
_bus->writeCommand(REG_INDEX_DRAW_PICTURE | x_start << 8 | y << (3 + 16), 24);
_bus->writeCommand(index | 1 << (3+8) | 1 << 16, 24);
_bus->endTransaction();
lgfx::delayMicroseconds(index << 3); // 描画が終わるまで少し待つ
lgfx::delayMicroseconds(index << 5); // 描画が終わるまで少し待つ
index = 0;
}
}
Expand All @@ -164,12 +164,13 @@ namespace lgfx
if (_bus->writeCommand(REG_INDEX_READ_KEY + (idx & 1), 8))
{
_bus->endTransaction();
lgfx::delayMicroseconds(384); // データ取得可能になるまで少し待つ
lgfx::delayMicroseconds(512); // データ取得可能になるまで少し待つ
_bus->beginRead();
if (_bus->readBytes(&res, 1)) { retry = 0; }
if (_bus->readBytes(&res, 1, false, true)) { retry = 0; }
}
_bus->endTransaction();
} while (--retry >= 0);
_msec_busy = lgfx::millis() + 1;
return res;
}

Expand All @@ -184,10 +185,11 @@ namespace lgfx
{
_bus->endTransaction();
_bus->beginRead();
if (_bus->readBytes(&res, 1)) { retry = 0; }
if (_bus->readBytes(&res, 1, false, true)) { retry = 0; }
}
_bus->endTransaction();
} while (--retry >= 0);
_msec_busy = lgfx::millis() + 1;
return res;
}

Expand All @@ -197,6 +199,7 @@ namespace lgfx
_bus->writeCommand(REG_INDEX_BUZZER, 8);
_bus->writeCommand(freq | duty << 16 | _enable_buzzer_flg << 24, 32);
_bus->endTransaction();
_msec_busy = lgfx::millis() + 1;
}

void Panel_M5UnitGlass::setBuzzerEnable(bool enable) {
Expand All @@ -205,6 +208,7 @@ namespace lgfx
_bus->beginTransaction();
_bus->writeCommand((REG_INDEX_BUZZER + 3) | enable << 8, 16);
_bus->endTransaction();
_msec_busy = lgfx::millis() + 1;
}

void Panel_M5UnitGlass::waitBusy(void)
Expand Down
Loading

0 comments on commit 5495e8f

Please sign in to comment.