zoukankan      html  css  js  c++  java
  • STM32F429--LTDC显示字符与图形

    硬件平台:正点原子阿波罗F429

    软件工具:STM32CubeMX 5.6.0

    开发IDE: SW4STM32

    首先在STM32CUBEMX配置SDRAM,DMA2D

    DMA2D 的用法
    DMA2D是AHB总线矩阵上的主设备,将图形数据传输到内存。建议使用DMA2D来为CPU减荷。
    DMA2D执行四项基本任务:
    • 填充独特颜色的矩形形状。
    • 将一帧或一帧的矩形部分从一个存储器复制到另一个存储器。
    • 转换一帧或一帧的矩形部分的像素格式,同时将其从一个存储器传输到另一个存储器。
    • 混合两种不同尺寸和像素格式的图像,并将结果图像存储在一个结果存储器中。

     使能DMA2D中断

     SDRAM 配置

    SDRAM芯片,型号为:W9825G6KH,容量为32M字节。该芯片挂在STM32F429的FMC接口上,有了这颗芯片,大大扩展了STM32的内存(本身只有256KB),在各种大内存需求场合,ALIENTEK这款STM32F429核心板,都可以从容面对

    SDRAM学习资料:

    SDRAM学习资料 - STM32F429 - 硬汉嵌入式论坛 - Powered by Discuz! (armbbs.cn)

    (7条消息) SDRAM学习笔记(eg. W9825G6KH)_Mculover666的博客(嵌入式)-CSDN博客_w9825g6kh

    (7条消息) 基于STM32F429的SDRAM使用_hducollins的博客-CSDN博客_w9825g6kh

    W9825G6KH-6共有4个Bank,13位行地址,9位列地址,位宽是16位,

    所以芯片的容量是:4x8192x512x16=256Mbits=32MBytes。

    STM32F429的FMC支持8/16/32位数据宽度,我们这里用到的LCD是16位宽度的,所以在设置的时候,选择16位宽就OK了。我们再来看看FMC的外部设备地址映像,STM32F429的FMC将外部存储器划分为6个固定大小为256M字节的存储区域,如图

    从上图可以看出,FMC总共管理1.5GB空间,拥有6个存储块(Bank),我们用到Bank5 也就是SDRAM Bank1,(0xC0000000 ~ 0xCFFFFFFF)

     

    FMC_D0~15:16位数据线;

    FMC_A0~12:13位地址线,行地址与列地址是公用的,作为行地址时使用了0~12位,作为列地址时使用了0~8位;

    FMC_SDNWE:低电平时写,高电平时读;

    FMC_SDNCAS:列地址选通信号,低电平有效;

    FMC_SDNRAS:行地址选通信号,低电平有效;

    FMC_SDNE0:片选信号,低电平有效;

    FMC_BA0~1:Bank选择信号;

    FMC_SDCKE0:时钟使能信号;

    FMC_SDCLK:时钟信号;

    FMC_NBL0~1:写访问的输出字节屏蔽

     Byte enable:表示可以通过LDQM,UDQM线控制访问8bit数据,还是16bit数据,UDQM/LDQM:数据掩码

     

     在stm32f4的数据手册有这么一句话"SDRAM clock can be HCLK/2 or HCLK/3" ,所以SDRAM的时钟最大为108MHz,所以对于SDRAM而言, 1tick = 9.26ns

     时钟树配置

     LTDC配置参考之前的笔记:

     STM32F429--LTDC显示图片 - M&D - 博客园 (cnblogs.com)

     同事需要需改配置的地方就是LCD缓存的地址

     配置PWM:PB5脚  10KHZ

    SDRAM的代码和LCD的代码可以参考 STM32CUBEMX的库文件:

     SDRAM初始化

     1 /* USER CODE BEGIN Private defines */
     2 #define SDRAM_DEVICE_ADDR         ((uint32_t)0xC0000000)
     3 /* USER CODE BEGIN PD */
     4 #define REFRESH_COUNT           ((uint32_t)683)   /* SDRAM refresh counter */
     5 #define SDRAM_TIMEOUT           ((uint32_t)0xFFFF)
     6 
     7 /**
     8   * @brief  FMC SDRAM Mode definition register defines
     9   */
    10 #define SDRAM_MODEREG_BURST_LENGTH_1             ((uint16_t)0x0000)
    11 #define SDRAM_MODEREG_BURST_LENGTH_2             ((uint16_t)0x0001)
    12 #define SDRAM_MODEREG_BURST_LENGTH_4             ((uint16_t)0x0002)
    13 #define SDRAM_MODEREG_BURST_LENGTH_8             ((uint16_t)0x0004)
    14 #define SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL      ((uint16_t)0x0000)
    15 #define SDRAM_MODEREG_BURST_TYPE_INTERLEAVED     ((uint16_t)0x0008)
    16 #define SDRAM_MODEREG_CAS_LATENCY_2              ((uint16_t)0x0020)
    17 #define SDRAM_MODEREG_CAS_LATENCY_3              ((uint16_t)0x0030)
    18 #define SDRAM_MODEREG_OPERATING_MODE_STANDARD    ((uint16_t)0x0000)
    19 #define SDRAM_MODEREG_WRITEBURST_MODE_PROGRAMMED ((uint16_t)0x0000)
    20 #define SDRAM_MODEREG_WRITEBURST_MODE_SINGLE     ((uint16_t)0x0200)
    21 
    22 
    23 /**
    24   * @brief  Programs the SDRAM device.
    25   * @param  RefreshCount: SDRAM refresh counter value
    26   */
    27 void BSP_SDRAM_Initialization_sequence(uint32_t RefreshCount)
    28 {
    29   __IO uint32_t tmpmrd =0;
    30 
    31   /* Step 1:  Configure a clock configuration enable command */
    32   Command.CommandMode             = FMC_SDRAM_CMD_CLK_ENABLE;
    33   Command.CommandTarget           = FMC_SDRAM_CMD_TARGET_BANK1;
    34   Command.AutoRefreshNumber       = 1;
    35   Command.ModeRegisterDefinition  = 0;
    36 
    37   /* Send the command */
    38   HAL_SDRAM_SendCommand(&hsdram1, &Command, SDRAM_TIMEOUT);
    39 
    40   /* Step 2: Insert 100 us minimum delay */
    41   /* Inserted delay is equal to 1 ms due to systick time base unit (ms) */
    42   HAL_Delay(1);
    43 
    44   /* Step 3: Configure a PALL (precharge all) command */
    45   Command.CommandMode             = FMC_SDRAM_CMD_PALL;
    46   Command.CommandTarget           = FMC_SDRAM_CMD_TARGET_BANK1;
    47   Command.AutoRefreshNumber       = 1;
    48   Command.ModeRegisterDefinition  = 0;
    49 
    50   /* Send the command */
    51   HAL_SDRAM_SendCommand(&hsdram1, &Command, SDRAM_TIMEOUT);
    52 
    53   /* Step 4: Configure an Auto Refresh command */
    54   Command.CommandMode             = FMC_SDRAM_CMD_AUTOREFRESH_MODE;
    55   Command.CommandTarget           = FMC_SDRAM_CMD_TARGET_BANK1;
    56   Command.AutoRefreshNumber       = 8;
    57   Command.ModeRegisterDefinition  = 0;
    58 
    59   /* Send the command */
    60   HAL_SDRAM_SendCommand(&hsdram1, &Command, SDRAM_TIMEOUT);
    61 
    62   /* Step 5: Program the external memory mode register */
    63   tmpmrd = (uint32_t)SDRAM_MODEREG_BURST_LENGTH_1          |
    64                      SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL   |
    65                      SDRAM_MODEREG_CAS_LATENCY_3           |
    66                      SDRAM_MODEREG_OPERATING_MODE_STANDARD |
    67                      SDRAM_MODEREG_WRITEBURST_MODE_SINGLE;
    68 
    69   Command.CommandMode             = FMC_SDRAM_CMD_LOAD_MODE;
    70   Command.CommandTarget           = FMC_SDRAM_CMD_TARGET_BANK1;
    71   Command.AutoRefreshNumber       = 1;
    72   Command.ModeRegisterDefinition  = tmpmrd;
    73 
    74   /* Send the command */
    75   HAL_SDRAM_SendCommand(&hsdram1, &Command, SDRAM_TIMEOUT);
    76 
    77   /* Step 6: Set the refresh rate counter */
    78   /* Set the device refresh rate */
    79   HAL_SDRAM_ProgramRefreshRate(&hsdram1, RefreshCount);
    80 }

    LCD 背光调节接口:

    1 void LCD_BL_PWM_Start(void)
    2 {
    3     HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);
    4 }
    5 
    6 void LCD_BL_PWM_SetVal(uint16_t value)
    7 {
    8     __HAL_TIM_SetCompare(&htim3,TIM_CHANNEL_2,value);
    9 }

    添加lcd.h和lcd.c都是参考库文件:

      1 #ifndef _LCD_H_
      2 #define _LCD_H_
      3 
      4 #include "ltdc.h"
      5 #include "dma2d.h"
      6 
      7 
      8 
      9 #define Dma2dHandler hdma2d
     10 #define LtdcHandler  hltdc
     11 
     12 #define  BSP_LCD_GetXSize() 480
     13 #define  BSP_LCD_GetYSize() 272
     14 
     15 #define LCD_DEFAULT_FONT         Font16
     16 
     17 
     18 /**
     19   * @brief  LCD status structure definition
     20   */
     21 #define MAX_LAYER_NUMBER       2
     22 #define LCD_FRAME_BUFFER       ((uint32_t)0xC0000000)
     23 #define BUFFER_OFFSET          ((uint32_t)0x50000)
     24 /**
     25   * @brief  LCD color
     26   */
     27 #define LCD_COLOR_BLUE          0xFF0000FF
     28 #define LCD_COLOR_GREEN         0xFF00FF00
     29 #define LCD_COLOR_RED           0xFFFF0000
     30 #define LCD_COLOR_CYAN          0xFF00FFFF
     31 #define LCD_COLOR_MAGENTA       0xFFFF00FF
     32 #define LCD_COLOR_YELLOW        0xFFFFFF00
     33 #define LCD_COLOR_LIGHTBLUE     0xFF8080FF
     34 #define LCD_COLOR_LIGHTGREEN    0xFF80FF80
     35 #define LCD_COLOR_LIGHTRED      0xFFFF8080
     36 #define LCD_COLOR_LIGHTCYAN     0xFF80FFFF
     37 #define LCD_COLOR_LIGHTMAGENTA  0xFFFF80FF
     38 #define LCD_COLOR_LIGHTYELLOW   0xFFFFFF80
     39 #define LCD_COLOR_DARKBLUE      0xFF000080
     40 #define LCD_COLOR_DARKGREEN     0xFF008000
     41 #define LCD_COLOR_DARKRED       0xFF800000
     42 #define LCD_COLOR_DARKCYAN      0xFF008080
     43 #define LCD_COLOR_DARKMAGENTA   0xFF800080
     44 #define LCD_COLOR_DARKYELLOW    0xFF808000
     45 #define LCD_COLOR_WHITE         0xFFFFFFFF
     46 #define LCD_COLOR_LIGHTGRAY     0xFFD3D3D3
     47 #define LCD_COLOR_GRAY          0xFF808080
     48 #define LCD_COLOR_DARKGRAY      0xFF404040
     49 #define LCD_COLOR_BLACK         0xFF000000
     50 #define LCD_COLOR_BROWN         0xFFA52A2A
     51 #define LCD_COLOR_ORANGE        0xFFFFA500
     52 #define LCD_COLOR_TRANSPARENT   0xFF000000
     53 
     54 typedef struct _tFont
     55 {
     56   const uint8_t *table;
     57   uint16_t Width;
     58   uint16_t Height;
     59 
     60 } sFONT;
     61 
     62 typedef struct
     63 {
     64   uint32_t  TextColor;
     65   uint32_t  BackColor;
     66   sFONT     *pFont;
     67 }LCD_DrawPropTypeDef;
     68 
     69 typedef struct
     70 {
     71   int16_t X;
     72   int16_t Y;
     73 } Point, * pPoint;
     74 
     75 /**
     76   * @brief  Line mode structures definition
     77   */
     78 typedef enum
     79 {
     80   CENTER_MODE             = 0x01,    /* center mode */
     81   RIGHT_MODE              = 0x02,    /* right mode  */
     82   LEFT_MODE               = 0x03,    /* left mode   */
     83 }Text_AlignModeTypdef;
     84 
     85 extern sFONT Font16;
     86 
     87 void BSP_LCD_Clear(uint32_t Color);
     88 void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t RGB_Code);
     89 void BSP_LCD_SetTextColor(uint32_t Color);
     90 void BSP_LCD_SetBackColor(uint32_t Color);
     91 void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length);
     92 void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length);
     93 void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
     94 void BSP_LCD_SetFont(sFONT *pFonts);
     95 sFONT *BSP_LCD_GetFont(void);
     96 void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii);
     97 void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr);
     98 void BSP_LCD_DisplayStringAt(uint16_t X, uint16_t Y, uint8_t *pText, Text_AlignModeTypdef mode);
     99 void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c);
    100 void FillBuffer(uint32_t LayerIndex, void * pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex);
    101 void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius);
    102 #endif

    lcd.c

      1 #include "lcd.h"
      2 
      3 sFONT Font16;
      4 uint32_t ActiveLayer = 0;
      5 static LCD_DrawPropTypeDef DrawProp[MAX_LAYER_NUMBER];
      6 
      7 /** @defgroup FONTS_Exported_Constants
      8   * @{
      9   */
     10 #define LINE(x) ((x) * (((sFONT *)BSP_LCD_GetFont())->Height))
     11 
     12 
     13 /**
     14   * @brief  Fills buffer.
     15   * @param  LayerIndex: layer index
     16   * @param  pDst: output color
     17   * @param  xSize: buffer width
     18   * @param  ySize: buffer height
     19   * @param  OffLine: offset
     20   * @param  ColorIndex: color Index
     21   */
     22 void FillBuffer(uint32_t LayerIndex, void * pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex)
     23 {
     24 
     25   /* Register to memory mode with ARGB8888 as color Mode */
     26   Dma2dHandler.Init.Mode         = DMA2D_R2M;
     27   Dma2dHandler.Init.ColorMode    = DMA2D_RGB565;
     28   Dma2dHandler.Init.OutputOffset = OffLine;
     29 
     30   Dma2dHandler.Instance = DMA2D;
     31 
     32   /* DMA2D Initialization */
     33   if(HAL_DMA2D_Init(&Dma2dHandler) == HAL_OK)
     34   {
     35     if(HAL_DMA2D_ConfigLayer(&Dma2dHandler, LayerIndex) == HAL_OK)
     36     {
     37       if (HAL_DMA2D_Start(&Dma2dHandler, ColorIndex, (uint32_t)pDst, xSize, ySize) == HAL_OK)
     38       {
     39         /* Polling For DMA transfer */
     40         HAL_DMA2D_PollForTransfer(&Dma2dHandler, 10);
     41       }
     42     }
     43   }
     44 }
     45 
     46 /**
     47   * @brief  Clears the hole LCD.
     48   * @param  Color: the color of the background
     49   */
     50 void BSP_LCD_Clear(uint32_t Color)
     51 {
     52   /* Clear the LCD */
     53   FillBuffer(ActiveLayer, (uint32_t *)(LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress), BSP_LCD_GetXSize(), BSP_LCD_GetYSize(), 0, Color);
     54 }
     55 
     56 /**
     57   * @brief  Writes Pixel.
     58   * @param  Xpos: the X position
     59   * @param  Ypos: the Y position
     60   * @param  RGB_Code: the pixel color in RGB565 mode (5-6-5)
     61   */
     62 void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t RGB_Code)
     63 {
     64   /* Write data value to all SDRAM memory */
     65   *(__IO uint32_t*) (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos))) = RGB_Code;
     66 }
     67 
     68 /**
     69   * @brief  Sets the Text color.
     70   * @param  Color: the Text color code ARGB(8-8-8-8)
     71   */
     72 void BSP_LCD_SetTextColor(uint32_t Color)
     73 {
     74   DrawProp[ActiveLayer].TextColor = Color;
     75 }
     76 
     77 /**
     78   * @brief  Sets the Background color.
     79   * @param  Color: the layer Background color code ARGB(8-8-8-8)
     80   */
     81 void BSP_LCD_SetBackColor(uint32_t Color)
     82 {
     83   DrawProp[ActiveLayer].BackColor = Color;
     84 }
     85 
     86 /**
     87   * @brief  Displays an horizontal line.
     88   * @param  Xpos: the X position
     89   * @param  Ypos: the Y position
     90   * @param  Length: line length
     91   */
     92 void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
     93 {
     94   uint32_t xaddress = 0;
     95 
     96   /* Get the line address */
     97   xaddress = (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 2*(BSP_LCD_GetXSize()*Ypos + Xpos);
     98 
     99   /* Write line */
    100   FillBuffer(ActiveLayer, (uint32_t *)xaddress, Length, 1, 0, DrawProp[ActiveLayer].TextColor);
    101 }
    102 
    103 /**
    104   * @brief  Displays a vertical line.
    105   * @param  Xpos: the X position
    106   * @param  Ypos: the Y position
    107   * @param  Length: line length
    108   */
    109 void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
    110 {
    111   uint32_t xaddress = 0;
    112 
    113   /* Get the line address */
    114   xaddress = (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 2*(BSP_LCD_GetXSize()*Ypos + Xpos);
    115 
    116   /* Write line */
    117   FillBuffer(ActiveLayer, (uint32_t *)xaddress, 1, Length, (BSP_LCD_GetXSize() - 1), DrawProp[ActiveLayer].TextColor);
    118 }
    119 
    120 /**
    121   * @brief  Displays a rectangle.
    122   * @param  Xpos: the X position
    123   * @param  Ypos: the Y position
    124   * @param  Height: display rectangle height
    125   * @param  Width: display rectangle width
    126   */
    127 void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
    128 {
    129   /* Draw horizontal lines */
    130   BSP_LCD_DrawHLine(Xpos, Ypos, Width);
    131   BSP_LCD_DrawHLine(Xpos, (Ypos+ Height), Width);
    132 
    133   /* Draw vertical lines */
    134   BSP_LCD_DrawVLine(Xpos, Ypos, Height);
    135   BSP_LCD_DrawVLine((Xpos + Width), Ypos, Height);
    136 }
    137 
    138 /**
    139   * @brief  Sets the Text Font.
    140   * @param  pFonts: the layer font to be used
    141   */
    142 void BSP_LCD_SetFont(sFONT *pFonts)
    143 {
    144   DrawProp[ActiveLayer].pFont = pFonts;
    145 }
    146 
    147 /**
    148   * @brief  Gets the Text Font.
    149   * @retval Layer font
    150   */
    151 sFONT *BSP_LCD_GetFont(void)
    152 {
    153   return DrawProp[ActiveLayer].pFont;
    154 }
    155 
    156 /**
    157   * @brief  Draws a character on LCD.
    158   * @param  Xpos: the Line where to display the character shape
    159   * @param  Ypos: start column address
    160   * @param  c: pointer to the character data
    161   */
    162 void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c)
    163 {
    164   uint32_t i = 0, j = 0;
    165   uint16_t height, width;
    166   uint8_t offset;
    167   uint8_t *pchar;
    168   uint32_t line=0;
    169 
    170   height = DrawProp[ActiveLayer].pFont->Height;
    171   width  = DrawProp[ActiveLayer].pFont->Width;
    172 
    173   offset = 8 *((width + 7)/8) -  width ;
    174 
    175   for(i = 0; i < height; i++)
    176   {
    177     pchar = ((uint8_t *)c + (width + 7)/8 * i);
    178 
    179     switch(((width + 7)/8))
    180     {
    181     case 1:
    182       line =  pchar[0];
    183       break;
    184 
    185     case 2:
    186       line =  (pchar[0]<< 8) | pchar[1];
    187       break;
    188 
    189     case 3:
    190     default:
    191       line =  (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2];
    192       break;
    193     }
    194 
    195     for (j = 0; j < width; j++)
    196     {
    197       if(line & (1 << (width- j + offset- 1)))
    198       {
    199         BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].TextColor);
    200       }
    201       else
    202       {
    203         BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].BackColor);
    204       }
    205     }
    206     Ypos++;
    207   }
    208 }
    209 
    210 /**
    211   * @brief  Displays one character.
    212   * @param  Xpos: start column address
    213   * @param  Ypos: the Line where to display the character shape
    214   * @param  Ascii: character ascii code, must be between 0x20 and 0x7E
    215   */
    216 void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii)
    217 {
    218   DrawChar(Xpos, Ypos, &DrawProp[ActiveLayer].pFont->table[(Ascii-' ') *
    219               DrawProp[ActiveLayer].pFont->Height * ((DrawProp[ActiveLayer].pFont->Width + 7) / 8)]);
    220 }
    221 
    222 /**
    223   * @brief  Displays a maximum of 20 char on the LCD.
    224   * @param  Line: the Line where to display the character shape
    225   * @param  ptr: pointer to string to display on LCD
    226   */
    227 void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr)
    228 {
    229   BSP_LCD_DisplayStringAt(0, LINE(Line), ptr, LEFT_MODE);
    230 }
    231 
    232 
    233 /**
    234   * @brief  Displays a maximum of 60 char on the LCD.
    235   * @param  X: pointer to x position (in pixel)
    236   * @param  Y: pointer to y position (in pixel)
    237   * @param  pText: pointer to string to display on LCD
    238   * @param  mode: The display mode
    239   *    This parameter can be one of the following values:
    240   *                @arg CENTER_MODE
    241   *                @arg RIGHT_MODE
    242   *                @arg LEFT_MODE
    243   */
    244 void BSP_LCD_DisplayStringAt(uint16_t X, uint16_t Y, uint8_t *pText, Text_AlignModeTypdef mode)
    245 {
    246   uint16_t refcolumn = 1, i = 0;
    247   uint32_t size = 0, xsize = 0;
    248   uint8_t  *ptr = pText;
    249 
    250   /* Get the text size */
    251   while (*ptr++) size ++ ;
    252 
    253   /* Characters number per line */
    254   xsize = (BSP_LCD_GetXSize()/DrawProp[ActiveLayer].pFont->Width);
    255 
    256   switch (mode)
    257   {
    258   case CENTER_MODE:
    259     {
    260       refcolumn = X+ ((xsize - size)* DrawProp[ActiveLayer].pFont->Width) / 2;
    261       break;
    262     }
    263   case LEFT_MODE:
    264     {
    265       refcolumn = X;
    266       break;
    267     }
    268   case RIGHT_MODE:
    269     {
    270       refcolumn = X + ((xsize - size)*DrawProp[ActiveLayer].pFont->Width);
    271       break;
    272     }
    273   default:
    274     {
    275       refcolumn = X;
    276       break;
    277     }
    278   }
    279 
    280   /* Send the string character by character on LCD */
    281   while ((*pText != 0) & (((BSP_LCD_GetXSize() - (i*DrawProp[ActiveLayer].pFont->Width)) & 0xFFFF) >= DrawProp[ActiveLayer].pFont->Width))
    282   {
    283     /* Display one character on LCD */
    284     BSP_LCD_DisplayChar(refcolumn, Y, *pText);
    285     /* Decrement the column position by 16 */
    286     refcolumn += DrawProp[ActiveLayer].pFont->Width;
    287     /* Point on the next character */
    288     pText++;
    289     i++;
    290   }
    291 }
    292 
    293 /**
    294   * @brief  Displays a circle.
    295   * @param  Xpos: the X position
    296   * @param  Ypos: the Y position
    297   * @param  Radius: the circle radius
    298   */
    299 void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
    300 {
    301   int32_t  d;/* Decision Variable */
    302   uint32_t  curx;/* Current X Value */
    303   uint32_t  cury;/* Current Y Value */
    304 
    305   d = 3 - (Radius << 1);
    306   curx = 0;
    307   cury = Radius;
    308 
    309   while (curx <= cury)
    310   {
    311     BSP_LCD_DrawPixel((Xpos + curx), (Ypos - cury), DrawProp[ActiveLayer].TextColor);
    312     BSP_LCD_DrawPixel((Xpos - curx), (Ypos - cury), DrawProp[ActiveLayer].TextColor);
    313     BSP_LCD_DrawPixel((Xpos + cury), (Ypos - curx), DrawProp[ActiveLayer].TextColor);
    314     BSP_LCD_DrawPixel((Xpos - cury), (Ypos - curx), DrawProp[ActiveLayer].TextColor);
    315     BSP_LCD_DrawPixel((Xpos + curx), (Ypos + cury), DrawProp[ActiveLayer].TextColor);
    316     BSP_LCD_DrawPixel((Xpos - curx), (Ypos + cury), DrawProp[ActiveLayer].TextColor);
    317     BSP_LCD_DrawPixel((Xpos + cury), (Ypos + curx), DrawProp[ActiveLayer].TextColor);
    318     BSP_LCD_DrawPixel((Xpos - cury), (Ypos + curx), DrawProp[ActiveLayer].TextColor);
    319 
    320     if (d < 0)
    321     {
    322       d += (curx << 2) + 6;
    323     }
    324     else
    325     {
    326       d += ((curx - cury) << 2) + 10;
    327       cury--;
    328     }
    329     curx++;
    330   }
    331 }

    字体库font16.c直接从库文件复制到工程

     main.c

     1 /* USER CODE END 0 */
     2 
     3 /**
     4   * @brief  The application entry point.
     5   * @retval int
     6   */
     7 int main(void)
     8 int main(void)
     9 {
    10   /* USER CODE BEGIN 1 */
    11 
    12   /* USER CODE END 1 */
    13 
    14   /* MCU Configuration--------------------------------------------------------*/
    15 
    16   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    17   HAL_Init();
    18   /* USER CODE BEGIN Init */
    19 
    20   /* USER CODE END Init */
    21 
    22   /* Configure the system clock */
    23   SystemClock_Config();
    24 
    25   /* USER CODE BEGIN SysInit */
    26 
    27   /* USER CODE END SysInit */
    28  /* Initialize all configured peripherals */
    29   MX_GPIO_Init();
    30   MX_USART1_UART_Init();
    31   MX_FMC_Init();
    32   MX_DMA2D_Init();
    33   MX_LTDC_Init();
    34   MX_TIM3_Init();
    35 
    36 
    37   /* Initialize interrupts */
    38   MX_NVIC_Init();
    39   /* USER CODE BEGIN 2 */
    40   //SDRAM Initialization
    41   //刷新频率计数器(以SDCLK频率计数),计算方法:
    42   //COUNT=SDRAM刷新周期/行数-20=SDRAM刷新周期(us)*SDCLK频率(Mhz)/行数
    43   //我们使用的SDRAM刷新周期为64ms,SDCLK=180/2=90Mhz,行数为8192(2^13).
    44   //所以,COUNT=64*1000*90/8192-20=683
    45   BSP_SDRAM_Initialization_sequence(REFRESH_COUNT);
    46 
    47   //LCD Background light
    48   LCD_BL_PWM_Start();
    49   LCD_BL_PWM_SetVal(0);
    50   HAL_Delay(500);
    51   LCD_BL_PWM_SetVal(100);
    52 
    53   //Clear LCD
    54   BSP_LCD_Clear(LCD_COLOR_BLUE);
    55 
    56   //Set text color
    57   BSP_LCD_SetTextColor(LCD_COLOR_RED);
    58 
    59   //draw Rectangle
    60   BSP_LCD_DrawRect(100,100,50,50);
    61 
    62  //draw line
    63   BSP_LCD_DrawHLine(150,150,100);
    64 
    65   //draw circle
    66   BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
    67   BSP_LCD_DrawCircle(200,200,50);
    68 
    69   //set font type
    70   BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
    71 
    72   //display string
    73   BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
    74   BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
    75   BSP_LCD_DisplayStringAt(0,0,(uint8_t*)"LCD TEST FONT",LEFT_MODE);
    76 
    77   /* USER CODE END 2 */
    78 
    79   /* Infinite loop */
    80   /* USER CODE BEGIN WHILE */
    81   while (1)
    82   {
    83     /* USER CODE END WHILE */
    84 
    85     /* USER CODE BEGIN 3 */
    86   }
    87   /* USER CODE END 3 */
    88 }

     

  • 相关阅读:
    SharePoint 2013 配置基于表单的身份认证
    SharePoint 2013 场解决方案包含第三方程序集
    SharePoint 2010 站点附加数据升级到SP2013
    SharePoint 2013 在母版页中插入WebPart
    SharePoint 2013 搭建负载均衡(NLB)
    SharePoint 部署解决方案Feature ID冲突
    SharePoint 2013 配置基于AD的Form认证
    SharePoint Server 2016 Update
    SharePoint 2013 为用户组自定义EventReceiver
    SharePoint 2013 JavaScript API 记录
  • 原文地址:https://www.cnblogs.com/mickey-double/p/14680844.html
Copyright © 2011-2022 走看看