YAHAL
Yet Another Hardware Abstraction Library
Loading...
Searching...
No Matches
lcd_interface.h
1// ---------------------------------------------
2// This file is part of
3// _ _ __ _ _ __ __
4// ( \/ ) /__\ ( )_( ) /__\ ( )
5// \ / /(__)\ ) _ ( /(__)\ )(__
6// (__)(__)(__)(_) (_)(__)(__)(____)
7//
8// Yet Another HW Abstraction Library
9// Copyright (C) Andreas Terstegge
10// BSD Licensed (see file LICENSE)
11//
12// ---------------------------------------------
13//
14// This file defines a generic interface for
15// LCD drivers.
16
17#ifndef _LCD_INTERFACE_H_
18#define _LCD_INTERFACE_H_
19
20#include <stdint.h>
21#include <cassert>
22
23// Colors use a 32-bit integer. The upper 8 bits
24// define the concrete color type.
25typedef uint32_t color_t;
26#define COLOR_TYPE(c) (c & 0xff000000)
27#define COLOR_RGB(c) (c & 0x00ffffff)
28
29namespace LCD {
30const uint32_t COLORTYPE_RGB888 = 0x00000000;
31const uint32_t COLORTYPE_RGB565 = 0x01000000;
32const uint32_t COLORTYPE_RGB555 = 0x02000000;
33}
34
35// Small interface for a pixel data stream
37public:
38 virtual color_t getColorType() = 0;
39 virtual color_t getNext() = 0;
40 virtual void reset() = 0;
41
42protected:
43 ~pixel_stream() = default;
44};
45
46
48public:
49
50 // Getters for screen dimensions
51 virtual uint16_t getSizeX() = 0;
52 virtual uint16_t getSizeY() = 0;
53
54 // Basic graphic methods
55 // x and y range from 0 to getX/YSize() - 1
56 // It is assumed that xs < xe and ys < ye !!
57 virtual void drawPixel(uint16_t xs, uint16_t ys, color_t color) = 0;
58 virtual void drawHLine(uint16_t xs, uint16_t ys, uint16_t xe, color_t c) = 0;
59 virtual void drawVLine(uint16_t xs, uint16_t ys, uint16_t ye, color_t c) = 0;
60
61 // Fill rectangle with data coming from a pixel stream
62 virtual void drawArea (uint16_t xs, uint16_t ys, uint16_t xe, uint16_t ye,
63 pixel_stream & ps) = 0;
64
65 // Fill rectangle with a specific color
66 virtual void fillArea (uint16_t xs, uint16_t ys, uint16_t xe, uint16_t ye,
67 color_t c) = 0;
68
69 // Translate from one color_t to another
70 color_t convertColor(color_t c, color_t return_type ) {
71 color_t in_type = COLOR_TYPE(c);
72
73 // Do nothing if color types match
74 if (in_type == return_type) return c;
75
76 // RGB888 -> RGB565
77 if (in_type == LCD::COLORTYPE_RGB888 &&
78 return_type == LCD::COLORTYPE_RGB565) {
79 return( ((c & 0x00f80000) >> 8) |
80 ((c & 0x0000fc00) >> 5) |
81 ((c & 0x000000f8) >> 3) |
82 LCD::COLORTYPE_RGB565 );
83 }
84 assert(false);
85 return 0;
86 }
87
88protected:
89 virtual ~lcd_interface() = default;
90};
91
92#endif // _LCD_INTERFACE_H_