Skip to content

Commit 4432dee

Browse files
authored
Merge pull request #44 from m5stack/develop
0.1.4
2 parents d231aa9 + 35e8f4a commit 4432dee

26 files changed

+550
-174
lines changed

examples/Basic/drawImageData/drawImageData.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11

22
#include <Arduino.h>
3+
4+
// If you want to use a set of functions to handle SD/SPIFFS/HTTP,
5+
// please include <SD.h>,<SPIFFS.h>,<HTTPClient.h> before <M5GFX.h>
36
// #include <SD.h>
47
// #include <SPIFFS.h>
58
// #include <HTTPClient.h>

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"type": "git",
1111
"url": "https://github.com/m5stack/M5GFX.git"
1212
},
13-
"version": "0.1.3",
13+
"version": "0.1.4",
1414
"frameworks": ["arduino", "espidf"],
1515
"platforms": "espressif32",
1616
"headers": "M5GFX.h"

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=M5GFX
2-
version=0.1.3
2+
version=0.1.4
33
author=M5Stack
44
maintainer=M5Stack
55
sentence=Library for M5Stack All Display

src/M5AtomDisplay.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,33 @@ class M5AtomDisplay : public M5GFX
5151

5252
public:
5353

54+
struct config_t
55+
{
56+
uint16_t logical_width = M5ATOMDISPLAY_LOGICAL_WIDTH;
57+
uint16_t logical_height = M5ATOMDISPLAY_LOGICAL_HEIGHT;
58+
float refresh_rate = M5ATOMDISPLAY_REFRESH_RATE;
59+
uint16_t output_width = M5ATOMDISPLAY_OUTPUT_WIDTH;
60+
uint16_t output_height = M5ATOMDISPLAY_OUTPUT_HEIGHT;
61+
uint_fast8_t scale_w = M5ATOMDISPLAY_SCALE_W;
62+
uint_fast8_t scale_h = M5ATOMDISPLAY_SCALE_H;
63+
uint32_t pixel_clock = M5ATOMDISPLAY_PIXELCLOCK;
64+
};
65+
66+
config_t config(void) const { return config_t(); }
67+
68+
M5AtomDisplay( const config_t& cfg )
69+
{
70+
_board = lgfx::board_t::board_M5AtomDisplay;
71+
_cfg_reso.logical_width = cfg.logical_width;
72+
_cfg_reso.logical_height = cfg.logical_height;
73+
_cfg_reso.refresh_rate = cfg.refresh_rate;
74+
_cfg_reso.output_width = cfg.output_width;
75+
_cfg_reso.output_height = cfg.output_height;
76+
_cfg_reso.scale_w = cfg.scale_w;
77+
_cfg_reso.scale_h = cfg.scale_h;
78+
_cfg_reso.pixel_clock = cfg.pixel_clock;
79+
}
80+
5481
M5AtomDisplay( uint16_t logical_width = M5ATOMDISPLAY_LOGICAL_WIDTH
5582
, uint16_t logical_height = M5ATOMDISPLAY_LOGICAL_HEIGHT
5683
, float refresh_rate = M5ATOMDISPLAY_REFRESH_RATE

src/M5GFX.cpp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <esp_log.h>
1111
#include <driver/i2c.h>
1212
#include <soc/efuse_reg.h>
13+
#include <soc/gpio_reg.h>
1314

1415
#include "lgfx/v1/panel/Panel_ILI9342.hpp"
1516
#include "lgfx/v1/panel/Panel_ST7735.hpp"
@@ -306,7 +307,7 @@ namespace m5gfx
306307
*(volatile uint32_t*)GPIO_FUNC35_OUT_SEL_CFG_REG = flg ? 0x43 : 0x100;
307308
if (flg == false)
308309
{ // CS low の場合はD/Cとして扱うためGPIO出力を有効にする;
309-
*(volatile uint32_t*)GPIO_ENABLE1_W1TS_REG = (0x1 << (GPIO_NUM_35 - 32));
310+
*(volatile uint32_t*)GPIO_ENABLE1_W1TS_REG = (0x1 << (GPIO_NUM_35 & 31));
310311
}
311312
}
312313
};
@@ -370,6 +371,27 @@ namespace m5gfx
370371
}
371372
};
372373

374+
struct Light_M5AtomS3 : public lgfx::Light_PWM
375+
{
376+
Light_M5AtomS3(void)
377+
{
378+
auto cfg = config();
379+
/// The backlight of AtomS3 does not light up if the PWM cycle is too fast.
380+
cfg.freq = 240;
381+
cfg.pin_bl = GPIO_NUM_16;
382+
cfg.pwm_channel = 7;
383+
config(cfg);
384+
}
385+
386+
void setBrightness(uint8_t brightness) override
387+
{
388+
if (brightness)
389+
{
390+
brightness = brightness - (brightness >> 3) + 31;
391+
}
392+
Light_PWM::setBrightness(brightness);
393+
}
394+
};
373395

374396

375397
#endif
@@ -944,7 +966,6 @@ namespace m5gfx
944966
cfg.pin_int = GPIO_NUM_36;
945967
cfg.pin_sda = GPIO_NUM_21;
946968
cfg.pin_scl = GPIO_NUM_22;
947-
cfg.i2c_addr = 0x14;
948969
#ifdef _M5EPD_H_
949970
cfg.i2c_port = I2C_NUM_0;
950971
#else
@@ -958,11 +979,6 @@ namespace m5gfx
958979
cfg.offset_rotation = 1;
959980
cfg.bus_shared = false;
960981
t->config(cfg);
961-
if (!t->init())
962-
{
963-
cfg.i2c_addr = 0x5D; // addr change (0x14 or 0x5D)
964-
t->config(cfg);
965-
}
966982
_panel_last->touch(t);
967983
}
968984
goto init_clear;
@@ -1023,7 +1039,7 @@ namespace m5gfx
10231039
p->config(cfg);
10241040
}
10251041
_panel_last.reset(p);
1026-
_set_pwm_backlight(GPIO_NUM_16, 7, 240); /// AtomS3LCDのバックライトはPWM周期が速いと点灯しない;
1042+
_set_backlight(new Light_M5AtomS3());
10271043

10281044
goto init_clear;
10291045
}
@@ -1113,7 +1129,7 @@ namespace m5gfx
11131129
void M5GFX::progressBar(int x, int y, int w, int h, uint8_t val)
11141130
{
11151131
drawRect(x, y, w, h, 0x09F1);
1116-
fillRect(x + 1, y + 1, w * (((float)val) / 100.0), h - 1, 0x09F1);
1132+
fillRect(x + 1, y + 1, w * (((float)val) / 100.0f), h - 1, 0x09F1);
11171133
}
11181134

11191135
void M5GFX::pushState(void)

src/M5ModuleDisplay.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,33 @@ class M5ModuleDisplay : public M5GFX
5151

5252
public:
5353

54+
struct config_t
55+
{
56+
uint16_t logical_width = M5MODULEDISPLAY_LOGICAL_WIDTH;
57+
uint16_t logical_height = M5MODULEDISPLAY_LOGICAL_HEIGHT;
58+
float refresh_rate = M5MODULEDISPLAY_REFRESH_RATE;
59+
uint16_t output_width = M5MODULEDISPLAY_OUTPUT_WIDTH;
60+
uint16_t output_height = M5MODULEDISPLAY_OUTPUT_HEIGHT;
61+
uint_fast8_t scale_w = M5MODULEDISPLAY_SCALE_W;
62+
uint_fast8_t scale_h = M5MODULEDISPLAY_SCALE_H;
63+
uint32_t pixel_clock = M5MODULEDISPLAY_PIXELCLOCK;
64+
};
65+
66+
config_t config(void) const { return config_t(); }
67+
68+
M5ModuleDisplay( const config_t& cfg )
69+
{
70+
_board = lgfx::board_t::board_M5ModuleDisplay;
71+
_cfg_reso.logical_width = cfg.logical_width;
72+
_cfg_reso.logical_height = cfg.logical_height;
73+
_cfg_reso.refresh_rate = cfg.refresh_rate;
74+
_cfg_reso.output_width = cfg.output_width;
75+
_cfg_reso.output_height = cfg.output_height;
76+
_cfg_reso.scale_w = cfg.scale_w;
77+
_cfg_reso.scale_h = cfg.scale_h;
78+
_cfg_reso.pixel_clock = cfg.pixel_clock;
79+
}
80+
5481
M5ModuleDisplay( uint16_t logical_width = M5MODULEDISPLAY_LOGICAL_WIDTH
5582
, uint16_t logical_height = M5MODULEDISPLAY_LOGICAL_HEIGHT
5683
, float refresh_rate = M5MODULEDISPLAY_REFRESH_RATE
@@ -107,11 +134,15 @@ class M5ModuleDisplay : public M5GFX
107134

108135
if (0x03 == m5gfx::i2c::readRegister8(1, 0x34, 0x03, 400000))
109136
{ // M5Stack Core2 / Tough
137+
#if defined ( ESP_LOGD )
110138
ESP_LOGD("LGFX","ModuleDisplay with Core2/Tough");
139+
#endif
111140
}
112141
else
113142
{ // M5Stack BASIC / FIRE / GO
143+
#if defined ( ESP_LOGD )
114144
ESP_LOGD("LGFX","ModuleDisplay with Core Basic/Fire/Go");
145+
#endif
115146
i2c_port = 0;
116147
spi_cs = GPIO_NUM_13;
117148
spi_miso = GPIO_NUM_19;

src/M5ModuleRCA.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,26 @@ class M5ModuleRCA : public M5GFX
5555
psram_use = 2,
5656
};
5757

58+
struct config_t
59+
{
60+
uint16_t logical_width = M5MODULERCA_LOGICAL_WIDTH;
61+
uint16_t logical_height = M5MODULERCA_LOGICAL_HEIGHT;
62+
uint16_t output_width = M5MODULERCA_OUTPUT_WIDTH;
63+
uint16_t output_height = M5MODULERCA_OUTPUT_HEIGHT;
64+
signal_type_t signal_type = M5MODULERCA_SIGNAL_TYPE;
65+
use_psram_t use_psram = M5MODULERCA_USE_PSRAM;
66+
uint8_t pin_dac = M5MODULERCA_PIN_DAC;
67+
uint8_t output_level = M5MODULERCA_OUTPUT_LEVEL;
68+
};
69+
70+
config_t config(void) const { return config_t(); }
71+
72+
M5ModuleRCA( const config_t& cfg )
73+
{
74+
_board = lgfx::board_t::board_M5ModuleRCA;
75+
setup(cfg.logical_width, cfg.logical_height, cfg.output_width, cfg.output_height, cfg.signal_type, cfg.use_psram, cfg.pin_dac, cfg.output_level);
76+
}
77+
5878
M5ModuleRCA( uint16_t logical_width = M5MODULERCA_LOGICAL_WIDTH
5979
, uint16_t logical_height = M5MODULERCA_LOGICAL_HEIGHT
6080
, uint16_t output_width = M5MODULERCA_OUTPUT_WIDTH
@@ -126,19 +146,27 @@ class M5ModuleRCA : public M5GFX
126146
if (_cfg_detail.output_level == 0) {
127147
if (0x03 == m5gfx::i2c::readRegister8(1, 0x34, 0x03, 400000))
128148
{ // M5Stack Core2 / Tough
149+
#if defined ( ESP_LOGD )
129150
ESP_LOGD("LGFX","ModuleRCA with Core2/Tough");
151+
#endif
130152
_cfg_detail.output_level = 200;
131153
}
132154
else
133155
{ // M5Stack BASIC / FIRE / GO
156+
#if defined ( ESP_LOGD )
134157
ESP_LOGD("LGFX","ModuleRCA with Core Basic/Fire/Go");
158+
#endif
135159
_cfg_detail.output_level = 128;
136160
}
137161
}
138162
#endif
139163

164+
_cfg.offset_rotation = 3;
165+
_cfg.bus_shared = false;
166+
140167
p->config_detail(_cfg_detail);
141168
p->config(_cfg);
169+
p->setRotation(1);
142170
setPanel(p);
143171

144172
if (lgfx::LGFX_Device::init_impl(use_reset, use_clear))

src/M5UnitLCD.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ class M5UnitLCD : public M5GFX
5555

5656
public:
5757

58+
struct config_t
59+
{
60+
uint8_t pin_sda = 255;
61+
uint8_t pin_scl = 255;
62+
uint8_t i2c_addr = M5UNITLCD_ADDR;
63+
int8_t i2c_port = -1;
64+
uint32_t i2c_freq = M5UNITLCD_FREQ;
65+
};
66+
67+
config_t config(void) const { return config_t(); }
68+
69+
M5UnitLCD(const config_t &cfg)
70+
{
71+
uint8_t pin_sda = cfg.pin_sda < GPIO_NUM_MAX ? cfg.pin_sda : M5UNITLCD_SDA;
72+
uint8_t pin_scl = cfg.pin_scl < GPIO_NUM_MAX ? cfg.pin_scl : M5UNITLCD_SCL;
73+
setup(pin_sda, pin_scl, cfg.i2c_freq, cfg.i2c_port, cfg.i2c_addr);
74+
}
75+
5876
M5UnitLCD(uint8_t pin_sda = M5UNITLCD_SDA, uint8_t pin_scl = M5UNITLCD_SCL, uint32_t i2c_freq = M5UNITLCD_FREQ, int8_t i2c_port = -1, uint8_t i2c_addr = M5UNITLCD_ADDR)
5977
{
6078
setup(pin_sda, pin_scl, i2c_freq, i2c_port, i2c_addr);
@@ -69,6 +87,7 @@ class M5UnitLCD : public M5GFX
6987

7088
void setup(uint8_t pin_sda = M5UNITLCD_SDA, uint8_t pin_scl = M5UNITLCD_SCL, uint32_t i2c_freq = M5UNITLCD_FREQ, int8_t i2c_port = -1, uint8_t i2c_addr = M5UNITLCD_ADDR)
7189
{
90+
_board = lgfx::board_t::board_M5UnitLCD;
7291
if (i2c_port < 0)
7392
{
7493
i2c_port = 0;
@@ -88,10 +107,7 @@ class M5UnitLCD : public M5GFX
88107
_bus_cfg.i2c_port = i2c_port;
89108
_bus_cfg.i2c_addr = i2c_addr;
90109
_bus_cfg.prefix_len = 0;
91-
92-
93110
}
94-
_board = lgfx::board_t::board_M5UnitLCD;
95111
}
96112

97113
bool init_impl(bool use_reset, bool use_clear)
@@ -111,6 +127,7 @@ class M5UnitLCD : public M5GFX
111127
cfg.panel_height = 240;
112128
cfg.offset_x = 0;
113129
cfg.offset_rotation = 0;
130+
cfg.bus_shared = false;
114131
p->config(cfg);
115132
}
116133
setPanel(p);

src/M5UnitOLED.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ class M5UnitOLED : public M5GFX
5555

5656
public:
5757

58+
struct config_t
59+
{
60+
uint8_t pin_sda = 255;
61+
uint8_t pin_scl = 255;
62+
uint8_t i2c_addr = M5UNITOLED_ADDR;
63+
int8_t i2c_port = -1;
64+
uint32_t i2c_freq = M5UNITOLED_FREQ;
65+
};
66+
67+
config_t config(void) const { return config_t(); }
68+
69+
M5UnitOLED(const config_t &cfg)
70+
{
71+
uint8_t pin_sda = cfg.pin_sda < GPIO_NUM_MAX ? cfg.pin_sda : M5UNITOLED_SDA;
72+
uint8_t pin_scl = cfg.pin_scl < GPIO_NUM_MAX ? cfg.pin_scl : M5UNITOLED_SCL;
73+
setup(pin_sda, pin_scl, cfg.i2c_freq, cfg.i2c_port, cfg.i2c_addr);
74+
}
75+
5876
M5UnitOLED(uint8_t pin_sda = M5UNITOLED_SDA, uint8_t pin_scl = M5UNITOLED_SCL, uint32_t i2c_freq = M5UNITOLED_FREQ, int8_t i2c_port = -1, uint8_t i2c_addr = M5UNITOLED_ADDR)
5977
{
6078
setup(pin_sda, pin_scl, i2c_freq, i2c_port, i2c_addr);
@@ -69,6 +87,7 @@ class M5UnitOLED : public M5GFX
6987

7088
void setup(uint8_t pin_sda = M5UNITOLED_SDA, uint8_t pin_scl = M5UNITOLED_SCL, uint32_t i2c_freq = M5UNITOLED_FREQ, int8_t i2c_port = -1, uint8_t i2c_addr = M5UNITOLED_ADDR)
7189
{
90+
_board = lgfx::board_t::board_M5UnitOLED;
7291
if (i2c_port < 0)
7392
{
7493
i2c_port = 0;
@@ -91,7 +110,6 @@ class M5UnitOLED : public M5GFX
91110
_bus_cfg.prefix_data = 0x40;
92111
_bus_cfg.prefix_len = 1;
93112
}
94-
_board = lgfx::board_t::board_M5UnitOLED;
95113
}
96114

97115
bool init_impl(bool use_reset, bool use_clear)
@@ -107,6 +125,7 @@ class M5UnitOLED : public M5GFX
107125
auto cfg = p->config();
108126
cfg.panel_width = 64;
109127
cfg.offset_x = 32;
128+
cfg.bus_shared = false;
110129
p->config(cfg);
111130
}
112131
setPanel(p);

0 commit comments

Comments
 (0)