Skip to content

Commit 9dd887f

Browse files
committed
Refactor DMX port config and UART API
Reworked GD32 DMX port handling to use a new `dmx::port::Info` definition with per-port UART metadata, usage flags (TX/RX/TXRX), compile-time UART uniqueness checks, and UART-to-port lookup in IRQ/DMA paths. This removes legacy `kUsartXPort`/`DmxPortToUart` mappings, updates direction/data flow logic for RX-only/TX-only cases, and fixes naming/constant cleanup (`has_continuous_output_`, E1.20 minimum length constants). Also migrated low-level UART helpers to `gd32::` (`UartBegin`, `UartFlagGet`, etc.), updated call sites, and refreshed GD32 identifier mappings in `gd32.json`.
1 parent 159be28 commit 9dd887f

14 files changed

Lines changed: 603 additions & 519 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_gd32f103rc.h

Lines changed: 2 additions & 3 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

@@ -38,9 +39,7 @@ inline constexpr uint32_t kPorts = DMX_MAX_PORTS;
3839
} // namespace max
3940

4041
#define DMX_USE_USART2
41-
inline constexpr auto kUsart2Port = 0;
4242

43-
inline constexpr auto kDirPort0GpioPort = GPIOB;
44-
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};
4544
} // namespace dmx::config
4645
#endif // DMX_BOARD_GD32F103RC_H_

common/include/dmx/board_gd32f107rc.h

Lines changed: 2 additions & 3 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

@@ -38,9 +39,7 @@ inline constexpr uint32_t kPorts = DMX_MAX_PORTS;
3839
} // namespace max
3940

4041
#define DMX_USE_USART2
41-
inline constexpr auto kUsart2Port = 0;
4242

43-
inline constexpr auto kDirPort0GpioPort = GPIOB;
44-
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};
4544
} // namespace dmx::config
4645
#endif // DMX_BOARD_GD32F107RC_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": {

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_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)