diff options
Diffstat (limited to 'firmware/export')
-rw-r--r-- | firmware/export/lcd.h | 71 |
1 files changed, 46 insertions, 25 deletions
diff --git a/firmware/export/lcd.h b/firmware/export/lcd.h index 4949f51cdb..22ae5a3763 100644 --- a/firmware/export/lcd.h +++ b/firmware/export/lcd.h | |||
@@ -161,37 +161,58 @@ static inline unsigned lcd_color_to_native(unsigned color) | |||
161 | #endif | 161 | #endif |
162 | 162 | ||
163 | #ifdef HAVE_LCD_COLOR | 163 | #ifdef HAVE_LCD_COLOR |
164 | #if LCD_DEPTH == 16 | 164 | #if LCD_PIXELFORMAT == RGB565 || LCD_PIXELFORMAT == RGB565SWAPPED |
165 | #define LCD_MAX_RED 31 | 165 | #define LCD_MAX_RED 31 |
166 | #define LCD_MAX_GREEN 63 | 166 | #define LCD_MAX_GREEN 63 |
167 | #define LCD_MAX_BLUE 31 | 167 | #define LCD_MAX_BLUE 31 |
168 | #define _RGB_UNPACK_RED(x) ((((x) >> 8) & 0xf8) | ((x) >> 13)) | 168 | #define LCD_RED_BITS 5 |
169 | #define _RGB_UNPACK_GREEN(x) ((((x) >> 3) & 0xfc) | (((x) >> 9) & 0x03)) | 169 | #define LCD_GREEN_BITS 6 |
170 | #define _RGB_UNPACK_BLUE(x) ((((x) << 3) & 0xf8) | (((x) >> 2) & 0x07)) | 170 | #define LCD_BLUE_BITS 5 |
171 | #define _RGBPACK(r, g, b) ( ((((r) * (31*257) + (127*257)) >> 16) << 11) \ | 171 | |
172 | |((((g) * (63*257) + (127*257)) >> 16) << 5) \ | 172 | /* pack/unpack native RGB values */ |
173 | | (((b) * (31*257) + (127*257)) >> 16)) | 173 | #define _RGBPACK_LCD(r, g, b) ( ((r) << 11) | ((g) << 5) | (b) ) |
174 | /* Note: ((x * 257) >> 16) almost equals (x / 255), but it avoids the division, | 174 | #define _RGB_UNPACK_RED_LCD(x) ( (((x) >> 11) ) ) |
175 | * so it's faster when the macro is used for variable r, g, b in the source. */ | 175 | #define _RGB_UNPACK_GREEN_LCD(x) ( (((x) >> 5) & 0x3f) ) |
176 | #define _RGB_UNPACK_BLUE_LCD(x) ( (((x) ) & 0x1f) ) | ||
177 | |||
178 | /* pack/unpack 24-bit RGB values */ | ||
179 | #define _RGBPACK(r, g, b) _RGBPACK_LCD((r) >> 3, (g) >> 2, (b) >> 3) | ||
180 | #define _RGB_UNPACK_RED(x) ( (((x) >> 8) & 0xf8) | (((x) >> 11) & 0x07) ) | ||
181 | #define _RGB_UNPACK_GREEN(x) ( (((x) >> 3) & 0xfc) | (((x) >> 5) & 0x03) ) | ||
182 | #define _RGB_UNPACK_BLUE(x) ( (((x) << 3) & 0xf8) | (((x) ) & 0x07) ) | ||
183 | |||
176 | #if (LCD_PIXELFORMAT == RGB565SWAPPED) | 184 | #if (LCD_PIXELFORMAT == RGB565SWAPPED) |
177 | #define LCD_RGBPACK(r, g, b) ( ((_RGBPACK((r), (g), (b)) & 0xff00) >> 8) \ | 185 | /* RGB3553 */ |
178 | |((_RGBPACK((r), (g), (b)) & 0x00ff) << 8)) | 186 | #define _LCD_UNSWAP_COLOR(x) swap16(x) |
179 | #define RGB_UNPACK_RED(x) _RGB_UNPACK_RED(swap16(x)) | 187 | #define LCD_RGBPACK_LCD(r, g, b) ( (((r) << 3) ) | \ |
180 | #define RGB_UNPACK_GREEN(x) _RGB_UNPACK_GREEN(swap16(x)) | 188 | (((g) >> 3) ) | \ |
181 | #define RGB_UNPACK_BLUE(x) _RGB_UNPACK_BLUE(swap16(x)) | 189 | (((g) & 0x07) << 13) | \ |
190 | (((b) << 8) ) ) | ||
191 | #define LCD_RGBPACK(r, g, b) ( (((r) >> 3) << 3) | \ | ||
192 | (((g) >> 5) ) | \ | ||
193 | (((g) & 0x1c) << 11) | \ | ||
194 | (((b) >> 3) << 8) ) | ||
195 | /* swap color once - not currenly used in static inits */ | ||
196 | #define _SWAPUNPACK(x, _unp_) \ | ||
197 | ({ typeof (x) _x_ = swap16(x); _unp_(_x_); }) | ||
198 | #define RGB_UNPACK_RED(x) _SWAPUNPACK((x), _RGB_UNPACK_RED) | ||
199 | #define RGB_UNPACK_GREEN(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN) | ||
200 | #define RGB_UNPACK_BLUE(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE) | ||
201 | #define RGB_UNPACK_RED_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_RED_LCD) | ||
202 | #define RGB_UNPACK_GREEN_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN_LCD) | ||
203 | #define RGB_UNPACK_BLUE_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE_LCD) | ||
182 | #else | 204 | #else |
183 | #define LCD_RGBPACK(r, g, b) _RGBPACK((r), (g), (b)) | 205 | /* RGB565 */ |
184 | #define RGB_UNPACK_RED(x) _RGB_UNPACK_RED(x) | 206 | #define _LCD_UNSWAP_COLOR(x) (x) |
185 | #define RGB_UNPACK_GREEN(x) _RGB_UNPACK_GREEN(x) | 207 | #define LCD_RGBPACK(r, g, b) _RGBPACK((r), (g), (b)) |
186 | #define RGB_UNPACK_BLUE(x) _RGB_UNPACK_BLUE(x) | 208 | #define LCD_RGBPACK_LCD(r, g, b) _RGBPACK_LCD((r), (g), (b)) |
209 | #define RGB_UNPACK_RED(x) _RGB_UNPACK_RED(x) | ||
210 | #define RGB_UNPACK_GREEN(x) _RGB_UNPACK_GREEN(x) | ||
211 | #define RGB_UNPACK_BLUE(x) _RGB_UNPACK_BLUE(x) | ||
212 | #define RGB_UNPACK_RED_LCD(x) _RGB_UNPACK_RED(x) | ||
213 | #define RGB_UNPACK_GREEN_LCD(x) _RGB_UNPACK_GREEN(x) | ||
214 | #define RGB_UNPACK_BLUE_LCD(x) _RGB_UNPACK_BLUE(x) | ||
187 | #endif | 215 | #endif |
188 | #elif LCD_DEPTH == 18 | ||
189 | #define LCD_MAX_RED 63 | ||
190 | #define LCD_MAX_GREEN 63 | ||
191 | #define LCD_MAX_BLUE 63 | ||
192 | #define LCD_RGBPACK(r, g, b) ( ((((r) * (63*257) + (127*257)) >> 16) << 12) \ | ||
193 | |((((g) * (63*257) + (127*257)) >> 16) << 6) \ | ||
194 | | (((b) * (63*257) + (127*257)) >> 16)) | ||
195 | #else | 216 | #else |
196 | /* other colour depths */ | 217 | /* other colour depths */ |
197 | #endif | 218 | #endif |