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 ST7783_CS_PORT 1 // CS (LCD Pin 7)
46 #define ST7783_CS_PIN 8
47 #define ST7783_CD_PORT 1 // CS/RS (LCD Pin 8)
48 #define ST7783_CD_PIN 9
49 #define ST7783_WR_PORT 1 // WR (LCD Pin 9)
50 #define ST7783_WR_PIN 10
51 #define ST7783_RD_PORT 1 // RD (LCD Pin 10)
52 #define ST7783_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 ST7783_CS_CD_PINS 0x300 // 8 + 9
58 #define ST7783_RD_WR_PINS 0xC00 // 11 + 10
59 #define ST7783_WR_CS_PINS 0x500 // 10 + 8
60 #define ST7783_CD_RD_WR_PINS 0xE00 // 9 + 11 + 10
61 #define ST7783_CS_CD_RD_WR_PINS 0xF00 // 8 + 9 + 11 + 10
63 // Backlight and Reset pins
64 #define ST7783_RES_PORT 3 // LCD Reset (LCD Pin 31)
65 #define ST7783_RES_PIN 3
66 #define ST7783_BL_PORT 2 // Backlight Enable (LCD Pin 16)
67 #define ST7783_BL_PIN 9
70 // Note: data pins must be consecutive and on the same port
71 #define ST7783_DATA_PORT 2 // 8-Pin Data Port
72 #define ST7783_DATA_PIN1 1
73 #define ST7783_DATA_PIN2 2
74 #define ST7783_DATA_PIN3 3
75 #define ST7783_DATA_PIN4 4
76 #define ST7783_DATA_PIN5 5
77 #define ST7783_DATA_PIN6 6
78 #define ST7783_DATA_PIN7 7
79 #define ST7783_DATA_PIN8 8
80 #define ST7783_DATA_MASK 0x000001FE
81 #define ST7783_DATA_OFFSET 1 // Offset = PIN1
83 // Placed here to try to keep all pin specific values in header file
84 #define ST7783_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 ST7783_GPIO2DATA_DATA (*(pREG32 (GPIO_GPIO2_BASE + (ST7783_DATA_MASK << 2))))
95 #define ST7783_GPIO1DATA_WR (*(pREG32 (GPIO_GPIO1_BASE + ((1 << ST7783_WR_PIN) << 2))))
96 #define ST7783_GPIO1DATA_CD (*(pREG32 (GPIO_GPIO1_BASE + ((1 << ST7783_CD_PIN) << 2))))
97 #define ST7783_GPIO1DATA_CS (*(pREG32 (GPIO_GPIO1_BASE + ((1 << ST7783_CS_PIN) << 2))))
98 #define ST7783_GPIO1DATA_RD (*(pREG32 (GPIO_GPIO1_BASE + ((1 << ST7783_RD_PIN) << 2))))
99 #define ST7783_GPIO3DATA_RES (*(pREG32 (GPIO_GPIO3_BASE + ((1 << ST7783_RES_PIN) << 2))))
100 #define ST7783_GPIO1DATA_CS_CD (*(pREG32 (GPIO_GPIO1_BASE + ((ST7783_CS_CD_PINS) << 2))))
101 #define ST7783_GPIO1DATA_RD_WR (*(pREG32 (GPIO_GPIO1_BASE + ((ST7783_RD_WR_PINS) << 2))))
102 #define ST7783_GPIO1DATA_WR_CS (*(pREG32 (GPIO_GPIO1_BASE + ((ST7783_WR_CS_PINS) << 2))))
103 #define ST7783_GPIO1DATA_CD_RD_WR (*(pREG32 (GPIO_GPIO1_BASE + ((ST7783_CD_RD_WR_PINS) << 2))))
104 #define ST7783_GPIO1DATA_CS_CD_RD_WR (*(pREG32 (GPIO_GPIO1_BASE + ((ST7783_CS_CD_RD_WR_PINS) << 2))))
106 // Macros to set data bus direction to input/output
107 #define ST7783_GPIO2DATA_SETINPUT GPIO_GPIO2DIR &= ~ST7783_DATA_MASK
108 #define ST7783_GPIO2DATA_SETOUTPUT GPIO_GPIO2DIR |= ST7783_DATA_MASK
110 // Macros for control line state
111 #define CLR_CD ST7783_GPIO1DATA_CD = (0)
112 #define SET_CD ST7783_GPIO1DATA_CD = (1 << ST7783_CD_PIN)
113 #define CLR_CS ST7783_GPIO1DATA_CS = (0)
114 #define SET_CS ST7783_GPIO1DATA_CS = (1 << ST7783_CS_PIN)
115 #define CLR_WR ST7783_GPIO1DATA_WR = (0)
116 #define SET_WR ST7783_GPIO1DATA_WR = (1 << ST7783_WR_PIN)
117 #define CLR_RD ST7783_GPIO1DATA_RD = (0)
118 #define SET_RD ST7783_GPIO1DATA_RD = (1 << ST7783_RD_PIN)
119 #define CLR_RESET ST7783_GPIO3DATA_RES = (0)
120 #define SET_RESET ST7783_GPIO3DATA_RES = (1 << ST7783_RES_PIN)
122 // These 'combined' macros are defined to improve code performance by
123 // reducing the number of instructions in heavily used functions
124 #define CLR_CS_CD ST7783_GPIO1DATA_CS_CD = (0);
125 #define SET_RD_WR ST7783_GPIO1DATA_RD_WR = (ST7783_RD_WR_PINS);
126 #define SET_WR_CS ST7783_GPIO1DATA_WR_CS = (ST7783_WR_CS_PINS);
127 #define SET_CD_RD_WR ST7783_GPIO1DATA_CD_RD_WR = (ST7783_CD_RD_WR_PINS);
128 #define CLR_CS_CD_SET_RD_WR ST7783_GPIO1DATA_CS_CD_RD_WR = (ST7783_RD_WR_PINS);
129 #define CLR_CS_SET_CD_RD_WR ST7783_GPIO1DATA_CS_CD_RD_WR = (ST7783_CD_RD_WR_PINS);
This page took 0.084015 seconds and 5 git commands to generate.