1 /**************************************************************************/
4 @author K. Townsend (microBuilder.eu)
8 Software License Agreement (BSD License)
10 Copyright (c) 2010, microBuilder SARL
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 1. Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 2. Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 3. Neither the name of the copyright holders nor the
21 names of its contributors may be used to endorse or promote products
22 derived from this software without specific prior written permission.
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 /**************************************************************************/
39 #include "projectconfig.h"
41 #include "drivers/displays/tft/lcd.h"
42 #include "core/gpio/gpio.h"
45 #define ILI9328_CS_PORT 1 // CS (LCD Pin 7)
46 #define ILI9328_CS_PIN 8
47 #define ILI9328_CD_PORT 1 // CS/RS (LCD Pin 8)
48 #define ILI9328_CD_PIN 9
49 #define ILI9328_WR_PORT 1 // WR (LCD Pin 9)
50 #define ILI9328_WR_PIN 10
51 #define ILI9328_RD_PORT 1 // RD (LCD Pin 10)
52 #define ILI9328_RD_PIN 11
54 // These combined pin definitions are for optimisation purposes.
55 // If the pin values above are modified the bit equivalents
56 // below will also need to be updated
57 #define ILI9328_CS_CD_PINS 0x300 // 8 + 9
58 #define ILI9328_RD_WR_PINS 0xC00 // 11 + 10
59 #define ILI9328_WR_CS_PINS 0x500 // 10 + 8
60 #define ILI9328_CD_RD_WR_PINS 0xE00 // 9 + 11 + 10
61 #define ILI9328_CS_CD_RD_WR_PINS 0xF00 // 8 + 9 + 11 + 10
63 // Backlight and Reset pins
64 #define ILI9328_RES_PORT 3 // LCD Reset (LCD Pin 31)
65 #define ILI9328_RES_PIN 3
66 #define ILI9328_BL_PORT 2 // Backlight Enable (LCD Pin 16)
67 #define ILI9328_BL_PIN 9
70 // Note: data pins must be consecutive and on the same port
71 #define ILI9328_DATA_PORT 2 // 8-Pin Data Port
72 #define ILI9328_DATA_PIN1 1
73 #define ILI9328_DATA_PIN2 2
74 #define ILI9328_DATA_PIN3 3
75 #define ILI9328_DATA_PIN4 4
76 #define ILI9328_DATA_PIN5 5
77 #define ILI9328_DATA_PIN6 6
78 #define ILI9328_DATA_PIN7 7
79 #define ILI9328_DATA_PIN8 8
80 #define ILI9328_DATA_MASK 0x000001FE
81 #define ILI9328_DATA_OFFSET 1 // Offset = PIN1
83 // Placed here to try to keep all pin specific values in header file
84 #define ILI9328_DISABLEPULLUPS() do { gpioSetPullup(&IOCON_PIO2_1, gpioPullupMode_Inactive); \
85 gpioSetPullup(&IOCON_PIO2_2, gpioPullupMode_Inactive); \
86 gpioSetPullup(&IOCON_PIO2_3, gpioPullupMode_Inactive); \
87 gpioSetPullup(&IOCON_PIO2_4, gpioPullupMode_Inactive); \
88 gpioSetPullup(&IOCON_PIO2_5, gpioPullupMode_Inactive); \
89 gpioSetPullup(&IOCON_PIO2_6, gpioPullupMode_Inactive); \
90 gpioSetPullup(&IOCON_PIO2_7, gpioPullupMode_Inactive); \
91 gpioSetPullup(&IOCON_PIO2_8, gpioPullupMode_Inactive); } while (0)
93 // These registers allow fast single operation clear+set of bits (see section 8.5.1 of LPC1343 UM)
94 #define ILI9328_GPIO2DATA_DATA (*(pREG32 (GPIO_GPIO2_BASE + (ILI9328_DATA_MASK << 2))))
95 #define ILI9328_GPIO1DATA_WR (*(pREG32 (GPIO_GPIO1_BASE + ((1 << ILI9328_WR_PIN) << 2))))
96 #define ILI9328_GPIO1DATA_CD (*(pREG32 (GPIO_GPIO1_BASE + ((1 << ILI9328_CD_PIN) << 2))))
97 #define ILI9328_GPIO1DATA_CS (*(pREG32 (GPIO_GPIO1_BASE + ((1 << ILI9328_CS_PIN) << 2))))
98 #define ILI9328_GPIO1DATA_RD (*(pREG32 (GPIO_GPIO1_BASE + ((1 << ILI9328_RD_PIN) << 2))))
99 #define ILI9328_GPIO3DATA_RES (*(pREG32 (GPIO_GPIO3_BASE + ((1 << ILI9328_RES_PIN) << 2))))
100 #define ILI9328_GPIO1DATA_CS_CD (*(pREG32 (GPIO_GPIO1_BASE + ((ILI9328_CS_CD_PINS) << 2))))
101 #define ILI9328_GPIO1DATA_RD_WR (*(pREG32 (GPIO_GPIO1_BASE + ((ILI9328_RD_WR_PINS) << 2))))
102 #define ILI9328_GPIO1DATA_WR_CS (*(pREG32 (GPIO_GPIO1_BASE + ((ILI9328_WR_CS_PINS) << 2))))
103 #define ILI9328_GPIO1DATA_CD_RD_WR (*(pREG32 (GPIO_GPIO1_BASE + ((ILI9328_CD_RD_WR_PINS) << 2))))
104 #define ILI9328_GPIO1DATA_CS_CD_RD_WR (*(pREG32 (GPIO_GPIO1_BASE + ((ILI9328_CS_CD_RD_WR_PINS) << 2))))
106 // Macros to set data bus direction to input/output
107 #define ILI9328_GPIO2DATA_SETINPUT GPIO_GPIO2DIR &= ~ILI9328_DATA_MASK
108 #define ILI9328_GPIO2DATA_SETOUTPUT GPIO_GPIO2DIR |= ILI9328_DATA_MASK
110 // Macros for control line state
111 // NOPs required since the bit-banding is too fast for some ILI9328s to handle :(
112 #define CLR_CD ILI9328_GPIO1DATA_CD = (0); __asm volatile("nop");
113 #define SET_CD ILI9328_GPIO1DATA_CD = (1 << ILI9328_CD_PIN); __asm volatile("nop");
114 #define CLR_CS ILI9328_GPIO1DATA_CS = (0); __asm volatile("nop");
115 #define SET_CS ILI9328_GPIO1DATA_CS = (1 << ILI9328_CS_PIN); __asm volatile("nop");
116 #define CLR_WR ILI9328_GPIO1DATA_WR = (0); __asm volatile("nop");
117 #define SET_WR ILI9328_GPIO1DATA_WR = (1 << ILI9328_WR_PIN); __asm volatile("nop");
118 #define CLR_RD ILI9328_GPIO1DATA_RD = (0); __asm volatile("nop");
119 #define SET_RD ILI9328_GPIO1DATA_RD = (1 << ILI9328_RD_PIN); __asm volatile("nop");
120 #define CLR_RESET ILI9328_GPIO3DATA_RES = (0); __asm volatile("nop");
121 #define SET_RESET ILI9328_GPIO3DATA_RES = (1 << ILI9328_RES_PIN); __asm volatile("nop");
123 // These 'combined' macros are defined to improve code performance by
124 // reducing the number of instructions in heavily used functions
125 #define CLR_CS_CD ILI9328_GPIO1DATA_CS_CD = (0); __asm volatile("nop");
126 #define SET_RD_WR ILI9328_GPIO1DATA_RD_WR = (ILI9328_RD_WR_PINS); __asm volatile("nop");
127 #define SET_WR_CS ILI9328_GPIO1DATA_WR_CS = (ILI9328_WR_CS_PINS); __asm volatile("nop");
128 #define SET_CD_RD_WR ILI9328_GPIO1DATA_CD_RD_WR = (ILI9328_CD_RD_WR_PINS); __asm volatile("nop");
129 #define CLR_CS_CD_SET_RD_WR ILI9328_GPIO1DATA_CS_CD_RD_WR = (ILI9328_RD_WR_PINS); __asm volatile("nop");
130 #define CLR_CS_SET_CD_RD_WR ILI9328_GPIO1DATA_CS_CD_RD_WR = (ILI9328_CD_RD_WR_PINS); __asm volatile("nop");
134 ILI9328_COMMANDS_DRIVERCODEREAD
= 0x0000,
135 ILI9328_COMMANDS_DRIVEROUTPUTCONTROL1
= 0x0001,
136 ILI9328_COMMANDS_LCDDRIVINGCONTROL
= 0x0002,
137 ILI9328_COMMANDS_ENTRYMODE
= 0x0003,
138 ILI9328_COMMANDS_RESIZECONTROL
= 0x0004,
139 ILI9328_COMMANDS_DISPLAYCONTROL1
= 0x0007,
140 ILI9328_COMMANDS_DISPLAYCONTROL2
= 0x0008,
141 ILI9328_COMMANDS_DISPLAYCONTROL3
= 0x0009,
142 ILI9328_COMMANDS_DISPLAYCONTROL4
= 0x000A,
143 ILI9328_COMMANDS_RGBDISPLAYINTERFACECONTROL1
= 0x000C,
144 ILI9328_COMMANDS_FRAMEMAKERPOSITION
= 0x000D,
145 ILI9328_COMMANDS_RGBDISPLAYINTERFACECONTROL2
= 0x000F,
146 ILI9328_COMMANDS_POWERCONTROL1
= 0x0010,
147 ILI9328_COMMANDS_POWERCONTROL2
= 0x0011,
148 ILI9328_COMMANDS_POWERCONTROL3
= 0x0012,
149 ILI9328_COMMANDS_POWERCONTROL4
= 0x0013,
150 ILI9328_COMMANDS_HORIZONTALGRAMADDRESSSET
= 0x0020,
151 ILI9328_COMMANDS_VERTICALGRAMADDRESSSET
= 0x0021,
152 ILI9328_COMMANDS_WRITEDATATOGRAM
= 0x0022,
153 ILI9328_COMMANDS_POWERCONTROL7
= 0x0029,
154 ILI9328_COMMANDS_FRAMERATEANDCOLORCONTROL
= 0x002B,
155 ILI9328_COMMANDS_GAMMACONTROL1
= 0x0030,
156 ILI9328_COMMANDS_GAMMACONTROL2
= 0x0031,
157 ILI9328_COMMANDS_GAMMACONTROL3
= 0x0032,
158 ILI9328_COMMANDS_GAMMACONTROL4
= 0x0035,
159 ILI9328_COMMANDS_GAMMACONTROL5
= 0x0036,
160 ILI9328_COMMANDS_GAMMACONTROL6
= 0x0037,
161 ILI9328_COMMANDS_GAMMACONTROL7
= 0x0038,
162 ILI9328_COMMANDS_GAMMACONTROL8
= 0x0039,
163 ILI9328_COMMANDS_GAMMACONTROL9
= 0x003C,
164 ILI9328_COMMANDS_GAMMACONTROL10
= 0x003D,
165 ILI9328_COMMANDS_HORIZONTALADDRESSSTARTPOSITION
= 0x0050,
166 ILI9328_COMMANDS_HORIZONTALADDRESSENDPOSITION
= 0x0051,
167 ILI9328_COMMANDS_VERTICALADDRESSSTARTPOSITION
= 0x0052,
168 ILI9328_COMMANDS_VERTICALADDRESSENDPOSITION
= 0x0053,
169 ILI9328_COMMANDS_DRIVEROUTPUTCONTROL2
= 0x0060,
170 ILI9328_COMMANDS_BASEIMAGEDISPLAYCONTROL
= 0x0061,
171 ILI9328_COMMANDS_VERTICALSCROLLCONTROL
= 0x006A,
172 ILI9328_COMMANDS_PARTIALIMAGE1DISPLAYPOSITION
= 0x0080,
173 ILI9328_COMMANDS_PARTIALIMAGE1AREASTARTLINE
= 0x0081,
174 ILI9328_COMMANDS_PARTIALIMAGE1AREAENDLINE
= 0x0082,
175 ILI9328_COMMANDS_PARTIALIMAGE2DISPLAYPOSITION
= 0x0083,
176 ILI9328_COMMANDS_PARTIALIMAGE2AREASTARTLINE
= 0x0084,
177 ILI9328_COMMANDS_PARTIALIMAGE2AREAENDLINE
= 0x0085,
178 ILI9328_COMMANDS_PANELINTERFACECONTROL1
= 0x0090,
179 ILI9328_COMMANDS_PANELINTERFACECONTROL2
= 0x0092,
180 ILI9328_COMMANDS_PANELINTERFACECONTROL4
= 0x0095,
181 ILI9328_COMMANDS_OTPVCMPROGRAMMINGCONTROL
= 0x00A1,
182 ILI9328_COMMANDS_OTPVCMSTATUSANDENABLE
= 0x00A2,
183 ILI9328_COMMANDS_OTPPROGRAMMINGIDKEY
= 0x00A5