Statistics
| Branch: | Tag: | Revision:

amiro-os / unittests / periphery-lld / src / ut_alld_AT42QT1050_v1.c @ 9487b4cd

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