📄 sed135x.c
字号:
SED1356_REG_MEM_CFG = SED1356_MEM_CFG_2CAS_EDO;
SED1356_REG_REF_RATE = SED1356_REF_RATE_2048;
SED1356_REG_MEM_TMG0 = SED1356_MEM_TMG0_EDO50_MCLK33;
SED1356_REG_MEM_TMG1 = SED1356_MEM_TMG1_EDO50_MCLK33;
SED1356_REG_PANEL_TYPE = SED1356_PANEL_TYPE_16 | SED1356_PANEL_TYPE_CLR | SED1356_PANEL_TYPE_TFT;
SED1356_REG_MOD_RATE = 0x00;
// LCD Specific Registers
SED1356_REG_LCD_HOR_DISP = (PIXELS_PER_ROW/8) - 1;
SED1356_REG_LCD_HOR_NONDISP = SED_HOR_NONDISP_LCD;
SED1356_REG_LCD_HOR_START = SED_HOR_PULSE_START_LCD;
SED1356_REG_LCD_HOR_PULSE = SED1356_PULSE_WID(SED_HOR_PULSE_WIDTH_LCD) | SED1356_PULSE_POL_LOW;
SED1356_REG_LCD_VER_DISP_HT_LO = (PIXELS_PER_COL - 1) & 0x0ff;
SED1356_REG_LCD_VER_DISP_HT_HI = ((PIXELS_PER_COL - 1) & 0x300) >> 8;
SED1356_REG_LCD_VER_NONDISP = SED_VER_NONDISP_LCD;
SED1356_REG_LCD_VER_START = SED_VER_PULSE_START_LCD;
SED1356_REG_LCD_VER_PULSE = SED1356_PULSE_WID(SED_VER_PULSE_WIDTH_LCD) | SED1356_PULSE_POL_LOW;
switch (sed_color_depth) {
case 4: SED1356_REG_LCD_DISP_MODE |= SED1356_LCD_DISP_BLANK | SED1356_LCD_DISP_SWIV_NORM | SED1356_LCD_DISP_4BPP; break;
case 8: SED1356_REG_LCD_DISP_MODE |= SED1356_LCD_DISP_BLANK | SED1356_LCD_DISP_SWIV_NORM | SED1356_LCD_DISP_8BPP; break;
default: SED1356_REG_LCD_DISP_MODE |= SED1356_LCD_DISP_BLANK | SED1356_LCD_DISP_SWIV_NORM | SED1356_LCD_DISP_16BPP; break;
}
SED1356_REG_LCD_MISC = 0x00;
SED1356_REG_LCD_DISP_START_LO = 0x00;
SED1356_REG_LCD_DISP_START_MID = 0x00;
SED1356_REG_LCD_DISP_START_HI = 0x00;
SED1356_REG_LCD_ADD_OFFSET_LO = (SED_ROW_SIZE(sed_color_depth) / 2) & 0x0ff;
SED1356_REG_LCD_ADD_OFFSET_HI = ((SED_ROW_SIZE(sed_color_depth) / 2) & 0x700) >> 8;
SED1356_REG_LCD_PIXEL_PAN = 0x00;
SED1356_REG_LCD_FIFO_HI_THRES = 0x00; // auto mode
SED1356_REG_LCD_FIFO_LO_THRES = 0x00;
// CRT Specific Registers
SED1356_REG_CRT_HOR_DISP = (PIXELS_PER_ROW/8) - 1;
SED1356_REG_CRT_HOR_NONDISP = SED_HOR_NONDISP_CRT;
SED1356_REG_CRT_HOR_START = SED_HOR_PULSE_START_CRT;
SED1356_REG_CRT_HOR_PULSE = SED1356_PULSE_WID(SED_HOR_PULSE_WIDTH_CRT) | SED1356_PULSE_POL_LOW;
SED1356_REG_CRT_VER_DISP_HT_LO = (PIXELS_PER_COL - 1) & 0x0ff;
SED1356_REG_CRT_VER_DISP_HT_HI = ((PIXELS_PER_COL - 1) & 0x300) >> 8;
SED1356_REG_CRT_VER_NONDISP = SED_VER_NONDISP_CRT;
SED1356_REG_CRT_VER_START = SED_VER_PULSE_START_CRT;
SED1356_REG_CRT_VER_PULSE = SED1356_PULSE_WID(SED_VER_PULSE_WIDTH_CRT) | SED1356_PULSE_POL_LOW;
switch (sed_color_depth) {
case 4: SED1356_REG_CRT_DISP_MODE |= SED1356_CRT_DISP_BLANK | SED1356_CRT_DISP_4BPP; break;
case 8: SED1356_REG_CRT_DISP_MODE |= SED1356_CRT_DISP_BLANK | SED1356_CRT_DISP_8BPP; break;
default: SED1356_REG_CRT_DISP_MODE |= SED1356_CRT_DISP_BLANK | SED1356_CRT_DISP_16BPP; break;
}
SED1356_REG_CRT_OUT_CTL = SED1356_CRT_OUT_DAC_LVL;
SED1356_REG_CRT_DISP_START_LO = 0x00;
SED1356_REG_CRT_DISP_START_MID = 0x00;
SED1356_REG_CRT_DISP_START_HI = 0x00;
SED1356_REG_CRT_ADD_OFFSET_LO = (SED_ROW_SIZE(sed_color_depth) / 2) & 0x0ff;
SED1356_REG_CRT_ADD_OFFSET_HI = ((SED_ROW_SIZE(sed_color_depth) / 2) & 0x700) >> 8;
SED1356_REG_CRT_PIXEL_PAN = 0x00;
SED1356_REG_CRT_FIFO_HI_THRES = 0x00; // auto mode
SED1356_REG_CRT_FIFO_LO_THRES = 0x00;
// Disable Cursor
SED1356_REG_LCD_CURSOR_CTL = 0x00;
// Disable BitBlt
SED1356_REG_BLT_CTL_0 = 0x00;
SED1356_REG_BLT_CTL_1 = 0x00;
SED1356_REG_BLT_ROP_CODE = 0x00;
SED1356_REG_BLT_OP = 0x00;
SED1356_REG_BLT_SRC_START_LO = 0x00;
SED1356_REG_BLT_SRC_START_MID = 0x00;
SED1356_REG_BLT_SRC_START_HI = 0x00;
SED1356_REG_BLT_DEST_START_LO = 0x00;
SED1356_REG_BLT_DEST_START_MID = 0x00;
SED1356_REG_BLT_DEST_START_HI = 0x00;
SED1356_REG_BLT_ADD_OFFSET_LO = 0x00;
SED1356_REG_BLT_ADD_OFFSET_HI = 0x00;
SED1356_REG_BLT_WID_LO = 0x00;
SED1356_REG_BLT_WID_HI = 0x00;
SED1356_REG_BLT_HGT_LO = 0x00;
SED1356_REG_BLT_HGT_HI = 0x00;
SED1356_REG_BLT_BG_CLR_LO = 0x00;
SED1356_REG_BLT_BG_CLR_HI = 0x00;
SED1356_REG_BLT_FG_CLR_LO = 0x00;
SED1356_REG_BLT_FG_CLR_HI = 0x00;
// Fill the LUT, write to both LCD and CRT luts simultaneously
SED1356_REG_LUT_MODE = 0x00;
for (i = 0; i < 256; i++){
SED1356_REG_LUT_ADD = i;
SED1356_REG_LUT_DATA = sed_lut[i][0]; // red
SED1356_REG_LUT_DATA = sed_lut[i][1]; // green
SED1356_REG_LUT_DATA = sed_lut[i][2]; // blue
}
// Disable Power Save Mode
SED1356_REG_PWR_CFG = 0x00;
// Set Watchdog
SED1356_REG_WATCHDOG_CTL = 0x00;
} // else sed1356
// initialize the globals
sed135x_ok = 1;
sed_fg_color = SED_FG_DEF;
sed_bg_color = SED_BG_DEF;
sed_row = 0;
sed_col = 0;
sed_fb_offset = 0x00;
// fill the screen with the background color, remember for the console driver
// we do double buffering, so fill twice as mush as the active screen size
switch (sed_color_depth){
case 4: temp16 = sed_bg_color | sed_bg_color << 4 | sed_bg_color << 8 | sed_bg_color << 12; break;
case 8: temp16 = sed_bg_color | sed_bg_color << 8; break;
default: temp16 = sed_bg_color; break;
}
for (i = 0; i < (PIXELS_PER_COL * PIXELS_PER_ROW) * 4; i += 2){
WR_FB16(i, temp16);
}
// turn on the display
sed135x_on();
return 0;
}
//--------------------------------------------------------------------------
// sed_pwr_dn()
void sed_pwr_dn(){
// Enable Host Access
SED1356_REG_MISC = 0x00;
// Disable the display
SED1356_REG_DISP_MODE = SED1356_DISP_SWIV_NORM | SED1356_DISP_MODE_OFF;
// Enable Power Save Mode
SED1356_REG_REF_RATE |= SED1356_REF_TYPE_SELF; // set dram to self refresh first
SED1356_REG_PWR_CFG |= SED1356_PWR_MCLK;
// Wait until power is down
while ((SED1356_REG_PWR_STAT & SED1356_PWR_MCLK) == 0){}
}
//--------------------------------------------------------------------------
// sed_tst()
//
// This test will initialize the SED135x, do a frame buffer
// test and then display 16 VGA colors full screen until stopped.
//
#define USAGE_STRING "-[cd:ln]"
#include "sed_tstHelp.c"
int sed_tst(int argc,char *argv[])
{
ushort wr16, rd16, temp16;
int i, x, opt;
ulong sed_fb_end;
int no_wait = 0;
char c;
if (sed135x_ok == 0) return -1;
sed135x_tst = 1;
sed135x_off();
while ((opt=getopt(argc,argv,"clnd:")) != -1) {
switch(opt) {
case 'l': // Override sed_disp_mode_crt, Run Test in LCD Mode
sed_disp_mode_crt = 0;
printf("Forcing LCD Mode!\n");
break;
case 'c': // Override sed_disp_mode_crt, Run Test in CRT Mode
sed_disp_mode_crt = 1;
printf("Forcing CRT Mode!\n");
break;
case 'd': // set the color depth
switch(*optarg) {
case '4':
sed_color_depth = 4;
printf("Forcing 4bpp Mode!\n");
break;
case '8':
sed_color_depth = 8;
printf("Forcing 8bpp Mode!\n");
break;
case '1':
sed_color_depth = 16;
printf("Forcing 16bpp Mode!\n");
break;
default: // test with current depth
break;
}
break;
case 'n': // no waiting fo keypress - fastest operation
no_wait = 1;
printf("No Keypress Mode, Must Reset System to Stop!\n");
break;
default: // test with current mode
break;
}
}
sed135x_init();
sed135x_on();
printf("Begin Frame Buffer R/W Test...");
// do an address=data read/write test on the frame buffer
// PIXELS_PER_COL * PIXELS_PER_ROW is the highest pixel.
// Multiply by bits_per_pixel (sed_color_depth), then
// divide by 8 to get the actual byte count.
for (i = 0; i < SED_FB_SIZE(sed_color_depth); i += 2){
WR_FB16(i, (i & 0xffff));
RD_FB16(i, rd16);
if(rd16 != (i & 0xffff)){
printf("Failed at 0x%08x, Wrote 0x%04x, Read 0x%04x!\n",SED_MEM_BASE + i, i, rd16);
return -1;
}
}
printf("Passed!\n");
printf("Frame Buffer Start: 0x%08lx, End 0x%08lx\n",SED_MEM_BASE, SED_MEM_BASE + SED_FB_SIZE(sed_color_depth));
if (no_wait)
{
printf("Begin Full Screen Color Test.\n");
while(1){
// fill the frame buffer with incrementing color values
for (x = 0; x < 16; x++){
switch (sed_color_depth){
case 4: wr16 = x | x << 4 | x << 8 | x << 12; break;
case 8: wr16 = x | x << 8; break;
default: wr16 = vga_lookup[x]; break; // 16-bits bypasses the lookup table
}
for (i = 0; i < SED_FB_SIZE(sed_color_depth); i += 2){
WR_FB16(i, wr16);
}
} // for x
} // while
} // no_wait
else
{
printf("Begin Full Screen Color Test, Press any key to end at current color.\n");
while(1){
// fill the frame buffer with incrementing color values
for (x = 0; x < 16; x++){
switch (sed_color_depth){
case 4: wr16 = x | x << 4 | x << 8 | x << 12; break;
case 8: wr16 = x | x << 8; break;
default: wr16 = vga_lookup[x]; break; // 16-bits bypasses the lookup table
}
for (i = 0; i < SED_FB_SIZE(sed_color_depth); i += 2){
WR_FB16(i, wr16);
}
if (no_wait == 0){
if (gotachar()) goto sed_tst_next;
}
} // for x
} // while
} // else no keycheck test
sed_tst_next:
sed135x_off();
sed135x_init();
sed135x_on();
return 0;
}
// sed_scroll()
//
// Because we are most likely running out of FLASH and probably also with
// cache disabled, a brute force memcpy of the whole screen would be very
// slow, even with reduced color depths. Instead, we define a frame buffer
// that is twice the size of our actual display. This does limit us to a
// 1Mbyte active display size, but 640 x 480 @ 16-bits/pixel = 614K so it
// works just fine. 800 x 600 can be had by reducing the color depth to
// 8-bits/pixel and using the look up tables.
//
// With the double buffering, we always write to the first buffer, even
// when the second buffer is active. This allows us to scroll by adjusting
// the starting and ending addresses in the SED135x by one row. When we
// reach the end of our virtual buffer, we reset the starting and ending
// addresses to the first buffer. Note that we can not adjust the SED135x
// registers until it is in vertical retrace. That means we have to wait
// until it is in active display, then goes to non-display, unless the
// screen is blanked, in which case we can update immediately.
//
ulong sed_scroll(){
ushort temp16;
sed_row++;
// clear the new row(s)
sed_clr_row(sed_row);
if (sed_row >= (ROWS_PER_SCREEN - 1)){
sed_clr_row(sed_row - ROWS_PER_SCREEN);
}
// when sed_y_pos is greater than ROWS_PER_SCREEN we just adjust the
// start and end addresses in the SED135x. If it is equal to 2 *
// ROWS_PER_SCREEN, we reset the start and end addresses to SED_MEM_BASE.
if (sed_row > (ROWS_PER_SCREEN - 1))
{
if (sed_row > ((ROWS_PER_SCREEN * 2) - 1))
{
sed_fb_offset = 0x00;
sed_row = ROWS_PER_SCREEN - 1;
}
else
{
// calculate the new offset address of the frame buffer in words
sed_fb_offset += (SED_GET_ADD(1, 0, sed_color_depth) / 2);
}
// write the new sed_fb_offset value
if (sed1355)
{
SED1355_REG_DISP1_START_LO = ((sed_fb_offset & 0x0000ff) >> 0);
SED1355_REG_DISP1_START_MID = ((sed_fb_offset & 0x00ff00) >> 8);
SED1355_REG_DISP1_START_HI = ((sed_fb_offset & 0x030000) >> 16);
}
else // sed1356
{
#if 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -