Skip to content

Commit 2d4e29d

Browse files
committed
Rename constants to k-prefixed and tidy GD32 code
Apply a consistent k-prefixed naming convention and modernize GD32/DMX code: rename hal::statusled::Mode, panelled bits, DMX buffer/config constants (SIZE -> kSize, PORTS -> kPorts), and panel LED symbols (PORT_* -> kPort*). Replace platform GPIO initialization with Gd32GpioFsel and refactor gd32_gpio helpers (formatting, inline constexpr, clearer names). Add/adjust includes and IWYU pragmas, update copyright years, and propagate these changes across multiple DMX, E1.31 and board headers/sources to keep interfaces consistent and fix compile-time checks.
1 parent 67a4c7e commit 2d4e29d

35 files changed

Lines changed: 447 additions & 624 deletions

lib-display/include/displayhandler.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@ void DisplayStatusled(hal::statusled::Mode status_led_mode)
3838
char c;
3939
switch (status_led_mode)
4040
{
41-
case hal::statusled::Mode::OFF_OFF:
41+
case hal::statusled::Mode::kOffOff:
4242
c = 'O';
4343
break;
44-
case hal::statusled::Mode::OFF_ON:
44+
case hal::statusled::Mode::kOffOn:
4545
c = 'O';
4646
break;
47-
case hal::statusled::Mode::NORMAL:
47+
case hal::statusled::Mode::kNormal:
4848
c = 'N';
4949
break;
50-
case hal::statusled::Mode::DATA:
50+
case hal::statusled::Mode::kData:
5151
c = 'D';
5252
break;
53-
case hal::statusled::Mode::FAST:
53+
case hal::statusled::Mode::kFast:
5454
c = 'F';
5555
break;
56-
case hal::statusled::Mode::REBOOT:
56+
case hal::statusled::Mode::kReboot:
5757
c = 'R';
5858
break;
5959
default:

lib-dmx/include/dmxreceiver.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class DMXReceiver : Dmx
8484
{
8585
dmx_node_output_type_->Start(0);
8686
is_active_ = true;
87-
hal::statusled::SetMode(hal::statusled::Mode::DATA);
87+
hal::statusled::SetMode(hal::statusled::Mode::kData);
8888
}
8989

9090
return const_cast<uint8_t*>(dmx_available);
@@ -95,7 +95,7 @@ class DMXReceiver : Dmx
9595
{
9696
dmx_node_output_type_->Stop(0);
9797
is_active_ = false;
98-
hal::statusled::SetMode(hal::statusled::Mode::NORMAL);
98+
hal::statusled::SetMode(hal::statusled::Mode::kNormal);
9999
}
100100

101101
length = -1;

lib-dmx/include/dmxsend.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class DmxSend
6363

6464
if (Dmx::Get()->GetOutputStyle(port_index) == dmx::OutputStyle::kConstant)
6565
{
66-
hal::panelled::On(hal::panelled::PORT_A_TX << port_index);
66+
hal::panelled::On(hal::panelled::kPortATx << port_index);
6767
}
6868

6969
DEBUG_EXIT();
@@ -86,7 +86,7 @@ class DmxSend
8686

8787
Dmx::Get()->SetPortDirection(port_index, dmx::PortDirection::kOutput, false);
8888

89-
hal::panelled::Off(hal::panelled::PORT_A_TX << port_index);
89+
hal::panelled::Off(hal::panelled::kPortATx << port_index);
9090

9191
DEBUG_EXIT();
9292
}
@@ -100,7 +100,7 @@ class DmxSend
100100
if constexpr (doUpdate)
101101
{
102102
Dmx::Get()->SetSendDataWithoutSC<doUpdate ? dmx::SendStyle::kDirect : dmx::SendStyle::kSync>(port_index, data, length);
103-
hal::panelled::On(hal::panelled::PORT_A_TX << port_index);
103+
hal::panelled::On(hal::panelled::kPortATx << port_index);
104104
}
105105
}
106106

@@ -115,13 +115,13 @@ class DmxSend
115115
{
116116
Dmx::Get()->Sync();
117117

118-
for (uint32_t port_index = 0; port_index < dmx::config::max::PORTS; port_index++)
118+
for (uint32_t port_index = 0; port_index < dmx::config::max::kPorts; port_index++)
119119
{
120120
const auto kLightsetOffset = port_index + dmxnode::kDmxportOffset;
121121
if (dmxnode::Data::GetLength(kLightsetOffset) != 0)
122122
{
123123
dmxnode::Data::ClearLength(kLightsetOffset);
124-
hal::panelled::On(hal::panelled::PORT_A_TX << port_index);
124+
hal::panelled::On(hal::panelled::kPortATx << port_index);
125125
if (!IsStarted(started_, port_index))
126126
{
127127
Start(port_index);

lib-dmx/include/gd32/dmx.h

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,16 @@
3232
#include "dmx/dmx_config.h"
3333
#include "dmxstatistics.h"
3434

35-
struct Statistics
36-
{
35+
struct Statistics {
3736
uint32_t nSlotsInPacket;
3837
};
3938

40-
struct Data
41-
{
42-
uint8_t Data[dmx::buffer::SIZE];
39+
struct Data {
40+
uint8_t Data[dmx::buffer::kSize];
4341
struct Statistics Statistics;
4442
};
4543

46-
class Dmx
47-
{
44+
class Dmx {
4845
public:
4946
Dmx();
5047

@@ -112,9 +109,9 @@ class Dmx
112109
private:
113110
uint32_t m_nDmxTransmitPeriod{dmx::transmit::kPeriodDefault};
114111
uint32_t m_nDmxTransmitPeriodRequested{dmx::transmit::kPeriodDefault};
115-
uint32_t m_nDmxTransmissionLength[dmx::config::max::PORTS];
112+
uint32_t m_nDmxTransmissionLength[dmx::config::max::kPorts];
116113
uint32_t m_nDmxTransmitSlots{dmx::kChannelsMax};
117-
dmx::PortDirection m_dmxPortDirection[dmx::config::max::PORTS];
114+
dmx::PortDirection m_dmxPortDirection[dmx::config::max::kPorts];
118115
bool m_bHasContinuosOutput{false};
119116

120117
inline static Dmx* s_this;
@@ -124,10 +121,8 @@ class Dmx
124121
case i: \
125122
return SetSendDataInternal<i, SC, STYLE>(pData, length)
126123

127-
template <dmx::SendStyle dmxSendStyle> inline void Dmx::SetSendData(uint32_t port_index, const uint8_t* pData, uint32_t length)
128-
{
129-
switch (port_index)
130-
{
124+
template <dmx::SendStyle dmxSendStyle> inline void Dmx::SetSendData(uint32_t port_index, const uint8_t* pData, uint32_t length) {
125+
switch (port_index) {
131126
DMX_HANDLE_SEND_CASE(0, true, dmxSendStyle);
132127
#if DMX_MAX_PORTS >= 2
133128
DMX_HANDLE_SEND_CASE(1, true, dmxSendStyle);
@@ -155,10 +150,8 @@ template <dmx::SendStyle dmxSendStyle> inline void Dmx::SetSendData(uint32_t por
155150
}
156151
}
157152

158-
template <dmx::SendStyle dmxSendStyle> inline void Dmx::SetSendDataWithoutSC(uint32_t port_index, const uint8_t* pData, uint32_t length)
159-
{
160-
switch (port_index)
161-
{
153+
template <dmx::SendStyle dmxSendStyle> inline void Dmx::SetSendDataWithoutSC(uint32_t port_index, const uint8_t* pData, uint32_t length) {
154+
switch (port_index) {
162155
DMX_HANDLE_SEND_CASE(0, false, dmxSendStyle);
163156
#if DMX_MAX_PORTS >= 2
164157
DMX_HANDLE_SEND_CASE(1, false, dmxSendStyle);
@@ -188,4 +181,4 @@ template <dmx::SendStyle dmxSendStyle> inline void Dmx::SetSendDataWithoutSC(uin
188181

189182
#undef DMX_HANDLE_SEND_CASE
190183

191-
#endif // GD32_DMX_H_
184+
#endif // GD32_DMX_H_

lib-dmx/include/gd32/dmx_assert.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
#define DMX_CHECK_PORT_INDEX_VOID(x) \
3838
do \
3939
{ \
40-
assert((x) < dmx::config::max::PORTS); \
41-
if ((x) >= dmx::config::max::PORTS) [[unlikely]] \
40+
assert((x) < dmx::config::max::kPorts); \
41+
if ((x) >= dmx::config::max::kPorts) [[unlikely]] \
4242
return; \
4343
} while (0)
4444
#endif
@@ -50,8 +50,8 @@
5050
#define DMX_CHECK_PORT_INDEX_RET(x, ret) \
5151
do \
5252
{ \
53-
assert((x) < dmx::config::max::PORTS); \
54-
if ((x) >= dmx::config::max::PORTS) [[unlikely]] \
53+
assert((x) < dmx::config::max::kPorts); \
54+
if ((x) >= dmx::config::max::kPorts) [[unlikely]] \
5555
return ret; \
5656
} while (0)
5757
#endif
@@ -63,8 +63,8 @@
6363
#define DMX_CHECK_PORT_INDEX_PTR(x) \
6464
do \
6565
{ \
66-
assert((x) < dmx::config::max::PORTS); \
67-
if ((x) >= dmx::config::max::PORTS) [[unlikely]] \
66+
assert((x) < dmx::config::max::kPorts); \
67+
if ((x) >= dmx::config::max::kPorts) [[unlikely]] \
6868
return nullptr; \
6969
} while (0)
7070
#endif

lib-dmx/src/gd32/dmx.cpp

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,18 @@
3535
#include <algorithm>
3636
#include <cassert>
3737

38-
#include "dmx.h"
38+
#include "dmx.h" // IWYU pragma: keep
3939
#include "dmxconst.h"
4040
#include "rdm.h"
4141
#include "rdm_e120.h"
4242
#include "gd32.h"
4343
#include "gd32_dma.h"
4444
#include "gd32_uart.h"
45+
#include "gd32_gpio.h"
4546
#include "dmx_internal.h"
4647
#include "dmx/dmx_config.h"
4748
#include "gd32/dmx_assert.h"
48-
#include "gd32/dmx_dma_check.h" // Do not reorder/move
49+
#include "gd32/dmx_dma_check.h" // IWYU pragma: keep // Do not reorder/move
4950
#if defined(LOGIC_ANALYZER)
5051
#include "logic_analyzer.h"
5152
#endif
@@ -69,7 +70,7 @@ enum class TxRxState {
6970
enum class PortState { kIdle, kTx, kRx };
7071

7172
struct TxDmxDataPacket {
72-
uint8_t data[dmx::buffer::SIZE]; // multiple of uint32_t
73+
uint8_t data[dmx::buffer::kSize]; // multiple of uint32_t
7374
uint32_t length;
7475
};
7576

@@ -99,7 +100,7 @@ struct RxDmxPackets {
99100
};
100101

101102
struct RxDmxData {
102-
uint8_t data[dmx::buffer::SIZE] ALIGNED; // multiple of uint32_t
103+
uint8_t data[dmx::buffer::kSize] ALIGNED; // multiple of uint32_t
103104
uint32_t slots_in_packet;
104105
};
105106

@@ -146,26 +147,26 @@ static constexpr dmx::DirGpio kDirGpio[DMX_MAX_PORTS] = {
146147
#endif
147148
};
148149

149-
static volatile dmx::PortState sv_port_state[dmx::config::max::PORTS] ALIGNED;
150+
static volatile dmx::PortState sv_port_state[dmx::config::max::kPorts] ALIGNED;
150151

151152
#if !defined(CONFIG_DMX_DISABLE_STATISTICS)
152-
static volatile dmx::TotalStatistics sv_total_statistics[dmx::config::max::PORTS] ALIGNED;
153+
static volatile dmx::TotalStatistics sv_total_statistics[dmx::config::max::kPorts] ALIGNED;
153154
#endif
154155

155156
// DMX RX
156157

157-
static volatile dmx::RxDmxPackets sv_rx_dmx_packets[dmx::config::max::PORTS] ALIGNED;
158+
static volatile dmx::RxDmxPackets sv_rx_dmx_packets[dmx::config::max::kPorts] ALIGNED;
158159

159160
// RDM RX
160161
volatile uint32_t gsv_RdmDataReceiveEnd;
161162

162163
// DMX RDM RX
163164

164-
static volatile dmx::RxData sv_rx_buffer[dmx::config::max::PORTS] ALIGNED;
165+
static volatile dmx::RxData sv_rx_buffer[dmx::config::max::kPorts] ALIGNED;
165166

166167
// DMX TX
167168

168-
static dmx::TxData s_TxBuffer[dmx::config::max::PORTS] ALIGNED SECTION_DMA_BUFFER;
169+
static dmx::TxData s_TxBuffer[dmx::config::max::kPorts] ALIGNED SECTION_DMA_BUFFER;
169170
static dmx::DmxTransmit s_dmx_transmit;
170171

171172
template <uint32_t uart, uint32_t port_index> void IrqHandlerDmxRdmInput() {
@@ -1390,11 +1391,11 @@ void Dmx::SetPortDirection(uint32_t port_index, dmx::PortDirection port_directio
13901391
}
13911392

13921393
void Dmx::ClearData(uint32_t port_index) {
1393-
assert(port_index < dmx::config::max::PORTS);
1394+
assert(port_index < dmx::config::max::kPorts);
13941395

13951396
auto* p = &s_TxBuffer[port_index].dmx.data[0];
13961397
p->length = 513; // Including START Code
1397-
__builtin_memset(p->data, 0, dmx::buffer::SIZE);
1398+
__builtin_memset(p->data, 0, dmx::buffer::kSize);
13981399
}
13991400

14001401
#if !defined(CONFIG_DMX_DISABLE_STATISTICS)
@@ -1499,13 +1500,13 @@ template <uint32_t port_index, uint32_t nUart> static void StartDmxOutput() {
14991500
}
15001501

15011502
template <uint32_t portIndex> static void StartDmxOutputPort() {
1502-
if constexpr (portIndex < dmx::config::max::PORTS) {
1503+
if constexpr (portIndex < dmx::config::max::kPorts) {
15031504
StartDmxOutput<portIndex, DmxPortToUart(portIndex)>();
15041505
}
15051506
}
15061507

15071508
void Dmx::StartDmxOutput(uint32_t port_index) {
1508-
assert(port_index < dmx::config::max::PORTS);
1509+
assert(port_index < dmx::config::max::kPorts);
15091510

15101511
switch (port_index) {
15111512
case 0:
@@ -1649,7 +1650,7 @@ void Dmx::FullOn() {
16491650
auto* __restrict__ p = &s_TxBuffer[port_index].dmx.data[0];
16501651
auto* p32 = reinterpret_cast<uint32_t*>(p->data);
16511652

1652-
for (auto i = 0; i < dmx::buffer::SIZE / 4; i++) {
1653+
for (auto i = 0; i < dmx::buffer::kSize / 4; i++) {
16531654
*p32++ = UINT32_MAX;
16541655
}
16551656

@@ -1672,7 +1673,7 @@ void Dmx::StartOutput(uint32_t port_index) {
16721673
}
16731674

16741675
void Dmx::Sync() {
1675-
for (uint32_t port_index = 0; port_index < dmx::config::max::PORTS; port_index++) {
1676+
for (uint32_t port_index = 0; port_index < dmx::config::max::kPorts; port_index++) {
16761677
auto& tx_buffer = s_TxBuffer[port_index];
16771678

16781679
if (!tx_buffer.dmx.data_pending) {
@@ -1737,7 +1738,7 @@ const uint8_t* Dmx::GetDmxChanged(uint32_t port_index) {
17371738
if (sv_rx_buffer[port_index].dmx.current.slots_in_packet != sv_rx_buffer[port_index].dmx.previous.slots_in_packet) {
17381739
sv_rx_buffer[port_index].dmx.previous.slots_in_packet = sv_rx_buffer[port_index].dmx.current.slots_in_packet;
17391740

1740-
for (size_t i = 0; i < dmx::buffer::SIZE / 4; ++i) {
1741+
for (size_t i = 0; i < dmx::buffer::kSize / 4; ++i) {
17411742
dst32[i] = src32[i];
17421743
}
17431744

@@ -1746,7 +1747,7 @@ const uint8_t* Dmx::GetDmxChanged(uint32_t port_index) {
17461747

17471748
bool is_changed = false;
17481749

1749-
for (size_t i = 0; i < dmx::buffer::SIZE / 4; ++i) {
1750+
for (size_t i = 0; i < dmx::buffer::kSize / 4; ++i) {
17501751
const auto kSrcValue = src32[i];
17511752
auto dst_value = dst32[i];
17521753

@@ -2168,7 +2169,7 @@ void Dmx::SetDmxPeriodTime(uint32_t period) {
21682169

21692170
auto length_max = s_TxBuffer[0].dmx.data[0].length;
21702171

2171-
for (uint32_t port_index = 1; port_index < dmx::config::max::PORTS; port_index++) {
2172+
for (uint32_t port_index = 1; port_index < dmx::config::max::kPorts; port_index++) {
21722173
const auto kLength = s_TxBuffer[port_index].dmx.data[0].length;
21732174
if (kLength > length_max) {
21742175
length_max = kLength;
@@ -2207,7 +2208,7 @@ void Dmx::SetDmxSlots(uint16_t slots) {
22072208
if ((slots >= 2) && (slots <= dmx::kChannelsMax)) {
22082209
m_nDmxTransmitSlots = slots;
22092210

2210-
for (uint32_t i = 0; i < dmx::config::max::PORTS; i++) {
2211+
for (uint32_t i = 0; i < dmx::config::max::kPorts; i++) {
22112212
m_nDmxTransmissionLength[i] = static_cast<uint32_t>(slots);
22122213
}
22132214

@@ -2230,20 +2231,20 @@ void Dmx::SetOutputStyle(uint32_t port_index, dmx::OutputStyle output_style) {
22302231
return;
22312232
}
22322233

2233-
for (uint32_t index = 0; index < dmx::config::max::PORTS; index++) {
2234+
for (uint32_t index = 0; index < dmx::config::max::kPorts; index++) {
22342235
if ((s_TxBuffer[index].output_style == dmx::OutputStyle::kConstant) && (m_dmxPortDirection[index] == dmx::PortDirection::kOutput)) {
22352236
StopData(index);
22362237
}
22372238
}
22382239

2239-
for (uint32_t index = 0; index < dmx::config::max::PORTS; index++) {
2240+
for (uint32_t index = 0; index < dmx::config::max::kPorts; index++) {
22402241
if ((s_TxBuffer[index].output_style == dmx::OutputStyle::kConstant) && (m_dmxPortDirection[index] == dmx::PortDirection::kOutput)) {
22412242
StartDmxOutput(index);
22422243
}
22432244
}
22442245
} else {
22452246
m_bHasContinuosOutput = false;
2246-
for (uint32_t index = 0; index < dmx::config::max::PORTS; index++) {
2247+
for (uint32_t index = 0; index < dmx::config::max::kPorts; index++) {
22472248
if (s_TxBuffer[index].output_style == dmx::OutputStyle::kConstant) {
22482249
m_bHasContinuosOutput = true;
22492250
return;
@@ -2273,20 +2274,15 @@ Dmx::Dmx() {
22732274
s_dmx_transmit.inter_time = dmx::transmit::kPeriodDefault - s_dmx_transmit.break_time - s_dmx_transmit.mab_time - (dmx::kChannelsMax * 44) - 44;
22742275

22752276
for (auto port_index = 0; port_index < DMX_MAX_PORTS; port_index++) {
2276-
#if defined(GPIO_INIT)
2277-
gpio_init(kDirGpio[port_index].port, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, kDirGpio[port_index].pin);
2278-
#else
2279-
gpio_mode_set(kDirGpio[port_index].port, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLDOWN, kDirGpio[port_index].pin);
2280-
gpio_output_options_set(kDirGpio[port_index].port, GPIO_OTYPE_PP, GPIO_OSPEED, kDirGpio[port_index].pin);
2281-
#endif
2277+
Gd32GpioFsel(kDirGpio[port_index].port, kDirGpio[port_index].pin, GPIO_FSEL_OUTPUT);
22822278
m_nDmxTransmissionLength[port_index] = dmx::kChannelsMax;
22832279
sv_rx_buffer[port_index].state = dmx::TxRxState::kIdle;
22842280
s_TxBuffer[port_index].state = dmx::TxRxState::kIdle;
22852281
SetPortDirection(port_index, dmx::PortDirection::kInput, false);
22862282
SetOutputStyle(port_index, dmx::OutputStyle::kDelta);
22872283
ClearData(port_index);
22882284
}
2289-
2285+
22902286
SetDmxBreakTime(dmx::transmit::kBreakTimeTypical);
22912287
SetDmxMabTime(dmx::transmit::kMabTimeMin);
22922288
SetDmxSlots(dmx::kChannelsMax);

0 commit comments

Comments
 (0)