Revision 651cb6e6

View differences:

periphery-lld/AMiRo-LLD
1
Subproject commit b95be72b70314916909196ddea055642914f4c6d
1
Subproject commit 7df78c60db679f32c180cc23776e5e449fc7fab5
unittests/periphery-lld/src/ut_alld_AT42QT1050_v1.c
20 20
#include <ut_alld_AT42QT1050_v1.h>
21 21

  
22 22
#if ((AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_AT42QT1050) && (AMIROLLD_CFG_AT42QT1050 == 1)) || defined(__DOXYGEN__)
23

  
24 23
/******************************************************************************/
25 24
/* LOCAL DEFINITIONS                                                          */
26 25
/******************************************************************************/
......
43 42
/* LOCAL FUNCTIONS                                                            */
44 43
/******************************************************************************/
45 44

  
45
void print_settings(apalExitStatus_t* status, BaseSequentialStream* stream, aos_unittest_t* ut) {
46
    chprintf(stream, "settings...\n");
47

  
48
    uint8_t test8;
49
    at42qt1050_lld_register_t txbuf;
50
    *status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_LOWPOWERMODE, &test8, ((ut_at42qt1050data_t*)ut->data)->timeout);
51
    chprintf(stream, "\tmeasurement inverval %d ms\n", test8*8);
52

  
53
    *status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_MAXONDURATION, &test8, ((ut_at42qt1050data_t*)ut->data)->timeout);
54
    chprintf(stream, "\tMax on duration %d ms\n", test8*160);
55

  
56
    *status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_FINFOUTMAXCALGUARD, &test8, ((ut_at42qt1050data_t*)ut->data)->timeout);
57
    chprintf(stream, "\tFast In %d, Fast Out, %d MaxCal %d\n\tGuard channel ",
58
             test8 & AT42QT1050_LLD_FINFOUTMAXCALGUARD_FI,     //enter fast mode whenever an unfiltered signal value is detected
59
             test8 & AT42QT1050_LLD_FINFOUTMAXCALGUARD_FO,     //DI of 4 (global setting for all keys)
60
             test8 & AT42QT1050_LLD_FINFOUTMAXCALGUARD_MAXCAL);//recalibrate ALL KEYS after a Max On Duration timeout vs. individually
61

  
62
    //guard channel (which gets priority filtering)
63
    if((test8 & AT42QT1050_LLD_FINFOUTMAXCALGUARD_GUARD) > AT42QT1050_LLD_NUM_KEYS-1)
64
        chprintf(stream, "off");
65
    else
66
        chprintf(stream, " %d", test8 & AT42QT1050_LLD_FINFOUTMAXCALGUARD_GUARD);
67

  
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);
94
    }
95

  
96
}
97

  
98
void show_live(const uint8_t first_key, apalExitStatus_t* status,
99
               BaseSequentialStream* stream, aos_unittest_t* ut) {
100

  
101
    apalDbgAssert(first_key<5);
102

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

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

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

  
112
    //get thresholds
113
    for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) {
114
        const at42qt1050_lld_register_t txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_NEGATIVETHRESHOLD_0, key);
115
        *status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, txbuf, &threshold[key], ((ut_at42qt1050data_t*)ut->data)->timeout);
116
    }
117
    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

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

  
125
            //highlight touched key
126
            *status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_KEYSTATUS, &keyStatus, ((ut_at42qt1050data_t*)ut->data)->timeout);
127
            if((key == 0 && keyStatus&AT42QT1050_LLD_KEYSTATUS_KEY0)
128
                    || (key == 1 && keyStatus&AT42QT1050_LLD_KEYSTATUS_KEY1)
129
                    || (key == 2 && keyStatus&AT42QT1050_LLD_KEYSTATUS_KEY2)
130
                    || (key == 3 && keyStatus&AT42QT1050_LLD_KEYSTATUS_KEY3)
131
                    || (key == 4 && keyStatus&AT42QT1050_LLD_KEYSTATUS_KEY4))
132
                chprintf(stream, "\033[31m"); //red
133
            else
134
                chprintf(stream, "\033[0m"); //black
135

  
136
            *status |= at42qt1050_lld_read_keyssignal(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, key, &signal, ((ut_at42qt1050data_t*)ut->data)->timeout);
137
            *status |= at42qt1050_lld_read_referencedata(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, key, &reference, ((ut_at42qt1050data_t*)ut->data)->timeout);
138

  
139
            const uint16_t dist = (signal<reference?0:signal-reference);
140
            chprintf(stream, "\033[Kkey %d, %d\t0x%04X 0x%04X [", key, dist, reference, signal);
141
            uint16_t stars=0;
142
            for(; stars < dist; stars++) {
143
                chprintf(stream, "0");
144
                if(stars > 40) {           //max_stars = 40
145
                    chprintf(stream, "+"); //more than max_stars
146
                    break;
147
                }
148
            }
149
            for(; stars < threshold[key]; stars++)
150
                chprintf(stream, " ");
151
            if(stars == threshold[key])
152
                chprintf(stream, "]");
153
            chprintf(stream, "\n\033[0m");
154
        }
155

  
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));
159
        const eventflags_t eflags = chEvtGetAndClearFlags(&event_listener);
160
        if (emask == EVENT_MASK(INTERRUPT_EVENT_ID) && eflags == ((ut_at42qt1050data_t*)ut->data)->evtflags) {
161
            // interrupt detected
162
            chprintf(stream, "interrupt ");
163
        } // else: timeout
164

  
165
        *status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_DETECTIONSTATUS, &detectionStatus, ((ut_at42qt1050data_t*)ut->data)->timeout);
166
        if(detectionStatus & AT42QT1050_LLD_DETECTIONSTATUS_TOUCH)
167
            chprintf(stream, "touch ");
168
        if(detectionStatus & AT42QT1050_LLD_DETECTIONSTATUS_OVERFLOW)
169
            chprintf(stream, "overflow ");
170
        if(detectionStatus & AT42QT1050_LLD_DETECTIONSTATUS_CALIBRATE)
171
            chprintf(stream, "calibrate");
172
        chprintf(stream, "\033[K");
173

  
174
        if(i>=30)
175
            break;
176

  
177
        chprintf(stream, "\033[%dF", 5-first_key); //cursor up
178
    }
179
    chEvtUnregister(((ut_at42qt1050data_t*)ut->data)->evtsource, &event_listener);
180
}
181

  
46 182
/******************************************************************************/
47 183
/* EXPORTED FUNCTIONS                                                         */
48 184
/******************************************************************************/
49 185

  
50 186
aos_utresult_t utAlldAt42qt1050Func(BaseSequentialStream* stream, aos_unittest_t* ut)
51 187
{
52
  aosDbgCheck(ut->data != NULL && ((ut_at42qt1050data_t*)ut->data)->at42qt1050d != NULL);
53

  
54
  // local variables
55
  aos_utresult_t result = {0, 0};
56
  uint32_t status;
57
  uint8_t buffer8[4] = {0, 0};
58
  uint16_t buffer16[5];
59
  event_listener_t event_listener;
60
  aos_timestamp_t tstart, tcurrent, tend;
61

  
62
  chprintf(stream, "reset device...\n");
63
  at42qt1050_lld_reset(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, ((ut_at42qt1050data_t*)ut->data)->timeout, true);
64

  
65
  chprintf(stream, "read register...\n");
66
  status = at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_CHIPID, &buffer8[0], ((ut_at42qt1050data_t*)ut->data)->timeout);
67
  status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_FIRMWAREVERSION, &buffer8[1], ((ut_at42qt1050data_t*)ut->data)->timeout);
68
  chprintf(stream, "\t\tchip ID: 0x%02X\n", buffer8[0]);
69
  chprintf(stream, "\t\tfirmware version: %u.%u (0x%02X)\n", ((at42qt1050_lld_firmwarereg_t)buffer8[1]).major, ((at42qt1050_lld_firmwarereg_t)buffer8[1]).minor, buffer8[1]);
70
  if (status == APAL_STATUS_SUCCESS && buffer8[0] == AT42QT1050_LLD_CHIPID) {
71
    aosUtPassed(stream, &result);
72
  } else {
73
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
74
  }
75

  
76
  chprintf(stream, "write register...\n");
77
  buffer8[1] = (((uint8_t)(at42qt1050_lld_samples2pulse(4096) + 0.5f)) << 4) | ((uint8_t)(at42qt1050_lld_scaling2scale(1024) + 0.5f));
78
  status = at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_PULSE_SCALE_1, &buffer8[0], ((ut_at42qt1050data_t*)ut->data)->timeout);
79
  status |= at42qt1050_lld_write_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_PULSE_SCALE_1, buffer8[1] , ((ut_at42qt1050data_t*)ut->data)->timeout);
80
  status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_PULSE_SCALE_1, &buffer8[2], ((ut_at42qt1050data_t*)ut->data)->timeout);
81
  status |= at42qt1050_lld_write_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_PULSE_SCALE_1, buffer8[0] , ((ut_at42qt1050data_t*)ut->data)->timeout);
82
  status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_PULSE_SCALE_1, &buffer8[3], ((ut_at42qt1050data_t*)ut->data)->timeout);
83
  if (status == APAL_STATUS_SUCCESS &&
84
      buffer8[3] == buffer8[0] &&
85
      buffer8[2] == buffer8[1] &&
86
      at42qt1050_lld_pulse2samples(((at42qt1050_lld_pulsescalereg_t)buffer8[2]).pulse) == 4096 &&
87
      at42qt1050_lld_scale2scaling(((at42qt1050_lld_pulsescalereg_t)buffer8[2]).scale) == 1024) {
88
    aosUtPassed(stream, &result);
89
  } else {
90
    aosUtFailedMsg(stream, &result, "0x%08X [0x%02X 0x%02X 0x%02X 0x%02X]\n", status, buffer8[0], buffer8[1], buffer8[2], buffer8[3]);
91
  }
92

  
93
  chprintf(stream, "read reference data...\n");
94
  status = APAL_STATUS_OK;
95
  for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) {
96
    status |= at42qt1050_lld_read_referencedata(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, key, &buffer16[key], ((ut_at42qt1050data_t*)ut->data)->timeout);
97
    chprintf(stream, "\t\tkey %u: 0x%04X\n", key, buffer16[key]);
98
  }
99
  if (status == APAL_STATUS_SUCCESS) {
100
    aosUtPassed(stream, &result);
101
  } else {
102
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
103
  }
104

  
105
  chprintf(stream, "read key signal for ten seconds...\n");
106
  status = APAL_STATUS_OK;
107
  chprintf(stream, "\t\t key 0  key 1  key 2  key 3  key 4\n");
108
  for (uint8_t s = 0; s < 10; ++s) {
109
    aosThdSSleep(1);
188
    aosDbgCheck(ut->data != NULL && ((ut_at42qt1050data_t*)ut->data)->at42qt1050d != NULL);
189

  
190
    // local variables
191
    aos_utresult_t result = {0, 0};
192
    apalExitStatus_t status;
193
    uint8_t  test_8;
194
    bool error;
195

  
196
    chprintf(stream, "read register...\n");
197
    error = false;
198
    status = at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_CHIPID, &test_8, ((ut_at42qt1050data_t*)ut->data)->timeout);
199
    chprintf(stream, "\t\tchip ID: 0x%02X\n", test_8);
200
    if (test_8 != AT42QT1050_LLD_CHIPID)
201
        error = true;
202
    status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_FIRMWAREVERSION, &test_8, ((ut_at42qt1050data_t*)ut->data)->timeout);
203
    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);
204
    if (status == APAL_STATUS_SUCCESS && !error) {
205
        aosUtPassed(stream, &result);
206
    } else {
207
        aosUtFailedMsg(stream, &result, "0x%08X\n", status);
208
    }
209

  
210
    chprintf(stream, "write and readback threshold data...\n");
211
    status = APAL_STATUS_OK;
212
    const uint8_t threshold_test = 0x40;
213
    error = false;
214
    for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) {
215
        const at42qt1050_lld_register_t txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_NEGATIVETHRESHOLD_0, key);
216
        status |= at42qt1050_lld_write_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, txbuf, threshold_test , ((ut_at42qt1050data_t*)ut->data)->timeout);
217
        status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, txbuf, &test_8, ((ut_at42qt1050data_t*)ut->data)->timeout);
218
        if(test_8 != threshold_test)
219
            error = true;
220
    }
221
    if (status == APAL_STATUS_SUCCESS  &&  !error) {
222
        aosUtPassedMsg(stream, &result, "Set thresholds successfull to 0x%04X\n", threshold_test);
223
    } else {
224
        aosUtFailedMsg(stream, &result, "0x%08X\n", status);
225
    }
226

  
227
    chprintf(stream, "guarding...\nincrease charge_delay0\ndisable multitouch\n");
228

  
229
    //channel 0 is to big to be charged in the default cycle
230
    status = at42qt1050_lld_write_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_CHARGESHAREDELAY_0, 128 , ((ut_at42qt1050data_t*)ut->data)->timeout);
231

  
232
    //set all channel to group 1 -> only 1 simultaneous touch in group = single touch
233
    at42qt1050_lld_detectionintegratoraksreg_t detectionintegrator;
234
    for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) {
235
        const at42qt1050_lld_register_t txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_INTEGRATOR_AKS_0, key);
236
        detectionintegrator.aks = 1;                  //on touch per group-id simultaneous
237
        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);
239
    }
240
    if (status == APAL_STATUS_SUCCESS) {
241
        aosUtPassed(stream, &result);
242
    } else {
243
        aosUtFailedMsg(stream, &result, "0x%08X\n", status);
244
    }
245

  
246
    chprintf(stream, "reset device...\n");
247
    status = at42qt1050_lld_reset(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, ((ut_at42qt1050data_t*)ut->data)->timeout, true);
248
    if (status == APAL_STATUS_SUCCESS) {
249
        aosUtPassed(stream, &result);
250
    } else {
251
        aosUtFailedMsg(stream, &result, "0x%08X\n", status);
252
    }
253

  
254
    chprintf(stream, "read threshold data again...\n");
255
    status = APAL_STATUS_OK;
256
    const uint8_t threshold_default = 20;
257
    error = false;
110 258
    for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) {
111
      status |= at42qt1050_lld_read_keyssignal(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, key, &buffer16[key], ((ut_at42qt1050data_t*)ut->data)->timeout);
112
    }
113
    chprintf(stream, "\t\t0x%04X 0x%04X 0x%04X 0x%04X 0x%04X\n", buffer16[0], buffer16[1], buffer16[2], buffer16[3], buffer16[4]);
114
  }
115
  if (status == APAL_STATUS_SUCCESS) {
116
    aosUtPassed(stream, &result);
117
  } else {
118
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
119
  }
120

  
121
  chprintf(stream, "test interrupts...\n");
122
  status = AOS_OK;
123
  chEvtRegister(((ut_at42qt1050data_t*)ut->data)->evtsource, &event_listener, INTERRUPT_EVENT_ID);
124
  aosSysGetUptime(&tstart);
125
  tend = tstart + (30 * MICROSECONDS_PER_SECOND);
126
  do {
127
    aosSysGetUptime(&tcurrent);
128
    const aos_timestamp_t ttimeout = MICROSECONDS_PER_SECOND - ((tcurrent - tstart) % MICROSECONDS_PER_SECOND);
129
    const eventmask_t emask = chEvtWaitOneTimeout(EVENT_MASK(INTERRUPT_EVENT_ID), chTimeUS2I(ttimeout));
130
    const eventflags_t eflags = chEvtGetAndClearFlags(&event_listener);
131
    if (emask == EVENT_MASK(INTERRUPT_EVENT_ID) && eflags == ((ut_at42qt1050data_t*)ut->data)->evtflags) {
132
      // interrupt detected
133
      chprintf(stream, "\t\tinterrupt detected\n");
134
    } // else: timeout
135
    status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_KEYSTATUS, &buffer8[0], ((ut_at42qt1050data_t*)ut->data)->timeout);
136
    chprintf(stream, "\t\tkey status: %u %u %u %u %u\n",
137
             (((buffer8[0] & AT42QT1050_LLD_KEYSTATUS_KEY0) == 0) ? 0 : 1),
138
             (((buffer8[0] & AT42QT1050_LLD_KEYSTATUS_KEY1) == 0) ? 0 : 1),
139
             (((buffer8[0] & AT42QT1050_LLD_KEYSTATUS_KEY2) == 0) ? 0 : 1),
140
             (((buffer8[0] & AT42QT1050_LLD_KEYSTATUS_KEY3) == 0) ? 0 : 1),
141
             (((buffer8[0] & AT42QT1050_LLD_KEYSTATUS_KEY4) == 0) ? 0 : 1));
142
    aosSysGetUptime(&tcurrent);
143
  } while (tcurrent < tend);
144
  chEvtUnregister(((ut_at42qt1050data_t*)ut->data)->evtsource, &event_listener);
145
  if (status == APAL_STATUS_SUCCESS) {
146
    aosUtPassed(stream, &result);
147
  } else {
148
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
149
  }
150

  
151
  aosUtInfoMsg(stream,"driver object memory footprint: %u bytes\n", sizeof(AT42QT1050Driver));
152

  
153
  return result;
259
        const at42qt1050_lld_register_t txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_NEGATIVETHRESHOLD_0, key);
260
        status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, txbuf, &test_8, ((ut_at42qt1050data_t*)ut->data)->timeout);
261
        if(test_8 != threshold_default)
262
            error = true;
263
    }
264

  
265
    if (status == APAL_STATUS_SUCCESS && !error) {
266
        aosUtPassedMsg(stream, &result, "threshold 0x%04X = default\n", threshold_default);
267
    } else {
268
        aosUtFailedMsg(stream, &result, "0x%08X\n", status);
269
    }
270

  
271
    chprintf(stream, "demo of default configuration:\n");
272
    status = APAL_STATUS_OK;
273
    show_live(0, &status, stream, ut);
274
    if (status == APAL_STATUS_SUCCESS) {
275
        aosUtPassed(stream, &result);
276
    } else {
277
        aosUtFailedMsg(stream, &result, "0x%08X\n", status);
278
    }
279

  
280
    status = APAL_STATUS_OK;
281
    chprintf(stream, "write configuration...\npuls + scale + threshold 16\n");
282
    at42qt1050_lld_pulsescalereg_t pulse_scale;
283
    //values stored as exponent of 2
284
    pulse_scale.pulse = 0; // accumulate #pulses -> increase resolution & time to acquire
285
    pulse_scale.scale = 0; // scale = average factor n: NewAvg = (NewData/n) + [OldAvg*(n-1/n)] -> decrease noise
286
    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);
288
    pulse_scale.pulse = 4;
289
    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
    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);
291
    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

  
293
    for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) {
294
        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);
296
    }
297
    chprintf(stream, "disable guard key\n");
298
    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
299
    status |= at42qt1050_lld_write_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_FINFOUTMAXCALGUARD, 8 , ((ut_at42qt1050data_t*)ut->data)->timeout); //disable feature
300

  
301
    chprintf(stream, "calibrate...\n");
302
    status = at42qt1050_lld_write_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_RESET_CALIBRATE, AT42QT1050_LLD_RESETCALIBRATE_CALIBRATE, ((ut_at42qt1050data_t*)ut->data)->timeout);
303

  
304

  
305

  
306
    //wait for calibration to complete
307
    error = true;
308
    for(uint8_t i=0; i<0xFF; i++) {
309
        usleep(10);
310
        status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_DETECTIONSTATUS, &test_8, ((ut_at42qt1050data_t*)ut->data)->timeout);
311
        if(!(test_8 & AT42QT1050_LLD_DETECTIONSTATUS_CALIBRATE)) {
312
            error = false;
313
            break;
314
        }
315
    }
316
    if (status == APAL_STATUS_SUCCESS) {
317
        aosUtPassed(stream, &result);
318
    } else {
319
        aosUtFailedMsg(stream, &result, "0x%08X\n", status);
320
    }
321
    chprintf(stream, "demo of custom configuration:\n");
322
    status = APAL_STATUS_OK;
323
    show_live(1, &status, stream, ut);
324
    if (status == APAL_STATUS_SUCCESS) {
325
        aosUtPassed(stream, &result);
326
    } else {
327
        aosUtFailedMsg(stream, &result, "0x%08X\n", status);
328
    }
329

  
330
    status = APAL_STATUS_OK;
331
    print_settings(&status, stream, ut);
332
    if (status == APAL_STATUS_SUCCESS) {
333
        aosUtPassed(stream, &result);
334
    } else {
335
        aosUtFailedMsg(stream, &result, "0x%08X\n", status);
336
    }
337

  
338
    chprintf(stream, "shutdown touch\n");
339
    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);
341
    if (status == APAL_STATUS_SUCCESS) {
342
        aosUtPassed(stream, &result);
343
    } else {
344
        aosUtFailedMsg(stream, &result, "0x%08X\n", status);
345
    }
346

  
347
    aosUtInfoMsg(stream,"driver object memory footprint: %u bytes\n", sizeof(AT42QT1050Driver));
348

  
349
    return result;
154 350
}
155 351

  
156
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_AT42QT1050) && (AMIROLLD_CFG_AT42QT1050 == 1) */
352
#endif

Also available in: Unified diff