Skip to content

Commit d434d6c

Browse files
authored
Header dependencies: separate helper pre-processor macros from utilities.h (speeduino#1360)
* Header dependencies: move helper pre-processor macros into their own header file. They are unrelated to utilities * Suppress SonarQube warnings
1 parent e4dfa5c commit d434d6c

File tree

14 files changed

+77
-39
lines changed

14 files changed

+77
-39
lines changed

speeduino/auxiliaries.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A full copy of the license may be found in the projects root directory
99
#include "src/PID_v1/PID_v1.h"
1010
#include "decoders.h"
1111
#include "timers.h"
12-
#include "utilities.h"
12+
#include "preprocessor.h"
1313
#include "units.h"
1414

1515
static long vvt1_pwm_value;

speeduino/comms_legacy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ A full copy of the license may be found in the projects root directory
1212
#include "comms_secondary.h"
1313
#include "storage.h"
1414
#include "maths.h"
15-
#include "utilities.h"
15+
#include "preprocessor.h"
1616
#include "decoders.h"
1717
#include "TS_CommandButtonHandler.h"
1818
#include "pages.h"

speeduino/comms_secondary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ sendcancommand is called when a command is to be sent either to serial3
2020
#include "comms_secondary.h"
2121
#include "comms_CAN.h"
2222
#include "maths.h"
23-
#include "utilities.h"
23+
#include "preprocessor.h"
2424
#include "comms_legacy.h"
2525
#include "logger.h"
2626
#include "page_crc.h"

speeduino/corrections.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ There are 2 top level functions that call more detailed corrections for Fuel and
2929
#include "maths.h"
3030
#include "sensors.h"
3131
#include "unit_testing.h"
32-
#include "utilities.h"
32+
#include "preprocessor.h"
3333
#include "src/PID_v1/PID_v1.h"
3434
#include "units.h"
3535
#include "fuel_calcs.h"

speeduino/engineProtection.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#include "globals.h"
22
#include "engineProtection.h"
33
#include "maths.h"
4-
#include "utilities.h"
54
#include "units.h"
6-
#include "crankMaths.h"
5+
#include "preprocessor.h"
76

87
byte oilProtStartTime = 0;
98
static table2D_u8_u8_4 oilPressureProtectTable(&configPage10.oilPressureProtRPM, &configPage10.oilPressureProtMins);

speeduino/idle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ A full copy of the license may be found in the projects root directory
66
#include "idle.h"
77
#include "maths.h"
88
#include "timers.h"
9-
#include "utilities.h"
9+
#include "preprocessor.h"
1010
#include "src/PID_v1/PID_v1.h"
1111
#include "units.h"
1212

speeduino/logger.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "init.h"
55
#include "maths.h"
66
#include "utilities.h"
7+
#include "preprocessor.h"
78
#include "units.h"
89
#include "board_definition.h"
910

speeduino/pages.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "pages.h"
22
#include "globals.h"
3-
#include "utilities.h"
3+
#include "preprocessor.h"
44

55
// Maps from virtual page "addresses" to addresses/bytes of real in memory entities
66
//

speeduino/preprocessor.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#pragma once
2+
3+
/** @file
4+
* This file contains various shared utility macros that make writing function
5+
* style macros easier.
6+
*/
7+
8+
#if !defined(UNUSED)
9+
/** @brief Used to suppress unused parameter compiler warnings */
10+
#define UNUSED(x) \
11+
(void)(x)
12+
#endif
13+
14+
/** @brief Compile time calculation of an array size */
15+
#if !defined(_countof)
16+
#define _countof(x) \
17+
(sizeof((x)) / sizeof ((x)[0]))
18+
#endif
19+
20+
/** @brief Obtain a pointer to 1 *element* past the end of an array */
21+
#if !defined(_end_range_address)
22+
#define _end_range_address(array) \
23+
((array) + _countof((array)))
24+
#endif
25+
26+
/** @brief Obtain a pointer to 1 *byte* past the end of an array */
27+
#if !defined(_end_range_byte_address)
28+
#define _end_range_byte_address(array) \
29+
(((byte*)(array)) + sizeof((array)))
30+
#endif
31+
32+
/** @brief Pre-processor arithmetic increment (pulled from Boost.Preprocessor) */
33+
#if !defined(PP_INC)
34+
#define PP_INC(x) \
35+
PP_INC_I(x)
36+
#endif
37+
38+
/// @cond
39+
// PP_INC() support macros
40+
#define PP_INC_I(x) PP_INC_ ## x
41+
#define PP_INC_0 1 // NOSONAR
42+
#define PP_INC_1 2 // NOSONAR
43+
#define PP_INC_2 3 // NOSONAR
44+
#define PP_INC_3 4 // NOSONAR
45+
#define PP_INC_4 5 // NOSONAR
46+
#define PP_INC_5 6 // NOSONAR
47+
#define PP_INC_6 7 // NOSONAR
48+
#define PP_INC_7 8 // NOSONAR
49+
#define PP_INC_8 9 // NOSONAR
50+
#define PP_INC_9 10 // NOSONAR
51+
#define PP_INC_10 11 // NOSONAR
52+
#define PP_INC_11 12 // NOSONAR
53+
#define PP_INC_12 13 // NOSONAR
54+
/// @endcond
55+
56+
/// @cond
57+
// CONCAT() support macros
58+
#define CAT_HELPER(a, b) a ## b
59+
/// @endcond
60+
61+
/** @brief Concatenate A & B *after* macro expansion */
62+
#if !defined(CONCAT)
63+
#define CONCAT(A, B) \
64+
CAT_HELPER(A, B)
65+
#endif

speeduino/scheduler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ A full copy of the license may be found in the projects root directory
2929
#include "scheduledIO.h"
3030
#include "timers.h"
3131
#include "schedule_calcs.h"
32-
#include "utilities.h"
32+
#include "preprocessor.h"
3333
#include "units.h"
3434

3535
FuelSchedule fuelSchedule1(FUEL1_COUNTER, FUEL1_COMPARE, FUEL1_TIMER_DISABLE, FUEL1_TIMER_ENABLE);

0 commit comments

Comments
 (0)