| 18 | static uint8_t decToBcd(uint8_t dec) { return ((dec / 10) << 4) | (dec % 10); } |
| 19 | |
| 20 | void 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 | |
| 50 | bool HalClock::getTime(uint8_t& hour, uint8_t& minute) const { |
| 51 | if (!_available) return false; |
nothing calls this directly
no test coverage detected