Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00084 #ifndef __MTOUCH_H
00085 #define __MTOUCH_H
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 #if defined(HI_TECH_C)
00098 #include <htc.h>
00099 #include <stdint.h>
00100 #else
00101 #include <p18cxxx.h>
00102 #endif
00103
00104 #include "mTouch_config.h"
00105 #include "mTouch_processConfiguration.h"
00106 #include "mTouch_modes.h"
00107
00108 #if defined(MTOUCH_PROXIMITY_ENABLED)
00109 #include "mTouch_proximity.h"
00110 #endif
00111
00112
00113 #include "mComm.h"
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00130 typedef struct
00131 {
00132 unsigned state :2;
00133 unsigned baselineCorrection :1;
00134
00135 #if (MTOUCH_BUTTON_TIMEOUT > 0)
00136 unsigned timeout :1;
00137 #endif
00138
00139 MTOUCH_STATE_BASELINE_COUNT ();
00140 MTOUCH_STATE_TIMER ();
00141 #if defined(MTOUCH_STATE_DEBOUNCE)
00142 MTOUCH_STATE_DEBOUNCE ();
00143 #endif
00144 } mTouch_SensorVariables;
00145
00146
00147
00148
00155 typedef struct
00156 {
00157 #if (CVD_STATE_SPS_BITS > 8)
00158 uint16_t sampleCounter;
00159 #else
00160 uint8_t sampleCounter;
00161 #endif
00162
00163 #if (MTOUCH_NUM_MODES > 1)
00164 #if MTOUCH_SLEEP_INACTIVE_RESET > 255
00165 uint16_t inactivity;
00166 #else
00167 uint8_t inactivity;
00168 #endif
00169 #endif
00170
00171 mTouch_SensorVariables sensor[MTOUCH_NUMBER_SENSORS];
00172
00173 } mTouch_StateVariables;
00174
00210 typedef union
00211 {
00212 uint32_t all;
00213
00214 struct
00215 {
00216 uint16_t invalid;
00217 uint16_t v;
00218 } result;
00219
00220 struct
00221 {
00222 uint24_t v;
00223 uint8_t invalid;
00224 } accumulator;
00225
00226 } mTouch_AcquisitionData;
00227
00228
00232 typedef struct
00233 {
00234 unsigned dataReady :1;
00235 unsigned areInitialized :1;
00236 unsigned buttonStateChange :1;
00237
00238 #if (MTOUCH_INTEGRATION_TYPE == MTOUCH_CALLED_FROM_MAINLOOP)
00239 unsigned isrServiced :1;
00240 unsigned isRepeatScan :1;
00241 #endif
00242
00243 #if (MTOUCH_NUM_MODES > 1)
00244 unsigned allReleased :1;
00245 unsigned skippedDecode :1;
00246 unsigned change :1;
00247 unsigned justChanged :1;
00248 #endif
00249
00250 #if (MTOUCH_INTEGRATION_TYPE == MTOUCH_CALLED_FROM_MAINLOOP)
00251 unsigned scanningEnabled :1;
00252 #endif
00253
00254 #if defined(MTOUCH_ERROR_DETECTION_ENABLED)
00255 unsigned error :1;
00256 #endif
00257
00258 } mTouch_State;
00259
00260 #if defined(MTOUCH_MOST_PRESSED_ONLY) || defined(MTOUCH_MATRIX_ENABLED)
00261 typedef struct
00262 {
00263 uint16_t maxValue;
00264 uint8_t maxIndex;
00265 } mTouch_MostPressedData;
00266
00267 typedef struct
00268 {
00269 uint8_t start;
00270 uint8_t end;
00271 } mTouch_MostPressedIndex;
00272 #endif
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 extern mTouch_State mTouch_state;
00284 extern mTouch_StateVariables mTouch_stateVars;
00285 extern uint16_t mTouch_sensorData [MTOUCH_NUMBER_SENSORS];
00286 extern mTouch_AcquisitionData mTouch_acqData [MTOUCH_NUMBER_SENSORS];
00287 extern uint16_t mTouch_average [MTOUCH_NUMBER_SENSORS];
00288
00289 #if defined(MCOMM_ENABLED)
00290 #if (MTOUCH_NUMBER_SENSORS <= 8)
00291 extern uint8_t mTouch_stateMask;
00292 #elif (MTOUCH_NUMBER_SENSORS <= 16)
00293 extern uint16_t mTouch_stateMask;
00294 #elif (MTOUCH_NUMBER_SENSORS <= 24)
00295 extern uint24_t mTouch_stateMask;
00296 #elif (MTOUCH_NUMBER_SENSORS <= 32)
00297 extern uint32_t mTouch_stateMask;
00298 #endif
00299 #endif
00300
00301 #if defined(MTOUCH_SLIDERS_ENABLED)
00302 #if defined(MTOUCH_SLIDER_SCALING_ENABLED)
00303 extern uint8_t mTouch_slider [MTOUCH_NUMBER_OF_SLIDERS];
00304 #else
00305 extern uint16_t mTouch_slider [MTOUCH_NUMBER_OF_SLIDERS];
00306 #endif
00307 #endif
00308
00309 #if defined(MTOUCH_TOGGLE_ENABLED)
00310 #if (MTOUCH_NUMBER_SENSORS <= 8)
00311 extern uint8_t mTouch_toggle;
00312 #elif (MTOUCH_NUMBER_SENSORS <= 16)
00313 extern uint16_t mTouch_toggle;
00314 #elif (MTOUCH_NUMBER_SENSORS <= 24)
00315 extern uint24_t mTouch_toggle;
00316 #elif (MTOUCH_NUMBER_SENSORS <= 32)
00317 extern uint32_t mTouch_toggle;
00318 #endif
00319 #endif
00320
00321 #if defined(MTOUCH_SLIDERS_ENABLED) || defined(MTOUCH_MOST_PRESSED_ONLY) || defined(MTOUCH_MATRIX_ENABLED)
00322 extern uint16_t mTouch_deltas [MTOUCH_NUMBER_SENSORS];
00323 #endif
00324
00325 #if defined(MTOUCH_MATRIX_ENABLED)
00326 extern uint8_t mTouch_matrix;
00327 extern uint8_t mTouch_matrix_latch;
00328 #endif
00329
00330
00331 #if (MTOUCH_INTEGRATION_TYPE != MTOUCH_CONTROLS_ISR) & defined(_PIC14)
00332 extern near uint8_t int_w;
00333 extern near uint8_t int_status;
00334 extern near uint8_t int_fsr;
00335 extern near uint8_t int_pclath;
00336 #elif defined(_PIC18) || defined(__18CXX)
00337 extern uint8_t int_w;
00338 extern uint8_t int_status;
00339 extern uint8_t int_bsr;
00340 #endif
00341
00342
00343 #if !defined(MTOUCH_EEPROM_ENABLED)
00344 extern const uint16_t mTouch_pressThreshold [MTOUCH_NUMBER_SENSORS];
00345 extern const uint16_t mTouch_releaseThreshold [MTOUCH_NUMBER_SENSORS];
00346 #endif
00347
00348 #if defined(MTOUCH_EEPROM_ENABLED) && defined(MTOUCH_EEPROM_STORED_IN_RAM)
00349 extern uint8_t mTouch_configOptions [MTOUCH_EEPROM_START_ADR + MTOUCH_EEPROM_SIZE];
00350 #endif
00351
00352 #if (MTOUCH_NUMBER_SENSORS > 1)
00353 #if (MTOUCH_NUM_MODES > 1)
00354 extern uint8_t mTouch_modeIndex;
00355 extern const uint8_t* mTouch_currentScan;
00356 #define MTOUCH_CURRENTSCAN_VALUE (*mTouch_currentScan)
00357 #else
00358 extern uint8_t mTouch_currentScan;
00359 #define MTOUCH_CURRENTSCAN_VALUE mTouch_currentScan
00360 #endif
00361 #else
00362 #define MTOUCH_CURRENTSCAN_VALUE 0
00363 #endif
00364
00365 #if MTOUCH_NUM_MODES > 1
00366 extern const uint8_t* const mTouch_mode [MTOUCH_NUM_MODES];
00367 #endif
00368
00369
00370
00371
00372
00373
00374
00375
00376
00378 enum mTouch_enum_ButtonState
00379 {
00380 MTOUCH_INITIALIZING,
00381 MTOUCH_RELEASED,
00382 MTOUCH_PRESSED
00383 };
00384
00385 #if defined(MTOUCH_TOGGLE_ENABLED)
00386
00387 enum mTouch_enum_ToggleState
00388 {
00389 MTOUCH_TOGGLE_OFF,
00390 MTOUCH_TOGGLE_ON
00391 };
00392 #endif
00393
00394 #if defined(MTOUCH_PROXIMITY_ENABLED)
00395
00396 enum mTouch_Prox_enum_SensorState
00397 {
00398 MTOUCH_PROX_INITIALIZING,
00399 MTOUCH_PROX_NOT_ACTIVATED,
00400 MTOUCH_PROX_ACTIVATED
00401 };
00402 #endif
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413 void mTouch_Init (void);
00414 void mTouch_Decode (void);
00415
00416 #if MTOUCH_NUM_MODES > 1
00417 void mTouch_ChangeMode (uint8_t);
00418 #else
00419 void mTouch_ChangeMode (void);
00420 #endif
00421
00422 #if (MTOUCH_INTEGRATION_TYPE == MTOUCH_CALLED_FROM_ISR)
00423 void mTouch_Scan (void);
00424 #elif (MTOUCH_INTEGRATION_TYPE == MTOUCH_CALLED_FROM_MAINLOOP)
00425 uint8_t mTouch_Scan (void);
00426 #endif
00427
00428 #if defined(MTOUCH_SLIDERS_ENABLED)
00429 void mTouch_SliderDecode (void);
00430 #endif
00431
00432 #if defined(MTOUCH_ERROR_DETECTION_ENABLED)
00433 void mTouch_ErrorDetect (void);
00434 #endif
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00462 #define mTouch_GetButtonState(i) mTouch_stateVars.sensor[i].state
00463
00471 #define mTouch_GetAverage(i) mTouch_average[i]
00472
00480 #define mTouch_GetSensor(i) mTouch_sensorData[i]
00481
00482
00483
00484 #if defined(MTOUCH_SLIDERS_ENABLED)
00485
00492 #define mTouch_GetSlider(i) mTouch_slider[i]
00493 #endif
00494
00495
00496 #if defined(MTOUCH_TOGGLE_ENABLED)
00497
00504 #define mTouch_GetToggleState(i) ((uint8_t)(mTouch_toggle >> i) & 0x01)
00505
00524 #if (MTOUCH_NUMBER_SENSORS <= 8)
00525 #define mTouch_ToggleToggle(i) mTouch_toggle ^= (uint8_t) (0x01 << i)
00526 #define mTouch_SetToggle(i) mTouch_toggle |= (uint8_t) (0x01 << i)
00527 #define mTouch_ClearToggle(i) mTouch_toggle &= ~(uint8_t) (0x01 << i)
00528 #elif (MTOUCH_NUMBER_SENSORS <= 16)
00529 #define mTouch_ToggleToggle(i) mTouch_toggle ^= (uint16_t)(0x01 << i)
00530 #define mTouch_SetToggle(i) mTouch_toggle |= (uint16_t)(0x01 << i)
00531 #define mTouch_ClearToggle(i) mTouch_toggle &= ~(uint16_t)(0x01 << i)
00532 #elif (MTOUCH_NUMBER_SENSORS <= 24)
00533 #define mTouch_ToggleToggle(i) mTouch_toggle ^= (uint24_t)(0x01 << i)
00534 #define mTouch_SetToggle(i) mTouch_toggle |= (uint24_t)(0x01 << i)
00535 #define mTouch_ClearToggle(i) mTouch_toggle &= ~(uint24_t)(0x01 << i)
00536 #elif (MTOUCH_NUMBER_SENSORS <= 32)
00537 #define mTouch_ToggleToggle(i) mTouch_toggle ^= (uint32_t)(0x01 << i)
00538 #define mTouch_SetToggle(i) mTouch_toggle |= (uint32_t)(0x01 << i)
00539 #define mTouch_ClearToggle(i) mTouch_toggle &= ~(uint32_t)(0x01 << i)
00540 #endif
00541
00542 #endif
00543
00544
00557 #if (MTOUCH_INTEGRATION_TYPE == MTOUCH_CALLED_FROM_MAINLOOP)
00558 #define mTouch_EnableScanning() mTouch_state.scanningEnabled = 1;
00559 #define mTouch_DisableScanning() mTouch_state.scanningEnabled = 0;
00560 #else
00561 #define mTouch_EnableScanning() MTOUCH_ISR_TMRxIF = 0; MTOUCH_ISR_TMRxIE = 1;
00562 #define mTouch_DisableScanning() MTOUCH_ISR_TMRxIE = 0;
00563 #endif
00564
00565
00566
00576 #define mTouch_Service() mTouch_state.dataReady = 0; mTouch_Decode()
00577
00578
00595 #if (MTOUCH_INTEGRATION_TYPE == MTOUCH_CALLED_FROM_MAINLOOP)
00596 #define mTouch_isDataReady() mTouch_Scan()
00597 #else
00598 #define mTouch_isDataReady() (mTouch_state.dataReady)
00599 #endif
00600
00608 #define mTouch_checkInterrupt() (MTOUCH_ISR_TMRxIF && MTOUCH_ISR_TMRxIE)
00609
00610 #if defined(MTOUCH_MATRIX_ENABLED)
00611 #define mTouch_Matrix_hasChanged() (mTouch_matrix != mTouch_matrix_latch)
00612 #define mTouch_Matrix_latchNewValue() mTouch_matrix_latch = mTouch_matrix
00613 #define mTouch_Matrix_isPressed() (mTouch_matrix != 0xFF)
00614 #define mTouch_Matrix_getColumn() mTouch_matrix >> MTOUCH_MATRIX_ROW_OFFSET
00615 #define mTouch_Matrix_getRow() mTouch_matrix & MTOUCH_MATRIX_ROW_MASK
00616 #endif
00617
00618 #endif // end: ifndef __MTOUCH_H
00619
00620