Commit Graph

69 Commits

Author SHA1 Message Date
0f99b7787c build: the libavr pin advances to the sweep's own record
Documentation only - the guideline sweep's condensed entry, the three measured
facts about class-type constants it produced, and the port filings it left
open. No header, tool or generated input moves, so every image is untouched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-12 17:02:56 +02:00
3e95160b00 fix: the quarter-degree rounding was wrong below zero, in three copies
`(quarters + 2) / 4` is round-half-up only for positive values: C truncates a
negative quotient toward zero, so -3.00 C read as -2, -1.00 C as 0 and -0.75 C
as 0 - nine of fifteen negative quarter-values off by a whole degree, always
toward zero. `(quarters + 2) >> 2` is an arithmetic shift, which floors, and
is right across the whole range. It is also smaller: the shift skips the bias
correction signed division needs.

The formula was written three times - thermistor::celsius(), which nothing
called, and inline at both live call sites - so the defect had three homes and
so would its fix. One `thermistor::whole_degrees()` now, called from both, and
the dead entry point is gone (rules 6, 27).

test/consteval.cpp is new and is what should have caught it: whole_degrees
across zero including both ties and both table limits, the curve's start and
saturation points and its monotonicity, and the thermistor table anchored
where the Beta equation fixes it - the count at which the divider reads the
thermistor's nominal resistance must read the nominal temperature - plus both
clamps and the fall across every step. Red-green: four assertions fire against
the old division.

Beside it: the cubic's three coefficients are named rather than inlined and
restated in prose (rule 5), the consteval table builders take explicit 32-bit
types (rule 25), the curve's clamp reads the table's own size (rule 36), and
the serial override says what expects the rate rather than what the board has
always done (rules 12, 13).

And bootloader::handle_reset()'s watchdog diversion is gone. Its own comment
called it a leftover "kept only because it is free and cannot hurt", and it
did not: pureboot peeks WDRF without clearing it and hands back on purpose, so
a watchdog reset arrives here with the flag still set and the diversion jumped
into the loader with MCUSR already cleared - opening the activation window
that policy exists to close. Clearing MCUSR is the whole job and stays.

8206 -> 8168 bytes, byte-identical between generated and reflect.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-12 16:23:05 +02:00
837b832bc7 build: the libavr pin advances past the audit sweep, and the numbers get names
The pin crosses libavr's phase-6 close and the guideline sweep behind it;
the image is byte-identical in both modes at 8206 bytes.

The port's own sweep, against the same rules. Every mutable `static inline`
takes `m_` - uptime's counter, the sampler's window, the controller's five,
the statistics histogram and the terminal's line state (rule 46; a private
`static constexpr` is a constant rather than state and keeps its bare name).
The command table is `std::to_array` and the serial config breaks one member
per line (rules 36, 40). And three numbers get the name they already had
somewhere: duty goes through `percent_t::of()` rather than a hand-built
basis-point count, the ADC's top count is `thermistor::adc_full_scale`
instead of 1023 in four places, and the two `0xffffffff` are `open_circuit`
- which was already declared five lines away - and `never_written`, which
replaces a comment explaining the literal (rules 5, 6, 41).

Measured, not assumed: rendering `adc_full_scale` into the `show` line
instead of leaving it in the message string cost 6 bytes, so the display
text stays text.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-12 14:40:33 +02:00
1489f4c3a0 editor: clangd and cmake work from a committed vscode workspace
The three files libavr's consumers carry, in the leaf-application shape:
nothing vendors this repo, so .clangd names the one build tree an editor
should read (build/atmega328p-generated) beside the stand-ins clang needs
for GCC's AVR dialect; .vscode/settings.json passes --query-driver and names
the toolchain prefix for the window that opens this folder. The libavr pin
advances to the editor-audit fixes. One residue stays red and is the
documented frontend divergence, not a defect: thermistor.hpp's consteval
Beta-equation table folds __builtin_log under GCC, which clang refuses to
fold in a constant expression -- the same class as libavr's breathe example
and its __builtin_cos.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-09 16:48:46 +02:00
b1caf49522 build: the libavr pin advances past phase 6
The renames land (interrupt_guard, consume_reset_cause, set_duty), the
sampler binds its input in the new converter shape (the input pack plus
in<>::start() as free-running's one kick), and the console states
.allow_baud_error = true for the 115200-at-16-MHz this board has always
spoken - the receiver-tolerance table libavr now enforces is stricter
than the rate's own +2.1 %. The loader probe reads through
avr::flash_load instead of raw pgmspace, the terminal's line buffer is
std::array with backspace and delete named, the tree is reformatted
under InsertBraces, and the sources are ASCII.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-09 11:45:07 +02:00
0e9060db69 build: the libavr pin advances past the consumer-report fixes
timer::engine gains stop()/start() and a runtime TOP, adc gains
disable()/enable(), and libavr_programming_targets() stops leaving .fuse bytes
in the flash HEX. Every one of them is additive, and this port adopts none of
them yet: its 3 built images come out byte-identical across the pin change,
which is what the advance is here to keep true.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-01 23:18:55 +02:00
3fbbcdade9 build: the libavr pin advances to the v9 era
Built and tested against it in a clean checkout of this port, through its own
submodule rather than a working-tree override, so the pin is what was proved.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-01 18:46:36 +02:00
6abf0b5563 console: values in a column, the curve as a graph, and Ctrl+C
Three more things the original did better, and two bugs found doing them.

`curve` walks every whole degree from 10 to 60 with a bar, which is the
original's. The port sampled it every five degrees and printed a bare
percentage — ten numbers for a cubic, showing none of its shape. The bar
is the duty itself, so it needs no scale.

`show` and `statistics` print one value per line behind a dotted label
instead of a run-on line. That reads the same either way for a single
reading and is the whole difference when `monitor` emits one a second
forever. The label renderer is now shared with the help, since it is the
same thing three times; the flash overload takes its width from the
string's type, so the padding needs no hand-counted constant and the
labels stay out of SRAM. `statistics` gains the sample total, and says
"not available" rather than a zero it never measured.

Ctrl+C echoes `^C` and gives a fresh prompt, abandoning whatever was
half-typed, and it is what stops `monitor` now. Stopping on *any* byte
was the port's own invention and it reads fine until a host sends a line
ending: `monitor\r\n` stopped itself on the `\n` it arrived with, one
reading in, which is why monitoring looked broken from a script and fine
by hand.

The other bug is arithmetic. A temperature's fraction came from
`(quarters % 4) * 25`, and C++ gives a negative remainder for a negative
dividend — so -40.25 C printed as "-40.-25". The sign comes off first
now, and the fraction is two digits, so the column lines up: -40.00,
-40.25.

Verified against v1.8b on the board, which was flashed back to compare
against directly: same 51 curve rows over the same span with the same
100-column bars, agreeing within the one percentage point the consteval
table costs against the legacy runtime doubles.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-31 02:34:02 +02:00
c01e583597 console: the terminal is the original's again, and the way out is a jump
Six things the port had dropped or got wrong, and the one that matters is
the last.

The help is a table again — name, dots, description, one command per line
— instead of a single line of bare words that said nothing about what any
of them did. The layout is the original's, colons at column 12, which
`bootloader` at ten characters is what sets.

Abbreviations are back, and they were a feature: any prefix resolves to
the first command it matches, so `up` is uptime and `st` is statistics.
Order does the disambiguating, which is why the table is in the
original's dispatch order and new entries go on the end — appending
cannot take an abbreviation that already meant something. `reset` keeps
the original's exception and must be typed in full: `r` should not be
able to clear the histogram.

The histogram gets its resolution back. The bar was capped at 40 columns
where the original scaled to 100, and on a distribution this narrow that
threw away most of the difference between neighbouring buckets. Same
normalisation as before: divide by whatever makes the tallest bucket fit.
The sample count moves to a fixed ten-column field before the bar, so the
numbers read as a table instead of trailing off the ragged right end.

`version` exists again, and this is 2.1 — 2.0 being the port as it stood.

Added while here: `save`, to force the writeback that otherwise waits up to
thirty minutes; the resistance in `show`, which is the one number that
says *why* a temperature is wrong and which the original printed; a
report when a line overflows the buffer rather than silently acting on
its head; "no data yet" where there is none; and a blank line after each
command's output.

And the way out. `bootloader` now jumps rather than resetting, because
pureboot hands straight back on WDRF by design — so the legacy
watchdog-reset hand-over reaches it and opens no window, which on a board
with no reset line is a board that cannot be reflashed. Two more bugs in
the same three lines: the target was 0x7800, a 2 KB boot section's base,
which on this board's 512-byte section reads erased and made the check
false and the command a no-op; and UCSR0B was left set, which mutes a
loader that bit-bangs the pin the USART still owns. All three are now
read back out of the emitted image by ctest, the address and the watchdog
red-proven against exactly the legacy behaviour they exist to catch.

libavr advances to 71cfb2f. Verified on the board: FanTemp v2.1, min 0 C
/ max 74 C matching what 1.8b reported off the same EEPROM, the fan curve
within one percentage point of the legacy double-precision one at every
5 C from 15 to 60, and `bootloader` -> pureboot 7 -> back to a running
application.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-31 01:58:09 +02:00
e5a9a38bba build: the libavr pin advances over the delay and format contracts
The console's decimals render arithmetically now: the to_chars digit
table leaves SRAM (-202 B of data) and the streaming frames shrink with
it (-664 B of text, 7094 to 6430). Cross-mode .text stays
byte-identical.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-30 17:18:41 +02:00
d77fe8ea9e build: the libavr pin advances over the trait projection
The de-string-2 pass upstream: every peripheral block behind generated
instance traits, the string layer gone. The firmware rebuilds
byte-identically across modes at its recorded size.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-29 19:59:43 +02:00
949dc125cd build: the libavr pin advances to current main
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-29 07:24:10 +02:00
ba2cae8f8f build: the libavr pin advances to current main
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-29 06:48:36 +02:00
5afe29359c build: libavr rides as the pinned submodule
The submodule replaces FetchContent and the unpinned forge fallback;
LIBAVR_ROOT stays as the tandem-development override, the presets take the
toolchain file from the submodule, and the Studio project's include path
anchors there — correct by construction.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-28 00:29:38 +02:00
2cdf56f8d6 ide: the whole project in Solution Explorer, and a path Studio can resolve
Three things the solution got wrong, all found by opening it in the GUI rather
than building it headlessly.

The project listed only main.cpp, so none of the headers could be opened from
Solution Explorer. Every source and header is listed now, with <Link> mirroring
the on-disk src/ layout, which is what master's project did.

Neither configuration compiled in the GUI: libavr was found through
$(LIBAVR_ROOT), and a variable exported in a shell is not visible to Studio
launched from the Start menu. Release only looked healthy because its objects
were already up to date from a headless build. The path is now anchored to the
project directory, which also side-steps a second trap: a plain relative include
is resolved against the generated makefile's own directory, the configuration's
output directory, not the project's. Pinning libavr as a submodule would remove
the assumption that the two sit side by side, and is on libavr's task list.

Both configurations verified with LIBAVR_ROOT deliberately unset, Release still
byte-identical to the CMake build and the flag gate still green. Debug's own
translation unit carries DWARF-4 as intended.

Studio's per-user state under ide/.vs/ and the build logs are ignored.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 19:19:20 +02:00
00849d25d5 ide: the Atmel Studio solution master has, on the libavr port
master opens in Studio, so this branch should too. One project, the port's own
chip, flags mirrored by hand against the CMake build — and the acceptance is
not that it builds but that it builds the same firmware: .text (7094 B) and
.data (336 B) come out byte-identical to the CMake output from the same
sources.

libavr is found through $(LIBAVR_ROOT), the variable the CMake build already
uses, so no machine path is committed; Studio expands it from the environment.
The toolchain is named by flavour only, since nothing Studio ships can compile
-std=c++26 and the path to one that can is per-machine state.

The componentinfo file the project cannot load without is generated by
libavr's tools/atmelstudio/componentinfo.py and ignored here, as are Studio's
output directories. Release is what the flag gate compares, the presets
defining no debug build; Debug carries the -Og -gdwarf-4 pair libavr's own
debug preset uses.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 18:37:56 +02:00
b7a2e50506 Keep the curve and thermistor comments timeless
Both headers described the port transformation ("legacy cubic becomes",
"no hand-rolled series needed") rather than what the code is. State the
cubic and the __builtin_log rationale directly.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-18 10:10:47 +02:00
f17ebd17e5 Use libavr flash_table and __builtin_log
The thermistor Beta curve and the fan cubic move onto avr::flash_table
instead of hand-rolled [[gnu::progmem]] arrays with raw pgm_read, and
the compile-time logarithm uses __builtin_log (which constant-folds on
the AVR backend) instead of a hand-rolled series. Same 11284 B, still
byte-identical across libavr modes.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-18 08:03:42 +02:00
ab78d94872 Rewrite on libavr
Same controller: thermistor on ADC0 averaged over 1000 free-running
conversions, 50 kHz fan PWM on OC0B, 115200 Bd console with the full
command set, EEPROM temperature histogram, watchdog-reset path into the
boot section. The Steinhart-Hart math and the libm log are gone — the
Beta equation and the cubic fan curve are consteval-evaluated into
flash tables; the firmware never does floating point. Byte-identical
.text in both libavr modes. Legacy stays on master.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-18 04:37:26 +02:00
76d6b1583b Indicate auto/manual fan speed 2021-02-12 17:12:56 +01:00
5ec4a5441a Implement setting fan speed manually 2021-02-12 16:38:41 +01:00
7aa98a8ebd Replace sprintf with dtostrf to save about 1.5k of flash 2020-04-13 01:13:44 +02:00
64d6df256d Fix string being located in RAM 2020-04-13 00:54:44 +02:00
16ebed63c2 Change to stk500v2 compatible bootloader 2020-04-13 00:49:21 +02:00
eee2e6172a Fix rounding of percentage calculation 2020-04-10 17:21:39 +02:00
d6269952a6 Add saving to EEPROM on bootloader entry 2020-04-09 13:21:53 +02:00
6a7213de60 Add statistics reset command 2020-04-08 13:45:14 +02:00
ed2fddc427 Fix handling of statistics before data is available and fix normalization factor 2020-04-08 13:44:54 +02:00
1694e3bbab Change histogram to only print from min to max 2020-04-08 12:58:59 +02:00
02565c9396 Add percentages to histogram 2020-04-08 12:41:53 +02:00
00082617d1 Make help messages consistent 2020-04-08 09:52:39 +02:00
b8a40aed17 Implement eeprom stored persistent histogram 2020-04-08 02:17:34 +02:00
cae18b98e7 Reduce code duplication 2020-04-07 21:54:15 +02:00
6ba4a2ce3d Add eeprom saved statistics 2020-04-07 21:09:27 +02:00
ea6a6bd218 Add check to prevent printing data before it's available 2020-04-07 21:05:40 +02:00
f3cf12db3b Refactor terminal callback 2020-04-06 22:17:32 +02:00
34428b76dd Add uptime command 2020-04-06 22:12:11 +02:00
9ef4d2a737 Add millis timer for timekeeping 2020-04-06 21:36:47 +02:00
e29ee8c11f Fix commands being accepted in monitor mode 2020-04-06 19:53:46 +02:00
dd42aebb16 Make adc sampling interrupt driven 2020-04-06 19:43:32 +02:00
8db7bde6e5 Remove bootloader countdown and change timeout to 3s 2020-04-06 17:50:17 +02:00
508f139f47 Refactor substring comparison 2020-04-06 17:46:10 +02:00
45a79adc56 Fix leaking details into global namespace 2020-04-06 17:05:48 +02:00
67559642a3 Change boot-up message to include version 2020-04-06 16:36:33 +02:00
9ab76f4ce5 Add version number 2020-04-06 16:33:57 +02:00
07be559e94 Add tsb bootloader support 2020-04-01 19:04:27 +02:00
04bcb76382 Change echo of backspace to be compatible with more terminals 2020-04-01 15:33:48 +02:00
6003ea6603 Add monitor command to continuously show measurements 2020-04-01 05:21:56 +02:00
d6fa78ae5f Change temperature curve to cubic 2020-04-01 05:07:30 +02:00
aab90f0fc0 Add ctrl + c handler 2020-04-01 05:07:12 +02:00