Remove freetouch files that were accidentally checked in and

readd the submodule.
This commit is contained in:
Scott Shawcroft 2018-03-28 13:49:14 -07:00
parent 6711c5c90d
commit 19b0b414e6
9 changed files with 4 additions and 985 deletions

6
.gitmodules vendored
View File

@ -33,9 +33,6 @@
path = lib/stm32lib
url = https://github.com/micropython/stm32lib
branch = work-F4-1.13.1+F7-1.5.0+L4-1.3.0
[submodule "freetouch2"]
path = ports/atmel-samd/freetouch
url = https://github.com/adafruit/Adafruit_FreeTouch.git
[submodule "atmel-samd/asf4"]
path = ports/atmel-samd/asf4
url = https://github.com/adafruit/asf4.git
@ -46,3 +43,6 @@
[submodule "lib/nrfutil"]
path = lib/nrfutil
url = https://github.com/adafruit/nRF52_nrfutil
[submodule "ports/atmel-samd/freetouch"]
path = ports/atmel-samd/freetouch
url = https://github.com/adafruit/Adafruit_FreeTouch.git

@ -0,0 +1 @@
Subproject commit c3deba11eb4be397ec719cfbfba1abcaecda2c08

View File

@ -1,280 +0,0 @@
/*
* FreeTouch, a QTouch-compatible library - tested on ATSAMD21 only!
* The MIT License (MIT)
*
* Copyright (c) 2017 Limor 'ladyada' Fried for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "Adafruit_FreeTouch.h"
#include "adafruit_ptc.h"
Adafruit_FreeTouch::Adafruit_FreeTouch(int p, oversample_t f, series_resistor_t r, freq_mode_t fh) {
adafruit_ptc_get_config_default(&config);
pin = p;
uint8_t port_offset = 0;
if (g_APinDescription[pin].ulPort == PORTB) {
port_offset += 32;
}
config.pin = port_offset + g_APinDescription[pin].ulPin;
config.yline = getYLine(); // determine the Y0-15 #
config.oversample = f;
config.seriesres = r;
config.freqhop = fh;
}
bool Adafruit_FreeTouch::begin(void) {
if (config.yline == -1) { // not all pins have Y line
return false;
}
/* Setup and enable generic clock source for PTC module.
struct system_gclk_chan_config gclk_chan_conf;
system_gclk_chan_get_config_defaults(&gclk_chan_conf);
*/
uint8_t channel = PTC_GCLK_ID;
uint8_t source_generator = 1;
// original line: system_gclk_chan_set_config(PTC_GCLK_ID, &gclk_chan_conf);
uint32_t new_clkctrl_config = (channel << GCLK_CLKCTRL_ID_Pos); // from gclk.c
// original line: gclk_chan_conf.source_generator = GCLK_GENERATOR_1;
/* Select the desired generic clock generator */
new_clkctrl_config |= source_generator << GCLK_CLKCTRL_GEN_Pos; // from gclk.c
/* Disable generic clock channel */
// original line: system_gclk_chan_disable(channel);
noInterrupts();
/* Select the requested generator channel */
*((uint8_t*)&GCLK->CLKCTRL.reg) = channel;
/* Sanity check WRTLOCK */
//Assert(!GCLK->CLKCTRL.bit.WRTLOCK);
/* Switch to known-working source so that the channel can be disabled */
uint32_t prev_gen_id = GCLK->CLKCTRL.bit.GEN;
GCLK->CLKCTRL.bit.GEN = 0;
/* Disable the generic clock */
GCLK->CLKCTRL.reg &= ~GCLK_CLKCTRL_CLKEN;
while (GCLK->CLKCTRL.reg & GCLK_CLKCTRL_CLKEN) {
/* Wait for clock to become disabled */
}
/* Restore previous configured clock generator */
GCLK->CLKCTRL.bit.GEN = prev_gen_id;
//system_interrupt_leave_critical_section();
interrupts();
/* Write the new configuration */
GCLK->CLKCTRL.reg = new_clkctrl_config;
// original line: system_gclk_chan_enable(PTC_GCLK_ID);
*((uint8_t*)&GCLK->CLKCTRL.reg) = channel;
GCLK->CLKCTRL.reg |= GCLK_CLKCTRL_CLKEN; /* Enable the generic clock */
// original line: system_apb_clock_set_mask(SYSTEM_CLOCK_APB_APBC, PM_APBCMASK_PTC);
PM->APBCMASK.reg |= PM_APBCMASK_PTC;
adafruit_ptc_init(PTC, &config);
return true;
}
uint16_t Adafruit_FreeTouch::measure(void) {
uint16_t m;
m = measureRaw();
if (m == -1) return -1;
// normalize the signal
switch (config.oversample) {
case OVERSAMPLE_1: return m;
case OVERSAMPLE_2: return m/2;
case OVERSAMPLE_4: return m/4;
case OVERSAMPLE_8: return m/8;
case OVERSAMPLE_16: return m/16;
case OVERSAMPLE_32: return m/32;
case OVERSAMPLE_64: return m/64;
}
return -1; // shouldn't reach here but fail if we do!
}
uint16_t Adafruit_FreeTouch::measureRaw(void) {
adafruit_ptc_start_conversion(PTC, &config);
while (!adafruit_ptc_is_conversion_finished(PTC)) {
yield();
}
return adafruit_ptc_get_conversion_result(PTC);
}
/*********************************** low level config **/
int Adafruit_FreeTouch::getYLine(void) {
int p = g_APinDescription[pin].ulPin;
if (g_APinDescription[pin].ulPort == PORTA) {
if ((p >= 2) && (p <= 7)) {
return (p - 2);
}
}
if (g_APinDescription[pin].ulPort == PORTB) {
if ((p >= 0) && (p <= 9)) {
return (p + 6);
}
}
// not valid
return -1;
}
void Adafruit_FreeTouch::setCompCap(uint16_t cc) {
config.compcap = cc & 0x3FFF;
}
void Adafruit_FreeTouch::setIntCap(uint8_t ic) {
config.intcap = ic & 0x3F;
}
void Adafruit_FreeTouch::setOversampling(oversample_t lvl) {
config.oversample = lvl; // back it up for later
}
void Adafruit_FreeTouch::setSeriesResistor(series_resistor_t res) {
config.seriesres = res;
}
void Adafruit_FreeTouch::setFreqHopping(freq_mode_t fh, freq_hop_t hs) {
config.freqhop = fh;
config.hops = hs;
}
/**************************** DEBUGGING ASSIST *************************/
void Adafruit_FreeTouch::snapshotRegsAndPrint(uint32_t base, uint8_t numregs) {
volatile uint32_t addr = base;
uint8_t datas[255];
digitalWrite(LED_BUILTIN, HIGH);
for (uint8_t i=0; i<numregs; i++) {
datas[i] = *(uint8_t *)(addr+i);
}
digitalWrite(LED_BUILTIN, LOW);
printPTCregs(base, datas, numregs);
for (uint8_t i=0; i<numregs; i++) {
// Serial.print("$"); Serial.print(addr+i, HEX); Serial.print("\t0x");
// printHex(datas[i]); Serial.println();
}
}
// Print a hex with leading zero
void Adafruit_FreeTouch::printHex(uint8_t h, boolean newline) {
if (h < 0x10) Serial.print("0");
Serial.print(h, HEX);
if (newline) Serial.println();
}
void Adafruit_FreeTouch::printPTCregs(uint32_t base, uint8_t *regs, uint8_t num) {
Serial.println("--------------------------------------------------------");
for (uint8_t i=0; i<num; i++) {
switch (i + base) {
case 0x41004430: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" PMUX0:\t\t0x"); printHex(regs[i], true); break;
case 0x41004431: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" PMUX1:\t\t0x"); printHex(regs[i], true); break;
case 0x41004432: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" PMUX2:\t\t0x"); printHex(regs[i], true); break;
case 0x41004433: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" PMUX3:\t\t0x"); printHex(regs[i], true); break;
case 0x41004440: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" PCFG0:\t\t0x"); printHex(regs[i], true); break;
case 0x41004441: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" PCFG1:\t\t0x"); printHex(regs[i], true); break;
case 0x41004442: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" PCFG2:\t\t0x"); printHex(regs[i], true); break;
case 0x41004443: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" PCFG3:\t\t0x"); printHex(regs[i], true); break;
case 0x41004444: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" PCFG4:\t\t0x"); printHex(regs[i], true); break;
case 0x42004C00: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" Control A:\t\t0x"); printHex(regs[i], true); break;
case 0x42004C01: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" Sync: \t\t0x"); printHex(regs[i], true); break;
case 0x42004C04: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" Prescaler:\t\t0x"); printHex(regs[i], true); break;
case 0x42004C05: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" Init: \t\t0x"); printHex(regs[i], true); break;
case 0x42004C08: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" Disable Irq:\t\t0x"); printHex(regs[i], true); break;
case 0x42004C09: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" Enable Irq:\t\t0x"); printHex(regs[i], true); break;
case 0x42004C0A: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" Flags: \t\t0x"); printHex(regs[i], true); break;
case 0x42004C0C: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" Freq Cntl:\t\t0x"); printHex(regs[i], true); break;
case 0x42004C0D: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" Conv Cntl:\t\t0x"); printHex(regs[i], true); break;
case 0x42004C10: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" Y Select1:\t\t0x"); printHex(regs[i], true); break;
case 0x42004C11: Serial.print("0x"); Serial.print(i+0x42004C00, HEX);
Serial.print(" Y Select2:\t\t0x"); printHex(regs[i], true); break;
/*
case 0x42004C12: Serial.print("0x"); Serial.print(i+0x42004C00, HEX);
Serial.print(" X Select1:\t\t0x"); printHex(regs[i], true); break;
case 0x42004C13: Serial.print("0x"); Serial.print(i+0x42004C00, HEX);
Serial.print(" X Select2:\t\t0x"); printHex(regs[i], true); break;
*/
case 0x42004C14: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" Y Enable1:\t\t0x"); printHex(regs[i], true); break;
case 0x42004C15: Serial.print("0x"); Serial.print(i+0x42004C00, HEX);
Serial.print(" Y Enable2:\t\t0x"); printHex(regs[i], true); break;
/*
case 0x42004C16: Serial.print("0x"); Serial.print(i+0x42004C00, HEX);
Serial.print(" X Enable1:\t\t0x"); printHex(regs[i], true); break;
case 0x42004C17: Serial.print("0x"); Serial.print(i+0x42004C00, HEX);
Serial.print(" X Enable2:\t\t0x"); printHex(regs[i], true); break;
*/
case 0x42004C18: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" Compcap L:\t\t0x"); printHex(regs[i], true); break;
case 0x42004C19: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" Compcap H:\t\t0x"); printHex(regs[i], true); break;
case 0x42004C1A: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" Intcap: \t\t0x"); printHex(regs[i], true); break;
case 0x42004C1B: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" Sense res:\t\t0x"); printHex(regs[i], true); break;
case 0x42004C1C: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" Result L:\t\t0x"); printHex(regs[i], true); break;
case 0x42004C1D: Serial.print("0x"); Serial.print(i+base, HEX);
Serial.print(" Result H:\t\t0x"); printHex(regs[i], true); break;
}
}
}

View File

@ -1,37 +0,0 @@
#ifndef ADAFRUIT_FREETOUCH_H
#define ADAFRUIT_FREETOUCH_H
#include <Arduino.h>
#include "adafruit_ptc.h"
class Adafruit_FreeTouch {
public:
Adafruit_FreeTouch(int p = 0, oversample_t f = OVERSAMPLE_4, series_resistor_t r = RESISTOR_0, freq_mode_t fh = FREQ_MODE_NONE);
bool begin(void);
uint16_t measure(void);
uint16_t measureRaw(void);
private:
void ptcInitSettings(void);
void ptcConfigIOpin(void);
uint16_t startPtcAcquire(void);
int getYLine(void);
void selectYLine(void);
void setOversampling(oversample_t lvl);
void setSeriesResistor(series_resistor_t res);
void setFreqHopping(freq_mode_t fh, freq_hop_t hops = FREQ_HOP_1);
void setCompCap(uint16_t cc);
void setIntCap(uint8_t ic);
void snapshotRegsAndPrint(uint32_t base, uint8_t numregs);
void printHex(uint8_t h, boolean newline);
void printPTCregs(uint32_t base, uint8_t *regs, uint8_t num);
private:
int pin; // arduino pin #
struct adafruit_ptc_config config;
};
#endif

View File

@ -1,2 +0,0 @@
# Adafruit_FreeTouch
A QTouch-compatible library

View File

@ -1,148 +0,0 @@
/*
* FreeTouch, a QTouch-compatible library - tested on ATSAMD21 only!
* The MIT License (MIT)
*
* Copyright (c) 2017 Limor 'ladyada' Fried for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "adafruit_ptc.h"
#include "pinmux.h"
static void sync_config(Ptc const* module_inst) {
while (module_inst->CONTROLB.bit.SYNCFLAG) ;
}
void adafruit_ptc_get_config_default(struct adafruit_ptc_config *config) {
config->pin = 0xff;
config->yline = -1;
config->oversample = OVERSAMPLE_4;
config->seriesres = RESISTOR_0;
config->freqhop = FREQ_MODE_NONE;
config->compcap = 0x2000;
config->intcap = 0x3F;
}
void adafruit_ptc_init(Ptc* module_inst, struct adafruit_ptc_config const* config) {
struct system_pinmux_config pinmux_config;
system_pinmux_get_config_defaults(&pinmux_config);
pinmux_config.mux_position = 0x1;
pinmux_config.input_pull = SYSTEM_PINMUX_PIN_PULL_NONE;
system_pinmux_pin_set_config(config->pin, &pinmux_config);
sync_config(module_inst);
module_inst->CONTROLA.bit.ENABLE = 0;
sync_config(module_inst);
module_inst->UNK4C04.reg &= 0xF7; //MEMORY[0x42004C04] &= 0xF7u;
module_inst->UNK4C04.reg &= 0xFB; //MEMORY[0x42004C04] &= 0xFBu;
module_inst->UNK4C04.reg &= 0xFC; //MEMORY[0x42004C04] &= 0xFCu;
sync_config(module_inst);
module_inst->FREQCONTROL.reg &= 0x9F; //MEMORY[0x42004C0C] &= 0x9Fu;
sync_config(module_inst);
module_inst->FREQCONTROL.reg &= 0xEF; //MEMORY[0x42004C0C] &= 0xEFu;
sync_config(module_inst);
module_inst->FREQCONTROL.bit.SAMPLEDELAY = 0; //MEMORY[0x42004C0C] &= 0xF0u;
module_inst->CONTROLC.bit.INIT = 1; //MEMORY[0x42004C05] |= 1u;
module_inst->CONTROLA.bit.RUNINSTANDBY = 1; //MEMORY[0x42004C00] |= 4u;
sync_config(module_inst);
module_inst->INTDISABLE.bit.WCO = 1;
sync_config(module_inst);
module_inst->INTDISABLE.bit.EOC = 1;
sync_config(module_inst);
// enable the sensor, only done once per line
if (config->yline < 8) {
sync_config(module_inst);
module_inst->YENABLEL.reg |= 1 << config->yline;
sync_config(module_inst);
} else if (config->yline < 16) {
module_inst->YENABLEH.reg |= 1 << (config->yline - 8);
}
sync_config(module_inst);
module_inst->CONTROLA.bit.ENABLE = 1;
sync_config(module_inst);
}
void adafruit_ptc_start_conversion(Ptc* module_inst, struct adafruit_ptc_config const* config) {
module_inst->CONTROLA.bit.RUNINSTANDBY = 1;
sync_config(module_inst);
module_inst->CONTROLA.bit.ENABLE = 1;
sync_config(module_inst);
module_inst->INTDISABLE.bit.WCO = 1;
sync_config(module_inst);
module_inst->INTFLAGS.bit.WCO = 1;
sync_config(module_inst);
module_inst->INTFLAGS.bit.EOC = 1;
sync_config(module_inst);
// set up pin!
sync_config(module_inst);
if (config->yline < 8) {
module_inst->YSELECTL.reg = 1 << config->yline;
} else {
module_inst->YSELECTL.reg = 0;
}
if (config->yline > 7) {
module_inst->YSELECTH.reg = 1 << (config->yline - 8);
} else {
module_inst->YSELECTH.reg = 0;
}
sync_config(module_inst);
// set up sense resistor
module_inst->SERRES.bit.RESISTOR = config->seriesres;
sync_config(module_inst);
// set up prescalar
module_inst->CONVCONTROL.bit.ADCACCUM = config->oversample;
sync_config(module_inst);
// set up freq hopping
if (config->freqhop == FREQ_MODE_NONE) {
module_inst->FREQCONTROL.bit.FREQSPREADEN = 0;
module_inst->FREQCONTROL.bit.SAMPLEDELAY = 0;
} else {
module_inst->FREQCONTROL.bit.FREQSPREADEN = 1;
module_inst->FREQCONTROL.bit.SAMPLEDELAY = config->hops;
}
// set up compensation cap + int (?) cap
sync_config(module_inst);
module_inst->COMPCAPL.bit.VALUE = config->compcap & 0xFF;
module_inst->COMPCAPH.bit.VALUE = (config->compcap>>8) & 0x3F;
sync_config(module_inst);
module_inst->INTCAP.bit.VALUE = config->intcap & 0x3F;
sync_config(module_inst);
module_inst->BURSTMODE.reg = 0xA4;
sync_config(module_inst);
module_inst->CONVCONTROL.bit.CONVERT = 1;
sync_config(module_inst);
}
bool adafruit_ptc_is_conversion_finished(Ptc* module_inst) {
return module_inst->CONVCONTROL.bit.CONVERT == 0;
}
uint16_t adafruit_ptc_get_conversion_result(Ptc* module_inst) {
sync_config(module_inst);
return module_inst->RESULT.reg;
}

View File

@ -1,109 +0,0 @@
/*
* FreeTouch, a QTouch-compatible library - tested on ATSAMD21 only!
* The MIT License (MIT)
*
* Copyright (c) 2017 Limor 'ladyada' Fried for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
// This is similar to the drivers found in sam0/drivers but for the PTC.
#ifndef ADAFRUIT_FREETOUCH_ADAFRUIT_PTC_H
#define ADAFRUIT_FREETOUCH_ADAFRUIT_PTC_H
#include <stdint.h>
#include "samd21_ptc_component.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Touch library oversampling (filter) setting */
typedef enum tag_oversample_level_t {
OVERSAMPLE_1,
OVERSAMPLE_2,
OVERSAMPLE_4,
OVERSAMPLE_8,
OVERSAMPLE_16,
OVERSAMPLE_32,
OVERSAMPLE_64
}
oversample_t;
/* Touch library series resistor setting */
typedef enum tag_series_resistor_t {
RESISTOR_0,
RESISTOR_20K,
RESISTOR_50K,
RESISTOR_100K,
}
series_resistor_t;
typedef enum tag_freq_mode_t {
FREQ_MODE_NONE,
FREQ_MODE_HOP,
FREQ_MODE_SPREAD,
FREQ_MODE_SPREAD_MEDIAN
}
freq_mode_t;
typedef enum tag_freq_hop_t {
FREQ_HOP_1,
FREQ_HOP_2,
FREQ_HOP_3,
FREQ_HOP_4,
FREQ_HOP_5,
FREQ_HOP_6,
FREQ_HOP_7,
FREQ_HOP_8,
FREQ_HOP_9,
FREQ_HOP_10,
FREQ_HOP_11,
FREQ_HOP_12,
FREQ_HOP_13,
FREQ_HOP_14,
FREQ_HOP_15,
FREQ_HOP_16
}
freq_hop_t;
struct adafruit_ptc_config {
uint8_t pin; // ASF pin #
int8_t yline; // the Y select line (see datasheet)
oversample_t oversample;
series_resistor_t seriesres;
freq_mode_t freqhop;
freq_hop_t hops;
uint16_t compcap;
uint8_t intcap;
};
void adafruit_ptc_get_config_default(struct adafruit_ptc_config *config);
void adafruit_ptc_init(Ptc* module_inst, struct adafruit_ptc_config const* config);
void adafruit_ptc_start_conversion(Ptc* module_inst, struct adafruit_ptc_config const* config);
bool adafruit_ptc_is_conversion_finished(Ptc* module_inst);
uint16_t adafruit_ptc_get_conversion_result(Ptc* module_inst);
#ifdef __cplusplus
}
#endif
#endif // ADAFRUIT_FREETOUCH_ADAFRUIT_PTC_H

View File

@ -1,56 +0,0 @@
#include "Adafruit_FreeTouch.h"
Adafruit_FreeTouch qt_1 = Adafruit_FreeTouch(A0, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
Adafruit_FreeTouch qt_2 = Adafruit_FreeTouch(A1, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
Adafruit_FreeTouch qt_3 = Adafruit_FreeTouch(A2, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
Adafruit_FreeTouch qt_4 = Adafruit_FreeTouch(A3, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println("FreeTouch test");
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
if (! qt_1.begin())
Serial.println("Failed to begin qt on pin A0");
if (! qt_2.begin())
Serial.println("Failed to begin qt on pin A1");
if (! qt_3.begin())
Serial.println("Failed to begin qt on pin A2");
if (! qt_4.begin())
Serial.println("Failed to begin qt on pin A3");
}
void loop() {
int counter, result = 0;
// DIY
Serial.println("\n*************************************");
counter = millis();
result = qt_1.measure();
Serial.print("QT 1: "); Serial.print(result);
Serial.print(" ("); Serial.print(millis() - counter); Serial.println(" ms)");
counter = millis();
result = qt_2.measure();
Serial.print("QT 2: "); Serial.print(result);
Serial.print(" ("); Serial.print(millis() - counter); Serial.println(" ms)");
counter = millis();
result = qt_3.measure();
Serial.print("QT 3: "); Serial.print(result);
Serial.print(" ("); Serial.print(millis() - counter); Serial.println(" ms)");
counter = millis();
result = qt_4.measure();
Serial.print("QT 4: "); Serial.print(result);
Serial.print(" ("); Serial.print(millis() - counter); Serial.println(" ms)");
delay(200);
}

View File

@ -1,350 +0,0 @@
/*
* FreeTouch, a QTouch-compatible library - tested on ATSAMD21 only!
* The MIT License (MIT)
*
* Copyright (c) 2017 Limor 'ladyada' Fried for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
// This is similar to the component definitions found in
// sam0/utils/cmsis/samd21/include/component but for the PTC.
#ifndef ADAFRUIT_FREETOUCH_PTC_COMPONENT_H
#define ADAFRUIT_FREETOUCH_PTC_COMPONENT_H
#include "compiler.h"
#undef ENABLE
/*************** CONTROL A register ***************/
#define PTC_REG_CONTROLA 0x42004C00
#define PTC_BIT_ENABLE 0x02
#define PTC_BIT_RUNINSTBY 0x04
typedef union {
struct {
uint8_t SWRESET:1;
uint8_t ENABLE:1;
uint8_t RUNINSTANDBY:1;
uint8_t __pad0__:5;
} bit;
uint8_t reg;
} PTC_REG_CONTROLA_Type;
/*************** CONTROL B register ***************/
#define PTC_REG_CONTROLB 0x42004C01
#define PTC_BIT_SYNCFLAG 0x80
typedef union {
struct {
uint8_t __pad0__:7;
uint8_t SYNCFLAG:1;
} bit;
uint8_t reg;
} PTC_REG_CONTROLB_Type;
/*************** UNK4C04 register ***************/
#define PTC_REG_UNK4C04 0x42004C04
typedef union {
uint8_t reg;
} PTC_REG_UNK4C04_Type;
/*************** CONTROL C register ***************/
#define PTC_REG_CONTROLC 0x42004C05
#define PTC_BIT_INIT 0x01
typedef union {
struct {
uint8_t INIT:1;
uint8_t __pad0__:7;
} bit;
uint8_t reg;
} PTC_REG_CONTROLC_Type;
/*************** INT registers ***************/
typedef union {
struct {
uint8_t EOC:1;
uint8_t WCO:1;
uint8_t __pad0__:6;
} bit;
uint8_t reg;
} PTC_REG_INT_Type;
#define PTC_REG_INTDISABLE 0x42004C08
#define PTC_REG_INTENABLE 0x42004C09
#define PTC_BIT_EOCINTEN 0x01
#define PTC_BIT_WCOINTEN 0x02
#define PTC_REG_INTFLAGS 0x42004C0A
#define PTC_BIT_EOCINTFLAG 0x01
#define PTC_BIT_WCOINTFLAG 0x02
/*************** FREQ CONTROL reg ***************/
typedef union {
struct {
uint8_t SAMPLEDELAY:4;
uint8_t FREQSPREADEN:1;
uint8_t __pad0__:3;
} bit;
uint8_t reg;
} PTC_REG_FREQCONTROL_Type;
#define PTC_REG_FREQCONTROL 0x42004C0C
#define PTC_BIT_FREQSPREADEN 0x10
#define PTC_REG_SAMPLEDELAY_MASK 0x0F
/*************** CONVERT CONTROL reg ***************/
typedef union {
struct {
uint8_t ADCACCUM:3;
uint8_t __pad0__:4;
uint8_t CONVERT:1;
} bit;
uint8_t reg;
} __attribute__ ((packed)) PTC_REG_CONVCONTROL_Type;
#define PTC_REG_CONVCONTROL 0x42004C0D
#define PTC_BIT_CONVSTARTED 0x80
#define PTC_REG_ADCACC_MASK 0x07
/*************** Y SELECT L+H reg ***************/
typedef union {
struct {
uint8_t Y0:1;
uint8_t Y1:1;
uint8_t Y2:1;
uint8_t Y3:1;
uint8_t Y4:1;
uint8_t Y5:1;
uint8_t Y6:1;
uint8_t Y7:1;
} bit;
uint8_t reg;
} __attribute__ ((packed)) PTC_REG_YSELECTL_Type;
typedef union {
struct {
uint8_t Y8:1;
uint8_t Y9:1;
uint8_t Y10:1;
uint8_t Y11:1;
uint8_t Y12:1;
uint8_t Y13:1;
uint8_t Y14:1;
uint8_t Y15:1;
} bit;
uint8_t reg;
} __attribute__ ((packed)) PTC_REG_YSELECTH_Type;
#define PTC_REG_YSELECT_L 0x42004C10
#define PTC_REG_YSELECT_H 0x42004C11
#define PTC_REG_YENABLE_L 0x42004C14
#define PTC_REG_YENABLE_H 0x42004C15
/*************** X SELECT L+H reg ***************/
typedef union {
struct {
uint8_t X0:1;
uint8_t X1:1;
uint8_t X2:1;
uint8_t X3:1;
uint8_t X4:1;
uint8_t X5:1;
uint8_t X6:1;
uint8_t X7:1;
} bit;
uint8_t reg;
} __attribute__ ((packed)) PTC_REG_XSELECTL_Type;
typedef union {
struct {
uint8_t X8:1;
uint8_t X9:1;
uint8_t X10:1;
uint8_t X11:1;
uint8_t X12:1;
uint8_t X13:1;
uint8_t X14:1;
uint8_t X15:1;
} bit;
uint8_t reg;
} __attribute__ ((packed)) PTC_REG_XSELECTH_Type;
#define PTC_REG_XSELECT_L 0x42004C12
#define PTC_REG_XSELECT_H 0x42004C13
#define PTC_REG_XENABLE_L 0x42004C16
#define PTC_REG_XENABLE_H 0x42004C17
/*************** Compensation Cap reg ***************/
typedef union {
struct {
uint8_t VALUE:8;
} bit;
uint8_t reg;
} __attribute__ ((packed)) PTC_REG_COMPCAPL_Type;
typedef union {
struct {
uint8_t VALUE:6;
uint8_t __pad0__:2;
} bit;
uint8_t reg;
} __attribute__ ((packed)) PTC_REG_COMPCAPH_Type;
#define PTC_REG_COMPCAPL 0x42004C18
#define PTC_REG_COMPCAPH 0x42004C19
/*************** Int Cap reg ***************/
typedef union {
struct {
uint8_t VALUE:6;
uint8_t __pad0__:2;
} bit;
uint8_t reg;
} __attribute__ ((packed)) PTC_REG_INTCAP_Type;
#define PTC_REG_INTCAP 0x42004C1A
/*************** Series resistor reg ***************/
typedef union {
struct {
uint8_t RESISTOR:2;
uint8_t __pad0__:6;
} bit;
uint8_t reg;
} __attribute__ ((packed)) PTC_REG_SERRES_Type;
#define PTC_REG_SERIESRES 0x42004C1B
/*************** conversion result reg ***************/
typedef union {
struct {
uint8_t LOWBYTE;
uint8_t HIGHBYTE;
} byte;
uint16_t reg;
} __attribute__ ((packed)) PTC_REG_CONVRESULT_Type;
#define PTC_REG_CONVRESULT_L 0x42004C1C
#define PTC_REG_CONVRESULT_H 0x42004C1D
/*************** burst mode reg ***************/
typedef union {
struct {
uint8_t __pad0__:2;
uint8_t CTSLOWPOWER:1;
uint8_t __pad1__:1;
uint8_t BURSTMODE:4;
} bit;
uint8_t reg;
} __attribute__ ((packed)) PTC_REG_BURSTMODE_Type;
#define PTC_REG_BURSTMODE 0x42004C20
#define PTC_REG_BURSTMODE_MASK 0xF0
#define PTC_BIT_CTSLOWPOWER 0x04
/*************** etc unused reg ***************/
#define PTC_REG_XYENABLE 0x42004C16
#define PTC_BIT_XYENABLE 0x02
#define PTC_REG_WCO_MODE 0x42004C21
#define PTC_REG_WCO_MODE_MASK 0x07
#define PTC_SET_WCO_THRESHHOLD_A_L 0x42004C24
#define PTC_SET_WCO_THRESHHOLD_A_H 0x42004C25
#define PTC_SET_WCO_THRESHHOLD_B_L 0x42004C26
#define PTC_SET_WCO_THRESHHOLD_B_H 0x42004C27
typedef struct {
__IO PTC_REG_CONTROLA_Type CONTROLA; // 0x42004C00
__IO PTC_REG_CONTROLB_Type CONTROLB; // 0x42004C01
uint8_t __pad4c02__; // 0x42004C02 unknown
uint8_t __pad4c03__; // 0x42004C03 unknown
__IO PTC_REG_UNK4C04_Type UNK4C04; // 0x42004C04 unknown
__IO PTC_REG_CONTROLC_Type CONTROLC; // 0x42004C05
uint8_t __pad4c06__; // 0x42004C06 unknown
uint8_t __pad4c07__; // 0x42004C07 unknown
__IO PTC_REG_INT_Type INTDISABLE; // 0x42004C08
__IO PTC_REG_INT_Type INTENABLE; // 0x42004C09
__IO PTC_REG_INT_Type INTFLAGS; // 0x42004C0A
uint8_t __pad4c0b__; // 0x42004C0B unknown
__IO PTC_REG_FREQCONTROL_Type FREQCONTROL; //0x42004C0C
__IO PTC_REG_CONVCONTROL_Type CONVCONTROL; // 0x42004C0D
uint8_t __pad4c0e__; // 0x42004C0E unknown
uint8_t __pad4c0f__; // 0x42004C0F unknown
__IO PTC_REG_YSELECTL_Type YSELECTL; // 0x42004C10
__IO PTC_REG_YSELECTL_Type YSELECTH; // 0x42004C11
__IO PTC_REG_XSELECTL_Type XSELECTL; // 0x42004C12
__IO PTC_REG_XSELECTL_Type XSELECTH; // 0x42004C13
__IO PTC_REG_YSELECTL_Type YENABLEL; // 0x42004C14
__IO PTC_REG_YSELECTL_Type YENABLEH; // 0x42004C15
__IO PTC_REG_XSELECTL_Type XENABLEL; // 0x42004C16
__IO PTC_REG_XSELECTL_Type XENABLEH; // 0x42004C17
__IO PTC_REG_COMPCAPL_Type COMPCAPL; // 0x42004C18
__IO PTC_REG_COMPCAPH_Type COMPCAPH; // 0x42004C19
__IO PTC_REG_INTCAP_Type INTCAP; // 0x42004C1A
__IO PTC_REG_SERRES_Type SERRES; // 0x42004C1B
__IO PTC_REG_CONVRESULT_Type RESULT; // 0x42004C1C + 0x42004C1D
uint8_t __pad4c1e__; // 0x42004C1E unknown
uint8_t __pad4c1f__; // 0x42004C1F unknown
__IO PTC_REG_BURSTMODE_Type BURSTMODE; // 0x42004C20
} Ptc;
#define PTC (( Ptc *)0x42004C00U)
#define PTC_REG_INTDISABLE 0x42004C08
#define PTC_REG_INTENABLE 0x42004C09
#define PTC_BIT_EOCINTEN 0x01
#define PTC_BIT_WCOINTEN 0x02
#define PTC_REG_INTFLAGS 0x42004C0A
#endif // ADAFRUIT_FREETOUCH_PTC_COMPONENT_H