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