amiro-os / unittests / periphery-lld / src / ut_alld_at42qt1050.c @ 90e99d44
History | View | Annotate | Download (6.709 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 | #include <ut_alld_at42qt1050.h> |
||
20 | |||
21 | #if ((AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_AT42QT1050)) || defined(__DOXYGEN__) |
||
22 | |||
23 | #include <aos_debug.h> |
||
24 | #include <chprintf.h> |
||
25 | #include <aos_thread.h> |
||
26 | #include <amiroos.h> |
||
27 | |||
28 | #define INTERRUPT_EVENT_ID 1 |
||
29 | |||
30 | aos_utresult_t utAlldAt42qt1050Func(BaseSequentialStream* stream, aos_unittest_t* ut) |
||
31 | { |
||
32 | aosDbgCheck(ut->data != NULL && ((ut_at42qt1050data_t*)ut->data)->at42qt1050d != NULL); |
||
33 | |||
34 | // local variables
|
||
35 | aos_utresult_t result = {0, 0}; |
||
36 | uint32_t status; |
||
37 | uint8_t buffer8[4] = {0, 0}; |
||
38 | uint16_t buffer16[5];
|
||
39 | event_listener_t event_listener; |
||
40 | aos_timestamp_t tstart, tcurrent, tend; |
||
41 | |||
42 | chprintf(stream, "read register...\n");
|
||
43 | status = at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_CHIPID, &buffer8[0], ((ut_at42qt1050data_t*)ut->data)->timeout);
|
||
44 | status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_FIRMWAREVERSION, &buffer8[1], ((ut_at42qt1050data_t*)ut->data)->timeout);
|
||
45 | chprintf(stream, "\t\tchip ID: 0x%02X\n", buffer8[0]); |
||
46 | 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]); |
||
47 | if (status == APAL_STATUS_SUCCESS && buffer8[0] == AT42QT1050_LLD_CHIPID) { |
||
48 | aosUtPassed(stream, &result); |
||
49 | } else {
|
||
50 | aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
||
51 | } |
||
52 | |||
53 | chprintf(stream, "write register...\n");
|
||
54 | buffer8[1] = (((uint8_t)(at42qt1050_lld_samples2pulse(4096) + 0.5f)) << 4) | ((uint8_t)(at42qt1050_lld_scaling2scale(1024) + 0.5f)); |
||
55 | 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);
|
||
56 | 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);
|
||
57 | 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);
|
||
58 | 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);
|
||
59 | 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);
|
||
60 | if (status == APAL_STATUS_SUCCESS &&
|
||
61 | buffer8[3] == buffer8[0] && |
||
62 | buffer8[2] == buffer8[1] && |
||
63 | at42qt1050_lld_pulse2samples(((at42qt1050_lld_pulsescalereg_t)buffer8[2]).pulse) == 4096 && |
||
64 | at42qt1050_lld_scale2scaling(((at42qt1050_lld_pulsescalereg_t)buffer8[2]).scale) == 1024) { |
||
65 | aosUtPassed(stream, &result); |
||
66 | } else {
|
||
67 | aosUtFailedMsg(stream, &result, "0x%08X [0x%02X 0x%02X 0x%02X 0x%02X]\n", status, buffer8[0], buffer8[1], buffer8[2], buffer8[3]); |
||
68 | } |
||
69 | |||
70 | chprintf(stream, "read reference data...\n");
|
||
71 | status = APAL_STATUS_OK; |
||
72 | for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) { |
||
73 | status |= at42qt1050_lld_read_referencedata(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, key, &buffer16[key], ((ut_at42qt1050data_t*)ut->data)->timeout); |
||
74 | chprintf(stream, "\t\tkey %u: 0x%04X\n", key, buffer16[key]);
|
||
75 | } |
||
76 | if (status == APAL_STATUS_SUCCESS) {
|
||
77 | aosUtPassed(stream, &result); |
||
78 | } else {
|
||
79 | aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
||
80 | } |
||
81 | |||
82 | chprintf(stream, "read key signal for ten seconds...\n");
|
||
83 | status = APAL_STATUS_OK; |
||
84 | chprintf(stream, "\t\t key 0 key 1 key 2 key 3 key 4\n");
|
||
85 | for (uint8_t s = 0; s < 10; ++s) { |
||
86 | aosThdSSleep(1);
|
||
87 | for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) { |
||
88 | status |= at42qt1050_lld_read_keyssignal(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, key, &buffer16[key], ((ut_at42qt1050data_t*)ut->data)->timeout); |
||
89 | } |
||
90 | chprintf(stream, "\t\t0x%04X 0x%04X 0x%04X 0x%04X 0x%04X\n", buffer16[0], buffer16[1], buffer16[2], buffer16[3], buffer16[4]); |
||
91 | } |
||
92 | if (status == APAL_STATUS_SUCCESS) {
|
||
93 | aosUtPassed(stream, &result); |
||
94 | } else {
|
||
95 | aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
||
96 | } |
||
97 | |||
98 | chprintf(stream, "test interrupts...\n");
|
||
99 | status = AOS_OK; |
||
100 | chEvtRegister(((ut_at42qt1050data_t*)ut->data)->evtsource, &event_listener, INTERRUPT_EVENT_ID); |
||
101 | aosSysGetUptime(&tstart); |
||
102 | tend = tstart + (30 * MICROSECONDS_PER_SECOND);
|
||
103 | do {
|
||
104 | aosSysGetUptime(&tcurrent); |
||
105 | const aos_timestamp_t ttimeout = MICROSECONDS_PER_SECOND - ((tcurrent - tstart) % MICROSECONDS_PER_SECOND);
|
||
106 | const eventmask_t emask = chEvtWaitOneTimeout(EVENT_MASK(INTERRUPT_EVENT_ID), chTimeUS2I(ttimeout));
|
||
107 | const eventflags_t eflags = chEvtGetAndClearFlags(&event_listener);
|
||
108 | if (emask == EVENT_MASK(INTERRUPT_EVENT_ID) && eflags == ((ut_at42qt1050data_t*)ut->data)->evtflags) {
|
||
109 | // interrupt detected
|
||
110 | chprintf(stream, "\t\tinterrupt detected\n");
|
||
111 | } // else: timeout
|
||
112 | status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_KEYSTATUS, &buffer8[0], ((ut_at42qt1050data_t*)ut->data)->timeout);
|
||
113 | chprintf(stream, "\t\tkey status: %u %u %u %u %u\n",
|
||
114 | (((buffer8[0] & AT42QT1050_LLD_KEYSTATUS_KEY0) == 0) ? 0 : 1), |
||
115 | (((buffer8[0] & AT42QT1050_LLD_KEYSTATUS_KEY1) == 0) ? 0 : 1), |
||
116 | (((buffer8[0] & AT42QT1050_LLD_KEYSTATUS_KEY2) == 0) ? 0 : 1), |
||
117 | (((buffer8[0] & AT42QT1050_LLD_KEYSTATUS_KEY3) == 0) ? 0 : 1), |
||
118 | (((buffer8[0] & AT42QT1050_LLD_KEYSTATUS_KEY4) == 0) ? 0 : 1)); |
||
119 | aosSysGetUptime(&tcurrent); |
||
120 | } while (tcurrent < tend);
|
||
121 | chEvtUnregister(((ut_at42qt1050data_t*)ut->data)->evtsource, &event_listener); |
||
122 | if (status == APAL_STATUS_SUCCESS) {
|
||
123 | aosUtPassed(stream, &result); |
||
124 | } else {
|
||
125 | aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
||
126 | } |
||
127 | |||
128 | aosUtInfoMsg(stream,"driver object memory footprint: %u bytes\n", sizeof(AT42QT1050Driver)); |
||
129 | |||
130 | return result;
|
||
131 | } |
||
132 | |||
133 | #endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_AT42QT1050) */ |