1.1 --- a/stage2/lcd.c Thu Jun 29 23:26:39 2017 +0200
1.2 +++ b/stage2/lcd.c Sat Jul 08 21:06:58 2017 +0200
1.3 @@ -25,34 +25,35 @@
1.4 #include "board.h"
1.5
1.6 extern vidinfo_t panel_info;
1.7 -static unsigned long lcd_base;
1.8 +extern struct jzfb_info jzfb;
1.9 +static uint32_t lcd_base;
1.10
1.11 -static unsigned int get_line_length()
1.12 +static uint16_t get_line_length()
1.13 {
1.14 - return ALIGN((panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8, sizeof(uint32_t));
1.15 + return ALIGN((panel_info.jz_fb->w * panel_info.jz_fb->bpp) / 8, sizeof(uint32_t));
1.16 }
1.17
1.18 -static uint32_t *get_pixel32(unsigned short h, unsigned short v)
1.19 +static uint32_t *get_pixel32(uint16_t h, uint16_t v)
1.20 {
1.21 return (uint32_t *) (lcd_base + v * get_line_length()) + h;
1.22 }
1.23
1.24 -static uint16_t *get_pixel16(unsigned short h, unsigned short v)
1.25 +static uint16_t *get_pixel16(uint16_t h, uint16_t v)
1.26 {
1.27 return (uint16_t *) (lcd_base + v * get_line_length()) + h;
1.28 }
1.29
1.30 -static uint8_t *get_pixel8(unsigned short h, unsigned short v)
1.31 +static uint8_t *get_pixel8(uint16_t h, uint16_t v)
1.32 {
1.33 return (uint8_t *) (lcd_base + v * get_line_length()) + h;
1.34 }
1.35
1.36 -static uint8_t *get_pixel4(unsigned short h, unsigned short v)
1.37 +static uint8_t *get_pixel4(uint16_t h, uint16_t v)
1.38 {
1.39 return (uint8_t *) (lcd_base + v * get_line_length()) + h / 2;
1.40 }
1.41
1.42 -static inline unsigned short div(unsigned short num, unsigned short denom, unsigned short scale)
1.43 +static inline uint16_t div(uint16_t num, uint16_t denom, uint16_t scale)
1.44 {
1.45 return (scale * num) / denom;
1.46 }
1.47 @@ -62,69 +63,69 @@
1.48 return (div(r, 255, rmax) << rshift) | (div(g, 255, gmax) << gshift) | (div(b, 255, bmax) << bshift);
1.49 }
1.50
1.51 -uint32_t get_bitmap_value(unsigned short x, uint32_t value)
1.52 +uint32_t get_bitmap_value(uint16_t x, uint32_t value)
1.53 {
1.54 - return (value >> (((panel_info.vl_col - 1 - x) * 32) / panel_info.vl_col)) % 2 ? 0xffffffff : 0;
1.55 + return (value >> (((panel_info.jz_fb->w - 1 - x) * 32) / panel_info.jz_fb->w)) % 2 ? 0xffffffff : 0;
1.56 }
1.57
1.58 -static void get_colour(unsigned short h, unsigned short v, uint8_t rgb[], unsigned short pixel_type)
1.59 +static void get_colour(uint16_t h, uint16_t v, uint8_t rgb[], uint16_t pixel_type)
1.60 {
1.61 - unsigned short v_max = panel_info.vl_row - 1;
1.62 - unsigned short h_max = panel_info.vl_col - 1;
1.63 + uint16_t v_max = panel_info.jz_fb->h - 1;
1.64 + uint16_t h_max = panel_info.jz_fb->w - 1;
1.65
1.66 rgb[(pixel_type - 1) % 3] = div(h, h_max, 255);
1.67 rgb[pixel_type % 3] = div(v, v_max, 255);
1.68 rgb[(pixel_type + 1) % 3] = (rgb[0] + rgb[1]) / 2;
1.69 }
1.70
1.71 -static void set_pixel32(unsigned short h, unsigned short v, uint32_t value)
1.72 +static void set_pixel32(uint16_t h, uint16_t v, uint32_t value)
1.73 {
1.74 uint32_t *pix = get_pixel32(h, v);
1.75 *pix = value;
1.76 }
1.77
1.78 -static void set_pixel16_565(unsigned short h, unsigned short v, uint32_t value)
1.79 +static void set_pixel16_565(uint16_t h, uint16_t v, uint32_t value)
1.80 {
1.81 uint16_t *pix = get_pixel16(h, v);
1.82 *pix = (uint16_t) value;
1.83 }
1.84
1.85 -static void set_pixel8(unsigned short h, unsigned short v, uint32_t value)
1.86 +static void set_pixel8(uint16_t h, uint16_t v, uint32_t value)
1.87 {
1.88 uint8_t *pix = get_pixel8(h, v);
1.89 *pix = (uint8_t) value;
1.90 }
1.91
1.92 -static void set_pixel4(unsigned short h, unsigned short v, uint32_t value)
1.93 +static void set_pixel4(uint16_t h, uint16_t v, uint32_t value)
1.94 {
1.95 uint8_t *pix = get_pixel4(h, v);
1.96 uint8_t mask = h & 1 ? 0xf0 : 0x0f;
1.97 *pix = (*pix & mask) | ((uint8_t) value);
1.98 }
1.99
1.100 -void set_pixel(unsigned short h, unsigned short v, uint32_t value)
1.101 +void set_pixel(uint16_t h, uint16_t v, uint32_t value)
1.102 {
1.103 - switch (panel_info.vl_bpix)
1.104 + switch (panel_info.jz_fb->bpp)
1.105 {
1.106 - case LCD_COLOR32:
1.107 + case 32:
1.108 set_pixel32(h, v, value);
1.109 break;
1.110
1.111 - case LCD_COLOR8:
1.112 + case 8:
1.113 set_pixel8(h, v, value);
1.114 break;
1.115
1.116 - case LCD_COLOR4:
1.117 + case 4:
1.118 set_pixel4(h, v, value);
1.119 break;
1.120
1.121 - case LCD_COLOR16:
1.122 + case 16:
1.123 default:
1.124 set_pixel16_565(h, v, value);
1.125 break;
1.126 }
1.127 }
1.128 -static void test_pixel32(unsigned short h, unsigned short v, unsigned short pixel_type)
1.129 +static void test_pixel32(uint16_t h, uint16_t v, uint16_t pixel_type)
1.130 {
1.131 uint8_t rgb[3];
1.132
1.133 @@ -132,7 +133,7 @@
1.134 set_pixel32(h, v, pixel(rgb[0], rgb[1], rgb[2], 255, 255, 255, 16, 8, 0) | get_bitmap_value(h, pixel_type));
1.135 }
1.136
1.137 -static void test_pixel16_565(unsigned short h, unsigned short v, unsigned short pixel_type)
1.138 +static void test_pixel16_565(uint16_t h, uint16_t v, uint16_t pixel_type)
1.139 {
1.140 uint8_t rgb[3];
1.141
1.142 @@ -140,7 +141,7 @@
1.143 set_pixel16_565(h, v, pixel(rgb[0], rgb[1], rgb[2], 31, 63, 31, 11, 5, 0) | get_bitmap_value(h, pixel_type));
1.144 }
1.145
1.146 -static void test_pixel8(unsigned short h, unsigned short v, unsigned short pixel_type)
1.147 +static void test_pixel8(uint16_t h, uint16_t v, uint16_t pixel_type)
1.148 {
1.149 uint8_t rgb[3];
1.150
1.151 @@ -148,7 +149,7 @@
1.152 set_pixel8(h, v, pixel(rgb[0], rgb[1], rgb[2], 7, 7, 3, 5, 2, 0) | get_bitmap_value(h, pixel_type));
1.153 }
1.154
1.155 -static void test_pixel4(unsigned short h, unsigned short v, unsigned short pixel_type)
1.156 +static void test_pixel4(uint16_t h, uint16_t v, uint16_t pixel_type)
1.157 {
1.158 uint8_t rgb[3];
1.159
1.160 @@ -156,71 +157,71 @@
1.161 set_pixel4(h, v, pixel(rgb[0], rgb[1], rgb[2], 1, 2, 1, 3, 1, 0) | get_bitmap_value(h, pixel_type));
1.162 }
1.163
1.164 -void test_pixel(unsigned short h, unsigned short v, unsigned short pixel_type)
1.165 +void test_pixel(uint16_t h, uint16_t v, uint16_t pixel_type)
1.166 {
1.167 - switch (panel_info.vl_bpix)
1.168 + switch (panel_info.jz_fb->bpp)
1.169 {
1.170 - case LCD_COLOR32:
1.171 + case 32:
1.172 test_pixel32(h, v, pixel_type);
1.173 break;
1.174
1.175 - case LCD_COLOR8:
1.176 + case 8:
1.177 test_pixel8(h, v, pixel_type);
1.178 break;
1.179
1.180 - case LCD_COLOR4:
1.181 + case 4:
1.182 test_pixel4(h, v, pixel_type);
1.183 break;
1.184
1.185 - case LCD_COLOR16:
1.186 + case 16:
1.187 default:
1.188 test_pixel16_565(h, v, pixel_type);
1.189 break;
1.190 }
1.191 }
1.192
1.193 -void clear_pixel32(unsigned short h, unsigned short v)
1.194 +void clear_pixel32(uint16_t h, uint16_t v)
1.195 {
1.196 uint32_t *pix = get_pixel32(h, v);
1.197 *pix = 0;
1.198 }
1.199
1.200 -void clear_pixel16(unsigned short h, unsigned short v)
1.201 +void clear_pixel16(uint16_t h, uint16_t v)
1.202 {
1.203 uint16_t *pix = get_pixel16(h, v);
1.204 *pix = 0;
1.205 }
1.206
1.207 -void clear_pixel8(unsigned short h, unsigned short v)
1.208 +void clear_pixel8(uint16_t h, uint16_t v)
1.209 {
1.210 uint8_t *pix = get_pixel8(h, v);
1.211 *pix = 0;
1.212 }
1.213
1.214 -void clear_pixel4(unsigned short h, unsigned short v)
1.215 +void clear_pixel4(uint16_t h, uint16_t v)
1.216 {
1.217 uint8_t *pix = get_pixel4(h, v);
1.218 uint8_t mask = h & 1 ? 0xf0 : 0x0f;
1.219 *pix = *pix & mask;
1.220 }
1.221
1.222 -void clear_pixel(unsigned short h, unsigned short v)
1.223 +void clear_pixel(uint16_t h, uint16_t v)
1.224 {
1.225 - switch (panel_info.vl_bpix)
1.226 + switch (panel_info.jz_fb->bpp)
1.227 {
1.228 - case LCD_COLOR32:
1.229 + case 32:
1.230 clear_pixel32(h, v);
1.231 break;
1.232
1.233 - case LCD_COLOR8:
1.234 + case 8:
1.235 clear_pixel8(h, v);
1.236 break;
1.237
1.238 - case LCD_COLOR4:
1.239 + case 4:
1.240 clear_pixel4(h, v);
1.241 break;
1.242
1.243 - case LCD_COLOR16:
1.244 + case 16:
1.245 default:
1.246 clear_pixel16(h, v);
1.247 break;
1.248 @@ -229,9 +230,9 @@
1.249
1.250 void test_pattern()
1.251 {
1.252 - unsigned short v_max = panel_info.vl_row;
1.253 - unsigned short h_max = panel_info.vl_col;
1.254 - unsigned short v, h;
1.255 + uint16_t v_max = panel_info.jz_fb->h;
1.256 + uint16_t h_max = panel_info.jz_fb->w;
1.257 + uint16_t v, h;
1.258
1.259 for (v = 0; v < v_max; v += 1) {
1.260 for (h = 0; h < h_max; h += 1) {
1.261 @@ -240,12 +241,12 @@
1.262 }
1.263 }
1.264
1.265 -void lcd_clear(unsigned long lcd_base)
1.266 +void lcd_clear(uint32_t lcd_base)
1.267 {
1.268 - unsigned short v_max = panel_info.vl_row;
1.269 - unsigned short h_max = panel_info.vl_col;
1.270 - unsigned short v, h;
1.271 - unsigned long *pix = (unsigned long *)lcd_base;
1.272 + uint16_t v_max = panel_info.jz_fb->h;
1.273 + uint16_t h_max = panel_info.jz_fb->w;
1.274 + uint16_t v, h;
1.275 + uint32_t *pix = (uint32_t *)lcd_base;
1.276
1.277 for (v = 0; v < v_max; v += 1) {
1.278 for (h = 0; h < h_max; h += 1) {
1.279 @@ -261,6 +262,10 @@
1.280 __lcd_display_pin_init();
1.281 __lcd_display_on();
1.282
1.283 + /* Initialise the member here since the address is otherwise invalid. */
1.284 +
1.285 + panel_info.jz_fb = (struct jzfb_info *) ((uint32_t) &jzfb & ~0x80000000);
1.286 +
1.287 lcd_base = lcd_ctrl_init();
1.288 lcd_clear(lcd_base);
1.289 lcd_enable();