eGUI alias D4D  Release 3.0
Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
d4dtch_cr_touch.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 D4DTCH_FUNCTIONS structure + "_ID"
52 // it is used for enable the code for compilation
53 #define d4dtch_cr_touch_ID 1
54 
55 
56 // copilation enable preprocessor condition
57 // the string d4dtch_cr_touch_ID must be replaced by define created one line up
58 #if (D4D_MK_STR(D4D_LLD_TCH) == d4dtch_cr_touch_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 D4DTCH_Init_CrTouch(void);
72  static unsigned char D4DTCH_DeInit_CrTouch(void);
73  static D4D_TOUCHSCREEN_LIMITS* D4DTCH_GetRawLimits_CrTouch(void);
74  static unsigned char D4DTCH_GetPositionRaw_CrTouch(unsigned short *TouchPositionX,
75  unsigned short *TouchPositionY);
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 D4DTCH_FUNCTIONS d4dtch_cr_touch =
87  {
88  D4DTCH_Init_CrTouch,
89  D4DTCH_GetPositionRaw_CrTouch,
90  D4DTCH_GetRawLimits_CrTouch,
91  D4DTCH_DeInit_CrTouch
92  };
93 
94  const D4D_TOUCHSCREEN_LIMITS d4dtchhw_crtouch_limits =
95  {
101  };
102 
103  /**************************************************************/
109  /**************************************************************/
114  //-----------------------------------------------------------------------------
115  // FUNCTION: D4DTCH_Init_CrTouch
116  // SCOPE: Low Level Driver API function
117  // DESCRIPTION: The function is used for initialization of this low level driver
118  //
119  // PARAMETERS: none
120  //
121  // RETURNS: result: 1 - Success
122  // 0 - Failed
123  //-----------------------------------------------------------------------------
124  static unsigned char D4DTCH_Init_CrTouch(void)
125  {
126  Byte status2;
127 
129  return 0;
130 
132  return 0;
133 
135  return 0;
136 
137 
139  return 0;
140 
143 
146 
148  {
150  return 0;
151  }
152 
153  if((status2 & D4D_CRTCH_STATUS2_RTSD_MASK) == 0)
154  {
155  // The touch screen hardware is NOT detected
157  return 0;
158  }
159 
160  #ifdef D4D_CRTCH_ENABLE_TOUCHPENDING
161  // Enable pin port clock and configure as input GPIO
164  #endif // D4D_CRTCH_ENABLE_TOUCHPENDING //
165 
166  // Initializations is OK
167  return 1;
168  }
169 
170  //-----------------------------------------------------------------------------
171  // FUNCTION: D4DTCH_DeInit_CrTouch
172  // SCOPE: Low Level Driver API function
173  // DESCRIPTION: The function is used for deinitialization of this low level driver
174  //
175  // PARAMETERS: none
176  //
177  // RETURNS: result: 1 - Success
178  // 0 - Failed
179  //-----------------------------------------------------------------------------
180  static unsigned char D4DTCH_DeInit_CrTouch(void)
181  {
183  return 1;
184  }
185 
186  //-----------------------------------------------------------------------------
187  // FUNCTION: D4DTCH_GetRawLimits_CrTouch
188  // SCOPE: Low Level Driver API function
189  // DESCRIPTION: The function returns pointer on touch screen raw limits
190  // structure.
191  // PARAMETERS: none
192  //
193  // RETURNS: pointer on touch screen raw limit structure
194  //
195  //-----------------------------------------------------------------------------
196  static D4D_TOUCHSCREEN_LIMITS* D4DTCH_GetRawLimits_CrTouch(void)
197  {
198  return (D4D_TOUCHSCREEN_LIMITS*)&d4dtchhw_crtouch_limits;
199  }
200 
201  //-----------------------------------------------------------------------------
202  // FUNCTION: D4DTCH_GetPositionRaw_CrTouch
203  // SCOPE: Low Level Driver API function
204  // DESCRIPTION: Reads touch screen and returns raw uncompensated X, Y
205  // coordinates if screen touched
206  // PARAMETERS: unsigned short *TouchPositionX Pointer to X coordinate
207  // unsigned short *TouchPositionY Pointer to Y ccordinate
208  // RETURNS: 0 no screen touch
209  // 1 screen touch,
210  //-----------------------------------------------------------------------------
211  static unsigned char D4DTCH_GetPositionRaw_CrTouch(unsigned short *TouchPositionX,
212  unsigned short *TouchPositionY)
213  {
214 
215  static unsigned char last_state = 0;
216  static unsigned short lastX, lastY;
217  CRTOUCH_RES_SIMPLE crtouch_res;
218 
219 
220  #ifdef D4D_CRTCH_ENABLE_TOUCHPENDING
221  // Check TOUCHPENDING GPIO for a new event (must be 0, otherwise no change)
223  *TouchPositionX = lastX;
224  *TouchPositionY = lastY;
225  return last_state;
226  }
227  #endif // D4D_CRTCH_ENABLE_TOUCHPENDING //
228 
231 
233  {
234  if(crtouch_res.status1 & D4D_CRTCH_STATUS1_RTST_MASK)
235  {
236  if(crtouch_res.status1 & D4D_CRTCH_STATUS1_RTSRDY_MASK)
237  {
238  #if D4DTCH_SWAP_AXES == 0
239  lastX = D4D_READ16B(crtouch_res.X);
240  lastY = D4D_READ16B(crtouch_res.Y);
241  #else
242  lastX = D4D_READ16B(crtouch_res.Y);
243  lastY = D4D_READ16B(crtouch_res.X);
244  #endif
245 
246  #ifdef D4DTCH_INVERSE_X_INT
247  lastX = D4DTCH_INVERSE_X_INT - lastX;
248  #endif
249 
250  #ifdef D4DTCH_INVERSE_Y_INT
251  lastY = D4DTCH_INVERSE_Y_INT - lastY;
252  #endif
253 
254  last_state = 1;
255  }
256  }
257  else
258  last_state = 0;
259  }
260 
261  *TouchPositionX = lastX;
262  *TouchPositionY = lastY;
263  return last_state;
264  }
265 
266 #endif //(D4D_MK_STR(D4D_LLD_TCH) == d4dtch_cr_touch_ID)
#define D4DTCH_Y_TOUCH_OFFMAX
#define D4D_CRTCH_STATUS2
#define D4D_CRTCH_TOUCHPENDING_SIM_SCGC
unsigned char(* D4DTCHHWCRTOUCH_MultiReadBytes)(unsigned char regAddr, unsigned char *pBuffer, unsigned char cnt)
#define D4D_CRTCH_STATUS2_RTSD_MASK
#define D4DTCH_FULL_SCALE
D4D low level touch screen interface API structure.
Definition: d4d_lldapi.h:195
#define D4DTCH_Y_TOUCH_MIN
D4D Driver main header file.
#define D4D_CRTCH_STATUS1_RTSRDY_MASK
#define D4D_CRTCH_TOUCHPENDING_PCR
#define D4D_CRTCH_STATUS1
D4D Driver private header file.
#define D4DTCH_X_TOUCH_OFFMAX
D4D driver - cr_touch touch screen driver function header file.
unsigned char Byte
Type definition of Byte (unsigned 8-bit).
Definition: d4d_types.h:151
D4D low level touch screen limitation structure.
Definition: d4d_lldapi.h:105
unsigned char(* D4DTCHHWCRTOUCH_Init)(void)
unsigned char(* D4DTCHHWCRTOUCH_DeInit)(void)
#define NULL
Type definition of null pointer.
Definition: d4d_types.h:184
#define D4DTCH_IIC_ADDRESS
#define D4D_CRTCH_TOUCHPENDING_PCR_MUX
#define D4D_CRTCH_TOUCHPENDING_SIM_SCGC_MASK
#define D4D_CRTCH_GPIO_PDIR
void(* D4DTCHHWCRTOUCH_SetAddress)(unsigned char)
#define D4D_READ16B(x)
Macro for handling endianism - read 16bit - from Big Endian.
Definition: d4d_extsrc.h:254
#define D4DTCH_X_TOUCH_MIN
#define D4D_CRTCH_TOUCHPENDING_PCR_FLAGS
#define D4D_CRTCH_STATUS1_RTST_MASK
const D4DTCHHWCRTOUCH_FUNCTIONS D4D_LLD_TCH_HW_CRTOUCH
D4D driver - resistive touch screen driver function header file.
#define D4DTCH_IIC_BAUDRATE
#define D4D_CRTCH_TOUCHPENDING_PIN
signed long(* D4DTCHHWCRTOUCH_SetBaudRate)(unsigned long baudRate)