Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zi-done opened this issue Jul 28, 2022 · 1 comment

Comments

@zi-done
Copy link

zi-done commented Jul 28, 2022

SPI-TFT-LCD

@zi-done zi-done changed the title 为对于大小是12的英文字符显示是异常的呢 为什么对于大小是12的英文字符显示是异常的呢,16,24显示是正常的 Jul 28, 2022
@yuehunliren
Copy link

代码中忘记对大小是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);

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants