Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvught committed Sep 21, 2024
1 parent 7f9e8be commit 46f6462
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 120 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,4 @@ software_version_id.h
/lib-nextion
/lib-node
/lib-showfile/Doxygen
/opi_emac_eve_example
4 changes: 2 additions & 2 deletions lib-dmx/include/gd32/dmx.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ class Dmx {
}

private:
void StartData(const uint32_t nUart, const uint32_t nPortIndex);
void StopData(const uint32_t nUart, const uint32_t nPortIndex);
void StartData(const uint32_t nPortIndex);
void StopData(const uint32_t nPortIndex);
void StartDmxOutput(const uint32_t nPortIndex);

private:
Expand Down
8 changes: 4 additions & 4 deletions lib-flash/src/spi/spi_flash_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ struct spi_flash {
extern int spi_init();
extern int spi_xfer(uint32_t bitlen, const uint8_t *dout, uint8_t *din, uint32_t flags);

#define CONFIG_SPI_FLASH_MACRONIX
int spi_flash_probe_macronix(struct spi_flash *flash, uint8_t *idcode);
//#define CONFIG_SPI_FLASH_MACRONIX
//int spi_flash_probe_macronix(struct spi_flash *flash, uint8_t *idcode);

#define CONFIG_SPI_FLASH_WINBOND
extern int spi_flash_probe_winbond(struct spi_flash *spi, uint8_t *idcode);

#define CONFIG_SPI_FLASH_GIGADEVICE
extern int spi_flash_probe_gigadevice(struct spi_flash *spi, uint8_t *idcode);
//#define CONFIG_SPI_FLASH_GIGADEVICE
//extern int spi_flash_probe_gigadevice(struct spi_flash *spi, uint8_t *idcode);

#endif /* SPI_FLASH_INTERNAL_H_ */
13 changes: 8 additions & 5 deletions lib-network/src/params/networkparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,13 @@ void NetworkParams::callbackFunction(const char *pLine) {
}

if (Sscan::IpAddress(pLine, NetworkParamsConst::DEFAULT_GATEWAY, nValue32) == Sscan::OK) {
m_Params.nGatewayIp = nValue32;
m_Params.nSetList |= networkparams::Mask::DEFAULT_GATEWAY;
if (nValue32 != 0) {
m_Params.nSetList |= networkparams::Mask::DEFAULT_GATEWAY;
m_Params.nGatewayIp = nValue32;
} else {
m_Params.nSetList &= ~networkparams::Mask::DEFAULT_GATEWAY;
}

return;
}

Expand Down Expand Up @@ -251,14 +256,12 @@ void NetworkParams::Builder(const struct networkparams::Params *ptNetworkParams,
void NetworkParams::Dump() {
printf("%s::%s \'%s\':\n", __FILE__, __FUNCTION__, NetworkParamsConst::FILE_NAME);

debug_print_bits(m_Params.nSetList);

printf(" %s=%d [%s]\n", NetworkParamsConst::USE_DHCP, static_cast<int>(m_Params.bIsDhcpUsed), m_Params.bIsDhcpUsed != 0 ? "Yes" : "No");
printf(" %s=" IPSTR "\n", NetworkParamsConst::IP_ADDRESS, IP2STR(m_Params.nLocalIp));
printf(" %s=" IPSTR "\n", NetworkParamsConst::NET_MASK, IP2STR(m_Params.nNetmask));
printf(" %s=" IPSTR "\n", NetworkParamsConst::DEFAULT_GATEWAY, IP2STR(m_Params.nGatewayIp));

#if defined (ESP8266)
printf(" %s=" IPSTR "\n", NetworkParamsConst::DEFAULT_GATEWAY, IP2STR(m_Params.nGatewayIp));
printf(" %s=" IPSTR "\n", NetworkParamsConst::NAME_SERVER, IP2STR(m_Params.nNameServerIp));
#endif

Expand Down
2 changes: 1 addition & 1 deletion lib-remoteconfig/include/remoteconfigparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file remoteconfigparams.h
*
*/
/* Copyright (C) 2019-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl
/* Copyright (C) 2019-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
83 changes: 43 additions & 40 deletions lib-remoteconfig/src/remoteconfigparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file remoteconfigparams.cpp
*
*/
/* Copyright (C) 2019-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl
/* Copyright (C) 2019-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -37,13 +37,26 @@
#include "remoteconfig.h"
#include "remoteconfigconst.h"


#include "readconfigfile.h"
#include "sscan.h"
#include "propertiesbuilder.h"

#include "debug.h"

struct ParamMask {
const char *pParam;
uint32_t nMask;
};

// Array of structs: parameter and corresponding mask
constexpr ParamMask paramMasks[] = {
{ RemoteConfigConst::PARAMS_DISABLE, remoteconfigparams::Mask::DISABLE },
{ RemoteConfigConst::PARAMS_DISABLE_WRITE, remoteconfigparams::Mask::DISABLE_WRITE },
{ RemoteConfigConst::PARAMS_ENABLE_REBOOT, remoteconfigparams::Mask::ENABLE_REBOOT },
{ RemoteConfigConst::PARAMS_ENABLE_UPTIME, remoteconfigparams::Mask::ENABLE_UPTIME },
{ RemoteConfigConst::PARAMS_ENABLE_FACTORY, remoteconfigparams::Mask::ENABLE_FACTORY },
};

RemoteConfigParams::RemoteConfigParams() {
DEBUG_ENTRY

Expand Down Expand Up @@ -72,7 +85,7 @@ void RemoteConfigParams::Load() {
DEBUG_EXIT
}

void RemoteConfigParams::Load(const char* pBuffer, uint32_t nLength) {
void RemoteConfigParams::Load(const char *pBuffer, uint32_t nLength) {
DEBUG_ENTRY

assert(pBuffer != nullptr);
Expand Down Expand Up @@ -103,34 +116,25 @@ void RemoteConfigParams::SetBool(const uint8_t nValue, const uint32_t nMask) {
void RemoteConfigParams::callbackFunction(const char *pLine) {
assert(pLine != nullptr);

uint8_t nValue8;

if (Sscan::Uint8(pLine, RemoteConfigConst::PARAMS_DISABLE, nValue8) == Sscan::OK) {
SetBool(nValue8, remoteconfigparams::Mask::DISABLE);
return;
}

if (Sscan::Uint8(pLine, RemoteConfigConst::PARAMS_DISABLE_WRITE, nValue8) == Sscan::OK) {
SetBool(nValue8, remoteconfigparams::Mask::DISABLE_WRITE);
return;
}

if (Sscan::Uint8(pLine, RemoteConfigConst::PARAMS_ENABLE_REBOOT, nValue8) == Sscan::OK) {
SetBool(nValue8, remoteconfigparams::Mask::ENABLE_REBOOT);
return;
}

if (Sscan::Uint8(pLine, RemoteConfigConst::PARAMS_ENABLE_UPTIME, nValue8) == Sscan::OK) {
SetBool(nValue8, remoteconfigparams::Mask::ENABLE_UPTIME);
return;
}

if (Sscan::Uint8(pLine, RemoteConfigConst::PARAMS_ENABLE_FACTORY, nValue8) == Sscan::OK) {
SetBool(nValue8, remoteconfigparams::Mask::ENABLE_FACTORY);
return;
}
// Helper lambda for setting masks
auto trySetMask = [&](const char* param, const uint32_t mask) {
uint8_t nValue8;
if (Sscan::Uint8(pLine, param, nValue8) == Sscan::OK) {
SetBool(nValue8, mask);
return true;
}
return false;
};

// Loop through parameters and masks
for (const auto& paramMask : paramMasks) {
if (trySetMask(paramMask.pParam, paramMask.nMask)) {
return;
}
}

uint32_t nLength = remoteconfig::DISPLAY_NAME_LENGTH - 1;

if (Sscan::Char(pLine, RemoteConfigConst::PARAMS_DISPLAY_NAME, m_Params.aDisplayName, nLength) == Sscan::OK) {
m_Params.aDisplayName[nLength] = '\0';
m_Params.nSetList |= remoteconfigparams::Mask::DISPLAY_NAME;
Expand All @@ -151,11 +155,10 @@ void RemoteConfigParams::Builder(const struct remoteconfigparams::Params *pRemot

PropertiesBuilder builder(RemoteConfigConst::PARAMS_FILE_NAME, pBuffer, nLength);

builder.Add(RemoteConfigConst::PARAMS_DISABLE, isMaskSet(remoteconfigparams::Mask::DISABLE));
builder.Add(RemoteConfigConst::PARAMS_DISABLE_WRITE, isMaskSet(remoteconfigparams::Mask::DISABLE_WRITE));
builder.Add(RemoteConfigConst::PARAMS_ENABLE_REBOOT, isMaskSet(remoteconfigparams::Mask::ENABLE_REBOOT));
builder.Add(RemoteConfigConst::PARAMS_ENABLE_UPTIME, isMaskSet(remoteconfigparams::Mask::ENABLE_UPTIME));
builder.Add(RemoteConfigConst::PARAMS_ENABLE_FACTORY, isMaskSet(remoteconfigparams::Mask::ENABLE_FACTORY));
// Loop through parameters and masks for building properties
for (const auto& paramMask : paramMasks) {
builder.Add(paramMask.pParam, isMaskSet(paramMask.nMask));
}

builder.Add(RemoteConfigConst::PARAMS_DISPLAY_NAME, m_Params.aDisplayName, isMaskSet(remoteconfigparams::Mask::DISPLAY_NAME));

Expand All @@ -165,7 +168,7 @@ void RemoteConfigParams::Builder(const struct remoteconfigparams::Params *pRemot
return;
}

void RemoteConfigParams::Set(RemoteConfig* pRemoteConfig) {
void RemoteConfigParams::Set(RemoteConfig *pRemoteConfig) {
assert(pRemoteConfig != nullptr);

pRemoteConfig->SetDisable(isMaskSet(remoteconfigparams::Mask::DISABLE));
Expand All @@ -188,10 +191,10 @@ void RemoteConfigParams::staticCallbackFunction(void *p, const char *s) {

void RemoteConfigParams::Dump() {
printf("%s::%s \'%s\':\n", __FILE__, __FUNCTION__, RemoteConfigConst::PARAMS_FILE_NAME);
printf(" %s=%d\n", RemoteConfigConst::PARAMS_DISABLE, isMaskSet(remoteconfigparams::Mask::DISABLE));
printf(" %s=%d\n", RemoteConfigConst::PARAMS_DISABLE_WRITE, isMaskSet(remoteconfigparams::Mask::DISABLE_WRITE));
printf(" %s=%d\n", RemoteConfigConst::PARAMS_ENABLE_REBOOT, isMaskSet(remoteconfigparams::Mask::ENABLE_REBOOT));
printf(" %s=%d\n", RemoteConfigConst::PARAMS_ENABLE_UPTIME, isMaskSet(remoteconfigparams::Mask::ENABLE_UPTIME));
printf(" %s=%d\n", RemoteConfigConst::PARAMS_ENABLE_FACTORY, isMaskSet(remoteconfigparams::Mask::ENABLE_FACTORY));

for (const auto& paramMask : paramMasks) {
printf(" %s=%d\n", paramMask.pParam, isMaskSet(paramMask.nMask));
}

printf(" %s=%s\n", RemoteConfigConst::PARAMS_DISPLAY_NAME, m_Params.aDisplayName);
}
2 changes: 1 addition & 1 deletion lib-showfile/Rules.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$(info [${CURDIR}])
$(info $$MAKE_FLAGS [${MAKE_FLAGS}])

EXTRA_INCLUDES+=../lib-properties/include ../lib-network/include
EXTRA_INCLUDES+=../lib-properties/include ../lib-lightset/include ../lib-network/include

ifneq ($(MAKE_FLAGS),)
ifeq (,$(findstring CONFIG_SHOWFILE_USE_CUSTOM_DISPLAY,$(MAKE_FLAGS)))
Expand Down
113 changes: 46 additions & 67 deletions lib-ws28xxdmx/src/dmxmulti/ws28xxdmxmulti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,96 +126,75 @@ void WS28xxDmxMulti::SetData(const uint32_t nPortIndex, const uint8_t* pData, ui

if (nChannelsPerPixel == 3) {
// Define a lambda to handle pixel setting based on color order
auto setPixelsColor3 = [&](const uint32_t nPortIndex, const uint32_t nPixelIndex, const uint32_t r, const uint32_t g, const uint32_t b) {
auto setPixelsColourRTZ = [&](const uint32_t nPortIndex, const uint32_t nPixelIndex, const uint32_t r, const uint32_t g, const uint32_t b) {
#if defined(CONFIG_PIXELDMX_ENABLE_GAMMATABLE)
const auto pGammaTable = m_pWS28xxMulti->m_PixelConfiguration.GetGammaTable();
r = pGammaTable[r];
g = pGammaTable[g];
b = pGammaTable[b];
#endif
if (isRTZProtocol) {
m_pWS28xxMulti->SetColourRTZ(nPortIndex, nPixelIndex, r, g, b);
} else {
switch (pixelType) {
case pixel::Type::WS2801:
m_pWS28xxMulti->SetColourWS2801(nPortIndex, nPixelIndex, r, g, b);
break;
case pixel::Type::APA102:
case pixel::Type::SK9822:
m_pWS28xxMulti->SetPixel4Bytes(nPortIndex, 1 + nPixelIndex, pixelDmxConfiguration.GetGlobalBrightness(), b, g, r);
break;
case pixel::Type::P9813: {
const auto nFlag = static_cast<uint8_t>(0xC0 | ((~b & 0xC0) >> 2) | ((~r & 0xC0) >> 4) | ((~r & 0xC0) >> 6));
m_pWS28xxMulti->SetPixel4Bytes(nPortIndex, 1 + nPixelIndex, nFlag, b, g, r);
}
break;
default:
assert(0);
__builtin_unreachable();
break;
}
}
m_pWS28xxMulti->SetColourRTZ(nPortIndex, nPixelIndex, r, g, b);
};

switch (pixelDmxConfiguration.GetMap()) {
case pixel::Map::RGB:
for (uint32_t j = beginIndex; (j < endIndex) && (d < nLength); j++) {
auto const nPixelIndexStart = j * nGroupingCount;
for (uint32_t k = 0; k < nGroupingCount; k++) {
setPixelsColor3(nOutIndex, nPixelIndexStart + k, pData[d + 0], pData[d + 1], pData[d + 2]);
}
d += 3; // Increment by 3 since we're processing 3 channels per pixel
}
break;
case pixel::Map::RBG:
for (uint32_t j = beginIndex; (j < endIndex) && (d < nLength); j++) {
auto const nPixelIndexStart = j * nGroupingCount;
for (uint32_t k = 0; k < nGroupingCount; k++) {
setPixelsColor3(nOutIndex, nPixelIndexStart + k, pData[d + 0], pData[d + 2], pData[d + 1]);
}
d += 3; // Increment by 3 since we're processing 3 channels per pixel
}
break;
case pixel::Map::GRB:
for (uint32_t j = beginIndex; (j < endIndex) && (d < nLength); j++) {
auto const nPixelIndexStart = j * nGroupingCount;
for (uint32_t k = 0; k < nGroupingCount; k++) {
setPixelsColor3(nOutIndex, nPixelIndexStart + k, pData[d + 1], pData[d + 0], pData[d + 2]);
}
d += 3; // Increment by 3 since we're processing 3 channels per pixel
// Define a lambda to handle pixel setting based on color order
auto setPixelsColour3 = [&](const uint32_t nPortIndex, const uint32_t nPixelIndex, const uint32_t r, const uint32_t g, const uint32_t b) {
#if defined(CONFIG_PIXELDMX_ENABLE_GAMMATABLE)
const auto pGammaTable = m_pWS28xxMulti->m_PixelConfiguration.GetGammaTable();
r = pGammaTable[r];
g = pGammaTable[g];
b = pGammaTable[b];
#endif

switch (pixelType) {
case pixel::Type::WS2801:
m_pWS28xxMulti->SetColourWS2801(nPortIndex, nPixelIndex, r, g, b);
break;
case pixel::Type::APA102:
case pixel::Type::SK9822:
m_pWS28xxMulti->SetPixel4Bytes(nPortIndex, 1 + nPixelIndex, pixelDmxConfiguration.GetGlobalBrightness(), b, g, r);
break;
case pixel::Type::P9813: {
const auto nFlag = static_cast<uint8_t>(0xC0 | ((~b & 0xC0) >> 2) | ((~r & 0xC0) >> 4) | ((~r & 0xC0) >> 6));
m_pWS28xxMulti->SetPixel4Bytes(nPortIndex, 1 + nPixelIndex, nFlag, b, g, r);
}
break;
case pixel::Map::GBR:
for (uint32_t j = beginIndex; (j < endIndex) && (d < nLength); j++) {
auto const nPixelIndexStart = j * nGroupingCount;
for (uint32_t k = 0; k < nGroupingCount; k++) {
setPixelsColor3(nOutIndex, nPixelIndexStart + k, pData[d + 2], pData[d + 0], pData[d + 1]);
}
d += 3; // Increment by 3 since we're processing 3 channels per pixel
default:
assert(0);
__builtin_unreachable();
break;
}
break;
case pixel::Map::BRG:
};

constexpr uint32_t channelMap[6][3] = {
{0, 1, 2}, // RGB
{0, 2, 1}, // RBG
{1, 0, 2}, // GRB
{2, 0, 1}, // GBR
{1, 2, 0}, // BRG
{2, 1, 0} // BGR
};

const auto mapIndex = static_cast<uint32_t>(pixelDmxConfiguration.GetMap());
// Ensure mapIndex is within valid bounds
assert(mapIndex < sizeof(channelMap) / sizeof(channelMap[0])); // Runtime check
auto const& map = channelMap[mapIndex];

if (isRTZProtocol) {
for (uint32_t j = beginIndex; (j < endIndex) && (d < nLength); j++) {
auto const nPixelIndexStart = j * nGroupingCount;
for (uint32_t k = 0; k < nGroupingCount; k++) {
setPixelsColor3(nOutIndex, nPixelIndexStart + k, pData[d + 1], pData[d + 2], pData[d + 0]);
setPixelsColourRTZ(nOutIndex, nPixelIndexStart + k, pData[d + map[0]], pData[d + map[1]], pData[d + map[2]]);
}
d += 3; // Increment by 3 since we're processing 3 channels per pixel
}
break;
case pixel::Map::BGR:
} else {
for (uint32_t j = beginIndex; (j < endIndex) && (d < nLength); j++) {
auto const nPixelIndexStart = j * nGroupingCount;
for (uint32_t k = 0; k < nGroupingCount; k++) {
setPixelsColor3(nOutIndex, nPixelIndexStart + k, pData[d + 2], pData[d + 1], pData[d + 0]);
setPixelsColour3(nOutIndex, nPixelIndexStart + k, pData[d + map[0]], pData[d + map[1]], pData[d + map[2]]);
}
d += 3; // Increment by 3 since we're processing 3 channels per pixel
}
break;
default:
assert(0);
__builtin_unreachable();
break;
}
} else {
assert(nChannelsPerPixel == 4);
Expand Down

0 comments on commit 46f6462

Please sign in to comment.