官方例程中显示不同大小的字符都是共用一个函数,即先指定字库、前景色和背景色,然后再将字符串及起始行列、对齐方式作为参数传送给字符串显示函数UTIL_LCD_DisplayStringAt(),如下图所示:
在UTIL_LCD_DisplayStringAt()函数中也仅仅是处理好显示的起始位置后,依次将字符串逐个字符传递给后续函数UTIL_LCD_DisplayChar(refcolumn, Ypos, *Text)处理:
后续的DisplayChar()函数如下: /** * @brief Displays one character in currently active layer.在当前活动层中显示一个字符。 * @param Xpos Start column address * @param Ypos Line where to display the character shape. * @param Ascii Character ascii code * This parameter must be a number between Min_Data = 0x20 and Max_Data = 0x7E */ void UTIL_LCD_DisplayChar(uint32_t Xpos, uint32_t Ypos, uint8_t Ascii) { DrawChar(Xpos, Ypos, &DrawProp[DrawProp->LcdLayer].pFont->table[(Ascii-' ') *\ DrawProp[DrawProp->LcdLayer].pFont->Height * ((DrawProp[DrawProp->LcdLayer].pFont->Width + 7) / 8)]); } 在这个函数中也只是将之前指定的字库设置好,继续交给DrawChar()函数执行,DrawChar函数如下: /** * @brief Draws a character on LCD. * @param Xpos Line where to display the character shape * @param Ypos Start column address * @param pData Pointer to the character data */ static void DrawChar(uint32_t Xpos, uint32_t Ypos, const uint8_t *pData) { uint32_t i = 0, j = 0, offset; uint32_t height, width; uint8_t *pchar; uint32_t line; height = DrawProp[DrawProp->LcdLayer].pFont->Height; width = DrawProp[DrawProp->LcdLayer].pFont->Width; uint16_t rgb565[24]; uint32_t argb8888[24]; offset = 8 *((width + 7)/8) - width ; for(i = 0; i < height; i++) { pchar = ((uint8_t *)pData + (width + 7)/8 * i); switch(((width + 7)/8)) { case 1: line = pchar[0]; break; case 2: line = (pchar[0]<< 8) | pchar[1]; break; case 3: default: line = (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2]; break; } if(DrawProp[DrawProp->LcdLayer].LcdPixelFormat == LCD_PIXEL_FORMAT_RGB565) { for (j = 0; j < width; j++) { if(line & (1 << (width- j + offset- 1))) { rgb565[j] = CONVERTARGB88882RGB565(DrawProp[DrawProp->LcdLayer].TextColor); } else { rgb565[j] = CONVERTARGB88882RGB565(DrawProp[DrawProp->LcdLayer].BackColor); } } UTIL_LCD_FillRGBRect(Xpos, Ypos++, (uint8_t*)&rgb565[0], width, 1); } else { for (j = 0; j < width; j++) { if(line & (1 << (width- j + offset- 1))) { argb8888[j] = DrawProp[DrawProp->LcdLayer].TextColor; } else { argb8888[j] = DrawProp[DrawProp->LcdLayer].BackColor; } } UTIL_LCD_FillRGBRect(Xpos, Ypos++, (uint8_t*)&argb8888[0], width, 1); } } } 在这个函数中,将字库中的字模逐个点交给写矩形的函数,在屏幕中“画”出字符来。 我好奇的是:为什么不使用画点的函数UTIL_LCD_SetPixel(),而使用画矩形的函数UTIL_LCD_FillRGBRect()? |
【福利三:逢7发帖赢大礼】使用arc弧形拉条控件控制PWM舵机及使用SPI3接口操作NRF24L01模块进行无线通信
STM32L562DK探索板——继续测试Audio
请教下STM32N6570 怎么把分辨率改成320x240并可以全屏显示
STM32L562DK探索板——初试显示汉字
【福利三:逢7发帖赢大礼】调试nucleo-WBA65RI工程测试样板的一些心得
【福利三:逢7发帖赢大礼】lv_timer和BME680实现温度、湿度、气压数据读取
STM32L562DK探索板——BSP项目的移植
【福利三:逢7发帖赢大礼】成功利用STM32H743VI片内SRAM12和DTCM空间(完全胜利)
【STM32U3评测】CANFD Bootloader(1)
【福利三:逢7发帖赢大礼】想要充分利用STM32H743VI片内的RAM空间(但并不顺利)
微信公众号
手机版