Skip to content

Commit 4a1e5e5

Browse files
committed
Add GD32H7 GPIO stub and tidy init code
Introduce a GD32H7-specific stub for Gd32GpioIntCfg (asserts false and marked [[maybe_unused]]) and invert the preprocessor branch so the existing interrupt configuration is used for other cores. Also apply non-functional formatting/clarity changes: split long template declarations across lines, convert several C-style block comments to // line comments, and perform minor whitespace cleanups in gd32_gpio_init. No behavioral changes for non-H7 targets.
1 parent dad3f8c commit 4a1e5e5

1 file changed

Lines changed: 27 additions & 20 deletions

File tree

lib-gd32/include/gd32_gpio.h

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ inline void Gd32GpioFsel(uint32_t gpio_periph, uint32_t pin, uint32_t fsel) {
124124
#endif
125125
}
126126

127-
#if !defined(GD32H7XX)
127+
#if defined(GD32H7XX)
128+
inline void Gd32GpioIntCfg([[maybe_unused]] uint32_t gpio, [[maybe_unused]] uint32_t trig_type) {
129+
assert(false && "Not implemented");
130+
}
131+
#else
128132
inline void Gd32GpioIntCfg(uint32_t gpio, uint32_t trig_type) {
129133
const uint32_t kLinex = BIT(GD32_GPIO_TO_NUMBER(gpio));
130134

@@ -244,7 +248,8 @@ inline void Gd32GpioSetPud(uint32_t gpio, uint32_t pud) {
244248
}
245249

246250
#if defined(GD32F4XX) || defined(GD32H7XX)
247-
template <uint32_t gpio_periph, uint32_t mode, uint32_t pull_up_down, uint32_t pin> inline void Gd32GpioModeSet() {
251+
template <uint32_t gpio_periph, uint32_t mode, uint32_t pull_up_down, uint32_t pin>
252+
inline void Gd32GpioModeSet() {
248253
static_assert(pin != 0, "pin cannot be zero");
249254
static_assert(pin == (1U << __builtin_ctz(pin)), "Only single pin values are allowed");
250255

@@ -267,7 +272,8 @@ template <uint32_t gpio_periph, uint32_t mode, uint32_t pull_up_down, uint32_t p
267272
GPIO_PUD(gpio_periph) = pupd;
268273
}
269274

270-
template <uint32_t gpio_periph, uint32_t alt_func_num, uint32_t pin> inline void Gd32GpioAfSet() {
275+
template <uint32_t gpio_periph, uint32_t alt_func_num, uint32_t pin>
276+
inline void Gd32GpioAfSet() {
271277
static_assert(pin != 0, "pin cannot be zero");
272278
static_assert(pin == (1U << __builtin_ctz(pin)), "Only single pin values are allowed");
273279

@@ -290,57 +296,58 @@ template <uint32_t gpio_periph, uint32_t alt_func_num, uint32_t pin> inline void
290296
GPIO_AFSEL1(gpio_periph) = afrh;
291297
}
292298
#else
293-
template <uint32_t gpio_periph, uint32_t mode, uint32_t pin, uint32_t speed = GPIO_OSPEED_50MHZ> inline void gd32_gpio_init() {
294-
/* GPIO mode configuration */
299+
template <uint32_t gpio_periph, uint32_t mode, uint32_t pin, uint32_t speed = GPIO_OSPEED_50MHZ>
300+
inline void gd32_gpio_init() {
301+
// GPIO mode configuration
295302
auto temp_mode = (mode & 0x0F);
296303

297-
/* GPIO speed configuration */
304+
// GPIO speed configuration
298305
if constexpr ((0x00U) != (mode & (0x10U))) {
299-
/* output mode max speed: 10MHz, 2MHz, 50MHz */
306+
// output mode max speed: 10MHz, 2MHz, 50MHz
300307
temp_mode |= speed;
301308
}
302309

303310
constexpr uint32_t kPinPos = 31U - __builtin_clz(pin);
304311

305312
if constexpr (kPinPos < 8U) {
306313
uint32_t reg = GPIO_CTL0(gpio_periph);
307-
/* clear the specified pin mode bits */
314+
// Clear the specified pin mode bits
308315
reg &= ~GPIO_MODE_MASK(kPinPos);
309-
/* set the specified pin mode bits */
316+
// Set the specified pin mode bits
310317
reg |= GPIO_MODE_SET(kPinPos, temp_mode);
311318

312-
/* set IPD or IPU */
319+
// Set IPD or IPU
313320
if constexpr (GPIO_MODE_IPD == mode) {
314-
/* reset the corresponding OCTL bit */
321+
// Reset the corresponding OCTL bit
315322
GPIO_BC(gpio_periph) = (1U << kPinPos);
316323
} else {
317-
/* set the corresponding OCTL bit */
324+
// Set the corresponding OCTL bit
318325
if constexpr (GPIO_MODE_IPU == mode) {
319326
GPIO_BOP(gpio_periph) = (1U << kPinPos);
320327
}
321328
}
322-
/* set GPIO_CTL0 register */
329+
// Set GPIO_CTL0 register */
323330
GPIO_CTL0(gpio_periph) = reg;
324331
} else {
325-
/* configure the eight high port pins with GPIO_CTL1 */
332+
// Configure the eight high port pins with GPIO_CTL1
326333
constexpr uint32_t kHighPinPos = kPinPos - 8U;
327334
uint32_t reg = GPIO_CTL1(gpio_periph);
328-
/* clear the specified pin mode bits */
335+
// Clear the specified pin mode bits */
329336
reg &= ~GPIO_MODE_MASK(kHighPinPos);
330-
/* set the specified pin mode bits */
337+
// Set the specified pin mode bits */
331338
reg |= GPIO_MODE_SET(kHighPinPos, temp_mode);
332339

333-
/* set IPD or IPU */
340+
// Set IPD or IPU
334341
if constexpr (GPIO_MODE_IPD == mode) {
335-
/* reset the corresponding OCTL bit */
342+
// Reset the corresponding OCTL bit
336343
GPIO_BC(gpio_periph) = (1U << kPinPos);
337344
} else {
338-
/* set the corresponding OCTL bit */
345+
// Set the corresponding OCTL bit
339346
if (GPIO_MODE_IPU == mode) {
340347
GPIO_BOP(gpio_periph) = (1U << kPinPos);
341348
}
342349
}
343-
/* set GPIO_CTL1 register */
350+
// set GPIO_CTL1 register
344351
GPIO_CTL1(gpio_periph) = reg;
345352
}
346353
}

0 commit comments

Comments
 (0)