Skip to content

Commit a08c574

Browse files
committed
Improve assertions, update copyrights & formatting
Replace bare assert(0) usages with assert(false && "<message>") or assert(false) to provide clearer diagnostics and mark unreachable cases. Update copyright years to include 2026 across several GD32/HAL files. Apply minor whitespace, include ordering and formatting fixes, adjust NDEBUG handling in pixel DMX JSON code, and small API/indentation cleanups. Affected files include gd32, hal and pixeldmx source/header files.
1 parent d65c638 commit a08c574

File tree

16 files changed

+91
-82
lines changed

16 files changed

+91
-82
lines changed

lib-displayudf/include/displayudf.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "firmwareversion.h"
3434
#if !defined(NO_EMAC)
3535
#include "network.h"
36-
#include "net/protocol/dhcp.h"
36+
#include "core/protocol/dhcp.h"
3737
#endif
3838
#if defined(NODE_ARTNET_MULTI)
3939
#define NODE_ARTNET
@@ -57,13 +57,13 @@
5757
#if defined(RDM_RESPONDER) || defined(OUTPUT_DMX_MONITOR) || defined(OUTPUT_DMX_PCA9685) || defined(OUTPUT_DMX_PIXEL) || defined(OUTPUT_DMX_TLC59711)
5858
#define HAVE_DMX_START_ADDRESS
5959
#endif
60-
#include "firmware/debug/debug_debug.h"
60+
#include "firmware/debug/debug_debug.h"
6161

6262
namespace displayudf
6363
{
6464
inline constexpr uint32_t kLabelMaxRows = 6;
6565

66-
enum class Labels: uint8_t
66+
enum class Labels : uint8_t
6767
{
6868
kTitle,
6969
kBoardname,
@@ -86,7 +86,7 @@ enum class Labels: uint8_t
8686
UNIVERSE_PORT_D,
8787
#endif
8888
#if defined(NODE_ARTNET) || defined(NODE_ARTNET_MULTI)
89-
kDestinationIpPortA,
89+
kDestinationIpPortA,
9090
#if (DMX_MAX_PORTS > 1)
9191
kDestinationIpPortB,
9292
#endif
@@ -178,40 +178,39 @@ class DisplayUdf final : public Display
178178
void ShowIpAddress()
179179
{
180180
ClearEndOfLine();
181-
Printf(labels_[static_cast<uint32_t>(displayudf::Labels::kIp)], "" IPSTR "/%d %c", IP2STR(net::GetPrimaryIp()), net::GetNetmaskCIDR(),
182-
network::iface::AddressingMode());
181+
Printf(labels_[static_cast<uint32_t>(displayudf::Labels::kIp)], "" IPSTR "/%d %c", IP2STR(network::GetPrimaryIp()), network::GetNetmaskCIDR(), network::iface::AddressingMode());
183182
}
184183

185184
void ShowNetmask()
186185
{
187186
ClearEndOfLine();
188-
Printf(labels_[static_cast<uint32_t>(displayudf::Labels::kNetmask)], "N: " IPSTR "", IP2STR(net::GetNetmask()));
187+
Printf(labels_[static_cast<uint32_t>(displayudf::Labels::kNetmask)], "N: " IPSTR "", IP2STR(network::GetNetmask()));
189188
ShowIpAddress();
190189
}
191190

192191
void ShowGatewayIp()
193192
{
194193
ClearEndOfLine();
195-
Printf(labels_[static_cast<uint32_t>(displayudf::Labels::kDefaultGateway)], "G: " IPSTR "", IP2STR(net::GetGatewayIp()));
194+
Printf(labels_[static_cast<uint32_t>(displayudf::Labels::kDefaultGateway)], "G: " IPSTR "", IP2STR(network::GetGatewayIp()));
196195
}
197196

198197
void ShowHostName()
199198
{
200199
ClearEndOfLine();
201-
Write(labels_[static_cast<uint32_t>(displayudf::Labels::kHostname)], network::iface::GetHostName());
200+
Write(labels_[static_cast<uint32_t>(displayudf::Labels::kHostname)], network::iface::HostName());
202201
}
203202

204-
void ShowDhcpStatus(net::dhcp::State state)
203+
void ShowDhcpStatus(network::dhcp::State state)
205204
{
206205
switch (state)
207206
{
208-
case net::dhcp::State::STATE_OFF:
207+
case network::dhcp::State::kOff:
209208
break;
210-
case net::dhcp::State::STATE_RENEWING:
209+
case network::dhcp::State::kRenewing:
211210
ClearEndOfLine();
212211
Printf(labels_[static_cast<uint32_t>(displayudf::Labels::kIp)], "DHCP renewing");
213212
break;
214-
case net::dhcp::State::STATE_BOUND:
213+
case network::dhcp::State::kBound:
215214
break;
216215
default:
217216
break;
@@ -248,4 +247,4 @@ class DisplayUdf final : public Display
248247
inline static DisplayUdf* s_this;
249248
};
250249

251-
#endif // DISPLAYUDF_H_
250+
#endif // DISPLAYUDF_H_

lib-dmx/include/dmxconfigudp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class DmxConfigUdp
106106
s_this = this;
107107

108108
assert(handle_ == -1);
109-
handle_ = net::udp::Begin(kUdpPort, DmxConfigUdp::StaticCallbackFunction);
109+
handle_ = network::udp::Begin(kUdpPort, DmxConfigUdp::StaticCallbackFunction);
110110

111111
DEBUG_EXIT();
112112
}
@@ -119,7 +119,7 @@ class DmxConfigUdp
119119
DEBUG_ENTRY();
120120

121121
assert(handle_ != -1);
122-
net::udp::End(kUdpPort);
122+
network::udp::End(kUdpPort);
123123
handle_ = -1;
124124

125125
s_this = nullptr;

lib-dmxnode/include/dmxnode_nodetype.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ enum class NodeType
4747

4848
inline constexpr const char* kNodeTypeNames[static_cast<uint32_t>(NodeType::kUndefined)] =
4949
{
50-
"Artnet",
50+
"Art-Net",
5151
"sACN E1.31",
5252
"DDP Display",
5353
"PixelPusher",

lib-dmxnode/include/dmxnode_outputtype.h

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @file dmxnode_outputtype.h
33
*/
4-
/* Copyright (C) 2025 by Arjan van Vught mailto:info@gd32-dmx.org
4+
/* Copyright (C) 2025-2026 by Arjan van Vught mailto:info@gd32-dmx.org
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -21,12 +21,11 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2222
* THE SOFTWARE.
2323
*/
24-
2524

2625
#ifndef DMXNODE_OUTPUTTYPE_H_
2726
#define DMXNODE_OUTPUTTYPE_H_
2827

29-
#include <cstdint>
28+
#include <cstdint>
3029

3130
namespace dmxnode
3231
{
@@ -49,23 +48,8 @@ enum class OutputType
4948
kUndefined
5049
};
5150

52-
inline constexpr const char* kOutputTypeNames[static_cast<uint32_t>(OutputType::kUndefined)] =
53-
{
54-
"DMX",
55-
"DMX/RDM",
56-
"Pixel",
57-
"Pixel/DMX",
58-
"PWM",
59-
"RGB Panel",
60-
"Serial",
61-
"OSC",
62-
"Monitor",
63-
"Stepper",
64-
"Player",
65-
"Art-Net",
66-
"Timecode",
67-
"None"
68-
};
51+
inline constexpr const char* kOutputTypeNames[static_cast<uint32_t>(OutputType::kUndefined)] = {
52+
"DMX", "DMX/RDM", "Pixel", "Pixel/DMX", "PWM", "RGB Panel", "Serial", "OSC", "Monitor", "Stepper", "Player", "Art-Net", "Timecode", "None"};
6953

7054
inline const char* GetOutputType(OutputType type)
7155
{
@@ -76,7 +60,7 @@ inline const char* GetOutputType(OutputType type)
7660

7761
return "Undefined";
7862
}
79-
} // namespace dmxnode
63+
} // namespace dmxnode
8064

8165
#if defined(OUTPUT_DMX_SEND) || defined(OUTPUT_DMX_SEND_MULTI)
8266
#define DMXNODE_OUTPUT_DMX
@@ -195,4 +179,4 @@ inline constexpr auto kOutputType = OutputType::kUndefined;
195179
#endif
196180
} // namespace dmxnode
197181

198-
#endif // DMXNODE_OUTPUTTYPE_H_
182+
#endif // DMXNODE_OUTPUTTYPE_H_

lib-gd32/include/gd32_dma.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file gd32_dma.h
33
*
44
*/
5-
/* Copyright (C) 2024-2025 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2024-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
@@ -63,7 +63,7 @@ template <uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag> inline
6363
interrupt_enable = DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_ERRIE;
6464
break;
6565
default:
66-
[[unlikely]] assert(0);
66+
[[unlikely]] assert(false && "Invalid flag");
6767
}
6868

6969
return interrupt_flag && interrupt_enable;
@@ -97,7 +97,7 @@ template <uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag> inline
9797
interrupt_enable = DMA_CHCTL(dma_periph, channelx) & gif_enable;
9898
break;
9999
default:
100-
[[unlikely]] assert(0);
100+
[[unlikely]] assert(false && "Invalid flag");
101101
}
102102

103103
return (interrupt_flag && interrupt_enable);
@@ -132,7 +132,7 @@ template <uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag> inline
132132
interrupt_enable = (DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_FTFIE);
133133
break;
134134
default:
135-
[[unlikely]] assert(0);
135+
[[unlikely]] assert(false && "Invalid flag");
136136
break;
137137
}
138138
}
@@ -162,13 +162,13 @@ template <uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag> inline
162162
interrupt_enable = DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_FTFIE;
163163
break;
164164
default:
165-
[[unlikely]] assert(0);
165+
[[unlikely]] assert(false && "Invalid flag");
166166
break;
167167
}
168168
}
169169
else
170170
{
171-
[[unlikely]] assert(0);
171+
[[unlikely]] assert(false && "Invalid channelx");
172172
}
173173

174174
return (interrupt_flag && interrupt_enable);

lib-gd32/include/gd32_dma_memcpy32.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file gd32_dma_memcpy32.h
33
*
44
*/
5-
/* Copyright (C) 2024-2025 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2024-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
@@ -37,10 +37,10 @@ void Init();
3737

3838
inline void StartDma(const void* destination, const void* source, uint32_t length)
3939
{
40+
#if !defined(GD32F4XX)
4041
assert((reinterpret_cast<uint32_t>(source) & 0x3) == 0);
4142
assert((reinterpret_cast<uint32_t>(destination) & 0x3) == 0);
4243

43-
#if !defined(GD32F4XX)
4444
uint32_t dma_chctl = DMA_CHCTL(DMA0, DMA_CH3);
4545
dma_chctl &= ~DMA_CHXCTL_CHEN;
4646
DMA_CHCTL(DMA0, DMA_CH3) = dma_chctl;
@@ -52,6 +52,9 @@ inline void StartDma(const void* destination, const void* source, uint32_t lengt
5252
dma_chctl |= (DMA_CHXCTL_CHEN | DMA_INT_FTF);
5353
DMA_CHCTL(DMA0, DMA_CH3) = dma_chctl;
5454
#else
55+
assert((reinterpret_cast<uint32_t>(source) & 0xF) == 0);
56+
assert((reinterpret_cast<uint32_t>(destination) & 0xF) == 0);
57+
5558
uint32_t dma_chctl = DMA_CHCTL(DMA1, DMA_CH0);
5659
dma_chctl &= ~DMA_CHXCTL_CHEN;
5760
DMA_CHCTL(DMA1, DMA_CH0) = dma_chctl;

lib-gd32/include/gd32_gpio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ inline uint32_t Gd32GpioToPeriph(uint32_t gpio)
196196
break;
197197
#endif
198198
default:
199-
assert(0);
199+
assert(false && "Invalid gpio");
200200
return 0;
201201
break;
202202
}

lib-gd32/src/f/gd32_dma_memcpy32.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file gd32_dma_memcpy32.cpp
33
*
44
*/
5-
/* Copyright (C) 2024-2025 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2024-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
@@ -23,7 +23,6 @@
2323
* THE SOFTWARE.
2424
*/
2525

26-
#include "gd32.h"
2726
#include "gd32_dma.h"
2827

2928
namespace dma::memcpy32
@@ -49,10 +48,12 @@ void Init()
4948
dma_circulation_disable(DMA0, DMA_CH3);
5049
dma_memory_to_memory_enable(DMA0, DMA_CH3);
5150

51+
#if !defined(DMA_MEMCPY32_DISABLE_IRQ)
5252
Gd32DmaInterruptFlagClear<DMA0, DMA_CH3, (DMA_INT_FLAG_FTF | DMA_INT_FLAG_G)>();
5353

5454
NVIC_SetPriority(DMA0_Channel3_IRQn, 0);
5555
NVIC_EnableIRQ(DMA0_Channel3_IRQn);
56+
#endif
5657
#else
5758
rcu_periph_clock_enable(RCU_DMA1);
5859
dma_deinit(DMA1, DMA_CH0);
@@ -73,10 +74,12 @@ void Init()
7374

7475
dma_multi_data_mode_init(DMA1, DMA_CH0, &dma_init_parameter);
7576

76-
Gd32DmaInterruptFlagClear<DMA1, DMA_CH3, (DMA_INT_FLAG_FTF | DMA_INT_FLAG_TAE)>();
77+
#if !defined(DMA_MEMCPY32_DISABLE_IRQ)
78+
Gd32DmaInterruptFlagClear<DMA1, DMA_CH0, (DMA_INT_FLAG_FTF | DMA_INT_FLAG_TAE)>();
7779

7880
NVIC_SetPriority(DMA1_Channel0_IRQn, 0);
7981
NVIC_EnableIRQ(DMA1_Channel0_IRQn);
8082
#endif
83+
#endif
8184
}
8285
} // namespace dma::memcpy32

lib-gd32/src/f/gd32_i2c.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file gd32_i2c.cpp
33
*
44
*/
5-
/* Copyright (C) 2021-2025 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
@@ -345,7 +345,7 @@ static void GpioConfigI2c()
345345
}
346346
else
347347
{
348-
assert(0);
348+
assert(false && "Invalid I2C_REMAP");
349349
}
350350
#endif
351351
#else
@@ -380,7 +380,7 @@ static void GpioConfigI2c1()
380380
}
381381
else
382382
{
383-
assert(0);
383+
assert(false && "Invalid I2C1_REMAP");
384384
}
385385
#endif
386386
#else

lib-gd32/src/gd32_bkp.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file gd32_bkp.cpp
33
*
44
*/
5-
/* Copyright (C) 2022-2025 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2022-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
@@ -38,7 +38,7 @@ void bkp_data_write(bkp_data_register_enum register_number, uint16_t data)
3838
RTC_BKP1 = static_cast<uint32_t>(data);
3939
break;
4040
default:
41-
assert(0);
41+
assert(false && "Invalid register_number");
4242
break;
4343
}
4444
}
@@ -54,11 +54,10 @@ uint16_t bkp_data_read(bkp_data_register_enum register_number)
5454
return RTC_BKP1;
5555
break;
5656
default:
57-
assert(0);
57+
assert(false && "Invalid register_number");
5858
break;
5959
}
6060

61-
assert(0);
6261
return 0;
6362
}
6463
#endif

0 commit comments

Comments
 (0)