eGUI alias D4D  Release 3.0
Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
d4dtchhw_kinetis_adc.h
Go to the documentation of this file.
1 /**************************************************************************
2 *
3 * Copyright 2014 by Petr Gargulak. eGUI Community.
4 * Copyright 2009-2013 by Petr Gargulak. Freescale Semiconductor, Inc.
5 *
6 ***************************************************************************
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License Version 3
9 * or later (the "LGPL").
10 *
11 * As a special exception, the copyright holders of the eGUI project give you
12 * permission to link the eGUI sources with independent modules to produce an
13 * executable, regardless of the license terms of these independent modules,
14 * and to copy and distribute the resulting executable under terms of your
15 * choice, provided that you also meet, for each linked independent module,
16 * the terms and conditions of the license of that module.
17 * An independent module is a module which is not derived from or based
18 * on this library.
19 * If you modify the eGUI sources, you may extend this exception
20 * to your version of the eGUI sources, but you are not obligated
21 * to do so. If you do not wish to do so, delete this
22 * exception statement from your version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27 *
28 * You should have received a copy of the GNU General Public License
29 * and the GNU Lesser General Public License along with this program.
30 * If not, see <http://www.gnu.org/licenses/>.
31 *
32 ***************************************************************************/
47 #ifndef __D4DTCHHW_KINETIS_ADC_H
48 #define __D4DTCHHW_KINETIS_ADC_H
49 
50  #if (D4D_MK_STR(D4D_LLD_TCH_HW) == d4dtchhw_kinetis_adc_ID)
51 
52  /******************************************************************************
53  * Includes
54  ******************************************************************************/
55  #include "d4dtchhw_kinetis_adc_cfg.h"
56 
57  /******************************************************************************
58  * Constants
59  ******************************************************************************/
60 
61  /******************************************************************************
62  * Types
63  ******************************************************************************/
64 
65  /******************************************************************************
66  * Macros
67  ******************************************************************************/
68 
69 
70  #define SET(x) (x##_PORT) |= (1 << (x))
71  #define RESET(x) (x##_PORT) &= ~(1 << (x))
72 
73  #define OUTPUT(x) (x##_DDR) |= (1 << (x)) ; (x##_PCR) = PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK;
74  #define INPUT(x) (x##_DDR) &= ~(1 << (x)); (x##_PCR) = PORT_PCR_MUX(1);
75 
76  // D4DTCH_X_PLUS_PCR pin PCR settings
77  #ifndef D4DTCH_X_PLUS_PCR_VAL
78  #define D4DTCH_X_PLUS_PCR_VAL PORT_PCR_MUX(1)
79  #endif
80  // D4DTCH_X_MINUS_PCR pin PCR settings
81  #ifndef D4DTCH_X_MINUS_PCR_VAL
82  #define D4DTCH_X_MINUS_PCR_VAL PORT_PCR_MUX(1)
83  #endif
84  // D4DTCH_Y_PLUS_PCR pin PCR settings
85  #ifndef D4DTCH_Y_PLUS_PCR_VAL
86  #define D4DTCH_Y_PLUS_PCR_VAL PORT_PCR_MUX(1)
87  #endif
88  // D4DTCH_Y_MINUS_PCR pin PCR settings
89  #ifndef D4DTCH_Y_MINUS_PCR_VAL
90  #define D4DTCH_Y_MINUS_PCR_VAL PORT_PCR_MUX(1)
91  #endif
92 
93 
94  #ifndef D4DTCH_INIT_TCH_PADS
95  #define D4DTCH_INIT_TCH_PADS D4DTCH_X_PLUS_PCR = D4DTCH_X_PLUS_PCR_VAL;\
96  D4DTCH_X_MINUS_PCR = D4DTCH_X_MINUS_PCR_VAL;\
97  D4DTCH_Y_PLUS_PCR = D4DTCH_Y_PLUS_PCR_VAL;\
98  D4DTCH_Y_MINUS_PCR = D4DTCH_Y_MINUS_PCR_VAL;
99  #endif
100 
101  /****** X PLUS signal macros ******/
102 
103  #ifndef D4DTCH_INIT_X_PLUS
104  #ifndef D4DTCH_X_PLUS
105  #error "The Macro D4DTCH_X_PLUS must be set in Touch Screen low level driver configuration file."
106  #else
107  #define D4DTCH_INIT_X_PLUS OUTPUT(D4DTCH_X_PLUS); RESET(D4DTCH_X_PLUS);
108  #endif
109  #endif
110 
111  #ifndef D4DTCH_RESET_X_PLUS
112  #ifndef D4DTCH_X_PLUS
113  #error "The Macro D4DTCH_X_PLUS must be set in Touch Screen low level driver configuration file."
114  #else
115  #define D4DTCH_RESET_X_PLUS RESET(D4DTCH_X_PLUS);
116  #endif
117  #endif
118 
119  #ifndef D4DTCH_SET_X_PLUS
120  #ifndef D4DTCH_X_PLUS
121  #error "The Macro D4DTCH_X_PLUS must be set in Touch Screen low level driver configuration file."
122  #else
123  #define D4DTCH_SET_X_PLUS SET(D4DTCH_X_PLUS);
124  #endif
125  #endif
126 
127  /****** X MINUS signal macros ******/
128 
129  #ifndef D4DTCH_INIT_X_MINUS
130  #ifndef D4DTCH_X_MINUS
131  #error "The Macro D4DTCH_X_MINUS must be set in Touch Screen low level driver configuration file."
132  #else
133  #define D4DTCH_INIT_X_MINUS OUTPUT(D4DTCH_X_MINUS); RESET(D4DTCH_X_MINUS);
134  #endif
135  #endif
136 
137  #ifndef D4DTCH_RESET_X_MINUS
138  #ifndef D4DTCH_X_MINUS
139  #error "The Macro D4DTCH_X_MINUS must be set in Touch Screen low level driver configuration file."
140  #else
141  #define D4DTCH_RESET_X_MINUS RESET(D4DTCH_X_MINUS);
142  #endif
143  #endif
144 
145  #ifndef D4DTCH_SET_X_MINUS
146  #ifndef D4DTCH_X_MINUS
147  #error "The Macro D4DTCH_X_MINUS must be set in Touch Screen low level driver configuration file."
148  #else
149  #define D4DTCH_SET_X_MINUS SET(D4DTCH_X_MINUS);
150  #endif
151  #endif
152 
153  #ifndef D4DTCH_X_MINUS_HIGH_Z_ENABLE
154  #ifndef D4DTCH_X_MINUS
155  #error "The Macro D4DTCH_X_MINUS must be set in Touch Screen low level driver configuration file."
156  #else
157  #define D4DTCH_X_MINUS_HIGH_Z_ENABLE INPUT(D4DTCH_X_MINUS);
158  #endif
159  #endif
160 
161  #ifndef D4DTCH_X_MINUS_HIGH_Z_DISABLE
162  #ifndef D4DTCH_X_MINUS
163  #error "The Macro D4DTCH_X_MINUS must be set in Touch Screen low level driver configuration file."
164  #else
165  #define D4DTCH_X_MINUS_HIGH_Z_DISABLE OUTPUT(D4DTCH_X_MINUS);
166  #endif
167  #endif
168 
169  /****** Y PLUS signal macros ******/
170 
171  #ifndef D4DTCH_INIT_Y_PLUS
172  #ifndef D4DTCH_Y_PLUS
173  #error "The Macro D4DTCH_Y_PLUS must be set in Touch Screen low level driver configuration file."
174  #else
175  #define D4DTCH_INIT_Y_PLUS OUTPUT(D4DTCH_Y_PLUS); RESET(D4DTCH_Y_PLUS);
176  #endif
177  #endif
178 
179  #ifndef D4DTCH_RESET_Y_PLUS
180  #ifndef D4DTCH_Y_PLUS
181  #error "The Macro D4DTCH_Y_PLUS must be set in Touch Screen low level driver configuration file."
182  #else
183  #define D4DTCH_RESET_Y_PLUS RESET(D4DTCH_Y_PLUS);
184  #endif
185  #endif
186 
187  #ifndef D4DTCH_SET_Y_PLUS
188  #ifndef D4DTCH_Y_PLUS
189  #error "The Macro D4DTCH_Y_PLUS must be set in Touch Screen low level driver configuration file."
190  #else
191  #define D4DTCH_SET_Y_PLUS SET(D4DTCH_Y_PLUS);
192  #endif
193  #endif
194 
195  /****** Y MINUS signal macros ******/
196 
197  #ifndef D4DTCH_INIT_Y_MINUS
198  #ifndef D4DTCH_Y_MINUS
199  #error "The Macro D4DTCH_Y_MINUS must be set in Touch Screen low level driver configuration file."
200  #else
201  #define D4DTCH_INIT_Y_MINUS OUTPUT(D4DTCH_Y_MINUS); RESET(D4DTCH_Y_MINUS);
202  #endif
203  #endif
204 
205  #ifndef D4DTCH_RESET_Y_MINUS
206  #ifndef D4DTCH_Y_MINUS
207  #error "The Macro D4DTCH_Y_MINUS must be set in Touch Screen low level driver configuration file."
208  #else
209  #define D4DTCH_RESET_Y_MINUS RESET(D4DTCH_Y_MINUS);
210  #endif
211  #endif
212 
213  #ifndef D4DTCH_SET_Y_MINUS
214  #ifndef D4DTCH_Y_MINUS
215  #error "The Macro D4DTCH_Y_MINUS must be set in Touch Screen low level driver configuration file."
216  #else
217  #define D4DTCH_SET_Y_MINUS SET(D4DTCH_Y_MINUS);
218  #endif
219  #endif
220 
221  #ifndef D4DTCH_Y_MINUS_HIGH_Z_ENABLE
222  #ifndef D4DTCH_Y_MINUS
223  #error "The Macro D4DTCH_Y_MINUS must be set in Touch Screen low level driver configuration file."
224  #else
225  #define D4DTCH_Y_MINUS_HIGH_Z_ENABLE INPUT(D4DTCH_Y_MINUS);
226  #endif
227  #endif
228 
229  #ifndef D4DTCH_Y_MINUS_HIGH_Z_DISABLE
230  #ifndef D4DTCH_Y_MINUS
231  #error "The Macro D4DTCH_Y_MINUS must be set in Touch Screen low level driver configuration file."
232  #else
233  #define D4DTCH_Y_MINUS_HIGH_Z_DISABLE OUTPUT(D4DTCH_Y_MINUS);
234  #endif
235  #endif
236 
237  /****** Switching pins between GPIO / ADC func *****/
238 
239  #ifndef D4DTCH_X_PLUS_ADCH_PIN_ENABLE
240  #define D4DTCH_X_PLUS_ADCH_PIN_ENABLE (D4DTCH_X_PLUS_PCR = PORT_PCR_MUX(0)); // Mux ADC
241  #endif
242 
243  #ifndef D4DTCH_X_PLUS_ADCH_PIN_DISABLE
244  #define D4DTCH_X_PLUS_ADCH_PIN_DISABLE (D4DTCH_X_PLUS_PCR = PORT_PCR_MUX(1)); // Mux GPIO
245  #endif
246 
247  #ifndef D4DTCH_Y_PLUS_ADCH_PIN_ENABLE
248  #define D4DTCH_Y_PLUS_ADCH_PIN_ENABLE (D4DTCH_Y_PLUS_PCR = PORT_PCR_MUX(0)); // Mux ADC
249  #endif
250 
251  #ifndef D4DTCH_Y_PLUS_ADCH_PIN_DISABLE
252  #define D4DTCH_Y_PLUS_ADCH_PIN_DISABLE (D4DTCH_Y_PLUS_PCR = PORT_PCR_MUX(1)); // Mux GPIO
253  #endif
254 
255  /****** ADC module selection *****/
256  #ifndef D4DTCH_ADC_ID
257  #error "The D4DTCH_ADC_ID must be set in Touch Screen low level driver configuration file."
258  #endif
259 
260  #if D4DTCH_ADC_ID == 0
261 
262  #define D4DTCH_ADC_SC1A ADC0_SC1A
263  #define D4DTCH_ADC_SC1B ADC0_SC1B
264  #define D4DTCH_ADC_CFG1 ADC0_CFG1
265  #define D4DTCH_ADC_CFG2 ADC0_CFG2
266  #define D4DTCH_ADC_RA ADC0_RA
267  #define D4DTCH_ADC_RB ADC0_RB
268  #define D4DTCH_ADC_CV1 ADC0_CV1
269  #define D4DTCH_ADC_CV2 ADC0_CV2
270  #define D4DTCH_ADC_SC2 ADC0_SC2
271  #define D4DTCH_ADC_SC3 ADC0_SC3
272  #define D4DTCH_ADC_OFS ADC0_OFS
273  #define D4DTCH_ADC_PG ADC0_PG
274  #define D4DTCH_ADC_MG ADC0_MG
275  #define D4DTCH_ADC_CLPD ADC0_CLPD
276  #define D4DTCH_ADC_CLPS ADC0_CLPS
277  #define D4DTCH_ADC_CLP4 ADC0_CLP4
278  #define D4DTCH_ADC_CLP3 ADC0_CLP3
279  #define D4DTCH_ADC_CLP2 ADC0_CLP2
280  #define D4DTCH_ADC_CLP1 ADC0_CLP1
281  #define D4DTCH_ADC_CLP0 ADC0_CLP0
282  #define D4DTCH_ADC_PGA ADC0_PGA
283  #define D4DTCH_ADC_CLMD ADC0_CLMD
284  #define D4DTCH_ADC_CLMS ADC0_CLMS
285  #define D4DTCH_ADC_CLM4 ADC0_CLM4
286  #define D4DTCH_ADC_CLM3 ADC0_CLM3
287  #define D4DTCH_ADC_CLM2 ADC0_CLM2
288  #define D4DTCH_ADC_CLM1 ADC0_CLM1
289  #define D4DTCH_ADC_CLM0 ADC0_CLM0
290 
291 
292  #elif D4DTCH_ADC_ID == 1
293 
294  #define D4DTCH_ADC_SC1A ADC1_SC1A
295  #define D4DTCH_ADC_SC1B ADC1_SC1B
296  #define D4DTCH_ADC_CFG1 ADC1_CFG1
297  #define D4DTCH_ADC_CFG2 ADC1_CFG2
298  #define D4DTCH_ADC_RA ADC1_RA
299  #define D4DTCH_ADC_RB ADC1_RB
300  #define D4DTCH_ADC_CV1 ADC1_CV1
301  #define D4DTCH_ADC_CV2 ADC1_CV2
302  #define D4DTCH_ADC_SC2 ADC1_SC2
303  #define D4DTCH_ADC_SC3 ADC1_SC3
304  #define D4DTCH_ADC_OFS ADC1_OFS
305  #define D4DTCH_ADC_PG ADC1_PG
306  #define D4DTCH_ADC_MG ADC1_MG
307  #define D4DTCH_ADC_CLPD ADC1_CLPD
308  #define D4DTCH_ADC_CLPS ADC1_CLPS
309  #define D4DTCH_ADC_CLP4 ADC1_CLP4
310  #define D4DTCH_ADC_CLP3 ADC1_CLP3
311  #define D4DTCH_ADC_CLP2 ADC1_CLP2
312  #define D4DTCH_ADC_CLP1 ADC1_CLP1
313  #define D4DTCH_ADC_CLP0 ADC1_CLP0
314  #define D4DTCH_ADC_PGA ADC1_PGA
315  #define D4DTCH_ADC_CLMD ADC1_CLMD
316  #define D4DTCH_ADC_CLMS ADC1_CLMS
317  #define D4DTCH_ADC_CLM4 ADC1_CLM4
318  #define D4DTCH_ADC_CLM3 ADC1_CLM3
319  #define D4DTCH_ADC_CLM2 ADC1_CLM2
320  #define D4DTCH_ADC_CLM1 ADC1_CLM1
321  #define D4DTCH_ADC_CLM0 ADC1_CLM0
322 
323  #else
324  #error "The D4DLCD_SPI_ID is invalid"
325  #endif
326 
327  /****** Algorithm constants/macros *****/
328 
329  #ifndef D4DTCH_FULL_SCALE
330  #define D4DTCH_FULL_SCALE 0x0FFF
331  #endif
332 
333  #ifndef D4DTCH_X_TOUCH_MIN
334  #define D4DTCH_X_TOUCH_MIN (D4DTCH_FULL_SCALE / 10)
335  #endif
336 
337  #ifndef D4DTCH_Y_TOUCH_MIN
338  #define D4DTCH_Y_TOUCH_MIN (D4DTCH_FULL_SCALE / 10)
339  #endif
340 
341  #ifndef D4DTCH_X_TOUCH_OFFMAX
342  #define D4DTCH_X_TOUCH_OFFMAX (D4DTCH_X_TOUCH_MIN * 4 / 2)
343  #endif
344 
345  #ifndef D4DTCH_Y_TOUCH_OFFMAX
346  #define D4DTCH_Y_TOUCH_OFFMAX (D4DTCH_Y_TOUCH_MIN * 4 / 2)
347  #endif
348 
349  #ifndef D4DTCH_SAMPLE_MARGIN
350  #define D4DTCH_SAMPLE_MARGIN (D4DTCH_FULL_SCALE / 256)
351  #endif
352 
353  /******************************************************************************
354  * Global variables
355  ******************************************************************************/
356 
357  /******************************************************************************
358  * Global functions
359  ******************************************************************************/
360 
361  #endif
362 #endif /* __D4DTCHHW_KINETIS_ADC_H */
363 
364 
365 
366 
367 
368 
369 
370 
371 
372