From 60350842cf6ae011cf8682e13d58fa143a8bc601 Mon Sep 17 00:00:00 2001 From: xoreo Date: Mon, 13 Nov 2023 17:05:12 +0100 Subject: [PATCH 01/14] Rename function lcd_draw_bmp to lcd_draw_raw_img --- project/Core/Inc/lcd_api.h | 2 +- project/Core/Src/lcd_api.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/project/Core/Inc/lcd_api.h b/project/Core/Inc/lcd_api.h index dee9190..4f20d68 100644 --- a/project/Core/Inc/lcd_api.h +++ b/project/Core/Inc/lcd_api.h @@ -93,7 +93,7 @@ void lcd_display_text(uint8_t* text, uint16_t x_pos, uint16_t y_pos, uint32_t co * @param[in] y_size Height of image * @param[in] color_mode Color mode (see defined color modes above in file) */ -void lcd_draw_bmp(const void* p_src, uint32_t x_pos, uint32_t y_pos, uint32_t x_size, uint32_t y_size, uint32_t color_mode); +void lcd_draw_raw_img(const void* p_src, uint32_t x_pos, uint32_t y_pos, uint32_t x_size, uint32_t y_size, uint32_t color_mode); /** * @brief Clear LCD screen diff --git a/project/Core/Src/lcd_api.c b/project/Core/Src/lcd_api.c index 9e3c264..57b3e66 100644 --- a/project/Core/Src/lcd_api.c +++ b/project/Core/Src/lcd_api.c @@ -61,7 +61,7 @@ void lcd_display_text(uint8_t* text, uint16_t x_pos, uint16_t y_pos, uint32_t co } -void lcd_draw_bmp(const void* p_src, uint32_t x_pos, uint32_t y_pos, uint32_t x_size, uint32_t y_size, uint32_t color_mode) { +void lcd_draw_raw_img(const void* p_src, uint32_t x_pos, uint32_t y_pos, uint32_t x_size, uint32_t y_size, uint32_t color_mode) { uint32_t address = hLtdcHandler.LayerCfg[1].FBStartAdress + (((BSP_LCD_GetXSize()*y_pos) + x_pos)*(4)); void *p_dst = (void *)address; From e56bd84cb89c86deab1c8a145eea8749a15c8fee Mon Sep 17 00:00:00 2001 From: xoreo Date: Mon, 13 Nov 2023 17:17:15 +0100 Subject: [PATCH 02/14] Add draw BMP function (lcd_draw_bmp_img) --- project/Core/Inc/lcd_api.h | 13 ++++++ project/Core/Src/lcd_api.c | 4 ++ project/project Debug.launch | 80 ------------------------------------ 3 files changed, 17 insertions(+), 80 deletions(-) delete mode 100644 project/project Debug.launch diff --git a/project/Core/Inc/lcd_api.h b/project/Core/Inc/lcd_api.h index 4f20d68..7fe30c0 100644 --- a/project/Core/Inc/lcd_api.h +++ b/project/Core/Inc/lcd_api.h @@ -13,6 +13,7 @@ #define LOGGER_LEVEL_ALL #include "log.h" #include "../../Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_lcd.h" +#include "llfs.h" #define LCD_BLUE LCD_COLOR_BLUE #define LCD_GREEN LCD_COLOR_GREEN @@ -95,6 +96,18 @@ void lcd_display_text(uint8_t* text, uint16_t x_pos, uint16_t y_pos, uint32_t co */ void lcd_draw_raw_img(const void* p_src, uint32_t x_pos, uint32_t y_pos, uint32_t x_size, uint32_t y_size, uint32_t color_mode); +/** + * @brief Draw BMP image on screen + * Draw BMP image from C array to the LCD screen at position X, Y. In color mode ARGB8888, RGB888, RGB565 or ARGB1555 + * Supports ARGB8888, RGB565, RGB888 + * + * @param[in] x_pos X-position + * @param[in] y_pos Y-position + * @param[in] BMP file data + */ +void lcd_draw_bmp_img(uint32_t x_pos, uint32_t y_pos, uint8_t* bmp_buff); + + /** * @brief Clear LCD screen * Clears the whole LCD screen to the desired color diff --git a/project/Core/Src/lcd_api.c b/project/Core/Src/lcd_api.c index 57b3e66..a632cc0 100644 --- a/project/Core/Src/lcd_api.c +++ b/project/Core/Src/lcd_api.c @@ -96,6 +96,10 @@ void lcd_draw_raw_img(const void* p_src, uint32_t x_pos, uint32_t y_pos, uint32_ HAL_DMA2D_PollForTransfer(&hDma2dHandler2, 10); } +void lcd_draw_bmp_img(uint32_t x_pos, uint32_t y_pos, uint8_t* bmp_buff){ + BSP_LCD_DrawBitmap(x_pos, y_pos, bmp_buff); +} + void lcd_clear(uint32_t color){ BSP_LCD_Clear(color); } diff --git a/project/project Debug.launch b/project/project Debug.launch deleted file mode 100644 index ccaf85d..0000000 --- a/project/project Debug.launch +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 91a1fc38f899a9f1d63f3311dca3f37db43306a5 Mon Sep 17 00:00:00 2001 From: Sander Speetjens Date: Mon, 13 Nov 2023 17:24:57 +0100 Subject: [PATCH 03/14] lcd_api follow style guide --- project/Core/Src/lcd_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/Core/Src/lcd_api.c b/project/Core/Src/lcd_api.c index 9e3c264..431a79f 100644 --- a/project/Core/Src/lcd_api.c +++ b/project/Core/Src/lcd_api.c @@ -96,6 +96,6 @@ void lcd_draw_bmp(const void* p_src, uint32_t x_pos, uint32_t y_pos, uint32_t x_ HAL_DMA2D_PollForTransfer(&hDma2dHandler2, 10); } -void lcd_clear(uint32_t color){ +void lcd_clear(uint32_t color) { BSP_LCD_Clear(color); } From 35871d9eaeb582a83dd801c39494c3ebc565d77d Mon Sep 17 00:00:00 2001 From: xoreo Date: Mon, 13 Nov 2023 17:45:28 +0100 Subject: [PATCH 04/14] Implement lcd_draw_img_from_fs_with_name --- project/Core/Inc/lcd_api.h | 12 +++++++++++- project/Core/Src/lcd_api.c | 11 ++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/project/Core/Inc/lcd_api.h b/project/Core/Inc/lcd_api.h index 7fe30c0..77a297f 100644 --- a/project/Core/Inc/lcd_api.h +++ b/project/Core/Inc/lcd_api.h @@ -105,8 +105,18 @@ void lcd_draw_raw_img(const void* p_src, uint32_t x_pos, uint32_t y_pos, uint32_ * @param[in] y_pos Y-position * @param[in] BMP file data */ -void lcd_draw_bmp_img(uint32_t x_pos, uint32_t y_pos, uint8_t* bmp_buff); +void lcd_draw_bmp_img(uint8_t* bmp_buff, uint32_t x_pos, uint32_t y_pos); +/** + * @brief Draw BMP image on screen by specifying the name, the BMP image has in the file system + * Draw BMP image from C array to the LCD screen at position X, Y by specifying the BMP image name on the filesystem + * Supports ARGB8888, RGB565, RGB888 + * + * @param[in] x_pos X-position + * @param[in] y_pos Y-position + * @param[in] BMP file data + */ +void lcd_draw_img_from_fs_with_name(const char* name, uint32_t x_pos, uint32_t y_pos); /** * @brief Clear LCD screen diff --git a/project/Core/Src/lcd_api.c b/project/Core/Src/lcd_api.c index a632cc0..18636a7 100644 --- a/project/Core/Src/lcd_api.c +++ b/project/Core/Src/lcd_api.c @@ -96,10 +96,19 @@ void lcd_draw_raw_img(const void* p_src, uint32_t x_pos, uint32_t y_pos, uint32_ HAL_DMA2D_PollForTransfer(&hDma2dHandler2, 10); } -void lcd_draw_bmp_img(uint32_t x_pos, uint32_t y_pos, uint8_t* bmp_buff){ +void lcd_draw_bmp_img(uint8_t* bmp_buff, uint32_t x_pos, uint32_t y_pos){ BSP_LCD_DrawBitmap(x_pos, y_pos, bmp_buff); } +void lcd_draw_img_from_fs_with_name(const char* name, uint32_t x_pos, uint32_t y_pos){ + llfs_file_t* file = llfs_file_open(name); + if (file != NULL) { + BSP_LCD_DrawBitmap(x_pos, y_pos, file->data); + } else { + LOG_WARN(TAG, "File \"%s\" not found", file->name); + } +} + void lcd_clear(uint32_t color){ BSP_LCD_Clear(color); } From e8d941b2dfabf23985c4448de4c8acff5acdbeff Mon Sep 17 00:00:00 2001 From: Sander Speetjens Date: Mon, 13 Nov 2023 18:09:32 +0100 Subject: [PATCH 05/14] Format code in lcd_api --- project/Core/Src/lcd_api.c | 40 ++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/project/Core/Src/lcd_api.c b/project/Core/Src/lcd_api.c index b0fcaf1..740e0c7 100644 --- a/project/Core/Src/lcd_api.c +++ b/project/Core/Src/lcd_api.c @@ -15,7 +15,7 @@ void lcd_init(bool bl_on) { BSP_LCD_Init(); BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS); - BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS + (BSP_LCD_GetXSize()*BSP_LCD_GetYSize()*4)); + BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS + (BSP_LCD_GetXSize() * BSP_LCD_GetYSize() * 4)); BSP_LCD_SelectLayer(0); BSP_LCD_Clear(LCD_COLOR_BLACK); BSP_LCD_SelectLayer(1); @@ -24,12 +24,12 @@ void lcd_init(bool bl_on) { HAL_GPIO_WritePin(GPIOK, GPIO_PIN_3, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOI, GPIO_PIN_12, GPIO_PIN_SET); } else { - HAL_GPIO_WritePin(GPIOK, GPIO_PIN_3, GPIO_PIN_RESET); - HAL_GPIO_WritePin(GPIOI, GPIO_PIN_12, GPIO_PIN_RESET); + HAL_GPIO_WritePin(GPIOK, GPIO_PIN_3, GPIO_PIN_RESET); + HAL_GPIO_WritePin(GPIOI, GPIO_PIN_12, GPIO_PIN_RESET); } } -void lcd_display_text(uint8_t* text, uint16_t x_pos, uint16_t y_pos, uint32_t color, uint32_t bg_color, sFONT *font) { +void lcd_display_text(uint8_t* text, uint16_t x_pos, uint16_t y_pos, uint32_t color, uint32_t bg_color, sFONT* font) { LOG_INFO(TAG, "Display text: %s @x=%d,y=%d", text, x_pos, y_pos); uint16_t tot_length = x_pos + (strlen(text) * font->Width); @@ -43,8 +43,8 @@ void lcd_display_text(uint8_t* text, uint16_t x_pos, uint16_t y_pos, uint32_t co if (tot_length > BSP_LCD_GetXSize()) { for (int i = 0; i < strlen(text); i++) { - if ((x_pos) > BSP_LCD_GetXSize() - (font->Width)*2) { - if (isalpha(text[i-1]) && isalpha(text[i])) { + if ((x_pos) > BSP_LCD_GetXSize() - (font->Width) * 2) { + if (isalpha(text[i - 1]) && isalpha(text[i])) { BSP_LCD_DisplayChar(x_pos, y_pos, '-'); i -= 1; } @@ -55,21 +55,23 @@ void lcd_display_text(uint8_t* text, uint16_t x_pos, uint16_t y_pos, uint32_t co x_pos += font->Width; } } - } else { - BSP_LCD_DisplayStringAt(x_pos, y_pos, text, LEFT_MODE); + return; } - + BSP_LCD_DisplayStringAt(x_pos, y_pos, text, LEFT_MODE); } -void lcd_draw_raw_img(const void* p_src, uint32_t x_pos, uint32_t y_pos, uint32_t x_size, uint32_t y_size, uint32_t color_mode) { +void lcd_draw_raw_img(const void* p_src, + uint32_t x_pos, + uint32_t y_pos, + uint32_t x_size, + uint32_t y_size, + uint32_t color_mode) { + uint32_t address = hLtdcHandler.LayerCfg[1].FBStartAdress + (((BSP_LCD_GetXSize() * y_pos) + x_pos) * (4)); + void* p_dst = (void*)address; - uint32_t address = hLtdcHandler.LayerCfg[1].FBStartAdress + (((BSP_LCD_GetXSize()*y_pos) + x_pos)*(4)); - void *p_dst = (void *)address; - - - hDma2dHandler2.Init.Mode = DMA2D_M2M_PFC; - hDma2dHandler2.Init.ColorMode = DMA2D_ARGB8888; - hDma2dHandler2.Init.OutputOffset = BSP_LCD_GetXSize()-x_size; + hDma2dHandler2.Init.Mode = DMA2D_M2M_PFC; + hDma2dHandler2.Init.ColorMode = DMA2D_ARGB8888; + hDma2dHandler2.Init.OutputOffset = BSP_LCD_GetXSize() - x_size; hDma2dHandler2.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; hDma2dHandler2.LayerCfg[1].InputAlpha = 0xFF; @@ -84,7 +86,7 @@ void lcd_draw_raw_img(const void* p_src, uint32_t x_pos, uint32_t y_pos, uint32_ } LOG_INFO(TAG, "DMA2D config layer"); if (HAL_DMA2D_ConfigLayer(&hDma2dHandler2, 1) != HAL_OK) { - LOG_CRIT(TAG, "HAL_DMA2D_ConfigLayer error"); + LOG_CRIT(TAG, "HAL_DMA2D_ConfigLayer error"); return; } LOG_INFO(TAG, "DMA2D start"); @@ -100,7 +102,7 @@ void lcd_draw_bmp_img(uint8_t* bmp_buff, uint32_t x_pos, uint32_t y_pos) { BSP_LCD_DrawBitmap(x_pos, y_pos, bmp_buff); } -void lcd_draw_img_from_fs_with_name(const char* name, uint32_t x_pos, uint32_t y_pos){ +void lcd_draw_img_from_fs_with_name(const char* name, uint32_t x_pos, uint32_t y_pos) { llfs_file_t* file = llfs_file_open(name); if (file != NULL) { BSP_LCD_DrawBitmap(x_pos, y_pos, file->data); From e88620dd3c061f29953098958bc969b76b7f57cc Mon Sep 17 00:00:00 2001 From: xoreo Date: Mon, 13 Nov 2023 18:17:02 +0100 Subject: [PATCH 06/14] Apply changes to doxygen --- project/Core/Inc/lcd_api.h | 14 ++++++------ project/Core/Src/lcd_api.c | 45 ++++++++++++++++++-------------------- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/project/Core/Inc/lcd_api.h b/project/Core/Inc/lcd_api.h index 77a297f..bf37e9d 100644 --- a/project/Core/Inc/lcd_api.h +++ b/project/Core/Inc/lcd_api.h @@ -47,11 +47,11 @@ #define LCD_RGB565 0x00000002U #define LCD_ARGB1555 0x00000003U -#define LCD_FONT8 &Font8 -#define LCD_FONT12 &Font12 -#define LCD_FONT16 &Font16 -#define LCD_FONT20 &Font20 -#define LCD_FONT24 &Font24 +#define LCD_FONT8 (&Font8) +#define LCD_FONT12 (&Font12) +#define LCD_FONT16 (&Font16) +#define LCD_FONT20 (&Font20) +#define LCD_FONT24 (&Font24) extern LTDC_HandleTypeDef hLtdcHandler; @@ -101,9 +101,9 @@ void lcd_draw_raw_img(const void* p_src, uint32_t x_pos, uint32_t y_pos, uint32_ * Draw BMP image from C array to the LCD screen at position X, Y. In color mode ARGB8888, RGB888, RGB565 or ARGB1555 * Supports ARGB8888, RGB565, RGB888 * + * @param[in] bmp_buff BMP file data * @param[in] x_pos X-position * @param[in] y_pos Y-position - * @param[in] BMP file data */ void lcd_draw_bmp_img(uint8_t* bmp_buff, uint32_t x_pos, uint32_t y_pos); @@ -112,9 +112,9 @@ void lcd_draw_bmp_img(uint8_t* bmp_buff, uint32_t x_pos, uint32_t y_pos); * Draw BMP image from C array to the LCD screen at position X, Y by specifying the BMP image name on the filesystem * Supports ARGB8888, RGB565, RGB888 * + * @param[in] name Name of image on filesystem * @param[in] x_pos X-position * @param[in] y_pos Y-position - * @param[in] BMP file data */ void lcd_draw_img_from_fs_with_name(const char* name, uint32_t x_pos, uint32_t y_pos); diff --git a/project/Core/Src/lcd_api.c b/project/Core/Src/lcd_api.c index 740e0c7..310b558 100644 --- a/project/Core/Src/lcd_api.c +++ b/project/Core/Src/lcd_api.c @@ -2,7 +2,6 @@ * @file lcd_api.c * @brief LCD API implementation * @author Tim S. - * @todo Implement function to read images from fs */ #include "lcd_api.h" @@ -15,7 +14,7 @@ void lcd_init(bool bl_on) { BSP_LCD_Init(); BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS); - BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS + (BSP_LCD_GetXSize() * BSP_LCD_GetYSize() * 4)); + BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS + (BSP_LCD_GetXSize()*BSP_LCD_GetYSize()*4)); BSP_LCD_SelectLayer(0); BSP_LCD_Clear(LCD_COLOR_BLACK); BSP_LCD_SelectLayer(1); @@ -24,12 +23,12 @@ void lcd_init(bool bl_on) { HAL_GPIO_WritePin(GPIOK, GPIO_PIN_3, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOI, GPIO_PIN_12, GPIO_PIN_SET); } else { - HAL_GPIO_WritePin(GPIOK, GPIO_PIN_3, GPIO_PIN_RESET); - HAL_GPIO_WritePin(GPIOI, GPIO_PIN_12, GPIO_PIN_RESET); + HAL_GPIO_WritePin(GPIOK, GPIO_PIN_3, GPIO_PIN_RESET); + HAL_GPIO_WritePin(GPIOI, GPIO_PIN_12, GPIO_PIN_RESET); } } -void lcd_display_text(uint8_t* text, uint16_t x_pos, uint16_t y_pos, uint32_t color, uint32_t bg_color, sFONT* font) { +void lcd_display_text(uint8_t* text, uint16_t x_pos, uint16_t y_pos, uint32_t color, uint32_t bg_color, sFONT *font) { LOG_INFO(TAG, "Display text: %s @x=%d,y=%d", text, x_pos, y_pos); uint16_t tot_length = x_pos + (strlen(text) * font->Width); @@ -43,8 +42,8 @@ void lcd_display_text(uint8_t* text, uint16_t x_pos, uint16_t y_pos, uint32_t co if (tot_length > BSP_LCD_GetXSize()) { for (int i = 0; i < strlen(text); i++) { - if ((x_pos) > BSP_LCD_GetXSize() - (font->Width) * 2) { - if (isalpha(text[i - 1]) && isalpha(text[i])) { + if ((x_pos) > BSP_LCD_GetXSize() - (font->Width)*2) { + if (isalpha(text[i-1]) && isalpha(text[i])) { BSP_LCD_DisplayChar(x_pos, y_pos, '-'); i -= 1; } @@ -55,23 +54,21 @@ void lcd_display_text(uint8_t* text, uint16_t x_pos, uint16_t y_pos, uint32_t co x_pos += font->Width; } } - return; + } else { + BSP_LCD_DisplayStringAt(x_pos, y_pos, text, LEFT_MODE); } - BSP_LCD_DisplayStringAt(x_pos, y_pos, text, LEFT_MODE); + } -void lcd_draw_raw_img(const void* p_src, - uint32_t x_pos, - uint32_t y_pos, - uint32_t x_size, - uint32_t y_size, - uint32_t color_mode) { - uint32_t address = hLtdcHandler.LayerCfg[1].FBStartAdress + (((BSP_LCD_GetXSize() * y_pos) + x_pos) * (4)); - void* p_dst = (void*)address; +void lcd_draw_raw_img(const void* p_src, uint32_t x_pos, uint32_t y_pos, uint32_t x_size, uint32_t y_size, uint32_t color_mode) { - hDma2dHandler2.Init.Mode = DMA2D_M2M_PFC; - hDma2dHandler2.Init.ColorMode = DMA2D_ARGB8888; - hDma2dHandler2.Init.OutputOffset = BSP_LCD_GetXSize() - x_size; + uint32_t address = hLtdcHandler.LayerCfg[1].FBStartAdress + (((BSP_LCD_GetXSize()*y_pos) + x_pos)*(4)); + void *p_dst = (void *)address; + + + hDma2dHandler2.Init.Mode = DMA2D_M2M_PFC; + hDma2dHandler2.Init.ColorMode = DMA2D_ARGB8888; + hDma2dHandler2.Init.OutputOffset = BSP_LCD_GetXSize()-x_size; hDma2dHandler2.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; hDma2dHandler2.LayerCfg[1].InputAlpha = 0xFF; @@ -86,7 +83,7 @@ void lcd_draw_raw_img(const void* p_src, } LOG_INFO(TAG, "DMA2D config layer"); if (HAL_DMA2D_ConfigLayer(&hDma2dHandler2, 1) != HAL_OK) { - LOG_CRIT(TAG, "HAL_DMA2D_ConfigLayer error"); + LOG_CRIT(TAG, "HAL_DMA2D_ConfigLayer error"); return; } LOG_INFO(TAG, "DMA2D start"); @@ -98,11 +95,11 @@ void lcd_draw_raw_img(const void* p_src, HAL_DMA2D_PollForTransfer(&hDma2dHandler2, 10); } -void lcd_draw_bmp_img(uint8_t* bmp_buff, uint32_t x_pos, uint32_t y_pos) { +void lcd_draw_bmp_img(uint8_t* bmp_buff, uint32_t x_pos, uint32_t y_pos){ BSP_LCD_DrawBitmap(x_pos, y_pos, bmp_buff); } -void lcd_draw_img_from_fs_with_name(const char* name, uint32_t x_pos, uint32_t y_pos) { +void lcd_draw_img_from_fs_with_name(const char* name, uint32_t x_pos, uint32_t y_pos){ llfs_file_t* file = llfs_file_open(name); if (file != NULL) { BSP_LCD_DrawBitmap(x_pos, y_pos, file->data); @@ -111,6 +108,6 @@ void lcd_draw_img_from_fs_with_name(const char* name, uint32_t x_pos, uint32_t y } } -void lcd_clear(uint32_t color) { +void lcd_clear(uint32_t color){ BSP_LCD_Clear(color); } From 425074336b69beb7e89cd52aa26cc1ae9d1556da Mon Sep 17 00:00:00 2001 From: xoreo Date: Tue, 14 Nov 2023 14:37:25 +0100 Subject: [PATCH 07/14] Add documentation --- docs/lcd_api.md | 67 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 4 deletions(-) diff --git a/docs/lcd_api.md b/docs/lcd_api.md index 32c46ae..46c32c9 100644 --- a/docs/lcd_api.md +++ b/docs/lcd_api.md @@ -73,9 +73,9 @@ void main(void) { ``` 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. -#### Drawing a BMP (C-array) onto the screen +#### Drawing a 'raw' image onto the screen ```c -void lcd_draw_bmp(const void* p_src, uint32_t x_pos, uint32_t y_pos, uint32_t x_size, uint32_t y_size, uint32_t color_mode); +void lcd_draw_raw_img(const void* p_src, uint32_t x_pos, uint32_t y_pos, uint32_t x_size, uint32_t y_size, uint32_t color_mode); ``` ```c @@ -86,7 +86,66 @@ void main(void) { ... lcd_init(true); ... - lcd_draw_bmp(bmp_array, 0, 0, 50, 50, LCD_ARGB8888); + lcd_draw_raw_img(raw_img_array, 0, 0, 50, 50, LCD_ARGB8888); } ``` -Draw BMP image from C array to the LCD screen at position X, Y. In color mode ARGB8888, RGB888, RGB565 or ARGB1555 Supports ARGB8888, RGB565, RGB888 (see LCD_* defines in header file). +Draw raw image from a C array to the LCD screen at position X, Y. In color mode ARGB8888, RGB888, RGB565 or ARGB1555 Supports ARGB8888, RGB565, RGB888 (see LCD_* defines in header file). + +#### Drawing a BMP image onto the screen +```c +void lcd_draw_bmp_img(uint8_t* bmp_buff, uint32_t x_pos, uint32_t y_pos); +``` + +```c +#include "lcd_api.h" +#include "test_image.h" + +void main(void) { + ... + lcd_init(true); + ... + lcd_draw_bmp_img(bmp_array, 0, 0); + lcd_draw_bmp_img(file->data, 50, 50); +} +``` +Drawing a BMP image (either from filesystem or a C-array) to the LCD screen at position X, Y. The image size and color scheme do not have to be passed as arguments like in the `lcd_draw_raw_img(...)` function, these values are present in the BMP header. + +#### Drawing a BMP from the filesystem to the LCD +```c +void lcd_draw_img_from_fs_with_name(const char* name, uint32_t x_pos, uint32_t y_pos); +``` + +```c +#include "lcd_api.h" +#include "test_image.h" + +void main(void) { + ... + lcd_init(true); + ... + lcd_draw_img_from_fs_with_name("st.bmp", 0, 0); +} +``` + +This function expects the name of the BMP image as argument, together with the X and Y coordinates. + +Note that this function only works for BMP images and not raw images. + +#### Clearing the LCD screen +```c +void lcd_clear(uint32_t color); +``` + +```c +#include "lcd_api.h" +#include "test_image.h" + +void main(void) { + ... + lcd_init(true); + ... + lcd_clear(LCD_BLACK); +} +``` + +Clears the LCD screen to the specified color. From 1621c8feb78da109a23421a956df18c85df24fd3 Mon Sep 17 00:00:00 2001 From: xoreo Date: Tue, 14 Nov 2023 14:47:40 +0100 Subject: [PATCH 08/14] Add link to lcd_api.md in README.md --- README.md | 3 ++- docs/lcd_api.md | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8d8ba21..e4f90fb 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ If your part needs documentation (e.g. how to use tcp cmd interface), add a mark This folder contains the following documents: - [llfs.md](docs/llfs.md): Linked List File System +- [lcd_api.md](docs/lcd_api.md): LCD API - [logger.md](docs/logger.md): Logging and Debugging Messages - [mkllfs.md](docs/mkllfs.md): Make Linked List File System -- [style_guide.md](docs/style_guide.md): Style Guide \ No newline at end of file +- [style_guide.md](docs/style_guide.md): Style Guide diff --git a/docs/lcd_api.md b/docs/lcd_api.md index 46c32c9..fdb4caf 100644 --- a/docs/lcd_api.md +++ b/docs/lcd_api.md @@ -117,7 +117,6 @@ void lcd_draw_img_from_fs_with_name(const char* name, uint32_t x_pos, uint32_t y ```c #include "lcd_api.h" -#include "test_image.h" void main(void) { ... @@ -138,7 +137,6 @@ void lcd_clear(uint32_t color); ```c #include "lcd_api.h" -#include "test_image.h" void main(void) { ... From ec5691a9abd605c4af7705552a4be28a8ce44e1a Mon Sep 17 00:00:00 2001 From: xoreo Date: Tue, 14 Nov 2023 15:01:38 +0100 Subject: [PATCH 09/14] Add note on images that can go out of frame --- docs/lcd_api.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/lcd_api.md b/docs/lcd_api.md index fdb4caf..58b2692 100644 --- a/docs/lcd_api.md +++ b/docs/lcd_api.md @@ -91,6 +91,8 @@ void main(void) { ``` Draw raw image from a C array to the LCD screen at position X, Y. In color mode ARGB8888, RGB888, RGB565 or ARGB1555 Supports ARGB8888, RGB565, RGB888 (see LCD_* defines in header file). +Note that when an image exceeds the X or Y size of the LCD display, the image will go out of the visible LCD area. + #### Drawing a BMP image onto the screen ```c void lcd_draw_bmp_img(uint8_t* bmp_buff, uint32_t x_pos, uint32_t y_pos); @@ -110,6 +112,8 @@ void main(void) { ``` Drawing a BMP image (either from filesystem or a C-array) to the LCD screen at position X, Y. The image size and color scheme do not have to be passed as arguments like in the `lcd_draw_raw_img(...)` function, these values are present in the BMP header. +Note that when an image exceeds the X or Y size of the LCD display, the image will go out of the visible LCD area. + #### Drawing a BMP from the filesystem to the LCD ```c void lcd_draw_img_from_fs_with_name(const char* name, uint32_t x_pos, uint32_t y_pos); @@ -128,7 +132,7 @@ void main(void) { This function expects the name of the BMP image as argument, together with the X and Y coordinates. -Note that this function only works for BMP images and not raw images. +Note that this function only works for BMP images and not raw images and when an image exceeds the X or Y size of the LCD display, the image will go out of the visible LCD area. #### Clearing the LCD screen ```c From 1562d4d3b0ede228e2bb42ad871c06db02ff2bcf Mon Sep 17 00:00:00 2001 From: xoreo Date: Tue, 14 Nov 2023 15:31:10 +0100 Subject: [PATCH 10/14] Bug fix in lcd_display_text() --- project/Core/Src/lcd_api.c | 3 +- project/project Debug.launch | 82 ++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 project/project Debug.launch diff --git a/project/Core/Src/lcd_api.c b/project/Core/Src/lcd_api.c index 310b558..9608462 100644 --- a/project/Core/Src/lcd_api.c +++ b/project/Core/Src/lcd_api.c @@ -45,7 +45,8 @@ void lcd_display_text(uint8_t* text, uint16_t x_pos, uint16_t y_pos, uint32_t co if ((x_pos) > BSP_LCD_GetXSize() - (font->Width)*2) { if (isalpha(text[i-1]) && isalpha(text[i])) { BSP_LCD_DisplayChar(x_pos, y_pos, '-'); - i -= 1; + } else { + BSP_LCD_DisplayChar(x_pos, y_pos, text[i]); } x_pos = 0; y_pos += font->Height; diff --git a/project/project Debug.launch b/project/project Debug.launch new file mode 100644 index 0000000..e766d28 --- /dev/null +++ b/project/project Debug.launch @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From a899fdaee8d853386a560b173533e5b3ed651d3b Mon Sep 17 00:00:00 2001 From: xoreo Date: Tue, 14 Nov 2023 15:39:22 +0100 Subject: [PATCH 11/14] Adapt to styleguide (Sani7 comments) --- docs/lcd_api.md | 4 ++-- project/Core/Inc/lcd_api.h | 2 +- project/Core/Src/lcd_api.c | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/lcd_api.md b/docs/lcd_api.md index 58b2692..4e61aca 100644 --- a/docs/lcd_api.md +++ b/docs/lcd_api.md @@ -116,7 +116,7 @@ Note that when an image exceeds the X or Y size of the LCD display, the image wi #### Drawing a BMP from the filesystem to the LCD ```c -void lcd_draw_img_from_fs_with_name(const char* name, uint32_t x_pos, uint32_t y_pos); +void lcd_draw_img_from_fs(const char* name, uint32_t x_pos, uint32_t y_pos); ``` ```c @@ -126,7 +126,7 @@ void main(void) { ... lcd_init(true); ... - lcd_draw_img_from_fs_with_name("st.bmp", 0, 0); + lcd_draw_img_from_fs("st.bmp", 0, 0); } ``` diff --git a/project/Core/Inc/lcd_api.h b/project/Core/Inc/lcd_api.h index bf37e9d..02715f5 100644 --- a/project/Core/Inc/lcd_api.h +++ b/project/Core/Inc/lcd_api.h @@ -116,7 +116,7 @@ void lcd_draw_bmp_img(uint8_t* bmp_buff, uint32_t x_pos, uint32_t y_pos); * @param[in] x_pos X-position * @param[in] y_pos Y-position */ -void lcd_draw_img_from_fs_with_name(const char* name, uint32_t x_pos, uint32_t y_pos); +void lcd_draw_img_from_fs(const char* name, uint32_t x_pos, uint32_t y_pos); /** * @brief Clear LCD screen diff --git a/project/Core/Src/lcd_api.c b/project/Core/Src/lcd_api.c index 9608462..446fd05 100644 --- a/project/Core/Src/lcd_api.c +++ b/project/Core/Src/lcd_api.c @@ -96,19 +96,19 @@ void lcd_draw_raw_img(const void* p_src, uint32_t x_pos, uint32_t y_pos, uint32_ HAL_DMA2D_PollForTransfer(&hDma2dHandler2, 10); } -void lcd_draw_bmp_img(uint8_t* bmp_buff, uint32_t x_pos, uint32_t y_pos){ +void lcd_draw_bmp_img(uint8_t* bmp_buff, uint32_t x_pos, uint32_t y_pos) { BSP_LCD_DrawBitmap(x_pos, y_pos, bmp_buff); } -void lcd_draw_img_from_fs_with_name(const char* name, uint32_t x_pos, uint32_t y_pos){ +void lcd_draw_img_from_fs(const char* name, uint32_t x_pos, uint32_t y_pos) { llfs_file_t* file = llfs_file_open(name); if (file != NULL) { BSP_LCD_DrawBitmap(x_pos, y_pos, file->data); - } else { - LOG_WARN(TAG, "File \"%s\" not found", file->name); + return; } + LOG_WARN(TAG, "File \"%s\" not found", file->name); } -void lcd_clear(uint32_t color){ +void lcd_clear(uint32_t color) { BSP_LCD_Clear(color); } From cb1e227790ecf919ec561811235c5b5cf495b934 Mon Sep 17 00:00:00 2001 From: xoreo Date: Tue, 14 Nov 2023 15:51:27 +0100 Subject: [PATCH 12/14] Addhere to some missed style guidlines --- project/Core/Src/lcd_api.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/project/Core/Src/lcd_api.c b/project/Core/Src/lcd_api.c index 446fd05..8a6c316 100644 --- a/project/Core/Src/lcd_api.c +++ b/project/Core/Src/lcd_api.c @@ -14,7 +14,7 @@ void lcd_init(bool bl_on) { BSP_LCD_Init(); BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS); - BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS + (BSP_LCD_GetXSize()*BSP_LCD_GetYSize()*4)); + BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS + (BSP_LCD_GetXSize() * BSP_LCD_GetYSize() * 4)); BSP_LCD_SelectLayer(0); BSP_LCD_Clear(LCD_COLOR_BLACK); BSP_LCD_SelectLayer(1); @@ -22,10 +22,10 @@ void lcd_init(bool bl_on) { if (bl_on) { HAL_GPIO_WritePin(GPIOK, GPIO_PIN_3, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOI, GPIO_PIN_12, GPIO_PIN_SET); - } else { - HAL_GPIO_WritePin(GPIOK, GPIO_PIN_3, GPIO_PIN_RESET); - HAL_GPIO_WritePin(GPIOI, GPIO_PIN_12, GPIO_PIN_RESET); + return; } + HAL_GPIO_WritePin(GPIOK, GPIO_PIN_3, GPIO_PIN_RESET); + HAL_GPIO_WritePin(GPIOI, GPIO_PIN_12, GPIO_PIN_RESET); } void lcd_display_text(uint8_t* text, uint16_t x_pos, uint16_t y_pos, uint32_t color, uint32_t bg_color, sFONT *font) { @@ -42,34 +42,33 @@ void lcd_display_text(uint8_t* text, uint16_t x_pos, uint16_t y_pos, uint32_t co if (tot_length > BSP_LCD_GetXSize()) { for (int i = 0; i < strlen(text); i++) { - if ((x_pos) > BSP_LCD_GetXSize() - (font->Width)*2) { - if (isalpha(text[i-1]) && isalpha(text[i])) { + if ((x_pos) > BSP_LCD_GetXSize() - (font->Width) * 2) { + if (isalpha(text[i - 1]) && isalpha(text[i])) { BSP_LCD_DisplayChar(x_pos, y_pos, '-'); } else { BSP_LCD_DisplayChar(x_pos, y_pos, text[i]); } x_pos = 0; y_pos += font->Height; - } else { - BSP_LCD_DisplayChar(x_pos, y_pos, text[i]); - x_pos += font->Width; + continue; } + BSP_LCD_DisplayChar(x_pos, y_pos, text[i]); + x_pos += font->Width; } - } else { - BSP_LCD_DisplayStringAt(x_pos, y_pos, text, LEFT_MODE); + return; } - + BSP_LCD_DisplayStringAt(x_pos, y_pos, text, LEFT_MODE); } void lcd_draw_raw_img(const void* p_src, uint32_t x_pos, uint32_t y_pos, uint32_t x_size, uint32_t y_size, uint32_t color_mode) { - uint32_t address = hLtdcHandler.LayerCfg[1].FBStartAdress + (((BSP_LCD_GetXSize()*y_pos) + x_pos)*(4)); + uint32_t address = hLtdcHandler.LayerCfg[1].FBStartAdress + (((BSP_LCD_GetXSize() * y_pos) + x_pos) * (4)); void *p_dst = (void *)address; hDma2dHandler2.Init.Mode = DMA2D_M2M_PFC; hDma2dHandler2.Init.ColorMode = DMA2D_ARGB8888; - hDma2dHandler2.Init.OutputOffset = BSP_LCD_GetXSize()-x_size; + hDma2dHandler2.Init.OutputOffset = BSP_LCD_GetXSize() - x_size; hDma2dHandler2.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; hDma2dHandler2.LayerCfg[1].InputAlpha = 0xFF; From e9abf1f46aa79c60fda6560f938bdb3eef89587a Mon Sep 17 00:00:00 2001 From: L-diy <25403682+ldiy@users.noreply.github.com> Date: Tue, 14 Nov 2023 16:16:50 +0100 Subject: [PATCH 13/14] Delete project/project Debug.launch --- project/project Debug.launch | 82 ------------------------------------ 1 file changed, 82 deletions(-) delete mode 100644 project/project Debug.launch diff --git a/project/project Debug.launch b/project/project Debug.launch deleted file mode 100644 index e766d28..0000000 --- a/project/project Debug.launch +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 288f78fe4026345001cf81f2fc3fd7599899e7cc Mon Sep 17 00:00:00 2001 From: L-diy <25403682+ldiy@users.noreply.github.com> Date: Tue, 14 Nov 2023 16:21:52 +0100 Subject: [PATCH 14/14] Update .gitignore --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1d3d17a..5b9efd7 100644 --- a/.gitignore +++ b/.gitignore @@ -56,4 +56,6 @@ project/.mxproject project/project.launch project/Scripts -Scripts/ \ No newline at end of file +Scripts/ + +project/project\ Debug.launch