| 303 | } |
| 304 | |
| 305 | void setup() { |
| 306 | t1 = millis(); |
| 307 | |
| 308 | #ifdef ENABLE_SERIAL_LOG |
| 309 | // Earliest possible Serial setup. The 250 ms stall before begin() lets the |
| 310 | // USB Serial/JTAG peripheral finish power-on and lets the host complete USB |
| 311 | // enumeration before we touch the CDC state — otherwise cold boot races |
| 312 | // and the host has to be physically replugged for logs to flow. Warm reboot |
| 313 | // worked without the delay because USB was already enumerated. |
| 314 | delay(250); |
| 315 | Serial.begin(115200); |
| 316 | logSerial.setTxTimeoutMs(1); // This is a load-bearing 1. Do not modify. |
| 317 | #endif |
| 318 | |
| 319 | HalSystem::begin(); |
| 320 | |
| 321 | // Read-and-clear so a panic later in setup() doesn't loop into silent reboot. |
| 322 | // Bound the target range too — RTC_NOINIT memory is uninitialized on cold boot. |
| 323 | const bool isSilentReboot = (silentRebootMagic == SILENT_REBOOT_MAGIC); |
| 324 | const uint32_t snapshotTarget = |
| 325 | (isSilentReboot && silentRebootTarget <= SILENT_REBOOT_TARGET_READER) ? silentRebootTarget : 0; |
| 326 | silentRebootMagic = 0; |
| 327 | silentRebootTarget = 0; |
| 328 | |
| 329 | gpio.begin(); |
| 330 | powerManager.begin(); |
| 331 | halTiltSensor.begin(); |
| 332 | halClock.begin(); |
| 333 | |
| 334 | LOG_INF("MAIN", "Hardware detect: %s", gpio.deviceIsX3() ? "X3" : "X4"); |
| 335 | |
| 336 | // SD Card Initialization |
| 337 | // We need 6 open files concurrently when parsing a new chapter |
| 338 | if (!Storage.begin()) { |
| 339 | LOG_ERR("MAIN", "SD card initialization failed"); |
| 340 | setupDisplayAndFonts(isSilentReboot); |
| 341 | activityManager.goToFullScreenMessage("SD card error", EpdFontFamily::BOLD); |
| 342 | return; |
| 343 | } |
| 344 | |
| 345 | HalSystem::checkPanic(); |
| 346 | |
| 347 | SETTINGS.loadFromFile(); |
| 348 | APP_STATE.loadFromFile(); |
| 349 | RECENT_BOOKS.loadFromFile(); |
| 350 | I18N.setLanguage(static_cast<Language>(SETTINGS.language)); |
| 351 | KOREADER_STORE.loadFromFile(); |
| 352 | OPDS_STORE.loadFromFile(); |
| 353 | UITheme::getInstance().reload(); |
| 354 | ButtonNavigator::setMappedInputManager(mappedInputManager); |
| 355 | |
| 356 | const auto wakeupReason = gpio.getWakeupReason(); |
| 357 | switch (wakeupReason) { |
| 358 | case HalGPIO::WakeupReason::PowerButton: |
| 359 | LOG_DBG("MAIN", "Verifying power button press duration"); |
| 360 | gpio.verifyPowerButtonWakeup(SETTINGS.getPowerButtonDuration(), |
| 361 | SETTINGS.shortPwrBtn == CrossPointSettings::SHORT_PWRBTN::SLEEP); |
| 362 | break; |
nothing calls this directly
no test coverage detected