build: the libavr pin advances past phase 6, and the driver takes the bus whole
The register sugar now rides the bus's own master role - device<Bus> resolves avr::i2c::device<typename Bus::master, bus_address>, so a consumer keeps handing over its declared dev::i2c<...> unchanged - and the DS3231's hardwired 0x68 is a named constant. The example's four discards became the LED's own error signal (a failed seed or a failed alarm clear holds it dark, the same word a stuck bus says), the tree is reformatted under InsertBraces, the sources are ASCII, and the README's stale Studio byte counts are replaced by the claim its check-flags gate holds. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,7 @@ using namespace avr::literals;
|
||||
|
||||
// One source for the tiny85 (open-drain software I2C on the USI pins) and
|
||||
// the mega328P (TWI hardware). On first power-up the clock is seeded and
|
||||
// alarm 1 armed; then the LED mirrors the seconds parity — a stuck LED
|
||||
// alarm 1 armed; then the LED mirrors the seconds parity - a stuck LED
|
||||
// means bus errors.
|
||||
using dev = avr::device<{.clock = 8_MHz}>;
|
||||
using bus = dev::i2c<{.frequency = 100_kHz}>;
|
||||
@@ -17,16 +17,21 @@ int main()
|
||||
avr::init<bus, led>();
|
||||
|
||||
if (auto stopped = rtc::oscillator_stopped(); stopped.value_or(false)) {
|
||||
(void)rtc::write_clock({{2026, 1, 1}, {12, 0, 0}});
|
||||
(void)rtc::set_alarm1({}, ds3231::alarm1_rate::once_per_second);
|
||||
(void)rtc::clear_oscillator_stopped();
|
||||
// A failed seed leaves the LED dark before the loop ever runs - the
|
||||
// same signal a stuck bus gives it below.
|
||||
const bool seeded = rtc::write_clock({{2026, 1, 1}, {12, 0, 0}}) &&
|
||||
rtc::set_alarm1({}, ds3231::alarm1_rate::once_per_second) &&
|
||||
rtc::clear_oscillator_stopped();
|
||||
led::write(seeded);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
if (auto now = rtc::read_clock(); now.has_value())
|
||||
if (auto now = rtc::read_clock(); now.has_value()) {
|
||||
led::write(now->second % 2 == 0);
|
||||
if (auto fired = rtc::alarm1_fired(); fired.value_or(false))
|
||||
(void)rtc::clear_alarm1();
|
||||
}
|
||||
if (auto fired = rtc::alarm1_fired(); fired.value_or(false) && !rtc::clear_alarm1()) {
|
||||
led::clear(); // a clear that failed holds the LED dark, like any bus error
|
||||
}
|
||||
dev::delay<100_ms>();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user