Skip to content

Commit

Permalink
Merge pull request #15 from lovyan03/unstable
Browse files Browse the repository at this point in the history
v0.1.7
  • Loading branch information
lovyan03 authored May 18, 2020
2 parents 2cb23f3 + a35f662 commit b7f193f
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 309 deletions.
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# LovyanGFX

SPI LCD graphics library (for ESP32 / SAMD51). (open beta edition.)

ベータ版の注意
----------------
LovyanGFXベータ版は動作テストおよび意見公募を目的として公開しているものです。ベータ版ソフトウェアは現在も開発途中のものであり、何らかの障害を引き起こす可能性があります。また、大きな仕様変更を行う場合があります。予めご了承ください。
The LovyanGFX beta version is open to the public for the purpose of testing and gathering feedback. This software is still under development and may fail in different ways. Additionally, major specification changes may occur. Thank you for your understanding.
SPI LCD graphics library (for ESP32 / SAMD51).

概要 Overview.
----------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void setup() {
Serial.println("Lovyan's LovyanGFX library Test!");

tft.init();
tft.setRotation(0);
tft.startWrite();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Fonts/lgfx_fonts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ namespace fonts {
namespace lgfx
{
// deprecated array.
PROGMEM const IFont* fontdata [] = {
const IFont* fontdata [] = {
&fonts::Font0, // GLCD font (Font 0)
&fonts::Font0, // GLCD font (or GFX font)
&fonts::Font2,
Expand Down
41 changes: 0 additions & 41 deletions src/Fonts/lgfx_fonts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,6 @@

namespace lgfx
{
enum textdatum_t : std::uint8_t
// 0:left 1:centre 2:right
// 0:top 4:middle 8:bottom 16:baseline
{ top_left = 0 // Top left (default)
, top_center = 1 // Top center
, top_centre = 1 // Top center
, top_right = 2 // Top right
, middle_left = 4 // Middle left
, middle_center = 5 // Middle center
, middle_centre = 5 // Middle center
, middle_right = 6 // Middle right
, bottom_left = 8 // Bottom left
, bottom_center = 9 // Bottom center
, bottom_centre = 9 // Bottom center
, bottom_right = 10 // Bottom right
, baseline_left = 16 // Baseline left (Line the 'A' character would sit on)
, baseline_center = 17 // Baseline center
, baseline_centre = 17 // Baseline center
, baseline_right = 18 // Baseline right
};

struct FontMetrics {
std::int16_t width;
std::int16_t x_advance;
Expand All @@ -36,16 +15,6 @@ namespace lgfx
std::int16_t baseline;
};

struct TextStyle {
std::uint32_t fore_rgb888 = 0xFFFFFFU;
std::uint32_t back_rgb888 = 0;
std::int_fast8_t size_x = 1;
std::int_fast8_t size_y = 1;
textdatum_t datum = textdatum_t::top_left;
bool utf8 = true;
bool cp437 = false;
};

struct IFont
{
enum font_type_t
Expand All @@ -62,16 +31,6 @@ namespace lgfx
virtual void getDefaultMetric(FontMetrics *metrics) const = 0;
virtual bool updateFontMetric(FontMetrics *metrics, std::uint16_t uniCode) const = 0;
virtual bool unloadFont(void) { return false; }
/*
struct param {
int32_t clip_left ;
int32_t clip_right ;
int32_t clip_top ;
int32_t clip_bottom;
int32_t filled_x ;
TextStyle* style ;
};
//*/
};

struct RunTimeFont : public IFont {
Expand Down
89 changes: 29 additions & 60 deletions src/LGFX_TFT_eSPI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,66 +9,6 @@

#include <LovyanGFX.hpp>


typedef lgfx::bgr888_t RGBColor;


// Font datum enumeration
// LEFT=0 CENTER=1 RIGHT=2
// TOP=0 MIDDLE=4 BOTTOM=8 BASELINE=16

#define TL_DATUM 0 // Top left (default)
#define TC_DATUM 1 // Top centre
#define TR_DATUM 2 // Top right
#define ML_DATUM 4 // Middle left
#define CL_DATUM 4 // Centre left, same as above
#define MC_DATUM 5 // Middle centre
#define CC_DATUM 5 // Centre centre, same as above
#define MR_DATUM 6 // Middle right
#define CR_DATUM 6 // Centre right, same as above
#define BL_DATUM 8 // Bottom left
#define BC_DATUM 9// Bottom centre
#define BR_DATUM 10 // Bottom right
#define L_BASELINE 16 // Left character baseline (Line the 'A' character would sit on)
#define C_BASELINE 17 // Centre character baseline
#define R_BASELINE 18 // Right character baseline


// Colour enumeration

// Default color definitions
#define TFT_BLACK 0x0000 /* 0, 0, 0 */
#define TFT_NAVY 0x000F /* 0, 0, 128 */
#define TFT_DARKGREEN 0x03E0 /* 0, 128, 0 */
#define TFT_DARKCYAN 0x03EF /* 0, 128, 128 */
#define TFT_MAROON 0x7800 /* 128, 0, 0 */
#define TFT_PURPLE 0x780F /* 128, 0, 128 */
#define TFT_OLIVE 0x7BE0 /* 128, 128, 0 */
#define TFT_LIGHTGREY 0xD69A /* 211, 211, 211 */
#define TFT_DARKGREY 0x7BEF /* 128, 128, 128 */
#define TFT_BLUE 0x001F /* 0, 0, 255 */
#define TFT_GREEN 0x07E0 /* 0, 255, 0 */
#define TFT_CYAN 0x07FF /* 0, 255, 255 */
#define TFT_RED 0xF800 /* 255, 0, 0 */
#define TFT_MAGENTA 0xF81F /* 255, 0, 255 */
#define TFT_YELLOW 0xFFE0 /* 255, 255, 0 */
#define TFT_WHITE 0xFFFF /* 255, 255, 255 */
#define TFT_ORANGE 0xFDA0 /* 255, 180, 0 */
#define TFT_GREENYELLOW 0xB7E0 /* 180, 255, 0 */
#define TFT_PINK 0xFE19 /* 255, 192, 203 */ //Lighter pink, was 0xFC9F
#define TFT_BROWN 0x9A60 /* 150, 75, 0 */
#define TFT_GOLD 0xFEA0 /* 255, 215, 0 */
#define TFT_SILVER 0xC618 /* 192, 192, 192 */
#define TFT_SKYBLUE 0x867D /* 135, 206, 235 */
#define TFT_VIOLET 0x915C /* 180, 46, 226 */

#define TFT_TRANSPARENT 0x0120


#define CP437_SWITCH lgfx::attribute_t::cp437_switch
#define UTF8_SWITCH lgfx::attribute_t::utf8_switch


typedef LGFX TFT_eSPI;

class TFT_eSprite : public lgfx::LGFX_Sprite {
Expand All @@ -79,4 +19,33 @@ class TFT_eSprite : public lgfx::LGFX_Sprite {
void* frameBuffer(uint8_t) { return getBuffer(); }
};

namespace textdatum
{
static constexpr textdatum_t TL_DATUM = textdatum_t::top_left;
static constexpr textdatum_t TC_DATUM = textdatum_t::top_center;
static constexpr textdatum_t TR_DATUM = textdatum_t::top_right;
static constexpr textdatum_t ML_DATUM = textdatum_t::middle_left;
static constexpr textdatum_t CL_DATUM = textdatum_t::middle_left;
static constexpr textdatum_t MC_DATUM = textdatum_t::middle_center;
static constexpr textdatum_t CC_DATUM = textdatum_t::middle_center;
static constexpr textdatum_t MR_DATUM = textdatum_t::middle_right;
static constexpr textdatum_t CR_DATUM = textdatum_t::middle_right;
static constexpr textdatum_t BL_DATUM = textdatum_t::bottom_left;
static constexpr textdatum_t BC_DATUM = textdatum_t::bottom_center;
static constexpr textdatum_t BR_DATUM = textdatum_t::bottom_right;
static constexpr textdatum_t L_BASELINE = textdatum_t::baseline_left;
static constexpr textdatum_t C_BASELINE = textdatum_t::baseline_center;
static constexpr textdatum_t R_BASELINE = textdatum_t::baseline_right;
};

namespace attribute
{
static constexpr attribute_t CP437_SWITCH = attribute_t::cp437_switch;
static constexpr attribute_t UTF8_SWITCH = attribute_t::utf8_switch;
}

using namespace textdatum;
using namespace attribute;


#endif
68 changes: 30 additions & 38 deletions src/LovyanGFX.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,10 @@ Original Source:

#include "lgfx/platforms/lgfx_spi_samd51.hpp"

#elif defined (ESP8266)
//#elif defined (STM32F7)
// not implemented.
#include "lgfx/platforms/lgfx_spi_esp8266.hpp"

#elif defined (STM32F7)
// not implemented.
#include "lgfx/platforms/lgfx_spi_stm32_spi.hpp"

#elif defined (__AVR__)
// not implemented.
#include "lgfx/platforms/lgfx_spi_avr.hpp"

// #include "lgfx/platforms/lgfx_spi_stm32_spi.hpp"
//
#endif


Expand Down Expand Up @@ -219,34 +211,34 @@ class LGFX : public lgfx::LGFX_SPI<lgfx::LGFX_Config>
}

#if defined( ARDUINO_ESP32_DEV ) // ESP-WROVER-KIT
// ESP-WROVER-KIT is available in two types of panels. (ILI9341 or ST7789)
void initPanel(void) override {
if (!_panel) return;
_panel->init();

if (readPanelID() > 0) { // check panel (ILI9341 or ST7789)
ESP_LOGI("LovyanGFX", "[Autodetect] Using Panel_ST7789");

static lgfx::Panel_ST7789 panel;
panel.spi_3wire = false;
panel.spi_cs = 22;
panel.spi_dc = 21;
panel.gpio_rst = 18;
panel.gpio_bl = 5;
panel.pwm_ch_bl = 7;
panel.freq_write = 80000000;
panel.freq_read = 16000000;
panel.freq_fill = 80000000;
panel.backlight_level = false;
panel.spi_mode_read = 1;
panel.len_dummy_read_pixel = 16;

setPanel(&panel);
} else {
ESP_LOGI("LovyanGFX", "[Autodetect] Using Panel_ILI9341");
}
lgfx::LGFX_SPI<lgfx::LGFX_Config>::initPanel();
// ESP-WROVER-KIT is available in two types of panels. (ILI9341 or ST7789)
void initPanel(void) override {
if (!_panel) return;
_panel->init();

if (readPanelID() > 0) { // check panel (ILI9341 or ST7789)
ESP_LOGI("LovyanGFX", "[Autodetect] Using Panel_ST7789");

static lgfx::Panel_ST7789 panel;
panel.spi_3wire = false;
panel.spi_cs = 22;
panel.spi_dc = 21;
panel.gpio_rst = 18;
panel.gpio_bl = 5;
panel.pwm_ch_bl = 7;
panel.freq_write = 80000000;
panel.freq_read = 16000000;
panel.freq_fill = 80000000;
panel.backlight_level = false;
panel.spi_mode_read = 1;
panel.len_dummy_read_pixel = 16;

setPanel(&panel);
} else {
ESP_LOGI("LovyanGFX", "[Autodetect] Using Panel_ILI9341");
}
lgfx::LGFX_SPI<lgfx::LGFX_Config>::initPanel();
}
#endif

};
Expand Down
1 change: 1 addition & 0 deletions src/lgfx/lgfx_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Original Source:

namespace lgfx
{
static constexpr float deg_to_rad = 0.017453292519943295769236907684886;

void LGFXBase::setAddrWindow(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h)
{
Expand Down
64 changes: 61 additions & 3 deletions src/lgfx/lgfx_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,60 @@ enum jpeg_div_t {

namespace lgfx
{
static constexpr float deg_to_rad = 0.017453292519943295769236907684886;
namespace colors // Colour enumeration
{
static constexpr int TFT_BLACK = 0x0000; /* 0, 0, 0 */
static constexpr int TFT_NAVY = 0x000F; /* 0, 0, 128 */
static constexpr int TFT_DARKGREEN = 0x03E0; /* 0, 128, 0 */
static constexpr int TFT_DARKCYAN = 0x03EF; /* 0, 128, 128 */
static constexpr int TFT_MAROON = 0x7800; /* 128, 0, 0 */
static constexpr int TFT_PURPLE = 0x780F; /* 128, 0, 128 */
static constexpr int TFT_OLIVE = 0x7BE0; /* 128, 128, 0 */
static constexpr int TFT_LIGHTGREY = 0xD69A; /* 211, 211, 211 */
static constexpr int TFT_DARKGREY = 0x7BEF; /* 128, 128, 128 */
static constexpr int TFT_BLUE = 0x001F; /* 0, 0, 255 */
static constexpr int TFT_GREEN = 0x07E0; /* 0, 255, 0 */
static constexpr int TFT_CYAN = 0x07FF; /* 0, 255, 255 */
static constexpr int TFT_RED = 0xF800; /* 255, 0, 0 */
static constexpr int TFT_MAGENTA = 0xF81F; /* 255, 0, 255 */
static constexpr int TFT_YELLOW = 0xFFE0; /* 255, 255, 0 */
static constexpr int TFT_WHITE = 0xFFFF; /* 255, 255, 255 */
static constexpr int TFT_ORANGE = 0xFDA0; /* 255, 180, 0 */
static constexpr int TFT_GREENYELLOW = 0xB7E0; /* 180, 255, 0 */
static constexpr int TFT_PINK = 0xFE19; /* 255, 192, 203 */ //Lighter pink, was 0xFC9F
static constexpr int TFT_BROWN = 0x9A60; /* 150, 75, 0 */
static constexpr int TFT_GOLD = 0xFEA0; /* 255, 215, 0 */
static constexpr int TFT_SILVER = 0xC618; /* 192, 192, 192 */
static constexpr int TFT_SKYBLUE = 0x867D; /* 135, 206, 235 */
static constexpr int TFT_VIOLET = 0x915C; /* 180, 46, 226 */
static constexpr int TFT_TRANSPARENT = 0x0120;
}

enum textdatum_t : std::uint8_t
// 0:left 1:centre 2:right
// 0:top 4:middle 8:bottom 16:baseline
{ top_left = 0 // Top left (default)
, top_center = 1 // Top center
, top_centre = 1 // Top center
, top_right = 2 // Top right
, middle_left = 4 // Middle left
, middle_center = 5 // Middle center
, middle_centre = 5 // Middle center
, middle_right = 6 // Middle right
, bottom_left = 8 // Bottom left
, bottom_center = 9 // Bottom center
, bottom_centre = 9 // Bottom center
, bottom_right = 10 // Bottom right
, baseline_left = 16 // Baseline left (Line the 'A' character would sit on)
, baseline_center = 17 // Baseline center
, baseline_centre = 17 // Baseline center
, baseline_right = 18 // Baseline right
};

enum attribute_t
{ cp437_switch = 1
, utf8_switch = 2
};

enum color_depth_t : std::uint8_t
{ palette_1bit = 1 // 2 color
Expand All @@ -47,7 +100,6 @@ namespace lgfx
, argb8888_4Byte = 32 // AAAAAAAA RRRRRRRR GGGGGGGG BBBBBBBB
};


__attribute__ ((always_inline)) inline static std::uint8_t color332(std::uint8_t r, std::uint8_t g, std::uint8_t b) { return (r >> 5) << 5 | (g >> 5) << 2 | b >> 6; }
__attribute__ ((always_inline)) inline static std::uint16_t color565(std::uint8_t r, std::uint8_t g, std::uint8_t b) { return (r >> 3) <<11 | (g >> 2) << 5 | b >> 3; }
__attribute__ ((always_inline)) inline static std::uint32_t color888(std::uint8_t r, std::uint8_t g, std::uint8_t b) { return r << 16 | g << 8 | b; }
Expand Down Expand Up @@ -92,7 +144,7 @@ namespace lgfx
struct rgb888_t; // 24bpp
struct argb8888_t; // 32bpp
struct swap565_t; // 16bpp
struct bgr666_t; // 18bpp
struct bgr666_t; // 18bpp (24bpp xxRRRRRRxxGGGGGGxxBBBBBB (for OLED SSD1351)
struct bgr888_t; // 24bpp


Expand Down Expand Up @@ -979,6 +1031,12 @@ namespace lgfx
//----------------------------------------------------------------------------
}

using namespace lgfx::colors;

using lgfx::textdatum_t;
using lgfx::attribute_t;

typedef lgfx::bgr888_t RGBColor;

#if defined (ESP32) || (CONFIG_IDF_TARGET_ESP32) || (ESP_PLATFORM)

Expand Down
Loading

0 comments on commit b7f193f

Please sign in to comment.