diff --git a/applications/drivers/subghz/cc1101_ext/cc1101_ext.c b/applications/drivers/subghz/cc1101_ext/cc1101_ext.c index ac72ab5c1..868f60616 100644 --- a/applications/drivers/subghz/cc1101_ext/cc1101_ext.c +++ b/applications/drivers/subghz/cc1101_ext/cc1101_ext.c @@ -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; } diff --git a/applications/main/subghz/scenes/subghz_scene_radio_settings.c b/applications/main/subghz/scenes/subghz_scene_radio_settings.c index ac1675d01..974a2f564 100644 --- a/applications/main/subghz/scenes/subghz_scene_radio_settings.c +++ b/applications/main/subghz/scenes/subghz_scene_radio_settings.c @@ -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", diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 30480054e..75b318005 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -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); diff --git a/applications/main/subghz/subghz_dangerous_freq.c b/applications/main/subghz/subghz_dangerous_freq.c index 699c42754..b76a6ec05 100644 --- a/applications/main/subghz/subghz_dangerous_freq.c +++ b/applications/main/subghz/subghz_dangerous_freq.c @@ -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); diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index 12e871a2f..174a15a5b 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -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); diff --git a/applications/main/subghz/subghz_last_settings.h b/applications/main/subghz/subghz_last_settings.h index 30c5884e5..c0559e4ec 100644 --- a/applications/main/subghz/subghz_last_settings.h +++ b/applications/main/subghz/subghz_last_settings.h @@ -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); diff --git a/lib/subghz/devices/devices.c b/lib/subghz/devices/devices.c index 9ae252017..099953136 100644 --- a/lib/subghz/devices/devices.c +++ b/lib/subghz/devices/devices.c @@ -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); diff --git a/lib/subghz/devices/types.h b/lib/subghz/devices/types.h index 6de2d9bd3..14852a160 100644 --- a/lib/subghz/devices/types.h +++ b/lib/subghz/devices/types.h @@ -94,5 +94,5 @@ struct SubGhzDevice { struct SubGhzDeviceConf { uint8_t ver; bool extended_range; - bool power_amp; + bool amp_and_leds; }; diff --git a/targets/f7/api_symbols.csv b/targets/f7/api_symbols.csv index cf8e69d26..781da2bb3 100644 --- a/targets/f7/api_symbols.csv +++ b/targets/f7/api_symbols.csv @@ -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 diff --git a/targets/f7/furi_hal/furi_hal_subghz.c b/targets/f7/furi_hal/furi_hal_subghz.c index c2efe1fd3..19aa0f766 100644 --- a/targets/f7/furi_hal/furi_hal_subghz.c +++ b/targets/f7/furi_hal/furi_hal_subghz.c @@ -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; } diff --git a/targets/f7/furi_hal/furi_hal_subghz.h b/targets/f7/furi_hal/furi_hal_subghz.h index e8e95d9f3..20843520a 100644 --- a/targets/f7/furi_hal/furi_hal_subghz.h +++ b/targets/f7/furi_hal/furi_hal_subghz.h @@ -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 }