Skip to content

Commit 6baaa4c

Browse files
authored
Merge pull request #188 from lovyan03/develop
Develop
2 parents 2f606df + cfe42b2 commit 6baaa4c

21 files changed

Lines changed: 320 additions & 121 deletions

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ set(COMPONENT_ADD_INCLUDEDIRS
33
)
44
file(GLOB SRCS
55
src/*.cpp
6-
src/lgfx/Fonts/lvgl/lv_font_*.c
76
src/lgfx/Fonts/efont/*.c
87
src/lgfx/Fonts/IPA/*.c
8+
src/lgfx/Fonts/lvgl/*.c
99
src/lgfx/utility/*.c
1010
src/lgfx/v1/*.cpp
1111
src/lgfx/v1/lv_font/*.c

src/lgfx/utility/result.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4242,7 +4242,7 @@ auto RESULT_NS_IMPL::detail::throw_bad_result_access(E&& error) -> void
42424242
std::abort();
42434243
#else
42444244
std::abort();
4245-
/* // ESP32-S3向けビルドがコンパイルエラーとなるためコメントアウト by lovyan03;
4245+
/* // ESP32-S3向けビルドがコンパイルエラーとなるためコメントアウト by lovyan03;
42464246
using exception_type = bad_result_access<
42474247
typename std::remove_const<
42484248
typename std::remove_reference<E>::type

src/lgfx/v1/LGFXBase.cpp

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,9 +1093,9 @@ namespace lgfx
10931093
auto scanline = (rgb888_t*)alloca(w * sizeof(rgb888_t));
10941094

10951095
startWrite();
1096-
for( int _y=0;_y<h;_y++ ) {
1096+
for( int _y=0;_y<(int)h;_y++ ) {
10971097
// only half of the scan line needs to be calculated, the other half is mirrored
1098-
for( int _x=0;_x<=w/2;_x++ ) {
1098+
for( int _x=0;_x<=(int)w/2;_x++ ) {
10991099
auto distance = pixelDistance( fmidx, fmidy, _x*vratio, _y*hratio );
11001100
scanline[_x] = map_gradient( distance, 0, hyp0, gradient );
11011101
scanline[(w-1)-_x] = scanline[_x];
@@ -1118,11 +1118,11 @@ namespace lgfx
11181118
bool is_vertical = style==VLINEAR;
11191119
const uint32_t gradient_len = is_vertical ? h : w;
11201120
auto scanline = (rgb888_t*)alloca(gradient_len * sizeof(rgb888_t));
1121-
for(int i=0;i<gradient_len;i++) { // memoize one gradient scanline
1121+
for(int i=0;i<(int)gradient_len;i++) { // memoize one gradient scanline
11221122
scanline[i] = map_gradient( i, 0, gradient_len, gradient );
11231123
}
11241124
startWrite();
1125-
for( int ys=0;ys<h;ys++ ) {
1125+
for( int ys=0;ys<(int)h;ys++ ) {
11261126
if( is_vertical ) { // scanline is used as an colors index
11271127
setColor(color888(scanline[ys].r, scanline[ys].g, scanline[ys].b));
11281128
drawFastHLine( x, y+ys, w );
@@ -2059,47 +2059,48 @@ namespace lgfx
20592059
uint16_t LGFXBase::decodeUTF8(uint8_t c)
20602060
{
20612061
// 7 bit Unicode Code Point
2062-
if (!(c & 0x80)) {
2063-
_decoderState = utf8_decode_state_t::utf8_state0;
2064-
return c;
2065-
}
2066-
2067-
if (_decoderState == utf8_decode_state_t::utf8_state0)
2068-
{
2069-
// 11 bit Unicode Code Point
2070-
if ((c & 0xE0) == 0xC0)
2062+
if ((c & 0x80)) {
2063+
// multibyte start or continue byte
2064+
switch (_decoderState)
20712065
{
2072-
_unicode_buffer = ((c & 0x1F)<<6);
2073-
_decoderState = utf8_decode_state_t::utf8_state1;
2074-
return 0;
2075-
}
2066+
case utf8_decode_state_t::utf8_state3:
2067+
case utf8_decode_state_t::utf8_state2:
2068+
case utf8_decode_state_t::utf8_state1:
2069+
_decoderState=(utf8_decode_state_t)((uint8_t)_decoderState-1);
2070+
_unicode_buffer |= ((c & 0x3F) << (6 * (uint8_t)_decoderState));
2071+
return _decoderState ? 0 : _unicode_buffer;
2072+
2073+
case utf8_decode_state_t::utf8_state0:
2074+
default:
2075+
// 11 bit Unicode Code Point
2076+
if ((c & 0xE0) == 0xC0)
2077+
{
2078+
_unicode_buffer = ((c & 0x1F) << (6 * 1));
2079+
_decoderState = utf8_decode_state_t::utf8_state1;
2080+
return 0;
2081+
}
20762082

2077-
// 16 bit Unicode Code Point
2078-
if ((c & 0xF0) == 0xE0)
2079-
{
2080-
_unicode_buffer = ((c & 0x0F)<<12);
2081-
_decoderState = utf8_decode_state_t::utf8_state2;
2082-
return 0;
2083-
}
2084-
// 21 bit Unicode Code Point not supported so fall-back to extended ASCII
2085-
//if ((c & 0xF8) == 0xF0) return (uint16_t)c;
2086-
}
2087-
else
2088-
{
2089-
if (_decoderState == utf8_decode_state_t::utf8_state2)
2090-
{
2091-
_unicode_buffer |= ((c & 0x3F)<<6);
2092-
_decoderState = utf8_decode_state_t::utf8_state1;
2093-
return 0;
2083+
// 16 bit Unicode Code Point
2084+
if ((c & 0xF0) == 0xE0)
2085+
{
2086+
_unicode_buffer = ((c & 0x0F) << (6 * 2));
2087+
_decoderState = utf8_decode_state_t::utf8_state2;
2088+
return 0;
2089+
}
2090+
// 21 bit Unicode Code Point not supported so fall-back to extended ASCII
2091+
if ((c & 0xF8) == 0xF0)
2092+
{
2093+
_unicode_buffer = (c & 0x07)<<(6 * 3); // 6 bits for each of the 3 bytes
2094+
_decoderState = utf8_decode_state_t::utf8_state3;
2095+
return 0;
2096+
}
2097+
// fallback to extended ASCII
2098+
break;
20942099
}
2095-
_unicode_buffer |= (c & 0x3F);
2096-
_decoderState = utf8_decode_state_t::utf8_state0;
2097-
return _unicode_buffer;
20982100
}
2099-
2101+
// single byte ASCII
21002102
_decoderState = utf8_decode_state_t::utf8_state0;
2101-
2102-
return c; // fall-back to extended ASCII
2103+
return c;
21032104
}
21042105

21052106
int32_t LGFXBase::fontHeight(const IFont* font) const

src/lgfx/v1/LGFXBase.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,7 @@ namespace lgfx
10221022
{ utf8_state0 = 0
10231023
, utf8_state1 = 1
10241024
, utf8_state2 = 2
1025+
, utf8_state3 = 3
10251026
};
10261027
utf8_decode_state_t _decoderState = utf8_state0; // UTF8 decoder state
10271028
uint16_t _unicode_buffer = 0; // Unicode code-point buffer

src/lgfx/v1/lgfx_fonts.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#ifdef max
2525
#undef max
2626
#endif
27+
#ifdef abs
28+
#undef abs
29+
#endif
2730

2831
namespace lgfx
2932
{
@@ -960,30 +963,20 @@ namespace lgfx
960963
}
961964

962965
uint8_t glyph_bpp = 8;
966+
// NOTE: LV_FONT_GLYPH_FORMAT_* are enum values (see lv_font/font.h),
967+
// not preprocessor macros, so they cannot be #ifdef'd.
963968
switch (gd.format)
964969
{
965-
#ifdef LV_FONT_GLYPH_FORMAT_A1
966970
case LV_FONT_GLYPH_FORMAT_A1:
967-
#endif
968-
#ifdef LV_FONT_GLYPH_FORMAT_A1_ALIGNED
969971
case LV_FONT_GLYPH_FORMAT_A1_ALIGNED:
970-
#endif
971972
glyph_bpp = 1;
972973
break;
973-
#ifdef LV_FONT_GLYPH_FORMAT_A2
974974
case LV_FONT_GLYPH_FORMAT_A2:
975-
#endif
976-
#ifdef LV_FONT_GLYPH_FORMAT_A2_ALIGNED
977975
case LV_FONT_GLYPH_FORMAT_A2_ALIGNED:
978-
#endif
979976
glyph_bpp = 2;
980977
break;
981-
#ifdef LV_FONT_GLYPH_FORMAT_A4
982978
case LV_FONT_GLYPH_FORMAT_A4:
983-
#endif
984-
#ifdef LV_FONT_GLYPH_FORMAT_A4_ALIGNED
985979
case LV_FONT_GLYPH_FORMAT_A4_ALIGNED:
986-
#endif
987980
glyph_bpp = 4;
988981
break;
989982
default:

src/lgfx/v1/platforms/esp32/Bus_EPD.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ bool Bus_EPD::init(void)
130130
bus_config.wr_gpio_num = (gpio_num_t)_config.pin_cl;
131131
bus_config.bus_width = _config.bus_width;
132132
for (int i = 0; i < _config.bus_width; ++i) {
133-
bus_config.data_gpio_nums[i] = _config.pin_data[i];
133+
bus_config.data_gpio_nums[i] = (gpio_num_t)_config.pin_data[i];
134134
// starting from ESP-IDF v5.4, esp_lcd_new_i80_bus removed `gpio_set_direction` call on all pins include these data pins,
135135
// for somehow unknown reason, some of data pin like GPIO11, GPIO12 are Open-Drain mode when bootup and remains OD after
136136
// `esp_lcd_new_i80_bus`, which will cause screen not works as expected.

src/lgfx/v1/platforms/esp32/Bus_Parallel8.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ Original Source:
2626
#include <soc/i2s_struct.h>
2727
#include <rom/gpio.h>
2828

29+
#if defined (ESP_IDF_VERSION_VAL) && (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 0, 0))
30+
#define LGFX_GPIO_PAD_SELECT(pin) rom_gpio_pad_select_gpio((gpio_num_t)(pin))
31+
#define LGFX_GPIO_MATRIX_OUT(pin, sig, inv, oen_inv) rom_gpio_matrix_out((gpio_num_t)(pin), (sig), (inv), (oen_inv))
32+
#else
33+
#define LGFX_GPIO_PAD_SELECT(pin) gpio_pad_select_gpio((gpio_num_t)(pin))
34+
#define LGFX_GPIO_MATRIX_OUT(pin, sig, inv, oen_inv) gpio_matrix_out((gpio_num_t)(pin), (sig), (inv), (oen_inv))
35+
#endif
36+
2937
namespace lgfx
3038
{
3139
inline namespace v1
@@ -122,21 +130,21 @@ namespace lgfx
122130
{
123131
int32_t pin = _cfg.pin_data[i];
124132
if (pin < 0) { continue; }
125-
gpio_pad_select_gpio(pin);
133+
LGFX_GPIO_PAD_SELECT(pin);
126134
gpio_set_direction((gpio_num_t)pin, GPIO_MODE_INPUT_OUTPUT);
127-
gpio_matrix_out(pin, idx_base + i, 0, 0);
135+
LGFX_GPIO_MATRIX_OUT(pin, idx_base + i, 0, 0);
128136
}
129137

130138
for (size_t i = 0; i < 3; ++i)
131139
{
132140
int32_t pin = _cfg.pin_ctrl[i];
133141
if (pin < 0) { continue; }
134-
gpio_pad_select_gpio(pin);
142+
LGFX_GPIO_PAD_SELECT(pin);
135143
gpio_hi(pin);
136144
gpio_set_direction((gpio_num_t)pin, GPIO_MODE_OUTPUT);
137145
}
138146

139-
gpio_matrix_out(_cfg.pin_rs, idx_base + 8, 0, 0);
147+
LGFX_GPIO_MATRIX_OUT(_cfg.pin_rs, idx_base + 8, 0, 0);
140148

141149
uint32_t dport_clk_en;
142150
uint32_t dport_rst;
@@ -154,7 +162,7 @@ namespace lgfx
154162
dport_rst = DPORT_I2S1_RST;
155163
}
156164
#endif
157-
gpio_matrix_out(_cfg.pin_wr, idx_base, 1, 0); // WR (Write-strobe in 8080 mode, Active-low)
165+
LGFX_GPIO_MATRIX_OUT(_cfg.pin_wr, idx_base, 1, 0); // WR (Write-strobe in 8080 mode, Active-low)
158166

159167
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, dport_clk_en);
160168
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, dport_rst);
@@ -534,7 +542,7 @@ namespace lgfx
534542
if (_cache_index) { _cache_index = _flush(_cache_index, true); }
535543
_wait();
536544

537-
gpio_matrix_out(_cfg.pin_rs, 0x100, 0, 0);
545+
LGFX_GPIO_MATRIX_OUT(_cfg.pin_rs, 0x100, 0, 0);
538546
gpio_lo(_cfg.pin_rd);
539547
}
540548

@@ -543,7 +551,7 @@ namespace lgfx
543551
gpio_hi(_cfg.pin_rd);
544552

545553
auto idx_base = (_cfg.i2s_port == I2S_NUM_0) ? I2S0O_DATA_OUT16_IDX : I2S1O_DATA_OUT16_IDX;
546-
gpio_matrix_out(_cfg.pin_rs, idx_base, 0, 0);
554+
LGFX_GPIO_MATRIX_OUT(_cfg.pin_rs, idx_base, 0, 0);
547555
}
548556

549557
void Bus_Parallel8::_read_bytes(uint8_t* __restrict dst, uint32_t length)

src/lgfx/v1/platforms/esp32/Bus_Parallel8.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ Original Source:
2727
#include <freertos/FreeRTOS.h>
2828
#endif
2929

30-
#if __has_include(<driver/i2s_std.h>)
30+
#if __has_include(<driver/i2s_types.h>)
31+
#include <driver/i2s_types.h>
32+
#elif __has_include(<driver/i2s_std.h>)
3133
#include <driver/i2s_std.h>
3234
#else
3335
#include <driver/i2s.h>

0 commit comments

Comments
 (0)