|
-
-
- #include "core_pins.h"
-
-
- #if defined(HAS_KINETIS_TSI) || defined(HAS_KINETIS_TSI_LITE)
-
- #if defined(__MK20DX128__) || defined(__MK20DX256__)
-
-
-
-
- #define CURRENT 2
- #define NSCAN 9
- #define PRESCALE 2
- static const uint8_t pin2tsi[] = {
-
- 9, 10, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, 255, 255, 255, 255, 13, 0, 6, 8, 7,
- 255, 255, 14, 15, 255, 12, 255, 255, 255, 255,
- 255, 255, 11, 5
- };
-
- #elif defined(__MK66FX1M0__)
- #define NSCAN 9
- #define PRESCALE 2
- static const uint8_t pin2tsi[] = {
-
- 9, 10, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, 255, 255, 255, 255, 13, 0, 6, 8, 7,
- 255, 255, 14, 15, 255, 255, 255, 255, 255, 11,
- 12, 255, 255, 255, 255, 255, 255, 255, 255, 255
- };
-
- #elif defined(__MKL26Z64__)
- #define NSCAN 9
- #define PRESCALE 2
- static const uint8_t pin2tsi[] = {
-
- 9, 10, 255, 2, 3, 255, 255, 255, 255, 255,
- 255, 255, 255, 255, 255, 13, 0, 6, 8, 7,
- 255, 255, 14, 15, 255, 255, 255
- };
-
- #endif
-
-
-
-
-
-
- int touchRead(uint8_t pin)
- {
- uint32_t ch;
-
- if (pin >= NUM_DIGITAL_PINS) return 0;
- ch = pin2tsi[pin];
- if (ch == 255) return 0;
-
- *portConfigRegister(pin) = PORT_PCR_MUX(0);
- SIM_SCGC5 |= SIM_SCGC5_TSI;
- #if defined(HAS_KINETIS_TSI)
- TSI0_GENCS = 0;
- TSI0_PEN = (1 << ch);
- TSI0_SCANC = TSI_SCANC_REFCHRG(3) | TSI_SCANC_EXTCHRG(CURRENT);
- TSI0_GENCS = TSI_GENCS_NSCN(NSCAN) | TSI_GENCS_PS(PRESCALE) | TSI_GENCS_TSIEN | TSI_GENCS_SWTS;
- delayMicroseconds(10);
- while (TSI0_GENCS & TSI_GENCS_SCNIP) ;
- delayMicroseconds(1);
- return *((volatile uint16_t *)(&TSI0_CNTR1) + ch);
- #elif defined(HAS_KINETIS_TSI_LITE)
- TSI0_GENCS = TSI_GENCS_REFCHRG(4) | TSI_GENCS_EXTCHRG(3) | TSI_GENCS_PS(PRESCALE)
- | TSI_GENCS_NSCN(NSCAN) | TSI_GENCS_TSIEN | TSI_GENCS_EOSF;
- TSI0_DATA = TSI_DATA_TSICH(ch) | TSI_DATA_SWTS;
- delayMicroseconds(10);
- while (TSI0_GENCS & TSI_GENCS_SCNIP) ;
- delayMicroseconds(1);
- return TSI0_DATA & 0xFFFF;
- #endif
- }
-
- #else
-
- int touchRead(uint8_t pin)
- {
- return 0;
- }
-
- #endif
-
|