Skip to content

Commit 18fc30d

Browse files
committed
Move GD32 MCU includes to gd32xxxx.h
Extracts the GD32/CMSIS conditional includes and compiler diagnostic handling from lib-gd32/include/gd32.h into a new header lib-gd32/include/gd32xxxx.h. gd32.h now simply includes gd32xxxx.h (IWYU keep). The new header adds a header guard, license, targeted GD32 family includes, GCC diagnostic pragmas and an #error for unsupported MCUs, centralizing MCU-specific logic and simplifying the original header.
1 parent 602f3b0 commit 18fc30d

2 files changed

Lines changed: 63 additions & 38 deletions

File tree

lib-gd32/include/gd32.h

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -35,44 +35,7 @@ struct HwTimersSeconds {
3535
volatile uint32_t uptime;
3636
};
3737

38-
/*
39-
* Needed for GD32 Firmware and CMSIS
40-
*/
41-
#ifdef __cplusplus
42-
#if !defined(__clang__)
43-
#pragma GCC diagnostic push
44-
#pragma GCC diagnostic ignored "-Wold-style-cast"
45-
#pragma GCC diagnostic ignored "-Wuseless-cast"
46-
#pragma GCC diagnostic ignored "-Wconversion"
47-
#pragma GCC diagnostic ignored "-Wsign-conversion"
48-
#if __cplusplus > 201402
49-
// error: compound assignment with 'volatile'-qualified left operand is deprecated
50-
#pragma GCC diagnostic ignored "-Wvolatile"
51-
#endif
52-
#endif
53-
extern "C" {
54-
#endif
55-
56-
#if defined(GD32F10X_HD) || defined(GD32F10X_CL)
57-
#include "gd32f10x.h" // IWYU pragma: keep
58-
#elif defined(GD32F20X_CL)
59-
#include "gd32f20x.h" // IWYU pragma: keep
60-
#elif defined(GD32F30X_HD)
61-
#include "gd32f30x.h" // IWYU pragma: keep
62-
#elif defined(GD32F407) || defined(GD32F450) || defined(GD32F470)
63-
#include "gd32f4xx.h" // IWYU pragma: keep
64-
#elif defined(GD32H757) || defined(GD32H759)
65-
#include "gd32h7xx.h" // IWYU pragma: keep
66-
#else
67-
#error MCU is not supported
68-
#endif
69-
70-
#ifdef __cplusplus
71-
}
72-
#if !defined(__clang__)
73-
#pragma GCC diagnostic pop
74-
#endif
75-
#endif
38+
#include "gd32xxxx.h" // IWYU pragma: keep
7639

7740
#if defined(GD32F30X)
7841
#define bkp_data_write bkp_write_data

lib-gd32/include/gd32xxxx.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* @file gd32xxxx.h
3+
*
4+
*/
5+
/* Copyright (C) 2026 by Arjan van Vught mailto:info@gd32-dmx.org
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
26+
#ifndef GD32FXXX_H_
27+
#define GD32FXXX_H_
28+
29+
// Needed for GD32 Firmware and CMSIS
30+
31+
#ifdef __cplusplus
32+
#pragma GCC diagnostic push
33+
#pragma GCC diagnostic ignored "-Wuseless-cast"
34+
#pragma GCC diagnostic ignored "-Wold-style-cast"
35+
#pragma GCC diagnostic ignored "-Wconversion"
36+
#pragma GCC diagnostic ignored "-Wsign-conversion"
37+
#if __cplusplus > 201402
38+
// error: compound assignment with 'volatile'-qualified left operand is
39+
// deprecated
40+
#pragma GCC diagnostic ignored "-Wvolatile"
41+
#endif
42+
#endif
43+
44+
#if defined(GD32F10X_HD) || defined(GD32F10X_CL)
45+
#include "gd32f10x.h" // IWYU pragma: keep
46+
#elif defined(GD32F20X_CL)
47+
#include "gd32f20x.h" // IWYU pragma: keep
48+
#elif defined(GD32F30X_HD)
49+
#include "gd32f30x.h" // IWYU pragma: keep
50+
#elif defined(GD32F407) || defined(GD32F450) || defined(GD32F470)
51+
#include "gd32f4xx.h" // IWYU pragma: keep
52+
#elif defined(GD32H757) || defined(GD32H759)
53+
#include "gd32h7xx.h" // IWYU pragma: keep
54+
#else
55+
#error MCU is not supported
56+
#endif
57+
58+
#ifdef __cplusplus
59+
#pragma GCC diagnostic pop
60+
#endif
61+
62+
#endif // GD32FXXX_H_ */

0 commit comments

Comments
 (0)