amiro-os / test / periphery-lld / AT42QT1050_v1 / aos_test_AT42QT1050.c @ 8d4d058e
History | View | Annotate | Download (18.758 KB)
| 1 | bffb3465 | Thomas Schöpping | /*
 | 
      
|---|---|---|---|
| 2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
 | 
      ||
| 3 | Copyright (C) 2016..2019  Thomas Schöpping et al.
 | 
      ||
| 4 | |||
| 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 | 4c72a54c | Thomas Schöpping |     aos_testresult_t result = {0, 0};
 | 
      
| 195 | b23ca7cc | Thomas Schöpping | int32_t status;  | 
      
| 196 | 265dae32 | Felix Wittenfeld | uint8_t test_8;  | 
      
| 197 | 651cb6e6 | Felix Wittenfeld |     bool error;
 | 
      
| 198 | |||
| 199 |     chprintf(stream, "read register...\n");
 | 
      ||
| 200 |     error = false;
 | 
      ||
| 201 | 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);  | 
      
| 202 | 651cb6e6 | Felix Wittenfeld |     chprintf(stream, "\t\tchip ID: 0x%02X\n", test_8);
 | 
      
| 203 |     if (test_8 != AT42QT1050_LLD_CHIPID)
 | 
      ||
| 204 |         error = true;
 | 
      ||
| 205 | 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);  | 
      
| 206 | 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);
 | 
      
| 207 |     if (status == APAL_STATUS_SUCCESS && !error) {
 | 
      ||
| 208 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result);  | 
      
| 209 | 651cb6e6 | Felix Wittenfeld |     } else {
 | 
      
| 210 | 4c72a54c | Thomas Schöpping |         aosTestFailedMsg(stream, &result, "0x%08X\n", status);
 | 
      
| 211 | 651cb6e6 | Felix Wittenfeld | }  | 
      
| 212 | |||
| 213 |     chprintf(stream, "write and readback threshold data...\n");
 | 
      ||
| 214 | status = APAL_STATUS_OK;  | 
      ||
| 215 | const uint8_t threshold_test = 0x40;  | 
      ||
| 216 |     error = false;
 | 
      ||
| 217 | for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) {  | 
      ||
| 218 |         const at42qt1050_lld_register_t txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_NEGATIVETHRESHOLD_0, key);
 | 
      ||
| 219 | 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);  | 
      
| 220 | status |= at42qt1050_lld_read_reg(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, txbuf, &test_8, ((aos_test_at42qt1050data_t*)test->data)->timeout);  | 
      ||
| 221 | 651cb6e6 | Felix Wittenfeld |         if(test_8 != threshold_test)
 | 
      
| 222 |             error = true;
 | 
      ||
| 223 | }  | 
      ||
| 224 |     if (status == APAL_STATUS_SUCCESS  &&  !error) {
 | 
      ||
| 225 | 4c72a54c | Thomas Schöpping |         aosTestPassedMsg(stream, &result, "Set thresholds successfull to 0x%04X\n", threshold_test);
 | 
      
| 226 | 651cb6e6 | Felix Wittenfeld |     } else {
 | 
      
| 227 | 4c72a54c | Thomas Schöpping |         aosTestFailedMsg(stream, &result, "0x%08X\n", status);
 | 
      
| 228 | 651cb6e6 | Felix Wittenfeld | }  | 
      
| 229 | |||
| 230 |     chprintf(stream, "guarding...\nincrease charge_delay0\ndisable multitouch\n");
 | 
      ||
| 231 | |||
| 232 |     //channel 0 is to big to be charged in the default cycle
 | 
      ||
| 233 | 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);
 | 
      
| 234 | 651cb6e6 | Felix Wittenfeld | |
| 235 |     //set all channel to group 1 -> only 1 simultaneous touch in group = single touch
 | 
      ||
| 236 | at42qt1050_lld_detectionintegratoraksreg_t detectionintegrator;  | 
      ||
| 237 | for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) {  | 
      ||
| 238 |         const at42qt1050_lld_register_t txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_INTEGRATOR_AKS_0, key);
 | 
      ||
| 239 | detectionintegrator.aks = 1; //on touch per group-id simultaneous  | 
      ||
| 240 | detectionintegrator.detection_integrator = 4; //4 times > threshold => touchevent  | 
      ||
| 241 | 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);  | 
      
| 242 | 651cb6e6 | Felix Wittenfeld | }  | 
      
| 243 |     if (status == APAL_STATUS_SUCCESS) {
 | 
      ||
| 244 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result);  | 
      
| 245 | 651cb6e6 | Felix Wittenfeld |     } else {
 | 
      
| 246 | 4c72a54c | Thomas Schöpping |         aosTestFailedMsg(stream, &result, "0x%08X\n", status);
 | 
      
| 247 | 651cb6e6 | Felix Wittenfeld | }  | 
      
| 248 | |||
| 249 |     chprintf(stream, "reset device...\n");
 | 
      ||
| 250 | 4c72a54c | Thomas Schöpping |     status = at42qt1050_lld_reset(((aos_test_at42qt1050data_t*)test->data)->at42qt1050d, ((aos_test_at42qt1050data_t*)test->data)->timeout, true);
 | 
      
| 251 | 651cb6e6 | Felix Wittenfeld |     if (status == APAL_STATUS_SUCCESS) {
 | 
      
| 252 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result);  | 
      
| 253 | 651cb6e6 | Felix Wittenfeld |     } else {
 | 
      
| 254 | 4c72a54c | Thomas Schöpping |         aosTestFailedMsg(stream, &result, "0x%08X\n", status);
 | 
      
| 255 | 651cb6e6 | Felix Wittenfeld | }  | 
      
| 256 | |||
| 257 |     chprintf(stream, "read threshold data again...\n");
 | 
      ||
| 258 | status = APAL_STATUS_OK;  | 
      ||
| 259 | const uint8_t threshold_default = 20;  | 
      ||
| 260 |     error = false;
 | 
      ||
| 261 | bffb3465 | Thomas Schöpping | for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) {  | 
      
| 262 | 651cb6e6 | Felix Wittenfeld |         const at42qt1050_lld_register_t txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_NEGATIVETHRESHOLD_0, key);
 | 
      
| 263 | 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);  | 
      
| 264 | 651cb6e6 | Felix Wittenfeld |         if(test_8 != threshold_default)
 | 
      
| 265 |             error = true;
 | 
      ||
| 266 | }  | 
      ||
| 267 | |||
| 268 |     if (status == APAL_STATUS_SUCCESS && !error) {
 | 
      ||
| 269 | 4c72a54c | Thomas Schöpping |         aosTestPassedMsg(stream, &result, "threshold 0x%04X = default\n", threshold_default);
 | 
      
| 270 | 651cb6e6 | Felix Wittenfeld |     } else {
 | 
      
| 271 | 4c72a54c | Thomas Schöpping |         aosTestFailedMsg(stream, &result, "0x%08X\n", status);
 | 
      
| 272 | 651cb6e6 | Felix Wittenfeld | }  | 
      
| 273 | |||
| 274 |     chprintf(stream, "demo of default configuration:\n");
 | 
      ||
| 275 | status = APAL_STATUS_OK;  | 
      ||
| 276 | 4c72a54c | Thomas Schöpping |     show_live(0, &status, stream, test);
 | 
      
| 277 | 651cb6e6 | Felix Wittenfeld |     if (status == APAL_STATUS_SUCCESS) {
 | 
      
| 278 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result);  | 
      
| 279 | 651cb6e6 | Felix Wittenfeld |     } else {
 | 
      
| 280 | 4c72a54c | Thomas Schöpping |         aosTestFailedMsg(stream, &result, "0x%08X\n", status);
 | 
      
| 281 | 651cb6e6 | Felix Wittenfeld | }  | 
      
| 282 | |||
| 283 | status = APAL_STATUS_OK;  | 
      ||
| 284 | 265dae32 | Felix Wittenfeld |     chprintf(stream, "write configuration...\npuls + scale + threshold 8\n");
 | 
      
| 285 | 651cb6e6 | Felix Wittenfeld | at42qt1050_lld_pulsescalereg_t pulse_scale;  | 
      
| 286 |     //values stored as exponent of 2
 | 
      ||
| 287 | pulse_scale.pulse = 0; // accumulate #pulses -> increase resolution & time to acquire  | 
      ||
| 288 | pulse_scale.scale = 0; // scale = average factor n: NewAvg = (NewData/n) + [OldAvg*(n-1/n)] -> decrease noise  | 
      ||
| 289 | 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);  | 
      
| 290 | 265dae32 | Felix Wittenfeld |     pulse_scale.pulse = 1;
 | 
      
| 291 | 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);  | 
      
| 292 | 265dae32 | Felix Wittenfeld | |
| 293 | 651cb6e6 | Felix Wittenfeld |     pulse_scale.pulse = 4;
 | 
      
| 294 | 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);  | 
      
| 295 | 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);  | 
      ||
| 296 | 265dae32 | Felix Wittenfeld | |
| 297 | 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);  | 
      
| 298 | 651cb6e6 | Felix Wittenfeld | |
| 299 | for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) {  | 
      ||
| 300 |         const at42qt1050_lld_register_t txbuf = at42qt1050_lld_addr_calc(AT42QT1050_LLD_REG_NEGATIVETHRESHOLD_0, key);
 | 
      ||
| 301 | 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);
 | 
      
| 302 | 651cb6e6 | Felix Wittenfeld | }  | 
      
| 303 |     chprintf(stream, "disable guard key\n");
 | 
      ||
| 304 | 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  | 
      
| 305 | 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  | 
      ||
| 306 | 651cb6e6 | Felix Wittenfeld | |
| 307 |     chprintf(stream, "calibrate...\n");
 | 
      ||
| 308 | 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);  | 
      
| 309 | 651cb6e6 | Felix Wittenfeld | |
| 310 | |||
| 311 | |||
| 312 |     //wait for calibration to complete
 | 
      ||
| 313 |     error = true;
 | 
      ||
| 314 | for(uint8_t i=0; i<0xFF; i++) {  | 
      ||
| 315 |         usleep(10);
 | 
      ||
| 316 | 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);  | 
      
| 317 | 651cb6e6 | Felix Wittenfeld |         if(!(test_8 & AT42QT1050_LLD_DETECTIONSTATUS_CALIBRATE)) {
 | 
      
| 318 |             error = false;
 | 
      ||
| 319 |             break;
 | 
      ||
| 320 | }  | 
      ||
| 321 | }  | 
      ||
| 322 |     if (status == APAL_STATUS_SUCCESS) {
 | 
      ||
| 323 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result);  | 
      
| 324 | 651cb6e6 | Felix Wittenfeld |     } else {
 | 
      
| 325 | 4c72a54c | Thomas Schöpping |         aosTestFailedMsg(stream, &result, "0x%08X\n", status);
 | 
      
| 326 | 651cb6e6 | Felix Wittenfeld | }  | 
      
| 327 |     chprintf(stream, "demo of custom configuration:\n");
 | 
      ||
| 328 | status = APAL_STATUS_OK;  | 
      ||
| 329 | 4c72a54c | Thomas Schöpping |     show_live(1, &status, stream, test);
 | 
      
| 330 | 651cb6e6 | Felix Wittenfeld |     if (status == APAL_STATUS_SUCCESS) {
 | 
      
| 331 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result);  | 
      
| 332 | 651cb6e6 | Felix Wittenfeld |     } else {
 | 
      
| 333 | 4c72a54c | Thomas Schöpping |         aosTestFailedMsg(stream, &result, "0x%08X\n", status);
 | 
      
| 334 | 651cb6e6 | Felix Wittenfeld | }  | 
      
| 335 | |||
| 336 | status = APAL_STATUS_OK;  | 
      ||
| 337 | 4c72a54c | Thomas Schöpping | print_settings(&status, stream, test);  | 
      
| 338 | 651cb6e6 | Felix Wittenfeld |     if (status == APAL_STATUS_SUCCESS) {
 | 
      
| 339 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result);  | 
      
| 340 | 651cb6e6 | Felix Wittenfeld |     } else {
 | 
      
| 341 | 4c72a54c | Thomas Schöpping |         aosTestFailedMsg(stream, &result, "0x%08X\n", status);
 | 
      
| 342 | 651cb6e6 | Felix Wittenfeld | }  | 
      
| 343 | |||
| 344 |     chprintf(stream, "shutdown touch\n");
 | 
      ||
| 345 | test_8 = 0; //Power down  | 
      ||
| 346 | 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);  | 
      
| 347 | 651cb6e6 | Felix Wittenfeld |     if (status == APAL_STATUS_SUCCESS) {
 | 
      
| 348 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result);  | 
      
| 349 | 651cb6e6 | Felix Wittenfeld |     } else {
 | 
      
| 350 | 4c72a54c | Thomas Schöpping |         aosTestFailedMsg(stream, &result, "0x%08X\n", status);
 | 
      
| 351 | 651cb6e6 | Felix Wittenfeld | }  | 
      
| 352 | |||
| 353 | 4c72a54c | Thomas Schöpping | aosTestInfoMsg(stream,"driver object memory footprint: %u bytes\n", sizeof(AT42QT1050Driver));  | 
      
| 354 | 651cb6e6 | Felix Wittenfeld | |
| 355 |     return result;
 | 
      ||
| 356 | bffb3465 | Thomas Schöpping | }  | 
      
| 357 | |||
| 358 | 4c72a54c | Thomas Schöpping | #endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */  |