Skip to content

TimerTwo on the template embedded-cpp-template (OIL 1) - #4

Merged
theAndreas merged 8 commits into
mainfrom
template
Nov 10, 2026
Merged

theAndreas merged 8 commits into
mainfrom
template

Conversation

@theAndreas

Copy link
Copy Markdown
Owner

TimerTwo gets the checks, CI and dev container of the copier template embedded-cpp-template, which Utl and MaxMatrix share, so that a change to one reaches the others with copier update. It is the first of four steps that the new OIL.md lists: the bugs found on the way (2), version 2.0.0 with a namespace (3) and its release (4) follow in pull requests of their own. In the template's roadmap this is R-3; the decision there was to bring TimerTwo in rather than retire it, as neither Utl nor the ETL drives a hardware timer.

What changes

  • The library layout of Arduino 1.5 in place of the AtmelStudio project, which carried a copy of the Arduino core and build artefacts.
  • A licence: GPL-3.0-or-later, as Utl and MaxMatrix have; TimerTwo had none, only "All rights reserved". The default branch is main now, as in the other projects.
  • The examples compile: the one sketch asked for a PWM pin the library never offered, and printed without starting the serial port. The README's example is a sketch of its own now, so that CI builds what the README shows.
  • The API is documented where the reference and the editor read it, and says what each function refuses.
  • clang-format once, then what cpplint and the stricter warnings find; none of it a bug.
  • Tests on the host against a mock of Timer2's registers, for what the library does right today. The mock's counter moves as the timer does, up and down, so that the code that waits for it ends.
  • For now the template's clang-tidy groups that the code of 2023 fails are off for the library and the examples, with the reason and OIL 3, which rewrites that code anyway. The new tests and mock keep every check.
  • Not yet: the self check in simavr, which comes with OIL 2, where it is to be seen how well simavr models this timer mode.

Behaviour

Unchanged for a sketch: same API, same results. The one change in the generated code is a read of the counter whose value was never used, which clang-tidy's analyser found; it goes.

What was measured

  • make check passes from a clean build: 27 of 27 tests by GCC, by clang, under the sanitizers and with coverage; lint, clang-tidy, cppcheck, each header on its own, Doxygen, arduino-lint, the examples. Coverage of the library: 97 % of the lines, the rest unreachable through the API.
  • Flash and RAM of both examples on the Uno: Basics 1290 / 25 bytes as before; Read 2790 / 210, 4 bytes of flash less for the dropped read.
  • Not on hardware, and not yet in simavr.

Found on the way, for OIL 2

Seven bugs, each listed in OIL.md with what it does wrong: among them, resuming a stopped timer leaves it marked stopped, the full duty is never full, and the time readout loses its lower steps. Each gets a test that fails first.

🤖 Generated with Claude Code

theAndreas and others added 8 commits November 10, 2026 20:45
…roject

The AtmelStudio solution carried a copy of the Arduino core, its .atsuo files and the
ignores of its Debug folders; arduino-cli and CMake take its place with the template. The
sketch is examples/Read now, in UTF-8: its µ was Windows-1252.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`uvx copier copy --overwrite` with skeleton=false: the checks, CI and the dev container that
Utl and MaxMatrix share, and GPL-3.0-or-later as TimerTwo's licence, which had none. The
namespace timer_two and the prefix TIMERTWO are what version 2.0.0 is to use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Read asked for PWM_PIN_11, which TimerTwo never offered, as OCR2A is the top of the counter,
and printed on a Serial it had not begun; its comment opened twice. Basics is the example of
the README, so that make examples builds what the README shows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rmat once

Each file starts with its copyright and SPDX line rather than the banner of "All rights
reserved"; the blocks of the API move from TimerTwo.cpp into TimerTwo.h, where Doxygen and
clangd read them, and say what each function refuses. The section banners are gone, as
clang-format would have broken them at 80 columns. Then clang-format with the template's
Google style, and what cpplint finds beyond it: an empty loop has braces.

StandardTypes.h keeps its guard, against cpplint: the author's older libraries carry the same
file under it, and a sketch with one of them would define E_OK twice otherwise. The fallback
of nullptr to NULL before C++11 is gone; the library uses C++11 throughout.

Flash and RAM of both examples on the Uno are those of before, to the byte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…of 2023

Nine places for the compilers, none a bug. The bit macros of StandardTypes.h computed in int
and cut to eight bits on the assignment; they say so with a static_cast now. Four narrowings
lie in a range the code makes sure of, each with the range beside its cast. The check of the
duty against 256 was always true for a byte, and goes: avr-gcc had removed it already.

clang-tidy's analyser found a read of TCNT2 in read() whose value the loop overwrote before
using it; it goes, which makes examples/Read 4 bytes smaller. Flash and RAM are otherwise
those of before, to the byte.

For now src/.clang-tidy and examples/.clang-tidy turn off the template's groups that the code
of 2023 fails: its names, macros, typedefs and C enums, some 450 places, which version 2.0.0
rewrites anyway (OIL 3). The examples need them as well, as clang-tidy holds a header to the
checks of the file that includes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
27 tests of what TimerTwo does right today: mode 5 on init(), the top and the prescaler of
each period, start(), stop() and resume() on the clock select bits, the interrupt and the
callback, the PWM on pin 3, and read() at each prescaler and in both directions. What it does
wrong waits for OIL 2, each with a test that fails first.

The mock of avr/io.h has the registers as bytes, and TCNT2 as a counter that steps on each
read while a clock is selected, up to OCR2A and down again: start() and read() wait for the
counter to move, and would wait forever on a plain byte. ISR() makes the handler a function a
test calls. Timer2 is a singleton that init() takes once, so each test needs a process of its
own, which ctest gives it; the fixture says so if a test begins from a used timer.

Coverage of src/: 97 % of the lines; what is left is a pin outside PwmPinType and the default
of a switch over all the prescalers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
OIL.md lists the four steps: this one onto the template, the bugs found on the way, version
2.0.0 and its release. AGENTS.md says what an agent has to know beyond the template: the
singleton and its tests, the mock's counter, the exceptions until 2.0.0. The README links the
examples and names the licence; library.properties says what TimerTwo does, in the category
Timing. SIMAVR_MCU stays empty until SelfCheck checks the timer in simavr (OIL 2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@theAndreas
theAndreas merged commit e1ffe01 into main Nov 10, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant