Skip to content

Commit 0783a54

Browse files
committed
qtouch: update tuning
* Lower the ADC/PTC frequency to 2Mhz * Lower the analog gain as that introduces more noise * Higher analog gain of edge sensors that are less sensitive * Make filter 8x digital gain as per recommendation * Reduce threshold for active to 12 (to be tweaked) * Put sensor groups in AKS groups so that if one sensor is active no other sensor in the same group can become active. * Reduce hysteris to 25% to make "untouch" quicker * Speed up all calibration rates to 1 step per 200ms * Set a maximum touch time of 10s to eventually abort in case someone puts the device on a table * Remove force calibrate. The faster calibration rates should fix the sensors equally quick. * Add all functions from templates that was missing to make future diffs with atmel start smaller.
1 parent d98e5c3 commit 0783a54

File tree

5 files changed

+82
-127
lines changed

5 files changed

+82
-127
lines changed

external/asf4-drivers/qtouch/include/touch_api_ptc.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,23 @@ extern "C" {
4141
*----------------------------------------------------------------------------*/
4242
/* Application Helper API's */
4343
uint16_t qtouch_get_sensor_node_signal(uint16_t sensor_node);
44-
uint16_t qtouch_get_sensor_node_reference(uint16_t sensor_node);
44+
void qtouch_update_sensor_node_signal(uint16_t sensor_node, uint16_t new_signal);
4545
uint16_t qtouch_get_sensor_node_signal_filtered(uint16_t sensor_node);
46+
uint16_t qtouch_get_sensor_node_reference(uint16_t sensor_node);
47+
void qtouch_update_sensor_node_reference(uint16_t sensor_node, uint16_t new_reference);
4648
uint16_t qtouch_get_sensor_cc_val(uint16_t sensor_node);
49+
void qtouch_update_sensor_cc_val(uint16_t sensor_node, uint16_t new_cc_value);
4750
uint8_t qtouch_get_sensor_state(uint16_t sensor_node);
51+
void qtouch_update_sensor_state(uint16_t sensor_node, uint8_t new_state);
52+
void qtouch_calibrate_node(uint16_t sensor_node);
53+
uint8_t qtouch_get_scroller_state(uint16_t sensor_node);
4854
bool qtouch_is_scroller_active(uint16_t sensor_node);
4955
uint16_t qtouch_get_scroller_position(uint16_t sensor_node);
5056

5157
void qtouch_timer_handler(void);
5258
void qtouch_init(void);
5359
void qtouch_process(void);
54-
void qtouch_force_calibrate(void);
5560

56-
void qtimer_task_cb(const struct timer_task *const timer_task);
5761
void qtouch_timer_config(void);
5862

5963
#ifdef __cplusplus

src/bootloader/bootloader.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ extern uint8_t bootloader_pairing_code_bytes[4];
363363

364364
void bootloader_render_ble_confirm_screen(bool confirmed)
365365
{
366-
qtouch_force_calibrate();
367366
bootloader_pairing_request = true;
368367
uint32_t pairing_code_int = (*(uint32_t*)&bootloader_pairing_code_bytes[0]) % 1000000;
369368
char code_str[10] = {0};

src/qtouch/qtouch.c

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ static void qtm_measure_complete_callback(void);
4646

4747
/*! \brief Touch Error callback function prototype.
4848
*/
49-
static void qtm_error_callback(uint8_t err);
49+
static void qtm_error_callback(uint8_t error);
5050

51-
/*! \brief Calculate scroller positions based on custom filter.
51+
/* Update our scroller implementation
5252
*/
53-
static void qtouch_process_scroller_positions(void);
53+
void qtouch_process_scroller_positions(void);
5454

5555
/*----------------------------------------------------------------------------
5656
* Global Variables
@@ -110,6 +110,9 @@ __extension__ static uint16_t scroller_position[] = {[0 ...(DEF_NUM_SCROLLERS -
110110
/* Whether or not scroller reading exceeds threshold for custom filter */
111111
__extension__ static bool scroller_active[DEF_NUM_SCROLLERS] = {[0 ...(DEF_NUM_SCROLLERS - 1)] = 0};
112112

113+
/* Holds preceding unfiltered scroller positions */
114+
static uint16_t sensor_previous_filtered_reading[DEF_NUM_SENSORS][DEF_SENSOR_NUM_PREV_POS] = {0};
115+
113116
/**********************************************************/
114117
/*********************** Keys Module **********************/
115118
/**********************************************************/
@@ -195,26 +198,6 @@ static touch_ret_t touch_sensors_config(void)
195198
return (touch_ret);
196199
}
197200

198-
/*
199-
* Force calibrate
200-
*
201-
* Call this function when the user "probably" isn't touching the device to reset all the
202-
* calibration values. It will only reset inputs that are not considered to be in "touched" states
203-
*/
204-
void qtouch_force_calibrate(void)
205-
{
206-
qtm_touch_key_data_t* key;
207-
for (uint16_t i = 0U; i < DEF_NUM_CHANNELS; i++) {
208-
key = &qtlib_key_data_set1[i];
209-
uint16_t value = key->node_data_struct_ptr->node_acq_signals;
210-
uint16_t reference = key->channel_reference;
211-
int32_t diff = (int32_t)reference - (int32_t)value;
212-
if (!(key->sensor_state & KEY_TOUCHED_MASK) && diff > KEY_FORCE_CALIBRATE_THRESHOLD) {
213-
key->channel_reference = key->node_data_struct_ptr->node_acq_signals;
214-
}
215-
}
216-
}
217-
218201
/*============================================================================
219202
static void qtm_measure_complete_callback( void )
220203
------------------------------------------------------------------------------
@@ -244,9 +227,9 @@ Derived Module_error_codes:
244227
... and so on
245228
246229
============================================================================*/
247-
static void qtm_error_callback(uint8_t err)
230+
static void qtm_error_callback(uint8_t error)
248231
{
249-
module_error_code = err + 1u;
232+
module_error_code = error + 1u;
250233
}
251234

252235
/*============================================================================
@@ -364,25 +347,40 @@ uint16_t qtouch_get_sensor_node_signal(uint16_t sensor_node)
364347
return (ptc_qtlib_node_stat1[sensor_node].node_acq_signals);
365348
}
366349

350+
void qtouch_update_sensor_node_signal(uint16_t sensor_node, uint16_t new_signal)
351+
{
352+
ptc_qtlib_node_stat1[sensor_node].node_acq_signals = new_signal;
353+
}
367354
uint16_t qtouch_get_sensor_node_reference(uint16_t sensor_node)
368355
{
369356
return (qtlib_key_data_set1[sensor_node].channel_reference);
370357
}
371358

359+
void qtouch_update_sensor_node_reference(uint16_t sensor_node, uint16_t new_reference)
360+
{
361+
qtlib_key_data_set1[sensor_node].channel_reference = new_reference;
362+
}
363+
372364
uint16_t qtouch_get_sensor_cc_val(uint16_t sensor_node)
373365
{
374366
return (ptc_qtlib_node_stat1[sensor_node].node_comp_caps);
375367
}
376368

369+
void qtouch_update_sensor_cc_val(uint16_t sensor_node, uint16_t new_cc_value)
370+
{
371+
ptc_qtlib_node_stat1[sensor_node].node_comp_caps = new_cc_value;
372+
}
373+
377374
uint8_t qtouch_get_sensor_state(uint16_t sensor_node)
378375
{
379376
return (qtlib_key_set1.qtm_touch_key_data[sensor_node].sensor_state);
380377
}
381378

382-
/* Holds preceding unfiltered scroller positions */
383-
static uint16_t sensor_previous_filtered_reading[DEF_NUM_SENSORS][DEF_SENSOR_NUM_PREV_POS] = {0};
379+
void qtouch_update_sensor_state(uint16_t sensor_node, uint8_t new_state)
380+
{
381+
qtlib_key_set1.qtm_touch_key_data[sensor_node].sensor_state = new_state;
382+
}
384383

385-
/* Custom sensor signal filter. */
386384
uint16_t qtouch_get_sensor_node_signal_filtered(uint16_t sensor_node)
387385
{
388386
// Filter the sensor signal.
@@ -403,11 +401,11 @@ uint16_t qtouch_get_sensor_node_signal_filtered(uint16_t sensor_node)
403401
}
404402
X = sensor_raw < sensor_reference ? 0 : sensor_raw - sensor_reference;
405403
// Add more weight to edge buttons because they are physically smaller (smaller readings).
406-
if ((sensor_node == DEF_SCROLLER_OFFSET_0) || (sensor_node == DEF_SCROLLER_OFFSET_1) ||
407-
(sensor_node == DEF_SCROLLER_OFFSET_0 + DEF_SCROLLER_NUM_CHANNELS - 1) ||
408-
(sensor_node == DEF_SCROLLER_OFFSET_1 + DEF_SCROLLER_NUM_CHANNELS - 1)) {
409-
X = (uint16_t)((double)X * (1 + DEF_SENSOR_EDGE_WEIGHT));
410-
}
404+
// if ((sensor_node == DEF_SCROLLER_OFFSET_0) || (sensor_node == DEF_SCROLLER_OFFSET_1) ||
405+
// (sensor_node == DEF_SCROLLER_OFFSET_0 + DEF_SCROLLER_NUM_CHANNELS - 1) ||
406+
// (sensor_node == DEF_SCROLLER_OFFSET_1 + DEF_SCROLLER_NUM_CHANNELS - 1)) {
407+
// X = (uint16_t)((double)X * (1 + DEF_SENSOR_EDGE_WEIGHT));
408+
//}
411409
// Saturate out-of-range readings.
412410
X = (X > DEF_SENSOR_CEILING) ? DEF_SENSOR_CEILING : X;
413411

@@ -431,11 +429,10 @@ uint16_t qtouch_get_sensor_node_signal_filtered(uint16_t sensor_node)
431429
return X_ave;
432430
}
433431

434-
bool qtouch_is_scroller_active(uint16_t scroller)
432+
bool qtouch_is_scroller_active(uint16_t sensor_node)
435433
{
436-
return scroller_active[scroller];
434+
return scroller_active[sensor_node];
437435
}
438-
439436
uint16_t qtouch_get_scroller_position(uint16_t sensor_node)
440437
{
441438
return scroller_position[sensor_node];

src/qtouch/qtouch.h

Lines changed: 42 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Copyright (c) 2017 Microchip. All rights reserved.
1717
------------------------------------------------------------------------------
1818
============================================================================*/
1919

20-
#ifndef TOUCH_H
21-
#define TOUCH_H
20+
#ifndef QTOUCH_H
21+
#define QTOUCH_H
2222

2323
#ifdef __cplusplus
2424
extern "C" {
@@ -65,7 +65,7 @@ extern "C" {
6565
* Range: FREQ_SEL_0 - FREQ_SEL_15 , FREQ_SEL_SPREAD
6666
* Default value: FREQ_SEL_0.
6767
*/
68-
#define DEF_SEL_FREQ_INIT FREQ_SEL_8
68+
#define DEF_SEL_FREQ_INIT FREQ_SEL_0
6969

7070
/*----------------------------------------------------------------------------
7171
* defines
@@ -86,63 +86,23 @@ extern "C" {
8686
* Gain , Digital Gain), filter level}
8787
*/
8888
// Slider 1 buttons
89-
#define NODE_0_PARAMS \
90-
{X_NONE, \
91-
Y_LINE(26), \
92-
0, \
93-
NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
94-
NODE_GAIN(GAIN_4, GAIN_4), \
95-
FILTER_LEVEL_512}
96-
#define NODE_1_PARAMS \
97-
{X_NONE, \
98-
Y_LINE(27), \
99-
0, \
100-
NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
101-
NODE_GAIN(GAIN_4, GAIN_4), \
102-
FILTER_LEVEL_512}
103-
#define NODE_2_PARAMS \
104-
{X_NONE, \
105-
Y_LINE(28), \
106-
0, \
107-
NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
108-
NODE_GAIN(GAIN_4, GAIN_4), \
109-
FILTER_LEVEL_512}
110-
#define NODE_3_PARAMS \
111-
{X_NONE, \
112-
Y_LINE(29), \
113-
0, \
114-
NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
115-
NODE_GAIN(GAIN_4, GAIN_4), \
116-
FILTER_LEVEL_512}
89+
#define NODE_0_PARAMS \
90+
{X_NONE, Y_LINE(26), 0, PRSC_DIV_SEL_4, NODE_GAIN(GAIN_2, GAIN_8), FILTER_LEVEL_64}
91+
#define NODE_1_PARAMS \
92+
{X_NONE, Y_LINE(27), 0, PRSC_DIV_SEL_4, NODE_GAIN(GAIN_1, GAIN_8), FILTER_LEVEL_64}
93+
#define NODE_2_PARAMS \
94+
{X_NONE, Y_LINE(28), 0, PRSC_DIV_SEL_4, NODE_GAIN(GAIN_1, GAIN_8), FILTER_LEVEL_64}
95+
#define NODE_3_PARAMS \
96+
{X_NONE, Y_LINE(29), 0, PRSC_DIV_SEL_4, NODE_GAIN(GAIN_2, GAIN_8), FILTER_LEVEL_64}
11797
// Slider 0 buttons
118-
#define NODE_4_PARAMS \
119-
{X_NONE, \
120-
Y_LINE(30), \
121-
0, \
122-
NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
123-
NODE_GAIN(GAIN_4, GAIN_4), \
124-
FILTER_LEVEL_512}
125-
#define NODE_5_PARAMS \
126-
{X_NONE, \
127-
Y_LINE(31), \
128-
0, \
129-
NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
130-
NODE_GAIN(GAIN_4, GAIN_4), \
131-
FILTER_LEVEL_512}
132-
#define NODE_6_PARAMS \
133-
{X_NONE, \
134-
Y_LINE(20), \
135-
0, \
136-
NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
137-
NODE_GAIN(GAIN_4, GAIN_4), \
138-
FILTER_LEVEL_512}
139-
#define NODE_7_PARAMS \
140-
{X_NONE, \
141-
Y_LINE(21), \
142-
0, \
143-
NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
144-
NODE_GAIN(GAIN_4, GAIN_4), \
145-
FILTER_LEVEL_512}
98+
#define NODE_4_PARAMS \
99+
{X_NONE, Y_LINE(30), 0, PRSC_DIV_SEL_4, NODE_GAIN(GAIN_2, GAIN_8), FILTER_LEVEL_64}
100+
#define NODE_5_PARAMS \
101+
{X_NONE, Y_LINE(31), 0, PRSC_DIV_SEL_4, NODE_GAIN(GAIN_1, GAIN_8), FILTER_LEVEL_64}
102+
#define NODE_6_PARAMS \
103+
{X_NONE, Y_LINE(20), 0, PRSC_DIV_SEL_4, NODE_GAIN(GAIN_1, GAIN_8), FILTER_LEVEL_64}
104+
#define NODE_7_PARAMS \
105+
{X_NONE, Y_LINE(21), 0, PRSC_DIV_SEL_4, NODE_GAIN(GAIN_2, GAIN_8), FILTER_LEVEL_64}
146106

147107
/**********************************************************/
148108
/***************** Key Params ******************/
@@ -157,75 +117,68 @@ extern "C" {
157117
* {Sensor Threshold, Sensor Hysterisis, Sensor AKS}
158118
*/
159119
// 0..3 higher Slider left to right 4..7 lower Slider right to left
160-
#define KEY_0_PARAMS {16, HYST_50, NO_AKS_GROUP}
161-
#define KEY_1_PARAMS {16, HYST_50, NO_AKS_GROUP}
162-
#define KEY_2_PARAMS {16, HYST_50, NO_AKS_GROUP}
163-
#define KEY_3_PARAMS {16, HYST_50, NO_AKS_GROUP}
164-
#define KEY_4_PARAMS {16, HYST_50, NO_AKS_GROUP}
165-
#define KEY_5_PARAMS {16, HYST_50, NO_AKS_GROUP}
166-
#define KEY_6_PARAMS {16, HYST_50, NO_AKS_GROUP}
167-
#define KEY_7_PARAMS {16, HYST_50, NO_AKS_GROUP}
120+
#define KEY_0_PARAMS {12, HYST_25, AKS_GROUP_1}
121+
#define KEY_1_PARAMS {12, HYST_25, AKS_GROUP_1}
122+
#define KEY_2_PARAMS {12, HYST_25, AKS_GROUP_1}
123+
#define KEY_3_PARAMS {12, HYST_25, AKS_GROUP_1}
124+
#define KEY_4_PARAMS {12, HYST_25, AKS_GROUP_2}
125+
#define KEY_5_PARAMS {12, HYST_25, AKS_GROUP_2}
126+
#define KEY_6_PARAMS {12, HYST_25, AKS_GROUP_2}
127+
#define KEY_7_PARAMS {12, HYST_25, AKS_GROUP_2}
168128

169129
/* De-bounce counter for additional measurements to confirm touch detection
170130
* Range: 0 to 255.
171131
* Default value: 4.
172132
*/
173-
#define DEF_TOUCH_DET_INT 0
133+
#define DEF_TOUCH_DET_INT 1
174134

175135
/* De-bounce counter for additional measurements to confirm away from touch signal
176136
* to initiate Away from touch re-calibration.
177137
* Range: 0 to 255.
178138
* Default value: 5.
179139
*/
180-
#define DEF_ANTI_TCH_DET_INT 0
140+
#define DEF_ANTI_TCH_DET_INT 1
181141

182142
/* Threshold beyond with automatic sensor recalibration is initiated.
183143
* Range: RECAL_100/ RECAL_50 / RECAL_25 / RECAL_12_5 / RECAL_6_25 / MAX_RECAL
184144
* Default value: RECAL_100.
185145
*/
186-
#define DEF_ANTI_TCH_RECAL_THRSHLD RECAL_50
146+
#define DEF_ANTI_TCH_RECAL_THRSHLD RECAL_100
187147

188148
/* Rate at which sensor reference value is adjusted towards sensor signal value
189149
* when signal value is greater than reference.
190150
* Units: 200ms
191151
* Range: 0-255
192152
* Default value: 20u = 4 seconds.
193153
*/
194-
#define DEF_TCH_DRIFT_RATE 20
154+
#define DEF_TCH_DRIFT_RATE 1
195155

196156
/* Rate at which sensor reference value is adjusted towards sensor signal value
197157
* when signal value is less than reference.
198158
* Units: 200ms
199159
* Range: 0-255
200160
* Default value: 5u = 1 second.
201161
*/
202-
#define DEF_ANTI_TCH_DRIFT_RATE 5
162+
#define DEF_ANTI_TCH_DRIFT_RATE 1
203163

204164
/* Time to restrict drift on all sensor when one or more sensors are activated.
205165
* Units: 200ms
206166
* Range: 0-255
207167
* Default value: 20u = 4 seconds.
208168
*/
209-
#define DEF_DRIFT_HOLD_TIME 20
169+
#define DEF_DRIFT_HOLD_TIME 1
210170

211171
/* Set mode for additional sensor measurements based on touch activity.
212172
* Range: REBURST_NONE / REBURST_UNRESOLVED / REBURST_ALL
213173
* Default value: REBURST_UNRESOLVED
214174
*/
215-
#define DEF_REBURST_MODE REBURST_ALL
175+
#define DEF_REBURST_MODE REBURST_NONE
216176

217177
/* Sensor maximum ON duration upon touch.
218178
* Range: 0-255
219179
* Default value: 0
220180
*/
221-
#define DEF_MAX_ON_DURATION 0
222-
223-
/*
224-
* The count that the reference value must be above the measured value to
225-
* allow the force calibrate procedure to overwrite the reference to the
226-
* current measured value.
227-
*/
228-
#define KEY_FORCE_CALIBRATE_THRESHOLD 10
181+
#define DEF_MAX_ON_DURATION 50
229182

230183
/**********************************************************/
231184
/***************** Slider/Wheel Parameters ****************/
@@ -237,21 +190,24 @@ extern "C" {
237190
* This allows low noise button readings while keeping
238191
* fast responsiveness.
239192
*/
193+
240194
#define DEF_NUM_SCROLLERS 2 // Number of scrollers (sliders or wheels)
241195
#define DEF_SCROLLER_NUM_CHANNELS 4 // Number of channels per scroller
242196
#define DEF_SCROLLER_OFFSET_0 4 // Index of first button in scroller
243197
#define DEF_SCROLLER_OFFSET_1 0 // Index of first button in scroller
244198
#define DEF_SCROLLER_RESOLUTION 256 // Scroller resolution in bits
245-
#define DEF_SCROLLER_DET_THRESHOLD 25 // Scroller detect threshold
246-
#define DEF_SCROLLER_TOUCH_THRESHOLD 25 // Scroller active threshold
247-
#define DEF_SCROLLER_UNTOUCH_THRESHOLD 20 // Scroller active threshold
199+
#define DEF_SCROLLER_DET_THRESHOLD 12 // Scroller detect threshold
200+
#define DEF_SCROLLER_TOUCH_THRESHOLD 12 // Scroller active threshold
201+
#define DEF_SCROLLER_UNTOUCH_THRESHOLD 9 // Scroller active threshold
248202
#define DEF_SCROLLER_DEADBAND 13 // 13 bits = 5% of 256-bit range
249203
#define DEF_SCROLLER_NUM_PREV_POS \
250204
4 // Number of previous scroller positions to remember; used in a simple filter
251205
#define DEF_SCROLLER_OFF \
252206
0xFFFF // Marker for indicating scroller reading does not exceed detection threshold
207+
/*
253208
#define DEF_SENSOR_EDGE_WEIGHT \
254209
0.15 // Percent added weight to edge sensors, which are physically smaller
210+
*/
255211
#define DEF_SENSOR_NUM_PREV_POS \
256212
4 // Number of previous sensor positions to remember; used in a simple filter
257213
#define DEF_SENSOR_CEILING \
@@ -261,4 +217,4 @@ extern "C" {
261217
#ifdef __cplusplus
262218
}
263219
#endif // __cplusplus
264-
#endif // TOUCH_C
220+
#endif // QTOUCH_H

0 commit comments

Comments
 (0)