Skip to content

Commit 2151248

Browse files
committed
Initialise the FSF screen
1 parent 99bfd6f commit 2151248

File tree

5 files changed

+217
-8
lines changed

5 files changed

+217
-8
lines changed

platformio.ini

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ debug_flags =
5555
#-D ENABLE_DEBUG_EVSE_MONITOR
5656
#-D ENABLE_DEBUG_DIVERT
5757
#-D ENABLE_DEBUG_LED
58-
#-D ENABLE_DEBUG_LCD
58+
-D ENABLE_DEBUG_LCD
5959
#-D ENABLE_DEBUG_MQTT
6060
#-D ENABLE_DEBUG_EMONCMS
6161
#-D ENABLE_DEBUG_TESLA_CLIENT
@@ -105,8 +105,36 @@ build_partitions_debug = min_spiffs_debug.csv
105105
neopixel_lib = adafruit/Adafruit [email protected]
106106

107107
gfx_display_libs =
108-
109-
bodmer/TFT_eSPI@^2.5.31
108+
109+
bodmer/TFT_eSPI@^2.5.31
110+
SPI
111+
112+
gfx_display_build_flags =
113+
-D LV_CONF_INCLUDE_SIMPLE
114+
-D LV_CONF_SUPPRESS_DEFINE_CHECK
115+
-D USER_SETUP_LOADED
116+
-D ILI9488_DRIVER
117+
-D TFT_WIDTH=320
118+
-D TFT_HEIGHT=480
119+
-D TFT_BL=27
120+
-D TFT_MISO=12
121+
-D TFT_MOSI=13
122+
-D TFT_SCLK=14
123+
-D TFT_CS=15
124+
-D TFT_DC=2
125+
-D TFT_RST=-1
126+
-D TOUCH_CS=33
127+
-D LOAD_GLCD
128+
-D LOAD_FONT2
129+
-D LOAD_FONT4
130+
-D LOAD_FONT6
131+
-D LOAD_FONT7
132+
-D LOAD_FONT8
133+
-D LOAD_GFXFF
134+
-D SPI_FREQUENCY=15999999
135+
-D SPI_READ_FREQUENCY=20000000
136+
-D SPI_TOUCH_FREQUENCY=600000
137+
-D ENABLE_SCREEN_LCD_TFT
110138

111139
[env]
112140
# specify exact Arduino ESP SDK version, requires platformio 3.5+ (curently dev version)
@@ -332,6 +360,17 @@ build_flags =
332360
-D RAPI_PORT=Serial1
333361
-D RX1=16
334362
-D TX1=17
335-
#lib_deps =
336-
# ${common.lib_deps}
337-
# ${common.gfx_display_libs}
363+
lib_deps =
364+
${common.lib_deps}
365+
${common.gfx_display_libs}
366+
367+
[env:elecrow_esp32_hmi_dev]
368+
extends = env:elecrow_esp32_hmi
369+
build_flags =
370+
${env:elecrow_esp32_hmi.build_flags}
371+
${common.debug_flags}
372+
${common.gfx_display_build_flags}
373+
upload_protocol = custom
374+
upload_command = curl -F firmware=@$SOURCE http://$UPLOAD_PORT/update
375+
#build_type = debug
376+
#board_build.partitions = ${common.build_partitions_debug}

src/lcd.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#undef ENABLE_DEBUG
33
#endif
44

5+
#ifndef ENABLE_SCREEN_LCD_TFT
6+
57
#include "emonesp.h"
68
#include "lcd.h"
79
#include "RapiSender.h"
@@ -734,3 +736,5 @@ void LcdTask::onButton(int long_press)
734736
}
735737

736738
LcdTask lcd;
739+
740+
#endif // ENABLE_SCREEN_LCD_TFT

src/lcd.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@
66
#define LCD_CLEAR_LINE (1 << 0)
77
#define LCD_DISPLAY_NOW (1 << 1)
88

9-
#define LCD_MAX_LEN 16
10-
119
#ifndef LCD_DISPLAY_CHANGE_TIME
1210
#define LCD_DISPLAY_CHANGE_TIME (4 * 1000)
1311
#endif
1412

13+
#if ENABLE_SCREEN_LCD_TFT
14+
// HACK: This should be done in a much more C++ way
15+
#include "lcd_tft.h"
16+
#else
17+
18+
#define LCD_MAX_LEN 16
19+
1520
#define LCD_CHAR_STOP 1
1621
#define LCD_CHAR_PLAY 2
1722
#define LCD_CHAR_LIGHTNING 3
@@ -151,6 +156,9 @@ class LcdTask : public MicroTasks::Task
151156
void display(const char *msg, int x, int y, int time, uint32_t flags);
152157
};
153158

159+
#endif // ENABLE_SCREEN_LCD_TFT
160+
154161
extern LcdTask lcd;
155162

156163
#endif // __LCD_H
164+

src/lcd_tft.cpp

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#if defined(ENABLE_DEBUG) && !defined(ENABLE_DEBUG_LCD)
2+
#undef ENABLE_DEBUG
3+
#endif
4+
5+
#ifdef ENABLE_SCREEN_LCD_TFT
6+
7+
#ifndef LCD_BACKLIGHT_PIN
8+
#define LCD_BACKLIGHT_PIN TFT_BL
9+
#endif
10+
11+
#include "emonesp.h"
12+
#include "lcd.h"
13+
#include "RapiSender.h"
14+
#include "openevse.h"
15+
#include "input.h"
16+
#include "app_config.h"
17+
#include <sys/time.h>
18+
19+
void LcdTask::displayFlush( lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p )
20+
{
21+
uint32_t w = ( area->x2 - area->x1 + 1 );
22+
uint32_t h = ( area->y2 - area->y1 + 1 );
23+
24+
lcd._lcd.startWrite();
25+
lcd._lcd.setAddrWindow( area->x1, area->y1, w, h );
26+
lcd._lcd.pushColors( ( uint16_t * )&color_p->full, w * h, true );
27+
lcd._lcd.endWrite();
28+
29+
lv_disp_flush_ready( disp );
30+
}
31+
32+
LcdTask::LcdTask() :
33+
MicroTasks::Task(),
34+
_lcd()
35+
{
36+
}
37+
38+
void LcdTask::display(const __FlashStringHelper *msg, int x, int y, int time, uint32_t flags)
39+
{
40+
}
41+
42+
void LcdTask::display(String &msg, int x, int y, int time, uint32_t flags)
43+
{
44+
}
45+
46+
void LcdTask::display(const char *msg, int x, int y, int time, uint32_t flags)
47+
{
48+
}
49+
50+
void LcdTask::begin(EvseManager &evse, Scheduler &scheduler, ManualOverride &manual)
51+
{
52+
MicroTask.startTask(this);
53+
}
54+
55+
void LcdTask::setup()
56+
{
57+
DBUGLN("LCD UI setup");
58+
59+
//lv_init();
60+
61+
_lcd.begin();
62+
_lcd.setRotation(1);
63+
_lcd.fillScreen(TFT_BLACK);
64+
65+
delay(100);
66+
67+
pinMode(LCD_BACKLIGHT_PIN, OUTPUT);
68+
digitalWrite(LCD_BACKLIGHT_PIN, HIGH);
69+
70+
//size_t bufferSize = _screenWidth * _screenHeight / 13;
71+
//_buf1 = ( lv_color_t * )malloc( bufferSize * sizeof( lv_color_t ) );
72+
//lv_disp_draw_buf_init( &_draw_buf, _buf1, NULL, bufferSize );
73+
//
74+
//static lv_disp_drv_t disp_drv;
75+
//lv_disp_drv_init( &disp_drv );
76+
//
77+
//disp_drv.hor_res = _screenWidth;
78+
//disp_drv.ver_res = _screenHeight;
79+
//disp_drv.flush_cb = displayFlush;
80+
//disp_drv.draw_buf = &_draw_buf;
81+
//lv_disp_drv_register( &disp_drv );
82+
83+
// static lv_indev_drv_t indev_drv;
84+
// lv_indev_drv_init( &indev_drv );
85+
// indev_drv.type = LV_INDEV_TYPE_POINTER;
86+
// indev_drv.read_cb = my_touchpad_read;
87+
// lv_indev_drv_register( &indev_drv );
88+
89+
}
90+
91+
unsigned long LcdTask::loop(MicroTasks::WakeReason reason)
92+
{
93+
DBUG("LCD UI woke: ");
94+
DBUGLN(WakeReason_Scheduled == reason ? "WakeReason_Scheduled" :
95+
WakeReason_Event == reason ? "WakeReason_Event" :
96+
WakeReason_Message == reason ? "WakeReason_Message" :
97+
WakeReason_Manual == reason ? "WakeReason_Manual" :
98+
"UNKNOWN");
99+
100+
unsigned long nextUpdate = MicroTask.Infinate;
101+
102+
//lv_timer_handler();
103+
104+
DBUGVAR(nextUpdate);
105+
return nextUpdate;
106+
}
107+
108+
LcdTask lcd;
109+
110+
#endif // ENABLE_SCREEN_LCD_TFT

src/lcd_tft.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifndef __LCD_TFT_H
2+
#define __LCD_TFT_H
3+
4+
#define LCD_CHAR_STOP 1
5+
#define LCD_CHAR_PLAY 2
6+
#define LCD_CHAR_LIGHTNING 3
7+
#define LCD_CHAR_LOCK 4
8+
#define LCD_CHAR_CLOCK 5
9+
10+
#include "evse_man.h"
11+
#include "scheduler.h"
12+
#include "manual.h"
13+
14+
#include <lvgl.h>
15+
#include <TFT_eSPI.h>
16+
17+
18+
class LcdTask : public MicroTasks::Task
19+
{
20+
private:
21+
TFT_eSPI _lcd;
22+
23+
// The TFT screen is portrate natively, so we need to rotate it
24+
const uint16_t _screenWidth = TFT_HEIGHT;
25+
const uint16_t _screenHeight = TFT_WIDTH;
26+
27+
lv_disp_draw_buf_t _draw_buf;
28+
lv_color_t *_buf1;
29+
30+
static void displayFlush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p);
31+
32+
protected:
33+
void setup();
34+
unsigned long loop(MicroTasks::WakeReason reason);
35+
36+
public:
37+
LcdTask();
38+
39+
void begin(EvseManager &evse, Scheduler &scheduler, ManualOverride &manual);
40+
41+
void display(const __FlashStringHelper *msg, int x, int y, int time, uint32_t flags);
42+
void display(String &msg, int x, int y, int time, uint32_t flags);
43+
void display(const char *msg, int x, int y, int time, uint32_t flags);
44+
};
45+
46+
extern LcdTask lcd;
47+
48+
#endif // __LCD_TFT_H

0 commit comments

Comments
 (0)