Skip to content

Commit

Permalink
Merge pull request #102 from m5stack/develop
Browse files Browse the repository at this point in the history
0.1.17
  • Loading branch information
lovyan03 authored Sep 20, 2024
2 parents fa3fc1c + f882faf commit ff11e09
Show file tree
Hide file tree
Showing 17 changed files with 253 additions and 75 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Supported device
----------------
- M5Stack ( Basic / Gray / GO / Fire )
- M5Stack Core2
- M5Stack CoreS3 / CoreS3SE
- M5Stack CoreInk
- M5Stick C
- M5Stick C Plus
Expand All @@ -23,6 +24,7 @@ Supported device
- M5Dial
- M5DinMeter
- M5Cardputer
- M5VAMeter
- UnitOLED
- UnitMiniOLED
- UnitLCD
Expand Down
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.16",
"version": "0.1.17",
"frameworks": ["arduino", "espidf", "*"],
"platforms": ["espressif32", "native"],
"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.16
version=0.1.17
author=M5Stack
maintainer=M5Stack
sentence=Library for M5Stack All Display
Expand Down
99 changes: 75 additions & 24 deletions src/M5GFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ namespace m5gfx
static constexpr int32_t i2c_freq = 400000;
static constexpr int_fast16_t aw9523_i2c_addr = 0x58; // AW9523B
static constexpr int_fast16_t axp_i2c_addr = 0x34; // AXP2101
static constexpr int_fast16_t gc0308_i2c_addr = 0x21; // GC0308
static constexpr int_fast16_t i2c_port = I2C_NUM_1;
static constexpr int_fast16_t i2c_sda = GPIO_NUM_12;
static constexpr int_fast16_t i2c_scl = GPIO_NUM_11;
Expand Down Expand Up @@ -424,6 +425,26 @@ namespace m5gfx
}
};

struct Light_M5StackAtomS3R : public lgfx::ILight
{
bool init(uint8_t brightness) override
{
lgfx::i2c::init(i2c_port, GPIO_NUM_45, GPIO_NUM_0);
lgfx::i2c::writeRegister8(i2c_port, 48, 0x00, 0b01000000, 0, i2c_freq);
lgfx::delay(1);
lgfx::i2c::writeRegister8(i2c_port, 48, 0x08, 0b00000001, 0, i2c_freq);
lgfx::i2c::writeRegister8(i2c_port, 48, 0x70, 0b00000000, 0, i2c_freq);

setBrightness(brightness);
return true;
}

void setBrightness(uint8_t brightness) override
{
lgfx::i2c::writeRegister8(i2c_port, 48, 0x0e, brightness, 0, i2c_freq);
}
};

#endif

__attribute__ ((unused))
Expand Down Expand Up @@ -1183,7 +1204,8 @@ namespace m5gfx
m5gfx::i2c::writeRegister8(i2c_port, aw9523_i2c_addr, 0x12, 0b11111111); // LEDMODE_P0
m5gfx::i2c::writeRegister8(i2c_port, aw9523_i2c_addr, 0x13, 0b11111111); // LEDMODE_P1
m5gfx::i2c::writeRegister8(i2c_port, axp_i2c_addr, 0x90, 0xBF); // LDOS ON/OFF control 0
m5gfx::i2c::writeRegister8(i2c_port, axp_i2c_addr, 0x95, 0x28); // ALDO3 set to 3.3v // for TF card slot
m5gfx::i2c::writeRegister8(i2c_port, axp_i2c_addr, 0x94, 33 - 5); // ALDO3 set to 3.3v // for GC0308 Camera
m5gfx::i2c::writeRegister8(i2c_port, axp_i2c_addr, 0x95, 33 - 5); // ALDO4 set to 3.3v // for TF card slot

bus_cfg.pin_mosi = GPIO_NUM_37;
bus_cfg.pin_miso = GPIO_NUM_35;
Expand All @@ -1199,31 +1221,14 @@ namespace m5gfx
id = _read_panel_id(bus_spi, GPIO_NUM_3);
if ((id & 0xFF) == 0xE3)
{ // check panel (ILI9342)
gpio::pin_backup_t backup_pins[] = { GPIO_NUM_38, GPIO_NUM_45, GPIO_NUM_46 };
auto result = lgfx::gpio::command(
(const uint8_t[]) {
lgfx::gpio::command_mode_input_pulldown, GPIO_NUM_38, // CoreS3 = CAM_HREF
lgfx::gpio::command_mode_input_pulldown, GPIO_NUM_45, // CoreS3 = CAM_PCLK
lgfx::gpio::command_mode_input_pulldown, GPIO_NUM_46, // CoreS3 = CAM_VSYNC
lgfx::gpio::command_mode_input_pullup , GPIO_NUM_38,
lgfx::gpio::command_read , GPIO_NUM_38,
lgfx::gpio::command_mode_input_pullup , GPIO_NUM_45,
lgfx::gpio::command_read , GPIO_NUM_45,
lgfx::gpio::command_mode_input_pullup , GPIO_NUM_46,
lgfx::gpio::command_read , GPIO_NUM_46,
lgfx::gpio::command_end
}
);
for (auto &bup : backup_pins) { bup.restore(); }

// In "CoreS3", even if GPIO38,45,46 are set to Input_pullup, LOW is output.
// This characteristic can be used to distinguish between the two models.
board = board_t::board_M5StackCoreS3;
if (result == 0b111) {
// Camera GC0308 check (not found == M5StackCoreS3SE)
auto chk_gc = lgfx::i2c::readRegister8(i2c_port, gc0308_i2c_addr, 0x00, i2c_freq);
if (chk_gc .has_value() && chk_gc .value() == 0x9b) {
ESP_LOGW(LIBRARY_NAME, "[Autodetect] board_M5StackCoreS3");
} else {
board = board_M5StackCoreS3SE;
ESP_LOGW(LIBRARY_NAME, "[Autodetect] board_M5StackCoreS3SE");
} else {
ESP_LOGW(LIBRARY_NAME, "[Autodetect] board_M5StackCoreS3");
}
bus_cfg.freq_write = 40000000;
bus_cfg.freq_read = 16000000;
Expand All @@ -1250,11 +1255,55 @@ namespace m5gfx
lgfx::i2c::release(i2c_port);
}

if (board == 0 || board == board_t::board_M5AtomS3R)
{
_pin_reset(GPIO_NUM_48, use_reset); // LCD RST
bus_cfg.pin_mosi = GPIO_NUM_21;
bus_cfg.pin_miso = (gpio_num_t)-1; //GPIO_NUM_NC;
bus_cfg.pin_sclk = GPIO_NUM_15;
bus_cfg.pin_dc = GPIO_NUM_42;
bus_cfg.spi_mode = 0;
bus_cfg.spi_3wire = true;
bus_spi->config(bus_cfg);
bus_spi->init();
id = _read_panel_id(bus_spi, GPIO_NUM_14);
if ((id & 0xFFFFFF) == 0x079100)
{ // check panel (GC9107)
board = board_t::board_M5AtomS3R;
ESP_LOGW(LIBRARY_NAME, "[Autodetect] board_M5AtomS3R");
bus_spi->release();
bus_cfg.spi_host = SPI3_HOST;
bus_cfg.freq_write = 40000000;
bus_cfg.freq_read = 16000000;
bus_spi->config(bus_cfg);
bus_spi->init();
auto p = new Panel_GC9107();
p->bus(bus_spi);
{
auto cfg = p->config();
cfg.pin_cs = GPIO_NUM_14;
cfg.pin_rst = GPIO_NUM_48;
cfg.panel_width = 128;
cfg.panel_height = 128;
cfg.offset_y = 32;
cfg.readable = false;
cfg.bus_shared = false;
p->config(cfg);
}
_panel_last.reset(p);
_set_backlight(new Light_M5StackAtomS3R());

goto init_clear;
}
lgfx::pinMode(GPIO_NUM_48, lgfx::pin_mode_t::input); // LCD RST
bus_spi->release();
}

if (board == 0 || board == board_t::board_M5AtomS3)
{
_pin_reset(GPIO_NUM_34, use_reset); // LCD RST
bus_cfg.pin_mosi = GPIO_NUM_21;
bus_cfg.pin_miso = GPIO_NUM_13;
bus_cfg.pin_miso = (gpio_num_t)-1; //GPIO_NUM_NC;
bus_cfg.pin_sclk = GPIO_NUM_17;
bus_cfg.pin_dc = GPIO_NUM_33;
bus_cfg.spi_mode = 0;
Expand Down Expand Up @@ -1586,6 +1635,7 @@ namespace m5gfx
case board_M5Tough: title = "M5Tough"; break;
case board_M5Station: title = "M5Station"; break;
case board_M5AtomS3: title = "M5AtomS3"; break;
case board_M5AtomS3R: title = "M5AtomS3R"; break;
case board_M5Dial: title = "M5Dial"; break;
case board_M5Cardputer: title = "M5Cardputer"; break;
case board_M5DinMeter: title = "M5DinMeter"; break;
Expand All @@ -1597,6 +1647,7 @@ namespace m5gfx

switch (board) {
case board_M5AtomS3:
case board_M5AtomS3R:
w = 128;
h = 128;
break;
Expand Down
3 changes: 3 additions & 0 deletions src/lgfx/boards.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace lgfx // This should not be changed to "m5gfx"
, board_M5AirQ
, board_M5VAMeter
, board_M5StackCoreS3SE
, board_M5AtomS3R

/// non display boards
, board_M5Atom = 128
Expand Down Expand Up @@ -52,6 +53,8 @@ namespace lgfx // This should not be changed to "m5gfx"
, board_M5UnitRCA
, board_M5ModuleDisplay
, board_M5ModuleRCA

, board_FrameBuffer = 512
};
}
using namespace boards;
Expand Down
31 changes: 26 additions & 5 deletions src/lgfx/v1/LGFXBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ namespace lgfx
for( int ys=0;ys<h;ys++ ) {
if( is_vertical ) { // scanline is used as an colors index
setColor(color888(scanline[ys].r, scanline[ys].g, scanline[ys].b));
drawFastHLine( x, ys, w );
drawFastHLine( x, y+ys, w );
} else { // scanline is used as a line buffer
pushImage( x, y+ys, w, 1, scanline );
}
Expand Down Expand Up @@ -1441,6 +1441,27 @@ namespace lgfx
endWrite();
}

void LGFXBase::pushAlphaImage(int32_t x, int32_t y, int32_t w, int32_t h, pixelcopy_t *param)
{
uint32_t x_mask = 7 >> (param->src_bits >> 1);
param->src_bitwidth = (w + x_mask) & (~x_mask);

int32_t dx=0, dw=w;
if (0 < _clip_l - x) { dx = _clip_l - x; dw -= dx; x = _clip_l; }

if (_adjust_width(x, dx, dw, _clip_l, _clip_r - _clip_l + 1)) return;
param->src_x32 = param->src_x32_add * dx;

int32_t dy=0, dh=h;
if (0 < _clip_t - y) { dy = _clip_t - y; dh -= dy; y = _clip_t; }
if (_adjust_width(y, dy, dh, _clip_t, _clip_b - _clip_t + 1)) return;
param->src_y = dy;

startWrite();
_panel->writeImageARGB(x, y, dw, dh, param);
endWrite();
}

void LGFXBase::make_rotation_matrix(float* result, float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y)
{
float rad = fmodf(angle, 360) * deg_to_rad;
Expand Down Expand Up @@ -1510,15 +1531,15 @@ namespace lgfx
else
if (pc_post.dst_bits > 16) {
if (dst_depth == rgb888_3Byte) {
pc_post.fp_copy = pixelcopy_t::blend_rgb_fast<bgr888_t>;
pc_post.fp_copy = pixelcopy_t::blend_rgb_fast<bgr888_t, argb8888_t>;
} else {
pc_post.fp_copy = pixelcopy_t::blend_rgb_fast<bgr666_t>;
pc_post.fp_copy = pixelcopy_t::blend_rgb_fast<bgr666_t, argb8888_t>;
}
} else {
if (dst_depth == rgb565_2Byte) {
pc_post.fp_copy = pixelcopy_t::blend_rgb_fast<swap565_t>;
pc_post.fp_copy = pixelcopy_t::blend_rgb_fast<swap565_t, argb8888_t>;
} else { // src_depth == rgb332_1Byte:
pc_post.fp_copy = pixelcopy_t::blend_rgb_fast<rgb332_t>;
pc_post.fp_copy = pixelcopy_t::blend_rgb_fast<rgb332_t, argb8888_t>;
}
}
push_image_affine_aa(matrix, pc, &pc_post);
Expand Down
29 changes: 29 additions & 0 deletions src/lgfx/v1/LGFXBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,35 @@ namespace lgfx
LGFX_INLINE_T void pushGrayscaleImageRotateZoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const uint8_t* image, color_depth_t depth, const T& forecolor, const T& backcolor) { push_grayimage_rotate_zoom(dst_x, dst_y, src_x, src_y, angle, zoom_x, zoom_y, w, h, image, depth, convert_to_rgb888(forecolor), convert_to_rgb888(backcolor)); }
LGFX_INLINE_T void pushGrayscaleImageAffine(const float matrix[6], int32_t w, int32_t h, const uint8_t* image, color_depth_t depth, const T& forecolor, const T& backcolor) { push_grayimage_affine(matrix, w, h, image, depth, convert_to_rgb888(forecolor), convert_to_rgb888(backcolor)); }

//----------------------------------------------------------------------------

// T == bgra8888_t or argb8888_t
template<typename T>
void pushAlphaImage(int32_t x, int32_t y, int32_t w, int32_t h, const T* data)
{
auto pc = create_pc(data);

// not support 1, 2, 4, and palette mode.
if (pc.dst_bits < 8 || this->hasPalette()) { return; }

if (pc.dst_bits > 16) {
if (pc.dst_depth == rgb888_3Byte) {
pc.fp_copy = pixelcopy_t::blend_rgb_fast<bgr888_t, T>;
} else {
pc.fp_copy = pixelcopy_t::blend_rgb_fast<bgr666_t, T>;
}
} else {
if (pc.dst_depth == rgb565_2Byte) {
pc.fp_copy = pixelcopy_t::blend_rgb_fast<swap565_t, T>;
} else { // src_depth == rgb332_1Byte:
pc.fp_copy = pixelcopy_t::blend_rgb_fast<rgb332_t, T>;
}
}
pushAlphaImage(x, y, w, h, &pc);
}

void pushAlphaImage(int32_t x, int32_t y, int32_t w, int32_t h, pixelcopy_t *param);

//----------------------------------------------------------------------------

/// read RGB565 16bit color
Expand Down
6 changes: 6 additions & 0 deletions src/lgfx/v1/LGFX_Sprite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ namespace lgfx
return createFromBmp(&data);
}

bool createFromBmpFile(const char *path)
{
auto data = _create_data_wrapper();
return create_from_bmp_file(data, path);
}

template <typename T>
bool createFromBmpFile(T &fs, const char *path)
{
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 16
#define LGFX_VERSION_PATCH 17
#define LOVYANGFX_VERSION F( LGFX_VERSION_MAJOR "." LGFX_VERSION_MINOR "." LGFX_VERSION_PATCH )
8 changes: 7 additions & 1 deletion src/lgfx/v1/misc/common_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ namespace lgfx

void memset_multi(uint8_t* buf, uint32_t c, size_t size, size_t length)
{
if (size == 1 || ((c & 0xFF) == ((c >> 8) & 0xFF) && (size == 2 || ((c & 0xFF) == ((c >> 16) & 0xFF)))))
if (size == 1
|| ( (c & 0xFF) == ((c >> 8) & 0xFF)
&& ( size == 2
|| ( (c & 0xFF) == ((c >> 16) & 0xFF)
&& ( size == 3
|| ( (c & 0xFF) == ((c >> 24) & 0xFF)
))))))
{
memset(buf, c, size * length);
return;
Expand Down
6 changes: 3 additions & 3 deletions src/lgfx/v1/misc/pixelcopy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,21 +449,21 @@ namespace lgfx
return last;
}

template <typename TDst>
template <typename TDst, typename TSrc>
static uint32_t blend_rgb_fast(void* __restrict dst, uint32_t index, uint32_t last, pixelcopy_t* __restrict param)
{
auto d = static_cast<TDst*>(dst);
auto src_x32_add = param->src_x32_add;
auto src_y32_add = param->src_y32_add;
auto s = static_cast<const argb8888_t*>(param->src_data);
auto s = static_cast<const TSrc*>(param->src_data);
for (;;) {
uint32_t i = param->src_x + param->src_y * param->src_bitwidth;
uint_fast16_t a = s[i].a;
if (a)
{
if (a == 255)
{
d[index].set(s[i].r, s[i].g, s[i].b);
d[index].set(s[i].R8(), s[i].G8(), s[i].B8());
param->src_x32 += src_x32_add;
param->src_y32 += src_y32_add;
if (++index == last) return last;
Expand Down
24 changes: 24 additions & 0 deletions src/lgfx/v1/panel/Panel_Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,30 @@ namespace lgfx
}

//----------------------------------------------------------------------------
void Panel_Device::writeImageARGB(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param)
{
auto src_x = param->src_x;
auto bytes = param->dst_bits >> 3;

pixelcopy_t pc_read(nullptr, _write_depth, _read_depth);
pixelcopy_t pc_write(nullptr, _write_depth, _write_depth);
for (;;)
{
uint8_t* dmabuf = _bus->getDMABuffer((w+1) * bytes);
pc_write.src_data = dmabuf;
readRect(x, y, w, 1, dmabuf, &pc_read);
{
param->fp_copy(dmabuf, 0, w, param);
pc_write.src_x = 0;
writeImage(x, y, w, 1, &pc_write, true);
}
if (!--h) return;
param->src_x = src_x;
param->src_y++;
++y;
}
}
#if 0
void Panel_Device::writeImageARGB(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param)
{
auto src_x = param->src_x;
Expand Down Expand Up @@ -237,6 +260,7 @@ namespace lgfx
++y;
}
}
#endif

void Panel_Device::copyRect(uint_fast16_t dst_x, uint_fast16_t dst_y, uint_fast16_t w, uint_fast16_t h, uint_fast16_t src_x, uint_fast16_t src_y)
{
Expand Down
Loading

0 comments on commit ff11e09

Please sign in to comment.