SubGHz: New check_tx API, ext modules follow settings

This commit is contained in:
Willy-JL
2024-05-16 11:57:42 +01:00
parent 0bcd521b29
commit 68a1d63360
17 changed files with 122 additions and 70 deletions

View File

@@ -20,7 +20,6 @@
#define SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO (&gpio_ext_pb2)
#define SUBGHZ_DEVICE_CC1101_EXT_E07M20S_AMP_GPIO &gpio_ext_pc3
#define SUBGHZ_DEVICE_CC1101_EXT_FORCE_EXTENDED_RANGE false
#define SUBGHZ_DEVICE_CC1101_CONFIG_VER 1
@@ -93,8 +92,9 @@ typedef struct {
const GpioPin* g0_pin;
SubGhzDeviceCC1101ExtAsyncTx async_tx;
SubGhzDeviceCC1101ExtAsyncRx async_rx;
bool power_amp;
bool extended_range;
bool bypass_region;
bool power_amp;
} SubGhzDeviceCC1101Ext;
static SubGhzDeviceCC1101Ext* subghz_device_cc1101_ext = NULL;
@@ -219,12 +219,14 @@ bool subghz_device_cc1101_ext_alloc(SubGhzDeviceConf* conf) {
subghz_device_cc1101_ext->regulation = SubGhzDeviceCC1101ExtRegulationTxRx;
subghz_device_cc1101_ext->async_mirror_pin = NULL;
subghz_device_cc1101_ext->g0_pin = SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO;
subghz_device_cc1101_ext->power_amp = false;
subghz_device_cc1101_ext->extended_range = false;
subghz_device_cc1101_ext->bypass_region = false;
subghz_device_cc1101_ext->power_amp = false;
if(conf) {
if(conf->ver == SUBGHZ_DEVICE_CC1101_CONFIG_VER) {
subghz_device_cc1101_ext->power_amp = conf->power_amp;
subghz_device_cc1101_ext->extended_range = conf->extended_range;
subghz_device_cc1101_ext->bypass_region = conf->bypass_region;
subghz_device_cc1101_ext->power_amp = conf->power_amp;
} else {
FURI_LOG_E(TAG, "Config version mismatch");
}
@@ -522,30 +524,47 @@ bool subghz_device_cc1101_ext_is_frequency_valid(uint32_t value) {
return true;
}
bool subghz_device_cc1101_ext_is_tx_allowed(uint32_t value) {
if(!(SUBGHZ_DEVICE_CC1101_EXT_FORCE_EXTENDED_RANGE ||
subghz_device_cc1101_ext->extended_range) &&
SubGhzTx subghz_device_cc1101_ext_check_tx(uint32_t value) {
// Check against extended range of YARD Stick One, no configuration would allow this frequency
if(!subghz_device_cc1101_ext_is_frequency_valid(value)) {
FURI_LOG_I(TAG, "Frequency blocked - outside supported range");
return SubGhzTxUnsupported;
}
// Check against default range, regardless of region restrictions
if(!subghz_device_cc1101_ext->extended_range &&
!(value >= 299999755 && value <= 350000335) && // was increased from 348 to 350
!(value >= 386999938 && value <= 467750000) && // was increased from 464 to 467.75
!(value >= 778999847 && value <= 928000000)) {
FURI_LOG_I(TAG, "Frequency blocked - outside default range");
return false;
} else if(
(SUBGHZ_DEVICE_CC1101_EXT_FORCE_EXTENDED_RANGE ||
subghz_device_cc1101_ext->extended_range) &&
!subghz_device_cc1101_ext_is_frequency_valid(value)) {
FURI_LOG_I(TAG, "Frequency blocked - outside extended range");
return false;
return SubGhzTxBlockedDefault;
}
return true;
// Check against region restrictions, tighter than extended and default
if(!subghz_device_cc1101_ext->bypass_region) {
if(!furi_hal_region_is_provisioned()) {
FURI_LOG_I(TAG, "Frequency blocked - region not provisioned");
return SubGhzTxBlockedRegionNotProvisioned;
}
if(!furi_hal_region_is_frequency_allowed(value)) {
FURI_LOG_I(TAG, "Frequency blocked - outside region range");
return SubGhzTxBlockedRegion;
}
}
// We already checked for extended range, default range, and region range
return SubGhzTxAllowed;
}
bool subghz_device_cc1101_ext_is_tx_allowed(uint32_t value) {
return subghz_device_cc1101_ext_check_tx(value) == SubGhzTxAllowed;
}
uint32_t subghz_device_cc1101_ext_set_frequency(uint32_t value) {
if(subghz_device_cc1101_ext_is_tx_allowed(value)) {
subghz_device_cc1101_ext->regulation = SubGhzDeviceCC1101ExtRegulationTxRx;
} else {
subghz_device_cc1101_ext->regulation = SubGhzDeviceCC1101ExtRegulationTxRx;
subghz_device_cc1101_ext->regulation = SubGhzDeviceCC1101ExtRegulationOnlyRx;
}
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);

View File

@@ -152,6 +152,14 @@ uint8_t subghz_device_cc1101_ext_get_lqi(void);
*/
bool subghz_device_cc1101_ext_is_frequency_valid(uint32_t value);
/** Сheck if and why transmission is blocked on this frequency with current config
*
* @param value frequency in Hz
*
* @return tx allowed or blocked enum
*/
SubGhzTx subghz_device_cc1101_ext_check_tx(uint32_t value);
/** Set frequency
*
* @param value frequency in Hz

View File

@@ -92,6 +92,8 @@ const SubGhzDeviceInterconnect subghz_device_cc1101_ext_interconnect = {
.is_rx_data_crc_valid = subghz_device_cc1101_ext_is_rx_data_crc_valid,
.read_packet = subghz_device_cc1101_ext_read_packet,
.write_packet = subghz_device_cc1101_ext_write_packet,
.check_tx = subghz_device_cc1101_ext_check_tx,
};
const SubGhzDevice subghz_device_cc1101_ext = {

View File

@@ -652,22 +652,9 @@ bool subghz_txrx_radio_device_is_frequency_valid(SubGhzTxRx* instance, uint32_t
return subghz_devices_is_frequency_valid(instance->radio_device, frequency);
}
bool subghz_txrx_radio_device_is_tx_allowed(SubGhzTxRx* instance, uint32_t frequency) {
// TODO: Remake this function to check if the frequency is allowed on specific module - for modules not based on CC1101
SubGhzTx subghz_txrx_radio_device_check_tx(SubGhzTxRx* instance, uint32_t frequency) {
furi_assert(instance);
UNUSED(frequency);
/*
furi_assert(instance->txrx_state != SubGhzTxRxStateSleep);
subghz_devices_idle(instance->radio_device);
subghz_devices_set_frequency(instance->radio_device, frequency);
bool ret = subghz_devices_set_tx(instance->radio_device);
subghz_devices_idle(instance->radio_device);
return ret;
*/
return true;
return subghz_devices_check_tx(instance->radio_device, frequency);
}
void subghz_txrx_set_debug_pin_state(SubGhzTxRx* instance, bool state) {

View File

@@ -366,7 +366,7 @@ const char* subghz_txrx_radio_device_get_name(SubGhzTxRx* instance);
*/
bool subghz_txrx_radio_device_is_frequency_valid(SubGhzTxRx* instance, uint32_t frequency);
bool subghz_txrx_radio_device_is_tx_allowed(SubGhzTxRx* instance, uint32_t frequency);
SubGhzTx subghz_txrx_radio_device_check_tx(SubGhzTxRx* instance, uint32_t frequency);
void subghz_txrx_set_debug_pin_state(SubGhzTxRx* instance, bool state);
bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* instance);

View File

@@ -15,7 +15,7 @@ void subghz_extended_freq() {
flipper_format_read_bool(file, "ignore_default_tx_region", &is_bypassed, 1);
}
furi_hal_subghz_set_extended_frequency(is_extended_i);
furi_hal_subghz_set_extended_range(is_extended_i);
furi_hal_subghz_set_bypass_region(is_bypassed);
flipper_format_free(file);

View File

@@ -30,7 +30,8 @@ bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format) {
break;
case SubGhzTxRxStartTxStateErrorOnlyRx:
uint32_t frequency = subghz_txrx_get_preset(subghz->txrx).frequency;
subghz_dialog_message_freq_error(subghz, furi_hal_subghz_check_tx(frequency));
SubGhzTx can_tx = subghz_txrx_radio_device_check_tx(subghz->txrx, frequency);
subghz_dialog_message_freq_error(subghz, can_tx);
break;
default:
@@ -40,26 +41,26 @@ bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format) {
return false;
}
void subghz_dialog_message_freq_error(SubGhz* subghz, FuriHalSubGhzTx can_tx) {
void subghz_dialog_message_freq_error(SubGhz* subghz, SubGhzTx can_tx) {
DialogsApp* dialogs = subghz->dialogs;
DialogMessage* message = dialog_message_alloc();
const char* header_text = "Transmission is blocked";
const char* message_text;
switch(can_tx) {
case FuriHalSubGhzTxAllowed:
case SubGhzTxAllowed:
default:
return;
case FuriHalSubGhzTxBlockedRegionNotProvisioned:
case SubGhzTxBlockedRegionNotProvisioned:
message_text = "Region is not\nprovisioned.\nUpdate firmware\nor bypass region.";
break;
case FuriHalSubGhzTxBlockedRegion:
case SubGhzTxBlockedRegion:
message_text = "Frequency outside\nof region range.\nMNTM > Protocols\n> Bypass Region";
break;
case FuriHalSubGhzTxBlockedDefault:
case SubGhzTxBlockedDefault:
message_text = "Frequency outside\nof default range.\nMNTM > Protocols\n> Extend Bands";
break;
case FuriHalSubGhzTxBlockedUnsupported:
case SubGhzTxUnsupported:
header_text = "Frequency not supported";
message_text = "Frequency is\noutside of\nsupported range.";
break;
@@ -88,7 +89,7 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) {
uint32_t temp_data32;
float temp_lat = NAN; // NAN or 0.0?? because 0.0 is valid value
float temp_lon = NAN;
FuriHalSubGhzTx can_tx = FuriHalSubGhzTxAllowed;
SubGhzTx can_tx = SubGhzTxUnsupported;
do {
stream_clean(fff_data_stream);
@@ -118,14 +119,13 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) {
if(!subghz_txrx_radio_device_is_frequency_valid(subghz->txrx, temp_data32)) {
FURI_LOG_E(TAG, "Frequency not supported on chosen radio module");
can_tx = FuriHalSubGhzTxBlockedUnsupported;
can_tx = SubGhzTxUnsupported;
load_key_state = SubGhzLoadKeyStateUnsuportedFreq;
break;
}
// TODO: use different frequency allowed lists for differnet modules (non cc1101)
can_tx = furi_hal_subghz_check_tx(temp_data32);
if(can_tx != FuriHalSubGhzTxAllowed) {
can_tx = subghz_txrx_radio_device_check_tx(subghz->txrx, temp_data32);
if(can_tx != SubGhzTxAllowed) {
FURI_LOG_E(TAG, "This frequency can only be used for RX");
load_key_state = SubGhzLoadKeyStateOnlyRx;

View File

@@ -115,7 +115,7 @@ void subghz_blink_start(SubGhz* subghz);
void subghz_blink_stop(SubGhz* subghz);
bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format);
void subghz_dialog_message_freq_error(SubGhz* subghz, FuriHalSubGhzTx can_tx);
void subghz_dialog_message_freq_error(SubGhz* subghz, SubGhzTx can_tx);
bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog);
bool subghz_get_next_name_file(SubGhz* subghz, uint8_t max_len);

View File

@@ -88,6 +88,8 @@ const SubGhzDeviceInterconnect subghz_device_cc1101_int_interconnect = {
.is_rx_data_crc_valid = furi_hal_subghz_is_rx_data_crc_valid,
.read_packet = furi_hal_subghz_read_packet,
.write_packet = furi_hal_subghz_write_packet,
.check_tx = furi_hal_subghz_check_tx,
};
const SubGhzDevice subghz_device_cc1101_int = {

View File

@@ -3,6 +3,7 @@
#include "registry.h"
#include <subghz/subghz_last_settings.h>
#include <furi_hal_subghz_i.h>
void subghz_devices_init(void) {
furi_check(!subghz_device_registry_is_valid());
@@ -34,7 +35,8 @@ bool subghz_devices_begin(const SubGhzDevice* device) {
if(device->interconnect->begin) {
SubGhzDeviceConf conf = {
.ver = 1,
.extended_range = false, // TODO
.extended_range = furi_hal_subghz_get_extended_range(),
.bypass_region = furi_hal_subghz_get_bypass_region(),
.power_amp = true,
};
@@ -242,3 +244,12 @@ void subghz_devices_write_packet(const SubGhzDevice* device, const uint8_t* data
device->interconnect->write_packet(data, size);
}
}
SubGhzTx subghz_devices_check_tx(const SubGhzDevice* device, uint32_t frequency) {
SubGhzTx ret = SubGhzTxUnsupported;
furi_check(device);
if(device->interconnect->check_tx) {
ret = device->interconnect->check_tx(frequency);
}
return ret;
}

View File

@@ -47,6 +47,8 @@ bool subghz_devices_is_rx_data_crc_valid(const SubGhzDevice* device);
void subghz_devices_read_packet(const SubGhzDevice* device, uint8_t* data, uint8_t* size);
void subghz_devices_write_packet(const SubGhzDevice* device, const uint8_t* data, uint8_t size);
SubGhzTx subghz_devices_check_tx(const SubGhzDevice* device, uint32_t frequency);
#ifdef __cplusplus
}
#endif

10
lib/subghz/devices/tx.h Normal file
View File

@@ -0,0 +1,10 @@
#pragma once
/** TX Allowed or Blocked Reasons */
typedef enum {
SubGhzTxAllowed, /**< TX is allowed with this configuration */
SubGhzTxBlockedRegionNotProvisioned, /**< Region not provisioned and not bypassed */
SubGhzTxBlockedRegion, /**< Outside region, needs bypass region */
SubGhzTxBlockedDefault, /**< Outisde default, needs extended range */
SubGhzTxUnsupported, /**< No configuration would allow this */
} SubGhzTx;

View File

@@ -8,6 +8,7 @@
#include <furi_hal.h>
#include "preset.h"
#include "tx.h"
#include <flipper_application/flipper_application.h>
@@ -50,6 +51,8 @@ typedef bool (*SubGhzRxIsDataCrcValid)(void);
typedef void (*SubGhzReadPacket)(uint8_t* data, uint8_t* size);
typedef void (*SubGhzWritePacket)(const uint8_t* data, uint8_t size);
typedef SubGhzTx (*SubGhzCheckTx)(uint32_t frequency);
typedef struct {
SubGhzBegin begin;
SubGhzEnd end;
@@ -84,6 +87,7 @@ typedef struct {
SubGhzReadPacket read_packet;
SubGhzWritePacket write_packet;
SubGhzCheckTx check_tx;
} SubGhzDeviceInterconnect;
struct SubGhzDevice {
@@ -94,5 +98,6 @@ struct SubGhzDevice {
struct SubGhzDeviceConf {
uint8_t ver;
bool extended_range;
bool bypass_region;
bool power_amp;
};

View File

@@ -1676,7 +1676,7 @@ Function,-,furi_hal_spi_config_init,void,
Function,-,furi_hal_spi_config_init_early,void,
Function,-,furi_hal_spi_dma_init,void,
Function,+,furi_hal_spi_release,void,FuriHalSpiBusHandle*
Function,+,furi_hal_subghz_check_tx,FuriHalSubGhzTx,uint32_t
Function,+,furi_hal_subghz_check_tx,SubGhzTx,uint32_t
Function,-,furi_hal_subghz_dump_state,void,
Function,+,furi_hal_subghz_flush_rx,void,
Function,+,furi_hal_subghz_flush_tx,void,
@@ -3347,6 +3347,7 @@ Function,+,subghz_custom_btn_set,_Bool,uint8_t
Function,+,subghz_custom_btns_reset,void,
Function,-,subghz_device_cc1101_ext_ep,const FlipperAppPluginDescriptor*,
Function,+,subghz_devices_begin,_Bool,const SubGhzDevice*
Function,+,subghz_devices_check_tx,SubGhzTx,"const SubGhzDevice*, uint32_t"
Function,+,subghz_devices_deinit,void,
Function,+,subghz_devices_end,void,const SubGhzDevice*
Function,+,subghz_devices_flush_rx,void,const SubGhzDevice*
1 entry status name type params
1676 Function - furi_hal_spi_config_init_early void
1677 Function - furi_hal_spi_dma_init void
1678 Function + furi_hal_spi_release void FuriHalSpiBusHandle*
1679 Function + furi_hal_subghz_check_tx FuriHalSubGhzTx SubGhzTx uint32_t
1680 Function - furi_hal_subghz_dump_state void
1681 Function + furi_hal_subghz_flush_rx void
1682 Function + furi_hal_subghz_flush_tx void
3347 Function + subghz_custom_btns_reset void
3348 Function - subghz_device_cc1101_ext_ep const FlipperAppPluginDescriptor*
3349 Function + subghz_devices_begin _Bool const SubGhzDevice*
3350 Function + subghz_devices_check_tx SubGhzTx const SubGhzDevice*, uint32_t
3351 Function + subghz_devices_deinit void
3352 Function + subghz_devices_end void const SubGhzDevice*
3353 Function + subghz_devices_flush_rx void const SubGhzDevice*

View File

@@ -53,7 +53,7 @@ typedef struct {
const GpioPin* async_mirror_pin;
int8_t rolling_counter_mult;
bool extended_frequency_i : 1;
bool extended_range : 1;
bool bypass_region : 1;
} FuriHalSubGhz;
@@ -62,7 +62,7 @@ volatile FuriHalSubGhz furi_hal_subghz = {
.regulation = SubGhzRegulationTxRx,
.async_mirror_pin = NULL,
.rolling_counter_mult = 1,
.extended_frequency_i = false,
.extended_range = false,
.bypass_region = false,
};
@@ -74,14 +74,22 @@ void furi_hal_subghz_set_rolling_counter_mult(int8_t mult) {
furi_hal_subghz.rolling_counter_mult = mult;
}
void furi_hal_subghz_set_extended_frequency(bool state_i) {
furi_hal_subghz.extended_frequency_i = state_i;
void furi_hal_subghz_set_extended_range(bool enabled) {
furi_hal_subghz.extended_range = enabled;
}
bool furi_hal_subghz_get_extended_range(void) {
return furi_hal_subghz.extended_range;
}
void furi_hal_subghz_set_bypass_region(bool enabled) {
furi_hal_subghz.bypass_region = enabled;
}
bool furi_hal_subghz_get_bypass_region(void) {
return furi_hal_subghz.bypass_region;
}
void furi_hal_subghz_set_async_mirror_pin(const GpioPin* pin) {
furi_hal_subghz.async_mirror_pin = pin;
}
@@ -390,40 +398,40 @@ uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value) {
return value;
}
FuriHalSubGhzTx furi_hal_subghz_check_tx(uint32_t value) {
SubGhzTx furi_hal_subghz_check_tx(uint32_t value) {
// Check against extended range of YARD Stick One, no configuration would allow this frequency
if(!furi_hal_subghz_is_frequency_valid(value)) {
FURI_LOG_I(TAG, "Frequency blocked - outside supported range");
return FuriHalSubGhzTxBlockedUnsupported;
return SubGhzTxUnsupported;
}
// Check against default range, regardless of region restrictions
if(!furi_hal_subghz.extended_frequency_i &&
if(!furi_hal_subghz.extended_range &&
!(value >= 299999755 && value <= 350000335) && // was increased from 348 to 350
!(value >= 386999938 && value <= 467750000) && // was increased from 464 to 467.75
!(value >= 778999847 && value <= 928000000)) {
FURI_LOG_I(TAG, "Frequency blocked - outside default range");
return FuriHalSubGhzTxBlockedDefault;
return SubGhzTxBlockedDefault;
}
// Check against region restrictions, tighter than extended and default
if(!furi_hal_subghz.bypass_region) {
if(!furi_hal_region_is_provisioned()) {
FURI_LOG_I(TAG, "Frequency blocked - region not provisioned");
return FuriHalSubGhzTxBlockedRegionNotProvisioned;
return SubGhzTxBlockedRegionNotProvisioned;
}
if(!_furi_hal_region_is_frequency_allowed(value)) {
FURI_LOG_I(TAG, "Frequency blocked - outside region range");
return FuriHalSubGhzTxBlockedRegion;
return SubGhzTxBlockedRegion;
}
}
// We already checked for extended range, default range, and region range
return FuriHalSubGhzTxAllowed;
return SubGhzTxAllowed;
}
bool furi_hal_subghz_is_tx_allowed(uint32_t value) {
return furi_hal_subghz_check_tx(value) == FuriHalSubGhzTxAllowed;
return furi_hal_subghz_check_tx(value) == SubGhzTxAllowed;
}
uint32_t furi_hal_subghz_set_frequency(uint32_t value) {

View File

@@ -6,6 +6,7 @@
#pragma once
#include <lib/subghz/devices/preset.h>
#include <lib/subghz/devices/tx.h>
#include <stdbool.h>
#include <stdint.h>
@@ -165,21 +166,13 @@ bool furi_hal_subghz_is_frequency_valid(uint32_t value);
*/
uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value);
typedef enum {
FuriHalSubGhzTxAllowed, // TX is allowed with this configuration
FuriHalSubGhzTxBlockedRegionNotProvisioned, // Region not provisioned and not bypassed
FuriHalSubGhzTxBlockedRegion, // Outside region, needs bypass region
FuriHalSubGhzTxBlockedDefault, // Outisde default, needs extended range
FuriHalSubGhzTxBlockedUnsupported, // No configuration would allow this
} FuriHalSubGhzTx;
/** Сheck if and why transmission is blocked on this frequency with current config
*
* @param value frequency in Hz
*
* @return tx allowed or blocked enum
*/
FuriHalSubGhzTx furi_hal_subghz_check_tx(uint32_t value);
SubGhzTx furi_hal_subghz_check_tx(uint32_t value);
/** Сheck if transmission is allowed on this frequency with your current config
*

View File

@@ -1,5 +1,9 @@
#pragma once
void furi_hal_subghz_set_extended_frequency(bool state_i);
void furi_hal_subghz_set_extended_range(bool enabled);
bool furi_hal_subghz_get_extended_range(void);
void furi_hal_subghz_set_bypass_region(bool enabled);
bool furi_hal_subghz_get_bypass_region(void);