Implement lcd_display_text
This commit is contained in:
@@ -7,39 +7,49 @@
|
|||||||
#ifndef INC_LCD_API_H_
|
#ifndef INC_LCD_API_H_
|
||||||
#define INC_LCD_API_H_
|
#define INC_LCD_API_H_
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "../../Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_lcd.h"
|
#include "../../Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_lcd.h"
|
||||||
|
|
||||||
#define BLUE LCD_COLOR_BLUE
|
#define LCD_BLUE LCD_COLOR_BLUE
|
||||||
#define GREEN LCD_COLOR_GREEN
|
#define LCD_GREEN LCD_COLOR_GREEN
|
||||||
#define RED LCD_COLOR_RED
|
#define LCD_RED LCD_COLOR_RED
|
||||||
#define CYAN LCD_COLOR_CYAN
|
#define LCD_CYAN LCD_COLOR_CYAN
|
||||||
#define MAGENTA LCD_COLOR_MAGENTA
|
#define LCD_MAGENTA LCD_COLOR_MAGENTA
|
||||||
#define YELLOW LCD_COLOR_YELLOW
|
#define LCD_YELLOW LCD_COLOR_YELLOW
|
||||||
#define LIGHTBLUE LCD_COLOR_LIGHTBLUE
|
#define LCD_LIGHTBLUE LCD_COLOR_LIGHTBLUE
|
||||||
#define LIGHTGREEN LCD_COLOR_LIGHTGREEN
|
#define LCD_LIGHTGREEN LCD_COLOR_LIGHTGREEN
|
||||||
#define LIGHTRED LCD_COLOR_LIGHTRED
|
#define LCD_LIGHTRED LCD_COLOR_LIGHTRED
|
||||||
#define LIGHTCYAN LCD_COLOR_LIGHTCYAN
|
#define LCD_LIGHTCYAN LCD_COLOR_LIGHTCYAN
|
||||||
#define LIGHTMAGENTA LCD_COLOR_LIGHTMAGENTA
|
#define LCD_LIGHTMAGENTA LCD_COLOR_LIGHTMAGENTA
|
||||||
#define LIGHTYELLOW LCD_COLOR_LIGHTYELLOW
|
#define LCD_LIGHTYELLOW LCD_COLOR_LIGHTYELLOW
|
||||||
#define DARKBLUE LCD_COLOR_DARKBLUE
|
#define LCD_DARKBLUE LCD_COLOR_DARKBLUE
|
||||||
#define DARKGREEN LCD_COLOR_DARKGREEN
|
#define LCD_DARKGREEN LCD_COLOR_DARKGREEN
|
||||||
#define DARKRED LCD_COLOR_DARKRED
|
#define LCD_DARKRED LCD_COLOR_DARKRED
|
||||||
#define DARKCYAN LCD_COLOR_DARKCYAN
|
#define LCD_DARKCYAN LCD_COLOR_DARKCYAN
|
||||||
#define DARKMAGENTA LCD_COLOR_DARKMAGENTA
|
#define LCD_DARKMAGENTA LCD_COLOR_DARKMAGENTA
|
||||||
#define DARKYELLOW LCD_COLOR_DARKYELLOW
|
#define LCD_DARKYELLOW LCD_COLOR_DARKYELLOW
|
||||||
#define WHITE LCD_COLOR_WHITE
|
#define LCD_WHITE LCD_COLOR_WHITE
|
||||||
#define LIGHTGRAY LCD_COLOR_LIGHTGRAY
|
#define LCD_LIGHTGRAY LCD_COLOR_LIGHTGRAY
|
||||||
#define GRAY LCD_COLOR_GRAY
|
#define LCD_GRAY LCD_COLOR_GRAY
|
||||||
#define DARKGRAY LCD_COLOR_DARKGRAY
|
#define LCD_DARKGRAY LCD_COLOR_DARKGRAY
|
||||||
#define BLACK LCD_COLOR_BLACK
|
#define LCD_BLACK LCD_COLOR_BLACK
|
||||||
#define BROWN LCD_COLOR_BROWN
|
#define LCD_BROWN LCD_COLOR_BROWN
|
||||||
#define ORANGE LCD_COLOR_ORANGE
|
#define LCD_ORANGE LCD_COLOR_ORANGE
|
||||||
#define TRANSPARENT LCD_COLOR_TRANSPARENT
|
#define LCD_TRANSPARENT LCD_COLOR_TRANSPARENT
|
||||||
|
|
||||||
|
#define LCD_ARGB8888 0x00000000U
|
||||||
|
#define LCD_RGB888 0x00000001U
|
||||||
|
#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 ARGB8888 0x00000000U
|
|
||||||
#define RGB888 0x00000001U
|
|
||||||
#define RGB565 0x00000002U
|
|
||||||
#define ARGB1555 0x00000003U
|
|
||||||
|
|
||||||
extern LTDC_HandleTypeDef hLtdcHandler;
|
extern LTDC_HandleTypeDef hLtdcHandler;
|
||||||
|
|
||||||
@@ -47,35 +57,40 @@ extern LTDC_HandleTypeDef hLtdcHandler;
|
|||||||
* @brief Initialise LCD
|
* @brief Initialise LCD
|
||||||
* Initialise the LCD screen with BackLight on or not
|
* Initialise the LCD screen with BackLight on or not
|
||||||
*
|
*
|
||||||
* @param[in] Bool to enable or disable the LCD backlight
|
* @param[in] bl_on Bool to enable or disable the LCD backlight
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void lcd_init(bool BL_on);
|
void lcd_init(bool bl_on);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Display text
|
* @brief Display text
|
||||||
* Display text on the LCD screen in a certain color
|
* 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 letters in a word, the '-' character
|
||||||
|
* will be injected.
|
||||||
*
|
*
|
||||||
* @param[in] C-style text string to display on the LCD screen
|
* @param[in] text C-style text string to display on the LCD screen
|
||||||
* @param[in] X-position
|
* @param[in] x_pos X-position
|
||||||
* @param[in] Y-position
|
* @param[in] y_pos Y-position
|
||||||
* @param[in] Color in which the text will be displayed, see preset colors in defines above
|
* @param[in] color Color in which the text will be displayed, see preset colors in defines above
|
||||||
|
* @param[in] bg_color Background color for the text
|
||||||
|
* @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);
|
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
|
* @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
|
* 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
|
||||||
*
|
*
|
||||||
* @author Wim Dams
|
* @author Wim Dams
|
||||||
*
|
*
|
||||||
* @param[in] * pSrc - C array containing the image data
|
* @param[in] p_src C array containing the image data
|
||||||
* @param[in] X-position
|
* @param[in] x_pos X-position
|
||||||
* @param[in] Y-position
|
* @param[in] y_pos Y-position
|
||||||
* @param[in] Width of image
|
* @param[in] x_size Width of image
|
||||||
* @param[in] Height of image
|
* @param[in] y_size Height of image
|
||||||
* @param[in] Color mode (see defined color modes above in file)
|
* @param[in] color_mode Color mode (see defined color modes above in file)
|
||||||
*/
|
*/
|
||||||
void lcd_draw_bmp(const void* pSrc, uint32_t xPos, uint32_t yPos, uint32_t xSize, uint32_t ySize, uint32_t ColorMode);
|
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);
|
||||||
|
|
||||||
#endif /* INC_LCD_API_H_ */
|
#endif /* INC_LCD_API_H_ */
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
* @file lcd_api.c
|
* @file lcd_api.c
|
||||||
* @brief LCD API implementation
|
* @brief LCD API implementation
|
||||||
* @author Tim S.
|
* @author Tim S.
|
||||||
* @todo Implement lcd_display_text(...)
|
|
||||||
* @todo Implement function to read images from fs
|
* @todo Implement function to read images from fs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -11,7 +10,7 @@
|
|||||||
|
|
||||||
static DMA2D_HandleTypeDef hDma2dHandler2;
|
static DMA2D_HandleTypeDef hDma2dHandler2;
|
||||||
|
|
||||||
void lcd_init(bool BL_On) {
|
void lcd_init(bool bl_on) {
|
||||||
BSP_LCD_Init();
|
BSP_LCD_Init();
|
||||||
BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS);
|
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));
|
||||||
@@ -19,7 +18,7 @@ void lcd_init(bool BL_On) {
|
|||||||
BSP_LCD_Clear(LCD_COLOR_BLACK);
|
BSP_LCD_Clear(LCD_COLOR_BLACK);
|
||||||
BSP_LCD_SelectLayer(1);
|
BSP_LCD_SelectLayer(1);
|
||||||
BSP_LCD_Clear(LCD_COLOR_BLACK);
|
BSP_LCD_Clear(LCD_COLOR_BLACK);
|
||||||
if (BL_On) {
|
if (bl_on) {
|
||||||
HAL_GPIO_WritePin(GPIOK, GPIO_PIN_3, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(GPIOK, GPIO_PIN_3, GPIO_PIN_SET);
|
||||||
HAL_GPIO_WritePin(GPIOI, GPIO_PIN_12, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(GPIOI, GPIO_PIN_12, GPIO_PIN_SET);
|
||||||
} else {
|
} else {
|
||||||
@@ -28,31 +27,68 @@ void lcd_init(bool BL_On) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: implement this function
|
void lcd_display_text(const char* text, uint16_t x_pos, uint16_t y_pos, uint32_t color, uint32_t bg_color, sFONT *font) {
|
||||||
void lcd_display_text(const char* text, uint16_t x_pos, uint16_t y_pos, uint32_t color) {
|
uint16_t tot_length = x_pos + (strlen(text) * font->Width);
|
||||||
|
if ((x_pos % font->Width) != 0) {
|
||||||
|
x_pos -= (x_pos % font->Width);
|
||||||
|
}
|
||||||
|
|
||||||
BSP_LCD_SetTextColor(color);
|
BSP_LCD_SetTextColor(color);
|
||||||
|
BSP_LCD_SetBackColor(bg_color);
|
||||||
|
BSP_LCD_SetFont(font);
|
||||||
|
|
||||||
|
if (tot_length > BSP_LCD_GetXSize()) {
|
||||||
|
uint16_t wrap_idx = (BSP_LCD_GetXSize() - x_pos)/font->Width;
|
||||||
|
if (isalpha(text[wrap_idx - 1]) && isalpha(text[wrap_idx])) {
|
||||||
|
x_pos -= (font->Width-2);
|
||||||
|
char part_one[wrap_idx+2];
|
||||||
|
char part_two[(strlen(text) - wrap_idx)+1];
|
||||||
|
strncpy(part_one, text, wrap_idx);
|
||||||
|
part_one[wrap_idx] = '-';
|
||||||
|
part_one[wrap_idx+1] = '\00';
|
||||||
|
strncpy(part_two, &text[wrap_idx], (strlen(text) - wrap_idx));
|
||||||
|
part_two[(strlen(text) - wrap_idx)] = '\00';
|
||||||
|
BSP_LCD_DisplayStringAt(x_pos, y_pos, part_one, LEFT_MODE);
|
||||||
|
y_pos += font->Height;
|
||||||
|
x_pos = 0;
|
||||||
|
BSP_LCD_DisplayStringAt(x_pos, y_pos, part_two, LEFT_MODE);
|
||||||
|
} else {
|
||||||
|
char part_one[wrap_idx+1];
|
||||||
|
char part_two[(strlen(text) - wrap_idx)+1];
|
||||||
|
strncpy(part_one, text, wrap_idx);
|
||||||
|
part_one[wrap_idx] = '\00';
|
||||||
|
strncpy(part_two, &text[wrap_idx], (strlen(text) - wrap_idx));
|
||||||
|
part_two[(strlen(text) - wrap_idx)] = '\00';
|
||||||
|
BSP_LCD_DisplayStringAt(x_pos, y_pos, part_one, LEFT_MODE);
|
||||||
|
y_pos += font->Height;
|
||||||
|
x_pos = 0;
|
||||||
|
BSP_LCD_DisplayStringAt(x_pos, y_pos, part_two, LEFT_MODE);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
BSP_LCD_DisplayStringAt(x_pos, y_pos, text, LEFT_MODE);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_draw_bmp(const void* pSrc, uint32_t xPos, uint32_t yPos, uint32_t xSize, uint32_t ySize, uint32_t ColorMode) {
|
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) {
|
||||||
|
|
||||||
uint32_t address = hLtdcHandler.LayerCfg[1].FBStartAdress + (((BSP_LCD_GetXSize()*yPos) + xPos)*(4));
|
uint32_t address = hLtdcHandler.LayerCfg[1].FBStartAdress + (((BSP_LCD_GetXSize()*y_pos) + x_pos)*(4));
|
||||||
void *pDst = (void *)address;
|
void *p_dst = (void *)address;
|
||||||
|
|
||||||
|
|
||||||
hDma2dHandler2.Init.Mode = DMA2D_M2M_PFC;
|
hDma2dHandler2.Init.Mode = DMA2D_M2M_PFC;
|
||||||
hDma2dHandler2.Init.ColorMode = DMA2D_ARGB8888;
|
hDma2dHandler2.Init.ColorMode = DMA2D_ARGB8888;
|
||||||
hDma2dHandler2.Init.OutputOffset = 480-xSize;
|
hDma2dHandler2.Init.OutputOffset = BSP_LCD_GetXSize()-x_size;
|
||||||
|
|
||||||
hDma2dHandler2.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
hDma2dHandler2.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
||||||
hDma2dHandler2.LayerCfg[1].InputAlpha = 0xFF;
|
hDma2dHandler2.LayerCfg[1].InputAlpha = 0xFF;
|
||||||
hDma2dHandler2.LayerCfg[1].InputColorMode = ColorMode;
|
hDma2dHandler2.LayerCfg[1].InputColorMode = color_mode;
|
||||||
hDma2dHandler2.LayerCfg[1].InputOffset = 0;
|
hDma2dHandler2.LayerCfg[1].InputOffset = 0;
|
||||||
|
|
||||||
hDma2dHandler2.Instance = DMA2D;
|
hDma2dHandler2.Instance = DMA2D;
|
||||||
if (HAL_DMA2D_Init(&hDma2dHandler2) == HAL_OK) {
|
if (HAL_DMA2D_Init(&hDma2dHandler2) == HAL_OK) {
|
||||||
if (HAL_DMA2D_ConfigLayer(&hDma2dHandler2, 1) == HAL_OK) {
|
if (HAL_DMA2D_ConfigLayer(&hDma2dHandler2, 1) == HAL_OK) {
|
||||||
if (HAL_DMA2D_Start(&hDma2dHandler2, (uint32_t)pSrc, (uint32_t)pDst, xSize, ySize) == HAL_OK) {
|
if (HAL_DMA2D_Start(&hDma2dHandler2, (uint32_t)p_src, (uint32_t)p_dst, x_size, y_size) == HAL_OK) {
|
||||||
HAL_DMA2D_PollForTransfer(&hDma2dHandler2, 10);
|
HAL_DMA2D_PollForTransfer(&hDma2dHandler2, 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,6 @@
|
|||||||
#define LOGGER_LEVEL_ALL
|
#define LOGGER_LEVEL_ALL
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
//#include "test_img.h"
|
|
||||||
#include "stlogo.h"
|
|
||||||
#include "lcd_api.h"
|
#include "lcd_api.h"
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
@@ -113,12 +111,8 @@ int main(void)
|
|||||||
MX_LWIP_Init();
|
MX_LWIP_Init();
|
||||||
MX_QUADSPI_Init();
|
MX_QUADSPI_Init();
|
||||||
/* USER CODE BEGIN 2 */
|
/* USER CODE BEGIN 2 */
|
||||||
//BSP_LCD_Init();
|
lcd_init(true);
|
||||||
HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_Port,LCD_BL_CTRL_Pin,GPIO_PIN_SET);
|
|
||||||
/* Assert display enable LCD_DISP pin */
|
|
||||||
HAL_GPIO_WritePin(LCD_DISP_GPIO_Port, LCD_DISP_Pin, GPIO_PIN_SET);
|
|
||||||
/* USER CODE END 2 */
|
/* USER CODE END 2 */
|
||||||
init_lcd();
|
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
/* USER CODE BEGIN WHILE */
|
/* USER CODE BEGIN WHILE */
|
||||||
while (1)
|
while (1)
|
||||||
|
|||||||
Reference in New Issue
Block a user