|
官方例程中显示不同大小的字符都是共用一个函数,即先指定字库、前景色和背景色,然后再将字符串及起始行列、对齐方式作为参数传送给字符串显示函数UTIL_LCD_DisplayStringAt(),如下图所示: ' c0 P% n% f7 d. |
在UTIL_LCD_DisplayStringAt()函数中也仅仅是处理好显示的起始位置后,依次将字符串逐个字符传递给后续函数UTIL_LCD_DisplayChar(refcolumn, Ypos, *Text)处理:
后续的DisplayChar()函数如下: # Q% y2 ^6 C( n7 n8 ~ /** * @brief Displays one character in currently active layer.在当前活动层中显示一个字符。0 e, C& E( U3 z" v2 C* C" M * @param Xpos Start column address * @param Ypos Line where to display the character shape.1 [* h" f3 k! d* a# D * @param Ascii Character ascii code" |. y% r" p; U4 f. M: P * 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). E; Y0 l0 i/ b/ v: R6 F {+ `3 {0 |( ]% ?$ ` DrawChar(Xpos, Ypos, &DrawProp[DrawProp->LcdLayer].pFont->table[(Ascii-' ') *\ DrawProp[DrawProp->LcdLayer].pFont->Height * ((DrawProp[DrawProp->LcdLayer].pFont->Width + 7) / 8)]);4 N- s( `% j' f8 W } % f6 U1 e B8 _* T- V. i" B7 Z' {# e 在这个函数中也只是将之前指定的字库设置好,继续交给DrawChar()函数执行,DrawChar函数如下: /** * @brief Draws a character on LCD.$ a3 f1 n; P6 Y/ p% S M$ b# ^! A2 e * @param Xpos Line where to display the character shape/ A( u7 o& b1 a: z0 `2 y1 J * @param Ypos Start column address( [4 l* c; b" t; D1 ` * @param pData Pointer to the character data2 N! n9 k0 |7 j6 y; l- a0 C */ static void DrawChar(uint32_t Xpos, uint32_t Ypos, const uint8_t *pData)8 d* M1 P+ X9 E. C- d- U { uint32_t i = 0, j = 0, offset;1 q) ~, ?/ j% H. q, G uint32_t height, width; uint8_t *pchar;5 Y/ D: G' u& s; x \ uint32_t line; & M3 q1 v( a; q# B8 K1 B0 R height = DrawProp[DrawProp->LcdLayer].pFont->Height;6 o7 t" N: U2 d6 G7 u width = DrawProp[DrawProp->LcdLayer].pFont->Width; uint16_t rgb565[24];: I+ n0 C* y. s2 R; q, J uint32_t argb8888[24];0 C# n7 Z0 I- m, L7 e offset = 8 *((width + 7)/8) - width ; for(i = 0; i < height; i++)8 D& d6 C# p9 E. O {! v& I' b4 x5 U: P9 R) ? pchar = ((uint8_t *)pData + (width + 7)/8 * i); ! H$ E" M; x3 D' Y9 T switch(((width + 7)/8))* }/ u) V" G+ T: j {: K; k/ {% B; D s8 y( d4 A case 1: line = pchar[0];* x4 g# `& d$ g. ~, b7 l$ K6 u" |1 y break; case 2: line = (pchar[0]<< 8) | pchar[1]; break; , o$ q$ z% M( f/ [ case 3: default: line = (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2]; break;. C3 g4 C% X+ Q* K: [ K( m% d } if(DrawProp[DrawProp->LcdLayer].LcdPixelFormat == LCD_PIXEL_FORMAT_RGB565) { for (j = 0; j < width; j++)0 O0 U& F/ _; ~ { if(line & (1 << (width- j + offset- 1)))6 H0 C& a1 d" C7 i5 f; b {$ a0 {3 v( }6 C rgb565[j] = CONVERTARGB88882RGB565(DrawProp[DrawProp->LcdLayer].TextColor); }! W8 Q! a9 R _; W( d else5 W0 ]) _- S- t% X% U8 [ {( m3 j5 p* T: z: ` s6 I, n* v rgb565[j] = CONVERTARGB88882RGB565(DrawProp[DrawProp->LcdLayer].BackColor); } }4 I- A- E+ j$ V3 O UTIL_LCD_FillRGBRect(Xpos, Ypos++, (uint8_t*)&rgb565[0], width, 1); } else {6 F+ y' ^6 A7 }$ v$ B0 k4 X+ w for (j = 0; j < width; j++) { if(line & (1 << (width- j + offset- 1))) { argb8888[j] = DrawProp[DrawProp->LcdLayer].TextColor;9 a- W2 i. z$ o* g3 L }) \+ a6 H+ K5 v& k$ ` else: K+ `; ?: [9 B! o% r { argb8888[j] = DrawProp[DrawProp->LcdLayer].BackColor; } }5 ~$ L# R7 W8 N UTIL_LCD_FillRGBRect(Xpos, Ypos++, (uint8_t*)&argb8888[0], width, 1); }8 s" o* a2 g3 v0 B" {0 l$ @0 U }8 b! `4 ~2 E+ L: E9 v } ' v- W3 N3 x) B- g& ^: B! k; R0 W 在这个函数中,将字库中的字模逐个点交给写矩形的函数,在屏幕中“画”出字符来。 我好奇的是:为什么不使用画点的函数UTIL_LCD_SetPixel(),而使用画矩形的函数UTIL_LCD_FillRGBRect()? |
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 输出实验
微信公众号
手机版