Line No. | Rev | Author | Line |
---|---|---|---|
1 | 32 | kaklik | /***************************************************************************** |
2 | * FileName: mTouchCap_CtmuAPI.c |
||
3 | * Dependencies: |
||
4 | * Processor: PIC18, PIC24 |
||
5 | * Compiler: C18, C30 |
||
6 | * Linker: MPLINK,MPLAB LINK30 |
||
7 | * Company: Microchip Technology Incorporated |
||
8 | * |
||
9 | * Software License Agreement |
||
10 | * |
||
11 | * Copyright © 2009 Microchip Technology Inc. |
||
12 | * Microchip licenses this software to you solely for use with Microchip products, according to the terms of the |
||
13 | * accompanying click-wrap software license. Microchip and its licensors retain all right, title and interest in |
||
14 | * and to the software. All rights reserved. This software and any accompanying information is for suggestion only. |
||
15 | * It shall not be deemed to modify Microchips standard warranty for its products. It is your responsibility to ensure |
||
16 | * that this software meets your requirements. |
||
17 | |||
18 | * SOFTWARE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
||
19 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT |
||
20 | * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP OR ITS LICENSORS BE LIABLE |
||
21 | * FOR ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO INCIDENTAL, |
||
22 | * SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, |
||
23 | * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, OR ANY CLAIMS BY THIRD PARTIES |
||
24 | * (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS. |
||
25 | * The aggregate and cumulative liability of Microchip and its licensors for damages related to the use of the software |
||
26 | * will in no event exceed $1000 or the amount you paid Microchip for the software, whichever is greater. |
||
27 | |||
28 | * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE TERMS AND |
||
29 | * THE TERMS OF THE ACCOMPANYING CLICK-WRAP SOFTWARE LICENSE. |
||
30 | * |
||
31 | * |
||
32 | * Author Date Comment |
||
33 | *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
||
34 | * Naveen. M 14 Apr 2009 Version 0.1 Initial Draft |
||
35 | * Sasha. M / Naveen. M 4 May 2009 Version 0.2 Updates |
||
36 | * Bruce Bohn 10 Nov 2009 Version 0.3 Updates |
||
37 | * Sasha. M / Naveen. M 11 Nov 2009 Version 1.0 Release |
||
38 | * Sasha. M / Nithin. 10 April 2010 Version 1.20 Release |
||
39 | *****************************************************************************/ |
||
40 | #ifndef _MTOUCHCAP_CTMU_API_C |
||
41 | #define _MTOUCHCAP_CTMU_API_C |
||
42 | |||
43 | |||
44 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
45 | /* ~~~~~~~~~~~~~~~~~~~~~ Includes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
46 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
47 | |||
48 | #include "mTouchCap_CtmuAPI.h" |
||
49 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
50 | /* ~~~~~~~~~~~~~~~~~~~~~ Variables ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
51 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
52 | CHAR trimbitsReady; |
||
53 | // array to store the active channel numbers that will be scanned in ISR |
||
54 | #ifdef __PIC24F__ |
||
55 | WORD ScanChannels[MAX_ADC_CHANNELS]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; |
||
56 | #else |
||
57 | WORD ScanChannels[MAX_ADC_CHANNELS]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; |
||
58 | #endif |
||
59 | BYTE ScanChannelIndex =0; // store the index of the channels that has to be scanned |
||
60 | BYTE Previous_Pressed_Channel_Num =0; //stores the channel number of the previous key that was pressed |
||
61 | BYTE Decode_Method_Used=DECODE_METHOD_PRESS_ASSERT; |
||
62 | |||
63 | |||
64 | |||
65 | |||
66 | |||
67 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
68 | /* ~~~~~~~~~~~~~~~~~~~~~ Function Prototypes ~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
69 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
70 | |||
71 | |||
72 | |||
73 | |||
74 | |||
75 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
76 | /* ~~~~~~~~~~~~~~~~~~~~~ Declarations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
77 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
78 | |||
79 | |||
80 | |||
81 | |||
82 | |||
83 | |||
84 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
85 | /* ~~~~~~~~~~~~~~~~~~~~~ Function Definitions ~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
86 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
87 | /******************************************************************** |
||
88 | Function : void mTouchCap_Init(void) |
||
89 | |||
90 | PreCondition : None |
||
91 | |||
92 | Input : None |
||
93 | |||
94 | Output : None |
||
95 | |||
96 | Side Effects : None |
||
97 | |||
98 | Overview : This function initializes the PORT, CTMU, TIMER and ADC modules. |
||
99 | |||
100 | |||
101 | *******************************************************************/ |
||
102 | void mTouchCap_Init(void) |
||
103 | { |
||
104 | WORD Index=0; |
||
105 | |||
106 | /* Initialize Physical layer */ |
||
107 | mTouchCapPhy_InitCTMU(); |
||
108 | |||
109 | |||
110 | /*************************************************************************** |
||
111 | --------------- Demo of API "mTouchCapAPI_SetUpCTMU_Default" ----------------------- |
||
112 | Initialize the CTMU module to defaults using the API "mTouchCapAPI_SetUpCTMU_Default". |
||
113 | ***************************************************************************/ |
||
114 | trimbitsReady = 0; |
||
115 | for (Index=0; Index < ScanChannelIndex; Index++) |
||
116 | { |
||
117 | mTouchCapAPI_SetUpCTMU_Default(ScanChannels[Index]); |
||
118 | } |
||
119 | |||
120 | trimbitsReady = 1; |
||
121 | |||
122 | #ifdef USE_STATIC_TRIP_VALUE |
||
123 | mTouchCap_UpdateStaticTripValue(); // Update the STATIC TRIP values defined in config.h |
||
124 | #endif |
||
125 | |||
126 | mTouchCapPhy_TickInit(); // Initialize Timer for system tick |
||
127 | |||
128 | mTouchCapPhy_StablizeChannelData(); |
||
129 | } |
||
130 | |||
131 | |||
132 | /******************************************************************** |
||
133 | Function : void mTouchCapAPI_SetUpCTMU_Default(WORD ChannelNum) |
||
134 | |||
135 | PreCondition : None |
||
136 | |||
137 | Input : ChannelNum- Channel Number |
||
138 | |||
139 | Output : None |
||
140 | |||
141 | Side Effects : None |
||
142 | |||
143 | Overview : This API is for those who want to use the cap-touch application without having to tweak much. |
||
144 | The API sets up the channel in a predefined default method with known configuration settings. |
||
145 | |||
146 | |||
147 | *******************************************************************/ |
||
148 | void mTouchCapAPI_SetUpCTMU_Default(WORD ChannelNum) |
||
149 | { |
||
150 | |||
151 | actualValue [ChannelNum] = 0; |
||
152 | avg_delay [ChannelNum] = 0; |
||
153 | curRawData[ChannelNum] = 0; |
||
154 | averageData[ChannelNum] = 0; |
||
155 | |||
156 | hystValue[ChannelNum] = 0; |
||
157 | channel_TRIM_value[ChannelNum] = 0; |
||
158 | channel_IRNG_value [ChannelNum] = 0; |
||
159 | Press_State[ChannelNum] = 0; |
||
160 | Channel_Pressed_Status[ChannelNum] = 0; |
||
161 | //ScanChannels[ChannelNum]=0; |
||
162 | /* Initialize Trip Value */ |
||
163 | #ifndef USE_STATIC_TRIP_VALUE |
||
164 | tripValue[ChannelNum] = DEFAULT_TRIP_VALUE; |
||
165 | #endif |
||
166 | mTouchCapPhy_ChargeTimeInit(); |
||
167 | |||
168 | /*************************************************************************** |
||
169 | --------------- Demo of API "mTouchCapAPI_AutoAdjustChannel" ----------------------- |
||
170 | Automatically adjust the charge voltage channel using the API "mTouchCapAPI_AutoAdjustChannel". |
||
171 | ***************************************************************************/ |
||
172 | if (FAILED == mTouchCapAPI_AutoAdjustChannel(ChannelNum,CTMU_CHARGE_VOLTAGE_TO_ACHIEVE) ) //0x2FF, 75% of charging of ADC Value 1024*0.75 |
||
173 | { |
||
174 | // DO THE ERROR HANDLING HERE |
||
175 | } |
||
176 | |||
177 | } |
||
178 | |||
179 | |||
180 | /********* End of Function *********************/ |
||
181 | |||
182 | |||
183 | /******************************************************************** |
||
184 | Function : WORD mTouchCapAPI_CTMU_GetChannelReading(WORD ChannelNum) |
||
185 | |||
186 | PreCondition : Channel setup is complete |
||
187 | |||
188 | Input : ChannelNum - Channel number (must have enabled in "mTouchCAp_Config.h") |
||
189 | CHANNEL_AN0 , |
||
190 | CHANNEL_AN1 , |
||
191 | CHANNEL_AN2 , |
||
192 | CHANNEL_AN3 , |
||
193 | CHANNEL_AN4 , |
||
194 | CHANNEL_AN5 , |
||
195 | CHANNEL_AN6 , |
||
196 | CHANNEL_AN7 , |
||
197 | CHANNEL_AN8 , |
||
198 | CHANNEL_AN9 , |
||
199 | CHANNEL_AN10 , |
||
200 | CHANNEL_AN11 , |
||
201 | CHANNEL_AN12 , |
||
202 | CHANNEL_AN13 , // for PIC24. Not available in PIC18 |
||
203 | CHANNEL_AN14 , // for PIC24. Not available in PIC18 |
||
204 | CHANNEL_AN15 // for PIC24. Not available in PIC18 |
||
205 | |||
206 | |||
207 | Output : ChannelData :ADC value (Range for 10 bit ADC is 0 : 0x3FF) |
||
208 | |||
209 | Side Effects : None |
||
210 | |||
211 | Overview : This API is used to get the channel reading. It initializes the CTMU and ADC module |
||
212 | for the corresponding channel passed. It reads ADC data from the channel and returns. |
||
213 | |||
214 | *******************************************************************/ |
||
215 | WORD mTouchCapAPI_CTMU_GetChannelReading(WORD ChannelNum) |
||
216 | { |
||
217 | WORD ChannelData; |
||
218 | |||
219 | /* Check for valid channel number being passed */ |
||
220 | if ( (ChannelNum >= CHANNEL_AN0) && (ChannelNum < MAX_ADC_CHANNELS)) |
||
221 | { |
||
222 | |||
223 | mTouchCapPhy_ChannelSetup (ChannelNum); |
||
224 | |||
225 | CTMU_Current_trim_config(ChannelNum); |
||
226 | |||
227 | mTouchCapPhy_Discharge_Current (); |
||
228 | |||
229 | mTouchCapPhy_Charge_Current (); |
||
230 | |||
231 | /* Disable CTMU Edge*/ |
||
232 | Disbl_CTMUEdge1; |
||
233 | |||
234 | ChannelData = mTouchCapPhy_Read_ADC(); |
||
235 | } |
||
236 | else |
||
237 | { |
||
238 | /* Error: exceeded available channel numbers */ |
||
239 | ChannelData = ADC_UNTOUCHED_VALUE_10_BIT; //Indicates untouched value for 12-bit ADC |
||
240 | } |
||
241 | |||
242 | return ChannelData; |
||
243 | } |
||
244 | |||
245 | /******************************************************************** |
||
246 | Function : CHAR mTouchCapAPI_AutoAdjustChannel (WORD ChannelNum, WORD AdcValueToAchieve) |
||
247 | |||
248 | PreCondition : Channel setup is complete. |
||
249 | |||
250 | Input : ChannelNum - Channel number |
||
251 | CHANNEL_AN0 , |
||
252 | CHANNEL_AN1 , |
||
253 | CHANNEL_AN2 , |
||
254 | CHANNEL_AN3 , |
||
255 | CHANNEL_AN4 , |
||
256 | CHANNEL_AN5 , |
||
257 | CHANNEL_AN6 , |
||
258 | CHANNEL_AN7 , |
||
259 | CHANNEL_AN8 , |
||
260 | CHANNEL_AN9 , |
||
261 | CHANNEL_AN10 , |
||
262 | CHANNEL_AN11 , |
||
263 | CHANNEL_AN12 , |
||
264 | CHANNEL_AN13 , // for PIC24. Not available in PIC18 |
||
265 | CHANNEL_AN14 , // for PIC24. Not available in PIC18 |
||
266 | CHANNEL_AN15 // for PIC24. Not available in PIC18 |
||
267 | |||
268 | AdcValueToAchieve - ADC Value to be achieved |
||
269 | |||
270 | Output : CHAR ChannelAdjResult |
||
271 | * -1 : FAILED |
||
272 | * 1 : PASSED |
||
273 | |||
274 | |||
275 | Side Effects : None |
||
276 | |||
277 | Overview : This API is used to automatically adjust the voltage reading(charge level) on a channel. This will read the |
||
278 | ADC value after charging the channel, and then adjust the CTMU current source Trim bits |
||
279 | to read the value defined as per AUTO_ADJUST_BAND_PERCENT. |
||
280 | |||
281 | *******************************************************************/ |
||
282 | |||
283 | CHAR mTouchCapAPI_AutoAdjustChannel (WORD ChannelNum, WORD AdcValueToAchieve) |
||
284 | { |
||
285 | CHAR ChannelAdjResult = FAILED; |
||
286 | WORD AdcValueToAchieve_DataRangeMax; |
||
287 | WORD AdcValueToAchieve_DataRangeMin; |
||
288 | WORD ChannelAdcData; |
||
289 | CHAR Trim_Value; |
||
290 | CHAR Currrent_range_value; |
||
291 | BYTE DelayLoop; |
||
292 | |||
293 | |||
294 | Trim_Value = 0; |
||
295 | Currrent_range_value = CURRENT_RANGE_100XBASE_CURRENT; |
||
296 | /* Check for valid channel number being passed */ |
||
297 | if (! ( (ChannelNum >= CHANNEL_AN0) && (ChannelNum < MAX_ADC_CHANNELS)) ) |
||
298 | { |
||
299 | /* return the error value if not a valid channel number */ |
||
300 | ChannelAdjResult = FAILED; |
||
301 | } |
||
302 | else //Handle the Auto adjustment for a valid channel |
||
303 | { |
||
304 | |||
305 | do { |
||
306 | |||
307 | mTouchCapAPI_CTMU_SetupCurrentSource(Currrent_range_value,Trim_Value); |
||
308 | for (DelayLoop=0; DelayLoop<= 20; DelayLoop++) |
||
309 | { |
||
310 | Nop(); |
||
311 | Nop(); |
||
312 | Nop(); |
||
313 | Nop(); |
||
314 | } |
||
315 | |||
316 | ChannelAdcData = mTouchCapAPI_CTMU_GetChannelReading(ChannelNum); |
||
317 | |||
318 | AdcValueToAchieve_DataRangeMax = (AdcValueToAchieve + (AdcValueToAchieve*AUTO_ADJUST_BAND_PERCENT/100)); |
||
319 | AdcValueToAchieve_DataRangeMin = (AdcValueToAchieve - (AdcValueToAchieve*AUTO_ADJUST_BAND_PERCENT/100)); |
||
320 | |||
321 | if( ChannelAdcData>=AdcValueToAchieve_DataRangeMin && ChannelAdcData<=AdcValueToAchieve_DataRangeMax ) |
||
322 | { |
||
323 | ChannelAdjResult = PASSED; |
||
324 | channel_TRIM_value[ChannelNum] =Trim_Value; |
||
325 | channel_IRNG_value[ChannelNum] = CTMU_Get_Current_Source; |
||
326 | break; |
||
327 | } |
||
328 | else |
||
329 | { |
||
330 | if ( CTMU_Get_Current_Source == CURRENT_RANGE_100XBASE_CURRENT) |
||
331 | { |
||
332 | if(Trim_Value<=CURRENT_SOURCE_TRIM_BITS_MAX_POSITIVE) |
||
333 | { |
||
334 | Trim_Value = Trim_Value+AUTO_ADJUST_STEP_SIZE; |
||
335 | if(Trim_Value>CURRENT_SOURCE_TRIM_BITS_MAX_POSITIVE) |
||
336 | { |
||
337 | Trim_Value = CURRENT_SOURCE_TRIM_BITS_MIN_NEGATIVE; |
||
338 | } |
||
339 | |||
340 | } |
||
341 | |||
342 | if(Trim_Value>=CURRENT_SOURCE_TRIM_BITS_MAX_NEGATIVE) |
||
343 | { |
||
344 | Trim_Value = Trim_Value-AUTO_ADJUST_STEP_SIZE; |
||
345 | if(Trim_Value<CURRENT_SOURCE_TRIM_BITS_MAX_NEGATIVE) |
||
346 | { |
||
347 | Trim_Value = CURRENT_SOURCE_TRIM_BITS_NOMINAL; |
||
348 | Currrent_range_value = CURRENT_RANGE_10XBASE_CURRENT; |
||
349 | } |
||
350 | } |
||
351 | } |
||
352 | else if ( CTMU_Get_Current_Source == CURRENT_RANGE_10XBASE_CURRENT) |
||
353 | { |
||
354 | if(Trim_Value<=CURRENT_SOURCE_TRIM_BITS_MAX_POSITIVE) |
||
355 | { |
||
356 | Trim_Value = Trim_Value+AUTO_ADJUST_STEP_SIZE; |
||
357 | if(Trim_Value>CURRENT_SOURCE_TRIM_BITS_MAX_POSITIVE) |
||
358 | { |
||
359 | Trim_Value = CURRENT_SOURCE_TRIM_BITS_MIN_NEGATIVE; |
||
360 | } |
||
361 | |||
362 | } |
||
363 | |||
364 | if(Trim_Value>=CURRENT_SOURCE_TRIM_BITS_MAX_NEGATIVE) |
||
365 | { |
||
366 | Trim_Value = Trim_Value-AUTO_ADJUST_STEP_SIZE; |
||
367 | if(Trim_Value<CURRENT_SOURCE_TRIM_BITS_MAX_NEGATIVE) |
||
368 | { |
||
369 | Trim_Value = CURRENT_SOURCE_TRIM_BITS_NOMINAL; |
||
370 | Currrent_range_value = CURRENT_RANGE_BASE_CURRENT; |
||
371 | } |
||
372 | } |
||
373 | } |
||
374 | else |
||
375 | { |
||
376 | if(Trim_Value<=CURRENT_SOURCE_TRIM_BITS_MAX_POSITIVE) |
||
377 | { |
||
378 | Trim_Value = Trim_Value+AUTO_ADJUST_STEP_SIZE; |
||
379 | if(Trim_Value>CURRENT_SOURCE_TRIM_BITS_MAX_POSITIVE) |
||
380 | { |
||
381 | Trim_Value = CURRENT_SOURCE_TRIM_BITS_MIN_NEGATIVE; |
||
382 | } |
||
383 | |||
384 | } |
||
385 | |||
386 | if(Trim_Value>=CURRENT_SOURCE_TRIM_BITS_MAX_NEGATIVE) |
||
387 | { |
||
388 | Trim_Value = Trim_Value-AUTO_ADJUST_STEP_SIZE; |
||
389 | if(Trim_Value<CURRENT_SOURCE_TRIM_BITS_MAX_NEGATIVE) |
||
390 | { |
||
391 | ChannelAdjResult = FAILED; |
||
392 | break; |
||
393 | } |
||
394 | } |
||
395 | } |
||
396 | |||
397 | } |
||
398 | |||
399 | }while(1); |
||
400 | } |
||
401 | |||
402 | return ChannelAdjResult; |
||
403 | } |
||
404 | |||
405 | /********* End of Function *********************/ |
||
406 | |||
407 | |||
408 | |||
409 | |||
410 | /******************************************************************** |
||
411 | Function : void mTouchCapAPI_CTMU_SetupCurrentSource (BYTE CurrentSourceRange, BYTE TrimValue) |
||
412 | |||
413 | PreCondition : None |
||
414 | |||
415 | Input : CurrentSourceRange - Current source range |
||
416 | * CURRENT_RANGE_100XBASE_CURRENT //urrent source Range is 100*Base current (55uA) |
||
417 | * CURRENT_RANGE_10XBASE_CURRENT //Current source Range is 10*Base current (5.5uA) |
||
418 | * CURRENT_RANGE_BASE_CURRENT //Current source Range is Base current (0.55uA) |
||
419 | * CURRENT_SRC_DISABLED //Current source disabled |
||
420 | |||
421 | TrimValue - Trim settings |
||
422 | |||
423 | Output : None |
||
424 | |||
425 | Side Effects : None |
||
426 | |||
427 | Overview : This API sets the current source and trim level for a particular channel. |
||
428 | |||
429 | *******************************************************************/ |
||
430 | void mTouchCapAPI_CTMU_SetupCurrentSource (BYTE CurrentSourceRange, BYTE TrimValue) |
||
431 | { |
||
432 | |||
433 | mTouchCapPhy_SetupCurrentSourceRange(CurrentSourceRange); |
||
434 | mTouchCapPhy_SetTrimValue( TrimValue); |
||
435 | |||
436 | } |
||
437 | |||
438 | |||
439 | /********* End of Function *********************/ |
||
440 | |||
441 | /******************************************************************** |
||
442 | Function : WORD mTouchCapAPI_ScanChannelIterative (WORD ChannelNum, BYTE SampleCount) |
||
443 | |||
444 | PreCondition : Channel setup is complete. |
||
445 | |||
446 | Input : ChannelNum - Channel number |
||
447 | CHANNEL_AN0 , |
||
448 | CHANNEL_AN1 , |
||
449 | CHANNEL_AN2 , |
||
450 | CHANNEL_AN3 , |
||
451 | CHANNEL_AN4 , |
||
452 | CHANNEL_AN5 , |
||
453 | CHANNEL_AN6 , |
||
454 | CHANNEL_AN7 , |
||
455 | CHANNEL_AN8 , |
||
456 | CHANNEL_AN9 , |
||
457 | CHANNEL_AN10 , |
||
458 | CHANNEL_AN11 , |
||
459 | CHANNEL_AN12 , |
||
460 | CHANNEL_AN13 , // for PIC24. Not available in PIC18 |
||
461 | CHANNEL_AN14 , // for PIC24. Not available in PIC18 |
||
462 | CHANNEL_AN15 // for PIC24. Not available in PIC18 |
||
463 | |||
464 | SampleCount - Count of Samples to be taken per scan |
||
465 | |||
466 | |||
467 | Output : RawData :Averaged ADC Value |
||
468 | |||
469 | Side Effects : None |
||
470 | |||
471 | Overview : This API is used for scanning the channels, one at a time. This should be called in the |
||
472 | Timer tick function, preferably in an interrupt. This will return the Averaged ADC value |
||
473 | based on the SampleCount passed. |
||
474 | |||
475 | *******************************************************************/ |
||
476 | |||
477 | WORD mTouchCapAPI_ScanChannelIterative (WORD ChannelNum, BYTE SampleCount) |
||
478 | { |
||
479 | WORD RawData; |
||
480 | WORD RawIterativeData = 0; |
||
481 | |||
482 | DWORD total = 0; |
||
483 | BYTE sample; |
||
484 | |||
485 | /* Check for valid channel number being passed */ |
||
486 | if (! ( (ChannelNum >= CHANNEL_AN0) && (ChannelNum < MAX_ADC_CHANNELS)) ) |
||
487 | { |
||
488 | /* return the error value if not a valid channel number */ |
||
489 | RawData = ADC_UNTOUCHED_VALUE_10_BIT; |
||
490 | } |
||
491 | else //Handle the scan for a valid channel |
||
492 | { |
||
493 | |||
494 | // Get the raw sensor reading. |
||
495 | for(sample=0; sample< SampleCount; sample++) |
||
496 | { |
||
497 | RawIterativeData = mTouchCapAPI_CTMU_GetChannelReading(ChannelNum); |
||
498 | |||
499 | total = total + RawIterativeData; |
||
500 | } |
||
501 | #if defined PROXIMITY |
||
502 | curBigData[ChannelNum] = total; |
||
503 | #endif |
||
504 | |||
505 | /* Error Check */ |
||
506 | if (total != 0) |
||
507 | { |
||
508 | RawData = total/ SampleCount; |
||
509 | } |
||
510 | else |
||
511 | { |
||
512 | RawData = 0; |
||
513 | } |
||
514 | } |
||
515 | |||
516 | |||
517 | return RawData; |
||
518 | } |
||
519 | |||
520 | |||
521 | |||
522 | /********* End of Function *********************/ |
||
523 | |||
524 | |||
525 | |||
526 | /******************************************************************** |
||
527 | * Function : BYTE mTouchCapAPI_getChannelTouchStatus(WORD ChIndex, BYTE Decode_Method) |
||
528 | * |
||
529 | * PreCondition : None |
||
530 | * |
||
531 | * Input : ChIndex -The Channel number. |
||
532 | Decode_Method-The type of Decode Method associated with that channel |
||
533 | DECODE_METHOD_MOST_PRESSED, |
||
534 | DECODE_METHOD_MULTIPLE_PRESS, |
||
535 | DECODE_METHOD_PRESS_AND_RELEASE, |
||
536 | DECODE_METHOD_PRESS_ASSERT |
||
537 | * |
||
538 | * Output : TouchStatus-Whether the key associated with the Channel is pressed or not |
||
539 | KEY_NOT_PRESSED, |
||
540 | KEY_PRESSED |
||
541 | * |
||
542 | * Side Effects : None |
||
543 | * |
||
544 | * Overview : This API will determine if the channel which is associated with a particular |
||
545 | * key is touched or not. It will output the pressed or unpressed status of the channel based on the |
||
546 | * Decode method which is associated with the channel. |
||
547 | * |
||
548 | * |
||
549 | * Note : |
||
550 | *******************************************************************/ |
||
551 | |||
552 | BYTE mTouchCapAPI_getChannelTouchStatus(WORD ChIndex, BYTE Decode_Method) |
||
553 | { |
||
554 | BYTE temp; |
||
555 | BYTE TouchStatus = KEY_NOT_PRESSED; |
||
556 | |||
557 | /* Check for valid channel number being passed */ |
||
558 | if (! ( (ChIndex >= CHANNEL_AN0) && (ChIndex < MAX_ADC_CHANNELS)) ) |
||
559 | { |
||
560 | /* return the error value if not a valid channel number */ |
||
561 | TouchStatus = KEY_NOT_PRESSED; |
||
562 | } |
||
563 | else //Handle the touch status for a valid channel |
||
564 | { |
||
565 | |||
566 | |||
567 | switch (Decode_Method) |
||
568 | { |
||
569 | |||
570 | case DECODE_METHOD_MOST_PRESSED: |
||
571 | |||
572 | |||
573 | if (curRawData[ChIndex] < (averageData[ChIndex] - tripValue[ChIndex])) |
||
574 | { |
||
575 | unpressedCount[ChIndex] = 0; |
||
576 | pressedCount[ChIndex] = pressedCount[ChIndex] + 1; |
||
577 | // Single-Button Only (Lockout other keys option) |
||
578 | if(pressedCount[ChIndex] > DEBOUNCECOUNT) |
||
579 | { |
||
580 | Decode_Method_Used=DECODE_METHOD_MOST_PRESSED; |
||
581 | TouchStatus = KEY_PRESSED; |
||
582 | for(temp = 0; temp<ScanChannelIndex; temp++) |
||
583 | { |
||
584 | if(ScanChannels[temp]!=ChIndex) |
||
585 | { |
||
586 | if (curRawData[ScanChannels[temp]] < (averageData[ScanChannels[temp]] - tripValue[ScanChannels[temp]])) |
||
587 | { |
||
588 | if ( curRawData[ChIndex] > curRawData[ScanChannels[temp]]) |
||
589 | TouchStatus = KEY_NOT_PRESSED; |
||
590 | |||
591 | } |
||
592 | } |
||
593 | } |
||
594 | |||
595 | } |
||
596 | }else |
||
597 | { |
||
598 | pressedCount[ChIndex] = 0; |
||
599 | TouchStatus = KEY_NOT_PRESSED; |
||
600 | } |
||
601 | if (curRawData[ChIndex] > (averageData[ChIndex] - tripValue[ChIndex] + hystValue[ChIndex])) |
||
602 | { // Is scaledBigValue above { average - (trip + hysteresis) } ? .. Yes |
||
603 | // Button is up. |
||
604 | unpressedCount[ChIndex] = unpressedCount[ChIndex] + 1; |
||
605 | if (unpressedCount[ChIndex] > DEBOUNCECOUNT) |
||
606 | { |
||
607 | TouchStatus = KEY_NOT_PRESSED; |
||
608 | } |
||
609 | |||
610 | } |
||
611 | else |
||
612 | { |
||
613 | unpressedCount[ChIndex] = 0; |
||
614 | } |
||
615 | |||
616 | |||
617 | break; |
||
618 | |||
619 | // This decode method will give the press status when the corresponding key is released after it is pressed |
||
620 | //The status TouchStatus is updated based on status of the key |
||
621 | //As long as the key is pressed, the status will remain as KEY_NOT_PRESSED. |
||
622 | //The status will change to KEY_PRESSED as long as the key is released after it has been pressed |
||
623 | case DECODE_METHOD_PRESS_AND_RELEASE: |
||
624 | |||
625 | if (curRawData[ChIndex] < (averageData[ChIndex] - tripValue[ChIndex])) |
||
626 | { |
||
627 | unpressedCount[ChIndex] = 0; |
||
628 | pressedCount[ChIndex] = pressedCount[ChIndex] + 1; |
||
629 | // Single-Button Only (Lockout other keys option) |
||
630 | if(pressedCount[ChIndex] > DEBOUNCECOUNT) |
||
631 | { |
||
632 | TouchStatus = KEY_NOT_PRESSED; |
||
633 | // This flag will indicate the channel that has been pressed so that the information about |
||
634 | // the previous pressed key is stored. |
||
635 | Press_State[ChIndex] = PRESS; |
||
636 | // the status of the previous pressed key should be reset when the new key is pressed |
||
637 | Channel_Pressed_Status[Previous_Pressed_Channel_Num] =0; |
||
638 | } |
||
639 | }else |
||
640 | { |
||
641 | //Check if the current channel has been pressed |
||
642 | if (Press_State[ChIndex]) |
||
643 | { |
||
644 | if (curRawData[ChIndex] > (averageData[ChIndex] - tripValue[ChIndex] + hystValue[ChIndex])) |
||
645 | { // Is scaledBigValue above { average - (trip + hysteresis) } ? .. Yes |
||
646 | // Button is up. |
||
647 | pressedCount[ChIndex] = 0; |
||
648 | unpressedCount[ChIndex] = unpressedCount[ChIndex] + 1; |
||
649 | if (unpressedCount[ChIndex] > DEBOUNCECOUNT) |
||
650 | { |
||
651 | |||
652 | pressedCount[ChIndex] = 0; |
||
653 | //store the pressed status of the key so that the pressed status till |
||
654 | //another key is pressed |
||
655 | |||
656 | Channel_Pressed_Status[ChIndex] = KEY_PRESSED; |
||
657 | |||
658 | TouchStatus = KEY_PRESSED ; |
||
659 | //store the pressed key channel number so that it can be used in the application |
||
660 | // to store the status of the channel of the pressed key |
||
661 | Previous_Pressed_Channel_Num = ChIndex; |
||
662 | |||
663 | Decode_Method_Used=DECODE_METHOD_PRESS_AND_RELEASE; |
||
664 | } |
||
665 | } |
||
666 | }//end of if (Press_State[ChIndex]) |
||
667 | else |
||
668 | { |
||
669 | TouchStatus = KEY_NOT_PRESSED; |
||
670 | unpressedCount[ChIndex] = 0; |
||
671 | pressedCount[ChIndex] = 0; |
||
672 | Press_State[ChIndex] = RELEASE; |
||
673 | } |
||
674 | } |
||
675 | |||
676 | |||
677 | break; |
||
678 | |||
679 | |||
680 | case DECODE_METHOD_MULTIPLE_PRESS: |
||
681 | case DECODE_METHOD_PRESS_ASSERT: |
||
682 | if (curRawData[ChIndex] < (averageData[ChIndex] - tripValue[ChIndex])) |
||
683 | { |
||
684 | unpressedCount[ChIndex] = 0; |
||
685 | pressedCount[ChIndex] = pressedCount[ChIndex] + 1; |
||
686 | // Single-Button Only (Lockout other keys option) |
||
687 | if(pressedCount[ChIndex] > DEBOUNCECOUNT) |
||
688 | { |
||
689 | TouchStatus = KEY_PRESSED; |
||
690 | Decode_Method_Used=DECODE_METHOD_PRESS_ASSERT; |
||
691 | |||
692 | } |
||
693 | }else |
||
694 | { |
||
695 | pressedCount[ChIndex] = 0; |
||
696 | TouchStatus = KEY_NOT_PRESSED; |
||
697 | } |
||
698 | if (curRawData[ChIndex] > (averageData[ChIndex] - tripValue[ChIndex] + hystValue[ChIndex])) |
||
699 | { // Is scaledBigValue above { average - (trip + hysteresis) } ? .. Yes |
||
700 | // Button is up. |
||
701 | unpressedCount[ChIndex] = unpressedCount[ChIndex] + 1; |
||
702 | if (unpressedCount[ChIndex] > DEBOUNCECOUNT) |
||
703 | { |
||
704 | TouchStatus = KEY_NOT_PRESSED; |
||
705 | } |
||
706 | |||
707 | } |
||
708 | else |
||
709 | { |
||
710 | unpressedCount[ChIndex] = 0; |
||
711 | } |
||
712 | |||
713 | break; |
||
714 | |||
715 | default: |
||
716 | TouchStatus = KEY_NOT_PRESSED; |
||
717 | break; |
||
718 | |||
719 | } |
||
720 | } |
||
721 | // 6. Implement quick-release for a released button |
||
722 | /* Untouched value - used as a average data */ |
||
723 | if (curRawData[ChIndex] > averageData[ChIndex]) |
||
724 | { |
||
725 | averageData[ChIndex] = curRawData[ChIndex]; // If curRawData is above Average, reset to high average. |
||
726 | } |
||
727 | |||
728 | return TouchStatus; |
||
729 | } |
||
730 | |||
731 | /******************************************************************** |
||
732 | * Function : CHAR mTouchCapAPI_SetUpChannelDirectKey(DirectKey *Button,CHAR Channel_number, WORD Trip_Value, WORD Decode_Method, WORD Filter_Method) |
||
733 | * |
||
734 | * PreCondition : None |
||
735 | * |
||
736 | * Input : Button : Object of the Direct key structure |
||
737 | Channel number : channel number of the object Button associated with corresponding direct key. |
||
738 | Trip Value: Default Trip value for the channel specified by the channel number. |
||
739 | Filter_Method: The filter method associated with the Direct Key. |
||
740 | FILTER_METHOD_SLOWAVERAGE=0, |
||
741 | FILTER_METHOD_GATEDAVERAGE, |
||
742 | FILTER_METHOD_FASTAVERAGE |
||
743 | |||
744 | Decode_Method : The Decode method associated with the Direct Key. |
||
745 | DECODE_METHOD_MOST_PRESSED, |
||
746 | DECODE_METHOD_MULTIPLE_PRESS, |
||
747 | DECODE_METHOD_PRESS_AND_RELEASE, |
||
748 | DECODE_METHOD_PRESS_ASSERT |
||
749 | * |
||
750 | * Output : SetUpStatus - Status of the Direct key(TRUE or FALSE). |
||
751 | * |
||
752 | * Side Effects : None |
||
753 | |||
754 | * Overview : This API will setup the channel associated with the Direct key . |
||
755 | * The channel number, filter type and decode method are stored in the structure associated with |
||
756 | * the Direct Key. |
||
757 | * |
||
758 | * Note : |
||
759 | *******************************************************************/ |
||
760 | BYTE mTouchCapAPI_SetUpChannelDirectKey(DirectKey *Button,BYTE Channel_number, WORD Trip_Value, WORD Decode_Method, WORD Filter_Method) |
||
761 | { |
||
762 | CHAR SetUpStatus = TRUE; |
||
763 | |||
764 | Button->Channel_Num = Channel_number; // Stores Channel Number |
||
765 | Button->FilterType = Filter_Method; |
||
766 | chFilterType [Channel_number] = Filter_Method; |
||
767 | Button->DecodeMethod = Decode_Method; |
||
768 | //NK_DIRKEY |
||
769 | |||
770 | LoadChannelNumber(Channel_number); |
||
771 | |||
772 | return SetUpStatus; |
||
773 | } |
||
774 | |||
775 | |||
776 | /******************************************************************** |
||
777 | * Function : BYTE mTouchCapAPI_GetStatusDirectButton(DirectKey *Button) |
||
778 | * |
||
779 | * PreCondition : The Channel associatd with the Direct key should have been set up. |
||
780 | * |
||
781 | * Input : Button - Object of the structure associated with the Direct Key |
||
782 | * |
||
783 | * Output : The Touch Status of the particular key. |
||
784 | * 0 = KEY_NOT_PRESSED |
||
785 | * 1 = KEY_PRESSED |
||
786 | * |
||
787 | * Side Effects : None |
||
788 | * |
||
789 | * Overview : This API will provide the status of the Direct key passed which will be used |
||
790 | by the application to perform the related task. |
||
791 | * |
||
792 | * Note : |
||
793 | *******************************************************************/ |
||
794 | |||
795 | BYTE mTouchCapAPI_GetStatusDirectButton (DirectKey *Button) |
||
796 | { |
||
797 | BYTE DirectKey_Status = KEY_NOT_PRESSED; |
||
798 | /* Check if the channel is used for Direct key */ |
||
799 | //Now check to see if the requested key is pressed |
||
800 | if( KEY_PRESSED == mTouchCapAPI_getChannelTouchStatus((Button->Channel_Num),(Button->DecodeMethod))) |
||
801 | { |
||
802 | Press_State[Button->Channel_Num]= RELEASE; //reset the flag |
||
803 | DirectKey_Status= KEY_PRESSED; |
||
804 | } |
||
805 | else |
||
806 | { |
||
807 | //Channel requested is not detected as pressed. |
||
808 | DirectKey_Status= KEY_NOT_PRESSED; |
||
809 | } |
||
810 | |||
811 | return DirectKey_Status; |
||
812 | |||
813 | |||
814 | |||
815 | } |
||
816 | /******************************************************************** |
||
817 | * Function : BYTE mTouchCapAPI_SetUpChannelMatrixKey(MatrixKey *Button,BYTE Row_Channel_number,BYTE Col_Channel_number, WORD Trip_Value, WORD Decode_Method, WORD Filter_Method) |
||
818 | * |
||
819 | * PreCondition : None |
||
820 | * |
||
821 | * Input : Button - Object of the Matrix key structure |
||
822 | Row_Channel_number - channel number of the Row associated with corresponding matrix key. |
||
823 | Col_Channel_number - channel number of the Column associated with corresponding matrix key. |
||
824 | Trip Value - Default trip value for the channel associated with corresponding matrix key |
||
825 | Filter_Method - The filter method associated with the corresponding Matrix key |
||
826 | Decode_Method - The Decode method associated with the corresponding Matrix key |
||
827 | * |
||
828 | * Output : SetUpStatus - Status of the Matrix key(TRUE or FALSE). |
||
829 | * |
||
830 | * Side Effects : None |
||
831 | * |
||
832 | * Overview : This API will setup the channels of the Row and Column associated with the Matrix key. |
||
833 | * The channel number of the Row and Column, filter type and decode method are stored in the structure associated with |
||
834 | * the corresponding channel. |
||
835 | * |
||
836 | * |
||
837 | * Note : |
||
838 | *******************************************************************/ |
||
839 | |||
840 | BYTE mTouchCapAPI_SetUpChannelMatrixKey(MatrixKey *Button,BYTE Row_Channel_Number,BYTE Col_Channel_Number, WORD Trip_Value, WORD Decode_Method, WORD Filter_Method) |
||
841 | { |
||
842 | BYTE SetUpStatus = TRUE; |
||
843 | |||
844 | Button->Channel_Num[0] = Row_Channel_Number; // Stores Channel Number of the Row asscoiated with the Matrix key |
||
845 | Button->Channel_Num[1] = Col_Channel_Number; // Stores Channel Number of the Column asscoiated with the Matrix key |
||
846 | |||
847 | Button->FilterType = Filter_Method; //Store the Filter type which will be common for both the multiplexed channel(Row and col) |
||
848 | chFilterType [Row_Channel_Number] = Filter_Method; |
||
849 | chFilterType [Col_Channel_Number] = Filter_Method; |
||
850 | Button->DecodeMethod = Decode_Method; //Store the Decode method which will be common for both the multiplexed channel(Row and col) |
||
851 | |||
852 | //store the channels numbers in the global array for all the Matrix Key channels |
||
853 | |||
854 | //Store the Row and column channel numbers in the global array which will be used by the ISR |
||
855 | // for reading the ADC value associated with the channels which are multiplxed to form a single key |
||
856 | LoadChannelNumber(Row_Channel_Number); |
||
857 | LoadChannelNumber(Col_Channel_Number); |
||
858 | |||
859 | return SetUpStatus; |
||
860 | } |
||
861 | |||
862 | |||
863 | |||
864 | /******************************************************************** |
||
865 | * Function : BYTE mTouchCapAPI_GetStatusMatrixButton (MatrixKey *Button) |
||
866 | * |
||
867 | * PreCondition : The Channels of the Row and Column associatd with the Matrix key should have been already set up |
||
868 | * |
||
869 | * Input : Button - Object of the Structure associated with the Matrix Key |
||
870 | * |
||
871 | * Output : The Touch Status of the particular key. |
||
872 | * 0 = KEY_NOT_PRESSED |
||
873 | * 1 = KEY_PRESSED |
||
874 | * |
||
875 | * Side Effects : None |
||
876 | * |
||
877 | * Overview : This API will provide the status of the Matrix key passed which will be used |
||
878 | by the application to perform the related task. |
||
879 | * |
||
880 | * Note : |
||
881 | *******************************************************************/ |
||
882 | |||
883 | #ifdef USE_MATRIX_KEYS |
||
884 | BYTE mTouchCapAPI_GetStatusMatrixButton (MatrixKey *Button) |
||
885 | { |
||
886 | BYTE MatrixKey_Status = KEY_NOT_PRESSED; |
||
887 | BYTE RowFlag = KEY_NOT_PRESSED; |
||
888 | BYTE ColFlag = KEY_NOT_PRESSED; |
||
889 | |||
890 | /* Check if the channel used as Row for corresponding Matrix key is pressed */ |
||
891 | //Now check to see if the requested row is pressed |
||
892 | |||
893 | if( KEY_PRESSED == mTouchCapAPI_getChannelTouchStatus((Button->Channel_Num[0]),(Button->DecodeMethod) )) |
||
894 | { |
||
895 | RowFlag=KEY_PRESSED; // Used for determining ROW match |
||
896 | } |
||
897 | else |
||
898 | { |
||
899 | //Channel requested is not detected as pressed. |
||
900 | RowFlag= KEY_NOT_PRESSED; |
||
901 | } |
||
902 | |||
903 | //Now check to see if the channel used as column for corresponding Matrix key is pressed |
||
904 | if( KEY_PRESSED == mTouchCapAPI_getChannelTouchStatus((Button->Channel_Num[1]),(Button->DecodeMethod) )) |
||
905 | { |
||
906 | ColFlag=KEY_PRESSED; // Used for determining COL match |
||
907 | } |
||
908 | else |
||
909 | { |
||
910 | //Channel requested is not detected as pressed. |
||
911 | ColFlag= KEY_NOT_PRESSED; |
||
912 | } |
||
913 | |||
914 | // check if both the row and column corresponding to the matrix key is pressed |
||
915 | |||
916 | |||
917 | if( (ColFlag == KEY_PRESSED) && (RowFlag == KEY_PRESSED) ) |
||
918 | { |
||
919 | MatrixKey_Status= KEY_PRESSED; //matrix key is pressed |
||
920 | Press_State[Button->Channel_Num[0]]= RELEASE; //reset the flag |
||
921 | Press_State[Button->Channel_Num[1]]= RELEASE; //reset the flag |
||
922 | } |
||
923 | else |
||
924 | { |
||
925 | //If both channels are not pressed, the key is not pressed |
||
926 | MatrixKey_Status= KEY_NOT_PRESSED; //key is not pressed |
||
927 | } |
||
928 | |||
929 | return MatrixKey_Status; |
||
930 | } |
||
931 | |||
932 | #endif |
||
933 | /******************************************************************** |
||
934 | * Function : BYTE mTouchCapAPI_SetUpChannelSlider2Ch(Slider2Ch *Slider, BYTE Slider_Channel1_number,BYTE Slider_Channel2_number, WORD Trip_Value, BYTE Decode_Method, BYTE Filter_Method) |
||
935 | * |
||
936 | * |
||
937 | * Input : Slider - Object of the Matrix key structure |
||
938 | Channel number - channel number of the object Slider associated with corresponding 2-channel slider. |
||
939 | Trip Value - Trip value for the channels associated with the 2-channel slider |
||
940 | Filter_Method - One of the filter method for the 2-channel slider |
||
941 | Decode_Method -The Decode method for the 2-channel slider |
||
942 | * |
||
943 | * Output : SetUpStatus - Status of the 2-channel slider(TRUE or FALSE). |
||
944 | * |
||
945 | * Side Effects : None |
||
946 | * |
||
947 | * Overview : This API will setup the 2 channels associated with the 2-channel Slider. |
||
948 | * The 2 channel numbers, filter type and decode method are stored in the structure associated with |
||
949 | * the corresponding 2-Channel Slider |
||
950 | * |
||
951 | * |
||
952 | * Note : |
||
953 | *******************************************************************/ |
||
954 | |||
955 | BYTE mTouchCapAPI_SetUpChannelSlider2Ch(Slider2Ch *Slider, BYTE Slider_Channel1_Number,BYTE Slider_Channel2_Number, WORD Trip_Value, BYTE Decode_Method, BYTE Filter_Method) |
||
956 | |||
957 | |||
958 | { |
||
959 | BYTE SetUpStatus = TRUE; |
||
960 | |||
961 | Slider->Channel_Num[0] = Slider_Channel1_Number; // Stores first Channel Number of the 2-channel slider |
||
962 | Slider->Channel_Num[1] = Slider_Channel2_Number; // Stores Second Channel Number of the 2-channel slider |
||
963 | |||
964 | Slider->FilterType = Filter_Method; //Store the Filter type which will be common for both the channels in the 2-channel slider |
||
965 | |||
966 | chFilterType [Slider_Channel1_Number] = Filter_Method; |
||
967 | chFilterType [Slider_Channel2_Number] = Filter_Method; |
||
968 | |||
969 | Slider->DecodeMethod = Decode_Method; //Store the Decode method which will be common for both the channels in the 2-channel slider |
||
970 | |||
971 | //store the channels numbers in the global array which are associated with the 2-channel slider |
||
972 | |||
973 | //Store the Channel 1 and Channel 2 numbers of the 2-channel slider in the global array which will be used by the ISR |
||
974 | // for reading the ADC value associated |
||
975 | |||
976 | LoadChannelNumber(Slider_Channel1_Number); |
||
977 | LoadChannelNumber(Slider_Channel2_Number); |
||
978 | |||
979 | return SetUpStatus; |
||
980 | } |
||
981 | |||
982 | /********************************************************************************** |
||
983 | Function : SHORT mTouchCapAPI_GetStatusSlider2Ch (Slider2Ch *Slider) |
||
984 | |||
985 | PreCondition : 2-channel Slider setup is complete. |
||
986 | |||
987 | Input : Slider - Object of the 2-channel slider |
||
988 | |||
989 | Output : sliderLevel gives the Slider percent level of the touch. |
||
990 | |||
991 | Side Effects : None |
||
992 | |||
993 | Overview : This API gets the percentage level of a particular 2-channel slider passed. |
||
994 | The output is ratio-metrically calculated from 0% to 100% proportional to the finger on the slider. |
||
995 | |||
996 | |||
997 | **********************************************************************************/ |
||
998 | #if defined(USE_SLIDER_2CHNL) |
||
999 | |||
1000 | SHORT mTouchCapAPI_GetStatusSlider2Ch (Slider2Ch *Slider) |
||
1001 | { |
||
1002 | |||
1003 | SHORT SliderState; |
||
1004 | WORD Percent_Level = 0; |
||
1005 | |||
1006 | |||
1007 | #ifdef USE_SLIDER_2CHNL |
||
1008 | |||
1009 | if( (KEY_PRESSED == mTouchCapAPI_getChannelTouchStatus((Slider->Channel_Num[0]),(Slider->DecodeMethod) )) || |
||
1010 | (KEY_PRESSED == mTouchCapAPI_getChannelTouchStatus((Slider->Channel_Num[1]),(Slider->DecodeMethod) )) ) |
||
1011 | { |
||
1012 | |||
1013 | //#ifdef USE_SLIDER_2CHNL |
||
1014 | /* Use the 2ch slider algorithm to get the Slider Level */ |
||
1015 | Percent_Level = mTouchCapApp_TwoChannelSliderLogic(Slider); |
||
1016 | SliderState = (SHORT)Percent_Level; |
||
1017 | //#endif |
||
1018 | } |
||
1019 | else |
||
1020 | { |
||
1021 | SliderState = -1; |
||
1022 | |||
1023 | } |
||
1024 | |||
1025 | |||
1026 | #endif // USE_SLIDER_2CHNL |
||
1027 | |||
1028 | /* Get the Level */ |
||
1029 | |||
1030 | |||
1031 | return SliderState; |
||
1032 | } |
||
1033 | #endif // end of #if defined(USE_SLIDER_2CHNL) |
||
1034 | |||
1035 | /******************************************************************** |
||
1036 | * Function : BYTE mTouchCapAPI_SetUpChannelSlider4Ch(Slider4Ch *Slider, BYTE Slider_Channel1_Number,BYTE Slider_Channel2_Number, BYTE Slider_Channel3_Number,BYTE Slider_Channel4_Number,WORD Trip_Value, BYTE Decode_Method, BYTE Filter_Method) |
||
1037 | * |
||
1038 | * PreCondition : None |
||
1039 | * |
||
1040 | * Input : Slider : object of the 4-channel Slider structure |
||
1041 | Channel number : channel number of the object Slider associated with 4-channel slider. |
||
1042 | Trip Value: Trip value for the channels associated with the 4-channel slider. |
||
1043 | Filter_Method: The filter method for the 4-channel slider. |
||
1044 | Decode_Method:The Decode method for the 4-channel slider. |
||
1045 | * |
||
1046 | * Output : SetUpStatus - Status of the 4-channel slider(TRUE or FALSE). |
||
1047 | * |
||
1048 | * Side Effects : None |
||
1049 | * |
||
1050 | * Overview : This API will setup the 4 channels associated with the 4-channel Slider. |
||
1051 | * The 4 channel numbers, filter type and decode method are stored in the structure associated with |
||
1052 | * the corresponding 4-Channel Slider |
||
1053 | |||
1054 | * |
||
1055 | * Note : |
||
1056 | *******************************************************************/ |
||
1057 | |||
1058 | BYTE mTouchCapAPI_SetUpChannelSlider4Ch(Slider4Ch *Slider, BYTE Slider_Channel1_Number,BYTE Slider_Channel2_Number, BYTE Slider_Channel3_Number,BYTE Slider_Channel4_Number,WORD Trip_Value, BYTE Decode_Method, BYTE Filter_Method) |
||
1059 | |||
1060 | { |
||
1061 | BYTE SetUpStatus = TRUE; |
||
1062 | |||
1063 | Slider->Channel_Num[0] = Slider_Channel1_Number; // Stores first Channel Number of the 4-channel slider |
||
1064 | Slider->Channel_Num[1] = Slider_Channel2_Number; // Stores Second Channel Number of the 4-channel slider |
||
1065 | Slider->Channel_Num[2] = Slider_Channel3_Number; // Stores third Channel Number of the 4-channel slider |
||
1066 | Slider->Channel_Num[3] = Slider_Channel4_Number; // Stores fourth Channel Number of the 4-channel slider |
||
1067 | |||
1068 | Slider->FilterType = Filter_Method; //Store the Filter type which will be common for all the channels in the 4 channel slider |
||
1069 | |||
1070 | chFilterType [Slider_Channel1_Number] = Filter_Method; |
||
1071 | chFilterType [Slider_Channel2_Number] = Filter_Method; |
||
1072 | chFilterType [Slider_Channel3_Number] = Filter_Method; |
||
1073 | chFilterType [Slider_Channel4_Number] = Filter_Method; |
||
1074 | |||
1075 | |||
1076 | Slider->DecodeMethod = Decode_Method; //Store the Decode method which will be common for all the channels in the 4 channel slider |
||
1077 | |||
1078 | //store the channels numbers in the global array which are associated with the 4-channel slider |
||
1079 | |||
1080 | //Store the Channel 1,Channel 2,Channel 3 and Channel4 numbers of the 4-channel slider in the global array which will be used by the ISR |
||
1081 | // for reading the ADC value associated |
||
1082 | |||
1083 | LoadChannelNumber(Slider_Channel1_Number); |
||
1084 | LoadChannelNumber(Slider_Channel2_Number); |
||
1085 | LoadChannelNumber(Slider_Channel3_Number); |
||
1086 | LoadChannelNumber(Slider_Channel4_Number); |
||
1087 | |||
1088 | return SetUpStatus; |
||
1089 | } |
||
1090 | |||
1091 | |||
1092 | |||
1093 | /********************************************************************************** |
||
1094 | Function : SHORT mTouchCapAPI_GetStatusSlider4Ch (Slider4Ch *Slider) |
||
1095 | |||
1096 | PreCondition : 4-channel Slider setup is complete |
||
1097 | |||
1098 | Input : Slider - Object of the 4-channel slider |
||
1099 | |||
1100 | Output : sliderLevel gives the Slider percent level of the touch. |
||
1101 | |||
1102 | Side Effects : None |
||
1103 | |||
1104 | Overview : This API gets the percentage level of a particular 4-channel slider passed. |
||
1105 | The output is ratio-metrically calculated from 0% to 100% proportional to the finger on the slider. |
||
1106 | |||
1107 | |||
1108 | **********************************************************************************/ |
||
1109 | #if defined(USE_SLIDER_4CHNL) |
||
1110 | |||
1111 | SHORT mTouchCapAPI_GetStatusSlider4Ch (Slider4Ch *Slider) |
||
1112 | { |
||
1113 | |||
1114 | SHORT SliderState; |
||
1115 | WORD Percent_Level = 0; |
||
1116 | |||
1117 | |||
1118 | #ifdef USE_SLIDER_4CHNL |
||
1119 | |||
1120 | if( (KEY_PRESSED == mTouchCapAPI_getChannelTouchStatus((Slider->Channel_Num[0]),(Slider->DecodeMethod) )) || |
||
1121 | (KEY_PRESSED == mTouchCapAPI_getChannelTouchStatus((Slider->Channel_Num[1]),(Slider->DecodeMethod) )) || |
||
1122 | (KEY_PRESSED == mTouchCapAPI_getChannelTouchStatus((Slider->Channel_Num[2]),(Slider->DecodeMethod) )) || |
||
1123 | (KEY_PRESSED == mTouchCapAPI_getChannelTouchStatus((Slider->Channel_Num[3]),(Slider->DecodeMethod) )) |
||
1124 | ) |
||
1125 | { |
||
1126 | /* Use the 4ch slider algorithm to get the Slider Level */ |
||
1127 | Percent_Level = mTouchCapApp_FourChannelSliderLogic(Slider); |
||
1128 | SliderState = (SHORT)Percent_Level; |
||
1129 | } |
||
1130 | else |
||
1131 | { |
||
1132 | SliderState = -1; // For KEY_NOT_PRESSED |
||
1133 | } |
||
1134 | |||
1135 | #endif |
||
1136 | |||
1137 | return SliderState; |
||
1138 | } |
||
1139 | #endif // end of #if defined(USE_SLIDER_4CHNL) |
||
1140 | |||
1141 | |||
1142 | /******************************************************************** |
||
1143 | * Function : void LoadChannelNumber (BYTE Channel_Number_Passed) |
||
1144 | * |
||
1145 | * PreCondition : None |
||
1146 | * |
||
1147 | * Input : Channel Number |
||
1148 | * |
||
1149 | * Output : None |
||
1150 | * |
||
1151 | * Side Effects : None |
||
1152 | * |
||
1153 | * Overview : This function will load the active Touchkey Channel number in the |
||
1154 | * global array ScanChannels[ScanChannelIndex++] and will also |
||
1155 | * store the total channels used in the application |
||
1156 | * |
||
1157 | * Note : |
||
1158 | *******************************************************************/ |
||
1159 | void LoadChannelNumber (BYTE Channel_Number_Passed) |
||
1160 | { |
||
1161 | BYTE index; |
||
1162 | BYTE result = FALSE; |
||
1163 | |||
1164 | for(index = 0; index<ScanChannelIndex; index++) |
||
1165 | { |
||
1166 | if(ScanChannels[index] == Channel_Number_Passed) |
||
1167 | { |
||
1168 | result = TRUE; |
||
1169 | } |
||
1170 | } |
||
1171 | |||
1172 | if(!result) |
||
1173 | { |
||
1174 | ScanChannels[ScanChannelIndex++] = Channel_Number_Passed; |
||
1175 | if(ScanChannelIndex > MAX_ADC_CHANNELS)// the ScanChannelIndex should not be incremented if the index is greater than the no of ADC channels used |
||
1176 | // If the index is greater than the number of channels in the direct key board, then the index should |
||
1177 | // not be incremented. reset the index value |
||
1178 | ScanChannelIndex = 0; |
||
1179 | |||
1180 | } |
||
1181 | |||
1182 | } |
||
1183 | |||
1184 | |||
1185 | /******************************************************************** |
||
1186 | * Function : void mTouchCap_UpdateStaticTripValue(void) |
||
1187 | * |
||
1188 | * PreCondition : None |
||
1189 | * |
||
1190 | * Input : None |
||
1191 | * |
||
1192 | * Output : None |
||
1193 | * |
||
1194 | * Side Effects : None |
||
1195 | * |
||
1196 | * Overview : It will load the static trip values for all the channels which |
||
1197 | * cannot be changed in runtime. |
||
1198 | * |
||
1199 | * |
||
1200 | * Note : |
||
1201 | *******************************************************************/ |
||
1202 | void mTouchCap_UpdateStaticTripValue(void) |
||
1203 | { |
||
1204 | #ifdef USE_STATIC_TRIP_VALUE |
||
1205 | tripValue[CHANNEL_AN0] = STATIC_TRIP_VALUE_CHANNEL0; |
||
1206 | tripValue[CHANNEL_AN1] = STATIC_TRIP_VALUE_CHANNEL1; |
||
1207 | tripValue[CHANNEL_AN2] = STATIC_TRIP_VALUE_CHANNEL2; |
||
1208 | tripValue[CHANNEL_AN3] = STATIC_TRIP_VALUE_CHANNEL3; |
||
1209 | tripValue[CHANNEL_AN4] = STATIC_TRIP_VALUE_CHANNEL4; |
||
1210 | tripValue[CHANNEL_AN5] = STATIC_TRIP_VALUE_CHANNEL5; |
||
1211 | tripValue[CHANNEL_AN6] = STATIC_TRIP_VALUE_CHANNEL6; |
||
1212 | tripValue[CHANNEL_AN7] = STATIC_TRIP_VALUE_CHANNEL7; |
||
1213 | tripValue[CHANNEL_AN8] = STATIC_TRIP_VALUE_CHANNEL8; |
||
1214 | tripValue[CHANNEL_AN9] = STATIC_TRIP_VALUE_CHANNEL9; |
||
1215 | tripValue[CHANNEL_AN10] = STATIC_TRIP_VALUE_CHANNEL10; |
||
1216 | tripValue[CHANNEL_AN11] = STATIC_TRIP_VALUE_CHANNEL11; |
||
1217 | tripValue[CHANNEL_AN12] = STATIC_TRIP_VALUE_CHANNEL12; |
||
1218 | #ifdef __PIC24F__ |
||
1219 | tripValue[CHANNEL_AN13] = STATIC_TRIP_VALUE_CHANNEL13; |
||
1220 | tripValue[CHANNEL_AN14] = STATIC_TRIP_VALUE_CHANNEL14; |
||
1221 | tripValue[CHANNEL_AN15] = STATIC_TRIP_VALUE_CHANNEL15; |
||
1222 | #if defined(__PIC24FJ_DAXXX__) |
||
1223 | tripValue[CHANNEL_AN16] = STATIC_TRIP_VALUE_CHANNEL16; |
||
1224 | tripValue[CHANNEL_AN17] = STATIC_TRIP_VALUE_CHANNEL17; |
||
1225 | tripValue[CHANNEL_AN18] = STATIC_TRIP_VALUE_CHANNEL18; |
||
1226 | tripValue[CHANNEL_AN19] = STATIC_TRIP_VALUE_CHANNEL19; |
||
1227 | tripValue[CHANNEL_AN20] = STATIC_TRIP_VALUE_CHANNEL20; |
||
1228 | tripValue[CHANNEL_AN21] = STATIC_TRIP_VALUE_CHANNEL21; |
||
1229 | tripValue[CHANNEL_AN22] = STATIC_TRIP_VALUE_CHANNEL22; |
||
1230 | tripValue[CHANNEL_AN23] = STATIC_TRIP_VALUE_CHANNEL23; |
||
1231 | #endif |
||
1232 | #endif |
||
1233 | #endif |
||
1234 | } |
||
1235 | |||
1236 | /******************************************************************** |
||
1237 | * Function : void InitAvgDelay(void) |
||
1238 | * |
||
1239 | * PreCondition : None |
||
1240 | * |
||
1241 | * Input : None |
||
1242 | * |
||
1243 | * Output : None |
||
1244 | * |
||
1245 | * Side Effects : None |
||
1246 | * |
||
1247 | * Overview : Initialize delay count to 0 for all assigned channels |
||
1248 | * |
||
1249 | * |
||
1250 | * Note : |
||
1251 | *******************************************************************/ |
||
1252 | |||
1253 | void InitAvgDelay(void) |
||
1254 | { |
||
1255 | WORD Index; |
||
1256 | for(Index=0; Index<ScanChannelIndex; Index++) //Initialize delay count to 0 for all channels |
||
1257 | { |
||
1258 | avg_delay[ScanChannels[Index]] = 0; |
||
1259 | } |
||
1260 | } |
||
1261 | |||
1262 | |||
1263 | |||
1264 | #undef _MTOUCHCAP_CTMU_API_C |
||
1265 | #endif |
||
1266 | |||
1267 |
Powered by WebSVN v2.8.3