521 lines
19 KiB
C++
521 lines
19 KiB
C++
// GxEPD_SD_Example : test example for e-Paper displays from Waveshare and from Dalian Good Display Inc.
|
||
//
|
||
// Created by Jean-Marc Zingg based on demo code from Good Display,
|
||
// available on http://www.good-display.com/download_list/downloadcategoryid=34&isMode=false.html
|
||
//
|
||
// The e-paper displays are available from:
|
||
//
|
||
// https://www.aliexpress.com/store/product/Wholesale-1-54inch-E-Ink-display-module-with-embedded-controller-200x200-Communicate-via-SPI-interface-Supports/216233_32824535312.html
|
||
//
|
||
// http://www.buy-lcd.com/index.php?route=product/product&path=2897_8363&product_id=35120
|
||
// or https://www.aliexpress.com/store/product/E001-1-54-inch-partial-refresh-Small-size-dot-matrix-e-paper-display/600281_32815089163.html
|
||
//
|
||
|
||
// Supporting Arduino Forum Topics:
|
||
// Waveshare e-paper displays with SPI: http://forum.arduino.cc/index.php?topic=487007.0
|
||
// Good Dispay ePaper for Arduino : https://forum.arduino.cc/index.php?topic=436411.0
|
||
|
||
// mapping suggestion from Waveshare SPI e-Paper to Wemos D1 mini
|
||
// BUSY -> D2, RST -> D4, DC -> D3, CS -> D8, CLK -> D5, DIN -> D7, GND -> GND, 3.3V -> 3.3V
|
||
|
||
// mapping suggestion from Waveshare SPI e-Paper to generic ESP8266
|
||
// BUSY -> GPIO4, RST -> GPIO2, DC -> GPIO0, CS -> GPIO15, CLK -> GPIO14, DIN -> GPIO13, GND -> GND, 3.3V -> 3.3V
|
||
|
||
// mapping suggestion for ESP32, e.g. LOLIN32, see .../variants/.../pins_arduino.h for your board
|
||
// NOTE: there are variants with different pins for SPI ! CHECK SPI PINS OF YOUR BOARD
|
||
// BUSY -> 4, RST -> 16, DC -> 17, CS -> SS(5), CLK -> SCK(18), DIN -> MOSI(23), GND -> GND, 3.3V -> 3.3V
|
||
|
||
// new mapping suggestion for STM32F1, e.g. STM32F103C8T6 "BluePill"
|
||
// BUSY -> A1, RST -> A2, DC -> A3, CS-> A4, CLK -> A5, DIN -> A7
|
||
|
||
// mapping suggestion for AVR, UNO, NANO etc.
|
||
// BUSY -> 7, RST -> 9, DC -> 8, CS-> 10, CLK -> 13, DIN -> 11
|
||
//
|
||
// **** NOTE that the mapping suggestion may need modification depending on SD board used! ****
|
||
// ********************************************************************************************
|
||
//
|
||
// **** NOTE: does not compile for small RAM AVR, not enough RAM. Not tested on MEGA.
|
||
|
||
#include <SPI.h>
|
||
|
||
#if defined(ESP32)
|
||
|
||
#define SD_CS 2
|
||
#define EPD_CS SS
|
||
|
||
// has support for FAT32 support with long filenames
|
||
#include "FS.h"
|
||
#include "SD.h"
|
||
#include "SPI.h"
|
||
#define SdFile File
|
||
#define seekSet seek
|
||
|
||
#elif defined(ESP8266)
|
||
|
||
#define SD_CS SS // e.g. for RobotDyn Wemos D1 mini SD board
|
||
#define EPD_CS D1 // alternative I use with RobotDyn Wemos D1 mini SD board
|
||
|
||
// include SdFat for FAT32 support with long filenames; available through Library Manager
|
||
#include <SdFat.h>
|
||
SdFat SD;
|
||
|
||
#else
|
||
|
||
#define SD_CS 6
|
||
#define EPD_CS SS
|
||
|
||
// include SdFat for FAT32 support with long filenames; available through Library Manager
|
||
#include <SdFat.h>
|
||
SdFat SD;
|
||
|
||
#endif
|
||
|
||
// include library, include base class, make path known
|
||
#include <GxEPD.h>
|
||
|
||
// select the display class to use, only one
|
||
//#include <GxDEPG0150BN/GxDEPG0150BN.h> // 1.50" b/w
|
||
//#include <GxGDEP015OC1/GxGDEP015OC1.h> // 1.54" b/w
|
||
//#include <GxGDEH0154D67/GxGDEH0154D67.h> // 1.54" b/w 200x200, SSD1681
|
||
//#include <GxGDEW0154T8/GxGDEW0154T8.h> // 1.54" b/w 152x152 UC8151 (IL0373)
|
||
//#include <GxGDEW0154M09/GxGDEW0154M09.h> // 1.54" b/w 200x200 JD79653A
|
||
//#include <GxGDEW0154M10/GxGDEW0154M10.h> // 1.54" b/w 152x152 UC8151D
|
||
//#include <GxGDEW0154Z04/GxGDEW0154Z04.h> // 1.54" b/w/r 200x200
|
||
//#include <GxGDEW0154Z17/GxGDEW0154Z17.h> // 1.54" b/w/r 152x152
|
||
//#include <GxGDEH0154Z90/GxGDEH0154Z90.h> // 1.54" b/w/r 200x200 SSD1681
|
||
//#include <GxGDEW0213I5F/GxGDEW0213I5F.h> // 2.13" b/w 104x212 flexible
|
||
//#include <GxGDE0213B1/GxGDE0213B1.h> // 2.13" b/w
|
||
//#include <GxGDEH0213B72/GxGDEH0213B72.h> // 2.13" b/w new panel
|
||
//#include <GxGDEH0213B73/GxGDEH0213B73.h> // 2.13" b/w newer panel
|
||
//#include <GxGDEM0213B74/GxGDEM0213B74.h> // 2.13" b/w 128x250 SSD1680
|
||
//#include <GxGDEW0213Z16/GxGDEW0213Z16.h> // 2.13" b/w/r
|
||
//#include <GxGDEH0213Z19/GxGDEH0213Z19.h> // 2.13" b/w/r UC8151D
|
||
//#include <GxGDEW0213T5D/GxGDEW0213T5D.h> // 2.13" b/w 104x212 UC8151D
|
||
//#include <GxDEPG0213BN/GxDEPG0213BN.h> // 2.13" b/w 128x250, SSD1680, TTGO T5 V2.4.1, V2.3.1
|
||
//#include <GxGDEH029A1/GxGDEH029A1.h> // 2.9" b/w
|
||
//#include <GxGDEW029T5/GxGDEW029T5.h> // 2.9" b/w UC8151 (IL0373)
|
||
//#include <GxGDEW029T5D/GxGDEW029T5D.h> // 2.9" b/w UC8151D
|
||
//#include <GxGDEM029T94/GxGDEM029T94.h> // 2.9" b/w
|
||
//#include <GxDEPG0290BS/GxDEPG0290BS.h> // 2.9" b/w Waveshare variant, TTGO T5 V2.4.1 2.9"
|
||
//#include <GxGDEW029Z10/GxGDEW029Z10.h> // 2.9" b/w/r
|
||
//#include <GxGDEH029Z13/GxGDEH029Z13.h> // 2.9" b/w/r UC8151D
|
||
//#include <GxGDEW026T0/GxGDEW026T0.h> // 2.6" b/w
|
||
//#include <GxDEPG0266BN/GxDEPG0266BN.h> // 2.66" b/w 152x296, SSD1680, TTGO T5 V2.66, TTGO T5 V2.4.1
|
||
//#include <GxGDEW027C44/GxGDEW027C44.h> // 2.7" b/w/r
|
||
//#include <GxGDEW027W3/GxGDEW027W3.h> // 2.7" b/w
|
||
//#include <GxGDEY027T91/GxGDEY027T91.h> // 2.7" b/w
|
||
//#include <GxGDEW0371W7/GxGDEW0371W7.h> // 3.7" b/w
|
||
//#include <GxGDEW042T2/GxGDEW042T2.h> // 4.2" b/w
|
||
//#include <GxGDEW042Z15/GxGDEW042Z15.h> // 4.2" b/w/r
|
||
//#include <GxGDEW0583T7/GxGDEW0583T7.h> // 5.83" b/w
|
||
//#include <GxGDEW075T8/GxGDEW075T8.h> // 7.5" b/w
|
||
//#include <GxGDEW075T7/GxGDEW075T7.h> // 7.5" b/w 800x480
|
||
//#include <GxGDEW075Z09/GxGDEW075Z09.h> // 7.5" b/w/r
|
||
//#include <GxGDEW075Z08/GxGDEW075Z08.h> // 7.5" b/w/r 800x480
|
||
|
||
#include <GxIO/GxIO_SPI/GxIO_SPI.h>
|
||
#include <GxIO/GxIO.h>
|
||
|
||
#if defined(ESP8266)
|
||
|
||
// for SPI pin definitions see e.g.:
|
||
// C:\Users\xxx\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic\common.h
|
||
|
||
GxIO_Class io(SPI, /*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2); // arbitrary selection of D3(=0), D4(=2), selected for default of GxEPD_Class
|
||
GxEPD_Class display(io /*RST=D4*/ /*BUSY=D2*/); // default selection of D4(=2), D2(=4)
|
||
// Heltec E-Paper 1.54" b/w without RST, BUSY
|
||
//GxEPD_Class display(io, /*RST=D4*/ -1, /*BUSY=D2*/ -1); // no RST, no BUSY
|
||
|
||
#elif defined(ESP32)
|
||
|
||
// for SPI pin definitions see e.g.:
|
||
// C:\Users\xxx\Documents\Arduino\hardware\espressif\esp32\variants\lolin32\pins_arduino.h
|
||
// for LILYGO® TTGO T5 2.66 board uncomment next two lines instead of previous two lines
|
||
//GxIO_Class io(SPI, /*CS=5*/ SS, /*DC=*/ 19, /*RST=*/ 4); // LILYGO® TTGO T5 2.66
|
||
//GxEPD_Class display(io, /*RST=*/ 4, /*BUSY=*/ 34); // LILYGO® TTGO T5 2.66
|
||
|
||
GxIO_Class io(SPI, /*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16); // arbitrary selection of 17, 16
|
||
GxEPD_Class display(io, /*RST=*/ 16, /*BUSY=*/ 4); // arbitrary selection of (16), 4
|
||
|
||
#elif defined(ARDUINO_ARCH_SAMD)
|
||
|
||
// for SPI pin definitions see e.g.:
|
||
// C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.19\variants\mkr1000\variant.h
|
||
// C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.19\variants\mkrzero\variant.h
|
||
|
||
GxIO_Class io(SPI, /*CS=*/ EPD_CS, /*DC=*/ 7, /*RST=*/ 6);
|
||
GxEPD_Class display(io, /*RST=*/ 6, /*BUSY=*/ 5);
|
||
|
||
#elif defined(ARDUINO_GENERIC_STM32F103C) && defined(MCU_STM32F103C8)
|
||
|
||
// STM32 Boards(STM32duino.com) Generic STM32F103C series STM32F103C8
|
||
// for SPI pin definitions see e.g.:
|
||
// C:\Users\xxx\Documents\Arduino\hardware\Arduino_STM32\STM32F1\variants\generic_stm32f103c\variant.h
|
||
// C:\Users\xxx\Documents\Arduino\hardware\Arduino_STM32\STM32F1\variants\generic_stm32f103c\board\board.h
|
||
|
||
// new mapping suggestion for STM32F1, e.g. STM32F103C8T6 "BluePill"
|
||
// BUSY -> A1, RST -> A2, DC -> A3, CS-> A4, CLK -> A5, DIN -> A7
|
||
|
||
GxIO_Class io(SPI, /*CS=*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2);
|
||
GxEPD_Class display(io, /*RST=*/ 2, /*BUSY=*/ 1);
|
||
|
||
#elif defined(ARDUINO_GENERIC_STM32F103V) && defined(MCU_STM32F103VB)
|
||
|
||
// STM32 Boards(STM32duino.com) Generic STM32F103V series STM32F103VB
|
||
// for SPI pin definitions see e.g.:
|
||
// C:\Users\xxx\Documents\Arduino\hardware\Arduino_STM32\STM32F1\variants\generic_stm32f103vb\variant.h
|
||
// C:\Users\xxx\Documents\Arduino\hardware\Arduino_STM32\STM32F1\variants\generic_stm32f103vb\board\board.h
|
||
|
||
// Good Display DESPI-M01
|
||
// note: needs jumper wires from SS=PA4->CS, SCK=PA5->SCK, MOSI=PA7->SDI
|
||
|
||
GxIO_Class io(SPI, /*CS=*/ EPD_CS, /*DC=*/ PE15, /*RST=*/ PE14); // DC, RST as wired by DESPI-M01
|
||
GxEPD_Class display(io, /*RST=*/ PE14, /*BUSY=*/ PE13); // RST, BUSY as wired by DESPI-M01
|
||
|
||
#else
|
||
|
||
// for SPI pin definitions see e.g.:
|
||
// C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\variants\standard\pins_arduino.h
|
||
|
||
GxIO_Class io(SPI, /*CS=*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9); // arbitrary selection of 8, 9 selected for default of GxEPD_Class
|
||
GxEPD_Class display(io /*RST=9*/ /*BUSY=7*/); // default selection of (9), 7
|
||
|
||
#endif
|
||
|
||
// function declaration with default parameter
|
||
void drawBitmapFromSD(const char *filename, int16_t x, int16_t y, bool with_color = true);
|
||
|
||
void setup(void)
|
||
{
|
||
Serial.begin(115200);
|
||
Serial.println();
|
||
Serial.println("GxEPD_SD_Example");
|
||
|
||
display.init(115200); // enable diagnostic output on Serial
|
||
|
||
Serial.print("Initializing SD card...");
|
||
if (!SD.begin(SD_CS))
|
||
{
|
||
Serial.println("SD failed!");
|
||
return;
|
||
}
|
||
Serial.println("SD OK!");
|
||
|
||
drawBitmaps_200x200();
|
||
drawBitmaps_other();
|
||
|
||
//drawBitmaps_test();
|
||
|
||
Serial.println("GxEPD_SD_Example done");
|
||
}
|
||
|
||
void loop()
|
||
{
|
||
}
|
||
|
||
void drawBitmaps_200x200()
|
||
{
|
||
int16_t x = (display.width() - 200) / 2;
|
||
int16_t y = (display.height() - 200) / 2;
|
||
drawBitmapFromSD("logo200x200.bmp", x, y);
|
||
delay(2000);
|
||
drawBitmapFromSD("first200x200.bmp", x, y);
|
||
delay(2000);
|
||
drawBitmapFromSD("second200x200.bmp", x, y);
|
||
delay(2000);
|
||
drawBitmapFromSD("third200x200.bmp", x, y);
|
||
delay(2000);
|
||
drawBitmapFromSD("fourth200x200.bmp", x, y);
|
||
delay(2000);
|
||
drawBitmapFromSD("fifth200x200.bmp", x, y);
|
||
delay(2000);
|
||
drawBitmapFromSD("sixth200x200.bmp", x, y);
|
||
delay(2000);
|
||
drawBitmapFromSD("seventh200x200.bmp", x, y);
|
||
delay(2000);
|
||
drawBitmapFromSD("eighth200x200.bmp", x, y);
|
||
delay(2000);
|
||
}
|
||
|
||
void drawBitmaps_other()
|
||
{
|
||
int16_t w2 = display.width() / 2;
|
||
int16_t h2 = display.height() / 2;
|
||
drawBitmapFromSD("parrot.bmp", w2 - 64, h2 - 80);
|
||
delay(2000);
|
||
drawBitmapFromSD("betty_1.bmp", w2 - 100, h2 - 160);
|
||
delay(2000);
|
||
drawBitmapFromSD("betty_4.bmp", w2 - 102, h2 - 126);
|
||
delay(2000);
|
||
drawBitmapFromSD("marilyn_240x240x8.bmp", w2 - 120, h2 - 120);
|
||
delay(2000);
|
||
drawBitmapFromSD("miniwoof.bmp", w2 - 60, h2 - 80);
|
||
delay(2000);
|
||
drawBitmapFromSD("t200x200.bmp", w2 - 100, h2 - 100);
|
||
delay(2000);
|
||
drawBitmapFromSD("test.bmp", w2 - 120, h2 - 160);
|
||
delay(2000);
|
||
drawBitmapFromSD("tiger.bmp", w2 - 160, h2 - 120);
|
||
delay(2000);
|
||
drawBitmapFromSD("tiger_178x160x4.bmp", w2 - 89, h2 - 80);
|
||
delay(2000);
|
||
drawBitmapFromSD("tiger_240x317x4.bmp", w2 - 120, h2 - 160);
|
||
delay(2000);
|
||
drawBitmapFromSD("tiger_320x200x24.bmp", w2 - 160, h2 - 100);
|
||
delay(2000);
|
||
drawBitmapFromSD("tiger16T.bmp", w2 - 160, h2 - 120);
|
||
delay(2000);
|
||
drawBitmapFromSD("woof.bmp", w2 - 120, h2 - 160);
|
||
delay(2000);
|
||
drawBitmapFromSD("bitmap640x384_1.bmp", 0, 0);
|
||
delay(2000);
|
||
}
|
||
|
||
void drawBitmaps_test()
|
||
{
|
||
int16_t w2 = display.width() / 2;
|
||
int16_t h2 = display.height() / 2;
|
||
drawBitmapFromSD("betty_4.bmp", w2 - 102, h2 - 126);
|
||
delay(2000);
|
||
drawBitmapFromSD("bb4.bmp", 0, 0);
|
||
delay(2000);
|
||
}
|
||
|
||
static const uint16_t input_buffer_pixels = 20; // may affect performance
|
||
|
||
static const uint16_t max_palette_pixels = 256; // for depth <= 8
|
||
|
||
uint8_t input_buffer[3 * input_buffer_pixels]; // up to depth 24
|
||
uint8_t mono_palette_buffer[max_palette_pixels / 8]; // palette buffer for depth <= 8 b/w
|
||
uint8_t color_palette_buffer[max_palette_pixels / 8]; // palette buffer for depth <= 8 c/w
|
||
|
||
void drawBitmapFrom_SD_ToBuffer(const char *filename, int16_t x, int16_t y, bool with_color)
|
||
{
|
||
SdFile file;
|
||
bool valid = false; // valid format to be handled
|
||
bool flip = true; // bitmap is stored bottom-to-top
|
||
uint32_t startTime = millis();
|
||
if ((x >= display.width()) || (y >= display.height())) return;
|
||
Serial.println();
|
||
Serial.print("Loading image '");
|
||
Serial.print(filename);
|
||
Serial.println('\'');
|
||
#if defined(ESP32)
|
||
file = SD.open(String("/") + filename, FILE_READ);
|
||
if (!file)
|
||
{
|
||
Serial.print("File not found");
|
||
return;
|
||
}
|
||
#else
|
||
if (!file.open(filename, FILE_READ))
|
||
{
|
||
Serial.print("File not found");
|
||
return;
|
||
}
|
||
#endif
|
||
// Parse BMP header
|
||
if (read16(file) == 0x4D42) // BMP signature
|
||
{
|
||
int32_t fileSize = read32(file);
|
||
int32_t creatorBytes = read32(file);
|
||
int32_t imageOffset = read32(file); // Start of image data
|
||
int32_t headerSize = read32(file);
|
||
int32_t width = read32(file);
|
||
int32_t height = read32(file);
|
||
uint16_t planes = read16(file);
|
||
uint16_t depth = read16(file); // bits per pixel
|
||
int32_t format = read32(file);
|
||
(void) creatorBytes;
|
||
if ((planes == 1) && ((format == 0) || (format == 3))) // uncompressed is handled, 565 also
|
||
{
|
||
Serial.print("File size: "); Serial.println(fileSize);
|
||
Serial.print("Image Offset: "); Serial.println(imageOffset);
|
||
Serial.print("Header size: "); Serial.println(headerSize);
|
||
Serial.print("Bit Depth: "); Serial.println(depth);
|
||
Serial.print("Image size: ");
|
||
Serial.print(width);
|
||
Serial.print('x');
|
||
Serial.println(height);
|
||
// BMP rows are padded (if needed) to 4-byte boundary
|
||
int32_t rowSize = (width * depth / 8 + 3) & ~3;
|
||
if (depth < 8) rowSize = ((width * depth + 8 - depth) / 8 + 3) & ~3;
|
||
if (height < 0)
|
||
{
|
||
height = -height;
|
||
flip = false;
|
||
}
|
||
uint16_t w = width;
|
||
uint16_t h = height;
|
||
if ((x + w - 1) >= display.width()) w = display.width() - x;
|
||
if ((y + h - 1) >= display.height()) h = display.height() - y;
|
||
valid = true;
|
||
uint8_t bitmask = 0xFF;
|
||
uint8_t bitshift = 8 - depth;
|
||
uint16_t red, green, blue;
|
||
bool whitish = false;
|
||
bool colored = false;
|
||
if (depth == 1) with_color = false;
|
||
if (depth <= 8)
|
||
{
|
||
if (depth < 8) bitmask >>= depth;
|
||
//file.seekSet(54); //palette is always @ 54
|
||
file.seekSet(imageOffset - (4 << depth)); // 54 for regular, diff for colorsimportant
|
||
for (uint16_t pn = 0; pn < (1 << depth); pn++)
|
||
{
|
||
blue = file.read();
|
||
green = file.read();
|
||
red = file.read();
|
||
file.read();
|
||
whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
|
||
colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
|
||
if (0 == pn % 8) mono_palette_buffer[pn / 8] = 0;
|
||
mono_palette_buffer[pn / 8] |= whitish << pn % 8;
|
||
if (0 == pn % 8) color_palette_buffer[pn / 8] = 0;
|
||
color_palette_buffer[pn / 8] |= colored << pn % 8;
|
||
}
|
||
}
|
||
display.fillScreen(GxEPD_WHITE);
|
||
int32_t rowPosition = flip ? imageOffset + (height - h) * rowSize : imageOffset;
|
||
for (uint16_t row = 0; row < h; row++, rowPosition += rowSize) // for each line
|
||
{
|
||
uint32_t in_remain = rowSize;
|
||
uint32_t in_idx = 0;
|
||
uint32_t in_bytes = 0;
|
||
uint8_t in_byte = 0; // for depth <= 8
|
||
uint8_t in_bits = 0; // for depth <= 8
|
||
uint16_t color = GxEPD_WHITE;
|
||
file.seekSet(rowPosition);
|
||
for (uint16_t col = 0; col < w; col++) // for each pixel
|
||
{
|
||
// Time to read more pixel data?
|
||
if (in_idx >= in_bytes) // ok, exact match for 24bit also (size IS multiple of 3)
|
||
{
|
||
in_bytes = file.read(input_buffer, in_remain > sizeof(input_buffer) ? sizeof(input_buffer) : in_remain);
|
||
in_remain -= in_bytes;
|
||
in_idx = 0;
|
||
}
|
||
switch (depth)
|
||
{
|
||
case 24:
|
||
blue = input_buffer[in_idx++];
|
||
green = input_buffer[in_idx++];
|
||
red = input_buffer[in_idx++];
|
||
whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
|
||
colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
|
||
break;
|
||
case 16:
|
||
{
|
||
uint8_t lsb = input_buffer[in_idx++];
|
||
uint8_t msb = input_buffer[in_idx++];
|
||
if (format == 0) // 555
|
||
{
|
||
blue = (lsb & 0x1F) << 3;
|
||
green = ((msb & 0x03) << 6) | ((lsb & 0xE0) >> 2);
|
||
red = (msb & 0x7C) << 1;
|
||
}
|
||
else // 565
|
||
{
|
||
blue = (lsb & 0x1F) << 3;
|
||
green = ((msb & 0x07) << 5) | ((lsb & 0xE0) >> 3);
|
||
red = (msb & 0xF8);
|
||
}
|
||
whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
|
||
colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
|
||
}
|
||
break;
|
||
case 1:
|
||
case 4:
|
||
case 8:
|
||
{
|
||
if (0 == in_bits)
|
||
{
|
||
in_byte = input_buffer[in_idx++];
|
||
in_bits = 8;
|
||
}
|
||
uint16_t pn = (in_byte >> bitshift) & bitmask;
|
||
whitish = mono_palette_buffer[pn / 8] & (0x1 << pn % 8);
|
||
colored = color_palette_buffer[pn / 8] & (0x1 << pn % 8);
|
||
in_byte <<= depth;
|
||
in_bits -= depth;
|
||
}
|
||
break;
|
||
}
|
||
if (whitish)
|
||
{
|
||
color = GxEPD_WHITE;
|
||
}
|
||
else if (colored && with_color)
|
||
{
|
||
color = GxEPD_RED;
|
||
}
|
||
else
|
||
{
|
||
color = GxEPD_BLACK;
|
||
}
|
||
uint16_t yrow = y + (flip ? h - row - 1 : row);
|
||
display.drawPixel(x + col, yrow, color);
|
||
} // end pixel
|
||
} // end line
|
||
Serial.print("loaded in "); Serial.print(millis() - startTime); Serial.println(" ms");
|
||
}
|
||
}
|
||
file.close();
|
||
if (!valid)
|
||
{
|
||
Serial.println("bitmap format not handled.");
|
||
}
|
||
}
|
||
|
||
#if defined(__AVR) //|| true
|
||
|
||
struct Parameters
|
||
{
|
||
const char* filename;
|
||
int16_t x;
|
||
int16_t y;
|
||
bool with_color;
|
||
};
|
||
|
||
void drawBitmapFrom_SD_ToBuffer_Callback(const void* params)
|
||
{
|
||
const Parameters* p = reinterpret_cast<const Parameters*>(params);
|
||
drawBitmapFrom_SD_ToBuffer(p->filename, p->x, p->y, p->with_color);
|
||
}
|
||
|
||
void drawBitmapFromSD(const char *filename, int16_t x, int16_t y, bool with_color)
|
||
{
|
||
Parameters parameters{filename, x, y, with_color};
|
||
display.drawPaged(drawBitmapFrom_SD_ToBuffer_Callback, ¶meters);
|
||
}
|
||
|
||
#else
|
||
|
||
void drawBitmapFromSD(const char *filename, int16_t x, int16_t y, bool with_color)
|
||
{
|
||
drawBitmapFrom_SD_ToBuffer(filename, x, y, with_color);
|
||
display.update();
|
||
}
|
||
|
||
#endif
|
||
|
||
uint16_t read16(SdFile& f)
|
||
{
|
||
// BMP data is stored little-endian, same as Arduino.
|
||
uint16_t result;
|
||
((uint8_t *)&result)[0] = f.read(); // LSB
|
||
((uint8_t *)&result)[1] = f.read(); // MSB
|
||
return result;
|
||
}
|
||
|
||
int32_t read32(SdFile& f)
|
||
{
|
||
// BMP data is stored little-endian, same as Arduino.
|
||
int32_t result;
|
||
((uint8_t *)&result)[0] = f.read(); // LSB
|
||
((uint8_t *)&result)[1] = f.read();
|
||
((uint8_t *)&result)[2] = f.read();
|
||
((uint8_t *)&result)[3] = f.read(); // MSB
|
||
return result;
|
||
}
|