Skip to content

Commit 15841e8

Browse files
committed
Refactor DMX port config to use port::Info struct
Replace per-UART port index constants with a unified `dmx::port::Info` struct that captures UART, GPIO port/pin, and usage mode (TxRx/TxOnly/RxOnly). Key changes: - Add `lib-dmx/include/gd32/dmx_port.h` with `port::Info` and `port::Usage` - Add `gd32::Uart` enum to `gd32_uart.h`; rename `Gd32Uart*` functions to `gd32::Uart*` - Replace `DmxPortToUart()` with `GetPortByUart()` consteval lookup - Board config now uses `kPort0` instead of separate GPIO/port constants - Fix typo `has_continuos_output_` → `has_continuous_output_` - Update `gd32.json` with additional GD32 device identifiers - Move `HwTimersSeconds` extern to `timing.h`
1 parent 3ece76e commit 15841e8

16 files changed

Lines changed: 767 additions & 642 deletions

File tree

.clang-tidy

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ Checks: >
66
modernize-*,
77
readability-*,
88
-readability-convert-member-functions-to-static,
9+
-readability-use-std-min-max,
910
-modernize-avoid-c-arrays,
10-
-modernize-loop-convert,
1111
-modernize-use-trailing-return-type,
12+
-modernize-use-std-print,
1213
misc-unused-include
1314
1415
CheckOptions:
@@ -78,6 +79,22 @@ CheckOptions:
7879
- key: readability-identifier-naming.TreatAsConstant
7980
value: 'constexpr'
8081

82+
- key: readability-identifier-naming.VariableConstantCase
83+
value: CamelCase
84+
- key: readability-identifier-naming.VariableConstantPrefix
85+
value: k
86+
87+
- key: readability-identifier-naming.TypeTemplateParameterCase
88+
value: CamelCase
89+
90+
- key: readability-identifier-naming.ValueTemplateParameterCase
91+
value: CamelCase
92+
- key: readability-identifier-naming.ValueTemplateParameterPrefix
93+
value: k
94+
95+
- key: readability-identifier-naming.TemplateTemplateParameterCase
96+
value: CamelCase
97+
8198
WarningsAsErrors: ''
8299
HeaderFilterRegex: '.*'
83100
FormatStyle: none

common/include/dmx/board_gd32f303rc.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <cstdint>
3030

3131
#include "gd32.h" // IWYU pragma: keep
32+
#include "gd32/dmx_port.h"
3233

3334
#define DMX_MAX_PORTS 1
3435

@@ -39,9 +40,6 @@ inline constexpr uint32_t kPorts = DMX_MAX_PORTS;
3940

4041
#define DMX_USE_USART2
4142

42-
inline constexpr auto kUsart2Port = 0;
43-
44-
inline constexpr auto kDirPort0GpioPort = GPIOB;
45-
inline constexpr auto kDirPort0GpioPin = GPIO_PIN_10;
43+
inline constexpr port::Info kPort0 = {.uart = gd32::Uart::kUart2, .port = GPIOB, .pin = GPIO_PIN_10, .usage = port::Usage::kTxRx};
4644
} // namespace dmx::config
4745
#endif // DMX_BOARD_GD32F303RC_H_

common/scripts/gd32/gd32.json

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
{
22
"0414": {
33
"identifiers": {
4+
"3RCB": {
5+
"series": "GD32F103",
6+
"flash": {
7+
"256": "GD32F103RCXX"
8+
}
9+
},
410
"3RCF": {
511
"series": "GD32F303",
612
"flash": {
7-
"256": "GD32F303RCXX"
13+
"256": "GD32F303XCXX"
814
}
915
},
10-
"3RCB": {
11-
"series": "GD32F103",
16+
"3VCF": {
17+
"series": "GD32F303",
1218
"flash": {
13-
"256": "GD32F103RCXX"
19+
"256": "GD32F303XCXX"
20+
}
21+
},
22+
"3VEF": {
23+
"series": "GD32F303",
24+
"flash": {
25+
"512": "GD32F303XEXX"
1426
}
1527
}
1628
}
@@ -20,13 +32,13 @@
2032
"7RCB": {
2133
"series": "GD32F107",
2234
"flash": {
23-
"256": "GD32F107RCXX"
35+
"256": "GD32F107XCXX"
2436
}
2537
},
2638
"7RGC": {
2739
"series": "GD32F207",
2840
"flash": {
29-
"1024": "GD32F207RGXX"
41+
"1024": "GD32F207XGXX"
3042
}
3143
}
3244
}
@@ -36,7 +48,7 @@
3648
"7REE": {
3749
"series": "GD32F407",
3850
"flash": {
39-
"512": "GD32F407REXX"
51+
"512": "GD32F407XEXX"
4052
}
4153
},
4254
"9VIE": {

gd32_rdm_responder/.settings/language.settings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
66
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
77
<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"/>
8-
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1126052751785405339" 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">
8+
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1514013159566216975" 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">
99
<language-scope id="org.eclipse.cdt.core.gcc"/>
1010
<language-scope id="org.eclipse.cdt.core.g++"/>
1111
</provider>

lib-dmx/.settings/language.settings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
66
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
77
<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"/>
8-
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1502105672097326095" 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">
8+
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1502104592066291977" 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">
99
<language-scope id="org.eclipse.cdt.core.gcc"/>
1010
<language-scope id="org.eclipse.cdt.core.g++"/>
1111
</provider>

lib-dmx/include/gd32/dmx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class Dmx {
120120
uint32_t transmit_length_[dmx::config::max::kPorts];
121121
uint16_t transmit_slots_{dmx::kChannelsMax};
122122
dmx::Direction port_direction_[dmx::config::max::kPorts];
123-
bool has_continuos_output_{false};
123+
bool has_continuous_output_{false};
124124

125125
inline static Dmx* s_this;
126126
};

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/include/gd32/dmx_port.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @file dmx_port.h
3+
*
4+
*/
5+
6+
#ifndef GD32_DMX_PORT_H_
7+
#define GD32_DMX_PORT_H_
8+
9+
#include <cstdint>
10+
#include "gd32_uart.h"
11+
12+
namespace dmx::port {
13+
enum class Usage { kTxRx = 0, kTxOnly = 1, kRxOnly = 2 };
14+
15+
struct Info {
16+
gd32::Uart uart;
17+
uint32_t port;
18+
uint32_t pin;
19+
Usage usage;
20+
};
21+
} // namespace dmx::port
22+
23+
#endif // GD32_DMX_PORT_H_

0 commit comments

Comments
 (0)