From aa3331fd76308ee4b2ecd40f9ed06861a6ee095a Mon Sep 17 00:00:00 2001 From: ankris812 <62661743+ankris812@users.noreply.github.com> Date: Fri, 9 Aug 2024 22:27:34 +0200 Subject: [PATCH] Update furi_hal_subghz.c --- targets/f7/furi_hal/furi_hal_subghz.c | 80 ++++++++------------------- 1 file changed, 23 insertions(+), 57 deletions(-) diff --git a/targets/f7/furi_hal/furi_hal_subghz.c b/targets/f7/furi_hal/furi_hal_subghz.c index b31ce0d5dc0..e6a08ab5efc 100644 --- a/targets/f7/furi_hal/furi_hal_subghz.c +++ b/targets/f7/furi_hal/furi_hal_subghz.c @@ -323,7 +323,28 @@ float furi_hal_subghz_get_rssi(void) { } else { rssi = (rssi / 2.0f) - 74.0f; } + +bool furi_hal_subghz_is_frequency_valid(uint32_t value) { + if(!(value >= 299999755 && value <= 348000335) && + !(value >= 386999938 && value <= 464000000) && + !(value >= 778999847 && value <= 928000000)) { + return false; + } + + return true; +} +uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value) { + value = furi_hal_subghz_set_frequency(value); + if(value >= 299999755 && value <= 348000335) { + furi_hal_subghz_set_path(FuriHalSubGhzPath315); + } else if(value >= 386999938 && value <= 464000000) { + furi_hal_subghz_set_path(FuriHalSubGhzPath433); + } else if(value >= 778999847 && value <= 928000000) { + furi_hal_subghz_set_path(FuriHalSubGhzPath868); + } else { + furi_crash("SubGhz: Incorrect frequency during set."); + } return rssi; } @@ -334,68 +355,13 @@ uint8_t furi_hal_subghz_get_lqi(void) { furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz); return data[0] & 0x7F; } -/* - Modified to the full YARD Stick One extended range of 281-361 MHz, 378-481 MHz, and 749-962 MHz. - These changes are at your own risk. The PLL may not lock and FZ devs have warned of possible damage - Set flag use_ext_range_at_own_risk in setting_user to use - */ - - bool furi_hal_subghz_is_frequency_valid(uint32_t value) { - FURI_LOG_I(TAG, "Checking if frequency is valid"); - bool is_extended = false; - - Storage* storage = furi_record_open("storage"); - FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); - - if(flipper_format_file_open_existing(fff_data_file, "/ext/subghz/assets/yardstick_range.txt")) { - flipper_format_read_bool(fff_data_file, "use_ext_range_may_damage", &is_extended, 1); - FURI_LOG_I(TAG, "Using extended frequencies at own risk"); - } else{ - FURI_LOG_I(TAG, "Keeping standard frequency ranges"); - } - - flipper_format_free(fff_data_file); - furi_record_close("storage"); - - - // No flag - test original range, flag set, test extended range - if(!(value >= 299999755 && value <= 348000335) && - !(value >= 386999938 && value <= 464000000) && - !(value >= 778999847 && value <= 928000000) && - !(is_extended)) { - FURI_LOG_I(TAG, "Frequency blocked - outside standard range"); - return false; - } else if(!(value >= 281000000 && value <= 361000000) && - !(value >= 378000000 && value <= 481000000) && - !(value >= 749000000 && value <= 962000000) && - is_extended) { - FURI_LOG_I(TAG, "Frequency blocked - outside extended range"); - return false; - } - - return true; - } - - uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value) { - // Set these values to the extended frequency range only. They dont define if you can transmit but do select the correct RF path - value = furi_hal_subghz_set_frequency(value); - if(value >= 281000000 && value <= 361000000) { - furi_hal_subghz_set_path(FuriHalSubGhzPath315); - } else if(value >= 378000000 && value <= 481000000) { - furi_hal_subghz_set_path(FuriHalSubGhzPath433); - } else if(value >= 749000000 && value <= 962000000) { - furi_hal_subghz_set_path(FuriHalSubGhzPath868); - } else { - furi_crash("SubGhz: Incorrect frequency during set."); - } + return value; } uint32_t furi_hal_subghz_set_frequency(uint32_t value) { if(furi_hal_region_is_frequency_allowed(value)) { - furi_hal_subghz.regulation = SubGhzRegulationTxRx; - } else { - furi_hal_subghz.regulation = SubGhzRegulationOnlyRx; + true; } furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);