mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2025-02-20 23:38:32 +00:00
Allow to disable control of GPIO pin on rx/tx states in subghz [ci skip]
in radio settings with debug ON, settings is saved on microsd, please don't use unless you know what you are doing
This commit is contained in:
parent
54ad331c4c
commit
1ceb1eb256
11 changed files with 102 additions and 31 deletions
applications
drivers/subghz/cc1101_ext
main/subghz
lib/subghz/devices
targets/f7
|
@ -92,7 +92,7 @@ typedef struct {
|
|||
const GpioPin* g0_pin;
|
||||
SubGhzDeviceCC1101ExtAsyncTx async_tx;
|
||||
SubGhzDeviceCC1101ExtAsyncRx async_rx;
|
||||
bool power_amp;
|
||||
bool amp_and_leds;
|
||||
bool extended_range;
|
||||
} SubGhzDeviceCC1101Ext;
|
||||
|
||||
|
@ -219,11 +219,11 @@ bool subghz_device_cc1101_ext_alloc(SubGhzDeviceConf* conf) {
|
|||
subghz_device_cc1101_ext->async_mirror_pin = NULL;
|
||||
subghz_device_cc1101_ext->spi_bus_handle = &furi_hal_spi_bus_handle_external;
|
||||
subghz_device_cc1101_ext->g0_pin = SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO;
|
||||
subghz_device_cc1101_ext->power_amp = false;
|
||||
subghz_device_cc1101_ext->amp_and_leds = false;
|
||||
subghz_device_cc1101_ext->extended_range = false;
|
||||
if(conf) {
|
||||
if(conf->ver == SUBGHZ_DEVICE_CC1101_CONFIG_VER) {
|
||||
subghz_device_cc1101_ext->power_amp = conf->power_amp;
|
||||
subghz_device_cc1101_ext->amp_and_leds = conf->amp_and_leds;
|
||||
subghz_device_cc1101_ext->extended_range = conf->extended_range;
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Config version mismatch");
|
||||
|
@ -233,7 +233,7 @@ bool subghz_device_cc1101_ext_alloc(SubGhzDeviceConf* conf) {
|
|||
subghz_device_cc1101_ext->async_rx.capture_delta_duration = 0;
|
||||
|
||||
furi_hal_spi_bus_handle_init(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
if(subghz_device_cc1101_ext->power_amp) {
|
||||
if(subghz_device_cc1101_ext->amp_and_leds) {
|
||||
furi_hal_gpio_init_simple(SUBGHZ_DEVICE_CC1101_EXT_E07_AMP_GPIO, GpioModeOutputPushPull);
|
||||
}
|
||||
|
||||
|
@ -244,7 +244,7 @@ void subghz_device_cc1101_ext_free(void) {
|
|||
furi_assert(subghz_device_cc1101_ext != NULL);
|
||||
|
||||
furi_hal_spi_bus_handle_deinit(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
if(subghz_device_cc1101_ext->power_amp) {
|
||||
if(subghz_device_cc1101_ext->amp_and_leds) {
|
||||
furi_hal_gpio_init_simple(SUBGHZ_DEVICE_CC1101_EXT_E07_AMP_GPIO, GpioModeAnalog);
|
||||
}
|
||||
|
||||
|
@ -418,9 +418,11 @@ void subghz_device_cc1101_ext_reset(void) {
|
|||
// Warning: push pull cc1101 clock output on GD0
|
||||
cc1101_write_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHighImpedance);
|
||||
// Reset GDO2 (!TX/RX) to floating state
|
||||
cc1101_write_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG2, CC1101IocfgHighImpedance);
|
||||
if(subghz_device_cc1101_ext->amp_and_leds) {
|
||||
// Reset GDO2 (!TX/RX) to floating state
|
||||
cc1101_write_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG2, CC1101IocfgHighImpedance);
|
||||
}
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
|
@ -430,13 +432,15 @@ void subghz_device_cc1101_ext_idle(void) {
|
|||
//waiting for the chip to switch to IDLE mode
|
||||
furi_check(cc1101_wait_status_state(
|
||||
subghz_device_cc1101_ext->spi_bus_handle, CC1101StateIDLE, 10000));
|
||||
// Reset GDO2 (!TX/RX) to floating state
|
||||
cc1101_write_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG2, CC1101IocfgHighImpedance);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
if(subghz_device_cc1101_ext->power_amp) {
|
||||
|
||||
if(subghz_device_cc1101_ext->amp_and_leds) {
|
||||
furi_hal_gpio_write(SUBGHZ_DEVICE_CC1101_EXT_E07_AMP_GPIO, 0);
|
||||
// Reset GDO2 (!TX/RX) to floating state
|
||||
cc1101_write_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG2, CC1101IocfgHighImpedance);
|
||||
}
|
||||
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_rx(void) {
|
||||
|
@ -445,14 +449,17 @@ void subghz_device_cc1101_ext_rx(void) {
|
|||
//waiting for the chip to switch to Rx mode
|
||||
furi_check(
|
||||
cc1101_wait_status_state(subghz_device_cc1101_ext->spi_bus_handle, CC1101StateRX, 10000));
|
||||
// Go GDO2 (!TX/RX) to high (RX state)
|
||||
cc1101_write_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG2, CC1101IocfgHW | CC1101_IOCFG_INV);
|
||||
|
||||
if(subghz_device_cc1101_ext->amp_and_leds) {
|
||||
furi_hal_gpio_write(SUBGHZ_DEVICE_CC1101_EXT_E07_AMP_GPIO, 0);
|
||||
// Go GDO2 (!TX/RX) to high (RX state)
|
||||
cc1101_write_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle,
|
||||
CC1101_IOCFG2,
|
||||
CC1101IocfgHW | CC1101_IOCFG_INV);
|
||||
}
|
||||
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
if(subghz_device_cc1101_ext->power_amp) {
|
||||
furi_hal_gpio_write(SUBGHZ_DEVICE_CC1101_EXT_E07_AMP_GPIO, 0);
|
||||
}
|
||||
}
|
||||
|
||||
bool subghz_device_cc1101_ext_tx(void) {
|
||||
|
@ -462,12 +469,14 @@ bool subghz_device_cc1101_ext_tx(void) {
|
|||
//waiting for the chip to switch to Tx mode
|
||||
furi_check(
|
||||
cc1101_wait_status_state(subghz_device_cc1101_ext->spi_bus_handle, CC1101StateTX, 10000));
|
||||
// Go GDO2 (!TX/RX) to low (TX state)
|
||||
cc1101_write_reg(subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG2, CC1101IocfgHW);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
if(subghz_device_cc1101_ext->power_amp) {
|
||||
|
||||
if(subghz_device_cc1101_ext->amp_and_leds) {
|
||||
furi_hal_gpio_write(SUBGHZ_DEVICE_CC1101_EXT_E07_AMP_GPIO, 1);
|
||||
// Go GDO2 (!TX/RX) to low (TX state)
|
||||
cc1101_write_reg(subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG2, CC1101IocfgHW);
|
||||
}
|
||||
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,8 +14,8 @@ const uint32_t radio_device_value[RADIO_DEVICE_COUNT] = {
|
|||
SubGhzRadioDeviceTypeExternalCC1101,
|
||||
};
|
||||
|
||||
#define TIMESTAMP_NAMES_COUNT 2
|
||||
const char* const timestamp_names_text[TIMESTAMP_NAMES_COUNT] = {
|
||||
#define ON_OFF_COUNT 2
|
||||
const char* const on_off_text[ON_OFF_COUNT] = {
|
||||
"OFF",
|
||||
"ON",
|
||||
};
|
||||
|
@ -81,6 +81,22 @@ static void subghz_scene_receiver_config_set_debug_pin(VariableItem* item) {
|
|||
subghz_txrx_set_debug_pin_state(subghz->txrx, index == 1);
|
||||
}
|
||||
|
||||
static void subghz_scene_reciever_config_set_ext_amp_leds_control(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, on_off_text[index]);
|
||||
subghz->last_settings->leds_and_amp = index == 1;
|
||||
// Set globally in furi hal
|
||||
furi_hal_subghz_set_ext_leds_and_amp(subghz->last_settings->leds_and_amp);
|
||||
subghz_last_settings_save(subghz->last_settings);
|
||||
// reinit external device
|
||||
const SubGhzRadioDeviceType current = subghz_txrx_radio_device_get(subghz->txrx);
|
||||
if(current != SubGhzRadioDeviceTypeInternal) {
|
||||
subghz_txrx_radio_device_set(subghz->txrx, SubGhzRadioDeviceTypeInternal);
|
||||
subghz_txrx_radio_device_set(subghz->txrx, current);
|
||||
}
|
||||
}
|
||||
|
||||
static void subghz_scene_receiver_config_set_debug_counter(VariableItem* item) {
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
|
@ -92,7 +108,7 @@ static void subghz_scene_receiver_config_set_timestamp_file_names(VariableItem*
|
|||
SubGhz* subghz = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
variable_item_set_current_value_text(item, timestamp_names_text[index]);
|
||||
variable_item_set_current_value_text(item, on_off_text[index]);
|
||||
|
||||
subghz->last_settings->protocol_file_names = (index == 1);
|
||||
subghz_last_settings_save(subghz->last_settings);
|
||||
|
@ -123,12 +139,12 @@ void subghz_scene_radio_settings_on_enter(void* context) {
|
|||
item = variable_item_list_add(
|
||||
variable_item_list,
|
||||
"Protocol Names",
|
||||
TIMESTAMP_NAMES_COUNT,
|
||||
ON_OFF_COUNT,
|
||||
subghz_scene_receiver_config_set_timestamp_file_names,
|
||||
subghz);
|
||||
value_index = subghz->last_settings->protocol_file_names;
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, timestamp_names_text[value_index]);
|
||||
variable_item_set_current_value_text(item, on_off_text[value_index]);
|
||||
|
||||
item = variable_item_list_add(
|
||||
variable_item_list,
|
||||
|
@ -146,6 +162,16 @@ void subghz_scene_radio_settings_on_enter(void* context) {
|
|||
variable_item_set_current_value_text(item, debug_counter_text[value_index]);
|
||||
|
||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
||||
item = variable_item_list_add(
|
||||
variable_item_list,
|
||||
"Ext Amp & LEDs",
|
||||
ON_OFF_COUNT,
|
||||
subghz_scene_reciever_config_set_ext_amp_leds_control,
|
||||
subghz);
|
||||
value_index = subghz->last_settings->leds_and_amp ? 1 : 0;
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, on_off_text[value_index]);
|
||||
|
||||
item = variable_item_list_add(
|
||||
variable_item_list,
|
||||
"Debug Pin",
|
||||
|
|
|
@ -197,6 +197,10 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) {
|
|||
subghz->last_settings = subghz_last_settings_alloc();
|
||||
size_t preset_count = subghz_setting_get_preset_count(setting);
|
||||
subghz_last_settings_load(subghz->last_settings, preset_count);
|
||||
|
||||
// Set LED and Amp GPIO control state
|
||||
furi_hal_subghz_set_ext_leds_and_amp(subghz->last_settings->leds_and_amp);
|
||||
|
||||
if(!alloc_for_tx_only) {
|
||||
subghz_txrx_set_preset_internal(
|
||||
subghz->txrx, subghz->last_settings->frequency, subghz->last_settings->preset_index);
|
||||
|
|
|
@ -27,6 +27,9 @@ void subghz_dangerous_freq() {
|
|||
SubGhzLastSettings* last_settings = subghz_last_settings_alloc();
|
||||
subghz_last_settings_load(last_settings, 0);
|
||||
|
||||
// Set LED and Amp GPIO control state
|
||||
furi_hal_subghz_set_ext_leds_and_amp(last_settings->leds_and_amp);
|
||||
|
||||
subghz_last_settings_free(last_settings);
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#define SUBGHZ_LAST_SETTING_FIELD_RSSI_THRESHOLD "RSSI"
|
||||
#define SUBGHZ_LAST_SETTING_FIELD_DELETE_OLD "DelOldSignals"
|
||||
#define SUBGHZ_LAST_SETTING_FIELD_HOPPING_THRESHOLD "HoppingThreshold"
|
||||
#define SUBGHZ_LAST_SETTING_FIELD_LED_AND_POWER_AMP "LedAndPowerAmp"
|
||||
|
||||
SubGhzLastSettings* subghz_last_settings_alloc(void) {
|
||||
SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings));
|
||||
|
@ -42,6 +43,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
|
|||
instance->filter = SubGhzProtocolFlag_Decodable;
|
||||
instance->rssi = SUBGHZ_RAW_THRESHOLD_MIN;
|
||||
instance->hopping_threshold = -90.0f;
|
||||
instance->leds_and_amp = true;
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
|
||||
|
@ -123,6 +125,13 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
|
|||
1)) {
|
||||
flipper_format_rewind(fff_data_file);
|
||||
}
|
||||
if(!flipper_format_read_bool(
|
||||
fff_data_file,
|
||||
SUBGHZ_LAST_SETTING_FIELD_LED_AND_POWER_AMP,
|
||||
&instance->leds_and_amp,
|
||||
1)) {
|
||||
flipper_format_rewind(fff_data_file);
|
||||
}
|
||||
|
||||
} while(0);
|
||||
} else {
|
||||
|
@ -219,6 +228,10 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) {
|
|||
1)) {
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_write_bool(
|
||||
file, SUBGHZ_LAST_SETTING_FIELD_LED_AND_POWER_AMP, &instance->leds_and_amp, 1)) {
|
||||
break;
|
||||
}
|
||||
|
||||
saved = true;
|
||||
} while(0);
|
||||
|
|
|
@ -25,6 +25,7 @@ typedef struct {
|
|||
float rssi;
|
||||
bool delete_old_signals;
|
||||
float hopping_threshold;
|
||||
bool leds_and_amp;
|
||||
} SubGhzLastSettings;
|
||||
|
||||
SubGhzLastSettings* subghz_last_settings_alloc(void);
|
||||
|
|
|
@ -33,7 +33,7 @@ bool subghz_devices_begin(const SubGhzDevice* device) {
|
|||
SubGhzDeviceConf conf = {
|
||||
.ver = 1,
|
||||
.extended_range = false, // TODO
|
||||
.power_amp = true,
|
||||
.amp_and_leds = furi_hal_subghz_get_ext_leds_and_amp(),
|
||||
};
|
||||
|
||||
ret = device->interconnect->begin(&conf);
|
||||
|
|
|
@ -94,5 +94,5 @@ struct SubGhzDevice {
|
|||
struct SubGhzDeviceConf {
|
||||
uint8_t ver;
|
||||
bool extended_range;
|
||||
bool power_amp;
|
||||
bool amp_and_leds;
|
||||
};
|
||||
|
|
|
@ -1690,6 +1690,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_leds_and_amp,_Bool,
|
||||
Function,+,furi_hal_subghz_get_lqi,uint8_t,
|
||||
Function,+,furi_hal_subghz_get_rolling_counter_mult,int8_t,
|
||||
Function,+,furi_hal_subghz_get_rssi,float,
|
||||
|
@ -1707,6 +1708,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_leds_and_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
|
||||
|
|
|
|
@ -52,6 +52,7 @@ typedef struct {
|
|||
const GpioPin* async_mirror_pin;
|
||||
|
||||
int8_t rolling_counter_mult;
|
||||
bool ext_leds_and_amp : 1;
|
||||
bool dangerous_frequency_i : 1;
|
||||
} FuriHalSubGhz;
|
||||
|
||||
|
@ -60,6 +61,7 @@ volatile FuriHalSubGhz furi_hal_subghz = {
|
|||
.regulation = SubGhzRegulationTxRx,
|
||||
.async_mirror_pin = NULL,
|
||||
.rolling_counter_mult = 1,
|
||||
.ext_leds_and_amp = true,
|
||||
.dangerous_frequency_i = false,
|
||||
};
|
||||
|
||||
|
@ -79,6 +81,14 @@ void furi_hal_subghz_set_async_mirror_pin(const GpioPin* pin) {
|
|||
furi_hal_subghz.async_mirror_pin = pin;
|
||||
}
|
||||
|
||||
void furi_hal_subghz_set_ext_leds_and_amp(bool enabled) {
|
||||
furi_hal_subghz.ext_leds_and_amp = enabled;
|
||||
}
|
||||
|
||||
bool furi_hal_subghz_get_ext_leds_and_amp(void) {
|
||||
return furi_hal_subghz.ext_leds_and_amp;
|
||||
}
|
||||
|
||||
const GpioPin* furi_hal_subghz_get_data_gpio(void) {
|
||||
return &gpio_cc1101_g0;
|
||||
}
|
||||
|
|
|
@ -238,7 +238,10 @@ bool furi_hal_subghz_is_async_tx_complete(void);
|
|||
*/
|
||||
void furi_hal_subghz_stop_async_tx(void);
|
||||
|
||||
// External CC1101 Ebytes power amplifier control is now enabled by default
|
||||
// External CC1101 Amplifier and LEDs (if present) control
|
||||
void furi_hal_subghz_set_ext_leds_and_amp(bool enabled);
|
||||
// Get state (enabled by default, can be disabled in radio setting with debug ON)
|
||||
bool furi_hal_subghz_get_ext_leds_and_amp(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue