官方例程中显示不同大小的字符都是共用一个函数,即先指定字库、前景色和背景色,然后再将字符串及起始行列、对齐方式作为参数传送给字符串显示函数UTIL_LCD_DisplayStringAt(),如下图所示:
( _0 }4 D1 K4 w 在UTIL_LCD_DisplayStringAt()函数中也仅仅是处理好显示的起始位置后,依次将字符串逐个字符传递给后续函数UTIL_LCD_DisplayChar(refcolumn, Ypos, *Text)处理:
. f9 H! `# z. `4 G, s" K 后续的DisplayChar()函数如下: X, X4 g1 H: L9 M7 @8 S; v# ~ /** * @brief Displays one character in currently active layer.在当前活动层中显示一个字符。+ v8 t$ U" n* P1 V' _* f * @param Xpos Start column address * @param Ypos Line where to display the character shape. * @param Ascii Character ascii code2 T9 s+ N# p; v * This parameter must be a number between Min_Data = 0x20 and Max_Data = 0x7E */4 {, ]3 Q( {1 n' h void UTIL_LCD_DisplayChar(uint32_t Xpos, uint32_t Ypos, uint8_t Ascii)6 T0 V4 F( V1 P+ v! ]) z$ U {+ y R b* s: {0 \1 C V DrawChar(Xpos, Ypos, &DrawProp[DrawProp->LcdLayer].pFont->table[(Ascii-' ') *\- z5 g0 ^% U8 q( u DrawProp[DrawProp->LcdLayer].pFont->Height * ((DrawProp[DrawProp->LcdLayer].pFont->Width + 7) / 8)]);! W1 d3 ^2 s; E }2 x8 Z( M4 y5 c6 q8 @3 w9 U, Z9 C4 s / m- e# i+ Z g$ v 在这个函数中也只是将之前指定的字库设置好,继续交给DrawChar()函数执行,DrawChar函数如下: / H/ b; H4 B% }$ ~6 P3 Z) l /** * @brief Draws a character on LCD.' _8 F- z! h/ E1 o' C9 C * @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;4 P# N/ G+ t# y @& I uint32_t line;. o$ W- C9 V9 r, ?8 r7 C1 S' p height = DrawProp[DrawProp->LcdLayer].pFont->Height;. h a! H, h2 D+ O5 p width = DrawProp[DrawProp->LcdLayer].pFont->Width; uint16_t rgb565[24];4 T) h1 b2 d2 a4 O! f# T0 h/ | uint32_t argb8888[24];% B4 C" F, @5 A8 W- A+ Z offset = 8 *((width + 7)/8) - width ; for(i = 0; i < height; i++) {$ c- b1 o2 E+ d pchar = ((uint8_t *)pData + (width + 7)/8 * i); m8 Z" Q! I& V9 ^2 n) o! T switch(((width + 7)/8)): O2 C/ W; b) x& I- Z9 \8 j {3 R3 p" `9 D$ K, M- d$ ? ' v5 D. n: M! [1 r4 a" x case 1: line = pchar[0]; break; # K8 _ j" }. I4 R; m- y case 2: line = (pchar[0]<< 8) | pchar[1]; break; 3 {/ T1 R! J# [ ]. t case 3: default: line = (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2];4 `6 _. T1 I1 W% z+ W break; }) N! p- H6 }7 M* s$ i. K+ N" ] if(DrawProp[DrawProp->LcdLayer].LcdPixelFormat == LCD_PIXEL_FORMAT_RGB565) {9 r: Q4 l$ i( H; x% U5 G2 Z for (j = 0; j < width; j++) { if(line & (1 << (width- j + offset- 1)))! O' [) ]# w+ | {# W5 o! Z# M& q+ x( E) \% o" e rgb565[j] = CONVERTARGB88882RGB565(DrawProp[DrawProp->LcdLayer].TextColor);) x8 j# r" G0 x9 ?6 T5 X } else! Z X* m3 H M q A! S" V {/ E3 C: l" x4 d( D rgb565[j] = CONVERTARGB88882RGB565(DrawProp[DrawProp->LcdLayer].BackColor);) n* F, f3 h' e% v! H3 {( m8 t } }- y' o, e! y) J% [# x- J. a! W9 A UTIL_LCD_FillRGBRect(Xpos, Ypos++, (uint8_t*)&rgb565[0], width, 1);( m6 {: F/ }) P6 p# ~ } else { for (j = 0; j < width; j++) { Z4 U7 i# x1 C. E if(line & (1 << (width- j + offset- 1))), Z" x! v7 f+ `1 x { argb8888[j] = DrawProp[DrawProp->LcdLayer].TextColor; }- d+ i8 q2 q/ H5 M else { argb8888[j] = DrawProp[DrawProp->LcdLayer].BackColor;; k E8 e; z- j' R8 m }3 M, y! X6 y! j" I+ w }% d- x, V2 g. J0 [6 {- B5 k6 y7 |3 G UTIL_LCD_FillRGBRect(Xpos, Ypos++, (uint8_t*)&argb8888[0], width, 1);/ l: i+ L/ t9 I; H }: W$ z) L) S1 j2 E7 L( o- r }9 j m7 n3 \' T E }; P8 U3 r9 w) r7 t _ ' Z- D- N% j1 b, ]# R 在这个函数中,将字库中的字模逐个点交给写矩形的函数,在屏幕中“画”出字符来。8 s% g" u0 c) ?8 Q; F: n: U 我好奇的是:为什么不使用画点的函数UTIL_LCD_SetPixel(),而使用画矩形的函数UTIL_LCD_FillRGBRect()?' L b; g4 Z' d U& U7 S- W6 I |
STM32C542RC开发板ADC转换实验
STM32C542RC开发板I2C通讯实验——AT24C32的读写操作
STM32C542RC开发板I2C通讯实验
STM32C542RC开发板启用SPI驱动TFT显示屏
STM32C542RC开发板驱动TFT显示屏
【STM32C5教程】(9)DAC 模拟量信号输出实验
STM32C542RC开发板Stop、Sleep和standby模式测试
【STM32C5教程】(10)LPUART DMA 通信实验
【STM32C5教程】(8)ADC 模拟量数据采集实验
【STM32C5教程】(7)TIM1 互补 PWM 输出实验
微信公众号
手机版