diff --git a/applications/main/unirfremix/unirfremix_app.c b/applications/main/unirfremix/unirfremix_app.c index b7295754c..fae194b26 100644 --- a/applications/main/unirfremix/unirfremix_app.c +++ b/applications/main/unirfremix/unirfremix_app.c @@ -402,7 +402,8 @@ bool unirfremix_key_load( preset->decoder = subghz_receiver_search_decoder_base_by_name( receiver, furi_string_get_cstr(preset->protocol)); if(preset->decoder) { - SubGhzProtocolStatus status = subghz_protocol_decoder_base_deserialize(preset->decoder, fff_data); + SubGhzProtocolStatus status = + subghz_protocol_decoder_base_deserialize(preset->decoder, fff_data); if(status != SubGhzProtocolStatusOk) { FURI_LOG_E(TAG, "Protocol deserialize failed, status = %d", status); break; @@ -736,6 +737,8 @@ UniRFRemix* unirfremix_alloc(void) { UniRFRemix* app = malloc(sizeof(UniRFRemix)); furi_hal_power_suppress_charge_enter(); + // Enable power for External CC1101 if it is connected + furi_hal_subghz_enable_ext_power(); app->model_mutex = furi_mutex_alloc(FuriMutexTypeNormal); @@ -757,6 +760,9 @@ UniRFRemix* unirfremix_alloc(void) { void unirfremix_free(UniRFRemix* app, bool with_subghz) { furi_hal_power_suppress_charge_exit(); + // Disable power for External CC1101 if it was enabled and module is connected + furi_hal_subghz_disable_ext_power(); + furi_string_free(app->up_file); furi_string_free(app->down_file); furi_string_free(app->left_file); diff --git a/applications/plugins/playlist/playlist.c b/applications/plugins/playlist/playlist.c index 9946fb95b..a6aa09cba 100644 --- a/applications/plugins/playlist/playlist.c +++ b/applications/plugins/playlist/playlist.c @@ -674,6 +674,9 @@ int32_t playlist_app(void* p) { furi_hal_power_suppress_charge_enter(); + // Enable power for External CC1101 if it is connected + furi_hal_subghz_enable_ext_power(); + // select playlist file { DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS); @@ -752,6 +755,8 @@ int32_t playlist_app(void* p) { exit_cleanup: furi_hal_power_suppress_charge_exit(); + // Disable power for External CC1101 if it was enabled and module is connected + furi_hal_subghz_disable_ext_power(); if(app->worker != NULL) { if(playlist_worker_running(app->worker)) { diff --git a/applications/plugins/pocsag_pager/pocsag_pager_app.c b/applications/plugins/pocsag_pager/pocsag_pager_app.c index 3ac242304..680edb2a5 100644 --- a/applications/plugins/pocsag_pager/pocsag_pager_app.c +++ b/applications/plugins/pocsag_pager/pocsag_pager_app.c @@ -124,6 +124,9 @@ POCSAGPagerApp* pocsag_pager_app_alloc() { furi_hal_power_suppress_charge_enter(); + // Enable power for External CC1101 if it is connected + furi_hal_subghz_enable_ext_power(); + scene_manager_next_scene(app->scene_manager, POCSAGPagerSceneStart); return app; @@ -135,6 +138,9 @@ void pocsag_pager_app_free(POCSAGPagerApp* app) { //CC1101 off pcsg_sleep(app); + // Disable power for External CC1101 if it was enabled and module is connected + furi_hal_subghz_disable_ext_power(); + // Submenu view_dispatcher_remove_view(app->view_dispatcher, POCSAGPagerViewSubmenu); submenu_free(app->submenu); diff --git a/applications/plugins/protoview/app.c b/applications/plugins/protoview/app.c index d27b3a54a..7dc8a7b83 100644 --- a/applications/plugins/protoview/app.c +++ b/applications/plugins/protoview/app.c @@ -170,6 +170,9 @@ ProtoViewApp* protoview_app_alloc() { furi_hal_power_suppress_charge_enter(); app->running = 1; + // Enable power for External CC1101 if it is connected + furi_hal_subghz_enable_ext_power(); + return app; } @@ -182,6 +185,9 @@ void protoview_app_free(ProtoViewApp* app) { // Put CC1101 on sleep, this also restores charging. radio_sleep(app); + // Disable power for External CC1101 if it was enabled and module is connected + furi_hal_subghz_disable_ext_power(); + // View related. view_port_enabled_set(app->view_port, false); gui_remove_view_port(app->gui, app->view_port); diff --git a/applications/plugins/spectrum_analyzer/spectrum_analyzer.c b/applications/plugins/spectrum_analyzer/spectrum_analyzer.c index 8d68c5a1a..10471e473 100644 --- a/applications/plugins/spectrum_analyzer/spectrum_analyzer.c +++ b/applications/plugins/spectrum_analyzer/spectrum_analyzer.c @@ -392,6 +392,9 @@ void spectrum_analyzer_free(SpectrumAnalyzer* instance) { furi_hal_subghz_idle(); furi_hal_subghz_sleep(); + + // Disable power for External CC1101 if it was enabled and module is connected + furi_hal_subghz_disable_ext_power(); } int32_t spectrum_analyzer_app(void* p) { @@ -402,6 +405,9 @@ int32_t spectrum_analyzer_app(void* p) { furi_hal_power_suppress_charge_enter(); + // Enable power for External CC1101 if it is connected + furi_hal_subghz_enable_ext_power(); + FURI_LOG_D("Spectrum", "Main Loop - Starting worker"); furi_delay_ms(50); diff --git a/applications/plugins/subbrute b/applications/plugins/subbrute index 7cdb9e138..552bd12d0 160000 --- a/applications/plugins/subbrute +++ b/applications/plugins/subbrute @@ -1 +1 @@ -Subproject commit 7cdb9e1386778ad7351f7e3b3389980afaeafea3 +Subproject commit 552bd12d0f710501c31f7d44b4755d7fa89de303 diff --git a/applications/plugins/weather_station/weather_station_app.c b/applications/plugins/weather_station/weather_station_app.c index b17f2acfc..0d83095b5 100644 --- a/applications/plugins/weather_station/weather_station_app.c +++ b/applications/plugins/weather_station/weather_station_app.c @@ -107,6 +107,9 @@ WeatherStationApp* weather_station_app_alloc() { furi_hal_power_suppress_charge_enter(); + // Enable power for External CC1101 if it is connected + furi_hal_subghz_enable_ext_power(); + scene_manager_next_scene(app->scene_manager, WeatherStationSceneStart); return app; @@ -118,6 +121,9 @@ void weather_station_app_free(WeatherStationApp* app) { //CC1101 off ws_sleep(app); + // Disable power for External CC1101 if it was enabled and module is connected + furi_hal_subghz_disable_ext_power(); + // Submenu view_dispatcher_remove_view(app->view_dispatcher, WeatherStationViewSubmenu); submenu_free(app->submenu); diff --git a/firmware/targets/f7/furi_hal/furi_hal_subghz.c b/firmware/targets/f7/furi_hal/furi_hal_subghz.c index 451cda439..e4a118652 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_subghz.c +++ b/firmware/targets/f7/furi_hal/furi_hal_subghz.c @@ -22,6 +22,7 @@ static uint32_t furi_hal_subghz_debug_gpio_buff[2]; static bool last_OTG_state = false; +static bool ext_power_is_enabled_already = false; /* DMA Channels definition */ #define SUBGHZ_DMA DMA2 @@ -80,12 +81,16 @@ void furi_hal_subghz_init(void) { } void furi_hal_subghz_enable_ext_power(void) { + if(ext_power_is_enabled_already) return; + ext_power_is_enabled_already = true; + last_OTG_state = furi_hal_power_is_otg_enabled(); if(furi_hal_subghz.radio_type != SubGhzRadioInternal && !furi_hal_power_is_otg_enabled()) { furi_hal_power_enable_otg(); } } void furi_hal_subghz_disable_ext_power(void) { + ext_power_is_enabled_already = false; if(furi_hal_subghz.radio_type != SubGhzRadioInternal && !last_OTG_state) { furi_hal_power_disable_otg(); } @@ -97,6 +102,7 @@ bool furi_hal_subghz_check_radio(void) { furi_hal_subghz_enable_ext_power(); furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle); + uint8_t ver = cc1101_get_version(furi_hal_subghz.spi_bus_handle); furi_hal_spi_release(furi_hal_subghz.spi_bus_handle); @@ -104,9 +110,10 @@ bool furi_hal_subghz_check_radio(void) { FURI_LOG_D(TAG, "Radio check ok"); } else { FURI_LOG_D(TAG, "Radio check failed"); - furi_hal_subghz_disable_ext_power(); + result = false; } + furi_hal_subghz_disable_ext_power(); return result; } @@ -117,7 +124,6 @@ bool furi_hal_subghz_init_check(void) { furi_hal_subghz.state = SubGhzStateIdle; furi_hal_subghz.preset = FuriHalSubGhzPresetIDLE; - last_OTG_state = furi_hal_power_is_otg_enabled(); furi_hal_subghz_enable_ext_power(); furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle); @@ -169,8 +175,8 @@ bool furi_hal_subghz_init_check(void) { FURI_LOG_I(TAG, "Init OK"); } else { FURI_LOG_E(TAG, "Failed to initialization"); - furi_hal_subghz_disable_ext_power(); } + furi_hal_subghz_disable_ext_power(); return result; } @@ -346,6 +352,7 @@ void furi_hal_subghz_reset() { } void furi_hal_subghz_idle() { + furi_hal_subghz_enable_ext_power(); furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle); cc1101_switch_to_idle(furi_hal_subghz.spi_bus_handle); furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);