HAL_Driver_Lib icon indicating copy to clipboard operation
HAL_Driver_Lib copied to clipboard

为什么对于大小是12的英文字符显示是异常的呢,16,24显示是正常的

Open zi-done opened this issue 2 years ago • 1 comments

SPI-TFT-LCD

zi-done avatar Jul 28 '22 02:07 zi-done

代码中忘记对大小是12的分支添加break,导致代码有问题,并且此份代码只对16大小有用。12 24 32大小的显示都是异常, 修改后可以正常使用 void lcd_draw_char(uint16_t x, uint16_t y, char ch, uint8_t font_size) { uint16_t i, j; uint16_t font_total_bytes, font_width, font_height; uint8_t *font_ptr; uint8_t bit_width, temp; uint16_t back_color, fore_color;

if((x > (LCD_WIDTH - font_size / 2)) || (y > (LCD_HEIGHT - font_size)))	{
    return;
}

font_width = font_size / 2;
font_height = font_size;
font_total_bytes = (font_width / 8 + ((font_width % 8) ? 1 : 0)) * font_height;
ch = ch - ' ';
back_color = s_lcd_color_params.background_color;
fore_color = s_lcd_color_params.foreground_color;

switch (font_size) {
    case 12:
        bit_width = 6;
        font_ptr = (uint8_t*)&asc2_1206[0] + ch * 12;
        break;
    case 16:
        bit_width = 8;
        font_ptr = (uint8_t*)&asc2_1608[0] + ch * 16;
        break;
    case 24:
        font_ptr = (uint8_t*)&asc2_2412[0] + ch * 48;
        break;
    case 32:
        bit_width = 8;
        font_ptr = (uint8_t*)&asc2_3216[0] + ch * 128;
        break;
    default:
        return;
}
lcd_address_set(x, y, x+font_width-1, y+font_height-1);
lcd->cs(0);
lcd->dc(1);
for (i = 0; i < font_total_bytes; i++) {
    temp = *(font_ptr + i);
    if (font_size == 24) {
        bit_width = (i % 2 == 0) ? 8 : 4;
    }
    for (j = 0; j < bit_width; j++) {
        if(temp & 0x80){
            lcd_write_color(fore_color);
        } else {
            lcd_write_color(back_color);

        }
        temp <<= 1;
    }
}
lcd->cs(1);

}

yuehunliren avatar Jan 25 '24 07:01 yuehunliren