mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2025-02-17 05:48:33 +00:00
External radio driver in frequency analyzer & test carrier (#5)
* SubGhz App: add support ext_cc1101 in freq analyzer * SubGhz App: add support ext_cc1101 in test_carrier * SubGhz app: Deleted the temporary menu
This commit is contained in:
parent
b1850fd700
commit
dd2cad0c20
12 changed files with 206 additions and 220 deletions
|
@ -4,8 +4,6 @@
|
|||
#include <furi.h>
|
||||
#include <float_tools.h>
|
||||
|
||||
// TODO add external module
|
||||
|
||||
#define TAG "SubghzFrequencyAnalyzerWorker"
|
||||
|
||||
#define SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD -97.0f
|
||||
|
@ -30,6 +28,10 @@ struct SubGhzFrequencyAnalyzerWorker {
|
|||
FrequencyRSSI frequency_rssi_buf;
|
||||
SubGhzSetting* setting;
|
||||
|
||||
const SubGhzDevice* radio_device;
|
||||
FuriHalSpiBusHandle* spi_bus;
|
||||
bool ext_radio;
|
||||
|
||||
float filVal;
|
||||
float trigger_level;
|
||||
|
||||
|
@ -37,14 +39,16 @@ struct SubGhzFrequencyAnalyzerWorker {
|
|||
void* context;
|
||||
};
|
||||
|
||||
static void subghz_frequency_analyzer_worker_load_registers(const uint8_t data[][2]) {
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
static void subghz_frequency_analyzer_worker_load_registers(
|
||||
FuriHalSpiBusHandle* spi_bus,
|
||||
const uint8_t data[][2]) {
|
||||
furi_hal_spi_acquire(spi_bus);
|
||||
size_t i = 0;
|
||||
while(data[i][0]) {
|
||||
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, data[i][0], data[i][1]);
|
||||
cc1101_write_reg(spi_bus, data[i][0], data[i][1]);
|
||||
i++;
|
||||
}
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
furi_hal_spi_release(spi_bus);
|
||||
}
|
||||
|
||||
// running average with adaptive coefficient
|
||||
|
@ -79,31 +83,35 @@ static int32_t subghz_frequency_analyzer_worker_thread(void* context) {
|
|||
uint32_t frequency_temp = 0;
|
||||
CC1101Status status;
|
||||
|
||||
//Start CC1101
|
||||
furi_hal_subghz_reset();
|
||||
FuriHalSpiBusHandle* spi_bus = instance->spi_bus;
|
||||
const SubGhzDevice* radio_device = instance->radio_device;
|
||||
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_flush_rx(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_flush_tx(&furi_hal_spi_bus_handle_subghz);
|
||||
//Start CC1101
|
||||
// furi_hal_subghz_reset();
|
||||
subghz_devices_reset(radio_device);
|
||||
|
||||
furi_hal_spi_acquire(spi_bus);
|
||||
cc1101_flush_rx(spi_bus);
|
||||
cc1101_flush_tx(spi_bus);
|
||||
|
||||
// TODO probably can be used device.load_preset(FuriHalSubGhzPresetCustom, ...) for external cc1101
|
||||
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG0, CC1101IocfgHW);
|
||||
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_MDMCFG3,
|
||||
cc1101_write_reg(spi_bus, CC1101_IOCFG0, CC1101IocfgHW);
|
||||
cc1101_write_reg(spi_bus, CC1101_MDMCFG3,
|
||||
0b01111111); // symbol rate
|
||||
cc1101_write_reg(
|
||||
&furi_hal_spi_bus_handle_subghz,
|
||||
spi_bus,
|
||||
CC1101_AGCCTRL2,
|
||||
0b00000111); // 00 - DVGA all; 000 - MAX LNA+LNA2; 111 - MAGN_TARGET 42 dB
|
||||
cc1101_write_reg(
|
||||
&furi_hal_spi_bus_handle_subghz,
|
||||
spi_bus,
|
||||
CC1101_AGCCTRL1,
|
||||
0b00001000); // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 1000 - Absolute carrier sense threshold disabled
|
||||
cc1101_write_reg(
|
||||
&furi_hal_spi_bus_handle_subghz,
|
||||
spi_bus,
|
||||
CC1101_AGCCTRL0,
|
||||
0b00110000); // 00 - No hysteresis, medium asymmetric dead zone, medium gain ; 11 - 64 samples agc; 00 - Normal AGC, 00 - 4dB boundary
|
||||
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
furi_hal_spi_release(spi_bus);
|
||||
|
||||
furi_hal_subghz_set_path(FuriHalSubGhzPathIsolate);
|
||||
|
||||
|
@ -116,36 +124,36 @@ static int32_t subghz_frequency_analyzer_worker_thread(void* context) {
|
|||
|
||||
frequency_rssi.rssi_coarse = -127.0f;
|
||||
frequency_rssi.rssi_fine = -127.0f;
|
||||
furi_hal_subghz_idle();
|
||||
subghz_frequency_analyzer_worker_load_registers(subghz_preset_ook_650khz);
|
||||
// furi_hal_subghz_idle();
|
||||
subghz_devices_idle(radio_device);
|
||||
subghz_frequency_analyzer_worker_load_registers(spi_bus, subghz_preset_ook_650khz);
|
||||
|
||||
// First stage: coarse scan
|
||||
for(size_t i = 0; i < subghz_setting_get_frequency_count(instance->setting); i++) {
|
||||
uint32_t current_frequency = subghz_setting_get_frequency(instance->setting, i);
|
||||
if(furi_hal_subghz_is_frequency_valid(current_frequency) &&
|
||||
(current_frequency != 467750000) && (current_frequency != 464000000)
|
||||
// &&
|
||||
// !((furi_hal_subghz.radio_type == SubGhzRadioExternal) &&
|
||||
// ((current_frequency == 390000000) || (current_frequency == 312000000) ||
|
||||
// (current_frequency == 312100000) || (current_frequency == 312200000) ||
|
||||
// (current_frequency == 440175000)))
|
||||
) {
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_switch_to_idle(&furi_hal_spi_bus_handle_subghz);
|
||||
frequency =
|
||||
cc1101_set_frequency(&furi_hal_spi_bus_handle_subghz, current_frequency);
|
||||
// if(furi_hal_subghz_is_frequency_valid(current_frequency) &&
|
||||
if(subghz_devices_is_frequency_valid(radio_device, current_frequency) &&
|
||||
(current_frequency != 467750000) && (current_frequency != 464000000) &&
|
||||
!((instance->ext_radio) &&
|
||||
((current_frequency == 390000000) || (current_frequency == 312000000) ||
|
||||
(current_frequency == 312100000) || (current_frequency == 312200000) ||
|
||||
(current_frequency == 440175000)))) {
|
||||
furi_hal_spi_acquire(spi_bus);
|
||||
cc1101_switch_to_idle(spi_bus);
|
||||
frequency = cc1101_set_frequency(spi_bus, current_frequency);
|
||||
|
||||
cc1101_calibrate(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_calibrate(spi_bus);
|
||||
do {
|
||||
status = cc1101_get_status(&furi_hal_spi_bus_handle_subghz);
|
||||
status = cc1101_get_status(spi_bus);
|
||||
} while(status.STATE != CC1101StateIDLE);
|
||||
|
||||
cc1101_switch_to_rx(&furi_hal_spi_bus_handle_subghz);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_switch_to_rx(spi_bus);
|
||||
furi_hal_spi_release(spi_bus);
|
||||
|
||||
furi_delay_ms(2);
|
||||
|
||||
rssi = furi_hal_subghz_get_rssi();
|
||||
// rssi = furi_hal_subghz_get_rssi();
|
||||
rssi = subghz_devices_get_rssi(radio_device);
|
||||
|
||||
rssi_avg += rssi;
|
||||
rssi_avg_samples++;
|
||||
|
@ -169,28 +177,31 @@ static int32_t subghz_frequency_analyzer_worker_thread(void* context) {
|
|||
|
||||
// Second stage: fine scan
|
||||
if(frequency_rssi.rssi_coarse > instance->trigger_level) {
|
||||
furi_hal_subghz_idle();
|
||||
subghz_frequency_analyzer_worker_load_registers(subghz_preset_ook_58khz);
|
||||
// furi_hal_subghz_idle();
|
||||
subghz_devices_idle(radio_device);
|
||||
subghz_frequency_analyzer_worker_load_registers(spi_bus, subghz_preset_ook_58khz);
|
||||
//for example -0.3 ... 433.92 ... +0.3 step 20KHz
|
||||
for(uint32_t i = frequency_rssi.frequency_coarse - 300000;
|
||||
i < frequency_rssi.frequency_coarse + 300000;
|
||||
i += 20000) {
|
||||
if(furi_hal_subghz_is_frequency_valid(i)) {
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_switch_to_idle(&furi_hal_spi_bus_handle_subghz);
|
||||
frequency = cc1101_set_frequency(&furi_hal_spi_bus_handle_subghz, i);
|
||||
// if(furi_hal_subghz_is_frequency_valid(i)) {
|
||||
if(subghz_devices_is_frequency_valid(radio_device, i)) {
|
||||
furi_hal_spi_acquire(spi_bus);
|
||||
cc1101_switch_to_idle(spi_bus);
|
||||
frequency = cc1101_set_frequency(spi_bus, i);
|
||||
|
||||
cc1101_calibrate(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_calibrate(spi_bus);
|
||||
do {
|
||||
status = cc1101_get_status(&furi_hal_spi_bus_handle_subghz);
|
||||
status = cc1101_get_status(spi_bus);
|
||||
} while(status.STATE != CC1101StateIDLE);
|
||||
|
||||
cc1101_switch_to_rx(&furi_hal_spi_bus_handle_subghz);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_switch_to_rx(spi_bus);
|
||||
furi_hal_spi_release(spi_bus);
|
||||
|
||||
furi_delay_ms(2);
|
||||
|
||||
rssi = furi_hal_subghz_get_rssi();
|
||||
// rssi = furi_hal_subghz_get_rssi();
|
||||
rssi = subghz_devices_get_rssi(radio_device);
|
||||
|
||||
FURI_LOG_T(TAG, "#:%lu:%f", frequency, (double)rssi);
|
||||
|
||||
|
@ -267,8 +278,10 @@ static int32_t subghz_frequency_analyzer_worker_thread(void* context) {
|
|||
}
|
||||
|
||||
//Stop CC1101
|
||||
furi_hal_subghz_idle();
|
||||
furi_hal_subghz_sleep();
|
||||
// furi_hal_subghz_idle();
|
||||
// furi_hal_subghz_sleep();
|
||||
subghz_devices_idle(radio_device);
|
||||
subghz_devices_sleep(radio_device);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -307,10 +320,26 @@ void subghz_frequency_analyzer_worker_set_pair_callback(
|
|||
instance->context = context;
|
||||
}
|
||||
|
||||
void subghz_frequency_analyzer_worker_start(SubGhzFrequencyAnalyzerWorker* instance) {
|
||||
void subghz_frequency_analyzer_worker_start(
|
||||
SubGhzFrequencyAnalyzerWorker* instance,
|
||||
SubGhzTxRx* txrx) {
|
||||
furi_assert(instance);
|
||||
furi_assert(!instance->worker_running);
|
||||
|
||||
SubGhzRadioDeviceType radio_type = subghz_txrx_radio_device_get(txrx);
|
||||
|
||||
if(radio_type == SubGhzRadioDeviceTypeExternalCC1101) {
|
||||
instance->spi_bus = &furi_hal_spi_bus_handle_external;
|
||||
instance->ext_radio = true;
|
||||
} else if(radio_type == SubGhzRadioDeviceTypeInternal) {
|
||||
instance->spi_bus = &furi_hal_spi_bus_handle_subghz;
|
||||
instance->ext_radio = false;
|
||||
} else {
|
||||
furi_crash("Unsuported external module");
|
||||
}
|
||||
|
||||
instance->radio_device = subghz_devices_get_by_name(subghz_txrx_radio_device_get_name(txrx));
|
||||
|
||||
instance->worker_running = true;
|
||||
|
||||
furi_thread_start(instance->thread);
|
||||
|
|
|
@ -45,8 +45,11 @@ void subghz_frequency_analyzer_worker_set_pair_callback(
|
|||
/** Start SubGhzFrequencyAnalyzerWorker
|
||||
*
|
||||
* @param instance SubGhzFrequencyAnalyzerWorker instance
|
||||
* @param txrx pointer to SubGhzTxRx
|
||||
*/
|
||||
void subghz_frequency_analyzer_worker_start(SubGhzFrequencyAnalyzerWorker* instance);
|
||||
void subghz_frequency_analyzer_worker_start(
|
||||
SubGhzFrequencyAnalyzerWorker* instance,
|
||||
SubGhzTxRx* txrx);
|
||||
|
||||
/** Stop SubGhzFrequencyAnalyzerWorker
|
||||
*
|
||||
|
|
|
@ -30,4 +30,3 @@ ADD_SCENE(subghz, decode_raw, DecodeRAW)
|
|||
ADD_SCENE(subghz, delete_raw, DeleteRAW)
|
||||
ADD_SCENE(subghz, need_saving, NeedSaving)
|
||||
ADD_SCENE(subghz, rpc, Rpc)
|
||||
ADD_SCENE(subghz, radio_setting, RadioSettings)
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
#include "../subghz_i.h"
|
||||
#include <lib/toolbox/value_index.h>
|
||||
#include <applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h>
|
||||
|
||||
enum SubGhzRadioSettingIndex {
|
||||
SubGhzRadioSettingIndexDevice,
|
||||
};
|
||||
|
||||
#define RADIO_DEVICE_COUNT 2
|
||||
const char* const radio_device_text[RADIO_DEVICE_COUNT] = {
|
||||
"Internal",
|
||||
"External",
|
||||
};
|
||||
|
||||
const uint32_t radio_device_value[RADIO_DEVICE_COUNT] = {
|
||||
SubGhzRadioDeviceTypeInternal,
|
||||
SubGhzRadioDeviceTypeExternalCC1101,
|
||||
};
|
||||
|
||||
static void subghz_scene_radio_setting_set_device(VariableItem* item) {
|
||||
SubGhz* subghz = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
if(!subghz_txrx_radio_device_is_external_connected(
|
||||
subghz->txrx, SUBGHZ_DEVICE_CC1101_EXT_NAME) &&
|
||||
radio_device_value[index] == SubGhzRadioDeviceTypeExternalCC1101) {
|
||||
//ToDo correct if there is more than 1 module
|
||||
index = 0;
|
||||
}
|
||||
variable_item_set_current_value_text(item, radio_device_text[index]);
|
||||
subghz_txrx_radio_device_set(subghz->txrx, radio_device_value[index]);
|
||||
}
|
||||
|
||||
void subghz_scene_radio_setting_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
VariableItem* item;
|
||||
uint8_t value_index;
|
||||
|
||||
uint8_t value_count_device = RADIO_DEVICE_COUNT;
|
||||
if(subghz_txrx_radio_device_get(subghz->txrx) == SubGhzRadioDeviceTypeInternal &&
|
||||
!subghz_txrx_radio_device_is_external_connected(subghz->txrx, SUBGHZ_DEVICE_CC1101_EXT_NAME))
|
||||
value_count_device = 1; // Only 1 item if external disconnected
|
||||
item = variable_item_list_add(
|
||||
subghz->variable_item_list,
|
||||
"Module",
|
||||
value_count_device,
|
||||
subghz_scene_radio_setting_set_device,
|
||||
subghz);
|
||||
value_index = value_index_uint32(
|
||||
subghz_txrx_radio_device_get(subghz->txrx), radio_device_value, value_count_device);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, radio_device_text[value_index]);
|
||||
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdVariableItemList);
|
||||
}
|
||||
|
||||
bool subghz_scene_radio_setting_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
bool consumed = false;
|
||||
UNUSED(subghz);
|
||||
UNUSED(event);
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void subghz_scene_radio_setting_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
variable_item_list_set_selected_item(subghz->variable_item_list, 0);
|
||||
variable_item_list_reset(subghz->variable_item_list);
|
||||
}
|
|
@ -1,17 +1,18 @@
|
|||
#include "../subghz_i.h"
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
#include <lib/toolbox/value_index.h>
|
||||
#include <applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h>
|
||||
|
||||
// #define EXT_MODULES_COUNT (sizeof(radio_modules_variables_text) / sizeof(char* const))
|
||||
// const char* const radio_modules_variables_text[] = {
|
||||
// "Internal",
|
||||
// "External",
|
||||
// };
|
||||
#define RADIO_DEVICE_COUNT 2
|
||||
const char* const radio_device_text[RADIO_DEVICE_COUNT] = {
|
||||
"Internal",
|
||||
"External",
|
||||
};
|
||||
|
||||
// #define EXT_MOD_POWER_COUNT 2
|
||||
// const char* const ext_mod_power_text[EXT_MOD_POWER_COUNT] = {
|
||||
// "ON",
|
||||
// "OFF",
|
||||
// };
|
||||
const uint32_t radio_device_value[RADIO_DEVICE_COUNT] = {
|
||||
SubGhzRadioDeviceTypeInternal,
|
||||
SubGhzRadioDeviceTypeExternalCC1101,
|
||||
};
|
||||
|
||||
#define TIMESTAMP_NAMES_COUNT 2
|
||||
const char* const timestamp_names_text[TIMESTAMP_NAMES_COUNT] = {
|
||||
|
@ -35,20 +36,19 @@ const char* const debug_counter_text[DEBUG_COUNTER_COUNT] = {
|
|||
"+10",
|
||||
};
|
||||
|
||||
// static void subghz_scene_ext_module_changed(VariableItem* item) {
|
||||
// SubGhz* subghz = variable_item_get_context(item);
|
||||
// uint8_t value_index_exm = variable_item_get_current_value_index(item);
|
||||
static void subghz_scene_radio_settings_set_device(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, radio_modules_variables_text[value_index_exm]);
|
||||
|
||||
// subghz->last_settings->external_module_enabled = value_index_exm == 1;
|
||||
// subghz_last_settings_save(subghz->last_settings);
|
||||
// }
|
||||
|
||||
// static void subghz_ext_module_start_var_list_enter_callback(void* context, uint32_t index) {
|
||||
// SubGhz* subghz = context;
|
||||
// view_dispatcher_send_custom_event(subghz->view_dispatcher, index);
|
||||
// }
|
||||
if(!subghz_txrx_radio_device_is_external_connected(
|
||||
subghz->txrx, SUBGHZ_DEVICE_CC1101_EXT_NAME) &&
|
||||
radio_device_value[index] == SubGhzRadioDeviceTypeExternalCC1101) {
|
||||
//ToDo correct if there is more than 1 module
|
||||
index = 0;
|
||||
}
|
||||
variable_item_set_current_value_text(item, radio_device_text[index]);
|
||||
subghz_txrx_radio_device_set(subghz->txrx, radio_device_value[index]);
|
||||
}
|
||||
|
||||
static void subghz_scene_receiver_config_set_debug_pin(VariableItem* item) {
|
||||
SubGhz* subghz = variable_item_get_context(item);
|
||||
|
@ -122,24 +122,20 @@ void subghz_scene_radio_settings_on_enter(void* context) {
|
|||
uint8_t value_index;
|
||||
VariableItem* item;
|
||||
|
||||
// VariableItem* item = variable_item_list_add(
|
||||
// variable_item_list, "Module", EXT_MODULES_COUNT, subghz_scene_ext_module_changed, subghz);
|
||||
|
||||
// variable_item_list_set_enter_callback(
|
||||
// variable_item_list, subghz_ext_module_start_var_list_enter_callback, subghz);
|
||||
// value_index = furi_hal_subghz.radio_type;
|
||||
// variable_item_set_current_value_index(item, value_index);
|
||||
// variable_item_set_current_value_text(item, radio_modules_variables_text[value_index]);
|
||||
|
||||
// item = variable_item_list_add(
|
||||
// variable_item_list,
|
||||
// "Ext Radio 5v",
|
||||
// EXT_MOD_POWER_COUNT,
|
||||
// subghz_scene_receiver_config_set_ext_mod_power,
|
||||
// subghz);
|
||||
// value_index = furi_hal_subghz_get_external_power_disable();
|
||||
// variable_item_set_current_value_index(item, value_index);
|
||||
// variable_item_set_current_value_text(item, ext_mod_power_text[value_index]);
|
||||
uint8_t value_count_device = RADIO_DEVICE_COUNT;
|
||||
if(subghz_txrx_radio_device_get(subghz->txrx) == SubGhzRadioDeviceTypeInternal &&
|
||||
!subghz_txrx_radio_device_is_external_connected(subghz->txrx, SUBGHZ_DEVICE_CC1101_EXT_NAME))
|
||||
value_count_device = 1; // Only 1 item if external disconnected
|
||||
item = variable_item_list_add(
|
||||
subghz->variable_item_list,
|
||||
"Module",
|
||||
value_count_device,
|
||||
subghz_scene_radio_settings_set_device,
|
||||
subghz);
|
||||
value_index = value_index_uint32(
|
||||
subghz_txrx_radio_device_get(subghz->txrx), radio_device_value, value_count_device);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, radio_device_text[value_index]);
|
||||
|
||||
item = variable_item_list_add(
|
||||
variable_item_list,
|
||||
|
@ -227,25 +223,11 @@ bool subghz_scene_radio_settings_on_event(void* context, SceneManagerEvent event
|
|||
UNUSED(subghz);
|
||||
UNUSED(event);
|
||||
|
||||
// Set selected radio module
|
||||
// furi_hal_subghz_select_radio_type(subghz->last_settings->external_module_enabled);
|
||||
// furi_hal_subghz_init_radio_type(subghz->last_settings->external_module_enabled);
|
||||
|
||||
// furi_hal_subghz_enable_ext_power();
|
||||
|
||||
// Check if module is present, if no -> show error
|
||||
// if(!furi_hal_subghz_check_radio()) {
|
||||
// subghz->last_settings->external_module_enabled = false;
|
||||
// furi_hal_subghz_select_radio_type(SubGhzRadioInternal);
|
||||
// furi_hal_subghz_init_radio_type(SubGhzRadioInternal);
|
||||
// furi_string_set(subghz->error_str, "Please connect\nexternal radio");
|
||||
// scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowErrorSub);
|
||||
// }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_radio_settings_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
variable_item_list_set_selected_item(subghz->variable_item_list, 0);
|
||||
variable_item_list_reset(subghz->variable_item_list);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "../subghz_i.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
// TODO move RadioSettings to ExtraSettings
|
||||
#include <lib/subghz/protocols/raw.h>
|
||||
|
||||
enum SubmenuIndex {
|
||||
|
@ -54,12 +53,6 @@ void subghz_scene_start_on_enter(void* context) {
|
|||
SubmenuIndexExtSettings,
|
||||
subghz_scene_start_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Radio Settings2",
|
||||
SubmenuIndexRadioSetting,
|
||||
subghz_scene_start_submenu_callback,
|
||||
subghz);
|
||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
||||
submenu_add_item(
|
||||
subghz->submenu, "Test", SubmenuIndexTest, subghz_scene_start_submenu_callback, subghz);
|
||||
|
@ -115,11 +108,6 @@ bool subghz_scene_start_on_event(void* context, SceneManagerEvent event) {
|
|||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexExtSettings);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneExtModuleSettings);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexRadioSetting) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexRadioSetting);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneRadioSettings);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -11,6 +11,9 @@ void subghz_scene_test_carrier_on_enter(void* context) {
|
|||
SubGhz* subghz = context;
|
||||
subghz_test_carrier_set_callback(
|
||||
subghz->subghz_test_carrier, subghz_scene_test_carrier_callback, subghz);
|
||||
subghz_test_carrier_set_radio(
|
||||
subghz->subghz_test_carrier,
|
||||
subghz_devices_get_by_name(subghz_txrx_radio_device_get_name(subghz->txrx)));
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdTestCarrier);
|
||||
}
|
||||
|
||||
|
|
|
@ -112,6 +112,8 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) {
|
|||
// Open Notification record
|
||||
subghz->notifications = furi_record_open(RECORD_NOTIFICATION);
|
||||
|
||||
subghz->txrx = subghz_txrx_alloc();
|
||||
|
||||
if(!alloc_for_tx_only) {
|
||||
// SubMenu
|
||||
subghz->submenu = submenu_alloc();
|
||||
|
@ -167,7 +169,8 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) {
|
|||
variable_item_list_get_view(subghz->variable_item_list));
|
||||
|
||||
// Frequency Analyzer
|
||||
subghz->subghz_frequency_analyzer = subghz_frequency_analyzer_alloc();
|
||||
// View knows too much
|
||||
subghz->subghz_frequency_analyzer = subghz_frequency_analyzer_alloc(subghz->txrx);
|
||||
view_dispatcher_add_view(
|
||||
subghz->view_dispatcher,
|
||||
SubGhzViewIdFrequencyAnalyzer,
|
||||
|
@ -209,8 +212,6 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) {
|
|||
//init TxRx & Protocol & History & KeyBoard
|
||||
subghz_unlock(subghz);
|
||||
|
||||
subghz->txrx = subghz_txrx_alloc();
|
||||
|
||||
SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx);
|
||||
|
||||
subghz_load_custom_presets(setting);
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
#include <assets_icons.h>
|
||||
#include <float_tools.h>
|
||||
|
||||
// TODO remove furi_hal_subghz
|
||||
|
||||
#define TAG "frequency_analyzer"
|
||||
|
||||
#define RSSI_MIN -97
|
||||
|
@ -40,6 +38,7 @@ struct SubGhzFrequencyAnalyzer {
|
|||
SubGhzFrequencyAnalyzerWorker* worker;
|
||||
SubGhzFrequencyAnalyzerCallback callback;
|
||||
void* context;
|
||||
SubGhzTxRx* txrx;
|
||||
bool locked;
|
||||
SubGHzFrequencyAnalyzerFeedbackLevel
|
||||
feedback_level; // 0 - no feedback, 1 - vibro only, 2 - vibro and sound
|
||||
|
@ -62,6 +61,7 @@ typedef struct {
|
|||
uint8_t selected_index;
|
||||
uint8_t max_index;
|
||||
bool show_frame;
|
||||
bool is_ext_radio;
|
||||
} SubGhzFrequencyAnalyzerModel;
|
||||
|
||||
void subghz_frequency_analyzer_set_callback(
|
||||
|
@ -168,8 +168,8 @@ void subghz_frequency_analyzer_draw(Canvas* canvas, SubGhzFrequencyAnalyzerModel
|
|||
// Title
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
// TODO
|
||||
// canvas_draw_str(canvas, 0, 7, furi_hal_subghz_get_radio_type() ? "Ext" : "Int");
|
||||
|
||||
canvas_draw_str(canvas, 0, 7, model->is_ext_radio ? "Ext" : "Int");
|
||||
canvas_draw_str(canvas, 20, 7, "Frequency Analyzer");
|
||||
|
||||
// RSSI
|
||||
|
@ -314,7 +314,9 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) {
|
|||
uint32_t prev_freq_to_save = model->frequency_to_save;
|
||||
uint32_t frequency_candidate = model->history_frequency[model->selected_index];
|
||||
if(frequency_candidate == 0 ||
|
||||
!furi_hal_subghz_is_frequency_valid(frequency_candidate) ||
|
||||
// !furi_hal_subghz_is_frequency_valid(frequency_candidate) ||
|
||||
!subghz_txrx_radio_device_is_frequecy_valid(
|
||||
instance->txrx, frequency_candidate) ||
|
||||
prev_freq_to_save == frequency_candidate) {
|
||||
frequency_candidate = 0;
|
||||
} else {
|
||||
|
@ -336,7 +338,9 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) {
|
|||
uint32_t prev_freq_to_save = model->frequency_to_save;
|
||||
uint32_t frequency_candidate = subghz_frequency_find_correct(model->frequency);
|
||||
if(frequency_candidate == 0 ||
|
||||
!furi_hal_subghz_is_frequency_valid(frequency_candidate) ||
|
||||
// !furi_hal_subghz_is_frequency_valid(frequency_candidate) ||
|
||||
!subghz_txrx_radio_device_is_frequecy_valid(
|
||||
instance->txrx, frequency_candidate) ||
|
||||
prev_freq_to_save == frequency_candidate) {
|
||||
frequency_candidate = 0;
|
||||
} else {
|
||||
|
@ -351,7 +355,9 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) {
|
|||
uint32_t prev_freq_to_save = model->frequency_to_save;
|
||||
uint32_t frequency_candidate = subghz_frequency_find_correct(model->frequency);
|
||||
if(frequency_candidate == 0 ||
|
||||
!furi_hal_subghz_is_frequency_valid(frequency_candidate) ||
|
||||
// !furi_hal_subghz_is_frequency_valid(frequency_candidate) ||
|
||||
!subghz_txrx_radio_device_is_frequecy_valid(
|
||||
instance->txrx, frequency_candidate) ||
|
||||
prev_freq_to_save == frequency_candidate) {
|
||||
frequency_candidate = 0;
|
||||
} else {
|
||||
|
@ -542,7 +548,7 @@ void subghz_frequency_analyzer_enter(void* context) {
|
|||
(SubGhzFrequencyAnalyzerWorkerPairCallback)subghz_frequency_analyzer_pair_callback,
|
||||
instance);
|
||||
|
||||
subghz_frequency_analyzer_worker_start(instance->worker);
|
||||
subghz_frequency_analyzer_worker_start(instance->worker, instance->txrx);
|
||||
|
||||
instance->rssi_last = 0;
|
||||
instance->selected_index = 0;
|
||||
|
@ -570,6 +576,8 @@ void subghz_frequency_analyzer_enter(void* context) {
|
|||
model->history_frequency_rx_count[0] = 0;
|
||||
model->frequency_to_save = 0;
|
||||
model->trigger = RSSI_MIN;
|
||||
model->is_ext_radio =
|
||||
(subghz_txrx_radio_device_get(instance->txrx) != SubGhzRadioDeviceTypeInternal);
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
@ -587,7 +595,7 @@ void subghz_frequency_analyzer_exit(void* context) {
|
|||
furi_record_close(RECORD_NOTIFICATION);
|
||||
}
|
||||
|
||||
SubGhzFrequencyAnalyzer* subghz_frequency_analyzer_alloc() {
|
||||
SubGhzFrequencyAnalyzer* subghz_frequency_analyzer_alloc(SubGhzTxRx* txrx) {
|
||||
SubGhzFrequencyAnalyzer* instance = malloc(sizeof(SubGhzFrequencyAnalyzer));
|
||||
|
||||
instance->feedback_level = 2;
|
||||
|
@ -602,6 +610,8 @@ SubGhzFrequencyAnalyzer* subghz_frequency_analyzer_alloc() {
|
|||
view_set_enter_callback(instance->view, subghz_frequency_analyzer_enter);
|
||||
view_set_exit_callback(instance->view, subghz_frequency_analyzer_exit);
|
||||
|
||||
instance->txrx = txrx;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <gui/view.h>
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
#include "../helpers/subghz_txrx.h"
|
||||
|
||||
typedef enum {
|
||||
SubGHzFrequencyAnalyzerFeedbackLevelAll,
|
||||
|
@ -18,7 +19,7 @@ void subghz_frequency_analyzer_set_callback(
|
|||
SubGhzFrequencyAnalyzerCallback callback,
|
||||
void* context);
|
||||
|
||||
SubGhzFrequencyAnalyzer* subghz_frequency_analyzer_alloc();
|
||||
SubGhzFrequencyAnalyzer* subghz_frequency_analyzer_alloc(SubGhzTxRx* txrx);
|
||||
|
||||
void subghz_frequency_analyzer_free(SubGhzFrequencyAnalyzer* subghz_static);
|
||||
|
||||
|
|
|
@ -8,12 +8,11 @@
|
|||
#include <furi_hal.h>
|
||||
#include <input/input.h>
|
||||
|
||||
// TODO add external module
|
||||
|
||||
struct SubGhzTestCarrier {
|
||||
View* view;
|
||||
FuriTimer* timer;
|
||||
SubGhzTestCarrierCallback callback;
|
||||
const SubGhzDevice* radio_device;
|
||||
void* context;
|
||||
};
|
||||
|
||||
|
@ -86,6 +85,7 @@ void subghz_test_carrier_draw(Canvas* canvas, SubGhzTestCarrierModel* model) {
|
|||
bool subghz_test_carrier_input(InputEvent* event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzTestCarrier* subghz_test_carrier = context;
|
||||
const SubGhzDevice* radio_device = subghz_test_carrier->radio_device;
|
||||
|
||||
if(event->key == InputKeyBack || event->type != InputTypeShort) {
|
||||
return false;
|
||||
|
@ -95,7 +95,8 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
|
|||
subghz_test_carrier->view,
|
||||
SubGhzTestCarrierModel * model,
|
||||
{
|
||||
furi_hal_subghz_idle();
|
||||
// furi_hal_subghz_idle();
|
||||
subghz_devices_idle(radio_device);
|
||||
|
||||
if(event->key == InputKeyLeft) {
|
||||
if(model->frequency > 0) model->frequency--;
|
||||
|
@ -113,19 +114,33 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
|
|||
}
|
||||
}
|
||||
|
||||
model->real_frequency =
|
||||
furi_hal_subghz_set_frequency(subghz_frequencies_testing[model->frequency]);
|
||||
// model->real_frequency =
|
||||
// furi_hal_subghz_set_frequency(subghz_frequencies_testing[model->frequency]);
|
||||
furi_hal_subghz_set_path(model->path);
|
||||
model->real_frequency = subghz_devices_set_frequency(
|
||||
radio_device, subghz_frequencies_testing[model->frequency]);
|
||||
|
||||
if(model->status == SubGhzTestCarrierModelStatusRx) {
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_subghz_rx();
|
||||
// furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
// furi_hal_subghz_rx();
|
||||
furi_hal_gpio_init(
|
||||
subghz_devices_get_data_gpio(radio_device),
|
||||
GpioModeInput,
|
||||
GpioPullNo,
|
||||
GpioSpeedLow);
|
||||
subghz_devices_set_rx(radio_device);
|
||||
} else {
|
||||
furi_hal_gpio_init(
|
||||
&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_write(&gpio_cc1101_g0, true);
|
||||
if(!furi_hal_subghz_tx()) {
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
// if(!furi_hal_subghz_tx()) {
|
||||
// furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
if(!subghz_devices_set_tx(radio_device)) {
|
||||
furi_hal_gpio_init(
|
||||
subghz_devices_get_data_gpio(radio_device),
|
||||
GpioModeInput,
|
||||
GpioPullNo,
|
||||
GpioSpeedLow);
|
||||
subghz_test_carrier->callback(
|
||||
SubGhzTestCarrierEventOnlyRx, subghz_test_carrier->context);
|
||||
}
|
||||
|
@ -139,26 +154,37 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
|
|||
void subghz_test_carrier_enter(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzTestCarrier* subghz_test_carrier = context;
|
||||
furi_assert(subghz_test_carrier->radio_device);
|
||||
const SubGhzDevice* radio_device = subghz_test_carrier->radio_device;
|
||||
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_ook_650khz_async_regs);
|
||||
// furi_hal_subghz_reset();
|
||||
// furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_ook_650khz_async_regs);
|
||||
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
// furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
subghz_devices_reset(radio_device);
|
||||
subghz_devices_load_preset(radio_device, FuriHalSubGhzPresetOok650Async, NULL);
|
||||
|
||||
furi_hal_gpio_init(
|
||||
subghz_devices_get_data_gpio(radio_device), GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
with_view_model(
|
||||
subghz_test_carrier->view,
|
||||
SubGhzTestCarrierModel * model,
|
||||
{
|
||||
model->frequency = subghz_frequencies_433_92_testing; // 433
|
||||
model->real_frequency =
|
||||
furi_hal_subghz_set_frequency(subghz_frequencies_testing[model->frequency]);
|
||||
// model->real_frequency =
|
||||
// furi_hal_subghz_set_frequency(subghz_frequencies_testing[model->frequency]);
|
||||
model->real_frequency = subghz_devices_set_frequency(
|
||||
radio_device, subghz_frequencies_testing[model->frequency]);
|
||||
model->path = FuriHalSubGhzPathIsolate; // isolate
|
||||
model->rssi = 0.0f;
|
||||
model->status = SubGhzTestCarrierModelStatusRx;
|
||||
},
|
||||
true);
|
||||
|
||||
furi_hal_subghz_rx();
|
||||
// furi_hal_subghz_rx();
|
||||
subghz_devices_set_rx(radio_device);
|
||||
|
||||
furi_timer_start(subghz_test_carrier->timer, furi_kernel_get_tick_frequency() / 4);
|
||||
}
|
||||
|
@ -170,7 +196,8 @@ void subghz_test_carrier_exit(void* context) {
|
|||
furi_timer_stop(subghz_test_carrier->timer);
|
||||
|
||||
// Reinitialize IC to default state
|
||||
furi_hal_subghz_sleep();
|
||||
// furi_hal_subghz_sleep();
|
||||
subghz_devices_sleep(subghz_test_carrier->radio_device);
|
||||
}
|
||||
|
||||
void subghz_test_carrier_rssi_timer_callback(void* context) {
|
||||
|
@ -182,7 +209,8 @@ void subghz_test_carrier_rssi_timer_callback(void* context) {
|
|||
SubGhzTestCarrierModel * model,
|
||||
{
|
||||
if(model->status == SubGhzTestCarrierModelStatusRx) {
|
||||
model->rssi = furi_hal_subghz_get_rssi();
|
||||
// model->rssi = furi_hal_subghz_get_rssi();
|
||||
model->rssi = subghz_devices_get_rssi(subghz_test_carrier->radio_device);
|
||||
}
|
||||
},
|
||||
false);
|
||||
|
@ -218,3 +246,10 @@ View* subghz_test_carrier_get_view(SubGhzTestCarrier* subghz_test_carrier) {
|
|||
furi_assert(subghz_test_carrier);
|
||||
return subghz_test_carrier->view;
|
||||
}
|
||||
|
||||
void subghz_test_carrier_set_radio(
|
||||
SubGhzTestCarrier* subghz_test_carrier,
|
||||
const SubGhzDevice* radio_device) {
|
||||
furi_assert(subghz_test_carrier);
|
||||
subghz_test_carrier->radio_device = radio_device;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include <lib/subghz/devices/devices.h>
|
||||
|
||||
typedef enum {
|
||||
SubGhzTestCarrierEventOnlyRx,
|
||||
|
@ -20,3 +21,7 @@ SubGhzTestCarrier* subghz_test_carrier_alloc();
|
|||
void subghz_test_carrier_free(SubGhzTestCarrier* subghz_test_carrier);
|
||||
|
||||
View* subghz_test_carrier_get_view(SubGhzTestCarrier* subghz_test_carrier);
|
||||
|
||||
void subghz_test_carrier_set_radio(
|
||||
SubGhzTestCarrier* subghz_test_carrier,
|
||||
const SubGhzDevice* radio_device);
|
||||
|
|
Loading…
Add table
Reference in a new issue