diff --git a/library.json b/library.json index 9852cab..60671d8 100644 --- a/library.json +++ b/library.json @@ -10,7 +10,7 @@ "type": "git", "url": "https://github.com/m5stack/M5GFX.git" }, - "version": "0.0.5", + "version": "0.0.6", "framework": "arduino", "platforms": "espressif32" } diff --git a/library.properties b/library.properties index 710da70..291065c 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=M5GFX -version=0.0.5 +version=0.0.6 author=M5Stack maintainer=M5Stack sentence=Library for M5Stack All Display diff --git a/src/M5GFX.cpp b/src/M5GFX.cpp index b0ec613..86ca257 100644 --- a/src/M5GFX.cpp +++ b/src/M5GFX.cpp @@ -361,7 +361,7 @@ namespace m5gfx nvs_board = board_t::board_M5Tough; #elif defined ( ARDUINO_M5Stack_ATOM ) -#elif defined ( ARDUINO_M5Stack_Timer_CAM ) +//#elif defined ( ARDUINO_M5Stack_Timer_CAM ) #endif } @@ -473,8 +473,8 @@ namespace m5gfx { // check panel (ST7789) board = board_t::board_M5StickCPlus; ESP_LOGW(LIBRARY_NAME, "[Autodetect] M5StickCPlus"); - bus_cfg.freq_write = 80000000; - bus_cfg.freq_read = 16000000; + bus_cfg.freq_write = 40000000; + bus_cfg.freq_read = 15000000; _bus_spi.config(bus_cfg); auto p = new Panel_M5StickCPlus(); p->bus(&_bus_spi); @@ -730,10 +730,9 @@ namespace m5gfx cfg.i2c_port = I2C_NUM_1;// I2C port number cfg.freq = 400000; // I2C freq cfg.x_min = 0; - cfg.x_max = 239; + cfg.x_max = 319; cfg.y_min = 0; - cfg.y_max = 319; - cfg.offset_rotation = 2; + cfg.y_max = 239; t->config(cfg); p->touch(t); lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x94, 0x02, ~0, axp_i2c_freq); // GPIO1 HIGH (TOUCH RST) @@ -772,7 +771,6 @@ ESP_LOGI("nvs_board","_board:%d", board); s.metrics = _font_metrics; s.cursor_x = _cursor_x; s.cursor_y = _cursor_y; - s.padX = _padding_x; _displayStateStack.push_back(s); } @@ -784,7 +782,6 @@ ESP_LOGI("nvs_board","_board:%d", board); _font = s.gfxFont; _text_style = s.style; _font_metrics = s.metrics; - _padding_x = s.padX; _cursor_x = s.cursor_x; _cursor_y = s.cursor_y; } diff --git a/src/M5GFX.h b/src/M5GFX.h index b9d6108..d3b2a78 100644 --- a/src/M5GFX.h +++ b/src/M5GFX.h @@ -143,6 +143,7 @@ namespace m5gfx , board_M5StackCoreInk , board_M5Paper , board_M5Tough + , board_M5ATOM }; } using board_t = boards::board_t; @@ -156,7 +157,7 @@ namespace m5gfx const lgfx::IFont *gfxFont; lgfx::TextStyle style; lgfx::FontMetrics metrics; - int32_t cursor_x, cursor_y, padX; + int32_t cursor_x, cursor_y; }; lgfx::Bus_SPI _bus_spi; @@ -182,6 +183,18 @@ namespace m5gfx void progressBar(int x, int y, int w, int h, uint8_t val); void pushState(void); void popState(void); + + /// draw RGB565 format image. + void drawBitmap(int16_t x, int16_t y, int16_t w, int16_t h, const void *data) + { + pushImage(x, y, w, h, (const rgb565_t*)data); + } + + /// draw RGB565 format image, with transparent color. + void drawBitmap(int16_t x, int16_t y, int16_t w, int16_t h, const void *data, uint16_t transparent) + { + pushImage(x, y, w, h, (const rgb565_t*)data, transparent); + } }; diff --git a/src/lgfx/internal/algorithm.h b/src/lgfx/internal/algorithm.h new file mode 100644 index 0000000..3c88856 --- /dev/null +++ b/src/lgfx/internal/algorithm.h @@ -0,0 +1,34 @@ +#pragma once + +#if defined ( CONFIG_ARCH_BOARD_SPRESENSE ) + #include + #include + #include + #ifdef atof + #undef atof + #endif + #ifdef atoi + #undef atoi + #endif + #ifdef atol + #undef atol + #endif + __attribute__((weak)) float atof(const char* nptr) { return strtod((nptr), NULL); } + __attribute__((weak)) int atoi(const char* nptr) { return (int)strtol((nptr), NULL, 10); } + __attribute__((weak)) long atol(const char* nptr) { return strtol((nptr), NULL, 10); } + __attribute__((weak)) int mblen(const char*, size_t) { return 0; } + __attribute__((weak)) size_t mbstowcs(wchar_t*, const char*, size_t) { return 0; } + __attribute__((weak)) int mbtowc(wchar_t*, const char*, size_t) { return 0; } + __attribute__((weak)) size_t wcstombs(char*, const wchar_t*, size_t) { return 0; } + __attribute__((weak)) int wctomb(char*, wchar_t) { return 0; } + + #ifdef max + #undef max + #endif + + #ifdef min + #undef min + #endif + +#endif +#include diff --git a/src/lgfx/internal/limits.h b/src/lgfx/internal/limits.h new file mode 100644 index 0000000..367fa69 --- /dev/null +++ b/src/lgfx/internal/limits.h @@ -0,0 +1,13 @@ +#pragma once + +#if defined ( CONFIG_ARCH_BOARD_SPRESENSE ) + #ifdef max + #undef max + #endif + + #ifdef min + #undef min + #endif + +#endif +#include diff --git a/src/lgfx/internal/memory.h b/src/lgfx/internal/memory.h new file mode 100644 index 0000000..119d739 --- /dev/null +++ b/src/lgfx/internal/memory.h @@ -0,0 +1,13 @@ +#pragma once + +#if defined ( CONFIG_ARCH_BOARD_SPRESENSE ) + #include + #include + #include + __attribute__((weak)) int vfwscanf(void*, const wchar_t *, ...) { return 0; } + __attribute__((weak)) int vswscanf(const wchar_t*, const wchar_t *, ...) { return 0; } + __attribute__((weak)) int vwscanf(const wchar_t*, ...) { return 0; } + + #define _GLIBCXX_CSTDINT 1 +#endif +#include diff --git a/src/lgfx/utility/pgmspace.h b/src/lgfx/utility/pgmspace.h new file mode 100644 index 0000000..debcec4 --- /dev/null +++ b/src/lgfx/utility/pgmspace.h @@ -0,0 +1,76 @@ +/*----------------------------------------------------------------------------/ + Lovyan GFX - Graphics library for embedded devices. + +Original Source: + https://github.com/lovyan03/LovyanGFX/ + +Licence: + [BSD](https://github.com/lovyan03/LovyanGFX/blob/master/license.txt) + +Author: + [lovyan03](https://twitter.com/lovyan03) + +Contributors: + [ciniml](https://github.com/ciniml) + [mongonta0716](https://github.com/mongonta0716) + [tobozo](https://github.com/tobozo) +/----------------------------------------------------------------------------*/ +#ifndef __LGFX_PGMSPACE_H__ +#define __LGFX_PGMSPACE_H__ + +#if defined ( ARDUINO ) && !defined ( pgm_read_byte ) + #if __has_include() + #include + #elif __has_include() || defined(__AVR__) + #include + #else + #include + #endif +#endif +#if !defined ( pgm_read_byte ) + #define pgm_read_byte(addr) (*(const uint8_t *)((uintptr_t)addr)) + #define pgm_read_word(addr) (*(const uint16_t *)((uintptr_t)addr)) + #define pgm_read_dword(addr) (*(const uint32_t *)((uintptr_t)addr)) +#endif + +/// for not ESP8266 +#if !defined ( pgm_read_dword_with_offset ) + #if defined (__SAMD21__) + #define pgm_read_word_unaligned(addr) (uint16_t) \ + ( *(const uint8_t *)((uintptr_t)addr) \ + | *(const uint8_t *)((uintptr_t)addr+1) << 8 ) + #define pgm_read_3byte_unaligned(addr) (uint32_t) \ + ( *(const uint8_t *)((uintptr_t)addr) \ + | *(const uint8_t *)((uintptr_t)addr+1) << 8 \ + | *(const uint8_t *)((uintptr_t)addr+2) << 16 ) + #define pgm_read_dword_unaligned(addr) (uint32_t) \ + ( *(const uint8_t *)((uintptr_t)addr) \ + | *(const uint8_t *)((uintptr_t)addr+1) << 8 \ + | *(const uint8_t *)((uintptr_t)addr+2) << 16 \ + | *(const uint8_t *)((uintptr_t)addr+3) << 24 ) + #else + #define pgm_read_word_unaligned(addr) (*(const uint16_t *)((uintptr_t)addr)) + #define pgm_read_dword_unaligned(addr) (*(const uint32_t *)((uintptr_t)addr)) + #endif +#endif + +#if !defined ( pgm_read_3byte_unaligned ) + #define pgm_read_3byte_unaligned(addr) (pgm_read_dword_unaligned(addr) & 0xFFFFFFu) +#endif + +#if defined (__SAMD21__) || defined ( ESP8266 ) + static inline void write_3byte_unaligned(void* addr, uint32_t value) + { + reinterpret_cast(addr)[0] = value; + reinterpret_cast(addr)[1] = value >> 8; + reinterpret_cast(addr)[2] = value >> 16; + } +#else + static inline void write_3byte_unaligned(void* addr, uint32_t value) + { + reinterpret_cast(addr)[0] = value; + reinterpret_cast(addr)[2] = value >> 16; + } +#endif + +#endif diff --git a/src/lgfx/v1/Bus.hpp b/src/lgfx/v1/Bus.hpp index 37ad8c5..400c7a2 100644 --- a/src/lgfx/v1/Bus.hpp +++ b/src/lgfx/v1/Bus.hpp @@ -17,7 +17,7 @@ Original Source: /----------------------------------------------------------------------------*/ #pragma once -#include +#include namespace lgfx { @@ -64,38 +64,38 @@ namespace lgfx virtual void initDMA(void) = 0; /// DMA転送キューを追加する。 - virtual void addDMAQueue(const std::uint8_t* data, std::uint32_t length) = 0; // { writeBytes(data, length, true); } + virtual void addDMAQueue(const uint8_t* data, uint32_t length) = 0; // { writeBytes(data, length, true); } /// 蓄積したDMA転送キューの送信を実行する。 virtual void execDMAQueue(void) = 0; /// DMA用のバッファを取得する。バスの実装によっては内部的には2個のバッファを交互に使用する。 /// 繰返し実行した場合は前回と異なるポインタを得るが、前々回と同じになる場合がある点に注意すること。 - virtual std::uint8_t* getDMABuffer(std::uint32_t length) = 0; + virtual uint8_t* getDMABuffer(uint32_t length) = 0; /// 未送信のデータがあれば送信を開始する。 virtual void flush(void) = 0; /// D/Cピンをlowにしてデータを送信する。 - virtual bool writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) = 0; + virtual bool writeCommand(uint32_t data, uint_fast8_t bit_length) = 0; /// D/Cピンをhighにしてデータを送信する。 - virtual void writeData(std::uint32_t data, std::uint_fast8_t bit_length) = 0; + virtual void writeData(uint32_t data, uint_fast8_t bit_length) = 0; /// D/Cピンをhighにして指定回数繰り返しデータを送信する。 - virtual void writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t count) = 0; + virtual void writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t count) = 0; /// pixelcopy構造体を利用してピクセルデータを送信する。 - virtual void writePixels(pixelcopy_t* pc, std::uint32_t length) = 0; + virtual void writePixels(pixelcopy_t* pc, uint32_t length) = 0; /// 引数のバイト列を送信する。 - virtual void writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) = 0; + virtual void writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) = 0; virtual void beginRead(void) = 0; virtual void endRead(void) = 0; - virtual std::uint32_t readData(std::uint_fast8_t bit_length) = 0; - virtual bool readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma = false) = 0; - virtual void readPixels(void* dst, pixelcopy_t* pc, std::uint32_t length) = 0; + virtual uint32_t readData(uint_fast8_t bit_length) = 0; + virtual bool readBytes(uint8_t* dst, uint32_t length, bool use_dma = false) = 0; + virtual void readPixels(void* dst, pixelcopy_t* pc, uint32_t length) = 0; }; struct Bus_NULL : public IBus @@ -109,22 +109,22 @@ namespace lgfx bool busy(void) const override { return false; } void initDMA(void) override {} - void addDMAQueue(const std::uint8_t* data, std::uint32_t length) override {} + void addDMAQueue(const uint8_t*, uint32_t) override {} void execDMAQueue(void) override {} - std::uint8_t* getDMABuffer(std::uint32_t length) override { return nullptr; } + uint8_t* getDMABuffer(uint32_t) override { return nullptr; } void flush(void) override {} - bool writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) override { return false; } - void writeData(std::uint32_t data, std::uint_fast8_t bit_length) override {} - void writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t count) override {} - void writePixels(pixelcopy_t* pc, std::uint32_t length) override {} - void writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) override {} + bool writeCommand(uint32_t, uint_fast8_t) override { return false; } + void writeData(uint32_t, uint_fast8_t) override {} + void writeDataRepeat(uint32_t, uint_fast8_t, uint32_t) override {} + void writePixels(pixelcopy_t*, uint32_t) override {} + void writeBytes(const uint8_t*, uint32_t, bool, bool) override {} void beginRead(void) override {} void endRead(void) override {} - std::uint32_t readData(std::uint_fast8_t bit_length) override { return 0; } - bool readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma = false) override { return false; } - void readPixels(void* dst, pixelcopy_t* pc, std::uint32_t length) override {} + uint32_t readData(uint_fast8_t) override { return 0; } + bool readBytes(uint8_t*, uint32_t, bool) override { return false; } + void readPixels(void*, pixelcopy_t*, uint32_t) override {} }; //---------------------------------------------------------------------------- diff --git a/src/lgfx/v1/LGFXBase.cpp b/src/lgfx/v1/LGFXBase.cpp index c55882f..dbdbb5d 100644 --- a/src/lgfx/v1/LGFXBase.cpp +++ b/src/lgfx/v1/LGFXBase.cpp @@ -17,6 +17,8 @@ Original Source: /----------------------------------------------------------------------------*/ #include "LGFXBase.hpp" + +#include "../internal/limits.h" #include "../utility/miniz.h" #include "../utility/lgfx_pngle.h" #include "../utility/lgfx_qrcode.h" @@ -25,9 +27,8 @@ Original Source: #include "misc/bitmap.hpp" //#include "lgfx_TTFfont.hpp" -#include +#include #include -#include #include namespace lgfx @@ -36,7 +37,7 @@ namespace lgfx { //---------------------------------------------------------------------------- static constexpr float deg_to_rad = 0.017453292519943295769236907684886; - static constexpr std::uint8_t FP_SCALE = 16; + static constexpr uint8_t FP_SCALE = 16; LGFXBase::LGFXBase(void) { @@ -49,14 +50,14 @@ namespace lgfx _read_conv.setColorDepth(_panel->getReadDepth()); } - void LGFXBase::setRotation(std::uint_fast8_t rotation) + void LGFXBase::setRotation(uint_fast8_t rotation) { if (_panel) _panel->setRotation(rotation); clearClipRect(); clearScrollRect(); } - void LGFXBase::setAddrWindow(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h) + void LGFXBase::setAddrWindow(int32_t x, int32_t y, int32_t w, int32_t h) { if (_adjust_abs(x, w)||_adjust_abs(y, h)) return; if (x < 0) { w += x; x = 0; } @@ -71,7 +72,7 @@ namespace lgfx endWrite(); } - void LGFXBase::setClipRect(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h) + void LGFXBase::setClipRect(int32_t x, int32_t y, int32_t w, int32_t h) { if (x < 0) { w += x; x = 0; } if (w > width() - x) w = width() - x; @@ -86,7 +87,7 @@ namespace lgfx _clip_b = y + h - 1; } - void LGFXBase::display(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h) + void LGFXBase::display(int32_t x, int32_t y, int32_t w, int32_t h) { if (x < 0) { w += x; x = 0; } if (w > width() - x) w = width() - x; @@ -97,7 +98,7 @@ namespace lgfx _panel->display(x, y, w, h); } - void LGFXBase::getClipRect(std::int32_t *x, std::int32_t *y, std::int32_t *w, std::int32_t *h) + void LGFXBase::getClipRect(int32_t *x, int32_t *y, int32_t *w, int32_t *h) { *x = _clip_l; *w = _clip_r - *x + 1; @@ -113,7 +114,7 @@ namespace lgfx _clip_b = height() - 1; } - void LGFXBase::setScrollRect(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h) + void LGFXBase::setScrollRect(int32_t x, int32_t y, int32_t w, int32_t h) { _adjust_abs(x, w); if (x < 0) { w += x; x = 0; } @@ -130,7 +131,7 @@ namespace lgfx _sh = h; } - void LGFXBase::getScrollRect(std::int32_t *x, std::int32_t *y, std::int32_t *w, std::int32_t *h) + void LGFXBase::getScrollRect(int32_t *x, int32_t *y, int32_t *w, int32_t *h) { *x = _sx; *y = _sy; @@ -146,7 +147,7 @@ namespace lgfx _sh = height(); } - void LGFXBase::drawFastVLine(std::int32_t x, std::int32_t y, std::int32_t h) + void LGFXBase::drawFastVLine(int32_t x, int32_t y, int32_t h) { _adjust_abs(y, h); startWrite(); @@ -154,7 +155,7 @@ namespace lgfx endWrite(); } - void LGFXBase::writeFastVLine(std::int32_t x, std::int32_t y, std::int32_t h) + void LGFXBase::writeFastVLine(int32_t x, int32_t y, int32_t h) { if (x < _clip_l || x > _clip_r) return; auto ct = _clip_t; @@ -166,7 +167,7 @@ namespace lgfx writeFillRectPreclipped(x, y, 1, h); } - void LGFXBase::drawFastHLine(std::int32_t x, std::int32_t y, std::int32_t w) + void LGFXBase::drawFastHLine(int32_t x, int32_t y, int32_t w) { _adjust_abs(x, w); startWrite(); @@ -174,7 +175,7 @@ namespace lgfx endWrite(); } - void LGFXBase::writeFastHLine(std::int32_t x, std::int32_t y, std::int32_t w) + void LGFXBase::writeFastHLine(int32_t x, int32_t y, int32_t w) { if (y < _clip_t || y > _clip_b) return; auto cl = _clip_l; @@ -186,7 +187,7 @@ namespace lgfx writeFillRectPreclipped(x, y, w, 1); } - void LGFXBase::fillRect(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h) + void LGFXBase::fillRect(int32_t x, int32_t y, int32_t w, int32_t h) { _adjust_abs(x, w); _adjust_abs(y, h); @@ -195,7 +196,7 @@ namespace lgfx endWrite(); } - void LGFXBase::writeFillRect(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h) + void LGFXBase::writeFillRect(int32_t x, int32_t y, int32_t w, int32_t h) { if (_clipping(x, y, w, h)) { @@ -203,7 +204,7 @@ namespace lgfx } } - void LGFXBase::drawRect(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h) + void LGFXBase::drawRect(int32_t x, int32_t y, int32_t w, int32_t h) { if (_adjust_abs(x, w)||_adjust_abs(y, h)) return; startWrite(); @@ -218,7 +219,7 @@ namespace lgfx endWrite(); } - void LGFXBase::drawCircle(std::int32_t x, std::int32_t y, std::int32_t r) + void LGFXBase::drawCircle(int32_t x, int32_t y, int32_t r) { if ( r <= 0 ) { drawPixel(x, y); @@ -226,11 +227,11 @@ namespace lgfx } startWrite(); - std::int32_t f = 1 - r; - std::int32_t ddF_y = - (r << 1); - std::int32_t ddF_x = 1; - std::int32_t i = 0; - std::int32_t j = -1; + int32_t f = 1 - r; + int32_t ddF_y = - (r << 1); + int32_t ddF_x = 1; + int32_t i = 0; + int32_t j = -1; do { while (f < 0) { ++i; @@ -252,14 +253,14 @@ namespace lgfx endWrite(); } - void LGFXBase::drawCircleHelper(std::int32_t x, std::int32_t y, std::int32_t r, std::uint_fast8_t cornername) + void LGFXBase::drawCircleHelper(int32_t x, int32_t y, int32_t r, uint_fast8_t cornername) { if (r <= 0) return; - std::int32_t f = 1 - r; - std::int32_t ddF_y = - (r << 1); - std::int32_t ddF_x = 1; - std::int32_t i = 0; - std::int32_t j = 0; + int32_t f = 1 - r; + int32_t ddF_y = - (r << 1); + int32_t ddF_x = 1; + int32_t i = 0; + int32_t j = 0; startWrite(); do { @@ -290,27 +291,27 @@ namespace lgfx endWrite(); } - void LGFXBase::fillCircle(std::int32_t x, std::int32_t y, std::int32_t r) { + void LGFXBase::fillCircle(int32_t x, int32_t y, int32_t r) { startWrite(); writeFastHLine(x - r, y, (r << 1) + 1); fillCircleHelper(x, y, r, 3, 0); endWrite(); } - void LGFXBase::fillCircleHelper(std::int32_t x, std::int32_t y, std::int32_t r, std::uint_fast8_t corners, std::int32_t delta) + void LGFXBase::fillCircleHelper(int32_t x, int32_t y, int32_t r, uint_fast8_t corners, int32_t delta) { if (r <= 0) return; ++delta; - std::int32_t f = 1 - r; - std::int32_t ddF_y = - (r << 1); - std::int32_t ddF_x = 1; - std::int32_t i = 0; + int32_t f = 1 - r; + int32_t ddF_y = - (r << 1); + int32_t ddF_x = 1; + int32_t i = 0; startWrite(); do { - std::int32_t len = 0; + int32_t len = 0; while (f < 0) { f += (ddF_x += 2); ++len; @@ -330,7 +331,7 @@ namespace lgfx endWrite(); } - void LGFXBase::drawEllipse(std::int32_t x, std::int32_t y, std::int32_t rx, std::int32_t ry) + void LGFXBase::drawEllipse(int32_t x, int32_t y, int32_t rx, int32_t ry) { if (ry == 0) { drawFastHLine(x - rx, y, (ry << 2) + 1); @@ -342,9 +343,9 @@ namespace lgfx } if (rx < 0 || ry < 0) return; - std::int32_t xt, yt, s, i; - std::int32_t rx2 = rx * rx; - std::int32_t ry2 = ry * ry; + int32_t xt, yt, s, i; + int32_t rx2 = rx * rx; + int32_t ry2 = ry * ry; startWrite(); @@ -379,7 +380,7 @@ namespace lgfx endWrite(); } - void LGFXBase::fillEllipse(std::int32_t x, std::int32_t y, std::int32_t rx, std::int32_t ry) + void LGFXBase::fillEllipse(int32_t x, int32_t y, int32_t rx, int32_t ry) { if (ry == 0) { drawFastHLine(x - rx, y, (ry << 2) + 1); @@ -391,10 +392,10 @@ namespace lgfx } if (rx < 0 || ry < 0) return; - std::int32_t xt, yt, i; - std::int32_t rx2 = rx * rx; - std::int32_t ry2 = ry * ry; - std::int32_t s; + int32_t xt, yt, i; + int32_t rx2 = rx * rx; + int32_t ry2 = ry * ry; + int32_t s; startWrite(); @@ -424,30 +425,30 @@ namespace lgfx endWrite(); } - void LGFXBase::drawRoundRect(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, std::int32_t r) + void LGFXBase::drawRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t r) { if (_adjust_abs(x, w)||_adjust_abs(y, h)) return; startWrite(); w--; h--; - std::int32_t len = (r << 1) + 1; - std::int32_t y1 = y + h - r; - std::int32_t y0 = y + r; + int32_t len = (r << 1) + 1; + int32_t y1 = y + h - r; + int32_t y0 = y + r; writeFastVLine(x , y0 + 1, h - len); writeFastVLine(x + w , y0 + 1, h - len); - std::int32_t x1 = x + w - r; - std::int32_t x0 = x + r; + int32_t x1 = x + w - r; + int32_t x0 = x + r; writeFastHLine(x0 + 1, y , w - len); writeFastHLine(x0 + 1, y + h , w - len); - std::int32_t f = 1 - r; - std::int32_t ddF_y = -(r << 1); - std::int32_t ddF_x = 1; + int32_t f = 1 - r; + int32_t ddF_y = -(r << 1); + int32_t ddF_x = 1; len = 0; - for (std::int32_t i = 0; i <= r; i++) { + for (int32_t i = 0; i <= r; i++) { len++; if (f >= 0) { writeFastHLine(x0 - i , y0 - r, len); @@ -469,20 +470,20 @@ namespace lgfx endWrite(); } - void LGFXBase::fillRoundRect(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, std::int32_t r) + void LGFXBase::fillRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t r) { if (_adjust_abs(x, w)||_adjust_abs(y, h)) return; startWrite(); - std::int32_t y2 = y + r; - std::int32_t y1 = y + h - r - 1; - std::int32_t ddF_y = - (r << 1); - std::int32_t delta = w + ddF_y; + int32_t y2 = y + r; + int32_t y1 = y + h - r - 1; + int32_t ddF_y = - (r << 1); + int32_t delta = w + ddF_y; writeFillRect(x, y2, w, h + ddF_y); - std::int32_t x0 = x + r; - std::int32_t f = 1 - r; - std::int32_t ddF_x = 1; - std::int32_t len = 0; - for (std::int32_t i = 0; i <= r; i++) { + int32_t x0 = x + r; + int32_t f = 1 - r; + int32_t ddF_x = 1; + int32_t len = 0; + for (int32_t i = 0; i <= r; i++) { len++; if (f >= 0) { writeFillRect(x0 - r, y2 - i , (r << 1) + delta, len); @@ -501,14 +502,14 @@ namespace lgfx endWrite(); } - void LGFXBase::drawLine(std::int32_t x0, std::int32_t y0, std::int32_t x1, std::int32_t y1) + void LGFXBase::drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1) { bool steep = abs(y1 - y0) > abs(x1 - x0); - std::int32_t xstart = _clip_l; - std::int32_t ystart = _clip_t; - std::int32_t xend = _clip_r; - std::int32_t yend = _clip_b; + int32_t xstart = _clip_l; + int32_t ystart = _clip_t; + int32_t xend = _clip_r; + int32_t yend = _clip_b; if (steep) { @@ -525,10 +526,10 @@ namespace lgfx if (x0 > xend || x1 < xstart) return; xend = std::min(x1, xend); - std::int32_t dy = abs(y1 - y0); - std::int32_t ystep = (y1 > y0) ? 1 : -1; - std::int32_t dx = x1 - x0; - std::int32_t err = dx >> 1; + int32_t dy = abs(y1 - y0); + int32_t ystep = (y1 > y0) ? 1 : -1; + int32_t dx = x1 - x0; + int32_t err = dx >> 1; while (x0 < xstart || y0 < ystart || y0 > yend) { @@ -540,8 +541,8 @@ namespace lgfx } if (++x0 > xend) return; } - std::int32_t xs = x0; - std::int32_t dlen = 0; + int32_t xs = x0; + int32_t dlen = 0; if (ystep < 0) std::swap(ystart, yend); yend += ystep; @@ -579,7 +580,7 @@ namespace lgfx endWrite(); } - void LGFXBase::drawTriangle(std::int32_t x0, std::int32_t y0, std::int32_t x1, std::int32_t y1, std::int32_t x2, std::int32_t y2) + void LGFXBase::drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2) { startWrite(); drawLine(x0, y0, x1, y1); @@ -588,9 +589,9 @@ namespace lgfx endWrite(); } - void LGFXBase::fillTriangle(std::int32_t x0, std::int32_t y0, std::int32_t x1, std::int32_t y1, std::int32_t x2, std::int32_t y2) + void LGFXBase::fillTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2) { - std::int32_t a, b; + int32_t a, b; // Sort coordinates by Y order (y2 >= y1 >= y0) if (y0 > y1) { std::swap(y0, y1); std::swap(x0, x1); } @@ -611,24 +612,24 @@ namespace lgfx return; } - std::int32_t dy1 = y1 - y0; - std::int32_t dy2 = y2 - y0; + int32_t dy1 = y1 - y0; + int32_t dy2 = y2 - y0; bool change = ((x1 - x0) * dy2 > (x2 - x0) * dy1); - std::int32_t dx1 = abs(x1 - x0); - std::int32_t dx2 = abs(x2 - x0); - std::int32_t xstep1 = x1 < x0 ? -1 : 1; - std::int32_t xstep2 = x2 < x0 ? -1 : 1; + int32_t dx1 = abs(x1 - x0); + int32_t dx2 = abs(x2 - x0); + int32_t xstep1 = x1 < x0 ? -1 : 1; + int32_t xstep2 = x2 < x0 ? -1 : 1; a = b = x0; if (change) { std::swap(dx1, dx2); std::swap(dy1, dy2); std::swap(xstep1, xstep2); } - std::int32_t err1 = (std::max(dx1, dy1) >> 1) + int32_t err1 = (std::max(dx1, dy1) >> 1) + (xstep1 < 0 ? std::min(dx1, dy1) : dx1); - std::int32_t err2 = (std::max(dx2, dy2) >> 1) + int32_t err2 = (std::max(dx2, dy2) >> 1) + (xstep2 > 0 ? std::min(dx2, dy2) : dx2); @@ -672,9 +673,9 @@ namespace lgfx endWrite(); } - void LGFXBase::drawBezier( std::int32_t x0, std::int32_t y0, std::int32_t x1, std::int32_t y1, std::int32_t x2, std::int32_t y2) + void LGFXBase::drawBezier( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2) { - std::int32_t x = x0 - x1, y = y0 - y1; + int32_t x = x0 - x1, y = y0 - y1; double t = x0 - 2 * x1 + x2, r; startWrite(); @@ -708,18 +709,18 @@ namespace lgfx endWrite(); } - void LGFXBase::draw_bezier_helper( std::int32_t x0, std::int32_t y0, std::int32_t x1, std::int32_t y1, std::int32_t x2, std::int32_t y2) + void LGFXBase::draw_bezier_helper( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2) { // Check if coordinates are sequential (replaces assert) if (((x2 >= x1 && x1 >= x0) || (x2 <= x1 && x1 <= x0)) && ((y2 >= y1 && y1 >= y0) || (y2 <= y1 && y1 <= y0))) { // Coordinates are sequential - std::int32_t sx = x2 - x1, sy = y2 - y1; - std::int32_t xx = x0 - x1, yy = y0 - y1, xy; + int32_t sx = x2 - x1, sy = y2 - y1; + int32_t xx = x0 - x1, yy = y0 - y1, xy; float dx, dy, err, cur = xx * sy - yy * sx; - if (sx * (std::int32_t)sx + sy * (std::int32_t)sy > xx * xx + yy * yy) { + if (sx * (int32_t)sx + sy * (int32_t)sy > xx * xx + yy * yy) { x2 = x0; x0 = sx + x1; y2 = y0; y0 = sy + y1; cur = -cur; } if (cur != 0) { @@ -755,20 +756,20 @@ namespace lgfx } } - void LGFXBase::drawBezier( std::int32_t x0, std::int32_t y0, std::int32_t x1, std::int32_t y1, std::int32_t x2, std::int32_t y2, std::int32_t x3, std::int32_t y3) + void LGFXBase::drawBezier( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3) { - std::int32_t w = x0-x1; - std::int32_t h = y0-y1; - std::int32_t len = w*w+h*h; + int32_t w = x0-x1; + int32_t h = y0-y1; + int32_t len = w*w+h*h; w = x1-x2; h = y1-y2; - std::int32_t len2 = w*w+h*h; + int32_t len2 = w*w+h*h; if (len < len2) len = len2; w = x2-x3; h = y2-y3; len2 = w*w+h*h; if (len < len2) len = len2; - len = (std::int32_t)round(sqrt(len)) >> 2; + len = (int32_t)round(sqrt(len)) >> 2; float fx0 = x0; float fy0 = y0; @@ -779,7 +780,7 @@ namespace lgfx float fx3 = x3; float fy3 = y3; - std::int32_t i = 0; + int32_t i = 0; startWrite(); //drawLine(x0, y0, x1, y1); //drawLine(x1, y1, x2, y2); @@ -818,7 +819,7 @@ namespace lgfx endWrite(); } - void LGFXBase::draw_gradient_line( std::int32_t x0, std::int32_t y0, std::int32_t x1, std::int32_t y1, uint32_t colorstart, uint32_t colorend ) + void LGFXBase::draw_gradient_line( int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t colorstart, uint32_t colorend ) { if ( colorstart == colorend || (x0 == x1 && y0 == y1)) { setColor(colorstart); @@ -838,21 +839,21 @@ namespace lgfx std::swap(colorstart, colorend); } - std::int32_t dx = x1 - x0; - std::int32_t err = dx >> 1; - std::int32_t dy = abs(y1 - y0); - std::int32_t ystep = (y0 < y1) ? 1 : -1; + int32_t dx = x1 - x0; + int32_t err = dx >> 1; + int32_t dy = abs(y1 - y0); + int32_t ystep = (y0 < y1) ? 1 : -1; - std::int32_t r = (colorstart >> 16)&0xFF; - std::int32_t g = (colorstart >> 8 )&0xFF; - std::int32_t b = (colorstart )&0xFF; + int32_t r = (colorstart >> 16)&0xFF; + int32_t g = (colorstart >> 8 )&0xFF; + int32_t b = (colorstart )&0xFF; - std::int32_t diff_r = ((colorend >> 16)&0xFF) - r; - std::int32_t diff_g = ((colorend >> 8 )&0xFF) - g; - std::int32_t diff_b = ((colorend )&0xFF) - b; + int32_t diff_r = ((colorend >> 16)&0xFF) - r; + int32_t diff_g = ((colorend >> 8 )&0xFF) - g; + int32_t diff_b = ((colorend )&0xFF) - b; startWrite(); - for (std::int32_t x = x0; x <= x1; x++) { + for (int32_t x = x0; x <= x1; x++) { setColor(color888( (x - x0) * diff_r / dx + r , (x - x0) * diff_g / dx + g , (x - x0) * diff_b / dx + b)); @@ -867,7 +868,7 @@ namespace lgfx endWrite(); } - void LGFXBase::drawEllipseArc(std::int32_t x, std::int32_t y, std::int32_t r0x, std::int32_t r1x, std::int32_t r0y, std::int32_t r1y, float start, float end) + void LGFXBase::drawEllipseArc(int32_t x, int32_t y, int32_t r0x, int32_t r1x, int32_t r0y, int32_t r1y, float start, float end) { if (r0x < r1x) std::swap(r0x, r1x); if (r0y < r1y) std::swap(r0y, r1y); @@ -889,7 +890,7 @@ namespace lgfx endWrite(); } - void LGFXBase::fillEllipseArc(std::int32_t x, std::int32_t y, std::int32_t r0x, std::int32_t r1x, std::int32_t r0y, std::int32_t r1y, float start, float end) + void LGFXBase::fillEllipseArc(int32_t x, int32_t y, int32_t r0x, int32_t r1x, int32_t r0y, int32_t r1y, float start, float end) { if (r0x < r1x) std::swap(r0x, r1x); if (r0y < r1y) std::swap(r0y, r1y); @@ -908,7 +909,7 @@ namespace lgfx endWrite(); } - void LGFXBase::fill_arc_helper(std::int32_t cx, std::int32_t cy, std::int32_t oradius_x, std::int32_t iradius_x, std::int32_t oradius_y, std::int32_t iradius_y, float start, float end) + void LGFXBase::fill_arc_helper(int32_t cx, int32_t cy, int32_t oradius_x, int32_t iradius_x, int32_t oradius_y, int32_t iradius_y, float start, float end) { float s_cos = (cosf(start * deg_to_rad)); float e_cos = (cosf(end * deg_to_rad)); @@ -922,10 +923,10 @@ namespace lgfx bool end180 = end < 180; bool reversed = start + 180 < end || (end < start && start < end + 180); - std::int32_t xleft = -oradius_x; - std::int32_t xright = oradius_x + 1; - std::int32_t y = -oradius_y; - std::int32_t ye = oradius_y; + int32_t xleft = -oradius_x; + int32_t xright = oradius_x + 1; + int32_t y = -oradius_y; + int32_t ye = oradius_y; if (!reversed) { if ( (end >= 270 || end < 90) && (start >= 270 || start < 90)) xleft = 0; @@ -941,26 +942,26 @@ namespace lgfx bool trueCircle = (oradius_x == oradius_y) && (iradius_x == iradius_y); - std::int32_t iradius_y2 = iradius_y * (iradius_y - 1); - std::int32_t iradius_x2 = iradius_x * (iradius_x - 1); + int32_t iradius_y2 = iradius_y * (iradius_y - 1); + int32_t iradius_x2 = iradius_x * (iradius_x - 1); float irad_rate = iradius_x2 && iradius_y2 ? (float)iradius_x2 / (float)iradius_y2 : 0; - std::int32_t oradius_y2 = oradius_y * (oradius_y + 1); - std::int32_t oradius_x2 = oradius_x * (oradius_x + 1); + int32_t oradius_y2 = oradius_y * (oradius_y + 1); + int32_t oradius_x2 = oradius_x * (oradius_x + 1); float orad_rate = oradius_x2 && oradius_y2 ? (float)oradius_x2 / (float)oradius_y2 : 0; do { - std::int32_t y2 = y * y; - std::int32_t compare_o = oradius_y2 - y2; - std::int32_t compare_i = iradius_y2 - y2; + int32_t y2 = y * y; + int32_t compare_o = oradius_y2 - y2; + int32_t compare_i = iradius_y2 - y2; if (!trueCircle) { compare_i = floorf(compare_i * irad_rate); compare_o = ceilf (compare_o * orad_rate); } - std::int32_t xe = ceilf(sqrtf(compare_o)); - std::int32_t x = 1 - xe; + int32_t xe = ceilf(sqrtf(compare_o)); + int32_t x = 1 - xe; if ( x < xleft ) x = xleft; if (xe > xright) xe = xright; @@ -971,7 +972,7 @@ namespace lgfx { bool flg1 = start180 != (x <= ysslope); bool flg2 = end180 != (x <= yeslope); - std::int32_t x2 = x * x; + int32_t x2 = x * x; if (x2 >= compare_i && ((flg1 && flg2) || (reversed && (flg1 || flg2))) && x != xe @@ -993,20 +994,20 @@ namespace lgfx } while (++y <= ye); } - void LGFXBase::draw_bitmap(std::int32_t x, std::int32_t y, const std::uint8_t *bitmap, std::int32_t w, std::int32_t h, std::uint32_t fg_rawcolor, std::uint32_t bg_rawcolor) + void LGFXBase::draw_bitmap(int32_t x, int32_t y, const uint8_t *bitmap, int32_t w, int32_t h, uint32_t fg_rawcolor, uint32_t bg_rawcolor) { if (w < 1 || h < 1) return; setRawColor(fg_rawcolor); - std::int32_t byteWidth = (w + 7) >> 3; - std::uint_fast8_t byte = 0; + int32_t byteWidth = (w + 7) >> 3; + uint_fast8_t byte = 0; bool fg = true; - std::int32_t j = 0; + int32_t j = 0; startWrite(); do { - std::int32_t i = 0; + int32_t i = 0; do { - std::int32_t ip = i; + int32_t ip = i; for (;;) { if (!(i & 7)) byte = bitmap[i >> 3]; if (fg != (bool)(byte & 0x80) || (++i >= w)) break; @@ -1023,20 +1024,20 @@ namespace lgfx endWrite(); } - void LGFXBase::draw_xbitmap(std::int32_t x, std::int32_t y, const std::uint8_t *bitmap, std::int32_t w, std::int32_t h, std::uint32_t fg_rawcolor, std::uint32_t bg_rawcolor) + void LGFXBase::draw_xbitmap(int32_t x, int32_t y, const uint8_t *bitmap, int32_t w, int32_t h, uint32_t fg_rawcolor, uint32_t bg_rawcolor) { if (w < 1 || h < 1) return; setRawColor(fg_rawcolor); - std::int32_t byteWidth = (w + 7) >> 3; - std::uint_fast8_t byte = 0; + int32_t byteWidth = (w + 7) >> 3; + uint_fast8_t byte = 0; bool fg = true; - std::int32_t j = 0; + int32_t j = 0; startWrite(); do { - std::int32_t i = 0; + int32_t i = 0; do { - std::int32_t ip = i; + int32_t ip = i; for (;;) { if (!(i & 7)) byte = bitmap[i >> 3]; if (fg != (bool)(byte & 0x01) || (++i >= w)) break; @@ -1053,25 +1054,25 @@ namespace lgfx endWrite(); } - void LGFXBase::pushImage(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, pixelcopy_t *param, bool use_dma) + void LGFXBase::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, pixelcopy_t *param, bool use_dma) { param->src_bitwidth = w; if (param->src_bits < 8) { // get bitwidth -// std::uint32_t x_mask = (1 << (4 - __builtin_ffs(param->src_bits))) - 1; -// std::uint32_t x_mask = (1 << ((~(param->src_bits>>1)) & 3)) - 1; - std::uint32_t x_mask = (param->src_bits == 1) ? 7 - : (param->src_bits == 2) ? 3 - : 1; +// uint32_t x_mask = (1 << (4 - __builtin_ffs(param->src_bits))) - 1; +// uint32_t x_mask = (1 << ((~(param->src_bits>>1)) & 3)) - 1; + uint32_t x_mask = (param->src_bits == 1) ? 7 + : (param->src_bits == 2) ? 3 + : 1; param->src_bitwidth = (w + x_mask) & (~x_mask); } - std::int32_t dx=0, dw=w; + int32_t dx=0, dw=w; if (0 < _clip_l - x) { dx = _clip_l - x; dw -= dx; x = _clip_l; } if (_adjust_width(x, dx, dw, _clip_l, _clip_r - _clip_l + 1)) return; param->src_x = dx; - std::int32_t dy=0, dh=h; + int32_t dy=0, dh=h; if (0 < _clip_t - y) { dy = _clip_t - y; dh -= dy; y = _clip_t; } if (_adjust_width(y, dy, dh, _clip_t, _clip_b - _clip_t + 1)) return; param->src_y = dy; @@ -1094,7 +1095,7 @@ namespace lgfx result[5] = dst_y - src_x * result[3] - src_y * result[4]; } - static bool make_invert_affine32(std::int32_t* __restrict__ result, const float* __restrict__ matrix) + static bool make_invert_affine32(int32_t* __restrict__ result, const float* __restrict__ matrix) { float det = matrix[0] * matrix[4] - matrix[1] * matrix[3]; if (det == 0.0f) return false; @@ -1108,43 +1109,43 @@ namespace lgfx return true; } - void LGFXBase::push_image_rotate_zoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, std::int32_t w, std::int32_t h, pixelcopy_t* pc) + void LGFXBase::push_image_rotate_zoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, pixelcopy_t* pc) { float matrix[6]; make_rotation_matrix(matrix, dst_x + 0.5, dst_y + 0.5, src_x + 0.5, src_y + 0.5, angle, zoom_x, zoom_y); push_image_affine(matrix, w, h, pc); } - void LGFXBase::push_image_rotate_zoom_aa(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, std::int32_t w, std::int32_t h, pixelcopy_t* pc) + void LGFXBase::push_image_rotate_zoom_aa(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, pixelcopy_t* pc) { float matrix[6]; make_rotation_matrix(matrix, dst_x + 0.5, dst_y + 0.5, src_x + 0.5, src_y + 0.5, angle, zoom_x, zoom_y); push_image_affine_aa(matrix, w, h, pc); } - void LGFXBase::push_image_affine(const float* matrix, std::int32_t w, std::int32_t h, pixelcopy_t* pc) + void LGFXBase::push_image_affine(const float* matrix, int32_t w, int32_t h, pixelcopy_t* pc) { pc->no_convert = false; pc->src_height = h; pc->src_width = w; pc->src_bitwidth = w; if (pc->src_bits < 8) { - std::uint32_t x_mask = (pc->src_bits == 1) ? 7 - : (pc->src_bits == 2) ? 3 - : 1; + uint32_t x_mask = (pc->src_bits == 1) ? 7 + : (pc->src_bits == 2) ? 3 + : 1; pc->src_bitwidth = (w + x_mask) & (~x_mask); } push_image_affine(matrix, pc); } - void LGFXBase::push_image_affine_aa(const float* matrix, std::int32_t w, std::int32_t h, pixelcopy_t* pc) + void LGFXBase::push_image_affine_aa(const float* matrix, int32_t w, int32_t h, pixelcopy_t* pc) { pc->no_convert = false; pc->src_height = h; pc->src_width = w; pc->src_bitwidth = w; if (pc->src_bits < 8) { - std::uint32_t x_mask = (pc->src_bits == 1) ? 7 + uint32_t x_mask = (pc->src_bits == 1) ? 7 : (pc->src_bits == 2) ? 3 : 1; pc->src_bitwidth = (w + x_mask) & (~x_mask); @@ -1174,10 +1175,10 @@ namespace lgfx push_image_affine_aa(matrix, pc, &pc_post); } - void LGFXBase::fillAffine(const float matrix[6], std::int32_t w, std::int32_t h) + void LGFXBase::fillAffine(const float matrix[6], int32_t w, int32_t h) { - std::int32_t min_y = matrix[3] * (w << FP_SCALE); - std::int32_t max_y = matrix[4] * (h << FP_SCALE); + int32_t min_y = matrix[3] * (w << FP_SCALE); + int32_t max_y = matrix[4] * (h << FP_SCALE); if ((min_y < 0) == (max_y < 0)) { max_y += min_y; @@ -1189,42 +1190,42 @@ namespace lgfx } { - std::int32_t offset_y32 = matrix[5] * (1 << FP_SCALE) + (1 << (FP_SCALE-1)); + int32_t offset_y32 = matrix[5] * (1 << FP_SCALE) + (1 << (FP_SCALE-1)); min_y = std::max(_clip_t , (offset_y32 + min_y - 1) >> FP_SCALE); max_y = std::min(_clip_b + 1, (offset_y32 + max_y + 1) >> FP_SCALE); if (min_y >= max_y) return; } - std::int32_t iA[6]; + int32_t iA[6]; if (!make_invert_affine32(iA, matrix)) return; - std::int32_t offset = (min_y << 1) - 1; + int32_t offset = (min_y << 1) - 1; iA[2] += ((iA[0] + iA[1] * offset) >> 1); iA[5] += ((iA[3] + iA[4] * offset) >> 1); - std::int32_t scale_w = w << FP_SCALE; - std::int32_t xs1 = (iA[0] < 0 ? - scale_w : 1) - iA[0]; - std::int32_t xs2 = (iA[0] < 0 ? 0 : (1 - scale_w)) - iA[0]; + int32_t scale_w = w << FP_SCALE; + int32_t xs1 = (iA[0] < 0 ? - scale_w : 1) - iA[0]; + int32_t xs2 = (iA[0] < 0 ? 0 : (1 - scale_w)) - iA[0]; - std::int32_t scale_h = h << FP_SCALE; - std::int32_t ys1 = (iA[3] < 0 ? - scale_h : 1) - iA[3]; - std::int32_t ys2 = (iA[3] < 0 ? 0 : (1 - scale_h)) - iA[3]; + int32_t scale_h = h << FP_SCALE; + int32_t ys1 = (iA[3] < 0 ? - scale_h : 1) - iA[3]; + int32_t ys2 = (iA[3] < 0 ? 0 : (1 - scale_h)) - iA[3]; - std::int32_t cl = _clip_l ; - std::int32_t cr = _clip_r + 1; + int32_t cl = _clip_l ; + int32_t cr = _clip_r + 1; - std::int32_t div1 = iA[0] ? - iA[0] : -1; - std::int32_t div2 = iA[3] ? - iA[3] : -1; - std::int32_t y = min_y - max_y; + int32_t div1 = iA[0] ? - iA[0] : -1; + int32_t div2 = iA[3] ? - iA[3] : -1; + int32_t y = min_y - max_y; startWrite(); do { iA[2] += iA[1]; iA[5] += iA[4]; - std::int32_t left = std::max(cl, std::max((iA[2] + xs1) / div1, (iA[5] + ys1) / div2)); - std::int32_t right = std::min(cr, std::min((iA[2] + xs2) / div1, (iA[5] + ys2) / div2)); + int32_t left = std::max(cl, std::max((iA[2] + xs1) / div1, (iA[5] + ys1) / div2)); + int32_t right = std::min(cr, std::min((iA[2] + xs2) / div1, (iA[5] + ys2) / div2)); if (left < right) { writeFillRectPreclipped(left, y + max_y, right - left, 1); @@ -1235,8 +1236,8 @@ namespace lgfx void LGFXBase::push_image_affine(const float* matrix, pixelcopy_t* pc) { - std::int32_t min_y = matrix[3] * (pc->src_width << FP_SCALE); - std::int32_t max_y = matrix[4] * (pc->src_height << FP_SCALE); + int32_t min_y = matrix[3] * (pc->src_width << FP_SCALE); + int32_t max_y = matrix[4] * (pc->src_height << FP_SCALE); if ((min_y < 0) == (max_y < 0)) { max_y += min_y; @@ -1248,47 +1249,47 @@ namespace lgfx } { - std::int32_t offset_y32 = matrix[5] * (1 << FP_SCALE) + (1 << (FP_SCALE-1)); + int32_t offset_y32 = matrix[5] * (1 << FP_SCALE) + (1 << (FP_SCALE-1)); min_y = std::max(_clip_t , (offset_y32 + min_y - 1) >> FP_SCALE); max_y = std::min(_clip_b + 1, (offset_y32 + max_y + 1) >> FP_SCALE); if (min_y >= max_y) return; } - std::int32_t iA[6]; + int32_t iA[6]; if (!make_invert_affine32(iA, matrix)) return; - std::int32_t offset = (min_y << 1) - 1; + int32_t offset = (min_y << 1) - 1; iA[2] += ((iA[0] + iA[1] * offset) >> 1); iA[5] += ((iA[3] + iA[4] * offset) >> 1); - std::int32_t scale_w = pc->src_width << FP_SCALE; - std::int32_t xs1 = (iA[0] < 0 ? - scale_w : 1) - iA[0]; - std::int32_t xs2 = (iA[0] < 0 ? 0 : (1 - scale_w)) - iA[0]; + int32_t scale_w = pc->src_width << FP_SCALE; + int32_t xs1 = (iA[0] < 0 ? - scale_w : 1) - iA[0]; + int32_t xs2 = (iA[0] < 0 ? 0 : (1 - scale_w)) - iA[0]; - std::int32_t scale_h = pc->src_height << FP_SCALE; - std::int32_t ys1 = (iA[3] < 0 ? - scale_h : 1) - iA[3]; - std::int32_t ys2 = (iA[3] < 0 ? 0 : (1 - scale_h)) - iA[3]; + int32_t scale_h = pc->src_height << FP_SCALE; + int32_t ys1 = (iA[3] < 0 ? - scale_h : 1) - iA[3]; + int32_t ys2 = (iA[3] < 0 ? 0 : (1 - scale_h)) - iA[3]; - std::int32_t cl = _clip_l ; - std::int32_t cr = _clip_r + 1; + int32_t cl = _clip_l ; + int32_t cr = _clip_r + 1; - std::int32_t y = min_y - max_y; + int32_t y = min_y - max_y; startWrite(); do { iA[2] += iA[1]; iA[5] += iA[4]; - std::int32_t left = std::max(cl, std::max(iA[0] ? (iA[2] + xs1) / - iA[0] : cl, iA[3] ? (iA[5] + ys1) / - iA[3] : cl)); - std::int32_t right = std::min(cr, std::min(iA[0] ? (iA[2] + xs2) / - iA[0] : cr, iA[3] ? (iA[5] + ys2) / - iA[3] : cr)); + int32_t left = std::max(cl, std::max(iA[0] ? (iA[2] + xs1) / - iA[0] : cl, iA[3] ? (iA[5] + ys1) / - iA[3] : cl)); + int32_t right = std::min(cr, std::min(iA[0] ? (iA[2] + xs2) / - iA[0] : cr, iA[3] ? (iA[5] + ys2) / - iA[3] : cr)); if (left < right) { pc->src_x32 = iA[2] + left * iA[0]; - if (static_cast(pc->src_x) < pc->src_width) + if (static_cast(pc->src_x) < pc->src_width) { pc->src_y32 = iA[5] + left * iA[3]; - if (static_cast(pc->src_y) < pc->src_height) + if (static_cast(pc->src_y) < pc->src_height) { pc->src_x32_add = iA[0]; pc->src_y32_add = iA[3]; @@ -1302,8 +1303,8 @@ namespace lgfx void LGFXBase::push_image_affine_aa(const float* matrix, pixelcopy_t* pc, pixelcopy_t* pc2) { - std::int32_t min_y = matrix[3] * (pc->src_width << FP_SCALE); - std::int32_t max_y = matrix[4] * (pc->src_height << FP_SCALE); + int32_t min_y = matrix[3] * (pc->src_width << FP_SCALE); + int32_t max_y = matrix[4] * (pc->src_height << FP_SCALE); if ((min_y < 0) == (max_y < 0)) { max_y += min_y; @@ -1315,35 +1316,36 @@ namespace lgfx } { - std::int32_t offset_y32 = matrix[5] * (1 << FP_SCALE); + int32_t offset_y32 = matrix[5] * (1 << FP_SCALE); min_y = std::max(_clip_t, (offset_y32 + min_y ) >> FP_SCALE); max_y = std::min(_clip_b, (offset_y32 + max_y -1) >> FP_SCALE) + 1; if (min_y >= max_y) return; } - std::int32_t iA[6]; + int32_t iA[6]; if (!make_invert_affine32(iA, matrix)) return; pc->src_x32_add = iA[0]; pc->src_y32_add = iA[3]; - std::uint32_t x32_diff = std::min(8 << FP_SCALE, std::max(abs(iA[0]), abs(iA[1])) - 1) >> 1; - std::uint32_t y32_diff = std::min(8 << FP_SCALE, std::max(abs(iA[3]), abs(iA[4])) - 1) >> 1; + uint32_t x32_diff = std::min(8 << FP_SCALE, std::max(abs(iA[0]), abs(iA[1])) - 1) >> 1; + uint32_t y32_diff = std::min(8 << FP_SCALE, std::max(abs(iA[3]), abs(iA[4])) - 1) >> 1; - std::int32_t offset = (min_y << 1) - 1; + int32_t offset = (min_y << 1) - 1; iA[2] += ((iA[0] + iA[1] * offset) >> 1); iA[5] += ((iA[3] + iA[4] * offset) >> 1); - std::int32_t scale_w = (pc->src_width << FP_SCALE) + (x32_diff << 1); - std::int32_t xs1 = (iA[0] < 0 ? - scale_w : 1) - iA[0] + x32_diff; - std::int32_t xs2 = (iA[0] < 0 ? 0 : (1 - scale_w)) - iA[0] + x32_diff; + int32_t scale_w = (pc->src_width << FP_SCALE) + (x32_diff << 1); + int32_t xs1 = (iA[0] < 0 ? - scale_w : 1) - iA[0] + x32_diff; + int32_t xs2 = (iA[0] < 0 ? 0 : (1 - scale_w)) - iA[0] + x32_diff; - std::int32_t scale_h = (pc->src_height << FP_SCALE) + (y32_diff << 1); - std::int32_t ys1 = (iA[3] < 0 ? - scale_h : 1) - iA[3] + y32_diff; - std::int32_t ys2 = (iA[3] < 0 ? 0 : (1 - scale_h)) - iA[3] + y32_diff; + int32_t scale_h = (pc->src_height << FP_SCALE) + (y32_diff << 1); + int32_t ys1 = (iA[3] < 0 ? - scale_h : 1) - iA[3] + y32_diff; + int32_t ys2 = (iA[3] < 0 ? 0 : (1 - scale_h)) - iA[3] + y32_diff; - std::int32_t cl = _clip_l ; - std::int32_t cr = _clip_r + 1; - argb8888_t buffer[cr - cl]; + int32_t cl = _clip_l ; + int32_t cr = _clip_r + 1; + + auto buffer = (argb8888_t*)alloca((cr - cl) * sizeof(argb8888_t)); pc2->src_data = buffer; startWrite(); @@ -1351,16 +1353,16 @@ namespace lgfx { iA[2] += iA[1]; iA[5] += iA[4]; - std::int32_t left = std::max(cl, std::max(iA[0] ? (iA[2] + xs1) / - iA[0] : cl, iA[3] ? (iA[5] + ys1) / - iA[3] : cl)); - std::int32_t right = std::min(cr, std::min(iA[0] ? (iA[2] + xs2) / - iA[0] : cr, iA[3] ? (iA[5] + ys2) / - iA[3] : cr)); + int32_t left = std::max(cl, std::max(iA[0] ? (iA[2] + xs1) / - iA[0] : cl, iA[3] ? (iA[5] + ys1) / - iA[3] : cl)); + int32_t right = std::min(cr, std::min(iA[0] ? (iA[2] + xs2) / - iA[0] : cr, iA[3] ? (iA[5] + ys2) / - iA[3] : cr)); if (left < right) { - std::int32_t len = right - left; + int32_t len = right - left; - std::uint32_t xs = iA[2] + left * iA[0]; + uint32_t xs = iA[2] + left * iA[0]; pc->src_x32 = xs - x32_diff; pc->src_xe32 = xs + x32_diff; - std::uint32_t ys = iA[5] + left * iA[3]; + uint32_t ys = iA[5] + left * iA[3]; pc->src_y32 = ys - y32_diff; pc->src_ye32 = ys + y32_diff; @@ -1375,12 +1377,12 @@ namespace lgfx endWrite(); } - void LGFXBase::readRect(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, std::uint8_t* data) + void LGFXBase::readRect(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t* data) { pixelcopy_t p(nullptr, rgb332_t::depth, _read_conv.depth, false, getPalette()); read_rect(x, y, w, h, data, &p); } - void LGFXBase::readRect(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, std::uint16_t* data) + void LGFXBase::readRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t* data) { pixelcopy_t p(nullptr, swap565_t::depth, _read_conv.depth, false, getPalette()); if (_swapBytes && !_palette_count && _read_conv.depth >= 8) { @@ -1389,7 +1391,7 @@ namespace lgfx } read_rect(x, y, w, h, data, &p); } - void LGFXBase::readRect(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, void* data) + void LGFXBase::readRect(int32_t x, int32_t y, int32_t w, int32_t h, void* data) { pixelcopy_t p(nullptr, bgr888_t::depth, _read_conv.depth, false, getPalette()); if (_swapBytes && !_palette_count && _read_conv.depth >= 8) { @@ -1399,21 +1401,21 @@ namespace lgfx read_rect(x, y, w, h, data, &p); } - void LGFXBase::scroll(std::int_fast16_t dx, std::int_fast16_t dy) + void LGFXBase::scroll(int_fast16_t dx, int_fast16_t dy) { setColor(_base_rgb888); - std::int32_t w = _sw - abs(dx); - std::int32_t h = _sh - abs(dy); + int32_t w = _sw - abs(dx); + int32_t h = _sh - abs(dy); if (w < 0 || h < 0) { writeFillRect(_sx, _sy, _sw, _sh); return; } - std::int32_t src_x = dx < 0 ? _sx - dx : _sx; - std::int32_t dst_x = src_x + dx; - std::int32_t src_y = dy < 0 ? _sy - dy : _sy; - std::int32_t dst_y = src_y + dy; + int32_t src_x = dx < 0 ? _sx - dx : _sx; + int32_t dst_x = src_x + dx; + int32_t src_y = dy < 0 ? _sy - dy : _sy; + int32_t dst_y = src_y + dy; startWrite(); _panel->copyRect(dst_x, dst_y, w, h, src_x, src_y); @@ -1425,7 +1427,7 @@ namespace lgfx endWrite(); } - void LGFXBase::copyRect(std::int32_t dst_x, std::int32_t dst_y, std::int32_t w, std::int32_t h, std::int32_t src_x, std::int32_t src_y) + void LGFXBase::copyRect(int32_t dst_x, int32_t dst_y, int32_t w, int32_t h, int32_t src_x, int32_t src_y) { auto wid = width(); if (src_x < dst_x) { if (src_x < 0) { w += src_x; dst_x -= src_x; src_x = 0; } if (w > wid - dst_x) w = wid - dst_x; } @@ -1440,7 +1442,7 @@ namespace lgfx _panel->copyRect(dst_x, dst_y, w, h, src_x, src_y); } - void LGFXBase::read_rect(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, void* dst, pixelcopy_t* param) + void LGFXBase::read_rect(int32_t x, int32_t y, int32_t w, int32_t h, void* dst, pixelcopy_t* param) { _adjust_abs(x, w); if (x < 0) { w += x; x = 0; } @@ -1455,22 +1457,23 @@ namespace lgfx _panel->readRect(x, y, w, h, dst, param); } - struct paint_point_t { std::int32_t lx,rx,y,oy; }; + struct paint_point_t { int32_t lx,rx,y,oy; }; - static void paint_add_points(std::list& points, int lx, int rx, int y, int oy, bool* linebuf) + static void paint_add_points(std::list& points, int32_t lx, int32_t rx, int32_t y, int32_t oy, uint8_t* linebuf) { paint_point_t pt { 0, 0, y, oy }; - while (lx <= rx) { + do + { while (lx < rx && !linebuf[lx]) ++lx; if (!linebuf[lx]) break; pt.lx = lx; while (++lx <= rx && linebuf[lx]); pt.rx = lx - 1; - points.push_back(pt); - } + points.emplace_back(pt); + } while (lx <= rx); } - void LGFXBase::floodFill(std::int32_t x, std::int32_t y) + void LGFXBase::floodFill(int32_t x, int32_t y) { if (x < _clip_l || x > _clip_r || y < _clip_t || y > _clip_b) return; bgr888_t target; @@ -1479,6 +1482,7 @@ namespace lgfx pixelcopy_t p; p.transp = _read_conv.convert(lgfx::color888(target.r, target.g, target.b)); + p.src_bits = _read_conv.depth & color_depth_t::bit_mask; switch (_read_conv.depth) { case color_depth_t::rgb888_3Byte: p.fp_copy = pixelcopy_t::compare_rgb_fast; break; @@ -1486,95 +1490,92 @@ namespace lgfx case color_depth_t::rgb565_2Byte: p.fp_copy = pixelcopy_t::compare_rgb_fast; break; case color_depth_t::rgb332_1Byte: p.fp_copy = pixelcopy_t::compare_rgb_fast; break; default: p.fp_copy = pixelcopy_t::compare_bit_fast; - p.src_bits = _read_conv.depth; p.src_mask = (1 << p.src_bits) - 1; p.transp &= p.src_mask; break; } - std::int32_t cl = _clip_l; - int w = _clip_r - cl + 1; - std::uint8_t bufIdx = 0; - bool* linebufs[3] = { new bool[w], new bool[w], new bool[w] }; - std::int32_t bufY[3] = {-2, -2, -2}; // 3 line buffer (default: out of range.) - bufY[0] = y; - read_rect(cl, y, w, 1, linebufs[0], &p); + const int32_t cl = _clip_l; + const int32_t w = _clip_r - cl + 1; + size_t bufIdx = 0; + uint8_t* linebufs[3] = { new uint8_t[w], new uint8_t[w], new uint8_t[w] }; + int32_t bufY[3] = {y, -2, -2}; // 3 line buffer (default: out of range.) + _panel->readRect(cl, y, w, 1, linebufs[0], &p); std::list points; points.push_back({x, x, y, y}); startWrite(); while (!points.empty()) { - std::int32_t y0 = bufY[bufIdx]; + int32_t y0 = bufY[bufIdx]; + auto it = points.begin(); - std::int32_t counter = 0; + int32_t counter = 0; while (it->y != y0 && ++it != points.end()) ++counter; if (it == points.end()) { if (counter < 256) { ++bufIdx; - std::int32_t y1 = bufY[(bufIdx )%3]; - std::int32_t y2 = bufY[(bufIdx+1)%3]; + int32_t y1 = bufY[(bufIdx )%3]; + int32_t y2 = bufY[(bufIdx+1)%3]; it = points.begin(); + while ((it->y != y1) && (it->y != y2) && (++it != points.end())); } - } + bufIdx = 0; + if (it == points.end()) + { + it = points.begin(); - bufIdx = 0; - if (it == points.end()) - { - it = points.begin(); - bufY[0] = it->y; - read_rect(cl, it->y, w, 1, linebufs[0], &p); - } - else - { - for (; bufIdx < 2; ++bufIdx) if (it->y == bufY[bufIdx]) break; + bufY[0] = it->y; + _panel->readRect(cl, it->y, w, 1, linebufs[0], &p); + } + else + { + for (; bufIdx < 2; ++bufIdx) if (it->y == bufY[bufIdx]) break; + } } - bool* linebuf = &linebufs[bufIdx][- cl]; + auto linebuf = &linebufs[bufIdx][- cl]; - int lx = it->lx; - int rx = it->rx; - int ly = it->y; - int oy = it->oy; + int32_t lx = it->lx; + int32_t rx = it->rx; + int32_t ly = it->y; + int32_t oy = it->oy; points.erase(it); if (!linebuf[lx]) continue; - int lxsav = lx - 1; - int rxsav = rx + 1; + int32_t lxsav = lx - 1; + int32_t rxsav = rx + 1; - int cr = _clip_r; + const int32_t cr = _clip_r; while (lx > cl && linebuf[lx - 1]) --lx; while (rx < cr && linebuf[rx + 1]) ++rx; + bool flg_noexpanded = lx >= lxsav && rxsav >= rx; - writeFastHLine(lx, ly, rx - lx + 1); memset(&linebuf[lx], 0, rx - lx + 1); + writeFillRectPreclipped(lx, ly, rx - lx + 1, 1); - int newy = ly - 1; + int32_t nexty[2] = { ly - 1, ly + 1 }; + if (ly < y) std::swap(nexty[0], nexty[1]); + size_t i = 0; do { - if (newy == oy && lx >= lxsav && rxsav >= rx) continue; - if (newy < _clip_t) continue; - if (newy > _clip_b) continue; - int bidx = 0; + int32_t newy = nexty[i]; + if (newy == oy && flg_noexpanded) continue; + if (newy < _clip_t || newy > _clip_b) continue; + size_t bidx = 0; while (newy != bufY[bidx] && ++bidx != 3); if (bidx == 3) { for (bidx = 0; bidx < 2 && (abs(bufY[bidx] - ly) <= 1); ++bidx); bufY[bidx] = newy; - read_rect(cl, newy, w, 1, linebufs[bidx], &p); + _panel->readRect(cl, newy, w, 1, linebufs[bidx], &p); } - bool* linebuf = &linebufs[bidx][- cl]; - if (newy == oy) - { - paint_add_points(points, lx ,lxsav, newy, ly, linebuf); - paint_add_points(points, rxsav ,rx, newy, ly, linebuf); - } else { - paint_add_points(points, lx ,rx, newy, ly, linebuf); - } - } while ((newy += 2) < ly + 2); + auto linebuf = &linebufs[bidx][- cl]; + paint_add_points(points, lx ,rx, newy, ly, linebuf); + } while (++i < 2); } - int i = 0; + size_t i = 0; do { delete[] linebufs[i]; } while (++i != 3); endWrite(); } @@ -1582,7 +1583,7 @@ namespace lgfx //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- - static char* numberToStr(unsigned long n, char* buf, std::size_t buflen, std::uint8_t base) + static char* numberToStr(unsigned long n, char* buf, size_t buflen, uint8_t base) { char *str = &buf[buflen - 1]; @@ -1599,7 +1600,7 @@ namespace lgfx return str; } - static char* numberToStr(long n, char* buf, std::size_t buflen, std::uint8_t base) + static char* numberToStr(long n, char* buf, size_t buflen, uint8_t base) { if (n >= 0) return numberToStr((unsigned long) n, buf, buflen, base); auto res = numberToStr(- n, buf, buflen, 10) - 1; @@ -1607,7 +1608,7 @@ namespace lgfx return res; } - static char* floatToStr(double number, char* buf, std::size_t /*buflen*/, std::uint8_t digits) + static char* floatToStr(double number, char* buf, size_t /*buflen*/, uint8_t digits) { if (std::isnan(number)) { return strcpy(buf, "nan"); } if (std::isinf(number)) { return strcpy(buf, "inf"); } @@ -1624,7 +1625,7 @@ namespace lgfx // Round correctly so that print(1.999, 2) prints as "2.00" double rounding = 0.5; - for(std::uint8_t i = 0; i < digits; ++i) { + for(uint8_t i = 0; i < digits; ++i) { rounding /= 10.0; } @@ -1635,7 +1636,7 @@ namespace lgfx double remainder = number - (double) int_part; { - constexpr std::size_t len = 14; + constexpr size_t len = 14; char numstr[len]; auto tmp = numberToStr(int_part, numstr, len, 10); auto slen = strlen(tmp); @@ -1660,7 +1661,7 @@ namespace lgfx return buf; } - std::uint16_t LGFXBase::decodeUTF8(std::uint8_t c) + uint16_t LGFXBase::decodeUTF8(uint8_t c) { // 7 bit Unicode Code Point if (!(c & 0x80)) { @@ -1686,7 +1687,7 @@ namespace lgfx return 0; } // 21 bit Unicode Code Point not supported so fall-back to extended ASCII - //if ((c & 0xF8) == 0xF0) return (std::uint16_t)c; + //if ((c & 0xF8) == 0xF0) return (uint16_t)c; } else { @@ -1706,25 +1707,25 @@ namespace lgfx return c; // fall-back to extended ASCII } - std::int32_t LGFXBase::fontHeight(const IFont* font) const + int32_t LGFXBase::fontHeight(const IFont* font) const { FontMetrics fm; font->getDefaultMetric(&fm); - std::int32_t sy = 65536 * _text_style.size_y; + int32_t sy = 65536 * _text_style.size_y; return (fm.height * sy) >> 16; } - std::int32_t LGFXBase::textLength(const char *string, std::int32_t width) + int32_t LGFXBase::textLength(const char *string, int32_t width) { if (!string || !string[0]) return 0; - std::int32_t sx = 65536 * _text_style.size_x; + int32_t sx = 65536 * _text_style.size_x; - std::int32_t left = 0; - std::int32_t right = 0; + int32_t left = 0; + int32_t right = 0; auto str = string; do { - std::uint16_t uniCode = *string; + uint16_t uniCode = *string; if (_text_style.utf8) { do { uniCode = decodeUTF8(*string); @@ -1735,7 +1736,7 @@ namespace lgfx //if (!_font->updateFontMetric(&_font_metrics, uniCode)) continue; _font->updateFontMetric(&_font_metrics, uniCode); if (left == 0 && right == 0 && _font_metrics.x_offset < 0) left = right = - ((_font_metrics.x_offset * sx) >> 16); - std::int32_t sxadvance = (_font_metrics.x_advance * sx) >> 16; + int32_t sxadvance = (_font_metrics.x_advance * sx) >> 16; right = left + std::max(sxadvance, ((_font_metrics.width * sx) >> 16) + ((_font_metrics.x_offset * sx) >> 16)); //right = left + (int)(std::max(_font_metrics.x_advance, _font_metrics.width + _font_metrics.x_offset) * sx); left += sxadvance; @@ -1744,7 +1745,7 @@ namespace lgfx return string - str; } - std::int32_t LGFXBase::textWidth(const char *string, const IFont* font) + int32_t LGFXBase::textWidth(const char *string, const IFont* font) { auto metrics = _font_metrics; if (font == nullptr) @@ -1759,16 +1760,16 @@ namespace lgfx return text_width(string, font, &metrics); } - std::int32_t LGFXBase::text_width(const char *string, const IFont* font, FontMetrics* metrics) + int32_t LGFXBase::text_width(const char *string, const IFont* font, FontMetrics* metrics) { if (!string || !string[0]) return 0; - std::int32_t sx = 65536 * _text_style.size_x; + int32_t sx = 65536 * _text_style.size_x; - std::int32_t left = 0; - std::int32_t right = 0; + int32_t left = 0; + int32_t right = 0; do { - std::uint16_t uniCode = *string; + uint16_t uniCode = *string; if (_text_style.utf8) { do { uniCode = decodeUTF8(*string); @@ -1778,9 +1779,9 @@ namespace lgfx //if (!_font->updateFontMetric(&metrics, uniCode)) continue; font->updateFontMetric(metrics, uniCode); - std::int32_t sxoffset = (metrics->x_offset * sx) >> 16; + int32_t sxoffset = (metrics->x_offset * sx) >> 16; if (left == 0 && right == 0 && metrics->x_offset < 0) left = right = - sxoffset; - std::int32_t sxadvance = (metrics->x_advance * sx) >> 16; + int32_t sxadvance = (metrics->x_advance * sx) >> 16; right = left + std::max(sxadvance, ((metrics->width * sx) >> 16) + sxoffset); //right = left + (int)(std::max(metrics->x_advance, metrics->width + metrics->x_offset) * sx); left += sxadvance; @@ -1789,30 +1790,30 @@ namespace lgfx } - std::size_t LGFXBase::drawNumber(long long_num, std::int32_t poX, std::int32_t poY, const IFont* font) + size_t LGFXBase::drawNumber(long long_num, int32_t poX, int32_t poY, const IFont* font) { - constexpr std::size_t len = 8 * sizeof(long) + 1; + constexpr size_t len = 8 * sizeof(long) + 1; char buf[len]; return drawString(numberToStr(long_num, buf, len, 10), poX, poY, font); } - std::size_t LGFXBase::drawFloat(float floatNumber, std::uint8_t dp, std::int32_t poX, std::int32_t poY, const IFont* font) + size_t LGFXBase::drawFloat(float floatNumber, uint8_t dp, int32_t poX, int32_t poY, const IFont* font) { - std::size_t len = 14 + dp; - char buf[len]; + size_t len = 14 + dp; + auto buf = (char*)alloca(len); return drawString(floatToStr(floatNumber, buf, len, dp), poX, poY, font); } - std::size_t LGFXBase::drawChar(std::uint16_t uniCode, std::int32_t x, std::int32_t y, std::uint8_t font) + size_t LGFXBase::drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font) { if (_font == fontdata[font]) return drawChar(uniCode, x, y); - std::int32_t dummy_filled_x = 0; + int32_t dummy_filled_x = 0; FontMetrics metrics; fontdata[font]->getDefaultMetric(&metrics); return fontdata[font]->drawChar(this, x, y, uniCode, &_text_style, &metrics, dummy_filled_x); } - std::size_t LGFXBase::draw_string(const char *string, std::int32_t x, std::int32_t y, textdatum_t datum, const IFont* font) + size_t LGFXBase::draw_string(const char *string, int32_t x, int32_t y, textdatum_t datum, const IFont* font) { auto metrics = _font_metrics; if (font == nullptr) @@ -1824,15 +1825,15 @@ namespace lgfx { font->getDefaultMetric(&metrics); } - std::int16_t sumX = 0; - std::int32_t cwidth = text_width(string, font, &metrics); // Find the pixel width of the string in the font - std::int32_t sy = 65536 * _text_style.size_y; - std::int32_t cheight = (metrics.height * sy) >> 16; + int16_t sumX = 0; + int32_t cwidth = text_width(string, font, &metrics); // Find the pixel width of the string in the font + int32_t sy = 65536 * _text_style.size_y; + int32_t cheight = (metrics.height * sy) >> 16; if (string && string[0]) { auto tmp = string; do { - std::uint16_t uniCode = *tmp; + uint16_t uniCode = *tmp; if (_text_style.utf8) { do { uniCode = decodeUTF8(*tmp); @@ -1844,7 +1845,7 @@ namespace lgfx font->updateFontMetric(&metrics, uniCode); if (metrics.x_offset < 0) { - std::int32_t sx = 65536 * _text_style.size_x; + int32_t sx = 65536 * _text_style.size_x; sumX = - (metrics.x_offset * sx) >> 16; } break; @@ -1860,7 +1861,7 @@ namespace lgfx } this->startWrite(); - std::int32_t padx = _padding_x; + int32_t padx = _text_style.padding_x; if ((_text_style.fore_rgb888 != _text_style.back_rgb888) && (padx > cwidth)) { this->setColor(_text_style.back_rgb888); if (datum & top_center) { @@ -1885,10 +1886,10 @@ namespace lgfx y -= (metrics.y_offset * sy) >> 16; - std::int32_t dummy_filled_x = 0; + int32_t dummy_filled_x = 0; if (string && string[0]) { do { - std::uint16_t uniCode = *string; + uint16_t uniCode = *string; if (_text_style.utf8) { do { uniCode = decodeUTF8(*string); @@ -1903,16 +1904,16 @@ namespace lgfx return sumX; } - std::size_t LGFXBase::write(std::uint8_t utf8) + size_t LGFXBase::write(uint8_t utf8) { if (utf8 == '\r') return 1; - std::int32_t sy = 65536 * _text_style.size_y; + int32_t sy = 65536 * _text_style.size_y; if (utf8 == '\n') { _filled_x = (_textscroll) ? this->_sx : 0; _cursor_x = _filled_x; _cursor_y += (_font_metrics.y_advance * sy) >> 16; } else { - std::uint16_t uniCode = utf8; + uint16_t uniCode = utf8; if (_text_style.utf8) { uniCode = decodeUTF8(utf8); if (uniCode < 0x20) return 1; @@ -1921,23 +1922,23 @@ namespace lgfx //if (!_font->updateFontMetric(&_font_metrics, uniCode)) return 1; _font->updateFontMetric(&_font_metrics, uniCode); - std::int32_t sx = 65536 * _text_style.size_x; - std::int32_t xo = (_font_metrics.x_offset * sx) >> 16; - std::int32_t w = std::max(xo + ((_font_metrics.width * sx) >> 16), (_font_metrics.x_advance * sx) >> 16); + int32_t sx = 65536 * _text_style.size_x; + int32_t xo = (_font_metrics.x_offset * sx) >> 16; + int32_t w = std::max(xo + ((_font_metrics.width * sx) >> 16), (_font_metrics.x_advance * sx) >> 16); if (_textscroll || _textwrap_x) { - std::int32_t llimit = _textscroll ? this->_sx : this->_clip_l; - std::int32_t rlimit = _textscroll ? this->_sx + this->_sw : (this->_clip_r + 1); + int32_t llimit = _textscroll ? this->_sx : this->_clip_l; + int32_t rlimit = _textscroll ? this->_sx + this->_sw : (this->_clip_r + 1); if (_cursor_x + w > rlimit) { _filled_x = llimit; - _cursor_x = llimit - std::min(0, xo); + _cursor_x = llimit - std::min(0, xo); _cursor_y += (_font_metrics.y_advance * sy) >> 16; } if (_cursor_x < llimit - xo) _cursor_x = llimit - xo; } - std::int32_t h = (_font_metrics.height * sy) >> 16; + int32_t h = (_font_metrics.height * sy) >> 16; - std::int32_t ydiff = 0; + int32_t ydiff = 0; if (_text_style.datum & middle_left) { // vertical: middle ydiff -= h >> 1; } else if (_text_style.datum & bottom_left) { // vertical: bottom @@ -1945,7 +1946,7 @@ namespace lgfx } else if (_text_style.datum & baseline_left) { // vertical: baseline ydiff -= (_font_metrics.baseline * sy) >> 16; } - std::int32_t y = _cursor_y + ydiff; + int32_t y = _cursor_y + ydiff; if (_textscroll) { if (y < this->_sy) y = this->_sy; @@ -1965,13 +1966,13 @@ namespace lgfx _cursor_y = y - ydiff; y -= (_font_metrics.y_offset * sy) >> 16; - if (y <= _clip_b) + if (y <= _clip_b + h) { _cursor_x += _font->drawChar(this, _cursor_x, y, uniCode, &_text_style, &_font_metrics, _filled_x); } else { - std::int32_t sx = 65536 * _text_style.size_x; + int32_t sx = 65536 * _text_style.size_x; _font->updateFontMetric(&_font_metrics, uniCode); _cursor_x += (_font_metrics.x_advance * sx) >> 16; } @@ -1980,33 +1981,33 @@ namespace lgfx return 1; } - std::size_t LGFXBase::printNumber(unsigned long n, std::uint8_t base) + size_t LGFXBase::printNumber(unsigned long n, uint8_t base) { - std::size_t len = 8 * sizeof(long) + 1; - char buf[len]; + size_t len = 8 * sizeof(long) + 1; + auto buf = (char*)alloca(len); return write(numberToStr(n, buf, len, base)); } - std::size_t LGFXBase::printFloat(double number, std::uint8_t digits) + size_t LGFXBase::printFloat(double number, uint8_t digits) { - std::size_t len = 14 + digits; - char buf[len]; + size_t len = 14 + digits; + auto buf = (char*)alloca(len); return write(floatToStr(number, buf, len, digits)); } #if !defined (ARDUINO) - std::size_t LGFXBase::printf(const char * __restrict__ format, ...) + size_t LGFXBase::printf(const char * __restrict__ format, ...) { va_list arg; va_start(arg, format); - std::size_t len = vprintf(format, arg); + size_t len = vprintf(format, arg); va_end(arg); return len; } #endif - std::size_t LGFXBase::vprintf(const char* __restrict__ format, va_list arg) + size_t LGFXBase::vprintf(const char* __restrict__ format, va_list arg) { char loc_buf[64]; char * temp = loc_buf; @@ -2015,7 +2016,7 @@ namespace lgfx int len = vsnprintf(temp, sizeof(loc_buf), format, copy); va_end(copy); if (len < 0) { return 0; } - if ((std::size_t)len >= sizeof(loc_buf)) + if ((size_t)len >= sizeof(loc_buf)) { temp = (char*) malloc(len + 1); if (temp == nullptr) @@ -2024,7 +2025,7 @@ namespace lgfx } len = vsnprintf(temp, len+1, format, arg); } - len = write((std::uint8_t*)temp, len); + len = write((uint8_t*)temp, len); if (temp != loc_buf) { free(temp); @@ -2046,7 +2047,7 @@ namespace lgfx } /// load VLW font - bool LGFXBase::loadFont(const std::uint8_t* array) + bool LGFXBase::loadFont(const uint8_t* array) { _font_data.set(array); return load_font(&_font_data); @@ -2059,7 +2060,7 @@ namespace lgfx #ifdef LGFX_TTFFONT_HPP_ // TTF support. - std::uint8_t buf[4]; + uint8_t buf[4]; data->seek(0); data->read(buf, 4); data->seek(0); @@ -2089,14 +2090,14 @@ namespace lgfx if (_runtime_font.get() != nullptr) { setFont(&fonts::Font0); } } - void LGFXBase::showFont(std::uint32_t td) + void LGFXBase::showFont(uint32_t td) { - std::int_fast16_t x = 0; - std::int_fast16_t y = 0; + int_fast16_t x = 0; + int_fast16_t y = 0; this->fillScreen(this->_text_style.back_rgb888); - std::uint32_t code = 0; + uint32_t code = 0; while (++code < 65536) { if (!getFont()->updateFontMetric(&_font_metrics, code)) continue; @@ -2118,7 +2119,7 @@ namespace lgfx this->fillScreen(this->_text_style.back_rgb888); } - void LGFXBase::setAttribute(attribute_t attr_id, std::uint8_t param) { + void LGFXBase::setAttribute(attribute_t attr_id, uint8_t param) { switch (attr_id) { case cp437_switch: _text_style.cp437 = param; @@ -2134,7 +2135,7 @@ namespace lgfx } } - std::uint8_t LGFXBase::getAttribute(attribute_t attr_id) { + uint8_t LGFXBase::getAttribute(attribute_t attr_id) { switch (attr_id) { case cp437_switch: return _text_style.cp437; case utf8_switch: return _text_style.utf8; @@ -2145,7 +2146,7 @@ namespace lgfx //---------------------------------------------------------------------------- - void LGFXBase::qrcode(const char *string, std::int32_t x, std::int32_t y, std::int32_t w, std::uint8_t version) { + void LGFXBase::qrcode(const char *string, int32_t x, int32_t y, int32_t w, uint8_t version) { if (w == -1) { w = std::min(width(), height()) * 9 / 10; } @@ -2157,15 +2158,16 @@ namespace lgfx setColor(0xFFFFFFU); startWrite(); writeFillRect(x, y, w, w); - for (; version <= 40; ++version) { + for (; version <= 40; ++version) + { QRCode qrcode; - std::uint8_t qrcodeData[lgfx_qrcode_getBufferSize(version)]; + auto qrcodeData = (uint8_t*)alloca(lgfx_qrcode_getBufferSize(version)); if (0 != lgfx_qrcode_initText(&qrcode, qrcodeData, version, 0, string)) continue; - std::int_fast16_t thickness = w / qrcode.size; + int_fast16_t thickness = w / qrcode.size; if (!thickness) break; - std::int_fast16_t lineLength = qrcode.size * thickness; - std::int_fast16_t xOffset = x + ((w - lineLength) >> 1); - std::int_fast16_t yOffset = y + ((w - lineLength) >> 1); + int_fast16_t lineLength = qrcode.size * thickness; + int_fast16_t xOffset = x + ((w - lineLength) >> 1); + int_fast16_t yOffset = y + ((w - lineLength) >> 1); setColor(0); y = 0; do { @@ -2181,17 +2183,17 @@ namespace lgfx //---------------------------------------------------------------------------- - bool LGFXBase::draw_bmp(DataWrapper* data, std::int32_t x, std::int32_t y, std::int32_t maxWidth, std::int32_t maxHeight, std::int32_t offX, std::int32_t offY, float scale_x, float scale_y, datum_t datum) + bool LGFXBase::draw_bmp(DataWrapper* data, int32_t x, int32_t y, int32_t maxWidth, int32_t maxHeight, int32_t offX, int32_t offY, float scale_x, float scale_y, datum_t datum) { bitmap_header_t bmpdata; if (!bmpdata.load_bmp_header(data) || (bmpdata.biCompression > 3)) { return false; } - std::uint32_t seekOffset = bmpdata.bfOffBits; + uint32_t seekOffset = bmpdata.bfOffBits; uint_fast16_t bpp = bmpdata.biBitCount; // 24 bcBitCount 24=RGB24bit - std::int32_t w = bmpdata.biWidth; - std::int32_t h = abs(bmpdata.biHeight); // bcHeight Image height (pixels) + int32_t w = bmpdata.biWidth; + int32_t h = abs(bmpdata.biHeight); // bcHeight Image height (pixels) const auto cl = this->_clip_l; const auto cr = this->_clip_r + 1; @@ -2253,14 +2255,15 @@ namespace lgfx if (bpp <= 8) { palette = (argb8888_t*)heap_alloc(sizeof(argb8888_t*) * (1 << bpp)); data->seek(bmpdata.biSize + 14); - data->read((std::uint8_t*)palette, (1 << bpp)*sizeof(argb8888_t)); // load palette + data->read((uint8_t*)palette, (1 << bpp)*sizeof(argb8888_t)); // load palette } data->seek(seekOffset); auto dst_depth = this->_write_conv.depth; - std::uint32_t buffersize = ((w * bpp + 31) >> 5) << 2; // readline 4Byte align. - std::uint8_t lineBuffer[buffersize + 4]; + uint32_t buffersize = ((w * bpp + 31) >> 5) << 2; // readline 4Byte align. + auto lineBuffer = (uint8_t*)alloca(buffersize + 4); + pixelcopy_t p(lineBuffer, dst_depth, (color_depth_t)bpp, this->_palette_count, palette); p.no_convert = false; if (8 >= bpp && !this->_palette_count) { @@ -2278,14 +2281,14 @@ namespace lgfx //If the value of Height is positive, the image data is from bottom to top //If the value of Height is negative, the image data is from top to bottom. - std::int32_t flow = (bmpdata.biHeight > 0) ? -1 : 1; + int32_t flow = (bmpdata.biHeight > 0) ? -1 : 1; if (bmpdata.biHeight > 0) y += ceilf(h * scale_y) - 1; x -= offX; y -= offY; - std::int32_t y32 = (y << FP_SCALE); - std::int32_t dst_y32_add = (1u << FP_SCALE) * scale_y; + int32_t y32 = (y << FP_SCALE); + int32_t dst_y32_add = (1u << FP_SCALE) * scale_y; if (bmpdata.biHeight > 0) dst_y32_add = - dst_y32_add; this->startWrite(!data->hasParent()); @@ -2312,7 +2315,7 @@ namespace lgfx } data->postRead(); y32 += dst_y32_add; - std::int32_t next_y = y32 >> FP_SCALE; + int32_t next_y = y32 >> FP_SCALE; while (y != next_y) { p.src_x32 = 0; @@ -2335,8 +2338,8 @@ namespace lgfx struct draw_jpg_info_t { - std::int32_t x; - std::int32_t y; + int32_t x; + int32_t y; DataWrapper *data; LGFXBase *lgfx; pixelcopy_t *pc; @@ -2344,7 +2347,7 @@ namespace lgfx float zoom_y; }; - static std::uint32_t jpg_read_data(lgfxJdec *decoder, std::uint8_t *buf, std::uint32_t len) + static uint32_t jpg_read_data(lgfxJdec *decoder, uint8_t *buf, uint32_t len) { auto jpeg = (draw_jpg_info_t *)decoder->device; auto data = (DataWrapper*)jpeg->data; @@ -2358,16 +2361,16 @@ namespace lgfx return res; } - static std::uint32_t jpg_push_image(lgfxJdec *decoder, void *bitmap, JRECT *rect) + static uint32_t jpg_push_image(lgfxJdec *decoder, void *bitmap, JRECT *rect) { draw_jpg_info_t *jpeg = static_cast(decoder->device); jpeg->pc->src_data = bitmap; auto data = static_cast(jpeg->data); data->postRead(); - std::int32_t x = rect->left; - std::int32_t y = rect->top; - std::int32_t w = rect->right - rect->left + 1; - std::int32_t h = rect->bottom - rect->top + 1; + int32_t x = rect->left; + int32_t y = rect->top; + int32_t w = rect->right - rect->left + 1; + int32_t h = rect->bottom - rect->top + 1; jpeg->lgfx->pushImage( jpeg->x + x , jpeg->y + y , w @@ -2377,17 +2380,17 @@ namespace lgfx return 1; } - static std::uint32_t jpg_push_image_affine(lgfxJdec *decoder, void *bitmap, JRECT *rect) + static uint32_t jpg_push_image_affine(lgfxJdec *decoder, void *bitmap, JRECT *rect) { draw_jpg_info_t *jpeg = static_cast(decoder->device); jpeg->pc->src_data = bitmap; auto data = static_cast(jpeg->data); data->postRead(); - std::int32_t x = rect->left; - std::int32_t y = rect->top; - std::int32_t w = rect->right - rect->left + 1; - std::int32_t h = rect->bottom - rect->top + 1; + int32_t x = rect->left; + int32_t y = rect->top; + int32_t w = rect->right - rect->left + 1; + int32_t h = rect->bottom - rect->top + 1; float affine[6] = { jpeg->zoom_x, 0.0f , x * jpeg->zoom_x + jpeg->x , 0.0f , jpeg->zoom_y, y * jpeg->zoom_y + jpeg->y @@ -2396,7 +2399,7 @@ namespace lgfx return 1; } - bool LGFXBase::draw_jpg(DataWrapper* data, std::int32_t x, std::int32_t y, std::int32_t maxWidth, std::int32_t maxHeight, std::int32_t offX, std::int32_t offY, float scale_x, float scale_y, datum_t datum) + bool LGFXBase::draw_jpg(DataWrapper* data, int32_t x, int32_t y, int32_t maxWidth, int32_t maxHeight, int32_t offX, int32_t offY, float scale_x, float scale_y, datum_t datum) { draw_jpg_info_t jpeg; pixelcopy_t pc(nullptr, this->getColorDepth(), bgr888_t::depth, this->hasPalette()); @@ -2409,8 +2412,8 @@ namespace lgfx //TJpgD jpegdec; lgfxJdec jpegdec; - static constexpr std::uint16_t sz_pool = 3100; - std::uint8_t *pool = (std::uint8_t*)heap_alloc_dma(sz_pool); + static constexpr uint16_t sz_pool = 3100; + uint8_t *pool = (uint8_t*)heap_alloc_dma(sz_pool); if (!pool) { return false; @@ -2514,25 +2517,26 @@ namespace lgfx struct png_file_decoder_t { - std::int32_t x; - std::int32_t y; - std::int32_t offX; - std::int32_t offY; - std::int32_t maxWidth; - std::int32_t maxHeight; + int32_t x; + int32_t y; + int32_t offX; + int32_t offY; + int32_t maxWidth; + int32_t maxHeight; float zoom_x; float zoom_y; datum_t datum; bgr888_t* lineBuffer; pixelcopy_t *pc; LGFXBase *gfx; - std::uint32_t last_pos; - std::uint32_t last_x; - std::int32_t scale_y0; - std::int32_t scale_y1; + uint32_t last_pos; + uint32_t last_x; + int32_t scale_y0; + int32_t scale_y1; + bool done; }; - static bool png_ypos_update(png_file_decoder_t *p, std::uint32_t y) + static bool png_ypos_update(png_file_decoder_t *p, uint32_t y) { p->last_pos = y; p->scale_y0 = ceilf( y * p->zoom_y) - p->offY; @@ -2544,12 +2548,12 @@ namespace lgfx static void png_post_line(png_file_decoder_t *p) { - std::int32_t h = p->scale_y1 - p->scale_y0; + int32_t h = p->scale_y1 - p->scale_y0; if (0 < h) p->gfx->pushImage(p->x, p->y + p->scale_y0, p->maxWidth, h, p->pc, true); } - static void png_prepare_line(png_file_decoder_t *p, std::uint32_t y) + static void png_prepare_line(png_file_decoder_t *p, uint32_t y) { if (png_ypos_update(p, y)) // read next line p->gfx->readRectRGB(p->x, p->y + p->scale_y0, p->maxWidth, p->scale_y1 - p->scale_y0, p->lineBuffer); @@ -2558,19 +2562,23 @@ namespace lgfx static void png_done_callback(pngle_t *pngle) { auto p = (png_file_decoder_t *)lgfx_pngle_get_user_data(pngle); - png_post_line(p); + p->done = true; + if (p->lineBuffer) + { + png_post_line(p); + } } - static void png_draw_normal_callback(pngle_t *pngle, std::uint32_t x, std::uint32_t y, std::uint8_t rgba[4]) + static void png_draw_normal_callback(pngle_t *pngle, uint32_t x, uint32_t y, uint8_t rgba[4]) { auto p = (png_file_decoder_t*)lgfx_pngle_get_user_data(pngle); - std::int32_t l = x - p->offX; + int32_t l = x - p->offX; if (l < 0 || l >= p->maxWidth) return; x = p->x + l; if (x != p->last_pos) { - std::int32_t t = y - p->offY; + int32_t t = y - p->offY; if (t < 0 || t >= p->maxHeight) return; p->gfx->setAddrWindow(x, p->y + t, p->maxWidth, 1); } @@ -2578,7 +2586,7 @@ namespace lgfx p->gfx->writeColor(color888(rgba[0], rgba[1], rgba[2]), 1); } - static void png_draw_normal_scale_callback(pngle_t *pngle, std::uint32_t x, std::uint32_t y, std::uint8_t rgba[4]) + static void png_draw_normal_scale_callback(pngle_t *pngle, uint32_t x, uint32_t y, uint8_t rgba[4]) { auto p = (png_file_decoder_t*)lgfx_pngle_get_user_data(pngle); @@ -2586,13 +2594,13 @@ namespace lgfx png_ypos_update(p, y); } - std::int32_t t = p->scale_y0; - std::int32_t h = p->scale_y1 - t; + int32_t t = p->scale_y0; + int32_t h = p->scale_y1 - t; if (h <= 0) return; - std::int32_t l = ceilf( x * p->zoom_x) - p->offX; + int32_t l = ceilf( x * p->zoom_x) - p->offX; if (l < 0) l = 0; - std::int32_t r = ceilf((x + 1) * p->zoom_x) - p->offX; + int32_t r = ceilf((x + 1) * p->zoom_x) - p->offX; if (r > p->maxWidth) r = p->maxWidth; if (l >= r) return; @@ -2600,7 +2608,7 @@ namespace lgfx p->gfx->writeFillRectPreclipped(p->x + l, p->y + t, r - l, h); } - static void png_draw_alpha_callback(pngle_t *pngle, std::uint32_t x, std::uint32_t y, std::uint8_t rgba[4]) + static void png_draw_alpha_callback(pngle_t *pngle, uint32_t x, uint32_t y, uint8_t rgba[4]) { auto p = (png_file_decoder_t*)lgfx_pngle_get_user_data(pngle); if (y != p->last_pos) { @@ -2610,8 +2618,8 @@ namespace lgfx if (p->scale_y0 >= p->scale_y1) return; - std::int32_t l = std::max(( x ) - p->offX, 0); - std::int32_t r = std::min(((x + 1) ) - p->offX, p->maxWidth); + int32_t l = std::max(( x ) - p->offX, 0); + int32_t r = std::min(((x + 1) ) - p->offX, p->maxWidth); if (l >= r) return; if (rgba[3] == 255) { @@ -2626,7 +2634,7 @@ namespace lgfx } } - static void png_draw_alpha_scale_callback(pngle_t *pngle, std::uint32_t x, std::uint32_t y, std::uint8_t rgba[4]) + static void png_draw_alpha_scale_callback(pngle_t *pngle, uint32_t x, uint32_t y, uint8_t rgba[4]) { auto p = (png_file_decoder_t*)lgfx_pngle_get_user_data(pngle); if (y != p->last_pos) { @@ -2634,19 +2642,19 @@ namespace lgfx png_prepare_line(p, y); } - std::int32_t b = p->scale_y1 - p->scale_y0; + int32_t b = p->scale_y1 - p->scale_y0; if (b <= 0) return; - std::int32_t l = ceilf( x * p->zoom_x) - p->offX; + int32_t l = ceilf( x * p->zoom_x) - p->offX; if (l < 0) l = 0; - std::int32_t r = ceilf((x + 1) * p->zoom_x) - p->offX; + int32_t r = ceilf((x + 1) * p->zoom_x) - p->offX; if (r > p->maxWidth) r = p->maxWidth; if (l >= r) return; if (rgba[3] == 255) { - std::int32_t i = l; + int32_t i = l; do { - for (std::int32_t j = 0; j < b; ++j) { + for (int32_t j = 0; j < b; ++j) { auto data = &p->lineBuffer[i + j * p->maxWidth]; memcpy(data, rgba, 3); } @@ -2654,9 +2662,9 @@ namespace lgfx } else { uint_fast8_t inv = 256 - rgba[3]; uint_fast8_t alpha = rgba[3] + 1; - std::int32_t i = l; + int32_t i = l; do { - for (std::int32_t j = 0; j < b; ++j) { + for (int32_t j = 0; j < b; ++j) { auto data = &p->lineBuffer[i + j * p->maxWidth]; data->r = (rgba[0] * alpha + data->r * inv) >> 8; data->g = (rgba[1] * alpha + data->g * inv) >> 8; @@ -2666,12 +2674,12 @@ namespace lgfx } } - static void png_init_callback(pngle_t *pngle, std::uint32_t w, std::uint32_t h, uint_fast8_t hasTransparent) + static void png_init_callback(pngle_t *pngle, uint32_t w, uint32_t h, uint_fast8_t hasTransparent) { auto p = (png_file_decoder_t*)lgfx_pngle_get_user_data(pngle); auto me = p->gfx; - std::int32_t cw, ch, cl, ct; + int32_t cw, ch, cl, ct; me->getClipRect(&cl, &ct, &cw, &ch); if (p->zoom_y <= 0.0f || p->zoom_x <= 0.0f) @@ -2704,26 +2712,26 @@ namespace lgfx { if (p->datum & (datum_t::top_center | datum_t::top_right)) { - float fw = p->maxWidth - (std::int32_t)w; + float fw = p->maxWidth - (int32_t)w; if (p->datum & datum_t::top_center) { fw /= 2; } p->offX -= fw; } if (p->datum & (datum_t::middle_left | datum_t::bottom_left | datum_t::baseline_left)) { - float fh = p->maxHeight - (std::int32_t)h; + float fh = p->maxHeight - (int32_t)h; if (p->datum & datum_t::middle_left) { fh /= 2; } p->offY -= fh; } } - const std::int32_t cr = cw + cl; - const std::int32_t cb = ch + ct; + const int32_t cr = cw + cl; + const int32_t cb = ch + ct; if (0 > p->x - cl) { p->maxWidth += p->x - cl; p->offX -= p->x - cl; p->x = cl; } if (0 > p->offX) { p->x -= p->offX; p->maxWidth += p->offX; p->offX = 0; } if (p->maxWidth > (cr - p->x)) p->maxWidth = (cr - p->x); - std::int32_t ww = w - abs(p->offX); + int32_t ww = w - abs(p->offX); if (p->maxWidth > ww) p->maxWidth = ww; if (p->maxWidth < 0) return; @@ -2731,16 +2739,16 @@ namespace lgfx if (0 > p->offY) { p->y -= p->offY; p->maxHeight += p->offY; p->offY = 0; } if (p->maxHeight > (cb - p->y)) p->maxHeight = (cb - p->y); - std::int32_t hh = h - abs(p->offY); + int32_t hh = h - abs(p->offY); if (p->maxHeight > hh) p->maxHeight = hh; if (p->maxHeight < 0) return; + lgfx_pngle_set_done_callback(pngle, png_done_callback); if (hasTransparent) { // need pixel read ? p->lineBuffer = (bgr888_t*)heap_alloc_dma(sizeof(bgr888_t) * p->maxWidth * ceilf(p->zoom_x)); p->pc->src_data = p->lineBuffer; png_prepare_line(p, 0); - lgfx_pngle_set_done_callback(pngle, png_done_callback); if (p->zoom_x == 1.0f && p->zoom_y == 1.0f) { @@ -2751,6 +2759,7 @@ namespace lgfx lgfx_pngle_set_draw_callback(pngle, png_draw_alpha_scale_callback); } } else { + p->lineBuffer = nullptr; if (p->zoom_x == 1.0f && p->zoom_y == 1.0f) { p->last_pos = ~0; @@ -2761,11 +2770,10 @@ namespace lgfx png_ypos_update(p, 0); lgfx_pngle_set_draw_callback(pngle, png_draw_normal_scale_callback); } - return; } } - bool LGFXBase::draw_png(DataWrapper* data, std::int32_t x, std::int32_t y, std::int32_t maxWidth, std::int32_t maxHeight, std::int32_t offX, std::int32_t offY, float scale_x, float scale_y, datum_t datum) + bool LGFXBase::draw_png(DataWrapper* data, int32_t x, int32_t y, int32_t maxWidth, int32_t maxHeight, int32_t offX, int32_t offY, float scale_x, float scale_y, datum_t datum) { png_file_decoder_t png; png.x = x; @@ -2779,6 +2787,7 @@ namespace lgfx png.datum = datum; png.gfx = this; png.lineBuffer = nullptr; + png.done = false; pixelcopy_t pc(nullptr, this->getColorDepth(), bgr888_t::depth, this->_palette_count); png.pc = &pc; @@ -2790,7 +2799,7 @@ namespace lgfx lgfx_pngle_set_init_callback(pngle, png_init_callback); // Feed data to pngle - std::uint8_t buf[512]; + uint8_t buf[512]; int remain = 0; int len; bool res = true; @@ -2801,7 +2810,13 @@ namespace lgfx int fed = lgfx_pngle_feed(pngle, buf, remain + len); - if (fed < 0) { + if (png.done) + { + break; + } + + if (fed < 0) + { //ESP_LOGE("LGFX", "[pngle error] %s", lgfx_pngle_error(pngle)); res = false; break; @@ -2823,11 +2838,11 @@ namespace lgfx struct png_encoder_t { LGFXBase* gfx; - std::int32_t x; - std::int32_t y; + int32_t x; + int32_t y; }; - static uint8_t *png_encoder_get_row( std::uint8_t *pImage, int flip, int w, int h, int y, int, void *target ) + static uint8_t *png_encoder_get_row( uint8_t *pImage, int flip, int w, int h, int y, int, void *target ) { auto enc = static_cast(target); uint32_t ypos = (flip ? (h - 1 - y) : y); @@ -2835,7 +2850,7 @@ namespace lgfx return pImage; } - void* LGFXBase::createPng(std::size_t* datalen, std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h) + void* LGFXBase::createPng(size_t* datalen, int32_t x, int32_t y, int32_t w, int32_t h) { if (_adjust_abs(x, w)||_adjust_abs(y, h)) return nullptr; if (x < 0) { w += x; x = 0; } @@ -2924,7 +2939,7 @@ namespace lgfx //---------------------------------------------------------------------------- - void LGFX_Device::draw_calibrate_point(std::int32_t x, std::int32_t y, std::int32_t r, std::uint32_t fg_rawcolor, std::uint32_t bg_rawcolor) + void LGFX_Device::draw_calibrate_point(int32_t x, int32_t y, int32_t r, uint32_t fg_rawcolor, uint32_t bg_rawcolor) { setRawColor(bg_rawcolor); fillRect(x - r, y - r, r * 2 + 1, r * 2 + 1); @@ -2932,10 +2947,10 @@ namespace lgfx setClipRect(x - r, y - r, r * 2 + 1, r * 2 + 1); setRawColor(fg_rawcolor); startWrite(); - auto w = std::max(1, r >> 3); + auto w = std::max(1, r >> 3); fillRect(x - w, y - r, w * 2 + 1, r * 2 + 1); fillRect(x - r, y - w, r * 2 + 1, w * 2 + 1); - for (std::int32_t i = - r; i <= r; ++i) { + for (int32_t i = - r; i <= r; ++i) { drawFastHLine(x + i - w, y + i, w * 2 + 1); drawFastHLine(x - i - w, y + i, w * 2 + 1); } @@ -2944,25 +2959,25 @@ namespace lgfx clearClipRect(); } - void LGFX_Device::calibrate_touch(std::uint16_t *parameters, std::uint32_t fg_rawcolor, std::uint32_t bg_rawcolor, std::uint8_t size) + void LGFX_Device::calibrate_touch(uint16_t *parameters, uint32_t fg_rawcolor, uint32_t bg_rawcolor, uint8_t size) { if (nullptr == touch()) return; auto rot = getRotation(); - std::uint_fast8_t panel_offsetrot = panel()->config().offset_rotation; - std::uint_fast8_t touch_offsetrot = touch()->config().offset_rotation; + uint_fast8_t panel_offsetrot = panel()->config().offset_rotation; + uint_fast8_t touch_offsetrot = touch()->config().offset_rotation; // 回転オフセットをキャンセルしてタッチデバイスのデフォルトの向きに合わせる setRotation(( (touch_offsetrot ^ panel_offsetrot) & 4) |(-(touch_offsetrot + panel_offsetrot) & 3)); - std::uint16_t orig[8]; + uint16_t orig[8]; for (int i = 0; i < 4; ++i) { - std::int32_t px = (width() - 1) * ((i>>1) & 1); - std::int32_t py = (height() - 1) * ( i & 1); + int32_t px = (width() - 1) * ((i>>1) & 1); + int32_t py = (height() - 1) * ( i & 1); draw_calibrate_point( px, py, size, fg_rawcolor, bg_rawcolor); delay(512); - std::int32_t x_touch = 0, y_touch = 0; + int32_t x_touch = 0, y_touch = 0; static constexpr int _RAWERR = 20; touch_point_t tp, tp2; for (int j = 0; j < 8; ++j) { @@ -2984,7 +2999,7 @@ namespace lgfx do { delay(1); } while (getTouchRaw(&tp)); } if (nullptr != parameters) { - memcpy(parameters, orig, sizeof(std::uint16_t) * 8); + memcpy(parameters, orig, sizeof(uint16_t) * 8); } panel()->setCalibrate(orig); setRotation(rot); diff --git a/src/lgfx/v1/LGFXBase.hpp b/src/lgfx/v1/LGFXBase.hpp index 3106578..c10d4ed 100644 --- a/src/lgfx/v1/LGFXBase.hpp +++ b/src/lgfx/v1/LGFXBase.hpp @@ -21,8 +21,8 @@ Original Source: #include #endif -#include -#include +#include +#include #include "platforms/common.hpp" #include "misc/enum.hpp" @@ -51,22 +51,22 @@ namespace lgfx #define LGFX_INLINE __attribute__ ((always_inline)) inline #define LGFX_INLINE_T template __attribute__ ((always_inline)) inline - LGFX_INLINE static constexpr std::uint8_t color332(std::uint8_t r, std::uint8_t g, std::uint8_t b) { return lgfx::color332(r, g, b); } - LGFX_INLINE static constexpr std::uint16_t color565(std::uint8_t r, std::uint8_t g, std::uint8_t b) { return lgfx::color565(r, g, b); } - LGFX_INLINE static constexpr std::uint32_t color888(std::uint8_t r, std::uint8_t g, std::uint8_t b) { return lgfx::color888(r, g, b); } - LGFX_INLINE static constexpr std::uint16_t swap565( std::uint8_t r, std::uint8_t g, std::uint8_t b) { return lgfx::swap565( r, g, b); } - LGFX_INLINE static constexpr std::uint32_t swap888( std::uint8_t r, std::uint8_t g, std::uint8_t b) { return lgfx::swap888( r, g, b); } - LGFX_INLINE static constexpr std::uint8_t color16to8(std::uint32_t rgb565) { return lgfx::convert_rgb565_to_rgb332(rgb565); } - LGFX_INLINE static constexpr std::uint16_t color8to16(std::uint32_t rgb332) { return lgfx::convert_rgb332_to_rgb565(rgb332); } - LGFX_INLINE static constexpr std::uint32_t color16to24(std::uint32_t rgb565) { return lgfx::convert_rgb565_to_rgb888(rgb565); } - LGFX_INLINE static constexpr std::uint16_t color24to16(std::uint32_t rgb888) { return lgfx::convert_rgb888_to_rgb565(rgb888); } - - LGFX_INLINE void setColor(std::uint8_t r, std::uint8_t g, std::uint8_t b) { setColor(lgfx::color888(r,g,b)); } + LGFX_INLINE static constexpr uint8_t color332(uint8_t r, uint8_t g, uint8_t b) { return lgfx::color332(r, g, b); } + LGFX_INLINE static constexpr uint16_t color565(uint8_t r, uint8_t g, uint8_t b) { return lgfx::color565(r, g, b); } + LGFX_INLINE static constexpr uint32_t color888(uint8_t r, uint8_t g, uint8_t b) { return lgfx::color888(r, g, b); } + LGFX_INLINE static constexpr uint16_t swap565( uint8_t r, uint8_t g, uint8_t b) { return lgfx::swap565( r, g, b); } + LGFX_INLINE static constexpr uint32_t swap888( uint8_t r, uint8_t g, uint8_t b) { return lgfx::swap888( r, g, b); } + LGFX_INLINE static uint8_t color16to8( uint32_t rgb565) { return lgfx::color_convert(rgb565); } + LGFX_INLINE static uint16_t color8to16( uint32_t rgb332) { return lgfx::color_convert(rgb332); } + LGFX_INLINE static uint32_t color16to24(uint32_t rgb565) { return lgfx::color_convert(rgb565); } + LGFX_INLINE static uint16_t color24to16(uint32_t rgb888) { return lgfx::color_convert(rgb888); } + + LGFX_INLINE void setColor(uint8_t r, uint8_t g, uint8_t b) { setColor(lgfx::color888(r,g,b)); } LGFX_INLINE_T void setColor(T color) { setRawColor(_write_conv.convert(color)); } - LGFX_INLINE void setRawColor(std::uint32_t c) { *((std::uint32_t*)&_color) = c; } - LGFX_INLINE std::uint32_t getRawColor(void) const { return *((std::uint32_t*)&_color); } + LGFX_INLINE void setRawColor(uint32_t c) { *((uint32_t*)&_color) = c; } + LGFX_INLINE uint32_t getRawColor(void) const { return *((uint32_t*)&_color); } LGFX_INLINE_T void setBaseColor(T c) { _base_rgb888 = hasPalette() ? c : convert_to_rgb888(c); } - LGFX_INLINE std::uint32_t getBaseColor(void) const { return _base_rgb888; } + LGFX_INLINE uint32_t getBaseColor(void) const { return _base_rgb888; } LGFX_INLINE color_conv_t* getColorConverter(void) { return &_write_conv; } LGFX_INLINE color_depth_t getColorDepth(void) const { return _write_conv.depth; } @@ -74,78 +74,78 @@ namespace lgfx LGFX_INLINE void endWrite(void) { _panel->endWrite(); } LGFX_INLINE void beginTransaction(void) { _panel->beginTransaction(); } LGFX_INLINE void endTransaction(void) { _panel->endTransaction(); } - LGFX_INLINE std::uint32_t getStartCount(void) const { return _panel->getStartCount(); } - - LGFX_INLINE void setWindow(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) { _panel->setWindow(xs, ys, xe, ye); } - LGFX_INLINE void writePixel(std::int32_t x, std::int32_t y) { if (x >= _clip_l && x <= _clip_r && y >= _clip_t && y <= _clip_b) writeFillRectPreclipped(x, y, 1, 1); } - LGFX_INLINE_T void writePixel ( std::int32_t x, std::int32_t y , const T& color) { setColor(color); writePixel (x, y ); } - LGFX_INLINE_T void writeFastVLine ( std::int32_t x, std::int32_t y , std::int32_t h, const T& color) { setColor(color); writeFastVLine(x, y , h); } - void writeFastVLine ( std::int32_t x, std::int32_t y , std::int32_t h); - LGFX_INLINE_T void writeFastHLine ( std::int32_t x, std::int32_t y, std::int32_t w , const T& color) { setColor(color); writeFastHLine(x, y, w ); } - void writeFastHLine ( std::int32_t x, std::int32_t y, std::int32_t w); - LGFX_INLINE_T void writeFillRect ( std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, const T& color) { setColor(color); writeFillRect (x, y, w, h); } - void writeFillRect ( std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h); - LGFX_INLINE_T void writeFillRectPreclipped( std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, const T& color) { setColor(color); writeFillRectPreclipped(x, y, w, h); } - LGFX_INLINE void writeFillRectPreclipped( std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h) { _panel->writeFillRectPreclipped(x, y, w, h, getRawColor()); } - LGFX_INLINE_T void writeColor ( const T& color, std::uint32_t length) { if (0 == length) return; setColor(color); _panel->writeBlock(getRawColor(), length); } - LGFX_INLINE_T void pushBlock ( const T& color, std::uint32_t length) { if (0 == length) return; setColor(color); startWrite(); _panel->writeBlock(getRawColor(), length); endWrite(); } - LGFX_INLINE void drawPixel ( std::int32_t x, std::int32_t y) { if (x >= _clip_l && x <= _clip_r && y >= _clip_t && y <= _clip_b) { _panel->drawPixelPreclipped(x, y, getRawColor()); } } - LGFX_INLINE_T void drawPixel ( std::int32_t x, std::int32_t y , const T& color) { setColor(color); drawPixel (x, y ); } - LGFX_INLINE_T void drawFastVLine ( std::int32_t x, std::int32_t y , std::int32_t h , const T& color) { setColor(color); drawFastVLine(x, y , h ); } - void drawFastVLine ( std::int32_t x, std::int32_t y , std::int32_t h); - LGFX_INLINE_T void drawFastHLine ( std::int32_t x, std::int32_t y, std::int32_t w , const T& color) { setColor(color); drawFastHLine(x, y, w ); } - void drawFastHLine ( std::int32_t x, std::int32_t y, std::int32_t w); - LGFX_INLINE_T void fillRect ( std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h , const T& color) { setColor(color); fillRect (x, y, w, h ); } - void fillRect ( std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h); - LGFX_INLINE_T void drawRect ( std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h , const T& color) { setColor(color); drawRect (x, y, w, h ); } - void drawRect ( std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h); - LGFX_INLINE_T void drawRoundRect ( std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, std::int32_t r, const T& color) { setColor(color); drawRoundRect(x, y, w, h, r); } - void drawRoundRect ( std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, std::int32_t r); - LGFX_INLINE_T void fillRoundRect ( std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, std::int32_t r, const T& color) { setColor(color); fillRoundRect(x, y, w, h, r); } - void fillRoundRect ( std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, std::int32_t r); - LGFX_INLINE_T void drawCircle ( std::int32_t x, std::int32_t y , std::int32_t r, const T& color) { setColor(color); drawCircle (x, y , r); } - void drawCircle ( std::int32_t x, std::int32_t y , std::int32_t r); - LGFX_INLINE_T void fillCircle ( std::int32_t x, std::int32_t y , std::int32_t r, const T& color) { setColor(color); fillCircle (x, y , r); } - void fillCircle ( std::int32_t x, std::int32_t y , std::int32_t r); - LGFX_INLINE_T void drawEllipse ( std::int32_t x, std::int32_t y, std::int32_t rx, std::int32_t ry , const T& color) { setColor(color); drawEllipse (x, y, rx, ry ); } - void drawEllipse ( std::int32_t x, std::int32_t y, std::int32_t rx, std::int32_t ry); - LGFX_INLINE_T void fillEllipse ( std::int32_t x, std::int32_t y, std::int32_t rx, std::int32_t ry , const T& color) { setColor(color); fillEllipse (x, y, rx, ry ); } - void fillEllipse ( std::int32_t x, std::int32_t y, std::int32_t rx, std::int32_t ry); - LGFX_INLINE_T void drawLine ( std::int32_t x0, std::int32_t y0, std::int32_t x1, std::int32_t y1 , const T& color) { setColor(color); drawLine (x0,y0,x1, y1 ); } - void drawLine ( std::int32_t x0, std::int32_t y0, std::int32_t x1, std::int32_t y1); - LGFX_INLINE_T void drawTriangle ( std::int32_t x0, std::int32_t y0, std::int32_t x1, std::int32_t y1, std::int32_t x2, std::int32_t y2, const T& color) { setColor(color); drawTriangle(x0, y0, x1, y1, x2, y2); } - void drawTriangle ( std::int32_t x0, std::int32_t y0, std::int32_t x1, std::int32_t y1, std::int32_t x2, std::int32_t y2); - LGFX_INLINE_T void fillTriangle ( std::int32_t x0, std::int32_t y0, std::int32_t x1, std::int32_t y1, std::int32_t x2, std::int32_t y2, const T& color) { setColor(color); fillTriangle(x0, y0, x1, y1, x2, y2); } - void fillTriangle ( std::int32_t x0, std::int32_t y0, std::int32_t x1, std::int32_t y1, std::int32_t x2, std::int32_t y2); - LGFX_INLINE_T void drawBezier ( std::int32_t x0, std::int32_t y0, std::int32_t x1, std::int32_t y1, std::int32_t x2, std::int32_t y2, const T& color) { setColor(color); drawBezier(x0, y0, x1, y1, x2, y2); } - void drawBezier ( std::int32_t x0, std::int32_t y0, std::int32_t x1, std::int32_t y1, std::int32_t x2, std::int32_t y2); - LGFX_INLINE_T void drawBezier ( std::int32_t x0, std::int32_t y0, std::int32_t x1, std::int32_t y1, std::int32_t x2, std::int32_t y2, std::int32_t x3, std::int32_t y3, const T& color) { setColor(color); drawBezier(x0, y0, x1, y1, x2, y2, x3, y3); } - void drawBezier ( std::int32_t x0, std::int32_t y0, std::int32_t x1, std::int32_t y1, std::int32_t x2, std::int32_t y2, std::int32_t x3, std::int32_t y3); - LGFX_INLINE_T void drawBezierHelper( std::int32_t x0, std::int32_t y0, std::int32_t x1, std::int32_t y1, std::int32_t x2, std::int32_t y2, const T& color) { setColor(color); drawBezierHelper(x0, y0, x1, y1, x2, y2); } - void drawBezierHelper( std::int32_t x0, std::int32_t y0, std::int32_t x1, std::int32_t y1, std::int32_t x2, std::int32_t y2); - LGFX_INLINE_T void drawEllipseArc ( std::int32_t x, std::int32_t y, std::int32_t r0x, std::int32_t r1x, std::int32_t r0y, std::int32_t r1y, float angle0, float angle1, const T& color) { setColor(color); drawEllipseArc( x, y, r0x, r1x, r0y, r1y, angle0, angle1); } - void drawEllipseArc ( std::int32_t x, std::int32_t y, std::int32_t r0x, std::int32_t r1x, std::int32_t r0y, std::int32_t r1y, float angle0, float angle1); - LGFX_INLINE_T void fillEllipseArc ( std::int32_t x, std::int32_t y, std::int32_t r0x, std::int32_t r1x, std::int32_t r0y, std::int32_t r1y, float angle0, float angle1, const T& color) { setColor(color); fillEllipseArc( x, y, r0x, r1x, r0y, r1y, angle0, angle1); } - void fillEllipseArc ( std::int32_t x, std::int32_t y, std::int32_t r0x, std::int32_t r1x, std::int32_t r0y, std::int32_t r1y, float angle0, float angle1); - LGFX_INLINE_T void drawArc ( std::int32_t x, std::int32_t y, std::int32_t r0, std::int32_t r1, float angle0, float angle1, const T& color) { setColor(color); drawEllipseArc( x, y, r0, r1, r0, r1, angle0, angle1); } - void drawArc ( std::int32_t x, std::int32_t y, std::int32_t r0, std::int32_t r1, float angle0, float angle1) { drawEllipseArc( x, y, r0, r1, r0, r1, angle0, angle1); } - LGFX_INLINE_T void fillArc ( std::int32_t x, std::int32_t y, std::int32_t r0, std::int32_t r1, float angle0, float angle1, const T& color) { setColor(color); fillEllipseArc( x, y, r0, r1, r0, r1, angle0, angle1); } - void fillArc ( std::int32_t x, std::int32_t y, std::int32_t r0, std::int32_t r1, float angle0, float angle1) { fillEllipseArc( x, y, r0, r1, r0, r1, angle0, angle1); } - LGFX_INLINE_T void drawCircleHelper( std::int32_t x, std::int32_t y, std::int32_t r, std::uint_fast8_t cornername , const T& color) { setColor(color); drawCircleHelper(x, y, r, cornername ); } - void drawCircleHelper( std::int32_t x, std::int32_t y, std::int32_t r, std::uint_fast8_t cornername); - LGFX_INLINE_T void fillCircleHelper( std::int32_t x, std::int32_t y, std::int32_t r, std::uint_fast8_t corners, std::int32_t delta, const T& color) { setColor(color); fillCircleHelper(x, y, r, corners, delta); } - void fillCircleHelper( std::int32_t x, std::int32_t y, std::int32_t r, std::uint_fast8_t corners, std::int32_t delta); - LGFX_INLINE_T void floodFill( std::int32_t x, std::int32_t y, const T& color) { setColor(color); floodFill(x, y); } - void floodFill( std::int32_t x, std::int32_t y ); - LGFX_INLINE_T void paint ( std::int32_t x, std::int32_t y, const T& color) { setColor(color); floodFill(x, y); } - LGFX_INLINE void paint ( std::int32_t x, std::int32_t y ) { floodFill(x, y); } - - LGFX_INLINE_T void fillAffine(const float matrix[6], std::int32_t w, std::int32_t h, const T& color) { setColor(color); fillAffine(matrix, w, h); } - void fillAffine(const float matrix[6], std::int32_t w, std::int32_t h); - - LGFX_INLINE_T void drawGradientHLine( std::int32_t x, std::int32_t y, std::int32_t w, const T& colorstart, const T& colorend ) { drawGradientLine( x, y, x + w - 1, y, colorstart, colorend ); } - LGFX_INLINE_T void drawGradientVLine( std::int32_t x, std::int32_t y, std::int32_t h, const T& colorstart, const T& colorend ) { drawGradientLine( x, y, x, y + h - 1, colorstart, colorend ); } - LGFX_INLINE_T void drawGradientLine ( std::int32_t x0, std::int32_t y0, std::int32_t x1, std::int32_t y1, const T& colorstart, const T& colorend ) { draw_gradient_line( x0, y0, x1, y1, convert_to_rgb888(colorstart), convert_to_rgb888(colorend) ); } + LGFX_INLINE uint32_t getStartCount(void) const { return _panel->getStartCount(); } + + LGFX_INLINE void setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye) { _panel->setWindow(xs, ys, xe, ye); } + LGFX_INLINE void writePixel(int32_t x, int32_t y) { if (x >= _clip_l && x <= _clip_r && y >= _clip_t && y <= _clip_b) writeFillRectPreclipped(x, y, 1, 1); } + LGFX_INLINE_T void writePixel ( int32_t x, int32_t y , const T& color) { setColor(color); writePixel (x, y ); } + LGFX_INLINE_T void writeFastVLine ( int32_t x, int32_t y , int32_t h, const T& color) { setColor(color); writeFastVLine(x, y , h); } + void writeFastVLine ( int32_t x, int32_t y , int32_t h); + LGFX_INLINE_T void writeFastHLine ( int32_t x, int32_t y, int32_t w , const T& color) { setColor(color); writeFastHLine(x, y, w ); } + void writeFastHLine ( int32_t x, int32_t y, int32_t w); + LGFX_INLINE_T void writeFillRect ( int32_t x, int32_t y, int32_t w, int32_t h, const T& color) { setColor(color); writeFillRect (x, y, w, h); } + void writeFillRect ( int32_t x, int32_t y, int32_t w, int32_t h); + LGFX_INLINE_T void writeFillRectPreclipped( int32_t x, int32_t y, int32_t w, int32_t h, const T& color) { setColor(color); writeFillRectPreclipped(x, y, w, h); } + LGFX_INLINE void writeFillRectPreclipped( int32_t x, int32_t y, int32_t w, int32_t h) { _panel->writeFillRectPreclipped(x, y, w, h, getRawColor()); } + LGFX_INLINE_T void writeColor ( const T& color, uint32_t length) { if (0 == length) return; setColor(color); _panel->writeBlock(getRawColor(), length); } + LGFX_INLINE_T void pushBlock ( const T& color, uint32_t length) { if (0 == length) return; setColor(color); startWrite(); _panel->writeBlock(getRawColor(), length); endWrite(); } + LGFX_INLINE void drawPixel ( int32_t x, int32_t y) { if (x >= _clip_l && x <= _clip_r && y >= _clip_t && y <= _clip_b) { _panel->drawPixelPreclipped(x, y, getRawColor()); } } + LGFX_INLINE_T void drawPixel ( int32_t x, int32_t y , const T& color) { setColor(color); drawPixel (x, y ); } + LGFX_INLINE_T void drawFastVLine ( int32_t x, int32_t y , int32_t h , const T& color) { setColor(color); drawFastVLine(x, y , h ); } + void drawFastVLine ( int32_t x, int32_t y , int32_t h); + LGFX_INLINE_T void drawFastHLine ( int32_t x, int32_t y, int32_t w , const T& color) { setColor(color); drawFastHLine(x, y, w ); } + void drawFastHLine ( int32_t x, int32_t y, int32_t w); + LGFX_INLINE_T void fillRect ( int32_t x, int32_t y, int32_t w, int32_t h , const T& color) { setColor(color); fillRect (x, y, w, h ); } + void fillRect ( int32_t x, int32_t y, int32_t w, int32_t h); + LGFX_INLINE_T void drawRect ( int32_t x, int32_t y, int32_t w, int32_t h , const T& color) { setColor(color); drawRect (x, y, w, h ); } + void drawRect ( int32_t x, int32_t y, int32_t w, int32_t h); + LGFX_INLINE_T void drawRoundRect ( int32_t x, int32_t y, int32_t w, int32_t h, int32_t r, const T& color) { setColor(color); drawRoundRect(x, y, w, h, r); } + void drawRoundRect ( int32_t x, int32_t y, int32_t w, int32_t h, int32_t r); + LGFX_INLINE_T void fillRoundRect ( int32_t x, int32_t y, int32_t w, int32_t h, int32_t r, const T& color) { setColor(color); fillRoundRect(x, y, w, h, r); } + void fillRoundRect ( int32_t x, int32_t y, int32_t w, int32_t h, int32_t r); + LGFX_INLINE_T void drawCircle ( int32_t x, int32_t y , int32_t r, const T& color) { setColor(color); drawCircle (x, y , r); } + void drawCircle ( int32_t x, int32_t y , int32_t r); + LGFX_INLINE_T void fillCircle ( int32_t x, int32_t y , int32_t r, const T& color) { setColor(color); fillCircle (x, y , r); } + void fillCircle ( int32_t x, int32_t y , int32_t r); + LGFX_INLINE_T void drawEllipse ( int32_t x, int32_t y, int32_t rx, int32_t ry , const T& color) { setColor(color); drawEllipse (x, y, rx, ry ); } + void drawEllipse ( int32_t x, int32_t y, int32_t rx, int32_t ry); + LGFX_INLINE_T void fillEllipse ( int32_t x, int32_t y, int32_t rx, int32_t ry , const T& color) { setColor(color); fillEllipse (x, y, rx, ry ); } + void fillEllipse ( int32_t x, int32_t y, int32_t rx, int32_t ry); + LGFX_INLINE_T void drawLine ( int32_t x0, int32_t y0, int32_t x1, int32_t y1 , const T& color) { setColor(color); drawLine (x0,y0,x1, y1 ); } + void drawLine ( int32_t x0, int32_t y0, int32_t x1, int32_t y1); + LGFX_INLINE_T void drawTriangle ( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, const T& color) { setColor(color); drawTriangle(x0, y0, x1, y1, x2, y2); } + void drawTriangle ( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2); + LGFX_INLINE_T void fillTriangle ( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, const T& color) { setColor(color); fillTriangle(x0, y0, x1, y1, x2, y2); } + void fillTriangle ( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2); + LGFX_INLINE_T void drawBezier ( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, const T& color) { setColor(color); drawBezier(x0, y0, x1, y1, x2, y2); } + void drawBezier ( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2); + LGFX_INLINE_T void drawBezier ( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, const T& color) { setColor(color); drawBezier(x0, y0, x1, y1, x2, y2, x3, y3); } + void drawBezier ( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3); + LGFX_INLINE_T void drawBezierHelper( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, const T& color) { setColor(color); drawBezierHelper(x0, y0, x1, y1, x2, y2); } + void drawBezierHelper( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2); + LGFX_INLINE_T void drawEllipseArc ( int32_t x, int32_t y, int32_t r0x, int32_t r1x, int32_t r0y, int32_t r1y, float angle0, float angle1, const T& color) { setColor(color); drawEllipseArc( x, y, r0x, r1x, r0y, r1y, angle0, angle1); } + void drawEllipseArc ( int32_t x, int32_t y, int32_t r0x, int32_t r1x, int32_t r0y, int32_t r1y, float angle0, float angle1); + LGFX_INLINE_T void fillEllipseArc ( int32_t x, int32_t y, int32_t r0x, int32_t r1x, int32_t r0y, int32_t r1y, float angle0, float angle1, const T& color) { setColor(color); fillEllipseArc( x, y, r0x, r1x, r0y, r1y, angle0, angle1); } + void fillEllipseArc ( int32_t x, int32_t y, int32_t r0x, int32_t r1x, int32_t r0y, int32_t r1y, float angle0, float angle1); + LGFX_INLINE_T void drawArc ( int32_t x, int32_t y, int32_t r0, int32_t r1, float angle0, float angle1, const T& color) { setColor(color); drawEllipseArc( x, y, r0, r1, r0, r1, angle0, angle1); } + void drawArc ( int32_t x, int32_t y, int32_t r0, int32_t r1, float angle0, float angle1) { drawEllipseArc( x, y, r0, r1, r0, r1, angle0, angle1); } + LGFX_INLINE_T void fillArc ( int32_t x, int32_t y, int32_t r0, int32_t r1, float angle0, float angle1, const T& color) { setColor(color); fillEllipseArc( x, y, r0, r1, r0, r1, angle0, angle1); } + void fillArc ( int32_t x, int32_t y, int32_t r0, int32_t r1, float angle0, float angle1) { fillEllipseArc( x, y, r0, r1, r0, r1, angle0, angle1); } + LGFX_INLINE_T void drawCircleHelper( int32_t x, int32_t y, int32_t r, uint_fast8_t cornername , const T& color) { setColor(color); drawCircleHelper(x, y, r, cornername ); } + void drawCircleHelper( int32_t x, int32_t y, int32_t r, uint_fast8_t cornername); + LGFX_INLINE_T void fillCircleHelper( int32_t x, int32_t y, int32_t r, uint_fast8_t corners, int32_t delta, const T& color) { setColor(color); fillCircleHelper(x, y, r, corners, delta); } + void fillCircleHelper( int32_t x, int32_t y, int32_t r, uint_fast8_t corners, int32_t delta); + LGFX_INLINE_T void floodFill( int32_t x, int32_t y, const T& color) { setColor(color); floodFill(x, y); } + void floodFill( int32_t x, int32_t y ); + LGFX_INLINE_T void paint ( int32_t x, int32_t y, const T& color) { setColor(color); floodFill(x, y); } + LGFX_INLINE void paint ( int32_t x, int32_t y ) { floodFill(x, y); } + + LGFX_INLINE_T void fillAffine(const float matrix[6], int32_t w, int32_t h, const T& color) { setColor(color); fillAffine(matrix, w, h); } + void fillAffine(const float matrix[6], int32_t w, int32_t h); + + LGFX_INLINE_T void drawGradientHLine( int32_t x, int32_t y, int32_t w, const T& colorstart, const T& colorend ) { drawGradientLine( x, y, x + w - 1, y, colorstart, colorend ); } + LGFX_INLINE_T void drawGradientVLine( int32_t x, int32_t y, int32_t h, const T& colorstart, const T& colorend ) { drawGradientLine( x, y, x, y + h - 1, colorstart, colorend ); } + LGFX_INLINE_T void drawGradientLine ( int32_t x0, int32_t y0, int32_t x1, int32_t y1, const T& colorstart, const T& colorend ) { draw_gradient_line( x0, y0, x1, y1, convert_to_rgb888(colorstart), convert_to_rgb888(colorend) ); } LGFX_INLINE_T void fillScreen ( const T& color) { setColor(color); fillRect(0, 0, width(), height()); } LGFX_INLINE void fillScreen ( void ) { fillRect(0, 0, width(), height()); } @@ -159,10 +159,10 @@ namespace lgfx LGFX_INLINE float getPivotX(void) const { return _xpivot; } LGFX_INLINE float getPivotY(void) const { return _ypivot; } - LGFX_INLINE std::int32_t width (void) const { return _panel->width(); } - LGFX_INLINE std::int32_t height(void) const { return _panel->height(); } + LGFX_INLINE int32_t width (void) const { return _panel->width(); } + LGFX_INLINE int32_t height(void) const { return _panel->height(); } LGFX_INLINE bool hasPalette (void) const { return _palette_count; } - LGFX_INLINE std::uint32_t getPaletteCount(void) const { return _palette_count; } + LGFX_INLINE uint32_t getPaletteCount(void) const { return _palette_count; } LGFX_INLINE RGBColor* getPalette(void) const { return getPalette_impl(); } LGFX_INLINE bool isReadable(void) const { return _panel->isReadable(); } LGFX_INLINE bool isEPD(void) const { return _panel->isEpd(); } @@ -171,7 +171,7 @@ namespace lgfx LGFX_INLINE bool isBusShared(void) const { return _panel->isBusShared(); } [[deprecated("use isBusShared()")]] LGFX_INLINE bool isSPIShared(void) const { return _panel->isBusShared(); } - void display(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h); + void display(int32_t x, int32_t y, int32_t w, int32_t h); LGFX_INLINE void display(void) { _panel->display(0, 0, 0, 0); } LGFX_INLINE void waitDisplay(void) { _panel->waitDisplay(); } LGFX_INLINE bool displayBusy(void) { return _panel->displayBusy(); } @@ -180,139 +180,139 @@ namespace lgfx LGFX_INLINE void waitDMA(void) { _panel->waitDMA(); } LGFX_INLINE bool dmaBusy(void) { return _panel->dmaBusy(); } - LGFX_INLINE_T void setScrollRect(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, const T& color) { setBaseColor(color); setScrollRect(x, y, w, h); } + LGFX_INLINE_T void setScrollRect(int32_t x, int32_t y, int32_t w, int32_t h, const T& color) { setBaseColor(color); setScrollRect(x, y, w, h); } - LGFX_INLINE_T void writePixels(const T *data, std::int32_t len) { auto pc = create_pc_fast(data ); _panel->writePixels(&pc, len, false); } - LGFX_INLINE void writePixels(const std::uint16_t* data, std::int32_t len, bool swap) { auto pc = create_pc_fast(data, swap); _panel->writePixels(&pc, len, false); } - LGFX_INLINE void writePixels(const void* data, std::int32_t len, bool swap) { auto pc = create_pc_fast(data, swap); _panel->writePixels(&pc, len, false); } + LGFX_INLINE_T void writePixels(const T* data, int32_t len ) { auto pc = create_pc_fast(data ); _panel->writePixels(&pc, len, false); } + LGFX_INLINE void writePixels(const uint16_t* data, int32_t len, bool swap) { auto pc = create_pc_fast(data, swap); _panel->writePixels(&pc, len, false); } + LGFX_INLINE void writePixels(const void* data, int32_t len, bool swap) { auto pc = create_pc_fast(data, swap); _panel->writePixels(&pc, len, false); } - LGFX_INLINE_T void writePixelsDMA(const T *data, std::int32_t len) { auto pc = create_pc_fast(data ); _panel->writePixels(&pc, len, true); } - LGFX_INLINE void writePixelsDMA(const std::uint16_t* data, std::int32_t len, bool swap) { auto pc = create_pc_fast(data, swap); _panel->writePixels(&pc, len, true); } - LGFX_INLINE void writePixelsDMA(const void* data, std::int32_t len, bool swap) { auto pc = create_pc_fast(data, swap); _panel->writePixels(&pc, len, true); } + LGFX_INLINE_T void writePixelsDMA(const T* data, int32_t len ) { auto pc = create_pc_fast(data ); _panel->writePixels(&pc, len, true); } + LGFX_INLINE void writePixelsDMA(const uint16_t* data, int32_t len, bool swap) { auto pc = create_pc_fast(data, swap); _panel->writePixels(&pc, len, true); } + LGFX_INLINE void writePixelsDMA(const void* data, int32_t len, bool swap) { auto pc = create_pc_fast(data, swap); _panel->writePixels(&pc, len, true); } - LGFX_INLINE_T void pushPixels(T* data, std::int32_t len ) { startWrite(); writePixels(data, len ); endWrite(); } - LGFX_INLINE void pushPixels(const std::uint16_t* data, std::int32_t len, bool swap) { startWrite(); writePixels(data, len, swap); endWrite(); } - LGFX_INLINE void pushPixels(const void* data, std::int32_t len, bool swap) { startWrite(); writePixels(data, len, swap); endWrite(); } + LGFX_INLINE_T void pushPixels(T* data, int32_t len ) { startWrite(); writePixels(data, len ); endWrite(); } + LGFX_INLINE void pushPixels(const uint16_t* data, int32_t len, bool swap) { startWrite(); writePixels(data, len, swap); endWrite(); } + LGFX_INLINE void pushPixels(const void* data, int32_t len, bool swap) { startWrite(); writePixels(data, len, swap); endWrite(); } - LGFX_INLINE_T void pushPixelsDMA(T* data, std::int32_t len ) { startWrite(); writePixelsDMA(data, len ); endWrite(); } - LGFX_INLINE void pushPixelsDMA(const std::uint16_t* data, std::int32_t len, bool swap) { startWrite(); writePixelsDMA(data, len, swap); endWrite(); } - LGFX_INLINE void pushPixelsDMA(const void* data, std::int32_t len, bool swap) { startWrite(); writePixelsDMA(data, len, swap); endWrite(); } + LGFX_INLINE_T void pushPixelsDMA(T* data, int32_t len ) { startWrite(); writePixelsDMA(data, len ); endWrite(); } + LGFX_INLINE void pushPixelsDMA(const uint16_t* data, int32_t len, bool swap) { startWrite(); writePixelsDMA(data, len, swap); endWrite(); } + LGFX_INLINE void pushPixelsDMA(const void* data, int32_t len, bool swap) { startWrite(); writePixelsDMA(data, len, swap); endWrite(); } template - void effect(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, TFunc&& effector) + void effect(int32_t x, int32_t y, int32_t w, int32_t h, TFunc&& effector) { if (!_clipping(x, y, w, h)) return; _panel->effect(x, y, w, h, effector); } template - void fillRectAlpha(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, std::uint8_t alpha, const T& color) + void fillRectAlpha(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t alpha, const T& color) { if (!_clipping(x, y, w, h)) return; _panel->writeFillRectAlphaPreclipped(x, y, w, h, convert_to_rgb888(color) | alpha << 24 ); } - LGFX_INLINE_T void drawBitmap (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_bitmap (x, y, bitmap, w, h, _write_conv.convert(color)); } - LGFX_INLINE_T void drawBitmap (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_bitmap (x, y, bitmap, w, h, _write_conv.convert(fgcolor), _write_conv.convert(bgcolor)); } - LGFX_INLINE_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)); } - LGFX_INLINE_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)); } + LGFX_INLINE_T void drawBitmap (int32_t x, int32_t y, const uint8_t* bitmap, int32_t w, int32_t h, const T& color ) { draw_bitmap (x, y, bitmap, w, h, _write_conv.convert(color)); } + LGFX_INLINE_T void drawBitmap (int32_t x, int32_t y, const uint8_t* bitmap, int32_t w, int32_t h, const T& fgcolor, const T& bgcolor) { draw_bitmap (x, y, bitmap, w, h, _write_conv.convert(fgcolor), _write_conv.convert(bgcolor)); } + LGFX_INLINE_T void drawXBitmap(int32_t x, int32_t y, const uint8_t* bitmap, int32_t w, int32_t h, const T& color ) { draw_xbitmap(x, y, bitmap, w, h, _write_conv.convert(color)); } + LGFX_INLINE_T void drawXBitmap(int32_t x, int32_t y, const uint8_t* bitmap, int32_t w, int32_t h, const T& fgcolor, const T& bgcolor) { draw_xbitmap(x, y, bitmap, w, h, _write_conv.convert(fgcolor), _write_conv.convert(bgcolor)); } LGFX_INLINE_T - void writeIndexedPixels(const std::uint8_t *data, T* palette, std::int32_t len, std::uint8_t depth = 8) + void writeIndexedPixels(const uint8_t* data, T* palette, int32_t len, uint8_t depth = 8) { auto src_depth = (color_depth_t)(depth | color_depth_t::has_palette); auto pc = create_pc_fast(data, palette, src_depth); - _panel->writePixels(&pc, len); + _panel->writePixels(&pc, len, false); } #undef LGFX_INLINE #undef LGFX_INLINE_T - std::uint8_t getRotation(void) const { return _panel->getRotation(); } - void setRotation(std::uint_fast8_t rotation); + uint8_t getRotation(void) const { return _panel->getRotation(); } + void setRotation(uint_fast8_t rotation); void setColorDepth(int bits) { setColorDepth((color_depth_t)(bits & color_depth_t::bit_mask));} void setColorDepth(color_depth_t depth); - void setAddrWindow(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h); + void setAddrWindow(int32_t x, int32_t y, int32_t w, int32_t h); - void setClipRect(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h); - void getClipRect(std::int32_t *x, std::int32_t *y, std::int32_t *w, std::int32_t *h); + void setClipRect(int32_t x, int32_t y, int32_t w, int32_t h); + void getClipRect(int32_t *x, int32_t *y, int32_t *w, int32_t *h); void clearClipRect(void); - void setScrollRect(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h); - void getScrollRect(std::int32_t *x, std::int32_t *y, std::int32_t *w, std::int32_t *h); + void setScrollRect(int32_t x, int32_t y, int32_t w, int32_t h); + void getScrollRect(int32_t *x, int32_t *y, int32_t *w, int32_t *h); void clearScrollRect(void); template - void pushImage(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, const T* data) + void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const T* data) { auto pc = create_pc(data); pushImage(x, y, w, h, &pc); } template - void pushImage(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, const T1* data, const T2& transparent) + void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const T1* data, const T2& transparent) { auto pc = create_pc_tr(data, transparent); pushImage(x, y, w, h, &pc); } template - void pushImage(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, const void* data, color_depth_t depth, const T* palette) + void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette) { auto pc = create_pc_palette(data, palette, depth); pushImage(x, y, w, h, &pc); } template - void pushImage(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, const void* data, std::uint32_t transparent, color_depth_t depth, const T* palette) + void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const void* data, uint32_t transparent, color_depth_t depth, const T* palette) { auto pc = create_pc_palette(data, palette, depth, transparent); pushImage(x, y, w, h, &pc); } template - void pushImageDMA(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, const T* data) + void pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h, const T* data) { auto pc = create_pc(data); pushImage(x, y, w, h, &pc, true); } template - void pushImageDMA(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, const void* data, color_depth_t depth, const T* palette) + void pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette) { auto pc = create_pc_palette(data, palette, depth); pushImage(x, y, w, h, &pc, true); } - void pushImage(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, pixelcopy_t *param, bool use_dma = false); + void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, pixelcopy_t *param, bool use_dma = false); //---------------------------------------------------------------------------- template - void pushImageRotateZoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, std::int32_t w, std::int32_t h, const T* data) + void pushImageRotateZoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const T* data) { auto pc = create_pc(data); push_image_rotate_zoom(dst_x, dst_y, src_x, src_y, angle, zoom_x, zoom_y, w, h, &pc); } template - void pushImageRotateZoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, std::int32_t w, std::int32_t h, const T1* data, const T2& transparent) + void pushImageRotateZoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const T1* data, const T2& transparent) { auto pc = create_pc_tr(data, transparent); push_image_rotate_zoom(dst_x, dst_y, src_x, src_y, angle, zoom_x, zoom_y, w, h, &pc); } template - void pushImageRotateZoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, std::int32_t w, std::int32_t h, const void* data, color_depth_t depth, const T* palette) + void pushImageRotateZoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette) { auto pc = create_pc_palette(data, palette, depth); push_image_rotate_zoom(dst_x, dst_y, src_x, src_y, angle, zoom_x, zoom_y, w, h, &pc); } template - void pushImageRotateZoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, std::int32_t w, std::int32_t h, const void* data, std::uint32_t transparent, color_depth_t depth, const T* palette) + void pushImageRotateZoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const void* data, uint32_t transparent, color_depth_t depth, const T* palette) { auto pc = create_pc_palette(data, palette, depth, transparent); push_image_rotate_zoom(dst_x, dst_y, src_x, src_y, angle, zoom_x, zoom_y, w, h, &pc); @@ -320,28 +320,28 @@ namespace lgfx template - void pushImageRotateZoomWithAA(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, std::int32_t w, std::int32_t h, const T* data) + void pushImageRotateZoomWithAA(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const T* data) { auto pc = create_pc_antialias(data); push_image_rotate_zoom_aa(dst_x, dst_y, src_x, src_y, angle, zoom_x, zoom_y, w, h, &pc); } template - void pushImageRotateZoomWithAA(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, std::int32_t w, std::int32_t h, const T1* data, const T2& transparent) + void pushImageRotateZoomWithAA(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const T1* data, const T2& transparent) { auto pc = create_pc_tr_antialias(data, transparent); push_image_rotate_zoom_aa(dst_x, dst_y, src_x, src_y, angle, zoom_x, zoom_y, w, h, &pc); } template - void pushImageRotateZoomWithAA(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, std::int32_t w, std::int32_t h, const void* data, color_depth_t depth, const T* palette) + void pushImageRotateZoomWithAA(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette) { auto pc = create_pc_antialias(data, palette, depth); push_image_rotate_zoom_aa(dst_x, dst_y, src_x, src_y, angle, zoom_x, zoom_y, w, h, &pc); } template - void pushImageRotateZoomWithAA(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, std::int32_t w, std::int32_t h, const void* data, std::uint32_t transparent, color_depth_t depth, const T* palette) + void pushImageRotateZoomWithAA(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const void* data, uint32_t transparent, color_depth_t depth, const T* palette) { auto pc = create_pc_antialias(data, palette, depth, transparent); push_image_rotate_zoom_aa(dst_x, dst_y, src_x, src_y, angle, zoom_x, zoom_y, w, h, &pc); @@ -350,28 +350,28 @@ namespace lgfx //---------------------------------------------------------------------------- template - void pushImageAffine(const float matrix[6], std::int32_t w, std::int32_t h, const T* data) + void pushImageAffine(const float matrix[6], int32_t w, int32_t h, const T* data) { auto pc = create_pc(data); push_image_affine(matrix, w, h, &pc); } template - void pushImageAffine(const float matrix[6], std::int32_t w, std::int32_t h, const T1* data, const T2& transparent) + void pushImageAffine(const float matrix[6], int32_t w, int32_t h, const T1* data, const T2& transparent) { auto pc = create_pc_tr(data, transparent); push_image_affine(matrix, w, h, &pc); } template - void pushImageAffine(const float matrix[6], std::int32_t w, std::int32_t h, const void* data, color_depth_t depth, const T* palette) + void pushImageAffine(const float matrix[6], int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette) { auto pc = create_pc_palette(data, palette, depth); push_image_affine(matrix, w, h, &pc); } template - void pushImageAffine(const float matrix[6], std::int32_t w, std::int32_t h, const void* data, std::uint32_t transparent, color_depth_t depth, const T* palette) + void pushImageAffine(const float matrix[6], int32_t w, int32_t h, const void* data, uint32_t transparent, color_depth_t depth, const T* palette) { auto pc = create_pc_palette(data, palette, depth, transparent); push_image_affine(matrix, w, h, &pc); @@ -379,28 +379,28 @@ namespace lgfx template - void pushImageAffineWithAA(const float matrix[6], std::int32_t w, std::int32_t h, const T* data) + void pushImageAffineWithAA(const float matrix[6], int32_t w, int32_t h, const T* data) { auto pc = create_pc_antialias(data); push_image_affine_aa(matrix, w, h, &pc); } template - void pushImageAffineWithAA(const float matrix[6], std::int32_t w, std::int32_t h, const T1* data, const T2& transparent) + void pushImageAffineWithAA(const float matrix[6], int32_t w, int32_t h, const T1* data, const T2& transparent) { auto pc = create_pc_tr_antialias(data, transparent); push_image_affine_aa(matrix, w, h, &pc); } template - void pushImageAffineWithAA(const float matrix[6], std::int32_t w, std::int32_t h, const void* data, color_depth_t depth, const T* palette) + void pushImageAffineWithAA(const float matrix[6], int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette) { auto pc = create_pc_antialias(data, palette, depth); push_image_affine_aa(matrix, w, h, &pc); } template - void pushImageAffineWithAA(const float matrix[6], std::int32_t w, std::int32_t h, const void* data, std::uint32_t transparent, color_depth_t depth, const T* palette) + void pushImageAffineWithAA(const float matrix[6], int32_t w, int32_t h, const void* data, uint32_t transparent, color_depth_t depth, const T* palette) { auto pc = create_pc_antialias(data, palette, depth, transparent); push_image_affine_aa(matrix, w, h, &pc); @@ -409,12 +409,12 @@ namespace lgfx //---------------------------------------------------------------------------- /// read RGB565 16bit color - std::uint16_t readPixel(std::int32_t x, std::int32_t y) + uint16_t readPixel(int32_t x, int32_t y) { if (x < 0 || x >= width() || y < 0 || y >= height()) return 0; pixelcopy_t p(nullptr, swap565_t::depth, _read_conv.depth, false, getPalette()); - std::uint16_t data = 0; + uint16_t data = 0; _panel->readRect(x, y, 1, 1, &data, &p); @@ -422,7 +422,7 @@ namespace lgfx } /// read RGB888 24bit color - RGBColor readPixelRGB(std::int32_t x, std::int32_t y) + RGBColor readPixelRGB(int32_t x, int32_t y) { RGBColor data[1]; if (x < 0 || x >= width() || y < 0 || y >= height()) return data[0]; @@ -435,15 +435,15 @@ namespace lgfx } __attribute__ ((always_inline)) inline - void readRectRGB( std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, std::uint8_t* data) { readRectRGB(x, y, w, h, (bgr888_t*)data); } - void readRectRGB( std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, RGBColor* data) + void readRectRGB( int32_t x, int32_t y, int32_t w, int32_t h, uint8_t* data) { readRectRGB(x, y, w, h, (bgr888_t*)data); } + void readRectRGB( int32_t x, int32_t y, int32_t w, int32_t h, RGBColor* data) { pixelcopy_t p(nullptr, bgr888_t::depth, _read_conv.depth, false, getPalette()); read_rect(x, y, w, h, data, &p); } template inline - void readRect( std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, T* data) + void readRect( int32_t x, int32_t y, int32_t w, int32_t h, T* data) { pixelcopy_t p(nullptr, get_depth::value, _read_conv.depth, false, getPalette()); if (std::is_same::value || std::is_same::value || std::is_same::value || std::is_same::value || p.fp_copy == nullptr) @@ -454,20 +454,20 @@ namespace lgfx read_rect(x, y, w, h, data, &p); } - void readRect(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, std::uint8_t* data); - void readRect(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, std::uint16_t* data); - void readRect(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, void* data); + void readRect(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t* data); + void readRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t* data); + void readRect(int32_t x, int32_t y, int32_t w, int32_t h, void* data); - void scroll(std::int_fast16_t dx, std::int_fast16_t dy = 0); - void copyRect(std::int32_t dst_x, std::int32_t dst_y, std::int32_t w, std::int32_t h, std::int32_t src_x, std::int32_t src_y); + void scroll(int_fast16_t dx, int_fast16_t dy = 0); + void copyRect(int32_t dst_x, int32_t dst_y, int32_t w, int32_t h, int32_t src_x, int32_t src_y); [[deprecated("use IFont")]] - void setCursor( std::int32_t x, std::int32_t y, std::uint8_t font) { _filled_x = 0; _cursor_x = x; _cursor_y = y; setFont(fontdata[font]); } - void setCursor( std::int32_t x, std::int32_t y, const IFont* font) { _filled_x = 0; _cursor_x = x; _cursor_y = y; setFont(font); } - void setCursor( std::int32_t x, std::int32_t y) { _filled_x = 0; _cursor_x = x; _cursor_y = y; } - std::int32_t getCursorX(void) const { return _cursor_x; } - std::int32_t getCursorY(void) const { return _cursor_y; } + void setCursor( int32_t x, int32_t y, uint8_t font) { _filled_x = 0; _cursor_x = x; _cursor_y = y; setFont(fontdata[font]); } + void setCursor( int32_t x, int32_t y, const IFont* font) { _filled_x = 0; _cursor_x = x; _cursor_y = y; setFont(font); } + void setCursor( int32_t x, int32_t y) { _filled_x = 0; _cursor_x = x; _cursor_y = y; } + int32_t getCursorX(void) const { return _cursor_x; } + int32_t getCursorY(void) const { return _cursor_y; } void setTextStyle(const TextStyle& text_style) { _text_style = text_style; } const TextStyle& getTextStyle(void) const { return _text_style; } void setTextSize(float size) { setTextSize(size, size); } @@ -475,11 +475,11 @@ namespace lgfx float getTextSizeX(void) const { return _text_style.size_x; } float getTextSizeY(void) const { return _text_style.size_y; } //[[deprecated("use textdatum_t")]] - void setTextDatum(std::uint8_t datum) { _text_style.datum = (textdatum_t)datum; } + void setTextDatum(uint8_t datum) { _text_style.datum = (textdatum_t)datum; } void setTextDatum(textdatum_t datum) { _text_style.datum = datum; } textdatum_t getTextDatum(void) const { return _text_style.datum; } - void setTextPadding(std::uint32_t padding_x) { _padding_x = padding_x; } - std::uint32_t getTextPadding(void) const { return _padding_x; } + void setTextPadding(uint32_t padding_x) { _text_style.padding_x = padding_x; } + uint32_t getTextPadding(void) const { return _text_style.padding_x; } void setTextWrap( bool wrapX, bool wrapY = false) { _textwrap_x = wrapX; _textwrap_y = wrapY; } void setTextScroll(bool scroll) { _textscroll = scroll; if (_cursor_x < this->_sx) { _cursor_x = this->_sx; } if (_cursor_y < this->_sy) { _cursor_y = this->_sy; } } @@ -499,81 +499,81 @@ namespace lgfx } [[deprecated("use IFont")]] - std::int32_t fontHeight(std::uint8_t font) const { return ((const BaseFont*)fontdata[font])->height * _text_style.size_y; } - std::int32_t fontHeight(const IFont* font) const; - std::int32_t fontHeight(void) const { return _font_metrics.height * _text_style.size_y; } - std::int32_t textLength(const char *string, std::int32_t width); - std::int32_t textWidth(const char *string) { return textWidth(string, _font); }; - std::int32_t textWidth(const char *string, const IFont* font); + int32_t fontHeight(uint8_t font) const { return ((const BaseFont*)fontdata[font])->height * _text_style.size_y; } + int32_t fontHeight(const IFont* font) const; + int32_t fontHeight(void) const { return _font_metrics.height * _text_style.size_y; } + int32_t textLength(const char *string, int32_t width); + int32_t textWidth(const char *string) { return textWidth(string, _font); }; + int32_t textWidth(const char *string, const IFont* font); [[deprecated("use IFont")]] - inline std::size_t drawString(const char *string, std::int32_t x, std::int32_t y, std::uint8_t font) { return draw_string(string, x, y, _text_style.datum, fontdata[font]); } - inline std::size_t drawString(const char *string, std::int32_t x, std::int32_t y ) { return draw_string(string, x, y, _text_style.datum); } - inline std::size_t drawString(const char *string, std::int32_t x, std::int32_t y, const IFont* font) { return draw_string(string, x, y, _text_style.datum, font); } + inline size_t drawString(const char *string, int32_t x, int32_t y, uint8_t font) { return draw_string(string, x, y, _text_style.datum, fontdata[font]); } + inline size_t drawString(const char *string, int32_t x, int32_t y ) { return draw_string(string, x, y, _text_style.datum); } + inline size_t drawString(const char *string, int32_t x, int32_t y, const IFont* font) { return draw_string(string, x, y, _text_style.datum, font); } [[deprecated("use IFont")]] - inline std::size_t drawNumber(long long_num, std::int32_t poX, std::int32_t poY, std::uint8_t font) { return drawNumber(long_num, poX, poY, fontdata[font]); } - inline std::size_t drawNumber(long long_num, std::int32_t poX, std::int32_t poY ) { return drawNumber(long_num, poX, poY, _font ); } - std::size_t drawNumber(long long_num, std::int32_t poX, std::int32_t poY, const IFont* font); + inline size_t drawNumber(long long_num, int32_t poX, int32_t poY, uint8_t font) { return drawNumber(long_num, poX, poY, fontdata[font]); } + inline size_t drawNumber(long long_num, int32_t poX, int32_t poY ) { return drawNumber(long_num, poX, poY, _font ); } + size_t drawNumber(long long_num, int32_t poX, int32_t poY, const IFont* font); [[deprecated("use IFont")]] - inline std::size_t drawFloat(float floatNumber, std::uint8_t dp, std::int32_t poX, std::int32_t poY, std::uint8_t font) { return drawFloat(floatNumber, dp, poX, poY, fontdata[font]); } - inline std::size_t drawFloat(float floatNumber, std::uint8_t dp, std::int32_t poX, std::int32_t poY ) { return drawFloat(floatNumber, dp, poX, poY, _font ); } - std::size_t drawFloat(float floatNumber, std::uint8_t dp, std::int32_t poX, std::int32_t poY, const IFont* font); - - [[deprecated("use IFont")]] inline std::size_t drawCentreString(const char *string, std::int32_t x, std::int32_t y, std::uint8_t font) { return draw_string(string, x, y, textdatum_t::top_center, fontdata[font]); } - [[deprecated("use IFont")]] inline std::size_t drawCenterString(const char *string, std::int32_t x, std::int32_t y, std::uint8_t font) { return draw_string(string, x, y, textdatum_t::top_center, fontdata[font]); } - [[deprecated("use IFont")]] inline std::size_t drawRightString( const char *string, std::int32_t x, std::int32_t y, std::uint8_t font) { return draw_string(string, x, y, textdatum_t::top_right , fontdata[font]); } - inline std::size_t drawCentreString(const char *string, std::int32_t x, std::int32_t y, const IFont* font) { return draw_string(string, x, y, textdatum_t::top_center, font); } - inline std::size_t drawCenterString(const char *string, std::int32_t x, std::int32_t y, const IFont* font) { return draw_string(string, x, y, textdatum_t::top_center, font); } - inline std::size_t drawRightString( const char *string, std::int32_t x, std::int32_t y, const IFont* font) { return draw_string(string, x, y, textdatum_t::top_right , font); } - inline std::size_t drawCentreString(const char *string, std::int32_t x, std::int32_t y ) { return draw_string(string, x, y, textdatum_t::top_center); } - inline std::size_t drawCenterString(const char *string, std::int32_t x, std::int32_t y ) { return draw_string(string, x, y, textdatum_t::top_center); } - inline std::size_t drawRightString( const char *string, std::int32_t x, std::int32_t y ) { return draw_string(string, x, y, textdatum_t::top_right ); } + inline size_t drawFloat(float floatNumber, uint8_t dp, int32_t poX, int32_t poY, uint8_t font) { return drawFloat(floatNumber, dp, poX, poY, fontdata[font]); } + inline size_t drawFloat(float floatNumber, uint8_t dp, int32_t poX, int32_t poY ) { return drawFloat(floatNumber, dp, poX, poY, _font ); } + size_t drawFloat(float floatNumber, uint8_t dp, int32_t poX, int32_t poY, const IFont* font); + + [[deprecated("use IFont")]] inline size_t drawCentreString(const char *string, int32_t x, int32_t y, uint8_t font) { return draw_string(string, x, y, textdatum_t::top_center, fontdata[font]); } + [[deprecated("use IFont")]] inline size_t drawCenterString(const char *string, int32_t x, int32_t y, uint8_t font) { return draw_string(string, x, y, textdatum_t::top_center, fontdata[font]); } + [[deprecated("use IFont")]] inline size_t drawRightString( const char *string, int32_t x, int32_t y, uint8_t font) { return draw_string(string, x, y, textdatum_t::top_right , fontdata[font]); } + inline size_t drawCentreString(const char *string, int32_t x, int32_t y, const IFont* font) { return draw_string(string, x, y, textdatum_t::top_center, font); } + inline size_t drawCenterString(const char *string, int32_t x, int32_t y, const IFont* font) { return draw_string(string, x, y, textdatum_t::top_center, font); } + inline size_t drawRightString( const char *string, int32_t x, int32_t y, const IFont* font) { return draw_string(string, x, y, textdatum_t::top_right , font); } + inline size_t drawCentreString(const char *string, int32_t x, int32_t y ) { return draw_string(string, x, y, textdatum_t::top_center); } + inline size_t drawCenterString(const char *string, int32_t x, int32_t y ) { return draw_string(string, x, y, textdatum_t::top_center); } + inline size_t drawRightString( const char *string, int32_t x, int32_t y ) { return draw_string(string, x, y, textdatum_t::top_right ); } #if defined (ARDUINO) - inline std::int32_t textLength(const String& string, std::int32_t width) { return textLength(string.c_str(), width); } - inline std::int32_t textWidth(const String& string) { return textWidth(string.c_str()); } - inline std::int32_t textWidth(const String& string, const IFont* font) { return textWidth(string.c_str(), font); } + inline int32_t textLength(const String& string, int32_t width) { return textLength(string.c_str(), width); } + inline int32_t textWidth(const String& string) { return textWidth(string.c_str()); } + inline int32_t textWidth(const String& string, const IFont* font) { return textWidth(string.c_str(), font); } [[deprecated("use IFont")]] - inline std::size_t drawString(const String& string, std::int32_t x, std::int32_t y, std::uint8_t font) { return draw_string(string.c_str(), x, y, _text_style.datum, fontdata[font]); } - inline std::size_t drawString(const String& string, std::int32_t x, std::int32_t y, const IFont* font) { return draw_string(string.c_str(), x, y, _text_style.datum, font ); } - inline std::size_t drawString(const String& string, std::int32_t x, std::int32_t y ) { return draw_string(string.c_str(), x, y, _text_style.datum); } - - [[deprecated("use IFont")]] inline std::size_t drawCentreString(const String& string, std::int32_t x, std::int32_t y, std::uint8_t font) { return draw_string(string.c_str(), x, y, textdatum_t::top_center, fontdata[font]); } - [[deprecated("use IFont")]] inline std::size_t drawCenterString(const String& string, std::int32_t x, std::int32_t y, std::uint8_t font) { return draw_string(string.c_str(), x, y, textdatum_t::top_center, fontdata[font]); } - [[deprecated("use IFont")]] inline std::size_t drawRightString( const String& string, std::int32_t x, std::int32_t y, std::uint8_t font) { return draw_string(string.c_str(), x, y, textdatum_t::top_right , fontdata[font]); } - inline std::size_t drawCentreString(const String& string, std::int32_t x, std::int32_t y, const IFont* font) { return draw_string(string.c_str(), x, y, textdatum_t::top_center, font); } - inline std::size_t drawCenterString(const String& string, std::int32_t x, std::int32_t y, const IFont* font) { return draw_string(string.c_str(), x, y, textdatum_t::top_center, font); } - inline std::size_t drawRightString( const String& string, std::int32_t x, std::int32_t y, const IFont* font) { return draw_string(string.c_str(), x, y, textdatum_t::top_right , font); } - inline std::size_t drawCentreString(const String& string, std::int32_t x, std::int32_t y ) { return draw_string(string.c_str(), x, y, textdatum_t::top_center); } - inline std::size_t drawCenterString(const String& string, std::int32_t x, std::int32_t y ) { return draw_string(string.c_str(), x, y, textdatum_t::top_center); } - inline std::size_t drawRightString( const String& string, std::int32_t x, std::int32_t y ) { return draw_string(string.c_str(), x, y, textdatum_t::top_right ); } + inline size_t drawString(const String& string, int32_t x, int32_t y, uint8_t font) { return draw_string(string.c_str(), x, y, _text_style.datum, fontdata[font]); } + inline size_t drawString(const String& string, int32_t x, int32_t y, const IFont* font) { return draw_string(string.c_str(), x, y, _text_style.datum, font ); } + inline size_t drawString(const String& string, int32_t x, int32_t y ) { return draw_string(string.c_str(), x, y, _text_style.datum); } + + [[deprecated("use IFont")]] inline size_t drawCentreString(const String& string, int32_t x, int32_t y, uint8_t font) { return draw_string(string.c_str(), x, y, textdatum_t::top_center, fontdata[font]); } + [[deprecated("use IFont")]] inline size_t drawCenterString(const String& string, int32_t x, int32_t y, uint8_t font) { return draw_string(string.c_str(), x, y, textdatum_t::top_center, fontdata[font]); } + [[deprecated("use IFont")]] inline size_t drawRightString( const String& string, int32_t x, int32_t y, uint8_t font) { return draw_string(string.c_str(), x, y, textdatum_t::top_right , fontdata[font]); } + inline size_t drawCentreString(const String& string, int32_t x, int32_t y, const IFont* font) { return draw_string(string.c_str(), x, y, textdatum_t::top_center, font); } + inline size_t drawCenterString(const String& string, int32_t x, int32_t y, const IFont* font) { return draw_string(string.c_str(), x, y, textdatum_t::top_center, font); } + inline size_t drawRightString( const String& string, int32_t x, int32_t y, const IFont* font) { return draw_string(string.c_str(), x, y, textdatum_t::top_right , font); } + inline size_t drawCentreString(const String& string, int32_t x, int32_t y ) { return draw_string(string.c_str(), x, y, textdatum_t::top_center); } + inline size_t drawCenterString(const String& string, int32_t x, int32_t y ) { return draw_string(string.c_str(), x, y, textdatum_t::top_center); } + inline size_t drawRightString( const String& string, int32_t x, int32_t y ) { return draw_string(string.c_str(), x, y, textdatum_t::top_right ); } #endif - std::size_t drawChar(std::uint16_t uniCode, std::int32_t x, std::int32_t y, std::uint8_t font); - inline std::size_t drawChar(std::uint16_t uniCode, std::int32_t x, std::int32_t y) { std::int32_t dummy_filled_x = 0; return _font->drawChar(this, x, y, uniCode, &_text_style, &_font_metrics, dummy_filled_x); } + size_t drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font); + inline size_t drawChar(uint16_t uniCode, int32_t x, int32_t y) { int32_t dummy_filled_x = 0; return _font->drawChar(this, x, y, uniCode, &_text_style, &_font_metrics, dummy_filled_x); } template - inline std::size_t drawChar(std::int32_t x, std::int32_t y, std::uint16_t uniCode, T color, T bg, float size) { return drawChar(x, y, uniCode, color, bg, size, size); } + inline size_t drawChar(int32_t x, int32_t y, uint16_t uniCode, T color, T bg, float size) { return drawChar(x, y, uniCode, color, bg, size, size); } template - inline std::size_t drawChar(std::int32_t x, std::int32_t y, std::uint16_t uniCode, T color, T bg, float size_x, float size_y) + inline size_t drawChar(int32_t x, int32_t y, uint16_t uniCode, T color, T bg, float size_x, float size_y) { TextStyle style = _text_style; style.back_rgb888 = convert_to_rgb888(color); style.fore_rgb888 = convert_to_rgb888(bg); style.size_x = size_x; style.size_y = size_y; - std::int32_t dummy_filled_x = 0; + int32_t dummy_filled_x = 0; return _font->drawChar(this, x, y, uniCode, &style, &_font_metrics, dummy_filled_x); //return (fpDrawChar)(this, x, y, uniCode, &style, _font); } [[deprecated("use getFont()")]] - std::uint8_t getTextFont(void) const + uint8_t getTextFont(void) const { - std::size_t i = 0; + size_t i = 0; do { if (fontdata[i] == _font) return i; } while (fontdata[++i]); @@ -598,34 +598,34 @@ namespace lgfx void setFont(const IFont* font); /// load VLW font - bool loadFont(const std::uint8_t* array); + bool loadFont(const uint8_t* array); /// unload VLW font void unloadFont(void); /// show VLW font - void showFont(std::uint32_t td = 2000); + void showFont(uint32_t td = 2000); void cp437(bool enable = true) { _text_style.cp437 = enable; } // AdafruitGFX compatible. - void setAttribute(attribute_t attr_id, std::uint8_t param); - std::uint8_t getAttribute(attribute_t attr_id); - std::uint8_t getAttribute(std::uint8_t attr_id) { return getAttribute((attribute_t)attr_id); } + void setAttribute(attribute_t attr_id, uint8_t param); + uint8_t getAttribute(attribute_t attr_id); + uint8_t getAttribute(uint8_t attr_id) { return getAttribute((attribute_t)attr_id); } //---------------------------------------------------------------------------- // print & text support //---------------------------------------------------------------------------- // Arduino Print.h compatible #if !defined (ARDUINO) - std::size_t print(const char str[]) { return write(str); } - std::size_t print(char c) { return write(c); } - std::size_t print(int n, int base = 10) { return print((long)n, base); } - std::size_t print(long n, int base = 10) + size_t print(const char str[]) { return write(str); } + size_t print(char c) { return write(c); } + size_t print(int n, int base = 10) { return print((long)n, base); } + size_t print(long n, int base = 10) { if (base == 0) { return write(n); } if (base == 10) { if (n < 0) { - std::size_t t = print('-'); + size_t t = print('-'); return printNumber(-n, 10) + t; } return printNumber(n, 10); @@ -633,105 +633,105 @@ namespace lgfx return printNumber(n, base); } - std::size_t print(unsigned char n, int base = 10) { return print((unsigned long)n, base); } - std::size_t print(unsigned int n, int base = 10) { return print((unsigned long)n, base); } - std::size_t print(unsigned long n, int base = 10) { return (base) ? printNumber(n, base) : write(n); } - std::size_t print(double n, int digits= 2) { return printFloat(n, digits); } + size_t print(unsigned char n, int base = 10) { return print((unsigned long)n, base); } + size_t print(unsigned int n, int base = 10) { return print((unsigned long)n, base); } + size_t print(unsigned long n, int base = 10) { return (base) ? printNumber(n, base) : write(n); } + size_t print(double n, int digits= 2) { return printFloat(n, digits); } - std::size_t println(void) { return print("\r\n"); } - std::size_t println(const char c[]) { std::size_t t = print(c); return println() + t; } - std::size_t println(char c ) { std::size_t t = print(c); return println() + t; } - std::size_t println(int n, int base = 10) { std::size_t t = print(n,base); return println() + t; } - std::size_t println(long n, int base = 10) { std::size_t t = print(n,base); return println() + t; } - std::size_t println(unsigned char n, int base = 10) { std::size_t t = print(n,base); return println() + t; } - std::size_t println(unsigned int n, int base = 10) { std::size_t t = print(n,base); return println() + t; } - std::size_t println(unsigned long n, int base = 10) { std::size_t t = print(n,base); return println() + t; } - std::size_t println(double n, int digits= 2) { std::size_t t = print(n, digits); return println() + t; } + size_t println(void) { return print("\r\n"); } + size_t println(const char c[]) { size_t t = print(c); return println() + t; } + size_t println(char c ) { size_t t = print(c); return println() + t; } + size_t println(int n, int base = 10) { size_t t = print(n,base); return println() + t; } + size_t println(long n, int base = 10) { size_t t = print(n,base); return println() + t; } + size_t println(unsigned char n, int base = 10) { size_t t = print(n,base); return println() + t; } + size_t println(unsigned int n, int base = 10) { size_t t = print(n,base); return println() + t; } + size_t println(unsigned long n, int base = 10) { size_t t = print(n,base); return println() + t; } + size_t println(double n, int digits= 2) { size_t t = print(n, digits); return println() + t; } - //std::size_t print(const String &s) { return write(s.c_str(), s.length()); } - //std::size_t print(const __FlashStringHelper *s) { return print(reinterpret_cast(s)); } - //std::size_t println(const String &s) { std::size_t t = print(s); return println() + t; } - //std::size_t println(const __FlashStringHelper *s) { std::size_t t = print(s); return println() + t; } + //size_t print(const String &s) { return write(s.c_str(), s.length()); } + //size_t print(const __FlashStringHelper *s) { return print(reinterpret_cast(s)); } + //size_t println(const String &s) { size_t t = print(s); return println() + t; } + //size_t println(const __FlashStringHelper *s) { size_t t = print(s); return println() + t; } - std::size_t printf(const char * format, ...) __attribute__ ((format (printf, 2, 3))); + size_t printf(const char * format, ...) __attribute__ ((format (printf, 2, 3))); - std::size_t write(const char* str) { return (!str) ? 0 : write((const std::uint8_t*)str, strlen(str)); } - std::size_t write(const char *buf, std::size_t size) { return write((const std::uint8_t *) buf, size); } + size_t write(const char* str) { return (!str) ? 0 : write((const uint8_t*)str, strlen(str)); } + size_t write(const char *buf, size_t size) { return write((const uint8_t *) buf, size); } #else using Print::write; #endif - std::size_t write(const std::uint8_t *buf, std::size_t size) { std::size_t n = 0; this->startWrite(); while (size--) { n += write(*buf++); } this->endWrite(); return n; } - std::size_t write(std::uint8_t utf8); - std::size_t vprintf(const char *format, va_list arg); + size_t write(const uint8_t *buf, size_t size) { size_t n = 0; this->startWrite(); while (size--) { n += write(*buf++); } this->endWrite(); return n; } + size_t write(uint8_t utf8); + size_t vprintf(const char *format, va_list arg); #ifdef ARDUINO - void qrcode(const String &string, std::int32_t x = -1, std::int32_t y = -1, std::int32_t width = -1, std::uint8_t version = 1) { + void qrcode(const String &string, int32_t x = -1, int32_t y = -1, int32_t width = -1, uint8_t version = 1) { qrcode(string.c_str(), x, y, width, version); } #endif - void qrcode(const char *string, std::int32_t x = -1, std::int32_t y = -1, std::int32_t width = -1, std::uint8_t version = 1); + void qrcode(const char *string, int32_t x = -1, int32_t y = -1, int32_t width = -1, uint8_t version = 1); - bool drawBmp(const std::uint8_t *bmp_data, std::uint32_t bmp_len, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + bool drawBmp(const uint8_t *bmp_data, uint32_t bmp_len, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { PointerWrapper data; data.set(bmp_data, bmp_len); return this->draw_bmp(&data, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - bool drawJpg(const std::uint8_t *jpg_data, std::uint32_t jpg_len, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + bool drawJpg(const uint8_t *jpg_data, uint32_t jpg_len, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { PointerWrapper data; data.set(jpg_data, jpg_len); return this->draw_jpg(&data, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - [[deprecated("use float scale")]] bool drawJpg(const std::uint8_t *jpg_data, std::uint32_t jpg_len, std::int32_t x, std::int32_t y, std::int32_t maxWidth, std::int32_t maxHeight, std::int32_t offX, std::int32_t offY, jpeg_div::jpeg_div_t scale) + [[deprecated("use float scale")]] bool drawJpg(const uint8_t *jpg_data, uint32_t jpg_len, int32_t x, int32_t y, int32_t maxWidth, int32_t maxHeight, int32_t offX, int32_t offY, jpeg_div::jpeg_div_t scale) { return drawJpg(jpg_data, jpg_len, x, y, maxWidth, maxHeight, offX, offY, 1.0f / (1 << scale)); } - bool drawPng(const std::uint8_t *png_data, std::uint32_t png_len, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + bool drawPng(const uint8_t *png_data, uint32_t png_len, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { PointerWrapper data; data.set(png_data, png_len); return this->draw_png(&data, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - inline bool drawBmp(DataWrapper *data, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawBmp(DataWrapper *data, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { return this->draw_bmp(data, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - inline bool drawJpg(DataWrapper *data, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawJpg(DataWrapper *data, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { return this->draw_jpg(data, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - [[deprecated("use float scale")]] inline bool drawJpg(DataWrapper *data, std::int32_t x, std::int32_t y, std::int32_t maxWidth, std::int32_t maxHeight, std::int32_t offX, std::int32_t offY, jpeg_div::jpeg_div_t scale) + [[deprecated("use float scale")]] inline bool drawJpg(DataWrapper *data, int32_t x, int32_t y, int32_t maxWidth, int32_t maxHeight, int32_t offX, int32_t offY, jpeg_div::jpeg_div_t scale) { return drawJpg(data, x, y, maxWidth, maxHeight, offX, offY, 1.0f / (1 << scale)); } - inline bool drawPng(DataWrapper *data, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawPng(DataWrapper *data, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { return this->draw_png(data, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - void* createPng( std::size_t* datalen, std::int32_t x = 0, std::int32_t y = 0, std::int32_t width = 0, std::int32_t height = 0); + void* createPng( size_t* datalen, int32_t x = 0, int32_t y = 0, int32_t width = 0, int32_t height = 0); template - [[deprecated("use pushImage")]] void pushRect( std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, const T* data) { pushImage(x, y, w, h, data); } + [[deprecated("use pushImage")]] void pushRect( int32_t x, int32_t y, int32_t w, int32_t h, const T* data) { pushImage(x, y, w, h, data); } template - [[deprecated("use pushBlock")]] void pushColor(const T& color, std::uint32_t length) { if (0 != length) { setColor(color); startWrite(); _panel->writeBlock(getRawColor(), length); endWrite(); } } + [[deprecated("use pushBlock")]] void pushColor(const T& color, uint32_t length) { if (0 != length) { setColor(color); startWrite(); _panel->writeBlock(getRawColor(), length); endWrite(); } } template [[deprecated("use pushBlock")]] void pushColor(const T& color ) { setColor(color); startWrite(); _panel->writeBlock(getRawColor(), 1); endWrite(); } template - [[deprecated("use pushPixels")]] void pushColors(T* data, std::int32_t len ) { startWrite(); writePixels(data, len ); endWrite(); } - [[deprecated("use pushPixels")]] void pushColors(const void* data, std::int32_t len ) { startWrite(); writePixels(data, len, _swapBytes); endWrite(); } - [[deprecated("use pushPixels")]] void pushColors(const std::uint16_t* data, std::int32_t len ) { startWrite(); writePixels(data, len, _swapBytes); endWrite(); } - [[deprecated("use pushPixels")]] void pushColors(const std::uint8_t* data, std::int32_t len ) { startWrite(); writePixels((const rgb332_t*)data, len); endWrite(); } - [[deprecated("use pushPixels")]] void pushColors(const void* data, std::int32_t len, bool swap) { startWrite(); writePixels(data, len, swap); endWrite(); } - [[deprecated("use pushPixels")]] void pushColors(const std::uint16_t* data, std::int32_t len, bool swap) { startWrite(); writePixels(data, len, swap); endWrite(); } + [[deprecated("use pushPixels")]] void pushColors(T* data, int32_t len ) { startWrite(); writePixels(data, len ); endWrite(); } + [[deprecated("use pushPixels")]] void pushColors(const void* data, int32_t len ) { startWrite(); writePixels(data, len, _swapBytes); endWrite(); } + [[deprecated("use pushPixels")]] void pushColors(const uint16_t* data, int32_t len ) { startWrite(); writePixels(data, len, _swapBytes); endWrite(); } + [[deprecated("use pushPixels")]] void pushColors(const uint8_t* data, int32_t len ) { startWrite(); writePixels((const rgb332_t*)data, len); endWrite(); } + [[deprecated("use pushPixels")]] void pushColors(const void* data, int32_t len, bool swap) { startWrite(); writePixels(data, len, swap); endWrite(); } + [[deprecated("use pushPixels")]] void pushColors(const uint16_t* data, int32_t len, bool swap) { startWrite(); writePixels(data, len, swap); endWrite(); } //---------------------------------------------------------------------------- @@ -742,16 +742,16 @@ namespace lgfx IPanel* _panel = nullptr; - std::int32_t _sx = 0, _sy = 0, _sw = 0, _sh = 0; // for scroll zone - std::int32_t _clip_l = 0, _clip_r = -1, _clip_t = 0, _clip_b = -1; // clip rect + int32_t _sx = 0, _sy = 0, _sw = 0, _sh = 0; // for scroll zone + int32_t _clip_l = 0, _clip_r = -1, _clip_t = 0, _clip_b = -1; // clip rect - std::uint32_t _base_rgb888 = 0; // gap fill colour for clear and scroll zone + uint32_t _base_rgb888 = 0; // gap fill colour for clear and scroll zone raw_color_t _color = 0xFFFFFFU; color_conv_t _write_conv; color_conv_t _read_conv; - std::uint16_t _palette_count = 0; + uint16_t _palette_count = 0; float _xpivot = 0.0f; // x pivot point coordinate float _ypivot = 0.0f; // x pivot point coordinate @@ -764,12 +764,11 @@ namespace lgfx , utf8_state2 = 2 }; utf8_decode_state_t _decoderState = utf8_state0; // UTF8 decoder state - std::uint_fast16_t _unicode_buffer = 0; // Unicode code-point buffer + uint_fast16_t _unicode_buffer = 0; // Unicode code-point buffer - std::int32_t _cursor_x = 0; // print text cursor - std::int32_t _cursor_y = 0; - std::int32_t _filled_x = 0; // print filled position - std::int32_t _padding_x = 0; + int32_t _cursor_x = 0; // print text cursor + int32_t _cursor_y = 0; + int32_t _filled_x = 0; // print filled position TextStyle _text_style; FontMetrics _font_metrics = { 6, 6, 0, 8, 8, 0, 7 }; // Font0 default metric @@ -783,15 +782,15 @@ namespace lgfx bool _textwrap_y = false; bool _textscroll = false; - __attribute__ ((always_inline)) inline static bool _adjust_abs(std::int32_t& x, std::int32_t& w) { if (w < 0) { x += w + 1; w = -w; } return !w; } - static bool _adjust_width(std::int32_t& x, std::int32_t& dx, std::int32_t& dw, std::int32_t left, std::int32_t width) + __attribute__ ((always_inline)) inline static bool _adjust_abs(int32_t& x, int32_t& w) { if (w < 0) { x += w + 1; w = -w; } return !w; } + static bool _adjust_width(int32_t& x, int32_t& dx, int32_t& dw, int32_t left, int32_t width) { if (x < left) { dx = -x; dw += x; x = left; } if (dw > left + width - x) dw = left + width - x; return (dw <= 0); } - bool _clipping(std::int32_t& x, std::int32_t& y, std::int32_t& w, std::int32_t& h) + bool _clipping(int32_t& x, int32_t& y, int32_t& w, int32_t& h) { auto cl = _clip_l; if (x < cl) { w += x - cl; x = cl; } @@ -833,10 +832,10 @@ namespace lgfx } return pc; } - __attribute__ ((always_inline)) inline pixelcopy_t create_pc_fast(const std::uint8_t *data) { return create_pc_fast(reinterpret_cast(data)); } - __attribute__ ((always_inline)) inline pixelcopy_t create_pc_fast(const std::uint16_t *data) { return create_pc_fast(data, _swapBytes); } - __attribute__ ((always_inline)) inline pixelcopy_t create_pc_fast(const void *data) { return create_pc_fast(data, _swapBytes); } - __attribute__ ((always_inline)) inline pixelcopy_t create_pc_fast(const std::uint16_t *data, bool swap) + __attribute__ ((always_inline)) inline pixelcopy_t create_pc_fast(const uint8_t* data) { return create_pc_fast(reinterpret_cast(data)); } + __attribute__ ((always_inline)) inline pixelcopy_t create_pc_fast(const uint16_t* data) { return create_pc_fast(data, _swapBytes); } + __attribute__ ((always_inline)) inline pixelcopy_t create_pc_fast(const void* data) { return create_pc_fast(data, _swapBytes); } + __attribute__ ((always_inline)) inline pixelcopy_t create_pc_fast(const uint16_t* data, bool swap) { return swap && !hasPalette() && _write_conv.bits >= 8 ? create_pc_fast(reinterpret_cast(data)) @@ -908,16 +907,16 @@ namespace lgfx return pc; } - __attribute__ ((always_inline)) inline pixelcopy_t create_pc(const std::uint8_t *data) { return create_pc(reinterpret_cast(data)); } - __attribute__ ((always_inline)) inline pixelcopy_t create_pc(const std::uint16_t *data) { return create_pc(data, _swapBytes); } - __attribute__ ((always_inline)) inline pixelcopy_t create_pc(const void *data) { return create_pc(data, _swapBytes); } - __attribute__ ((always_inline)) inline pixelcopy_t create_pc(const std::uint16_t *data, bool swap) + __attribute__ ((always_inline)) inline pixelcopy_t create_pc(const uint8_t* data) { return create_pc(reinterpret_cast(data)); } + __attribute__ ((always_inline)) inline pixelcopy_t create_pc(const uint16_t* data) { return create_pc(data, _swapBytes); } + __attribute__ ((always_inline)) inline pixelcopy_t create_pc(const void* data) { return create_pc(data, _swapBytes); } + __attribute__ ((always_inline)) inline pixelcopy_t create_pc(const uint16_t* data, bool swap) { return swap && !hasPalette() && _write_conv.bits >= 8 ? create_pc(reinterpret_cast(data)) : create_pc(reinterpret_cast(data)); } - __attribute__ ((always_inline)) inline pixelcopy_t create_pc(const void *data, bool swap) + __attribute__ ((always_inline)) inline pixelcopy_t create_pc(const void* data, bool swap) { return swap && !hasPalette() && _write_conv.bits >= 8 ? create_pc(reinterpret_cast(data)) @@ -925,7 +924,7 @@ namespace lgfx } template - pixelcopy_t create_pc_rawtr(const T *data, std::uint32_t raw_transparent) + pixelcopy_t create_pc_rawtr(const T *data, uint32_t raw_transparent) { if (std::is_same::value) { raw_transparent = getSwap16(raw_transparent); } if (std::is_same::value) { raw_transparent = getSwap24(raw_transparent); } @@ -948,10 +947,10 @@ namespace lgfx : get_fp_convert_src(get_depth::value, false)(transparent)); } - template pixelcopy_t create_pc_tr(const std::uint8_t *data, const T& transparent) { return create_pc_tr(reinterpret_cast(data), transparent); } - template pixelcopy_t create_pc_tr(const std::uint16_t *data, const T& transparent) { return create_pc_tr(data, transparent, _swapBytes); } - template pixelcopy_t create_pc_tr(const void *data, const T& transparent) { return create_pc_tr(data, transparent, _swapBytes); } - template pixelcopy_t create_pc_tr(const std::uint16_t *data, const T& transparent, bool swap) + template pixelcopy_t create_pc_tr(const uint8_t* data, const T& transparent) { return create_pc_tr(reinterpret_cast(data), transparent); } + template pixelcopy_t create_pc_tr(const uint16_t* data, const T& transparent) { return create_pc_tr(data, transparent, _swapBytes); } + template pixelcopy_t create_pc_tr(const void* data, const T& transparent) { return create_pc_tr(data, transparent, _swapBytes); } + template pixelcopy_t create_pc_tr(const uint16_t* data, const T& transparent, bool swap) { return swap && _write_conv.bits >= 8 && !hasPalette() ? create_pc_tr(reinterpret_cast(data), transparent) @@ -964,13 +963,13 @@ namespace lgfx : create_pc_tr(reinterpret_cast(data), transparent); } - pixelcopy_t create_pc_palette(const void *data, const bgr888_t *palette, lgfx::color_depth_t depth, std::uint32_t transparent = pixelcopy_t::NON_TRANSP) + pixelcopy_t create_pc_palette(const void *data, const bgr888_t *palette, lgfx::color_depth_t depth, uint32_t transparent = pixelcopy_t::NON_TRANSP) { return pixelcopy_t (data, _write_conv.depth, depth, hasPalette(), palette, transparent); } template - pixelcopy_t create_pc_palette(const void *data, const T *palette, lgfx::color_depth_t depth, std::uint32_t transparent = pixelcopy_t::NON_TRANSP) + pixelcopy_t create_pc_palette(const void *data, const T *palette, lgfx::color_depth_t depth, uint32_t transparent = pixelcopy_t::NON_TRANSP) { pixelcopy_t pc(data, getColorDepth(), depth, hasPalette(), palette, transparent); if (!hasPalette() && palette && _write_conv.bits >= 8) @@ -981,17 +980,17 @@ namespace lgfx } - __attribute__ ((always_inline)) inline pixelcopy_t create_pc_antialias(const std::uint8_t *data, std::uint32_t raw_transparent = pixelcopy_t::NON_TRANSP) + __attribute__ ((always_inline)) inline pixelcopy_t create_pc_antialias(const uint8_t *data, uint32_t raw_transparent = pixelcopy_t::NON_TRANSP) { return create_pc_antialias(reinterpret_cast(data), raw_transparent); } - __attribute__ ((always_inline)) inline pixelcopy_t create_pc_antialias(const std::uint16_t *data, std::uint32_t raw_transparent = pixelcopy_t::NON_TRANSP) + __attribute__ ((always_inline)) inline pixelcopy_t create_pc_antialias(const uint16_t *data, uint32_t raw_transparent = pixelcopy_t::NON_TRANSP) { return _swapBytes ? create_pc_antialias(reinterpret_cast(data), raw_transparent) : create_pc_antialias(reinterpret_cast(data), raw_transparent); } - __attribute__ ((always_inline)) inline pixelcopy_t create_pc_antialias(const void *data, std::uint32_t raw_transparent = pixelcopy_t::NON_TRANSP) + __attribute__ ((always_inline)) inline pixelcopy_t create_pc_antialias(const void *data, uint32_t raw_transparent = pixelcopy_t::NON_TRANSP) { return _swapBytes ? create_pc_antialias(reinterpret_cast(data), raw_transparent) @@ -999,7 +998,7 @@ namespace lgfx } template - pixelcopy_t create_pc_antialias(const T* data, std::uint32_t raw_transparent = pixelcopy_t::NON_TRANSP) + pixelcopy_t create_pc_antialias(const T* data, uint32_t raw_transparent = pixelcopy_t::NON_TRANSP) { pixelcopy_t pc(data, argb8888_t::depth, get_depth::value, false, nullptr, raw_transparent); pc.src_data = data; @@ -1017,7 +1016,7 @@ namespace lgfx } template - static pixelcopy_t create_pc_antialias(const void* data, const T* palette, lgfx::color_depth_t depth, std::uint32_t transparent = pixelcopy_t::NON_TRANSP) + static pixelcopy_t create_pc_antialias(const void* data, const T* palette, lgfx::color_depth_t depth, uint32_t transparent = pixelcopy_t::NON_TRANSP) { pixelcopy_t pc(data, argb8888_t::depth, depth, false, palette, transparent); if (palette) @@ -1047,30 +1046,30 @@ namespace lgfx static void make_rotation_matrix(float* result, float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y); - void read_rect(std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, void* dst, pixelcopy_t* param); - void draw_gradient_line( std::int32_t x0, std::int32_t y0, std::int32_t x1, std::int32_t y1, uint32_t colorstart, uint32_t colorend ); - void fill_arc_helper(std::int32_t cx, std::int32_t cy, std::int32_t oradius_x, std::int32_t iradius_x, std::int32_t oradius_y, std::int32_t iradius_y, float start, float end); - void draw_bezier_helper(std::int32_t x0, std::int32_t y0, std::int32_t x1, std::int32_t y1, std::int32_t x2, std::int32_t y2); - void draw_bitmap(std::int32_t x, std::int32_t y, const std::uint8_t *bitmap, std::int32_t w, std::int32_t h, std::uint32_t fg_rawcolor, std::uint32_t bg_rawcolor = ~0u); - void draw_xbitmap(std::int32_t x, std::int32_t y, const std::uint8_t *bitmap, std::int32_t w, std::int32_t h, std::uint32_t fg_rawcolor, std::uint32_t bg_rawcolor = ~0u); - void push_image_rotate_zoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, std::int32_t w, std::int32_t h, pixelcopy_t* pc); - void push_image_rotate_zoom_aa(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, std::int32_t w, std::int32_t h, pixelcopy_t* pc); - void push_image_affine(const float* matrix, std::int32_t w, std::int32_t h, pixelcopy_t *pc); + void read_rect(int32_t x, int32_t y, int32_t w, int32_t h, void* dst, pixelcopy_t* param); + void draw_gradient_line( int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t colorstart, uint32_t colorend ); + void fill_arc_helper(int32_t cx, int32_t cy, int32_t oradius_x, int32_t iradius_x, int32_t oradius_y, int32_t iradius_y, float start, float end); + void draw_bezier_helper(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2); + void draw_bitmap(int32_t x, int32_t y, const uint8_t *bitmap, int32_t w, int32_t h, uint32_t fg_rawcolor, uint32_t bg_rawcolor = ~0u); + void draw_xbitmap(int32_t x, int32_t y, const uint8_t *bitmap, int32_t w, int32_t h, uint32_t fg_rawcolor, uint32_t bg_rawcolor = ~0u); + void push_image_rotate_zoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, pixelcopy_t* pc); + void push_image_rotate_zoom_aa(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, pixelcopy_t* pc); + void push_image_affine(const float* matrix, int32_t w, int32_t h, pixelcopy_t *pc); void push_image_affine(const float* matrix, pixelcopy_t *pc); - void push_image_affine_aa(const float* matrix, std::int32_t w, std::int32_t h, pixelcopy_t *pc); + void push_image_affine_aa(const float* matrix, int32_t w, int32_t h, pixelcopy_t *pc); void push_image_affine_aa(const float* matrix, pixelcopy_t *pre_pc, pixelcopy_t *post_pc); - std::uint16_t decodeUTF8(std::uint8_t c); + uint16_t decodeUTF8(uint8_t c); - std::size_t printNumber(unsigned long n, std::uint8_t base); - std::size_t printFloat(double number, std::uint8_t digits); - std::size_t draw_string(const char *string, std::int32_t x, std::int32_t y, textdatum_t datum, const IFont* font = nullptr); - std::int32_t text_width(const char *string, const IFont* font, FontMetrics* metrics); + size_t printNumber(unsigned long n, uint8_t base); + size_t printFloat(double number, uint8_t digits); + size_t draw_string(const char *string, int32_t x, int32_t y, textdatum_t datum, const IFont* font = nullptr); + int32_t text_width(const char *string, const IFont* font, FontMetrics* metrics); bool load_font(lgfx::DataWrapper* data); - bool draw_bmp(DataWrapper* data, std::int32_t x, std::int32_t y, std::int32_t maxWidth, std::int32_t maxHeight, std::int32_t offX, std::int32_t offY, float scale_x, float scale_y, datum_t datum); - bool draw_jpg(DataWrapper* data, std::int32_t x, std::int32_t y, std::int32_t maxWidth, std::int32_t maxHeight, std::int32_t offX, std::int32_t offY, float scale_x, float scale_y, datum_t datum); - bool draw_png(DataWrapper* data, std::int32_t x, std::int32_t y, std::int32_t maxWidth, std::int32_t maxHeight, std::int32_t offX, std::int32_t offY, float scale_x, float scale_y, datum_t datum); + bool draw_bmp(DataWrapper* data, int32_t x, int32_t y, int32_t maxWidth, int32_t maxHeight, int32_t offX, int32_t offY, float scale_x, float scale_y, datum_t datum); + bool draw_jpg(DataWrapper* data, int32_t x, int32_t y, int32_t maxWidth, int32_t maxHeight, int32_t offX, int32_t offY, float scale_x, float scale_y, datum_t datum); + bool draw_png(DataWrapper* data, int32_t x, int32_t y, int32_t maxWidth, int32_t maxHeight, int32_t offX, int32_t offY, float scale_x, float scale_y, datum_t datum); static void tmpBeginTransaction(LGFXBase* lgfx) { @@ -1132,29 +1131,29 @@ namespace lgfx inline Panel_Device* getPanel(void) const { return reinterpret_cast(_panel); } inline void panel(Panel_Device* panel) { setPanel(panel); } - inline void writeCommand( std::uint8_t cmd) { _panel->writeCommand( cmd , 1); } // AdafruitGFX compatible - inline void writecommand( std::uint8_t cmd) { _panel->writeCommand( cmd , 1); } // TFT_eSPI compatible - inline void writeCommand16(std::uint16_t cmd) { _panel->writeCommand(__builtin_bswap16(cmd), 2); } - inline void spiWrite( std::uint8_t data) { _panel->writeData( data , 1); } // AdafruitGFX compatible - inline void writedata( std::uint8_t data) { _panel->writeData( data , 1); } // TFT_eSPI compatible - inline void writeData( std::uint8_t data) { _panel->writeData( data , 1); } - inline void writeData16(std::uint16_t data) { _panel->writeData(__builtin_bswap16(data), 2); } - inline void writeData32(std::uint32_t data) { _panel->writeData(__builtin_bswap32(data), 4); } - inline std::uint8_t readData8( std::uint8_t index=0) { return _panel->readData(index, 1) ; } - inline std::uint16_t readData16(std::uint8_t index=0) { return __builtin_bswap16(_panel->readData(index, 2)); } - inline std::uint32_t readData32(std::uint8_t index=0) { return __builtin_bswap32(_panel->readData(index, 4)); } + inline void writeCommand( uint8_t cmd) { _panel->writeCommand( cmd , 1); } // AdafruitGFX compatible + inline void writecommand( uint8_t cmd) { _panel->writeCommand( cmd , 1); } // TFT_eSPI compatible + inline void writeCommand16(uint16_t cmd) { _panel->writeCommand(__builtin_bswap16(cmd), 2); } + inline void spiWrite( uint8_t data) { _panel->writeData( data , 1); } // AdafruitGFX compatible + inline void writedata( uint8_t data) { _panel->writeData( data , 1); } // TFT_eSPI compatible + inline void writeData( uint8_t data) { _panel->writeData( data , 1); } + inline void writeData16(uint16_t data) { _panel->writeData(__builtin_bswap16(data), 2); } + inline void writeData32(uint32_t data) { _panel->writeData(__builtin_bswap32(data), 4); } + inline uint8_t readData8( uint8_t index=0) { return _panel->readData(index, 1) ; } + inline uint16_t readData16(uint8_t index=0) { return __builtin_bswap16(_panel->readData(index, 2)); } + inline uint32_t readData32(uint8_t index=0) { return __builtin_bswap32(_panel->readData(index, 4)); } inline ILight* light(void) const { return _panel ? panel()->light() : nullptr; } - inline void setBrightness(std::uint8_t brightness) { _brightness = brightness; if (_panel) { _panel->setBrightness(brightness); } } - inline std::uint8_t getBrightness(void) const { return _brightness; } + inline void setBrightness(uint8_t brightness) { _brightness = brightness; if (_panel) { _panel->setBrightness(brightness); } } + inline uint8_t getBrightness(void) const { return _brightness; } inline ITouch* touch(void) const { return _panel ? panel()->touch() : nullptr; } - inline std::uint_fast8_t getTouchRaw(touch_point_t *tp, std::uint_fast8_t count = 1) { return panel()->getTouchRaw(tp, count); } - inline std::uint_fast8_t getTouch(touch_point_t *tp, std::uint_fast8_t count = 1) { return panel()->getTouch(tp, count); } - inline void convertRawXY(touch_point_t *tp, std::uint_fast8_t count = 1) { panel()->convertRawXY(tp, count); } + inline uint_fast8_t getTouchRaw(touch_point_t *tp, uint_fast8_t count = 1) { return panel()->getTouchRaw(tp, count); } + inline uint_fast8_t getTouch(touch_point_t *tp, uint_fast8_t count = 1) { return panel()->getTouch(tp, count); } + inline void convertRawXY(touch_point_t *tp, uint_fast8_t count = 1) { panel()->convertRawXY(tp, count); } template - std::uint_fast8_t getTouchRaw(T *x, T *y, std::uint_fast8_t index = 0) + uint_fast8_t getTouchRaw(T *x, T *y, uint_fast8_t index = 0) { touch_point_t tp[index + 1]; auto count = getTouchRaw(tp, index + 1); @@ -1165,14 +1164,14 @@ namespace lgfx } template - std::uint_fast8_t getTouch(T *x, T *y, std::uint_fast8_t index = 0) + uint_fast8_t getTouch(T *x, T *y, uint_fast8_t index = 0) { touch_point_t tp[index + 1]; auto count = getTouch(tp, index + 1); if (index >= count) return 0; if (x) *x = tp[index].x; if (y) *y = tp[index].y; - return index; + return count; } template @@ -1188,7 +1187,7 @@ namespace lgfx /// This requires a uint16_t array with 8 elements. ( or nullptr ) template - void calibrateTouch(std::uint16_t *parameters, const T& color_fg, const T& color_bg, std::uint8_t size = 10) + void calibrateTouch(uint16_t *parameters, const T& color_fg, const T& color_bg, uint8_t size = 10) { // 第1引数 にuint16_t[8]のポインタを渡すことで、setTouchCalibrateで使用できるキャリブレーション値を得ることが出来る。 // この値をフラッシュ等に記録しておき、次回起動時にsetTouchCalibrateを使うことで、手作業によるキャリブレーションを省略できる。 calibrate_touch(parameters, _write_conv.convert(color_fg), _write_conv.convert(color_bg), size); @@ -1196,19 +1195,19 @@ namespace lgfx /// This requires a uint16_t array with 8 elements. /// calibrateTouchで得たキャリブレーション値を用いて設定を再現する。 - void setTouchCalibrate(std::uint16_t *parameters) + void setTouchCalibrate(uint16_t *parameters) { panel()->setCalibrate(parameters); } protected: - std::uint8_t _brightness = 127; + uint8_t _brightness = 127; virtual bool init_impl(bool use_reset, bool use_clear); - void draw_calibrate_point(std::int32_t x, std::int32_t y, std::int32_t r, std::uint32_t fg_rawcolor, std::uint32_t bg_rawcolor); + void draw_calibrate_point(int32_t x, int32_t y, int32_t r, uint32_t fg_rawcolor, uint32_t bg_rawcolor); - void calibrate_touch(std::uint16_t *parameters, std::uint32_t fg_rawcolor, std::uint32_t bg_rawcolor, std::uint8_t size); + void calibrate_touch(uint16_t *parameters, uint32_t fg_rawcolor, uint32_t bg_rawcolor, uint8_t size); //---------------------------------------------------------------------------- diff --git a/src/lgfx/v1/LGFX_Button.cpp b/src/lgfx/v1/LGFX_Button.cpp new file mode 100644 index 0000000..52c5a41 --- /dev/null +++ b/src/lgfx/v1/LGFX_Button.cpp @@ -0,0 +1,80 @@ +/*----------------------------------------------------------------------------/ + Lovyan GFX - Graphics library for embedded devices. + +Original Source: + https://github.com/lovyan03/LovyanGFX/ + +Licence: + [FreeBSD](https://github.com/lovyan03/LovyanGFX/blob/master/license.txt) + +Author: + [lovyan03](https://twitter.com/lovyan03) + +Contributors: + [ciniml](https://github.com/ciniml) + [mongonta0716](https://github.com/mongonta0716) + [tobozo](https://github.com/tobozo) +/----------------------------------------------------------------------------*/ + +#include "LGFX_Button.hpp" + +#include "LGFXBase.hpp" + +#include "../internal/limits.h" + +namespace lgfx +{ + inline namespace v1 + { +//---------------------------------------------------------------------------- + + void LGFX_Button::_init_button( LovyanGFX *gfx, int16_t x, int16_t y, uint16_t w, uint16_t h + , const char *label, float textsize_x, float textsize_y) + { + _gfx = gfx; + _x = x; + _y = y; + _w = w; + _h = h; + _textsize_x = textsize_x; + _textsize_y = textsize_y <= std::numeric_limits::epsilon() ? textsize_x : textsize_y; + strncpy(_label, label, 11); + } + + // Adjust text datum and x, y deltas + void LGFX_Button::setLabelDatum(int16_t x_delta, int16_t y_delta, textdatum_t datum) + { + _xd = x_delta; + _yd = y_delta; + _textdatum = datum; + } + + void LGFX_Button::drawButton(bool inverted, const char* long_name) + { + if( _drawCb ) { + _drawCb( _gfx, _x, _y, _w, _h, inverted, long_name ? long_name : _label ); + return; + } + auto style = _gfx->getTextStyle(); + + _gfx->setTextSize(_textsize_x, _textsize_y); + _gfx->setTextDatum(_textdatum); + _gfx->setTextPadding(0); + + auto fill = inverted ? _textcolor : _fillcolor; + auto text = inverted ? _fillcolor : _textcolor; + _gfx->setTextColor(text, fill); + + uint_fast8_t r = (_w < _h ? _w : _h) >> 2; // Corner radius + _gfx->startWrite(); + _gfx->fillRoundRect(_x, _y, _w, _h, r, fill); + _gfx->drawRoundRect(_x, _y, _w, _h, r, _outlinecolor); + _gfx->drawString(long_name ? long_name : _label, _x + (_w >> 1) + _xd, _y + (_h >> 1) + _yd); + _gfx->endWrite(); + + _gfx->setTextStyle(style); + } + +//---------------------------------------------------------------------------- + } +} diff --git a/src/lgfx/v1/LGFX_Button.hpp b/src/lgfx/v1/LGFX_Button.hpp new file mode 100644 index 0000000..daa630b --- /dev/null +++ b/src/lgfx/v1/LGFX_Button.hpp @@ -0,0 +1,100 @@ +/*----------------------------------------------------------------------------/ + Lovyan GFX - Graphics library for embedded devices. + +Original Source: + https://github.com/lovyan03/LovyanGFX/ + +Licence: + [FreeBSD](https://github.com/lovyan03/LovyanGFX/blob/master/license.txt) + +Author: + [lovyan03](https://twitter.com/lovyan03) + +Contributors: + [ciniml](https://github.com/ciniml) + [mongonta0716](https://github.com/mongonta0716) + [tobozo](https://github.com/tobozo) +/----------------------------------------------------------------------------*/ +#pragma once + +#include "misc/colortype.hpp" +#include "misc/enum.hpp" + +namespace lgfx +{ + inline namespace v1 + { +//---------------------------------------------------------------------------- + + class LovyanGFX; + + class LGFX_Button + { + public: + template + void initButton( LovyanGFX *gfx, int16_t x, int16_t y, uint16_t w, uint16_t h + , const T& outline, const T& fill, const T& textcolor, const char *label, float textsize_x = 1.0f, float textsize_y = 0.0f) + { + _outlinecolor = lgfx::convert_to_rgb888(outline); + _fillcolor = lgfx::convert_to_rgb888(fill); + _textcolor = lgfx::convert_to_rgb888(textcolor); + _init_button(gfx, x-(w>>1), y-(h>>1), w, h, label, textsize_x, textsize_y); + } + + template + void initButtonUL( LovyanGFX *gfx, int16_t x, int16_t y, uint16_t w, uint16_t h + , const T& outline, const T& fill, const T& textcolor, const char *label, float textsize_x = 1.0f, float textsize_y = 0.0f) + { + _outlinecolor = lgfx::convert_to_rgb888(outline); + _fillcolor = lgfx::convert_to_rgb888(fill); + _textcolor = lgfx::convert_to_rgb888(textcolor); + _init_button(gfx, x, y, w, h, label, textsize_x, textsize_y); + } + + void setLabelDatum(int16_t x_delta, int16_t y_delta, textdatum_t datum = middle_center); + + void drawButton(bool inverted = false, const char* long_name = nullptr); + + bool contains(int16_t x, int16_t y) const + { + return (uint_fast16_t)(x - _x) < _w && (uint_fast16_t)(y - _y) < _h; + } + + void press(bool p) + { + _last_press = _pressed; + _pressed = p; + } + bool isPressed(void) const { return _pressed; } + bool justPressed(void) const { return (_pressed && !_last_press); } + bool justReleased(void) const { return (!_pressed && _last_press); } + + typedef void (*drawCb)( LovyanGFX *_gfx, int32_t x, int32_t y, int32_t w, int32_t h, bool invert, const char* long_name ); + void setDrawCb(drawCb cb) { _drawCb=cb; }; + + private: + void _init_button( LovyanGFX *gfx, int16_t x, int16_t y, uint16_t w, uint16_t h + , const char *label, float textsize_x, float textsize_y); + + LovyanGFX *_gfx = nullptr; + drawCb _drawCb = nullptr; + int16_t _x = 0; // Coordinates of top-left corner of button + int16_t _y = 0; // Coordinates of top-left corner of button + int16_t _xd = 0; // Button text datum offsets (wrt centre of button) + int16_t _yd = 0; // Button text datum offsets (wrt centre of button) + uint16_t _w = 0; // Width and height of button + uint16_t _h = 0; // Width and height of button + uint32_t _outlinecolor = 0xFFFFFF; + uint32_t _fillcolor = 0; + uint32_t _textcolor = 0xFFFFFF; + textdatum_t _textdatum = middle_center; // Text size multiplier and text datum for button + char _label[12]; // Button text is 11 chars maximum unless long_name used + float _textsize_x, _textsize_y; + bool _pressed, _last_press; // Button states + }; + +//---------------------------------------------------------------------------- + } +} + +using LGFX_Button = lgfx::LGFX_Button; diff --git a/src/lgfx/v1/LGFX_Sprite.cpp b/src/lgfx/v1/LGFX_Sprite.cpp index e39c103..a321009 100644 --- a/src/lgfx/v1/LGFX_Sprite.cpp +++ b/src/lgfx/v1/LGFX_Sprite.cpp @@ -24,27 +24,33 @@ namespace lgfx { //---------------------------------------------------------------------------- - static void memset_multi(std::uint8_t* buf, std::uint32_t c, std::size_t size, std::size_t length) + static void memset_multi(uint8_t* buf, uint32_t c, size_t size, size_t length) { - std::size_t l = length; + if (size == 1 || ((c & 0xFF) == ((c >> 8) & 0xFF) && (size == 2 || ((c & 0xFF) == ((c >> 16) & 0xFF))))) + { + memset(buf, c, size * length); + return; + } + + size_t l = length; if (l & ~0xF) { while ((l >>= 1) & ~0xF); ++l; } - std::size_t len = l * size; + size_t len = l * size; length = (length * size) - len; - std::uint8_t* dst = buf; + uint8_t* dst = buf; if (size == 2) { do { // 2byte speed tweak - *(std::uint16_t*)dst = c; + *(uint16_t*)dst = c; dst += 2; } while (--l); } else { do { - std::size_t i = 0; + size_t i = 0; do { - *dst++ = *(((std::uint8_t*)&c) + i); + *dst++ = *(((uint8_t*)&c) + i); } while (++i != size); } while (--l); } @@ -60,12 +66,12 @@ namespace lgfx } } - void Panel_Sprite::setBuffer(void* buffer, std::int32_t w, std::int32_t h, color_conv_t* conv) + void Panel_Sprite::setBuffer(void* buffer, int32_t w, int32_t h, color_conv_t* conv) { deleteSprite(); _img.reset(buffer); - _bitwidth = (w + conv->x_mask) & (~(std::uint32_t)conv->x_mask); + _bitwidth = (w + conv->x_mask) & (~(uint32_t)conv->x_mask); _panel_width = w; _xe = w - 1; _panel_height = h; @@ -81,19 +87,19 @@ namespace lgfx _img.release(); } - void* Panel_Sprite::createSprite(std::int32_t w, std::int32_t h, color_conv_t* conv, bool psram) + void* Panel_Sprite::createSprite(int32_t w, int32_t h, color_conv_t* conv, bool psram) { if (w < 1 || h < 1) { deleteSprite(); return nullptr; } - if (!_img || (std::uint_fast16_t)w != _panel_width || (std::uint_fast16_t)h != _panel_height) + if (!_img || (uint_fast16_t)w != _panel_width || (uint_fast16_t)h != _panel_height) { _panel_width = w; _panel_height = h; - _bitwidth = (w + conv->x_mask) & (~(std::uint32_t)conv->x_mask); - std::size_t len = h * (_bitwidth * _write_bits >> 3) + 1; + _bitwidth = (w + conv->x_mask) & (~(uint32_t)conv->x_mask); + size_t len = h * (_bitwidth * _write_bits >> 3) + 1; _img.reset(len, psram ? AllocationSource::Psram : AllocationSource::Dma); @@ -119,7 +125,7 @@ namespace lgfx return depth; } - void Panel_Sprite::setRotation(std::uint_fast8_t r) + void Panel_Sprite::setRotation(uint_fast8_t r) { r &= 7; _rotation = r; @@ -137,12 +143,12 @@ namespace lgfx _ys = 0; } - void Panel_Sprite::setWindow(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) + void Panel_Sprite::setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye) { - xs = std::max(0u, std::min(_width - 1, xs)); - xe = std::max(0u, std::min(_width - 1, xe)); - ys = std::max(0u, std::min(_height - 1, ys)); - ye = std::max(0u, std::min(_height - 1, ye)); + xs = std::max(0u, std::min(_width - 1, xs)); + xe = std::max(0u, std::min(_width - 1, xe)); + ys = std::max(0u, std::min(_height - 1, ys)); + ye = std::max(0u, std::min(_height - 1, ye)); _xpos = xs; _xs = xs; _xe = xe; @@ -151,9 +157,9 @@ namespace lgfx _ye = ye; } - void Panel_Sprite::drawPixelPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t rawcolor) + void Panel_Sprite::drawPixelPreclipped(uint_fast16_t x, uint_fast16_t y, uint32_t rawcolor) { - std::uint_fast8_t r = _rotation; + uint_fast8_t r = _rotation; if (r) { if ((1u << r) & 0b10010110) { y = _height - (y + 1); } @@ -161,7 +167,7 @@ namespace lgfx if (r & 1) { std::swap(x, y); } } auto bits = _write_bits; - std::uint32_t index = x + y * _bitwidth; + uint32_t index = x + y * _bitwidth; if (bits >= 8) { if (bits == 8) @@ -180,15 +186,15 @@ namespace lgfx else { index *= bits; - std::uint8_t* dst = &_img.img8()[index >> 3]; - std::uint8_t mask = (std::uint8_t)(~(0xFF >> bits)) >> (index & 7); + uint8_t* dst = &_img.img8()[index >> 3]; + uint8_t mask = (uint8_t)(~(0xFF >> bits)) >> (index & 7); *dst = (*dst & ~mask) | (rawcolor & mask); } } - void Panel_Sprite::writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) + void Panel_Sprite::writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t rawcolor) { - std::uint_fast8_t r = _rotation; + uint_fast8_t r = _rotation; if (r) { if ((1u << r) & 0b10010110) { y = _height - (y + h); } @@ -196,70 +202,46 @@ namespace lgfx if (r & 1) { std::swap(x, y); std::swap(w, h); } } - std::uint_fast8_t bits = _write_bits; + uint_fast8_t bits = _write_bits; if (bits >= 8) { if (w > 1) { - std::uint_fast8_t bytes = bits >> 3; - std::uint32_t bw = _bitwidth; - std::uint8_t* dst = &_img[(x + y * bw) * bytes]; - std::uint8_t c = rawcolor; - if (bytes == 1 || (c == ((rawcolor >> 8) & 0xFF) && (bytes == 2 || (c == ((rawcolor >> 16) & 0xFF))))) + uint_fast8_t bytes = bits >> 3; + uint_fast16_t bw = _bitwidth; + uint8_t* dst = &_img[(x + y * bw) * bytes]; + uint8_t* src = dst; + uint_fast16_t add_dst = bw * bytes; + uint_fast16_t len = w * bytes; + + if (_img.use_memcpy()) { - if (w == bw) + if (w != bw) { - memset(dst, rawcolor, w * bytes * h); + dst += add_dst; } else { - std::uint32_t add_dst = bw * bytes; - do - { - memset(dst, c, w * bytes); - dst += add_dst; - } while (--h); + w *= h; + h = 1; } } else { - std::size_t len = w * bytes; - std::uint32_t add_dst = bw * bytes; - - if (_img.use_memcpy() && (w == bw || h == 1)) - { -// if (w == bw) - { - memset_multi(dst, rawcolor, bytes, w * h); - } -/* - else - { - memset_multi(dst, rawcolor, bytes, w); - while (--h) - { - memcpy(dst + add_dst, dst, len); - dst += add_dst; - } - } -//*/ - } - else - { - std::uint8_t linebuf[len]; - memset_multi(linebuf, rawcolor, bytes, w); - do - { - memcpy(dst, linebuf, len); - dst += add_dst; - } while (--h); - } + src = (uint8_t*)alloca(len); + ++h; + } + memset_multi(src, rawcolor, bytes, w); + while (--h) + { + memcpy(dst, src, len); + dst += add_dst; } } else { - std::uint_fast16_t bw = _bitwidth; - std::uint32_t index = x + y * bw; + uint_fast16_t bw = _bitwidth; + uint32_t index = x + y * bw; if (bits == 8) { auto img = &_img[index]; @@ -271,11 +253,9 @@ namespace lgfx do { *img = rawcolor; img += bw; } while (--h); } else - { // if (_write_conv.bytes == 3) - //auto c = _color; + { auto img = &_img.img24()[index]; do { *img = rawcolor; img += bw; } while (--h); - //do { img->r = c.raw0; img->g = c.raw1; img->b = c.raw2; img += bw; } while (--h); } } } @@ -283,17 +263,17 @@ namespace lgfx { x *= bits; w *= bits; - std::size_t add_dst = _bitwidth * bits >> 3; - std::uint8_t* dst = &_img[y * add_dst + (x >> 3)]; - std::uint32_t len = ((x + w) >> 3) - (x >> 3); - std::uint8_t mask = 0xFF >> (x & 7); + uint32_t add_dst = _bitwidth * bits >> 3; + uint8_t* dst = &_img[y * add_dst + (x >> 3)]; + uint32_t len = ((x + w) >> 3) - (x >> 3); + uint8_t mask = 0xFF >> (x & 7); if (len) { if (mask != 0xFF) { --len; auto d = dst++; - std::uint8_t mc = rawcolor & mask; + uint8_t mc = rawcolor & mask; auto i = h; do { *d = (*d & ~mask) | mc; d += add_dst; } while (--i); } @@ -316,15 +296,15 @@ namespace lgfx } } - void Panel_Sprite::writeBlock(std::uint32_t rawcolor, std::uint32_t length) + void Panel_Sprite::writeBlock(uint32_t rawcolor, uint32_t length) { do { - std::uint32_t h = 1; - auto w = std::min(length, _xe + 1 - _xpos); + uint32_t h = 1; + auto w = std::min(length, _xe + 1 - _xpos); if (length >= (w << 1) && _xpos == _xs) { - h = std::min(length / w, _ye + 1 - _ypos); + h = std::min(length / w, _ye + 1 - _ypos); } writeFillRectPreclipped(_xpos, _ypos, w, h, rawcolor); if ((_xpos += w) <= _xe) return; @@ -334,12 +314,12 @@ namespace lgfx } while (length); } - void Panel_Sprite::_rotate_pixelcopy(std::uint_fast16_t& x, std::uint_fast16_t& y, std::uint_fast16_t& w, std::uint_fast16_t& h, pixelcopy_t* param, std::uint32_t& nextx, std::uint32_t& nexty) + void Panel_Sprite::_rotate_pixelcopy(uint_fast16_t& x, uint_fast16_t& y, uint_fast16_t& w, uint_fast16_t& h, pixelcopy_t* param, uint32_t& nextx, uint32_t& nexty) { - std::uint32_t addx = param->src_x32_add; - std::uint32_t addy = param->src_y32_add; - std::uint_fast8_t r = _rotation; - std::uint_fast8_t bitr = 1u << r; + uint32_t addx = param->src_x32_add; + uint32_t addy = param->src_y32_add; + uint_fast8_t r = _rotation; + uint_fast8_t bitr = 1u << r; // if (bitr & 0b10011100) // { // nextx = -nextx; @@ -369,23 +349,24 @@ namespace lgfx param->src_y32_add = addy; } - void Panel_Sprite::writePixels(pixelcopy_t* param, std::uint32_t length, bool use_dma) + void Panel_Sprite::writePixels(pixelcopy_t* param, uint32_t length, bool use_dma) { - std::uint_fast16_t xs = _xs; - std::uint_fast16_t xe = _xe; - std::uint_fast16_t ys = _ys; - std::uint_fast16_t ye = _ye; - std::uint_fast16_t x = _xpos; - std::uint_fast16_t y = _ypos; - const std::size_t bits = _write_bits; + (void)use_dma; + uint_fast16_t xs = _xs; + uint_fast16_t xe = _xe; + uint_fast16_t ys = _ys; + uint_fast16_t ye = _ye; + uint_fast16_t x = _xpos; + uint_fast16_t y = _ypos; + const size_t bits = _write_bits; auto k = _bitwidth * bits >> 3; - std::uint_fast8_t r = _rotation; + uint_fast8_t r = _rotation; if (!r) { - std::uint_fast16_t linelength; + uint_fast16_t linelength; do { - linelength = std::min(xe - x + 1, length); + linelength = std::min(xe - x + 1, length); param->fp_copy(&_img.img8()[y * k], x, x + linelength, param); if ((x += linelength) > xe) { @@ -398,22 +379,22 @@ namespace lgfx return; } - std::int_fast16_t ax = 1; - std::int_fast16_t ay = 1; + int_fast16_t ax = 1; + int_fast16_t ay = 1; if ((1u << r) & 0b10010110) { y = _height - (y + 1); ys = _height - (ys + 1); ye = _height - (ye + 1); ay = -1; } if (r & 2) { x = _width - (x + 1); xs = _width - (xs + 1); xe = _width - (xe + 1); ax = -1; } if (param->no_convert) { - std::size_t bytes = bits >> 3; - std::size_t xw = 1; - std::size_t yw = _bitwidth; + size_t bytes = bits >> 3; + size_t xw = 1; + size_t yw = _bitwidth; if (r & 1) std::swap(xw, yw); - std::size_t idx = y * yw + x * xw; - auto data = (std::uint8_t*)param->src_data; + size_t idx = y * yw + x * xw; + auto data = (uint8_t*)param->src_data; do { auto dst = &_img.img8()[idx * bytes]; - std::size_t b = 0; + size_t b = 0; do { dst[b] = *data++; @@ -472,22 +453,27 @@ namespace lgfx _ypos = y; } - void Panel_Sprite::writeImage(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param, bool) + void Panel_Sprite::writeImage(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param, bool) { - std::uint_fast8_t r = _rotation; + uint_fast8_t r = _rotation; if (r == 0 && param->transp == pixelcopy_t::NON_TRANSP && param->no_convert && _img.use_memcpy()) { auto sx = param->src_x; auto bits = param->src_bits; - std::uint_fast8_t mask = (bits == 1) ? 7 - : (bits == 2) ? 3 - : 1; - if (0 == (bits & 7) || ((sx & mask) == (x & mask) && (w == this->_panel_width || 0 == (w & mask)))) + bool flg_memcpy = (0 == (bits & 7)); + if (!flg_memcpy) + { + uint_fast8_t mask = (bits == 1) ? 7 + : (bits == 2) ? 3 + : 1; + flg_memcpy = (sx & mask) == (x & mask) && (w == this->_panel_width || 0 == (w & mask)); + } + if (flg_memcpy) { auto bw = _bitwidth * bits >> 3; auto dst = &_img[bw * y]; auto sw = param->src_bitwidth * bits >> 3; - auto src = &((std::uint8_t*)param->src_data)[param->src_y * sw]; + auto src = &((uint8_t*)param->src_data)[param->src_y * sw]; if (sw == bw && this->_panel_width == w && sx == 0 && x == 0) { memcpy(dst, src, bw * h); @@ -505,20 +491,20 @@ namespace lgfx } } - std::uint32_t nextx = 0; - std::uint32_t nexty = 1 << pixelcopy_t::FP_SCALE; + uint32_t nextx = 0; + uint32_t nexty = 1 << pixelcopy_t::FP_SCALE; if (r) { _rotate_pixelcopy(x, y, w, h, param, nextx, nexty); } - std::uint32_t sx32 = param->src_x32; - std::uint32_t sy32 = param->src_y32; + uint32_t sx32 = param->src_x32; + uint32_t sy32 = param->src_y32; y *= _bitwidth; do { - std::int32_t pos = x + y; - std::int32_t end = pos + w; + int32_t pos = x + y; + int32_t end = pos + w; while (end != (pos = param->fp_copy(_img, pos, end, param)) && end != (pos = param->fp_skip( pos, end, param))); param->src_x32 = (sx32 += nextx); @@ -527,19 +513,19 @@ namespace lgfx } while (--h); } - void Panel_Sprite::writeImageARGB(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param) + void Panel_Sprite::writeImageARGB(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param) { - std::uint32_t nextx = 0; - std::uint32_t nexty = 1 << pixelcopy_t::FP_SCALE; + uint32_t nextx = 0; + uint32_t nexty = 1 << pixelcopy_t::FP_SCALE; if (_rotation) { _rotate_pixelcopy(x, y, w, h, param, nextx, nexty); } - std::uint32_t sx32 = param->src_x32; - std::uint32_t sy32 = param->src_y32; + uint32_t sx32 = param->src_x32; + uint32_t sy32 = param->src_y32; - std::uint32_t pos = x + y * _bitwidth; - std::uint32_t end = pos + w; + uint32_t pos = x + y * _bitwidth; + uint32_t end = pos + w; param->fp_copy(_img, pos, end, param); while (--h) { @@ -551,9 +537,9 @@ namespace lgfx } } - std::uint32_t Panel_Sprite::readPixelValue(std::uint_fast16_t x, std::uint_fast16_t y) + uint32_t Panel_Sprite::readPixelValue(uint_fast16_t x, uint_fast16_t y) { - std::uint_fast8_t r = _rotation; + uint_fast8_t r = _rotation; if (r) { if ((1u << r) & 0b10010110) { y = _height - (y + 1); } @@ -562,7 +548,7 @@ namespace lgfx } if (x >= _panel_width || y >= _panel_height) return 0; - std::size_t index = x + y * _bitwidth; + size_t index = x + y * _bitwidth; auto bits = _read_bits; if (bits >= 8) { @@ -574,22 +560,22 @@ namespace lgfx { return _img.img16()[index]; } - return (std::uint32_t)_img.img24()[index]; + return (uint32_t)_img.img24()[index]; } index *= bits; - std::uint8_t mask = (1 << bits) - 1; + uint8_t mask = (1 << bits) - 1; return (_img.img8()[index >> 3] >> (-(index + bits) & 7)) & mask; } - void Panel_Sprite::readRect(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, void* dst, pixelcopy_t* param) + void Panel_Sprite::readRect(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, void* dst, pixelcopy_t* param) { - std::uint_fast8_t r = _rotation; + uint_fast8_t r = _rotation; if (0 == r && param->no_convert && _write_bits >= 8) { h += y; auto bytes = _write_bits >> 3; auto bw = _bitwidth; - auto d = (std::uint8_t*)dst; + auto d = (uint8_t*)dst; do { memcpy(d, &_img[(x + y * bw) * bytes], w * bytes); d += w * bytes; @@ -599,13 +585,13 @@ namespace lgfx { param->src_bitwidth = _bitwidth; param->src_data = _img; - std::uint32_t nextx = 0; - std::uint32_t nexty = 1 << pixelcopy_t::FP_SCALE; + uint32_t nextx = 0; + uint32_t nexty = 1 << pixelcopy_t::FP_SCALE; if (r) { - std::uint32_t addx = param->src_x32_add; - std::uint32_t addy = param->src_y32_add; - std::uint_fast8_t rb = 1 << r; + uint32_t addx = param->src_x32_add; + uint32_t addy = param->src_y32_add; + uint_fast8_t rb = 1 << r; if (rb & 0b10010110) // case 1:2:4:7: { nexty = -nexty; @@ -629,9 +615,9 @@ namespace lgfx param->src_x32_add = addx; param->src_y32_add = addy; } - std::size_t dstindex = 0; - std::uint32_t x32 = x << pixelcopy_t::FP_SCALE; - std::uint32_t y32 = y << pixelcopy_t::FP_SCALE; + size_t dstindex = 0; + uint32_t x32 = x << pixelcopy_t::FP_SCALE; + uint32_t y32 = y << pixelcopy_t::FP_SCALE; param->src_x32 = x32; param->src_y32 = y32; do @@ -645,9 +631,9 @@ namespace lgfx } } - void Panel_Sprite::copyRect(std::uint_fast16_t dst_x, std::uint_fast16_t dst_y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint_fast16_t src_x, std::uint_fast16_t src_y) + void Panel_Sprite::copyRect(uint_fast16_t dst_x, uint_fast16_t dst_y, uint_fast16_t w, uint_fast16_t h, uint_fast16_t src_x, uint_fast16_t src_y) { - std::uint_fast8_t r = _rotation; + uint_fast8_t r = _rotation; if (r) { if ((1u << r) & 0b10010110) { src_y = _height - (src_y + h); dst_y = _height - (dst_y + h); } @@ -658,7 +644,7 @@ namespace lgfx if (_write_bits < 8) { pixelcopy_t param(_img, _write_depth, _write_depth); param.src_bitwidth = _bitwidth; - std::int32_t add_y = (src_y < dst_y) ? -1 : 1; + int32_t add_y = (src_y < dst_y) ? -1 : 1; if (src_y != dst_y) { if (src_y < dst_y) { src_y += h - 1; @@ -674,8 +660,8 @@ namespace lgfx param.src_y += add_y; } while (--h); } else { - std::size_t len = (_bitwidth * _write_bits) >> 3; - std::uint8_t buf[len]; + size_t len = (_bitwidth * _write_bits) >> 3; + auto buf = (uint8_t*)alloca(len); param.src_data = buf; param.src_y32 = 0; do { @@ -690,13 +676,13 @@ namespace lgfx } else { - std::size_t bytes = _write_bits >> 3; - std::size_t len = w * bytes; - std::int32_t add = _bitwidth * bytes; + size_t bytes = _write_bits >> 3; + size_t len = w * bytes; + int32_t add = _bitwidth * bytes; if (src_y < dst_y) add = -add; - std::int32_t pos = (src_y < dst_y) ? h - 1 : 0; - std::uint8_t* src = &_img.img8()[(src_x + (src_y + pos) * _bitwidth) * bytes]; - std::uint8_t* dst = &_img.img8()[(dst_x + (dst_y + pos) * _bitwidth) * bytes]; + int32_t pos = (src_y < dst_y) ? h - 1 : 0; + uint8_t* src = &_img.img8()[(src_x + (src_y + pos) * _bitwidth) * bytes]; + uint8_t* dst = &_img.img8()[(dst_x + (dst_y + pos) * _bitwidth) * bytes]; if (_img.use_memcpy()) { do @@ -708,7 +694,7 @@ namespace lgfx } else { - std::uint8_t buf[len]; + auto buf = (uint8_t*)alloca(len); do { memcpy(buf, src, len); diff --git a/src/lgfx/v1/LGFX_Sprite.hpp b/src/lgfx/v1/LGFX_Sprite.hpp index a61dd6a..9d51e82 100644 --- a/src/lgfx/v1/LGFX_Sprite.hpp +++ b/src/lgfx/v1/LGFX_Sprite.hpp @@ -17,8 +17,7 @@ Original Source: /----------------------------------------------------------------------------*/ #pragma once -#include -#include +#include #include "LGFXBase.hpp" #include "misc/SpriteBuffer.hpp" @@ -40,59 +39,59 @@ namespace lgfx void beginTransaction(void) override {} void endTransaction(void) override {} - void setInvert(bool invert) override {} - void setSleep(bool flg_sleep) override {} - void setPowerSave(bool flg_partial) override {} - void writeCommand(std::uint32_t cmd, std::uint_fast8_t length) override {} - void writeData(std::uint32_t data, std::uint_fast8_t length) override {} + void setInvert(bool) override {} + void setSleep(bool) override {} + void setPowerSave(bool) override {} + void writeCommand(uint32_t, uint_fast8_t) override {} + void writeData(uint32_t, uint_fast8_t) override {} void initDMA(void) override {} void waitDMA(void) override {} bool dmaBusy(void) override { return false; } void waitDisplay(void) override {} bool displayBusy(void) override { return false; } - void display(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h) override {} + void display(uint_fast16_t, uint_fast16_t, uint_fast16_t, uint_fast16_t) override {} bool isReadable(void) const override { return true; } bool isBusShared(void) const override { return false; } - std::uint32_t readCommand(std::uint_fast8_t cmd, std::uint_fast8_t index = 0, std::uint_fast8_t length = 4) override { return 0; } - std::uint32_t readData(std::uint_fast8_t index = 0, std::uint_fast8_t length = 4) override { return 0; } + uint32_t readCommand(uint_fast8_t, uint_fast8_t, uint_fast8_t) override { return 0; } + uint32_t readData(uint_fast8_t, uint_fast8_t) override { return 0; } - void setBuffer(void* buffer, std::int32_t w, std::int32_t h, color_conv_t* conv); + void setBuffer(void* buffer, int32_t w, int32_t h, color_conv_t* conv); void deleteSprite(void); - void* createSprite(std::int32_t w, std::int32_t h, color_conv_t* conv, bool psram); + void* createSprite(int32_t w, int32_t h, color_conv_t* conv, bool psram); __attribute__ ((always_inline)) inline void* getBuffer(void) const { return _img.get(); } __attribute__ ((always_inline)) inline const SpriteBuffer* getSpriteBuffer(void) const { return &_img; } - __attribute__ ((always_inline)) inline std::uint32_t bufferLength(void) const { return (_bitwidth * _write_bits >> 3) * _panel_height; } + __attribute__ ((always_inline)) inline uint32_t bufferLength(void) const { return (_bitwidth * _write_bits >> 3) * _panel_height; } color_depth_t setColorDepth(color_depth_t depth) override; - void setRotation(std::uint_fast8_t r) override; + void setRotation(uint_fast8_t r) override; - void setWindow(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) override; - void drawPixelPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t rawcolor) override; - void writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t raw_color) override; - void writeBlock(std::uint32_t rawcolor, std::uint32_t len) override; - void writePixels(pixelcopy_t* param, std::uint32_t len, bool use_dma) override; - void writeImage(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param, bool) override; - void writeImageARGB(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param) override; + void setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye) override; + void drawPixelPreclipped(uint_fast16_t x, uint_fast16_t y, uint32_t rawcolor) override; + void writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t raw_color) override; + void writeBlock(uint32_t rawcolor, uint32_t len) override; + void writePixels(pixelcopy_t* param, uint32_t len, bool use_dma) override; + void writeImage(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param, bool) override; + void writeImageARGB(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param) override; - void readRect(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, void* dst, pixelcopy_t* param) override; - void copyRect(std::uint_fast16_t dst_x, std::uint_fast16_t dst_y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint_fast16_t src_x, std::uint_fast16_t src_y) override; + void readRect(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, void* dst, pixelcopy_t* param) override; + void copyRect(uint_fast16_t dst_x, uint_fast16_t dst_y, uint_fast16_t w, uint_fast16_t h, uint_fast16_t src_x, uint_fast16_t src_y) override; - std::uint32_t readPixelValue(std::uint_fast16_t x, std::uint_fast16_t y); + uint32_t readPixelValue(uint_fast16_t x, uint_fast16_t y); protected: - void _rotate_pixelcopy(std::uint_fast16_t& x, std::uint_fast16_t& y, std::uint_fast16_t& w, std::uint_fast16_t& h, pixelcopy_t* param, std::uint32_t& nextx, std::uint32_t& nexty); + void _rotate_pixelcopy(uint_fast16_t& x, uint_fast16_t& y, uint_fast16_t& w, uint_fast16_t& h, pixelcopy_t* param, uint32_t& nextx, uint32_t& nexty); SpriteBuffer _img; - std::uint_fast16_t _xpos; - std::uint_fast16_t _ypos; - std::uint_fast16_t _panel_width; // rotationしていない状態の幅 - std::uint_fast16_t _panel_height; // rotationしていない状態の高さ - std::uint_fast16_t _bitwidth; + uint_fast16_t _xpos; + uint_fast16_t _ypos; + uint_fast16_t _panel_width; // rotationしていない状態の幅 + uint_fast16_t _panel_height; // rotationしていない状態の高さ + uint_fast16_t _bitwidth; }; class LGFX_Sprite : public LovyanGFX @@ -109,7 +108,7 @@ namespace lgfx } __attribute__ ((always_inline)) inline void* getBuffer(void) const { return _panel_sprite.getBuffer(); } - std::uint32_t bufferLength(void) const { return _panel_sprite.bufferLength(); } + uint32_t bufferLength(void) const { return _panel_sprite.bufferLength(); } LGFX_Sprite() : LGFX_Sprite(nullptr) @@ -145,7 +144,7 @@ namespace lgfx deleteSprite(); } - void setBuffer(void* buffer, std::int32_t w, std::int32_t h, std::uint8_t bpp = 0) + void setBuffer(void* buffer, int32_t w, int32_t h, uint8_t bpp = 0) { deleteSprite(); if (bpp != 0) _write_conv.setColorDepth((color_depth_t)bpp, hasPalette()); @@ -153,7 +152,7 @@ namespace lgfx _panel_sprite.setBuffer(buffer, w, h, &_write_conv); _img = _panel_sprite.getBuffer(); -// _bitwidth = (w + _write_conv.x_mask) & (~(std::uint32_t)_write_conv.x_mask); +// _bitwidth = (w + _write_conv.x_mask) & (~(uint32_t)_write_conv.x_mask); _sw = w; _clip_r = w - 1; _xpivot = w >> 1; @@ -163,7 +162,7 @@ namespace lgfx _ypivot = h >> 1; } - void* createSprite(std::int32_t w, std::int32_t h) + void* createSprite(int32_t w, int32_t h) { _img = _panel_sprite.createSprite(w, h, &_write_conv, _psram); if (_img) { @@ -172,7 +171,7 @@ namespace lgfx createPalette(); } } -// _bitwidth = (w + _write_conv.x_mask) & (~(std::uint32_t)_write_conv.x_mask); +// _bitwidth = (w + _write_conv.x_mask) & (~(uint32_t)_write_conv.x_mask); setRotation(getRotation()); _sw = width(); @@ -221,7 +220,7 @@ namespace lgfx #endif - void createFromBmp(const std::uint8_t *bmp_data, std::uint32_t bmp_len = ~0u) { + void createFromBmp(const uint8_t *bmp_data, uint32_t bmp_len = ~0u) { PointerWrapper data; data.set(bmp_data, bmp_len); create_from_bmp(&data); @@ -235,26 +234,26 @@ namespace lgfx return true; } - // create palette from RGB565(std::uint16_t) array - bool createPalette(const std::uint16_t* colors, std::uint32_t count) + // create palette from RGB565(uint16_t) array + bool createPalette(const uint16_t* colors, uint32_t count) { if (!create_palette()) return false; if (count > _palette_count) count = _palette_count; - for (std::uint32_t i = 0; i < count; ++i) { - _palette.img24()[i] = convert_rgb565_to_bgr888(colors[i]); + for (uint32_t i = 0; i < count; ++i) { + _palette.img24()[i] = color_convert(colors[i]); } return true; } - // create palette from RGB888(std::uint32_t) array - bool createPalette(const std::uint32_t* colors, std::uint32_t count) + // create palette from RGB888(uint32_t) array + bool createPalette(const uint32_t* colors, uint32_t count) { if (!create_palette()) return false; if (count > _palette_count) count = _palette_count; - for (std::uint32_t i = 0; i < count; ++i) { - _palette.img24()[i] = convert_rgb888_to_bgr888(colors[i]); + for (uint32_t i = 0; i < count; ++i) { + _palette.img24()[i] = color_convert(colors[i]); } return true; } @@ -262,7 +261,7 @@ namespace lgfx void setPaletteGrayscale(void) { if (!_palette) return; - std::uint32_t k; + uint32_t k; switch (_write_conv.bits) { case 8: k = 0x010101; break; case 4: k = 0x111111; break; @@ -270,28 +269,28 @@ namespace lgfx case 1: k = 0xFFFFFF; break; default: k = 1; break; } - for (std::uint32_t i = 0; i < _palette_count; i++) { + for (uint32_t i = 0; i < _palette_count; i++) { _palette.img24()[i] = i * k; } } - void setBitmapColor(std::uint16_t fgcolor, std::uint16_t bgcolor) // For 1bpp sprites + void setBitmapColor(uint16_t fgcolor, uint16_t bgcolor) // For 1bpp sprites { if (_palette) { - _palette.img24()[0] = *(rgb565_t*)&bgcolor; - _palette.img24()[1] = *(rgb565_t*)&fgcolor; + _palette.img24()[0].set(color_convert(bgcolor)); + _palette.img24()[1].set(color_convert(fgcolor)); } } - template inline std::int32_t getPaletteIndex(const T& color) + template inline int32_t getPaletteIndex(const T& color) { - std::uint32_t rgb = convert_to_rgb888(color); - bgr888_t bgr((std::uint8_t)(rgb >> 16), (std::uint8_t)(rgb >> 8), (std::uint8_t)rgb); + uint32_t rgb = convert_to_rgb888(color); + bgr888_t bgr((uint8_t)(rgb >> 16), (uint8_t)(rgb >> 8), (uint8_t)rgb); return getPaletteIndex(bgr); } - std::int32_t getPaletteIndex(const bgr888_t& color) + int32_t getPaletteIndex(const bgr888_t& color) { - std::size_t res = 0; + size_t res = 0; do { if (_palette.img24()[res] == color) return res; } while (++res < _palette_count); @@ -299,23 +298,23 @@ namespace lgfx } template __attribute__ ((always_inline)) inline - void setPaletteColor(std::size_t index, T color) { + void setPaletteColor(size_t index, T color) { if (!_palette || index >= _palette_count) return; rgb888_t c = convert_to_rgb888(color); _palette.img24()[index] = c; } - void setPaletteColor(std::size_t index, const bgr888_t& rgb) + void setPaletteColor(size_t index, const bgr888_t& rgb) { if (_palette && index < _palette_count) { _palette.img24()[index] = rgb; } } - void setPaletteColor(std::size_t index, std::uint8_t r, std::uint8_t g, std::uint8_t b) + void setPaletteColor(size_t index, uint8_t r, uint8_t g, uint8_t b) { if (_palette && index < _palette_count) { _palette.img24()[index].set(r, g, b); } } - __attribute__ ((always_inline)) inline void* setColorDepth(std::uint8_t bpp) { return setColorDepth((color_depth_t)bpp); } + __attribute__ ((always_inline)) inline void* setColorDepth(uint8_t bpp) { return setColorDepth((color_depth_t)bpp); } void* setColorDepth(color_depth_t depth) { _panel_sprite.setColorDepth(depth); @@ -331,17 +330,17 @@ namespace lgfx return createSprite(w, h); } - std::uint32_t readPixelValue(std::int32_t x, std::int32_t y) { return _panel_sprite.readPixelValue(x, y); } + uint32_t readPixelValue(int32_t x, int32_t y) { return _panel_sprite.readPixelValue(x, y); } template __attribute__ ((always_inline)) inline void fillSprite (const T& color) { fillScreen(color); } template - __attribute__ ((always_inline)) inline void pushSprite( std::int32_t x, std::int32_t y, const T& transp) { push_sprite(_parent, x, y, _write_conv.convert(transp) & _write_conv.colormask); } + __attribute__ ((always_inline)) inline void pushSprite( int32_t x, int32_t y, const T& transp) { push_sprite(_parent, x, y, _write_conv.convert(transp) & _write_conv.colormask); } template - __attribute__ ((always_inline)) inline void pushSprite(LovyanGFX* dst, std::int32_t x, std::int32_t y, const T& transp) { push_sprite( dst, x, y, _write_conv.convert(transp) & _write_conv.colormask); } - __attribute__ ((always_inline)) inline void pushSprite( std::int32_t x, std::int32_t y) { push_sprite(_parent, x, y); } - __attribute__ ((always_inline)) inline void pushSprite(LovyanGFX* dst, std::int32_t x, std::int32_t y) { push_sprite( dst, x, y); } + __attribute__ ((always_inline)) inline void pushSprite(LovyanGFX* dst, int32_t x, int32_t y, const T& transp) { push_sprite( dst, x, y, _write_conv.convert(transp) & _write_conv.colormask); } + __attribute__ ((always_inline)) inline void pushSprite( int32_t x, int32_t y) { push_sprite(_parent, x, y); } + __attribute__ ((always_inline)) inline void pushSprite(LovyanGFX* dst, int32_t x, int32_t y) { push_sprite( dst, x, y); } template void pushRotated( float angle, const T& transp) { push_rotate_zoom(_parent, _parent->getPivotX(), _parent->getPivotY(), angle, 1.0f, 1.0f, _write_conv.convert(transp) & _write_conv.colormask); } template void pushRotated(LovyanGFX* dst, float angle, const T& transp) { push_rotate_zoom(dst , dst ->getPivotX(), dst ->getPivotY(), angle, 1.0f, 1.0f, _write_conv.convert(transp) & _write_conv.colormask); } @@ -398,7 +397,7 @@ namespace lgfx LovyanGFX* _parent; SpriteBuffer _palette; -// std::int32_t _bitwidth; +// int32_t _bitwidth; bool _psram = false; @@ -408,7 +407,7 @@ namespace lgfx deletePalette(); - std::size_t palettes = 1 << _write_conv.bits; + size_t palettes = 1 << _write_conv.bits; _palette.reset(palettes * sizeof(bgr888_t), AllocationSource::Normal); if (!_palette) { _write_conv.setColorDepth(_write_conv.depth, false); @@ -435,28 +434,28 @@ namespace lgfx || ( bmpdata.biCompression > 3)) { return false; } - std::uint32_t seekOffset = bmpdata.bfOffBits; - std::uint_fast16_t bpp = bmpdata.biBitCount; // 24 bcBitCount 24=RGB24bit + uint32_t seekOffset = bmpdata.bfOffBits; + uint_fast16_t bpp = bmpdata.biBitCount; // 24 bcBitCount 24=RGB24bit setColorDepth(bpp); - std::int32_t w = bmpdata.biWidth; - std::int32_t h = bmpdata.biHeight; // bcHeight Image height (pixels) + int32_t w = bmpdata.biWidth; + int32_t h = bmpdata.biHeight; // bcHeight Image height (pixels) if (!createSprite(w, h)) return false; //If the value of Height is positive, the image data is from bottom to top //If the value of Height is negative, the image data is from top to bottom. - std::int32_t flow = (h < 0) ? 1 : -1; - std::int32_t y = 0; + int32_t flow = (h < 0) ? 1 : -1; + int32_t y = 0; if (h < 0) h = -h; else y = h - 1; if (bpp <= 8) { if (!_palette) createPalette(); - std::uint_fast16_t palettecount = 1 << bpp; + uint_fast16_t palettecount = 1 << bpp; argb8888_t *palette = new argb8888_t[palettecount]; data->seek(bmpdata.biSize + 14); - data->read((std::uint8_t*)palette, (palettecount * sizeof(argb8888_t))); // load palette - for (std::uint_fast16_t i = 0; i < _palette_count; ++i) { - _palette.img24()[i] = palette[i]; + data->read((uint8_t*)palette, (palettecount * sizeof(argb8888_t))); // load palette + for (uint_fast16_t i = 0; i < _palette_count; ++i) { + _palette.img24()[i].set(color_convert(palette[i].get())); } delete[] palette; } @@ -465,8 +464,8 @@ namespace lgfx auto bitwidth = _panel_sprite._bitwidth; - std::size_t buffersize = ((w * bpp + 31) >> 5) << 2; // readline 4Byte align. - std::uint8_t lineBuffer[buffersize]; // readline 4Byte align. + size_t buffersize = ((w * bpp + 31) >> 5) << 2; // readline 4Byte align. + auto lineBuffer = (uint8_t*)alloca(buffersize); if (bpp <= 8) { do { if (bmpdata.biCompression == 1) { @@ -485,7 +484,7 @@ namespace lgfx data->read(lineBuffer, buffersize); auto img = &_img8[y * bitwidth * bpp >> 3]; y += flow; - for (std::size_t i = 0; i < buffersize; ++i) { + for (size_t i = 0; i < buffersize; ++i) { img[i] = lineBuffer[i ^ 1]; } } while (--h); @@ -494,7 +493,7 @@ namespace lgfx data->read(lineBuffer, buffersize); auto img = &_img8[y * bitwidth * bpp >> 3]; y += flow; - for (std::size_t i = 0; i < buffersize; i += 3) { + for (size_t i = 0; i < buffersize; i += 3) { img[i ] = lineBuffer[i + 2]; img[i + 1] = lineBuffer[i + 1]; img[i + 2] = lineBuffer[i ]; @@ -505,7 +504,7 @@ namespace lgfx data->read(lineBuffer, buffersize); auto img = &_img8[y * bitwidth * 3]; y += flow; - for (std::size_t i = 0; i < buffersize; i += 4) { + for (size_t i = 0; i < buffersize; i += 4) { img[(i>>2)*3 ] = lineBuffer[i + 2]; img[(i>>2)*3 + 1] = lineBuffer[i + 1]; img[(i>>2)*3 + 2] = lineBuffer[i + 0]; @@ -515,28 +514,28 @@ namespace lgfx return true; } - void push_sprite(LovyanGFX* dst, std::int32_t x, std::int32_t y, std::uint32_t transp = pixelcopy_t::NON_TRANSP) + void push_sprite(LovyanGFX* dst, int32_t x, int32_t y, uint32_t transp = pixelcopy_t::NON_TRANSP) { pixelcopy_t p(_img, dst->getColorDepth(), getColorDepth(), dst->hasPalette(), _palette, transp); dst->pushImage(x, y, _panel_sprite._panel_width, _panel_sprite._panel_height, &p, _panel_sprite.getSpriteBuffer()->use_dma()); // DMA disable with use SPIRAM } - void push_rotate_zoom(LovyanGFX* dst, float x, float y, float angle, float zoom_x, float zoom_y, std::uint32_t transp = pixelcopy_t::NON_TRANSP) + void push_rotate_zoom(LovyanGFX* dst, float x, float y, float angle, float zoom_x, float zoom_y, uint32_t transp = pixelcopy_t::NON_TRANSP) { dst->pushImageRotateZoom(x, y, _xpivot, _ypivot, angle, zoom_x, zoom_y, _panel_sprite._panel_width, _panel_sprite._panel_height, _img, transp, getColorDepth(), _palette.img24()); } - void push_rotate_zoom_aa(LovyanGFX* dst, float x, float y, float angle, float zoom_x, float zoom_y, std::uint32_t transp = pixelcopy_t::NON_TRANSP) + void push_rotate_zoom_aa(LovyanGFX* dst, float x, float y, float angle, float zoom_x, float zoom_y, uint32_t transp = pixelcopy_t::NON_TRANSP) { dst->pushImageRotateZoomWithAA(x, y, _xpivot, _ypivot, angle, zoom_x, zoom_y, _panel_sprite._panel_width, _panel_sprite._panel_height, _img, transp, getColorDepth(), _palette.img24()); } - void push_affine(LovyanGFX* dst, float matrix[6], std::uint32_t transp = pixelcopy_t::NON_TRANSP) + void push_affine(LovyanGFX* dst, float matrix[6], uint32_t transp = pixelcopy_t::NON_TRANSP) { dst->pushImageAffine(matrix, _panel_sprite._panel_width, _panel_sprite._panel_height, _img, transp, getColorDepth(), _palette.img24()); } - void push_affine_aa(LovyanGFX* dst, float matrix[6], std::uint32_t transp = pixelcopy_t::NON_TRANSP) + void push_affine_aa(LovyanGFX* dst, float matrix[6], uint32_t transp = pixelcopy_t::NON_TRANSP) { dst->pushImageAffineWithAA(matrix, _panel_sprite._panel_width, _panel_sprite._panel_height, _img, transp, getColorDepth(), _palette.img24()); } diff --git a/src/lgfx/v1/Light.hpp b/src/lgfx/v1/Light.hpp index c9819c0..4be859f 100644 --- a/src/lgfx/v1/Light.hpp +++ b/src/lgfx/v1/Light.hpp @@ -17,7 +17,7 @@ Original Source: /----------------------------------------------------------------------------*/ #pragma once -#include +#include namespace lgfx { @@ -29,14 +29,14 @@ namespace lgfx { virtual ~ILight(void) = default; - virtual bool init(std::uint8_t brightness) = 0; - virtual void setBrightness(std::uint8_t brightness) = 0; + virtual bool init(uint8_t brightness) = 0; + virtual void setBrightness(uint8_t brightness) = 0; }; /* struct Light_NULL : public ILight { bool init(void) override {} - void setBrightness(std::uint8_t brightness) override {} + void setBrightness(uint8_t brightness) override {} }; //*/ //---------------------------------------------------------------------------- diff --git a/src/lgfx/v1/Panel.hpp b/src/lgfx/v1/Panel.hpp index 4ae4446..fe051a8 100644 --- a/src/lgfx/v1/Panel.hpp +++ b/src/lgfx/v1/Panel.hpp @@ -17,8 +17,8 @@ Original Source: /----------------------------------------------------------------------------*/ #pragma once -#include -#include +#include +#include #include "misc/enum.hpp" #include "misc/pixelcopy.hpp" @@ -34,18 +34,18 @@ namespace lgfx struct IPanel { protected: - std::uint32_t _start_count = 0; - std::uint16_t _xs = ~0; - std::uint16_t _xe = ~0; - std::uint16_t _ys = ~0; - std::uint16_t _ye = ~0; - std::uint16_t _width = 0; - std::uint16_t _height = 0; + uint32_t _start_count = 0; + uint16_t _xs = ~0; + uint16_t _xe = ~0; + uint16_t _ys = ~0; + uint16_t _ye = ~0; + uint16_t _width = 0; + uint16_t _height = 0; color_depth_t _write_depth = color_depth_t::rgb565_2Byte; color_depth_t _read_depth = color_depth_t::rgb565_2Byte; - std::uint8_t _write_bits = 16; - std::uint8_t _read_bits = 16; - std::uint8_t _rotation = 0; + uint8_t _write_bits = 16; + uint8_t _read_bits = 16; + uint8_t _rotation = 0; epd_mode_t _epd_mode = (epd_mode_t)0; // EPDでない場合は0。それ以外の場合はEPD描画モード bool _invert = false; bool _auto_display = false; @@ -56,14 +56,14 @@ namespace lgfx void startWrite(bool transaction = true) { if (1 == ++_start_count && transaction) { beginTransaction(); } } void endWrite(void) { if (_start_count) { if (0 == --_start_count) { if (_auto_display) { display(0,0,0,0); } endTransaction(); } } } - std::uint32_t getStartCount(void) const { return _start_count; } + uint32_t getStartCount(void) const { return _start_count; } color_depth_t getWriteDepth(void) const { return _write_depth; } color_depth_t getReadDepth(void) const { return _read_depth; } - std::uint8_t getRotation(void) const { return _rotation; } + uint8_t getRotation(void) const { return _rotation; } bool getInvert(void) const { return _invert; } - std::uint16_t width(void) const { return _width; } - std::uint16_t height(void) const { return _height; } + uint16_t width(void) const { return _width; } + uint16_t height(void) const { return _height; } epd_mode_t getEpdMode(void) const { return _epd_mode; } void setEpdMode(epd_mode_t epd_mode) { if (_epd_mode && epd_mode) _epd_mode = epd_mode; } bool isEpd(void) const { return _epd_mode; } @@ -73,57 +73,57 @@ namespace lgfx virtual void beginTransaction(void) = 0; virtual void endTransaction(void) = 0; - virtual void setBrightness(std::uint8_t brightness) {}; + virtual void setBrightness(__attribute__((unused)) uint8_t brightness) {}; virtual color_depth_t setColorDepth(color_depth_t depth) = 0; virtual void setInvert(bool invert) = 0; - virtual void setRotation(std::uint_fast8_t r) = 0; + virtual void setRotation(uint_fast8_t r) = 0; virtual void setSleep(bool flg_sleep) = 0; virtual void setPowerSave(bool flg_idle) = 0; - virtual void writeCommand(std::uint32_t cmd, std::uint_fast8_t length) = 0; - virtual void writeData(std::uint32_t data, std::uint_fast8_t length) = 0; + virtual void writeCommand(uint32_t cmd, uint_fast8_t length) = 0; + virtual void writeData(uint32_t data, uint_fast8_t length) = 0; virtual void initDMA(void) = 0; virtual void waitDMA(void) = 0; virtual bool dmaBusy(void) = 0; virtual void waitDisplay(void) = 0; virtual bool displayBusy(void) = 0; - virtual void display(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h) = 0; + virtual void display(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h) = 0; virtual bool isReadable(void) const = 0; virtual bool isBusShared(void) const = 0; - virtual void writeBlock(std::uint32_t rawcolor, std::uint32_t len) = 0; - virtual void setWindow(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) = 0; - virtual void drawPixelPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t rawcolor) = 0; - virtual void writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) = 0; - virtual void writeImage(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param, bool use_dma) = 0; - virtual void writeImageARGB(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param) = 0; - virtual void writePixels(pixelcopy_t* param, std::uint32_t len, bool use_dma) = 0; + virtual void writeBlock(uint32_t rawcolor, uint32_t len) = 0; + virtual void setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye) = 0; + virtual void drawPixelPreclipped(uint_fast16_t x, uint_fast16_t y, uint32_t rawcolor) = 0; + virtual void writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t rawcolor) = 0; + virtual void writeImage(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param, bool use_dma) = 0; + virtual void writeImageARGB(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param) = 0; + virtual void writePixels(pixelcopy_t* param, uint32_t len, bool use_dma) = 0; - virtual std::uint32_t readCommand(std::uint_fast8_t cmd, std::uint_fast8_t index = 0, std::uint_fast8_t length = 4) = 0; - virtual std::uint32_t readData(std::uint_fast8_t index = 0, std::uint_fast8_t length = 4) = 0; - virtual void readRect(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, void* dst, pixelcopy_t* param) = 0; - virtual void copyRect(std::uint_fast16_t dst_x, std::uint_fast16_t dst_y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint_fast16_t src_x, std::uint_fast16_t src_y) = 0; + virtual uint32_t readCommand(uint_fast8_t cmd, uint_fast8_t index = 0, uint_fast8_t length = 4) = 0; + virtual uint32_t readData(uint_fast8_t index = 0, uint_fast8_t length = 4) = 0; + virtual void readRect(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, void* dst, pixelcopy_t* param) = 0; + virtual void copyRect(uint_fast16_t dst_x, uint_fast16_t dst_y, uint_fast16_t w, uint_fast16_t h, uint_fast16_t src_x, uint_fast16_t src_y) = 0; - virtual void writeFillRectAlphaPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t argb8888) + virtual void writeFillRectAlphaPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t argb8888) { effect(x, y, w, h, effect_fill_alpha ( argb8888_t { argb8888 } ) ); } template - void effect(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, TFunc&& effector) + void effect(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, TFunc&& effector) { auto ye = y + h; - RGBColor buf[w]; + auto buf = (RGBColor*)alloca(w * sizeof(RGBColor)); pixelcopy_t pc_write(buf ,_write_depth, RGBColor::depth, false); pixelcopy_t pc_read( nullptr, RGBColor::depth, _read_depth, false); startWrite(); do { readRect(x, y, w, 1, buf, &pc_read); - std::size_t i = 0; + size_t i = 0; do { effector(x + i, y, buf[i]); diff --git a/src/lgfx/v1/Touch.hpp b/src/lgfx/v1/Touch.hpp index 4b585d7..df69d02 100644 --- a/src/lgfx/v1/Touch.hpp +++ b/src/lgfx/v1/Touch.hpp @@ -17,7 +17,8 @@ Original Source: /----------------------------------------------------------------------------*/ #pragma once -#include +#include +#include namespace lgfx { @@ -27,10 +28,10 @@ namespace lgfx struct touch_point_t { - std::int16_t x = -1; - std::int16_t y = -1; - std::uint16_t size = 0; - std::uint16_t id = 0; + int16_t x = -1; + int16_t y = -1; + uint16_t size = 0; + uint16_t id = 0; }; //---------------------------------------------------------------------------- @@ -39,30 +40,30 @@ namespace lgfx { struct config_t { - std::uint32_t freq = 1000000; - std::uint16_t x_min = 0; - std::uint16_t x_max = 3600; - std::uint16_t y_min = 0; - std::uint16_t y_max = 3600; + uint32_t freq = 1000000; + uint16_t x_min = 0; + uint16_t x_max = 3600; + uint16_t y_min = 0; + uint16_t y_max = 3600; bool bus_shared = true; /// パネルとタッチが同じバスに繋がっている場合true - std::int16_t pin_int = -1; - std::uint8_t offset_rotation = 0; + int16_t pin_int = -1; + uint8_t offset_rotation = 0; union { struct { - std::int8_t spi_host; // ESP32:spi_host_device_t VSPI_HOST or HSPI_HOST - std::int16_t pin_sclk; - std::int16_t pin_mosi; - std::int16_t pin_miso; - std::int16_t pin_cs = -1; + int8_t spi_host; // ESP32:spi_host_device_t VSPI_HOST or HSPI_HOST + int16_t pin_sclk; + int16_t pin_mosi; + int16_t pin_miso; + int16_t pin_cs = -1; }; struct { - std::int8_t i2c_port; // ESP32:i2c_port_t I2C_NUM_0 or I2C_NUM_1 - std::int16_t pin_scl; - std::int16_t pin_sda; - std::int16_t i2c_addr; + int8_t i2c_port; // ESP32:i2c_port_t I2C_NUM_0 or I2C_NUM_1 + int16_t pin_scl; + int16_t pin_sda; + int16_t i2c_addr; }; }; }; @@ -78,7 +79,7 @@ namespace lgfx virtual void wakeup(void) = 0; virtual void sleep(void) = 0; virtual bool isEnable(void) { return true; }; - virtual std::uint_fast8_t getTouchRaw(touch_point_t* tp, std::uint_fast8_t count) = 0; + virtual uint_fast8_t getTouchRaw(touch_point_t* tp, uint_fast8_t count) = 0; protected: config_t _cfg; diff --git a/src/lgfx/v1/gitTagVersion.h b/src/lgfx/v1/gitTagVersion.h index c16ed9a..2eb8314 100644 --- a/src/lgfx/v1/gitTagVersion.h +++ b/src/lgfx/v1/gitTagVersion.h @@ -1,4 +1,4 @@ #define LGFX_VERSION_MAJOR 1 #define LGFX_VERSION_MINOR 0 -#define LGFX_VERSION_PATCH 0 +#define LGFX_VERSION_PATCH 2 #define LOVYANGFX_VERSION F( LGFX_VERSION_MAJOR "." LGFX_VERSION_MINOR "." LGFX_VERSION_PATCH ) diff --git a/src/lgfx/v1/lgfx_TTFfont.cpp b/src/lgfx/v1/lgfx_TTFfont.cpp index d2d6f93..fb21b85 100644 --- a/src/lgfx/v1/lgfx_TTFfont.cpp +++ b/src/lgfx/v1/lgfx_TTFfont.cpp @@ -4,7 +4,7 @@ #include "misc/pixelcopy.hpp" #include "LGFXBase.hpp" -#include +#include "../internal/algorithm.h" //#include "../lgfx_debug.hpp" @@ -19,7 +19,7 @@ namespace lgfx unloadFont(); } - std::size_t TTFfont::drawChar(LGFXBase* gfx, std::int32_t x, std::int32_t y, std::uint16_t c, const TextStyle* style, FontMetrics* metrics, std::int32_t& filled_x) const + size_t TTFfont::drawChar(LGFXBase* gfx, int32_t x, int32_t y, uint16_t c, const TextStyle* style, FontMetrics* metrics, int32_t& filled_x) const { // unimplemented return 0; @@ -36,9 +36,9 @@ metrics->y_offset = 0; metrics->baseline = _vertical.Ascender; } - static void _load_metrics(std::uint16_t *width, std::int16_t *bearing, DataWrapper* data, std::size_t glyph_index, std::size_t k, std::size_t table_pos, std::size_t table_size) + static void _load_metrics(uint16_t *width, int16_t *bearing, DataWrapper* data, size_t glyph_index, size_t k, size_t table_pos, size_t table_size) { - std::size_t table_end = table_pos + table_size; + size_t table_end = table_pos + table_size; bool contain = glyph_index < k; table_pos += 4 * (contain ? glyph_index : (k - 1)); @@ -64,7 +64,7 @@ metrics->baseline = _vertical.Ascender; } } - TTFfont::Metrics_t TTFfont::_get_metrics(std::uint32_t glyph_index) const + TTFfont::Metrics_t TTFfont::_get_metrics(uint32_t glyph_index) const { // ---- tt_face_get_metrics Metrics_t res; @@ -79,10 +79,10 @@ metrics->baseline = _vertical.Ascender; return res; } - bool TTFfont::updateFontMetric(FontMetrics *metrics, std::uint16_t uniCode) const + bool TTFfont::updateFontMetric(FontMetrics *metrics, uint16_t uniCode) const { //LGFX_DEBUG_LOG("uniCode:%04x \r\n", uniCode); - std::uint16_t glyph_index; + uint16_t glyph_index; if (!_get_glyph_index(uniCode, &glyph_index)) return false; auto data = _fontData; @@ -99,13 +99,13 @@ metrics->height = ttf_mtx.advance_height >> 6; return true; } - bool TTFfont::_get_glyph_index(std::uint16_t unicode, std::uint16_t *index) const + bool TTFfont::_get_glyph_index(uint16_t unicode, uint16_t *index) const { - std::uint_fast16_t num_segs2 = _cmap.rawdata[3]; - //std::uint_fast16_t search_range = _cmap.rawdata[4]; - //std::uint_fast16_t entry_selector = _cmap.rawdata[5]; - //std::uint_fast16_t range_shift = _cmap.rawdata[6]; - std::uint_fast16_t num_segs = num_segs2 >> 1; + uint_fast16_t num_segs2 = _cmap.rawdata[3]; + //uint_fast16_t search_range = _cmap.rawdata[4]; + //uint_fast16_t entry_selector = _cmap.rawdata[5]; + //uint_fast16_t range_shift = _cmap.rawdata[6]; + uint_fast16_t num_segs = num_segs2 >> 1; auto charcode = unicode; @@ -142,36 +142,36 @@ metrics->height = ttf_mtx.advance_height >> 6; bool TTFfont::loadFont(DataWrapper* data) { #define FT_MAKE_TAG( _x1, _x2, _x3, _x4 ) \ - ( ( (std::uint32_t)_x1 << 24 ) | \ - ( (std::uint32_t)_x2 << 16 ) | \ - ( (std::uint32_t)_x3 << 8 ) | \ - (std::uint32_t)_x4 ) - - static constexpr std::uint32_t TTAG_ttcf = FT_MAKE_TAG( 't', 't', 'c', 'f' ); - static constexpr std::uint32_t TTAG_true = FT_MAKE_TAG( 't', 'r', 'u', 'e' ); -// static constexpr std::uint32_t TTAG_OTTO = FT_MAKE_TAG( 'O', 'T', 'T', 'O' ); -// static constexpr std::uint32_t TTAG_typ1 = FT_MAKE_TAG( 't', 'y', 'p', '1' ); - - static constexpr std::uint32_t TTAG_glyf = FT_MAKE_TAG( 'g', 'l', 'y', 'f' ); - static constexpr std::uint32_t TTAG_CFF = FT_MAKE_TAG( 'C', 'F', 'F', ' ' ); - - static constexpr std::uint32_t TTAG_head = FT_MAKE_TAG( 'h', 'e', 'a', 'd' ); - static constexpr std::uint32_t TTAG_maxp = FT_MAKE_TAG( 'm', 'a', 'x', 'p' ); - static constexpr std::uint32_t TTAG_cmap = FT_MAKE_TAG( 'c', 'm', 'a', 'p' ); -// static constexpr std::uint32_t TTAG_name = FT_MAKE_TAG( 'n', 'a', 'm', 'e' ); - static constexpr std::uint32_t TTAG_hhea = FT_MAKE_TAG( 'h', 'h', 'e', 'a' ); - static constexpr std::uint32_t TTAG_hmtx = FT_MAKE_TAG( 'h', 'm', 't', 'x' ); - static constexpr std::uint32_t TTAG_vhea = FT_MAKE_TAG( 'v', 'h', 'e', 'a' ); - static constexpr std::uint32_t TTAG_vmtx = FT_MAKE_TAG( 'v', 'm', 't', 'x' ); - static constexpr std::uint32_t TTAG_OS2 = FT_MAKE_TAG( 'O', 'S', '/', '2' ); -// static constexpr std::uint32_t TTAG_gasp = FT_MAKE_TAG( 'g', 'a', 's', 'p' ); -// static constexpr std::uint32_t TTAG_kern = FT_MAKE_TAG( 'k', 'e', 'r', 'n' ); + ( ( (uint32_t)_x1 << 24 ) | \ + ( (uint32_t)_x2 << 16 ) | \ + ( (uint32_t)_x3 << 8 ) | \ + (uint32_t)_x4 ) + + static constexpr uint32_t TTAG_ttcf = FT_MAKE_TAG( 't', 't', 'c', 'f' ); + static constexpr uint32_t TTAG_true = FT_MAKE_TAG( 't', 'r', 'u', 'e' ); +// static constexpr uint32_t TTAG_OTTO = FT_MAKE_TAG( 'O', 'T', 'T', 'O' ); +// static constexpr uint32_t TTAG_typ1 = FT_MAKE_TAG( 't', 'y', 'p', '1' ); + + static constexpr uint32_t TTAG_glyf = FT_MAKE_TAG( 'g', 'l', 'y', 'f' ); + static constexpr uint32_t TTAG_CFF = FT_MAKE_TAG( 'C', 'F', 'F', ' ' ); + + static constexpr uint32_t TTAG_head = FT_MAKE_TAG( 'h', 'e', 'a', 'd' ); + static constexpr uint32_t TTAG_maxp = FT_MAKE_TAG( 'm', 'a', 'x', 'p' ); + static constexpr uint32_t TTAG_cmap = FT_MAKE_TAG( 'c', 'm', 'a', 'p' ); +// static constexpr uint32_t TTAG_name = FT_MAKE_TAG( 'n', 'a', 'm', 'e' ); + static constexpr uint32_t TTAG_hhea = FT_MAKE_TAG( 'h', 'h', 'e', 'a' ); + static constexpr uint32_t TTAG_hmtx = FT_MAKE_TAG( 'h', 'm', 't', 'x' ); + static constexpr uint32_t TTAG_vhea = FT_MAKE_TAG( 'v', 'h', 'e', 'a' ); + static constexpr uint32_t TTAG_vmtx = FT_MAKE_TAG( 'v', 'm', 't', 'x' ); + static constexpr uint32_t TTAG_OS2 = FT_MAKE_TAG( 'O', 'S', '/', '2' ); +// static constexpr uint32_t TTAG_gasp = FT_MAKE_TAG( 'g', 'a', 's', 'p' ); +// static constexpr uint32_t TTAG_kern = FT_MAKE_TAG( 'k', 'e', 'r', 'n' ); unloadFont(); _fontData = data; - std::uint32_t tag = data->read32swap(); + uint32_t tag = data->read32swap(); if (tag != 0x00010000UL && tag != 0x00020000UL @@ -192,8 +192,8 @@ metrics->height = ttf_mtx.advance_height >> 6; { return false; } - _ttc_header.offsets = (std::size_t*)lgfx::heap_alloc(4 * _ttc_header.count); - for (std::uint32_t i = 0; i < _ttc_header.count; i++) + _ttc_header.offsets = (size_t*)lgfx::heap_alloc(4 * _ttc_header.count); + for (uint32_t i = 0; i < _ttc_header.count; i++) { _ttc_header.offsets[i] = data->read32swap(); } @@ -202,7 +202,7 @@ metrics->height = ttf_mtx.advance_height >> 6; { _ttc_header.version = 1 << 16; _ttc_header.count = 1; - _ttc_header.offsets = (std::size_t*)lgfx::heap_alloc(4); + _ttc_header.offsets = (size_t*)lgfx::heap_alloc(4); _ttc_header.offsets[0] = 0; } @@ -286,10 +286,10 @@ metrics->height = ttf_mtx.advance_height >> 6; if (!_cmap.load(data)) { return false; } /* - _cmap_table = (std::uint8_t*)lgfx::heap_alloc_psram(_cmap_size); + _cmap_table = (uint8_t*)lgfx::heap_alloc_psram(_cmap_size); if (_cmap_table == nullptr) { - _cmap_table = (std::uint8_t*)lgfx::heap_alloc(_cmap_size); + _cmap_table = (uint8_t*)lgfx::heap_alloc(_cmap_size); } if (_cmap_table == nullptr) { return false; } data->read(_cmap_table, _cmap_size); @@ -360,7 +360,7 @@ metrics->height = ttf_mtx.advance_height >> 6; return true; } - TTFfont::TT_TableRec* TTFfont::tt_face_lookup_table(std::uint32_t tag) + TTFfont::TT_TableRec* TTFfont::tt_face_lookup_table(uint32_t tag) { TT_TableRec* entry = _dir_tables; TT_TableRec* limit = entry + _sfnt.num_tables; @@ -374,9 +374,9 @@ metrics->height = ttf_mtx.advance_height >> 6; return nullptr; } - bool TTFfont::tt_face_goto_table( std::uint32_t tag + bool TTFfont::tt_face_goto_table( uint32_t tag , DataWrapper* data - , std::uint32_t* length ) + , uint32_t* length ) { auto table = tt_face_lookup_table( tag ); if ( table ) @@ -392,7 +392,7 @@ metrics->height = ttf_mtx.advance_height >> 6; void TTFfont::TT_Header::load(DataWrapper* data) { - data->read((std::uint8_t*)this, 54); + data->read((uint8_t*)this, 54); Table_Version = __builtin_bswap32(Table_Version ); Font_Revision = __builtin_bswap32(Font_Revision ); CheckSum_Adjust = __builtin_bswap32(CheckSum_Adjust ); @@ -417,33 +417,33 @@ metrics->height = ttf_mtx.advance_height >> 6; void TTFfont::TT_MaxProfile::load(DataWrapper* data) { memset(this, 0, sizeof(TTFfont::TT_MaxProfile)); - data->read((std::uint8_t*)this, 6); + data->read((uint8_t*)this, 6); version = __builtin_bswap32(version ); numGlyphs = __builtin_bswap16(numGlyphs); //ESP_LOGI("lgfx_fonts", "numGlyphs: %u", numGlyphs ); if ( version >= 0x10000L ) { - data->read((std::uint8_t*)&maxPoints, 26); + data->read((uint8_t*)&maxPoints, 26); maxPoints = __builtin_bswap16(maxPoints ); maxContours = __builtin_bswap16(maxContours ); maxCompositePoints = __builtin_bswap16(maxCompositePoints ); maxCompositeContours = __builtin_bswap16(maxCompositeContours); maxZones = __builtin_bswap16(maxZones ); - maxTwilightPoints = std::min( 0xFFFFu - 4, __builtin_bswap16(maxTwilightPoints)); + maxTwilightPoints = std::min( 0xFFFFu - 4, __builtin_bswap16(maxTwilightPoints)); maxStorage = __builtin_bswap16(maxStorage); - maxFunctionDefs = std::max(64u, __builtin_bswap16(maxFunctionDefs)); + maxFunctionDefs = std::max(64u, __builtin_bswap16(maxFunctionDefs)); maxInstructionDefs = __builtin_bswap16(maxInstructionDefs ); maxStackElements = __builtin_bswap16(maxStackElements ); maxSizeOfInstructions= __builtin_bswap16(maxSizeOfInstructions); maxComponentElements = __builtin_bswap16(maxComponentElements ); - maxComponentDepth = std::max(100, __builtin_bswap16(maxComponentDepth)); + maxComponentDepth = std::max(100, __builtin_bswap16(maxComponentDepth)); } } void TTFfont::TT_HoriHeader::load(DataWrapper* data) { - data->read((std::uint8_t*)this, 36); + data->read((uint8_t*)this, 36); Version = __builtin_bswap32(Version ); Ascender = __builtin_bswap16(Ascender ); Descender = __builtin_bswap16(Descender ); @@ -468,7 +468,7 @@ metrics->height = ttf_mtx.advance_height >> 6; void TTFfont::TT_OS2::load(DataWrapper* data) { - data->read((std::uint8_t*)this, 78); + data->read((uint8_t*)this, 78); version = __builtin_bswap16(version ); xAvgCharWidth = __builtin_bswap16(xAvgCharWidth ); usWeightClass = __builtin_bswap16(usWeightClass ); @@ -511,14 +511,14 @@ metrics->height = ttf_mtx.advance_height >> 6; if ( version >= 0x0001 ) { // only version 1 tables - data->read((std::uint8_t*)&ulCodePageRange1, 8); + data->read((uint8_t*)&ulCodePageRange1, 8); ulCodePageRange1 = __builtin_bswap32(ulCodePageRange1); ulCodePageRange2 = __builtin_bswap32(ulCodePageRange2); if ( version >= 0x0002 ) { // only version 2 tables - data->read((std::uint8_t*)&sxHeight, 10); + data->read((uint8_t*)&sxHeight, 10); sxHeight = __builtin_bswap16(sxHeight ); sCapHeight = __builtin_bswap16(sCapHeight ); usDefaultChar = __builtin_bswap16(usDefaultChar); @@ -530,28 +530,28 @@ metrics->height = ttf_mtx.advance_height >> 6; } - static constexpr std::uint16_t TT_PLATFORM_APPLE_UNICODE = 0; - static constexpr std::uint16_t TT_PLATFORM_MICROSOFT = 3; - static constexpr std::uint16_t TT_APPLE_ID_UNICODE_32 = 4; - static constexpr std::uint16_t TT_MS_ID_UCS_4 =10; - static constexpr std::uint16_t TT_MS_ID_UNICODE_CS = 1; + static constexpr uint16_t TT_PLATFORM_APPLE_UNICODE = 0; + static constexpr uint16_t TT_PLATFORM_MICROSOFT = 3; + static constexpr uint16_t TT_APPLE_ID_UNICODE_32 = 4; + static constexpr uint16_t TT_MS_ID_UCS_4 =10; + static constexpr uint16_t TT_MS_ID_UNICODE_CS = 1; bool TTFfont::cmap_t::load(DataWrapper* data) { auto cmap_pos = data->tell(); - std::uint16_t table_ver = data->read16swap(); + uint16_t table_ver = data->read16swap(); if (table_ver != 0) return false; - std::uint16_t numTables = data->read16swap(); + uint16_t numTables = data->read16swap(); //Serial.printf("cmap table version:%d num:%d\r\n", table_ver, numTables); /// Unicode かつ Format 4 の CMAP を探す - for (std::size_t idx = 0; idx < numTables; ++idx) + for (size_t idx = 0; idx < numTables; ++idx) { - std::uint16_t platform_id = data->read16swap(); - std::uint16_t encoding_id = data->read16swap(); - std::uint32_t offset = data->read32swap(); + uint16_t platform_id = data->read16swap(); + uint16_t encoding_id = data->read16swap(); + uint32_t offset = data->read32swap(); //Serial.printf("pid:%d eid:%d offset:%d \r\n", platform_id, encoding_id, offset); /// プラットフォームIDとエンコードIDの組み合わせからunicodeのものを探す @@ -565,24 +565,24 @@ metrics->height = ttf_mtx.advance_height >> 6; auto cmap_prev_pos = data->tell(); data->seek(cmap_pos + offset); - std::uint16_t cmap_format = data->read16swap(); + uint16_t cmap_format = data->read16swap(); //Serial.printf("format: %d\r\n", cmap_format); // CMAP FORMAT 4 か否か判定 if (cmap_format == 4) { - std::uint16_t length = data->read16swap(); + uint16_t length = data->read16swap(); - rawdata = (std::uint16_t*)lgfx::heap_alloc_psram(length); + rawdata = (uint16_t*)lgfx::heap_alloc_psram(length); if (rawdata == nullptr) { - rawdata = (std::uint16_t*)lgfx::heap_alloc(length); + rawdata = (uint16_t*)lgfx::heap_alloc(length); } if (rawdata == nullptr) return false; data->seek(cmap_pos + offset); - data->read(reinterpret_cast(rawdata), length); + data->read(reinterpret_cast(rawdata), length); length >>= 1; - std::size_t idx = 0; + size_t idx = 0; do { rawdata[idx] = __builtin_bswap16(rawdata[idx]); @@ -594,10 +594,10 @@ for (int j = 0; j < 8; ++j) { for (int i = 0; i < 8; ++i) { Serial.printf(" %04x", rawdata[i+j*8]); } Serial.println(); } -std::uint16_t num_segs = rawdata[3]; // __builtin_bswap16(num_segs ) >> 1; -std::uint16_t search_range = rawdata[4]; // __builtin_bswap16(search_range ); -std::uint16_t entry_selector = rawdata[5]; // __builtin_bswap16(entry_selector); -std::uint16_t range_shift = rawdata[6]; // __builtin_bswap16(range_shift ); +uint16_t num_segs = rawdata[3]; // __builtin_bswap16(num_segs ) >> 1; +uint16_t search_range = rawdata[4]; // __builtin_bswap16(search_range ); +uint16_t entry_selector = rawdata[5]; // __builtin_bswap16(entry_selector); +uint16_t range_shift = rawdata[6]; // __builtin_bswap16(range_shift ); Serial.printf("len:%d num_segs:%d search_range:%d entry_selector:%d range_shift:%d \r\n", length, num_segs, search_range, entry_selector, range_shift); //*/ return true; @@ -612,10 +612,10 @@ Serial.printf("len:%d num_segs:%d search_range:%d entry_selector:%d range_shift: /* bool TTFfont::tt_face_build_cmaps( void ) { - std::uint8_t* table = _cmap_table; - std::uint8_t* limit = table + _cmap_size; + uint8_t* table = _cmap_table; + uint8_t* limit = table + _cmap_size; unsigned int volatile num_cmaps; - std::uint8_t* volatile p = table; + uint8_t* volatile p = table; if ( !p || p + 4 > limit ) return false; diff --git a/src/lgfx/v1/lgfx_TTFfont.hpp b/src/lgfx/v1/lgfx_TTFfont.hpp index 5329160..6db6185 100644 --- a/src/lgfx/v1/lgfx_TTFfont.hpp +++ b/src/lgfx/v1/lgfx_TTFfont.hpp @@ -16,7 +16,7 @@ namespace lgfx font_type_t getType(void) const override { return ft_ttf; } - std::size_t drawChar(LGFXBase* gfx, std::int32_t x, std::int32_t y, std::uint16_t c, const TextStyle* style, FontMetrics* metrics, std::int32_t& filled_x) const override; + size_t drawChar(LGFXBase* gfx, int32_t x, int32_t y, uint16_t c, const TextStyle* style, FontMetrics* metrics, int32_t& filled_x) const override; void getDefaultMetric(FontMetrics *metrics) const override; @@ -24,11 +24,11 @@ namespace lgfx bool unloadFont(void) override; - bool updateFontMetric(FontMetrics *metrics, std::uint16_t uniCode) const override; + bool updateFontMetric(FontMetrics *metrics, uint16_t uniCode) const override; private: - bool _get_glyph_index(std::uint16_t unicode, std::uint16_t *index) const; + bool _get_glyph_index(uint16_t unicode, uint16_t *index) const; bool tt_face_build_cmaps( void ); @@ -37,109 +37,109 @@ namespace lgfx struct TTC_HeaderRec { - std::int32_t version = 0; - std::uint32_t count = 0; - std::size_t* offsets = nullptr; + int32_t version = 0; + uint32_t count = 0; + size_t* offsets = nullptr; }; TTC_HeaderRec _ttc_header; struct TT_TableRec { - std::uint32_t Tag; - std::uint32_t CheckSum; - std::uint32_t Offset; - std::uint32_t Length; + uint32_t Tag; + uint32_t CheckSum; + uint32_t Offset; + uint32_t Length; }; struct SFNT_HeaderRec { - std::uint32_t format_tag; - std::uint16_t num_tables; - std::uint16_t search_range; - std::uint16_t entry_selector; - std::uint16_t range_shift; - std::uint32_t offset; // not in file + uint32_t format_tag; + uint16_t num_tables; + uint16_t search_range; + uint16_t entry_selector; + uint16_t range_shift; + uint32_t offset; // not in file }; struct TT_Header { - std::int32_t Table_Version; - std::int32_t Font_Revision; + int32_t Table_Version; + int32_t Font_Revision; - std::int32_t CheckSum_Adjust; - std::int32_t Magic_Number; + int32_t CheckSum_Adjust; + int32_t Magic_Number; - std::uint16_t Flags; - std::uint16_t Units_Per_EM; + uint16_t Flags; + uint16_t Units_Per_EM; - std::int32_t Created [2]; - std::int32_t Modified[2]; + int32_t Created [2]; + int32_t Modified[2]; - std::int16_t xMin; - std::int16_t yMin; - std::int16_t xMax; - std::int16_t yMax; + int16_t xMin; + int16_t yMin; + int16_t xMax; + int16_t yMax; - std::uint16_t Mac_Style; - std::uint16_t Lowest_Rec_PPEM; + uint16_t Mac_Style; + uint16_t Lowest_Rec_PPEM; - std::int16_t Font_Direction; - std::int16_t Index_To_Loc_Format; - std::int16_t Glyph_Data_Format; + int16_t Font_Direction; + int16_t Index_To_Loc_Format; + int16_t Glyph_Data_Format; void load(DataWrapper* data); }; struct TT_MaxProfile { - std::int32_t version; - std::uint16_t numGlyphs; - std::uint16_t maxPoints; - std::uint16_t maxContours; - std::uint16_t maxCompositePoints; - std::uint16_t maxCompositeContours; - std::uint16_t maxZones; - std::uint16_t maxTwilightPoints; - std::uint16_t maxStorage; - std::uint16_t maxFunctionDefs; - std::uint16_t maxInstructionDefs; - std::uint16_t maxStackElements; - std::uint16_t maxSizeOfInstructions; - std::uint16_t maxComponentElements; - std::uint16_t maxComponentDepth; + int32_t version; + uint16_t numGlyphs; + uint16_t maxPoints; + uint16_t maxContours; + uint16_t maxCompositePoints; + uint16_t maxCompositeContours; + uint16_t maxZones; + uint16_t maxTwilightPoints; + uint16_t maxStorage; + uint16_t maxFunctionDefs; + uint16_t maxInstructionDefs; + uint16_t maxStackElements; + uint16_t maxSizeOfInstructions; + uint16_t maxComponentElements; + uint16_t maxComponentDepth; void load(DataWrapper* data); }; struct TT_HoriHeader { - std::int32_t Version; - std::int16_t Ascender; - std::int16_t Descender; - std::int16_t Line_Gap; + int32_t Version; + int16_t Ascender; + int16_t Descender; + int16_t Line_Gap; union { struct { - std::uint16_t advance_Width_Max; /* advance width maximum */ - std::int16_t min_Left_Side_Bearing; /* minimum left-sb */ - std::int16_t min_Right_Side_Bearing; /* minimum right-sb */ - std::int16_t xMax_Extent; /* xmax extents */ + uint16_t advance_Width_Max; /* advance width maximum */ + int16_t min_Left_Side_Bearing; /* minimum left-sb */ + int16_t min_Right_Side_Bearing; /* minimum right-sb */ + int16_t xMax_Extent; /* xmax extents */ }; struct { - std::uint16_t advance_Height_Max; /* advance height maximum */ - std::int16_t min_Top_Side_Bearing; /* minimum left-sb or top-sb */ - std::int16_t min_Bottom_Side_Bearing; /* minimum right-sb or bottom-sb */ - std::int16_t yMax_Extent; /* xmax or ymax extents */ + uint16_t advance_Height_Max; /* advance height maximum */ + int16_t min_Top_Side_Bearing; /* minimum left-sb or top-sb */ + int16_t min_Bottom_Side_Bearing; /* minimum right-sb or bottom-sb */ + int16_t yMax_Extent; /* xmax or ymax extents */ }; }; - std::int16_t caret_Slope_Rise; - std::int16_t caret_Slope_Run; - std::int16_t caret_Offset; - std::int16_t Reserved[4]; - std::int16_t metric_Data_Format; + int16_t caret_Slope_Rise; + int16_t caret_Slope_Run; + int16_t caret_Offset; + int16_t Reserved[4]; + int16_t metric_Data_Format; union { - std::uint16_t number_Of_HMetrics; - std::uint16_t number_Of_VMetrics; + uint16_t number_Of_HMetrics; + uint16_t number_Of_VMetrics; }; void* long_metrics; void* short_metrics; @@ -148,63 +148,63 @@ namespace lgfx struct TT_OS2 { - std::uint16_t version; - std::int16_t xAvgCharWidth; - std::uint16_t usWeightClass; - std::uint16_t usWidthClass; - std::int16_t fsType; - std::int16_t ySubscriptXSize; - std::int16_t ySubscriptYSize; - std::int16_t ySubscriptXOffset; - std::int16_t ySubscriptYOffset; - std::int16_t ySuperscriptXSize; - std::int16_t ySuperscriptYSize; - std::int16_t ySuperscriptXOffset; - std::int16_t ySuperscriptYOffset; - std::int16_t yStrikeoutSize; - std::int16_t yStrikeoutPosition; - std::int16_t sFamilyClass; - std::uint8_t panose[10]; - std::uint32_t ulUnicodeRange1; - std::uint32_t ulUnicodeRange2; - std::uint32_t ulUnicodeRange3; - std::uint32_t ulUnicodeRange4; - std::uint8_t achVendID[4]; - - std::uint16_t fsSelection; - std::uint16_t usFirstCharIndex; - std::uint16_t usLastCharIndex; - std::int16_t sTypoAscender; - std::int16_t sTypoDescender; - std::int16_t sTypoLineGap; - std::uint16_t usWinAscent; - std::uint16_t usWinDescent; + uint16_t version; + int16_t xAvgCharWidth; + uint16_t usWeightClass; + uint16_t usWidthClass; + int16_t fsType; + int16_t ySubscriptXSize; + int16_t ySubscriptYSize; + int16_t ySubscriptXOffset; + int16_t ySubscriptYOffset; + int16_t ySuperscriptXSize; + int16_t ySuperscriptYSize; + int16_t ySuperscriptXOffset; + int16_t ySuperscriptYOffset; + int16_t yStrikeoutSize; + int16_t yStrikeoutPosition; + int16_t sFamilyClass; + uint8_t panose[10]; + uint32_t ulUnicodeRange1; + uint32_t ulUnicodeRange2; + uint32_t ulUnicodeRange3; + uint32_t ulUnicodeRange4; + uint8_t achVendID[4]; + + uint16_t fsSelection; + uint16_t usFirstCharIndex; + uint16_t usLastCharIndex; + int16_t sTypoAscender; + int16_t sTypoDescender; + int16_t sTypoLineGap; + uint16_t usWinAscent; + uint16_t usWinDescent; // only version 1 tables: - std::uint32_t ulCodePageRange1; - std::uint32_t ulCodePageRange2; + uint32_t ulCodePageRange1; + uint32_t ulCodePageRange2; // only version 2 tables: - std::int16_t sxHeight; - std::int16_t sCapHeight; - std::uint16_t usDefaultChar; - std::uint16_t usBreakChar; - std::uint16_t usMaxContext; + int16_t sxHeight; + int16_t sCapHeight; + uint16_t usDefaultChar; + uint16_t usBreakChar; + uint16_t usMaxContext; void load(DataWrapper* data); }; struct cmap_t // 自作 { - std::uint16_t* rawdata = nullptr; + uint16_t* rawdata = nullptr; bool load(DataWrapper* data); }; #define FT_ENC_TAG( value, a, b, c, d ) \ - value = ( ( (std::uint32_t)(a) << 24 ) | \ - ( (std::uint32_t)(b) << 16 ) | \ - ( (std::uint32_t)(c) << 8 ) | \ - (std::uint32_t)(d) ) + value = ( ( (uint32_t)(a) << 24 ) | \ + ( (uint32_t)(b) << 16 ) | \ + ( (uint32_t)(c) << 8 ) | \ + (uint32_t)(d) ) enum FT_Encoding { @@ -240,16 +240,16 @@ namespace lgfx { // FT_Face face; FT_Encoding encoding; - std::uint16_t platform_id; - std::uint16_t encoding_id; + uint16_t platform_id; + uint16_t encoding_id; }; struct Metrics_t { - std::int16_t left_bearing = 0; - std::int16_t top_bearing = 0; - std::uint16_t advance_width = 0; - std::uint16_t advance_height = 0; + int16_t left_bearing = 0; + int16_t top_bearing = 0; + uint16_t advance_width = 0; + uint16_t advance_height = 0; }; #pragma pack(pop) @@ -263,24 +263,24 @@ namespace lgfx TT_OS2 _os2; TT_TableRec* _dir_tables = nullptr; - //std::uint8_t* _cmap_table = nullptr; - //std::uint32_t _cmap_size = 0; + //uint8_t* _cmap_table = nullptr; + //uint32_t _cmap_size = 0; cmap_t _cmap; - std::uint32_t _horz_metrics_size; - std::uint32_t _horz_metrics_offset; - std::uint32_t _vert_metrics_size; - std::uint32_t _vert_metrics_offset; + uint32_t _horz_metrics_size; + uint32_t _horz_metrics_offset; + uint32_t _vert_metrics_size; + uint32_t _vert_metrics_offset; - TT_TableRec* tt_face_lookup_table(std::uint32_t tag); - bool tt_face_goto_table( std::uint32_t tag + TT_TableRec* tt_face_lookup_table(uint32_t tag); + bool tt_face_goto_table( uint32_t tag , DataWrapper* data - , std::uint32_t* length = nullptr); + , uint32_t* length = nullptr); - Metrics_t _get_metrics(std::uint32_t glyph_index) const; + Metrics_t _get_metrics(uint32_t glyph_index) const; - std::uint_fast8_t face_index = 0; + uint_fast8_t face_index = 0; }; //---------------------------------------------------------------------------- diff --git a/src/lgfx/v1/lgfx_filesystem_support.hpp b/src/lgfx/v1/lgfx_filesystem_support.hpp index c598c2e..3c35f10 100644 --- a/src/lgfx/v1/lgfx_filesystem_support.hpp +++ b/src/lgfx/v1/lgfx_filesystem_support.hpp @@ -25,7 +25,7 @@ Original Source: #include "misc/enum.hpp" #include -#include +#include namespace lgfx { @@ -80,66 +80,66 @@ namespace lgfx load_font_with_path(path); } - inline bool drawBmp(fs::FS &fs, const char *path, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawBmp(fs::FS &fs, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { return drawBmpFile(fs, path, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - inline bool drawBmpFile(fs::FS &fs, const char *path, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawBmpFile(fs::FS &fs, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { FileWrapper file(fs); return this->drawBmpFile(&file, path, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - inline bool drawBmpFile(fs::FS &fs, const String& path, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawBmpFile(fs::FS &fs, const String& path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { return drawBmpFile(fs, path.c_str(), x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - inline bool drawJpgFile(fs::FS &fs, const char *path, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawJpgFile(fs::FS &fs, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { FileWrapper file(fs); return this->drawJpgFile(&file, path, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - inline bool drawJpgFile(fs::FS &fs, const String& path, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawJpgFile(fs::FS &fs, const String& path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { return drawJpgFile(fs, path.c_str(), x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } [[deprecated("use float scale")]] - inline bool drawJpgFile(fs::FS &fs, const char *path, std::int32_t x, std::int32_t y, std::int32_t maxWidth, std::int32_t maxHeight, std::int32_t offX, std::int32_t offY, jpeg_div::jpeg_div_t scale) + inline bool drawJpgFile(fs::FS &fs, const char *path, int32_t x, int32_t y, int32_t maxWidth, int32_t maxHeight, int32_t offX, int32_t offY, jpeg_div::jpeg_div_t scale) { return drawJpgFile(fs, path, x, y, maxWidth, maxHeight, offX, offY, 1.0f / (1 << scale)); } - inline bool drawPngFile(fs::FS &fs, const char *path, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawPngFile(fs::FS &fs, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { FileWrapper file(fs); return this->drawPngFile(&file, path, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - inline bool drawPngFile(fs::FS &fs, const String& path, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawPngFile(fs::FS &fs, const String& path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { return drawPngFile(fs, path.c_str(), x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - inline bool drawBmpFile(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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawBmpFile(fs::FS &fs, fs::File *file, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { FileWrapper data(fs, file); this->prepareTmpTransaction(&data); return this->draw_bmp(&data, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawJpgFile(fs::FS &fs, fs::File *file, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { FileWrapper data(fs, file); this->prepareTmpTransaction(&data); return this->draw_jpg(&data, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } [[deprecated("use float scale")]] - inline bool drawJpgFile(fs::FS &fs, fs::File *file, std::int32_t x, std::int32_t y, std::int32_t maxWidth, std::int32_t maxHeight, std::int32_t offX, std::int32_t offY, jpeg_div::jpeg_div_t scale) + inline bool drawJpgFile(fs::FS &fs, fs::File *file, int32_t x, int32_t y, int32_t maxWidth, int32_t maxHeight, int32_t offX, int32_t offY, jpeg_div::jpeg_div_t scale) { return drawJpgFile(fs, file, x, y, maxWidth, maxHeight, offX, offY, 1.0f / (1 << 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawPngFile(fs::FS &fs, fs::File *file, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { FileWrapper data(fs, file); this->prepareTmpTransaction(&data); @@ -147,7 +147,7 @@ namespace lgfx } - inline bool drawBmp(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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawBmp(fs::File *dataSource, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { StreamWrapper data; data.set(dataSource); @@ -156,7 +156,7 @@ namespace lgfx return this->draw_bmp(&data, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawJpg(fs::File *dataSource, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { StreamWrapper data; data.set(dataSource); @@ -165,12 +165,12 @@ namespace lgfx return this->draw_jpg(&data, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } [[deprecated("use float scale")]] - inline bool drawJpg(fs::File *dataSource, std::int32_t x, std::int32_t y, std::int32_t maxWidth, std::int32_t maxHeight, std::int32_t offX, std::int32_t offY, jpeg_div::jpeg_div_t scale) + inline bool drawJpg(fs::File *dataSource, int32_t x, int32_t y, int32_t maxWidth, int32_t maxHeight, int32_t offX, int32_t offY, jpeg_div::jpeg_div_t scale) { return drawJpg(dataSource, x, y, maxWidth, maxHeight, offX, offY, 1.0f / (1 << scale)); } - inline bool 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawPng(fs::File *dataSource, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { StreamWrapper data; data.set(dataSource); @@ -195,66 +195,66 @@ namespace lgfx load_font_with_path(path); } - inline bool drawBmp(SdBase &fs, const char *path, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawBmp(SdBase &fs, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { return drawBmpFile(fs, path, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - inline bool drawBmpFile(SdBase &fs, const char *path, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawBmpFile(SdBase &fs, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { SdFatWrapper file(fs); return this->drawBmpFile(&file, path, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - inline bool drawBmpFile(SdBase &fs, const String& path, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawBmpFile(SdBase &fs, const String& path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { return drawBmpFile(fs, path.c_str(), x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - inline bool drawJpgFile(SdBase &fs, const char *path, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawJpgFile(SdBase &fs, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { SdFatWrapper file(fs); return this->drawJpgFile(&file, path, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - inline bool drawJpgFile(SdBase &fs, const String& path, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawJpgFile(SdBase &fs, const String& path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { return drawJpgFile(fs, path.c_str(), x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } [[deprecated("use float scale")]] - inline bool drawJpgFile(SdBase &fs, const char *path, std::int32_t x, std::int32_t y, std::int32_t maxWidth, std::int32_t maxHeight, std::int32_t offX, std::int32_t offY, jpeg_div::jpeg_div_t scale) + inline bool drawJpgFile(SdBase &fs, const char *path, int32_t x, int32_t y, int32_t maxWidth, int32_t maxHeight, int32_t offX, int32_t offY, jpeg_div::jpeg_div_t scale) { return drawJpgFile(fs, path, x, y, maxWidth, maxHeight, offX, offY, 1.0f / (1 << scale)); } - inline bool drawPngFile(SdBase &fs, const char *path, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawPngFile(SdBase &fs, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { SdFatWrapper file(fs); return this->drawPngFile(&file, path, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - inline bool drawPngFile(SdBase &fs, const String& path, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawPngFile(SdBase &fs, const String& path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { return drawPngFile(fs, path.c_str(), x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - inline bool drawBmpFile(SdBase &fs, FsFile *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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawBmpFile(SdBase &fs, FsFile *file, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { SdFatWrapper data(fs, file); this->prepareTmpTransaction(&data); return this->draw_bmp(&data, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - inline bool drawJpgFile(SdBase &fs, FsFile *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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawJpgFile(SdBase &fs, FsFile *file, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { SdFatWrapper data(fs, file); this->prepareTmpTransaction(&data); return this->draw_jpg(&data, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } [[deprecated("use float scale")]] - inline bool drawJpgFile(SdBase &fs, FsFile *file, std::int32_t x, std::int32_t y, std::int32_t maxWidth, std::int32_t maxHeight, std::int32_t offX, std::int32_t offY, jpeg_div::jpeg_div_t scale) + inline bool drawJpgFile(SdBase &fs, FsFile *file, int32_t x, int32_t y, int32_t maxWidth, int32_t maxHeight, int32_t offX, int32_t offY, jpeg_div::jpeg_div_t scale) { return drawJpgFile(fs, file, x, y, maxWidth, maxHeight, offX, offY, 1.0f / (1 << scale)); } - inline bool drawPngFile(SdBase &fs, FsFile *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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawPngFile(SdBase &fs, FsFile *file, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { SdFatWrapper data(fs, file); this->prepareTmpTransaction(&data); @@ -265,26 +265,26 @@ namespace lgfx #if defined (Stream_h) - inline bool drawBmp(Stream *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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawBmp(Stream *dataSource, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { StreamWrapper data; data.set(dataSource); return this->draw_bmp(&data, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - inline bool drawJpg(Stream *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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawJpg(Stream *dataSource, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { StreamWrapper data; data.set(dataSource); return this->draw_jpg(&data, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } [[deprecated("use float scale")]] - inline bool drawJpg(Stream *dataSource, std::int32_t x, std::int32_t y, std::int32_t maxWidth, std::int32_t maxHeight, std::int32_t offX, std::int32_t offY, jpeg_div::jpeg_div_t scale) + inline bool drawJpg(Stream *dataSource, int32_t x, int32_t y, int32_t maxWidth, int32_t maxHeight, int32_t offX, int32_t offY, jpeg_div::jpeg_div_t scale) { return drawJpg(dataSource, x, y, maxWidth, maxHeight, offX, offY, 1.0f / (1 << scale)); } - inline bool drawPng(Stream *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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawPng(Stream *dataSource, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { StreamWrapper data; data.set(dataSource); @@ -295,7 +295,7 @@ namespace lgfx struct HttpWrapper : public StreamWrapper { - int read(std::uint8_t *buf, std::uint32_t len) override { + int read(uint8_t *buf, uint32_t len) override { while (_http.connected() && !_stream->available() && _index < _length) delay(1); return StreamWrapper::read(buf, len); } @@ -317,37 +317,37 @@ namespace lgfx }; - inline bool drawBmpUrl(const char* url, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawBmpUrl(const char* url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { HttpWrapper http; return http.open(url) && drawBmp(&http, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - inline bool drawBmpUrl(const String& url, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawBmpUrl(const String& url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { return drawBmpUrl(url.c_str(), x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - inline bool drawJpgUrl(const char* url, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawJpgUrl(const char* url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { HttpWrapper http; return http.open(url) && drawJpg(&http, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - inline bool drawJpgUrl(const String& url, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawJpgUrl(const String& url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { return drawJpgUrl(url.c_str(), x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } [[deprecated("use float scale")]] - inline bool drawJpgUrl(const char* url, std::int32_t x, std::int32_t y, std::int32_t maxWidth, std::int32_t maxHeight, std::int32_t offX, std::int32_t offY, jpeg_div::jpeg_div_t scale) + inline bool drawJpgUrl(const char* url, int32_t x, int32_t y, int32_t maxWidth, int32_t maxHeight, int32_t offX, int32_t offY, jpeg_div::jpeg_div_t scale) { return drawJpgUrl(url, x, y, maxWidth, maxHeight, offX, offY, 1.0f / (1 << scale)); } - inline bool drawPngUrl(const char* url, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawPngUrl(const char* url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { HttpWrapper http; return http.open(url) && drawPng(&http, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - inline bool drawPngUrl(const String& url, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawPngUrl(const String& url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { return drawPngUrl(url.c_str(), x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } @@ -357,22 +357,22 @@ namespace lgfx #elif defined (CONFIG_IDF_TARGET_ESP32) || defined(__SAMD51_HARMONY__) // ESP-IDF or Harmony - inline bool drawBmpFile(const char *path, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawBmpFile(const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { FileWrapper file; return drawBmpFile(&file, path, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } - inline bool drawJpgFile(const char *path, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawJpgFile(const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { FileWrapper file; return drawJpgFile(&file, path, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); } [[deprecated("use float scale")]] - inline bool drawJpgFile(const char *path, std::int32_t x, std::int32_t y, std::int32_t maxWidth, std::int32_t maxHeight, std::int32_t offX, std::int32_t offY, jpeg_div::jpeg_div_t scale) + inline bool drawJpgFile(const char *path, int32_t x, int32_t y, int32_t maxWidth, int32_t maxHeight, int32_t offX, int32_t offY, jpeg_div::jpeg_div_t scale) { return drawJpgFile(path, x, y, maxWidth, maxHeight, offX, offY, 1.0f / (1 << scale)); } - inline bool drawPngFile(const char *path, 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, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) + inline bool drawPngFile(const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) { FileWrapper file; return drawPngFile(&file, path, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); @@ -425,7 +425,7 @@ namespace lgfx return result; } - bool drawBmpFile(DataWrapper* file, const char *path, std::int32_t x, std::int32_t y, std::int32_t maxWidth, std::int32_t maxHeight, std::int32_t offX, std::int32_t offY, float scale_x, float scale_y, datum_t datum) + bool drawBmpFile(DataWrapper* file, const char *path, int32_t x, int32_t y, int32_t maxWidth, int32_t maxHeight, int32_t offX, int32_t offY, float scale_x, float scale_y, datum_t datum) { bool res = false; this->prepareTmpTransaction(file); @@ -439,7 +439,7 @@ namespace lgfx return res; } - bool drawJpgFile(DataWrapper* file, const char *path, std::int32_t x, std::int32_t y, std::int32_t maxWidth, std::int32_t maxHeight, std::int32_t offX, std::int32_t offY, float scale_x, float scale_y, datum_t datum) + bool drawJpgFile(DataWrapper* file, const char *path, int32_t x, int32_t y, int32_t maxWidth, int32_t maxHeight, int32_t offX, int32_t offY, float scale_x, float scale_y, datum_t datum) { bool res = false; this->prepareTmpTransaction(file); @@ -453,7 +453,7 @@ namespace lgfx return res; } - bool drawPngFile(DataWrapper* file, const char *path, std::int32_t x, std::int32_t y, std::int32_t maxWidth, std::int32_t maxHeight, std::int32_t offX, std::int32_t offY, float scale_x, float scale_y, datum_t datum) + bool drawPngFile(DataWrapper* file, const char *path, int32_t x, int32_t y, int32_t maxWidth, int32_t maxHeight, int32_t offX, int32_t offY, float scale_x, float scale_y, datum_t datum) { bool res = false; this->prepareTmpTransaction(file); diff --git a/src/lgfx/v1/lgfx_fonts.cpp b/src/lgfx/v1/lgfx_fonts.cpp index d04f11e..7ebcef3 100644 --- a/src/lgfx/v1/lgfx_fonts.cpp +++ b/src/lgfx/v1/lgfx_fonts.cpp @@ -10,22 +10,12 @@ #include "../Fonts/efont/lgfx_efont_kr.h" #include "../Fonts/efont/lgfx_efont_tw.h" -#include -#include -#include -#include - -#if !defined (pgm_read_byte) - #if __has_include() - #include - #elif __has_include() - #include - #else - #define pgm_read_byte(addr) (*(const std::uint8_t *)((std::size_t)addr)) - #define pgm_read_word(addr) (*(const std::uint16_t *)((std::size_t)addr)) - #define pgm_read_dword(addr) (*(const std::uint32_t *)((std::size_t)addr)) - #endif -#endif +#include +#include +#include +#include "../internal/algorithm.h" + +#include "../utility/pgmspace.h" #ifndef PROGMEM #define PROGMEM @@ -37,16 +27,16 @@ namespace lgfx { struct glcd_fontinfo_t { - std::uint8_t start; - std::uint8_t end; - std::uint8_t datawidth; + uint8_t start; + uint8_t end; + uint8_t datawidth; }; - std::size_t IFont::drawCharDummy(LGFXBase* gfx, std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, const TextStyle* style, std::int32_t& filled_x) const + size_t IFont::drawCharDummy(LGFXBase* gfx, int32_t x, int32_t y, int32_t w, int32_t h, const TextStyle* style, int32_t& filled_x) const { - std::int32_t sx = 65536 * style->size_x; + int32_t sx = 65536 * style->size_x; w = (w * sx) >> 16; - std::int32_t sy = 65536 * style->size_y; + int32_t sy = 65536 * style->size_y; h = (h * sy) >> 16; gfx->startWrite(); if (style->fore_rgb888 != style->back_rgb888) @@ -78,13 +68,14 @@ namespace lgfx metrics->y_advance = y_advance; } - bool GLCDfont::updateFontMetric(FontMetrics*, std::uint16_t uniCode) const { + bool GLCDfont::updateFontMetric(FontMetrics*, uint16_t uniCode) const { auto info = reinterpret_cast(widthtbl); return info->start <= uniCode && uniCode <= info->end; } - std::size_t GLCDfont::drawChar(LGFXBase* gfx, std::int32_t x, std::int32_t y, std::uint16_t c, const TextStyle* style, FontMetrics* metrics, std::int32_t& filled_x) const + size_t GLCDfont::drawChar(LGFXBase* gfx, int32_t x, int32_t y, uint16_t c, const TextStyle* style, FontMetrics* metrics, int32_t& filled_x) const { + (void)metrics; auto info = reinterpret_cast(widthtbl); if (c < pgm_read_byte(&info->start) || pgm_read_byte(&info->end) < c) { @@ -97,35 +88,35 @@ namespace lgfx c -= pgm_read_byte(&info->start); - const std::int32_t fontWidth = this->width; - const std::int32_t fontHeight = this->height; + const int32_t fontWidth = this->width; + const int32_t fontHeight = this->height; const auto datawidth = pgm_read_byte(&info->datawidth); auto font_addr = this->chartbl + (c * datawidth); auto cc = gfx->getColorConverter(); bool fillbg = (style->back_rgb888 != style->fore_rgb888); - std::uint32_t colortbl[2] = { cc->convert(style->back_rgb888), cc->convert(style->fore_rgb888) }; + uint32_t colortbl[2] = { cc->convert(style->back_rgb888), cc->convert(style->fore_rgb888) }; - const std::int32_t sy = 65536 * style->size_y; - const std::int32_t sx = 65536 * style->size_x; + const int32_t sy = 65536 * style->size_y; + const int32_t sx = 65536 * style->size_x; gfx->startWrite(); - std::uint32_t x1 = 0; - std::int_fast8_t i = 0; + uint32_t x1 = 0; + int_fast8_t i = 0; do { - std::uint_fast8_t line = pgm_read_byte(&font_addr[i]); - std::uint_fast8_t flg = (line & 0x01); - std::int_fast8_t j = 1; - std::uint32_t y1 = 0; - std::uint32_t x0 = x1; + uint_fast8_t line = pgm_read_byte(&font_addr[i]); + uint_fast8_t flg = (line & 0x01); + int_fast8_t j = 1; + uint32_t y1 = 0; + uint32_t x0 = x1; x1 = (++i * sx) >> 16; - std::uint32_t w = x1 - x0; + uint32_t w = x1 - x0; do { while (flg == ((line >> j) & 0x01) && ++j < fontHeight); - std::uint32_t y0 = y1; + uint32_t y0 = y1; y1 = (j * sy) >> 16; if (flg || fillbg) { @@ -137,7 +128,7 @@ namespace lgfx x += w; } while (i < datawidth); - std::uint32_t x2 = (fontWidth * sx) >> 16; + uint32_t x2 = (fontWidth * sx) >> 16; if (fillbg && datawidth < fontWidth) { gfx->setRawColor(colortbl[0]); @@ -148,18 +139,18 @@ namespace lgfx return x2; } - static std::size_t draw_char_bmp(LGFXBase* gfx, std::int32_t x, std::int32_t y, const TextStyle* style, const std::uint8_t* font_addr, std::int_fast8_t fontWidth, std::int_fast8_t fontHeight, std::int_fast8_t w, std::int_fast8_t margin) + static size_t draw_char_bmp(LGFXBase* gfx, int32_t x, int32_t y, const TextStyle* style, const uint8_t* font_addr, int_fast8_t fontWidth, int_fast8_t fontHeight, int_fast8_t w, int_fast8_t margin) { - std::uint32_t colortbl[2] = {gfx->getColorConverter()->convert(style->back_rgb888), gfx->getColorConverter()->convert(style->fore_rgb888)}; + uint32_t colortbl[2] = {gfx->getColorConverter()->convert(style->back_rgb888), gfx->getColorConverter()->convert(style->fore_rgb888)}; bool fillbg = (style->back_rgb888 != style->fore_rgb888); - //std::int32_t clip_left = gfx->_clip_l; - //std::int32_t clip_right = gfx->_clip_r; - //std::int32_t clip_top = gfx->_clip_t; - //std::int32_t clip_bottom = gfx->_clip_b; + //int32_t clip_left = gfx->_clip_l; + //int32_t clip_right = gfx->_clip_r; + //int32_t clip_top = gfx->_clip_t; + //int32_t clip_bottom = gfx->_clip_b; - std::int32_t sx = 65536 * style->size_x; - std::int32_t sy = 65536 * style->size_y; + int32_t sx = 65536 * style->size_x; + int32_t sy = 65536 * style->size_y; //if ((x <= clip_right) && (clip_left < (x + fontWidth * sx )) // && (y <= clip_bottom) && (clip_top < (y + sh ))) @@ -167,32 +158,32 @@ namespace lgfx gfx->startWrite(); if (fillbg && margin) { - std::int32_t x0 = ((fontWidth - margin) * sx) >> 16; - std::int32_t x1 = ((fontWidth ) * sx) >> 16; + int32_t x0 = ((fontWidth - margin) * sx) >> 16; + int32_t x1 = ((fontWidth ) * sx) >> 16; if (x0 < x1) { gfx->setRawColor(colortbl[0]); gfx->writeFillRect(x + x0, y, x1 - x0, (fontHeight * sy) >> 16); } } - std::int32_t i = 0; - std::int32_t y1 = 0; - std::int32_t y0 = - 1; - std::int32_t height = (sy * fontHeight) >> 16; + int32_t i = 0; + int32_t y1 = 0; + int32_t y0 = - 1; + int32_t height = (sy * fontHeight) >> 16; do { bool fill = y0 != y1; y0 = y1; y1 = (++i * sy) >> 16; - std::int32_t h = (y1 < height && y0 == y1) ? 1 : (y1 - y0); - std::uint8_t line = pgm_read_byte(&font_addr[0]); + int32_t h = (y1 < height && y0 == y1) ? 1 : (y1 - y0); + uint8_t line = pgm_read_byte(&font_addr[0]); bool flg = line & 0x80; - std::int_fast8_t j = 1; - std::int_fast8_t je = fontWidth - margin; - std::int32_t x0 = 0; + int_fast8_t j = 1; + int_fast8_t je = fontWidth - margin; + int32_t x0 = 0; do { do { if (0 == (j & 7)) line = pgm_read_byte(&font_addr[j >> 3]); } while (flg == (bool)(line & (0x80) >> (j&7)) && ++j < je); - std::int32_t x1 = (j * sx) >> 16; + int32_t x1 = (j * sx) >> 16; if (flg || (fillbg && fill)) { gfx->setRawColor(colortbl[flg]); if (flg && x1 == x0) ++x1; @@ -210,27 +201,28 @@ namespace lgfx } - bool FixedBMPfont::updateFontMetric(FontMetrics *metrics, std::uint16_t uniCode) const { + bool FixedBMPfont::updateFontMetric(FontMetrics *metrics, uint16_t uniCode) const { metrics->x_advance = metrics->width = this->width; auto info = reinterpret_cast(widthtbl); return info->start <= uniCode && uniCode <= info->end; } - bool BMPfont::updateFontMetric(FontMetrics *metrics, std::uint16_t uniCode) const { + bool BMPfont::updateFontMetric(FontMetrics *metrics, uint16_t uniCode) const { bool res = ((uniCode -= 0x20u) < 0x60u); if (!res) uniCode = 0; metrics->x_advance = metrics->width = pgm_read_byte(&this->widthtbl[uniCode]); return res; } - bool BDFfont::updateFontMetric(FontMetrics *metrics, std::uint16_t uniCode) const { + bool BDFfont::updateFontMetric(FontMetrics *metrics, uint16_t uniCode) const { metrics->x_advance = metrics->width = (uniCode < 0x0100) ? halfwidth : width; return true; } - std::size_t FixedBMPfont::drawChar(LGFXBase* gfx, std::int32_t x, std::int32_t y, std::uint16_t uniCode, const TextStyle* style, FontMetrics* metrics, std::int32_t& filled_x) const + size_t FixedBMPfont::drawChar(LGFXBase* gfx, int32_t x, int32_t y, uint16_t uniCode, const TextStyle* style, FontMetrics* metrics, int32_t& filled_x) const { // BMP font - const std::int_fast16_t fontHeight = this->height; + (void)metrics; + const int_fast16_t fontHeight = this->height; auto info = reinterpret_cast(widthtbl); if (info->start > uniCode || uniCode > info->end) { return drawCharDummy(gfx, x, y, width, fontHeight, style, filled_x); } @@ -240,62 +232,65 @@ namespace lgfx uniCode++; // Handle 'classic' charset behavior } uniCode -= info->start; - std::int_fast8_t w = (width + 7) >> 3; - auto font_addr = (const std::uint8_t*) &chartbl[uniCode * w * fontHeight]; + int_fast8_t w = (width + 7) >> 3; + auto font_addr = (const uint8_t*) &chartbl[uniCode * w * fontHeight]; return draw_char_bmp(gfx, x, y, style, font_addr, width, fontHeight, (width + 7) >> 3, 0); } - std::size_t BMPfont::drawChar(LGFXBase* gfx, std::int32_t x, std::int32_t y, std::uint16_t uniCode, const TextStyle* style, FontMetrics* metrics, std::int32_t& filled_x) const + size_t BMPfont::drawChar(LGFXBase* gfx, int32_t x, int32_t y, uint16_t uniCode, const TextStyle* style, FontMetrics* metrics, int32_t& filled_x) const { // BMP font + (void)metrics; if ((uniCode -= 0x20u) >= 0x60u) return drawCharDummy(gfx, x, y, this->widthtbl[0], this->height, style, filled_x); - const std::int_fast8_t fontWidth = pgm_read_byte(&this->widthtbl[uniCode]); - const std::int_fast8_t fontHeight = this->height; + const int_fast8_t fontWidth = pgm_read_byte(&this->widthtbl[uniCode]); + const int_fast8_t fontHeight = this->height; - auto font_addr = ((const std::uint8_t**)this->chartbl)[uniCode]; + auto font_addr = ((const uint8_t**)this->chartbl)[uniCode]; return draw_char_bmp(gfx, x, y, style, font_addr, fontWidth, fontHeight, (fontWidth + 6) >> 3, 1); } - std::size_t BDFfont::drawChar(LGFXBase* gfx, std::int32_t x, std::int32_t y, std::uint16_t c, const TextStyle* style, FontMetrics* metrics, std::int32_t& filled_x) const + size_t BDFfont::drawChar(LGFXBase* gfx, int32_t x, int32_t y, uint16_t c, const TextStyle* style, FontMetrics* metrics, int32_t& filled_x) const { - const std::int_fast8_t bytesize = (this->width + 7) >> 3; - const std::int_fast8_t fontHeight = this->height; - const std::int_fast8_t fontWidth = (c < 0x0100) ? this->halfwidth : this->width; + (void)metrics; + const int_fast8_t bytesize = (this->width + 7) >> 3; + const int_fast8_t fontHeight = this->height; + const int_fast8_t fontWidth = (c < 0x0100) ? this->halfwidth : this->width; auto it = std::lower_bound(this->indextbl, &this->indextbl[this->indexsize], c); if (*it != c) return drawCharDummy(gfx, x, y, fontWidth, fontHeight, style, filled_x); - const std::uint8_t* font_addr = &this->chartbl[std::distance(this->indextbl, it) * fontHeight * bytesize]; + const uint8_t* font_addr = &this->chartbl[std::distance(this->indextbl, it) * fontHeight * bytesize]; return draw_char_bmp(gfx, x, y, style, font_addr, fontWidth, fontHeight, bytesize, 0); } - std::size_t RLEfont::drawChar(LGFXBase* gfx, std::int32_t x, std::int32_t y, std::uint16_t code, const TextStyle* style, FontMetrics* metrics, std::int32_t& filled_x) const + size_t RLEfont::drawChar(LGFXBase* gfx, int32_t x, int32_t y, uint16_t code, const TextStyle* style, FontMetrics* metrics, int32_t& filled_x) const { // RLE font + (void)metrics; if ((code -= 0x20u) >= 0x60u) return drawCharDummy(gfx, x, y, this->widthtbl[0], this->height, style, filled_x); - const std::uint_fast16_t fontWidth = pgm_read_byte(&this->widthtbl[code]); - const std::uint_fast16_t fontHeight = this->height; + const uint_fast16_t fontWidth = pgm_read_byte(&this->widthtbl[code]); + const uint_fast16_t fontHeight = this->height; - auto font_addr = ((const std::uint8_t**)this->chartbl)[code]; + auto font_addr = ((const uint8_t**)this->chartbl)[code]; - std::uint32_t colortbl[2] = {gfx->getColorConverter()->convert(style->back_rgb888), gfx->getColorConverter()->convert(style->fore_rgb888)}; + uint32_t colortbl[2] = {gfx->getColorConverter()->convert(style->back_rgb888), gfx->getColorConverter()->convert(style->fore_rgb888)}; bool fillbg = (style->back_rgb888 != style->fore_rgb888); - //std::int32_t clip_left = gfx->_clip_l; - //std::int32_t clip_right = gfx->_clip_r; - //std::int32_t clip_top = gfx->_clip_t; - //std::int32_t clip_bottom = gfx->_clip_b; + //int32_t clip_left = gfx->_clip_l; + //int32_t clip_right = gfx->_clip_r; + //int32_t clip_top = gfx->_clip_t; + //int32_t clip_bottom = gfx->_clip_b; - std::int32_t sx = 65536 * style->size_x; - std::int32_t sy = 65536 * style->size_y; + int32_t sx = 65536 * style->size_x; + int32_t sy = 65536 * style->size_y; //if ((x <= clip_right) && (clip_left < (x + fontWidth * sx )) // && (y <= clip_bottom) && (clip_top < (y + fontHeight * sy ))) { bool flg = false; - std::uint_fast8_t line = 0, i = 1, j = 0; - std::int32_t len; - std::int32_t y0 = 0; - std::int32_t y1 = sy >> 16; - std::int32_t x0 = 0; + uint_fast8_t line = 0, i = 1, j = 0; + int32_t len; + int32_t y0 = 0; + int32_t y1 = sy >> 16; + int32_t x0 = 0; gfx->startWrite(); do { line = pgm_read_byte(font_addr++); @@ -305,7 +300,7 @@ namespace lgfx len = (line > fontWidth - j) ? fontWidth - j : line; line -= len; j += len; - std::int32_t x1 = (j * sx) >> 16; + int32_t x1 = (j * sx) >> 16; if (fillbg || flg) { gfx->setRawColor(colortbl[flg]); gfx->writeFillRect( x + x0, y + y0, x1 - x0, y1 - y0); @@ -329,7 +324,7 @@ namespace lgfx //---------------------------------------------------------------------------- - bool GFXfont::updateFontMetric(lgfx::FontMetrics *metrics, std::uint16_t uniCode) const { + bool GFXfont::updateFontMetric(lgfx::FontMetrics *metrics, uint16_t uniCode) const { auto glyph = getGlyph(uniCode); bool res = glyph; if (!res) @@ -348,10 +343,10 @@ namespace lgfx return res; } - GFXglyph* GFXfont::getGlyph(std::uint16_t uniCode) const { + GFXglyph* GFXfont::getGlyph(uint16_t uniCode) const { if (uniCode > last || uniCode < first) return nullptr; - std::uint16_t custom_range_num = range_num; + uint16_t custom_range_num = range_num; if (custom_range_num == 0) { uniCode -= first; return &glyph[uniCode]; @@ -368,14 +363,14 @@ namespace lgfx void GFXfont::getDefaultMetric(lgfx::FontMetrics *metrics) const { - std::int_fast8_t glyph_ab = 0; // glyph delta Y (height) above baseline - std::int_fast8_t glyph_bb = 0; // glyph delta Y (height) below baseline - std::size_t numChars = last - first; + int_fast8_t glyph_ab = 0; // glyph delta Y (height) above baseline + int_fast8_t glyph_bb = 0; // glyph delta Y (height) below baseline + size_t numChars = last - first; - std::size_t custom_range_num = range_num; + size_t custom_range_num = range_num; if (custom_range_num != 0) { EncodeRange *range_pst = range; - std::size_t i = 0; + size_t i = 0; numChars = custom_range_num; do { numChars += range_pst[i].end - range_pst[i].start; @@ -383,13 +378,13 @@ namespace lgfx } // Find the biggest above and below baseline offsets - std::size_t c = 0; + size_t c = 0; do { GFXglyph *glyph1 = &glyph[c]; - std::int_fast8_t ab = -glyph1->yOffset; + int_fast8_t ab = -glyph1->yOffset; if (ab > glyph_ab) glyph_ab = ab; - std::int_fast8_t bb = glyph1->height - ab; + int_fast8_t bb = glyph1->height - ab; if (bb > glyph_bb) glyph_bb = bb; } while ( ++c < numChars ); @@ -399,9 +394,9 @@ namespace lgfx metrics->y_advance = yAdvance; } - std::size_t GFXfont::drawChar(LGFXBase* gfx, std::int32_t x, std::int32_t y, std::uint16_t uniCode, const TextStyle* style, FontMetrics* metrics, std::int32_t& filled_x) const + size_t GFXfont::drawChar(LGFXBase* gfx, int32_t x, int32_t y, uint16_t uniCode, const TextStyle* style, FontMetrics* metrics, int32_t& filled_x) const { - std::int32_t sy = 65536 * style->size_y; + int32_t sy = 65536 * style->size_y; y += (metrics->y_offset * sy) >> 16; auto glyph = this->getGlyph(uniCode); if (!glyph) @@ -411,18 +406,18 @@ namespace lgfx return 0; } - std::int32_t w = glyph->width; - std::int32_t h = glyph->height; + int32_t w = glyph->width; + int32_t h = glyph->height; - std::int32_t sx = 65536 * style->size_x; + int32_t sx = 65536 * style->size_x; - std::int32_t xAdvance = sx * glyph->xAdvance >> 16; - std::int32_t xoffset = sx * glyph->xOffset >> 16; + int32_t xAdvance = sx * glyph->xAdvance >> 16; + int32_t xoffset = sx * glyph->xOffset >> 16; - std::uint32_t colortbl[2] = {gfx->getColorConverter()->convert(style->back_rgb888), gfx->getColorConverter()->convert(style->fore_rgb888)}; + uint32_t colortbl[2] = {gfx->getColorConverter()->convert(style->back_rgb888), gfx->getColorConverter()->convert(style->fore_rgb888)}; bool fillbg = (style->back_rgb888 != style->fore_rgb888); - std::int32_t left = 0; - std::int32_t right = 0; + int32_t left = 0; + int32_t right = 0; if (fillbg) { left = std::max(filled_x, x + (xoffset < 0 ? xoffset : 0)); right = x + std::max((w * sx >> 16) + xoffset, xAdvance); @@ -431,7 +426,7 @@ namespace lgfx } x += xoffset; - std::int32_t yoffset = (- metrics->y_offset) + glyph->yOffset; + int32_t yoffset = (- metrics->y_offset) + glyph->yOffset; gfx->startWrite(); @@ -439,27 +434,27 @@ namespace lgfx if (yoffset > 0) { gfx->writeFillRect(left, y, right - left, (yoffset * sy) >> 16); } - std::int32_t y0 = ((yoffset + h) * sy) >> 16; - std::int32_t y1 = (metrics->height * sy) >> 16; + int32_t y0 = ((yoffset + h) * sy) >> 16; + int32_t y1 = (metrics->height * sy) >> 16; if (y0 < y1) { gfx->writeFillRect(left, y + y0, right - left, y1 - y0); } } - std::uint8_t *bitmap = &this->bitmap[glyph->bitmapOffset]; - std::uint8_t mask=0x80; + uint8_t *bitmap = &this->bitmap[glyph->bitmapOffset]; + uint8_t mask=0x80; gfx->setRawColor(colortbl[1]); - std::int_fast8_t i = 0; - std::int32_t limit_height = ((h + yoffset) * sy) >> 16; - std::int32_t limit_width = ( w * sx) >> 16; - std::int32_t y1 = (yoffset * sy) >> 16; - std::int32_t y0 = y1 - 1; + int_fast8_t i = 0; + int32_t limit_height = ((h + yoffset) * sy) >> 16; + int32_t limit_width = ( w * sx) >> 16; + int32_t y1 = (yoffset * sy) >> 16; + int32_t y0 = y1 - 1; do { bool fill = y0 != y1; y0 = y1; y1 = ((++i + yoffset) * sy) >> 16; - std::int32_t fh = (y1 < limit_height && y1 == y0) ? 1 : (y1 - y0); + int32_t fh = (y1 < limit_height && y1 == y0) ? 1 : (y1 - y0); //if (!fh) fh = 1; if (left < right && fill) { gfx->setRawColor(colortbl[0]); @@ -467,8 +462,8 @@ namespace lgfx gfx->setRawColor(colortbl[1]); } - std::int32_t j = 0; - std::int32_t x0 = 0; + int32_t j = 0; + int32_t x0 = 0; bool flg = false; do { do { @@ -478,9 +473,9 @@ namespace lgfx ++bitmap; } } while (++j < w); - std::int32_t x1 = (j * sx) >> 16; + int32_t x1 = (j * sx) >> 16; if (flg) { - std::int32_t fw = (x1 < limit_width && x1 == x0) ? 1 : (x1 - x0); + int32_t fw = (x1 < limit_width && x1 == x0) ? 1 : (x1 - x0); gfx->writeFillRect(x + x0, y + y0, fw, fh); } x0 = x1; @@ -500,10 +495,10 @@ namespace lgfx const uint8_t* decode_ptr; /* pointer to the compressed data */ uint8_t decode_bit_pos; /* bitpos inside a byte of the compressed data */ - std::uint_fast8_t get_unsigned_bits(std::uint_fast8_t cnt) + uint_fast8_t get_unsigned_bits(uint_fast8_t cnt) { - std::uint_fast8_t bit_pos = this->decode_bit_pos; - std::uint_fast8_t val = *(this->decode_ptr) >> bit_pos; + uint_fast8_t bit_pos = this->decode_bit_pos; + uint_fast8_t val = *(this->decode_ptr) >> bit_pos; auto bit_pos_plus_cnt = bit_pos + cnt; if ( bit_pos_plus_cnt >= 8 ) @@ -515,14 +510,14 @@ namespace lgfx return val & ((1U << cnt) - 1); } - std::int_fast8_t get_signed_bits(std::uint_fast8_t cnt) + int_fast8_t get_signed_bits(uint_fast8_t cnt) { - return (std::int_fast8_t)get_unsigned_bits(cnt) - (1 << (cnt-1)); + return (int_fast8_t)get_unsigned_bits(cnt) - (1 << (cnt-1)); } }; - const uint8_t* U8g2font::getGlyph(std::uint16_t encoding) const + const uint8_t* U8g2font::getGlyph(uint16_t encoding) const { const uint8_t *font = &this->_font[23]; @@ -568,7 +563,7 @@ namespace lgfx metrics->x_offset = 0; } - bool U8g2font::updateFontMetric(lgfx::FontMetrics *metrics, std::uint16_t uniCode) const + bool U8g2font::updateFontMetric(lgfx::FontMetrics *metrics, uint16_t uniCode) const { u8g2_font_decode_t decode(getGlyph(uniCode)); if ( decode.decode_ptr ) @@ -585,28 +580,28 @@ namespace lgfx return false; } - std::size_t U8g2font::drawChar(LGFXBase* gfx, std::int32_t x, std::int32_t y, std::uint16_t uniCode, const TextStyle* style, FontMetrics* metrics, std::int32_t& filled_x) const + size_t U8g2font::drawChar(LGFXBase* gfx, int32_t x, int32_t y, uint16_t uniCode, const TextStyle* style, FontMetrics* metrics, int32_t& filled_x) const { - std::int32_t sy = 65536 * style->size_y; + int32_t sy = 65536 * style->size_y; y += (metrics->y_offset * sy) >> 16; u8g2_font_decode_t decode(getGlyph(uniCode)); if ( decode.decode_ptr == nullptr ) return drawCharDummy(gfx, x, y, this->max_char_width(), metrics->height, style, filled_x); - std::uint32_t w = decode.get_unsigned_bits(bits_per_char_width()); - std::uint32_t h = decode.get_unsigned_bits(bits_per_char_height()); + uint32_t w = decode.get_unsigned_bits(bits_per_char_width()); + uint32_t h = decode.get_unsigned_bits(bits_per_char_height()); - std::int32_t sx = 65536 * style->size_x; + int32_t sx = 65536 * style->size_x; - std::int32_t xoffset = (decode.get_signed_bits(bits_per_char_x()) * sx) >> 16; + int32_t xoffset = (decode.get_signed_bits(bits_per_char_x()) * sx) >> 16; - std::int32_t yoffset = -(decode.get_signed_bits(bits_per_char_y()) + h + metrics->y_offset); + int32_t yoffset = -(decode.get_signed_bits(bits_per_char_y()) + h + metrics->y_offset); - std::int32_t xAdvance = (decode.get_signed_bits(bits_per_delta_x()) * sx) >> 16; + int32_t xAdvance = (decode.get_signed_bits(bits_per_delta_x()) * sx) >> 16; - std::uint32_t colortbl[2] = {gfx->getColorConverter()->convert(style->back_rgb888), gfx->getColorConverter()->convert(style->fore_rgb888)}; + uint32_t colortbl[2] = {gfx->getColorConverter()->convert(style->back_rgb888), gfx->getColorConverter()->convert(style->fore_rgb888)}; bool fillbg = (style->back_rgb888 != style->fore_rgb888); - std::int32_t left = 0; - std::int32_t right = 0; + int32_t left = 0; + int32_t right = 0; if (fillbg) { left = std::max(filled_x, x + (xoffset < 0 ? xoffset : 0)); right = x + std::max(((w * sx) >> 16) + xoffset, xAdvance); @@ -621,8 +616,8 @@ namespace lgfx if (yoffset > 0) { gfx->writeFillRect(left, y, right - left, (yoffset * sy) >> 16); } - std::int32_t y0 = ((yoffset + h) * sy) >> 16; - std::int32_t y1 = (metrics->height * sy) >> 16; + int32_t y0 = ((yoffset + h) * sy) >> 16; + int32_t y1 = (metrics->height * sy) >> 16; if (y0 < y1) { gfx->writeFillRect(left, y + y0, right - left, y1 - y0); } @@ -632,24 +627,24 @@ namespace lgfx { if (left < right) { - std::int32_t y0 = ( yoffset * sy) >> 16; - std::int32_t len = (((yoffset + h) * sy) >> 16) - y0; + int32_t y0 = ( yoffset * sy) >> 16; + int32_t len = (((yoffset + h) * sy) >> 16) - y0; if (left < x) { gfx->writeFillRect(left, y + y0, x - left, len); } - std::int32_t xwsx = x + ((w * sx) >> 16); + int32_t xwsx = x + ((w * sx) >> 16); if (xwsx < right) { gfx->writeFillRect(xwsx, y + y0, right - xwsx, len); } } left -= x; - std::uint32_t ab[2]; - std::uint32_t lx = 0; - std::uint32_t ly = 0; - std::int32_t y0 = ((yoffset ) * sy) >> 16; - std::int32_t y1 = ((yoffset + 1) * sy) >> 16; + uint32_t ab[2]; + uint32_t lx = 0; + uint32_t ly = 0; + int32_t y0 = ((yoffset ) * sy) >> 16; + int32_t y1 = ((yoffset + 1) * sy) >> 16; do { ab[0] = decode.get_unsigned_bits(bits_per_0()); @@ -657,16 +652,16 @@ namespace lgfx bool i = 0; do { - std::uint32_t length = ab[i]; + uint32_t length = ab[i]; while (length) { - std::uint32_t len = (length > w - lx) ? w - lx : length; + uint32_t len = (length > w - lx) ? w - lx : length; length -= len; if (i || fillbg) { - std::int32_t x0 = (lx * sx) >> 16; + int32_t x0 = (lx * sx) >> 16; if (!i && x0 < left) x0 = left; - std::int32_t x1 = ((lx + len) * sx) >> 16; + int32_t x1 = ((lx + len) * sx) >> 16; if (x0 < x1) { gfx->setRawColor(colortbl[i]); @@ -725,7 +720,7 @@ namespace lgfx return true; } - bool VLWfont::getUnicodeIndex(std::uint16_t unicode, std::uint16_t *index) const + bool VLWfont::getUnicodeIndex(uint16_t unicode, uint16_t *index) const { if (gUnicode[gCount-1] < unicode) return false; auto poi = std::lower_bound(gUnicode, &gUnicode[gCount], unicode); @@ -733,8 +728,8 @@ namespace lgfx return (*poi == unicode); } - bool VLWfont::updateFontMetric(FontMetrics *metrics, std::uint16_t uniCode) const { - std::uint16_t gNum = 0; + bool VLWfont::updateFontMetric(FontMetrics *metrics, uint16_t uniCode) const { + uint16_t gNum = 0; if (getUnicodeIndex(uniCode, &gNum)) { if (gWidth && gxAdvance && gdX[gNum]) { metrics->width = gWidth[gNum]; @@ -746,11 +741,11 @@ namespace lgfx file->preRead(); file->seek(28 + gNum * 28); // headerPtr - std::uint32_t buffer[6]; - file->read((std::uint8_t*)buffer, 24); + uint32_t buffer[6]; + file->read((uint8_t*)buffer, 24); metrics->width = __builtin_bswap32(buffer[1]); // Width of glyph metrics->x_advance = __builtin_bswap32(buffer[2]); // xAdvance - to move x cursor - metrics->x_offset = (std::int32_t)((std::int8_t)__builtin_bswap32(buffer[4])); // x delta from cursor + metrics->x_offset = (int32_t)((int8_t)__builtin_bswap32(buffer[4])); // x delta from cursor file->postRead(); } @@ -765,8 +760,8 @@ namespace lgfx bool VLWfont::loadFont(DataWrapper* data) { _fontData = data; { - std::uint32_t buf[6]; - data->read((std::uint8_t*)buf, 6 * 4); // 24 Byte read + uint32_t buf[6]; + data->read((uint8_t*)buf, 6 * 4); // 24 Byte read gCount = __builtin_bswap32(buf[0]); // glyph count in file //__builtin_bswap32(buf[1]); // vlw encoder version - discard @@ -788,19 +783,19 @@ namespace lgfx //ESP_LOGI("LGFX", "font count:%d", gCount); - std::uint32_t bitmapPtr = 24 + (std::uint32_t)gCount * 28; + uint32_t bitmapPtr = 24 + (uint32_t)gCount * 28; - gBitmap = (std::uint32_t*)heap_alloc_psram( gCount * 4); // seek pointer to glyph bitmap in the file - gUnicode = (std::uint16_t*)heap_alloc_psram( gCount * 2); // Unicode 16 bit Basic Multilingual Plane (0-FFFF) - gWidth = (std::uint8_t*)heap_alloc_psram( gCount ); // Width of glyph - gxAdvance = (std::uint8_t*)heap_alloc_psram( gCount ); // xAdvance - to move x cursor - gdX = (std::int8_t*)heap_alloc_psram( gCount ); // offset for bitmap left edge relative to cursor X + gBitmap = (uint32_t*)heap_alloc_psram( gCount * 4); // seek pointer to glyph bitmap in the file + gUnicode = (uint16_t*)heap_alloc_psram( gCount * 2); // Unicode 16 bit Basic Multilingual Plane (0-FFFF) + gWidth = (uint8_t*)heap_alloc_psram( gCount ); // Width of glyph + gxAdvance = (uint8_t*)heap_alloc_psram( gCount ); // xAdvance - to move x cursor + gdX = (int8_t*)heap_alloc_psram( gCount ); // offset for bitmap left edge relative to cursor X - if (nullptr == gBitmap ) gBitmap = (std::uint32_t*)heap_alloc( gCount * 4); // seek pointer to glyph bitmap in the file - if (nullptr == gUnicode ) gUnicode = (std::uint16_t*)heap_alloc( gCount * 2); // Unicode 16 bit Basic Multilingual Plane (0-FFFF) - if (nullptr == gWidth ) gWidth = (std::uint8_t*)heap_alloc( gCount ); // Width of glyph - if (nullptr == gxAdvance) gxAdvance = (std::uint8_t*)heap_alloc( gCount ); // xAdvance - to move x cursor - if (nullptr == gdX ) gdX = (std::int8_t*)heap_alloc( gCount ); // offset for bitmap left edge relative to cursor X + if (nullptr == gBitmap ) gBitmap = (uint32_t*)heap_alloc( gCount * 4); // seek pointer to glyph bitmap in the file + if (nullptr == gUnicode ) gUnicode = (uint16_t*)heap_alloc( gCount * 2); // Unicode 16 bit Basic Multilingual Plane (0-FFFF) + if (nullptr == gWidth ) gWidth = (uint8_t*)heap_alloc( gCount ); // Width of glyph + if (nullptr == gxAdvance) gxAdvance = (uint8_t*)heap_alloc( gCount ); // xAdvance - to move x cursor + if (nullptr == gdX ) gdX = (int8_t*)heap_alloc( gCount ); // offset for bitmap left edge relative to cursor X if (!gUnicode || !gBitmap @@ -815,19 +810,19 @@ namespace lgfx size_t gNum = 0; _fontData->seek(24); // headerPtr - std::uint32_t buffer[7]; + uint32_t buffer[7]; do { - _fontData->read((std::uint8_t*)buffer, 7 * 4); // 28 Byte read - std::uint16_t unicode = __builtin_bswap32(buffer[0]); // Unicode code point value - std::uint32_t w = (std::uint8_t)__builtin_bswap32(buffer[2]); // Width of glyph + _fontData->read((uint8_t*)buffer, 7 * 4); // 28 Byte read + uint16_t unicode = __builtin_bswap32(buffer[0]); // Unicode code point value + uint32_t w = (uint8_t)__builtin_bswap32(buffer[2]); // Width of glyph if (gUnicode) gUnicode[gNum] = unicode; if (gWidth) gWidth[gNum] = w; - if (gxAdvance) gxAdvance[gNum] = (std::uint8_t)__builtin_bswap32(buffer[3]); // xAdvance - to move x cursor - if (gdX) gdX[gNum] = (std::int8_t)__builtin_bswap32(buffer[5]); // x delta from cursor + if (gxAdvance) gxAdvance[gNum] = (uint8_t)__builtin_bswap32(buffer[3]); // xAdvance - to move x cursor + if (gdX) gdX[gNum] = (int8_t)__builtin_bswap32(buffer[5]); // x delta from cursor - std::uint16_t height = __builtin_bswap32(buffer[1]); // Height of glyph + uint16_t height = __builtin_bswap32(buffer[1]); // Height of glyph if ((unicode > 0xFF) || ((unicode > 0x20) && (unicode < 0xA0) && (unicode != 0x7F))) { - std::int16_t dY = (std::int16_t)__builtin_bswap32(buffer[4]); // y delta from baseline + int16_t dY = (int16_t)__builtin_bswap32(buffer[4]); // y delta from baseline //Serial.printf("LGFX:unicode:%x dY:%d\r\n", unicode, dY); if (maxAscent < dY && unicode != 0x3000) { maxAscent = dY; @@ -850,14 +845,14 @@ namespace lgfx //---------------------------------------------------------------------------- - std::size_t VLWfont::drawChar(LGFXBase* gfx, std::int32_t x, std::int32_t y, std::uint16_t code, const TextStyle* style, FontMetrics* metrics, std::int32_t& filled_x) const + size_t VLWfont::drawChar(LGFXBase* gfx, int32_t x, int32_t y, uint16_t code, const TextStyle* style, FontMetrics* metrics, int32_t& filled_x) const { auto file = this->_fontData; - std::uint32_t buffer[6] = {0}; - std::uint16_t gNum = 0; + uint32_t buffer[6] = {0}; + uint16_t gNum = 0; - std::int32_t sy = 65536 * style->size_y; + int32_t sy = 65536 * style->size_y; y += (metrics->y_offset * sy) >> 16; if (code == 0x20) { @@ -868,22 +863,21 @@ namespace lgfx } else { file->preRead(); file->seek(28 + gNum * 28); - file->read((std::uint8_t*)buffer, 24); + file->read((uint8_t*)buffer, 24); file->seek(this->gBitmap[gNum]); } - std::int32_t h = __builtin_bswap32(buffer[0]); // Height of glyph - std::int32_t w = __builtin_bswap32(buffer[1]); // Width of glyph - std::int32_t sx = 65536 * style->size_x; - std::int32_t xAdvance = (__builtin_bswap32(buffer[2]) * sx) >> 16; // xAdvance - to move x cursor - std::int32_t xoffset = ((std::int32_t)((std::int8_t)__builtin_bswap32(buffer[4])) * sx) >> 16; // x delta from cursor - std::int32_t dY = (std::int16_t)__builtin_bswap32(buffer[3]); // y delta from baseline - std::int32_t yoffset = (this->maxAscent - dY); -// std::int32_t yoffset = (gfx->_font_metrics.y_offset) - dY; + int32_t h = __builtin_bswap32(buffer[0]); // Height of glyph + int32_t w = __builtin_bswap32(buffer[1]); // Width of glyph + int32_t sx = 65536 * style->size_x; + int32_t xAdvance = (__builtin_bswap32(buffer[2]) * sx) >> 16; // xAdvance - to move x cursor + int32_t xoffset = ((int32_t)((int8_t)__builtin_bswap32(buffer[4])) * sx) >> 16; // x delta from cursor + int32_t dY = (int16_t)__builtin_bswap32(buffer[3]); // y delta from baseline + int32_t yoffset = (this->maxAscent - dY); +// int32_t yoffset = (gfx->_font_metrics.y_offset) - dY; - std::uint8_t pbuffer[w * h]; - std::uint8_t* pixel = pbuffer; + auto pixel = (uint8_t*)alloca(w * h); if (gNum != 0xFFFF) { file->read(pixel, w * h); file->postRead(); @@ -891,10 +885,10 @@ namespace lgfx gfx->startWrite(); - std::uint32_t colortbl[2] = {gfx->getColorConverter()->convert(style->back_rgb888), gfx->getColorConverter()->convert(style->fore_rgb888)}; + uint32_t colortbl[2] = {gfx->getColorConverter()->convert(style->back_rgb888), gfx->getColorConverter()->convert(style->fore_rgb888)}; bool fillbg = (style->back_rgb888 != style->fore_rgb888); - std::int32_t left = 0; - std::int32_t right = 0; + int32_t left = 0; + int32_t right = 0; if (fillbg) { left = std::max(filled_x, x + (xoffset < 0 ? xoffset : 0)); right = x + std::max(((w * sx) >> 16) + xoffset, xAdvance); @@ -902,26 +896,26 @@ namespace lgfx } x += xoffset; - std::int32_t clip_left; - std::int32_t clip_top; - std::int32_t clip_w; - std::int32_t clip_h; + int32_t clip_left; + int32_t clip_top; + int32_t clip_w; + int32_t clip_h; gfx->getClipRect(&clip_left, &clip_top, &clip_w, &clip_h); - std::int32_t clip_right = clip_left + clip_w-1; - std::int32_t clip_bottom = clip_top + clip_h-1; + int32_t clip_right = clip_left + clip_w-1; + int32_t clip_bottom = clip_top + clip_h-1; - std::int32_t bx = x; - std::int32_t bw = (w * sx) >> 16; + int32_t bx = x; + int32_t bw = (w * sx) >> 16; if (x < clip_left) { bw += (x - clip_left); bx = clip_left; } if (bw > clip_right+1 - bx) bw = clip_right+1 - bx; if (bw >= 0) { - std::int32_t fore_r = ((style->fore_rgb888>>16)&0xFF); - std::int32_t fore_g = ((style->fore_rgb888>> 8)&0xFF); - std::int32_t fore_b = ((style->fore_rgb888) &0xFF); + int32_t fore_r = ((style->fore_rgb888>>16)&0xFF); + int32_t fore_g = ((style->fore_rgb888>> 8)&0xFF); + int32_t fore_b = ((style->fore_rgb888) &0xFF); if (fillbg || !gfx->isReadable() || gfx->hasPalette()) { // fill background mode or unreadable panel or palette sprite mode @@ -930,8 +924,8 @@ namespace lgfx if (yoffset > 0) { gfx->writeFillRect(left, y, right - left, (yoffset * sy) >> 16); } - std::int32_t y0 = ((yoffset + h) * sy) >> 16; - std::int32_t y1 = (metrics->height * sy) >> 16; + int32_t y0 = ((yoffset + h) * sy) >> 16; + int32_t y1 = (metrics->height * sy) >> 16; if (y0 < y1) { gfx->writeFillRect(left, y + y0, right - left, y1 - y0); } @@ -939,11 +933,11 @@ namespace lgfx if (0 < w) { uint32_t back = fillbg ? style->back_rgb888 : gfx->getBaseColor(); - std::int32_t back_r = ((back>>16)&0xFF); - std::int32_t back_g = ((back>> 8)&0xFF); - std::int32_t back_b = ( back &0xFF); - std::int32_t i = 0; - std::int32_t y0, y1 = (yoffset * sy) >> 16; + int32_t back_r = ((back>>16)&0xFF); + int32_t back_g = ((back>> 8)&0xFF); + int32_t back_b = ( back &0xFF); + int32_t i = 0; + int32_t y0, y1 = (yoffset * sy) >> 16; do { y0 = y1; if (y0 > clip_bottom) break; @@ -952,13 +946,13 @@ namespace lgfx gfx->setRawColor(colortbl[0]); gfx->writeFillRect(left, y + y0, right - left, y1 - y0); } - std::int32_t j = 0; + int32_t j = 0; do { - std::int32_t x0 = (j * sx) >> 16; + int32_t x0 = (j * sx) >> 16; while (pixel[j] != 0xFF) { - std::int32_t x1 = ((j + 1) * sx) >> 16; + int32_t x1 = ((j + 1) * sx) >> 16; if (pixel[j] != 0 && x0 < x1) { - std::int32_t p = 1 + (std::uint32_t)pixel[j]; + int32_t p = 1 + (uint32_t)pixel[j]; gfx->setColor(color888( ( fore_r * p + back_r * (257 - p)) >> 8 , ( fore_g * p + back_g * (257 - p)) >> 8 , ( fore_b * p + back_b * (257 - p)) >> 8 )); @@ -978,45 +972,46 @@ namespace lgfx } else // alpha blend mode { - bgr888_t buf[bw * ((sy + 65535) >> 16)]; + auto buf = (bgr888_t*)alloca((bw * ((sy + 65535) >> 16)) * sizeof(bgr888_t)); + pixelcopy_t p(buf, gfx->getColorConverter()->depth, rgb888_3Byte, gfx->hasPalette()); - std::int32_t y0, y1 = (yoffset * sy) >> 16; - std::int32_t i = 0; + int32_t y0, y1 = (yoffset * sy) >> 16; + int32_t i = 0; do { y0 = y1; if (y0 > clip_bottom) break; y1 = ((yoffset + i + 1) * sy) >> 16; - std::int32_t by = y + y0; - std::int32_t bh = y1 - y0; + int32_t by = y + y0; + int32_t bh = y1 - y0; if (by < clip_top) { bh += by - clip_top; by = clip_top; } if (bh > 0) { - std::int32_t j0 = 0; + int32_t j0 = 0; // search first and last pixel while (j0 != w && !pixel[j0 ]) { ++j0; } if (j0 != w) { - std::int32_t j1 = w; + int32_t j1 = w; while (j0 != j1 && !pixel[j1 - 1]) { --j1; } - std::int32_t rx = (j0 * sx) >> 16; - std::int32_t rw = (j1 * sx) >> 16; + int32_t rx = (j0 * sx) >> 16; + int32_t rw = (j1 * sx) >> 16; if (rx < bx -x) rx = bx -x; if (rw > bx+bw -x) rw = bx+bw -x; rw -= rx; if (0 < rw) { - gfx->readRectRGB(x + rx, by, rw, bh, (std::uint8_t*)buf); + gfx->readRectRGB(x + rx, by, rw, bh, (uint8_t*)buf); - std::int32_t x0, x1 = ((j0 * sx) >> 16) - rx; + int32_t x0, x1 = ((j0 * sx) >> 16) - rx; do { x0 = x1; if (x0 < 0) x0 = 0; x1 = (int)(((j0 + 1) * sx) >> 16) - rx; if (x1 > rw) x1 = rw; if (pixel[j0] && x0 < x1) { - std::int32_t p = 1 + pixel[j0]; + int32_t p = 1 + pixel[j0]; do { - std::int32_t yy = 0; + int32_t yy = 0; do { auto bgr = &buf[x0 + yy * rw]; bgr->r = ( fore_r * p + bgr->r * (257 - p)) >> 8; @@ -1142,9 +1137,9 @@ namespace lgfx #include "../Fonts/Ascii24x48.h" #include "../Fonts/Ascii8x16.h" - static constexpr std::uint8_t font0_info[] = { 0, 255, 5 }; // start code, end code, width - static constexpr std::uint8_t font8x8c64_info[] = { 32, 143, 8 }; // start code, end code, width - static constexpr std::uint8_t fontlib24x48_info[] = { 32, 126, 0 }; // start code, end code + static constexpr uint8_t font0_info[] = { 0, 255, 5 }; // start code, end code, width + static constexpr uint8_t font8x8c64_info[] = { 32, 143, 8 }; // start code, end code, width + static constexpr uint8_t fontlib24x48_info[] = { 32, 126, 0 }; // start code, end code const GLCDfont Font0 = { font , font0_info, 6, 8, 7 }; const BMPfont Font2 = { chrtbl_f16, widtbl_f16, 0, chr_hgt_f16, baseline_f16 }; diff --git a/src/lgfx/v1/lgfx_fonts.hpp b/src/lgfx/v1/lgfx_fonts.hpp index 7cd0c76..03ac8d8 100644 --- a/src/lgfx/v1/lgfx_fonts.hpp +++ b/src/lgfx/v1/lgfx_fonts.hpp @@ -1,8 +1,8 @@ #ifndef LGFX_FONTS_HPP_ #define LGFX_FONTS_HPP_ -#include -#include +#include +#include #include "misc/enum.hpp" namespace lgfx @@ -31,26 +31,26 @@ namespace lgfx virtual font_type_t getType(void) const { return font_type_t::ft_unknown; } virtual void getDefaultMetric(FontMetrics *metrics) const = 0; - virtual bool updateFontMetric(FontMetrics *metrics, std::uint16_t uniCode) const = 0; + virtual bool updateFontMetric(FontMetrics *metrics, uint16_t uniCode) const = 0; virtual bool unloadFont(void) { return false; } - virtual std::size_t drawChar(LGFXBase* gfx, std::int32_t x, std::int32_t y, std::uint16_t c, const TextStyle* style, FontMetrics* metrics, std::int32_t& filled_x) const = 0; + virtual size_t drawChar(LGFXBase* gfx, int32_t x, int32_t y, uint16_t c, const TextStyle* style, FontMetrics* metrics, int32_t& filled_x) const = 0; protected: - std::size_t drawCharDummy(LGFXBase* gfx, std::int32_t x, std::int32_t y, std::int32_t w, std::int32_t h, const TextStyle* style, std::int32_t& filled_x) const; + size_t drawCharDummy(LGFXBase* gfx, int32_t x, int32_t y, int32_t w, int32_t h, const TextStyle* style, int32_t& filled_x) const; }; struct BaseFont : public IFont { union { const void *void_chartbl; - const std::uint8_t *chartbl; + const uint8_t *chartbl; }; - const std::uint8_t *widthtbl; - const std::uint8_t width; - const std::uint8_t height; - const std::uint8_t baseline; + const uint8_t *widthtbl; + const uint8_t width; + const uint8_t height; + const uint8_t baseline; BaseFont() = default; - constexpr BaseFont(const void *chartbl, const std::uint8_t *widthtbl, std::uint8_t width, std::uint8_t height, std::uint8_t baseline) + constexpr BaseFont(const void *chartbl, const uint8_t *widthtbl, uint8_t width, uint8_t height, uint8_t baseline) : void_chartbl(chartbl ) , widthtbl (widthtbl ) , width (width ) @@ -61,42 +61,42 @@ namespace lgfx }; struct GLCDfont : public BaseFont { - constexpr GLCDfont(const void *chartbl, const std::uint8_t *widthtbl, std::uint8_t width, std::uint8_t height, std::uint8_t baseline) : BaseFont(chartbl, widthtbl, width, height, baseline ) {} + constexpr GLCDfont(const void *chartbl, const uint8_t *widthtbl, uint8_t width, uint8_t height, uint8_t baseline) : BaseFont(chartbl, widthtbl, width, height, baseline ) {} font_type_t getType(void) const override { return ft_glcd; } - bool updateFontMetric(FontMetrics *metrics, std::uint16_t uniCode) const override; - std::size_t drawChar(LGFXBase* gfx, std::int32_t x, std::int32_t y, std::uint16_t c, const TextStyle* style, FontMetrics* metrics, std::int32_t& filled_x) const override; + bool updateFontMetric(FontMetrics *metrics, uint16_t uniCode) const override; + size_t drawChar(LGFXBase* gfx, int32_t x, int32_t y, uint16_t c, const TextStyle* style, FontMetrics* metrics, int32_t& filled_x) const override; }; struct FixedBMPfont : public BaseFont { - constexpr FixedBMPfont(const void *chartbl, const std::uint8_t *widthtbl, std::uint8_t width, std::uint8_t height, std::uint8_t baseline) : BaseFont(chartbl, widthtbl, width, height, baseline ) {} + constexpr FixedBMPfont(const void *chartbl, const uint8_t *widthtbl, uint8_t width, uint8_t height, uint8_t baseline) : BaseFont(chartbl, widthtbl, width, height, baseline ) {} font_type_t getType(void) const override { return ft_bmp; } - bool updateFontMetric(FontMetrics *metrics, std::uint16_t uniCode) const override; - std::size_t drawChar(LGFXBase* gfx, std::int32_t x, std::int32_t y, std::uint16_t c, const TextStyle* style, FontMetrics* metrics, std::int32_t& filled_x) const override; + bool updateFontMetric(FontMetrics *metrics, uint16_t uniCode) const override; + size_t drawChar(LGFXBase* gfx, int32_t x, int32_t y, uint16_t c, const TextStyle* style, FontMetrics* metrics, int32_t& filled_x) const override; }; struct BMPfont : public BaseFont { - constexpr BMPfont(const void *chartbl, const std::uint8_t *widthtbl, std::uint8_t width, std::uint8_t height, std::uint8_t baseline) : BaseFont(chartbl, widthtbl, width, height, baseline ) {} + constexpr BMPfont(const void *chartbl, const uint8_t *widthtbl, uint8_t width, uint8_t height, uint8_t baseline) : BaseFont(chartbl, widthtbl, width, height, baseline ) {} font_type_t getType(void) const override { return ft_bmp; } - bool updateFontMetric(FontMetrics *metrics, std::uint16_t uniCode) const override; - std::size_t drawChar(LGFXBase* gfx, std::int32_t x, std::int32_t y, std::uint16_t c, const TextStyle* style, FontMetrics* metrics, std::int32_t& filled_x) const override; + bool updateFontMetric(FontMetrics *metrics, uint16_t uniCode) const override; + size_t drawChar(LGFXBase* gfx, int32_t x, int32_t y, uint16_t c, const TextStyle* style, FontMetrics* metrics, int32_t& filled_x) const override; }; struct RLEfont : public BMPfont { - constexpr RLEfont(const void *chartbl, const std::uint8_t *widthtbl, std::uint8_t width, std::uint8_t height, std::uint8_t baseline) : BMPfont(chartbl, widthtbl, width, height, baseline ) {} + constexpr RLEfont(const void *chartbl, const uint8_t *widthtbl, uint8_t width, uint8_t height, uint8_t baseline) : BMPfont(chartbl, widthtbl, width, height, baseline ) {} font_type_t getType(void) const override { return ft_rle; } - std::size_t drawChar(LGFXBase* gfx, std::int32_t x, std::int32_t y, std::uint16_t c, const TextStyle* style, FontMetrics* metrics, std::int32_t& filled_x) const override; + size_t drawChar(LGFXBase* gfx, int32_t x, int32_t y, uint16_t c, const TextStyle* style, FontMetrics* metrics, int32_t& filled_x) const override; }; struct BDFfont : public BaseFont { - const std::uint16_t *indextbl; - std::uint16_t indexsize; - std::uint8_t halfwidth; - std::uint8_t y_advance; + const uint16_t *indextbl; + uint16_t indexsize; + uint8_t halfwidth; + uint8_t y_advance; BDFfont() = default; - constexpr BDFfont(const void *chartbl, const std::uint16_t *indextbl, std::uint16_t indexsize, std::uint8_t width, std::uint8_t halfwidth, std::uint8_t height, std::uint8_t baseline, std::uint8_t y_advance) + constexpr BDFfont(const void *chartbl, const uint16_t *indextbl, uint16_t indexsize, uint8_t width, uint8_t halfwidth, uint8_t height, uint8_t baseline, uint8_t y_advance) : BaseFont(chartbl, nullptr, width, height, baseline ) , indextbl(indextbl) , indexsize(indexsize) @@ -106,8 +106,8 @@ namespace lgfx font_type_t getType(void) const override { return ft_bdf; } void getDefaultMetric(FontMetrics *metrics) const override; - bool updateFontMetric(FontMetrics *metrics, std::uint16_t uniCode) const override; - std::size_t drawChar(LGFXBase* gfx, std::int32_t x, std::int32_t y, std::uint16_t c, const TextStyle* style, FontMetrics* metrics, std::int32_t& filled_x) const override; + bool updateFontMetric(FontMetrics *metrics, uint16_t uniCode) const override; + size_t drawChar(LGFXBase* gfx, int32_t x, int32_t y, uint16_t c, const TextStyle* style, FontMetrics* metrics, int32_t& filled_x) const override; }; // deprecated array. @@ -117,34 +117,34 @@ namespace lgfx // Adafruit GFX font struct EncodeRange { - std::uint16_t start; - std::uint16_t end; - std::uint16_t base; + uint16_t start; + uint16_t end; + uint16_t base; }; struct GFXglyph { // Data stored PER GLYPH - std::uint32_t bitmapOffset; // Pointer into GFXfont->bitmap - std::uint8_t width, height; // Bitmap dimensions in pixels - std::uint8_t xAdvance; // Distance to advance cursor (x axis) - std::int8_t xOffset, yOffset; // Dist from cursor pos to UL corner + uint32_t bitmapOffset; // Pointer into GFXfont->bitmap + uint8_t width, height; // Bitmap dimensions in pixels + uint8_t xAdvance; // Distance to advance cursor (x axis) + int8_t xOffset, yOffset; // Dist from cursor pos to UL corner }; struct GFXfont : public lgfx::IFont { // Data stored for FONT AS A WHOLE: - std::uint8_t *bitmap; // Glyph bitmaps, concatenated + uint8_t *bitmap; // Glyph bitmaps, concatenated GFXglyph *glyph; // Glyph array - std::uint16_t first, last; // ASCII extents - std::uint8_t yAdvance; // Newline distance (y axis) + uint16_t first, last; // ASCII extents + uint8_t yAdvance; // Newline distance (y axis) - std::uint16_t range_num; // Number of EncodeRange + uint16_t range_num; // Number of EncodeRange EncodeRange *range; // Array ofEncodeRange - constexpr GFXfont ( std::uint8_t *bitmap + constexpr GFXfont ( uint8_t *bitmap , GFXglyph *glyph - , std::uint16_t first - , std::uint16_t last - , std::uint8_t yAdvance - , std::uint16_t range_num = 0 + , uint16_t first + , uint16_t last + , uint8_t yAdvance + , uint16_t range_num = 0 , EncodeRange *range = nullptr ) : bitmap (bitmap ) @@ -158,11 +158,11 @@ namespace lgfx font_type_t getType(void) const override { return font_type_t::ft_gfx; } void getDefaultMetric(FontMetrics *metrics) const override; - bool updateFontMetric(FontMetrics *metrics, std::uint16_t uniCode) const override; - std::size_t drawChar(LGFXBase* gfx, std::int32_t x, std::int32_t y, std::uint16_t c, const TextStyle* style, FontMetrics* metrics, std::int32_t& filled_x) const override; + bool updateFontMetric(FontMetrics *metrics, uint16_t uniCode) const override; + size_t drawChar(LGFXBase* gfx, int32_t x, int32_t y, uint16_t c, const TextStyle* style, FontMetrics* metrics, int32_t& filled_x) const override; private: - GFXglyph* getGlyph(std::uint16_t uniCode) const; + GFXglyph* getGlyph(uint16_t uniCode) const; }; //---------------------------------------------------------------------------- @@ -170,38 +170,38 @@ namespace lgfx struct U8g2font : public lgfx::IFont { - constexpr U8g2font(const std::uint8_t *u8g2_font) : _font(u8g2_font) {} + constexpr U8g2font(const uint8_t *u8g2_font) : _font(u8g2_font) {} font_type_t getType(void) const override { return ft_u8g2; } - std::uint8_t glyph_cnt (void) const { return _font[0]; } - std::uint8_t bbx_mode (void) const { return _font[1]; } - std::uint8_t bits_per_0(void) const { return _font[2]; } - std::uint8_t bits_per_1(void) const { return _font[3]; } - std::uint8_t bits_per_char_width (void) const { return _font[4]; } - std::uint8_t bits_per_char_height(void) const { return _font[5]; } - std::uint8_t bits_per_char_x (void) const { return _font[6]; } - std::uint8_t bits_per_char_y (void) const { return _font[7]; } - std::uint8_t bits_per_delta_x (void) const { return _font[8]; } - std::int8_t max_char_width (void) const { return _font[ 9]; } - std::int8_t max_char_height(void) const { return _font[10]; } /* overall height, NOT ascent. Instead ascent = max_char_height + y_offset */ - std::int8_t x_offset (void) const { return _font[11]; } - std::int8_t y_offset (void) const { return _font[12]; } - std::int8_t ascent_A (void) const { return _font[13]; } - std::int8_t descent_g (void) const { return _font[14]; } /* usually a negative value */ - std::int8_t ascent_para (void) const { return _font[15]; } - std::int8_t descent_para(void) const { return _font[16]; } - - std::uint16_t start_pos_upper_A(void) const { return _font[17] << 8 | _font[18]; } - std::uint16_t start_pos_lower_a(void) const { return _font[19] << 8 | _font[20]; } - std::uint16_t start_pos_unicode(void) const { return _font[21] << 8 | _font[22]; } + uint8_t glyph_cnt (void) const { return _font[0]; } + uint8_t bbx_mode (void) const { return _font[1]; } + uint8_t bits_per_0(void) const { return _font[2]; } + uint8_t bits_per_1(void) const { return _font[3]; } + uint8_t bits_per_char_width (void) const { return _font[4]; } + uint8_t bits_per_char_height(void) const { return _font[5]; } + uint8_t bits_per_char_x (void) const { return _font[6]; } + uint8_t bits_per_char_y (void) const { return _font[7]; } + uint8_t bits_per_delta_x (void) const { return _font[8]; } + int8_t max_char_width (void) const { return _font[ 9]; } + int8_t max_char_height(void) const { return _font[10]; } /* overall height, NOT ascent. Instead ascent = max_char_height + y_offset */ + int8_t x_offset (void) const { return _font[11]; } + int8_t y_offset (void) const { return _font[12]; } + int8_t ascent_A (void) const { return _font[13]; } + int8_t descent_g (void) const { return _font[14]; } /* usually a negative value */ + int8_t ascent_para (void) const { return _font[15]; } + int8_t descent_para(void) const { return _font[16]; } + + uint16_t start_pos_upper_A(void) const { return _font[17] << 8 | _font[18]; } + uint16_t start_pos_lower_a(void) const { return _font[19] << 8 | _font[20]; } + uint16_t start_pos_unicode(void) const { return _font[21] << 8 | _font[22]; } void getDefaultMetric(FontMetrics *metrics) const override; - bool updateFontMetric(FontMetrics *metrics, std::uint16_t uniCode) const override; - std::size_t drawChar(LGFXBase* gfx, std::int32_t x, std::int32_t y, std::uint16_t c, const TextStyle* style, FontMetrics* metrics, std::int32_t& filled_x) const override; + bool updateFontMetric(FontMetrics *metrics, uint16_t uniCode) const override; + size_t drawChar(LGFXBase* gfx, int32_t x, int32_t y, uint16_t c, const TextStyle* style, FontMetrics* metrics, int32_t& filled_x) const override; private: - const uint8_t* getGlyph(std::uint16_t encoding) const; - const std::uint8_t* _font; + const uint8_t* getGlyph(uint16_t encoding) const; + const uint8_t* _font; }; //---------------------------------------------------------------------------- @@ -219,24 +219,24 @@ namespace lgfx // VLW font struct VLWfont : public RunTimeFont { - std::uint16_t gCount; // Total number of characters - std::uint16_t yAdvance; // Line advance - std::uint16_t spaceWidth; // Width of a space character - std::int16_t ascent; // Height of top of 'd' above baseline, other characters may be taller - std::int16_t descent; // Offset to bottom of 'p', other characters may have a larger descent - std::uint16_t maxAscent; // Maximum ascent found in font - std::uint16_t maxDescent; // Maximum descent found in font + uint16_t gCount; // Total number of characters + uint16_t yAdvance; // Line advance + uint16_t spaceWidth; // Width of a space character + int16_t ascent; // Height of top of 'd' above baseline, other characters may be taller + int16_t descent; // Offset to bottom of 'p', other characters may have a larger descent + uint16_t maxAscent; // Maximum ascent found in font + uint16_t maxDescent; // Maximum descent found in font // These are for the metrics for each individual glyph (so we don't need to seek this in file and waste time) - std::uint16_t* gUnicode = nullptr; //UTF-16 code, the codes are searched so do not need to be sequential - std::uint8_t* gWidth = nullptr; //cwidth - std::uint8_t* gxAdvance = nullptr; //setWidth - std::int8_t* gdX = nullptr; //leftExtent - std::uint32_t* gBitmap = nullptr; //file pointer to greyscale bitmap + uint16_t* gUnicode = nullptr; //UTF-16 code, the codes are searched so do not need to be sequential + uint8_t* gWidth = nullptr; //cwidth + uint8_t* gxAdvance = nullptr; //setWidth + int8_t* gdX = nullptr; //leftExtent + uint32_t* gBitmap = nullptr; //file pointer to greyscale bitmap font_type_t getType(void) const override { return ft_vlw; } - std::size_t drawChar(LGFXBase* gfx, std::int32_t x, std::int32_t y, std::uint16_t c, const TextStyle* style, FontMetrics* metrics, std::int32_t& filled_x) const override; + size_t drawChar(LGFXBase* gfx, int32_t x, int32_t y, uint16_t c, const TextStyle* style, FontMetrics* metrics, int32_t& filled_x) const override; void getDefaultMetric(FontMetrics *metrics) const override; @@ -246,9 +246,9 @@ namespace lgfx bool unloadFont(void) override; - bool updateFontMetric(FontMetrics *metrics, std::uint16_t uniCode) const override; + bool updateFontMetric(FontMetrics *metrics, uint16_t uniCode) const override; - bool getUnicodeIndex(std::uint16_t unicode, std::uint16_t *index) const; + bool getUnicodeIndex(uint16_t unicode, uint16_t *index) const; }; //---------------------------------------------------------------------------- @@ -256,7 +256,7 @@ namespace lgfx namespace fonts { #ifdef __EFONT_FONT_DATA_H__ - static constexpr lgfx::BDFfont efont = { (const std::uint8_t *)efontFontData, efontFontList, sizeof(efontFontList)>>1, 16, 8, 16, 14, 16 }; + static constexpr lgfx::BDFfont efont = { (const uint8_t *)efontFontData, efontFontList, sizeof(efontFontList)>>1, 16, 8, 16, 14, 16 }; #endif extern const lgfx::GLCDfont Font0; @@ -449,22 +449,23 @@ namespace lgfx struct FontMetrics { - std::int16_t width; - std::int16_t x_advance; - std::int16_t x_offset; - std::int16_t height; - std::int16_t y_advance; - std::int16_t y_offset; - std::int16_t baseline; + int16_t width; + int16_t x_advance; + int16_t x_offset; + int16_t height; + int16_t y_advance; + int16_t y_offset; + int16_t baseline; }; struct TextStyle { - std::uint32_t fore_rgb888 = 0xFFFFFFU; - std::uint32_t back_rgb888 = 0; + uint32_t fore_rgb888 = 0xFFFFFFU; + uint32_t back_rgb888 = 0; float size_x = 1; float size_y = 1; textdatum_t datum = textdatum_t::top_left; + int32_t padding_x = 0; bool utf8 = true; bool cp437 = false; // IFont* font = &fonts::Font0; diff --git a/src/lgfx/v1/misc/DataWrapper.hpp b/src/lgfx/v1/misc/DataWrapper.hpp index 1373741..b8119b7 100644 --- a/src/lgfx/v1/misc/DataWrapper.hpp +++ b/src/lgfx/v1/misc/DataWrapper.hpp @@ -17,8 +17,8 @@ Original Source: /----------------------------------------------------------------------------*/ #pragma once -#include -#include +#include +#include namespace lgfx { @@ -34,35 +34,35 @@ namespace lgfx bool need_transaction = false; - std::uint8_t read8(void) + uint8_t read8(void) { - std::uint8_t result; + uint8_t result; read(&result, 1); return result; } - std::uint16_t read16(void) + uint16_t read16(void) { - std::uint16_t result; - read(reinterpret_cast(&result), 2); + uint16_t result; + read(reinterpret_cast(&result), 2); return result; } - std::uint32_t read32(void) { - std::uint32_t result; - read(reinterpret_cast(&result), 4); + uint32_t read32(void) { + uint32_t result; + read(reinterpret_cast(&result), 4); return result; } - __attribute__ ((always_inline)) inline std::uint16_t read16swap(void) { return __builtin_bswap16(read16()); } - __attribute__ ((always_inline)) inline std::uint32_t read32swap(void) { return __builtin_bswap32(read32()); } + __attribute__ ((always_inline)) inline uint16_t read16swap(void) { return __builtin_bswap16(read16()); } + __attribute__ ((always_inline)) inline uint32_t read32swap(void) { return __builtin_bswap32(read32()); } - virtual bool open(const char* path) { return true; }; - virtual int read(std::uint8_t *buf, std::uint32_t len) = 0; - virtual void skip(std::int32_t offset) = 0; - virtual bool seek(std::uint32_t offset) = 0; + virtual bool open(__attribute__((unused)) const char* path) { return true; }; + virtual int read(uint8_t *buf, uint32_t len) = 0; + virtual void skip(int32_t offset) = 0; + virtual bool seek(uint32_t offset) = 0; virtual void close(void) = 0; - virtual std::int32_t tell(void) = 0; + virtual 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); } @@ -76,22 +76,22 @@ namespace lgfx struct PointerWrapper : public DataWrapper { - void set(const std::uint8_t* src, std::uint32_t length = ~0) { _ptr = src; _length = length; _index = 0; } - int read(std::uint8_t *buf, std::uint32_t len) override { + void set(const uint8_t* src, uint32_t length = ~0) { _ptr = src; _length = length; _index = 0; } + int read(uint8_t *buf, uint32_t len) override { if (len > _length - _index) { len = _length - _index; } memcpy(buf, &_ptr[_index], len); _index += len; return len; } - void skip(std::int32_t offset) override { _index += offset; } - bool seek(std::uint32_t offset) override { _index = offset; return true; } + void skip(int32_t offset) override { _index += offset; } + bool seek(uint32_t offset) override { _index = offset; return true; } void close(void) override { } - std::int32_t tell(void) override { return _index; } + int32_t tell(void) override { return _index; } private: - const std::uint8_t* _ptr = nullptr; - std::uint32_t _index = 0; - std::uint32_t _length = 0; + const uint8_t* _ptr = nullptr; + uint32_t _index = 0; + uint32_t _length = 0; }; //---------------------------------------------------------------------------- @@ -131,11 +131,11 @@ namespace lgfx _fp = &_file; return _file; } - int read(std::uint8_t *buf, std::uint32_t len) override { return _fp->read(buf, len); } - void skip(std::int32_t offset) override { _fp->seekCur(offset); } - bool seek(std::uint32_t offset) override { return _fp->seekSet(offset); } + int read(uint8_t *buf, uint32_t len) override { return _fp->read(buf, len); } + void skip(int32_t offset) override { _fp->seekCur(offset); } + bool seek(uint32_t offset) override { return _fp->seekSet(offset); } void close(void) override { if (_fp) _fp->close(); } - std::int32_t tell(void) override { return _fp->position(); } + int32_t tell(void) override { return _fp->position(); } }; #endif diff --git a/src/lgfx/v1/misc/SpriteBuffer.cpp b/src/lgfx/v1/misc/SpriteBuffer.cpp new file mode 100644 index 0000000..bac04e5 --- /dev/null +++ b/src/lgfx/v1/misc/SpriteBuffer.cpp @@ -0,0 +1,158 @@ +/*----------------------------------------------------------------------------/ + Lovyan GFX - Graphics library for embedded devices. + +Original Source: + https://github.com/lovyan03/LovyanGFX/ + +Licence: + [FreeBSD](https://github.com/lovyan03/LovyanGFX/blob/master/license.txt) + +Author: + [lovyan03](https://twitter.com/lovyan03) + +Contributors: + [ciniml](https://github.com/ciniml) + [mongonta0716](https://github.com/mongonta0716) + [tobozo](https://github.com/tobozo) +/----------------------------------------------------------------------------*/ + +#include "SpriteBuffer.hpp" + +#include "../../internal/algorithm.h" +#include "../platforms/common.hpp" + +#include + +namespace lgfx +{ + inline namespace v1 + { +//---------------------------------------------------------------------------- + + SpriteBuffer::SpriteBuffer(size_t length, AllocationSource source) : _buffer(nullptr), _length(0), _source(source) + { + if (length) + { + assert (source != AllocationSource::Preallocated); + this->reset(length, source); + } + } + + SpriteBuffer::SpriteBuffer(const SpriteBuffer& rhs) : _buffer(nullptr) + { + if ( rhs._source == AllocationSource::Preallocated ) + { + this->_buffer = rhs._buffer; + this->_length = rhs._length; + this->_source = rhs._source; + } + else + { + this->reset(rhs._length, rhs._source); + if( _buffer != nullptr && rhs._buffer != nullptr ) + { + std::copy(rhs._buffer, rhs._buffer + _length, _buffer); + } + } + } + + SpriteBuffer::SpriteBuffer(SpriteBuffer&& rhs) : _buffer(nullptr) + { + if ( rhs._source == AllocationSource::Preallocated ) { + this->_buffer = rhs._buffer; + this->_length = rhs._length; + this->_source = rhs._source; + } + else { + this->reset(rhs._length, rhs._source); + if( _buffer != nullptr && rhs._buffer != nullptr ) { + std::copy(rhs._buffer, rhs._buffer + _length, _buffer); + rhs.release(); + } + } + } + + SpriteBuffer& SpriteBuffer::operator=(const SpriteBuffer& rhs) + { + if ( rhs._source == AllocationSource::Preallocated ) { + this->_buffer = rhs._buffer; + this->_length = rhs._length; + this->_source = rhs._source; + } + else { + this->reset(rhs._length, rhs._source); + if ( _buffer != nullptr && rhs._buffer != nullptr ) { + std::copy(rhs._buffer, rhs._buffer + _length, _buffer); + } + } + return *this; + } + + SpriteBuffer& SpriteBuffer::operator=(SpriteBuffer&& rhs) + { + if( rhs._source == AllocationSource::Preallocated ) { + this->_buffer = rhs._buffer; + this->_length = rhs._length; + this->_source = rhs._source; + } + else { + this->reset(rhs._length, rhs._source); + if( _buffer != nullptr && rhs._buffer != nullptr ) { + std::copy(rhs._buffer, rhs._buffer + _length, _buffer); + rhs.release(); + } + } + return *this; + } + + void SpriteBuffer::reset(void* buffer) + { + this->release(); + _source = AllocationSource::Preallocated; + _buffer = reinterpret_cast(buffer); + _length = 0; + } + + void SpriteBuffer::reset(size_t length, AllocationSource source) + { + this->release(); + void* buffer = nullptr; + _source = source; + switch (source) + { + default: + case AllocationSource::Normal: + buffer = heap_alloc(length); + break; + case AllocationSource::Dma: + buffer = heap_alloc_dma(length); + break; + case AllocationSource::Psram: + buffer = heap_alloc_psram(length); + if (!buffer) + { + _source = AllocationSource::Dma; + buffer = heap_alloc_dma(length); + } + break; + } + _buffer = reinterpret_cast(buffer); + if ( _buffer != nullptr ) { + _length = length; + } + } + + void SpriteBuffer::release(void) { + _length = 0; + if ( _buffer != nullptr ) { + if (_source != AllocationSource::Preallocated) + { + heap_free(_buffer); + } + _buffer = nullptr; + } + } + +//---------------------------------------------------------------------------- + } +} diff --git a/src/lgfx/v1/misc/SpriteBuffer.hpp b/src/lgfx/v1/misc/SpriteBuffer.hpp index 389fe61..5ab4703 100644 --- a/src/lgfx/v1/misc/SpriteBuffer.hpp +++ b/src/lgfx/v1/misc/SpriteBuffer.hpp @@ -17,10 +17,8 @@ Original Source: /----------------------------------------------------------------------------*/ #pragma once -#include -#include - -#include "../platforms/common.hpp" +#include +#include namespace lgfx { @@ -41,151 +39,43 @@ namespace lgfx class SpriteBuffer { private: - std::uint8_t* _buffer; - std::size_t _length; + uint8_t* _buffer; + size_t _length; AllocationSource _source; public: SpriteBuffer(void) : _buffer(nullptr), _length(0), _source(Dma) {} - SpriteBuffer(std::size_t length, AllocationSource source = AllocationSource::Dma) : _buffer(nullptr), _length(0), _source(source) - { - if (length) - { - assert (source != AllocationSource::Preallocated); - this->reset(length, source); - } - } + SpriteBuffer(size_t length, AllocationSource source = AllocationSource::Dma); - SpriteBuffer(std::uint8_t* buffer, std::size_t length) : _buffer(buffer), _length(length), _source(AllocationSource::Preallocated) + SpriteBuffer(uint8_t* buffer, size_t length) : _buffer(buffer), _length(length), _source(AllocationSource::Preallocated) { } - SpriteBuffer(const SpriteBuffer& rhs) : _buffer(nullptr) - { - if ( rhs._source == AllocationSource::Preallocated ) - { - this->_buffer = rhs._buffer; - this->_length = rhs._length; - this->_source = rhs._source; - } - else - { - this->reset(rhs._length, rhs._source); - if( _buffer != nullptr && rhs._buffer != nullptr ) - { - std::copy(rhs._buffer, rhs._buffer + _length, _buffer); - } - } - } + SpriteBuffer(const SpriteBuffer& rhs); - SpriteBuffer(SpriteBuffer&& rhs) : _buffer(nullptr) - { - if ( rhs._source == AllocationSource::Preallocated ) { - this->_buffer = rhs._buffer; - this->_length = rhs._length; - this->_source = rhs._source; - } - else { - this->reset(rhs._length, rhs._source); - if( _buffer != nullptr && rhs._buffer != nullptr ) { - std::copy(rhs._buffer, rhs._buffer + _length, _buffer); - rhs.release(); - } - } - } + SpriteBuffer(SpriteBuffer&& rhs); - SpriteBuffer& operator=(const SpriteBuffer& rhs) - { - if ( rhs._source == AllocationSource::Preallocated ) { - this->_buffer = rhs._buffer; - this->_length = rhs._length; - this->_source = rhs._source; - } - else { - this->reset(rhs._length, rhs._source); - if ( _buffer != nullptr && rhs._buffer != nullptr ) { - std::copy(rhs._buffer, rhs._buffer + _length, _buffer); - } - } - return *this; - } + SpriteBuffer& operator=(const SpriteBuffer& rhs); - SpriteBuffer& operator=(SpriteBuffer&& rhs) - { - if( rhs._source == AllocationSource::Preallocated ) { - this->_buffer = rhs._buffer; - this->_length = rhs._length; - this->_source = rhs._source; - } - else { - this->reset(rhs._length, rhs._source); - if( _buffer != nullptr && rhs._buffer != nullptr ) { - std::copy(rhs._buffer, rhs._buffer + _length, _buffer); - rhs.release(); - } - } - return *this; - } + SpriteBuffer& operator=(SpriteBuffer&& rhs); - operator std::uint8_t*() const { return _buffer; } + operator uint8_t*() const { return _buffer; } operator bool() const { return _buffer != nullptr; } - std::uint8_t* get() const { return _buffer; } - std::uint8_t* img8() const { return _buffer; } - std::uint16_t* img16() const { return reinterpret_cast(_buffer); } + uint8_t* get() const { return _buffer; } + uint8_t* img8() const { return _buffer; } + uint16_t* img16() const { return reinterpret_cast(_buffer); } bgr888_t* img24() const { return reinterpret_cast(_buffer); } - void reset(void* buffer) - { - this->release(); - _source = AllocationSource::Preallocated; - _buffer = reinterpret_cast(buffer); - _length = 0; - } + void reset(void* buffer); - void reset(std::size_t length, AllocationSource source) - { - this->release(); - void* buffer = nullptr; - _source = source; - switch (source) - { - default: - case AllocationSource::Normal: - buffer = heap_alloc(length); - break; - case AllocationSource::Dma: - buffer = heap_alloc_dma(length); - break; - case AllocationSource::Psram: - buffer = heap_alloc_psram(length); - if (!buffer) - { - _source = AllocationSource::Dma; - buffer = heap_alloc_dma(length); - } - break; - } - _buffer = reinterpret_cast(buffer); - if ( _buffer != nullptr ) { - _length = length; - } - } + void reset(size_t length, AllocationSource source); - void release() { - _length = 0; - if ( _buffer != nullptr ) { - if (_source != AllocationSource::Preallocated) - { - heap_free(_buffer); - } - _buffer = nullptr; - } - } + void release(void); - bool use_dma() const { return _source == AllocationSource::Dma; } - bool use_memcpy() const { return _source != AllocationSource::Psram; } + bool use_dma(void) const { return _source == AllocationSource::Dma; } + bool use_memcpy(void) const { return _source != AllocationSource::Psram; } }; //---------------------------------------------------------------------------- diff --git a/src/lgfx/v1/misc/bitmap.hpp b/src/lgfx/v1/misc/bitmap.hpp index 8abd227..6027f29 100644 --- a/src/lgfx/v1/misc/bitmap.hpp +++ b/src/lgfx/v1/misc/bitmap.hpp @@ -29,31 +29,31 @@ namespace lgfx { union { - std::uint8_t raw[54]; + uint8_t raw[54]; struct { - std::uint16_t bfType; - std::uint32_t bfSize; - std::uint16_t bfReserved1; - std::uint16_t bfReserved2; - std::uint32_t bfOffBits; - - std::uint32_t biSize; - std::int32_t biWidth; - std::int32_t biHeight; - std::uint16_t biPlanes; - std::uint16_t biBitCount; - std::uint32_t biCompression; - std::uint32_t biSizeImage; - std::int32_t biXPelsPerMeter; - std::int32_t biYPelsPerMeter; - std::uint32_t biClrUsed; - std::uint32_t biClrImportant; + uint16_t bfType; + uint32_t bfSize; + uint16_t bfReserved1; + uint16_t bfReserved2; + uint32_t bfOffBits; + + uint32_t biSize; + int32_t biWidth; + int32_t biHeight; + uint16_t biPlanes; + uint16_t biBitCount; + uint32_t biCompression; + uint32_t biSizeImage; + int32_t biXPelsPerMeter; + int32_t biYPelsPerMeter; + uint32_t biClrUsed; + uint32_t biClrImportant; } __attribute__((packed)); }; bool load_bmp_header(DataWrapper* data) { - data->read((std::uint8_t*)this, sizeof(bitmap_header_t)); + data->read((uint8_t*)this, sizeof(bitmap_header_t)); return ( (bfType == 0x4D42) // bmp header "BM" && (biPlanes == 1) // bcPlanes always 1 && (biWidth > 0) @@ -62,10 +62,10 @@ namespace lgfx && (biBitCount != 0)); } - static bool load_bmp_rle8(DataWrapper* data, std::uint8_t* linebuf, uint_fast16_t width) + static bool load_bmp_rle8(DataWrapper* data, uint8_t* linebuf, uint_fast16_t width) { width = (width + 3) & ~3; - std::uint8_t code[2]; + uint8_t code[2]; uint_fast16_t xidx = 0; bool eol = false; do { @@ -95,10 +95,10 @@ namespace lgfx return true; } - static bool load_bmp_rle4(DataWrapper* data, std::uint8_t* linebuf, uint_fast16_t width) + static bool load_bmp_rle4(DataWrapper* data, uint8_t* linebuf, uint_fast16_t width) { width = (width + 3) & ~3; - std::uint8_t code[2]; + uint8_t code[2]; uint_fast16_t xidx = 0; bool eol = false; do { diff --git a/src/lgfx/v1/misc/colortype.hpp b/src/lgfx/v1/misc/colortype.hpp index 80199db..d8f0495 100644 --- a/src/lgfx/v1/misc/colortype.hpp +++ b/src/lgfx/v1/misc/colortype.hpp @@ -17,34 +17,11 @@ Original Source: /----------------------------------------------------------------------------*/ #pragma once -#include +#include #include -#if defined ( ARDUINO ) && !defined ( pgm_read_byte ) - #if __has_include() - #include - #elif __has_include() - #include - #endif -#endif -#if !defined ( pgm_read_byte ) - #define pgm_read_byte(addr) (*(const std::uint8_t *)((std::uintptr_t)addr)) - #define pgm_read_word(addr) (*(const std::uint16_t *)((std::uintptr_t)addr)) - #define pgm_read_dword(addr) (*(const std::uint32_t *)((std::uintptr_t)addr)) -#endif - -/// for not ESP8266 -#if !defined ( pgm_read_dword_with_offset ) - #if defined (__SAMD21__) - #define pgm_read_dword_unaligned(addr) (std::uint32_t) \ - ( *(const std::uint8_t *)((std::uintptr_t)addr) \ - | *(const std::uint8_t *)((std::uintptr_t)addr+1) << 8 \ - | *(const std::uint8_t *)((std::uintptr_t)addr+2) << 16 \ - | *(const std::uint8_t *)((std::uintptr_t)addr+3) << 24 ) - #else - #define pgm_read_dword_unaligned(addr) (*(const std::uint32_t *)((std::uintptr_t)addr)) - #endif -#endif +#include "../../utility/pgmspace.h" + #include "enum.hpp" @@ -54,60 +31,23 @@ namespace lgfx { //---------------------------------------------------------------------------- -#define LGFX_INLINE __attribute__((used)) __attribute__ ((always_inline)) inline static constexpr - - LGFX_INLINE 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; } - LGFX_INLINE 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; } - LGFX_INLINE std::uint32_t color888(std::uint8_t r, std::uint8_t g, std::uint8_t b) { return r << 16 | g << 8 | b; } - LGFX_INLINE std::uint16_t swap565( std::uint8_t r, std::uint8_t g, std::uint8_t b) { return (((r >> 3) << 3) + (g >> 5)) | (((g >> 2) << 5) | (b >> 3)) << 8; } - LGFX_INLINE std::uint32_t swap888( std::uint8_t r, std::uint8_t g, std::uint8_t b) { return b << 16 | g << 8 | r; } - LGFX_INLINE std::uint16_t getSwap16(std::uint16_t c) { return __builtin_bswap16(c); } - LGFX_INLINE std::uint32_t getSwap24(std::uint32_t c) { return ((std::uint8_t)c)<<16 | ((std::uint8_t)(c>>8))<<8 | (std::uint8_t)(c>>16); } - - LGFX_INLINE std::uint32_t convert_bgr888_to_bgra8888(std::uint32_t c) { return c << 8 | 0xFF; } - LGFX_INLINE std::uint32_t convert_bgr888_to_argb8888(std::uint32_t c) { return getSwap24(c) | 0xFF << 24; } - LGFX_INLINE std::uint32_t convert_bgr888_to_rgb888( std::uint32_t c) { return getSwap24(c); } - LGFX_INLINE std::uint32_t convert_bgr888_to_rgb565( std::uint32_t c) { return (((std::uint8_t)c) >> 3) << 11 | (((std::uint16_t)c)>>10)<<5 | c>>19; } - LGFX_INLINE std::uint32_t convert_bgr888_to_swap565(std::uint32_t c) { return (((std::uint8_t)c) >> 3) << 3 | ((std::uint16_t)c) >> 13 | (c & 0x1C00) << 3 | (c>>19) << 8; } - LGFX_INLINE std::uint32_t convert_bgr888_to_bgr666 (std::uint32_t c) { return (c>>2) & 0x3F3F3F; } - LGFX_INLINE std::uint32_t convert_bgr888_to_rgb332 (std::uint32_t c) { return ((std::uint8_t)c >> 5) << 5 | (((std::uint16_t)c)>>13) << 2 | c>>22; } - - LGFX_INLINE std::uint32_t convert_rgb888_to_bgra8888(std::uint32_t c) { return __builtin_bswap32(c) | 0xFF; } - LGFX_INLINE std::uint32_t convert_rgb888_to_argb8888(std::uint32_t c) { return c | 0xFF << 24; } - LGFX_INLINE std::uint32_t convert_rgb888_to_bgr666 (std::uint32_t c) { return ((c>>2) & 0x3F) << 16 | ((c >> 10) & 0x3F) << 8 | ((c>>18)&0x3F); } - LGFX_INLINE std::uint32_t convert_rgb888_to_rgb565 (std::uint32_t c) { return (c>>19) << 11 | (((std::uint16_t)c)>>10)<<5 | ((std::uint8_t)c) >> 3; } - LGFX_INLINE std::uint32_t convert_rgb888_to_bgr888 (std::uint32_t c) { return getSwap24(c); } - LGFX_INLINE std::uint32_t convert_rgb888_to_swap565(std::uint32_t c) { return (c>>19) << 3 | ((std::uint16_t)c) >> 13 | (c & 0x1C00) << 3 | (((std::uint8_t)c) >> 3) << 8; } - LGFX_INLINE std::uint32_t convert_rgb888_to_rgb332 (std::uint32_t c) { return ((c>>21) << 5) | ((((std::uint16_t)c)>>13) << 2) | ((c>>6) & 3); } - - LGFX_INLINE std::uint32_t convert_rgb565_to_bgra8888(std::uint32_t c) { return (((((c&0x1F)*0x21)>>2)<<8 | ((((c>>5)&0x3F)*0x41)>>4))<<8 | (((c>>11)*0x21)>>2)) << 8 | 0xFF; } - LGFX_INLINE std::uint32_t convert_rgb565_to_argb8888(std::uint32_t c) { return ((((c>>11)*0x21)>>2)<<8 | ((((c>>5)&0x3F)*0x41)>>4))<<8 | (((c&0x1F)*0x21)>>2) | 0xFF << 24; } - LGFX_INLINE std::uint32_t convert_rgb565_to_rgb888( std::uint32_t c) { return ((((c>>11)*0x21)>>2)<<8 | ((((c>>5)&0x3F)*0x41)>>4))<<8 | (((c&0x1F)*0x21)>>2); } - LGFX_INLINE std::uint32_t convert_rgb565_to_bgr888 (std::uint32_t c) { return ((((c&0x1F)*0x21)>>2)<<8 | ((((c>>5)&0x3F)*0x41)>>4))<<8 | (((c>>11)*0x21)>>2); } - LGFX_INLINE std::uint32_t convert_rgb565_to_bgr666 (std::uint32_t c) { return ((c&0x1F)<<17) | ((c&0x10)<<12) | ((c&0x7E0)<<3) | ((c>>10)&0xF8) | (c>>15); } - LGFX_INLINE std::uint32_t convert_rgb565_to_swap565(std::uint32_t c) { return (0xFF & c)<<8|c>>8; } - LGFX_INLINE std::uint32_t convert_rgb565_to_rgb332 (std::uint32_t c) { return ((c>>13) <<5) | ((c>>6) & 0x1C) | ((c>>3) & 3); } - - LGFX_INLINE std::uint32_t convert_rgb332_to_bgra8888(std::uint32_t c) { return ((((c&3)*0x55)<<8 | ((c&0x1C)*0x49)>>3)<<8 | (((c>>5)*0x49) >> 1)) << 8 | 0xFF; } - LGFX_INLINE std::uint32_t convert_rgb332_to_argb8888(std::uint32_t c) { return ((((c>>5)*0x49) >> 1)<<8 | ((c&0x1C)*0x49)>>3)<<8 | ((c&3)*0x55) | 0xFF << 24; } - LGFX_INLINE std::uint32_t convert_rgb332_to_rgb888 (std::uint32_t c) { return ((((c>>5)*0x49) >> 1)<<8 | ((c&0x1C)*0x49)>>3)<<8 | ((c&3)*0x55); } - LGFX_INLINE std::uint32_t convert_rgb332_to_bgr888 (std::uint32_t c) { return (((c&3)*0x55)<<8 | ((c&0x1C)*0x49)>>3)<<8 | (((c>>5)*0x49) >> 1); } - LGFX_INLINE std::uint32_t convert_rgb332_to_bgr666 (std::uint32_t c) { return (((c&0xE0)*9)>>5) | ((c&0x1C)*0x240) | ((c&3)*0x15)<<16; } - LGFX_INLINE std::uint32_t convert_rgb332_to_swap565(std::uint32_t c) { return (((c&3)*0x15)>>1)<<8 | ((c&0x1C)<<11) | ((c&0x1C)>>2) | (((c>>5)*0x24)&0xF8); } - LGFX_INLINE std::uint32_t convert_rgb332_to_rgb565 (std::uint32_t c) { return (((c&3)*0x15)>>1) | ((c&0x1C)*0x48) | ((c&0xE0)|(c>>6)<<3)<<8; } - - LGFX_INLINE std::uint32_t convert_bgra8888_to_bgr888(std::uint32_t c) { return c >> 8; } - LGFX_INLINE std::uint32_t convert_bgra8888_to_bgr666(std::uint32_t c) { return (c >> 10) & 0x3F3F3F; } - LGFX_INLINE std::uint32_t convert_bgra8888_to_swap565(std::uint32_t c){ return convert_bgr888_to_swap565(c>>8); } - LGFX_INLINE std::uint32_t convert_bgra8888_to_rgb332(std::uint32_t c) { return convert_bgr888_to_rgb332(c>>8); } - LGFX_INLINE std::uint32_t convert_bgra8888_to_argb8888(std::uint32_t c) { return __builtin_bswap32(c); } - LGFX_INLINE std::uint32_t convert_argb8888_to_bgra8888(std::uint32_t c) { return __builtin_bswap32(c); } - - LGFX_INLINE std::uint32_t convert_uint32_to_palette8(std::uint32_t c) { return c & 0xFF; } - LGFX_INLINE std::uint32_t convert_uint32_to_palette4(std::uint32_t c) { return (c & 0x0F) * 0x11; } - LGFX_INLINE std::uint32_t convert_uint32_to_palette2(std::uint32_t c) { return (c & 0x03) * 0x55; } - LGFX_INLINE std::uint32_t convert_uint32_to_palette1(std::uint32_t c) { return (c & 1) ? 0xFF : 0; } - LGFX_INLINE std::uint32_t no_convert(std::uint32_t c) { return c; } +#define LGFX_INLINE __attribute__((used)) __attribute__ ((always_inline)) inline static + + LGFX_INLINE constexpr uint8_t color332(uint8_t r, uint8_t g, uint8_t b) { return ((((r >> 5) << 3) + (g >> 5)) << 2) + (b >> 6); } + LGFX_INLINE constexpr uint16_t color565(uint8_t r, uint8_t g, uint8_t b) { return (r >> 3) <<11 | (g >> 2) << 5 | b >> 3; } + LGFX_INLINE constexpr uint32_t color888(uint8_t r, uint8_t g, uint8_t b) { return r << 16 | g << 8 | b; } + LGFX_INLINE constexpr uint16_t swap565( uint8_t r, uint8_t g, uint8_t b) { return (((r >> 3) << 3) + (g >> 5)) | (((g >> 2) << 5) | (b >> 3)) << 8; } + LGFX_INLINE constexpr uint32_t swap888( uint8_t r, uint8_t g, uint8_t b) { return b << 16 | g << 8 | r; } + + LGFX_INLINE constexpr uint32_t no_convert(uint32_t c) { return c; } + LGFX_INLINE constexpr uint32_t convert_uint32_to_palette8(uint32_t c) { return c & 0xFF; } + LGFX_INLINE constexpr uint32_t convert_uint32_to_palette4(uint32_t c) { return (c & 0x0F) * 0x11; } + LGFX_INLINE constexpr uint32_t convert_uint32_to_palette2(uint32_t c) { return (c & 0x03) * 0x55; } + LGFX_INLINE constexpr uint32_t convert_uint32_to_palette1(uint32_t c) { return (c & 1) ? 0xFF : 0; } + + LGFX_INLINE constexpr uint32_t getSwap16(uint32_t c) { return (uint16_t)((c << 8) + (c >> 8)); } + LGFX_INLINE constexpr uint32_t getSwap24(uint32_t c) { return ((((c & 0xFF) << 8) + ((c >> 8) & 0xFF)) << 8) + ((c>>16) & 0xFF); } + LGFX_INLINE uint32_t getSwap32(uint32_t c) { c = (c >> 16) + (c << 16); return ((c >> 8) & 0xFF00FF) + ((c & 0xFF00FF) << 8); } #undef LGFX_INLINE @@ -130,383 +70,418 @@ namespace lgfx { struct { - std::uint8_t b2: 2; - std::uint8_t g3: 3; - std::uint8_t r3: 3; + uint8_t b2: 2; + uint8_t g3: 3; + uint8_t r3: 3; }; - std::uint8_t raw; + uint8_t raw; }; - static constexpr std::uint8_t bits = 8; + static constexpr uint8_t bits = 8; static constexpr bool swapped = true; static constexpr color_depth_t depth = rgb332_1Byte; constexpr rgb332_t(void) : raw(0) {} constexpr rgb332_t(const rgb332_t&) = default; - constexpr rgb332_t(std::uint8_t r8, std::uint8_t g8, std::uint8_t b8) : raw(color332(r8, g8, b8)) {} - constexpr rgb332_t(std::uint8_t rgb332) : raw(rgb332) {} - inline rgb332_t& operator=(const rgb565_t&); - inline rgb332_t& operator=(const rgb888_t&); - inline rgb332_t& operator=(const argb8888_t&); - inline rgb332_t& operator=(const swap565_t&); - inline rgb332_t& operator=(const bgr666_t&); - inline rgb332_t& operator=(const bgr888_t&); - inline rgb332_t& operator=(const bgra8888_t&); + constexpr rgb332_t(uint8_t r8, uint8_t g8, uint8_t b8) : raw(color332(r8, g8, b8)) {} + constexpr rgb332_t(uint8_t rgb332) : raw(rgb332) {} + inline rgb332_t& operator=(uint8_t rgb332) { *reinterpret_cast(this) = rgb332; return *this; } + inline rgb332_t& operator=(const rgb332_t& ) = default; + inline rgb332_t& operator=(const rgb565_t& ); + inline rgb332_t& operator=(const rgb888_t& ); + inline rgb332_t& operator=(const argb8888_t& ); + inline rgb332_t& operator=(const swap565_t& ); + inline rgb332_t& operator=(const bgr666_t& ); + inline rgb332_t& operator=(const bgr888_t& ); + inline rgb332_t& operator=(const bgra8888_t& ); inline rgb332_t& operator=(const grayscale_t&); - inline rgb332_t& operator=(std::uint8_t rgb332) { *reinterpret_cast(this) = rgb332; return *this; } - explicit inline constexpr operator std::uint8_t(void) const { return raw; } - explicit inline constexpr operator bool(void) const { return raw; } - static constexpr std::uint8_t A8(void) { return 255; } - inline constexpr std::uint8_t R8(void) const { return (r3 * 0x49) >> 1; } // (r<<5)|(r<<2)|(r>>1); - inline constexpr std::uint8_t G8(void) const { return (g3 * 0x49) >> 1; } // (g<<5)|(g<<2)|(g>>1); - inline constexpr std::uint8_t B8(void) const { return b2 * 0x55; } // (b<<6)|(b<<4)|(b<<2)|b; - inline constexpr std::uint8_t R6(void) const { return r3 | r3 << 3; } - inline constexpr std::uint8_t G6(void) const { return g3 | g3 << 3; } - inline constexpr std::uint8_t B6(void) const { return b2 * 0x15; } - inline void R8(std::uint8_t r8) { r3 = r8 >> 5; } - inline void G8(std::uint8_t g8) { g3 = g8 >> 5; } - inline void B8(std::uint8_t b8) { b2 = b8 >> 6; } - inline void set(std::uint8_t r8, std::uint8_t g8, std::uint8_t b8) { *reinterpret_cast(this) = color332(r8, g8, b8); } + explicit inline operator uint8_t(void) const { return pgm_read_byte(this); } + explicit inline operator bool(void) const { return pgm_read_byte(this); } + static constexpr uint8_t A8(void) { return 255; } + inline constexpr uint8_t R8(void) const { return (((r3 << 3) + r3) << 2) + (r3 >> 1); } + inline constexpr uint8_t G8(void) const { return (((g3 << 3) + g3) << 2) + (g3 >> 1); } + inline constexpr uint8_t B8(void) const { return b2 * 0x55; } // (b<<6)|(b<<4)|(b<<2)|b; + inline constexpr uint8_t R6(void) const { return (r3 << 3) + r3; } + inline constexpr uint8_t G6(void) const { return (g3 << 3) + g3; } + inline constexpr uint8_t B6(void) const { return b2 * 0x15; } + inline void R8(uint8_t r8) { r3 = r8 >> 5; } + inline void G8(uint8_t g8) { g3 = g8 >> 5; } + inline void B8(uint8_t b8) { b2 = b8 >> 6; } + inline void set(uint8_t r8, uint8_t g8, uint8_t b8) { *reinterpret_cast(this) = color332(r8, g8, b8); } + inline void set(uint_fast8_t c) { *reinterpret_cast(this) = c; } + inline uint_fast8_t get(void) const { return pgm_read_byte(this); } }; - struct swap565_t + struct rgb565_t { union { struct { - std::uint16_t gh:3; - std::uint16_t r5:5; - std::uint16_t b5:5; - std::uint16_t gl:3; + uint16_t b5: 5; + uint16_t g6: 6; + uint16_t r5: 5; }; - std::uint16_t raw; + uint16_t raw; }; - static constexpr std::uint8_t bits = 16; - static constexpr bool swapped = true; - static constexpr color_depth_t depth = rgb565_2Byte; - constexpr swap565_t(void) : raw(0) {} - constexpr swap565_t(const swap565_t&) = default; - constexpr swap565_t(std::uint8_t r8, std::uint8_t g8, std::uint8_t b8) : raw(swap565(r8, g8, b8)) {} - constexpr swap565_t(std::uint16_t swap565) : raw(swap565) {} - inline swap565_t& operator=(const rgb332_t&); - inline swap565_t& operator=(const rgb565_t&); - inline swap565_t& operator=(const rgb888_t&); - inline swap565_t& operator=(const argb8888_t&); - inline swap565_t& operator=(const bgr666_t&); - inline swap565_t& operator=(const bgr888_t&); - inline swap565_t& operator=(const bgra8888_t&); - inline swap565_t& operator=(const grayscale_t&); - inline swap565_t& operator=(std::uint16_t swap565) { *reinterpret_cast(this) = swap565; return *this; } - explicit inline constexpr operator std::uint16_t(void) const { return raw; } - explicit inline constexpr operator bool(void) const { return raw; } - static constexpr std::uint8_t A8(void) { return 255; } - inline constexpr std::uint8_t R8(void) const { return (r5 << 3) + (r5 >> 5); } - inline constexpr std::uint8_t G8(void) const { return (gl << 2) + ((gh << 5) | (gh >> 1)); } - inline constexpr std::uint8_t B8(void) const { return (b5 << 3) + (b5 >> 5); } - inline constexpr std::uint8_t R6(void) const { return (r5 * 0x21) >> 4; } - inline constexpr std::uint8_t G6(void) const { return gh << 3 | gl; } - inline constexpr std::uint8_t B6(void) const { return (b5 * 0x21) >> 4; } - inline void R8(std::uint8_t r8) { r5 = r8 >> 3; } - inline void G8(std::uint8_t g8) { gh = g8 >> 5; gl = g8 >> 2;} - inline void B8(std::uint8_t b8) { b5 = b8 >> 3; } - inline void set(std::uint8_t r8, std::uint8_t g8, std::uint8_t b8) { *reinterpret_cast(this) = swap565(r8, g8, b8); } + static constexpr uint8_t bits = 16; + static constexpr bool swapped = false; + static constexpr color_depth_t depth = rgb565_nonswapped; + constexpr rgb565_t(void) : raw(0) {} + constexpr rgb565_t(const rgb565_t&) = default; + constexpr rgb565_t(uint8_t r8, uint8_t g8, uint8_t b8) : raw(color565(r8, g8, b8)) {} + constexpr rgb565_t(uint16_t rgb565) : raw(rgb565) {} + inline rgb565_t& operator=(uint16_t rgb565) { *reinterpret_cast(this) = rgb565; return *this; } + inline rgb565_t& operator=(const rgb332_t& ); + inline rgb565_t& operator=(const rgb565_t& ) = default; + inline rgb565_t& operator=(const rgb888_t& ); + inline rgb565_t& operator=(const argb8888_t& ); + inline rgb565_t& operator=(const swap565_t& ); + inline rgb565_t& operator=(const bgr666_t& ); + inline rgb565_t& operator=(const bgr888_t& ); + inline rgb565_t& operator=(const bgra8888_t& ); + inline rgb565_t& operator=(const grayscale_t&); + explicit inline operator uint16_t(void) const { return pgm_read_word(this); } + explicit inline operator bool(void) const { return pgm_read_word(this); } + static constexpr uint8_t A8(void) { return 255; } + inline constexpr uint8_t R8(void) const { return (r5 << 3) + (r5 >> 2); } + inline constexpr uint8_t G8(void) const { return (g6 << 2) + (g6 >> 4); } + inline constexpr uint8_t B8(void) const { return (b5 << 3) + (b5 >> 2); } + inline constexpr uint8_t R6(void) const { return (r5 << 1) + (r5 >> 4); } + inline constexpr uint8_t G6(void) const { return g6; } + inline constexpr uint8_t B6(void) const { return (b5 << 1) + (b5 >> 4); } + inline void R8(uint8_t r8) { r5 = r8 >> 3; } + inline void G8(uint8_t g8) { g6 = g8 >> 2; } + inline void B8(uint8_t b8) { b5 = b8 >> 3; } + inline void set(uint8_t r8, uint8_t g8, uint8_t b8) { *reinterpret_cast(this) = color565(r8, g8, b8); } + inline void set(uint_fast16_t c) { *reinterpret_cast(this) = c; } + inline uint_fast16_t get(void) const { return pgm_read_word(this); } }; - struct rgb565_t + struct rgb888_t { union { struct { - std::uint16_t b5: 5; - std::uint16_t g6: 6; - std::uint16_t r5: 5; + uint8_t b; + uint8_t g; + uint8_t r; }; - std::uint16_t raw; + uint16_t bg; }; - static constexpr std::uint8_t bits = 16; + static constexpr uint8_t bits = 24; static constexpr bool swapped = false; - static constexpr color_depth_t depth = rgb565_nonswapped; - constexpr rgb565_t(void) : raw(0) {} - constexpr rgb565_t(const rgb565_t&) = default; - constexpr rgb565_t(std::uint8_t r8, std::uint8_t g8, std::uint8_t b8) : raw(color565(r8, g8, b8)) {} - constexpr rgb565_t(std::uint16_t rgb565) : raw(rgb565) {} - inline rgb565_t& operator=(const rgb332_t&); - inline rgb565_t& operator=(const rgb888_t&); - inline rgb565_t& operator=(const argb8888_t&); - inline rgb565_t& operator=(const swap565_t&); - inline rgb565_t& operator=(const bgr666_t&); - inline rgb565_t& operator=(const bgr888_t&); - inline rgb565_t& operator=(const bgra8888_t&); - inline rgb565_t& operator=(const grayscale_t&); - inline rgb565_t& operator=(std::uint16_t rgb565) { *reinterpret_cast(this) = rgb565; return *this; } - explicit inline constexpr operator std::uint16_t(void) const { return raw; } - explicit inline constexpr operator bool(void) const { return raw; } - static constexpr std::uint8_t A8(void) { return 255; } - inline constexpr std::uint8_t R8(void) const { return (r5 * 0x21) >> 2; } // (r << 3) | (r >> 2); - inline constexpr std::uint8_t G8(void) const { return (g6 * 0x41) >> 4; } // (g << 2) | (g >> 4); - inline constexpr std::uint8_t B8(void) const { return (b5 * 0x21) >> 2; } // (b << 3) | (b >> 2); - inline constexpr std::uint8_t R6(void) const { return (r5 * 0x21) >> 4; } - inline constexpr std::uint8_t G6(void) const { return g6; } - inline constexpr std::uint8_t B6(void) const { return (b5 * 0x21) >> 4; } - inline void R8(std::uint8_t r8) { r5 = r8 >> 3; } - inline void G8(std::uint8_t g8) { g6 = g8 >> 2; } - inline void B8(std::uint8_t b8) { b5 = b8 >> 3; } - inline void set(std::uint8_t r8, std::uint8_t g8, std::uint8_t b8) { *reinterpret_cast(this) = color565(r8, g8, b8); } + static constexpr color_depth_t depth = rgb888_nonswapped; + constexpr rgb888_t(void) : b(0), g(0), r(0) {} + constexpr rgb888_t(const rgb888_t&) = default; + constexpr rgb888_t(uint8_t r8, uint8_t g8, uint8_t b8) : b(b8), g(g8), r(r8) {} + constexpr rgb888_t(uint32_t rgb888) : b(rgb888), g(rgb888>>8), r(rgb888>>16) {} + inline rgb888_t& operator=(uint32_t rgb888) { r = rgb888>>16; g = rgb888>>8; b = rgb888; return *this; } + inline rgb888_t& operator=(const rgb332_t& ); + inline rgb888_t& operator=(const rgb565_t& ); + inline rgb888_t& operator=(const rgb888_t& ) = default; + inline rgb888_t& operator=(const argb8888_t& ); + inline rgb888_t& operator=(const swap565_t& ); + inline rgb888_t& operator=(const bgr666_t& ); + inline rgb888_t& operator=(const bgr888_t& ); + inline rgb888_t& operator=(const bgra8888_t& ); + inline rgb888_t& operator=(const grayscale_t&); + explicit inline operator uint32_t(void) const { return pgm_read_3byte_unaligned(this); } + explicit inline operator bool(void) const { return pgm_read_3byte_unaligned(this); } + static constexpr uint8_t A8(void) { return 255; } + inline constexpr uint8_t R8(void) const { return r; } + inline constexpr uint8_t G8(void) const { return g; } + inline constexpr uint8_t B8(void) const { return b; } + inline constexpr uint8_t R6(void) const { return r >> 2; } + inline constexpr uint8_t G6(void) const { return g >> 2; } + inline constexpr uint8_t B6(void) const { return b >> 2; } + inline void R8(uint8_t r8) { r = r8; } + inline void G8(uint8_t g8) { g = g8; } + inline void B8(uint8_t b8) { b = b8; } + inline void set(uint8_t r8, uint8_t g8, uint8_t b8) { r = r8; g = g8; b = b8; } + inline void set(uint_fast32_t c) { write_3byte_unaligned(this, c); } + inline uint_fast32_t get(void) const { return pgm_read_3byte_unaligned(this); } }; - struct bgr666_t + struct argb8888_t { - std::uint8_t r6; - std::uint8_t g6; - std::uint8_t b6; - static constexpr std::uint8_t bits = 24; - static constexpr bool swapped = true; - static constexpr color_depth_t depth = rgb666_3Byte; - constexpr bgr666_t(void) : r6(0), g6(0), b6(0) {}; - constexpr bgr666_t(const bgr666_t&) = default; - constexpr bgr666_t(std::uint8_t r8, std::uint8_t g8, std::uint8_t b8) : r6(r8>>2), g6(g8>>2), b6(b8>>2) {} - constexpr bgr666_t(std::uint32_t raw) : r6(raw), g6(raw>>8), b6(raw>>16) {} - inline bgr666_t& operator=(std::uint32_t rhs) { r6 = rhs; g6 = rhs>>8 ; b6 = rhs>>16; return *this; } - inline bgr666_t& operator=(const rgb332_t&); - inline bgr666_t& operator=(const rgb565_t&); - inline bgr666_t& operator=(const rgb888_t&); - inline bgr666_t& operator=(const argb8888_t&); - inline bgr666_t& operator=(const swap565_t&); - inline bgr666_t& operator=(const bgr888_t&); - inline bgr666_t& operator=(const bgra8888_t&); - inline bgr666_t& operator=(const grayscale_t&); - explicit inline constexpr operator std::uint32_t(void) const { return *reinterpret_cast(this) & ((1ul << 24) - 1); } - explicit inline constexpr operator bool(void) const { return r6 || g6 || b6; } - static constexpr std::uint8_t A8(void) { return 255; } - inline constexpr std::uint8_t R8(void) const { return r6<<2; } - inline constexpr std::uint8_t G8(void) const { return g6<<2; } - inline constexpr std::uint8_t B8(void) const { return b6<<2; } - inline constexpr std::uint8_t R6(void) const { return r6; } - inline constexpr std::uint8_t G6(void) const { return g6; } - inline constexpr std::uint8_t B6(void) const { return b6; } - inline void R8(std::uint8_t r8) { r6 = r8 >> 2; } - inline void G8(std::uint8_t g8) { g6 = g8 >> 2; } - inline void B8(std::uint8_t b8) { b6 = b8 >> 2; } - inline void set(std::uint8_t r8, std::uint8_t g8, std::uint8_t b8) { r6 = r8>>2; g6 = g8>>2; b6 = b8>>2; } + union + { + struct + { + uint8_t b; + uint8_t g; + uint8_t r; + uint8_t a; + }; + uint32_t raw; + }; + static constexpr uint8_t bits = 32; + static constexpr bool swapped = false; + static constexpr color_depth_t depth = argb8888_nonswapped; + constexpr argb8888_t(void) : raw(0) {} + constexpr argb8888_t(const argb8888_t&) = default; + constexpr argb8888_t(uint8_t r8, uint8_t g8, uint8_t b8) : b(b8), g(g8), r(r8), a(255) {} + constexpr argb8888_t(uint8_t a8, uint8_t r8, uint8_t g8, uint8_t b8) : b(b8), g(g8), r(r8), a(a8) {} + constexpr argb8888_t(uint32_t argb8888) : raw(argb8888) {} + inline argb8888_t& operator=(uint32_t argb8888) { *reinterpret_cast(this) = argb8888; return *this; } + inline argb8888_t& operator=(const rgb332_t& ); + inline argb8888_t& operator=(const rgb565_t& ); + inline argb8888_t& operator=(const rgb888_t& ); + inline argb8888_t& operator=(const argb8888_t& ) = default; + inline argb8888_t& operator=(const swap565_t& ); + inline argb8888_t& operator=(const bgr666_t& ); + inline argb8888_t& operator=(const bgr888_t& ); + inline argb8888_t& operator=(const bgra8888_t& ); + inline argb8888_t& operator=(const grayscale_t&); + explicit inline operator uint32_t(void) const { return pgm_read_dword(this); } + explicit inline operator bool(void) const { return pgm_read_dword(this); } + inline constexpr uint8_t A8(void) const { return a; } + inline constexpr uint8_t R8(void) const { return r; } + inline constexpr uint8_t G8(void) const { return g; } + inline constexpr uint8_t B8(void) const { return b; } + inline constexpr uint8_t R6(void) const { return r >> 2; } + inline constexpr uint8_t G6(void) const { return g >> 2; } + inline constexpr uint8_t B6(void) const { return b >> 2; } + inline void A8(uint8_t a8) { a = a8; } + inline void R8(uint8_t r8) { r = r8; } + inline void G8(uint8_t g8) { g = g8; } + inline void B8(uint8_t b8) { b = b8; } + inline void set(uint8_t r8, uint8_t g8, uint8_t b8) { a = 255; r = r8; g = g8; b = b8; } + inline void set(uint8_t a8, uint8_t r8, uint8_t g8, uint8_t b8) { a = a8; r = r8; g = g8; b = b8; } + inline void set(uint_fast32_t c) { *reinterpret_cast(this) = c; } + inline uint_fast32_t get(void) const { return pgm_read_dword(this); } }; - struct bgr888_t + struct swap565_t { union { struct { - std::uint8_t r; - std::uint8_t g; - std::uint8_t b; + uint16_t gh:3; + uint16_t r5:5; + uint16_t b5:5; + uint16_t gl:3; }; - std::uint16_t rg; + uint16_t raw; }; - static constexpr std::uint8_t bits = 24; + static constexpr uint8_t bits = 16; static constexpr bool swapped = true; - static constexpr color_depth_t depth = rgb888_3Byte; - constexpr bgr888_t(void) : r{0}, g{0}, b{0} {}; - constexpr bgr888_t(const bgr888_t&) = default; - constexpr bgr888_t(std::uint8_t r8, std::uint8_t g8, std::uint8_t b8) : r(r8), g(g8), b(b8) {} - constexpr bgr888_t(std::uint32_t bgr888) : r(bgr888), g(bgr888>>8), b(bgr888>>16) {} - inline bgr888_t& operator=(std::uint32_t rhs) { r = rhs; g = rhs>>8 ; b = rhs>>16; return *this; } - inline bgr888_t& operator=(const rgb332_t&); - inline bgr888_t& operator=(const rgb565_t&); - inline bgr888_t& operator=(const rgb888_t&); - inline bgr888_t& operator=(const argb8888_t&); - inline bgr888_t& operator=(const swap565_t&); - inline bgr888_t& operator=(const bgr666_t&); - inline bgr888_t& operator=(const bgra8888_t&); - inline bgr888_t& operator=(const grayscale_t&); - explicit inline constexpr operator std::uint32_t(void) const { return *reinterpret_cast(this) & ((1ul << 24) - 1); } - explicit inline constexpr operator bool(void) const { return rg || b; } - static constexpr std::uint8_t A8() { return 255; } - inline constexpr std::uint8_t R8() const { return r; } - inline constexpr std::uint8_t G8() const { return g; } - inline constexpr std::uint8_t B8() const { return b; } - inline constexpr std::uint8_t R6() const { return r >> 2; } - inline constexpr std::uint8_t G6() const { return g >> 2; } - inline constexpr std::uint8_t B6() const { return b >> 2; } - inline void R8(std::uint8_t r8) { r = r8; } - inline void G8(std::uint8_t g8) { g = g8; } - inline void B8(std::uint8_t b8) { b = b8; } - inline void set(std::uint8_t r8, std::uint8_t g8, std::uint8_t b8) { r = r8; g = g8; b = b8; } + static constexpr color_depth_t depth = rgb565_2Byte; + constexpr swap565_t(void) : raw(0) {} + constexpr swap565_t(const swap565_t&) = default; + constexpr swap565_t(uint8_t r8, uint8_t g8, uint8_t b8) : raw(swap565(r8, g8, b8)) {} + constexpr swap565_t(uint16_t swap565) : raw(swap565) {} + inline swap565_t& operator=(uint16_t swap565) { *reinterpret_cast(this) = swap565; return *this; } + inline swap565_t& operator=(const rgb332_t& ); + inline swap565_t& operator=(const rgb565_t& ); + inline swap565_t& operator=(const rgb888_t& ); + inline swap565_t& operator=(const argb8888_t& ); + inline swap565_t& operator=(const swap565_t& ) = default; + inline swap565_t& operator=(const bgr666_t& ); + inline swap565_t& operator=(const bgr888_t& ); + inline swap565_t& operator=(const bgra8888_t& ); + inline swap565_t& operator=(const grayscale_t&); + explicit inline operator uint16_t(void) const { return pgm_read_word(this); } + explicit inline operator bool(void) const { return pgm_read_word(this); } + static constexpr uint8_t A8(void) { return 255; } + inline constexpr uint8_t R8(void) const { return (r5 << 3) + (r5 >> 2); } + inline constexpr uint8_t G8(void) const { return (((gh << 3) + gl) << 2) + (gh >> 1); } + inline constexpr uint8_t B8(void) const { return (b5 << 3) + (b5 >> 2); } + inline constexpr uint8_t R6(void) const { return (r5 << 1) + (r5 >> 4); } + inline constexpr uint8_t G6(void) const { return (gh << 3) + gl; } + inline constexpr uint8_t B6(void) const { return (b5 << 1) + (b5 >> 4); } + inline void R8(uint8_t r8) { r5 = r8 >> 3; } + inline void G8(uint8_t g8) { gh = g8 >> 5; gl = g8 >> 2;} + inline void B8(uint8_t b8) { b5 = b8 >> 3; } + inline void set(uint8_t r8, uint8_t g8, uint8_t b8) { *reinterpret_cast(this) = swap565(r8, g8, b8); } + inline void set(uint_fast16_t c) { *reinterpret_cast(this) = c; } + inline uint_fast16_t get(void) const { return pgm_read_word(this); } }; - struct rgb888_t + struct bgr666_t { union { struct { - std::uint8_t b; - std::uint8_t g; - std::uint8_t r; + uint8_t r6; + uint8_t g6; + uint8_t b6; }; - std::uint16_t bg; + uint16_t rg; }; - static constexpr std::uint8_t bits = 24; - static constexpr bool swapped = false; - static constexpr color_depth_t depth = rgb888_nonswapped; - constexpr rgb888_t(void) : b(0), g(0), r(0) {} - constexpr rgb888_t(const rgb888_t&) = default; - constexpr rgb888_t(std::uint8_t r8, std::uint8_t g8, std::uint8_t b8) : b(b8), g(g8), r(r8) {} - constexpr rgb888_t(std::uint32_t rgb888) : b(rgb888), g(rgb888>>8), r(rgb888>>16) {} - inline rgb888_t& operator=(const rgb332_t&); - inline rgb888_t& operator=(const rgb565_t&); - inline rgb888_t& operator=(const argb8888_t&); - inline rgb888_t& operator=(const swap565_t&); - inline rgb888_t& operator=(const bgr666_t&); - inline rgb888_t& operator=(const bgr888_t&); - inline rgb888_t& operator=(const bgra8888_t&); - inline rgb888_t& operator=(const grayscale_t&); - inline rgb888_t& operator=(std::uint32_t rgb888) { r = rgb888>>16; g = rgb888>>8; b = rgb888; return *this; } - explicit inline constexpr operator std::uint32_t(void) const { return *reinterpret_cast(this) & ((1ul << 24) - 1); } - explicit inline constexpr operator bool(void) const { return bg || r; } - static constexpr std::uint8_t A8(void) { return 255; } - inline constexpr std::uint8_t R8(void) const { return r; } - inline constexpr std::uint8_t G8(void) const { return g; } - inline constexpr std::uint8_t B8(void) const { return b; } - inline constexpr std::uint8_t R6(void) const { return r >> 2; } - inline constexpr std::uint8_t G6(void) const { return g >> 2; } - inline constexpr std::uint8_t B6(void) const { return b >> 2; } - inline void R8(std::uint8_t r8) { r = r8; } - inline void G8(std::uint8_t g8) { g = g8; } - inline void B8(std::uint8_t b8) { b = b8; } - inline void set(std::uint8_t r8, std::uint8_t g8, std::uint8_t b8) { r = r8; g = g8; b = b8; } + static constexpr uint8_t bits = 24; + static constexpr bool swapped = true; + static constexpr color_depth_t depth = rgb666_3Byte; + constexpr bgr666_t(void) : r6(0), g6(0), b6(0) {}; + constexpr bgr666_t(const bgr666_t&) = default; + constexpr bgr666_t(uint8_t r8, uint8_t g8, uint8_t b8) : r6(r8>>2), g6(g8>>2), b6(b8>>2) {} + constexpr bgr666_t(uint32_t raw) : r6(raw), g6(raw>>8), b6(raw>>16) {} + inline bgr666_t& operator=(uint32_t bgr666) { r6 = bgr666; g6 = bgr666 >> 8 ; b6 = bgr666 >> 16; return *this; } + inline bgr666_t& operator=(const rgb332_t& ); + inline bgr666_t& operator=(const rgb565_t& ); + inline bgr666_t& operator=(const rgb888_t& ); + inline bgr666_t& operator=(const argb8888_t& ); + inline bgr666_t& operator=(const swap565_t& ); + inline bgr666_t& operator=(const bgr666_t& ) = default; + inline bgr666_t& operator=(const bgr888_t& ); + inline bgr666_t& operator=(const bgra8888_t& ); + inline bgr666_t& operator=(const grayscale_t&); + explicit inline operator uint32_t(void) const { return pgm_read_3byte_unaligned(this); } + explicit inline operator bool(void) const { return pgm_read_3byte_unaligned(this); } + static constexpr uint8_t A8(void) { return 255; } + inline constexpr uint8_t R8(void) const { return (r6 << 2) + (r6 >> 4); } + inline constexpr uint8_t G8(void) const { return (g6 << 2) + (g6 >> 4); } + inline constexpr uint8_t B8(void) const { return (b6 << 2) + (b6 >> 4); } + inline constexpr uint8_t R6(void) const { return r6; } + inline constexpr uint8_t G6(void) const { return g6; } + inline constexpr uint8_t B6(void) const { return b6; } + inline void R8(uint8_t r8) { r6 = r8 >> 2; } + inline void G8(uint8_t g8) { g6 = g8 >> 2; } + inline void B8(uint8_t b8) { b6 = b8 >> 2; } + inline void set(uint8_t r8, uint8_t g8, uint8_t b8) { r6 = r8>>2; g6 = g8>>2; b6 = b8>>2; } + inline void set(uint_fast32_t c) { write_3byte_unaligned(this, c); } + inline uint_fast32_t get(void) const { return pgm_read_3byte_unaligned(this); } }; - struct bgra8888_t + struct bgr888_t { union { struct { - std::uint8_t a; - std::uint8_t r; - std::uint8_t g; - std::uint8_t b; + uint8_t r; + uint8_t g; + uint8_t b; }; - std::uint32_t raw; + uint16_t rg; }; - static constexpr std::uint8_t bits = 32; + static constexpr uint8_t bits = 24; static constexpr bool swapped = true; - static constexpr color_depth_t depth = argb8888_4Byte; - constexpr bgra8888_t(void) : raw{0} {}; - constexpr bgra8888_t(const bgra8888_t&) = default; - constexpr bgra8888_t(std::uint8_t r8, std::uint8_t g8, std::uint8_t b8) : r(r8), g(g8), b(b8) {} - constexpr bgra8888_t(std::uint8_t a8, std::uint8_t r8, std::uint8_t g8, std::uint8_t b8) : a(a8), r(r8), g(g8), b(b8) {} - constexpr bgra8888_t(std::uint32_t bgra8888) : raw(bgra8888) {} - inline bgra8888_t& operator=(std::uint32_t rhs) { raw = rhs; return *this; } - inline bgra8888_t& operator=(const rgb332_t&); - inline bgra8888_t& operator=(const rgb565_t&); - inline bgra8888_t& operator=(const rgb888_t&); - inline bgra8888_t& operator=(const argb8888_t&); - inline bgra8888_t& operator=(const swap565_t&); - inline bgra8888_t& operator=(const bgr666_t&); - inline bgra8888_t& operator=(const bgr888_t&); - inline bgra8888_t& operator=(const grayscale_t&); - explicit inline constexpr operator std::uint32_t(void) const { return raw; } - explicit inline constexpr operator bool(void) const { return raw; } - inline constexpr std::uint8_t A8(void) const { return a; } - inline constexpr std::uint8_t R8(void) const { return r; } - inline constexpr std::uint8_t G8(void) const { return g; } - inline constexpr std::uint8_t B8(void) const { return b; } - inline constexpr std::uint8_t R6(void) const { return r >> 2; } - inline constexpr std::uint8_t G6(void) const { return g >> 2; } - inline constexpr std::uint8_t B6(void) const { return b >> 2; } - inline void A8(std::uint8_t a8) { a = a8; } - inline void R8(std::uint8_t r8) { r = r8; } - inline void G8(std::uint8_t g8) { g = g8; } - inline void B8(std::uint8_t b8) { b = b8; } - inline void set(std::uint8_t r8, std::uint8_t g8, std::uint8_t b8) { a = 255; r = r8; g = g8; b = b8; } - inline void set(std::uint8_t a8, std::uint8_t r8, std::uint8_t g8, std::uint8_t b8) { a = a8; r = r8; g = g8; b = b8; } + static constexpr color_depth_t depth = rgb888_3Byte; + constexpr bgr888_t(void) : r{0}, g{0}, b{0} {}; + constexpr bgr888_t(const bgr888_t&) = default; + constexpr bgr888_t(uint8_t r8, uint8_t g8, uint8_t b8) : r(r8), g(g8), b(b8) {} + constexpr bgr888_t(uint32_t bgr888) : r(bgr888), g(bgr888>>8), b(bgr888>>16) {} + inline bgr888_t& operator=(uint32_t bgr888) { r = bgr888; g = bgr888>>8 ; b = bgr888>>16; return *this; } + inline bgr888_t& operator=(const rgb332_t& ); + inline bgr888_t& operator=(const rgb565_t& ); + inline bgr888_t& operator=(const rgb888_t& ); + inline bgr888_t& operator=(const argb8888_t& ); + inline bgr888_t& operator=(const swap565_t& ); + inline bgr888_t& operator=(const bgr666_t& ); + inline bgr888_t& operator=(const bgr888_t& ) = default; + inline bgr888_t& operator=(const bgra8888_t& ); + inline bgr888_t& operator=(const grayscale_t&); + explicit inline operator uint32_t(void) const { return pgm_read_3byte_unaligned(this); } + explicit inline operator bool(void) const { return pgm_read_3byte_unaligned(this); } + static constexpr uint8_t A8() { return 255; } + inline constexpr uint8_t R8() const { return r; } + inline constexpr uint8_t G8() const { return g; } + inline constexpr uint8_t B8() const { return b; } + inline constexpr uint8_t R6() const { return r >> 2; } + inline constexpr uint8_t G6() const { return g >> 2; } + inline constexpr uint8_t B6() const { return b >> 2; } + inline void R8(uint8_t r8) { r = r8; } + inline void G8(uint8_t g8) { g = g8; } + inline void B8(uint8_t b8) { b = b8; } + inline void set(uint8_t r8, uint8_t g8, uint8_t b8) { r = r8; g = g8; b = b8; } + inline void set(uint_fast32_t c) { write_3byte_unaligned(this, c); } + inline uint_fast32_t get(void) const { return pgm_read_3byte_unaligned(this); } }; - struct argb8888_t + struct bgra8888_t { union { struct { - std::uint8_t b; - std::uint8_t g; - std::uint8_t r; - std::uint8_t a; + uint8_t a; + uint8_t r; + uint8_t g; + uint8_t b; }; - std::uint32_t raw; + uint32_t raw; }; - static constexpr std::uint8_t bits = 32; - static constexpr bool swapped = false; - static constexpr color_depth_t depth = argb8888_nonswapped; - constexpr argb8888_t(void) : raw(0) {} - constexpr argb8888_t(const argb8888_t&) = default; - constexpr argb8888_t(std::uint8_t r8, std::uint8_t g8, std::uint8_t b8) : b(b8), g(g8), r(r8), a(255) {} - constexpr argb8888_t(std::uint8_t a8, std::uint8_t r8, std::uint8_t g8, std::uint8_t b8) : b(b8), g(g8), r(r8), a(a8) {} - constexpr argb8888_t(std::uint32_t argb8888) : raw(argb8888) {} - inline argb8888_t& operator=(const rgb332_t&); - inline argb8888_t& operator=(const rgb565_t&); - inline argb8888_t& operator=(const rgb888_t&); - inline argb8888_t& operator=(const swap565_t&); - inline argb8888_t& operator=(const bgr666_t&); - inline argb8888_t& operator=(const bgr888_t&); - inline argb8888_t& operator=(const bgra8888_t&); - inline argb8888_t& operator=(const grayscale_t&); - inline argb8888_t& operator=(std::uint32_t argb8888) { *reinterpret_cast(this) = argb8888; return *this; } - explicit inline constexpr operator std::uint32_t(void) const { return raw; } - explicit inline constexpr operator bool(void) const { return raw; } - inline constexpr std::uint8_t A8(void) const { return a; } - inline constexpr std::uint8_t R8(void) const { return r; } - inline constexpr std::uint8_t G8(void) const { return g; } - inline constexpr std::uint8_t B8(void) const { return b; } - inline constexpr std::uint8_t R6(void) const { return r >> 2; } - inline constexpr std::uint8_t G6(void) const { return g >> 2; } - inline constexpr std::uint8_t B6(void) const { return b >> 2; } - inline void A8(std::uint8_t a8) { a = a8; } - inline void R8(std::uint8_t r8) { r = r8; } - inline void G8(std::uint8_t g8) { g = g8; } - inline void B8(std::uint8_t b8) { b = b8; } - inline void set(std::uint8_t r8, std::uint8_t g8, std::uint8_t b8) { a = 255; r = r8; g = g8; b = b8; } - inline void set(std::uint8_t a8, std::uint8_t r8, std::uint8_t g8, std::uint8_t b8) { a = a8; r = r8; g = g8; b = b8; } + static constexpr uint8_t bits = 32; + static constexpr bool swapped = true; + static constexpr color_depth_t depth = argb8888_4Byte; + constexpr bgra8888_t(void) : raw{0} {}; + constexpr bgra8888_t(const bgra8888_t&) = default; + constexpr bgra8888_t(uint8_t r8, uint8_t g8, uint8_t b8) : r(r8), g(g8), b(b8) {} + constexpr bgra8888_t(uint8_t a8, uint8_t r8, uint8_t g8, uint8_t b8) : a(a8), r(r8), g(g8), b(b8) {} + constexpr bgra8888_t(uint32_t bgra8888) : raw(bgra8888) {} + inline bgra8888_t& operator=(uint32_t rhs) { *reinterpret_cast(this) = rhs; return *this; } + inline bgra8888_t& operator=(const rgb332_t& ); + inline bgra8888_t& operator=(const rgb565_t& ); + inline bgra8888_t& operator=(const rgb888_t& ); + inline bgra8888_t& operator=(const argb8888_t& ); + inline bgra8888_t& operator=(const swap565_t& ); + inline bgra8888_t& operator=(const bgr666_t& ); + inline bgra8888_t& operator=(const bgr888_t& ); + inline bgra8888_t& operator=(const bgra8888_t& ) = default; + inline bgra8888_t& operator=(const grayscale_t&); + explicit inline operator uint32_t(void) const { return pgm_read_dword(this); } + explicit inline operator bool(void) const { return pgm_read_dword(this); } + inline constexpr uint8_t A8(void) const { return a; } + inline constexpr uint8_t R8(void) const { return r; } + inline constexpr uint8_t G8(void) const { return g; } + inline constexpr uint8_t B8(void) const { return b; } + inline constexpr uint8_t R6(void) const { return r >> 2; } + inline constexpr uint8_t G6(void) const { return g >> 2; } + inline constexpr uint8_t B6(void) const { return b >> 2; } + inline void A8(uint8_t a8) { a = a8; } + inline void R8(uint8_t r8) { r = r8; } + inline void G8(uint8_t g8) { g = g8; } + inline void B8(uint8_t b8) { b = b8; } + inline void set(uint8_t r8, uint8_t g8, uint8_t b8) { a = 255; r = r8; g = g8; b = b8; } + inline void set(uint8_t a8, uint8_t r8, uint8_t g8, uint8_t b8) { a = a8; r = r8; g = g8; b = b8; } + inline void set(uint_fast32_t c) { *reinterpret_cast(this) = c; } + inline uint_fast32_t get(void) const { return pgm_read_dword(this); } }; struct grayscale_t { union { - std::uint8_t raw; - std::uint8_t r; - std::uint8_t g; - std::uint8_t b; + uint8_t raw; + uint8_t r; + uint8_t g; + uint8_t b; }; - static constexpr std::uint8_t bits = 8; + static constexpr uint8_t bits = 8; static constexpr bool swapped = true; static constexpr color_depth_t depth = grayscale_8bit; constexpr grayscale_t(void) : raw{0} {}; constexpr grayscale_t(const grayscale_t&) = default; - constexpr grayscale_t(std::uint8_t r8, std::uint8_t g8, std::uint8_t b8) : raw((r8 + (g8 << 1) + b8) >> 2) {} - constexpr grayscale_t(std::uint8_t gray8) : raw(gray8) {} - inline grayscale_t& operator=(std::uint8_t gray8) { *reinterpret_cast(this) = gray8; return *this; } - inline grayscale_t& operator=(const rgb332_t&); - inline grayscale_t& operator=(const rgb565_t&); - inline grayscale_t& operator=(const rgb888_t&); - inline grayscale_t& operator=(const argb8888_t&); - inline grayscale_t& operator=(const swap565_t&); - inline grayscale_t& operator=(const bgr666_t&); - inline grayscale_t& operator=(const bgr888_t&); - explicit inline constexpr operator std::uint8_t(void) const { return raw; } - explicit inline constexpr operator bool(void) const { return raw; } - static constexpr std::uint8_t A8(void) { return 255; } - inline constexpr std::uint8_t R8(void) const { return r; } - inline constexpr std::uint8_t G8(void) const { return g; } - inline constexpr std::uint8_t B8(void) const { return b; } - inline constexpr std::uint8_t R6(void) const { return r >> 2; } - inline constexpr std::uint8_t G6(void) const { return g >> 2; } - inline constexpr std::uint8_t B6(void) const { return b >> 2; } - inline void R8(std::uint8_t r8) { r = r8; } - inline void G8(std::uint8_t g8) { g = g8; } - inline void B8(std::uint8_t b8) { b = b8; } - inline void set(std::uint8_t r8, std::uint8_t g8, std::uint8_t b8) { raw = (r8 + (g8 << 1) + b8) >> 2; } + constexpr grayscale_t(uint8_t r8, uint8_t g8, uint8_t b8) : raw((r8 + (g8 << 1) + b8) >> 2) {} + constexpr grayscale_t(uint8_t gray8) : raw(gray8) {} + inline grayscale_t& operator=(uint8_t gray8) { *reinterpret_cast(this) = gray8; return *this; } + inline grayscale_t& operator=(const rgb332_t& ); + inline grayscale_t& operator=(const rgb565_t& ); + inline grayscale_t& operator=(const rgb888_t& ); + inline grayscale_t& operator=(const argb8888_t& ); + inline grayscale_t& operator=(const swap565_t& ); + inline grayscale_t& operator=(const bgr666_t& ); + inline grayscale_t& operator=(const bgr888_t& ); + inline grayscale_t& operator=(const bgra8888_t& ); + inline grayscale_t& operator=(const grayscale_t&) = default; + explicit inline operator uint8_t(void) const { return pgm_read_byte(this); } + explicit inline operator bool(void) const { return pgm_read_byte(this); } + static constexpr uint8_t A8(void) { return 255; } + inline constexpr uint8_t R8(void) const { return r; } + inline constexpr uint8_t G8(void) const { return g; } + inline constexpr uint8_t B8(void) const { return b; } + inline constexpr uint8_t R6(void) const { return r >> 2; } + inline constexpr uint8_t G6(void) const { return g >> 2; } + inline constexpr uint8_t B6(void) const { return b >> 2; } + inline void R8(uint8_t r8) { r = r8; } + inline void G8(uint8_t g8) { g = g8; } + inline void B8(uint8_t b8) { b = b8; } + inline void set(uint8_t r8, uint8_t g8, uint8_t b8) { raw = (r8 + (g8 << 1) + b8) >> 2; } + inline void set(uint_fast32_t c) { *reinterpret_cast(this) = c; } + inline uint_fast8_t get(void) const { return pgm_read_byte(this); } }; struct raw_color_t @@ -515,127 +490,199 @@ namespace lgfx { struct { - std::uint8_t raw0; - std::uint8_t raw1; - std::uint8_t raw2; - std::uint8_t raw3; + uint8_t raw0; + uint8_t raw1; + uint8_t raw2; + uint8_t raw3; }; struct { - std::uint16_t rawL; - std::uint16_t rawH; + uint16_t rawL; + uint16_t rawH; }; - std::uint32_t raw; + uint32_t raw; }; constexpr raw_color_t() : raw(0) {} constexpr raw_color_t(const raw_color_t&) = default; - constexpr raw_color_t(const std::uint32_t& rhs) : raw(rhs) {} + constexpr raw_color_t(const uint32_t& rhs) : raw(rhs) {} }; #pragma pack(pop) - inline rgb332_t& rgb332_t::operator=(const rgb565_t& rhs) { raw = (rhs.r5 >> 2) << 5 | (rhs.g6 >> 3) << 2 | rhs.b5 >> 3; return *this; } - inline rgb332_t& rgb332_t::operator=(const swap565_t& rhs) { raw = ((rhs.r5 << 3) & 0xE0) | ((rhs.gh << 2) + (rhs.b5 >> 3)); return *this; } - inline rgb332_t& rgb332_t::operator=(const bgr666_t& rhs) { raw = ((rhs.r6 << 2) & 0xE0) | ((rhs.g6 >> 1) & 0x1C) | (rhs.b6 >> 4); return *this; } - inline rgb332_t& rgb332_t::operator=(const rgb888_t& rhs) { raw = color332(rhs.R8(), rhs.G8(), rhs.B8()); return *this; } - inline rgb332_t& rgb332_t::operator=(const bgr888_t& rhs) { raw = color332(rhs.R8(), rhs.G8(), rhs.B8()); return *this; } - inline rgb332_t& rgb332_t::operator=(const argb8888_t& rhs) { raw = color332(rhs.R8(), rhs.G8(), rhs.B8()); return *this; } - inline rgb332_t& rgb332_t::operator=(const bgra8888_t& rhs) { raw = color332(rhs.R8(), rhs.G8(), rhs.B8()); return *this; } - inline rgb332_t& rgb332_t::operator=(const grayscale_t& rhs){ raw = color332(rhs.R8(), rhs.G8(), rhs.B8()); return *this; } - - inline rgb565_t& rgb565_t::operator=(const rgb332_t& rhs) { raw = color565(rhs.R8(), rhs.G8(), rhs.B8()); return *this; } - inline rgb565_t& rgb565_t::operator=(const swap565_t& rhs) { raw = __builtin_bswap16(rhs.raw); return *this; } - inline rgb565_t& rgb565_t::operator=(const bgr666_t& rhs) { raw = color565(rhs.R8(), rhs.G8(), rhs.B8()); return *this; } - inline rgb565_t& rgb565_t::operator=(const rgb888_t& rhs) { raw = color565(rhs.R8(), rhs.G8(), rhs.B8()); return *this; } - inline rgb565_t& rgb565_t::operator=(const bgr888_t& rhs) { raw = color565(rhs.R8(), rhs.G8(), rhs.B8()); return *this; } - inline rgb565_t& rgb565_t::operator=(const argb8888_t& rhs) { raw = color565(rhs.R8(), rhs.G8(), rhs.B8()); return *this; } - inline rgb565_t& rgb565_t::operator=(const bgra8888_t& rhs) { raw = color565(rhs.R8(), rhs.G8(), rhs.B8()); return *this; } - inline rgb565_t& rgb565_t::operator=(const grayscale_t& rhs){ raw = color565(rhs.R8(), rhs.G8(), rhs.B8()); return *this; } - - inline rgb888_t& rgb888_t::operator=(const rgb332_t& rhs) { r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline rgb888_t& rgb888_t::operator=(const rgb565_t& rhs) { r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline rgb888_t& rgb888_t::operator=(const swap565_t& rhs) { r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline rgb888_t& rgb888_t::operator=(const bgr666_t& rhs) { r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline rgb888_t& rgb888_t::operator=(const bgr888_t& rhs) { r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline rgb888_t& rgb888_t::operator=(const argb8888_t& rhs) { r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline rgb888_t& rgb888_t::operator=(const bgra8888_t& rhs) { r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline rgb888_t& rgb888_t::operator=(const grayscale_t& rhs){ r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - - inline swap565_t& swap565_t::operator=(const rgb332_t& rhs) { *reinterpret_cast(this) = ((rhs.b2 * 0x15)>>1)<<8 | rhs.g3 << 13 | rhs.g3 | ((rhs.r3 * 0x09) >> 1) << 3; return *this; } - inline swap565_t& swap565_t::operator=(const rgb565_t& rhs) { *reinterpret_cast(this) = __builtin_bswap16(rhs.raw); return *this; } - inline swap565_t& swap565_t::operator=(const rgb888_t& rhs) { *reinterpret_cast(this) = swap565(rhs.R8(), rhs.G8(), rhs.B8()); return *this; } - inline swap565_t& swap565_t::operator=(const bgr666_t& rhs) { raw = (rhs.b6 >> 1)<<8 | rhs.g6 << 13 | rhs.g6 >> 3 | (rhs.r6 >> 1) << 3; return *this; } - inline swap565_t& swap565_t::operator=(const bgr888_t& rhs) { *reinterpret_cast(this) = swap565(rhs.R8(), rhs.G8(), rhs.B8()); return *this; } - inline swap565_t& swap565_t::operator=(const argb8888_t& rhs) { *reinterpret_cast(this) = swap565(rhs.R8(), rhs.G8(), rhs.B8()); return *this; } - inline swap565_t& swap565_t::operator=(const bgra8888_t& rhs) { *reinterpret_cast(this) = swap565(rhs.R8(), rhs.G8(), rhs.B8()); return *this; } - inline swap565_t& swap565_t::operator=(const grayscale_t& rhs){ *reinterpret_cast(this) = swap565(rhs.R8(), rhs.G8(), rhs.B8()); return *this; } - - inline bgr666_t& bgr666_t::operator=(const rgb332_t& rhs) { r6 = rhs.R6(); g6 = rhs.G6(); b6 = rhs.B6(); return *this; } - inline bgr666_t& bgr666_t::operator=(const rgb565_t& rhs) { r6 = rhs.R6(); g6 = rhs.G6(); b6 = rhs.B6(); return *this; } - inline bgr666_t& bgr666_t::operator=(const swap565_t& rhs) { r6 = rhs.R6(); g6 = rhs.G6(); b6 = rhs.B6(); return *this; } - inline bgr666_t& bgr666_t::operator=(const bgr888_t& rhs) { r6 = rhs.R6(); g6 = rhs.G6(); b6 = rhs.B6(); return *this; } - inline bgr666_t& bgr666_t::operator=(const rgb888_t& rhs) { r6 = rhs.R6(); g6 = rhs.G6(); b6 = rhs.B6(); return *this; } - inline bgr666_t& bgr666_t::operator=(const argb8888_t& rhs) { r6 = rhs.R6(); g6 = rhs.G6(); b6 = rhs.B6(); return *this; } - inline bgr666_t& bgr666_t::operator=(const bgra8888_t& rhs) { r6 = rhs.R6(); g6 = rhs.G6(); b6 = rhs.B6(); return *this; } - inline bgr666_t& bgr666_t::operator=(const grayscale_t& rhs){ r6 = rhs.R6(); g6 = rhs.G6(); b6 = rhs.B6(); return *this; } - - inline bgr888_t& bgr888_t::operator=(const rgb332_t& rhs) { r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline bgr888_t& bgr888_t::operator=(const rgb565_t& rhs) { rg = rhs.R8() | rhs.G8() <<8; b = rhs.B8(); return *this; } - inline bgr888_t& bgr888_t::operator=(const swap565_t& rhs) { rg = rhs.R8() | rhs.G8() <<8; b = rhs.B8(); return *this; } - inline bgr888_t& bgr888_t::operator=(const bgr666_t& rhs) { r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline bgr888_t& bgr888_t::operator=(const rgb888_t& rhs) { r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline bgr888_t& bgr888_t::operator=(const argb8888_t& rhs) { r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline bgr888_t& bgr888_t::operator=(const bgra8888_t& rhs) { r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline bgr888_t& bgr888_t::operator=(const grayscale_t& rhs){ r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - - inline bgra8888_t& bgra8888_t::operator=(const rgb332_t& rhs) { a = 255; r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline bgra8888_t& bgra8888_t::operator=(const rgb565_t& rhs) { a = 255; r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline bgra8888_t& bgra8888_t::operator=(const swap565_t& rhs) { a = 255; r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline bgra8888_t& bgra8888_t::operator=(const bgr666_t& rhs) { a = 255; r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline bgra8888_t& bgra8888_t::operator=(const rgb888_t& rhs) { a = 255; r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline bgra8888_t& bgra8888_t::operator=(const bgr888_t& rhs) { a = 255; r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline bgra8888_t& bgra8888_t::operator=(const grayscale_t& rhs){a = 255; r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline bgra8888_t& bgra8888_t::operator=(const argb8888_t& rhs){ a = rhs.A8(); r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - - inline argb8888_t& argb8888_t::operator=(const rgb332_t& rhs) { a = 255; r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline argb8888_t& argb8888_t::operator=(const rgb565_t& rhs) { a = 255; r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline argb8888_t& argb8888_t::operator=(const swap565_t& rhs) { a = 255; r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline argb8888_t& argb8888_t::operator=(const bgr666_t& rhs) { a = 255; r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline argb8888_t& argb8888_t::operator=(const rgb888_t& rhs) { a = 255; r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline argb8888_t& argb8888_t::operator=(const bgr888_t& rhs) { a = 255; r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline argb8888_t& argb8888_t::operator=(const grayscale_t& rhs){a = 255; r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - inline argb8888_t& argb8888_t::operator=(const bgra8888_t& rhs){ a = rhs.A8(); r = rhs.R8(); g = rhs.G8(); b = rhs.B8(); return *this; } - - inline grayscale_t& grayscale_t::operator=(const rgb332_t& rhs) { raw = (rhs.R8() + (rhs.G8()<<1) + rhs.B8()) >> 2; return *this; } - inline grayscale_t& grayscale_t::operator=(const rgb565_t& rhs) { raw = (rhs.R8() + (rhs.G8()<<1) + rhs.B8()) >> 2; return *this; } - inline grayscale_t& grayscale_t::operator=(const rgb888_t& rhs) { raw = (rhs.R8() + (rhs.G8()<<1) + rhs.B8()) >> 2; return *this; } - inline grayscale_t& grayscale_t::operator=(const argb8888_t& rhs) { raw = (rhs.R8() + (rhs.G8()<<1) + rhs.B8()) >> 2; return *this; } - inline grayscale_t& grayscale_t::operator=(const swap565_t& rhs) { raw = (rhs.R8() + (rhs.G8()<<1) + rhs.B8()) >> 2; return *this; } - inline grayscale_t& grayscale_t::operator=(const bgr666_t& rhs) { raw = (rhs.R8() + (rhs.G8()<<1) + rhs.B8()) >> 2; return *this; } - inline grayscale_t& grayscale_t::operator=(const bgr888_t& rhs) { raw = (rhs.R8() + (rhs.G8()<<1) + rhs.B8()) >> 2; return *this; } - - inline constexpr bool operator==(const rgb332_t& lhs, const rgb332_t& rhs) { return lhs.raw == rhs.raw; } - inline constexpr bool operator==(const rgb565_t& lhs, const rgb565_t& rhs) { return lhs.raw == rhs.raw; } - inline constexpr bool operator==(const swap565_t& lhs, const swap565_t& rhs) { return lhs.raw == rhs.raw; } - inline constexpr bool operator==(const bgr666_t& lhs, const bgr666_t& rhs) { return (*reinterpret_cast(&lhs) << 8) == (*reinterpret_cast(&rhs) << 8); } - inline constexpr bool operator==(const rgb888_t& lhs, const rgb888_t& rhs) { return (*reinterpret_cast(&lhs) << 8) == (*reinterpret_cast(&rhs) << 8); } - inline constexpr bool operator==(const bgr888_t& lhs, const bgr888_t& rhs) { return (*reinterpret_cast(&lhs) << 8) == (*reinterpret_cast(&rhs) << 8); } - inline constexpr bool operator==(const argb8888_t& lhs, const argb8888_t& rhs) { return lhs.raw == rhs.raw; } - inline constexpr bool operator==(const grayscale_t& lhs,const grayscale_t& rhs){ return lhs.raw == rhs.raw; } +#define LGFX_INLINE __attribute__((used)) __attribute__ ((always_inline)) inline + + template LGFX_INLINE uint32_t color_convert(uint32_t c) { return c; } + + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return (((((c >>13) & 7) << 3) + ((c >> 8) & 7)) << 2) + ((c >> 3) & 3); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return (((((c >>21) & 7) << 3) + ((c >>13) & 7)) << 2) + ((c >> 6) & 3); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return (((((c >>21) & 7) << 3) + ((c >>13) & 7)) << 2) + ((c >> 6) & 3); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return (((((c >> 5) & 7) << 3) + ( c & 7)) << 2) + ((c >>11) & 3); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return (((((c >> 3) & 7) << 3) + ((c >>11) & 7)) << 2) + ((c >>20) & 3); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return (((((c >> 5) & 7) << 3) + ((c >>13) & 7)) << 2) + ((c >>22) & 3); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return (((((c >>13) & 7) << 3) + ((c >>21) & 7)) << 2) + ((c >>30) & 3); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return ((c>>5)*0x49)>>1; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast8_t r = (c >> 5) & 0x07; r = (r << 2) + (r >> 1); uint_fast8_t g = (c >> 2) & 0x07; g = (g << 3) + g; uint_fast8_t b = c & 0x03; b = (((b << 2) + b) << 1) + (b >> 1); return (((r<<6)+g)<<5)+b; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return (((((c >>19) & 0x1F) << 6) + ((c >>10) & 0x3F)) << 5) + ((c >> 3) & 0x1F); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return (((((c >>19) & 0x1F) << 6) + ((c >>10) & 0x3F)) << 5) + ((c >> 3) & 0x1F); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return getSwap16(c); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return (((((c >> 1) & 0x1F) << 6) + ((c >> 8) & 0x3F)) << 5) + (c >> 17); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return (((((c >> 3) & 0x1F) << 6) + ((c >>10) & 0x3F)) << 5) + (c >> 19); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return (((((c >>11) & 0x1F) << 6) + ((c >>18) & 0x3F)) << 5) +((c >> 27) & 0x1F); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast8_t r = c >> 3; return ((c&0xFC) << 3) + (r | r << 11); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast8_t r = (c >> 5) & 0x07; r = (((r<<3)+r)<<2)+(r>>1); uint_fast8_t g = c & 0x1C; g = (g << 3) + g + (g >> 3); uint_fast8_t b = (c & 0x03); b = (b << 2) + b; b = (b << 4) + b; return (((r<<8)+g)<<8)+b; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast8_t r = (c >> 11) & 0x1F; r = (r << 3) + (r >> 2); uint_fast8_t g = (c >> 5) & 0x3F; g = (g << 2) + (g >> 4); uint_fast8_t b = c & 0x1F; b = (b << 3) + (b >> 2); return (((r<<8)+g)<<8)+b; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return (c << 8) >> 8; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast16_t g = (c & 7); uint_fast16_t b = (c >> 8) & 0x1F; b = (b << 3) + (b >> 2); uint_fast16_t r = (c >> 3) & 0x1F; r = (r << 3) + (r >> 2); return (((((((r << 3) + g) << 3) + (c >> 13)) << 2) + (g >> 1)) << 8) + b; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return getSwap24((c << 2) + ((c >> 4) & 0x030303)); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return getSwap24(c); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return ((c>>8) & 0xFF) << 16 | ((c>>16)&0xFF)<<8 | (c>>24); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return c*0x010101; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast8_t r = (c >> 5) & 0x07; r = (((r<<3)+r)<<2)+(r>>1); uint_fast8_t g = c & 0x1C; g = (g << 3) + g + (g >> 3); uint_fast8_t b = (c & 0x03); b = (b << 2) + b; b = (b << 4) + b; return (((((0xFF<<8)+r)<<8)+g)<<8)+b; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast8_t r = (c >> 11) & 0x1F; r = (r << 3) + (r >> 2); uint_fast8_t g = (c >> 5) & 0x3F; g = (g << 2) + (g >> 4); uint_fast8_t b = c & 0x1F; b = (b << 3) + (b >> 2); return (((((0xFF<<8)+r)<<8)+g)<<8)+b; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return c | (0xFF << 24); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast16_t g = (c & 7); uint_fast16_t b = (c >> 8) & 0x1F; b = (b << 3) + (b >> 2); uint_fast16_t r = (c >> 3) & 0x1F; r = (r << 3) + (r >> 2); return (((((((((0xFF << 8) + r) << 3) + g) << 3) + (c >> 13)) << 2) + (g >> 1)) << 8) + b; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { c = ((((c | 0x3FC0)<<8) + ((c>>8)&0x3F))<<8) + ((c>>16)&0x3F); return (c << 2) + ((c >> 4) & 0x030303); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return (c | 0xFF00)<<16 | (((c>>8)&0xFF))<<8 | ((c>>16)&0xFF); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return getSwap32(c); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return (c * 0x010101) | (0xFF<<24); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast8_t r = (c >> 5) & 0x07; r = (r << 2) + (r >> 1); uint_fast8_t g = (c >> 2) & 0x07; uint_fast8_t b = c & 0x03; b = (((b << 2) + b) << 1) + (b >> 1); return (((((g<<5)+b)<<5)+r)<<3)+g; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return getSwap16(c); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast8_t r = (c >> 19) & 0x1F; uint_fast8_t gh = (c >> 13) & 0x07; uint_fast8_t gl = (c >> 10) & 0x07; uint_fast8_t b = (c >> 3) & 0x1F; return (((((gl << 5) + b) << 5) + r) << 3) + gh; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast8_t r = (c >> 19) & 0x1F; uint_fast8_t gh = (c >> 13) & 0x07; uint_fast8_t gl = (c >> 10) & 0x07; uint_fast8_t b = (c >> 3) & 0x1F; return (((((gl << 5) + b) << 5) + r) << 3) + gh; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast8_t r = (c >> 1) & 0x1F; uint_fast8_t gh = (c >> 11) & 0x07; uint_fast8_t gl = (c >> 8) & 0x07; uint_fast8_t b = (c >> 17) & 0x1F; return (((((gl << 5) + b) << 5) + r) << 3) + gh; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast8_t r = (c >> 3) & 0x1F; uint_fast8_t gh = (c >> 13) & 0x07; uint_fast8_t gl = (c >> 10) & 0x07; uint_fast8_t b = (c >> 19) & 0x1F; return (((((gl << 5) + b) << 5) + r) << 3) + gh; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast8_t r = (c >> 11) & 0x1F; uint_fast8_t gh = (c >> 21) & 0x07; uint_fast8_t gl = (c >> 18) & 0x07; uint_fast8_t b = (c >> 27) & 0x1F; return (((((gl << 5) + b) << 5) + r) << 3) + gh; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast8_t rb = c >> 3; return ((((((c & 0x1C) << 3) + rb) << 5) + rb) << 3) + (c >> 5); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast8_t r = (c >> 5) & 0x07; r = (r << 3) + r; uint_fast8_t g = (c >> 2) & 0x07; g = (g << 3) + g; uint_fast8_t b = (c & 3) * 0x15; return (((b<<8)+g)<<8)+r; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast8_t r = (c >> 11) & 0x1F; r = (r << 1) + (r >> 4); uint_fast8_t g = (c >> 5) & 0x3F; uint_fast8_t b = c & 0x1F; b = (b << 1) + (b >> 4); return (((b<<8)+g)<<8)+r; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return ((c >> 2) & 0x3F) << 16 | ((c >> 10) & 0x3F) << 8 | ((c >> 18) & 0x3F); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return ((c >> 2) & 0x3F) << 16 | ((c >> 10) & 0x3F) << 8 | ((c >> 18) & 0x3F); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast16_t g = (c & 7); g = (g << 3) + (c >> 13); uint_fast16_t b = (c >> 8) & 0x1F; b = (b << 1) + (b >> 4); uint_fast16_t r = (c >> 3) & 0x1F; r = (r << 1) + (r >> 4); return (((b<<8)+g)<<8)+r; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return (c >> 2) & 0x3F3F3F; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return (c >> 10) & 0x3F3F3F; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return (c >> 2) * 0x010101; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast8_t r = (c >> 5) & 0x07; r = (((r<<3)+r)<<2)+(r>>1); uint_fast8_t g = c & 0x1C; g = (g << 3) + g + (g >> 3); uint_fast8_t b = (c & 0x03) * 0x55; return (((b<<8)+g)<<8)+r; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast8_t r = (c >> 11) & 0x1F; r = (r << 3) + (r >> 2); uint_fast8_t g = (c >> 5) & 0x3F; g = (g << 2) + (g >> 4); uint_fast8_t b = c & 0x1F; b = (b << 3) + (b >> 2); return (((b<<8)+g)<<8)+r; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return getSwap24(c); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return getSwap24(c); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast16_t g = (c & 7); uint_fast16_t b = (c >> 8) & 0x1F; b = (b << 3) + (b >> 2); uint_fast16_t r = (c >> 3) & 0x1F; r = (r << 3) + (r >> 2); return (((((((b << 3) + g) << 3) + (c >> 13)) << 2) + (g >> 1)) << 8) + r; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return (c << 2) + ((c >> 4) & 0x030303); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return c >> 8; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return ((c << 16) + c) + (c << 8); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast8_t r = (c>> 5)*0x49; uint_fast8_t g = c & 0x1C; g = (g << 3) + g + (g >> 3); uint_fast8_t b = (c & 0x03) * 0x55; return (((((b<<8)+g)<<9)+r)<<7)|0xFF; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast8_t r = (c >> 11) & 0x1F; r = (r << 3) + (r >> 2); uint_fast8_t g = (c >> 5) & 0x3F; g = (g << 2) + (g >> 4); uint_fast8_t b = c & 0x1F; b = (b << 3) + (b >> 2); return (((((b<<8)+g)<<8)+r)<<8)+0xFF; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return (((c << 8) + ((c >> 8) & 0xFF)) << 16) + ((uint16_t)(c >> 8) | 0xFF); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return getSwap32(c); } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast16_t g = (c & 7); uint_fast16_t b = (c >> 8) & 0x1F; b = (b << 3) + (b >> 2); uint_fast16_t r = (c >> 3) & 0x1F; r = (r << 3) + (r >> 2); return (((((((((b << 3) + g) << 3) + (c >> 13)) << 2) + (g >> 1)) << 8) + r) << 8) + 0xFF; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { c<<=2; return (c << 8) + ((c & 0xC0C0C0) << 2) + 0xFF; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return (c << 8) + 0xFF; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return (((c << 8) + c) << 16) + (c << 8) + 0xFF; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast16_t t = ((c>>5)*0x49); t += ((c>>2)&7)*0x92; t += (c&3) * 0xAA; return t >> 3; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast16_t g = ( c & 0x07E0); g |= g >> 6; uint_fast16_t rb = ((c>>11)+(c&0x1F))*0x21; return (rb+g)>>4; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast16_t g = ( c >> 8) & 0xFF; g = (g << 1) + (g >> 7); return (g + ((c>>16)&0xFF)+(c&0xFF))>>2; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast16_t g = ( c >> 8) & 0xFF; g = (g << 1) + (g >> 7); return (g + ((c>>16)&0xFF)+(c&0xFF))>>2; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast16_t rb = ((((c>>3)&0x1F) + ((c>>8)&0x1F)) * 0x21) >> 2; uint_fast16_t g = (c & 7); g = (((g << 3) + (c >> 13)) << 3) + g; return (rb+g) >> 2; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast16_t g = ((c >> 8) & 0x3F)*0x82; uint_fast16_t rb = ((c>>16) + (c&0x3F))*0x41; return (rb+g)>>6; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { uint_fast16_t g = ( c >> 8) & 0xFF; g = (g << 1) + (g >> 7); return (g + ((c>>16)&0xFF)+(c&0xFF))>>2; } + template<> LGFX_INLINE uint32_t color_convert(uint32_t c) { return color_convert(c>>8); } + +#undef LGFX_INLINE + + inline rgb332_t& rgb332_t ::operator=(const rgb565_t& c) { set(color_convert(c.get())); return *this; } + inline rgb332_t& rgb332_t ::operator=(const rgb888_t& c) { set(color_convert(c.get())); return *this; } + inline rgb332_t& rgb332_t ::operator=(const argb8888_t& c) { set(color_convert(c.get())); return *this; } + inline rgb332_t& rgb332_t ::operator=(const swap565_t& c) { set(color_convert(c.get())); return *this; } + inline rgb332_t& rgb332_t ::operator=(const bgr666_t& c) { set(color_convert(c.get())); return *this; } + inline rgb332_t& rgb332_t ::operator=(const bgr888_t& c) { set(color_convert(c.get())); return *this; } + inline rgb332_t& rgb332_t ::operator=(const bgra8888_t& c) { set(color_convert(c.get())); return *this; } + inline rgb332_t& rgb332_t ::operator=(const grayscale_t& c) { set(color_convert(c.get())); return *this; } + inline rgb565_t& rgb565_t ::operator=(const rgb332_t& c) { set(color_convert(c.get())); return *this; } + inline rgb565_t& rgb565_t ::operator=(const rgb888_t& c) { set(color_convert(c.get())); return *this; } + inline rgb565_t& rgb565_t ::operator=(const argb8888_t& c) { set(color_convert(c.get())); return *this; } + inline rgb565_t& rgb565_t ::operator=(const swap565_t& c) { set(getSwap16 (c.get())); return *this; } + inline rgb565_t& rgb565_t ::operator=(const bgr666_t& c) { set(color_convert(c.get())); return *this; } + inline rgb565_t& rgb565_t ::operator=(const bgr888_t& c) { set(color_convert(c.get())); return *this; } + inline rgb565_t& rgb565_t ::operator=(const bgra8888_t& c) { set(color_convert(c.get())); return *this; } + inline rgb565_t& rgb565_t ::operator=(const grayscale_t& c) { set(color_convert(c.get())); return *this; } + inline rgb888_t& rgb888_t ::operator=(const rgb332_t& c) { set(color_convert(c.get())); return *this; } + inline rgb888_t& rgb888_t ::operator=(const rgb565_t& c) { set(color_convert(c.get())); return *this; } + inline rgb888_t& rgb888_t ::operator=(const argb8888_t& c) { set(color_convert(c.get())); return *this; } + inline rgb888_t& rgb888_t ::operator=(const swap565_t& c) { set(color_convert(c.get())); return *this; } + inline rgb888_t& rgb888_t ::operator=(const bgr666_t& c) { set(color_convert(c.get())); return *this; } + inline rgb888_t& rgb888_t ::operator=(const bgr888_t& c) { set(getSwap24 (c.get())); return *this; } + inline rgb888_t& rgb888_t ::operator=(const bgra8888_t& c) { set(color_convert(c.get())); return *this; } + inline rgb888_t& rgb888_t ::operator=(const grayscale_t& c) { set(color_convert(c.get())); return *this; } + inline argb8888_t& argb8888_t ::operator=(const rgb332_t& c) { set(color_convert(c.get())); return *this; } + inline argb8888_t& argb8888_t ::operator=(const rgb565_t& c) { set(color_convert(c.get())); return *this; } + inline argb8888_t& argb8888_t ::operator=(const rgb888_t& c) { set(color_convert(c.get())); return *this; } + inline argb8888_t& argb8888_t ::operator=(const swap565_t& c) { set(color_convert(c.get())); return *this; } + inline argb8888_t& argb8888_t ::operator=(const bgr666_t& c) { set(color_convert(c.get())); return *this; } + inline argb8888_t& argb8888_t ::operator=(const bgr888_t& c) { set(color_convert(c.get())); return *this; } + inline argb8888_t& argb8888_t ::operator=(const bgra8888_t& c) { set(getSwap32 (c.get())); return *this; } + inline argb8888_t& argb8888_t ::operator=(const grayscale_t& c) { set(color_convert(c.get())); return *this; } + inline swap565_t& swap565_t ::operator=(const rgb332_t& c) { set(color_convert(c.get())); return *this; } + inline swap565_t& swap565_t ::operator=(const rgb565_t& c) { set(getSwap16( c.get())); return *this; } + inline swap565_t& swap565_t ::operator=(const rgb888_t& c) { set(color_convert(c.get())); return *this; } + inline swap565_t& swap565_t ::operator=(const argb8888_t& c) { set(color_convert(c.get())); return *this; } + inline swap565_t& swap565_t ::operator=(const bgr666_t& c) { set(color_convert(c.get())); return *this; } + inline swap565_t& swap565_t ::operator=(const bgr888_t& c) { set(color_convert(c.get())); return *this; } + inline swap565_t& swap565_t ::operator=(const bgra8888_t& c) { set(color_convert(c.get())); return *this; } + inline swap565_t& swap565_t ::operator=(const grayscale_t& c) { set(color_convert(c.get())); return *this; } + inline bgr666_t& bgr666_t ::operator=(const rgb332_t& c) { set(color_convert(c.get())); return *this; } + inline bgr666_t& bgr666_t ::operator=(const rgb565_t& c) { set(color_convert(c.get())); return *this; } + inline bgr666_t& bgr666_t ::operator=(const rgb888_t& c) { set(color_convert(c.get())); return *this; } + inline bgr666_t& bgr666_t ::operator=(const argb8888_t& c) { set(color_convert(c.get())); return *this; } + inline bgr666_t& bgr666_t ::operator=(const swap565_t& c) { set(color_convert(c.get())); return *this; } + inline bgr666_t& bgr666_t ::operator=(const bgr888_t& c) { set(color_convert(c.get())); return *this; } + inline bgr666_t& bgr666_t ::operator=(const bgra8888_t& c) { set(color_convert(c.get())); return *this; } + inline bgr666_t& bgr666_t ::operator=(const grayscale_t& c) { set(color_convert(c.get())); return *this; } + inline bgr888_t& bgr888_t ::operator=(const rgb332_t& c) { set(color_convert(c.get())); return *this; } + inline bgr888_t& bgr888_t ::operator=(const rgb565_t& c) { set(color_convert(c.get())); return *this; } + inline bgr888_t& bgr888_t ::operator=(const rgb888_t& c) { set(getSwap24 (c.get())); return *this; } + inline bgr888_t& bgr888_t ::operator=(const argb8888_t& c) { set(color_convert(c.get())); return *this; } + inline bgr888_t& bgr888_t ::operator=(const swap565_t& c) { set(color_convert(c.get())); return *this; } + inline bgr888_t& bgr888_t ::operator=(const bgr666_t& c) { set(color_convert(c.get())); return *this; } + inline bgr888_t& bgr888_t ::operator=(const bgra8888_t& c) { set(color_convert(c.get())); return *this; } + inline bgr888_t& bgr888_t ::operator=(const grayscale_t& c) { set(color_convert(c.get())); return *this; } + inline bgra8888_t& bgra8888_t ::operator=(const rgb332_t& c) { set(color_convert(c.get())); return *this; } + inline bgra8888_t& bgra8888_t ::operator=(const rgb565_t& c) { set(color_convert(c.get())); return *this; } + inline bgra8888_t& bgra8888_t ::operator=(const rgb888_t& c) { set(color_convert(c.get())); return *this; } + inline bgra8888_t& bgra8888_t ::operator=(const argb8888_t& c) { set(getSwap32 (c.get())); return *this; } + inline bgra8888_t& bgra8888_t ::operator=(const swap565_t& c) { set(color_convert(c.get())); return *this; } + inline bgra8888_t& bgra8888_t ::operator=(const bgr666_t& c) { set(color_convert(c.get())); return *this; } + inline bgra8888_t& bgra8888_t ::operator=(const bgr888_t& c) { set(color_convert(c.get())); return *this; } + inline bgra8888_t& bgra8888_t ::operator=(const grayscale_t& c) { set(color_convert(c.get())); return *this; } + inline grayscale_t& grayscale_t::operator=(const rgb332_t& c) { set(color_convert(c.get())); return *this; } + inline grayscale_t& grayscale_t::operator=(const rgb565_t& c) { set(color_convert(c.get())); return *this; } + inline grayscale_t& grayscale_t::operator=(const rgb888_t& c) { set(color_convert(c.get())); return *this; } + inline grayscale_t& grayscale_t::operator=(const argb8888_t& c) { set(color_convert(c.get())); return *this; } + inline grayscale_t& grayscale_t::operator=(const swap565_t& c) { set(color_convert(c.get())); return *this; } + inline grayscale_t& grayscale_t::operator=(const bgr666_t& c) { set(color_convert(c.get())); return *this; } + inline grayscale_t& grayscale_t::operator=(const bgr888_t& c) { set(color_convert(c.get())); return *this; } + inline grayscale_t& grayscale_t::operator=(const bgra8888_t& c) { set(color_convert(c.get())); return *this; } + + inline bool operator==(const rgb332_t& lhs, const rgb332_t& rhs) { return pgm_read_byte (&lhs) == pgm_read_byte (&rhs); } + inline bool operator==(const rgb565_t& lhs, const rgb565_t& rhs) { return pgm_read_word (&lhs) == pgm_read_word (&rhs); } + inline bool operator==(const swap565_t& lhs, const swap565_t& rhs) { return pgm_read_word (&lhs) == pgm_read_word (&rhs); } + inline bool operator==(const bgr666_t& lhs, const bgr666_t& rhs) { return pgm_read_3byte_unaligned(&lhs) == pgm_read_3byte_unaligned(&rhs); } + inline bool operator==(const rgb888_t& lhs, const rgb888_t& rhs) { return pgm_read_3byte_unaligned(&lhs) == pgm_read_3byte_unaligned(&rhs); } + inline bool operator==(const bgr888_t& lhs, const bgr888_t& rhs) { return pgm_read_3byte_unaligned(&lhs) == pgm_read_3byte_unaligned(&rhs); } + inline bool operator==(const argb8888_t& lhs, const argb8888_t& rhs) { return pgm_read_dword (&lhs) == pgm_read_dword (&rhs); } + inline bool operator==(const grayscale_t& lhs, const grayscale_t& rhs) { return pgm_read_byte (&lhs) == pgm_read_byte (&rhs); } // for compare transparent color. - inline constexpr bool operator==(const rgb332_t& lhs, std::uint32_t rhs) { return *reinterpret_cast(&lhs) == rhs; } - inline constexpr bool operator==(const rgb565_t& lhs, std::uint32_t rhs) { return *reinterpret_cast(&lhs) == rhs; } - inline constexpr bool operator==(const swap565_t& lhs, std::uint32_t rhs) { return *reinterpret_cast(&lhs) == rhs; } - inline bool operator==(const bgr666_t& lhs, std::uint32_t rhs) { return (pgm_read_dword_unaligned(&lhs) << 8) >> 8 == rhs; } - inline bool operator==(const rgb888_t& lhs, std::uint32_t rhs) { return (pgm_read_dword_unaligned(&lhs) << 8) >> 8 == rhs; } - inline bool operator==(const bgr888_t& lhs, std::uint32_t rhs) { return (pgm_read_dword_unaligned(&lhs) << 8) >> 8 == rhs; } - inline constexpr bool operator==(const argb8888_t& lhs, std::uint32_t rhs) { return *reinterpret_cast(&lhs) == rhs; } - inline constexpr bool operator==(const bgra8888_t& lhs, std::uint32_t rhs) { return *reinterpret_cast(&lhs) == rhs; } - inline constexpr bool operator==(const grayscale_t& lhs,std::uint32_t rhs) { return *reinterpret_cast(&lhs) == rhs; } + inline bool operator==(const rgb332_t& lhs, uint32_t rhs) { return pgm_read_byte (&lhs) == rhs; } + inline bool operator==(const rgb565_t& lhs, uint32_t rhs) { return pgm_read_word (&lhs) == rhs; } + inline bool operator==(const swap565_t& lhs, uint32_t rhs) { return pgm_read_word (&lhs) == rhs; } + inline bool operator==(const bgr666_t& lhs, uint32_t rhs) { return pgm_read_3byte_unaligned(&lhs) == rhs; } + inline bool operator==(const rgb888_t& lhs, uint32_t rhs) { return pgm_read_3byte_unaligned(&lhs) == rhs; } + inline bool operator==(const bgr888_t& lhs, uint32_t rhs) { return pgm_read_3byte_unaligned(&lhs) == rhs; } + inline bool operator==(const argb8888_t& lhs, uint32_t rhs) { return pgm_read_dword (&lhs) == rhs; } + inline bool operator==(const bgra8888_t& lhs, uint32_t rhs) { return pgm_read_dword (&lhs) == rhs; } + inline bool operator==(const grayscale_t& lhs, uint32_t rhs) { return pgm_read_byte (&lhs) == rhs; } - inline constexpr bool operator==(const raw_color_t& lhs, const raw_color_t& rhs) { return *reinterpret_cast(&lhs) == *reinterpret_cast(&rhs); } - inline constexpr bool operator!=(const raw_color_t& lhs, const raw_color_t& rhs) { return *reinterpret_cast(&lhs) != *reinterpret_cast(&rhs); } + inline constexpr bool operator==(const raw_color_t& lhs, const raw_color_t& rhs) { return *reinterpret_cast(&lhs) == *reinterpret_cast(&rhs); } + inline constexpr bool operator!=(const raw_color_t& lhs, const raw_color_t& rhs) { return *reinterpret_cast(&lhs) != *reinterpret_cast(&rhs); } struct get_depth_impl { @@ -645,61 +692,61 @@ namespace lgfx template class get_depth : public decltype(get_depth_impl::check(nullptr)) {}; template - static auto get_fp_convert_src(color_depth_t dst_depth, bool has_palette) -> std::uint32_t(*)(std::uint32_t) + static auto get_fp_convert_src(color_depth_t dst_depth, bool has_palette) -> uint32_t(*)(uint32_t) { - if (std::is_same::value || std::is_same::value) { + if (std::is_same::value || std::is_same::value) { switch (dst_depth) { - case argb8888_4Byte: return convert_rgb332_to_bgra8888; - case rgb888_3Byte: return convert_rgb332_to_bgr888; - case rgb666_3Byte: return convert_rgb332_to_bgr666; - case rgb565_2Byte: return convert_rgb332_to_swap565; - case rgb332_1Byte: return has_palette - ? convert_uint32_to_palette8 - : no_convert; + case argb8888_4Byte: return color_convert; + case rgb888_3Byte : return color_convert; + case rgb666_3Byte : return color_convert; + case rgb565_2Byte : return color_convert; + case rgb332_1Byte : return has_palette + ? convert_uint32_to_palette8 + : no_convert; default: break; } - } else if (std::is_same::value || std::is_same::value) { + } else if (std::is_same::value || std::is_same::value) { switch (dst_depth) { - case argb8888_4Byte: return convert_rgb888_to_bgra8888; - case rgb888_3Byte: return convert_rgb888_to_bgr888; - case rgb666_3Byte: return convert_rgb888_to_bgr666; - case rgb565_2Byte: return convert_rgb888_to_swap565; - case rgb332_1Byte: return has_palette - ? convert_uint32_to_palette8 - : convert_rgb888_to_rgb332; + case argb8888_4Byte: return color_convert; + case rgb888_3Byte : return getSwap24; + case rgb666_3Byte : return color_convert; + case rgb565_2Byte : return color_convert; + case rgb332_1Byte : return has_palette + ? convert_uint32_to_palette8 + : color_convert; default: break; } - } else if (std::is_same::value) { + } else if (std::is_same::value) { switch (dst_depth) { - case argb8888_4Byte: return convert_bgr888_to_bgra8888; - case rgb888_3Byte: return no_convert; - case rgb666_3Byte: return convert_bgr888_to_bgr666; - case rgb565_2Byte: return convert_bgr888_to_swap565; - case rgb332_1Byte: return has_palette - ? convert_uint32_to_palette8 - : convert_bgr888_to_rgb332; + case argb8888_4Byte: return getSwap32; + case rgb888_3Byte : return color_convert; + case rgb666_3Byte : return color_convert; + case rgb565_2Byte : return color_convert; + case rgb332_1Byte : return has_palette + ? convert_uint32_to_palette8 + : color_convert; default: break; } - } else if (std::is_same::value) { + } else if (std::is_same::value) { switch (dst_depth) { - case argb8888_4Byte: return convert_argb8888_to_bgra8888; - case rgb888_3Byte: return convert_rgb888_to_bgr888; - case rgb666_3Byte: return convert_rgb888_to_bgr666; - case rgb565_2Byte: return convert_rgb888_to_swap565; - case rgb332_1Byte: return has_palette - ? convert_uint32_to_palette8 - : convert_rgb888_to_rgb332; + case argb8888_4Byte: return color_convert; + case rgb888_3Byte : return no_convert; + case rgb666_3Byte : return color_convert; + case rgb565_2Byte : return color_convert; + case rgb332_1Byte : return has_palette + ? convert_uint32_to_palette8 + : color_convert; default: break; } - } else { // if (std::is_same::value || std::is_same::value || std::is_same::value) + } else { // if (std::is_same::value || std::is_same::value || std::is_same::value) switch (dst_depth) { - case argb8888_4Byte: return convert_rgb565_to_bgra8888; - case rgb888_3Byte: return convert_rgb565_to_bgr888; - case rgb666_3Byte: return convert_rgb565_to_bgr666; - case rgb565_2Byte: return convert_rgb565_to_swap565; - case rgb332_1Byte: return has_palette - ? convert_uint32_to_palette8 - : convert_rgb565_to_rgb332; + case argb8888_4Byte: return color_convert; + case rgb888_3Byte : return color_convert; + case rgb666_3Byte : return color_convert; + case rgb565_2Byte : return getSwap16; + case rgb332_1Byte : return has_palette + ? convert_uint32_to_palette8 + : color_convert; default: break; } } @@ -715,19 +762,22 @@ namespace lgfx struct color_conv_t { - std::uint32_t (*convert_argb8888)(std::uint32_t)=convert_rgb888_to_swap565; - std::uint32_t (*convert_bgr888)(std::uint32_t) = convert_bgr888_to_swap565; - std::uint32_t (*convert_rgb888)(std::uint32_t) = convert_rgb888_to_swap565; - std::uint32_t (*convert_rgb565)(std::uint32_t) = convert_rgb565_to_swap565; - std::uint32_t (*convert_rgb332)(std::uint32_t) = convert_rgb332_to_swap565; - color_depth_t depth = rgb565_2Byte; - std::uint32_t colormask = 0xFFFF; - std::uint8_t bytes = 2; - std::uint8_t bits = 16; - std::uint8_t x_mask = 0; - - color_conv_t() = default; + uint32_t (*convert_argb8888)(uint32_t); + uint32_t (*convert_bgr888)(uint32_t); + uint32_t (*convert_rgb888)(uint32_t); + uint32_t (*convert_rgb565)(uint32_t); + uint32_t (*convert_rgb332)(uint32_t); + color_depth_t depth; + uint32_t colormask; + uint8_t bytes; + uint8_t bits; + uint8_t x_mask; + color_conv_t(const color_conv_t&) = default; + color_conv_t() + { + setColorDepth(color_depth_t::rgb565_2Byte, false); + } void setColorDepth(color_depth_t depth, bool has_palette = false) { @@ -755,54 +805,54 @@ namespace lgfx colormask = (1 << bits) - 1; convert_argb8888 = get_fp_convert_src(depth, has_palette); - convert_rgb888 = get_fp_convert_src(depth, has_palette); - convert_rgb565 = get_fp_convert_src(depth, has_palette); - convert_rgb332 = get_fp_convert_src(depth, has_palette); - convert_bgr888 = get_fp_convert_src(depth, has_palette); + convert_rgb888 = get_fp_convert_src(depth, has_palette); + convert_rgb565 = get_fp_convert_src(depth, has_palette); + convert_rgb332 = get_fp_convert_src(depth, has_palette); + convert_bgr888 = get_fp_convert_src(depth, has_palette); } #define TYPECHECK(dType) template < typename T, typename std::enable_if < (sizeof(T) == sizeof(dType)) && (std::is_signed::value == std::is_signed::value), std::nullptr_t >::type=nullptr > __attribute__ ((always_inline)) inline - TYPECHECK(std::int8_t ) std::uint32_t convert(T c) { return convert_rgb332(c); } - TYPECHECK(std::uint8_t ) std::uint32_t convert(T c) { return convert_rgb332(c); } - TYPECHECK(std::uint16_t) std::uint32_t convert(T c) { return convert_rgb565(c); } - TYPECHECK(std::int16_t ) std::uint32_t convert(T c) { return convert_rgb565(c); } - TYPECHECK(std::int32_t ) std::uint32_t convert(T c) { return convert_rgb565(c); } - TYPECHECK(std::uint32_t) std::uint32_t convert(T c) { return convert_rgb888(c); } - - __attribute__ ((always_inline)) inline std::uint32_t convert(const argb8888_t& c) { return convert_argb8888(c.raw); } - __attribute__ ((always_inline)) inline std::uint32_t convert(const rgb888_t& c) { return convert_rgb888(*(std::uint32_t*)&c); } - __attribute__ ((always_inline)) inline std::uint32_t convert(const rgb565_t& c) { return convert_rgb565(c.raw); } - __attribute__ ((always_inline)) inline std::uint32_t convert(const rgb332_t& c) { return convert_rgb332(c.raw); } - __attribute__ ((always_inline)) inline std::uint32_t convert(const bgr888_t& c) { return convert_bgr888(*(std::uint32_t*)&c); } + TYPECHECK(int8_t ) uint32_t convert(T c) { return convert_rgb332(c); } + TYPECHECK(uint8_t ) uint32_t convert(T c) { return convert_rgb332(c); } + TYPECHECK(uint16_t) uint32_t convert(T c) { return convert_rgb565(c); } + TYPECHECK(int16_t ) uint32_t convert(T c) { return convert_rgb565(c); } + TYPECHECK(int32_t ) uint32_t convert(T c) { return convert_rgb565(c); } + TYPECHECK(uint32_t) uint32_t convert(T c) { return convert_rgb888(c); } + + __attribute__ ((always_inline)) inline uint32_t convert(const rgb332_t& c) { return convert_rgb332( c.get()); } + __attribute__ ((always_inline)) inline uint32_t convert(const rgb565_t& c) { return convert_rgb565( c.get()); } + __attribute__ ((always_inline)) inline uint32_t convert(const rgb888_t& c) { return convert_rgb888( c.get()); } + __attribute__ ((always_inline)) inline uint32_t convert(const argb8888_t& c) { return convert_argb8888(c.get()); } + __attribute__ ((always_inline)) inline uint32_t convert(const bgr888_t& c) { return convert_bgr888( c.get()); } }; - TYPECHECK(std::int8_t ) constexpr std::uint32_t convert_to_rgb888(T c) { return convert_rgb332_to_rgb888(c); } - TYPECHECK(std::uint8_t ) constexpr std::uint32_t convert_to_rgb888(T c) { return convert_rgb332_to_rgb888(c); } - TYPECHECK(std::uint16_t) constexpr std::uint32_t convert_to_rgb888(T c) { return convert_rgb565_to_rgb888(c); } - TYPECHECK(std::int16_t ) constexpr std::uint32_t convert_to_rgb888(T c) { return convert_rgb565_to_rgb888(c); } - TYPECHECK(std::int32_t ) constexpr std::uint32_t convert_to_rgb888(T c) { return convert_rgb565_to_rgb888(c); } - TYPECHECK(std::uint32_t) constexpr std::uint32_t convert_to_rgb888(T c) { return c & 0xFFFFFF; } - __attribute__ ((always_inline)) inline constexpr std::uint32_t convert_to_rgb888(const argb8888_t& c) { return c.R8()<<16|c.G8()<<8|c.B8(); } - __attribute__ ((always_inline)) inline constexpr std::uint32_t convert_to_rgb888(const rgb888_t& c) { return c.R8()<<16|c.G8()<<8|c.B8(); } - __attribute__ ((always_inline)) inline constexpr std::uint32_t convert_to_rgb888(const rgb565_t& c) { return c.R8()<<16|c.G8()<<8|c.B8(); } - __attribute__ ((always_inline)) inline constexpr std::uint32_t convert_to_rgb888(const rgb332_t& c) { return c.R8()<<16|c.G8()<<8|c.B8(); } - __attribute__ ((always_inline)) inline constexpr std::uint32_t convert_to_rgb888(const bgr888_t& c) { return c.R8()<<16|c.G8()<<8|c.B8(); } - __attribute__ ((always_inline)) inline constexpr std::uint32_t convert_to_rgb888(const bgr666_t& c) { return c.R8()<<16|c.G8()<<8|c.B8(); } - __attribute__ ((always_inline)) inline constexpr std::uint32_t convert_to_rgb888(const swap565_t& c) { return c.R8()<<16|c.G8()<<8|c.B8(); } - - TYPECHECK(std::int8_t ) constexpr std::uint32_t convert_to_bgr888(T c) { return convert_rgb332_to_bgr888(c); } - TYPECHECK(std::uint8_t ) constexpr std::uint32_t convert_to_bgr888(T c) { return convert_rgb332_to_bgr888(c); } - TYPECHECK(std::uint16_t) constexpr std::uint32_t convert_to_bgr888(T c) { return convert_rgb565_to_bgr888(c); } - TYPECHECK(std::int16_t ) constexpr std::uint32_t convert_to_bgr888(T c) { return convert_rgb565_to_bgr888(c); } - TYPECHECK(std::int32_t ) constexpr std::uint32_t convert_to_bgr888(T c) { return convert_rgb565_to_bgr888(c); } - TYPECHECK(std::uint32_t) constexpr std::uint32_t convert_to_bgr888(T c) { return convert_rgb888_to_bgr888(c); } - __attribute__ ((always_inline)) inline constexpr std::uint32_t convert_to_bgr888(const argb8888_t& c) { return c.B8()<<16|c.G8()<<8|c.R8(); } - __attribute__ ((always_inline)) inline constexpr std::uint32_t convert_to_bgr888(const rgb888_t& c) { return c.B8()<<16|c.G8()<<8|c.R8(); } - __attribute__ ((always_inline)) inline constexpr std::uint32_t convert_to_bgr888(const rgb565_t& c) { return c.B8()<<16|c.G8()<<8|c.R8(); } - __attribute__ ((always_inline)) inline constexpr std::uint32_t convert_to_bgr888(const rgb332_t& c) { return c.B8()<<16|c.G8()<<8|c.R8(); } - __attribute__ ((always_inline)) inline constexpr std::uint32_t convert_to_bgr888(const bgr888_t& c) { return c.B8()<<16|c.G8()<<8|c.R8(); } - __attribute__ ((always_inline)) inline constexpr std::uint32_t convert_to_bgr888(const bgr666_t& c) { return c.B8()<<16|c.G8()<<8|c.R8(); } - __attribute__ ((always_inline)) inline constexpr std::uint32_t convert_to_bgr888(const swap565_t& c) { return c.B8()<<16|c.G8()<<8|c.R8(); } + TYPECHECK(int8_t ) uint32_t convert_to_rgb888(T c) { return color_convert(c); } + TYPECHECK(uint8_t ) uint32_t convert_to_rgb888(T c) { return color_convert(c); } + TYPECHECK(uint16_t) uint32_t convert_to_rgb888(T c) { return color_convert(c); } + TYPECHECK(int16_t ) uint32_t convert_to_rgb888(T c) { return color_convert(c); } + TYPECHECK(int32_t ) uint32_t convert_to_rgb888(T c) { return color_convert(c); } + TYPECHECK(uint32_t) uint32_t convert_to_rgb888(T c) { return c & 0xFFFFFF; } + __attribute__ ((always_inline)) inline uint32_t convert_to_rgb888(const argb8888_t& c) { return color_convert(c.get()); } // c.R8()<<16|c.G8()<<8|c.B8(); } + __attribute__ ((always_inline)) inline uint32_t convert_to_rgb888(const rgb888_t& c) { return c.get(); } + __attribute__ ((always_inline)) inline uint32_t convert_to_rgb888(const rgb565_t& c) { return color_convert(c.get()); } // c.R8()<<16|c.G8()<<8|c.B8(); } + __attribute__ ((always_inline)) inline uint32_t convert_to_rgb888(const rgb332_t& c) { return color_convert(c.get()); } // c.R8()<<16|c.G8()<<8|c.B8(); } + __attribute__ ((always_inline)) inline uint32_t convert_to_rgb888(const bgr888_t& c) { return getSwap24(c.get()); } + __attribute__ ((always_inline)) inline uint32_t convert_to_rgb888(const bgr666_t& c) { return color_convert(c.get()); } // c.R8()<<16|c.G8()<<8|c.B8(); } + __attribute__ ((always_inline)) inline uint32_t convert_to_rgb888(const swap565_t& c) { return color_convert(c.get()); } // c.R8()<<16|c.G8()<<8|c.B8(); } + + TYPECHECK(int8_t ) uint32_t convert_to_bgr888(T c) { return color_convert(c); } + TYPECHECK(uint8_t ) uint32_t convert_to_bgr888(T c) { return color_convert(c); } + TYPECHECK(uint16_t) uint32_t convert_to_bgr888(T c) { return color_convert(c); } + TYPECHECK(int16_t ) uint32_t convert_to_bgr888(T c) { return color_convert(c); } + TYPECHECK(int32_t ) uint32_t convert_to_bgr888(T c) { return color_convert(c); } + TYPECHECK(uint32_t) uint32_t convert_to_bgr888(T c) { return getSwap24(c); } + __attribute__ ((always_inline)) inline uint32_t convert_to_bgr888(const argb8888_t& c) { return color_convert(c.get()); } // return c.B8()<<16|c.G8()<<8|c.R8(); } + __attribute__ ((always_inline)) inline uint32_t convert_to_bgr888(const rgb888_t& c) { return color_convert(c.get()); } // return c.B8()<<16|c.G8()<<8|c.R8(); } + __attribute__ ((always_inline)) inline uint32_t convert_to_bgr888(const rgb565_t& c) { return color_convert(c.get()); } // return c.B8()<<16|c.G8()<<8|c.R8(); } + __attribute__ ((always_inline)) inline uint32_t convert_to_bgr888(const rgb332_t& c) { return color_convert(c.get()); } // return c.B8()<<16|c.G8()<<8|c.R8(); } + __attribute__ ((always_inline)) inline uint32_t convert_to_bgr888(const bgr888_t& c) { return c.get(); } + __attribute__ ((always_inline)) inline uint32_t convert_to_bgr888(const bgr666_t& c) { return color_convert(c.get()); } // return c.B8()<<16|c.G8()<<8|c.R8(); } + __attribute__ ((always_inline)) inline uint32_t convert_to_bgr888(const swap565_t& c) { return color_convert(c.get()); } // return c.B8()<<16|c.G8()<<8|c.R8(); } #undef TYPECHECK @@ -811,34 +861,36 @@ namespace lgfx struct effect_fill_alpha { effect_fill_alpha(argb8888_t src) - : _inv { (std::uint_fast16_t)(256 - src.A8()) } - , _r8a { (std::uint_fast16_t)(src.R8() * (1 + src.A8())) } - , _g8a { (std::uint_fast16_t)(src.G8() * (1 + src.A8())) } - , _b8a { (std::uint_fast16_t)(src.B8() * (1 + src.A8())) } + : _inv { (uint_fast16_t)(256 - src.A8()) } + , _r8a { (uint_fast16_t)(src.R8() * (1 + src.A8())) } + , _g8a { (uint_fast16_t)(src.G8() * (1 + src.A8())) } + , _b8a { (uint_fast16_t)(src.B8() * (1 + src.A8())) } {} void set(argb8888_t src) { - _inv = (std::uint_fast16_t)(256 - src.A8()); - _r8a = (std::uint_fast16_t)(src.R8() * (1 + src.A8())); - _g8a = (std::uint_fast16_t)(src.G8() * (1 + src.A8())); - _b8a = (std::uint_fast16_t)(src.B8() * (1 + src.A8())); + _inv = (uint_fast16_t)(256 - src.A8()); + _r8a = (uint_fast16_t)(src.R8() * (1 + src.A8())); + _g8a = (uint_fast16_t)(src.G8() * (1 + src.A8())); + _b8a = (uint_fast16_t)(src.B8() * (1 + src.A8())); } template - void operator() (std::int32_t x, std::int32_t y, TDstColor& dst) + void operator() (int32_t x, int32_t y, TDstColor& dst) { + (void)x; (void)y; dst.set((_r8a + dst.R8() * _inv) >> 8 ,(_g8a + dst.G8() * _inv) >> 8 ,(_b8a + dst.B8() * _inv) >> 8 ); } template - void operator() (std::int32_t x, std::int32_t y, TDstColor& dst, TSrcColor& src) + void operator() (int32_t x, int32_t y, TDstColor& dst, TSrcColor& src) { - std::uint_fast16_t a8 = 1 + src.A8(); - std::uint_fast16_t inv = 257 - a8; - std::uint_fast16_t r8a = a8 * src.R8(); - std::uint_fast16_t g8a = a8 * src.G8(); - std::uint_fast16_t b8a = a8 * src.B8(); + (void)x; (void)y; + uint_fast16_t a8 = 1 + src.A8(); + uint_fast16_t inv = 257 - a8; + uint_fast16_t r8a = a8 * src.R8(); + uint_fast16_t g8a = a8 * src.G8(); + uint_fast16_t b8a = a8 * src.B8(); dst.set((r8a + dst.R8() * inv) >> 8 ,(g8a + dst.G8() * inv) >> 8 @@ -846,10 +898,10 @@ namespace lgfx ); } private: - std::uint_fast16_t _inv; - std::uint_fast16_t _r8a; - std::uint_fast16_t _g8a; - std::uint_fast16_t _b8a; + uint_fast16_t _inv; + uint_fast16_t _r8a; + uint_fast16_t _g8a; + uint_fast16_t _b8a; }; //---------------------------------------------------------------------------- diff --git a/src/lgfx/v1/misc/enum.hpp b/src/lgfx/v1/misc/enum.hpp index a2801cf..a1544ab 100644 --- a/src/lgfx/v1/misc/enum.hpp +++ b/src/lgfx/v1/misc/enum.hpp @@ -17,7 +17,7 @@ Original Source: /----------------------------------------------------------------------------*/ #pragma once -#include +#include namespace lgfx { @@ -116,7 +116,7 @@ namespace lgfx namespace textdatum { - enum textdatum_t : std::uint8_t + enum textdatum_t : uint8_t // 0:left 1:centre 2:right // 0:top 4:middle 8:bottom 16:baseline { top_left = 0 // Top left (default) @@ -204,7 +204,7 @@ namespace lgfx //---------------------------------------------------------------------------- - enum color_depth_t : std::uint16_t + enum color_depth_t : uint16_t { bit_mask = 0x00FF , /// ビット数取得用マスク値 (下位1Byteはビット数表現専用とする。変更しないこと) has_palette = 0x0800 , /// パレット値として扱う diff --git a/src/lgfx/v1/misc/pixelcopy.hpp b/src/lgfx/v1/misc/pixelcopy.hpp index e1dc2ac..e38a74e 100644 --- a/src/lgfx/v1/misc/pixelcopy.hpp +++ b/src/lgfx/v1/misc/pixelcopy.hpp @@ -17,7 +17,7 @@ Original Source: /----------------------------------------------------------------------------*/ #pragma once -#include +#include #include "colortype.hpp" @@ -29,42 +29,42 @@ namespace lgfx struct pixelcopy_t { - static constexpr std::uint32_t FP_SCALE = 16; - static constexpr std::uint32_t NON_TRANSP = 1 << 24; + static constexpr uint32_t FP_SCALE = 16; + static constexpr uint32_t NON_TRANSP = 1 << 24; union { - std::uint32_t positions[4] = {0}; + uint32_t positions[4] = {0}; struct { - std::uint32_t src_x32; - std::uint32_t src_y32; - std::uint32_t src_xe32; - std::uint32_t src_ye32; + uint32_t src_x32; + uint32_t src_y32; + uint32_t src_xe32; + uint32_t src_ye32; }; struct { - std::uint16_t src_x_lo; - std:: int16_t src_x; - std::uint16_t src_y_lo; - std:: int16_t src_y; - std::uint16_t src_xe_lo; - std:: int16_t src_xe; - std::uint16_t src_ye_lo; - std:: int16_t src_ye; + uint16_t src_x_lo; + int16_t src_x; + uint16_t src_y_lo; + int16_t src_y; + uint16_t src_xe_lo; + int16_t src_xe; + uint16_t src_ye_lo; + int16_t src_ye; }; }; - std::uint32_t src_x32_add = 1 << FP_SCALE; - std::uint32_t src_y32_add = 0; - std::uint32_t src_bitwidth = 0; - std::uint32_t src_width = 0; - std::uint32_t src_height = 0; - std::uint32_t transp = NON_TRANSP; + uint32_t src_x32_add = 1 << FP_SCALE; + uint32_t src_y32_add = 0; + uint32_t src_bitwidth = 0; + uint32_t src_width = 0; + uint32_t src_height = 0; + uint32_t transp = NON_TRANSP; union { color_depth_t src_depth = rgb332_1Byte; struct { - std::uint8_t src_bits; - std::uint8_t src_attrib; + uint8_t src_bits; + uint8_t src_attrib; }; }; union @@ -72,16 +72,16 @@ namespace lgfx color_depth_t dst_depth = rgb332_1Byte; struct { - std::uint8_t dst_bits; - std::uint8_t dst_attrib; + uint8_t dst_bits; + uint8_t dst_attrib; }; }; const void* src_data = nullptr; const void* palette = nullptr; - std::uint32_t (*fp_copy)(void*, std::uint32_t, std::uint32_t, pixelcopy_t*) = nullptr; - std::uint32_t (*fp_skip)( std::uint32_t, std::uint32_t, pixelcopy_t*) = nullptr; - std::uint8_t src_mask = ~0; - std::uint8_t dst_mask = ~0; + uint32_t (*fp_copy)(void*, uint32_t, uint32_t, pixelcopy_t*) = nullptr; + uint32_t (*fp_skip)( uint32_t, uint32_t, pixelcopy_t*) = nullptr; + uint8_t src_mask = ~0; + uint8_t dst_mask = ~0; bool no_convert = false; pixelcopy_t(void) = default; @@ -91,7 +91,7 @@ namespace lgfx , color_depth_t src_depth , bool dst_palette = false , const void* src_palette = nullptr - , std::uint32_t src_transp = NON_TRANSP + , uint32_t src_transp = NON_TRANSP ) : transp ( src_transp ) /* @@ -139,10 +139,10 @@ namespace lgfx } template - static auto get_fp_copy_rgb_affine(color_depth_t dst_depth) -> std::uint32_t(*)(void*, std::uint32_t, std::uint32_t, pixelcopy_t*) + static auto get_fp_copy_rgb_affine(color_depth_t dst_depth) -> uint32_t(*)(void*, uint32_t, uint32_t, pixelcopy_t*) { return (dst_depth == rgb565_2Byte) ? copy_rgb_affine - : (dst_depth == rgb332_1Byte ) ? copy_rgb_affine + : (dst_depth == rgb332_1Byte) ? copy_rgb_affine : (dst_depth == rgb888_3Byte) ? copy_rgb_affine : (dst_depth == rgb666_3Byte) ? (std::is_same::value ? copy_rgb_affine @@ -151,10 +151,10 @@ namespace lgfx } template - static auto get_fp_copy_rgb_affine_dst(color_depth_t src_depth) -> std::uint32_t(*)(void*, std::uint32_t, std::uint32_t, pixelcopy_t*) + static auto get_fp_copy_rgb_affine_dst(color_depth_t src_depth) -> uint32_t(*)(void*, uint32_t, uint32_t, pixelcopy_t*) { return (src_depth == rgb565_2Byte) ? copy_rgb_affine - : (src_depth == rgb332_1Byte ) ? copy_rgb_affine + : (src_depth == rgb332_1Byte) ? copy_rgb_affine : (src_depth == rgb888_3Byte) ? copy_rgb_affine : (std::is_same::value) ? copy_rgb_affine @@ -162,26 +162,26 @@ namespace lgfx } template - static auto get_fp_copy_palette_affine(color_depth_t dst_depth) -> std::uint32_t(*)(void*, std::uint32_t, std::uint32_t, pixelcopy_t*) + static auto get_fp_copy_palette_affine(color_depth_t dst_depth) -> uint32_t(*)(void*, uint32_t, uint32_t, pixelcopy_t*) { return (dst_depth == rgb565_2Byte) ? copy_palette_affine - : (dst_depth == rgb332_1Byte ) ? copy_palette_affine - : (dst_depth == rgb888_3Byte) ? copy_palette_affine - : (dst_depth == rgb666_3Byte) ? copy_palette_affine + : (dst_depth == rgb332_1Byte) ? copy_palette_affine + : (dst_depth == rgb888_3Byte) ? copy_palette_affine + : (dst_depth == rgb666_3Byte) ? copy_palette_affine : nullptr; } - static std::uint32_t copy_bit_fast(void* __restrict__ dst, std::uint32_t index, std::uint32_t last, pixelcopy_t* __restrict__ param) + static uint32_t copy_bit_fast(void* __restrict__ dst, uint32_t index, uint32_t last, pixelcopy_t* __restrict__ param) { auto dst_bits = param->dst_bits; auto shift = ((~index) * dst_bits) & 7; - auto s = static_cast(param->src_data); - auto d = &(static_cast(dst)[(index * dst_bits) >> 3]); + auto s = static_cast(param->src_data); + auto d = &(static_cast(dst)[(index * dst_bits) >> 3]); - std::uint32_t i = param->positions[0] * param->src_bits; + uint32_t i = param->positions[0] * param->src_bits; param->positions[0] += last - index; do { - std::uint32_t raw = s[i >> 3]; + uint32_t raw = s[i >> 3]; i += param->src_bits; raw = (raw >> (-i & 7)) & param->src_mask; *d = (*d & ~(param->dst_mask << shift)) | ((param->dst_mask & raw) << shift); @@ -192,24 +192,24 @@ namespace lgfx } template - static std::uint32_t copy_palette_fast(void* __restrict__ dst, std::uint32_t index, std::uint32_t last, pixelcopy_t* __restrict__ param) + static uint32_t copy_palette_fast(void* __restrict__ dst, uint32_t index, uint32_t last, pixelcopy_t* __restrict__ param) { - auto s = static_cast(param->src_data); + auto s = static_cast(param->src_data); auto d = static_cast(dst); auto pal = static_cast(param->palette); - std::uint32_t i = param->positions[0] * param->src_bits; + uint32_t i = param->positions[0] * param->src_bits; param->positions[0] += last - index; do { - std::uint32_t raw = s[i >> 3]; + uint32_t raw = s[i >> 3]; i += param->src_bits; raw = (raw >> (-i & 7)) & param->src_mask; - d[index] = pal[raw]; + d[index].set(color_convert(pal[raw].get())); } while (++index != last); return index; } template - static std::uint32_t copy_rgb_fast(void* dst, std::uint32_t index, std::uint32_t last, pixelcopy_t* param) + static uint32_t copy_rgb_fast(void* dst, uint32_t index, uint32_t last, pixelcopy_t* param) { auto s = &static_cast(param->src_data)[param->positions[0] - index]; auto d = static_cast(dst); @@ -221,22 +221,22 @@ namespace lgfx else { do { - d[index] = s[index]; + d[index].set(color_convert(s[index].get())); } while (++index != last); } return last; } - static std::uint32_t copy_bit_affine(void* __restrict__ dst, std::uint32_t index, std::uint32_t last, pixelcopy_t* __restrict__ param) + static uint32_t copy_bit_affine(void* __restrict__ dst, uint32_t index, uint32_t last, pixelcopy_t* __restrict__ param) { - auto s = static_cast(param->src_data); - auto d = static_cast(dst); + auto s = static_cast(param->src_data); + auto d = static_cast(dst); do { - std::uint32_t i = (param->src_x + param->src_y * param->src_bitwidth) * param->src_bits; + uint32_t i = (param->src_x + param->src_y * param->src_bitwidth) * param->src_bits; param->src_x32 += param->src_x32_add; param->src_y32 += param->src_y32_add; - std::uint32_t raw = (s[i >> 3] >> (-(i + param->src_bits) & 7)) & param->src_mask; + uint32_t raw = (pgm_read_byte(&s[i >> 3]) >> (-(i + param->src_bits) & 7)) & param->src_mask; if (raw != param->transp) { auto dstidx = index * param->dst_bits; auto shift = (-(dstidx + param->dst_bits)) & 7; @@ -248,17 +248,17 @@ namespace lgfx } template - static std::uint32_t copy_palette_affine(void* __restrict__ dst, std::uint32_t index, std::uint32_t last, pixelcopy_t* __restrict__ param) + static uint32_t copy_palette_affine(void* __restrict__ dst, uint32_t index, uint32_t last, pixelcopy_t* __restrict__ param) { - auto s = static_cast(param->src_data); + auto s = static_cast(param->src_data); auto d = static_cast(dst); auto pal = static_cast(param->palette); auto transp = param->transp; do { - std::uint32_t i = (param->src_x + param->src_y * param->src_bitwidth) * param->src_bits; - std::uint32_t raw = (s[i >> 3] >> (-(i + param->src_bits) & 7)) & param->src_mask; + uint32_t i = (param->src_x + param->src_y * param->src_bitwidth) * param->src_bits; + uint32_t raw = (pgm_read_byte(&s[i >> 3]) >> (-(i + param->src_bits) & 7)) & param->src_mask; if (raw == transp) break; - d[index] = pal[raw]; + d[index].set(color_convert(pal[raw].get())); param->src_x32 += param->src_x32_add; param->src_y32 += param->src_y32_add; } while (++index != last); @@ -266,26 +266,32 @@ namespace lgfx } template - static std::uint32_t copy_rgb_affine(void* __restrict__ dst, std::uint32_t index, std::uint32_t last, pixelcopy_t* __restrict__ param) + static uint32_t copy_rgb_affine(void* __restrict__ dst, uint32_t index, uint32_t last, pixelcopy_t* __restrict__ param) { auto s = static_cast(param->src_data); auto d = static_cast(dst); + auto src_bitwidth = param->src_bitwidth; auto src_x32_add = param->src_x32_add; auto src_y32_add = param->src_y32_add; + auto src_x32 = param->src_x32; + auto src_y32 = param->src_y32; do { - std::uint32_t i = param->src_x + param->src_y * param->src_bitwidth; - if (s[i] == param->transp) break; - d[index] = s[i]; - param->src_x32 += src_x32_add; - param->src_y32 += src_y32_add; + uint32_t i = (src_x32 >> FP_SCALE) + (src_y32 >> FP_SCALE) * src_bitwidth; + uint32_t raw = s[i].get(); + if (raw == param->transp) break; + d[index].set(color_convert(raw)); + src_x32 += src_x32_add; + src_y32 += src_y32_add; } while (++index != last); + param->src_x32 = src_x32; + param->src_y32 = src_y32; return index; } template - static std::uint32_t copy_palette_antialias(void* __restrict__ dst, std::uint32_t index, std::uint32_t last, pixelcopy_t* __restrict__ param) + static uint32_t copy_palette_antialias(void* __restrict__ dst, uint32_t index, uint32_t last, pixelcopy_t* __restrict__ param) { - auto s = static_cast(param->src_data); + auto s = static_cast(param->src_data); auto d = static_cast(dst); auto pal = static_cast(param->palette); auto src_bitwidth= param->src_bitwidth; @@ -306,37 +312,37 @@ namespace lgfx param->src_y32 += param->src_y32_add; param->src_ye32 += param->src_y32_add; - std::int32_t x = param->src_x; - std::int32_t y = param->src_y; - if (param->src_x == param->src_xe && param->src_y == param->src_ye && static_cast(param->src_x) < src_width && static_cast(param->src_y) < src_height) + int32_t x = param->src_x; + int32_t y = param->src_y; + if (param->src_x == param->src_xe && param->src_y == param->src_ye && static_cast(param->src_x) < src_width && static_cast(param->src_y) < src_height) { - std::uint32_t i = (x + y * src_bitwidth) * src_bits; - std::uint32_t raw = (s[i >> 3] >> (-(i + src_bits) & 7)) & src_mask; + uint32_t i = (x + y * src_bitwidth) * src_bits; + uint32_t raw = (s[i >> 3] >> (-(i + src_bits) & 7)) & src_mask; if (!(raw == transp)) { d[index].set(pal[raw].R8(), pal[raw].G8(), pal[raw].B8()); } else { - d[index] = 0u; + d[index].set(0); } } else { - std::uint32_t argb[5] = {0}; + uint32_t argb[5] = {0}; { - std::uint32_t rate_x = 256u - (param->src_x_lo >> 8); - std::uint32_t rate_y = 256u - (param->src_y_lo >> 8); - std::uint32_t i = y * src_bitwidth; + uint32_t rate_x = 256u - (param->src_x_lo >> 8); + uint32_t rate_y = 256u - (param->src_y_lo >> 8); + uint32_t i = y * src_bitwidth; for (;;) { - std::uint32_t rate = rate_x * rate_y; + uint32_t rate = rate_x * rate_y; argb[4] += rate; - if (static_cast(y) < src_height - && static_cast(x) < src_width) + if (static_cast(y) < src_height + && static_cast(x) < src_width) { - std::uint32_t k = (i + x) * src_bits; - std::uint32_t raw = (s[k >> 3] >> (-(k + src_bits) & 7)) & src_mask; + uint32_t k = (i + x) * src_bits; + uint32_t raw = (s[k >> 3] >> (-(k + src_bits) & 7)) & src_mask; if (!(raw == transp)) { if (std::is_same::value) { rate *= pal[raw].A8(); } @@ -360,10 +366,10 @@ namespace lgfx } } } - std::uint32_t a = argb[3]; + uint32_t a = argb[3]; if (!a) { - d[index] = 0u; + d[index].set(0); } else { @@ -379,7 +385,7 @@ namespace lgfx } template - static std::uint32_t copy_rgb_antialias(void* __restrict__ dst, std::uint32_t index, std::uint32_t last, pixelcopy_t* __restrict__ param) + static uint32_t copy_rgb_antialias(void* __restrict__ dst, uint32_t index, uint32_t last, pixelcopy_t* __restrict__ param) { auto s = static_cast(param->src_data); auto d = static_cast(dst); @@ -397,10 +403,10 @@ namespace lgfx param->src_y32 += param->src_y32_add; param->src_ye32 += param->src_y32_add; - std::int32_t x = param->src_x; - std::int32_t y = param->src_y; + int32_t x = param->src_x; + int32_t y = param->src_y; auto color = &s[x + y * src_width]; - if (param->src_x == param->src_xe && param->src_y == param->src_ye && static_cast(param->src_x) < src_width && static_cast(param->src_y) < src_height) + if (param->src_x == param->src_xe && param->src_y == param->src_ye && static_cast(param->src_x) < src_width && static_cast(param->src_y) < src_height) { if (!(*color == param->transp)) { @@ -408,21 +414,21 @@ namespace lgfx } else { - d[index] = 0u; + d[index].set(0); } } else { - std::uint32_t argb[5] = {0}; + uint32_t argb[5] = {0}; { - std::uint32_t rate_y = 256u - (param->src_y_lo >> 8); - std::uint32_t rate_x = 256u - (param->src_x_lo >> 8); + uint32_t rate_y = 256u - (param->src_y_lo >> 8); + uint32_t rate_x = 256u - (param->src_x_lo >> 8); for (;;) { - std::uint32_t rate = rate_x * rate_y; + uint32_t rate = rate_x * rate_y; argb[4] += rate; - if (static_cast(y) < src_height - && static_cast(x) < src_width + if (static_cast(y) < src_height + && static_cast(x) < src_width && !(*color == param->transp)) { if (std::is_same::value) { rate *= color->A8(); } @@ -446,10 +452,10 @@ namespace lgfx } } } - std::uint32_t a = argb[3]; + uint32_t a = argb[3]; if (!a) { - d[index] = 0u; + d[index].set(0); } else { @@ -467,17 +473,17 @@ namespace lgfx } - static std::uint32_t blend_palette_fast(void* __restrict__ dst, std::uint32_t index, std::uint32_t last, pixelcopy_t* __restrict__ param) + static uint32_t blend_palette_fast(void* __restrict__ dst, uint32_t index, uint32_t last, pixelcopy_t* __restrict__ param) { auto dst_bits = param->dst_bits; auto dst_mask = param->dst_mask; - std::uint32_t k = (dst_bits == 1) ? 0xFF - : (dst_bits == 2) ? 0x55 - : (dst_bits == 4) ? 0x11 - : 0x01 - ; + uint32_t k = (dst_bits == 1) ? 0xFF + : (dst_bits == 2) ? 0x55 + : (dst_bits == 4) ? 0x11 + : 0x01 + ; auto shift = ((~index) * dst_bits) & 7; - auto d = &(static_cast(dst)[(index * dst_bits) >> 3]); + auto d = &(static_cast(dst)[(index * dst_bits) >> 3]); auto src_x32_add = param->src_x32_add; auto src_y32_add = param->src_y32_add; /* @@ -485,13 +491,13 @@ namespace lgfx { auto s = &(static_cast(param->src_data)[param->src_x + param->src_y * param->src_bitwidth - index]); do { - std::uint_fast16_t a = s[index].a; + uint_fast16_t a = s[index].a; if (a) { - std::uint32_t raw = (s[index].R8() + (s[index].G8()<<1) + s[index].B8()) >> 2; + uint32_t raw = (s[index].R8() + (s[index].G8()<<1) + s[index].B8()) >> 2; if (a != 255) { - std::uint_fast16_t inv = (256 - a) * k; + uint_fast16_t inv = (256 - a) * k; raw = (((*d >> shift) & dst_mask) * inv + raw * ++a) >> 8; } *d = (*d & ~(dst_mask << shift)) | (dst_mask & (raw >> (8 - dst_bits))) << shift; @@ -504,14 +510,14 @@ namespace lgfx //*/ auto s = static_cast(param->src_data); do { - std::uint32_t i = param->src_x + param->src_y * param->src_bitwidth; - std::uint_fast16_t a = s[i].a; + uint32_t i = param->src_x + param->src_y * param->src_bitwidth; + uint_fast16_t a = s[i].a; if (a) { - std::uint32_t raw = (s[i].R8() + (s[i].G8()<<1) + s[i].B8()) >> 2; + uint32_t raw = (s[i].R8() + (s[i].G8()<<1) + s[i].B8()) >> 2; if (a != 255) { - std::uint_fast16_t inv = (256 - a) * k; + uint_fast16_t inv = (256 - a) * k; raw = (((*d >> shift) & dst_mask) * inv + raw * ++a) >> 8; } *d = (*d & ~(dst_mask << shift)) | (dst_mask & (raw >> (8 - dst_bits))) << shift; @@ -525,7 +531,7 @@ namespace lgfx } template - static std::uint32_t blend_rgb_fast(void* __restrict__ dst, std::uint32_t index, std::uint32_t last, pixelcopy_t* __restrict__ param) + static uint32_t blend_rgb_fast(void* __restrict__ dst, uint32_t index, uint32_t last, pixelcopy_t* __restrict__ param) { auto d = static_cast(dst); auto src_x32_add = param->src_x32_add; @@ -535,7 +541,7 @@ namespace lgfx { auto s = &(static_cast(param->src_data)[param->src_x + param->src_y * param->src_bitwidth - index]); for (;;) { - std::uint_fast16_t a = s[index].a; + uint_fast16_t a = s[index].a; if (a) { if (a == 255) @@ -545,7 +551,7 @@ namespace lgfx continue; } - std::uint_fast16_t inv = 256 - a; + uint_fast16_t inv = 256 - a; ++a; d[index].set( (d[index].R8() * inv + s[index].R8() * a) >> 8 , (d[index].G8() * inv + s[index].G8() * a) >> 8 @@ -558,8 +564,8 @@ namespace lgfx //*/ auto s = static_cast(param->src_data); for (;;) { - std::uint32_t i = param->src_x + param->src_y * param->src_bitwidth; - std::uint_fast16_t a = s[i].a; + uint32_t i = param->src_x + param->src_y * param->src_bitwidth; + uint_fast16_t a = s[i].a; if (a) { if (a == 255) @@ -571,7 +577,7 @@ namespace lgfx continue; } - std::uint_fast16_t inv = 256 - a; + uint_fast16_t inv = 256 - a; ++a; d[index].set( (d[index].R8() * inv + s[i].R8() * a) >> 8 , (d[index].G8() * inv + s[i].G8() * a) >> 8 @@ -584,9 +590,9 @@ namespace lgfx } } - static std::uint32_t skip_bit_affine(std::uint32_t index, std::uint32_t last, pixelcopy_t* param) + static uint32_t skip_bit_affine(uint32_t index, uint32_t last, pixelcopy_t* param) { - auto s = static_cast(param->src_data); + auto s = static_cast(param->src_data); auto src_x32 = param->src_x32; auto src_y32 = param->src_y32; auto src_x32_add = param->src_x32_add; @@ -596,8 +602,8 @@ namespace lgfx auto src_bits = param->src_bits; auto src_mask = param->src_mask; do { - std::uint32_t i = ((src_x32 >> FP_SCALE) + (src_y32 >> FP_SCALE) * src_bitwidth) * src_bits; - std::uint32_t raw = (s[i >> 3] >> (-(i + src_bits) & 7)) & src_mask; + uint32_t i = ((src_x32 >> FP_SCALE) + (src_y32 >> FP_SCALE) * src_bitwidth) * src_bits; + uint32_t raw = (pgm_read_byte(&s[i >> 3]) >> (-(i + src_bits) & 7)) & src_mask; if (raw != transp) break; src_x32 += src_x32_add; src_y32 += src_y32_add; @@ -608,7 +614,7 @@ namespace lgfx } template - static std::uint32_t skip_rgb_affine(std::uint32_t index, std::uint32_t last, pixelcopy_t* param) + static uint32_t skip_rgb_affine(uint32_t index, uint32_t last, pixelcopy_t* param) { auto s = static_cast(param->src_data); auto src_x32 = param->src_x32; @@ -618,8 +624,8 @@ namespace lgfx auto src_bitwidth= param->src_bitwidth; auto transp = param->transp; do { - std::uint32_t i = (src_x32 >> FP_SCALE) + (src_y32 >> FP_SCALE) * src_bitwidth; - if (!(s[i] == transp)) break; + uint32_t i = (src_x32 >> FP_SCALE) + (src_y32 >> FP_SCALE) * src_bitwidth; + if (!(s[i].get() == transp)) break; src_x32 += src_x32_add; src_y32 += src_y32_add; } while (++index != last); @@ -629,26 +635,26 @@ namespace lgfx } template - static std::uint32_t compare_rgb_fast(void* __restrict__ dst, std::uint32_t index, std::uint32_t last, pixelcopy_t* __restrict__ param) + static uint32_t compare_rgb_fast(void* __restrict__ dst, uint32_t index, uint32_t last, pixelcopy_t* __restrict__ param) { auto s = static_cast(param->src_data); auto d = static_cast(dst); auto transp = param->transp; - std::uint32_t i = param->src_x + param->src_y * param->src_bitwidth - 1; + s += param->src_x + param->src_y * param->src_bitwidth - index; do { - d[index] = s[++i] == transp; + d[index] = s[index].get() == transp; } while (++index != last); return index; } - static std::uint32_t compare_bit_fast(void* __restrict__ dst, std::uint32_t index, std::uint32_t last, pixelcopy_t* __restrict__ param) + static uint32_t compare_bit_fast(void* __restrict__ dst, uint32_t index, uint32_t last, pixelcopy_t* __restrict__ param) { - auto s = static_cast(param->src_data); + auto s = static_cast(param->src_data); auto d = static_cast(dst); auto transp = param->transp; auto src_bits = param->src_bits; auto src_mask = param->src_mask; - std::uint32_t i = (param->src_x + param->src_y * param->src_bitwidth) * src_bits; + uint32_t i = (param->src_x + param->src_y * param->src_bitwidth) * src_bits; do { d[index] = transp == ((s[i >> 3] >> (-(i + src_bits) & 7)) & src_mask); i += src_bits; diff --git a/src/lgfx/v1/misc/range.hpp b/src/lgfx/v1/misc/range.hpp index 8bc74f7..a466e0c 100644 --- a/src/lgfx/v1/misc/range.hpp +++ b/src/lgfx/v1/misc/range.hpp @@ -17,7 +17,7 @@ Original Source: /----------------------------------------------------------------------------*/ #pragma once -#include +#include namespace lgfx { @@ -29,13 +29,13 @@ namespace lgfx #pragma pack(1) struct range_t { - std::int_fast16_t first; - std::int_fast16_t last; + int_fast16_t first; + int_fast16_t last; - std::int_fast16_t length(void) const { return last - first + 1; } + int_fast16_t length(void) const { return last - first + 1; } bool empty(void) const { return last < first; } bool intersectsWith(const range_t& r) const { return (r.first <= last) && (first <= r.last); } - bool intersectsWith(std::int_fast16_t f, std::int_fast16_t l) const { return (f <= last) && (first <= l); } + bool intersectsWith(int_fast16_t f, int_fast16_t l) const { return (f <= last) && (first <= l); } }; struct range_rect_t @@ -49,24 +49,24 @@ namespace lgfx }; struct { - std::int_fast16_t left; - std::int_fast16_t right; - std::int_fast16_t top; - std::int_fast16_t bottom; + int_fast16_t left; + int_fast16_t right; + int_fast16_t top; + int_fast16_t bottom; }; struct { - std::int_fast16_t l; - std::int_fast16_t r; - std::int_fast16_t t; - std::int_fast16_t b; + int_fast16_t l; + int_fast16_t r; + int_fast16_t t; + int_fast16_t b; }; }; - __attribute__ ((always_inline)) inline std::int_fast16_t width(void) const { return right - left + 1; } - __attribute__ ((always_inline)) inline std::int_fast16_t height(void) const { return bottom - top + 1; } + __attribute__ ((always_inline)) inline int_fast16_t width(void) const { return right - left + 1; } + __attribute__ ((always_inline)) inline int_fast16_t height(void) const { return bottom - top + 1; } __attribute__ ((always_inline)) inline bool empty(void) const { return left > right || top > bottom; } - __attribute__ ((always_inline)) inline bool contain(std::int_fast16_t x, std::int_fast16_t y) const { return left <= x && x <= right && top <= y && y <= bottom; } + __attribute__ ((always_inline)) inline bool contain(int_fast16_t x, int_fast16_t y) const { return left <= x && x <= right && top <= y && y <= bottom; } }; #pragma pack(pop) diff --git a/src/lgfx/v1/panel/Panel_Device.cpp b/src/lgfx/v1/panel/Panel_Device.cpp index 4fb2f59..83f9603 100644 --- a/src/lgfx/v1/panel/Panel_Device.cpp +++ b/src/lgfx/v1/panel/Panel_Device.cpp @@ -39,7 +39,7 @@ namespace lgfx _bus = bus ? bus : &nullobj; } - void Panel_Device::setBrightness(std::uint8_t brightness) + void Panel_Device::setBrightness(uint8_t brightness) { if (_light) _light->setBrightness(brightness); } @@ -66,7 +66,6 @@ namespace lgfx if (use_reset) { reset(); - delay(50); } return true; } @@ -93,18 +92,18 @@ namespace lgfx return _bus->busy(); } - void Panel_Device::display(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h) + void Panel_Device::display(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h) { _bus->flush(); } - void Panel_Device::writeCommand(std::uint32_t data, std::uint_fast8_t length) + void Panel_Device::writeCommand(uint32_t data, uint_fast8_t length) { if (_cfg.dlen_16bit) { - if (_align_data) + if (_has_align_data) { - _align_data = false; + _has_align_data = false; _bus->writeData(0, 8); } if (length == 1) { length = 2; data <<= 8; } @@ -112,7 +111,7 @@ namespace lgfx _bus->writeCommand(data, length << 3); } - void Panel_Device::writeData(std::uint32_t data, std::uint_fast8_t length) + void Panel_Device::writeData(uint32_t data, uint_fast8_t length) { if (!_cfg.dlen_16bit) { @@ -131,25 +130,25 @@ namespace lgfx } } /* - void Panel_Device::writeBytes(const std::uint8_t* data, std::uint32_t len, bool use_dma) + void Panel_Device::writeBytes(const uint8_t* data, uint32_t len, bool use_dma) { _bus->writeBytes(data, len, use_dma); if (_cfg.dlen_16bit && (_write_bits & 15) && (len & 1)) { - _align_data = !_align_data; + _has_align_data = !_has_align_data; } } */ - void Panel_Device::command_list(const std::uint8_t *addr) + void Panel_Device::command_list(const uint8_t *addr) { for (;;) { // For each command... - std::uint8_t cmd = *addr++; - std::uint8_t num = *addr++; // Number of args to follow + uint8_t cmd = *addr++; + uint8_t num = *addr++; // Number of args to follow if (cmd == 0xFF && num == 0xFF) break; writeCommand(cmd, 1); // Read, issue command - std::uint_fast8_t ms = num & CMD_INIT_DELAY; // If hibit set, delay follows args + uint_fast8_t ms = num & CMD_INIT_DELAY; // If hibit set, delay follows args num &= ~CMD_INIT_DELAY; // Mask out delay bit if (num) { @@ -169,13 +168,13 @@ namespace lgfx //---------------------------------------------------------------------------- - void Panel_Device::writeImageARGB(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param) + void Panel_Device::writeImageARGB(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param) { auto src_x = param->src_x; auto buffer = reinterpret_cast(const_cast(param->src_data)); auto bytes = param->dst_bits >> 3; // ESP_LOGI("LGFX","DEBUG: %d %d", param->dst_bits, bytes); - // std::uint8_t* dmabuf = _bus->getFlipBuffer(w * bytes); + // uint8_t* dmabuf = _bus->getFlipBuffer(w * bytes); // memset(dmabuf, 0, w * bytes); // param->fp_copy(dmabuf, 0, w, param); // setWindow(x, y, x + w - 1, y); @@ -185,12 +184,12 @@ namespace lgfx pixelcopy_t pc_write(nullptr, _write_depth, _write_depth); for (;;) { - std::uint8_t* dmabuf = _bus->getDMABuffer((w+1) * bytes); + uint8_t* dmabuf = _bus->getDMABuffer((w+1) * bytes); pc_write.src_data = dmabuf; - std::uint32_t xstart = 0, drawed_x = 0; + uint32_t xstart = 0, drawed_x = 0; do { - std::uint_fast8_t a = buffer[xstart].a; + uint_fast8_t a = buffer[xstart].a; if (!a) { if (drawed_x < xstart) @@ -207,7 +206,7 @@ namespace lgfx { while (255 == buffer[xstart].a && ++xstart != w); if (xstart == w) break; - std::uint32_t j = xstart; + uint32_t j = xstart; while (++j != w && buffer[j].a && buffer[j].a != 255); readRect(x + xstart, y, j - xstart + 1, 1, &dmabuf[xstart * bytes], &pc_read); if (w == (xstart = j)) break; @@ -228,24 +227,24 @@ namespace lgfx } } - void Panel_Device::copyRect(std::uint_fast16_t dst_x, std::uint_fast16_t dst_y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint_fast16_t src_x, std::uint_fast16_t src_y) + void Panel_Device::copyRect(uint_fast16_t dst_x, uint_fast16_t dst_y, uint_fast16_t w, uint_fast16_t h, uint_fast16_t src_x, uint_fast16_t src_y) { pixelcopy_t pc_read( (void*)nullptr, _write_depth, _read_depth); pixelcopy_t pc_write((void*)nullptr, _write_depth, _write_depth); - std::size_t write_bytes = (_write_depth + 7) >> 3; + size_t write_bytes = (_write_depth + 7) >> 3; startWrite(); auto dir = get_fastread_dir(); if (dir == fastread_dir_t::fastread_vertical || (dir == fastread_dir_t::fastread_nothing && (w < h))) { - const std::uint32_t buflen = h * write_bytes; - std::uint8_t buf[buflen]; + const uint32_t buflen = h * write_bytes; + auto buf = (uint8_t*)alloca(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; + int32_t add = (src_x < dst_x) ? - 1 : 1; + int32_t pos = (src_x < dst_x) ? w - 1 : 0; do { readRect(src_x + pos, src_y, 1, h, buf, &pc_read); pc_write.src_x = 0; @@ -259,11 +258,11 @@ namespace lgfx } else { - const std::uint32_t buflen = w * write_bytes; - std::uint8_t buf[buflen]; + const uint32_t buflen = w * write_bytes; + auto buf = (uint8_t*)alloca(buflen); pc_write.src_data = buf; - std::int32_t add = (src_y < dst_y) ? - 1 : 1; - std::int32_t pos = (src_y < dst_y) ? h - 1 : 0; + int32_t add = (src_y < dst_y) ? - 1 : 1; + int32_t pos = (src_y < dst_y) ? h - 1 : 0; do { readRect(src_x, src_y + pos, w, 1, buf, &pc_read); pc_write.src_x = 0; @@ -312,9 +311,12 @@ namespace lgfx { auto pin = _cfg.pin_rst; if (pin < 0) return; + gpio_hi(pin); + delay(64); gpio_lo(pin); delay(4); gpio_hi(pin); + delay(64); } //---------------------------------------------------------------------------- @@ -330,7 +332,7 @@ namespace lgfx if (_touch == nullptr) return; auto cfg = _touch->config(); - std::uint16_t parameters[8] = + uint16_t parameters[8] = { cfg.x_min, cfg.y_min , cfg.x_min, cfg.y_max , cfg.x_max, cfg.y_min @@ -343,9 +345,9 @@ namespace lgfx memcpy(_affine, affine, sizeof(float) * 6); } - void Panel_Device::setCalibrate(std::uint16_t *parameters) + void Panel_Device::setCalibrate(uint16_t *parameters) { - std::uint32_t vect[6] = {0,0,0,0,0,0}; + uint32_t vect[6] = {0,0,0,0,0,0}; float mat[3][3] = {{0,0,0},{0,0,0},{0,0,0}}; float a; @@ -357,10 +359,10 @@ namespace lgfx } for ( int i = 0; i < 4; ++i ) { - std::int32_t tx = (i & 2) ? (w - 1) : 0; - std::int32_t ty = (i & 1) ? (h - 1) : 0; - std::int32_t px = parameters[i*2 ]; - std::int32_t py = parameters[i*2+1]; + int32_t tx = (i & 2) ? (w - 1) : 0; + int32_t ty = (i & 1) ? (h - 1) : 0; + int32_t px = parameters[i*2 ]; + int32_t py = parameters[i*2+1]; a = px * px; mat[0][0] += a; a = px * py; @@ -422,7 +424,7 @@ namespace lgfx _affine[5] = mat[2][0] * v3 + mat[2][1] * v4 + mat[2][2] * v5; } - void Panel_Device::convertRawXY(touch_point_t *tp, std::uint_fast8_t count) + void Panel_Device::convertRawXY(touch_point_t *tp, uint_fast8_t count) { auto r = _internal_rotation; if (_touch) { @@ -431,10 +433,10 @@ namespace lgfx } bool vflip = (1 << r) & 0b10010110; // r 1,2,4,7 - for (std::size_t idx = 0; idx < count; ++idx) + for (size_t idx = 0; idx < count; ++idx) { - std::int32_t tx = (_affine[0] * (float)tp[idx].x + _affine[1] * (float)tp[idx].y) + _affine[2]; - std::int32_t ty = (_affine[3] * (float)tp[idx].x + _affine[4] * (float)tp[idx].y) + _affine[5]; + int32_t tx = (_affine[0] * (float)tp[idx].x + _affine[1] * (float)tp[idx].y) + _affine[2]; + int32_t ty = (_affine[3] * (float)tp[idx].x + _affine[4] * (float)tp[idx].y) + _affine[5]; if (r) { if (r & 1) { std::swap(tx, ty); } @@ -446,7 +448,7 @@ namespace lgfx } } - std::uint_fast8_t Panel_Device::getTouchRaw(touch_point_t* tp, std::uint_fast8_t count) + uint_fast8_t Panel_Device::getTouchRaw(touch_point_t* tp, uint_fast8_t count) { if (_touch == nullptr) return 0; @@ -457,7 +459,7 @@ namespace lgfx return count; } - std::uint_fast8_t Panel_Device::getTouch(touch_point_t* tp, std::uint_fast8_t count) + uint_fast8_t Panel_Device::getTouch(touch_point_t* tp, uint_fast8_t count) { auto res = getTouchRaw(tp, count); convertRawXY(tp, res); diff --git a/src/lgfx/v1/panel/Panel_Device.hpp b/src/lgfx/v1/panel/Panel_Device.hpp index bd92954..7c1e415 100644 --- a/src/lgfx/v1/panel/Panel_Device.hpp +++ b/src/lgfx/v1/panel/Panel_Device.hpp @@ -38,51 +38,51 @@ namespace lgfx { /// Number of CS pin /// CS ピン番号 - std::int16_t pin_cs = -1; + int16_t pin_cs = -1; /// Number of RST pin /// RST ピン番号 - std::int16_t pin_rst = -1; + int16_t pin_rst = -1; /// Number of BUSY pin /// BUSY ピン番号 - std::int16_t pin_busy = -1; + int16_t pin_busy = -1; /// The maximum width of an image that the LCD driver can handle. /// LCDドライバが扱える画像の最大幅 - std::uint16_t memory_width = 240; + uint16_t memory_width = 240; /// The maximum height of an image that the LCD driver can handle. /// LCDドライバが扱える画像の最大高さ - std::uint16_t memory_height = 240; + uint16_t memory_height = 240; /// Actual width of the display. /// 実際に表示できる幅 - std::uint16_t panel_width = 240; + uint16_t panel_width = 240; /// Actual height of the display. /// 実際に表示できる高さ - std::uint16_t panel_height = 240; + uint16_t panel_height = 240; /// Number of offset pixels in the X direction. /// パネルのX方向オフセット量 - std::uint16_t offset_x = 0; + uint16_t offset_x = 0; /// Number of offset pixels in the Y direction. /// パネルのY方向オフセット量 - std::uint16_t offset_y = 0; + uint16_t offset_y = 0; /// Offset value in the direction of rotation. 0~7 (4~7 is upside down) /// 回転方向のオフセット 0~7 (4~7は上下反転) - std::uint8_t offset_rotation = 0; + uint8_t offset_rotation = 0; /// Number of bits in dummy read before pixel readout. /// ピクセル読出し前のダミーリードのビット数 - std::uint8_t dummy_read_pixel = 8; + uint8_t dummy_read_pixel = 8; /// Number of bits in dummy read before data readout. /// データ読出し前のダミーリードのビット数 - std::uint8_t dummy_read_bits = 1; + uint8_t dummy_read_bits = 1; /// Whether the data is readable or not. /// データ読出しが可能か否か @@ -122,19 +122,19 @@ namespace lgfx void light(ILight* light) { _light = light; } ILight* getLight(void) const { return _light; } ILight* light(void) const { return _light; } - void setBrightness(std::uint8_t brightness) override; + void setBrightness(uint8_t brightness) override; void setTouch(ITouch* touch); void touch(ITouch* touch) { setTouch(touch); } ITouch* getTouch(void) const { return _touch; } ITouch* touch(void) const { return _touch; } - std::uint_fast8_t getTouchRaw(touch_point_t* tp, std::uint_fast8_t count); - std::uint_fast8_t getTouch(touch_point_t* tp, std::uint_fast8_t count); - void convertRawXY(touch_point_t *tp, std::uint_fast8_t count); + uint_fast8_t getTouchRaw(touch_point_t* tp, uint_fast8_t count); + uint_fast8_t getTouch(touch_point_t* tp, uint_fast8_t count); + void convertRawXY(touch_point_t *tp, uint_fast8_t count); void touchCalibrate(void); void setCalibrateAffine(float affine[6]); - void setCalibrate(std::uint16_t *parameters); + void setCalibrate(uint16_t *parameters); bool isReadable(void) const override { return _cfg.readable; } @@ -143,25 +143,25 @@ namespace lgfx void initDMA(void) override; void waitDMA(void) override; bool dmaBusy(void) override; - void display(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h) override; + void display(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h) override; - void writeCommand(std::uint32_t data, std::uint_fast8_t length) override; - void writeData(std::uint32_t data, std::uint_fast8_t length) override; - //void writePixelsDMA(const std::uint8_t* data, std::uint32_t length) override; - void writeImageARGB(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param) override; - void copyRect(std::uint_fast16_t dst_x, std::uint_fast16_t dst_y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint_fast16_t src_x, std::uint_fast16_t src_y) override; + void writeCommand(uint32_t data, uint_fast8_t length) override; + void writeData(uint32_t data, uint_fast8_t length) override; + //void writePixelsDMA(const uint8_t* data, uint32_t length) override; + void writeImageARGB(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param) override; + void copyRect(uint_fast16_t dst_x, uint_fast16_t dst_y, uint_fast16_t w, uint_fast16_t h, uint_fast16_t src_x, uint_fast16_t src_y) override; protected: - static constexpr std::uint8_t CMD_INIT_DELAY = 0x80; + static constexpr uint8_t CMD_INIT_DELAY = 0x80; config_t _cfg; IBus* _bus = nullptr; ILight* _light = nullptr; ITouch* _touch = nullptr; - bool _align_data = false; - std::uint8_t _internal_rotation = 0; + bool _has_align_data = false; + uint8_t _internal_rotation = 0; float _affine[6] = {1,0,0,0,1,0}; /// touch affine parameter @@ -187,7 +187,7 @@ namespace lgfx /// Get the panel initialization command sequence. /// パネルの初期化コマンド列を得る。無い場合はnullptrを返す。 - virtual const std::uint8_t* getInitCommands(std::uint8_t listno) const { (void)listno; return nullptr; } + virtual const uint8_t* getInitCommands(uint8_t listno) const { (void)listno; return nullptr; } enum fastread_dir_t { @@ -197,7 +197,7 @@ namespace lgfx }; virtual fastread_dir_t get_fastread_dir(void) const { return fastread_nothing; } - void command_list(const std::uint8_t *addr); + void command_list(const uint8_t *addr); }; @@ -210,42 +210,42 @@ namespace lgfx void initBus(void) override {} void releaseBus(void) override {} - bool init(bool use_reset) override { return false; } + bool init(bool) override { return false; } void beginTransaction(void) override {} void endTransaction(void) override {} color_depth_t setColorDepth(color_depth_t depth) override { return depth; } - void setInvert(bool invert) override {} - void setRotation(std::uint_fast8_t r) override {} - void setSleep(bool flg_sleep) override {} - void setPowerSave(bool flg_partial) override {} + void setInvert(bool) override {} + void setRotation(uint_fast8_t) override {} + void setSleep(bool) override {} + void setPowerSave(bool) override {} - void writeCommand(std::uint32_t cmd, std::uint_fast8_t length) override {} - void writeData(std::uint32_t data, std::uint_fast8_t length) override {} + void writeCommand(uint32_t, uint_fast8_t) override {} + void writeData(uint32_t, uint_fast8_t) override {} void initDMA(void) override {} void waitDMA(void) override {} bool dmaBusy(void) override { return false; } void waitDisplay(void) override {} bool displayBusy(void) override { return false; } - void display(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h) override {} + void display(uint_fast16_t, uint_fast16_t, uint_fast16_t, uint_fast16_t) override {} bool isReadable(void) const override { return false; } bool isBusShared(void) const override { return false; } - void writeBlock(std::uint32_t rawcolor, std::uint32_t len) override {} - void setWindow(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) override {} - void drawPixelPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t rawcolor) override {} - void writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) override {} - void writeImage(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param, bool use_dma) override {} - void writeImageARGB(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param) override {} - void writePixels(pixelcopy_t* param, std::uint32_t len, bool use_dma) override {} - - std::uint32_t readCommand(std::uint_fast8_t cmd, std::uint_fast8_t index = 0, std::uint_fast8_t length = 4) override { return 0; } - std::uint32_t readData(std::uint_fast8_t index = 0, std::uint_fast8_t length = 4) override { return 0; } - void readRect(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, void* dst, pixelcopy_t* param) override {} - void copyRect(std::uint_fast16_t dst_x, std::uint_fast16_t dst_y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint_fast16_t src_x, std::uint_fast16_t src_y) override {} + void writeBlock(uint32_t, uint32_t) override {} + void setWindow(uint_fast16_t, uint_fast16_t, uint_fast16_t, uint_fast16_t) override {} + void drawPixelPreclipped(uint_fast16_t, uint_fast16_t, uint32_t) override {} + void writeFillRectPreclipped(uint_fast16_t, uint_fast16_t, uint_fast16_t, uint_fast16_t, uint32_t) override {} + void writeImage(uint_fast16_t, uint_fast16_t, uint_fast16_t, uint_fast16_t, pixelcopy_t*, bool) override {} + void writeImageARGB(uint_fast16_t, uint_fast16_t, uint_fast16_t, uint_fast16_t, pixelcopy_t*) override {} + void writePixels(pixelcopy_t*, uint32_t, bool) override {} + + uint32_t readCommand(uint_fast8_t, uint_fast8_t, uint_fast8_t) override { return 0; } + uint32_t readData(uint_fast8_t, uint_fast8_t) override { return 0; } + void readRect(uint_fast16_t, uint_fast16_t, uint_fast16_t, uint_fast16_t, void*, pixelcopy_t*) override {} + void copyRect(uint_fast16_t, uint_fast16_t, uint_fast16_t, uint_fast16_t, uint_fast16_t, uint_fast16_t) override {} }; //---------------------------------------------------------------------------- diff --git a/src/lgfx/v1/panel/Panel_GC9A01.hpp b/src/lgfx/v1/panel/Panel_GC9A01.hpp index 04dabba..7e85d30 100644 --- a/src/lgfx/v1/panel/Panel_GC9A01.hpp +++ b/src/lgfx/v1/panel/Panel_GC9A01.hpp @@ -35,7 +35,7 @@ namespace lgfx _cfg.dummy_read_pixel = 16; } - void setWindow(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) override + void setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye) override { if (xs != _xs || xe != _xe || ys != _ys || ye != _ye) { @@ -63,9 +63,9 @@ namespace lgfx protected: - std::uint8_t getMadCtl(std::uint8_t r) const override + uint8_t getMadCtl(uint8_t r) const override { - static constexpr std::uint8_t madctl_table[] = + static constexpr uint8_t madctl_table[] = { 0, MAD_MV|MAD_MX , @@ -79,9 +79,9 @@ namespace lgfx return madctl_table[r]; } - const std::uint8_t* getInitCommands(std::uint8_t listno) const override + const uint8_t* getInitCommands(uint8_t listno) const override { - static constexpr std::uint8_t list0[] = { + static constexpr uint8_t list0[] = { 0xEF, 0, 0xEB, 1, 0x14, 0xFE, 0, diff --git a/src/lgfx/v1/panel/Panel_GDEW0154M09.cpp b/src/lgfx/v1/panel/Panel_GDEW0154M09.cpp index 96081d8..93e61b4 100644 --- a/src/lgfx/v1/panel/Panel_GDEW0154M09.cpp +++ b/src/lgfx/v1/panel/Panel_GDEW0154M09.cpp @@ -26,7 +26,7 @@ namespace lgfx { //---------------------------------------------------------------------------- - static constexpr std::uint8_t Bayer[16] = { 8, 200, 40, 232, 72, 136, 104, 168, 56, 248, 24, 216, 120, 184, 88, 152 }; + static constexpr uint8_t Bayer[16] = { 8, 200, 40, 232, 72, 136, 104, 168, 56, 248, 24, 216, 120, 184, 88, 152 }; Panel_GDEW0154M09::Panel_GDEW0154M09(void) { @@ -43,7 +43,7 @@ namespace lgfx return color_depth_t::rgb565_2Byte; } - std::size_t Panel_GDEW0154M09::_get_buffer_length(void) const + size_t Panel_GDEW0154M09::_get_buffer_length(void) const { return ((_cfg.panel_width + 7) & ~7) * _cfg.panel_height >> 3; } @@ -63,7 +63,7 @@ namespace lgfx startWrite(true); - for (std::uint8_t i = 0; auto cmds = getInitCommands(i); i++) + for (uint8_t i = 0; auto cmds = getInitCommands(i); i++) { command_list(cmds); } @@ -95,14 +95,14 @@ namespace lgfx return _cfg.pin_busy >= 0 && !gpio_in(_cfg.pin_busy); } - void Panel_GDEW0154M09::display(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h) + void Panel_GDEW0154M09::display(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h) { if (0 < w && 0 < h) { - _range_mod.left = std::min(_range_mod.left , x ); - _range_mod.right = std::max(_range_mod.right , x + w - 1); - _range_mod.top = std::min(_range_mod.top , y ); - _range_mod.bottom = std::max(_range_mod.bottom, y + h - 1); + _range_mod.left = std::min(_range_mod.left , x ); + _range_mod.right = std::max(_range_mod.right , x + w - 1); + _range_mod.top = std::min(_range_mod.top , y ); + _range_mod.bottom = std::max(_range_mod.bottom, y + h - 1); } if (_range_mod.empty()) { return; } _close_transfer(); @@ -178,10 +178,10 @@ namespace lgfx endWrite(); } - void Panel_GDEW0154M09::writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) + void Panel_GDEW0154M09::writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t rawcolor) { - std::uint_fast16_t xs = x, xe = x + w - 1; - std::uint_fast16_t ys = y, ye = y + h - 1; + uint_fast16_t xs = x, xe = x + w - 1; + uint_fast16_t ys = y, ye = y + h - 1; _xs = xs; _ys = ys; _xe = xe; @@ -190,13 +190,13 @@ namespace lgfx swap565_t color; color.raw = rawcolor; - std::uint32_t value = (color.R8() + (color.G8() << 1) + color.B8()) >> 2; + uint32_t value = (color.R8() + (color.G8() << 1) + color.B8()) >> 2; y = ys; do { x = xs; - std::uint32_t idx = ((_cfg.panel_width + 7) & ~7) * y + x; + uint32_t idx = ((_cfg.panel_width + 7) & ~7) * y + x; auto btbl = &Bayer[(y & 3) << 2]; do { @@ -208,18 +208,18 @@ namespace lgfx } while (++y <= ye); } - void Panel_GDEW0154M09::writeImage(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param, bool use_dma) + void Panel_GDEW0154M09::writeImage(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param, bool use_dma) { - std::uint_fast16_t xs = x, xe = x + w - 1; - std::uint_fast16_t ys = y, ye = y + h - 1; + uint_fast16_t xs = x, xe = x + w - 1; + uint_fast16_t ys = y, ye = y + h - 1; _update_transferred_rect(xs, ys, xe, ye); - swap565_t readbuf[w]; + auto readbuf = (swap565_t*)alloca(w * sizeof(swap565_t)); auto sx = param->src_x32; h += y; do { - std::uint32_t prev_pos = 0, new_pos = 0; + uint32_t prev_pos = 0, new_pos = 0; do { new_pos = param->fp_copy(readbuf, prev_pos, w, param); @@ -237,21 +237,21 @@ namespace lgfx } while (++y < h); } - void Panel_GDEW0154M09::writePixels(pixelcopy_t* param, std::uint32_t length, bool use_dma) + void Panel_GDEW0154M09::writePixels(pixelcopy_t* param, uint32_t length, bool use_dma) { { - std::uint_fast16_t xs = _xs; - std::uint_fast16_t xe = _xe; - std::uint_fast16_t ys = _ys; - std::uint_fast16_t ye = _ye; + uint_fast16_t xs = _xs; + uint_fast16_t xe = _xe; + uint_fast16_t ys = _ys; + uint_fast16_t ye = _ye; _update_transferred_rect(xs, ys, xe, ye); } - std::uint_fast16_t xs = _xs ; - std::uint_fast16_t ys = _ys ; - std::uint_fast16_t xe = _xe ; - std::uint_fast16_t ye = _ye ; - std::uint_fast16_t xpos = _xpos; - std::uint_fast16_t ypos = _ypos; + uint_fast16_t xs = _xs ; + uint_fast16_t ys = _ys ; + uint_fast16_t xe = _xe ; + uint_fast16_t ye = _ye ; + uint_fast16_t xpos = _xpos; + uint_fast16_t ypos = _ypos; static constexpr uint32_t buflen = 16; swap565_t colors[buflen]; @@ -277,15 +277,15 @@ namespace lgfx _ypos = ypos; } - void Panel_GDEW0154M09::readRect(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, void* dst, pixelcopy_t* param) + void Panel_GDEW0154M09::readRect(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, void* dst, pixelcopy_t* param) { - swap565_t readbuf[w]; + auto readbuf = (swap565_t*)alloca(w * sizeof(swap565_t)); param->src_data = readbuf; - std::int32_t readpos = 0; + int32_t readpos = 0; h += y; do { - std::uint32_t idx = 0; + uint32_t idx = 0; do { readbuf[idx] = _read_pixel(x + idx, y) ? ~0u : 0; @@ -295,11 +295,11 @@ namespace lgfx } while (++y < h); } - bool Panel_GDEW0154M09::_wait_busy(std::uint32_t timeout) + bool Panel_GDEW0154M09::_wait_busy(uint32_t timeout) { if (_cfg.pin_busy >= 0 && !gpio_in(_cfg.pin_busy)) { - std::uint32_t start_time = millis(); + uint32_t start_time = millis(); do { if (millis() - start_time > timeout) return false; @@ -309,26 +309,26 @@ namespace lgfx return true; } - void Panel_GDEW0154M09::_draw_pixel(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t value) + void Panel_GDEW0154M09::_draw_pixel(uint_fast16_t x, uint_fast16_t y, uint32_t value) { _rotate_pos(x, y); - std::uint32_t idx = ((_cfg.panel_width + 7) & ~7) * y + x; + uint32_t idx = ((_cfg.panel_width + 7) & ~7) * y + x; bool flg = 256 <= value + Bayer[(x & 3) | (y & 3) << 2]; if (flg) _buf[idx >> 3] |= 0x80 >> (idx & 7); else _buf[idx >> 3] &= ~(0x80 >> (idx & 7)); } - bool Panel_GDEW0154M09::_read_pixel(std::uint_fast16_t x, std::uint_fast16_t y) + bool Panel_GDEW0154M09::_read_pixel(uint_fast16_t x, uint_fast16_t y) { _rotate_pos(x, y); - std::uint32_t idx = ((_cfg.panel_width + 7) & ~7) * y + x; + uint32_t idx = ((_cfg.panel_width + 7) & ~7) * y + x; return _buf[idx >> 3] & (0x80 >> (idx & 7)); } - void Panel_GDEW0154M09::_exec_transfer(std::uint32_t cmd, const range_rect_t& range, bool invert) + void Panel_GDEW0154M09::_exec_transfer(uint32_t cmd, const range_rect_t& range, bool invert) { - std::int32_t xs = range.left & ~7; - std::int32_t xe = range.right & ~7; + int32_t xs = range.left & ~7; + int32_t xe = range.right & ~7; _wait_busy(); @@ -343,16 +343,16 @@ namespace lgfx _wait_busy(); _bus->writeCommand(cmd, 8); - std::int32_t w = ((xe - xs) >> 3) + 1; - std::int32_t y = range.top; - std::int32_t add = ((_cfg.panel_width + 7) & ~7) >> 3; + int32_t w = ((xe - xs) >> 3) + 1; + int32_t y = range.top; + int32_t add = ((_cfg.panel_width + 7) & ~7) >> 3; auto b = &_buf[xs >> 3]; if (invert) { b += y * add; do { - std::int32_t i = 0; + int32_t i = 0; do { _bus->writeData(~b[i], 8); @@ -388,21 +388,21 @@ namespace lgfx _bus->wait(); } - void Panel_GDEW0154M09::_update_transferred_rect(std::uint_fast16_t &xs, std::uint_fast16_t &ys, std::uint_fast16_t &xe, std::uint_fast16_t &ye) + void Panel_GDEW0154M09::_update_transferred_rect(uint_fast16_t &xs, uint_fast16_t &ys, uint_fast16_t &xe, uint_fast16_t &ye) { _rotate_pos(xs, ys, xe, ye); - std::int32_t x1 = xs & ~7; - std::int32_t x2 = (xe & ~7) + 7; + int32_t x1 = xs & ~7; + int32_t x2 = (xe & ~7) + 7; if (_range_old.horizon.intersectsWith(x1, x2) && _range_old.vertical.intersectsWith(ys, ye)) { _close_transfer(); } - _range_mod.top = std::min(ys, _range_mod.top); - _range_mod.left = std::min(x1, _range_mod.left); - _range_mod.right = std::max(x2, _range_mod.right); - _range_mod.bottom = std::max(ye, _range_mod.bottom); + _range_mod.top = std::min(ys, _range_mod.top); + _range_mod.left = std::min(x1, _range_mod.left); + _range_mod.right = std::max(x2, _range_mod.right); + _range_mod.bottom = std::max(ye, _range_mod.bottom); } //---------------------------------------------------------------------------- diff --git a/src/lgfx/v1/panel/Panel_GDEW0154M09.hpp b/src/lgfx/v1/panel/Panel_GDEW0154M09.hpp index 50cf42c..dd3f43f 100644 --- a/src/lgfx/v1/panel/Panel_GDEW0154M09.hpp +++ b/src/lgfx/v1/panel/Panel_GDEW0154M09.hpp @@ -40,16 +40,16 @@ namespace lgfx void waitDisplay(void) override; bool displayBusy(void) override; - void display(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h) override; + void display(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h) override; - void writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) override; - void writeImage(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param, bool use_dma) override; - void writePixels(pixelcopy_t* param, std::uint32_t len, bool use_dma) override; + void writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t rawcolor) override; + void writeImage(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param, bool use_dma) override; + void writePixels(pixelcopy_t* param, uint32_t len, bool use_dma) override; - std::uint32_t readCommand(std::uint_fast8_t cmd, std::uint_fast8_t index = 0, std::uint_fast8_t length = 4) override { return 0; } - std::uint32_t readData(std::uint_fast8_t index = 0, std::uint_fast8_t length = 4) override { return 0; } + uint32_t readCommand(uint_fast8_t, uint_fast8_t, uint_fast8_t) override { return 0; } + uint32_t readData(uint_fast8_t, uint_fast8_t) override { return 0; } - void readRect(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, void* dst, pixelcopy_t* param) override; + void readRect(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, void* dst, pixelcopy_t* param) override; private: @@ -58,18 +58,18 @@ namespace lgfx range_rect_t _range_old; unsigned long _send_msec = 0; - std::size_t _get_buffer_length(void) const override; + size_t _get_buffer_length(void) const override; - bool _wait_busy(std::uint32_t timeout = 1000); - void _draw_pixel(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t value); - bool _read_pixel(std::uint_fast16_t x, std::uint_fast16_t y); - void _update_transferred_rect(std::uint_fast16_t &xs, std::uint_fast16_t &ys, std::uint_fast16_t &xe, std::uint_fast16_t &ye); - void _exec_transfer(std::uint32_t cmd, const range_rect_t& range, bool invert = false); + bool _wait_busy(uint32_t timeout = 1000); + void _draw_pixel(uint_fast16_t x, uint_fast16_t y, uint32_t value); + bool _read_pixel(uint_fast16_t x, uint_fast16_t y); + void _update_transferred_rect(uint_fast16_t &xs, uint_fast16_t &ys, uint_fast16_t &xe, uint_fast16_t &ye); + void _exec_transfer(uint32_t cmd, const range_rect_t& range, bool invert = false); void _close_transfer(void); - const std::uint8_t* getInitCommands(std::uint8_t listno) const override + const uint8_t* getInitCommands(uint8_t listno) const override { - static constexpr std::uint8_t list0[] = { + static constexpr uint8_t list0[] = { 0x00,2,0xdf,0x0e, //panel setting 0x4D,1,0x55, //FITIinternal code 0xaa,1,0x0f, diff --git a/src/lgfx/v1/panel/Panel_HasBuffer.cpp b/src/lgfx/v1/panel/Panel_HasBuffer.cpp index 8a011db..24b698b 100644 --- a/src/lgfx/v1/panel/Panel_HasBuffer.cpp +++ b/src/lgfx/v1/panel/Panel_HasBuffer.cpp @@ -45,7 +45,7 @@ namespace lgfx auto len = _get_buffer_length(); if (_buf) heap_free(_buf); - _buf = static_cast(heap_alloc_dma(len)); + _buf = static_cast(heap_alloc_dma(len)); return ((_buf != nullptr) && (Panel_Device::init(use_reset))); } @@ -62,7 +62,7 @@ namespace lgfx cs_control(true); } - void Panel_HasBuffer::setRotation(std::uint_fast8_t r) + void Panel_HasBuffer::setRotation(uint_fast8_t r) { r &= 7; _rotation = r; @@ -73,7 +73,7 @@ namespace lgfx if (_internal_rotation & 1) std::swap(_width, _height); } - void Panel_HasBuffer::setWindow(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) + void Panel_HasBuffer::setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye) { _xpos = xs; _ypos = ys; @@ -83,7 +83,7 @@ namespace lgfx _ye = ye; } - void Panel_HasBuffer::drawPixelPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t rawcolor) + void Panel_HasBuffer::drawPixelPreclipped(uint_fast16_t x, uint_fast16_t y, uint32_t rawcolor) { /* bool need_transaction = !getStartCount(); @@ -96,17 +96,17 @@ namespace lgfx endWrite(); } - void Panel_HasBuffer::writeBlock(std::uint32_t rawcolor, std::uint32_t length) + void Panel_HasBuffer::writeBlock(uint32_t rawcolor, uint32_t length) { - std::uint32_t xs = _xs; - std::uint32_t xe = _xe; - std::uint32_t ys = _ys; - std::uint32_t ye = _ye; - std::uint32_t xpos = _xpos; - std::uint32_t ypos = _ypos; + uint32_t xs = _xs; + uint32_t xe = _xe; + uint32_t ys = _ys; + uint32_t ye = _ye; + uint32_t xpos = _xpos; + uint32_t ypos = _ypos; do { - auto len = std::min(length, xe + 1 - xpos); + auto len = std::min(length, xe + 1 - xpos); writeFillRectPreclipped(xpos, ypos, len, 1, rawcolor); xpos += len; if (xpos > xe) @@ -127,25 +127,25 @@ namespace lgfx _ypos = ypos; } - void Panel_HasBuffer::_rotate_pos(std::uint_fast16_t &x, std::uint_fast16_t &y) + void Panel_HasBuffer::_rotate_pos(uint_fast16_t &x, uint_fast16_t &y) { - std::uint_fast8_t r = _internal_rotation; + uint_fast8_t r = _internal_rotation; if (r) { if (r & 1) { std::swap(x, y); } - std::uint_fast8_t rb = 1 << r; + uint_fast8_t rb = 1 << r; if (rb & 0b11000110) { x = _cfg.panel_width - 1 - x; } // case 1:2:6:7: if (rb & 0b10011100) { y = _cfg.panel_height - 1 - y; } // case 2:3:4:7: } } - void Panel_HasBuffer::_rotate_pos(std::uint_fast16_t &xs, std::uint_fast16_t &ys, std::uint_fast16_t &xe, std::uint_fast16_t &ye) + void Panel_HasBuffer::_rotate_pos(uint_fast16_t &xs, uint_fast16_t &ys, uint_fast16_t &xe, uint_fast16_t &ye) { - std::uint_fast8_t r = _internal_rotation; + uint_fast8_t r = _internal_rotation; if (r) { if (r & 1) { std::swap(xs, ys); std::swap(xe, ye); } - std::uint_fast8_t rb = 1 << r; + uint_fast8_t rb = 1 << r; if (rb & 0b11000110) // case 1:2:6:7: { std::swap(xs, xe); diff --git a/src/lgfx/v1/panel/Panel_HasBuffer.hpp b/src/lgfx/v1/panel/Panel_HasBuffer.hpp index 0b05a04..26caa45 100644 --- a/src/lgfx/v1/panel/Panel_HasBuffer.hpp +++ b/src/lgfx/v1/panel/Panel_HasBuffer.hpp @@ -38,21 +38,21 @@ namespace lgfx void beginTransaction(void) override; void endTransaction(void) override; - void setRotation(std::uint_fast8_t r) override; + void setRotation(uint_fast8_t r) override; - void setWindow(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) override; - void drawPixelPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t rawcolor) override; - void writeBlock(std::uint32_t rawcolor, std::uint32_t length) override; + void setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye) override; + void drawPixelPreclipped(uint_fast16_t x, uint_fast16_t y, uint32_t rawcolor) override; + void writeBlock(uint32_t rawcolor, uint32_t length) override; protected: - std::uint8_t* _buf = nullptr; + uint8_t* _buf = nullptr; range_rect_t _range_mod; - std::int32_t _xpos = 0; - std::int32_t _ypos = 0; + int32_t _xpos = 0; + int32_t _ypos = 0; - virtual std::size_t _get_buffer_length(void) const = 0; - void _rotate_pos(std::uint_fast16_t &x, std::uint_fast16_t &y); - void _rotate_pos(std::uint_fast16_t &xs, std::uint_fast16_t &ys, std::uint_fast16_t &xe, std::uint_fast16_t &ye); + virtual size_t _get_buffer_length(void) const = 0; + void _rotate_pos(uint_fast16_t &x, uint_fast16_t &y); + void _rotate_pos(uint_fast16_t &xs, uint_fast16_t &ys, uint_fast16_t &xe, uint_fast16_t &ye); }; //---------------------------------------------------------------------------- diff --git a/src/lgfx/v1/panel/Panel_ILI9163.hpp b/src/lgfx/v1/panel/Panel_ILI9163.hpp index 9295aa6..00bcc02 100644 --- a/src/lgfx/v1/panel/Panel_ILI9163.hpp +++ b/src/lgfx/v1/panel/Panel_ILI9163.hpp @@ -36,24 +36,24 @@ namespace lgfx protected: - static constexpr std::uint8_t CMD_FRMCTR1 = 0xB1; - static constexpr std::uint8_t CMD_FRMCTR2 = 0xB2; - static constexpr std::uint8_t CMD_FRMCTR3 = 0xB3; - static constexpr std::uint8_t CMD_INVCTR = 0xB4; - static constexpr std::uint8_t CMD_DFUNCTR = 0xB6; - static constexpr std::uint8_t CMD_PWCTR1 = 0xC0; - static constexpr std::uint8_t CMD_PWCTR2 = 0xC1; - static constexpr std::uint8_t CMD_PWCTR3 = 0xC2; - static constexpr std::uint8_t CMD_PWCTR4 = 0xC3; - static constexpr std::uint8_t CMD_PWCTR5 = 0xC4; - static constexpr std::uint8_t CMD_VMCTR1 = 0xC5; - static constexpr std::uint8_t CMD_VMCTR2 = 0xC7; - static constexpr std::uint8_t CMD_GMCTRP1 = 0xE0; // Positive Gamma Correction (E0h) - static constexpr std::uint8_t CMD_GMCTRN1 = 0xE1; // Negative Gamma Correction (E1h) + static constexpr uint8_t CMD_FRMCTR1 = 0xB1; + static constexpr uint8_t CMD_FRMCTR2 = 0xB2; + static constexpr uint8_t CMD_FRMCTR3 = 0xB3; + static constexpr uint8_t CMD_INVCTR = 0xB4; + static constexpr uint8_t CMD_DFUNCTR = 0xB6; + static constexpr uint8_t CMD_PWCTR1 = 0xC0; + static constexpr uint8_t CMD_PWCTR2 = 0xC1; + static constexpr uint8_t CMD_PWCTR3 = 0xC2; + static constexpr uint8_t CMD_PWCTR4 = 0xC3; + static constexpr uint8_t CMD_PWCTR5 = 0xC4; + static constexpr uint8_t CMD_VMCTR1 = 0xC5; + static constexpr uint8_t CMD_VMCTR2 = 0xC7; + static constexpr uint8_t CMD_GMCTRP1 = 0xE0; // Positive Gamma Correction (E0h) + static constexpr uint8_t CMD_GMCTRN1 = 0xE1; // Negative Gamma Correction (E1h) - const std::uint8_t* getInitCommands(std::uint8_t listno) const override + const uint8_t* getInitCommands(uint8_t listno) const override { - static constexpr std::uint8_t list0[] = + static constexpr uint8_t list0[] = { CMD_FRMCTR1, 2, 0x08, 0x08, // Frame rate control 1 CMD_INVCTR , 1, 0x07, // Display inversion diff --git a/src/lgfx/v1/panel/Panel_ILI9225.cpp b/src/lgfx/v1/panel/Panel_ILI9225.cpp index c39ac24..aaf85d1 100644 --- a/src/lgfx/v1/panel/Panel_ILI9225.cpp +++ b/src/lgfx/v1/panel/Panel_ILI9225.cpp @@ -17,6 +17,7 @@ Original Source: /----------------------------------------------------------------------------*/ #include "Panel_ILI9225.hpp" +#include "../../internal/memory.h" #include "../Bus.hpp" namespace lgfx @@ -30,7 +31,7 @@ namespace lgfx _invert = invert; startWrite(); _bus->writeCommand(CMD_DISPLAY_CTRL1, 8); - std::uint_fast16_t data = (invert ^ _cfg.invert) + uint_fast16_t data = (invert ^ _cfg.invert) ? __builtin_bswap16(0x1013) : __builtin_bswap16(0x1017) ; @@ -42,7 +43,7 @@ namespace lgfx { startWrite(); _bus->writeCommand(CMD_POWER_CTRL1, 8); - std::uint_fast16_t data = flg + uint_fast16_t data = flg ? __builtin_bswap16(0x0802) : __builtin_bswap16(0x0800) ; @@ -54,7 +55,7 @@ namespace lgfx { startWrite(); _bus->writeCommand(CMD_POWER_CTRL1, 8); - std::uint_fast16_t data = flg + uint_fast16_t data = flg ? __builtin_bswap16(0x0801) : __builtin_bswap16(0x0800) ; @@ -62,12 +63,12 @@ namespace lgfx endWrite(); } - void Panel_ILI9225::setWindow(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) + void Panel_ILI9225::setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye) { set_window(xs, ys, xe, ye, CMD_RAMWR); } - void Panel_ILI9225::drawPixelPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t rawcolor) + void Panel_ILI9225::drawPixelPreclipped(uint_fast16_t x, uint_fast16_t y, uint32_t rawcolor) { bool tr = _in_transaction; if (!tr) begin_transaction(); @@ -78,11 +79,11 @@ namespace lgfx if (!tr) end_transaction(); } - void Panel_ILI9225::writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) + void Panel_ILI9225::writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t rawcolor) { - std::uint32_t len = w * h; - std::uint_fast16_t xe = w + x - 1; - std::uint_fast16_t ye = y + h - 1; + uint32_t len = w * h; + uint_fast16_t xe = w + x - 1; + uint_fast16_t ye = y + h - 1; set_window(x, y, xe, ye, CMD_RAMWR); _bus->writeDataRepeat(rawcolor, _write_bits, len); } @@ -97,7 +98,7 @@ namespace lgfx return _write_depth; } - void Panel_ILI9225::setRotation(std::uint_fast8_t r) + void Panel_ILI9225::setRotation(uint_fast8_t r) { r &= 7; _rotation = r; @@ -139,7 +140,7 @@ namespace lgfx endWrite(); } - void Panel_ILI9225::set_window(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye, std::uint32_t cmd) + void Panel_ILI9225::set_window(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye, uint32_t cmd) { if (_internal_rotation & 1) { @@ -147,7 +148,7 @@ namespace lgfx std::swap(xe, ye); } - std::uint_fast8_t rb = 1u << _internal_rotation; + uint_fast8_t rb = 1u << _internal_rotation; if (xs != _xs || xe != _xe) { auto tmp = xs; diff --git a/src/lgfx/v1/panel/Panel_ILI9225.hpp b/src/lgfx/v1/panel/Panel_ILI9225.hpp index a8fb773..0ae688a 100644 --- a/src/lgfx/v1/panel/Panel_ILI9225.hpp +++ b/src/lgfx/v1/panel/Panel_ILI9225.hpp @@ -39,36 +39,36 @@ namespace lgfx void setSleep(bool flg) override; void setPowerSave(bool flg) override; - void setWindow(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) override; - void drawPixelPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t rawcolor) override; - void writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) override; + void setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye) override; + void drawPixelPreclipped(uint_fast16_t x, uint_fast16_t y, uint32_t rawcolor) override; + void writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t rawcolor) override; color_depth_t setColorDepth(color_depth_t depth) override; - void setRotation(std::uint_fast8_t r) override; + void setRotation(uint_fast8_t r) override; protected: void update_madctl(void); - void set_window(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye, std::uint32_t cmd); - - static constexpr std::uint8_t CMD_RAMWR = 0x22; - - static constexpr std::uint8_t CMD_H_ADDR1 = 0x36; - static constexpr std::uint8_t CMD_H_ADDR2 = 0x37; - static constexpr std::uint8_t CMD_V_ADDR1 = 0x38; - static constexpr std::uint8_t CMD_V_ADDR2 = 0x39; - static constexpr std::uint8_t CMD_OUTPUT_CTRL = 0x01; - static constexpr std::uint8_t CMD_ENTRY_MODE = 0x03; - static constexpr std::uint8_t CMD_POWER_CTRL1 = 0x10; - static constexpr std::uint8_t CMD_POWER_CTRL2 = 0x11; - static constexpr std::uint8_t CMD_POWER_CTRL3 = 0x12; - static constexpr std::uint8_t CMD_POWER_CTRL4 = 0x13; - static constexpr std::uint8_t CMD_POWER_CTRL5 = 0x14; - static constexpr std::uint8_t CMD_DISPLAY_CTRL1 = 0x07; - - const std::uint8_t* getInitCommands(std::uint8_t listno) const override + void set_window(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye, uint32_t cmd); + + static constexpr uint8_t CMD_RAMWR = 0x22; + + static constexpr uint8_t CMD_H_ADDR1 = 0x36; + static constexpr uint8_t CMD_H_ADDR2 = 0x37; + static constexpr uint8_t CMD_V_ADDR1 = 0x38; + static constexpr uint8_t CMD_V_ADDR2 = 0x39; + static constexpr uint8_t CMD_OUTPUT_CTRL = 0x01; + static constexpr uint8_t CMD_ENTRY_MODE = 0x03; + static constexpr uint8_t CMD_POWER_CTRL1 = 0x10; + static constexpr uint8_t CMD_POWER_CTRL2 = 0x11; + static constexpr uint8_t CMD_POWER_CTRL3 = 0x12; + static constexpr uint8_t CMD_POWER_CTRL4 = 0x13; + static constexpr uint8_t CMD_POWER_CTRL5 = 0x14; + static constexpr uint8_t CMD_DISPLAY_CTRL1 = 0x07; + + const uint8_t* getInitCommands(uint8_t listno) const override { - static constexpr std::uint8_t list0[] = + static constexpr uint8_t list0[] = { CMD_POWER_CTRL2 , 2, 0x00, 0x18, CMD_POWER_CTRL3 , 2, 0x61, 0x21, diff --git a/src/lgfx/v1/panel/Panel_ILI9341.hpp b/src/lgfx/v1/panel/Panel_ILI9341.hpp index 8258c0c..2270f01 100644 --- a/src/lgfx/v1/panel/Panel_ILI9341.hpp +++ b/src/lgfx/v1/panel/Panel_ILI9341.hpp @@ -35,26 +35,26 @@ namespace lgfx protected: - static constexpr std::uint8_t CMD_FRMCTR1 = 0xB1; - static constexpr std::uint8_t CMD_FRMCTR2 = 0xB2; - static constexpr std::uint8_t CMD_FRMCTR3 = 0xB3; - static constexpr std::uint8_t CMD_INVCTR = 0xB4; - static constexpr std::uint8_t CMD_DFUNCTR = 0xB6; - static constexpr std::uint8_t CMD_PWCTR1 = 0xC0; - static constexpr std::uint8_t CMD_PWCTR2 = 0xC1; - static constexpr std::uint8_t CMD_PWCTR3 = 0xC2; - static constexpr std::uint8_t CMD_PWCTR4 = 0xC3; - static constexpr std::uint8_t CMD_PWCTR5 = 0xC4; - static constexpr std::uint8_t CMD_VMCTR1 = 0xC5; - static constexpr std::uint8_t CMD_VMCTR2 = 0xC7; - static constexpr std::uint8_t CMD_GMCTRP1 = 0xE0; // Positive Gamma Correction (E0h) - static constexpr std::uint8_t CMD_GMCTRN1 = 0xE1; // Negative Gamma Correction (E1h) - static constexpr std::uint8_t CMD_RDINDEX = 0xD9; // ili9341 - static constexpr std::uint8_t CMD_IDXRD = 0xDD; // ILI9341 only, indexed control register read + static constexpr uint8_t CMD_FRMCTR1 = 0xB1; + static constexpr uint8_t CMD_FRMCTR2 = 0xB2; + static constexpr uint8_t CMD_FRMCTR3 = 0xB3; + static constexpr uint8_t CMD_INVCTR = 0xB4; + static constexpr uint8_t CMD_DFUNCTR = 0xB6; + static constexpr uint8_t CMD_PWCTR1 = 0xC0; + static constexpr uint8_t CMD_PWCTR2 = 0xC1; + static constexpr uint8_t CMD_PWCTR3 = 0xC2; + static constexpr uint8_t CMD_PWCTR4 = 0xC3; + static constexpr uint8_t CMD_PWCTR5 = 0xC4; + static constexpr uint8_t CMD_VMCTR1 = 0xC5; + static constexpr uint8_t CMD_VMCTR2 = 0xC7; + static constexpr uint8_t CMD_GMCTRP1 = 0xE0; // Positive Gamma Correction (E0h) + static constexpr uint8_t CMD_GMCTRN1 = 0xE1; // Negative Gamma Correction (E1h) + static constexpr uint8_t CMD_RDINDEX = 0xD9; // ili9341 + static constexpr uint8_t CMD_IDXRD = 0xDD; // ILI9341 only, indexed control register read - const std::uint8_t* getInitCommands(std::uint8_t listno) const override + const uint8_t* getInitCommands(uint8_t listno) const override { - static constexpr std::uint8_t list0[] = + static constexpr uint8_t list0[] = { 0xEF , 3, 0x03,0x80,0x02, 0xCF , 3, 0x00,0xC1,0x30, diff --git a/src/lgfx/v1/panel/Panel_ILI9342.hpp b/src/lgfx/v1/panel/Panel_ILI9342.hpp index 75fc176..8358e87 100644 --- a/src/lgfx/v1/panel/Panel_ILI9342.hpp +++ b/src/lgfx/v1/panel/Panel_ILI9342.hpp @@ -35,17 +35,17 @@ namespace lgfx protected: - static constexpr std::uint8_t CMD_DFUNCTR = 0xB6; - static constexpr std::uint8_t CMD_PWCTR1 = 0xC0; - static constexpr std::uint8_t CMD_PWCTR2 = 0xC1; - static constexpr std::uint8_t CMD_VMCTR1 = 0xC5; - static constexpr std::uint8_t CMD_SETEXTC = 0xC8; - static constexpr std::uint8_t CMD_GMCTRP1 = 0xE0; // Positive Gamma Correction (E0h) - static constexpr std::uint8_t CMD_GMCTRN1 = 0xE1; // Negative Gamma Correction (E1h) + static constexpr uint8_t CMD_DFUNCTR = 0xB6; + static constexpr uint8_t CMD_PWCTR1 = 0xC0; + static constexpr uint8_t CMD_PWCTR2 = 0xC1; + static constexpr uint8_t CMD_VMCTR1 = 0xC5; + static constexpr uint8_t CMD_SETEXTC = 0xC8; + static constexpr uint8_t CMD_GMCTRP1 = 0xE0; // Positive Gamma Correction (E0h) + static constexpr uint8_t CMD_GMCTRN1 = 0xE1; // Negative Gamma Correction (E1h) - const std::uint8_t* getInitCommands(std::uint8_t listno) const override + const uint8_t* getInitCommands(uint8_t listno) const override { - static constexpr std::uint8_t list0[] = + static constexpr uint8_t list0[] = { CMD_SETEXTC, 3, 0xFF,0x93,0x42, // Turn on the external command CMD_PWCTR1 , 2, 0x12, 0x12, diff --git a/src/lgfx/v1/panel/Panel_ILI948x.hpp b/src/lgfx/v1/panel/Panel_ILI948x.hpp index d4701ba..e5f2d45 100644 --- a/src/lgfx/v1/panel/Panel_ILI948x.hpp +++ b/src/lgfx/v1/panel/Panel_ILI948x.hpp @@ -36,7 +36,7 @@ namespace lgfx } void setColorDepth_impl(color_depth_t depth) override - { // ILI9481,ILI9486,ILI9488 は SPIバス接続時は16bppが使用できない + { // ILI9481,ILI9486 は SPIバス接続時は16bppが使用できない (ILI9486 spec Page 125 of 312) _write_depth = (((int)depth & color_depth_t::bit_mask) > 16 || (_bus && _bus->busType() == bus_spi)) ? rgb888_3Byte @@ -52,17 +52,17 @@ namespace lgfx { protected: - static constexpr std::uint8_t CMD_PNLDRV = 0xC0; - static constexpr std::uint8_t CMD_FRMCTR = 0xC5; - static constexpr std::uint8_t CMD_IFCTR = 0xC6; - static constexpr std::uint8_t CMD_PWSET = 0xD0; - static constexpr std::uint8_t CMD_VMCTR = 0xD1; - static constexpr std::uint8_t CMD_PWSETN = 0xD2; - static constexpr std::uint8_t CMD_GMCTR = 0xC8; + static constexpr uint8_t CMD_PNLDRV = 0xC0; + static constexpr uint8_t CMD_FRMCTR = 0xC5; + static constexpr uint8_t CMD_IFCTR = 0xC6; + static constexpr uint8_t CMD_PWSET = 0xD0; + static constexpr uint8_t CMD_VMCTR = 0xD1; + static constexpr uint8_t CMD_PWSETN = 0xD2; + static constexpr uint8_t CMD_GMCTR = 0xC8; - const std::uint8_t* getInitCommands(std::uint8_t listno) const override + const uint8_t* getInitCommands(uint8_t listno) const override { - static constexpr std::uint8_t list0[] = + static constexpr uint8_t list0[] = { CMD_SLPOUT , 0+CMD_INIT_DELAY, 120, // Exit sleep mode CMD_PWSET , 3, 0x07, 0x40, 0x1D, @@ -84,9 +84,9 @@ namespace lgfx } } - std::uint8_t getMadCtl(std::uint8_t r) const override + uint8_t getMadCtl(uint8_t r) const override { - static constexpr std::uint8_t madctl_table[] = + static constexpr uint8_t madctl_table[] = { MAD_HF , MAD_MV , @@ -107,26 +107,26 @@ namespace lgfx { protected: - static constexpr std::uint8_t CMD_FRMCTR1 = 0xB1; - static constexpr std::uint8_t CMD_FRMCTR2 = 0xB2; - static constexpr std::uint8_t CMD_FRMCTR3 = 0xB3; - static constexpr std::uint8_t CMD_INVCTR = 0xB4; - static constexpr std::uint8_t CMD_DFUNCTR = 0xB6; - static constexpr std::uint8_t CMD_ETMOD = 0xB7; - static constexpr std::uint8_t CMD_PWCTR1 = 0xC0; - static constexpr std::uint8_t CMD_PWCTR2 = 0xC1; - static constexpr std::uint8_t CMD_PWCTR3 = 0xC2; - static constexpr std::uint8_t CMD_PWCTR4 = 0xC3; - static constexpr std::uint8_t CMD_PWCTR5 = 0xC4; - static constexpr std::uint8_t CMD_VMCTR1 = 0xC5; - static constexpr std::uint8_t CMD_VMCTR2 = 0xC7; - static constexpr std::uint8_t CMD_GMCTRP1 = 0xE0; // Positive Gamma Correction - static constexpr std::uint8_t CMD_GMCTRN1 = 0xE1; // Negative Gamma Correction - static constexpr std::uint8_t CMD_ADJCTL3 = 0xF7; - - const std::uint8_t* getInitCommands(std::uint8_t listno) const override + static constexpr uint8_t CMD_FRMCTR1 = 0xB1; + static constexpr uint8_t CMD_FRMCTR2 = 0xB2; + static constexpr uint8_t CMD_FRMCTR3 = 0xB3; + static constexpr uint8_t CMD_INVCTR = 0xB4; + static constexpr uint8_t CMD_DFUNCTR = 0xB6; + static constexpr uint8_t CMD_ETMOD = 0xB7; + static constexpr uint8_t CMD_PWCTR1 = 0xC0; + static constexpr uint8_t CMD_PWCTR2 = 0xC1; + static constexpr uint8_t CMD_PWCTR3 = 0xC2; + static constexpr uint8_t CMD_PWCTR4 = 0xC3; + static constexpr uint8_t CMD_PWCTR5 = 0xC4; + static constexpr uint8_t CMD_VMCTR1 = 0xC5; + static constexpr uint8_t CMD_VMCTR2 = 0xC7; + static constexpr uint8_t CMD_GMCTRP1 = 0xE0; // Positive Gamma Correction + static constexpr uint8_t CMD_GMCTRN1 = 0xE1; // Negative Gamma Correction + static constexpr uint8_t CMD_ADJCTL3 = 0xF7; + + const uint8_t* getInitCommands(uint8_t listno) const override { - static constexpr std::uint8_t list0[] = + static constexpr uint8_t list0[] = { CMD_PWCTR1, 2, 0x17, // VRH1 0x15, // VRH2 @@ -168,27 +168,37 @@ namespace lgfx struct Panel_ILI9488 : public Panel_ILI948x { + void setColorDepth_impl(color_depth_t depth) override + { + _write_depth = (((int)depth & color_depth_t::bit_mask) > 16 + || (_bus && _bus->busType() == bus_spi)) + ? rgb888_3Byte + : rgb565_2Byte; + + _read_depth = rgb888_3Byte; + } + protected: - static constexpr std::uint8_t CMD_FRMCTR1 = 0xB1; - static constexpr std::uint8_t CMD_FRMCTR2 = 0xB2; - static constexpr std::uint8_t CMD_FRMCTR3 = 0xB3; - static constexpr std::uint8_t CMD_INVCTR = 0xB4; - static constexpr std::uint8_t CMD_DFUNCTR = 0xB6; - static constexpr std::uint8_t CMD_ETMOD = 0xB7; - static constexpr std::uint8_t CMD_PWCTR1 = 0xC0; - static constexpr std::uint8_t CMD_PWCTR2 = 0xC1; - static constexpr std::uint8_t CMD_PWCTR3 = 0xC2; - static constexpr std::uint8_t CMD_PWCTR4 = 0xC3; - static constexpr std::uint8_t CMD_PWCTR5 = 0xC4; - static constexpr std::uint8_t CMD_VMCTR = 0xC5; - static constexpr std::uint8_t CMD_GMCTRP1 = 0xE0; // Positive Gamma Correction - static constexpr std::uint8_t CMD_GMCTRN1 = 0xE1; // Negative Gamma Correction - static constexpr std::uint8_t CMD_ADJCTL3 = 0xF7; - - const std::uint8_t* getInitCommands(std::uint8_t listno) const override + static constexpr uint8_t CMD_FRMCTR1 = 0xB1; + static constexpr uint8_t CMD_FRMCTR2 = 0xB2; + static constexpr uint8_t CMD_FRMCTR3 = 0xB3; + static constexpr uint8_t CMD_INVCTR = 0xB4; + static constexpr uint8_t CMD_DFUNCTR = 0xB6; + static constexpr uint8_t CMD_ETMOD = 0xB7; + static constexpr uint8_t CMD_PWCTR1 = 0xC0; + static constexpr uint8_t CMD_PWCTR2 = 0xC1; + static constexpr uint8_t CMD_PWCTR3 = 0xC2; + static constexpr uint8_t CMD_PWCTR4 = 0xC3; + static constexpr uint8_t CMD_PWCTR5 = 0xC4; + static constexpr uint8_t CMD_VMCTR = 0xC5; + static constexpr uint8_t CMD_GMCTRP1 = 0xE0; // Positive Gamma Correction + static constexpr uint8_t CMD_GMCTRN1 = 0xE1; // Negative Gamma Correction + static constexpr uint8_t CMD_ADJCTL3 = 0xF7; + + const uint8_t* getInitCommands(uint8_t listno) const override { - static constexpr std::uint8_t list0[] = + static constexpr uint8_t list0[] = { CMD_PWCTR1, 2, 0x17, // VRH1 0x15, // VRH2 @@ -225,19 +235,19 @@ namespace lgfx { protected: - static constexpr std::uint8_t CMD_SETEXTC = 0xB0; - static constexpr std::uint8_t CMD_SETDISPMODE = 0xB4; - static constexpr std::uint8_t CMD_SET_PANEL_DRIVING = 0xC0; - static constexpr std::uint8_t CMD_SETDISPLAYFRAME = 0xC5; - static constexpr std::uint8_t CMD_SETGAMMA = 0xC8; - static constexpr std::uint8_t CMD_SETPOWER = 0xD0; - static constexpr std::uint8_t CMD_SETVCOM = 0xD1; - static constexpr std::uint8_t CMD_SETPWRNORMAL = 0xD2; - static constexpr std::uint8_t CMD_SETPANELRELATED = 0xE9; - - const std::uint8_t* getInitCommands(std::uint8_t listno) const override + static constexpr uint8_t CMD_SETEXTC = 0xB0; + static constexpr uint8_t CMD_SETDISPMODE = 0xB4; + static constexpr uint8_t CMD_SET_PANEL_DRIVING = 0xC0; + static constexpr uint8_t CMD_SETDISPLAYFRAME = 0xC5; + static constexpr uint8_t CMD_SETGAMMA = 0xC8; + static constexpr uint8_t CMD_SETPOWER = 0xD0; + static constexpr uint8_t CMD_SETVCOM = 0xD1; + static constexpr uint8_t CMD_SETPWRNORMAL = 0xD2; + static constexpr uint8_t CMD_SETPANELRELATED = 0xE9; + + const uint8_t* getInitCommands(uint8_t listno) const override { - static constexpr std::uint8_t list0[] = + static constexpr uint8_t list0[] = { CMD_SETEXTC, 1, 0x00, CMD_SETPOWER, 3, 0x44, 0x41, 0x06, @@ -269,21 +279,21 @@ namespace lgfx { protected: - static constexpr std::uint8_t CMD_TEON = 0x35; - static constexpr std::uint8_t CMD_TEARLINE= 0x44; - static constexpr std::uint8_t CMD_SETOSC = 0xB0; - static constexpr std::uint8_t CMD_SETPWR1 = 0xB1; - static constexpr std::uint8_t CMD_SETRGB = 0xB3; - static constexpr std::uint8_t CMD_SETCYC = 0xB4; - static constexpr std::uint8_t CMD_SETCOM = 0xB6; - static constexpr std::uint8_t CMD_SETC = 0xB9; - static constexpr std::uint8_t CMD_SETSTBA = 0xC0; - static constexpr std::uint8_t CMD_SETPANEL= 0xCC; - static constexpr std::uint8_t CMD_SETGAMMA= 0xE0; - - const std::uint8_t* getInitCommands(std::uint8_t listno) const override + static constexpr uint8_t CMD_TEON = 0x35; + static constexpr uint8_t CMD_TEARLINE= 0x44; + static constexpr uint8_t CMD_SETOSC = 0xB0; + static constexpr uint8_t CMD_SETPWR1 = 0xB1; + static constexpr uint8_t CMD_SETRGB = 0xB3; + static constexpr uint8_t CMD_SETCYC = 0xB4; + static constexpr uint8_t CMD_SETCOM = 0xB6; + static constexpr uint8_t CMD_SETC = 0xB9; + static constexpr uint8_t CMD_SETSTBA = 0xC0; + static constexpr uint8_t CMD_SETPANEL= 0xCC; + static constexpr uint8_t CMD_SETGAMMA= 0xE0; + + const uint8_t* getInitCommands(uint8_t listno) const override { - static constexpr std::uint8_t list0[] = + static constexpr uint8_t list0[] = { CMD_SWRESET , CMD_INIT_DELAY, 20, CMD_SETC , 3+CMD_INIT_DELAY, 0xFF, 0x83, 0x57, 100, diff --git a/src/lgfx/v1/panel/Panel_IT8951.cpp b/src/lgfx/v1/panel/Panel_IT8951.cpp index 35562ae..564a7ed 100644 --- a/src/lgfx/v1/panel/Panel_IT8951.cpp +++ b/src/lgfx/v1/panel/Panel_IT8951.cpp @@ -26,74 +26,74 @@ namespace lgfx { //---------------------------------------------------------------------------- - static constexpr std::int8_t Bayer[16] = {-30, 2, -22, 10, 18, -14, 26, -6, -18, 14, -26, 6, 30, -2, 22, -10}; + static constexpr int8_t Bayer[16] = {-30, 2, -22, 10, 18, -14, 26, -6, -18, 14, -26, 6, 30, -2, 22, -10}; - static constexpr std::uint32_t _tar_memaddr = 0x001236E0; + static constexpr uint32_t _tar_memaddr = 0x001236E0; //Built in I80 Command Code - static constexpr std::uint32_t IT8951_TCON_SYS_RUN = 0x0001; - static constexpr std::uint32_t IT8951_TCON_STANDBY = 0x0002; - static constexpr std::uint32_t IT8951_TCON_SLEEP = 0x0003; - static constexpr std::uint32_t IT8951_TCON_REG_RD = 0x0010; - static constexpr std::uint32_t IT8951_TCON_REG_WR = 0x0011; - static constexpr std::uint32_t IT8951_TCON_MEM_BST_RD_T = 0x0012; - static constexpr std::uint32_t IT8951_TCON_MEM_BST_RD_S = 0x0013; - static constexpr std::uint32_t IT8951_TCON_MEM_BST_WR = 0x0014; - static constexpr std::uint32_t IT8951_TCON_MEM_BST_END = 0x0015; - static constexpr std::uint32_t IT8951_TCON_LD_IMG = 0x0020; - static constexpr std::uint32_t IT8951_TCON_LD_IMG_AREA = 0x0021; - static constexpr std::uint32_t IT8951_TCON_LD_IMG_END = 0x0022; + static constexpr uint32_t IT8951_TCON_SYS_RUN = 0x0001; + static constexpr uint32_t IT8951_TCON_STANDBY = 0x0002; + static constexpr uint32_t IT8951_TCON_SLEEP = 0x0003; + static constexpr uint32_t IT8951_TCON_REG_RD = 0x0010; + static constexpr uint32_t IT8951_TCON_REG_WR = 0x0011; + static constexpr uint32_t IT8951_TCON_MEM_BST_RD_T = 0x0012; + static constexpr uint32_t IT8951_TCON_MEM_BST_RD_S = 0x0013; + static constexpr uint32_t IT8951_TCON_MEM_BST_WR = 0x0014; + static constexpr uint32_t IT8951_TCON_MEM_BST_END = 0x0015; + static constexpr uint32_t IT8951_TCON_LD_IMG = 0x0020; + static constexpr uint32_t IT8951_TCON_LD_IMG_AREA = 0x0021; + static constexpr uint32_t IT8951_TCON_LD_IMG_END = 0x0022; //I80 User defined command code - static constexpr std::uint32_t IT8951_I80_CMD_DPY_AREA = 0x0034; - static constexpr std::uint32_t IT8951_I80_CMD_GET_DEV_INFO = 0x0302; - static constexpr std::uint32_t IT8951_I80_CMD_DPY_BUF_AREA = 0x0037; - static constexpr std::uint32_t IT8951_I80_CMD_VCOM = 0x0039; - static constexpr std::uint32_t IT8951_I80_CMD_FILLRECT = 0x003A; - - static constexpr std::uint32_t IT8951_ROTATE_0 = 0; - static constexpr std::uint32_t IT8951_ROTATE_90 = 1; - static constexpr std::uint32_t IT8951_ROTATE_180 = 2; - static constexpr std::uint32_t IT8951_ROTATE_270 = 3; - - static constexpr std::uint32_t IT8951_2BPP = 0; - static constexpr std::uint32_t IT8951_3BPP = 1; - static constexpr std::uint32_t IT8951_4BPP = 2; - static constexpr std::uint32_t IT8951_8BPP = 3; - static constexpr std::uint32_t IT8951_LDIMG_B_ENDIAN = 1; + static constexpr uint32_t IT8951_I80_CMD_DPY_AREA = 0x0034; + static constexpr uint32_t IT8951_I80_CMD_GET_DEV_INFO = 0x0302; + static constexpr uint32_t IT8951_I80_CMD_DPY_BUF_AREA = 0x0037; + static constexpr uint32_t IT8951_I80_CMD_VCOM = 0x0039; + static constexpr uint32_t IT8951_I80_CMD_FILLRECT = 0x003A; + + static constexpr uint32_t IT8951_ROTATE_0 = 0; + static constexpr uint32_t IT8951_ROTATE_90 = 1; + static constexpr uint32_t IT8951_ROTATE_180 = 2; + static constexpr uint32_t IT8951_ROTATE_270 = 3; + + static constexpr uint32_t IT8951_2BPP = 0; + static constexpr uint32_t IT8951_3BPP = 1; + static constexpr uint32_t IT8951_4BPP = 2; + static constexpr uint32_t IT8951_8BPP = 3; + static constexpr uint32_t IT8951_LDIMG_B_ENDIAN = 1; /*----------------------------------------------------------------------- IT8951 Registers defines ------------------------------------------------------------------------*/ //Register Base Address - static constexpr std::uint32_t IT8951_DISPLAY_REG_BASE = 0x1000; //Register RW access + static constexpr uint32_t IT8951_DISPLAY_REG_BASE = 0x1000; //Register RW access //Base Address of Basic LUT Registers - static constexpr std::uint32_t IT8951_LUT0EWHR = (IT8951_DISPLAY_REG_BASE + 0x0000); //LUT0 Engine Width Height Reg - static constexpr std::uint32_t IT8951_LUT0XYR = (IT8951_DISPLAY_REG_BASE + 0x0040); //LUT0 XY Reg - static constexpr std::uint32_t IT8951_LUT0BADDR = (IT8951_DISPLAY_REG_BASE + 0x0080); //LUT0 Base Address Reg - static constexpr std::uint32_t IT8951_LUT0MFN = (IT8951_DISPLAY_REG_BASE + 0x00C0); //LUT0 Mode and Frame number Reg - static constexpr std::uint32_t IT8951_LUT01AF = (IT8951_DISPLAY_REG_BASE + 0x0114); //LUT0 and LUT1 Active Flag Reg + static constexpr uint32_t IT8951_LUT0EWHR = (IT8951_DISPLAY_REG_BASE + 0x0000); //LUT0 Engine Width Height Reg + static constexpr uint32_t IT8951_LUT0XYR = (IT8951_DISPLAY_REG_BASE + 0x0040); //LUT0 XY Reg + static constexpr uint32_t IT8951_LUT0BADDR = (IT8951_DISPLAY_REG_BASE + 0x0080); //LUT0 Base Address Reg + static constexpr uint32_t IT8951_LUT0MFN = (IT8951_DISPLAY_REG_BASE + 0x00C0); //LUT0 Mode and Frame number Reg + static constexpr uint32_t IT8951_LUT01AF = (IT8951_DISPLAY_REG_BASE + 0x0114); //LUT0 and LUT1 Active Flag Reg //Update Parameter Setting Register - static constexpr std::uint32_t IT8951_UP0SR = (IT8951_DISPLAY_REG_BASE + 0x134); //Update Parameter0 Setting Reg - static constexpr std::uint32_t IT8951_UP1SR = (IT8951_DISPLAY_REG_BASE + 0x138); //Update Parameter1 Setting Reg - static constexpr std::uint32_t IT8951_LUT0ABFRV = (IT8951_DISPLAY_REG_BASE + 0x13C); //LUT0 Alpha blend and Fill rectangle Value - static constexpr std::uint32_t IT8951_UPBBADDR = (IT8951_DISPLAY_REG_BASE + 0x17C); //Update Buffer Base Address - static constexpr std::uint32_t IT8951_LUT0IMXY = (IT8951_DISPLAY_REG_BASE + 0x180); //LUT0 Image buffer X/Y offset Reg - static constexpr std::uint32_t IT8951_LUTAFSR = (IT8951_DISPLAY_REG_BASE + 0x224); //LUT Status Reg (status of All LUT Engines) - static constexpr std::uint32_t IT8951_BGVR = (IT8951_DISPLAY_REG_BASE + 0x250); //Bitmap (1bpp) image color table + static constexpr uint32_t IT8951_UP0SR = (IT8951_DISPLAY_REG_BASE + 0x134); //Update Parameter0 Setting Reg + static constexpr uint32_t IT8951_UP1SR = (IT8951_DISPLAY_REG_BASE + 0x138); //Update Parameter1 Setting Reg + static constexpr uint32_t IT8951_LUT0ABFRV = (IT8951_DISPLAY_REG_BASE + 0x13C); //LUT0 Alpha blend and Fill rectangle Value + static constexpr uint32_t IT8951_UPBBADDR = (IT8951_DISPLAY_REG_BASE + 0x17C); //Update Buffer Base Address + static constexpr uint32_t IT8951_LUT0IMXY = (IT8951_DISPLAY_REG_BASE + 0x180); //LUT0 Image buffer X/Y offset Reg + static constexpr uint32_t IT8951_LUTAFSR = (IT8951_DISPLAY_REG_BASE + 0x224); //LUT Status Reg (status of All LUT Engines) + static constexpr uint32_t IT8951_BGVR = (IT8951_DISPLAY_REG_BASE + 0x250); //Bitmap (1bpp) image color table //System Registers - static constexpr std::uint32_t IT8951_SYS_REG_BASE = 0x0000; + static constexpr uint32_t IT8951_SYS_REG_BASE = 0x0000; //Address of System Registers - static constexpr std::uint32_t IT8951_I80CPCR = (IT8951_SYS_REG_BASE + 0x04); + static constexpr uint32_t IT8951_I80CPCR = (IT8951_SYS_REG_BASE + 0x04); //Memory Converter Registers - static constexpr std::uint32_t IT8951_MCSR_BASE_ADDR = 0x0200; - static constexpr std::uint32_t IT8951_MCSR = (IT8951_MCSR_BASE_ADDR + 0x0000); - static constexpr std::uint32_t IT8951_LISAR = (IT8951_MCSR_BASE_ADDR + 0x0008); + static constexpr uint32_t IT8951_MCSR_BASE_ADDR = 0x0200; + static constexpr uint32_t IT8951_MCSR = (IT8951_MCSR_BASE_ADDR + 0x0000); + static constexpr uint32_t IT8951_LISAR = (IT8951_MCSR_BASE_ADDR + 0x0008); Panel_IT8951::Panel_IT8951(void) @@ -166,7 +166,7 @@ IT8951 Registers defines cs_control(true); } - bool Panel_IT8951::_wait_busy(std::uint32_t timeout) + bool Panel_IT8951::_wait_busy(uint32_t timeout) { _bus->wait(); cs_control(true); @@ -194,7 +194,7 @@ IT8951 Registers defines bool Panel_IT8951::displayBusy(void) { - std::uint16_t infobuf[1] = { 1 }; + uint16_t infobuf[1] = { 1 }; if (_write_command(IT8951_TCON_REG_RD) && _write_word(IT8951_LUTAFSR) && _read_words(infobuf, 1)) @@ -207,8 +207,8 @@ IT8951 Registers defines bool Panel_IT8951::_check_afsr(void) { - std::uint32_t start_time = millis(); - std::uint16_t infobuf[1] = { 1 }; + uint32_t start_time = millis(); + uint16_t infobuf[1] = { 1 }; do { if (_write_command(IT8951_TCON_REG_RD) @@ -226,32 +226,32 @@ IT8951 Registers defines return infobuf[0] != 0; } - bool Panel_IT8951::_write_command(std::uint16_t cmd) + bool Panel_IT8951::_write_command(uint16_t cmd) { - std::uint32_t buf = __builtin_bswap16(0x6000) | __builtin_bswap16(cmd) << 16; + uint32_t buf = __builtin_bswap16(0x6000) | __builtin_bswap16(cmd) << 16; if (!_wait_busy()) return false; _bus->writeData(buf, 32); return true; } - bool Panel_IT8951::_write_word(std::uint16_t data) + bool Panel_IT8951::_write_word(uint16_t data) { - std::uint32_t buf = __builtin_bswap16(data) << 16; + uint32_t buf = __builtin_bswap16(data) << 16; if (!_wait_busy()) return false; _bus->writeData(buf, 32); return true; } - bool Panel_IT8951::_write_args(std::uint16_t cmd, std::uint16_t *args, std::int32_t length) + bool Panel_IT8951::_write_args(uint16_t cmd, uint16_t *args, int32_t length) { if (_write_command(cmd) && _wait_busy()) { _bus->writeData(0, 16); - std::int32_t i = 0; + int32_t i = 0; do { - std::uint32_t buf = __builtin_bswap16(args[i]); + uint32_t buf = __builtin_bswap16(args[i]); _bus->wait(); while (!lgfx::gpio_in(_cfg.pin_busy)); _bus->writeData(buf, 16); @@ -261,12 +261,12 @@ IT8951 Registers defines return false; } - bool Panel_IT8951::_read_words(std::uint16_t *buf, std::uint32_t length) + bool Panel_IT8951::_read_words(uint16_t *buf, uint32_t length) { if (!_wait_busy()) return false; _bus->writeData(__builtin_bswap16(0x1000), 16 + 16); // +16 dummy read _bus->beginRead(); - _bus->readBytes(reinterpret_cast(buf), length << 1); + _bus->readBytes(reinterpret_cast(buf), length << 1); _bus->endRead(); cs_control(true); for (size_t i = 0; i < length; i++) @@ -276,22 +276,22 @@ IT8951 Registers defines return true; } - bool Panel_IT8951::_write_reg(std::uint16_t addr, std::uint16_t data) + bool Panel_IT8951::_write_reg(uint16_t addr, uint16_t data) { return _write_command(0x0011) && _write_word(addr) && _write_word(data); } - bool Panel_IT8951::_set_target_memory_addr(std::uint32_t tar_addr) + bool Panel_IT8951::_set_target_memory_addr(uint32_t tar_addr) { return _write_reg(IT8951_LISAR + 2, tar_addr >> 16) && _write_reg(IT8951_LISAR , tar_addr ); } - bool Panel_IT8951::_set_area( std::uint32_t x, std::uint32_t y, std::uint32_t w, std::uint32_t h) + bool Panel_IT8951::_set_area( uint32_t x, uint32_t y, uint32_t w, uint32_t h) { - std::uint32_t rx, ry, rw, rh; + uint32_t rx, ry, rw, rh; rx = ((_it8951_rotation+1) & 2) ? _width - w - x : x; ry = ( _it8951_rotation & 2) ? _height - h - y : y; rw = w; @@ -302,10 +302,10 @@ IT8951 Registers defines std::swap(rw, rh); } - _range_new.left = std::min(_range_new.left , rx ); - _range_new.right = std::max(_range_new.right , rx + rw - 1); - _range_new.top = std::min(_range_new.top , ry ); - _range_new.bottom = std::max(_range_new.bottom, ry + rh - 1); + _range_new.left = std::min(_range_new.left , rx ); + _range_new.right = std::max(_range_new.right , rx + rw - 1); + _range_new.top = std::min(_range_new.top , ry ); + _range_new.bottom = std::max(_range_new.bottom, ry + rh - 1); if (_epd_mode != epd_mode_t::epd_fastest && _range_old.horizon.intersectsWith(rx, rx + rw - 1) @@ -318,7 +318,7 @@ IT8951 Registers defines _range_old.bottom = 0; } - std::uint16_t params[5]; + uint16_t params[5]; params[0] = IT8951_LDIMG_B_ENDIAN << 8 | IT8951_4BPP << 4 | _it8951_rotation; params[1] = x; params[2] = y; @@ -330,8 +330,8 @@ IT8951 Registers defines bool Panel_IT8951::_update_raw_area(epd_update_mode_t mode) { if (_range_new.empty()) return false; - std::uint32_t l = _range_new.left; - std::uint32_t r = _range_new.right; + uint32_t l = _range_new.left; + uint32_t r = _range_new.right; // 更新範囲の幅が小さすぎる場合、IT8951がフリーズすることがある。 // 厳密には、範囲の左右端の座標値の下2ビット捨てた場合に同値になる場合、 @@ -348,19 +348,19 @@ IT8951 Registers defines r = (r + 4) & ~3; } } - std::uint32_t w = r - l + 1; - std::uint16_t params[7]; + uint32_t w = r - l + 1; + uint16_t params[7]; params[0] = l; params[1] = _range_new.top; params[2] = w; params[3] = _range_new.bottom - _range_new.top + 1; params[4] = mode; - params[5] = (std::uint16_t)_tar_memaddr; - params[6] = (std::uint16_t)(_tar_memaddr >> 16); + params[5] = (uint16_t)_tar_memaddr; + params[6] = (uint16_t)(_tar_memaddr >> 16); return _write_args(IT8951_I80_CMD_DPY_BUF_AREA, params, 7); } - void Panel_IT8951::display(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h) + void Panel_IT8951::display(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h) { if (0 < w && 0 < h) { @@ -417,7 +417,7 @@ IT8951 Registers defines endWrite(); } - void Panel_IT8951::setRotation(std::uint_fast8_t r) + void Panel_IT8951::setRotation(uint_fast8_t r) { r &= 7; _rotation = r; @@ -431,7 +431,7 @@ IT8951 Registers defines if (_it8951_rotation & 1) { std::swap(_width, _height); } } - void Panel_IT8951::setWindow(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) + void Panel_IT8951::setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye) { _xpos = xs; _ypos = ys; @@ -441,14 +441,14 @@ IT8951 Registers defines _ye = ye; } - void Panel_IT8951::drawPixelPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t rawcolor) + void Panel_IT8951::drawPixelPreclipped(uint_fast16_t x, uint_fast16_t y, uint32_t rawcolor) { startWrite(); writeFillRectPreclipped(x, y, 1, 1, rawcolor); endWrite(); } - void Panel_IT8951::writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) + void Panel_IT8951::writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t rawcolor) { if (_it8951_rotation & 4) { @@ -456,16 +456,16 @@ IT8951 Registers defines } _set_area(x, y, w, h); bgr888_t color = rawcolor; - std::int32_t sum = color.R8() + (color.G8() << 1) + color.B8(); + int32_t sum = color.R8() + (color.G8() << 1) + color.B8(); _wait_busy(); _bus->writeData(0, 16); bool fast = _epd_mode == epd_mode_t::epd_fast || _epd_mode == epd_mode_t::epd_fastest; - std::uint32_t wid = (((x + w + 3) >> 2) - (x >> 2)); + uint32_t wid = (((x + w + 3) >> 2) - (x >> 2)); do { auto btbl = &Bayer[(y & 3) << 2]; ++y; - std::uint32_t value; + uint32_t value; if (fast) { value = (sum + btbl[2]*16 < 512 ? 0 : 0xF000) @@ -475,10 +475,10 @@ IT8951 Registers defines } else { - value = std::min(15, (std::max(0, sum + btbl[2])) >> 6) << 12 - | std::min(15, (std::max(0, sum + btbl[3])) >> 6) << 8 - | std::min(15, (std::max(0, sum + btbl[0])) >> 6) << 4 - | std::min(15, (std::max(0, sum + btbl[1])) >> 6) ; + value = std::min(15, (std::max(0, sum + btbl[2])) >> 6) << 12 + | std::min(15, (std::max(0, sum + btbl[3])) >> 6) << 8 + | std::min(15, (std::max(0, sum + btbl[0])) >> 6) << 4 + | std::min(15, (std::max(0, sum + btbl[1])) >> 6) ; } if (_invert) value = ~value; _bus->writeDataRepeat(value, 16, wid); @@ -486,15 +486,15 @@ IT8951 Registers defines _write_command(IT8951_TCON_LD_IMG_END); } - void Panel_IT8951::writeImage(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param, bool use_dma) + void Panel_IT8951::writeImage(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param, bool use_dma) { - std::uint16_t* writebuf = static_cast(heap_alloc(w * sizeof(bgr888_t) + 4)); + uint16_t* writebuf = static_cast(heap_alloc(w * sizeof(bgr888_t) + 4)); bgr888_t* readbuf = reinterpret_cast(&writebuf[2]); if (writebuf == nullptr) return; writebuf[0] = 0; - std::int32_t add_y = 1; + int32_t add_y = 1; bool flg_setarea = false; if (_it8951_rotation & 4) { @@ -516,7 +516,7 @@ IT8951 Registers defines do { - std::uint32_t prev_pos = 0, new_pos = 0; + uint32_t prev_pos = 0, new_pos = 0; do { new_pos = param->fp_copy(readbuf, prev_pos, w, param); @@ -533,23 +533,23 @@ IT8951 Registers defines //_wait_busy(); //_bus->writeData(0, 16); } - std::uint32_t writepos = 1; - std::int32_t shift = (3 - ((x + prev_pos) & 3)) << 2; + uint32_t writepos = 1; + int32_t shift = (3 - ((x + prev_pos) & 3)) << 2; auto btbl = &Bayer[(y & 3) << 2]; do { - std::uint_fast16_t buf = 0; + uint_fast16_t buf = 0; do { auto color = readbuf[prev_pos]; - std::int32_t pixel = color.R8() + (color.G8() << 1) + color.B8(); + int32_t pixel = color.R8() + (color.G8() << 1) + color.B8(); if (fast) { pixel = (pixel + btbl[(x + prev_pos) & 3] * 16 < 512) ? 0 : 15; } else { - pixel = std::min(15, std::max(0, pixel + btbl[(x + prev_pos) & 3]) >> 6); + pixel = std::min(15, std::max(0, pixel + btbl[(x + prev_pos) & 3]) >> 6); } buf |= pixel << shift; shift -= 4; @@ -561,7 +561,7 @@ IT8951 Registers defines //_bus->writeData(__builtin_bswap16(buf), 16); } while (new_pos != prev_pos); _wait_busy(); - _bus->writeBytes((std::uint8_t*)writebuf, writepos << 1, true, false); + _bus->writeBytes((uint8_t*)writebuf, writepos << 1, true, false); } } while (w != new_pos && w != (prev_pos = param->fp_skip(new_pos, w, param))); param->src_x32 = sx; @@ -575,13 +575,13 @@ IT8951 Registers defines } } - void Panel_IT8951::writeBlock(std::uint32_t rawcolor, std::uint32_t length) + void Panel_IT8951::writeBlock(uint32_t rawcolor, uint32_t length) { auto xpos = _xpos; auto ypos = _ypos; - std::int32_t len; + int32_t len; do { - len = std::min(length, _xe + 1 - _xpos); + len = std::min(length, _xe + 1 - _xpos); writeFillRectPreclipped(xpos, ypos, len, 1, rawcolor); xpos += len; if (xpos > _xe) @@ -597,24 +597,24 @@ IT8951 Registers defines _xpos = xpos; } - void Panel_IT8951::writePixels(pixelcopy_t* param, std::uint32_t length, bool use_dma) + void Panel_IT8951::writePixels(pixelcopy_t* param, uint32_t length, bool use_dma) { - std::uint32_t xs = _xs ; - std::uint32_t ys = _ys ; - std::uint32_t xe = _xe ; - std::uint32_t ye = _ye ; - std::uint32_t xpos = _xpos; - std::uint32_t ypos = _ypos; - std::uint32_t w; - - std::uint32_t maxw = std::min(length, xe - xs + 1); + uint32_t xs = _xs ; + uint32_t ys = _ys ; + uint32_t xe = _xe ; + uint32_t ye = _ye ; + uint32_t xpos = _xpos; + uint32_t ypos = _ypos; + uint32_t w; + + uint32_t maxw = std::min(length, xe - xs + 1); bgr888_t* readbuf = static_cast(heap_alloc(maxw * sizeof(bgr888_t))); if (readbuf == nullptr) return; do { w = std::min(length, xe - xs + 1); auto y = _it8951_rotation & 4 ? height() - ypos - 1 : ypos; - std::int32_t prev_pos = 0, new_pos = 0; + int32_t prev_pos = 0, new_pos = 0; //do { new_pos = param->fp_copy(readbuf, prev_pos, w, param); @@ -623,13 +623,13 @@ IT8951 Registers defines _set_area(xpos + prev_pos, y, new_pos - prev_pos, 1); _wait_busy(); _bus->writeData(0, 16); - std::uint32_t shift = (3 - ((xpos + prev_pos) & 3)) << 2; - std::uint16_t buf = 0; + uint32_t shift = (3 - ((xpos + prev_pos) & 3)) << 2; + uint16_t buf = 0; auto btbl = &Bayer[(y & 3) << 2]; do { auto color = readbuf[prev_pos]; - std::uint16_t pixel = std::min(15, std::max(0, (color.R8() + (color.G8() << 1) + color.B8() + btbl[(xpos + prev_pos) & 3])) >> 6); + uint16_t pixel = std::min(15, std::max(0, (color.R8() + (color.G8() << 1) + color.B8() + btbl[(xpos + prev_pos) & 3])) >> 6); buf |= pixel << shift; if (shift) { @@ -666,12 +666,12 @@ IT8951 Registers defines heap_free(readbuf); } - bool Panel_IT8951::_read_raw_line(std::int32_t raw_x, std::int32_t raw_y, std::int32_t len, std::uint16_t* __restrict__ buf) + bool Panel_IT8951::_read_raw_line(int32_t raw_x, int32_t raw_y, int32_t len, uint16_t* __restrict__ buf) { - std::uint16_t params[4]; + uint16_t params[4]; auto addr = _tar_memaddr + raw_x + raw_y * _cfg.panel_width; - params[0] = (std::uint16_t)addr; - params[1] = (std::uint16_t)(addr >> 16); + params[0] = (uint16_t)addr; + params[1] = (uint16_t)(addr >> 16); params[2] = len; // (len + 15) & ~15; params[3] = 0; return _write_args(IT8951_TCON_MEM_BST_RD_T, params, 4) @@ -679,12 +679,12 @@ IT8951 Registers defines && _read_words(buf, len); } - void Panel_IT8951::readRect(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, void* __restrict__ dst, pixelcopy_t* param) + void Panel_IT8951::readRect(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, void* __restrict__ dst, pixelcopy_t* param) { /// IT8951には画素読出しコマンドが存在せず、画像メモリを直接読むコマンドが提供されている。 /// 画像メモリを直接読み出す場合、ビットシフトや回転方向の解決などは自前で行う必要がある。 - std::uint32_t rx, ry, rw, rh; + uint32_t rx, ry, rw, rh; if (_it8951_rotation & 4) { y = height() - y - h; @@ -718,19 +718,19 @@ IT8951 Registers defines break; } - std::int32_t adjust_left = (rx & 3); - std::uint32_t padding_len = (adjust_left + rw + 31) & ~31; - auto readbuf = static_cast(heap_alloc(std::max(padding_len, rw * param->dst_bits >> 3))); + int32_t adjust_left = (rx & 3); + uint32_t padding_len = (adjust_left + rw + 31) & ~31; + auto readbuf = static_cast(heap_alloc(std::max(padding_len, rw * param->dst_bits >> 3))); auto colorbuf = static_cast(heap_alloc(rw * sizeof(bgr888_t))); param->src_data = colorbuf; - for (std::uint32_t j = 0; j < rh; ++j) + for (uint32_t j = 0; j < rh; ++j) { - _read_raw_line(rx & ~3, ry, padding_len >> 1, reinterpret_cast(readbuf)); - for (std::uint32_t i = 0; i < rw; ++i) + _read_raw_line(rx & ~3, ry, padding_len >> 1, reinterpret_cast(readbuf)); + for (uint32_t i = 0; i < rw; ++i) { - std::uint_fast8_t l = 8 + readbuf[adjust_left + i]; + uint_fast8_t l = 8 + readbuf[adjust_left + i]; if (_invert) l = ~l; colorbuf[i].set(l,l,l); } @@ -743,13 +743,13 @@ IT8951 Registers defines param->src_x32_add = (~0u << pixelcopy_t::FP_SCALE); param->src_x = rw - 1; } - std::uint32_t dstpos = rw * ((_it8951_rotation & 4) ? (rh - j - 1) : j); + uint32_t dstpos = rw * ((_it8951_rotation & 4) ? (rh - j - 1) : j); param->fp_copy(dst, dstpos, dstpos + rw, param); } else { - for (std::uint32_t i = 0; i < rw; ++i) { - std::int32_t dstpos; + for (uint32_t i = 0; i < rw; ++i) { + int32_t dstpos; switch (_it8951_rotation) { default: diff --git a/src/lgfx/v1/panel/Panel_IT8951.hpp b/src/lgfx/v1/panel/Panel_IT8951.hpp index b759bcf..e3320a9 100644 --- a/src/lgfx/v1/panel/Panel_IT8951.hpp +++ b/src/lgfx/v1/panel/Panel_IT8951.hpp @@ -38,25 +38,25 @@ namespace lgfx color_depth_t setColorDepth(color_depth_t depth) override; void setInvert(bool invert) override; - void setRotation(std::uint_fast8_t r) override; + void setRotation(uint_fast8_t r) override; void setSleep(bool flg) override; void setPowerSave(bool flg) override; void waitDisplay(void) override; bool displayBusy(void) override; - void display(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h) override; + void display(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h) override; - void writeBlock(std::uint32_t rawcolor, std::uint32_t len) override; - void setWindow(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) override; - void drawPixelPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t rawcolor) override; - void writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) override; - void writeImage(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param, bool use_dma) override; - void writePixels(pixelcopy_t* param, std::uint32_t len, bool use_dma) override; + void writeBlock(uint32_t rawcolor, uint32_t len) override; + void setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye) override; + void drawPixelPreclipped(uint_fast16_t x, uint_fast16_t y, uint32_t rawcolor) override; + void writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t rawcolor) override; + void writeImage(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param, bool use_dma) override; + void writePixels(pixelcopy_t* param, uint32_t len, bool use_dma) override; - std::uint32_t readCommand(std::uint_fast8_t cmd, std::uint_fast8_t index = 0, std::uint_fast8_t length = 4) override { return 0; } - std::uint32_t readData(std::uint_fast8_t index = 0, std::uint_fast8_t length = 4) override { return 0; } + uint32_t readCommand(uint_fast8_t, uint_fast8_t, uint_fast8_t) override { return 0; } + uint32_t readData(uint_fast8_t, uint_fast8_t) override { return 0; } - void readRect(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, void* dst, pixelcopy_t* param) override; + void readRect(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, void* dst, pixelcopy_t* param) override; private: @@ -76,22 +76,22 @@ namespace lgfx range_rect_t _range_new; range_rect_t _range_old; - std::uint_fast16_t _xpos = 0; - std::uint_fast16_t _ypos = 0; - std::uint_fast8_t _it8951_rotation = 0; + uint_fast16_t _xpos = 0; + uint_fast16_t _ypos = 0; + uint_fast8_t _it8951_rotation = 0; bool _in_transaction = false; - bool _wait_busy( std::uint32_t timeout = 1000); - bool _write_command( std::uint16_t cmd); - bool _write_word( std::uint16_t data); - bool _write_args( std::uint16_t cmd, std::uint16_t *args, std::int32_t length); - bool _write_reg( std::uint16_t addr, std::uint16_t data); - bool _read_words( std::uint16_t *buf, std::uint32_t length); + bool _wait_busy( uint32_t timeout = 1000); + bool _write_command( uint16_t cmd); + bool _write_word( uint16_t data); + bool _write_args( uint16_t cmd, uint16_t *args, int32_t length); + bool _write_reg( uint16_t addr, uint16_t data); + bool _read_words( uint16_t *buf, uint32_t length); bool _check_afsr( void ); - bool _set_target_memory_addr( std::uint32_t tar_addr); - bool _set_area( std::uint32_t x, std::uint32_t y, std::uint32_t w, std::uint32_t h); + bool _set_target_memory_addr( uint32_t tar_addr); + bool _set_area( uint32_t x, uint32_t y, uint32_t w, uint32_t h); bool _update_raw_area( epd_update_mode_t mode); - bool _read_raw_line( std::int32_t raw_x, std::int32_t raw_y, std::int32_t len, std::uint16_t* buf); + bool _read_raw_line( int32_t raw_x, int32_t raw_y, int32_t len, uint16_t* buf); fastread_dir_t get_fastread_dir(void) const override { return _it8951_rotation & 1 ? fastread_vertical : fastread_horizontal; } }; diff --git a/src/lgfx/v1/panel/Panel_LCD.cpp b/src/lgfx/v1/panel/Panel_LCD.cpp index 3b2cc5f..c4e9a8c 100644 --- a/src/lgfx/v1/panel/Panel_LCD.cpp +++ b/src/lgfx/v1/panel/Panel_LCD.cpp @@ -35,7 +35,7 @@ namespace lgfx startWrite(true); - for (std::uint8_t i = 0; auto cmds = getInitCommands(i); i++) + for (uint8_t i = 0; auto cmds = getInitCommands(i); i++) { command_list(cmds); } @@ -66,9 +66,9 @@ namespace lgfx if (!_in_transaction) return; _in_transaction = false; - if (_align_data) + if (_has_align_data) { - _align_data = false; + _has_align_data = false; _bus->writeData(0, 8); } @@ -85,6 +85,7 @@ namespace lgfx _invert = invert; startWrite(); write_command((invert ^ _cfg.invert) ? CMD_INVON : CMD_INVOFF); + _bus->flush(); endWrite(); } @@ -92,6 +93,7 @@ namespace lgfx { startWrite(); write_command(flg ? CMD_SLPIN : CMD_SLPOUT); + _bus->flush(); endWrite(); } @@ -99,6 +101,7 @@ namespace lgfx { startWrite(); write_command(flg ? CMD_IDMON : CMD_IDMOFF); + _bus->flush(); endWrite(); } @@ -112,7 +115,7 @@ namespace lgfx return _write_depth; } - void Panel_LCD::setRotation(std::uint_fast8_t r) + void Panel_LCD::setRotation(uint_fast8_t r) { r &= 7; _rotation = r; @@ -157,7 +160,7 @@ namespace lgfx } } - void Panel_LCD::write_command(std::uint32_t data) + void Panel_LCD::write_command(uint32_t data) { if (!_cfg.dlen_16bit) { @@ -165,16 +168,16 @@ namespace lgfx } else { - if (_align_data) + if (_has_align_data) { _bus->writeData(0, 8); - _align_data = false; + _has_align_data = false; } _bus->writeCommand(data << 8, 16); } } - std::uint32_t Panel_LCD::readCommand(std::uint_fast8_t cmd, std::uint_fast8_t index, std::uint_fast8_t len) + uint32_t Panel_LCD::readCommand(uint_fast8_t cmd, uint_fast8_t index, uint_fast8_t len) { startWrite(); write_command(cmd); @@ -185,7 +188,7 @@ namespace lgfx return res; } - std::uint32_t Panel_LCD::readData(std::uint_fast8_t index, std::uint_fast8_t len) + uint32_t Panel_LCD::readData(uint_fast8_t index, uint_fast8_t len) { startWrite(); auto res = read_bits(index << 3, len << 3); @@ -194,7 +197,7 @@ namespace lgfx return res; } - std::uint32_t Panel_LCD::read_bits(std::uint_fast8_t bit_index, std::uint_fast8_t bit_len) + uint32_t Panel_LCD::read_bits(uint_fast8_t bit_index, uint_fast8_t bit_len) { _bus->beginRead(); if (bit_index) { _bus->readData(bit_index); } // dummy read @@ -204,7 +207,7 @@ namespace lgfx return res; } - void Panel_LCD::setWindow(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) + void Panel_LCD::setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye) { if (!_cfg.dlen_16bit) { @@ -216,43 +219,43 @@ namespace lgfx } } - void Panel_LCD::drawPixelPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t rawcolor) + void Panel_LCD::drawPixelPreclipped(uint_fast16_t x, uint_fast16_t y, uint32_t rawcolor) { bool tr = _in_transaction; if (!tr) begin_transaction(); setWindow(x,y,x,y); - if (_cfg.dlen_16bit) { _align_data = (_write_bits & 15); } + if (_cfg.dlen_16bit) { _has_align_data = (_write_bits & 15); } _bus->writeData(rawcolor, _write_bits); if (!tr) end_transaction(); } - void Panel_LCD::writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) + void Panel_LCD::writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t rawcolor) { - std::uint32_t len = w * h; - std::uint_fast16_t xe = w + x - 1; - std::uint_fast16_t ye = y + h - 1; + uint32_t len = w * h; + uint_fast16_t xe = w + x - 1; + uint_fast16_t ye = y + h - 1; setWindow(x,y,xe,ye); - if (_cfg.dlen_16bit) { _align_data = (_write_bits & 15) && (len & 1); } + if (_cfg.dlen_16bit) { _has_align_data = (_write_bits & 15) && (len & 1); } _bus->writeDataRepeat(rawcolor, _write_bits, len); } - void Panel_LCD::writeBlock(std::uint32_t rawcolor, std::uint32_t len) + void Panel_LCD::writeBlock(uint32_t rawcolor, uint32_t len) { _bus->writeDataRepeat(rawcolor, _write_bits, len); if (_cfg.dlen_16bit && (_write_bits & 15) && (len & 1)) { - _align_data = !_align_data; + _has_align_data = !_has_align_data; } } - void Panel_LCD::writePixels(pixelcopy_t* param, std::uint32_t len, bool use_dma) + void Panel_LCD::writePixels(pixelcopy_t* param, uint32_t len, bool use_dma) { if (param->no_convert) { - _bus->writeBytes(reinterpret_cast(param->src_data), len * _write_bits >> 3, true, use_dma); + _bus->writeBytes(reinterpret_cast(param->src_data), len * _write_bits >> 3, true, use_dma); } else { @@ -260,11 +263,11 @@ namespace lgfx } if (_cfg.dlen_16bit && (_write_bits & 15) && (len & 1)) { - _align_data = !_align_data; + _has_align_data = !_has_align_data; } } - void Panel_LCD::writeImage(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param, bool use_dma) + void Panel_LCD::writeImage(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param, bool use_dma) { auto bytes = param->dst_bits >> 3; auto src_x = param->src_x; @@ -274,8 +277,8 @@ namespace lgfx if (param->no_convert) { auto wb = w * bytes; - std::uint32_t i = (src_x + param->src_y * param->src_bitwidth) * bytes; - auto src = &((const std::uint8_t*)param->src_data)[i]; + uint32_t i = (src_x + param->src_y * param->src_bitwidth) * bytes; + auto src = &((const uint8_t*)param->src_data)[i]; setWindow(x, y, x + w - 1, y + h - 1); if (param->src_bitwidth == w || h == 1) { @@ -288,7 +291,7 @@ namespace lgfx { if (_cfg.dlen_16bit && ((wb * h) & 1)) { - _align_data = !_align_data; + _has_align_data = !_has_align_data; } do { @@ -309,42 +312,41 @@ namespace lgfx } else { -/* - if (!_bus->busy() && (h == 1 || (param->src_bitwidth == w && w * h <= INT16_MAX))) + if (!_bus->busy()) { + static constexpr uint32_t WRITEPIXELS_MAXLEN = 32767; + setWindow(x, y, x + w - 1, y + h - 1); - writePixels(param, w * h); - } -// - if (h == 1 || (param->src_bitwidth == w && w * h <= INT16_MAX)) - { - std::size_t length = w * h; - std::size_t limit = (bytes == 2) ? 64 : 48; -// std::size_t len = ((wh - 1) % limit) + 1; - std::size_t len = (limit << 1) <= length ? limit : length; - limit <<= 1; - auto buf = _bus->getDMABuffer(len * bytes); - param->fp_copy(buf, 0, len, param); - setWindow(x, y, x + w - 1, y + h - 1); - write_bytes(buf, len * bytes, true); - while (length -= len) + bool nogap = (param->src_bitwidth == w || h == 1); + if (nogap && (w * h <= WRITEPIXELS_MAXLEN)) + { + writePixels(param, w * h, use_dma); + } + else { -// len = ((wh - 1) % limit) + 1; - len = (limit << 1) <= length ? limit : length; - if (limit <= 256) limit <<= 1; - auto buf = _bus->getDMABuffer(len * bytes); - param->fp_copy(buf, 0, len, param); - write_bytes(buf, len * bytes, true); + uint_fast16_t h_step = nogap ? WRITEPIXELS_MAXLEN / w : 1; + uint_fast16_t h_len = (h_step > 1) ? ((h - 1) % h_step) + 1 : 1; + writePixels(param, w * h_len, use_dma); + if (h -= h_len) + { + param->src_y += h_len; + do + { + param->src_x = src_x; + writePixels(param, w * h_step, use_dma); + param->src_y += h_step; + } while (h -= h_step); + } } } else -//*/ { - std::size_t wb = w * bytes; + size_t wb = w * bytes; auto buf = _bus->getDMABuffer(wb); param->fp_copy(buf, 0, w, param); setWindow(x, y, x + w - 1, y + h - 1); write_bytes(buf, wb, true); + _has_align_data = (_cfg.dlen_16bit && (_write_bits & 15) && (w & h & 1)); while (--h) { param->src_x = src_x; @@ -359,14 +361,14 @@ namespace lgfx else { h += y; - std::uint32_t wb = w * bytes; + uint32_t wb = w * bytes; do { - std::uint32_t i = 0; + uint32_t i = 0; while (w != (i = param->fp_skip(i, w, param))) { auto buf = _bus->getDMABuffer(wb); - std::int32_t len = param->fp_copy(buf, 0, w - i, param); + int32_t len = param->fp_copy(buf, 0, w - i, param); setWindow(x + i, y, x + i + len - 1, y); write_bytes(buf, len * bytes, true); if (w == (i += len)) break; @@ -377,18 +379,18 @@ namespace lgfx } } - void Panel_LCD::write_bytes(const std::uint8_t* data, std::uint32_t len, bool use_dma) + void Panel_LCD::write_bytes(const uint8_t* data, uint32_t len, bool use_dma) { _bus->writeBytes(data, len, true, use_dma); if (_cfg.dlen_16bit && (_write_bits & 15) && (len & 1)) { - _align_data = !_align_data; + _has_align_data = !_has_align_data; } } - void Panel_LCD::readRect(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, void* dst, pixelcopy_t* param) + void Panel_LCD::readRect(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, void* dst, pixelcopy_t* param) { - std::uint_fast16_t bytes = param->dst_bits >> 3; + uint_fast16_t bytes = param->dst_bits >> 3; auto len = w * h; if (!_cfg.readable) { @@ -409,7 +411,7 @@ namespace lgfx if (param->no_convert) { - _bus->readBytes((std::uint8_t*)dst, len * bytes); + _bus->readBytes((uint8_t*)dst, len * bytes); } else { @@ -423,7 +425,7 @@ namespace lgfx if (_in_transaction) { cs_control(false); } } - void Panel_LCD::set_window_8(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye, std::uint32_t cmd) + void Panel_LCD::set_window_8(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye, uint32_t cmd) { if (xs != _xs || xe != _xe) { @@ -446,12 +448,12 @@ namespace lgfx _bus->writeCommand(cmd, 8); } - void Panel_LCD::set_window_16(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye, std::uint32_t cmd) + void Panel_LCD::set_window_16(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye, uint32_t cmd) { - if (_align_data) + if (_has_align_data) { _bus->writeData(0, 8); - _align_data = false; + _has_align_data = false; } if (xs != _xs || xe != _xe) { diff --git a/src/lgfx/v1/panel/Panel_LCD.hpp b/src/lgfx/v1/panel/Panel_LCD.hpp index af82610..7a37e35 100644 --- a/src/lgfx/v1/panel/Panel_LCD.hpp +++ b/src/lgfx/v1/panel/Panel_LCD.hpp @@ -33,7 +33,7 @@ namespace lgfx void endTransaction(void) override; color_depth_t setColorDepth(color_depth_t depth) override; - void setRotation(std::uint_fast8_t r) override; + void setRotation(uint_fast8_t r) override; void setInvert(bool invert) override; void setSleep(bool flg) override; void setPowerSave(bool flg) override; @@ -41,25 +41,25 @@ namespace lgfx void waitDisplay(void) override {} bool displayBusy(void) override { return false; } - void writePixels(pixelcopy_t* param, std::uint32_t len, bool use_dma) override; - void writeBlock(std::uint32_t rawcolor, std::uint32_t len) override; + void writePixels(pixelcopy_t* param, uint32_t len, bool use_dma) override; + void writeBlock(uint32_t rawcolor, uint32_t len) override; - void setWindow(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) override; - void drawPixelPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t rawcolor) override; - void writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) override; - void writeImage(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param, bool use_dma) override; + void setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye) override; + void drawPixelPreclipped(uint_fast16_t x, uint_fast16_t y, uint32_t rawcolor) override; + void writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t rawcolor) override; + void writeImage(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param, bool use_dma) override; - std::uint32_t readCommand(std::uint_fast8_t cmd, std::uint_fast8_t index, std::uint_fast8_t len) override; - std::uint32_t readData(std::uint_fast8_t index, std::uint_fast8_t len) override; - void readRect(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, void* dst, pixelcopy_t* param) override; + uint32_t readCommand(uint_fast8_t cmd, uint_fast8_t index, uint_fast8_t len) override; + uint32_t readData(uint_fast8_t index, uint_fast8_t len) override; + void readRect(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, void* dst, pixelcopy_t* param) override; protected: - std::uint16_t _colstart = 0; - std::uint16_t _rowstart = 0; + uint16_t _colstart = 0; + uint16_t _rowstart = 0; bool _in_transaction = false; - std::uint8_t _cmd_nop = CMD_NOP; - std::uint8_t _cmd_ramrd = CMD_RAMRD; + uint8_t _cmd_nop = CMD_NOP; + uint8_t _cmd_ramrd = CMD_RAMRD; enum mad_t { MAD_MY = 0x80 @@ -79,9 +79,9 @@ namespace lgfx , RGB888_3BYTE = 0x66 }; - virtual std::uint8_t getMadCtl(std::uint8_t r) const + virtual uint8_t getMadCtl(uint8_t r) const { - static constexpr std::uint8_t madctl_table[] = + static constexpr uint8_t madctl_table[] = { 0, MAD_MV|MAD_MX|MAD_MH , @@ -95,42 +95,42 @@ namespace lgfx return madctl_table[r]; } - static constexpr std::uint8_t CMD_NOP = 0x00; - static constexpr std::uint8_t CMD_SWRESET = 0x01; - static constexpr std::uint8_t CMD_RDDID = 0x04; - static constexpr std::uint8_t CMD_RDDST = 0x09; - static constexpr std::uint8_t CMD_SLPIN = 0x10; - static constexpr std::uint8_t CMD_SLPOUT = 0x11; - static constexpr std::uint8_t CMD_PTLON = 0x12; - static constexpr std::uint8_t CMD_NORON = 0x13; - static constexpr std::uint8_t CMD_INVOFF = 0x20; - static constexpr std::uint8_t CMD_INVON = 0x21; - static constexpr std::uint8_t CMD_GAMMASET= 0x26; - static constexpr std::uint8_t CMD_DISPOFF = 0x28; - static constexpr std::uint8_t CMD_DISPON = 0x29; - static constexpr std::uint8_t CMD_CASET = 0x2A; - static constexpr std::uint8_t CMD_RASET = 0x2B; - static constexpr std::uint8_t CMD_PASET = 0x2B; - static constexpr std::uint8_t CMD_RAMWR = 0x2C; - static constexpr std::uint8_t CMD_RAMRD = 0x2E; - static constexpr std::uint8_t CMD_MADCTL = 0x36; - static constexpr std::uint8_t CMD_IDMOFF = 0x38; - static constexpr std::uint8_t CMD_IDMON = 0x39; - static constexpr std::uint8_t CMD_COLMOD = 0x3A; - static constexpr std::uint8_t CMD_PIXSET = 0x3A; + static constexpr uint8_t CMD_NOP = 0x00; + static constexpr uint8_t CMD_SWRESET = 0x01; + static constexpr uint8_t CMD_RDDID = 0x04; + static constexpr uint8_t CMD_RDDST = 0x09; + static constexpr uint8_t CMD_SLPIN = 0x10; + static constexpr uint8_t CMD_SLPOUT = 0x11; + static constexpr uint8_t CMD_PTLON = 0x12; + static constexpr uint8_t CMD_NORON = 0x13; + static constexpr uint8_t CMD_INVOFF = 0x20; + static constexpr uint8_t CMD_INVON = 0x21; + static constexpr uint8_t CMD_GAMMASET= 0x26; + static constexpr uint8_t CMD_DISPOFF = 0x28; + static constexpr uint8_t CMD_DISPON = 0x29; + static constexpr uint8_t CMD_CASET = 0x2A; + static constexpr uint8_t CMD_RASET = 0x2B; + static constexpr uint8_t CMD_PASET = 0x2B; + static constexpr uint8_t CMD_RAMWR = 0x2C; + static constexpr uint8_t CMD_RAMRD = 0x2E; + static constexpr uint8_t CMD_MADCTL = 0x36; + static constexpr uint8_t CMD_IDMOFF = 0x38; + static constexpr uint8_t CMD_IDMON = 0x39; + static constexpr uint8_t CMD_COLMOD = 0x3A; + static constexpr uint8_t CMD_PIXSET = 0x3A; void begin_transaction(void); void end_transaction(void); - std::uint32_t read_bits(std::uint_fast8_t bit_index, std::uint_fast8_t bit_len); + uint32_t read_bits(uint_fast8_t bit_index, uint_fast8_t bit_len); - void write_command(std::uint32_t data); - void write_bytes(const std::uint8_t* data, std::uint32_t len, bool use_dma); - void set_window_8(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye, std::uint32_t cmd); - void set_window_16(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye, std::uint32_t cmd); + void write_command(uint32_t data); + void write_bytes(const uint8_t* data, uint32_t len, bool use_dma); + void set_window_8(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye, uint32_t cmd); + void set_window_16(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye, uint32_t cmd); virtual void update_madctl(void); - virtual std::uint8_t getColMod(std::uint8_t bpp) const { return (bpp > 16) ? RGB888_3BYTE : RGB565_2BYTE; } + virtual uint8_t getColMod(uint8_t bpp) const { return (bpp > 16) ? RGB888_3BYTE : RGB565_2BYTE; } /// 引数に応じて _write_depth と _read_depth を設定する。_read_depthはドライバによってrgb888_3Byte固定のものや_write_depthと同じなるものがある。違いに注意が必要。 virtual void setColorDepth_impl(color_depth_t depth) { _write_depth = ((int)depth & color_depth_t::bit_mask) > 16 ? rgb888_3Byte : rgb565_2Byte; _read_depth = rgb888_3Byte; } diff --git a/src/lgfx/v1/panel/Panel_M5UnitLCD.cpp b/src/lgfx/v1/panel/Panel_M5UnitLCD.cpp index c11d085..a9455e6 100644 --- a/src/lgfx/v1/panel/Panel_M5UnitLCD.cpp +++ b/src/lgfx/v1/panel/Panel_M5UnitLCD.cpp @@ -43,7 +43,7 @@ namespace lgfx startWrite(true); _bus->writeCommand(CMD_READ_ID, 8); - std::uint8_t buf[4]; + uint8_t buf[4]; bool res = _bus->readBytes(buf, 4, true) && buf[0] == 0x77 && buf[1] == 0x89; @@ -72,7 +72,7 @@ namespace lgfx _last_cmd = 0; } - bool Panel_M5UnitLCD::_check_repeat(std::uint32_t cmd, std::uint_fast8_t limit) + bool Panel_M5UnitLCD::_check_repeat(uint32_t cmd, uint_fast8_t limit) { switch (_last_cmd & ~7) { @@ -99,9 +99,9 @@ namespace lgfx --_buff_free_count; return false; } - limit = std::min(255u, limit * 2); + limit = std::min(255, limit * 2); - std::size_t retry = 16; + size_t retry = 16; _buff_free_count = 255; while (!_bus->writeCommand(CMD_READ_BUFCOUNT, 8) && --retry); if (retry) @@ -109,7 +109,7 @@ namespace lgfx retry = 255; do { - if (_bus->readBytes((std::uint8_t*)&_buff_free_count, 1)) + if (_bus->readBytes((uint8_t*)&_buff_free_count, 1)) { if (_buff_free_count >= limit) { @@ -143,7 +143,7 @@ namespace lgfx return _write_depth; } - void Panel_M5UnitLCD::setRotation(std::uint_fast8_t r) + void Panel_M5UnitLCD::setRotation(uint_fast8_t r) { r &= 7; _rotation = r; @@ -194,7 +194,7 @@ namespace lgfx endWrite(); } - void Panel_M5UnitLCD::setBrightness(std::uint8_t brightness) + void Panel_M5UnitLCD::setBrightness(uint8_t brightness) { startWrite(); _check_repeat(); @@ -202,16 +202,16 @@ namespace lgfx endWrite(); } - void Panel_M5UnitLCD::writeBlock(std::uint32_t rawcolor, std::uint32_t length) + void Panel_M5UnitLCD::writeBlock(uint32_t rawcolor, uint32_t length) { /* do { - std::uint32_t h = 1; - auto w = std::min(length, _xe + 1 - _xpos); + uint32_t h = 1; + auto w = std::min(length, _xe + 1 - _xpos); if (length >= (w << 1) && _xpos == _xs) { - h = std::min(length / w, _ye + 1 - _ypos); + h = std::min(length / w, _ye + 1 - _ypos); } writeFillRectPreclipped(_xpos, _ypos, w, h, rawcolor); if ((_xpos += w) <= _xe) return; @@ -221,15 +221,15 @@ namespace lgfx } while (length); /*/ _raw_color = rawcolor; - std::size_t bytes = (rawcolor == 0) ? 1 : (_write_bits >> 3); - std::uint8_t buf[(length >> 8) * (bytes + 1) + 2]; + size_t bytes = (rawcolor == 0) ? 1 : (_write_bits >> 3); + auto buf = (uint8_t*)alloca((length >> 8) * (bytes + 1) + 2); buf[0] = CMD_WRITE_RLE | bytes; - std::size_t idx = _check_repeat(buf[0]) ? 0 : 1; + size_t idx = _check_repeat(buf[0]) ? 0 : 1; //_check_repeat(buf[0]); - //std::size_t idx = 1; + //size_t idx = 1; do { - std::uint32_t len = (length < 0x100) + uint32_t len = (length < 0x100) ? length : 0xFF; buf[idx++] = len; auto color = rawcolor; @@ -244,7 +244,7 @@ namespace lgfx //*/ } - void Panel_M5UnitLCD::drawPixelPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t rawcolor) + void Panel_M5UnitLCD::drawPixelPreclipped(uint_fast16_t x, uint_fast16_t y, uint32_t rawcolor) { startWrite(); _check_repeat(); @@ -252,7 +252,7 @@ namespace lgfx endWrite(); } - void Panel_M5UnitLCD::_fill_rect(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint_fast8_t bytes) + void Panel_M5UnitLCD::_fill_rect(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint_fast8_t bytes) { _xs = x; _ys = y; @@ -260,10 +260,10 @@ namespace lgfx _ye = y + h - 1; _check_repeat(); - std::uint8_t buf[16]; + uint8_t buf[16]; bool rect = (w > 1) || (h > 1); buf[0] = (rect ? CMD_FILLRECT : CMD_DRAWPIXEL) | bytes; - std::size_t idx = 1; + size_t idx = 1; bool flg_large = (_cfg.memory_width >= 256) || (_cfg.memory_height >= 256); if (flg_large) { buf[idx++] = _xs >> 8; } buf[idx++] = _xs; if (flg_large) { buf[idx++] = _ys >> 8; } buf[idx++] = _ys; @@ -273,7 +273,7 @@ namespace lgfx if (flg_large) { buf[idx++] = _ye >> 8; } buf[idx++] = _ye; } auto rawcolor = _raw_color; - for (std::size_t i = 0; i < bytes; ++i) + for (size_t i = 0; i < bytes; ++i) { buf[idx++] = rawcolor; rawcolor >>= 8; @@ -281,9 +281,9 @@ namespace lgfx _bus->writeBytes(buf, idx, false, true); } - void Panel_M5UnitLCD::writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) + void Panel_M5UnitLCD::writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t rawcolor) { - std::size_t bytes = 0; + size_t bytes = 0; if (_raw_color != rawcolor) { _raw_color = rawcolor; @@ -292,14 +292,14 @@ namespace lgfx _fill_rect(x, y, w, h, bytes); } - void Panel_M5UnitLCD::writeFillRectAlphaPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t argb8888) + void Panel_M5UnitLCD::writeFillRectAlphaPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t argb8888) { _raw_color = __builtin_bswap32(argb8888); _fill_rect(x, y, w, h, 4); _raw_color = ~0u; } - void Panel_M5UnitLCD::setWindow(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) + void Panel_M5UnitLCD::setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye) { _xpos = xs; _ypos = ys; @@ -307,17 +307,17 @@ namespace lgfx _set_window(xs, ys, xe, ye); endWrite(); } - void Panel_M5UnitLCD::_set_window(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) + void Panel_M5UnitLCD::_set_window(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye) { - std::uint8_t buf[10]; - std::size_t idx = 0; + uint8_t buf[10]; + size_t idx = 0; bool flg_large = (_cfg.memory_width >= 256) || (_cfg.memory_height >= 256); if (!flg_large) { - ys = std::min(ys, 255u); - ye = std::min(ye, 255u); - xs = std::min(xs, 255u); - xe = std::min(xe, 255u); + ys = std::min(ys, 255u); + ye = std::min(ye, 255u); + xs = std::min(xs, 255u); + xe = std::min(xe, 255u); } if (xs != _xs || xe != _xe) { @@ -343,7 +343,7 @@ namespace lgfx } - static std::uint8_t* store_encoded(std::uint8_t* dst, const std::uint8_t* src, std::size_t data_num, std::size_t bytes) + static uint8_t* store_encoded(uint8_t* dst, const uint8_t* src, size_t data_num, size_t bytes) { *dst++ = data_num; memmove(dst, src, bytes); @@ -351,7 +351,7 @@ namespace lgfx return dst; } - static std::uint8_t* store_absolute(std::uint8_t* dst, const std::uint8_t* src, std::size_t src_size, std::size_t bytes) + static uint8_t* store_absolute(uint8_t* dst, const uint8_t* src, size_t src_size, size_t bytes) { if (src_size >= 3) // 絶対モード { @@ -362,7 +362,7 @@ namespace lgfx } else // RLEモード { - for (std::size_t i = 0; i < src_size; i++) + for (size_t i = 0; i < src_size; i++) { dst = store_encoded(dst, src + i * bytes, 1, bytes); } @@ -370,15 +370,15 @@ namespace lgfx return dst; } /* - static std::size_t rleDecode(const std::uint8_t* src, std::size_t len, std::size_t bytes) + static size_t rleDecode(const uint8_t* src, size_t len, size_t bytes) { - std::size_t res = 0; - std::size_t idx = 0; + size_t res = 0; + size_t idx = 0; while (idx < len) { if (src[idx++] == 0) { - std::size_t abs_len = src[idx++]; + size_t abs_len = src[idx++]; idx += abs_len * bytes; res += abs_len; continue; @@ -389,24 +389,24 @@ namespace lgfx return res; } */ - static std::size_t rleEncode(std::uint8_t* dest, const std::uint8_t* src, std::size_t bytelen, std::size_t bytes) + static size_t rleEncode(uint8_t* dest, const uint8_t* src, size_t bytelen, size_t bytes) { /* Serial.printf("bytelen:%d bytes:%d\r\n", bytelen, bytes); for (int i = 0; i < bytelen; ++i) { Serial.printf("%02x ",src[i]); } Serial.println(); //*/ - static constexpr std::size_t maxbyte = 255; + static constexpr size_t maxbyte = 255; - std::uint8_t* pdest = dest; - const std::uint8_t* pabs = src; - const std::uint8_t* prev = src; + uint8_t* pdest = dest; + const uint8_t* pabs = src; + const uint8_t* prev = src; - std::int_fast16_t cont = 1; - std::int_fast16_t abso = 0; + int_fast16_t cont = 1; + int_fast16_t abso = 0; - for (std::size_t i = bytes; i < bytelen; i += bytes) + for (size_t i = bytes; i < bytelen; i += bytes) { - std::size_t byteidx = 0; + size_t byteidx = 0; while (src[i + byteidx] == src[i + byteidx - bytes] && ++byteidx != bytes); if (byteidx == bytes) @@ -450,7 +450,7 @@ for (int i = 0; i < bytelen; ++i) { Serial.printf("%02x ",src[i]); } Serial.prin pdest = store_encoded(pdest, prev, cont, bytes); } /* -std::size_t res = pdest - dest; +size_t res = pdest - dest; if (bytelen != rleDecode(dest, res, bytes)*bytes) { Serial.printf("res:%d\r\n", res); for (int i = 0; i < res; ++i) { Serial.printf("%02x ",dest[i]); } Serial.println(); @@ -459,54 +459,55 @@ if (bytelen != rleDecode(dest, res, bytes)*bytes) { return pdest - dest; } //* - void Panel_M5UnitLCD::writePixels(pixelcopy_t* param, std::uint32_t length, bool use_dma) + void Panel_M5UnitLCD::writePixels(pixelcopy_t* param, uint32_t length, bool use_dma) { + (void)use_dma; auto bytes = _write_bits >> 3; - std::uint32_t wb = length * bytes; + uint32_t wb = length * bytes; auto dmabuf = _bus->getDMABuffer(wb + (wb >> 7) + 128); dmabuf[0] = CMD_WRITE_RLE | bytes; - std::size_t idx = _check_repeat(dmabuf[0]) ? 0 : 1; + size_t idx = _check_repeat(dmabuf[0]) ? 0 : 1; auto buf = &dmabuf[(wb >> 7) + 128]; param->fp_copy(buf, 0, length, param); - std::size_t writelen = idx + rleEncode(&dmabuf[idx], buf, length * bytes, bytes); + size_t writelen = idx + rleEncode(&dmabuf[idx], buf, length * bytes, bytes); _bus->writeBytes(dmabuf, writelen, false, true); _raw_color = ~0u; } /*/ - void Panel_M5UnitLCD::writePixels(pixelcopy_t* param, std::uint32_t length) + void Panel_M5UnitLCD::writePixels(pixelcopy_t* param, uint32_t length) { auto bytes = _write_bits >> 3; - std::uint32_t wb = length * bytes; + uint32_t wb = length * bytes; auto dmabuf = _bus->getDMABuffer(wb + (wb >> 7) + 1); dmabuf[0] = CMD_WRITE_RAW | _write_bits >> 3; - std::size_t idx = _check_repeat(dmabuf[0]) ? 0 : 1; + size_t idx = _check_repeat(dmabuf[0]) ? 0 : 1; auto buf = &dmabuf[idx]; param->fp_copy(buf, 0, length, param); - std::size_t writelen = idx + wb; + size_t writelen = idx + wb; _bus->writeBytes(dmabuf, writelen, false, true); _raw_color = ~0u; } //*/ /* - void Panel_M5UnitLCD::writeImage(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param, bool use_dma) + void Panel_M5UnitLCD::writeImage(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param, bool use_dma) { - std::uint32_t sx32 = param->src_x32; + uint32_t sx32 = param->src_x32; auto bytes = _write_bits >> 3; - std::uint32_t y_add = 1; + uint32_t y_add = 1; bool transp = (param->transp != pixelcopy_t::NON_TRANSP); if (!transp) { _set_window(x, y, x+w-1, y+h-1); } - std::uint32_t wb = w * bytes; + uint32_t wb = w * bytes; do { - std::uint32_t i = 0; + uint32_t i = 0; while (w != (i = param->fp_skip(i, w, param))) { auto dmabuf = _bus->getDMABuffer(wb + 1); dmabuf[0] = CMD_WRITE_RAW | ((_write_bits >> 3) & 3); auto buf = &dmabuf[1]; - std::int32_t len = param->fp_copy(buf, 0, w - i, param); + int32_t len = param->fp_copy(buf, 0, w - i, param); if (transp) { _set_window(x + i, y, x + i + len - 1, y); } _bus->writeBytes(dmabuf, 1 + wb, false, true); if (w == (i += len)) break; @@ -518,24 +519,25 @@ if (bytelen != rleDecode(dest, res, bytes)*bytes) { _raw_color = ~0u; } /*/ - void Panel_M5UnitLCD::writeImage(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param, bool use_dma) + void Panel_M5UnitLCD::writeImage(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param, bool use_dma) { + (void)use_dma; // _xs_raw = ~0u; // _ys_raw = ~0u; - std::uint32_t sx32 = param->src_x32; + uint32_t sx32 = param->src_x32; auto bytes = _write_bits >> 3; - std::uint32_t y_add = 1; - std::uint32_t cmd = CMD_WRITE_RLE | bytes; + uint32_t y_add = 1; + uint32_t cmd = CMD_WRITE_RLE | bytes; bool transp = (param->transp != pixelcopy_t::NON_TRANSP); if (!transp) { _set_window(x, y, x+w-1, y+h-1); } - std::uint32_t wb = w * bytes; + uint32_t wb = w * bytes; do { - std::uint32_t i = 0; + uint32_t i = 0; while (w != (i = param->fp_skip(i, w, param))) { auto sub = (w - i) >> 2; @@ -545,7 +547,7 @@ if (bytelen != rleDecode(dest, res, bytes)*bytes) { auto dmabuf = _bus->getDMABuffer(wb + (wb >> 7) + 128); dmabuf[0] = cmd; auto buf = &dmabuf[(wb >> 7) + 128]; - std::int32_t len = param->fp_copy(buf, 0, w - i, param); + int32_t len = param->fp_copy(buf, 0, w - i, param); if (transp) { _set_window(x + i, y, x + i + len - 1, y); @@ -554,8 +556,8 @@ if (bytelen != rleDecode(dest, res, bytes)*bytes) { { _bus->writeCommand(cmd, 8); } - std::size_t idx = 0; - std::size_t writelen = rleEncode(&dmabuf[idx], buf, len * bytes, bytes); + size_t idx = 0; + size_t writelen = rleEncode(&dmabuf[idx], buf, len * bytes, bytes); _bus->writeBytes(dmabuf, writelen, false, true); if (w == (i += len)) break; } @@ -566,22 +568,22 @@ if (bytelen != rleDecode(dest, res, bytes)*bytes) { _raw_color = ~0u; } - void Panel_M5UnitLCD::writeImageARGB(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param) + void Panel_M5UnitLCD::writeImageARGB(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param) { _set_window(x, y, x + w - 1, y); - auto buf = (std::uint32_t*)param->src_data; + auto buf = (uint32_t*)param->src_data; if (!_check_repeat(CMD_WRITE_RAW_32)) { writeCommand(CMD_WRITE_RAW_32, 1); } - for (std::size_t i = 0; i < w; ++i) + for (size_t i = 0; i < w; ++i) { _bus->writeCommand(__builtin_bswap32(buf[i]), 32); } _raw_color = ~0u; } - void Panel_M5UnitLCD::readRect(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, void* dst, pixelcopy_t* param) + void Panel_M5UnitLCD::readRect(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, void* dst, pixelcopy_t* param) { startWrite(); int retry = 4; @@ -593,7 +595,7 @@ if (bytelen != rleDecode(dest, res, bytes)*bytes) { _bus->writeCommand(CMD_READ_RAW | ((_read_bits >> 3) & 3), 8); if (param->no_convert) { - _bus->readBytes((std::uint8_t*)dst, w * h * _read_bits >> 3, true); + _bus->readBytes((uint8_t*)dst, w * h * _read_bits >> 3, true); } else { @@ -607,10 +609,10 @@ if (bytelen != rleDecode(dest, res, bytes)*bytes) { } } - void Panel_M5UnitLCD::copyRect(std::uint_fast16_t dst_x, std::uint_fast16_t dst_y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint_fast16_t src_x, std::uint_fast16_t src_y) + void Panel_M5UnitLCD::copyRect(uint_fast16_t dst_x, uint_fast16_t dst_y, uint_fast16_t w, uint_fast16_t h, uint_fast16_t src_x, uint_fast16_t src_y) { - std::uint8_t buf[16]; - std::size_t idx = 0; + uint8_t buf[16]; + size_t idx = 0; buf[idx++] = CMD_COPYRECT; auto xe = src_x + w - 1; auto ye = src_y + h - 1; diff --git a/src/lgfx/v1/panel/Panel_M5UnitLCD.hpp b/src/lgfx/v1/panel/Panel_M5UnitLCD.hpp index c9e6723..66b7a3d 100644 --- a/src/lgfx/v1/panel/Panel_M5UnitLCD.hpp +++ b/src/lgfx/v1/panel/Panel_M5UnitLCD.hpp @@ -39,105 +39,105 @@ namespace lgfx void endTransaction(void) override; color_depth_t setColorDepth(color_depth_t depth) override; - void setRotation(std::uint_fast8_t r) override; - void setBrightness(std::uint8_t brightness) override; + void setRotation(uint_fast8_t r) override; + void setBrightness(uint8_t brightness) override; void setInvert(bool invert) override; void setSleep(bool flg) override; void setPowerSave(bool flg) override; void waitDisplay(void) override {} bool displayBusy(void) override { return false; } - void display(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h) override {} - - void writePixels(pixelcopy_t* param, std::uint32_t len, bool use_dma) override; - void writeBlock(std::uint32_t rawcolor, std::uint32_t len) override; - - void setWindow(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) override; - void drawPixelPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t rawcolor) override; - void writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) override; - void writeFillRectAlphaPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t argb8888) override; - void writeImage(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param, bool use_dma) override; - void writeImageARGB(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param) override; - void copyRect(std::uint_fast16_t dst_x, std::uint_fast16_t dst_y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint_fast16_t src_x, std::uint_fast16_t src_y) override; - - std::uint32_t readCommand(std::uint_fast8_t cmd, std::uint_fast8_t index, std::uint_fast8_t len) override { return 0; } - std::uint32_t readData(std::uint_fast8_t index, std::uint_fast8_t len) override { return 0; } - void readRect(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, void* dst, pixelcopy_t* param) override; - - static constexpr std::uint8_t CMD_NOP = 0x00; // 1Byte 何もしない - static constexpr std::uint8_t CMD_READ_ID = 0x04; // 1Byte ID読出し スレーブからの回答は4Byte (0x77 0x89 0x00 0x?? (最後の1バイトはファームウェアバージョン)) - static constexpr std::uint8_t CMD_READ_BUFCOUNT= 0x09; // 1Byte コマンドバッファの空き取得。回答は1Byte、受信可能なコマンド数が返される。数字が小さいほどバッファの余裕がない。 - static constexpr std::uint8_t CMD_INVOFF = 0x20; // 1Byte 色反転を解除 - static constexpr std::uint8_t CMD_INVON = 0x21; // 1Byte 色反転を有効 - static constexpr std::uint8_t CMD_BRIGHTNESS = 0x22; // 2Byte バックライト data[1]==明るさ 0~255 - static constexpr std::uint8_t CMD_COPYRECT = 0x23; // 7Byte 矩形範囲コピー [1]==XS [2]==YS [3]==XE [4]==YE [5]==DST_X [6]==DST_Y - static constexpr std::uint8_t CMD_CASET = 0x2A; // 3Byte X方向の範囲選択 data[1]==XS data[2]==XE - static constexpr std::uint8_t CMD_RASET = 0x2B; // 3Byte Y方向の範囲選択 data[1]==YS data[2]==YE - static constexpr std::uint8_t CMD_ROTATE = 0x36; // 2Byte 回転処理 [1]==回転方向 0:通常 1:右90度 2:180度 3:270度 4~7は0~3の上下反転 - static constexpr std::uint8_t CMD_SET_POWER = 0x38; // 2Byte data[1] 0:低速ローパワー / 1:通常 / 2:高速ハイパワー - static constexpr std::uint8_t CMD_SET_SLEEP = 0x39; // 2Byte data[1] 0:スリープ解除 / 1:スリープ開始 - - static constexpr std::uint8_t CMD_WRITE_RAW = 0x40; - static constexpr std::uint8_t CMD_WRITE_RAW_8 = 0x41; // 不定長 RGB332 1Byteのピクセルデータを連続送信 - static constexpr std::uint8_t CMD_WRITE_RAW_16 = 0x42; // 不定長 RGB565 2Byteのピクセルデータを連続送信 - static constexpr std::uint8_t CMD_WRITE_RAW_24 = 0x43; // 不定長 RGB888 3Byteのピクセルデータを連続送信 - static constexpr std::uint8_t CMD_WRITE_RAW_32 = 0x44; // 不定長 ARGB8888 4Byteのピクセルデータを連続送信 - static constexpr std::uint8_t CMD_WRITE_RAW_A = 0x45; // 不定長 A8 1Byteのピクセルデータを連続送信(アルファチャネルのみ、描画色は最後に使用したものを再利用する) - - static constexpr std::uint8_t CMD_WRITE_RLE = 0x48; - static constexpr std::uint8_t CMD_WRITE_RLE_8 = 0x49; // 不定長 RGB332 1Byteのピクセルデータを連続送信(RLE圧縮) - static constexpr std::uint8_t CMD_WRITE_RLE_16 = 0x4A; // 不定長 RGB565 2Byteのピクセルデータを連続送信(RLE圧縮) - static constexpr std::uint8_t CMD_WRITE_RLE_24 = 0x4B; // 不定長 RGB888 3Byteのピクセルデータを連続送信(RLE圧縮) - static constexpr std::uint8_t CMD_WRITE_RLE_32 = 0x4C; // 不定長 ARGB8888 4Byteのピクセルデータを連続送信(RLE圧縮) - static constexpr std::uint8_t CMD_WRITE_RLE_A = 0x4D; // 不定長 A8 1Byteのピクセルデータを連続送信(RLE圧縮 アルファチャネルのみ、描画色は最後に使用したものを再利用する) - - static constexpr std::uint8_t CMD_RAM_FILL = 0x50; // 1Byte 現在の描画色で選択範囲全塗り - static constexpr std::uint8_t CMD_SET_COLOR = 0x50; - static constexpr std::uint8_t CMD_SET_COLOR_8 = 0x51; // 2Byte 描画色をRGB332で指定 - static constexpr std::uint8_t CMD_SET_COLOR_16 = 0x52; // 3Byte 描画色をRGB565で指定 - static constexpr std::uint8_t CMD_SET_COLOR_24 = 0x53; // 4Byte 描画色をRGB888で指定 - static constexpr std::uint8_t CMD_SET_COLOR_32 = 0x54; // 5Byte 描画色をARGB8888で指定 - - static constexpr std::uint8_t CMD_DRAWPIXEL = 0x60; // 3Byte ドット描画 [1]==X [2]==Y - static constexpr std::uint8_t CMD_DRAWPIXEL_8 = 0x61; // 4Byte ドット描画 [1]==X [2]==Y [3 ]==RGB332 - static constexpr std::uint8_t CMD_DRAWPIXEL_16 = 0x62; // 5Byte ドット描画 [1]==X [2]==Y [3~4]==RGB565 - static constexpr std::uint8_t CMD_DRAWPIXEL_24 = 0x63; // 6Byte ドット描画 [1]==X [2]==Y [3~5]==RGB888 - static constexpr std::uint8_t CMD_DRAWPIXEL_32 = 0x64; // 7Byte ドット描画 [1]==X [2]==Y [3~6]==ARGB8888 - - static constexpr std::uint8_t CMD_FILLRECT = 0x68; // 5Byte 矩形塗潰 [1]==XS [2]==YS [3]==XE [4]==YE - static constexpr std::uint8_t CMD_FILLRECT_8 = 0x69; // 6Byte 矩形塗潰 [1]==XS [2]==YS [3]==XE [4]==YE [5 ]==RGB332 - static constexpr std::uint8_t CMD_FILLRECT_16 = 0x6A; // 7Byte 矩形塗潰 [1]==XS [2]==YS [3]==XE [4]==YE [5~6]==RGB565 - static constexpr std::uint8_t CMD_FILLRECT_24 = 0x6B; // 8Byte 矩形塗潰 [1]==XS [2]==YS [3]==XE [4]==YE [5~7]==RGB888 - static constexpr std::uint8_t CMD_FILLRECT_32 = 0x6C; // 9Byte 矩形塗潰 [1]==XS [2]==YS [3]==XE [4]==YE [5~8]==ARGB8888 - - static constexpr std::uint8_t CMD_READ_RAW = 0x80; - static constexpr std::uint8_t CMD_READ_RAW_8 = 0x81; // 1Byte RGB332のピクセルデータを読出し - static constexpr std::uint8_t CMD_READ_RAW_16 = 0x82; // 1Byte RGB565のピクセルデータを読出し - static constexpr std::uint8_t CMD_READ_RAW_24 = 0x83; // 1Byte RGB888のピクセルデータを読出し - - static constexpr std::uint8_t CMD_CHANGE_ADDR = 0xA0; // 4Byte i2cアドレス変更 [0]=0xA0 [1]=変更後のI2Cアドレス [2]=変更後のI2Cアドレスのビット反転値 [3]=0xA0 - - static constexpr std::uint8_t CMD_UPDATE_BEGIN = 0xF0; // 4Byte ファームウェア更新開始 [0]=0xF0 [1]=0x77 [2]=0x89 [3]=0xF0 - static constexpr std::uint8_t CMD_UPDATE_DATA = 0xF1; // 4Byte ファームウェアデータ送信 [0]=0xF1 [1]=0x77 [2]=0x89 [3]=0xF1 - static constexpr std::uint8_t CMD_UPDATE_END = 0xF2; // 4Byte ファームウェア更新完了 [0]=0xF2 [1]=0x77 [2]=0x89 [3]=0xF2 - static constexpr std::uint8_t CMD_RESET = 0xFF; // 4Byte リセット(再起動) [0]=0xFF [1]=0x77 [2]=0x89 [3]=0xFF - - static constexpr std::uint8_t UPDATE_RESULT_BROKEN = 0x01; - static constexpr std::uint8_t UPDATE_RESULT_ERROR = 0x00; - static constexpr std::uint8_t UPDATE_RESULT_OK = 0xF1; - static constexpr std::uint8_t UPDATE_RESULT_BUSY = 0xFF; + void display(uint_fast16_t, uint_fast16_t, uint_fast16_t, uint_fast16_t) override {} + + void writePixels(pixelcopy_t* param, uint32_t len, bool use_dma) override; + void writeBlock(uint32_t rawcolor, uint32_t len) override; + + void setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye) override; + void drawPixelPreclipped(uint_fast16_t x, uint_fast16_t y, uint32_t rawcolor) override; + void writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t rawcolor) override; + void writeFillRectAlphaPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t argb8888) override; + void writeImage(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param, bool use_dma) override; + void writeImageARGB(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param) override; + void copyRect(uint_fast16_t dst_x, uint_fast16_t dst_y, uint_fast16_t w, uint_fast16_t h, uint_fast16_t src_x, uint_fast16_t src_y) override; + + uint32_t readCommand(uint_fast8_t, uint_fast8_t, uint_fast8_t) override { return 0; } + uint32_t readData(uint_fast8_t, uint_fast8_t) override { return 0; } + void readRect(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, void* dst, pixelcopy_t* param) override; + + static constexpr uint8_t CMD_NOP = 0x00; // 1Byte 何もしない + static constexpr uint8_t CMD_READ_ID = 0x04; // 1Byte ID読出し スレーブからの回答は4Byte (0x77 0x89 0x00 0x?? (最後の1バイトはファームウェアバージョン)) + static constexpr uint8_t CMD_READ_BUFCOUNT= 0x09; // 1Byte コマンドバッファの空き取得。回答は1Byte、受信可能なコマンド数が返される。数字が小さいほどバッファの余裕がない。 + static constexpr uint8_t CMD_INVOFF = 0x20; // 1Byte 色反転を解除 + static constexpr uint8_t CMD_INVON = 0x21; // 1Byte 色反転を有効 + static constexpr uint8_t CMD_BRIGHTNESS = 0x22; // 2Byte バックライト data[1]==明るさ 0~255 + static constexpr uint8_t CMD_COPYRECT = 0x23; // 7Byte 矩形範囲コピー [1]==XS [2]==YS [3]==XE [4]==YE [5]==DST_X [6]==DST_Y + static constexpr uint8_t CMD_CASET = 0x2A; // 3Byte X方向の範囲選択 data[1]==XS data[2]==XE + static constexpr uint8_t CMD_RASET = 0x2B; // 3Byte Y方向の範囲選択 data[1]==YS data[2]==YE + static constexpr uint8_t CMD_ROTATE = 0x36; // 2Byte 回転処理 [1]==回転方向 0:通常 1:右90度 2:180度 3:270度 4~7は0~3の上下反転 + static constexpr uint8_t CMD_SET_POWER = 0x38; // 2Byte data[1] 0:低速ローパワー / 1:通常 / 2:高速ハイパワー + static constexpr uint8_t CMD_SET_SLEEP = 0x39; // 2Byte data[1] 0:スリープ解除 / 1:スリープ開始 + + static constexpr uint8_t CMD_WRITE_RAW = 0x40; + static constexpr uint8_t CMD_WRITE_RAW_8 = 0x41; // 不定長 RGB332 1Byteのピクセルデータを連続送信 + static constexpr uint8_t CMD_WRITE_RAW_16 = 0x42; // 不定長 RGB565 2Byteのピクセルデータを連続送信 + static constexpr uint8_t CMD_WRITE_RAW_24 = 0x43; // 不定長 RGB888 3Byteのピクセルデータを連続送信 + static constexpr uint8_t CMD_WRITE_RAW_32 = 0x44; // 不定長 ARGB8888 4Byteのピクセルデータを連続送信 + static constexpr uint8_t CMD_WRITE_RAW_A = 0x45; // 不定長 A8 1Byteのピクセルデータを連続送信(アルファチャネルのみ、描画色は最後に使用したものを再利用する) + + static constexpr uint8_t CMD_WRITE_RLE = 0x48; + static constexpr uint8_t CMD_WRITE_RLE_8 = 0x49; // 不定長 RGB332 1Byteのピクセルデータを連続送信(RLE圧縮) + static constexpr uint8_t CMD_WRITE_RLE_16 = 0x4A; // 不定長 RGB565 2Byteのピクセルデータを連続送信(RLE圧縮) + static constexpr uint8_t CMD_WRITE_RLE_24 = 0x4B; // 不定長 RGB888 3Byteのピクセルデータを連続送信(RLE圧縮) + static constexpr uint8_t CMD_WRITE_RLE_32 = 0x4C; // 不定長 ARGB8888 4Byteのピクセルデータを連続送信(RLE圧縮) + static constexpr uint8_t CMD_WRITE_RLE_A = 0x4D; // 不定長 A8 1Byteのピクセルデータを連続送信(RLE圧縮 アルファチャネルのみ、描画色は最後に使用したものを再利用する) + + static constexpr uint8_t CMD_RAM_FILL = 0x50; // 1Byte 現在の描画色で選択範囲全塗り + static constexpr uint8_t CMD_SET_COLOR = 0x50; + static constexpr uint8_t CMD_SET_COLOR_8 = 0x51; // 2Byte 描画色をRGB332で指定 + static constexpr uint8_t CMD_SET_COLOR_16 = 0x52; // 3Byte 描画色をRGB565で指定 + static constexpr uint8_t CMD_SET_COLOR_24 = 0x53; // 4Byte 描画色をRGB888で指定 + static constexpr uint8_t CMD_SET_COLOR_32 = 0x54; // 5Byte 描画色をARGB8888で指定 + + static constexpr uint8_t CMD_DRAWPIXEL = 0x60; // 3Byte ドット描画 [1]==X [2]==Y + static constexpr uint8_t CMD_DRAWPIXEL_8 = 0x61; // 4Byte ドット描画 [1]==X [2]==Y [3 ]==RGB332 + static constexpr uint8_t CMD_DRAWPIXEL_16 = 0x62; // 5Byte ドット描画 [1]==X [2]==Y [3~4]==RGB565 + static constexpr uint8_t CMD_DRAWPIXEL_24 = 0x63; // 6Byte ドット描画 [1]==X [2]==Y [3~5]==RGB888 + static constexpr uint8_t CMD_DRAWPIXEL_32 = 0x64; // 7Byte ドット描画 [1]==X [2]==Y [3~6]==ARGB8888 + + static constexpr uint8_t CMD_FILLRECT = 0x68; // 5Byte 矩形塗潰 [1]==XS [2]==YS [3]==XE [4]==YE + static constexpr uint8_t CMD_FILLRECT_8 = 0x69; // 6Byte 矩形塗潰 [1]==XS [2]==YS [3]==XE [4]==YE [5 ]==RGB332 + static constexpr uint8_t CMD_FILLRECT_16 = 0x6A; // 7Byte 矩形塗潰 [1]==XS [2]==YS [3]==XE [4]==YE [5~6]==RGB565 + static constexpr uint8_t CMD_FILLRECT_24 = 0x6B; // 8Byte 矩形塗潰 [1]==XS [2]==YS [3]==XE [4]==YE [5~7]==RGB888 + static constexpr uint8_t CMD_FILLRECT_32 = 0x6C; // 9Byte 矩形塗潰 [1]==XS [2]==YS [3]==XE [4]==YE [5~8]==ARGB8888 + + static constexpr uint8_t CMD_READ_RAW = 0x80; + static constexpr uint8_t CMD_READ_RAW_8 = 0x81; // 1Byte RGB332のピクセルデータを読出し + static constexpr uint8_t CMD_READ_RAW_16 = 0x82; // 1Byte RGB565のピクセルデータを読出し + static constexpr uint8_t CMD_READ_RAW_24 = 0x83; // 1Byte RGB888のピクセルデータを読出し + + static constexpr uint8_t CMD_CHANGE_ADDR = 0xA0; // 4Byte i2cアドレス変更 [0]=0xA0 [1]=変更後のI2Cアドレス [2]=変更後のI2Cアドレスのビット反転値 [3]=0xA0 + + static constexpr uint8_t CMD_UPDATE_BEGIN = 0xF0; // 4Byte ファームウェア更新開始 [0]=0xF0 [1]=0x77 [2]=0x89 [3]=0xF0 + static constexpr uint8_t CMD_UPDATE_DATA = 0xF1; // 4Byte ファームウェアデータ送信 [0]=0xF1 [1]=0x77 [2]=0x89 [3]=0xF1 + static constexpr uint8_t CMD_UPDATE_END = 0xF2; // 4Byte ファームウェア更新完了 [0]=0xF2 [1]=0x77 [2]=0x89 [3]=0xF2 + static constexpr uint8_t CMD_RESET = 0xFF; // 4Byte リセット(再起動) [0]=0xFF [1]=0x77 [2]=0x89 [3]=0xFF + + static constexpr uint8_t UPDATE_RESULT_BROKEN = 0x01; + static constexpr uint8_t UPDATE_RESULT_ERROR = 0x00; + static constexpr uint8_t UPDATE_RESULT_OK = 0xF1; + static constexpr uint8_t UPDATE_RESULT_BUSY = 0xFF; protected: - std::uint32_t _raw_color = ~0u; - std::uint32_t _xpos; - std::uint32_t _ypos; - std::uint32_t _last_cmd; - std::uint32_t _buff_free_count; - - void _set_window(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye); - void _fill_rect(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint_fast8_t bytes); - bool _check_repeat(std::uint32_t cmd = 0, std::uint_fast8_t limit = 64); + uint32_t _raw_color = ~0u; + uint32_t _xpos; + uint32_t _ypos; + uint32_t _last_cmd; + uint32_t _buff_free_count; + + void _set_window(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye); + void _fill_rect(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint_fast8_t bytes); + bool _check_repeat(uint32_t cmd = 0, uint_fast8_t limit = 64); }; diff --git a/src/lgfx/v1/panel/Panel_SSD1306.cpp b/src/lgfx/v1/panel/Panel_SSD1306.cpp index f1b2ea3..86b3709 100644 --- a/src/lgfx/v1/panel/Panel_SSD1306.cpp +++ b/src/lgfx/v1/panel/Panel_SSD1306.cpp @@ -26,7 +26,7 @@ namespace lgfx { //---------------------------------------------------------------------------- - static constexpr std::uint8_t Bayer[16] = { 8, 136, 40, 168, 200, 72, 232, 104, 56, 184, 24, 152, 248, 120, 216, 88 }; + static constexpr uint8_t Bayer[16] = { 8, 136, 40, 168, 200, 72, 232, 104, 56, 184, 24, 152, 248, 120, 216, 88 }; color_depth_t Panel_1bitOLED::setColorDepth(color_depth_t depth) { @@ -47,7 +47,7 @@ namespace lgfx return _bus->busy(); } - std::size_t Panel_1bitOLED::_get_buffer_length(void) const + size_t Panel_1bitOLED::_get_buffer_length(void) const { return ((_cfg.panel_height + 7) >> 3) * _cfg.panel_width; } @@ -61,7 +61,7 @@ namespace lgfx //memset(_buf, 0, len); _bus->beginRead(); - std::uint8_t buf; + uint8_t buf; bool res = _bus->readBytes(&buf, 1, true); _bus->endTransaction(); @@ -72,9 +72,9 @@ namespace lgfx startWrite(true); - for (std::size_t i = 0; auto cmds = getInitCommands(i); i++) + for (size_t i = 0; auto cmds = getInitCommands(i); i++) { - std::size_t idx = 0; + size_t idx = 0; while (cmds[idx] != 0xFF || cmds[idx + 1] != 0xFF) ++idx; if (idx) { _bus->writeBytes(cmds, idx, false, true); } } @@ -101,10 +101,10 @@ namespace lgfx endWrite(); } - void Panel_1bitOLED::writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) + void Panel_1bitOLED::writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t rawcolor) { - std::uint_fast16_t xs = x, xe = x + w - 1; - std::uint_fast16_t ys = y, ye = y + h - 1; + uint_fast16_t xs = x, xe = x + w - 1; + uint_fast16_t ys = y, ye = y + h - 1; _xs = xs; _ys = ys; _xe = xe; @@ -113,15 +113,15 @@ namespace lgfx swap565_t color; color.raw = rawcolor; - std::uint32_t value = (color.R8() + (color.G8() << 1) + color.B8()) >> 2; + uint32_t value = (color.R8() + (color.G8() << 1) + color.B8()) >> 2; y = ys; do { x = xs; - std::uint32_t idx = x + (y >> 3) * _cfg.panel_width; + uint32_t idx = x + (y >> 3) * _cfg.panel_width; auto btbl = &Bayer[(y & 3) << 2]; - std::uint32_t mask = 1 << (y&7); + uint32_t mask = 1 << (y&7); do { bool flg = 256 <= value + btbl[x & 3]; @@ -132,18 +132,18 @@ namespace lgfx } while (++y <= ye); } - void Panel_1bitOLED::writeImage(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param, bool use_dma) + void Panel_1bitOLED::writeImage(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param, bool use_dma) { - std::uint_fast16_t xs = x, xe = x + w - 1; - std::uint_fast16_t ys = y, ye = y + h - 1; + uint_fast16_t xs = x, xe = x + w - 1; + uint_fast16_t ys = y, ye = y + h - 1; _update_transferred_rect(xs, ys, xe, ye); - swap565_t readbuf[w]; + auto readbuf = (swap565_t*)alloca(w * sizeof(swap565_t)); auto sx = param->src_x32; h += y; do { - std::uint32_t prev_pos = 0, new_pos = 0; + uint32_t prev_pos = 0, new_pos = 0; do { new_pos = param->fp_copy(readbuf, prev_pos, w, param); @@ -161,21 +161,21 @@ namespace lgfx } while (++y < h); } - void Panel_1bitOLED::writePixels(pixelcopy_t* param, std::uint32_t length, bool use_dma) + void Panel_1bitOLED::writePixels(pixelcopy_t* param, uint32_t length, bool use_dma) { { - std::uint_fast16_t xs = _xs; - std::uint_fast16_t xe = _xe; - std::uint_fast16_t ys = _ys; - std::uint_fast16_t ye = _ye; + uint_fast16_t xs = _xs; + uint_fast16_t xe = _xe; + uint_fast16_t ys = _ys; + uint_fast16_t ye = _ye; _update_transferred_rect(xs, ys, xe, ye); } - std::uint_fast16_t xs = _xs ; - std::uint_fast16_t ys = _ys ; - std::uint_fast16_t xe = _xe ; - std::uint_fast16_t ye = _ye ; - std::uint_fast16_t xpos = _xpos; - std::uint_fast16_t ypos = _ypos; + uint_fast16_t xs = _xs ; + uint_fast16_t ys = _ys ; + uint_fast16_t xe = _xe ; + uint_fast16_t ye = _ye ; + uint_fast16_t xpos = _xpos; + uint_fast16_t ypos = _ypos; static constexpr uint32_t buflen = 16; swap565_t colors[buflen]; @@ -201,15 +201,15 @@ namespace lgfx _ypos = ypos; } - void Panel_1bitOLED::readRect(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, void* dst, pixelcopy_t* param) + void Panel_1bitOLED::readRect(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, void* dst, pixelcopy_t* param) { - swap565_t readbuf[w]; + auto readbuf = (swap565_t*)alloca(w * sizeof(swap565_t)); param->src_data = readbuf; - std::int32_t readpos = 0; + int32_t readpos = 0; h += y; do { - std::uint32_t idx = 0; + uint32_t idx = 0; do { readbuf[idx] = _read_pixel(x + idx, y) ? ~0u : 0; @@ -219,35 +219,35 @@ namespace lgfx } while (++y < h); } - void Panel_1bitOLED::_draw_pixel(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t value) + void Panel_1bitOLED::_draw_pixel(uint_fast16_t x, uint_fast16_t y, uint32_t value) { _rotate_pos(x, y); - std::uint32_t idx = x + (y >> 3) * _cfg.panel_width; - std::uint32_t mask = 1 << (y&7); + uint32_t idx = x + (y >> 3) * _cfg.panel_width; + uint32_t mask = 1 << (y&7); bool flg = 256 <= value + Bayer[(x & 3) | (y & 3) << 2]; if (flg) _buf[idx] |= mask; else _buf[idx] &= ~mask; } - bool Panel_1bitOLED::_read_pixel(std::uint_fast16_t x, std::uint_fast16_t y) + bool Panel_1bitOLED::_read_pixel(uint_fast16_t x, uint_fast16_t y) { _rotate_pos(x, y); - std::uint32_t idx = x + (y >> 3) * _cfg.panel_width; + uint32_t idx = x + (y >> 3) * _cfg.panel_width; return _buf[idx] & (1 << (y&7)); } - void Panel_1bitOLED::_update_transferred_rect(std::uint_fast16_t &xs, std::uint_fast16_t &ys, std::uint_fast16_t &xe, std::uint_fast16_t &ye) + void Panel_1bitOLED::_update_transferred_rect(uint_fast16_t &xs, uint_fast16_t &ys, uint_fast16_t &xe, uint_fast16_t &ye) { _rotate_pos(xs, ys, xe, ye); - _range_mod.left = std::min(xs, _range_mod.left); - _range_mod.right = std::max(xe, _range_mod.right); - _range_mod.top = std::min(ys, _range_mod.top); - _range_mod.bottom = std::max(ye, _range_mod.bottom); + _range_mod.left = std::min(xs, _range_mod.left); + _range_mod.right = std::max(xe, _range_mod.right); + _range_mod.top = std::min(ys, _range_mod.top); + _range_mod.bottom = std::max(ye, _range_mod.bottom); } //---------------------------------------------------------------------------- - void Panel_SSD1306::setBrightness(std::uint8_t brightness) + void Panel_SSD1306::setBrightness(uint8_t brightness) { startWrite(); _bus->writeCommand(CMD_SETPRECHARGE | ((brightness+15)/17)*0x11 << 8, 16); @@ -256,23 +256,23 @@ namespace lgfx endWrite(); } - void Panel_SSD1306::display(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h) + void Panel_SSD1306::display(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h) { if (0 < w && 0 < h) { - _range_mod.left = std::min(_range_mod.left , x ); - _range_mod.right = std::max(_range_mod.right , x + w - 1); - _range_mod.top = std::min(_range_mod.top , y ); - _range_mod.bottom = std::max(_range_mod.bottom, y + h - 1); + _range_mod.left = std::min(_range_mod.left , x ); + _range_mod.right = std::max(_range_mod.right , x + w - 1); + _range_mod.top = std::min(_range_mod.top , y ); + _range_mod.bottom = std::max(_range_mod.bottom, y + h - 1); } if (_range_mod.empty()) { return; } - std::uint_fast8_t xs = _range_mod.left; - std::uint_fast8_t xe = _range_mod.right; + uint_fast8_t xs = _range_mod.left; + uint_fast8_t xe = _range_mod.right; _bus->writeCommand(CMD_COLUMNADDR| (xs + _cfg.offset_x) << 8 | (xe + _cfg.offset_x) << 16, 24); - std::uint_fast8_t ys = _range_mod.top >> 3; - std::uint_fast8_t ye = _range_mod.bottom >> 3; + uint_fast8_t ys = _range_mod.top >> 3; + uint_fast8_t ye = _range_mod.bottom >> 3; _bus->writeCommand(CMD_PAGEADDR | (ys + (_cfg.offset_y >> 3)) << 8 | (ye + (_cfg.offset_y >> 3)) << 16, 24); do { @@ -310,30 +310,30 @@ namespace lgfx // _bus->writeCommand(CMD_READMODIFYWRITE_END, 8); } - void Panel_SH110x::setBrightness(std::uint8_t brightness) + void Panel_SH110x::setBrightness(uint8_t brightness) { startWrite(); _bus->writeCommand(CMD_SETCONTRAST | brightness << 8, 16); endWrite(); } - void Panel_SH110x::display(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h) + void Panel_SH110x::display(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h) { if (0 < w && 0 < h) { - _range_mod.left = std::min(_range_mod.left , x ); - _range_mod.right = std::max(_range_mod.right , x + w - 1); - _range_mod.top = std::min(_range_mod.top , y ); - _range_mod.bottom = std::max(_range_mod.bottom, y + h - 1); + _range_mod.left = std::min(_range_mod.left , x ); + _range_mod.right = std::max(_range_mod.right , x + w - 1); + _range_mod.top = std::min(_range_mod.top , y ); + _range_mod.bottom = std::max(_range_mod.bottom, y + h - 1); } if (_range_mod.empty()) { return; } - std::uint_fast8_t xs = _range_mod.left ; - std::uint_fast8_t xe = _range_mod.right; - std::uint_fast8_t ys = _range_mod.top >> 3; - std::uint_fast8_t ye = _range_mod.bottom >> 3; + uint_fast8_t xs = _range_mod.left ; + uint_fast8_t xe = _range_mod.right; + uint_fast8_t ys = _range_mod.top >> 3; + uint_fast8_t ye = _range_mod.bottom >> 3; - std::uint_fast8_t offset_y = _cfg.offset_y >> 3; + uint_fast8_t offset_y = _cfg.offset_y >> 3; do { diff --git a/src/lgfx/v1/panel/Panel_SSD1306.hpp b/src/lgfx/v1/panel/Panel_SSD1306.hpp index df4de97..cf96c5f 100644 --- a/src/lgfx/v1/panel/Panel_SSD1306.hpp +++ b/src/lgfx/v1/panel/Panel_SSD1306.hpp @@ -36,34 +36,34 @@ namespace lgfx void setInvert(bool invert) override; void setSleep(bool flg) override; - void setPowerSave(bool flg) override {} + void setPowerSave(bool) override {} - void writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) override; - void writeImage(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param, bool use_dma) override; - void writePixels(pixelcopy_t* param, std::uint32_t len, bool use_dma) override; + void writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t rawcolor) override; + void writeImage(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param, bool use_dma) override; + void writePixels(pixelcopy_t* param, uint32_t len, bool use_dma) override; - std::uint32_t readCommand(std::uint_fast8_t cmd, std::uint_fast8_t index = 0, std::uint_fast8_t length = 4) override { return 0; } - std::uint32_t readData(std::uint_fast8_t index = 0, std::uint_fast8_t length = 4) override { return 0; } + uint32_t readCommand(uint_fast8_t, uint_fast8_t, uint_fast8_t) override { return 0; } + uint32_t readData(uint_fast8_t, uint_fast8_t) override { return 0; } - void readRect(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, void* dst, pixelcopy_t* param) override; + void readRect(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, void* dst, pixelcopy_t* param) override; protected: - static constexpr std::uint8_t CMD_SETSTARTLINE = 0x40; - static constexpr std::uint8_t CMD_DISPLAYALLON_RESUME = 0xA4; - static constexpr std::uint8_t CMD_DISPLAYALLON = 0xA5; - static constexpr std::uint8_t CMD_NORMALDISPLAY = 0xA6; - static constexpr std::uint8_t CMD_INVERTDISPLAY = 0xA7; - static constexpr std::uint8_t CMD_SETMULTIPLEX = 0xA8; - static constexpr std::uint8_t CMD_DISP_OFF = 0xAE; - static constexpr std::uint8_t CMD_DISP_ON = 0xAF; - static constexpr std::uint8_t CMD_SETPRECHARGE = 0xD9; - static constexpr std::uint8_t CMD_SETVCOMDETECT = 0xDB; - - std::size_t _get_buffer_length(void) const override; - bool _read_pixel(std::uint_fast16_t x, std::uint_fast16_t y); - void _draw_pixel(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t value); - void _update_transferred_rect(std::uint_fast16_t &xs, std::uint_fast16_t &ys, std::uint_fast16_t &xe, std::uint_fast16_t &ye); + static constexpr uint8_t CMD_SETSTARTLINE = 0x40; + static constexpr uint8_t CMD_DISPLAYALLON_RESUME = 0xA4; + static constexpr uint8_t CMD_DISPLAYALLON = 0xA5; + static constexpr uint8_t CMD_NORMALDISPLAY = 0xA6; + static constexpr uint8_t CMD_INVERTDISPLAY = 0xA7; + static constexpr uint8_t CMD_SETMULTIPLEX = 0xA8; + static constexpr uint8_t CMD_DISP_OFF = 0xAE; + static constexpr uint8_t CMD_DISP_ON = 0xAF; + static constexpr uint8_t CMD_SETPRECHARGE = 0xD9; + static constexpr uint8_t CMD_SETVCOMDETECT = 0xDB; + + size_t _get_buffer_length(void) const override; + bool _read_pixel(uint_fast16_t x, uint_fast16_t y); + void _draw_pixel(uint_fast16_t x, uint_fast16_t y, uint32_t value); + void _update_transferred_rect(uint_fast16_t &xs, uint_fast16_t &ys, uint_fast16_t &xe, uint_fast16_t &ye); }; @@ -75,32 +75,32 @@ namespace lgfx _cfg.memory_height = _cfg.panel_height = 64; } - void setBrightness(std::uint8_t brightness) override; + void setBrightness(uint8_t brightness) override; - void display(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h) override; + void display(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h) override; protected: - static constexpr std::uint8_t CMD_MEMORYMODE = 0x20; + static constexpr uint8_t CMD_MEMORYMODE = 0x20; - static constexpr std::uint8_t CMD_COLUMNADDR = 0x21; - static constexpr std::uint8_t CMD_PAGEADDR = 0x22; + static constexpr uint8_t CMD_COLUMNADDR = 0x21; + static constexpr uint8_t CMD_PAGEADDR = 0x22; - static constexpr std::uint8_t CMD_SETCONTRAST = 0x81; - static constexpr std::uint8_t CMD_CHARGEPUMP = 0x8D; - static constexpr std::uint8_t CMD_SEGREMAP = 0xA0; -// static constexpr std::uint8_t CMD_SETMLTPLX = 0xA8; - static constexpr std::uint8_t CMD_COMSCANINC = 0xC0; -// static constexpr std::uint8_t CMD_COMSCANDEC = 0xC8; - static constexpr std::uint8_t CMD_SETOFFSET = 0xD3; - static constexpr std::uint8_t CMD_SETCLKDIV = 0xD5; - static constexpr std::uint8_t CMD_SETCOMPINS = 0xDA; + static constexpr uint8_t CMD_SETCONTRAST = 0x81; + static constexpr uint8_t CMD_CHARGEPUMP = 0x8D; + static constexpr uint8_t CMD_SEGREMAP = 0xA0; +// static constexpr uint8_t CMD_SETMLTPLX = 0xA8; + static constexpr uint8_t CMD_COMSCANINC = 0xC0; +// static constexpr uint8_t CMD_COMSCANDEC = 0xC8; + static constexpr uint8_t CMD_SETOFFSET = 0xD3; + static constexpr uint8_t CMD_SETCLKDIV = 0xD5; + static constexpr uint8_t CMD_SETCOMPINS = 0xDA; - static constexpr std::uint8_t CMD_DEACTIVATE_SCROLL = 0x2E; + static constexpr uint8_t CMD_DEACTIVATE_SCROLL = 0x2E; - const std::uint8_t* getInitCommands(std::uint8_t listno) const override + const uint8_t* getInitCommands(uint8_t listno) const override { - static constexpr std::uint8_t list0[] = { + static constexpr uint8_t list0[] = { CMD_DISP_OFF , CMD_SETCLKDIV , 0x80, CMD_SETMULTIPLEX , 0x3F, @@ -139,33 +139,33 @@ namespace lgfx void beginTransaction(void) override; - void setBrightness(std::uint8_t brightness) override; + void setBrightness(uint8_t brightness) override; - void display(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h) override; + void display(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h) override; protected: - static constexpr std::uint8_t CMD_PAGEADDRESSINGMODE = 0x20; - static constexpr std::uint8_t CMD_VERTADDRESSINGMODE = 0x21; - static constexpr std::uint8_t CMD_PAGEADDR = 0x22; - static constexpr std::uint8_t CMD_SETCONTRAST = 0x81; -// static constexpr std::uint8_t CMD_CHARGEPUMP = 0x8D; - static constexpr std::uint8_t CMD_SEGREMAP = 0xA0; - static constexpr std::uint8_t CMD_DCDC = 0xAD; - static constexpr std::uint8_t CMD_SETPAGEADDR = 0xB0; - static constexpr std::uint8_t CMD_COMSCANINC = 0xC0; - static constexpr std::uint8_t CMD_COMSCANDEC = 0xC8; - static constexpr std::uint8_t CMD_SETDISPLAYOFFSET = 0xD3; - static constexpr std::uint8_t CMD_SETDISPLAYCLOCKDIV = 0xD5; - static constexpr std::uint8_t CMD_SETCOMPINS = 0xDA; - static constexpr std::uint8_t CMD_SETDISPSTARTLINE = 0xDC; - static constexpr std::uint8_t CMD_SETLOWCOLUMN = 0x00; - static constexpr std::uint8_t CMD_SETHIGHCOLUMN = 0x10; - static constexpr std::uint8_t CMD_READMODIFYWRITE = 0xE0; - static constexpr std::uint8_t CMD_READMODIFYWRITE_END = 0xEE; - - const std::uint8_t* getInitCommands(std::uint8_t listno) const override + static constexpr uint8_t CMD_PAGEADDRESSINGMODE = 0x20; + static constexpr uint8_t CMD_VERTADDRESSINGMODE = 0x21; + static constexpr uint8_t CMD_PAGEADDR = 0x22; + static constexpr uint8_t CMD_SETCONTRAST = 0x81; +// static constexpr uint8_t CMD_CHARGEPUMP = 0x8D; + static constexpr uint8_t CMD_SEGREMAP = 0xA0; + static constexpr uint8_t CMD_DCDC = 0xAD; + static constexpr uint8_t CMD_SETPAGEADDR = 0xB0; + static constexpr uint8_t CMD_COMSCANINC = 0xC0; + static constexpr uint8_t CMD_COMSCANDEC = 0xC8; + static constexpr uint8_t CMD_SETDISPLAYOFFSET = 0xD3; + static constexpr uint8_t CMD_SETDISPLAYCLOCKDIV = 0xD5; + static constexpr uint8_t CMD_SETCOMPINS = 0xDA; + static constexpr uint8_t CMD_SETDISPSTARTLINE = 0xDC; + static constexpr uint8_t CMD_SETLOWCOLUMN = 0x00; + static constexpr uint8_t CMD_SETHIGHCOLUMN = 0x10; + static constexpr uint8_t CMD_READMODIFYWRITE = 0xE0; + static constexpr uint8_t CMD_READMODIFYWRITE_END = 0xEE; + + const uint8_t* getInitCommands(uint8_t listno) const override { - static constexpr std::uint8_t list0[] = { + static constexpr uint8_t list0[] = { CMD_DISP_OFF , CMD_SETSTARTLINE , CMD_READMODIFYWRITE_END, diff --git a/src/lgfx/v1/panel/Panel_SSD1327.cpp b/src/lgfx/v1/panel/Panel_SSD1327.cpp index bdf3b45..a417e59 100644 --- a/src/lgfx/v1/panel/Panel_SSD1327.cpp +++ b/src/lgfx/v1/panel/Panel_SSD1327.cpp @@ -26,7 +26,7 @@ namespace lgfx { //---------------------------------------------------------------------------- - static constexpr std::int8_t Bayer[16] = {-30, 2, -22, 10, 18, -14, 26, -6, -18, 14, -26, 6, 30, -2, 22, -10}; + static constexpr int8_t Bayer[16] = {-30, 2, -22, 10, 18, -14, 26, -6, -18, 14, -26, 6, 30, -2, 22, -10}; color_depth_t Panel_SSD1327::setColorDepth(color_depth_t depth) { @@ -47,7 +47,7 @@ namespace lgfx return _bus->busy(); } - std::size_t Panel_SSD1327::_get_buffer_length(void) const + size_t Panel_SSD1327::_get_buffer_length(void) const { // 横2ピクセル = 1Byteなのでバッファサイズはパネル幅の半分×高さになる return ((_cfg.panel_width + 1) >> 1) * _cfg.panel_height; @@ -63,9 +63,9 @@ namespace lgfx startWrite(true); - for (std::size_t i = 0; auto cmds = getInitCommands(i); i++) + for (size_t i = 0; auto cmds = getInitCommands(i); i++) { - std::size_t idx = 0; + size_t idx = 0; while (cmds[idx] != 0xFF || cmds[idx + 1] != 0xFF) ++idx; if (idx) { _bus->writeBytes(cmds, idx, false, true); } } @@ -92,10 +92,10 @@ namespace lgfx endWrite(); } - void Panel_SSD1327::writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) + void Panel_SSD1327::writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t rawcolor) { - std::uint_fast16_t xs = x, xe = x + w - 1; - std::uint_fast16_t ys = y, ye = y + h - 1; + uint_fast16_t xs = x, xe = x + w - 1; + uint_fast16_t ys = y, ye = y + h - 1; _xs = xs; _ys = ys; _xe = xe; @@ -103,7 +103,7 @@ namespace lgfx _update_transferred_rect(xs, ys, xe, ye); bgr888_t color { rawcolor }; - std::int32_t sum = (color.R8() + (color.G8() << 1) + color.B8()); + int32_t sum = (color.R8() + (color.G8() << 1) + color.B8()); y = ys; do @@ -113,27 +113,27 @@ namespace lgfx auto buf = &_buf[y * ((_cfg.panel_width + 1) >> 1)]; do { - std::size_t idx = x >> 1; - std::uint_fast8_t shift = (x & 1) ? 0 : 4; - std::uint_fast8_t value = (std::min(15, std::max(0, sum + btbl[x & 3]) >> 6) & 0x0F) << shift; + size_t idx = x >> 1; + uint_fast8_t shift = (x & 1) ? 0 : 4; + uint_fast8_t value = (std::min(15, std::max(0, sum + btbl[x & 3]) >> 6) & 0x0F) << shift; buf[idx] = (buf[idx] & (0xF0 >> shift)) | value; } while (++x <= xe); } while (++y <= ye); // display(0,0,0,0); } - void Panel_SSD1327::writeImage(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param, bool use_dma) + void Panel_SSD1327::writeImage(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param, bool use_dma) { - std::uint_fast16_t xs = x, xe = x + w - 1; - std::uint_fast16_t ys = y, ye = y + h - 1; + uint_fast16_t xs = x, xe = x + w - 1; + uint_fast16_t ys = y, ye = y + h - 1; _update_transferred_rect(xs, ys, xe, ye); - bgr888_t readbuf[w]; + auto readbuf = (bgr888_t*)alloca(w * sizeof(bgr888_t)); auto sx = param->src_x32; h += y; do { - std::uint32_t prev_pos = 0, new_pos = 0; + uint32_t prev_pos = 0, new_pos = 0; do { new_pos = param->fp_copy(readbuf, prev_pos, w, param); @@ -151,21 +151,21 @@ namespace lgfx } while (++y < h); } - void Panel_SSD1327::writePixels(pixelcopy_t* param, std::uint32_t length, bool use_dma) + void Panel_SSD1327::writePixels(pixelcopy_t* param, uint32_t length, bool use_dma) { { - std::uint_fast16_t xs = _xs; - std::uint_fast16_t xe = _xe; - std::uint_fast16_t ys = _ys; - std::uint_fast16_t ye = _ye; + uint_fast16_t xs = _xs; + uint_fast16_t xe = _xe; + uint_fast16_t ys = _ys; + uint_fast16_t ye = _ye; _update_transferred_rect(xs, ys, xe, ye); } - std::uint_fast16_t xs = _xs ; - std::uint_fast16_t ys = _ys ; - std::uint_fast16_t xe = _xe ; - std::uint_fast16_t ye = _ye ; - std::uint_fast16_t xpos = _xpos; - std::uint_fast16_t ypos = _ypos; + uint_fast16_t xs = _xs ; + uint_fast16_t ys = _ys ; + uint_fast16_t xe = _xe ; + uint_fast16_t ye = _ye ; + uint_fast16_t xpos = _xpos; + uint_fast16_t ypos = _ypos; static constexpr uint32_t buflen = 16; bgr888_t colors[buflen]; @@ -191,15 +191,15 @@ namespace lgfx _ypos = ypos; } - void Panel_SSD1327::readRect(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, void* dst, pixelcopy_t* param) + void Panel_SSD1327::readRect(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, void* dst, pixelcopy_t* param) { - bgr888_t readbuf[w]; + auto readbuf = (bgr888_t*)alloca(w * sizeof(bgr888_t)); param->src_data = readbuf; - std::int32_t readpos = 0; + int32_t readpos = 0; h += y; do { - std::uint32_t idx = 0; + uint32_t idx = 0; do { readbuf[idx] = 0x010101u * (_read_pixel(x + idx, y) * 16 + 8); @@ -209,37 +209,37 @@ namespace lgfx } while (++y < h); } - void Panel_SSD1327::_draw_pixel(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t sum) + void Panel_SSD1327::_draw_pixel(uint_fast16_t x, uint_fast16_t y, uint32_t sum) { _rotate_pos(x, y); auto btbl = &Bayer[(y & 3) << 2]; - std::size_t idx = (x >> 1) + (y * ((_cfg.panel_width + 1) >> 1)); - std::uint_fast8_t shift = (x & 1) ? 0 : 4; - std::uint_fast8_t value = (std::min(15, std::max(0, sum + btbl[x & 3]) >> 6) & 0x0F) << shift; + size_t idx = (x >> 1) + (y * ((_cfg.panel_width + 1) >> 1)); + uint_fast8_t shift = (x & 1) ? 0 : 4; + uint_fast8_t value = (std::min(15, std::max(0, sum + btbl[x & 3]) >> 6) & 0x0F) << shift; _buf[idx] = (_buf[idx] & (0xF0 >> shift)) | value; } - std::uint8_t Panel_SSD1327::_read_pixel(std::uint_fast16_t x, std::uint_fast16_t y) + uint8_t Panel_SSD1327::_read_pixel(uint_fast16_t x, uint_fast16_t y) { _rotate_pos(x, y); - std::size_t idx = (x >> 1) + (y * ((_cfg.panel_width + 1) >> 1)); + size_t idx = (x >> 1) + (y * ((_cfg.panel_width + 1) >> 1)); return (x & 1) ? (_buf[idx] & 0x0F) : (_buf[idx] >> 4) ; } - void Panel_SSD1327::_update_transferred_rect(std::uint_fast16_t &xs, std::uint_fast16_t &ys, std::uint_fast16_t &xe, std::uint_fast16_t &ye) + void Panel_SSD1327::_update_transferred_rect(uint_fast16_t &xs, uint_fast16_t &ys, uint_fast16_t &xe, uint_fast16_t &ye) { _rotate_pos(xs, ys, xe, ye); - _range_mod.left = std::min(xs, _range_mod.left); - _range_mod.right = std::max(xe, _range_mod.right); - _range_mod.top = std::min(ys, _range_mod.top); - _range_mod.bottom = std::max(ye, _range_mod.bottom); + _range_mod.left = std::min(xs, _range_mod.left); + _range_mod.right = std::max(xe, _range_mod.right); + _range_mod.top = std::min(ys, _range_mod.top); + _range_mod.bottom = std::max(ye, _range_mod.bottom); } - void Panel_SSD1327::setBrightness(std::uint8_t brightness) + void Panel_SSD1327::setBrightness(uint8_t brightness) { startWrite(); _bus->writeCommand(0x81 | brightness << 8, 16); @@ -253,26 +253,26 @@ namespace lgfx endWrite(); } - void Panel_SSD1327::display(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h) + void Panel_SSD1327::display(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h) { if (0 < w && 0 < h) { - _range_mod.left = std::min(_range_mod.left , x ); - _range_mod.right = std::max(_range_mod.right , x + w - 1); - _range_mod.top = std::min(_range_mod.top , y ); - _range_mod.bottom = std::max(_range_mod.bottom, y + h - 1); + _range_mod.left = std::min(_range_mod.left , x ); + _range_mod.right = std::max(_range_mod.right , x + w - 1); + _range_mod.top = std::min(_range_mod.top , y ); + _range_mod.bottom = std::max(_range_mod.bottom, y + h - 1); } if (_range_mod.empty()) { return; } - std::uint_fast8_t xs = _range_mod.left >> 1; - std::uint_fast8_t xe = _range_mod.right >> 1; - std::uint_fast8_t ofs = _cfg.offset_x >> 1; + uint_fast8_t xs = _range_mod.left >> 1; + uint_fast8_t xe = _range_mod.right >> 1; + uint_fast8_t ofs = _cfg.offset_x >> 1; _bus->writeCommand(CMD_CASET | (xs + ofs) << 8 | (xe + ofs) << 16, 24); - std::uint_fast8_t ys = _range_mod.top + _cfg.offset_y; - std::uint_fast8_t ye = _range_mod.bottom + _cfg.offset_y; + uint_fast8_t ys = _range_mod.top + _cfg.offset_y; + uint_fast8_t ye = _range_mod.bottom + _cfg.offset_y; ofs = _cfg.offset_y; _bus->writeCommand(CMD_RASET | (ys + ofs) << 8 | (ye + ofs) << 16, 24); diff --git a/src/lgfx/v1/panel/Panel_SSD1327.hpp b/src/lgfx/v1/panel/Panel_SSD1327.hpp index 393d2ec..ce2a687 100644 --- a/src/lgfx/v1/panel/Panel_SSD1327.hpp +++ b/src/lgfx/v1/panel/Panel_SSD1327.hpp @@ -41,43 +41,43 @@ namespace lgfx bool displayBusy(void) override; color_depth_t setColorDepth(color_depth_t depth) override; - void setBrightness(std::uint8_t brightness) override; + void setBrightness(uint8_t brightness) override; void setInvert(bool invert) override; void setSleep(bool flg) override; void setPowerSave(bool flg) override; - void display(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h) override; + void display(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h) override; - void writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) override; - void writeImage(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, pixelcopy_t* param, bool use_dma) override; - void writePixels(pixelcopy_t* param, std::uint32_t len, bool use_dma) override; + void writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t rawcolor) override; + void writeImage(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param, bool use_dma) override; + void writePixels(pixelcopy_t* param, uint32_t len, bool use_dma) override; - std::uint32_t readCommand(std::uint_fast8_t cmd, std::uint_fast8_t index = 0, std::uint_fast8_t length = 4) override { return 0; } - std::uint32_t readData(std::uint_fast8_t index = 0, std::uint_fast8_t length = 4) override { return 0; } + uint32_t readCommand(uint_fast8_t, uint_fast8_t, uint_fast8_t) override { return 0; } + uint32_t readData(uint_fast8_t, uint_fast8_t) override { return 0; } - void readRect(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, void* dst, pixelcopy_t* param) override; + void readRect(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, void* dst, pixelcopy_t* param) override; protected: - static constexpr std::uint8_t CMD_NOP = 0xE3; - static constexpr std::uint8_t CMD_SWRESET = 0x01; - static constexpr std::uint8_t CMD_SLPIN = 0xAE; - static constexpr std::uint8_t CMD_SLPOUT = 0xAF; - static constexpr std::uint8_t CMD_INVOFF = 0xA4; - static constexpr std::uint8_t CMD_INVON = 0xA7; - static constexpr std::uint8_t CMD_DISPOFF = 0xA6; - static constexpr std::uint8_t CMD_DISPON = 0xA4; - static constexpr std::uint8_t CMD_CASET = 0x15; - static constexpr std::uint8_t CMD_RASET = 0x75; - static constexpr std::uint8_t CMD_PASET = 0x75; - static constexpr std::uint8_t CMD_RAMRD = 0x5D; - static constexpr std::uint8_t CMD_MADCTL = 0xA0; - static constexpr std::uint8_t CMD_CMDLOCK = 0xFD; - static constexpr std::uint8_t CMD_STARTLINE = 0xA1; - - const std::uint8_t* getInitCommands(std::uint8_t listno) const override + static constexpr uint8_t CMD_NOP = 0xE3; + static constexpr uint8_t CMD_SWRESET = 0x01; + static constexpr uint8_t CMD_SLPIN = 0xAE; + static constexpr uint8_t CMD_SLPOUT = 0xAF; + static constexpr uint8_t CMD_INVOFF = 0xA4; + static constexpr uint8_t CMD_INVON = 0xA7; + static constexpr uint8_t CMD_DISPOFF = 0xA6; + static constexpr uint8_t CMD_DISPON = 0xA4; + static constexpr uint8_t CMD_CASET = 0x15; + static constexpr uint8_t CMD_RASET = 0x75; + static constexpr uint8_t CMD_PASET = 0x75; + static constexpr uint8_t CMD_RAMRD = 0x5D; + static constexpr uint8_t CMD_MADCTL = 0xA0; + static constexpr uint8_t CMD_CMDLOCK = 0xFD; + static constexpr uint8_t CMD_STARTLINE = 0xA1; + + const uint8_t* getInitCommands(uint8_t listno) const override { - static constexpr std::uint8_t list0[] = + static constexpr uint8_t list0[] = { CMD_CMDLOCK , 0x12, // unlock the controller CMD_DISPOFF , // set display off @@ -101,10 +101,10 @@ namespace lgfx } } - std::size_t _get_buffer_length(void) const override; - std::uint8_t _read_pixel(std::uint_fast16_t x, std::uint_fast16_t y); - void _draw_pixel(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t value); - void _update_transferred_rect(std::uint_fast16_t &xs, std::uint_fast16_t &ys, std::uint_fast16_t &xe, std::uint_fast16_t &ye); + size_t _get_buffer_length(void) const override; + uint8_t _read_pixel(uint_fast16_t x, uint_fast16_t y); + void _draw_pixel(uint_fast16_t x, uint_fast16_t y, uint32_t value); + void _update_transferred_rect(uint_fast16_t &xs, uint_fast16_t &ys, uint_fast16_t &xe, uint_fast16_t &ye); }; diff --git a/src/lgfx/v1/panel/Panel_SSD1331.cpp b/src/lgfx/v1/panel/Panel_SSD1331.cpp index 42a6fb9..d332bcc 100644 --- a/src/lgfx/v1/panel/Panel_SSD1331.cpp +++ b/src/lgfx/v1/panel/Panel_SSD1331.cpp @@ -27,7 +27,7 @@ namespace lgfx { //---------------------------------------------------------------------------- - void Panel_SSD1331::setBrightness(std::uint8_t brightness) + void Panel_SSD1331::setBrightness(uint8_t brightness) { startWrite(); _bus->writeCommand(CMD_MASTERCURRENT | (brightness>>4) << 8, 16); @@ -55,7 +55,7 @@ namespace lgfx update_madctl(); return _write_depth; } - void Panel_SSD1331::setRotation(std::uint_fast8_t r) + void Panel_SSD1331::setRotation(uint_fast8_t r) { r &= 7; _rotation = r; @@ -88,7 +88,7 @@ namespace lgfx */ void Panel_SSD1331::update_madctl(void) { - static constexpr std::uint8_t madctl_table[] = { + static constexpr uint8_t madctl_table[] = { 0b00100000, 0b00100011, 0b00110010, @@ -124,7 +124,7 @@ namespace lgfx endWrite(); } - void Panel_SSD1331::setWindow(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) + void Panel_SSD1331::setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye) { if (_need_delay) { @@ -155,7 +155,7 @@ namespace lgfx _bus->writeCommand(CMD_RAMWR, 8); } - void Panel_SSD1331::drawPixelPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t rawcolor) + void Panel_SSD1331::drawPixelPreclipped(uint_fast16_t x, uint_fast16_t y, uint32_t rawcolor) { bool need_transaction = !getStartCount(); if (need_transaction) startWrite(); @@ -163,7 +163,7 @@ namespace lgfx if (need_transaction) endWrite(); } - void Panel_SSD1331::writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) + void Panel_SSD1331::writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t rawcolor) { auto us = lgfx::micros() - _last_us; if (us < _need_delay) @@ -182,7 +182,7 @@ namespace lgfx std::swap(xe, ye); } _bus->writeCommand(x | y << 8 | xe << 16 | ye << 24, 32); - std::uint32_t data; + uint32_t data; if (_write_bits == 16) { swap565_t color = rawcolor; @@ -200,7 +200,7 @@ namespace lgfx _last_us = lgfx::micros(); } - void Panel_SSD1331::copyRect(std::uint_fast16_t dst_x, std::uint_fast16_t dst_y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint_fast16_t src_x, std::uint_fast16_t src_y) + void Panel_SSD1331::copyRect(uint_fast16_t dst_x, uint_fast16_t dst_y, uint_fast16_t w, uint_fast16_t h, uint_fast16_t src_x, uint_fast16_t src_y) { auto us = lgfx::micros() - _last_us; if (us < _need_delay) diff --git a/src/lgfx/v1/panel/Panel_SSD1331.hpp b/src/lgfx/v1/panel/Panel_SSD1331.hpp index 5c3d88f..932979e 100644 --- a/src/lgfx/v1/panel/Panel_SSD1331.hpp +++ b/src/lgfx/v1/panel/Panel_SSD1331.hpp @@ -34,56 +34,56 @@ namespace lgfx _cfg.readable = false; } - void setBrightness(std::uint8_t brightness) override; + void setBrightness(uint8_t brightness) override; void setInvert(bool invert) override; void setSleep(bool flg) override; void setPowerSave(bool flg) override; - void setWindow(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) override; - void drawPixelPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t rawcolor) override; - void writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) override; - void copyRect(std::uint_fast16_t dst_x, std::uint_fast16_t dst_y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint_fast16_t src_x, std::uint_fast16_t src_y) override; + void setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye) override; + void drawPixelPreclipped(uint_fast16_t x, uint_fast16_t y, uint32_t rawcolor) override; + void writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t rawcolor) override; + void copyRect(uint_fast16_t dst_x, uint_fast16_t dst_y, uint_fast16_t w, uint_fast16_t h, uint_fast16_t src_x, uint_fast16_t src_y) override; protected: - std::uint32_t _last_us = 0; - std::uint32_t _need_delay = 0; - - static constexpr std::uint8_t CMD_DRAWLINE = 0x21; //!< Draw line - static constexpr std::uint8_t CMD_DRAWRECT = 0x22; //!< Draw rectangle - static constexpr std::uint8_t CMD_COPY = 0x23; - static constexpr std::uint8_t CMD_FILL = 0x26; //!< Fill enable/disable - static constexpr std::uint8_t CMD_SETCOLUMN = 0x15; //!< Set column address - static constexpr std::uint8_t CMD_SETROW = 0x75; //!< Set row adress - static constexpr std::uint8_t CMD_CONTRASTA = 0x81; //!< Set contrast for color A - static constexpr std::uint8_t CMD_CONTRASTB = 0x82; //!< Set contrast for color B - static constexpr std::uint8_t CMD_CONTRASTC = 0x83; //!< Set contrast for color C - static constexpr std::uint8_t CMD_MASTERCURRENT = 0x87; //!< Master current control - static constexpr std::uint8_t CMD_SETREMAP = 0xA0; //!< Set re-map & data format - static constexpr std::uint8_t CMD_STARTLINE = 0xA1; //!< Set display start line - static constexpr std::uint8_t CMD_DISPLAYOFFSET = 0xA2; //!< Set display offset - static constexpr std::uint8_t CMD_NORMALDISPLAY = 0xA4; //!< Set display to normal mode - static constexpr std::uint8_t CMD_DISPLAYALLON = 0xA5; //!< Set entire display ON - static constexpr std::uint8_t CMD_DISPLAYALLOFF = 0xA6; //!< Set entire display OFF - static constexpr std::uint8_t CMD_INVERTDISPLAY = 0xA7; //!< Invert display - static constexpr std::uint8_t CMD_SETMULTIPLEX = 0xA8; //!< Set multiplex ratio - static constexpr std::uint8_t CMD_DISPONDIMMER = 0xAC; - static constexpr std::uint8_t CMD_SETMASTER = 0xAD; //!< Set master configuration - static constexpr std::uint8_t CMD_DISPLAYOFF = 0xAE; //!< Display OFF (sleep mode) - static constexpr std::uint8_t CMD_DISPLAYON = 0xAF; //!< Normal Brightness Display ON - static constexpr std::uint8_t CMD_POWERMODE = 0xB0; //!< Power save mode - static constexpr std::uint8_t CMD_PRECHARGE = 0xB1; //!< Phase 1 and 2 period adjustment - static constexpr std::uint8_t CMD_CLOCKDIV = 0xB3; //!< Set display clock divide ratio/oscillator frequency - static constexpr std::uint8_t CMD_PRECHARGEA = 0x8A; //!< Set second pre-charge speed for color A - static constexpr std::uint8_t CMD_PRECHARGEB = 0x8B; //!< Set second pre-charge speed for color B - static constexpr std::uint8_t CMD_PRECHARGEC = 0x8C; //!< Set second pre-charge speed for color C - static constexpr std::uint8_t CMD_PRECHARGELEVEL = 0xBB; //!< Set pre-charge voltage - static constexpr std::uint8_t CMD_VCOMH = 0xBE; //!< Set Vcomh voltge - static constexpr std::uint8_t CMD_NOP = 0xE3; - - const std::uint8_t* getInitCommands(std::uint8_t listno) const override + uint32_t _last_us = 0; + uint32_t _need_delay = 0; + + static constexpr uint8_t CMD_DRAWLINE = 0x21; //!< Draw line + static constexpr uint8_t CMD_DRAWRECT = 0x22; //!< Draw rectangle + static constexpr uint8_t CMD_COPY = 0x23; + static constexpr uint8_t CMD_FILL = 0x26; //!< Fill enable/disable + static constexpr uint8_t CMD_SETCOLUMN = 0x15; //!< Set column address + static constexpr uint8_t CMD_SETROW = 0x75; //!< Set row adress + static constexpr uint8_t CMD_CONTRASTA = 0x81; //!< Set contrast for color A + static constexpr uint8_t CMD_CONTRASTB = 0x82; //!< Set contrast for color B + static constexpr uint8_t CMD_CONTRASTC = 0x83; //!< Set contrast for color C + static constexpr uint8_t CMD_MASTERCURRENT = 0x87; //!< Master current control + static constexpr uint8_t CMD_SETREMAP = 0xA0; //!< Set re-map & data format + static constexpr uint8_t CMD_STARTLINE = 0xA1; //!< Set display start line + static constexpr uint8_t CMD_DISPLAYOFFSET = 0xA2; //!< Set display offset + static constexpr uint8_t CMD_NORMALDISPLAY = 0xA4; //!< Set display to normal mode + static constexpr uint8_t CMD_DISPLAYALLON = 0xA5; //!< Set entire display ON + static constexpr uint8_t CMD_DISPLAYALLOFF = 0xA6; //!< Set entire display OFF + static constexpr uint8_t CMD_INVERTDISPLAY = 0xA7; //!< Invert display + static constexpr uint8_t CMD_SETMULTIPLEX = 0xA8; //!< Set multiplex ratio + static constexpr uint8_t CMD_DISPONDIMMER = 0xAC; + static constexpr uint8_t CMD_SETMASTER = 0xAD; //!< Set master configuration + static constexpr uint8_t CMD_DISPLAYOFF = 0xAE; //!< Display OFF (sleep mode) + static constexpr uint8_t CMD_DISPLAYON = 0xAF; //!< Normal Brightness Display ON + static constexpr uint8_t CMD_POWERMODE = 0xB0; //!< Power save mode + static constexpr uint8_t CMD_PRECHARGE = 0xB1; //!< Phase 1 and 2 period adjustment + static constexpr uint8_t CMD_CLOCKDIV = 0xB3; //!< Set display clock divide ratio/oscillator frequency + static constexpr uint8_t CMD_PRECHARGEA = 0x8A; //!< Set second pre-charge speed for color A + static constexpr uint8_t CMD_PRECHARGEB = 0x8B; //!< Set second pre-charge speed for color B + static constexpr uint8_t CMD_PRECHARGEC = 0x8C; //!< Set second pre-charge speed for color C + static constexpr uint8_t CMD_PRECHARGELEVEL = 0xBB; //!< Set pre-charge voltage + static constexpr uint8_t CMD_VCOMH = 0xBE; //!< Set Vcomh voltge + static constexpr uint8_t CMD_NOP = 0xE3; + + const uint8_t* getInitCommands(uint8_t listno) const override { - static constexpr std::uint8_t list0[] = + static constexpr uint8_t list0[] = { CMD_DISPLAYOFF , 0, // 0xAE CMD_STARTLINE , 0, 0x00, 0, diff --git a/src/lgfx/v1/panel/Panel_SSD1351.cpp b/src/lgfx/v1/panel/Panel_SSD1351.cpp index 0af40ba..0fae69e 100644 --- a/src/lgfx/v1/panel/Panel_SSD1351.cpp +++ b/src/lgfx/v1/panel/Panel_SSD1351.cpp @@ -50,7 +50,7 @@ namespace lgfx void Panel_SSD1351::update_madctl(void) { - static constexpr std::uint8_t madctl_table[] = { + static constexpr uint8_t madctl_table[] = { 0b00100000, 0b00100011, 0b00110010, @@ -72,12 +72,12 @@ namespace lgfx endWrite(); } - void Panel_SSD1351::setWindow(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) + void Panel_SSD1351::setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye) { set_window_8(xs, ys, xe, ye, CMD_RAMWR); } - void Panel_SSD1351::drawPixelPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t rawcolor) + void Panel_SSD1351::drawPixelPreclipped(uint_fast16_t x, uint_fast16_t y, uint32_t rawcolor) { bool tr = _in_transaction; if (!tr) begin_transaction(); @@ -88,16 +88,16 @@ namespace lgfx if (!tr) end_transaction(); } - void Panel_SSD1351::writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) + void Panel_SSD1351::writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t rawcolor) { - std::uint32_t len = w * h; - std::uint_fast16_t xe = w + x - 1; - std::uint_fast16_t ye = y + h - 1; + uint32_t len = w * h; + uint_fast16_t xe = w + x - 1; + uint_fast16_t ye = y + h - 1; set_window_8(x, y, xe, ye, CMD_RAMWR); _bus->writeDataRepeat(rawcolor, _write_bits, len); } - void Panel_SSD1351::set_window_8(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye, std::uint32_t cmd) + void Panel_SSD1351::set_window_8(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye, uint32_t cmd) { if (xs != _xs || xe != _xe) { diff --git a/src/lgfx/v1/panel/Panel_SSD1351.hpp b/src/lgfx/v1/panel/Panel_SSD1351.hpp index 18943e2..742f336 100644 --- a/src/lgfx/v1/panel/Panel_SSD1351.hpp +++ b/src/lgfx/v1/panel/Panel_SSD1351.hpp @@ -41,32 +41,32 @@ namespace lgfx void setSleep(bool flg) override; void setPowerSave(bool flg) override; - void setWindow(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) override; - void drawPixelPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t rawcolor) override; - void writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) override; + void setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye) override; + void drawPixelPreclipped(uint_fast16_t x, uint_fast16_t y, uint32_t rawcolor) override; + void writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t rawcolor) override; protected: - static constexpr std::uint8_t CMD_NOP = 0xE3; - static constexpr std::uint8_t CMD_SWRESET = 0x01; - static constexpr std::uint8_t CMD_SLPIN = 0xAE; - static constexpr std::uint8_t CMD_SLPOUT = 0xAF; - static constexpr std::uint8_t CMD_INVOFF = 0xA6; - static constexpr std::uint8_t CMD_INVON = 0xA7; - static constexpr std::uint8_t CMD_DISPOFF = 0xA4; - static constexpr std::uint8_t CMD_DISPON = 0xA5; - static constexpr std::uint8_t CMD_CASET = 0x15; - static constexpr std::uint8_t CMD_RASET = 0x75; - static constexpr std::uint8_t CMD_PASET = 0x75; - static constexpr std::uint8_t CMD_RAMWR = 0x5C; - static constexpr std::uint8_t CMD_RAMRD = 0x5D; - static constexpr std::uint8_t CMD_MADCTL = 0xA0; - static constexpr std::uint8_t CMD_CMDLOCK = 0xFD; - static constexpr std::uint8_t CMD_STARTLINE = 0xA1; - - const std::uint8_t* getInitCommands(std::uint8_t listno) const override + static constexpr uint8_t CMD_NOP = 0xE3; + static constexpr uint8_t CMD_SWRESET = 0x01; + static constexpr uint8_t CMD_SLPIN = 0xAE; + static constexpr uint8_t CMD_SLPOUT = 0xAF; + static constexpr uint8_t CMD_INVOFF = 0xA6; + static constexpr uint8_t CMD_INVON = 0xA7; + static constexpr uint8_t CMD_DISPOFF = 0xA4; + static constexpr uint8_t CMD_DISPON = 0xA5; + static constexpr uint8_t CMD_CASET = 0x15; + static constexpr uint8_t CMD_RASET = 0x75; + static constexpr uint8_t CMD_PASET = 0x75; + static constexpr uint8_t CMD_RAMWR = 0x5C; + static constexpr uint8_t CMD_RAMRD = 0x5D; + static constexpr uint8_t CMD_MADCTL = 0xA0; + static constexpr uint8_t CMD_CMDLOCK = 0xFD; + static constexpr uint8_t CMD_STARTLINE = 0xA1; + + const uint8_t* getInitCommands(uint8_t listno) const override { - static constexpr std::uint8_t list0[] = + static constexpr uint8_t list0[] = { CMD_CMDLOCK , 1, 0x12, CMD_CMDLOCK , 1, 0xB1, @@ -97,8 +97,8 @@ namespace lgfx } } - void set_window_8(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye, std::uint32_t cmd); - void set_window_16(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye, std::uint32_t cmd); + void set_window_8(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye, uint32_t cmd); + void set_window_16(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye, uint32_t cmd); void update_madctl(void) override; diff --git a/src/lgfx/v1/panel/Panel_SSD1963.cpp b/src/lgfx/v1/panel/Panel_SSD1963.cpp index c3975d2..1a2acfd 100644 --- a/src/lgfx/v1/panel/Panel_SSD1963.cpp +++ b/src/lgfx/v1/panel/Panel_SSD1963.cpp @@ -17,6 +17,7 @@ Original Source: /----------------------------------------------------------------------------*/ #include "Panel_SSD1963.hpp" +#include "../../internal/memory.h" #include "../Bus.hpp" namespace lgfx @@ -42,13 +43,13 @@ namespace lgfx return true; } - void Panel_SSD1963::setHSync(std::uint_fast16_t front, std::uint_fast16_t sync, std::uint_fast16_t back, std::uint_fast16_t move, std::uint_fast16_t lpspp) + void Panel_SSD1963::setHSync(uint_fast16_t front, uint_fast16_t sync, uint_fast16_t back, uint_fast16_t move, uint_fast16_t lpspp) { startWrite(); - std::uint_fast16_t ht = _cfg.panel_width + front + sync + back; - std::uint_fast16_t hpw = sync; - std::uint_fast16_t hps = move + sync + back; - std::uint_fast16_t lps = move; + uint_fast16_t ht = _cfg.panel_width + front + sync + back; + uint_fast16_t hpw = sync; + uint_fast16_t hps = move + sync + back; + uint_fast16_t lps = move; writeCommand(0xB4, 1); writeData(__builtin_bswap16( ht-1), 2); @@ -61,13 +62,13 @@ namespace lgfx endWrite(); } - void Panel_SSD1963::setVSync(std::uint_fast16_t front, std::uint_fast16_t sync, std::uint_fast16_t back, std::uint_fast16_t move) + void Panel_SSD1963::setVSync(uint_fast16_t front, uint_fast16_t sync, uint_fast16_t back, uint_fast16_t move) { startWrite(); - std::uint_fast16_t vt = _cfg.panel_height + front + sync + back; - std::uint_fast16_t vpw = sync; - std::uint_fast16_t vps = move + sync + back; - std::uint_fast16_t fps = move; + uint_fast16_t vt = _cfg.panel_height + front + sync + back; + uint_fast16_t vpw = sync; + uint_fast16_t vps = move + sync + back; + uint_fast16_t fps = move; writeCommand(0xB6, 1); writeData(__builtin_bswap16( vt-1), 2); @@ -79,12 +80,12 @@ namespace lgfx endWrite(); } - void Panel_SSD1963::setWindow(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) + void Panel_SSD1963::setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye) { set_window(xs, ys, xe, ye, CMD_RAMWR); } - void Panel_SSD1963::drawPixelPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t rawcolor) + void Panel_SSD1963::drawPixelPreclipped(uint_fast16_t x, uint_fast16_t y, uint32_t rawcolor) { bool tr = _in_transaction; if (!tr) begin_transaction(); @@ -95,16 +96,16 @@ namespace lgfx if (!tr) end_transaction(); } - void Panel_SSD1963::writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) + void Panel_SSD1963::writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t rawcolor) { - std::uint32_t len = w * h; - std::uint_fast16_t xe = w + x - 1; - std::uint_fast16_t ye = y + h - 1; + uint32_t len = w * h; + uint_fast16_t xe = w + x - 1; + uint_fast16_t ye = y + h - 1; set_window(x, y, xe, ye, CMD_RAMWR); _bus->writeDataRepeat(rawcolor, _write_bits, len); } - void Panel_SSD1963::setRotation(std::uint_fast8_t r) + void Panel_SSD1963::setRotation(uint_fast8_t r) { r &= 7; _rotation = r; @@ -122,9 +123,9 @@ namespace lgfx update_madctl(); } - void Panel_SSD1963::set_window(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye, std::uint32_t cmd) + void Panel_SSD1963::set_window(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye, uint32_t cmd) { - std::uint_fast8_t rb = 1u << _internal_rotation; + uint_fast8_t rb = 1u << _internal_rotation; if (_internal_rotation & 1) { std::swap(xs, ys); diff --git a/src/lgfx/v1/panel/Panel_SSD1963.hpp b/src/lgfx/v1/panel/Panel_SSD1963.hpp index 6b1163b..7ff63a0 100644 --- a/src/lgfx/v1/panel/Panel_SSD1963.hpp +++ b/src/lgfx/v1/panel/Panel_SSD1963.hpp @@ -35,28 +35,28 @@ namespace lgfx _read_depth = rgb888_3Byte; } - void setHSync(std::uint_fast16_t front, std::uint_fast16_t sync, std::uint_fast16_t back, std::uint_fast16_t move = 0, std::uint_fast16_t lpspp = 0); - void setVSync(std::uint_fast16_t front, std::uint_fast16_t sync, std::uint_fast16_t back, std::uint_fast16_t move = 0); + void setHSync(uint_fast16_t front, uint_fast16_t sync, uint_fast16_t back, uint_fast16_t move = 0, uint_fast16_t lpspp = 0); + void setVSync(uint_fast16_t front, uint_fast16_t sync, uint_fast16_t back, uint_fast16_t move = 0); bool init(bool use_reset) override; - void setWindow(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye) override; - void drawPixelPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint32_t rawcolor) override; - void writeFillRectPreclipped(std::uint_fast16_t x, std::uint_fast16_t y, std::uint_fast16_t w, std::uint_fast16_t h, std::uint32_t rawcolor) override; - void setRotation(std::uint_fast8_t r) override; + void setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye) override; + void drawPixelPreclipped(uint_fast16_t x, uint_fast16_t y, uint32_t rawcolor) override; + void writeFillRectPreclipped(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, uint32_t rawcolor) override; + void setRotation(uint_fast8_t r) override; protected: - void set_window(std::uint_fast16_t xs, std::uint_fast16_t ys, std::uint_fast16_t xe, std::uint_fast16_t ye, std::uint32_t cmd); + void set_window(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye, uint32_t cmd); - void setColorDepth_impl(color_depth_t depth) override + void setColorDepth_impl(color_depth_t) override { _write_depth = rgb888_3Byte; _read_depth = _write_depth; } - const std::uint8_t* getInitCommands(std::uint8_t listno) const override + const uint8_t* getInitCommands(uint8_t listno) const override { - static constexpr std::uint8_t list0[] = + static constexpr uint8_t list0[] = { 0x01, 0+CMD_INIT_DELAY, 100, // software reset //PLL multiplier, set PLL clock to 120M diff --git a/src/lgfx/v1/panel/Panel_ST7735.hpp b/src/lgfx/v1/panel/Panel_ST7735.hpp index c714164..a4684ed 100644 --- a/src/lgfx/v1/panel/Panel_ST7735.hpp +++ b/src/lgfx/v1/panel/Panel_ST7735.hpp @@ -43,31 +43,31 @@ namespace lgfx protected: - static constexpr std::uint8_t CMD_FRMCTR1 = 0xB1; - static constexpr std::uint8_t CMD_FRMCTR2 = 0xB2; - static constexpr std::uint8_t CMD_FRMCTR3 = 0xB3; - static constexpr std::uint8_t CMD_INVCTR = 0xB4; - static constexpr std::uint8_t CMD_DISSET5 = 0xB6; - - static constexpr std::uint8_t CMD_PWCTR1 = 0xC0; - static constexpr std::uint8_t CMD_PWCTR2 = 0xC1; - static constexpr std::uint8_t CMD_PWCTR3 = 0xC2; - static constexpr std::uint8_t CMD_PWCTR4 = 0xC3; - static constexpr std::uint8_t CMD_PWCTR5 = 0xC4; - static constexpr std::uint8_t CMD_VMCTR1 = 0xC5; - - static constexpr std::uint8_t CMD_RDID1 = 0xDA; - static constexpr std::uint8_t CMD_RDID2 = 0xDB; - static constexpr std::uint8_t CMD_RDID3 = 0xDC; - static constexpr std::uint8_t CMD_RDID4 = 0xDD; - - static constexpr std::uint8_t CMD_PWCTR6 = 0xFC; - - static constexpr std::uint8_t CMD_GMCTRP1 = 0xE0; - static constexpr std::uint8_t CMD_GMCTRN1 = 0xE1; - - const std::uint8_t* getInitCommands(std::uint8_t listno) const override { - static constexpr std::uint8_t Bcmd[] = { // Initialization commands for 7735B screens + static constexpr uint8_t CMD_FRMCTR1 = 0xB1; + static constexpr uint8_t CMD_FRMCTR2 = 0xB2; + static constexpr uint8_t CMD_FRMCTR3 = 0xB3; + static constexpr uint8_t CMD_INVCTR = 0xB4; + static constexpr uint8_t CMD_DISSET5 = 0xB6; + + static constexpr uint8_t CMD_PWCTR1 = 0xC0; + static constexpr uint8_t CMD_PWCTR2 = 0xC1; + static constexpr uint8_t CMD_PWCTR3 = 0xC2; + static constexpr uint8_t CMD_PWCTR4 = 0xC3; + static constexpr uint8_t CMD_PWCTR5 = 0xC4; + static constexpr uint8_t CMD_VMCTR1 = 0xC5; + + static constexpr uint8_t CMD_RDID1 = 0xDA; + static constexpr uint8_t CMD_RDID2 = 0xDB; + static constexpr uint8_t CMD_RDID3 = 0xDC; + static constexpr uint8_t CMD_RDID4 = 0xDD; + + static constexpr uint8_t CMD_PWCTR6 = 0xFC; + + static constexpr uint8_t CMD_GMCTRP1 = 0xE0; + static constexpr uint8_t CMD_GMCTRN1 = 0xE1; + + const uint8_t* getInitCommands(uint8_t listno) const override { + static constexpr uint8_t Bcmd[] = { // Initialization commands for 7735B screens CMD_SWRESET, CMD_INIT_DELAY, 50, // Software reset, no args, w/delay CMD_SLPOUT , CMD_INIT_DELAY, 255, // Out of sleep mode, no args, w/delay CMD_FRMCTR1, 3+CMD_INIT_DELAY, // Frame rate control, 3 args + delay: @@ -123,9 +123,9 @@ namespace lgfx struct Panel_ST7735S : public Panel_ST7735 { protected: - const std::uint8_t* getInitCommands(std::uint8_t listno) const override { + const uint8_t* getInitCommands(uint8_t listno) const override { - static constexpr std::uint8_t Rcmd1[] = { // Init for 7735R, part 1 (red or green tab) + static constexpr uint8_t Rcmd1[] = { // Init for 7735R, part 1 (red or green tab) CMD_SWRESET, CMD_INIT_DELAY, // 1: Software reset, 0 args, w/delay 150, // 150 ms delay CMD_SLPOUT , CMD_INIT_DELAY, // 2: Out of sleep mode, 0 args, w/delay @@ -157,7 +157,7 @@ namespace lgfx 0x0E, 0xFF,0xFF }; - static constexpr std::uint8_t Rcmd2[] = { // Init for 7735R, part 2 (red or green tab) + static constexpr uint8_t Rcmd2[] = { // Init for 7735R, part 2 (red or green tab) CMD_GMCTRP1, 16 , // 1: 16 args, no delay: 0x02, 0x1c, 0x07, 0x12, 0x37, 0x32, 0x29, 0x2d, diff --git a/src/lgfx/v1/panel/Panel_ST7789.hpp b/src/lgfx/v1/panel/Panel_ST7789.hpp index dd091ca..bf93edb 100644 --- a/src/lgfx/v1/panel/Panel_ST7789.hpp +++ b/src/lgfx/v1/panel/Panel_ST7789.hpp @@ -36,20 +36,20 @@ namespace lgfx protected: - static constexpr std::uint8_t CMD_PORCTRL = 0xB2; // Porch control - static constexpr std::uint8_t CMD_GCTRL = 0xB7; // Gate control - static constexpr std::uint8_t CMD_VCOMS = 0xBB; // VCOMS setting - static constexpr std::uint8_t CMD_LCMCTRL = 0xC0; // LCM control - static constexpr std::uint8_t CMD_VDVVRHEN = 0xC2; // VDV and VRH command enable - static constexpr std::uint8_t CMD_VRHS = 0xC3; // VRH set - static constexpr std::uint8_t CMD_VDVSET = 0xC4; // VDV setting - static constexpr std::uint8_t CMD_FRCTR2 = 0xC6; // FR Control 2 - static constexpr std::uint8_t CMD_PWCTRL1 = 0xD0; // Power control 1 - static constexpr std::uint8_t CMD_PVGAMCTRL= 0xE0; // Positive voltage gamma control - static constexpr std::uint8_t CMD_NVGAMCTRL= 0xE1; // Negative voltage gamma control + static constexpr uint8_t CMD_PORCTRL = 0xB2; // Porch control + static constexpr uint8_t CMD_GCTRL = 0xB7; // Gate control + static constexpr uint8_t CMD_VCOMS = 0xBB; // VCOMS setting + static constexpr uint8_t CMD_LCMCTRL = 0xC0; // LCM control + static constexpr uint8_t CMD_VDVVRHEN = 0xC2; // VDV and VRH command enable + static constexpr uint8_t CMD_VRHS = 0xC3; // VRH set + static constexpr uint8_t CMD_VDVSET = 0xC4; // VDV setting + static constexpr uint8_t CMD_FRCTR2 = 0xC6; // FR Control 2 + static constexpr uint8_t CMD_PWCTRL1 = 0xD0; // Power control 1 + static constexpr uint8_t CMD_PVGAMCTRL= 0xE0; // Positive voltage gamma control + static constexpr uint8_t CMD_NVGAMCTRL= 0xE1; // Negative voltage gamma control - const std::uint8_t* getInitCommands(std::uint8_t listno) const override { - static constexpr std::uint8_t list0[] = { + const uint8_t* getInitCommands(uint8_t listno) const override { + static constexpr uint8_t list0[] = { // CMD_SLPOUT , CMD_INIT_DELAY, 120, // CMD_NORON , CMD_INIT_DELAY, 0, // 0xB6 , 2, 0x0A,0x82, diff --git a/src/lgfx/v1/panel/Panel_ST7796.hpp b/src/lgfx/v1/panel/Panel_ST7796.hpp index 74915ee..c7568fb 100644 --- a/src/lgfx/v1/panel/Panel_ST7796.hpp +++ b/src/lgfx/v1/panel/Panel_ST7796.hpp @@ -37,25 +37,25 @@ namespace lgfx protected: - static constexpr std::uint8_t CMD_FRMCTR1 = 0xB1; - static constexpr std::uint8_t CMD_FRMCTR2 = 0xB2; - static constexpr std::uint8_t CMD_FRMCTR3 = 0xB3; - static constexpr std::uint8_t CMD_INVCTR = 0xB4; - static constexpr std::uint8_t CMD_DFUNCTR = 0xB6; - static constexpr std::uint8_t CMD_ETMOD = 0xB7; - static constexpr std::uint8_t CMD_PWCTR1 = 0xC0; - static constexpr std::uint8_t CMD_PWCTR2 = 0xC1; - static constexpr std::uint8_t CMD_PWCTR3 = 0xC2; - static constexpr std::uint8_t CMD_PWCTR4 = 0xC3; - static constexpr std::uint8_t CMD_PWCTR5 = 0xC4; - static constexpr std::uint8_t CMD_VMCTR = 0xC5; - static constexpr std::uint8_t CMD_GMCTRP1 = 0xE0; // Positive Gamma Correction - static constexpr std::uint8_t CMD_GMCTRN1 = 0xE1; // Negative Gamma Correction - static constexpr std::uint8_t CMD_DOCA = 0xE8; // Display Output Ctrl Adjust - static constexpr std::uint8_t CMD_CSCON = 0xF0; // Command Set Control + static constexpr uint8_t CMD_FRMCTR1 = 0xB1; + static constexpr uint8_t CMD_FRMCTR2 = 0xB2; + static constexpr uint8_t CMD_FRMCTR3 = 0xB3; + static constexpr uint8_t CMD_INVCTR = 0xB4; + static constexpr uint8_t CMD_DFUNCTR = 0xB6; + static constexpr uint8_t CMD_ETMOD = 0xB7; + static constexpr uint8_t CMD_PWCTR1 = 0xC0; + static constexpr uint8_t CMD_PWCTR2 = 0xC1; + static constexpr uint8_t CMD_PWCTR3 = 0xC2; + static constexpr uint8_t CMD_PWCTR4 = 0xC3; + static constexpr uint8_t CMD_PWCTR5 = 0xC4; + static constexpr uint8_t CMD_VMCTR = 0xC5; + static constexpr uint8_t CMD_GMCTRP1 = 0xE0; // Positive Gamma Correction + static constexpr uint8_t CMD_GMCTRN1 = 0xE1; // Negative Gamma Correction + static constexpr uint8_t CMD_DOCA = 0xE8; // Display Output Ctrl Adjust + static constexpr uint8_t CMD_CSCON = 0xF0; // Command Set Control - const std::uint8_t* getInitCommands(std::uint8_t listno) const override { - static constexpr std::uint8_t list0[] = { + const uint8_t* getInitCommands(uint8_t listno) const override { + static constexpr uint8_t list0[] = { CMD_CSCON, 1, 0xC3, // Enable extension command 2 partI CMD_CSCON, 1, 0x96, // Enable extension command 2 partII CMD_INVCTR, 1, 0x01, //1-dot inversion diff --git a/src/lgfx/v1/platforms/arduino_default/Bus_SPI.cpp b/src/lgfx/v1/platforms/arduino_default/Bus_SPI.cpp index 0cc89a2..94a6dcd 100644 --- a/src/lgfx/v1/platforms/arduino_default/Bus_SPI.cpp +++ b/src/lgfx/v1/platforms/arduino_default/Bus_SPI.cpp @@ -15,11 +15,13 @@ Original Source: [mongonta0716](https://github.com/mongonta0716) [tobozo](https://github.com/tobozo) /----------------------------------------------------------------------------*/ -#if defined (ESP32) || defined (CONFIG_IDF_TARGET_ESP32) || defined (CONFIG_IDF_TARGET_ESP32S2) || defined (ESP_PLATFORM) +#if defined (ESP_PLATFORM) #elif defined (ESP8266) #elif defined (__SAMD21__) || defined (__SAMD51__) #elif defined (STM32F2xx) || defined (STM32F4xx) || defined (STM32F7xx) -#elif defined ( ARDUINO ) +#elif defined (ARDUINO_ARCH_SPRESENSE) +#elif defined (ARDUINO_ARCH_MBED_RP2040) || defined(ARDUINO_ARCH_RP2040) +#elif defined (ARDUINO) #include "Bus_SPI.hpp" #include "../../misc/pixelcopy.hpp" @@ -47,13 +49,14 @@ namespace lgfx { dc_h(); pinMode(_cfg.pin_dc, pin_mode_t::output); - SPI.pins(_cfg.pin_sclk, _cfg.pin_miso, _cfg.pin_mosi, -1); + //SPI.pins(_cfg.pin_sclk, _cfg.pin_miso, _cfg.pin_mosi, -1); SPI.begin(); return true; } void Bus_SPI::release(void) { + SPI.end(); } void Bus_SPI::beginTransaction(void) @@ -93,76 +96,77 @@ namespace lgfx return false; } - bool Bus_SPI::writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) + bool Bus_SPI::writeCommand(uint32_t data, uint_fast8_t bit_length) { dc_l(); - do - { - SPI.transfer(data); - data >>= 8; - } while (bit_length -= 8); + SPI.transfer((uint8_t*)&data, bit_length >> 3); dc_h(); return true; } - void Bus_SPI::writeData(std::uint32_t data, std::uint_fast8_t bit_length) + void Bus_SPI::writeData(uint32_t data, uint_fast8_t bit_length) { - do - { - SPI.transfer(data); - data >>= 8; - } while (bit_length -= 8); + SPI.transfer((uint8_t*)&data, bit_length >> 3); } - void Bus_SPI::writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t length) + void Bus_SPI::writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t length) { - const std::uint8_t dst_bytes = bit_length >> 3; - std::uint32_t limit = (dst_bytes == 3) ? 12 : 16; - auto dmabuf = _flip_buffer.getBuffer(512); - std::size_t fillpos = 0; - reinterpret_cast(dmabuf)[0] = data; +/* + auto bytes = bit_length >> 3; + do + { + SPI.send(reinterpret_cast(&data), bytes); + } while (--length); +/*/ + const uint8_t dst_bytes = bit_length >> 3; + uint32_t limit = (dst_bytes == 3) ? 12 : 16; + auto buf = _flip_buffer.getBuffer(512); + size_t fillpos = 0; + reinterpret_cast(buf)[0] = data; fillpos += dst_bytes; - std::uint32_t len; + uint32_t len; do { len = ((length - 1) % limit) + 1; - if (limit <= 256) limit <<= 1; + if (limit <= 64) limit <<= 1; while (fillpos < len * dst_bytes) { - memcpy(&dmabuf[fillpos], dmabuf, fillpos); + memcpy(&buf[fillpos], buf, fillpos); fillpos += fillpos; } - writeBytes(dmabuf, len * dst_bytes, true, true); + SPI.transfer(buf, len * dst_bytes); } while (length -= len); +//*/ } - void Bus_SPI::writePixels(pixelcopy_t* param, std::uint32_t length) + void Bus_SPI::writePixels(pixelcopy_t* param, uint32_t length) { - const std::uint8_t dst_bytes = param->dst_bits >> 3; - std::uint32_t limit = (dst_bytes == 3) ? 12 : 16; - std::uint32_t len; + const uint8_t dst_bytes = param->dst_bits >> 3; + uint32_t limit = (dst_bytes == 3) ? 12 : 16; + uint32_t len; do { len = ((length - 1) % limit) + 1; - if (limit <= 256) limit <<= 1; - auto dmabuf = _flip_buffer.getBuffer(len * dst_bytes); - param->fp_copy(dmabuf, 0, len, param); - writeBytes(dmabuf, len * dst_bytes, true, true); + if (limit <= 32) limit <<= 1; + auto buf = _flip_buffer.getBuffer(len * dst_bytes); + param->fp_copy(buf, 0, len, param); + SPI.transfer(buf, len * dst_bytes); } while (length -= len); } - void Bus_SPI::writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) + void Bus_SPI::writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) { if (dc) dc_h(); else dc_l(); - SPI.transfer(const_cast(data), length); + SPI.transfer(const_cast(data), length); + if (!dc) dc_h(); } - std::uint32_t Bus_SPI::readData(std::uint_fast8_t bit_length) + uint32_t Bus_SPI::readData(uint_fast8_t bit_length) { - std::uint32_t res = 0; + uint32_t res = 0; bit_length >>= 3; if (!bit_length) return res; int idx = 0; @@ -174,7 +178,7 @@ namespace lgfx return res; } - bool Bus_SPI::readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma) + bool Bus_SPI::readBytes(uint8_t* dst, uint32_t length, bool use_dma) { do { @@ -184,16 +188,16 @@ namespace lgfx return true; } - void Bus_SPI::readPixels(void* dst, pixelcopy_t* param, std::uint32_t length) + void Bus_SPI::readPixels(void* dst, pixelcopy_t* param, uint32_t length) { - std::uint32_t bytes = param->src_bits >> 3; - std::uint32_t dstindex = 0; - std::uint32_t len = 4; - std::uint8_t buf[24]; + uint32_t bytes = param->src_bits >> 3; + uint32_t dstindex = 0; + uint32_t len = 4; + uint8_t buf[24]; param->src_data = buf; do { if (len > length) len = length; - readBytes((std::uint8_t*)buf, len * bytes, true); + readBytes((uint8_t*)buf, len * bytes, true); param->src_x = 0; dstindex = param->fp_copy(dst, dstindex, dstindex + len, param); length -= len; diff --git a/src/lgfx/v1/platforms/arduino_default/Bus_SPI.hpp b/src/lgfx/v1/platforms/arduino_default/Bus_SPI.hpp index cdb47c0..f9e4f02 100644 --- a/src/lgfx/v1/platforms/arduino_default/Bus_SPI.hpp +++ b/src/lgfx/v1/platforms/arduino_default/Bus_SPI.hpp @@ -17,7 +17,7 @@ Original Source: /----------------------------------------------------------------------------*/ #pragma once -#include +#include #include "../../Bus.hpp" #include "../common.hpp" @@ -33,15 +33,15 @@ namespace lgfx public: struct config_t { - std::uint32_t freq_write = 16000000; - std::uint32_t freq_read = 8000000; + uint32_t freq_write = 16000000; + uint32_t freq_read = 8000000; //bool spi_3wire = true; //bool use_lock = true; - std::int16_t pin_sclk = -1; - std::int16_t pin_miso = -1; - std::int16_t pin_mosi = -1; - std::int16_t pin_dc = -1; - std::uint8_t spi_mode = 0; + int16_t pin_sclk = -1; + int16_t pin_miso = -1; + int16_t pin_mosi = -1; + int16_t pin_dc = -1; + uint8_t spi_mode = 0; }; const config_t& config(void) const { return _cfg; } @@ -58,23 +58,23 @@ namespace lgfx void wait(void) override; bool busy(void) const override; - bool writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) override; - void writeData(std::uint32_t data, std::uint_fast8_t bit_length) override; - void writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t count) override; - void writePixels(pixelcopy_t* param, std::uint32_t length) override; - void writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) override; + bool writeCommand(uint32_t data, uint_fast8_t bit_length) override; + void writeData(uint32_t data, uint_fast8_t bit_length) override; + void writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t count) override; + void writePixels(pixelcopy_t* param, uint32_t length) override; + void writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) override; void initDMA(void) {} void flush(void) {} - void addDMAQueue(const std::uint8_t* data, std::uint32_t length) override { writeBytes(data, length, true, true); } + void addDMAQueue(const uint8_t* data, uint32_t length) override { writeBytes(data, length, true, true); } void execDMAQueue(void) {} - std::uint8_t* getDMABuffer(std::uint32_t length) override { return _flip_buffer.getBuffer(length); } + uint8_t* getDMABuffer(uint32_t length) override { return _flip_buffer.getBuffer(length); } void beginRead(void) override; void endRead(void) override; - std::uint32_t readData(std::uint_fast8_t bit_length) override; - bool readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma) override; - void readPixels(void* dst, pixelcopy_t* param, std::uint32_t length) override; + uint32_t readData(uint_fast8_t bit_length) override; + bool readBytes(uint8_t* dst, uint32_t length, bool use_dma) override; + void readPixels(void* dst, pixelcopy_t* param, uint32_t length) override; private: @@ -88,12 +88,12 @@ namespace lgfx config_t _cfg; FlipBuffer _flip_buffer; bool _need_wait; - std::uint32_t _mask_reg_dc; - std::uint32_t _last_apb_freq = -1; - std::uint32_t _clkdiv_write; - std::uint32_t _clkdiv_read; - volatile std::uint32_t* _gpio_reg_dc_h; - volatile std::uint32_t* _gpio_reg_dc_l; + uint32_t _mask_reg_dc; + uint32_t _last_apb_freq = -1; + uint32_t _clkdiv_write; + uint32_t _clkdiv_read; + volatile uint32_t* _gpio_reg_dc_h; + volatile uint32_t* _gpio_reg_dc_l; }; diff --git a/src/lgfx/v1/platforms/arduino_default/common.cpp b/src/lgfx/v1/platforms/arduino_default/common.cpp index 97c3fc3..9a9f0cb 100644 --- a/src/lgfx/v1/platforms/arduino_default/common.cpp +++ b/src/lgfx/v1/platforms/arduino_default/common.cpp @@ -15,11 +15,13 @@ Original Source: [mongonta0716](https://github.com/mongonta0716) [tobozo](https://github.com/tobozo) /----------------------------------------------------------------------------*/ -#if defined (ESP32) || defined (CONFIG_IDF_TARGET_ESP32) || defined (CONFIG_IDF_TARGET_ESP32S2) || defined (ESP_PLATFORM) +#if defined (ESP_PLATFORM) #elif defined (ESP8266) #elif defined (__SAMD21__) || defined (__SAMD51__) #elif defined (STM32F2xx) || defined (STM32F4xx) || defined (STM32F7xx) -#elif defined ( ARDUINO ) +#elif defined (ARDUINO_ARCH_SPRESENSE) +#elif defined (ARDUINO_ARCH_MBED_RP2040) || defined(ARDUINO_ARCH_RP2040) +#elif defined (ARDUINO) #include "common.hpp" @@ -29,7 +31,7 @@ namespace lgfx { //---------------------------------------------------------------------------- - void pinMode(std::int_fast16_t pin, pin_mode_t mode) + void pinMode(int_fast16_t pin, pin_mode_t mode) { switch (mode) { @@ -66,10 +68,10 @@ namespace lgfx { cpp::result init(int spi_host, int spi_sclk, int spi_miso, int spi_mosi) { return cpp::fail(error_t::unknown_err); } void release(int spi_host) {} - void beginTransaction(int spi_host, std::uint32_t freq, int spi_mode) {} + void beginTransaction(int spi_host, uint32_t freq, int spi_mode) {} void endTransaction(int spi_host) {} - void writeBytes(int spi_host, const std::uint8_t* data, std::size_t length) {} - void readBytes(int spi_host, std::uint8_t* data, std::size_t length) {} + void writeBytes(int spi_host, const uint8_t* data, size_t length) {} + void readBytes(int spi_host, uint8_t* data, size_t length) {} } //---------------------------------------------------------------------------- @@ -79,20 +81,20 @@ namespace lgfx { cpp::result init(int i2c_port, int pin_sda, int pin_scl) { return cpp::fail(error_t::unknown_err); } cpp::result release(int i2c_port) { return cpp::fail(error_t::unknown_err); } - cpp::result restart(int i2c_port, int i2c_addr, std::uint32_t freq, bool read) { return cpp::fail(error_t::unknown_err); } - cpp::result beginTransaction(int i2c_port, int i2c_addr, std::uint32_t freq, bool read) { return cpp::fail(error_t::unknown_err); } + cpp::result restart(int i2c_port, int i2c_addr, uint32_t freq, bool read) { return cpp::fail(error_t::unknown_err); } + cpp::result beginTransaction(int i2c_port, int i2c_addr, uint32_t freq, bool read) { return cpp::fail(error_t::unknown_err); } cpp::result endTransaction(int i2c_port) { return cpp::fail(error_t::unknown_err); } - cpp::result writeBytes(int i2c_port, const std::uint8_t *data, std::size_t length) { return cpp::fail(error_t::unknown_err); } - cpp::result readBytes(int i2c_port, std::uint8_t *data, std::size_t length) { return cpp::fail(error_t::unknown_err); } + cpp::result writeBytes(int i2c_port, const uint8_t *data, size_t length) { return cpp::fail(error_t::unknown_err); } + cpp::result readBytes(int i2c_port, uint8_t *data, size_t length) { return cpp::fail(error_t::unknown_err); } //-------- - cpp::result transactionWrite(int i2c_port, int addr, const std::uint8_t *writedata, std::uint8_t writelen, std::uint32_t freq) { return cpp::fail(error_t::unknown_err); } - cpp::result transactionRead(int i2c_port, int addr, std::uint8_t *readdata, std::uint8_t readlen, std::uint32_t freq) { return cpp::fail(error_t::unknown_err); } - cpp::result transactionWriteRead(int i2c_port, int addr, const std::uint8_t *writedata, std::uint8_t writelen, std::uint8_t *readdata, std::size_t readlen, std::uint32_t freq) { return cpp::fail(error_t::unknown_err); } + cpp::result transactionWrite(int i2c_port, int addr, const uint8_t *writedata, uint8_t writelen, uint32_t freq) { return cpp::fail(error_t::unknown_err); } + cpp::result transactionRead(int i2c_port, int addr, uint8_t *readdata, uint8_t readlen, uint32_t freq) { return cpp::fail(error_t::unknown_err); } + cpp::result transactionWriteRead(int i2c_port, int addr, const uint8_t *writedata, uint8_t writelen, uint8_t *readdata, size_t readlen, uint32_t freq) { return cpp::fail(error_t::unknown_err); } - cpp::result readRegister8(int i2c_port, int addr, std::uint8_t reg, std::uint32_t freq) { return cpp::fail(error_t::unknown_err); } - cpp::result writeRegister8(int i2c_port, int addr, std::uint8_t reg, std::uint8_t data, std::uint8_t mask, std::uint32_t freq) { return cpp::fail(error_t::unknown_err); } + cpp::result readRegister8(int i2c_port, int addr, uint8_t reg, uint32_t freq) { return cpp::fail(error_t::unknown_err); } + cpp::result writeRegister8(int i2c_port, int addr, uint8_t reg, uint8_t data, uint8_t mask, uint32_t freq) { return cpp::fail(error_t::unknown_err); } } //---------------------------------------------------------------------------- diff --git a/src/lgfx/v1/platforms/arduino_default/common.hpp b/src/lgfx/v1/platforms/arduino_default/common.hpp index fe603f5..4b83fa5 100644 --- a/src/lgfx/v1/platforms/arduino_default/common.hpp +++ b/src/lgfx/v1/platforms/arduino_default/common.hpp @@ -21,9 +21,19 @@ Original Source: #include "../../misc/enum.hpp" #include "../../../utility/result.hpp" +#if defined ( CONFIG_ARCH_BOARD_SPRESENSE ) +#include +#else #include +#endif #include +#ifdef min +#undef min +#endif +#ifdef max +#undef max +#endif namespace lgfx { @@ -57,9 +67,9 @@ namespace lgfx static inline void* heap_alloc_dma( size_t length) { return malloc(length); } // aligned_alloc(16, length); static inline void heap_free(void* buf) { free(buf); } - static inline void gpio_hi(std::uint32_t pin) { digitalWrite(pin, HIGH); } - static inline void gpio_lo(std::uint32_t pin) { digitalWrite(pin, LOW); } - static inline bool gpio_in(std::uint32_t pin) { return digitalRead(pin); } + static inline void gpio_hi(uint32_t pin) { digitalWrite(pin, HIGH); } + static inline void gpio_lo(uint32_t pin) { digitalWrite(pin, LOW); } + static inline bool gpio_in(uint32_t pin) { return digitalRead(pin); } enum pin_mode_t { output @@ -68,8 +78,8 @@ namespace lgfx , input_pulldown }; - void pinMode(std::int_fast16_t pin, pin_mode_t mode); - inline void lgfxPinMode(std::int_fast16_t pin, pin_mode_t mode) + void pinMode(int_fast16_t pin, pin_mode_t mode); + inline void lgfxPinMode(int_fast16_t pin, pin_mode_t mode) { pinMode(pin, mode); } @@ -108,22 +118,22 @@ namespace lgfx return _file; } - int read(std::uint8_t *buf, std::uint32_t len) override { return _fp->read(buf, len); } - void skip(std::int32_t offset) override { seek(offset, SeekCur); } - bool seek(std::uint32_t offset) override { return seek(offset, SeekSet); } - bool seek(std::uint32_t offset, SeekMode mode) { return _fp->seek(offset, mode); } + int read(uint8_t *buf, uint32_t len) override { return _fp->read(buf, len); } + void skip(int32_t offset) override { seek(offset, SeekCur); } + bool seek(uint32_t offset) override { return seek(offset, SeekSet); } + bool seek(uint32_t offset, SeekMode mode) { return _fp->seek(offset, mode); } void close() override { _fp->close(); } - std::int32_t tell(void) override { return _fp->position(); } + int32_t tell(void) override { return _fp->position(); } #else // dummy. bool open(const char*) override { return false; } - int read(std::uint8_t*, std::uint32_t) override { return 0; } - void skip(std::int32_t) override { } - bool seek(std::uint32_t) override { return false; } - bool seek(std::uint32_t, int) { return false; } + int read(uint8_t*, uint32_t) override { return 0; } + void skip(int32_t) override { } + bool seek(uint32_t) override { return false; } + bool seek(uint32_t, int) { return false; } void close() override { } - std::int32_t tell(void) override { return 0; } + int32_t tell(void) override { return 0; } #endif @@ -135,22 +145,22 @@ namespace lgfx struct StreamWrapper : public DataWrapper { - void set(Stream* src, std::uint32_t length = ~0u) { _stream = src; _length = length; _index = 0; } + void set(Stream* src, uint32_t length = ~0u) { _stream = src; _length = length; _index = 0; } - int read(std::uint8_t *buf, std::uint32_t len) override { + int read(uint8_t *buf, uint32_t len) override { if (len > _length - _index) { len = _length - _index; } _index += len; return _stream->readBytes((char*)buf, len); } - void skip(std::int32_t offset) override { if (0 < offset) { char dummy[offset]; _stream->readBytes(dummy, offset); _index += offset; } } - bool seek(std::uint32_t offset) override { if (offset < _index) { return false; } skip(offset - _index); return true; } + void skip(int32_t offset) override { if (0 < offset) { char dummy[offset]; _stream->readBytes(dummy, offset); _index += offset; } } + bool seek(uint32_t offset) override { if (offset < _index) { return false; } skip(offset - _index); return true; } void close() override { } - std::int32_t tell(void) override { return _index; } + int32_t tell(void) override { return _index; } private: Stream* _stream; - std::uint32_t _index; - std::uint32_t _length = 0; + uint32_t _index; + uint32_t _length = 0; }; diff --git a/src/lgfx/v1/platforms/common.hpp b/src/lgfx/v1/platforms/common.hpp index 7e3b08b..c0b51a7 100644 --- a/src/lgfx/v1/platforms/common.hpp +++ b/src/lgfx/v1/platforms/common.hpp @@ -17,11 +17,11 @@ Original Source: /----------------------------------------------------------------------------*/ #pragma once -#if defined (ESP32) || defined (CONFIG_IDF_TARGET_ESP32) || defined (CONFIG_IDF_TARGET_ESP32S2) || defined (ESP_PLATFORM) +#if defined (ESP_PLATFORM) #include "esp32/common.hpp" -#elif defined ( ESP8266 ) +#elif defined (ESP8266) #include "esp8266/common.hpp" @@ -37,7 +37,15 @@ Original Source: #include "stm32/common.hpp" -#elif defined ( ARDUINO ) +#elif defined (ARDUINO_ARCH_SPRESENSE) + +#include "spresense/common.hpp" + +#elif defined (ARDUINO_ARCH_MBED_RP2040) || defined(ARDUINO_ARCH_RP2040) + +#include "rp2040/common.hpp" + +#elif defined (ARDUINO) #include "arduino_default/common.hpp" @@ -67,22 +75,22 @@ namespace lgfx } } - std::uint8_t* getBuffer(std::size_t length) + uint8_t* getBuffer(size_t length) { length = (length + 3) & ~3; if (_length != length) { if (_buffer) heap_free(_buffer); - _buffer = (std::uint8_t*)heap_alloc_dma(length); + _buffer = (uint8_t*)heap_alloc_dma(length); _length = _buffer ? length : 0; } return _buffer; } private: - std::uint8_t* _buffer = nullptr; - std::size_t _length = 0; + uint8_t* _buffer = nullptr; + size_t _length = 0; }; //---------------------------------------------------------------------------- @@ -97,7 +105,7 @@ namespace lgfx void deleteBuffer(void) { - for (std::size_t i = 0; i < 2; i++) + for (size_t i = 0; i < 2; i++) { _length[i] = 0; if (_buffer[i]) @@ -108,7 +116,7 @@ namespace lgfx } } - std::uint8_t* getBuffer(std::size_t length) + uint8_t* getBuffer(size_t length) { length = (length + 3) & ~3; _flip = !_flip; @@ -116,15 +124,15 @@ namespace lgfx if (_length[_flip] != length) { if (_buffer[_flip]) heap_free(_buffer[_flip]); - _buffer[_flip] = (std::uint8_t*)heap_alloc_dma(length); + _buffer[_flip] = (uint8_t*)heap_alloc_dma(length); _length[_flip] = _buffer[_flip] ? length : 0; } return _buffer[_flip]; } private: - std::uint8_t* _buffer[2] = { nullptr, nullptr }; - std::size_t _length[2] = { 0, 0 }; + uint8_t* _buffer[2] = { nullptr, nullptr }; + size_t _length[2] = { 0, 0 }; bool _flip = false; }; @@ -134,42 +142,42 @@ namespace lgfx { cpp::result init(int spi_host, int spi_sclk, int spi_miso, int spi_mosi); void release(int spi_host); - void beginTransaction(int spi_host, std::uint32_t freq, int spi_mode = 0); + void beginTransaction(int spi_host, uint32_t freq, int spi_mode = 0); void endTransaction(int spi_host); - void writeBytes(int spi_host, const std::uint8_t* data, std::size_t length); - void readBytes(int spi_host, std::uint8_t* data, std::size_t length); + void writeBytes(int spi_host, const uint8_t* data, size_t length); + void readBytes(int spi_host, uint8_t* data, size_t length); } namespace i2c { - static constexpr std::uint32_t I2C_DEFAULT_FREQ = 400000; + static constexpr uint32_t I2C_DEFAULT_FREQ = 400000; cpp::result init(int i2c_port, int pin_sda, int pin_scl); cpp::result release(int i2c_port); - cpp::result restart(int i2c_port, int i2c_addr, std::uint32_t freq, bool read = false); - cpp::result beginTransaction(int i2c_port, int i2c_addr, std::uint32_t freq, bool read = false); + cpp::result restart(int i2c_port, int i2c_addr, uint32_t freq, bool read = false); + cpp::result beginTransaction(int i2c_port, int i2c_addr, uint32_t freq, bool read = false); cpp::result endTransaction(int i2c_port); - cpp::result writeBytes(int i2c_port, const std::uint8_t *data, std::size_t length); - cpp::result readBytes(int i2c_port, std::uint8_t *data, std::size_t length); + cpp::result writeBytes(int i2c_port, const uint8_t *data, size_t length); + cpp::result readBytes(int i2c_port, uint8_t *data, size_t length); //-------- - cpp::result transactionWrite(int i2c_port, int addr, const std::uint8_t *writedata, std::uint8_t writelen, std::uint32_t freq = I2C_DEFAULT_FREQ); - cpp::result transactionRead(int i2c_port, int addr, std::uint8_t *readdata, std::uint8_t readlen, std::uint32_t freq = I2C_DEFAULT_FREQ); - cpp::result transactionWriteRead(int i2c_port, int addr, const std::uint8_t *writedata, std::uint8_t writelen, std::uint8_t *readdata, std::size_t readlen, std::uint32_t freq = I2C_DEFAULT_FREQ); + cpp::result transactionWrite(int i2c_port, int addr, const uint8_t *writedata, uint8_t writelen, uint32_t freq = I2C_DEFAULT_FREQ); + cpp::result transactionRead(int i2c_port, int addr, uint8_t *readdata, uint8_t readlen, uint32_t freq = I2C_DEFAULT_FREQ); + cpp::result transactionWriteRead(int i2c_port, int addr, const uint8_t *writedata, uint8_t writelen, uint8_t *readdata, size_t readlen, uint32_t freq = I2C_DEFAULT_FREQ); - cpp::result readRegister8(int i2c_port, int addr, std::uint8_t reg, std::uint32_t freq = I2C_DEFAULT_FREQ); - cpp::result writeRegister8(int i2c_port, int addr, std::uint8_t reg, std::uint8_t data, std::uint8_t mask = 0, std::uint32_t freq = I2C_DEFAULT_FREQ); + cpp::result readRegister8(int i2c_port, int addr, uint8_t reg, uint32_t freq = I2C_DEFAULT_FREQ); + cpp::result writeRegister8(int i2c_port, int addr, uint8_t reg, uint8_t data, uint8_t mask = 0, uint32_t freq = I2C_DEFAULT_FREQ); - inline cpp::result readRegister(int i2c_port, int addr, std::uint8_t reg, std::uint8_t* data, std::size_t len, std::uint32_t freq = I2C_DEFAULT_FREQ) + inline cpp::result readRegister(int i2c_port, int addr, uint8_t reg, uint8_t* data, size_t len, uint32_t freq = I2C_DEFAULT_FREQ) { return transactionWriteRead(i2c_port, addr, ®, 1, data, len, freq); } - inline cpp::result bitOn(int i2c_port, int addr, std::uint8_t reg, std::uint8_t bit, std::uint32_t freq = I2C_DEFAULT_FREQ) + inline cpp::result bitOn(int i2c_port, int addr, uint8_t reg, uint8_t bit, uint32_t freq = I2C_DEFAULT_FREQ) { return writeRegister8(i2c_port, addr, reg, bit, ~0, freq); } - inline cpp::result bitOff(int i2c_port, int addr, std::uint8_t reg, std::uint8_t bit, std::uint32_t freq = I2C_DEFAULT_FREQ) + inline cpp::result bitOff(int i2c_port, int addr, uint8_t reg, uint8_t bit, uint32_t freq = I2C_DEFAULT_FREQ) { return writeRegister8(i2c_port, addr, reg, 0, ~bit, freq); } diff --git a/src/lgfx/v1/platforms/device.hpp b/src/lgfx/v1/platforms/device.hpp index 9f487b6..a1b1e19 100644 --- a/src/lgfx/v1/platforms/device.hpp +++ b/src/lgfx/v1/platforms/device.hpp @@ -17,14 +17,33 @@ Original Source: /----------------------------------------------------------------------------*/ #pragma once -#if defined (ESP32) || defined (CONFIG_IDF_TARGET_ESP32) || defined (CONFIG_IDF_TARGET_ESP32S2) || defined (ESP_PLATFORM) +#if defined (ESP_PLATFORM) -#include "esp32/Light_PWM.hpp" -#include "esp32/Bus_SPI.hpp" -#include "esp32/Bus_I2C.hpp" -#include "esp32/Bus_Parallel8.hpp" + #include -#elif defined ( ESP8266 ) + #if defined (CONFIG_IDF_TARGET_ESP32C3) + + #include "esp32/Bus_SPI.hpp" + #include "esp32/Bus_I2C.hpp" + + #elif defined (CONFIG_IDF_TARGET_ESP32S2) + + #include "esp32/Light_PWM.hpp" + #include "esp32/Bus_SPI.hpp" + #include "esp32/Bus_I2C.hpp" + #include "esp32s2/Bus_Parallel8.hpp" + #include "esp32s2/Bus_Parallel16.hpp" + + #else + + #include "esp32/Light_PWM.hpp" + #include "esp32/Bus_SPI.hpp" + #include "esp32/Bus_I2C.hpp" + #include "esp32/Bus_Parallel8.hpp" + + #endif + +#elif defined (ESP8266) #include "esp8266/Bus_SPI.hpp" @@ -42,7 +61,15 @@ Original Source: #include "stm32/Bus_SPI.hpp" -#elif defined ( ARDUINO ) +#elif defined (ARDUINO_ARCH_SPRESENSE) + +#include "spresense/Bus_SPI.hpp" + +#elif defined (ARDUINO_ARCH_MBED_RP2040) || defined(ARDUINO_ARCH_RP2040) + +#include "rp2040/Bus_SPI.hpp" + +#elif defined (ARDUINO) #include "arduino_default/Bus_SPI.hpp" diff --git a/src/lgfx/v1/platforms/esp32/Bus_I2C.cpp b/src/lgfx/v1/platforms/esp32/Bus_I2C.cpp index c99dff7..f858b7a 100644 --- a/src/lgfx/v1/platforms/esp32/Bus_I2C.cpp +++ b/src/lgfx/v1/platforms/esp32/Bus_I2C.cpp @@ -15,7 +15,9 @@ Original Source: [mongonta0716](https://github.com/mongonta0716) [tobozo](https://github.com/tobozo) /----------------------------------------------------------------------------*/ -#if defined (ESP32) || defined (CONFIG_IDF_TARGET_ESP32) || defined (CONFIG_IDF_TARGET_ESP32S2) || defined (ESP_PLATFORM) +#if defined (ESP_PLATFORM) +#include +#if !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32) || defined (CONFIG_IDF_TARGET_ESP32S2) || defined (CONFIG_IDF_TARGET_ESP32C3) #include "Bus_I2C.hpp" #include "../../misc/pixelcopy.hpp" @@ -97,14 +99,24 @@ namespace lgfx void Bus_I2C::wait(void) { +#if defined (CONFIG_IDF_TARGET_ESP32C3) + auto dev = &I2C0; + while (dev->sr.bus_busy) { taskYIELD(); } +#else auto dev = (_cfg.i2c_port == 0) ? &I2C0 : &I2C1; while (dev->status_reg.bus_busy) { taskYIELD(); } +#endif } bool Bus_I2C::busy(void) const { +#if defined (CONFIG_IDF_TARGET_ESP32C3) + auto dev = &I2C0; + return dev->sr.bus_busy; +#else auto dev = (_cfg.i2c_port == 0) ? &I2C0 : &I2C1; return dev->status_reg.bus_busy; +#endif } void Bus_I2C::dc_control(bool dc) @@ -136,29 +148,29 @@ namespace lgfx lgfx::i2c::endTransaction(_cfg.i2c_port); lgfx::i2c::beginTransaction(_cfg.i2c_port, _cfg.i2c_addr, _cfg.freq_write, false); } - lgfx::i2c::writeBytes(_cfg.i2c_port, (std::uint8_t*)(dc ? &_cfg.prefix_data : &_cfg.prefix_cmd), _cfg.prefix_len); + lgfx::i2c::writeBytes(_cfg.i2c_port, (uint8_t*)(dc ? &_cfg.prefix_data : &_cfg.prefix_cmd), _cfg.prefix_len); _state = st; } - bool Bus_I2C::writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) + bool Bus_I2C::writeCommand(uint32_t data, uint_fast8_t bit_length) { dc_control(false); - return lgfx::i2c::writeBytes(_cfg.i2c_port, (std::uint8_t*)&data, (bit_length >> 3)).has_value(); + return lgfx::i2c::writeBytes(_cfg.i2c_port, (uint8_t*)&data, (bit_length >> 3)).has_value(); } - void Bus_I2C::writeData(std::uint32_t data, std::uint_fast8_t bit_length) + void Bus_I2C::writeData(uint32_t data, uint_fast8_t bit_length) { dc_control(true); - lgfx::i2c::writeBytes(_cfg.i2c_port, (std::uint8_t*)&data, (bit_length >> 3)); + lgfx::i2c::writeBytes(_cfg.i2c_port, (uint8_t*)&data, (bit_length >> 3)); } - void Bus_I2C::writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t length) + void Bus_I2C::writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t length) { dc_control(true); - const std::uint8_t dst_bytes = bit_length >> 3; - std::uint32_t buf0 = data | data << bit_length; - std::uint32_t buf1; - std::uint32_t buf2; + const uint8_t dst_bytes = bit_length >> 3; + uint32_t buf0 = data | data << bit_length; + uint32_t buf1; + uint32_t buf2; // make 12Bytes data. if (dst_bytes != 3) { @@ -174,10 +186,10 @@ namespace lgfx buf1 = buf0 >> 8 | buf0 << 16; buf2 = buf0 >> 16 | buf0 << 8; } - std::uint32_t src[8] = { buf0, buf1, buf2, buf0, buf1, buf2, buf0, buf1 }; - auto buf = reinterpret_cast(src); - std::uint32_t limit = 32 / dst_bytes; - std::uint32_t len; + uint32_t src[8] = { buf0, buf1, buf2, buf0, buf1, buf2, buf0, buf1 }; + auto buf = reinterpret_cast(src); + uint32_t limit = 32 / dst_bytes; + uint32_t len; do { len = ((length - 1) % limit) + 1; @@ -185,13 +197,13 @@ namespace lgfx } while (length -= len); } - void Bus_I2C::writePixels(pixelcopy_t* param, std::uint32_t length) + void Bus_I2C::writePixels(pixelcopy_t* param, uint32_t length) { dc_control(true); - const std::uint8_t dst_bytes = param->dst_bits >> 3; - std::uint32_t limit = 32 / dst_bytes; - std::uint32_t len; - std::uint8_t buf[32]; + const uint8_t dst_bytes = param->dst_bits >> 3; + uint32_t limit = 32 / dst_bytes; + uint32_t len; + uint8_t buf[32]; do { len = ((length - 1) % limit) + 1; @@ -200,39 +212,39 @@ namespace lgfx } while (length -= len); } - void Bus_I2C::writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) + void Bus_I2C::writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) { dc_control(dc); i2c::writeBytes(_cfg.i2c_port, data, length); } - std::uint32_t Bus_I2C::readData(std::uint_fast8_t bit_length) + uint32_t Bus_I2C::readData(uint_fast8_t bit_length) { beginRead(); - std::uint32_t res; - i2c::readBytes(_cfg.i2c_port, reinterpret_cast(&res), bit_length >> 3); + uint32_t res; + i2c::readBytes(_cfg.i2c_port, reinterpret_cast(&res), bit_length >> 3); return res; } - bool Bus_I2C::readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma) + bool Bus_I2C::readBytes(uint8_t* dst, uint32_t length, bool use_dma) { beginRead(); return i2c::readBytes(_cfg.i2c_port, dst, length).has_value(); } - void Bus_I2C::readPixels(void* dst, pixelcopy_t* param, std::uint32_t length) + void Bus_I2C::readPixels(void* dst, pixelcopy_t* param, uint32_t length) { beginRead(); const auto bytes = param->src_bits >> 3; - std::uint32_t regbuf[8]; - std::uint32_t limit = 32 / bytes; + uint32_t regbuf[8]; + uint32_t limit = 32 / bytes; param->src_data = regbuf; - std::int32_t dstindex = 0; + int32_t dstindex = 0; do { - std::uint32_t len = (limit > length) ? length : limit; + uint32_t len = (limit > length) ? length : limit; length -= len; - i2c::readBytes(_cfg.i2c_port, (std::uint8_t*)regbuf, len * bytes); + i2c::readBytes(_cfg.i2c_port, (uint8_t*)regbuf, len * bytes); param->src_x = 0; dstindex = param->fp_copy(dst, dstindex, dstindex + len, param); } while (length); @@ -243,3 +255,4 @@ namespace lgfx } #endif +#endif diff --git a/src/lgfx/v1/platforms/esp32/Bus_I2C.hpp b/src/lgfx/v1/platforms/esp32/Bus_I2C.hpp index 8ab4f08..6e3513d 100644 --- a/src/lgfx/v1/platforms/esp32/Bus_I2C.hpp +++ b/src/lgfx/v1/platforms/esp32/Bus_I2C.hpp @@ -31,15 +31,15 @@ namespace lgfx public: struct config_t { - std::uint32_t freq_write = 400000; - std::uint32_t freq_read = 400000; - std::int16_t pin_scl = 22; - std::int16_t pin_sda = 21; - std::uint8_t i2c_port = 0; // e.g. ESP32 0=I2C_NUM_0 / 1=I2C_NUM_1 - std::uint8_t i2c_addr = 0x3C; - std::uint32_t prefix_cmd = 0x00; - std::uint32_t prefix_data = 0x40; - std::uint32_t prefix_len = 1; + uint32_t freq_write = 400000; + uint32_t freq_read = 400000; + int16_t pin_scl = 22; + int16_t pin_sda = 21; + uint8_t i2c_port = 0; // e.g. ESP32 0=I2C_NUM_0 / 1=I2C_NUM_1 + uint8_t i2c_addr = 0x3C; + uint32_t prefix_cmd = 0x00; + uint32_t prefix_data = 0x40; + uint32_t prefix_len = 1; }; const config_t& config(void) const { return _cfg; } @@ -57,22 +57,22 @@ namespace lgfx bool busy(void) const override; void flush(void) override {} - bool writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) override; - void writeData(std::uint32_t data, std::uint_fast8_t bit_length) override; - void writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t count) override; - void writePixels(pixelcopy_t* param, std::uint32_t length) override; - void writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) override; + bool writeCommand(uint32_t data, uint_fast8_t bit_length) override; + void writeData(uint32_t data, uint_fast8_t bit_length) override; + void writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t count) override; + void writePixels(pixelcopy_t* param, uint32_t length) override; + void writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) override; void initDMA(void) {} - void addDMAQueue(const std::uint8_t* data, std::uint32_t length) override { writeBytes(data, length, true, true); } + void addDMAQueue(const uint8_t* data, uint32_t length) override { writeBytes(data, length, true, true); } void execDMAQueue(void) {} - std::uint8_t* getDMABuffer(std::uint32_t length) override { return _flip_buffer.getBuffer(length); } + uint8_t* getDMABuffer(uint32_t length) override { return _flip_buffer.getBuffer(length); } void beginRead(void) override; void endRead(void) override; - std::uint32_t readData(std::uint_fast8_t bit_length) override; - bool readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma) override; - void readPixels(void* dst, pixelcopy_t* param, std::uint32_t length) override; + uint32_t readData(uint_fast8_t bit_length) override; + bool readBytes(uint8_t* dst, uint32_t length, bool use_dma) override; + void readPixels(void* dst, pixelcopy_t* param, uint32_t length) override; protected: diff --git a/src/lgfx/v1/platforms/esp32/Bus_Parallel8.cpp b/src/lgfx/v1/platforms/esp32/Bus_Parallel8.cpp index 4e34be4..c05829b 100644 --- a/src/lgfx/v1/platforms/esp32/Bus_Parallel8.cpp +++ b/src/lgfx/v1/platforms/esp32/Bus_Parallel8.cpp @@ -15,12 +15,15 @@ Original Source: [mongonta0716](https://github.com/mongonta0716) [tobozo](https://github.com/tobozo) /----------------------------------------------------------------------------*/ -#if defined (ESP32) || defined (CONFIG_IDF_TARGET_ESP32) || defined (CONFIG_IDF_TARGET_ESP32S2) || defined (ESP_PLATFORM) +#if defined (ESP_PLATFORM) +#include +#if !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32) #include "Bus_Parallel8.hpp" #include "../../misc/pixelcopy.hpp" #include +#include namespace lgfx { @@ -28,28 +31,41 @@ namespace lgfx { //---------------------------------------------------------------------------- +#ifndef I2S_CLKA_ENA +#define I2S_CLKA_ENA (BIT(21)) +#endif + // #define SAFE_I2S_FIFO_WR_REG(i) (0x6000F000 + ((i)*0x1E000)) // #define SAFE_I2S_FIFO_RD_REG(i) (0x6000F004 + ((i)*0x1E000)) #define SAFE_I2S_FIFO_WR_REG(i) (0x3FF4F000 + ((i)*0x1E000)) #define SAFE_I2S_FIFO_RD_REG(i) (0x3FF4F004 + ((i)*0x1E000)) - static constexpr std::size_t CACHE_THRESH = 128; + static constexpr size_t CACHE_THRESH = 128; + + static constexpr uint32_t _conf_reg_default = I2S_TX_MSB_RIGHT | I2S_TX_RIGHT_FIRST | I2S_RX_RIGHT_FIRST; + static constexpr uint32_t _conf_reg_start = _conf_reg_default | I2S_TX_START; + static constexpr uint32_t _conf_reg_reset = _conf_reg_default | I2S_TX_RESET; + static constexpr uint32_t _sample_rate_conf_reg_32bit = 32 << I2S_TX_BITS_MOD_S | 32 << I2S_RX_BITS_MOD_S | 1 << I2S_TX_BCK_DIV_NUM_S | 1 << I2S_RX_BCK_DIV_NUM_S; + static constexpr uint32_t _sample_rate_conf_reg_16bit = 16 << I2S_TX_BITS_MOD_S | 16 << I2S_RX_BITS_MOD_S | 1 << I2S_TX_BCK_DIV_NUM_S | 1 << I2S_RX_BCK_DIV_NUM_S; + static constexpr uint32_t _fifo_conf_default = 1 << I2S_TX_FIFO_MOD | 1 << I2S_RX_FIFO_MOD | 32 << I2S_TX_DATA_NUM_S | 32 << I2S_RX_DATA_NUM_S; + static constexpr uint32_t _fifo_conf_dma = _fifo_conf_default | I2S_DSCR_EN; - static constexpr std::uint32_t _conf_reg_default = I2S_TX_MSB_RIGHT | I2S_TX_RIGHT_FIRST | I2S_RX_RIGHT_FIRST; - static constexpr std::uint32_t _conf_reg_start = _conf_reg_default | I2S_TX_START; - static constexpr std::uint32_t _conf_reg_reset = _conf_reg_default | I2S_TX_RESET; - static constexpr std::uint32_t _sample_rate_conf_reg_32bit = 32 << I2S_TX_BITS_MOD_S | 32 << I2S_RX_BITS_MOD_S | 1 << I2S_TX_BCK_DIV_NUM_S | 1 << I2S_RX_BCK_DIV_NUM_S; - static constexpr std::uint32_t _sample_rate_conf_reg_16bit = 16 << I2S_TX_BITS_MOD_S | 16 << I2S_RX_BITS_MOD_S | 1 << I2S_TX_BCK_DIV_NUM_S | 1 << I2S_RX_BCK_DIV_NUM_S; - static constexpr std::uint32_t _fifo_conf_default = 1 << I2S_TX_FIFO_MOD | 1 << I2S_RX_FIFO_MOD | 32 << I2S_TX_DATA_NUM_S | 32 << I2S_RX_DATA_NUM_S; - static constexpr std::uint32_t _fifo_conf_dma = _fifo_conf_default | I2S_DSCR_EN; + static __attribute__ ((always_inline)) inline volatile uint32_t* reg(uint32_t addr) { return (volatile uint32_t *)ETS_UNCACHED_ADDR(addr); } - static __attribute__ ((always_inline)) inline volatile std::uint32_t* reg(std::uint32_t addr) { return (volatile std::uint32_t *)ETS_UNCACHED_ADDR(addr); } + static i2s_dev_t* getDev(i2s_port_t port) + { +#if defined (CONFIG_IDF_TARGET_ESP32S2) + return &I2S0; +#else + return (port == 0) ? &I2S0 : &I2S1; +#endif + } void Bus_Parallel8::config(const config_t& cfg) { _cfg = cfg; auto port = cfg.i2s_port; - _dev = (port == 0) ? &I2S0 : &I2S1; + _dev = getDev(port); _i2s_fifo_wr_reg = reg(SAFE_I2S_FIFO_WR_REG(port)); @@ -70,7 +86,7 @@ namespace lgfx //Reset DMA i2s_dev->lc_conf.val = I2S_IN_RST | I2S_OUT_RST | I2S_AHBM_RST | I2S_AHBM_FIFO_RST; - i2s_dev->lc_conf.val = I2S_OUT_EOF_MODE; + i2s_dev->lc_conf.val = I2S_OUT_EOF_MODE | I2S_OUTDSCR_BURST_EN | I2S_OUT_DATA_BURST_EN; i2s_dev->in_link.val = 0; i2s_dev->out_link.val = 0; @@ -86,14 +102,28 @@ namespace lgfx void Bus_Parallel8::_init_pin(void) { - gpio_pad_select_gpio(_cfg.pin_d0); - gpio_pad_select_gpio(_cfg.pin_d1); - gpio_pad_select_gpio(_cfg.pin_d2); - gpio_pad_select_gpio(_cfg.pin_d3); - gpio_pad_select_gpio(_cfg.pin_d4); - gpio_pad_select_gpio(_cfg.pin_d5); - gpio_pad_select_gpio(_cfg.pin_d6); - gpio_pad_select_gpio(_cfg.pin_d7); + int8_t pins[] = + { _cfg.pin_d0 + , _cfg.pin_d1 + , _cfg.pin_d2 + , _cfg.pin_d3 + , _cfg.pin_d4 + , _cfg.pin_d5 + , _cfg.pin_d6 + , _cfg.pin_d7 + }; + +#if defined (CONFIG_IDF_TARGET_ESP32S2) + auto idx_base = I2S0O_DATA_OUT8_IDX; +#else + auto idx_base = (_cfg.i2s_port == I2S_NUM_0) ? I2S0O_DATA_OUT8_IDX : I2S1O_DATA_OUT8_IDX; +#endif + for (size_t i = 0; i < 8; ++i) + { + gpio_pad_select_gpio(pins[i]); + gpio_set_direction((gpio_num_t)pins[i], GPIO_MODE_INPUT_OUTPUT); + gpio_matrix_out(pins[i], idx_base + i, 0, 0); + } gpio_pad_select_gpio(_cfg.pin_rd); gpio_pad_select_gpio(_cfg.pin_wr); @@ -107,29 +137,24 @@ namespace lgfx gpio_set_direction((gpio_num_t)_cfg.pin_wr, GPIO_MODE_OUTPUT); gpio_set_direction((gpio_num_t)_cfg.pin_rs, GPIO_MODE_OUTPUT); - auto idx_base = (_cfg.i2s_port == I2S_NUM_0) ? I2S0O_DATA_OUT8_IDX : I2S1O_DATA_OUT8_IDX; gpio_matrix_out(_cfg.pin_rs, idx_base + 8, 0, 0); - gpio_matrix_out(_cfg.pin_d7, idx_base + 7, 0, 0); - gpio_matrix_out(_cfg.pin_d6, idx_base + 6, 0, 0); - gpio_matrix_out(_cfg.pin_d5, idx_base + 5, 0, 0); - gpio_matrix_out(_cfg.pin_d4, idx_base + 4, 0, 0); - gpio_matrix_out(_cfg.pin_d3, idx_base + 3, 0, 0); - gpio_matrix_out(_cfg.pin_d2, idx_base + 2, 0, 0); - gpio_matrix_out(_cfg.pin_d1, idx_base + 1, 0, 0); - gpio_matrix_out(_cfg.pin_d0, idx_base , 0, 0); - - std::uint32_t dport_clk_en; - std::uint32_t dport_rst; + + uint32_t dport_clk_en; + uint32_t dport_rst; if (_cfg.i2s_port == I2S_NUM_0) { idx_base = I2S0O_WS_OUT_IDX; dport_clk_en = DPORT_I2S0_CLK_EN; dport_rst = DPORT_I2S0_RST; - } else { + } +#if !defined (CONFIG_IDF_TARGET_ESP32S2) + else + { idx_base = I2S1O_WS_OUT_IDX; dport_clk_en = DPORT_I2S1_CLK_EN; dport_rst = DPORT_I2S1_RST; } +#endif gpio_matrix_out(_cfg.pin_wr, idx_base, 1, 0); // WR (Write-strobe in 8080 mode, Active-low) DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, dport_clk_en); @@ -141,7 +166,7 @@ namespace lgfx void Bus_Parallel8::beginTransaction(void) { - std::uint32_t freq_apb = getApbFrequency(); + uint32_t freq_apb = getApbFrequency(); if (_last_freq_apb != freq_apb) { _last_freq_apb = freq_apb; @@ -159,8 +184,9 @@ namespace lgfx *reg(I2S_CLKM_CONF_REG(_cfg.i2s_port)) = _clkdiv_write; auto i2s_dev = (i2s_dev_t*)_dev; + i2s_dev->out_link.val = 0; i2s_dev->sample_rate_conf.val = _sample_rate_conf_reg_16bit; - i2s_dev->fifo_conf.val = _fifo_conf_default; + i2s_dev->fifo_conf.val = _fifo_conf_dma; _cache_index = 0; _cache_flip = _cache[0]; @@ -179,10 +205,16 @@ namespace lgfx { //i2s_dev->int_clr.val = I2S_TX_REMPTY_INT_CLR; auto i2s_dev = (i2s_dev_t*)_dev; - auto conf_reg = _conf_reg_default | I2S_TX_RESET; - while (!i2s_dev->state.tx_idle) - {} - i2s_dev->conf.val = conf_reg; + if (i2s_dev->out_link.val) + { +#if defined (CONFIG_IDF_TARGET_ESP32S2) + while (!(i2s_dev->lc_state0.out_empty)) {} +#else + while (!(i2s_dev->lc_state0 & 0x80000000)) {} // I2S_OUT_EMPTY +#endif + i2s_dev->out_link.val = 0; + } + while (!i2s_dev->state.tx_idle) {} } void Bus_Parallel8::wait(void) @@ -193,7 +225,13 @@ namespace lgfx bool Bus_Parallel8::busy(void) const { auto i2s_dev = (i2s_dev_t*)_dev; - return !i2s_dev->int_raw.tx_rempty || !i2s_dev->state.tx_idle; +#if defined (CONFIG_IDF_TARGET_ESP32S2) + return !i2s_dev->state.tx_idle + || (i2s_dev->out_link.val && !(i2s_dev->lc_state0.out_empty)); // I2S_OUT_EMPTY +#else + return !i2s_dev->state.tx_idle + || (i2s_dev->out_link.val && !(i2s_dev->lc_state0 & 0x80000000)); // I2S_OUT_EMPTY +#endif } void Bus_Parallel8::flush(void) @@ -204,47 +242,57 @@ namespace lgfx } } - /// WiFi,BT使用状況確認 - static bool checkWireless(void) - { - return *reg(DPORT_WIFI_CLK_EN_REG) & 0x7FF; - } + // /// WiFi,BT使用状況確認 + // static bool checkWireless(void) + // { + // return *reg(DPORT_WIFI_CLK_EN_REG) & 0x7FF; + // } //* // use DMA - std::size_t Bus_Parallel8::_flush(std::size_t count, bool force) + size_t Bus_Parallel8::_flush(size_t count, bool force) { bool slow = _div_num > 8; - std::size_t idx_e = count & ~1; + size_t idx_e = count & ~1; auto i2s_dev = (i2s_dev_t*)_dev; if (idx_e) { - _dmadesc.buf = (std::uint8_t*)_cache_flip; - *(std::uint32_t*)&_dmadesc = idx_e << 1 | idx_e << 13 | 0xC0000000; - while (!i2s_dev->state.tx_idle) - {} - i2s_dev->fifo_conf.val = _fifo_conf_dma; + if (i2s_dev->out_link.val) + { +#if defined (CONFIG_IDF_TARGET_ESP32S2) + while (!(i2s_dev->lc_state0.out_empty)) {} +#else + while (!(i2s_dev->lc_state0 & 0x80000000)) {} // I2S_OUT_EMPTY +#endif + i2s_dev->out_link.val = 0; + } + _dmadesc.buf = (uint8_t*)_cache_flip; + *(uint32_t*)&_dmadesc = idx_e << 1 | idx_e << 13 | 0xC0000000; + while (!i2s_dev->state.tx_idle) {} i2s_dev->conf.val = _conf_reg_reset | I2S_TX_FIFO_RESET; i2s_dev->out_link.val = I2S_OUTLINK_START | ((uint32_t)&_dmadesc & I2S_OUTLINK_ADDR); - i2s_dev->sample_rate_conf.val = _sample_rate_conf_reg_16bit; - + while (!i2s_dev->state.tx_fifo_reset_back) {} auto cache_old = _cache_flip; _cache_flip = (cache_old == _cache[0]) ? _cache[1] : _cache[0]; - while (!i2s_dev->state.tx_fifo_reset_back) - {} + i2s_dev->int_clr.val = ~0u; - // DMAの準備待ちウェイト …無線使用中はウェイトを増やす - std::size_t wait = (16 << checkWireless()) + (_div_num >> 2); +// DMAの準備待ちウェイト …無線使用中はウェイトを増やす +// size_t wait = (16 << checkWireless()) + (_div_num >> 2); + size_t wait = 16 + (_div_num >> 2); do { __asm__ __volatile__ ("nop"); } while (--wait); i2s_dev->conf.val = _conf_reg_start; - if (slow) while (i2s_dev->state.tx_idle) {} - + if (slow) + { + wait = _div_num >> 1; + do { __asm__ __volatile__ ("nop"); } while (--wait); + } + // if (slow) while (i2s_dev->state.tx_idle) {} count -= idx_e; if (!count) return 0; // 送り残しがあれば次回分のキャッシュに移しておく; - *(std::uint32_t*)_cache_flip = *(std::uint32_t*)(&cache_old[idx_e]); + *(uint32_t*)_cache_flip = *(uint32_t*)(&cache_old[idx_e]); } if (!force) @@ -253,46 +301,56 @@ namespace lgfx } // ここから DMAで送信しきれなかった端数ぶんの送信処理 - -//ets_delay_us(2); - while (!i2s_dev->state.tx_idle) - {} + if (i2s_dev->out_link.val) + { +#if defined (CONFIG_IDF_TARGET_ESP32S2) + while (!(i2s_dev->lc_state0.out_empty)) {} +#else + while (!(i2s_dev->lc_state0 & 0x80000000)) {} // I2S_OUT_EMPTY +#endif + i2s_dev->out_link.val = 0; + } + while (!i2s_dev->state.tx_idle) {} + i2s_dev->conf.val = _conf_reg_reset; i2s_dev->fifo_conf.val = _fifo_conf_default; - i2s_dev->conf.val = _conf_reg_reset;// | I2S_TX_FIFO_RESET; - i2s_dev->out_link.val = 0; i2s_dev->sample_rate_conf.val = _sample_rate_conf_reg_32bit; - std::size_t idx = 0; + size_t idx = 0; do { *_i2s_fifo_wr_reg = _cache_flip[idx ^ 1] << 16; } while (++idx != count); - std::size_t wait = (16 << checkWireless()) + (_div_num >> 2); + size_t wait = 16 + _div_num; do { __asm__ __volatile__ ("nop"); } while (--wait); - if (slow) ets_delay_us(_div_num >> 6); i2s_dev->conf.val = _conf_reg_start; - if (slow) while (i2s_dev->state.tx_idle) {} -//ets_delay_us(2); + if (slow) + { + wait = _div_num >> 1; + do { __asm__ __volatile__ ("nop"); } while (--wait); + } + while (!i2s_dev->state.tx_idle) {} + i2s_dev->sample_rate_conf.val = _sample_rate_conf_reg_16bit; + i2s_dev->fifo_conf.val = _fifo_conf_dma; return 0; } /*/ // use FIFO - std::size_t Bus_Parallel8::_flush(std::size_t count, bool force) + size_t Bus_Parallel8::_flush(size_t count, bool force) { bool slow = _div_num > 8; while (!i2s_dev->int_raw.tx_rempty || (slow && !i2s_dev->state.tx_idle)) {} i2s_dev->conf.val = _conf_reg_reset; - std::size_t idx_e = std::min(CACHE_THRESH, count & ~3); + size_t idx_e = std::min(CACHE_THRESH, count & ~3); auto cache = _cache_flip; if (idx_e) { - std::size_t idx = 0; - auto c = (std::uint32_t*)cache; + size_t idx = 0; + auto c = (uint32_t*)cache; do { *_i2s_fifo_wr_reg = c[idx>>1]; @@ -317,7 +375,7 @@ namespace lgfx return count; } - std::size_t idx = 0; + size_t idx = 0; while (!i2s_dev->int_raw.tx_rempty || (slow && !i2s_dev->state.tx_idle)) {} i2s_dev->conf.val = _conf_reg_reset; @@ -336,7 +394,7 @@ namespace lgfx return 0; } //*/ - bool Bus_Parallel8::writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) + bool Bus_Parallel8::writeCommand(uint32_t data, uint_fast8_t bit_length) { auto idx = _cache_index; auto bytes = bit_length >> 3; @@ -354,7 +412,7 @@ namespace lgfx return true; } - void Bus_Parallel8::writeData(std::uint32_t data, std::uint_fast8_t bit_length) + void Bus_Parallel8::writeData(uint32_t data, uint_fast8_t bit_length) { auto idx = _cache_index; auto bytes = bit_length >> 3; @@ -371,44 +429,73 @@ namespace lgfx _cache_index = idx; } - void Bus_Parallel8::writeDataRepeat(std::uint32_t color_raw, std::uint_fast8_t bit_length, std::uint32_t length) + void Bus_Parallel8::writeDataRepeat(uint32_t color_raw, uint_fast8_t bit_length, uint32_t length) { - std::size_t bytes = bit_length >> 3; - std::uint16_t raw[bytes]; - std::size_t b = 0; - do - { - raw[b] = color_raw | 0x100; - color_raw >>= 8; - } while (++b != bytes); + size_t bytes = bit_length >> 3; auto idx = _cache_index; auto c = _cache_flip; - b = 0; - for (;;) + + if (bytes == 2) { - c[idx ^ 1] = raw[b]; - ++idx; - if (++b == bytes) + if (idx & 1) + { + color_raw = color_raw << 8 | color_raw | 0x01000100; + c[idx ^ 1] = color_raw; + } + else { - b = 0; + color_raw = color_raw << 16 | color_raw >> 8 | 0x01000100; + } + auto cache = (uint32_t*)&c[(idx + 1) & ~1]; + for (;;) + { + *cache++ = color_raw; + idx += 2; if (idx >= CACHE_THRESH) { idx = _flush(idx); - c = _cache_flip; + cache = (uint32_t*)&_cache_flip[(idx + 1) & ~1]; } if (!--length) break; } } + else +//*/ + { + size_t b = 0; + uint16_t raw[bytes]; + do + { + raw[b] = color_raw | 0x100; + color_raw >>= 8; + } while (++b != bytes); + b = 0; + for (;;) + { + c[idx ^ 1] = raw[b]; + ++idx; + if (++b == bytes) + { + b = 0; + if (idx >= CACHE_THRESH) + { + idx = _flush(idx); + c = _cache_flip; + } + if (!--length) break; + } + } + } _cache_index = idx; } - void Bus_Parallel8::writePixels(pixelcopy_t* param, std::uint32_t length) + void Bus_Parallel8::writePixels(pixelcopy_t* param, uint32_t length) { - std::uint8_t buf[CACHE_THRESH]; - const std::uint32_t bytes = param->dst_bits >> 3; + uint8_t buf[CACHE_THRESH]; + const uint32_t bytes = param->dst_bits >> 3; auto fp_copy = param->fp_copy; - const std::uint32_t limit = CACHE_THRESH / bytes; - std::uint8_t len = length % limit; + const uint32_t limit = CACHE_THRESH / bytes; + uint8_t len = length % limit; if (len) { fp_copy(buf, 0, len, param); writeBytes(buf, len * bytes, true, false); @@ -419,182 +506,135 @@ namespace lgfx writeBytes(buf, limit * bytes, true, false); } while (length -= limit); } - //* - void Bus_Parallel8::writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) + void Bus_Parallel8::writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) { - std::uint32_t dc_data = dc << 8; + uint32_t dc_data = dc ? 0x01000100 : 0; auto idx = _cache_index; auto c = _cache_flip; - std::size_t limit = std::min(CACHE_THRESH, length + idx); - length -= limit - idx; - --data; - for (;;) { - // --length; - c[idx^1] = *++data | dc_data; - if (++idx < limit) continue; - if (idx >= CACHE_THRESH) + while (length && ((idx & 3) || (length < 4))) { - idx = _flush(idx); - c = _cache_flip; + --length; + c[idx^1] = *data++ | dc_data; + ++idx; } - if (!length) break; - limit = std::min(CACHE_THRESH, length + idx); - length -= limit - idx; - } - _cache_index = idx; - } -/*/ - void Bus_Parallel8::writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) - { - std::uint32_t dc_data = dc << 8; - auto idx = _cache_index; - auto c = _cache_flip; - do - { - c[idx^1] = *data++ | dc_data; - if (++idx >= CACHE_THRESH) + if (CACHE_THRESH <= idx) { idx = _flush(idx); c = _cache_flip; } - } while (--length); + if (!length) + { + break; + } + size_t limit = std::min(CACHE_THRESH, (length + idx) & ~3); + length -= (limit - idx); + do + { + *(uint32_t*)(&c[idx ]) = (data[0] << 16) | data[1] | dc_data; + *(uint32_t*)(&c[idx+2]) = (data[2] << 16) | data[3] | dc_data; + data += 4; + } while ((idx += 4) < limit); + } _cache_index = idx; } -//*/ - std::uint_fast8_t Bus_Parallel8::_reg_to_value(std::uint32_t raw_value) - { - return ((raw_value >> _cfg.pin_d7) & 1) << 7 - | ((raw_value >> _cfg.pin_d6) & 1) << 6 - | ((raw_value >> _cfg.pin_d5) & 1) << 5 - | ((raw_value >> _cfg.pin_d4) & 1) << 4 - | ((raw_value >> _cfg.pin_d3) & 1) << 3 - | ((raw_value >> _cfg.pin_d2) & 1) << 2 - | ((raw_value >> _cfg.pin_d1) & 1) << 1 - | ((raw_value >> _cfg.pin_d0) & 1) ; - } void Bus_Parallel8::beginRead(void) { if (_cache_index) { _cache_index = _flush(_cache_index, true); } - _wait(); + + gpio_matrix_out(_cfg.pin_rs, 0x100, 0, 0); gpio_lo(_cfg.pin_rd); -// gpio_pad_select_gpio(_gpio_rd); -// gpio_set_direction(_gpio_rd, GPIO_MODE_OUTPUT); - gpio_pad_select_gpio(_cfg.pin_wr); - gpio_hi(_cfg.pin_wr); - gpio_set_direction((gpio_num_t)_cfg.pin_wr, GPIO_MODE_OUTPUT); - gpio_pad_select_gpio(_cfg.pin_rs); - gpio_hi(_cfg.pin_rs); - gpio_set_direction((gpio_num_t)_cfg.pin_rs, GPIO_MODE_OUTPUT); -// if (_i2s_port == I2S_NUM_0) { -//// gpio_matrix_out(_gpio_rd, I2S0O_WS_OUT_IDX ,1,0); -// gpio_matrix_out(_gpio_rd, I2S0O_BCK_OUT_IDX ,1,0); -// } else { -//// gpio_matrix_out(_gpio_rd, I2S1O_WS_OUT_IDX ,1,0); -// gpio_matrix_out(_gpio_rd, I2S1O_BCK_OUT_IDX ,1,0); -// } -//* -// auto idx_base = (_i2s_port == I2S_NUM_0) ? I2S0O_DATA_OUT8_IDX : I2S1O_DATA_OUT8_IDX; -// gpio_matrix_in(_gpio_d7, idx_base + 7, 0); // MSB -// gpio_matrix_in(_gpio_d6, idx_base + 6, 0); -// gpio_matrix_in(_gpio_d5, idx_base + 5, 0); -// gpio_matrix_in(_gpio_d4, idx_base + 4, 0); -// gpio_matrix_in(_gpio_d3, idx_base + 3, 0); -// gpio_matrix_in(_gpio_d2, idx_base + 2, 0); -// gpio_matrix_in(_gpio_d1, idx_base + 1, 0); -// gpio_matrix_in(_gpio_d0, idx_base , 0); // LSB -//*/ -/* - gpio_pad_select_gpio(_gpio_d7); gpio_set_direction(_gpio_d7, GPIO_MODE_INPUT); - gpio_pad_select_gpio(_gpio_d6); gpio_set_direction(_gpio_d6, GPIO_MODE_INPUT); - gpio_pad_select_gpio(_gpio_d5); gpio_set_direction(_gpio_d5, GPIO_MODE_INPUT); - gpio_pad_select_gpio(_gpio_d4); gpio_set_direction(_gpio_d4, GPIO_MODE_INPUT); - gpio_pad_select_gpio(_gpio_d3); gpio_set_direction(_gpio_d3, GPIO_MODE_INPUT); - gpio_pad_select_gpio(_gpio_d2); gpio_set_direction(_gpio_d2, GPIO_MODE_INPUT); - gpio_pad_select_gpio(_gpio_d1); gpio_set_direction(_gpio_d1, GPIO_MODE_INPUT); - gpio_pad_select_gpio(_gpio_d0); gpio_set_direction(_gpio_d0, GPIO_MODE_INPUT); - set_clock_read(); -/*/ - gpio_matrix_out(_cfg.pin_d7, 0x100, 0, 0); // MSB - gpio_matrix_out(_cfg.pin_d6, 0x100, 0, 0); - gpio_matrix_out(_cfg.pin_d5, 0x100, 0, 0); - gpio_matrix_out(_cfg.pin_d4, 0x100, 0, 0); - gpio_matrix_out(_cfg.pin_d3, 0x100, 0, 0); - gpio_matrix_out(_cfg.pin_d2, 0x100, 0, 0); - gpio_matrix_out(_cfg.pin_d1, 0x100, 0, 0); - gpio_matrix_out(_cfg.pin_d0, 0x100, 0, 0); // LSB - - lgfx::pinMode(_cfg.pin_d7, pin_mode_t::input); - lgfx::pinMode(_cfg.pin_d6, pin_mode_t::input); - lgfx::pinMode(_cfg.pin_d5, pin_mode_t::input); - lgfx::pinMode(_cfg.pin_d4, pin_mode_t::input); - lgfx::pinMode(_cfg.pin_d3, pin_mode_t::input); - lgfx::pinMode(_cfg.pin_d2, pin_mode_t::input); - lgfx::pinMode(_cfg.pin_d1, pin_mode_t::input); - lgfx::pinMode(_cfg.pin_d0, pin_mode_t::input); -//*/ } void Bus_Parallel8::endRead(void) { - _wait(); - _init_pin(); + gpio_hi(_cfg.pin_rd); + + auto idx_base = (_cfg.i2s_port == I2S_NUM_0) ? I2S0O_DATA_OUT16_IDX : I2S1O_DATA_OUT16_IDX; + gpio_matrix_out(_cfg.pin_rs, idx_base, 0, 0); + } + + void Bus_Parallel8::_read_bytes(uint8_t* __restrict__ dst, uint32_t length) + { + uint8_t in[8]; + + uint_fast8_t m7 = 1ul << (_cfg.pin_d7 & 7); + uint_fast8_t m6 = 1ul << (_cfg.pin_d6 & 7); + uint_fast8_t m5 = 1ul << (_cfg.pin_d5 & 7); + uint_fast8_t m4 = 1ul << (_cfg.pin_d4 & 7); + uint_fast8_t m3 = 1ul << (_cfg.pin_d3 & 7); + uint_fast8_t m2 = 1ul << (_cfg.pin_d2 & 7); + uint_fast8_t m1 = 1ul << (_cfg.pin_d1 & 7); + uint_fast8_t m0 = 1ul << (_cfg.pin_d0 & 7); + + uint_fast8_t i7 = _cfg.pin_d7 >> 3; + uint_fast8_t i6 = _cfg.pin_d6 >> 3; + uint_fast8_t i5 = _cfg.pin_d5 >> 3; + uint_fast8_t i4 = _cfg.pin_d4 >> 3; + uint_fast8_t i3 = _cfg.pin_d3 >> 3; + uint_fast8_t i2 = _cfg.pin_d2 >> 3; + uint_fast8_t i1 = _cfg.pin_d1 >> 3; + uint_fast8_t i0 = _cfg.pin_d0 >> 3; + + auto reg_rd_h = get_gpio_hi_reg(_cfg.pin_rd); + auto reg_rd_l = get_gpio_lo_reg(_cfg.pin_rd); + uint32_t mask_rd = 1ul << (_cfg.pin_rd & 31); + uint32_t val; + do + { + ((uint32_t*)in)[1] = GPIO.in1.val; + ((uint32_t*)in)[0] = GPIO.in; + *reg_rd_h = mask_rd; + + val = ((((bool)(in[i7] & m7) << 1) + + (bool)(in[i6] & m6) ) << 2) + + ((bool)(in[i5] & m5) << 1) + + ((bool)(in[i4] & m4) ); + + *reg_rd_l = mask_rd; + val = (((val << 2) + + ((bool)(in[i3] & m3) << 1) + + ((bool)(in[i2] & m2) )) << 2) + + ((bool)(in[i1] & m1) << 1) + + ((bool)(in[i0] & m0) ) + ; + *dst++ = val; + } while (--length); } - std::uint32_t Bus_Parallel8::readData(std::uint_fast8_t bit_length) + uint32_t Bus_Parallel8::readData(uint_fast8_t bit_length) { union { - std::uint32_t res; - std::uint8_t raw[4]; + uint32_t res; + uint8_t raw[4]; }; - bit_length = (bit_length + 7) & ~7; - - auto buf = raw; - do { - std::uint32_t tmp = GPIO.in; // dummy read speed tweak. - tmp = GPIO.in; - gpio_hi(_cfg.pin_rd); - gpio_lo(_cfg.pin_rd); - *buf++ = _reg_to_value(tmp); - } while (bit_length -= 8); + _read_bytes(raw, (bit_length + 7) >> 3); return res; } - bool Bus_Parallel8::readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma) + bool Bus_Parallel8::readBytes(uint8_t* dst, uint32_t length, bool use_dma) { - do { - std::uint32_t tmp = GPIO.in; // dummy read speed tweak. - tmp = GPIO.in; - gpio_hi(_cfg.pin_rd); - gpio_lo(_cfg.pin_rd); - *dst++ = _reg_to_value(tmp); - } while (--length); + _read_bytes(dst, length); return true; } - void Bus_Parallel8::readPixels(void* dst, pixelcopy_t* param, std::uint32_t length) + void Bus_Parallel8::readPixels(void* dst, pixelcopy_t* param, uint32_t length) { - std::uint32_t _regbuf[8]; + uint32_t _regbuf[8]; const auto bytes = param->src_bits >> 3; - std::uint32_t limit = (bytes == 2) ? 16 : 10; + uint32_t limit = (bytes == 2) ? 16 : 10; param->src_data = _regbuf; - std::int32_t dstindex = 0; + int32_t dstindex = 0; do { - std::uint32_t len2 = (limit > length) ? length : limit; + uint32_t len2 = (limit > length) ? length : limit; length -= len2; - std::uint32_t i = len2 * bytes; - auto d = (std::uint8_t*)_regbuf; - do { - std::uint32_t tmp = GPIO.in; - gpio_hi(_cfg.pin_rd); - gpio_lo(_cfg.pin_rd); - *d++ = _reg_to_value(tmp); - } while (--i); + + _read_bytes((uint8_t*)_regbuf, len2 * bytes); param->src_x = 0; dstindex = param->fp_copy(dst, dstindex, dstindex + len2, param); } while (length); @@ -604,4 +644,5 @@ namespace lgfx } } -#endif \ No newline at end of file +#endif +#endif diff --git a/src/lgfx/v1/platforms/esp32/Bus_Parallel8.hpp b/src/lgfx/v1/platforms/esp32/Bus_Parallel8.hpp index f85a839..0302fb6 100644 --- a/src/lgfx/v1/platforms/esp32/Bus_Parallel8.hpp +++ b/src/lgfx/v1/platforms/esp32/Bus_Parallel8.hpp @@ -18,7 +18,7 @@ Original Source: #pragma once #include -#include +#include #if __has_include() #include @@ -49,18 +49,18 @@ namespace lgfx i2s_port_t i2s_port = I2S_NUM_0; // max 20MHz , 16MHz , 13.3MHz , 11.43MHz , 10MHz , 8.9MHz and more ... - std::uint32_t freq_write = 16000000; - std::int8_t pin_d0 = -1; - std::int8_t pin_d1 = -1; - std::int8_t pin_d2 = -1; - std::int8_t pin_d3 = -1; - std::int8_t pin_d4 = -1; - std::int8_t pin_d5 = -1; - std::int8_t pin_d6 = -1; - std::int8_t pin_d7 = -1; - std::int8_t pin_wr = -1; - std::int8_t pin_rd = -1; - std::int8_t pin_rs = -1; // D/C + uint32_t freq_write = 16000000; + int8_t pin_d0 = -1; + int8_t pin_d1 = -1; + int8_t pin_d2 = -1; + int8_t pin_d3 = -1; + int8_t pin_d4 = -1; + int8_t pin_d5 = -1; + int8_t pin_d6 = -1; + int8_t pin_d7 = -1; + int8_t pin_wr = -1; + int8_t pin_rd = -1; + int8_t pin_rs = -1; // D/C }; @@ -78,45 +78,45 @@ namespace lgfx bool busy(void) const override; void flush(void) override; - bool writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) override; - void writeData(std::uint32_t data, std::uint_fast8_t bit_length) override; - void writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t count) override; - void writePixels(pixelcopy_t* param, std::uint32_t length) override; - void writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) override; + bool writeCommand(uint32_t data, uint_fast8_t bit_length) override; + void writeData(uint32_t data, uint_fast8_t bit_length) override; + void writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t count) override; + void writePixels(pixelcopy_t* param, uint32_t length) override; + void writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) override; void initDMA(void) override {} - void addDMAQueue(const std::uint8_t* data, std::uint32_t length) override { writeBytes(data, length, true, true); } + void addDMAQueue(const uint8_t* data, uint32_t length) override { writeBytes(data, length, true, true); } void execDMAQueue(void) override { flush(); }; - std::uint8_t* getDMABuffer(std::uint32_t length) override { return _flip_buffer.getBuffer(length); } + uint8_t* getDMABuffer(uint32_t length) override { return _flip_buffer.getBuffer(length); } void beginRead(void) override; void endRead(void) override; - std::uint32_t readData(std::uint_fast8_t bit_length) override; - bool readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma) override; - void readPixels(void* dst, pixelcopy_t* param, std::uint32_t length) override; + uint32_t readData(uint_fast8_t bit_length) override; + bool readBytes(uint8_t* dst, uint32_t length, bool use_dma) override; + void readPixels(void* dst, pixelcopy_t* param, uint32_t length) override; private: - static constexpr std::size_t CACHE_SIZE = 132; + static constexpr size_t CACHE_SIZE = 132; config_t _cfg; SimpleBuffer _flip_buffer; - std::size_t _div_num; - std::size_t _cache_index; - std::uint16_t _cache[2][CACHE_SIZE]; - std::uint16_t* _cache_flip; + size_t _div_num; + size_t _cache_index; + uint16_t _cache[2][CACHE_SIZE]; + uint16_t* _cache_flip; void _wait(void); void _init_pin(void); - std::size_t _flush(std::size_t idx, bool force = false); - std::uint_fast8_t _reg_to_value(std::uint32_t raw_value); + size_t _flush(size_t idx, bool force = false); + void _read_bytes(uint8_t* dst, uint32_t length); - std::uint32_t _last_freq_apb; - std::uint32_t _clkdiv_write; + uint32_t _last_freq_apb; + uint32_t _clkdiv_write; volatile void *_dev; lldesc_t _dmadesc; - volatile std::uint32_t* _i2s_fifo_wr_reg; + volatile uint32_t* _i2s_fifo_wr_reg; }; //---------------------------------------------------------------------------- diff --git a/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp b/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp index 1f2f0f4..0954bdb 100644 --- a/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp +++ b/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp @@ -15,7 +15,9 @@ Original Source: [mongonta0716](https://github.com/mongonta0716) [tobozo](https://github.com/tobozo) /----------------------------------------------------------------------------*/ -#if defined (ESP32) || defined (CONFIG_IDF_TARGET_ESP32) || defined (CONFIG_IDF_TARGET_ESP32S2) || defined (ESP_PLATFORM) +#if defined (ESP_PLATFORM) +#include +#if !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32) || defined (CONFIG_IDF_TARGET_ESP32S2) || defined (CONFIG_IDF_TARGET_ESP32C3) #include "Bus_SPI.hpp" @@ -33,12 +35,15 @@ Original Source: #include #endif -#if defined (CONFIG_IDF_TARGET_ESP32S2) - #ifndef SPI_PIN_REG +#ifndef SPI_PIN_REG #define SPI_PIN_REG SPI_MISC_REG - #endif #endif +#if defined (CONFIG_IDF_TARGET_ESP32C3) + #include + #include + #include +#endif #include "common.hpp" #include @@ -59,7 +64,16 @@ namespace lgfx _spi_cmd_reg = reg(SPI_CMD_REG( spi_port)); _spi_user_reg = reg(SPI_USER_REG( spi_port)); _spi_mosi_dlen_reg = reg(SPI_MOSI_DLEN_REG( spi_port)); +#if defined ( SOC_GDMA_SUPPORTED ) + _spi_dma_out_link_reg = reg(DMA_OUT_LINK_CH0_REG); + _spi_dma_outstatus_reg = reg(DMA_OUTFIFO_STATUS_CH0_REG); +#elif defined ( SPI_DMA_STATUS_REG ) + _spi_dma_out_link_reg = reg(SPI_DMA_OUT_LINK_REG(spi_port)); + _spi_dma_outstatus_reg = reg(SPI_DMA_STATUS_REG(spi_port)); +#else _spi_dma_out_link_reg = reg(SPI_DMA_OUT_LINK_REG(spi_port)); + _spi_dma_outstatus_reg = reg(SPI_DMA_OUTSTATUS_REG(spi_port)); +#endif _mask_reg_dc = (cfg.pin_dc < 0) ? 0 : (1ul << (cfg.pin_dc & 31)); _gpio_reg_dc[0] = get_gpio_lo_reg(cfg.pin_dc); _gpio_reg_dc[1] = get_gpio_hi_reg(cfg.pin_dc); @@ -95,8 +109,8 @@ namespace lgfx void Bus_SPI::beginTransaction(void) { //ESP_LOGI("LGFX","Bus_SPI::beginTransaction"); - std::uint32_t freq_apb = getApbFrequency(); - std::uint32_t clkdiv_write = _clkdiv_write; + uint32_t freq_apb = getApbFrequency(); + uint32_t clkdiv_write = _clkdiv_write; if (_last_freq_apb != freq_apb) { _last_freq_apb = freq_apb; @@ -109,12 +123,13 @@ namespace lgfx if (_cfg.dma_channel) _next_dma_reset = true; auto spi_mode = _cfg.spi_mode; - std::uint32_t pin = (spi_mode & 2) ? SPI_CK_IDLE_EDGE : 0; + uint32_t pin = (spi_mode & 2) ? SPI_CK_IDLE_EDGE : 0; if (_cfg.use_lock) spi::beginTransaction(_cfg.spi_host); *_spi_user_reg = _user_reg; auto spi_port = _spi_port; + (void)spi_port; *reg(SPI_PIN_REG(spi_port)) = pin; *reg(SPI_CLOCK_REG(spi_port)) = clkdiv_write; } @@ -139,7 +154,7 @@ namespace lgfx return (*_spi_cmd_reg & SPI_USR); } - bool Bus_SPI::writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) + bool Bus_SPI::writeCommand(uint32_t data, uint_fast8_t bit_length) { //ESP_LOGI("LGFX","writeCmd: %02x len:%d dc:%02x", data, bit_length, _mask_reg_dc); --bit_length; @@ -148,15 +163,29 @@ namespace lgfx auto spi_cmd_reg = _spi_cmd_reg; auto gpio_reg_dc = _gpio_reg_dc[0]; auto mask_reg_dc = _mask_reg_dc; - while (*spi_cmd_reg & SPI_USR); // wait SPI - *gpio_reg_dc = mask_reg_dc; // D/C +#if !defined ( CONFIG_IDF_TARGET ) || defined ( CONFIG_IDF_TARGET_ESP32 ) + while (*spi_cmd_reg & SPI_USR) {} // wait SPI +#else + auto dma = _clear_dma_reg; + if (dma) + { + _clear_dma_reg = nullptr; + while (*spi_cmd_reg & SPI_USR) {} // wait SPI + *dma = 0; + } + else + { + while (*spi_cmd_reg & SPI_USR) {} // wait SPI + } +#endif *spi_mosi_dlen_reg = bit_length; // set bitlength *spi_w0_reg = data; // set data - *spi_cmd_reg = SPI_USR; // exec SPI + *gpio_reg_dc = mask_reg_dc; // D/C + *spi_cmd_reg = SPI_EXECUTE; // exec SPI return true; } - void Bus_SPI::writeData(std::uint32_t data, std::uint_fast8_t bit_length) + void Bus_SPI::writeData(uint32_t data, uint_fast8_t bit_length) { //ESP_LOGI("LGFX","writeData: %02x len:%d", data, bit_length); --bit_length; @@ -165,34 +194,55 @@ namespace lgfx auto spi_cmd_reg = _spi_cmd_reg; auto gpio_reg_dc = _gpio_reg_dc[1]; auto mask_reg_dc = _mask_reg_dc; - while (*spi_cmd_reg & SPI_USR); // wait SPI - *gpio_reg_dc = mask_reg_dc; // D/C +#if !defined ( CONFIG_IDF_TARGET ) || defined ( CONFIG_IDF_TARGET_ESP32 ) + while (*spi_cmd_reg & SPI_USR) {} // wait SPI +#else + auto dma = _clear_dma_reg; + if (dma) + { + _clear_dma_reg = nullptr; + while (*spi_cmd_reg & SPI_USR) {} // wait SPI + *dma = 0; + } + else + { + while (*spi_cmd_reg & SPI_USR) {} // wait SPI + } +#endif *spi_mosi_dlen_reg = bit_length; // set bitlength *spi_w0_reg = data; // set data - *spi_cmd_reg = SPI_USR; // exec SPI + *gpio_reg_dc = mask_reg_dc; // D/C + *spi_cmd_reg = SPI_EXECUTE; // exec SPI } - void Bus_SPI::writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t count) + void Bus_SPI::writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t count) { auto spi_mosi_dlen_reg = _spi_mosi_dlen_reg; auto spi_w0_reg = _spi_w0_reg; auto spi_cmd_reg = _spi_cmd_reg; auto gpio_reg_dc = _gpio_reg_dc[1]; auto mask_reg_dc = _mask_reg_dc; +#if defined ( CONFIG_IDF_TARGET ) && !defined ( CONFIG_IDF_TARGET_ESP32 ) + auto dma = _clear_dma_reg; + if (dma) { _clear_dma_reg = nullptr; } +#endif if (1 == count) { --bit_length; while (*spi_cmd_reg & SPI_USR); // wait SPI +#if defined ( CONFIG_IDF_TARGET ) && !defined ( CONFIG_IDF_TARGET_ESP32 ) + if (dma) { *dma = 0; } +#endif *gpio_reg_dc = mask_reg_dc; // D/C high (data) *spi_mosi_dlen_reg = bit_length; // set bitlength *spi_w0_reg = data; // set data - *spi_cmd_reg = SPI_USR; // exec SPI + *spi_cmd_reg = SPI_EXECUTE; // exec SPI return; } - std::uint32_t regbuf0 = data | data << bit_length; - std::uint32_t regbuf1; - std::uint32_t regbuf2; + uint32_t regbuf0 = data | data << bit_length; + uint32_t regbuf1; + uint32_t regbuf2; // make 12Bytes data. bool bits24 = (bit_length == 24); if (bits24) { @@ -203,23 +253,26 @@ namespace lgfx regbuf2 = regbuf0; } - std::uint32_t length = bit_length * count; // convert to bitlength. - std::uint32_t len = (length <= 96u) ? length : (length <= 144u) ? 48u : 96u; // 1st send length = max 12Byte (96bit). + uint32_t length = bit_length * count; // convert to bitlength. + uint32_t len = (length <= 96u) ? length : (length <= 144u) ? 48u : 96u; // 1st send length = max 12Byte (96bit). length -= len; --len; - while (*spi_cmd_reg & SPI_USR); // wait SPI + while (*spi_cmd_reg & SPI_USR) {} // wait SPI +#if defined ( CONFIG_IDF_TARGET ) && !defined ( CONFIG_IDF_TARGET_ESP32 ) + if (dma) { *dma = 0; } +#endif *gpio_reg_dc = mask_reg_dc; // D/C high (data) *spi_mosi_dlen_reg = len; // copy to SPI buffer register spi_w0_reg[0] = regbuf0; spi_w0_reg[1] = regbuf1; spi_w0_reg[2] = regbuf2; - *spi_cmd_reg = SPI_USR; // exec SPI + *spi_cmd_reg = SPI_EXECUTE; // exec SPI if (0 == length) return; - std::uint32_t regbuf[7] = { regbuf0, regbuf1, regbuf2, regbuf0, regbuf1, regbuf2, regbuf0 } ; + uint32_t regbuf[7] = { regbuf0, regbuf1, regbuf2, regbuf0, regbuf1, regbuf2, regbuf0 } ; // copy to SPI buffer register memcpy((void*)&spi_w0_reg[3], regbuf, 24); @@ -228,7 +281,7 @@ namespace lgfx // limit = 64Byte / depth_bytes; // When 24bit color, 504 bits out of 512bit buffer are used. // When 16bit color, it uses exactly 512 bytes. but, it behaves like a ring buffer, can specify a larger size. - std::uint32_t limit; + uint32_t limit; if (bits24) { limit = 504; @@ -236,10 +289,10 @@ namespace lgfx } else { -#if defined( CONFIG_IDF_TARGET_ESP32S2 ) - limit = (1 << 9); -#else +#if defined ( CONFIG_IDF_TARGET_ESP32 ) limit = (1 << 11); +#else + limit = (1 << 9); #endif len = length & (limit - 1); } @@ -250,27 +303,27 @@ namespace lgfx --len; while (*spi_cmd_reg & SPI_USR); *spi_mosi_dlen_reg = len; - *spi_cmd_reg = SPI_USR; + *spi_cmd_reg = SPI_EXECUTE; if (0 == length) return; } while (*spi_cmd_reg & SPI_USR); *spi_mosi_dlen_reg = limit - 1; - *spi_cmd_reg = SPI_USR; + *spi_cmd_reg = SPI_EXECUTE; while (length -= limit) { while (*spi_cmd_reg & SPI_USR); - *spi_cmd_reg = SPI_USR; + *spi_cmd_reg = SPI_EXECUTE; } } - void Bus_SPI::writePixels(pixelcopy_t* param, std::uint32_t length) + void Bus_SPI::writePixels(pixelcopy_t* param, uint32_t length) { - const std::uint8_t bytes = param->dst_bits >> 3; + const uint8_t bytes = param->dst_bits >> 3; if (_cfg.dma_channel) { - std::uint32_t limit = (bytes == 2) ? 32 : 24; - std::uint32_t len; + uint32_t limit = (bytes == 2) ? 32 : 24; + uint32_t len; do { len = (limit << 1) <= length ? limit : length; @@ -282,16 +335,54 @@ namespace lgfx return; } - const std::uint32_t limit = (bytes == 2) ? 16 : 10; // limit = 32/bytes (bytes==2 is 16 bytes==3 is 10) - std::uint32_t len = (length - 1) / limit; - std::uint32_t highpart = (len & 1) << 3; +/// ESP32-C3 で HIGHPART を使用すると異常動作するため分岐する +#if defined ( CONFIG_IDF_TARGET_ESP32C3 ) + + const uint32_t limit = (bytes == 2) ? 32 : 21; + uint32_t l = (length - 1) / limit; + uint32_t len = length - (l * limit); + length = l; + uint32_t regbuf[16]; + param->fp_copy(regbuf, 0, len, param); + + auto spi_w0_reg = _spi_w0_reg; + + dc_control(true); + set_write_len(len * bytes << 3); + + memcpy((void*)spi_w0_reg, regbuf, (len * bytes + 3) & (~3)); + + exec_spi(); + if (0 == length) return; + + + param->fp_copy(regbuf, 0, limit, param); + wait_spi(); + set_write_len(limit * bytes << 3); + memcpy((void*)spi_w0_reg, regbuf, limit * bytes); + exec_spi(); + + + while (--length) + { + param->fp_copy(regbuf, 0, limit, param); + wait_spi(); + memcpy((void*)spi_w0_reg, regbuf, limit * bytes); + exec_spi(); + } + +#else + + const uint32_t limit = (bytes == 2) ? 16 : 10; // limit = 32/bytes (bytes==2 is 16 bytes==3 is 10) + uint32_t len = (length - 1) / limit; + uint32_t highpart = (len & 1) << 3; len = length - (len * limit); - std::uint32_t regbuf[8]; + uint32_t regbuf[8]; param->fp_copy(regbuf, 0, len, param); auto spi_w0_reg = _spi_w0_reg; - std::uint32_t user_reg = *_spi_user_reg; + uint32_t user_reg = *_spi_user_reg; dc_control(true); set_write_len(len * bytes << 3); @@ -305,7 +396,7 @@ namespace lgfx { param->fp_copy(regbuf, 0, limit, param); memcpy((void*)&spi_w0_reg[highpart ^= 0x08], regbuf, limit * bytes); - std::uint32_t user = user_reg; + uint32_t user = user_reg; if (highpart) user |= SPI_USR_MOSI_HIGHPART; if (len != limit) { @@ -322,9 +413,12 @@ namespace lgfx exec_spi(); } } + +#endif + } - void Bus_SPI::writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) + void Bus_SPI::writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) { if (length <= 64) { @@ -349,22 +443,77 @@ namespace lgfx } if (use_dma) { - dc_control(dc); - set_write_len(length << 3); + auto spi_dma_out_link_reg = _spi_dma_out_link_reg; + auto cmd = _spi_cmd_reg; + while (*cmd & SPI_USR) {} + *spi_dma_out_link_reg = 0; _setup_dma_desc_links(data, length); - *_spi_dma_out_link_reg = SPI_OUTLINK_START | ((int)(&_dmadesc[0]) & 0xFFFFF); +#if defined ( SOC_GDMA_SUPPORTED ) + *spi_dma_out_link_reg = DMA_OUTLINK_START_CH0 | ((int)(&_dmadesc[0]) & 0xFFFFF); + auto dma = reg(SPI_DMA_CONF_REG(spi_port)); + *dma = SPI_DMA_TX_ENA; + _clear_dma_reg = dma; +#else + *spi_dma_out_link_reg = SPI_OUTLINK_START | ((int)(&_dmadesc[0]) & 0xFFFFF); + _clear_dma_reg = spi_dma_out_link_reg; +#endif + set_write_len(length << 3); + *_gpio_reg_dc[dc] = _mask_reg_dc; + + // DMA準備完了待ち +#if defined ( SOC_GDMA_SUPPORTED ) + while (*_spi_dma_outstatus_reg & DMA_OUTFIFO_EMPTY_CH0 ) {} +#elif defined (SPI_DMA_OUTFIFO_EMPTY) + while (*_spi_dma_outstatus_reg & SPI_DMA_OUTFIFO_EMPTY ) {} +#else spicommon_dmaworkaround_transfer_active(_cfg.dma_channel); +#endif exec_spi(); return; } } - constexpr std::uint32_t limit = 32; - std::uint32_t len = ((length - 1) & 0x1F) + 1; - std::uint32_t highpart = ((length - 1) & limit) >> 2; // 8 or 0 auto spi_w0_reg = _spi_w0_reg; - std::uint32_t user_reg = _user_reg; +/// ESP32-C3 で HIGHPART を使用すると異常動作するため分岐する +#if defined ( CONFIG_IDF_TARGET_ESP32C3 ) + + uint32_t regbuf[16]; + constexpr uint32_t limit = 64; + uint32_t len = ((length - 1) & 0x3F) + 1; + + memcpy(regbuf, data, len); + dc_control(dc); + set_write_len(len << 3); + + memcpy((void*)spi_w0_reg, regbuf, (len + 3) & (~3)); + exec_spi(); + if (0 == (length -= len)) return; + + data += len; + memcpy(regbuf, data, limit); + wait_spi(); + set_write_len(limit << 3); + memcpy((void*)spi_w0_reg, regbuf, limit); + exec_spi(); + if (0 == (length -= limit)) return; + + do + { + data += limit; + memcpy(regbuf, data, limit); + wait_spi(); + memcpy((void*)spi_w0_reg, regbuf, limit); + exec_spi(); + } while (0 != (length -= limit)); + +#else + + constexpr uint32_t limit = 32; + uint32_t len = ((length - 1) & 0x1F) + 1; + uint32_t highpart = ((length - 1) & limit) >> 2; // 8 or 0 + + uint32_t user_reg = _user_reg; dc_control(dc); set_write_len(len << 3); @@ -377,7 +526,7 @@ namespace lgfx { data += len; memcpy((void*)&spi_w0_reg[highpart ^= 0x08], data, limit); - std::uint32_t user = user_reg; + uint32_t user = user_reg; if (highpart) user |= SPI_USR_MOSI_HIGHPART; if (len != limit) { @@ -394,6 +543,9 @@ namespace lgfx exec_spi(); } } + +#endif + } void Bus_SPI::initDMA(void) @@ -404,7 +556,7 @@ namespace lgfx } } - void Bus_SPI::addDMAQueue(const std::uint8_t* data, std::uint32_t length) + void Bus_SPI::addDMAQueue(const uint8_t* data, uint32_t length) { if (!_cfg.dma_channel) { @@ -413,8 +565,8 @@ namespace lgfx } _dma_queue_bytes += length; - std::size_t index = _dma_queue_size; - std::size_t new_size = index + ((length-1) / SPI_MAX_DMA_LEN) + 1; + size_t index = _dma_queue_size; + size_t new_size = index + ((length-1) / SPI_MAX_DMA_LEN) + 1; if (_dma_queue_capacity < new_size) { @@ -432,14 +584,14 @@ namespace lgfx while (length > SPI_MAX_DMA_LEN) { - *(std::uint32_t*)dmadesc = SPI_MAX_DMA_LEN | SPI_MAX_DMA_LEN << 12 | 0x80000000; - dmadesc->buf = const_cast(data); + *(uint32_t*)dmadesc = SPI_MAX_DMA_LEN | SPI_MAX_DMA_LEN << 12 | 0x80000000; + dmadesc->buf = const_cast(data); dmadesc++; data += SPI_MAX_DMA_LEN; length -= SPI_MAX_DMA_LEN; } - *(std::uint32_t*)dmadesc = ((length + 3) & ( ~3 )) | length << 12 | 0x80000000; - dmadesc->buf = const_cast(data); + *(uint32_t*)dmadesc = ((length + 3) & ( ~3 )) | length << 12 | 0x80000000; + dmadesc->buf = const_cast(data); } void Bus_SPI::execDMAQueue(void) @@ -459,50 +611,74 @@ namespace lgfx std::swap(_dmadesc_size, _dma_queue_capacity); dc_control(true); - set_write_len(_dma_queue_bytes << 3); - _dma_queue_bytes = 0; - + *_spi_dma_out_link_reg = 0; if (_next_dma_reset) { _spi_dma_reset(); } - *_spi_dma_out_link_reg = SPI_OUTLINK_START | ((int)(_dmadesc) & 0xFFFFF); +#if defined ( SOC_GDMA_SUPPORTED ) + *_spi_dma_out_link_reg = DMA_OUTLINK_START_CH0 | ((int)(&_dmadesc[0]) & 0xFFFFF); + auto dma = reg(SPI_DMA_CONF_REG(spi_port)); + *dma = SPI_DMA_TX_ENA; + _clear_dma_reg = dma; +#else + *_spi_dma_out_link_reg = SPI_OUTLINK_START | ((int)(&_dmadesc[0]) & 0xFFFFF); + _clear_dma_reg = _spi_dma_out_link_reg; +#endif + + set_write_len(_dma_queue_bytes << 3); + _dma_queue_bytes = 0; + // DMA準備完了待ち +#if defined ( SOC_GDMA_SUPPORTED ) + while (*_spi_dma_outstatus_reg & DMA_OUTFIFO_EMPTY_CH0 ) {} +#elif defined (SPI_DMA_OUTFIFO_EMPTY) + while (*_spi_dma_outstatus_reg & SPI_DMA_OUTFIFO_EMPTY ) {} +#else spicommon_dmaworkaround_transfer_active(_cfg.dma_channel); +#endif + exec_spi(); } void Bus_SPI::beginRead(void) { - std::uint32_t pin = (_cfg.spi_mode & 2) ? SPI_CK_IDLE_EDGE : 0; - std::uint32_t user = ((_cfg.spi_mode == 1 || _cfg.spi_mode == 2) ? SPI_CK_OUT_EDGE | SPI_USR_MISO : SPI_USR_MISO) + uint32_t pin = (_cfg.spi_mode & 2) ? SPI_CK_IDLE_EDGE : 0; + uint32_t user = ((_cfg.spi_mode == 1 || _cfg.spi_mode == 2) ? SPI_CK_OUT_EDGE | SPI_USR_MISO : SPI_USR_MISO) | (_cfg.spi_3wire ? SPI_SIO : 0); dc_control(true); *_spi_user_reg = user; *reg(SPI_PIN_REG(_spi_port)) = pin; *reg(SPI_CLOCK_REG(_spi_port)) = _clkdiv_read; +#if defined ( SPI_UPDATE ) + *_spi_cmd_reg = SPI_UPDATE; +#endif } void Bus_SPI::endRead(void) { - std::uint32_t pin = (_cfg.spi_mode & 2) ? SPI_CK_IDLE_EDGE : 0; + uint32_t pin = (_cfg.spi_mode & 2) ? SPI_CK_IDLE_EDGE : 0; *_spi_user_reg = _user_reg; *reg(SPI_PIN_REG(_spi_port)) = pin; *reg(SPI_CLOCK_REG(_spi_port)) = _clkdiv_write; +#if defined ( SPI_UPDATE ) + *_spi_cmd_reg = SPI_UPDATE; +#endif } - std::uint32_t Bus_SPI::readData(std::uint_fast8_t bit_length) + uint32_t Bus_SPI::readData(uint_fast8_t bit_length) { set_read_len(bit_length); auto spi_cmd_reg = _spi_cmd_reg; - *spi_cmd_reg = SPI_USR; + *spi_cmd_reg = SPI_EXECUTE; auto spi_w0_reg = _spi_w0_reg; while (*spi_cmd_reg & SPI_USR); return *spi_w0_reg; } - bool Bus_SPI::readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma) + bool Bus_SPI::readBytes(uint8_t* dst, uint32_t length, bool use_dma) { +#if defined ( SPI_DMA_IN_LINK_REG ) if (_cfg.dma_channel && use_dma) { wait_spi(); set_read_len(length << 3); @@ -510,14 +686,43 @@ namespace lgfx *reg(SPI_DMA_IN_LINK_REG(_spi_port)) = SPI_INLINK_START | ((int)(&_dmadesc[0]) & 0xFFFFF); spicommon_dmaworkaround_transfer_active(_cfg.dma_channel); exec_spi(); - } else { - std::int32_t len1 = std::min(length, 32u); // 32 Byte read. - std::int32_t len2 = len1; + } + else +#endif + { + auto len1 = std::min(length, 32u); // 32 Byte read. + auto len2 = len1; wait_spi(); set_read_len(len1 << 3); exec_spi(); - std::uint32_t highpart = 8; - std::uint32_t userreg = *_spi_user_reg; + +/// ESP32-C3 で HIGHPART を使用すると異常動作するため分岐する +#if defined ( CONFIG_IDF_TARGET_ESP32C3 ) + + auto spi_w0_reg = _spi_w0_reg; + do { + if (0 == (length -= len1)) { + len2 = len1; + wait_spi(); + memcpy(dst, (void*)spi_w0_reg, len2); + } else { + if (length < len1) { + len1 = length; + wait_spi(); + set_read_len(len1 << 3); + } else { + wait_spi(); + } + memcpy(dst, (void*)spi_w0_reg, len2); + exec_spi(); + } + dst += len2; + } while (length); + +#else + + uint32_t userreg = *_spi_user_reg; + uint32_t highpart = 8; auto spi_w0_reg = _spi_w0_reg; do { if (0 == (length -= len1)) { @@ -525,7 +730,7 @@ namespace lgfx wait_spi(); *_spi_user_reg = userreg; } else { - std::uint32_t user = userreg; + uint32_t user = userreg; if (highpart) user = userreg | SPI_USR_MISO_HIGHPART; if (length < len1) { len1 = length; @@ -537,34 +742,63 @@ namespace lgfx *_spi_user_reg = user; exec_spi(); } - memcpy(dst, (void*)&spi_w0_reg[highpart ^= 8], len2); + memcpy(dst, (void*)&spi_w0_reg[highpart ^= 8], (len2+3)&~3u); dst += len2; } while (length); + +#endif + } return true; } - void Bus_SPI::readPixels(void* dst, pixelcopy_t* param, std::uint32_t length) + void Bus_SPI::readPixels(void* dst, pixelcopy_t* param, uint32_t length) { - std::uint32_t len1 = std::min(length, 10u); // 10 pixel read - std::uint32_t len2 = len1; + auto len1 = std::min(length, 10u); // 10 pixel read + auto len2 = len1; auto len_read_pixel = param->src_bits; - std::uint32_t regbuf[8]; + uint32_t regbuf[8]; wait_spi(); set_read_len(len_read_pixel * len1); exec_spi(); param->src_data = regbuf; - std::int32_t dstindex = 0; - std::uint32_t highpart = 8; - std::uint32_t userreg = *_spi_user_reg; + int32_t dstindex = 0; auto spi_w0_reg = _spi_w0_reg; + +/// ESP32-C3 で HIGHPART を使用すると異常動作するため分岐する +#if defined ( CONFIG_IDF_TARGET_ESP32C3 ) + + do { + if (0 == (length -= len1)) { + len2 = len1; + wait_spi(); + memcpy(regbuf, (void*)spi_w0_reg, len2 * len_read_pixel >> 3); + } else { + if (length < len1) { + len1 = length; + wait_spi(); + set_read_len(len_read_pixel * len1); + } else { + wait_spi(); + } + memcpy(regbuf, (void*)spi_w0_reg, len2 * len_read_pixel >> 3); + exec_spi(); + } + param->src_x = 0; + dstindex = param->fp_copy(dst, dstindex, dstindex + len2, param); + } while (length); + +#else + + uint32_t userreg = *_spi_user_reg; + uint32_t highpart = 8; do { if (0 == (length -= len1)) { len2 = len1; wait_spi(); *_spi_user_reg = userreg; } else { - std::uint32_t user = userreg; + uint32_t user = userreg; if (highpart) user = userreg | SPI_USR_MISO_HIGHPART; if (length < len1) { len1 = length; @@ -576,12 +810,14 @@ namespace lgfx *_spi_user_reg = user; exec_spi(); } - memcpy(regbuf, (void*)&spi_w0_reg[highpart ^= 8], len2 * len_read_pixel >> 3); + memcpy(regbuf, (void*)&spi_w0_reg[highpart ^= 8], ((len2 * len_read_pixel >> 3)+3)&~3u); param->src_x = 0; dstindex = param->fp_copy(dst, dstindex, dstindex + len2, param); } while (length); - } +#endif + + } void Bus_SPI::_alloc_dmadesc(size_t len) { @@ -593,12 +829,14 @@ namespace lgfx void Bus_SPI::_spi_dma_reset(void) { _next_dma_reset = false; -#if defined( CONFIG_IDF_TARGET_ESP32S2 ) - if (_conf.spi_host == SPI2_HOST) +#if defined( CONFIG_IDF_TARGET_ESP32C3 ) + +#elif defined( CONFIG_IDF_TARGET_ESP32S2 ) + if (_cfg.spi_host == SPI2_HOST) { periph_module_reset( PERIPH_SPI2_DMA_MODULE ); } - else if (_conf.spi_host == SPI3_HOST) + else if (_cfg.spi_host == SPI3_HOST) { periph_module_reset( PERIPH_SPI3_DMA_MODULE ); } @@ -607,7 +845,7 @@ namespace lgfx #endif } - void Bus_SPI::_setup_dma_desc_links(const std::uint8_t *data, std::int32_t len) + void Bus_SPI::_setup_dma_desc_links(const uint8_t *data, int32_t len) { //spicommon_setup_dma_desc_links if (!_cfg.dma_channel) return; @@ -624,14 +862,14 @@ namespace lgfx while (len > SPI_MAX_DMA_LEN) { len -= SPI_MAX_DMA_LEN; - dmadesc->buf = (std::uint8_t *)data; + dmadesc->buf = (uint8_t *)data; data += SPI_MAX_DMA_LEN; - *(std::uint32_t*)dmadesc = SPI_MAX_DMA_LEN | SPI_MAX_DMA_LEN << 12 | 0x80000000; + *(uint32_t*)dmadesc = SPI_MAX_DMA_LEN | SPI_MAX_DMA_LEN << 12 | 0x80000000; dmadesc->qe.stqe_next = dmadesc + 1; dmadesc++; } - *(std::uint32_t*)dmadesc = ((len + 3) & ( ~3 )) | len << 12 | 0xC0000000; - dmadesc->buf = (std::uint8_t *)data; + *(uint32_t*)dmadesc = ((len + 3) & ( ~3 )) | len << 12 | 0xC0000000; + dmadesc->buf = (uint8_t *)data; dmadesc->qe.stqe_next = nullptr; } @@ -639,4 +877,5 @@ namespace lgfx } } -#endif \ No newline at end of file +#endif +#endif diff --git a/src/lgfx/v1/platforms/esp32/Bus_SPI.hpp b/src/lgfx/v1/platforms/esp32/Bus_SPI.hpp index b10b6ff..8ff1d7b 100644 --- a/src/lgfx/v1/platforms/esp32/Bus_SPI.hpp +++ b/src/lgfx/v1/platforms/esp32/Bus_SPI.hpp @@ -17,7 +17,7 @@ Original Source: /----------------------------------------------------------------------------*/ #pragma once -#include +#include #if __has_include() #include @@ -43,24 +43,32 @@ namespace lgfx class Bus_SPI : public IBus { +#if defined (CONFIG_IDF_TARGET_ESP32C3) + static constexpr uint32_t SPI_EXECUTE = SPI_USR | SPI_UPDATE; + #define SPI_MOSI_DLEN_REG(i) (REG_SPI_BASE(i) + 0x1C) + #define SPI_MISO_DLEN_REG(i) (REG_SPI_BASE(i) + 0x1C) +#else + static constexpr uint32_t SPI_EXECUTE = SPI_USR; +#endif public: struct config_t { // max80MHz , 40MHz , 26.67MHz , 20MHz , 16MHz , and more ... - std::uint32_t freq_write = 16000000; - std::uint32_t freq_read = 8000000; - std::int16_t pin_sclk = -1; - std::int16_t pin_miso = -1; - std::int16_t pin_mosi = -1; - std::int16_t pin_dc = -1; - std::uint8_t spi_mode = 0; + uint32_t freq_write = 16000000; + uint32_t freq_read = 8000000; + int16_t pin_sclk = -1; + int16_t pin_miso = -1; + int16_t pin_mosi = -1; + int16_t pin_dc = -1; + uint8_t spi_mode = 0; bool spi_3wire = true; bool use_lock = true; -#if defined (CONFIG_IDF_TARGET_ESP32S2) - spi_host_device_t spi_host = SPI3_HOST; -#else +#if !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32) + uint8_t dma_channel = 0; spi_host_device_t spi_host = VSPI_HOST; - std::uint8_t dma_channel = 0; +#else + uint8_t dma_channel = SPI_DMA_CH_AUTO; // or SPI_DMA_DISABLED + spi_host_device_t spi_host = SPI2_HOST; #endif }; @@ -81,56 +89,86 @@ namespace lgfx bool busy(void) const override; void flush(void) override {} - bool writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) override; - void writeData(std::uint32_t data, std::uint_fast8_t bit_length) override; - void writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t count) override; - void writePixels(pixelcopy_t* pc, std::uint32_t length) override; - void writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) override; + bool writeCommand(uint32_t data, uint_fast8_t bit_length) override; + void writeData(uint32_t data, uint_fast8_t bit_length) override; + void writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t count) override; + void writePixels(pixelcopy_t* pc, uint32_t length) override; + void writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) override; void initDMA(void) override; - void addDMAQueue(const std::uint8_t* data, std::uint32_t length) override; + void addDMAQueue(const uint8_t* data, uint32_t length) override; void execDMAQueue(void) override; - std::uint8_t* getDMABuffer(std::uint32_t length) override { return _flip_buffer.getBuffer(length); } + uint8_t* getDMABuffer(uint32_t length) override { return _flip_buffer.getBuffer(length); } void beginRead(void) override; void endRead(void) override; - std::uint32_t readData(std::uint_fast8_t bit_length) override; - bool readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma) override; - void readPixels(void* dst, pixelcopy_t* pc, std::uint32_t length) override; + uint32_t readData(uint_fast8_t bit_length) override; + bool readBytes(uint8_t* dst, uint32_t length, bool use_dma) override; + void readPixels(void* dst, pixelcopy_t* pc, uint32_t length) override; private: - static __attribute__ ((always_inline)) inline volatile std::uint32_t* reg(std::uint32_t addr) { return (volatile std::uint32_t *)ETS_UNCACHED_ADDR(addr); } - __attribute__ ((always_inline)) inline void dc_control(bool flg) { auto reg = _gpio_reg_dc[flg]; auto mask = _mask_reg_dc; auto cmd = _spi_cmd_reg; while (*cmd & SPI_USR); *reg = mask; } - __attribute__ ((always_inline)) inline void exec_spi(void) { *_spi_cmd_reg = SPI_USR; } + static __attribute__ ((always_inline)) inline volatile uint32_t* reg(uint32_t addr) { return (volatile uint32_t *)ETS_UNCACHED_ADDR(addr); } + __attribute__ ((always_inline)) inline void exec_spi(void) { *_spi_cmd_reg = SPI_EXECUTE; } __attribute__ ((always_inline)) inline void wait_spi(void) { while (*_spi_cmd_reg & SPI_USR); } - __attribute__ ((always_inline)) inline void set_write_len(std::uint32_t bitlen) { *_spi_mosi_dlen_reg = bitlen - 1; } - __attribute__ ((always_inline)) inline void set_read_len( std::uint32_t bitlen) { *reg(SPI_MISO_DLEN_REG(_spi_port)) = bitlen - 1; } + __attribute__ ((always_inline)) inline void set_write_len(uint32_t bitlen) { *_spi_mosi_dlen_reg = bitlen - 1; } + __attribute__ ((always_inline)) inline void set_read_len( uint32_t bitlen) { *reg(SPI_MISO_DLEN_REG(_spi_port)) = bitlen - 1; } + + void dc_control(bool flg) + { + auto reg = _gpio_reg_dc[flg]; + auto mask = _mask_reg_dc; + auto spi_cmd_reg = _spi_cmd_reg; +#if !defined ( CONFIG_IDF_TARGET ) || defined ( CONFIG_IDF_TARGET_ESP32 ) + while (*spi_cmd_reg & SPI_USR) {} // wait SPI +#else + #if defined ( SOC_GDMA_SUPPORTED ) + auto dma = _clear_dma_reg; + if (dma) + { + _clear_dma_reg = nullptr; + while (*spi_cmd_reg & SPI_USR) {} // wait SPI + *dma = 0; + } + else + { + while (*spi_cmd_reg & SPI_USR) {} // wait SPI + } + #else + auto dma = _spi_dma_out_link_reg; + while (*spi_cmd_reg & SPI_USR) {} // wait SPI + *dma = 0; + #endif +#endif + *reg = mask; + } void _alloc_dmadesc(size_t len); void _spi_dma_reset(void); - void _setup_dma_desc_links(const std::uint8_t *data, std::int32_t len); + void _setup_dma_desc_links(const uint8_t *data, int32_t len); config_t _cfg; FlipBuffer _flip_buffer; - volatile std::uint32_t* _gpio_reg_dc[2] = { nullptr, nullptr }; - volatile std::uint32_t* _spi_mosi_dlen_reg = nullptr; - volatile std::uint32_t* _spi_w0_reg = nullptr; - volatile std::uint32_t* _spi_cmd_reg = nullptr; - volatile std::uint32_t* _spi_user_reg = nullptr; - volatile std::uint32_t* _spi_dma_out_link_reg = nullptr; - std::uint32_t _last_freq_apb = 0; - std::uint32_t _clkdiv_write = 0; - std::uint32_t _clkdiv_read = 0; - std::uint32_t _user_reg = 0; - std::uint32_t _mask_reg_dc = 0; - std::uint32_t _dma_queue_bytes = 0; + volatile uint32_t* _gpio_reg_dc[2] = { nullptr, nullptr }; + volatile uint32_t* _spi_mosi_dlen_reg = nullptr; + volatile uint32_t* _spi_w0_reg = nullptr; + volatile uint32_t* _spi_cmd_reg = nullptr; + volatile uint32_t* _spi_user_reg = nullptr; + volatile uint32_t* _spi_dma_out_link_reg = nullptr; + volatile uint32_t* _spi_dma_outstatus_reg = nullptr; + volatile uint32_t* _clear_dma_reg = nullptr; + uint32_t _last_freq_apb = 0; + uint32_t _clkdiv_write = 0; + uint32_t _clkdiv_read = 0; + uint32_t _user_reg = 0; + uint32_t _mask_reg_dc = 0; + uint32_t _dma_queue_bytes = 0; lldesc_t* _dmadesc = nullptr; - std::uint32_t _dmadesc_size = 0; + uint32_t _dmadesc_size = 0; lldesc_t* _dma_queue = nullptr; - std::uint32_t _dma_queue_size = 0; - std::uint32_t _dma_queue_capacity = 0; - std::uint8_t _spi_port = 0; + uint32_t _dma_queue_size = 0; + uint32_t _dma_queue_capacity = 0; + uint8_t _spi_port = 0; bool _next_dma_reset = false; bool _inited = false; }; diff --git a/src/lgfx/v1/platforms/esp32/Light_PWM.cpp b/src/lgfx/v1/platforms/esp32/Light_PWM.cpp index a01d752..aa475a8 100644 --- a/src/lgfx/v1/platforms/esp32/Light_PWM.cpp +++ b/src/lgfx/v1/platforms/esp32/Light_PWM.cpp @@ -15,7 +15,9 @@ Original Source: [mongonta0716](https://github.com/mongonta0716) [tobozo](https://github.com/tobozo) /----------------------------------------------------------------------------*/ -#if defined (ESP32) || defined (CONFIG_IDF_TARGET_ESP32) || defined (CONFIG_IDF_TARGET_ESP32S2) || defined (ESP_PLATFORM) +#if defined (ESP_PLATFORM) +#include +#if !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32) || defined (CONFIG_IDF_TARGET_ESP32S2) #include "Light_PWM.hpp" @@ -31,7 +33,7 @@ namespace lgfx { //---------------------------------------------------------------------------- - bool Light_PWM::init(std::uint8_t brightness) + bool Light_PWM::init(uint8_t brightness) { #ifdef ARDUINO @@ -76,10 +78,10 @@ namespace lgfx return true; } - void Light_PWM::setBrightness(std::uint8_t brightness) + void Light_PWM::setBrightness(uint8_t brightness) { if (_cfg.invert) brightness = ~brightness; - std::uint32_t duty = brightness + (brightness >> 7); + uint32_t duty = brightness + (brightness >> 7); #ifdef ARDUINO ledcWrite(_cfg.pwm_channel, duty); @@ -97,4 +99,5 @@ namespace lgfx } } -#endif \ No newline at end of file +#endif +#endif diff --git a/src/lgfx/v1/platforms/esp32/Light_PWM.hpp b/src/lgfx/v1/platforms/esp32/Light_PWM.hpp index 1a3526e..c10644e 100644 --- a/src/lgfx/v1/platforms/esp32/Light_PWM.hpp +++ b/src/lgfx/v1/platforms/esp32/Light_PWM.hpp @@ -30,9 +30,9 @@ namespace lgfx public: struct config_t { - std::uint32_t freq = 1200; - std::int16_t pin_bl = -1; - std::uint8_t pwm_channel = 7; + uint32_t freq = 1200; + int16_t pin_bl = -1; + uint8_t pwm_channel = 7; bool invert = false; }; @@ -40,8 +40,8 @@ namespace lgfx void config(const config_t &cfg) { _cfg = cfg; } - bool init(std::uint8_t brightness) override; - void setBrightness(std::uint8_t brightness) override; + bool init(uint8_t brightness) override; + void setBrightness(uint8_t brightness) override; private: config_t _cfg; diff --git a/src/lgfx/v1/platforms/esp32/common.cpp b/src/lgfx/v1/platforms/esp32/common.cpp index d5b6b6e..054ae4c 100644 --- a/src/lgfx/v1/platforms/esp32/common.cpp +++ b/src/lgfx/v1/platforms/esp32/common.cpp @@ -15,28 +15,33 @@ Original Source: [mongonta0716](https://github.com/mongonta0716) [tobozo](https://github.com/tobozo) /----------------------------------------------------------------------------*/ -#if defined (ESP32) || defined (CONFIG_IDF_TARGET_ESP32) || defined (CONFIG_IDF_TARGET_ESP32S2) || defined (ESP_PLATFORM) +#if defined (ESP_PLATFORM) +#include +#if !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32) || defined (CONFIG_IDF_TARGET_ESP32S2) || defined (CONFIG_IDF_TARGET_ESP32C3) #include "../common.hpp" #include -#include +#include #include #include +#include #include #include +#include #include #include #include +#include + +#if __has_include() + #include +#endif #if defined ( ARDUINO ) #include #include - #include -#else - #include - #include #endif namespace lgfx @@ -45,7 +50,7 @@ namespace lgfx { //---------------------------------------------------------------------------- - std::uint32_t getApbFrequency(void) + uint32_t getApbFrequency(void) { rtc_cpu_freq_config_t conf; rtc_clk_cpu_freq_get_config(&conf); @@ -55,21 +60,25 @@ namespace lgfx return (conf.source_freq_mhz * 1000000) / conf.div; } - std::uint32_t FreqToClockDiv(std::uint32_t fapb, std::uint32_t hz) + uint32_t FreqToClockDiv(uint32_t fapb, uint32_t hz) { if (fapb <= hz) return SPI_CLK_EQU_SYSCLK; - std::uint32_t div_num = fapb / (1 + hz); - std::uint32_t pre = div_num / 64u; + uint32_t div_num = fapb / (1 + hz); + uint32_t pre = div_num / 64u; div_num = div_num / (pre+1); return div_num << 12 | ((div_num-1)>>1) << 6 | div_num | pre << 18; } //---------------------------------------------------------------------------- - void pinMode(std::int_fast16_t pin, pin_mode_t mode) + void pinMode(int_fast16_t pin, pin_mode_t mode) { if (pin < 0) return; - if (pin < 6 || pin > 11) { + +#if !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32) + if (pin < 6 || pin > 11) +#endif + { gpio_set_direction((gpio_num_t)pin, GPIO_MODE_DISABLE); } #if defined (ARDUINO) @@ -84,7 +93,10 @@ namespace lgfx } ::pinMode(pin, m); #else + +#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED if (rtc_gpio_is_valid_gpio((gpio_num_t)pin)) rtc_gpio_deinit((gpio_num_t)pin); +#endif gpio_config_t io_conf; io_conf.intr_type = GPIO_INTR_DISABLE; io_conf.pin_bit_mask = (std::uint64_t)1 << pin; @@ -108,33 +120,91 @@ namespace lgfx namespace spi { + +#if defined (CONFIG_IDF_TARGET_ESP32C3) + static constexpr uint32_t SPI_EXECUTE = SPI_USR | SPI_UPDATE; + #define SPI_MOSI_DLEN_REG(i) (REG_SPI_BASE(i) + 0x1C) + #define SPI_MISO_DLEN_REG(i) (REG_SPI_BASE(i) + 0x1C) +#else + static constexpr uint32_t SPI_EXECUTE = SPI_USR; +#endif + +#if !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32) + static constexpr int default_spi_host = VSPI_HOST; + static constexpr int spi_periph_num = 3; +#else + static constexpr int default_spi_host = SPI2_HOST; + static constexpr int spi_periph_num = SOC_SPI_PERIPH_NUM; +#endif + #if defined ( ARDUINO ) - static spi_t* _spi_handle[VSPI_HOST + 1] = {nullptr}; -#else // ESP-IDF - static spi_device_handle_t _spi_handle[SOC_SPI_PERIPH_NUM] = {nullptr}; + static spi_t* _spi_handle[spi_periph_num] = {nullptr}; #endif + static spi_device_handle_t _spi_dev_handle[spi_periph_num] = {nullptr}; cpp::result init(int spi_host, int spi_sclk, int spi_miso, int spi_mosi) { - return init(spi_host, spi_sclk, spi_miso, spi_mosi, 0); + return init(spi_host, spi_sclk, spi_miso, spi_mosi, 0); // SPI_DMA_CH_AUTO; } cpp::result init(int spi_host, int spi_sclk, int spi_miso, int spi_mosi, int dma_channel) { //ESP_LOGI("LGFX","spi::init host:%d, sclk:%d, miso:%d, mosi:%d, dma:%d", spi_host, spi_sclk, spi_miso, spi_mosi, dma_channel); - std::uint32_t spi_port = (spi_host + 1); + uint32_t spi_port = (spi_host + 1); + (void)spi_port; + + // バスの設定にはESP-IDFのSPIドライバを使用する。 + if (_spi_dev_handle[spi_host] == nullptr) + { + spi_bus_config_t buscfg = { + .mosi_io_num = spi_mosi, + .miso_io_num = spi_miso, + .sclk_io_num = spi_sclk, + .quadwp_io_num = -1, + .quadhd_io_num = -1, + .max_transfer_sz = 1, + .flags = SPICOMMON_BUSFLAG_MASTER, + .intr_flags = 0, + }; + + if (ESP_OK != spi_bus_initialize(static_cast(spi_host), &buscfg, dma_channel)) + { + ESP_LOGE("LGFX", "Failed to spi_bus_initialize. "); + } + + spi_device_interface_config_t devcfg = { + .command_bits = 0, + .address_bits = 0, + .dummy_bits = 0, + .mode = 0, + .duty_cycle_pos = 0, + .cs_ena_pretrans = 0, + .cs_ena_posttrans = 0, + .clock_speed_hz = (int)getApbFrequency()>>1, + .input_delay_ns = 0, + .spics_io_num = -1, + .flags = SPI_DEVICE_3WIRE | SPI_DEVICE_HALFDUPLEX, + .queue_size = 1, + .pre_cb = nullptr, + .post_cb = nullptr}; + if (ESP_OK != spi_bus_add_device(static_cast(spi_host), &devcfg, &_spi_dev_handle[spi_host])) { + ESP_LOGE("LGFX", "Failed to spi_bus_add_device. "); + } + } #if defined (ARDUINO) // Arduino ESP32 - if (spi_host == VSPI_HOST) + + if (spi_host == default_spi_host) { SPI.end(); SPI.begin(spi_sclk, spi_miso, spi_mosi); _spi_handle[spi_host] = SPI.bus(); } - - if (_spi_handle[spi_host] == nullptr) { + 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); @@ -168,47 +238,13 @@ namespace lgfx WRITE_PERI_REG(SPI_USER_REG (spi_port), SPI_USR_MOSI | SPI_USR_MISO | SPI_DOUTDIN); // need SD card access (full duplex setting) WRITE_PERI_REG(SPI_CTRL_REG( spi_port), 0); WRITE_PERI_REG(SPI_CTRL2_REG(spi_port), 0); - WRITE_PERI_REG(SPI_SLAVE_REG(spi_port), READ_PERI_REG(SPI_SLAVE_REG(spi_port)) & ~(SPI_SLAVE_MODE | SPI_TRANS_DONE)); - -#else // ESP-IDF - - spi_bus_config_t buscfg = { - .mosi_io_num = spi_mosi, - .miso_io_num = spi_miso, - .sclk_io_num = spi_sclk, - .quadwp_io_num = -1, - .quadhd_io_num = -1, - .max_transfer_sz = 1, - .flags = SPICOMMON_BUSFLAG_MASTER, - .intr_flags = 0, - }; - - if (_spi_handle[spi_host] == nullptr) - { - spi_bus_initialize(static_cast(spi_host), &buscfg, dma_channel); - - spi_device_interface_config_t devcfg = { - .command_bits = 0, - .address_bits = 0, - .dummy_bits = 0, - .mode = 0, - .duty_cycle_pos = 0, - .cs_ena_pretrans = 0, - .cs_ena_posttrans = 0, - .clock_speed_hz = (int)getApbFrequency()>>1, - .input_delay_ns = 0, - .spics_io_num = -1, - .flags = SPI_DEVICE_3WIRE | SPI_DEVICE_HALFDUPLEX, - .queue_size = 1, - .pre_cb = nullptr, - .post_cb = nullptr}; - if (ESP_OK != spi_bus_add_device(static_cast(spi_host), &devcfg, &_spi_handle[spi_host])) { - ESP_LOGE("LGFX", "Failed to spi_bus_add_device. "); - } - } - + WRITE_PERI_REG(SPI_SLAVE_REG(spi_port), 0); +//*/ #endif + +#if defined ( SPI_CTRL1_REG ) WRITE_PERI_REG(SPI_CTRL1_REG(spi_port), 0); +#endif return {}; } @@ -216,9 +252,10 @@ namespace lgfx void release(int spi_host) { //ESP_LOGI("LGFX","spi::release"); - if (_spi_handle[spi_host] != nullptr) { #if defined (ARDUINO) // Arduino ESP32 - if (spi_host == VSPI_HOST) + if (_spi_handle[spi_host] != nullptr) + { + if (spi_host == default_spi_host) { SPI.end(); } @@ -226,12 +263,15 @@ namespace lgfx { spiStopBus(_spi_handle[spi_host]); } -#else // ESP-IDF - spi_bus_remove_device(_spi_handle[spi_host]); - spi_bus_free(static_cast(spi_host)); -#endif _spi_handle[spi_host] = nullptr; } +#endif + if (_spi_dev_handle[spi_host] != nullptr) + { + spi_bus_remove_device(_spi_dev_handle[spi_host]); + spi_bus_free(static_cast(spi_host)); + _spi_dev_handle[spi_host] = nullptr; + } } void beginTransaction(int spi_host) @@ -239,22 +279,23 @@ namespace lgfx #if defined (ARDUINO) // Arduino ESP32 spiSimpleTransaction(_spi_handle[spi_host]); #else // ESP-IDF - if (_spi_handle[spi_host]) { - if (ESP_OK != spi_device_acquire_bus(_spi_handle[spi_host], portMAX_DELAY)) { + if (_spi_dev_handle[spi_host]) { + if (ESP_OK != spi_device_acquire_bus(_spi_dev_handle[spi_host], portMAX_DELAY)) { ESP_LOGE("LGFX", "Failed to spi_device_acquire_bus. "); } } #endif } - void beginTransaction(int spi_host, std::uint32_t freq, int spi_mode) + void beginTransaction(int spi_host, uint32_t freq, int spi_mode) { - std::uint32_t spi_port = (spi_host + 1); - std::uint32_t clkdiv = FreqToClockDiv(getApbFrequency(), freq); + uint32_t spi_port = (spi_host + 1); + (void)spi_port; + uint32_t clkdiv = FreqToClockDiv(getApbFrequency(), freq); - std::uint32_t user = SPI_USR_MOSI | SPI_USR_MISO | SPI_DOUTDIN; + uint32_t user = SPI_USR_MOSI | SPI_USR_MISO | SPI_DOUTDIN; if (spi_mode == 1 || spi_mode == 2) user |= SPI_CK_OUT_EDGE; - std::uint32_t pin = 0; + uint32_t pin = 0; if (spi_mode & 2) pin = SPI_CK_IDLE_EDGE; beginTransaction(spi_host); @@ -271,45 +312,47 @@ namespace lgfx void endTransaction(int spi_host) { - if (_spi_handle[spi_host]) { + if (_spi_dev_handle[spi_host]) { #if defined (ARDUINO) // Arduino ESP32 spiEndTransaction(_spi_handle[spi_host]); #else // ESP-IDF - spi_device_release_bus(_spi_handle[spi_host]); + spi_device_release_bus(_spi_dev_handle[spi_host]); #endif } } void endTransaction(int spi_host, int spi_cs) { - if (_spi_handle[spi_host]) { + if (_spi_dev_handle[spi_host]) { #if defined (ARDUINO) // Arduino ESP32 spiEndTransaction(_spi_handle[spi_host]); #else // ESP-IDF - spi_device_release_bus(_spi_handle[spi_host]); + spi_device_release_bus(_spi_dev_handle[spi_host]); #endif } gpio_hi(spi_cs); } - void writeBytes(int spi_host, const std::uint8_t* data, std::size_t len) + void writeBytes(int spi_host, const uint8_t* data, size_t len) { - std::uint32_t spi_port = (spi_host + 1); + uint32_t spi_port = (spi_host + 1); + (void)spi_port; if (len > 64) len = 64; memcpy(reinterpret_cast(SPI_W0_REG(spi_port)), data, len); WRITE_PERI_REG(SPI_MOSI_DLEN_REG(spi_port), (len << 3) - 1); WRITE_PERI_REG(SPI_CMD_REG( spi_port), SPI_USR); - while (READ_PERI_REG(SPI_CMD_REG(spi_port)) & SPI_USR); + while (READ_PERI_REG(SPI_CMD_REG(spi_port)) & SPI_EXECUTE); } - void readBytes(int spi_host, std::uint8_t* data, std::size_t len) + void readBytes(int spi_host, uint8_t* data, size_t len) { - std::uint32_t spi_port = (spi_host + 1); + uint32_t spi_port = (spi_host + 1); + (void)spi_port; if (len > 64) len = 64; memcpy(reinterpret_cast(SPI_W0_REG(spi_port)), data, len); WRITE_PERI_REG(SPI_MOSI_DLEN_REG(spi_port), (len << 3) - 1); WRITE_PERI_REG(SPI_CMD_REG( spi_port), SPI_USR); - while (READ_PERI_REG(SPI_CMD_REG(spi_port)) & SPI_USR); + while (READ_PERI_REG(SPI_CMD_REG(spi_port)) & SPI_EXECUTE); memcpy(data, reinterpret_cast(SPI_W0_REG(spi_port)), len); } @@ -319,6 +362,65 @@ namespace lgfx namespace i2c { +#if !defined ( I2C_ACK_ERR_INT_RAW_M ) + #define I2C_ACK_ERR_INT_RAW_M I2C_NACK_INT_RAW_M +#endif + +#if __has_include() + static periph_module_t getPeriphModule(int num) + { + return i2c_periph_signal[num].module; + } +#else + static periph_module_t getPeriphModule(int num) + { + return num == 0 ? PERIPH_I2C0_MODULE : PERIPH_I2C1_MODULE; + } +#endif + +#if defined ( CONFIG_IDF_TARGET_ESP32C3 ) + + static i2c_dev_t* getDev(int num) + { + return &I2C0; + } + static void updateDev(i2c_dev_t* dev) + { + dev->ctr.conf_upgate = 1; + } + static volatile uint32_t* getFifoAddr(int num) + { + return &I2C0.fifo_data.val; + } + + static constexpr int i2c_cmd_start = 6; + static constexpr int i2c_cmd_write = 1; + static constexpr int i2c_cmd_read = 3; + static constexpr int i2c_cmd_stop = 2; + static constexpr int i2c_cmd_end = 4; + +#else + + static i2c_dev_t* getDev(int num) + { + return num == 0 ? &I2C0 : &I2C1; + } + static void updateDev(i2c_dev_t* dev) + { + } + static volatile uint32_t* getFifoAddr(int num) + { + return (volatile uint32_t*)((num == 0) ? 0x6001301c : 0x6002701c); + } + + static constexpr int i2c_cmd_start = 0; + static constexpr int i2c_cmd_write = 1; + static constexpr int i2c_cmd_read = 2; + static constexpr int i2c_cmd_stop = 3; + static constexpr int i2c_cmd_end = 4; + +#endif + static constexpr int I2C_7BIT_ADDR_MIN = 0x08; static constexpr int I2C_7BIT_ADDR_MAX = 0x77; static constexpr int I2C_10BIT_ADDR_MAX = 1023; @@ -335,7 +437,7 @@ namespace lgfx bool wait_ack = false; gpio_num_t pin_scl = (gpio_num_t)-1; gpio_num_t pin_sda = (gpio_num_t)-1; - std::uint32_t freq = 0; + uint32_t freq = 0; void save_reg(i2c_dev_t* dev) { @@ -347,10 +449,14 @@ namespace lgfx scl_stop_setup = dev->scl_stop_setup.val ; sda_hold = dev->sda_hold.val ; sda_sample = dev->sda_sample.val ; - scl_filter = dev->scl_filter_cfg.val ; - sda_filter = dev->sda_filter_cfg.val ; fifo_conf = dev->fifo_conf.val ; timeout = dev->timeout.val ; +#if defined ( I2C_FILTER_CFG_REG ) + filter_cfg = dev->filter_cfg.val ; +#else + scl_filter = dev->scl_filter_cfg.val ; + sda_filter = dev->sda_filter_cfg.val ; +#endif } void load_reg(i2c_dev_t* dev) @@ -363,40 +469,59 @@ namespace lgfx dev->scl_stop_setup.val = scl_stop_setup ; dev->sda_hold.val = sda_hold ; dev->sda_sample.val = sda_sample ; - dev->scl_filter_cfg.val = scl_filter ; - dev->sda_filter_cfg.val = sda_filter ; dev->fifo_conf.val = fifo_conf ; dev->timeout.val = timeout ; +#if defined ( I2C_FILTER_CFG_REG ) + dev->filter_cfg.val = filter_cfg ; +#else + dev->scl_filter_cfg.val = scl_filter ; + dev->sda_filter_cfg.val = sda_filter ; +#endif } private: - std::uint32_t scl_high_period; - std::uint32_t scl_low_period; - std::uint32_t scl_start_hold; - std::uint32_t scl_rstart_setup; - std::uint32_t scl_stop_hold; - std::uint32_t scl_stop_setup; - std::uint32_t sda_hold; - std::uint32_t sda_sample; - std::uint32_t scl_filter; - std::uint32_t sda_filter; - std::uint32_t fifo_conf; - std::uint32_t timeout; + uint32_t scl_high_period; + uint32_t scl_low_period; + uint32_t scl_start_hold; + uint32_t scl_rstart_setup; + uint32_t scl_stop_hold; + uint32_t scl_stop_setup; + uint32_t sda_hold; + uint32_t sda_sample; + uint32_t fifo_conf; + uint32_t timeout; +#if defined ( I2C_FILTER_CFG_REG ) + uint32_t filter_cfg; +#else + uint32_t scl_filter; + uint32_t sda_filter; +#endif }; i2c_context_t i2c_context[I2C_NUM_MAX]; + + static void i2c_set_cmd(i2c_dev_t* dev, uint8_t index, uint8_t op_code, uint8_t byte_num) { +/* typeof(dev->command[0]) cmd; cmd.val = 0; - cmd.ack_en = (op_code == I2C_CMD_WRITE || op_code == I2C_CMD_STOP); + cmd.ack_en = (op_code == i2c_cmd_write || op_code == i2c_cmd_stop); cmd.byte_num = byte_num; cmd.op_code = op_code; dev->command[index].val = cmd.val; +*/ + uint32_t cmd_val = byte_num + | (( op_code == i2c_cmd_write + || op_code == i2c_cmd_stop) + ? 0x100 : 0) // writeおよびstop時はACK_ENを有効にする + | op_code << 11 ; + dev->command[index].val = cmd_val; } static void i2c_stop(int i2c_port) { +#if 1 //!defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32) static constexpr int I2C_CLR_BUS_HALF_PERIOD_US = 5; // use standard 100kHz data rate static constexpr int I2C_CLR_BUS_SCL_NUM = 9; @@ -408,7 +533,7 @@ namespace lgfx gpio_set_level(scl_io, 1); gpio_set_direction(scl_io, GPIO_MODE_OUTPUT_OD); - auto mod = i2c_port == 0 ? PERIPH_I2C0_MODULE : PERIPH_I2C1_MODULE; + auto mod = getPeriphModule(i2c_port); // ESP-IDF環境でperiph_module_disableを使うと、後でenableできなくなる問題が起きたためコメントアウト //periph_module_disable(mod); gpio_set_level(scl_io, 0); @@ -428,6 +553,13 @@ namespace lgfx periph_module_reset(mod); //gpio_set_level(sda_io, 1); // STOP, SDA low -> high while SCL is HIGH i2c_set_pin((i2c_port_t)i2c_port, sda_io, scl_io, gpio_pullup_t::GPIO_PULLUP_ENABLE, gpio_pullup_t::GPIO_PULLUP_ENABLE, I2C_MODE_MASTER); +#else + auto dev = getDev(i2c_port); + dev->scl_sp_conf.scl_rst_slv_num = 9; + dev->scl_sp_conf.scl_rst_slv_en = 0; + updateDev(dev); + dev->scl_sp_conf.scl_rst_slv_en = 1; +#endif } static cpp::result i2c_wait(int i2c_port, bool flg_stop = false) @@ -435,25 +567,31 @@ namespace lgfx if (i2c_context[i2c_port].state.has_error()) { return cpp::fail(i2c_context[i2c_port].state.error()); } cpp::result res = {}; if (i2c_context[i2c_port].state == i2c_context_t::state_disconnect) { return res; } - auto dev = (i2c_port == 0) ? &I2C0 : &I2C1; + auto dev = getDev(i2c_port); typeof(dev->int_raw) int_raw; -// static constexpr std::uint32_t intmask = I2C_ACK_ERR_INT_RAW_M | I2C_TIME_OUT_INT_RAW_M | I2C_END_DETECT_INT_RAW_M | I2C_ARBITRATION_LOST_INT_RAW_M; - static constexpr std::uint32_t intmask = I2C_ACK_ERR_INT_RAW_M | I2C_END_DETECT_INT_RAW_M | I2C_ARBITRATION_LOST_INT_RAW_M; + static constexpr uint32_t intmask = I2C_ACK_ERR_INT_RAW_M | I2C_END_DETECT_INT_RAW_M | I2C_ARBITRATION_LOST_INT_RAW_M; if (i2c_context[i2c_port].wait_ack) { int_raw.val = dev->int_raw.val; if (!(int_raw.val & intmask)) { - std::uint32_t us = lgfx::micros(); - std::uint32_t us_limit = (dev->scl_high_period.period + dev->scl_low_period.period + 16 ) * (1 + dev->status_reg.tx_fifo_cnt); + uint32_t us = lgfx::micros(); +#if defined ( CONFIG_IDF_TARGET_ESP32C3 ) + uint32_t us_limit = (dev->scl_high_period.period + dev->scl_low_period.period + 16 ) * (1 + dev->sr.tx_fifo_cnt); +#else + uint32_t us_limit = (dev->scl_high_period.period + dev->scl_low_period.period + 16 ) * (1 + dev->status_reg.tx_fifo_cnt); +#endif do { int_raw.val = dev->int_raw.val; } while (!(int_raw.val & intmask) && ((lgfx::micros() - us) <= us_limit)); } dev->int_clr.val = int_raw.val; - +#if !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32) if (!int_raw.end_detect || int_raw.ack_err) +#else + if (!int_raw.end_detect || int_raw.nack) +#endif { res = cpp::fail(error_t::connection_lost); i2c_context[i2c_port].state = cpp::fail(error_t::connection_lost); @@ -468,13 +606,17 @@ namespace lgfx } else { - i2c_set_cmd(dev, 0, I2C_CMD_STOP, 0); + i2c_set_cmd(dev, 0, i2c_cmd_stop, 0); dev->ctr.trans_start = 1; - static constexpr std::uint32_t intmask = I2C_ACK_ERR_INT_RAW_M | I2C_TIME_OUT_INT_RAW_M | I2C_END_DETECT_INT_RAW_M | I2C_ARBITRATION_LOST_INT_RAW_M | I2C_TRANS_COMPLETE_INT_RAW_M; - std::uint32_t ms = lgfx::millis(); + static constexpr uint32_t intmask = I2C_ACK_ERR_INT_RAW_M | I2C_TIME_OUT_INT_RAW_M | I2C_END_DETECT_INT_RAW_M | I2C_ARBITRATION_LOST_INT_RAW_M | I2C_TRANS_COMPLETE_INT_RAW_M; + uint32_t ms = lgfx::millis(); taskYIELD(); while (!(dev->int_raw.val & intmask) && ((millis() - ms) < 14)); +#if !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32) if (res.has_value() && dev->int_raw.ack_err) +#else + if (res.has_value() && dev->int_raw.nack) +#endif { res = cpp::fail(error_t::connection_lost); } @@ -493,7 +635,7 @@ namespace lgfx cpp::result init(int i2c_port, int pin_sda, int pin_scl) { if (i2c_port >= I2C_NUM_MAX) { return cpp::fail(error_t::invalid_arg); } - auto dev = (i2c_port == 0) ? &I2C0 : &I2C1; + auto dev = getDev(i2c_port); i2c_context[i2c_port].save_reg(dev); release(i2c_port); i2c_context[i2c_port].pin_scl = (gpio_num_t)pin_scl; @@ -501,6 +643,10 @@ namespace lgfx i2c_stop(i2c_port); i2c_context[i2c_port].load_reg(dev); +//ESP_LOGI("LGFX", "i2c_set_pin : %d", res); + // i2c_set_pin((i2c_port_t)i2c_port, pin_sda, pin_scl, gpio_pullup_t::GPIO_PULLUP_ENABLE, gpio_pullup_t::GPIO_PULLUP_ENABLE, I2C_MODE_MASTER); + // periph_module_enable(getPeriphModule(i2c_port)); + return {}; } @@ -511,7 +657,7 @@ namespace lgfx if (i2c_context[i2c_port].pin_scl >= 0 || i2c_context[i2c_port].pin_sda >= 0) { // ESP-IDF環境でperiph_module_disableを使うと、後でenableできなくなる問題が起きたためコメントアウト -// periph_module_disable(i2c_port == 0 ? PERIPH_I2C0_MODULE : PERIPH_I2C1_MODULE); +// periph_module_disable(getPeriphModule(i2c_port)); pinMode(i2c_context[i2c_port].pin_scl, pin_mode_t::input); pinMode(i2c_context[i2c_port].pin_sda, pin_mode_t::input); i2c_context[i2c_port].pin_scl = (gpio_num_t)-1; @@ -521,7 +667,7 @@ namespace lgfx return {}; } - cpp::result restart(int i2c_port, int i2c_addr, std::uint32_t freq, bool read) + cpp::result restart(int i2c_port, int i2c_addr, uint32_t freq, bool read) { if (i2c_port >= I2C_NUM_MAX) { return cpp::fail(error_t::invalid_arg); } if (i2c_addr < I2C_7BIT_ADDR_MIN || i2c_addr > I2C_10BIT_ADDR_MAX) return cpp::fail(error_t::invalid_arg); @@ -529,65 +675,97 @@ namespace lgfx auto res = i2c_wait(i2c_port); if (res.has_error()) return res; -//ESP_LOGI("LGFX", "i2c::beginTransaction : port:%d / addr:%02x / freq:%d / rw:%d", i2c_port, i2c_addr, freq, read); +// ESP_LOGI("LGFX", "i2c::restart : port:%d / addr:%02x / freq:%d / rw:%d", i2c_port, i2c_addr, freq, read); - auto dev = (i2c_port == 0) ? &I2C0 : &I2C1; + auto dev = getDev(i2c_port); - uint32_t fifo_addr = (i2c_port == 0) ? 0x6001301c : 0x6002701c; - i2c_set_cmd(dev, 0, I2C_CMD_RESTART, 0); - i2c_set_cmd(dev, 2, I2C_CMD_END, 0); + auto fifo_addr = getFifoAddr(i2c_port); + i2c_set_cmd(dev, 0, i2c_cmd_start, 0); + i2c_set_cmd(dev, 2, i2c_cmd_end, 0); if (i2c_addr <= I2C_7BIT_ADDR_MAX) { // 7bitアドレスの場合 - WRITE_PERI_REG(fifo_addr, i2c_addr << 1 | (read ? I2C_MASTER_READ : I2C_MASTER_WRITE)); - i2c_set_cmd(dev, 1, I2C_CMD_WRITE, 1); + *fifo_addr = i2c_addr << 1 | (read ? I2C_MASTER_READ : I2C_MASTER_WRITE); + i2c_set_cmd(dev, 1, i2c_cmd_write, 1); } else { // 10bitアドレスの場合 - WRITE_PERI_REG(fifo_addr, 0xF0 | (i2c_addr>>8)<<1 | I2C_MASTER_WRITE); - WRITE_PERI_REG(fifo_addr, i2c_addr); - i2c_set_cmd(dev, 1, I2C_CMD_WRITE, 2); + *fifo_addr = 0xF0 | (i2c_addr>>8)<<1 | I2C_MASTER_WRITE; + *fifo_addr = i2c_addr; + i2c_set_cmd(dev, 1, i2c_cmd_write, 2); if (read) { // 10bitアドレスのread要求の場合 - WRITE_PERI_REG(fifo_addr, 0xF0 | (i2c_addr>>8)<<1 | I2C_MASTER_READ); - i2c_set_cmd(dev, 2, I2C_CMD_RESTART, 0); - i2c_set_cmd(dev, 3, I2C_CMD_READ, 1); - i2c_set_cmd(dev, 4, I2C_CMD_END, 0); + *fifo_addr = 0xF0 | (i2c_addr>>8)<<1 | I2C_MASTER_READ; + i2c_set_cmd(dev, 2, i2c_cmd_start, 0); + i2c_set_cmd(dev, 3, i2c_cmd_read, 1); + i2c_set_cmd(dev, 4, i2c_cmd_end, 0); } } if (i2c_context[i2c_port].state == i2c_context_t::state_disconnect || i2c_context[i2c_port].freq != freq) { i2c_context[i2c_port].freq = freq; - static constexpr std::uint32_t MIN_I2C_CYCLE = 35; + static constexpr uint32_t MIN_I2C_CYCLE = 35; +#if defined (CONFIG_IDF_TARGET_ESP32C3) + uint32_t src_clock = 40 * 1000 * 1000; // XTAL clock +#else rtc_cpu_freq_config_t cpu_freq_conf; rtc_clk_cpu_freq_get_config(&cpu_freq_conf); - std::uint32_t apb = 80 * 1000000; + uint32_t src_clock = 80 * 1000 * 1000; if (cpu_freq_conf.freq_mhz < 80) { - apb = (cpu_freq_conf.source_freq_mhz * 1000000) / cpu_freq_conf.div; + src_clock = (cpu_freq_conf.source_freq_mhz * 1000000) / cpu_freq_conf.div; } - std::uint32_t cycle = std::min(32767u, std::max(MIN_I2C_CYCLE, (apb / (freq + 1) + 1))); - freq = apb / cycle; +// ESP_LOGI("LGFX", "i2c::restart : port:%d / addr:%02x / freq:%d / rw:%d", i2c_port, i2c_addr, freq, read); +// ESP_LOGI("LGFX", "cpu_freq_conf.div :%d", cpu_freq_conf.div); +// ESP_LOGI("LGFX", "cpu_freq_conf.freq_mhz :%d", cpu_freq_conf.freq_mhz); +// ESP_LOGI("LGFX", "cpu_freq_conf.source :%d", cpu_freq_conf.source); +// ESP_LOGI("LGFX", "cpu_freq_conf.source_freq_mhz :%d", cpu_freq_conf.source_freq_mhz); +#endif + + auto cycle = std::min(32767u, std::max(MIN_I2C_CYCLE, (src_clock / (freq + 1) + 1))); + freq = src_clock / cycle; + +#if defined (CONFIG_IDF_TARGET_ESP32S2) + dev->ctr.ref_always_on = 1; +#endif + +#if defined ( I2C_FILTER_CFG_REG ) + dev->filter_cfg.scl_en = cycle > 64; + dev->filter_cfg.scl_thres = 0; + dev->filter_cfg.sda_en = cycle > 64; + dev->filter_cfg.sda_thres = 0; + + uint32_t scl_high_offset = ( dev->filter_cfg.scl_en + ? ( dev->filter_cfg.scl_thres <= 2 + ? 8 : (6 + dev->filter_cfg.scl_thres) + ) + : 7 + ); + dev->clk_conf.sclk_sel = 0; +#else dev->scl_filter_cfg.en = cycle > 64; dev->scl_filter_cfg.thres = 0; dev->sda_filter_cfg.en = cycle > 64; dev->sda_filter_cfg.thres = 0; - /// ESP32 TRM page 286 Table 57: SCL Frequency Configuration - std::uint32_t scl_high_offset = ( dev->scl_filter_cfg.en + uint32_t scl_high_offset = ( dev->scl_filter_cfg.en ? ( dev->scl_filter_cfg.thres <= 2 ? 8 : (6 + dev->scl_filter_cfg.thres) ) : 7 ); - std::uint32_t period_total = cycle - scl_high_offset - 1; - std::uint32_t scl_high_period = std::max(18u, (period_total-10) >> 1); - std::uint32_t scl_low_period = period_total - scl_high_period; +#endif + + uint32_t period_total = cycle - scl_high_offset - 1; + uint32_t scl_high_period = std::max(18, (period_total-10) >> 1); + uint32_t scl_low_period = period_total - scl_high_period; dev->scl_high_period.period = scl_high_period; dev->scl_low_period .period = scl_low_period ; - +#if defined (CONFIG_IDF_TARGET_ESP32S2) || defined (CONFIG_IDF_TARGET_ESP32C3) + dev->scl_high_period.scl_wait_high_period = scl_high_period >> 2; +#endif dev->sda_hold.time = std::min(1023, (dev->scl_high_period.period >> 1)); dev->sda_sample.time = std::min(1023, (dev->scl_low_period .period >> 1)); @@ -606,39 +784,58 @@ namespace lgfx dev->scl_rstart_setup.time = cycle; //the clock num between the posedge of SCL and the negedge of SDA for restart mark } - dev->int_clr.val = 0x1FFF; + updateDev(dev); + dev->int_clr.val = 0x1FFFF; dev->ctr.trans_start = 1; i2c_context[i2c_port].state = read ? i2c_context_t::state_t::state_read : i2c_context_t::state_t::state_write; i2c_context[i2c_port].wait_ack = true; - return res; } - cpp::result beginTransaction(int i2c_port, int i2c_addr, std::uint32_t freq, bool read) + cpp::result beginTransaction(int i2c_port, int i2c_addr, uint32_t freq, bool read) { if (i2c_port >= I2C_NUM_MAX) return cpp::fail(error_t::invalid_arg); //ESP_LOGI("LGFX", "i2c::beginTransaction : port:%d / addr:%02x / freq:%d / rw:%d", i2c_port, i2c_addr, freq, read); - auto dev = (i2c_port == 0) ? &I2C0 : &I2C1; + auto dev = getDev(i2c_port); i2c_context[i2c_port].save_reg(dev); +#if defined ( CONFIG_IDF_TARGET_ESP32C3 ) + if (dev->sr.bus_busy) +#else if (dev->status_reg.bus_busy) +#endif { //ESP_LOGI("LGFX", "i2c::begin wait"); auto ms = micros(); do { taskYIELD(); - } while (dev->status_reg.bus_busy && micros() - ms < 128); + } +#if defined ( CONFIG_IDF_TARGET_ESP32C3 ) + while (dev->sr.bus_busy && micros() - ms < 128); +#else + while (dev->status_reg.bus_busy && micros() - ms < 128); +#endif } - dev->int_ena.val = 0; +#if SOC_I2C_SUPPORT_HW_FSM_RST + dev->ctr.fsm_rst = 1; +#endif + +#if defined ( CONFIG_IDF_TARGET_ESP32C3 ) + dev->timeout.time_out_value = 31; + dev->timeout.time_out_en = 1; +#else dev->timeout.tout = 0xFFFFF; // max 13ms +#endif + dev->int_ena.val = 0; // ---------- i2c_ll_master_init typeof(dev->ctr) ctrl_reg; ctrl_reg.val = 0; ctrl_reg.ms_mode = 1; // master mode + ctrl_reg.clk_en = 1; ctrl_reg.sda_force_out = 1; ctrl_reg.scl_force_out = 1; dev->ctr.val = ctrl_reg.val; @@ -650,6 +847,9 @@ namespace lgfx dev->fifo_conf.val = fifo_conf_reg.val; fifo_conf_reg.val = 0; +#if defined (CONFIG_IDF_TARGET_ESP32S2) || defined (CONFIG_IDF_TARGET_ESP32C3) + fifo_conf_reg.fifo_prt_en = 1; +#endif dev->fifo_conf.val = fifo_conf_reg.val; i2c_context[i2c_port].state = i2c_context_t::state_t::state_disconnect; @@ -663,7 +863,7 @@ namespace lgfx return i2c_wait(i2c_port, true); } //*/ - cpp::result writeBytes(int i2c_port, const std::uint8_t *data, std::size_t length) + cpp::result writeBytes(int i2c_port, const uint8_t *data, size_t length) { if (i2c_port >= I2C_NUM_MAX) { return cpp::fail(error_t::invalid_arg); } if (i2c_context[i2c_port].state.has_error()) { return cpp::fail(i2c_context[i2c_port].state.error()); } @@ -672,9 +872,9 @@ namespace lgfx if (!length) return res; static constexpr int txfifo_limit = 32; - auto dev = (i2c_port == 0) ? &I2C0 : &I2C1; - uint32_t fifo_addr = (i2c_port == 0) ? 0x6001301c : 0x6002701c; - std::size_t len = ((length - 1) & (txfifo_limit-1)) + 1; + auto dev = getDev(i2c_port); + auto fifo_addr = getFifoAddr(i2c_port); + size_t len = ((length - 1) & (txfifo_limit-1)) + 1; do { res = i2c_wait(i2c_port); @@ -683,13 +883,14 @@ namespace lgfx ESP_LOGE("LGFX", "i2c write error : ack wait"); break; } - std::size_t idx = 0; + size_t idx = 0; do { - WRITE_PERI_REG(fifo_addr, data[idx]); + *fifo_addr = data[idx]; } while (++idx != len); - i2c_set_cmd(dev, 0, I2C_CMD_WRITE, len); - i2c_set_cmd(dev, 1, I2C_CMD_END, 0); + i2c_set_cmd(dev, 0, i2c_cmd_write, len); + i2c_set_cmd(dev, 1, i2c_cmd_end, 0); + updateDev(dev); dev->ctr.trans_start = 1; i2c_context[i2c_port].wait_ack = true; data += len; @@ -699,7 +900,7 @@ namespace lgfx return res; } - cpp::result readBytes(int i2c_port, std::uint8_t *readdata, std::size_t length) + cpp::result readBytes(int i2c_port, uint8_t *readdata, size_t length) { if (i2c_port >= I2C_NUM_MAX) { return cpp::fail(error_t::invalid_arg); } if (i2c_context[i2c_port].state.has_error()) { return cpp::fail(i2c_context[i2c_port].state.error()); } @@ -707,12 +908,12 @@ namespace lgfx cpp::result res {}; if (!length) return res; - static constexpr std::uint32_t intmask = I2C_ACK_ERR_INT_RAW_M | I2C_TIME_OUT_INT_RAW_M | I2C_END_DETECT_INT_RAW_M | I2C_ARBITRATION_LOST_INT_RAW_M; - - auto dev = (i2c_port == 0) ? &I2C0 : &I2C1; - std::size_t len = 0; + static constexpr uint32_t intmask = I2C_ACK_ERR_INT_RAW_M | I2C_TIME_OUT_INT_RAW_M | I2C_END_DETECT_INT_RAW_M | I2C_ARBITRATION_LOST_INT_RAW_M; + auto fifo_addr = getFifoAddr(i2c_port); + auto dev = getDev(i2c_port); + size_t len = 0; - std::uint32_t us_limit = (dev->scl_high_period.period + dev->scl_low_period.period + 16); + uint32_t us_limit = (dev->scl_high_period.period + dev->scl_low_period.period + 16); do { len = ((length-1) & 63) + 1; @@ -723,18 +924,23 @@ namespace lgfx ESP_LOGE("LGFX", "i2c read error : ack wait"); break; } - i2c_set_cmd(dev, 0, I2C_CMD_READ, len); - i2c_set_cmd(dev, 1, I2C_CMD_END, 0); + i2c_set_cmd(dev, 0, i2c_cmd_read, len); + i2c_set_cmd(dev, 1, i2c_cmd_end, 0); dev->int_clr.val = intmask; dev->ctr.trans_start = 1; //taskYIELD(); do { - std::uint32_t us = lgfx::micros(); + uint32_t us = lgfx::micros(); +#if defined ( CONFIG_IDF_TARGET_ESP32C3 ) + while (0 == dev->sr.rx_fifo_cnt && !(dev->int_raw.val & intmask) && ((micros() - us) <= us_limit)); + if (0 != dev->sr.rx_fifo_cnt) +#else while (0 == dev->status_reg.rx_fifo_cnt && !(dev->int_raw.val & intmask) && ((micros() - us) <= us_limit)); if (0 != dev->status_reg.rx_fifo_cnt) +#endif { - *readdata++ = dev->fifo_data.data; + *readdata++ = *fifo_addr; //dev->fifo_data.data; } else { @@ -749,7 +955,7 @@ namespace lgfx return res; } - cpp::result transactionWrite(int i2c_port, int addr, const std::uint8_t *writedata, std::uint8_t writelen, std::uint32_t freq) + cpp::result transactionWrite(int i2c_port, int addr, const uint8_t *writedata, uint8_t writelen, uint32_t freq) { cpp::result res; if ((res = beginTransaction(i2c_port, addr, freq, false)).has_value() @@ -761,7 +967,7 @@ namespace lgfx return res; } - cpp::result transactionRead(int i2c_port, int addr, std::uint8_t *readdata, std::uint8_t readlen, std::uint32_t freq) + cpp::result transactionRead(int i2c_port, int addr, uint8_t *readdata, uint8_t readlen, uint32_t freq) { cpp::result res; if ((res = beginTransaction(i2c_port, addr, freq, true)).has_value() @@ -773,7 +979,7 @@ namespace lgfx return res; } - cpp::result transactionWriteRead(int i2c_port, int addr, const std::uint8_t *writedata, std::uint8_t writelen, std::uint8_t *readdata, std::size_t readlen, std::uint32_t freq) + cpp::result transactionWriteRead(int i2c_port, int addr, const uint8_t *writedata, uint8_t writelen, uint8_t *readdata, size_t readlen, uint32_t freq) { cpp::result res; if ((res = beginTransaction(i2c_port, addr, freq, false)).has_value() @@ -787,16 +993,16 @@ namespace lgfx return res; } - cpp::result readRegister8(int i2c_port, int addr, std::uint8_t reg, std::uint32_t freq) + cpp::result readRegister8(int i2c_port, int addr, uint8_t reg, uint32_t freq) { auto res = transactionWriteRead(i2c_port, addr, ®, 1, ®, 1, freq); if (res.has_value()) { return reg; } return cpp::fail( res.error() ); } - cpp::result writeRegister8(int i2c_port, int addr, std::uint8_t reg, std::uint8_t data, std::uint8_t mask, std::uint32_t freq) + cpp::result writeRegister8(int i2c_port, int addr, uint8_t reg, uint8_t data, uint8_t mask, uint32_t freq) { - std::uint8_t tmp[2] = { reg, data }; + uint8_t tmp[2] = { reg, data }; if (mask) { auto res = transactionWriteRead(i2c_port, addr, ®, 1, &tmp[1], 1, freq); @@ -813,3 +1019,4 @@ namespace lgfx } #endif +#endif diff --git a/src/lgfx/v1/platforms/esp32/common.hpp b/src/lgfx/v1/platforms/esp32/common.hpp index 100a559..6c09f43 100644 --- a/src/lgfx/v1/platforms/esp32/common.hpp +++ b/src/lgfx/v1/platforms/esp32/common.hpp @@ -21,11 +21,19 @@ Original Source: #include "../../misc/enum.hpp" #include "../../../utility/result.hpp" -#include +#include #include #include #include +#include +#include +#include + +#if !defined ( REG_SPI_BASE ) +//#define REG_SPI_BASE(i) (DR_REG_SPI0_BASE - (i) * 0x1000) +#define REG_SPI_BASE(i) (DR_REG_SPI2_BASE) +#endif namespace lgfx { @@ -35,11 +43,11 @@ namespace lgfx __attribute__ ((unused)) static inline unsigned long millis(void) { return (unsigned long) (esp_timer_get_time() / 1000ULL); } __attribute__ ((unused)) static inline unsigned long micros(void) { return (unsigned long) (esp_timer_get_time()); } - __attribute__ ((unused)) static inline void delayMicroseconds(std::uint32_t us) { ets_delay_us(us); } - __attribute__ ((unused)) static inline void delay(std::uint32_t ms) + __attribute__ ((unused)) static inline void delayMicroseconds(uint32_t us) { ets_delay_us(us); } + __attribute__ ((unused)) static inline void delay(uint32_t ms) { - std::uint32_t time = micros(); - vTaskDelay( std::max(2u, ms / portTICK_PERIOD_MS) - 1 ); + uint32_t time = micros(); + vTaskDelay( std::max(2u, ms / portTICK_PERIOD_MS) - 1 ); if (ms != 0 && ms < portTICK_PERIOD_MS*8) { ms *= 1000; @@ -63,22 +71,28 @@ namespace lgfx , input_pulldown }; - void pinMode(std::int_fast16_t pin, pin_mode_t mode); - inline void lgfxPinMode(std::int_fast16_t pin, pin_mode_t mode) + void pinMode(int_fast16_t pin, pin_mode_t mode); + inline void lgfxPinMode(int_fast16_t pin, pin_mode_t mode) { pinMode(pin, mode); } - static inline volatile std::uint32_t* get_gpio_hi_reg(std::int_fast8_t pin) { return (pin & 32) ? &GPIO.out1_w1ts.val : &GPIO.out_w1ts; } -//static inline volatile std::uint32_t* get_gpio_hi_reg(std::int_fast8_t pin) { return (volatile uint32_t*)((pin & 32) ? 0x60004014 : 0x60004008) ; } // workaround Eratta - static inline volatile std::uint32_t* get_gpio_lo_reg(std::int_fast8_t pin) { return (pin & 32) ? &GPIO.out1_w1tc.val : &GPIO.out_w1tc; } -//static inline volatile std::uint32_t* get_gpio_lo_reg(std::int_fast8_t pin) { return (volatile uint32_t*)((pin & 32) ? 0x60004018 : 0x6000400C) ; } - static inline void gpio_hi(std::int_fast8_t pin) { if (pin >= 0) *get_gpio_hi_reg(pin) = 1 << (pin & 31); } // ESP_LOGI("LGFX", "gpio_hi: %d", pin); } - static inline void gpio_lo(std::int_fast8_t pin) { if (pin >= 0) *get_gpio_lo_reg(pin) = 1 << (pin & 31); } // ESP_LOGI("LGFX", "gpio_lo: %d", pin); } - static inline bool gpio_in(std::int_fast8_t pin) { return ((pin & 32) ? GPIO.in1.data : GPIO.in) & (1 << (pin & 31)); } +#if defined ( CONFIG_IDF_TARGET_ESP32C3 ) + static inline volatile uint32_t* get_gpio_hi_reg(int_fast8_t pin) { return &GPIO.out_w1ts.val; } + static inline volatile uint32_t* get_gpio_lo_reg(int_fast8_t pin) { return &GPIO.out_w1tc.val; } + static inline bool gpio_in(int_fast8_t pin) { return GPIO.in.val & (1 << (pin & 31)); } +#else + static inline volatile uint32_t* get_gpio_hi_reg(int_fast8_t pin) { return (pin & 32) ? &GPIO.out1_w1ts.val : &GPIO.out_w1ts; } +//static inline volatile uint32_t* get_gpio_hi_reg(int_fast8_t pin) { return (volatile uint32_t*)((pin & 32) ? 0x60004014 : 0x60004008) ; } // workaround Eratta + static inline volatile uint32_t* get_gpio_lo_reg(int_fast8_t pin) { return (pin & 32) ? &GPIO.out1_w1tc.val : &GPIO.out_w1tc; } +//static inline volatile uint32_t* get_gpio_lo_reg(int_fast8_t pin) { return (volatile uint32_t*)((pin & 32) ? 0x60004018 : 0x6000400C) ; } + static inline bool gpio_in(int_fast8_t pin) { return ((pin & 32) ? GPIO.in1.data : GPIO.in) & (1 << (pin & 31)); } +#endif + static inline void gpio_hi(int_fast8_t pin) { if (pin >= 0) *get_gpio_hi_reg(pin) = 1 << (pin & 31); } // ESP_LOGI("LGFX", "gpio_hi: %d", pin); } + static inline void gpio_lo(int_fast8_t pin) { if (pin >= 0) *get_gpio_lo_reg(pin) = 1 << (pin & 31); } // ESP_LOGI("LGFX", "gpio_lo: %d", pin); } - std::uint32_t getApbFrequency(void); - std::uint32_t FreqToClockDiv(std::uint32_t fapb, std::uint32_t hz); + uint32_t getApbFrequency(void); + uint32_t FreqToClockDiv(uint32_t fapb, uint32_t hz); //---------------------------------------------------------------------------- @@ -131,12 +145,12 @@ namespace lgfx _fp = &_file; return _file; } - int read(std::uint8_t *buf, std::uint32_t len) override { return _fp->read(buf, len); } - void skip(std::int32_t offset) override { seek(offset, SeekCur); } - bool seek(std::uint32_t offset) override { return seek(offset, SeekSet); } - bool seek(std::uint32_t offset, SeekMode mode) { return _fp->seek(offset, mode); } + int read(uint8_t *buf, uint32_t len) override { return _fp->read(buf, len); } + void skip(int32_t offset) override { seek(offset, SeekCur); } + bool seek(uint32_t offset) override { return seek(offset, SeekSet); } + bool seek(uint32_t offset, SeekMode mode) { return _fp->seek(offset, mode); } void close(void) override { if (_fp) _fp->close(); } - std::int32_t tell(void) override { return _fp->position(); } + int32_t tell(void) override { return _fp->position(); } }; #else // dummy @@ -152,12 +166,12 @@ namespace lgfx void setFS(T& fs) {} bool open(const char* path, const char* mode) { return false; } - int read(std::uint8_t *buf, std::uint32_t len) override { return false; } - void skip(std::int32_t offset) override { } - bool seek(std::uint32_t offset) override { return false; } - bool seek(std::uint32_t offset, int origin) { return false; } + int read(uint8_t *buf, uint32_t len) override { return false; } + void skip(int32_t offset) override { } + bool seek(uint32_t offset) override { return false; } + bool seek(uint32_t offset, int origin) { return false; } void close() override { } - std::int32_t tell(void) override { return 0; } + int32_t tell(void) override { return 0; } }; #endif @@ -171,12 +185,12 @@ namespace lgfx } FILE* _fp; bool open(const char* path) override { return (_fp = fopen(path, "r")); } - int read(std::uint8_t *buf, std::uint32_t len) override { return fread((char*)buf, 1, len, _fp); } - void skip(std::int32_t offset) override { seek(offset, SEEK_CUR); } - bool seek(std::uint32_t offset) override { return seek(offset, SEEK_SET); } - bool seek(std::uint32_t offset, int origin) { return fseek(_fp, offset, origin); } + int read(uint8_t *buf, uint32_t len) override { return fread((char*)buf, 1, len, _fp); } + void skip(int32_t offset) override { seek(offset, SEEK_CUR); } + bool seek(uint32_t offset) override { return seek(offset, SEEK_SET); } + bool seek(uint32_t offset, int origin) { return fseek(_fp, offset, origin); } void close() override { if (_fp) fclose(_fp); } - std::int32_t tell(void) override { return ftell(_fp); } + int32_t tell(void) override { return ftell(_fp); } }; #endif @@ -187,23 +201,23 @@ namespace lgfx struct StreamWrapper : public DataWrapper { - void set(Stream* src, std::uint32_t length = ~0) { _stream = src; _length = length; _index = 0; } + void set(Stream* src, uint32_t length = ~0) { _stream = src; _length = length; _index = 0; } - int read(std::uint8_t *buf, std::uint32_t len) override { - len = std::min(len, _stream->available()); + int read(uint8_t *buf, uint32_t len) override { + len = std::min(len, _stream->available()); if (len > _length - _index) { len = _length - _index; } _index += len; return _stream->readBytes((char*)buf, len); } - void skip(std::int32_t offset) override { if (0 < offset) { char dummy[offset]; _stream->readBytes(dummy, offset); _index += offset; } } - bool seek(std::uint32_t offset) override { if (offset < _index) { return false; } skip(offset - _index); return true; } + void skip(int32_t offset) override { if (0 < offset) { char dummy[offset]; _stream->readBytes(dummy, offset); _index += offset; } } + bool seek(uint32_t offset) override { if (offset < _index) { return false; } skip(offset - _index); return true; } void close() override { } - std::int32_t tell(void) override { return _index; } + int32_t tell(void) override { return _index; } protected: Stream* _stream; - std::uint32_t _index; - std::uint32_t _length = 0; + uint32_t _index; + uint32_t _length = 0; }; #endif diff --git a/src/lgfx/v1/platforms/esp32s2/Bus_Parallel16.cpp b/src/lgfx/v1/platforms/esp32s2/Bus_Parallel16.cpp new file mode 100644 index 0000000..43942ab --- /dev/null +++ b/src/lgfx/v1/platforms/esp32s2/Bus_Parallel16.cpp @@ -0,0 +1,690 @@ +/*----------------------------------------------------------------------------/ + Lovyan GFX - Graphics library for embedded devices. + +Original Source: + https://github.com/lovyan03/LovyanGFX/ + +Licence: + [FreeBSD](https://github.com/lovyan03/LovyanGFX/blob/master/license.txt) + +Author: + [lovyan03](https://twitter.com/lovyan03) + +Contributors: + [ciniml](https://github.com/ciniml) + [mongonta0716](https://github.com/mongonta0716) + [tobozo](https://github.com/tobozo) +/----------------------------------------------------------------------------*/ +#if defined (ESP_PLATFORM) +#include +#if defined (CONFIG_IDF_TARGET_ESP32S2) + +#include "Bus_Parallel16.hpp" +#include "../../misc/pixelcopy.hpp" + +#include +#include +#include + +namespace lgfx +{ + inline namespace v1 + { +//---------------------------------------------------------------------------- + +#ifndef I2S_CLKA_ENA +#define I2S_CLKA_ENA (BIT(22)) // clk_sel = 2 +#endif + + static constexpr size_t CACHE_THRESH = 128; + + // static constexpr uint32_t _conf_reg_default = I2S_TX_MSB_RIGHT | I2S_TX_RIGHT_FIRST | I2S_RX_RIGHT_FIRST | I2S_TX_DMA_EQUAL; + static constexpr uint32_t _conf_reg_default = I2S_TX_RIGHT_FIRST | I2S_RX_RIGHT_FIRST | I2S_TX_DMA_EQUAL; + static constexpr uint32_t _conf_reg_start = _conf_reg_default | I2S_TX_START; + static constexpr uint32_t _conf_reg_reset = _conf_reg_default | I2S_TX_RESET; + static constexpr uint32_t _sample_rate_conf_reg_bufferd = 32 << I2S_TX_BITS_MOD_S | 32 << I2S_RX_BITS_MOD_S | 1 << I2S_TX_BCK_DIV_NUM_S | 1 << I2S_RX_BCK_DIV_NUM_S; + static constexpr uint32_t _sample_rate_conf_reg_direct = 16 << I2S_TX_BITS_MOD_S | 16 << I2S_RX_BITS_MOD_S | 1 << I2S_TX_BCK_DIV_NUM_S | 1 << I2S_RX_BCK_DIV_NUM_S; + static constexpr uint32_t _fifo_conf_default = 1 << I2S_TX_FIFO_MOD | 1 << I2S_RX_FIFO_MOD | 32 << I2S_TX_DATA_NUM_S | 32 << I2S_RX_DATA_NUM_S | I2S_TX_FIFO_MOD_FORCE_EN; + static constexpr uint32_t _fifo_conf_dma = _fifo_conf_default | I2S_DSCR_EN; + + static __attribute__ ((always_inline)) inline volatile uint32_t* reg(uint32_t addr) { return (volatile uint32_t *)ETS_UNCACHED_ADDR(addr); } + + static i2s_dev_t* getDev(i2s_port_t port) + { +#if defined (CONFIG_IDF_TARGET_ESP32S2) + return &I2S0; +#else + return (port == 0) ? &I2S0 : &I2S1; +#endif + } + + void Bus_Parallel16::config(const config_t& cfg) + { + _cfg = cfg; + auto port = cfg.i2s_port; + _dev = getDev(port); + + _mask_reg_dc = (cfg.pin_rs < 0) ? 0 : (1ul << (cfg.pin_rs & 31)); + _gpio_reg_dc[0] = get_gpio_lo_reg(cfg.pin_rs); + _gpio_reg_dc[1] = get_gpio_hi_reg(cfg.pin_rs); + _last_freq_apb = 0; + } + + bool Bus_Parallel16::init(void) + { + _init_pin(); + + // gpio_pad_select_gpio(_cfg.pin_rd); + // gpio_pad_select_gpio(_cfg.pin_wr); + // gpio_pad_select_gpio(_cfg.pin_rs); + + gpio_hi(_cfg.pin_rd); + gpio_hi(_cfg.pin_wr); + gpio_hi(_cfg.pin_rs); + pinMode(_cfg.pin_rd, pin_mode_t::output); + pinMode(_cfg.pin_wr, pin_mode_t::output); + pinMode(_cfg.pin_rs, pin_mode_t::output); + + // gpio_set_direction((gpio_num_t)_cfg.pin_rd, GPIO_MODE_OUTPUT); + // gpio_set_direction((gpio_num_t)_cfg.pin_wr, GPIO_MODE_OUTPUT); + // gpio_set_direction((gpio_num_t)_cfg.pin_rs, GPIO_MODE_OUTPUT); + + auto idx_base = I2S0O_DATA_OUT8_IDX; + + gpio_matrix_out(_cfg.pin_rs , I2S0O_DATA_OUT0_IDX, 0, 0); + + _direct_dc = false; + + uint32_t dport_clk_en; + uint32_t dport_rst; + + if (_cfg.i2s_port == I2S_NUM_0) { + idx_base = I2S0O_WS_OUT_IDX; + dport_clk_en = DPORT_I2S0_CLK_EN; + dport_rst = DPORT_I2S0_RST; + } +#if !defined (CONFIG_IDF_TARGET_ESP32S2) + else + { + idx_base = I2S1O_WS_OUT_IDX; + dport_clk_en = DPORT_I2S1_CLK_EN; + dport_rst = DPORT_I2S1_RST; + } +#endif + gpio_matrix_out(_cfg.pin_wr, idx_base, 1, 0); // WR (Write-strobe in 8080 mode, Active-low) + + DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, dport_clk_en); + DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, dport_rst); + + auto i2s_dev = (i2s_dev_t*)_dev; + //Reset I2S subsystem + i2s_dev->conf.val = I2S_TX_RESET | I2S_RX_RESET | I2S_TX_FIFO_RESET | I2S_RX_FIFO_RESET; + i2s_dev->conf.val = _conf_reg_default; + + i2s_dev->int_ena.val = 0; + i2s_dev->timing.val = 0; + + //Reset DMA + i2s_dev->lc_conf.val = I2S_IN_RST | I2S_OUT_RST | I2S_AHBM_RST | I2S_AHBM_FIFO_RST; + i2s_dev->lc_conf.val = I2S_OUT_EOF_MODE | I2S_OUTDSCR_BURST_EN | I2S_OUT_DATA_BURST_EN; + + i2s_dev->in_link.val = 0; + i2s_dev->out_link.val = 0; + + i2s_dev->conf1.val = I2S_TX_PCM_BYPASS | I2S_TX_STOP_EN; + i2s_dev->conf2.val = I2S_LCD_EN; + i2s_dev->conf_chan.val = 1 << I2S_TX_CHAN_MOD_S | 1 << I2S_RX_CHAN_MOD_S; + + _alloc_dmadesc(1); + + return true; + } + + void Bus_Parallel16::_init_pin(bool read) + { + int8_t* pins = _cfg.pin_data; + if (read) + { + for (size_t i = 0; i < 16; ++i) + { + // gpio_pad_select_gpio(pins[i]); + gpio_set_direction((gpio_num_t)pins[i], GPIO_MODE_INPUT); + } + } + else + { + for (size_t i = 0; i < 8; ++i) + { + // gpio_set_direction((gpio_num_t)pins[i], GPIO_MODE_INPUT_OUTPUT); + gpio_pad_select_gpio(pins[i ]); + gpio_pad_select_gpio(pins[i+8]); + gpio_matrix_out(pins[i ], I2S0O_DATA_OUT8_IDX + i+8, 0, 0); + gpio_matrix_out(pins[i+8], I2S0O_DATA_OUT8_IDX + i , 0, 0); + } + } + } + + void Bus_Parallel16::release(void) + { + if (_dmadesc) + { + heap_caps_free(_dmadesc); + _dmadesc = nullptr; + _dmadesc_size = 0; + } + } + + void Bus_Parallel16::beginTransaction(void) + { + uint32_t freq_apb = getApbFrequency(); + if (_last_freq_apb != freq_apb) + { + _last_freq_apb = freq_apb; + // clock = 80MHz(apb_freq) / I2S_CLKM_DIV_NUM + // I2S_CLKM_DIV_NUM 2=40MHz / 3=27MHz / 4=20MHz / 5=16MHz / 8=10MHz / 10=8MHz + _div_num = std::min(255u, 1 + (freq_apb / (1 + _cfg.freq_write))); + + _clkdiv_write = I2S_CLKA_ENA + | I2S_CLK_EN + | 1 << I2S_CLKM_DIV_A_S + | 0 << I2S_CLKM_DIV_B_S + | _div_num << I2S_CLKM_DIV_NUM_S + ; + } + *reg(I2S_CLKM_CONF_REG(_cfg.i2s_port)) = _clkdiv_write; + + auto i2s_dev = (i2s_dev_t*)_dev; + i2s_dev->out_link.val = 0; + i2s_dev->sample_rate_conf.val = _sample_rate_conf_reg_bufferd; + i2s_dev->fifo_conf.val = _fifo_conf_dma; + + _cache_index = 0; + _cache_flip = _cache[0]; + + _has_align_data = false; + } + + void Bus_Parallel16::endTransaction(void) + { + if (_cache_index) + { + _flush(_cache_index, true); + _cache_index = 0; + ets_delay_us(1); + } + _wait(); + } + + void Bus_Parallel16::_wait(void) + { + auto i2s_dev = (i2s_dev_t*)_dev; + if (i2s_dev->out_link.val) + { +#if defined (CONFIG_IDF_TARGET_ESP32S2) + while (!(i2s_dev->lc_state0.out_empty)) {} +#else + while (!(i2s_dev->lc_state0 & 0x80000000)) {} // I2S_OUT_EMPTY +#endif + i2s_dev->out_link.val = 0; + } + while (!i2s_dev->state.tx_idle) {} + } + + void Bus_Parallel16::wait(void) + { + _wait(); + } + + bool Bus_Parallel16::busy(void) const + { + auto i2s_dev = (i2s_dev_t*)_dev; +#if defined (CONFIG_IDF_TARGET_ESP32S2) + return !i2s_dev->state.tx_idle + || (i2s_dev->out_link.val && !(i2s_dev->lc_state0.out_empty)); // I2S_OUT_EMPTY +#else + return !i2s_dev->state.tx_idle + || (i2s_dev->out_link.val && !(i2s_dev->lc_state0 & 0x80000000)); // I2S_OUT_EMPTY +#endif + } + + void Bus_Parallel16::flush(void) + { + if (_cache_index) + { + _flush(_cache_index, true); + _cache_index = 0; + } + } + + size_t Bus_Parallel16::_flush(size_t count, bool dc) + { + auto i2s_dev = (i2s_dev_t*)_dev; + if (i2s_dev->out_link.val) + { +#if defined (CONFIG_IDF_TARGET_ESP32S2) + while (!(i2s_dev->lc_state0.out_empty)) {} +#else + while (!(i2s_dev->lc_state0 & 0x80000000)) {} // I2S_OUT_EMPTY +#endif + } + _dmadesc[0].buf = (uint8_t *)_cache_flip; + *(uint32_t*)&_dmadesc[0] = count << 2 | count << 14 | 0xC0000000; + _dmadesc[0].empty = 0; + + while (!i2s_dev->state.tx_idle) {} + + i2s_dev->conf.val = _conf_reg_reset; + i2s_dev->sample_rate_conf.val = _sample_rate_conf_reg_bufferd; + i2s_dev->out_link.val = I2S_OUTLINK_START | ((uint32_t)&_dmadesc[0] & I2S_OUTLINK_ADDR); + + int wait = 40 - (_div_num << 3); + if (_direct_dc) + { + _direct_dc = false; + gpio_matrix_out(_cfg.pin_rs, I2S0O_DATA_OUT0_IDX, 0, 0); + wait -= 16; + } + if (wait > 0) + { /// OUTLINK_START~TX_STARTの時間が短すぎるとデータの先頭を送り損じる事があるのでnopウェイトを入れる + do { __asm__ __volatile__ ("nop"); } while (--wait); + } + i2s_dev->conf.val = _conf_reg_start; + + _cache_flip = (_cache_flip == _cache[0]) ? _cache[1] : _cache[0]; + return 0; + } + + bool Bus_Parallel16::writeCommand(uint32_t data, uint_fast8_t bit_length) + { + auto idx = _cache_index; + int bytes = bit_length >> 4; + auto c = _cache_flip; + + do + { + c[idx++] = data << 16; + data >>= 16; + } while (0 < --bytes); + if (idx >= CACHE_THRESH) + { + _flush(idx); + idx = 0; + } + _cache_index = idx; + return true; + } + + void Bus_Parallel16::writeData(uint32_t data, uint_fast8_t bit_length) + { + auto idx = _cache_index; + auto c = _cache_flip; + auto bytes = bit_length >> 3; + + if (_has_align_data) + { + _has_align_data = false; + c[idx++] = ((data << 8 | _align_data) << 16) | 0x100; + --bytes; + data >>= 8; + } + + while (1 < bytes) + { + bytes -= 2; + c[idx++] = (data << 16) | 0x100; + data >>= 16; + } + + if (idx >= CACHE_THRESH) + { + _flush(idx); + idx = 0; + } + _cache_index = idx; + if (bytes == 1) + { + _has_align_data = true; + _align_data = data; + } + } + + void Bus_Parallel16::writeDataRepeat(uint32_t color_raw, uint_fast8_t bit_length, uint32_t length) + { + size_t bytes = bit_length >> 3; + auto idx = _cache_index; + auto c = _cache_flip; + + if (bytes == 2) + { + int step = (idx == 0) ? 1 : 0; + color_raw = color_raw << 16 | 0x100; + while (length) + { + --length; + *(uint32_t*)(&c[idx]) = color_raw; + if (++idx >= CACHE_THRESH) + { + _flush(idx); + if (++step == 2 && length >= CACHE_THRESH) + { + memcpy(_cache_flip, c, CACHE_THRESH * sizeof(uint32_t)); + do + { + _flush(CACHE_THRESH); + length -= CACHE_THRESH; + } while (length >= CACHE_THRESH); + idx = length; + break; + } + c = _cache_flip; + idx = 0; + } + } + } + else // if (bytes == 3) + { + // size_t step = 0; + uint32_t raw[3] = + { color_raw << 16 | 0x100 + , color_raw | color_raw << 24 | 0x100 + , color_raw << 8 | 0x100 + }; + if (_has_align_data) + { + _has_align_data = false; + --length; + c[idx++] = ((color_raw << 8 | _align_data) << 16) | 0x100; + c[idx++] = raw[2]; + if (idx >= CACHE_THRESH) + { + _flush(idx); + idx = 0; + c = _cache_flip; + // step = 1; + } + } + while (1 < length) + { + length -= 2; + c[idx ] = raw[0]; + c[idx+1] = raw[1]; + c[idx+2] = raw[2]; + idx += 3; + if (idx >= CACHE_THRESH) + { + _flush(idx); + idx = 0; +/* + if (++step == 2) + { + if (length > ((CACHE_THRESH / 3) * 2)) + { + memcpy(_cache_flip, c, CACHE_THRESH * sizeof(uint32_t)); + do + { + _flush(((CACHE_THRESH / 3) * 3)); + length -= ((CACHE_THRESH / 3) * 2); + } while (length >= ((CACHE_THRESH / 3) * 2)); + idx = (length >> 1) * 3; + length = length & 1; + break; + } + } +//*/ + c = _cache_flip; + } + } + if (length == 1) + { + _has_align_data = true; + c[idx++] = raw[0]; + _align_data = raw[1] >> 16; + } + } + _cache_index = idx; + } + + void Bus_Parallel16::writePixels(pixelcopy_t* param, uint32_t length) + { + if (_cache_index) + { + _flush(_cache_index); + _cache_index = 0; + } + const uint32_t bytes = param->dst_bits >> 3; + auto fp_copy = param->fp_copy; + const uint32_t limit = CACHE_SIZE / bytes; + uint8_t len = length % limit; + if (len) + { + fp_copy(_cache_flip, 0, len, param); + writeBytes((uint8_t*)_cache_flip, len * bytes, true, true); + _cache_flip = (_cache_flip == _cache[0]) ? _cache[1] : _cache[0]; + if (0 == (length -= len)) return; + } + do + { + fp_copy(_cache_flip, 0, limit, param); + writeBytes((uint8_t*)_cache_flip, limit * bytes, true, true); + _cache_flip = (_cache_flip == _cache[0]) ? _cache[1] : _cache[0]; + } while (length -= limit); + } + + void Bus_Parallel16::writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) + { + if (_cache_index) + { + _flush(_cache_index); + _cache_index = 0; + } + auto i2s_dev = (i2s_dev_t*)_dev; + do + { + dc_control(dc); + i2s_dev->sample_rate_conf.val = _sample_rate_conf_reg_direct; + i2s_dev->conf.val = _conf_reg_reset; + if (use_dma) + { + _setup_dma_desc_links(data, length); + length = 0; + } + else + { + size_t len = ((length - 1) % CACHE_SIZE) + 1; + length -= len; + memcpy(_cache_flip, data, len); + data += len; + _setup_dma_desc_links((const uint8_t*)_cache_flip, len); + _cache_flip = (_cache_flip == _cache[0]) ? _cache[1] : _cache[0]; + } + i2s_dev->out_link.val = I2S_OUTLINK_START | ((uint32_t)_dmadesc & I2S_OUTLINK_ADDR); + int wait = 40 - (_div_num << 3); + if (!_direct_dc) + { + _direct_dc = true; + gpio_matrix_out(_cfg.pin_rs, 0x100, 0, 0); + wait -= 16; + } + if (wait > 0) + { /// OUTLINK_START~TX_STARTの時間が短すぎるとデータの先頭を送り損じる事があるのでnopウェイトを入れる + do { __asm__ __volatile__ ("nop"); } while (--wait); + } + + i2s_dev->conf.val = _conf_reg_start; + } while (length); + } + + void Bus_Parallel16::beginRead(void) + { + if (_cache_index) { _cache_index = _flush(_cache_index, true); } + + dc_control(true); + if (!_direct_dc) + { + _direct_dc = true; + gpio_matrix_out(_cfg.pin_rs, 0x100, 0, 0); + } + gpio_lo(_cfg.pin_rd); + + _init_pin(true); + } + + void Bus_Parallel16::endRead(void) + { + gpio_hi(_cfg.pin_rd); + + _init_pin(); + } + + void Bus_Parallel16::_read_bytes(uint8_t* dst, uint32_t length) + { + uint8_t in[8]; + + uint32_t mh = ((((((((((((((( + (_cfg.pin_d8 & 7)) << 3) + + (_cfg.pin_d9 & 7)) << 3) + + (_cfg.pin_d10 & 7)) << 3) + + (_cfg.pin_d11 & 7)) << 3) + + (_cfg.pin_d12 & 7)) << 3) + + (_cfg.pin_d13 & 7)) << 3) + + (_cfg.pin_d14 & 7)) << 3) + + (_cfg.pin_d15 & 7)) + ; + + uint32_t ih = ((((((((((((((( + (_cfg.pin_d8 >> 3)) << 3) + + (_cfg.pin_d9 >> 3)) << 3) + + (_cfg.pin_d10 >> 3)) << 3) + + (_cfg.pin_d11 >> 3)) << 3) + + (_cfg.pin_d12 >> 3)) << 3) + + (_cfg.pin_d13 >> 3)) << 3) + + (_cfg.pin_d14 >> 3)) << 3) + + (_cfg.pin_d15 >> 3)) + ; + + uint32_t ml = ((((((((((((((( + (_cfg.pin_d0 & 7)) << 3) + + (_cfg.pin_d1 & 7)) << 3) + + (_cfg.pin_d2 & 7)) << 3) + + (_cfg.pin_d3 & 7)) << 3) + + (_cfg.pin_d4 & 7)) << 3) + + (_cfg.pin_d5 & 7)) << 3) + + (_cfg.pin_d6 & 7)) << 3) + + (_cfg.pin_d7 & 7)) + ; + + uint32_t il = ((((((((((((((( + (_cfg.pin_d0 >> 3)) << 3) + + (_cfg.pin_d1 >> 3)) << 3) + + (_cfg.pin_d2 >> 3)) << 3) + + (_cfg.pin_d3 >> 3)) << 3) + + (_cfg.pin_d4 >> 3)) << 3) + + (_cfg.pin_d5 >> 3)) << 3) + + (_cfg.pin_d6 >> 3)) << 3) + + (_cfg.pin_d7 >> 3)) + ; + + auto reg_rd_h = get_gpio_hi_reg(_cfg.pin_rd); + auto reg_rd_l = get_gpio_lo_reg(_cfg.pin_rd); + uint32_t mask_rd = 1ul << (_cfg.pin_rd & 31); + uint32_t val; + do + { + ((uint32_t*)in)[0] = GPIO.in; + ((uint32_t*)in)[1] = GPIO.in1.val; + *reg_rd_h = mask_rd; + val = (1 & (in[(ih >> 0) & 7] >> ((mh >> 0) & 7))); + val = (val << 1) + (1 & (in[(ih >> 3) & 7] >> ((mh >> 3) & 7))); + val = (val << 1) + (1 & (in[(ih >> 6) & 7] >> ((mh >> 6) & 7))); + val = (val << 1) + (1 & (in[(ih >> 9) & 7] >> ((mh >> 9) & 7))); + val = (val << 1) + (1 & (in[(ih >> 12) & 7] >> ((mh >> 12) & 7))); + val = (val << 1) + (1 & (in[(ih >> 15) & 7] >> ((mh >> 15) & 7))); + val = (val << 1) + (1 & (in[(ih >> 18) & 7] >> ((mh >> 18) & 7))); + val = (val << 1) + (1 & (in[(ih >> 21) & 7] >> ((mh >> 21) & 7))); + *dst++ = val; + + *reg_rd_l = mask_rd; + if (0 == --length) break; + + val = (1 & (in[(il >> 0) & 7] >> ((ml >> 0) & 7))); + val = (val << 1) + (1 & (in[(il >> 3) & 7] >> ((ml >> 3) & 7))); + val = (val << 1) + (1 & (in[(il >> 6) & 7] >> ((ml >> 6) & 7))); + val = (val << 1) + (1 & (in[(il >> 9) & 7] >> ((ml >> 9) & 7))); + val = (val << 1) + (1 & (in[(il >> 12) & 7] >> ((ml >> 12) & 7))); + val = (val << 1) + (1 & (in[(il >> 15) & 7] >> ((ml >> 15) & 7))); + val = (val << 1) + (1 & (in[(il >> 18) & 7] >> ((ml >> 18) & 7))); + val = (val << 1) + (1 & (in[(il >> 21) & 7] >> ((ml >> 21) & 7))); + *dst++ = val; + } while (--length); + } + + uint32_t Bus_Parallel16::readData(uint_fast8_t bit_length) + { + union { + uint32_t res; + uint8_t raw[4]; + }; + _read_bytes(raw, (bit_length + 7) >> 3); + return res; + } + + bool Bus_Parallel16::readBytes(uint8_t* dst, uint32_t length, bool use_dma) + { + _read_bytes(dst, length); + return true; + } + + void Bus_Parallel16::readPixels(void* dst, pixelcopy_t* param, uint32_t length) + { + uint32_t _regbuf[8]; + const auto bytes = param->src_bits >> 3; + uint32_t limit = (bytes == 2) ? 16 : 10; + param->src_data = _regbuf; + int32_t dstindex = 0; + do { + uint32_t len2 = (limit > length) ? length : limit; + length -= len2; + + _read_bytes((uint8_t*)_regbuf, len2 * bytes); + param->src_x = 0; + dstindex = param->fp_copy(dst, dstindex, dstindex + len2, param); + } while (length); + } + + void Bus_Parallel16::_alloc_dmadesc(size_t len) + { + if (_dmadesc) heap_caps_free(_dmadesc); + _dmadesc_size = len; + _dmadesc = (lldesc_t*)heap_caps_malloc(sizeof(lldesc_t) * len, MALLOC_CAP_DMA); + } + + void Bus_Parallel16::_setup_dma_desc_links(const uint8_t *data, int32_t len) + { + static constexpr size_t MAX_DMA_LEN = (4096-4); + + if (_dmadesc_size * MAX_DMA_LEN < len) + { + _alloc_dmadesc(len / MAX_DMA_LEN + 1); + } + lldesc_t *dmadesc = _dmadesc; + + while (len > MAX_DMA_LEN) + { + len -= MAX_DMA_LEN; + dmadesc->buf = (uint8_t *)data; + data += MAX_DMA_LEN; + *(uint32_t*)dmadesc = MAX_DMA_LEN | MAX_DMA_LEN << 12 | 0x80000000; + dmadesc->qe.stqe_next = dmadesc + 1; + dmadesc++; + } + *(uint32_t*)dmadesc = ((len + 3) & ( ~3 )) | len << 12 | 0xC0000000; + dmadesc->buf = (uint8_t *)data; + dmadesc->qe.stqe_next = nullptr; + } + +//---------------------------------------------------------------------------- + } +} + +#endif +#endif diff --git a/src/lgfx/v1/platforms/esp32s2/Bus_Parallel16.hpp b/src/lgfx/v1/platforms/esp32s2/Bus_Parallel16.hpp new file mode 100644 index 0000000..8d01fb7 --- /dev/null +++ b/src/lgfx/v1/platforms/esp32s2/Bus_Parallel16.hpp @@ -0,0 +1,169 @@ +/*----------------------------------------------------------------------------/ + Lovyan GFX - Graphics library for embedded devices. + +Original Source: + https://github.com/lovyan03/LovyanGFX/ + +Licence: + [FreeBSD](https://github.com/lovyan03/LovyanGFX/blob/master/license.txt) + +Author: + [lovyan03](https://twitter.com/lovyan03) + +Contributors: + [ciniml](https://github.com/ciniml) + [mongonta0716](https://github.com/mongonta0716) + [tobozo](https://github.com/tobozo) +/----------------------------------------------------------------------------*/ +#pragma once + +#include +#include + +#if __has_include() + #include +#else + #include +#endif + +#if __has_include() + #include +#endif + +#include + +#include "../../Bus.hpp" +#include "../common.hpp" + +namespace lgfx +{ + inline namespace v1 + { +//---------------------------------------------------------------------------- + + class Bus_Parallel16 : public IBus + { + public: + struct config_t + { + i2s_port_t i2s_port = I2S_NUM_0; + + // max 40MHz , 27MHz , 20MHz , 16MHz , 13.3MHz , 11.43MHz , 10MHz , 8.9MHz and more ... + uint32_t freq_write = 16000000; + int8_t pin_wr = -1; + int8_t pin_rd = -1; + int8_t pin_rs = -1; // D/C + union + { + int8_t pin_data[16]; + struct + { + int8_t pin_d0; + int8_t pin_d1; + int8_t pin_d2; + int8_t pin_d3; + int8_t pin_d4; + int8_t pin_d5; + int8_t pin_d6; + int8_t pin_d7; + int8_t pin_d8; + int8_t pin_d9; + int8_t pin_d10; + int8_t pin_d11; + int8_t pin_d12; + int8_t pin_d13; + int8_t pin_d14; + int8_t pin_d15; + }; + }; + }; + + + const config_t& config(void) const { return _cfg; } + void config(const config_t& config); + + bus_type_t busType(void) const override { return bus_type_t::bus_parallel16; } + + bool init(void) override; + void release(void) override; + + void beginTransaction(void) override; + void endTransaction(void) override; + void wait(void) override; + bool busy(void) const override; + + void flush(void) override; + bool writeCommand(uint32_t data, uint_fast8_t bit_length) override; + void writeData(uint32_t data, uint_fast8_t bit_length) override; + void writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t count) override; + void writePixels(pixelcopy_t* param, uint32_t length) override; + void writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) override; + + void initDMA(void) override {} + void addDMAQueue(const uint8_t* data, uint32_t length) override { writeBytes(data, length, true, true); } + void execDMAQueue(void) override { flush(); }; + uint8_t* getDMABuffer(uint32_t length) override { return _flip_buffer.getBuffer(length); } + + void beginRead(void) override; + void endRead(void) override; + uint32_t readData(uint_fast8_t bit_length) override; + bool readBytes(uint8_t* dst, uint32_t length, bool use_dma) override; + void readPixels(void* dst, pixelcopy_t* param, uint32_t length) override; + + private: + + void dc_control(bool flg) + { + auto reg = _gpio_reg_dc[flg]; + auto mask = _mask_reg_dc; + auto i2s_dev = (i2s_dev_t*)_dev; + if (i2s_dev->out_link.val) + { +#if defined (CONFIG_IDF_TARGET_ESP32S2) + while (!(i2s_dev->lc_state0.out_empty)) {} +#else + while (!(i2s_dev->lc_state0 & 0x80000000)) {} // I2S_OUT_EMPTY +#endif + i2s_dev->out_link.val = 0; + } + while (!i2s_dev->state.tx_idle) {} + *reg = mask; + } + + static constexpr size_t CACHE_SIZE = 132; + + config_t _cfg; + SimpleBuffer _flip_buffer; + size_t _div_num; + size_t _cache_index; + uint32_t _cache[2][CACHE_SIZE]; + uint32_t* _cache_flip; + + bool _has_align_data; + uint8_t _align_data; + + uint32_t _pin_mask_h, _pin_mask_l, _pin_index_h, _pin_index_l; + + void _wait(void); + void _init_pin(bool read = false); + size_t _flush(size_t idx, bool dc = true); + void _read_bytes(uint8_t* dst, uint32_t length); + + void _alloc_dmadesc(size_t len); + void _setup_dma_desc_links(const uint8_t *data, int32_t len); + + volatile uint32_t* _gpio_reg_dc[2] = { nullptr, nullptr }; + uint32_t _mask_reg_dc = 0; + bool _direct_dc; + + uint32_t _last_freq_apb; + uint32_t _clkdiv_write; + volatile void *_dev; + + lldesc_t* _dmadesc = nullptr; + uint32_t _dmadesc_size = 0; + }; + +//---------------------------------------------------------------------------- + } +} diff --git a/src/lgfx/v1/platforms/esp32s2/Bus_Parallel8.cpp b/src/lgfx/v1/platforms/esp32s2/Bus_Parallel8.cpp new file mode 100644 index 0000000..d1d09b4 --- /dev/null +++ b/src/lgfx/v1/platforms/esp32s2/Bus_Parallel8.cpp @@ -0,0 +1,598 @@ +/*----------------------------------------------------------------------------/ + Lovyan GFX - Graphics library for embedded devices. + +Original Source: + https://github.com/lovyan03/LovyanGFX/ + +Licence: + [FreeBSD](https://github.com/lovyan03/LovyanGFX/blob/master/license.txt) + +Author: + [lovyan03](https://twitter.com/lovyan03) + +Contributors: + [ciniml](https://github.com/ciniml) + [mongonta0716](https://github.com/mongonta0716) + [tobozo](https://github.com/tobozo) +/----------------------------------------------------------------------------*/ +#if defined (ESP_PLATFORM) +#include +#if defined (CONFIG_IDF_TARGET_ESP32S2) + +#include "Bus_Parallel8.hpp" +#include "../../misc/pixelcopy.hpp" + +#include +#include +#include + +namespace lgfx +{ + inline namespace v1 + { +//---------------------------------------------------------------------------- + +#ifndef I2S_CLKA_ENA +#define I2S_CLKA_ENA (BIT(22)) // clk_sel = 2 +#endif + + static constexpr size_t CACHE_THRESH = 128; + + // static constexpr uint32_t _conf_reg_default = I2S_TX_MSB_RIGHT | I2S_TX_RIGHT_FIRST | I2S_RX_RIGHT_FIRST | I2S_TX_DMA_EQUAL; + static constexpr uint32_t _conf_reg_default = I2S_TX_RIGHT_FIRST | I2S_RX_RIGHT_FIRST | I2S_TX_DMA_EQUAL; + static constexpr uint32_t _conf_reg_start = _conf_reg_default | I2S_TX_START; + static constexpr uint32_t _conf_reg_reset = _conf_reg_default | I2S_TX_RESET; + static constexpr uint32_t _sample_rate_conf_reg_16bit = 16 << I2S_TX_BITS_MOD_S | 16 << I2S_RX_BITS_MOD_S | 1 << I2S_TX_BCK_DIV_NUM_S | 1 << I2S_RX_BCK_DIV_NUM_S; + static constexpr uint32_t _sample_rate_conf_reg_8bit = 8 << I2S_TX_BITS_MOD_S | 8 << I2S_RX_BITS_MOD_S | 1 << I2S_TX_BCK_DIV_NUM_S | 1 << I2S_RX_BCK_DIV_NUM_S; + static constexpr uint32_t _fifo_conf_default = 1 << I2S_TX_FIFO_MOD | 1 << I2S_RX_FIFO_MOD | 32 << I2S_TX_DATA_NUM_S | 32 << I2S_RX_DATA_NUM_S | I2S_TX_FIFO_MOD_FORCE_EN; + static constexpr uint32_t _fifo_conf_dma = _fifo_conf_default | I2S_DSCR_EN; + + static __attribute__ ((always_inline)) inline volatile uint32_t* reg(uint32_t addr) { return (volatile uint32_t *)ETS_UNCACHED_ADDR(addr); } + + static i2s_dev_t* getDev(i2s_port_t port) + { +#if defined (CONFIG_IDF_TARGET_ESP32S2) + return &I2S0; +#else + return (port == 0) ? &I2S0 : &I2S1; +#endif + } + + void Bus_Parallel8::config(const config_t& cfg) + { + _cfg = cfg; + auto port = cfg.i2s_port; + _dev = getDev(port); + + _mask_reg_dc = (cfg.pin_rs < 0) ? 0 : (1ul << (cfg.pin_rs & 31)); + _gpio_reg_dc[0] = get_gpio_lo_reg(cfg.pin_rs); + _gpio_reg_dc[1] = get_gpio_hi_reg(cfg.pin_rs); + _last_freq_apb = 0; + } + + bool Bus_Parallel8::init(void) + { + _init_pin(); + + gpio_pad_select_gpio(_cfg.pin_rd); + gpio_pad_select_gpio(_cfg.pin_wr); + gpio_pad_select_gpio(_cfg.pin_rs); + + gpio_hi(_cfg.pin_rd); + gpio_hi(_cfg.pin_wr); + gpio_hi(_cfg.pin_rs); + + gpio_set_direction((gpio_num_t)_cfg.pin_rd, GPIO_MODE_OUTPUT); + gpio_set_direction((gpio_num_t)_cfg.pin_wr, GPIO_MODE_OUTPUT); + gpio_set_direction((gpio_num_t)_cfg.pin_rs, GPIO_MODE_OUTPUT); + + auto idx_base = I2S0O_DATA_OUT15_IDX; + + gpio_matrix_out(_cfg.pin_rs, idx_base , 0, 0); + + _direct_dc = false; + + uint32_t dport_clk_en; + uint32_t dport_rst; + + if (_cfg.i2s_port == I2S_NUM_0) { + idx_base = I2S0O_WS_OUT_IDX; + dport_clk_en = DPORT_I2S0_CLK_EN; + dport_rst = DPORT_I2S0_RST; + } +#if !defined (CONFIG_IDF_TARGET_ESP32S2) + else + { + idx_base = I2S1O_WS_OUT_IDX; + dport_clk_en = DPORT_I2S1_CLK_EN; + dport_rst = DPORT_I2S1_RST; + } +#endif + gpio_matrix_out(_cfg.pin_wr, idx_base, 1, 0); // WR (Write-strobe in 8080 mode, Active-low) + + DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, dport_clk_en); + DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, dport_rst); + + auto i2s_dev = (i2s_dev_t*)_dev; + //Reset I2S subsystem + i2s_dev->conf.val = I2S_TX_RESET | I2S_RX_RESET | I2S_TX_FIFO_RESET | I2S_RX_FIFO_RESET; + i2s_dev->conf.val = _conf_reg_default; + + i2s_dev->int_ena.val = 0; + i2s_dev->timing.val = 0; + + //Reset DMA + i2s_dev->lc_conf.val = I2S_IN_RST | I2S_OUT_RST | I2S_AHBM_RST | I2S_AHBM_FIFO_RST; + i2s_dev->lc_conf.val = I2S_OUT_EOF_MODE | I2S_OUTDSCR_BURST_EN | I2S_OUT_DATA_BURST_EN; + + i2s_dev->in_link.val = 0; + i2s_dev->out_link.val = 0; + + i2s_dev->conf1.val = I2S_TX_PCM_BYPASS | I2S_TX_STOP_EN; + i2s_dev->conf2.val = I2S_LCD_EN; + i2s_dev->conf_chan.val = 1 << I2S_TX_CHAN_MOD_S | 1 << I2S_RX_CHAN_MOD_S; + + _alloc_dmadesc(1); + + return true; + } + + void Bus_Parallel8::_init_pin(bool read) + { + int8_t* pins = _cfg.pin_data; + if (read) + { + for (size_t i = 0; i < 8; ++i) + { + // gpio_pad_select_gpio(pins[i]); + gpio_set_direction((gpio_num_t)pins[i], GPIO_MODE_INPUT); + } + } + else + { + auto idx_base = I2S0O_DATA_OUT16_IDX; + for (size_t i = 0; i < 8; ++i) + { + // gpio_set_direction((gpio_num_t)pins[i], GPIO_MODE_INPUT_OUTPUT); + gpio_pad_select_gpio(pins[i]); + gpio_matrix_out(pins[i], idx_base + i, 0, 0); + } + } + } + + void Bus_Parallel8::release(void) + { + if (_dmadesc) + { + heap_caps_free(_dmadesc); + _dmadesc = nullptr; + _dmadesc_size = 0; + } + } + + void Bus_Parallel8::beginTransaction(void) + { + uint32_t freq_apb = getApbFrequency(); + if (_last_freq_apb != freq_apb) + { + _last_freq_apb = freq_apb; + // clock = 80MHz(apb_freq) / I2S_CLKM_DIV_NUM + // I2S_CLKM_DIV_NUM 2=40MHz / 3=27MHz / 4=20MHz / 5=16MHz / 8=10MHz / 10=8MHz + _div_num = std::min(255u, 1 + (freq_apb / (1 + _cfg.freq_write))); + + _clkdiv_write = I2S_CLKA_ENA + | I2S_CLK_EN + | 1 << I2S_CLKM_DIV_A_S + | 0 << I2S_CLKM_DIV_B_S + | _div_num << I2S_CLKM_DIV_NUM_S + ; + } + *reg(I2S_CLKM_CONF_REG(_cfg.i2s_port)) = _clkdiv_write; + + auto i2s_dev = (i2s_dev_t*)_dev; + i2s_dev->out_link.val = 0; + i2s_dev->sample_rate_conf.val = _sample_rate_conf_reg_16bit; + i2s_dev->fifo_conf.val = _fifo_conf_dma; + + _cache_index = 0; + _cache_flip = _cache[0]; + } + + void Bus_Parallel8::endTransaction(void) + { + if (_cache_index) + { + _flush(_cache_index, true); + _cache_index = 0; + ets_delay_us(1); + } + _wait(); + } + + void Bus_Parallel8::_wait(void) + { + //i2s_dev->int_clr.val = I2S_TX_REMPTY_INT_CLR; + auto i2s_dev = (i2s_dev_t*)_dev; + if (i2s_dev->out_link.val) + { +#if defined (CONFIG_IDF_TARGET_ESP32S2) + while (!(i2s_dev->lc_state0.out_empty)) {} +#else + while (!(i2s_dev->lc_state0 & 0x80000000)) {} // I2S_OUT_EMPTY +#endif + i2s_dev->out_link.val = 0; + } + while (!i2s_dev->state.tx_idle) {} + } + + void Bus_Parallel8::wait(void) + { + _wait(); + } + + bool Bus_Parallel8::busy(void) const + { + auto i2s_dev = (i2s_dev_t*)_dev; +#if defined (CONFIG_IDF_TARGET_ESP32S2) + return !i2s_dev->state.tx_idle + || (i2s_dev->out_link.val && !(i2s_dev->lc_state0.out_empty)); // I2S_OUT_EMPTY +#else + return !i2s_dev->state.tx_idle + || (i2s_dev->out_link.val && !(i2s_dev->lc_state0 & 0x80000000)); // I2S_OUT_EMPTY +#endif + } + + void Bus_Parallel8::flush(void) + { + if (_cache_index) + { + _flush(_cache_index, true); + _cache_index = 0; + } + } + + size_t Bus_Parallel8::_flush(size_t count, bool dc) + { + auto i2s_dev = (i2s_dev_t*)_dev; + if (i2s_dev->out_link.val) + { +#if defined (CONFIG_IDF_TARGET_ESP32S2) + while (!(i2s_dev->lc_state0.out_empty)) {} +#else + while (!(i2s_dev->lc_state0 & 0x80000000)) {} // I2S_OUT_EMPTY +#endif + } + // _setup_dma_desc_links((const uint8_t*)_cache_flip, count << 1); + _dmadesc[0].buf = (uint8_t *)_cache_flip; + *(uint32_t*)&_dmadesc[0] = count << 1 | count << 13 | 0xC0000000; + //*(uint32_t*)&_dmadesc[0] = ((count+1) &~1) << 1 | count << 13 | 0xC0000000; + _dmadesc[0].empty = 0; + + while (!i2s_dev->state.tx_idle) {} + + i2s_dev->conf.val = _conf_reg_reset; + i2s_dev->sample_rate_conf.val = _sample_rate_conf_reg_16bit; + i2s_dev->out_link.val = I2S_OUTLINK_START | ((uint32_t)&_dmadesc[0] & I2S_OUTLINK_ADDR); + + if (_direct_dc) + { + _direct_dc = false; + auto idx_base = I2S0O_DATA_OUT15_IDX; + gpio_matrix_out(_cfg.pin_rs, idx_base, 0, 0); + } + else if (_div_num < 4) + { /// OUTLINK_START~TX_STARTの時間が短すぎるとデータの先頭を送り損じる事があるのでnopウェイトを入れる + size_t wait = (8 - _div_num) << 2; + do { __asm__ __volatile__ ("nop"); } while (--wait); + } + i2s_dev->conf.val = _conf_reg_start; + + _cache_flip = (_cache_flip == _cache[0]) ? _cache[1] : _cache[0]; + return 0; + } + + bool Bus_Parallel8::writeCommand(uint32_t data, uint_fast8_t bit_length) + { + auto idx = _cache_index; + auto bytes = bit_length >> 3; + auto c = _cache_flip; + do + { + c[idx++] = (data & 0xFF) << 8; + data >>= 8; + } while (--bytes); + if (idx >= CACHE_THRESH) + { + _flush(idx); + idx = 0; + } + _cache_index = idx; + return true; + } + + void Bus_Parallel8::writeData(uint32_t data, uint_fast8_t bit_length) + { + auto idx = _cache_index; + auto bytes = bit_length >> 3; + auto c = _cache_flip; + do + { + c[idx++] = (data << 8) | 0xFF; + data >>= 8; + } while (--bytes); + if (idx >= CACHE_THRESH) + { + _flush(idx); + idx = 0; + } + _cache_index = idx; + } + + void Bus_Parallel8::writeDataRepeat(uint32_t color_raw, uint_fast8_t bit_length, uint32_t length) + { + size_t bytes = bit_length >> 3; + auto idx = _cache_index; + auto c = _cache_flip; + + if (bytes == 2) + { + uint32_t color_r1 = (uint8_t)(color_raw) << 8 | color_raw << 16 | 0xFF00FF; + while (length) + { + --length; + *(uint32_t*)(&c[idx]) = color_r1; + idx += 2; + if (idx >= CACHE_THRESH) + { + idx = _flush(idx); + c = _cache_flip; + } + } + } + else // if (bytes == 3) + { + uint32_t raw[3] = + { (uint8_t)(color_raw) << 8 | color_raw << 16 | 0xFF00FF + , color_raw >> 8 | color_raw << 24 | 0xFF00FF + , color_raw | (color_raw>>16)<<24 | 0xFF00FF + }; + if (length & 1) + { + --length; + *(uint32_t*)(&c[idx ]) = raw[0]; + *(uint32_t*)(&c[idx+2]) = raw[1]; + idx += 3; + } + if (idx >= CACHE_THRESH - 4) + { + idx = _flush(idx); + c = _cache_flip; + } + while (length) + { + length -= 2; + *(uint32_t*)(&c[idx ]) = raw[0]; + *(uint32_t*)(&c[idx+2]) = raw[1]; + *(uint32_t*)(&c[idx+4]) = raw[2]; + idx += 6; + if (idx >= CACHE_THRESH - 4) + { + idx = _flush(idx); + c = _cache_flip; + } + } + } + _cache_index = idx; + } + + void Bus_Parallel8::writePixels(pixelcopy_t* param, uint32_t length) + { + if (_cache_index) + { + _flush(_cache_index); + _cache_index = 0; + } + const uint32_t bytes = param->dst_bits >> 3; + auto fp_copy = param->fp_copy; + const uint32_t limit = CACHE_SIZE / bytes; + uint8_t len = length % limit; + if (len) + { + fp_copy(_cache_flip, 0, len, param); + writeBytes((uint8_t*)_cache_flip, len * bytes, true, true); + _cache_flip = (_cache_flip == _cache[0]) ? _cache[1] : _cache[0]; + if (0 == (length -= len)) return; + } + do + { + fp_copy(_cache_flip, 0, limit, param); + writeBytes((uint8_t*)_cache_flip, limit * bytes, true, true); + _cache_flip = (_cache_flip == _cache[0]) ? _cache[1] : _cache[0]; + } while (length -= limit); + } + + void Bus_Parallel8::writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) + { + if (_cache_index) + { + _flush(_cache_index); + _cache_index = 0; + } + auto i2s_dev = (i2s_dev_t*)_dev; + do + { + dc_control(dc); + i2s_dev->sample_rate_conf.val = _sample_rate_conf_reg_8bit; + i2s_dev->conf.val = _conf_reg_reset; + if (use_dma) + { + _setup_dma_desc_links(data, length); + length = 0; + } + else + { + size_t len = ((length - 1) % CACHE_SIZE) + 1; + length -= len; + memcpy(_cache_flip, data, len); + data += len; + _setup_dma_desc_links((const uint8_t*)_cache_flip, len); + _cache_flip = (_cache_flip == _cache[0]) ? _cache[1] : _cache[0]; + } + i2s_dev->out_link.val = I2S_OUTLINK_START | ((uint32_t)_dmadesc & I2S_OUTLINK_ADDR); + if (!_direct_dc) + { + _direct_dc = true; + gpio_matrix_out(_cfg.pin_rs, 0x100, 0, 0); + } + else + { + if (_div_num <= 4) + { + size_t wait = (8 - _div_num) << 2; + do { __asm__ __volatile__ ("nop"); } while (--wait); + } + } + i2s_dev->conf.val = _conf_reg_start; + } while (length); + } + + void Bus_Parallel8::beginRead(void) + { + if (_cache_index) { _cache_index = _flush(_cache_index, true); } + + dc_control(true); + if (!_direct_dc) + { + _direct_dc = true; + gpio_matrix_out(_cfg.pin_rs, 0x100, 0, 0); + } + gpio_lo(_cfg.pin_rd); + + _init_pin(true); + } + + void Bus_Parallel8::endRead(void) + { + gpio_hi(_cfg.pin_rd); + + _init_pin(); + } + + void Bus_Parallel8::_read_bytes(uint8_t* dst, uint32_t length) + { + uint8_t in[8]; + + uint32_t mask = ((((((((((((((( + (_cfg.pin_d0 & 7)) << 3) + + (_cfg.pin_d1 & 7)) << 3) + + (_cfg.pin_d2 & 7)) << 3) + + (_cfg.pin_d3 & 7)) << 3) + + (_cfg.pin_d4 & 7)) << 3) + + (_cfg.pin_d5 & 7)) << 3) + + (_cfg.pin_d6 & 7)) << 3) + + (_cfg.pin_d7 & 7)) + ; + + uint32_t idx = ((((((((((((((( + (_cfg.pin_d0 >> 3)) << 3) + + (_cfg.pin_d1 >> 3)) << 3) + + (_cfg.pin_d2 >> 3)) << 3) + + (_cfg.pin_d3 >> 3)) << 3) + + (_cfg.pin_d4 >> 3)) << 3) + + (_cfg.pin_d5 >> 3)) << 3) + + (_cfg.pin_d6 >> 3)) << 3) + + (_cfg.pin_d7 >> 3)) + ; + + auto reg_rd_h = get_gpio_hi_reg(_cfg.pin_rd); + auto reg_rd_l = get_gpio_lo_reg(_cfg.pin_rd); + uint32_t mask_rd = 1ul << (_cfg.pin_rd & 31); + uint_fast8_t val; + do + { + ((uint32_t*)in)[0] = GPIO.in; + ((uint32_t*)in)[1] = GPIO.in1.val; + *reg_rd_h = mask_rd; + val = (1 & (in[(idx >> 0) & 7] >> ((mask >> 0) & 7))); + val = (val << 1) + (1 & (in[(idx >> 3) & 7] >> ((mask >> 3) & 7))); + val = (val << 1) + (1 & (in[(idx >> 6) & 7] >> ((mask >> 6) & 7))); + val = (val << 1) + (1 & (in[(idx >> 9) & 7] >> ((mask >> 9) & 7))); + val = (val << 1) + (1 & (in[(idx >> 12) & 7] >> ((mask >> 12) & 7))); + *reg_rd_l = mask_rd; + val = (val << 1) + (1 & (in[(idx >> 15) & 7] >> ((mask >> 15) & 7))); + val = (val << 1) + (1 & (in[(idx >> 18) & 7] >> ((mask >> 18) & 7))); + val = (val << 1) + (1 & (in[(idx >> 21) & 7] >> ((mask >> 21) & 7))); + *dst++ = val; + } while (--length); + } + + uint32_t Bus_Parallel8::readData(uint_fast8_t bit_length) + { + union { + uint32_t res; + uint8_t raw[4]; + }; + _read_bytes(raw, (bit_length + 7) >> 3); + return res; + } + + bool Bus_Parallel8::readBytes(uint8_t* dst, uint32_t length, bool use_dma) + { + _read_bytes(dst, length); + return true; + } + + void Bus_Parallel8::readPixels(void* dst, pixelcopy_t* param, uint32_t length) + { + uint32_t _regbuf[8]; + const auto bytes = param->src_bits >> 3; + uint32_t limit = (bytes == 2) ? 16 : 10; + param->src_data = _regbuf; + int32_t dstindex = 0; + do { + uint32_t len2 = (limit > length) ? length : limit; + length -= len2; + + _read_bytes((uint8_t*)_regbuf, len2 * bytes); + param->src_x = 0; + dstindex = param->fp_copy(dst, dstindex, dstindex + len2, param); + } while (length); + } + + void Bus_Parallel8::_alloc_dmadesc(size_t len) + { + if (_dmadesc) heap_caps_free(_dmadesc); + _dmadesc_size = len; + _dmadesc = (lldesc_t*)heap_caps_malloc(sizeof(lldesc_t) * len, MALLOC_CAP_DMA); + } + + void Bus_Parallel8::_setup_dma_desc_links(const uint8_t *data, int32_t len) + { + static constexpr size_t MAX_DMA_LEN = (4096-4); + + if (_dmadesc_size * MAX_DMA_LEN < len) + { + _alloc_dmadesc(len / MAX_DMA_LEN + 1); + } + lldesc_t *dmadesc = _dmadesc; + + while (len > MAX_DMA_LEN) + { + len -= MAX_DMA_LEN; + dmadesc->buf = (uint8_t *)data; + data += MAX_DMA_LEN; + *(uint32_t*)dmadesc = MAX_DMA_LEN | MAX_DMA_LEN << 12 | 0x80000000; + dmadesc->qe.stqe_next = dmadesc + 1; + dmadesc++; + } + *(uint32_t*)dmadesc = ((len + 3) & ( ~3 )) | len << 12 | 0xC0000000; + dmadesc->buf = (uint8_t *)data; + dmadesc->qe.stqe_next = nullptr; + } + +//---------------------------------------------------------------------------- + } +} + +#endif +#endif diff --git a/src/lgfx/v1/platforms/esp32s2/Bus_Parallel8.hpp b/src/lgfx/v1/platforms/esp32s2/Bus_Parallel8.hpp new file mode 100644 index 0000000..62e2f48 --- /dev/null +++ b/src/lgfx/v1/platforms/esp32s2/Bus_Parallel8.hpp @@ -0,0 +1,156 @@ +/*----------------------------------------------------------------------------/ + Lovyan GFX - Graphics library for embedded devices. + +Original Source: + https://github.com/lovyan03/LovyanGFX/ + +Licence: + [FreeBSD](https://github.com/lovyan03/LovyanGFX/blob/master/license.txt) + +Author: + [lovyan03](https://twitter.com/lovyan03) + +Contributors: + [ciniml](https://github.com/ciniml) + [mongonta0716](https://github.com/mongonta0716) + [tobozo](https://github.com/tobozo) +/----------------------------------------------------------------------------*/ +#pragma once + +#include +#include + +#if __has_include() + #include +#else + #include +#endif + +#if __has_include() + #include +#endif + +#include + +#include "../../Bus.hpp" +#include "../common.hpp" + +namespace lgfx +{ + inline namespace v1 + { +//---------------------------------------------------------------------------- + + class Bus_Parallel8 : public IBus + { + public: + struct config_t + { + i2s_port_t i2s_port = I2S_NUM_0; + + // max 40MHz , 27MHz , 20MHz , 16MHz , 13.3MHz , 11.43MHz , 10MHz , 8.9MHz and more ... + uint32_t freq_write = 16000000; + int8_t pin_wr = -1; + int8_t pin_rd = -1; + int8_t pin_rs = -1; // D/C + union + { + int8_t pin_data[8]; + struct + { + int8_t pin_d0 = -1; + int8_t pin_d1 = -1; + int8_t pin_d2 = -1; + int8_t pin_d3 = -1; + int8_t pin_d4 = -1; + int8_t pin_d5 = -1; + int8_t pin_d6 = -1; + int8_t pin_d7 = -1; + }; + }; + }; + + + const config_t& config(void) const { return _cfg; } + void config(const config_t& config); + + bus_type_t busType(void) const override { return bus_type_t::bus_parallel8; } + + bool init(void) override; + void release(void) override; + + void beginTransaction(void) override; + void endTransaction(void) override; + void wait(void) override; + bool busy(void) const override; + + void flush(void) override; + bool writeCommand(uint32_t data, uint_fast8_t bit_length) override; + void writeData(uint32_t data, uint_fast8_t bit_length) override; + void writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t count) override; + void writePixels(pixelcopy_t* param, uint32_t length) override; + void writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) override; + + void initDMA(void) override {} + void addDMAQueue(const uint8_t* data, uint32_t length) override { writeBytes(data, length, true, true); } + void execDMAQueue(void) override { flush(); }; + uint8_t* getDMABuffer(uint32_t length) override { return _flip_buffer.getBuffer(length); } + + void beginRead(void) override; + void endRead(void) override; + uint32_t readData(uint_fast8_t bit_length) override; + bool readBytes(uint8_t* dst, uint32_t length, bool use_dma) override; + void readPixels(void* dst, pixelcopy_t* param, uint32_t length) override; + + private: + + void dc_control(bool flg) + { + auto reg = _gpio_reg_dc[flg]; + auto mask = _mask_reg_dc; + auto i2s_dev = (i2s_dev_t*)_dev; + if (i2s_dev->out_link.val) + { +#if defined (CONFIG_IDF_TARGET_ESP32S2) + while (!(i2s_dev->lc_state0.out_empty)) {} +#else + while (!(i2s_dev->lc_state0 & 0x80000000)) {} // I2S_OUT_EMPTY +#endif + i2s_dev->out_link.val = 0; + } + while (!i2s_dev->state.tx_idle) {} + *reg = mask; + } + + static constexpr size_t CACHE_SIZE = 132; + + config_t _cfg; + SimpleBuffer _flip_buffer; + size_t _div_num; + size_t _cache_index; + uint16_t _cache[2][CACHE_SIZE]; + uint16_t* _cache_flip; + + void _wait(void); + void _init_pin(bool read = false); + size_t _flush(size_t idx, bool dc = true); + void _read_bytes(uint8_t* dst, uint32_t length); + + void _alloc_dmadesc(size_t len); + void _setup_dma_desc_links(const uint8_t *data, int32_t len); + + volatile uint32_t* _gpio_reg_dc[2] = { nullptr, nullptr }; + uint32_t _mask_reg_dc = 0; + bool _direct_dc; + + uint32_t _last_freq_apb; + uint32_t _clkdiv_write; + volatile void *_dev; + + lldesc_t* _dmadesc = nullptr; + uint32_t _dmadesc_size = 0; + }; + +//---------------------------------------------------------------------------- + } +} diff --git a/src/lgfx/v1/platforms/esp8266/Bus_SPI.cpp b/src/lgfx/v1/platforms/esp8266/Bus_SPI.cpp index fc34f6b..d394852 100644 --- a/src/lgfx/v1/platforms/esp8266/Bus_SPI.cpp +++ b/src/lgfx/v1/platforms/esp8266/Bus_SPI.cpp @@ -65,17 +65,19 @@ namespace lgfx void Bus_SPI::beginRead(void) { + uint32_t user = (SPI1U & ~(SPIUMOSI | SPIUSIO)) | SPIUMISO | (_cfg.spi_3wire ? SPIUSIO : 0); + dc_control(true); spi::endTransaction(0); spi::beginTransaction(0, _cfg.freq_read, _cfg.spi_mode); - SPI1U = (SPI1U & ~SPIUMOSI) | SPIUMISO; + SPI1U = user; } void Bus_SPI::endRead(void) { spi::endTransaction(0); spi::beginTransaction(0, _cfg.freq_write, _cfg.spi_mode); - SPI1U = (SPI1U & ~SPIUMISO) | SPIUMOSI; + SPI1U = (SPI1U & ~(SPIUMISO | SPIUSIO)) | SPIUMOSI; } void Bus_SPI::wait(void) @@ -88,7 +90,7 @@ namespace lgfx return SPI1CMD & SPIBUSY; } - bool Bus_SPI::writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) + bool Bus_SPI::writeCommand(uint32_t data, uint_fast8_t bit_length) { const uint32_t u1 = --bit_length << SPILMOSI; dc_control(false); @@ -98,7 +100,7 @@ namespace lgfx return true; } - void Bus_SPI::writeData(std::uint32_t data, std::uint_fast8_t bit_length) + void Bus_SPI::writeData(uint32_t data, uint_fast8_t bit_length) { const uint32_t u1 = --bit_length << SPILMOSI; dc_control(true); @@ -107,11 +109,11 @@ namespace lgfx SPI1CMD = SPIBUSY; } - void Bus_SPI::writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t count) + void Bus_SPI::writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t count) { - std::uint32_t regbuf0 = data | data << bit_length; - std::uint32_t regbuf1; - std::uint32_t regbuf2; + uint32_t regbuf0 = data | data << bit_length; + uint32_t regbuf1; + uint32_t regbuf2; // make 12Bytes data. bool bits24 = (bit_length == 24); if (bits24) { @@ -122,8 +124,8 @@ namespace lgfx regbuf2 = regbuf0; } - std::uint32_t length = bit_length * count; // convert to bitlength. - std::uint32_t len = (length <= 96u) ? length : (length <= 144u) ? 48u : 96u; // 1st send length = max 12Byte (96bit). + uint32_t length = bit_length * count; // convert to bitlength. + uint32_t len = (length <= 96u) ? length : (length <= 144u) ? 48u : 96u; // 1st send length = max 12Byte (96bit). length -= len; --len; @@ -139,10 +141,10 @@ namespace lgfx SPI1CMD = SPIBUSY; if (0 == length) return; - std::uint32_t regbuf[7] = { regbuf0, regbuf1, regbuf2, regbuf0, regbuf1, regbuf2, regbuf0 } ; + uint32_t regbuf[7] = { regbuf0, regbuf1, regbuf2, regbuf0, regbuf1, regbuf2, regbuf0 } ; memcpy((void*)&SPI1W3, regbuf, 24); memcpy((void*)&SPI1W9, regbuf, 28); - std::uint32_t limit; + uint32_t limit; if (bits24) { limit = 504; @@ -176,71 +178,46 @@ namespace lgfx } } - void Bus_SPI::writePixels(pixelcopy_t* param, std::uint32_t length) + void Bus_SPI::writePixels(pixelcopy_t* param, uint32_t length) { - const std::uint8_t bytes = param->dst_bits >> 3; - const std::uint32_t limit = (bytes == 2) ? 16 : 10; // limit = 32/bytes (bytes==2 is 16 bytes==3 is 10) - std::uint32_t len = (length - 1) / limit; - std::uint32_t highpart = (len & 1) << 3; + const uint8_t bytes = param->dst_bits >> 3; + const uint32_t limit = (bytes == 2) ? 32 : 20; // limit = 64/bytes (4Byte aligned) (bytes==2 is 32 bytes==3 is 20) + uint32_t len = (length - 1) / limit; + uint32_t highpart = (len & 1) << 3; len = length - (len * limit); - std::uint32_t regbuf[8]; + uint32_t regbuf[16]; param->fp_copy(regbuf, 0, len, param); - auto spi_w0_reg = reinterpret_cast(&SPI1W0); - - std::uint32_t user_reg = SPI1U; + auto spi_w0_reg = (void*)reinterpret_cast(&SPI1W0); dc_control(true); set_write_len(len * bytes << 3); - memcpy((void*)&spi_w0_reg[highpart], regbuf, (len * bytes + 3) & (~3)); - if (highpart) SPI1U = user_reg | SPIUMOSIH; + memcpy(spi_w0_reg, regbuf, (len * bytes + 3) & (~3)); exec_spi(); if (0 == (length -= len)) return; - for (; length; length -= limit) + if (len != limit) { param->fp_copy(regbuf, 0, limit, param); - memcpy((void*)&spi_w0_reg[highpart ^= 0x08], regbuf, limit * bytes); - std::uint32_t user = user_reg; - if (highpart) user |= SPIUMOSIH; - if (len == limit) - { - wait_spi(); - SPI1U = user; - exec_spi(); - } - else - { - len = limit; - wait_spi(); - set_write_len(limit * bytes << 3); - SPI1U = user; - exec_spi(); - } + wait_spi(); + memcpy(spi_w0_reg, regbuf, limit * bytes); + set_write_len(limit * bytes << 3); + exec_spi(); + if (0 == (length -= limit)) return; } - } - void Bus_SPI::writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) - { -/* - if (reinterpret_cast(data) & 3) + for (; length; length -= limit) { - auto len = reinterpret_cast(data) & 3; - length -= len; - std::uint32_t val = 0; - std::size_t i = 0; - do - { - val = pgm_read_byte(data++) << (i * 8); - } while (++i != len); - dc_control(dc); - set_write_len(len << 3); - SPI1W0 = val; + param->fp_copy(regbuf, 0, limit, param); + wait_spi(); + memcpy(spi_w0_reg, regbuf, limit * bytes); exec_spi(); - if (!length) return; } -//*/ + } + + void Bus_SPI::writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) + { if (length <= 64) { auto aligned_len = (length + 3) & (~3); @@ -252,45 +229,46 @@ namespace lgfx return; } - constexpr std::uint32_t limit = 32; - std::uint32_t len = ((length - 1) & 0x1F) + 1; - std::uint32_t highpart = ((length - 1) & limit) >> 2; // 8 or 0 + static constexpr uint32_t limit = 32; + uint32_t len = ((length - 1) & 0x1F) + 1; + uint32_t highpart = ((length - 1) & limit) ? 8 : 0; - auto spi_w0_reg = reinterpret_cast(&SPI1W0); + auto spi_w0_reg = reinterpret_cast(&SPI1W0); - std::uint32_t user_reg = SPI1U; + uint32_t user_reg_0 = SPI1U; + uint32_t user_reg_1 = user_reg_0 | SPIUMOSIH; dc_control(dc); set_write_len(len << 3); - memcpy((void*)&spi_w0_reg[highpart], data, (len + 3) & (~3)); - if (highpart) SPI1U = user_reg | SPIUMOSIH; + if (highpart) SPI1U = user_reg_1; exec_spi(); - if (0 == (length -= len)) return; + length -= len; - for (; length; length -= limit) + if (len != limit) { data += len; memcpy((void*)&spi_w0_reg[highpart ^= 0x08], data, limit); - std::uint32_t user = user_reg; - if (highpart) user |= SPIUMOSIH; - if (len == limit) - { - wait_spi(); - SPI1U = user; - exec_spi(); - } - else - { - len = limit; - wait_spi(); - set_write_len(limit << 3); - SPI1U = user; - exec_spi(); - } + uint32_t user = highpart ? user_reg_1 : user_reg_0; + wait_spi(); + set_write_len(limit << 3); + SPI1U = user; + exec_spi(); + if (0 == (length -= limit)) return; } + + length >>= 5; + do + { + data += limit; + memcpy((void*)&spi_w0_reg[highpart ^= 0x08], data, limit); + uint32_t user = highpart ? user_reg_1 : user_reg_0; + wait_spi(); + SPI1U = user; + exec_spi(); + } while (--length); } - std::uint32_t Bus_SPI::readData(std::uint_fast8_t bit_length) + uint32_t Bus_SPI::readData(uint_fast8_t bit_length) { set_read_len(bit_length); exec_spi(); @@ -298,23 +276,23 @@ namespace lgfx return SPI1W0; } - bool Bus_SPI::readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma) + bool Bus_SPI::readBytes(uint8_t* dst, uint32_t length, bool use_dma) { - std::uint32_t len1 = std::min(length, 32u); // 32 Byte read. - std::uint32_t len2 = len1; + uint32_t len1 = std::min(length, 32u); // 32 Byte read. + uint32_t len2 = len1; wait_spi(); set_read_len(len1 << 3); exec_spi(); - std::uint32_t highpart = 8; - std::uint32_t userreg = SPI1U; - auto spi_w0_reg = reinterpret_cast(&SPI1W0); + uint32_t highpart = 8; + uint32_t userreg = SPI1U; + auto spi_w0_reg = reinterpret_cast(&SPI1W0); do { if (0 == (length -= len1)) { len2 = len1; wait_spi(); SPI1U = userreg; } else { - std::uint32_t user = userreg; + uint32_t user = userreg; if (highpart) user = userreg | SPIUMISOH; if (length < len1) { len1 = length; @@ -334,16 +312,16 @@ namespace lgfx return true; } - void Bus_SPI::readPixels(void* dst, pixelcopy_t* param, std::uint32_t length) + void Bus_SPI::readPixels(void* dst, pixelcopy_t* param, uint32_t length) { - std::uint32_t bytes = param->src_bits >> 3; - std::uint32_t dstindex = 0; - std::uint32_t len = 4; - std::uint32_t buf[6]; + uint32_t bytes = param->src_bits >> 3; + uint32_t dstindex = 0; + uint32_t len = 4; + uint32_t buf[6]; param->src_data = buf; do { if (len > length) len = length; - readBytes((std::uint8_t*)buf, len * bytes, true); + readBytes((uint8_t*)buf, len * bytes, true); param->src_x = 0; dstindex = param->fp_copy(dst, dstindex, dstindex + len, param); length -= len; diff --git a/src/lgfx/v1/platforms/esp8266/Bus_SPI.hpp b/src/lgfx/v1/platforms/esp8266/Bus_SPI.hpp index 15f9539..37cec30 100644 --- a/src/lgfx/v1/platforms/esp8266/Bus_SPI.hpp +++ b/src/lgfx/v1/platforms/esp8266/Bus_SPI.hpp @@ -17,7 +17,7 @@ Original Source: /----------------------------------------------------------------------------*/ #pragma once -#include +#include #include "../../Bus.hpp" #include "../common.hpp" @@ -33,15 +33,15 @@ namespace lgfx public: struct config_t { - std::uint32_t freq_write = 16000000; - std::uint32_t freq_read = 8000000; - //bool spi_3wire = true; + uint32_t freq_write = 16000000; + uint32_t freq_read = 8000000; + bool spi_3wire = true; //bool use_lock = true; - std::int16_t pin_sclk = -1; - std::int16_t pin_miso = -1; - std::int16_t pin_mosi = -1; - std::int16_t pin_dc = -1; - std::uint8_t spi_mode = 0; + int16_t pin_sclk = -1; // 14 or 6 + int16_t pin_miso = -1; // 12 or 7 + int16_t pin_mosi = -1; // 13 or 8 + int16_t pin_dc = -1; + uint8_t spi_mode = 0; }; const config_t& config(void) const { return _cfg; } @@ -58,28 +58,28 @@ namespace lgfx void wait(void) override; bool busy(void) const override; - bool writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) override; - void writeData(std::uint32_t data, std::uint_fast8_t bit_length) override; - void writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t count) override; - void writePixels(pixelcopy_t* param, std::uint32_t length) override; - void writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) override; + bool writeCommand(uint32_t data, uint_fast8_t bit_length) override; + void writeData(uint32_t data, uint_fast8_t bit_length) override; + void writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t count) override; + void writePixels(pixelcopy_t* param, uint32_t length) override; + void writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) override; void initDMA(void) {} void flush(void) {} - void addDMAQueue(const std::uint8_t* data, std::uint32_t length) override { writeBytes(data, length, true, true); } + void addDMAQueue(const uint8_t* data, uint32_t length) override { writeBytes(data, length, true, true); } void execDMAQueue(void) {} - std::uint8_t* getDMABuffer(std::uint32_t length) override { return _flip_buffer.getBuffer(length); } + uint8_t* getDMABuffer(uint32_t length) override { return _flip_buffer.getBuffer(length); } void beginRead(void) override; void endRead(void) override; - std::uint32_t readData(std::uint_fast8_t bit_length) override; - bool readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma) override; - void readPixels(void* dst, pixelcopy_t* param, std::uint32_t length) override; + uint32_t readData(uint_fast8_t bit_length) override; + bool readBytes(uint8_t* dst, uint32_t length, bool use_dma) override; + void readPixels(void* dst, pixelcopy_t* param, uint32_t length) override; private: - __attribute__ ((always_inline)) inline void set_write_len( std::uint32_t bitlen) { SPI1U1 = (bitlen - 1) << SPILMOSI; } - __attribute__ ((always_inline)) inline void set_read_len( std::uint32_t bitlen) { SPI1U1 = (bitlen - 1) << SPILMISO; } + __attribute__ ((always_inline)) inline void set_write_len( uint32_t bitlen) { SPI1U1 = (bitlen - 1) << SPILMOSI; } + __attribute__ ((always_inline)) inline void set_read_len( uint32_t bitlen) { SPI1U1 = (bitlen - 1) << SPILMISO; } __attribute__ ((always_inline)) inline void wait_spi(void) { while (SPI1CMD & SPIBUSY); } __attribute__ ((always_inline)) inline void exec_spi(void) { SPI1CMD = SPIBUSY; } __attribute__ ((always_inline)) inline void dc_control(bool flg) @@ -100,12 +100,12 @@ namespace lgfx config_t _cfg; FlipBuffer _flip_buffer; bool _need_wait; - std::uint32_t _mask_reg_dc; - std::uint32_t _last_apb_freq = -1; - std::uint32_t _clkdiv_write; - std::uint32_t _clkdiv_read; - volatile std::uint32_t* _gpio_reg_dc_h; - volatile std::uint32_t* _gpio_reg_dc_l; + uint32_t _mask_reg_dc; + uint32_t _last_apb_freq = -1; + uint32_t _clkdiv_write; + uint32_t _clkdiv_read; + volatile uint32_t* _gpio_reg_dc_h; + volatile uint32_t* _gpio_reg_dc_l; }; diff --git a/src/lgfx/v1/platforms/esp8266/common.cpp b/src/lgfx/v1/platforms/esp8266/common.cpp index 204963f..be51cf8 100644 --- a/src/lgfx/v1/platforms/esp8266/common.cpp +++ b/src/lgfx/v1/platforms/esp8266/common.cpp @@ -31,7 +31,7 @@ namespace lgfx #if defined ( ARDUINO ) - void pinMode(std::int_fast16_t pin, pin_mode_t mode) + void pinMode(int_fast16_t pin, pin_mode_t mode) { switch (mode) { @@ -155,7 +155,7 @@ namespace lgfx SPI.end(); #endif } - void beginTransaction(int spi_host, std::uint32_t freq, int spi_mode) + void beginTransaction(int spi_host, uint32_t freq, int spi_mode) { #if defined ( ARDUINO ) SPI.setFrequency(freq); @@ -176,7 +176,7 @@ namespace lgfx #endif SPI1U |= SPIUDUPLEX; } - void writeBytes(int spi_host, const std::uint8_t* data, std::size_t length) + void writeBytes(int spi_host, const uint8_t* data, size_t length) { const uint32_t u1 = ((length << 3) - 1) << SPILMOSI; while (SPI1CMD & SPIBUSY); @@ -184,7 +184,7 @@ namespace lgfx memcpy_P(reinterpret_cast(SPI1W0), data, length); SPI1CMD = SPIBUSY; } - void readBytes(int spi_host, std::uint8_t* data, std::size_t length) + void readBytes(int spi_host, uint8_t* data, size_t length) { const uint32_t u1 = ((length << 3) - 1) << SPILMISO; while (SPI1CMD & SPIBUSY); @@ -203,20 +203,20 @@ namespace lgfx { cpp::result init(int i2c_port, int pin_sda, int pin_scl) { return cpp::fail(error_t::unknown_err); } cpp::result release(int i2c_port) { return cpp::fail(error_t::unknown_err); } - cpp::result restart(int i2c_port, int i2c_addr, std::uint32_t freq, bool read) { return cpp::fail(error_t::unknown_err); } - cpp::result beginTransaction(int i2c_port, int i2c_addr, std::uint32_t freq, bool read) { return cpp::fail(error_t::unknown_err); } + cpp::result restart(int i2c_port, int i2c_addr, uint32_t freq, bool read) { return cpp::fail(error_t::unknown_err); } + cpp::result beginTransaction(int i2c_port, int i2c_addr, uint32_t freq, bool read) { return cpp::fail(error_t::unknown_err); } cpp::result endTransaction(int i2c_port) { return cpp::fail(error_t::unknown_err); } - cpp::result writeBytes(int i2c_port, const std::uint8_t *data, std::size_t length) { return cpp::fail(error_t::unknown_err); } - cpp::result readBytes(int i2c_port, std::uint8_t *data, std::size_t length) { return cpp::fail(error_t::unknown_err); } + cpp::result writeBytes(int i2c_port, const uint8_t *data, size_t length) { return cpp::fail(error_t::unknown_err); } + cpp::result readBytes(int i2c_port, uint8_t *data, size_t length) { return cpp::fail(error_t::unknown_err); } //-------- - cpp::result transactionWrite(int i2c_port, int addr, const std::uint8_t *writedata, std::uint8_t writelen, std::uint32_t freq) { return cpp::fail(error_t::unknown_err); } - cpp::result transactionRead(int i2c_port, int addr, std::uint8_t *readdata, std::uint8_t readlen, std::uint32_t freq) { return cpp::fail(error_t::unknown_err); } - cpp::result transactionWriteRead(int i2c_port, int addr, const std::uint8_t *writedata, std::uint8_t writelen, std::uint8_t *readdata, std::size_t readlen, std::uint32_t freq) { return cpp::fail(error_t::unknown_err); } + cpp::result transactionWrite(int i2c_port, int addr, const uint8_t *writedata, uint8_t writelen, uint32_t freq) { return cpp::fail(error_t::unknown_err); } + cpp::result transactionRead(int i2c_port, int addr, uint8_t *readdata, uint8_t readlen, uint32_t freq) { return cpp::fail(error_t::unknown_err); } + cpp::result transactionWriteRead(int i2c_port, int addr, const uint8_t *writedata, uint8_t writelen, uint8_t *readdata, size_t readlen, uint32_t freq) { return cpp::fail(error_t::unknown_err); } - cpp::result readRegister8(int i2c_port, int addr, std::uint8_t reg, std::uint32_t freq) { return cpp::fail(error_t::unknown_err); } - cpp::result writeRegister8(int i2c_port, int addr, std::uint8_t reg, std::uint8_t data, std::uint8_t mask, std::uint32_t freq) { return cpp::fail(error_t::unknown_err); } + cpp::result readRegister8(int i2c_port, int addr, uint8_t reg, uint32_t freq) { return cpp::fail(error_t::unknown_err); } + cpp::result writeRegister8(int i2c_port, int addr, uint8_t reg, uint8_t data, uint8_t mask, uint32_t freq) { return cpp::fail(error_t::unknown_err); } } //---------------------------------------------------------------------------- diff --git a/src/lgfx/v1/platforms/esp8266/common.hpp b/src/lgfx/v1/platforms/esp8266/common.hpp index 139430c..b734b65 100644 --- a/src/lgfx/v1/platforms/esp8266/common.hpp +++ b/src/lgfx/v1/platforms/esp8266/common.hpp @@ -69,9 +69,9 @@ namespace lgfx static inline void* heap_alloc_dma( size_t length) { return malloc(length); } // aligned_alloc(16, length); static inline void heap_free(void* buf) { free(buf); } - static inline void gpio_hi(std::int_fast8_t pin) { if (pin & 16) { if (pin == 16) *(volatile uint32_t*)(0x60000768) |= 1; } else { *(volatile uint32_t*)(0x60000304) = 1 << (pin & 15); } } - static inline void gpio_lo(std::int_fast8_t pin) { if (pin & 16) { if (pin == 16) *(volatile uint32_t*)(0x60000768) &= ~1; } else { *(volatile uint32_t*)(0x60000308) = 1 << (pin & 15); } } - static inline bool gpio_in(std::int_fast8_t pin) + static inline void gpio_hi(int_fast8_t pin) { if (pin & 16) { if (pin == 16) *(volatile uint32_t*)(0x60000768) |= 1; } else { *(volatile uint32_t*)(0x60000304) = 1 << (pin & 15); } } + static inline void gpio_lo(int_fast8_t pin) { if (pin & 16) { if (pin == 16) *(volatile uint32_t*)(0x60000768) &= ~1; } else { *(volatile uint32_t*)(0x60000308) = 1 << (pin & 15); } } + static inline bool gpio_in(int_fast8_t pin) { return *(volatile uint32_t*)((pin & 16) ? 0x6000078C // GP16I @@ -86,8 +86,8 @@ namespace lgfx , input_pulldown }; - void pinMode(std::int_fast16_t pin, pin_mode_t mode); - inline void lgfxPinMode(std::int_fast16_t pin, pin_mode_t mode) + void pinMode(int_fast16_t pin, pin_mode_t mode); + inline void lgfxPinMode(int_fast16_t pin, pin_mode_t mode) { pinMode(pin, mode); } @@ -143,12 +143,12 @@ namespace lgfx _fp = &_file; return _file; } - int read(std::uint8_t *buf, std::uint32_t len) override { return _fp->read(buf, len); } - void skip(std::int32_t offset) override { seek(offset, SeekCur); } - bool seek(std::uint32_t offset) override { return seek(offset, SeekSet); } - bool seek(std::uint32_t offset, SeekMode mode) { return _fp->seek(offset, mode); } + int read(uint8_t *buf, uint32_t len) override { return _fp->read(buf, len); } + void skip(int32_t offset) override { seek(offset, SeekCur); } + bool seek(uint32_t offset) override { return seek(offset, SeekSet); } + bool seek(uint32_t offset, SeekMode mode) { return _fp->seek(offset, mode); } void close(void) override { if (_fp) _fp->close(); } - std::int32_t tell(void) override { return _fp->position(); } + int32_t tell(void) override { return _fp->position(); } }; #else // dummy @@ -163,13 +163,13 @@ namespace lgfx template void setFS(T& fs) {} - bool open(const char* path, const char* mode) { return false; } - int read(std::uint8_t *buf, std::uint32_t len) override { return false; } - void skip(std::int32_t offset) override { } - bool seek(std::uint32_t offset) override { return false; } - bool seek(std::uint32_t offset, int origin) { return false; } + bool open(const char*, const char*) { return false; } + int read(uint8_t*, uint32_t) override { return false; } + void skip(int32_t) override { } + bool seek(uint32_t) override { return false; } + bool seek(uint32_t, int) { return false; } void close() override { } - std::int32_t tell(void) override { return 0; } + int32_t tell(void) override { return 0; } }; #endif @@ -183,12 +183,12 @@ namespace lgfx } FILE* _fp; bool open(const char* path) override { return (_fp = fopen(path, "r")); } - int read(std::uint8_t *buf, std::uint32_t len) override { return fread((char*)buf, 1, len, _fp); } - void skip(std::int32_t offset) override { seek(offset, SEEK_CUR); } - bool seek(std::uint32_t offset) override { return seek(offset, SEEK_SET); } - bool seek(std::uint32_t offset, int origin) { return fseek(_fp, offset, origin); } + int read(uint8_t *buf, uint32_t len) override { return fread((char*)buf, 1, len, _fp); } + void skip(int32_t offset) override { seek(offset, SEEK_CUR); } + bool seek(uint32_t offset) override { return seek(offset, SEEK_SET); } + bool seek(uint32_t offset, int origin) { return fseek(_fp, offset, origin); } void close() override { if (_fp) fclose(_fp); } - std::int32_t tell(void) override { return ftell(_fp); } + int32_t tell(void) override { return ftell(_fp); } }; #endif @@ -199,23 +199,23 @@ namespace lgfx struct StreamWrapper : public DataWrapper { - void set(Stream* src, std::uint32_t length = ~0u) { _stream = src; _length = length; _index = 0; } + void set(Stream* src, uint32_t length = ~0u) { _stream = src; _length = length; _index = 0; } - int read(std::uint8_t *buf, std::uint32_t len) override { - len = std::min(len, _stream->available()); + int read(uint8_t *buf, uint32_t len) override { + len = std::min(len, _stream->available()); if (len > _length - _index) { len = _length - _index; } _index += len; return _stream->readBytes((char*)buf, len); } - void skip(std::int32_t offset) override { if (0 < offset) { char dummy[offset]; _stream->readBytes(dummy, offset); _index += offset; } } - bool seek(std::uint32_t offset) override { if (offset < _index) { return false; } skip(offset - _index); return true; } + void skip(int32_t offset) override { if (0 < offset) { char dummy[offset]; _stream->readBytes(dummy, offset); _index += offset; } } + bool seek(uint32_t offset) override { if (offset < _index) { return false; } skip(offset - _index); return true; } void close() override { } - std::int32_t tell(void) override { return _index; } + int32_t tell(void) override { return _index; } protected: Stream* _stream; - std::uint32_t _index; - std::uint32_t _length = 0; + uint32_t _index; + uint32_t _length = 0; }; #endif diff --git a/src/lgfx/v1/platforms/samd21/Bus_I2C.cpp b/src/lgfx/v1/platforms/samd21/Bus_I2C.cpp index 142384a..53506bf 100644 --- a/src/lgfx/v1/platforms/samd21/Bus_I2C.cpp +++ b/src/lgfx/v1/platforms/samd21/Bus_I2C.cpp @@ -136,29 +136,29 @@ namespace lgfx lgfx::i2c::endTransaction(_cfg.sercom_index); lgfx::i2c::beginTransaction(_cfg.sercom_index, _cfg.i2c_addr, _cfg.freq_write, false); } - lgfx::i2c::writeBytes(_cfg.sercom_index, (std::uint8_t*)(dc ? &_cfg.prefix_data : &_cfg.prefix_cmd), _cfg.prefix_len); + lgfx::i2c::writeBytes(_cfg.sercom_index, (uint8_t*)(dc ? &_cfg.prefix_data : &_cfg.prefix_cmd), _cfg.prefix_len); _state = st; } - bool Bus_I2C::writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) + bool Bus_I2C::writeCommand(uint32_t data, uint_fast8_t bit_length) { dc_control(false); - return lgfx::i2c::writeBytes(_cfg.sercom_index, (std::uint8_t*)&data, (bit_length >> 3)).has_value(); + return lgfx::i2c::writeBytes(_cfg.sercom_index, (uint8_t*)&data, (bit_length >> 3)).has_value(); } - void Bus_I2C::writeData(std::uint32_t data, std::uint_fast8_t bit_length) + void Bus_I2C::writeData(uint32_t data, uint_fast8_t bit_length) { dc_control(true); - lgfx::i2c::writeBytes(_cfg.sercom_index, (std::uint8_t*)&data, (bit_length >> 3)); + lgfx::i2c::writeBytes(_cfg.sercom_index, (uint8_t*)&data, (bit_length >> 3)); } - void Bus_I2C::writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t length) + void Bus_I2C::writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t length) { dc_control(true); - const std::uint8_t dst_bytes = bit_length >> 3; - std::uint32_t buf0 = data | data << bit_length; - std::uint32_t buf1; - std::uint32_t buf2; + const uint8_t dst_bytes = bit_length >> 3; + uint32_t buf0 = data | data << bit_length; + uint32_t buf1; + uint32_t buf2; // make 12Bytes data. if (dst_bytes != 3) { @@ -174,10 +174,10 @@ namespace lgfx buf1 = buf0 >> 8 | buf0 << 16; buf2 = buf0 >> 16 | buf0 << 8; } - std::uint32_t src[8] = { buf0, buf1, buf2, buf0, buf1, buf2, buf0, buf1 }; - auto buf = reinterpret_cast(src); - std::uint32_t limit = 32 / dst_bytes; - std::uint32_t len; + uint32_t src[8] = { buf0, buf1, buf2, buf0, buf1, buf2, buf0, buf1 }; + auto buf = reinterpret_cast(src); + uint32_t limit = 32 / dst_bytes; + uint32_t len; do { len = ((length - 1) % limit) + 1; @@ -185,13 +185,13 @@ namespace lgfx } while (length -= len); } - void Bus_I2C::writePixels(pixelcopy_t* param, std::uint32_t length) + void Bus_I2C::writePixels(pixelcopy_t* param, uint32_t length) { dc_control(true); - const std::uint8_t dst_bytes = param->dst_bits >> 3; - std::uint32_t limit = 32 / dst_bytes; - std::uint32_t len; - std::uint8_t buf[32]; + const uint8_t dst_bytes = param->dst_bits >> 3; + uint32_t limit = 32 / dst_bytes; + uint32_t len; + uint8_t buf[32]; do { len = ((length - 1) % limit) + 1; @@ -200,7 +200,7 @@ namespace lgfx } while (length -= len); } - void Bus_I2C::writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) + void Bus_I2C::writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) { if (length < 64) { @@ -209,7 +209,7 @@ namespace lgfx } else { - std::uint32_t len = ((length - 1) & 63) + 1; + uint32_t len = ((length - 1) & 63) + 1; do { dc_control(dc); @@ -223,33 +223,33 @@ namespace lgfx } } - std::uint32_t Bus_I2C::readData(std::uint_fast8_t bit_length) + uint32_t Bus_I2C::readData(uint_fast8_t bit_length) { beginRead(); - std::uint32_t res; - i2c::readBytes(_cfg.sercom_index, reinterpret_cast(&res), bit_length >> 3); + uint32_t res; + i2c::readBytes(_cfg.sercom_index, reinterpret_cast(&res), bit_length >> 3); return res; } - bool Bus_I2C::readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma) + bool Bus_I2C::readBytes(uint8_t* dst, uint32_t length, bool use_dma) { beginRead(); return i2c::readBytes(_cfg.sercom_index, dst, length).has_value(); } - void Bus_I2C::readPixels(void* dst, pixelcopy_t* param, std::uint32_t length) + void Bus_I2C::readPixels(void* dst, pixelcopy_t* param, uint32_t length) { beginRead(); const auto bytes = param->src_bits >> 3; - std::uint32_t regbuf[8]; - std::uint32_t limit = 32 / bytes; + uint32_t regbuf[8]; + uint32_t limit = 32 / bytes; param->src_data = regbuf; - std::int32_t dstindex = 0; + int32_t dstindex = 0; do { - std::uint32_t len = (limit > length) ? length : limit; + uint32_t len = (limit > length) ? length : limit; length -= len; - i2c::readBytes(_cfg.sercom_index, (std::uint8_t*)regbuf, len * bytes); + i2c::readBytes(_cfg.sercom_index, (uint8_t*)regbuf, len * bytes); param->src_x = 0; dstindex = param->fp_copy(dst, dstindex, dstindex + len, param); } while (length); diff --git a/src/lgfx/v1/platforms/samd21/Bus_I2C.hpp b/src/lgfx/v1/platforms/samd21/Bus_I2C.hpp index 46fe8ad..9f5de73 100644 --- a/src/lgfx/v1/platforms/samd21/Bus_I2C.hpp +++ b/src/lgfx/v1/platforms/samd21/Bus_I2C.hpp @@ -31,16 +31,16 @@ namespace lgfx public: struct config_t { - std::uint8_t sercom_index = 0; - std::uint32_t freq_write = 400000; - std::uint32_t freq_read = 400000; - std::int16_t pin_scl = samd21::PORT_A | 9; - std::int16_t pin_sda = samd21::PORT_A | 8; - - std::uint8_t i2c_addr = 0x3C; - std::uint32_t prefix_cmd = 0x00; - std::uint32_t prefix_data = 0x40; - std::uint32_t prefix_len = 1; + uint8_t sercom_index = 0; + uint32_t freq_write = 400000; + uint32_t freq_read = 400000; + int16_t pin_scl = samd21::PORT_A | 9; + int16_t pin_sda = samd21::PORT_A | 8; + + uint8_t i2c_addr = 0x3C; + uint32_t prefix_cmd = 0x00; + uint32_t prefix_data = 0x40; + uint32_t prefix_len = 1; }; const config_t& config(void) const { return _cfg; } @@ -58,22 +58,22 @@ namespace lgfx bool busy(void) const override; void flush(void) override {} - bool writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) override; - void writeData(std::uint32_t data, std::uint_fast8_t bit_length) override; - void writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t count) override; - void writePixels(pixelcopy_t* param, std::uint32_t length) override; - void writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) override; + bool writeCommand(uint32_t data, uint_fast8_t bit_length) override; + void writeData(uint32_t data, uint_fast8_t bit_length) override; + void writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t count) override; + void writePixels(pixelcopy_t* param, uint32_t length) override; + void writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) override; void initDMA(void) {} - void addDMAQueue(const std::uint8_t* data, std::uint32_t length) override { writeBytes(data, length, true, true); } + void addDMAQueue(const uint8_t* data, uint32_t length) override { writeBytes(data, length, true, true); } void execDMAQueue(void) {} - std::uint8_t* getDMABuffer(std::uint32_t length) override { return _flip_buffer.getBuffer(length); } + uint8_t* getDMABuffer(uint32_t length) override { return _flip_buffer.getBuffer(length); } void beginRead(void) override; void endRead(void) override; - std::uint32_t readData(std::uint_fast8_t bit_length) override; - bool readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma) override; - void readPixels(void* dst, pixelcopy_t* param, std::uint32_t length) override; + uint32_t readData(uint_fast8_t bit_length) override; + bool readBytes(uint8_t* dst, uint32_t length, bool use_dma) override; + void readPixels(void* dst, pixelcopy_t* param, uint32_t length) override; protected: diff --git a/src/lgfx/v1/platforms/samd21/Bus_SPI.cpp b/src/lgfx/v1/platforms/samd21/Bus_SPI.cpp index be6cf14..0c87d58 100644 --- a/src/lgfx/v1/platforms/samd21/Bus_SPI.cpp +++ b/src/lgfx/v1/platforms/samd21/Bus_SPI.cpp @@ -27,13 +27,13 @@ namespace lgfx { //---------------------------------------------------------------------------- - std::uint32_t Bus_SPI::FreqToClockDiv(std::uint32_t freq) + uint32_t Bus_SPI::FreqToClockDiv(uint32_t freq) { - std::uint32_t div = std::min(255, _cfg.sercom_clkfreq / (1+(freq<<1))); + uint32_t div = std::min(255, _cfg.sercom_clkfreq / (1+(freq<<1))); return div; } - void Bus_SPI::setFreqDiv(std::uint32_t div) + void Bus_SPI::setFreqDiv(uint32_t div) { auto *spi = &_sercom->SPI; while (spi->SYNCBUSY.reg); @@ -53,7 +53,7 @@ namespace lgfx _sercom = reinterpret_cast(samd21::getSercomData(_cfg.sercom_index)->sercomPtr); _last_apb_freq = -1; _mask_reg_dc = 0; - std::uint32_t port = 0; + uint32_t port = 0; if (_cfg.pin_dc >= 0) { _mask_reg_dc = (1ul << (_cfg.pin_dc & (samd21::PIN_MASK))); @@ -122,7 +122,7 @@ namespace lgfx return _need_wait && (_sercom->SPI.INTFLAG.bit.TXC == 0); } - bool Bus_SPI::writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) + bool Bus_SPI::writeCommand(uint32_t data, uint_fast8_t bit_length) { bit_length >>= 3; auto *spi = &_sercom->SPI; @@ -142,7 +142,7 @@ namespace lgfx return true; } - void Bus_SPI::writeData(std::uint32_t data, std::uint_fast8_t bit_length) + void Bus_SPI::writeData(uint32_t data, uint_fast8_t bit_length) { bit_length >>= 3; auto *spi = &_sercom->SPI; @@ -161,16 +161,16 @@ namespace lgfx } } - void Bus_SPI::writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t length) + void Bus_SPI::writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t length) { - std::size_t bits = bit_length & ~7; + size_t bits = bit_length & ~7; auto *spi = &_sercom->SPI; dc_control(true); _need_wait = true; - std::size_t i = 0; + size_t i = 0; for (;;) { - std::size_t tmp = data >> i; + size_t tmp = data >> i; i += 8; while (spi->INTFLAG.bit.DRE == 0); spi->DATA.reg = tmp; @@ -180,16 +180,16 @@ namespace lgfx } } - void Bus_SPI::writePixels(pixelcopy_t* param, std::uint32_t length) + void Bus_SPI::writePixels(pixelcopy_t* param, uint32_t length) { - const std::uint8_t bytes = param->dst_bits >> 3; + const uint8_t bytes = param->dst_bits >> 3; auto *spi = &_sercom->SPI; - std::uint32_t data; - param->fp_copy((std::uint8_t*)&data, 0, 1, param); + uint32_t data; + param->fp_copy((uint8_t*)&data, 0, 1, param); dc_control(true); spi->DATA.reg = data; _need_wait = true; - std::uint32_t i = 0; + uint32_t i = 0; while (++i != bytes) { while (spi->INTFLAG.bit.DRE == 0); @@ -197,18 +197,21 @@ namespace lgfx } if (--length) { - param->fp_copy((std::uint8_t*)&data, 0, 1, param); - i = 0; do { - std::uint32_t tmp = data >> (i << 3); - while (spi->INTFLAG.bit.DRE == 0); - spi->DATA.reg = tmp; - } while (++i != bytes); - } while (--length); + param->fp_copy((uint8_t*)&data, 0, 1, param); + i = 0; + do + { + uint32_t tmp = data >> (i << 3); + while (spi->INTFLAG.bit.DRE == 0); + spi->DATA.reg = tmp; + } while (++i != bytes); + } while (--length); + } } - void Bus_SPI::writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) + void Bus_SPI::writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) { auto *spi = &_sercom->SPI; dc_control(dc); @@ -216,16 +219,16 @@ namespace lgfx _need_wait = true; while (--length) { - std::uint32_t tmp = *++data; + uint32_t tmp = *++data; while (spi->INTFLAG.bit.DRE == 0); spi->DATA.reg = tmp; } } - std::uint32_t Bus_SPI::readData(std::uint_fast8_t bit_length) + uint32_t Bus_SPI::readData(uint_fast8_t bit_length) { auto *spi = &_sercom->SPI; - std::uint32_t res = 0; + uint32_t res = 0; bit_length >>= 3; if (!bit_length) return res; int idx = 0; @@ -239,14 +242,14 @@ namespace lgfx return res; } - bool Bus_SPI::readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma) + bool Bus_SPI::readBytes(uint8_t* dst, uint32_t length, bool use_dma) { auto *spi = &_sercom->SPI; spi->DATA.reg = 0; while (--length) { while (spi->INTFLAG.bit.RXC == 0); - std::uint_fast8_t tmp = spi->DATA.reg; + uint_fast8_t tmp = spi->DATA.reg; spi->DATA.reg = 0; *dst++ = tmp; } @@ -255,16 +258,16 @@ namespace lgfx return true; } - void Bus_SPI::readPixels(void* dst, pixelcopy_t* param, std::uint32_t length) + void Bus_SPI::readPixels(void* dst, pixelcopy_t* param, uint32_t length) { - std::uint32_t bytes = param->src_bits >> 3; - std::uint32_t dstindex = 0; - std::uint32_t len = 4; - std::uint8_t buf[24]; + uint32_t bytes = param->src_bits >> 3; + uint32_t dstindex = 0; + uint32_t len = 4; + uint8_t buf[24]; param->src_data = buf; do { if (len > length) len = length; - readBytes((std::uint8_t*)buf, len * bytes, true); + readBytes((uint8_t*)buf, len * bytes, true); param->src_x = 0; dstindex = param->fp_copy(dst, dstindex, dstindex + len, param); length -= len; diff --git a/src/lgfx/v1/platforms/samd21/Bus_SPI.hpp b/src/lgfx/v1/platforms/samd21/Bus_SPI.hpp index ac44fc3..7177ef7 100644 --- a/src/lgfx/v1/platforms/samd21/Bus_SPI.hpp +++ b/src/lgfx/v1/platforms/samd21/Bus_SPI.hpp @@ -22,7 +22,7 @@ Original Source: #endif #include -#include +#include #include "../../Bus.hpp" #include "../common.hpp" @@ -38,19 +38,19 @@ namespace lgfx public: struct config_t { - std::uint8_t sercom_index = 7; - std::int8_t sercom_clksrc = 0; // -1=notchange / 0=select GCLK0 - std::uint32_t sercom_clkfreq = F_CPU; + uint8_t sercom_index = 7; + int8_t sercom_clksrc = 0; // -1=notchange / 0=select GCLK0 + uint32_t sercom_clkfreq = F_CPU; - std::uint32_t freq_write = 16000000; - std::uint32_t freq_read = 8000000; + uint32_t freq_write = 16000000; + uint32_t freq_read = 8000000; //bool spi_3wire = true; //bool use_lock = true; - std::int16_t pin_sclk = samd21::PORT_B | 20; - std::int16_t pin_miso = samd21::PORT_B | 18; - std::int16_t pin_mosi = samd21::PORT_B | 19; - std::int16_t pin_dc = -1; - std::uint8_t spi_mode = 0; + int16_t pin_sclk = samd21::PORT_B | 20; + int16_t pin_miso = samd21::PORT_B | 18; + int16_t pin_mosi = samd21::PORT_B | 19; + int16_t pin_dc = -1; + uint8_t spi_mode = 0; }; @@ -69,27 +69,27 @@ namespace lgfx bool busy(void) const override; void flush(void) override {} - bool writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) override; - void writeData(std::uint32_t data, std::uint_fast8_t bit_length) override; - void writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t count) override; - void writePixels(pixelcopy_t* param, std::uint32_t length) override; - void writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) override; + bool writeCommand(uint32_t data, uint_fast8_t bit_length) override; + void writeData(uint32_t data, uint_fast8_t bit_length) override; + void writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t count) override; + void writePixels(pixelcopy_t* param, uint32_t length) override; + void writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) override; void initDMA(void) {} - void addDMAQueue(const std::uint8_t* data, std::uint32_t length) override { writeBytes(data, length, true, true); } + void addDMAQueue(const uint8_t* data, uint32_t length) override { writeBytes(data, length, true, true); } void execDMAQueue(void) {} - std::uint8_t* getDMABuffer(std::uint32_t length) override { return _flip_buffer.getBuffer(length); } + uint8_t* getDMABuffer(uint32_t length) override { return _flip_buffer.getBuffer(length); } void beginRead(void) override; void endRead(void) override; - std::uint32_t readData(std::uint_fast8_t bit_length) override; - bool readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma) override; - void readPixels(void* dst, pixelcopy_t* param, std::uint32_t length) override; + uint32_t readData(uint_fast8_t bit_length) override; + bool readBytes(uint8_t* dst, uint32_t length, bool use_dma) override; + void readPixels(void* dst, pixelcopy_t* param, uint32_t length) override; private: - std::uint32_t FreqToClockDiv(std::uint32_t freq); - void setFreqDiv(std::uint32_t div); + uint32_t FreqToClockDiv(uint32_t freq); + void setFreqDiv(uint32_t div); __attribute__ ((always_inline)) inline void set_clock_write(void) { setFreqDiv(_clkdiv_write); } __attribute__ ((always_inline)) inline void set_clock_read(void) { setFreqDiv(_clkdiv_read ); } @@ -106,12 +106,12 @@ namespace lgfx FlipBuffer _flip_buffer; bool _need_wait = false; Sercom* _sercom = nullptr; - std::uint32_t _mask_reg_dc; - std::uint32_t _last_apb_freq = -1; - std::uint32_t _clkdiv_write; - std::uint32_t _clkdiv_read; - volatile std::uint32_t* _gpio_reg_dc_h; - volatile std::uint32_t* _gpio_reg_dc_l; + uint32_t _mask_reg_dc; + uint32_t _last_apb_freq = -1; + uint32_t _clkdiv_write; + uint32_t _clkdiv_read; + volatile uint32_t* _gpio_reg_dc_h; + volatile uint32_t* _gpio_reg_dc_l; #if defined (ARDUINO) Adafruit_ZeroDMA _dma_adafruit; diff --git a/src/lgfx/v1/platforms/samd21/common.cpp b/src/lgfx/v1/platforms/samd21/common.cpp index 072d36b..14edcf5 100644 --- a/src/lgfx/v1/platforms/samd21/common.cpp +++ b/src/lgfx/v1/platforms/samd21/common.cpp @@ -32,8 +32,8 @@ namespace lgfx namespace samd21 { - static constexpr std::int8_t sercom_pin_list_end = 0; - static constexpr std::int8_t sercom0_c_pin_list[] = + static constexpr int8_t sercom_pin_list_end = 0; + static constexpr int8_t sercom0_c_pin_list[] = { PORT_A | 8 // PAD 0 MUX C , - 1 , PORT_A | 9 // PAD 1 MUX C @@ -43,7 +43,7 @@ namespace lgfx , PORT_A | 11 // PAD 3 MUX C , sercom_pin_list_end }; - static constexpr std::int8_t sercom0_d_pin_list[] = + static constexpr int8_t sercom0_d_pin_list[] = { PORT_A | 4 // PAD 0 MUX D , - 1 , PORT_A | 5 // PAD 1 MUX D @@ -54,7 +54,7 @@ namespace lgfx , sercom_pin_list_end }; - static constexpr std::int8_t sercom1_c_pin_list[] = + static constexpr int8_t sercom1_c_pin_list[] = { PORT_A | 16 // PAD 0 MUX C , - 1 , PORT_A | 17 // PAD 1 MUX C @@ -64,7 +64,7 @@ namespace lgfx , PORT_A | 19 // PAD 3 MUX C , sercom_pin_list_end }; - static constexpr std::int8_t sercom1_d_pin_list[] = + static constexpr int8_t sercom1_d_pin_list[] = { PORT_A | 0 // PAD 0 MUX D , - 1 , PORT_A | 1 // PAD 1 MUX D @@ -75,7 +75,7 @@ namespace lgfx , sercom_pin_list_end }; - static constexpr std::int8_t sercom2_c_pin_list[] = + static constexpr int8_t sercom2_c_pin_list[] = { PORT_A | 12 // PAD 0 MUX C , - 1 , PORT_A | 13 // PAD 1 MUX C @@ -85,7 +85,7 @@ namespace lgfx , PORT_A | 15 // PAD 3 MUX C , sercom_pin_list_end }; - static constexpr std::int8_t sercom2_d_pin_list[] = + static constexpr int8_t sercom2_d_pin_list[] = { PORT_A | 8 // PAD 0 MUX D , - 1 , PORT_A | 9 // PAD 1 MUX D @@ -96,7 +96,7 @@ namespace lgfx , sercom_pin_list_end }; - static constexpr std::int8_t sercom3_c_pin_list[] = + static constexpr int8_t sercom3_c_pin_list[] = { PORT_A | 22 // PAD 0 MUX C , - 1 , PORT_A | 23 // PAD 1 MUX C @@ -106,7 +106,7 @@ namespace lgfx , PORT_A | 25 // PAD 3 MUX C , sercom_pin_list_end }; - static constexpr std::int8_t sercom3_d_pin_list[] = + static constexpr int8_t sercom3_d_pin_list[] = { PORT_A | 16 // PAD 0 MUX D , - 1 , PORT_A | 17 // PAD 1 MUX D @@ -119,7 +119,7 @@ namespace lgfx , sercom_pin_list_end }; #if SERCOM_INST_NUM > 4 - static constexpr std::int8_t sercom4_c_pin_list[] = + static constexpr int8_t sercom4_c_pin_list[] = { PORT_B | 12 // PAD 0 MUX C , - 1 , PORT_B | 13 // PAD 1 MUX C @@ -129,7 +129,7 @@ namespace lgfx , PORT_B | 15 // PAD 3 MUX C , sercom_pin_list_end }; - static constexpr std::int8_t sercom4_d_pin_list[] = + static constexpr int8_t sercom4_d_pin_list[] = { PORT_A | 12 // PAD 0 MUX D , PORT_B | 8 // PAD 0 MUX D , - 1 @@ -145,7 +145,7 @@ namespace lgfx }; #endif #if SERCOM_INST_NUM > 5 - static constexpr std::int8_t sercom5_c_pin_list[] = + static constexpr int8_t sercom5_c_pin_list[] = { PORT_B | 16 // PAD 0 MUX C , - 1 , PORT_B | 17 // PAD 1 MUX C @@ -155,7 +155,7 @@ namespace lgfx , PORT_A | 21 // PAD 3 MUX C , sercom_pin_list_end }; - static constexpr std::int8_t sercom5_d_pin_list[] = + static constexpr int8_t sercom5_d_pin_list[] = { PORT_A | 22 // PAD 0 MUX D , PORT_B | 2 // PAD 0 MUX D , PORT_B | 30 // PAD 0 MUX D @@ -174,7 +174,7 @@ namespace lgfx , sercom_pin_list_end }; #endif - static constexpr const std::int8_t* sercom_mux_pin_list[2][SERCOM_INST_NUM] = + static constexpr const int8_t* sercom_mux_pin_list[2][SERCOM_INST_NUM] = { { sercom0_c_pin_list , sercom1_c_pin_list @@ -213,7 +213,7 @@ namespace lgfx { (uintptr_t)SERCOM5, GCM_SERCOM5_CORE, SERCOM5_IRQn }, #endif }; - const sercom_data_t* getSercomData(std::size_t sercom_index) + const sercom_data_t* getSercomData(size_t sercom_index) { return &sercom_data[sercom_index]; } @@ -225,7 +225,7 @@ namespace lgfx auto spl = samd21::sercom_mux_pin_list[alt][sercom_index]; int pad = 0; int tmp = spl[0]; - std::size_t idx = 0; + size_t idx = 0; do { if (pin == tmp) return pad; @@ -237,9 +237,9 @@ namespace lgfx void pinAssignPeriph(int pin_and_port, int type) { if (pin_and_port < 0) return; - std::uint_fast8_t port = (pin_and_port >> samd21::PORT_SHIFT); - std::uint_fast8_t pin = pin_and_port & (samd21::PIN_MASK); - std::uint32_t temp = PORT->Group[port].PMUX[pin >> 1].reg; + uint_fast8_t port = (pin_and_port >> samd21::PORT_SHIFT); + uint_fast8_t pin = pin_and_port & (samd21::PIN_MASK); + uint32_t temp = PORT->Group[port].PMUX[pin >> 1].reg; if (pin&1) temp = PORT_PMUX_PMUXO( type ) | (temp & PORT_PMUX_PMUXE( 0xF )); else temp = PORT_PMUX_PMUXE( type ) | (temp & PORT_PMUX_PMUXO( 0xF )); @@ -249,9 +249,9 @@ namespace lgfx //---------------------------------------------------------------------------- - void pinMode(std::int_fast16_t pin, pin_mode_t mode) + void pinMode(int_fast16_t pin, pin_mode_t mode) { - std::size_t port = pin >> samd21::PORT_SHIFT; + size_t port = pin >> samd21::PORT_SHIFT; if (port >= 2) return; pin &= samd21::PIN_MASK; @@ -288,7 +288,7 @@ namespace lgfx { cpp::result init(int sercom_index, int pin_sclk, int pin_miso, int pin_mosi) { - if ((std::size_t)sercom_index >= SERCOM_INST_NUM) { return cpp::fail(error_t::invalid_arg); } + if ((size_t)sercom_index >= SERCOM_INST_NUM) { return cpp::fail(error_t::invalid_arg); } int dipo = -1; int dopo = -1; @@ -405,12 +405,12 @@ namespace lgfx while (sercom->SPI.CTRLA.bit.SWRST || sercom->SPI.SYNCBUSY.bit.SWRST); } - static std::uint32_t FreqToClockDiv(std::uint32_t hz) + static uint32_t FreqToClockDiv(uint32_t hz) { return (SERCOM_SPI_FREQ_REF >> 1) / (1 + hz); } - void beginTransaction(int sercom_index, std::uint32_t freq, int spi_mode) + void beginTransaction(int sercom_index, uint32_t freq, int spi_mode) { auto sercomData = samd21::getSercomData(sercom_index); auto sercom = reinterpret_cast(sercomData->sercomPtr); @@ -431,11 +431,11 @@ namespace lgfx { } - void writeBytes(int spi_host, const std::uint8_t* data, std::size_t length) + void writeBytes(int spi_host, const uint8_t* data, size_t length) { } - void readBytes(int spi_host, std::uint8_t* data, std::size_t length) + void readBytes(int spi_host, uint8_t* data, size_t length) { } @@ -447,7 +447,7 @@ namespace lgfx { cpp::result init(int sercom_index, int pin_sda, int pin_scl) { - if ((std::size_t)sercom_index >= SERCOM_INST_NUM) { return cpp::fail(error_t::invalid_arg); } + if ((size_t)sercom_index >= SERCOM_INST_NUM) { return cpp::fail(error_t::invalid_arg); } int pad_sda; int pad_scl; @@ -478,12 +478,12 @@ namespace lgfx return {}; } - cpp::result restart(int sercom_index, int i2c_addr, std::uint32_t freq, bool read) + cpp::result restart(int sercom_index, int i2c_addr, uint32_t freq, bool read) { return {}; } - cpp::result beginTransaction(int sercom_index, int i2c_addr, std::uint32_t freq, bool read) + cpp::result beginTransaction(int sercom_index, int i2c_addr, uint32_t freq, bool read) { if (!read) { @@ -499,18 +499,18 @@ namespace lgfx return {}; } - cpp::result writeBytes(int sercom_index, const std::uint8_t *data, std::size_t length) + cpp::result writeBytes(int sercom_index, const uint8_t *data, size_t length) { Wire.write(data, length); return {}; } - cpp::result readBytes(int sercom_index, std::uint8_t *data, std::size_t length) + cpp::result readBytes(int sercom_index, uint8_t *data, size_t length) { return {}; } - cpp::result transactionWrite(int sercom_index, int addr, const std::uint8_t *writedata, std::uint8_t writelen, std::uint32_t freq) + cpp::result transactionWrite(int sercom_index, int addr, const uint8_t *writedata, uint8_t writelen, uint32_t freq) { cpp::result res; if ((res = beginTransaction(sercom_index, addr, freq, false)).has_value() @@ -522,7 +522,7 @@ namespace lgfx return res; } - cpp::result transactionRead(int sercom_index, int addr, std::uint8_t *readdata, std::uint8_t readlen, std::uint32_t freq) + cpp::result transactionRead(int sercom_index, int addr, uint8_t *readdata, uint8_t readlen, uint32_t freq) { cpp::result res; if ((res = beginTransaction(sercom_index, addr, freq, true)).has_value() @@ -534,7 +534,7 @@ namespace lgfx return res; } - cpp::result transactionWriteRead(int sercom_index, int addr, const std::uint8_t *writedata, std::uint8_t writelen, std::uint8_t *readdata, std::size_t readlen, std::uint32_t freq) + cpp::result transactionWriteRead(int sercom_index, int addr, const uint8_t *writedata, uint8_t writelen, uint8_t *readdata, size_t readlen, uint32_t freq) { cpp::result res; if ((res = beginTransaction(sercom_index, addr, freq, false)).has_value() @@ -548,16 +548,16 @@ namespace lgfx return res; } - cpp::result readRegister8(int sercom_index, int addr, std::uint8_t reg, std::uint32_t freq) + cpp::result readRegister8(int sercom_index, int addr, uint8_t reg, uint32_t freq) { auto res = transactionWriteRead(sercom_index, addr, ®, 1, ®, 1, freq); if (res.has_value()) { return reg; } return cpp::fail( res.error() ); } - cpp::result writeRegister8(int sercom_index, int addr, std::uint8_t reg, std::uint8_t data, std::uint8_t mask, std::uint32_t freq) + cpp::result writeRegister8(int sercom_index, int addr, uint8_t reg, uint8_t data, uint8_t mask, uint32_t freq) { - std::uint8_t tmp[2] = { reg, data }; + uint8_t tmp[2] = { reg, data }; if (mask) { auto res = transactionWriteRead(sercom_index, addr, ®, 1, &tmp[1], 1, freq); diff --git a/src/lgfx/v1/platforms/samd21/common.hpp b/src/lgfx/v1/platforms/samd21/common.hpp index c3e5fc4..d4f8206 100644 --- a/src/lgfx/v1/platforms/samd21/common.hpp +++ b/src/lgfx/v1/platforms/samd21/common.hpp @@ -48,11 +48,11 @@ namespace lgfx }; struct sercom_data_t { - std::uintptr_t sercomPtr; + uintptr_t sercomPtr; uint8_t clock; IRQn_Type irqn; }; - const sercom_data_t* getSercomData(std::size_t sercom_number); + const sercom_data_t* getSercomData(size_t sercom_number); } #if defined ( ARDUINO ) @@ -80,7 +80,7 @@ namespace lgfx #else - static inline void delay(std::size_t milliseconds) + static inline void delay(size_t milliseconds) { vTaskDelay(pdMS_TO_TICKS(milliseconds)); } @@ -109,9 +109,9 @@ namespace lgfx static inline void* heap_alloc_dma( size_t length) { return memalign(16, length); } static inline void heap_free(void* buf) { free(buf); } - static inline void gpio_hi(std::uint32_t pin) { if (pin > 255) return; PORT->Group[pin >> samd21::PORT_SHIFT].OUTSET.reg = (1ul << (pin & samd21::PIN_MASK)); } - static inline void gpio_lo(std::uint32_t pin) { if (pin > 255) return; PORT->Group[pin >> samd21::PORT_SHIFT].OUTCLR.reg = (1ul << (pin & samd21::PIN_MASK)); } - static inline bool gpio_in(std::uint32_t pin) { if (pin > 255) return false; return PORT->Group[pin >> samd21::PORT_SHIFT].IN.reg & (1ul << (pin & samd21::PIN_MASK)); } + static inline void gpio_hi(uint32_t pin) { if (pin > 255) return; PORT->Group[pin >> samd21::PORT_SHIFT].OUTSET.reg = (1ul << (pin & samd21::PIN_MASK)); } + static inline void gpio_lo(uint32_t pin) { if (pin > 255) return; PORT->Group[pin >> samd21::PORT_SHIFT].OUTCLR.reg = (1ul << (pin & samd21::PIN_MASK)); } + static inline bool gpio_in(uint32_t pin) { if (pin > 255) return false; return PORT->Group[pin >> samd21::PORT_SHIFT].IN.reg & (1ul << (pin & samd21::PIN_MASK)); } enum pin_mode_t { output @@ -120,8 +120,8 @@ namespace lgfx , input_pulldown }; - void pinMode(std::int_fast16_t pin, pin_mode_t mode); - inline void lgfxPinMode(std::int_fast16_t pin, pin_mode_t mode) + void pinMode(int_fast16_t pin, pin_mode_t mode); + inline void lgfxPinMode(int_fast16_t pin, pin_mode_t mode) { pinMode(pin, mode); } @@ -161,22 +161,22 @@ namespace lgfx return _file; } - int read(std::uint8_t *buf, std::uint32_t len) override { return _fp->read(buf, len); } - void skip(std::int32_t offset) override { seek(offset, SeekCur); } - bool seek(std::uint32_t offset) override { return seek(offset, SeekSet); } - bool seek(std::uint32_t offset, SeekMode mode) { return _fp->seek(offset, mode); } + int read(uint8_t *buf, uint32_t len) override { return _fp->read(buf, len); } + void skip(int32_t offset) override { seek(offset, SeekCur); } + bool seek(uint32_t offset) override { return seek(offset, SeekSet); } + bool seek(uint32_t offset, SeekMode mode) { return _fp->seek(offset, mode); } void close(void) override { if (_fp) _fp->close(); } - std::int32_t tell(void) override { return _fp->position(); } + int32_t tell(void) override { return _fp->position(); } #else // dummy. bool open(const char*) override { return false; } - int read(std::uint8_t*, std::uint32_t) override { return 0; } - void skip(std::int32_t) override { } - bool seek(std::uint32_t) override { return false; } - bool seek(std::uint32_t, int) { return false; } + int read(uint8_t*, uint32_t) override { return 0; } + void skip(int32_t) override { } + bool seek(uint32_t) override { return false; } + bool seek(uint32_t, int) { return false; } void close() override { } - std::int32_t tell(void) override { return 0; } + int32_t tell(void) override { return 0; } #endif @@ -188,22 +188,22 @@ namespace lgfx struct StreamWrapper : public DataWrapper { - void set(Stream* src, std::uint32_t length = ~0u) { _stream = src; _length = length; _index = 0; } + void set(Stream* src, uint32_t length = ~0u) { _stream = src; _length = length; _index = 0; } - int read(std::uint8_t *buf, std::uint32_t len) override { + int read(uint8_t *buf, uint32_t len) override { if (len > _length - _index) { len = _length - _index; } _index += len; return _stream->readBytes((char*)buf, len); } - void skip(std::int32_t offset) override { if (0 < offset) { char dummy[offset]; _stream->readBytes(dummy, offset); _index += offset; } } - bool seek(std::uint32_t offset) override { if (offset < _index) { return false; } skip(offset - _index); return true; } + void skip(int32_t offset) override { if (0 < offset) { char dummy[offset]; _stream->readBytes(dummy, offset); _index += offset; } } + bool seek(uint32_t offset) override { if (offset < _index) { return false; } skip(offset - _index); return true; } void close() override { } - std::int32_t tell(void) override { return _index; } + int32_t tell(void) override { return _index; } private: Stream* _stream; - std::uint32_t _index; - std::uint32_t _length = 0; + uint32_t _index; + uint32_t _length = 0; }; diff --git a/src/lgfx/v1/platforms/samd51/Bus_I2C.cpp b/src/lgfx/v1/platforms/samd51/Bus_I2C.cpp index 0c6829f..a9cba46 100644 --- a/src/lgfx/v1/platforms/samd51/Bus_I2C.cpp +++ b/src/lgfx/v1/platforms/samd51/Bus_I2C.cpp @@ -135,29 +135,29 @@ namespace lgfx lgfx::i2c::endTransaction(_cfg.i2c_port); lgfx::i2c::beginTransaction(_cfg.i2c_port, _cfg.i2c_addr, _cfg.freq_write, false); } - lgfx::i2c::writeBytes(_cfg.i2c_port, (std::uint8_t*)(dc ? &_cfg.prefix_data : &_cfg.prefix_cmd), _cfg.prefix_len); + lgfx::i2c::writeBytes(_cfg.i2c_port, (uint8_t*)(dc ? &_cfg.prefix_data : &_cfg.prefix_cmd), _cfg.prefix_len); _state = st; } - bool Bus_I2C::writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) + bool Bus_I2C::writeCommand(uint32_t data, uint_fast8_t bit_length) { dc_control(false); - return lgfx::i2c::writeBytes(_cfg.i2c_port, (std::uint8_t*)&data, (bit_length >> 3)).has_value(); + return lgfx::i2c::writeBytes(_cfg.i2c_port, (uint8_t*)&data, (bit_length >> 3)).has_value(); } - void Bus_I2C::writeData(std::uint32_t data, std::uint_fast8_t bit_length) + void Bus_I2C::writeData(uint32_t data, uint_fast8_t bit_length) { dc_control(true); - lgfx::i2c::writeBytes(_cfg.i2c_port, (std::uint8_t*)&data, (bit_length >> 3)); + lgfx::i2c::writeBytes(_cfg.i2c_port, (uint8_t*)&data, (bit_length >> 3)); } - void Bus_I2C::writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t length) + void Bus_I2C::writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t length) { dc_control(true); - const std::uint8_t dst_bytes = bit_length >> 3; - std::uint32_t buf0 = data | data << bit_length; - std::uint32_t buf1; - std::uint32_t buf2; + const uint8_t dst_bytes = bit_length >> 3; + uint32_t buf0 = data | data << bit_length; + uint32_t buf1; + uint32_t buf2; // make 12Bytes data. if (dst_bytes != 3) { @@ -173,10 +173,10 @@ namespace lgfx buf1 = buf0 >> 8 | buf0 << 16; buf2 = buf0 >> 16 | buf0 << 8; } - std::uint32_t src[8] = { buf0, buf1, buf2, buf0, buf1, buf2, buf0, buf1 }; - auto buf = reinterpret_cast(src); - std::uint32_t limit = 32 / dst_bytes; - std::uint32_t len; + uint32_t src[8] = { buf0, buf1, buf2, buf0, buf1, buf2, buf0, buf1 }; + auto buf = reinterpret_cast(src); + uint32_t limit = 32 / dst_bytes; + uint32_t len; do { len = ((length - 1) % limit) + 1; @@ -184,13 +184,13 @@ namespace lgfx } while (length -= len); } - void Bus_I2C::writePixels(pixelcopy_t* param, std::uint32_t length) + void Bus_I2C::writePixels(pixelcopy_t* param, uint32_t length) { dc_control(true); - const std::uint8_t dst_bytes = param->dst_bits >> 3; - std::uint32_t limit = 32 / dst_bytes; - std::uint32_t len; - std::uint8_t buf[32]; + const uint8_t dst_bytes = param->dst_bits >> 3; + uint32_t limit = 32 / dst_bytes; + uint32_t len; + uint8_t buf[32]; do { len = ((length - 1) % limit) + 1; @@ -199,39 +199,39 @@ namespace lgfx } while (length -= len); } - void Bus_I2C::writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) + void Bus_I2C::writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) { dc_control(dc); i2c::writeBytes(_cfg.i2c_port, data, length); } - std::uint32_t Bus_I2C::readData(std::uint_fast8_t bit_length) + uint32_t Bus_I2C::readData(uint_fast8_t bit_length) { beginRead(); - std::uint32_t res; - i2c::readBytes(_cfg.i2c_port, reinterpret_cast(&res), bit_length >> 3); + uint32_t res; + i2c::readBytes(_cfg.i2c_port, reinterpret_cast(&res), bit_length >> 3); return res; } - bool Bus_I2C::readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma) + bool Bus_I2C::readBytes(uint8_t* dst, uint32_t length, bool use_dma) { beginRead(); return i2c::readBytes(_cfg.i2c_port, dst, length).has_value(); } - void Bus_I2C::readPixels(void* dst, pixelcopy_t* param, std::uint32_t length) + void Bus_I2C::readPixels(void* dst, pixelcopy_t* param, uint32_t length) { beginRead(); const auto bytes = param->src_bits >> 3; - std::uint32_t regbuf[8]; - std::uint32_t limit = 32 / bytes; + uint32_t regbuf[8]; + uint32_t limit = 32 / bytes; param->src_data = regbuf; - std::int32_t dstindex = 0; + int32_t dstindex = 0; do { - std::uint32_t len = (limit > length) ? length : limit; + uint32_t len = (limit > length) ? length : limit; length -= len; - i2c::readBytes(_cfg.i2c_port, (std::uint8_t*)regbuf, len * bytes); + i2c::readBytes(_cfg.i2c_port, (uint8_t*)regbuf, len * bytes); param->src_x = 0; dstindex = param->fp_copy(dst, dstindex, dstindex + len, param); } while (length); diff --git a/src/lgfx/v1/platforms/samd51/Bus_I2C.hpp b/src/lgfx/v1/platforms/samd51/Bus_I2C.hpp index 6ad5582..04e4eef 100644 --- a/src/lgfx/v1/platforms/samd51/Bus_I2C.hpp +++ b/src/lgfx/v1/platforms/samd51/Bus_I2C.hpp @@ -31,15 +31,15 @@ namespace lgfx public: struct config_t { - std::uint32_t freq_write = 400000; - std::uint32_t freq_read = 400000; - std::int16_t pin_scl ; - std::int16_t pin_sda ; - std::uint8_t i2c_port ; - std::uint8_t i2c_addr ; - std::uint32_t prefix_cmd = 0x00; - std::uint32_t prefix_data = 0x40; - std::uint32_t prefix_len = 1; + uint32_t freq_write = 400000; + uint32_t freq_read = 400000; + int16_t pin_scl ; + int16_t pin_sda ; + uint8_t i2c_port ; + uint8_t i2c_addr ; + uint32_t prefix_cmd = 0x00; + uint32_t prefix_data = 0x40; + uint32_t prefix_len = 1; }; const config_t& config(void) const { return _cfg; } @@ -57,22 +57,22 @@ namespace lgfx bool busy(void) const override; void flush(void) override {} - bool writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) override; - void writeData(std::uint32_t data, std::uint_fast8_t bit_length) override; - void writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t count) override; - void writePixels(pixelcopy_t* param, std::uint32_t length) override; - void writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) override; + bool writeCommand(uint32_t data, uint_fast8_t bit_length) override; + void writeData(uint32_t data, uint_fast8_t bit_length) override; + void writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t count) override; + void writePixels(pixelcopy_t* param, uint32_t length) override; + void writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) override; void initDMA(void) {} - void addDMAQueue(const std::uint8_t* data, std::uint32_t length) override { writeBytes(data, length, true, true); } + void addDMAQueue(const uint8_t* data, uint32_t length) override { writeBytes(data, length, true, true); } void execDMAQueue(void) {} - std::uint8_t* getDMABuffer(std::uint32_t length) override { return _flip_buffer.getBuffer(length); } + uint8_t* getDMABuffer(uint32_t length) override { return _flip_buffer.getBuffer(length); } void beginRead(void) override; void endRead(void) override; - std::uint32_t readData(std::uint_fast8_t bit_length) override; - bool readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma) override; - void readPixels(void* dst, pixelcopy_t* param, std::uint32_t length) override; + uint32_t readData(uint_fast8_t bit_length) override; + bool readBytes(uint8_t* dst, uint32_t length, bool use_dma) override; + void readPixels(void* dst, pixelcopy_t* param, uint32_t length) override; protected: diff --git a/src/lgfx/v1/platforms/samd51/Bus_SPI.cpp b/src/lgfx/v1/platforms/samd51/Bus_SPI.cpp index 45fd7d7..690d612 100644 --- a/src/lgfx/v1/platforms/samd51/Bus_SPI.cpp +++ b/src/lgfx/v1/platforms/samd51/Bus_SPI.cpp @@ -64,7 +64,7 @@ Original Source: #undef GCLK_PCHCTRL_CHEN_Pos #undef GCLK_PCHCTRL_CHEN - #define _Ul(n) (static_cast((n))) + #define _Ul(n) (static_cast((n))) #define PORT_PINCFG_PMUXEN_Pos 0 /**< \brief (PORT_PINCFG) Peripheral Multiplexer Enable */ #define PORT_PINCFG_PMUXEN (_Ul(0x1) << PORT_PINCFG_PMUXEN_Pos) #define PORT_PINCFG_INEN_Pos 1 /**< \brief (PORT_PINCFG) Input Enable */ @@ -75,7 +75,7 @@ Original Source: #define PORT_PINCFG_DRVSTR (_Ul(0x1) << PORT_PINCFG_DRVSTR_Pos) #define PORT_PINCFG_MASK _Ul(0x47) /**< \brief (PORT_PINCFG) MASK Register */ - typedef std::uint8_t SercomDataOrder; + typedef uint8_t SercomDataOrder; #define SERCOM_SPI_CTRLA_MODE_Pos 2 /**< \brief (SERCOM_SPI_CTRLA) Operating Mode */ #define SERCOM_SPI_CTRLA_MODE_Msk (_Ul(0x7) << SERCOM_SPI_CTRLA_MODE_Pos) #define SERCOM_SPI_CTRLA_MODE(value) (SERCOM_SPI_CTRLA_MODE_Msk & ((value) << SERCOM_SPI_CTRLA_MODE_Pos)) @@ -124,13 +124,13 @@ namespace lgfx while (spi->SYNCBUSY.bit.ENABLE); } //*/ - std::uint32_t Bus_SPI::FreqToClockDiv(std::uint32_t freq) + uint32_t Bus_SPI::FreqToClockDiv(uint32_t freq) { - std::uint32_t div = std::min(255, _cfg.sercom_clkfreq / (1+(freq<<1))); + uint32_t div = std::min(255, _cfg.sercom_clkfreq / (1+(freq<<1))); return div; } - void Bus_SPI::setFreqDiv(std::uint32_t div) + void Bus_SPI::setFreqDiv(uint32_t div) { auto *spi = &_sercom->SPI; while (spi->SYNCBUSY.reg); @@ -150,7 +150,7 @@ namespace lgfx _sercom = reinterpret_cast(samd51::getSercomData(_cfg.sercom_index)->sercomPtr); _last_apb_freq = -1; _mask_reg_dc = 0; - std::uint32_t port = 0; + uint32_t port = 0; if (_cfg.pin_dc >= 0) { _mask_reg_dc = (1ul << (_cfg.pin_dc & (samd51::PIN_MASK))); @@ -179,13 +179,13 @@ namespace lgfx if (_cfg.sercom_clksrc >= 0) { - std::uint8_t id_core = sercom_data->id_core; - std::uint8_t id_slow = sercom_data->id_slow; + uint8_t id_core = sercom_data->id_core; + uint8_t id_slow = sercom_data->id_slow; GCLK->PCHCTRL[id_core].bit.CHEN = 0; // Disable timer GCLK->PCHCTRL[id_slow].bit.CHEN = 0; // Disable timer - std::uint32_t gclk_reg_value = GCLK_PCHCTRL_CHEN | _cfg.sercom_clksrc << GCLK_PCHCTRL_GEN_Pos; + uint32_t gclk_reg_value = GCLK_PCHCTRL_CHEN | _cfg.sercom_clksrc << GCLK_PCHCTRL_GEN_Pos; while (GCLK->PCHCTRL[id_core].bit.CHEN || GCLK->PCHCTRL[id_slow].bit.CHEN); // Wait for disable @@ -221,7 +221,7 @@ namespace lgfx /* _alloc_dmadesc(4); - std::uint8_t channel = _dma_channel; + uint8_t channel = _dma_channel; #if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) PM->AHBMASK.bit.DMAC_ = 1; #elif defined(__SAMD51__) @@ -235,8 +235,8 @@ namespace lgfx DMAC->CTRL.bit.SWRST = 1; // Perform software reset // Initialize descriptor list addresses - DMAC->BASEADDR.bit.BASEADDR = (std::uint32_t)&_dmadesc[1]; - DMAC->WRBADDR.bit.WRBADDR = (std::uint32_t)&_dmadesc[0]; + DMAC->BASEADDR.bit.BASEADDR = (uint32_t)&_dmadesc[1]; + DMAC->WRBADDR.bit.WRBADDR = (uint32_t)&_dmadesc[0]; // Re-enable DMA controller with all priority levels DMAC->CTRL.reg = DMAC_CTRL_DMAENABLE | DMAC_CTRL_LVLEN(0xF); @@ -245,7 +245,7 @@ namespace lgfx #ifdef __SAMD51__ IRQn_Type irqs[] = { DMAC_0_IRQn, DMAC_1_IRQn, DMAC_2_IRQn, DMAC_3_IRQn, DMAC_4_IRQn }; - for(std::uint8_t i=0; i<(sizeof irqs / sizeof irqs[0]); i++) { + for(uint8_t i=0; i<(sizeof irqs / sizeof irqs[0]); i++) { NVIC_EnableIRQ(irqs[i]); NVIC_SetPriority(irqs[i], (1<<__NVIC_PRIO_BITS)-1); } @@ -308,7 +308,7 @@ namespace lgfx return _need_wait && (_sercom->SPI.INTFLAG.bit.TXC == 0); } - bool Bus_SPI::writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) + bool Bus_SPI::writeCommand(uint32_t data, uint_fast8_t bit_length) { auto *spi = &_sercom->SPI; dc_control(false); @@ -332,7 +332,7 @@ namespace lgfx return true; } - void Bus_SPI::writeData(std::uint32_t data, std::uint_fast8_t bit_length) + void Bus_SPI::writeData(uint32_t data, uint_fast8_t bit_length) { auto len = bit_length >> 3 | SERCOM_SPI_LENGTH_LENEN; auto *spi = &_sercom->SPI; @@ -349,9 +349,9 @@ namespace lgfx _need_wait = true; } - void Bus_SPI::writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t length) + void Bus_SPI::writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t length) { - std::size_t bytes = bit_length >> 3; + size_t bytes = bit_length >> 3; auto *spi = &_sercom->SPI; bool d32b = spi->CTRLC.bit.DATA32B; dc_control(true); @@ -387,7 +387,7 @@ namespace lgfx _need_wait = true; if (!--length) return; - std::uint32_t surplus = length & 3; + uint32_t surplus = length & 3; if (surplus) { length -= surplus; do { @@ -397,7 +397,7 @@ namespace lgfx if (!length) return; } - std::uint32_t buf[3]; + uint32_t buf[3]; buf[0] = data | data << 24; buf[1] = data >> 8 | data << 16; buf[2] = data >> 16 | data << 8; @@ -419,11 +419,11 @@ namespace lgfx } } - void Bus_SPI::writePixels(pixelcopy_t* param, std::uint32_t length) + void Bus_SPI::writePixels(pixelcopy_t* param, uint32_t length) { - const std::uint8_t dst_bytes = param->dst_bits >> 3; - std::uint32_t limit = (dst_bytes == 3) ? 12 : 16; - std::uint32_t len; + const uint8_t dst_bytes = param->dst_bits >> 3; + uint32_t limit = (dst_bytes == 3) ? 12 : 16; + uint32_t len; do { len = ((length - 1) % limit) + 1; @@ -435,15 +435,15 @@ namespace lgfx } while (length -= len); } - void Bus_SPI::writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) + void Bus_SPI::writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) { auto *spi = &_sercom->SPI; #if defined (ARDUINO) if (length > 31) { - std::uint_fast8_t beatsize = spi->CTRLC.bit.DATA32B ? 2 : 0; + uint_fast8_t beatsize = spi->CTRLC.bit.DATA32B ? 2 : 0; // If the data is 4 bytes aligned, the DATA32B can be enabled. - if ((bool)(beatsize) == ((length & 3) || ((std::uint32_t)data & 3))) + if ((bool)(beatsize) == ((length & 3) || ((uint32_t)data & 3))) { beatsize = 2 - beatsize; wait_spi(); @@ -456,11 +456,11 @@ namespace lgfx } auto desc = _dma_write_desc; - std::uint32_t len = length; + uint32_t len = length; dc_control(dc); spi->LENGTH.reg = 0; desc->BTCTRL.bit.BEATSIZE = beatsize; - desc->SRCADDR.reg = (std::uint32_t)data + length; + desc->SRCADDR.reg = (uint32_t)data + length; do { if (!use_dma) @@ -470,7 +470,7 @@ namespace lgfx memcpy(dmabuf, data, len); data += len; wait_spi(); - desc->SRCADDR.reg = (std::uint32_t)dmabuf + len; + desc->SRCADDR.reg = (uint32_t)dmabuf + len; } desc->BTCNT.reg = len >> beatsize; _dma_adafruit.startJob(); @@ -492,20 +492,20 @@ namespace lgfx if (length >= 4) { spi->LENGTH.reg = 0; - spi->DATA.reg = *(std::uint32_t*)data; + spi->DATA.reg = *(uint32_t*)data; data += 4; length -= 4; if (4 <= length) { do { while (spi->INTFLAG.bit.DRE == 0); - spi->DATA.reg = *(std::uint32_t*)data; + spi->DATA.reg = *(uint32_t*)data; data += 4; } while (4 <= (length -= 4)); } } _need_wait = true; if (length) { - std::uint32_t tmp = *(std::uint32_t*)data; + uint32_t tmp = *(uint32_t*)data; while (spi->INTFLAG.bit.TXC == 0); spi->LENGTH.reg = length | SERCOM_SPI_LENGTH_LENEN; spi->DATA.reg = tmp; @@ -523,21 +523,21 @@ namespace lgfx set_clock_write(); } - std::uint32_t Bus_SPI::readData(std::uint_fast8_t bit_length) + uint32_t Bus_SPI::readData(uint_fast8_t bit_length) { - std::uint32_t res = 0; - readBytes((std::uint8_t*)&res, bit_length >> 3, false); + uint32_t res = 0; + readBytes((uint8_t*)&res, bit_length >> 3, false); return res; // writeData(0, bit_length); // return _sercom->SPI.DATA.reg; } - bool Bus_SPI::readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma) + bool Bus_SPI::readBytes(uint8_t* dst, uint32_t length, bool use_dma) { /* if (use_dma && length > 16) { _sercom->SPI.LENGTH.reg = 0; - std::uint_fast8_t beatsize = _sercom->SPI.CTRLC.bit.DATA32B ? 2 : 0; + uint_fast8_t beatsize = _sercom->SPI.CTRLC.bit.DATA32B ? 2 : 0; if (beatsize && (length & 3)) { disableSPI(); beatsize = 0; @@ -554,8 +554,8 @@ namespace lgfx desc->BTCTRL.bit.DSTINC = true; // dstInc; desc->BTCTRL.bit.STEPSEL = 0; // DMA_STEPSEL_DST; // stepSel; desc->BTCTRL.bit.STEPSIZE = 0; // DMA_ADDRESS_INCREMENT_STEP_SIZE_1; // stepSize; - desc->DSTADDR.reg = (std::uint32_t)dst; - desc->SRCADDR.reg = (std::uint32_t)(&_sercom->SPI.DATA.reg); + desc->DSTADDR.reg = (uint32_t)dst; + desc->SRCADDR.reg = (uint32_t)(&_sercom->SPI.DATA.reg); if (desc->BTCTRL.bit.DSTINC) { if (desc->BTCTRL.bit.STEPSEL) { @@ -566,7 +566,7 @@ namespace lgfx } // _dma_adafruit.setTrigger(sercomData[CFG::sercom_index].dmac_id_rx); - //_dma_adafruit.changeDescriptor(desc, nullptr, const_cast(dst), length>>beatsize); + //_dma_adafruit.changeDescriptor(desc, nullptr, const_cast(dst), length>>beatsize); _dma_adafruit.startJob(); _need_wait = true; return; @@ -575,8 +575,8 @@ namespace lgfx auto *datreg = &_sercom->SPI.DATA.reg; auto *lenreg = &_sercom->SPI.LENGTH.reg; auto *intflag = &_sercom->SPI.INTFLAG.bit; - std::uint32_t len1 = length > 3 ? 4 : length; - std::uint32_t len2 = len1; + uint32_t len1 = length > 3 ? 4 : length; + uint32_t len2 = len1; wait_spi(); dst[0] = *datreg; *lenreg = len1 | SERCOM_SPI_LENGTH_LENEN; @@ -596,7 +596,7 @@ namespace lgfx } *datreg = 0; } - std::uint32_t d = *datreg; + uint32_t d = *datreg; memcpy(dst, &d, len2); dst += len2; } while (length); @@ -604,16 +604,16 @@ namespace lgfx return true; } - void Bus_SPI::readPixels(void* dst, pixelcopy_t* param, std::uint32_t length) + void Bus_SPI::readPixels(void* dst, pixelcopy_t* param, uint32_t length) { - std::uint32_t bytes = param->src_bits >> 3; - std::uint32_t dstindex = 0; - std::uint32_t len = 4; - std::uint8_t buf[24]; + uint32_t bytes = param->src_bits >> 3; + uint32_t dstindex = 0; + uint32_t len = 4; + uint8_t buf[24]; param->src_data = buf; do { if (len > length) len = length; - readBytes((std::uint8_t*)buf, len * bytes, true); + readBytes((uint8_t*)buf, len * bytes, true); param->src_x = 0; dstindex = param->fp_copy(dst, dstindex, dstindex + len, param); length -= len; diff --git a/src/lgfx/v1/platforms/samd51/Bus_SPI.hpp b/src/lgfx/v1/platforms/samd51/Bus_SPI.hpp index fa80b17..0382491 100644 --- a/src/lgfx/v1/platforms/samd51/Bus_SPI.hpp +++ b/src/lgfx/v1/platforms/samd51/Bus_SPI.hpp @@ -22,7 +22,7 @@ Original Source: #endif #include -#include +#include #include "../../Bus.hpp" #include "../common.hpp" @@ -38,19 +38,19 @@ namespace lgfx public: struct config_t { - std::uint8_t sercom_index = 7; - std::int8_t sercom_clksrc = 0; // -1=notchange / 0=select GCLK0 - std::uint32_t sercom_clkfreq = F_CPU; + uint8_t sercom_index = 7; + int8_t sercom_clksrc = 0; // -1=notchange / 0=select GCLK0 + uint32_t sercom_clkfreq = F_CPU; - std::uint32_t freq_write = 16000000; - std::uint32_t freq_read = 8000000; + uint32_t freq_write = 16000000; + uint32_t freq_read = 8000000; //bool spi_3wire = true; //bool use_lock = true; - std::int16_t pin_sclk = samd51::PORT_B | 20; - std::int16_t pin_miso = samd51::PORT_B | 18; - std::int16_t pin_mosi = samd51::PORT_B | 19; - std::int16_t pin_dc = -1; - std::uint8_t spi_mode = 0; + int16_t pin_sclk = samd51::PORT_B | 20; + int16_t pin_miso = samd51::PORT_B | 18; + int16_t pin_mosi = samd51::PORT_B | 19; + int16_t pin_dc = -1; + uint8_t spi_mode = 0; }; @@ -69,27 +69,27 @@ namespace lgfx bool busy(void) const override; void flush(void) override {} - bool writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) override; - void writeData(std::uint32_t data, std::uint_fast8_t bit_length) override; - void writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t count) override; - void writePixels(pixelcopy_t* param, std::uint32_t length) override; - void writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) override; + bool writeCommand(uint32_t data, uint_fast8_t bit_length) override; + void writeData(uint32_t data, uint_fast8_t bit_length) override; + void writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t count) override; + void writePixels(pixelcopy_t* param, uint32_t length) override; + void writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) override; void initDMA(void) {} - void addDMAQueue(const std::uint8_t* data, std::uint32_t length) override { writeBytes(data, length, true, true); } + void addDMAQueue(const uint8_t* data, uint32_t length) override { writeBytes(data, length, true, true); } void execDMAQueue(void) {} - std::uint8_t* getDMABuffer(std::uint32_t length) override { return _flip_buffer.getBuffer(length); } + uint8_t* getDMABuffer(uint32_t length) override { return _flip_buffer.getBuffer(length); } void beginRead(void) override; void endRead(void) override; - std::uint32_t readData(std::uint_fast8_t bit_length) override; - bool readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma) override; - void readPixels(void* dst, pixelcopy_t* param, std::uint32_t length) override; + uint32_t readData(uint_fast8_t bit_length) override; + bool readBytes(uint8_t* dst, uint32_t length, bool use_dma) override; + void readPixels(void* dst, pixelcopy_t* param, uint32_t length) override; private: - std::uint32_t FreqToClockDiv(std::uint32_t freq); - void setFreqDiv(std::uint32_t div); + uint32_t FreqToClockDiv(uint32_t freq); + void setFreqDiv(uint32_t div); __attribute__ ((always_inline)) inline void set_clock_write(void) { setFreqDiv(_clkdiv_write); } __attribute__ ((always_inline)) inline void set_clock_read(void) { setFreqDiv(_clkdiv_read ); } @@ -106,12 +106,12 @@ namespace lgfx FlipBuffer _flip_buffer; bool _need_wait = false; Sercom* _sercom = nullptr; - std::uint32_t _mask_reg_dc; - std::uint32_t _last_apb_freq = -1; - std::uint32_t _clkdiv_write; - std::uint32_t _clkdiv_read; - volatile std::uint32_t* _gpio_reg_dc_h; - volatile std::uint32_t* _gpio_reg_dc_l; + uint32_t _mask_reg_dc; + uint32_t _last_apb_freq = -1; + uint32_t _clkdiv_write; + uint32_t _clkdiv_read; + volatile uint32_t* _gpio_reg_dc_h; + volatile uint32_t* _gpio_reg_dc_l; #if defined (ARDUINO) Adafruit_ZeroDMA _dma_adafruit; diff --git a/src/lgfx/v1/platforms/samd51/common.cpp b/src/lgfx/v1/platforms/samd51/common.cpp index 36b8237..2f83ced 100644 --- a/src/lgfx/v1/platforms/samd51/common.cpp +++ b/src/lgfx/v1/platforms/samd51/common.cpp @@ -25,7 +25,7 @@ Original Source: #undef PORT_PINCFG_INEN_Pos #undef _Ul -#define _Ul(n) (static_cast((n))) +#define _Ul(n) (static_cast((n))) #define PORT_PINCFG_INEN_Pos 1 /**< \brief (PORT_PINCFG) Input Enable */ #define PORT_PINCFG_INEN (_Ul(0x1) << PORT_PINCFG_INEN_Pos) #define PORT_PINCFG_PULLEN_Pos 2 /**< \brief (PORT_PINCFG) Pull Enable */ @@ -39,8 +39,8 @@ namespace lgfx namespace samd51 { - static constexpr std::int8_t sercom_pin_list_end = 0; - static constexpr std::int8_t sercom0_c_pin_list[] = + static constexpr int8_t sercom_pin_list_end = 0; + static constexpr int8_t sercom0_c_pin_list[] = { PORT_A | 8 // PAD 0 MUX C , PORT_B | 24 // PAD 0 MUX C , - 1 @@ -54,7 +54,7 @@ namespace lgfx , PORT_C | 25 // PAD 3 MUX C , sercom_pin_list_end }; - static constexpr std::int8_t sercom1_c_pin_list[] = + static constexpr int8_t sercom1_c_pin_list[] = { PORT_A | 16 // PAD 0 MUX C , PORT_C | 22 // PAD 0 MUX C , PORT_C | 27 // PAD 0 MUX C @@ -72,7 +72,7 @@ namespace lgfx , PORT_D | 21 // PAD 3 MUX C , sercom_pin_list_end }; - static constexpr std::int8_t sercom2_c_pin_list[] = + static constexpr int8_t sercom2_c_pin_list[] = { PORT_A | 12 // PAD 0 MUX C , PORT_B | 26 // PAD 0 MUX C , - 1 @@ -86,7 +86,7 @@ namespace lgfx , PORT_B | 29 // PAD 3 MUX C , sercom_pin_list_end }; - static constexpr std::int8_t sercom3_c_pin_list[] = + static constexpr int8_t sercom3_c_pin_list[] = { PORT_A | 22 // PAD 0 MUX C , PORT_B | 20 // PAD 0 MUX C , - 1 @@ -98,7 +98,7 @@ namespace lgfx , PORT_A | 25 // PAD 3 MUX C , sercom_pin_list_end }; - static constexpr std::int8_t sercom4_c_pin_list[] = + static constexpr int8_t sercom4_c_pin_list[] = { PORT_B | 12 // PAD 0 MUX C , - 1 , PORT_B | 13 // PAD 1 MUX C @@ -108,7 +108,7 @@ namespace lgfx , PORT_B | 15 // PAD 3 MUX C , sercom_pin_list_end }; - static constexpr std::int8_t sercom5_c_pin_list[] = + static constexpr int8_t sercom5_c_pin_list[] = { PORT_B | 16 // PAD 0 MUX C , - 1 , PORT_B | 17 // PAD 1 MUX C @@ -120,7 +120,7 @@ namespace lgfx , PORT_B | 19 // PAD 3 MUX C , sercom_pin_list_end }; - static constexpr std::int8_t sercom6_c_pin_list[] = + static constexpr int8_t sercom6_c_pin_list[] = { PORT_C | 4 // PAD 0 MUX C , PORT_C | 16 // PAD 0 MUX C , - 1 @@ -136,7 +136,7 @@ namespace lgfx , PORT_C | 19 // PAD 3 MUX C , sercom_pin_list_end }; - static constexpr std::int8_t sercom7_c_pin_list[] = + static constexpr int8_t sercom7_c_pin_list[] = { PORT_B | 30 // PAD 0 MUX C , PORT_C | 12 // PAD 0 MUX C , PORT_D | 8 // PAD 0 MUX C @@ -155,7 +155,7 @@ namespace lgfx , sercom_pin_list_end }; - static constexpr std::int8_t sercom0_d_pin_list[] = + static constexpr int8_t sercom0_d_pin_list[] = { PORT_A | 4 // PAD 0 MUX D , PORT_C | 17 // PAD 0 MUX D , - 1 @@ -169,7 +169,7 @@ namespace lgfx , PORT_C | 19 // PAD 3 MUX D , sercom_pin_list_end }; - static constexpr std::int8_t sercom1_d_pin_list[] = + static constexpr int8_t sercom1_d_pin_list[] = { PORT_A | 0 // PAD 0 MUX D , - 1 , PORT_A | 1 // PAD 1 MUX D @@ -179,7 +179,7 @@ namespace lgfx , PORT_A | 31 // PAD 3 MUX D , sercom_pin_list_end }; - static constexpr std::int8_t sercom2_d_pin_list[] = + static constexpr int8_t sercom2_d_pin_list[] = { PORT_A | 9 // PAD 0 MUX D , PORT_B | 25 // PAD 0 MUX D , - 1 @@ -193,7 +193,7 @@ namespace lgfx , PORT_C | 25 // PAD 3 MUX D , sercom_pin_list_end }; - static constexpr std::int8_t sercom3_d_pin_list[] = + static constexpr int8_t sercom3_d_pin_list[] = { PORT_A | 17 // PAD 0 MUX D , PORT_C | 23 // PAD 0 MUX D , - 1 @@ -209,7 +209,7 @@ namespace lgfx , PORT_D | 21 // PAD 3 MUX D , sercom_pin_list_end }; - static constexpr std::int8_t sercom4_d_pin_list[] = + static constexpr int8_t sercom4_d_pin_list[] = { PORT_A | 13 // PAD 0 MUX D , PORT_B | 8 // PAD 0 MUX D , PORT_B | 27 // PAD 0 MUX D @@ -227,7 +227,7 @@ namespace lgfx , PORT_B | 29 // PAD 3 MUX D , sercom_pin_list_end }; - static constexpr std::int8_t sercom5_d_pin_list[] = + static constexpr int8_t sercom5_d_pin_list[] = { PORT_A | 23 // PAD 0 MUX D , PORT_B | 2 // PAD 0 MUX D , PORT_B | 31 // PAD 0 MUX D @@ -245,7 +245,7 @@ namespace lgfx , PORT_B | 23 // PAD 3 MUX D , sercom_pin_list_end }; - static constexpr std::int8_t sercom6_d_pin_list[] = + static constexpr int8_t sercom6_d_pin_list[] = { PORT_C | 13 // PAD 0 MUX D , PORT_D | 9 // PAD 0 MUX D , - 1 @@ -259,7 +259,7 @@ namespace lgfx , PORT_D | 11 // PAD 3 MUX D , sercom_pin_list_end }; - static constexpr std::int8_t sercom7_d_pin_list[] = + static constexpr int8_t sercom7_d_pin_list[] = { PORT_B | 21 // PAD 0 MUX D , - 1 , PORT_B | 20 // PAD 1 MUX D @@ -272,7 +272,7 @@ namespace lgfx , sercom_pin_list_end }; - static constexpr const std::int8_t* sercom_mux_pin_list[2][SERCOM_INST_NUM] = + static constexpr const int8_t* sercom_mux_pin_list[2][SERCOM_INST_NUM] = { { sercom0_c_pin_list , sercom1_c_pin_list @@ -317,7 +317,7 @@ namespace lgfx { (uintptr_t)SERCOM7, SERCOM7_GCLK_ID_CORE, SERCOM7_GCLK_ID_SLOW, SERCOM7_DMAC_ID_TX, SERCOM7_DMAC_ID_RX }, #endif }; - const sercom_data_t* getSercomData(std::size_t sercom_index) + const sercom_data_t* getSercomData(size_t sercom_index) { return &sercom_data[sercom_index]; } @@ -328,7 +328,7 @@ namespace lgfx auto spl = samd51::sercom_mux_pin_list[alt][sercom_index]; int pad = 0; int tmp = spl[0]; - std::size_t idx = 0; + size_t idx = 0; do { if (pin == tmp) return pad; @@ -340,9 +340,9 @@ namespace lgfx void pinAssignPeriph(int pin_and_port, int type) { if (pin_and_port < 0) return; - std::uint_fast8_t port = (pin_and_port >> samd51::PORT_SHIFT); - std::uint_fast8_t pin = pin_and_port & (samd51::PIN_MASK); - std::uint32_t temp = PORT->Group[port].PMUX[pin >> 1].reg; + uint_fast8_t port = (pin_and_port >> samd51::PORT_SHIFT); + uint_fast8_t pin = pin_and_port & (samd51::PIN_MASK); + uint32_t temp = PORT->Group[port].PMUX[pin >> 1].reg; if (pin&1) temp = PORT_PMUX_PMUXO( type ) | (temp & PORT_PMUX_PMUXE( 0xF )); else temp = PORT_PMUX_PMUXE( type ) | (temp & PORT_PMUX_PMUXO( 0xF )); @@ -352,24 +352,24 @@ namespace lgfx //---------------------------------------------------------------------------- - void pinMode(std::int_fast16_t pin, pin_mode_t mode) + void pinMode(int_fast16_t pin, pin_mode_t mode) { - std::uint32_t port = pin >> samd51::PORT_SHIFT; + uint32_t port = pin >> samd51::PORT_SHIFT; pin &= samd51::PIN_MASK; - std::uint32_t pinMask = (1ul << pin); + uint32_t pinMask = (1ul << pin); // Set pin mode according to chapter '22.6.3 I/O Pin Configuration' switch ( mode ) { case pin_mode_t::input: // Set pin to input mode - PORT->Group[port].PINCFG[pin].reg=(std::uint8_t)(PORT_PINCFG_INEN) ; + PORT->Group[port].PINCFG[pin].reg=(uint8_t)(PORT_PINCFG_INEN) ; PORT->Group[port].DIRCLR.reg = pinMask ; break ; case pin_mode_t::input_pullup: // Set pin to input mode with pull-up resistor enabled - PORT->Group[port].PINCFG[pin].reg=(std::uint8_t)(PORT_PINCFG_INEN|PORT_PINCFG_PULLEN) ; + PORT->Group[port].PINCFG[pin].reg=(uint8_t)(PORT_PINCFG_INEN|PORT_PINCFG_PULLEN) ; PORT->Group[port].DIRCLR.reg = pinMask ; // Enable pull level (cf '22.6.3.2 Input Configuration' and '22.8.7 Data Output Value Set') @@ -378,7 +378,7 @@ namespace lgfx case pin_mode_t::input_pulldown: // Set pin to input mode with pull-down resistor enabled - PORT->Group[port].PINCFG[pin].reg=(std::uint8_t)(PORT_PINCFG_INEN|PORT_PINCFG_PULLEN) ; + PORT->Group[port].PINCFG[pin].reg=(uint8_t)(PORT_PINCFG_INEN|PORT_PINCFG_PULLEN) ; PORT->Group[port].DIRCLR.reg = pinMask ; // Enable pull level (cf '22.6.3.2 Input Configuration' and '22.8.6 Data Output Value Clear') @@ -387,7 +387,7 @@ namespace lgfx case pin_mode_t::output: // enable input, to support reading back values, with pullups disabled - PORT->Group[port].PINCFG[pin].reg=(std::uint8_t)(PORT_PINCFG_INEN) ; + PORT->Group[port].PINCFG[pin].reg=(uint8_t)(PORT_PINCFG_INEN) ; // Set pin to output mode PORT->Group[port].DIRSET.reg = pinMask ; @@ -414,7 +414,7 @@ namespace lgfx cpp::result init(int sercom_index, int pin_sclk, int pin_miso, int pin_mosi) { - if ((std::size_t)sercom_index >= SERCOM_INST_NUM) { return cpp::fail(error_t::invalid_arg); } + if ((size_t)sercom_index >= SERCOM_INST_NUM) { return cpp::fail(error_t::invalid_arg); } int dopo = -1; int dipo = -1; @@ -485,11 +485,11 @@ auto mastermode = SERCOM_SPI_CTRLA_MODE_SPI_MASTER; //void endTransaction(int spi_host, int spi_cs) void endTransaction(int, int) {} - //void writeData(int spi_host, const std::uint8_t* data, std::uint32_t len) - void writeBytes(int, const std::uint8_t*, std::uint32_t) {} + //void writeData(int spi_host, const uint8_t* data, uint32_t len) + void writeBytes(int, const uint8_t*, uint32_t) {} - //void readData(int spi_host, std::uint8_t* data, std::uint32_t len) - void readBytes(int, std::uint8_t*, std::uint32_t) {} + //void readData(int spi_host, uint8_t* data, uint32_t len) + void readBytes(int, uint8_t*, uint32_t) {} } //---------------------------------------------------------------------------- @@ -507,9 +507,9 @@ auto mastermode = SERCOM_SPI_CTRLA_MODE_SPI_MASTER; cpp::result state; bool wait_ack = false; - std::uint_fast16_t pin_scl = -1; - std::uint_fast16_t pin_sda = -1; - std::uint32_t freq = 0; + uint_fast16_t pin_scl = -1; + uint_fast16_t pin_sda = -1; + uint32_t freq = 0; void save_reg(SercomI2cm* dev) { @@ -522,14 +522,14 @@ auto mastermode = SERCOM_SPI_CTRLA_MODE_SPI_MASTER; } private: - std::uint32_t baudrate; + uint32_t baudrate; }; i2c_context_t i2c_context[SERCOM_INST_NUM]; cpp::result init(int sercom_index, int pin_sda, int pin_scl) { - if ((std::size_t)sercom_index >= SERCOM_INST_NUM) { return cpp::fail(error_t::invalid_arg); } + if ((size_t)sercom_index >= SERCOM_INST_NUM) { return cpp::fail(error_t::invalid_arg); } int pad_sda; int pad_scl; @@ -550,11 +550,11 @@ auto mastermode = SERCOM_SPI_CTRLA_MODE_SPI_MASTER; auto *i2cm = &sercom->I2CM; - std::uint_fast8_t id_core = sercomData->id_core; - std::uint_fast8_t id_slow = sercomData->id_slow; + uint_fast8_t id_core = sercomData->id_core; + uint_fast8_t id_slow = sercomData->id_slow; GCLK->PCHCTRL[id_core].bit.CHEN = 0; // Disable timer GCLK->PCHCTRL[id_slow].bit.CHEN = 0; // Disable timer - std::uint32_t gclk_reg_value = GCLK_PCHCTRL_CHEN | SERCOM_CLOCK_SOURCE_48M << GCLK_PCHCTRL_GEN_Pos; + uint32_t gclk_reg_value = GCLK_PCHCTRL_CHEN | SERCOM_CLOCK_SOURCE_48M << GCLK_PCHCTRL_GEN_Pos; while (GCLK->PCHCTRL[id_core].bit.CHEN || GCLK->PCHCTRL[id_slow].bit.CHEN); // Wait for disable GCLK->PCHCTRL[id_core].reg = gclk_reg_value; GCLK->PCHCTRL[id_slow].reg = gclk_reg_value; @@ -586,7 +586,7 @@ auto mastermode = SERCOM_SPI_CTRLA_MODE_SPI_MASTER; cpp::result release(int sercom_index) { - if ((std::size_t)sercom_index >= SERCOM_INST_NUM) { return cpp::fail(error_t::invalid_arg); } + if ((size_t)sercom_index >= SERCOM_INST_NUM) { return cpp::fail(error_t::invalid_arg); } sercom3.disableWIRE(); /* @@ -600,9 +600,9 @@ auto mastermode = SERCOM_SPI_CTRLA_MODE_SPI_MASTER; return {}; } - cpp::result restart(int sercom_index, int i2c_addr, std::uint32_t freq, bool read) + cpp::result restart(int sercom_index, int i2c_addr, uint32_t freq, bool read) { - if ((std::size_t)sercom_index >= SERCOM_INST_NUM) { return cpp::fail(error_t::invalid_arg); } + if ((size_t)sercom_index >= SERCOM_INST_NUM) { return cpp::fail(error_t::invalid_arg); } auto sercomData = samd51::getSercomData(sercom_index); auto sercom = reinterpret_cast(sercomData->sercomPtr); @@ -717,9 +717,9 @@ Serial.println("restart:ok"); //*/ } - cpp::result beginTransaction(int sercom_index, int i2c_addr, std::uint32_t freq, bool read) + cpp::result beginTransaction(int sercom_index, int i2c_addr, uint32_t freq, bool read) { - if ((std::size_t)sercom_index >= SERCOM_INST_NUM) { return cpp::fail(error_t::invalid_arg); } + if ((size_t)sercom_index >= SERCOM_INST_NUM) { return cpp::fail(error_t::invalid_arg); } /* auto sercomData = samd51::getSercomData(sercom_index); auto sercom = reinterpret_cast(sercomData->sercomPtr); @@ -736,7 +736,7 @@ Serial.println("restart:ok"); cpp::result i2c_wait(int sercom_index, bool flg_stop = false) { - if ((std::size_t)sercom_index >= SERCOM_INST_NUM) { return cpp::fail(error_t::invalid_arg); } + if ((size_t)sercom_index >= SERCOM_INST_NUM) { return cpp::fail(error_t::invalid_arg); } auto sercomData = samd51::getSercomData(sercom_index); auto sercom = reinterpret_cast(sercomData->sercomPtr); @@ -783,7 +783,7 @@ Serial.println("i2c_wait 4"); return i2c_wait(sercom_index, true); /* - if ((std::size_t)sercom_index >= SERCOM_INST_NUM) { return cpp::fail(error_t::invalid_arg); } + if ((size_t)sercom_index >= SERCOM_INST_NUM) { return cpp::fail(error_t::invalid_arg); } auto sercomData = samd51::getSercomData(sercom_index); auto sercom = reinterpret_cast(sercomData->sercomPtr); auto i2cm = &(sercom->I2CM); @@ -796,9 +796,9 @@ Serial.println("i2c_wait 4"); //*/ } - cpp::result writeBytes(int sercom_index, const std::uint8_t *data, std::size_t length) + cpp::result writeBytes(int sercom_index, const uint8_t *data, size_t length) { - if ((std::size_t)sercom_index >= SERCOM_INST_NUM) { return cpp::fail(error_t::invalid_arg); } + if ((size_t)sercom_index >= SERCOM_INST_NUM) { return cpp::fail(error_t::invalid_arg); } auto sercomData = samd51::getSercomData(sercom_index); auto sercom = reinterpret_cast(sercomData->sercomPtr); @@ -816,9 +816,9 @@ Serial.println("i2c_wait 4"); return res; } - cpp::result readBytes(int sercom_index, std::uint8_t *data, std::size_t length) + cpp::result readBytes(int sercom_index, uint8_t *data, size_t length) { - if ((std::size_t)sercom_index >= SERCOM_INST_NUM) { return cpp::fail(error_t::invalid_arg); } + if ((size_t)sercom_index >= SERCOM_INST_NUM) { return cpp::fail(error_t::invalid_arg); } auto res = i2c_wait(sercom_index); if (res.has_error()) { return res; } @@ -879,7 +879,7 @@ Serial.println("read fail"); } - cpp::result transactionWrite(int sercom_index, int addr, const std::uint8_t *writedata, std::uint8_t writelen, std::uint32_t freq) + cpp::result transactionWrite(int sercom_index, int addr, const uint8_t *writedata, uint8_t writelen, uint32_t freq) { cpp::result res; if ((res = beginTransaction(sercom_index, addr, freq, false)).has_value() @@ -891,7 +891,7 @@ Serial.println("read fail"); return res; } - cpp::result transactionRead(int sercom_index, int addr, std::uint8_t *readdata, std::uint8_t readlen, std::uint32_t freq) + cpp::result transactionRead(int sercom_index, int addr, uint8_t *readdata, uint8_t readlen, uint32_t freq) { cpp::result res; if ((res = beginTransaction(sercom_index, addr, freq, true)).has_value() @@ -903,7 +903,7 @@ Serial.println("read fail"); return res; } - cpp::result transactionWriteRead(int sercom_index, int addr, const std::uint8_t *writedata, std::uint8_t writelen, std::uint8_t *readdata, std::size_t readlen, std::uint32_t freq) + cpp::result transactionWriteRead(int sercom_index, int addr, const uint8_t *writedata, uint8_t writelen, uint8_t *readdata, size_t readlen, uint32_t freq) { cpp::result res; if ((res = beginTransaction(sercom_index, addr, freq, false)).has_value() @@ -917,16 +917,16 @@ Serial.println("read fail"); return res; } - cpp::result readRegister8(int sercom_index, int addr, std::uint8_t reg, std::uint32_t freq) + cpp::result readRegister8(int sercom_index, int addr, uint8_t reg, uint32_t freq) { auto res = transactionWriteRead(sercom_index, addr, ®, 1, ®, 1, freq); if (res.has_value()) { return reg; } return cpp::fail( res.error() ); } - cpp::result writeRegister8(int sercom_index, int addr, std::uint8_t reg, std::uint8_t data, std::uint8_t mask, std::uint32_t freq) + cpp::result writeRegister8(int sercom_index, int addr, uint8_t reg, uint8_t data, uint8_t mask, uint32_t freq) { - std::uint8_t tmp[2] = { reg, data }; + uint8_t tmp[2] = { reg, data }; if (mask) { auto res = transactionWriteRead(sercom_index, addr, ®, 1, &tmp[1], 1, freq); diff --git a/src/lgfx/v1/platforms/samd51/common.hpp b/src/lgfx/v1/platforms/samd51/common.hpp index 9ce953b..4897439 100644 --- a/src/lgfx/v1/platforms/samd51/common.hpp +++ b/src/lgfx/v1/platforms/samd51/common.hpp @@ -48,7 +48,7 @@ Original Source: #undef PORT_PINCFG_INEN #undef PORT_PINCFG_INEN_Pos - #define _Ul(n) (static_cast((n))) + #define _Ul(n) (static_cast((n))) #define PORT_PINCFG_INEN_Pos 1 /**< \brief (PORT_PINCFG) Input Enable */ #define PORT_PINCFG_INEN (_Ul(0x1) << PORT_PINCFG_INEN_Pos) #define PORT_PINCFG_PULLEN_Pos 2 /**< \brief (PORT_PINCFG) Pull Enable */ @@ -76,13 +76,13 @@ namespace lgfx struct sercom_data_t { - std::uintptr_t sercomPtr; - std::uint8_t id_core; - std::uint8_t id_slow; + uintptr_t sercomPtr; + uint8_t id_core; + uint8_t id_slow; int dmac_id_tx; int dmac_id_rx; }; - const sercom_data_t* getSercomData(std::size_t sercom_number); + const sercom_data_t* getSercomData(size_t sercom_number); } #if defined ( ARDUINO ) @@ -110,7 +110,7 @@ namespace lgfx #else - static inline void delay(std::size_t milliseconds) + static inline void delay(size_t milliseconds) { vTaskDelay(pdMS_TO_TICKS(milliseconds)); } @@ -139,9 +139,9 @@ namespace lgfx static inline void* heap_alloc_dma( size_t length) { return memalign(16, length); } static inline void heap_free(void* buf) { free(buf); } - static inline void gpio_hi(std::uint32_t pin) { PORT->Group[pin >> samd51::PORT_SHIFT].OUTSET.reg = (1ul << (pin & samd51::PIN_MASK)); } - static inline void gpio_lo(std::uint32_t pin) { PORT->Group[pin >> samd51::PORT_SHIFT].OUTCLR.reg = (1ul << (pin & samd51::PIN_MASK)); } - static inline bool gpio_in(std::uint32_t pin) { return PORT->Group[pin >> samd51::PORT_SHIFT].IN.reg & (1ul << (pin & samd51::PIN_MASK)); } + static inline void gpio_hi(uint32_t pin) { PORT->Group[pin >> samd51::PORT_SHIFT].OUTSET.reg = (1ul << (pin & samd51::PIN_MASK)); } + static inline void gpio_lo(uint32_t pin) { PORT->Group[pin >> samd51::PORT_SHIFT].OUTCLR.reg = (1ul << (pin & samd51::PIN_MASK)); } + static inline bool gpio_in(uint32_t pin) { return PORT->Group[pin >> samd51::PORT_SHIFT].IN.reg & (1ul << (pin & samd51::PIN_MASK)); } enum pin_mode_t { output @@ -150,8 +150,8 @@ namespace lgfx , input_pulldown }; - void pinMode(std::int_fast16_t pin, pin_mode_t mode); - inline void lgfxPinMode(std::int_fast16_t pin, pin_mode_t mode) + void pinMode(int_fast16_t pin, pin_mode_t mode); + inline void lgfxPinMode(int_fast16_t pin, pin_mode_t mode) { pinMode(pin, mode); } @@ -191,12 +191,12 @@ namespace lgfx return _file; } - int read(std::uint8_t *buf, std::uint32_t len) override { return _fp->read(buf, len); } - void skip(std::int32_t offset) override { seek(offset, SeekCur); } - bool seek(std::uint32_t offset) override { return seek(offset, SeekSet); } - bool seek(std::uint32_t offset, SeekMode mode) { return _fp->seek(offset, mode); } + int read(uint8_t *buf, uint32_t len) override { return _fp->read(buf, len); } + void skip(int32_t offset) override { seek(offset, SeekCur); } + bool seek(uint32_t offset) override { return seek(offset, SeekSet); } + bool seek(uint32_t offset, SeekMode mode) { return _fp->seek(offset, mode); } void close(void) override { if (_fp) _fp->close(); } - std::int32_t tell(void) override { return _fp->position(); } + int32_t tell(void) override { return _fp->position(); } #elif __SAMD51_HARMONY__ @@ -207,19 +207,19 @@ namespace lgfx this->handle = SYS_FS_FileOpen(path, SYS_FS_FILE_OPEN_ATTRIBUTES::SYS_FS_FILE_OPEN_READ); return this->handle != SYS_FS_HANDLE_INVALID; } - int read(std::uint8_t* buffer, std::uint32_t length) override + int read(uint8_t* buffer, uint32_t length) override { return SYS_FS_FileRead(this->handle, buffer, length); } - void skip(std::int32_t offset) override + void skip(int32_t offset) override { SYS_FS_FileSeek(this->handle, offset, SYS_FS_FILE_SEEK_CONTROL::SYS_FS_SEEK_CUR); } - bool seek(std::uint32_t offset) override + bool seek(uint32_t offset) override { return SYS_FS_FileSeek(this->handle, offset, SYS_FS_FILE_SEEK_CONTROL::SYS_FS_SEEK_SET) >= 0; } - bool seek(std::uint32_t offset, SYS_FS_FILE_SEEK_CONTROL mode) + bool seek(uint32_t offset, SYS_FS_FILE_SEEK_CONTROL mode) { return SYS_FS_FileSeek(this->handle, offset, mode) >= 0; } @@ -230,7 +230,7 @@ namespace lgfx this->handle = SYS_FS_HANDLE_INVALID; } } - std::int32_t tell(void) override + int32_t tell(void) override { return SYS_FS_FileTell(this->handle); } @@ -238,12 +238,12 @@ namespace lgfx #else // dummy. bool open(const char*) override { return false; } - int read(std::uint8_t*, std::uint32_t) override { return 0; } - void skip(std::int32_t) override { } - bool seek(std::uint32_t) override { return false; } - bool seek(std::uint32_t, int) { return false; } + int read(uint8_t*, uint32_t) override { return 0; } + void skip(int32_t) override { } + bool seek(uint32_t) override { return false; } + bool seek(uint32_t, int) { return false; } void close() override { } - std::int32_t tell(void) override { return 0; } + int32_t tell(void) override { return 0; } #endif @@ -255,22 +255,22 @@ namespace lgfx struct StreamWrapper : public DataWrapper { - void set(Stream* src, std::uint32_t length = ~0u) { _stream = src; _length = length; _index = 0; } + void set(Stream* src, uint32_t length = ~0u) { _stream = src; _length = length; _index = 0; } - int read(std::uint8_t *buf, std::uint32_t len) override { + int read(uint8_t *buf, uint32_t len) override { if (len > _length - _index) { len = _length - _index; } _index += len; return _stream->readBytes((char*)buf, len); } - void skip(std::int32_t offset) override { if (0 < offset) { char dummy[offset]; _stream->readBytes(dummy, offset); _index += offset; } } - bool seek(std::uint32_t offset) override { if (offset < _index) { return false; } skip(offset - _index); return true; } + void skip(int32_t offset) override { if (0 < offset) { char dummy[offset]; _stream->readBytes(dummy, offset); _index += offset; } } + bool seek(uint32_t offset) override { if (offset < _index) { return false; } skip(offset - _index); return true; } void close() override { } - std::int32_t tell(void) override { return _index; } + int32_t tell(void) override { return _index; } private: Stream* _stream; - std::uint32_t _index; - std::uint32_t _length = 0; + uint32_t _index; + uint32_t _length = 0; }; diff --git a/src/lgfx/v1/platforms/samd51/samd51_arduino_compat.hpp b/src/lgfx/v1/platforms/samd51/samd51_arduino_compat.hpp index 35f8c57..91c7034 100644 --- a/src/lgfx/v1/platforms/samd51/samd51_arduino_compat.hpp +++ b/src/lgfx/v1/platforms/samd51/samd51_arduino_compat.hpp @@ -1,7 +1,7 @@ #ifndef SAMD51_ARDUINO_COMPAT_HPP__ #define SAMD51_ARDUINO_COMPAT_HPP__ -#include +#include #include #ifndef __I @@ -10,67 +10,67 @@ #define __IO volatile #endif -typedef std::uint8_t RoReg8; +typedef uint8_t RoReg8; typedef union { struct { - std::uint8_t SWRST:1; /*!< bit: 0 Software Reset */ - std::uint8_t :7; /*!< bit: 1.. 7 Reserved */ + uint8_t SWRST:1; /*!< bit: 0 Software Reset */ + uint8_t :7; /*!< bit: 1.. 7 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } GCLK_CTRLA_Type; typedef union { struct { - std::uint32_t SWRST:1; /*!< bit: 0 Software Reset Synchroniation Busy bit */ - std::uint32_t :1; /*!< bit: 1 Reserved */ - std::uint32_t GENCTRL0:1; /*!< bit: 2 Generic Clock Generator Control 0 Synchronization Busy bits */ - std::uint32_t GENCTRL1:1; /*!< bit: 3 Generic Clock Generator Control 1 Synchronization Busy bits */ - std::uint32_t GENCTRL2:1; /*!< bit: 4 Generic Clock Generator Control 2 Synchronization Busy bits */ - std::uint32_t GENCTRL3:1; /*!< bit: 5 Generic Clock Generator Control 3 Synchronization Busy bits */ - std::uint32_t GENCTRL4:1; /*!< bit: 6 Generic Clock Generator Control 4 Synchronization Busy bits */ - std::uint32_t GENCTRL5:1; /*!< bit: 7 Generic Clock Generator Control 5 Synchronization Busy bits */ - std::uint32_t GENCTRL6:1; /*!< bit: 8 Generic Clock Generator Control 6 Synchronization Busy bits */ - std::uint32_t GENCTRL7:1; /*!< bit: 9 Generic Clock Generator Control 7 Synchronization Busy bits */ - std::uint32_t GENCTRL8:1; /*!< bit: 10 Generic Clock Generator Control 8 Synchronization Busy bits */ - std::uint32_t GENCTRL9:1; /*!< bit: 11 Generic Clock Generator Control 9 Synchronization Busy bits */ - std::uint32_t GENCTRL10:1; /*!< bit: 12 Generic Clock Generator Control 10 Synchronization Busy bits */ - std::uint32_t GENCTRL11:1; /*!< bit: 13 Generic Clock Generator Control 11 Synchronization Busy bits */ - std::uint32_t :18; /*!< bit: 14..31 Reserved */ + uint32_t SWRST:1; /*!< bit: 0 Software Reset Synchroniation Busy bit */ + uint32_t :1; /*!< bit: 1 Reserved */ + uint32_t GENCTRL0:1; /*!< bit: 2 Generic Clock Generator Control 0 Synchronization Busy bits */ + uint32_t GENCTRL1:1; /*!< bit: 3 Generic Clock Generator Control 1 Synchronization Busy bits */ + uint32_t GENCTRL2:1; /*!< bit: 4 Generic Clock Generator Control 2 Synchronization Busy bits */ + uint32_t GENCTRL3:1; /*!< bit: 5 Generic Clock Generator Control 3 Synchronization Busy bits */ + uint32_t GENCTRL4:1; /*!< bit: 6 Generic Clock Generator Control 4 Synchronization Busy bits */ + uint32_t GENCTRL5:1; /*!< bit: 7 Generic Clock Generator Control 5 Synchronization Busy bits */ + uint32_t GENCTRL6:1; /*!< bit: 8 Generic Clock Generator Control 6 Synchronization Busy bits */ + uint32_t GENCTRL7:1; /*!< bit: 9 Generic Clock Generator Control 7 Synchronization Busy bits */ + uint32_t GENCTRL8:1; /*!< bit: 10 Generic Clock Generator Control 8 Synchronization Busy bits */ + uint32_t GENCTRL9:1; /*!< bit: 11 Generic Clock Generator Control 9 Synchronization Busy bits */ + uint32_t GENCTRL10:1; /*!< bit: 12 Generic Clock Generator Control 10 Synchronization Busy bits */ + uint32_t GENCTRL11:1; /*!< bit: 13 Generic Clock Generator Control 11 Synchronization Busy bits */ + uint32_t :18; /*!< bit: 14..31 Reserved */ } bit; /*!< Structure used for bit access */ struct { - std::uint32_t :2; /*!< bit: 0.. 1 Reserved */ - std::uint32_t GENCTRL:12; /*!< bit: 2..13 Generic Clock Generator Control x Synchronization Busy bits */ - std::uint32_t :18; /*!< bit: 14..31 Reserved */ + uint32_t :2; /*!< bit: 0.. 1 Reserved */ + uint32_t GENCTRL:12; /*!< bit: 2..13 Generic Clock Generator Control x Synchronization Busy bits */ + uint32_t :18; /*!< bit: 14..31 Reserved */ } vec; /*!< Structure used for vec access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } GCLK_SYNCBUSY_Type; typedef union { struct { - std::uint32_t SRC:4; /*!< bit: 0.. 3 Source Select */ - std::uint32_t :4; /*!< bit: 4.. 7 Reserved */ - std::uint32_t GENEN:1; /*!< bit: 8 Generic Clock Generator Enable */ - std::uint32_t IDC:1; /*!< bit: 9 Improve Duty Cycle */ - std::uint32_t OOV:1; /*!< bit: 10 Output Off Value */ - std::uint32_t OE:1; /*!< bit: 11 Output Enable */ - std::uint32_t DIVSEL:1; /*!< bit: 12 Divide Selection */ - std::uint32_t RUNSTDBY:1; /*!< bit: 13 Run in Standby */ - std::uint32_t :2; /*!< bit: 14..15 Reserved */ - std::uint32_t DIV:16; /*!< bit: 16..31 Division Factor */ + uint32_t SRC:4; /*!< bit: 0.. 3 Source Select */ + uint32_t :4; /*!< bit: 4.. 7 Reserved */ + uint32_t GENEN:1; /*!< bit: 8 Generic Clock Generator Enable */ + uint32_t IDC:1; /*!< bit: 9 Improve Duty Cycle */ + uint32_t OOV:1; /*!< bit: 10 Output Off Value */ + uint32_t OE:1; /*!< bit: 11 Output Enable */ + uint32_t DIVSEL:1; /*!< bit: 12 Divide Selection */ + uint32_t RUNSTDBY:1; /*!< bit: 13 Run in Standby */ + uint32_t :2; /*!< bit: 14..15 Reserved */ + uint32_t DIV:16; /*!< bit: 16..31 Division Factor */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } GCLK_GENCTRL_Type; typedef union { struct { - std::uint32_t GEN:4; /*!< bit: 0.. 3 Generic Clock Generator */ - std::uint32_t :2; /*!< bit: 4.. 5 Reserved */ - std::uint32_t CHEN:1; /*!< bit: 6 Channel Enable */ - std::uint32_t WRTLOCK:1; /*!< bit: 7 Write Lock */ - std::uint32_t :24; /*!< bit: 8..31 Reserved */ + uint32_t GEN:4; /*!< bit: 0.. 3 Generic Clock Generator */ + uint32_t :2; /*!< bit: 4.. 5 Reserved */ + uint32_t CHEN:1; /*!< bit: 6 Channel Enable */ + uint32_t WRTLOCK:1; /*!< bit: 7 Write Lock */ + uint32_t :24; /*!< bit: 8..31 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } GCLK_PCHCTRL_Type; typedef struct { @@ -85,156 +85,156 @@ typedef struct { typedef union { struct { - std::uint8_t CKRDY:1; /*!< bit: 0 Clock Ready Interrupt Enable */ - std::uint8_t :7; /*!< bit: 1.. 7 Reserved */ + uint8_t CKRDY:1; /*!< bit: 0 Clock Ready Interrupt Enable */ + uint8_t :7; /*!< bit: 1.. 7 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } MCLK_INTENCLR_Type; typedef union { struct { - std::uint8_t CKRDY:1; /*!< bit: 0 Clock Ready Interrupt Enable */ - std::uint8_t :7; /*!< bit: 1.. 7 Reserved */ + uint8_t CKRDY:1; /*!< bit: 0 Clock Ready Interrupt Enable */ + uint8_t :7; /*!< bit: 1.. 7 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } MCLK_INTENSET_Type; typedef union { // __I to avoid read-modify-write on write-to-clear register struct { - __I std::uint8_t CKRDY:1; /*!< bit: 0 Clock Ready */ - __I std::uint8_t :7; /*!< bit: 1.. 7 Reserved */ + __I uint8_t CKRDY:1; /*!< bit: 0 Clock Ready */ + __I uint8_t :7; /*!< bit: 1.. 7 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } MCLK_INTFLAG_Type; typedef union { struct { - std::uint8_t DIV:8; /*!< bit: 0.. 7 CPU Clock Division Factor */ + uint8_t DIV:8; /*!< bit: 0.. 7 CPU Clock Division Factor */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } MCLK_HSDIV_Type; typedef union { struct { - std::uint8_t DIV:8; /*!< bit: 0.. 7 Low-Power Clock Division Factor */ + uint8_t DIV:8; /*!< bit: 0.. 7 Low-Power Clock Division Factor */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } MCLK_CPUDIV_Type; typedef union { struct { - std::uint32_t HPB0_:1; /*!< bit: 0 HPB0 AHB Clock Mask */ - std::uint32_t HPB1_:1; /*!< bit: 1 HPB1 AHB Clock Mask */ - std::uint32_t HPB2_:1; /*!< bit: 2 HPB2 AHB Clock Mask */ - std::uint32_t HPB3_:1; /*!< bit: 3 HPB3 AHB Clock Mask */ - std::uint32_t DSU_:1; /*!< bit: 4 DSU AHB Clock Mask */ - std::uint32_t HMATRIX_:1; /*!< bit: 5 HMATRIX AHB Clock Mask */ - std::uint32_t NVMCTRL_:1; /*!< bit: 6 NVMCTRL AHB Clock Mask */ - std::uint32_t HSRAM_:1; /*!< bit: 7 HSRAM AHB Clock Mask */ - std::uint32_t CMCC_:1; /*!< bit: 8 CMCC AHB Clock Mask */ - std::uint32_t DMAC_:1; /*!< bit: 9 DMAC AHB Clock Mask */ - std::uint32_t USB_:1; /*!< bit: 10 USB AHB Clock Mask */ - std::uint32_t BKUPRAM_:1; /*!< bit: 11 BKUPRAM AHB Clock Mask */ - std::uint32_t PAC_:1; /*!< bit: 12 PAC AHB Clock Mask */ - std::uint32_t QSPI_:1; /*!< bit: 13 QSPI AHB Clock Mask */ - std::uint32_t :1; /*!< bit: 14 Reserved */ - std::uint32_t SDHC0_:1; /*!< bit: 15 SDHC0 AHB Clock Mask */ - std::uint32_t SDHC1_:1; /*!< bit: 16 SDHC1 AHB Clock Mask */ - std::uint32_t :2; /*!< bit: 17..18 Reserved */ - std::uint32_t ICM_:1; /*!< bit: 19 ICM AHB Clock Mask */ - std::uint32_t PUKCC_:1; /*!< bit: 20 PUKCC AHB Clock Mask */ - std::uint32_t QSPI_2X_:1; /*!< bit: 21 QSPI_2X AHB Clock Mask */ - std::uint32_t NVMCTRL_SMEEPROM_:1; /*!< bit: 22 NVMCTRL_SMEEPROM AHB Clock Mask */ - std::uint32_t NVMCTRL_CACHE_:1; /*!< bit: 23 NVMCTRL_CACHE AHB Clock Mask */ - std::uint32_t :8; /*!< bit: 24..31 Reserved */ - } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t HPB0_:1; /*!< bit: 0 HPB0 AHB Clock Mask */ + uint32_t HPB1_:1; /*!< bit: 1 HPB1 AHB Clock Mask */ + uint32_t HPB2_:1; /*!< bit: 2 HPB2 AHB Clock Mask */ + uint32_t HPB3_:1; /*!< bit: 3 HPB3 AHB Clock Mask */ + uint32_t DSU_:1; /*!< bit: 4 DSU AHB Clock Mask */ + uint32_t HMATRIX_:1; /*!< bit: 5 HMATRIX AHB Clock Mask */ + uint32_t NVMCTRL_:1; /*!< bit: 6 NVMCTRL AHB Clock Mask */ + uint32_t HSRAM_:1; /*!< bit: 7 HSRAM AHB Clock Mask */ + uint32_t CMCC_:1; /*!< bit: 8 CMCC AHB Clock Mask */ + uint32_t DMAC_:1; /*!< bit: 9 DMAC AHB Clock Mask */ + uint32_t USB_:1; /*!< bit: 10 USB AHB Clock Mask */ + uint32_t BKUPRAM_:1; /*!< bit: 11 BKUPRAM AHB Clock Mask */ + uint32_t PAC_:1; /*!< bit: 12 PAC AHB Clock Mask */ + uint32_t QSPI_:1; /*!< bit: 13 QSPI AHB Clock Mask */ + uint32_t :1; /*!< bit: 14 Reserved */ + uint32_t SDHC0_:1; /*!< bit: 15 SDHC0 AHB Clock Mask */ + uint32_t SDHC1_:1; /*!< bit: 16 SDHC1 AHB Clock Mask */ + uint32_t :2; /*!< bit: 17..18 Reserved */ + uint32_t ICM_:1; /*!< bit: 19 ICM AHB Clock Mask */ + uint32_t PUKCC_:1; /*!< bit: 20 PUKCC AHB Clock Mask */ + uint32_t QSPI_2X_:1; /*!< bit: 21 QSPI_2X AHB Clock Mask */ + uint32_t NVMCTRL_SMEEPROM_:1; /*!< bit: 22 NVMCTRL_SMEEPROM AHB Clock Mask */ + uint32_t NVMCTRL_CACHE_:1; /*!< bit: 23 NVMCTRL_CACHE AHB Clock Mask */ + uint32_t :8; /*!< bit: 24..31 Reserved */ + } bit; /*!< Structure used for bit access */ + uint32_t reg; /*!< Type used for register access */ } MCLK_AHBMASK_Type; typedef union { struct { - std::uint32_t PAC_:1; /*!< bit: 0 PAC APB Clock Enable */ - std::uint32_t PM_:1; /*!< bit: 1 PM APB Clock Enable */ - std::uint32_t MCLK_:1; /*!< bit: 2 MCLK APB Clock Enable */ - std::uint32_t RSTC_:1; /*!< bit: 3 RSTC APB Clock Enable */ - std::uint32_t OSCCTRL_:1; /*!< bit: 4 OSCCTRL APB Clock Enable */ - std::uint32_t OSC32KCTRL_:1; /*!< bit: 5 OSC32KCTRL APB Clock Enable */ - std::uint32_t SUPC_:1; /*!< bit: 6 SUPC APB Clock Enable */ - std::uint32_t GCLK_:1; /*!< bit: 7 GCLK APB Clock Enable */ - std::uint32_t WDT_:1; /*!< bit: 8 WDT APB Clock Enable */ - std::uint32_t RTC_:1; /*!< bit: 9 RTC APB Clock Enable */ - std::uint32_t EIC_:1; /*!< bit: 10 EIC APB Clock Enable */ - std::uint32_t FREQM_:1; /*!< bit: 11 FREQM APB Clock Enable */ - std::uint32_t SERCOM0_:1; /*!< bit: 12 SERCOM0 APB Clock Enable */ - std::uint32_t SERCOM1_:1; /*!< bit: 13 SERCOM1 APB Clock Enable */ - std::uint32_t TC0_:1; /*!< bit: 14 TC0 APB Clock Enable */ - std::uint32_t TC1_:1; /*!< bit: 15 TC1 APB Clock Enable */ - std::uint32_t :16; /*!< bit: 16..31 Reserved */ - } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t PAC_:1; /*!< bit: 0 PAC APB Clock Enable */ + uint32_t PM_:1; /*!< bit: 1 PM APB Clock Enable */ + uint32_t MCLK_:1; /*!< bit: 2 MCLK APB Clock Enable */ + uint32_t RSTC_:1; /*!< bit: 3 RSTC APB Clock Enable */ + uint32_t OSCCTRL_:1; /*!< bit: 4 OSCCTRL APB Clock Enable */ + uint32_t OSC32KCTRL_:1; /*!< bit: 5 OSC32KCTRL APB Clock Enable */ + uint32_t SUPC_:1; /*!< bit: 6 SUPC APB Clock Enable */ + uint32_t GCLK_:1; /*!< bit: 7 GCLK APB Clock Enable */ + uint32_t WDT_:1; /*!< bit: 8 WDT APB Clock Enable */ + uint32_t RTC_:1; /*!< bit: 9 RTC APB Clock Enable */ + uint32_t EIC_:1; /*!< bit: 10 EIC APB Clock Enable */ + uint32_t FREQM_:1; /*!< bit: 11 FREQM APB Clock Enable */ + uint32_t SERCOM0_:1; /*!< bit: 12 SERCOM0 APB Clock Enable */ + uint32_t SERCOM1_:1; /*!< bit: 13 SERCOM1 APB Clock Enable */ + uint32_t TC0_:1; /*!< bit: 14 TC0 APB Clock Enable */ + uint32_t TC1_:1; /*!< bit: 15 TC1 APB Clock Enable */ + uint32_t :16; /*!< bit: 16..31 Reserved */ + } bit; /*!< Structure used for bit access */ + uint32_t reg; /*!< Type used for register access */ } MCLK_APBAMASK_Type; typedef union { struct { - std::uint32_t USB_:1; /*!< bit: 0 USB APB Clock Enable */ - std::uint32_t DSU_:1; /*!< bit: 1 DSU APB Clock Enable */ - std::uint32_t NVMCTRL_:1; /*!< bit: 2 NVMCTRL APB Clock Enable */ - std::uint32_t :1; /*!< bit: 3 Reserved */ - std::uint32_t PORT_:1; /*!< bit: 4 PORT APB Clock Enable */ - std::uint32_t :1; /*!< bit: 5 Reserved */ - std::uint32_t HMATRIX_:1; /*!< bit: 6 HMATRIX APB Clock Enable */ - std::uint32_t EVSYS_:1; /*!< bit: 7 EVSYS APB Clock Enable */ - std::uint32_t :1; /*!< bit: 8 Reserved */ - std::uint32_t SERCOM2_:1; /*!< bit: 9 SERCOM2 APB Clock Enable */ - std::uint32_t SERCOM3_:1; /*!< bit: 10 SERCOM3 APB Clock Enable */ - std::uint32_t TCC0_:1; /*!< bit: 11 TCC0 APB Clock Enable */ - std::uint32_t TCC1_:1; /*!< bit: 12 TCC1 APB Clock Enable */ - std::uint32_t TC2_:1; /*!< bit: 13 TC2 APB Clock Enable */ - std::uint32_t TC3_:1; /*!< bit: 14 TC3 APB Clock Enable */ - std::uint32_t TAL_:1; /*!< bit: 15 TAL APB Clock Enable */ - std::uint32_t RAMECC_:1; /*!< bit: 16 RAMECC APB Clock Enable */ - std::uint32_t :15; /*!< bit: 17..31 Reserved */ - } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t USB_:1; /*!< bit: 0 USB APB Clock Enable */ + uint32_t DSU_:1; /*!< bit: 1 DSU APB Clock Enable */ + uint32_t NVMCTRL_:1; /*!< bit: 2 NVMCTRL APB Clock Enable */ + uint32_t :1; /*!< bit: 3 Reserved */ + uint32_t PORT_:1; /*!< bit: 4 PORT APB Clock Enable */ + uint32_t :1; /*!< bit: 5 Reserved */ + uint32_t HMATRIX_:1; /*!< bit: 6 HMATRIX APB Clock Enable */ + uint32_t EVSYS_:1; /*!< bit: 7 EVSYS APB Clock Enable */ + uint32_t :1; /*!< bit: 8 Reserved */ + uint32_t SERCOM2_:1; /*!< bit: 9 SERCOM2 APB Clock Enable */ + uint32_t SERCOM3_:1; /*!< bit: 10 SERCOM3 APB Clock Enable */ + uint32_t TCC0_:1; /*!< bit: 11 TCC0 APB Clock Enable */ + uint32_t TCC1_:1; /*!< bit: 12 TCC1 APB Clock Enable */ + uint32_t TC2_:1; /*!< bit: 13 TC2 APB Clock Enable */ + uint32_t TC3_:1; /*!< bit: 14 TC3 APB Clock Enable */ + uint32_t TAL_:1; /*!< bit: 15 TAL APB Clock Enable */ + uint32_t RAMECC_:1; /*!< bit: 16 RAMECC APB Clock Enable */ + uint32_t :15; /*!< bit: 17..31 Reserved */ + } bit; /*!< Structure used for bit access */ + uint32_t reg; /*!< Type used for register access */ } MCLK_APBBMASK_Type; typedef union { struct { - std::uint32_t :3; /*!< bit: 0.. 2 Reserved */ - std::uint32_t TCC2_:1; /*!< bit: 3 TCC2 APB Clock Enable */ - std::uint32_t TCC3_:1; /*!< bit: 4 TCC3 APB Clock Enable */ - std::uint32_t TC4_:1; /*!< bit: 5 TC4 APB Clock Enable */ - std::uint32_t TC5_:1; /*!< bit: 6 TC5 APB Clock Enable */ - std::uint32_t PDEC_:1; /*!< bit: 7 PDEC APB Clock Enable */ - std::uint32_t AC_:1; /*!< bit: 8 AC APB Clock Enable */ - std::uint32_t AES_:1; /*!< bit: 9 AES APB Clock Enable */ - std::uint32_t TRNG_:1; /*!< bit: 10 TRNG APB Clock Enable */ - std::uint32_t ICM_:1; /*!< bit: 11 ICM APB Clock Enable */ - std::uint32_t :1; /*!< bit: 12 Reserved */ - std::uint32_t QSPI_:1; /*!< bit: 13 QSPI APB Clock Enable */ - std::uint32_t CCL_:1; /*!< bit: 14 CCL APB Clock Enable */ - std::uint32_t :17; /*!< bit: 15..31 Reserved */ + uint32_t :3; /*!< bit: 0.. 2 Reserved */ + uint32_t TCC2_:1; /*!< bit: 3 TCC2 APB Clock Enable */ + uint32_t TCC3_:1; /*!< bit: 4 TCC3 APB Clock Enable */ + uint32_t TC4_:1; /*!< bit: 5 TC4 APB Clock Enable */ + uint32_t TC5_:1; /*!< bit: 6 TC5 APB Clock Enable */ + uint32_t PDEC_:1; /*!< bit: 7 PDEC APB Clock Enable */ + uint32_t AC_:1; /*!< bit: 8 AC APB Clock Enable */ + uint32_t AES_:1; /*!< bit: 9 AES APB Clock Enable */ + uint32_t TRNG_:1; /*!< bit: 10 TRNG APB Clock Enable */ + uint32_t ICM_:1; /*!< bit: 11 ICM APB Clock Enable */ + uint32_t :1; /*!< bit: 12 Reserved */ + uint32_t QSPI_:1; /*!< bit: 13 QSPI APB Clock Enable */ + uint32_t CCL_:1; /*!< bit: 14 CCL APB Clock Enable */ + uint32_t :17; /*!< bit: 15..31 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } MCLK_APBCMASK_Type; typedef union { struct { - std::uint32_t SERCOM4_:1; /*!< bit: 0 SERCOM4 APB Clock Enable */ - std::uint32_t SERCOM5_:1; /*!< bit: 1 SERCOM5 APB Clock Enable */ - std::uint32_t SERCOM6_:1; /*!< bit: 2 SERCOM6 APB Clock Enable */ - std::uint32_t SERCOM7_:1; /*!< bit: 3 SERCOM7 APB Clock Enable */ - std::uint32_t TCC4_:1; /*!< bit: 4 TCC4 APB Clock Enable */ - std::uint32_t TC6_:1; /*!< bit: 5 TC6 APB Clock Enable */ - std::uint32_t TC7_:1; /*!< bit: 6 TC7 APB Clock Enable */ - std::uint32_t ADC0_:1; /*!< bit: 7 ADC0 APB Clock Enable */ - std::uint32_t ADC1_:1; /*!< bit: 8 ADC1 APB Clock Enable */ - std::uint32_t DAC_:1; /*!< bit: 9 DAC APB Clock Enable */ - std::uint32_t I2S_:1; /*!< bit: 10 I2S APB Clock Enable */ - std::uint32_t PCC_:1; /*!< bit: 11 PCC APB Clock Enable */ - std::uint32_t :20; /*!< bit: 12..31 Reserved */ + uint32_t SERCOM4_:1; /*!< bit: 0 SERCOM4 APB Clock Enable */ + uint32_t SERCOM5_:1; /*!< bit: 1 SERCOM5 APB Clock Enable */ + uint32_t SERCOM6_:1; /*!< bit: 2 SERCOM6 APB Clock Enable */ + uint32_t SERCOM7_:1; /*!< bit: 3 SERCOM7 APB Clock Enable */ + uint32_t TCC4_:1; /*!< bit: 4 TCC4 APB Clock Enable */ + uint32_t TC6_:1; /*!< bit: 5 TC6 APB Clock Enable */ + uint32_t TC7_:1; /*!< bit: 6 TC7 APB Clock Enable */ + uint32_t ADC0_:1; /*!< bit: 7 ADC0 APB Clock Enable */ + uint32_t ADC1_:1; /*!< bit: 8 ADC1 APB Clock Enable */ + uint32_t DAC_:1; /*!< bit: 9 DAC APB Clock Enable */ + uint32_t I2S_:1; /*!< bit: 10 I2S APB Clock Enable */ + uint32_t PCC_:1; /*!< bit: 11 PCC APB Clock Enable */ + uint32_t :20; /*!< bit: 12..31 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } MCLK_APBDMASK_Type; typedef struct { @@ -254,41 +254,41 @@ typedef struct { typedef union { struct { - std::uint8_t SWRST:1; /*!< bit: 0 Software Reset */ - std::uint8_t ENABLE:1; /*!< bit: 1 Enable */ - std::uint8_t :4; /*!< bit: 2.. 5 Reserved */ - std::uint8_t RUNSTDBY:1; /*!< bit: 6 Run in Standby */ - std::uint8_t :1; /*!< bit: 7 Reserved */ + uint8_t SWRST:1; /*!< bit: 0 Software Reset */ + uint8_t ENABLE:1; /*!< bit: 1 Enable */ + uint8_t :4; /*!< bit: 2.. 5 Reserved */ + uint8_t RUNSTDBY:1; /*!< bit: 6 Run in Standby */ + uint8_t :1; /*!< bit: 7 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } CCL_CTRL_Type; typedef union { struct { - std::uint8_t SEQSEL:4; /*!< bit: 0.. 3 Sequential Selection */ - std::uint8_t :4; /*!< bit: 4.. 7 Reserved */ + uint8_t SEQSEL:4; /*!< bit: 0.. 3 Sequential Selection */ + uint8_t :4; /*!< bit: 4.. 7 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } CCL_SEQCTRL_Type; typedef union { struct { - std::uint32_t :1; /*!< bit: 0 Reserved */ - std::uint32_t ENABLE:1; /*!< bit: 1 LUT Enable */ - std::uint32_t :2; /*!< bit: 2.. 3 Reserved */ - std::uint32_t FILTSEL:2; /*!< bit: 4.. 5 Filter Selection */ - std::uint32_t :1; /*!< bit: 6 Reserved */ - std::uint32_t EDGESEL:1; /*!< bit: 7 Edge Selection */ - std::uint32_t INSEL0:4; /*!< bit: 8..11 Input Selection 0 */ - std::uint32_t INSEL1:4; /*!< bit: 12..15 Input Selection 1 */ - std::uint32_t INSEL2:4; /*!< bit: 16..19 Input Selection 2 */ - std::uint32_t INVEI:1; /*!< bit: 20 Inverted Event Input Enable */ - std::uint32_t LUTEI:1; /*!< bit: 21 LUT Event Input Enable */ - std::uint32_t LUTEO:1; /*!< bit: 22 LUT Event Output Enable */ - std::uint32_t :1; /*!< bit: 23 Reserved */ - std::uint32_t TRUTH:8; /*!< bit: 24..31 Truth Value */ + uint32_t :1; /*!< bit: 0 Reserved */ + uint32_t ENABLE:1; /*!< bit: 1 LUT Enable */ + uint32_t :2; /*!< bit: 2.. 3 Reserved */ + uint32_t FILTSEL:2; /*!< bit: 4.. 5 Filter Selection */ + uint32_t :1; /*!< bit: 6 Reserved */ + uint32_t EDGESEL:1; /*!< bit: 7 Edge Selection */ + uint32_t INSEL0:4; /*!< bit: 8..11 Input Selection 0 */ + uint32_t INSEL1:4; /*!< bit: 12..15 Input Selection 1 */ + uint32_t INSEL2:4; /*!< bit: 16..19 Input Selection 2 */ + uint32_t INVEI:1; /*!< bit: 20 Inverted Event Input Enable */ + uint32_t LUTEI:1; /*!< bit: 21 LUT Event Input Enable */ + uint32_t LUTEO:1; /*!< bit: 22 LUT Event Output Enable */ + uint32_t :1; /*!< bit: 23 Reserved */ + uint32_t TRUTH:8; /*!< bit: 24..31 Truth Value */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } CCL_LUTCTRL_Type; typedef struct { @@ -301,200 +301,200 @@ typedef struct { typedef union { struct { - std::uint8_t SWRST:1; /*!< bit: 0 Software Reset */ - std::uint8_t :7; /*!< bit: 1.. 7 Reserved */ + uint8_t SWRST:1; /*!< bit: 0 Software Reset */ + uint8_t :7; /*!< bit: 1.. 7 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } EVSYS_CTRLA_Type; typedef union { struct { - std::uint32_t CHANNEL0:1; /*!< bit: 0 Channel 0 Software Selection */ - std::uint32_t CHANNEL1:1; /*!< bit: 1 Channel 1 Software Selection */ - std::uint32_t CHANNEL2:1; /*!< bit: 2 Channel 2 Software Selection */ - std::uint32_t CHANNEL3:1; /*!< bit: 3 Channel 3 Software Selection */ - std::uint32_t CHANNEL4:1; /*!< bit: 4 Channel 4 Software Selection */ - std::uint32_t CHANNEL5:1; /*!< bit: 5 Channel 5 Software Selection */ - std::uint32_t CHANNEL6:1; /*!< bit: 6 Channel 6 Software Selection */ - std::uint32_t CHANNEL7:1; /*!< bit: 7 Channel 7 Software Selection */ - std::uint32_t CHANNEL8:1; /*!< bit: 8 Channel 8 Software Selection */ - std::uint32_t CHANNEL9:1; /*!< bit: 9 Channel 9 Software Selection */ - std::uint32_t CHANNEL10:1; /*!< bit: 10 Channel 10 Software Selection */ - std::uint32_t CHANNEL11:1; /*!< bit: 11 Channel 11 Software Selection */ - std::uint32_t CHANNEL12:1; /*!< bit: 12 Channel 12 Software Selection */ - std::uint32_t CHANNEL13:1; /*!< bit: 13 Channel 13 Software Selection */ - std::uint32_t CHANNEL14:1; /*!< bit: 14 Channel 14 Software Selection */ - std::uint32_t CHANNEL15:1; /*!< bit: 15 Channel 15 Software Selection */ - std::uint32_t CHANNEL16:1; /*!< bit: 16 Channel 16 Software Selection */ - std::uint32_t CHANNEL17:1; /*!< bit: 17 Channel 17 Software Selection */ - std::uint32_t CHANNEL18:1; /*!< bit: 18 Channel 18 Software Selection */ - std::uint32_t CHANNEL19:1; /*!< bit: 19 Channel 19 Software Selection */ - std::uint32_t CHANNEL20:1; /*!< bit: 20 Channel 20 Software Selection */ - std::uint32_t CHANNEL21:1; /*!< bit: 21 Channel 21 Software Selection */ - std::uint32_t CHANNEL22:1; /*!< bit: 22 Channel 22 Software Selection */ - std::uint32_t CHANNEL23:1; /*!< bit: 23 Channel 23 Software Selection */ - std::uint32_t CHANNEL24:1; /*!< bit: 24 Channel 24 Software Selection */ - std::uint32_t CHANNEL25:1; /*!< bit: 25 Channel 25 Software Selection */ - std::uint32_t CHANNEL26:1; /*!< bit: 26 Channel 26 Software Selection */ - std::uint32_t CHANNEL27:1; /*!< bit: 27 Channel 27 Software Selection */ - std::uint32_t CHANNEL28:1; /*!< bit: 28 Channel 28 Software Selection */ - std::uint32_t CHANNEL29:1; /*!< bit: 29 Channel 29 Software Selection */ - std::uint32_t CHANNEL30:1; /*!< bit: 30 Channel 30 Software Selection */ - std::uint32_t CHANNEL31:1; /*!< bit: 31 Channel 31 Software Selection */ - } bit; /*!< Structure used for bit access */ - struct { - std::uint32_t CHANNEL:32; /*!< bit: 0..31 Channel x Software Selection */ + uint32_t CHANNEL0:1; /*!< bit: 0 Channel 0 Software Selection */ + uint32_t CHANNEL1:1; /*!< bit: 1 Channel 1 Software Selection */ + uint32_t CHANNEL2:1; /*!< bit: 2 Channel 2 Software Selection */ + uint32_t CHANNEL3:1; /*!< bit: 3 Channel 3 Software Selection */ + uint32_t CHANNEL4:1; /*!< bit: 4 Channel 4 Software Selection */ + uint32_t CHANNEL5:1; /*!< bit: 5 Channel 5 Software Selection */ + uint32_t CHANNEL6:1; /*!< bit: 6 Channel 6 Software Selection */ + uint32_t CHANNEL7:1; /*!< bit: 7 Channel 7 Software Selection */ + uint32_t CHANNEL8:1; /*!< bit: 8 Channel 8 Software Selection */ + uint32_t CHANNEL9:1; /*!< bit: 9 Channel 9 Software Selection */ + uint32_t CHANNEL10:1; /*!< bit: 10 Channel 10 Software Selection */ + uint32_t CHANNEL11:1; /*!< bit: 11 Channel 11 Software Selection */ + uint32_t CHANNEL12:1; /*!< bit: 12 Channel 12 Software Selection */ + uint32_t CHANNEL13:1; /*!< bit: 13 Channel 13 Software Selection */ + uint32_t CHANNEL14:1; /*!< bit: 14 Channel 14 Software Selection */ + uint32_t CHANNEL15:1; /*!< bit: 15 Channel 15 Software Selection */ + uint32_t CHANNEL16:1; /*!< bit: 16 Channel 16 Software Selection */ + uint32_t CHANNEL17:1; /*!< bit: 17 Channel 17 Software Selection */ + uint32_t CHANNEL18:1; /*!< bit: 18 Channel 18 Software Selection */ + uint32_t CHANNEL19:1; /*!< bit: 19 Channel 19 Software Selection */ + uint32_t CHANNEL20:1; /*!< bit: 20 Channel 20 Software Selection */ + uint32_t CHANNEL21:1; /*!< bit: 21 Channel 21 Software Selection */ + uint32_t CHANNEL22:1; /*!< bit: 22 Channel 22 Software Selection */ + uint32_t CHANNEL23:1; /*!< bit: 23 Channel 23 Software Selection */ + uint32_t CHANNEL24:1; /*!< bit: 24 Channel 24 Software Selection */ + uint32_t CHANNEL25:1; /*!< bit: 25 Channel 25 Software Selection */ + uint32_t CHANNEL26:1; /*!< bit: 26 Channel 26 Software Selection */ + uint32_t CHANNEL27:1; /*!< bit: 27 Channel 27 Software Selection */ + uint32_t CHANNEL28:1; /*!< bit: 28 Channel 28 Software Selection */ + uint32_t CHANNEL29:1; /*!< bit: 29 Channel 29 Software Selection */ + uint32_t CHANNEL30:1; /*!< bit: 30 Channel 30 Software Selection */ + uint32_t CHANNEL31:1; /*!< bit: 31 Channel 31 Software Selection */ + } bit; /*!< Structure used for bit access */ + struct { + uint32_t CHANNEL:32; /*!< bit: 0..31 Channel x Software Selection */ } vec; /*!< Structure used for vec access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } EVSYS_SWEVT_Type; typedef union { struct { - std::uint8_t PRI:4; /*!< bit: 0.. 3 Channel Priority Number */ - std::uint8_t :3; /*!< bit: 4.. 6 Reserved */ - std::uint8_t RREN:1; /*!< bit: 7 Round-Robin Scheduling Enable */ + uint8_t PRI:4; /*!< bit: 0.. 3 Channel Priority Number */ + uint8_t :3; /*!< bit: 4.. 6 Reserved */ + uint8_t RREN:1; /*!< bit: 7 Round-Robin Scheduling Enable */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } EVSYS_PRICTRL_Type; typedef union { struct { - std::uint16_t ID:4; /*!< bit: 0.. 3 Channel ID */ - std::uint16_t :4; /*!< bit: 4.. 7 Reserved */ - std::uint16_t OVR:1; /*!< bit: 8 Channel Overrun */ - std::uint16_t EVD:1; /*!< bit: 9 Channel Event Detected */ - std::uint16_t :4; /*!< bit: 10..13 Reserved */ - std::uint16_t READY:1; /*!< bit: 14 Ready */ - std::uint16_t BUSY:1; /*!< bit: 15 Busy */ + uint16_t ID:4; /*!< bit: 0.. 3 Channel ID */ + uint16_t :4; /*!< bit: 4.. 7 Reserved */ + uint16_t OVR:1; /*!< bit: 8 Channel Overrun */ + uint16_t EVD:1; /*!< bit: 9 Channel Event Detected */ + uint16_t :4; /*!< bit: 10..13 Reserved */ + uint16_t READY:1; /*!< bit: 14 Ready */ + uint16_t BUSY:1; /*!< bit: 15 Busy */ } bit; /*!< Structure used for bit access */ - std::uint16_t reg; /*!< Type used for register access */ + uint16_t reg; /*!< Type used for register access */ } EVSYS_INTPEND_Type; typedef union { struct { - std::uint32_t CHINT0:1; /*!< bit: 0 Channel 0 Pending Interrupt */ - std::uint32_t CHINT1:1; /*!< bit: 1 Channel 1 Pending Interrupt */ - std::uint32_t CHINT2:1; /*!< bit: 2 Channel 2 Pending Interrupt */ - std::uint32_t CHINT3:1; /*!< bit: 3 Channel 3 Pending Interrupt */ - std::uint32_t CHINT4:1; /*!< bit: 4 Channel 4 Pending Interrupt */ - std::uint32_t CHINT5:1; /*!< bit: 5 Channel 5 Pending Interrupt */ - std::uint32_t CHINT6:1; /*!< bit: 6 Channel 6 Pending Interrupt */ - std::uint32_t CHINT7:1; /*!< bit: 7 Channel 7 Pending Interrupt */ - std::uint32_t CHINT8:1; /*!< bit: 8 Channel 8 Pending Interrupt */ - std::uint32_t CHINT9:1; /*!< bit: 9 Channel 9 Pending Interrupt */ - std::uint32_t CHINT10:1; /*!< bit: 10 Channel 10 Pending Interrupt */ - std::uint32_t CHINT11:1; /*!< bit: 11 Channel 11 Pending Interrupt */ - std::uint32_t :20; /*!< bit: 12..31 Reserved */ + uint32_t CHINT0:1; /*!< bit: 0 Channel 0 Pending Interrupt */ + uint32_t CHINT1:1; /*!< bit: 1 Channel 1 Pending Interrupt */ + uint32_t CHINT2:1; /*!< bit: 2 Channel 2 Pending Interrupt */ + uint32_t CHINT3:1; /*!< bit: 3 Channel 3 Pending Interrupt */ + uint32_t CHINT4:1; /*!< bit: 4 Channel 4 Pending Interrupt */ + uint32_t CHINT5:1; /*!< bit: 5 Channel 5 Pending Interrupt */ + uint32_t CHINT6:1; /*!< bit: 6 Channel 6 Pending Interrupt */ + uint32_t CHINT7:1; /*!< bit: 7 Channel 7 Pending Interrupt */ + uint32_t CHINT8:1; /*!< bit: 8 Channel 8 Pending Interrupt */ + uint32_t CHINT9:1; /*!< bit: 9 Channel 9 Pending Interrupt */ + uint32_t CHINT10:1; /*!< bit: 10 Channel 10 Pending Interrupt */ + uint32_t CHINT11:1; /*!< bit: 11 Channel 11 Pending Interrupt */ + uint32_t :20; /*!< bit: 12..31 Reserved */ } bit; /*!< Structure used for bit access */ struct { - std::uint32_t CHINT:12; /*!< bit: 0..11 Channel x Pending Interrupt */ - std::uint32_t :20; /*!< bit: 12..31 Reserved */ + uint32_t CHINT:12; /*!< bit: 0..11 Channel x Pending Interrupt */ + uint32_t :20; /*!< bit: 12..31 Reserved */ } vec; /*!< Structure used for vec access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } EVSYS_INTSTATUS_Type; typedef union { struct { - std::uint32_t BUSYCH0:1; /*!< bit: 0 Busy Channel 0 */ - std::uint32_t BUSYCH1:1; /*!< bit: 1 Busy Channel 1 */ - std::uint32_t BUSYCH2:1; /*!< bit: 2 Busy Channel 2 */ - std::uint32_t BUSYCH3:1; /*!< bit: 3 Busy Channel 3 */ - std::uint32_t BUSYCH4:1; /*!< bit: 4 Busy Channel 4 */ - std::uint32_t BUSYCH5:1; /*!< bit: 5 Busy Channel 5 */ - std::uint32_t BUSYCH6:1; /*!< bit: 6 Busy Channel 6 */ - std::uint32_t BUSYCH7:1; /*!< bit: 7 Busy Channel 7 */ - std::uint32_t BUSYCH8:1; /*!< bit: 8 Busy Channel 8 */ - std::uint32_t BUSYCH9:1; /*!< bit: 9 Busy Channel 9 */ - std::uint32_t BUSYCH10:1; /*!< bit: 10 Busy Channel 10 */ - std::uint32_t BUSYCH11:1; /*!< bit: 11 Busy Channel 11 */ - std::uint32_t :20; /*!< bit: 12..31 Reserved */ + uint32_t BUSYCH0:1; /*!< bit: 0 Busy Channel 0 */ + uint32_t BUSYCH1:1; /*!< bit: 1 Busy Channel 1 */ + uint32_t BUSYCH2:1; /*!< bit: 2 Busy Channel 2 */ + uint32_t BUSYCH3:1; /*!< bit: 3 Busy Channel 3 */ + uint32_t BUSYCH4:1; /*!< bit: 4 Busy Channel 4 */ + uint32_t BUSYCH5:1; /*!< bit: 5 Busy Channel 5 */ + uint32_t BUSYCH6:1; /*!< bit: 6 Busy Channel 6 */ + uint32_t BUSYCH7:1; /*!< bit: 7 Busy Channel 7 */ + uint32_t BUSYCH8:1; /*!< bit: 8 Busy Channel 8 */ + uint32_t BUSYCH9:1; /*!< bit: 9 Busy Channel 9 */ + uint32_t BUSYCH10:1; /*!< bit: 10 Busy Channel 10 */ + uint32_t BUSYCH11:1; /*!< bit: 11 Busy Channel 11 */ + uint32_t :20; /*!< bit: 12..31 Reserved */ } bit; /*!< Structure used for bit access */ struct { - std::uint32_t BUSYCH:12; /*!< bit: 0..11 Busy Channel x */ - std::uint32_t :20; /*!< bit: 12..31 Reserved */ + uint32_t BUSYCH:12; /*!< bit: 0..11 Busy Channel x */ + uint32_t :20; /*!< bit: 12..31 Reserved */ } vec; /*!< Structure used for vec access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } EVSYS_BUSYCH_Type; typedef union { struct { - std::uint32_t READYUSR0:1; /*!< bit: 0 Ready User for Channel 0 */ - std::uint32_t READYUSR1:1; /*!< bit: 1 Ready User for Channel 1 */ - std::uint32_t READYUSR2:1; /*!< bit: 2 Ready User for Channel 2 */ - std::uint32_t READYUSR3:1; /*!< bit: 3 Ready User for Channel 3 */ - std::uint32_t READYUSR4:1; /*!< bit: 4 Ready User for Channel 4 */ - std::uint32_t READYUSR5:1; /*!< bit: 5 Ready User for Channel 5 */ - std::uint32_t READYUSR6:1; /*!< bit: 6 Ready User for Channel 6 */ - std::uint32_t READYUSR7:1; /*!< bit: 7 Ready User for Channel 7 */ - std::uint32_t READYUSR8:1; /*!< bit: 8 Ready User for Channel 8 */ - std::uint32_t READYUSR9:1; /*!< bit: 9 Ready User for Channel 9 */ - std::uint32_t READYUSR10:1; /*!< bit: 10 Ready User for Channel 10 */ - std::uint32_t READYUSR11:1; /*!< bit: 11 Ready User for Channel 11 */ - std::uint32_t :20; /*!< bit: 12..31 Reserved */ + uint32_t READYUSR0:1; /*!< bit: 0 Ready User for Channel 0 */ + uint32_t READYUSR1:1; /*!< bit: 1 Ready User for Channel 1 */ + uint32_t READYUSR2:1; /*!< bit: 2 Ready User for Channel 2 */ + uint32_t READYUSR3:1; /*!< bit: 3 Ready User for Channel 3 */ + uint32_t READYUSR4:1; /*!< bit: 4 Ready User for Channel 4 */ + uint32_t READYUSR5:1; /*!< bit: 5 Ready User for Channel 5 */ + uint32_t READYUSR6:1; /*!< bit: 6 Ready User for Channel 6 */ + uint32_t READYUSR7:1; /*!< bit: 7 Ready User for Channel 7 */ + uint32_t READYUSR8:1; /*!< bit: 8 Ready User for Channel 8 */ + uint32_t READYUSR9:1; /*!< bit: 9 Ready User for Channel 9 */ + uint32_t READYUSR10:1; /*!< bit: 10 Ready User for Channel 10 */ + uint32_t READYUSR11:1; /*!< bit: 11 Ready User for Channel 11 */ + uint32_t :20; /*!< bit: 12..31 Reserved */ } bit; /*!< Structure used for bit access */ struct { - std::uint32_t READYUSR:12; /*!< bit: 0..11 Ready User for Channel x */ - std::uint32_t :20; /*!< bit: 12..31 Reserved */ + uint32_t READYUSR:12; /*!< bit: 0..11 Ready User for Channel x */ + uint32_t :20; /*!< bit: 12..31 Reserved */ } vec; /*!< Structure used for vec access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } EVSYS_READYUSR_Type; typedef union { struct { - std::uint32_t EVGEN:7; /*!< bit: 0.. 6 Event Generator Selection */ - std::uint32_t :1; /*!< bit: 7 Reserved */ - std::uint32_t PATH:2; /*!< bit: 8.. 9 Path Selection */ - std::uint32_t EDGSEL:2; /*!< bit: 10..11 Edge Detection Selection */ - std::uint32_t :2; /*!< bit: 12..13 Reserved */ - std::uint32_t RUNSTDBY:1; /*!< bit: 14 Run in standby */ - std::uint32_t ONDEMAND:1; /*!< bit: 15 Generic Clock On Demand */ - std::uint32_t :16; /*!< bit: 16..31 Reserved */ + uint32_t EVGEN:7; /*!< bit: 0.. 6 Event Generator Selection */ + uint32_t :1; /*!< bit: 7 Reserved */ + uint32_t PATH:2; /*!< bit: 8.. 9 Path Selection */ + uint32_t EDGSEL:2; /*!< bit: 10..11 Edge Detection Selection */ + uint32_t :2; /*!< bit: 12..13 Reserved */ + uint32_t RUNSTDBY:1; /*!< bit: 14 Run in standby */ + uint32_t ONDEMAND:1; /*!< bit: 15 Generic Clock On Demand */ + uint32_t :16; /*!< bit: 16..31 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } EVSYS_CHANNEL_Type; typedef union { struct { - std::uint8_t OVR:1; /*!< bit: 0 Channel Overrun Interrupt Disable */ - std::uint8_t EVD:1; /*!< bit: 1 Channel Event Detected Interrupt Disable */ - std::uint8_t :6; /*!< bit: 2.. 7 Reserved */ + uint8_t OVR:1; /*!< bit: 0 Channel Overrun Interrupt Disable */ + uint8_t EVD:1; /*!< bit: 1 Channel Event Detected Interrupt Disable */ + uint8_t :6; /*!< bit: 2.. 7 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } EVSYS_CHINTENCLR_Type; typedef union { struct { - std::uint8_t OVR:1; /*!< bit: 0 Channel Overrun Interrupt Enable */ - std::uint8_t EVD:1; /*!< bit: 1 Channel Event Detected Interrupt Enable */ - std::uint8_t :6; /*!< bit: 2.. 7 Reserved */ + uint8_t OVR:1; /*!< bit: 0 Channel Overrun Interrupt Enable */ + uint8_t EVD:1; /*!< bit: 1 Channel Event Detected Interrupt Enable */ + uint8_t :6; /*!< bit: 2.. 7 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } EVSYS_CHINTENSET_Type; typedef union { // __I to avoid read-modify-write on write-to-clear register struct { - __I std::uint8_t OVR:1; /*!< bit: 0 Channel Overrun */ - __I std::uint8_t EVD:1; /*!< bit: 1 Channel Event Detected */ - __I std::uint8_t :6; /*!< bit: 2.. 7 Reserved */ + __I uint8_t OVR:1; /*!< bit: 0 Channel Overrun */ + __I uint8_t EVD:1; /*!< bit: 1 Channel Event Detected */ + __I uint8_t :6; /*!< bit: 2.. 7 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } EVSYS_CHINTFLAG_Type; typedef union { struct { - std::uint8_t RDYUSR:1; /*!< bit: 0 Ready User */ - std::uint8_t BUSYCH:1; /*!< bit: 1 Busy Channel */ - std::uint8_t :6; /*!< bit: 2.. 7 Reserved */ + uint8_t RDYUSR:1; /*!< bit: 0 Ready User */ + uint8_t BUSYCH:1; /*!< bit: 1 Busy Channel */ + uint8_t :6; /*!< bit: 2.. 7 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } EVSYS_CHSTATUS_Type; typedef union { struct { - std::uint32_t CHANNEL:6; /*!< bit: 0.. 5 Channel Event Selection */ - std::uint32_t :26; /*!< bit: 6..31 Reserved */ + uint32_t CHANNEL:6; /*!< bit: 0.. 5 Channel Event Selection */ + uint32_t :26; /*!< bit: 6..31 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } EVSYS_USER_Type; typedef struct { @@ -522,258 +522,258 @@ typedef struct { typedef union { struct { - std::uint32_t SWRST:1; /*!< bit: 0 Software Reset */ - std::uint32_t ENABLE:1; /*!< bit: 1 Enable */ - std::uint32_t MODE:2; /*!< bit: 2.. 3 Timer Counter Mode */ - std::uint32_t PRESCSYNC:2; /*!< bit: 4.. 5 Prescaler and Counter Synchronization */ - std::uint32_t RUNSTDBY:1; /*!< bit: 6 Run during Standby */ - std::uint32_t ONDEMAND:1; /*!< bit: 7 Clock On Demand */ - std::uint32_t PRESCALER:3; /*!< bit: 8..10 Prescaler */ - std::uint32_t ALOCK:1; /*!< bit: 11 Auto Lock */ - std::uint32_t :4; /*!< bit: 12..15 Reserved */ - std::uint32_t CAPTEN0:1; /*!< bit: 16 Capture Channel 0 Enable */ - std::uint32_t CAPTEN1:1; /*!< bit: 17 Capture Channel 1 Enable */ - std::uint32_t :2; /*!< bit: 18..19 Reserved */ - std::uint32_t COPEN0:1; /*!< bit: 20 Capture On Pin 0 Enable */ - std::uint32_t COPEN1:1; /*!< bit: 21 Capture On Pin 1 Enable */ - std::uint32_t :2; /*!< bit: 22..23 Reserved */ - std::uint32_t CAPTMODE0:2; /*!< bit: 24..25 Capture Mode Channel 0 */ - std::uint32_t :1; /*!< bit: 26 Reserved */ - std::uint32_t CAPTMODE1:2; /*!< bit: 27..28 Capture mode Channel 1 */ - std::uint32_t :3; /*!< bit: 29..31 Reserved */ - } bit; /*!< Structure used for bit access */ - struct { - std::uint32_t :16; /*!< bit: 0..15 Reserved */ - std::uint32_t CAPTEN:2; /*!< bit: 16..17 Capture Channel x Enable */ - std::uint32_t :2; /*!< bit: 18..19 Reserved */ - std::uint32_t COPEN:2; /*!< bit: 20..21 Capture On Pin x Enable */ - std::uint32_t :10; /*!< bit: 22..31 Reserved */ + uint32_t SWRST:1; /*!< bit: 0 Software Reset */ + uint32_t ENABLE:1; /*!< bit: 1 Enable */ + uint32_t MODE:2; /*!< bit: 2.. 3 Timer Counter Mode */ + uint32_t PRESCSYNC:2; /*!< bit: 4.. 5 Prescaler and Counter Synchronization */ + uint32_t RUNSTDBY:1; /*!< bit: 6 Run during Standby */ + uint32_t ONDEMAND:1; /*!< bit: 7 Clock On Demand */ + uint32_t PRESCALER:3; /*!< bit: 8..10 Prescaler */ + uint32_t ALOCK:1; /*!< bit: 11 Auto Lock */ + uint32_t :4; /*!< bit: 12..15 Reserved */ + uint32_t CAPTEN0:1; /*!< bit: 16 Capture Channel 0 Enable */ + uint32_t CAPTEN1:1; /*!< bit: 17 Capture Channel 1 Enable */ + uint32_t :2; /*!< bit: 18..19 Reserved */ + uint32_t COPEN0:1; /*!< bit: 20 Capture On Pin 0 Enable */ + uint32_t COPEN1:1; /*!< bit: 21 Capture On Pin 1 Enable */ + uint32_t :2; /*!< bit: 22..23 Reserved */ + uint32_t CAPTMODE0:2; /*!< bit: 24..25 Capture Mode Channel 0 */ + uint32_t :1; /*!< bit: 26 Reserved */ + uint32_t CAPTMODE1:2; /*!< bit: 27..28 Capture mode Channel 1 */ + uint32_t :3; /*!< bit: 29..31 Reserved */ + } bit; /*!< Structure used for bit access */ + struct { + uint32_t :16; /*!< bit: 0..15 Reserved */ + uint32_t CAPTEN:2; /*!< bit: 16..17 Capture Channel x Enable */ + uint32_t :2; /*!< bit: 18..19 Reserved */ + uint32_t COPEN:2; /*!< bit: 20..21 Capture On Pin x Enable */ + uint32_t :10; /*!< bit: 22..31 Reserved */ } vec; /*!< Structure used for vec access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } TC_CTRLA_Type; typedef union { struct { - std::uint8_t DIR:1; /*!< bit: 0 Counter Direction */ - std::uint8_t LUPD:1; /*!< bit: 1 Lock Update */ - std::uint8_t ONESHOT:1; /*!< bit: 2 One-Shot on Counter */ - std::uint8_t :2; /*!< bit: 3.. 4 Reserved */ - std::uint8_t CMD:3; /*!< bit: 5.. 7 Command */ + uint8_t DIR:1; /*!< bit: 0 Counter Direction */ + uint8_t LUPD:1; /*!< bit: 1 Lock Update */ + uint8_t ONESHOT:1; /*!< bit: 2 One-Shot on Counter */ + uint8_t :2; /*!< bit: 3.. 4 Reserved */ + uint8_t CMD:3; /*!< bit: 5.. 7 Command */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } TC_CTRLBCLR_Type; typedef union { struct { - std::uint8_t DIR:1; /*!< bit: 0 Counter Direction */ - std::uint8_t LUPD:1; /*!< bit: 1 Lock Update */ - std::uint8_t ONESHOT:1; /*!< bit: 2 One-Shot on Counter */ - std::uint8_t :2; /*!< bit: 3.. 4 Reserved */ - std::uint8_t CMD:3; /*!< bit: 5.. 7 Command */ + uint8_t DIR:1; /*!< bit: 0 Counter Direction */ + uint8_t LUPD:1; /*!< bit: 1 Lock Update */ + uint8_t ONESHOT:1; /*!< bit: 2 One-Shot on Counter */ + uint8_t :2; /*!< bit: 3.. 4 Reserved */ + uint8_t CMD:3; /*!< bit: 5.. 7 Command */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } TC_CTRLBSET_Type; typedef union { struct { - std::uint16_t EVACT:3; /*!< bit: 0.. 2 Event Action */ - std::uint16_t :1; /*!< bit: 3 Reserved */ - std::uint16_t TCINV:1; /*!< bit: 4 TC Event Input Polarity */ - std::uint16_t TCEI:1; /*!< bit: 5 TC Event Enable */ - std::uint16_t :2; /*!< bit: 6.. 7 Reserved */ - std::uint16_t OVFEO:1; /*!< bit: 8 Event Output Enable */ - std::uint16_t :3; /*!< bit: 9..11 Reserved */ - std::uint16_t MCEO0:1; /*!< bit: 12 MC Event Output Enable 0 */ - std::uint16_t MCEO1:1; /*!< bit: 13 MC Event Output Enable 1 */ - std::uint16_t :2; /*!< bit: 14..15 Reserved */ + uint16_t EVACT:3; /*!< bit: 0.. 2 Event Action */ + uint16_t :1; /*!< bit: 3 Reserved */ + uint16_t TCINV:1; /*!< bit: 4 TC Event Input Polarity */ + uint16_t TCEI:1; /*!< bit: 5 TC Event Enable */ + uint16_t :2; /*!< bit: 6.. 7 Reserved */ + uint16_t OVFEO:1; /*!< bit: 8 Event Output Enable */ + uint16_t :3; /*!< bit: 9..11 Reserved */ + uint16_t MCEO0:1; /*!< bit: 12 MC Event Output Enable 0 */ + uint16_t MCEO1:1; /*!< bit: 13 MC Event Output Enable 1 */ + uint16_t :2; /*!< bit: 14..15 Reserved */ } bit; /*!< Structure used for bit access */ struct { - std::uint16_t :12; /*!< bit: 0..11 Reserved */ - std::uint16_t MCEO:2; /*!< bit: 12..13 MC Event Output Enable x */ - std::uint16_t :2; /*!< bit: 14..15 Reserved */ + uint16_t :12; /*!< bit: 0..11 Reserved */ + uint16_t MCEO:2; /*!< bit: 12..13 MC Event Output Enable x */ + uint16_t :2; /*!< bit: 14..15 Reserved */ } vec; /*!< Structure used for vec access */ - std::uint16_t reg; /*!< Type used for register access */ + uint16_t reg; /*!< Type used for register access */ } TC_EVCTRL_Type; typedef union { struct { - std::uint8_t OVF:1; /*!< bit: 0 OVF Interrupt Disable */ - std::uint8_t ERR:1; /*!< bit: 1 ERR Interrupt Disable */ - std::uint8_t :2; /*!< bit: 2.. 3 Reserved */ - std::uint8_t MC0:1; /*!< bit: 4 MC Interrupt Disable 0 */ - std::uint8_t MC1:1; /*!< bit: 5 MC Interrupt Disable 1 */ - std::uint8_t :2; /*!< bit: 6.. 7 Reserved */ + uint8_t OVF:1; /*!< bit: 0 OVF Interrupt Disable */ + uint8_t ERR:1; /*!< bit: 1 ERR Interrupt Disable */ + uint8_t :2; /*!< bit: 2.. 3 Reserved */ + uint8_t MC0:1; /*!< bit: 4 MC Interrupt Disable 0 */ + uint8_t MC1:1; /*!< bit: 5 MC Interrupt Disable 1 */ + uint8_t :2; /*!< bit: 6.. 7 Reserved */ } bit; /*!< Structure used for bit access */ struct { - std::uint8_t :4; /*!< bit: 0.. 3 Reserved */ - std::uint8_t MC:2; /*!< bit: 4.. 5 MC Interrupt Disable x */ - std::uint8_t :2; /*!< bit: 6.. 7 Reserved */ + uint8_t :4; /*!< bit: 0.. 3 Reserved */ + uint8_t MC:2; /*!< bit: 4.. 5 MC Interrupt Disable x */ + uint8_t :2; /*!< bit: 6.. 7 Reserved */ } vec; /*!< Structure used for vec access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } TC_INTENCLR_Type; typedef union { struct { - std::uint8_t OVF:1; /*!< bit: 0 OVF Interrupt Enable */ - std::uint8_t ERR:1; /*!< bit: 1 ERR Interrupt Enable */ - std::uint8_t :2; /*!< bit: 2.. 3 Reserved */ - std::uint8_t MC0:1; /*!< bit: 4 MC Interrupt Enable 0 */ - std::uint8_t MC1:1; /*!< bit: 5 MC Interrupt Enable 1 */ - std::uint8_t :2; /*!< bit: 6.. 7 Reserved */ + uint8_t OVF:1; /*!< bit: 0 OVF Interrupt Enable */ + uint8_t ERR:1; /*!< bit: 1 ERR Interrupt Enable */ + uint8_t :2; /*!< bit: 2.. 3 Reserved */ + uint8_t MC0:1; /*!< bit: 4 MC Interrupt Enable 0 */ + uint8_t MC1:1; /*!< bit: 5 MC Interrupt Enable 1 */ + uint8_t :2; /*!< bit: 6.. 7 Reserved */ } bit; /*!< Structure used for bit access */ struct { - std::uint8_t :4; /*!< bit: 0.. 3 Reserved */ - std::uint8_t MC:2; /*!< bit: 4.. 5 MC Interrupt Enable x */ - std::uint8_t :2; /*!< bit: 6.. 7 Reserved */ + uint8_t :4; /*!< bit: 0.. 3 Reserved */ + uint8_t MC:2; /*!< bit: 4.. 5 MC Interrupt Enable x */ + uint8_t :2; /*!< bit: 6.. 7 Reserved */ } vec; /*!< Structure used for vec access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } TC_INTENSET_Type; typedef union { // __I to avoid read-modify-write on write-to-clear register struct { - __I std::uint8_t OVF:1; /*!< bit: 0 OVF Interrupt Flag */ - __I std::uint8_t ERR:1; /*!< bit: 1 ERR Interrupt Flag */ - __I std::uint8_t :2; /*!< bit: 2.. 3 Reserved */ - __I std::uint8_t MC0:1; /*!< bit: 4 MC Interrupt Flag 0 */ - __I std::uint8_t MC1:1; /*!< bit: 5 MC Interrupt Flag 1 */ - __I std::uint8_t :2; /*!< bit: 6.. 7 Reserved */ + __I uint8_t OVF:1; /*!< bit: 0 OVF Interrupt Flag */ + __I uint8_t ERR:1; /*!< bit: 1 ERR Interrupt Flag */ + __I uint8_t :2; /*!< bit: 2.. 3 Reserved */ + __I uint8_t MC0:1; /*!< bit: 4 MC Interrupt Flag 0 */ + __I uint8_t MC1:1; /*!< bit: 5 MC Interrupt Flag 1 */ + __I uint8_t :2; /*!< bit: 6.. 7 Reserved */ } bit; /*!< Structure used for bit access */ struct { - __I std::uint8_t :4; /*!< bit: 0.. 3 Reserved */ - __I std::uint8_t MC:2; /*!< bit: 4.. 5 MC Interrupt Flag x */ - __I std::uint8_t :2; /*!< bit: 6.. 7 Reserved */ + __I uint8_t :4; /*!< bit: 0.. 3 Reserved */ + __I uint8_t MC:2; /*!< bit: 4.. 5 MC Interrupt Flag x */ + __I uint8_t :2; /*!< bit: 6.. 7 Reserved */ } vec; /*!< Structure used for vec access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } TC_INTFLAG_Type; typedef union { struct { - std::uint8_t STOP:1; /*!< bit: 0 Stop Status Flag */ - std::uint8_t SLAVE:1; /*!< bit: 1 Slave Status Flag */ - std::uint8_t :1; /*!< bit: 2 Reserved */ - std::uint8_t PERBUFV:1; /*!< bit: 3 Synchronization Busy Status */ - std::uint8_t CCBUFV0:1; /*!< bit: 4 Compare channel buffer 0 valid */ - std::uint8_t CCBUFV1:1; /*!< bit: 5 Compare channel buffer 1 valid */ - std::uint8_t :2; /*!< bit: 6.. 7 Reserved */ + uint8_t STOP:1; /*!< bit: 0 Stop Status Flag */ + uint8_t SLAVE:1; /*!< bit: 1 Slave Status Flag */ + uint8_t :1; /*!< bit: 2 Reserved */ + uint8_t PERBUFV:1; /*!< bit: 3 Synchronization Busy Status */ + uint8_t CCBUFV0:1; /*!< bit: 4 Compare channel buffer 0 valid */ + uint8_t CCBUFV1:1; /*!< bit: 5 Compare channel buffer 1 valid */ + uint8_t :2; /*!< bit: 6.. 7 Reserved */ } bit; /*!< Structure used for bit access */ struct { - std::uint8_t :4; /*!< bit: 0.. 3 Reserved */ - std::uint8_t CCBUFV:2; /*!< bit: 4.. 5 Compare channel buffer x valid */ - std::uint8_t :2; /*!< bit: 6.. 7 Reserved */ + uint8_t :4; /*!< bit: 0.. 3 Reserved */ + uint8_t CCBUFV:2; /*!< bit: 4.. 5 Compare channel buffer x valid */ + uint8_t :2; /*!< bit: 6.. 7 Reserved */ } vec; /*!< Structure used for vec access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } TC_STATUS_Type; typedef union { struct { - std::uint8_t WAVEGEN:2; /*!< bit: 0.. 1 Waveform Generation Mode */ - std::uint8_t :6; /*!< bit: 2.. 7 Reserved */ + uint8_t WAVEGEN:2; /*!< bit: 0.. 1 Waveform Generation Mode */ + uint8_t :6; /*!< bit: 2.. 7 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } TC_WAVE_Type; typedef union { struct { - std::uint8_t INVEN0:1; /*!< bit: 0 Output Waveform Invert Enable 0 */ - std::uint8_t INVEN1:1; /*!< bit: 1 Output Waveform Invert Enable 1 */ - std::uint8_t :6; /*!< bit: 2.. 7 Reserved */ + uint8_t INVEN0:1; /*!< bit: 0 Output Waveform Invert Enable 0 */ + uint8_t INVEN1:1; /*!< bit: 1 Output Waveform Invert Enable 1 */ + uint8_t :6; /*!< bit: 2.. 7 Reserved */ } bit; /*!< Structure used for bit access */ struct { - std::uint8_t INVEN:2; /*!< bit: 0.. 1 Output Waveform Invert Enable x */ - std::uint8_t :6; /*!< bit: 2.. 7 Reserved */ + uint8_t INVEN:2; /*!< bit: 0.. 1 Output Waveform Invert Enable x */ + uint8_t :6; /*!< bit: 2.. 7 Reserved */ } vec; /*!< Structure used for vec access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } TC_DRVCTRL_Type; typedef union { struct { - std::uint8_t DBGRUN:1; /*!< bit: 0 Run During Debug */ - std::uint8_t :7; /*!< bit: 1.. 7 Reserved */ + uint8_t DBGRUN:1; /*!< bit: 0 Run During Debug */ + uint8_t :7; /*!< bit: 1.. 7 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } TC_DBGCTRL_Type; typedef union { struct { - std::uint32_t SWRST:1; /*!< bit: 0 swrst */ - std::uint32_t ENABLE:1; /*!< bit: 1 enable */ - std::uint32_t CTRLB:1; /*!< bit: 2 CTRLB */ - std::uint32_t STATUS:1; /*!< bit: 3 STATUS */ - std::uint32_t COUNT:1; /*!< bit: 4 Counter */ - std::uint32_t PER:1; /*!< bit: 5 Period */ - std::uint32_t CC0:1; /*!< bit: 6 Compare Channel 0 */ - std::uint32_t CC1:1; /*!< bit: 7 Compare Channel 1 */ - std::uint32_t :24; /*!< bit: 8..31 Reserved */ + uint32_t SWRST:1; /*!< bit: 0 swrst */ + uint32_t ENABLE:1; /*!< bit: 1 enable */ + uint32_t CTRLB:1; /*!< bit: 2 CTRLB */ + uint32_t STATUS:1; /*!< bit: 3 STATUS */ + uint32_t COUNT:1; /*!< bit: 4 Counter */ + uint32_t PER:1; /*!< bit: 5 Period */ + uint32_t CC0:1; /*!< bit: 6 Compare Channel 0 */ + uint32_t CC1:1; /*!< bit: 7 Compare Channel 1 */ + uint32_t :24; /*!< bit: 8..31 Reserved */ } bit; /*!< Structure used for bit access */ struct { - std::uint32_t :6; /*!< bit: 0.. 5 Reserved */ - std::uint32_t CC:2; /*!< bit: 6.. 7 Compare Channel x */ - std::uint32_t :24; /*!< bit: 8..31 Reserved */ + uint32_t :6; /*!< bit: 0.. 5 Reserved */ + uint32_t CC:2; /*!< bit: 6.. 7 Compare Channel x */ + uint32_t :24; /*!< bit: 8..31 Reserved */ } vec; /*!< Structure used for vec access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } TC_SYNCBUSY_Type; typedef union { struct { - std::uint16_t COUNT:16; /*!< bit: 0..15 Counter Value */ + uint16_t COUNT:16; /*!< bit: 0..15 Counter Value */ } bit; /*!< Structure used for bit access */ - std::uint16_t reg; /*!< Type used for register access */ + uint16_t reg; /*!< Type used for register access */ } TC_COUNT16_COUNT_Type; typedef union { struct { - std::uint32_t COUNT:32; /*!< bit: 0..31 Counter Value */ + uint32_t COUNT:32; /*!< bit: 0..31 Counter Value */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } TC_COUNT32_COUNT_Type; typedef union { struct { - std::uint8_t COUNT:8; /*!< bit: 0.. 7 Counter Value */ + uint8_t COUNT:8; /*!< bit: 0.. 7 Counter Value */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } TC_COUNT8_COUNT_Type; typedef union { struct { - std::uint8_t PER:8; /*!< bit: 0.. 7 Period Value */ + uint8_t PER:8; /*!< bit: 0.. 7 Period Value */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } TC_COUNT8_PER_Type; typedef union { struct { - std::uint16_t CC:16; /*!< bit: 0..15 Counter/Compare Value */ + uint16_t CC:16; /*!< bit: 0..15 Counter/Compare Value */ } bit; /*!< Structure used for bit access */ - std::uint16_t reg; /*!< Type used for register access */ + uint16_t reg; /*!< Type used for register access */ } TC_COUNT16_CC_Type; typedef union { struct { - std::uint32_t CC:32; /*!< bit: 0..31 Counter/Compare Value */ + uint32_t CC:32; /*!< bit: 0..31 Counter/Compare Value */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } TC_COUNT32_CC_Type; typedef union { struct { - std::uint8_t CC:8; /*!< bit: 0.. 7 Counter/Compare Value */ + uint8_t CC:8; /*!< bit: 0.. 7 Counter/Compare Value */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } TC_COUNT8_CC_Type; typedef union { struct { - std::uint8_t PERBUF:8; /*!< bit: 0.. 7 Period Buffer Value */ + uint8_t PERBUF:8; /*!< bit: 0.. 7 Period Buffer Value */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } TC_COUNT8_PERBUF_Type; typedef union { struct { - std::uint8_t CCBUF:8; /*!< bit: 0.. 7 Counter/Compare Buffer Value */ + uint8_t CCBUF:8; /*!< bit: 0.. 7 Counter/Compare Buffer Value */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } TC_COUNT8_CCBUF_Type; typedef struct { /* 8-bit Counter Mode */ @@ -807,128 +807,128 @@ typedef union { typedef union { struct { - std::uint32_t DIR:32; /*!< bit: 0..31 Port Data Direction */ + uint32_t DIR:32; /*!< bit: 0..31 Port Data Direction */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } PORT_DIR_Type; typedef union { struct { - std::uint32_t DIRCLR:32; /*!< bit: 0..31 Port Data Direction Clear */ + uint32_t DIRCLR:32; /*!< bit: 0..31 Port Data Direction Clear */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } PORT_DIRCLR_Type; typedef union { struct { - std::uint32_t DIRSET:32; /*!< bit: 0..31 Port Data Direction Set */ + uint32_t DIRSET:32; /*!< bit: 0..31 Port Data Direction Set */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } PORT_DIRSET_Type; typedef union { struct { - std::uint32_t DIRTGL:32; /*!< bit: 0..31 Port Data Direction Toggle */ + uint32_t DIRTGL:32; /*!< bit: 0..31 Port Data Direction Toggle */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } PORT_DIRTGL_Type; typedef union { struct { - std::uint32_t OUT:32; /*!< bit: 0..31 PORT Data Output Value */ + uint32_t OUT:32; /*!< bit: 0..31 PORT Data Output Value */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } PORT_OUT_Type; typedef union { struct { - std::uint32_t OUTCLR:32; /*!< bit: 0..31 PORT Data Output Value Clear */ + uint32_t OUTCLR:32; /*!< bit: 0..31 PORT Data Output Value Clear */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } PORT_OUTCLR_Type; typedef union { struct { - std::uint32_t OUTSET:32; /*!< bit: 0..31 PORT Data Output Value Set */ + uint32_t OUTSET:32; /*!< bit: 0..31 PORT Data Output Value Set */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } PORT_OUTSET_Type; typedef union { struct { - std::uint32_t OUTTGL:32; /*!< bit: 0..31 PORT Data Output Value Toggle */ + uint32_t OUTTGL:32; /*!< bit: 0..31 PORT Data Output Value Toggle */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } PORT_OUTTGL_Type; typedef union { struct { - std::uint32_t IN:32; /*!< bit: 0..31 PORT Data Input Value */ + uint32_t IN:32; /*!< bit: 0..31 PORT Data Input Value */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } PORT_IN_Type; typedef union { struct { - std::uint32_t SAMPLING:32; /*!< bit: 0..31 Input Sampling Mode */ + uint32_t SAMPLING:32; /*!< bit: 0..31 Input Sampling Mode */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } PORT_CTRL_Type; typedef union { struct { - std::uint32_t PINMASK:16; /*!< bit: 0..15 Pin Mask for Multiple Pin Configuration */ - std::uint32_t PMUXEN:1; /*!< bit: 16 Peripheral Multiplexer Enable */ - std::uint32_t INEN:1; /*!< bit: 17 Input Enable */ - std::uint32_t PULLEN:1; /*!< bit: 18 Pull Enable */ - std::uint32_t :3; /*!< bit: 19..21 Reserved */ - std::uint32_t DRVSTR:1; /*!< bit: 22 Output Driver Strength Selection */ - std::uint32_t :1; /*!< bit: 23 Reserved */ - std::uint32_t PMUX:4; /*!< bit: 24..27 Peripheral Multiplexing */ - std::uint32_t WRPMUX:1; /*!< bit: 28 Write PMUX */ - std::uint32_t :1; /*!< bit: 29 Reserved */ - std::uint32_t WRPINCFG:1; /*!< bit: 30 Write PINCFG */ - std::uint32_t HWSEL:1; /*!< bit: 31 Half-Word Select */ + uint32_t PINMASK:16; /*!< bit: 0..15 Pin Mask for Multiple Pin Configuration */ + uint32_t PMUXEN:1; /*!< bit: 16 Peripheral Multiplexer Enable */ + uint32_t INEN:1; /*!< bit: 17 Input Enable */ + uint32_t PULLEN:1; /*!< bit: 18 Pull Enable */ + uint32_t :3; /*!< bit: 19..21 Reserved */ + uint32_t DRVSTR:1; /*!< bit: 22 Output Driver Strength Selection */ + uint32_t :1; /*!< bit: 23 Reserved */ + uint32_t PMUX:4; /*!< bit: 24..27 Peripheral Multiplexing */ + uint32_t WRPMUX:1; /*!< bit: 28 Write PMUX */ + uint32_t :1; /*!< bit: 29 Reserved */ + uint32_t WRPINCFG:1; /*!< bit: 30 Write PINCFG */ + uint32_t HWSEL:1; /*!< bit: 31 Half-Word Select */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } PORT_WRCONFIG_Type; typedef union { struct { - std::uint32_t PID0:5; /*!< bit: 0.. 4 PORT Event Pin Identifier 0 */ - std::uint32_t EVACT0:2; /*!< bit: 5.. 6 PORT Event Action 0 */ - std::uint32_t PORTEI0:1; /*!< bit: 7 PORT Event Input Enable 0 */ - std::uint32_t PID1:5; /*!< bit: 8..12 PORT Event Pin Identifier 1 */ - std::uint32_t EVACT1:2; /*!< bit: 13..14 PORT Event Action 1 */ - std::uint32_t PORTEI1:1; /*!< bit: 15 PORT Event Input Enable 1 */ - std::uint32_t PID2:5; /*!< bit: 16..20 PORT Event Pin Identifier 2 */ - std::uint32_t EVACT2:2; /*!< bit: 21..22 PORT Event Action 2 */ - std::uint32_t PORTEI2:1; /*!< bit: 23 PORT Event Input Enable 2 */ - std::uint32_t PID3:5; /*!< bit: 24..28 PORT Event Pin Identifier 3 */ - std::uint32_t EVACT3:2; /*!< bit: 29..30 PORT Event Action 3 */ - std::uint32_t PORTEI3:1; /*!< bit: 31 PORT Event Input Enable 3 */ + uint32_t PID0:5; /*!< bit: 0.. 4 PORT Event Pin Identifier 0 */ + uint32_t EVACT0:2; /*!< bit: 5.. 6 PORT Event Action 0 */ + uint32_t PORTEI0:1; /*!< bit: 7 PORT Event Input Enable 0 */ + uint32_t PID1:5; /*!< bit: 8..12 PORT Event Pin Identifier 1 */ + uint32_t EVACT1:2; /*!< bit: 13..14 PORT Event Action 1 */ + uint32_t PORTEI1:1; /*!< bit: 15 PORT Event Input Enable 1 */ + uint32_t PID2:5; /*!< bit: 16..20 PORT Event Pin Identifier 2 */ + uint32_t EVACT2:2; /*!< bit: 21..22 PORT Event Action 2 */ + uint32_t PORTEI2:1; /*!< bit: 23 PORT Event Input Enable 2 */ + uint32_t PID3:5; /*!< bit: 24..28 PORT Event Pin Identifier 3 */ + uint32_t EVACT3:2; /*!< bit: 29..30 PORT Event Action 3 */ + uint32_t PORTEI3:1; /*!< bit: 31 PORT Event Input Enable 3 */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } PORT_EVCTRL_Type; typedef union { struct { - std::uint8_t PMUXE:4; /*!< bit: 0.. 3 Peripheral Multiplexing for Even-Numbered Pin */ - std::uint8_t PMUXO:4; /*!< bit: 4.. 7 Peripheral Multiplexing for Odd-Numbered Pin */ + uint8_t PMUXE:4; /*!< bit: 0.. 3 Peripheral Multiplexing for Even-Numbered Pin */ + uint8_t PMUXO:4; /*!< bit: 4.. 7 Peripheral Multiplexing for Odd-Numbered Pin */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } PORT_PMUX_Type; typedef union { struct { - std::uint8_t PMUXEN:1; /*!< bit: 0 Peripheral Multiplexer Enable */ - std::uint8_t INEN:1; /*!< bit: 1 Input Enable */ - std::uint8_t PULLEN:1; /*!< bit: 2 Pull Enable */ - std::uint8_t :3; /*!< bit: 3.. 5 Reserved */ - std::uint8_t DRVSTR:1; /*!< bit: 6 Output Driver Strength Selection */ - std::uint8_t :1; /*!< bit: 7 Reserved */ + uint8_t PMUXEN:1; /*!< bit: 0 Peripheral Multiplexer Enable */ + uint8_t INEN:1; /*!< bit: 1 Input Enable */ + uint8_t PULLEN:1; /*!< bit: 2 Pull Enable */ + uint8_t :3; /*!< bit: 3.. 5 Reserved */ + uint8_t DRVSTR:1; /*!< bit: 6 Output Driver Strength Selection */ + uint8_t :1; /*!< bit: 7 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } PORT_PINCFG_Type; typedef struct { @@ -955,151 +955,151 @@ typedef struct { typedef union { struct { - std::uint32_t SWRST:1; /*!< bit: 0 Software Reset */ - std::uint32_t ENABLE:1; /*!< bit: 1 Enable */ - std::uint32_t MODE:3; /*!< bit: 2.. 4 Operating Mode */ - std::uint32_t :2; /*!< bit: 5.. 6 Reserved */ - std::uint32_t RUNSTDBY:1; /*!< bit: 7 Run during Standby */ - std::uint32_t IBON:1; /*!< bit: 8 Immediate Buffer Overflow Notification */ - std::uint32_t :7; /*!< bit: 9..15 Reserved */ - std::uint32_t DOPO:2; /*!< bit: 16..17 Data Out Pinout */ - std::uint32_t :2; /*!< bit: 18..19 Reserved */ - std::uint32_t DIPO:2; /*!< bit: 20..21 Data In Pinout */ - std::uint32_t :2; /*!< bit: 22..23 Reserved */ - std::uint32_t FORM:4; /*!< bit: 24..27 Frame Format */ - std::uint32_t CPHA:1; /*!< bit: 28 Clock Phase */ - std::uint32_t CPOL:1; /*!< bit: 29 Clock Polarity */ - std::uint32_t DORD:1; /*!< bit: 30 Data Order */ - std::uint32_t :1; /*!< bit: 31 Reserved */ - } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t SWRST:1; /*!< bit: 0 Software Reset */ + uint32_t ENABLE:1; /*!< bit: 1 Enable */ + uint32_t MODE:3; /*!< bit: 2.. 4 Operating Mode */ + uint32_t :2; /*!< bit: 5.. 6 Reserved */ + uint32_t RUNSTDBY:1; /*!< bit: 7 Run during Standby */ + uint32_t IBON:1; /*!< bit: 8 Immediate Buffer Overflow Notification */ + uint32_t :7; /*!< bit: 9..15 Reserved */ + uint32_t DOPO:2; /*!< bit: 16..17 Data Out Pinout */ + uint32_t :2; /*!< bit: 18..19 Reserved */ + uint32_t DIPO:2; /*!< bit: 20..21 Data In Pinout */ + uint32_t :2; /*!< bit: 22..23 Reserved */ + uint32_t FORM:4; /*!< bit: 24..27 Frame Format */ + uint32_t CPHA:1; /*!< bit: 28 Clock Phase */ + uint32_t CPOL:1; /*!< bit: 29 Clock Polarity */ + uint32_t DORD:1; /*!< bit: 30 Data Order */ + uint32_t :1; /*!< bit: 31 Reserved */ + } bit; /*!< Structure used for bit access */ + uint32_t reg; /*!< Type used for register access */ } SERCOM_SPI_CTRLA_Type; typedef union { struct { - std::uint32_t CHSIZE:3; /*!< bit: 0.. 2 Character Size */ - std::uint32_t :3; /*!< bit: 3.. 5 Reserved */ - std::uint32_t PLOADEN:1; /*!< bit: 6 Data Preload Enable */ - std::uint32_t :2; /*!< bit: 7.. 8 Reserved */ - std::uint32_t SSDE:1; /*!< bit: 9 Slave Select Low Detect Enable */ - std::uint32_t :3; /*!< bit: 10..12 Reserved */ - std::uint32_t MSSEN:1; /*!< bit: 13 Master Slave Select Enable */ - std::uint32_t AMODE:2; /*!< bit: 14..15 Address Mode */ - std::uint32_t :1; /*!< bit: 16 Reserved */ - std::uint32_t RXEN:1; /*!< bit: 17 Receiver Enable */ - std::uint32_t :14; /*!< bit: 18..31 Reserved */ + uint32_t CHSIZE:3; /*!< bit: 0.. 2 Character Size */ + uint32_t :3; /*!< bit: 3.. 5 Reserved */ + uint32_t PLOADEN:1; /*!< bit: 6 Data Preload Enable */ + uint32_t :2; /*!< bit: 7.. 8 Reserved */ + uint32_t SSDE:1; /*!< bit: 9 Slave Select Low Detect Enable */ + uint32_t :3; /*!< bit: 10..12 Reserved */ + uint32_t MSSEN:1; /*!< bit: 13 Master Slave Select Enable */ + uint32_t AMODE:2; /*!< bit: 14..15 Address Mode */ + uint32_t :1; /*!< bit: 16 Reserved */ + uint32_t RXEN:1; /*!< bit: 17 Receiver Enable */ + uint32_t :14; /*!< bit: 18..31 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } SERCOM_SPI_CTRLB_Type; typedef union { struct { - std::uint32_t ICSPACE:6; /*!< bit: 0.. 5 Inter-Character Spacing */ - std::uint32_t :18; /*!< bit: 6..23 Reserved */ - std::uint32_t DATA32B:1; /*!< bit: 24 Data 32 Bit */ - std::uint32_t :7; /*!< bit: 25..31 Reserved */ + uint32_t ICSPACE:6; /*!< bit: 0.. 5 Inter-Character Spacing */ + uint32_t :18; /*!< bit: 6..23 Reserved */ + uint32_t DATA32B:1; /*!< bit: 24 Data 32 Bit */ + uint32_t :7; /*!< bit: 25..31 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } SERCOM_SPI_CTRLC_Type; typedef union { struct { - std::uint8_t BAUD:8; /*!< bit: 0.. 7 Baud Rate Value */ + uint8_t BAUD:8; /*!< bit: 0.. 7 Baud Rate Value */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } SERCOM_SPI_BAUD_Type; typedef union { struct { - std::uint8_t DRE:1; /*!< bit: 0 Data Register Empty Interrupt Disable */ - std::uint8_t TXC:1; /*!< bit: 1 Transmit Complete Interrupt Disable */ - std::uint8_t RXC:1; /*!< bit: 2 Receive Complete Interrupt Disable */ - std::uint8_t SSL:1; /*!< bit: 3 Slave Select Low Interrupt Disable */ - std::uint8_t :3; /*!< bit: 4.. 6 Reserved */ - std::uint8_t ERROR:1; /*!< bit: 7 Combined Error Interrupt Disable */ + uint8_t DRE:1; /*!< bit: 0 Data Register Empty Interrupt Disable */ + uint8_t TXC:1; /*!< bit: 1 Transmit Complete Interrupt Disable */ + uint8_t RXC:1; /*!< bit: 2 Receive Complete Interrupt Disable */ + uint8_t SSL:1; /*!< bit: 3 Slave Select Low Interrupt Disable */ + uint8_t :3; /*!< bit: 4.. 6 Reserved */ + uint8_t ERROR:1; /*!< bit: 7 Combined Error Interrupt Disable */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } SERCOM_SPI_INTENCLR_Type; typedef union { struct { - std::uint8_t DRE:1; /*!< bit: 0 Data Register Empty Interrupt Enable */ - std::uint8_t TXC:1; /*!< bit: 1 Transmit Complete Interrupt Enable */ - std::uint8_t RXC:1; /*!< bit: 2 Receive Complete Interrupt Enable */ - std::uint8_t SSL:1; /*!< bit: 3 Slave Select Low Interrupt Enable */ - std::uint8_t :3; /*!< bit: 4.. 6 Reserved */ - std::uint8_t ERROR:1; /*!< bit: 7 Combined Error Interrupt Enable */ + uint8_t DRE:1; /*!< bit: 0 Data Register Empty Interrupt Enable */ + uint8_t TXC:1; /*!< bit: 1 Transmit Complete Interrupt Enable */ + uint8_t RXC:1; /*!< bit: 2 Receive Complete Interrupt Enable */ + uint8_t SSL:1; /*!< bit: 3 Slave Select Low Interrupt Enable */ + uint8_t :3; /*!< bit: 4.. 6 Reserved */ + uint8_t ERROR:1; /*!< bit: 7 Combined Error Interrupt Enable */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } SERCOM_SPI_INTENSET_Type; typedef union { // __I to avoid read-modify-write on write-to-clear register struct { - __I std::uint8_t DRE:1; /*!< bit: 0 Data Register Empty Interrupt */ - __I std::uint8_t TXC:1; /*!< bit: 1 Transmit Complete Interrupt */ - __I std::uint8_t RXC:1; /*!< bit: 2 Receive Complete Interrupt */ - __I std::uint8_t SSL:1; /*!< bit: 3 Slave Select Low Interrupt Flag */ - __I std::uint8_t :3; /*!< bit: 4.. 6 Reserved */ - __I std::uint8_t ERROR:1; /*!< bit: 7 Combined Error Interrupt */ + __I uint8_t DRE:1; /*!< bit: 0 Data Register Empty Interrupt */ + __I uint8_t TXC:1; /*!< bit: 1 Transmit Complete Interrupt */ + __I uint8_t RXC:1; /*!< bit: 2 Receive Complete Interrupt */ + __I uint8_t SSL:1; /*!< bit: 3 Slave Select Low Interrupt Flag */ + __I uint8_t :3; /*!< bit: 4.. 6 Reserved */ + __I uint8_t ERROR:1; /*!< bit: 7 Combined Error Interrupt */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } SERCOM_SPI_INTFLAG_Type; typedef union { struct { - std::uint16_t :2; /*!< bit: 0.. 1 Reserved */ - std::uint16_t BUFOVF:1; /*!< bit: 2 Buffer Overflow */ - std::uint16_t :8; /*!< bit: 3..10 Reserved */ - std::uint16_t LENERR:1; /*!< bit: 11 Transaction Length Error */ - std::uint16_t :4; /*!< bit: 12..15 Reserved */ + uint16_t :2; /*!< bit: 0.. 1 Reserved */ + uint16_t BUFOVF:1; /*!< bit: 2 Buffer Overflow */ + uint16_t :8; /*!< bit: 3..10 Reserved */ + uint16_t LENERR:1; /*!< bit: 11 Transaction Length Error */ + uint16_t :4; /*!< bit: 12..15 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint16_t reg; /*!< Type used for register access */ + uint16_t reg; /*!< Type used for register access */ } SERCOM_SPI_STATUS_Type; typedef union { struct { - std::uint32_t SWRST:1; /*!< bit: 0 Software Reset Synchronization Busy */ - std::uint32_t ENABLE:1; /*!< bit: 1 SERCOM Enable Synchronization Busy */ - std::uint32_t CTRLB:1; /*!< bit: 2 CTRLB Synchronization Busy */ - std::uint32_t :1; /*!< bit: 3 Reserved */ - std::uint32_t LENGTH:1; /*!< bit: 4 LENGTH Synchronization Busy */ - std::uint32_t :27; /*!< bit: 5..31 Reserved */ + uint32_t SWRST:1; /*!< bit: 0 Software Reset Synchronization Busy */ + uint32_t ENABLE:1; /*!< bit: 1 SERCOM Enable Synchronization Busy */ + uint32_t CTRLB:1; /*!< bit: 2 CTRLB Synchronization Busy */ + uint32_t :1; /*!< bit: 3 Reserved */ + uint32_t LENGTH:1; /*!< bit: 4 LENGTH Synchronization Busy */ + uint32_t :27; /*!< bit: 5..31 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } SERCOM_SPI_SYNCBUSY_Type; typedef union { struct { - std::uint16_t LEN:8; /*!< bit: 0.. 7 Data Length */ - std::uint16_t LENEN:1; /*!< bit: 8 Data Length Enable */ - std::uint16_t :7; /*!< bit: 9..15 Reserved */ + uint16_t LEN:8; /*!< bit: 0.. 7 Data Length */ + uint16_t LENEN:1; /*!< bit: 8 Data Length Enable */ + uint16_t :7; /*!< bit: 9..15 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint16_t reg; /*!< Type used for register access */ + uint16_t reg; /*!< Type used for register access */ } SERCOM_SPI_LENGTH_Type; typedef union { struct { - std::uint32_t ADDR:8; /*!< bit: 0.. 7 Address Value */ - std::uint32_t :8; /*!< bit: 8..15 Reserved */ - std::uint32_t ADDRMASK:8; /*!< bit: 16..23 Address Mask */ - std::uint32_t :8; /*!< bit: 24..31 Reserved */ + uint32_t ADDR:8; /*!< bit: 0.. 7 Address Value */ + uint32_t :8; /*!< bit: 8..15 Reserved */ + uint32_t ADDRMASK:8; /*!< bit: 16..23 Address Mask */ + uint32_t :8; /*!< bit: 24..31 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } SERCOM_SPI_ADDR_Type; typedef union { struct { - std::uint32_t DATA:32; /*!< bit: 0..31 Data Value */ + uint32_t DATA:32; /*!< bit: 0..31 Data Value */ } bit; /*!< Structure used for bit access */ - std::uint32_t reg; /*!< Type used for register access */ + uint32_t reg; /*!< Type used for register access */ } SERCOM_SPI_DATA_Type; typedef union { struct { - std::uint8_t DBGSTOP:1; /*!< bit: 0 Debug Mode */ - std::uint8_t :7; /*!< bit: 1.. 7 Reserved */ + uint8_t DBGSTOP:1; /*!< bit: 0 Debug Mode */ + uint8_t :7; /*!< bit: 1.. 7 Reserved */ } bit; /*!< Structure used for bit access */ - std::uint8_t reg; /*!< Type used for register access */ + uint8_t reg; /*!< Type used for register access */ } SERCOM_SPI_DBGCTRL_Type; typedef struct { /* SPI Mode */ @@ -1170,8 +1170,8 @@ typedef union { #define TC_INST_NUM 8 /**< \brief (TC) Number of instances */ #define TC_INSTS { TC0, TC1, TC2, TC3, TC4, TC5, TC6, TC7 } /**< \brief (TC) Instances List */ -typedef std::uint32_t SercomSpiTXPad; -typedef std::uint32_t SercomRXPad; +typedef uint32_t SercomSpiTXPad; +typedef uint32_t SercomRXPad; static constexpr SercomSpiTXPad SPI_PAD_3_SCK_1 = 2; static constexpr SercomSpiTXPad SERCOM_RX_PAD_2 = 2; diff --git a/src/lgfx/v1/platforms/spresense/Bus_SPI.cpp b/src/lgfx/v1/platforms/spresense/Bus_SPI.cpp new file mode 100644 index 0000000..11e2289 --- /dev/null +++ b/src/lgfx/v1/platforms/spresense/Bus_SPI.cpp @@ -0,0 +1,352 @@ +/*----------------------------------------------------------------------------/ + Lovyan GFX - Graphics library for embedded devices. + +Original Source: + https://github.com/lovyan03/LovyanGFX/ + +Licence: + [FreeBSD](https://github.com/lovyan03/LovyanGFX/blob/master/license.txt) + +Author: + [lovyan03](https://twitter.com/lovyan03) + +Contributors: + [ciniml](https://github.com/ciniml) + [mongonta0716](https://github.com/mongonta0716) + [tobozo](https://github.com/tobozo) +/----------------------------------------------------------------------------*/ +#if defined (ARDUINO_ARCH_SPRESENSE) + +#include "Bus_SPI.hpp" +#include "../../misc/pixelcopy.hpp" + +#include +#include +#include +#include +#include + +#include +#include + +#include + +namespace lgfx +{ + inline namespace v1 + { +//---------------------------------------------------------------------------- + + static uintptr_t get_gpio_regaddr(uint32_t pin) + { + pin = pin_convert(pin); + uint32_t base = (pin < PIN_IS_CLK) ? 1 : 7; + return CXD56_TOPREG_GP_I2C4_BCK + ((pin - base) * 4); + } + +//---------------------------------------------------------------------------- + + void Bus_SPI::config(const config_t& config) + { + _cfg = config; + + switch (_cfg.spi_port) + { + case 3: _spibase = CXD56_SCU_SPI_BASE; break; + case 4: _spibase = CXD56_IMG_SPI_BASE; break; + case 5: _spibase = CXD56_IMG_WSPI_BASE; break; + default: _spibase = CXD56_SPIM_BASE; break; // SPI 0 + } + _spi_reg_sr = (volatile uint32_t*)(_spibase + CXD56_SPI_SR_OFFSET); + _spi_reg_dr = (volatile uint32_t*)(_spibase + CXD56_SPI_DR_OFFSET); + + _gpio_reg_dc = nullptr; + if (_cfg.pin_dc >= 0) + { + _gpio_reg_dc = get_gpio_regaddr(_cfg.pin_dc); + pinMode(_cfg.pin_dc, pin_mode_t::output); + gpio_hi(_cfg.pin_dc); + } + } + + bool Bus_SPI::init(void) + { + dc_h(); + pinMode(_cfg.pin_dc, pin_mode_t::output); + SPI.begin(); + + _spi_dev = cxd56_spibus_initialize(_cfg.spi_port); + + return true; + } + + void Bus_SPI::release(void) + { + SPI.end(); + } + + void Bus_SPI::beginTransaction(void) + { + dc_h(); + SPISettings setting(_cfg.freq_write, MSBFIRST, _cfg.spi_mode); + SPI.beginTransaction(setting); + + _spi_dev->ops->setbits(_spi_dev, 8); + } + + void Bus_SPI::endTransaction(void) + { + auto sr = _spi_reg_sr; + auto dr = _spi_reg_dr; + while (*sr & (SPI_SR_BSY | SPI_SR_RNE)) { volatile uint32_t dummy = *dr; }; + dc_h(); + SPI.endTransaction(); + } + + void Bus_SPI::beginRead(void) + { + SPI.endTransaction(); + SPISettings setting(_cfg.freq_read, MSBFIRST, _cfg.spi_mode); + SPI.beginTransaction(setting); + + _spi_dev->ops->setbits(_spi_dev, 8); + } + + void Bus_SPI::endRead(void) + { + SPI.endTransaction(); + beginTransaction(); + } + + void Bus_SPI::wait(void) + { + } + + bool Bus_SPI::busy(void) const + { + return false; + } + + bool Bus_SPI::writeCommand(uint32_t data, uint_fast8_t bit_length) + { + auto bytes = bit_length >> 3; + dc_l(); + //SPI.send((uint8_t*)&data, bit_length >> 3); + //SPI_EXCHANGE(_spi_dev, (uint8_t*)&data, nullptr, bit_length >> 3); + //_spi_dev->ops->exchange(_spi_dev, (uint8_t*)&data, nullptr, bit_length >> 3); + +//while ((spi_getreg(priv, CXD56_SPI_SR_OFFSET) & SPI_SR_TNF) + //while (!(*_spi_reg_sr & SPI_SR_TNF)) {} // 送信完了待ち + *_spi_reg_dr = data; + while (--bytes) + { + data >>= 8; + *_spi_reg_dr = data; + } + + return true; + } + + void Bus_SPI::writeData(uint32_t data, uint_fast8_t bit_length) + { + auto bytes = bit_length >> 3; + dc_h(); + //SPI.send((uint8_t*)&data, bit_length >> 3); + //_spi_dev->ops->exchange(_spi_dev, (uint8_t*)&data, nullptr, bit_length >> 3); + //while (!(*_spi_reg_sr & SPI_SR_TNF)) {} // 送信完了待ち + *_spi_reg_dr = data; + while (--bytes) + { + data >>= 8; + *_spi_reg_dr = data; + } + } + + void Bus_SPI::writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t length) + { + auto bytes = bit_length >> 3; + auto buf = (uint8_t*)&data; + auto dr = _spi_reg_dr; + auto sr = _spi_reg_sr; + + if (bytes == 2) + { + data = __builtin_bswap16(data); + auto cr0_reg = (volatile uint32_t*)(_spibase + CXD56_SPI_CR0_OFFSET); + uint32_t cr0 = *cr0_reg; + cr0 |= 0x0F; // 16bit len setting + dc_h(); + *cr0_reg = cr0; + do + { + while (!(*sr & SPI_SR_TNF)) {} + *dr = data; + } while (--length); + cr0 &= ~0x08; // 8bit len setting + while (*sr & SPI_SR_BSY) {} + *cr0_reg = cr0; + return; + } + + dc_h(); + do + { + for (size_t b = 0; b < bytes; ++b) + { + while (!(*sr & SPI_SR_TNF)) {} + *dr = buf[b]; + } +/* + writeData(data, bit_length); +//*/ + //SPI.send(reinterpret_cast(&data), bytes); + } while (--length); +/*/ + dc_h(); + const uint8_t dst_bytes = bit_length >> 3; + uint32_t limit = (dst_bytes == 3) ? 12 : 16; + auto buf = _flip_buffer.getBuffer(512); + size_t fillpos = 0; + reinterpret_cast(buf)[0] = data; + fillpos += dst_bytes; + uint32_t len; + do + { + len = ((length - 1) % limit) + 1; + if (limit <= 64) limit <<= 1; + + while (fillpos < len * dst_bytes) + { + memcpy(&buf[fillpos], buf, fillpos); + fillpos += fillpos; + } + + SPI.send(buf, len * dst_bytes); + } while (length -= len); +//*/ + } + + void Bus_SPI::writePixels(pixelcopy_t* param, uint32_t length) + { + auto dr = _spi_reg_dr; + auto sr = _spi_reg_sr; + const uint8_t dst_bytes = param->dst_bits >> 3; + uint8_t buf[18]; + uint32_t limit = 18 / dst_bytes; + +auto cr0_reg = (volatile uint32_t*)(_spibase + CXD56_SPI_CR0_OFFSET); +uint32_t cr0 = *cr0_reg; +bool en16 = false; + + dc_h(); + uint32_t len; + do + { +// len = ((length - 1) % limit) + 1; + len = std::min(length, limit); + param->fp_copy(buf, 0, len, param); + auto b = buf; + auto l = len * dst_bytes; + if ((l & 1) == en16) + { + en16 = !en16; + while (!(*sr & SPI_SR_TFE)) {} + *cr0_reg = cr0 | (en16 ? 8 : 0); + } + if (en16) + { + do + { + while (!(*sr & SPI_SR_TNF)) {} + *dr = b[0]<<8 | b[1]; + b += 2; + } while (l -= 2); + } + else + { + do + { + while (!(*sr & SPI_SR_TNF)) {} + *dr = *b++; + } while (--l); + } + } while (length -= len); + + if (en16) + { + while (!(*sr & SPI_SR_TFE)) {} + *cr0_reg = cr0; + } + } + + void Bus_SPI::writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) + { + auto dr = _spi_reg_dr; + auto sr = _spi_reg_sr; + if (!dc) dc_l(); + else dc_h(); + do + { + uint32_t tmp = *data++; + while (!(*sr & SPI_SR_TNF)) {} + *dr = tmp; + } while (--length); +/*/ + SPI.send(const_cast(data), length); +//*/ +/* + auto reg_dma = (volatile uint32_t*)(_spibase + CXD56_SPI_DMACR_OFFSET); + *reg_dma |= SPI_DMACR_TXDMAE; + + + uint32_t dst = (_spibase + CXD56_SPI_DR_OFFSET) & 0x03ffffffu; + cxd56_txdmasetup(priv->txdmach, (uintptr_t)dst, (uintptr_t)txbuffer, + nwords, priv->txconfig); +//*/ + } + + uint32_t Bus_SPI::readData(uint_fast8_t bit_length) + { + uint32_t res = 0; + bit_length >>= 3; + if (!bit_length) return res; + int idx = 0; + do + { + res |= SPI.transfer(0) << idx; + idx += 8; + } while (--bit_length); + return res; + } + + bool Bus_SPI::readBytes(uint8_t* dst, uint32_t length, bool use_dma) + { + do + { + dst[0] = SPI.transfer(0); + ++dst; + } while (--length); + return true; + } + + void Bus_SPI::readPixels(void* dst, pixelcopy_t* param, uint32_t length) + { + uint32_t bytes = param->src_bits >> 3; + uint32_t dstindex = 0; + uint32_t len = 4; + uint8_t buf[24]; + param->src_data = buf; + do { + if (len > length) len = length; + readBytes((uint8_t*)buf, len * bytes, true); + param->src_x = 0; + dstindex = param->fp_copy(dst, dstindex, dstindex + len, param); + length -= len; + } while (length); + } + +//---------------------------------------------------------------------------- + } +} + +#endif diff --git a/src/lgfx/v1/platforms/spresense/Bus_SPI.hpp b/src/lgfx/v1/platforms/spresense/Bus_SPI.hpp new file mode 100644 index 0000000..f432b86 --- /dev/null +++ b/src/lgfx/v1/platforms/spresense/Bus_SPI.hpp @@ -0,0 +1,122 @@ +/*----------------------------------------------------------------------------/ + Lovyan GFX - Graphics library for embedded devices. + +Original Source: + https://github.com/lovyan03/LovyanGFX/ + +Licence: + [FreeBSD](https://github.com/lovyan03/LovyanGFX/blob/master/license.txt) + +Author: + [lovyan03](https://twitter.com/lovyan03) + +Contributors: + [ciniml](https://github.com/ciniml) + [mongonta0716](https://github.com/mongonta0716) + [tobozo](https://github.com/tobozo) +/----------------------------------------------------------------------------*/ +#pragma once + +#include + +#include "../../Bus.hpp" +#include "../common.hpp" + +#include + +struct spi_dev_s; + +namespace lgfx +{ + inline namespace v1 + { +//---------------------------------------------------------------------------- + + class Bus_SPI : public IBus + { + public: + struct config_t + { + uint32_t freq_write = 16000000; + uint32_t freq_read = 8000000; + //bool spi_3wire = true; + //bool use_lock = true; + int16_t pin_sclk = -1; + int16_t pin_miso = -1; + int16_t pin_mosi = -1; + int16_t pin_dc = -1; + uint8_t spi_mode = 0; + uint8_t spi_port = 4; + }; + + const config_t& config(void) const { return _cfg; } + + void config(const config_t& config); + + bus_type_t busType(void) const override { return bus_type_t::bus_spi; } + + bool init(void) override; + void release(void) override; + + void beginTransaction(void) override; + void endTransaction(void) override; + void wait(void) override; + bool busy(void) const override; + + bool writeCommand(uint32_t data, uint_fast8_t bit_length) override; + void writeData(uint32_t data, uint_fast8_t bit_length) override; + void writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t count) override; + void writePixels(pixelcopy_t* param, uint32_t length) override; + void writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) override; + + void initDMA(void) {} + void flush(void) {} + void addDMAQueue(const uint8_t* data, uint32_t length) override { writeBytes(data, length, true, true); } + void execDMAQueue(void) {} + uint8_t* getDMABuffer(uint32_t length) override { return _flip_buffer.getBuffer(length); } + + void beginRead(void) override; + void endRead(void) override; + uint32_t readData(uint_fast8_t bit_length) override; + bool readBytes(uint8_t* dst, uint32_t length, bool use_dma) override; + void readPixels(void* dst, pixelcopy_t* param, uint32_t length) override; + + private: + __attribute__ ((always_inline)) inline void wait_spi(void) + { + auto sr = _spi_reg_sr; + while (*sr & SPI_SR_BSY) {}; + } + + __attribute__ ((always_inline)) inline void dc_h(void) + { + auto gpio_reg = _gpio_reg_dc; + auto sr = _spi_reg_sr; + while (*sr & SPI_SR_BSY) {}; + if (gpio_reg) *gpio_reg = 1u << 8; + } + __attribute__ ((always_inline)) inline void dc_l(void) + { + auto gpio_reg = _gpio_reg_dc; + auto sr = _spi_reg_sr; + while (*sr & SPI_SR_BSY) {}; + if (gpio_reg) *gpio_reg = 0; + } + + config_t _cfg; + FlipBuffer _flip_buffer; + int _need_wait; + uint32_t _last_apb_freq = -1; + uint32_t _clkdiv_write; + uint32_t _clkdiv_read; + volatile uint32_t* _gpio_reg_dc; + volatile uint32_t* _spi_reg_sr; + volatile uint32_t* _spi_reg_dr; + + spi_dev_s* _spi_dev; + uintptr_t _spibase; + }; + +//---------------------------------------------------------------------------- + } +} diff --git a/src/lgfx/v1/platforms/spresense/common.cpp b/src/lgfx/v1/platforms/spresense/common.cpp new file mode 100644 index 0000000..73ecce9 --- /dev/null +++ b/src/lgfx/v1/platforms/spresense/common.cpp @@ -0,0 +1,98 @@ +/*----------------------------------------------------------------------------/ + Lovyan GFX - Graphics library for embedded devices. + +Original Source: + https://github.com/lovyan03/LovyanGFX/ + +Licence: + [FreeBSD](https://github.com/lovyan03/LovyanGFX/blob/master/license.txt) + +Author: + [lovyan03](https://twitter.com/lovyan03) + +Contributors: + [ciniml](https://github.com/ciniml) + [mongonta0716](https://github.com/mongonta0716) + [tobozo](https://github.com/tobozo) +/----------------------------------------------------------------------------*/ +#if defined (ARDUINO_ARCH_SPRESENSE) + +#include "common.hpp" + +namespace lgfx +{ + inline namespace v1 + { +//---------------------------------------------------------------------------- + + void pinMode(int_fast16_t pin, pin_mode_t mode) + { + switch (mode) + { + case pin_mode_t::output: + ::pinMode(pin, OUTPUT); + break; + +#if defined (INPUT_PULLUP) + case pin_mode_t::input_pullup: + ::pinMode(pin, INPUT_PULLUP); + break; +#endif +#if defined (INPUT_PULLDOWN) + case pin_mode_t::input_pulldown: + ::pinMode(pin, INPUT_PULLDOWN); + break; +#endif +#if defined (INPUT_PULLDOWN_16) + case pin_mode_t::input_pulldown: + ::pinMode(pin, INPUT_PULLDOWN_16); + break; +#endif + + default: + ::pinMode(pin, INPUT); + break; + } + } + +//---------------------------------------------------------------------------- + + /// unimplemented. + namespace spi + { + cpp::result init(int spi_host, int spi_sclk, int spi_miso, int spi_mosi) { return cpp::fail(error_t::unknown_err); } + void release(int spi_host) {} + void beginTransaction(int spi_host, uint32_t freq, int spi_mode) {} + void endTransaction(int spi_host) {} + void writeBytes(int spi_host, const uint8_t* data, size_t length) {} + void readBytes(int spi_host, uint8_t* data, size_t length) {} + } + +//---------------------------------------------------------------------------- + + /// unimplemented. + namespace i2c + { + cpp::result init(int i2c_port, int pin_sda, int pin_scl) { return cpp::fail(error_t::unknown_err); } + cpp::result release(int i2c_port) { return cpp::fail(error_t::unknown_err); } + cpp::result restart(int i2c_port, int i2c_addr, uint32_t freq, bool read) { return cpp::fail(error_t::unknown_err); } + cpp::result beginTransaction(int i2c_port, int i2c_addr, uint32_t freq, bool read) { return cpp::fail(error_t::unknown_err); } + cpp::result endTransaction(int i2c_port) { return cpp::fail(error_t::unknown_err); } + cpp::result writeBytes(int i2c_port, const uint8_t *data, size_t length) { return cpp::fail(error_t::unknown_err); } + cpp::result readBytes(int i2c_port, uint8_t *data, size_t length) { return cpp::fail(error_t::unknown_err); } + +//-------- + + cpp::result transactionWrite(int i2c_port, int addr, const uint8_t *writedata, uint8_t writelen, uint32_t freq) { return cpp::fail(error_t::unknown_err); } + cpp::result transactionRead(int i2c_port, int addr, uint8_t *readdata, uint8_t readlen, uint32_t freq) { return cpp::fail(error_t::unknown_err); } + cpp::result transactionWriteRead(int i2c_port, int addr, const uint8_t *writedata, uint8_t writelen, uint8_t *readdata, size_t readlen, uint32_t freq) { return cpp::fail(error_t::unknown_err); } + + cpp::result readRegister8(int i2c_port, int addr, uint8_t reg, uint32_t freq) { return cpp::fail(error_t::unknown_err); } + cpp::result writeRegister8(int i2c_port, int addr, uint8_t reg, uint8_t data, uint8_t mask, uint32_t freq) { return cpp::fail(error_t::unknown_err); } + } + +//---------------------------------------------------------------------------- + } +} + +#endif diff --git a/src/lgfx/v1/platforms/spresense/common.hpp b/src/lgfx/v1/platforms/spresense/common.hpp new file mode 100644 index 0000000..4b83fa5 --- /dev/null +++ b/src/lgfx/v1/platforms/spresense/common.hpp @@ -0,0 +1,171 @@ +/*----------------------------------------------------------------------------/ + Lovyan GFX - Graphics library for embedded devices. + +Original Source: + https://github.com/lovyan03/LovyanGFX/ + +Licence: + [FreeBSD](https://github.com/lovyan03/LovyanGFX/blob/master/license.txt) + +Author: + [lovyan03](https://twitter.com/lovyan03) + +Contributors: + [ciniml](https://github.com/ciniml) + [mongonta0716](https://github.com/mongonta0716) + [tobozo](https://github.com/tobozo) +/----------------------------------------------------------------------------*/ +#pragma once + +#include "../../misc/DataWrapper.hpp" +#include "../../misc/enum.hpp" +#include "../../../utility/result.hpp" + +#if defined ( CONFIG_ARCH_BOARD_SPRESENSE ) +#include +#else +#include +#endif + +#include +#ifdef min +#undef min +#endif +#ifdef max +#undef max +#endif + +namespace lgfx +{ + inline namespace v1 + { +//---------------------------------------------------------------------------- + + __attribute__ ((unused)) + static inline unsigned long millis(void) + { + return ::millis(); + } + __attribute__ ((unused)) + static inline unsigned long micros(void) + { + return ::micros(); + } + __attribute__ ((unused)) + static inline void delay(unsigned long milliseconds) + { + ::delay(milliseconds); + } + __attribute__ ((unused)) + static void delayMicroseconds(unsigned int us) + { + ::delayMicroseconds(us); + } + + static inline void* heap_alloc( size_t length) { return malloc(length); } + static inline void* heap_alloc_psram(size_t length) { return malloc(length); } + static inline void* heap_alloc_dma( size_t length) { return malloc(length); } // aligned_alloc(16, length); + static inline void heap_free(void* buf) { free(buf); } + + static inline void gpio_hi(uint32_t pin) { digitalWrite(pin, HIGH); } + static inline void gpio_lo(uint32_t pin) { digitalWrite(pin, LOW); } + static inline bool gpio_in(uint32_t pin) { return digitalRead(pin); } + + enum pin_mode_t + { output + , input + , input_pullup + , input_pulldown + }; + + void pinMode(int_fast16_t pin, pin_mode_t mode); + inline void lgfxPinMode(int_fast16_t pin, pin_mode_t mode) + { + pinMode(pin, mode); + } + +//---------------------------------------------------------------------------- + struct FileWrapper : public DataWrapper + { + FileWrapper() : DataWrapper() { need_transaction = true; } + +#if defined (ARDUINO) && defined (__SEEED_FS__) + + fs::File _file; + fs::File *_fp; + + fs::FS *_fs = nullptr; + void setFS(fs::FS& fs) { + _fs = &fs; + need_transaction = false; + } + FileWrapper(fs::FS& fs) : DataWrapper(), _fp(nullptr) { setFS(fs); } + FileWrapper(fs::FS& fs, fs::File* fp) : DataWrapper(), _fp(fp) { setFS(fs); } + + bool open(fs::FS& fs, const char* path) { + setFS(fs); + return open(path); + } + + bool open(const char* path) override { + fs::File file = _fs->open(path, "r"); + // この邪悪なmemcpyは、Seeed_FSのFile実装が所有権moveを提供してくれないのにデストラクタでcloseを呼ぶ実装になっているため、 + // 正攻法ではFileをクラスメンバに保持できない状況を打開すべく応急処置的に実装したものです。 + memcpy(&_file, &file, sizeof(fs::File)); + // memsetにより一時変数の中身を吹っ飛ばし、デストラクタによるcloseを予防します。 + memset(&file, 0, sizeof(fs::File)); + _fp = &_file; + return _file; + } + + int read(uint8_t *buf, uint32_t len) override { return _fp->read(buf, len); } + void skip(int32_t offset) override { seek(offset, SeekCur); } + bool seek(uint32_t offset) override { return seek(offset, SeekSet); } + bool seek(uint32_t offset, SeekMode mode) { return _fp->seek(offset, mode); } + void close() override { _fp->close(); } + int32_t tell(void) override { return _fp->position(); } + +#else // dummy. + + bool open(const char*) override { return false; } + int read(uint8_t*, uint32_t) override { return 0; } + void skip(int32_t) override { } + bool seek(uint32_t) override { return false; } + bool seek(uint32_t, int) { return false; } + void close() override { } + int32_t tell(void) override { return 0; } + +#endif + + }; + +//---------------------------------------------------------------------------- + +#if defined (ARDUINO) && defined (Stream_h) + + struct StreamWrapper : public DataWrapper + { + void set(Stream* src, uint32_t length = ~0u) { _stream = src; _length = length; _index = 0; } + + int read(uint8_t *buf, uint32_t len) override { + if (len > _length - _index) { len = _length - _index; } + _index += len; + return _stream->readBytes((char*)buf, len); + } + void skip(int32_t offset) override { if (0 < offset) { char dummy[offset]; _stream->readBytes(dummy, offset); _index += offset; } } + bool seek(uint32_t offset) override { if (offset < _index) { return false; } skip(offset - _index); return true; } + void close() override { } + int32_t tell(void) override { return _index; } + + private: + Stream* _stream; + uint32_t _index; + uint32_t _length = 0; + + }; + +#endif + +//---------------------------------------------------------------------------- + } +} diff --git a/src/lgfx/v1/platforms/stm32/Bus_SPI.cpp b/src/lgfx/v1/platforms/stm32/Bus_SPI.cpp index 7caaca7..f601ecd 100644 --- a/src/lgfx/v1/platforms/stm32/Bus_SPI.cpp +++ b/src/lgfx/v1/platforms/stm32/Bus_SPI.cpp @@ -141,7 +141,7 @@ namespace lgfx return _cfg.spi_port->SR & SPI_SR_BSY; } - void Bus_SPI::writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) + void Bus_SPI::writeCommand(uint32_t data, uint_fast8_t bit_length) { if (0 == (bit_length >>= 3)) return; auto spidr = reinterpret_cast(&_cfg.spi_port->DR); @@ -156,7 +156,7 @@ namespace lgfx } } - void Bus_SPI::writeData(std::uint32_t data, std::uint_fast8_t bit_length) + void Bus_SPI::writeData(uint32_t data, uint_fast8_t bit_length) { if (0 == (bit_length >>= 3)) return; auto spidr = reinterpret_cast(&_cfg.spi_port->DR); @@ -171,15 +171,15 @@ namespace lgfx } } - void Bus_SPI::writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t length) + void Bus_SPI::writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t length) { /* auto spisr = &_cfg.spi_port->SR; auto spidr = &_cfg.spi_port->DR; - std::size_t bytes = bit_length >> 3; + size_t bytes = bit_length >> 3; if (bytes == 3) { - std::uint32_t surplus = length & 3; + uint32_t surplus = length & 3; if (surplus) { length -= surplus; @@ -189,7 +189,7 @@ namespace lgfx } while (--surplus); } if (0 == length) return; - std::uint32_t buf[3]; + uint32_t buf[3]; buf[0] = data | data << 24; buf[1] = data >> 8 | data << 16; buf[2] = data >> 16 | data << 8; @@ -212,13 +212,13 @@ namespace lgfx } while (--length); } /*/ - const std::uint8_t dst_bytes = bit_length >> 3; - std::uint32_t limit = (dst_bytes == 3) ? 12 : 16; + const uint8_t dst_bytes = bit_length >> 3; + uint32_t limit = (dst_bytes == 3) ? 12 : 16; auto dmabuf = _flip_buffer.getBuffer(1024); - std::size_t fillpos = 0; + size_t fillpos = 0; reinterpret_cast(dmabuf)[0] = data; fillpos += dst_bytes; - std::uint32_t len; + uint32_t len; do { len = ((length - 1) % limit) + 1; @@ -235,11 +235,11 @@ namespace lgfx //*/ } - void Bus_SPI::writePixels(pixelcopy_t* param, std::uint32_t length) + void Bus_SPI::writePixels(pixelcopy_t* param, uint32_t length) { - const std::uint8_t dst_bytes = param->dst_bits >> 3; - std::uint32_t limit = (dst_bytes == 3) ? 12 : 16; - std::uint32_t len; + const uint8_t dst_bytes = param->dst_bits >> 3; + uint32_t limit = (dst_bytes == 3) ? 12 : 16; + uint32_t len; do { len = ((length - 1) % limit) + 1; @@ -250,13 +250,13 @@ namespace lgfx } while (length -= len); } - void Bus_SPI::writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) + void Bus_SPI::writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) { dc_control(dc); if (length < 16) { - SPI.transfer(const_cast(data), length); + SPI.transfer(const_cast(data), length); return; } _spiHal.State = HAL_SPI_STATE_READY; @@ -268,9 +268,9 @@ namespace lgfx HAL_SPI_Transmit_DMA(&_spiHal, (uint8_t*)data, length); } - std::uint32_t Bus_SPI::readData(std::uint_fast8_t bit_length) + uint32_t Bus_SPI::readData(uint_fast8_t bit_length) { - std::uint32_t res = 0; + uint32_t res = 0; bit_length >>= 3; if (!bit_length) return res; int idx = 0; @@ -282,7 +282,7 @@ namespace lgfx return res; } - void Bus_SPI::readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma) + void Bus_SPI::readBytes(uint8_t* dst, uint32_t length, bool use_dma) { do { @@ -291,16 +291,16 @@ namespace lgfx } while (--length); } - void Bus_SPI::readPixels(void* dst, pixelcopy_t* param, std::uint32_t length) + void Bus_SPI::readPixels(void* dst, pixelcopy_t* param, uint32_t length) { - std::uint32_t bytes = param->src_bits >> 3; - std::uint32_t dstindex = 0; - std::uint32_t len = 4; - std::uint8_t buf[24]; + uint32_t bytes = param->src_bits >> 3; + uint32_t dstindex = 0; + uint32_t len = 4; + uint8_t buf[24]; param->src_data = buf; do { if (len > length) len = length; - readBytes((std::uint8_t*)buf, len * bytes, true); + readBytes((uint8_t*)buf, len * bytes, true); param->src_x = 0; dstindex = param->fp_copy(dst, dstindex, dstindex + len, param); length -= len; diff --git a/src/lgfx/v1/platforms/stm32/Bus_SPI.hpp b/src/lgfx/v1/platforms/stm32/Bus_SPI.hpp index ab61439..29fad29 100644 --- a/src/lgfx/v1/platforms/stm32/Bus_SPI.hpp +++ b/src/lgfx/v1/platforms/stm32/Bus_SPI.hpp @@ -18,7 +18,7 @@ Original Source: #pragma once #include -#include +#include #include "../../Bus.hpp" #include "../common.hpp" @@ -34,15 +34,15 @@ namespace lgfx public: struct config_t { - std::uint32_t freq_write = 16000000; - std::uint32_t freq_read = 8000000; + uint32_t freq_write = 16000000; + uint32_t freq_read = 8000000; //bool spi_3wire = true; //bool use_lock = true; - std::int16_t pin_sclk = -1; - std::int16_t pin_miso = -1; - std::int16_t pin_mosi = -1; - std::int16_t pin_dc = -1; - std::uint8_t spi_mode = 0; + int16_t pin_sclk = -1; + int16_t pin_miso = -1; + int16_t pin_mosi = -1; + int16_t pin_dc = -1; + uint8_t spi_mode = 0; SPI_TypeDef *spi_port = SPI1; DMA_TypeDef *dma_port = DMA1; }; @@ -61,34 +61,34 @@ namespace lgfx void wait(void) override; bool busy(void) const override; - void writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) override; - void writeData(std::uint32_t data, std::uint_fast8_t bit_length) override; - void writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t count) override; - void writePixels(pixelcopy_t* param, std::uint32_t length) override; - void writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) override; + void writeCommand(uint32_t data, uint_fast8_t bit_length) override; + void writeData(uint32_t data, uint_fast8_t bit_length) override; + void writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t count) override; + void writePixels(pixelcopy_t* param, uint32_t length) override; + void writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) override; void initDMA(void) {} - void addDMAQueue(const std::uint8_t* data, std::uint32_t length) override { writeBytes(data, length, true, true); } + void addDMAQueue(const uint8_t* data, uint32_t length) override { writeBytes(data, length, true, true); } void execDMAQueue(void) {} - std::uint8_t* getDMABuffer(std::uint32_t length) override { return _flip_buffer.getBuffer(length); } + uint8_t* getDMABuffer(uint32_t length) override { return _flip_buffer.getBuffer(length); } void beginRead(void) override; void endRead(void) override; - std::uint32_t readData(std::uint_fast8_t bit_length) override; - void readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma) override; - void readPixels(void* dst, pixelcopy_t* param, std::uint32_t length) override; + uint32_t readData(uint_fast8_t bit_length) override; + void readBytes(uint8_t* dst, uint32_t length, bool use_dma) override; + void readPixels(void* dst, pixelcopy_t* param, uint32_t length) override; private: #if defined(STM32H7xx) || defined(STM32MP1xx) - static constexpr std::uint32_t sr_mask = SPI_SR_TXP; + static constexpr uint32_t sr_mask = SPI_SR_TXP; #else - static constexpr std::uint32_t sr_mask = SPI_SR_TXE; + static constexpr uint32_t sr_mask = SPI_SR_TXE; #endif __attribute__ ((always_inline)) inline void wait_spi(void) { - volatile std::uint32_t *spisr = &_cfg.spi_port->SR; + volatile uint32_t *spisr = &_cfg.spi_port->SR; do {} while (*spisr & SPI_SR_BSY); } @@ -96,7 +96,7 @@ namespace lgfx { auto gpio_reg_dc = _gpio_reg_dc; auto mask_reg_dc = flg ? _mask_reg_dc_h : _mask_reg_dc_l; - volatile std::uint32_t *spisr = &_cfg.spi_port->SR; + volatile uint32_t *spisr = &_cfg.spi_port->SR; do {} while (*spisr & SPI_SR_BSY); *gpio_reg_dc = mask_reg_dc; } @@ -105,7 +105,7 @@ namespace lgfx { auto gpio_reg_dc = _gpio_reg_dc; auto mask_reg_dc = _mask_reg_dc_h; - volatile std::uint32_t *spisr = &_cfg.spi_port->SR; + volatile uint32_t *spisr = &_cfg.spi_port->SR; do {} while (*spisr & SPI_SR_BSY); *gpio_reg_dc = mask_reg_dc; } @@ -114,7 +114,7 @@ namespace lgfx { auto gpio_reg_dc = _gpio_reg_dc; auto mask_reg_dc = _mask_reg_dc_l; - volatile std::uint32_t *spisr = &_cfg.spi_port->SR; + volatile uint32_t *spisr = &_cfg.spi_port->SR; do {} while (*spisr & SPI_SR_BSY); *gpio_reg_dc = mask_reg_dc; } @@ -122,12 +122,12 @@ namespace lgfx config_t _cfg; FlipBuffer _flip_buffer; bool _need_wait; - std::uint32_t _mask_reg_dc_h; - std::uint32_t _mask_reg_dc_l; - std::uint32_t _last_apb_freq = -1; - std::uint32_t _clkdiv_write; - std::uint32_t _clkdiv_read; - volatile std::uint32_t* _gpio_reg_dc; + uint32_t _mask_reg_dc_h; + uint32_t _mask_reg_dc_l; + uint32_t _last_apb_freq = -1; + uint32_t _clkdiv_write; + uint32_t _clkdiv_read; + volatile uint32_t* _gpio_reg_dc; DMA_HandleTypeDef _dmaHal; SPI_HandleTypeDef _spiHal; }; diff --git a/src/lgfx/v1/platforms/stm32/common.cpp b/src/lgfx/v1/platforms/stm32/common.cpp index 18ecf4a..0b1984b 100644 --- a/src/lgfx/v1/platforms/stm32/common.cpp +++ b/src/lgfx/v1/platforms/stm32/common.cpp @@ -25,7 +25,7 @@ namespace lgfx { //---------------------------------------------------------------------------- - void pinMode(std::int_fast16_t pin, pin_mode_t mode) + void pinMode(int_fast16_t pin, pin_mode_t mode) { if (pin < 0) return; /* @@ -79,11 +79,11 @@ namespace lgfx //void endTransaction(int spi_host, int spi_cs) void endTransaction(int, int) {} - //void writeData(int spi_host, const std::uint8_t* data, std::uint32_t len) - void writeData(int, const std::uint8_t*, std::uint32_t) {} + //void writeData(int spi_host, const uint8_t* data, uint32_t len) + void writeData(int, const uint8_t*, uint32_t) {} - //void readData(int spi_host, std::uint8_t* data, std::uint32_t len) - void readData(int, std::uint8_t*, std::uint32_t) {} + //void readData(int spi_host, uint8_t* data, uint32_t len) + void readData(int, uint8_t*, uint32_t) {} } //---------------------------------------------------------------------------- @@ -93,27 +93,27 @@ namespace lgfx //void init(int i2c_port, int sda, int scl, int freq) { } void init(int, int, int, int) {} - //bool writeBytes(int i2c_port, std::uint16_t addr, const std::uint8_t *data, std::uint8_t len) - bool writeBytes(int, std::uint16_t, const std::uint8_t*, std::uint8_t) + //bool writeBytes(int i2c_port, uint16_t addr, const uint8_t *data, uint8_t len) + bool writeBytes(int, uint16_t, const uint8_t*, uint8_t) { return false; } - //bool writeReadBytes(int i2c_port, std::uint16_t addr, const std::uint8_t *writedata, std::uint8_t writelen, std::uint8_t *readdata, std::uint8_t readlen) - bool writeReadBytes(int, std::uint16_t, const std::uint8_t*, std::uint8_t, std::uint8_t*, std::uint8_t) + //bool writeReadBytes(int i2c_port, uint16_t addr, const uint8_t *writedata, uint8_t writelen, uint8_t *readdata, uint8_t readlen) + bool writeReadBytes(int, uint16_t, const uint8_t*, uint8_t, uint8_t*, uint8_t) { return false; } - //bool readRegister(int i2c_port, std::uint16_t addr, std::uint8_t reg, std::uint8_t *data, uint8_t len) - bool readRegister(int, std::uint16_t, std::uint8_t, std::uint8_t*, uint8_t) + //bool readRegister(int i2c_port, uint16_t addr, uint8_t reg, uint8_t *data, uint8_t len) + bool readRegister(int, uint16_t, uint8_t, uint8_t*, uint8_t) { return false; } - bool writeRegister8(int i2c_port, std::uint16_t addr, std::uint8_t reg, std::uint8_t data, std::uint8_t mask) + bool writeRegister8(int i2c_port, uint16_t addr, uint8_t reg, uint8_t data, uint8_t mask) { - std::uint8_t tmp[2] = { reg, data }; + uint8_t tmp[2] = { reg, data }; if (mask) { if (!readRegister(i2c_port, addr, reg, &tmp[1], 1)) return false; tmp[1] = (tmp[1] & mask) | data; diff --git a/src/lgfx/v1/platforms/stm32/common.hpp b/src/lgfx/v1/platforms/stm32/common.hpp index 704eeab..2086c8e 100644 --- a/src/lgfx/v1/platforms/stm32/common.hpp +++ b/src/lgfx/v1/platforms/stm32/common.hpp @@ -74,21 +74,21 @@ namespace lgfx static inline void* heap_alloc_dma( size_t length) { return memalign(16, length); } static inline void heap_free(void* buf) { free(buf); } - static inline volatile std::uint32_t* get_gpio_out_reg(std::int_fast8_t pin) + static inline volatile uint32_t* get_gpio_out_reg(int_fast8_t pin) { - static constexpr std::size_t _offset_bsrr = 0x18; + static constexpr size_t _offset_bsrr = 0x18; return (volatile uint32_t*)( AHB1PERIPH_BASE + _offset_bsrr + (0x0400UL * ((pin >> 4)&0x0F))); } - static inline volatile std::uint32_t* get_gpio_in_reg(std::int_fast8_t pin) + static inline volatile uint32_t* get_gpio_in_reg(int_fast8_t pin) { - static constexpr std::size_t _offset_idr = 0x10; + static constexpr size_t _offset_idr = 0x10; return (volatile uint32_t*)( AHB1PERIPH_BASE + _offset_idr + (0x0400UL * ((pin >> 4)&0x0F))); } - static inline void gpio_hi(std::int_fast8_t pin) { if (pin >= 0) *get_gpio_out_reg(pin) = 1ul << (pin & 15); } - static inline void gpio_lo(std::int_fast8_t pin) { if (pin >= 0) *get_gpio_out_reg(pin) = 1ul << ((pin & 15) + 16); } - static inline bool gpio_in(std::int_fast8_t pin) { return *get_gpio_in_reg(pin) & (1ul << (pin & 0x0F)); } + static inline void gpio_hi(int_fast8_t pin) { if (pin >= 0) *get_gpio_out_reg(pin) = 1ul << (pin & 15); } + static inline void gpio_lo(int_fast8_t pin) { if (pin >= 0) *get_gpio_out_reg(pin) = 1ul << ((pin & 15) + 16); } + static inline bool gpio_in(int_fast8_t pin) { return *get_gpio_in_reg(pin) & (1ul << (pin & 0x0F)); } enum pin_mode_t { output @@ -97,8 +97,8 @@ namespace lgfx , input_pulldown }; - void pinMode(std::int_fast16_t pin, pin_mode_t mode); - inline void lgfxPinMode(std::int_fast16_t pin, pin_mode_t mode) + void pinMode(int_fast16_t pin, pin_mode_t mode); + inline void lgfxPinMode(int_fast16_t pin, pin_mode_t mode) { pinMode(pin, mode); } @@ -137,22 +137,22 @@ namespace lgfx return _file; } - int read(std::uint8_t *buf, std::uint32_t len) override { return _fp->read(buf, len); } - void skip(std::int32_t offset) override { seek(offset, SeekCur); } - bool seek(std::uint32_t offset) override { return seek(offset, SeekSet); } - bool seek(std::uint32_t offset, SeekMode mode) { return _fp->seek(offset, mode); } + int read(uint8_t *buf, uint32_t len) override { return _fp->read(buf, len); } + void skip(int32_t offset) override { seek(offset, SeekCur); } + bool seek(uint32_t offset) override { return seek(offset, SeekSet); } + bool seek(uint32_t offset, SeekMode mode) { return _fp->seek(offset, mode); } void close() override { _fp->close(); } - std::int32_t tell(void) override { return _fp->position(); } + int32_t tell(void) override { return _fp->position(); } #else // dummy. bool open(const char*) override { return false; } - int read(std::uint8_t*, std::uint32_t) override { return 0; } - void skip(std::int32_t) override { } - bool seek(std::uint32_t) override { return false; } - bool seek(std::uint32_t, int) { return false; } + int read(uint8_t*, uint32_t) override { return 0; } + void skip(int32_t) override { } + bool seek(uint32_t) override { return false; } + bool seek(uint32_t, int) { return false; } void close() override { } - std::int32_t tell(void) override { return 0; } + int32_t tell(void) override { return 0; } #endif @@ -164,22 +164,22 @@ namespace lgfx struct StreamWrapper : public DataWrapper { - void set(Stream* src, std::uint32_t length = ~0u) { _stream = src; _length = length; _index = 0; } + void set(Stream* src, uint32_t length = ~0u) { _stream = src; _length = length; _index = 0; } - int read(std::uint8_t *buf, std::uint32_t len) override { + int read(uint8_t *buf, uint32_t len) override { if (len > _length - _index) { len = _length - _index; } _index += len; return _stream->readBytes((char*)buf, len); } - void skip(std::int32_t offset) override { if (0 < offset) { char dummy[offset]; _stream->readBytes(dummy, offset); _index += offset; } } - bool seek(std::uint32_t offset) override { if (offset < _index) { return false; } skip(offset - _index); return true; } + void skip(int32_t offset) override { if (0 < offset) { char dummy[offset]; _stream->readBytes(dummy, offset); _index += offset; } } + bool seek(uint32_t offset) override { if (offset < _index) { return false; } skip(offset - _index); return true; } void close() override { } - std::int32_t tell(void) override { return _index; } + int32_t tell(void) override { return _index; } private: Stream* _stream; - std::uint32_t _index; - std::uint32_t _length = 0; + uint32_t _index; + uint32_t _length = 0; }; diff --git a/src/lgfx/v1/touch/Touch_FT5x06.cpp b/src/lgfx/v1/touch/Touch_FT5x06.cpp index b81d31a..2c7385d 100644 --- a/src/lgfx/v1/touch/Touch_FT5x06.cpp +++ b/src/lgfx/v1/touch/Touch_FT5x06.cpp @@ -25,23 +25,23 @@ namespace lgfx { //---------------------------------------------------------------------------- - static constexpr std::uint8_t FT5x06_VENDID_REG = 0xA8; - static constexpr std::uint8_t FT5x06_POWER_REG = 0x87; - static constexpr std::uint8_t FT5x06_PERIODACTIVE = 0x88; - static constexpr std::uint8_t FT5x06_INTMODE_REG= 0xA4; + static constexpr uint8_t FT5x06_VENDID_REG = 0xA8; + static constexpr uint8_t FT5x06_POWER_REG = 0x87; + static constexpr uint8_t FT5x06_PERIODACTIVE = 0x88; + static constexpr uint8_t FT5x06_INTMODE_REG= 0xA4; - static constexpr std::uint8_t FT5x06_MONITOR = 0x01; - static constexpr std::uint8_t FT5x06_SLEEP_IN = 0x03; + static constexpr uint8_t FT5x06_MONITOR = 0x01; + static constexpr uint8_t FT5x06_SLEEP_IN = 0x03; - bool Touch_FT5x06::_write_reg(std::uint8_t reg, std::uint8_t val) + bool Touch_FT5x06::_write_reg(uint8_t reg, uint8_t val) { return i2c::writeRegister8(_cfg.i2c_port, _cfg.i2c_addr, reg, val, 0, _cfg.freq).has_value(); - // std::uint8_t data[] = { reg, val }; + // uint8_t data[] = { reg, val }; // return lgfx::i2c::transactionWrite(_cfg.i2c_port, _cfg.i2c_addr, data, 2, _cfg.freq).has_value(); } - bool Touch_FT5x06::_read_reg(std::uint8_t reg, std::uint8_t *data, std::size_t length) + bool Touch_FT5x06::_read_reg(uint8_t reg, uint8_t *data, size_t length) { return lgfx::i2c::transactionWriteRead(_cfg.i2c_port, _cfg.i2c_addr, ®, 1, data, length, _cfg.freq).has_value(); } @@ -50,7 +50,7 @@ namespace lgfx { if (_inited) return true; - std::uint8_t tmp[2] = { 0 }; + uint8_t tmp[2] = { 0 }; _inited = _write_reg(0x00, 0x00) && _read_reg(FT5x06_VENDID_REG, tmp, 1) && _write_reg(FT5x06_INTMODE_REG, 0x00) // INT Polling mode @@ -84,7 +84,7 @@ namespace lgfx _write_reg(FT5x06_POWER_REG, FT5x06_SLEEP_IN); } - std::uint_fast8_t Touch_FT5x06::getTouchRaw(touch_point_t *tp, std::uint_fast8_t count) + uint_fast8_t Touch_FT5x06::getTouchRaw(touch_point_t *tp, uint_fast8_t count) { if (!_check_init() || count == 0) return 0; if (_cfg.pin_int >= 0) @@ -100,18 +100,18 @@ namespace lgfx } } if (count > 5) count = 5; // 最大5点まで - std::size_t len = count * 6 - 1; + size_t len = count * 6 - 1; - std::uint8_t tmp[2][len]; + uint8_t tmp[2][len]; _read_reg(0x02, tmp[0], len); - std::int32_t retry = 5; + int32_t retry = 5; do { // 読出し中に値が変わる事があるので、連続読出しして前回と同値でなければリトライする _read_reg(0x02, tmp[retry & 1], len); } while (memcmp(tmp[0], tmp[1], len) && --retry); if (count > tmp[0][0]) count = tmp[0][0]; - for (std::size_t idx = 0; idx < count; ++idx) + for (size_t idx = 0; idx < count; ++idx) { auto data = &tmp[0][idx * 6]; tp[idx].size = 1; diff --git a/src/lgfx/v1/touch/Touch_FT5x06.hpp b/src/lgfx/v1/touch/Touch_FT5x06.hpp index 27ab70b..43a63c0 100644 --- a/src/lgfx/v1/touch/Touch_FT5x06.hpp +++ b/src/lgfx/v1/touch/Touch_FT5x06.hpp @@ -41,16 +41,16 @@ namespace lgfx void sleep(void) override; - std::uint_fast8_t getTouchRaw(touch_point_t* tp, std::uint_fast8_t count) override; + uint_fast8_t getTouchRaw(touch_point_t* tp, uint_fast8_t count) override; private: bool _flg_released = false; bool _check_init(void); - bool _write_reg(std::uint8_t reg, std::uint8_t val); + bool _write_reg(uint8_t reg, uint8_t val); - bool _read_reg(std::uint8_t reg, std::uint8_t *data, std::size_t length); + bool _read_reg(uint8_t reg, uint8_t *data, size_t length); }; //---------------------------------------------------------------------------- diff --git a/src/lgfx/v1/touch/Touch_GT911.cpp b/src/lgfx/v1/touch/Touch_GT911.cpp index 35844b1..1bb1631 100644 --- a/src/lgfx/v1/touch/Touch_GT911.cpp +++ b/src/lgfx/v1/touch/Touch_GT911.cpp @@ -17,16 +17,15 @@ Original Source: /----------------------------------------------------------------------------*/ #include "Touch_GT911.hpp" +#include "../../internal/algorithm.h" #include "../platforms/common.hpp" -#include - namespace lgfx { inline namespace v1 { //---------------------------------------------------------------------------- - static constexpr std::uint8_t gt911cmd_getdata[] = { 0x81, 0x4E, 0x00 }; + static constexpr uint8_t gt911cmd_getdata[] = { 0x81, 0x4E, 0x00 }; static uint8_t calcChecksum(const uint8_t *buf, uint8_t len) { @@ -39,12 +38,12 @@ namespace lgfx return ccsum; } - bool Touch_GT911::writeBytes(const std::uint8_t* data, std::size_t len) + bool Touch_GT911::writeBytes(const uint8_t* data, size_t len) { return lgfx::i2c::transactionWrite(_cfg.i2c_port, _cfg.i2c_addr, data, len, _cfg.freq).has_value(); } - bool Touch_GT911::writeReadBytes(const std::uint8_t* write_data, std::size_t write_len, std::uint8_t* read_data, std::size_t read_len) + bool Touch_GT911::writeReadBytes(const uint8_t* write_data, size_t write_len, uint8_t* read_data, size_t read_len) { return lgfx::i2c::transactionWriteRead(_cfg.i2c_port, _cfg.i2c_addr, write_data, write_len, read_data, read_len, _cfg.freq).has_value(); } @@ -66,17 +65,17 @@ namespace lgfx if (_inited) { - std::uint8_t buf[] = { 0x80, 0x56 }; + uint8_t buf[] = { 0x80, 0x56 }; writeReadBytes(buf, 2, buf, 1); _refresh_rate = 5 + (buf[0] & 0x0F); /* { - std::uint8_t writedata[4] = { 0x80, 0x40 }; + uint8_t writedata[4] = { 0x80, 0x40 }; - std::uint8_t readdata[193] = {0}; + uint8_t readdata[193] = {0}; writeReadBytes(writedata, 2, readdata, 193); - std::uint32_t addr = 0x8040; + uint32_t addr = 0x8040; for (int i = 0; i < 12; ++i) { Serial.printf("%04x:" , addr); for (int j = 0; j < 4; ++j) { @@ -108,11 +107,11 @@ namespace lgfx void Touch_GT911::sleep(void) { if (!_inited) return; - static constexpr std::uint8_t writedata[] = { 0x80, 0x40, 0x05 }; + static constexpr uint8_t writedata[] = { 0x80, 0x40, 0x05 }; writeBytes(writedata, 3); } - std::uint_fast8_t Touch_GT911::getTouchRaw(touch_point_t* __restrict__ tp, std::uint_fast8_t count) + uint_fast8_t Touch_GT911::getTouchRaw(touch_point_t* __restrict__ tp, uint_fast8_t count) { if (!_inited || count == 0) return 0; if (count > 5) { count = 5; } @@ -121,13 +120,13 @@ namespace lgfx { if (lgfx::i2c::beginTransaction(_cfg.i2c_port, _cfg.i2c_addr, _cfg.freq, false)) { - std::uint8_t buf; + uint8_t buf; if (lgfx::i2c::writeBytes(_cfg.i2c_port, gt911cmd_getdata, 2) && lgfx::i2c::restart(_cfg.i2c_port, _cfg.i2c_addr, _cfg.freq, true) && lgfx::i2c::readBytes(_cfg.i2c_port, &buf, 1) && (buf & 0x80)) { - std::uint32_t points = std::min(count, buf & 0x0F); + uint32_t points = std::min(count, buf & 0x0F); if (lgfx::i2c::readBytes(_cfg.i2c_port, &_readdata[1], points * 8)) { _readdata[0] = buf; @@ -140,10 +139,10 @@ namespace lgfx if (lgfx::i2c::endTransaction(_cfg.i2c_port)) {} } } - std::uint32_t points = std::min(count, _readdata[0] & 0x0F); - for (std::size_t idx = 0; idx < points; ++idx) + uint32_t points = std::min(count, _readdata[0] & 0x0F); + for (size_t idx = 0; idx < points; ++idx) { - auto data = reinterpret_cast(&_readdata[idx * 8]); + auto data = reinterpret_cast(&_readdata[idx * 8]); tp[idx].id = data[0] >> 8; tp[idx].x = data[1]; tp[idx].y = data[2]; @@ -152,11 +151,11 @@ namespace lgfx return points; } - void Touch_GT911::setTouchNums(std::int_fast8_t nums) + void Touch_GT911::setTouchNums(int_fast8_t nums) { - nums = std::max(1, std::min(5, nums)); + nums = std::max(1, std::min(5, nums)); - std::uint8_t buf[] = { 0x80, 0x4c, 0x00 }; + uint8_t buf[] = { 0x80, 0x4c, 0x00 }; writeReadBytes(buf, 2, &buf[2], 1); if (buf[2] != nums) { @@ -170,7 +169,7 @@ namespace lgfx void Touch_GT911::freshConfig(void) { // 設定レジスタ全体を読取り - std::uint8_t writedata[188] = { 0x80, 0x47 }; + uint8_t writedata[188] = { 0x80, 0x47 }; if (writeReadBytes(writedata, 2, &writedata[2], 184)) { // チェックサムを計算し、設定値の更新指示を行う diff --git a/src/lgfx/v1/touch/Touch_GT911.hpp b/src/lgfx/v1/touch/Touch_GT911.hpp index 03c1a4d..71166c0 100644 --- a/src/lgfx/v1/touch/Touch_GT911.hpp +++ b/src/lgfx/v1/touch/Touch_GT911.hpp @@ -41,18 +41,18 @@ namespace lgfx void sleep(void) override; - std::uint_fast8_t getTouchRaw(touch_point_t *tp, std::uint_fast8_t count) override; + uint_fast8_t getTouchRaw(touch_point_t *tp, uint_fast8_t count) override; - void setTouchNums(std::int_fast8_t nums); + void setTouchNums(int_fast8_t nums); private: - std::uint32_t _lasttime; - std::uint32_t _refresh_rate = 5; - std::uint8_t _readdata[42]; // 5point * 8byte + 2byte + uint32_t _lasttime; + uint32_t _refresh_rate = 5; + uint8_t _readdata[42]; // 5point * 8byte + 2byte void freshConfig(void); - bool writeBytes(const std::uint8_t* data, std::size_t len); - bool writeReadBytes(const std::uint8_t* write_data, std::size_t write_len, std::uint8_t* read_data, std::size_t read_len); + bool writeBytes(const uint8_t* data, size_t len); + bool writeReadBytes(const uint8_t* write_data, size_t write_len, uint8_t* read_data, size_t read_len); }; //---------------------------------------------------------------------------- diff --git a/src/lgfx/v1/touch/Touch_STMPE610.cpp b/src/lgfx/v1/touch/Touch_STMPE610.cpp index add4101..e3ec783 100644 --- a/src/lgfx/v1/touch/Touch_STMPE610.cpp +++ b/src/lgfx/v1/touch/Touch_STMPE610.cpp @@ -17,112 +17,111 @@ Original Source: /----------------------------------------------------------------------------*/ #include "Touch_STMPE610.hpp" +#include "../../internal/algorithm.h" #include "../platforms/common.hpp" -#include - /** STMPE610 Address **/ -static constexpr std::uint8_t STMPE_ADDR = 0x41; +static constexpr uint8_t STMPE_ADDR = 0x41; /** Reset Control **/ -static constexpr std::uint8_t STMPE_SYS_CTRL1 = 0x03; -static constexpr std::uint8_t STMPE_SYS_CTRL1_RESET = 0x02; +static constexpr uint8_t STMPE_SYS_CTRL1 = 0x03; +static constexpr uint8_t STMPE_SYS_CTRL1_RESET = 0x02; /** Clock Contrl **/ -static constexpr std::uint8_t STMPE_SYS_CTRL2 = 0x04; +static constexpr uint8_t STMPE_SYS_CTRL2 = 0x04; /** Touchscreen controller setup **/ -static constexpr std::uint8_t STMPE_TSC_CTRL = 0x40; -static constexpr std::uint8_t STMPE_TSC_CTRL_EN = 0x01; -static constexpr std::uint8_t STMPE_TSC_CTRL_XYZ = 0x00; -static constexpr std::uint8_t STMPE_TSC_CTRL_XY = 0x02; +static constexpr uint8_t STMPE_TSC_CTRL = 0x40; +static constexpr uint8_t STMPE_TSC_CTRL_EN = 0x01; +static constexpr uint8_t STMPE_TSC_CTRL_XYZ = 0x00; +static constexpr uint8_t STMPE_TSC_CTRL_XY = 0x02; /** Interrupt control **/ -static constexpr std::uint8_t STMPE_INT_CTRL = 0x09; -static constexpr std::uint8_t STMPE_INT_CTRL_POL_HIGH = 0x04; -static constexpr std::uint8_t STMPE_INT_CTRL_POL_LOW = 0x00; -static constexpr std::uint8_t STMPE_INT_CTRL_EDGE = 0x02; -static constexpr std::uint8_t STMPE_INT_CTRL_LEVEL = 0x00; -static constexpr std::uint8_t STMPE_INT_CTRL_ENABLE = 0x01; -static constexpr std::uint8_t STMPE_INT_CTRL_DISABLE = 0x00; +static constexpr uint8_t STMPE_INT_CTRL = 0x09; +static constexpr uint8_t STMPE_INT_CTRL_POL_HIGH = 0x04; +static constexpr uint8_t STMPE_INT_CTRL_POL_LOW = 0x00; +static constexpr uint8_t STMPE_INT_CTRL_EDGE = 0x02; +static constexpr uint8_t STMPE_INT_CTRL_LEVEL = 0x00; +static constexpr uint8_t STMPE_INT_CTRL_ENABLE = 0x01; +static constexpr uint8_t STMPE_INT_CTRL_DISABLE = 0x00; /** Interrupt enable **/ -static constexpr std::uint8_t STMPE_INT_EN = 0x0A; -static constexpr std::uint8_t STMPE_INT_EN_TOUCHDET = 0x01; -static constexpr std::uint8_t STMPE_INT_EN_FIFOTH = 0x02; -static constexpr std::uint8_t STMPE_INT_EN_FIFOOF = 0x04; -static constexpr std::uint8_t STMPE_INT_EN_FIFOFULL = 0x08; -static constexpr std::uint8_t STMPE_INT_EN_FIFOEMPTY = 0x10; -static constexpr std::uint8_t STMPE_INT_EN_ADC = 0x40; -static constexpr std::uint8_t STMPE_INT_EN_GPIO = 0x80; +static constexpr uint8_t STMPE_INT_EN = 0x0A; +static constexpr uint8_t STMPE_INT_EN_TOUCHDET = 0x01; +static constexpr uint8_t STMPE_INT_EN_FIFOTH = 0x02; +static constexpr uint8_t STMPE_INT_EN_FIFOOF = 0x04; +static constexpr uint8_t STMPE_INT_EN_FIFOFULL = 0x08; +static constexpr uint8_t STMPE_INT_EN_FIFOEMPTY = 0x10; +static constexpr uint8_t STMPE_INT_EN_ADC = 0x40; +static constexpr uint8_t STMPE_INT_EN_GPIO = 0x80; /** Interrupt status **/ -static constexpr std::uint8_t STMPE_INT_STA = 0x0B; -static constexpr std::uint8_t STMPE_INT_STA_TOUCHDET = 0x01; +static constexpr uint8_t STMPE_INT_STA = 0x0B; +static constexpr uint8_t STMPE_INT_STA_TOUCHDET = 0x01; /** ADC control **/ -static constexpr std::uint8_t STMPE_ADC_CTRL1 = 0x20; -static constexpr std::uint8_t STMPE_ADC_CTRL1_12BIT = 0x08; -static constexpr std::uint8_t STMPE_ADC_CTRL1_10BIT = 0x00; +static constexpr uint8_t STMPE_ADC_CTRL1 = 0x20; +static constexpr uint8_t STMPE_ADC_CTRL1_12BIT = 0x08; +static constexpr uint8_t STMPE_ADC_CTRL1_10BIT = 0x00; /** ADC control **/ -static constexpr std::uint8_t STMPE_ADC_CTRL2 = 0x21; -static constexpr std::uint8_t STMPE_ADC_CTRL2_1_625MHZ = 0x00; -static constexpr std::uint8_t STMPE_ADC_CTRL2_3_25MHZ = 0x01; -static constexpr std::uint8_t STMPE_ADC_CTRL2_6_5MHZ = 0x02; +static constexpr uint8_t STMPE_ADC_CTRL2 = 0x21; +static constexpr uint8_t STMPE_ADC_CTRL2_1_625MHZ = 0x00; +static constexpr uint8_t STMPE_ADC_CTRL2_3_25MHZ = 0x01; +static constexpr uint8_t STMPE_ADC_CTRL2_6_5MHZ = 0x02; /** Touchscreen controller configuration **/ -static constexpr std::uint8_t STMPE_TSC_CFG = 0x41; -static constexpr std::uint8_t STMPE_TSC_CFG_1SAMPLE = 0x00; -static constexpr std::uint8_t STMPE_TSC_CFG_2SAMPLE = 0x40; -static constexpr std::uint8_t STMPE_TSC_CFG_4SAMPLE = 0x80; -static constexpr std::uint8_t STMPE_TSC_CFG_8SAMPLE = 0xC0; -static constexpr std::uint8_t STMPE_TSC_CFG_DELAY_10US = 0x00; -static constexpr std::uint8_t STMPE_TSC_CFG_DELAY_50US = 0x08; -static constexpr std::uint8_t STMPE_TSC_CFG_DELAY_100US = 0x10; -static constexpr std::uint8_t STMPE_TSC_CFG_DELAY_500US = 0x18; -static constexpr std::uint8_t STMPE_TSC_CFG_DELAY_1MS = 0x20; -static constexpr std::uint8_t STMPE_TSC_CFG_DELAY_5MS = 0x28; -static constexpr std::uint8_t STMPE_TSC_CFG_DELAY_10MS = 0x30; -static constexpr std::uint8_t STMPE_TSC_CFG_DELAY_50MS = 0x38; -static constexpr std::uint8_t STMPE_TSC_CFG_SETTLE_10US = 0x00; -static constexpr std::uint8_t STMPE_TSC_CFG_SETTLE_100US = 0x01; -static constexpr std::uint8_t STMPE_TSC_CFG_SETTLE_500US = 0x02; -static constexpr std::uint8_t STMPE_TSC_CFG_SETTLE_1MS = 0x03; -static constexpr std::uint8_t STMPE_TSC_CFG_SETTLE_5MS = 0x04; -static constexpr std::uint8_t STMPE_TSC_CFG_SETTLE_10MS = 0x05; -static constexpr std::uint8_t STMPE_TSC_CFG_SETTLE_50MS = 0x06; -static constexpr std::uint8_t STMPE_TSC_CFG_SETTLE_100MS = 0x07; +static constexpr uint8_t STMPE_TSC_CFG = 0x41; +static constexpr uint8_t STMPE_TSC_CFG_1SAMPLE = 0x00; +static constexpr uint8_t STMPE_TSC_CFG_2SAMPLE = 0x40; +static constexpr uint8_t STMPE_TSC_CFG_4SAMPLE = 0x80; +static constexpr uint8_t STMPE_TSC_CFG_8SAMPLE = 0xC0; +static constexpr uint8_t STMPE_TSC_CFG_DELAY_10US = 0x00; +static constexpr uint8_t STMPE_TSC_CFG_DELAY_50US = 0x08; +static constexpr uint8_t STMPE_TSC_CFG_DELAY_100US = 0x10; +static constexpr uint8_t STMPE_TSC_CFG_DELAY_500US = 0x18; +static constexpr uint8_t STMPE_TSC_CFG_DELAY_1MS = 0x20; +static constexpr uint8_t STMPE_TSC_CFG_DELAY_5MS = 0x28; +static constexpr uint8_t STMPE_TSC_CFG_DELAY_10MS = 0x30; +static constexpr uint8_t STMPE_TSC_CFG_DELAY_50MS = 0x38; +static constexpr uint8_t STMPE_TSC_CFG_SETTLE_10US = 0x00; +static constexpr uint8_t STMPE_TSC_CFG_SETTLE_100US = 0x01; +static constexpr uint8_t STMPE_TSC_CFG_SETTLE_500US = 0x02; +static constexpr uint8_t STMPE_TSC_CFG_SETTLE_1MS = 0x03; +static constexpr uint8_t STMPE_TSC_CFG_SETTLE_5MS = 0x04; +static constexpr uint8_t STMPE_TSC_CFG_SETTLE_10MS = 0x05; +static constexpr uint8_t STMPE_TSC_CFG_SETTLE_50MS = 0x06; +static constexpr uint8_t STMPE_TSC_CFG_SETTLE_100MS = 0x07; /** FIFO level to generate interrupt **/ -static constexpr std::uint8_t STMPE_FIFO_TH = 0x4A; +static constexpr uint8_t STMPE_FIFO_TH = 0x4A; /** Current filled level of FIFO **/ -static constexpr std::uint8_t STMPE_FIFO_SIZE = 0x4C; +static constexpr uint8_t STMPE_FIFO_SIZE = 0x4C; /** Current status of FIFO **/ -static constexpr std::uint8_t STMPE_FIFO_STA = 0x4B; -static constexpr std::uint8_t STMPE_FIFO_STA_RESET = 0x01; -static constexpr std::uint8_t STMPE_FIFO_STA_OFLOW = 0x80; -static constexpr std::uint8_t STMPE_FIFO_STA_FULL = 0x40; -static constexpr std::uint8_t STMPE_FIFO_STA_EMPTY = 0x20; -static constexpr std::uint8_t STMPE_FIFO_STA_THTRIG = 0x10; +static constexpr uint8_t STMPE_FIFO_STA = 0x4B; +static constexpr uint8_t STMPE_FIFO_STA_RESET = 0x01; +static constexpr uint8_t STMPE_FIFO_STA_OFLOW = 0x80; +static constexpr uint8_t STMPE_FIFO_STA_FULL = 0x40; +static constexpr uint8_t STMPE_FIFO_STA_EMPTY = 0x20; +static constexpr uint8_t STMPE_FIFO_STA_THTRIG = 0x10; /** Touchscreen controller drive I **/ -static constexpr std::uint8_t STMPE_TSC_I_DRIVE = 0x58; -static constexpr std::uint8_t STMPE_TSC_I_DRIVE_20MA = 0x00; -static constexpr std::uint8_t STMPE_TSC_I_DRIVE_50MA = 0x01; +static constexpr uint8_t STMPE_TSC_I_DRIVE = 0x58; +static constexpr uint8_t STMPE_TSC_I_DRIVE_20MA = 0x00; +static constexpr uint8_t STMPE_TSC_I_DRIVE_50MA = 0x01; /** Data port for TSC data address **/ -static constexpr std::uint8_t STMPE_TSC_DATA_X = 0x4D; -static constexpr std::uint8_t STMPE_TSC_DATA_Y = 0x4F; -static constexpr std::uint8_t STMPE_TSC_FRACTION_Z = 0x56; +static constexpr uint8_t STMPE_TSC_DATA_X = 0x4D; +static constexpr uint8_t STMPE_TSC_DATA_Y = 0x4F; +static constexpr uint8_t STMPE_TSC_FRACTION_Z = 0x56; /** GPIO **/ -static constexpr std::uint8_t STMPE_GPIO_SET_PIN = 0x10; -static constexpr std::uint8_t STMPE_GPIO_CLR_PIN = 0x11; -static constexpr std::uint8_t STMPE_GPIO_DIR = 0x13; -static constexpr std::uint8_t STMPE_GPIO_ALT_FUNCT = 0x17; +static constexpr uint8_t STMPE_GPIO_SET_PIN = 0x10; +static constexpr uint8_t STMPE_GPIO_CLR_PIN = 0x11; +static constexpr uint8_t STMPE_GPIO_DIR = 0x13; +static constexpr uint8_t STMPE_GPIO_ALT_FUNCT = 0x17; namespace lgfx { @@ -130,10 +129,10 @@ namespace lgfx { //---------------------------------------------------------------------------- - std::uint8_t Touch_STMPE610::readRegister8(std::uint8_t reg) + uint8_t Touch_STMPE610::readRegister8(uint8_t reg) { if (isSPI()) { - std::uint8_t tmp[2] = { (std::uint8_t)(0x80 | reg), 0 }; + uint8_t tmp[2] = { (uint8_t)(0x80 | reg), 0 }; spi::beginTransaction(_cfg.spi_host, _cfg.freq, _spi_mode); lgfx::gpio_lo(_cfg.pin_cs); spi::writeBytes(_cfg.spi_host, tmp, 1); @@ -145,10 +144,10 @@ namespace lgfx return 0; } - void Touch_STMPE610::writeRegister8(std::uint8_t reg, std::uint8_t val) + void Touch_STMPE610::writeRegister8(uint8_t reg, uint8_t val) { if (isSPI()) { - std::uint8_t tmp[2] = { reg, val }; + uint8_t tmp[2] = { reg, val }; spi::beginTransaction(_cfg.spi_host, _cfg.freq, _spi_mode); lgfx::gpio_lo(_cfg.pin_cs); spi::writeBytes(_cfg.spi_host, tmp, 1); @@ -162,7 +161,7 @@ namespace lgfx { if (isSPI()) { lgfx::pinMode(_cfg.pin_cs, lgfx::pin_mode_t::output); - std::uint16_t v = readRegister8(0) << 8; + uint16_t v = readRegister8(0) << 8; v |= readRegister8(1); //Serial.printf("getVersion:%04x \r\n", v); return v; @@ -190,7 +189,7 @@ namespace lgfx writeRegister8(STMPE_SYS_CTRL1, STMPE_SYS_CTRL1_RESET); delay(10); - for (std::uint8_t i = 0; i < 65; i++) { + for (uint8_t i = 0; i < 65; i++) { readRegister8(i); } @@ -231,12 +230,12 @@ namespace lgfx if (!_inited) return; } - std::uint_fast8_t Touch_STMPE610::getTouchRaw(touch_point_t* __restrict__ tp, std::uint_fast8_t count) + uint_fast8_t Touch_STMPE610::getTouchRaw(touch_point_t* __restrict__ tp, uint_fast8_t count) { if (!_inited || count == 0) return 0; if (isSPI()) { - std::uint8_t data[8]; + uint8_t data[8]; spi::beginTransaction(_cfg.spi_host, _cfg.freq, _spi_mode); lgfx::gpio_lo(_cfg.pin_cs); data[0] = 0x80 | STMPE_FIFO_STA; // check buffer empty diff --git a/src/lgfx/v1/touch/Touch_STMPE610.hpp b/src/lgfx/v1/touch/Touch_STMPE610.hpp index 52cf1e9..babc03a 100644 --- a/src/lgfx/v1/touch/Touch_STMPE610.hpp +++ b/src/lgfx/v1/touch/Touch_STMPE610.hpp @@ -44,7 +44,7 @@ namespace lgfx void sleep(void) override; - std::uint_fast8_t getTouchRaw(touch_point_t* tp, std::uint_fast8_t count) override; + uint_fast8_t getTouchRaw(touch_point_t* tp, uint_fast8_t count) override; private: diff --git a/src/lgfx/v1/touch/Touch_XPT2046.cpp b/src/lgfx/v1/touch/Touch_XPT2046.cpp index 550ca7e..e9ab802 100644 --- a/src/lgfx/v1/touch/Touch_XPT2046.cpp +++ b/src/lgfx/v1/touch/Touch_XPT2046.cpp @@ -17,10 +17,9 @@ Original Source: /----------------------------------------------------------------------------*/ #include "Touch_XPT2046.hpp" +#include "../../internal/algorithm.h" #include "../platforms/common.hpp" -#include - namespace lgfx { inline namespace v1 @@ -48,7 +47,7 @@ namespace lgfx return true; } - std::uint_fast8_t Touch_XPT2046::getTouchRaw(touch_point_t* __restrict__ tp, std::uint_fast8_t count) + uint_fast8_t Touch_XPT2046::getTouchRaw(touch_point_t* __restrict__ tp, uint_fast8_t count) { if (!_inited || count == 0) return 0; @@ -59,7 +58,7 @@ namespace lgfx return 0; } - std::uint8_t data[57]; + uint8_t data[57]; memset(data, 0, 8); data[ 0] = 0x91; @@ -77,9 +76,9 @@ namespace lgfx spi::endTransaction(_cfg.spi_host); lgfx::gpio_hi(_cfg.pin_cs); - std::size_t ix = 0, iy = 0, iz = 0; - std::uint_fast16_t xt[7], yt[7], zt[7]; - for (std::size_t j = 0; j < 7; ++j) + size_t ix = 0, iy = 0, iz = 0; + uint_fast16_t xt[7], yt[7], zt[7]; + for (size_t j = 0; j < 7; ++j) { auto d = &data[j * 8]; int x = (d[5] << 8 | d[6]) >> 3; diff --git a/src/lgfx/v1/touch/Touch_XPT2046.hpp b/src/lgfx/v1/touch/Touch_XPT2046.hpp index 63b379a..e96f631 100644 --- a/src/lgfx/v1/touch/Touch_XPT2046.hpp +++ b/src/lgfx/v1/touch/Touch_XPT2046.hpp @@ -41,7 +41,7 @@ namespace lgfx void wakeup(void) override {} void sleep(void) override {} - std::uint_fast8_t getTouchRaw(touch_point_t* tp, std::uint_fast8_t count) override; + uint_fast8_t getTouchRaw(touch_point_t* tp, uint_fast8_t count) override; }; //----------------------------------------------------------------------------