From d20145c166a57b9b9b7e702ad4952d6ea3af5481 Mon Sep 17 00:00:00 2001 From: virskl Date: Mon, 16 Nov 2026 15:56:00 +0100 Subject: [PATCH 1/8] Mock: avr-libc's names in avr/, as the core has them PROGMEM and the reads from flash in avr/pgmspace.h, SREG in avr/io.h and cli() in avr/interrupt.h, which Arduino.h includes as the core's does. A file of the library can then include what it uses (F-5) and compile on the host and the board alike. --- test/mock/Arduino.h | 35 +++++------------------------------ test/mock/avr/interrupt.h | 15 +++++++++++++++ test/mock/avr/io.h | 14 ++++++++++++++ test/mock/avr/pgmspace.h | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 30 deletions(-) create mode 100644 test/mock/avr/interrupt.h create mode 100644 test/mock/avr/io.h create mode 100644 test/mock/avr/pgmspace.h diff --git a/test/mock/Arduino.h b/test/mock/Arduino.h index 5838e39..56ea23c 100644 --- a/test/mock/Arduino.h +++ b/test/mock/Arduino.h @@ -15,9 +15,11 @@ #ifndef MAXMATRIX_TEST_MOCK_ARDUINO_H_ #define MAXMATRIX_TEST_MOCK_ARDUINO_H_ +#include +#include +#include #include #include -#include #include #include @@ -25,38 +27,16 @@ #include "Max7219.h" #include "binary.h" -/* The names of the Arduino core and avr-libc, which the library calls by them. - */ +/* The names of the Arduino core, which the library calls by them; those of + * avr-libc are in avr/, which the core includes as this does. */ // NOLINTBEGIN(readability-identifier-naming) typedef uint8_t byte; -#define PROGMEM -#define memcpy_P memcpy -#define PSTR(text) (text) -#define strcmp_P strcmp /* F() has the type it has in the Arduino core, so that a function returning a * text in flash builds as on the board */ class __FlashStringHelper; // NOLINT(bugprone-reserved-identifier): the core's // name #define F(text) (reinterpret_cast<__FlashStringHelper const*>(PSTR(text))) -/* pgm_read_byte() reads the byte at address, as avr-libc reads it from flash, - * taking the address as it is given, as pgm_read_ptr() does */ -template -inline uint8_t pgm_read_byte(AddressType const* address) { - return *reinterpret_cast(address); -} -/* pgm_read_ptr() reads the bytes of the pointer at address, as avr-libc reads - * them from flash, and takes the address as it is given, as avr-libc's macro - * does. A macro that cast the stored pointer to void* made the library's cast - * back to its own type one through void, and a parameter of const void* a - * conversion of the address: clang-tidy reports both in the library, though - * neither is there on the board. */ -template -inline void* pgm_read_ptr(AddressType const* address) { - void* value; - memcpy(&value, address, sizeof(value)); - return value; -} #define HIGH 1 #define LOW 0 @@ -149,11 +129,6 @@ uint8_t digitalPinToPort(uint8_t pin); uint8_t digitalPinToBitMask(uint8_t pin); mock::PortRegister* portOutputRegister(uint8_t port); -/* the status register and cli(), which the library holds the interrupts off - * with while it writes a port: cli() clears the I bit, 0x80, which the library - * puts back by restoring SREG */ -extern uint8_t SREG; -inline void cli() { SREG &= 0x7FU; } // NOLINTEND(readability-identifier-naming) namespace mock { diff --git a/test/mock/avr/interrupt.h b/test/mock/avr/interrupt.h new file mode 100644 index 0000000..831e588 --- /dev/null +++ b/test/mock/avr/interrupt.h @@ -0,0 +1,15 @@ +// Copyright 2026 Andreas Burnickl +// SPDX-License-Identifier: GPL-3.0-or-later + +/* Stand-in for avr-libc's interrupts, see Arduino.h: cli(), which the library + * holds the interrupts off with while it writes a port. It clears the I bit of + * SREG, 0x80, which the library puts back by restoring SREG. */ +#ifndef MAXMATRIX_TEST_MOCK_AVR_INTERRUPT_H_ +#define MAXMATRIX_TEST_MOCK_AVR_INTERRUPT_H_ + +#include + +/* avr-libc's name, which the library calls. */ +inline void cli() { SREG &= 0x7FU; } // NOLINT(readability-identifier-naming) + +#endif // MAXMATRIX_TEST_MOCK_AVR_INTERRUPT_H_ diff --git a/test/mock/avr/io.h b/test/mock/avr/io.h new file mode 100644 index 0000000..d725a15 --- /dev/null +++ b/test/mock/avr/io.h @@ -0,0 +1,14 @@ +// Copyright 2026 Andreas Burnickl +// SPDX-License-Identifier: GPL-3.0-or-later + +/* Stand-in for avr-libc's registers, see Arduino.h: the status register alone, + * which the library saves and restores around a write to a port. */ +#ifndef MAXMATRIX_TEST_MOCK_AVR_IO_H_ +#define MAXMATRIX_TEST_MOCK_AVR_IO_H_ + +#include + +/* avr-libc's name, which the library uses. */ +extern uint8_t SREG; // NOLINT(readability-identifier-naming) + +#endif // MAXMATRIX_TEST_MOCK_AVR_IO_H_ diff --git a/test/mock/avr/pgmspace.h b/test/mock/avr/pgmspace.h new file mode 100644 index 0000000..4e6a75e --- /dev/null +++ b/test/mock/avr/pgmspace.h @@ -0,0 +1,38 @@ +// Copyright 2026 Andreas Burnickl +// SPDX-License-Identifier: GPL-3.0-or-later + +/* Stand-in for avr-libc's access to flash, see Arduino.h. The host has no + * separate flash: PROGMEM is nothing, and a read from flash is a read. */ +#ifndef MAXMATRIX_TEST_MOCK_AVR_PGMSPACE_H_ +#define MAXMATRIX_TEST_MOCK_AVR_PGMSPACE_H_ + +#include +#include + +/* The names of avr-libc, which the library calls by them. */ +// NOLINTBEGIN(readability-identifier-naming) +#define PROGMEM +#define memcpy_P memcpy +#define PSTR(text) (text) +#define strcmp_P strcmp +/* pgm_read_byte() reads the byte at address, as avr-libc reads it from flash, + * taking the address as it is given, as pgm_read_ptr() does */ +template +inline uint8_t pgm_read_byte(AddressType const* address) { + return *reinterpret_cast(address); +} +/* pgm_read_ptr() reads the bytes of the pointer at address, as avr-libc reads + * them from flash, and takes the address as it is given, as avr-libc's macro + * does. A macro that cast the stored pointer to void* made the library's cast + * back to its own type one through void, and a parameter of const void* a + * conversion of the address: clang-tidy reports both in the library, though + * neither is there on the board. */ +template +inline void* pgm_read_ptr(AddressType const* address) { + void* value; + memcpy(&value, address, sizeof(value)); + return value; +} +// NOLINTEND(readability-identifier-naming) + +#endif // MAXMATRIX_TEST_MOCK_AVR_PGMSPACE_H_ From f45753da8b1959ecd26b165b483f4cda0c210eb7 Mon Sep 17 00:00:00 2001 From: virskl Date: Mon, 16 Nov 2026 16:09:10 +0100 Subject: [PATCH 2/8] MaxMatrix.h exports the headers whose names a sketch uses A sketch includes MaxMatrix.h alone, and names ModuleType, Sprite, Byte, make_array() and the rest through it. // IWYU pragma: export says so to misc-include-cleaner (F-5), which would otherwise ask a sketch for Matrix/Panel.h or Utility/array.h. --- src/MaxMatrix.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/MaxMatrix.h b/src/MaxMatrix.h index 15219a1..ecc3d2b 100644 --- a/src/MaxMatrix.h +++ b/src/MaxMatrix.h @@ -18,19 +18,21 @@ #define MAXMATRIX_SRC_MAXMATRIX_H_ #include "Arduino.h" -#include "Command/Command.h" -#include "Font/Font.h" -#include "Matrix/Panel.h" -#include "Max7219/Chain.h" #include "MaxMatrixAttributes.h" -#include "MaxMatrixConfig.h" -#include "MaxMatrixError.h" -#include "MaxMatrixStandardTypes.h" #include "Text/Text.h" -#include "Utility/Byte.h" -#include "Utility/array.h" #include "Utility/reference_wrapper.h" -#include "Utility/span.h" + +// What a sketch names, it has through this header alone. +#include "Command/Command.h" // IWYU pragma: export +#include "Font/Font.h" // IWYU pragma: export +#include "Matrix/Panel.h" // IWYU pragma: export +#include "Max7219/Chain.h" // IWYU pragma: export +#include "MaxMatrixConfig.h" // IWYU pragma: export +#include "MaxMatrixError.h" // IWYU pragma: export +#include "MaxMatrixStandardTypes.h" // IWYU pragma: export +#include "Utility/Byte.h" // IWYU pragma: export +#include "Utility/array.h" // IWYU pragma: export +#include "Utility/span.h" // IWYU pragma: export namespace max_matrix { From eee903d081d00a9b257e432a4631712596051418 Mon Sep 17 00:00:00 2001 From: virskl Date: Mon, 16 Nov 2026 16:09:10 +0100 Subject: [PATCH 3/8] src/: every file includes what it uses (F-5) and rather than , which avr-gcc lacks; for PROGMEM and the reads from flash, and for SREG and cli(). MaxMatrixErrorReport.cpp includes MaxMatrixError.h only where it uses it, with MAXMATRIX_DEV_ERROR_DETECT, and keeps MaxMatrixConfig.h, whose switch the build may set with -D. --- src/Command/Command.cpp | 4 ++++ src/Font/Font.cpp | 7 +++++++ src/Matrix/Panel.cpp | 8 ++++++++ src/Matrix/Wired.cpp | 8 ++++++++ src/Max7219/Chain.cpp | 9 +++++++++ src/MaxMatrix.cpp | 2 ++ src/MaxMatrixError.cpp | 3 +++ src/MaxMatrixErrorReport.cpp | 8 ++++++-- src/Text/Text.cpp | 8 ++++++++ 9 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/Command/Command.cpp b/src/Command/Command.cpp index a214e54..ce8ee67 100644 --- a/src/Command/Command.cpp +++ b/src/Command/Command.cpp @@ -11,6 +11,10 @@ #include "Command.h" +#include +#include +#include + #include "MaxMatrix.h" #include "Utility/Bit.h" #include "Utility/Byte.h" diff --git a/src/Font/Font.cpp b/src/Font/Font.cpp index 20a0426..87a9ae6 100644 --- a/src/Font/Font.cpp +++ b/src/Font/Font.cpp @@ -11,8 +11,15 @@ #include "Font.h" +#include +#include +#include + #include "MaxMatrixConfig.h" +#include "MaxMatrixError.h" #include "Utility/Bit.h" +#include "Utility/array.h" +#include "Utility/span.h" namespace max_matrix { diff --git a/src/Matrix/Panel.cpp b/src/Matrix/Panel.cpp index 6c106e7..4bdd5b6 100644 --- a/src/Matrix/Panel.cpp +++ b/src/Matrix/Panel.cpp @@ -11,8 +11,16 @@ #include "Panel.h" +#include +#include +#include + +#include "MaxMatrixConfig.h" +#include "MaxMatrixError.h" #include "Utility/Bit.h" +#include "Utility/Byte.h" #include "Utility/array.h" +#include "Utility/span.h" namespace max_matrix { namespace internal { diff --git a/src/Matrix/Wired.cpp b/src/Matrix/Wired.cpp index f000f66..b08fdb1 100644 --- a/src/Matrix/Wired.cpp +++ b/src/Matrix/Wired.cpp @@ -12,6 +12,14 @@ #include "Wired.h" +#include +#include + +#include "Max7219/Chain.h" +#include "MaxMatrixConfig.h" +#include "Utility/Byte.h" +#include "Utility/span.h" + namespace max_matrix { namespace internal { diff --git a/src/Max7219/Chain.cpp b/src/Max7219/Chain.cpp index b899e4b..209cf43 100644 --- a/src/Max7219/Chain.cpp +++ b/src/Max7219/Chain.cpp @@ -13,6 +13,15 @@ */ #include "Chain.h" + +#include +#include +#include + +#include "MaxMatrixConfig.h" +#include "MaxMatrixStandardTypes.h" +#include "Utility/Byte.h" +#include "Utility/span.h" #if (MAXMATRIX_USE_SPI == STD_ON) #include "SPI.h" #endif diff --git a/src/MaxMatrix.cpp b/src/MaxMatrix.cpp index efa4db0..b134031 100644 --- a/src/MaxMatrix.cpp +++ b/src/MaxMatrix.cpp @@ -11,6 +11,8 @@ #include "MaxMatrix.h" +#include + namespace max_matrix { Matrix::Matrix(uint8_t data_in_pin, uint8_t chip_select_pin, uint8_t clock_pin, diff --git a/src/MaxMatrixError.cpp b/src/MaxMatrixError.cpp index 039e945..1ce0f1c 100644 --- a/src/MaxMatrixError.cpp +++ b/src/MaxMatrixError.cpp @@ -10,6 +10,9 @@ #include "MaxMatrixError.h" +#include +#include + #include "Utility/array.h" namespace max_matrix { diff --git a/src/MaxMatrixErrorReport.cpp b/src/MaxMatrixErrorReport.cpp index e33f039..021f25f 100644 --- a/src/MaxMatrixErrorReport.cpp +++ b/src/MaxMatrixErrorReport.cpp @@ -15,11 +15,15 @@ * calls PrintError(). */ +// MAXMATRIX_DEV_ERROR_DETECT, unless the build sets it with -D. +#include "MaxMatrixConfig.h" // IWYU pragma: keep +#include "MaxMatrixStandardTypes.h" + +#if (MAXMATRIX_DEV_ERROR_DETECT == STD_ON) #include "MaxMatrixError.h" namespace max_matrix { -#if (MAXMATRIX_DEV_ERROR_DETECT == STD_ON) __attribute__((weak)) void ReportError(__FlashStringHelper const* api, Error error) { PrintError(api, error); @@ -34,6 +38,6 @@ void PrintError(__FlashStringHelper const* api, Error error) { Serial.print(F(": ")); Serial.println(Status(error).GetErrorText()); } -#endif } // namespace max_matrix +#endif diff --git a/src/Text/Text.cpp b/src/Text/Text.cpp index fbd2dd0..893b067 100644 --- a/src/Text/Text.cpp +++ b/src/Text/Text.cpp @@ -10,7 +10,15 @@ #include "Text.h" +#include +#include + +#include "Font/Font.h" +#include "Matrix/Panel.h" +#include "MaxMatrixAttributes.h" +#include "MaxMatrixError.h" #include "Utility/Byte.h" +#include "Utility/span.h" namespace max_matrix { namespace internal { From fd15a624de9f04c08c387f8cb555242c0c606388 Mon Sep 17 00:00:00 2001 From: virskl Date: Mon, 16 Nov 2026 16:09:10 +0100 Subject: [PATCH 4/8] examples/: and where a sketch uses them (F-5) The rest of what a sketch names comes through MaxMatrix.h. --- examples/Animation/Animation.ino | 1 + examples/Band/Band.ino | 2 ++ examples/Basics/Basics.ino | 1 + examples/Messages/Messages.ino | 1 + examples/ScrollText/ScrollText.ino | 1 + examples/SerialControl/SerialControl.ino | 1 + examples/Shapes/Shapes.ino | 2 ++ examples/Sprites/Sprites.ino | 1 + 8 files changed, 10 insertions(+) diff --git a/examples/Animation/Animation.ino b/examples/Animation/Animation.ino index 172617b..3b7b878 100644 --- a/examples/Animation/Animation.ino +++ b/examples/Animation/Animation.ino @@ -12,6 +12,7 @@ * DIN -> 11, CS -> 10, CLK -> 13 */ #include +#include uint32_t const kStepIntervalMs{40}; diff --git a/examples/Band/Band.ino b/examples/Band/Band.ino index 16e0f60..bfd5786 100644 --- a/examples/Band/Band.ino +++ b/examples/Band/Band.ino @@ -13,6 +13,8 @@ * DIN -> 11, CS -> 10, CLK -> 13 */ #include +#include +#include uint32_t const kStepIntervalMs{60}; diff --git a/examples/Basics/Basics.ino b/examples/Basics/Basics.ino index 8c37ab5..418f443 100644 --- a/examples/Basics/Basics.ino +++ b/examples/Basics/Basics.ino @@ -11,6 +11,7 @@ * DIN -> 11, CS -> 10, CLK -> 13 */ #include +#include /* a chain of four modules, with the buffer for them; one of eight is * max_matrix::MatrixOf<8> */ diff --git a/examples/Messages/Messages.ino b/examples/Messages/Messages.ino index 25bae88..6e184f6 100644 --- a/examples/Messages/Messages.ino +++ b/examples/Messages/Messages.ino @@ -13,6 +13,7 @@ * DIN -> 11, CS -> 10, CLK -> 13 */ #include +#include /* a text must stay valid while it is shifted, so none of them is a local * variable; the blanks at the end let it leave the matrix before the next one diff --git a/examples/ScrollText/ScrollText.ino b/examples/ScrollText/ScrollText.ino index f449f86..f4d8b8c 100644 --- a/examples/ScrollText/ScrollText.ino +++ b/examples/ScrollText/ScrollText.ino @@ -14,6 +14,7 @@ * is max_matrix::MatrixOf<8>. */ #include +#include uint8_t const kDataInPin{11}; uint8_t const kChipSelectPin{10}; diff --git a/examples/SerialControl/SerialControl.ino b/examples/SerialControl/SerialControl.ino index 1542cba..38f9382 100644 --- a/examples/SerialControl/SerialControl.ino +++ b/examples/SerialControl/SerialControl.ino @@ -26,6 +26,7 @@ * DIN -> 11, CS -> 10, CLK -> 13 */ #include +#include uint8_t const kDataInPin{11}; uint8_t const kChipSelectPin{10}; diff --git a/examples/Shapes/Shapes.ino b/examples/Shapes/Shapes.ino index b0c04cf..cff15f4 100644 --- a/examples/Shapes/Shapes.ino +++ b/examples/Shapes/Shapes.ino @@ -12,6 +12,8 @@ * DIN -> 11, CS -> 10, CLK -> 13 */ #include +#include +#include uint32_t const kShowMs{1000}; uint8_t const kNumberOfShapes{4}; diff --git a/examples/Sprites/Sprites.ino b/examples/Sprites/Sprites.ino index 3573b42..b8e2b29 100644 --- a/examples/Sprites/Sprites.ino +++ b/examples/Sprites/Sprites.ino @@ -15,6 +15,7 @@ * DIN -> 11, CS -> 10, CLK -> 13 */ #include +#include uint16_t const kStepDelayMs{100}; int16_t const kSpriteY{2}; From 734634af4cf847bb452f5e38926f9d4f77698a5e Mon Sep 17 00:00:00 2001 From: virskl Date: Mon, 16 Nov 2026 16:09:10 +0100 Subject: [PATCH 5/8] test/: every file includes what it uses (F-5) MaxMatrixTestSupport.h exports MaxMatrix.h, so that a test reaches the library through it alone: one that included Font/Font.h itself would have it sorted before #define private public. The headers of GoogleTest, the mock and the model each test includes itself. and went where nothing used them: htons() comes with . --- test/Command/CommandTest.cpp | 4 ++++ test/ControlCommandTest.cpp | 2 ++ test/ControlLinkTest.cpp | 2 ++ test/ControlPortTest.cpp | 6 +++++- test/Font/FontTest.cpp | 6 ++++++ test/Matrix/PanelTest.cpp | 7 +++++++ test/Matrix/WiredTest.cpp | 6 ++++++ test/Max7219/ChainTest.cpp | 3 +++ test/Max7219Test.cpp | 1 + test/MaxMatrixChainLengthTest.cpp | 4 ++++ test/MaxMatrixErrorReportTest.cpp | 2 ++ test/MaxMatrixErrorTest.cpp | 4 ++++ test/MaxMatrixTest.cpp | 5 +++++ test/MaxMatrixTestSupport.cpp | 13 ++++++++++--- test/MaxMatrixTestSupport.h | 2 +- test/SimulatorSerialHostTest.cpp | 4 +++- test/SimulatorTest.cpp | 3 +++ test/SimulatorWebHostTest.cpp | 2 +- test/SimulatorWebSocketTest.cpp | 3 +++ test/Text/TextTest.cpp | 5 +++++ test/model/Max7219.cpp | 1 + 21 files changed, 78 insertions(+), 7 deletions(-) diff --git a/test/Command/CommandTest.cpp b/test/Command/CommandTest.cpp index 7b21a7b..4c00d02 100644 --- a/test/Command/CommandTest.cpp +++ b/test/Command/CommandTest.cpp @@ -3,6 +3,10 @@ /* The lines a control page or program sends, carried out on a matrix. */ +#include +#include +#include + #include #include #include diff --git a/test/ControlCommandTest.cpp b/test/ControlCommandTest.cpp index 08966ce..f5218f7 100644 --- a/test/ControlCommandTest.cpp +++ b/test/ControlCommandTest.cpp @@ -6,6 +6,8 @@ #include "ControlCommand.h" #include +#include +#include #include #include diff --git a/test/ControlLinkTest.cpp b/test/ControlLinkTest.cpp index 523446a..70a10e9 100644 --- a/test/ControlLinkTest.cpp +++ b/test/ControlLinkTest.cpp @@ -6,11 +6,13 @@ #include "ControlLink.h" #include +#include #include #include #include "ControlCommand.h" +#include "ControlPort.h" #include "MaxMatrixAttributes.h" namespace { diff --git a/test/ControlPortTest.cpp b/test/ControlPortTest.cpp index 8cd698e..a86a637 100644 --- a/test/ControlPortTest.cpp +++ b/test/ControlPortTest.cpp @@ -4,10 +4,14 @@ /* Tests of the control program's ports: the serial port against a pseudo * terminal, which stands in for a board_'s port as the kernel gives it to a * program, and the TCP port against the simulator's serial host on loopback. */ -#include +#include "ControlPort.h" + #include #include #include +#include +#include +#include #include #include diff --git a/test/Font/FontTest.cpp b/test/Font/FontTest.cpp index 9a73de3..7a2357f 100644 --- a/test/Font/FontTest.cpp +++ b/test/Font/FontTest.cpp @@ -4,6 +4,12 @@ /* Fonts: the chars beyond ASCII and how a text reaches them, the default * font, and a font of a sketch's own. */ +#include +#include +#include +#include +#include + #include #include #include diff --git a/test/Matrix/PanelTest.cpp b/test/Matrix/PanelTest.cpp index c9f74e0..b26374a 100644 --- a/test/Matrix/PanelTest.cpp +++ b/test/Matrix/PanelTest.cpp @@ -4,6 +4,11 @@ /* The panel as the viewer sees it: every matrix orientation and module type, * dots, rows, columns and shifts, and the shapes drawn on it. */ +#include +#include +#include +#include + #include #include #include @@ -12,6 +17,8 @@ #include #include +#include "Arduino.h" +#include "Max7219.h" #include "MaxMatrixTestSupport.h" #include "Utility/Bit.h" diff --git a/test/Matrix/WiredTest.cpp b/test/Matrix/WiredTest.cpp index 79f45be..29e2b0c 100644 --- a/test/Matrix/WiredTest.cpp +++ b/test/Matrix/WiredTest.cpp @@ -3,8 +3,14 @@ /* The buffer as wired: which columns go out, and when nothing has to. */ +#include +#include +#include + #include +#include "Arduino.h" +#include "Max7219.h" #include "MaxMatrixTestSupport.h" /* a changed column of a module goes out in one frame with the same column of diff --git a/test/Max7219/ChainTest.cpp b/test/Max7219/ChainTest.cpp index 8179348..ba4608b 100644 --- a/test/Max7219/ChainTest.cpp +++ b/test/Max7219/ChainTest.cpp @@ -3,6 +3,9 @@ /* The transfer to the chain: every bit within a frame. */ +#include + +#include "Arduino.h" #include "MaxMatrixTestSupport.h" using max_matrix::ModuleType; diff --git a/test/Max7219Test.cpp b/test/Max7219Test.cpp index e1045fb..49b0ca3 100644 --- a/test/Max7219Test.cpp +++ b/test/Max7219Test.cpp @@ -9,6 +9,7 @@ #include "Max7219.h" #include +#include #include #include diff --git a/test/MaxMatrixChainLengthTest.cpp b/test/MaxMatrixChainLengthTest.cpp index cafdeab..ad871b6 100644 --- a/test/MaxMatrixChainLengthTest.cpp +++ b/test/MaxMatrixChainLengthTest.cpp @@ -3,11 +3,15 @@ /* Chains of other lengths than the examples'. */ +#include +#include + #include #include #include #include +#include "Arduino.h" #include "MaxMatrixAttributes.h" #include "MaxMatrixTestSupport.h" diff --git a/test/MaxMatrixErrorReportTest.cpp b/test/MaxMatrixErrorReportTest.cpp index 92963bb..588423e 100644 --- a/test/MaxMatrixErrorReportTest.cpp +++ b/test/MaxMatrixErrorReportTest.cpp @@ -6,7 +6,9 @@ * define the report themselves to record it. */ #include +#include +#include "Arduino.h" #include "MaxMatrix.h" using max_matrix::Error; diff --git a/test/MaxMatrixErrorTest.cpp b/test/MaxMatrixErrorTest.cpp index b1e2017..3470f64 100644 --- a/test/MaxMatrixErrorTest.cpp +++ b/test/MaxMatrixErrorTest.cpp @@ -4,10 +4,14 @@ /* Errors: every way a call can fail, that it changes nothing, and what the * report and the texts say. */ +#include +#include + #include #include #include +#include "Arduino.h" #include "MaxMatrixTestSupport.h" using max_matrix::Command; diff --git a/test/MaxMatrixTest.cpp b/test/MaxMatrixTest.cpp index e1781ab..90975ea 100644 --- a/test/MaxMatrixTest.cpp +++ b/test/MaxMatrixTest.cpp @@ -4,8 +4,13 @@ /* The facade: what Init() sets, sending at once or in a batch, the pace of a * shifting text, and the settings of the MAX7219. */ +#include +#include + #include +#include "Arduino.h" +#include "Max7219.h" #include "MaxMatrixTestSupport.h" using max_matrix::Batch; diff --git a/test/MaxMatrixTestSupport.cpp b/test/MaxMatrixTestSupport.cpp index b994f2f..2b2b348 100644 --- a/test/MaxMatrixTestSupport.cpp +++ b/test/MaxMatrixTestSupport.cpp @@ -4,15 +4,22 @@ /* What the tests share, defined once: see MaxMatrixTestSupport.h. */ #include "MaxMatrixTestSupport.h" +#include +#include + +#include +#include +#include + +#include "Arduino.h" +#include "Max7219.h" + using max_matrix::CommandState; using max_matrix::Error; using max_matrix::Matrix; using max_matrix::ModuleType; using max_matrix::Result; -#include -#include - namespace max_matrix { void PrintTo(Error error, std::ostream* out) { diff --git a/test/MaxMatrixTestSupport.h b/test/MaxMatrixTestSupport.h index d822f00..ba5317f 100644 --- a/test/MaxMatrixTestSupport.h +++ b/test/MaxMatrixTestSupport.h @@ -32,7 +32,7 @@ // What it redefines is a keyword, not a name of ours. // NOLINTNEXTLINE(readability-identifier-naming) #define private public -#include "MaxMatrix.h" +#include "MaxMatrix.h" // IWYU pragma: export #undef private static uint8_t const kDataInPin{11}; diff --git a/test/SimulatorSerialHostTest.cpp b/test/SimulatorSerialHostTest.cpp index 670a9dd..3f3931a 100644 --- a/test/SimulatorSerialHostTest.cpp +++ b/test/SimulatorSerialHostTest.cpp @@ -9,11 +9,13 @@ * come back. On a port of its own, so that it needs no lock with the others. */ #include "Host/SimulatorSerialHost.h" -#include #include #include #include +#include +#include #include +#include #include #include diff --git a/test/SimulatorTest.cpp b/test/SimulatorTest.cpp index 83d936e..02b2bae 100644 --- a/test/SimulatorTest.cpp +++ b/test/SimulatorTest.cpp @@ -8,10 +8,13 @@ * they cannot see is a value on the command line that is quietly wrong, or a * line of the terminal that shows the chips in the wrong order. */ #include +#include +#include #include #include +#include "Arduino.h" #include "SimulatorOptions.h" #include "SimulatorPanel.h" #include "SimulatorTerminal.h" diff --git a/test/SimulatorWebHostTest.cpp b/test/SimulatorWebHostTest.cpp index 43d5fb7..e7a4714 100644 --- a/test/SimulatorWebHostTest.cpp +++ b/test/SimulatorWebHostTest.cpp @@ -9,9 +9,9 @@ * lock with simulator/web. */ #include "Host/SimulatorWebHost.h" -#include #include #include +#include #include #include diff --git a/test/SimulatorWebSocketTest.cpp b/test/SimulatorWebSocketTest.cpp index f6a3a96..5b2713d 100644 --- a/test/SimulatorWebSocketTest.cpp +++ b/test/SimulatorWebSocketTest.cpp @@ -11,9 +11,12 @@ #include "Host/SimulatorWebSocket.h" #include +#include +#include #include #include +#include #include #include diff --git a/test/Text/TextTest.cpp b/test/Text/TextTest.cpp index 27301d9..360aeb5 100644 --- a/test/Text/TextTest.cpp +++ b/test/Text/TextTest.cpp @@ -3,9 +3,14 @@ /* Text that shifts in: to its end, over again, and held. */ +#include +#include +#include + #include #include +#include "Arduino.h" #include "MaxMatrixTestSupport.h" using max_matrix::Error; diff --git a/test/model/Max7219.cpp b/test/model/Max7219.cpp index a321cff..74ec74a 100644 --- a/test/model/Max7219.cpp +++ b/test/model/Max7219.cpp @@ -4,6 +4,7 @@ #include "Max7219.h" #include +#include #include From c953ed03b00c944c4e5cb04c63d3d9b15b3b8040 Mon Sep 17 00:00:00 2001 From: virskl Date: Mon, 16 Nov 2026 16:09:10 +0100 Subject: [PATCH 6/8] Host code: every file includes what it uses (F-5) , and went where nothing used them. Four headers of wxWidgets that include only the port's header, and for timeval, which glibc declares in bits/, stay with // IWYU pragma: keep. --- control/ControlCommand.cpp | 1 + control/ControlDotPanel.cpp | 6 ++++++ control/ControlLink.cpp | 4 ++++ control/ControlSerialPort.cpp | 3 +++ control/ControlTcpPort.cpp | 4 +++- control/ControlWindow.cpp | 16 ++++++++++++---- docu/DocuPictures.cpp | 2 ++ docu/DocuSvg.cpp | 3 +++ simulator/Avr/SimulatorAvr.cpp | 6 ++++++ simulator/Avr/mainAvr.cpp | 2 ++ simulator/Host/SimulatorSerialHost.cpp | 3 +++ simulator/Host/SimulatorSocket.cpp | 7 +++++-- simulator/Host/SimulatorWebHost.cpp | 4 ++++ simulator/Host/SimulatorWebSocket.cpp | 2 ++ simulator/SimulatorFrontEnd.cpp | 4 ++++ simulator/SimulatorOptions.cpp | 3 +++ simulator/SimulatorPanel.cpp | 6 ++++++ simulator/SimulatorTerminal.cpp | 5 +++++ simulator/Web/SimulatorWeb.cpp | 9 ++++++++- simulator/main.cpp | 2 +- 20 files changed, 83 insertions(+), 9 deletions(-) diff --git a/control/ControlCommand.cpp b/control/ControlCommand.cpp index a6e7654..636e916 100644 --- a/control/ControlCommand.cpp +++ b/control/ControlCommand.cpp @@ -10,6 +10,7 @@ #include "ControlCommand.h" #include +#include #include #include diff --git a/control/ControlDotPanel.cpp b/control/ControlDotPanel.cpp index d7f0c2a..a1faba4 100644 --- a/control/ControlDotPanel.cpp +++ b/control/ControlDotPanel.cpp @@ -13,11 +13,17 @@ #include "ControlDotPanel.h" #include +#include #include #include +#include +#include +#include #include +#include #include +#include #include "ControlCommand.h" #include "MaxMatrixConfig.h" diff --git a/control/ControlLink.cpp b/control/ControlLink.cpp index 47abcc3..27ef7ab 100644 --- a/control/ControlLink.cpp +++ b/control/ControlLink.cpp @@ -9,11 +9,15 @@ #include "ControlLink.h" +#include +#include + #include #include #include #include "ControlCommand.h" +#include "ControlPort.h" ControlLink::ControlLink(ControlPort& port) : port_{port} {} diff --git a/control/ControlSerialPort.cpp b/control/ControlSerialPort.cpp index a659004..82519f1 100644 --- a/control/ControlSerialPort.cpp +++ b/control/ControlSerialPort.cpp @@ -22,6 +22,9 @@ #include #include #endif +#include +#include + #include #include #include diff --git a/control/ControlTcpPort.cpp b/control/ControlTcpPort.cpp index f8d4e02..51da66c 100644 --- a/control/ControlTcpPort.cpp +++ b/control/ControlTcpPort.cpp @@ -13,7 +13,6 @@ #ifdef _WIN32 #include #else -#include #include #include #include @@ -21,6 +20,9 @@ #include #include #endif +#include +#include + #include #include diff --git a/control/ControlWindow.cpp b/control/ControlWindow.cpp index 8492396..6158dc0 100644 --- a/control/ControlWindow.cpp +++ b/control/ControlWindow.cpp @@ -12,18 +12,25 @@ #include "ControlWindow.h" #include +#include #include -#include -#include -#include +#include // IWYU pragma: keep +#include // IWYU pragma: keep +#include // IWYU pragma: keep +#include +#include #include #include #include #include #include -#include +#include // IWYU pragma: keep #include +#include +#include #include +#include +#include #include #include @@ -32,6 +39,7 @@ #include "ControlCommand.h" #include "ControlDotPanel.h" +#include "ControlLink.h" #include "MaxMatrixConfig.h" namespace { diff --git a/docu/DocuPictures.cpp b/docu/DocuPictures.cpp index efa35b2..37d6371 100644 --- a/docu/DocuPictures.cpp +++ b/docu/DocuPictures.cpp @@ -17,6 +17,7 @@ * fails when the library changes and the pictures were not written again. */ +#include #include #include @@ -29,6 +30,7 @@ #include "Arduino.h" #include "DocuSvg.h" +#include "Max7219.h" #include "MaxMatrix.h" #include "Utility/Bit.h" diff --git a/docu/DocuSvg.cpp b/docu/DocuSvg.cpp index 502306f..10ac46e 100644 --- a/docu/DocuSvg.cpp +++ b/docu/DocuSvg.cpp @@ -12,6 +12,9 @@ #include "DocuSvg.h" +#include + +#include #include namespace { diff --git a/simulator/Avr/SimulatorAvr.cpp b/simulator/Avr/SimulatorAvr.cpp index 7371b37..3c1b65b 100644 --- a/simulator/Avr/SimulatorAvr.cpp +++ b/simulator/Avr/SimulatorAvr.cpp @@ -16,8 +16,14 @@ #include #include #include +#include +#include +#include +#include +#include #include #include +#include #include #include "Arduino.h" diff --git a/simulator/Avr/mainAvr.cpp b/simulator/Avr/mainAvr.cpp index b1a14df..4217499 100644 --- a/simulator/Avr/mainAvr.cpp +++ b/simulator/Avr/mainAvr.cpp @@ -21,6 +21,8 @@ * of an example that moves. */ +#include + #include #include #include diff --git a/simulator/Host/SimulatorSerialHost.cpp b/simulator/Host/SimulatorSerialHost.cpp index d8b3244..1273e95 100644 --- a/simulator/Host/SimulatorSerialHost.cpp +++ b/simulator/Host/SimulatorSerialHost.cpp @@ -10,7 +10,10 @@ #include "SimulatorSerialHost.h" #include +#include +#include #include +#include #include #include diff --git a/simulator/Host/SimulatorSocket.cpp b/simulator/Host/SimulatorSocket.cpp index 785fb54..700002a 100644 --- a/simulator/Host/SimulatorSocket.cpp +++ b/simulator/Host/SimulatorSocket.cpp @@ -9,12 +9,15 @@ #include "SimulatorSocket.h" -#include #include #include #include +#include +#include #include -#include +#include // IWYU pragma: keep: timeval, which glibc declares in bits/ +#include +#include #include #include diff --git a/simulator/Host/SimulatorWebHost.cpp b/simulator/Host/SimulatorWebHost.cpp index 0229b8b..b95514f 100644 --- a/simulator/Host/SimulatorWebHost.cpp +++ b/simulator/Host/SimulatorWebHost.cpp @@ -13,9 +13,13 @@ #include "SimulatorWebHost.h" #include +#include +#include #include +#include #include +#include #include #include #include diff --git a/simulator/Host/SimulatorWebSocket.cpp b/simulator/Host/SimulatorWebSocket.cpp index e90a9a8..91bbd7f 100644 --- a/simulator/Host/SimulatorWebSocket.cpp +++ b/simulator/Host/SimulatorWebSocket.cpp @@ -13,6 +13,8 @@ #include "SimulatorWebSocket.h" #include +#include +#include #include #include diff --git a/simulator/SimulatorFrontEnd.cpp b/simulator/SimulatorFrontEnd.cpp index b1b6824..9e5af5d 100644 --- a/simulator/SimulatorFrontEnd.cpp +++ b/simulator/SimulatorFrontEnd.cpp @@ -9,10 +9,14 @@ #include "SimulatorFrontEnd.h" +#include + #include #include #include "Arduino.h" +#include "SimulatorOptions.h" +#include "SimulatorPanel.h" #include "SimulatorTerminal.h" SimulatorFrontEnd::SimulatorFrontEnd() = default; diff --git a/simulator/SimulatorOptions.cpp b/simulator/SimulatorOptions.cpp index 6813e75..9081f0a 100644 --- a/simulator/SimulatorOptions.cpp +++ b/simulator/SimulatorOptions.cpp @@ -11,12 +11,15 @@ #include "SimulatorOptions.h" +#include #include #include #include #include +#include "SimulatorPanel.h" + SimulatorOptions::SimulatorOptions() : wiring_name_(kSimulatorPanelDefaultWiring) {} diff --git a/simulator/SimulatorPanel.cpp b/simulator/SimulatorPanel.cpp index af01987..f50c9ac 100644 --- a/simulator/SimulatorPanel.cpp +++ b/simulator/SimulatorPanel.cpp @@ -12,9 +12,15 @@ #include "SimulatorPanel.h" +#include + #include #include +#include "Arduino.h" +#include "Max7219.h" +#include "MaxMatrixConfig.h" + /* the four wirings MD_MAX72XX has names for, beside DR0CR0RR0 ... DR1CR1RR1 * from kMax7219Wirings */ namespace { diff --git a/simulator/SimulatorTerminal.cpp b/simulator/SimulatorTerminal.cpp index 403aa4f..bbda5c3 100644 --- a/simulator/SimulatorTerminal.cpp +++ b/simulator/SimulatorTerminal.cpp @@ -10,11 +10,16 @@ #include "SimulatorTerminal.h" +#include + #include #include #include #include +#include "Arduino.h" +#include "SimulatorPanel.h" + namespace { /* ANSI escape sequences */ diff --git a/simulator/Web/SimulatorWeb.cpp b/simulator/Web/SimulatorWeb.cpp index 18b70a6..f5fcc45 100644 --- a/simulator/Web/SimulatorWeb.cpp +++ b/simulator/Web/SimulatorWeb.cpp @@ -12,12 +12,19 @@ #include "SimulatorWeb.h" -#include +#include +#include + #include +#include #include #include #include +#include "Arduino.h" +#include "MaxMatrixConfig.h" +#include "SimulatorPanel.h" + namespace { /* commands of the page */ diff --git a/simulator/main.cpp b/simulator/main.cpp index ac88cb6..6f853e1 100644 --- a/simulator/main.cpp +++ b/simulator/main.cpp @@ -30,7 +30,7 @@ * prints, it gets back. */ -#include +#include #include #include From 32fd7113589a7d194c9f0279a9cb45a34ab4ec79 Mon Sep 17 00:00:00 2001 From: virskl Date: Mon, 16 Nov 2026 16:09:10 +0100 Subject: [PATCH 7/8] misc-include-cleaner on (OIL 41, F-5) IgnoreHeaders leaves out what a public header includes and include-cleaner takes for a name's provider, as the template does for avr/io*.h: avr/common.h, glibc's bits/ and sys/poll.h, Linux's asm-generic/ and the GTK port of wxWidgets. Decided against a NOLINT on each of some 20 lines. --- .clang-tidy | 15 ++++++++------- AGENTS.md | 11 ++++++++++- OIL.md | 21 ++++++++++++++++++++- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index b7ea09b..341c323 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -44,8 +44,7 @@ Checks: > -bugprone-easily-swappable-parameters, -cert-err58-cpp, -bugprone-throwing-static-initialization, - -modernize-concat-nested-namespaces, - -misc-include-cleaner + -modernize-concat-nested-namespaces # MaxMatrix's own, for good: # cert-err58-cpp, bugprone-throwing-static-initialization, its name in clang-tidy 23: reports # the simulator's static objects, which a sketch has as well: a static @@ -60,10 +59,6 @@ Checks: > # shapes and of internal::Panel::ConvertDotToBuffer(), the three pins of internal::Chain, a # port and its mask, and the same in the host code. FN-16 asks for a type each, which the # review of FN-16 in OIL 41 weighs against the shapes' parameters as Adafruit GFX names them. -# misc-include-cleaner, apart from the rest of misc-*: some 540 places, a header included -# for every symbol it provides, and its fix names , which avr-gcc lacks, and -# , which the host lacks. Its includes are written by hand, in a pull request -# of their own. # house-*: the checks of our own, in tools/lib/tidy_module/; tools/tidy.sh loads them. Without # the module, as in clangd, the name matches nothing. house-bitwise-in-bit-class takes the # bit class to be any class named Bit (docs/CodingStyle.md H-9); a project whose class has @@ -182,7 +177,13 @@ CheckOptions: # include-cleaner does not take back to . Any core's folder, not # only cores/arduino/ of Arduino's: a third party's core has its own, as # cores/xmega/ of XMegaForArduino's, where Serial comes from. - misc-include-cleaner.IgnoreHeaders: '.*/cores/[^/]+/.*;.*/variants/.*;.*/avr/io[^/]*\.h' + # MaxMatrix's own, at the end, alike: a header that a public one includes and + # include-cleaner takes for the provider of a name. avr/common.h, SREG's, + # which includes; glibc's bits/ and sys/poll.h, which , + # and include; Linux's asm-generic/, through + # ; and the port of wxWidgets, wx/gtk/ and wx/generic/, which + # wx/panel.h or wx/app.h include, and which a build on Windows does not have. + misc-include-cleaner.IgnoreHeaders: '.*/cores/[^/]+/.*;.*/variants/.*;.*/avr/io[^/]*\.h;.*/avr/common\.h;.*/bits/.*;.*/sys/poll\.h;.*/asm-generic/.*;.*/wx/(gtk|generic)/.*' # Google's names, which readability-identifier-naming checks only once it is told them; the # same block in every project, so that every project names alike. Two exceptions Google # makes itself are general: an accessor is named like the variable it gives (group(), diff --git a/AGENTS.md b/AGENTS.md index 0e46802..4ba997a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -491,6 +491,14 @@ does the same from `simulator/` (`"Host/SimulatorSerialHost.h"`), in its own fil tests. A header includes what it uses itself, rather than relying on a header included before it. +Every file includes what it uses (F-5, `misc-include-cleaner`), the C library's headers as +``, as avr-gcc has no ``. `MaxMatrix.h` exports the headers whose names a +sketch uses, with `// IWYU pragma: export`, so that a sketch includes it alone and, of avr-libc, +what it uses itself, as ``; a new public header is exported there as well. +`MaxMatrixTestSupport.h` exports `MaxMatrix.h` to the tests, which must see the library after +`#define private public`: a test that included `"Font/Font.h"` itself would have it sorted +before the define, and lose its private members. + #### Comments Comments say *why*, not what — the reasoning that is not recoverable from the code, such as @@ -561,7 +569,8 @@ MD_MAX72XX gives those names; the README's table says the same and changes with The mock has a `Serial` that reads `mock::serial_input` and appends what the sketch prints to `mock::serial_output`, so that `SerialControl` builds into a simulator as well; `F()`, `PSTR()`, `strcmp_P()` and `pgm_read_ptr()` take strings in RAM there, as the host has no separate flash, but -`F()` keeps the type `__FlashStringHelper const*` of the core. +`F()` keeps the type `__FlashStringHelper const*` of the core. What avr-libc declares lies in +`test/mock/avr/`, as on the board, so that a file includes the same header for both. The mock also has `millis()`, `micros()` and `delay()` on the host clock, for the simulator; `delay()` really waits. A test that times something holds the clock with `mock::SetMillis()` instead, until the next `mock::Reset()`; `delay()` then moves it on without waiting. The library diff --git a/OIL.md b/OIL.md index fd6b793..dffb838 100644 --- a/OIL.md +++ b/OIL.md @@ -1036,7 +1036,26 @@ A first look found, besides those two: the rule, assignability, where the rule says never. That is the template's to take up, in the rule's text or its "Checked by". `Batch` was the only such member in the repository. - F-5: `misc-include-cleaner` is still off, with some 540 places, waiting for the pull request - 36 named for it. + 36 named for it. As built, it is on, and every file includes what it uses: some 175 includes + in 59 files, and 7 that nothing used are gone. The C library's headers are written as + `` and ``, as the template and Utl write them, since avr-gcc has no + ``. `MaxMatrix.h` exports the headers whose names a sketch uses, with + `// IWYU pragma: export`, so that a sketch includes it alone and, of avr-libc, what it uses + itself: ``, and `` where it keeps a table in flash. + `MaxMatrixTestSupport.h` exports `MaxMatrix.h` to the tests, which must see the library after + `#define private public`. The mock has avr-libc's `avr/pgmspace.h`, `avr/io.h` and + `avr/interrupt.h`, as the core has them, so that a file of the library includes the same + header on the host and the board. + + Where include-cleaner takes for a name's provider a header that a public one includes, + `IgnoreHeaders` leaves it out, as the template does for `avr/io*.h`, decided on 2026-11-16 + against a NOLINT on each of some 20 lines: `avr/common.h`, where `SREG` is, which the + template's pattern misses as well and is the template's to take up; glibc's `bits/` and + `sys/poll.h`, Linux's `asm-generic/`, and the GTK port of wxWidgets. Six includes that the + check takes for unused stay, with `// IWYU pragma: keep`: four of wxWidgets that only include + the port's header, `` for `timeval`, and `MaxMatrixConfig.h` in + `MaxMatrixErrorReport.cpp`, whose switch the variant with `MAXMATRIX_DEV_ERROR_DETECT` sets + with `-D`. Every example is the same size in every variant. - S-5: the reasons in `.clang-tidy` for `bugprone-easily-swappable-parameters` and `bugprone-too-small-loop-variable` name `MaxMatrixChain` and `MAXMATRIX_NUMBER_OF_COLUMNS`, which are gone. As built, every check the project turns off was run again with clang-tidy 23. From eaaf050ca239be64b36c482f808326fbdfcfb58e Mon Sep 17 00:00:00 2001 From: virskl Date: Mon, 16 Nov 2026 16:09:33 +0100 Subject: [PATCH 8/8] OIL.md: 41 is #113 as well --- OIL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OIL.md b/OIL.md index dffb838..513dea1 100644 --- a/OIL.md +++ b/OIL.md @@ -50,7 +50,7 @@ Status: `open`, `in progress`, `done`, `dropped` (with the reason in the item). | 38 | Results that must not be ignored | 36 | done | #94 | | 39 | MC/DC coverage | 34 | done | #95, #96 | | 40 | Braced initialization checked | 34 | done | #93 | -| 41 | The template's rules that review checks | 36 | in progress | #99, #100, #101, #102, #104, #105, #106, #107 | +| 41 | The template's rules that review checks | 36 | in progress | #99, #100, #101, #102, #104, #105, #106, #107, #113 | | 42 | A newer avr-gcc as a cross-check | 41 | done | | | 43 | Bit operations in one class, from the template | 41 | done | #109 |