Skip to content

Commit d890eed

Browse files
committed
Clean up GD32 header declarations
Standardize formatting across the GD32 public headers by adding explicit `#endif` comments, normalizing namespace and template layout, and marking required includes with IWYU pragmas. The shared `gd32.h` header is also trimmed by removing unused or duplicated helper declarations so the common interface stays smaller and easier to maintain.
1 parent 6a910c7 commit d890eed

23 files changed

Lines changed: 317 additions & 315 deletions

lib-gd32/include/board/gd32f103rc.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828

2929
#if !defined(BOARD_GD32F103RC)
3030
# error This file should not be included
31-
#endif
31+
#endif // BOARD_GD32F103RC
3232

3333
#if defined (MCU_GD32F10X_MCU_H_)
3434
# error This file should be included later
35-
#endif
35+
#endif // defined (MCU_GD32F10X_MCU_H_)
3636

3737
#include <stdint.h>
3838

@@ -142,7 +142,7 @@ inline constexpr uint32_t kTcnet = 0;
142142
static constexpr uint32_t kPortARx = 0;
143143
static constexpr uint32_t kPortATx = 0;
144144
} // namespace panelled
145-
#endif
145+
#endif // __cplusplus
146146

147147
/**
148148
* SPI flash
@@ -159,7 +159,7 @@ static constexpr uint32_t kPortATx = 0;
159159
#define GD32_MCU_NAME "GD32F103RC"
160160
#if !defined(GD32_BOARD_NAME)
161161
#define GD32_BOARD_NAME "GD32F103RC"
162-
#endif
162+
#endif // GD32_BOARD_NAME
163163

164164
#include "mcu/gd32f10x_mcu.h"
165165
#include "gd32_gpio.h"
@@ -197,4 +197,4 @@ static constexpr uint32_t kPortATx = 0;
197197

198198
#include "gpio_header.h"
199199

200-
#endif /* BOARD_GD32F103RC_H_ */
200+
#endif // BOARD_GD32F103RC_H_

lib-gd32/include/board/gd32f107rc.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828

2929
#if !defined(BOARD_GD32F107RC)
3030
# error This file should not be included
31-
#endif
31+
#endif // BOARD_GD32F107RC
3232

3333
#if defined (MCU_GD32F10X_MCU_H_)
3434
# error This file should be included later
35-
#endif
35+
#endif // defined (MCU_GD32F10X_MCU_H_)
3636

3737
#include <stdint.h>
3838

@@ -146,7 +146,7 @@ inline constexpr uint32_t kTcnet = 0;
146146
static constexpr uint32_t kPortARx = 0;
147147
static constexpr uint32_t kPortATx = 0;
148148
} // namespace panelled
149-
#endif
149+
#endif // __cplusplus
150150

151151
/**
152152
* SPI flash
@@ -180,7 +180,7 @@ static constexpr uint32_t kPortATx = 0;
180180
#define GD32_MCU_NAME "GD32F107RC"
181181
#if !defined(GD32_BOARD_NAME)
182182
#define GD32_BOARD_NAME "GD32F107RC"
183-
#endif
183+
#endif // GD32_BOARD_NAME
184184

185185
#include "mcu/gd32f10x_mcu.h"
186186
#include "gd32_gpio.h"
@@ -226,8 +226,8 @@ static constexpr uint32_t kPortATx = 0;
226226
#define SPI_LCD_BL_GPIO GPIO_EXT_22
227227
#if defined(SPI_LCD_HAVE_CS_GPIO)
228228
# define SPI_LCD_CS_GPIO GPIO_EXT_24
229-
#endif
229+
#endif // SPI_LCD_HAVE_CS_GPIO
230230

231231
#include "gpio_header.h"
232232

233-
#endif /* BOARD_GD32F107RC_H_ */
233+
#endif // BOARD_GD32F107RC_H_

lib-gd32/include/board/gpio_header.h

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file gpio_header.h
33
*
44
*/
5-
/* Copyright (C) 2021 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2021-2026 by Arjan van Vught mailto:info@gd32-dmx.org
66
*
77
* Permission is hereby granted, free of charge, to any person obtaining a copy
88
* of this software and associated documentation files (the "Software"), to deal
@@ -26,37 +26,37 @@
2626
#ifndef BOARD_GPIO_HEADER_H_
2727
#define BOARD_GPIO_HEADER_H_
2828

29-
/**
30-
* Below is for (backwards) compatibility with Orange Pi Zero board.
31-
*/
29+
// Below is for (backwards) compatibility with Orange Pi Zero board.
30+
31+
#define EXT_UART_NUMBER 2
32+
#define EXT_UART_BASE USART2
33+
#define EXT_MIDI_UART_BASE USART5
34+
35+
#include "gd32_gpio_macros.h"
36+
37+
using gpio_pin = enum GD32_BOARD_GPIO_HEADER {
38+
// 1 3V3
39+
GPIO_EXT_3 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTB, 7), ///< I2C0 SCA, PB7
40+
GPIO_EXT_5 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTB, 6), ///< I2C0 SDL, PB6
41+
GPIO_EXT_7 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTA, 6), ///< PA6
42+
GPIO_EXT_11 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTC, 7), ///< USART5 RX, PC7
43+
GPIO_EXT_13 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTC, 6), ///< USART5 TX, PC6
44+
GPIO_EXT_15 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTB, 14), ///< PB14
45+
// 17 3V3
46+
GPIO_EXT_19 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTB, 5), ///< SPI2 MOSI, PB5
47+
GPIO_EXT_21 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTB, 4), ///< SPI2 MISO, PB4
48+
GPIO_EXT_23 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTB, 3), ///< SPI2 SCLK, PB3
49+
// 2, 4 5V
50+
// 6 GND
51+
GPIO_EXT_8 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTC, 10), ///< USART2 TX, PC10
52+
GPIO_EXT_10 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTC, 11), ///< USART2 RX, PC11
53+
GPIO_EXT_12 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTB, 10), ///< PB10
54+
// 14 GND
55+
GPIO_EXT_16 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTB, 15), ///< PB15
56+
GPIO_EXT_18 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTA, 13), ///< PA13
57+
GPIO_EXT_22 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTA, 11), ///< PA11
58+
GPIO_EXT_24 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTA, 15), ///< SPI2 NSS, PA15
59+
GPIO_EXT_26 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTA, 14) ///< PA14
60+
};
3261

33-
#define EXT_UART_NUMBER 2
34-
#define EXT_UART_BASE USART2
35-
#define EXT_MIDI_UART_BASE USART5
36-
37-
typedef enum GD32_BOARD_GPIO_HEADER {
38-
// 1 3V3
39-
GPIO_EXT_3 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTB, 7), ///< I2C0 SCA, PB7
40-
GPIO_EXT_5 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTB, 6), ///< I2C0 SDL, PB6
41-
GPIO_EXT_7 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTA, 6), ///< PA6
42-
GPIO_EXT_11 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTC, 7), ///< USART5 RX, PC7
43-
GPIO_EXT_13 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTC, 6), ///< USART5 TX, PC6
44-
GPIO_EXT_15 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTB, 14), ///< PB14
45-
// 17 3V3
46-
GPIO_EXT_19 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTB, 5), ///< SPI2 MOSI, PB5
47-
GPIO_EXT_21 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTB, 4), ///< SPI2 MISO, PB4
48-
GPIO_EXT_23 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTB, 3), ///< SPI2 SCLK, PB3
49-
// 2, 4 5V
50-
// 6 GND
51-
GPIO_EXT_8 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTC, 10), ///< USART2 TX, PC10
52-
GPIO_EXT_10 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTC, 11), ///< USART2 RX, PC11
53-
GPIO_EXT_12 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTB, 10), ///< PB10
54-
// 14 GND
55-
GPIO_EXT_16 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTB, 15), ///< PB15
56-
GPIO_EXT_18 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTA, 13), ///< PA13
57-
GPIO_EXT_22 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTA, 11), ///< PA11
58-
GPIO_EXT_24 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTA, 15), ///< SPI2 NSS, PA15
59-
GPIO_EXT_26 = GD32_PORT_TO_GPIO(GD32_GPIO_PORTA, 14) ///< PA14
60-
} _gpio_pin;
61-
62-
#endif /* BOARD_GPIO_HEADER_H_ */
62+
#endif // BOARD_GPIO_HEADER_H_

lib-gd32/include/board/logic_analyzer.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@
2828

2929
// Do not use GPIOA_6, GPIOB_15
3030

31-
#define LOGIC_ANALYZER_CH0_GPIO_PINx GPIO_PIN_11
32-
#define LOGIC_ANALYZER_CH0_GPIOx GPIOA
33-
#define LOGIC_ANALYZER_CH0_RCU_GPIOx RCU_GPIOA
31+
#define LOGIC_ANALYZER_CH0_GPIO_PINx GPIO_PIN_8
32+
#define LOGIC_ANALYZER_CH0_GPIOx GPIOC
33+
#define LOGIC_ANALYZER_CH0_RCU_GPIOx RCU_GPIOC
3434

35-
#define LOGIC_ANALYZER_CH1_GPIO_PINx GPIO_PIN_4
36-
#define LOGIC_ANALYZER_CH1_GPIOx GPIOA
37-
#define LOGIC_ANALYZER_CH1_RCU_GPIOx RCU_GPIOA
35+
#define LOGIC_ANALYZER_CH1_GPIO_PINx GPIO_PIN_9
36+
#define LOGIC_ANALYZER_CH1_GPIOx GPIOC
37+
#define LOGIC_ANALYZER_CH1_RCU_GPIOx RCU_GPIOC
3838

39-
#define LOGIC_ANALYZER_CH2_GPIO_PINx GPIO_PIN_5
40-
#define LOGIC_ANALYZER_CH2_GPIOx GPIOA
41-
#define LOGIC_ANALYZER_CH2_RCU_GPIOx RCU_GPIOA
39+
#define LOGIC_ANALYZER_CH2_GPIO_PINx GPIO_PIN_13
40+
#define LOGIC_ANALYZER_CH2_GPIOx GPIOC
41+
#define LOGIC_ANALYZER_CH2_RCU_GPIOx RCU_GPIOC
4242

43-
#define LOGIC_ANALYZER_CH3_GPIO_PINx GPIO_PIN_13
43+
//#define LOGIC_ANALYZER_CH3_GPIO_PINx GPIO_PIN_13
4444
#define LOGIC_ANALYZER_CH3_GPIOx GPIOA
4545
#define LOGIC_ANALYZER_CH3_RCU_GPIOx RCU_GPIOA
4646

47-
#define LOGIC_ANALYZER_CH4_GPIO_PINx GPIO_PIN_15
47+
//#define LOGIC_ANALYZER_CH4_GPIO_PINx GPIO_PIN_15
4848
#define LOGIC_ANALYZER_CH4_GPIOx GPIOA
4949
#define LOGIC_ANALYZER_CH4_RCU_GPIOx RCU_GPIOA
5050

lib-gd32/include/gd32.h

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -26,69 +26,28 @@
2626
#ifndef GD32_H_
2727
#define GD32_H_
2828

29-
#include <stdint.h>
30-
31-
struct HwTimersSeconds {
32-
#if !defined(CONFIG_NET_ENABLE_PTP)
33-
volatile uint32_t timeval;
34-
#endif
35-
volatile uint32_t uptime;
36-
};
37-
3829
#include "gd32xxxx.h" // IWYU pragma: keep
3930

4031
#if defined(GD32F30X)
4132
#define bkp_data_write bkp_write_data
4233
#define bkp_data_read bkp_read_data
43-
#endif
34+
#endif // GD32F30X
4435

4536
#if (defined(GD32F4XX) || defined(GD32H7XX)) && defined(__cplusplus)
4637
typedef enum { BKP_DATA_0, BKP_DATA_1 } bkp_data_register_enum;
4738
void bkp_data_write(bkp_data_register_enum register_number, uint16_t data);
4839
uint16_t bkp_data_read(bkp_data_register_enum register_number);
49-
#endif
40+
#endif // (defined(GD32F4XX) || defined(GD32H7XX)) && defined(__cplusplus)
5041

5142
#if !(defined(GD32F4XX) || defined(GD32H7XX))
5243
#define GPIO_INIT
53-
#endif
44+
#endif // !(defined(GD32F4XX) || defined(GD32H7XX))
5445

5546
#if defined(GD32H7XX)
5647
#define GPIO_OSPEED GPIO_OSPEED_60MHZ
5748
#else
5849
#define GPIO_OSPEED GPIO_OSPEED_50MHZ
59-
#endif
60-
61-
#ifdef __cplusplus
62-
constexpr uint32_t Gd32PortToGpio(uint32_t port, uint32_t pin) {
63-
return (port * 16U) + pin;
64-
}
65-
66-
constexpr uint8_t Gd32GpioToPort(uint32_t gpio) {
67-
return static_cast<uint8_t>(gpio / 16U);
68-
}
69-
70-
constexpr uint8_t Gd32GpioToNumber(uint32_t gpio) {
71-
return static_cast<uint8_t>(gpio % 16U);
72-
}
73-
74-
#define GD32_PORT_TO_GPIO(p, n) Gd32PortToGpio((p), (n))
75-
#define GD32_GPIO_TO_PORT(g) Gd32GpioToPort((g))
76-
#define GD32_GPIO_TO_NUMBER(g) Gd32GpioToNumber((g))
77-
#endif
78-
79-
typedef enum T_GD32_Port {
80-
GD32_GPIO_PORTA = 0,
81-
GD32_GPIO_PORTB,
82-
GD32_GPIO_PORTC,
83-
GD32_GPIO_PORTD,
84-
GD32_GPIO_PORTE,
85-
GD32_GPIO_PORTF,
86-
GD32_GPIO_PORTG,
87-
GD32_GPIO_PORTH,
88-
GD32_GPIO_PORTI,
89-
GD32_GPIO_PORTJ,
90-
GD32_GPIO_PORTK
91-
} GD32_Port_TypeDef;
50+
#endif // GD32H7XX
9251

9352
#include "gd32_board.h" // IWYU pragma: keep
9453

lib-gd32/include/gd32_adc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ float G32AdcGetTemp();
3030
float Gd32AdcGetVref();
3131
#if defined(GD32F4XX)
3232
float Gd32AdcGetVbat();
33-
#endif
33+
#endif // GD32F4XX
3434

3535
#endif // GD32_ADC_H_

0 commit comments

Comments
 (0)