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

Function setup

src/main.cpp:305–481  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

303}
304
305void 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;

Callers

nothing calls this directly

Calls 15

beginFunction · 0.85
setupDisplayAndFontsFunction · 0.85
checkPanicFunction · 0.85
loadSleepFrameBufferFunction · 0.85
isRebootFromPanicFunction · 0.85
waitForPowerReleaseFunction · 0.85
deviceIsX3Method · 0.80
goToFullScreenMessageMethod · 0.80
setLanguageMethod · 0.80
reloadMethod · 0.80
getWakeupReasonMethod · 0.80

Tested by

no test coverage detected