@@ -137,6 +137,7 @@ enum IRQ_NUMBER_t { | |||
#define HAS_KINETIS_I2C0 | |||
#define HAS_KINETIS_LLWU_16CH | |||
#define HAS_KINETIS_ADC0 | |||
#define HAS_KINETIS_TSI | |||
// Teensy 3.1 | |||
#elif defined(__MK20DX256__) | |||
@@ -276,6 +277,7 @@ enum IRQ_NUMBER_t { | |||
#define HAS_KINETIS_LLWU_16CH | |||
#define HAS_KINETIS_ADC0 | |||
#define HAS_KINETIS_ADC1 | |||
#define HAS_KINETIS_TSI | |||
// Teensy-LC | |||
#elif defined(__MKL26Z64__) | |||
@@ -365,6 +367,7 @@ enum IRQ_NUMBER_t { | |||
#define HAS_KINETIS_I2C1_STOPF | |||
#define HAS_KINETIS_LLWU_16CH | |||
#define HAS_KINETIS_ADC0 | |||
#define HAS_KINETIS_TSI_LITE | |||
#elif defined(__MK64FX512__) | |||
@@ -743,6 +746,7 @@ enum IRQ_NUMBER_t { | |||
#define HAS_KINETIS_MPU | |||
#define HAS_KINETIS_ADC0 | |||
#define HAS_KINETIS_ADC1 | |||
#define HAS_KINETIS_TSI_LITE | |||
@@ -4696,7 +4700,7 @@ typedef struct __attribute__((packed)) { | |||
// Touch sense input (TSI) | |||
#if defined(KINETISK) | |||
#if defined(HAS_KINETIS_TSI) | |||
#define TSI0_GENCS (*(volatile uint32_t *)0x40045000) // General Control and Status Register | |||
#define TSI_GENCS_LPCLKS ((uint32_t)0x10000000) // | |||
#define TSI_GENCS_LPSCNITV(n) (((n) & 15) << 24) // | |||
@@ -4731,7 +4735,7 @@ typedef struct __attribute__((packed)) { | |||
#define TSI0_CNTR13 (*(volatile uint32_t *)0x40045118) // Counter Register | |||
#define TSI0_CNTR15 (*(volatile uint32_t *)0x4004511C) // Counter Register | |||
#define TSI0_THRESHOLD (*(volatile uint32_t *)0x40045120) // Low Power Channel Threshold Register | |||
#elif defined(KINETISL) | |||
#elif defined(HAS_KINETIS_TSI_LITE) | |||
#define TSI0_GENCS (*(volatile uint32_t *)0x40045000) // General Control and Status | |||
#define TSI_GENCS_OUTRGF ((uint32_t)0x80000000) // Out of Range Flag | |||
#define TSI_GENCS_ESOR ((uint32_t)0x10000000) // End-of-scan or Out-of-Range Interrupt Selection |
@@ -31,6 +31,8 @@ | |||
#include "core_pins.h" | |||
//#include "HardwareSerial.h" | |||
#if defined(HAS_KINETIS_TSI) || defined(HAS_KINETIS_TSI_LITE) | |||
#if defined(__MK20DX128__) || defined(__MK20DX256__) | |||
// These settings give approx 0.02 pF sensitivity and 1200 pF range | |||
// Lower current, higher number of scans, and higher prescaler | |||
@@ -48,7 +50,6 @@ static const uint8_t pin2tsi[] = { | |||
}; | |||
#elif defined(__MK66FX1M0__) | |||
#define CURRENT 2 | |||
#define NSCAN 9 | |||
#define PRESCALE 2 | |||
static const uint8_t pin2tsi[] = { | |||
@@ -78,9 +79,6 @@ static const uint8_t pin2tsi[] = { | |||
int touchRead(uint8_t pin) | |||
{ | |||
#if defined(__MK64FX512__) | |||
return 0; // no Touch sensing :( | |||
#else | |||
uint32_t ch; | |||
if (pin >= NUM_DIGITAL_PINS) return 0; | |||
@@ -89,7 +87,7 @@ int touchRead(uint8_t pin) | |||
*portConfigRegister(pin) = PORT_PCR_MUX(0); | |||
SIM_SCGC5 |= SIM_SCGC5_TSI; | |||
#if defined(KINETISK) | |||
#if defined(HAS_KINETIS_TSI) | |||
TSI0_GENCS = 0; | |||
TSI0_PEN = (1 << ch); | |||
TSI0_SCANC = TSI_SCANC_REFCHRG(3) | TSI_SCANC_EXTCHRG(CURRENT); | |||
@@ -98,7 +96,7 @@ int touchRead(uint8_t pin) | |||
while (TSI0_GENCS & TSI_GENCS_SCNIP) ; // wait | |||
delayMicroseconds(1); | |||
return *((volatile uint16_t *)(&TSI0_CNTR1) + ch); | |||
#elif defined(KINETISL) | |||
#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; | |||
@@ -107,9 +105,15 @@ int touchRead(uint8_t pin) | |||
delayMicroseconds(1); | |||
return TSI0_DATA & 0xFFFF; | |||
#endif | |||
#endif | |||
} | |||
#else | |||
int touchRead(uint8_t pin) | |||
{ | |||
return 0; // no Touch sensing :( | |||
} | |||
#endif | |||