Skip to content

Commit ce449d3

Browse files
committed
Add utils_port, configstore fixes, build tweaks
Add common/utils/utils_port.h providing PortSet/PortGet helpers. Update configuration layout and APIs: rename dmxnode fields (long_name -> node_name, label -> port_name, kLabelNameLength -> kPortNameLength), change DmxSerial/DmxMonitor/RdmDevice set_list -> flags and adapt ConfigStore setters/getters and array helpers accordingly. Bump copyright years in several headers. Remove -fprefetch-loop-arrays pragmas from multiple files. Add canonical _TIME_STAMP_ define via common/make/Timestamp.mk and include it from gd32/Validate.mk to centralize timestamp handling. Simplify FirmwareVersion by removing the stored version id and remove board/release id constants from hal.h. Add detailed RTL8201F RMII timing comment and platform-specific notes, and make various lib-remoteconfig formatting/feature-include tweaks (NODE_RDMNET_LLRP_ONLY include, kjsoninfos entry reflow and NODE_SHOWFILE handling).
1 parent 3779bc5 commit ce449d3

14 files changed

Lines changed: 206 additions & 125 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* @file dmxnode_utils.h
3+
*
4+
*/
5+
/* Copyright (C) 2025 by Arjan van Vught mailto:info@gd32-dmx.org
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
26+
#ifndef COMMON_UTILS_UTILS_PORT_H_
27+
#define COMMON_UTILS_UTILS_PORT_H_
28+
29+
#include <cstdint>
30+
31+
namespace common
32+
{
33+
template <class S> void PortSet(uint32_t port_index, S s, uint16_t& n)
34+
{
35+
uint16_t value = n; // Create a local copy
36+
value &= static_cast<uint16_t>(~(0x3 << (port_index * 2)));
37+
value |= static_cast<uint16_t>((static_cast<uint32_t>(s) & 0x3) << (port_index * 2));
38+
n = value; // Write back to the original field
39+
}
40+
41+
template <class S> S PortGet(uint32_t port_index, uint16_t n)
42+
{
43+
return static_cast<S>((n >> (port_index * 2)) & 0x3);
44+
}
45+
} // namespace common
46+
47+
#endif // COMMON_UTILS_UTILS_PORT_H_

common/make/Timestamp.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ $(info "Timestamp.mk")
22

33
ifneq ($(findstring _TIME_STAMP_YEAR_,$(DEFINES)), _TIME_STAMP_YEAR_)
44
DEFINES += \
5-
-D_TIME_STAMP_YEAR_=$(shell date +"%Y") \
5+
-D_TIME_STAMP_=$(shell date "+%s") \
6+
-D_TIME_STAMP_YEAR_=$(shell date +"%Y") \
67
-D_TIME_STAMP_MONTH_=$(shell date +"%m" | sed 's/^0*//') \
78
-D_TIME_STAMP_DAY_=$(shell date +"%d" | sed 's/^0*//')
89
endif

common/make/gd32/Validate.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ifeq ($(FLAGS),)
88
endif
99

1010
ifneq ($(findstring _TIME_STAMP_YEAR_,$(FLAGS)),_TIME_STAMP_YEAR_)
11-
DEFINES+=-D_TIME_STAMP_YEAR_=$(shell date +"%Y") -D_TIME_STAMP_MONTH_=$(shell date +"%-m") -D_TIME_STAMP_DAY_=$(shell date +"%-d")
11+
include ../common/make/Timestamp.mk
1212
endif
1313

1414
ifneq (,$(findstring OUTPUT_DMX_SEND,$(FLAGS))$(findstring CONFIG_RDM,$(FLAGS))$(findstring RDM_CONTROLLER,$(FLAGS))$(findstring LTC,$(FLAGS)))

lib-clib/src/crc32/crc32.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#pragma GCC push_options
1212
#pragma GCC optimize ("O2")
1313
#pragma GCC optimize ("-funroll-loops")
14-
#pragma GCC optimize ("-fprefetch-loop-arrays")
1514

1615
#include <cstdint>
1716
#include <cstddef>

lib-configstore/include/configstore.h

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file configstore.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
@@ -211,9 +211,9 @@ class ConfigStore : StoreDevice
211211
void SetFlagDmxSend(uint32_t flag) { SetFlagInternal(GetStore()->dmx_send, &common::store::DmxSend::flags, flag); }
212212
void SetFlagDmxLed(uint32_t flag) { SetFlagInternal(GetStore()->dmx_led, &common::store::DmxLed::flags, flag); }
213213
void SetFlagDmxPwm(uint32_t flag) { SetFlagInternal(GetStore()->dmx_pwm, &common::store::DmxPwm::flags, flag); }
214-
void SetFlagDmxSerial(uint32_t flag) { SetFlagInternal(GetStore()->dmx_serial, &common::store::DmxSerial::set_list, flag); }
215-
void SetFlagDmxMonitor(uint32_t flag) { SetFlagInternal(GetStore()->dmx_monitor, &common::store::DmxMonitor::set_list, flag); }
216-
void SetFlagRdmDevice(uint32_t flag) { SetFlagInternal(GetStore()->rdm_device, &common::store::RdmDevice::set_list, flag); }
214+
void SetFlagDmxSerial(uint32_t flag) { SetFlagInternal(GetStore()->dmx_serial, &common::store::DmxSerial::flags, flag); }
215+
void SetFlagDmxMonitor(uint32_t flag) { SetFlagInternal(GetStore()->dmx_monitor, &common::store::DmxMonitor::flags, flag); }
216+
void SetFlagRdmDevice(uint32_t flag) { SetFlagInternal(GetStore()->rdm_device, &common::store::RdmDevice::flags, flag); }
217217
void SetFlagShowFile(uint32_t flag) { SetFlagInternal(GetStore()->show_file, &common::store::ShowFile::flags, flag); }
218218
void SetFlagLtc(uint32_t flag) { SetFlagInternal(GetStore()->ltc, &common::store::Ltc::flags, flag); }
219219
void SetFlagLtcDisplay(uint32_t flag) { SetFlagInternal(GetStore()->ltc_display, &common::store::LtcDisplay::flags, flag); }
@@ -233,9 +233,9 @@ class ConfigStore : StoreDevice
233233
void ClearFlagDmxSend(uint32_t flag) { ClearFlagInternal(GetStore()->dmx_send, &common::store::DmxSend::flags, flag); }
234234
void ClearFlagDmxLed(uint32_t flag) { ClearFlagInternal(GetStore()->dmx_led, &common::store::DmxLed::flags, flag); }
235235
void ClearFlagDmxPwm(uint32_t flag) { ClearFlagInternal(GetStore()->dmx_pwm, &common::store::DmxPwm::flags, flag); }
236-
void ClearFlagDmxSerial(uint32_t flag) { ClearFlagInternal(GetStore()->dmx_serial, &common::store::DmxSerial::set_list, flag); }
237-
void ClearFlagDmxMonitor(uint32_t flag) { ClearFlagInternal(GetStore()->dmx_monitor, &common::store::DmxMonitor::set_list, flag); }
238-
void ClearFlagRdmDevice(uint32_t flag) { ClearFlagInternal(GetStore()->rdm_device, &common::store::RdmDevice::set_list, flag); }
236+
void ClearFlagDmxSerial(uint32_t flag) { ClearFlagInternal(GetStore()->dmx_serial, &common::store::DmxSerial::flags, flag); }
237+
void ClearFlagDmxMonitor(uint32_t flag) { ClearFlagInternal(GetStore()->dmx_monitor, &common::store::DmxMonitor::flags, flag); }
238+
void ClearFlagRdmDevice(uint32_t flag) { ClearFlagInternal(GetStore()->rdm_device, &common::store::RdmDevice::flags, flag); }
239239
void ClearFlagShowFile(uint32_t flag) { ClearFlagInternal(GetStore()->show_file, &common::store::ShowFile::flags, flag); }
240240
void ClearFlagLtc(uint32_t flag) { ClearFlagInternal(GetStore()->ltc, &common::store::Ltc::flags, flag); }
241241
void ClearFlagLtcDisplay(uint32_t flag) { ClearFlagInternal(GetStore()->ltc_display, &common::store::LtcDisplay::flags, flag); }
@@ -255,9 +255,9 @@ class ConfigStore : StoreDevice
255255
bool IsFlagSetDmxSend(uint32_t flag) const { return IsFlagSetInternal(GetStore()->dmx_send, &common::store::DmxSend::flags, flag); }
256256
bool IsFlagSetDmxLed(uint32_t flag) const { return IsFlagSetInternal(GetStore()->dmx_led, &common::store::DmxLed::flags, flag); }
257257
bool IsFlagSetDmxPwm(uint32_t flag) const { return IsFlagSetInternal(GetStore()->dmx_pwm, &common::store::DmxPwm::flags, flag); }
258-
bool IsFlagSetDmxSerial(uint32_t flag) const { return IsFlagSetInternal(GetStore()->dmx_serial, &common::store::DmxSerial::set_list, flag); }
259-
bool IsFlagSetDmxMonitor(uint32_t flag) const { return IsFlagSetInternal(GetStore()->dmx_monitor, &common::store::DmxMonitor::set_list, flag); }
260-
bool IsFlagSetRdmDevice(uint32_t flag) const { return IsFlagSetInternal(GetStore()->rdm_device, &common::store::RdmDevice::set_list, flag); }
258+
bool IsFlagSetDmxSerial(uint32_t flag) const { return IsFlagSetInternal(GetStore()->dmx_serial, &common::store::DmxSerial::flags, flag); }
259+
bool IsFlagSetDmxMonitor(uint32_t flag) const { return IsFlagSetInternal(GetStore()->dmx_monitor, &common::store::DmxMonitor::flags, flag); }
260+
bool IsFlagSetRdmDevice(uint32_t flag) const { return IsFlagSetInternal(GetStore()->rdm_device, &common::store::RdmDevice::flags, flag); }
261261
bool IsFlagSetShowFile(uint32_t flag) const { return IsFlagSetInternal(GetStore()->show_file, &common::store::ShowFile::flags, flag); }
262262
bool IsFlagSetLtc(uint32_t flag) const { return IsFlagSetInternal(GetStore()->ltc, &common::store::Ltc::flags, flag); }
263263
bool IsFlagSetLtcDisplay(uint32_t flag) const { return IsFlagSetInternal(GetStore()->ltc_display, &common::store::LtcDisplay::flags, flag); }
@@ -289,10 +289,16 @@ class ConfigStore : StoreDevice
289289
static_assert(N == common::store::ltc::display::kMaxInfoMessage, "Size mismatch");
290290
memcpy(dest, (GetStore()->ltc_display.*field), N);
291291
}
292+
293+
template <std::size_t N> void RdmDeviceCopyArray(uint8_t (&dest)[N], const uint8_t (common::store::RdmDevice::*field)[N]) const
294+
{
295+
static_assert(N == common::store::rdmdevice::kLabelMaxLength, "Size mismatch");
296+
memcpy(dest, (GetStore()->rdm_device.*field), N);
297+
}
292298

293-
template <std::size_t N> void RdmDeviceUpdateArray(uint8_t (common::store::RdmDevice::*field)[N], const char* src, uint32_t length)
299+
template <std::size_t N> void RdmDeviceUpdateArray(uint8_t (common::store::RdmDevice::*field)[N], const uint8_t* src, uint32_t length)
294300
{
295-
UpdateArray(GetStore()->rdm_device, field, reinterpret_cast<const uint8_t*>(src), length);
301+
UpdateArray(GetStore()->rdm_device, field, src, length);
296302
}
297303

298304
uint8_t RdmSensorsIndexedGetType(uint32_t index) const
@@ -329,7 +335,7 @@ class ConfigStore : StoreDevice
329335
template <std::size_t N>
330336
void DmxNodeUpdateLabel(uint8_t (common::store::DmxNode::*field)[common::store::dmxnode::kParamPorts][N], uint32_t index, const char* src, uint32_t length)
331337
{
332-
static_assert(N == common::store::dmxnode::kLabelNameLength, "Label size mismatch");
338+
static_assert(N == common::store::dmxnode::kPortNameLength, "Label size mismatch");
333339
assert(index < common::store::dmxnode::kParamPorts);
334340
assert(src != nullptr);
335341

lib-configstore/include/configurationstore.h

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file configurationstore.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
@@ -149,7 +149,7 @@ namespace dmxnode
149149
{
150150
inline constexpr uint32_t kParamPorts = 4;
151151
inline constexpr uint32_t kNodeNameLength = 64;
152-
inline constexpr uint32_t kLabelNameLength = 18;
152+
inline constexpr uint32_t kPortNameLength = 18;
153153

154154
struct Flags
155155
{
@@ -174,8 +174,8 @@ struct DmxNode
174174
uint16_t merge_mode;
175175
uint8_t output_style;
176176
uint8_t fail_safe;
177-
uint8_t long_name[dmxnode::kNodeNameLength];
178-
uint8_t label[dmxnode::kParamPorts][dmxnode::kLabelNameLength];
177+
uint8_t node_name[dmxnode::kNodeNameLength];
178+
uint8_t port_name[dmxnode::kParamPorts][dmxnode::kPortNameLength];
179179
uint8_t reserved1[2];
180180
uint16_t protocol;
181181
uint16_t rdm;
@@ -340,7 +340,7 @@ static_assert(sizeof(DmxPwm) == kDmxPwmSize);
340340

341341
struct DmxSerial
342342
{
343-
uint32_t set_list;
343+
uint32_t flags;
344344
uint8_t type;
345345
uint8_t reserved1[3];
346346
uint32_t baud;
@@ -361,7 +361,7 @@ static_assert(sizeof(DmxSerial) == kDmxSerialSize);
361361

362362
struct DmxMonitor
363363
{
364-
uint32_t set_list;
364+
uint32_t flags;
365365
uint16_t dmx_start_address;
366366
uint16_t dmx_max_channels;
367367
uint8_t format;
@@ -377,16 +377,12 @@ inline constexpr uint32_t kLabelMaxLength = 32;
377377

378378
struct RdmDevice
379379
{
380-
uint32_t set_list;
380+
uint32_t flags;
381381
uint8_t device_root_label[rdmdevice::kLabelMaxLength];
382382
uint8_t device_root_label_length;
383-
uint8_t reserved;
384-
uint16_t product_category;
385-
uint16_t product_detail;
386-
uint8_t reserved2[6];
383+
uint8_t reserved2[11];
387384
} PACKED;
388385

389-
static_assert(offsetof(RdmDevice, product_category) % alignof(uint16_t) == 0, "product_category must be uint16_t-aligned");
390386
static_assert(sizeof(RdmDevice) == kRdmDeviceSize);
391387

392388
namespace rdm::sensors
@@ -619,7 +615,8 @@ struct Gps
619615

620616
static_assert(sizeof(Gps) == kGpsSize);
621617

622-
namespace midi {
618+
namespace midi
619+
{
623620
struct Flags
624621
{
625622
enum class Flag : uint32_t
@@ -629,7 +626,7 @@ struct Flags
629626

630627
static constexpr bool Has(uint32_t value, Flag flag) noexcept { return (value & static_cast<uint32_t>(flag)) != 0; }
631628
};
632-
} // namespace midi
629+
} // namespace midi
633630

634631
struct Midi
635632
{
@@ -705,7 +702,7 @@ struct SlotInfo
705702
namespace mode
706703
{
707704
inline constexpr uint16_t kMaxDmxFootprint = 4;
708-
705+
709706
struct Flags
710707
{
711708
enum class Flag : uint32_t
@@ -749,8 +746,8 @@ struct Flags
749746
};
750747

751748
static constexpr bool Has(uint32_t value, Flag flag) noexcept { return (value & static_cast<uint32_t>(flag)) != 0; }
752-
};
753-
} // namespace l6470
749+
};
750+
} // namespace l6470
754751

755752
struct L6470
756753
{
@@ -788,7 +785,7 @@ struct Store
788785
static_assert(offsetof(Store, mode) % alignof(uint32_t) == 0, "mode must be uint32_t-aligned");
789786
static_assert(offsetof(Store, l6470) % alignof(uint32_t) == 0, "l6470 must be uint32_t-aligned");
790787
static_assert(offsetof(Store, motor) % alignof(uint32_t) == 0, "motor must be uint32_t-aligned");
791-
} // namespace l6470dmx
788+
} // namespace l6470dmx
792789

793790
struct DmxL6470
794791
{
@@ -851,4 +848,4 @@ static_assert(offsetof(ConfigurationStore, global) == 16, "Wrong offset: global"
851848
#undef PACKED
852849
#endif
853850

854-
#endif // CONFIGURATIONSTORE_H_
851+
#endif // CONFIGURATIONSTORE_H_

lib-display/include/i2c/display.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#pragma GCC optimize("O3")
4040
#endif
4141
#pragma GCC optimize("no-tree-loop-distribute-patterns")
42-
#pragma GCC optimize("-fprefetch-loop-arrays")
4342
#endif
4443
#endif
4544

lib-display/include/spi/display.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file display.h
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
@@ -39,7 +39,6 @@
3939
#pragma GCC optimize("O3")
4040
#endif
4141
#pragma GCC optimize("no-tree-loop-distribute-patterns")
42-
#pragma GCC optimize("-fprefetch-loop-arrays")
4342
#endif
4443
#endif
4544

@@ -70,7 +69,7 @@ inline constexpr uint32_t CS_GPIO = SPI_LCD_CS_GPIO;
7069
inline constexpr uint32_t CS_GPIO = 0;
7170
#endif
7271

73-
#include "firmware/debug/debug_debug.h"
72+
#include "firmware/debug/debug_debug.h"
7473

7574
class Display : public LcdDriver
7675
{
@@ -356,4 +355,4 @@ class Display : public LcdDriver
356355
#endif
357356
#endif
358357

359-
#endif // SPI_DISPLAY_H_
358+
#endif // SPI_DISPLAY_H_

lib-hal/include/firmwareversion.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @file firmwareversion.h
33
*/
4-
/* Copyright (C) 2019-2025 by Arjan van Vught mailto:info@gd32-dmx.org
4+
/* Copyright (C) 2019-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
@@ -56,8 +56,7 @@ struct Info
5656
class FirmwareVersion
5757
{
5858
public:
59-
explicit FirmwareVersion(const char* software_version, const char* date, const char* time, uint32_t software_version_id = 0)
60-
: kSoftwareVersionId(software_version_id)
59+
explicit FirmwareVersion(const char* software_version, const char* date, const char* time)
6160
{
6261
assert(software_version != nullptr);
6362
assert(date != nullptr);
@@ -90,12 +89,10 @@ class FirmwareVersion
9089
const struct firmwareversion::Info* GetVersion() { return &s_firmware_version; }
9190
const char* GetPrint() { return s_print; }
9291
const char* GetSoftwareVersion() { return s_firmware_version.software_version; }
93-
uint32_t GetVersionId() const { return kSoftwareVersionId; }
9492

9593
static FirmwareVersion* Get() { return s_this; }
9694

9795
private:
98-
const uint32_t kSoftwareVersionId;
9996
static inline firmwareversion::Info s_firmware_version;
10097
static inline char s_print[64];
10198
static inline FirmwareVersion* s_this;

lib-hal/include/gd32/hal.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,6 @@ extern volatile uint32_t gv_nSysTickMillis;
6868

6969
namespace hal
7070
{
71-
inline constexpr uint32_t kBoardId =
72-
#if defined(GD32_BOARD_ID)
73-
GD32_BOARD_ID;
74-
#else
75-
0;
76-
#endif
77-
static constexpr uint32_t kReleaseId =
78-
#if defined(RELEASE_ID)
79-
RELEASE_ID;
80-
#else
81-
0;
82-
#endif
8371
inline constexpr const char kWebsite[] = "https://gd32-dmx.org";
8472
inline constexpr float kCoreTemperatureMin = -40.0;
8573
inline constexpr float kCoreTemperatureMax = +85.0;

0 commit comments

Comments
 (0)