eGUI alias D4D  Release 3.0
Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
d4dtchhw_s12_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"
49 
50 
51 // define the identification string of this low level driver
52 #define d4dtchhw_s12_adc_ID 1
53 
54 #if (D4D_MK_STR(D4D_LLD_TCH_HW) == d4dtchhw_s12_adc_ID)
55 
57  /******************************************************************************
58  * Macros
59  ******************************************************************************/
60  /**************************************************************/
65  static unsigned char D4DTCHHW_Init_s12_adc(void);
66  static unsigned char D4DTCHHW_DeInit_s12_adc(void);
67  static unsigned short D4DTCHHW_ReadTouchAxis_s12_adc(D4DTCHHW_PINS pinId);
68  static D4D_TOUCHSCREEN_LIMITS* D4DTCHHW_GetRawLimits_s12_adc(void);
69  static unsigned char D4DTCHHW_PinCtl_s12_adc(D4DTCHHW_PINS pinId, D4DHW_PIN_STATE setState);
70 
71  /**************************************************************/
77  const D4DTCHHW_FUNCTIONS d4dtchhw_s12_adc =
78  {
79  D4DTCHHW_Init_s12_adc,
80  D4DTCHHW_ReadTouchAxis_s12_adc,
81  D4DTCHHW_GetRawLimits_s12_adc,
82  D4DTCHHW_PinCtl_s12_adc,
83  D4DTCHHW_DeInit_s12_adc
84  };
85 
86  const D4D_TOUCHSCREEN_LIMITS d4dtchhw_s12_adc_12b_limits =
87  {
93  };
94 
95  /**************************************************************/
101  static unsigned char D4DTCHHW_Init_s12_adc(void)
102  {
103  D4DTCH_INIT_X_PLUS;
104  D4DTCH_INIT_X_MINUS;
105  D4DTCH_INIT_Y_PLUS;
106  D4DTCH_INIT_Y_MINUS;
107 
108  return 1;
109  }
110 
111  //-----------------------------------------------------------------------------
112  // FUNCTION: D4DTCHHW_DeInit_s12_adc
113  // SCOPE: Low Level Driver API function
114  // DESCRIPTION: The function is used for deinitialization of this hw low level driver
115  //
116  // PARAMETERS: none
117  //
118  // RETURNS: result: 1 - Success
119  // 0 - Failed
120  //-----------------------------------------------------------------------------
121  static unsigned char D4DTCHHW_DeInit_s12_adc(void)
122  {
123  return 0;
124  }
125 
126  /**************************************************************/
134  static unsigned short D4DTCHHW_ReadTouchAxis_s12_adc(D4DTCHHW_PINS pinId)
135  {
136  short cnt = 1;
137  unsigned short advalue=0;
138  //unsigned short adres0,adres1,adres2,adres3;// Adresults
139 
140  // clock divide = max. 8.3MHz @50MHz BUS
141  if(D4DTCH_ATDSTAT0_SCF) // b01800
142  return 0;
143 
144  D4DTCH_ATDCTL1 = 0x40;// 12bit
145  //D4DTCH_ATDCTL2 = 0x40;// Fast flag clear (AFFC=1)
146  D4DTCH_ATDCTL3 = 0xA3;// 4conv.(S4C=1),right justified (DJM=1), Freeze in debug
147  D4DTCH_ATDCTL4 = 0x02;// Fatd = Fbus/6
148 
149  if(pinId == D4DTCH_X_PLUS_PIN)
150  D4DTCH_ATDCTL5 = D4DTCH_X_PLUS_ADCH;
151 
152  else if(pinId == D4DTCH_Y_PLUS_PIN)
153  D4DTCH_ATDCTL5 = D4DTCH_Y_PLUS_ADCH;
154  else
155  return 0;
156 
157  //D4DTCH_ATDCTL5 = AdcChannel & 0x0F;// Set channel and run single sequence
158 
159  // Wait for ADC conversion to complete
160  while ((!D4DTCH_ATDSTAT0_SCF) && (++cnt)) // loop w timeout
161  {
162  ;
163  }
164 
165  // if the measurement ends by timeout return 0 in other case result of ADC conversion
166  if(cnt)
167  { //Average of four results
168  advalue = (unsigned short)((D4DTCH_ATDDR0+D4DTCH_ATDDR1+D4DTCH_ATDDR2+D4DTCH_ATDDR3)/4);
169  D4DTCH_ATDSTAT0 = 0x80; // clear Flag manually
170  return(advalue);
171  }
172  else
173  return 0;
174  }
175 
176  static D4D_TOUCHSCREEN_LIMITS* D4DTCHHW_GetRawLimits_s12_adc(void)
177  {
178  return (D4D_TOUCHSCREEN_LIMITS*)&d4dtchhw_s12_adc_12b_limits;
179  }
180 
181  static unsigned char D4DTCHHW_PinCtl_s12_adc(D4DTCHHW_PINS pinId, D4DHW_PIN_STATE setState)
182  {
183  switch(pinId)
184  {
185  case D4DTCH_X_PLUS_PIN:
186  switch(setState)
187  {
188  case D4DHW_PIN_OUT:
189  OUTPUT(D4DTCH_X_PLUS);
190  break;
191  case D4DHW_PIN_IN:
192  INPUT(D4DTCH_X_PLUS);
193  break;
194  case D4DHW_PIN_SET_1:
195  D4DTCH_SET_X_PLUS
196  break;
197  case D4DHW_PIN_SET_0:
198  D4DTCH_RESET_X_PLUS;
199  break;
200  case D4DHW_PIN_ADC_ON:
202  break;
203  case D4DHW_PIN_ADC_OFF:
205  break;
206  }
207  break;
208  case D4DTCH_X_MINUS_PIN:
209  switch(setState)
210  {
211  case D4DHW_PIN_OUT:
212  OUTPUT(D4DTCH_X_MINUS);
213  break;
214  case D4DHW_PIN_IN:
215  INPUT(D4DTCH_X_MINUS);
216  break;
217  case D4DHW_PIN_SET_1:
218  D4DTCH_SET_X_MINUS
219  break;
220  case D4DHW_PIN_SET_0:
221  D4DTCH_RESET_X_MINUS;
222  break;
223  }
224  break;
225  case D4DTCH_Y_PLUS_PIN:
226  switch(setState)
227  {
228  case D4DHW_PIN_OUT:
229  OUTPUT(D4DTCH_Y_PLUS);
230  break;
231  case D4DHW_PIN_IN:
232  INPUT(D4DTCH_Y_PLUS);
233  break;
234  case D4DHW_PIN_SET_1:
235  D4DTCH_SET_Y_PLUS
236  break;
237  case D4DHW_PIN_SET_0:
238  D4DTCH_RESET_Y_PLUS;
239  break;
240  case D4DHW_PIN_ADC_ON:
242  break;
243  case D4DHW_PIN_ADC_OFF:
245  break;
246  }
247  break;
248  case D4DTCH_Y_MINUS_PIN:
249  switch(setState)
250  {
251  case D4DHW_PIN_OUT:
252  OUTPUT(D4DTCH_Y_MINUS);
253  break;
254  case D4DHW_PIN_IN:
255  INPUT(D4DTCH_Y_MINUS);
256  break;
257  case D4DHW_PIN_SET_1:
258  D4DTCH_SET_Y_MINUS
259  break;
260  case D4DHW_PIN_SET_0:
261  D4DTCH_RESET_Y_MINUS;
262  break;
263  }
264  break;
265 
266  }
267  return 0;
268  }
269 
270 #endif
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_ATDCTL1
#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
#define D4DTCH_ATDDR0
#define D4DTCH_ATDCTL4
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
#define D4DTCH_ATDSTAT0_SCF
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
#define D4DTCH_ATDDR3
Analog touch screen X+ signal.
Definition: d4d_lldapi.h:89
#define D4DTCH_X_TOUCH_MIN
#define D4DTCH_ATDCTL3
#define D4DTCH_ATDDR2
Set pin output register to logic 0.
Definition: d4d_lldapi.h:79
#define D4DTCH_ATDCTL5
D4D driver - low level driver of ADC and gpio for resistive touch screen header file.
D4D driver - resistive touch screen driver function header file.
D4D low level touch screen hardware interface API structure.
Definition: d4d_lldapi.h:207
#define D4DTCH_X_PLUS_ADCH_PIN_DISABLE
#define D4DTCH_Y_PLUS_ADCH_PIN_ENABLE
#define D4DTCH_ATDSTAT0
#define D4DTCH_ATDDR1
Analog touch screen Y- signal.
Definition: d4d_lldapi.h:92
Analog touch screen Y+ signal.
Definition: d4d_lldapi.h:91