Skip to content

Commit 8e4024b

Browse files
committed
Refactor DMX port mapping and UART API
Reworked DMX board/driver configuration to use a unified `dmx::port::Info` model with UART-per-port mapping, compile-time uniqueness checks, and direct UART-to-port lookup in IRQ/DMA paths. The update also modernizes the GD32 UART layer into the `gd32` namespace (`Uart*` APIs), removes legacy port-to-UART macros, adds RDM E1.20 length constants, fixes a continuous-output typo, and updates GD32 identifier mappings in `gd32.json`.
1 parent 6fca482 commit 8e4024b

18 files changed

Lines changed: 625 additions & 599 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_bw_opidmx4.h

Lines changed: 5 additions & 16 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 4
3435

@@ -42,21 +43,9 @@ inline constexpr uint32_t kPorts = DMX_MAX_PORTS;
4243
#define DMX_USE_UART4
4344
#define DMX_USE_USART5
4445

45-
inline constexpr auto kUsart0Port = 3; // OPi One UART0
46-
inline constexpr auto kUsart2Port = 2; // OPi One UART3
47-
inline constexpr auto kUart4Port = 0; // OPi One UART1 Pin 38 TX, Pin 40 RX
48-
inline constexpr auto kUsart5Port = 1; // OPi One UART2
49-
50-
inline constexpr auto kDirPort0GpioPort = GPIOA; // OPi One UART1
51-
inline constexpr auto kDirPort0GpioPin = GPIO_PIN_4; // GPIO_EXT_32
52-
53-
inline constexpr auto kDirPort1GpioPort = GPIOA; // OPi One UART2
54-
inline constexpr auto kDirPort1GpioPin = GPIO_PIN_11; // GPIO_EXT_22
55-
56-
inline constexpr auto kDirPort2GpioPort = GPIOB; // OPi One UART3
57-
inline constexpr auto kDirPort2GpioPin = GPIO_PIN_10; // GPIO_EXT_12
58-
59-
inline constexpr auto kDirPort3GpioPort = GPIOA; // OPi One UART0
60-
inline constexpr auto kDirPort3GpioPin = GPIO_PIN_5; // GPIO_EXT_31
46+
inline constexpr port::Info kPort0 = {.uart = gd32::Uart::kUart4, .port = GPIOA, .pin = GPIO_PIN_4, .usage = port::Usage::kTxRx};
47+
inline constexpr port::Info kPort1 = {.uart = gd32::Uart::kUart5, .port = GPIOA, .pin = GPIO_PIN_11, .usage = port::Usage::kTxRx};
48+
inline constexpr port::Info kPort2 = {.uart = gd32::Uart::kUart2, .port = GPIOB, .pin = GPIO_PIN_10, .usage = port::Usage::kTxRx};
49+
inline constexpr port::Info kPort3 = {.uart = gd32::Uart::kUart0, .port = GPIOA, .pin = GPIO_PIN_5, .usage = port::Usage::kTxRx};
6150
} // namespace dmx::config
6251
#endif // DMX_BOARD_BW_OPIDMX4_H_

common/include/dmx/board_dmx3.h

Lines changed: 4 additions & 12 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 3
3435

@@ -41,17 +42,8 @@ inline constexpr uint32_t kPorts = DMX_MAX_PORTS;
4142
#define DMX_USE_UART4
4243
#define DMX_USE_USART5
4344

44-
inline constexpr auto kUsart2Port = 0;
45-
inline constexpr auto kUart4Port = 1;
46-
inline constexpr auto kUsart5Port = 2;
47-
48-
inline constexpr auto kDirPort0GpioPort = GPIOB;
49-
inline constexpr auto kDirPort0GpioPin = GPIO_PIN_10;
50-
51-
inline constexpr auto kDirPort1GpioPort = GPIOA;
52-
inline constexpr auto kDirPort1GpioPin = GPIO_PIN_5;
53-
54-
inline constexpr auto kDirPort2GpioPort = GPIOB;
55-
inline constexpr auto kDirPort2GpioPin = GPIO_PIN_14;
45+
inline constexpr port::Info kPort0 = {.uart = gd32::Uart::kUart2, .port = GPIOB, .pin = GPIO_PIN_10, .usage = port::Usage::kTxRx};
46+
inline constexpr port::Info kPort1 = {.uart = gd32::Uart::kUart4, .port = GPIOA, .pin = GPIO_PIN_5, .usage = port::Usage::kTxRx};
47+
inline constexpr port::Info kPort2 = {.uart = gd32::Uart::kUart5, .port = GPIOB, .pin = GPIO_PIN_14, .usage = port::Usage::kTxRx};
5648
} // namespace dmx::config
5749
#endif // DMX_BOARD_DMX3_H_

common/include/dmx/board_dmx4.h

Lines changed: 5 additions & 16 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 4
3435

@@ -42,21 +43,9 @@ inline constexpr uint32_t kPorts = DMX_MAX_PORTS;
4243
#define DMX_USE_UART4
4344
#define DMX_USE_USART5
4445

45-
inline constexpr auto kUsart0Port = 0;
46-
inline constexpr auto kUsart2Port = 1;
47-
inline constexpr auto kUart4Port = 2;
48-
inline constexpr auto kUsart5Port = 3;
49-
50-
inline constexpr auto kDirPort0GpioPort = GPIOA;
51-
inline constexpr auto kDirPort0GpioPin = GPIO_PIN_4;
52-
53-
inline constexpr auto kDirPort1GpioPort = GPIOB;
54-
inline constexpr auto kDirPort1GpioPin = GPIO_PIN_10;
55-
56-
inline constexpr auto kDirPort2GpioPort = GPIOA;
57-
inline constexpr auto kDirPort2GpioPin = GPIO_PIN_5;
58-
59-
inline constexpr auto kDirPort3GpioPort = GPIOB;
60-
inline constexpr auto kDirPort3GpioPin = GPIO_PIN_14;
46+
inline constexpr port::Info kPort0 = {.uart = gd32::Uart::kUart0, .port = GPIOA, .pin = GPIO_PIN_4, .usage = port::Usage::kTxRx};
47+
inline constexpr port::Info kPort1 = {.uart = gd32::Uart::kUart2, .port = GPIOB, .pin = GPIO_PIN_10, .usage = port::Usage::kTxRx};
48+
inline constexpr port::Info kPort2 = {.uart = gd32::Uart::kUart4, .port = GPIOA, .pin = GPIO_PIN_5, .usage = port::Usage::kTxRx};
49+
inline constexpr port::Info kPort3 = {.uart = gd32::Uart::kUart5, .port = GPIOB, .pin = GPIO_PIN_14, .usage = port::Usage::kTxRx};
6150
} // namespace dmx::config
6251
#endif // DMX_BOARD_DMX4_H_

common/include/dmx/board_gd32f207c_eval.h

Lines changed: 9 additions & 32 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 2
3435

@@ -46,37 +47,13 @@ inline constexpr uint32_t kPorts = DMX_MAX_PORTS;
4647
// #define DMX_USE_UART6
4748
// #define DMX_USE_UART7
4849

49-
// inline constexpr auto kUsart0Port = 0;
50-
inline constexpr auto kUsart1Port = 0;
51-
inline constexpr auto kUsart2Port = 1;
52-
// inline constexpr auto kUart3Port = 2;
53-
// inline constexpr auto kUart4Port = 3;
54-
// inline constexpr auto kUsart5Port = 5;
55-
// inline constexpr auto kUart6Port = 6;
56-
// inline constexpr auto kUart7Port = 7;
57-
58-
inline constexpr auto kDirPort0GpioPort = GPIOE;
59-
inline constexpr auto kDirPort0GpioPin = GPIO_PIN_9;
60-
61-
inline constexpr auto kDirPort1GpioPort = GPIOE;
62-
inline constexpr auto kDirPort1GpioPin = GPIO_PIN_10;
63-
64-
inline constexpr auto kDirPort2GpioPort = GPIOE;
65-
inline constexpr auto kDirPort2GpioPin = GPIO_PIN_11;
66-
67-
inline constexpr auto kDirPort3GpioPort = GPIOE;
68-
inline constexpr auto kDirPort3GpioPin = GPIO_PIN_12;
69-
70-
inline constexpr auto kDirPort4GpioPort = GPIOE;
71-
inline constexpr auto kDirPort4GpioPin = GPIO_PIN_13;
72-
73-
inline constexpr auto kDirPort5GpioPort = GPIOE;
74-
inline constexpr auto kDirPort5GpioPin = GPIO_PIN_14;
75-
76-
inline constexpr auto kDirPort6GpioPort = GPIOE;
77-
inline constexpr auto kDirPort6GpioPin = GPIO_PIN_15;
78-
79-
inline constexpr auto kDirPort7GpioPort = GPIOB;
80-
inline constexpr auto kDirPort7GpioPin = GPIO_PIN_15;
50+
inline constexpr port::Info kPort0 = {.uart = gd32::Uart::kUart1, .port = GPIOE, .pin = GPIO_PIN_9, .usage = port::Usage::kTxRx};
51+
inline constexpr port::Info kPort1 = {.uart = gd32::Uart::kUart2, .port = GPIOE, .pin = GPIO_PIN_10, .usage = port::Usage::kTxRx};
52+
inline constexpr port::Info kPort2 = {.uart = gd32::Uart::kUart0, .port = GPIOE, .pin = GPIO_PIN_11, .usage = port::Usage::kTxRx};
53+
inline constexpr port::Info kPort3 = {.uart = gd32::Uart::kUart3, .port = GPIOE, .pin = GPIO_PIN_12, .usage = port::Usage::kTxRx};
54+
inline constexpr port::Info kPort4 = {.uart = gd32::Uart::kUart4, .port = GPIOE, .pin = GPIO_PIN_13, .usage = port::Usage::kTxRx};
55+
inline constexpr port::Info kPort5 = {.uart = gd32::Uart::kUart5, .port = GPIOE, .pin = GPIO_PIN_14, .usage = port::Usage::kTxRx};
56+
inline constexpr port::Info kPort6 = {.uart = gd32::Uart::kUart6, .port = GPIOE, .pin = GPIO_PIN_15, .usage = port::Usage::kTxRx};
57+
inline constexpr port::Info kPort7 = {.uart = gd32::Uart::kUart7, .port = GPIOB, .pin = GPIO_PIN_15, .usage = port::Usage::kTxRx};
8158
} // namespace dmx::config
8259
#endif // DMX_BOARD_GD32F207C_EVAL_H_

common/include/dmx/board_gd32f207rg.h

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

@@ -40,13 +41,7 @@ inline constexpr uint32_t kPorts = DMX_MAX_PORTS;
4041
#define DMX_USE_USART2
4142
#define DMX_USE_USART5
4243

43-
inline constexpr auto kUsart2Port = 0;
44-
inline constexpr auto kUsart5Port = 1;
45-
46-
inline constexpr auto kDirPort0GpioPort = GPIOB;
47-
inline constexpr auto kDirPort0GpioPin = GPIO_PIN_10; // GPIO_EXT_12
48-
49-
inline constexpr auto kDirPort1GpioPort = GPIOA;
50-
inline constexpr auto kDirPort1GpioPin = GPIO_PIN_11; // GPIO_EXT_22
44+
inline constexpr port::Info kPort0 = {.uart = gd32::Uart::kUart2, .port = GPIOB, .pin = GPIO_PIN_10, .usage = port::Usage::kTxRx}; // GPIO_EXT_12
45+
inline constexpr port::Info kPort1 = {.uart = gd32::Uart::kUart5, .port = GPIOA, .pin = GPIO_PIN_11, .usage = port::Usage::kTxRx}; // GPIO_EXT_22
5146
} // namespace dmx::config
5247
#endif // DMX_BOARD_GD32F207RG_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)