Skip to content

Commit

Permalink
per pixel led self test base
Browse files Browse the repository at this point in the history
  • Loading branch information
openshwprojects committed Apr 28, 2024
1 parent ef2ef4a commit 7798e70
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/driver/drv_sm16703P.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,37 @@ void SM16703P_setRaw(int start_offset, const char *s, int push) {
}
}

bool SM16703P_VerifyPixel(uint32_t pixel, byte r, byte g, byte b) {
uint8_t *dst = spi_msg->send_buf + pixel_offset + (pixel * 3 * 4);

if (*dst++ != translate_2bit((r >> 6)))
return false;
if (*dst++ != translate_2bit((r >> 4)))
return false;
if (*dst++ != translate_2bit((r >> 2)))
return false;
if (*dst++ != translate_2bit(r))
return false;
if (*dst++ != translate_2bit((g >> 6)))
return false;
if (*dst++ != translate_2bit((g >> 4)))
return false;
if (*dst++ != translate_2bit((g >> 2)))
return false;
if (*dst++ != translate_2bit(g))
return false;
if (*dst++ != translate_2bit((b >> 6)))
return false;
if (*dst++ != translate_2bit((b >> 4)))
return false;
if (*dst++ != translate_2bit((b >> 2)))
return false;
if (*dst++ != translate_2bit(b))
return false;

return true;
}


void SM16703P_setMultiplePixel(uint32_t pixel, uint8_t *data, bool push) {

Expand Down
26 changes: 26 additions & 0 deletions src/selftest/selftest_ws2812b.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
#ifdef WINDOWS

#include "selftest_local.h"


bool SM16703P_VerifyPixel(uint32_t pixel, byte r, byte g, byte b);

#define SELFTEST_ASSERT_PIXEL(index, r, g, b) SELFTEST_ASSERT(SM16703P_VerifyPixel(index, r, g, b));

void Test_WS2812B() {
// reset whole device
SIM_ClearOBK(0);

CMD_ExecuteCommand("startDriver SM16703P", 0);
CMD_ExecuteCommand("SM16703P_Init 3", 0);
CMD_ExecuteCommand("SM16703P_SetPixel all 255 0 128", 0);
SELFTEST_ASSERT_PIXEL(0, 255, 0, 128);
SELFTEST_ASSERT_PIXEL(1, 255, 0, 128);
SELFTEST_ASSERT_PIXEL(2, 255, 0, 128);
CMD_ExecuteCommand("SM16703P_SetPixel 1 22 33 44", 0);
SELFTEST_ASSERT_PIXEL(0, 255, 0, 128);
SELFTEST_ASSERT_PIXEL(1, 22, 33, 44);
SELFTEST_ASSERT_PIXEL(2, 255, 0, 128);
// channel as pixel
CMD_ExecuteCommand("SetChannel 5 124", 0);
CMD_ExecuteCommand("SM16703P_SetPixel 1 $CH5 33 44", 0);
SELFTEST_ASSERT_PIXEL(1, 124, 33, 44);
// math expression
CMD_ExecuteCommand("SetChannel 5 124", 0);
CMD_ExecuteCommand("SM16703P_SetPixel 1 2*$CH5 33 44", 0);
SELFTEST_ASSERT_PIXEL(1, 2 * 124, 33, 44);
// math expression e2
CMD_ExecuteCommand("SetChannel 5 124", 0);
CMD_ExecuteCommand("SM16703P_SetPixel 1 10+$CH5 2*33+10 44/4", 0);
SELFTEST_ASSERT_PIXEL(1, 10+ 124, 2 * 33+10, 44/4);

}

Expand Down

0 comments on commit 7798e70

Please sign in to comment.