diff --git a/applications/main/subghz/scenes/subghz_scene_radio_settings.c b/applications/main/subghz/scenes/subghz_scene_radio_settings.c index 6fb6e5089..2ff2f565f 100644 --- a/applications/main/subghz/scenes/subghz_scene_radio_settings.c +++ b/applications/main/subghz/scenes/subghz_scene_radio_settings.c @@ -20,6 +20,12 @@ const char* const timestamp_names_text[TIMESTAMP_NAMES_COUNT] = { "ON", }; +#define EXT_MOD_POWER_AMP_COUNT 2 +const char* const ext_mod_power_amp_text[EXT_MOD_POWER_AMP_COUNT] = { + "OFF", + "ON", +}; + #define DEBUG_P_COUNT 2 const char* const debug_pin_text[DEBUG_P_COUNT] = { "OFF", @@ -105,6 +111,26 @@ static void subghz_scene_receiver_config_set_debug_counter(VariableItem* item) { // subghz_last_settings_save(subghz->last_settings); // } +static void subghz_scene_reciever_config_set_ext_mod_power_amp_text(VariableItem* item) { + SubGhz* subghz = variable_item_get_context(item); + uint8_t index = variable_item_get_current_value_index(item); + + variable_item_set_current_value_text(item, ext_mod_power_amp_text[index]); + + if(index == 1) { + furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull); + } else { + furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog); + } + + subghz->last_settings->external_module_power_amp = index == 1; + + // Set globally in furi hal + furi_hal_subghz_set_ext_power_amp(subghz->last_settings->external_module_power_amp); + + subghz_last_settings_save(subghz->last_settings); +} + static void subghz_scene_receiver_config_set_timestamp_file_names(VariableItem* item) { SubGhz* subghz = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); @@ -139,7 +165,17 @@ void subghz_scene_radio_settings_on_enter(void* context) { item = variable_item_list_add( variable_item_list, - "Time in names", + "Ext Power Amp", + EXT_MOD_POWER_AMP_COUNT, + subghz_scene_reciever_config_set_ext_mod_power_amp_text, + subghz); + value_index = subghz->last_settings->external_module_power_amp ? 1 : 0; + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, ext_mod_power_amp_text[value_index]); + + item = variable_item_list_add( + variable_item_list, + "Time In Names", TIMESTAMP_NAMES_COUNT, subghz_scene_receiver_config_set_timestamp_file_names, subghz); @@ -150,7 +186,7 @@ void subghz_scene_radio_settings_on_enter(void* context) { if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { item = variable_item_list_add( variable_item_list, - "Counter incr.", + "Counter Incr.", DEBUG_COUNTER_COUNT, subghz_scene_receiver_config_set_debug_counter, subghz); @@ -179,7 +215,7 @@ void subghz_scene_radio_settings_on_enter(void* context) { } else { item = variable_item_list_add( variable_item_list, - "Counter incr.", + "Counter Incr.", 3, subghz_scene_receiver_config_set_debug_counter, subghz); diff --git a/applications/main/subghz/subghz_dangerous_freq.c b/applications/main/subghz/subghz_dangerous_freq.c index 69a54f04b..8552c5f16 100644 --- a/applications/main/subghz/subghz_dangerous_freq.c +++ b/applications/main/subghz/subghz_dangerous_freq.c @@ -5,6 +5,8 @@ #include +#include + void subghz_dangerous_freq() { bool is_extended_i = false; @@ -19,5 +21,16 @@ void subghz_dangerous_freq() { furi_hal_subghz_set_dangerous_frequency(is_extended_i); flipper_format_free(fff_data_file); + + // Load external module power amp setting (TODO: move to other place) + // TODO: Disable this when external module is not CC1101 E07 + SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); + subghz_last_settings_load(last_settings, 0); + + // Set globally in furi hal + furi_hal_subghz_set_ext_power_amp(last_settings->external_module_power_amp); + + subghz_last_settings_free(last_settings); + furi_record_close(RECORD_STORAGE); } diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index b61ed3769..465312b19 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -20,6 +20,7 @@ #define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_ENABLED "External" #define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER "ExtPower" #define SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES "TimestampNames" +#define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP "ExtPowerAmp" SubGhzLastSettings* subghz_last_settings_alloc(void) { SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings)); @@ -46,6 +47,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count float temp_frequency_analyzer_trigger = 0; bool temp_external_module_enabled = false; bool temp_external_module_power_5v_disable = false; + bool temp_external_module_power_amp = false; bool temp_timestamp_file_names = false; //int32_t temp_preset = 0; bool frequency_analyzer_feedback_level_was_read = false; @@ -83,6 +85,11 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES, (bool*)&temp_timestamp_file_names, 1); + flipper_format_read_bool( + fff_data_file, + SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP, + (bool*)&temp_external_module_power_amp, + 1); } else { FURI_LOG_E(TAG, "Error open file %s", SUBGHZ_LAST_SETTINGS_PATH); @@ -97,6 +104,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count instance->frequency_analyzer_trigger = SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER; instance->external_module_enabled = false; instance->timestamp_file_names = false; + instance->external_module_power_amp = false; } else { instance->frequency = temp_frequency; @@ -119,6 +127,12 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count instance->timestamp_file_names = temp_timestamp_file_names; + // External power amp CC1101 + instance->external_module_power_amp = temp_external_module_power_amp; + + // Set globally in furi hal + furi_hal_subghz_set_ext_power_amp(instance->external_module_power_amp); + /*/} else { instance->preset = temp_preset; }*/ @@ -196,6 +210,13 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { 1)) { break; } + if(!flipper_format_insert_or_update_bool( + file, + SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP, + &instance->external_module_power_amp, + 1)) { + break; + } saved = true; } while(0); diff --git a/applications/main/subghz/subghz_last_settings.h b/applications/main/subghz/subghz_last_settings.h index d1a5b495f..c351cb6a5 100644 --- a/applications/main/subghz/subghz_last_settings.h +++ b/applications/main/subghz/subghz_last_settings.h @@ -13,6 +13,7 @@ typedef struct { // TODO not using but saved so as not to change the version bool external_module_enabled; bool external_module_power_5v_disable; + bool external_module_power_amp; // saved so as not to change the version bool timestamp_file_names; } SubGhzLastSettings; diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index 81cae4013..a6807e131 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -1401,6 +1401,7 @@ Function,-,furi_hal_subghz_dump_state,void, Function,+,furi_hal_subghz_flush_rx,void, Function,+,furi_hal_subghz_flush_tx,void, Function,+,furi_hal_subghz_get_data_gpio,const GpioPin*, +Function,+,furi_hal_subghz_get_ext_power_amp,_Bool, Function,+,furi_hal_subghz_get_lqi,uint8_t, Function,+,furi_hal_subghz_get_rolling_counter_mult,uint8_t, Function,+,furi_hal_subghz_get_rssi,float, @@ -1418,6 +1419,7 @@ 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_set_async_mirror_pin,void,const GpioPin* +Function,+,furi_hal_subghz_set_ext_power_amp,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 diff --git a/firmware/targets/f7/furi_hal/furi_hal_subghz.c b/firmware/targets/f7/furi_hal/furi_hal_subghz.c index 936d685fe..b651fc59f 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_subghz.c +++ b/firmware/targets/f7/furi_hal/furi_hal_subghz.c @@ -53,7 +53,7 @@ typedef struct { const GpioPin* async_mirror_pin; uint8_t rolling_counter_mult; - bool timestamp_file_names : 1; + bool ext_power_amp : 1; bool dangerous_frequency_i : 1; } FuriHalSubGhz; @@ -62,6 +62,7 @@ volatile FuriHalSubGhz furi_hal_subghz = { .regulation = SubGhzRegulationTxRx, .async_mirror_pin = NULL, .rolling_counter_mult = 1, + .ext_power_amp = false, .dangerous_frequency_i = false, }; @@ -77,6 +78,14 @@ void furi_hal_subghz_set_dangerous_frequency(bool state_i) { furi_hal_subghz.dangerous_frequency_i = state_i; } +void furi_hal_subghz_set_ext_power_amp(bool enabled) { + furi_hal_subghz.ext_power_amp = enabled; +} + +bool furi_hal_subghz_get_ext_power_amp() { + return furi_hal_subghz.ext_power_amp; +} + void furi_hal_subghz_set_async_mirror_pin(const GpioPin* pin) { furi_hal_subghz.async_mirror_pin = pin; } diff --git a/firmware/targets/f7/furi_hal/furi_hal_subghz.h b/firmware/targets/f7/furi_hal/furi_hal_subghz.h index c7249e1a6..b390ac6cc 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_subghz.h +++ b/firmware/targets/f7/furi_hal/furi_hal_subghz.h @@ -282,6 +282,11 @@ void furi_hal_subghz_stop_async_tx(); // */ // void furi_hal_subghz_select_radio_type(SubGhzRadioType state); +// External CC1101 Ebytes power amplifier control +void furi_hal_subghz_set_ext_power_amp(bool enabled); + +bool furi_hal_subghz_get_ext_power_amp(); + #ifdef __cplusplus } #endif diff --git a/lib/subghz/devices/devices.c b/lib/subghz/devices/devices.c index a90bf73a3..98cb0f609 100644 --- a/lib/subghz/devices/devices.c +++ b/lib/subghz/devices/devices.c @@ -30,6 +30,13 @@ bool subghz_devices_begin(const SubGhzDevice* device) { bool ret = false; furi_assert(device); if(device->interconnect->begin) { + // TODO: Remake this check and move this code + if(strcmp("cc1101_ext", device->name) == 0) { + if(furi_hal_subghz_get_ext_power_amp()) { + furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull); + } + } + ret = device->interconnect->begin(); } return ret; @@ -38,6 +45,12 @@ bool subghz_devices_begin(const SubGhzDevice* device) { void subghz_devices_end(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->end) { + // TODO: Remake this check and move this code + if(strcmp("cc1101_ext", device->name) == 0) { + if(furi_hal_subghz_get_ext_power_amp()) { + furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog); + } + } device->interconnect->end(); } } @@ -69,6 +82,12 @@ void subghz_devices_idle(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->idle) { device->interconnect->idle(); + // TODO: Remake this check and move this code + if(strcmp("cc1101_ext", device->name) == 0) { + if(furi_hal_subghz_get_ext_power_amp()) { + furi_hal_gpio_write(&gpio_ext_pc3, 0); + } + } } } @@ -121,6 +140,13 @@ bool subghz_devices_set_tx(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->set_tx) { ret = device->interconnect->set_tx(); + + // TODO: Remake this check and move this code + if(strcmp("cc1101_ext", device->name) == 0) { + if(furi_hal_subghz_get_ext_power_amp()) { + furi_hal_gpio_write(&gpio_ext_pc3, 1); + } + } } return ret; } @@ -161,6 +187,13 @@ void subghz_devices_set_rx(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->set_rx) { device->interconnect->set_rx(); + + // TODO: Remake this check and move this code + if(strcmp("cc1101_ext", device->name) == 0) { + if(furi_hal_subghz_get_ext_power_amp()) { + furi_hal_gpio_write(&gpio_ext_pc3, 0); + } + } } }