more fixes

This commit is contained in:
RogueMaster
2022-09-16 16:27:33 -04:00
parent 4cf45e36c7
commit b186a912c8
11 changed files with 260 additions and 127 deletions

View File

@@ -172,7 +172,7 @@ SubGhz* subghz_alloc() {
//init setting
subghz->setting = subghz_setting_alloc();
subghz_setting_load(subghz->setting, EXT_PATH("subghz/assets/setting_user"));
subghz_setting_load(subghz->setting, EXT_PATH("subghz/assets/setting_user.txt"));
// Load last used values for Read, Read RAW, etc. or default
subghz->last_setting = subghz_last_setting_alloc();

View File

@@ -20,7 +20,7 @@
#include <lib/subghz/protocols/keeloq.h>
#include <lib/subghz/protocols/star_line.h>
#define UNIRFMAP_FOLDER "/ext/unirf"
#define UNIRFMAP_FOLDER "/ext/subghz/unirf"
#define UNIRFMAP_EXTENSION ".txt"
#define TAG "UniRF Remix"
@@ -827,7 +827,7 @@ static void input_callback(InputEvent* input_event, void* ctx) {
void unirfremix_subghz_alloc(UniRFRemix* app) {
// load subghz presets
app->setting = subghz_setting_alloc();
subghz_setting_load(app->setting, EXT_PATH("subghz/assets/setting_user"));
subghz_setting_load(app->setting, EXT_PATH("subghz/assets/setting_user.txt"));
// load mfcodes
app->environment = subghz_environment_alloc();

View File

@@ -20,7 +20,7 @@
#include "playlist_file.h"
#include "canvas_helper.h"
#define PLAYLIST_FOLDER "/ext/subplaylist"
#define PLAYLIST_FOLDER "/ext/subghz/playlist"
#define PLAYLIST_EXT ".txt"
#define TAG "Playlist"

View File

@@ -1,4 +0,0 @@
# Do you want to damage your flipper CC1101 radio chip by using Frequencies that outside HW specs?
# CC1101 Frequency range specs: 300-348 MHz, 386-464 MHz, and 778-928 MHz
# This setting will extend to: 281-361 MHz, 378-481 MHz, and 749-962 MHz
yes_i_want_to_destroy_my_flipper: false

View File

@@ -1,80 +0,0 @@
Filetype: Flipper SubGhz Setting File
Version: 1
# Add All Standard frequencies
Add_standard_frequencies: false
# Default Frequency: used as default for "Read" and "Read Raw"
Default_frequency: 433920000
# Frequencies used for "Read", "Read Raw" and "Frequency Analyzer" - they added after default ones if enabled in Add_standard_frequencies
Frequency: 300000000
Frequency: 302757000
Frequency: 303875000
Frequency: 304250000
Frequency: 307000000
Frequency: 307500000
Frequency: 307800000
Frequency: 309000000
Frequency: 310000000
Frequency: 312000000
Frequency: 312100000
Frequency: 313000000
Frequency: 313850000
Frequency: 314000000
Frequency: 314350000
Frequency: 315000000
Frequency: 318000000
Frequency: 345000000
Frequency: 348000000
Frequency: 387000000
Frequency: 390000000
Frequency: 418000000
Frequency: 433075000
Frequency: 433220000
Frequency: 433420000
Frequency: 433657070
Frequency: 433889000
Frequency: 433920000
Frequency: 434176948
Frequency: 434420000
Frequency: 434775000
Frequency: 438900000
Frequency: 464000000
Frequency: 779000000
Frequency: 868350000
Frequency: 906400000
Frequency: 915000000
Frequency: 925000000
Frequency: 928000000
# Frequencies used for hopping mode (keep this list small or flipper will miss signal) - they added after default ones if enabled in Add_standard_frequencies
Hopper_frequency: 310000000
Hopper_frequency: 315000000
Hopper_frequency: 313000000
Hopper_frequency: 318000000
Hopper_frequency: 390000000
Hopper_frequency: 433920000
Hopper_frequency: 434420000
Hopper_frequency: 868350000
# Custom preset
# format for CC1101 "Custom_preset_data:" XX YY XX YY .. 00 00 ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ, where: XX-register, YY - register data, 00 00 - end load register, ZZ - 8 byte Pa table register
#Custom_preset_name: AM_1
#Custom_preset_module: CC1101
#Custom_preset_data: 02 0D 03 07 08 32 0B 06 14 00 13 00 12 30 11 32 10 17 18 18 19 18 1D 91 1C 00 1B 07 20 FB 22 11 21 B6 00 00 00 C0 00 00 00 00 00 00
#Custom_preset_name: AM_2
#Custom_preset_module: CC1101
#Custom_preset_data: 02 0D 03 07 08 32 0B 06 14 00 13 00 12 30 11 32 10 17 18 18 19 18 1D 91 1C 00 1B 07 20 FB 22 11 21 B6 00 00 00 C0 00 00 00 00 00 00
Custom_preset_name: HND_1
Custom_preset_module: CC1101
# G2 G3 G4 D L0 L1 L2
Custom_preset_data: 02 0D 0B 06 08 32 07 04 14 00 13 02 12 04 11 36 10 69 15 32 18 18 19 16 1D 91 1C 00 1B 07 20 FB 22 10 21 56 00 00 C0 00 00 00 00 00 00 00
Custom_preset_name: HND_2
Custom_preset_module: CC1101
# G2 G3 G4 D L0 L1 L2
Custom_preset_data: 02 0D 0B 06 08 32 07 04 14 00 13 02 12 07 11 36 10 E9 15 32 18 18 19 16 1D 92 1C 40 1B 03 20 FB 22 10 21 56 00 00 C0 00 00 00 00 00 00 00

View File

@@ -1,5 +0,0 @@
# Example file, it will not work, you need to add paths to your files!
sub: /ext/subghz/Vehicles/Tesla/Tesla_charge_AM270.sub
sub: /ext/subghz/Vehicles/Tesla/Tesla_charge_AM650.sub
sub: /ext/subghz/Test1.sub
sub: /ext/subghz/Test2.sub

View File

@@ -1,10 +0,0 @@
UP: /ext/subghz/Up.sub
DOWN: /ext/subghz/Down.sub
LEFT: /ext/subghz/Left.sub
RIGHT: /ext/subghz/Right.sub
OK: /ext/subghz/Ok.sub
ULABEL: Up Label
DLABEL: Down Label
LLABEL: Left Label
RLABEL: Right Label
OKLABEL: Ok Label

View File

@@ -1,9 +1,138 @@
#include <furi_hal_region.h>
#include <furi_hal_subghz.h>
#include <furi_hal_version.h>
const FuriHalRegion furi_hal_region_zero = {
.country_code = "00",
.bands_count = 1,
.bands = {
{
.start = 0,
.end = 1000000000,
.power_limit = 12,
.duty_cycle = 50,
},
}};
const FuriHalRegion furi_hal_region_eu_ru = {
.country_code = "EU",
.bands_count = 2,
.bands = {
{
.start = 433050000,
.end = 434790000,
.power_limit = 12,
.duty_cycle = 50,
},
{
.start = 868150000,
.end = 868550000,
.power_limit = 12,
.duty_cycle = 50,
}}};
const FuriHalRegion furi_hal_region_us_ca_au = {
.country_code = "US",
.bands_count = 3,
.bands = {
{
.start = 304100000,
.end = 321950000,
.power_limit = 12,
.duty_cycle = 50,
},
{
.start = 433050000,
.end = 434790000,
.power_limit = 12,
.duty_cycle = 50,
},
{
.start = 915000000,
.end = 928000000,
.power_limit = 12,
.duty_cycle = 50,
}}};
const FuriHalRegion furi_hal_region_jp = {
.country_code = "JP",
.bands_count = 2,
.bands = {
{
.start = 312000000,
.end = 315250000,
.power_limit = 12,
.duty_cycle = 50,
},
{
.start = 920500000,
.end = 923500000,
.power_limit = 12,
.duty_cycle = 50,
}}};
static const FuriHalRegion* furi_hal_region = NULL;
void furi_hal_region_init() {
FuriHalVersionRegion region = furi_hal_version_get_hw_region();
if(region == FuriHalVersionRegionUnknown) {
furi_hal_region = &furi_hal_region_zero;
} else if(region == FuriHalVersionRegionEuRu) {
furi_hal_region = &furi_hal_region_eu_ru;
} else if(region == FuriHalVersionRegionUsCaAu) {
furi_hal_region = &furi_hal_region_us_ca_au;
} else if(region == FuriHalVersionRegionJp) {
furi_hal_region = &furi_hal_region_jp;
}
}
const FuriHalRegion* furi_hal_region_get() {
return furi_hal_region;
}
void furi_hal_region_set(FuriHalRegion* region) {
furi_hal_region = region;
}
bool furi_hal_region_is_provisioned() {
return true;
return furi_hal_region != NULL;
}
const char* furi_hal_region_get_name() {
return "00";
if(furi_hal_region) {
return furi_hal_region->country_code;
} else {
return "--";
}
}
bool furi_hal_region_is_frequency_allowed(uint32_t frequency) {
bool isAllowed = true;
if(!furi_hal_region) {
isAllowed = false;
}
const FuriHalRegionBand* band = furi_hal_region_get_band(frequency);
if(!band) {
isAllowed = false;
}
if(!isAllowed) {
isAllowed = furi_hal_subghz_is_tx_allowed(frequency);
}
return isAllowed;
}
const FuriHalRegionBand* furi_hal_region_get_band(uint32_t frequency) {
if(!furi_hal_region) {
return NULL;
}
for(size_t i = 0; i < furi_hal_region->bands_count; i++) {
if(furi_hal_region->bands[i].start <= frequency &&
furi_hal_region->bands[i].end >= frequency) {
return &furi_hal_region->bands[i];
}
}
return NULL;
}

View File

@@ -1,6 +1,7 @@
#include "furi_hal_subghz.h"
#include "furi_hal_subghz_configs.h"
#include <furi_hal_region.h>
#include <furi_hal_version.h>
#include <furi_hal_rtc.h>
#include <furi_hal_gpio.h>
@@ -8,16 +9,17 @@
#include <furi_hal_interrupt.h>
#include <furi_hal_resources.h>
#include <stm32wbxx_ll_dma.h>
#include <lib/flipper_format/flipper_format.h>
#include <stm32wbxx_ll_dma.h>
#include <furi.h>
#include <cc1101.h>
#include <stdio.h>
#define TAG "FuriHalSubGhz"
/*
* Uncomment define to enable duplication of
* IO GO0 CC1101 to an external comb.
@@ -33,7 +35,7 @@
* Attention this setting switches pin to output.
* Make sure it is not connected directly to power or ground
*/
//#define SUBGHZ_DEBUG_CC1101_PIN gpio_ext_pa7
#ifdef SUBGHZ_DEBUG_CC1101_PIN
uint32_t subghz_debug_gpio_buff[2];
@@ -277,7 +279,7 @@ void furi_hal_subghz_rx() {
}
bool furi_hal_subghz_tx() {
if(furi_hal_subghz.regulation != SubGhzRegulationTxRx) return false;
// if(furi_hal_subghz.regulation != SubGhzRegulationTxRx) return false;
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
cc1101_switch_to_tx(&furi_hal_spi_bus_handle_subghz);
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
@@ -309,9 +311,9 @@ uint8_t furi_hal_subghz_get_lqi() {
/*
Modified by @tkerby & MX 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!
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 extend_range.txt to use
*/
bool furi_hal_subghz_is_frequency_valid(uint32_t value) {
if(!(value >= 281000000 && value <= 361000000) &&
!(value >= 378000000 && value <= 481000000) &&
@@ -338,38 +340,79 @@ uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value) {
}
bool furi_hal_subghz_is_tx_allowed(uint32_t value) {
//checking regional settings
bool is_extended = false;
bool is_allowed = false;
// TODO: !!! Move file check to another place
Storage* storage = furi_record_open(RECORD_STORAGE);
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
if(flipper_format_file_open_existing(fff_data_file, "/ext/subghz/assets/dangerous_settings")) {
flipper_format_read_bool(
fff_data_file, "yes_i_want_to_destroy_my_flipper", &is_extended, 1);
if(flipper_format_file_open_existing(fff_data_file, "/ext/subghz/assets/extend_range.txt")) {
flipper_format_read_bool(fff_data_file, "use_ext_range_at_own_risk", &is_extended, 1);
flipper_format_read_bool(fff_data_file, "ignore_default_tx_region", &is_allowed, 1);
}
flipper_format_free(fff_data_file);
furi_record_close(RECORD_STORAGE);
switch(furi_hal_version_get_hw_region()) {
case FuriHalVersionRegionEuRu:
//433,05..434,79; 868,15..868,55
if(!(value >= 433050000 && value <= 434790000) &&
!(value >= 868150000 && value <= 868550000)) {
} else {
is_allowed = true;
}
break;
case FuriHalVersionRegionUsCaAu:
//304,10..321,95; 433,05..434,79; 915,00..928,00
if(!(value >= 304100000 && value <= 321950000) &&
!(value >= 433050000 && value <= 434790000) &&
!(value >= 915000000 && value <= 928000000)) {
} else {
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
if((value >= 304100000 && value <= 321950000) &&
((furi_hal_subghz.preset == FuriHalSubGhzPresetOok270Async) ||
(furi_hal_subghz.preset == FuriHalSubGhzPresetOok650Async))) {
furi_hal_subghz_load_patable(furi_hal_subghz_preset_ook_async_patable_au);
}
}
is_allowed = true;
}
break;
case FuriHalVersionRegionJp:
//312,00..315,25; 920,50..923,50
if(!(value >= 312000000 && value <= 315250000) &&
!(value >= 920500000 && value <= 923500000)) {
} else {
is_allowed = true;
}
break;
default:
is_allowed = true;
break;
}
// 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 default range");
return false;
FURI_LOG_I(TAG, "Frequency blocked - outside standard range");
is_allowed = false;
} else if(
!(value >= 281000000 && value <= 361000000) &&
!(value >= 378000000 && value <= 481000000) &&
!(value >= 749000000 && value <= 962000000) && is_extended) {
FURI_LOG_I(TAG, "Frequency blocked - outside dangerous range");
return false;
FURI_LOG_I(TAG, "Frequency blocked - outside extended range");
is_allowed = false;
}
return true;
return is_allowed;
}
uint32_t furi_hal_subghz_set_frequency(uint32_t value) {
furi_hal_subghz.regulation = SubGhzRegulationTxRx;
if(furi_hal_region_is_frequency_allowed(value)) {
furi_hal_subghz.regulation = SubGhzRegulationTxRx;
} else {
furi_hal_subghz.regulation = SubGhzRegulationOnlyRx;
}
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
uint32_t real_frequency = cc1101_set_frequency(&furi_hal_spi_bus_handle_subghz, value);
@@ -627,7 +670,7 @@ bool furi_hal_subghz_start_async_tx(FuriHalSubGhzAsyncTxCallback callback, void*
furi_assert(callback);
//If transmission is prohibited by regional settings
if(furi_hal_subghz.regulation != SubGhzRegulationTxRx) return false;
// if(furi_hal_subghz.regulation != SubGhzRegulationTxRx) return false;
furi_hal_subghz_async_tx.callback = callback;
furi_hal_subghz_async_tx.callback_context = context;

View File

@@ -273,6 +273,16 @@ static const uint8_t furi_hal_subghz_preset_ook_async_patable[8] = {
0x00,
0x00};
static const uint8_t furi_hal_subghz_preset_ook_async_patable_au[8] = {
0x00,
0x37, // 12dBm 0xC0, 10dBm 0xC5, 7dBm 0xCD, 5dBm 0x86, 0dBm 0x50, -6dBm 0x37, -10dBm 0x26, -15dBm 0x1D, -20dBm 0x17, -30dBm 0x03
0x00,
0x00,
0x00,
0x00,
0x00,
0x00};
static const uint8_t furi_hal_subghz_preset_2fsk_async_patable[8] = {
0xC0, // 10dBm 0xC0, 7dBm 0xC8, 5dBm 0x84, 0dBm 0x60, -10dBm 0x34, -15dBm 0x1D, -20dBm 0x0E, -30dBm 0x12
0x00,

View File

@@ -2,10 +2,43 @@
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
uint32_t start;
uint32_t end;
int8_t power_limit;
uint8_t duty_cycle;
} FuriHalRegionBand;
typedef struct {
char country_code[4];
uint16_t bands_count;
FuriHalRegionBand bands[];
} FuriHalRegion;
/** Initialize region */
void furi_hal_region_init();
/** Get Region Data.
*
* Region data may be allocated in Flash or in RAM.
* Keep in mind that we don't do memory management on our side.
*
* @return pointer to FuriHalRegion instance (in RAM or Flash, check before freeing on region update)
*/
const FuriHalRegion* furi_hal_region_get();
/** Set device region data
*
* @param region pointer to the FuriHalRegion
*/
void furi_hal_region_set(FuriHalRegion* region);
/** Check if region data provisioned
*
* @return true if provisioned, false otherwise
@@ -16,8 +49,6 @@ bool furi_hal_region_is_provisioned();
*
* 2 letter Region code according to iso 3166 standard
* There are 2 extra values that we use in special cases:
* RM, whats the reason you not doing a release?
* Waiting for my commits?
* - "00" - developer edition, unlocked
* - "WW" - world wide, region provisioned by default
* - "--" - no provisioned region
@@ -26,6 +57,25 @@ bool furi_hal_region_is_provisioned();
*/
const char* furi_hal_region_get_name();
/** Сheck if transmission is allowed on this frequency for your flipper region
*
* @param[in] frequency The frequency
* @param value frequency in Hz
*
* @return true if allowed
*/
bool furi_hal_region_is_frequency_allowed(uint32_t frequency);
/** Get band data for frequency
*
*
*
* @param[in] frequency The frequency
*
* @return { description_of_the_return_value }
*/
const FuriHalRegionBand* furi_hal_region_get_band(uint32_t frequency);
#ifdef __cplusplus
}
#endif