|
1 #ifndef SPI8_H |
|
2 #define SPI8_H |
|
3 |
|
4 #define NDEBUG // avoid MBED_ASSERT to halt process when PinName DC==NC |
|
5 |
|
6 #include "mbed.h" |
|
7 #include "Protocols.h" |
|
8 //#include "GraphicsDisplay.h" |
|
9 |
|
10 /** SPI 8bit interface |
|
11 */ |
|
12 class SPI8 : public Protocols |
|
13 { |
|
14 public: |
|
15 |
|
16 /** Create an SPI 8bit display interface with 3 control pins |
|
17 * |
|
18 * @param SPI mosi |
|
19 * @param SPI miso |
|
20 * @param SPI sclk |
|
21 * @param CS pin connected to CS of display |
|
22 * @param reset pin connected to RESET of display |
|
23 * @param DC pin connected to data/command of display |
|
24 */ |
|
25 SPI8(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC=NC); |
|
26 |
|
27 protected: |
|
28 |
|
29 /** Send 8bit command to display controller |
|
30 * |
|
31 * @param cmd: byte to send |
|
32 * |
|
33 */ |
|
34 virtual void wr_cmd8(unsigned char cmd); |
|
35 |
|
36 /** Send 8bit data to display controller |
|
37 * |
|
38 * @param data: byte to send |
|
39 * |
|
40 */ |
|
41 virtual void wr_data8(unsigned char data); |
|
42 |
|
43 /** Send 2x8bit command to display controller |
|
44 * |
|
45 * @param cmd: halfword to send |
|
46 */ |
|
47 virtual void wr_cmd16(unsigned short cmd); |
|
48 |
|
49 /** Send 2x8bit data to display controller |
|
50 * |
|
51 * @param data: halfword to send |
|
52 * |
|
53 */ |
|
54 virtual void wr_data16(unsigned short data); |
|
55 |
|
56 /** Send 16bit pixeldata to display controller |
|
57 * |
|
58 * @param data: halfword to send |
|
59 * |
|
60 */ |
|
61 virtual void wr_gram(unsigned short data); |
|
62 |
|
63 /** Send same 16bit pixeldata to display controller multiple times |
|
64 * |
|
65 * @param data: halfword to send |
|
66 * @param count: how many |
|
67 * |
|
68 */ |
|
69 virtual void wr_gram(unsigned short data, unsigned int count); |
|
70 |
|
71 /** Send array of pixeldata shorts to display controller |
|
72 * |
|
73 * @param data: unsigned short pixeldata array |
|
74 * @param lenght: lenght (in shorts) |
|
75 * |
|
76 */ |
|
77 virtual void wr_grambuf(unsigned short* data, unsigned int lenght); |
|
78 |
|
79 /** Read 16bit pixeldata from display controller (with dummy cycle) |
|
80 * |
|
81 * @param convert true/false. Convert 18bit to 16bit, some controllers returns 18bit |
|
82 * @returns 16bit color |
|
83 */ |
|
84 virtual unsigned short rd_gram(bool convert); |
|
85 |
|
86 /** Read 4x8bit register data (with dummy cycle) |
|
87 * @param reg the register to read |
|
88 * @returns data as uint |
|
89 * |
|
90 */ |
|
91 virtual unsigned int rd_reg_data32(unsigned char reg); |
|
92 |
|
93 /** Read 3x8bit ExtendedCommands register data |
|
94 * @param reg the register to read |
|
95 * @param SPIreadenablecmd vendor/device specific cmd to read EXTC registers |
|
96 * @returns data as uint |
|
97 * @note EXTC regs (0xB0 to 0xFF) are read/write registers but needs special cmd to be read in SPI mode |
|
98 */ |
|
99 virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd); |
|
100 |
|
101 /** ILI932x specific, does a dummy read cycle, number of bits is protocol dependent |
|
102 * for PAR protocols: a signle RD bit toggle |
|
103 * for SPI8: 8clocks |
|
104 * for SPI16: 16 clocks |
|
105 */ |
|
106 virtual void dummyread (); |
|
107 |
|
108 /** ILI932x specific, select register for a successive write or read |
|
109 * |
|
110 * @param reg register to be selected |
|
111 * @param forread false = a write next (default), true = a read next |
|
112 * @note forread only used by SPI protocols |
|
113 */ |
|
114 virtual void reg_select(unsigned char reg, bool forread =false); |
|
115 |
|
116 /** ILI932x specific, write register with data |
|
117 * |
|
118 * @param reg register to write |
|
119 * @param data 16bit data |
|
120 */ |
|
121 virtual void reg_write(unsigned char reg, unsigned short data); |
|
122 |
|
123 /** ILI932x specific, read register |
|
124 * |
|
125 * @param reg register to be read |
|
126 * @returns 16bit register value |
|
127 */ |
|
128 virtual unsigned short reg_read(unsigned char reg); |
|
129 |
|
130 /** HW reset sequence (without display init commands) |
|
131 */ |
|
132 virtual void hw_reset(); |
|
133 |
|
134 /** Set ChipSelect high or low |
|
135 * @param enable 0/1 |
|
136 */ |
|
137 virtual void BusEnable(bool enable); |
|
138 |
|
139 DigitalOut _CS; |
|
140 |
|
141 private: |
|
142 |
|
143 SPI _spi; |
|
144 DigitalOut _reset; |
|
145 DigitalOut _DC; |
|
146 |
|
147 }; |
|
148 #endif |