Skip to content

Commit 266aabe

Browse files
committed
Refactor display/timing/watchdog APIs
Unify and modernize display and HAL code: replace udelay() calls with timing::DelayUs() and add timing includes; switch watchdog to watchdog::Init()/Feed() and include watchdog.h; rename hal::statusled enum values to k-prefixed variants and update display handling. Apply style/formatting cleanups (brace placement, indentation), modernize casts (reinterpret_cast/static_cast), make framebuffer static inline, tighten DrawLine to use signed ints, and update debug::Dump calls. Also bump copyright years and perform assorted small fixes in SPI/paint, SPI LCD, ST77xx drivers, HD44780 I2C, flashcode, and FMC operation sources.
1 parent 8f46e56 commit 266aabe

62 files changed

Lines changed: 1056 additions & 2974 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bootloader-tftp/firmware/main.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file main.cpp
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
@@ -27,7 +27,7 @@
2727
#include <cstdint>
2828

2929
#include "hal.h"
30-
#include "gd32/hal_watchdog.h"
30+
#include "watchdog.h"
3131
#include "network.h"
3232
#include "display.h"
3333
#include "hal_statusled.h"
@@ -38,13 +38,11 @@
3838
#include "configstore.h"
3939
#include "gd32.h"
4040

41-
namespace hal
42-
{
41+
namespace hal {
4342
void RebootHandler() {}
4443
} // namespace hal
4544

46-
int main()
47-
{
45+
int main() {
4846
rcu_periph_clock_enable(KEY_BOOTLOADER_TFTP_RCU_GPIOx);
4947
#if defined(GD32F4XX) || defined(GD32H7XX)
5048
rcu_periph_clock_enable(RCU_PMU);
@@ -57,10 +55,8 @@ int main()
5755
#else
5856
rcu_periph_clock_enable(RCU_AF);
5957
rcu_periph_clock_enable(KEY_BOOTLOADER_TFTP_RCU_GPIOx);
60-
if constexpr (KEY_BOOTLOADER_TFTP_GPIOx == GPIOA)
61-
{
62-
if constexpr ((KEY_BOOTLOADER_TFTP_GPIO_PINx == GPIO_PIN_13) || (KEY_BOOTLOADER_TFTP_GPIO_PINx == GPIO_PIN_14))
63-
{
58+
if constexpr (KEY_BOOTLOADER_TFTP_GPIOx == GPIOA) {
59+
if constexpr ((KEY_BOOTLOADER_TFTP_GPIO_PINx == GPIO_PIN_13) || (KEY_BOOTLOADER_TFTP_GPIO_PINx == GPIO_PIN_14)) {
6460
gpio_pin_remap_config(GPIO_SWJ_DISABLE_REMAP, ENABLE);
6561
}
6662
}
@@ -70,8 +66,7 @@ int main()
7066
const auto kIsNotRemote = (bkp_data_read(BKP_DATA_1) != 0xA5A5);
7167
const auto kIsNotKey = (gpio_input_bit_get(KEY_BOOTLOADER_TFTP_GPIOx, KEY_BOOTLOADER_TFTP_GPIO_PINx));
7268

73-
if (kIsNotRemote && kIsNotKey)
74-
{
69+
if (kIsNotRemote && kIsNotKey) {
7570
// https://developer.arm.com/documentation/ka001423/1-0
7671
// 1. Disable interrupt response.
7772
__disable_irq();
@@ -115,12 +110,11 @@ int main()
115110

116111
display.Printf(3, "Bootloader TFTP Srvr");
117112

118-
hal::statusled::SetMode(hal::statusled::Mode::FAST);
119-
hal::WatchdogInit();
113+
hal::statusled::SetMode(hal::statusled::Mode::kFast);
114+
watchdog::Init();
120115

121-
while (1)
122-
{
123-
hal::WatchdogFeed();
116+
while (1) {
117+
watchdog::Feed();
124118
network::Run();
125119
hal::Run();
126120
}

lib-display/include/displayhandler.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@ void DisplayStatusled(hal::statusled::Mode status_led_mode)
3838
char c;
3939
switch (status_led_mode)
4040
{
41-
case hal::statusled::Mode::OFF_OFF:
41+
case hal::statusled::Mode::kOffOff:
4242
c = 'O';
4343
break;
44-
case hal::statusled::Mode::OFF_ON:
44+
case hal::statusled::Mode::kOffOn:
4545
c = 'O';
4646
break;
47-
case hal::statusled::Mode::NORMAL:
47+
case hal::statusled::Mode::kNormal:
4848
c = 'N';
4949
break;
50-
case hal::statusled::Mode::DATA:
50+
case hal::statusled::Mode::kData:
5151
c = 'D';
5252
break;
53-
case hal::statusled::Mode::FAST:
53+
case hal::statusled::Mode::kFast:
5454
c = 'F';
5555
break;
56-
case hal::statusled::Mode::REBOOT:
56+
case hal::statusled::Mode::kReboot:
5757
c = 'R';
5858
break;
5959
default:

0 commit comments

Comments
 (0)