bbdcc1e623
- 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
19 lines
432 B
C
19 lines
432 B
C
|
|
#include "spi.h"
|
|
|
|
// RFM69 chip select (SS1/PE2, active low)
|
|
void spi_rfm69_select(bool state)
|
|
{
|
|
SET_PIN_OUT(DDRE, DDE2);
|
|
SET_PIN_TO(PORTE, PE2, !state);
|
|
}
|
|
|
|
uint8_t spi_write(uint8_t data)
|
|
{
|
|
SPDR1 = data; // Load data into the SPI data register
|
|
while (!(SPSR1 & (1 << SPIF1))) { }; // Wait for transmission to complete
|
|
return SPDR1; // Return received data
|
|
}
|
|
|
|
uint8_t spi_read(void) { return spi_write(0xFF); }
|