Skip to content

Commit df5e159

Browse files
committed
Introduce LedType/LedMap and refactor pixel types
Rename pixel::Type/Map to pixel::LedType/pixel::LedMap and centralize type metadata into a constexpr TypeInfo table in pixeltype.h. Add helper APIs (GetTypeName, GetMapName, GetTypeInfo, GetTxH) and replace many callsites accordingly; remove the old pixeltype.cpp implementation. Update PixelConfiguration to use the new info (led count, protocol, default/max SPI Hz, map), simplify validation, and compute refresh/clock settings from TypeInfo. Make utils::ToValue/FromValue constexpr with static_asserts. Propagate enum and API name changes across gd32_rdm_responder, lib-pixel, lib-pixeldmx and JSON/status code. Minor formatting, include fixes, and copyright year updates (2026).
1 parent 8a95228 commit df5e159

21 files changed

Lines changed: 516 additions & 530 deletions

File tree

common/include/common/utils/utils_enum.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file utils_enum.h
33
*
44
*/
5-
/* Copyright (C) 2025 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2025-2026 by Arjan van Vught mailto:info@gd32-dmx.org
66
*
77
* Permission is hereby granted, free of charge, to any person obtaining a copy
88
* of this software and associated documentation files (the "Software"), to deal
@@ -30,19 +30,20 @@
3030

3131
namespace common
3232
{
33-
3433
/// Converts an enum class value to its underlying integer type.
35-
template <typename Enum>
36-
inline auto ToValue(Enum e) noexcept {
34+
template <typename Enum> constexpr auto ToValue(Enum e) noexcept -> std::underlying_type_t<Enum>
35+
{
36+
static_assert(std::is_enum_v<Enum>);
3737
return static_cast<std::underlying_type_t<Enum>>(e);
3838
}
3939

4040
/// Converts an integer value to the corresponding enum class value.
41-
template <typename Enum>
42-
inline Enum FromValue(std::underlying_type_t<Enum> value) noexcept {
41+
template <typename Enum> constexpr Enum FromValue(std::underlying_type_t<Enum> value) noexcept
42+
{
43+
static_assert(std::is_enum_v<Enum>);
4344
return static_cast<Enum>(value);
4445
}
4546

4647
} // namespace common
4748

48-
#endif // COMMON_UTILS_UTILS_ENUM_H_
49+
#endif // COMMON_UTILS_UTILS_ENUM_H_

common/include/firmware/pixeldmx/show.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* display.h
33
*
44
*/
5-
/* Copyright (C) 2025 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2025-2026 by Arjan van Vught mailto:info@gd32-dmx.org
66
*
77
* Permission is hereby granted, free of charge, to any person obtaining a copy
88
* of this software and associated documentation files (the "Software"), to deal
@@ -41,8 +41,8 @@ inline void Show(uint32_t line, pixelpatterns::Pattern pattern = pixelpatterns::
4141
assert(display != nullptr);
4242

4343
display->ClearEndOfLine();
44-
display->Printf(line, "%s:%d G%d %s", pixel::GetType(configuration.GetType()), configuration.GetCount(), configuration.GetGroupingCount(),
45-
pixel::GetMap(configuration.GetMap()));
44+
display->Printf(line, "%s:%d G%d %s", pixel::GetTypeName(configuration.GetType()), configuration.GetCount(), configuration.GetGroupingCount(),
45+
pixel::GetMapName(configuration.GetMap()));
4646
display->ClearLine(8); // Status line
4747

4848
if (pattern != pixelpatterns::Pattern::kNone)

gd32_rdm_responder/firmware/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ int main() // NOLINT
8282
PixelDmxParamsRdm pixeldmx_paramsrdm;
8383

8484
#if defined(CONFIG_RDM_MANUFACTURER_PIDS_SET)
85-
static constexpr auto kPersonalityCount = static_cast<uint32_t>(pixel::Type::UNDEFINED);
85+
static constexpr auto kPersonalityCount = static_cast<uint32_t>(pixel::LedType::kUndefined);
8686
RDMPersonality* personalities[kPersonalityCount];
8787

8888
for (uint32_t index = 0; index < kPersonalityCount; index++)
8989
{
90-
const auto* description = pixel::GetType(static_cast<pixel::Type>(index));
90+
const auto* description = pixel::GetTypeName(static_cast<pixel::LedType>(index));
9191
personalities[index] = new RDMPersonality(description, &pixeldmx);
9292
}
9393

gd32_rdm_responder/lib/display.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file display.cpp
33
*
44
*/
5-
/* Copyright (C) 2021 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2021-2026 by Arjan van Vught mailto:info@gd32-dmx.org
66
*
77
* Permission is hereby granted, free of charge, to any person obtaining a copy
88
* of this software and associated documentation files (the "Software"), to deal
@@ -43,15 +43,11 @@ void Display(const uint8_t data[kDmxFootprint])
4343
}
4444
else
4545
{
46-
DisplayUdf::Get()->Printf(6,
47-
"%-20s",
48-
PixelPatterns::GetName(static_cast<pixelpatterns::Pattern>(data[static_cast<uint32_t>(pixeldmx::paramsdmx::SlotsInfo::TEST_PATTERN)])));
46+
DisplayUdf::Get()->Printf(6, "%-20s", PixelPatterns::GetName(static_cast<pixelpatterns::Pattern>(data[static_cast<uint32_t>(pixeldmx::paramsdmx::SlotsInfo::TEST_PATTERN)])));
4947
}
5048

51-
DisplayUdf::Get()->Printf(
52-
7, "%-8s %-2d G%-2d %-5s", pixel::GetType(static_cast<pixel::Type>(data[static_cast<uint32_t>(pixeldmx::paramsdmx::SlotsInfo::TYPE)])),
53-
data[static_cast<uint32_t>(pixeldmx::paramsdmx::SlotsInfo::COUNT)], data[static_cast<uint32_t>(pixeldmx::paramsdmx::SlotsInfo::GROUPING_COUNT)],
54-
pixel::GetMap(static_cast<pixel::Map>(data[static_cast<uint32_t>(pixeldmx::paramsdmx::SlotsInfo::MAP)])));
49+
DisplayUdf::Get()->Printf(7, "%-8s %-2d G%-2d %-5s", pixel::GetTypeName(static_cast<pixel::LedType>(data[static_cast<uint32_t>(pixeldmx::paramsdmx::SlotsInfo::TYPE)])), data[static_cast<uint32_t>(pixeldmx::paramsdmx::SlotsInfo::COUNT)],
50+
data[static_cast<uint32_t>(pixeldmx::paramsdmx::SlotsInfo::GROUPING_COUNT)], pixel::GetMapName(static_cast<pixel::LedMap>(data[static_cast<uint32_t>(pixeldmx::paramsdmx::SlotsInfo::MAP)])));
5551

5652
if (data[kLastIndex] == 0xFF)
5753
{

gd32_rdm_responder/lib/personalityupdate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ void RDMResponder::PersonalityUpdate(uint32_t personality)
4141

4242
#if defined(CONFIG_RDM_MANUFACTURER_PIDS_SET)
4343
assert(personality != 0);
44-
assert((personality - 1U) < static_cast<uint32_t>(pixel::Type::UNDEFINED));
44+
assert((personality - 1U) < static_cast<uint32_t>(pixel::LedType::kUndefined));
4545

4646
const auto kType = static_cast<uint8_t>(personality - 1);
4747
auto& configuration = PixelDmxConfiguration::Get();
48-
configuration.SetType(common::FromValue<pixel::Type>(kType));
48+
configuration.SetType(common::FromValue<pixel::LedType>(kType));
4949
configuration.Validate(1);
5050

5151
dmxled_store::SaveType(kType);

lib-pixel/include/pixel.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@ inline void SetPixelColour([[maybe_unused]] uint32_t port_index, uint32_t pixel_
8080
#if defined(PIXELPATTERNS_MULTI)
8181
switch (PixelConfiguration::Get().GetType())
8282
{
83-
case pixel::Type::WS2801:
83+
case pixel::LedType::kWS2801:
8484
output_type->SetColourWS2801(port_index, pixel_index, kColours.Red(), kColours.Green(), kColours.Blue());
8585
break;
8686

87-
case pixel::Type::APA102:
88-
case pixel::Type::SK9822:
87+
case pixel::LedType::kAPA102:
88+
case pixel::LedType::kSK9822:
8989
output_type->SetPixel4Bytes(port_index, pixel_index, 0xFF, kColours.Red(), kColours.Green(), kColours.Blue());
9090
break;
9191

92-
case pixel::Type::P9813:
92+
case pixel::LedType::kP9813:
9393
{
9494
const auto kRed = kColours.Red();
9595
const auto kBlue = kColours.Blue();
@@ -98,7 +98,7 @@ inline void SetPixelColour([[maybe_unused]] uint32_t port_index, uint32_t pixel_
9898
break;
9999
}
100100

101-
case pixel::Type::SK6812W:
101+
case pixel::LedType::kSK6812W:
102102
output_type->SetColourRTZ(port_index, pixel_index, kColours.Red(), kColours.Green(), kColours.Blue(), kColours.White());
103103
break;
104104

@@ -110,7 +110,7 @@ inline void SetPixelColour([[maybe_unused]] uint32_t port_index, uint32_t pixel_
110110
auto& pixel_configuration = PixelConfiguration::Get();
111111
const auto kType = pixel_configuration.GetType();
112112

113-
if (kType != pixel::Type::SK6812W)
113+
if (kType != pixel::LedType::kSK6812W)
114114
{
115115
output_type->SetPixel(pixel_index, kColours.Red(), kColours.Green(), kColours.Blue());
116116
}

0 commit comments

Comments
 (0)