Skip to content

Instantly share code, notes, and snippets.

@netskink
Last active June 30, 2017 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netskink/ec3cc4078d20be0f2fb56a67fa50f10d to your computer and use it in GitHub Desktop.
Save netskink/ec3cc4078d20be0f2fb56a67fa50f10d to your computer and use it in GitHub Desktop.
touch screen linear touch does not scale/normalize
// TODO: fix this comment
// this is the one in Applications/TouchSensing/TouchSensing_Linear/Inc folder
// This one is being used
/**
******************************************************************************
* @file TouchSensing\TouchSensing_Linear\inc\tsl_conf.h
* @author MCD Application Team
* @version V1.7.0
* @date 04-November-2016
* @brief TSC configuration file.
* @note This file must be copied in the application folder with the 'tsl_conf.h' name.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
*
* 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. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __TSL_CONF_H
#define __TSL_CONF_H
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+++++++++++++++++++++++++++ COMMON PARAMETERS ++++++++++++++++++++++++++++++*/
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/** @defgroup Common_Parameters Common Parameters
* @{ */
/*============================================================================*/
/* Number of elements */
/*============================================================================*/
/** @defgroup Common_Parameters_Number_Of_Elements 01 - Number of elements
* @{ */
/** Total number of channels in application (range=1..255)
*/
// all #define TSLPRM_TOTAL_CHANNELS (7)
#define TSLPRM_TOTAL_CHANNELS (5)
/** Total number of banks in application (range=1..255)
*/
//#define TSLPRM_TOTAL_BANKS (3)
#define TSLPRM_TOTAL_BANKS (1)
/** Total number of "Extended" TouchKeys in application (range=0..255)
*/
//#define TSLPRM_TOTAL_TOUCHKEYS (2)
#define TSLPRM_TOTAL_TOUCHKEYS (0)
/** Total number of "Basic" TouchKeys in application (range=0..255)
*/
#define TSLPRM_TOTAL_TOUCHKEYS_B (0)
/** Total number of "Extended" Linear and Rotary sensors in application (range=0..255)
- Count also the 1-channel linear sensor used as TouchKey
*/
#define TSLPRM_TOTAL_LINROTS (1)
/** Total number of "Basic" Linear and Rotary sensors in application (range=0..255)
- Count also the 1-channel linear sensor used as TouchKey
*/
#define TSLPRM_TOTAL_LINROTS_B (0)
/** Total number of sensors/objects in application (range=1..255)
- Count all TouchKeys, Linear and Rotary sensors
*/
//#define TSLPRM_TOTAL_OBJECTS (3)
#define TSLPRM_TOTAL_OBJECTS (1)
/** @} Common_Parameters_Number_Of_Elements */
/*============================================================================*/
/* Optional features */
/*============================================================================*/
/** @defgroup Common_Parameters_Options 02 - Optional features
* @{ */
/** Record the last measure (0=No, 1=Yes)
- If No the measure is recalculated using the Reference and Delta
*/
#define TSLPRM_USE_MEAS (1)
/** Proximity detection usage (0=No, 1=Yes)
*/
#define TSLPRM_USE_PROX (0) // was 1
/** Zone management usage (0=No, 1=Yes)
*/
#define TSLPRM_USE_ZONE (0)
/** @} Common_Parameters_Options */
/*============================================================================*/
/* Acquisition limits */
/*============================================================================*/
/** @defgroup Common_Parameters_Acquisition_Limits 03 - Acquisition limits
* @{ */
/** Minimum acquisition measurement (range=0..65535)
- This is the minimum acceptable value for the acquisition measure.
- The acquisition will be in error if the measure is below this value.
*/
#define TSLPRM_ACQ_MIN (10)
/** Maximum acquisition measurement (range=255, 511, 1023, 2047, 8191, 16383)
- This is the maximum acceptable value for the acquisition measure.
- The acquisition will be in error if the measure is above this value.
*/
#define TSLPRM_ACQ_MAX (8191)
/** @} Common_Parameters_Acquisition_Limits */
/*============================================================================*/
/* Calibration */
/*============================================================================*/
/** @defgroup Common_Parameters_Calibration 04 - Calibration
* @{ */
/** Number of calibration samples (range=4, 8, 16)
- Low value = faster calibration but less precision.
- High value = slower calibration but more precision.
*/
#define TSLPRM_CALIB_SAMPLES (4)
/** Delay in measurement samples before starting the calibration (range=0..40)
- This is useful if a noise filter is used.
- Write 0 to disable the delay.
*/
#define TSLPRM_CALIB_DELAY (0)
/** @} Common_Parameters_Calibration */
/*============================================================================*/
/* Thresholds for TouchKey sensors */
/*============================================================================*/
/** @defgroup Common_Parameters_TouchKey_Thresholds 05 - Thresholds for TouchKey sensors
* @{ */
/** TouchKeys Proximity state input threshold (range=0..255)
- Enter Proximity state if delta is above
*/
#define TSLPRM_TKEY_PROX_IN_TH (10)
/** TouchKeys Proximity state output threshold (range=0..255)
- Exit Proximity state if delta is below
*/
#define TSLPRM_TKEY_PROX_OUT_TH (5)
/** TouchKeys Detect state input threshold (range=0..255)
- Enter Detect state if delta is above
*/
#define TSLPRM_TKEY_DETECT_IN_TH (120)
/** TouchKeys Detect state output threshold (range=0..255)
- Exit Detect state if delta is below
*/
#define TSLPRM_TKEY_DETECT_OUT_TH (110)
/** TouchKeys re-Calibration threshold (range=0..255)
- @warning The value is inverted in the sensor state machine
- Enter Calibration state if delta is below
*/
#define TSLPRM_TKEY_CALIB_TH (120)
/** TouchKey, Linear and Rotary sensors thresholds coefficient (range=0..4)
This multiplier coefficient is applied on Detect and Re-Calibration thresholds only.
- 0: feature disabled
- 1: thresholds x 2
- 2: thresholds x 4
- 3: thresholds x 8
- 4: thresholds x 16
*/
#define TSLPRM_COEFF_TH (0)
/** @} Common_Parameters_TouchKey_Thresholds */
/*============================================================================*/
/* Thresholds for Linear and Rotary sensors */
/*============================================================================*/
/** @defgroup Common_Parameters_LinRot_Thresholds 06 - Thresholds for Linear and Rotary sensors
* @{ */
/** Linear/Rotary Proximity state input threshold (range=0..255)
- Enter Proximity state if delta is above
*/
#define TSLPRM_LINROT_PROX_IN_TH (10)
/** Linear/Rotary Proximity state output threshold (range=0..255)
- Exit Proximity state if delta is below
*/
#define TSLPRM_LINROT_PROX_OUT_TH (5)
/** Linear/Rotary Detect state input threshold (range=0..255)
- Enter Detect state if delta is above
*/
#define TSLPRM_LINROT_DETECT_IN_TH (80)
/** Linear/Rotary Detect state output threshold (range=0..255)
- Exit Detect state if delta is below
*/
#define TSLPRM_LINROT_DETECT_OUT_TH (75)
/** Linear/Rotary re-Calibration threshold (range=0..255)
- @warning The value is inverted in the sensor state machine
- Enter Calibration state if delta is below
- A low absolute value will result in a higher sensitivity and thus some spurious
recalibration may be issued.
*/
#define TSLPRM_LINROT_CALIB_TH (80)
/** Linear/Rotary Delta normalization (0=No, 1=Yes)
- When this parameter is set, a coefficient is applied on all Delta of all sensors
in order to normalize them and to improve the position calculation.
- These coefficients must be defined in a constant table in the application (see Library examples).
- The MSB is the coefficient integer part, the LSB is the coefficient real part.
- Examples:
- To apply a factor 1.10:
0x01 to the MSB
0x1A to the LSB (0.10 x 256 = 25.6 -> rounded to 26 = 0x1A)
- To apply a factor 0.90:
0x00 to the MSB
0xE6 to the LSB (0.90 x 256 = 230.4 -> rounded to 230 = 0xE6)
- To apply no factor:
0x01 to the MSB
0x00 to the LSB
*/
#define TSLPRM_LINROT_USE_NORMDELTA (1) // does this need to be set to use coefficients?
/** @} Common_Parameters_LinRot_Thresholds */
/*============================================================================*/
/* Linear/Rotary sensors used */
/*============================================================================*/
/** @defgroup Common_Parameters_LinRot_Used 07 - Linear/Rotary sensors used
* @{ */
/** Select which Linear and Rotary sensors you use in your application.
- 0 = Not Used
- 1 = Used
LIN = Linear sensor
ROT = Rotary sensor
M1 = Mono electrodes design with 0/255 position at extremities of the sensor
M2 = Mono electrodes design
H = Half-ended electrodes design
D = Dual electrodes design
*/
#define TSLPRM_USE_3CH_LIN_M1 (0) // 0 ch1 ch2 ch3 255
#define TSLPRM_USE_3CH_LIN_M2 (0) // ch1 0 ch2 255 ch3
#define TSLPRM_USE_3CH_LIN_H (0) // this is used by discovery
#define TSLPRM_USE_3CH_ROT_M (0)
#define TSLPRM_USE_4CH_LIN_M1 (0)
#define TSLPRM_USE_4CH_LIN_M2 (0)
#define TSLPRM_USE_4CH_LIN_H (0)
#define TSLPRM_USE_4CH_ROT_M (0)
#define TSLPRM_USE_5CH_LIN_M1 (1) // this is used by GP board
#define TSLPRM_USE_5CH_LIN_M2 (0)
#define TSLPRM_USE_5CH_LIN_H (0)
#define TSLPRM_USE_5CH_ROT_M (0)
#define TSLPRM_USE_5CH_ROT_D (0)
#define TSLPRM_USE_6CH_LIN_M1 (0)
#define TSLPRM_USE_6CH_LIN_M2 (0)
#define TSLPRM_USE_6CH_LIN_H (0)
#define TSLPRM_USE_6CH_ROT_M (0)
/** @} Common_Parameters_LinRot_used */
/*============================================================================*/
/* Linear/Rotary sensors position */
/*============================================================================*/
/** @defgroup Common_Parameters_LinRot_Position 08 - Linear/Rotary sensors position
* @{ */
/** Position resolution in number of bits (range=1..8)
- A Low value will result in a low resolution and will be less subject to noise.
- A High value will result in a high resolution and will be more subject to noise.
*/
#define TSLPRM_LINROT_RESOLUTION (4)
/** Direction change threshold in position unit (range=0..255)
- Defines the default threshold used during the change direction process.
- A Low value will result in a faster direction change.
- A High value will result in a slower direction change.
*/
#define TSLPRM_LINROT_DIR_CHG_POS (10)
/** Direction change debounce (range=0..63)
- Defines the default integrator counter used during the change direction process.
- This counter is decremented when the same change in the position is detected and the direction will
change after this counter reaches zero.
- A Low value will result in a faster direction change.
- A High value will result in a slower direction change.
*/
#define TSLPRM_LINROT_DIR_CHG_DEB (1)
/** @} Common_Parameters_LinRot_Position */
/*============================================================================*/
/* Debounce counters */
/*============================================================================*/
/** @defgroup Common_Parameters_Debounce 09 - Debounce counters
* @{ */
/** Proximity state debounce in samples unit (range=0..63)
- A Low value will result in a higher sensitivity during the Proximity detection but with less noise filtering.
- A High value will result in improving the system noise immunity but will increase the system response time.
*/
#define TSLPRM_DEBOUNCE_PROX (2)
/** Detect state debounce in samples unit (range=0..63)
- A Low value will result in a higher sensitivity during the detection but with less noise filtering.
- A High value will result in improving the system noise immunity but will increase the system response time.
*/
#define TSLPRM_DEBOUNCE_DETECT (2)
/** Release state debounce in samples unit (range=0..63)
- A Low value will result in a higher sensitivity during the end-detection but with less noise filtering.
- A High value will result in a lower sensitivity during the end-detection but with more noise filtering.
*/
#define TSLPRM_DEBOUNCE_RELEASE (2)
/** Re-calibration state debounce in samples unit (range=0..63)
- A Low value will result in a higher sensitivity during the recalibration but with less noise filtering.
- A High value will result in a lower sensitivity during the recalibration but with more noise filtering.
*/
#define TSLPRM_DEBOUNCE_CALIB (3)
/** Error state debounce in samples unit (range=0..63)
- A Low value will result in a higher sensitivity to enter in error state.
- A High value will result in a lower sensitivity to enter in error state.
*/
#define TSLPRM_DEBOUNCE_ERROR (3)
/** @} Common_Parameters_Debounce */
/*============================================================================*/
/* Environment Change System (ECS) */
/*============================================================================*/
/** @defgroup Common_Parameters_ECS 10 - ECS
* @{ */
/** Environment Change System Slow K factor (range=0..255)
- The higher value is K, the faster is the response time.
*/
#define TSLPRM_ECS_K_SLOW (10)
/** Environment Change System Fast K factor (range=0..255)
- The higher value is K, the faster is the response time.
*/
#define TSLPRM_ECS_K_FAST (20)
/** Environment Change System delay in msec (range=0..5000)
- The ECS will be started after this delay and when all sensors are in Release state.
*/
#define TSLPRM_ECS_DELAY (500)
/** @} Common_Parameters_ECS */
/*============================================================================*/
/* Detection Time Out (DTO) */
/*============================================================================*/
/** @defgroup Common_Parameters_DTO 11 - DTO
* @{ */
/** Detection Time Out delay in seconds (range=0..63)
- Value 0: DTO processing not compiled in the code (to gain size if not used).
- Value 1: Default time out infinite.
- Value between 2 and 63: Default time out between value n-1 and n.
- Examples:
- With a DTO equal to 2, the time out is between 1s and 2s.
- With a DTO equal to 63, the time out is between 62s and 63s.
@note The DTO can be changed in run-time by the application only if the
default value is between 1 and 63.
*/
#define TSLPRM_DTO (5)
/** @} Common_Parameters_DTO */
/*============================================================================*/
/* Detection Exclusion System (DXS) */
/*============================================================================*/
/** @defgroup Common_Parameters_DXS 12 - DXS
* @{ */
/** Detection Exclusion System (0=No, 1=Yes)
*/
#define TSLPRM_USE_DXS (0)
/** @} Common_Parameters_DXS */
/*============================================================================*/
/* Miscellaneous parameters */
/*============================================================================*/
/** @defgroup Common_Parameters_Misc 13 - Miscellaneous
* @{ */
/** Timing tick frequency in Hz (range=125, 250, 500, 1000, 2000)
- Result to a timing interrupt respectively every 8ms, 4ms, 2ms, 1ms, 0.5ms
*/
#define TSLPRM_TICK_FREQ (1000)
/** Delay for discharging Cx and Cs capacitors (range=0..65535)
- The value corresponds to the Softdelay function parameter.
- 500 gives around 63 \B5s delay whatever HCLK
- 1000 gives around 125 \B5s delay whatever HCLK
- 2000 gives around 250 \B5s delay whatever HCLK
*/
#define TSLPRM_DELAY_DISCHARGE_ALL (1000)
/** IOs default mode when no on-going acquisition (range=0..1)
- 0: Output push-pull low
- 1: Input floating
@note To ensure a correct operation in noisy environment, this parameter should
be configured to output push-pull low (excepted for Linear sensors).
*/
#define TSLPRM_IODEF (1)
/** @} Common_Parameters_Misc */
/** @} Common_Parameters */
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+++++++++++++++++++++++++ MCU AND ACQUISITION SELECTION ++++++++++++++++++++*/
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#include "stm32f0xx.h" /* Select the file corresponding to the device in use (i.e. stm32f3xx.h, stm32f0xx.h, ...) */
#include "tsl_acq_tsc.h" /* The TSC acquisition is used for this device. Do not change it! */
#endif /* __TSL_CONF_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#include "tsl_user.h"
/* define for the linear */
#define LINEAR_DETECT ((MyLinRots[0].p_Data->StateId == TSL_STATEID_DETECT) || \
(MyLinRots[0].p_Data->StateId == TSL_STATEID_DEB_RELEASE_DETECT))
#define LINEAR_POSITION (MyLinRots[0].p_Data->Position)
/*============================================================================*/
/* Channels */
/*============================================================================*/
/* Source and Configuration (ROM) */
CONST TSL_ChannelSrc_T MyChannels_Src[TSLPRM_TOTAL_CHANNELS] = {
// The five linrot channels
{ CHANNEL_0_SRC, CHANNEL_0_IO_MSK, CHANNEL_0_GRP_MSK },
{ CHANNEL_1_SRC, CHANNEL_1_IO_MSK, CHANNEL_1_GRP_MSK },
{ CHANNEL_2_SRC, CHANNEL_2_IO_MSK, CHANNEL_2_GRP_MSK },
{ CHANNEL_3_SRC, CHANNEL_3_IO_MSK, CHANNEL_3_GRP_MSK },
{ CHANNEL_4_SRC, CHANNEL_4_IO_MSK, CHANNEL_4_GRP_MSK }
// The three touchkey channels
// { CHANNEL_5_SRC, CHANNEL_5_IO_MSK, CHANNEL_5_GRP_MSK },
// { CHANNEL_6_SRC, CHANNEL_6_IO_MSK, CHANNEL_6_GRP_MSK }
};
/* Destination (ROM) */
CONST TSL_ChannelDest_T MyChannels_Dest[TSLPRM_TOTAL_CHANNELS] = {
// The five linrot channels
{ CHANNEL_0_DEST },
{ CHANNEL_1_DEST },
{ CHANNEL_2_DEST },
{ CHANNEL_3_DEST },
{ CHANNEL_4_DEST }
// The two touchkey channels
// { CHANNEL_5_DEST },
// { CHANNEL_6_DEST }
};
/* Data (RAM) */
TSL_ChannelData_T MyChannels_Data[TSLPRM_TOTAL_CHANNELS];
/*============================================================================*/
/* Banks */
/*============================================================================*/
/* List (ROM) */
CONST TSL_Bank_T MyBanks[TSLPRM_TOTAL_BANKS] = {
// The one linrot bank
{&MyChannels_Src[0], &MyChannels_Dest[0], MyChannels_Data, BANK_0_NBCHANNELS, BANK_0_MSK_CHANNELS, BANK_0_MSK_GROUPS},
// The two touchkey bankss
// {&MyChannels_Src[5], &MyChannels_Dest[5], MyChannels_Data, BANK_1_NBCHANNELS, BANK_1_MSK_CHANNELS, BANK_1_MSK_GROUPS},
// {&MyChannels_Src[6], &MyChannels_Dest[6], MyChannels_Data, BANK_2_NBCHANNELS, BANK_2_MSK_CHANNELS, BANK_2_MSK_GROUPS}
};
/*============================================================================*/
/* Touchkey sensors */
/*============================================================================*/
/* Data (RAM) */
//TSL_TouchKeyData_T MyTKeys_Data[TSLPRM_TOTAL_TKEYS];
/* Parameters (RAM) */
//TSL_TouchKeyParam_T MyTKeys_Param[TSLPRM_TOTAL_TKEYS];
/* State Machine (ROM) */
//void MyTKeys_ErrorStateProcess(void);
//void MyTKeys_OffStateProcess(void);
//CONST TSL_State_T MyTKeys_StateMachine[] = {
// /* Calibration states */
// /* 0 */ { TSL_STATEMASK_CALIB, TSL_tkey_CalibrationStateProcess },
// /* 1 */ { TSL_STATEMASK_DEB_CALIB, TSL_tkey_DebCalibrationStateProcess },
// /* Release states */
// /* 2 */ { TSL_STATEMASK_RELEASE, TSL_tkey_ReleaseStateProcess },
//#if TSLPRM_USE_PROX > 0
// /* 3 */ { TSL_STATEMASK_DEB_RELEASE_PROX, TSL_tkey_DebReleaseProxStateProcess },
//#else
// /* 3 */ { TSL_STATEMASK_DEB_RELEASE_PROX, 0 },
//#endif
// /* 4 */ { TSL_STATEMASK_DEB_RELEASE_DETECT, TSL_tkey_DebReleaseDetectStateProcess },
// /* 5 */ { TSL_STATEMASK_DEB_RELEASE_TOUCH, TSL_tkey_DebReleaseTouchStateProcess },
//#if TSLPRM_USE_PROX > 0
// /* Proximity states */
// /* 6 */ { TSL_STATEMASK_PROX, TSL_tkey_ProxStateProcess },
// /* 7 */ { TSL_STATEMASK_DEB_PROX, TSL_tkey_DebProxStateProcess },
// /* 8 */ { TSL_STATEMASK_DEB_PROX_DETECT, TSL_tkey_DebProxDetectStateProcess },
// /* 9 */ { TSL_STATEMASK_DEB_PROX_TOUCH, TSL_tkey_DebProxTouchStateProcess },
//#else
// /* 6 */ { TSL_STATEMASK_PROX, 0 },
// /* 7 */ { TSL_STATEMASK_DEB_PROX, 0 },
// /* 8 */ { TSL_STATEMASK_DEB_PROX_DETECT, 0 },
// /* 9 */ { TSL_STATEMASK_DEB_PROX_TOUCH, 0 },
//#endif
// /* Detect states */
// /* 10 */ { TSL_STATEMASK_DETECT, TSL_tkey_DetectStateProcess },
// /* 11 */ { TSL_STATEMASK_DEB_DETECT, TSL_tkey_DebDetectStateProcess },
// /* Touch state */
// /* 12 */ { TSL_STATEMASK_TOUCH, TSL_tkey_TouchStateProcess },
// /* Error states */
// /* 13 */ { TSL_STATEMASK_ERROR, MyTKeys_ErrorStateProcess },
// /* 14 */ { TSL_STATEMASK_DEB_ERROR_CALIB, TSL_tkey_DebErrorStateProcess },
// /* 15 */ { TSL_STATEMASK_DEB_ERROR_RELEASE, TSL_tkey_DebErrorStateProcess },
// /* 16 */ { TSL_STATEMASK_DEB_ERROR_PROX, TSL_tkey_DebErrorStateProcess },
// /* 17 */ { TSL_STATEMASK_DEB_ERROR_DETECT, TSL_tkey_DebErrorStateProcess },
// /* 18 */ { TSL_STATEMASK_DEB_ERROR_TOUCH, TSL_tkey_DebErrorStateProcess },
// /* Other states */
// /* 19 */ { TSL_STATEMASK_OFF, MyTKeys_OffStateProcess }
//};
/* Methods for "extended" type (ROM) */
//CONST TSL_TouchKeyMethods_T MyTKeys_Methods = {
// TSL_tkey_Init,
// TSL_tkey_Process
//};
/* TouchKeys list (ROM) */
//CONST TSL_TouchKey_T MyTKeys[TSLPRM_TOTAL_TKEYS] = {
// { &MyTKeys_Data[0], &MyTKeys_Param[0], &MyChannels_Data[CHANNEL_5_DEST], MyTKeys_StateMachine, &MyTKeys_Methods },
// { &MyTKeys_Data[1], &MyTKeys_Param[1], &MyChannels_Data[CHANNEL_6_DEST], MyTKeys_StateMachine, &MyTKeys_Methods }
//};
/*============================================================================*/
/* Linear and Rotary sensors */
/*============================================================================*/
/* Data (RAM) */
TSL_LinRotData_T MyLinRots_Data[TSLPRM_TOTAL_LINROTS]; // extended
//TSL_LinRotData_T MyLinRots_Data[TSLPRM_TOTAL_LINROTS_B]; // basic
/* Parameters (RAM) */
TSL_LinRotParam_T MyLinRots_Param[TSLPRM_TOTAL_LINROTS]; // extended
//TSL_LinRotParam_T MyLinRots_Param[TSLPRM_TOTAL_LINROTS_B]; // basic
/* State Machine (ROM) */
void MyLinRots_ErrorStateProcess(void);
void MyLinRots_OffStateProcess(void);
CONST TSL_State_T MyLinRots_StateMachine[] = {
/* Calibration states */
/* 0 */ { TSL_STATEMASK_CALIB, TSL_linrot_CalibrationStateProcess },
/* 1 */ { TSL_STATEMASK_DEB_CALIB, TSL_linrot_DebCalibrationStateProcess },
/* Release states */
/* 2 */ { TSL_STATEMASK_RELEASE, TSL_linrot_ReleaseStateProcess },
#if TSLPRM_USE_PROX > 0
/* 3 */ { TSL_STATEMASK_DEB_RELEASE_PROX, TSL_linrot_DebReleaseProxStateProcess },
#else
/* 3 */ { TSL_STATEMASK_DEB_RELEASE_PROX, 0 },
#endif
/* 4 */ { TSL_STATEMASK_DEB_RELEASE_DETECT, TSL_linrot_DebReleaseDetectStateProcess },
/* 5 */ { TSL_STATEMASK_DEB_RELEASE_TOUCH, TSL_linrot_DebReleaseTouchStateProcess },
#if TSLPRM_USE_PROX > 0
/* Proximity states */
/* 6 */ { TSL_STATEMASK_PROX, TSL_linrot_ProxStateProcess },
/* 7 */ { TSL_STATEMASK_DEB_PROX, TSL_linrot_DebProxStateProcess },
/* 8 */ { TSL_STATEMASK_DEB_PROX_DETECT, TSL_linrot_DebProxDetectStateProcess },
/* 9 */ { TSL_STATEMASK_DEB_PROX_TOUCH, TSL_linrot_DebProxTouchStateProcess },
#else
/* 6 */ { TSL_STATEMASK_PROX, 0 },
/* 7 */ { TSL_STATEMASK_DEB_PROX, 0 },
/* 8 */ { TSL_STATEMASK_DEB_PROX_DETECT, 0 },
/* 9 */ { TSL_STATEMASK_DEB_PROX_TOUCH, 0 },
#endif
/* Detect states */
/* 10 */ { TSL_STATEMASK_DETECT, TSL_linrot_DetectStateProcess },
/* 11 */ { TSL_STATEMASK_DEB_DETECT, TSL_linrot_DebDetectStateProcess },
/* Touch state */
/* 12 */ { TSL_STATEMASK_TOUCH, TSL_linrot_TouchStateProcess },
/* Error states */
/* 13 */ { TSL_STATEMASK_ERROR, MyLinRots_ErrorStateProcess },
/* 14 */ { TSL_STATEMASK_DEB_ERROR_CALIB, TSL_linrot_DebErrorStateProcess },
/* 15 */ { TSL_STATEMASK_DEB_ERROR_RELEASE, TSL_linrot_DebErrorStateProcess },
/* 16 */ { TSL_STATEMASK_DEB_ERROR_PROX, TSL_linrot_DebErrorStateProcess },
/* 17 */ { TSL_STATEMASK_DEB_ERROR_DETECT, TSL_linrot_DebErrorStateProcess },
/* 18 */ { TSL_STATEMASK_DEB_ERROR_TOUCH, TSL_linrot_DebErrorStateProcess },
/* Other states */
/* 19 */ { TSL_STATEMASK_OFF, MyLinRots_OffStateProcess }
};
/* Methods for "extended" type (ROM) */
CONST TSL_LinRotMethods_T MyLinRots_Methods = {
TSL_linrot_Init,
TSL_linrot_Process,
TSL_linrot_CalcPos
};
// This might require that we set the value below which resides in the tsl_conf.h file
// to one.
// In tsl_conf.h #define TSLPRM_LINROT_USE_NORMDELTA (1) // does this need to be set to use coefficients?
/* Delta Normalization Process
The MSB is the integer part, the LSB is the real part
Examples:
- To apply a factor 1.10:
0x01 to the MSB
0x1A to the LSB (0.10 x 256 = 25.6 -> rounded to 26 = 0x1A)
- To apply a factor 0.90:
0x00 to the MSB
0xE6 to the LSB (0.90 x 256 = 230.4 -> rounded to 230 = 0xE6)
*/
// This is supposed to change result
// Default
//CONST uint16_t MyLinRot0_DeltaCoeff[5] = {0x0100, 0x0100, 0x0100, 0x0100, 0x0100};
//CONST uint16_t MyLinRot0_DeltaCoeff[5] = {(0x0100*1270.0/920.0), (0x0100*1270.0/1000.0), (0x0100*1270.0/928.0), (0x0100*1270.0/1040.0), (0x0100*1270.0/1270.0)}; // CH0, CH1, CH2, .. CH4
//CONST uint16_t MyLinRot0_DeltaCoeff[5] = {353, 325, 350, 312, 256}; // CH0, CH1, CH2, .. CH4
//CONST uint16_t MyLinRot0_DeltaCoeff[5] = {375, 325, 350, 312, 256}; // CH0, CH1, CH2, .. CH4
// calculated
//CONST uint16_t MyLinRot0_DeltaCoeff[5] = {0x15c, 0x13b, 0x158, 0x138, 0x100}; // CH0, CH1, CH2, .. CH4
// Tweaked
CONST uint16_t MyLinRot0_DeltaCoeff[5] = {0x15c, 0x13b, 0x1b8, 0x138, 0x100}; // CH0, CH1, CH2, .. CH4
/* LinRots list (ROM)*/
CONST TSL_LinRot_T MyLinRots[TSLPRM_TOTAL_LINROTS] = { // extended
//CONST TSL_LinRotB_T MyLinRots[TSLPRM_TOTAL_LINROTS_B] = { // basic
{
/* LinRot sensor 0 = S1 */
&MyLinRots_Data[0],
&MyLinRots_Param[0],
&MyChannels_Data[CHANNEL_0_DEST], // first channel data
5, /* Number of channels */ //
MyLinRot0_DeltaCoeff,
(TSL_tsignPosition_T *) TSL_POSOFF_5CH_LIN_M1,
TSL_SCTCOMP_5CH_LIN_M1,
TSL_POSCORR_5CH_LIN_M1,
// for extended
MyLinRots_StateMachine,
&MyLinRots_Methods
}
};
/*============================================================================*/
/* Generic Objects */
/*============================================================================*/
/* List (ROM) */
CONST TSL_Object_T MyObjects[TSLPRM_TOTAL_OBJECTS] = {
// lin rot
{ TSL_OBJ_LINEAR, (TSL_LinRot_T *)&MyLinRots[0] } // extended
// touchkeys
// { TSL_OBJ_TOUCHKEY, (TSL_TouchKey_T *)&MyTKeys[0] },
// { TSL_OBJ_TOUCHKEY, (TSL_TouchKey_T *)&MyTKeys[1] }
};
/* Group (RAM) */
TSL_ObjectGroup_T MyObjGroup = {
&MyObjects[0], /* First object */
TSLPRM_TOTAL_OBJECTS, /* Number of objects */
0x00, /* State mask reset value */
TSL_STATE_NOT_CHANGED /* Current state */
};
/*============================================================================*/
/* TSL Common Parameters placed in RAM or ROM */
/* --> external declaration in tsl_conf.h */
/*============================================================================*/
TSL_Params_T TSL_Params = {
TSLPRM_ACQ_MIN,
TSLPRM_ACQ_MAX,
TSLPRM_CALIB_SAMPLES,
TSLPRM_DTO,
#if TSLPRM_TOTAL_TKEYS > 0
MyTKeys_StateMachine, /* Default state machine for TKeys */
&MyTKeys_Methods, /* Default methods for TKeys */
#endif
#if TSLPRM_TOTAL_LNRTS > 0
MyLinRots_StateMachine, /* Default state machine for LinRots */
&MyLinRots_Methods /* Default methods for LinRots */
#endif
};
/* Private functions prototype -----------------------------------------------*/
/* Global variables ----------------------------------------------------------*/
__IO TSL_tTick_ms_T ECSLastTick; /* Hold the last time value for ECS */
/**
* @brief Initialize the STMTouch Driver
* @param None
* @retval None
*/
void tsl_user_Init(void) {
TSL_obj_GroupInit(&MyObjGroup); /* Init Objects */
TSL_Init(MyBanks); /* Init acquisition module */
tsl_user_SetThresholds(); /* Init thresholds for each object individually (optional) */
}
/**
* @brief Execute STMTouch Driver main State machine
* @param None
* @retval status Return TSL_STATUS_OK if the acquisition is done
*/
tsl_user_status_t tsl_user_Exec(void)
{
static uint32_t idx_bank = 0;
static uint32_t config_done = 0;
tsl_user_status_t status = TSL_USER_STATUS_BUSY;
/* Configure and start bank acquisition */
if (!config_done)
{
TSL_acq_BankConfig(idx_bank);
TSL_acq_BankStartAcq();
config_done = 1;
}
/* Check end of acquisition (polling mode) and read result */
if (TSL_acq_BankWaitEOC() == TSL_STATUS_OK) {
STMSTUDIO_LOCK;
TSL_acq_BankGetResult(idx_bank, 0, 0);
STMSTUDIO_UNLOCK;
idx_bank++; /* Next bank */
config_done = 0;
}
/* Process objects, DxS and ECS
Check if all banks have been acquired
*/
if (idx_bank > TSLPRM_TOTAL_BANKS-1)
{
/* Reset flags for next banks acquisition */
idx_bank = 0;
config_done = 0;
/* Process Objects */
TSL_obj_GroupProcess(&MyObjGroup);
/* DxS processing (if TSLPRM_USE_DXS option is set) */
TSL_dxs_FirstObj(&MyObjGroup);
/* ECS every 100ms */
if (TSL_tim_CheckDelay_ms(100, &ECSLastTick) == TSL_STATUS_OK)
{
if (TSL_ecs_Process(&MyObjGroup) == TSL_STATUS_OK)
{
status = TSL_USER_STATUS_OK_ECS_ON;
}
else
{
status = TSL_USER_STATUS_OK_ECS_OFF;
}
}
else
{
status = TSL_USER_STATUS_OK_NO_ECS;
}
}
else
{
status = TSL_USER_STATUS_BUSY;
}
return status;
}
/**
* @brief Set thresholds for each object (optional).
* @param None
* @retval None
*/
void tsl_user_SetThresholds(void)
{
/* Example: Decrease the Detect thresholds for the TKEY 0
MyTKeys_Param[0].DetectInTh -= 10;
MyTKeys_Param[0].DetectOutTh -= 10;
*/
}
/**
* @brief Executed when a sensor is in Error state
* @param None
* @retval None
*/
void MyTKeys_ErrorStateProcess(void)
{
/* Add here your own processing when a sensor is in Error state */
}
/**
* @brief Executed when a sensor is in Off state
* @param None
* @retval None
*/
void MyTKeys_OffStateProcess(void)
{
/* Add here your own processing when a sensor is in Off state */
}
/**
* @brief Executed when a sensor is in Error state
* @param None
* @retval None
*/
void MyLinRots_ErrorStateProcess(void)
{
/* Add here your own processing when a sensor is in Error state */
}
/**
* @brief Executed when a sensor is in Off state
* @param None
* @retval None
*/
void MyLinRots_OffStateProcess(void)
{
/* Add here your own processing when a sensor is in Off state */
}
/**
* @brief This function handles a tick.
* @param None
* @retval None
*/
void User_Tick_Management(void) {
// tick counters set to zero first time this routine is called
static uint32_t tempo_50ms=0;
static uint32_t tempo_100ms=0;
static uint32_t tempo_200ms=0;
static uint32_t tempo_300ms=0;
static uint32_t tempo_400ms=0;
static uint32_t tempo_500ms=0;
static uint32_t tempo_1000ms=0;
// increment each counter, but bound to max count for each
tempo_50ms++;
tempo_100ms++;
tempo_200ms++;
tempo_300ms++;
tempo_400ms++;
tempo_500ms++;
tempo_1000ms++;
tempo_50ms%=50;
tempo_100ms%=100;
tempo_200ms%=200;
tempo_300ms%=300;
tempo_400ms%=400;
tempo_500ms%=500;
tempo_1000ms%=1000;
// LINEAR_POSITION = MyLinRots[0].p_Data->Position
if (LINEAR_POSITION < 4) {
if (tempo_1000ms==0) {
BSP_LED_Toggle(LED2);
}
} else if (LINEAR_POSITION < 8) {
if (tempo_500ms==0) {
BSP_LED_Toggle(LED2);
}
} else if (LINEAR_POSITION < 12) {
if (tempo_200ms==0) {
BSP_LED_Toggle(LED2);
}
} else if (LINEAR_POSITION < 16) {
if (tempo_100ms==0) {
BSP_LED_Toggle(LED2);
}
} else { // pos >= 16
if (tempo_50ms==0) {
BSP_LED_Toggle(LED2);
}
}
}
/**
* @brief Display sensors information on LEDs
* @param status TSL user status
* @retval None
*/
void Process_Sensors(tsl_user_status_t status) {
//// /* LED1 is ON when TS1 on board is touched */
// if (MyTKeys[0].p_Data->StateId == TSL_STATEID_DETECT){
// BSP_LED_On(LED3);
// } else {
// BSP_LED_Off(LED3);
// }
//// /* LED2 is ON when TS2 on board is touched */
// if (MyTKeys[1].p_Data->StateId == TSL_STATEID_DETECT) {
// BSP_LED_On(LED4);
// } else {
// BSP_LED_Off(LED4);
// }
#ifdef isthisused
/* ECS information */
switch (status){
case TSL_USER_STATUS_OK_ECS_OFF:
BSP_LED_Off(LED5);
break;
case TSL_USER_STATUS_OK_ECS_ON:
BSP_LED_Toggle(LED5);
break;
default:
break;
}
#endif
if (LINEAR_DETECT) {
BSP_LED_On(LED1);
} else{
BSP_LED_Off(LED1);
}
}
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __TSL_USER_H
#define __TSL_USER_H
#include "tsl.h"
#include "stm32f0xx_hal.h"
#include "stm32f091r_gp-board.h"
/* Select if you use STMStudio software (0=No, 1=Yes) */
#define USE_STMSTUDIO (1)
#if USE_STMSTUDIO > 0
#include "stmCriticalSection.h"
#define STMSTUDIO_LOCK {enterLock();}
#define STMSTUDIO_UNLOCK {exitLock();}
#else
#define STMSTUDIO_LOCK
#define STMSTUDIO_UNLOCK
#endif
typedef enum {
TSL_USER_STATUS_BUSY = 0, /**< The bank acquisition is on-going */
TSL_USER_STATUS_OK_NO_ECS = 1, /**< The bank acquisition is ok, no time for ECS */
TSL_USER_STATUS_OK_ECS_ON = 2, /**< The bank acquisition is ok, ECS finished */
TSL_USER_STATUS_OK_ECS_OFF = 3 /**< The bank acquisition is ok, ECS not executed */
} tsl_user_status_t;
// The five linrot channels
#define CHANNEL_0_IO_MSK (TSC_GROUP1_IO3)
#define CHANNEL_0_GRP_MSK (TSC_GROUP1)
#define CHANNEL_0_SRC (TSC_GROUP1_IDX) /* Index in source register (TSC->IOGXCR[]) */
#define CHANNEL_0_DEST (0) /* Index in destination result array */
#define CHANNEL_1_IO_MSK (TSC_GROUP2_IO4)
#define CHANNEL_1_GRP_MSK (TSC_GROUP2)
#define CHANNEL_1_SRC (TSC_GROUP2_IDX) /* Index in source register (TSC->IOGXCR[]) */
#define CHANNEL_1_DEST (1) /* Index in destination result array */
#define CHANNEL_2_IO_MSK (TSC_GROUP3_IO3)
#define CHANNEL_2_GRP_MSK (TSC_GROUP3)
#define CHANNEL_2_SRC (TSC_GROUP3_IDX) /* Index in source register (TSC->IOGXCR[]) */
#define CHANNEL_2_DEST (2) /* Index in destination result array */
#define CHANNEL_3_IO_MSK (TSC_GROUP4_IO3)
#define CHANNEL_3_GRP_MSK (TSC_GROUP4)
#define CHANNEL_3_SRC (TSC_GROUP4_IDX) /* Index in source register (TSC->IOGXCR[]) */
#define CHANNEL_3_DEST (3) /* Index in destination result array */
#define CHANNEL_4_IO_MSK (TSC_GROUP5_IO2)
#define CHANNEL_4_GRP_MSK (TSC_GROUP5)
#define CHANNEL_4_SRC (TSC_GROUP5_IDX) /* Index in source register (TSC->IOGXCR[]) */
#define CHANNEL_4_DEST (4) /* Index in destination result array */
/* Channel IOs definition */
// The two touchkey channels
//#define CHANNEL_5_IO_MSK (TSC_GROUP6_IO3)
//#define CHANNEL_5_GRP_MSK (TSC_GROUP6)
//#define CHANNEL_5_SRC (TSC_GROUP6_IDX) /* Index in source register (TSC->IOGXCR[]) */
//#define CHANNEL_5_DEST (5) /* Index in destination result array */
//#define CHANNEL_6_IO_MSK (TSC_GROUP6_IO4)
//#define CHANNEL_6_GRP_MSK (TSC_GROUP6)
//#define CHANNEL_6_SRC (TSC_GROUP6_IDX)
//#define CHANNEL_6_DEST (6)
/* Shield IOs definition */
#define SHIELD_IO_MSK (0) // orig (TSC_GROUP7_IO3) we dont have a shield
/* Banks definition */
// The touch key bank
//#define BANK_1_NBCHANNELS (1)
//#define BANK_1_MSK_CHANNELS (CHANNEL_5_IO_MSK | SHIELD_IO_MSK)
//#define BANK_1_MSK_GROUPS (CHANNEL_5_GRP_MSK)
//#define BANK_2_NBCHANNELS (1)
//#define BANK_2_MSK_CHANNELS (CHANNEL_6_IO_MSK | SHIELD_IO_MSK)
//#define BANK_2_MSK_GROUPS (CHANNEL_6_GRP_MSK)
// The linrot bank
#define BANK_0_NBCHANNELS (5)
#define BANK_0_MSK_CHANNELS (CHANNEL_0_IO_MSK | CHANNEL_1_IO_MSK | CHANNEL_2_IO_MSK |CHANNEL_3_IO_MSK | CHANNEL_4_IO_MSK | SHIELD_IO_MSK)
#define BANK_0_MSK_GROUPS (CHANNEL_0_GRP_MSK | CHANNEL_1_GRP_MSK | CHANNEL_2_GRP_MSK | CHANNEL_3_GRP_MSK | CHANNEL_4_GRP_MSK)
/* User Parameters */
extern CONST TSL_Bank_T MyBanks[];
extern CONST TSL_TouchKey_T MyTKeys[];
extern CONST TSL_LinRot_T MyLinRots[];
extern CONST TSL_Object_T MyObjects[];
extern TSL_ObjectGroup_T MyObjGroup;
void tsl_user_Init(void);
tsl_user_status_t tsl_user_Exec(void);
void tsl_user_SetThresholds(void);
void Process_Sensors(tsl_user_status_t status);
void User_Tick_Management(void);
#endif /* __TSL_USER_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment