Skip to content

Commit 8f46e56

Browse files
committed
Refactor DMX board headers and config
Standardize and modernize DMX headers and build includes: - Move board-specific constants into dmx::config namespace and nested max namespace; convert macro-like names to inline constexpr k*-style identifiers. - Replace gd32_board.h includes with gd32.h and mark them IWYU pragma: keep. - Update header guards/copyright years to 2026 and reformat header structure for consistency. - Tidy common/utils/utils_enum.h formatting (braces/newlines) and add minor style changes. - Change dmx buffer SIZE to kSize in namespace dmx::buffer. - Add a printf of the value in debug::PrintBits (function body formatting adjusted). - Add lib-hwclock include to common make Includes.mk. These changes are primarily refactors for namespacing, constexpr usage and include hygiene; functional behavior is intended to remain the same except for debug::PrintBits now printing the value prior to iterating bits.
1 parent 485065f commit 8f46e56

8 files changed

Lines changed: 110 additions & 110 deletions

File tree

common/include/common/utils/utils_enum.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,19 @@
3030

3131
namespace common
3232
{
33-
/// Converts an enum class value to its underlying integer type.
34-
template <typename Enum> constexpr auto ToValue(Enum e) noexcept -> std::underlying_type_t<Enum>
35-
{
33+
// Converts an enum class value to its underlying integer type.
34+
template <typename Enum>
35+
constexpr auto ToValue(Enum e) noexcept -> std::underlying_type_t<Enum> {
3636
static_assert(std::is_enum_v<Enum>);
3737
return static_cast<std::underlying_type_t<Enum>>(e);
3838
}
3939

40-
/// Converts an integer value to the corresponding enum class value.
41-
template <typename Enum> constexpr Enum FromValue(std::underlying_type_t<Enum> value) noexcept
42-
{
40+
// Converts an integer value to the corresponding enum class value.
41+
template <typename Enum>
42+
constexpr Enum FromValue(std::underlying_type_t<Enum> value) noexcept {
4343
static_assert(std::is_enum_v<Enum>);
4444
return static_cast<Enum>(value);
4545
}
46-
4746
} // namespace common
4847

4948
#endif // COMMON_UTILS_UTILS_ENUM_H_
Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
#ifndef DMX_BOARD_BW_OPIDMX4_H_
2-
#define DMX_BOARD_BW_OPIDMX4_H_
3-
41
/**
52
* @file board_bw_opidmx4.h
63
*
74
*/
8-
/* Copyright (C) 2022 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2022-2026 by Arjan van Vught mailto:info@gd32-dmx.org
96
*
107
* Permission is hereby granted, free of charge, to any person obtaining a copy
118
* of this software and associated documentation files (the "Software"), to deal
@@ -26,36 +23,40 @@
2623
* THE SOFTWARE.
2724
*/
2825

26+
#ifndef DMX_BOARD_BW_OPIDMX4_H_
27+
#define DMX_BOARD_BW_OPIDMX4_H_
28+
2929
#include <cstdint>
30-
#include "gd32_board.h"
30+
31+
#include "gd32.h" // IWYU pragma: keep
3132

3233
#define DMX_MAX_PORTS 4
3334

34-
namespace max
35-
{
36-
static constexpr uint32_t PORTS = DMX_MAX_PORTS;
35+
namespace dmx::config {
36+
namespace max {
37+
inline constexpr uint32_t kPorts = DMX_MAX_PORTS;
3738
} // namespace max
3839

3940
#define DMX_USE_USART0
4041
#define DMX_USE_USART2
4142
#define DMX_USE_UART4
4243
#define DMX_USE_USART5
4344

44-
static constexpr auto USART0_PORT = 3; // OPi One UART0
45-
static constexpr auto USART2_PORT = 2; // OPi One UART3
46-
static constexpr auto UART4_PORT = 0; // OPi One UART1 Pin 38 TX, Pin 40 RX
47-
static constexpr auto USART5_PORT = 1; // OPi One UART2
48-
49-
static constexpr auto DIR_PORT_0_GPIO_PORT = GPIOA; // OPi One UART1
50-
static constexpr auto DIR_PORT_0_GPIO_PIN = GPIO_PIN_4; // GPIO_EXT_32
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
5149

52-
static constexpr auto DIR_PORT_1_GPIO_PORT = GPIOA; // OPi One UART2
53-
static constexpr auto DIR_PORT_1_GPIO_PIN = GPIO_PIN_11; // GPIO_EXT_22
50+
inline constexpr auto kDirPort0GpioPort = GPIOA; // OPi One UART1
51+
inline constexpr auto kDirPort0GpioPin = GPIO_PIN_4; // GPIO_EXT_32
5452

55-
static constexpr auto DIR_PORT_2_GPIO_PORT = GPIOB; // OPi One UART3
56-
static constexpr auto DIR_PORT_2_GPIO_PIN = GPIO_PIN_10; // GPIO_EXT_12
53+
inline constexpr auto kDirPort1GpioPort = GPIOA; // OPi One UART2
54+
inline constexpr auto kDirPort1GpioPin = GPIO_PIN_11; // GPIO_EXT_22
5755

58-
static constexpr auto DIR_PORT_3_GPIO_PORT = GPIOA; // OPi One UART0
59-
static constexpr auto DIR_PORT_3_GPIO_PIN = GPIO_PIN_5; // GPIO_EXT_31
56+
inline constexpr auto kDirPort2GpioPort = GPIOB; // OPi One UART3
57+
inline constexpr auto kDirPort2GpioPin = GPIO_PIN_10; // GPIO_EXT_12
6058

61-
#endif // DMX_BOARD_BW_OPIDMX4_H_
59+
inline constexpr auto kDirPort3GpioPort = GPIOA; // OPi One UART0
60+
inline constexpr auto kDirPort3GpioPin = GPIO_PIN_5; // GPIO_EXT_31
61+
} // namespace dmx::config
62+
#endif // DMX_BOARD_BW_OPIDMX4_H_

common/include/dmx/board_dmx3.h

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
#ifndef DMX_BOARD_DMX3_H_
2-
#define DMX_BOARD_DMX3_H_
3-
41
/**
52
* @file board_dmx3.h
63
*
74
*/
8-
/* Copyright (C) 2023 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2023-2026 by Arjan van Vught mailto:info@gd32-dmx.org
96
*
107
* Permission is hereby granted, free of charge, to any person obtaining a copy
118
* of this software and associated documentation files (the "Software"), to deal
@@ -26,31 +23,35 @@
2623
* THE SOFTWARE.
2724
*/
2825

26+
#ifndef DMX_BOARD_DMX3_H_
27+
#define DMX_BOARD_DMX3_H_
28+
2929
#include <cstdint>
30-
#include "gd32_board.h"
30+
31+
#include "gd32.h" // IWYU pragma: keep
3132

3233
#define DMX_MAX_PORTS 3
3334

34-
namespace max
35-
{
36-
static constexpr uint32_t PORTS = DMX_MAX_PORTS;
35+
namespace dmx::config {
36+
namespace max {
37+
inline constexpr uint32_t kPorts = DMX_MAX_PORTS;
3738
} // namespace max
3839

3940
#define DMX_USE_USART2
4041
#define DMX_USE_UART4
4142
#define DMX_USE_USART5
4243

43-
static constexpr auto USART2_PORT = 0;
44-
static constexpr auto UART4_PORT = 1;
45-
static constexpr auto USART5_PORT = 2;
46-
47-
static constexpr auto DIR_PORT_0_GPIO_PORT = GPIOB;
48-
static constexpr auto DIR_PORT_0_GPIO_PIN = GPIO_PIN_10;
44+
inline constexpr auto kUsart2Port = 0;
45+
inline constexpr auto kUart4Port = 1;
46+
inline constexpr auto kUsart5Port = 2;
4947

50-
static constexpr auto DIR_PORT_1_GPIO_PORT = GPIOA;
51-
static constexpr auto DIR_PORT_1_GPIO_PIN = GPIO_PIN_5;
48+
inline constexpr auto kDirPort0GpioPort = GPIOB;
49+
inline constexpr auto kDirPort0GpioPin = GPIO_PIN_10;
5250

53-
static constexpr auto DIR_PORT_2_GPIO_PORT = GPIOB;
54-
static constexpr auto DIR_PORT_2_GPIO_PIN = GPIO_PIN_14;
51+
inline constexpr auto kDirPort1GpioPort = GPIOA;
52+
inline constexpr auto kDirPort1GpioPin = GPIO_PIN_5;
5553

56-
#endif // DMX_BOARD_DMX3_H_
54+
inline constexpr auto kDirPort2GpioPort = GPIOB;
55+
inline constexpr auto kDirPort2GpioPin = GPIO_PIN_14;
56+
} // namespace dmx::config
57+
#endif // DMX_BOARD_DMX3_H_

common/include/dmx/board_dmx4.h

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
#ifndef DMX_BOARD_DMX4_H_
2-
#define DMX_BOARD_DMX4_H_
3-
41
/**
52
* @file board_dmx4.h
63
*
74
*/
8-
/* Copyright (C) 2022 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2022-2026 by Arjan van Vught mailto:info@gd32-dmx.org
96
*
107
* Permission is hereby granted, free of charge, to any person obtaining a copy
118
* of this software and associated documentation files (the "Software"), to deal
@@ -26,36 +23,40 @@
2623
* THE SOFTWARE.
2724
*/
2825

26+
#ifndef DMX_BOARD_DMX4_H_
27+
#define DMX_BOARD_DMX4_H_
28+
2929
#include <cstdint>
30-
#include "gd32_board.h"
30+
31+
#include "gd32.h" // IWYU pragma: keep
3132

3233
#define DMX_MAX_PORTS 4
3334

34-
namespace max
35-
{
36-
static constexpr uint32_t PORTS = DMX_MAX_PORTS;
35+
namespace dmx::config {
36+
namespace max {
37+
inline constexpr uint32_t kPorts = DMX_MAX_PORTS;
3738
} // namespace max
3839

3940
#define DMX_USE_USART0
4041
#define DMX_USE_USART2
4142
#define DMX_USE_UART4
4243
#define DMX_USE_USART5
4344

44-
static constexpr auto USART0_PORT = 0;
45-
static constexpr auto USART2_PORT = 1;
46-
static constexpr auto UART4_PORT = 2;
47-
static constexpr auto USART5_PORT = 3;
48-
49-
static constexpr auto DIR_PORT_0_GPIO_PORT = GPIOA;
50-
static constexpr auto DIR_PORT_0_GPIO_PIN = GPIO_PIN_4;
45+
inline constexpr auto kUsart0Port = 0;
46+
inline constexpr auto kUsart2Port = 1;
47+
inline constexpr auto kUart4Port = 2;
48+
inline constexpr auto kUsart5Port = 3;
5149

52-
static constexpr auto DIR_PORT_1_GPIO_PORT = GPIOB;
53-
static constexpr auto DIR_PORT_1_GPIO_PIN = GPIO_PIN_10;
50+
inline constexpr auto kDirPort0GpioPort = GPIOA;
51+
inline constexpr auto kDirPort0GpioPin = GPIO_PIN_4;
5452

55-
static constexpr auto DIR_PORT_2_GPIO_PORT = GPIOA;
56-
static constexpr auto DIR_PORT_2_GPIO_PIN = GPIO_PIN_5;
53+
inline constexpr auto kDirPort1GpioPort = GPIOB;
54+
inline constexpr auto kDirPort1GpioPin = GPIO_PIN_10;
5755

58-
static constexpr auto DIR_PORT_3_GPIO_PORT = GPIOB;
59-
static constexpr auto DIR_PORT_3_GPIO_PIN = GPIO_PIN_14;
56+
inline constexpr auto kDirPort2GpioPort = GPIOA;
57+
inline constexpr auto kDirPort2GpioPin = GPIO_PIN_5;
6058

61-
#endif // DMX_BOARD_DMX4_H_
59+
inline constexpr auto kDirPort3GpioPort = GPIOB;
60+
inline constexpr auto kDirPort3GpioPin = GPIO_PIN_14;
61+
} // namespace dmx::config
62+
#endif // DMX_BOARD_DMX4_H_
Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
#ifndef DMX_BOARD_GD32F407RE_H_
2-
#define DMX_BOARD_GD32F407RE_H_
3-
41
/**
52
* @file board_gd32f407re.h
63
*
74
*/
8-
/* Copyright (C) 2022 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2022-2026 by Arjan van Vught mailto:info@gd32-dmx.org
96
*
107
* Permission is hereby granted, free of charge, to any person obtaining a copy
118
* of this software and associated documentation files (the "Software"), to deal
@@ -26,26 +23,30 @@
2623
* THE SOFTWARE.
2724
*/
2825

26+
#ifndef DMX_BOARD_GD32F407RE_H_
27+
#define DMX_BOARD_GD32F407RE_H_
28+
2929
#include <cstdint>
30-
#include "gd32_board.h"
30+
31+
#include "gd32.h" // IWYU pragma: keep
3132

3233
#define DMX_MAX_PORTS 2
3334

34-
namespace max
35-
{
36-
static constexpr uint32_t PORTS = DMX_MAX_PORTS;
35+
namespace dmx::config {
36+
namespace max {
37+
inline constexpr uint32_t kPorts = DMX_MAX_PORTS;
3738
} // namespace max
3839

3940
#define DMX_USE_USART2
4041
#define DMX_USE_USART5
4142

42-
static constexpr auto USART2_PORT = 0;
43-
static constexpr auto USART5_PORT = 1;
44-
45-
static constexpr auto DIR_PORT_0_GPIO_PORT = GPIOB;
46-
static constexpr auto DIR_PORT_0_GPIO_PIN = GPIO_PIN_10;
43+
inline constexpr auto kUsart2Port = 0;
44+
inline constexpr auto kUsart5Port = 1;
4745

48-
static constexpr auto DIR_PORT_1_GPIO_PORT = GPIOA;
49-
static constexpr auto DIR_PORT_1_GPIO_PIN = GPIO_PIN_11;
46+
inline constexpr auto kDirPort0GpioPort = GPIOB;
47+
inline constexpr auto kDirPort0GpioPin = GPIO_PIN_10;
5048

51-
#endif // DMX_BOARD_GD32F407RE_H_
49+
inline constexpr auto kDirPort1GpioPort = GPIOA;
50+
inline constexpr auto kDirPort1GpioPin = GPIO_PIN_11;
51+
} // namespace dmx::config
52+
#endif // DMX_BOARD_GD32F407RE_H_

common/include/dmx/dmx_config.h

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @file dmx_config.h
66
*
77
*/
8-
/* Copyright (C) 2021-2025 by Arjan van Vught mailto:info@gd32-dmx.org
8+
/* Copyright (C) 2021-2026 by Arjan van Vught mailto:info@gd32-dmx.org
99
*
1010
* Permission is hereby granted, free of charge, to any person obtaining a copy
1111
* of this software and associated documentation files (the "Software"), to deal
@@ -28,44 +28,40 @@
2828

2929
#include "gd32.h" // IWYU pragma: keep
3030

31-
namespace dmx::config
32-
{
3331
#if defined(BOARD_GD32F103RC)
34-
#include "board_gd32f103rc.h"
32+
#include "board_gd32f103rc.h" // IWYU pragma: keep
3533
#elif defined(BOARD_GD32F107RC)
36-
#include "board_gd32f107rc.h"
34+
#include "board_gd32f107rc.h" // IWYU pragma: keep
3735
#elif defined(BOARD_GD32F207RG)
38-
#include "board_gd32f207rg.h"
36+
#include "board_gd32f207rg.h" // IWYU pragma: keep
3937
#elif defined(BOARD_GD32F303RC)
40-
#include "board_gd32f303rc.h"
38+
#include "board_gd32f303rc.h" // IWYU pragma: keep
4139
#elif defined(BOARD_GD32F407RE)
42-
#include "board_gd32f407re.h"
40+
#include "board_gd32f407re.h" // IWYU pragma: keep
4341
#elif defined(BOARD_GD32F450VI)
44-
#include "board_gd32f450vi.h"
42+
#include "board_gd32f450vi.h" // IWYU pragma: keep
4543
#elif defined(BOARD_GD32H757ZM)
46-
#include "board_gd32h757zm.h"
44+
#include "board_gd32h757zm.h" // IWYU pragma: keep
4745
#elif defined(BOARD_GD32F470Z_EVAL)
48-
#include "board_gd32f470z_eval.h"
46+
#include "board_gd32f470z_eval.h" // IWYU pragma: keep
4947
#elif defined(BOARD_GD32F207C_EVAL)
50-
#include "board_gd32f207c_eval.h"
48+
#include "board_gd32f207c_eval.h" // IWYU pragma: keep
5149
#elif defined(BOARD_GD32H759I_EVAL)
52-
#include "board_gd32h759i_eval.h"
50+
#include "board_gd32h759i_eval.h" // IWYU pragma: keep
5351
#elif defined(BOARD_BW_OPIDMX4)
54-
#include "board_bw_opidmx4.h"
52+
#include "board_bw_opidmx4.h" // IWYU pragma: keep
5553
#elif defined(BOARD_DMX3)
56-
#include "board_dmx3.h"
54+
#include "board_dmx3.h" // IWYU pragma: keep
5755
#elif defined(BOARD_DMX4)
58-
#include "board_dmx4.h"
56+
#include "board_dmx4.h" // IWYU pragma: keep
5957
#else
6058
#error
6159
#endif
62-
} // namespace dmx::config
6360

64-
namespace dmx::buffer
65-
{
66-
static constexpr auto SIZE = 516; // multiple of uint32_t
61+
namespace dmx::buffer {
62+
static constexpr auto kSize = 516; // multiple of uint32_t
6763
} // namespace dmx::buffer
6864

69-
#include "gd32/dmx_dma_check.h"
65+
#include "gd32/dmx_dma_check.h" // IWYU pragma: keep
7066

71-
#endif // DMX_DMX_CONFIG_H_
67+
#endif // DMX_DMX_CONFIG_H_

common/include/firmware/debug/debug_printbits.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ namespace debug
4242
#ifdef NDEBUG
4343
inline void PrintBits([[maybe_unused]] uint32_t u) {}
4444
#else
45-
inline void PrintBits(uint32_t u)
46-
{
45+
inline void PrintBits(uint32_t u) {
46+
printf("%.8x ", u);
4747
uint32_t b = 1U << 31;
4848

4949
for (uint32_t i = 0; i < 32; i++)

common/make/gd32/Includes.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ INCLUDES+=-I../CMSIS/Core/Include
77
INCLUDES+=-I../lib-gd32/${FAMILY}/${FAMILY_UC}_standard_peripheral/Include
88
INCLUDES+=-I../lib-gd32/${FAMILY}/CMSIS/GD/${FAMILY_UC}/Include
99
INCLUDES+=-I../lib-gd32/include
10+
INCLUDES+=-I../lib-hwclock/include
1011
INCLUDES+=$(addprefix -I,$(EXTRA_INCLUDES))
1112

1213
ALL_FLAGS := $(DEFINES) $(MAKE_FLAGS)

0 commit comments

Comments
 (0)