Skip to content

Commit b3a1b53

Browse files
committed
Refactor GD32 drivers and update headers
Wide-ranging refactor across lib-gd32 and lib-display: bump copyright years to 2026, add IWYU pragma: keep to gd32.h includes, and normalize brace/style/formatting. Key changes: - Add conditional display timeout IRQ stub when SOFTUART0 RX is used. - Refactor ENET helpers into gd32::enet and rename several functions for clarity (DescInformationGet, ClearDmaTxFlagsAndResume/HandleRxBufferUnavailable/ResetHash/FilterFeatureDisable/FilterFeatureEnable/FilterSetHash). - Expand and standardize DMA and UART macros/interrupt helpers (additional DMA interrupt flags/clear macros, USART helpers). - Adjust USART0 DMA/RCU macro definitions and UART GPIO config handling. - Rename lib-gd32/src/gd32_mac_address.cpp to macaddress.cpp and rename function to MacAddress. - Minor functional/style cleanups across PWM, SPI/I2S DMA, UART, BKP, softuart and timer sources. Most changes are non-functional cleanup, API consolidations and maintainability improvements.
1 parent eca8e44 commit b3a1b53

18 files changed

Lines changed: 596 additions & 580 deletions

File tree

lib-display/src/arm/gd32/display.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file display.cpp
33
*
44
*/
5-
/* Copyright (C) 2024-2025 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2024-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
@@ -27,32 +27,34 @@
2727
#undef NDEBUG
2828
#endif
2929

30-
#include "display.h"
30+
#include "firmware/debug/debug_debug.h"
31+
32+
#if defined(CONFIG_USE_SOFTUART0) && defined(SOFTUART0_ENABLE_RX)
33+
namespace display::timeout {
34+
void irq_init() {
35+
DEBUG_PUTS("Display timeout with IRQ disabled.");
36+
}
37+
} // namespace display::timeout
38+
#else // defined(CONFIG_USE_SOFTUART0) && defined(SOFTUART0_ENABLE_RX)
3139

40+
#include "display.h"
3241
#include "gd32.h"
3342
#include "gd32_gpio.h"
3443

35-
#include "firmware/debug/debug_debug.h"
36-
3744
#if defined(DISPLAYTIMEOUT_CONFIG_IRQ) && !defined(CONFIG_USE_EXTI10_15_IRQHandler)
38-
extern "C"
39-
{
40-
void DISPLAYTIMEOUT_IRQ_HANDLE()
41-
{
42-
if (RESET != exti_interrupt_flag_get(DISPLAYTIMEOUT_EXTI_LINE))
43-
{
44-
exti_interrupt_flag_clear(DISPLAYTIMEOUT_EXTI_LINE);
45-
Display::Get()->SetSleep(false);
46-
DEBUG_PUTS("Key pressed.");
47-
}
45+
extern "C" {
46+
void DISPLAYTIMEOUT_IRQ_HANDLE() {
47+
if (RESET != exti_interrupt_flag_get(DISPLAYTIMEOUT_EXTI_LINE)) {
48+
exti_interrupt_flag_clear(DISPLAYTIMEOUT_EXTI_LINE);
49+
Display::Get()->SetSleep(false);
50+
DEBUG_PUTS("Key pressed.");
4851
}
4952
}
53+
}
5054
#endif
5155

52-
namespace display::timeout
53-
{
54-
void irq_init()
55-
{
56+
namespace display::timeout {
57+
void irq_init() {
5658
#if defined(DISPLAYTIMEOUT_CONFIG_IRQ) && !defined(CONFIG_USE_EXTI10_15_IRQHandler)
5759
DEBUG_ENTRY();
5860

@@ -73,3 +75,4 @@ void irq_init()
7375
#endif
7476
}
7577
} // namespace display::timeout
78+
#endif // defined(CONFIG_USE_SOFTUART0) && defined(SOFTUART0_ENABLE_RX)

lib-gd32/device/enet/f/enet_gpio_config.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* EnetGpioConfig.cpp
33
*
44
*/
5-
/* Copyright (C) 2021-2025 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
@@ -27,16 +27,15 @@
2727
#undef NDEBUG
2828
#endif
2929

30-
#include "gd32.h"
30+
#include "gd32.h" // IWYU pragma: keep
3131
#include "firmware/debug/debug_debug.h"
3232

3333
// Needed for older GD32F firmware
3434
#if !defined(GPIO_OSPEED_MAX)
3535
#define GPIO_OSPEED_MAX GPIO_OSPEED_200MHZ
3636
#endif
3737

38-
void EnetGpioConfig()
39-
{
38+
void EnetGpioConfig() {
4039
DEBUG_ENTRY();
4140
#if defined(GD32F10X) || defined(GD32F20X)
4241
rcu_periph_clock_enable(RCU_GPIOA);

lib-gd32/device/enet/h/enet_gpio_config.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* EnetGpioConfig.cpp
33
*
44
*/
5-
/* Copyright (C) 2024-2025 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2024-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
@@ -27,13 +27,12 @@
2727
#undef NDEBUG
2828
#endif
2929

30-
#include "gd32.h"
30+
#include "gd32.h" // IWYU pragma: keep
3131
#include "firmware/debug/debug_debug.h"
3232

3333
#define RMII_MODE
3434

35-
void EnetGpioConfig()
36-
{
35+
void EnetGpioConfig() {
3736
DEBUG_ENTRY();
3837

3938
rcu_periph_clock_enable(RCU_GPIOA);

lib-gd32/device/enet/ptp/gd32_ptp.cpp

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
#include <time.h>
2929
#include <sys/time.h>
3030

31+
#include "gd32.h" // IWYU pragma: keep
3132
#include "gd32_ptp.h"
32-
#include "gd32.h"
3333
#include "firmware/debug/debug_debug.h"
3434

3535
void Error(const char*);
@@ -42,33 +42,28 @@ void Error(const char*);
4242
#define enet_ptp_timestamp_addend_config(x) enet_ptp_timestamp_addend_config(ENETx, x)
4343
#define enet_ptp_timestamp_update_config(x, y, z) enet_ptp_timestamp_update_config(ENETx, x, y, z)
4444
#define enet_ptp_system_time_get(x) enet_ptp_system_time_get(ENETx, x)
45-
static FlagStatus EnetPtpflagstatusGet(uint32_t flag)
46-
{
45+
static FlagStatus EnetPtpflagstatusGet(uint32_t flag) {
4746
FlagStatus bitstatus = RESET;
4847

49-
if (0 != (ENET_PTP_TSCTL(ENETx) & flag))
50-
{
48+
if (0 != (ENET_PTP_TSCTL(ENETx) & flag)) {
5149
bitstatus = SET;
5250
}
5351

5452
return bitstatus;
5553
}
5654
#else
57-
static FlagStatus EnetPtpflagstatusGet(uint32_t flag)
58-
{
55+
static FlagStatus EnetPtpflagstatusGet(uint32_t flag) {
5956
FlagStatus bitstatus = RESET;
6057

61-
if (0 != (ENET_PTP_TSCTL & flag))
62-
{
58+
if (0 != (ENET_PTP_TSCTL & flag)) {
6359
bitstatus = SET;
6460
}
6561

6662
return bitstatus;
6763
}
6864
#endif
6965

70-
static void PtpStart(uint32_t init_sec, uint32_t init_subsec, [[maybe_unused]] uint32_t carry_cfg, uint32_t accuracy_cfg)
71-
{
66+
static void PtpStart(uint32_t init_sec, uint32_t init_subsec, [[maybe_unused]] uint32_t carry_cfg, uint32_t accuracy_cfg) {
7267
DEBUG_ENTRY();
7368

7469
enet_interrupt_disable(ENET_MAC_INT_TMSTIM);
@@ -94,8 +89,7 @@ static void PtpStart(uint32_t init_sec, uint32_t init_subsec, [[maybe_unused]] u
9489
DEBUG_EXIT();
9590
}
9691

97-
void gd32_ptp_start()
98-
{
92+
void gd32_ptp_start() {
9993
DEBUG_ENTRY();
10094
DEBUG_PRINTF("PTP_TICK=%u", gd32::ptp::PTP_TICK);
10195
DEBUG_PRINTF("ADJ_FREQ_BASE_INCREMENT=%u", gd32::ptp::ADJ_FREQ_BASE_INCREMENT);
@@ -119,8 +113,7 @@ void gd32_ptp_start()
119113
DEBUG_EXIT();
120114
}
121115

122-
void gd32_ptp_get_time(gd32::ptp::ptptime* ptp_time)
123-
{
116+
void gd32_ptp_get_time(gd32::ptp::ptptime* ptp_time) {
124117
enet_ptp_systime_struct systime;
125118

126119
enet_ptp_system_time_get(&systime);
@@ -133,8 +126,7 @@ void gd32_ptp_get_time(gd32::ptp::ptptime* ptp_time)
133126
#endif
134127
}
135128

136-
void gd32_ptp_set_time(const gd32::ptp::ptptime* ptp_time)
137-
{
129+
void gd32_ptp_set_time(const gd32::ptp::ptptime* ptp_time) {
138130
const auto kSign = ENET_PTP_ADD_TO_TIME;
139131
const auto kSecond = ptp_time->tv_sec;
140132
const auto kNanoSecond = ptp_time->tv_nsec;
@@ -145,20 +137,16 @@ void gd32_ptp_set_time(const gd32::ptp::ptptime* ptp_time)
145137
while (EnetPtpflagstatusGet(ENET_PTP_SYSTIME_INIT) == SET);
146138
}
147139

148-
void gd32_ptp_update_time(const gd32::ptp::time_t* time)
149-
{
140+
void gd32_ptp_update_time(const gd32::ptp::time_t* time) {
150141
uint32_t sign;
151142
uint32_t second;
152143
uint32_t nano_second;
153144

154-
if (time->tv_sec < 0 || (time->tv_sec == 0 && time->tv_nsec < 0))
155-
{
145+
if (time->tv_sec < 0 || (time->tv_sec == 0 && time->tv_nsec < 0)) {
156146
sign = ENET_PTP_SUBSTRACT_FROM_TIME;
157147
second = -time->tv_sec;
158148
nano_second = -time->tv_nsec;
159-
}
160-
else
161-
{
149+
} else {
162150
sign = ENET_PTP_ADD_TO_TIME;
163151
second = time->tv_sec;
164152
nano_second = time->tv_nsec;
@@ -179,16 +167,14 @@ void gd32_ptp_update_time(const gd32::ptp::time_t* time)
179167
enet_ptp_timestamp_function_config(ENET_PTP_ADDEND_UPDATE);
180168
}
181169

182-
bool gd32_adj_frequency(int32_t adjust_ppb)
183-
{
170+
bool gd32_adj_frequency(int32_t adjust_ppb) {
184171
const uint32_t kAddend = gd32::ptp::ADJ_FREQ_BASE_ADDEND + static_cast<int32_t>((((static_cast<int64_t>(gd32::ptp::ADJ_FREQ_BASE_ADDEND)) * adjust_ppb) / 1000000000ULL));
185172

186173
enet_ptp_timestamp_addend_config(kAddend);
187174

188175
const auto kReval = enet_ptp_timestamp_function_config(ENET_PTP_ADDEND_UPDATE);
189176

190-
if (kReval == ERROR)
191-
{
177+
if (kReval == ERROR) {
192178
Error("enet_ptp_timestamp_addend_config\n");
193179
}
194180

0 commit comments

Comments
 (0)