Line No. | Rev | Author | Line |
---|---|---|---|
1 | 32 | kaklik | |
2 | /***************************************************************************** |
||
3 | * Module for Microchip Graphics Library |
||
4 | * PMP driver |
||
5 | ***************************************************************************** |
||
6 | * FileName: pmp.c |
||
7 | * Dependencies: Graphics.h |
||
8 | * Processor: PIC24, PIC32 |
||
9 | * Compiler: MPLAB C30, MPLAB C32 |
||
10 | * Linker: MPLAB LINK30, MPLAB LINK32 |
||
11 | * Company: Microchip Technology Incorporated |
||
12 | * |
||
13 | * Software License Agreement |
||
14 | * |
||
15 | * Copyright © 2010 Microchip Technology Inc. All rights reserved. |
||
16 | * Microchip licenses to you the right to use, modify, copy and distribute |
||
17 | * Software only when embedded on a Microchip microcontroller or digital |
||
18 | * signal controller, which is integrated into your product or third party |
||
19 | * product (pursuant to the sublicense terms in the accompanying license |
||
20 | * agreement). |
||
21 | * |
||
22 | * You should refer to the license agreement accompanying this Software |
||
23 | * for additional information regarding your rights and obligations. |
||
24 | * |
||
25 | * SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY |
||
26 | * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY |
||
27 | * OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR |
||
28 | * PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR |
||
29 | * OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, |
||
30 | * BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT |
||
31 | * DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, |
||
32 | * INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, |
||
33 | * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY |
||
34 | * CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), |
||
35 | * OR OTHER SIMILAR COSTS. |
||
36 | * |
||
37 | * Author Date Comment |
||
38 | *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
||
39 | * Anton Alkhimenok 01/12/10 |
||
40 | *****************************************************************************/ |
||
41 | #ifndef _GFX_PMP_H_FILE |
||
42 | #define _GFX_PMP_H_FILE |
||
43 | |||
44 | #include "Graphics\Graphics.h" |
||
45 | #include "Compiler.h" |
||
46 | |||
47 | #ifdef USE_GFX_PMP |
||
48 | |||
49 | /********************************************************************* |
||
50 | * Graphic Controller PMP wait states |
||
51 | * |
||
52 | * The setup time required when running the SSD1926 at 80MHz is |
||
53 | * 50ns or (20 MHz). |
||
54 | * |
||
55 | * To calculate the number of required wait states, we will use the |
||
56 | * following equation. |
||
57 | * |
||
58 | * wait states = Peripheral Clock (Hz) / setup time (Hz) |
||
59 | * |
||
60 | * For example if you peripheral clock is running at 80 MHz, the |
||
61 | * wait states required: |
||
62 | * wait states = 80,000,000 / 20,000,000 |
||
63 | * wait states = 4 |
||
64 | *********************************************************************/ |
||
65 | #if (DISPLAY_CONTROLLER == LGDP4531) |
||
66 | #define DISPLAY_CONTROLLER_SETUP_Hz (20000000) |
||
67 | #endif |
||
68 | #if (DISPLAY_CONTROLLER == SSD1926) |
||
69 | #define DISPLAY_CONTROLLER_SETUP_Hz (20000000) |
||
70 | #endif |
||
71 | |||
72 | #define PMP_WAIT_STATES (GetPeripheralClock() / DISPLAY_CONTROLLER_SETUP_Hz) |
||
73 | #ifdef __PIC32MX__ |
||
74 | #define PMDIN1 PMDIN |
||
75 | #endif |
||
76 | /********************************************************************* |
||
77 | * Macros: PMPWaitBusy() |
||
78 | * |
||
79 | * Overview: waits for PMP cycle end. |
||
80 | * |
||
81 | * PreCondition: none |
||
82 | * |
||
83 | * Input: none |
||
84 | * |
||
85 | * Output: none |
||
86 | * |
||
87 | * Side Effects: none |
||
88 | * |
||
89 | ********************************************************************/ |
||
90 | #define PMPWaitBusy() while(PMMODEbits.BUSY); |
||
91 | |||
92 | /********************************************************************* |
||
93 | * Function: void DeviceSetCommand() |
||
94 | * |
||
95 | * Overview: set RS line to access a control register space |
||
96 | * |
||
97 | * PreCondition: none |
||
98 | * |
||
99 | * Input: none |
||
100 | * |
||
101 | * Output: none |
||
102 | * |
||
103 | * Side Effects: none |
||
104 | * |
||
105 | ********************************************************************/ |
||
106 | extern inline void __attribute__ ((always_inline)) DeviceSetCommand() |
||
107 | { |
||
108 | RS_LAT_BIT = 0; |
||
109 | } |
||
110 | |||
111 | /********************************************************************* |
||
112 | * Function: void DeviceSetData() |
||
113 | * |
||
114 | * Overview: set RS line to access a data space |
||
115 | * |
||
116 | * PreCondition: none |
||
117 | * |
||
118 | * Input: none |
||
119 | * |
||
120 | * Output: none |
||
121 | * |
||
122 | * Side Effects: none |
||
123 | * |
||
124 | ********************************************************************/ |
||
125 | extern inline void __attribute__ ((always_inline)) DeviceSetData() |
||
126 | { |
||
127 | RS_LAT_BIT = 1; |
||
128 | } |
||
129 | |||
130 | /********************************************************************* |
||
131 | * Function: void DeviceSelect() |
||
132 | * |
||
133 | * Overview: asserts the chip select line |
||
134 | * |
||
135 | * PreCondition: none |
||
136 | * |
||
137 | * Input: none |
||
138 | * |
||
139 | * Output: none |
||
140 | * |
||
141 | * Side Effects: none |
||
142 | * |
||
143 | ********************************************************************/ |
||
144 | extern inline void __attribute__ ((always_inline)) DeviceSelect() |
||
145 | { |
||
146 | CS_LAT_BIT = 0; |
||
147 | } |
||
148 | |||
149 | /********************************************************************* |
||
150 | * Function: void DeviceDeselect() |
||
151 | * |
||
152 | * Overview: puts the chip select line in inactive state |
||
153 | * |
||
154 | * PreCondition: none |
||
155 | * |
||
156 | * Input: none |
||
157 | * |
||
158 | * Output: none |
||
159 | * |
||
160 | * Side Effects: none |
||
161 | * |
||
162 | ********************************************************************/ |
||
163 | extern inline void __attribute__ ((always_inline)) DeviceDeselect() |
||
164 | { |
||
165 | CS_LAT_BIT = 1; |
||
166 | } |
||
167 | |||
168 | /********************************************************************* |
||
169 | * Macros: DeviceWrite(data) |
||
170 | * |
||
171 | * PreCondition: none |
||
172 | * |
||
173 | * Input: data - value to be written to RAM |
||
174 | * |
||
175 | * Output: none |
||
176 | * |
||
177 | * Side Effects: none |
||
178 | * |
||
179 | * Overview: writes data into controller's RAM |
||
180 | * |
||
181 | * Note: chip select should be enabled |
||
182 | * |
||
183 | ********************************************************************/ |
||
184 | #ifdef USE_16BIT_PMP |
||
185 | |||
186 | extern inline void __attribute__ ((always_inline)) DeviceWrite(WORD data) |
||
187 | { |
||
188 | PMDIN1 = data; |
||
189 | PMPWaitBusy(); |
||
190 | } |
||
191 | |||
192 | #else |
||
193 | |||
194 | extern inline void __attribute__ ((always_inline)) DeviceWrite(BYTE data) |
||
195 | { |
||
196 | PMDIN1 = data; |
||
197 | PMPWaitBusy(); |
||
198 | } |
||
199 | |||
200 | #endif |
||
201 | |||
202 | /********************************************************************* |
||
203 | * Macros: DeviceRead() |
||
204 | * |
||
205 | * PreCondition: none |
||
206 | * |
||
207 | * Input: none |
||
208 | * |
||
209 | * Output: data read |
||
210 | * |
||
211 | * Side Effects: none |
||
212 | * |
||
213 | * Overview: reads data from controller's RAM |
||
214 | * |
||
215 | * Note: chip select should be enabled |
||
216 | * |
||
217 | ********************************************************************/ |
||
218 | #ifdef USE_16BIT_PMP |
||
219 | |||
220 | extern inline WORD __attribute__ ((always_inline)) DeviceRead() |
||
221 | { |
||
222 | WORD value; |
||
223 | value = PMDIN1; |
||
224 | PMPWaitBusy(); |
||
225 | PMCONbits.PMPEN = 0; // disable PMP |
||
226 | value = PMDIN1; |
||
227 | PMPWaitBusy(); |
||
228 | PMCONbits.PMPEN = 1; // enable PMP |
||
229 | return value; |
||
230 | } |
||
231 | |||
232 | #else |
||
233 | |||
234 | |||
235 | extern inline BYTE __attribute__ ((always_inline)) DeviceRead(){ |
||
236 | BYTE value; |
||
237 | value = PMDIN1; |
||
238 | PMPWaitBusy(); |
||
239 | PMCONbits.PMPEN = 0; // disable PMP |
||
240 | value = PMDIN1; |
||
241 | PMCONbits.PMPEN = 1; // enable PMP |
||
242 | return value; |
||
243 | } |
||
244 | |||
245 | #endif |
||
246 | |||
247 | |||
248 | /********************************************************************* |
||
249 | * Macros: SingleDeviceRead() |
||
250 | * |
||
251 | * PreCondition: none |
||
252 | * |
||
253 | * Input: none |
||
254 | * |
||
255 | * Output: data read |
||
256 | * |
||
257 | * Side Effects: none |
||
258 | * |
||
259 | * Overview: a single read is performed. This is useful in issuing |
||
260 | * one read acess only. |
||
261 | * |
||
262 | * Note: chip select should be enabled |
||
263 | * |
||
264 | ********************************************************************/ |
||
265 | #ifdef USE_8BIT_PMP |
||
266 | extern inline BYTE __attribute__ ((always_inline)) SingleDeviceRead() |
||
267 | { |
||
268 | BYTE value; |
||
269 | value = PMDIN1; |
||
270 | PMPWaitBusy(); |
||
271 | return value; |
||
272 | } |
||
273 | |||
274 | #endif |
||
275 | |||
276 | /********************************************************************* |
||
277 | * Function: DeviceInit() |
||
278 | * |
||
279 | * PreCondition: none |
||
280 | * |
||
281 | * Input: none |
||
282 | * |
||
283 | * Output: none |
||
284 | * |
||
285 | * Side Effects: none |
||
286 | * |
||
287 | * Overview: initializes the device |
||
288 | * |
||
289 | * Note: none |
||
290 | * |
||
291 | ********************************************************************/ |
||
292 | |||
293 | extern inline void __attribute__ ((always_inline)) DeviceInit(void) |
||
294 | { |
||
295 | RST_LAT_BIT = 0; // hold in reset by default |
||
296 | RST_TRIS_BIT = 0; // enable RESET line |
||
297 | RS_TRIS_BIT = 0; // enable RS line |
||
298 | CS_LAT_BIT = 1; // not selected by default |
||
299 | CS_TRIS_BIT = 0; // enable chip select line |
||
300 | |||
301 | // PMP setup |
||
302 | PMMODE = 0; |
||
303 | PMAEN = 0; |
||
304 | PMCON = 0; |
||
305 | PMMODEbits.MODE = 2; // Intel 80 master interface |
||
306 | #if defined(__PIC32MX__) |
||
307 | PMMODEbits.WAITB = 0; |
||
308 | PMMODEbits.WAITM = PMP_WAIT_STATES; |
||
309 | #elif defined(__dsPIC33F__) || defined(__PIC24H__) |
||
310 | PMMODEbits.WAITB = 1; |
||
311 | PMMODEbits.WAITM = 3; |
||
312 | #else |
||
313 | PMMODEbits.WAITB = 0; |
||
314 | PMMODEbits.WAITM = 2; |
||
315 | #endif |
||
316 | PMMODEbits.WAITE = 0; |
||
317 | |||
318 | #ifdef USE_16BIT_PMP |
||
319 | PMMODEbits.MODE16 = 1; // 16 bit mode |
||
320 | #else |
||
321 | PMMODEbits.MODE16 = 0; // 8 bit mode |
||
322 | #endif |
||
323 | |||
324 | PMCONbits.PTRDEN = 1; // enable RD line |
||
325 | PMCONbits.PTWREN = 1; // enable WR line |
||
326 | PMCONbits.PMPEN = 1; // enable PMP |
||
327 | |||
328 | DelayMs(40); |
||
329 | RST_LAT_BIT = 1; // release from reset |
||
330 | DelayMs(400); |
||
331 | } |
||
332 | #endif |
||
333 | #endif |
Powered by WebSVN v2.8.3