|
官方例程中显示不同大小的字符都是共用一个函数,即先指定字库、前景色和背景色,然后再将字符串及起始行列、对齐方式作为参数传送给字符串显示函数UTIL_LCD_DisplayStringAt(),如下图所示:% x4 b% B7 @) T8 h) E ^- B 5 m2 ~/ E# ?$ i9 H
! ^8 L* K6 u! b 在UTIL_LCD_DisplayStringAt()函数中也仅仅是处理好显示的起始位置后,依次将字符串逐个字符传递给后续函数UTIL_LCD_DisplayChar(refcolumn, Ypos, *Text)处理:
) l6 V9 @2 v( l, l! V 后续的DisplayChar()函数如下: /**$ s X& E5 n# v$ o* F1 L * @brief Displays one character in currently active layer.在当前活动层中显示一个字符。 * @param Xpos Start column address( M% |9 _. p/ l& ?" L5 l* S * @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)2 X9 T, F3 i8 W% b {1 E0 Q1 Y0 [8 @: f6 k4 j DrawChar(Xpos, Ypos, &DrawProp[DrawProp->LcdLayer].pFont->table[(Ascii-' ') *\) x u( x2 V; L2 ~/ E3 s; G DrawProp[DrawProp->LcdLayer].pFont->Height * ((DrawProp[DrawProp->LcdLayer].pFont->Width + 7) / 8)]);; a7 M! ^ W7 r" l: l) j }" r; I, g' N4 E6 z8 d 在这个函数中也只是将之前指定的字库设置好,继续交给DrawChar()函数执行,DrawChar函数如下: /**8 l; ~) o1 D* }6 h# x" a * @brief Draws a character on LCD. * @param Xpos Line where to display the character shape * @param Ypos Start column address- _( E! T2 b! i& @1 v% |' n. Y * @param pData Pointer to the character data$ X1 n' [4 I! b, Q/ { */6 N! B) W, w5 b- ]1 ]4 w static void DrawChar(uint32_t Xpos, uint32_t Ypos, const uint8_t *pData) { uint32_t i = 0, j = 0, offset;2 A0 c- A4 m2 B8 S X, U uint32_t height, width;4 e6 D" `' m; F2 Y) Z$ p* `! r uint8_t *pchar; uint32_t line; height = DrawProp[DrawProp->LcdLayer].pFont->Height; width = DrawProp[DrawProp->LcdLayer].pFont->Width; uint16_t rgb565[24];- V k: w- ?7 f* A1 h. `& o uint32_t argb8888[24];, q& i3 `2 |8 A9 S offset = 8 *((width + 7)/8) - width ; 0 J! [# |1 E7 b# V% n for(i = 0; i < height; i++) { pchar = ((uint8_t *)pData + (width + 7)/8 * i);3 g C9 y. p M& v( f+ \7 C switch(((width + 7)/8))$ j- @+ n6 t9 I. {. H% I4 Y; n% T7 Z { + Y b" A2 |8 V case 1: line = pchar[0];1 g* o( H4 ?) N0 t/ n4 d break; case 2:, A2 M& v7 a1 E2 O6 m line = (pchar[0]<< 8) | pchar[1]; break;4 i- m# A1 @- g7 u7 v. i 3 o7 f6 f, _! U3 q5 F g case 3:, b: U/ M; |+ t5 [2 W( r default: line = (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2]; break;& T3 o5 Y1 b# f1 l J' Y; C }" p! ^- \) l9 [- h Q" r $ P" K' Z( K& i if(DrawProp[DrawProp->LcdLayer].LcdPixelFormat == LCD_PIXEL_FORMAT_RGB565)3 Y/ {. J" y! y9 b- n; f+ b { for (j = 0; j < width; j++) { if(line & (1 << (width- j + offset- 1))); M0 g$ X5 [5 a Q' K0 K {# l2 o6 q: m$ _* H rgb565[j] = CONVERTARGB88882RGB565(DrawProp[DrawProp->LcdLayer].TextColor); }8 F- p- d+ A* P else {$ n' H( @) C: q3 n rgb565[j] = CONVERTARGB88882RGB565(DrawProp[DrawProp->LcdLayer].BackColor);7 Y$ S y5 A# ^ } } UTIL_LCD_FillRGBRect(Xpos, Ypos++, (uint8_t*)&rgb565[0], width, 1); } else/ \+ L0 Q7 B! u, T; o5 v, s { for (j = 0; j < width; j++) { if(line & (1 << (width- j + offset- 1)))6 r5 l& p/ y7 N8 G$ P( G { p: l! Z) I" v, ~ argb8888[j] = DrawProp[DrawProp->LcdLayer].TextColor;; S5 p7 p: O. [' K5 N }8 ^) M- v4 D8 C2 r* R# x: m% I else { z0 D" y# f- v5 I p argb8888[j] = DrawProp[DrawProp->LcdLayer].BackColor;8 p# c. l# w$ S' g5 N }# Y& O# R9 t3 u% X: ~* @' g; B5 s }! K+ X$ L! r3 Z UTIL_LCD_FillRGBRect(Xpos, Ypos++, (uint8_t*)&argb8888[0], width, 1); } } }6 P$ c6 \4 d( A$ [4 g2 M) A8 X3 L 9 A9 p& C! b9 t) O, G 在这个函数中,将字库中的字模逐个点交给写矩形的函数,在屏幕中“画”出字符来。% v1 O# V6 R5 k$ O, l1 Z8 F1 T$ _# h' I 我好奇的是:为什么不使用画点的函数UTIL_LCD_SetPixel(),而使用画矩形的函数UTIL_LCD_FillRGBRect()? ; ]) q# G C1 s, v: A& `# x) P |
STM32C543RC开发板Stop、Sleep和standby模式测试
【STM32C5教程】(10)LPUART DMA 通信实验
【STM32C5教程】(9)DAC 模拟量信号输出实验
【STM32C5教程】(8)ADC 模拟量数据采集实验
【STM32C5教程】(7)TIM1 互补 PWM 输出实验
【STM32C5教程】(6)定时器 PWM 输出实验
【STM32C5教程】(5)定时器周期中断实验
【STM32C5教程】(4)GPIO 外部中断实验
【STM32C5教程】(3)GPIO 按键输入实验
STM32C542RC开发板PWM呼吸灯及多功能按键实验
微信公众号
手机版