Skip to content

Commit

Permalink
Merge pull request lovyan03#98 from lovyan03/develop
Browse files Browse the repository at this point in the history
0.3.8
  • Loading branch information
lovyan03 authored Jan 27, 2021
2 parents 87dd862 + 1d74289 commit dc2e771
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 66 deletions.
42 changes: 42 additions & 0 deletions examples/Standard/LongTextScroll/LongTextScroll.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#define LGFX_AUTODETECT
#include <LovyanGFX.hpp>

LGFX lcd;
LGFX_Sprite canvas;

static constexpr char text[] = "Hello world ! こんにちは世界! this is long long string sample. 寿限無、寿限無、五劫の擦り切れ、海砂利水魚の、水行末・雲来末・風来末、喰う寝る処に住む処、藪ら柑子の藪柑子、パイポ・パイポ・パイポのシューリンガン、シューリンガンのグーリンダイ、グーリンダイのポンポコピーのポンポコナの、長久命の長助";
static constexpr size_t textlen = sizeof(text) / sizeof(text[0]);
size_t textpos = 0;

void setup(void)
{
lcd.init();

// 画面が横長になるように回転
if (lcd.width() < lcd.height()) lcd.setRotation(lcd.getRotation() ^ 1);

canvas.setColorDepth(8);
canvas.setFont(&fonts::lgfxJapanMinchoP_32);
canvas.setTextWrap(false); // 右端到達時のカーソル折り返しを禁止
canvas.createSprite(lcd.width() + 36, 36); // 画面幅+1文字分の横幅を用意
}

void loop(void)
{
int32_t cursor_x = canvas.getCursorX() - 1; // 現在のカーソル位置を取得し、1ドット左に移動
if (cursor_x <= 0) // カーソル位置が左端に到達している場合は一周したと判断
{
textpos = 0; // 文字列の読取り位置をリセット
cursor_x = lcd.width(); // 新たな文字が画面右端に描画されるようにカーソル位置を変更
}

canvas.setCursor(cursor_x, 0); // カーソル位置を更新
canvas.scroll(-1, 0); // キャンバスの内容を1ドット左にスクロール
while (textpos < textlen && cursor_x <= lcd.width()) // 画面右端に文字が書けるか判定
{
canvas.print(text[textpos++]); // 1バイトずつ出力 (マルチバイト文字でもこの処理で動作します)
cursor_x = canvas.getCursorX(); // 出力後のカーソル位置を取得
}

canvas.pushSprite(&lcd, 0, 0);
}
4 changes: 0 additions & 4 deletions examples/Standard/SaveBMP/SaveBMP.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ static constexpr char filename[] = "/lovyangfx_test.bmp";

bool saveToSD_16bit(void)
{
std::size_t dlen;

bool result = false;
File file = SD.open(filename, "w");
if (file)
Expand Down Expand Up @@ -67,8 +65,6 @@ bool saveToSD_16bit(void)

bool saveToSD_24bit(void)
{
std::size_t dlen;

bool result = false;
File file = SD.open(filename, "w");
if (file)
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"type": "git",
"url": "https://github.com/lovyan03/LovyanGFX.git"
},
"version": "0.3.7",
"version": "0.3.8",
"frameworks": ["arduino", "espidf"],
"platforms": ["espressif32", "atmelsam"],
"build": {
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=LovyanGFX
version=0.3.7
version=0.3.8
author=lovyan03
maintainer=Lovyan <[email protected]>
sentence=TFT LCD Graphics driver with touch for ESP32 and SAMD51
Expand Down
2 changes: 1 addition & 1 deletion src/gitTagVersion.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define LOVYANGFX_VERSION F("0.3.7")
#define LOVYANGFX_VERSION F("0.3.8")
4 changes: 4 additions & 0 deletions src/lgfx/LGFX_Device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,12 @@ namespace lgfx
endWrite();
}

startWrite();
invertDisplay(getInvert());
setColorDepth(getColorDepth());
setRotation(getRotation());
setBrightness(getBrightness());
endWrite();

_panel->post_init(this, use_reset);
}
Expand Down Expand Up @@ -416,6 +418,8 @@ namespace lgfx
const std::uint32_t buflen = h * _write_conv.bytes;
std::uint8_t buf[buflen];
pc_write.src_data = buf;
pc_write.src_width = 1;
pc_write.src_bitwidth = 1;
std::int32_t add = (src_x < dst_x) ? - 1 : 1;
std::int32_t pos = (src_x < dst_x) ? w - 1 : 0;
do {
Expand Down
3 changes: 3 additions & 0 deletions src/lgfx/lgfx_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace lgfx
, board_Makerfabs_MakePython
, board_M5Stack_CoreInk
, board_M5Paper
, board_ESP32_S2_Kaluga_1
};
}
using namespace boards;
Expand Down Expand Up @@ -1411,6 +1412,7 @@ namespace lgfx
virtual void skip(std::int32_t offset) = 0;
virtual bool seek(std::uint32_t offset) = 0;
virtual void close(void) = 0;
virtual std::int32_t tell(void) = 0;

__attribute__ ((always_inline)) inline void preRead(void) { if (fp_pre_read) fp_pre_read(parent); }
__attribute__ ((always_inline)) inline void postRead(void) { if (fp_post_read) fp_post_read(parent); }
Expand All @@ -1432,6 +1434,7 @@ namespace lgfx
void skip(std::int32_t offset) override { _index += offset; }
bool seek(std::uint32_t offset) override { _index = offset; return true; }
void close(void) override { }
std::int32_t tell(void) override { return _index; }

private:
const std::uint8_t* _ptr;
Expand Down
4 changes: 2 additions & 2 deletions src/lgfx/panel/PanelIlitekCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ namespace lgfx
, MAD_ML = 0x10
, MAD_BGR = 0x08
, MAD_MH = 0x04
, MAD_SS = 0x02
, MAD_GS = 0x01
, MAD_HF = 0x02
, MAD_VF = 0x01
, MAD_RGB = 0x00
};

Expand Down
29 changes: 14 additions & 15 deletions src/lgfx/panel/Panel_ILI9481.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace lgfx
panel_width = memory_width = 320;
panel_height = memory_height = 480;

freq_write = 27000000;
freq_write = 16000000;
freq_read = 16000000;
freq_fill = 27000000;
freq_fill = 16000000;
}

protected:
Expand All @@ -32,7 +32,7 @@ namespace lgfx
const std::uint8_t* getInitCommands(std::uint8_t listno) const override
{
static constexpr std::uint8_t list0[] = {
CMD::SLPOUT , CMD_INIT_DELAY, 5, // Exit sleep mode
CMD::SLPOUT , CMD_INIT_DELAY, 130, // Exit sleep mode
CMD::PWSET , 3, 0x07, 0x41, 0x1D,
CMD::VMCTR , 3, 0x00, 0x1C, 0x1F,
CMD::PWSETN , 2, 0x01, 0x11,
Expand All @@ -44,33 +44,32 @@ namespace lgfx
0xB0 , 1, 0x00, // CommandAccessProtect
0xE4 , 1, 0xA0,
0xF0 , 1, 0x01,
0xFF,0xFF, // end
};
static constexpr std::uint8_t list1[] = {

CMD::DISPON, 0, // Set display on
0xFF,0xFF, // end
};
switch (listno) {
case 0: return list0;
case 1: return list1;
default: return nullptr;
}
}

std::uint8_t getMadCtl(std::uint8_t r) const override
{
static constexpr std::uint8_t madctl_table[] = {
MAD_MX|MAD_MH ,
MAD_MV ,
MAD_MY|MAD_ML,
MAD_MV|MAD_MX|MAD_MY|MAD_MH|MAD_ML,
MAD_MX|MAD_MH|MAD_MY|MAD_ML,
MAD_MV|MAD_MX|MAD_MH ,
0,
MAD_MV| MAD_MY|MAD_ML,
MAD_HF ,
MAD_MV ,
MAD_VF,
MAD_MV|MAD_HF|MAD_VF,
MAD_HF|MAD_VF,
MAD_MV|MAD_HF ,
0,
MAD_MV| MAD_VF,
};
return madctl_table[r];
}

color_depth_t getAdjustBpp(color_depth_t) const override { return rgb888_3Byte; }
};
}

Expand Down
73 changes: 34 additions & 39 deletions src/lgfx/platforms/LGFX_PARALLEL_ESP32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,8 @@ Original Source:

namespace lgfx
{
#ifndef I2S_FIFO_WR_REG
#define I2S_FIFO_WR_REG(i) (REG_I2S_BASE(i))
#endif

#ifndef I2S_FIFO_RD_REG
#define I2S_FIFO_RD_REG(i) (REG_I2S_BASE(i+4))
#endif
#define SAFE_I2S_FIFO_WR_REG(i) (0x6000F000 + ((i)*0x1E000))
#define SAFE_I2S_FIFO_RD_REG(i) (0x6000F004 + ((i)*0x1E000))

#define MEMBER_DETECTOR(member, classname, classname_impl, valuetype) struct classname_impl { \
template<class T, valuetype V> static constexpr std::integral_constant<valuetype, T::member> check(decltype(T::member)*); \
Expand Down Expand Up @@ -334,7 +329,7 @@ namespace lgfx
*reg(I2S_FIFO_CONF_REG(_i2s_port)) = _fifo_conf_default;

while (limit--) {
*reg(I2S_FIFO_WR_REG(_i2s_port)) = data;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = data;
}
*reg(I2S_CONF_REG(_i2s_port)) = conf_start;
limit = 32;
Expand All @@ -358,9 +353,9 @@ namespace lgfx
wait();
*reg(I2S_FIFO_CONF_REG(_i2s_port)) = _fifo_conf_default;
while (limit--) {
*reg(I2S_FIFO_WR_REG(_i2s_port)) = data0;
*reg(I2S_FIFO_WR_REG(_i2s_port)) = data1;
*reg(I2S_FIFO_WR_REG(_i2s_port)) = data2;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = data0;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = data1;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = data2;
}
*reg(I2S_CONF_REG(_i2s_port)) = conf_start;
limit = 10;
Expand All @@ -373,7 +368,7 @@ namespace lgfx
wait();
*reg(I2S_SAMPLE_RATE_CONF_REG(_i2s_port)) = _sample_rate_conf_reg_32bit;
*reg(I2S_FIFO_CONF_REG(_i2s_port)) = _fifo_conf_default;
*reg(I2S_FIFO_WR_REG(_i2s_port)) = cmd << 16;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = cmd << 16;
*reg(I2S_CONF_REG(_i2s_port)) = _conf_reg_start;
//auto dummy = *reg(I2S_CONF_REG(_i2s_port));
}
Expand All @@ -383,10 +378,10 @@ namespace lgfx
wait();
*reg(I2S_SAMPLE_RATE_CONF_REG(_i2s_port)) = _sample_rate_conf_reg_32bit;
*reg(I2S_FIFO_CONF_REG(_i2s_port)) = _fifo_conf_default;
*reg(I2S_FIFO_WR_REG(_i2s_port)) = (0x100 | (data & 0xFF)) << 16;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = (0x100 | (data & 0xFF)) << 16;
while (bit_length -= 8) {
data >>= 8;
*reg(I2S_FIFO_WR_REG(_i2s_port)) = (0x100 | (data & 0xFF)) << 16;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = (0x100 | (data & 0xFF)) << 16;
}
*reg(I2S_CONF_REG(_i2s_port)) = _conf_reg_start;
//auto dummy = *reg(I2S_CONF_REG(_i2s_port));
Expand All @@ -406,15 +401,15 @@ namespace lgfx
std::uint32_t tmp = _colstart;
xs += tmp;
xe += tmp;
*reg(I2S_FIFO_WR_REG(_i2s_port)) = _cmd_caset << 16;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = _cmd_caset << 16;
if (!len32) {
*reg(I2S_FIFO_WR_REG(_i2s_port)) = xs<<16|data_wr;
*reg(I2S_FIFO_WR_REG(_i2s_port)) = xe<<16|data_wr;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = xs<<16|data_wr;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = xe<<16|data_wr;
} else {
*reg(I2S_FIFO_WR_REG(_i2s_port)) = xs<< 8|data_wr;
*reg(I2S_FIFO_WR_REG(_i2s_port)) = xs<<16|data_wr;
*reg(I2S_FIFO_WR_REG(_i2s_port)) = xe<< 8|data_wr;
*reg(I2S_FIFO_WR_REG(_i2s_port)) = xe<<16|data_wr;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = xs<< 8|data_wr;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = xs<<16|data_wr;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = xe<< 8|data_wr;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = xe<<16|data_wr;
}
}
if (_ys != ys || _ye != ye) {
Expand All @@ -423,18 +418,18 @@ namespace lgfx
std::uint32_t tmp = _rowstart;
ys += tmp;
ye += tmp;
*reg(I2S_FIFO_WR_REG(_i2s_port)) = _cmd_raset << 16;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = _cmd_raset << 16;
if (!len32) {
*reg(I2S_FIFO_WR_REG(_i2s_port)) = ys<<16|data_wr;
*reg(I2S_FIFO_WR_REG(_i2s_port)) = ye<<16|data_wr;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = ys<<16|data_wr;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = ye<<16|data_wr;
} else {
*reg(I2S_FIFO_WR_REG(_i2s_port)) = ys<< 8|data_wr;
*reg(I2S_FIFO_WR_REG(_i2s_port)) = ys<<16|data_wr;
*reg(I2S_FIFO_WR_REG(_i2s_port)) = ye<< 8|data_wr;
*reg(I2S_FIFO_WR_REG(_i2s_port)) = ye<<16|data_wr;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = ys<< 8|data_wr;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = ys<<16|data_wr;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = ye<< 8|data_wr;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = ye<<16|data_wr;
}
}
*reg(I2S_FIFO_WR_REG(_i2s_port)) = cmd << 16;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = cmd << 16;
*reg(I2S_CONF_REG(_i2s_port)) = _conf_reg_start;
/*/
Expand All @@ -450,12 +445,12 @@ namespace lgfx
std::uint32_t tmp = _colstart;
xs += tmp;
xe += tmp;
*reg(I2S_FIFO_WR_REG(_i2s_port)) = _cmd_caset;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = _cmd_caset;
if (!len32) {
*reg(I2S_FIFO_WR_REG(_i2s_port)) = xs|xe<<16|data_wr;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = xs|xe<<16|data_wr;
} else {
*reg(I2S_FIFO_WR_REG(_i2s_port)) = xs|xs<<8|data_wr;
*reg(I2S_FIFO_WR_REG(_i2s_port)) = xe|xe<<8|data_wr;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = xs|xs<<8|data_wr;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = xe|xe<<8|data_wr;
}
}
if (_ys != ys || _ye != ye) {
Expand All @@ -464,15 +459,15 @@ namespace lgfx
std::uint32_t tmp = _rowstart;
ys += tmp;
ye += tmp;
*reg(I2S_FIFO_WR_REG(_i2s_port)) = _cmd_raset;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = _cmd_raset;
if (!len32) {
*reg(I2S_FIFO_WR_REG(_i2s_port)) = ys|ye<<16|data_wr;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = ys|ye<<16|data_wr;
} else {
*reg(I2S_FIFO_WR_REG(_i2s_port)) = ys|ys<<8|data_wr;
*reg(I2S_FIFO_WR_REG(_i2s_port)) = ye|ye<<8|data_wr;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = ys|ys<<8|data_wr;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = ye|ye<<8|data_wr;
}
}
*reg(I2S_FIFO_WR_REG(_i2s_port)) = cmd;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = cmd;

*reg(I2S_CONF_REG(_i2s_port)) = _conf_reg_start;
//*/
Expand Down Expand Up @@ -695,7 +690,7 @@ namespace lgfx
std::int32_t limit = (((length>>1)-1)&(31))+1;
length -= limit << 1;
do {
*reg(I2S_FIFO_WR_REG(_i2s_port)) = data[0] << 16 | data[1] | data_wr;
*reg(SAFE_I2S_FIFO_WR_REG(_i2s_port)) = data[0] << 16 | data[1] | data_wr;
data += 2;
} while (--limit);
*reg(I2S_CONF_REG(_i2s_port)) = conf_start;
Expand Down
4 changes: 3 additions & 1 deletion src/lgfx/platforms/esp32_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ namespace lgfx
if (_spi_handle[spi_host] == nullptr) {
_spi_handle[spi_host] = spiStartBus(spi_port, SPI_CLK_EQU_SYSCLK, 0, 0);
}
periph_module_enable(spi_periph_signal[spi_host].module);
if (spi_mosi >= 0) {
gpio_lo(spi_mosi);
lgfxPinMode(spi_mosi, pin_mode_t::output);
gpio_matrix_out(spi_mosi, spi_periph_signal[spi_host].spid_out, false, false);
gpio_matrix_in(spi_mosi, spi_periph_signal[spi_host].spid_in, false);
Expand All @@ -187,12 +189,12 @@ namespace lgfx
gpio_matrix_in(spi_miso, spi_periph_signal[spi_host].spiq_in, false);
}
if (spi_sclk >= 0) {
gpio_lo(spi_sclk); // ここでLOWにしておくことで、pinMode変更によるHIGHパルスが出力されるのを防止する (CSなしパネル対策)
lgfxPinMode(spi_sclk, pin_mode_t::output);
//gpio_set_direction((gpio_num_t)_spi_sclk, GPIO_MODE_INPUT_OUTPUT);
gpio_matrix_out(spi_sclk, spi_periph_signal[spi_host].spiclk_out, false, false);
gpio_matrix_in(spi_sclk, spi_periph_signal[spi_host].spiclk_in, false);
}
periph_module_enable(spi_periph_signal[spi_host].module);
if (dma_channel) {
periph_module_enable( PERIPH_SPI_DMA_MODULE );
//Select DMA channel.
Expand Down
Loading

0 comments on commit dc2e771

Please sign in to comment.