commence breakage
[inav.git] / src / test / unit / ws2811_unittest.cc.txt
blob8b6b256d634f13f9a6a8d2949ce1b84d84cfeec0
1 /*
2  * This file is part of Cleanflight.
3  *
4  * Cleanflight is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Cleanflight is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Cleanflight.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 #include <stdint.h>
18 #include <stdlib.h>
20 #include <limits.h>
22 extern "C" {
23     #include "build_config.h"
25     #include "common/color.h"
27     #include "drivers/light_ws2811strip.h"
30 #include "unittest_macros.h"
31 #include "gtest/gtest.h"
33 extern "C" {
34 STATIC_UNIT_TESTED extern uint16_t dmaBufferOffset;
36 STATIC_UNIT_TESTED void fastUpdateLEDDMABuffer(rgbColor24bpp_t *color);
37 STATIC_UNIT_TESTED void updateLEDDMABuffer(uint8_t componentValue);
40 TEST(WS2812, updateDMABuffer) {
41     // given
42     rgbColor24bpp_t color1 = { .raw = {0xFF,0xAA,0x55} };
44     // and
45     dmaBufferOffset = 0;
47     // when
48     fastUpdateLEDDMABuffer(&color1);
50     // then
51     EXPECT_EQ(24, dmaBufferOffset);
53     // and
54     uint8_t byteIndex = 0;
56     EXPECT_EQ(BIT_COMPARE_1, ledStripDMABuffer[(byteIndex * 8) + 0]);
57     EXPECT_EQ(BIT_COMPARE_0, ledStripDMABuffer[(byteIndex * 8) + 1]);
58     EXPECT_EQ(BIT_COMPARE_1, ledStripDMABuffer[(byteIndex * 8) + 2]);
59     EXPECT_EQ(BIT_COMPARE_0, ledStripDMABuffer[(byteIndex * 8) + 3]);
60     EXPECT_EQ(BIT_COMPARE_1, ledStripDMABuffer[(byteIndex * 8) + 4]);
61     EXPECT_EQ(BIT_COMPARE_0, ledStripDMABuffer[(byteIndex * 8) + 5]);
62     EXPECT_EQ(BIT_COMPARE_1, ledStripDMABuffer[(byteIndex * 8) + 6]);
63     EXPECT_EQ(BIT_COMPARE_0, ledStripDMABuffer[(byteIndex * 8) + 7]);
64     byteIndex++;
66     EXPECT_EQ(BIT_COMPARE_1, ledStripDMABuffer[(byteIndex * 8) + 0]);
67     EXPECT_EQ(BIT_COMPARE_1, ledStripDMABuffer[(byteIndex * 8) + 1]);
68     EXPECT_EQ(BIT_COMPARE_1, ledStripDMABuffer[(byteIndex * 8) + 2]);
69     EXPECT_EQ(BIT_COMPARE_1, ledStripDMABuffer[(byteIndex * 8) + 3]);
70     EXPECT_EQ(BIT_COMPARE_1, ledStripDMABuffer[(byteIndex * 8) + 4]);
71     EXPECT_EQ(BIT_COMPARE_1, ledStripDMABuffer[(byteIndex * 8) + 5]);
72     EXPECT_EQ(BIT_COMPARE_1, ledStripDMABuffer[(byteIndex * 8) + 6]);
73     EXPECT_EQ(BIT_COMPARE_1, ledStripDMABuffer[(byteIndex * 8) + 7]);
74     byteIndex++;
76     EXPECT_EQ(BIT_COMPARE_0, ledStripDMABuffer[(byteIndex * 8) + 0]);
77     EXPECT_EQ(BIT_COMPARE_1, ledStripDMABuffer[(byteIndex * 8) + 1]);
78     EXPECT_EQ(BIT_COMPARE_0, ledStripDMABuffer[(byteIndex * 8) + 2]);
79     EXPECT_EQ(BIT_COMPARE_1, ledStripDMABuffer[(byteIndex * 8) + 3]);
80     EXPECT_EQ(BIT_COMPARE_0, ledStripDMABuffer[(byteIndex * 8) + 4]);
81     EXPECT_EQ(BIT_COMPARE_1, ledStripDMABuffer[(byteIndex * 8) + 5]);
82     EXPECT_EQ(BIT_COMPARE_0, ledStripDMABuffer[(byteIndex * 8) + 6]);
83     EXPECT_EQ(BIT_COMPARE_1, ledStripDMABuffer[(byteIndex * 8) + 7]);
84     byteIndex++;
87 extern "C" {
88 rgbColor24bpp_t* hsvToRgb24(const hsvColor_t *c) {
89     UNUSED(c);
90     return NULL;
93 void ws2811LedStripHardwareInit(void) {}
94 void ws2811LedStripDMAEnable(void) {}
96 void dmaSetHandler(dmaHandlerIdentifier_e, dmaCallbackHandlerFuncPtr ) {}
98 uint8_t DMA_GetFlagStatus(uint32_t) { return 0; }
99 void DMA_Cmd(DMA_Channel_TypeDef*, FunctionalState ) {}
100 void DMA_ClearFlag(uint32_t) {}