Statistics
| Branch: | Tag: | Revision:

amiro-os / unittests / periphery-lld / src / ut_alld_tlc5947.c @ 8a93b752

History | View | Annotate | Download (8.119 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 <ut_alld_tlc5947.h>
20

    
21
#if ((AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_TLC5947)) || defined(__DOXYGEN__)
22

    
23
#include <string.h>
24

    
25
/******************************************************************************/
26
/* LOCAL DEFINITIONS                                                          */
27
/******************************************************************************/
28

    
29
/******************************************************************************/
30
/* EXPORTED VARIABLES                                                         */
31
/******************************************************************************/
32

    
33
/******************************************************************************/
34
/* LOCAL TYPES                                                                */
35
/******************************************************************************/
36

    
37
/******************************************************************************/
38
/* LOCAL VARIABLES                                                            */
39
/******************************************************************************/
40

    
41
/******************************************************************************/
42
/* LOCAL FUNCTIONS                                                            */
43
/******************************************************************************/
44

    
45
/******************************************************************************/
46
/* EXPORTED FUNCTIONS                                                         */
47
/******************************************************************************/
48

    
49
/**
50
 * @brief   TLC9547 unit test function
51
 *
52
 * @param[in] stream  Stream for input/output.
53
 * @param[in] ut      Unit test object.
54
 *
55
 * @return            Unit test result value.
56
 */
57
aos_utresult_t utAlldTlc5947Func(BaseSequentialStream *stream, aos_unittest_t *ut)
58
{
59
  aosDbgCheck(ut->data != NULL);
60

    
61
  // local variables
62
  aos_utresult_t result = {0, 0};
63
  uint32_t status = 0;
64
  tlc5947_lld_blank_t blank;
65
  tlc5947_lld_buffer_t buffer;
66

    
67
  chprintf(stream, "reading blank pin...\n");
68
  status = tlc5947_lld_getBlank((TLC5947Driver*)ut->data, &blank);
69
  if (status == APAL_STATUS_OK) {
70
    aosUtPassedMsg(stream, &result, "blank is %s\n", (blank == TLC5947_LLD_BLANK_ENABLE) ? "enabled" : "disabled");
71
  } else {
72
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
73
  }
74

    
75
  // enabling/disabling blank pin
76
  for (uint8_t i = 0; i < 2; ++i) {
77
    blank = (blank == TLC5947_LLD_BLANK_ENABLE) ? TLC5947_LLD_BLANK_DISABLE : TLC5947_LLD_BLANK_ENABLE;
78
    tlc5947_lld_blank_t blank_after = (blank == TLC5947_LLD_BLANK_ENABLE) ? TLC5947_LLD_BLANK_DISABLE : TLC5947_LLD_BLANK_ENABLE;
79
    chprintf(stream, "%s blank pin...\n", (blank == TLC5947_LLD_BLANK_ENABLE) ? "enabling" : "disabling");
80
    status = tlc5947_lld_setBlank((TLC5947Driver*)ut->data, blank);
81
    status |= tlc5947_lld_getBlank((TLC5947Driver*)ut->data, &blank_after);
82
    if (status == APAL_STATUS_OK && blank_after == blank) {
83
      aosUtPassed(stream, &result);
84
    } else {
85
      aosUtFailedMsg(stream, &result, "0x%08X\n", status);
86
    }
87
  }
88

    
89
  chprintf(stream, "setting all black and dimming white...\n");
90
  status = tlc5947_lld_setBlank((TLC5947Driver*)ut->data, TLC5947_LLD_BLANK_ENABLE);
91
  memset(buffer.data, 0, TLC5947_LLD_BUFFER_SIZE);
92
  status |= tlc5947_lld_write((TLC5947Driver*)ut->data, &buffer);
93
  status |= tlc5947_lld_update((TLC5947Driver*)ut->data);
94
  status |= tlc5947_lld_setBlank((TLC5947Driver*)ut->data, TLC5947_LLD_BLANK_DISABLE);
95
  for (uint8_t bit = 0; bit < TLC5947_LLD_PWM_RESOLUTION_BITS; ++bit) {
96
    for (uint8_t channel = 0; channel < TLC5947_LLD_NUM_CHANNELS; ++channel) {
97
      tlc5947_lld_setBuffer(&buffer, channel, (1 << (bit+1)) - 1);
98
    }
99
    status |= tlc5947_lld_write((TLC5947Driver*)ut->data, &buffer);
100
    status |= tlc5947_lld_update((TLC5947Driver*)ut->data);
101
    aosThdMSleep(100);
102
  }
103
  if (status == APAL_STATUS_OK) {
104
    aosUtPassed(stream, &result);
105
  } else {
106
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
107
  }
108

    
109
  chprintf(stream, "NOT dimming black again...\n");
110
  status = APAL_STATUS_OK;
111
  for (uint8_t bit = TLC5947_LLD_PWM_RESOLUTION_BITS; bit > 0; --bit) {
112
    for (uint8_t channel = 0; channel < TLC5947_LLD_NUM_CHANNELS; ++channel) {
113
      tlc5947_lld_setBuffer(&buffer, channel, (1 << bit) - 1);
114
    }
115
    status |= tlc5947_lld_setBlank((TLC5947Driver*)ut->data, TLC5947_LLD_BLANK_ENABLE);
116
    status |= tlc5947_lld_write((TLC5947Driver*)ut->data, &buffer);
117
    status |= tlc5947_lld_setBlank((TLC5947Driver*)ut->data, TLC5947_LLD_BLANK_ENABLE);
118
    // Grayscale data is not updated this time (tlc5947_lld_update() not called).
119
    // TODO: For some reason the PWMs are updated nevertheless.
120
    aosThdMSleep(100);
121
  }
122
  status |= tlc5947_lld_setBlank((TLC5947Driver*)ut->data, TLC5947_LLD_BLANK_ENABLE);
123
  if (status == APAL_STATUS_OK) {
124
    aosUtPassed(stream, &result);
125
  } else {
126
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
127
  }
128

    
129
  chprintf(stream, "setting each channel incrementally...\n");
130
  status = APAL_STATUS_OK;
131
  memset(buffer.data, 0, TLC5947_LLD_BUFFER_SIZE);
132
  status |= tlc5947_lld_write((TLC5947Driver*)ut->data, &buffer);
133
  status |= tlc5947_lld_update((TLC5947Driver*)ut->data);
134
  status |= tlc5947_lld_setBlank((TLC5947Driver*)ut->data, TLC5947_LLD_BLANK_DISABLE);
135
  for (uint8_t channel = 0; channel < TLC5947_LLD_NUM_CHANNELS; ++channel) {
136
    uint16_t value = 0x0000u;
137
    for (uint8_t byte = 0; byte < 3; ++byte) {
138
      switch (byte) {
139
        case 0:
140
          value |= 0x00Fu;
141
          break;
142
        case 1:
143
          value |= 0x0F0u;
144
          break;
145
        case 2:
146
          value |= 0xF00u;
147
          break;
148
      }
149
      tlc5947_lld_setBuffer(&buffer, channel, value);
150
      status |= tlc5947_lld_write((TLC5947Driver*)ut->data, &buffer);
151
      status |= tlc5947_lld_update((TLC5947Driver*)ut->data);
152
      aosThdSleep(1.0f / 3.0f);
153
      tlc5947_lld_setBuffer(&buffer, channel, 0);
154
    }
155
  }
156
  if (status == APAL_STATUS_OK) {
157
    aosUtPassed(stream, &result);
158
  } else {
159
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
160
  }
161

    
162
  chprintf(stream, "setting one color after another...\n");
163
  status = APAL_STATUS_OK;
164
  for (int8_t color = 0; color < 3; ++color) {
165
    for (uint8_t channel = color; channel < TLC5947_LLD_NUM_CHANNELS; channel += 3) {
166
      const uint16_t val = 0xAF5u; // some deterministic value with high entropy
167
      tlc5947_lld_setBuffer(&buffer, channel, val);
168
      status |= tlc5947_lld_write((TLC5947Driver*)ut->data, &buffer);
169
      status |= tlc5947_lld_update((TLC5947Driver*)ut->data);
170
      status |= (tlc5947_lld_getBuffer(&buffer, channel) != val) ? (1 << 31) : 0;
171
      if (status != APAL_STATUS_OK) {
172
        break;
173
      } else {
174
        aosThdSleep(1.0f / 8.0f);
175
      }
176
    }
177
    for (uint8_t channel = 0; channel < TLC5947_LLD_NUM_CHANNELS; ++channel) {
178
      tlc5947_lld_setBuffer(&buffer, channel, 0);
179
    }
180
  }
181
  if (status == APAL_STATUS_OK) {
182
    aosUtPassed(stream, &result);
183
  } else {
184
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
185
  }
186

    
187
  // turn LEDs off
188
  tlc5947_lld_setBlank((TLC5947Driver*)ut->data, TLC5947_LLD_BLANK_ENABLE);
189
  memset(buffer.data, 0, TLC5947_LLD_BUFFER_SIZE);
190
  tlc5947_lld_write((TLC5947Driver*)ut->data, &buffer);
191
  tlc5947_lld_update((TLC5947Driver*)ut->data);
192

    
193
  aosUtInfoMsg(stream, "driver object memory footprint: %u bytes\n", sizeof(TLC5947Driver));
194

    
195
  return result;
196
}
197

    
198
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_TLC5947) */