Merge pull request #559 from Z3BRO/dev

SubGHz External High Power
This commit is contained in:
MMX
2023-07-29 04:14:34 +03:00
committed by GitHub
8 changed files with 124 additions and 4 deletions
@@ -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);
@@ -5,6 +5,8 @@
#include <flipper_format/flipper_format_i.h>
#include <subghz/subghz_last_settings.h>
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);
}
@@ -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);
@@ -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;
+2
View File
@@ -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
1 entry status name type params
1401 Function + furi_hal_subghz_flush_rx void
1402 Function + furi_hal_subghz_flush_tx void
1403 Function + furi_hal_subghz_get_data_gpio const GpioPin*
1404 Function + furi_hal_subghz_get_ext_power_amp _Bool
1405 Function + furi_hal_subghz_get_lqi uint8_t
1406 Function + furi_hal_subghz_get_rolling_counter_mult uint8_t
1407 Function + furi_hal_subghz_get_rssi float
1419 Function + furi_hal_subghz_rx void
1420 Function + furi_hal_subghz_rx_pipe_not_empty _Bool
1421 Function + furi_hal_subghz_set_async_mirror_pin void const GpioPin*
1422 Function + furi_hal_subghz_set_ext_power_amp void _Bool
1423 Function + furi_hal_subghz_set_frequency uint32_t uint32_t
1424 Function + furi_hal_subghz_set_frequency_and_path uint32_t uint32_t
1425 Function + furi_hal_subghz_set_path void FuriHalSubGhzPath
+10 -1
View File
@@ -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;
}
@@ -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
+33
View File
@@ -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);
}
}
}
}