Revision 265dae32

View differences:

unittests/periphery-lld/src/ut_alld_AT42QT1050_v1.c
66 66
        chprintf(stream, " %d", test8 & AT42QT1050_LLD_FINFOUTMAXCALGUARD_GUARD);
67 67

  
68 68
    chprintf(stream, "\n\n\tkey\tgroup\tintegr.\tdelay\tthresh.\tpulse\tscale\n");
69
     for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) {
70
         chprintf(stream, "\t%d\t", key);
71
         txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_INTEGRATOR_AKS_0, key);
72
         *status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, txbuf, &test8, ((ut_at42qt1050data_t*)ut->data)->timeout);
73
         if(!((at42qt1050_lld_detectionintegratoraksreg_t)test8).aks)
74
             chprintf(stream, "none\t");
75
         else
76
             chprintf(stream, "%d\t", ((at42qt1050_lld_detectionintegratoraksreg_t)test8).aks);
77

  
78
         if(!((at42qt1050_lld_detectionintegratoraksreg_t)test8).detection_integrator)
79
             chprintf(stream, "off", key);
80
         else
81
             chprintf(stream, "%d", ((at42qt1050_lld_detectionintegratoraksreg_t)test8).detection_integrator);
82

  
83
         txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_CHARGESHAREDELAY_0, key);
84
         *status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, txbuf, &test8, ((ut_at42qt1050data_t*)ut->data)->timeout);
85
         chprintf(stream, "\t+%d", test8);
86

  
87
         txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_NEGATIVETHRESHOLD_0, key);
88
         *status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, txbuf, &test8, ((ut_at42qt1050data_t*)ut->data)->timeout);
89
         chprintf(stream, "\t%d", test8);
90

  
91
         txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_PULSE_SCALE_0, key);
92
         *status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, txbuf, &test8, ((ut_at42qt1050data_t*)ut->data)->timeout);
93
         chprintf(stream, "\t%d\t%d\n", key, ((at42qt1050_lld_pulsescalereg_t)test8).pulse, ((at42qt1050_lld_pulsescalereg_t)test8).scale);
69
    for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) {
70
        chprintf(stream, "\t%d\t", key);
71
        txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_INTEGRATOR_AKS_0, key);
72
        *status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, txbuf, &test8, ((ut_at42qt1050data_t*)ut->data)->timeout);
73
        if(!((at42qt1050_lld_detectionintegratoraksreg_t)test8).aks)
74
            chprintf(stream, "none\t");
75
        else
76
            chprintf(stream, "%d\t", ((at42qt1050_lld_detectionintegratoraksreg_t)test8).aks);
77

  
78
        if(!((at42qt1050_lld_detectionintegratoraksreg_t)test8).detection_integrator)
79
            chprintf(stream, "off");
80
        else
81
            chprintf(stream, "%d", ((at42qt1050_lld_detectionintegratoraksreg_t)test8).detection_integrator);
82

  
83
        txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_CHARGESHAREDELAY_0, key);
84
        *status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, txbuf, &test8, ((ut_at42qt1050data_t*)ut->data)->timeout);
85
        chprintf(stream, "\t+%d", test8);
86

  
87
        txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_NEGATIVETHRESHOLD_0, key);
88
        *status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, txbuf, &test8, ((ut_at42qt1050data_t*)ut->data)->timeout);
89
        chprintf(stream, "\t%d", test8);
90

  
91
        txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_PULSE_SCALE_0, key);
92
        *status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, txbuf, &test8, ((ut_at42qt1050data_t*)ut->data)->timeout);
93
        chprintf(stream, "\t%d\t%d\n", ((at42qt1050_lld_pulsescalereg_t)test8).pulse, ((at42qt1050_lld_pulsescalereg_t)test8).scale);
94 94
    }
95 95

  
96 96
}
......
101 101
    apalDbgAssert(first_key<5);
102 102

  
103 103
    event_listener_t event_listener;
104
    aos_timestamp_t tstart, tcurrent, tend;
104
    aos_timestamp_t tcurrent, tend ,tdemo_end;
105

  
106
    //stop demo after 15 seconds
107
    aosSysGetUptime(&tcurrent);
108
    tdemo_end = tcurrent + 15*MICROSECONDS_PER_SECOND;
105 109

  
106 110
    uint8_t keyStatus, detectionStatus;
107 111
    uint16_t signal, reference;
108 112
    uint8_t threshold[AT42QT1050_LLD_NUM_KEYS];
109 113

  
110
    chprintf(stream, "key, count, signal, ref, [threshold], \033[31mtouch\n\033[0m");
114
    chprintf(stream, "key, count, ref, signal, [threshold], \033[31mtouch\n\033[0m");
111 115

  
112 116
    //get thresholds
113 117
    for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) {
......
115 119
        *status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, txbuf, &threshold[key], ((ut_at42qt1050data_t*)ut->data)->timeout);
116 120
    }
117 121
    chEvtRegister(((ut_at42qt1050data_t*)ut->data)->evtsource, &event_listener, INTERRUPT_EVENT_ID);
118
    for(uint16_t i=0;; i++) {
119
        aosSysGetUptime(&tstart);
120
        //wait 1 second for a touch event
121
        tend = tstart + (MICROSECONDS_PER_SECOND);
122
    while(true) {
123
        aosSysGetUptime(&tcurrent);
122 124

  
123 125
        for (uint8_t key = first_key; key < AT42QT1050_LLD_NUM_KEYS; ++key) {
124 126

  
......
153 155
            chprintf(stream, "\n\033[0m");
154 156
        }
155 157

  
156
        aosSysGetUptime(&tcurrent);
157
//        const aos_timestamp_t ttimeout = MICROSECONDS_PER_SECOND - ((tcurrent - tstart) % MICROSECONDS_PER_SECOND);
158
        const eventmask_t emask = chEvtWaitOneTimeout(EVENT_MASK(INTERRUPT_EVENT_ID), chTimeUS2I(tend));//ttimeout));
158
        //wait 1/3 second for a touch event
159
        tend = tcurrent + (MICROSECONDS_PER_SECOND/3);
160
        const eventmask_t emask = chEvtWaitOneTimeout(EVENT_MASK(INTERRUPT_EVENT_ID), chTimeUS2I(tend));
159 161
        const eventflags_t eflags = chEvtGetAndClearFlags(&event_listener);
160 162
        if (emask == EVENT_MASK(INTERRUPT_EVENT_ID) && eflags == ((ut_at42qt1050data_t*)ut->data)->evtflags) {
161 163
            // interrupt detected
......
171 173
            chprintf(stream, "calibrate");
172 174
        chprintf(stream, "\033[K");
173 175

  
174
        if(i>=30)
176
        if(tcurrent > tdemo_end)
175 177
            break;
176 178

  
177 179
        chprintf(stream, "\033[%dF", 5-first_key); //cursor up
......
190 192
    // local variables
191 193
    aos_utresult_t result = {0, 0};
192 194
    apalExitStatus_t status;
193
    uint8_t  test_8;
195
    uint8_t test_8;
194 196
    bool error;
195 197

  
196 198
    chprintf(stream, "read register...\n");
......
235 237
        const at42qt1050_lld_register_t txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_INTEGRATOR_AKS_0, key);
236 238
        detectionintegrator.aks = 1;                  //on touch per group-id simultaneous
237 239
        detectionintegrator.detection_integrator = 4; //4 times > threshold => touchevent
238
        status |= at42qt1050_lld_write_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, txbuf, 0x11 , ((ut_at42qt1050data_t*)ut->data)->timeout);
240
        status |= at42qt1050_lld_write_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, txbuf, detectionintegrator.raw, ((ut_at42qt1050data_t*)ut->data)->timeout);
239 241
    }
240 242
    if (status == APAL_STATUS_SUCCESS) {
241 243
        aosUtPassed(stream, &result);
......
278 280
    }
279 281

  
280 282
    status = APAL_STATUS_OK;
281
    chprintf(stream, "write configuration...\npuls + scale + threshold 16\n");
283
    chprintf(stream, "write configuration...\npuls + scale + threshold 8\n");
282 284
    at42qt1050_lld_pulsescalereg_t pulse_scale;
283 285
    //values stored as exponent of 2
284 286
    pulse_scale.pulse = 0; // accumulate #pulses -> increase resolution & time to acquire
285 287
    pulse_scale.scale = 0; // scale = average factor n: NewAvg = (NewData/n) + [OldAvg*(n-1/n)] -> decrease noise
286 288
    status  = at42qt1050_lld_write_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_PULSE_SCALE_0, pulse_scale.raw , ((ut_at42qt1050data_t*)ut->data)->timeout);
287
    status |= at42qt1050_lld_write_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_PULSE_SCALE_3, 0x00u , ((ut_at42qt1050data_t*)ut->data)->timeout);
289
    pulse_scale.pulse = 1;
290
    status |= at42qt1050_lld_write_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_PULSE_SCALE_3, pulse_scale.raw , ((ut_at42qt1050data_t*)ut->data)->timeout);
291

  
288 292
    pulse_scale.pulse = 4;
289 293
    status |= at42qt1050_lld_write_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_PULSE_SCALE_1, pulse_scale.raw , ((ut_at42qt1050data_t*)ut->data)->timeout);
290 294
    status |= at42qt1050_lld_write_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_PULSE_SCALE_2, pulse_scale.raw , ((ut_at42qt1050data_t*)ut->data)->timeout);
295

  
291 296
    status |= at42qt1050_lld_write_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_PULSE_SCALE_4, pulse_scale.raw , ((ut_at42qt1050data_t*)ut->data)->timeout);
292 297

  
293 298
    for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) {
294 299
        const at42qt1050_lld_register_t txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_NEGATIVETHRESHOLD_0, key);
295
        status |= at42qt1050_lld_write_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, txbuf, 16, ((ut_at42qt1050data_t*)ut->data)->timeout);
300
        status |= at42qt1050_lld_write_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, txbuf, 8, ((ut_at42qt1050data_t*)ut->data)->timeout);
296 301
    }
297 302
    chprintf(stream, "disable guard key\n");
298 303
    status |= at42qt1050_lld_write_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_INTEGRATOR_AKS_0, 0 , ((ut_at42qt1050data_t*)ut->data)->timeout); //disable key
......
337 342

  
338 343
    chprintf(stream, "shutdown touch\n");
339 344
    test_8 = 0; //Power down
340
    status = at42qt1050_lld_write_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_LOWPOWERMODE, &test_8, ((ut_at42qt1050data_t*)ut->data)->timeout);
345
    status = at42qt1050_lld_write_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_LOWPOWERMODE, test_8, ((ut_at42qt1050data_t*)ut->data)->timeout);
341 346
    if (status == APAL_STATUS_SUCCESS) {
342 347
        aosUtPassed(stream, &result);
343 348
    } else {

Also available in: Unified diff