mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-14 07:08:36 -07:00
Random cleanup and housekeeping
This commit is contained in:
@@ -193,47 +193,15 @@ static void storage_int_lfs_mount(LFSData* lfs_data, StorageData* storage) {
|
||||
was_fingerprint_outdated;
|
||||
|
||||
if(need_format) {
|
||||
// Backup U2F keys
|
||||
// lfs_file_t file;
|
||||
// uint8_t* key = NULL;
|
||||
// uint32_t key_size;
|
||||
// if(lfs_mount(lfs, &lfs_data->config) == 0) {
|
||||
// FURI_LOG_I(TAG, "Factory reset: Mounted for backup");
|
||||
|
||||
// if(lfs_file_open(lfs, &file, ".key.u2f", LFS_O_RDONLY) == 0) {
|
||||
// key_size = file.ctz.size;
|
||||
// key = malloc(key_size);
|
||||
// if(lfs_file_read(lfs, &file, key, key_size) != (int32_t)key_size) {
|
||||
// free(key);
|
||||
// key = NULL;
|
||||
// }
|
||||
// lfs_file_close(lfs, &file);
|
||||
// }
|
||||
|
||||
// if(lfs_unmount(lfs) == 0) {
|
||||
// FURI_LOG_E(TAG, "Factory reset: Unmounted after backup");
|
||||
// } else {
|
||||
// FURI_LOG_E(TAG, "Factory reset: Unmount after backup failed");
|
||||
// }
|
||||
// } else {
|
||||
// FURI_LOG_E(TAG, "Factory reset: Mount for backup failed");
|
||||
// }
|
||||
|
||||
// Format storage
|
||||
if(lfs_format(lfs, &lfs_data->config) == 0) {
|
||||
err = lfs_format(lfs, &lfs_data->config);
|
||||
if(err == 0) {
|
||||
FURI_LOG_I(TAG, "Factory reset: Format successful, trying to mount");
|
||||
furi_hal_rtc_reset_flag(FuriHalRtcFlagFactoryReset);
|
||||
if(lfs_mount(lfs, &lfs_data->config) == 0) {
|
||||
err = lfs_mount(lfs, &lfs_data->config);
|
||||
if(err == 0) {
|
||||
FURI_LOG_I(TAG, "Factory reset: Mounted");
|
||||
storage->status = StorageStatusOK;
|
||||
|
||||
// Restore U2F keys
|
||||
// if(key != NULL) {
|
||||
// if(lfs_file_open(lfs, &file, ".key.u2f", LFS_O_WRONLY | LFS_O_CREAT) == 0) {
|
||||
// lfs_file_write(lfs, &file, key, key_size);
|
||||
// lfs_file_close(lfs, &file);
|
||||
// }
|
||||
// }
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Factory reset: Mount after format failed");
|
||||
storage->status = StorageStatusNotMounted;
|
||||
@@ -242,7 +210,6 @@ static void storage_int_lfs_mount(LFSData* lfs_data, StorageData* storage) {
|
||||
FURI_LOG_E(TAG, "Factory reset: Format failed");
|
||||
storage->status = StorageStatusNoFS;
|
||||
}
|
||||
// if(key != NULL) free(key);
|
||||
} else {
|
||||
// Normal
|
||||
err = lfs_mount(lfs, &lfs_data->config);
|
||||
|
||||
@@ -1334,7 +1334,6 @@ Function,+,gui_get_framebuffer_size,size_t,const Gui*
|
||||
Function,+,gui_remove_framebuffer_callback,void,"Gui*, GuiCanvasCommitCallback, void*"
|
||||
Function,+,gui_remove_view_port,void,"Gui*, ViewPort*"
|
||||
Function,+,gui_set_lockdown,void,"Gui*, _Bool"
|
||||
Function,+,gui_set_hide_statusbar,void,"Gui*, _Bool"
|
||||
Function,-,gui_view_port_send_to_back,void,"Gui*, ViewPort*"
|
||||
Function,+,gui_view_port_send_to_front,void,"Gui*, ViewPort*"
|
||||
Function,+,hal_sd_detect,_Bool,
|
||||
|
||||
|
@@ -27,7 +27,6 @@
|
||||
"one_wire",
|
||||
"misc",
|
||||
"flipper_application",
|
||||
"pulse_reader",
|
||||
"flipperformat",
|
||||
"toolbox",
|
||||
"flipper18"
|
||||
|
||||
@@ -520,16 +520,6 @@ bool gap_init(GapConfig* config, GapEventCallback on_event_cb, void* context) {
|
||||
gap->advertise_timer = furi_timer_alloc(gap_advetise_timer_callback, FuriTimerTypeOnce, NULL);
|
||||
// Initialization of GATT & GAP layer
|
||||
gap->service.adv_name = config->adv_name;
|
||||
FURI_LOG_D(TAG, "Advertising name: %s", &(gap->service.adv_name[1]));
|
||||
FURI_LOG_D(
|
||||
TAG,
|
||||
"MAC @ : %02X:%02X:%02X:%02X:%02X:%02X",
|
||||
config->mac_address[5],
|
||||
config->mac_address[4],
|
||||
config->mac_address[3],
|
||||
config->mac_address[2],
|
||||
config->mac_address[1],
|
||||
config->mac_address[0]);
|
||||
gap_init_svc(gap);
|
||||
// Initialization of the BLE Services
|
||||
SVCCTL_Init();
|
||||
|
||||
@@ -461,40 +461,6 @@ uint32_t furi_hal_bt_get_conn_rssi(uint8_t* rssi) {
|
||||
return since;
|
||||
}
|
||||
|
||||
uint32_t furi_hal_bt_get_transmitted_packets() {
|
||||
uint32_t packets = 0;
|
||||
aci_hal_le_tx_test_packet_number(&packets);
|
||||
return packets;
|
||||
}
|
||||
|
||||
void furi_hal_bt_stop_rx() {
|
||||
aci_hal_rx_stop();
|
||||
}
|
||||
|
||||
bool furi_hal_bt_ensure_c2_mode(BleGlueC2Mode mode) {
|
||||
BleGlueCommandResult fw_start_res = ble_glue_force_c2_mode(mode);
|
||||
if(fw_start_res == BleGlueCommandResultOK) {
|
||||
return true;
|
||||
} else if(fw_start_res == BleGlueCommandResultRestartPending) {
|
||||
// Do nothing and wait for system reset
|
||||
furi_delay_ms(C2_MODE_SWITCH_TIMEOUT);
|
||||
furi_crash("Waiting for FUS->radio stack transition");
|
||||
return true;
|
||||
}
|
||||
|
||||
FURI_LOG_E(TAG, "Failed to switch C2 mode: %d", fw_start_res);
|
||||
return false;
|
||||
}
|
||||
|
||||
const FuriHalBtHardfaultInfo* furi_hal_bt_get_hardfault_info() {
|
||||
/* AN5289, 4.8.2 */
|
||||
const FuriHalBtHardfaultInfo* info = (FuriHalBtHardfaultInfo*)(SRAM2A_BASE);
|
||||
if(info->magic != FURI_HAL_BT_HARDFAULT_INFO_MAGIC) {
|
||||
return NULL;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
void furi_hal_bt_set_profile_adv_name(
|
||||
FuriHalBtProfile profile,
|
||||
const char name[FURI_HAL_BT_ADV_NAME_LENGTH]) {
|
||||
@@ -540,3 +506,37 @@ GapPairing furi_hal_bt_get_profile_pairing_method(FuriHalBtProfile profile) {
|
||||
furi_assert(profile < FuriHalBtProfileNumber);
|
||||
return profile_config[profile].config.pairing_method;
|
||||
}
|
||||
|
||||
uint32_t furi_hal_bt_get_transmitted_packets() {
|
||||
uint32_t packets = 0;
|
||||
aci_hal_le_tx_test_packet_number(&packets);
|
||||
return packets;
|
||||
}
|
||||
|
||||
void furi_hal_bt_stop_rx() {
|
||||
aci_hal_rx_stop();
|
||||
}
|
||||
|
||||
bool furi_hal_bt_ensure_c2_mode(BleGlueC2Mode mode) {
|
||||
BleGlueCommandResult fw_start_res = ble_glue_force_c2_mode(mode);
|
||||
if(fw_start_res == BleGlueCommandResultOK) {
|
||||
return true;
|
||||
} else if(fw_start_res == BleGlueCommandResultRestartPending) {
|
||||
// Do nothing and wait for system reset
|
||||
furi_delay_ms(C2_MODE_SWITCH_TIMEOUT);
|
||||
furi_crash("Waiting for FUS->radio stack transition");
|
||||
return true;
|
||||
}
|
||||
|
||||
FURI_LOG_E(TAG, "Failed to switch C2 mode: %d", fw_start_res);
|
||||
return false;
|
||||
}
|
||||
|
||||
const FuriHalBtHardfaultInfo* furi_hal_bt_get_hardfault_info() {
|
||||
/* AN5289, 4.8.2 */
|
||||
const FuriHalBtHardfaultInfo* info = (FuriHalBtHardfaultInfo*)(SRAM2A_BASE);
|
||||
if(info->magic != FURI_HAL_BT_HARDFAULT_INFO_MAGIC) {
|
||||
return NULL;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@@ -48,10 +48,6 @@ void furi_hal_clock_init() {
|
||||
LL_RCC_LSI1_Enable();
|
||||
while(!LS_CLOCK_IS_READY())
|
||||
;
|
||||
|
||||
/* RF wakeup */
|
||||
LL_RCC_SetRFWKPClockSource(LL_RCC_RFWKP_CLKSOURCE_LSE);
|
||||
|
||||
LL_EXTI_EnableIT_0_31(
|
||||
LL_EXTI_LINE_18); /* Why? Because that's why. See RM0434, Table 61. CPU1 vector table. */
|
||||
LL_EXTI_EnableRisingTrig_0_31(LL_EXTI_LINE_18);
|
||||
@@ -115,7 +111,7 @@ void furi_hal_clock_init() {
|
||||
|
||||
LL_RCC_SetCLK48ClockSource(LL_RCC_CLK48_CLKSOURCE_PLLSAI1);
|
||||
LL_RCC_HSI_EnableInStopMode(); // Ensure that MR is capable of work in STOP0
|
||||
LL_RCC_SetSMPSClockSource(LL_RCC_SMPS_CLKSOURCE_HSI);
|
||||
LL_RCC_SetSMPSClockSource(LL_RCC_SMPS_CLKSOURCE_HSE);
|
||||
LL_RCC_SetSMPSPrescaler(LL_RCC_SMPS_DIV_1);
|
||||
LL_RCC_SetRFWKPClockSource(LL_RCC_RFWKP_CLKSOURCE_LSE);
|
||||
|
||||
@@ -128,8 +124,8 @@ void furi_hal_clock_switch_to_hsi() {
|
||||
while(!LL_RCC_HSI_IsReady())
|
||||
;
|
||||
|
||||
LL_RCC_SetSMPSClockSource(LL_RCC_SMPS_CLKSOURCE_HSI);
|
||||
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSI);
|
||||
furi_assert(LL_RCC_GetSMPSClockSource() == LL_RCC_SMPS_CLKSOURCE_HSI);
|
||||
|
||||
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSI)
|
||||
;
|
||||
@@ -160,6 +156,7 @@ void furi_hal_clock_switch_to_pll() {
|
||||
;
|
||||
|
||||
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
|
||||
LL_RCC_SetSMPSClockSource(LL_RCC_SMPS_CLKSOURCE_HSE);
|
||||
|
||||
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
|
||||
;
|
||||
|
||||
@@ -106,15 +106,15 @@ void furi_hal_version_set_name(const char* name) {
|
||||
|
||||
// BLE Mac address
|
||||
uint32_t udn = LL_FLASH_GetUDN();
|
||||
if(name != NULL) {
|
||||
udn = *((uint32_t*)name);
|
||||
if(version_get_custom_name(NULL) != NULL) {
|
||||
udn = *((uint32_t*)version_get_custom_name(NULL));
|
||||
}
|
||||
|
||||
uint32_t company_id = LL_FLASH_GetSTCompanyID();
|
||||
// uint32_t device_id = LL_FLASH_GetDeviceID();
|
||||
// Somehow some new flippers return 0x27 instead of 0x26
|
||||
// Mobile apps expects it to return 0x26 (and clearly STM too)
|
||||
// Temporarely hardcoded until cause / fix is found
|
||||
// Hardcoded here instead of the stupid "Flipper" name "fix"
|
||||
uint32_t device_id = 0x26;
|
||||
furi_hal_version.ble_mac[0] = (uint8_t)(udn & 0x000000FF);
|
||||
furi_hal_version.ble_mac[1] = (uint8_t)((udn & 0x0000FF00) >> 8);
|
||||
|
||||
Reference in New Issue
Block a user