diff --git a/docs/lcd_api.md b/docs/lcd_api.md index a5f82da..28f9b8a 100644 --- a/docs/lcd_api.md +++ b/docs/lcd_api.md @@ -104,7 +104,7 @@ void main(void) { #### Drawing text on the screen ```c -void lcd_display_text(const char* text, uint16_t x_pos, uint16_t y_pos, uint32_t color, sFONT *font); +void lcd_display_text(const char* text, uint16_t x_pos, uint16_t y_pos, uint32_t color, uint32_t bg_color, sFONT *font); ``` ```c @@ -116,7 +116,7 @@ void main(void) { ... lcd_init(true); ... - lcd_display_text("This is a text string.", 10, 10, LCD_GREEN, LCD_FONT16); + lcd_display_text("This is a text string.", 10, 10, LCD_GREEN, LCD_BLACK, LCD_FONT16); } ``` Display text on the LCD screen in a certain color. When text width exceeds BSP_LCD_GetXSize(), a text wrap will be performed. If the text wrap is between two will be injected. @@ -279,3 +279,20 @@ void main(void) { ``` Clears all text strings on the LCD screen. + +#### Clearing (background/images) layer 0 to color +```c +void lcd_set_bg_color_layer0(uint32_t color); +``` + +```c +#include "lcd_api.h" + +void main(void) { + ... + lcd_init(true); + lcd_draw_img_from_fs("st.bmp", 300, 100); + ... + lcd_set_bg_color_layer0(LCD_BLACK); +} +``` diff --git a/project/Core/Inc/lcd_api.h b/project/Core/Inc/lcd_api.h index c3ee770..cdc2f7d 100644 --- a/project/Core/Inc/lcd_api.h +++ b/project/Core/Inc/lcd_api.h @@ -96,13 +96,16 @@ void lcd_task(void); * a text wrap will be performed. If the text wrap is between two letters in a word, the '-' character * will be injected. * + * @note When bg_color 0 is passed as a parameter, the background for the text will be transparent + * * @param[in] text C-style text string to display on the LCD screen * @param[in] x_pos X-position * @param[in] y_pos Y-position * @param[in] color Color in which the text will be displayed, see preset colors in defines above + * @param[in] bg_color Text background color * @param[in] font Font size, see defines above in file */ -void lcd_display_text(const char* text, uint16_t x_pos, uint16_t y_pos, uint32_t color, sFONT *font); +void lcd_display_text(const char* text, uint16_t x_pos, uint16_t y_pos, uint32_t color, uint32_t bg_color, sFONT *font); /** * @brief Draw BMP image on screen @@ -156,6 +159,14 @@ void lcd_clear_text(void); */ void lcd_clear_images(void); +/** + * @brief Set background color of layer 0 + * Sets the layer 0 color + * + * @param[in] color Color of layer 0 (images layer) + */ +void lcd_set_bg_color_layer0(uint32_t color); + /** * @brief LCD stop all GIFs * Stops all playing GIFs on lcd screen diff --git a/project/Core/Src/lcd_api.c b/project/Core/Src/lcd_api.c index 2c0738e..59a8a5e 100644 --- a/project/Core/Src/lcd_api.c +++ b/project/Core/Src/lcd_api.c @@ -84,7 +84,7 @@ void lcd_task(void) { } } -void lcd_display_text(const char* text, uint16_t x_pos, uint16_t y_pos, uint32_t color, sFONT* font) { +void lcd_display_text(const char* text, uint16_t x_pos, uint16_t y_pos, uint32_t color, uint32_t bg_color, sFONT* font) { BSP_LCD_SelectLayer(1); LOG_INFO(TAG, "Display text: %s @x=%d,y=%d", text, x_pos, y_pos); @@ -94,7 +94,7 @@ void lcd_display_text(const char* text, uint16_t x_pos, uint16_t y_pos, uint32_t } BSP_LCD_SetTextColor(color); - BSP_LCD_SetBackColor(0); + BSP_LCD_SetBackColor(bg_color); BSP_LCD_SetFont(font); if (tot_length > BSP_LCD_GetXSize()) { @@ -186,6 +186,11 @@ void lcd_clear_images(void) { BSP_LCD_Clear(0); } +void lcd_set_bg_color_layer0(uint32_t color){ + BSP_LCD_SelectLayer(0); + BSP_LCD_Clear(color); +} + void lcd_stop_all_gifs(void) { for (uint8_t i = 0; i < LCD_MAX_GIFS; i++) { if (gifs[i].src != NULL) { diff --git a/project/Core/Src/tftp.c b/project/Core/Src/tftp.c index ac04312..e1d8f53 100644 --- a/project/Core/Src/tftp.c +++ b/project/Core/Src/tftp.c @@ -167,7 +167,7 @@ void tftp_close(void* handle) { if (handle == &virt_file[VIRT_TEXT_TXT]) { lcd_clear_images(); lcd_clear_text(); - lcd_display_text((uint8_t*)virt_file[VIRT_TEXT_TXT].data, 0, 0, LCD_COLOR_WHITE, LCD_FONT16); + lcd_display_text((uint8_t*)virt_file[VIRT_TEXT_TXT].data, 0, 0, LCD_COLOR_WHITE, LCD_TRANSPARENT, LCD_FONT16); } if (handle == &virt_file[VIRT_INDEX_TXT] || handle == &virt_file[VIRT_IMAGE_BMP] @@ -321,4 +321,4 @@ void tftp_server_deinit(void) { virt_file[VIRT_TEXT_TXT].data = NULL; virt_file[VIRT_TEXT_TXT].len = 0; -} \ No newline at end of file +}