diff --git a/applications/external/playlist/playlist.c b/applications/external/playlist/playlist.c index 263b296e5fc..1ecfda02ad9 100644 --- a/applications/external/playlist/playlist.c +++ b/applications/external/playlist/playlist.c @@ -716,7 +716,8 @@ int32_t playlist_app(void* p) { // Auto switch to internal radio if external radio is not available furi_delay_ms(15); if(!furi_hal_subghz_check_radio()) { - furi_hal_subghz_set_radio_type(SubGhzRadioInternal); + furi_hal_subghz_select_radio_type(SubGhzRadioInternal); + furi_hal_subghz_init_radio_type(SubGhzRadioInternal); } furi_hal_power_suppress_charge_enter(); @@ -809,6 +810,8 @@ int32_t playlist_app(void* p) { 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(); + // Reinit SPI handles for internal radio / nfc + furi_hal_subghz_init_radio_type(SubGhzRadioInternal); if(app->worker != NULL) { if(playlist_worker_running(app->worker)) { diff --git a/applications/external/pocsag_pager/pocsag_pager_app.c b/applications/external/pocsag_pager/pocsag_pager_app.c index f5e989fba24..1013164f271 100644 --- a/applications/external/pocsag_pager/pocsag_pager_app.c +++ b/applications/external/pocsag_pager/pocsag_pager_app.c @@ -127,7 +127,8 @@ POCSAGPagerApp* pocsag_pager_app_alloc() { // Auto switch to internal radio if external radio is not available furi_delay_ms(15); if(!furi_hal_subghz_check_radio()) { - furi_hal_subghz_set_radio_type(SubGhzRadioInternal); + furi_hal_subghz_select_radio_type(SubGhzRadioInternal); + furi_hal_subghz_init_radio_type(SubGhzRadioInternal); } furi_hal_power_suppress_charge_enter(); @@ -145,6 +146,8 @@ void pocsag_pager_app_free(POCSAGPagerApp* app) { // Disable power for External CC1101 if it was enabled and module is connected furi_hal_subghz_disable_ext_power(); + // Reinit SPI handles for internal radio / nfc + furi_hal_subghz_init_radio_type(SubGhzRadioInternal); // Submenu view_dispatcher_remove_view(app->view_dispatcher, POCSAGPagerViewSubmenu); diff --git a/applications/external/protoview/app.c b/applications/external/protoview/app.c index 678c9d75f46..3e22b378184 100644 --- a/applications/external/protoview/app.c +++ b/applications/external/protoview/app.c @@ -172,7 +172,8 @@ ProtoViewApp* protoview_app_alloc() { // Auto switch to internal radio if external radio is not available furi_delay_ms(15); if(!furi_hal_subghz_check_radio()) { - furi_hal_subghz_set_radio_type(SubGhzRadioInternal); + furi_hal_subghz_select_radio_type(SubGhzRadioInternal); + furi_hal_subghz_init_radio_type(SubGhzRadioInternal); } furi_hal_power_suppress_charge_enter(); @@ -192,6 +193,8 @@ void protoview_app_free(ProtoViewApp* app) { // Disable power for External CC1101 if it was enabled and module is connected furi_hal_subghz_disable_ext_power(); + // Reinit SPI handles for internal radio / nfc + furi_hal_subghz_init_radio_type(SubGhzRadioInternal); // View related. view_port_enabled_set(app->view_port, false); diff --git a/applications/external/spectrum_analyzer/spectrum_analyzer.c b/applications/external/spectrum_analyzer/spectrum_analyzer.c index d38c6bf23af..26e41f0ce64 100644 --- a/applications/external/spectrum_analyzer/spectrum_analyzer.c +++ b/applications/external/spectrum_analyzer/spectrum_analyzer.c @@ -395,6 +395,8 @@ void spectrum_analyzer_free(SpectrumAnalyzer* instance) { // Disable power for External CC1101 if it was enabled and module is connected furi_hal_subghz_disable_ext_power(); + // Reinit SPI handles for internal radio / nfc + furi_hal_subghz_init_radio_type(SubGhzRadioInternal); } int32_t spectrum_analyzer_app(void* p) { @@ -408,7 +410,8 @@ int32_t spectrum_analyzer_app(void* p) { // Auto switch to internal radio if external radio is not available furi_delay_ms(15); if(!furi_hal_subghz_check_radio()) { - furi_hal_subghz_set_radio_type(SubGhzRadioInternal); + furi_hal_subghz_select_radio_type(SubGhzRadioInternal); + furi_hal_subghz_init_radio_type(SubGhzRadioInternal); } furi_hal_power_suppress_charge_enter(); diff --git a/applications/external/subbrute b/applications/external/subbrute index df12fcd72e1..c94efdf88ac 160000 --- a/applications/external/subbrute +++ b/applications/external/subbrute @@ -1 +1 @@ -Subproject commit df12fcd72e168fd1b3007ca767fe8ba13c024ba7 +Subproject commit c94efdf88ac2ed51b88caf288ab3c50afaaec9bb diff --git a/applications/external/weather_station/weather_station_app.c b/applications/external/weather_station/weather_station_app.c index a3135a6b007..8bea4961d75 100644 --- a/applications/external/weather_station/weather_station_app.c +++ b/applications/external/weather_station/weather_station_app.c @@ -110,7 +110,8 @@ WeatherStationApp* weather_station_app_alloc() { // Auto switch to internal radio if external radio is not available furi_delay_ms(15); if(!furi_hal_subghz_check_radio()) { - furi_hal_subghz_set_radio_type(SubGhzRadioInternal); + furi_hal_subghz_select_radio_type(SubGhzRadioInternal); + furi_hal_subghz_init_radio_type(SubGhzRadioInternal); } furi_hal_power_suppress_charge_enter(); @@ -128,6 +129,8 @@ void weather_station_app_free(WeatherStationApp* app) { // Disable power for External CC1101 if it was enabled and module is connected furi_hal_subghz_disable_ext_power(); + // Reinit SPI handles for internal radio / nfc + furi_hal_subghz_init_radio_type(SubGhzRadioInternal); // Submenu view_dispatcher_remove_view(app->view_dispatcher, WeatherStationViewSubmenu); diff --git a/applications/main/subghz/scenes/subghz_scene_ext_module_settings.c b/applications/main/subghz/scenes/subghz_scene_ext_module_settings.c index 75a2215fc33..508ca7dccd3 100644 --- a/applications/main/subghz/scenes/subghz_scene_ext_module_settings.c +++ b/applications/main/subghz/scenes/subghz_scene_ext_module_settings.c @@ -209,14 +209,16 @@ bool subghz_scene_ext_module_settings_on_event(void* context, SceneManagerEvent UNUSED(event); // Set selected radio module - furi_hal_subghz_set_radio_type(value_index_exm); + furi_hal_subghz_select_radio_type(value_index_exm); + furi_hal_subghz_init_radio_type(value_index_exm); furi_hal_subghz_enable_ext_power(); // Check if module is present, if no -> show error if(!furi_hal_subghz_check_radio()) { value_index_exm = 0; - furi_hal_subghz_set_radio_type(SubGhzRadioInternal); + furi_hal_subghz_select_radio_type(SubGhzRadioInternal); + furi_hal_subghz_init_radio_type(SubGhzRadioInternal); furi_string_set(subghz->error_str, "Please connect\nexternal radio"); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowErrorSub); } diff --git a/applications/main/subghz/scenes/subghz_scene_start.c b/applications/main/subghz/scenes/subghz_scene_start.c index eb14315a8b3..8777d2461f1 100644 --- a/applications/main/subghz/scenes/subghz_scene_start.c +++ b/applications/main/subghz/scenes/subghz_scene_start.c @@ -84,7 +84,8 @@ bool subghz_scene_start_on_event(void* context, SceneManagerEvent event) { furi_hal_subghz_enable_ext_power(); if(!furi_hal_subghz_check_radio()) { - furi_hal_subghz_set_radio_type(SubGhzRadioInternal); + furi_hal_subghz_select_radio_type(SubGhzRadioInternal); + furi_hal_subghz_init_radio_type(SubGhzRadioInternal); subghz->last_settings->external_module_enabled = false; furi_string_set(subghz->error_str, "Please connect\nexternal radio"); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowErrorSub); diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 75c6e627ab0..47da7ae40fd 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -451,7 +451,8 @@ int32_t subghz_app(void* p) { // Auto switch to internal radio if external radio is not available if(!furi_hal_subghz_check_radio()) { subghz->last_settings->external_module_enabled = false; - furi_hal_subghz_set_radio_type(SubGhzRadioInternal); + furi_hal_subghz_select_radio_type(SubGhzRadioInternal); + furi_hal_subghz_init_radio_type(SubGhzRadioInternal); } // Check argument and run corresponding scene if(p && strlen(p)) { @@ -507,6 +508,8 @@ int32_t subghz_app(void* p) { 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(); + // Reinit SPI handles for internal radio / nfc + furi_hal_subghz_init_radio_type(SubGhzRadioInternal); subghz_free(subghz, alloc_for_tx); diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index 2f4445a4212..7ee2554b0d6 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -129,7 +129,8 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count // Set selected radio module if(instance->external_module_enabled) { - furi_hal_subghz_set_radio_type(SubGhzRadioExternal); + furi_hal_subghz_select_radio_type(SubGhzRadioExternal); + furi_hal_subghz_init_radio_type(SubGhzRadioExternal); } /*/} else { diff --git a/applications/main/subghz_remote/subghz_remote_app.c b/applications/main/subghz_remote/subghz_remote_app.c index 64f866b876d..d215a1d0e6a 100644 --- a/applications/main/subghz_remote/subghz_remote_app.c +++ b/applications/main/subghz_remote/subghz_remote_app.c @@ -765,7 +765,8 @@ SubGHzRemote* subghz_remote_alloc(void) { // Auto switch to internal radio if external radio is not available furi_delay_ms(15); if(!furi_hal_subghz_check_radio()) { - furi_hal_subghz_set_radio_type(SubGhzRadioInternal); + furi_hal_subghz_select_radio_type(SubGhzRadioInternal); + furi_hal_subghz_init_radio_type(SubGhzRadioInternal); } furi_hal_power_suppress_charge_enter(); @@ -792,6 +793,8 @@ void subghz_remote_free(SubGHzRemote* app, bool with_subghz) { // Disable power for External CC1101 if it was enabled and module is connected furi_hal_subghz_disable_ext_power(); + // Reinit SPI handles for internal radio / nfc + furi_hal_subghz_init_radio_type(SubGhzRadioInternal); furi_string_free(app->up_file); furi_string_free(app->down_file); diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index d9cc6d21f12..a61e236c8e4 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -1377,6 +1377,7 @@ Function,+,furi_hal_subghz_get_timestamp_file_names,_Bool, Function,+,furi_hal_subghz_idle,void, Function,-,furi_hal_subghz_init,void, Function,+,furi_hal_subghz_init_check,_Bool, +Function,+,furi_hal_subghz_init_radio_type,_Bool,SubGhzRadioType Function,+,furi_hal_subghz_is_async_tx_complete,_Bool, Function,+,furi_hal_subghz_is_frequency_valid,_Bool,uint32_t Function,+,furi_hal_subghz_is_rx_data_crc_valid,_Bool, @@ -1389,12 +1390,12 @@ Function,+,furi_hal_subghz_read_packet,void,"uint8_t*, uint8_t*" Function,+,furi_hal_subghz_reset,void, Function,+,furi_hal_subghz_rx,void, Function,+,furi_hal_subghz_rx_pipe_not_empty,_Bool, +Function,+,furi_hal_subghz_select_radio_type,void,SubGhzRadioType Function,+,furi_hal_subghz_set_async_mirror_pin,void,const GpioPin* Function,+,furi_hal_subghz_set_external_power_disable,void,_Bool Function,+,furi_hal_subghz_set_frequency,uint32_t,uint32_t Function,+,furi_hal_subghz_set_frequency_and_path,uint32_t,uint32_t Function,+,furi_hal_subghz_set_path,void,FuriHalSubGhzPath -Function,+,furi_hal_subghz_set_radio_type,_Bool,SubGhzRadioType Function,+,furi_hal_subghz_set_rolling_counter_mult,void,uint8_t Function,+,furi_hal_subghz_set_timestamp_file_names,void,_Bool Function,-,furi_hal_subghz_shutdown,void, diff --git a/firmware/targets/f7/furi_hal/furi_hal_subghz.c b/firmware/targets/f7/furi_hal/furi_hal_subghz.c index 8667f2c5fd3..952e840fee2 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_subghz.c +++ b/firmware/targets/f7/furi_hal/furi_hal_subghz.c @@ -43,11 +43,14 @@ volatile FuriHalSubGhz furi_hal_subghz = { .timestamp_file_names = false, }; -bool furi_hal_subghz_set_radio_type(SubGhzRadioType state) { +void furi_hal_subghz_select_radio_type(SubGhzRadioType state) { furi_hal_subghz.radio_type = state; +} + +bool furi_hal_subghz_init_radio_type(SubGhzRadioType state) { furi_hal_spi_bus_handle_deinit(furi_hal_subghz.spi_bus_handle); - if(furi_hal_subghz.radio_type == SubGhzRadioInternal) { + if(state == SubGhzRadioInternal) { furi_hal_subghz.spi_bus_handle = &furi_hal_spi_bus_handle_subghz; furi_hal_subghz.cc1101_g0_pin = &gpio_cc1101_g0; } else { @@ -120,6 +123,8 @@ void furi_hal_subghz_disable_ext_power(void) { bool furi_hal_subghz_check_radio(void) { bool result = true; + furi_hal_subghz_init_radio_type(furi_hal_subghz.radio_type); + furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle); uint8_t ver = cc1101_get_version(furi_hal_subghz.spi_bus_handle); diff --git a/firmware/targets/f7/furi_hal/furi_hal_subghz.h b/firmware/targets/f7/furi_hal/furi_hal_subghz.h index b366e8578a5..35eab4faf83 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_subghz.h +++ b/firmware/targets/f7/furi_hal/furi_hal_subghz.h @@ -292,7 +292,7 @@ void furi_hal_subghz_stop_async_tx(); * @param state SubGhzRadioInternal or SubGhzRadioExternal * @return true if switching is successful */ -bool furi_hal_subghz_set_radio_type(SubGhzRadioType state); +bool furi_hal_subghz_init_radio_type(SubGhzRadioType state); /** Get current radio * @return SubGhzRadioInternal or SubGhzRadioExternal @@ -339,6 +339,10 @@ void furi_hal_subghz_set_timestamp_file_names(bool state); */ bool furi_hal_subghz_get_timestamp_file_names(void); +/** Set what radio module we will be using + */ +void furi_hal_subghz_select_radio_type(SubGhzRadioType state); + #ifdef __cplusplus } #endif