amiro-os / unittests / periphery-lld / src / ut_alld_TLC5947_v1.c @ ddf34c3d
History | View | Annotate | Download (8.2 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 |
|
21 |
#if ((AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_TLC5947) && (AMIROLLD_CFG_TLC5947 == 1)) || defined(__DOXYGEN__) |
22 |
|
23 |
#include <ut_alld_TLC5947_v1.h> |
24 |
#include <string.h> |
25 |
|
26 |
/******************************************************************************/
|
27 |
/* LOCAL DEFINITIONS */
|
28 |
/******************************************************************************/
|
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 |
/**
|
51 |
* @brief TLC9547 unit test function
|
52 |
*
|
53 |
* @param[in] stream Stream for input/output.
|
54 |
* @param[in] ut Unit test object.
|
55 |
*
|
56 |
* @return Unit test result value.
|
57 |
*/
|
58 |
aos_utresult_t utAlldTlc5947Func(BaseSequentialStream *stream, aos_unittest_t *ut) |
59 |
{ |
60 |
aosDbgCheck(ut->data != NULL);
|
61 |
|
62 |
// local variables
|
63 |
aos_utresult_t result = {0, 0}; |
64 |
uint32_t status = 0;
|
65 |
tlc5947_lld_blank_t blank; |
66 |
tlc5947_lld_buffer_t buffer; |
67 |
|
68 |
chprintf(stream, "reading blank pin...\n");
|
69 |
status = tlc5947_lld_getBlank((TLC5947Driver*)ut->data, &blank); |
70 |
if (status == APAL_STATUS_OK) {
|
71 |
aosUtPassedMsg(stream, &result, "blank is %s\n", (blank == TLC5947_LLD_BLANK_ENABLE) ? "enabled" : "disabled"); |
72 |
} else {
|
73 |
aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
74 |
} |
75 |
|
76 |
// enabling/disabling blank pin
|
77 |
for (uint8_t i = 0; i < 2; ++i) { |
78 |
blank = (blank == TLC5947_LLD_BLANK_ENABLE) ? TLC5947_LLD_BLANK_DISABLE : TLC5947_LLD_BLANK_ENABLE; |
79 |
tlc5947_lld_blank_t blank_after = (blank == TLC5947_LLD_BLANK_ENABLE) ? TLC5947_LLD_BLANK_DISABLE : TLC5947_LLD_BLANK_ENABLE; |
80 |
chprintf(stream, "%s blank pin...\n", (blank == TLC5947_LLD_BLANK_ENABLE) ? "enabling" : "disabling"); |
81 |
status = tlc5947_lld_setBlank((TLC5947Driver*)ut->data, blank); |
82 |
status |= tlc5947_lld_getBlank((TLC5947Driver*)ut->data, &blank_after); |
83 |
if (status == APAL_STATUS_OK && blank_after == blank) {
|
84 |
aosUtPassed(stream, &result); |
85 |
} else {
|
86 |
aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
87 |
} |
88 |
} |
89 |
|
90 |
chprintf(stream, "setting all black and dimming white...\n");
|
91 |
status = tlc5947_lld_setBlank((TLC5947Driver*)ut->data, TLC5947_LLD_BLANK_ENABLE); |
92 |
memset(buffer.data, 0, TLC5947_LLD_BUFFER_SIZE);
|
93 |
status |= tlc5947_lld_write((TLC5947Driver*)ut->data, &buffer); |
94 |
status |= tlc5947_lld_update((TLC5947Driver*)ut->data); |
95 |
status |= tlc5947_lld_setBlank((TLC5947Driver*)ut->data, TLC5947_LLD_BLANK_DISABLE); |
96 |
for (uint8_t bit = 0; bit < TLC5947_LLD_PWM_RESOLUTION_BITS; ++bit) { |
97 |
for (uint8_t channel = 0; channel < TLC5947_LLD_NUM_CHANNELS; ++channel) { |
98 |
tlc5947_lld_setBuffer(&buffer, channel, (1 << (bit+1)) - 1); |
99 |
} |
100 |
status |= tlc5947_lld_write((TLC5947Driver*)ut->data, &buffer); |
101 |
status |= tlc5947_lld_update((TLC5947Driver*)ut->data); |
102 |
aosThdMSleep(100);
|
103 |
} |
104 |
if (status == APAL_STATUS_OK) {
|
105 |
aosUtPassed(stream, &result); |
106 |
} else {
|
107 |
aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
108 |
} |
109 |
|
110 |
chprintf(stream, "NOT dimming black again...\n");
|
111 |
status = APAL_STATUS_OK; |
112 |
for (uint8_t bit = TLC5947_LLD_PWM_RESOLUTION_BITS; bit > 0; --bit) { |
113 |
for (uint8_t channel = 0; channel < TLC5947_LLD_NUM_CHANNELS; ++channel) { |
114 |
tlc5947_lld_setBuffer(&buffer, channel, (1 << bit) - 1); |
115 |
} |
116 |
status |= tlc5947_lld_setBlank((TLC5947Driver*)ut->data, TLC5947_LLD_BLANK_ENABLE); |
117 |
status |= tlc5947_lld_write((TLC5947Driver*)ut->data, &buffer); |
118 |
status |= tlc5947_lld_setBlank((TLC5947Driver*)ut->data, TLC5947_LLD_BLANK_ENABLE); |
119 |
// Grayscale data is not updated this time (tlc5947_lld_update() not called).
|
120 |
// TODO: For some reason the PWMs are updated nevertheless.
|
121 |
aosThdMSleep(100);
|
122 |
} |
123 |
status |= tlc5947_lld_setBlank((TLC5947Driver*)ut->data, TLC5947_LLD_BLANK_ENABLE); |
124 |
if (status == APAL_STATUS_OK) {
|
125 |
aosUtPassed(stream, &result); |
126 |
} else {
|
127 |
aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
128 |
} |
129 |
|
130 |
chprintf(stream, "setting each channel incrementally...\n");
|
131 |
status = APAL_STATUS_OK; |
132 |
memset(buffer.data, 0, TLC5947_LLD_BUFFER_SIZE);
|
133 |
status |= tlc5947_lld_write((TLC5947Driver*)ut->data, &buffer); |
134 |
status |= tlc5947_lld_update((TLC5947Driver*)ut->data); |
135 |
status |= tlc5947_lld_setBlank((TLC5947Driver*)ut->data, TLC5947_LLD_BLANK_DISABLE); |
136 |
for (uint8_t channel = 0; channel < TLC5947_LLD_NUM_CHANNELS; ++channel) { |
137 |
uint16_t value = 0x0000u;
|
138 |
for (uint8_t byte = 0; byte < 3; ++byte) { |
139 |
switch (byte) {
|
140 |
case 0: |
141 |
value |= 0x00Fu;
|
142 |
break;
|
143 |
case 1: |
144 |
value |= 0x0F0u;
|
145 |
break;
|
146 |
case 2: |
147 |
value |= 0xF00u;
|
148 |
break;
|
149 |
} |
150 |
tlc5947_lld_setBuffer(&buffer, channel, value); |
151 |
status |= tlc5947_lld_write((TLC5947Driver*)ut->data, &buffer); |
152 |
status |= tlc5947_lld_update((TLC5947Driver*)ut->data); |
153 |
aosThdSleep(1.0f / 3.0f); |
154 |
tlc5947_lld_setBuffer(&buffer, channel, 0);
|
155 |
} |
156 |
} |
157 |
if (status == APAL_STATUS_OK) {
|
158 |
aosUtPassed(stream, &result); |
159 |
} else {
|
160 |
aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
161 |
} |
162 |
|
163 |
chprintf(stream, "setting one color after another...\n");
|
164 |
status = APAL_STATUS_OK; |
165 |
for (int8_t color = 0; color < 3; ++color) { |
166 |
for (uint8_t channel = color; channel < TLC5947_LLD_NUM_CHANNELS; channel += 3) { |
167 |
const uint16_t val = 0xAF5u; // some deterministic value with high entropy |
168 |
tlc5947_lld_setBuffer(&buffer, channel, val); |
169 |
status |= tlc5947_lld_write((TLC5947Driver*)ut->data, &buffer); |
170 |
status |= tlc5947_lld_update((TLC5947Driver*)ut->data); |
171 |
status |= (tlc5947_lld_getBuffer(&buffer, channel) != val) ? (1 << 31) : 0; |
172 |
if (status != APAL_STATUS_OK) {
|
173 |
break;
|
174 |
} else {
|
175 |
aosThdSleep(1.0f / 8.0f); |
176 |
} |
177 |
} |
178 |
for (uint8_t channel = 0; channel < TLC5947_LLD_NUM_CHANNELS; ++channel) { |
179 |
tlc5947_lld_setBuffer(&buffer, channel, 0);
|
180 |
} |
181 |
} |
182 |
if (status == APAL_STATUS_OK) {
|
183 |
aosUtPassed(stream, &result); |
184 |
} else {
|
185 |
aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
186 |
} |
187 |
|
188 |
// turn LEDs off
|
189 |
tlc5947_lld_setBlank((TLC5947Driver*)ut->data, TLC5947_LLD_BLANK_ENABLE); |
190 |
memset(buffer.data, 0, TLC5947_LLD_BUFFER_SIZE);
|
191 |
tlc5947_lld_write((TLC5947Driver*)ut->data, &buffer); |
192 |
tlc5947_lld_update((TLC5947Driver*)ut->data); |
193 |
|
194 |
aosUtInfoMsg(stream, "driver object memory footprint: %u bytes\n", sizeof(TLC5947Driver)); |
195 |
|
196 |
return result;
|
197 |
} |
198 |
|
199 |
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_TLC5947) && (AMIROLLD_CFG_TLC5947 == 1) */ |