eGUI alias D4D  Release 3.0
Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
d4dtchhw_s08_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_s08_adc_ID 1
54 
55 
56 // copilation enable preprocessor condition
57 // the string d4dtch_s08_adc_ID must be replaced by define created one line up
58 #if (D4D_MK_STR(D4D_LLD_TCH_HW) == d4dtchhw_s08_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_S08_adc(void);
72  static unsigned char D4DTCHHW_DeInit_S08_adc(void);
73  static unsigned short D4DTCHHW_ReadTouchAxis_S08_adc(D4DTCHHW_PINS pinId);
74  static D4D_TOUCHSCREEN_LIMITS* D4DTCHHW_GetRawLimits_S08_adc(void);
75  static unsigned char D4DTCHHW_PinCtl_S08_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_s08_adc =
87  {
88  D4DTCHHW_Init_S08_adc,
89  D4DTCHHW_ReadTouchAxis_S08_adc,
90  D4DTCHHW_GetRawLimits_S08_adc,
91  D4DTCHHW_PinCtl_S08_adc,
92  D4DTCHHW_DeInit_S08_adc
93  };
94 
95  const D4D_TOUCHSCREEN_LIMITS d4dtchhw_s08_adc_12b_limits =
96  {
102  };
103 
104 
105  /**************************************************************/
111  /**************************************************************/
118  //-----------------------------------------------------------------------------
119  // FUNCTION: D4DTCHHW_Init_S08_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_S08_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  #ifdef D4DTCHHW_MCU_USER_INIT
136  D4DTCHHW_MCU_USER_INIT
137  #endif
138 
139  return 1;
140  }
141 
142  //-----------------------------------------------------------------------------
143  // FUNCTION: D4DTCHHW_DeInit_S08_adc
144  // SCOPE: Low Level Driver API function
145  // DESCRIPTION: The function is used for deinitialization of this hw low level driver
146  //
147  // PARAMETERS: none
148  //
149  // RETURNS: result: 1 - Success
150  // 0 - Failed
151  //-----------------------------------------------------------------------------
152  static unsigned char D4DTCHHW_DeInit_S08_adc(void)
153  {
154  return 0;
155  }
156 
157  //-----------------------------------------------------------------------------
158  // FUNCTION: D4DTCHHW_ReadTouchAxis_S08_adc
159  // SCOPE: Low Level Driver API function
160  // DESCRIPTION: The function is used to read one RAW nonfiltered value of the
161  // touch screen signal
162  // PARAMETERS: pinId - the signal to read
163  //
164  // RETURNS: readed value of the specified signal
165  //
166  //-----------------------------------------------------------------------------
167  static unsigned short D4DTCHHW_ReadTouchAxis_S08_adc(D4DTCHHW_PINS pinId)
168  {
169  short cnt = 1;
170 
171  // Configure ADC for low power,
172  // clock divide = input clock,
173  // short sample time and 10-bits
175  return 0;
176 
177 
178  D4D_TCHHW_ADC_INIT // set the ADC to be prepare for measuring
179 
180 
181  if(pinId == D4DTCH_X_PLUS_PIN)
182  D4D_TCHHW_ADCH = D4DTCH_X_PLUS_ADCH;
183  else if(pinId == D4DTCH_Y_PLUS_PIN)
184  D4D_TCHHW_ADCH = D4DTCH_Y_PLUS_ADCH;
185  else
186  return 0;
187 
188 
189  // Wait for ADC conversion to complete
190  while ((!D4D_TCHHW_ADCSC1_COCO) && (++cnt))
191  {
192  ;
193  }
194  D4D_TCHHW_ADCH = 0b11111; //Turn off ADC
195 
196  // if the measurement ends by timeout return 0 in other case result of ADC conversion
197  if(cnt)
198  return D4D_TCHHW_ADCR;
199  else
200  return 0;
201  }
202 
203  //-----------------------------------------------------------------------------
204  // FUNCTION: D4DTCHHW_GetRawLimits_S08_adc
205  // SCOPE: Low Level Driver API function
206  // DESCRIPTION: The function returns pointer on touch screen raw limits
207  // structure.
208  // PARAMETERS: none
209  //
210  // RETURNS: pointer on touch screen raw limit structure
211  //
212  //-----------------------------------------------------------------------------
213  static D4D_TOUCHSCREEN_LIMITS* D4DTCHHW_GetRawLimits_S08_adc(void)
214  {
215  return (D4D_TOUCHSCREEN_LIMITS*)&d4dtchhw_s08_adc_12b_limits;
216  }
217 
218  //-----------------------------------------------------------------------------
219  // FUNCTION: D4DTCHHW_PinCtl_S08_adc
220  // SCOPE: Low Level Driver API function
221  // DESCRIPTION: allows control GPIO pins for touch screen purposes
222  //
223  // PARAMETERS: D4DTCHHW_PINS pinId - Pin identification
224  // D4DHW_PIN_STATE setState - Pin action
225  // RETURNS: for Get action retuns the pin value
226  //-----------------------------------------------------------------------------
227  static unsigned char D4DTCHHW_PinCtl_S08_adc(D4DTCHHW_PINS pinId, D4DHW_PIN_STATE setState)
228  {
229  switch(pinId)
230  {
231  case D4DTCH_X_PLUS_PIN:
232  switch(setState)
233  {
234  case D4DHW_PIN_OUT:
235  OUTPUT(D4DTCH_X_PLUS);
236  break;
237  case D4DHW_PIN_IN:
238  INPUT(D4DTCH_X_PLUS);
239  break;
240  case D4DHW_PIN_SET_1:
241  D4DTCH_SET_X_PLUS
242  break;
243  case D4DHW_PIN_SET_0:
244  D4DTCH_RESET_X_PLUS;
245  break;
246  case D4DHW_PIN_ADC_ON:
248  break;
249  case D4DHW_PIN_ADC_OFF:
251  break;
252  }
253  break;
254  case D4DTCH_X_MINUS_PIN:
255  switch(setState)
256  {
257  case D4DHW_PIN_OUT:
258  OUTPUT(D4DTCH_X_MINUS);
259  break;
260  case D4DHW_PIN_IN:
261  INPUT(D4DTCH_X_MINUS);
262  break;
263  case D4DHW_PIN_SET_1:
264  D4DTCH_SET_X_MINUS
265  break;
266  case D4DHW_PIN_SET_0:
267  D4DTCH_RESET_X_MINUS;
268  break;
269  }
270  break;
271  case D4DTCH_Y_PLUS_PIN:
272  switch(setState)
273  {
274  case D4DHW_PIN_OUT:
275  OUTPUT(D4DTCH_Y_PLUS);
276  break;
277  case D4DHW_PIN_IN:
278  INPUT(D4DTCH_Y_PLUS);
279  break;
280  case D4DHW_PIN_SET_1:
281  D4DTCH_SET_Y_PLUS
282  break;
283  case D4DHW_PIN_SET_0:
284  D4DTCH_RESET_Y_PLUS;
285  break;
286  case D4DHW_PIN_ADC_ON:
288  break;
289  case D4DHW_PIN_ADC_OFF:
291  break;
292  }
293  break;
294  case D4DTCH_Y_MINUS_PIN:
295  switch(setState)
296  {
297  case D4DHW_PIN_OUT:
298  OUTPUT(D4DTCH_Y_MINUS);
299  break;
300  case D4DHW_PIN_IN:
301  INPUT(D4DTCH_Y_MINUS);
302  break;
303  case D4DHW_PIN_SET_1:
304  D4DTCH_SET_Y_MINUS
305  break;
306  case D4DHW_PIN_SET_0:
307  D4DTCH_RESET_Y_MINUS;
308  break;
309  }
310  break;
311 
312  }
313  return 0;
314  }
315 
316 #endif //(D4D_MK_STR(D4D_LLD_TCH) == d4dtchhw_s08_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 D4D_TCHHW_ADCH
#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
#define D4D_TCHHW_ADCSC2_ADACT
Analog touch screen X+ signal.
Definition: d4d_lldapi.h:89
#define D4DTCH_X_TOUCH_MIN
#define D4D_TCHHW_ADCR
Set pin output register to logic 0.
Definition: d4d_lldapi.h:79
D4D driver - resistive touch screen driver function header file.
D4D driver - low level driver of ADC and gpio for resistive touch screen header file.
D4D low level touch screen hardware interface API structure.
Definition: d4d_lldapi.h:207
#define D4D_TCHHW_ADCSC1_COCO
#define D4DTCH_X_PLUS_ADCH_PIN_DISABLE
#define D4DTCH_Y_PLUS_ADCH_PIN_ENABLE
#define D4D_TCHHW_ADC_INIT
Analog touch screen Y- signal.
Definition: d4d_lldapi.h:92
Analog touch screen Y+ signal.
Definition: d4d_lldapi.h:91