Skip to content

Commit

Permalink
Fix external radio SPI handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
xMasterX committed Apr 23, 2023
1 parent 69530cd commit 8cb3b67
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 16 deletions.
5 changes: 4 additions & 1 deletion applications/external/playlist/playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)) {
Expand Down
5 changes: 4 additions & 1 deletion applications/external/pocsag_pager/pocsag_pager_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion applications/external/protoview/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion applications/external/spectrum_analyzer/spectrum_analyzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion applications/external/subbrute
Submodule subbrute updated 1 files
+4 −1 subbrute.c
5 changes: 4 additions & 1 deletion applications/external/weather_station/weather_station_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion applications/main/subghz/scenes/subghz_scene_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion applications/main/subghz/subghz.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion applications/main/subghz/subghz_last_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion applications/main/subghz_remote/subghz_remote_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion firmware/targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions firmware/targets/f7/furi_hal/furi_hal_subghz.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion firmware/targets/f7/furi_hal/furi_hal_subghz.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 8cb3b67

Please sign in to comment.