summaryrefslogtreecommitdiff
path: root/firmware/export/lcd.h
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/export/lcd.h')
-rw-r--r--firmware/export/lcd.h85
1 files changed, 84 insertions, 1 deletions
diff --git a/firmware/export/lcd.h b/firmware/export/lcd.h
index 673ce069af..cf6a16572a 100644
--- a/firmware/export/lcd.h
+++ b/firmware/export/lcd.h
@@ -127,7 +127,13 @@ typedef unsigned char fb_data;
127#elif LCD_DEPTH <= 16 127#elif LCD_DEPTH <= 16
128typedef unsigned short fb_data; 128typedef unsigned short fb_data;
129#define FB_DATA_SZ 2 129#define FB_DATA_SZ 2
130#else /* LCD_DEPTH > 16 */ 130#elif LCD_DEPTH <= 24
131struct _fb_pixel {
132 unsigned char b, g, r;
133};
134typedef struct _fb_pixel fb_data;
135#define FB_DATA_SZ 3
136#else /* LCD_DEPTH > 24 */
131typedef unsigned long fb_data; 137typedef unsigned long fb_data;
132#define FB_DATA_SZ 4 138#define FB_DATA_SZ 4
133#endif /* LCD_DEPTH */ 139#endif /* LCD_DEPTH */
@@ -341,6 +347,31 @@ static inline unsigned lcd_color_to_native(unsigned color)
341#define RGB_UNPACK_GREEN_LCD(x) _RGB_UNPACK_GREEN_LCD(x) 347#define RGB_UNPACK_GREEN_LCD(x) _RGB_UNPACK_GREEN_LCD(x)
342#define RGB_UNPACK_BLUE_LCD(x) _RGB_UNPACK_BLUE_LCD(x) 348#define RGB_UNPACK_BLUE_LCD(x) _RGB_UNPACK_BLUE_LCD(x)
343#endif /* RGB565* */ 349#endif /* RGB565* */
350
351#elif LCD_PIXELFORMAT == RGB888
352#define LCD_MAX_RED 255
353#define LCD_MAX_GREEN 255
354#define LCD_MAX_BLUE 255
355#define LCD_RED_BITS 8
356#define LCD_GREEN_BITS 8
357#define LCD_BLUE_BITS 8
358
359/* pack/unpack native RGB values */
360#define _RGBPACK(r, g, b) ( r << 16 | g << 8 | b )
361#define _RGB_UNPACK_RED(x) ((x >> 16) & 0xff)
362#define _RGB_UNPACK_GREEN(x) ((x >> 8) & 0xff)
363#define _RGB_UNPACK_BLUE(x) ((x >> 0) & 0xff)
364
365#define _LCD_UNSWAP_COLOR(x) (x)
366#define LCD_RGBPACK(r, g, b) _RGBPACK((r), (g), (b))
367#define LCD_RGBPACK_LCD(r, g, b) _RGBPACK((r), (g), (b))
368#define RGB_UNPACK_RED(x) _RGB_UNPACK_RED(x)
369#define RGB_UNPACK_GREEN(x) _RGB_UNPACK_GREEN(x)
370#define RGB_UNPACK_BLUE(x) _RGB_UNPACK_BLUE(x)
371#define RGB_UNPACK_RED_LCD(x) _RGB_UNPACK_RED(x)
372#define RGB_UNPACK_GREEN_LCD(x) _RGB_UNPACK_GREEN(x)
373#define RGB_UNPACK_BLUE_LCD(x) _RGB_UNPACK_BLUE(x)
374
344#else 375#else
345/* other colour depths */ 376/* other colour depths */
346#endif 377#endif
@@ -367,6 +398,58 @@ static inline unsigned lcd_color_to_native(unsigned color)
367 398
368#endif /* HAVE_LCD_COLOR */ 399#endif /* HAVE_LCD_COLOR */
369 400
401/* Framebuffer conversion macros: Convert from and to the native display data
402 * format (fb_data).
403 *
404 * FB_RGBPACK: Convert the three r,g,b values to fb_data. r,g,b are
405 * assumed to in 8-bit format.
406 * FB_RGBPACK_LCD Like FB_RGBPACK, except r,g,b shall be in display-native
407 * bit format (e.g. 5-bit r for RGB565)
408 * FB_UNPACK_RED Extract the red component of fb_data into 8-bit red value.
409 * FB_UNPACK_GREEN Like FB_UNPACK_RED, just for the green component.
410 * FB_UNPACK_BLIE Like FB_UNPACK_RED, just for the green component.
411 * FB_SCALARPACK Similar to FB_RGBPACK, except that the channels are already
412 * combined into a single scalar value. Again, 8-bit per channel.
413 * FB_SCALARPACK_LCD Like FB_SCALARPACK, except the channels shall be in
414 * display-native format (i.e. the scalar is 16bits on RGB565)
415 * FB_UNPACK_SCALAR_LCD Converts an fb_data to a scalar value in display-native
416 * format, so it's the reverse of FB_SCALARPACK_LCD
417 */
418#if LCD_DEPTH >= 24
419static inline fb_data scalar_to_fb(unsigned p)
420{
421 union { fb_data st; unsigned sc; } convert;
422 convert.sc = p; return convert.st;
423}
424static inline unsigned fb_to_scalar(fb_data p)
425{
426 union { fb_data st; unsigned sc; } convert;
427 convert.st = p; return convert.sc;
428}
429#define FB_RGBPACK(r_, g_, b_) ((fb_data){.r = r_, .g = g_, .b = b_})
430#define FB_RGBPACK_LCD(r_, g_, b_) FB_RGBPACK(r_, g_, b_)
431#define FB_UNPACK_RED(fb) ((fb).r)
432#define FB_UNPACK_GREEN(fb) ((fb).g)
433#define FB_UNPACK_BLUE(fb) ((fb).b)
434#define FB_SCALARPACK(c) scalar_to_fb(c)
435#define FB_SCALARPACK_LCD(c) scalar_to_fb(c)
436#define FB_UNPACK_SCALAR_LCD(fb) fb_to_scalar(fb)
437#elif defined(HAVE_LCD_COLOR)
438#define FB_RGBPACK(r_, g_, b_) LCD_RGBPACK(r_, g_, b_)
439#define FB_RGBPACK_LCD(r_, g_, b_) LCD_RGBPACK_LCD(r_, g_, b_)
440#define FB_UNPACK_RED(fb) RGB_UNPACK_RED(fb)
441#define FB_UNPACK_GREEN(fb) RGB_UNPACK_GREEN(fb)
442#define FB_UNPACK_BLUE(fb) RGB_UNPACK_BLUE(fb)
443#define FB_SCALARPACK(c) LCD_RGBPACK(RGB_UNPACK_RED(c), RGB_UNPACK_GREEN(c), RGB_UNPACK_BLUE(c))
444#define FB_SCALARPACK_LCD(c) (c)
445#define FB_UNPACK_SCALAR_LCD(fb) (fb)
446#else
447#define FB_SCALARPACK(c) (c)
448#define FB_SCALARPACK_LCD(c) (c)
449#define FB_UNPACK_SCALAR_LCD(fb) (fb)
450#endif
451
452
370/* Frame buffer dimensions */ 453/* Frame buffer dimensions */
371#if LCD_DEPTH == 1 454#if LCD_DEPTH == 1
372#if LCD_PIXELFORMAT == HORIZONTAL_PACKING 455#if LCD_PIXELFORMAT == HORIZONTAL_PACKING