Skip to content

Commit ce0a785

Browse files
committed
Update display/spi headers, GD32 GPIO and utils
Refactors and platform additions across display and GPIO headers. - Replace constexpr static_assert in FromHex with a runtime assert to avoid unconditional compile-time failure. - Bump copyright years to 2026 in several display headers. - Reformat display namespace and Defaults struct for consistency. - Improve Display::PutString implementation to use a pointer-based loop. - Enhance SPI config: add RASPPI board GPIO mappings, normalize macro formatting, and provide safe default (0) pins when not specified; tidy SPI CS guards. - Include timing.h in st7789 and add minor header include reordering. - Add GD32H7XX stub for Gd32GpioIntCfg and various formatting/comment style cleanups in gd32_gpio.h; split long template lines for readability. These changes are mostly stylistic, safety fixes, and platform support additions to improve maintainability and RaspPi/ODROID support.
1 parent 621fcf7 commit ce0a785

6 files changed

Lines changed: 59 additions & 46 deletions

File tree

common/include/common/utils/utils_hex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ constexpr uint32_t FromHex(const char (&string)[N]) {
8585
for (size_t i = 0; i < N - 1; ++i) {
8686
const uint8_t kNibble = FromChar(string[i]);
8787
if constexpr (kNibble == 0xFF) {
88-
static_assert(false, "Invalid hex digit");
88+
assert(false && "Invalid hex digit");
8989
}
9090
result = (result << 4) | kNibble;
9191
}

lib-display/include/display.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file display.h
33
*
44
*/
5-
/* Copyright (C) 2022-2025 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2022-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
@@ -28,10 +28,8 @@
2828

2929
#include <cstdint>
3030

31-
namespace display
32-
{
33-
struct Defaults
34-
{
31+
namespace display {
32+
struct Defaults {
3533
static constexpr uint32_t kSleepTimeout = 5;
3634
};
3735
} // namespace display
@@ -51,4 +49,4 @@ struct Defaults
5149
#include STR(EXPAND(DISPLAY_USE_CUSTOM_INCLUDE)/custom/display.h)
5250
#endif
5351

54-
#endif // DISPLAY_H_
52+
#endif // DISPLAY_H_

lib-display/include/spi/config.h

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file config.h
33
*
44
*/
5-
/* Copyright (C) 2022-2025 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2022-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
@@ -47,21 +47,29 @@ inline constexpr uint32_t kHeight = 160;
4747
} // namespace config
4848

4949
#if defined(H3)
50-
#define SPI_LCD_RST_GPIO GPIO_EXT_7 // GPIO6
51-
#define SPI_LCD_DC_GPIO GPIO_EXT_26 // GPIO10
52-
#define SPI_LCD_BL_GPIO GPIO_EXT_22 // GPIO2
50+
#define SPI_LCD_RST_GPIO GPIO_EXT_7 // GPIO6
51+
#define SPI_LCD_DC_GPIO GPIO_EXT_26 // GPIO10
52+
#define SPI_LCD_BL_GPIO GPIO_EXT_22 // GPIO2
5353
#if defined(SPI_LCD_HAVE_CS_GPIO)
54-
#define SPI_LCD_CS_GPIO GPIO_EXT_24 // GPIO13 / SPI CS0
55-
#endif
54+
#define SPI_LCD_CS_GPIO GPIO_EXT_24 // GPIO13 / SPI CS0
55+
#endif // defined(SPI_LCD_HAVE_CS_GPIO)
5656
#elif defined(GD32) // See board file
57+
#elif defined(RASPPI)
58+
#include "gpio_rasppi.h"
59+
#define SPI_LCD_RST_GPIO GPIO_EXT_7 // GPIO4
60+
#define SPI_LCD_DC_GPIO GPIO_EXT_31 // GPIO6
61+
#define SPI_LCD_BL_GPIO GPIO_EXT_29 // GPIO5
62+
#if defined(SPI_LCD_HAVE_CS_GPIO)
63+
#define SPI_LCD_CS_GPIO GPIO_EXT_22 // GPIO25
64+
#endif // defined(SPI_LCD_HAVE_CS_GPIO)
65+
#elif defined(ODROID)
5766
#else
58-
#include "bcm2835.h"
59-
#define SPI_LCD_RST_GPIO RPI_V2_GPIO_P1_07 // GPIO4
60-
#define SPI_LCD_DC_GPIO RPI_V2_GPIO_P1_31 // GPIO6
61-
#define SPI_LCD_BL_GPIO RPI_V2_GPIO_P1_29 // GPIO5
67+
#define SPI_LCD_RST_GPIO 0
68+
#define SPI_LCD_DC_GPIO 0
69+
#define SPI_LCD_BL_GPIO 0
6270
#if defined(SPI_LCD_HAVE_CS_GPIO)
63-
#define SPI_LCD_CS_GPIO RPI_V2_GPIO_P1_24 // GPIO8 / SPI CS0
64-
#endif
71+
#define SPI_LCD_CS_GPIO 0
72+
#endif // defined(SPI_LCD_HAVE_CS_GPIO)
6573
#endif
6674

6775
#endif // SPI_CONFIG_H_

lib-display/include/spi/display.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,11 @@ class Display : public LcdDriver {
131131
}
132132
}
133133

134-
void PutString(const char* p) {
135-
for (uint32_t i = 0; *p != '\0'; i++) {
136-
PutChar(static_cast<int>(*p));
137-
p++;
138-
}
139-
}
134+
void PutString(const char* p) {
135+
while (*p != '\0') {
136+
PutChar(static_cast<int>(*p++));
137+
}
138+
}
140139

141140
void ClearLine(const uint32_t nLine) {
142141
if (__builtin_expect((!(nLine <= rows_)), 0)) {

lib-display/include/spi/st7789.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file st7789.h
33
*
44
*/
5-
/* Copyright (C) 2022-2025 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2022-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
@@ -31,6 +31,7 @@
3131

3232
#include "spi/config.h"
3333
#include "spi/st77xx.h"
34+
#include "timing.h"
3435
#include "firmware/debug/debug_debug.h"
3536

3637
namespace st7789 {

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)