Skip to content

Commit

Permalink
Merge pull request #23 from lovyan03/unstable
Browse files Browse the repository at this point in the history
v0.1.14
  • Loading branch information
lovyan03 committed Jun 28, 2020
2 parents fd4e8e1 + 0ef15bc commit ea9c5c6
Show file tree
Hide file tree
Showing 18 changed files with 207 additions and 54 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ This library is also compatible with the above models and LCD panels with a simi
[examples](examples/)に具体的なサンプルがあります。
### 基本的な使い方
```c

// ※ もし対応機種を ArduinoIDE以外の環境で使用する場合や、
// 対応機種がボードマネージャに無い場合 ( TTGO T-Wristband や ESP-WROVER-KIT等 ) は、
// LovyanGFX.hppのincludeより前に、define LGFX_~ を記述してください。

// #define LGFX_M5STACK // M5Stack
// #define LGFX_M5STICKC // M5Stick C
// #define LGFX_ODROID_GO // ODROID-GO
// #define LGFX_TTGO_TS // TTGO TS
// #define LGFX_TTGO_TWATCH // TTGO T-Watch
// #define LGFX_TTGO_TWRISTBAND // TTGO T-Wristband
// #define LGFX_DDUINO32_XS // DSTIKE D-duino-32 XS
// #define LGFX_LOLIN_D32 // LoLin D32 Pro
// #define LGFX_ESP_WROVER_KIT // ESP-WROVER-KIT
// #define LGFX_WIO_TERMINAL // Wio Terminal

// ヘッダをincludeします。
#include <LovyanGFX.hpp>

Expand Down
15 changes: 15 additions & 0 deletions examples/HowToUse/1_simple_use/1_simple_use.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
// 基本的な使い方

// ※ もし対応機種を ArduinoIDE以外の環境で使用する場合や、
// 対応機種がボードマネージャに無い場合 ( TTGO T-Wristband や ESP-WROVER-KIT等 ) は、
// LovyanGFX.hppのincludeより前に、define LGFX_~ を記述してください。

// #define LGFX_M5STACK // M5Stack
// #define LGFX_M5STICKC // M5Stick C
// #define LGFX_ODROID_GO // ODROID-GO
// #define LGFX_TTGO_TS // TTGO TS
// #define LGFX_TTGO_TWATCH // TTGO T-Watch
// #define LGFX_TTGO_TWRISTBAND // TTGO T-Wristband
// #define LGFX_DDUINO32_XS // DSTIKE D-duino-32 XS
// #define LGFX_LOLIN_D32 // LoLin D32 Pro
// #define LGFX_ESP_WROVER_KIT // ESP-WROVER-KIT
// #define LGFX_WIO_TERMINAL // Wio Terminal

// ヘッダをincludeします。
#include <LovyanGFX.hpp>

Expand Down
16 changes: 3 additions & 13 deletions examples/HowToUse/2_spi_setting/2_spi_setting.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


// SPI設定用の構造体を用意します。
// 構造体の名称に決まりはありませんが
// 構造体の名称 "LGFX_Config" は変更しても構いませんが
// 構造体の各メンバ変数の名前と型は例の通りにしてください。

// for ESP32
Expand Down Expand Up @@ -77,18 +77,7 @@ struct LGFX_Config
static lgfx::LGFX_SPI<LGFX_Config> lcd;


// Panelクラスのインスタンスを作成します。使用するパネルにあったクラスを選択してください。
// ★LCD一体型製品の対応機種の場合はこちらから選択できます。
//static lgfx::Panel_DDUINO32_XS panel;
//static lgfx::Panel_LoLinD32 panel;
//static lgfx::Panel_M5Stack panel;
//static lgfx::Panel_M5StickC panel;
//static lgfx::Panel_ODROID_GO panel;
//static lgfx::Panel_TTGO_TS panel;
//static lgfx::Panel_TTGO_TWatch panel;
//static lgfx::Panel_WioTerminal panel;

// ★対応機種以外の場合はこちらから選択できます。
// Panelクラスのインスタンスを作成します。使用するパネルにあった記述をコメントアウトしてください。
//static lgfx::Panel_HX8357B panel;
//static lgfx::Panel_HX8357D panel;
//static lgfx::Panel_ILI9163 panel;
Expand Down Expand Up @@ -133,6 +122,7 @@ void setup(void)
panel.len_dummy_read_pixel = 8;

// データの読取りが可能なパネルの場合はtrueを、不可の場合はfalseを設定します。
// ※ CSピンのないST7789等はfalseにしてください。
// 省略時はtrueになります。
panel.spi_read = true;

Expand Down
2 changes: 1 addition & 1 deletion examples/Sprite/MovingCircles/MovingCircles.ino
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void loop(void)
sprites[flip].setTextColor(TFT_WHITE);
sprites[flip].printf("obj:%d fps:%d", obj_count, fps);
}
std::int32_t len = sprites[flip].bufferLength();
std::int32_t len = sprites[flip].bufferLength() >> 1;
if (y + sprite_height > lcd_height) {
len = (lcd_height - y) * lcd_width * lcd.getColorConverter()->bytes;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/Sprite/MovingIcons/MovingIcons.ino
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void loop(void)
sprites[flip].setTextColor(0xFFFFFFU);
sprites[flip].printf("obj:%d fps:%d", obj_count, fps);
}
size_t len = sprites[flip].bufferLength();
size_t len = sprites[flip].bufferLength() >> 1;
if (y + sprite_height > tft_height) {
len = (tft_height - y) * tft_width * lcd.getColorConverter()->bytes;
}
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"
},
"version": "0.1.13",
"version": "0.1.14",
"framework": "arduino",
"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.1.13
version=0.1.14
author=lovyan03
maintainer=Lovyan <42724151+lovyan03@users.noreply.github.com>
sentence=LCD Graphics driver for ESP32 and SAMD51
Expand Down
28 changes: 13 additions & 15 deletions src/LovyanGFX.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,22 @@ Original Source:


#if defined (ESP32) || (CONFIG_IDF_TARGET_ESP32)

#include "lgfx/platforms/LGFX_SPI_ESP32.hpp"

#elif defined (__SAMD51__)
#include "lgfx/platforms/LGFX_SPI_SAMD51.hpp"

#endif

// ArduinoIDEで利用する場合、ボードマネージャで選択したボードに合うConfigが読み込まれます。
// ESP-IDFやHarmonyで利用する場合は、#include<LovyanGFX.hpp> より前に #define LGFX_ボード名 の記述をしてください。
// お使いのボードが対応機種にない場合、"config/LGFX_Config_Custom" をコピーしてプロジェクトフォルダに配置し、
// 動作環境に応じて内容に修正を加えて include して使用してください。

// When using the Arduino IDE, the configuration for the board selected in the Board Manager will be loaded.
// When using ESP-IDF or Harmony, please specify a #define LGFX_M5STACK or other #define before the #include<LovyanGFX.hpp> .
// ArduinoIDEで利用する場合、ボードマネージャで選択したボードに合うConfigが読み込まれます。
// ESP-IDFやHarmonyで利用する場合は、#include<LovyanGFX.hpp> より前に #define LGFX_M5STACK 等の #define を記述してください。
// When using ESP-IDF or Harmony, please specify a #define LGFX_YOUR_BOARD before the #include<LovyanGFX.hpp> .
// If the board you are using is not supported, Put a copy of "config/LGFX_Config_Custom" in your project folder,
// and include it with modifications to the content to suit your environment.

#if defined( LGFX_M5STACK ) || defined( ARDUINO_M5Stack_Core_ESP32 ) || defined( ARDUINO_M5STACK_FIRE ) // M5Stack
#include "config/LGFX_Config_M5Stack.hpp"
Expand All @@ -82,28 +85,23 @@ Original Source:
#elif defined( LGFX_TTGO_TWATCH ) || defined( ARDUINO_T ) // TTGO T-Watch
#include "config/LGFX_Config_TTGO_TWatch.hpp"

#elif defined( LGFX_DDUINO32_XS ) || defined( ARDUINO_D ) || defined( ARDUINO_DDUINO32_XS )
#elif defined( LGFX_TTGO_TWRISTBAND ) // TTGO T-Wristband
#include "config/LGFX_Config_TTGO_TWristband.hpp"

#elif defined( LGFX_DDUINO32_XS ) || defined( ARDUINO_D ) || defined( ARDUINO_DDUINO32_XS ) // DSTIKE D-duino-32 XS
#include "config/LGFX_Config_DDUINO32_XS.hpp"

#elif defined( LGFX_LOLIN_D32 ) || defined( ARDUINO_LOLIN_D32_PRO ) // LoLin D32 Pro
#include "config/LGFX_Config_LoLinD32.hpp"

#elif defined( LGFX_ESP_WROVER_KIT ) || defined( ARDUINO_ESP32_DEV ) // ESP-WROVER-KIT
#elif defined( LGFX_ESP_WROVER_KIT ) || defined( ARDUINO_ESP32_WROVER_KIT ) // ESP-WROVER-KIT
#include "config/LGFX_Config_ESP_WROVER_KIT.hpp"

#elif defined( LGFX_WIO_TERMINAL ) || defined (ARDUINO_WIO_TERMINAL) || defined(WIO_TERMINAL)
#include "lgfx/platforms/LGFX_SPI_SAMD51.hpp"
#include "config/LGFX_Config_WioTerminal.hpp"

#else

// If none of the above apply, Put a copy of "config/LGFX_Config_Custom" in libraries folder,
// and modify the content according to the environment.
// 上記のいずれにも該当しない場合、"config/LGFX_Config_Custom" のコピーをライブラリフォルダに配置し、
// 動作環境に応じて内容を修正してください。
#include "../LGFX_Config_Custom.hpp"

#endif



#endif
57 changes: 57 additions & 0 deletions src/config/LGFX_Config_TTGO_TWristband.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef LOVYANGFX_CONFIG_HPP_
#define LOVYANGFX_CONFIG_HPP_

namespace lgfx
{
struct LGFX_Config
{
static constexpr spi_host_device_t spi_host = VSPI_HOST;
static constexpr int dma_channel = 1;
static constexpr int spi_mosi = 19;
static constexpr int spi_miso = -1;
static constexpr int spi_sclk = 18;
};
}

class LGFX : public lgfx::LGFX_SPI<lgfx::LGFX_Config>
{
struct Panel_default : public lgfx::Panel_ST7735S
{
Panel_default() {
len_dummy_read_pixel = 17;
spi_3wire = true;
invert = true;
spi_cs = 5;
spi_dc = 23;
gpio_rst = 26;
gpio_bl = 27;
pwm_ch_bl = 7;
panel_width = 80;
panel_height = 160;
offset_x = 26;
offset_y = 1;
offset_rotation = 2;
}
/*
protected:
const std::uint8_t* getInitCommands(std::uint8_t listno) const override {
static constexpr std::uint8_t list[] = {
CMD::GAMMASET, 1, 0x08, // Gamma set, curve 4
0xFF,0xFF, // end
};
if (listno == 2) return list;
return Panel_ST7735S::getInitCommands(listno);
}
//*/
};

public:
LGFX(void) : lgfx::LGFX_SPI<lgfx::LGFX_Config>()
{
static Panel_default panel;

setPanel(&panel);
}
};

#endif
6 changes: 6 additions & 0 deletions src/lgfx/LGFXBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ namespace lgfx

__attribute__ ((always_inline)) inline void beginTransaction(void) { beginTransaction_impl(); }
__attribute__ ((always_inline)) inline void endTransaction(void) { endTransaction_impl(); }
__attribute__ ((always_inline)) inline void initDMA(void) { } // TFT_eSPI compatible
__attribute__ ((always_inline)) inline void waitDMA(void) { waitDMA_impl(); }
__attribute__ ((always_inline)) inline void setWindow(std::int32_t xs, std::int32_t ys, std::int32_t xe, std::int32_t ye) { setWindow_impl(xs, ys, xe, ye); }

Expand Down Expand Up @@ -195,6 +196,10 @@ namespace lgfx
template<typename T> void drawXBitmap(std::int32_t x, std::int32_t y, const std::uint8_t *bitmap, std::int32_t w, std::int32_t h, const T& color ) { draw_xbitmap(x, y, bitmap, w, h, _write_conv.convert(color)); }
template<typename T> void drawXBitmap(std::int32_t x, std::int32_t y, const std::uint8_t *bitmap, std::int32_t w, std::int32_t h, const T& fgcolor, const T& bgcolor) { draw_xbitmap(x, y, bitmap, w, h, _write_conv.convert(fgcolor), _write_conv.convert(bgcolor)); }

void pushPixelsDMA(const void* data, std::int32_t len) { if (len < 0) return; pushPixelsDMA_impl(data, len); }

void writePixels(std::uint16_t* colors, std::int32_t len) { pushColors(colors, len, true); }

void pushColors(const std::uint8_t* data, std::int32_t len)
{
pushColors((rgb332_t*)data, len);
Expand Down Expand Up @@ -510,6 +515,7 @@ namespace lgfx
virtual void beginTransaction_impl(void) = 0;
virtual void endTransaction_impl(void) = 0;
virtual void waitDMA_impl(void) = 0;
virtual void pushPixelsDMA_impl(const void* data, std::int32_t length) = 0;

virtual void drawPixel_impl(std::int32_t x, std::int32_t y) = 0;
virtual void writeFillRect_impl(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h) = 0;
Expand Down
13 changes: 13 additions & 0 deletions src/lgfx/LGFX_Sprite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,19 @@ return;
} while (--h);
}

void pushPixelsDMA_impl(const void* data, std::int32_t length) override
{
auto k = _bitwidth * _write_conv.bits >> 3;
std::int32_t linelength;
do {
linelength = std::min<int>(_xe - _xptr + 1, length);
auto len = length * _write_conv.bits >> 3;
memcpy(&_img[(_xptr * _write_conv.bits >> 3) + _yptr * k], data, len);
data += len;
ptr_advance(linelength);
} while (length -= linelength);
}

void pushColors_impl(std::int32_t length, pixelcopy_t* param) override
{
auto k = _bitwidth * _write_conv.bits >> 3;
Expand Down
45 changes: 45 additions & 0 deletions src/lgfx/lgfx_img_support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,51 @@ namespace lgfx
return drawPngFile(&file, path, x, y, maxWidth, maxHeight, offX, offY, scale);
}


inline void drawBmpFile(fs::FS &fs, fs::File *file, std::int32_t x=0, std::int32_t y=0) {
FileWrapper data(fs, file);
this->prepareTmpTransaction(&data);
draw_bmp(&data, x, y);
}

inline bool drawJpgFile(fs::FS &fs, fs::File *file, std::int32_t x=0, std::int32_t y=0, std::int32_t maxWidth=0, std::int32_t maxHeight=0, std::int32_t offX=0, std::int32_t offY=0, jpeg_div::jpeg_div_t scale=jpeg_div::jpeg_div_t::JPEG_DIV_NONE) {
FileWrapper data(fs, file);
this->prepareTmpTransaction(&data);
return draw_jpg(&data, x, y, maxWidth, maxHeight, offX, offY, scale);
}

inline bool drawPngFile(fs::FS &fs, fs::File *file, std::int32_t x = 0, std::int32_t y = 0, std::int32_t maxWidth = 0, std::int32_t maxHeight = 0, std::int32_t offX = 0, std::int32_t offY = 0, double scale = 1.0)
{
FileWrapper data(fs, file);
this->prepareTmpTransaction(&data);
return draw_png(&data, x, y, maxWidth, maxHeight, offX, offY, scale);
}


inline void drawBmp(fs::File *dataSource, std::int32_t x=0, std::int32_t y=0) {
StreamWrapper data;
data.set(dataSource);
data.need_transaction = true;
this->prepareTmpTransaction(&data);
draw_bmp(&data, x, y);
}

inline bool drawJpg(fs::File *dataSource, std::int32_t x=0, std::int32_t y=0, std::int32_t maxWidth=0, std::int32_t maxHeight=0, std::int32_t offX=0, std::int32_t offY=0, jpeg_div::jpeg_div_t scale=jpeg_div::jpeg_div_t::JPEG_DIV_NONE) {
StreamWrapper data;
data.set(dataSource);
data.need_transaction = true;
this->prepareTmpTransaction(&data);
return draw_jpg(&data, x, y, maxWidth, maxHeight, offX, offY, scale);
}

inline void drawPng(fs::File *dataSource, std::int32_t x = 0, std::int32_t y = 0, std::int32_t maxWidth = 0, std::int32_t maxHeight = 0, std::int32_t offX = 0, std::int32_t offY = 0, double scale = 1.0) {
StreamWrapper data;
data.set(dataSource);
data.need_transaction = true;
this->prepareTmpTransaction(&data);
return draw_png(&data, x, y, maxWidth, maxHeight, offX, offY, scale);
}

#endif
#if defined (Stream_h)

Expand Down
1 change: 1 addition & 0 deletions src/lgfx/panel/PanelCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace lgfx
if (gpio_rst >= 0) { // RST on
lgfxPinMode(gpio_rst, pin_mode_t::output);
gpio_lo(gpio_rst);
delay(1);
}

if (gpio_bl >= 0) { // Backlight control
Expand Down
2 changes: 1 addition & 1 deletion src/lgfx/panel/Panel_ST7735.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace lgfx
panel_height = memory_height = 162; // or 160 or 132

freq_write = 27000000;
freq_read = 16000000;
freq_read = 14000000;
freq_fill = 27000000;

len_dummy_read_pixel = 9;
Expand Down
4 changes: 2 additions & 2 deletions src/lgfx/platforms/LGFX_SPI_ESP32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ namespace lgfx
periph_module_reset( PERIPH_SPI_DMA_MODULE );
}

void pushPixelsDMA(const void* data, std::uint32_t length) {
write_bytes((const std::uint8_t*)data, length, true);
void pushPixelsDMA_impl(const void* data, std::int32_t length) override {
write_bytes((const std::uint8_t*)data, length * _write_conv.bytes, true);
}


Expand Down
4 changes: 2 additions & 2 deletions src/lgfx/platforms/LGFX_SPI_SAMD51.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,8 @@ void disableSPI()
_sh = _height;
}

void pushPixelsDMA(const void* data, std::uint32_t length) {
write_bytes((const std::uint8_t*)data, length, true);
void pushPixelsDMA_impl(const void* data, std::int32_t length) override {
write_bytes((const std::uint8_t*)data, length * _write_conv.bytes, true);
}


Expand Down
Loading

0 comments on commit ea9c5c6

Please sign in to comment.