mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-10 15:04:19 +00:00
Remake it more properly
still has problems, need to rewrite subghz_devices tx/rx switch code, checking strcmp every time is not good too, but better than loading whole config from microsd
This commit is contained in:
parent
58beca313d
commit
0f9c6ba847
7 changed files with 87 additions and 55 deletions
|
@ -124,6 +124,10 @@ static void subghz_scene_reciever_config_set_ext_mod_power_amp_text(VariableItem
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -159,9 +163,9 @@ void subghz_scene_radio_settings_on_enter(void* context) {
|
|||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, radio_device_text[value_index]);
|
||||
|
||||
item = variable_item_list_add(
|
||||
item = variable_item_list_add(
|
||||
variable_item_list,
|
||||
"Ext High Power",
|
||||
"Ext Power Amp",
|
||||
EXT_MOD_POWER_AMP_COUNT,
|
||||
subghz_scene_reciever_config_set_ext_mod_power_amp_text,
|
||||
subghz);
|
||||
|
@ -171,7 +175,7 @@ void subghz_scene_radio_settings_on_enter(void* context) {
|
|||
|
||||
item = variable_item_list_add(
|
||||
variable_item_list,
|
||||
"Time in names",
|
||||
"Time In Names",
|
||||
TIMESTAMP_NAMES_COUNT,
|
||||
subghz_scene_receiver_config_set_timestamp_file_names,
|
||||
subghz);
|
||||
|
@ -182,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);
|
||||
|
@ -211,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);
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
#define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY_ANALYZER_TRIGGER "FATrigger"
|
||||
#define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_ENABLED "External"
|
||||
#define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER "ExtPower"
|
||||
#define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP "ExtPowerAmp"
|
||||
#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));
|
||||
|
@ -47,7 +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_external_module_power_amp = false;
|
||||
bool temp_timestamp_file_names = false;
|
||||
//int32_t temp_preset = 0;
|
||||
bool frequency_analyzer_feedback_level_was_read = false;
|
||||
|
@ -79,17 +79,17 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
|
|||
fff_data_file,
|
||||
SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER,
|
||||
(bool*)&temp_external_module_power_5v_disable,
|
||||
1);
|
||||
flipper_format_read_bool(
|
||||
fff_data_file,
|
||||
SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP,
|
||||
(bool*)&temp_external_module_power_amp,
|
||||
1);
|
||||
flipper_format_read_bool(
|
||||
fff_data_file,
|
||||
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);
|
||||
|
@ -103,8 +103,8 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
|
|||
SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_FEEDBACK_LEVEL;
|
||||
instance->frequency_analyzer_trigger = SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER;
|
||||
instance->external_module_enabled = false;
|
||||
instance->external_module_power_amp = false;
|
||||
instance->timestamp_file_names = false;
|
||||
instance->external_module_power_amp = false;
|
||||
|
||||
} else {
|
||||
instance->frequency = temp_frequency;
|
||||
|
@ -126,9 +126,13 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
|
|||
instance->external_module_power_5v_disable = temp_external_module_power_5v_disable;
|
||||
|
||||
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;
|
||||
}*/
|
||||
|
@ -199,17 +203,17 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) {
|
|||
1)) {
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_insert_or_update_bool(
|
||||
if(!flipper_format_insert_or_update_bool(
|
||||
file,
|
||||
SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP,
|
||||
&instance->external_module_power_amp,
|
||||
SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES,
|
||||
&instance->timestamp_file_names,
|
||||
1)) {
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_insert_or_update_bool(
|
||||
file,
|
||||
SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES,
|
||||
&instance->timestamp_file_names,
|
||||
SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP,
|
||||
&instance->external_module_power_amp,
|
||||
1)) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
|
@ -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
|
||||
|
|
|
@ -2,34 +2,14 @@
|
|||
|
||||
#include "registry.h"
|
||||
|
||||
#include <subghz/subghz_last_settings.h>
|
||||
|
||||
void subghz_devices_init() {
|
||||
furi_check(!subghz_device_registry_is_valid());
|
||||
subghz_device_registry_init();
|
||||
|
||||
SubGhzLastSettings* last_settings = subghz_last_settings_alloc();
|
||||
subghz_last_settings_load(last_settings, 0);
|
||||
|
||||
if(last_settings->external_module_power_amp) {
|
||||
furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull);
|
||||
}
|
||||
|
||||
subghz_last_settings_free(last_settings);
|
||||
}
|
||||
|
||||
void subghz_devices_deinit(void) {
|
||||
furi_check(subghz_device_registry_is_valid());
|
||||
subghz_device_registry_deinit();
|
||||
|
||||
SubGhzLastSettings* last_settings = subghz_last_settings_alloc();
|
||||
subghz_last_settings_load(last_settings, 0);
|
||||
|
||||
if(last_settings->external_module_power_amp) {
|
||||
furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog);
|
||||
}
|
||||
|
||||
subghz_last_settings_free(last_settings);
|
||||
}
|
||||
|
||||
const SubGhzDevice* subghz_devices_get_by_name(const char* device_name) {
|
||||
|
@ -50,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;
|
||||
|
@ -58,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();
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +82,12 @@ void subghz_devices_idle(const SubGhzDevice* device) {
|
|||
furi_assert(device);
|
||||
if(device->interconnect->idle) {
|
||||
device->interconnect->idle();
|
||||
furi_hal_gpio_write(&gpio_ext_pc3, 0);
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,14 +141,12 @@ bool subghz_devices_set_tx(const SubGhzDevice* device) {
|
|||
if(device->interconnect->set_tx) {
|
||||
ret = device->interconnect->set_tx();
|
||||
|
||||
SubGhzLastSettings* last_settings = subghz_last_settings_alloc();
|
||||
subghz_last_settings_load(last_settings, 0);
|
||||
|
||||
if(last_settings->external_module_power_amp) {
|
||||
furi_hal_gpio_write(&gpio_ext_pc3, 1);
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
subghz_last_settings_free(last_settings);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -191,14 +187,13 @@ void subghz_devices_set_rx(const SubGhzDevice* device) {
|
|||
furi_assert(device);
|
||||
if(device->interconnect->set_rx) {
|
||||
device->interconnect->set_rx();
|
||||
SubGhzLastSettings* last_settings = subghz_last_settings_alloc();
|
||||
subghz_last_settings_load(last_settings, 0);
|
||||
|
||||
if(last_settings->external_module_power_amp) {
|
||||
furi_hal_gpio_write(&gpio_ext_pc3, 0);
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
subghz_last_settings_free(last_settings);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue