Skip to content

Commit c037598

Browse files
committed
Integrate DMA checks into dmx_config.h
Consolidate and centralize GD32 DMA/port compile-time checks: remove lib-dmx/include/gd32/dmx_dma_check.h and move its static_asserts and DMA channel availability checks into common/include/dmx/dmx_config.h. Add buffer size static_asserts, clarify board error message, and enforce MCU-specific limits for DMX_MAX_PORTS and unavailable UART/DMA combinations. Also remove the now-unnecessary include from lib-dmx/src/gd32/dmx.cpp.
1 parent 0669e00 commit c037598

3 files changed

Lines changed: 49 additions & 70 deletions

File tree

common/include/dmx/dmx_config.h

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#ifndef DMX_DMX_CONFIG_H_
2-
#define DMX_DMX_CONFIG_H_
3-
41
/**
52
* @file dmx_config.h
63
*
@@ -26,6 +23,9 @@
2623
* THE SOFTWARE.
2724
*/
2825

26+
#ifndef DMX_DMX_CONFIG_H_
27+
#define DMX_DMX_CONFIG_H_
28+
2929
#include "gd32.h" // IWYU pragma: keep
3030

3131
#if defined(BOARD_GD32F103RC)
@@ -55,13 +55,56 @@
5555
#elif defined(BOARD_DMX4)
5656
#include "board_dmx4.h" // IWYU pragma: keep
5757
#else
58-
#error
58+
#error Board is not defined
5959
#endif
6060

6161
namespace dmx::buffer {
62-
static constexpr auto kSize = 516; // multiple of uint32_t
62+
static constexpr auto kSize = 516;
6363
} // namespace dmx::buffer
64+
static_assert(dmx::buffer::kSize >= 513); // 512 with Start Code
65+
static_assert(dmx::buffer::kSize % 4 == 0); // multiple of uint32_t
6466

65-
#include "gd32/dmx_dma_check.h" // IWYU pragma: keep
67+
// Maximum available USART check
68+
#if defined(GD32F10X_HD) || defined(GD32F10X_CL)
69+
static_assert(DMX_MAX_PORTS <= 4, "Too many ports defined");
70+
#endif
71+
#if defined(GD32F20X_CL)
72+
static_assert(DMX_MAX_PORTS <= 6, "Too many ports defined");
73+
#endif
74+
#if defined(GD32F30X_HD)
75+
static_assert(DMX_MAX_PORTS <= 5, "Too many ports defined");
76+
#endif
77+
78+
// DMA channel check
79+
#if defined(GD32F10X_HD) || defined(GD32F10X_CL)
80+
#if defined(DMX_USE_UART4)
81+
#error There is no DMA channel for UART4
82+
#endif
83+
#if defined(DMX_USE_USART5)
84+
#error USART5 is not available
85+
#endif
86+
#if defined(DMX_USE_UART6)
87+
#error UART6 is not available
88+
#endif
89+
#if defined(DMX_USE_UART7)
90+
#error UART7 is not available
91+
#endif
92+
#endif
93+
94+
#if defined(GD32F20X_CL)
95+
#if defined(DMX_USE_UART4) && defined(DMX_USE_UART7)
96+
#error DMA1 Channel 3
97+
#endif
98+
99+
#if defined(DMX_USE_UART3) && defined(DMX_USE_UART6)
100+
#error DMA1 Channel 4
101+
#endif
102+
#endif
103+
104+
#if defined(GD32F30X_HD)
105+
#if defined(DMX_USE_UART4)
106+
#error There is no DMA channel for UART4
107+
#endif
108+
#endif
66109

67110
#endif // DMX_DMX_CONFIG_H_

lib-dmx/include/gd32/dmx_dma_check.h

Lines changed: 0 additions & 63 deletions
This file was deleted.

lib-dmx/src/gd32/dmx.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
#include "gd32_uart.h"
5151
#include "gd32_gpio.h"
5252
#include "dmx_internal.h"
53-
#include "gd32/dmx_dma_check.h" // IWYU pragma: keep // Do not reorder/move
5453
#if defined(LOGIC_ANALYZER)
5554
#include "logic_analyzer.h" // IWYU pragma: keep
5655
#endif

0 commit comments

Comments
 (0)