2021-10-18 01:54:19 +03:00
|
|
|
#include <furi.h>
|
2022-01-05 19:10:18 +03:00
|
|
|
#include <furi_hal.h>
|
2021-10-18 01:54:19 +03:00
|
|
|
#include <flipper.h>
|
2022-04-13 23:50:25 +03:00
|
|
|
#include <alt_boot.h>
|
|
|
|
#include <semphr.h>
|
2021-10-18 01:54:19 +03:00
|
|
|
|
2021-11-12 16:04:35 +03:00
|
|
|
#define TAG "Main"
|
|
|
|
|
2022-04-21 16:15:19 +03:00
|
|
|
static const osThreadAttr_t init_thread_attr = {
|
|
|
|
.name = "Init",
|
|
|
|
.stack_size = 4096,
|
|
|
|
};
|
2022-04-13 23:50:25 +03:00
|
|
|
|
2022-04-21 16:15:19 +03:00
|
|
|
void init_task() {
|
2021-10-18 01:54:19 +03:00
|
|
|
// Flipper FURI HAL
|
|
|
|
furi_hal_init();
|
|
|
|
|
|
|
|
// Init flipper
|
|
|
|
flipper_init();
|
|
|
|
|
2022-04-21 16:15:19 +03:00
|
|
|
osThreadExit();
|
2021-10-18 01:54:19 +03:00
|
|
|
}
|
2022-04-21 16:15:19 +03:00
|
|
|
|
2022-04-13 23:50:25 +03:00
|
|
|
int main() {
|
|
|
|
// Initialize FURI layer
|
|
|
|
furi_init();
|
|
|
|
|
|
|
|
// Flipper critical FURI HAL
|
|
|
|
furi_hal_init_early();
|
2022-04-21 16:15:19 +03:00
|
|
|
|
|
|
|
#ifdef FURI_RAM_EXEC
|
|
|
|
osThreadNew(init_task, NULL, &init_thread_attr);
|
|
|
|
#else
|
2022-04-13 23:50:25 +03:00
|
|
|
furi_hal_light_sequence("RGB");
|
|
|
|
|
|
|
|
// Delay is for button sampling
|
|
|
|
furi_hal_delay_ms(100);
|
|
|
|
|
|
|
|
FuriHalRtcBootMode boot_mode = furi_hal_rtc_get_boot_mode();
|
|
|
|
if(boot_mode == FuriHalRtcBootModeDfu || !furi_hal_gpio_read(&gpio_button_left)) {
|
|
|
|
furi_hal_light_sequence("rgb WB");
|
|
|
|
furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal);
|
|
|
|
flipper_boot_dfu_exec();
|
|
|
|
furi_hal_power_reset();
|
|
|
|
} else if(boot_mode == FuriHalRtcBootModeUpdate) {
|
|
|
|
furi_hal_light_sequence("rgb BR");
|
|
|
|
flipper_boot_update_exec();
|
|
|
|
// if things go nice, we shouldn't reach this point.
|
|
|
|
// But if we do, abandon to avoid bootloops
|
|
|
|
furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal);
|
|
|
|
furi_hal_power_reset();
|
|
|
|
} else {
|
|
|
|
furi_hal_light_sequence("rgb G");
|
2022-04-21 16:15:19 +03:00
|
|
|
osThreadNew(init_task, NULL, &init_thread_attr);
|
2022-04-13 23:50:25 +03:00
|
|
|
}
|
2022-04-21 16:15:19 +03:00
|
|
|
#endif
|
2022-04-13 23:50:25 +03:00
|
|
|
|
2022-04-21 16:15:19 +03:00
|
|
|
// Run Kernel
|
|
|
|
furi_run();
|
|
|
|
|
|
|
|
furi_crash("Kernel is Dead");
|
2022-04-13 23:50:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Error_Handler(void) {
|
|
|
|
furi_crash("ErrorHandler");
|
|
|
|
}
|
|
|
|
|
2022-04-23 04:56:59 +03:00
|
|
|
void abort() {
|
|
|
|
furi_crash("AbortHandler");
|
|
|
|
}
|