Statistics
| Branch: | Tag: | Revision:

amiro-os / unittests / periphery-lld / src / ut_alld_AT42QT1050_v1.c @ 2a4dbf93

History | View | Annotate | Download (8.13 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, "read register...\n");
63
  status = at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_CHIPID, &buffer8[0], ((ut_at42qt1050data_t*)ut->data)->timeout);
64
  status |= at42qt1050_lld_read_reg(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, AT42QT1050_LLD_REG_FIRMWAREVERSION, &buffer8[1], ((ut_at42qt1050data_t*)ut->data)->timeout);
65
  chprintf(stream, "\t\tchip ID: 0x%02X\n", buffer8[0]);
66
  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]);
67
  if (status == APAL_STATUS_SUCCESS && buffer8[0] == AT42QT1050_LLD_CHIPID) {
68
    aosUtPassed(stream, &result);
69
  } else {
70
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
71
  }
72

    
73
  chprintf(stream, "write register...\n");
74
  buffer8[1] = (((uint8_t)(at42qt1050_lld_samples2pulse(4096) + 0.5f)) << 4) | ((uint8_t)(at42qt1050_lld_scaling2scale(1024) + 0.5f));
75
  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);
76
  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);
77
  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);
78
  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);
79
  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);
80
  if (status == APAL_STATUS_SUCCESS &&
81
      buffer8[3] == buffer8[0] &&
82
      buffer8[2] == buffer8[1] &&
83
      at42qt1050_lld_pulse2samples(((at42qt1050_lld_pulsescalereg_t)buffer8[2]).pulse) == 4096 &&
84
      at42qt1050_lld_scale2scaling(((at42qt1050_lld_pulsescalereg_t)buffer8[2]).scale) == 1024) {
85
    aosUtPassed(stream, &result);
86
  } else {
87
    aosUtFailedMsg(stream, &result, "0x%08X [0x%02X 0x%02X 0x%02X 0x%02X]\n", status, buffer8[0], buffer8[1], buffer8[2], buffer8[3]);
88
  }
89

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

    
102
  chprintf(stream, "read key signal for ten seconds...\n");
103
  status = APAL_STATUS_OK;
104
  chprintf(stream, "\t\t key 0  key 1  key 2  key 3  key 4\n");
105
  for (uint8_t s = 0; s < 10; ++s) {
106
    aosThdSSleep(1);
107
    for (uint8_t key = 0; key < AT42QT1050_LLD_NUM_KEYS; ++key) {
108
      status |= at42qt1050_lld_read_keyssignal(((ut_at42qt1050data_t*)ut->data)->at42qt1050d, key, &buffer16[key], ((ut_at42qt1050data_t*)ut->data)->timeout);
109
    }
110
    chprintf(stream, "\t\t0x%04X 0x%04X 0x%04X 0x%04X 0x%04X\n", buffer16[0], buffer16[1], buffer16[2], buffer16[3], buffer16[4]);
111
  }
112
  if (status == APAL_STATUS_SUCCESS) {
113
    aosUtPassed(stream, &result);
114
  } else {
115
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
116
  }
117

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

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

    
150
  return result;
151
}
152

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