Stm32 SPFD5420A TFT LCD screen debugging font rotation

 Stm32 SPFD5420A TFT LCD screen debugging font rotation   

Use the built-in LCD screen of the Anfulai development board to make the fonts rotate with the rotation of the screen like the fonts on the mobile phone screen
Obtained by modifying the algorithm in the LCD driver code of the Anfulai development board

The following code is the modified algorithm:

/*
************************************************* ***************************************************** *****
* Function name: LCD_DispStr
* Function description: Display a character string at the specified coordinates (upper left corner) of the LCD
* Formal parameters:
* _usX: X coordinate, for 3.0-inch widescreen, the range is [0 - 399]
* _usY: Y coordinate, for 3.0-inch widescreen, the range is [0 - 239]
* _ptr: string pointer
* _tFont: font structure, including parameters such as color, background color (transparent), font code, text spacing, etc.
* Return Value: None
*********************************************** ***************************************************** *********
*/
void LCD_DispStr(uint16_t _usX, uint16_t _usY, char *_ptr, FONT_T *_tFont,uint8_t direction_flag)
{
 uint8_t num = 1;
 uint32_t i;
 uint8_t code1;
 uint8_t code2;
 uint32_t address;
 uint8_t buf[24 * 24 / 8]; /* supports up to 24 dot matrix Chinese characters*/
 uint8_t m, width, height;
 uint16_t x, y;
 /* Temporarily only supports 16 dot matrix Song type Chinese characters*/
 if (_tFont->usFontCode == FC_ST_16X16)
 {
  height = 16;
  while (*_ptr != 0)
  {
   code1 = *_ptr; /* height of ascii code or Chinese character code byte */
   if (code1 < 0x80)
   {
    /* copy ascii character matrix to buf */
    memcpy(buf, &g_Ascii16[code1 * 16], 16);
    width = 8;
   }
   else
   {
    code2 = *++_ptr ;
    if (code2 == 0)
    {
     break;
    }
    /* Calculate 16 dot matrix Chinese character dot matrix address
     ADDRESS = [(code1-0xa1) * 94 + (code2-0xa1)] * 32
     ;
    */
    #ifdef USE_SMALL_FONT
     m = 0;
     while(1)
     {
      address = m* 34;
      m++;
      if(num == 0)
      {
       if ((code1 == g_Hz16_lie[address + 0]) && (code2 == g_Hz16_lie[address + 1]))
       {
        address += 2;
        memcpy(buf, &g_Hz16_lie[address] , 32);
        break;
       }
       else if ((g_Hz16_lie[address + 0] == 0xFF) && (g_Hz16_lie[address + 1] == 0xFF))
       {
        /* After searching the font library, if not found, fill in all FF */
        memset(buf, 0xFF, 32);
        break;
       }
      }
      else
      {
       if ((code1 == g_Hz16[address + 0]) && (code2 == g_Hz16[ address + 1]))
       {
        address += 2;
        memcpy(buf, &g_Hz16[address], 32);
        break;
       }
       else if ((g_Hz16[address + 0] == 0xFF) && (g_Hz16[address + 1] = = 0xFF))
       {
        /* After searching the font library, if not found, fill in all FF */
        memset(buf, 0xFF, 32);
        break;
       }  
      }
     }
     width = 16;
    #else
     address = ((code1-0xa1) * 94 + (code2-0xa1)) * 32 + HZK16_ADDR;
     memcpy(buf, (const uint8_t *)address, 32);
    #endif
     width = 16;
   }
   
   if (direction_flag == 0) //Words are displayed from left to right
   {
    y = _usY; //Give y-axis coordinates to y
    /* start to brush LCD */
    for (m = 0; m < height; m++) / / character height
    {
     x = _usX;
     for (i = 0; i < width; i++) // character width
     {
      if ((buf[m * (width / 8) + i / 8] & (0x80 >> (i % 8))) != 0x00)
      {
       LCD_PutPixel(x, y, _tFont->usTextColor); // Set the pixel color to the text color, that is, put dots on the screen}
      else
      if (_tFont->usBackColor != CL_MASK) /* If it is a color mask value, then do Transparency processing*/
      {
       LCD_PutPixel(x, y, _tFont->usBackColor); /* set the pixel color as text background color*/;
      }
      x++; //Dots from left to right, hit width
     }
     y++; //Move one coordinate down (x moves 16 from left to right, y moves 1 from top to bottom) } }
    if
   (
   
   direction_flag == 1 )
   {
    x = _usX; //Give the x-axis coordinates to x
    /* start to brush LCD */
    for (m = 0; m < height; m++) /* character height*/
    {
     
     y = _usY;
     for (i = 0 ; i < width; i++) /* character width*/
     {  
      if ((buf[m * (width / 8) + i / 8] & (0x80 >> (i % 8))) != 0x00) {
      LCD_PutPixel
       ( x, y, _tFont->usTextColor); /* Set pixel color to text color*/ }
      else
      if (_tFont->usBackColor != CL_MASK) /* If it is a color mask value, it will be transparent*/
      {
       LCD_PutPixel(x, y, _tFont->usBackColor); /* Set the pixel color as the text background color*/;
      }
      
      y++;//Dot from top to bottom, hit width
     }
     x--; //Move one to the left Coordinates (y is 16 from top to bottom, x is 1 from right to left)
    }
   }
   
   if(direction_flag == 2)
   {
    x = _usX;//Give x-axis coordinates to x
    /* start to brush LCD */
    for (m = 0; m < height; m++) /* character height*/
    {
     y = _usY;
     for (i = 0; i < width; i++) /* character width*/ {
     if
      ((buf[m * (width / 8 ) + i / 8] & (0x80 >> (i % 8))) != 0x00)
      {
       LCD_PutPixel(x, y, _tFont->usTextColor); /* set pixel color to text color*/
      }
      else if (_tFont->usBackColor != CL_MASK) /* If it is a color mask value, then do transparent processing*/ {
      LCD_PutPixel
       (x, y, _tFont->usBackColor); /* Set the pixel color as the text background color* /;
      }
      y--; //dot y from bottom to top, hit y
     }
     x++; //move one coordinate to the right, (16 coordinates from bottom to top for y, 1 coordinate for x from left to right)
    }
   }
   if (_tFont->usBackColor != CL_MASK && _tFont->usSpace > 0)
   {
    /* If the background color of the text is _tFont->usBackColor, and the character spacing is greater than the width of the dot matrix, then it needs to be filled between the text (not yet Realize) */
   }
   
   if(direction_flag == 0)
   {
    _usX += width + _tFont->usSpace; //Font order is displayed from left to right
    _ptr++; /* point to the next character*/
   }
   if(direction_flag == 1)
   {
    _usY += width + _tFont->usSpace; //The font order is displayed from top to
    bottom_ptr++; /* point to the next character*/
   }
   
   if(direction_flag == 2)
   {
    _usY -= width - _tFont->usSpace; //Font order is displayed from bottom to top
    _ptr++; /* Point to the next character*/
   }
   
  }
 }
 else
 {
  /* Other fonts are not supported temporarily*/
  return;
 }
}

Guess you like

Origin blog.csdn.net/qq_27568125/article/details/54602718