Wed, 21 Sep 2016 20:09:21 +0200
[SSD1322] add a copy_to_lcd method that accepts an area
5 | 1 | /* mbed UniGraphic library - Abstract protocol class |
2 | * Copyright (c) 2015 Giuliano Dianda | |
3 | * Released under the MIT License: http://mbed.org/license/mit | |
4 | */ | |
5 | ||
6 | /** @file Protocols.h | |
7 | */ | |
8 | #ifndef Protocols_H | |
9 | #define Protocols_H | |
10 | ||
11 | #include "mbed.h" | |
12 | ||
13 | #define RGB24to16(r,g,b) (((r&0xF8)<<8)|((g&0xFC)<<3)|((b&0xF8)>>3)) //5 red | 6 green | 5 blue | |
14 | #define BGR2RGB(color) (((color&0x1F)<<11) | (color&0x7E0) | ((color&0xF800)>>11)) | |
15 | ||
16 | #define FLIP_NONE 0 | |
17 | #define FLIP_X 1 | |
18 | #define FLIP_Y 2 | |
19 | ||
20 | //#define USE_CS | |
21 | ||
22 | /** Protocol types | |
23 | */ | |
24 | #include "platform.h" | |
25 | ||
26 | #if DEVICE_PORTINOUT | |
27 | enum proto_t { | |
28 | PAR_8 /**< Parallel 8bit, port pins 0 to 7 */ | |
29 | ,PAR_16 /**< Parallel 16bit, port pins 0 to 15 */ | |
30 | ,BUS_8 /**< Parallel 8bit, scattered pins */ | |
31 | ,BUS_16 /**< Parallel 16bit, scattered pins */ | |
32 | ,SPI_8 /**< SPI 8bit */ | |
33 | ,SPI_16 /**< SPI 16bit */ | |
34 | }; | |
35 | #else | |
36 | enum proto_t { | |
37 | BUS_8 /**< Parallel 8bit, scattered pins */ | |
38 | ,BUS_16 /**< Parallel 16bit, scattered pins */ | |
39 | ,SPI_8 /**< SPI 8bit */ | |
40 | ,SPI_16 /**< SPI 16bit */ | |
41 | }; | |
42 | #endif | |
43 | ||
44 | ||
45 | /** Abstract interface class for spi and parallel protocols | |
46 | */ | |
47 | class Protocols | |
48 | { | |
49 | public: | |
50 | ||
51 | /** Send 8bit command to display controller | |
52 | * | |
53 | * @param cmd: byte to send | |
54 | * | |
55 | */ | |
56 | virtual void wr_cmd8(unsigned char cmd) = 0; | |
57 | ||
58 | /** Send 8bit data to display controller | |
59 | * | |
60 | * @param data: byte to send | |
61 | * | |
62 | */ | |
63 | virtual void wr_data8(unsigned char data) = 0; | |
64 | ||
65 | /** Send 2x8bit command to display controller | |
66 | * | |
67 | * @param cmd: halfword to send | |
68 | * | |
69 | */ | |
70 | virtual void wr_cmd16(unsigned short cmd) = 0; | |
71 | ||
72 | /** Send 2x8bit data to display controller | |
73 | * | |
74 | * @param data: halfword to send | |
75 | * | |
76 | */ | |
77 | virtual void wr_data16(unsigned short data) = 0; | |
78 | ||
79 | /** Send 16bit pixeldata to display controller | |
80 | * | |
81 | * @param data: halfword to send | |
82 | * | |
83 | */ | |
84 | virtual void wr_gram(unsigned short data) = 0; | |
85 | ||
86 | /** Send same 16bit pixeldata to display controller multiple times | |
87 | * | |
88 | * @param data: halfword to send | |
89 | * @param count: how many | |
90 | * | |
91 | */ | |
92 | virtual void wr_gram(unsigned short data, unsigned int count) = 0; | |
93 | ||
94 | /** Send array of pixeldata shorts to display controller | |
95 | * | |
96 | * @param data: unsigned short pixeldata array | |
97 | * @param lenght: lenght (in shorts) | |
98 | * | |
99 | */ | |
100 | virtual void wr_grambuf(unsigned short* data, unsigned int lenght) = 0; | |
101 | ||
102 | /** Read 16bit pixeldata from display controller (with dummy cycle) | |
103 | * | |
104 | * @param convert true/false. Convert 18bit to 16bit, some controllers returns 18bit | |
105 | * @returns 16bit color | |
106 | */ | |
107 | virtual unsigned short rd_gram(bool convert) = 0; | |
108 | ||
109 | /** Read 4x8bit register data (with dummy cycle) | |
110 | * @param reg the register to read | |
111 | * @returns data as uint | |
112 | * | |
113 | */ | |
114 | virtual unsigned int rd_reg_data32(unsigned char reg) = 0; | |
115 | ||
116 | /** Read 3x8bit ExtendedCommands register data | |
117 | * @param reg the register to read | |
118 | * @param SPIreadenablecmd vendor/device specific cmd to read EXTC registers | |
119 | * @returns data as uint | |
120 | * @note EXTC regs (0xB0 to 0xFF) are read/write registers but needs special cmd to be read in SPI mode | |
121 | */ | |
122 | virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd) = 0; | |
123 | ||
124 | /** ILI932x specific, does a dummy read cycle, number of bits is protocol dependent | |
125 | * for PAR protocols: a signle RD bit toggle | |
126 | * for SPI8: 8clocks | |
127 | * for SPI16: 16 clocks | |
128 | */ | |
129 | virtual void dummyread () = 0; | |
130 | ||
131 | /** ILI932x specific, select register for a successive write or read | |
132 | * | |
133 | * @param reg register to be selected | |
134 | * @param forread false = a write next (default), true = a read next | |
135 | * @note forread only used by SPI protocols | |
136 | */ | |
137 | virtual void reg_select(unsigned char reg, bool forread =false) = 0; | |
138 | ||
139 | /** ILI932x specific, write register with data | |
140 | * | |
141 | * @param reg register to write | |
142 | * @param data 16bit data | |
143 | */ | |
144 | virtual void reg_write(unsigned char reg, unsigned short data) = 0; | |
145 | ||
146 | /** ILI932x specific, read register | |
147 | * | |
148 | * @param reg register to be read | |
149 | * @returns 16bit register value | |
150 | */ | |
151 | virtual unsigned short reg_read(unsigned char reg) = 0; | |
152 | ||
153 | /** HW reset sequence (without display init commands) | |
154 | */ | |
155 | virtual void hw_reset() = 0; | |
156 | ||
157 | /** Set ChipSelect high or low | |
158 | * @param enable 0/1 | |
159 | */ | |
160 | virtual void BusEnable(bool enable) = 0; | |
161 | ||
162 | }; | |
163 | #endif |