Skip to content

Commit c18da38

Browse files
committed
Restructure and migrate network, properties, and params
Migrated network, properties, and parameter-related files from lib-network, lib-properties, and other libraries into a new common directory structure. Added new JSON helpers and utility headers, updated Makefiles, and removed obsolete files. This refactor centralizes shared code, improves modularity, and prepares for future extensibility.
1 parent 3a5f110 commit c18da38

File tree

408 files changed

+10940
-12891
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

408 files changed

+10940
-12891
lines changed

common/.cproject

Lines changed: 149 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<projectDescription>
3-
<name>lib-network</name>
3+
<name>common</name>
44
<comment></comment>
55
<projects>
66
</projects>

lib-network/.settings/language.settings.xml renamed to common/.settings/language.settings.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
22
<project>
3-
<configuration id="cdt.managedbuild.toolchain.gnu.cross.base.2047974044" name="GD32">
3+
<configuration id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.base.306944287" name="Default">
44
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
5-
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1379390566130282924" id="org.eclipse.embedcdt.managedbuild.cross.arm.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Arm Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
5+
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
6+
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
7+
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
8+
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1069578116264638190" id="org.eclipse.embedcdt.managedbuild.cross.arm.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Arm Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
69
<language-scope id="org.eclipse.cdt.core.gcc"/>
710
<language-scope id="org.eclipse.cdt.core.g++"/>
811
</provider>
9-
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
10-
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
11-
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="([^/\\\\]*)((g?cc)|([gc]\+\+)|(clang))" prefer-non-shared="true"/>
1212
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
1313
</extension>
1414
</configuration>
File renamed without changes.

lib-network/include/networkparamsconst.h renamed to common/include/common/firmware/jamstapl/handleroled.h

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22
/**
3-
* @file networkparamsconst.h
3+
* @file handleroled.h
44
*
55
*/
66
/* Copyright (C) 2021-2025 by Arjan van Vught mailto:info@gd32-dmx.org
@@ -24,17 +24,29 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
struct NetworkParamsConst
27+
#include "jamstapl.h"
28+
#include "console.h"
29+
#include "display.h"
30+
31+
struct HandlerOled : public JamSTAPLDisplay
2832
{
29-
static inline const char FILE_NAME[] = "network.txt";
33+
HandlerOled() { s_this = this; }
34+
~HandlerOled() override = default;
35+
36+
// JamSTAPL
37+
void JamShowInfo(const char* info) override
38+
{
39+
Display::Get()->ClearLine(1);
40+
Display::Get()->Write(1, info);
41+
}
3042

31-
static inline const char USE_STATIC_IP[] = "use_static_ip";
43+
void JamShowStatus(const char* status, int exit_code) override
44+
{
45+
Display::Get()->TextStatus(status, exit_code == 0 ? console::Colours::kConsoleGreen : console::Colours::kConsoleRed);
46+
}
3247

33-
static inline const char IP_ADDRESS[] = "ip_address";
34-
static inline const char NET_MASK[] = "net_mask";
35-
static inline const char DEFAULT_GATEWAY[] = "default_gateway";
36-
static inline const char HOSTNAME[] = "hostname";
48+
static HandlerOled* Get() { return s_this; }
3749

38-
static inline const char NTP_SERVER[] = "ntp_server";
39-
static inline const char NAME_SERVER[] = "name_server";
50+
private:
51+
inline static HandlerOled* s_this;
4052
};
Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
2-
/**
3-
* @file globalparams.h
2+
/*
3+
* display.h
44
*
55
*/
66
/* Copyright (C) 2025 by Arjan van Vught mailto:info@gd32-dmx.org
@@ -25,37 +25,28 @@
2525
*/
2626

2727
#include <cstdint>
28-
#include <cassert>
2928

30-
#include "configurationstore.h"
29+
#include "pixeldmxconfiguration.h"
30+
#include "display.h"
31+
#include "pixelpatterns.h"
3132

32-
class GlobalParams
33+
namespace common::firmware::pixeldmx
3334
{
34-
public:
35-
GlobalParams() = default;
36-
37-
GlobalParams(const GlobalParams&) = delete;
38-
GlobalParams& operator=(const GlobalParams&) = delete;
39-
40-
GlobalParams(GlobalParams&&) = delete;
41-
GlobalParams& operator=(GlobalParams&&) = delete;
42-
43-
void Load();
44-
void Load(const char* buffer, uint32_t length);
45-
void Builder(char* buffer, uint32_t length, uint32_t& size);
35+
inline void Show(uint32_t line, pixelpatterns::Pattern pattern = pixelpatterns::Pattern::kNone)
36+
{
37+
auto& configuration = PixelDmxConfiguration::Get();
38+
auto* display = Display::Get();
39+
assert(display != nullptr);
4640

47-
void Set();
41+
display->ClearEndOfLine();
42+
display->Printf(line, "%s:%d G%d %s", pixel::GetType(configuration.GetType()), configuration.GetCount(), configuration.GetGroupingCount(),
43+
pixel::GetMap(configuration.GetMap()));
44+
display->ClearLine(8); // Status line
4845

49-
static void StaticCallbackFunction(void* p, const char* s)
46+
if (pattern != pixelpatterns::Pattern::kNone)
5047
{
51-
assert(p != nullptr);
52-
assert(s != nullptr);
53-
(static_cast<GlobalParams*>(p))->CallbackFunction(s);
48+
display->ClearLine(6);
49+
display->Printf(6, "%s:%u", PixelPatterns::GetName(pattern), static_cast<uint32_t>(pattern));
5450
}
55-
56-
private:
57-
void Dump();
58-
void CallbackFunction(const char* s);
59-
60-
common::store::Global store_global_;
61-
};
51+
}
52+
} // namespace common::firmware::pixeldmx
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22
/**
3-
* @file network_event.h
3+
* @file utils_array.h
44
*
55
*/
66
/* Copyright (C) 2025 by Arjan van Vught mailto:info@gd32-dmx.org
@@ -24,11 +24,12 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
namespace network::event
27+
#include <cstddef>
28+
29+
namespace common
30+
{
31+
template <typename T, size_t N> constexpr size_t ArraySize(const T (&)[N]) noexcept
2832
{
29-
void LinkUp();
30-
void LinkDown();
31-
void Ipv4AddressChanged();
32-
void Ipv4NetmaskChanged();
33-
void Ipv4GatewayChanged();
34-
} // namespace network::event
33+
return N;
34+
}
35+
} // namespace common
Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22
/**
3-
* @file net.h
3+
* @file utils_enum.h
44
*
55
*/
66
/* Copyright (C) 2025 by Arjan van Vught mailto:info@gd32-dmx.org
@@ -24,12 +24,21 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#include "emac/phy.h"
28-
#include "net/netif.h"
27+
#include <type_traits>
2928

30-
namespace net
29+
namespace common
3130
{
32-
void netif_set(phy::Link link, ip4_addr_t ipaddr, ip4_addr_t netmask, ip4_addr_t gw, bool use_dhcp);
33-
void net_handle();
34-
void net_link_down();
35-
} // namespace net
31+
32+
/// Converts an enum class value to its underlying integer type.
33+
template <typename Enum>
34+
inline auto ToValue(Enum e) noexcept {
35+
return static_cast<std::underlying_type_t<Enum>>(e);
36+
}
37+
38+
/// Converts an integer value to the corresponding enum class value.
39+
template <typename Enum>
40+
inline Enum FromValue(std::underlying_type_t<Enum> value) noexcept {
41+
return static_cast<Enum>(value);
42+
}
43+
44+
} // namespace common
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#pragma once
2+
/**
3+
* @file utils_flags.h
4+
* Generic enum class bitmask helpers (C++20, freestanding-safe, Google Style)
5+
*/
6+
/* Copyright (C) 2025 by Arjan van Vught mailto:info@gd32-dmx.org
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include <cstdint>
28+
#include <type_traits>
29+
30+
#include "common/utils/utils_enum.h" // Ensure this provides ToValue and FromValue
31+
32+
namespace common
33+
{
34+
35+
template <typename E>
36+
requires std::is_enum_v<E>
37+
constexpr E operator|(E lhs, E rhs)
38+
{
39+
return static_cast<E>(ToValue(lhs) | ToValue(rhs));
40+
}
41+
42+
template <typename E>
43+
requires std::is_enum_v<E>
44+
constexpr E operator&(E lhs, E rhs)
45+
{
46+
return static_cast<E>(ToValue(lhs) & ToValue(rhs));
47+
}
48+
49+
template <typename E>
50+
requires std::is_enum_v<E>
51+
constexpr E operator~(E e)
52+
{
53+
return static_cast<E>(~ToValue(e));
54+
}
55+
56+
template <typename E>
57+
requires std::is_enum_v<E>
58+
constexpr E& operator|=(E& lhs, E rhs)
59+
{
60+
lhs = lhs | rhs;
61+
return lhs;
62+
}
63+
64+
template <typename E>
65+
requires std::is_enum_v<E>
66+
constexpr E& operator&=(E& lhs, E rhs)
67+
{
68+
lhs = lhs & rhs;
69+
return lhs;
70+
}
71+
72+
template <typename E>
73+
requires std::is_enum_v<E>
74+
constexpr void SetFlag(uint32_t& flags, E bit, bool enable)
75+
{
76+
if (enable)
77+
{
78+
flags |= ToValue(bit);
79+
}
80+
else
81+
{
82+
flags &= ~ToValue(bit);
83+
}
84+
}
85+
86+
template <typename E>
87+
requires std::is_enum_v<E>
88+
constexpr uint32_t SetFlagValue(uint32_t flags, E bit, bool enable)
89+
{
90+
if (enable)
91+
{
92+
return flags | ToValue(bit);
93+
}
94+
else
95+
{
96+
return flags & ~ToValue(bit);
97+
}
98+
}
99+
100+
template <typename E>
101+
requires std::is_enum_v<E>
102+
constexpr bool IsFlagSet(uint32_t flags, E bit) {
103+
return (flags & ToValue(bit)) != 0;
104+
}
105+
106+
} // namespace common

0 commit comments

Comments
 (0)