Statistics
| Branch: | Tag: | Revision:

amiro-os / test / periphery-lld / AT42QT1050_v1 / aos_test_AT42QT1050.c @ 40b5aa1d

History | View | Annotate | Download (18.787 KB)

1 bffb3465 Thomas Schöpping
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3 96621a83 Thomas Schöpping
Copyright (C) 2016..2020  Thomas Schöpping et al.
4 bffb3465 Thomas Schöpping

5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14

15
You should have received a copy of the GNU General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19 ddf34c3d Thomas Schöpping
#include <amiroos.h>
20 4c72a54c Thomas Schöpping
#include <aos_test_AT42QT1050.h>
21
22
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
23 bffb3465 Thomas Schöpping
24 f3ac1c96 Thomas Schöpping
/******************************************************************************/
25
/* LOCAL DEFINITIONS                                                          */
26
/******************************************************************************/
27 bffb3465 Thomas Schöpping
28
#define INTERRUPT_EVENT_ID            1
29
30 f3ac1c96 Thomas Schöpping
/******************************************************************************/
31
/* EXPORTED VARIABLES                                                         */
32
/******************************************************************************/
33
34
/******************************************************************************/
35
/* LOCAL TYPES                                                                */
36
/******************************************************************************/
37
38
/******************************************************************************/
39
/* LOCAL VARIABLES                                                            */
40
/******************************************************************************/
41
42
/******************************************************************************/
43
/* LOCAL FUNCTIONS                                                            */
44
/******************************************************************************/
45
46 b23ca7cc Thomas Schöpping
void print_settings(int32_t* status, BaseSequentialStream* stream, const aos_test_t* test) {
47 651cb6e6 Felix Wittenfeld
    chprintf(stream, "settings...\n");
48
49
    uint8_t test8;
50
    at42qt1050_lld_register_t txbuf;
51 4c72a54c Thomas Schöpping
    *status |= at42qt1050_lld_read_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, AT42QT1050_LLD_REG_LOWPOWERMODE, &test8, ((aos_test_at42qt1050data_t*)test->data)->timeout);
52 651cb6e6 Felix Wittenfeld
    chprintf(stream, "\tmeasurement inverval %d ms\n", test8*8);
53
54 4c72a54c Thomas Schöpping
    *status |= at42qt1050_lld_read_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, AT42QT1050_LLD_REG_MAXONDURATION, &test8, ((aos_test_at42qt1050data_t*)test->data)->timeout);
55 651cb6e6 Felix Wittenfeld
    chprintf(stream, "\tMax on duration %d ms\n", test8*160);
56
57 4c72a54c Thomas Schöpping
    *status |= at42qt1050_lld_read_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, AT42QT1050_LLD_REG_FINFOUTMAXCALGUARD, &test8, ((aos_test_at42qt1050data_t*)test->data)->timeout);
58 651cb6e6 Felix Wittenfeld
    chprintf(stream, "\tFast In %d, Fast Out, %d MaxCal %d\n\tGuard channel ",
59
             test8 & AT42QT1050_LLD_FINFOUTMAXCALGUARD_FI,     //enter fast mode whenever an unfiltered signal value is detected
60
             test8 & AT42QT1050_LLD_FINFOUTMAXCALGUARD_FO,     //DI of 4 (global setting for all keys)
61
             test8 & AT42QT1050_LLD_FINFOUTMAXCALGUARD_MAXCAL);//recalibrate ALL KEYS after a Max On Duration timeout vs. individually
62
63
    //guard channel (which gets priority filtering)
64
    if((test8 & AT42QT1050_LLD_FINFOUTMAXCALGUARD_GUARD) > AT42QT1050_LLD_NUM_KEYS-1)
65
        chprintf(stream, "off");
66
    else
67
        chprintf(stream, " %d", test8 & AT42QT1050_LLD_FINFOUTMAXCALGUARD_GUARD);
68
69
    chprintf(stream, "\n\n\tkey\tgroup\tintegr.\tdelay\tthresh.\tpulse\tscale\n");
70 265dae32 Felix Wittenfeld
    for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) {
71
        chprintf(stream, "\t%d\t", key);
72
        txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_INTEGRATOR_AKS_0, key);
73 4c72a54c Thomas Schöpping
        *status |= at42qt1050_lld_read_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, txbuf, &test8, ((aos_test_at42qt1050data_t*)test->data)->timeout);
74 265dae32 Felix Wittenfeld
        if(!((at42qt1050_lld_detectionintegratoraksreg_t)test8).aks)
75
            chprintf(stream, "none\t");
76
        else
77
            chprintf(stream, "%d\t", ((at42qt1050_lld_detectionintegratoraksreg_t)test8).aks);
78
79
        if(!((at42qt1050_lld_detectionintegratoraksreg_t)test8).detection_integrator)
80
            chprintf(stream, "off");
81
        else
82
            chprintf(stream, "%d", ((at42qt1050_lld_detectionintegratoraksreg_t)test8).detection_integrator);
83
84
        txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_CHARGESHAREDELAY_0, key);
85 4c72a54c Thomas Schöpping
        *status |= at42qt1050_lld_read_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, txbuf, &test8, ((aos_test_at42qt1050data_t*)test->data)->timeout);
86 265dae32 Felix Wittenfeld
        chprintf(stream, "\t+%d", test8);
87
88
        txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_NEGATIVETHRESHOLD_0, key);
89 4c72a54c Thomas Schöpping
        *status |= at42qt1050_lld_read_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, txbuf, &test8, ((aos_test_at42qt1050data_t*)test->data)->timeout);
90 265dae32 Felix Wittenfeld
        chprintf(stream, "\t%d", test8);
91
92
        txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_PULSE_SCALE_0, key);
93 4c72a54c Thomas Schöpping
        *status |= at42qt1050_lld_read_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, txbuf, &test8, ((aos_test_at42qt1050data_t*)test->data)->timeout);
94 265dae32 Felix Wittenfeld
        chprintf(stream, "\t%d\t%d\n", ((at42qt1050_lld_pulsescalereg_t)test8).pulse, ((at42qt1050_lld_pulsescalereg_t)test8).scale);
95 651cb6e6 Felix Wittenfeld
    }
96
97
}
98
99 b23ca7cc Thomas Schöpping
void show_live(const uint8_t first_key, int32_t* status,
100 4c72a54c Thomas Schöpping
               BaseSequentialStream* stream, const aos_test_t* test) {
101 651cb6e6 Felix Wittenfeld
102
    apalDbgAssert(first_key<5);
103
104
    event_listener_t event_listener;
105 265dae32 Felix Wittenfeld
    aos_timestamp_t tcurrent, tend ,tdemo_end;
106
107
    //stop demo after 15 seconds
108
    aosSysGetUptime(&tcurrent);
109
    tdemo_end = tcurrent + 15*MICROSECONDS_PER_SECOND;
110 651cb6e6 Felix Wittenfeld
111
    uint8_t keyStatus, detectionStatus;
112
    uint16_t signal, reference;
113
    uint8_t threshold[AT42QT1050_LLD_NUM_KEYS];
114
115 265dae32 Felix Wittenfeld
    chprintf(stream, "key, count, ref, signal, [threshold], \033[31mtouch\n\033[0m");
116 651cb6e6 Felix Wittenfeld
117
    //get thresholds
118
    for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) {
119
        const at42qt1050_lld_register_t txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_NEGATIVETHRESHOLD_0, key);
120 4c72a54c Thomas Schöpping
        *status |= at42qt1050_lld_read_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, txbuf, &threshold[key], ((aos_test_at42qt1050data_t*)test->data)->timeout);
121 651cb6e6 Felix Wittenfeld
    }
122 4c72a54c Thomas Schöpping
    chEvtRegister(((aos_test_at42qt1050data_t*)test->data)->evtsource, &event_listener, INTERRUPT_EVENT_ID);
123 265dae32 Felix Wittenfeld
    while(true) {
124
        aosSysGetUptime(&tcurrent);
125 651cb6e6 Felix Wittenfeld
126
        for (uint8_t key = first_key; key < AT42QT1050_LLD_NUM_KEYS; ++key) {
127
128
            //highlight touched key
129 4c72a54c Thomas Schöpping
            *status |= at42qt1050_lld_read_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, AT42QT1050_LLD_REG_KEYSTATUS, &keyStatus, ((aos_test_at42qt1050data_t*)test->data)->timeout);
130 651cb6e6 Felix Wittenfeld
            if((key == 0 && keyStatus&AT42QT1050_LLD_KEYSTATUS_KEY0)
131
                    || (key == 1 && keyStatus&AT42QT1050_LLD_KEYSTATUS_KEY1)
132
                    || (key == 2 && keyStatus&AT42QT1050_LLD_KEYSTATUS_KEY2)
133
                    || (key == 3 && keyStatus&AT42QT1050_LLD_KEYSTATUS_KEY3)
134
                    || (key == 4 && keyStatus&AT42QT1050_LLD_KEYSTATUS_KEY4))
135
                chprintf(stream, "\033[31m"); //red
136
            else
137
                chprintf(stream, "\033[0m"); //black
138
139 4c72a54c Thomas Schöpping
            *status |= at42qt1050_lld_read_keyssignal(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, key, &signal, ((aos_test_at42qt1050data_t*)test->data)->timeout);
140
            *status |= at42qt1050_lld_read_referencedata(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, key, &reference, ((aos_test_at42qt1050data_t*)test->data)->timeout);
141 651cb6e6 Felix Wittenfeld
142
            const uint16_t dist = (signal<reference?0:signal-reference);
143
            chprintf(stream, "\033[Kkey %d, %d\t0x%04X 0x%04X [", key, dist, reference, signal);
144
            uint16_t stars=0;
145
            for(; stars < dist; stars++) {
146
                chprintf(stream, "0");
147
                if(stars > 40) {           //max_stars = 40
148
                    chprintf(stream, "+"); //more than max_stars
149
                    break;
150
                }
151
            }
152
            for(; stars < threshold[key]; stars++)
153
                chprintf(stream, " ");
154
            if(stars == threshold[key])
155
                chprintf(stream, "]");
156
            chprintf(stream, "\n\033[0m");
157
        }
158
159 265dae32 Felix Wittenfeld
        //wait 1/3 second for a touch event
160
        tend = tcurrent + (MICROSECONDS_PER_SECOND/3);
161
        const eventmask_t emask = chEvtWaitOneTimeout(EVENT_MASK(INTERRUPT_EVENT_ID), chTimeUS2I(tend));
162 651cb6e6 Felix Wittenfeld
        const eventflags_t eflags = chEvtGetAndClearFlags(&event_listener);
163 4c72a54c Thomas Schöpping
        if (emask == EVENT_MASK(INTERRUPT_EVENT_ID) && eflags == ((aos_test_at42qt1050data_t*)test->data)->evtflags) {
164 651cb6e6 Felix Wittenfeld
            // interrupt detected
165
            chprintf(stream, "interrupt ");
166
        } // else: timeout
167
168 4c72a54c Thomas Schöpping
        *status |= at42qt1050_lld_read_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, AT42QT1050_LLD_REG_DETECTIONSTATUS, &detectionStatus, ((aos_test_at42qt1050data_t*)test->data)->timeout);
169 651cb6e6 Felix Wittenfeld
        if(detectionStatus & AT42QT1050_LLD_DETECTIONSTATUS_TOUCH)
170
            chprintf(stream, "touch ");
171
        if(detectionStatus & AT42QT1050_LLD_DETECTIONSTATUS_OVERFLOW)
172
            chprintf(stream, "overflow ");
173
        if(detectionStatus & AT42QT1050_LLD_DETECTIONSTATUS_CALIBRATE)
174
            chprintf(stream, "calibrate");
175
        chprintf(stream, "\033[K");
176
177 265dae32 Felix Wittenfeld
        if(tcurrent > tdemo_end)
178 651cb6e6 Felix Wittenfeld
            break;
179
180
        chprintf(stream, "\033[%dF", 5-first_key); //cursor up
181
    }
182 4c72a54c Thomas Schöpping
    chEvtUnregister(((aos_test_at42qt1050data_t*)test->data)->evtsource, &event_listener);
183 651cb6e6 Felix Wittenfeld
}
184
185 f3ac1c96 Thomas Schöpping
/******************************************************************************/
186
/* EXPORTED FUNCTIONS                                                         */
187
/******************************************************************************/
188
189 4c72a54c Thomas Schöpping
aos_testresult_t aosTestAt42qt1050Func(BaseSequentialStream* stream, const aos_test_t* test)
190 bffb3465 Thomas Schöpping
{
191 4c72a54c Thomas Schöpping
    aosDbgCheck(test->data != NULL && ((aos_test_at42qt1050data_t*)test->data)->at42qt1050d != NULL);
192 651cb6e6 Felix Wittenfeld
193
    // local variables
194 ce12e797 Thomas Schöpping
    aos_testresult_t result;
195 b23ca7cc Thomas Schöpping
    int32_t status;
196 265dae32 Felix Wittenfeld
    uint8_t test_8;
197 651cb6e6 Felix Wittenfeld
    bool error;
198
199 ce12e797 Thomas Schöpping
    aosTestResultInit(&result);
200
201 651cb6e6 Felix Wittenfeld
    chprintf(stream, "read register...\n");
202
    error = false;
203 4c72a54c Thomas Schöpping
    status = at42qt1050_lld_read_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, AT42QT1050_LLD_REG_CHIPID, &test_8, ((aos_test_at42qt1050data_t*)test->data)->timeout);
204 651cb6e6 Felix Wittenfeld
    chprintf(stream, "\t\tchip ID: 0x%02X\n", test_8);
205
    if (test_8 != AT42QT1050_LLD_CHIPID)
206
        error = true;
207 4c72a54c Thomas Schöpping
    status |= at42qt1050_lld_read_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, AT42QT1050_LLD_REG_FIRMWAREVERSION, &test_8, ((aos_test_at42qt1050data_t*)test->data)->timeout);
208 651cb6e6 Felix Wittenfeld
    chprintf(stream, "\t\tfirmware version: %u.%u (0x%02X)\n", ((at42qt1050_lld_firmwarereg_t)test_8).major, ((at42qt1050_lld_firmwarereg_t)test_8).minor, test_8);
209
    if (status == APAL_STATUS_SUCCESS && !error) {
210 4c72a54c Thomas Schöpping
        aosTestPassed(stream, &result);
211 651cb6e6 Felix Wittenfeld
    } else {
212 4c72a54c Thomas Schöpping
        aosTestFailedMsg(stream, &result, "0x%08X\n", status);
213 651cb6e6 Felix Wittenfeld
    }
214
215
    chprintf(stream, "write and readback threshold data...\n");
216
    status = APAL_STATUS_OK;
217
    const uint8_t threshold_test = 0x40;
218
    error = false;
219
    for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) {
220
        const at42qt1050_lld_register_t txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_NEGATIVETHRESHOLD_0, key);
221 4c72a54c Thomas Schöpping
        status |= at42qt1050_lld_write_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, txbuf, threshold_test , ((aos_test_at42qt1050data_t*)test->data)->timeout);
222
        status |= at42qt1050_lld_read_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, txbuf, &test_8, ((aos_test_at42qt1050data_t*)test->data)->timeout);
223 651cb6e6 Felix Wittenfeld
        if(test_8 != threshold_test)
224
            error = true;
225
    }
226
    if (status == APAL_STATUS_SUCCESS  &&  !error) {
227 4c72a54c Thomas Schöpping
        aosTestPassedMsg(stream, &result, "Set thresholds successfull to 0x%04X\n", threshold_test);
228 651cb6e6 Felix Wittenfeld
    } else {
229 4c72a54c Thomas Schöpping
        aosTestFailedMsg(stream, &result, "0x%08X\n", status);
230 651cb6e6 Felix Wittenfeld
    }
231
232
    chprintf(stream, "guarding...\nincrease charge_delay0\ndisable multitouch\n");
233
234
    //channel 0 is to big to be charged in the default cycle
235 4c72a54c Thomas Schöpping
    status = at42qt1050_lld_write_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, AT42QT1050_LLD_REG_CHARGESHAREDELAY_0, 128 , ((aos_test_at42qt1050data_t*)test->data)->timeout);
236 651cb6e6 Felix Wittenfeld
237
    //set all channel to group 1 -> only 1 simultaneous touch in group = single touch
238
    at42qt1050_lld_detectionintegratoraksreg_t detectionintegrator;
239
    for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) {
240
        const at42qt1050_lld_register_t txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_INTEGRATOR_AKS_0, key);
241
        detectionintegrator.aks = 1;                  //on touch per group-id simultaneous
242
        detectionintegrator.detection_integrator = 4; //4 times > threshold => touchevent
243 4c72a54c Thomas Schöpping
        status |= at42qt1050_lld_write_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, txbuf, detectionintegrator.raw, ((aos_test_at42qt1050data_t*)test->data)->timeout);
244 651cb6e6 Felix Wittenfeld
    }
245
    if (status == APAL_STATUS_SUCCESS) {
246 4c72a54c Thomas Schöpping
        aosTestPassed(stream, &result);
247 651cb6e6 Felix Wittenfeld
    } else {
248 4c72a54c Thomas Schöpping
        aosTestFailedMsg(stream, &result, "0x%08X\n", status);
249 651cb6e6 Felix Wittenfeld
    }
250
251
    chprintf(stream, "reset device...\n");
252 4c72a54c Thomas Schöpping
    status = at42qt1050_lld_reset(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, ((aos_test_at42qt1050data_t*)test->data)->timeout, true);
253 651cb6e6 Felix Wittenfeld
    if (status == APAL_STATUS_SUCCESS) {
254 4c72a54c Thomas Schöpping
        aosTestPassed(stream, &result);
255 651cb6e6 Felix Wittenfeld
    } else {
256 4c72a54c Thomas Schöpping
        aosTestFailedMsg(stream, &result, "0x%08X\n", status);
257 651cb6e6 Felix Wittenfeld
    }
258
259
    chprintf(stream, "read threshold data again...\n");
260
    status = APAL_STATUS_OK;
261
    const uint8_t threshold_default = 20;
262
    error = false;
263 bffb3465 Thomas Schöpping
    for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) {
264 651cb6e6 Felix Wittenfeld
        const at42qt1050_lld_register_t txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_NEGATIVETHRESHOLD_0, key);
265 4c72a54c Thomas Schöpping
        status |= at42qt1050_lld_read_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, txbuf, &test_8, ((aos_test_at42qt1050data_t*)test->data)->timeout);
266 651cb6e6 Felix Wittenfeld
        if(test_8 != threshold_default)
267
            error = true;
268
    }
269
270
    if (status == APAL_STATUS_SUCCESS && !error) {
271 4c72a54c Thomas Schöpping
        aosTestPassedMsg(stream, &result, "threshold 0x%04X = default\n", threshold_default);
272 651cb6e6 Felix Wittenfeld
    } else {
273 4c72a54c Thomas Schöpping
        aosTestFailedMsg(stream, &result, "0x%08X\n", status);
274 651cb6e6 Felix Wittenfeld
    }
275
276
    chprintf(stream, "demo of default configuration:\n");
277
    status = APAL_STATUS_OK;
278 4c72a54c Thomas Schöpping
    show_live(0, &status, stream, test);
279 651cb6e6 Felix Wittenfeld
    if (status == APAL_STATUS_SUCCESS) {
280 4c72a54c Thomas Schöpping
        aosTestPassed(stream, &result);
281 651cb6e6 Felix Wittenfeld
    } else {
282 4c72a54c Thomas Schöpping
        aosTestFailedMsg(stream, &result, "0x%08X\n", status);
283 651cb6e6 Felix Wittenfeld
    }
284
285
    status = APAL_STATUS_OK;
286 265dae32 Felix Wittenfeld
    chprintf(stream, "write configuration...\npuls + scale + threshold 8\n");
287 651cb6e6 Felix Wittenfeld
    at42qt1050_lld_pulsescalereg_t pulse_scale;
288
    //values stored as exponent of 2
289
    pulse_scale.pulse = 0; // accumulate #pulses -> increase resolution & time to acquire
290
    pulse_scale.scale = 0; // scale = average factor n: NewAvg = (NewData/n) + [OldAvg*(n-1/n)] -> decrease noise
291 4c72a54c Thomas Schöpping
    status  = at42qt1050_lld_write_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, AT42QT1050_LLD_REG_PULSE_SCALE_0, pulse_scale.raw , ((aos_test_at42qt1050data_t*)test->data)->timeout);
292 265dae32 Felix Wittenfeld
    pulse_scale.pulse = 1;
293 4c72a54c Thomas Schöpping
    status |= at42qt1050_lld_write_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, AT42QT1050_LLD_REG_PULSE_SCALE_3, pulse_scale.raw , ((aos_test_at42qt1050data_t*)test->data)->timeout);
294 265dae32 Felix Wittenfeld
295 651cb6e6 Felix Wittenfeld
    pulse_scale.pulse = 4;
296 4c72a54c Thomas Schöpping
    status |= at42qt1050_lld_write_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, AT42QT1050_LLD_REG_PULSE_SCALE_1, pulse_scale.raw , ((aos_test_at42qt1050data_t*)test->data)->timeout);
297
    status |= at42qt1050_lld_write_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, AT42QT1050_LLD_REG_PULSE_SCALE_2, pulse_scale.raw , ((aos_test_at42qt1050data_t*)test->data)->timeout);
298 265dae32 Felix Wittenfeld
299 4c72a54c Thomas Schöpping
    status |= at42qt1050_lld_write_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, AT42QT1050_LLD_REG_PULSE_SCALE_4, pulse_scale.raw , ((aos_test_at42qt1050data_t*)test->data)->timeout);
300 651cb6e6 Felix Wittenfeld
301
    for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) {
302
        const at42qt1050_lld_register_t txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_NEGATIVETHRESHOLD_0, key);
303 4c72a54c Thomas Schöpping
        status |= at42qt1050_lld_write_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, txbuf, 8, ((aos_test_at42qt1050data_t*)test->data)->timeout);
304 651cb6e6 Felix Wittenfeld
    }
305
    chprintf(stream, "disable guard key\n");
306 4c72a54c Thomas Schöpping
    status |= at42qt1050_lld_write_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, AT42QT1050_LLD_REG_INTEGRATOR_AKS_0, 0 , ((aos_test_at42qt1050data_t*)test->data)->timeout); //disable key
307
    status |= at42qt1050_lld_write_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, AT42QT1050_LLD_REG_FINFOUTMAXCALGUARD, 8 , ((aos_test_at42qt1050data_t*)test->data)->timeout); //disable feature
308 651cb6e6 Felix Wittenfeld
309
    chprintf(stream, "calibrate...\n");
310 4c72a54c Thomas Schöpping
    status = at42qt1050_lld_write_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, AT42QT1050_LLD_REG_RESET_CALIBRATE, AT42QT1050_LLD_RESETCALIBRATE_CALIBRATE, ((aos_test_at42qt1050data_t*)test->data)->timeout);
311 651cb6e6 Felix Wittenfeld
312
313
314
    //wait for calibration to complete
315
    error = true;
316
    for(uint8_t i=0; i<0xFF; i++) {
317 232ccea6 Thomas Schöpping
        aosThdUSleep(10);
318 4c72a54c Thomas Schöpping
        status |= at42qt1050_lld_read_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, AT42QT1050_LLD_REG_DETECTIONSTATUS, &test_8, ((aos_test_at42qt1050data_t*)test->data)->timeout);
319 651cb6e6 Felix Wittenfeld
        if(!(test_8 & AT42QT1050_LLD_DETECTIONSTATUS_CALIBRATE)) {
320
            error = false;
321
            break;
322
        }
323
    }
324
    if (status == APAL_STATUS_SUCCESS) {
325 4c72a54c Thomas Schöpping
        aosTestPassed(stream, &result);
326 651cb6e6 Felix Wittenfeld
    } else {
327 4c72a54c Thomas Schöpping
        aosTestFailedMsg(stream, &result, "0x%08X\n", status);
328 651cb6e6 Felix Wittenfeld
    }
329
    chprintf(stream, "demo of custom configuration:\n");
330
    status = APAL_STATUS_OK;
331 4c72a54c Thomas Schöpping
    show_live(1, &status, stream, test);
332 651cb6e6 Felix Wittenfeld
    if (status == APAL_STATUS_SUCCESS) {
333 4c72a54c Thomas Schöpping
        aosTestPassed(stream, &result);
334 651cb6e6 Felix Wittenfeld
    } else {
335 4c72a54c Thomas Schöpping
        aosTestFailedMsg(stream, &result, "0x%08X\n", status);
336 651cb6e6 Felix Wittenfeld
    }
337
338
    status = APAL_STATUS_OK;
339 4c72a54c Thomas Schöpping
    print_settings(&status, stream, test);
340 651cb6e6 Felix Wittenfeld
    if (status == APAL_STATUS_SUCCESS) {
341 4c72a54c Thomas Schöpping
        aosTestPassed(stream, &result);
342 651cb6e6 Felix Wittenfeld
    } else {
343 4c72a54c Thomas Schöpping
        aosTestFailedMsg(stream, &result, "0x%08X\n", status);
344 651cb6e6 Felix Wittenfeld
    }
345
346
    chprintf(stream, "shutdown touch\n");
347
    test_8 = 0; //Power down
348 4c72a54c Thomas Schöpping
    status = at42qt1050_lld_write_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, AT42QT1050_LLD_REG_LOWPOWERMODE, test_8, ((aos_test_at42qt1050data_t*)test->data)->timeout);
349 651cb6e6 Felix Wittenfeld
    if (status == APAL_STATUS_SUCCESS) {
350 4c72a54c Thomas Schöpping
        aosTestPassed(stream, &result);
351 651cb6e6 Felix Wittenfeld
    } else {
352 4c72a54c Thomas Schöpping
        aosTestFailedMsg(stream, &result, "0x%08X\n", status);
353 651cb6e6 Felix Wittenfeld
    }
354
355 4c72a54c Thomas Schöpping
    aosTestInfoMsg(stream,"driver object memory footprint: %u bytes\n", sizeof(AT42QT1050Driver));
356 651cb6e6 Felix Wittenfeld
357
    return result;
358 bffb3465 Thomas Schöpping
}
359
360 4c72a54c Thomas Schöpping
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */