Skip to content

Commit 36c6eae

Browse files
committed
Refactor include guards and move debug utilities to headers
Standardized include guards across multiple header files, replacing #pragma once and correcting placement. Moved debug_dump and debug_print_bits implementations from .cpp files to new header files in common/include/firmware/debug/. Updated references to these debug utilities and to pixeldmx/show.h to match new include paths. Changed file permissions for consistency and performed minor code cleanups.
1 parent c0b76ca commit 36c6eae

215 files changed

Lines changed: 818 additions & 123 deletions

File tree

Some content is hidden

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

common/include/common/utils/utils_array.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#ifndef COMMON_UTILS_UTILS_ARRAY_H_
2-
#define COMMON_UTILS_UTILS_ARRAY_H_
3-
41
/**
52
* @file utils_array.h
63
*
@@ -26,6 +23,9 @@
2623
* THE SOFTWARE.
2724
*/
2825

26+
#ifndef COMMON_UTILS_UTILS_ARRAY_H_
27+
#define COMMON_UTILS_UTILS_ARRAY_H_
28+
2929
#include <cstddef>
3030

3131
namespace common

common/include/common/utils/utils_enum.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#ifndef COMMON_UTILS_UTILS_ENUM_H_
2-
#define COMMON_UTILS_UTILS_ENUM_H_
3-
41
/**
52
* @file utils_enum.h
63
*
@@ -26,6 +23,9 @@
2623
* THE SOFTWARE.
2724
*/
2825

26+
#ifndef COMMON_UTILS_UTILS_ENUM_H_
27+
#define COMMON_UTILS_UTILS_ENUM_H_
28+
2929
#include <type_traits>
3030

3131
namespace common

common/include/common/utils/utils_flags.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#ifndef COMMON_UTILS_UTILS_FLAGS_H_
2-
#define COMMON_UTILS_UTILS_FLAGS_H_
3-
41
/**
52
* @file utils_flags.h
63
* Generic enum class bitmask helpers (C++20, freestanding-safe, Google Style)
@@ -26,6 +23,9 @@
2623
* THE SOFTWARE.
2724
*/
2825

26+
#ifndef COMMON_UTILS_UTILS_FLAGS_H_
27+
#define COMMON_UTILS_UTILS_FLAGS_H_
28+
2929
#include <cstdint>
3030
#include <type_traits>
3131

common/include/common/utils/utils_hash.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#ifndef COMMON_UTILS_UTILS_HASH_H_
2-
#define COMMON_UTILS_UTILS_HASH_H_
3-
41
/**
52
* @file hash.h
63
*
@@ -26,6 +23,9 @@
2623
* THE SOFTWARE.
2724
*/
2825

26+
#ifndef COMMON_UTILS_UTILS_HASH_H_
27+
#define COMMON_UTILS_UTILS_HASH_H_
28+
2929
#include <cstdint>
3030

3131
// Compile-time FNV-1a 32-bit hash

common/include/common/utils/utils_hex.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#ifndef COMMON_UTILS_UTILS_HEX_H_
2-
#define COMMON_UTILS_UTILS_HEX_H_
3-
41
/**
52
* @file utils_hex.h
63
*
@@ -26,6 +23,9 @@
2623
* THE SOFTWARE.
2724
*/
2825

26+
#ifndef COMMON_UTILS_UTILS_HEX_H_
27+
#define COMMON_UTILS_UTILS_HEX_H_
28+
2929
#include <cstdint>
3030
#include <cstddef>
3131
#include <cassert>

lib-hal/debug/debug_dump.cpp renamed to common/include/firmware/debug/debug_dump.h

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @file debug_dump.cpp
2+
* @file debug_dump.h
33
*
44
*/
55
/* Copyright (C) 2018-2025 by Arjan van Vught mailto:info@gd32-dmx.org
@@ -23,21 +23,31 @@
2323
* THE SOFTWARE.
2424
*/
2525

26-
#include <cstdio>
26+
#ifndef COMMON_DEBUG_DEBUG_DUMP_H_
27+
#define COMMON_DEBUG_DEBUG_DUMP_H_
28+
2729
#include <cstdint>
30+
#include <cstdio>
2831
#include <ctype.h>
2932

3033
#if defined(H3)
3134
namespace uart0
3235
{
3336
int Printf(const char* fmt, ...);
3437
}
35-
#define printf uart0::Printf
38+
#define printf uart0::Printf // NOLINT
3639
#endif
3740

38-
static constexpr uint32_t kCharsPerLine = 16;
39-
40-
void debug_dump(const void* data, uint32_t size)
41+
namespace debug
42+
{
43+
namespace dump
44+
{
45+
inline constexpr uint32_t kCharsPerLine = 16;
46+
}
47+
#ifdef NDEBUG
48+
inline void Dump([[maybe_unused]] const void* data, [[maybe_unused]] uint32_t size) {}
49+
#else
50+
inline void Dump(const void* data, uint32_t size)
4151
{
4252
uint32_t chars = 0;
4353
const auto* p = reinterpret_cast<const uint8_t*>(data);
@@ -52,7 +62,7 @@ void debug_dump(const void* data, uint32_t size)
5262

5363
const auto* q = p;
5464

55-
while ((chars_this_line < kCharsPerLine) && (chars < size))
65+
while ((chars_this_line < dump::kCharsPerLine) && (chars < size))
5666
{
5767
if (chars_this_line % 8 == 0)
5868
{
@@ -68,7 +78,7 @@ void debug_dump(const void* data, uint32_t size)
6878

6979
auto chars_dot_line = chars_this_line;
7080

71-
for (; chars_this_line < kCharsPerLine; chars_this_line++)
81+
for (; chars_this_line < dump::kCharsPerLine; chars_this_line++)
7282
{
7383
if (chars_this_line % 8 == 0)
7484
{
@@ -104,3 +114,7 @@ void debug_dump(const void* data, uint32_t size)
104114

105115
} while (chars < size);
106116
}
117+
#endif
118+
} // namespace debug
119+
120+
#endif /* COMMON_DEBUG_DEBUG_DUMP_H_ */

lib-hal/debug/debug_print_bits.cpp renamed to common/include/firmware/debug/debug_printbits.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
2-
* @file debug_print_bits.cpp
2+
* @file debug_print_bits.h
33
*
44
*/
5-
/* Copyright (C) 2018-2025 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2025 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
@@ -23,6 +23,9 @@
2323
* THE SOFTWARE.
2424
*/
2525

26+
#ifndef COMMON_DEBUG_DEBUG_PRINTBITS_H_
27+
#define COMMON_DEBUG_DEBUG_PRINTBITS_H_
28+
2629
#include <cstdio>
2730
#include <cstdint>
2831

@@ -31,16 +34,19 @@ namespace uart0
3134
{
3235
int Printf(const char* fmt, ...);
3336
}
34-
#define printf uart0::Printf
37+
#define printf uart0::Printf // NOLINT
3538
#endif
3639

37-
void debug_print_bits(uint32_t u)
40+
namespace debug
41+
{
42+
#ifdef NDEBUG
43+
inline void PrintBits([[maybe_unused]] uint32_t u) {}
44+
#else
45+
inline void PrintBits(uint32_t u)
3846
{
39-
uint32_t i;
40-
4147
uint32_t b = 1U << 31;
4248

43-
for (i = 0; i < 32; i++)
49+
for (uint32_t i = 0; i < 32; i++)
4450
{
4551
if ((b & u) == b)
4652
{
@@ -52,3 +58,7 @@ void debug_print_bits(uint32_t u)
5258

5359
puts("");
5460
}
61+
#endif
62+
} // namespace debug
63+
64+
#endif /* COMMON_DEBUG_DEBUG_PRINTBITS_H_ */

common/include/common/firmware/jamstapl/handleroled.h renamed to common/include/firmware/jamstapl/handleroled.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#ifndef COMMON_FIRMWARE_JAMSTAPL_HANDLEROLED_H_
2-
#define COMMON_FIRMWARE_JAMSTAPL_HANDLEROLED_H_
3-
41
/**
52
* @file handleroled.h
63
*
@@ -26,6 +23,9 @@
2623
* THE SOFTWARE.
2724
*/
2825

26+
#ifndef COMMON_FIRMWARE_JAMSTAPL_HANDLEROLED_H_
27+
#define COMMON_FIRMWARE_JAMSTAPL_HANDLEROLED_H_
28+
2929
#include "jamstapl.h"
3030
#include "console.h"
3131
#include "display.h"

common/include/common/firmware/pixeldmx/show.h renamed to common/include/firmware/pixeldmx/show.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#ifndef COMMON_FIRMWARE_PIXELDMX_SHOW_H_
2-
#define COMMON_FIRMWARE_PIXELDMX_SHOW_H_
3-
41
/*
52
* display.h
63
*
@@ -26,6 +23,9 @@
2623
* THE SOFTWARE.
2724
*/
2825

26+
#ifndef COMMON_FIRMWARE_PIXELDMX_SHOW_H_
27+
#define COMMON_FIRMWARE_PIXELDMX_SHOW_H_
28+
2929
#include <cstdint>
3030

3131
#include "pixeldmxconfiguration.h"
@@ -53,4 +53,4 @@ inline void Show(uint32_t line, pixelpatterns::Pattern pattern = pixelpatterns::
5353
}
5454
} // namespace common::firmware::pixeldmx
5555

56-
#endif // COMMON_FIRMWARE_PIXELDMX_SHOW_H_
56+
#endif // COMMON_FIRMWARE_PIXELDMX_SHOW_H_

common/include/json/json_format_helpers.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#ifndef JSON_JSON_FORMAT_HELPERS_H_
2-
#define JSON_JSON_FORMAT_HELPERS_H_
3-
41
/**
52
* @file format_helpers.h
63
*
@@ -26,6 +23,9 @@
2623
* THE SOFTWARE.
2724
*/
2825

26+
#ifndef JSON_JSON_FORMAT_HELPERS_H_
27+
#define JSON_JSON_FORMAT_HELPERS_H_
28+
2929
#include <cstdio>
3030
#include <cstdint>
3131

0 commit comments

Comments
 (0)