lib/unigraphic/SPI8.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 #ifndef SPI8_H
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
2 #define SPI8_H
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
3
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
4 #define NDEBUG // avoid MBED_ASSERT to halt process when PinName DC==NC
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 #include "mbed.h"
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
7 #include "Protocols.h"
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
8 //#include "GraphicsDisplay.h"
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
9
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
10 /** SPI 8bit interface
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
11 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
12 class SPI8 : public Protocols
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
13 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
14 public:
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 /** Create an SPI 8bit display interface with 3 control pins
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
17 *
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
18 * @param SPI mosi
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
19 * @param SPI miso
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
20 * @param SPI sclk
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
21 * @param CS pin connected to CS of display
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
22 * @param reset pin connected to RESET of display
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
23 * @param DC pin connected to data/command of display
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
24 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
25 SPI8(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC=NC);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
26
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
27 protected:
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
28
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
29 /** Send 8bit command to display controller
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
30 *
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
31 * @param cmd: byte to send
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
32 *
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
33 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
34 virtual void wr_cmd8(unsigned char cmd);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
35
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
36 /** Send 8bit data to display controller
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
37 *
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
38 * @param data: byte to send
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
39 *
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
40 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
41 virtual void wr_data8(unsigned char data);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
42
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
43 /** Send 2x8bit command to display controller
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 * @param cmd: halfword to send
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 virtual void wr_cmd16(unsigned short cmd);
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 /** Send 2x8bit data to display controller
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 * @param data: halfword to send
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 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
54 virtual void wr_data16(unsigned short data);
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 /** Send 16bit pixeldata to display controller
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 * @param data: halfword to send
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 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
61 virtual void wr_gram(unsigned short data);
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 /** Send same 16bit pixeldata to display controller multiple times
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 * @param data: halfword to send
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
66 * @param count: how many
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
67 *
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 virtual void wr_gram(unsigned short data, unsigned int count);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
70
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
71 /** Send array of pixeldata shorts to display controller
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
72 *
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
73 * @param data: unsigned short pixeldata array
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
74 * @param lenght: lenght (in shorts)
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_grambuf(unsigned short* data, unsigned int lenght);
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 /** Read 16bit pixeldata from display controller (with dummy cycle)
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 convert true/false. Convert 18bit to 16bit, some controllers returns 18bit
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
82 * @returns 16bit color
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 unsigned short rd_gram(bool convert);
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 /** Read 4x8bit register data (with dummy cycle)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
87 * @param reg the register to read
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
88 * @returns data as uint
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
89 *
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 virtual unsigned int rd_reg_data32(unsigned char reg);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
92
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
93 /** Read 3x8bit ExtendedCommands register data
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
94 * @param reg the register to read
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
95 * @param SPIreadenablecmd vendor/device specific cmd to read EXTC registers
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
96 * @returns data as uint
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
97 * @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
98 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
99 virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
100
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
101 /** 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
102 * for PAR protocols: a signle RD bit toggle
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
103 * for SPI8: 8clocks
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
104 * for SPI16: 16 clocks
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
105 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
106 virtual void dummyread ();
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
107
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
108 /** ILI932x specific, select register for a successive write or read
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
109 *
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
110 * @param reg register to be selected
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
111 * @param forread false = a write next (default), true = a read next
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
112 * @note forread only used by SPI protocols
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 void reg_select(unsigned char reg, bool forread =false);
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 /** ILI932x specific, write register with data
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
117 *
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
118 * @param reg register to write
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
119 * @param data 16bit data
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
120 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
121 virtual void reg_write(unsigned char reg, unsigned short data);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
122
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
123 /** ILI932x specific, read register
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
124 *
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
125 * @param reg register to be read
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
126 * @returns 16bit register value
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
127 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
128 virtual unsigned short reg_read(unsigned char reg);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
129
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
130 /** HW reset sequence (without display init commands)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
131 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
132 virtual void hw_reset();
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
133
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
134 /** Set ChipSelect high or low
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
135 * @param enable 0/1
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 BusEnable(bool enable);
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 DigitalOut _CS;
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 private:
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
142
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
143 SPI _spi;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
144 DigitalOut _reset;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
145 DigitalOut _DC;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
146
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 #endif

mercurial