LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lpc43xx_systick.c
Go to the documentation of this file.
1 /*
2  * @brief System Tick module functions for stand-alone configuration
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2012
6  * All rights reserved.
7  *
8  * @par
9  * Software that is described herein is for illustrative purposes only
10  * which provides customers with programming information regarding the
11  * LPC products. This software is supplied "AS IS" without any warranties of
12  * any kind, and NXP Semiconductors and its licensor disclaim any and
13  * all warranties, express or implied, including all implied warranties of
14  * merchantability, fitness for a particular purpose and non-infringement of
15  * intellectual property rights. NXP Semiconductors assumes no responsibility
16  * or liability for the use of the software, conveys no license or rights under any
17  * patent, copyright, mask work right, or any other intellectual property rights in
18  * or to any products. NXP Semiconductors reserves the right to make changes
19  * in the software without notification. NXP Semiconductors also makes no
20  * representation or warranty that such application will be suitable for the
21  * specified use without further testing or modification.
22  *
23  * @par
24  * Permission to use, copy, modify, and distribute this software and its
25  * documentation is hereby granted, under NXP Semiconductors' and its
26  * licensor's relevant copyrights in the software, without fee, provided that it
27  * is used in conjunction with NXP Semiconductors microcontrollers. This
28  * copyright, permission, and disclaimer notice must appear in all copies of
29  * this code.
30  */
31 
37 #include "chip.h"
38 #include "board.h"
39 
40 #include "GUI.h"
41 
51 /*****************************************************************************
52  * Private types/enumerations/variables
53  ****************************************************************************/
54 /* Saved reference period */
56 static int16_t old_tmp_x = -1, old_tmp_y = -1;
57 
58 /* Check every 20ms for TSC events */
59 #define TSC_CHECK_DELAY (20)
60 
61 #if (defined(CHIP_LPC43XX) && defined(CORE_M0))
62 
63 #define RITIMER_IRQn_PRI (255)
64 
65 /* RITimer Reload value */
66 static uint32_t reload_val;
67 #endif
68 
69 /*****************************************************************************
70  * Public types/enumerations/variables
71  ****************************************************************************/
72 
76 /* Saved total time in mS since timer was enabled */
78 
82 extern volatile int tsc_init_done;
83 
88 
89 /*****************************************************************************
90  * Private functions
91  ****************************************************************************/
92 
93 /*****************************************************************************
94  * Public functions
95  ****************************************************************************/
96 
97 #if (defined(CHIP_LPC43XX) && defined(CORE_M0))
98 
107 void SysTick_Enable(uint32_t period)
108 {
109  saved_period = period;
110 
111  /* Clear any pending interrupt */
113 
114  /* Calculate reload value */
115  reload_val = ( SystemCoreClock / ( 1000 / period ) );
116  Chip_RIT_SetCOMPVAL(Chip_RIT_GetCounter() + reload_val);/* Let it tick */
117 
118  /* Set the priority and enable the interrupt */
119  NVIC_SetPriority((IRQn_Type) RITIMER_IRQn, RITIMER_IRQn_PRI);
120  NVIC_EnableIRQ((IRQn_Type) RITIMER_IRQn);
121 }
122 
130 void SysTick_Disable(void)
131 {
133 }
134 
144 void RIT_IRQHandler(void)
145 {
146  int16_t tmp_x = -1, tmp_y = -1;
147  int16_t tmp_x1 = -1, tmp_y1 = -1;
148  static uint8_t tsc_tick = 0;
149  static uint8_t pressed = 0;
150  bool touched;
151 
152  /* Clear RITimer Interrupt, Reload counter value */
154  Chip_RIT_SetCOMPVAL(Chip_RIT_GetCounter() + reload_val);/* Reload value */
155 
156  /* Increment tick count */
158 
159  /* If TSC enabled, store Touch event */
160  if (tsc_init_done) {
161  tsc_tick += saved_period;
162  if (tsc_tick == TSC_CHECK_DELAY) {
163  touched = GetTouchPos((int16_t *) &tmp_x, (int16_t *) &tmp_y);
164  if (touched == true) {
165  if (pressed == 1) {
166  if ((tmp_x >= 0) && (tmp_y > 0) && ((tmp_x != old_tmp_x) || (tmp_y != old_tmp_y))) {
167  tmp_x1 = tmp_y;
168  tmp_y1 = tmp_x;
169  GUI_TOUCH_StoreState(320 - tmp_x1, tmp_y1);
170  old_tmp_x = tmp_x;
171  old_tmp_y = tmp_y;
172  }
173  }
174  else {
175  GUI_TOUCH_StoreState(320 - tmp_x1, tmp_y1);
176  old_tmp_x = tmp_x;
177  old_tmp_y = tmp_y;
178  pressed = 1;
179  }
180  }
181  else {
182  if (pressed == 1) {
183  GUI_TOUCH_StoreState(-1, -1);
184  pressed = 0;
185  }
186  }
187  tsc_tick = 0;
188  }
189  }
190 }
191 
192 #else
193 
203 {
204  saved_period = period;
205  SysTick_Config((SystemCoreClock * period) / 1000);
206 }
207 
213 void SysTick_Disable(void)
214 {
215  SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
216 }
217 
226 void SysTick_Handler(void)
227 {
228  int16_t tmp_x = -1, tmp_y = -1;
229  int16_t tmp_x1 = -1, tmp_y1 = -1;
230  static uint8_t tsc_tick = 0;
231  static uint8_t pressed = 0;
232  bool touched;
233 
234  /* Increment tick count */
236 
237  /* If TSC enabled, store Touch event */
238  if (tsc_init_done) {
239  tsc_tick += saved_period;
240  if (tsc_tick == TSC_CHECK_DELAY) {
241  touched = GetTouchPos((int16_t *) &tmp_x, (int16_t *) &tmp_y);
242  if (touched == true) {
243  if (pressed == 1) {
244  if ((tmp_x >= 0) && (tmp_y > 0) && ((tmp_x != old_tmp_x) || (tmp_y != old_tmp_y))) {
245  tmp_x1 = tmp_y;
246  tmp_y1 = tmp_x;
247  GUI_TOUCH_StoreState(320 - tmp_x1, tmp_y1);
248  old_tmp_x = tmp_x;
249  old_tmp_y = tmp_y;
250  }
251  }
252  else {
253  GUI_TOUCH_StoreState(320 - tmp_x1, tmp_y1);
254  old_tmp_x = tmp_x;
255  old_tmp_y = tmp_y;
256  pressed = 1;
257  }
258  }
259  else {
260  if (pressed == 1) {
261  GUI_TOUCH_StoreState(-1, -1);
262  pressed = 0;
263  }
264  }
265  tsc_tick = 0;
266  }
267  }
268 }
269 
270 #endif
271 
276 /* --------------------------------- End Of File ------------------------------ */