00001 /************************************************************************* 00002 * © 2012 Microchip Technology Inc. 00003 * 00004 * Project Name: mTouch Framework v2.1 00005 * FileName: mTouch_acquisition.c 00006 * Dependencies: mTouch.h 00007 * Processor: See documentation for supported PIC® microcontrollers 00008 * Compiler: HI-TECH Ver. 9.81 or later 00009 * IDE: MPLAB® IDE v8.50 (or later) or MPLAB® X 00010 * Hardware: 00011 * Company: 00012 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00013 * Description: mTouch Framework Acquisition Module 00014 * - Implements the mTouch acquisition process. 00015 * Additional ISR functions should be carefully 00016 * designed to not interfere with the mTouch interrupt 00017 * service. 00018 * - See the documentation for more information about 00019 * implementing the framework with your application. 00020 *************************************************************************/ 00021 /************************************************************************** 00022 * MICROCHIP SOFTWARE NOTICE AND DISCLAIMER: You may use this software, and 00023 * any derivatives created by any person or entity by or on your behalf, 00024 * exclusively with Microchip's products in accordance with applicable 00025 * software license terms and conditions, a copy of which is provided for 00026 * your referencein accompanying documentation. Microchip and its licensors 00027 * retain all ownership and intellectual property rights in the 00028 * accompanying software and in all derivatives hereto. 00029 * 00030 * This software and any accompanying information is for suggestion only. 00031 * It does not modify Microchip's standard warranty for its products. You 00032 * agree that you are solely responsible for testing the software and 00033 * determining its suitability. Microchip has no obligation to modify, 00034 * test, certify, or support the software. 00035 * 00036 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 00037 * EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED 00038 * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A 00039 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE, ITS INTERACTION WITH 00040 * MICROCHIP'S PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY 00041 * APPLICATION. 00042 * 00043 * IN NO EVENT, WILL MICROCHIP BE LIABLE, WHETHER IN CONTRACT, WARRANTY, 00044 * TORT (INCLUDING NEGLIGENCE OR BREACH OF STATUTORY DUTY), STRICT 00045 * LIABILITY, INDEMNITY, CONTRIBUTION, OR OTHERWISE, FOR ANY INDIRECT, 00046 * SPECIAL, PUNITIVE, EXEMPLARY, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, 00047 * FOR COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, 00048 * HOWSOEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY 00049 * OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT ALLOWABLE BY LAW, 00050 * MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS 00051 * SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID 00052 * DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. 00053 * 00054 * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF 00055 * THESE TERMS. 00056 *************************************************************************/ 00057 00064 #include "mTouch.h" 00065 00066 00072 mTouch_AcquisitionData mTouch_acqData [MTOUCH_NUMBER_SENSORS]; 00073 mTouch_AcquisitionData* mTouch_previousSensor; 00074 uint16_t mTouch_sensorData [MTOUCH_NUMBER_SENSORS]; 00075 uint16_t mTouch_lastResult; 00076 uint8_t mTouch_delayCount; 00077 00078 #if (MTOUCH_NUMBER_SENSORS > 1) 00079 #if (MTOUCH_NUM_MODES > 1) 00080 uint8_t mTouch_modeIndex; 00081 const uint8_t* mTouch_currentScan; 00082 #else 00083 uint8_t mTouch_currentScan; 00084 #endif 00085 #endif 00086 00087 #if defined(MTOUCH_UNIQUE_OVERSAMPLE_ENABLE) && (MTOUCH_NUMBER_SENSORS > 1) 00088 uint8_t mTouch_oversample [MTOUCH_NUMBER_SENSORS]; 00089 #endif 00090 00091 #if defined(MTOUCH_JITTER_ENABLE) 00092 uint8_t mTouch_jitter = 0x55; 00093 #endif 00094 00095 #if defined(_PIC14) 00096 // These state-saving variables are only required in non-enhanced core PIC microcontrollers. 00097 // They are automatically omitted if not needed. 00098 near uint8_t int_w; 00099 near uint8_t int_status; 00100 near uint8_t int_fsr; 00101 near uint8_t int_pclath; 00102 // TIP: The 'near' qualifier tells the compiler to place these variables in 'common' memory so 00103 // they may be accessed from any bank. On the enhanced core products, this typically 00104 // refers to the registers: 0x70 to 0x7F. 00105 #elif defined(_PIC18) 00106 uint8_t int_w; 00107 uint8_t int_status; 00108 uint8_t int_bsr; 00109 // TIP: The 'near' qualifier is not needed in this case due to the PIC18's bank access features. 00110 #endif 00111 00112 00113 00114 // 00115 // TODO: 00116 // 00117 // 1. Rework storage macros to not be offset 00118 // 2. Rewrite mTouch scan loop - allow for independant oversampling values 00119 // 3. Adjust for a variable number of modes 00120 // - If only one mode, simplify code 00121 // 4. If only one sensor, simplify code further 00122 00123 // Local Function Prototypes 00124 void mTouch_DecimationFilter (void); 00125 void mTouch_WaitForGoDone (void); 00126 void mTouch_StoreScanA (void); 00127 void mTouch_StoreScanB (void); 00128 #if MTOUCH_NUM_MODES > 1 00129 void mTouch_ChangeMode (uint8_t); 00130 #else 00131 void mTouch_ChangeMode (void); 00132 #endif 00133 void mTouch_UpdateAccumulator2 (void); 00134 MTOUCH_SCAN_PROTOTYPES(); 00135 00136 00137 // Constant Memory 00138 #if (MTOUCH_NUMBER_SENSORS > 1) 00139 #if MTOUCH_NUM_MODES > 1 00140 const uint8_t mTouch_mode0[MTOUCH_MODE0_NUM_SENSORS + 1] = MTOUCH_MODE0_VAR_INIT; 00141 const uint8_t mTouch_mode1[MTOUCH_MODE1_NUM_SENSORS + 1] = MTOUCH_MODE1_VAR_INIT; 00142 #endif 00143 #if MTOUCH_NUM_MODES > 2 00144 const uint8_t mTouch_mode2[MTOUCH_MODE2_NUM_SENSORS + 1] = MTOUCH_MODE2_VAR_INIT; 00145 #endif 00146 #if MTOUCH_NUM_MODES > 3 00147 const uint8_t mTouch_mode3[MTOUCH_MODE3_NUM_SENSORS + 1] = MTOUCH_MODE3_VAR_INIT; 00148 #endif 00149 #if MTOUCH_NUM_MODES > 4 00150 const uint8_t mTouch_mode4[MTOUCH_MODE4_NUM_SENSORS + 1] = MTOUCH_MODE4_VAR_INIT; 00151 #endif 00152 #if MTOUCH_NUM_MODES > 5 00153 const uint8_t mTouch_mode5[MTOUCH_MODE5_NUM_SENSORS + 1] = MTOUCH_MODE5_VAR_INIT; 00154 #endif 00155 #if MTOUCH_NUM_MODES > 6 00156 const uint8_t mTouch_mode6[MTOUCH_MODE6_NUM_SENSORS + 1] = MTOUCH_MODE6_VAR_INIT; 00157 #endif 00158 #if MTOUCH_NUM_MODES > 7 00159 const uint8_t mTouch_mode7[MTOUCH_MODE7_NUM_SENSORS + 1] = MTOUCH_MODE7_VAR_INIT; 00160 #endif 00161 #if MTOUCH_NUM_MODES > 1 00162 const uint8_t* const mTouch_mode [MTOUCH_NUM_MODES] = MTOUCH_MODE_VAR_INIT; 00163 #endif 00164 00165 #if defined(MTOUCH_UNIQUE_OVERSAMPLE_ENABLE) && (MTOUCH_NUMBER_SENSORS > 1) 00166 const uint8_t mTouch_Oversample_Default[MTOUCH_NUMBER_SENSORS] = MTOUCH_UNIQUE_OVERSAMPLE_INIT; 00167 #endif 00168 00169 void (*const mTouch_ScanA[MTOUCH_NUMBER_SENSORS])(void) = MTOUCH_SCANA_VAR_INIT; // Constant array of function pointers 00170 void (*const mTouch_ScanB[MTOUCH_NUMBER_SENSORS])(void) = MTOUCH_SCANB_VAR_INIT; // Constant array of function pointers 00171 #endif 00172 00173 00183 #if (MTOUCH_INTEGRATION_TYPE == MTOUCH_CONTROLS_ISR) 00184 void interrupt mTouch_Scan(void) 00185 #elif (MTOUCH_INTEGRATION_TYPE == MTOUCH_CALLED_FROM_ISR) 00186 void mTouch_Scan(void) 00187 #elif (MTOUCH_INTEGRATION_TYPE == MTOUCH_CALLED_FROM_MAINLOOP) 00188 uint8_t mTouch_Scan(void) 00189 #endif 00190 { 00191 #asm 00192 #ifndef MTOUCH_ACQ_CAS_INCLUDE 00193 #define MTOUCH_ACQ_CAS_INCLUDE 00194 #if defined(_12F617) && (_HTC_VER_MAJOR_ == 9 && _HTC_VER_MINOR_ == 80) 00195 #include <cas12F617.h> // HiTech's 9.80 compiler's caspic.h includes the 617 header file twice, causing compiling 00196 // errors. This will by-pass the mistake by directly including the correct file only once. 00197 // This issue has been fixed as of the 9.81 release. 00198 #else 00199 #if defined(_PIC14) || defined(_PIC14E) 00200 #include <caspic.h> 00201 #endif 00202 #endif 00203 #endif 00204 mTouch_Scan: 00205 #endasm 00206 00207 NOP(); 00208 NOP(); 00209 NOP(); 00210 00211 // 00212 // Intro Logic :: Check to see if we should scan. 00213 // 00214 #if (MTOUCH_INTEGRATION_TYPE == MTOUCH_CONTROLS_ISR) 00215 SAVE_STATE(); 00216 if (MTOUCH_ISR_TMRxIF == 0) 00217 { 00218 return; 00219 } else { 00220 MTOUCH_ISR_TMRxIF = 0; 00221 } 00222 #elif (MTOUCH_INTEGRATION_TYPE == MTOUCH_CALLED_FROM_MAINLOOP) 00223 if (mTouch_state.scanningEnabled == 0) 00224 { 00225 return 0; 00226 } 00227 #endif 00228 00229 #if (MTOUCH_SCAN_FUNCTIONALITY == MTOUCH_SCANS_ALL_SENSORS) 00230 do 00231 { 00232 #endif 00233 00234 #if defined(MTOUCH_UNIQUE_OVERSAMPLE_ENABLE) 00235 if (mTouch_oversample[MTOUCH_CURRENTSCAN_VALUE] != 0) 00236 { 00237 #endif 00238 00239 #if (MTOUCH_INTEGRATION_TYPE == MTOUCH_CALLED_FROM_MAINLOOP) 00240 do 00241 { 00242 mTouch_state.isrServiced = 0; 00243 #endif 00244 00245 // 00246 // Scan A 00247 // 00248 #if MTOUCH_NUMBER_SENSORS > 1 00249 mTouch_ScanA[MTOUCH_CURRENTSCAN_VALUE](); 00250 #else 00251 mTouch_ScanA_0(); 00252 #endif 00253 00254 // 00255 // Math on Previous Sensor 00256 // 00257 #if (MTOUCH_INTEGRATION_TYPE == MTOUCH_CALLED_FROM_MAINLOOP) 00258 if (!mTouch_state.isRepeatScan) 00259 { 00260 #endif 00261 if (mTouch_previousSensor != 0) 00262 { 00263 mTouch_DecimationFilter(); 00264 } 00265 #if (MTOUCH_INTEGRATION_TYPE == MTOUCH_CALLED_FROM_MAINLOOP) 00266 } 00267 #endif 00268 00269 mTouch_WaitForGoDone(); 00270 mTouch_StoreScanA(); 00271 00272 // 00273 // Scan B 00274 // 00275 #if MTOUCH_NUMBER_SENSORS > 1 00276 mTouch_ScanB[MTOUCH_CURRENTSCAN_VALUE](); 00277 #else 00278 mTouch_ScanB_0(); 00279 #endif 00280 00281 // 00282 // Update accumulator 00283 // 00284 #if (MTOUCH_INTEGRATION_TYPE == MTOUCH_CALLED_FROM_MAINLOOP) 00285 if (!mTouch_state.isRepeatScan) 00286 { 00287 #endif 00288 if (mTouch_previousSensor != 0) 00289 { 00290 mTouch_UpdateAccumulator2(); // Take the result from the decimation filter and update the 00291 // accumulator value for the previous sensor. 00292 } 00293 #if (MTOUCH_INTEGRATION_TYPE == MTOUCH_CALLED_FROM_MAINLOOP) 00294 } 00295 #endif 00296 00297 mTouch_WaitForGoDone(); 00298 mTouch_StoreScanB(); 00299 00300 #if (MTOUCH_INTEGRATION_TYPE == MTOUCH_CALLED_FROM_MAINLOOP) 00301 mTouch_state.isRepeatScan = mTouch_state.isrServiced; 00302 } while (mTouch_state.isRepeatScan); 00303 #endif 00304 00305 #if defined(MTOUCH_UNIQUE_OVERSAMPLE_ENABLE) 00306 mTouch_oversample[MTOUCH_CURRENTSCAN_VALUE]--; 00307 } 00308 #endif 00309 00310 // 00311 // Increment sensor index and sample counter 00312 // 00313 mTouch_previousSensor = &mTouch_acqData[MTOUCH_CURRENTSCAN_VALUE]; 00314 00315 #if MTOUCH_NUMBER_SENSORS > 1 00316 mTouch_currentScan++; 00317 #if (MTOUCH_SCAN_FUNCTIONALITY == MTOUCH_SCANS_ALL_SENSORS) 00318 } while (MTOUCH_CURRENTSCAN_VALUE != MTOUCH_NUMBER_SENSORS); 00319 #else 00320 if (MTOUCH_CURRENTSCAN_VALUE == MTOUCH_NUMBER_SENSORS) 00321 { 00322 #endif 00323 00324 #if MTOUCH_NUM_MODES > 1 00325 mTouch_currentScan = mTouch_mode[mTouch_modeIndex]; 00326 #else 00327 mTouch_currentScan = 0; 00328 #endif 00329 #endif // end: if MTOUCH_NUMBER_SENSORS > 1 00330 00331 #if defined(MTOUCH_UNIQUE_OVERSAMPLE_ENABLE) && (MTOUCH_NUMBER_SENSORS > 1) 00332 mTouch_delayCount = 0; // Used as a temporary flag variable 00333 do 00334 { 00335 if (mTouch_oversample[MTOUCH_CURRENTSCAN_VALUE]) // Are there any sensors left to be scanned? 00336 mTouch_delayCount++; 00337 mTouch_currentScan++; 00338 } while (MTOUCH_CURRENTSCAN_VALUE != MTOUCH_NUMBER_SENSORS); 00339 00340 #if MTOUCH_NUM_MODES > 1 00341 mTouch_currentScan = mTouch_mode[mTouch_modeIndex]; 00342 #else 00343 mTouch_currentScan = 0; 00344 #endif 00345 00346 if (mTouch_delayCount == 0) 00347 { 00348 #else 00349 if (--mTouch_stateVars.sampleCounter == 0) 00350 { 00351 mTouch_stateVars.sampleCounter = MTOUCH_SpS_VALUE; 00352 #endif 00353 00354 mTouch_DecimationFilter(); // Store the final ADC result from the last sensor before 00355 mTouch_UpdateAccumulator2(); // continuing with the output dump. 00356 00357 #if (MTOUCH_NUMBER_SENSORS > 1) 00358 do 00359 { 00360 mTouch_previousSensor = &mTouch_acqData[MTOUCH_CURRENTSCAN_VALUE]; 00361 mTouch_sensorData[MTOUCH_CURRENTSCAN_VALUE] = (uint16_t)(((uint24_t)((*mTouch_previousSensor).accumulator.v) & 0xFFFFF) >> MTOUCH_SCALING_VALUE); 00362 (*mTouch_previousSensor).accumulator.v &= 0xF00000; 00363 00364 mTouch_currentScan++; 00365 } while (MTOUCH_CURRENTSCAN_VALUE != MTOUCH_NUMBER_SENSORS); 00366 #else 00367 mTouch_sensorData[MTOUCH_CURRENTSCAN_VALUE] = (uint16_t)(((uint24_t)(mTouch_acqData[0].accumulator.v) & 0xFFFFF) >> MTOUCH_SCALING_VALUE); 00368 mTouch_acqData[0].accumulator.v &= 0xF00000; 00369 #endif 00370 00371 #if MTOUCH_NUM_MODES > 1 00372 mTouch_ChangeMode(mTouch_modeIndex); 00373 #else 00374 mTouch_ChangeMode(); 00375 #endif 00376 mTouch_state.dataReady = 1; 00377 } 00378 00379 #if MTOUCH_NUMBER_SENSORS > 1 00380 #if (MTOUCH_SCAN_FUNCTIONALITY != MTOUCH_SCANS_ALL_SENSORS) 00381 } 00382 #endif 00383 #endif 00384 00385 #if defined(MTOUCH_EEPROM_ENABLE) 00386 if (MTOUCH_JITTER_VALUE != 0) 00387 { 00388 #endif 00389 00390 #if defined(MTOUCH_EEPROM_ENABLE) || defined(MTOUCH_JITTER_ENABLE) 00391 #if (MTOUCH_INTEGRATION_TYPE == MTOUCH_CALLED_FROM_MAINLOOP) 00392 JITTER_MAIN_LOOP(); 00393 #else 00394 JITTER_START_TIME(); 00395 #endif 00396 #endif 00397 00398 #if defined(MTOUCH_EEPROM_ENABLE) 00399 } 00400 #endif 00401 00402 #if (MTOUCH_INTEGRATION_TYPE == MTOUCH_CONTROLS_ISR) || (MTOUCH_INTEGRATION_TYPE == MTOUCH_CALLED_FROM_ISR) 00403 MTOUCH_ISR_TMRxIF = 0; // Clear TMRxIF to avoid immediate ISR re-entry upon leaving. 00404 #endif 00405 00406 #if (MTOUCH_INTEGRATION_TYPE == MTOUCH_CONTROLS_ISR) 00407 RESTORE_STATE(); 00408 asm("retfie"); 00409 #elif (MTOUCH_INTEGRATION_TYPE == MTOUCH_CALLED_FROM_ISR) 00410 asm("return"); 00411 #elif (MTOUCH_INTEGRATION_TYPE == MTOUCH_CALLED_FROM_MAINLOOP) 00412 return mTouch_state.dataReady; 00413 #endif 00414 00415 } 00416 00417 void mTouch_DecimationFilter(void) 00418 { 00419 // Get the current decimated filter value for the sensor. 00420 #if MTOUCH_NUMBER_SENSORS > 1 00421 uint16_t result = (uint16_t)((*mTouch_previousSensor).result.v >> 4); 00422 #else 00423 uint16_t result = (uint16_t)(mTouch_acqData[0].result.v >> 4); 00424 #endif 00425 00426 #if defined(MTOUCH_EEPROM_ENABLED) 00427 #if MTOUCH_DECIMATION_MAX_STEP > 255 00428 uint16_t decMaxStep = MTOUCH_DECIMATION_MAX_VALUE; 00429 #else 00430 uint8_t decMaxStep = MTOUCH_DECIMATION_MAX_VALUE; 00431 #endif 00432 00433 #undef MTOUCH_DECIMATION_MAX_VALUE 00434 #define MTOUCH_DECIMATION_MAX_VALUE decMaxStep // Replace the EEPROM access code with our temporary variable 00435 #endif 00436 00437 #if defined(MTOUCH_DECIMATION_MAX_STEP) || defined(MTOUCH_EEPROM_ENABLED) 00438 #if (MTOUCH_DECIMATION_MAX_STEP != 0) || defined(MTOUCH_EEPROM_ENABLED) 00439 if ((uint16_t)(mTouch_lastResult) > (uint16_t)(result + MTOUCH_DECIMATION_MAX_VALUE)) 00440 { 00441 result += MTOUCH_DECIMATION_MAX_VALUE; // Latest conversion is very large. Increment by max step size only. 00442 } 00443 else if (result > MTOUCH_DECIMATION_MAX_VALUE) 00444 { 00445 if ((uint16_t)(mTouch_lastResult) < result - MTOUCH_DECIMATION_MAX_VALUE) 00446 { 00447 result -= MTOUCH_DECIMATION_MAX_VALUE; // Latest conversion is very small. Decrement by max step size only. 00448 } else { 00449 result = mTouch_lastResult; // Latest conversion is similar in value to decimated value. 00450 } 00451 } 00452 else // Latest conversion is less than (decimated value + STEP_SIZE) 00453 { // AND the decimated value is in danger of underflowing. 00454 result = mTouch_lastResult; 00455 } 00456 #else 00457 result = mTouch_lastResult; // Decimation disabled. 00458 #endif 00459 #else 00460 result = mTouch_lastResult; // Decimation disabled. 00461 #endif 00462 00463 #if MTOUCH_NUMBER_SENSORS > 1 00464 (*mTouch_previousSensor).result.v &= 0x000F; // Store the new decimated value into memory for later use. 00465 (*mTouch_previousSensor).result.v |= (uint16_t)(result << 4); 00466 #else 00467 mTouch_acqData[0].result.v &= 0x000F; // Store the new decimated value into memory for later use. 00468 mTouch_acqData[0].result.v |= (uint16_t)(result << 4); 00469 #endif 00470 } 00471 00472 void mTouch_WaitForGoDone(void) 00473 { 00474 mTouch_delayCount = 0xFF; 00475 while (GO_nDONE && --mTouch_delayCount); 00476 } 00477 00478 void mTouch_StoreScanA(void) 00479 { 00480 #if (PIC_ADC_BITS == 8) 00481 mTouch_lastResult = ADRES; 00482 #elif (PIC_ADC_BITS == 10) 00483 mTouch_lastResult = (uint16_t) (ADRESH << 8) + ADRESL; 00484 #elif (PIC_ADC_BITS == 12) 00485 mTouch_lastResult = (uint16_t) (ADRESH << 8) + ADRESL; 00486 #else 00487 #error The PIC_ADC_BITS value in your device's hardware profile is invalid. It must be 8, 10, or 12. 00488 #endif 00489 } 00490 00491 void mTouch_StoreScanB(void) 00492 { 00493 #if (PIC_ADC_BITS == 8) 00494 mTouch_lastResult = (uint16_t) (ADRES | 0x0100) - mTouch_lastResult; 00495 #elif (PIC_ADC_BITS == 10) 00496 mTouch_lastResult = (uint16_t)((ADRESH | 0x04) << 8) + ADRESL - mTouch_lastResult; 00497 #elif (PIC_ADC_BITS == 12) 00498 mTouch_lastResult = (uint16_t)((ADRESH | 0x10) << 8) + ADRESL - mTouch_lastResult; 00499 #else 00500 #error The PIC_ADC_BITS value in your device's hardware profile is invalid. It must be 8, 10, or 12. 00501 #endif 00502 } 00503 00504 #if MTOUCH_NUM_MODES > 1 00505 void mTouch_ChangeMode(uint8_t newModeIndex) 00506 { 00507 #else 00508 void mTouch_ChangeMode(void) 00509 { 00510 #endif 00511 mTouch_previousSensor = 0; 00512 00513 #if MTOUCH_NUMBER_SENSORS > 1 00514 #if MTOUCH_NUM_MODES > 1 00515 mTouch_currentScan = mTouch_mode[mTouch_modeIndex]; 00516 00517 if (mTouch_modeIndex != newModeIndex) 00518 { 00519 mTouch_modeIndex = newModeIndex; 00520 mTouch_state.justChanged = 1; 00521 } 00522 #else 00523 mTouch_currentScan = 0; 00524 #endif 00525 #endif 00526 00527 #if defined(MTOUCH_UNIQUE_OVERSAMPLE_ENABLE) && MTOUCH_NUMBER_SENSORS > 1 00528 do 00529 { 00530 mTouch_oversample[MTOUCH_CURRENTSCAN_VALUE] = mTouch_Oversample_Default[MTOUCH_CURRENTSCAN_VALUE]; 00531 mTouch_currentScan++; 00532 } while (MTOUCH_CURRENTSCAN_VALUE != MTOUCH_NUMBER_SENSORS); 00533 00534 #if MTOUCH_NUM_MODES > 1 00535 mTouch_currentScan = mTouch_mode[mTouch_modeIndex]; 00536 #else 00537 mTouch_currentScan = 0; 00538 #endif 00539 00540 #else 00541 mTouch_stateVars.sampleCounter = MTOUCH_SpS_VALUE; 00542 #endif 00543 } 00544 00545 void mTouch_UpdateAccumulator2(void) 00546 { 00547 #if MTOUCH_NUMBER_SENSORS > 1 00548 (*mTouch_previousSensor).accumulator.v += (uint16_t)((*mTouch_previousSensor).result.v >> 4); 00549 #else 00550 mTouch_acqData[0].accumulator.v += (uint16_t)(mTouch_acqData[0].result.v >> 4); 00551 #endif 00552 } 00553 00554 #if MTOUCH_NUMBER_SENSORS > 0 00555 MTOUCH_SCAN_FUNCTION(0); 00556 #endif 00557 #if MTOUCH_NUMBER_SENSORS > 1 00558 MTOUCH_SCAN_FUNCTION(1); 00559 #endif 00560 #if MTOUCH_NUMBER_SENSORS > 2 00561 MTOUCH_SCAN_FUNCTION(2); 00562 #endif 00563 #if MTOUCH_NUMBER_SENSORS > 3 00564 MTOUCH_SCAN_FUNCTION(3); 00565 #endif 00566 #if MTOUCH_NUMBER_SENSORS > 4 00567 MTOUCH_SCAN_FUNCTION(4); 00568 #endif 00569 #if MTOUCH_NUMBER_SENSORS > 5 00570 MTOUCH_SCAN_FUNCTION(5); 00571 #endif 00572 #if MTOUCH_NUMBER_SENSORS > 6 00573 MTOUCH_SCAN_FUNCTION(6); 00574 #endif 00575 #if MTOUCH_NUMBER_SENSORS > 7 00576 MTOUCH_SCAN_FUNCTION(7); 00577 #endif 00578 #if MTOUCH_NUMBER_SENSORS > 8 00579 MTOUCH_SCAN_FUNCTION(8); 00580 #endif 00581 #if MTOUCH_NUMBER_SENSORS > 9 00582 MTOUCH_SCAN_FUNCTION(9); 00583 #endif 00584 #if MTOUCH_NUMBER_SENSORS > 10 00585 MTOUCH_SCAN_FUNCTION(10); 00586 #endif 00587 #if MTOUCH_NUMBER_SENSORS > 11 00588 MTOUCH_SCAN_FUNCTION(11); 00589 #endif 00590 #if MTOUCH_NUMBER_SENSORS > 12 00591 MTOUCH_SCAN_FUNCTION(12); 00592 #endif 00593 #if MTOUCH_NUMBER_SENSORS > 13 00594 MTOUCH_SCAN_FUNCTION(13); 00595 #endif 00596 #if MTOUCH_NUMBER_SENSORS > 14 00597 MTOUCH_SCAN_FUNCTION(14); 00598 #endif 00599 #if MTOUCH_NUMBER_SENSORS > 15 00600 MTOUCH_SCAN_FUNCTION(15); 00601 #endif 00602 #if MTOUCH_NUMBER_SENSORS > 16 00603 MTOUCH_SCAN_FUNCTION(16); 00604 #endif 00605 #if MTOUCH_NUMBER_SENSORS > 17 00606 MTOUCH_SCAN_FUNCTION(17); 00607 #endif 00608 #if MTOUCH_NUMBER_SENSORS > 18 00609 MTOUCH_SCAN_FUNCTION(18); 00610 #endif 00611 #if MTOUCH_NUMBER_SENSORS > 19 00612 MTOUCH_SCAN_FUNCTION(19); 00613 #endif 00614 #if MTOUCH_NUMBER_SENSORS > 20 00615 MTOUCH_SCAN_FUNCTION(20); 00616 #endif 00617 #if MTOUCH_NUMBER_SENSORS > 21 00618 MTOUCH_SCAN_FUNCTION(21); 00619 #endif 00620 #if MTOUCH_NUMBER_SENSORS > 22 00621 MTOUCH_SCAN_FUNCTION(22); 00622 #endif 00623 #if MTOUCH_NUMBER_SENSORS > 23 00624 MTOUCH_SCAN_FUNCTION(23); 00625 #endif 00626 #if MTOUCH_NUMBER_SENSORS > 24 00627 MTOUCH_SCAN_FUNCTION(24); 00628 #endif 00629 #if MTOUCH_NUMBER_SENSORS > 25 00630 MTOUCH_SCAN_FUNCTION(25); 00631 #endif 00632 #if MTOUCH_NUMBER_SENSORS > 26 00633 MTOUCH_SCAN_FUNCTION(26); 00634 #endif 00635 #if MTOUCH_NUMBER_SENSORS > 27 00636 MTOUCH_SCAN_FUNCTION(27); 00637 #endif 00638 #if MTOUCH_NUMBER_SENSORS > 28 00639 MTOUCH_SCAN_FUNCTION(28); 00640 #endif 00641 #if MTOUCH_NUMBER_SENSORS > 29 00642 MTOUCH_SCAN_FUNCTION(29); 00643 #endif