Refactor firmware for clarity; no functional changes

- main.c: file-header comment describing the hardware and operation, logic
  split into named phases (sleep_until_interrupt, wake_peripheral_rails,
  take_counts_snapshot, send_wheel_counts_report, handle_minute_alarm,
  init_all_hardware); shared state renamed to say what it is and made static.
- rfm69.c: reorganized into six labeled sections; cond_1/2/3 and hash scratch
  globals replaced by a reply_acknowledges() helper with clear locals; packet
  layout and every init register write documented.
- LOG() macro (compiled out when DO_UART is off) replaces the #if DO_UART
  blocks that obscured the logic.
- Drivers: file-header comments; named RTC_REG_*/RTC_ALM_MASK_BIT constants;
  EEPROM spool scheme documented; ADC_CHANNEL_BANDGAP named; repeated pin
  if/else helpers collapsed to SET_PIN_TO().
- Removed unused globals/buffers and commented-out code; ran clang-format
  with the project style.

Register writes and radio protocol are byte-identical. Builds clean under
-Wall -Wextra on gnu17 and c23; flash 13028 -> 12830 B, static RAM
1038 -> 999 B.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YVJKatfeMJjAmuH9KYiLuv
This commit is contained in:
2026-08-31 23:04:00 -04:00
parent ed476473b6
commit bbdcc1e623
25 changed files with 825 additions and 1798 deletions
+8 -7
View File
@@ -1,4 +1,6 @@
// Minimal NDEF parser: finds the first record in a raw tag dump and accepts
// only a short text record, whose text becomes the node's "name,diameter"
// identity string.
#include "ndef.h"
// Everything read here comes off an NFC tag that anyone can write, so every
@@ -11,7 +13,8 @@
} \
}
ndef_message readNDEFText(unsigned char *buf, uint8_t buf_len) {
ndef_message readNDEFText(unsigned char* buf, uint8_t buf_len)
{
uint16_t addr = 0;
NDEF_MSG.success = 0;
NDEF_MSG.payload_len = 0;
@@ -80,7 +83,7 @@ ndef_message readNDEFText(unsigned char *buf, uint8_t buf_len) {
return NDEF_MSG;
}
payload_length -= lang_str_len; // Language string
payload_length -= 1; // The byte that says how long the language string is
payload_length -= 1; // The byte that says how long the language string is
NDEF_NEED((uint16_t)lang_str_len + 1);
addr += lang_str_len;
@@ -99,10 +102,8 @@ ndef_message readNDEFText(unsigned char *buf, uint8_t buf_len) {
NDEF_MSG.payload[payload_length] = '\0';
NDEF_MSG.payload_len = payload_length;
#if DO_UART
uart_sendString(NDEF_MSG.payload);
uart_sendString("\n");
#endif
LOG(NDEF_MSG.payload);
LOG("\n");
return NDEF_MSG;
};