aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/gdisp/ED060SC4/gdisp_lld_config.h2
-rw-r--r--drivers/gdisp/HX8347D/gdisp_lld_config.h2
-rw-r--r--drivers/gdisp/ILI9320/gdisp_lld_config.h2
-rw-r--r--drivers/gdisp/ILI9325/gdisp_lld_config.h2
-rw-r--r--drivers/gdisp/ILI9341/gdisp_lld_config.h2
-rw-r--r--drivers/gdisp/ILI9481/gdisp_lld_config.h2
-rw-r--r--drivers/gdisp/Nokia6610GE12/gdisp_lld_config.h2
-rw-r--r--drivers/gdisp/Nokia6610GE8/gdisp_lld_config.h2
-rw-r--r--drivers/gdisp/RA8875/gdisp_lld_config.h2
-rw-r--r--drivers/gdisp/S6D1121/gdisp_lld_config.h2
-rw-r--r--drivers/gdisp/SSD1289/gdisp_lld_config.h2
-rw-r--r--drivers/gdisp/SSD1306/gdisp_lld_config.h2
-rw-r--r--drivers/gdisp/SSD1963/gdisp_lld_config.h2
-rw-r--r--drivers/gdisp/SSD2119/gdisp_lld_config.h2
-rw-r--r--drivers/gdisp/ST7565/gdisp_lld_config.h2
-rw-r--r--drivers/gdisp/TestStub/gdisp_lld_config.h2
-rw-r--r--drivers/multiple/Win32/gdisp_lld_config.h6
-rw-r--r--drivers/multiple/X/gdisp_lld_config.h2
-rw-r--r--include/gdisp/colors.h353
-rw-r--r--include/gdisp/gdisp.h181
20 files changed, 385 insertions, 189 deletions
diff --git a/drivers/gdisp/ED060SC4/gdisp_lld_config.h b/drivers/gdisp/ED060SC4/gdisp_lld_config.h
index d7e836c9..47e84779 100644
--- a/drivers/gdisp/ED060SC4/gdisp_lld_config.h
+++ b/drivers/gdisp/ED060SC4/gdisp_lld_config.h
@@ -17,7 +17,7 @@
#define GDISP_HARDWARE_CLEARS TRUE
#define GDISP_HARDWARE_CONTROL TRUE
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_MONO
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_MONO
#endif
diff --git a/drivers/gdisp/HX8347D/gdisp_lld_config.h b/drivers/gdisp/HX8347D/gdisp_lld_config.h
index 48801f55..ab4c8639 100644
--- a/drivers/gdisp/HX8347D/gdisp_lld_config.h
+++ b/drivers/gdisp/HX8347D/gdisp_lld_config.h
@@ -25,7 +25,7 @@
#define GDISP_HARDWARE_STREAM_WRITE TRUE
#define GDISP_HARDWARE_CONTROL TRUE
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/ILI9320/gdisp_lld_config.h b/drivers/gdisp/ILI9320/gdisp_lld_config.h
index 1a1f139f..5709de50 100644
--- a/drivers/gdisp/ILI9320/gdisp_lld_config.h
+++ b/drivers/gdisp/ILI9320/gdisp_lld_config.h
@@ -27,7 +27,7 @@
//#define GDISP_HARDWARE_STREAM_POS TRUE
#define GDISP_HARDWARE_CONTROL TRUE
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/ILI9325/gdisp_lld_config.h b/drivers/gdisp/ILI9325/gdisp_lld_config.h
index 8c586c78..c40bd2b7 100644
--- a/drivers/gdisp/ILI9325/gdisp_lld_config.h
+++ b/drivers/gdisp/ILI9325/gdisp_lld_config.h
@@ -27,7 +27,7 @@
#define GDISP_HARDWARE_STREAM_POS TRUE
#define GDISP_HARDWARE_CONTROL TRUE
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/ILI9341/gdisp_lld_config.h b/drivers/gdisp/ILI9341/gdisp_lld_config.h
index ba9c05bc..668a06c9 100644
--- a/drivers/gdisp/ILI9341/gdisp_lld_config.h
+++ b/drivers/gdisp/ILI9341/gdisp_lld_config.h
@@ -27,7 +27,7 @@
//#define GDISP_HARDWARE_STREAM_READ TRUE
#define GDISP_HARDWARE_CONTROL TRUE
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/ILI9481/gdisp_lld_config.h b/drivers/gdisp/ILI9481/gdisp_lld_config.h
index 4a33d110..3f3a4834 100644
--- a/drivers/gdisp/ILI9481/gdisp_lld_config.h
+++ b/drivers/gdisp/ILI9481/gdisp_lld_config.h
@@ -27,7 +27,7 @@
#define GDISP_HARDWARE_STREAM_READ TRUE
#define GDISP_HARDWARE_CONTROL TRUE
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/Nokia6610GE12/gdisp_lld_config.h b/drivers/gdisp/Nokia6610GE12/gdisp_lld_config.h
index 73f505be..19a455d8 100644
--- a/drivers/gdisp/Nokia6610GE12/gdisp_lld_config.h
+++ b/drivers/gdisp/Nokia6610GE12/gdisp_lld_config.h
@@ -25,7 +25,7 @@
#define GDISP_HARDWARE_CONTROL TRUE
#define GDISP_HARDWARE_STREAM_WRITE TRUE
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB444
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB444
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/Nokia6610GE8/gdisp_lld_config.h b/drivers/gdisp/Nokia6610GE8/gdisp_lld_config.h
index 70a57d12..1476dbcf 100644
--- a/drivers/gdisp/Nokia6610GE8/gdisp_lld_config.h
+++ b/drivers/gdisp/Nokia6610GE8/gdisp_lld_config.h
@@ -41,7 +41,7 @@
#define GDISP_HARDWARE_STREAM_WRITE TRUE
#endif
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB444
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB444
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/RA8875/gdisp_lld_config.h b/drivers/gdisp/RA8875/gdisp_lld_config.h
index ae290245..55a07839 100644
--- a/drivers/gdisp/RA8875/gdisp_lld_config.h
+++ b/drivers/gdisp/RA8875/gdisp_lld_config.h
@@ -27,7 +27,7 @@
#define GDISP_HARDWARE_STREAM_POS TRUE
#define GDISP_HARDWARE_CONTROL TRUE
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/S6D1121/gdisp_lld_config.h b/drivers/gdisp/S6D1121/gdisp_lld_config.h
index 839bbf9d..79e859bc 100644
--- a/drivers/gdisp/S6D1121/gdisp_lld_config.h
+++ b/drivers/gdisp/S6D1121/gdisp_lld_config.h
@@ -27,7 +27,7 @@
#define GDISP_HARDWARE_STREAM_POS TRUE
#define GDISP_HARDWARE_CONTROL TRUE
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/SSD1289/gdisp_lld_config.h b/drivers/gdisp/SSD1289/gdisp_lld_config.h
index 84e518d2..4cf5fa5c 100644
--- a/drivers/gdisp/SSD1289/gdisp_lld_config.h
+++ b/drivers/gdisp/SSD1289/gdisp_lld_config.h
@@ -32,7 +32,7 @@
#define GDISP_HARDWARE_BITFILLS TRUE
#endif
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/SSD1306/gdisp_lld_config.h b/drivers/gdisp/SSD1306/gdisp_lld_config.h
index 8580f933..627de17b 100644
--- a/drivers/gdisp/SSD1306/gdisp_lld_config.h
+++ b/drivers/gdisp/SSD1306/gdisp_lld_config.h
@@ -19,7 +19,7 @@
#define GDISP_HARDWARE_PIXELREAD TRUE
#define GDISP_HARDWARE_CONTROL TRUE
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_MONO
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_MONO
// This controller supports a special gdispControl() to inverse the display.
// Pass a parameter of 1 for inverse and 0 for normal.
diff --git a/drivers/gdisp/SSD1963/gdisp_lld_config.h b/drivers/gdisp/SSD1963/gdisp_lld_config.h
index 054d72b8..8ad94738 100644
--- a/drivers/gdisp/SSD1963/gdisp_lld_config.h
+++ b/drivers/gdisp/SSD1963/gdisp_lld_config.h
@@ -25,7 +25,7 @@
#define GDISP_HARDWARE_STREAM_WRITE TRUE
//#define GDISP_HARDWARE_CONTROL TRUE // Not Yet.
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/SSD2119/gdisp_lld_config.h b/drivers/gdisp/SSD2119/gdisp_lld_config.h
index 5d81057c..a974c623 100644
--- a/drivers/gdisp/SSD2119/gdisp_lld_config.h
+++ b/drivers/gdisp/SSD2119/gdisp_lld_config.h
@@ -32,7 +32,7 @@
#define GDISP_HARDWARE_BITFILLS TRUE
#endif
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/ST7565/gdisp_lld_config.h b/drivers/gdisp/ST7565/gdisp_lld_config.h
index 632dc431..f774e8fa 100644
--- a/drivers/gdisp/ST7565/gdisp_lld_config.h
+++ b/drivers/gdisp/ST7565/gdisp_lld_config.h
@@ -19,7 +19,7 @@
#define GDISP_HARDWARE_PIXELREAD TRUE
#define GDISP_HARDWARE_CONTROL TRUE
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_MONO
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_MONO
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/TestStub/gdisp_lld_config.h b/drivers/gdisp/TestStub/gdisp_lld_config.h
index adb6c8b4..63471c6c 100644
--- a/drivers/gdisp/TestStub/gdisp_lld_config.h
+++ b/drivers/gdisp/TestStub/gdisp_lld_config.h
@@ -25,7 +25,7 @@
#define GDISP_HARDWARE_DRAWPIXEL TRUE
#define GDISP_HARDWARE_PIXELREAD TRUE
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
#endif /* GFX_USE_GDISP */
diff --git a/drivers/multiple/Win32/gdisp_lld_config.h b/drivers/multiple/Win32/gdisp_lld_config.h
index e2fc3de4..4985bc43 100644
--- a/drivers/multiple/Win32/gdisp_lld_config.h
+++ b/drivers/multiple/Win32/gdisp_lld_config.h
@@ -21,10 +21,10 @@
/*===========================================================================*/
/* Driver hardware support. */
/*===========================================================================*/
-
+
// Calling gdispGFlush() is optional for this driver but can be used by the
// application to force a display update. eg after streaming.
-
+
#define GDISP_HARDWARE_FLUSH TRUE
#define GDISP_HARDWARE_CONTROL TRUE
@@ -45,7 +45,7 @@
#define GDISP_HARDWARE_SCROLL TRUE
#endif
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB888
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB888
#endif /* GFX_USE_GDISP */
diff --git a/drivers/multiple/X/gdisp_lld_config.h b/drivers/multiple/X/gdisp_lld_config.h
index b58a3d54..631ecf46 100644
--- a/drivers/multiple/X/gdisp_lld_config.h
+++ b/drivers/multiple/X/gdisp_lld_config.h
@@ -29,7 +29,7 @@
#define GDISP_HARDWARE_PIXELREAD TRUE
#define GDISP_HARDWARE_CONTROL FALSE
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB888
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB888
#endif /* GFX_USE_GDISP */
diff --git a/include/gdisp/colors.h b/include/gdisp/colors.h
new file mode 100644
index 00000000..975934d0
--- /dev/null
+++ b/include/gdisp/colors.h
@@ -0,0 +1,353 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file include/gdisp/colors.h
+ * @brief GDISP color definitions header file.
+ *
+ * @defgroup Colors Colors
+ * @ingroup GDISP
+ * @{
+ */
+
+#ifndef _GDISP_COLORS_H
+#define _GDISP_COLORS_H
+
+#include "gfx.h"
+
+#if GFX_USE_GDISP || defined(__DOXYGEN__)
+
+/**
+ * For pixel formats we do some assignment of codes to enable
+ * format auto-calculation. (Undocumented).
+ * 0x2RGB TRUECOLOR RGB format, R = red bits, G = green bits, B = blue bits
+ * 0x3RGB TRUECOLOR BGR format, R = red bits, G = green bits, B = blue bits
+ * 0x40XX GRAYSCALE XX = bits
+ * 0x60XX PALLETTE XX = bits
+ * 0x8XXX CUSTOM format.
+ */
+#define GDISP_COLORSYSTEM_MASK 0xF000
+#define GDISP_COLORSYSTEM_RGB 0x2000
+#define GDISP_COLORSYSTEM_BGR 0x3000
+
+/**
+ * @brief Color Type Constants
+ * @{
+ */
+#define GDISP_COLORSYSTEM_TRUECOLOR 0x2000
+#define GDISP_COLORSYSTEM_GRAYSCALE 0x4000
+#define GDISP_COLORSYSTEM_PALETTE 0x6000
+/** @} */
+
+/**
+ * @brief Pixel Format Constants
+ * @{
+ */
+#define GDISP_PIXELFORMAT_MONO (GDISP_COLORSYSTEM_GRAYSCALE|0x0001)
+#define GDISP_PIXELFORMAT_RGB565 (GDISP_COLORSYSTEM_RGB|0x0565)
+#define GDISP_PIXELFORMAT_BGR565 (GDISP_COLORSYSTEM_BGR|0x0565)
+#define GDISP_PIXELFORMAT_RGB888 (GDISP_COLORSYSTEM_RGB|0x0888)
+#define GDISP_PIXELFORMAT_BGR888 (GDISP_COLORSYSTEM_BGR|0x0888)
+#define GDISP_PIXELFORMAT_RGB444 (GDISP_COLORSYSTEM_RGB|0x0444)
+#define GDISP_PIXELFORMAT_BGR444 (GDISP_COLORSYSTEM_BGR|0x0444)
+#define GDISP_PIXELFORMAT_RGB332 (GDISP_COLORSYSTEM_RGB|0x0332)
+#define GDISP_PIXELFORMAT_BGR332 (GDISP_COLORSYSTEM_BGR|0x0332)
+#define GDISP_PIXELFORMAT_RGB666 (GDISP_COLORSYSTEM_RGB|0x0666)
+#define GDISP_PIXELFORMAT_BGR666 (GDISP_COLORSYSTEM_BGR|0x0666)
+#define GDISP_PIXELFORMAT_ERROR 0x0000
+/** @} */
+
+/**
+ * @name Some basic colors
+ * @{
+ */
+#define White HTML2COLOR(0xFFFFFF)
+#define Black HTML2COLOR(0x000000)
+#define Gray HTML2COLOR(0x808080)
+#define Grey Gray
+#define Blue HTML2COLOR(0x0000FF)
+#define Red HTML2COLOR(0xFF0000)
+#define Fuchsia HTML2COLOR(0xFF00FF)
+#define Magenta Fuchsia
+#define Green HTML2COLOR(0x008000)
+#define Yellow HTML2COLOR(0xFFFF00)
+#define Aqua HTML2COLOR(0x00FFFF)
+#define Cyan Aqua
+#define Lime HTML2COLOR(0x00FF00)
+#define Maroon HTML2COLOR(0x800000)
+#define Navy HTML2COLOR(0x000080)
+#define Olive HTML2COLOR(0x808000)
+#define Purple HTML2COLOR(0x800080)
+#define Silver HTML2COLOR(0xC0C0C0)
+#define Teal HTML2COLOR(0x008080)
+#define Orange HTML2COLOR(0xFFA500)
+#define Pink HTML2COLOR(0xFFC0CB)
+#define SkyBlue HTML2COLOR(0x87CEEB)
+/** @} */
+
+#if defined(__DOXYGEN__)
+ /**
+ * @brief The color system (grayscale, palette or truecolor)
+ */
+ #define COLOR_SYSTEM GDISP_COLORSYSTEM_TRUECOLOR
+ /**
+ * @brief The number of bits in a color value
+ */
+ #define COLOR_BITS 16
+ /**
+ * @brief The number of bits for each of red, green and blue
+ * @{
+ */
+ #define COLOR_BITS_R 5
+ #define COLOR_BITS_G 6
+ #define COLOR_BITS_B 5
+ /** @} */
+ /**
+ * @brief The number of bits to shift each of red, green and blue to put it in the correct place in the color
+ * @{
+ */
+ #define COLOR_SHIFT_R 11
+ #define COLOR_SHIFT_G 5
+ #define COLOR_SHIFT_B 0
+ /** @} */
+ /**
+ * @brief Does the color need masking to remove invalid bits
+ */
+ #define COLOR_NEEDS_MASK FALSE
+ /**
+ * @brief If the color need masking to remove invalid bits, this is the mask
+ */
+ #define COLOR_MASK 0xFFFF
+ /**
+ * @brief The color type
+ * @{
+ */
+ #define COLOR_TYPE uint16_t
+ /** @} */
+ /**
+ * @brief The number of bits in the color type (not necessarily the same as COLOR_BITS).
+ */
+ #define COLOR_TYPE_BITS 16
+ /**
+ * @brief Convert red, green, blue (each 0 to 255) into a color value.
+ */
+ #define RGB2COLOR(r,g,b) ((color_t)((((r) & 0xF8)<<8) | (((g) & 0xFC)<<3) | (((b) & 0xF8)>>3)))
+ /**
+ * @brief Convert a 6 digit HTML code (hex) into a color value.
+ */
+ #define HTML2COLOR(h) ((color_t)((((h) & 0xF80000)>>8) | (((h) & 0x00FC00)>>5) | (((h) & 0x0000F8)>>3)))
+ /**
+ * @brief Extract the red/green/blue component (0 to 255) of a color value.
+ * @note This uses quick and dirty bit shifting. If you want more exact colors
+ * use @p EXACT_RED_OF() etc which uses multiplies and divides. For constant
+ * colors using @p EXACT_REF_OF() is no more expensive because the compiler
+ * evaluates the arithmetic.
+ * @note A 5 bit maximum value (0x1F) converts to 0xF8 (slightly off-color)
+ * @{
+ */
+ #define RED_OF(c) (((c) & 0xF800)>>8)
+ #define GREEN_OF(c) (((c)&0x007E)>>3)
+ #define BLUE_OF(c) (((c)&0x001F)<<3)
+ /** @} */
+ /**
+ * @brief Extract the exact red/green/blue component (0 to 255) of a color value.
+ * @note This uses multiplies and divides rather than bit shifting.
+ * This gives exact equivalent colors at the expense of more cpu intensive
+ * operations. Note for constants this is no more expensive than @p REF_OF()
+ * because the compiler evaluates the arithmetic.
+ * @note A 5 bit maximum value (0x1F) converts to 0xFF ( the true equivalent color)
+ * @{
+ */
+ #define EXACT_RED_OF(c) (((((c)>>11)&0x1F)*255)/31)
+ #define EXACT_GREEN_OF(c) (((((c)>>5)&0x3F)*255)/63)
+ #define EXACT_BLUE_OF(c) (((((c)>>0)&0x1F)*255)/31)
+ /** @} */
+#endif
+
+/*
+ * We use this big mess of macros to calculate all the components
+ * to prevent user errors in the color definitions. It greatly simplifies
+ * the above definitions and ensures a consistent implementation.
+ */
+
+//-------------------------
+// True-Color color system
+//-------------------------
+#if GDISP_PIXELFORMAT & GDISP_COLORSYSTEM_TRUECOLOR
+ #define COLOR_SYSTEM GDISP_COLORSYSTEM_TRUECOLOR
+
+ // Calculate the number of bits
+ #define COLOR_BITS_R ((GDISP_PIXELFORMAT>>8) & 0x0F)
+ #define COLOR_BITS_G ((GDISP_PIXELFORMAT>>4) & 0x0F)
+ #define COLOR_BITS_B ((GDISP_PIXELFORMAT>>0) & 0x0F)
+ #define COLOR_BITS (COLOR_BITS_R + COLOR_BITS_G + COLOR_BITS_B)
+
+ // From the number of bits determine COLOR_TYPE, COLOR_TYPE_BITS and masking
+ #if COLOR_BITS <= 8
+ #define COLOR_TYPE uint8_t
+ #define COLOR_TYPE_BITS 8
+ #elif COLOR_BITS <= 16
+ #define COLOR_TYPE uint16_t
+ #define COLOR_TYPE_BITS 16
+ #elif COLOR_BITS <= 32
+ #define COLOR_TYPE uint32_t
+ #define COLOR_TYPE_BITS 32
+ #else
+ #error "GDISP: Cannot define color types with more than 32 bits"
+ #endif
+ #if COLOR_TYPE_BITS == COLOR_BITS
+ #define COLOR_NEEDS_MASK FALSE
+ #else
+ #define COLOR_NEEDS_MASK TRUE
+ #endif
+ #define COLOR_MASK() ((1 << COLOR_BITS)-1)
+
+ // Calculate the component bit shifts
+ #if (GDISP_PIXELFORMAT & GDISP_COLORSYSTEM_MASK) == GDISP_COLORSYSTEM_RGB
+ #define COLOR_SHIFT_R (COLOR_BITS_B+COLOR_BITS_G)
+ #define COLOR_SHIFT_G COLOR_BITS_B
+ #define COLOR_SHIFT_B 0
+ #else
+ #define COLOR_SHIFT_B (COLOR_BITS_R+COLOR_BITS_G)
+ #define COLOR_SHIFT_G COLOR_BITS_R
+ #define COLOR_SHIFT_R 0
+ #endif
+
+ // Calculate RED_OF, GREEN_OF, BLUE_OF and RGB2COLOR
+ #if COLOR_BITS_R + COLOR_SHIFT_R == 8
+ #define RED_OF(val) ((val) & (((1<<COLOR_BITS_R)-1) << COLOR_SHIFT_R))
+ #define RGB2COLOR_R(val) ((COLOR_TYPE)((val) & (0xFF & ~((1<<(8-COLOR_BITS_R))-1))))
+ #elif COLOR_BITS_R + COLOR_SHIFT_R > 8
+ #define RED_OF(val) (((val) & (((1<<COLOR_BITS_R)-1) << COLOR_SHIFT_R)) >> (COLOR_BITS_R+COLOR_SHIFT_R-8))
+ #define RGB2COLOR_R(val) (((COLOR_TYPE)((val) & (0xFF & ~((1<<(8-COLOR_BITS_R))-1)))) << (COLOR_BITS_R+COLOR_SHIFT_R-8))
+ #else // COLOR_BITS_R + COLOR_SHIFT_R < 8
+ #define RED_OF(val) (((val) & (((1<<COLOR_BITS_R)-1) << COLOR_SHIFT_R)) << (8-(COLOR_BITS_R+COLOR_SHIFT_R)))
+ #define RGB2COLOR_R(val) (((COLOR_TYPE)((val) & (0xFF & ~((1<<(8-COLOR_BITS_R))-1)))) >> (8-(COLOR_BITS_R+COLOR_SHIFT_R)))
+ #endif
+ #if COLOR_BITS_G + COLOR_SHIFT_G == 8
+ #define GREEN_OF(val) ((val) & (((1<<COLOR_BITS_G)-1) << COLOR_SHIFT_G))
+ #define RGB2COLOR_G(val) ((COLOR_TYPE)((val) & (0xFF & ~((1<<(8-COLOR_BITS_G))-1))))
+ #elif COLOR_BITS_G + COLOR_SHIFT_G > 8
+ #define GREEN_OF(val) (((val) & (((1<<COLOR_BITS_G)-1) << COLOR_SHIFT_G)) >> (COLOR_BITS_G+COLOR_SHIFT_G-8))
+ #define RGB2COLOR_G(val) (((COLOR_TYPE)((val) & (0xFF & ~((1<<(8-COLOR_BITS_G))-1)))) << (COLOR_BITS_G+COLOR_SHIFT_G-8))
+ #else // COLOR_BITS_G + COLOR_SHIFT_G < 8
+ #define GREEN_OF(val) (((val) & (((1<<COLOR_BITS_G)-1) << COLOR_SHIFT_G)) << (8-(COLOR_BITS_G+COLOR_SHIFT_G)))
+ #define RGB2COLOR_G(val) (((COLOR_TYPE)((val) & (0xFF & ~((1<<(8-COLOR_BITS_G))-1)))) >> (8-(COLOR_BITS_G+COLOR_SHIFT_G)))
+ #endif
+ #if COLOR_BITS_B + COLOR_SHIFT_B == 8
+ #define BLUE_OF(val) ((val) & (((1<<COLOR_BITS_B)-1) << COLOR_SHIFT_B))
+ #define RGB2COLOR_B(val) ((COLOR_TYPE)((val) & (0xFF & ~((1<<(8-COLOR_BITS_B))-1))))
+ #elif COLOR_BITS_B + COLOR_SHIFT_B > 8
+ #define BLUE_OF(val) (((val) & (((1<<COLOR_BITS_B)-1) << COLOR_SHIFT_B)) >> (COLOR_BITS_B+COLOR_SHIFT_B-8))
+ #define RGB2COLOR_B(val) (((COLOR_TYPE)((val) & (0xFF & ~((1<<(8-COLOR_BITS_B))-1)))) << (COLOR_BITS_B+COLOR_SHIFT_B-8))
+ #else // COLOR_BITS_B + COLOR_SHIFT_B < 8
+ #define BLUE_OF(val) (((val) & (((1<<COLOR_BITS_B)-1) << COLOR_SHIFT_B)) << (8-(COLOR_BITS_B+COLOR_SHIFT_B)))
+ #define RGB2COLOR_B(val) (((COLOR_TYPE)((val) & (0xFF & ~((1<<(8-COLOR_BITS_B))-1)))) >> (8-(COLOR_BITS_B+COLOR_SHIFT_B)))
+ #endif
+ #define EXACT_RED_OF(val) (((((val)>>COLOR_SHIFT_R)&((1<<COLOR_BITS_R)-1))*255)/((1<<COLOR_BITS_R)-1))
+ #define EXACT_GREEN_OF(val) (((((val)>>COLOR_SHIFT_G)&((1<<COLOR_BITS_G)-1))*255)/((1<<COLOR_BITS_G)-1))
+ #define EXACT_BLUE_OF(val) (((((val)>>COLOR_SHIFT_B)&((1<<COLOR_BITS_B)-1))*255)/((1<<COLOR_BITS_B)-1))
+ #define RGB2COLOR(r,g,b) (RGB2COLOR_R(r) | RGB2COLOR_G(g) | RGB2COLOR_B(b))
+
+ // Calculate HTML2COLOR
+ #if COLOR_BITS_R + COLOR_SHIFT_R == 24
+ #define HTML2COLOR_R(val) ((val) & ((0xFF & ~((1<<(8-COLOR_BITS_R))-1))<<16))
+ #elif COLOR_BITS_R + COLOR_SHIFT_R > 24
+ #define HTML2COLOR_R(val) (((val) & ((0xFF & ~((1<<(8-COLOR_BITS_R))-1))<<16)) << (COLOR_BITS_R+COLOR_SHIFT_R-24))
+ #else // COLOR_BITS_R + COLOR_SHIFT_R < 24
+ #define HTML2COLOR_R(val) (((val) & ((0xFF & ~((1<<(8-COLOR_BITS_R))-1))<<16)) >> (24-(COLOR_BITS_R+COLOR_SHIFT_R)))
+ #endif
+ #if COLOR_BITS_G + COLOR_SHIFT_G == 16
+ #define HTML2COLOR_G(val) ((val) & ((0xFF & ~((1<<(8-COLOR_BITS_G))-1))<<8))
+ #elif COLOR_BITS_G + COLOR_SHIFT_G > 16
+ #define HTML2COLOR_G(val) (((val) & ((0xFF & ~((1<<(8-COLOR_BITS_G))-1))<<8)) << (COLOR_BITS_G+COLOR_SHIFT_G-16))
+ #else // COLOR_BITS_G + COLOR_SHIFT_G < 16
+ #define HTML2COLOR_G(val) (((val) & ((0xFF & ~((1<<(8-COLOR_BITS_G))-1))<<8)) >> (16-(COLOR_BITS_G+COLOR_SHIFT_G)))
+ #endif
+ #if COLOR_BITS_B + COLOR_SHIFT_B == 8
+ #define HTML2COLOR_B(val) ((val) & (0xFF & ~((1<<(8-COLOR_BITS_B))-1)))
+ #elif COLOR_BITS_B + COLOR_SHIFT_B > 8
+ #define HTML2COLOR_B(val) (((val) & (0xFF & ~((1<<(8-COLOR_BITS_B))-1))) << (COLOR_BITS_B+COLOR_SHIFT_B-8))
+ #else // COLOR_BITS_B + COLOR_SHIFT_B < 8
+ #define HTML2COLOR_B(val) (((val) & (0xFF & ~((1<<(8-COLOR_BITS_B))-1))) >> (8-(COLOR_BITS_B+COLOR_SHIFT_B)))
+ #endif
+ #define HTML2COLOR(h) ((COLOR_TYPE)(HTML2COLOR_R(h) | HTML2COLOR_G(h) | HTML2COLOR_B(h)))
+
+//-------------------------
+// Gray-scale color system
+//-------------------------
+#elif (GDISP_PIXELFORMAT & GDISP_COLORSYSTEM_MASK) == GDISP_COLORSYSTEM_GRAYSCALE
+ #define COLOR_SYSTEM GDISP_COLORSYSTEM_GRAYSCALE
+
+ // Calculate the number of bits and shifts
+ #define COLOR_BITS (GDISP_PIXELFORMAT & 0xFF)
+ #define COLOR_BITS_R COLOR_BITS
+ #define COLOR_BITS_G COLOR_BITS
+ #define COLOR_BITS_B COLOR_BITS
+ #define COLOR_SHIFT_R 0
+ #define COLOR_SHIFT_G 0
+ #define COLOR_SHIFT_B 0
+
+ // From the number of bits determine COLOR_TYPE, COLOR_TYPE_BITS and masking
+ #if COLOR_BITS <= 8
+ #define COLOR_TYPE uint8_t
+ #define COLOR_TYPE_BITS 8
+ #else
+ #error "GDISP: Cannot define gray-scale color types with more than 8 bits"
+ #endif
+ #if COLOR_TYPE_BITS == COLOR_BITS
+ #define COLOR_NEEDS_MASK FALSE
+ #else
+ #define COLOR_NEEDS_MASK TRUE
+ #endif
+ #define COLOR_MASK() ((1 << COLOR_BITS)-1)
+
+ #if COLOR_BITS == 1
+ #define RGB2COLOR(r,g,b) (((r)|(g)|(b)) ? 1 : 0)
+ #define HTML2COLOR(h) ((h) ? 1 : 0)
+ #define RED_OF(c) ((c) ? 255 : 0)
+ #define GREEN_OF(c) RED_OF(c)
+ #define BLUE_OF(c) RED_OF(c)
+ #define EXACT_RED_OF(val) RED_OF(c)
+ #define EXACT_GREEN_OF(val) RED_OF(c)
+ #define EXACT_BLUE_OF(val) RED_OF(c)
+ #else
+ // They eye is more sensitive to green
+ #define RGB2COLOR(r,g,b) ((COLOR_TYPE)(((uint16_t)(r)+(g)+(g)+(b)) >> (10-COLOR_BITS)))
+ #define HTML2COLOR(h) ((COLOR_TYPE)(((((h)&0xFF0000)>>16)+(((h)&0x00FF00)>>7)+((h)&0x0000FF)) >> (10-COLOR_BITS)))
+ #define RED_OF(val) (((val) & ((1<<COLOR_BITS)-1)) << (8-COLOR_BITS))
+ #define GREEN_OF(c) RED_OF(c)
+ #define BLUE_OF(c) RED_OF(c)
+ #define EXACT_RED_OF(val) ((((uint16_t)(val) & ((1<<COLOR_BITS)-1))*255)/((1<<COLOR_BITS)-1))
+ #define EXACT_GREEN_OF(val) EXACT_RED_OF(c)
+ #define EXACT_BLUE_OF(val) EXACT_RED_OF(c)
+ #endif
+
+//-------------------------
+// Palette color system
+//-------------------------
+#elif (GDISP_PIXELFORMAT & GDISP_COLORSYSTEM_MASK) == GDISP_COLORSYSTEM_PALETTE
+ #define COLOR_SYSTEM GDISP_COLORSYSTEM_PALETTE
+
+ #error "GDISP: A palette color system is not currently supported"
+
+//-------------------------
+// Some other color system
+//-------------------------
+#else
+ #error "GDISP: Unsupported color system"
+#endif
+
+/**
+ * @brief The color type definition
+ */
+typedef COLOR_TYPE color_t;
+
+#endif /* GFX_USE_GDISP */
+
+#endif /* _GDISP_COLORS_H */
+/** @} */
diff --git a/include/gdisp/gdisp.h b/include/gdisp/gdisp.h
index 810ecb6b..3d617e50 100644
--- a/include/gdisp/gdisp.h
+++ b/include/gdisp/gdisp.h
@@ -120,47 +120,6 @@ extern GDisplay *GDISP;
#define GDISP_CONTROL_CONTRAST 3
#define GDISP_CONTROL_LLD 1000
-/**
- * @brief Driver Pixel Format Constants
- */
-#define GDISP_PIXELFORMAT_MONO 1
-#define GDISP_PIXELFORMAT_RGB565 565
-#define GDISP_PIXELFORMAT_BGR565 9565
-#define GDISP_PIXELFORMAT_RGB888 888
-#define GDISP_PIXELFORMAT_RGB444 444
-#define GDISP_PIXELFORMAT_RGB332 332
-#define GDISP_PIXELFORMAT_RGB666 666
-#define GDISP_PIXELFORMAT_CUSTOM 99999
-#define GDISP_PIXELFORMAT_ERROR 88888
-
-/**
- * @name Some basic colors
- * @{
- */
-#define White HTML2COLOR(0xFFFFFF)
-#define Black HTML2COLOR(0x000000)
-#define Gray HTML2COLOR(0x808080)
-#define Grey Gray
-#define Blue HTML2COLOR(0x0000FF)
-#define Red HTML2COLOR(0xFF0000)
-#define Fuchsia HTML2COLOR(0xFF00FF)
-#define Magenta Fuchsia
-#define Green HTML2COLOR(0x008000)
-#define Yellow HTML2COLOR(0xFFFF00)
-#define Aqua HTML2COLOR(0x00FFFF)
-#define Cyan Aqua
-#define Lime HTML2COLOR(0x00FF00)
-#define Maroon HTML2COLOR(0x800000)
-#define Navy HTML2COLOR(0x000080)
-#define Olive HTML2COLOR(0x808000)
-#define Purple HTML2COLOR(0x800080)
-#define Silver HTML2COLOR(0xC0C0C0)
-#define Teal HTML2COLOR(0x008080)
-#define Orange HTML2COLOR(0xFFA500)
-#define Pink HTML2COLOR(0xFFC0CB)
-#define SkyBlue HTML2COLOR(0x87CEEB)
-/** @} */
-
/*===========================================================================*/
/* Defines relating to the display hardware */
/*===========================================================================*/
@@ -170,6 +129,12 @@ extern GDisplay *GDISP;
// If we have multiple controllers the settings must be set in the
// users gfxconf.h file.
#include "gdisp_lld_config.h"
+
+ // Unless the user has specified a specific pixel format, use
+ // the native format for the controller.
+ #if !defined(GDISP_PIXELFORMAT) && defined(GDISP_LLD_PIXELFORMAT)
+ #define GDISP_PIXELFORMAT GDISP_LLD_PIXELFORMAT
+ #endif
#endif
/**
@@ -181,40 +146,24 @@ extern GDisplay *GDISP;
* @default It generally defaults to the hardware pixel format.
* @note This doesn't need to match the hardware pixel format.
* It is definitely more efficient when it does.
- * @note When GDISP_TOTAL_CONTROLLERS > 1, this should
- * also be explicitly defined to ensure the best match
+ * @note When GDISP_TOTAL_CONTROLLERS > 1, this must
+ * be explicitly defined and should ensure the best match
* with your hardware across all devices.
- * @note Should be set to one of the following:
- * GDISP_PIXELFORMAT_RGB565
- * GDISP_PIXELFORMAT_BGR565
- * GDISP_PIXELFORMAT_RGB888
- * GDISP_PIXELFORMAT_RGB444
- * GDISP_PIXELFORMAT_RGB332
- * GDISP_PIXELFORMAT_RGB666
- * GDISP_PIXELFORMAT_CUSTOM
- * @note If you set GDISP_PIXELFORMAT_CUSTOM you need to also define
- * color_t, RGB2COLOR(r,g,b), HTML2COLOR(h),
- * RED_OF(c), GREEN_OF(c), BLUE_OF(c),
- * COLOR(c) and MASKCOLOR.
*/
#ifndef GDISP_PIXELFORMAT
#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_ERROR
#endif
/**
* @brief Do pixels require packing for a blit
- * @note Is only valid for a pixel format that doesn't fill it's datatype. ie formats:
+ * @note Is only valid for a pixel format that doesn't fill it's datatype. eg formats:
* GDISP_PIXELFORMAT_RGB888
* GDISP_PIXELFORMAT_RGB444
* GDISP_PIXELFORMAT_RGB666
* GDISP_PIXELFORMAT_CUSTOM
- * @note If you use GDISP_PIXELFORMAT_CUSTOM and packed bit fills
- * you need to also define @p gdispPackPixels(buf,cx,x,y,c)
- * @note If you are using GDISP_HARDWARE_BITFILLS = FALSE then the pixel
- * format must not be a packed format as the software blit does
- * not support packed pixels
* @note Very few cases should actually require packed pixels as the low
* level driver can also pack on the fly as it is sending it
* to the graphics device.
+ * @note Packed pixels are not really supported at this point.
*/
#ifndef GDISP_PACKED_PIXELS
#define GDISP_PACKED_PIXELS FALSE
@@ -233,114 +182,8 @@ extern GDisplay *GDISP;
/* Defines related to the pixel format */
/*===========================================================================*/
-#if defined(__DOXYGEN__)
- /**
- * @brief The color of a pixel.
- */
- typedef uint16_t color_t;
- /**
- * @brief Convert a number (of any type) to a color_t.
- * @details Masks any invalid bits in the color
- */
- #define COLOR(c) ((color_t)(c))
- /**
- * @brief Does the color_t type contain invalid bits that need masking.
- */
- #define MASKCOLOR FALSE
- /**
- * @brief Convert red, green, blue (each 0 to 255) into a color value.
- */
- #define RGB2COLOR(r,g,b) ((color_t)((((r) & 0xF8)<<8) | (((g) & 0xFC)<<3) | (((b) & 0xF8)>>3)))
- /**
- * @brief Convert a 6 digit HTML code (hex) into a color value.
- */
- #define HTML2COLOR(h) ((color_t)((((h) & 0xF80000)>>8) | (((h) & 0x00FC00)>>5) | (((h) & 0x0000F8)>>3)))
- /**
- * @brief Extract the red component (0 to 255) of a color value.
- */
- #define RED_OF(c) (((c) & 0xF800)>>8)
- /**
- * @brief Extract the green component (0 to 255) of a color value.
- */
- #define GREEN_OF(c) (((c)&0x007E)>>3)
- /**
- * @brief Extract the blue component (0 to 255) of a color value.
- */
- #define BLUE_OF(c) (((c)&0x001F)<<3)
-
-#elif GDISP_PIXELFORMAT == GDISP_PIXELFORMAT_MONO
- typedef uint8_t color_t;
- #define COLOR(c) ((color_t)(c))
- #define MASKCOLOR TRUE
- #define RGB2COLOR(r,g,b) ((r|g|b) ? 1 : 0)
- #define HTML2COLOR(h) (h ? 1 : 0)
- #define RED_OF(c) (c ? 255 : 0)
- #define GREEN_OF(c) (c ? 255 : 0)
- #define BLUE_OF(c) (c ? 255 : 0)
-
-#elif GDISP_PIXELFORMAT == GDISP_PIXELFORMAT_RGB565
- typedef uint16_t color_t;
- #define COLOR(c) ((color_t)(c))
- #define MASKCOLOR FALSE
- #define RGB2COLOR(r,g,b) ((color_t)((((r) & 0xF8)<<8) | (((g) & 0xFC)<<3) | (((b) & 0xF8)>>3)))
- #define HTML2COLOR(h) ((color_t)((((h) & 0xF80000)>>8) | (((h) & 0x00FC00)>>5) | (((h) & 0x0000F8)>>3)))
- #define RED_OF(c) (((c)&0xF800)>>8)
- #define GREEN_OF(c) (((c)&0x07E0)>>3)
- #define BLUE_OF(c) (((c)&0x001F)<<3)
-
-#elif GDISP_PIXELFORMAT == GDISP_PIXELFORMAT_BGR565
- typedef uint16_t color_t;
- #define COLOR(c) ((color_t)(c))
- #define MASKCOLOR FALSE
- #define RGB2COLOR(r,g,b) ((color_t)((((r) & 0xF8)>>3) | (((g) & 0xFC)<<3) | (((b) & 0xF8)<<8)))
- #define HTML2COLOR(h) ((color_t)((((h) & 0x0000F8)>>3) | (((h) & 0x00FC00)>>5) | (((h) & 0xF80000)>>8)))
- #define RED_OF(c) (((c)&0x001F)<<3)
- #define GREEN_OF(c) (((c)&0x07E0)>>3)
- #define BLUE_OF(c) (((c)& 0xF800)>>8)
-
-#elif GDISP_PIXELFORMAT == GDISP_PIXELFORMAT_RGB888
- typedef uint32_t color_t;
- #define COLOR(c) ((color_t)(((c) & 0xFFFFFF)))
- #define MASKCOLOR TRUE
- #define RGB2COLOR(r,g,b) ((color_t)((((r) & 0xFF)<<16) | (((g) & 0xFF) << 8) | ((b) & 0xFF)))
- #define HTML2COLOR(h) ((color_t)(h))
- #define RED_OF(c) (((c) & 0xFF0000)>>16)
- #define GREEN_OF(c) (((c)&0x00FF00)>>8)
- #define BLUE_OF(c) ((c)&0x0000FF)
-
-#elif GDISP_PIXELFORMAT == GDISP_PIXELFORMAT_RGB444
- typedef uint16_t color_t;
- #define COLOR(c) ((color_t)(((c) & 0x0FFF)))
- #define MASKCOLOR TRUE
- #define RGB2COLOR(r,g,b) ((color_t)((((r) & 0xF0)<<4) | ((g) & 0xF0) | (((b) & 0xF0)>>4)))
- #define HTML2COLOR(h) ((color_t)((((h) & 0xF00000)>>12) | (((h) & 0x00F000)>>8) | (((h) & 0x0000F0)>>4)))
- #define RED_OF(c) (((c) & 0x0F00)>>4)
- #define GREEN_OF(c) ((c)&0x00F0)
- #define BLUE_OF(c) (((c)&0x000F)<<4)
-
-#elif GDISP_PIXELFORMAT == GDISP_PIXELFORMAT_RGB332
- typedef uint8_t color_t;
- #define COLOR(c) ((color_t)(c))
- #define MASKCOLOR FALSE
- #define RGB2COLOR(r,g,b) ((color_t)(((r) & 0xE0) | (((g) & 0xE0)>>3) | (((b) & 0xC0)>>6)))
- #define HTML2COLOR(h) ((color_t)((((h) & 0xE00000)>>16) | (((h) & 0x00E000)>>11) | (((h) & 0x0000C0)>>6)))
- #define RED_OF(c) ((c) & 0xE0)
- #define GREEN_OF(c) (((c)&0x1C)<<3)
- #define BLUE_OF(c) (((c)&0x03)<<6)
-
-#elif GDISP_PIXELFORMAT == GDISP_PIXELFORMAT_RGB666
- typedef uint32_t color_t;
- #define COLOR(c) ((color_t)(((c) & 0x03FFFF)))
- #define MASKCOLOR TRUE
- #define RGB2COLOR(r,g,b) ((color_t)((((r) & 0xFC)<<10) | (((g) & 0xFC)<<4) | (((b) & 0xFC)>>2)))
- #define HTML2COLOR(h) ((color_t)((((h) & 0xFC0000)>>6) | (((h) & 0x00FC00)>>4) | (((h) & 0x0000FC)>>2)))
- #define RED_OF(c) (((c) & 0x03F000)>>12)
- #define GREEN_OF(c) (((c)&0x00FC00)>>8)
- #define BLUE_OF(c) (((c)&0x00003F)<<2)
-
-#elif GDISP_PIXELFORMAT != GDISP_PIXELFORMAT_CUSTOM
- #error "GDISP: No supported pixel format has been specified."
-#endif
+/* Load our color definitions and pixel formats */
+#include "colors.h"
/**
* @brief The type of a pixel.