2021-10-17 22:54:19 +00:00
|
|
|
#include <furi.h>
|
2022-01-05 16:10:18 +00:00
|
|
|
#include <furi_hal.h>
|
2021-10-17 22:54:19 +00:00
|
|
|
#include <flipper.h>
|
2022-04-13 20:50:25 +00:00
|
|
|
#include <alt_boot.h>
|
|
|
|
#include <semphr.h>
|
2022-05-06 16:26:25 +00:00
|
|
|
#include <update_util/update_operation.h>
|
2021-10-17 22:54:19 +00:00
|
|
|
|
2021-11-12 13:04:35 +00:00
|
|
|
#define TAG "Main"
|
|
|
|
|
2022-06-20 14:54:48 +00:00
|
|
|
int32_t init_task(void* context) {
|
|
|
|
UNUSED(context);
|
2022-04-13 20:50:25 +00:00
|
|
|
|
2021-10-17 22:54:19 +00:00
|
|
|
// Flipper FURI HAL
|
|
|
|
furi_hal_init();
|
|
|
|
|
|
|
|
// Init flipper
|
|
|
|
flipper_init();
|
|
|
|
|
2022-06-20 14:54:48 +00:00
|
|
|
return 0;
|
2021-10-17 22:54:19 +00:00
|
|
|
}
|
2022-04-21 13:15:19 +00:00
|
|
|
|
2022-04-13 20:50:25 +00:00
|
|
|
int main() {
|
|
|
|
// Initialize FURI layer
|
|
|
|
furi_init();
|
|
|
|
|
|
|
|
// Flipper critical FURI HAL
|
|
|
|
furi_hal_init_early();
|
2022-04-21 13:15:19 +00:00
|
|
|
|
2022-06-20 14:54:48 +00:00
|
|
|
FuriThread* main_thread = furi_thread_alloc();
|
|
|
|
furi_thread_set_name(main_thread, "Init");
|
|
|
|
furi_thread_set_stack_size(main_thread, 4096);
|
|
|
|
furi_thread_set_callback(main_thread, init_task);
|
|
|
|
|
2022-04-21 13:15:19 +00:00
|
|
|
#ifdef FURI_RAM_EXEC
|
2022-06-20 14:54:48 +00:00
|
|
|
furi_thread_start(main_thread);
|
2022-04-21 13:15:19 +00:00
|
|
|
#else
|
2022-04-13 20:50:25 +00:00
|
|
|
furi_hal_light_sequence("RGB");
|
|
|
|
|
|
|
|
// Delay is for button sampling
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_delay_ms(100);
|
2022-04-13 20:50:25 +00:00
|
|
|
|
|
|
|
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
|
2022-05-11 09:45:01 +00:00
|
|
|
furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal);
|
2022-04-13 20:50:25 +00:00
|
|
|
furi_hal_power_reset();
|
|
|
|
} else {
|
|
|
|
furi_hal_light_sequence("rgb G");
|
2022-06-20 14:54:48 +00:00
|
|
|
furi_thread_start(main_thread);
|
2022-04-13 20:50:25 +00:00
|
|
|
}
|
2022-04-21 13:15:19 +00:00
|
|
|
#endif
|
2022-04-13 20:50:25 +00:00
|
|
|
|
2022-04-21 13:15:19 +00:00
|
|
|
// Run Kernel
|
|
|
|
furi_run();
|
|
|
|
|
|
|
|
furi_crash("Kernel is Dead");
|
2022-04-13 20:50:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Error_Handler(void) {
|
|
|
|
furi_crash("ErrorHandler");
|
|
|
|
}
|
|
|
|
|
2022-04-23 01:56:59 +00:00
|
|
|
void abort() {
|
|
|
|
furi_crash("AbortHandler");
|
|
|
|
}
|