Skip to content

Commit

Permalink
Add support for Waveshare 1.54" ePaper
Browse files Browse the repository at this point in the history
Co-authored-by: dAjaY85 <[email protected]>
  • Loading branch information
mtavenrath and dAjaY85 committed Jun 21, 2024
1 parent c144b68 commit 027e382
Show file tree
Hide file tree
Showing 18 changed files with 2,015 additions and 29 deletions.
41 changes: 41 additions & 0 deletions docs/DeviceProfiles/opendtu_fusion.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,46 @@
"data": 2,
"clk": 1
}
},
{
"name": "OpenDTU Fusion v2 with CMT2300A, NRF24 and ePaper Display",
"nrf24": {
"miso": 48,
"mosi": 35,
"clk": 36,
"irq": 47,
"en": 38,
"cs": 37
},
"cmt": {
"clk": 6,
"cs": 4,
"fcs": 21,
"sdio": 5,
"gpio2": 3,
"gpio3": 8
},
"eth": {
"enabled": false,
"phy_addr": -1,
"power": -1,
"mdc": -1,
"mdio": -1,
"type": 0,
"clk_mode": 0
},
"led": {
"led0": 17,
"led1": 18
},
"display": {
"type": 6,
"data": 9,
"clk": 10,
"cs": 11,
"reset": 13,
"busy": 14,
"dc": 12
}
}
]
1 change: 1 addition & 0 deletions include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ struct CONFIG_T {
uint8_t Rotation;
uint8_t Contrast;
uint8_t Language;
uint16_t UpdatePeriod;
struct {
uint32_t Duration;
uint8_t Mode;
Expand Down
50 changes: 50 additions & 0 deletions include/Display.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once

#include "defaults.h"
#include <Arduino.h>
#include <TaskSchedulerDeclarations.h>

enum DisplayType_t {
None,
PCD8544,
SSD1306,
SH1106,
SSD1309,
ST7567_GM12864I_59N,
ePaper154,
DisplayType_Max,
};

enum DiagramMode_t {
Off,
Small,
Fullscreen,
DisplayMode_Max,
};

class DisplayClass {
public:
void init(Scheduler& scheduler, DisplayType_t _type, uint8_t _data, uint8_t _clk, uint8_t _cs, uint8_t _reset, uint8_t _busy, uint8_t _dc);

void setContrast(uint8_t contrast);
void setStatus(bool turnOn);
void setOrientation(uint8_t rotation = DISPLAY_ROTATION);
void setLanguage(uint8_t language);
void setUpdatePeriod(uint16_t updatePeriod);
void setEnablePowerSafe(bool display_PowerSafe);
void setEnableScreensaver(bool display_ScreenSaver);
void setDiagramMode(DiagramMode_t mode);
void setStartupDisplay();
void DiagramUpdatePeriod();

private:
bool _displayTurnedOn;

DisplayType_t _display_type = DisplayType_t::None;
uint32_t _lastDisplayUpdate = 0;
uint16_t _counterEPaper;
uint16_t _settedUpdatePeriod = 10000; // Achtung, max 65535
};

extern DisplayClass Display;
20 changes: 2 additions & 18 deletions include/Display_Graphic.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once

#include "Display.h"
#include "Display_Graphic_Diagram.h"
#include "defaults.h"
#include <TaskSchedulerDeclarations.h>
Expand All @@ -14,23 +15,6 @@
#define CHART_POSX 80
#define CHART_POSY 0

enum DisplayType_t {
None,
PCD8544,
SSD1306,
SH1106,
SSD1309,
ST7567_GM12864I_59N,
DisplayType_Max,
};

enum DiagramMode_t {
Off,
Small,
Fullscreen,
DisplayMode_Max,
};

class DisplayGraphicClass {
public:
DisplayGraphicClass();
Expand Down Expand Up @@ -75,4 +59,4 @@ class DisplayGraphicClass {
uint8_t _lineOffsets[5];
};

extern DisplayGraphicClass Display;
extern DisplayGraphicClass DisplayGraphic;
58 changes: 58 additions & 0 deletions include/Display_ePaper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once

/// uncomment next line to use class GFX of library GFX_Root instead of Adafruit_GFX, to use less code and ram
// #include <GFX.h>
// base class GxEPD2_GFX can be used to pass references or pointers to the display instance as parameter, uses ~1.2k more code
// enable GxEPD2_GFX base class
#define ENABLE_GxEPD2_GFX 1

#include "Display.h"
#include <GxEPD2_3C.h>
#include <GxEPD2_BW.h>
#include <SPI.h>
#include <map>

// FreeFonts from Adafruit_GFX
#include <Fonts/FreeSans12pt7b.h>
#include <Fonts/FreeSans18pt7b.h>
#include <Fonts/FreeSans24pt7b.h>
#include <Fonts/FreeSans9pt7b.h>

#include "defaults.h"
#include "imagedata.h"

// GDEW027C44 2.7 " b/w/r 176x264, IL91874
// GDEH0154D67 1.54" b/w 200x200

class DisplayEPaperClass {
public:
DisplayEPaperClass();
~DisplayEPaperClass();

void init(Scheduler& scheduler, DisplayType_t type, uint8_t _CS, uint8_t _DC, uint8_t _RST, uint8_t _BUSY, uint8_t _SCK, uint8_t _MOSI);
void loop();
void fullRefresh();
void setOrientation(uint8_t rotation);
void setLanguage(uint8_t language);

private:
void headlineIP();
void actualPowerPaged(float _totalPower, float _totalYieldDay, float _totalYieldTotal, uint8_t _isprod);
void lastUpdatePaged();

Task _loopTask;

const uint16_t _period = 10000;
uint16_t _counterEPaper;

bool _changed = false;
char _fmtText[35];
String _settedIP;
uint8_t _headfootline = 16;
uint8_t _displayRotation = DISPLAY_ROTATION;
uint8_t _display_language = DISPLAY_LANGUAGE;
GxEPD2_GFX* _display;
};

extern DisplayEPaperClass DisplayEPaper;
2 changes: 2 additions & 0 deletions include/PinMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ struct PinMapping_t {
uint8_t display_clk;
uint8_t display_cs;
uint8_t display_reset;
uint8_t display_busy; // for epaper
uint8_t display_dc; // for epaper
int8_t led[PINMAPPING_LED_COUNT];
};

Expand Down
1 change: 1 addition & 0 deletions include/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
#define DISPLAY_ROTATION 2U
#define DISPLAY_CONTRAST 60U
#define DISPLAY_LANGUAGE 0U
#define DISPLAY_UPDATE 10000 // epaper
#define DISPLAY_DIAGRAM_DURATION (10UL * 60UL * 60UL)
#define DISPLAY_DIAGRAM_MODE 1U

Expand Down
12 changes: 12 additions & 0 deletions include/imagedata.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once

extern const unsigned char AhoyLogo[];
extern const unsigned char OpenDTULogo[];
extern const unsigned char myHoy[];
extern const unsigned char mySigma[];
extern const unsigned char mySun[];
extern const unsigned char myToday[];
extern const unsigned char myWR[];

extern const unsigned char gImage_1in54[];
Loading

0 comments on commit 027e382

Please sign in to comment.