File indexing completed on 2025-05-11 08:22:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #include <bsp.h>
0037
0038 #include <stdlib.h>
0039 #include <stdio.h>
0040 #include "sed1356.h"
0041 #include "font8x16.h"
0042
0043 int mode900lq;
0044 long PIXELS_PER_ROW;
0045 long PIXELS_PER_COL;
0046 long COLS_PER_SCREEN;
0047 long ROWS_PER_SCREEN;
0048 long SED_HOR_PULSE_WIDTH_LCD;
0049 long SED_VER_PULSE_START_LCD;
0050 long SED_HOR_PULSE_START_LCD;
0051 long SED_HOR_NONDISP_LCD;
0052 long SED_VER_NONDISP_LCD;
0053 long SED_VER_PULSE_WIDTH_LCD;
0054
0055
0056 int sed_color_depth;
0057 int sed_fg_color;
0058 int sed_bg_color;
0059 int sed_col;
0060 int sed_row;
0061 int sed_disp_mode_crt;
0062 int sed135x_ok;
0063 int sed135x_tst;
0064 uint32_t sed_fb_offset;
0065
0066 void sed_writechar(uint8_t c);
0067 void sed_scroll(void);
0068
0069 #define SED_REG_BASE 0x30000000
0070 #define SED_MEM_BASE (SED_REG_BASE + 0x00200000)
0071 #define SED_STEP 1
0072
0073 #define SED_REG16(_x_) *(volatile uint16_t *)((uint32_t)SED_REG_BASE + (((uint32_t)_x_ * SED_STEP) ^ 0))
0074 #define RD_FB16(_reg_,_val_) ((_val_) = *((volatile uint16_t *)(((uint32_t)SED_MEM_BASE + ((uint32_t)(_reg_ * SED_STEP) ^ 0)))))
0075 #define WR_FB16(_reg_,_val_) (*((volatile uint16_t *)(((uint32_t)SED_MEM_BASE + ((uint32_t)(_reg_ * SED_STEP) ^ 0)))) = (_val_))
0076
0077 #if 0
0078 #define SED1356_REG_LCD_HOR_DISP SED_REG16(0x32)
0079 #define SED1356_REG_LCD_HOR_NONDISP_and_START SED_REG16(0x34)
0080 #define SED1356_REG_LCD_HOR_PULSE SED_REG16(0x36)
0081 #define SED1356_REG_LCD_VER_DISP_HT_LO_and_HI SED_REG16(0x38)
0082 #define SED1356_REG_LCD_VER_NONDISP_and_START SED_REG16(0x3a)
0083 #define SED1356_REG_LCD_VER_PULSE SED_REG16(0x3c)
0084 #define SED1356_REG_LCD_DISP_MODE_and_MISC SED_REG16(0x40)
0085 #define SED1356_REG_LCD_DISP_START_LO_and_MID SED_REG16(0x42)
0086 #define SED1356_REG_LCD_DISP_START_HI SED_REG16(0x44)
0087 #define SED1356_REG_LCD_ADD_OFFSET_LO_and_HI SED_REG16(0x46)
0088 #define SED1356_REG_LCD_PIXEL_PAN SED_REG16(0x48)
0089 #define SED1356_REG_LCD_FIFO_THRESH_LO_and_HI SED_REG16(0x4a)
0090 #endif
0091
0092
0093 #define H2SED(_x_) (_x_)
0094
0095 #define FB_SIZE (640 * 480)
0096 #define SED_ROW_SIZE(_depth_) ((PIXELS_PER_ROW * _depth_) / 8)
0097 #define SED_FB_SIZE(_depth_) (((PIXELS_PER_COL * PIXELS_PER_ROW) * _depth_) / 8)
0098
0099 #define FONT_WIDTH 8
0100 #define FONT_HEIGHT 16
0101
0102 #define SED_GET_ADD(_row_, _col_, _depth_) \
0103 (((((_row_ * PIXELS_PER_ROW) * FONT_HEIGHT) \
0104 + (_col_ * FONT_WIDTH)) \
0105 * _depth_) / 8)
0106
0107
0108 #define SED_GET_PHYS_ADD(_reg_) \
0109 (volatile unsigned long)(SED_MEM_BASE + ((_reg_ * SED_STEP) ^ 0))
0110
0111
0112 #include "sed1356_16bit.h"
0113
0114
0115 int sed135x_tst = 0;
0116
0117 void sed_write_frame_buffer(
0118 uint32_t i,
0119 uint16_t wr16
0120 )
0121 {
0122 WR_FB16(i, wr16);
0123 }
0124
0125 int sed_frame_buffer_size(void)
0126 {
0127 return SED_FB_SIZE(sed_color_depth);
0128 }
0129
0130 void sed_clr_row(int char_row)
0131 {
0132 unsigned long sed_mem_add;
0133 int i;
0134 uint16_t wr16;
0135
0136
0137 sed_mem_add = SED_GET_ADD(char_row, 0, sed_color_depth);
0138
0139 #ifdef SED_DBG
0140 sed135x_tst = 1;
0141 printf("SED Clear Row %d, FB Add 0x%08lx, CPU Add 0x%08lx.\n ", char_row, sed_mem_add, SED_GET_PHYS_ADD(sed_mem_add));
0142 sed135x_tst = 0;
0143 #endif
0144
0145 switch (sed_color_depth)
0146 {
0147 case 4:
0148 wr16 = ((sed_bg_color << 12) | (sed_bg_color << 8) | (sed_bg_color << 4) | (sed_bg_color << 0));
0149 #ifdef SED_DBG
0150 sed135x_tst = 1;
0151 printf("SED Clear Row %d, FB Add 0x%08lx to 0x%08lx.\n ", char_row, sed_mem_add, sed_mem_add + ((PIXELS_PER_ROW * FONT_HEIGHT) / 2));
0152 sed135x_tst = 0;
0153 #endif
0154 for (i = 0; i < ((PIXELS_PER_ROW * FONT_HEIGHT) / 2); i += 2){
0155 WR_FB16(sed_mem_add, wr16);
0156 sed_mem_add += 2;
0157 }
0158 break;
0159 case 8:
0160 wr16 = ((sed_bg_color << 8) | (sed_bg_color << 0));
0161 for (i = 0; i < (PIXELS_PER_ROW * FONT_HEIGHT); i += 2){
0162 WR_FB16(sed_mem_add, wr16);
0163 sed_mem_add += 2;
0164 }
0165 break;
0166 case 16:
0167 wr16 = ((vga_lookup[sed_bg_color]));
0168 for (i = 0; i < ((PIXELS_PER_ROW * FONT_HEIGHT) * 2); i += 2){
0169 WR_FB16(sed_mem_add, wr16);
0170 sed_mem_add += 2;
0171 }
0172 break;
0173 }
0174 }
0175
0176 void sed_init(void)
0177 {
0178 mode900lq = 0;
0179 PIXELS_PER_ROW = 640;
0180 PIXELS_PER_COL = 480;
0181 COLS_PER_SCREEN = 80;
0182 ROWS_PER_SCREEN = 30;
0183 SED_HOR_PULSE_WIDTH_LCD = 0x0b;
0184 SED_HOR_NONDISP_LCD = 0x13;
0185 SED_VER_PULSE_WIDTH_LCD = 0x01;
0186 SED_VER_PULSE_START_LCD = 0x09;
0187 SED_VER_NONDISP_LCD = 0x2c;
0188
0189 sed_color_depth = 16;
0190 sed_fg_color = 14;
0191 sed_bg_color = 1;
0192 sed_disp_mode_crt = 0;
0193 sed_fb_offset = 0x00;
0194 sed_row = 0;
0195 sed_col = 0;
0196
0197 sed135x_ok = 1;
0198 sed135x_tst = 0;
0199 sed_clearscreen();
0200 }
0201
0202
0203
0204
0205
0206
0207
0208 void sed_putchar(char c)
0209 {
0210
0211 if ((sed135x_ok == 0) || (sed135x_tst == 1)) return;
0212
0213
0214
0215
0216 switch (c) {
0217 case '\r':
0218 sed_col = 0;
0219 return;
0220 case '\n':
0221 sed_col = 0;
0222 sed_scroll();
0223 return;
0224 case '\b':
0225 sed_col--;
0226 if (sed_col < 0) {
0227 sed_row--;
0228 if (sed_row < 0)
0229 sed_row = 0;
0230 sed_col = COLS_PER_SCREEN - 1;
0231 }
0232 c = 0;
0233 sed_writechar(c);
0234 break;
0235 default:
0236 if (((uint8_t)c < FIRST_CHAR) || ((uint8_t)c > LAST_CHAR))
0237 return;
0238 c -= FIRST_CHAR;
0239 sed_writechar(c);
0240
0241 sed_col++;
0242 if (sed_col == COLS_PER_SCREEN) {
0243 sed_col = 0;
0244 sed_scroll();
0245 }
0246 break;
0247 }
0248
0249 }
0250
0251
0252
0253
0254
0255
0256
0257 void sed_writechar(uint8_t c)
0258 {
0259 uint32_t sed_mem_add;
0260 int font_row, font_col;
0261 uint8_t font_data8;
0262 uint16_t wr16;
0263
0264
0265
0266
0267 sed_mem_add = SED_GET_ADD(sed_row, sed_col, sed_color_depth);
0268
0269 #ifdef SED_DBG
0270 sed135x_tst = 1;
0271 printf("SED writechar at row %d, col %d, FB Add 0x%08lx, CPU Add 0x%08lx.\n ", sed_row, sed_col, sed_mem_add, SED_GET_PHYS_ADD(sed_mem_add));
0272 sed135x_tst = 0;
0273 #endif
0274
0275 if (FONT_WIDTH == 8) {
0276 switch (sed_color_depth) {
0277 case 4:
0278
0279 for (font_row = 0; font_row < FONT_HEIGHT; font_row++) {
0280
0281 font_data8 = font8x16[(c * FONT_HEIGHT) + font_row];
0282
0283
0284 for (font_col = 0; font_col < 8; font_col += 4)
0285 {
0286
0287 wr16 = (((font_data8 & 0x80) ? sed_fg_color << 12 : sed_bg_color << 12)
0288 | ((font_data8 & 0x40) ? sed_fg_color << 8 : sed_bg_color << 8)
0289 | ((font_data8 & 0x20) ? sed_fg_color << 4 : sed_bg_color << 4)
0290 | ((font_data8 & 0x10) ? sed_fg_color << 0 : sed_bg_color << 0));
0291 font_data8 = font_data8 << 4;
0292 WR_FB16(sed_mem_add, wr16);
0293
0294
0295
0296 if (sed_row > (ROWS_PER_SCREEN - 1)) {
0297 WR_FB16((sed_mem_add - SED_FB_SIZE(sed_color_depth)), wr16);
0298 }
0299 sed_mem_add += 2;
0300 }
0301
0302 sed_mem_add += (SED_ROW_SIZE(sed_color_depth) - ((FONT_WIDTH * sed_color_depth) / 8));
0303 }
0304 break;
0305
0306 case 8:
0307
0308 for (font_row = 0; font_row < FONT_HEIGHT; font_row++) {
0309
0310 font_data8 = font8x16[(c * FONT_HEIGHT) + font_row];
0311 for (font_col = 0; font_col < 8; font_col += 2)
0312 {
0313
0314 wr16 = (((font_data8 & 0x80) ? sed_fg_color << 8 : sed_bg_color << 8)
0315 | ((font_data8 & 0x40) ? sed_fg_color << 0 : sed_bg_color << 0));
0316 font_data8 = font_data8 << 2;
0317 WR_FB16(sed_mem_add, wr16);
0318
0319
0320
0321 if (sed_row > (ROWS_PER_SCREEN - 1)) {
0322 WR_FB16((sed_mem_add - SED_FB_SIZE(sed_color_depth)), wr16);
0323 }
0324 sed_mem_add += 2;
0325 }
0326
0327 sed_mem_add += (SED_ROW_SIZE(sed_color_depth) - ((FONT_WIDTH * sed_color_depth) / 8));
0328 }
0329 break;
0330
0331 case 16:
0332
0333 for (font_row = 0; font_row < FONT_HEIGHT; font_row++) {
0334
0335 font_data8 = font8x16[(c * FONT_HEIGHT) + font_row];
0336 for (font_col = 0; font_col < 8; font_col++)
0337 {
0338
0339 wr16 = ((font_data8 & 0x80) ?
0340 vga_lookup[sed_fg_color] : vga_lookup[sed_bg_color]);
0341 font_data8 = font_data8 << 1;
0342 WR_FB16(sed_mem_add, wr16);
0343
0344
0345
0346 if (sed_row > (ROWS_PER_SCREEN - 1)) {
0347 WR_FB16((sed_mem_add - SED_FB_SIZE(sed_color_depth)), wr16);
0348 }
0349 sed_mem_add += 2;
0350 }
0351
0352 sed_mem_add += (SED_ROW_SIZE(sed_color_depth) - ((FONT_WIDTH * sed_color_depth) / 8));
0353 }
0354 break;
0355
0356 }
0357 }
0358 else
0359 {
0360 return;
0361 }
0362 }
0363
0364 static void sed_update_fb_offset(void)
0365 {
0366
0367 if (sed_disp_mode_crt) {
0368
0369
0370
0371 if (SED1356_REG_DISP_MODE & H2SED(SED1356_DISP_MODE_CRT)) {
0372 while ((SED1356_REG_CRT_VER_NONDISP_and_START & H2SED(SED1356_VER_NONDISP)) == 0) {}
0373 while ((SED1356_REG_CRT_VER_NONDISP_and_START & H2SED(SED1356_VER_NONDISP)) == 1) {}
0374 }
0375 SED1356_REG_CRT_DISP_START_LO_and_MID = H2SED(((sed_fb_offset & 0x00ffff) >> 0));
0376 SED1356_REG_CRT_DISP_START_HI = H2SED(((sed_fb_offset & 0x070000) >> 16));
0377 }
0378 else
0379 {
0380 if (SED1356_REG_DISP_MODE & H2SED(SED1356_DISP_MODE_LCD)) {
0381 while ((SED1356_REG_LCD_VER_NONDISP_and_START & H2SED(SED1356_VER_NONDISP)) == 0) {}
0382 while ((SED1356_REG_LCD_VER_NONDISP_and_START & H2SED(SED1356_VER_NONDISP)) == 1) {}
0383 }
0384 SED1356_REG_LCD_DISP_START_LO_and_MID = H2SED(((sed_fb_offset & 0x00ffff) >> 0));
0385 SED1356_REG_LCD_DISP_START_HI = H2SED(((sed_fb_offset & 0x070000) >> 16));
0386 }
0387 }
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408 void sed_scroll(void)
0409 {
0410 sed_row++;
0411
0412
0413 sed_clr_row(sed_row);
0414 if (sed_row > (ROWS_PER_SCREEN - 1)) {
0415 sed_clr_row(sed_row - ROWS_PER_SCREEN);
0416 }
0417
0418
0419
0420
0421 if (sed_row > (ROWS_PER_SCREEN - 1)) {
0422 if (sed_row > ((ROWS_PER_SCREEN * 2) - 1)) {
0423 sed_fb_offset = 0x00;
0424 sed_row = 0;
0425 sed_clearscreen();
0426 } else {
0427
0428 sed_fb_offset += (SED_GET_ADD(1, 0, sed_color_depth) / 2);
0429 }
0430 sed_update_fb_offset();
0431 }
0432 }
0433
0434 void sed_putstring(char *s)
0435 {
0436 char *p = s;
0437 while (*p)
0438 sed_putchar(*p++);
0439 }
0440
0441 void sed_clearscreen(void)
0442 {
0443 int i;
0444 uint16_t wr16;
0445 int bg = sed_bg_color;
0446 int fbsize = sed_frame_buffer_size();
0447
0448
0449 fbsize *= 2;
0450
0451
0452 switch (sed_color_depth){
0453 case 4: wr16 = bg | bg << 4 | bg << 8 | bg << 12; break;
0454 case 8: wr16 = bg | bg << 8; break;
0455
0456 default: wr16 = vga_lookup[bg]; break;
0457 }
0458 for (i = 0; i < fbsize; i += 2){
0459 sed_write_frame_buffer(i, wr16);
0460 }
0461 }