Merge pull request #564 from DarkFlippers/cc1101_power_amp

Init config for external radio driver
This commit is contained in:
MMX 2023-07-31 00:25:32 +03:00 committed by GitHub
commit 7413f707ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 87 additions and 142 deletions

View file

@ -18,7 +18,10 @@
#define TAG "SubGhz_Device_CC1101_Ext" #define TAG "SubGhz_Device_CC1101_Ext"
#define SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO &gpio_ext_pb2 #define SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO &gpio_ext_pb2
#define SUBGHZ_DEVICE_CC1101_EXT_DANGEROUS_RANGE false #define SUBGHZ_DEVICE_CC1101_EXT_E07_AMP_GPIO &gpio_ext_pc3
#define SUBGHZ_DEVICE_CC1101_EXT_FORCE_DANGEROUS_RANGE false
#define SUBGHZ_DEVICE_CC1101_CONFIG_VER 1
/* DMA Channels definition */ /* DMA Channels definition */
#define SUBGHZ_DEVICE_CC1101_EXT_DMA DMA2 #define SUBGHZ_DEVICE_CC1101_EXT_DMA DMA2
@ -78,6 +81,8 @@ typedef struct {
const GpioPin* g0_pin; const GpioPin* g0_pin;
SubGhzDeviceCC1101ExtAsyncTx async_tx; SubGhzDeviceCC1101ExtAsyncTx async_tx;
SubGhzDeviceCC1101ExtAsyncRx async_rx; SubGhzDeviceCC1101ExtAsyncRx async_rx;
bool power_amp;
bool extended_range;
} SubGhzDeviceCC1101Ext; } SubGhzDeviceCC1101Ext;
static SubGhzDeviceCC1101Ext* subghz_device_cc1101_ext = NULL; static SubGhzDeviceCC1101Ext* subghz_device_cc1101_ext = NULL;
@ -187,7 +192,7 @@ static bool subghz_device_cc1101_ext_check_init() {
return ret; return ret;
} }
bool subghz_device_cc1101_ext_alloc() { bool subghz_device_cc1101_ext_alloc(SubGhzDeviceConf* conf) {
furi_assert(subghz_device_cc1101_ext == NULL); furi_assert(subghz_device_cc1101_ext == NULL);
subghz_device_cc1101_ext = malloc(sizeof(SubGhzDeviceCC1101Ext)); subghz_device_cc1101_ext = malloc(sizeof(SubGhzDeviceCC1101Ext));
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateInit; subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateInit;
@ -195,16 +200,35 @@ bool subghz_device_cc1101_ext_alloc() {
subghz_device_cc1101_ext->async_mirror_pin = NULL; 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->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->g0_pin = SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO;
subghz_device_cc1101_ext->power_amp = 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->extended_range = conf->extented_range;
} else {
FURI_LOG_E(TAG, "Config version mismatch");
}
}
subghz_device_cc1101_ext->async_rx.capture_delta_duration = 0; subghz_device_cc1101_ext->async_rx.capture_delta_duration = 0;
furi_hal_spi_bus_handle_init(subghz_device_cc1101_ext->spi_bus_handle); furi_hal_spi_bus_handle_init(subghz_device_cc1101_ext->spi_bus_handle);
if(subghz_device_cc1101_ext->power_amp) {
furi_hal_gpio_init_simple(SUBGHZ_DEVICE_CC1101_EXT_E07_AMP_GPIO, GpioModeOutputPushPull);
}
return subghz_device_cc1101_ext_check_init(); return subghz_device_cc1101_ext_check_init();
} }
void subghz_device_cc1101_ext_free() { void subghz_device_cc1101_ext_free() {
furi_assert(subghz_device_cc1101_ext != NULL); furi_assert(subghz_device_cc1101_ext != NULL);
furi_hal_spi_bus_handle_deinit(subghz_device_cc1101_ext->spi_bus_handle); furi_hal_spi_bus_handle_deinit(subghz_device_cc1101_ext->spi_bus_handle);
if(subghz_device_cc1101_ext->power_amp) {
furi_hal_gpio_init_simple(SUBGHZ_DEVICE_CC1101_EXT_E07_AMP_GPIO, GpioModeAnalog);
}
free(subghz_device_cc1101_ext); free(subghz_device_cc1101_ext);
subghz_device_cc1101_ext = NULL; subghz_device_cc1101_ext = NULL;
} }
@ -221,7 +245,7 @@ bool subghz_device_cc1101_ext_is_connect() {
bool ret = false; bool ret = false;
if(subghz_device_cc1101_ext == NULL) { // not initialized if(subghz_device_cc1101_ext == NULL) { // not initialized
ret = subghz_device_cc1101_ext_alloc(); ret = subghz_device_cc1101_ext_alloc(NULL);
subghz_device_cc1101_ext_free(); subghz_device_cc1101_ext_free();
} else { // initialized } else { // initialized
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle); furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
@ -381,12 +405,18 @@ void subghz_device_cc1101_ext_idle() {
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle); furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
cc1101_switch_to_idle(subghz_device_cc1101_ext->spi_bus_handle); cc1101_switch_to_idle(subghz_device_cc1101_ext->spi_bus_handle);
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle); 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);
}
} }
void subghz_device_cc1101_ext_rx() { void subghz_device_cc1101_ext_rx() {
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle); furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
cc1101_switch_to_rx(subghz_device_cc1101_ext->spi_bus_handle); cc1101_switch_to_rx(subghz_device_cc1101_ext->spi_bus_handle);
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle); 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() { bool subghz_device_cc1101_ext_tx() {
@ -394,6 +424,9 @@ bool subghz_device_cc1101_ext_tx() {
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle); furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
cc1101_switch_to_tx(subghz_device_cc1101_ext->spi_bus_handle); cc1101_switch_to_tx(subghz_device_cc1101_ext->spi_bus_handle);
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle); 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, 1);
}
return true; return true;
} }
@ -432,14 +465,16 @@ bool subghz_device_cc1101_ext_is_frequency_valid(uint32_t value) {
} }
bool subghz_device_cc1101_ext_is_tx_allowed(uint32_t value) { bool subghz_device_cc1101_ext_is_tx_allowed(uint32_t value) {
if(!(SUBGHZ_DEVICE_CC1101_EXT_DANGEROUS_RANGE) && if(!(SUBGHZ_DEVICE_CC1101_EXT_FORCE_DANGEROUS_RANGE ||
subghz_device_cc1101_ext->extended_range) &&
!(value >= 299999755 && value <= 350000335) && // was increased from 348 to 350 !(value >= 299999755 && value <= 350000335) && // was increased from 348 to 350
!(value >= 386999938 && value <= 467750000) && // was increased from 464 to 467.75 !(value >= 386999938 && value <= 467750000) && // was increased from 464 to 467.75
!(value >= 778999847 && value <= 928000000)) { !(value >= 778999847 && value <= 928000000)) {
FURI_LOG_I(TAG, "Frequency blocked - outside default range"); FURI_LOG_I(TAG, "Frequency blocked - outside default range");
return false; return false;
} else if( } else if(
(SUBGHZ_DEVICE_CC1101_EXT_DANGEROUS_RANGE) && (SUBGHZ_DEVICE_CC1101_EXT_FORCE_DANGEROUS_RANGE ||
subghz_device_cc1101_ext->extended_range) &&
!subghz_device_cc1101_ext_is_frequency_valid(value)) { !subghz_device_cc1101_ext_is_frequency_valid(value)) {
FURI_LOG_I(TAG, "Frequency blocked - outside dangerous range"); FURI_LOG_I(TAG, "Frequency blocked - outside dangerous range");
return false; return false;
@ -529,7 +564,7 @@ void subghz_device_cc1101_ext_start_async_rx(
furi_hal_bus_enable(FuriHalBusTIM17); furi_hal_bus_enable(FuriHalBusTIM17);
// Configure TIM // Configure TIM
//Set the timer resolution to 2 µs //Set the timer resolution to 2 <EFBFBD>s
LL_TIM_SetPrescaler(TIM17, (64 << 1) - 1); LL_TIM_SetPrescaler(TIM17, (64 << 1) - 1);
LL_TIM_SetCounterMode(TIM17, LL_TIM_COUNTERMODE_UP); LL_TIM_SetCounterMode(TIM17, LL_TIM_COUNTERMODE_UP);
LL_TIM_SetAutoReload(TIM17, 0xFFFF); LL_TIM_SetAutoReload(TIM17, 0xFFFF);
@ -710,7 +745,7 @@ bool subghz_device_cc1101_ext_start_async_tx(SubGhzDeviceCC1101ExtCallback callb
furi_hal_bus_enable(FuriHalBusTIM17); furi_hal_bus_enable(FuriHalBusTIM17);
// Configure TIM // Configure TIM
// Set the timer resolution to 2 µs // Set the timer resolution to 2 <EFBFBD>s
LL_TIM_SetPrescaler(TIM17, (64 << 1) - 1); LL_TIM_SetPrescaler(TIM17, (64 << 1) - 1);
LL_TIM_SetCounterMode(TIM17, LL_TIM_COUNTERMODE_UP); LL_TIM_SetCounterMode(TIM17, LL_TIM_COUNTERMODE_UP);
LL_TIM_SetAutoReload(TIM17, 0xFFFF); LL_TIM_SetAutoReload(TIM17, 0xFFFF);

View file

@ -5,6 +5,7 @@
#pragma once #pragma once
#include <lib/subghz/devices/preset.h> #include <lib/subghz/devices/preset.h>
#include <lib/subghz/devices/types.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
@ -34,7 +35,7 @@ const GpioPin* subghz_device_cc1101_ext_get_data_gpio();
* *
* @return true if success * @return true if success
*/ */
bool subghz_device_cc1101_ext_alloc(); bool subghz_device_cc1101_ext_alloc(SubGhzDeviceConf* conf);
/** Deinitialize device /** Deinitialize device
*/ */

View file

@ -41,6 +41,14 @@ const char* const debug_counter_text[DEBUG_COUNTER_COUNT] = {
"+5", "+5",
"+10", "+10",
}; };
const uint32_t debug_counter_val[DEBUG_COUNTER_COUNT] = {
1,
2,
3,
4,
5,
10,
};
static void subghz_scene_radio_settings_set_device(VariableItem* item) { static void subghz_scene_radio_settings_set_device(VariableItem* item) {
SubGhz* subghz = variable_item_get_context(item); SubGhz* subghz = variable_item_get_context(item);
@ -69,47 +77,8 @@ static void subghz_scene_receiver_config_set_debug_counter(VariableItem* item) {
uint8_t index = variable_item_get_current_value_index(item); uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, debug_counter_text[index]); variable_item_set_current_value_text(item, debug_counter_text[index]);
furi_hal_subghz_set_rolling_counter_mult(debug_counter_val[index]);
switch(index) {
case 0:
furi_hal_subghz_set_rolling_counter_mult(1);
break;
case 1:
furi_hal_subghz_set_rolling_counter_mult(2);
break;
case 2:
furi_hal_subghz_set_rolling_counter_mult(3);
break;
case 3:
furi_hal_subghz_set_rolling_counter_mult(4);
break;
case 4:
furi_hal_subghz_set_rolling_counter_mult(5);
break;
case 5:
furi_hal_subghz_set_rolling_counter_mult(10);
break;
default:
break;
} }
}
// static void subghz_scene_receiver_config_set_ext_mod_power(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, ext_mod_power_text[index]);
// furi_hal_subghz_set_external_power_disable(index == 1);
// if(index == 1) {
// furi_hal_subghz_disable_ext_power();
// } else {
// furi_hal_subghz_enable_ext_power();
// }
// subghz->last_settings->external_module_power_5v_disable = index == 1;
// subghz_last_settings_save(subghz->last_settings);
// }
static void subghz_scene_reciever_config_set_ext_mod_power_amp_text(VariableItem* item) { static void subghz_scene_reciever_config_set_ext_mod_power_amp_text(VariableItem* item) {
SubGhz* subghz = variable_item_get_context(item); SubGhz* subghz = variable_item_get_context(item);
@ -117,18 +86,19 @@ static void subghz_scene_reciever_config_set_ext_mod_power_amp_text(VariableItem
variable_item_set_current_value_text(item, ext_mod_power_amp_text[index]); variable_item_set_current_value_text(item, ext_mod_power_amp_text[index]);
if(index == 1) {
furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull);
} else {
furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog);
}
subghz->last_settings->external_module_power_amp = index == 1; subghz->last_settings->external_module_power_amp = index == 1;
// Set globally in furi hal // Set globally in furi hal
furi_hal_subghz_set_ext_power_amp(subghz->last_settings->external_module_power_amp); furi_hal_subghz_set_ext_power_amp(subghz->last_settings->external_module_power_amp);
subghz_last_settings_save(subghz->last_settings); 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_timestamp_file_names(VariableItem* item) { static void subghz_scene_receiver_config_set_timestamp_file_names(VariableItem* item) {
@ -183,59 +153,18 @@ void subghz_scene_radio_settings_on_enter(void* context) {
variable_item_set_current_value_index(item, value_index); 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, timestamp_names_text[value_index]);
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
item = variable_item_list_add( item = variable_item_list_add(
variable_item_list, variable_item_list,
"Counter Incr.", "Counter Incr.",
DEBUG_COUNTER_COUNT, furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug) ? DEBUG_COUNTER_COUNT : 3,
subghz_scene_receiver_config_set_debug_counter, subghz_scene_receiver_config_set_debug_counter,
subghz); subghz);
switch(furi_hal_subghz_get_rolling_counter_mult()) { value_index = value_index_uint32(
case 1: furi_hal_subghz_get_rolling_counter_mult(),
value_index = 0; debug_counter_val,
break; furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug) ? DEBUG_COUNTER_COUNT : 3);
case 2: furi_hal_subghz_set_rolling_counter_mult(debug_counter_val[value_index]);
value_index = 1;
break;
case 3:
value_index = 2;
break;
case 4:
value_index = 3;
break;
case 5:
value_index = 4;
break;
case 10:
value_index = 5;
break;
default:
break;
}
} else {
item = variable_item_list_add(
variable_item_list,
"Counter Incr.",
3,
subghz_scene_receiver_config_set_debug_counter,
subghz);
switch(furi_hal_subghz_get_rolling_counter_mult()) {
case 1:
value_index = 0;
break;
case 2:
value_index = 1;
break;
case 3:
value_index = 2;
break;
default:
// Reset to default value
value_index = 0;
furi_hal_subghz_set_rolling_counter_mult(1);
break;
}
}
variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, debug_counter_text[value_index]); variable_item_set_current_value_text(item, debug_counter_text[value_index]);

View file

@ -30,14 +30,13 @@ bool subghz_devices_begin(const SubGhzDevice* device) {
bool ret = false; bool ret = false;
furi_assert(device); furi_assert(device);
if(device->interconnect->begin) { if(device->interconnect->begin) {
// TODO: Remake this check and move this code SubGhzDeviceConf conf = {
if(strcmp("cc1101_ext", device->name) == 0) { .ver = 1,
if(furi_hal_subghz_get_ext_power_amp()) { .extended_range = false, // TODO
furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull); .power_amp = furi_hal_subghz_get_ext_power_amp(),
} };
}
ret = device->interconnect->begin(); ret = device->interconnect->begin(&conf);
} }
return ret; return ret;
} }
@ -45,12 +44,6 @@ bool subghz_devices_begin(const SubGhzDevice* device) {
void subghz_devices_end(const SubGhzDevice* device) { void subghz_devices_end(const SubGhzDevice* device) {
furi_assert(device); furi_assert(device);
if(device->interconnect->end) { if(device->interconnect->end) {
// TODO: Remake this check and move this code
if(strcmp("cc1101_ext", device->name) == 0) {
if(furi_hal_subghz_get_ext_power_amp()) {
furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog);
}
}
device->interconnect->end(); device->interconnect->end();
} }
} }
@ -82,12 +75,6 @@ void subghz_devices_idle(const SubGhzDevice* device) {
furi_assert(device); furi_assert(device);
if(device->interconnect->idle) { if(device->interconnect->idle) {
device->interconnect->idle(); device->interconnect->idle();
// TODO: Remake this check and move this code
if(strcmp("cc1101_ext", device->name) == 0) {
if(furi_hal_subghz_get_ext_power_amp()) {
furi_hal_gpio_write(&gpio_ext_pc3, 0);
}
}
} }
} }
@ -140,13 +127,6 @@ bool subghz_devices_set_tx(const SubGhzDevice* device) {
furi_assert(device); furi_assert(device);
if(device->interconnect->set_tx) { if(device->interconnect->set_tx) {
ret = device->interconnect->set_tx(); ret = device->interconnect->set_tx();
// TODO: Remake this check and move this code
if(strcmp("cc1101_ext", device->name) == 0) {
if(furi_hal_subghz_get_ext_power_amp()) {
furi_hal_gpio_write(&gpio_ext_pc3, 1);
}
}
} }
return ret; return ret;
} }
@ -187,13 +167,6 @@ void subghz_devices_set_rx(const SubGhzDevice* device) {
furi_assert(device); furi_assert(device);
if(device->interconnect->set_rx) { if(device->interconnect->set_rx) {
device->interconnect->set_rx(); device->interconnect->set_rx();
// TODO: Remake this check and move this code
if(strcmp("cc1101_ext", device->name) == 0) {
if(furi_hal_subghz_get_ext_power_amp()) {
furi_hal_gpio_write(&gpio_ext_pc3, 0);
}
}
} }
} }

View file

@ -12,12 +12,13 @@
#include <flipper_application/flipper_application.h> #include <flipper_application/flipper_application.h>
#define SUBGHZ_RADIO_DEVICE_PLUGIN_APP_ID "subghz_radio_device" #define SUBGHZ_RADIO_DEVICE_PLUGIN_APP_ID "subghz_radio_device"
#define SUBGHZ_RADIO_DEVICE_PLUGIN_API_VERSION 1 #define SUBGHZ_RADIO_DEVICE_PLUGIN_API_VERSION 2
typedef struct SubGhzDeviceRegistry SubGhzDeviceRegistry; typedef struct SubGhzDeviceRegistry SubGhzDeviceRegistry;
typedef struct SubGhzDevice SubGhzDevice; typedef struct SubGhzDevice SubGhzDevice;
typedef struct SubGhzDeviceConf SubGhzDeviceConf;
typedef bool (*SubGhzBegin)(void); typedef bool (*SubGhzBegin)(SubGhzDeviceConf* conf);
typedef void (*SubGhzEnd)(void); typedef void (*SubGhzEnd)(void);
typedef bool (*SubGhzIsConnect)(void); typedef bool (*SubGhzIsConnect)(void);
typedef void (*SubGhzReset)(void); typedef void (*SubGhzReset)(void);
@ -89,3 +90,9 @@ struct SubGhzDevice {
const char* name; const char* name;
const SubGhzDeviceInterconnect* interconnect; const SubGhzDeviceInterconnect* interconnect;
}; };
struct SubGhzDeviceConf {
uint8_t ver;
bool extended_range;
bool power_amp;
};