📄 lcd.c.svn-base
字号:
ushort *red, ushort *green, ushort *blue);static int lcd_getfgcolor (void);#endif /* NOT_USED_SO_FAR *//************************************************************************//*----------------------------------------------------------------------*/static void console_scrollup (void){#if 1 /* Copy up rows ignoring the first one */ memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE); /* Clear the last one */ memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);#else /* * Poor attempt to optimize speed by moving "long"s. * But the code is ugly, and not a bit faster :-( */ ulong *t = (ulong *)CONSOLE_ROW_FIRST; ulong *s = (ulong *)CONSOLE_ROW_SECOND; ulong l = CONSOLE_SCROLL_SIZE / sizeof(ulong); uchar c = lcd_color_bg & 0xFF; ulong val= (c<<24) | (c<<16) | (c<<8) | c; while (l--) *t++ = *s++; t = (ulong *)CONSOLE_ROW_LAST; l = CONSOLE_ROW_SIZE / sizeof(ulong); while (l-- > 0) *t++ = val;#endif}/*----------------------------------------------------------------------*/static inline void console_back (void){ if (--console_col < 0) { console_col = CONSOLE_COLS-1 ; if (--console_row < 0) { console_row = 0; } } lcd_putc_xy (console_col * VIDEO_FONT_WIDTH, console_row * VIDEO_FONT_HEIGHT, ' ');}/*----------------------------------------------------------------------*/static inline void console_newline (void){ ++console_row; console_col = 0; /* Check if we need to scroll the terminal */ if (console_row >= CONSOLE_ROWS) { /* Scroll everything up */ console_scrollup () ; --console_row; }}/*----------------------------------------------------------------------*/void lcd_putc (const char c){ if (!lcd_is_enabled) { serial_putc(c); return; } switch (c) { case '\r': console_col = 0; return; case '\n': console_newline(); return; case '\t': /* Tab (8 chars alignment) */ console_col |= 8; console_col &= ~7; if (console_col >= CONSOLE_COLS) { console_newline(); } return; case '\b': console_back(); return; default: lcd_putc_xy (console_col * VIDEO_FONT_WIDTH, console_row * VIDEO_FONT_HEIGHT, c); if (++console_col >= CONSOLE_COLS) { console_newline(); } return; } /* NOTREACHED */}/*----------------------------------------------------------------------*/void lcd_puts (const char *s){ if (!lcd_is_enabled) { serial_puts (s); return; } while (*s) { lcd_putc (*s++); }}/************************************************************************//* ** Low-Level Graphics Routines *//************************************************************************/static void lcd_drawchars (ushort x, ushort y, uchar *str, int count){ uchar *dest; ushort off, row; dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8); off = x * (1 << LCD_BPP) % 8; for (row=0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) { uchar *s = str; uchar *d = dest; int i;#if LCD_BPP == LCD_MONOCHROME uchar rest = *d & -(1 << (8-off)); uchar sym;#endif for (i=0; i<count; ++i) { uchar c, bits; c = *s++; bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];#if LCD_BPP == LCD_MONOCHROME sym = (COLOR_MASK(lcd_color_fg) & bits) | (COLOR_MASK(lcd_color_bg) & ~bits); *d++ = rest | (sym >> off); rest = sym << (8-off);#elif LCD_BPP == LCD_COLOR8 for (c=0; c<8; ++c) { *d++ = (bits & 0x80) ? lcd_color_fg : lcd_color_bg; bits <<= 1; }#endif }#if LCD_BPP == LCD_MONOCHROME *d = rest | (*d & ((1 << (8-off)) - 1));#endif }}/*----------------------------------------------------------------------*/static inline void lcd_puts_xy (ushort x, ushort y, uchar *s){#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO) lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen (s));#else lcd_drawchars (x, y, s, strlen (s));#endif}/*----------------------------------------------------------------------*/static inline void lcd_putc_xy (ushort x, ushort y, uchar c){#if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO) lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1);#else lcd_drawchars (x, y, &c, 1);#endif}/************************************************************************//** Small utility to check that you got the colours right *//************************************************************************/#ifdef LCD_TEST_PATTERN#define N_BLK_VERT 2#define N_BLK_HOR 3static int test_colors[N_BLK_HOR*N_BLK_VERT] = { CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW, CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,};static void test_pattern (void){ ushort v_max = panel_info.vl_row; ushort h_max = panel_info.vl_col; ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT; ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR; ushort v, h; uchar *pix = (uchar *)lcd_base; printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n", h_max, v_max, h_step, v_step); /* WARNING: Code silently assumes 8bit/pixel */ for (v=0; v<v_max; ++v) { uchar iy = v / v_step; for (h=0; h<h_max; ++h) { uchar ix = N_BLK_HOR * iy + (h/h_step); *pix++ = test_colors[ix]; } }}#endif /* LCD_TEST_PATTERN *//************************************************************************//* ** GENERIC Initialization Routines *//************************************************************************/int drv_lcd_init (void){ DECLARE_GLOBAL_DATA_PTR; device_t lcddev; int rc; lcd_base = (void *)(gd->fb_base); lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8; lcd_init (lcd_base); /* LCD initialization */ /* Device initialization */ memset (&lcddev, 0, sizeof (lcddev)); strcpy (lcddev.name, "lcd"); lcddev.ext = 0; /* No extensions */ lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */ lcddev.putc = lcd_putc; /* 'putc' function */ lcddev.puts = lcd_puts; /* 'puts' function */ rc = device_register (&lcddev); return (rc == 0) ? 1 : rc;}/*----------------------------------------------------------------------*/int lcd_init (void *lcdbase){ /* Initialize the lcd controller */ debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase); lcd_ctrl_init (lcdbase);#if LCD_BPP == LCD_MONOCHROME /* Setting the palette */ lcd_initcolregs();#elif LCD_BPP == LCD_COLOR8 /* Setting the palette */ lcd_setcolreg (CONSOLE_COLOR_BLACK, 0, 0, 0); lcd_setcolreg (CONSOLE_COLOR_RED, 0xFF, 0, 0); lcd_setcolreg (CONSOLE_COLOR_GREEN, 0, 0xFF, 0); lcd_setcolreg (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0); lcd_setcolreg (CONSOLE_COLOR_BLUE, 0, 0, 0xFF); lcd_setcolreg (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF); lcd_setcolreg (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF); lcd_setcolreg (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA); lcd_setcolreg (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);#endif#ifndef CFG_WHITE_ON_BLACK lcd_setfgcolor (CONSOLE_COLOR_BLACK); lcd_setbgcolor (CONSOLE_COLOR_WHITE);#else lcd_setfgcolor (CONSOLE_COLOR_WHITE); lcd_setbgcolor (CONSOLE_COLOR_BLACK);#endif /* CFG_WHITE_ON_BLACK */#ifdef LCD_TEST_PATTERN test_pattern();#else /* set framebuffer to background color */ memset ((char *)lcd_base, COLOR_MASK(lcd_getbgcolor()), lcd_line_length*panel_info.vl_row);#endif lcd_enable (); /* Paint the logo and retrieve LCD base address */ debug ("[LCD] Drawing the logo...\n"); lcd_console_address = lcd_logo (); /* Initialize the console */ console_col = 0;#ifdef LCD_INFO_BELOW_LOGO console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;#else console_row = 1; /* leave 1 blank line below logo */#endif lcd_is_enabled = 1; return 0;}/************************************************************************//* ** ROM capable initialization part - needed to reserve FB memory *//************************************************************************//* * This is called early in the system initialization to grab memory * for the LCD controller. * Returns new address for monitor, after reserving LCD buffer memory * * Note that this is running from ROM, so no write access to global data. */ulong lcd_setmem (ulong addr){ ulong size; int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8; debug ("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) ); size = line_length * panel_info.vl_row; /* Round up to nearest full page */ size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1); /* Allocate pages for the frame buffer. */ addr -= size; debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr); return (addr);}/************************************************************************//* ----------------- chipset specific functions ----------------------- *//************************************************************************/static void lcd_ctrl_init (void *lcdbase){ volatile immap_t *immr = (immap_t *) CFG_IMMR; volatile lcd823_t *lcdp = &immr->im_lcd; uint lccrtmp; uint lchcr_hpc_tmp; /* Initialize the LCD control register according to the LCD * parameters defined. We do everything here but enable * the controller. */ lccrtmp = LCDBIT (LCCR_BNUM_BIT, (((panel_info.vl_row * panel_info.vl_col) * (1 << LCD_BPP)) / 128)); lccrtmp |= LCDBIT (LCCR_CLKP_BIT, panel_info.vl_clkp) | LCDBIT (LCCR_OEP_BIT, panel_info.vl_oep) | LCDBIT (LCCR_HSP_BIT, panel_info.vl_hsp) | LCDBIT (LCCR_VSP_BIT, panel_info.vl_vsp) | LCDBIT (LCCR_DP_BIT, panel_info.vl_dp) | LCDBIT (LCCR_BPIX_BIT, panel_info.vl_bpix) | LCDBIT (LCCR_LBW_BIT, panel_info.vl_lbw) | LCDBIT (LCCR_SPLT_BIT, panel_info.vl_splt) | LCDBIT (LCCR_CLOR_BIT, panel_info.vl_clor) | LCDBIT (LCCR_TFT_BIT, panel_info.vl_tft);#if 0 lccrtmp |= ((SIU_LEVEL5 / 2) << 12); lccrtmp |= LCCR_EIEN;#endif lcdp->lcd_lccr = lccrtmp; lcdp->lcd_lcsr = 0xFF; /* Clear pending interrupts */ /* Initialize LCD controller bus priorities. */#ifdef CONFIG_RBC823 immr->im_siu_conf.sc_sdcr = (immr->im_siu_conf.sc_sdcr & ~0x0f) | 1; /* RAID = 01, LAID = 00 */#else immr->im_siu_conf.sc_sdcr &= ~0x0f; /* RAID = LAID = 0 */ /* set SHFT/CLOCK division factor 4 * This needs to be set based upon display type and processor * speed. The TFT displays run about 20 to 30 MHz. * I was running 64 MHz processor speed. * The value for this divider must be chosen so the result is * an integer of the processor speed (i.e., divide by 3 with * 64 MHz would be bad). */ immr->im_clkrst.car_sccr &= ~0x1F; immr->im_clkrst.car_sccr |= LCD_DF; /* was 8 */#endif /* CONFIG_RBC823 */#if defined(CONFIG_RBC823) /* Enable LCD on port D. */ immr->im_ioport.iop_pddat &= 0x0300; immr->im_ioport.iop_pdpar |= 0x1CFF; immr->im_ioport.iop_pddir |= 0x1CFF; /* Configure LCD_ON, VEE_ON, CCFL_ON on port B. */ immr->im_cpm.cp_pbdat &= ~0x00005001; immr->im_cpm.cp_pbpar &= ~0x00005001; immr->im_cpm.cp_pbdir |= 0x00005001;#elif !defined(CONFIG_EDT32F10) /* Enable LCD on port D. */ immr->im_ioport.iop_pdpar |= 0x1FFF; immr->im_ioport.iop_pddir |= 0x1FFF; /* Enable LCD_A/B/C on port B. */ immr->im_cpm.cp_pbpar |= 0x00005001; immr->im_cpm.cp_pbdir |= 0x00005001;#else /* Enable LCD on port D. */ immr->im_ioport.iop_pdpar |= 0x1DFF; immr->im_ioport.iop_pdpar &= ~0x0200; immr->im_ioport.iop_pddir |= 0x1FFF; immr->im_ioport.iop_pddat |= 0x0200;#endif /* Load the physical address of the linear frame buffer * into the LCD controller. * BIG NOTE: This has to be modified to load A and B depending * upon the split mode of the LCD. */ lcdp->lcd_lcfaa = (ulong)lcd_base; lcdp->lcd_lcfba = (ulong)lcd_base; /* MORE HACKS...This must be updated according to 823 manual * for different panels. * Udi Finkelstein - done - see below: * Note: You better not try unsupported combinations such as * 4-bit wide passive dual scan LCD at 4/8 Bit color.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -