lcd.c
来自「国产CPU-龙芯(loongson)BIOS源代码」· C语言 代码 · 共 198 行
C
198 行
#include <types.h>#include <lcd.h>#include <font.h>#include <lcd_pix.h> /* test pixmap here */#include <lcd_pix1.h>#define DELAY 1000/* font variable */static FONTS *lcd_font = NULL;void lcd_test(){ int buf_size = 224*320/8; int status = 0; int ctrl = 0; int counter = DELAY; serial_puts("It is a 32-bit SOC platform based on GODSON-1\n"); /* Fill the two Buffers */ Fill_lcd_Buffer((void *)SD_LCD_BARA_BASE, (void *)lcd_test_pixmap, buf_size); Fill_lcd_Buffer((void *)SD_LCD_BARB_BASE, (void *)lcd_test_pixmap, buf_size); init_lcd_regs(); while (1) { status = LCD_GET32(REG_LCD_STAT); ctrl = LCD_GET32(REG_LCD_CTRL); if (status & LCD_NO_DATA_FOLLOW) { ctrl &= ~0x1; LCD_SET32(REG_LCD_CTRL, ctrl); if (counter > (DELAY >> 1)) { Fill_lcd_Buffer((void *)SD_LCD_BARA_BASE, (void *)lcd_test_pixmap, buf_size); Fill_lcd_Buffer((void *)SD_LCD_BARB_BASE, (void *)lcd_test_pixmap, buf_size); } else { Fill_lcd_Buffer((void *)SD_LCD_BARA_BASE, (void *)lcd_test_pixmap1, buf_size); Fill_lcd_Buffer((void *)SD_LCD_BARB_BASE, (void *)lcd_test_pixmap1, buf_size); } init_lcd_regs(); counter = DELAY; continue; } if (status & LCD_FRAME_SWITCH) { if (status & LCD_FRAME_A) { if (counter > (DELAY >> 1)) Fill_lcd_Buffer((void *)SD_LCD_BARA_BASE, (void *)lcd_test_pixmap, buf_size); else Fill_lcd_Buffer((void *)SD_LCD_BARA_BASE, (void *)lcd_test_pixmap1, buf_size); } else { if (counter > (DELAY >> 1)) Fill_lcd_Buffer((void *)SD_LCD_BARB_BASE, (void *)lcd_test_pixmap, buf_size); else Fill_lcd_Buffer((void *)SD_LCD_BARB_BASE, (void *)lcd_test_pixmap1, buf_size); } LCD_SET32(REG_LCD_STAT, status | LCD_FRAME_SWITCH); LCD_SET32(REG_LCD_CTRL, ctrl | LCD_INT_RESET); } counter--; if (!counter) { serial_puts("It is a 32-bit SOC platform based on GODSON-1\n"); counter = DELAY; } }}void init_lcd(){ init_lcd_regs(); lcd_font = get_font_by_name("default");}void init_lcd_regs(){ LCD_SET32(REG_LCD_VBARa, SD_LCD_BARA_BASE); LCD_SET32(REG_LCD_VBARb, SD_LCD_BARB_BASE); LCD_SET32(REG_LCD_HTIM, 0x020200df); LCD_SET32(REG_LCD_VTIM, 0x0000013f); /* LCD_SET32(REG_LCD_HTIM, 0x0000003f); LCD_SET32(REG_LCD_VTIM, 0x0000002f); */ LCD_SET32(REG_LCD_HVLEN, 0x00020000); LCD_SET32(REG_LCD_CTRL, 0x000201a9);}void Fill_lcd_Buffer(volatile void *to, volatile void *from, int size){ int i = 0; for (i = 0; i < size; i += 4) { KSEG1_STORE32(to, *(u32 *)from); to += 4; from += 4; }}/* Only work on font size equal 8x16 */void lcd_print_char(FONTS *pft, char c, u32 x, u32 y){ u32 ft_size = 0; void *ft_base = NULL; u32 tmp1,tmp2,tmp3=0,tmp4; u8 *first,*second; u8 *firstB,*secondB; int i,n; int status = 0; u32 bara_base; ft_base = pft->font_base + c*(pft->length*pft->width)/8; for (n=0;n<pft->width;n++) { tmp1 = ((x+n)*224 + y)/8; tmp2 = ((x+n)*224 + y)%8; first = (u8 *)(KSEG1(SD_LCD_BARA_BASE) + tmp1); second = (u8 *)(KSEG1(SD_LCD_BARA_BASE) + tmp1) + 1; firstB = (u8 *)(KSEG1(SD_LCD_BARB_BASE) + tmp1); secondB = (u8 *)(KSEG1(SD_LCD_BARB_BASE) + tmp1) + 1; for (i=0;i<pft->length;i++) tmp3 |= ((((u8 *)ft_base)[i] >> (7-n)) & 0x1) << i; if (tmp2 == 0) { first[0] = firstB[0] = tmp3 & 0xff; second[0] = secondB[0] = (tmp3 >> 8) & 0xff; } else { first[0] = firstB[0] = (tmp3 << tmp2) & 0xff; second[0] = secondB[0] = (tmp3 >> (8 - tmp2)) & 0xff; } }}void lcd_prints(char *str){ int i = 0; u32 x = 0, y = 0; for (i=0;i<strlen(str);i++) { switch (str[i]) { case '\n': y+=lcd_font->length; x = 0; break; case '\t': if ((320-x)/(4*lcd_font->width)) { lcd_print_char(lcd_font, 0, x, y); x+=lcd_font->width; lcd_print_char(lcd_font, 0, x, y); x+=lcd_font->width; lcd_print_char(lcd_font, 0, x, y); x+=lcd_font->width; lcd_print_char(lcd_font, 0, x, y); x+=lcd_font->width; if (320-x < lcd_font->width) { y += lcd_font->length; x = 0; } } else { x = 0; y+=lcd_font->length; } break; case ' ': lcd_print_char(lcd_font, 0, x, y); x+=lcd_font->width; if (320-x < lcd_font->width) { y += lcd_font->length; x = 0; } break; default: lcd_print_char(lcd_font, str[i], x, y); x+=lcd_font->width; if (320-x < lcd_font->width) { y += lcd_font->length; x = 0; } } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?