static inline void delayMicroseconds(uint32_t) __attribute__((always_inline, unused)); | static inline void delayMicroseconds(uint32_t) __attribute__((always_inline, unused)); | ||||
static inline void delayMicroseconds(uint32_t usec) | static inline void delayMicroseconds(uint32_t usec) | ||||
{ | { | ||||
#if F_CPU == 168000000 | |||||
#if F_CPU == 192000000 | |||||
uint32_t n = usec * 64; | |||||
#elif F_CPU == 180000000 | |||||
uint32_t n = usec * 60; | |||||
#elif F_CPU == 168000000 | |||||
uint32_t n = usec * 56; | uint32_t n = usec * 56; | ||||
#elif F_CPU == 144000000 | #elif F_CPU == 144000000 | ||||
uint32_t n = usec * 48; | uint32_t n = usec * 48; |
#if defined(__MK64FX512__) || defined(__MK66FX1M0__) | #if defined(__MK64FX512__) || defined(__MK66FX1M0__) | ||||
SCB_CPACR = 0x00F00000; | SCB_CPACR = 0x00F00000; | ||||
#endif | #endif | ||||
#if defined(__MK66FX1M0__) | |||||
LMEM_PCCCR = 0x85000003; | |||||
#endif | |||||
#if 0 | #if 0 | ||||
// testing only, enable ser_print | // testing only, enable ser_print | ||||
SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV4(1); | SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV4(1); |
} | } | ||||
// TODO: verify these result in correct timeouts... | // TODO: verify these result in correct timeouts... | ||||
#if F_CPU == 168000000 | |||||
#if F_CPU == 192000000 | |||||
#define PULSEIN_LOOPS_PER_USEC 29 | |||||
#elif F_CPU == 180000000 | |||||
#define PULSEIN_LOOPS_PER_USEC 27 | |||||
#elif F_CPU == 168000000 | |||||
#define PULSEIN_LOOPS_PER_USEC 25 | #define PULSEIN_LOOPS_PER_USEC 25 | ||||
#elif F_CPU == 144000000 | #elif F_CPU == 144000000 | ||||
#define PULSEIN_LOOPS_PER_USEC 21 | #define PULSEIN_LOOPS_PER_USEC 21 |
int touchRead(uint8_t pin) | int touchRead(uint8_t pin) | ||||
{ | { | ||||
#if defined(__MK64FX512__) | |||||
return 0; // no Touch sensing :( | |||||
#else | |||||
uint32_t ch; | uint32_t ch; | ||||
if (pin >= NUM_DIGITAL_PINS) return 0; | if (pin >= NUM_DIGITAL_PINS) return 0; | ||||
delayMicroseconds(1); | delayMicroseconds(1); | ||||
return TSI0_DATA & 0xFFFF; | return TSI0_DATA & 0xFFFF; | ||||
#endif | #endif | ||||
#endif | |||||
} | } | ||||
// When the PC isn't listening, how long do we wait before discarding data? | // When the PC isn't listening, how long do we wait before discarding data? | ||||
#define TX_TIMEOUT_MSEC 30 | #define TX_TIMEOUT_MSEC 30 | ||||
#if F_CPU == 168000000 | |||||
#if F_CPU == 192000000 | |||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1280) | |||||
#elif F_CPU == 180000000 | |||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1200) | |||||
#elif F_CPU == 168000000 | |||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1100) | #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1100) | ||||
#elif F_CPU == 144000000 | #elif F_CPU == 144000000 | ||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 932) | #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 932) |
// When the PC isn't listening, how long do we wait before discarding data? | // When the PC isn't listening, how long do we wait before discarding data? | ||||
#define TX_TIMEOUT_MSEC 50 | #define TX_TIMEOUT_MSEC 50 | ||||
#if F_CPU == 168000000 | |||||
#if F_CPU == 192000000 | |||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1280) | |||||
#elif F_CPU == 180000000 | |||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1200) | |||||
#elif F_CPU == 168000000 | |||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1100) | #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1100) | ||||
#elif F_CPU == 144000000 | #elif F_CPU == 144000000 | ||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 932) | #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 932) |
// When the PC isn't listening, how long do we wait before discarding data? | // When the PC isn't listening, how long do we wait before discarding data? | ||||
#define TX_TIMEOUT_MSEC 40 | #define TX_TIMEOUT_MSEC 40 | ||||
#if F_CPU == 168000000 | |||||
#if F_CPU == 192000000 | |||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1280) | |||||
#elif F_CPU == 180000000 | |||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1200) | |||||
#elif F_CPU == 168000000 | |||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1100) | #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1100) | ||||
#elif F_CPU == 144000000 | #elif F_CPU == 144000000 | ||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 932) | #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 932) |
// When the PC isn't listening, how long do we wait before discarding data? | // When the PC isn't listening, how long do we wait before discarding data? | ||||
#define TX_TIMEOUT_MSEC 30 | #define TX_TIMEOUT_MSEC 30 | ||||
#if F_CPU == 168000000 | |||||
#if F_CPU == 192000000 | |||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1280) | |||||
#elif F_CPU == 180000000 | |||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1200) | |||||
#elif F_CPU == 168000000 | |||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1100) | #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1100) | ||||
#elif F_CPU == 144000000 | #elif F_CPU == 144000000 | ||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 932) | #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 932) |
// software. If it's too long, we stall the user's program when no software is running. | // software. If it's too long, we stall the user's program when no software is running. | ||||
#define TX_TIMEOUT_MSEC 30 | #define TX_TIMEOUT_MSEC 30 | ||||
#if F_CPU == 168000000 | |||||
#if F_CPU == 192000000 | |||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1280) | |||||
#elif F_CPU == 180000000 | |||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1200) | |||||
#elif F_CPU == 168000000 | |||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1100) | #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1100) | ||||
#elif F_CPU == 144000000 | #elif F_CPU == 144000000 | ||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 932) | #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 932) |
// software. If it's too long, we stall the user's program when no software is running. | // software. If it's too long, we stall the user's program when no software is running. | ||||
#define TX_TIMEOUT_MSEC 70 | #define TX_TIMEOUT_MSEC 70 | ||||
#if F_CPU == 168000000 | |||||
#if F_CPU == 192000000 | |||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1280) | |||||
#elif F_CPU == 180000000 | |||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1200) | |||||
#elif F_CPU == 168000000 | |||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1100) | #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1100) | ||||
#elif F_CPU == 144000000 | #elif F_CPU == 144000000 | ||||
#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 932) | #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 932) |