Statistics
| Branch: | Tag: | Revision:

amiro-os / unittests / periphery-lld / src / ut_alld_AT42QT1050_v1.c @ 0f60c8ad

History | View | Annotate | Download (8.29 KB)

1
/*
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 <amiroos.h>
20
#include <ut_alld_AT42QT1050_v1.h>
21

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

    
24
/******************************************************************************/
25
/* LOCAL DEFINITIONS                                                          */
26
/******************************************************************************/
27

    
28
#define INTERRUPT_EVENT_ID            1
29

    
30
/******************************************************************************/
31
/* EXPORTED VARIABLES                                                         */
32
/******************************************************************************/
33

    
34
/******************************************************************************/
35
/* LOCAL TYPES                                                                */
36
/******************************************************************************/
37

    
38
/******************************************************************************/
39
/* LOCAL VARIABLES                                                            */
40
/******************************************************************************/
41

    
42
/******************************************************************************/
43
/* LOCAL FUNCTIONS                                                            */
44
/******************************************************************************/
45

    
46
/******************************************************************************/
47
/* EXPORTED FUNCTIONS                                                         */
48
/******************************************************************************/
49

    
50
aos_utresult_t utAlldAt42qt1050Func(BaseSequentialStream* stream, aos_unittest_t* ut)
51
{
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);
110
    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;
154
}
155

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