|
-
-
- #include "core_pins.h"
-
-
- 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
- };
-
-
-
-
-
- #define CURRENT 2
- #define NSCAN 9
- #define PRESCALE 2
-
-
-
-
-
-
- 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;
- 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);
- }
-
-
-
|