eGUI alias D4D  Release 3.0
Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
d4dtchhw_mcf52259_adc.c
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 ***************************************************************************/
46 #include "d4d.h" // include of all public items (types, function etc) of D4D driver
47 #include "common_files/d4d_lldapi.h" // include non public low level driver interface header file (types, function prototypes, enums etc. )
48 #include "common_files/d4d_private.h" // include the private header file that contains perprocessor macros as D4D_MK_STR
49 
50 
51 // identification string of driver - must be same as name D4DTCHHW_FUNCTIONS structure + "_ID"
52 // it is used for enable the code for compilation
53 #define d4dtchhw_mcf52259_adc_ID 1
54 
55 
56 // copilation enable preprocessor condition
57 // the string d4dtch_mcf52259_adc_ID must be replaced by define created one line up
58 #if (D4D_MK_STR(D4D_LLD_TCH_HW) == d4dtchhw_mcf52259_adc_ID)
59 
60  // include of low level driver heaser file
61  // it will be included into wole project only in case that this driver is selected in main D4D configuration file
63  /******************************************************************************
64  * Macros
65  ******************************************************************************/
66 
67  /******************************************************************************
68  * Internal function prototypes
69  ******************************************************************************/
70 
71  static unsigned char D4DTCHHW_Init_MCF52259_adc(void);
72  static unsigned char D4DTCHHW_DeInit_MCF52259_adc(void);
73  static unsigned short D4DTCHHW_ReadTouchAxis_MCF52259_adc(D4DTCHHW_PINS pinId);
74  static D4D_TOUCHSCREEN_LIMITS* D4DTCHHW_GetRawLimits_MCF52259_adc(void);
75  static unsigned char D4DTCHHW_PinCtl_MCF52259_adc(D4DTCHHW_PINS pinId, D4DHW_PIN_STATE setState);
76 
77  /**************************************************************/
83  // the main structure that contains low level driver api functions
84  // the name fo this structure is used for recognizing of configured low level driver of whole D4D
85  // so this name has to be used in main configuration header file of D4D driver to enable this driver
86  const D4DTCHHW_FUNCTIONS d4dtchhw_mcf52259_adc =
87  {
88  D4DTCHHW_Init_MCF52259_adc,
89  D4DTCHHW_ReadTouchAxis_MCF52259_adc,
90  D4DTCHHW_GetRawLimits_MCF52259_adc,
91  D4DTCHHW_PinCtl_MCF52259_adc,
92  D4DTCHHW_DeInit_MCF52259_adc
93  };
94 
95  const D4D_TOUCHSCREEN_LIMITS d4dtchhw_mcf52259_adc_12b_limits =
96  {
102  };
103 
104 
105  /**************************************************************/
111  /**************************************************************/
118  //-----------------------------------------------------------------------------
119  // FUNCTION: D4DTCHHW_Init_MCF52259_adc
120  // SCOPE: Low Level Driver API function
121  // DESCRIPTION: The function is used for initialization of this hw low level driver
122  //
123  // PARAMETERS: none
124  //
125  // RETURNS: result: 1 - Success
126  // 0 - Failed
127  //-----------------------------------------------------------------------------
128  static unsigned char D4DTCHHW_Init_MCF52259_adc(void)
129  {
130  D4DTCH_INIT_X_PLUS;
131  D4DTCH_INIT_X_MINUS;
132  D4DTCH_INIT_Y_PLUS;
133  D4DTCH_INIT_Y_MINUS;
134 
135  return 1;
136  }
137 
138  //-----------------------------------------------------------------------------
139  // FUNCTION: D4DTCHHW_DeInit_MCF52259_adc
140  // SCOPE: Low Level Driver API function
141  // DESCRIPTION: The function is used for deinitialization of this hw low level driver
142  //
143  // PARAMETERS: none
144  //
145  // RETURNS: result: 1 - Success
146  // 0 - Failed
147  //-----------------------------------------------------------------------------
148  static unsigned char D4DTCHHW_DeInit_MCF52259_adc(void)
149  {
150  return 0;
151  }
152 
153  //-----------------------------------------------------------------------------
154  // FUNCTION: D4DTCHHW_ReadTouchAxis_MCF52259_adc
155  // SCOPE: Low Level Driver API function
156  // DESCRIPTION: The function is used to read one RAW nonfiltered value of the
157  // touch screen signal
158  // PARAMETERS: pinId - the signal to read
159  //
160  // RETURNS: readed value of the specified signal
161  //
162  //-----------------------------------------------------------------------------
163  static unsigned short D4DTCHHW_ReadTouchAxis_MCF52259_adc(D4DTCHHW_PINS pinId)
164  {
165  short cnt = 0;
166 
167  // Configure ADC for low power,
168  // clock divide = input clock,
169  // short sample time and 12-bits
170 
171  if(MCF_ADC_ADSTAT & MCF_ADC_ADSTAT_CIP0)
172  return 0;
173 
174 
175  MCF_ADC_CTRL1 = 0x0000; // set default setting of ADC
176  MCF_ADC_CTRL2 = 0x0007; // set the fastest speed on 80MHz core frequency
177  MCF_ADC_ADSDIS = 0x00FE; // disable all samples without first one
178 
179  if(pinId == D4DTCH_X_PLUS_PIN)
180  MCF_ADC_ADLST1 = D4DTCH_X_PLUS_ADCH;
181  else if(pinId == D4DTCH_Y_PLUS_PIN)
182  MCF_ADC_ADLST1 = D4DTCH_Y_PLUS_ADCH;
183  else
184  return 0;
185 
186  MCF_ADC_POWER &= ~0x0003;
187 
188 
189 
190  MCF_ADC_CTRL1 |= MCF_ADC_CTRL1_START0;
191 
192  while ((!(MCF_ADC_ADSTAT & MCF_ADC_ADSTAT_EOSI0)) && (++cnt))
193  {
194  ;
195  }
196 
197  MCF_ADC_ADSTAT |= MCF_ADC_ADSTAT_EOSI0;
198 
199  if(!cnt)
200  return 0;
201 
202  cnt = 1;
203  while ((!(MCF_ADC_ADSTAT & MCF_ADC_ADSTAT_RDY0)) && (++cnt))
204  {
205  ;
206  }
207 
208 
209  // if the measurement ends by timeout return 0 in other case result of ADC conversion
210  if(cnt)
211  return (unsigned short)(MCF_ADC_ADRSLT0 >> 3);
212  else
213  return 0;
214 
215  #if 0
216  short cnt = 1;
217 
218  // Configure ADC for low power,
219  // clock divide = input clock,
220  // short sample time and 10-bits
221  if(ADCSC2_ADACT)
222  return 0;
223 
224 
225  ADCCFG = 0x04; // set the ADC to 12 bit mode and short time measuring
226 
227  if(pinId == D4DTCH_X_PLUS_PIN)
228  ADCSC1_ADCH = D4DTCH_X_PLUS_ADCH;
229  else if(pinId == D4DTCH_Y_PLUS_PIN)
230  ADCSC1_ADCH = D4DTCH_Y_PLUS_ADCH;
231  else
232  return 0;
233 
234 
235  // Wait for ADC conversion to complete
236  while ((!ADCSC1_COCO) && (++cnt))
237  {
238  ;
239  }
240  ADCSC1_ADCH = 0b11111; //Turn off ADC
241 
242  // if the measurement ends by timeout return 0 in other case result of ADC conversion
243  if(cnt)
244  return ADCR;
245  else
246  return 0;
247 
248  #endif
249  }
250 
251  //-----------------------------------------------------------------------------
252  // FUNCTION: D4DTCHHW_GetRawLimits_MCF52259_adc
253  // SCOPE: Low Level Driver API function
254  // DESCRIPTION: The function returns pointer on touch screen raw limits
255  // structure.
256  // PARAMETERS: none
257  //
258  // RETURNS: pointer on touch screen raw limit structure
259  //
260  //-----------------------------------------------------------------------------
261  static D4D_TOUCHSCREEN_LIMITS* D4DTCHHW_GetRawLimits_MCF52259_adc(void)
262  {
263  return (D4D_TOUCHSCREEN_LIMITS*)&d4dtchhw_mcf52259_adc_12b_limits;
264  }
265 
266  //-----------------------------------------------------------------------------
267  // FUNCTION: D4DTCHHW_PinCtl_MCF52259_adc
268  // SCOPE: Low Level Driver API function
269  // DESCRIPTION: allows control GPIO pins for touch screen purposes
270  //
271  // PARAMETERS: D4DTCHHW_PINS pinId - Pin identification
272  // D4DHW_PIN_STATE setState - Pin action
273  // RETURNS: for Get action retuns the pin value
274  //-----------------------------------------------------------------------------
275  static unsigned char D4DTCHHW_PinCtl_MCF52259_adc(D4DTCHHW_PINS pinId, D4DHW_PIN_STATE setState)
276  {
277  switch(pinId)
278  {
279  case D4DTCH_X_PLUS_PIN:
280  switch(setState)
281  {
282  case D4DHW_PIN_OUT:
283  OUTPUT(D4DTCH_X_PLUS);
284  break;
285  case D4DHW_PIN_IN:
286  INPUT(D4DTCH_X_PLUS);
287  break;
288  case D4DHW_PIN_SET_1:
289  D4DTCH_SET_X_PLUS
290  break;
291  case D4DHW_PIN_SET_0:
292  D4DTCH_RESET_X_PLUS;
293  break;
294  case D4DHW_PIN_ADC_ON:
296  break;
297  case D4DHW_PIN_ADC_OFF:
299  break;
300  }
301  break;
302  case D4DTCH_X_MINUS_PIN:
303  switch(setState)
304  {
305  case D4DHW_PIN_OUT:
306  OUTPUT(D4DTCH_X_MINUS);
307  break;
308  case D4DHW_PIN_IN:
309  INPUT(D4DTCH_X_MINUS);
310  break;
311  case D4DHW_PIN_SET_1:
312  D4DTCH_SET_X_MINUS
313  break;
314  case D4DHW_PIN_SET_0:
315  D4DTCH_RESET_X_MINUS;
316  break;
317  }
318  break;
319  case D4DTCH_Y_PLUS_PIN:
320  switch(setState)
321  {
322  case D4DHW_PIN_OUT:
323  OUTPUT(D4DTCH_Y_PLUS);
324  break;
325  case D4DHW_PIN_IN:
326  INPUT(D4DTCH_Y_PLUS);
327  break;
328  case D4DHW_PIN_SET_1:
329  D4DTCH_SET_Y_PLUS
330  break;
331  case D4DHW_PIN_SET_0:
332  D4DTCH_RESET_Y_PLUS;
333  break;
334  case D4DHW_PIN_ADC_ON:
336  break;
337  case D4DHW_PIN_ADC_OFF:
339  break;
340  }
341  break;
342  case D4DTCH_Y_MINUS_PIN:
343  switch(setState)
344  {
345  case D4DHW_PIN_OUT:
346  OUTPUT(D4DTCH_Y_MINUS);
347  break;
348  case D4DHW_PIN_IN:
349  INPUT(D4DTCH_Y_MINUS);
350  break;
351  case D4DHW_PIN_SET_1:
352  D4DTCH_SET_Y_MINUS
353  break;
354  case D4DHW_PIN_SET_0:
355  D4DTCH_RESET_Y_MINUS;
356  break;
357  }
358  break;
359 
360  }
361  return 0;
362  }
363 
364 #endif //(D4D_MK_STR(D4D_LLD_TCH) == d4dtchhw_mcf52259_adc_ID)
Switch on the pin for read by ADC.
Definition: d4d_lldapi.h:82
#define D4DTCH_Y_PLUS_ADCH_PIN_DISABLE
#define D4DTCH_Y_TOUCH_OFFMAX
#define INPUT(x)
Analog touch screen X- signal.
Definition: d4d_lldapi.h:90
#define D4DTCH_FULL_SCALE
D4DTCHHW_PINS
D4D low level MCU types definition for analog resistive touch screen signals.
Definition: d4d_lldapi.h:87
#define D4DTCH_Y_TOUCH_MIN
D4D Driver main header file.
D4DHW_PIN_STATE
D4D low level MCU pin state enumeration type.
Definition: d4d_lldapi.h:73
D4D Driver private header file.
#define OUTPUT(x)
#define D4DTCH_X_TOUCH_OFFMAX
Switch pin to input mode (equivalent to high-Z)
Definition: d4d_lldapi.h:78
D4D low level touch screen limitation structure.
Definition: d4d_lldapi.h:105
Switch pin to output mode.
Definition: d4d_lldapi.h:77
#define D4DTCH_X_PLUS_ADCH_PIN_ENABLE
Set pin output register to logic 1.
Definition: d4d_lldapi.h:80
Switch off the pin for read by ADC.
Definition: d4d_lldapi.h:83
Analog touch screen X+ signal.
Definition: d4d_lldapi.h:89
#define D4DTCH_X_TOUCH_MIN
Set pin output register to logic 0.
Definition: d4d_lldapi.h:79
D4D driver - resistive touch screen driver function header file.
D4D low level touch screen hardware interface API structure.
Definition: d4d_lldapi.h:207
D4D driver - low level driver of ADC and gpio for resistive touch screen header file.
#define D4DTCH_X_PLUS_ADCH_PIN_DISABLE
#define D4DTCH_Y_PLUS_ADCH_PIN_ENABLE
Analog touch screen Y- signal.
Definition: d4d_lldapi.h:92
Analog touch screen Y+ signal.
Definition: d4d_lldapi.h:91