eGUI alias D4D  Release 3.0
Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
d4dtch_mcf52277_asp.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_mcf52277_asp_ID 1
54 
55 
56 // copilation enable preprocessor condition
57 // the string d4dtch_mcf52277_asp_ID must be replaced by define created one line up
58 #if (D4D_MK_STR(D4D_LLD_TCH) == d4dtch_mcf52277_asp_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_Mcf52277_asp(void);
72  static unsigned char D4DTCH_DeInit_Mcf52277_asp(void);
73  static D4D_TOUCHSCREEN_LIMITS* D4DTCH_GetRawLimits_Mcf52277_asp(void);
74  static unsigned char D4DTCH_GetPositionRaw_Mcf52277_asp(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_mcf52277_asp =
87  {
88  D4DTCH_Init_Mcf52277_asp,
89  D4DTCH_GetPositionRaw_Mcf52277_asp,
90  D4DTCH_GetRawLimits_Mcf52277_asp,
91  D4DTCH_DeInit_Mcf52277_asp
92  };
93 
94  /**************************************************************/
100  const D4D_TOUCHSCREEN_LIMITS d4dtch_mcf52277_asp_limits =
101  {
107  };
108 
109  static uint32 touched = 0;
110  static uint16 coordinationX = 0;
111  static uint16 coordinationY = 0;
112 
113 
114  /**************************************************************/
120  static void mcf5xxx_set_handler (int vector, int (*handler) (void));
121  int aspc_handler(void);
122  void read_aspc_fifo(void);
123  //-----------------------------------------------------------------------------
124  // FUNCTION: D4DTCH_Init_Mcf52277_asp
125  // SCOPE: Low Level Driver API function
126  // DESCRIPTION: The function is used for initialization of this low level driver
127  //
128  // PARAMETERS: none
129  //
130  // RETURNS: result: 1 - Success
131  // 0 - Failed
132  //-----------------------------------------------------------------------------
133  static unsigned char D4DTCH_Init_Mcf52277_asp(void)
134  {
135  mcf5xxx_set_handler(128+61, aspc_handler);
136 
137  MCF_INTC1_ICR61 |= 4;
138  MCF_INTC1_IMRH &= ~(MCF_INTC_IMRH_INT_MASK61); //enable interrupt
139 
140 
141  MCF_ASP_CR = ( 0 // <--don't need &~'s below
142  &~MCF_ASP_CR_MDIS // clear module disable
143  &~MCF_ASP_CR_CALA // no cal
144  // | MCF_ASP_CR_CALA // enable cal
145  | MCF_ASP_CR_PENE // pen detect enable
146  | MCF_ASP_CR_TSE // touch detect enable
147  & ~MCF_ASP_CR_AZE // no auto zero
148  // | MCF_ASP_CR_AZE // auto zero enable
149  &~(MCF_ASP_CR_TSTYPE(0x00)) //4 wire
150  // | MCF_ASP_CR_TSTYPE(0x01) //5 wire
151  // | MCF_ASP_CR_TSTYPE(0x10) //7 wire
152  // | MCF_ASP_CR_TSTYPE(0x11) //8 wire
153  &~MCF_ASP_CR_AUTO //turn off auto
154  // | MCF_ASP_CR_AUTO
155  &~(MCF_ASP_CR_MODE(00)) // clear mode (set mode zero)
156  | MCF_ASP_CR_MODE(0x01) // set mode one
157  // | MCF_ASP_CR_MODE(0x10) // set mode two
158  // | MCF_ASP_CR_MODE(0x11) // set mode three
159  );// | MCF_ASP_CR_ASPE
160 
161  MCF_ASP_CLKD = MCF_ASP_CLKD_CLKD(0x4E); //1Mhz At 80MHz Core
162  //MCF_ASP_CLKD = MCF_ASP_CLKD_CLKD(0x27); //2Mhz At 80MHz Core
163  //MCF_ASP_CLKD = MCF_ASP_CLKD_CLKD(0x14); //4Mhz At 80MHz Core
164  //MCF_ASP_CLKD = MCF_ASP_CLKD_CLKD(0x0A); //8Mhz At 80MHz Core
165 
166  MCF_ASP_ICR = ( 0
167  // |MCF_ASP_ICR_PDRIE // FIFO data avail
168  |MCF_ASP_ICR_PFFIE // FIFO full
169  |MCF_ASP_ICR_PFLIE // FIFO level
170  // |MCF_ASP_ICR_PFLDE // FIFO DMA / INT req
171  |MCF_ASP_ICR_PDIE // pen dwn
172  |MCF_ASP_ICR_PUIE // pen up
173  |MCF_ASP_ICR_POVIE // FIFO Overflow
174  |MCF_ASP_ICR_FIFO_WM(16)
175  ); // set WM / enable all interrupt sources
176 
177  //MCF_ASP_TIM = 0x00010111; //setup ASPC -> PANNEL timing
178  //MCF_ASP_TIM = 0x0800ff88; //setup ASPC -> PANNEL timing
179  MCF_ASP_TIM = 0x0F00ffFF; //setup ASPC -> PANNEL timing
180 
181  //temp = MCF_ASP_SFIFO; //clear the pointers.
182  MCF_ASP_FIFOP = 0; //clear the pointers.
183  MCF_ASP_ISR = 0x000000B7; // clear all interrupts
184 
185  MCF_ASP_CR |= ( MCF_ASP_CR_AUTO); //enable auto scan| MCF_ASP_CR_AZE
186 
187  return 1;
188  }
189 
190  //-----------------------------------------------------------------------------
191  // FUNCTION: D4DTCH_DeInit_Mcf52277_asp
192  // SCOPE: Low Level Driver API function
193  // DESCRIPTION: The function is used for deinitialization of this low level driver
194  //
195  // PARAMETERS: none
196  //
197  // RETURNS: result: 1 - Success
198  // 0 - Failed
199  //-----------------------------------------------------------------------------
200  static unsigned char D4DTCH_DeInit_Mcf52277_asp(void)
201  {
202  MCF_ASP_CR = 0x00080000; // Disable ASP module
203  return 1;
204  }
205 
206  //-----------------------------------------------------------------------------
207  // FUNCTION: D4DTCH_GetRawLimits_Mcf52277_asp
208  // SCOPE: Low Level Driver API function
209  // DESCRIPTION: The function returns pointer on touch screen raw limits
210  // structure.
211  // PARAMETERS: none
212  //
213  // RETURNS: pointer on touch screen raw limit structure
214  //
215  //-----------------------------------------------------------------------------
216  static D4D_TOUCHSCREEN_LIMITS* D4DTCH_GetRawLimits_Mcf52277_asp(void)
217  {
218  return (D4D_TOUCHSCREEN_LIMITS*)&d4dtch_mcf52277_asp_limits;
219  }
220 
221  //-----------------------------------------------------------------------------
222  // FUNCTION: D4DTCH_GetPositionRaw_Mcf52277_asp
223  // SCOPE: Low Level Driver API function
224  // DESCRIPTION: Reads touch screen and returns raw uncompensated X, Y
225  // coordinates if screen touched
226  // PARAMETERS: unsigned short *TouchPositionX Pointer to X coordinate
227  // unsigned short *TouchPositionY Pointer to Y ccordinate
228  // RETURNS: 0 no screen touch
229  // 1 screen touch,
230  //-----------------------------------------------------------------------------
231  static unsigned char D4DTCH_GetPositionRaw_Mcf52277_asp (unsigned short *TouchPositionX,
232  unsigned short *TouchPositionY)
233  {
234 
235  if(touched == 0)
236  return 0;
237 
238  *TouchPositionX = coordinationX;
239  *TouchPositionY = coordinationY;
240 
241 
242  return 1;
243  }
244 
245  static void mcf5xxx_set_handler (int vector, int (*handler) (void))
246  {
247  extern uint32 D4DTCHHW_VECTOR_RAM[];
248 
249  D4DTCHHW_VECTOR_RAM[vector] = (uint32)handler;
250  }
251 
252  /********************************************************************/
253 //
254 /********************************************************************/
255 void read_aspc_fifo(void)
256 {
257  uint8 incount=0;
258  uint8 avgcount=0;
259  uint32 MCF_ASP_SFIFO_temp;
260 
261  uint16 coorX[32];
262  uint16 coorY[32];
263 
264 
265  while (((MCF_ASP_FIFOP & 0x003F0000)>>16) != (MCF_ASP_FIFOP & 0x0000003F))
266  {
267  MCF_ASP_SFIFO_temp=MCF_ASP_SFIFO;
268 
269  switch(MCF_ASP_SFIFO_temp & 0x0000F000)
270  {
271  case MCF_ASP_SFIFO_CHANID_X_COORD:
272  coorX[incount] = (uint16)(MCF_ASP_SFIFO_temp & 0x00000FFF);
273  break;
274 
275  case MCF_ASP_SFIFO_CHANID_Y_COORD:
276  coorY[incount] = (uint16)(MCF_ASP_SFIFO_temp & 0x00000FFF);
277  incount++;
278  break;
279 
280  default:
281  break;
282  }
283  }
284 
285  for (avgcount=1;avgcount<=incount-1;avgcount++){
286  coorX[0] += coorX[avgcount];
287  coorY[0] += coorY[avgcount];
288  }
289 
290  if(avgcount>=1){
291  coorX[0] /= avgcount;
292  coorY[0] /= avgcount;
293 
294  }
295  #if D4DTCH_MIRROVED_X == 1
296  coordinationX = (uint16)(4096 - coorX[0]);
297  #else
298  coordinationX = coorX[0];
299  #endif
300 
301  #if D4DTCH_MIRROVED_Y == 1
302  coordinationY = (uint16)(4096 - coorY[0]);
303  #else
304  coordinationY = coorY[0];
305  #endif
306 
307  #if D4DTCH_SWAP_AXES == 1
308  coorX[0] = coordinationX;
309  coordinationX = coordinationY;
310  coordinationY = coorX[0];
311  #endif
312 
313 }
314 
315  /********************************************************************/
316  //
317  // The calls in the handler below are in a specific order as flags
318  // for events will be set even if interrupts are disabled.
319  // (just does not cause an int to ocurr)
320  //
321  /********************************************************************/
322  __declspec(interrupt) int aspc_handler(void)
323  {
324 
325  if(MCF_ASP_ISR & MCF_ASP_ISR_PUF){ // pen up detected
326  //printf("Pen Up\n");
327  MCF_ASP_ISR = MCF_ASP_ISR_PUF | MCF_ASP_ISR_PDF; // clear pen flags
328  // MCF_ASP_CR &= (~MCF_ASP_CR_ASPE); //stop convertion
329  MCF_ASP_ICR |= MCF_ASP_ICR_PDIE; // turn on PenDwn int.
330 
331  MCF_GPIO_PCLRR_TIMER = 0xf7;
332  touched = 0;
333  #if D4DTCH_ASYNCH_EVENTS == 1
334  D4D_PutRawTouchScreen(0, 0, 0);
335  #endif
336  }
337  if(MCF_ASP_ISR & MCF_ASP_ISR_PFFF){ // FIFO Full (should not be here)
338  //printf("FIFO Full\n");
339  MCF_ASP_FIFOP = 0; // clear FIFo pointers.
340  }
341  if(MCF_ASP_ISR & MCF_ASP_ISR_PFLF){
342  //printf("PFLF\n");
343  MCF_ASP_CR &= (~MCF_ASP_CR_ASPE); //stop convertion
344  read_aspc_fifo();
345  MCF_GPIO_PPDSDR_TIMER = 0x08;
346  touched = 1;
347  #if D4DTCH_ASYNCH_EVENTS == 1
348  D4D_PutRawTouchScreen(1, coordinationX, coordinationY);
349  #endif
350  }
351  if(MCF_ASP_ISR & MCF_ASP_ISR_PDRF){ // FIFO has data
352  //printf("FIFO has data\n");
353  MCF_ASP_ISR = MCF_ASP_ISR_PDRF; // clear flag
354  }
355  if(MCF_ASP_ISR & MCF_ASP_ISR_PDF){ // pen down detected
356  //printf("Pen Dwn\n");
357  MCF_ASP_ISR = MCF_ASP_ISR_PDF; // clear flag
358  MCF_ASP_ICR &= ~MCF_ASP_ICR_PDIE; // turn off PenDwn int.
359  MCF_ASP_CR |= MCF_ASP_CR_ASPE; // start convertion
360  MCF_ASP_FIFOP = 0; // clear FIFo pointers.
361 
362  }
363  if(MCF_ASP_ISR & MCF_ASP_ISR_POVF){
364  //printf("FIFO Overflow\n");
365  MCF_ASP_FIFOP = 0; // clear FIFo pointers.
366  MCF_ASP_ISR = MCF_ASP_ISR_POVF;
367  }
368 
369  return( 1) ;
370  }
371 
372 #endif //(D4D_MK_STR(D4D_LLD_TCH) == d4dtch_mcf52277_asp_ID)
#define D4DTCHHW_VECTOR_RAM
#define D4DTCH_Y_TOUCH_OFFMAX
#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.
void D4D_PutRawTouchScreen(D4D_BOOL touched, D4D_COOR x, D4D_COOR y)
D4D Driver private header file.
#define D4DTCH_X_TOUCH_OFFMAX
D4D low level touch screen limitation structure.
Definition: d4d_lldapi.h:105
#define D4DTCH_X_TOUCH_MIN
D4D driver - mcf52277_asp touch screen driver function header file.
D4D driver - resistive touch screen driver function header file.