firmware: Add background image
This commit is contained in:
parent
8bdd1c018f
commit
b6f242a73a
1
firmware/.gitignore
vendored
1
firmware/.gitignore
vendored
@ -4,3 +4,4 @@ sdkconfig
|
|||||||
sdkconfig.old
|
sdkconfig.old
|
||||||
*.swp
|
*.swp
|
||||||
/main/font/*.c
|
/main/font/*.c
|
||||||
|
/main/img/*.c
|
||||||
|
BIN
firmware/assets/bg.png
Normal file
BIN
firmware/assets/bg.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 27 KiB |
@ -1,10 +1,52 @@
|
|||||||
{
|
{
|
||||||
perSystem = { libMy, pkgs, ... }: {
|
perSystem = { libMy, pkgs, ... }:
|
||||||
|
let
|
||||||
|
genImgsPy = pkgs.python3.withPackages (ps: with ps; [ pillow ]);
|
||||||
|
genImgs = pkgs.writeScriptBin "gen-imgs" ''
|
||||||
|
#!${genImgsPy}/bin/python
|
||||||
|
import itertools
|
||||||
|
import os
|
||||||
|
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
imgs = ['bg.png']
|
||||||
|
for fname in imgs:
|
||||||
|
with Image.open(os.path.join('assets/', fname)) as img:
|
||||||
|
w = img.width
|
||||||
|
h = img.height
|
||||||
|
|
||||||
|
data = [(r >> 3) << 11 | (g >> 2) << 5 | (b >> 3) for r, g, b in img.getdata()]
|
||||||
|
|
||||||
|
basename = os.path.splitext(fname)[0]
|
||||||
|
with open(os.path.join('main/img/', basename + '.c'), 'w') as f:
|
||||||
|
f.write(
|
||||||
|
'#include <inttypes.h>\n\n'
|
||||||
|
'#include "lvgl.h"\n\n'
|
||||||
|
'static const uint16_t _data[] = {\n')
|
||||||
|
|
||||||
|
for group in itertools.batched(data, 20):
|
||||||
|
f.write(' ' + ' '.join(map(lambda i: f'{i:#x},', group)) + '\n')
|
||||||
|
|
||||||
|
f.write('};\n\n')
|
||||||
|
|
||||||
|
f.write(
|
||||||
|
f'const lv_image_dsc_t ui_img_{basename} = {{\n'
|
||||||
|
' .header.magic = LV_IMAGE_HEADER_MAGIC,\n'
|
||||||
|
' .header.cf = LV_COLOR_FORMAT_RGB565,\n'
|
||||||
|
f' .header.w = {w},\n'
|
||||||
|
f' .header.h = {h},\n'
|
||||||
|
' .data_size = sizeof(_data) * 2,\n'
|
||||||
|
' .data = (const uint8_t *)_data,\n'
|
||||||
|
'};\n')
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
{
|
||||||
devenv.shells.firmware = libMy.withRootdir {
|
devenv.shells.firmware = libMy.withRootdir {
|
||||||
packages = with pkgs; [
|
packages = with pkgs; [
|
||||||
esp-idf-esp32s3
|
esp-idf-esp32s3
|
||||||
picocom
|
picocom
|
||||||
lv_font_conv
|
lv_font_conv
|
||||||
|
genImgs
|
||||||
];
|
];
|
||||||
|
|
||||||
env = {
|
env = {
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
idf_component_register(
|
idf_component_register(
|
||||||
SRCS "valconomy.c" "ui.c" "lcd.c" "usb.c" "font/tungsten_120.c"
|
SRCS "valconomy.c" "ui.c" "lcd.c" "usb.c" "font/tungsten_120.c" "img/bg.c"
|
||||||
INCLUDE_DIRS ".")
|
INCLUDE_DIRS ".")
|
||||||
|
0
firmware/main/img/.gitkeep
Normal file
0
firmware/main/img/.gitkeep
Normal file
@ -2,7 +2,12 @@
|
|||||||
|
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
|
||||||
static const lv_font_t *font_normal = &lv_font_montserrat_14;
|
static const lv_font_t *font_normal = &lv_font_montserrat_24;
|
||||||
|
|
||||||
|
static lv_color_t color_primary, color_secondary;
|
||||||
|
static lv_color_t color_text_hero;
|
||||||
|
|
||||||
|
static lv_style_t s_hero;
|
||||||
|
|
||||||
static void b_cfg_cb(lv_event_t *e) {
|
static void b_cfg_cb(lv_event_t *e) {
|
||||||
lv_obj_t *box = lv_msgbox_create(NULL);
|
lv_obj_t *box = lv_msgbox_create(NULL);
|
||||||
@ -12,8 +17,11 @@ static void b_cfg_cb(lv_event_t *e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void ui_home() {
|
static void ui_home() {
|
||||||
|
lv_obj_t *i_bg = lv_image_create(lv_screen_active());
|
||||||
|
lv_image_set_src(i_bg, &ui_img_bg);
|
||||||
|
|
||||||
lv_obj_t *l_test = lv_label_create(lv_screen_active());
|
lv_obj_t *l_test = lv_label_create(lv_screen_active());
|
||||||
lv_obj_set_style_text_font(l_test, &lv_font_tungsten_120, 0);
|
lv_obj_add_style(l_test, &s_hero, 0);
|
||||||
lv_label_set_text(l_test, "VAL TIME");
|
lv_label_set_text(l_test, "VAL TIME");
|
||||||
|
|
||||||
lv_obj_t *b_cfg = lv_button_create(lv_screen_active());
|
lv_obj_t *b_cfg = lv_button_create(lv_screen_active());
|
||||||
@ -26,12 +34,21 @@ static void ui_home() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void val_lvgl_ui(lv_display_t *disp) {
|
void val_lvgl_ui(lv_display_t *disp) {
|
||||||
|
color_primary = lv_color_hex(0xff4655);
|
||||||
|
color_secondary = lv_color_hex(0xf7518f);
|
||||||
|
|
||||||
|
color_text_hero = lv_palette_lighten(LV_PALETTE_GREY, 2);
|
||||||
|
|
||||||
// init default theme
|
// init default theme
|
||||||
lv_theme_default_init(
|
lv_theme_default_init(
|
||||||
disp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED),
|
disp, color_primary, color_secondary,
|
||||||
true, // dark theme
|
true, // dark theme
|
||||||
font_normal);
|
font_normal);
|
||||||
// lv_sysmon_hide_performance(disp);
|
// lv_sysmon_hide_performance(disp);
|
||||||
|
|
||||||
|
lv_style_init(&s_hero);
|
||||||
|
lv_style_set_text_font(&s_hero, &lv_font_tungsten_120);
|
||||||
|
lv_style_set_text_color(&s_hero, color_text_hero);
|
||||||
|
|
||||||
ui_home();
|
ui_home();
|
||||||
}
|
}
|
||||||
|
@ -4,4 +4,6 @@
|
|||||||
|
|
||||||
LV_FONT_DECLARE(lv_font_tungsten_120)
|
LV_FONT_DECLARE(lv_font_tungsten_120)
|
||||||
|
|
||||||
|
LV_IMAGE_DECLARE(ui_img_bg);
|
||||||
|
|
||||||
void val_lvgl_ui(lv_display_t *disp);
|
void val_lvgl_ui(lv_display_t *disp);
|
||||||
|
5
firmware/partitions.csv
Normal file
5
firmware/partitions.csv
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# ESP-IDF Partition Table
|
||||||
|
# Name, Type, SubType, Offset, Size, Flags
|
||||||
|
nvs,data,nvs,0x9000,24K,
|
||||||
|
phy_init,data,phy,0xf000,4K,
|
||||||
|
factory,app,factory,0x10000,4M,
|
|
@ -6,6 +6,7 @@ CONFIG_ESPTOOLPY_FLASH_MODE_AUTO_DETECT=n
|
|||||||
CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
|
CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
|
||||||
CONFIG_ESPTOOLPY_FLASHFREQ_120M=y
|
CONFIG_ESPTOOLPY_FLASHFREQ_120M=y
|
||||||
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
|
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
|
||||||
|
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||||
CONFIG_USJ_ENABLE_USB_SERIAL_JTAG=n
|
CONFIG_USJ_ENABLE_USB_SERIAL_JTAG=n
|
||||||
CONFIG_SPIRAM=y
|
CONFIG_SPIRAM=y
|
||||||
CONFIG_SPIRAM_MODE_OCT=y
|
CONFIG_SPIRAM_MODE_OCT=y
|
||||||
@ -22,6 +23,7 @@ CONFIG_TINYUSB_HID_COUNT=1
|
|||||||
CONFIG_LV_DEF_REFR_PERIOD=24
|
CONFIG_LV_DEF_REFR_PERIOD=24
|
||||||
CONFIG_LV_USE_LOG=y
|
CONFIG_LV_USE_LOG=y
|
||||||
CONFIG_LV_LOG_PRINTF=y
|
CONFIG_LV_LOG_PRINTF=y
|
||||||
|
CONFIG_LV_FONT_MONTSERRAT_24=y
|
||||||
CONFIG_LV_USE_SYSMON=y
|
CONFIG_LV_USE_SYSMON=y
|
||||||
CONFIG_LV_USE_PERF_MONITOR=y
|
CONFIG_LV_USE_PERF_MONITOR=y
|
||||||
CONFIG_IDF_EXPERIMENTAL_FEATURES=y
|
CONFIG_IDF_EXPERIMENTAL_FEATURES=y
|
||||||
|
Loading…
Reference in New Issue
Block a user