MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / begin

Method begin

lib/hal/HalClock.cpp:20–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18static uint8_t decToBcd(uint8_t dec) { return ((dec / 10) << 4) | (dec % 10); }
19
20void HalClock::begin() {
21 if (!gpio.deviceIsX3()) {
22 _available = false;
23 return;
24 }
25
26 // I2C is already initialised by HalPowerManager::begin() for X3.
27 // Probe the DS3231 by reading the seconds register.
28 Wire.beginTransmission(I2C_ADDR_DS3231);
29 Wire.write(DS3231_SEC_REG);
30 if (Wire.endTransmission(false) != 0) {
31 LOG_INF("CLK", "DS3231 RTC not found");
32 _available = false;
33 return;
34 }
35 Wire.requestFrom(I2C_ADDR_DS3231, (uint8_t)1);
36 if (Wire.available() < 1) {
37 _available = false;
38 return;
39 }
40 Wire.read(); // discard — just testing connectivity
41
42 _available = true;
43 LOG_INF("CLK", "DS3231 RTC found");
44
45 // Prime the cache with an initial read
46 uint8_t h, m;
47 getTime(h, m);
48}
49
50bool HalClock::getTime(uint8_t& hour, uint8_t& minute) const {
51 if (!_available) return false;

Callers

nothing calls this directly

Calls 4

deviceIsX3Method · 0.80
writeMethod · 0.45
availableMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected