atmel-samd: Basic capacitive touch button support.

Currently only works on a single channel and is only enabled for boards with
SPI flash. Only really designed for hardware testing at this point.
This commit is contained in:
Scott Shawcroft 2016-12-06 18:39:18 -08:00
parent cd09726904
commit 3972bc19c7
18 changed files with 4539 additions and 65 deletions

View File

@ -141,8 +141,8 @@ endif
LIBGCC_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
LIBM_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-file-name=libm.a)
LDFLAGS = -Lasf/thirdparty/CMSIS/Lib/GCC/ -L $(dir $(LIBGCC_FILE_NAME)) -L $(dir $(LIBM_FILE_NAME)) -nostdlib -T $(LD_FILE) -Map=$@.map --cref --gc-sections
LIBS = -larm_cortexM0l_math -lm -lgcc -lc
LDFLAGS = -L asf/thirdparty/CMSIS/Lib/GCC/ -L QTouch/ -L $(dir $(LIBGCC_FILE_NAME)) -L $(dir $(LIBM_FILE_NAME)) -nostdlib -T $(LD_FILE) -Map=$@.map --cref --gc-sections
LIBS = -larm_cortexM0l_math -lsamd21_qtouch_gcc -lm -lgcc -lc
SRC_ASF = $(addprefix asf/sam0/,\
@ -224,6 +224,16 @@ SRC_BINDINGS = \
SRC_BINDINGS_EXPANDED = $(addprefix shared-bindings/, $(SRC_BINDINGS)) \
$(addprefix common-hal/, $(SRC_BINDINGS))
# Handle touch support on its own since it only fits in the image when external
# flash is used to store the file system.
SRC_BINDINGS_EXPANDED += shared-bindings/nativeio/TouchIn.c
ifeq ($(FLASH_IMPL),internal_flash.c)
SRC_BINDINGS_EXPANDED += common-hal/nativeio/TouchInStub.c
else
SRC_BINDINGS_EXPANDED += common-hal/nativeio/TouchIn.c
endif
SRC_SHARED_MODULE = \
bitbangio/__init__.c \
bitbangio/I2C.c \

File diff suppressed because it is too large Load Diff

View File

@ -140,11 +140,11 @@
# define CONF_CLOCK_GCLK_0_OUTPUT_ENABLE false
/* Configure GCLK generator 1 */
# define CONF_CLOCK_GCLK_1_ENABLE false
# define CONF_CLOCK_GCLK_1_RUN_IN_STANDBY false
# define CONF_CLOCK_GCLK_1_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_XOSC32K
# define CONF_CLOCK_GCLK_1_ENABLE true
# define CONF_CLOCK_GCLK_1_RUN_IN_STANDBY true
# define CONF_CLOCK_GCLK_1_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_OSC8M
# define CONF_CLOCK_GCLK_1_PRESCALER 1
# define CONF_CLOCK_GCLK_1_OUTPUT_ENABLE true
# define CONF_CLOCK_GCLK_1_OUTPUT_ENABLE false
/* Configure GCLK generator 2 (RTC) */
# define CONF_CLOCK_GCLK_2_ENABLE false

View File

@ -0,0 +1,613 @@
/* This source file is part of the ATMEL QTouch Library 5.0.8 */
/*****************************************************************************
*
* \file
*
* \brief This file contains the SAMD QTouch Library pin, register and
* sensors configuration options for Capacitive Touch acquisition using
* the PTC module.
*
*
* - Userguide: QTouch Library Peripheral Touch Controller User Guide.
* - Support email: www.atmel.com/design-support/
*
*
* Copyright (c) 2013-2015 Atmel Corporation. All rights reserved.
*
* \asf_license_start
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name of Atmel may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 4. This software may only be redistributed and used in connection with an
* Atmel microcontroller product.
*
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* \asf_license_stop
*
******************************************************************************/
#ifndef TOUCH_CONFIG_SAMD_H
#define TOUCH_CONFIG_SAMD_H
/*----------------------------------------------------------------------------
* Self Cap method enable/disable.
*
*
*----------------------------------------------------------------------------*/
/**
* Enable/Disable Self/Mutual Capacitance method.
*/
#define DEF_TOUCH_SELFCAP (1)
#define DEF_TOUCH_MUTLCAP (0)
/*----------------------------------------------------------------------------
* PTC module clock and interrupt level configuration.
*
*
*----------------------------------------------------------------------------*/
/**
* PTC Module clock configuration.
* Before using the QTouch library API, the PTC module clock generator source
* should be configured appropriately. The PTC module clock can be generated
* using any of the eight generic clock generators (GCLK0-GCLK7). The
*associated
* generic clock multiplexer should be configured such that the PTC module clock
* is set to 4MHz. Refer touch_configure_ptc_clock API in touch.c for more
* information.
*/
/**
* PTC Module interrupt level.
* The Nested Vectored Interrupt Controller (NVIC) in the SAMD supports
* four different priority levels. The priority level of the PTC end of
* conversion ISR, used within QTouch library can be chosen based on application
* requirements in order to accommodate time critical operations.
* Range: 0u (Highest priority) to 3u (Lowest prioirity)
* For more details refer to the Cortex-M0 Technical Reference Manual.
*/
#define DEF_TOUCH_PTC_ISR_LVL (2u)
/*----------------------------------------------------------------------------
* Self Cap method pin configuration.
*
*
*----------------------------------------------------------------------------*/
/**
* Self Cap touch channel selected.
* The capacitance measurement is done sequentially in the order in which
* the touch channel (nodes) are specified below. Touch channel numbering
* follows the order in which Y lines are specified. Capacitance measurement
* is done sequentially in the order in which touch channel nodes are specified.
*/
#define DEF_SELFCAP_LINES Y(2),Y(3),Y(4),Y(5),Y(8),Y(9),Y(14),Y(15)
/*----------------------------------------------------------------------------
* Self Cap method channel and sensor configuration.
*
*
*----------------------------------------------------------------------------*/
/**
* Self Cap number of channels.
* Specify the number of Self Cap touch channels to be used by the Touch
*Library.
* A key is formed used one touch channel. A rotor or slider can be formed
* using 3 touch channels.
* Range: 1u to 16u.
*/
#define DEF_SELFCAP_NUM_CHANNELS (8) //Total number of channels
/**
* Self Cap number of Sensors.
* Specify the number of Self Cap touch sensors to be used by the Touch Library.
* A sensor is either a key, rotor or slider.
* Example configuration: If the configuration has 6 keys (a key is formed
* using one Sensor Pin), one rotor (a Self Cap rotor is formed using 3 Sensor
* Pins) and one slider (a Self Cap slider is formed using 3 Sensor Pins), then
* the number of sensors is 6 key + 1 rotor + 1 slider = 8 sensors.
* Range: 1u to 16u.
*/
#define DEF_SELFCAP_NUM_SENSORS (8) //Total number of sensors
/**
* Self Cap number of Rotors and Sliders.
* Specify the total number of Self Cap Rotors and Sliders to be used by
* the Touch Library. The number of Rotors and Sliders mentioned here is part
* of
* the Total number of sensors specified in the QT_NUM_SENSORS macro. When
* no rotors or slider are required, specify a value of 0u.
* Range: 0u to 8u.
*/
#define DEF_SELFCAP_NUM_ROTORS_SLIDERS (0) //Number of rotor sliders
/*----------------------------------------------------------------------------
* Self Cap method aquisition parameters.
*
*
*----------------------------------------------------------------------------*/
/**
* Self Cap filter level setting.
* The filter level setting controls the number of samples taken
* to resolve each acquisition. A higher filter level setting provides
* improved signal to noise ratio under noisy conditions, while
* increasing the total time for measurement resulting in increased
* power consumption and response time. Refer filter_level_t in
*touch_api_ptc.h
* Range: FILTER_LEVEL_1 (one sample) to FILTER_LEVEL_64 ( 64 samples).
*/
#define DEF_SELFCAP_FILTER_LEVEL_PER_NODE FILTER_LEVEL_16,FILTER_LEVEL_16,FILTER_LEVEL_16,FILTER_LEVEL_16,FILTER_LEVEL_16,FILTER_LEVEL_16,FILTER_LEVEL_16,FILTER_LEVEL_16
/*
* SelfCap Auto OS function can be enabled/disabled
* 1u = Self cap Auto OS functionality is enabled
* 0u = Self Auto OS functionality is disabled
*/
#define DEF_SELFCAP_AUTO_OS_ENABLE 0u
/**
* Self Cap auto oversample setting.
* Auto oversample controls the automatic oversampling of sensor channels when
* unstable signals are detected with the default setting of ?Filter level?.
* Enabling Auto oversample results in 'Filter level' x 'Auto Oversample' number
* of samples taken on the corresponding sensor channel when an unstable signal
* is observed. In a case where ?Filter level? is set to FILTER_LEVEL_4 and
* ?Auto Oversample? is set to AUTO_OS_4, 4 oversamples are taken with stable
* signal values and 16 oversamples are taken when unstable signal is detected.
* Refer auto_os_t in touch_api_ptc.h
* Range: 0 to 7
0 --> AUTO_OS_DISABLE, 1 --> AUTO_OS_2,
2 --> AUTO_OS_4, 3 --> AUTO_OS_8,
4 --> AUTO_OS_16, 5 --> AUTO_OS_32,
6 --> AUTO_OS_64, 7 --> AUTO_OS_128
*/
#define DEF_SELFCAP_AUTO_OS_PER_NODE AUTO_OS_DISABLE,AUTO_OS_DISABLE,AUTO_OS_DISABLE,AUTO_OS_DISABLE,AUTO_OS_DISABLE,AUTO_OS_DISABLE,AUTO_OS_DISABLE,AUTO_OS_DISABLE
/**
* Stability limit is the variance in sensor signal value under noisy environment.
* The signal stability limit level is set to auto trigger oversamples on noise presence.
* It is recommended to keep this setting close to the lowest sensor detect threshold of
* the system and tune it further based on the noise.
* Range: 1 to 1000
*/
#define DEF_SELFCAP_AUTO_OS_SIGNAL_STABILITY_LIMIT 20
/**
* Self Cap gain per touch channel.
* Gain is applied on a per-channel basis to allow a scaling-up of the touch
* sensitivity on contact.
* Note: delta on touch contact, not the resting signal which is measured on
* each sensor.
* Refer gain_t in touch_api_ptc.h
* Range:GAIN_1 (no scaling) to GAIN_32 (scale-up by 32)
*/
#define DEF_SELFCAP_GAIN_PER_NODE GAIN_1,GAIN_1,GAIN_1,GAIN_1,GAIN_1,GAIN_1,GAIN_1,GAIN_1
/*----------------------------------------------------------------------------
* Tuning for Noise performance, touch response time and Power consumption.
*
*
*----------------------------------------------------------------------------*/
/**
* Refer QTouch Library Peripheral Touch Controller User Guide for detailed
* information on tuning for Noise performance, touch response time and Power
* consumption
*/
/**
* For best noise performance, set -
* - DEF_SELFCAP_FREQ_MODE to FREQ_MODE_HOP
* - DEF_SELFCAP_SENSE_RESISTOR to RSEL_VAL_100
* - use AUTO_TUNE_PRSC input to touch_xxcap_sensors_calibrate() API in touch.c
* Based on the type of noise, FREQ_MODE_SPREAD or FREQ_MODE_SPREAD_MEDIAN can
* also be used.
*
* For best power consumption, set -
* - DEF_SELFCAP_FREQ_MODE to FREQ_MODE_NONE
* - DEF_SELFCAP_CLK_PRESCALE to PRSC_DIV_SEL_1
* - use AUTO_TUNE_RSEL input to touch_xxcap_sensors_calibrate() API in touch.c
*
*/
/**
* Self Cap acquisition frequency mode.
*
* FREQ_MODE_HOP:
* When frequency mode hopping option is selected, the PTC runs a
* frequency hopping cycle with subsequent measurements done using
* the three PTC acquisition frequency delay settings as specified in
* DEF_SELFCAP_HOP_FREQS.
*
* FREQ_MODE_SPREAD:
* When frequency mode spread spectrum option is selected, the PTC
* runs with spread spectrum enabled for jittered delay based
* acquisition.
*
* FREQ_MODE_SPREAD_MEDIAN:
* When frequency mode spread spectrum median option is selected,
* the PTC runs with spread spectrum enabled. In this case, an
* additional software median filter is applied to the measured
* signal values.
*
* FREQ_MODE_NONE:
* When frequency mode none option is selected, the PTC runs at
* constant speed. This mode is suited for best power consumption.
*/
#define DEF_SELFCAP_FREQ_MODE FREQ_MODE_NONE
/**
* PTC acquisition frequency delay setting.
*
* Specify three frequency hop delay settings.
*
* The PTC acquisition frequency is dependent on the Generic clock
* input to PTC and PTC clock pre-scaler setting. This delay setting
* inserts "n" PTC clock cycles between consecutive measurements on
* a given sensor, thereby changing the PTC acquisition frequency.
* FREQ_HOP_SEL_1 setting inserts 0 PTC clock cycle between consecutive
* measurements. FREQ_HOP_SEL_16 setting inserts 15 PTC clock cycles.
* Hence, higher delay setting will increase the total time taken for
* capacitance measurement on a given sensor as compared to a lower
* delay setting.
*
* A desired setting can be used to avoid noise around the same frequency
* as the acquisition frequency.
* Range: FREQ_HOP_SEL_1 to FREQ_HOP_SEL_16
*/
#define DEF_SELFCAP_HOP_FREQS FREQ_HOP_SEL_1,FREQ_HOP_SEL_2,FREQ_HOP_SEL_3
/**
* Self cap PTC clock pre-scalar.
* PTC clock prescale setting. Refer touch_configure_ptc_clock() API in
*touch.c
* Example: if Generic clock input to PTC = 4MHz, then:
* PRSC_DIV_SEL_1 sets PTC Clock to 4MHz
* PRSC_DIV_SEL_2 sets PTC Clock to 2MHz
* PRSC_DIV_SEL_4 sets PTC Clock to 1MHz
* PRSC_DIV_SEL_8 sets PTC Clock to 500KHz
*/
#define DEF_SELFCAP_CLK_PRESCALE_PER_NODE PRSC_DIV_SEL_1,PRSC_DIV_SEL_1,PRSC_DIV_SEL_1,PRSC_DIV_SEL_1,PRSC_DIV_SEL_1,PRSC_DIV_SEL_1,PRSC_DIV_SEL_1,PRSC_DIV_SEL_1
/**
* PTC series resistor setting. For Mutual cap mode, this series
* resistor is switched internally on the Y-pin. For Self cap mode,
* the series resistor is switched internally on the Sensor pin.
*
* Example:
* RSEL_VAL_0 sets internal series resistor to 0ohms.
* RSEL_VAL_20 sets internal series resistor to 20Kohms.
* RSEL_VAL_50 sets internal series resistor to 50Kohms.
* RSEL_VAL_100 sets internal series resistor to 100Kohms.
*/
#define DEF_SELFCAP_SENSE_RESISTOR_PER_NODE
/**
This is the default auto tune mode selection.
This is used in the AUTO calibration routine,
The allowed values are 0 to 2
0 --> DEF_AUTO_TUNE_NONE if Auto tune is not required
1 --> DEF_AUTO_TUNE_PRSC if the Pre-scaler needs to be tuned
2 --> DEF_AUTO_TUNE_RSEL if the Series resistor needs to be tuned
3 --> DEF_AUTO_TUNE_CSD this is available only in C2x devices,
DEF_AUTO_TUNE_CSD tunes internal Charge sharing delay for proper charge transfer
*/
#define DEF_SELF_AUTO_TUNE_VALUE 2
/*----------------------------------------------------------------------------
* Self Cap method sensor global parameters.
*
*
*----------------------------------------------------------------------------*/
/*! \name Self Cap Global acquisition parameters.
* Refer the Touch Library User guide for more information on these parameters.
*/
/* ! @{ */
/**
* Self Cap Sensor measurement interval.
* Speicify period in milliseconds. Example, DEF_TOUCH_MEASUREMENT_PERIOD_MS
*50u
* will perform measurement on touch sensors every 50msec.
*/
#define DEF_TOUCH_MEASUREMENT_PERIOD_MS 20u
/**
* Self Cap Sensor detect integration (DI) limit.
* Range: 0u to 255u.
*/
#define DEF_SELFCAP_DI 4u
/**
* Self Cap Sensor towards touch drift rate.
* Units: 200ms
* Default value: 20 = 4 seconds.
* Range: 1u to 127u.
*/
#define DEF_SELFCAP_TCH_DRIFT_RATE 20u
/**
* Self Cap Sensor away from touch drift rate.
* Units: 200ms
* Default value: 5u = 1 second.
* Range: 1u to 127u.
*/
#define DEF_SELFCAP_ATCH_DRIFT_RATE 5u
/**
* Self Cap Sensor maximum ON time duration.
* Units: 200ms (Example: a value 5u indicated Max ON duration of 1 second.)
* Default value: 0 (No maximum ON time limit).
* Range: 0u to 255u.
*/
#define DEF_SELFCAP_MAX_ON_DURATION 0u
/**
* Self Cap Sensor drift hold time.
* Units: 200ms
* Default value: 20 (hold off drifting for 4 seconds after leaving detect).
* Range: 1u to 255u.
*/
#define DEF_SELFCAP_DRIFT_HOLD_TIME 20u
/**
* Self Cap Sensor away from touch recalibration delay.
* Default value: 10.
* Range: 0u to 255u.
*/
#define DEF_SELFCAP_ATCH_RECAL_DELAY 10u
/** Self Cap Sensor away from touch recalibration threshold.
* Default: RECAL_50 (recalibration threshold = 50% of detection threshold).
* Range: refer recal_threshold_t enum in touch_api_ptc.h.
*/
#define DEF_SELFCAP_ATCH_RECAL_THRESHOLD 0u
/** Self Cap Sensor post-processing mode.
* Default: TOUCH_LIBRARY_DRIVEN.
* Range: TOUCH_LIBRARY_DRIVEN or TOUCH_APPLN_DRIVEN refer in touch_api_ptc.h.
*/
#define DEF_SELFCAP_TOUCH_POSTPROCESS_MODE TOUCH_APPLN_DRIVEN
/* ! @} */
/*----------------------------------------------------------------------------
* Self Cap method moisture detection feature parameters.
*
*
*----------------------------------------------------------------------------*/
/*! \name Mutual Cap method moisture feature parameters.
* Refer the Touch Library User guide for more information on these parameters.
*/
/* ! @{ */
/**
* Enable or disable moisture detection feature.
*/
#define DEF_SELFCAP_MOIS_TOLERANCE_ENABLE (0u)
/**
* Enable or disable quick re-burst feature within a given moisture group.
* When enabled, if within a given moisture group, when any sensor is touched,
* repeated measurements are done only that sensor to resolve detect integration or de-bounce.
* When disabled, if within a given moisture group, when any sensor is touched, repeated measurements are done
* on all sensors within the moisture group to resolve detect integration or de-bounce.
* It is recommended to enable this feature for best touch response time.
*/
#define DEF_SELFCAP_MOIS_QUICK_REBURST_ENABLE (1u)
/**
* Self cap number of moisture groups
*/
#define DEF_SELFCAP_NUM_MOIS_GROUPS (0u)
/**State of the Self Cap PTC pins.
* Default: GND_WHEN_NOT_MEASURED (PTC pins are pulled to GND when they are not bursted).
* Range: ptc_gpio_state_t enum in touch_api_ptc.h.
*/
#define DEF_SELFCAP_PTC_GPIO_STATE (PULLHIGH_WHEN_NOT_MEASURED)
/* ! @} */
/*
* AKS grouping function can be enabled/disabled
* 1u = AKS grouping functionality is enabled
* 0u = AKS grouping functionality is disabled
*/
#define DEF_SELFCAP_AKS_ENABLE (0u)
/*
* Charge share delay indicates the number of additional charge cycles that are inserted within a capacitance measurement cycle
* to ensure full charging of the touch sensor.
* The CSD value is dependent on the sensor capacitance along with the series resistor on the Y line.
* When manual tuning is done, the CSD value for the sensor with largest combination of capacitance along with series resistance
* should be considered.
* allowed Range 0-255
*/
#define DEF_SELF_CAP_CSD_VALUE 0
/*----------------------------------------------------------------------------
* Self Cap method noise measurement & lockout.
*
*
*----------------------------------------------------------------------------*/
/*! \name Self Cap Global acquisition parameters.
* Refer the Touch Library User guide for more information on these parameters.
*/
/* ! @{ */
/**
* Noise measurement enable/disable
* If configured as 1, noise measurement will be enabled
* If configured as 0, noise measurement will be disabled
*/
#define DEF_SELFCAP_NOISE_MEAS_ENABLE (0u)
/**
* Stability limit is the variance in sensor signal value under noisy environment.
* Any noise level over and above the noise signal stability limit contributes to the Noise limit.
* It is recommended to keep this setting close to the lowest sensor detect threshold of
* the system and tune it further based on the noise.
* Range: 1 to 1000
*/
#define DEF_SELFCAP_NOISE_MEAS_SIGNAL_STABILITY_LIMIT 10u
/**
* The noise limit specifies the limit to the total noise accumulated over the noise buffer count.
* If the accumulated noise exceeds the noise limit, then lockout is triggered.
* Range: 1 to 255
*/
#define DEF_SELFCAP_NOISE_LIMIT 12u
/**
* Noise buffer count
* Selection of buffer count for noise calculation.
* Defines the buffer limit for internal noise measurement
* Range: 3 to 10 (select value N + 1, here N nmber of samples)
* if N = 4 then set DEF_NM_BUFFER_CNT 5u ->> (N + 1).
* Default : 5u
*/
#define DEF_SELFCAP_NOISE_MEAS_BUFFER_CNT (5u)
/**
* Mutual cap method : noisy Sensor lockout settings.
* 0u: single sensor lockout.
* 1u: Global sensor lockout.
* 2u : No lockout
* Range : 0 to 2
*/
#define DEF_SELFCAP_LOCKOUT_SEL 0
/**
* Mutual cap Lockout count down
* If the sensor signal is moves from noisy to a good condition and stays there
* for a count value higher than the max count defined by user, sensor is
*declared as stable
* Range: 1 to 255
*/
#define DEF_SELFCAP_LOCKOUT_CNTDOWN 10
/* ! @} */
/*----------------------------------------------------------------------------
* Self Cap method Frequency auto tune.
*
*
*----------------------------------------------------------------------------*/
/*! \name Self Cap Global acquisition parameters.
* Refer the Touch Library User guide for more information on these parameters.
*/
/* ! @{ */
/**
* Freq auto tune enable/disable ( applicable only to freq_hop mode)
* If configured as 1, Freq auto tune will be enabled
* If configured as 0, Freq auto tune will be disabled
*/
#define DEF_SELFCAP_FREQ_AUTO_TUNE_ENABLE (0u)
/**
* Stability limit is the variance in sensor signal value under noisy environment.
* A signal stability limit level is set to auto tune acquisition frequency on noise presence.
* It is recommended to keep this setting close to the lowest sensor detect threshold of the system
* and tune it further based on the noise.
* Range: 1 to 1000
*/
#define DEF_SELFCAP_FREQ_AUTO_TUNE_SIGNAL_STABILITY_LIMIT 10u
/**
* Frequency Auto tune-in count
* If the channel signal is noisy for a count value higher than the max count
*defined by user,
* system will trigger auto tune
* Range: 1 to 255
* Note : this appies only for FREQ_MODE_HOP
*/
#define DEF_SELFCAP_FREQ_AUTO_TUNE_IN_CNT 12
/* ! @} */
/*----------------------------------------------------------------------------
* Self Cap Callback functions.
*
*
*----------------------------------------------------------------------------*/
/*! \name Self Cap Callback functions.
*/
/* ! @{ */
/**
* Self Cap Filter callback function.
* A filter callback (when not NULL) is called by the Touch Library each time
* a new set of Signal values are available.
* An Example filter callback function prototype.
* void touch_filter_callback( touch_filter_data_t *p_filter_data );
*/
#define DEF_SELFCAP_FILTER_CALLBACK (NULL)
/**
* Touch Application Error Handler Enable or Disable; while(1) is used to trap errors when it is enabled
* If configured as 1, Touch Application Error Handler will be enabled
* If configured as 0, Touch Application Error Handler will be disabled
* Default: Touch Application Error Handler will be disabled
*/
#define DEF_TOUCH_APP_ERR_HANDLER 0
/* ! @} */
/*----------------------------------------------------------------------------
* QDebug debug communication parameters.
*
*
*----------------------------------------------------------------------------*/
/*! \name QDebug debug communication parameters.
*/
/* ! @{ */
#define DEF_TOUCH_QDEBUG_ENABLE_SELFCAP
#define DEF_TOUCH_QDEBUG_ENABLE 0u
/* ! @} */
#endif /* TOUCH_CONFIG_SAMD_H */

View File

@ -0,0 +1,613 @@
/* This source file is part of the ATMEL QTouch Library 5.0.8 */
/*****************************************************************************
*
* \file
*
* \brief This file contains the SAMD QTouch Library pin, register and
* sensors configuration options for Capacitive Touch acquisition using
* the PTC module.
*
*
* - Userguide: QTouch Library Peripheral Touch Controller User Guide.
* - Support email: www.atmel.com/design-support/
*
*
* Copyright (c) 2013-2015 Atmel Corporation. All rights reserved.
*
* \asf_license_start
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name of Atmel may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 4. This software may only be redistributed and used in connection with an
* Atmel microcontroller product.
*
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* \asf_license_stop
*
******************************************************************************/
#ifndef TOUCH_CONFIG_SAMD_H
#define TOUCH_CONFIG_SAMD_H
/*----------------------------------------------------------------------------
* Self Cap method enable/disable.
*
*
*----------------------------------------------------------------------------*/
/**
* Enable/Disable Self/Mutual Capacitance method.
*/
#define DEF_TOUCH_SELFCAP (1)
#define DEF_TOUCH_MUTLCAP (0)
/*----------------------------------------------------------------------------
* PTC module clock and interrupt level configuration.
*
*
*----------------------------------------------------------------------------*/
/**
* PTC Module clock configuration.
* Before using the QTouch library API, the PTC module clock generator source
* should be configured appropriately. The PTC module clock can be generated
* using any of the eight generic clock generators (GCLK0-GCLK7). The
*associated
* generic clock multiplexer should be configured such that the PTC module clock
* is set to 4MHz. Refer touch_configure_ptc_clock API in touch.c for more
* information.
*/
/**
* PTC Module interrupt level.
* The Nested Vectored Interrupt Controller (NVIC) in the SAMD supports
* four different priority levels. The priority level of the PTC end of
* conversion ISR, used within QTouch library can be chosen based on application
* requirements in order to accommodate time critical operations.
* Range: 0u (Highest priority) to 3u (Lowest prioirity)
* For more details refer to the Cortex-M0 Technical Reference Manual.
*/
#define DEF_TOUCH_PTC_ISR_LVL (2u)
/*----------------------------------------------------------------------------
* Self Cap method pin configuration.
*
*
*----------------------------------------------------------------------------*/
/**
* Self Cap touch channel selected.
* The capacitance measurement is done sequentially in the order in which
* the touch channel (nodes) are specified below. Touch channel numbering
* follows the order in which Y lines are specified. Capacitance measurement
* is done sequentially in the order in which touch channel nodes are specified.
*/
#define DEF_SELFCAP_LINES Y(0),Y(2),Y(3),Y(8),Y(14),Y(15)
/*----------------------------------------------------------------------------
* Self Cap method channel and sensor configuration.
*
*
*----------------------------------------------------------------------------*/
/**
* Self Cap number of channels.
* Specify the number of Self Cap touch channels to be used by the Touch
*Library.
* A key is formed used one touch channel. A rotor or slider can be formed
* using 3 touch channels.
* Range: 1u to 16u.
*/
#define DEF_SELFCAP_NUM_CHANNELS (6) //Total number of channels
/**
* Self Cap number of Sensors.
* Specify the number of Self Cap touch sensors to be used by the Touch Library.
* A sensor is either a key, rotor or slider.
* Example configuration: If the configuration has 6 keys (a key is formed
* using one Sensor Pin), one rotor (a Self Cap rotor is formed using 3 Sensor
* Pins) and one slider (a Self Cap slider is formed using 3 Sensor Pins), then
* the number of sensors is 6 key + 1 rotor + 1 slider = 8 sensors.
* Range: 1u to 16u.
*/
#define DEF_SELFCAP_NUM_SENSORS (6) //Total number of sensors
/**
* Self Cap number of Rotors and Sliders.
* Specify the total number of Self Cap Rotors and Sliders to be used by
* the Touch Library. The number of Rotors and Sliders mentioned here is part
* of
* the Total number of sensors specified in the QT_NUM_SENSORS macro. When
* no rotors or slider are required, specify a value of 0u.
* Range: 0u to 8u.
*/
#define DEF_SELFCAP_NUM_ROTORS_SLIDERS (0) //Number of rotor sliders
/*----------------------------------------------------------------------------
* Self Cap method aquisition parameters.
*
*
*----------------------------------------------------------------------------*/
/**
* Self Cap filter level setting.
* The filter level setting controls the number of samples taken
* to resolve each acquisition. A higher filter level setting provides
* improved signal to noise ratio under noisy conditions, while
* increasing the total time for measurement resulting in increased
* power consumption and response time. Refer filter_level_t in
*touch_api_ptc.h
* Range: FILTER_LEVEL_1 (one sample) to FILTER_LEVEL_64 ( 64 samples).
*/
#define DEF_SELFCAP_FILTER_LEVEL_PER_NODE FILTER_LEVEL_16,FILTER_LEVEL_16,FILTER_LEVEL_16,FILTER_LEVEL_16,FILTER_LEVEL_16,FILTER_LEVEL_16
/*
* SelfCap Auto OS function can be enabled/disabled
* 1u = Self cap Auto OS functionality is enabled
* 0u = Self Auto OS functionality is disabled
*/
#define DEF_SELFCAP_AUTO_OS_ENABLE 0u
/**
* Self Cap auto oversample setting.
* Auto oversample controls the automatic oversampling of sensor channels when
* unstable signals are detected with the default setting of ?Filter level?.
* Enabling Auto oversample results in 'Filter level' x 'Auto Oversample' number
* of samples taken on the corresponding sensor channel when an unstable signal
* is observed. In a case where ?Filter level? is set to FILTER_LEVEL_4 and
* ?Auto Oversample? is set to AUTO_OS_4, 4 oversamples are taken with stable
* signal values and 16 oversamples are taken when unstable signal is detected.
* Refer auto_os_t in touch_api_ptc.h
* Range: 0 to 7
0 --> AUTO_OS_DISABLE, 1 --> AUTO_OS_2,
2 --> AUTO_OS_4, 3 --> AUTO_OS_8,
4 --> AUTO_OS_16, 5 --> AUTO_OS_32,
6 --> AUTO_OS_64, 7 --> AUTO_OS_128
*/
#define DEF_SELFCAP_AUTO_OS_PER_NODE AUTO_OS_DISABLE,AUTO_OS_DISABLE,AUTO_OS_DISABLE,AUTO_OS_DISABLE,AUTO_OS_DISABLE,AUTO_OS_DISABLE
/**
* Stability limit is the variance in sensor signal value under noisy environment.
* The signal stability limit level is set to auto trigger oversamples on noise presence.
* It is recommended to keep this setting close to the lowest sensor detect threshold of
* the system and tune it further based on the noise.
* Range: 1 to 1000
*/
#define DEF_SELFCAP_AUTO_OS_SIGNAL_STABILITY_LIMIT 20
/**
* Self Cap gain per touch channel.
* Gain is applied on a per-channel basis to allow a scaling-up of the touch
* sensitivity on contact.
* Note: delta on touch contact, not the resting signal which is measured on
* each sensor.
* Refer gain_t in touch_api_ptc.h
* Range:GAIN_1 (no scaling) to GAIN_32 (scale-up by 32)
*/
#define DEF_SELFCAP_GAIN_PER_NODE GAIN_1,GAIN_1,GAIN_1,GAIN_1,GAIN_1,GAIN_1
/*----------------------------------------------------------------------------
* Tuning for Noise performance, touch response time and Power consumption.
*
*
*----------------------------------------------------------------------------*/
/**
* Refer QTouch Library Peripheral Touch Controller User Guide for detailed
* information on tuning for Noise performance, touch response time and Power
* consumption
*/
/**
* For best noise performance, set -
* - DEF_SELFCAP_FREQ_MODE to FREQ_MODE_HOP
* - DEF_SELFCAP_SENSE_RESISTOR to RSEL_VAL_100
* - use AUTO_TUNE_PRSC input to touch_xxcap_sensors_calibrate() API in touch.c
* Based on the type of noise, FREQ_MODE_SPREAD or FREQ_MODE_SPREAD_MEDIAN can
* also be used.
*
* For best power consumption, set -
* - DEF_SELFCAP_FREQ_MODE to FREQ_MODE_NONE
* - DEF_SELFCAP_CLK_PRESCALE to PRSC_DIV_SEL_1
* - use AUTO_TUNE_RSEL input to touch_xxcap_sensors_calibrate() API in touch.c
*
*/
/**
* Self Cap acquisition frequency mode.
*
* FREQ_MODE_HOP:
* When frequency mode hopping option is selected, the PTC runs a
* frequency hopping cycle with subsequent measurements done using
* the three PTC acquisition frequency delay settings as specified in
* DEF_SELFCAP_HOP_FREQS.
*
* FREQ_MODE_SPREAD:
* When frequency mode spread spectrum option is selected, the PTC
* runs with spread spectrum enabled for jittered delay based
* acquisition.
*
* FREQ_MODE_SPREAD_MEDIAN:
* When frequency mode spread spectrum median option is selected,
* the PTC runs with spread spectrum enabled. In this case, an
* additional software median filter is applied to the measured
* signal values.
*
* FREQ_MODE_NONE:
* When frequency mode none option is selected, the PTC runs at
* constant speed. This mode is suited for best power consumption.
*/
#define DEF_SELFCAP_FREQ_MODE FREQ_MODE_NONE
/**
* PTC acquisition frequency delay setting.
*
* Specify three frequency hop delay settings.
*
* The PTC acquisition frequency is dependent on the Generic clock
* input to PTC and PTC clock pre-scaler setting. This delay setting
* inserts "n" PTC clock cycles between consecutive measurements on
* a given sensor, thereby changing the PTC acquisition frequency.
* FREQ_HOP_SEL_1 setting inserts 0 PTC clock cycle between consecutive
* measurements. FREQ_HOP_SEL_16 setting inserts 15 PTC clock cycles.
* Hence, higher delay setting will increase the total time taken for
* capacitance measurement on a given sensor as compared to a lower
* delay setting.
*
* A desired setting can be used to avoid noise around the same frequency
* as the acquisition frequency.
* Range: FREQ_HOP_SEL_1 to FREQ_HOP_SEL_16
*/
#define DEF_SELFCAP_HOP_FREQS FREQ_HOP_SEL_1,FREQ_HOP_SEL_2,FREQ_HOP_SEL_3
/**
* Self cap PTC clock pre-scalar.
* PTC clock prescale setting. Refer touch_configure_ptc_clock() API in
*touch.c
* Example: if Generic clock input to PTC = 4MHz, then:
* PRSC_DIV_SEL_1 sets PTC Clock to 4MHz
* PRSC_DIV_SEL_2 sets PTC Clock to 2MHz
* PRSC_DIV_SEL_4 sets PTC Clock to 1MHz
* PRSC_DIV_SEL_8 sets PTC Clock to 500KHz
*/
#define DEF_SELFCAP_CLK_PRESCALE_PER_NODE PRSC_DIV_SEL_1,PRSC_DIV_SEL_1,PRSC_DIV_SEL_1,PRSC_DIV_SEL_1,PRSC_DIV_SEL_1,PRSC_DIV_SEL_1
/**
* PTC series resistor setting. For Mutual cap mode, this series
* resistor is switched internally on the Y-pin. For Self cap mode,
* the series resistor is switched internally on the Sensor pin.
*
* Example:
* RSEL_VAL_0 sets internal series resistor to 0ohms.
* RSEL_VAL_20 sets internal series resistor to 20Kohms.
* RSEL_VAL_50 sets internal series resistor to 50Kohms.
* RSEL_VAL_100 sets internal series resistor to 100Kohms.
*/
#define DEF_SELFCAP_SENSE_RESISTOR_PER_NODE RSEL_VAL_0,RSEL_VAL_0,RSEL_VAL_0,RSEL_VAL_0,RSEL_VAL_0,RSEL_VAL_0
/**
This is the default auto tune mode selection.
This is used in the AUTO calibration routine,
The allowed values are 0 to 2
0 --> DEF_AUTO_TUNE_NONE if Auto tune is not required
1 --> DEF_AUTO_TUNE_PRSC if the Pre-scaler needs to be tuned
2 --> DEF_AUTO_TUNE_RSEL if the Series resistor needs to be tuned
3 --> DEF_AUTO_TUNE_CSD this is available only in C2x devices,
DEF_AUTO_TUNE_CSD tunes internal Charge sharing delay for proper charge transfer
*/
#define DEF_SELF_AUTO_TUNE_VALUE 2
/*----------------------------------------------------------------------------
* Self Cap method sensor global parameters.
*
*
*----------------------------------------------------------------------------*/
/*! \name Self Cap Global acquisition parameters.
* Refer the Touch Library User guide for more information on these parameters.
*/
/* ! @{ */
/**
* Self Cap Sensor measurement interval.
* Speicify period in milliseconds. Example, DEF_TOUCH_MEASUREMENT_PERIOD_MS
*50u
* will perform measurement on touch sensors every 50msec.
*/
#define DEF_TOUCH_MEASUREMENT_PERIOD_MS 20u
/**
* Self Cap Sensor detect integration (DI) limit.
* Range: 0u to 255u.
*/
#define DEF_SELFCAP_DI 4u
/**
* Self Cap Sensor towards touch drift rate.
* Units: 200ms
* Default value: 20 = 4 seconds.
* Range: 1u to 127u.
*/
#define DEF_SELFCAP_TCH_DRIFT_RATE 20u
/**
* Self Cap Sensor away from touch drift rate.
* Units: 200ms
* Default value: 5u = 1 second.
* Range: 1u to 127u.
*/
#define DEF_SELFCAP_ATCH_DRIFT_RATE 5u
/**
* Self Cap Sensor maximum ON time duration.
* Units: 200ms (Example: a value 5u indicated Max ON duration of 1 second.)
* Default value: 0 (No maximum ON time limit).
* Range: 0u to 255u.
*/
#define DEF_SELFCAP_MAX_ON_DURATION 0u
/**
* Self Cap Sensor drift hold time.
* Units: 200ms
* Default value: 20 (hold off drifting for 4 seconds after leaving detect).
* Range: 1u to 255u.
*/
#define DEF_SELFCAP_DRIFT_HOLD_TIME 20u
/**
* Self Cap Sensor away from touch recalibration delay.
* Default value: 10.
* Range: 0u to 255u.
*/
#define DEF_SELFCAP_ATCH_RECAL_DELAY 10u
/** Self Cap Sensor away from touch recalibration threshold.
* Default: RECAL_50 (recalibration threshold = 50% of detection threshold).
* Range: refer recal_threshold_t enum in touch_api_ptc.h.
*/
#define DEF_SELFCAP_ATCH_RECAL_THRESHOLD 0u
/** Self Cap Sensor post-processing mode.
* Default: TOUCH_LIBRARY_DRIVEN.
* Range: TOUCH_LIBRARY_DRIVEN or TOUCH_APPLN_DRIVEN refer in touch_api_ptc.h.
*/
#define DEF_SELFCAP_TOUCH_POSTPROCESS_MODE TOUCH_APPLN_DRIVEN
/* ! @} */
/*----------------------------------------------------------------------------
* Self Cap method moisture detection feature parameters.
*
*
*----------------------------------------------------------------------------*/
/*! \name Mutual Cap method moisture feature parameters.
* Refer the Touch Library User guide for more information on these parameters.
*/
/* ! @{ */
/**
* Enable or disable moisture detection feature.
*/
#define DEF_SELFCAP_MOIS_TOLERANCE_ENABLE (0u)
/**
* Enable or disable quick re-burst feature within a given moisture group.
* When enabled, if within a given moisture group, when any sensor is touched,
* repeated measurements are done only that sensor to resolve detect integration or de-bounce.
* When disabled, if within a given moisture group, when any sensor is touched, repeated measurements are done
* on all sensors within the moisture group to resolve detect integration or de-bounce.
* It is recommended to enable this feature for best touch response time.
*/
#define DEF_SELFCAP_MOIS_QUICK_REBURST_ENABLE (1u)
/**
* Self cap number of moisture groups
*/
#define DEF_SELFCAP_NUM_MOIS_GROUPS (0u)
/**State of the Self Cap PTC pins.
* Default: GND_WHEN_NOT_MEASURED (PTC pins are pulled to GND when they are not bursted).
* Range: ptc_gpio_state_t enum in touch_api_ptc.h.
*/
#define DEF_SELFCAP_PTC_GPIO_STATE (PULLHIGH_WHEN_NOT_MEASURED)
/* ! @} */
/*
* AKS grouping function can be enabled/disabled
* 1u = AKS grouping functionality is enabled
* 0u = AKS grouping functionality is disabled
*/
#define DEF_SELFCAP_AKS_ENABLE (0u)
/*
* Charge share delay indicates the number of additional charge cycles that are inserted within a capacitance measurement cycle
* to ensure full charging of the touch sensor.
* The CSD value is dependent on the sensor capacitance along with the series resistor on the Y line.
* When manual tuning is done, the CSD value for the sensor with largest combination of capacitance along with series resistance
* should be considered.
* allowed Range 0-255
*/
#define DEF_SELF_CAP_CSD_VALUE 0
/*----------------------------------------------------------------------------
* Self Cap method noise measurement & lockout.
*
*
*----------------------------------------------------------------------------*/
/*! \name Self Cap Global acquisition parameters.
* Refer the Touch Library User guide for more information on these parameters.
*/
/* ! @{ */
/**
* Noise measurement enable/disable
* If configured as 1, noise measurement will be enabled
* If configured as 0, noise measurement will be disabled
*/
#define DEF_SELFCAP_NOISE_MEAS_ENABLE (0u)
/**
* Stability limit is the variance in sensor signal value under noisy environment.
* Any noise level over and above the noise signal stability limit contributes to the Noise limit.
* It is recommended to keep this setting close to the lowest sensor detect threshold of
* the system and tune it further based on the noise.
* Range: 1 to 1000
*/
#define DEF_SELFCAP_NOISE_MEAS_SIGNAL_STABILITY_LIMIT 10u
/**
* The noise limit specifies the limit to the total noise accumulated over the noise buffer count.
* If the accumulated noise exceeds the noise limit, then lockout is triggered.
* Range: 1 to 255
*/
#define DEF_SELFCAP_NOISE_LIMIT 12u
/**
* Noise buffer count
* Selection of buffer count for noise calculation.
* Defines the buffer limit for internal noise measurement
* Range: 3 to 10 (select value N + 1, here N nmber of samples)
* if N = 4 then set DEF_NM_BUFFER_CNT 5u ->> (N + 1).
* Default : 5u
*/
#define DEF_SELFCAP_NOISE_MEAS_BUFFER_CNT (5u)
/**
* Mutual cap method : noisy Sensor lockout settings.
* 0u: single sensor lockout.
* 1u: Global sensor lockout.
* 2u : No lockout
* Range : 0 to 2
*/
#define DEF_SELFCAP_LOCKOUT_SEL 0
/**
* Mutual cap Lockout count down
* If the sensor signal is moves from noisy to a good condition and stays there
* for a count value higher than the max count defined by user, sensor is
*declared as stable
* Range: 1 to 255
*/
#define DEF_SELFCAP_LOCKOUT_CNTDOWN 10
/* ! @} */
/*----------------------------------------------------------------------------
* Self Cap method Frequency auto tune.
*
*
*----------------------------------------------------------------------------*/
/*! \name Self Cap Global acquisition parameters.
* Refer the Touch Library User guide for more information on these parameters.
*/
/* ! @{ */
/**
* Freq auto tune enable/disable ( applicable only to freq_hop mode)
* If configured as 1, Freq auto tune will be enabled
* If configured as 0, Freq auto tune will be disabled
*/
#define DEF_SELFCAP_FREQ_AUTO_TUNE_ENABLE (0u)
/**
* Stability limit is the variance in sensor signal value under noisy environment.
* A signal stability limit level is set to auto tune acquisition frequency on noise presence.
* It is recommended to keep this setting close to the lowest sensor detect threshold of the system
* and tune it further based on the noise.
* Range: 1 to 1000
*/
#define DEF_SELFCAP_FREQ_AUTO_TUNE_SIGNAL_STABILITY_LIMIT 10u
/**
* Frequency Auto tune-in count
* If the channel signal is noisy for a count value higher than the max count
*defined by user,
* system will trigger auto tune
* Range: 1 to 255
* Note : this appies only for FREQ_MODE_HOP
*/
#define DEF_SELFCAP_FREQ_AUTO_TUNE_IN_CNT 12
/* ! @} */
/*----------------------------------------------------------------------------
* Self Cap Callback functions.
*
*
*----------------------------------------------------------------------------*/
/*! \name Self Cap Callback functions.
*/
/* ! @{ */
/**
* Self Cap Filter callback function.
* A filter callback (when not NULL) is called by the Touch Library each time
* a new set of Signal values are available.
* An Example filter callback function prototype.
* void touch_filter_callback( touch_filter_data_t *p_filter_data );
*/
#define DEF_SELFCAP_FILTER_CALLBACK (NULL)
/**
* Touch Application Error Handler Enable or Disable; while(1) is used to trap errors when it is enabled
* If configured as 1, Touch Application Error Handler will be enabled
* If configured as 0, Touch Application Error Handler will be disabled
* Default: Touch Application Error Handler will be disabled
*/
#define DEF_TOUCH_APP_ERR_HANDLER 0
/* ! @} */
/*----------------------------------------------------------------------------
* QDebug debug communication parameters.
*
*
*----------------------------------------------------------------------------*/
/*! \name QDebug debug communication parameters.
*/
/* ! @{ */
#define DEF_TOUCH_QDEBUG_ENABLE_SELFCAP
#define DEF_TOUCH_QDEBUG_ENABLE 0u
/* ! @} */
#endif /* TOUCH_CONFIG_SAMD_H */

View File

@ -0,0 +1,613 @@
/* This source file is part of the ATMEL QTouch Library 5.0.8 */
/*****************************************************************************
*
* \file
*
* \brief This file contains the SAMD QTouch Library pin, register and
* sensors configuration options for Capacitive Touch acquisition using
* the PTC module.
*
*
* - Userguide: QTouch Library Peripheral Touch Controller User Guide.
* - Support email: www.atmel.com/design-support/
*
*
* Copyright (c) 2013-2015 Atmel Corporation. All rights reserved.
*
* \asf_license_start
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name of Atmel may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 4. This software may only be redistributed and used in connection with an
* Atmel microcontroller product.
*
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* \asf_license_stop
*
******************************************************************************/
#ifndef TOUCH_CONFIG_SAMD_H
#define TOUCH_CONFIG_SAMD_H
/*----------------------------------------------------------------------------
* Self Cap method enable/disable.
*
*
*----------------------------------------------------------------------------*/
/**
* Enable/Disable Self/Mutual Capacitance method.
*/
#define DEF_TOUCH_SELFCAP (1)
#define DEF_TOUCH_MUTLCAP (0)
/*----------------------------------------------------------------------------
* PTC module clock and interrupt level configuration.
*
*
*----------------------------------------------------------------------------*/
/**
* PTC Module clock configuration.
* Before using the QTouch library API, the PTC module clock generator source
* should be configured appropriately. The PTC module clock can be generated
* using any of the eight generic clock generators (GCLK0-GCLK7). The
*associated
* generic clock multiplexer should be configured such that the PTC module clock
* is set to 4MHz. Refer touch_configure_ptc_clock API in touch.c for more
* information.
*/
/**
* PTC Module interrupt level.
* The Nested Vectored Interrupt Controller (NVIC) in the SAMD supports
* four different priority levels. The priority level of the PTC end of
* conversion ISR, used within QTouch library can be chosen based on application
* requirements in order to accommodate time critical operations.
* Range: 0u (Highest priority) to 3u (Lowest prioirity)
* For more details refer to the Cortex-M0 Technical Reference Manual.
*/
#define DEF_TOUCH_PTC_ISR_LVL (2u)
/*----------------------------------------------------------------------------
* Self Cap method pin configuration.
*
*
*----------------------------------------------------------------------------*/
/**
* Self Cap touch channel selected.
* The capacitance measurement is done sequentially in the order in which
* the touch channel (nodes) are specified below. Touch channel numbering
* follows the order in which Y lines are specified. Capacitance measurement
* is done sequentially in the order in which touch channel nodes are specified.
*/
#define DEF_SELFCAP_LINES Y(0),Y(2),Y(3),Y(4),Y(5),Y(8),Y(14),Y(15)
/*----------------------------------------------------------------------------
* Self Cap method channel and sensor configuration.
*
*
*----------------------------------------------------------------------------*/
/**
* Self Cap number of channels.
* Specify the number of Self Cap touch channels to be used by the Touch
*Library.
* A key is formed used one touch channel. A rotor or slider can be formed
* using 3 touch channels.
* Range: 1u to 16u.
*/
#define DEF_SELFCAP_NUM_CHANNELS (8) //Total number of channels
/**
* Self Cap number of Sensors.
* Specify the number of Self Cap touch sensors to be used by the Touch Library.
* A sensor is either a key, rotor or slider.
* Example configuration: If the configuration has 6 keys (a key is formed
* using one Sensor Pin), one rotor (a Self Cap rotor is formed using 3 Sensor
* Pins) and one slider (a Self Cap slider is formed using 3 Sensor Pins), then
* the number of sensors is 6 key + 1 rotor + 1 slider = 8 sensors.
* Range: 1u to 16u.
*/
#define DEF_SELFCAP_NUM_SENSORS (8) //Total number of sensors
/**
* Self Cap number of Rotors and Sliders.
* Specify the total number of Self Cap Rotors and Sliders to be used by
* the Touch Library. The number of Rotors and Sliders mentioned here is part
* of
* the Total number of sensors specified in the QT_NUM_SENSORS macro. When
* no rotors or slider are required, specify a value of 0u.
* Range: 0u to 8u.
*/
#define DEF_SELFCAP_NUM_ROTORS_SLIDERS (0) //Number of rotor sliders
/*----------------------------------------------------------------------------
* Self Cap method aquisition parameters.
*
*
*----------------------------------------------------------------------------*/
/**
* Self Cap filter level setting.
* The filter level setting controls the number of samples taken
* to resolve each acquisition. A higher filter level setting provides
* improved signal to noise ratio under noisy conditions, while
* increasing the total time for measurement resulting in increased
* power consumption and response time. Refer filter_level_t in
*touch_api_ptc.h
* Range: FILTER_LEVEL_1 (one sample) to FILTER_LEVEL_64 ( 64 samples).
*/
#define DEF_SELFCAP_FILTER_LEVEL_PER_NODE FILTER_LEVEL_16,FILTER_LEVEL_16,FILTER_LEVEL_16,FILTER_LEVEL_16,FILTER_LEVEL_16,FILTER_LEVEL_16,FILTER_LEVEL_16,FILTER_LEVEL_16
/*
* SelfCap Auto OS function can be enabled/disabled
* 1u = Self cap Auto OS functionality is enabled
* 0u = Self Auto OS functionality is disabled
*/
#define DEF_SELFCAP_AUTO_OS_ENABLE 0u
/**
* Self Cap auto oversample setting.
* Auto oversample controls the automatic oversampling of sensor channels when
* unstable signals are detected with the default setting of ?Filter level?.
* Enabling Auto oversample results in 'Filter level' x 'Auto Oversample' number
* of samples taken on the corresponding sensor channel when an unstable signal
* is observed. In a case where ?Filter level? is set to FILTER_LEVEL_4 and
* ?Auto Oversample? is set to AUTO_OS_4, 4 oversamples are taken with stable
* signal values and 16 oversamples are taken when unstable signal is detected.
* Refer auto_os_t in touch_api_ptc.h
* Range: 0 to 7
0 --> AUTO_OS_DISABLE, 1 --> AUTO_OS_2,
2 --> AUTO_OS_4, 3 --> AUTO_OS_8,
4 --> AUTO_OS_16, 5 --> AUTO_OS_32,
6 --> AUTO_OS_64, 7 --> AUTO_OS_128
*/
#define DEF_SELFCAP_AUTO_OS_PER_NODE AUTO_OS_DISABLE,AUTO_OS_DISABLE,AUTO_OS_DISABLE,AUTO_OS_DISABLE,AUTO_OS_DISABLE,AUTO_OS_DISABLE,AUTO_OS_DISABLE,AUTO_OS_DISABLE
/**
* Stability limit is the variance in sensor signal value under noisy environment.
* The signal stability limit level is set to auto trigger oversamples on noise presence.
* It is recommended to keep this setting close to the lowest sensor detect threshold of
* the system and tune it further based on the noise.
* Range: 1 to 1000
*/
#define DEF_SELFCAP_AUTO_OS_SIGNAL_STABILITY_LIMIT 20
/**
* Self Cap gain per touch channel.
* Gain is applied on a per-channel basis to allow a scaling-up of the touch
* sensitivity on contact.
* Note: delta on touch contact, not the resting signal which is measured on
* each sensor.
* Refer gain_t in touch_api_ptc.h
* Range:GAIN_1 (no scaling) to GAIN_32 (scale-up by 32)
*/
#define DEF_SELFCAP_GAIN_PER_NODE GAIN_1,GAIN_1,GAIN_1,GAIN_1,GAIN_1,GAIN_1,GAIN_1,GAIN_1
/*----------------------------------------------------------------------------
* Tuning for Noise performance, touch response time and Power consumption.
*
*
*----------------------------------------------------------------------------*/
/**
* Refer QTouch Library Peripheral Touch Controller User Guide for detailed
* information on tuning for Noise performance, touch response time and Power
* consumption
*/
/**
* For best noise performance, set -
* - DEF_SELFCAP_FREQ_MODE to FREQ_MODE_HOP
* - DEF_SELFCAP_SENSE_RESISTOR to RSEL_VAL_100
* - use AUTO_TUNE_PRSC input to touch_xxcap_sensors_calibrate() API in touch.c
* Based on the type of noise, FREQ_MODE_SPREAD or FREQ_MODE_SPREAD_MEDIAN can
* also be used.
*
* For best power consumption, set -
* - DEF_SELFCAP_FREQ_MODE to FREQ_MODE_NONE
* - DEF_SELFCAP_CLK_PRESCALE to PRSC_DIV_SEL_1
* - use AUTO_TUNE_RSEL input to touch_xxcap_sensors_calibrate() API in touch.c
*
*/
/**
* Self Cap acquisition frequency mode.
*
* FREQ_MODE_HOP:
* When frequency mode hopping option is selected, the PTC runs a
* frequency hopping cycle with subsequent measurements done using
* the three PTC acquisition frequency delay settings as specified in
* DEF_SELFCAP_HOP_FREQS.
*
* FREQ_MODE_SPREAD:
* When frequency mode spread spectrum option is selected, the PTC
* runs with spread spectrum enabled for jittered delay based
* acquisition.
*
* FREQ_MODE_SPREAD_MEDIAN:
* When frequency mode spread spectrum median option is selected,
* the PTC runs with spread spectrum enabled. In this case, an
* additional software median filter is applied to the measured
* signal values.
*
* FREQ_MODE_NONE:
* When frequency mode none option is selected, the PTC runs at
* constant speed. This mode is suited for best power consumption.
*/
#define DEF_SELFCAP_FREQ_MODE FREQ_MODE_NONE
/**
* PTC acquisition frequency delay setting.
*
* Specify three frequency hop delay settings.
*
* The PTC acquisition frequency is dependent on the Generic clock
* input to PTC and PTC clock pre-scaler setting. This delay setting
* inserts "n" PTC clock cycles between consecutive measurements on
* a given sensor, thereby changing the PTC acquisition frequency.
* FREQ_HOP_SEL_1 setting inserts 0 PTC clock cycle between consecutive
* measurements. FREQ_HOP_SEL_16 setting inserts 15 PTC clock cycles.
* Hence, higher delay setting will increase the total time taken for
* capacitance measurement on a given sensor as compared to a lower
* delay setting.
*
* A desired setting can be used to avoid noise around the same frequency
* as the acquisition frequency.
* Range: FREQ_HOP_SEL_1 to FREQ_HOP_SEL_16
*/
#define DEF_SELFCAP_HOP_FREQS FREQ_HOP_SEL_1,FREQ_HOP_SEL_2,FREQ_HOP_SEL_3
/**
* Self cap PTC clock pre-scalar.
* PTC clock prescale setting. Refer touch_configure_ptc_clock() API in
*touch.c
* Example: if Generic clock input to PTC = 4MHz, then:
* PRSC_DIV_SEL_1 sets PTC Clock to 4MHz
* PRSC_DIV_SEL_2 sets PTC Clock to 2MHz
* PRSC_DIV_SEL_4 sets PTC Clock to 1MHz
* PRSC_DIV_SEL_8 sets PTC Clock to 500KHz
*/
#define DEF_SELFCAP_CLK_PRESCALE_PER_NODE PRSC_DIV_SEL_1,PRSC_DIV_SEL_1,PRSC_DIV_SEL_1,PRSC_DIV_SEL_1,PRSC_DIV_SEL_1,PRSC_DIV_SEL_1,PRSC_DIV_SEL_1,PRSC_DIV_SEL_1
/**
* PTC series resistor setting. For Mutual cap mode, this series
* resistor is switched internally on the Y-pin. For Self cap mode,
* the series resistor is switched internally on the Sensor pin.
*
* Example:
* RSEL_VAL_0 sets internal series resistor to 0ohms.
* RSEL_VAL_20 sets internal series resistor to 20Kohms.
* RSEL_VAL_50 sets internal series resistor to 50Kohms.
* RSEL_VAL_100 sets internal series resistor to 100Kohms.
*/
#define DEF_SELFCAP_SENSE_RESISTOR_PER_NODE
/**
This is the default auto tune mode selection.
This is used in the AUTO calibration routine,
The allowed values are 0 to 2
0 --> DEF_AUTO_TUNE_NONE if Auto tune is not required
1 --> DEF_AUTO_TUNE_PRSC if the Pre-scaler needs to be tuned
2 --> DEF_AUTO_TUNE_RSEL if the Series resistor needs to be tuned
3 --> DEF_AUTO_TUNE_CSD this is available only in C2x devices,
DEF_AUTO_TUNE_CSD tunes internal Charge sharing delay for proper charge transfer
*/
#define DEF_SELF_AUTO_TUNE_VALUE 2
/*----------------------------------------------------------------------------
* Self Cap method sensor global parameters.
*
*
*----------------------------------------------------------------------------*/
/*! \name Self Cap Global acquisition parameters.
* Refer the Touch Library User guide for more information on these parameters.
*/
/* ! @{ */
/**
* Self Cap Sensor measurement interval.
* Speicify period in milliseconds. Example, DEF_TOUCH_MEASUREMENT_PERIOD_MS
*50u
* will perform measurement on touch sensors every 50msec.
*/
#define DEF_TOUCH_MEASUREMENT_PERIOD_MS 20u
/**
* Self Cap Sensor detect integration (DI) limit.
* Range: 0u to 255u.
*/
#define DEF_SELFCAP_DI 4u
/**
* Self Cap Sensor towards touch drift rate.
* Units: 200ms
* Default value: 20 = 4 seconds.
* Range: 1u to 127u.
*/
#define DEF_SELFCAP_TCH_DRIFT_RATE 20u
/**
* Self Cap Sensor away from touch drift rate.
* Units: 200ms
* Default value: 5u = 1 second.
* Range: 1u to 127u.
*/
#define DEF_SELFCAP_ATCH_DRIFT_RATE 5u
/**
* Self Cap Sensor maximum ON time duration.
* Units: 200ms (Example: a value 5u indicated Max ON duration of 1 second.)
* Default value: 0 (No maximum ON time limit).
* Range: 0u to 255u.
*/
#define DEF_SELFCAP_MAX_ON_DURATION 0u
/**
* Self Cap Sensor drift hold time.
* Units: 200ms
* Default value: 20 (hold off drifting for 4 seconds after leaving detect).
* Range: 1u to 255u.
*/
#define DEF_SELFCAP_DRIFT_HOLD_TIME 20u
/**
* Self Cap Sensor away from touch recalibration delay.
* Default value: 10.
* Range: 0u to 255u.
*/
#define DEF_SELFCAP_ATCH_RECAL_DELAY 10u
/** Self Cap Sensor away from touch recalibration threshold.
* Default: RECAL_50 (recalibration threshold = 50% of detection threshold).
* Range: refer recal_threshold_t enum in touch_api_ptc.h.
*/
#define DEF_SELFCAP_ATCH_RECAL_THRESHOLD 0u
/** Self Cap Sensor post-processing mode.
* Default: TOUCH_LIBRARY_DRIVEN.
* Range: TOUCH_LIBRARY_DRIVEN or TOUCH_APPLN_DRIVEN refer in touch_api_ptc.h.
*/
#define DEF_SELFCAP_TOUCH_POSTPROCESS_MODE TOUCH_APPLN_DRIVEN
/* ! @} */
/*----------------------------------------------------------------------------
* Self Cap method moisture detection feature parameters.
*
*
*----------------------------------------------------------------------------*/
/*! \name Mutual Cap method moisture feature parameters.
* Refer the Touch Library User guide for more information on these parameters.
*/
/* ! @{ */
/**
* Enable or disable moisture detection feature.
*/
#define DEF_SELFCAP_MOIS_TOLERANCE_ENABLE (0u)
/**
* Enable or disable quick re-burst feature within a given moisture group.
* When enabled, if within a given moisture group, when any sensor is touched,
* repeated measurements are done only that sensor to resolve detect integration or de-bounce.
* When disabled, if within a given moisture group, when any sensor is touched, repeated measurements are done
* on all sensors within the moisture group to resolve detect integration or de-bounce.
* It is recommended to enable this feature for best touch response time.
*/
#define DEF_SELFCAP_MOIS_QUICK_REBURST_ENABLE (1u)
/**
* Self cap number of moisture groups
*/
#define DEF_SELFCAP_NUM_MOIS_GROUPS (0u)
/**State of the Self Cap PTC pins.
* Default: GND_WHEN_NOT_MEASURED (PTC pins are pulled to GND when they are not bursted).
* Range: ptc_gpio_state_t enum in touch_api_ptc.h.
*/
#define DEF_SELFCAP_PTC_GPIO_STATE (PULLHIGH_WHEN_NOT_MEASURED)
/* ! @} */
/*
* AKS grouping function can be enabled/disabled
* 1u = AKS grouping functionality is enabled
* 0u = AKS grouping functionality is disabled
*/
#define DEF_SELFCAP_AKS_ENABLE (0u)
/*
* Charge share delay indicates the number of additional charge cycles that are inserted within a capacitance measurement cycle
* to ensure full charging of the touch sensor.
* The CSD value is dependent on the sensor capacitance along with the series resistor on the Y line.
* When manual tuning is done, the CSD value for the sensor with largest combination of capacitance along with series resistance
* should be considered.
* allowed Range 0-255
*/
#define DEF_SELF_CAP_CSD_VALUE 0
/*----------------------------------------------------------------------------
* Self Cap method noise measurement & lockout.
*
*
*----------------------------------------------------------------------------*/
/*! \name Self Cap Global acquisition parameters.
* Refer the Touch Library User guide for more information on these parameters.
*/
/* ! @{ */
/**
* Noise measurement enable/disable
* If configured as 1, noise measurement will be enabled
* If configured as 0, noise measurement will be disabled
*/
#define DEF_SELFCAP_NOISE_MEAS_ENABLE (0u)
/**
* Stability limit is the variance in sensor signal value under noisy environment.
* Any noise level over and above the noise signal stability limit contributes to the Noise limit.
* It is recommended to keep this setting close to the lowest sensor detect threshold of
* the system and tune it further based on the noise.
* Range: 1 to 1000
*/
#define DEF_SELFCAP_NOISE_MEAS_SIGNAL_STABILITY_LIMIT 10u
/**
* The noise limit specifies the limit to the total noise accumulated over the noise buffer count.
* If the accumulated noise exceeds the noise limit, then lockout is triggered.
* Range: 1 to 255
*/
#define DEF_SELFCAP_NOISE_LIMIT 12u
/**
* Noise buffer count
* Selection of buffer count for noise calculation.
* Defines the buffer limit for internal noise measurement
* Range: 3 to 10 (select value N + 1, here N nmber of samples)
* if N = 4 then set DEF_NM_BUFFER_CNT 5u ->> (N + 1).
* Default : 5u
*/
#define DEF_SELFCAP_NOISE_MEAS_BUFFER_CNT (5u)
/**
* Mutual cap method : noisy Sensor lockout settings.
* 0u: single sensor lockout.
* 1u: Global sensor lockout.
* 2u : No lockout
* Range : 0 to 2
*/
#define DEF_SELFCAP_LOCKOUT_SEL 0
/**
* Mutual cap Lockout count down
* If the sensor signal is moves from noisy to a good condition and stays there
* for a count value higher than the max count defined by user, sensor is
*declared as stable
* Range: 1 to 255
*/
#define DEF_SELFCAP_LOCKOUT_CNTDOWN 10
/* ! @} */
/*----------------------------------------------------------------------------
* Self Cap method Frequency auto tune.
*
*
*----------------------------------------------------------------------------*/
/*! \name Self Cap Global acquisition parameters.
* Refer the Touch Library User guide for more information on these parameters.
*/
/* ! @{ */
/**
* Freq auto tune enable/disable ( applicable only to freq_hop mode)
* If configured as 1, Freq auto tune will be enabled
* If configured as 0, Freq auto tune will be disabled
*/
#define DEF_SELFCAP_FREQ_AUTO_TUNE_ENABLE (0u)
/**
* Stability limit is the variance in sensor signal value under noisy environment.
* A signal stability limit level is set to auto tune acquisition frequency on noise presence.
* It is recommended to keep this setting close to the lowest sensor detect threshold of the system
* and tune it further based on the noise.
* Range: 1 to 1000
*/
#define DEF_SELFCAP_FREQ_AUTO_TUNE_SIGNAL_STABILITY_LIMIT 10u
/**
* Frequency Auto tune-in count
* If the channel signal is noisy for a count value higher than the max count
*defined by user,
* system will trigger auto tune
* Range: 1 to 255
* Note : this appies only for FREQ_MODE_HOP
*/
#define DEF_SELFCAP_FREQ_AUTO_TUNE_IN_CNT 12
/* ! @} */
/*----------------------------------------------------------------------------
* Self Cap Callback functions.
*
*
*----------------------------------------------------------------------------*/
/*! \name Self Cap Callback functions.
*/
/* ! @{ */
/**
* Self Cap Filter callback function.
* A filter callback (when not NULL) is called by the Touch Library each time
* a new set of Signal values are available.
* An Example filter callback function prototype.
* void touch_filter_callback( touch_filter_data_t *p_filter_data );
*/
#define DEF_SELFCAP_FILTER_CALLBACK (NULL)
/**
* Touch Application Error Handler Enable or Disable; while(1) is used to trap errors when it is enabled
* If configured as 1, Touch Application Error Handler will be enabled
* If configured as 0, Touch Application Error Handler will be disabled
* Default: Touch Application Error Handler will be disabled
*/
#define DEF_TOUCH_APP_ERR_HANDLER 0
/* ! @} */
/*----------------------------------------------------------------------------
* QDebug debug communication parameters.
*
*
*----------------------------------------------------------------------------*/
/*! \name QDebug debug communication parameters.
*/
/* ! @{ */
#define DEF_TOUCH_QDEBUG_ENABLE_SELFCAP
#define DEF_TOUCH_QDEBUG_ENABLE 0u
/* ! @} */
#endif /* TOUCH_CONFIG_SAMD_H */

View File

@ -61,9 +61,11 @@ typedef struct {
uint8_t pin;
bool has_adc:1;
enum adc_positive_input adc_input:7;
pin_timer_t primary_timer; // Mux E
pin_timer_t secondary_timer; // Mux F
pin_sercom_t sercom[NUM_SERCOMS_PER_PIN]; // Mux C and D
bool has_touch:1;
uint8_t touch_y_line:7; // 0 - 15. Assumed to be Y channel.
pin_timer_t primary_timer;
pin_timer_t secondary_timer;
pin_sercom_t sercom[NUM_SERCOMS_PER_PIN];
} mcu_pin_obj_t;
#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_MICROCONTROLLER_TYPES_H__

View File

@ -0,0 +1,274 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2016 Scott Shawcroft 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 <string.h>
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/binary.h"
#include "py/mphal.h"
#include "shared-bindings/nativeio/TouchIn.h"
#include "tick.h"
#include "QTouch/touch_api_ptc.h"
#define DEF_SELFCAP_CAL_SEQ1_COUNT 8
#define DEF_SELFCAP_CAL_SEQ2_COUNT 4
#define DEF_SELFCAP_CC_CAL_CLK_PRESCALE_PER_NODE DEF_SELFCAP_CLK_PRESCALE_PER_NODE
#define DEF_SELFCAP_CC_CAL_SENSE_RESISTOR_PER_NODE DEF_SELFCAP_SENSE_RESISTOR_PER_NODE
#define DEF_SELFCAP_QUICK_REBURST_ENABLE 1u
/**
* Mutual Cap sensors measured data pointer.
* Note: This pointer is initialized by the QTouch library once the
* touch_mutlcap_sensors_init API is called. */
touch_measure_data_t *p_mutlcap_measure_data = NULL;
/**
* Self Cap sensors measured data pointer.
* Note: This pointer is initialized by the QTouch library once the
* touch_selfcap_sensors_init API is called. */
touch_measure_data_t *p_selfcap_measure_data = NULL;
/**
* Self Cap sensors data block provided as input to Touch library.
*/
static uint8_t selfcap_data_blk[PRIV_SELFCAP_DATA_BLK_SIZE];
/**
* Self Cap sensors Pins Info.
*/
uint32_t selfcap_y_nodes[DEF_SELFCAP_NUM_CHANNELS] = {DEF_SELFCAP_LINES};
filter_level_t selfcap_filter_level_per_node[DEF_SELFCAP_NUM_CHANNELS] = {DEF_SELFCAP_FILTER_LEVEL_PER_NODE};
uint8_t selfcap_auto_os_per_node[DEF_SELFCAP_NUM_CHANNELS]= {DEF_SELFCAP_AUTO_OS_PER_NODE};
gain_t selfcap_gain_per_node[DEF_SELFCAP_NUM_CHANNELS] = {DEF_SELFCAP_GAIN_PER_NODE};
rsel_val_t selfcap_resistor_per_node[DEF_SELFCAP_NUM_CHANNELS] = {DEF_SELFCAP_SENSE_RESISTOR_PER_NODE};
prsc_div_sel_t selfcap_prsc_per_node[DEF_SELFCAP_NUM_CHANNELS] = {DEF_SELFCAP_CLK_PRESCALE_PER_NODE};
prsc_div_sel_t selfcap_boot_prsc_per_node[DEF_SELFCAP_NUM_CHANNELS] = {DEF_SELFCAP_CC_CAL_CLK_PRESCALE_PER_NODE};
rsel_val_t selfcap_boot_resistor_per_node[DEF_SELFCAP_NUM_CHANNELS] = { DEF_SELFCAP_CC_CAL_SENSE_RESISTOR_PER_NODE};
freq_hop_sel_t selfcap_freq_hops[3u] = {DEF_SELFCAP_HOP_FREQS};
/**
* Self Cap Configuration structure provided as input to Touch Library.
*
* Note: Use the touch.h configuration header file to fill in
* the elements of this structure. DO NOT modify any of the input values
* directly in this structure.
*/
static touch_selfcap_config_t selfcap_config = {
DEF_SELFCAP_NUM_CHANNELS, /* Self Cap number of channels. */
DEF_SELFCAP_NUM_SENSORS, /* Self Cap number of sensors. */
DEF_SELFCAP_NUM_ROTORS_SLIDERS, /* Self Cap number of rotors and
* sliders. */
/* Self Cap GLOBAL SENSOR CONFIGURATION INFO. */
{
DEF_SELFCAP_DI, /* uint8_t di; Sensor detect
* integration (DI) limit. */
/* Interchanging Negative and Positive Drift rate, since Signal
* increases on Touch. */
DEF_SELFCAP_ATCH_DRIFT_RATE, /* uint8_t neg_drift_rate;
* Sensor
* negative drift rate. */
DEF_SELFCAP_TCH_DRIFT_RATE, /* uint8_t pos_drift_rate;
* Sensor
* positive drift rate. */
DEF_SELFCAP_MAX_ON_DURATION, /* uint8_t max_on_duration;
* Sensor
* maximum on duration. */
DEF_SELFCAP_DRIFT_HOLD_TIME, /* uint8_t drift_hold_time;
* Sensor
* drift hold time. */
DEF_SELFCAP_ATCH_RECAL_DELAY, /* uint8_t pos_recal_delay;
* Sensor positive recalibration
* delay. */
DEF_SELFCAP_CAL_SEQ1_COUNT,
DEF_SELFCAP_CAL_SEQ2_COUNT,
DEF_SELFCAP_ATCH_RECAL_THRESHOLD, /* recal_threshold_t
* recal_threshold; Sensor
* recalibration threshold. */
DEF_SELFCAP_TOUCH_POSTPROCESS_MODE,
DEF_SELFCAP_AUTO_OS_SIGNAL_STABILITY_LIMIT,
DEF_SELFCAP_FREQ_AUTO_TUNE_SIGNAL_STABILITY_LIMIT,
DEF_SELFCAP_FREQ_AUTO_TUNE_IN_CNT,
DEF_SELFCAP_NOISE_MEAS_SIGNAL_STABILITY_LIMIT, /* signal
*stability */
DEF_SELFCAP_NOISE_LIMIT,
DEF_SELFCAP_LOCKOUT_SEL,
DEF_SELFCAP_LOCKOUT_CNTDOWN,
#if ((SAMC20) || (SAMC21) || (SAML22))
DEF_SELF_CAP_CSD_VALUE,
#endif
},
{
selfcap_gain_per_node, /* Self Cap channel gain setting. */
DEF_SELFCAP_FREQ_MODE, /* Self Cap noise counter measure
* enable/disable. */
selfcap_prsc_per_node,
selfcap_resistor_per_node,
selfcap_boot_prsc_per_node,
selfcap_boot_resistor_per_node,
selfcap_freq_hops,
selfcap_filter_level_per_node, /* Self Cap filter level setting. */
selfcap_auto_os_per_node, /* Self Cap auto oversamples
*setting. */
},
selfcap_data_blk, /* Self Cap data block index. */
PRIV_SELFCAP_DATA_BLK_SIZE, /* Self Cap data block size. */
selfcap_y_nodes, /* Self Cap channel nodes. */
DEF_SELFCAP_QUICK_REBURST_ENABLE,
DEF_SELFCAP_FILTER_CALLBACK, /* Self Cap filter callback
* function
* pointer. */
DEF_SELFCAP_FREQ_AUTO_TUNE_ENABLE,
DEF_SELFCAP_NOISE_MEAS_ENABLE,
DEF_SELFCAP_NOISE_MEAS_BUFFER_CNT,
DEF_SELFCAP_MOIS_TOLERANCE_ENABLE,
DEF_SELFCAP_NUM_MOIS_GROUPS,
DEF_SELFCAP_MOIS_QUICK_REBURST_ENABLE,
DEF_SELFCAP_PTC_GPIO_STATE,
.tlib_feature_list ={
.lk_chk = DEF_LOCKOUT_FUNC,
.auto_os_init = DEF_AUTO_OS_FUNC,//auto_os_resolve,
.auto_tune_init = DEF_SELF_AUTO_TUNE_FUNC,// self_auto_tuning
.enable_aks = DEF_AKS_FUNC, /*AKS grouping function */
}
};
/**
* Touch Library input configuration structure.
*/
touch_config_t touch_config = {
NULL,
&selfcap_config, /* Pointer to Self Cap configuration
* structure. */
DEF_TOUCH_PTC_ISR_LVL, /* PTC interrupt level. */
};
bool ptc_initialized = false;
void common_hal_nativeio_touchin_construct(nativeio_touchin_obj_t* self,
const mcu_pin_obj_t *pin) {
if (!pin->has_touch) {
// No ADC function on that pin
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin %q does not have touch capabilities", pin->name));
}
touch_ret_t status;
if (!ptc_initialized) {
/* 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);
gclk_chan_conf.source_generator = GCLK_GENERATOR_1;
system_gclk_chan_set_config(PTC_GCLK_ID, &gclk_chan_conf);
system_gclk_chan_enable(PTC_GCLK_ID);
system_apb_clock_set_mask(SYSTEM_CLOCK_APB_APBC, PM_APBCMASK_PTC);
/* Initialize touch library for Self Cap operation. */
status = touch_selfcap_sensors_init_with_rs_table(&touch_config,
PRIV_SELFCAP_RS_TABLE_INIT, PRIV_NM_TABLE_INIT,
PRIV_FREQ_AUTO_TUNE_CHK, PRIV_MOIS_TOLERANCE_CHK);
if (status != TOUCH_SUCCESS) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Touch init failed (%d)", status));
}
ptc_initialized = true;
}
// Map Y line to channel. Boards can switch the order.
int channel;
for (channel = 0; channel < DEF_SELFCAP_NUM_CHANNELS; channel++) {
if (selfcap_y_nodes[channel] == Y(pin->touch_y_line)) {
break;
}
}
if (channel == DEF_SELFCAP_NUM_CHANNELS) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Pin %q on this board does not have touch capabilities", pin->name));
}
status = touch_selfcap_sensor_config(SENSOR_TYPE_KEY, channel, channel,
NO_AKS_GROUP, 10u, HYST_25, RES_8_BIT, &self->sensor_id);
if (status != TOUCH_SUCCESS) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Touch pad config failed (%d)", status));
}
status = touch_selfcap_sensors_calibrate(AUTO_TUNE_RSEL);
if (status != TOUCH_SUCCESS) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Touch pad calibration failed (%d)", status));
}
self->pin = pin;
}
void common_hal_nativeio_touchin_deinit(nativeio_touchin_obj_t* self) {
touch_selfcap_sensor_disable(self->sensor_id);
}
volatile bool touch_read_ready = false;
volatile touch_acq_status_t touch_acq_status;
void touch_selfcap_measure_complete_callback(void)
{
touch_read_ready = true;
touch_acq_status = p_selfcap_measure_data->acq_status;
}
bool common_hal_nativeio_touchin_get_value(nativeio_touchin_obj_t *self) {
if (p_selfcap_measure_data->acq_status & TOUCH_CC_CALIB_ERROR) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Touch calibration error"));
}
touch_acq_status = TOUCH_BURST_AGAIN;
uint64_t start_ticks = ticks_ms;
while((touch_acq_status & TOUCH_BURST_AGAIN) && ticks_ms - start_ticks < 1000) {
touch_read_ready = false;
touch_ret_t touch_ret = touch_selfcap_sensors_measure(
ticks_ms,
NORMAL_ACQ_MODE,
touch_selfcap_measure_complete_callback);
if (touch_ret != TOUCH_SUCCESS) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Touch measure failed"));
}
while(!touch_read_ready && ticks_ms - start_ticks < 1000) {
// wait
}
}
if (touch_acq_status & TOUCH_BURST_AGAIN) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Touch read failed"));
}
return (p_selfcap_measure_data->p_sensor_states[self->sensor_id / 8] & (1 << (self->sensor_id % 8))) == 1;
}

View File

@ -0,0 +1,46 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2016 Scott Shawcroft 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 <string.h>
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/binary.h"
#include "py/mphal.h"
#include "shared-bindings/nativeio/TouchIn.h"
void common_hal_nativeio_touchin_construct(nativeio_touchin_obj_t* self,
const mcu_pin_obj_t *pin) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError,
"No room in flash for capacitive touch hardware support."));
}
void common_hal_nativeio_touchin_deinit(nativeio_touchin_obj_t* self) {
}
bool common_hal_nativeio_touchin_get_value(nativeio_touchin_obj_t *self) {
return false;
}

View File

@ -44,6 +44,10 @@
#include "asf/sam0/drivers/sercom/spi/spi.h"
#include "asf/sam0/drivers/tc/tc.h"
#include "asf/sam0/drivers/tcc/tcc.h"
// Only support TouchIn when external SPI flash is used.
#ifdef SPI_FLASH_SECTOR_SIZE
#include "QTouch/touch_api_ptc.h"
#endif
#include "py/obj.h"
@ -90,4 +94,13 @@ typedef struct {
struct tcc_module tcc_instance;
} nativeio_pwmout_obj_t;
typedef struct {
mp_obj_base_t base;
// Only support TouchIn when external SPI flash is used.
#ifdef SPI_FLASH_SECTOR_SIZE
const mcu_pin_obj_t * pin;
sensor_id_t sensor_id;
#endif
} nativeio_touchin_obj_t;
#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_NATIVEIO_TYPES_H__

View File

@ -22,6 +22,10 @@
#include "asf/sam0/drivers/system/system.h"
#include <board.h>
#ifdef SPI_FLASH_SECTOR_SIZE
#include "QTouch/touch_api_ptc.h"
#endif
#include "autoreset.h"
#include "mpconfigboard.h"
#include "rgb_led_status.h"
@ -155,6 +159,7 @@ void reset_mp(void) {
MP_STATE_PORT(mp_kbd_exception) = mp_obj_new_exception(&mp_type_KeyboardInterrupt);
}
extern bool ptc_initialized;
void reset_samd21(void) {
// Reset all SERCOMs except the one being used by the SPI flash.
Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS;
@ -172,6 +177,11 @@ void reset_samd21(void) {
sercom_instances[i]->SPI.CTRLA.bit.SWRST = 1;
}
#ifdef SPI_FLASH_SECTOR_SIZE
touch_selfcap_sensors_deinit();
ptc_initialized = false;
#endif
struct system_pinmux_config config;
system_pinmux_get_config_defaults(&config);
config.powersave = true;

View File

@ -28,15 +28,29 @@
#define NO_TIMER TCC(0, 0, 0)
#define TOUCH(y_line) \
.has_touch = true, \
.touch_y_line = y_line,
#define NO_TOUCH \
.has_touch = false,
#define ADC_INPUT(input) \
.has_adc = true, \
.adc_input = input,
#define NO_ADC \
.has_adc = false,
// This macro is used to simplify pin definition in boards/<board>/pins.c
#define PIN(p_name, p_has_adc, p_adc_input, p_primary_timer, \
p_secondary_timer, p_primary_sercom, p_secondary_sercom) \
#define PIN(p_name, p_adc, p_touch, p_primary_timer, p_secondary_timer, \
p_primary_sercom, p_secondary_sercom) \
const mcu_pin_obj_t pin_## p_name = { \
{ &mcu_pin_type }, \
.name = MP_QSTR_ ## p_name, \
.pin = (PIN_## p_name), \
.has_adc = p_has_adc, \
.adc_input = p_adc_input, \
p_adc \
p_touch \
.primary_timer = p_primary_timer, \
.secondary_timer = p_secondary_timer, \
.sercom = {p_primary_sercom, p_secondary_sercom}, \
@ -53,161 +67,161 @@ void reset_pin(uint8_t pin) {
// Pins in datasheet order.
#ifdef PIN_PA00
PIN(PA00, false, NO_ADC_INPUT, \
PIN(PA00, NO_ADC, NO_TOUCH,
TCC(TCC2, 0, 0),
NO_TIMER,
SERCOM(SERCOM1, 0),
NO_SERCOM);
#endif
#ifdef PIN_PA01
PIN(PA01, false, NO_ADC_INPUT,
PIN(PA01, NO_ADC, NO_TOUCH,
TCC(TCC2, 1, 1),
NO_TIMER,
SERCOM(SERCOM1, 1),
NO_SERCOM);
#endif
#ifdef PIN_PA02
PIN(PA02, true, ADC_POSITIVE_INPUT_PIN0,
PIN(PA02, ADC_INPUT(ADC_POSITIVE_INPUT_PIN0), TOUCH(0),
NO_TIMER,
NO_TIMER,
NO_SERCOM,
NO_SERCOM);
#endif
#ifdef PIN_PA03
PIN(PA03, true, ADC_POSITIVE_INPUT_PIN1,
PIN(PA03, ADC_INPUT(ADC_POSITIVE_INPUT_PIN1), TOUCH(1),
NO_TIMER,
NO_TIMER,
NO_SERCOM,
NO_SERCOM);
#endif
#ifdef PIN_PB04
PIN(PB04, true, ADC_POSITIVE_INPUT_PIN12,
PIN(PB04, ADC_INPUT(ADC_POSITIVE_INPUT_PIN12), TOUCH(10),
NO_TIMER,
NO_TIMER,
NO_SERCOM,
NO_SERCOM);
#endif
#ifdef PIN_PB05
PIN(PB05, true, ADC_POSITIVE_INPUT_PIN13,
PIN(PB05, ADC_INPUT(ADC_POSITIVE_INPUT_PIN13), TOUCH(11),
NO_TIMER,
NO_TIMER,
NO_SERCOM,
NO_SERCOM);
#endif
#ifdef PIN_PB06
PIN(PB06, true, ADC_POSITIVE_INPUT_PIN14,
PIN(PB06, ADC_INPUT(ADC_POSITIVE_INPUT_PIN14), TOUCH(12),
NO_TIMER,
NO_TIMER,
NO_SERCOM,
NO_SERCOM);
#endif
#ifdef PIN_PB07
PIN(PB07, true, ADC_POSITIVE_INPUT_PIN15,
PIN(PB07, TOUCH(ADC_POSITIVE_INPUT_PIN15), TOUCH(13),
NO_TIMER,
NO_TIMER,
NO_SERCOM,
NO_SERCOM);
#endif
#ifdef PIN_PB08
PIN(PB08, true, ADC_POSITIVE_INPUT_PIN2,
PIN(PB08, ADC_INPUT(ADC_POSITIVE_INPUT_PIN2), TOUCH(14),
TC(TC4, 0, 0),
NO_TIMER,
NO_SERCOM,
SERCOM(SERCOM4, 0));
#endif
#ifdef PIN_PB09
PIN(PB09, true, ADC_POSITIVE_INPUT_PIN3,
PIN(PB09, ADC_INPUT(ADC_POSITIVE_INPUT_PIN3), TOUCH(15),
TC(TC4, 1, 1),
NO_TIMER,
NO_SERCOM,
SERCOM(SERCOM4, 1));
#endif
#ifdef PIN_PA04
PIN(PA04, true, ADC_POSITIVE_INPUT_PIN4,
PIN(PA04, ADC_INPUT(ADC_POSITIVE_INPUT_PIN4), TOUCH(2),
TCC(TCC0, 0, 0),
NO_TIMER,
NO_SERCOM,
SERCOM(SERCOM0, 0));
#endif
#ifdef PIN_PA05
PIN(PA05, true, ADC_POSITIVE_INPUT_PIN5,
PIN(PA05, ADC_INPUT(ADC_POSITIVE_INPUT_PIN5), TOUCH(3),
TCC(TCC0, 1, 1),
NO_TIMER,
NO_SERCOM,
SERCOM(SERCOM0, 1));
#endif
#ifdef PIN_PA06
PIN(PA06, true, ADC_POSITIVE_INPUT_PIN6,
PIN(PA06, ADC_INPUT(ADC_POSITIVE_INPUT_PIN6), TOUCH(4),
TCC(TCC1, 0, 0),
NO_TIMER,
SERCOM(SERCOM0, 2),
NO_SERCOM);
#endif
#ifdef PIN_PA07
PIN(PA07, true, ADC_POSITIVE_INPUT_PIN7,
PIN(PA07, ADC_INPUT(ADC_POSITIVE_INPUT_PIN7), TOUCH(5),
TCC(TCC1, 1, 1),
NO_TIMER,
SERCOM(SERCOM0, 3),
NO_SERCOM);
#endif
#ifdef PIN_PA08
PIN(PA08, true, ADC_POSITIVE_INPUT_PIN17,
PIN(PA08, ADC_INPUT(ADC_POSITIVE_INPUT_PIN17), NO_TOUCH,
TCC(TCC0, 0, 0),
TCC(TCC1, 2, 2),
SERCOM(SERCOM0, 0),
SERCOM(SERCOM2, 0));
#endif
#ifdef PIN_PA09
PIN(PA09, true, ADC_POSITIVE_INPUT_PIN17,
PIN(PA09, ADC_INPUT(ADC_POSITIVE_INPUT_PIN17), NO_TOUCH,
TCC(TCC0, 1, 1),
TCC(TCC1, 3, 3),
SERCOM(SERCOM0, 1),
SERCOM(SERCOM2, 1));
#endif
#ifdef PIN_PA10
PIN(PA10, true, ADC_POSITIVE_INPUT_PIN18,
PIN(PA10, ADC_INPUT(ADC_POSITIVE_INPUT_PIN18), NO_TOUCH,
TCC(TCC1, 0, 0),
TCC(TCC0, 2, 2),
SERCOM(SERCOM0, 2),
SERCOM(SERCOM2, 2));
#endif
#ifdef PIN_PA11
PIN(PA11, true, ADC_POSITIVE_INPUT_PIN19,
PIN(PA11, ADC_INPUT(ADC_POSITIVE_INPUT_PIN19), NO_TOUCH,
TCC(TCC1, 1, 1),
TCC(TCC0, 3, 3),
SERCOM(SERCOM0, 3),
SERCOM(SERCOM2, 3));
#endif
#ifdef PIN_PB10
PIN(PB10, false, NO_ADC_INPUT,
PIN(PB10, NO_ADC, NO_TOUCH,
TC(TC5, 0, 0),
TCC(TCC0, 0, 4),
NO_SERCOM,
SERCOM(SERCOM4, 2));
#endif
#ifdef PIN_PB11
PIN(PB11, false, NO_ADC_INPUT,
PIN(PB11, NO_ADC, NO_TOUCH,
TC(TC5, 1, 1),
TCC(TCC0, 1, 5),
NO_SERCOM,
SERCOM(SERCOM4, 3));
#endif
#ifdef PIN_PB12
PIN(PB12, false, NO_ADC_INPUT,
PIN(PB12, NO_ADC, NO_TOUCH,
TC(TC4, 0, 0),
TCC(TCC0, 2, 6),
SERCOM(SERCOM4, 0),
NO_SERCOM);
#endif
#ifdef PIN_PB13
PIN(PB13, false, NO_ADC_INPUT,
PIN(PB13, NO_ADC, NO_TOUCH,
TC(TC4, 1, 1),
TCC(TCC0, 3, 7),
SERCOM(SERCOM4, 1),
NO_SERCOM);
#endif
#ifdef PIN_PB14
PIN(PB14, false, NO_ADC_INPUT,
PIN(PB14, NO_ADC, NO_TOUCH,
TC(TC5, 0, 0),
NO_TIMER,
SERCOM(SERCOM4, 2),
@ -216,28 +230,28 @@ PIN(PB14, false, NO_ADC_INPUT,
// Second page.
#ifdef PIN_PB15
PIN(PB15, false, NO_ADC_INPUT,
PIN(PB15, NO_ADC, NO_TOUCH,
TC(TC5, 1, 1),
NO_TIMER,
SERCOM(SERCOM4, 3),
NO_SERCOM);
#endif
#ifdef PIN_PA12
PIN(PA12, false, NO_ADC_INPUT,
PIN(PA12, NO_ADC, NO_TOUCH,
TCC(TCC2, 0, 0),
TCC(TCC0, 2, 6),
SERCOM(SERCOM2, 0),
SERCOM(SERCOM4, 0));
#endif
#ifdef PIN_PA13
PIN(PA13, false, NO_ADC_INPUT,
PIN(PA13, NO_ADC, NO_TOUCH,
TCC(TCC2, 1, 1),
TCC(TCC0, 3, 7),
SERCOM(SERCOM2, 1),
SERCOM(SERCOM4, 1));
#endif
#ifdef PIN_PA14
PIN(PA14, false, NO_ADC_INPUT,
PIN(PA14, NO_ADC, NO_TOUCH,
TC(TC3, 0, 0),
TCC(TCC0, 0, 4),
SERCOM(SERCOM2, 2),
@ -249,7 +263,7 @@ PIN(PA14, false, NO_ADC_INPUT,
);
#endif
#ifdef PIN_PA15
PIN(PA15, false, NO_ADC_INPUT,
PIN(PA15, NO_ADC, NO_TOUCH,
TC(TC3, 1, 1),
TCC(TCC0, 1, 5),
SERCOM(SERCOM2, 3),
@ -261,35 +275,35 @@ PIN(PA15, false, NO_ADC_INPUT,
);
#endif
#ifdef PIN_PA16
PIN(PA16, false, NO_ADC_INPUT,
PIN(PA16, NO_ADC, NO_TOUCH,
TCC(TCC2, 0, 0),
TCC(TCC0, 2, 6),
SERCOM(SERCOM1, 0),
SERCOM(SERCOM3, 0));
#endif
#ifdef PIN_PA17
PIN(PA17, false, NO_ADC_INPUT,
PIN(PA17, NO_ADC, NO_TOUCH,
TCC(TCC2, 1, 1),
TCC(TCC0, 3, 7),
SERCOM(SERCOM1, 1),
SERCOM(SERCOM3, 1));
#endif
#ifdef PIN_PA18
PIN(PA18, false, NO_ADC_INPUT,
PIN(PA18, NO_ADC, NO_TOUCH,
TC(TC3, 0, 0),
TCC(TCC0, 2, 2),
SERCOM(SERCOM1, 2),
SERCOM(SERCOM3, 2));
#endif
#ifdef PIN_PA19
PIN(PA19, false, NO_ADC_INPUT,
PIN(PA19, NO_ADC, NO_TOUCH,
TC(TC3, 1, 1),
TCC(TCC0, 3, 3),
SERCOM(SERCOM1, 3),
SERCOM(SERCOM3, 3));
#endif
#ifdef PIN_PB16
PIN(PB16, false, NO_ADC_INPUT,
PIN(PB16, NO_ADC, NO_TOUCH,
#ifdef _SAMD21_TC6_INSTANCE_
TC(TC6, 0, 0),
#else
@ -300,7 +314,7 @@ PIN(PB16, false, NO_ADC_INPUT,
NO_SERCOM);
#endif
#ifdef PIN_PB17
PIN(PB17, false, NO_ADC_INPUT,
PIN(PB17, NO_ADC, NO_TOUCH,
#ifdef _SAMD21_TC6_INSTANCE_
TC(TC6, 0, 0),
#else
@ -311,7 +325,7 @@ PIN(PB17, false, NO_ADC_INPUT,
NO_SERCOM);
#endif
#ifdef PIN_PA20
PIN(PA20, false, NO_ADC_INPUT,
PIN(PA20, NO_ADC, NO_TOUCH,
#ifdef _SAMD21_TC7_INSTANCE_
TC(TC7, 0, 0),
#else
@ -322,7 +336,7 @@ PIN(PA20, false, NO_ADC_INPUT,
SERCOM(SERCOM3, 2));
#endif
#ifdef PIN_PA21
PIN(PA21, false, NO_ADC_INPUT,
PIN(PA21, NO_ADC, NO_TOUCH,
#ifdef _SAMD21_TC7_INSTANCE_
TC(TC7, 1, 1),
#else
@ -333,7 +347,7 @@ PIN(PA21, false, NO_ADC_INPUT,
SERCOM(SERCOM3, 3));
#endif
#ifdef PIN_PA22
PIN(PA22, false, NO_ADC_INPUT,
PIN(PA22, NO_ADC, NO_TOUCH,
TC(TC4, 0, 0),
TCC(TCC0, 0, 4),
SERCOM(SERCOM3, 0),
@ -345,7 +359,7 @@ PIN(PA22, false, NO_ADC_INPUT,
);
#endif
#ifdef PIN_PA23
PIN(PA23, false, NO_ADC_INPUT,
PIN(PA23, NO_ADC, NO_TOUCH,
TC(TC4, 1, 1),
TCC(TCC0, 1, 5),
SERCOM(SERCOM3, 1),
@ -357,7 +371,7 @@ PIN(PA23, false, NO_ADC_INPUT,
);
#endif
#ifdef PIN_PA24
PIN(PA24, false, NO_ADC_INPUT,
PIN(PA24, NO_ADC, NO_TOUCH,
TC(TC5, 0, 0),
TCC(TCC0, 2, 2),
SERCOM(SERCOM3, 2),
@ -369,7 +383,7 @@ PIN(PA24, false, NO_ADC_INPUT,
);
#endif
#ifdef PIN_PA25
PIN(PA25, false, NO_ADC_INPUT,
PIN(PA25, NO_ADC, NO_TOUCH,
TC(TC5, 1, 1),
TCC(TCC1, 3, 3),
SERCOM(SERCOM3, 3),
@ -381,7 +395,7 @@ PIN(PA25, false, NO_ADC_INPUT,
);
#endif
#ifdef PIN_PB22
PIN(PB22, false, NO_ADC_INPUT,
PIN(PB22, NO_ADC, NO_TOUCH,
#ifdef _SAMD21_TC7_INSTANCE_
TC(TC7, 1, 1),
#else
@ -392,7 +406,7 @@ PIN(PB22, false, NO_ADC_INPUT,
SERCOM(SERCOM5, 2));
#endif
#ifdef PIN_PB23
PIN(PB23, false, NO_ADC_INPUT,
PIN(PB23, NO_ADC, NO_TOUCH,
#ifdef _SAMD21_TC7_INSTANCE_
TC(TC7, 1, 1),
#else
@ -403,49 +417,49 @@ PIN(PB23, false, NO_ADC_INPUT,
SERCOM(SERCOM5, 3));
#endif
#ifdef PIN_PA27
PIN(PA27, false, NO_ADC_INPUT,
PIN(PA27, NO_ADC, NO_TOUCH,
NO_TIMER,
NO_TIMER,
NO_SERCOM,
NO_SERCOM);
#endif
#ifdef PIN_PA28
PIN(PA28, false, NO_ADC_INPUT,
PIN(PA28, NO_ADC, NO_TOUCH,
NO_TIMER,
NO_TIMER,
NO_SERCOM,
NO_SERCOM);
#endif
#ifdef PIN_PA30
PIN(PA30, false, NO_ADC_INPUT,
PIN(PA30, NO_ADC, NO_TOUCH,
TCC(TCC1, 0, 0),
NO_TIMER,
NO_SERCOM,
SERCOM(SERCOM1, 2));
#endif
#ifdef PIN_PA31
PIN(PA31, false, NO_ADC_INPUT,
PIN(PA31, NO_ADC, NO_TOUCH,
TCC(TCC1, 1, 1),
NO_TIMER,
NO_SERCOM,
SERCOM(SERCOM1, 3));
#endif
#ifdef PIN_PB30
PIN(PB30, false, NO_ADC_INPUT,
PIN(PB30, NO_ADC, NO_TOUCH,
TCC(TCC0, 0, 0),
TCC(TCC1, 2, 2),
NO_SERCOM,
SERCOM(SERCOM5, 0));
#endif
#ifdef PIN_PB31
PIN(PB31, false, NO_ADC_INPUT,
PIN(PB31, NO_ADC, NO_TOUCH,
TCC(TCC0, 1, 1),
TCC(TCC1, 3, 3),
NO_SERCOM,
SERCOM(SERCOM5, 1));
#endif
#ifdef PIN_PB00
PIN(PB00, true, ADC_POSITIVE_INPUT_PIN8,
PIN(PB00, ADC_INPUT(ADC_POSITIVE_INPUT_PIN8), TOUCH(6),
#ifdef _SAMD21_TC7_INSTANCE_
TC(TC7, 0, 0),
#else
@ -456,7 +470,7 @@ PIN(PB00, true, ADC_POSITIVE_INPUT_PIN8,
SERCOM(SERCOM5, 2));
#endif
#ifdef PIN_PB01
PIN(PB01, true, ADC_POSITIVE_INPUT_PIN9,
PIN(PB01, ADC_INPUT(ADC_POSITIVE_INPUT_PIN9), TOUCH(7),
#ifdef _SAMD21_TC7_INSTANCE_
TC(TC7, 1, 1),
#else
@ -467,7 +481,7 @@ PIN(PB01, true, ADC_POSITIVE_INPUT_PIN9,
SERCOM(SERCOM5, 3));
#endif
#ifdef PIN_PB02
PIN(PB02, true, ADC_POSITIVE_INPUT_PIN10,
PIN(PB02, ADC_INPUT(ADC_POSITIVE_INPUT_PIN10), TOUCH(8),
#ifdef _SAMD21_TC6_INSTANCE_
TC(TC6, 0, 0),
#else
@ -478,7 +492,7 @@ PIN(PB02, true, ADC_POSITIVE_INPUT_PIN10,
SERCOM(SERCOM5, 0));
#endif
#ifdef PIN_PB03
PIN(PB03, true, ADC_POSITIVE_INPUT_PIN11,
PIN(PB03, ADC_INPUT(ADC_POSITIVE_INPUT_PIN11), TOUCH(9),
#ifdef _SAMD21_TC6_INSTANCE_
TC(TC6, 1, 1),
#else

View File

@ -116,6 +116,7 @@ SRC_COMMON_HAL = \
nativeio/I2C.c \
nativeio/PWMOut.c \
nativeio/SPI.c \
nativeio/TouchIn.c \
neopixel_write/__init__.c \
time/__init__.c \
board/__init__.c

View File

@ -0,0 +1,46 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2016 Scott Shawcroft 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 <string.h>
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/binary.h"
#include "py/mphal.h"
#include "shared-bindings/nativeio/TouchIn.h"
void common_hal_nativeio_touchin_construct(nativeio_touchin_obj_t* self,
const mcu_pin_obj_t *pin) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError,
"No hardware support for capacitive touch."));
}
void common_hal_nativeio_touchin_deinit(nativeio_touchin_obj_t* self) {
}
bool common_hal_nativeio_touchin_get_value(nativeio_touchin_obj_t *self) {
return false;
}

View File

@ -67,4 +67,8 @@ typedef struct {
const mcu_pin_obj_t* pin;
} nativeio_pwmout_obj_t;
typedef struct {
mp_obj_base_t base;
} nativeio_touchin_obj_t;
#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_NATIVEIO_TYPES_H__

View File

@ -0,0 +1,141 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2013, 2014 Damien P. George
*
* 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 <string.h>
#include "py/binary.h"
#include "py/mphal.h"
#include "py/nlr.h"
#include "py/objproperty.h"
#include "py/runtime.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/nativeio/TouchIn.h"
//| .. currentmodule:: nativeio
//|
//| :class:`TouchIn` -- Read the state of a capacitive touch sensor
//| ============================================
//|
//| Usage::
//|
//| import nativeio
//| from board import *
//|
//| with nativeio.TouchIn(A1) as touch:
//| if touch.value:
//| print("touched!")
//|
//| .. class:: TouchIn(pin)
//|
//| Use the TouchIn on the given pin.
//|
//| :param ~microcontroller.Pin pin: the pin to read from
//|
STATIC mp_obj_t nativeio_touchin_make_new(const mp_obj_type_t *type,
mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
// check number of arguments
mp_arg_check_num(n_args, n_kw, 1, 1, false);
// 1st argument is the pin
mp_obj_t pin_obj = args[0];
assert_pin(pin_obj, false);
nativeio_touchin_obj_t *self = m_new_obj(nativeio_touchin_obj_t);
self->base.type = &nativeio_touchin_type;
const mcu_pin_obj_t *pin = MP_OBJ_TO_PTR(pin_obj);
common_hal_nativeio_touchin_construct(self, pin);
return (mp_obj_t) self;
}
//| .. method:: deinit()
//|
//| Deinitialises the TouchIn and releases any hardware resources for reuse.
//|
STATIC mp_obj_t nativeio_touchin_deinit(mp_obj_t self_in) {
nativeio_touchin_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_nativeio_touchin_deinit(self);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(nativeio_touchin_deinit_obj, nativeio_touchin_deinit);
//| .. method:: __enter__()
//|
//| No-op used by Context Managers.
//|
STATIC mp_obj_t nativeio_touchin_obj___enter__(mp_obj_t self_in) {
return self_in;
}
MP_DEFINE_CONST_FUN_OBJ_1(nativeio_touchin___enter___obj, nativeio_touchin_obj___enter__);
//| .. method:: __exit__()
//|
//| Automatically deinitializes the hardware when exiting a context.
//|
STATIC mp_obj_t nativeio_touchin_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_nativeio_touchin_deinit(args[0]);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(nativeio_touchin___exit___obj, 4, 4, nativeio_touchin_obj___exit__);
//| .. attribute:: value
//|
//| Whether the touch pad is being touched or not.
//|
//| :return: True when touched, False otherwise.
//| :rtype: bool
//|
STATIC mp_obj_t nativeio_touchin_obj_get_value(mp_obj_t self_in) {
nativeio_touchin_obj_t *self = MP_OBJ_TO_PTR(self_in);
return mp_obj_new_bool(common_hal_nativeio_touchin_get_value(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(nativeio_touchin_get_value_obj, nativeio_touchin_obj_get_value);
mp_obj_property_t nativeio_touchin_value_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&nativeio_touchin_get_value_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj},
};
STATIC const mp_rom_map_elem_t nativeio_touchin_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&nativeio_touchin___enter___obj) },
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&nativeio_touchin___exit___obj) },
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&nativeio_touchin_deinit_obj) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_value), MP_ROM_PTR(&nativeio_touchin_value_obj)},
};
STATIC MP_DEFINE_CONST_DICT(nativeio_touchin_locals_dict, nativeio_touchin_locals_dict_table);
const mp_obj_type_t nativeio_touchin_type = {
{ &mp_type_type },
.name = MP_QSTR_TouchIn,
.make_new = nativeio_touchin_make_new,
.locals_dict = (mp_obj_t)&nativeio_touchin_locals_dict,
};

View File

@ -0,0 +1,39 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2013, 2014 Damien P. George
*
* 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.
*/
#ifndef __MICROPY_INCLUDED_SHARED_BINDINGS_NATIVEIO_TOUCHIN_H__
#define __MICROPY_INCLUDED_SHARED_BINDINGS_NATIVEIO_TOUCHIN_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/nativeio/types.h"
extern const mp_obj_type_t nativeio_touchin_type;
void common_hal_nativeio_touchin_construct(nativeio_touchin_obj_t* self, const mcu_pin_obj_t *pin);
void common_hal_nativeio_touchin_deinit(nativeio_touchin_obj_t* self);
bool common_hal_nativeio_touchin_get_value(nativeio_touchin_obj_t *self);
#endif // __MICROPY_INCLUDED_SHARED_BINDINGS_NATIVEIO_TOUCHIN_H__

View File

@ -41,6 +41,7 @@
#include "shared-bindings/nativeio/I2C.h"
#include "shared-bindings/nativeio/PWMOut.h"
#include "shared-bindings/nativeio/SPI.h"
#include "shared-bindings/nativeio/TouchIn.h"
#include "common-hal/nativeio/types.h"
#include "shared-bindings/nativeio/__init__.h"
@ -114,6 +115,7 @@ STATIC const mp_rom_map_elem_t nativeio_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&nativeio_i2c_type) },
{ MP_ROM_QSTR(MP_QSTR_PWMOut), MP_ROM_PTR(&nativeio_pwmout_type) },
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&nativeio_spi_type) },
{ MP_ROM_QSTR(MP_QSTR_TouchIn), MP_ROM_PTR(&nativeio_touchin_type) },
};
STATIC MP_DEFINE_CONST_DICT(nativeio_module_globals, nativeio_module_globals_table);