Skip to content

Commit

Permalink
Merge pull request #745 from OpenEVSE/elecrow_esp32_hmi
Browse files Browse the repository at this point in the history
OpenEVSE TFT LCD HMI support and initial TFT display POC
  • Loading branch information
chris1howell authored Feb 23, 2024
2 parents 0a01cc3 + fd44f89 commit d92677f
Show file tree
Hide file tree
Showing 44 changed files with 5,096 additions and 64 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ jobs:
- heltec_esp32-wifi-lora-v2
- wt32-eth01
- esp32-c3-devkitc-02
- elecrow_esp32_hmi
- elecrow_esp32_hmi_dev
- openevse_wifi_tft_v1
- openevse_wifi_tft_v1_dev
gui:
- name: gui-v2
repo: OpenEVSE/openevse-gui-v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,4 @@ lib/MicroTasks
*.bin
divert_sim/epoxyfsdata
divert_sim/epoxyeepromdata
*.pem
Binary file added BootScreen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ChargeScreen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui-tft/button_bar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui-tft/car_connected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui-tft/car_disconnected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui-tft/charging.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui-tft/connected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui-tft/disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui-tft/error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui-tft/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui-tft/not_connected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui-tft/sleeping.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui-tft/start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion gui-v2
7 changes: 7 additions & 0 deletions openevse_16mb.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x640000,
app1, app, ota_1, 0x650000,0x640000,
spiffs, data, spiffs, 0xc90000,0x360000,
coredump, data, coredump,0xFF0000,0x10000,
100 changes: 100 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ debug_flags =
#-D ENABLE_NOISY_PROFILE
#-D ENABLE_DEBUG_MICROTASKS
#-D ENABLE_DEBUG_ENERGY_METER
#-D ENABLE_DEBUG_MEMORY_MONITOR
src_build_flags =
# -D ARDUINOJSON_USE_LONG_LONG
# -D ENABLE_ASYNC_WIFI_SCAN
Expand Down Expand Up @@ -99,11 +100,60 @@ build_flags =
-D USE_ESP32
-D USE_ESP32_FRAMEWORK_ARDUINO
-D MG_MAX_HTTP_REQUEST_SIZE=8196
build_flags_openevse_tft =
${common.build_flags}
${common.src_build_flags}
${common.gfx_display_build_flags}
-D NEO_PIXEL_PIN=26
-D NEO_PIXEL_LENGTH=14
-D WIFI_PIXEL_NUMBER=1
-D WIFI_BUTTON=0
-D WIFI_BUTTON_PRESSED_STATE=LOW
build_partitions = min_spiffs.csv
build_partitions_debug = min_spiffs_debug.csv
build_partitions_16mb = openevse_16mb.csv

neopixel_lib = adafruit/Adafruit [email protected]

gfx_display_libs =
# lvgl/[email protected]
bodmer/TFT_eSPI@^2.5.31
bitbank2/PNGdec@^1.0.1
SPI

gfx_display_build_flags =
# -D LV_CONF_INCLUDE_SIMPLE
# -D LV_CONF_SUPPRESS_DEFINE_CHECK
-D USER_SETUP_LOADED
-D ILI9488_DRIVER
-D TFT_WIDTH=320
-D TFT_HEIGHT=480
-D TFT_BL=27
-D TFT_MISO=12
-D TFT_MOSI=13
-D TFT_SCLK=14
-D TFT_CS=15
-D TFT_DC=2
-D TFT_RST=-1
-D TOUCH_CS=33
# -D LOAD_GLCD
# -D LOAD_FONT2
# -D LOAD_FONT4
# -D LOAD_FONT6
# -D LOAD_FONT7
# -D LOAD_FONT8
-D LOAD_GFXFF
# -D SMOOTH_FONT
# -D SPI_FREQUENCY=15999999
# -D SPI_FREQUENCY=20000000
# -D SPI_FREQUENCY=27000000
-D SPI_FREQUENCY=40000000
# -D SPI_FREQUENCY=55000000
# -D SPI_FREQUENCY=65000000
# -D SPI_FREQUENCY=80000000
-D SPI_READ_FREQUENCY=20000000
-D SPI_TOUCH_FREQUENCY=600000
-D ENABLE_SCREEN_LCD_TFT

[env]
# specify exact Arduino ESP SDK version, requires platformio 3.5+ (curently dev version)
Expand Down Expand Up @@ -358,3 +408,53 @@ build_flags =
-D NEO_PIXEL_PIN=8
-D NEO_PIXEL_LENGTH=1
-D WIFI_PIXEL_NUMBER=1

[env:elecrow_esp32_hmi]
board = denky32
build_flags =
${common.build_flags}
${common.src_build_flags}
-D DEBUG_PORT=Serial
-D RAPI_PORT=Serial1
-D RX1=16
-D TX1=17
lib_deps =
${common.lib_deps}
${common.gfx_display_libs}

[env:elecrow_esp32_hmi_dev]
extends = env:elecrow_esp32_hmi
build_flags =
${env:elecrow_esp32_hmi.build_flags}
${common.debug_flags}
${common.gfx_display_build_flags}
upload_protocol = custom
upload_command = curl -F firmware=@$SOURCE http://$UPLOAD_PORT/update
#build_type = debug
#board_build.partitions = ${common.build_partitions_debug}

[env:openevse_wifi_tft_v1]
board = denky32
build_flags =
${common.build_flags_openevse_tft}
-D DEBUG_PORT=Serial2
-D RAPI_PORT=Serial
lib_deps =
${common.lib_deps}
${common.gfx_display_libs}
${common.neopixel_lib}
board_build.partitions = ${common.build_partitions_16mb}
board_upload.flash_size = 16MB
board_build.flash_mode = qio
board_build.f_flash = 80000000L

[env:openevse_wifi_tft_v1_dev]
extends = env:openevse_wifi_tft_v1
build_flags =
${common.build_flags_openevse_tft}
${common.debug_flags}
-D DEBUG_PORT=Serial
-D RAPI_PORT=Serial2
#upload_protocol = custom
#upload_command = curl -F firmware=@$SOURCE http://$UPLOAD_PORT/update
build_type = debug
35 changes: 23 additions & 12 deletions scripts/extra_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,26 @@ def make_safe(file):
for c in chars:
if c in file:
file = file.replace(c, "_")

return file

def make_static(env, target, source):
def make_static_web(env, target, source):
return make_static(env, target, source, "web_server", dist_dir)

def make_static_lcd(env, target, source):
return make_static(env, target, source, "lcd_gui", lcd_gui_dir)

def make_static(env, target, source, prefix, files_dir):
output = ""

out_files = filtered_listdir(dist_dir)
out_files = filtered_listdir(files_dir)

# include the files
for out_file in out_files:
filename = "web_server."+make_safe(out_file)+".h"
filename = prefix+"."+make_safe(out_file)+".h"
output += "#include \"{}\"\n".format(filename)

output += "StaticFile staticFiles[] = {\n"
output += "StaticFile "+prefix+"_static_files[] = {\n"

for out_file in out_files:
filetype = None
Expand Down Expand Up @@ -156,19 +162,19 @@ def make_static(env, target, source):
with open(target_file, "w") as output_file:
output_file.write(output)

def process_html_app(source, dest, env):
web_server_static_files = join(dest, "web_server_static_files.h")
web_server_static = join(env.subst("$BUILD_DIR"), "src/web_server_static.cpp.o")
def process_html_app(source, dest, env, prefix, static_func):
web_server_static_files = join(dest, prefix+"_static_files.h")
web_server_static = join(env.subst("$BUILD_DIR"), "src/"+prefix+"_static.cpp.o")

files = filtered_listdir(source)

for file in files:
data_file = join(source, file)
header_file = join(dest, "web_server."+make_safe(file)+".h")
header_file = join(dest, prefix+"."+make_safe(file)+".h")
env.Command(header_file, data_file, data_to_header)
env.Depends(web_server_static_files, header_file)

env.Depends(web_server_static, env.Command(web_server_static_files, source, make_static))
env.Depends(web_server_static, env.Command(web_server_static_files, source, static_func))

#
# Generate Web app resources
Expand All @@ -177,7 +183,7 @@ def process_html_app(source, dest, env):
headers_src = join(env.subst("$PROJECTSRC_DIR"), "web_static")

gui_name = environ.get("GUI_NAME")
if gui_name in (None, ""):
if gui_name in (None, ""):
gui_name = "gui-v2"

gui_dir = join(env.subst("$PROJECT_DIR"), gui_name)
Expand All @@ -189,7 +195,7 @@ def process_html_app(source, dest, env):
# Check to see if the Node modules have been downloaded
if(isdir(node_modules)):
if(isdir(dist_dir)):
process_html_app(dist_dir, headers_src, env)
process_html_app(dist_dir, headers_src, env, "web_server", make_static_web)
else:
print("Warning: GUI not built, run 'cd %s; npm run build'" % (gui_dir))
else:
Expand All @@ -199,4 +205,9 @@ def process_html_app(source, dest, env):
else:
print("Warning: Node.JS and NPM required to update the UI")

# LCD GUI files
lcd_gui_dir = join(env.subst("$PROJECT_DIR"), "gui-tft")
headers_src = join(env.subst("$PROJECTSRC_DIR"), "lcd_static")
process_html_app(lcd_gui_dir, headers_src, env, "lcd_gui", make_static_lcd)

print("PATH="+env['ENV']['PATH'])
26 changes: 26 additions & 0 deletions src/embedded_files.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#if defined(ENABLE_DEBUG) && !defined(ENABLE_DEBUG_EMBEDDED_FILES)
#undef ENABLE_DEBUG
#endif

#include "embedded_files.h"
#include "emonesp.h"

bool embedded_get_file(String filename, StaticFile *index, size_t length, StaticFile **file)
{
DBUGF("Looking for %s", filename.c_str());

for(int i = 0; i < length; i++)
{
if(filename == index[i].filename)
{
DBUGF("Found %s %d@%p", index[i].filename, index[i].length, index[i].data);

if(file) {
*file = &index[i];
}
return true;
}
}

return false;
}
22 changes: 22 additions & 0 deletions src/embedded_files.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef EMBEDDED_FILES_H
#define EMBEDDED_FILES_H

#include <Arduino.h>

#define ARRAY_LENGTH(x) (sizeof(x)/sizeof((x)[0]))

#define IS_ALIGNED(x) (0 == ((uint32_t)(x) & 0x3))

struct StaticFile
{
const char *filename;
const char *data;
size_t length;
const char *type;
const char *etag;
bool compressed;
};

bool embedded_get_file(String filename, StaticFile *index, size_t length, StaticFile **file);

#endif // EMBEDDED_FILES_H
4 changes: 4 additions & 0 deletions src/lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#undef ENABLE_DEBUG
#endif

#ifndef ENABLE_SCREEN_LCD_TFT

#include "emonesp.h"
#include "lcd.h"
#include "RapiSender.h"
Expand Down Expand Up @@ -734,3 +736,5 @@ void LcdTask::onButton(int long_press)
}

LcdTask lcd;

#endif // ENABLE_SCREEN_LCD_TFT
12 changes: 10 additions & 2 deletions src/lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
#define LCD_CLEAR_LINE (1 << 0)
#define LCD_DISPLAY_NOW (1 << 1)

#define LCD_MAX_LEN 16

#ifndef LCD_DISPLAY_CHANGE_TIME
#define LCD_DISPLAY_CHANGE_TIME (4 * 1000)
#endif

#if ENABLE_SCREEN_LCD_TFT
// HACK: This should be done in a much more C++ way
#include "lcd_tft.h"
#else

#define LCD_MAX_LEN 16

#define LCD_CHAR_STOP 1
#define LCD_CHAR_PLAY 2
#define LCD_CHAR_LIGHTNING 3
Expand Down Expand Up @@ -151,6 +156,9 @@ class LcdTask : public MicroTasks::Task
void display(const char *msg, int x, int y, int time, uint32_t flags);
};

#endif // ENABLE_SCREEN_LCD_TFT

extern LcdTask lcd;

#endif // __LCD_H

Loading

0 comments on commit d92677f

Please sign in to comment.