Statistics
| Branch: | Tag: | Revision:

amiro-os / unittests / periphery-lld / src / ut_alld_tlc5947.c @ 2e69d671

History | View | Annotate | Download (6.78 KB)

1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2018  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 <aos_debug.h>
24
#include <chprintf.h>
25
#include <alld_tlc5947.h>
26
#include <string.h>
27
#include <aos_thread.h>
28

    
29
/**
30
 * @brief   TLC9547 unit test function
31
 *
32
 * @param[in] stream  Stream for input/output.
33
 * @param[in] ut      Unit test object.
34
 *
35
 * @return            Unit test result value.
36
 */
37
aos_utresult_t utAlldTlc5947Func(BaseSequentialStream *stream, aos_unittest_t *ut)
38
{
39
  aosDbgCheck(ut->data != NULL);
40

    
41
  // local variables
42
  aos_utresult_t result = {0, 0};
43
  uint32_t status = 0;
44
  tlc5947_lld_blank_t blank;
45
  tlc5947_lld_buffer_t buffer;
46

    
47
  chprintf(stream, "reading blank pin...\n");
48
  status = tlc5947_lld_getBlank((TLC5947Driver*)ut->data, &blank);
49
  if (status == APAL_STATUS_OK) {
50
    aosUtPassedMsg(stream, &result, "blank is %s\n", (blank == TLC5947_LLD_BLANK_ENABLE) ? "enabled" : "disabled");
51
  } else {
52
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
53
  }
54

    
55
  // enabling/disabling blank pin
56
  for (uint8_t i = 0; i < 2; ++i) {
57
    blank = (blank == TLC5947_LLD_BLANK_ENABLE) ? TLC5947_LLD_BLANK_DISABLE : TLC5947_LLD_BLANK_ENABLE;
58
    tlc5947_lld_blank_t blank_after = (blank == TLC5947_LLD_BLANK_ENABLE) ? TLC5947_LLD_BLANK_DISABLE : TLC5947_LLD_BLANK_ENABLE;
59
    chprintf(stream, "%s blank pin...\n", (blank == TLC5947_LLD_BLANK_ENABLE) ? "enabling" : "disabling");
60
    status = tlc5947_lld_setBlank((TLC5947Driver*)ut->data, blank);
61
    status |= tlc5947_lld_getBlank((TLC5947Driver*)ut->data, &blank_after);
62
    if (status == APAL_STATUS_OK && blank_after == blank) {
63
      aosUtPassed(stream, &result);
64
    } else {
65
      aosUtFailedMsg(stream, &result, "0x%08X\n", status);
66
    }
67
  }
68

    
69
  chprintf(stream, "setting all black and dimming white...\n");
70
  status = tlc5947_lld_setBlank((TLC5947Driver*)ut->data, TLC5947_LLD_BLANK_ENABLE);
71
  memset(buffer.data, 0, TLC5947_LLD_BUFFER_SIZE);
72
  status |= tlc5947_lld_write((TLC5947Driver*)ut->data, &buffer);
73
  status |= tlc5947_lld_update((TLC5947Driver*)ut->data);
74
  status |= tlc5947_lld_setBlank((TLC5947Driver*)ut->data, TLC5947_LLD_BLANK_DISABLE);
75
  for (uint8_t bit = 0; bit < TLC5947_LLD_PWM_RESOLUTION_BITS; ++bit) {
76
    for (uint8_t channel = 0; channel < TLC5947_LLD_NUM_CHANNELS; ++channel) {
77
      tlc5947_lld_setBuffer(&buffer, channel, (1 << (bit+1)) - 1);
78
    }
79
    status |= tlc5947_lld_write((TLC5947Driver*)ut->data, &buffer);
80
    status |= tlc5947_lld_update((TLC5947Driver*)ut->data);
81
    aosThdMSleep(100);
82
  }
83
  if (status == APAL_STATUS_OK) {
84
    aosUtPassed(stream, &result);
85
  } else {
86
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
87
  }
88

    
89
  chprintf(stream, "NOT dimming black again...\n");
90
  status = APAL_STATUS_OK;
91
  for (uint8_t bit = TLC5947_LLD_PWM_RESOLUTION_BITS; bit > 0; --bit) {
92
    for (uint8_t channel = 0; channel < TLC5947_LLD_NUM_CHANNELS; ++channel) {
93
      tlc5947_lld_setBuffer(&buffer, channel, (1 << bit) - 1);
94
    }
95
    status |= tlc5947_lld_setBlank((TLC5947Driver*)ut->data, TLC5947_LLD_BLANK_ENABLE);
96
    status |= tlc5947_lld_write((TLC5947Driver*)ut->data, &buffer);
97
    status |= tlc5947_lld_setBlank((TLC5947Driver*)ut->data, TLC5947_LLD_BLANK_ENABLE);
98
    // Grayscale data is not updated this time (tlc5947_lld_update() not called).
99
    // TODO: For some reason the PWMs are updated nevertheless.
100
    aosThdMSleep(100);
101
  }
102
  status |= tlc5947_lld_setBlank((TLC5947Driver*)ut->data, TLC5947_LLD_BLANK_ENABLE);
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, "setting each channel incrementally...\n");
110
  status = APAL_STATUS_OK;
111
  memset(buffer.data, 0, TLC5947_LLD_BUFFER_SIZE);
112
  status |= tlc5947_lld_write((TLC5947Driver*)ut->data, &buffer);
113
  status |= tlc5947_lld_update((TLC5947Driver*)ut->data);
114
  status |= tlc5947_lld_setBlank((TLC5947Driver*)ut->data, TLC5947_LLD_BLANK_DISABLE);
115
  for (uint8_t channel = 0; channel < TLC5947_LLD_NUM_CHANNELS; ++channel) {
116
    uint16_t value = 0x0000u;
117
    for (uint8_t byte = 0; byte < 3; ++byte) {
118
      switch (byte) {
119
        case 0:
120
          value |= 0x00Fu;
121
          break;
122
        case 1:
123
          value |= 0x0F0u;
124
          break;
125
        case 2:
126
          value |= 0xF00u;
127
          break;
128
      }
129
      tlc5947_lld_setBuffer(&buffer, channel, value);
130
      status |= tlc5947_lld_write((TLC5947Driver*)ut->data, &buffer);
131
      status |= tlc5947_lld_update((TLC5947Driver*)ut->data);
132
      aosThdSleep(1.0f / 3.0f);
133
      tlc5947_lld_setBuffer(&buffer, channel, 0);
134
    }
135
  }
136
  if (status == APAL_STATUS_OK) {
137
    aosUtPassed(stream, &result);
138
  } else {
139
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
140
  }
141

    
142
  chprintf(stream, "setting one color after another...\n");
143
  status = APAL_STATUS_OK;
144
  for (int8_t color = 0; color < 3; ++color) {
145
    for (uint8_t channel = color; channel < TLC5947_LLD_NUM_CHANNELS; channel += 3) {
146
      const uint16_t val = 0xAF5u; // some deterministic value with high entropy
147
      tlc5947_lld_setBuffer(&buffer, channel, val);
148
      status |= tlc5947_lld_write((TLC5947Driver*)ut->data, &buffer);
149
      status |= tlc5947_lld_update((TLC5947Driver*)ut->data);
150
      status |= (tlc5947_lld_getBuffer(&buffer, channel) != val) ? (1 << 31) : 0;
151
      if (status != APAL_STATUS_OK) {
152
        break;
153
      } else {
154
        aosThdSleep(1.0f / 8.0f);
155
      }
156
    }
157
    for (uint8_t channel = 0; channel < TLC5947_LLD_NUM_CHANNELS; ++channel) {
158
      tlc5947_lld_setBuffer(&buffer, channel, 0);
159
    }
160
  }
161
  if (status == APAL_STATUS_OK) {
162
    aosUtPassed(stream, &result);
163
  } else {
164
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
165
  }
166

    
167
  // turn LEDs off
168
  tlc5947_lld_setBlank((TLC5947Driver*)ut->data, TLC5947_LLD_BLANK_ENABLE);
169
  memset(buffer.data, 0, TLC5947_LLD_BUFFER_SIZE);
170
  tlc5947_lld_write((TLC5947Driver*)ut->data, &buffer);
171
  tlc5947_lld_update((TLC5947Driver*)ut->data);
172

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

    
175
  return result;
176
}
177

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