Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom (LCD) boot logo. #55

Merged
merged 3 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set(CMAKE_CXX_STANDARD 17)
set(FANPICO_BOARD 0804D CACHE STRING "Fanpico Board Model")
#set_property(CACHE FANPICO_BOARD PROPERTY STRINGS 0804 0803D)
set(FANPICO_CUSTOM_THEME 0 CACHE STRING "Fanpico LCD Custom Theme")
set(FANPICO_CUSTOM_LOGO 0 CACHE STRING "Fanpico LCD Custom Logo")
set(TLS_SUPPORT 0 CACHE STRING "TLS Support")

#set(CMAKE_BUILD_TYPE Debug)
Expand All @@ -26,6 +27,7 @@ message("---------------------------------")
message(" FANPICO_BOARD: ${FANPICO_BOARD}")
message(" PICO_BOARD: ${PICO_BOARD}")
message("FANPICO_CUSTOM_THEME: ${FANPICO_CUSTOM_THEME}")
message(" FANPICO_CUSTOM_LOGO: ${FANPICO_CUSTOM_LOGO}")
message(" CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message("---------------------------------")

Expand Down Expand Up @@ -92,7 +94,7 @@ add_executable(fanpico
src/crc32.c
src/default_config.s
src/credits.s
src/lcd-logo.s
src/logos/default.s
src/themes/lcd-background.s
)

Expand All @@ -102,8 +104,15 @@ if (FANPICO_CUSTOM_THEME)
set_property(SOURCE src/themes/custom.s APPEND PROPERTY COMPILE_OPTIONS -I${CMAKE_CURRENT_LIST_DIR}/src/themes)
endif()

if (FANPICO_CUSTOM_LOGO)
message("Enable custom logo...")
target_sources(fanpico PRIVATE src/logos/custom.s)
set_property(SOURCE src/logos/custom.s APPEND PROPERTY COMPILE_OPTIONS -I${CMAKE_CURRENT_LIST_DIR}/src/logos)
endif()

set_property(SOURCE src/*.s APPEND PROPERTY COMPILE_OPTIONS -I${CMAKE_CURRENT_LIST_DIR}/src)
set_property(SOURCE src/themes/lcd-background.s APPEND PROPERTY COMPILE_OPTIONS -I${CMAKE_CURRENT_LIST_DIR}/src/themes)
set_property(SOURCE src/logos/default.s APPEND PROPERTY COMPILE_OPTIONS -I${CMAKE_CURRENT_LIST_DIR}/src/logos)
set_property(SOURCE src/credits.s APPEND PROPERTY COMPILE_OPTIONS -I${CMAKE_CURRENT_LIST_DIR})

pico_generate_pio_header(fanpico ${CMAKE_CURRENT_LIST_DIR}/src/square_wave_gen.pio)
Expand Down
31 changes: 29 additions & 2 deletions commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ Fanpico supports following commands:
* [SYStem:DISPlay?](#systemdisplay)
* [SYStem:DISPlay:LAYOUTR](#systemdisplaylayoutr)
* [SYStem:DISPlay:LAYOUTR?](#systemdisplaylayoutr-1)
* [SYStem:DISPlay:LOGO](#systemdisplaylogo)
* [SYStem:DISPlay:LOGO?](#systemdisplaylogo-1)
* [SYStem:DISPlay:THEMe](#systemdisplaytheme)
* [SYStem:DISPlay:THEMe?](#systemdisplaytheme-1)
* [SYStem:ECHO](#systemecho)
Expand Down Expand Up @@ -1433,7 +1435,7 @@ display on each row (8 rows available if using 128x64 OLEd module, 10 rows avail

Syntax: <R1>,<R2>,...<R8>

Wehre tow specifications can be one of the following:
Where tow specifications can be one of the following:

Type|Description|Notes
----|-----------|-----
Expand All @@ -1459,7 +1461,7 @@ Example: configure custom theme (for 128x64 display):
SYS:DISP:LAYOUTR M1,M2,-,S1,S2,S3,V1,V2
```

#### SYStem:DISPlay:THEMe?
#### SYStem:DISPlay:LAYOUTR?
Display currently configured (OLED) Display layout for the right side of the screen.

Example:
Expand All @@ -1469,6 +1471,31 @@ M1,M2,-,S1,S2,S3,V1,V2
```


#### SYStem:DISPlay:LOGO
Configure (LCD) Display boot logo.

Currently available logos:

Name|Description
----|-----------
default|Default FanPico boot logo.
custom|Custom boot logo (only available if firmware has been compiled with custom logo included).

Example: configure custom logo
```
SYS:DISP:LOGO custom
```

#### SYStem:DISPlay:LOGO?
Display currently configured (LCD) Display boot logo.

Example:
```
SYS:DISP:LOGO?
default
```


#### SYStem:DISPlay:THEMe
Configure (LCD) Display theme to use.

Expand Down
13 changes: 12 additions & 1 deletion src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,16 @@ int cmd_display_theme(const char *cmd, const char *args, int query, char *prev_c
return 0;
}

int cmd_display_logo(const char *cmd, const char *args, int query, char *prev_cmd)
{
if (query) {
printf("%s\n", conf->display_logo);
} else {
strncopy(conf->display_logo, args, sizeof(conf->display_logo));
}
return 0;
}

int cmd_display_layout_r(const char *cmd, const char *args, int query, char *prev_cmd)
{
if (query) {
Expand Down Expand Up @@ -1998,8 +2008,9 @@ int cmd_spi(const char *cmd, const char *args, int query, char *prev_cmd)


struct cmd_t display_commands[] = {
{ "LAYOUTR", 7, NULL, cmd_display_layout_r },
{ "LOGO", 4, NULL, cmd_display_logo },
{ "THEMe", 4, NULL, cmd_display_theme },
{ "LAYOUTR", 4, NULL, cmd_display_layout_r },
{ 0, 0, 0, 0 }
};
struct cmd_t wifi_commands[] = {
Expand Down
7 changes: 7 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ void clear_config(struct fanpico_config *cfg)
strncopy(cfg->name, "fanpico1", sizeof(cfg->name));
strncopy(cfg->display_type, "default", sizeof(cfg->display_type));
strncopy(cfg->display_theme, "default", sizeof(cfg->display_theme));
strncopy(cfg->display_logo, "default", sizeof(cfg->display_logo));
strncopy(cfg->display_layout_r, "", sizeof(cfg->display_layout_r));
#ifdef WIFI_SUPPORT
cfg->wifi_ssid[0] = 0;
Expand Down Expand Up @@ -466,6 +467,8 @@ cJSON *config_to_json(const struct fanpico_config *cfg)
cJSON_AddItemToObject(config, "display_type", cJSON_CreateString(cfg->display_type));
if (strlen(cfg->display_theme) > 0)
cJSON_AddItemToObject(config, "display_theme", cJSON_CreateString(cfg->display_theme));
if (strlen(cfg->display_logo) > 0)
cJSON_AddItemToObject(config, "display_logo", cJSON_CreateString(cfg->display_logo));
if (strlen(cfg->display_layout_r) > 0)
cJSON_AddItemToObject(config, "display_layout_r", cJSON_CreateString(cfg->display_layout_r));
if (strlen(cfg->name) > 0)
Expand Down Expand Up @@ -647,6 +650,10 @@ int json_to_config(cJSON *config, struct fanpico_config *cfg)
if ((val = cJSON_GetStringValue(ref)))
strncopy(cfg->display_theme, val, sizeof(cfg->display_theme));
}
if ((ref = cJSON_GetObjectItem(config, "display_logo"))) {
if ((val = cJSON_GetStringValue(ref)))
strncopy(cfg->display_logo, val, sizeof(cfg->display_logo));
}
if ((ref = cJSON_GetObjectItem(config, "display_layout_r"))) {
if ((val = cJSON_GetStringValue(ref)))
strncopy(cfg->display_layout_r, val, sizeof(cfg->display_layout_r));
Expand Down
1 change: 1 addition & 0 deletions src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define FANPICO_BOARD "@FANPICO_BOARD@"

#define FANPICO_CUSTOM_THEME @FANPICO_CUSTOM_THEME@
#define FANPICO_CUSTOM_LOGO @FANPICO_CUSTOM_LOGO@

#include "fanpico-compile.h"

Expand Down
50 changes: 40 additions & 10 deletions src/display_lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@
static SPILCD lcd;
static uint8_t lcd_found = 0;

/* Embedded FanPico Logo graphics */
#define LCD_LOGO_WIDTH 160
#define LCD_LOGO_HEIGHT 140
extern uint8_t fanpico_lcd_logo_bmp[];


/* Macros for converting RGB888 colorspace to RGB565 */

Expand Down Expand Up @@ -120,6 +115,14 @@ struct display_theme_entry {
const struct display_theme *theme_normal; /* 480x320 */
};

typedef struct display_logo {
const char *name;
uint16_t width;
uint16_t height;
const uint8_t *bmp;
} display_logo_t;


static uint16_t bg_color = RGB565(0x006163);
static uint16_t text_color = RGB565(0x07a3aa);

Expand All @@ -139,6 +142,20 @@ const struct display_theme_entry themes[] = {
{NULL, NULL, NULL}
};


#include "logos/default.h"
#if FANPICO_CUSTOM_LOGO > 0
#include "logos/custom.h"
#endif

const display_logo_t* logos[] = {
&default_lcd_logo_entry,
#if FANPICO_CUSTOM_LOGO > 0
&custom_lcd_logo_entry,
#endif
NULL
};

const struct display_theme *theme = NULL;


Expand Down Expand Up @@ -345,14 +362,27 @@ void lcd_display_init()
lcd_name,
lcd.iCurrentWidth, lcd.iCurrentHeight);

/* Draw logo screen */

/* Draw logo to screen */
const display_logo_t *logo = logos[0]; /* Default logo */
if (strlen(cfg->display_logo) > 0) {
int idx = 0;
while (logos[idx]) {
if (!strncmp(cfg->display_logo, logos[idx]->name, sizeof(cfg->display_logo))) {
logo = logos[idx];
break;
}
idx++;
}
}

int w_c = lcd.iCurrentWidth / 2;
int h_c = lcd.iCurrentHeight / 2;
spilcdDrawBMP(&lcd, fanpico_lcd_logo_bmp,
w_c - (LCD_LOGO_WIDTH / 2),
h_c - ((LCD_LOGO_HEIGHT + 80) / 2),
spilcdDrawBMP(&lcd, logo->bmp,
w_c - (logo->width / 2),
h_c - ((logo->height + 80) / 2),
0, -1, DRAW_TO_LCD);
h_c += LCD_LOGO_HEIGHT / 2;
h_c += logo->height / 2;
spilcdWriteString(&lcd, w_c - 100, h_c, "FanPico-" FANPICO_MODEL, text_color, 0, FONT_16x16, DRAW_TO_LCD);
spilcdWriteString(&lcd, w_c - 40, h_c + 25, "v" FANPICO_VERSION, text_color, 0, FONT_16x16, DRAW_TO_LCD);
spilcdWriteString(&lcd, w_c - 50, h_c + 55, "Initializing...", text_color, 0, FONT_8x8, DRAW_TO_LCD);
Expand Down
1 change: 1 addition & 0 deletions src/fanpico.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ struct fanpico_config {
uint8_t led_mode;
char display_type[64];
char display_theme[16];
char display_logo[16];
char display_layout_r[64];
char name[32];
bool spi_active;
Expand Down
Binary file removed src/lcd-logo.bmp
Binary file not shown.
31 changes: 31 additions & 0 deletions src/logos/custom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* custom.h
Copyright (C) 2022-2023 Timo Kokkonen <[email protected]>

SPDX-License-Identifier: GPL-3.0-or-later

This file is part of FanPico.

FanPico is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

FanPico is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with FanPico. If not, see <https://www.gnu.org/licenses/>.
*/

extern const uint8_t fanpico_custom_lcd_logo_bmp[]; /* ptr to logo image */

const display_logo_t custom_lcd_logo_entry = {
"custom",
160,
140,
fanpico_custom_lcd_logo_bmp
};


23 changes: 23 additions & 0 deletions src/logos/custom.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# custom.s
# Copyright (C) 2021-2023 Timo Kokkonen <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of FanPico.
#

#
# Stub for embedding lcd-logo-custom.bmp in the executable.
#

.global fanpico_custom_lcd_logo_bmp
.global fanpico_custom_lcd_logo_bmp_end

.section .rodata

.p2align 4
fanpico_custom_lcd_logo_bmp:
.incbin "custom.bmp"
fanpico_custom_lcd_logo_bmp_end:

# eof
Binary file added src/logos/default.bmp
Binary file not shown.
31 changes: 31 additions & 0 deletions src/logos/default.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* default.h
Copyright (C) 2022-2023 Timo Kokkonen <[email protected]>

SPDX-License-Identifier: GPL-3.0-or-later

This file is part of FanPico.

FanPico is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

FanPico is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with FanPico. If not, see <https://www.gnu.org/licenses/>.
*/

extern const uint8_t fanpico_lcd_logo_bmp[]; /* ptr to logo image */

const display_logo_t default_lcd_logo_entry = {
"default",
160,
140,
fanpico_lcd_logo_bmp
};


4 changes: 2 additions & 2 deletions src/lcd-logo.s → src/logos/default.s
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# lcd-logo.s
# default.s
# Copyright (C) 2021-2023 Timo Kokkonen <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later
Expand All @@ -17,7 +17,7 @@

.p2align 4
fanpico_lcd_logo_bmp:
.incbin "lcd-logo.bmp"
.incbin "default.bmp"
fanpico_lcd_logo_bmp_end:

# eof
Loading