lib/unigraphic/Protocols.h

Wed, 21 Sep 2016 20:09:21 +0200

author
David Douard <david.douard@logilab.fr>
date
Wed, 21 Sep 2016 20:09:21 +0200
changeset 6
8cb67d7afd79
parent 5
f1c85c2500f2
permissions
-rw-r--r--

[SSD1322] add a copy_to_lcd method that accepts an area

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

mercurial