mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-24 05:23:06 +00:00
commit
f91a73159f
95 changed files with 4030 additions and 1465 deletions
|
@ -12,6 +12,7 @@ struct SubGhzTestCarrier {
|
|||
View* view;
|
||||
FuriTimer* timer;
|
||||
SubGhzTestCarrierCallback callback;
|
||||
// const SubGhzDevice* radio_device;
|
||||
void* context;
|
||||
};
|
||||
|
||||
|
@ -84,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;
|
||||
|
@ -94,6 +96,7 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
|
|||
SubGhzTestCarrierModel * model,
|
||||
{
|
||||
furi_hal_subghz_idle();
|
||||
// subghz_devices_idle(radio_device);
|
||||
|
||||
if(event->key == InputKeyLeft) {
|
||||
if(model->frequency > 0) model->frequency--;
|
||||
|
@ -114,10 +117,18 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
|
|||
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(
|
||||
// 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);
|
||||
|
@ -127,6 +138,15 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
|
|||
subghz_test_carrier->callback(
|
||||
SubGhzTestCarrierEventOnlyRx, subghz_test_carrier->context);
|
||||
}
|
||||
// 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);
|
||||
// }
|
||||
}
|
||||
},
|
||||
true);
|
||||
|
@ -137,12 +157,20 @@ 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_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,
|
||||
|
@ -150,6 +178,8 @@ void subghz_test_carrier_enter(void* context) {
|
|||
model->frequency = subghz_frequencies_433_92_testing; // 433
|
||||
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;
|
||||
|
@ -157,6 +187,7 @@ void subghz_test_carrier_enter(void* context) {
|
|||
true);
|
||||
|
||||
furi_hal_subghz_rx();
|
||||
// subghz_devices_set_rx(radio_device);
|
||||
|
||||
furi_timer_start(subghz_test_carrier->timer, furi_kernel_get_tick_frequency() / 4);
|
||||
}
|
||||
|
@ -169,6 +200,7 @@ void subghz_test_carrier_exit(void* context) {
|
|||
|
||||
// Reinitialize IC to default state
|
||||
furi_hal_subghz_sleep();
|
||||
// subghz_devices_sleep(subghz_test_carrier->radio_device);
|
||||
}
|
||||
|
||||
void subghz_test_carrier_rssi_timer_callback(void* context) {
|
||||
|
@ -181,6 +213,7 @@ void subghz_test_carrier_rssi_timer_callback(void* context) {
|
|||
{
|
||||
if(model->status == SubGhzTestCarrierModelStatusRx) {
|
||||
model->rssi = furi_hal_subghz_get_rssi();
|
||||
// model->rssi = subghz_devices_get_rssi(subghz_test_carrier->radio_device);
|
||||
}
|
||||
},
|
||||
false);
|
||||
|
@ -216,3 +249,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);
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include <lib/subghz/subghz_file_encoder_worker.h>
|
||||
#include <lib/subghz/protocols/protocol_items.h>
|
||||
#include <flipper_format/flipper_format_i.h>
|
||||
#include <lib/subghz/devices/devices.h>
|
||||
#include <lib/subghz/devices/cc1101_configs.h>
|
||||
|
||||
#define TAG "SubGhz TEST"
|
||||
#define KEYSTORE_DIR_NAME EXT_PATH("subghz/assets/keeloq_mfcodes")
|
||||
|
@ -49,12 +51,15 @@ static void subghz_test_init(void) {
|
|||
subghz_environment_set_protocol_registry(
|
||||
environment_handler, (void*)&subghz_protocol_registry);
|
||||
|
||||
subghz_devices_init();
|
||||
|
||||
receiver_handler = subghz_receiver_alloc_init(environment_handler);
|
||||
subghz_receiver_set_filter(receiver_handler, SubGhzProtocolFlag_Decodable);
|
||||
subghz_receiver_set_rx_callback(receiver_handler, subghz_test_rx_callback, NULL);
|
||||
}
|
||||
|
||||
static void subghz_test_deinit(void) {
|
||||
subghz_devices_deinit();
|
||||
subghz_receiver_free(receiver_handler);
|
||||
subghz_environment_free(environment_handler);
|
||||
}
|
||||
|
@ -68,7 +73,7 @@ static bool subghz_decoder_test(const char* path, const char* name_decoder) {
|
|||
|
||||
if(decoder) {
|
||||
file_worker_encoder_handler = subghz_file_encoder_worker_alloc();
|
||||
if(subghz_file_encoder_worker_start(file_worker_encoder_handler, path)) {
|
||||
if(subghz_file_encoder_worker_start(file_worker_encoder_handler, path, NULL)) {
|
||||
// the worker needs a file in order to open and read part of the file
|
||||
furi_delay_ms(100);
|
||||
|
||||
|
@ -108,7 +113,7 @@ static bool subghz_decode_random_test(const char* path) {
|
|||
uint32_t test_start = furi_get_tick();
|
||||
|
||||
file_worker_encoder_handler = subghz_file_encoder_worker_alloc();
|
||||
if(subghz_file_encoder_worker_start(file_worker_encoder_handler, path)) {
|
||||
if(subghz_file_encoder_worker_start(file_worker_encoder_handler, path, NULL)) {
|
||||
// the worker needs a file in order to open and read part of the file
|
||||
furi_delay_ms(100);
|
||||
|
||||
|
@ -318,7 +323,7 @@ bool subghz_hal_async_tx_test_run(SubGhzHalAsyncTxTestType type) {
|
|||
SubGhzHalAsyncTxTest test = {0};
|
||||
test.type = type;
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_ook_650khz_async_regs);
|
||||
furi_hal_subghz_set_frequency_and_path(433920000);
|
||||
|
||||
if(!furi_hal_subghz_start_async_tx(subghz_hal_async_tx_test_yield, &test)) {
|
||||
|
|
6
applications/drivers/application.fam
Normal file
6
applications/drivers/application.fam
Normal file
|
@ -0,0 +1,6 @@
|
|||
# Placeholder
|
||||
App(
|
||||
appid="drivers",
|
||||
name="Drivers device",
|
||||
apptype=FlipperAppType.METAPACKAGE,
|
||||
)
|
8
applications/drivers/subghz/application.fam
Normal file
8
applications/drivers/subghz/application.fam
Normal file
|
@ -0,0 +1,8 @@
|
|||
App(
|
||||
appid="radio_device_cc1101_ext",
|
||||
apptype=FlipperAppType.PLUGIN,
|
||||
targets=["f7"],
|
||||
entry_point="subghz_device_cc1101_ext_ep",
|
||||
requires=["subghz"],
|
||||
fap_libs=["hwdrivers"],
|
||||
)
|
782
applications/drivers/subghz/cc1101_ext/cc1101_ext.c
Normal file
782
applications/drivers/subghz/cc1101_ext/cc1101_ext.c
Normal file
|
@ -0,0 +1,782 @@
|
|||
#include "cc1101_ext.h"
|
||||
#include <lib/subghz/devices/cc1101_configs.h>
|
||||
|
||||
#include <furi_hal_version.h>
|
||||
#include <furi_hal_rtc.h>
|
||||
#include <furi_hal_spi.h>
|
||||
#include <furi_hal_interrupt.h>
|
||||
#include <furi_hal_resources.h>
|
||||
#include <furi_hal_bus.h>
|
||||
|
||||
#include <stm32wbxx_ll_dma.h>
|
||||
#include <furi_hal_cortex.h>
|
||||
|
||||
#include <furi.h>
|
||||
#include <cc1101.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define TAG "SubGhz_Device_CC1101_Ext"
|
||||
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO &gpio_ext_pb2
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_DANGEROUS_RANGE false
|
||||
|
||||
/* DMA Channels definition */
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_DMA DMA2
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_CHANNEL LL_DMA_CHANNEL_3
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_CHANNEL LL_DMA_CHANNEL_4
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_CHANNEL LL_DMA_CHANNEL_5
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_IRQ FuriHalInterruptIdDma2Ch3
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF \
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA, SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_CHANNEL
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF \
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA, SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_CHANNEL
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF \
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA, SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_CHANNEL
|
||||
|
||||
/** Low level buffer dimensions and guard times */
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_FULL (256)
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_HALF \
|
||||
(SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_FULL / 2)
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_GUARD_TIME 999
|
||||
|
||||
/** SubGhz state */
|
||||
typedef enum {
|
||||
SubGhzDeviceCC1101ExtStateInit, /**< Init pending */
|
||||
SubGhzDeviceCC1101ExtStateIdle, /**< Idle, energy save mode */
|
||||
SubGhzDeviceCC1101ExtStateAsyncRx, /**< Async RX started */
|
||||
SubGhzDeviceCC1101ExtStateAsyncTx, /**< Async TX started, DMA and timer is on */
|
||||
SubGhzDeviceCC1101ExtStateAsyncTxEnd, /**< Async TX complete, cleanup needed */
|
||||
} SubGhzDeviceCC1101ExtState;
|
||||
|
||||
/** SubGhz regulation, receive transmission on the current frequency for the
|
||||
* region */
|
||||
typedef enum {
|
||||
SubGhzDeviceCC1101ExtRegulationOnlyRx, /**only Rx*/
|
||||
SubGhzDeviceCC1101ExtRegulationTxRx, /**TxRx*/
|
||||
} SubGhzDeviceCC1101ExtRegulation;
|
||||
|
||||
typedef struct {
|
||||
uint32_t* buffer;
|
||||
LevelDuration carry_ld;
|
||||
SubGhzDeviceCC1101ExtCallback callback;
|
||||
void* callback_context;
|
||||
uint32_t gpio_tx_buff[2];
|
||||
uint32_t debug_gpio_buff[2];
|
||||
} SubGhzDeviceCC1101ExtAsyncTx;
|
||||
|
||||
typedef struct {
|
||||
uint32_t capture_delta_duration;
|
||||
SubGhzDeviceCC1101ExtCaptureCallback capture_callback;
|
||||
void* capture_callback_context;
|
||||
} SubGhzDeviceCC1101ExtAsyncRx;
|
||||
|
||||
typedef struct {
|
||||
volatile SubGhzDeviceCC1101ExtState state;
|
||||
volatile SubGhzDeviceCC1101ExtRegulation regulation;
|
||||
const GpioPin* async_mirror_pin;
|
||||
FuriHalSpiBusHandle* spi_bus_handle;
|
||||
const GpioPin* g0_pin;
|
||||
SubGhzDeviceCC1101ExtAsyncTx async_tx;
|
||||
SubGhzDeviceCC1101ExtAsyncRx async_rx;
|
||||
} SubGhzDeviceCC1101Ext;
|
||||
|
||||
static SubGhzDeviceCC1101Ext* subghz_device_cc1101_ext = NULL;
|
||||
|
||||
static bool subghz_device_cc1101_ext_check_init() {
|
||||
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateInit);
|
||||
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateIdle;
|
||||
|
||||
bool ret = false;
|
||||
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
FuriHalCortexTimer timer = furi_hal_cortex_timer_get(100 * 1000);
|
||||
do {
|
||||
// Reset
|
||||
furi_hal_gpio_init(
|
||||
subghz_device_cc1101_ext->g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
cc1101_reset(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_write_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHighImpedance);
|
||||
|
||||
// Prepare GD0 for power on self test
|
||||
furi_hal_gpio_init(
|
||||
subghz_device_cc1101_ext->g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
// GD0 low
|
||||
cc1101_write_reg(subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHW);
|
||||
while(furi_hal_gpio_read(subghz_device_cc1101_ext->g0_pin) != false) {
|
||||
if(furi_hal_cortex_timer_is_expired(timer)) {
|
||||
//timeout
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(furi_hal_cortex_timer_is_expired(timer)) {
|
||||
//timeout
|
||||
break;
|
||||
}
|
||||
|
||||
// GD0 high
|
||||
cc1101_write_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle,
|
||||
CC1101_IOCFG0,
|
||||
CC1101IocfgHW | CC1101_IOCFG_INV);
|
||||
while(furi_hal_gpio_read(subghz_device_cc1101_ext->g0_pin) != true) {
|
||||
if(furi_hal_cortex_timer_is_expired(timer)) {
|
||||
//timeout
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(furi_hal_cortex_timer_is_expired(timer)) {
|
||||
//timeout
|
||||
break;
|
||||
}
|
||||
|
||||
// Reset GD0 to floating state
|
||||
cc1101_write_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHighImpedance);
|
||||
furi_hal_gpio_init(
|
||||
subghz_device_cc1101_ext->g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
// RF switches
|
||||
furi_hal_gpio_init(&gpio_rf_sw_0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
cc1101_write_reg(subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG2, CC1101IocfgHW);
|
||||
|
||||
// Go to sleep
|
||||
cc1101_shutdown(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
ret = true;
|
||||
} while(false);
|
||||
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
|
||||
if(ret) {
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Init failed");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool subghz_device_cc1101_ext_alloc() {
|
||||
furi_assert(subghz_device_cc1101_ext == NULL);
|
||||
subghz_device_cc1101_ext = malloc(sizeof(SubGhzDeviceCC1101Ext));
|
||||
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateInit;
|
||||
subghz_device_cc1101_ext->regulation = SubGhzDeviceCC1101ExtRegulationTxRx;
|
||||
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->g0_pin = SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO;
|
||||
|
||||
subghz_device_cc1101_ext->async_rx.capture_delta_duration = 0;
|
||||
|
||||
furi_hal_spi_bus_handle_init(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
return subghz_device_cc1101_ext_check_init();
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_free() {
|
||||
furi_assert(subghz_device_cc1101_ext != NULL);
|
||||
furi_hal_spi_bus_handle_deinit(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
free(subghz_device_cc1101_ext);
|
||||
subghz_device_cc1101_ext = NULL;
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_set_async_mirror_pin(const GpioPin* pin) {
|
||||
subghz_device_cc1101_ext->async_mirror_pin = pin;
|
||||
}
|
||||
|
||||
const GpioPin* subghz_device_cc1101_ext_get_data_gpio() {
|
||||
return subghz_device_cc1101_ext->g0_pin;
|
||||
}
|
||||
|
||||
bool subghz_device_cc1101_ext_is_connect() {
|
||||
bool ret = false;
|
||||
|
||||
if(subghz_device_cc1101_ext == NULL) { // not initialized
|
||||
ret = subghz_device_cc1101_ext_alloc();
|
||||
subghz_device_cc1101_ext_free();
|
||||
} else { // initialized
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
uint8_t partnumber = cc1101_get_partnumber(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
ret = (partnumber != 0) && (partnumber != 0xFF);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_sleep() {
|
||||
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateIdle);
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
|
||||
cc1101_switch_to_idle(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
|
||||
cc1101_write_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHighImpedance);
|
||||
furi_hal_gpio_init(subghz_device_cc1101_ext->g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
cc1101_shutdown(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_dump_state() {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
printf(
|
||||
"[subghz_device_cc1101_ext] cc1101 chip %d, version %d\r\n",
|
||||
cc1101_get_partnumber(subghz_device_cc1101_ext->spi_bus_handle),
|
||||
cc1101_get_version(subghz_device_cc1101_ext->spi_bus_handle));
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_load_custom_preset(const uint8_t* preset_data) {
|
||||
//load config
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_reset(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
uint32_t i = 0;
|
||||
uint8_t pa[8] = {0};
|
||||
while(preset_data[i]) {
|
||||
cc1101_write_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle, preset_data[i], preset_data[i + 1]);
|
||||
i += 2;
|
||||
}
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
|
||||
//load pa table
|
||||
memcpy(&pa[0], &preset_data[i + 2], 8);
|
||||
subghz_device_cc1101_ext_load_patable(pa);
|
||||
|
||||
//show debug
|
||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
||||
i = 0;
|
||||
FURI_LOG_D(TAG, "Loading custom preset");
|
||||
while(preset_data[i]) {
|
||||
FURI_LOG_D(TAG, "Reg[%lu]: %02X=%02X", i, preset_data[i], preset_data[i + 1]);
|
||||
i += 2;
|
||||
}
|
||||
for(uint8_t y = i; y < i + 10; y++) {
|
||||
FURI_LOG_D(TAG, "PA[%u]: %02X", y, preset_data[y]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_load_registers(const uint8_t* data) {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_reset(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
uint32_t i = 0;
|
||||
while(data[i]) {
|
||||
cc1101_write_reg(subghz_device_cc1101_ext->spi_bus_handle, data[i], data[i + 1]);
|
||||
i += 2;
|
||||
}
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_load_patable(const uint8_t data[8]) {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_set_pa_table(subghz_device_cc1101_ext->spi_bus_handle, data);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_write_packet(const uint8_t* data, uint8_t size) {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_flush_tx(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_write_reg(subghz_device_cc1101_ext->spi_bus_handle, CC1101_FIFO, size);
|
||||
cc1101_write_fifo(subghz_device_cc1101_ext->spi_bus_handle, data, size);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_flush_rx() {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_flush_rx(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_flush_tx() {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_flush_tx(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
bool subghz_device_cc1101_ext_rx_pipe_not_empty() {
|
||||
CC1101RxBytes status[1];
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_read_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle,
|
||||
(CC1101_STATUS_RXBYTES) | CC1101_BURST,
|
||||
(uint8_t*)status);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
// TODO: you can add a buffer overflow flag if needed
|
||||
if(status->NUM_RXBYTES > 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool subghz_device_cc1101_ext_is_rx_data_crc_valid() {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
uint8_t data[1];
|
||||
cc1101_read_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle, CC1101_STATUS_LQI | CC1101_BURST, data);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
if(((data[0] >> 7) & 0x01)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_read_packet(uint8_t* data, uint8_t* size) {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_read_fifo(subghz_device_cc1101_ext->spi_bus_handle, data, size);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_shutdown() {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
// Reset and shutdown
|
||||
cc1101_shutdown(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_reset() {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
furi_hal_gpio_init(subghz_device_cc1101_ext->g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
cc1101_switch_to_idle(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_reset(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_write_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHighImpedance);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_idle() {
|
||||
furi_hal_spi_acquire(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);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_rx() {
|
||||
furi_hal_spi_acquire(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);
|
||||
}
|
||||
|
||||
bool subghz_device_cc1101_ext_tx() {
|
||||
if(subghz_device_cc1101_ext->regulation != SubGhzDeviceCC1101ExtRegulationTxRx) return false;
|
||||
furi_hal_spi_acquire(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);
|
||||
return true;
|
||||
}
|
||||
|
||||
float subghz_device_cc1101_ext_get_rssi() {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
int32_t rssi_dec = cc1101_get_rssi(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
|
||||
float rssi = rssi_dec;
|
||||
if(rssi_dec >= 128) {
|
||||
rssi = ((rssi - 256.0f) / 2.0f) - 74.0f;
|
||||
} else {
|
||||
rssi = (rssi / 2.0f) - 74.0f;
|
||||
}
|
||||
|
||||
return rssi;
|
||||
}
|
||||
|
||||
uint8_t subghz_device_cc1101_ext_get_lqi() {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
uint8_t data[1];
|
||||
cc1101_read_reg(
|
||||
subghz_device_cc1101_ext->spi_bus_handle, CC1101_STATUS_LQI | CC1101_BURST, data);
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
return data[0] & 0x7F;
|
||||
}
|
||||
|
||||
bool subghz_device_cc1101_ext_is_frequency_valid(uint32_t value) {
|
||||
if(!(value >= 281000000 && value <= 361000000) &&
|
||||
!(value >= 378000000 && value <= 481000000) &&
|
||||
!(value >= 749000000 && value <= 962000000)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool subghz_device_cc1101_ext_is_tx_allowed(uint32_t value) {
|
||||
if(!(SUBGHZ_DEVICE_CC1101_EXT_DANGEROUS_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_DANGEROUS_RANGE) &&
|
||||
!subghz_device_cc1101_ext_is_frequency_valid(value)) {
|
||||
FURI_LOG_I(TAG, "Frequency blocked - outside dangerous range");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
uint32_t real_frequency =
|
||||
cc1101_set_frequency(subghz_device_cc1101_ext->spi_bus_handle, value);
|
||||
cc1101_calibrate(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
|
||||
while(true) {
|
||||
CC1101Status status = cc1101_get_status(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
if(status.STATE == CC1101StateIDLE) break;
|
||||
}
|
||||
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
return real_frequency;
|
||||
}
|
||||
|
||||
static bool subghz_device_cc1101_ext_start_debug() {
|
||||
bool ret = false;
|
||||
if(subghz_device_cc1101_ext->async_mirror_pin != NULL) {
|
||||
furi_hal_gpio_init(
|
||||
subghz_device_cc1101_ext->async_mirror_pin,
|
||||
GpioModeOutputPushPull,
|
||||
GpioPullNo,
|
||||
GpioSpeedVeryHigh);
|
||||
ret = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool subghz_device_cc1101_ext_stop_debug() {
|
||||
bool ret = false;
|
||||
if(subghz_device_cc1101_ext->async_mirror_pin != NULL) {
|
||||
furi_hal_gpio_init(
|
||||
subghz_device_cc1101_ext->async_mirror_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
ret = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void subghz_device_cc1101_ext_capture_ISR() {
|
||||
if(!furi_hal_gpio_read(subghz_device_cc1101_ext->g0_pin)) {
|
||||
if(subghz_device_cc1101_ext->async_rx.capture_callback) {
|
||||
if(subghz_device_cc1101_ext->async_mirror_pin != NULL)
|
||||
furi_hal_gpio_write(subghz_device_cc1101_ext->async_mirror_pin, false);
|
||||
|
||||
subghz_device_cc1101_ext->async_rx.capture_callback(
|
||||
true,
|
||||
LL_TIM_GetCounter(TIM17),
|
||||
(void*)subghz_device_cc1101_ext->async_rx.capture_callback_context);
|
||||
}
|
||||
} else {
|
||||
if(subghz_device_cc1101_ext->async_rx.capture_callback) {
|
||||
if(subghz_device_cc1101_ext->async_mirror_pin != NULL)
|
||||
furi_hal_gpio_write(subghz_device_cc1101_ext->async_mirror_pin, true);
|
||||
|
||||
subghz_device_cc1101_ext->async_rx.capture_callback(
|
||||
false,
|
||||
LL_TIM_GetCounter(TIM17),
|
||||
(void*)subghz_device_cc1101_ext->async_rx.capture_callback_context);
|
||||
}
|
||||
}
|
||||
LL_TIM_SetCounter(TIM17, 6);
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_start_async_rx(
|
||||
SubGhzDeviceCC1101ExtCaptureCallback callback,
|
||||
void* context) {
|
||||
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateIdle);
|
||||
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateAsyncRx;
|
||||
|
||||
subghz_device_cc1101_ext->async_rx.capture_callback = callback;
|
||||
subghz_device_cc1101_ext->async_rx.capture_callback_context = context;
|
||||
|
||||
furi_hal_bus_enable(FuriHalBusTIM17);
|
||||
|
||||
// Configure TIM
|
||||
LL_TIM_SetPrescaler(TIM17, 64 - 1);
|
||||
LL_TIM_SetCounterMode(TIM17, LL_TIM_COUNTERMODE_UP);
|
||||
LL_TIM_SetAutoReload(TIM17, 0xFFFF);
|
||||
LL_TIM_SetClockDivision(TIM17, LL_TIM_CLOCKDIVISION_DIV1);
|
||||
|
||||
// Timer: advanced
|
||||
LL_TIM_SetClockSource(TIM17, LL_TIM_CLOCKSOURCE_INTERNAL);
|
||||
LL_TIM_DisableARRPreload(TIM17);
|
||||
LL_TIM_DisableDMAReq_TRIG(TIM17);
|
||||
LL_TIM_DisableIT_TRIG(TIM17);
|
||||
|
||||
furi_hal_gpio_init(
|
||||
subghz_device_cc1101_ext->g0_pin, GpioModeInterruptRiseFall, GpioPullUp, GpioSpeedVeryHigh);
|
||||
furi_hal_gpio_remove_int_callback(subghz_device_cc1101_ext->g0_pin);
|
||||
furi_hal_gpio_add_int_callback(
|
||||
subghz_device_cc1101_ext->g0_pin,
|
||||
subghz_device_cc1101_ext_capture_ISR,
|
||||
subghz_device_cc1101_ext->async_rx.capture_callback);
|
||||
|
||||
// Start timer
|
||||
LL_TIM_SetCounter(TIM17, 0);
|
||||
LL_TIM_EnableCounter(TIM17);
|
||||
|
||||
// Start debug
|
||||
subghz_device_cc1101_ext_start_debug();
|
||||
|
||||
// Switch to RX
|
||||
subghz_device_cc1101_ext_rx();
|
||||
|
||||
//Clear the variable after the end of the session
|
||||
subghz_device_cc1101_ext->async_rx.capture_delta_duration = 0;
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_stop_async_rx() {
|
||||
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncRx);
|
||||
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateIdle;
|
||||
|
||||
// Shutdown radio
|
||||
subghz_device_cc1101_ext_idle();
|
||||
|
||||
FURI_CRITICAL_ENTER();
|
||||
furi_hal_bus_disable(FuriHalBusTIM17);
|
||||
|
||||
// Stop debug
|
||||
subghz_device_cc1101_ext_stop_debug();
|
||||
|
||||
FURI_CRITICAL_EXIT();
|
||||
furi_hal_gpio_remove_int_callback(subghz_device_cc1101_ext->g0_pin);
|
||||
furi_hal_gpio_init(subghz_device_cc1101_ext->g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
}
|
||||
|
||||
static void subghz_device_cc1101_ext_async_tx_refill(uint32_t* buffer, size_t samples) {
|
||||
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTx);
|
||||
while(samples > 0) {
|
||||
bool is_odd = samples % 2;
|
||||
LevelDuration ld;
|
||||
if(level_duration_is_reset(subghz_device_cc1101_ext->async_tx.carry_ld)) {
|
||||
ld = subghz_device_cc1101_ext->async_tx.callback(
|
||||
subghz_device_cc1101_ext->async_tx.callback_context);
|
||||
} else {
|
||||
ld = subghz_device_cc1101_ext->async_tx.carry_ld;
|
||||
subghz_device_cc1101_ext->async_tx.carry_ld = level_duration_reset();
|
||||
}
|
||||
|
||||
if(level_duration_is_wait(ld)) {
|
||||
*buffer = SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_GUARD_TIME;
|
||||
buffer++;
|
||||
samples--;
|
||||
} else if(level_duration_is_reset(ld)) {
|
||||
*buffer = 0;
|
||||
buffer++;
|
||||
samples--;
|
||||
LL_DMA_DisableIT_HT(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF);
|
||||
LL_DMA_DisableIT_TC(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF);
|
||||
LL_TIM_EnableIT_UPDATE(TIM17);
|
||||
break;
|
||||
} else {
|
||||
bool level = level_duration_get_level(ld);
|
||||
|
||||
// Inject guard time if level is incorrect
|
||||
if(is_odd != level) {
|
||||
*buffer = SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_GUARD_TIME;
|
||||
buffer++;
|
||||
samples--;
|
||||
|
||||
// Special case: prevent buffer overflow if sample is last
|
||||
if(samples == 0) {
|
||||
subghz_device_cc1101_ext->async_tx.carry_ld = ld;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t duration = level_duration_get_duration(ld);
|
||||
furi_assert(duration > 0);
|
||||
*buffer = duration - 1;
|
||||
buffer++;
|
||||
samples--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void subghz_device_cc1101_ext_async_tx_dma_isr() {
|
||||
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTx);
|
||||
|
||||
#if SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_CHANNEL == LL_DMA_CHANNEL_3
|
||||
if(LL_DMA_IsActiveFlag_HT3(SUBGHZ_DEVICE_CC1101_EXT_DMA)) {
|
||||
LL_DMA_ClearFlag_HT3(SUBGHZ_DEVICE_CC1101_EXT_DMA);
|
||||
subghz_device_cc1101_ext_async_tx_refill(
|
||||
subghz_device_cc1101_ext->async_tx.buffer,
|
||||
SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_HALF);
|
||||
}
|
||||
if(LL_DMA_IsActiveFlag_TC3(SUBGHZ_DEVICE_CC1101_EXT_DMA)) {
|
||||
LL_DMA_ClearFlag_TC3(SUBGHZ_DEVICE_CC1101_EXT_DMA);
|
||||
subghz_device_cc1101_ext_async_tx_refill(
|
||||
subghz_device_cc1101_ext->async_tx.buffer +
|
||||
SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_HALF,
|
||||
SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_HALF);
|
||||
}
|
||||
#else
|
||||
#error Update this code. Would you kindly?
|
||||
#endif
|
||||
}
|
||||
|
||||
static void subghz_device_cc1101_ext_async_tx_timer_isr() {
|
||||
if(LL_TIM_IsActiveFlag_UPDATE(TIM17)) {
|
||||
if(LL_TIM_GetAutoReload(TIM17) == 0) {
|
||||
LL_DMA_DisableChannel(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF);
|
||||
furi_hal_gpio_write(subghz_device_cc1101_ext->g0_pin, false);
|
||||
if(subghz_device_cc1101_ext->async_mirror_pin != NULL)
|
||||
furi_hal_gpio_write(subghz_device_cc1101_ext->async_mirror_pin, false);
|
||||
LL_TIM_DisableCounter(TIM17);
|
||||
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateAsyncTxEnd;
|
||||
}
|
||||
LL_TIM_ClearFlag_UPDATE(TIM17);
|
||||
}
|
||||
}
|
||||
|
||||
bool subghz_device_cc1101_ext_start_async_tx(SubGhzDeviceCC1101ExtCallback callback, void* context) {
|
||||
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateIdle);
|
||||
furi_assert(callback);
|
||||
|
||||
//If transmission is prohibited by regional settings
|
||||
if(subghz_device_cc1101_ext->regulation != SubGhzDeviceCC1101ExtRegulationTxRx) return false;
|
||||
|
||||
subghz_device_cc1101_ext->async_tx.callback = callback;
|
||||
subghz_device_cc1101_ext->async_tx.callback_context = context;
|
||||
|
||||
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateAsyncTx;
|
||||
|
||||
subghz_device_cc1101_ext->async_tx.buffer =
|
||||
malloc(SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_FULL * sizeof(uint32_t));
|
||||
|
||||
//Signal generation with mem-to-mem DMA
|
||||
furi_hal_gpio_write(subghz_device_cc1101_ext->g0_pin, false);
|
||||
furi_hal_gpio_init(
|
||||
subghz_device_cc1101_ext->g0_pin, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh);
|
||||
|
||||
// Configure DMA update timer
|
||||
LL_DMA_SetMemoryAddress(
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF, (uint32_t)subghz_device_cc1101_ext->async_tx.buffer);
|
||||
LL_DMA_SetPeriphAddress(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF, (uint32_t) & (TIM17->ARR));
|
||||
LL_DMA_ConfigTransfer(
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF,
|
||||
LL_DMA_DIRECTION_MEMORY_TO_PERIPH | LL_DMA_MODE_CIRCULAR | LL_DMA_PERIPH_NOINCREMENT |
|
||||
LL_DMA_MEMORY_INCREMENT | LL_DMA_PDATAALIGN_WORD | LL_DMA_MDATAALIGN_WORD |
|
||||
LL_DMA_MODE_NORMAL);
|
||||
LL_DMA_SetDataLength(
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF, SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_FULL);
|
||||
LL_DMA_SetPeriphRequest(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF, LL_DMAMUX_REQ_TIM17_UP);
|
||||
|
||||
LL_DMA_EnableIT_TC(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF);
|
||||
LL_DMA_EnableIT_HT(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF);
|
||||
LL_DMA_EnableChannel(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF);
|
||||
|
||||
furi_hal_interrupt_set_isr(
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_IRQ, subghz_device_cc1101_ext_async_tx_dma_isr, NULL);
|
||||
|
||||
furi_hal_bus_enable(FuriHalBusTIM17);
|
||||
|
||||
// Configure TIM
|
||||
LL_TIM_SetPrescaler(TIM17, 64 - 1);
|
||||
LL_TIM_SetCounterMode(TIM17, LL_TIM_COUNTERMODE_UP);
|
||||
LL_TIM_SetAutoReload(TIM17, 0xFFFF);
|
||||
LL_TIM_SetClockDivision(TIM17, LL_TIM_CLOCKDIVISION_DIV1);
|
||||
LL_TIM_SetClockSource(TIM17, LL_TIM_CLOCKSOURCE_INTERNAL);
|
||||
LL_TIM_DisableARRPreload(TIM17);
|
||||
|
||||
furi_hal_interrupt_set_isr(
|
||||
FuriHalInterruptIdTim1TrgComTim17, subghz_device_cc1101_ext_async_tx_timer_isr, NULL);
|
||||
|
||||
subghz_device_cc1101_ext_async_tx_refill(
|
||||
subghz_device_cc1101_ext->async_tx.buffer, SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_FULL);
|
||||
|
||||
// Configure tx gpio dma
|
||||
const GpioPin* gpio = subghz_device_cc1101_ext->g0_pin;
|
||||
|
||||
subghz_device_cc1101_ext->async_tx.gpio_tx_buff[0] = (uint32_t)gpio->pin << GPIO_NUMBER;
|
||||
subghz_device_cc1101_ext->async_tx.gpio_tx_buff[1] = gpio->pin;
|
||||
|
||||
LL_DMA_SetMemoryAddress(
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF,
|
||||
(uint32_t)subghz_device_cc1101_ext->async_tx.gpio_tx_buff);
|
||||
LL_DMA_SetPeriphAddress(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF, (uint32_t) & (gpio->port->BSRR));
|
||||
LL_DMA_ConfigTransfer(
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF,
|
||||
LL_DMA_DIRECTION_MEMORY_TO_PERIPH | LL_DMA_MODE_CIRCULAR | LL_DMA_PERIPH_NOINCREMENT |
|
||||
LL_DMA_MEMORY_INCREMENT | LL_DMA_PDATAALIGN_WORD | LL_DMA_MDATAALIGN_WORD |
|
||||
LL_DMA_PRIORITY_HIGH);
|
||||
LL_DMA_SetDataLength(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF, 2);
|
||||
LL_DMA_SetPeriphRequest(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF, LL_DMAMUX_REQ_TIM17_UP);
|
||||
LL_DMA_EnableChannel(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF);
|
||||
|
||||
// Start debug
|
||||
if(subghz_device_cc1101_ext_start_debug()) {
|
||||
gpio = subghz_device_cc1101_ext->async_mirror_pin;
|
||||
subghz_device_cc1101_ext->async_tx.debug_gpio_buff[0] = (uint32_t)gpio->pin << GPIO_NUMBER;
|
||||
subghz_device_cc1101_ext->async_tx.debug_gpio_buff[1] = gpio->pin;
|
||||
|
||||
LL_DMA_SetMemoryAddress(
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF,
|
||||
(uint32_t)subghz_device_cc1101_ext->async_tx.debug_gpio_buff);
|
||||
LL_DMA_SetPeriphAddress(
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF, (uint32_t) & (gpio->port->BSRR));
|
||||
LL_DMA_ConfigTransfer(
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF,
|
||||
LL_DMA_DIRECTION_MEMORY_TO_PERIPH | LL_DMA_MODE_CIRCULAR | LL_DMA_PERIPH_NOINCREMENT |
|
||||
LL_DMA_MEMORY_INCREMENT | LL_DMA_PDATAALIGN_WORD | LL_DMA_MDATAALIGN_WORD |
|
||||
LL_DMA_PRIORITY_LOW);
|
||||
LL_DMA_SetDataLength(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF, 2);
|
||||
LL_DMA_SetPeriphRequest(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF, LL_DMAMUX_REQ_TIM17_UP);
|
||||
LL_DMA_EnableChannel(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF);
|
||||
}
|
||||
|
||||
// Start counter
|
||||
LL_TIM_EnableDMAReq_UPDATE(TIM17);
|
||||
LL_TIM_GenerateEvent_UPDATE(TIM17);
|
||||
|
||||
subghz_device_cc1101_ext_tx();
|
||||
|
||||
LL_TIM_SetCounter(TIM17, 0);
|
||||
LL_TIM_EnableCounter(TIM17);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool subghz_device_cc1101_ext_is_async_tx_complete() {
|
||||
return subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTxEnd;
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_stop_async_tx() {
|
||||
furi_assert(
|
||||
subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTx ||
|
||||
subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTxEnd);
|
||||
|
||||
// Shutdown radio
|
||||
subghz_device_cc1101_ext_idle();
|
||||
|
||||
// Deinitialize Timer
|
||||
FURI_CRITICAL_ENTER();
|
||||
furi_hal_bus_disable(FuriHalBusTIM17);
|
||||
furi_hal_interrupt_set_isr(FuriHalInterruptIdTim1TrgComTim17, NULL, NULL);
|
||||
|
||||
// Deinitialize DMA
|
||||
LL_DMA_DeInit(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF);
|
||||
LL_DMA_DisableChannel(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF);
|
||||
furi_hal_interrupt_set_isr(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_IRQ, NULL, NULL);
|
||||
|
||||
// Deinitialize GPIO
|
||||
furi_hal_gpio_write(subghz_device_cc1101_ext->g0_pin, false);
|
||||
furi_hal_gpio_init(subghz_device_cc1101_ext->g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
// Stop debug
|
||||
if(subghz_device_cc1101_ext_stop_debug()) {
|
||||
LL_DMA_DisableChannel(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF);
|
||||
}
|
||||
|
||||
FURI_CRITICAL_EXIT();
|
||||
|
||||
free(subghz_device_cc1101_ext->async_tx.buffer);
|
||||
|
||||
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateIdle;
|
||||
}
|
206
applications/drivers/subghz/cc1101_ext/cc1101_ext.h
Normal file
206
applications/drivers/subghz/cc1101_ext/cc1101_ext.h
Normal file
|
@ -0,0 +1,206 @@
|
|||
/**
|
||||
* @file furi_hal_subghz.h
|
||||
* SubGhz HAL API
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <lib/subghz/devices/preset.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <toolbox/level_duration.h>
|
||||
#include <furi_hal_gpio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Mirror RX/TX async modulation signal to specified pin
|
||||
*
|
||||
* @warning Configures pin to output mode. Make sure it is not connected
|
||||
* directly to power or ground.
|
||||
*
|
||||
* @param[in] pin pointer to the gpio pin structure or NULL to disable
|
||||
*/
|
||||
void subghz_device_cc1101_ext_set_async_mirror_pin(const GpioPin* pin);
|
||||
|
||||
/** Get data GPIO
|
||||
*
|
||||
* @return pointer to the gpio pin structure
|
||||
*/
|
||||
const GpioPin* subghz_device_cc1101_ext_get_data_gpio();
|
||||
|
||||
/** Initialize device
|
||||
*
|
||||
* @return true if success
|
||||
*/
|
||||
bool subghz_device_cc1101_ext_alloc();
|
||||
|
||||
/** Deinitialize device
|
||||
*/
|
||||
void subghz_device_cc1101_ext_free();
|
||||
|
||||
/** Check and switch to power save mode Used by internal API-HAL
|
||||
* initialization routine Can be used to reinitialize device to safe state and
|
||||
* send it to sleep
|
||||
*/
|
||||
bool subghz_device_cc1101_ext_is_connect();
|
||||
|
||||
/** Send device to sleep mode
|
||||
*/
|
||||
void subghz_device_cc1101_ext_sleep();
|
||||
|
||||
/** Dump info to stdout
|
||||
*/
|
||||
void subghz_device_cc1101_ext_dump_state();
|
||||
|
||||
/** Load custom registers from preset
|
||||
*
|
||||
* @param preset_data registers to load
|
||||
*/
|
||||
void subghz_device_cc1101_ext_load_custom_preset(const uint8_t* preset_data);
|
||||
|
||||
/** Load registers
|
||||
*
|
||||
* @param data Registers data
|
||||
*/
|
||||
void subghz_device_cc1101_ext_load_registers(const uint8_t* data);
|
||||
|
||||
/** Load PATABLE
|
||||
*
|
||||
* @param data 8 uint8_t values
|
||||
*/
|
||||
void subghz_device_cc1101_ext_load_patable(const uint8_t data[8]);
|
||||
|
||||
/** Write packet to FIFO
|
||||
*
|
||||
* @param data bytes array
|
||||
* @param size size
|
||||
*/
|
||||
void subghz_device_cc1101_ext_write_packet(const uint8_t* data, uint8_t size);
|
||||
|
||||
/** Check if receive pipe is not empty
|
||||
*
|
||||
* @return true if not empty
|
||||
*/
|
||||
bool subghz_device_cc1101_ext_rx_pipe_not_empty();
|
||||
|
||||
/** Check if received data crc is valid
|
||||
*
|
||||
* @return true if valid
|
||||
*/
|
||||
bool subghz_device_cc1101_ext_is_rx_data_crc_valid();
|
||||
|
||||
/** Read packet from FIFO
|
||||
*
|
||||
* @param data pointer
|
||||
* @param size size
|
||||
*/
|
||||
void subghz_device_cc1101_ext_read_packet(uint8_t* data, uint8_t* size);
|
||||
|
||||
/** Flush rx FIFO buffer
|
||||
*/
|
||||
void subghz_device_cc1101_ext_flush_rx();
|
||||
|
||||
/** Flush tx FIFO buffer
|
||||
*/
|
||||
void subghz_device_cc1101_ext_flush_tx();
|
||||
|
||||
/** Shutdown Issue SPWD command
|
||||
* @warning registers content will be lost
|
||||
*/
|
||||
void subghz_device_cc1101_ext_shutdown();
|
||||
|
||||
/** Reset Issue reset command
|
||||
* @warning registers content will be lost
|
||||
*/
|
||||
void subghz_device_cc1101_ext_reset();
|
||||
|
||||
/** Switch to Idle
|
||||
*/
|
||||
void subghz_device_cc1101_ext_idle();
|
||||
|
||||
/** Switch to Receive
|
||||
*/
|
||||
void subghz_device_cc1101_ext_rx();
|
||||
|
||||
/** Switch to Transmit
|
||||
*
|
||||
* @return true if the transfer is allowed by belonging to the region
|
||||
*/
|
||||
bool subghz_device_cc1101_ext_tx();
|
||||
|
||||
/** Get RSSI value in dBm
|
||||
*
|
||||
* @return RSSI value
|
||||
*/
|
||||
float subghz_device_cc1101_ext_get_rssi();
|
||||
|
||||
/** Get LQI
|
||||
*
|
||||
* @return LQI value
|
||||
*/
|
||||
uint8_t subghz_device_cc1101_ext_get_lqi();
|
||||
|
||||
/** Check if frequency is in valid range
|
||||
*
|
||||
* @param value frequency in Hz
|
||||
*
|
||||
* @return true if frequency is valid, otherwise false
|
||||
*/
|
||||
bool subghz_device_cc1101_ext_is_frequency_valid(uint32_t value);
|
||||
|
||||
/** Set frequency
|
||||
*
|
||||
* @param value frequency in Hz
|
||||
*
|
||||
* @return real frequency in Hz
|
||||
*/
|
||||
uint32_t subghz_device_cc1101_ext_set_frequency(uint32_t value);
|
||||
|
||||
/* High Level API */
|
||||
|
||||
/** Signal Timings Capture callback */
|
||||
typedef void (*SubGhzDeviceCC1101ExtCaptureCallback)(bool level, uint32_t duration, void* context);
|
||||
|
||||
/** Enable signal timings capture Initializes GPIO and TIM2 for timings capture
|
||||
*
|
||||
* @param callback SubGhzDeviceCC1101ExtCaptureCallback
|
||||
* @param context callback context
|
||||
*/
|
||||
void subghz_device_cc1101_ext_start_async_rx(
|
||||
SubGhzDeviceCC1101ExtCaptureCallback callback,
|
||||
void* context);
|
||||
|
||||
/** Disable signal timings capture Resets GPIO and TIM2
|
||||
*/
|
||||
void subghz_device_cc1101_ext_stop_async_rx();
|
||||
|
||||
/** Async TX callback type
|
||||
* @param context callback context
|
||||
* @return LevelDuration
|
||||
*/
|
||||
typedef LevelDuration (*SubGhzDeviceCC1101ExtCallback)(void* context);
|
||||
|
||||
/** Start async TX Initializes GPIO, TIM2 and DMA1 for signal output
|
||||
*
|
||||
* @param callback SubGhzDeviceCC1101ExtCallback
|
||||
* @param context callback context
|
||||
*
|
||||
* @return true if the transfer is allowed by belonging to the region
|
||||
*/
|
||||
bool subghz_device_cc1101_ext_start_async_tx(SubGhzDeviceCC1101ExtCallback callback, void* context);
|
||||
|
||||
/** Wait for async transmission to complete
|
||||
*
|
||||
* @return true if TX complete
|
||||
*/
|
||||
bool subghz_device_cc1101_ext_is_async_tx_complete();
|
||||
|
||||
/** Stop async transmission and cleanup resources Resets GPIO, TIM2, and DMA1
|
||||
*/
|
||||
void subghz_device_cc1101_ext_stop_async_tx();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
110
applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.c
Normal file
110
applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.c
Normal file
|
@ -0,0 +1,110 @@
|
|||
#include "cc1101_ext_interconnect.h"
|
||||
#include "cc1101_ext.h"
|
||||
#include <lib/subghz/devices/cc1101_configs.h>
|
||||
|
||||
#define TAG "SubGhzDeviceCC1101Ext"
|
||||
|
||||
static bool subghz_device_cc1101_ext_interconnect_is_frequency_valid(uint32_t frequency) {
|
||||
bool ret = subghz_device_cc1101_ext_is_frequency_valid(frequency);
|
||||
if(!ret) {
|
||||
furi_crash("SubGhz: Incorrect frequency.");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static uint32_t subghz_device_cc1101_ext_interconnect_set_frequency(uint32_t frequency) {
|
||||
subghz_device_cc1101_ext_interconnect_is_frequency_valid(frequency);
|
||||
return subghz_device_cc1101_ext_set_frequency(frequency);
|
||||
}
|
||||
|
||||
static bool subghz_device_cc1101_ext_interconnect_start_async_tx(void* callback, void* context) {
|
||||
return subghz_device_cc1101_ext_start_async_tx(
|
||||
(SubGhzDeviceCC1101ExtCallback)callback, context);
|
||||
}
|
||||
|
||||
static void subghz_device_cc1101_ext_interconnect_start_async_rx(void* callback, void* context) {
|
||||
subghz_device_cc1101_ext_start_async_rx(
|
||||
(SubGhzDeviceCC1101ExtCaptureCallback)callback, context);
|
||||
}
|
||||
|
||||
static void subghz_device_cc1101_ext_interconnect_load_preset(
|
||||
FuriHalSubGhzPreset preset,
|
||||
uint8_t* preset_data) {
|
||||
switch(preset) {
|
||||
case FuriHalSubGhzPresetOok650Async:
|
||||
subghz_device_cc1101_ext_load_custom_preset(
|
||||
subghz_device_cc1101_preset_ook_650khz_async_regs);
|
||||
break;
|
||||
case FuriHalSubGhzPresetOok270Async:
|
||||
subghz_device_cc1101_ext_load_custom_preset(
|
||||
subghz_device_cc1101_preset_ook_270khz_async_regs);
|
||||
break;
|
||||
case FuriHalSubGhzPreset2FSKDev238Async:
|
||||
subghz_device_cc1101_ext_load_custom_preset(
|
||||
subghz_device_cc1101_preset_2fsk_dev2_38khz_async_regs);
|
||||
break;
|
||||
case FuriHalSubGhzPreset2FSKDev476Async:
|
||||
subghz_device_cc1101_ext_load_custom_preset(
|
||||
subghz_device_cc1101_preset_2fsk_dev47_6khz_async_regs);
|
||||
break;
|
||||
case FuriHalSubGhzPresetMSK99_97KbAsync:
|
||||
subghz_device_cc1101_ext_load_custom_preset(
|
||||
subghz_device_cc1101_preset_msk_99_97kb_async_regs);
|
||||
break;
|
||||
case FuriHalSubGhzPresetGFSK9_99KbAsync:
|
||||
subghz_device_cc1101_ext_load_custom_preset(
|
||||
subghz_device_cc1101_preset_gfsk_9_99kb_async_regs);
|
||||
break;
|
||||
|
||||
default:
|
||||
subghz_device_cc1101_ext_load_custom_preset(preset_data);
|
||||
}
|
||||
}
|
||||
|
||||
const SubGhzDeviceInterconnect subghz_device_cc1101_ext_interconnect = {
|
||||
.begin = subghz_device_cc1101_ext_alloc,
|
||||
.end = subghz_device_cc1101_ext_free,
|
||||
.is_connect = subghz_device_cc1101_ext_is_connect,
|
||||
.reset = subghz_device_cc1101_ext_reset,
|
||||
.sleep = subghz_device_cc1101_ext_sleep,
|
||||
.idle = subghz_device_cc1101_ext_idle,
|
||||
.load_preset = subghz_device_cc1101_ext_interconnect_load_preset,
|
||||
.set_frequency = subghz_device_cc1101_ext_interconnect_set_frequency,
|
||||
.is_frequency_valid = subghz_device_cc1101_ext_is_frequency_valid,
|
||||
.set_async_mirror_pin = subghz_device_cc1101_ext_set_async_mirror_pin,
|
||||
.get_data_gpio = subghz_device_cc1101_ext_get_data_gpio,
|
||||
|
||||
.set_tx = subghz_device_cc1101_ext_tx,
|
||||
.flush_tx = subghz_device_cc1101_ext_flush_tx,
|
||||
.start_async_tx = subghz_device_cc1101_ext_interconnect_start_async_tx,
|
||||
.is_async_complete_tx = subghz_device_cc1101_ext_is_async_tx_complete,
|
||||
.stop_async_tx = subghz_device_cc1101_ext_stop_async_tx,
|
||||
|
||||
.set_rx = subghz_device_cc1101_ext_rx,
|
||||
.flush_rx = subghz_device_cc1101_ext_flush_rx,
|
||||
.start_async_rx = subghz_device_cc1101_ext_interconnect_start_async_rx,
|
||||
.stop_async_rx = subghz_device_cc1101_ext_stop_async_rx,
|
||||
|
||||
.get_rssi = subghz_device_cc1101_ext_get_rssi,
|
||||
.get_lqi = subghz_device_cc1101_ext_get_lqi,
|
||||
|
||||
.rx_pipe_not_empty = subghz_device_cc1101_ext_rx_pipe_not_empty,
|
||||
.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,
|
||||
};
|
||||
|
||||
const SubGhzDevice subghz_device_cc1101_ext = {
|
||||
.name = SUBGHZ_DEVICE_CC1101_EXT_NAME,
|
||||
.interconnect = &subghz_device_cc1101_ext_interconnect,
|
||||
};
|
||||
|
||||
static const FlipperAppPluginDescriptor subghz_device_cc1101_ext_descriptor = {
|
||||
.appid = SUBGHZ_RADIO_DEVICE_PLUGIN_APP_ID,
|
||||
.ep_api_version = SUBGHZ_RADIO_DEVICE_PLUGIN_API_VERSION,
|
||||
.entry_point = &subghz_device_cc1101_ext,
|
||||
};
|
||||
|
||||
const FlipperAppPluginDescriptor* subghz_device_cc1101_ext_ep() {
|
||||
return &subghz_device_cc1101_ext_descriptor;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
#include <lib/subghz/devices/types.h>
|
||||
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_NAME "cc1101_ext"
|
||||
|
||||
typedef struct SubGhzDeviceCC1101Ext SubGhzDeviceCC1101Ext;
|
||||
|
||||
const FlipperAppPluginDescriptor* subghz_device_cc1101_ext_ep();
|
64
applications/external/playlist/helpers/radio_device_loader.c
vendored
Normal file
64
applications/external/playlist/helpers/radio_device_loader.c
vendored
Normal file
|
@ -0,0 +1,64 @@
|
|||
#include "radio_device_loader.h"
|
||||
|
||||
#include <applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h>
|
||||
#include <lib/subghz/devices/cc1101_int/cc1101_int_interconnect.h>
|
||||
|
||||
static void radio_device_loader_power_on() {
|
||||
uint8_t attempts = 0;
|
||||
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
|
||||
furi_hal_power_enable_otg();
|
||||
//CC1101 power-up time
|
||||
furi_delay_ms(10);
|
||||
}
|
||||
}
|
||||
|
||||
static void radio_device_loader_power_off() {
|
||||
if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg();
|
||||
}
|
||||
|
||||
bool radio_device_loader_is_connect_external(const char* name) {
|
||||
bool is_connect = false;
|
||||
bool is_otg_enabled = furi_hal_power_is_otg_enabled();
|
||||
|
||||
if(!is_otg_enabled) {
|
||||
radio_device_loader_power_on();
|
||||
}
|
||||
|
||||
const SubGhzDevice* device = subghz_devices_get_by_name(name);
|
||||
if(device) {
|
||||
is_connect = subghz_devices_is_connect(device);
|
||||
}
|
||||
|
||||
if(!is_otg_enabled) {
|
||||
radio_device_loader_power_off();
|
||||
}
|
||||
return is_connect;
|
||||
}
|
||||
|
||||
const SubGhzDevice* radio_device_loader_set(
|
||||
const SubGhzDevice* current_radio_device,
|
||||
SubGhzRadioDeviceType radio_device_type) {
|
||||
const SubGhzDevice* radio_device;
|
||||
|
||||
if(radio_device_type == SubGhzRadioDeviceTypeExternalCC1101 &&
|
||||
radio_device_loader_is_connect_external(SUBGHZ_DEVICE_CC1101_EXT_NAME)) {
|
||||
radio_device_loader_power_on();
|
||||
radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_EXT_NAME);
|
||||
subghz_devices_begin(radio_device);
|
||||
} else if(current_radio_device == NULL) {
|
||||
radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME);
|
||||
} else {
|
||||
radio_device_loader_end(current_radio_device);
|
||||
radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME);
|
||||
}
|
||||
|
||||
return radio_device;
|
||||
}
|
||||
|
||||
void radio_device_loader_end(const SubGhzDevice* radio_device) {
|
||||
furi_assert(radio_device);
|
||||
radio_device_loader_power_off();
|
||||
if(radio_device != subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME)) {
|
||||
subghz_devices_end(radio_device);
|
||||
}
|
||||
}
|
15
applications/external/playlist/helpers/radio_device_loader.h
vendored
Normal file
15
applications/external/playlist/helpers/radio_device_loader.h
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <lib/subghz/devices/devices.h>
|
||||
|
||||
/** SubGhzRadioDeviceType */
|
||||
typedef enum {
|
||||
SubGhzRadioDeviceTypeInternal,
|
||||
SubGhzRadioDeviceTypeExternalCC1101,
|
||||
} SubGhzRadioDeviceType;
|
||||
|
||||
const SubGhzDevice* radio_device_loader_set(
|
||||
const SubGhzDevice* current_radio_device,
|
||||
SubGhzRadioDeviceType radio_device_type);
|
||||
|
||||
void radio_device_loader_end(const SubGhzDevice* radio_device);
|
64
applications/external/playlist/playlist.c
vendored
64
applications/external/playlist/playlist.c
vendored
|
@ -10,7 +10,8 @@
|
|||
|
||||
#include <lib/subghz/protocols/protocol_items.h>
|
||||
#include <flipper_format/flipper_format_i.h>
|
||||
#include <applications/main/subghz/subghz_i.h>
|
||||
|
||||
#include "helpers/radio_device_loader.h"
|
||||
|
||||
#include "flipper_format_stream.h"
|
||||
#include "flipper_format_stream_i.h"
|
||||
|
@ -58,6 +59,7 @@ typedef struct {
|
|||
DisplayMeta* meta;
|
||||
|
||||
FuriString* file_path; // path to the playlist file
|
||||
const SubGhzDevice* radio_device;
|
||||
|
||||
bool ctl_request_exit; // can be set to true if the worker should exit
|
||||
bool ctl_pause; // can be set to true if the worker should pause
|
||||
|
@ -135,7 +137,9 @@ static int playlist_worker_process(
|
|||
FURI_LOG_W(TAG, " (TX) Missing Frequency, defaulting to 433.92MHz");
|
||||
frequency = 433920000;
|
||||
}
|
||||
if(!furi_hal_subghz_is_tx_allowed(frequency)) {
|
||||
if(!subghz_devices_is_frequency_valid(worker->radio_device, frequency)) {
|
||||
FURI_LOG_E(
|
||||
TAG, " (TX) The SubGhz device used does not support the frequency %lu", frequency);
|
||||
return -2;
|
||||
}
|
||||
|
||||
|
@ -152,12 +156,13 @@ static int playlist_worker_process(
|
|||
}
|
||||
|
||||
if(!furi_string_cmp_str(protocol, "RAW")) {
|
||||
subghz_protocol_raw_gen_fff_data(fff_data, path);
|
||||
subghz_protocol_raw_gen_fff_data(
|
||||
fff_data, path, subghz_devices_get_name(worker->radio_device));
|
||||
} else {
|
||||
stream_copy_full(
|
||||
flipper_format_get_raw_stream(fff_file), flipper_format_get_raw_stream(fff_data));
|
||||
}
|
||||
flipper_format_free(fff_file);
|
||||
flipper_format_file_close(fff_file);
|
||||
|
||||
// (try to) send file
|
||||
SubGhzEnvironment* environment = subghz_environment_alloc();
|
||||
|
@ -167,16 +172,23 @@ static int playlist_worker_process(
|
|||
|
||||
subghz_transmitter_deserialize(transmitter, fff_data);
|
||||
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(str_to_preset(preset));
|
||||
|
||||
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
subghz_devices_load_preset(worker->radio_device, str_to_preset(preset), NULL);
|
||||
// there is no check for a custom preset
|
||||
frequency = subghz_devices_set_frequency(worker->radio_device, frequency);
|
||||
|
||||
// Set device to TX and check frequency is alowed to TX
|
||||
if(!subghz_devices_set_tx(worker->radio_device)) {
|
||||
FURI_LOG_E(
|
||||
TAG,
|
||||
" (TX) The SubGhz device used does not support the frequency for transmitеing, %lu",
|
||||
frequency);
|
||||
return -5;
|
||||
}
|
||||
FURI_LOG_D(TAG, " (TX) Start sending ...");
|
||||
int status = 0;
|
||||
|
||||
furi_hal_subghz_start_async_tx(subghz_transmitter_yield, transmitter);
|
||||
while(!furi_hal_subghz_is_async_tx_complete()) {
|
||||
subghz_devices_start_async_tx(worker->radio_device, subghz_transmitter_yield, transmitter);
|
||||
while(!subghz_devices_is_async_complete_tx(worker->radio_device)) {
|
||||
if(worker->ctl_request_exit) {
|
||||
FURI_LOG_D(TAG, " (TX) Requested to exit. Cancelling sending...");
|
||||
status = 2;
|
||||
|
@ -204,8 +216,8 @@ static int playlist_worker_process(
|
|||
|
||||
FURI_LOG_D(TAG, " (TX) Done sending.");
|
||||
|
||||
furi_hal_subghz_stop_async_tx();
|
||||
furi_hal_subghz_sleep();
|
||||
subghz_devices_stop_async_tx(worker->radio_device);
|
||||
subghz_devices_idle(worker->radio_device);
|
||||
|
||||
subghz_transmitter_free(transmitter);
|
||||
|
||||
|
@ -287,6 +299,7 @@ static bool playlist_worker_play_playlist_once(
|
|||
|
||||
// if there was an error, fff_file is not already freed
|
||||
if(status < 0) {
|
||||
flipper_format_file_close(fff_file);
|
||||
flipper_format_free(fff_file);
|
||||
}
|
||||
|
||||
|
@ -437,6 +450,14 @@ PlaylistWorker* playlist_worker_alloc(DisplayMeta* meta) {
|
|||
|
||||
instance->file_path = furi_string_alloc();
|
||||
|
||||
subghz_devices_init();
|
||||
|
||||
instance->radio_device =
|
||||
radio_device_loader_set(instance->radio_device, SubGhzRadioDeviceTypeExternalCC1101);
|
||||
|
||||
subghz_devices_reset(instance->radio_device);
|
||||
subghz_devices_idle(instance->radio_device);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
@ -444,6 +465,12 @@ void playlist_worker_free(PlaylistWorker* instance) {
|
|||
furi_assert(instance);
|
||||
furi_thread_free(instance->thread);
|
||||
furi_string_free(instance->file_path);
|
||||
|
||||
subghz_devices_sleep(instance->radio_device);
|
||||
radio_device_loader_end(instance->radio_device);
|
||||
|
||||
subghz_devices_deinit();
|
||||
|
||||
free(instance);
|
||||
}
|
||||
|
||||
|
@ -711,15 +738,6 @@ int32_t playlist_app(void* p) {
|
|||
Playlist* app = playlist_alloc(meta);
|
||||
meta->view_port = app->view_port;
|
||||
|
||||
// Enable power for External CC1101 if it is connected
|
||||
furi_hal_subghz_enable_ext_power();
|
||||
// Auto switch to internal radio if external radio is not available
|
||||
furi_delay_ms(15);
|
||||
if(!furi_hal_subghz_check_radio()) {
|
||||
furi_hal_subghz_select_radio_type(SubGhzRadioInternal);
|
||||
furi_hal_subghz_init_radio_type(SubGhzRadioInternal);
|
||||
}
|
||||
|
||||
furi_hal_power_suppress_charge_enter();
|
||||
|
||||
// select playlist file
|
||||
|
@ -808,10 +826,6 @@ int32_t playlist_app(void* p) {
|
|||
exit_cleanup:
|
||||
|
||||
furi_hal_power_suppress_charge_exit();
|
||||
// Disable power for External CC1101 if it was enabled and module is connected
|
||||
furi_hal_subghz_disable_ext_power();
|
||||
// Reinit SPI handles for internal radio / nfc
|
||||
furi_hal_subghz_init_radio_type(SubGhzRadioInternal);
|
||||
|
||||
if(app->worker != NULL) {
|
||||
if(playlist_worker_running(app->worker)) {
|
||||
|
|
64
applications/external/spectrum_analyzer/helpers/radio_device_loader.c
vendored
Normal file
64
applications/external/spectrum_analyzer/helpers/radio_device_loader.c
vendored
Normal file
|
@ -0,0 +1,64 @@
|
|||
#include "radio_device_loader.h"
|
||||
|
||||
#include <applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h>
|
||||
#include <lib/subghz/devices/cc1101_int/cc1101_int_interconnect.h>
|
||||
|
||||
static void radio_device_loader_power_on() {
|
||||
uint8_t attempts = 0;
|
||||
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
|
||||
furi_hal_power_enable_otg();
|
||||
//CC1101 power-up time
|
||||
furi_delay_ms(10);
|
||||
}
|
||||
}
|
||||
|
||||
static void radio_device_loader_power_off() {
|
||||
if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg();
|
||||
}
|
||||
|
||||
bool radio_device_loader_is_connect_external(const char* name) {
|
||||
bool is_connect = false;
|
||||
bool is_otg_enabled = furi_hal_power_is_otg_enabled();
|
||||
|
||||
if(!is_otg_enabled) {
|
||||
radio_device_loader_power_on();
|
||||
}
|
||||
|
||||
const SubGhzDevice* device = subghz_devices_get_by_name(name);
|
||||
if(device) {
|
||||
is_connect = subghz_devices_is_connect(device);
|
||||
}
|
||||
|
||||
if(!is_otg_enabled) {
|
||||
radio_device_loader_power_off();
|
||||
}
|
||||
return is_connect;
|
||||
}
|
||||
|
||||
const SubGhzDevice* radio_device_loader_set(
|
||||
const SubGhzDevice* current_radio_device,
|
||||
SubGhzRadioDeviceType radio_device_type) {
|
||||
const SubGhzDevice* radio_device;
|
||||
|
||||
if(radio_device_type == SubGhzRadioDeviceTypeExternalCC1101 &&
|
||||
radio_device_loader_is_connect_external(SUBGHZ_DEVICE_CC1101_EXT_NAME)) {
|
||||
radio_device_loader_power_on();
|
||||
radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_EXT_NAME);
|
||||
subghz_devices_begin(radio_device);
|
||||
} else if(current_radio_device == NULL) {
|
||||
radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME);
|
||||
} else {
|
||||
radio_device_loader_end(current_radio_device);
|
||||
radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME);
|
||||
}
|
||||
|
||||
return radio_device;
|
||||
}
|
||||
|
||||
void radio_device_loader_end(const SubGhzDevice* radio_device) {
|
||||
furi_assert(radio_device);
|
||||
radio_device_loader_power_off();
|
||||
if(radio_device != subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME)) {
|
||||
subghz_devices_end(radio_device);
|
||||
}
|
||||
}
|
15
applications/external/spectrum_analyzer/helpers/radio_device_loader.h
vendored
Normal file
15
applications/external/spectrum_analyzer/helpers/radio_device_loader.h
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <lib/subghz/devices/devices.h>
|
||||
|
||||
/** SubGhzRadioDeviceType */
|
||||
typedef enum {
|
||||
SubGhzRadioDeviceTypeInternal,
|
||||
SubGhzRadioDeviceTypeExternalCC1101,
|
||||
} SubGhzRadioDeviceType;
|
||||
|
||||
const SubGhzDevice* radio_device_loader_set(
|
||||
const SubGhzDevice* current_radio_device,
|
||||
SubGhzRadioDeviceType radio_device_type);
|
||||
|
||||
void radio_device_loader_end(const SubGhzDevice* radio_device);
|
|
@ -389,14 +389,6 @@ void spectrum_analyzer_free(SpectrumAnalyzer* instance) {
|
|||
|
||||
free(instance->model);
|
||||
free(instance);
|
||||
|
||||
furi_hal_subghz_idle();
|
||||
furi_hal_subghz_sleep();
|
||||
|
||||
// Disable power for External CC1101 if it was enabled and module is connected
|
||||
furi_hal_subghz_disable_ext_power();
|
||||
// Reinit SPI handles for internal radio / nfc
|
||||
furi_hal_subghz_init_radio_type(SubGhzRadioInternal);
|
||||
}
|
||||
|
||||
int32_t spectrum_analyzer_app(void* p) {
|
||||
|
@ -405,21 +397,18 @@ int32_t spectrum_analyzer_app(void* p) {
|
|||
SpectrumAnalyzer* spectrum_analyzer = spectrum_analyzer_alloc();
|
||||
InputEvent input;
|
||||
|
||||
// Enable power for External CC1101 if it is connected
|
||||
furi_hal_subghz_enable_ext_power();
|
||||
// Auto switch to internal radio if external radio is not available
|
||||
furi_delay_ms(15);
|
||||
if(!furi_hal_subghz_check_radio()) {
|
||||
furi_hal_subghz_select_radio_type(SubGhzRadioInternal);
|
||||
furi_hal_subghz_init_radio_type(SubGhzRadioInternal);
|
||||
}
|
||||
|
||||
furi_hal_power_suppress_charge_enter();
|
||||
|
||||
FURI_LOG_D("Spectrum", "Main Loop - Starting worker");
|
||||
furi_delay_ms(50);
|
||||
|
||||
spectrum_analyzer_worker_start(spectrum_analyzer->worker);
|
||||
spectrum_analyzer_calculate_frequencies(spectrum_analyzer->model);
|
||||
spectrum_analyzer_worker_set_frequencies(
|
||||
spectrum_analyzer->worker,
|
||||
spectrum_analyzer->model->channel0_frequency,
|
||||
spectrum_analyzer->model->spacing,
|
||||
spectrum_analyzer->model->width);
|
||||
|
||||
FURI_LOG_D("Spectrum", "Main Loop - Wait on queue");
|
||||
furi_delay_ms(50);
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include <furi_hal.h>
|
||||
#include <furi.h>
|
||||
|
||||
#include "helpers/radio_device_loader.h"
|
||||
|
||||
#include <lib/drivers/cc1101_regs.h>
|
||||
|
||||
struct SpectrumAnalyzerWorker {
|
||||
|
@ -13,6 +15,8 @@ struct SpectrumAnalyzerWorker {
|
|||
SpectrumAnalyzerWorkerCallback callback;
|
||||
void* callback_context;
|
||||
|
||||
const SubGhzDevice* radio_device;
|
||||
|
||||
uint32_t channel0_frequency;
|
||||
uint32_t spacing;
|
||||
uint8_t width;
|
||||
|
@ -44,7 +48,9 @@ void spectrum_analyzer_worker_set_filter(SpectrumAnalyzerWorker* instance) {
|
|||
filter_config[0][1] = 0x6C; /* 196 kHz / .8 = 245 kHz --> 270 kHz */
|
||||
break;
|
||||
}
|
||||
furi_hal_subghz_load_registers((uint8_t*)filter_config);
|
||||
|
||||
UNUSED(filter_config);
|
||||
// furi_hal_subghz_load_registers((uint8_t*)filter_config);
|
||||
}
|
||||
|
||||
static int32_t spectrum_analyzer_worker_thread(void* context) {
|
||||
|
@ -54,32 +60,53 @@ static int32_t spectrum_analyzer_worker_thread(void* context) {
|
|||
FURI_LOG_D("SpectrumWorker", "spectrum_analyzer_worker_thread: Start");
|
||||
|
||||
// Start CC1101
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
furi_hal_subghz_set_frequency(433920000);
|
||||
furi_hal_subghz_flush_rx();
|
||||
furi_hal_subghz_rx();
|
||||
subghz_devices_reset(instance->radio_device);
|
||||
subghz_devices_load_preset(instance->radio_device, FuriHalSubGhzPresetOok650Async, NULL);
|
||||
subghz_devices_set_frequency(instance->radio_device, 433920000);
|
||||
subghz_devices_flush_rx(instance->radio_device);
|
||||
subghz_devices_set_rx(instance->radio_device);
|
||||
|
||||
static const uint8_t radio_config[][2] = {
|
||||
{CC1101_FSCTRL1, 0x12},
|
||||
{CC1101_FSCTRL0, 0x00},
|
||||
const uint8_t radio_config[] = {
|
||||
|
||||
{CC1101_AGCCTRL2, 0xC0},
|
||||
CC1101_FSCTRL0,
|
||||
0x00,
|
||||
CC1101_FSCTRL1,
|
||||
0x12,
|
||||
|
||||
CC1101_AGCCTRL2,
|
||||
0xC0,
|
||||
|
||||
CC1101_MDMCFG4,
|
||||
0x6C,
|
||||
CC1101_TEST2,
|
||||
0x88,
|
||||
CC1101_TEST1,
|
||||
0x31,
|
||||
CC1101_TEST0,
|
||||
0x09,
|
||||
|
||||
{CC1101_MDMCFG4, 0x6C},
|
||||
{CC1101_TEST2, 0x88},
|
||||
{CC1101_TEST1, 0x31},
|
||||
{CC1101_TEST0, 0x09},
|
||||
/* End */
|
||||
{0, 0},
|
||||
0,
|
||||
0,
|
||||
|
||||
// ook_async_patable
|
||||
0x00,
|
||||
0xC0, // 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,
|
||||
};
|
||||
|
||||
while(instance->should_work) {
|
||||
furi_delay_ms(50);
|
||||
|
||||
// FURI_LOG_T("SpectrumWorker", "spectrum_analyzer_worker_thread: Worker Loop");
|
||||
furi_hal_subghz_idle();
|
||||
furi_hal_subghz_load_registers((uint8_t*)radio_config);
|
||||
subghz_devices_idle(instance->radio_device);
|
||||
subghz_devices_load_preset(
|
||||
instance->radio_device, FuriHalSubGhzPresetCustom, (uint8_t*)radio_config);
|
||||
|
||||
// TODO: Check filter!
|
||||
// spectrum_analyzer_worker_set_filter(instance);
|
||||
|
@ -90,9 +117,15 @@ static int32_t spectrum_analyzer_worker_thread(void* context) {
|
|||
for(uint8_t ch_offset = 0, chunk = 0; ch_offset < CHUNK_SIZE;
|
||||
++chunk >= NUM_CHUNKS && ++ch_offset && (chunk = 0)) {
|
||||
uint8_t ch = chunk * CHUNK_SIZE + ch_offset;
|
||||
furi_hal_subghz_set_frequency(instance->channel0_frequency + (ch * instance->spacing));
|
||||
|
||||
furi_hal_subghz_rx();
|
||||
if(subghz_devices_is_frequency_valid(
|
||||
instance->radio_device,
|
||||
instance->channel0_frequency + (ch * instance->spacing)))
|
||||
subghz_devices_set_frequency(
|
||||
instance->radio_device,
|
||||
instance->channel0_frequency + (ch * instance->spacing));
|
||||
|
||||
subghz_devices_set_rx(instance->radio_device);
|
||||
furi_delay_ms(3);
|
||||
|
||||
// dec dBm
|
||||
|
@ -100,7 +133,7 @@ static int32_t spectrum_analyzer_worker_thread(void* context) {
|
|||
//max_ss = 0 -> -74.0
|
||||
//max_ss = 255 -> -74.5
|
||||
//max_ss = 128 -> -138.0
|
||||
instance->channel_ss[ch] = (furi_hal_subghz_get_rssi() + 138) * 2;
|
||||
instance->channel_ss[ch] = (subghz_devices_get_rssi(instance->radio_device) + 138) * 2;
|
||||
|
||||
if(instance->channel_ss[ch] > instance->max_rssi_dec) {
|
||||
instance->max_rssi_dec = instance->channel_ss[ch];
|
||||
|
@ -108,7 +141,7 @@ static int32_t spectrum_analyzer_worker_thread(void* context) {
|
|||
instance->max_rssi_channel = ch;
|
||||
}
|
||||
|
||||
furi_hal_subghz_idle();
|
||||
subghz_devices_idle(instance->radio_device);
|
||||
}
|
||||
|
||||
// FURI_LOG_T("SpectrumWorker", "channel_ss[0]: %u", instance->channel_ss[0]);
|
||||
|
@ -138,6 +171,11 @@ SpectrumAnalyzerWorker* spectrum_analyzer_worker_alloc() {
|
|||
furi_thread_set_context(instance->thread, instance);
|
||||
furi_thread_set_callback(instance->thread, spectrum_analyzer_worker_thread);
|
||||
|
||||
subghz_devices_init();
|
||||
|
||||
instance->radio_device =
|
||||
radio_device_loader_set(instance->radio_device, SubGhzRadioDeviceTypeExternalCC1101);
|
||||
|
||||
FURI_LOG_D("Spectrum", "spectrum_analyzer_worker_alloc: End");
|
||||
|
||||
return instance;
|
||||
|
@ -147,6 +185,12 @@ void spectrum_analyzer_worker_free(SpectrumAnalyzerWorker* instance) {
|
|||
FURI_LOG_D("Spectrum", "spectrum_analyzer_worker_free");
|
||||
furi_assert(instance);
|
||||
furi_thread_free(instance->thread);
|
||||
|
||||
subghz_devices_sleep(instance->radio_device);
|
||||
radio_device_loader_end(instance->radio_device);
|
||||
|
||||
subghz_devices_deinit();
|
||||
|
||||
free(instance);
|
||||
}
|
||||
|
||||
|
|
|
@ -84,8 +84,8 @@ SubRemLoadSubState subrem_sub_preset_load(
|
|||
if(!flipper_format_read_uint32(fff_data_file, "Frequency", &temp_data32, 1)) {
|
||||
FURI_LOG_W(TAG, "Cannot read frequency. Set default frequency");
|
||||
sub_preset->freq_preset.frequency = subghz_setting_get_default_frequency(setting);
|
||||
} else if(!furi_hal_subghz_is_tx_allowed(temp_data32)) {
|
||||
FURI_LOG_E(TAG, "This frequency can only be used for RX");
|
||||
} else if(!subghz_txrx_radio_device_is_frequecy_valid(txrx, temp_data32)) {
|
||||
FURI_LOG_E(TAG, "Frequency not supported on chosen radio module");
|
||||
break;
|
||||
}
|
||||
sub_preset->freq_preset.frequency = temp_data32;
|
||||
|
@ -124,7 +124,9 @@ SubRemLoadSubState subrem_sub_preset_load(
|
|||
if(!strcmp(furi_string_get_cstr(temp_str), "RAW")) {
|
||||
//if RAW
|
||||
subghz_protocol_raw_gen_fff_data(
|
||||
fff_data, furi_string_get_cstr(sub_preset->file_path));
|
||||
fff_data,
|
||||
furi_string_get_cstr(sub_preset->file_path),
|
||||
subghz_txrx_radio_device_get_name(txrx));
|
||||
} else {
|
||||
stream_copy_full(
|
||||
flipper_format_get_raw_stream(fff_data_file),
|
||||
|
|
|
@ -1,8 +1,28 @@
|
|||
#include "subghz_txrx_i.h"
|
||||
|
||||
#include <lib/subghz/protocols/protocol_items.h>
|
||||
#include <applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h>
|
||||
#include <lib/subghz/devices/cc1101_int/cc1101_int_interconnect.h>
|
||||
|
||||
#include <lib/subghz/blocks/custom_btn.h>
|
||||
|
||||
#define TAG "SubGhz"
|
||||
|
||||
static void subghz_txrx_radio_device_power_on(SubGhzTxRx* instance) {
|
||||
UNUSED(instance);
|
||||
uint8_t attempts = 0;
|
||||
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
|
||||
furi_hal_power_enable_otg();
|
||||
//CC1101 power-up time
|
||||
furi_delay_ms(10);
|
||||
}
|
||||
}
|
||||
|
||||
static void subghz_txrx_radio_device_power_off(SubGhzTxRx* instance) {
|
||||
UNUSED(instance);
|
||||
if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg();
|
||||
}
|
||||
|
||||
SubGhzTxRx* subghz_txrx_alloc() {
|
||||
SubGhzTxRx* instance = malloc(sizeof(SubGhzTxRx));
|
||||
instance->setting = subghz_setting_alloc();
|
||||
|
@ -23,16 +43,15 @@ SubGhzTxRx* subghz_txrx_alloc() {
|
|||
instance->fff_data = flipper_format_string_alloc();
|
||||
|
||||
instance->environment = subghz_environment_alloc();
|
||||
instance->is_database_loaded = subghz_environment_load_keystore(
|
||||
instance->environment, EXT_PATH("subghz/assets/keeloq_mfcodes"));
|
||||
subghz_environment_load_keystore(
|
||||
instance->environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user"));
|
||||
instance->is_database_loaded =
|
||||
subghz_environment_load_keystore(instance->environment, SUBGHZ_KEYSTORE_DIR_NAME);
|
||||
subghz_environment_load_keystore(instance->environment, SUBGHZ_KEYSTORE_DIR_USER_NAME);
|
||||
subghz_environment_set_came_atomo_rainbow_table_file_name(
|
||||
instance->environment, EXT_PATH("subghz/assets/came_atomo"));
|
||||
instance->environment, SUBGHZ_CAME_ATOMO_DIR_NAME);
|
||||
subghz_environment_set_alutech_at_4n_rainbow_table_file_name(
|
||||
instance->environment, EXT_PATH("subghz/assets/alutech_at_4n"));
|
||||
instance->environment, SUBGHZ_ALUTECH_AT_4N_DIR_NAME);
|
||||
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
|
||||
instance->environment, EXT_PATH("subghz/assets/nice_flor_s"));
|
||||
instance->environment, SUBGHZ_NICE_FLOR_S_DIR_NAME);
|
||||
subghz_environment_set_protocol_registry(
|
||||
instance->environment, (void*)&subghz_protocol_registry);
|
||||
instance->receiver = subghz_receiver_alloc_init(instance->environment);
|
||||
|
@ -43,18 +62,32 @@ SubGhzTxRx* subghz_txrx_alloc() {
|
|||
instance->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode);
|
||||
subghz_worker_set_context(instance->worker, instance->receiver);
|
||||
|
||||
//set default device Internal
|
||||
subghz_devices_init();
|
||||
instance->radio_device_type = SubGhzRadioDeviceTypeInternal;
|
||||
instance->radio_device_type =
|
||||
subghz_txrx_radio_device_set(instance, SubGhzRadioDeviceTypeInternal);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_txrx_free(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
if(instance->radio_device_type != SubGhzRadioDeviceTypeInternal) {
|
||||
subghz_txrx_radio_device_power_off(instance);
|
||||
subghz_devices_end(instance->radio_device);
|
||||
}
|
||||
|
||||
subghz_devices_deinit();
|
||||
|
||||
subghz_worker_free(instance->worker);
|
||||
subghz_receiver_free(instance->receiver);
|
||||
subghz_environment_free(instance->environment);
|
||||
flipper_format_free(instance->fff_data);
|
||||
furi_string_free(instance->preset->name);
|
||||
subghz_setting_free(instance->setting);
|
||||
|
||||
free(instance->preset);
|
||||
free(instance);
|
||||
}
|
||||
|
@ -127,29 +160,25 @@ void subghz_txrx_get_frequency_and_modulation(
|
|||
|
||||
static void subghz_txrx_begin(SubGhzTxRx* instance, uint8_t* preset_data) {
|
||||
furi_assert(instance);
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_idle();
|
||||
furi_hal_subghz_load_custom_preset(preset_data);
|
||||
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
subghz_devices_reset(instance->radio_device);
|
||||
subghz_devices_idle(instance->radio_device);
|
||||
subghz_devices_load_preset(instance->radio_device, FuriHalSubGhzPresetCustom, preset_data);
|
||||
instance->txrx_state = SubGhzTxRxStateIDLE;
|
||||
}
|
||||
|
||||
static uint32_t subghz_txrx_rx(SubGhzTxRx* instance, uint32_t frequency) {
|
||||
furi_assert(instance);
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
furi_crash("SubGhz: Incorrect RX frequency.");
|
||||
}
|
||||
furi_assert(
|
||||
instance->txrx_state != SubGhzTxRxStateRx && instance->txrx_state != SubGhzTxRxStateSleep);
|
||||
|
||||
furi_hal_subghz_idle();
|
||||
uint32_t value = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_subghz_flush_rx();
|
||||
subghz_txrx_speaker_on(instance);
|
||||
furi_hal_subghz_rx();
|
||||
subghz_devices_idle(instance->radio_device);
|
||||
|
||||
furi_hal_subghz_start_async_rx(subghz_worker_rx_callback, instance->worker);
|
||||
uint32_t value = subghz_devices_set_frequency(instance->radio_device, frequency);
|
||||
subghz_devices_flush_rx(instance->radio_device);
|
||||
subghz_txrx_speaker_on(instance);
|
||||
|
||||
subghz_devices_start_async_rx(
|
||||
instance->radio_device, subghz_worker_rx_callback, instance->worker);
|
||||
subghz_worker_start(instance->worker);
|
||||
instance->txrx_state = SubGhzTxRxStateRx;
|
||||
return value;
|
||||
|
@ -158,7 +187,7 @@ static uint32_t subghz_txrx_rx(SubGhzTxRx* instance, uint32_t frequency) {
|
|||
static void subghz_txrx_idle(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
furi_assert(instance->txrx_state != SubGhzTxRxStateSleep);
|
||||
furi_hal_subghz_idle();
|
||||
subghz_devices_idle(instance->radio_device);
|
||||
subghz_txrx_speaker_off(instance);
|
||||
instance->txrx_state = SubGhzTxRxStateIDLE;
|
||||
}
|
||||
|
@ -169,31 +198,27 @@ static void subghz_txrx_rx_end(SubGhzTxRx* instance) {
|
|||
|
||||
if(subghz_worker_is_running(instance->worker)) {
|
||||
subghz_worker_stop(instance->worker);
|
||||
furi_hal_subghz_stop_async_rx();
|
||||
subghz_devices_stop_async_rx(instance->radio_device);
|
||||
}
|
||||
furi_hal_subghz_idle();
|
||||
subghz_devices_idle(instance->radio_device);
|
||||
subghz_txrx_speaker_off(instance);
|
||||
instance->txrx_state = SubGhzTxRxStateIDLE;
|
||||
}
|
||||
|
||||
void subghz_txrx_sleep(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
furi_hal_subghz_sleep();
|
||||
subghz_devices_sleep(instance->radio_device);
|
||||
instance->txrx_state = SubGhzTxRxStateSleep;
|
||||
}
|
||||
|
||||
static bool subghz_txrx_tx(SubGhzTxRx* instance, uint32_t frequency) {
|
||||
furi_assert(instance);
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
furi_crash("SubGhz: Incorrect TX frequency.");
|
||||
}
|
||||
furi_assert(instance->txrx_state != SubGhzTxRxStateSleep);
|
||||
furi_hal_subghz_idle();
|
||||
furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
furi_hal_gpio_write(furi_hal_subghz.cc1101_g0_pin, false);
|
||||
furi_hal_gpio_init(
|
||||
furi_hal_subghz.cc1101_g0_pin, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
bool ret = furi_hal_subghz_tx();
|
||||
|
||||
subghz_devices_idle(instance->radio_device);
|
||||
subghz_devices_set_frequency(instance->radio_device, frequency);
|
||||
|
||||
bool ret = subghz_devices_set_tx(instance->radio_device);
|
||||
if(ret) {
|
||||
subghz_txrx_speaker_on(instance);
|
||||
instance->txrx_state = SubGhzTxRxStateTx;
|
||||
|
@ -255,8 +280,8 @@ SubGhzTxRxStartTxState subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat*
|
|||
|
||||
if(ret == SubGhzTxRxStartTxStateOk) {
|
||||
//Start TX
|
||||
furi_hal_subghz_start_async_tx(
|
||||
subghz_transmitter_yield, instance->transmitter);
|
||||
subghz_devices_start_async_tx(
|
||||
instance->radio_device, subghz_transmitter_yield, instance->transmitter);
|
||||
}
|
||||
} else {
|
||||
ret = SubGhzTxRxStartTxStateErrorParserOthers;
|
||||
|
@ -299,7 +324,7 @@ static void subghz_txrx_tx_stop(SubGhzTxRx* instance) {
|
|||
furi_assert(instance);
|
||||
furi_assert(instance->txrx_state == SubGhzTxRxStateTx);
|
||||
//Stop TX
|
||||
furi_hal_subghz_stop_async_tx();
|
||||
subghz_devices_stop_async_tx(instance->radio_device);
|
||||
subghz_transmitter_stop(instance->transmitter);
|
||||
subghz_transmitter_free(instance->transmitter);
|
||||
|
||||
|
@ -312,7 +337,6 @@ static void subghz_txrx_tx_stop(SubGhzTxRx* instance) {
|
|||
subghz_txrx_idle(instance);
|
||||
subghz_txrx_speaker_off(instance);
|
||||
//Todo: Show message
|
||||
// notification_message(notifications, &sequence_reset_red);
|
||||
}
|
||||
|
||||
FlipperFormat* subghz_txrx_get_fff_data(SubGhzTxRx* instance) {
|
||||
|
@ -362,7 +386,7 @@ void subghz_txrx_hopper_update(SubGhzTxRx* instance) {
|
|||
float rssi = -127.0f;
|
||||
if(instance->hopper_state != SubGhzHopperStateRSSITimeOut) {
|
||||
// See RSSI Calculation timings in CC1101 17.3 RSSI
|
||||
rssi = furi_hal_subghz_get_rssi();
|
||||
rssi = subghz_devices_get_rssi(instance->radio_device);
|
||||
|
||||
// Stay if RSSI is high enough
|
||||
if(rssi > -90.0f) {
|
||||
|
@ -419,13 +443,13 @@ void subghz_txrx_hopper_pause(SubGhzTxRx* instance) {
|
|||
void subghz_txrx_speaker_on(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
if(instance->debug_pin_state) {
|
||||
furi_hal_subghz_set_async_mirror_pin(&gpio_ibutton);
|
||||
subghz_devices_set_async_mirror_pin(instance->radio_device, &gpio_ibutton);
|
||||
}
|
||||
|
||||
if(instance->speaker_state == SubGhzSpeakerStateEnable) {
|
||||
if(furi_hal_speaker_acquire(30)) {
|
||||
if(!instance->debug_pin_state) {
|
||||
furi_hal_subghz_set_async_mirror_pin(&gpio_speaker);
|
||||
subghz_devices_set_async_mirror_pin(instance->radio_device, &gpio_speaker);
|
||||
}
|
||||
} else {
|
||||
instance->speaker_state = SubGhzSpeakerStateDisable;
|
||||
|
@ -436,12 +460,12 @@ void subghz_txrx_speaker_on(SubGhzTxRx* instance) {
|
|||
void subghz_txrx_speaker_off(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
if(instance->debug_pin_state) {
|
||||
furi_hal_subghz_set_async_mirror_pin(NULL);
|
||||
subghz_devices_set_async_mirror_pin(instance->radio_device, NULL);
|
||||
}
|
||||
if(instance->speaker_state != SubGhzSpeakerStateDisable) {
|
||||
if(furi_hal_speaker_is_mine()) {
|
||||
if(!instance->debug_pin_state) {
|
||||
furi_hal_subghz_set_async_mirror_pin(NULL);
|
||||
subghz_devices_set_async_mirror_pin(instance->radio_device, NULL);
|
||||
}
|
||||
furi_hal_speaker_release();
|
||||
if(instance->speaker_state == SubGhzSpeakerStateShutdown)
|
||||
|
@ -453,12 +477,12 @@ void subghz_txrx_speaker_off(SubGhzTxRx* instance) {
|
|||
void subghz_txrx_speaker_mute(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
if(instance->debug_pin_state) {
|
||||
furi_hal_subghz_set_async_mirror_pin(NULL);
|
||||
subghz_devices_set_async_mirror_pin(instance->radio_device, NULL);
|
||||
}
|
||||
if(instance->speaker_state == SubGhzSpeakerStateEnable) {
|
||||
if(furi_hal_speaker_is_mine()) {
|
||||
if(!instance->debug_pin_state) {
|
||||
furi_hal_subghz_set_async_mirror_pin(NULL);
|
||||
subghz_devices_set_async_mirror_pin(instance->radio_device, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -467,12 +491,12 @@ void subghz_txrx_speaker_mute(SubGhzTxRx* instance) {
|
|||
void subghz_txrx_speaker_unmute(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
if(instance->debug_pin_state) {
|
||||
furi_hal_subghz_set_async_mirror_pin(&gpio_ibutton);
|
||||
subghz_devices_set_async_mirror_pin(instance->radio_device, &gpio_ibutton);
|
||||
}
|
||||
if(instance->speaker_state == SubGhzSpeakerStateEnable) {
|
||||
if(furi_hal_speaker_is_mine()) {
|
||||
if(!instance->debug_pin_state) {
|
||||
furi_hal_subghz_set_async_mirror_pin(&gpio_speaker);
|
||||
subghz_devices_set_async_mirror_pin(instance->radio_device, &gpio_speaker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -547,6 +571,82 @@ void subghz_txrx_set_raw_file_encoder_worker_callback_end(
|
|||
context);
|
||||
}
|
||||
|
||||
bool subghz_txrx_radio_device_is_external_connected(SubGhzTxRx* instance, const char* name) {
|
||||
furi_assert(instance);
|
||||
|
||||
bool is_connect = false;
|
||||
bool is_otg_enabled = furi_hal_power_is_otg_enabled();
|
||||
|
||||
if(!is_otg_enabled) {
|
||||
subghz_txrx_radio_device_power_on(instance);
|
||||
}
|
||||
|
||||
const SubGhzDevice* device = subghz_devices_get_by_name(name);
|
||||
if(device) {
|
||||
is_connect = subghz_devices_is_connect(device);
|
||||
}
|
||||
|
||||
if(!is_otg_enabled) {
|
||||
subghz_txrx_radio_device_power_off(instance);
|
||||
}
|
||||
return is_connect;
|
||||
}
|
||||
|
||||
SubGhzRadioDeviceType
|
||||
subghz_txrx_radio_device_set(SubGhzTxRx* instance, SubGhzRadioDeviceType radio_device_type) {
|
||||
furi_assert(instance);
|
||||
|
||||
if(radio_device_type == SubGhzRadioDeviceTypeExternalCC1101 &&
|
||||
subghz_txrx_radio_device_is_external_connected(instance, SUBGHZ_DEVICE_CC1101_EXT_NAME)) {
|
||||
subghz_txrx_radio_device_power_on(instance);
|
||||
instance->radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_EXT_NAME);
|
||||
subghz_devices_begin(instance->radio_device);
|
||||
instance->radio_device_type = SubGhzRadioDeviceTypeExternalCC1101;
|
||||
} else {
|
||||
subghz_txrx_radio_device_power_off(instance);
|
||||
if(instance->radio_device_type != SubGhzRadioDeviceTypeInternal) {
|
||||
subghz_devices_end(instance->radio_device);
|
||||
}
|
||||
instance->radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME);
|
||||
instance->radio_device_type = SubGhzRadioDeviceTypeInternal;
|
||||
}
|
||||
|
||||
return instance->radio_device_type;
|
||||
}
|
||||
|
||||
SubGhzRadioDeviceType subghz_txrx_radio_device_get(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->radio_device_type;
|
||||
}
|
||||
|
||||
float subghz_txrx_radio_device_get_rssi(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
return subghz_devices_get_rssi(instance->radio_device);
|
||||
}
|
||||
|
||||
const char* subghz_txrx_radio_device_get_name(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
return subghz_devices_get_name(instance->radio_device);
|
||||
}
|
||||
|
||||
bool subghz_txrx_radio_device_is_frequecy_valid(SubGhzTxRx* instance, uint32_t frequency) {
|
||||
furi_assert(instance);
|
||||
return subghz_devices_is_frequency_valid(instance->radio_device, frequency);
|
||||
}
|
||||
|
||||
bool subghz_txrx_radio_device_is_tx_alowed(SubGhzTxRx* instance, uint32_t frequency) {
|
||||
furi_assert(instance);
|
||||
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;
|
||||
}
|
||||
|
||||
void subghz_txrx_set_debug_pin_state(SubGhzTxRx* instance, bool state) {
|
||||
furi_assert(instance);
|
||||
instance->debug_pin_state = state;
|
||||
|
@ -557,6 +657,13 @@ bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* instance) {
|
|||
return instance->debug_pin_state;
|
||||
}
|
||||
|
||||
void subghz_txrx_reset_dynamic_and_custom_btns(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
subghz_environment_reset_keeloq(instance->environment);
|
||||
|
||||
subghz_custom_btns_reset();
|
||||
}
|
||||
|
||||
SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->receiver;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <lib/subghz/receiver.h>
|
||||
#include <lib/subghz/transmitter.h>
|
||||
#include <lib/subghz/protocols/raw.h>
|
||||
#include <lib/subghz/devices/devices.h>
|
||||
|
||||
typedef struct SubGhzTxRx SubGhzTxRx;
|
||||
|
||||
|
@ -40,6 +41,13 @@ typedef enum {
|
|||
SubGhzSpeakerStateEnable,
|
||||
} SubGhzSpeakerState;
|
||||
|
||||
/** SubGhzRadioDeviceType */
|
||||
typedef enum {
|
||||
SubGhzRadioDeviceTypeAuto,
|
||||
SubGhzRadioDeviceTypeInternal,
|
||||
SubGhzRadioDeviceTypeExternalCC1101,
|
||||
} SubGhzRadioDeviceType;
|
||||
|
||||
/**
|
||||
* Allocate SubGhzTxRx
|
||||
*
|
||||
|
@ -312,7 +320,56 @@ void subghz_txrx_set_raw_file_encoder_worker_callback_end(
|
|||
SubGhzProtocolEncoderRAWCallbackEnd callback,
|
||||
void* context);
|
||||
|
||||
/* Checking if an external radio device is connected
|
||||
*
|
||||
* @param instance Pointer to a SubGhzTxRx
|
||||
* @param name Name of external radio device
|
||||
* @return bool True if is connected to the external radio device
|
||||
*/
|
||||
bool subghz_txrx_radio_device_is_external_connected(SubGhzTxRx* instance, const char* name);
|
||||
|
||||
/* Set the selected radio device to use
|
||||
*
|
||||
* @param instance Pointer to a SubGhzTxRx
|
||||
* @param radio_device_type Radio device type
|
||||
* @return SubGhzRadioDeviceType Type of installed radio device
|
||||
*/
|
||||
SubGhzRadioDeviceType
|
||||
subghz_txrx_radio_device_set(SubGhzTxRx* instance, SubGhzRadioDeviceType radio_device_type);
|
||||
|
||||
/* Get the selected radio device to use
|
||||
*
|
||||
* @param instance Pointer to a SubGhzTxRx
|
||||
* @return SubGhzRadioDeviceType Type of installed radio device
|
||||
*/
|
||||
SubGhzRadioDeviceType subghz_txrx_radio_device_get(SubGhzTxRx* instance);
|
||||
|
||||
/* Get RSSI the selected radio device to use
|
||||
*
|
||||
* @param instance Pointer to a SubGhzTxRx
|
||||
* @return float RSSI
|
||||
*/
|
||||
float subghz_txrx_radio_device_get_rssi(SubGhzTxRx* instance);
|
||||
|
||||
/* Get name the selected radio device to use
|
||||
*
|
||||
* @param instance Pointer to a SubGhzTxRx
|
||||
* @return const char* Name of installed radio device
|
||||
*/
|
||||
const char* subghz_txrx_radio_device_get_name(SubGhzTxRx* instance);
|
||||
|
||||
/* Get get intelligence whether frequency the selected radio device to use
|
||||
*
|
||||
* @param instance Pointer to a SubGhzTxRx
|
||||
* @return bool True if the frequency is valid
|
||||
*/
|
||||
bool subghz_txrx_radio_device_is_frequecy_valid(SubGhzTxRx* instance, uint32_t frequency);
|
||||
|
||||
bool subghz_txrx_radio_device_is_tx_alowed(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);
|
||||
|
||||
void subghz_txrx_reset_dynamic_and_custom_btns(SubGhzTxRx* instance);
|
||||
|
||||
SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* instance); // TODO use only in DecodeRaw
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "subghz_txrx.h"
|
||||
|
||||
struct SubGhzTxRx {
|
||||
|
@ -21,9 +21,11 @@ struct SubGhzTxRx {
|
|||
|
||||
SubGhzTxRxState txrx_state;
|
||||
SubGhzSpeakerState speaker_state;
|
||||
const SubGhzDevice* radio_device;
|
||||
SubGhzRadioDeviceType radio_device_type;
|
||||
|
||||
SubGhzTxRxNeedSaveCallback need_save_callback;
|
||||
void* need_save_context;
|
||||
|
||||
bool debug_pin_state;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -28,18 +28,9 @@ SubGhzRemoteApp* subghz_remote_app_alloc() {
|
|||
//FURI_LOG_E(TAG, "Could not create folder %s", SUBREM_APP_FOLDER);
|
||||
}
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
/*
|
||||
// Enable power for External CC1101 if it is connected
|
||||
furi_hal_subghz_enable_ext_power();
|
||||
// Auto switch to internal radio if external radio is not available
|
||||
furi_delay_ms(15);
|
||||
if(!furi_hal_subghz_check_radio()) {
|
||||
furi_hal_subghz_select_radio_type(SubGhzRadioInternal);
|
||||
furi_hal_subghz_init_radio_type(SubGhzRadioInternal);
|
||||
}
|
||||
|
||||
furi_hal_power_suppress_charge_enter();
|
||||
*/
|
||||
// furi_hal_power_suppress_charge_enter();
|
||||
|
||||
app->file_path = furi_string_alloc();
|
||||
furi_string_set(app->file_path, SUBREM_APP_FOLDER);
|
||||
|
||||
|
@ -125,14 +116,9 @@ SubGhzRemoteApp* subghz_remote_app_alloc() {
|
|||
|
||||
void subghz_remote_app_free(SubGhzRemoteApp* app) {
|
||||
furi_assert(app);
|
||||
/*
|
||||
furi_hal_power_suppress_charge_exit();
|
||||
|
||||
// Disable power for External CC1101 if it was enabled and module is connected
|
||||
furi_hal_subghz_disable_ext_power();
|
||||
// Reinit SPI handles for internal radio / nfc
|
||||
furi_hal_subghz_init_radio_type(SubGhzRadioInternal);
|
||||
*/
|
||||
// furi_hal_power_suppress_charge_exit();
|
||||
|
||||
// Submenu
|
||||
view_dispatcher_remove_view(app->view_dispatcher, SubRemViewIDSubmenu);
|
||||
submenu_free(app->submenu);
|
||||
|
|
69
applications/external/weather_station/helpers/radio_device_loader.c
vendored
Normal file
69
applications/external/weather_station/helpers/radio_device_loader.c
vendored
Normal file
|
@ -0,0 +1,69 @@
|
|||
#include "radio_device_loader.h"
|
||||
|
||||
#include <applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h>
|
||||
#include <lib/subghz/devices/cc1101_int/cc1101_int_interconnect.h>
|
||||
|
||||
static void radio_device_loader_power_on() {
|
||||
uint8_t attempts = 0;
|
||||
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
|
||||
furi_hal_power_enable_otg();
|
||||
//CC1101 power-up time
|
||||
furi_delay_ms(10);
|
||||
}
|
||||
}
|
||||
|
||||
static void radio_device_loader_power_off() {
|
||||
if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg();
|
||||
}
|
||||
|
||||
bool radio_device_loader_is_connect_external(const char* name) {
|
||||
bool is_connect = false;
|
||||
bool is_otg_enabled = furi_hal_power_is_otg_enabled();
|
||||
|
||||
if(!is_otg_enabled) {
|
||||
radio_device_loader_power_on();
|
||||
}
|
||||
|
||||
const SubGhzDevice* device = subghz_devices_get_by_name(name);
|
||||
if(device) {
|
||||
is_connect = subghz_devices_is_connect(device);
|
||||
}
|
||||
|
||||
if(!is_otg_enabled) {
|
||||
radio_device_loader_power_off();
|
||||
}
|
||||
return is_connect;
|
||||
}
|
||||
|
||||
const SubGhzDevice* radio_device_loader_set(
|
||||
const SubGhzDevice* current_radio_device,
|
||||
SubGhzRadioDeviceType radio_device_type) {
|
||||
const SubGhzDevice* radio_device;
|
||||
|
||||
if(radio_device_type == SubGhzRadioDeviceTypeExternalCC1101 &&
|
||||
radio_device_loader_is_connect_external(SUBGHZ_DEVICE_CC1101_EXT_NAME)) {
|
||||
radio_device_loader_power_on();
|
||||
radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_EXT_NAME);
|
||||
subghz_devices_begin(radio_device);
|
||||
} else if(current_radio_device == NULL) {
|
||||
radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME);
|
||||
} else {
|
||||
radio_device_loader_end(current_radio_device);
|
||||
radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME);
|
||||
}
|
||||
|
||||
return radio_device;
|
||||
}
|
||||
|
||||
bool radio_device_loader_is_external(const SubGhzDevice* radio_device) {
|
||||
furi_assert(radio_device);
|
||||
return (radio_device != subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME));
|
||||
}
|
||||
|
||||
void radio_device_loader_end(const SubGhzDevice* radio_device) {
|
||||
furi_assert(radio_device);
|
||||
radio_device_loader_power_off();
|
||||
if(radio_device != subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME)) {
|
||||
subghz_devices_end(radio_device);
|
||||
}
|
||||
}
|
17
applications/external/weather_station/helpers/radio_device_loader.h
vendored
Normal file
17
applications/external/weather_station/helpers/radio_device_loader.h
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include <lib/subghz/devices/devices.h>
|
||||
|
||||
/** SubGhzRadioDeviceType */
|
||||
typedef enum {
|
||||
SubGhzRadioDeviceTypeInternal,
|
||||
SubGhzRadioDeviceTypeExternalCC1101,
|
||||
} SubGhzRadioDeviceType;
|
||||
|
||||
const SubGhzDevice* radio_device_loader_set(
|
||||
const SubGhzDevice* current_radio_device,
|
||||
SubGhzRadioDeviceType radio_device_type);
|
||||
|
||||
bool radio_device_loader_is_external(const SubGhzDevice* radio_device);
|
||||
|
||||
void radio_device_loader_end(const SubGhzDevice* radio_device);
|
|
@ -48,13 +48,18 @@ static void weather_station_scene_receiver_update_statusbar(void* context) {
|
|||
app->ws_receiver,
|
||||
furi_string_get_cstr(frequency_str),
|
||||
furi_string_get_cstr(modulation_str),
|
||||
furi_string_get_cstr(history_stat_str));
|
||||
furi_string_get_cstr(history_stat_str),
|
||||
radio_device_loader_is_external(app->txrx->radio_device));
|
||||
|
||||
furi_string_free(frequency_str);
|
||||
furi_string_free(modulation_str);
|
||||
} else {
|
||||
ws_view_receiver_add_data_statusbar(
|
||||
app->ws_receiver, furi_string_get_cstr(history_stat_str), "", "");
|
||||
app->ws_receiver,
|
||||
furi_string_get_cstr(history_stat_str),
|
||||
"",
|
||||
"",
|
||||
radio_device_loader_is_external(app->txrx->radio_device));
|
||||
}
|
||||
furi_string_free(history_stat_str);
|
||||
}
|
||||
|
@ -196,7 +201,7 @@ bool weather_station_scene_receiver_on_event(void* context, SceneManagerEvent ev
|
|||
weather_station_scene_receiver_update_statusbar(app);
|
||||
}
|
||||
// Get current RSSI
|
||||
float rssi = furi_hal_subghz_get_rssi();
|
||||
float rssi = subghz_devices_get_rssi(app->txrx->radio_device);
|
||||
ws_view_receiver_set_rssi(app->ws_receiver, rssi);
|
||||
|
||||
if(app->txrx->txrx_state == WSTxRxStateRx) {
|
||||
|
|
|
@ -61,6 +61,7 @@ typedef struct {
|
|||
uint16_t history_item;
|
||||
WSReceiverBarShow bar_show;
|
||||
uint8_t u_rssi;
|
||||
bool external_redio;
|
||||
} WSReceiverModel;
|
||||
|
||||
void ws_view_receiver_set_rssi(WSReceiver* instance, float rssi) {
|
||||
|
@ -154,7 +155,8 @@ void ws_view_receiver_add_data_statusbar(
|
|||
WSReceiver* ws_receiver,
|
||||
const char* frequency_str,
|
||||
const char* preset_str,
|
||||
const char* history_stat_str) {
|
||||
const char* history_stat_str,
|
||||
bool external) {
|
||||
furi_assert(ws_receiver);
|
||||
with_view_model(
|
||||
ws_receiver->view,
|
||||
|
@ -163,6 +165,7 @@ void ws_view_receiver_add_data_statusbar(
|
|||
furi_string_set_str(model->frequency_str, frequency_str);
|
||||
furi_string_set_str(model->preset_str, preset_str);
|
||||
furi_string_set_str(model->history_stat_str, history_stat_str);
|
||||
model->external_redio = external;
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
@ -202,7 +205,7 @@ void ws_view_receiver_draw(Canvas* canvas, WSReceiverModel* model) {
|
|||
FuriString* str_buff;
|
||||
str_buff = furi_string_alloc();
|
||||
|
||||
bool ext_module = furi_hal_subghz_get_radio_type();
|
||||
// bool ext_module = furi_hal_subghz_get_radio_type();
|
||||
|
||||
WSReceiverMenuItem* item_menu;
|
||||
|
||||
|
@ -228,11 +231,12 @@ void ws_view_receiver_draw(Canvas* canvas, WSReceiverModel* model) {
|
|||
canvas_set_color(canvas, ColorBlack);
|
||||
|
||||
if(model->history_item == 0) {
|
||||
canvas_draw_icon(canvas, 0, 0, ext_module ? &I_Fishing_123x52 : &I_Scanning_123x52);
|
||||
canvas_draw_icon(
|
||||
canvas, 0, 0, model->external_redio ? &I_Fishing_123x52 : &I_Scanning_123x52);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str(canvas, 63, 46, "Scanning...");
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str(canvas, 44, 10, ext_module ? "Ext" : "Int");
|
||||
canvas_draw_str(canvas, 44, 10, model->external_redio ? "Ext" : "Int");
|
||||
}
|
||||
|
||||
// Draw RSSI
|
||||
|
@ -408,6 +412,7 @@ WSReceiver* ws_view_receiver_alloc() {
|
|||
model->history_stat_str = furi_string_alloc();
|
||||
model->bar_show = WSReceiverBarShowDefault;
|
||||
model->history = malloc(sizeof(WSReceiverHistory));
|
||||
model->external_redio = false;
|
||||
WSReceiverMenuItemArray_init(model->history->data);
|
||||
},
|
||||
true);
|
||||
|
|
|
@ -27,7 +27,8 @@ void ws_view_receiver_add_data_statusbar(
|
|||
WSReceiver* ws_receiver,
|
||||
const char* frequency_str,
|
||||
const char* preset_str,
|
||||
const char* history_stat_str);
|
||||
const char* history_stat_str,
|
||||
bool external);
|
||||
|
||||
void ws_view_receiver_add_item_to_menu(WSReceiver* ws_receiver, const char* name, uint8_t type);
|
||||
|
||||
|
|
|
@ -98,6 +98,14 @@ WeatherStationApp* weather_station_app_alloc() {
|
|||
app->txrx->environment, (void*)&weather_station_protocol_registry);
|
||||
app->txrx->receiver = subghz_receiver_alloc_init(app->txrx->environment);
|
||||
|
||||
subghz_devices_init();
|
||||
|
||||
app->txrx->radio_device =
|
||||
radio_device_loader_set(app->txrx->radio_device, SubGhzRadioDeviceTypeExternalCC1101);
|
||||
|
||||
subghz_devices_reset(app->txrx->radio_device);
|
||||
subghz_devices_idle(app->txrx->radio_device);
|
||||
|
||||
subghz_receiver_set_filter(app->txrx->receiver, SubGhzProtocolFlag_Decodable);
|
||||
subghz_worker_set_overrun_callback(
|
||||
app->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset);
|
||||
|
@ -105,15 +113,6 @@ WeatherStationApp* weather_station_app_alloc() {
|
|||
app->txrx->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode);
|
||||
subghz_worker_set_context(app->txrx->worker, app->txrx->receiver);
|
||||
|
||||
// Enable power for External CC1101 if it is connected
|
||||
furi_hal_subghz_enable_ext_power();
|
||||
// Auto switch to internal radio if external radio is not available
|
||||
furi_delay_ms(15);
|
||||
if(!furi_hal_subghz_check_radio()) {
|
||||
furi_hal_subghz_select_radio_type(SubGhzRadioInternal);
|
||||
furi_hal_subghz_init_radio_type(SubGhzRadioInternal);
|
||||
}
|
||||
|
||||
furi_hal_power_suppress_charge_enter();
|
||||
|
||||
scene_manager_next_scene(app->scene_manager, WeatherStationSceneStart);
|
||||
|
@ -124,13 +123,10 @@ WeatherStationApp* weather_station_app_alloc() {
|
|||
void weather_station_app_free(WeatherStationApp* app) {
|
||||
furi_assert(app);
|
||||
|
||||
//CC1101 off
|
||||
ws_sleep(app);
|
||||
subghz_devices_sleep(app->txrx->radio_device);
|
||||
radio_device_loader_end(app->txrx->radio_device);
|
||||
|
||||
// Disable power for External CC1101 if it was enabled and module is connected
|
||||
furi_hal_subghz_disable_ext_power();
|
||||
// Reinit SPI handles for internal radio / nfc
|
||||
furi_hal_subghz_init_radio_type(SubGhzRadioInternal);
|
||||
subghz_devices_deinit();
|
||||
|
||||
// Submenu
|
||||
view_dispatcher_remove_view(app->view_dispatcher, WeatherStationViewSubmenu);
|
||||
|
|
|
@ -54,29 +54,28 @@ void ws_get_frequency_modulation(
|
|||
|
||||
void ws_begin(WeatherStationApp* app, uint8_t* preset_data) {
|
||||
furi_assert(app);
|
||||
UNUSED(preset_data);
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_idle();
|
||||
furi_hal_subghz_load_custom_preset(preset_data);
|
||||
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
subghz_devices_reset(app->txrx->radio_device);
|
||||
subghz_devices_idle(app->txrx->radio_device);
|
||||
subghz_devices_load_preset(app->txrx->radio_device, FuriHalSubGhzPresetCustom, preset_data);
|
||||
app->txrx->txrx_state = WSTxRxStateIDLE;
|
||||
}
|
||||
|
||||
uint32_t ws_rx(WeatherStationApp* app, uint32_t frequency) {
|
||||
furi_assert(app);
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
if(!subghz_devices_is_frequency_valid(app->txrx->radio_device, frequency)) {
|
||||
furi_crash("WeatherStation: Incorrect RX frequency.");
|
||||
}
|
||||
furi_assert(
|
||||
app->txrx->txrx_state != WSTxRxStateRx && app->txrx->txrx_state != WSTxRxStateSleep);
|
||||
|
||||
furi_hal_subghz_idle();
|
||||
uint32_t value = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_subghz_flush_rx();
|
||||
furi_hal_subghz_rx();
|
||||
subghz_devices_idle(app->txrx->radio_device);
|
||||
uint32_t value = subghz_devices_set_frequency(app->txrx->radio_device, frequency);
|
||||
subghz_devices_flush_rx(app->txrx->radio_device);
|
||||
subghz_devices_set_rx(app->txrx->radio_device);
|
||||
|
||||
subghz_devices_start_async_rx(
|
||||
app->txrx->radio_device, subghz_worker_rx_callback, app->txrx->worker);
|
||||
|
||||
furi_hal_subghz_start_async_rx(subghz_worker_rx_callback, app->txrx->worker);
|
||||
subghz_worker_start(app->txrx->worker);
|
||||
app->txrx->txrx_state = WSTxRxStateRx;
|
||||
return value;
|
||||
|
@ -85,7 +84,7 @@ uint32_t ws_rx(WeatherStationApp* app, uint32_t frequency) {
|
|||
void ws_idle(WeatherStationApp* app) {
|
||||
furi_assert(app);
|
||||
furi_assert(app->txrx->txrx_state != WSTxRxStateSleep);
|
||||
furi_hal_subghz_idle();
|
||||
subghz_devices_idle(app->txrx->radio_device);
|
||||
app->txrx->txrx_state = WSTxRxStateIDLE;
|
||||
}
|
||||
|
||||
|
@ -94,15 +93,15 @@ void ws_rx_end(WeatherStationApp* app) {
|
|||
furi_assert(app->txrx->txrx_state == WSTxRxStateRx);
|
||||
if(subghz_worker_is_running(app->txrx->worker)) {
|
||||
subghz_worker_stop(app->txrx->worker);
|
||||
furi_hal_subghz_stop_async_rx();
|
||||
subghz_devices_stop_async_rx(app->txrx->radio_device);
|
||||
}
|
||||
furi_hal_subghz_idle();
|
||||
subghz_devices_idle(app->txrx->radio_device);
|
||||
app->txrx->txrx_state = WSTxRxStateIDLE;
|
||||
}
|
||||
|
||||
void ws_sleep(WeatherStationApp* app) {
|
||||
furi_assert(app);
|
||||
furi_hal_subghz_sleep();
|
||||
subghz_devices_sleep(app->txrx->radio_device);
|
||||
app->txrx->txrx_state = WSTxRxStateSleep;
|
||||
}
|
||||
|
||||
|
@ -125,7 +124,7 @@ void ws_hopper_update(WeatherStationApp* app) {
|
|||
float rssi = -127.0f;
|
||||
if(app->txrx->hopper_state != WSHopperStateRSSITimeOut) {
|
||||
// See RSSI Calculation timings in CC1101 17.3 RSSI
|
||||
rssi = furi_hal_subghz_get_rssi();
|
||||
rssi = subghz_devices_get_rssi(app->txrx->radio_device);
|
||||
|
||||
// Stay if RSSI is high enough
|
||||
if(rssi > -90.0f) {
|
||||
|
|
|
@ -20,11 +20,14 @@
|
|||
#include <lib/subghz/transmitter.h>
|
||||
#include <lib/subghz/registry.h>
|
||||
|
||||
#include "helpers/radio_device_loader.h"
|
||||
|
||||
typedef struct WeatherStationApp WeatherStationApp;
|
||||
|
||||
struct WeatherStationTxRx {
|
||||
SubGhzWorker* worker;
|
||||
|
||||
const SubGhzDevice* radio_device;
|
||||
SubGhzEnvironment* environment;
|
||||
SubGhzReceiver* receiver;
|
||||
SubGhzRadioPreset* preset;
|
||||
|
|
|
@ -76,12 +76,15 @@ void subghz_chat_worker_free(SubGhzChatWorker* instance) {
|
|||
free(instance);
|
||||
}
|
||||
|
||||
bool subghz_chat_worker_start(SubGhzChatWorker* instance, uint32_t frequency) {
|
||||
bool subghz_chat_worker_start(
|
||||
SubGhzChatWorker* instance,
|
||||
const SubGhzDevice* device,
|
||||
uint32_t frequency) {
|
||||
furi_assert(instance);
|
||||
furi_assert(!instance->worker_running);
|
||||
bool res = false;
|
||||
|
||||
if(subghz_tx_rx_worker_start(instance->subghz_txrx, frequency)) {
|
||||
if(subghz_tx_rx_worker_start(instance->subghz_txrx, device, frequency)) {
|
||||
furi_message_queue_reset(instance->event_queue);
|
||||
subghz_tx_rx_worker_set_callback_have_read(
|
||||
instance->subghz_txrx, subghz_chat_worker_update_rx_event_chat, instance);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include "../subghz_i.h"
|
||||
#include <lib/subghz/devices/devices.h>
|
||||
#include <cli/cli.h>
|
||||
|
||||
typedef struct SubGhzChatWorker SubGhzChatWorker;
|
||||
|
@ -20,7 +21,10 @@ typedef struct {
|
|||
|
||||
SubGhzChatWorker* subghz_chat_worker_alloc(Cli* cli);
|
||||
void subghz_chat_worker_free(SubGhzChatWorker* instance);
|
||||
bool subghz_chat_worker_start(SubGhzChatWorker* instance, uint32_t frequency);
|
||||
bool subghz_chat_worker_start(
|
||||
SubGhzChatWorker* instance,
|
||||
const SubGhzDevice* device,
|
||||
uint32_t frequency);
|
||||
void subghz_chat_worker_stop(SubGhzChatWorker* instance);
|
||||
bool subghz_chat_worker_is_running(SubGhzChatWorker* instance);
|
||||
SubGhzChatEvent subghz_chat_worker_get_event_chat(SubGhzChatWorker* instance);
|
||||
|
|
|
@ -28,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;
|
||||
|
||||
|
@ -35,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_subghz.spi_bus_handle);
|
||||
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_subghz.spi_bus_handle, data[i][0], data[i][1]);
|
||||
cc1101_write_reg(spi_bus, data[i][0], data[i][1]);
|
||||
i++;
|
||||
}
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_release(spi_bus);
|
||||
}
|
||||
|
||||
// running average with adaptive coefficient
|
||||
|
@ -77,29 +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_subghz.spi_bus_handle);
|
||||
cc1101_flush_rx(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_flush_tx(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_write_reg(furi_hal_subghz.spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHW);
|
||||
cc1101_write_reg(furi_hal_subghz.spi_bus_handle, CC1101_MDMCFG3,
|
||||
//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(spi_bus, CC1101_IOCFG0, CC1101IocfgHW);
|
||||
cc1101_write_reg(spi_bus, CC1101_MDMCFG3,
|
||||
0b01111111); // symbol rate
|
||||
cc1101_write_reg(
|
||||
furi_hal_subghz.spi_bus_handle,
|
||||
spi_bus,
|
||||
CC1101_AGCCTRL2,
|
||||
0b00000111); // 00 - DVGA all; 000 - MAX LNA+LNA2; 111 - MAGN_TARGET 42 dB
|
||||
cc1101_write_reg(
|
||||
furi_hal_subghz.spi_bus_handle,
|
||||
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_subghz.spi_bus_handle,
|
||||
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_subghz.spi_bus_handle);
|
||||
furi_hal_spi_release(spi_bus);
|
||||
|
||||
furi_hal_subghz_set_path(FuriHalSubGhzPathIsolate);
|
||||
|
||||
|
@ -112,34 +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) &&
|
||||
// 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) &&
|
||||
!((furi_hal_subghz.radio_type == SubGhzRadioExternal) &&
|
||||
!((instance->ext_radio) &&
|
||||
((current_frequency == 390000000) || (current_frequency == 312000000) ||
|
||||
(current_frequency == 312100000) || (current_frequency == 312200000) ||
|
||||
(current_frequency == 440175000)))) {
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_switch_to_idle(furi_hal_subghz.spi_bus_handle);
|
||||
frequency =
|
||||
cc1101_set_frequency(furi_hal_subghz.spi_bus_handle, current_frequency);
|
||||
furi_hal_spi_acquire(spi_bus);
|
||||
cc1101_switch_to_idle(spi_bus);
|
||||
frequency = cc1101_set_frequency(spi_bus, current_frequency);
|
||||
|
||||
cc1101_calibrate(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_calibrate(spi_bus);
|
||||
do {
|
||||
status = cc1101_get_status(furi_hal_subghz.spi_bus_handle);
|
||||
status = cc1101_get_status(spi_bus);
|
||||
} while(status.STATE != CC1101StateIDLE);
|
||||
|
||||
cc1101_switch_to_rx(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
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++;
|
||||
|
@ -163,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_subghz.spi_bus_handle);
|
||||
cc1101_switch_to_idle(furi_hal_subghz.spi_bus_handle);
|
||||
frequency = cc1101_set_frequency(furi_hal_subghz.spi_bus_handle, 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_subghz.spi_bus_handle);
|
||||
cc1101_calibrate(spi_bus);
|
||||
do {
|
||||
status = cc1101_get_status(furi_hal_subghz.spi_bus_handle);
|
||||
status = cc1101_get_status(spi_bus);
|
||||
} while(status.STATE != CC1101StateIDLE);
|
||||
|
||||
cc1101_switch_to_rx(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
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);
|
||||
|
||||
|
@ -261,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;
|
||||
}
|
||||
|
@ -301,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
|
||||
*
|
||||
|
|
|
@ -32,9 +32,8 @@ float subghz_threshold_rssi_get(SubGhzThresholdRssi* instance) {
|
|||
return instance->threshold_rssi;
|
||||
}
|
||||
|
||||
SubGhzThresholdRssiData subghz_threshold_get_rssi_data(SubGhzThresholdRssi* instance) {
|
||||
SubGhzThresholdRssiData subghz_threshold_get_rssi_data(SubGhzThresholdRssi* instance, float rssi) {
|
||||
furi_assert(instance);
|
||||
float rssi = furi_hal_subghz_get_rssi();
|
||||
SubGhzThresholdRssiData ret = {.rssi = rssi, .is_above = false};
|
||||
|
||||
if(float_is_equal(instance->threshold_rssi, SUBGHZ_RAW_THRESHOLD_MIN)) {
|
||||
|
|
|
@ -38,6 +38,7 @@ float subghz_threshold_rssi_get(SubGhzThresholdRssi* instance);
|
|||
/** Check threshold
|
||||
*
|
||||
* @param instance Pointer to a SubGhzThresholdRssi
|
||||
* @param rssi Current RSSI
|
||||
* @return SubGhzThresholdRssiData
|
||||
*/
|
||||
SubGhzThresholdRssiData subghz_threshold_get_rssi_data(SubGhzThresholdRssi* instance);
|
||||
SubGhzThresholdRssiData subghz_threshold_get_rssi_data(SubGhzThresholdRssi* instance, float rssi);
|
||||
|
|
|
@ -1,9 +1,28 @@
|
|||
#include "subghz_txrx_i.h"
|
||||
|
||||
#include <lib/subghz/protocols/protocol_items.h>
|
||||
#include <applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h>
|
||||
#include <lib/subghz/devices/cc1101_int/cc1101_int_interconnect.h>
|
||||
|
||||
#include <lib/subghz/blocks/custom_btn.h>
|
||||
|
||||
#define TAG "SubGhz"
|
||||
|
||||
static void subghz_txrx_radio_device_power_on(SubGhzTxRx* instance) {
|
||||
UNUSED(instance);
|
||||
uint8_t attempts = 0;
|
||||
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
|
||||
furi_hal_power_enable_otg();
|
||||
//CC1101 power-up time
|
||||
furi_delay_ms(10);
|
||||
}
|
||||
}
|
||||
|
||||
static void subghz_txrx_radio_device_power_off(SubGhzTxRx* instance) {
|
||||
UNUSED(instance);
|
||||
if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg();
|
||||
}
|
||||
|
||||
SubGhzTxRx* subghz_txrx_alloc() {
|
||||
SubGhzTxRx* instance = malloc(sizeof(SubGhzTxRx));
|
||||
instance->setting = subghz_setting_alloc();
|
||||
|
@ -24,16 +43,15 @@ SubGhzTxRx* subghz_txrx_alloc() {
|
|||
instance->fff_data = flipper_format_string_alloc();
|
||||
|
||||
instance->environment = subghz_environment_alloc();
|
||||
instance->is_database_loaded = subghz_environment_load_keystore(
|
||||
instance->environment, EXT_PATH("subghz/assets/keeloq_mfcodes"));
|
||||
subghz_environment_load_keystore(
|
||||
instance->environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user"));
|
||||
instance->is_database_loaded =
|
||||
subghz_environment_load_keystore(instance->environment, SUBGHZ_KEYSTORE_DIR_NAME);
|
||||
subghz_environment_load_keystore(instance->environment, SUBGHZ_KEYSTORE_DIR_USER_NAME);
|
||||
subghz_environment_set_came_atomo_rainbow_table_file_name(
|
||||
instance->environment, EXT_PATH("subghz/assets/came_atomo"));
|
||||
instance->environment, SUBGHZ_CAME_ATOMO_DIR_NAME);
|
||||
subghz_environment_set_alutech_at_4n_rainbow_table_file_name(
|
||||
instance->environment, EXT_PATH("subghz/assets/alutech_at_4n"));
|
||||
instance->environment, SUBGHZ_ALUTECH_AT_4N_DIR_NAME);
|
||||
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
|
||||
instance->environment, EXT_PATH("subghz/assets/nice_flor_s"));
|
||||
instance->environment, SUBGHZ_NICE_FLOR_S_DIR_NAME);
|
||||
subghz_environment_set_protocol_registry(
|
||||
instance->environment, (void*)&subghz_protocol_registry);
|
||||
instance->receiver = subghz_receiver_alloc_init(instance->environment);
|
||||
|
@ -44,18 +62,32 @@ SubGhzTxRx* subghz_txrx_alloc() {
|
|||
instance->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode);
|
||||
subghz_worker_set_context(instance->worker, instance->receiver);
|
||||
|
||||
//set default device External
|
||||
subghz_devices_init();
|
||||
instance->radio_device_type = SubGhzRadioDeviceTypeInternal;
|
||||
instance->radio_device_type =
|
||||
subghz_txrx_radio_device_set(instance, SubGhzRadioDeviceTypeExternalCC1101);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_txrx_free(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
if(instance->radio_device_type != SubGhzRadioDeviceTypeInternal) {
|
||||
subghz_txrx_radio_device_power_off(instance);
|
||||
subghz_devices_end(instance->radio_device);
|
||||
}
|
||||
|
||||
subghz_devices_deinit();
|
||||
|
||||
subghz_worker_free(instance->worker);
|
||||
subghz_receiver_free(instance->receiver);
|
||||
subghz_environment_free(instance->environment);
|
||||
flipper_format_free(instance->fff_data);
|
||||
furi_string_free(instance->preset->name);
|
||||
subghz_setting_free(instance->setting);
|
||||
|
||||
free(instance->preset);
|
||||
free(instance);
|
||||
}
|
||||
|
@ -128,29 +160,25 @@ void subghz_txrx_get_frequency_and_modulation(
|
|||
|
||||
static void subghz_txrx_begin(SubGhzTxRx* instance, uint8_t* preset_data) {
|
||||
furi_assert(instance);
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_idle();
|
||||
furi_hal_subghz_load_custom_preset(preset_data);
|
||||
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
subghz_devices_reset(instance->radio_device);
|
||||
subghz_devices_idle(instance->radio_device);
|
||||
subghz_devices_load_preset(instance->radio_device, FuriHalSubGhzPresetCustom, preset_data);
|
||||
instance->txrx_state = SubGhzTxRxStateIDLE;
|
||||
}
|
||||
|
||||
static uint32_t subghz_txrx_rx(SubGhzTxRx* instance, uint32_t frequency) {
|
||||
furi_assert(instance);
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
furi_crash("SubGhz: Incorrect RX frequency.");
|
||||
}
|
||||
furi_assert(
|
||||
instance->txrx_state != SubGhzTxRxStateRx && instance->txrx_state != SubGhzTxRxStateSleep);
|
||||
|
||||
furi_hal_subghz_idle();
|
||||
uint32_t value = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_subghz_flush_rx();
|
||||
subghz_txrx_speaker_on(instance);
|
||||
furi_hal_subghz_rx();
|
||||
subghz_devices_idle(instance->radio_device);
|
||||
|
||||
furi_hal_subghz_start_async_rx(subghz_worker_rx_callback, instance->worker);
|
||||
uint32_t value = subghz_devices_set_frequency(instance->radio_device, frequency);
|
||||
subghz_devices_flush_rx(instance->radio_device);
|
||||
subghz_txrx_speaker_on(instance);
|
||||
|
||||
subghz_devices_start_async_rx(
|
||||
instance->radio_device, subghz_worker_rx_callback, instance->worker);
|
||||
subghz_worker_start(instance->worker);
|
||||
instance->txrx_state = SubGhzTxRxStateRx;
|
||||
return value;
|
||||
|
@ -159,7 +187,7 @@ static uint32_t subghz_txrx_rx(SubGhzTxRx* instance, uint32_t frequency) {
|
|||
static void subghz_txrx_idle(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
furi_assert(instance->txrx_state != SubGhzTxRxStateSleep);
|
||||
furi_hal_subghz_idle();
|
||||
subghz_devices_idle(instance->radio_device);
|
||||
subghz_txrx_speaker_off(instance);
|
||||
instance->txrx_state = SubGhzTxRxStateIDLE;
|
||||
}
|
||||
|
@ -170,31 +198,27 @@ static void subghz_txrx_rx_end(SubGhzTxRx* instance) {
|
|||
|
||||
if(subghz_worker_is_running(instance->worker)) {
|
||||
subghz_worker_stop(instance->worker);
|
||||
furi_hal_subghz_stop_async_rx();
|
||||
subghz_devices_stop_async_rx(instance->radio_device);
|
||||
}
|
||||
furi_hal_subghz_idle();
|
||||
subghz_devices_idle(instance->radio_device);
|
||||
subghz_txrx_speaker_off(instance);
|
||||
instance->txrx_state = SubGhzTxRxStateIDLE;
|
||||
}
|
||||
|
||||
void subghz_txrx_sleep(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
furi_hal_subghz_sleep();
|
||||
subghz_devices_sleep(instance->radio_device);
|
||||
instance->txrx_state = SubGhzTxRxStateSleep;
|
||||
}
|
||||
|
||||
static bool subghz_txrx_tx(SubGhzTxRx* instance, uint32_t frequency) {
|
||||
furi_assert(instance);
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
furi_crash("SubGhz: Incorrect TX frequency.");
|
||||
}
|
||||
furi_assert(instance->txrx_state != SubGhzTxRxStateSleep);
|
||||
furi_hal_subghz_idle();
|
||||
furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
furi_hal_gpio_write(furi_hal_subghz.cc1101_g0_pin, false);
|
||||
furi_hal_gpio_init(
|
||||
furi_hal_subghz.cc1101_g0_pin, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
bool ret = furi_hal_subghz_tx();
|
||||
|
||||
subghz_devices_idle(instance->radio_device);
|
||||
subghz_devices_set_frequency(instance->radio_device, frequency);
|
||||
|
||||
bool ret = subghz_devices_set_tx(instance->radio_device);
|
||||
if(ret) {
|
||||
subghz_txrx_speaker_on(instance);
|
||||
instance->txrx_state = SubGhzTxRxStateTx;
|
||||
|
@ -256,8 +280,8 @@ SubGhzTxRxStartTxState subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat*
|
|||
|
||||
if(ret == SubGhzTxRxStartTxStateOk) {
|
||||
//Start TX
|
||||
furi_hal_subghz_start_async_tx(
|
||||
subghz_transmitter_yield, instance->transmitter);
|
||||
subghz_devices_start_async_tx(
|
||||
instance->radio_device, subghz_transmitter_yield, instance->transmitter);
|
||||
}
|
||||
} else {
|
||||
ret = SubGhzTxRxStartTxStateErrorParserOthers;
|
||||
|
@ -300,7 +324,7 @@ static void subghz_txrx_tx_stop(SubGhzTxRx* instance) {
|
|||
furi_assert(instance);
|
||||
furi_assert(instance->txrx_state == SubGhzTxRxStateTx);
|
||||
//Stop TX
|
||||
furi_hal_subghz_stop_async_tx();
|
||||
subghz_devices_stop_async_tx(instance->radio_device);
|
||||
subghz_transmitter_stop(instance->transmitter);
|
||||
subghz_transmitter_free(instance->transmitter);
|
||||
|
||||
|
@ -313,7 +337,6 @@ static void subghz_txrx_tx_stop(SubGhzTxRx* instance) {
|
|||
subghz_txrx_idle(instance);
|
||||
subghz_txrx_speaker_off(instance);
|
||||
//Todo: Show message
|
||||
// notification_message(notifications, &sequence_reset_red);
|
||||
}
|
||||
|
||||
FlipperFormat* subghz_txrx_get_fff_data(SubGhzTxRx* instance) {
|
||||
|
@ -363,7 +386,7 @@ void subghz_txrx_hopper_update(SubGhzTxRx* instance) {
|
|||
float rssi = -127.0f;
|
||||
if(instance->hopper_state != SubGhzHopperStateRSSITimeOut) {
|
||||
// See RSSI Calculation timings in CC1101 17.3 RSSI
|
||||
rssi = furi_hal_subghz_get_rssi();
|
||||
rssi = subghz_devices_get_rssi(instance->radio_device);
|
||||
|
||||
// Stay if RSSI is high enough
|
||||
if(rssi > -90.0f) {
|
||||
|
@ -420,13 +443,13 @@ void subghz_txrx_hopper_pause(SubGhzTxRx* instance) {
|
|||
void subghz_txrx_speaker_on(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
if(instance->debug_pin_state) {
|
||||
furi_hal_subghz_set_async_mirror_pin(&gpio_ibutton);
|
||||
subghz_devices_set_async_mirror_pin(instance->radio_device, &gpio_ibutton);
|
||||
}
|
||||
|
||||
if(instance->speaker_state == SubGhzSpeakerStateEnable) {
|
||||
if(furi_hal_speaker_acquire(30)) {
|
||||
if(!instance->debug_pin_state) {
|
||||
furi_hal_subghz_set_async_mirror_pin(&gpio_speaker);
|
||||
subghz_devices_set_async_mirror_pin(instance->radio_device, &gpio_speaker);
|
||||
}
|
||||
} else {
|
||||
instance->speaker_state = SubGhzSpeakerStateDisable;
|
||||
|
@ -437,12 +460,12 @@ void subghz_txrx_speaker_on(SubGhzTxRx* instance) {
|
|||
void subghz_txrx_speaker_off(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
if(instance->debug_pin_state) {
|
||||
furi_hal_subghz_set_async_mirror_pin(NULL);
|
||||
subghz_devices_set_async_mirror_pin(instance->radio_device, NULL);
|
||||
}
|
||||
if(instance->speaker_state != SubGhzSpeakerStateDisable) {
|
||||
if(furi_hal_speaker_is_mine()) {
|
||||
if(!instance->debug_pin_state) {
|
||||
furi_hal_subghz_set_async_mirror_pin(NULL);
|
||||
subghz_devices_set_async_mirror_pin(instance->radio_device, NULL);
|
||||
}
|
||||
furi_hal_speaker_release();
|
||||
if(instance->speaker_state == SubGhzSpeakerStateShutdown)
|
||||
|
@ -454,12 +477,12 @@ void subghz_txrx_speaker_off(SubGhzTxRx* instance) {
|
|||
void subghz_txrx_speaker_mute(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
if(instance->debug_pin_state) {
|
||||
furi_hal_subghz_set_async_mirror_pin(NULL);
|
||||
subghz_devices_set_async_mirror_pin(instance->radio_device, NULL);
|
||||
}
|
||||
if(instance->speaker_state == SubGhzSpeakerStateEnable) {
|
||||
if(furi_hal_speaker_is_mine()) {
|
||||
if(!instance->debug_pin_state) {
|
||||
furi_hal_subghz_set_async_mirror_pin(NULL);
|
||||
subghz_devices_set_async_mirror_pin(instance->radio_device, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -468,12 +491,12 @@ void subghz_txrx_speaker_mute(SubGhzTxRx* instance) {
|
|||
void subghz_txrx_speaker_unmute(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
if(instance->debug_pin_state) {
|
||||
furi_hal_subghz_set_async_mirror_pin(&gpio_ibutton);
|
||||
subghz_devices_set_async_mirror_pin(instance->radio_device, &gpio_ibutton);
|
||||
}
|
||||
if(instance->speaker_state == SubGhzSpeakerStateEnable) {
|
||||
if(furi_hal_speaker_is_mine()) {
|
||||
if(!instance->debug_pin_state) {
|
||||
furi_hal_subghz_set_async_mirror_pin(&gpio_speaker);
|
||||
subghz_devices_set_async_mirror_pin(instance->radio_device, &gpio_speaker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -548,6 +571,82 @@ void subghz_txrx_set_raw_file_encoder_worker_callback_end(
|
|||
context);
|
||||
}
|
||||
|
||||
bool subghz_txrx_radio_device_is_external_connected(SubGhzTxRx* instance, const char* name) {
|
||||
furi_assert(instance);
|
||||
|
||||
bool is_connect = false;
|
||||
bool is_otg_enabled = furi_hal_power_is_otg_enabled();
|
||||
|
||||
if(!is_otg_enabled) {
|
||||
subghz_txrx_radio_device_power_on(instance);
|
||||
}
|
||||
|
||||
const SubGhzDevice* device = subghz_devices_get_by_name(name);
|
||||
if(device) {
|
||||
is_connect = subghz_devices_is_connect(device);
|
||||
}
|
||||
|
||||
if(!is_otg_enabled) {
|
||||
subghz_txrx_radio_device_power_off(instance);
|
||||
}
|
||||
return is_connect;
|
||||
}
|
||||
|
||||
SubGhzRadioDeviceType
|
||||
subghz_txrx_radio_device_set(SubGhzTxRx* instance, SubGhzRadioDeviceType radio_device_type) {
|
||||
furi_assert(instance);
|
||||
|
||||
if(radio_device_type == SubGhzRadioDeviceTypeExternalCC1101 &&
|
||||
subghz_txrx_radio_device_is_external_connected(instance, SUBGHZ_DEVICE_CC1101_EXT_NAME)) {
|
||||
subghz_txrx_radio_device_power_on(instance);
|
||||
instance->radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_EXT_NAME);
|
||||
subghz_devices_begin(instance->radio_device);
|
||||
instance->radio_device_type = SubGhzRadioDeviceTypeExternalCC1101;
|
||||
} else {
|
||||
subghz_txrx_radio_device_power_off(instance);
|
||||
if(instance->radio_device_type != SubGhzRadioDeviceTypeInternal) {
|
||||
subghz_devices_end(instance->radio_device);
|
||||
}
|
||||
instance->radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME);
|
||||
instance->radio_device_type = SubGhzRadioDeviceTypeInternal;
|
||||
}
|
||||
|
||||
return instance->radio_device_type;
|
||||
}
|
||||
|
||||
SubGhzRadioDeviceType subghz_txrx_radio_device_get(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->radio_device_type;
|
||||
}
|
||||
|
||||
float subghz_txrx_radio_device_get_rssi(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
return subghz_devices_get_rssi(instance->radio_device);
|
||||
}
|
||||
|
||||
const char* subghz_txrx_radio_device_get_name(SubGhzTxRx* instance) {
|
||||
furi_assert(instance);
|
||||
return subghz_devices_get_name(instance->radio_device);
|
||||
}
|
||||
|
||||
bool subghz_txrx_radio_device_is_frequecy_valid(SubGhzTxRx* instance, uint32_t frequency) {
|
||||
furi_assert(instance);
|
||||
return subghz_devices_is_frequency_valid(instance->radio_device, frequency);
|
||||
}
|
||||
|
||||
bool subghz_txrx_radio_device_is_tx_alowed(SubGhzTxRx* instance, uint32_t frequency) {
|
||||
furi_assert(instance);
|
||||
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;
|
||||
}
|
||||
|
||||
void subghz_txrx_set_debug_pin_state(SubGhzTxRx* instance, bool state) {
|
||||
furi_assert(instance);
|
||||
instance->debug_pin_state = state;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <lib/subghz/receiver.h>
|
||||
#include <lib/subghz/transmitter.h>
|
||||
#include <lib/subghz/protocols/raw.h>
|
||||
#include <lib/subghz/devices/devices.h>
|
||||
|
||||
typedef struct SubGhzTxRx SubGhzTxRx;
|
||||
|
||||
|
@ -290,6 +291,53 @@ void subghz_txrx_set_raw_file_encoder_worker_callback_end(
|
|||
SubGhzProtocolEncoderRAWCallbackEnd callback,
|
||||
void* context);
|
||||
|
||||
/* Checking if an external radio device is connected
|
||||
*
|
||||
* @param instance Pointer to a SubGhzTxRx
|
||||
* @param name Name of external radio device
|
||||
* @return bool True if is connected to the external radio device
|
||||
*/
|
||||
bool subghz_txrx_radio_device_is_external_connected(SubGhzTxRx* instance, const char* name);
|
||||
|
||||
/* Set the selected radio device to use
|
||||
*
|
||||
* @param instance Pointer to a SubGhzTxRx
|
||||
* @param radio_device_type Radio device type
|
||||
* @return SubGhzRadioDeviceType Type of installed radio device
|
||||
*/
|
||||
SubGhzRadioDeviceType
|
||||
subghz_txrx_radio_device_set(SubGhzTxRx* instance, SubGhzRadioDeviceType radio_device_type);
|
||||
|
||||
/* Get the selected radio device to use
|
||||
*
|
||||
* @param instance Pointer to a SubGhzTxRx
|
||||
* @return SubGhzRadioDeviceType Type of installed radio device
|
||||
*/
|
||||
SubGhzRadioDeviceType subghz_txrx_radio_device_get(SubGhzTxRx* instance);
|
||||
|
||||
/* Get RSSI the selected radio device to use
|
||||
*
|
||||
* @param instance Pointer to a SubGhzTxRx
|
||||
* @return float RSSI
|
||||
*/
|
||||
float subghz_txrx_radio_device_get_rssi(SubGhzTxRx* instance);
|
||||
|
||||
/* Get name the selected radio device to use
|
||||
*
|
||||
* @param instance Pointer to a SubGhzTxRx
|
||||
* @return const char* Name of installed radio device
|
||||
*/
|
||||
const char* subghz_txrx_radio_device_get_name(SubGhzTxRx* instance);
|
||||
|
||||
/* Get get intelligence whether frequency the selected radio device to use
|
||||
*
|
||||
* @param instance Pointer to a SubGhzTxRx
|
||||
* @return bool True if the frequency is valid
|
||||
*/
|
||||
bool subghz_txrx_radio_device_is_frequecy_valid(SubGhzTxRx* instance, uint32_t frequency);
|
||||
|
||||
bool subghz_txrx_radio_device_is_tx_alowed(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);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "subghz_txrx.h"
|
||||
|
||||
struct SubGhzTxRx {
|
||||
|
@ -21,9 +21,11 @@ struct SubGhzTxRx {
|
|||
|
||||
SubGhzTxRxState txrx_state;
|
||||
SubGhzSpeakerState speaker_state;
|
||||
const SubGhzDevice* radio_device;
|
||||
SubGhzRadioDeviceType radio_device_type;
|
||||
|
||||
SubGhzTxRxNeedSaveCallback need_save_callback;
|
||||
void* need_save_context;
|
||||
|
||||
bool debug_pin_state;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -35,6 +35,13 @@ typedef enum {
|
|||
SubGhzSpeakerStateEnable,
|
||||
} SubGhzSpeakerState;
|
||||
|
||||
/** SubGhzRadioDeviceType */
|
||||
typedef enum {
|
||||
SubGhzRadioDeviceTypeAuto,
|
||||
SubGhzRadioDeviceTypeInternal,
|
||||
SubGhzRadioDeviceTypeExternalCC1101,
|
||||
} SubGhzRadioDeviceType;
|
||||
|
||||
/** SubGhzRxKeyState state */
|
||||
typedef enum {
|
||||
SubGhzRxKeyStateIDLE,
|
||||
|
@ -54,6 +61,7 @@ typedef enum {
|
|||
SubGhzLoadKeyStateOK,
|
||||
SubGhzLoadKeyStateParseErr,
|
||||
SubGhzLoadKeyStateOnlyRx,
|
||||
SubGhzLoadKeyStateUnsuportedFreq,
|
||||
SubGhzLoadKeyStateProtocolDescriptionErr,
|
||||
} SubGhzLoadKeyState;
|
||||
|
||||
|
|
|
@ -93,7 +93,9 @@ bool subghz_scene_decode_raw_start(SubGhz* subghz) {
|
|||
|
||||
subghz->decode_raw_file_worker_encoder = subghz_file_encoder_worker_alloc();
|
||||
if(subghz_file_encoder_worker_start(
|
||||
subghz->decode_raw_file_worker_encoder, furi_string_get_cstr(file_name))) {
|
||||
subghz->decode_raw_file_worker_encoder,
|
||||
furi_string_get_cstr(file_name),
|
||||
subghz_txrx_radio_device_get_name(subghz->txrx))) {
|
||||
//the worker needs a file in order to open and read part of the file
|
||||
furi_delay_ms(100);
|
||||
} else {
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
#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[] = {
|
||||
#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
|
||||
|
@ -35,19 +36,18 @@ const char* const debug_counter_text[DEBUG_COUNTER_COUNT] = {
|
|||
"+10",
|
||||
};
|
||||
|
||||
static void subghz_scene_ext_module_changed(VariableItem* item) {
|
||||
static void subghz_scene_radio_settings_set_device(VariableItem* item) {
|
||||
SubGhz* subghz = variable_item_get_context(item);
|
||||
uint8_t value_index_exm = variable_item_get_current_value_index(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) {
|
||||
|
@ -88,22 +88,22 @@ static void subghz_scene_receiver_config_set_debug_counter(VariableItem* item) {
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
// 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]);
|
||||
// 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();
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
// subghz->last_settings->external_module_power_5v_disable = index == 1;
|
||||
// subghz_last_settings_save(subghz->last_settings);
|
||||
// }
|
||||
|
||||
static void subghz_scene_receiver_config_set_timestamp_file_names(VariableItem* item) {
|
||||
SubGhz* subghz = variable_item_get_context(item);
|
||||
|
@ -120,29 +120,25 @@ void subghz_scene_radio_settings_on_enter(void* context) {
|
|||
|
||||
VariableItemList* variable_item_list = subghz->variable_item_list;
|
||||
uint8_t value_index;
|
||||
VariableItem* item;
|
||||
|
||||
value_index = furi_hal_subghz.radio_type;
|
||||
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);
|
||||
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, radio_modules_variables_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,
|
||||
"Ext Radio 5v",
|
||||
EXT_MOD_POWER_COUNT,
|
||||
subghz_scene_receiver_config_set_ext_mod_power,
|
||||
"Module",
|
||||
value_count_device,
|
||||
subghz_scene_radio_settings_set_device,
|
||||
subghz);
|
||||
value_index = furi_hal_subghz_get_external_power_disable();
|
||||
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, ext_mod_power_text[value_index]);
|
||||
variable_item_set_current_value_text(item, radio_device_text[value_index]);
|
||||
|
||||
item = variable_item_list_add(
|
||||
subghz->variable_item_list,
|
||||
variable_item_list,
|
||||
"Time in names",
|
||||
TIMESTAMP_NAMES_COUNT,
|
||||
subghz_scene_receiver_config_set_timestamp_file_names,
|
||||
|
@ -153,7 +149,7 @@ void subghz_scene_radio_settings_on_enter(void* context) {
|
|||
|
||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
||||
item = variable_item_list_add(
|
||||
subghz->variable_item_list,
|
||||
variable_item_list,
|
||||
"Counter incr.",
|
||||
DEBUG_COUNTER_COUNT,
|
||||
subghz_scene_receiver_config_set_debug_counter,
|
||||
|
@ -182,7 +178,7 @@ void subghz_scene_radio_settings_on_enter(void* context) {
|
|||
}
|
||||
} else {
|
||||
item = variable_item_list_add(
|
||||
subghz->variable_item_list,
|
||||
variable_item_list,
|
||||
"Counter incr.",
|
||||
3,
|
||||
subghz_scene_receiver_config_set_debug_counter,
|
||||
|
@ -209,7 +205,7 @@ void subghz_scene_radio_settings_on_enter(void* context) {
|
|||
|
||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
||||
item = variable_item_list_add(
|
||||
subghz->variable_item_list,
|
||||
variable_item_list,
|
||||
"Debug Pin",
|
||||
DEBUG_P_COUNT,
|
||||
subghz_scene_receiver_config_set_debug_pin,
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -52,6 +52,9 @@ static void subghz_scene_read_raw_update_statusbar(void* context) {
|
|||
|
||||
furi_string_free(frequency_str);
|
||||
furi_string_free(modulation_str);
|
||||
|
||||
subghz_read_raw_set_radio_device_type(
|
||||
subghz->subghz_read_raw, subghz_txrx_radio_device_get(subghz->txrx));
|
||||
}
|
||||
|
||||
void subghz_scene_read_raw_callback(SubGhzCustomEvent event, void* context) {
|
||||
|
@ -247,7 +250,9 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
|
|||
furi_string_printf(
|
||||
temp_str, "%s/%s%s", SUBGHZ_RAW_FOLDER, RAW_FILE_NAME, SUBGHZ_APP_EXTENSION);
|
||||
subghz_protocol_raw_gen_fff_data(
|
||||
subghz_txrx_get_fff_data(subghz->txrx), furi_string_get_cstr(temp_str));
|
||||
subghz_txrx_get_fff_data(subghz->txrx),
|
||||
furi_string_get_cstr(temp_str),
|
||||
subghz_txrx_radio_device_get_name(subghz->txrx));
|
||||
furi_string_free(temp_str);
|
||||
|
||||
if(spl_count > 0) {
|
||||
|
@ -307,8 +312,8 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
|
|||
subghz_read_raw_update_sample_write(
|
||||
subghz->subghz_read_raw, subghz_protocol_raw_get_sample_write(decoder_raw));
|
||||
|
||||
SubGhzThresholdRssiData ret_rssi =
|
||||
subghz_threshold_get_rssi_data(subghz->threshold_rssi);
|
||||
SubGhzThresholdRssiData ret_rssi = subghz_threshold_get_rssi_data(
|
||||
subghz->threshold_rssi, subghz_txrx_radio_device_get_rssi(subghz->txrx));
|
||||
subghz_read_raw_add_data_rssi(
|
||||
subghz->subghz_read_raw, ret_rssi.rssi, ret_rssi.is_above);
|
||||
subghz_protocol_raw_save_to_file_pause(decoder_raw, !ret_rssi.is_above);
|
||||
|
|
|
@ -55,7 +55,9 @@ static void subghz_scene_receiver_update_statusbar(void* context) {
|
|||
furi_string_printf(
|
||||
modulation_str,
|
||||
"%s Mod: %s",
|
||||
furi_hal_subghz_get_radio_type() ? "Ext" : "Int",
|
||||
(subghz_txrx_radio_device_get(subghz->txrx) == SubGhzRadioDeviceTypeInternal) ?
|
||||
"Int" :
|
||||
"Ext",
|
||||
furi_string_get_cstr(temp_str));
|
||||
furi_string_free(temp_str);
|
||||
}
|
||||
|
@ -78,6 +80,9 @@ static void subghz_scene_receiver_update_statusbar(void* context) {
|
|||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
}
|
||||
furi_string_free(history_stat_str);
|
||||
|
||||
subghz_view_receiver_set_radio_device_type(
|
||||
subghz->subghz_receiver, subghz_txrx_radio_device_get(subghz->txrx));
|
||||
}
|
||||
|
||||
void subghz_scene_receiver_callback(SubGhzCustomEvent event, void* context) {
|
||||
|
@ -253,8 +258,8 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
|
|||
subghz_scene_receiver_update_statusbar(subghz);
|
||||
}
|
||||
|
||||
//get RSSI
|
||||
SubGhzThresholdRssiData ret_rssi = subghz_threshold_get_rssi_data(subghz->threshold_rssi);
|
||||
SubGhzThresholdRssiData ret_rssi = subghz_threshold_get_rssi_data(
|
||||
subghz->threshold_rssi, subghz_txrx_radio_device_get_rssi(subghz->txrx));
|
||||
|
||||
subghz_receiver_rssi(subghz->subghz_receiver, ret_rssi.rssi);
|
||||
subghz_protocol_decoder_bin_raw_data_input_rssi(
|
||||
|
|
|
@ -165,7 +165,8 @@ bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) {
|
|||
SubGhzCustomEventManagerNoSet) {
|
||||
subghz_protocol_raw_gen_fff_data(
|
||||
subghz_txrx_get_fff_data(subghz->txrx),
|
||||
furi_string_get_cstr(subghz->file_path));
|
||||
furi_string_get_cstr(subghz->file_path),
|
||||
subghz_txrx_radio_device_get_name(subghz->txrx));
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet);
|
||||
} else {
|
||||
|
|
|
@ -10,6 +10,7 @@ enum SubmenuIndex {
|
|||
SubmenuIndexFrequencyAnalyzer,
|
||||
SubmenuIndexReadRAW,
|
||||
SubmenuIndexExtSettings,
|
||||
SubmenuIndexRadioSetting,
|
||||
};
|
||||
|
||||
void subghz_scene_start_submenu_callback(void* context, uint32_t index) {
|
||||
|
@ -65,49 +66,38 @@ bool subghz_scene_start_on_event(void* context, SceneManagerEvent event) {
|
|||
view_dispatcher_stop(subghz->view_dispatcher);
|
||||
return true;
|
||||
} else if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubmenuIndexExtSettings) {
|
||||
if(event.event == SubmenuIndexReadRAW) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexExtSettings);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneExtModuleSettings);
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexReadRAW);
|
||||
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexRead) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexRead);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiver);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexSaved) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexSaved);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaved);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexAddManually) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexAddManually);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetType);
|
||||
return true;
|
||||
} else {
|
||||
furi_hal_subghz_enable_ext_power();
|
||||
|
||||
if(!furi_hal_subghz_check_radio()) {
|
||||
furi_hal_subghz_select_radio_type(SubGhzRadioInternal);
|
||||
furi_hal_subghz_init_radio_type(SubGhzRadioInternal);
|
||||
subghz->last_settings->external_module_enabled = false;
|
||||
furi_string_set(subghz->error_str, "Please connect\nexternal radio");
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowErrorSub);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexReadRAW) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexReadRAW);
|
||||
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexRead) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexRead);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiver);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexSaved) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexSaved);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaved);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexFrequencyAnalyzer) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexFrequencyAnalyzer);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneFrequencyAnalyzer);
|
||||
dolphin_deed(DolphinDeedSubGhzFrequencyAnalyzer);
|
||||
return true;
|
||||
}
|
||||
} else if(event.event == SubmenuIndexFrequencyAnalyzer) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexFrequencyAnalyzer);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneFrequencyAnalyzer);
|
||||
dolphin_deed(DolphinDeedSubGhzFrequencyAnalyzer);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexExtSettings) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexExtSettings);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneExtModuleSettings);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -38,6 +38,8 @@ bool subghz_scene_transmitter_update_data_show(void* context) {
|
|||
furi_string_free(modulation_str);
|
||||
furi_string_free(key_str);
|
||||
}
|
||||
subghz_view_transmitter_set_radio_device_type(
|
||||
subghz->subghz_transmitter, subghz_txrx_radio_device_get(subghz->txrx));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
@ -186,8 +189,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);
|
||||
|
@ -342,15 +343,6 @@ int32_t subghz_app(void* p) {
|
|||
subghz->raw_send_only = false;
|
||||
}
|
||||
|
||||
// Call enable power for external module
|
||||
furi_hal_subghz_enable_ext_power();
|
||||
|
||||
// Auto switch to internal radio if external radio is not available
|
||||
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);
|
||||
}
|
||||
// Check argument and run corresponding scene
|
||||
if(p && strlen(p)) {
|
||||
uint32_t rpc_ctx = 0;
|
||||
|
@ -403,10 +395,6 @@ int32_t subghz_app(void* p) {
|
|||
view_dispatcher_run(subghz->view_dispatcher);
|
||||
|
||||
furi_hal_power_suppress_charge_exit();
|
||||
// Disable power for External CC1101 if it was enabled and module is connected
|
||||
furi_hal_subghz_disable_ext_power();
|
||||
// Reinit SPI handles for internal radio / nfc
|
||||
furi_hal_subghz_init_radio_type(SubGhzRadioInternal);
|
||||
|
||||
subghz_free(subghz, alloc_for_tx);
|
||||
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
#include <lib/subghz/transmitter.h>
|
||||
#include <lib/subghz/subghz_file_encoder_worker.h>
|
||||
#include <lib/subghz/protocols/protocol_items.h>
|
||||
#include <applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h>
|
||||
#include <lib/subghz/devices/cc1101_int/cc1101_int_interconnect.h>
|
||||
#include <lib/subghz/devices/devices.h>
|
||||
#include <lib/subghz/devices/cc1101_configs.h>
|
||||
|
||||
#include "helpers/subghz_chat.h"
|
||||
|
||||
|
@ -19,6 +23,24 @@
|
|||
#define SUBGHZ_FREQUENCY_RANGE_STR \
|
||||
"299999755...348000000 or 386999938...464000000 or 778999847...928000000"
|
||||
|
||||
// Tx/Rx Carrier | only internal module
|
||||
// Tx/Rx command | both
|
||||
// Rx RAW | only internal module
|
||||
// Chat | both
|
||||
|
||||
static void subghz_cli_radio_device_power_on() {
|
||||
uint8_t attempts = 0;
|
||||
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
|
||||
furi_hal_power_enable_otg();
|
||||
//CC1101 power-up time
|
||||
furi_delay_ms(10);
|
||||
}
|
||||
}
|
||||
|
||||
static void subghz_cli_radio_device_power_off() {
|
||||
if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg();
|
||||
}
|
||||
|
||||
void subghz_cli_command_tx_carrier(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(context);
|
||||
uint32_t frequency = 433920000;
|
||||
|
@ -39,12 +61,11 @@ void subghz_cli_command_tx_carrier(Cli* cli, FuriString* args, void* context) {
|
|||
}
|
||||
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_ook_650khz_async_regs);
|
||||
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
|
||||
furi_hal_gpio_init(
|
||||
furi_hal_subghz.cc1101_g0_pin, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_write(furi_hal_subghz.cc1101_g0_pin, true);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_write(&gpio_cc1101_g0, true);
|
||||
|
||||
furi_hal_power_suppress_charge_enter();
|
||||
|
||||
|
@ -84,7 +105,7 @@ void subghz_cli_command_rx_carrier(Cli* cli, FuriString* args, void* context) {
|
|||
}
|
||||
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_ook_650khz_async_regs);
|
||||
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
printf("Receiving at frequency %lu Hz\r\n", frequency);
|
||||
printf("Press CTRL+C to stop\r\n");
|
||||
|
@ -105,44 +126,70 @@ void subghz_cli_command_rx_carrier(Cli* cli, FuriString* args, void* context) {
|
|||
furi_hal_subghz_sleep();
|
||||
}
|
||||
|
||||
static const SubGhzDevice* subghz_cli_command_get_device(uint32_t device_ind) {
|
||||
const SubGhzDevice* device = NULL;
|
||||
switch(device_ind) {
|
||||
case 1:
|
||||
subghz_cli_radio_device_power_on();
|
||||
device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_EXT_NAME);
|
||||
break;
|
||||
|
||||
default:
|
||||
device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME);
|
||||
break;
|
||||
}
|
||||
return device;
|
||||
}
|
||||
|
||||
void subghz_cli_command_tx(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(context);
|
||||
uint32_t frequency = 433920000;
|
||||
uint32_t key = 0x0074BADE;
|
||||
uint32_t repeat = 10;
|
||||
uint32_t te = 403;
|
||||
uint32_t device_ind = 0; // 0 - CC1101_INT, 1 - CC1101_EXT
|
||||
|
||||
if(furi_string_size(args)) {
|
||||
int ret =
|
||||
sscanf(furi_string_get_cstr(args), "%lx %lu %lu %lu", &key, &frequency, &te, &repeat);
|
||||
if(ret != 4) {
|
||||
int ret = sscanf(
|
||||
furi_string_get_cstr(args),
|
||||
"%lx %lu %lu %lu %lu",
|
||||
&key,
|
||||
&frequency,
|
||||
&te,
|
||||
&repeat,
|
||||
&device_ind);
|
||||
if(ret != 5) {
|
||||
printf(
|
||||
"sscanf returned %d, key: %lx, frequency: %lu, te:%lu, repeat: %lu\r\n",
|
||||
"sscanf returned %d, key: %lx, frequency: %lu, te: %lu, repeat: %lu, device: %lu\r\n ",
|
||||
ret,
|
||||
key,
|
||||
frequency,
|
||||
te,
|
||||
repeat);
|
||||
repeat,
|
||||
device_ind);
|
||||
cli_print_usage(
|
||||
"subghz tx",
|
||||
"<3 Byte Key: in hex> <Frequency: in Hz> <Te us> <Repeat count>",
|
||||
"<3 Byte Key: in hex> <Frequency: in Hz> <Te us> <Repeat count> <Device: 0 - CC1101_INT, 1 - CC1101_EXT>",
|
||||
furi_string_get_cstr(args));
|
||||
return;
|
||||
}
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
printf(
|
||||
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
||||
frequency);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
subghz_devices_init();
|
||||
const SubGhzDevice* device = subghz_cli_command_get_device(device_ind);
|
||||
if(!subghz_devices_is_frequency_valid(device, frequency)) {
|
||||
printf(
|
||||
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n", frequency);
|
||||
subghz_devices_deinit();
|
||||
subghz_cli_radio_device_power_off();
|
||||
return;
|
||||
}
|
||||
printf(
|
||||
"Transmitting at %lu, key %lx, te %lu, repeat %lu. Press CTRL+C to stop\r\n",
|
||||
"Transmitting at %lu, key %lx, te %lu, repeat %lu device %lu. Press CTRL+C to stop\r\n",
|
||||
frequency,
|
||||
key,
|
||||
te,
|
||||
repeat);
|
||||
repeat,
|
||||
device_ind);
|
||||
|
||||
FuriString* flipper_format_string = furi_string_alloc_printf(
|
||||
"Protocol: Princeton\n"
|
||||
|
@ -166,25 +213,29 @@ void subghz_cli_command_tx(Cli* cli, FuriString* args, void* context) {
|
|||
SubGhzTransmitter* transmitter = subghz_transmitter_alloc_init(environment, "Princeton");
|
||||
subghz_transmitter_deserialize(transmitter, flipper_format);
|
||||
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
subghz_devices_begin(device);
|
||||
subghz_devices_reset(device);
|
||||
subghz_devices_load_preset(device, FuriHalSubGhzPresetOok650Async, NULL);
|
||||
frequency = subghz_devices_set_frequency(device, frequency);
|
||||
|
||||
furi_hal_power_suppress_charge_enter();
|
||||
|
||||
if(furi_hal_subghz_start_async_tx(subghz_transmitter_yield, transmitter)) {
|
||||
while(!(furi_hal_subghz_is_async_tx_complete() || cli_cmd_interrupt_received(cli))) {
|
||||
if(subghz_devices_start_async_tx(device, subghz_transmitter_yield, transmitter)) {
|
||||
while(!(subghz_devices_is_async_complete_tx(device) || cli_cmd_interrupt_received(cli))) {
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
furi_delay_ms(333);
|
||||
}
|
||||
furi_hal_subghz_stop_async_tx();
|
||||
subghz_devices_stop_async_tx(device);
|
||||
|
||||
} else {
|
||||
printf("Transmission on this frequency is restricted in your region\r\n");
|
||||
printf("Frequency is outside of default range. Check docs.\r\n");
|
||||
}
|
||||
|
||||
furi_hal_subghz_sleep();
|
||||
subghz_devices_sleep(device);
|
||||
subghz_devices_end(device);
|
||||
subghz_devices_deinit();
|
||||
subghz_cli_radio_device_power_off();
|
||||
|
||||
furi_hal_power_suppress_charge_exit();
|
||||
|
||||
flipper_format_free(flipper_format);
|
||||
|
@ -228,21 +279,29 @@ static void subghz_cli_command_rx_callback(
|
|||
void subghz_cli_command_rx(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(context);
|
||||
uint32_t frequency = 433920000;
|
||||
uint32_t device_ind = 0; // 0 - CC1101_INT, 1 - CC1101_EXT
|
||||
|
||||
if(furi_string_size(args)) {
|
||||
int ret = sscanf(furi_string_get_cstr(args), "%lu", &frequency);
|
||||
if(ret != 1) {
|
||||
printf("sscanf returned %d, frequency: %lu\r\n", ret, frequency);
|
||||
cli_print_usage("subghz rx", "<Frequency: in Hz>", furi_string_get_cstr(args));
|
||||
return;
|
||||
}
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
int ret = sscanf(furi_string_get_cstr(args), "%lu %lu", &frequency, &device_ind);
|
||||
if(ret != 2) {
|
||||
printf(
|
||||
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
||||
frequency);
|
||||
"sscanf returned %d, frequency: %lu device: %lu\r\n", ret, frequency, device_ind);
|
||||
cli_print_usage(
|
||||
"subghz rx",
|
||||
"<Frequency: in Hz> <Device: 0 - CC1101_INT, 1 - CC1101_EXT>",
|
||||
furi_string_get_cstr(args));
|
||||
return;
|
||||
}
|
||||
}
|
||||
subghz_devices_init();
|
||||
const SubGhzDevice* device = subghz_cli_command_get_device(device_ind);
|
||||
if(!subghz_devices_is_frequency_valid(device, frequency)) {
|
||||
printf(
|
||||
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n", frequency);
|
||||
subghz_devices_deinit();
|
||||
subghz_cli_radio_device_power_off();
|
||||
return;
|
||||
}
|
||||
|
||||
// Allocate context and buffers
|
||||
SubGhzCliCommandRx* instance = malloc(sizeof(SubGhzCliCommandRx));
|
||||
|
@ -251,14 +310,14 @@ void subghz_cli_command_rx(Cli* cli, FuriString* args, void* context) {
|
|||
furi_check(instance->stream);
|
||||
|
||||
SubGhzEnvironment* environment = subghz_environment_alloc();
|
||||
subghz_environment_load_keystore(environment, EXT_PATH("subghz/assets/keeloq_mfcodes"));
|
||||
subghz_environment_load_keystore(environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user"));
|
||||
subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_NAME);
|
||||
subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_USER_NAME);
|
||||
subghz_environment_set_came_atomo_rainbow_table_file_name(
|
||||
environment, EXT_PATH("subghz/assets/came_atomo"));
|
||||
environment, SUBGHZ_CAME_ATOMO_DIR_NAME);
|
||||
subghz_environment_set_alutech_at_4n_rainbow_table_file_name(
|
||||
environment, EXT_PATH("subghz/assets/alutech_at_4n"));
|
||||
environment, SUBGHZ_ALUTECH_AT_4N_DIR_NAME);
|
||||
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
|
||||
environment, EXT_PATH("subghz/assets/nice_flor_s"));
|
||||
environment, SUBGHZ_NICE_FLOR_S_DIR_NAME);
|
||||
subghz_environment_set_protocol_registry(environment, (void*)&subghz_protocol_registry);
|
||||
|
||||
SubGhzReceiver* receiver = subghz_receiver_alloc_init(environment);
|
||||
|
@ -266,18 +325,21 @@ void subghz_cli_command_rx(Cli* cli, FuriString* args, void* context) {
|
|||
subghz_receiver_set_rx_callback(receiver, subghz_cli_command_rx_callback, instance);
|
||||
|
||||
// Configure radio
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
subghz_devices_begin(device);
|
||||
subghz_devices_reset(device);
|
||||
subghz_devices_load_preset(device, FuriHalSubGhzPresetOok650Async, NULL);
|
||||
frequency = subghz_devices_set_frequency(device, frequency);
|
||||
|
||||
furi_hal_power_suppress_charge_enter();
|
||||
|
||||
// Prepare and start RX
|
||||
furi_hal_subghz_start_async_rx(subghz_cli_command_rx_capture_callback, instance);
|
||||
subghz_devices_start_async_rx(device, subghz_cli_command_rx_capture_callback, instance);
|
||||
|
||||
// Wait for packets to arrive
|
||||
printf("Listening at %lu. Press CTRL+C to stop\r\n", frequency);
|
||||
printf(
|
||||
"Listening at frequency: %lu device: %lu. Press CTRL+C to stop\r\n",
|
||||
frequency,
|
||||
device_ind);
|
||||
LevelDuration level_duration;
|
||||
while(!cli_cmd_interrupt_received(cli)) {
|
||||
int ret = furi_stream_buffer_receive(
|
||||
|
@ -295,8 +357,11 @@ void subghz_cli_command_rx(Cli* cli, FuriString* args, void* context) {
|
|||
}
|
||||
|
||||
// Shutdown radio
|
||||
furi_hal_subghz_stop_async_rx();
|
||||
furi_hal_subghz_sleep();
|
||||
subghz_devices_stop_async_rx(device);
|
||||
subghz_devices_sleep(device);
|
||||
subghz_devices_end(device);
|
||||
subghz_devices_deinit();
|
||||
subghz_cli_radio_device_power_off();
|
||||
|
||||
furi_hal_power_suppress_charge_exit();
|
||||
|
||||
|
@ -336,9 +401,9 @@ void subghz_cli_command_rx_raw(Cli* cli, FuriString* args, void* context) {
|
|||
|
||||
// Configure radio
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok270Async);
|
||||
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_ook_650khz_async_regs);
|
||||
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
furi_hal_power_suppress_charge_enter();
|
||||
|
||||
|
@ -384,6 +449,7 @@ void subghz_cli_command_rx_raw(Cli* cli, FuriString* args, void* context) {
|
|||
furi_stream_buffer_free(instance->stream);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void subghz_cli_command_decode_raw(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(context);
|
||||
FuriString* file_name = furi_string_alloc();
|
||||
|
@ -435,25 +501,23 @@ void subghz_cli_command_decode_raw(Cli* cli, FuriString* args, void* context) {
|
|||
SubGhzCliCommandRx* instance = malloc(sizeof(SubGhzCliCommandRx));
|
||||
|
||||
SubGhzEnvironment* environment = subghz_environment_alloc();
|
||||
if(subghz_environment_load_keystore(
|
||||
environment, EXT_PATH("subghz/assets/keeloq_mfcodes"))) {
|
||||
if(subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_NAME)) {
|
||||
printf("SubGhz decode_raw: Load_keystore keeloq_mfcodes \033[0;32mOK\033[0m\r\n");
|
||||
} else {
|
||||
printf("SubGhz decode_raw: Load_keystore keeloq_mfcodes \033[0;31mERROR\033[0m\r\n");
|
||||
}
|
||||
if(subghz_environment_load_keystore(
|
||||
environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user"))) {
|
||||
if(subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_USER_NAME)) {
|
||||
printf("SubGhz decode_raw: Load_keystore keeloq_mfcodes_user \033[0;32mOK\033[0m\r\n");
|
||||
} else {
|
||||
printf(
|
||||
"SubGhz decode_raw: Load_keystore keeloq_mfcodes_user \033[0;31mERROR\033[0m\r\n");
|
||||
}
|
||||
subghz_environment_set_came_atomo_rainbow_table_file_name(
|
||||
environment, EXT_PATH("subghz/assets/came_atomo"));
|
||||
environment, SUBGHZ_CAME_ATOMO_DIR_NAME);
|
||||
subghz_environment_set_alutech_at_4n_rainbow_table_file_name(
|
||||
environment, EXT_PATH("subghz/assets/alutech_at_4n"));
|
||||
environment, SUBGHZ_ALUTECH_AT_4N_DIR_NAME);
|
||||
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
|
||||
environment, EXT_PATH("subghz/assets/nice_flor_s"));
|
||||
environment, SUBGHZ_NICE_FLOR_S_DIR_NAME);
|
||||
subghz_environment_set_protocol_registry(environment, (void*)&subghz_protocol_registry);
|
||||
|
||||
SubGhzReceiver* receiver = subghz_receiver_alloc_init(environment);
|
||||
|
@ -461,7 +525,8 @@ void subghz_cli_command_decode_raw(Cli* cli, FuriString* args, void* context) {
|
|||
subghz_receiver_set_rx_callback(receiver, subghz_cli_command_rx_callback, instance);
|
||||
|
||||
SubGhzFileEncoderWorker* file_worker_encoder = subghz_file_encoder_worker_alloc();
|
||||
if(subghz_file_encoder_worker_start(file_worker_encoder, furi_string_get_cstr(file_name))) {
|
||||
if(subghz_file_encoder_worker_start(
|
||||
file_worker_encoder, furi_string_get_cstr(file_name), NULL)) {
|
||||
//the worker needs a file in order to open and read part of the file
|
||||
furi_delay_ms(100);
|
||||
}
|
||||
|
@ -503,10 +568,11 @@ static void subghz_cli_command_print_usage() {
|
|||
printf("subghz <cmd> <args>\r\n");
|
||||
printf("Cmd list:\r\n");
|
||||
|
||||
printf("\tchat <frequency:in Hz>\t - Chat with other Flippers\r\n");
|
||||
printf(
|
||||
"\ttx <3 byte Key: in hex> <frequency: in Hz> <te: us> <repeat: count>\t - Transmitting key\r\n");
|
||||
printf("\trx <frequency:in Hz>\t - Receive\r\n");
|
||||
"\tchat <frequency:in Hz> <device: 0 - CC1101_INT, 1 - CC1101_EXT>\t - Chat with other Flippers\r\n");
|
||||
printf(
|
||||
"\ttx <3 byte Key: in hex> <frequency: in Hz> <te: us> <repeat: count> <device: 0 - CC1101_INT, 1 - CC1101_EXT>\t - Transmitting key\r\n");
|
||||
printf("\trx <frequency:in Hz> <device: 0 - CC1101_INT, 1 - CC1101_EXT>\t - Receive\r\n");
|
||||
printf("\trx_raw <frequency:in Hz>\t - Receive RAW\r\n");
|
||||
printf("\tdecode_raw <file_name: path_RAW_file>\t - Testing\r\n");
|
||||
|
||||
|
@ -600,21 +666,31 @@ static void subghz_cli_command_encrypt_raw(Cli* cli, FuriString* args) {
|
|||
|
||||
static void subghz_cli_command_chat(Cli* cli, FuriString* args) {
|
||||
uint32_t frequency = 433920000;
|
||||
uint32_t device_ind = 0; // 0 - CC1101_INT, 1 - CC1101_EXT
|
||||
|
||||
if(furi_string_size(args)) {
|
||||
int ret = sscanf(furi_string_get_cstr(args), "%lu", &frequency);
|
||||
if(ret != 1) {
|
||||
printf("sscanf returned %d, frequency: %lu\r\n", ret, frequency);
|
||||
cli_print_usage("subghz chat", "<Frequency: in Hz>", furi_string_get_cstr(args));
|
||||
return;
|
||||
}
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
printf(
|
||||
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
||||
frequency);
|
||||
int ret = sscanf(furi_string_get_cstr(args), "%lu %lu", &frequency, &device_ind);
|
||||
if(ret != 2) {
|
||||
printf("sscanf returned %d, Frequency: %lu\r\n", ret, frequency);
|
||||
printf("sscanf returned %d, Device: %lu\r\n", ret, device_ind);
|
||||
cli_print_usage(
|
||||
"subghz chat",
|
||||
"<Frequency: in Hz> <Device: 0 - CC1101_INT, 1 - CC1101_EXT>",
|
||||
furi_string_get_cstr(args));
|
||||
return;
|
||||
}
|
||||
}
|
||||
subghz_devices_init();
|
||||
const SubGhzDevice* device = subghz_cli_command_get_device(device_ind);
|
||||
if(!subghz_devices_is_frequency_valid(device, frequency)) {
|
||||
printf(
|
||||
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n", frequency);
|
||||
subghz_devices_deinit();
|
||||
subghz_cli_radio_device_power_off();
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO
|
||||
if(!furi_hal_subghz_is_tx_allowed(frequency)) {
|
||||
printf(
|
||||
"In your settings, only reception on this frequency (%lu) is allowed,\r\n"
|
||||
|
@ -624,7 +700,8 @@ static void subghz_cli_command_chat(Cli* cli, FuriString* args) {
|
|||
}
|
||||
|
||||
SubGhzChatWorker* subghz_chat = subghz_chat_worker_alloc(cli);
|
||||
if(!subghz_chat_worker_start(subghz_chat, frequency)) {
|
||||
|
||||
if(!subghz_chat_worker_start(subghz_chat, device, frequency)) {
|
||||
printf("Startup error SubGhzChatWorker\r\n");
|
||||
|
||||
if(subghz_chat_worker_is_running(subghz_chat)) {
|
||||
|
@ -766,6 +843,10 @@ static void subghz_cli_command_chat(Cli* cli, FuriString* args) {
|
|||
furi_string_free(name);
|
||||
furi_string_free(output);
|
||||
furi_string_free(sysmsg);
|
||||
|
||||
subghz_devices_deinit();
|
||||
subghz_cli_radio_device_power_off();
|
||||
|
||||
furi_hal_power_suppress_charge_exit();
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
|
||||
|
@ -779,15 +860,6 @@ static void subghz_cli_command_chat(Cli* cli, FuriString* args) {
|
|||
static void subghz_cli_command(Cli* cli, FuriString* args, void* context) {
|
||||
FuriString* cmd = furi_string_alloc();
|
||||
|
||||
// Enable power for External CC1101 if it is connected
|
||||
furi_hal_subghz_enable_ext_power();
|
||||
// Auto switch to internal radio if external radio is not available
|
||||
furi_delay_ms(15);
|
||||
if(!furi_hal_subghz_check_radio()) {
|
||||
furi_hal_subghz_select_radio_type(SubGhzRadioInternal);
|
||||
furi_hal_subghz_init_radio_type(SubGhzRadioInternal);
|
||||
}
|
||||
|
||||
do {
|
||||
if(!args_read_string_and_trim(args, cmd)) {
|
||||
subghz_cli_command_print_usage();
|
||||
|
@ -844,11 +916,6 @@ static void subghz_cli_command(Cli* cli, FuriString* args, void* context) {
|
|||
subghz_cli_command_print_usage();
|
||||
} while(false);
|
||||
|
||||
// Disable power for External CC1101 if it was enabled and module is connected
|
||||
furi_hal_subghz_disable_ext_power();
|
||||
// Reinit SPI handles for internal radio / nfc
|
||||
furi_hal_subghz_init_radio_type(SubGhzRadioInternal);
|
||||
|
||||
furi_string_free(cmd);
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format) {
|
|||
subghz->dialogs, "Error in protocol\nparameters\ndescription");
|
||||
break;
|
||||
case SubGhzTxRxStartTxStateErrorOnlyRx:
|
||||
subghz_dialog_message_show_only_rx(subghz);
|
||||
subghz_dialog_message_freq_error(subghz, true);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -56,12 +56,16 @@ bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format) {
|
|||
return false;
|
||||
}
|
||||
|
||||
void subghz_dialog_message_show_only_rx(SubGhz* subghz) {
|
||||
void subghz_dialog_message_freq_error(SubGhz* subghz, bool only_rx) {
|
||||
DialogsApp* dialogs = subghz->dialogs;
|
||||
DialogMessage* message = dialog_message_alloc();
|
||||
const char* header_text = "Frequency not supported";
|
||||
const char* message_text = "Frequency\nis outside of\nsuported range.";
|
||||
|
||||
const char* header_text = "Transmission is blocked";
|
||||
const char* message_text = "Frequency\nis outside of\ndefault range.\nCheck docs.";
|
||||
if(only_rx) {
|
||||
header_text = "Transmission is blocked";
|
||||
message_text = "Frequency\nis outside of\ndefault range.\nCheck docs.";
|
||||
}
|
||||
|
||||
dialog_message_set_header(message, header_text, 63, 3, AlignCenter, AlignTop);
|
||||
dialog_message_set_text(message, message_text, 0, 17, AlignLeft, AlignTop);
|
||||
|
@ -111,13 +115,14 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) {
|
|||
break;
|
||||
}
|
||||
|
||||
if(!furi_hal_subghz_is_frequency_valid(temp_data32)) {
|
||||
FURI_LOG_E(TAG, "Frequency not supported");
|
||||
if(!subghz_txrx_radio_device_is_frequecy_valid(subghz->txrx, temp_data32)) {
|
||||
FURI_LOG_E(TAG, "Frequency not supported on chosen radio module");
|
||||
load_key_state = SubGhzLoadKeyStateUnsuportedFreq;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!furi_hal_subghz_is_tx_allowed(temp_data32)) {
|
||||
FURI_LOG_E(TAG, "This frequency can only be used for RX");
|
||||
if(!subghz_txrx_radio_device_is_tx_alowed(subghz->txrx, temp_data32)) {
|
||||
FURI_LOG_E(TAG, "This frequency can only be used for RX on chosen radio module");
|
||||
load_key_state = SubGhzLoadKeyStateOnlyRx;
|
||||
break;
|
||||
}
|
||||
|
@ -165,7 +170,8 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) {
|
|||
if(!strcmp(furi_string_get_cstr(temp_str), "RAW")) {
|
||||
//if RAW
|
||||
subghz->load_type_file = SubGhzLoadTypeFileRaw;
|
||||
subghz_protocol_raw_gen_fff_data(fff_data, file_path);
|
||||
subghz_protocol_raw_gen_fff_data(
|
||||
fff_data, file_path, subghz_txrx_radio_device_get_name(subghz->txrx));
|
||||
} else {
|
||||
subghz->load_type_file = SubGhzLoadTypeFileKey;
|
||||
stream_copy_full(
|
||||
|
@ -206,9 +212,15 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) {
|
|||
}
|
||||
return false;
|
||||
|
||||
case SubGhzLoadKeyStateUnsuportedFreq:
|
||||
if(show_dialog) {
|
||||
subghz_dialog_message_freq_error(subghz, false);
|
||||
}
|
||||
return false;
|
||||
|
||||
case SubGhzLoadKeyStateOnlyRx:
|
||||
if(show_dialog) {
|
||||
subghz_dialog_message_show_only_rx(subghz);
|
||||
subghz_dialog_message_freq_error(subghz, true);
|
||||
}
|
||||
return false;
|
||||
|
||||
|
|
|
@ -103,7 +103,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_show_only_rx(SubGhz* subghz);
|
||||
void subghz_dialog_message_freq_error(SubGhz* subghz, bool only_rx);
|
||||
|
||||
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);
|
||||
|
|
|
@ -119,17 +119,6 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
|
|||
|
||||
instance->timestamp_file_names = temp_timestamp_file_names;
|
||||
|
||||
if(instance->external_module_power_5v_disable) {
|
||||
furi_hal_subghz_set_external_power_disable(true);
|
||||
furi_hal_subghz_disable_ext_power();
|
||||
}
|
||||
|
||||
// Set selected radio module
|
||||
if(instance->external_module_enabled) {
|
||||
furi_hal_subghz_select_radio_type(SubGhzRadioExternal);
|
||||
furi_hal_subghz_init_radio_type(SubGhzRadioExternal);
|
||||
}
|
||||
|
||||
/*/} else {
|
||||
instance->preset = temp_preset;
|
||||
}*/
|
||||
|
|
|
@ -10,8 +10,10 @@ typedef struct {
|
|||
int32_t preset;
|
||||
uint32_t frequency_analyzer_feedback_level;
|
||||
float frequency_analyzer_trigger;
|
||||
// TODO not using but saved so as not to change the version
|
||||
bool external_module_enabled;
|
||||
bool external_module_power_5v_disable;
|
||||
// saved so as not to change the version
|
||||
bool timestamp_file_names;
|
||||
} SubGhzLastSettings;
|
||||
|
||||
|
|
|
@ -69,7 +69,11 @@ typedef struct {
|
|||
SubGhzViewReceiverBarShow bar_show;
|
||||
SubGhzViewReceiverMode mode;
|
||||
uint8_t u_rssi;
|
||||
|
||||
SubGhzRadioDeviceType device_type;
|
||||
|
||||
bool show_time;
|
||||
|
||||
bool nodraw;
|
||||
} SubGhzViewReceiverModel;
|
||||
|
||||
|
@ -220,6 +224,17 @@ void subghz_view_receiver_add_data_progress(
|
|||
true);
|
||||
}
|
||||
|
||||
void subghz_view_receiver_set_radio_device_type(
|
||||
SubGhzViewReceiver* subghz_receiver,
|
||||
SubGhzRadioDeviceType device_type) {
|
||||
furi_assert(subghz_receiver);
|
||||
with_view_model(
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{ model->device_type = device_type; },
|
||||
true);
|
||||
}
|
||||
|
||||
static void subghz_view_receiver_draw_frame(Canvas* canvas, uint16_t idx, bool scrollbar) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_box(canvas, 0, 0 + idx * FRAME_HEIGHT, scrollbar ? 122 : 127, FRAME_HEIGHT);
|
||||
|
@ -296,12 +311,14 @@ void subghz_view_receiver_draw(Canvas* canvas, SubGhzViewReceiverModel* model) {
|
|||
canvas_set_color(canvas, ColorBlack);
|
||||
|
||||
if(model->history_item == 0) {
|
||||
// TODO
|
||||
if(model->mode == SubGhzViewReceiverModeLive) {
|
||||
canvas_draw_icon(
|
||||
canvas,
|
||||
0,
|
||||
0,
|
||||
furi_hal_subghz_get_radio_type() ? &I_Fishing_123x52 : &I_Scanning_123x52);
|
||||
(model->device_type == SubGhzRadioDeviceTypeInternal) ? &I_Scanning_123x52 :
|
||||
&I_Fishing_123x52);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str(canvas, 63, 46, "Scanning...");
|
||||
//canvas_draw_line(canvas, 46, 51, 125, 51);
|
||||
|
@ -311,7 +328,8 @@ void subghz_view_receiver_draw(Canvas* canvas, SubGhzViewReceiverModel* model) {
|
|||
canvas,
|
||||
0,
|
||||
0,
|
||||
furi_hal_subghz_get_radio_type() ? &I_Fishing_123x52 : &I_Scanning_123x52);
|
||||
(model->device_type == SubGhzRadioDeviceTypeInternal) ? &I_Scanning_123x52 :
|
||||
&I_Fishing_123x52);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str(canvas, 63, 46, "Decoding...");
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
|
|
|
@ -33,6 +33,10 @@ void subghz_view_receiver_add_data_statusbar(
|
|||
const char* preset_str,
|
||||
const char* history_stat_str);
|
||||
|
||||
void subghz_view_receiver_set_radio_device_type(
|
||||
SubGhzViewReceiver* subghz_receiver,
|
||||
SubGhzRadioDeviceType device_type);
|
||||
|
||||
void subghz_view_receiver_add_data_progress(
|
||||
SubGhzViewReceiver* subghz_receiver,
|
||||
const char* progress_str);
|
||||
|
|
|
@ -38,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
|
||||
|
@ -60,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(
|
||||
|
@ -166,7 +168,8 @@ void subghz_frequency_analyzer_draw(Canvas* canvas, SubGhzFrequencyAnalyzerModel
|
|||
// Title
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
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
|
||||
|
@ -311,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 {
|
||||
|
@ -333,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 {
|
||||
|
@ -348,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 {
|
||||
|
@ -539,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;
|
||||
|
@ -567,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);
|
||||
}
|
||||
|
@ -584,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;
|
||||
|
@ -599,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);
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ typedef struct {
|
|||
bool raw_send_only;
|
||||
float raw_threshold_rssi;
|
||||
bool not_showing_samples;
|
||||
SubGhzRadioDeviceType device_type;
|
||||
} SubGhzReadRAWModel;
|
||||
|
||||
void subghz_read_raw_set_callback(
|
||||
|
@ -58,6 +59,14 @@ void subghz_read_raw_add_data_statusbar(
|
|||
true);
|
||||
}
|
||||
|
||||
void subghz_read_raw_set_radio_device_type(
|
||||
SubGhzReadRAW* instance,
|
||||
SubGhzRadioDeviceType device_type) {
|
||||
furi_assert(instance);
|
||||
with_view_model(
|
||||
instance->view, SubGhzReadRAWModel * model, { model->device_type = device_type; }, true);
|
||||
}
|
||||
|
||||
void subghz_read_raw_add_data_rssi(SubGhzReadRAW* instance, float rssi, bool trace) {
|
||||
furi_assert(instance);
|
||||
uint8_t u_rssi = 0;
|
||||
|
@ -288,9 +297,15 @@ void subghz_read_raw_draw(Canvas* canvas, SubGhzReadRAWModel* model) {
|
|||
canvas_draw_str(canvas, 35, 7, furi_string_get_cstr(model->preset_str));
|
||||
|
||||
if(model->not_showing_samples) {
|
||||
canvas_draw_str(canvas, 77, 7, furi_hal_subghz_get_radio_type() ? "R: Ext" : "R: Int");
|
||||
// TODO
|
||||
canvas_draw_str(
|
||||
canvas,
|
||||
77,
|
||||
7,
|
||||
(model->device_type == SubGhzRadioDeviceTypeInternal) ? "R: Int" : "R: Ext");
|
||||
} else {
|
||||
canvas_draw_str(canvas, 70, 7, furi_hal_subghz_get_radio_type() ? "E" : "I");
|
||||
canvas_draw_str(
|
||||
canvas, 70, 7, (model->device_type == SubGhzRadioDeviceTypeInternal) ? "I" : "E");
|
||||
}
|
||||
|
||||
canvas_draw_str_aligned(
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "../helpers/subghz_types.h"
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
#define SUBGHZ_RAW_THRESHOLD_MIN -90.0f
|
||||
|
@ -36,6 +37,10 @@ void subghz_read_raw_add_data_statusbar(
|
|||
const char* frequency_str,
|
||||
const char* preset_str);
|
||||
|
||||
void subghz_read_raw_set_radio_device_type(
|
||||
SubGhzReadRAW* instance,
|
||||
SubGhzRadioDeviceType device_type);
|
||||
|
||||
void subghz_read_raw_update_sample_write(SubGhzReadRAW* instance, size_t sample);
|
||||
|
||||
void subghz_read_raw_stop_send(SubGhzReadRAW* instance);
|
||||
|
|
|
@ -17,6 +17,7 @@ typedef struct {
|
|||
FuriString* preset_str;
|
||||
FuriString* key_str;
|
||||
bool show_button;
|
||||
SubGhzRadioDeviceType device_type;
|
||||
FuriString* temp_button_id;
|
||||
bool draw_temp_button;
|
||||
} SubGhzViewTransmitterModel;
|
||||
|
@ -50,6 +51,17 @@ void subghz_view_transmitter_add_data_to_show(
|
|||
true);
|
||||
}
|
||||
|
||||
void subghz_view_transmitter_set_radio_device_type(
|
||||
SubGhzViewTransmitter* subghz_transmitter,
|
||||
SubGhzRadioDeviceType device_type) {
|
||||
furi_assert(subghz_transmitter);
|
||||
with_view_model(
|
||||
subghz_transmitter->view,
|
||||
SubGhzViewTransmitterModel * model,
|
||||
{ model->device_type = device_type; },
|
||||
true);
|
||||
}
|
||||
|
||||
static void subghz_view_transmitter_button_right(Canvas* canvas, const char* str) {
|
||||
const uint8_t button_height = 12;
|
||||
const uint8_t vertical_offset = 3;
|
||||
|
@ -100,7 +112,12 @@ void subghz_view_transmitter_draw(Canvas* canvas, SubGhzViewTransmitterModel* mo
|
|||
}
|
||||
|
||||
if(model->show_button) {
|
||||
canvas_draw_str(canvas, 58, 62, furi_hal_subghz_get_radio_type() ? "R: Ext" : "R: Int");
|
||||
// TODO
|
||||
canvas_draw_str(
|
||||
canvas,
|
||||
58,
|
||||
62,
|
||||
(model->device_type == SubGhzRadioDeviceTypeInternal) ? "R: Int" : "R: Ext");
|
||||
subghz_view_transmitter_button_right(canvas, "Send");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "../helpers/subghz_types.h"
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
typedef struct SubGhzViewTransmitter SubGhzViewTransmitter;
|
||||
|
@ -12,6 +13,10 @@ void subghz_view_transmitter_set_callback(
|
|||
SubGhzViewTransmitterCallback callback,
|
||||
void* context);
|
||||
|
||||
void subghz_view_transmitter_set_radio_device_type(
|
||||
SubGhzViewTransmitter* subghz_transmitter,
|
||||
SubGhzRadioDeviceType device_type);
|
||||
|
||||
SubGhzViewTransmitter* subghz_view_transmitter_alloc();
|
||||
|
||||
void subghz_view_transmitter_free(SubGhzViewTransmitter* subghz_transmitter);
|
||||
|
|
|
@ -84,8 +84,8 @@ SubRemLoadSubState subrem_sub_preset_load(
|
|||
if(!flipper_format_read_uint32(fff_data_file, "Frequency", &temp_data32, 1)) {
|
||||
FURI_LOG_W(TAG, "Cannot read frequency. Set default frequency");
|
||||
sub_preset->freq_preset.frequency = subghz_setting_get_default_frequency(setting);
|
||||
} else if(!furi_hal_subghz_is_tx_allowed(temp_data32)) {
|
||||
FURI_LOG_E(TAG, "This frequency can only be used for RX");
|
||||
} else if(!subghz_txrx_radio_device_is_frequecy_valid(txrx, temp_data32)) {
|
||||
FURI_LOG_E(TAG, "Frequency not supported on chosen radio module");
|
||||
break;
|
||||
}
|
||||
sub_preset->freq_preset.frequency = temp_data32;
|
||||
|
@ -124,7 +124,9 @@ SubRemLoadSubState subrem_sub_preset_load(
|
|||
if(!strcmp(furi_string_get_cstr(temp_str), "RAW")) {
|
||||
//if RAW
|
||||
subghz_protocol_raw_gen_fff_data(
|
||||
fff_data, furi_string_get_cstr(sub_preset->file_path));
|
||||
fff_data,
|
||||
furi_string_get_cstr(sub_preset->file_path),
|
||||
subghz_txrx_radio_device_get_name(txrx));
|
||||
} else {
|
||||
stream_copy_full(
|
||||
flipper_format_get_raw_stream(fff_data_file),
|
||||
|
|
|
@ -80,7 +80,7 @@ bool subrem_scene_remote_on_event(void* context, SceneManagerEvent event) {
|
|||
} else {
|
||||
subrem_view_remote_set_state(
|
||||
app->subrem_remote_view, SubRemViewRemoteStateIdle, 0);
|
||||
notification_message(app->notifications, &sequence_blink_stop);
|
||||
notification_message(app->notifications, &sequence_blink_red_100);
|
||||
}
|
||||
return true;
|
||||
} else if(event.event == SubRemCustomEventViewRemoteForcedStop) {
|
||||
|
|
|
@ -29,14 +29,14 @@ SubGhzRemoteApp* subghz_remote_app_alloc() {
|
|||
}
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
// Enable power for External CC1101 if it is connected
|
||||
furi_hal_subghz_enable_ext_power();
|
||||
// Auto switch to internal radio if external radio is not available
|
||||
furi_delay_ms(15);
|
||||
if(!furi_hal_subghz_check_radio()) {
|
||||
furi_hal_subghz_select_radio_type(SubGhzRadioInternal);
|
||||
furi_hal_subghz_init_radio_type(SubGhzRadioInternal);
|
||||
}
|
||||
// // Enable power for External CC1101 if it is connected
|
||||
// furi_hal_subghz_enable_ext_power();
|
||||
// // Auto switch to internal radio if external radio is not available
|
||||
// furi_delay_ms(15);
|
||||
// if(!furi_hal_subghz_check_radio()) {
|
||||
// furi_hal_subghz_select_radio_type(SubGhzRadioInternal);
|
||||
// furi_hal_subghz_init_radio_type(SubGhzRadioInternal);
|
||||
// }
|
||||
|
||||
furi_hal_power_suppress_charge_enter();
|
||||
|
||||
|
@ -105,10 +105,10 @@ void subghz_remote_app_free(SubGhzRemoteApp* app) {
|
|||
|
||||
furi_hal_power_suppress_charge_exit();
|
||||
|
||||
// Disable power for External CC1101 if it was enabled and module is connected
|
||||
furi_hal_subghz_disable_ext_power();
|
||||
// Reinit SPI handles for internal radio / nfc
|
||||
furi_hal_subghz_init_radio_type(SubGhzRadioInternal);
|
||||
// // Disable power for External CC1101 if it was enabled and module is connected
|
||||
// furi_hal_subghz_disable_ext_power();
|
||||
// // Reinit SPI handles for internal radio / nfc
|
||||
// furi_hal_subghz_init_radio_type(SubGhzRadioInternal);
|
||||
|
||||
// Submenu
|
||||
view_dispatcher_remove_view(app->view_dispatcher, SubRemViewIDSubmenu);
|
||||
|
|
|
@ -78,9 +78,9 @@ The system will take over any given peripheral only when the respective feature
|
|||
| ADC | | |
|
||||
| QUADSPI | | |
|
||||
| TIM1 | yes | subghz, lfrfid, nfc, infrared, etc... |
|
||||
| TIM2 | yes | -- |
|
||||
| TIM2 | yes | subghz, infrared, etc... |
|
||||
| TIM16 | yes | speaker |
|
||||
| TIM17 | | |
|
||||
| TIM17 | yes | cc1101_ext |
|
||||
| LPTIM1 | yes | tickless idle timer |
|
||||
| LPTIM2 | yes | pwm |
|
||||
| SAI1 | | |
|
||||
|
@ -104,10 +104,10 @@ Below is the list of DMA channels and their usage by the system.
|
|||
| -- | 5 | | |
|
||||
| -- | 6 | | |
|
||||
| -- | 7 | | |
|
||||
| DMA2 | 1 | yes | infrared, lfrfid, subghz |
|
||||
| DMA2 | 1 | yes | infrared, lfrfid, subghz, |
|
||||
| -- | 2 | yes | -- |
|
||||
| -- | 3 | yes | SPI |
|
||||
| -- | 4 | yes | SPI |
|
||||
| -- | 5 | | |
|
||||
| -- | 6 | | |
|
||||
| -- | 7 | | |
|
||||
| -- | 3 | yes | cc1101_ext |
|
||||
| -- | 4 | yes | cc1101_ext |
|
||||
| -- | 5 | yes | cc1101_ext |
|
||||
| -- | 6 | yes | SPI |
|
||||
| -- | 7 | yes | SPI |
|
||||
|
|
|
@ -56,7 +56,6 @@ Header,+,firmware/targets/f7/furi_hal/furi_hal_rfid.h,,
|
|||
Header,+,firmware/targets/f7/furi_hal/furi_hal_spi_config.h,,
|
||||
Header,+,firmware/targets/f7/furi_hal/furi_hal_spi_types.h,,
|
||||
Header,+,firmware/targets/f7/furi_hal/furi_hal_subghz.h,,
|
||||
Header,+,firmware/targets/f7/furi_hal/furi_hal_subghz_configs.h,,
|
||||
Header,+,firmware/targets/f7/furi_hal/furi_hal_target_hw.h,,
|
||||
Header,+,firmware/targets/f7/furi_hal/furi_hal_uart.h,,
|
||||
Header,+,firmware/targets/f7/furi_hal/furi_hal_usb_cdc.h,,
|
||||
|
@ -193,6 +192,7 @@ Header,+,lib/subghz/blocks/decoder.h,,
|
|||
Header,+,lib/subghz/blocks/encoder.h,,
|
||||
Header,+,lib/subghz/blocks/generic.h,,
|
||||
Header,+,lib/subghz/blocks/math.h,,
|
||||
Header,+,lib/subghz/devices/cc1101_configs.h,,
|
||||
Header,+,lib/subghz/environment.h,,
|
||||
Header,+,lib/subghz/protocols/raw.h,,
|
||||
Header,+,lib/subghz/receiver.h,,
|
||||
|
@ -678,26 +678,6 @@ Function,+,canvas_width,uint8_t,const Canvas*
|
|||
Function,-,cbrt,double,double
|
||||
Function,-,cbrtf,float,float
|
||||
Function,-,cbrtl,long double,long double
|
||||
Function,+,cc1101_calibrate,void,FuriHalSpiBusHandle*
|
||||
Function,+,cc1101_flush_rx,void,FuriHalSpiBusHandle*
|
||||
Function,+,cc1101_flush_tx,void,FuriHalSpiBusHandle*
|
||||
Function,-,cc1101_get_partnumber,uint8_t,FuriHalSpiBusHandle*
|
||||
Function,+,cc1101_get_rssi,uint8_t,FuriHalSpiBusHandle*
|
||||
Function,+,cc1101_get_status,CC1101Status,FuriHalSpiBusHandle*
|
||||
Function,-,cc1101_get_version,uint8_t,FuriHalSpiBusHandle*
|
||||
Function,+,cc1101_read_fifo,uint8_t,"FuriHalSpiBusHandle*, uint8_t*, uint8_t*"
|
||||
Function,+,cc1101_read_reg,CC1101Status,"FuriHalSpiBusHandle*, uint8_t, uint8_t*"
|
||||
Function,+,cc1101_reset,void,FuriHalSpiBusHandle*
|
||||
Function,+,cc1101_set_frequency,uint32_t,"FuriHalSpiBusHandle*, uint32_t"
|
||||
Function,-,cc1101_set_intermediate_frequency,uint32_t,"FuriHalSpiBusHandle*, uint32_t"
|
||||
Function,+,cc1101_set_pa_table,void,"FuriHalSpiBusHandle*, const uint8_t[8]"
|
||||
Function,+,cc1101_shutdown,void,FuriHalSpiBusHandle*
|
||||
Function,+,cc1101_strobe,CC1101Status,"FuriHalSpiBusHandle*, uint8_t"
|
||||
Function,+,cc1101_switch_to_idle,void,FuriHalSpiBusHandle*
|
||||
Function,+,cc1101_switch_to_rx,void,FuriHalSpiBusHandle*
|
||||
Function,+,cc1101_switch_to_tx,void,FuriHalSpiBusHandle*
|
||||
Function,+,cc1101_write_fifo,uint8_t,"FuriHalSpiBusHandle*, const uint8_t*, uint8_t"
|
||||
Function,+,cc1101_write_reg,CC1101Status,"FuriHalSpiBusHandle*, uint8_t, uint8_t"
|
||||
Function,-,ceil,double,double
|
||||
Function,-,ceilf,float,float
|
||||
Function,-,ceill,long double,long double
|
||||
|
@ -1414,36 +1394,27 @@ 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_radio,_Bool,
|
||||
Function,+,furi_hal_subghz_disable_ext_power,void,
|
||||
Function,-,furi_hal_subghz_dump_state,void,
|
||||
Function,+,furi_hal_subghz_enable_ext_power,_Bool,
|
||||
Function,+,furi_hal_subghz_flush_rx,void,
|
||||
Function,+,furi_hal_subghz_flush_tx,void,
|
||||
Function,+,furi_hal_subghz_get_external_power_disable,_Bool,
|
||||
Function,+,furi_hal_subghz_get_data_gpio,const GpioPin*,
|
||||
Function,+,furi_hal_subghz_get_lqi,uint8_t,
|
||||
Function,+,furi_hal_subghz_get_radio_type,SubGhzRadioType,
|
||||
Function,+,furi_hal_subghz_get_rolling_counter_mult,uint8_t,
|
||||
Function,+,furi_hal_subghz_get_rssi,float,
|
||||
Function,+,furi_hal_subghz_idle,void,
|
||||
Function,-,furi_hal_subghz_init,void,
|
||||
Function,-,furi_hal_subghz_init_check,_Bool,
|
||||
Function,+,furi_hal_subghz_init_radio_type,_Bool,SubGhzRadioType
|
||||
Function,+,furi_hal_subghz_is_async_tx_complete,_Bool,
|
||||
Function,+,furi_hal_subghz_is_frequency_valid,_Bool,uint32_t
|
||||
Function,+,furi_hal_subghz_is_rx_data_crc_valid,_Bool,
|
||||
Function,+,furi_hal_subghz_is_tx_allowed,_Bool,uint32_t
|
||||
Function,+,furi_hal_subghz_load_custom_preset,void,uint8_t*
|
||||
Function,+,furi_hal_subghz_load_custom_preset,void,const uint8_t*
|
||||
Function,+,furi_hal_subghz_load_patable,void,const uint8_t[8]
|
||||
Function,+,furi_hal_subghz_load_preset,void,FuriHalSubGhzPreset
|
||||
Function,+,furi_hal_subghz_load_registers,void,uint8_t*
|
||||
Function,+,furi_hal_subghz_load_registers,void,const uint8_t*
|
||||
Function,+,furi_hal_subghz_read_packet,void,"uint8_t*, uint8_t*"
|
||||
Function,+,furi_hal_subghz_reset,void,
|
||||
Function,+,furi_hal_subghz_rx,void,
|
||||
Function,+,furi_hal_subghz_rx_pipe_not_empty,_Bool,
|
||||
Function,+,furi_hal_subghz_select_radio_type,void,SubGhzRadioType
|
||||
Function,+,furi_hal_subghz_set_async_mirror_pin,void,const GpioPin*
|
||||
Function,+,furi_hal_subghz_set_external_power_disable,void,_Bool
|
||||
Function,+,furi_hal_subghz_set_frequency,uint32_t,uint32_t
|
||||
Function,+,furi_hal_subghz_set_frequency_and_path,uint32_t,uint32_t
|
||||
Function,+,furi_hal_subghz_set_path,void,FuriHalSubGhzPath
|
||||
|
@ -2765,6 +2736,36 @@ Function,+,subghz_custom_btn_get_original,uint8_t,
|
|||
Function,+,subghz_custom_btn_is_allowed,_Bool,
|
||||
Function,+,subghz_custom_btn_set,_Bool,uint8_t
|
||||
Function,+,subghz_custom_btns_reset,void,
|
||||
Function,+,subghz_devices_begin,_Bool,const SubGhzDevice*
|
||||
Function,+,subghz_devices_deinit,void,
|
||||
Function,+,subghz_devices_end,void,const SubGhzDevice*
|
||||
Function,+,subghz_devices_flush_rx,void,const SubGhzDevice*
|
||||
Function,+,subghz_devices_flush_tx,void,const SubGhzDevice*
|
||||
Function,+,subghz_devices_get_by_name,const SubGhzDevice*,const char*
|
||||
Function,+,subghz_devices_get_data_gpio,const GpioPin*,const SubGhzDevice*
|
||||
Function,+,subghz_devices_get_lqi,uint8_t,const SubGhzDevice*
|
||||
Function,+,subghz_devices_get_name,const char*,const SubGhzDevice*
|
||||
Function,+,subghz_devices_get_rssi,float,const SubGhzDevice*
|
||||
Function,+,subghz_devices_idle,void,const SubGhzDevice*
|
||||
Function,+,subghz_devices_init,void,
|
||||
Function,+,subghz_devices_is_async_complete_tx,_Bool,const SubGhzDevice*
|
||||
Function,+,subghz_devices_is_connect,_Bool,const SubGhzDevice*
|
||||
Function,+,subghz_devices_is_frequency_valid,_Bool,"const SubGhzDevice*, uint32_t"
|
||||
Function,+,subghz_devices_is_rx_data_crc_valid,_Bool,const SubGhzDevice*
|
||||
Function,+,subghz_devices_load_preset,void,"const SubGhzDevice*, FuriHalSubGhzPreset, uint8_t*"
|
||||
Function,+,subghz_devices_read_packet,void,"const SubGhzDevice*, uint8_t*, uint8_t*"
|
||||
Function,+,subghz_devices_reset,void,const SubGhzDevice*
|
||||
Function,+,subghz_devices_rx_pipe_not_empty,_Bool,const SubGhzDevice*
|
||||
Function,+,subghz_devices_set_async_mirror_pin,void,"const SubGhzDevice*, const GpioPin*"
|
||||
Function,+,subghz_devices_set_frequency,uint32_t,"const SubGhzDevice*, uint32_t"
|
||||
Function,+,subghz_devices_set_rx,void,const SubGhzDevice*
|
||||
Function,+,subghz_devices_set_tx,_Bool,const SubGhzDevice*
|
||||
Function,+,subghz_devices_sleep,void,const SubGhzDevice*
|
||||
Function,+,subghz_devices_start_async_rx,void,"const SubGhzDevice*, void*, void*"
|
||||
Function,+,subghz_devices_start_async_tx,_Bool,"const SubGhzDevice*, void*, void*"
|
||||
Function,+,subghz_devices_stop_async_rx,void,const SubGhzDevice*
|
||||
Function,+,subghz_devices_stop_async_tx,void,const SubGhzDevice*
|
||||
Function,+,subghz_devices_write_packet,void,"const SubGhzDevice*, const uint8_t*, uint8_t"
|
||||
Function,+,subghz_environment_alloc,SubGhzEnvironment*,
|
||||
Function,+,subghz_environment_free,void,SubGhzEnvironment*
|
||||
Function,+,subghz_environment_get_alutech_at_4n_rainbow_table_file_name,const char*,SubGhzEnvironment*
|
||||
|
@ -2785,7 +2786,7 @@ Function,+,subghz_file_encoder_worker_free,void,SubGhzFileEncoderWorker*
|
|||
Function,+,subghz_file_encoder_worker_get_level_duration,LevelDuration,void*
|
||||
Function,+,subghz_file_encoder_worker_get_text_progress,void,"SubGhzFileEncoderWorker*, FuriString*"
|
||||
Function,+,subghz_file_encoder_worker_is_running,_Bool,SubGhzFileEncoderWorker*
|
||||
Function,+,subghz_file_encoder_worker_start,_Bool,"SubGhzFileEncoderWorker*, const char*"
|
||||
Function,+,subghz_file_encoder_worker_start,_Bool,"SubGhzFileEncoderWorker*, const char*, const char*"
|
||||
Function,+,subghz_file_encoder_worker_stop,void,SubGhzFileEncoderWorker*
|
||||
Function,-,subghz_keystore_alloc,SubGhzKeystore*,
|
||||
Function,-,subghz_keystore_free,void,SubGhzKeystore*
|
||||
|
@ -2840,7 +2841,7 @@ Function,+,subghz_protocol_keeloq_bft_create_data,_Bool,"void*, FlipperFormat*,
|
|||
Function,+,subghz_protocol_keeloq_create_data,_Bool,"void*, FlipperFormat*, uint32_t, uint8_t, uint16_t, const char*, SubGhzRadioPreset*"
|
||||
Function,+,subghz_protocol_nice_flor_s_create_data,_Bool,"void*, FlipperFormat*, uint32_t, uint8_t, uint16_t, SubGhzRadioPreset*, _Bool"
|
||||
Function,+,subghz_protocol_raw_file_encoder_worker_set_callback_end,void,"SubGhzProtocolEncoderRAW*, SubGhzProtocolEncoderRAWCallbackEnd, void*"
|
||||
Function,+,subghz_protocol_raw_gen_fff_data,void,"FlipperFormat*, const char*"
|
||||
Function,+,subghz_protocol_raw_gen_fff_data,void,"FlipperFormat*, const char*, const char*"
|
||||
Function,+,subghz_protocol_raw_get_sample_write,size_t,SubGhzProtocolDecoderRAW*
|
||||
Function,+,subghz_protocol_raw_save_to_file_init,_Bool,"SubGhzProtocolDecoderRAW*, const char*, SubGhzRadioPreset*"
|
||||
Function,+,subghz_protocol_raw_save_to_file_pause,void,"SubGhzProtocolDecoderRAW*, _Bool"
|
||||
|
@ -2889,7 +2890,7 @@ Function,+,subghz_tx_rx_worker_free,void,SubGhzTxRxWorker*
|
|||
Function,+,subghz_tx_rx_worker_is_running,_Bool,SubGhzTxRxWorker*
|
||||
Function,+,subghz_tx_rx_worker_read,size_t,"SubGhzTxRxWorker*, uint8_t*, size_t"
|
||||
Function,+,subghz_tx_rx_worker_set_callback_have_read,void,"SubGhzTxRxWorker*, SubGhzTxRxWorkerCallbackHaveRead, void*"
|
||||
Function,+,subghz_tx_rx_worker_start,_Bool,"SubGhzTxRxWorker*, uint32_t"
|
||||
Function,+,subghz_tx_rx_worker_start,_Bool,"SubGhzTxRxWorker*, const SubGhzDevice*, uint32_t"
|
||||
Function,+,subghz_tx_rx_worker_stop,void,SubGhzTxRxWorker*
|
||||
Function,+,subghz_tx_rx_worker_write,_Bool,"SubGhzTxRxWorker*, uint8_t*, size_t"
|
||||
Function,+,subghz_worker_alloc,SubGhzWorker*,
|
||||
|
@ -3243,15 +3244,12 @@ Variable,+,furi_hal_spi_bus_handle_nfc,FuriHalSpiBusHandle,
|
|||
Variable,+,furi_hal_spi_bus_handle_sd_fast,FuriHalSpiBusHandle,
|
||||
Variable,+,furi_hal_spi_bus_handle_sd_slow,FuriHalSpiBusHandle,
|
||||
Variable,+,furi_hal_spi_bus_handle_subghz,FuriHalSpiBusHandle,
|
||||
Variable,+,furi_hal_spi_bus_handle_subghz_ext,FuriHalSpiBusHandle,
|
||||
Variable,+,furi_hal_spi_bus_handle_subghz_int,FuriHalSpiBusHandle,
|
||||
Variable,+,furi_hal_spi_bus_r,FuriHalSpiBus,
|
||||
Variable,+,furi_hal_spi_preset_1edge_low_16m,const LL_SPI_InitTypeDef,
|
||||
Variable,+,furi_hal_spi_preset_1edge_low_2m,const LL_SPI_InitTypeDef,
|
||||
Variable,+,furi_hal_spi_preset_1edge_low_4m,const LL_SPI_InitTypeDef,
|
||||
Variable,+,furi_hal_spi_preset_1edge_low_8m,const LL_SPI_InitTypeDef,
|
||||
Variable,+,furi_hal_spi_preset_2edge_low_8m,const LL_SPI_InitTypeDef,
|
||||
Variable,+,furi_hal_subghz,volatile FuriHalSubGhz,
|
||||
Variable,+,gpio_button_back,const GpioPin,
|
||||
Variable,+,gpio_button_down,const GpioPin,
|
||||
Variable,+,gpio_button_left,const GpioPin,
|
||||
|
@ -3259,7 +3257,6 @@ Variable,+,gpio_button_ok,const GpioPin,
|
|||
Variable,+,gpio_button_right,const GpioPin,
|
||||
Variable,+,gpio_button_up,const GpioPin,
|
||||
Variable,+,gpio_cc1101_g0,const GpioPin,
|
||||
Variable,+,gpio_cc1101_g0_ext,const GpioPin,
|
||||
Variable,+,gpio_display_cs,const GpioPin,
|
||||
Variable,+,gpio_display_di,const GpioPin,
|
||||
Variable,+,gpio_display_rst_n,const GpioPin,
|
||||
|
@ -3292,13 +3289,9 @@ Variable,+,gpio_spi_d_miso,const GpioPin,
|
|||
Variable,+,gpio_spi_d_mosi,const GpioPin,
|
||||
Variable,+,gpio_spi_d_sck,const GpioPin,
|
||||
Variable,+,gpio_spi_r_miso,const GpioPin,
|
||||
Variable,+,gpio_spi_r_miso_ext,const GpioPin,
|
||||
Variable,+,gpio_spi_r_mosi,const GpioPin,
|
||||
Variable,+,gpio_spi_r_mosi_ext,const GpioPin,
|
||||
Variable,+,gpio_spi_r_sck,const GpioPin,
|
||||
Variable,+,gpio_spi_r_sck_ext,const GpioPin,
|
||||
Variable,+,gpio_subghz_cs,const GpioPin,
|
||||
Variable,+,gpio_subghz_cs_ext,const GpioPin,
|
||||
Variable,+,gpio_swclk,const GpioPin,
|
||||
Variable,+,gpio_swdio,const GpioPin,
|
||||
Variable,+,gpio_usart_rx,const GpioPin,
|
||||
|
@ -3506,6 +3499,12 @@ Variable,+,sequence_set_vibro_on,const NotificationSequence,
|
|||
Variable,+,sequence_single_vibro,const NotificationSequence,
|
||||
Variable,+,sequence_solid_yellow,const NotificationSequence,
|
||||
Variable,+,sequence_success,const NotificationSequence,
|
||||
Variable,+,subghz_device_cc1101_preset_2fsk_dev2_38khz_async_regs,const uint8_t[],
|
||||
Variable,+,subghz_device_cc1101_preset_2fsk_dev47_6khz_async_regs,const uint8_t[],
|
||||
Variable,+,subghz_device_cc1101_preset_gfsk_9_99kb_async_regs,const uint8_t[],
|
||||
Variable,+,subghz_device_cc1101_preset_msk_99_97kb_async_regs,const uint8_t[],
|
||||
Variable,+,subghz_device_cc1101_preset_ook_270khz_async_regs,const uint8_t[],
|
||||
Variable,+,subghz_device_cc1101_preset_ook_650khz_async_regs,const uint8_t[],
|
||||
Variable,+,subghz_protocol_raw,const SubGhzProtocol,
|
||||
Variable,+,subghz_protocol_raw_decoder,const SubGhzProtocolDecoder,
|
||||
Variable,+,subghz_protocol_raw_encoder,const SubGhzProtocolEncoder,
|
||||
|
|
|
|
@ -14,11 +14,9 @@ const GpioPin gpio_vibro = {.port = VIBRO_GPIO_Port, .pin = VIBRO_Pin};
|
|||
const GpioPin gpio_ibutton = {.port = iBTN_GPIO_Port, .pin = iBTN_Pin};
|
||||
|
||||
const GpioPin gpio_cc1101_g0 = {.port = CC1101_G0_GPIO_Port, .pin = CC1101_G0_Pin};
|
||||
const GpioPin gpio_cc1101_g0_ext = {.port = GPIOB, .pin = LL_GPIO_PIN_2};
|
||||
const GpioPin gpio_rf_sw_0 = {.port = RF_SW_0_GPIO_Port, .pin = RF_SW_0_Pin};
|
||||
|
||||
const GpioPin gpio_subghz_cs = {.port = CC1101_CS_GPIO_Port, .pin = CC1101_CS_Pin};
|
||||
const GpioPin gpio_subghz_cs_ext = {.port = GPIOA, .pin = LL_GPIO_PIN_4};
|
||||
const GpioPin gpio_display_cs = {.port = DISPLAY_CS_GPIO_Port, .pin = DISPLAY_CS_Pin};
|
||||
const GpioPin gpio_display_rst_n = {.port = DISPLAY_RST_GPIO_Port, .pin = DISPLAY_RST_Pin};
|
||||
const GpioPin gpio_display_di = {.port = DISPLAY_DI_GPIO_Port, .pin = DISPLAY_DI_Pin};
|
||||
|
@ -39,9 +37,6 @@ const GpioPin gpio_spi_d_sck = {.port = SPI_D_SCK_GPIO_Port, .pin = SPI_D_SCK_Pi
|
|||
const GpioPin gpio_spi_r_miso = {.port = SPI_R_MISO_GPIO_Port, .pin = SPI_R_MISO_Pin};
|
||||
const GpioPin gpio_spi_r_mosi = {.port = SPI_R_MOSI_GPIO_Port, .pin = SPI_R_MOSI_Pin};
|
||||
const GpioPin gpio_spi_r_sck = {.port = SPI_R_SCK_GPIO_Port, .pin = SPI_R_SCK_Pin};
|
||||
const GpioPin gpio_spi_r_miso_ext = {.port = GPIOA, .pin = LL_GPIO_PIN_6};
|
||||
const GpioPin gpio_spi_r_mosi_ext = {.port = GPIOA, .pin = LL_GPIO_PIN_7};
|
||||
const GpioPin gpio_spi_r_sck_ext = {.port = GPIOB, .pin = LL_GPIO_PIN_3};
|
||||
|
||||
const GpioPin gpio_ext_pc0 = {.port = GPIOC, .pin = LL_GPIO_PIN_0};
|
||||
const GpioPin gpio_ext_pc1 = {.port = GPIOC, .pin = LL_GPIO_PIN_1};
|
||||
|
|
|
@ -57,11 +57,9 @@ extern const GpioPin gpio_vibro;
|
|||
extern const GpioPin gpio_ibutton;
|
||||
|
||||
extern const GpioPin gpio_cc1101_g0;
|
||||
extern const GpioPin gpio_cc1101_g0_ext;
|
||||
extern const GpioPin gpio_rf_sw_0;
|
||||
|
||||
extern const GpioPin gpio_subghz_cs;
|
||||
extern const GpioPin gpio_subghz_cs_ext;
|
||||
extern const GpioPin gpio_display_cs;
|
||||
extern const GpioPin gpio_display_rst_n;
|
||||
extern const GpioPin gpio_display_di;
|
||||
|
@ -82,9 +80,6 @@ extern const GpioPin gpio_spi_d_sck;
|
|||
extern const GpioPin gpio_spi_r_miso;
|
||||
extern const GpioPin gpio_spi_r_mosi;
|
||||
extern const GpioPin gpio_spi_r_sck;
|
||||
extern const GpioPin gpio_spi_r_miso_ext;
|
||||
extern const GpioPin gpio_spi_r_mosi_ext;
|
||||
extern const GpioPin gpio_spi_r_sck_ext;
|
||||
|
||||
extern const GpioPin gpio_ext_pc0;
|
||||
extern const GpioPin gpio_ext_pc1;
|
||||
|
|
|
@ -12,10 +12,10 @@
|
|||
#define TAG "FuriHalSpi"
|
||||
|
||||
#define SPI_DMA DMA2
|
||||
#define SPI_DMA_RX_CHANNEL LL_DMA_CHANNEL_3
|
||||
#define SPI_DMA_TX_CHANNEL LL_DMA_CHANNEL_4
|
||||
#define SPI_DMA_RX_IRQ FuriHalInterruptIdDma2Ch3
|
||||
#define SPI_DMA_TX_IRQ FuriHalInterruptIdDma2Ch4
|
||||
#define SPI_DMA_RX_CHANNEL LL_DMA_CHANNEL_6
|
||||
#define SPI_DMA_TX_CHANNEL LL_DMA_CHANNEL_7
|
||||
#define SPI_DMA_RX_IRQ FuriHalInterruptIdDma2Ch6
|
||||
#define SPI_DMA_TX_IRQ FuriHalInterruptIdDma2Ch7
|
||||
#define SPI_DMA_RX_DEF SPI_DMA, SPI_DMA_RX_CHANNEL
|
||||
#define SPI_DMA_TX_DEF SPI_DMA, SPI_DMA_TX_CHANNEL
|
||||
|
||||
|
@ -170,18 +170,18 @@ bool furi_hal_spi_bus_trx(
|
|||
}
|
||||
|
||||
static void spi_dma_isr() {
|
||||
#if SPI_DMA_RX_CHANNEL == LL_DMA_CHANNEL_3
|
||||
if(LL_DMA_IsActiveFlag_TC3(SPI_DMA) && LL_DMA_IsEnabledIT_TC(SPI_DMA_RX_DEF)) {
|
||||
LL_DMA_ClearFlag_TC3(SPI_DMA);
|
||||
#if SPI_DMA_RX_CHANNEL == LL_DMA_CHANNEL_6
|
||||
if(LL_DMA_IsActiveFlag_TC6(SPI_DMA) && LL_DMA_IsEnabledIT_TC(SPI_DMA_RX_DEF)) {
|
||||
LL_DMA_ClearFlag_TC6(SPI_DMA);
|
||||
furi_check(furi_semaphore_release(spi_dma_completed) == FuriStatusOk);
|
||||
}
|
||||
#else
|
||||
#error Update this code. Would you kindly?
|
||||
#endif
|
||||
|
||||
#if SPI_DMA_TX_CHANNEL == LL_DMA_CHANNEL_4
|
||||
if(LL_DMA_IsActiveFlag_TC4(SPI_DMA) && LL_DMA_IsEnabledIT_TC(SPI_DMA_TX_DEF)) {
|
||||
LL_DMA_ClearFlag_TC4(SPI_DMA);
|
||||
#if SPI_DMA_TX_CHANNEL == LL_DMA_CHANNEL_7
|
||||
if(LL_DMA_IsActiveFlag_TC7(SPI_DMA) && LL_DMA_IsEnabledIT_TC(SPI_DMA_TX_DEF)) {
|
||||
LL_DMA_ClearFlag_TC7(SPI_DMA);
|
||||
furi_check(furi_semaphore_release(spi_dma_completed) == FuriStatusOk);
|
||||
}
|
||||
#else
|
||||
|
@ -241,8 +241,8 @@ bool furi_hal_spi_bus_trx_dma(
|
|||
dma_config.Priority = LL_DMA_PRIORITY_MEDIUM;
|
||||
LL_DMA_Init(SPI_DMA_TX_DEF, &dma_config);
|
||||
|
||||
#if SPI_DMA_TX_CHANNEL == LL_DMA_CHANNEL_4
|
||||
LL_DMA_ClearFlag_TC4(SPI_DMA);
|
||||
#if SPI_DMA_TX_CHANNEL == LL_DMA_CHANNEL_7
|
||||
LL_DMA_ClearFlag_TC7(SPI_DMA);
|
||||
#else
|
||||
#error Update this code. Would you kindly?
|
||||
#endif
|
||||
|
@ -315,8 +315,8 @@ bool furi_hal_spi_bus_trx_dma(
|
|||
dma_config.Priority = LL_DMA_PRIORITY_MEDIUM;
|
||||
LL_DMA_Init(SPI_DMA_RX_DEF, &dma_config);
|
||||
|
||||
#if SPI_DMA_RX_CHANNEL == LL_DMA_CHANNEL_3
|
||||
LL_DMA_ClearFlag_TC3(SPI_DMA);
|
||||
#if SPI_DMA_RX_CHANNEL == LL_DMA_CHANNEL_6
|
||||
LL_DMA_ClearFlag_TC6(SPI_DMA);
|
||||
#else
|
||||
#error Update this code. Would you kindly?
|
||||
#endif
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include <furi_hal_spi.h>
|
||||
#include <furi_hal_bus.h>
|
||||
#include <furi.h>
|
||||
#include <furi_hal_subghz.h>
|
||||
|
||||
#define TAG "FuriHalSpiConfig"
|
||||
|
||||
|
@ -91,7 +90,7 @@ void furi_hal_spi_config_deinit_early() {
|
|||
void furi_hal_spi_config_init() {
|
||||
furi_hal_spi_bus_init(&furi_hal_spi_bus_r);
|
||||
|
||||
furi_hal_spi_bus_handle_init(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_bus_handle_init(&furi_hal_spi_bus_handle_subghz);
|
||||
furi_hal_spi_bus_handle_init(&furi_hal_spi_bus_handle_nfc);
|
||||
furi_hal_spi_bus_handle_init(&furi_hal_spi_bus_handle_sd_fast);
|
||||
furi_hal_spi_bus_handle_init(&furi_hal_spi_bus_handle_sd_slow);
|
||||
|
@ -265,15 +264,6 @@ static void furi_hal_spi_bus_handle_subghz_event_callback(
|
|||
furi_hal_spi_bus_r_handle_event_callback(handle, event, &furi_hal_spi_preset_1edge_low_8m);
|
||||
}
|
||||
|
||||
FuriHalSpiBusHandle furi_hal_spi_bus_handle_subghz_int = {
|
||||
.bus = &furi_hal_spi_bus_r,
|
||||
.callback = furi_hal_spi_bus_handle_subghz_event_callback,
|
||||
.miso = &gpio_spi_r_miso,
|
||||
.mosi = &gpio_spi_r_mosi,
|
||||
.sck = &gpio_spi_r_sck,
|
||||
.cs = &gpio_subghz_cs,
|
||||
};
|
||||
|
||||
FuriHalSpiBusHandle furi_hal_spi_bus_handle_subghz = {
|
||||
.bus = &furi_hal_spi_bus_r,
|
||||
.callback = furi_hal_spi_bus_handle_subghz_event_callback,
|
||||
|
@ -283,15 +273,6 @@ FuriHalSpiBusHandle furi_hal_spi_bus_handle_subghz = {
|
|||
.cs = &gpio_subghz_cs,
|
||||
};
|
||||
|
||||
FuriHalSpiBusHandle furi_hal_spi_bus_handle_subghz_ext = {
|
||||
.bus = &furi_hal_spi_bus_r,
|
||||
.callback = furi_hal_spi_bus_handle_subghz_event_callback,
|
||||
.miso = &gpio_ext_pa6,
|
||||
.mosi = &gpio_ext_pa7,
|
||||
.sck = &gpio_ext_pb3,
|
||||
.cs = &gpio_ext_pa4,
|
||||
};
|
||||
|
||||
static void furi_hal_spi_bus_handle_nfc_event_callback(
|
||||
FuriHalSpiBusHandle* handle,
|
||||
FuriHalSpiBusHandleEvent event) {
|
||||
|
|
|
@ -27,12 +27,8 @@ extern FuriHalSpiBus furi_hal_spi_bus_r;
|
|||
/** Furi Hal Spi Bus D (Display, SdCard) */
|
||||
extern FuriHalSpiBus furi_hal_spi_bus_d;
|
||||
|
||||
/** CC1101 on current SPI bus */
|
||||
extern FuriHalSpiBusHandle furi_hal_spi_bus_handle_subghz;
|
||||
/** CC1101 on `furi_hal_spi_bus_r` */
|
||||
extern FuriHalSpiBusHandle furi_hal_spi_bus_handle_subghz_int;
|
||||
/** CC1101 on external `furi_hal_spi_bus_r` */
|
||||
extern FuriHalSpiBusHandle furi_hal_spi_bus_handle_subghz_ext;
|
||||
extern FuriHalSpiBusHandle furi_hal_spi_bus_handle_subghz;
|
||||
|
||||
/** ST25R3916 on `furi_hal_spi_bus_r` */
|
||||
extern FuriHalSpiBusHandle furi_hal_spi_bus_handle_nfc;
|
||||
|
|
|
@ -1,25 +1,20 @@
|
|||
#include <furi_hal_subghz.h>
|
||||
#include <furi_hal_subghz_configs.h>
|
||||
#include <lib/subghz/devices/cc1101_configs.h>
|
||||
|
||||
#include <furi_hal_version.h>
|
||||
#include <furi_hal_rtc.h>
|
||||
#include <furi_hal_spi.h>
|
||||
#include <furi_hal_interrupt.h>
|
||||
#include <furi_hal_resources.h>
|
||||
#include <furi_hal_power.h>
|
||||
#include <furi_hal_bus.h>
|
||||
|
||||
#include <stm32wbxx_ll_dma.h>
|
||||
|
||||
#include <lib/flipper_format/flipper_format.h>
|
||||
|
||||
#include <furi.h>
|
||||
#include <cc1101.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define TAG "FuriHalSubGhz"
|
||||
//Initialisation timeout (ms)
|
||||
#define INIT_TIMEOUT 10
|
||||
|
||||
static uint32_t furi_hal_subghz_debug_gpio_buff[2];
|
||||
|
||||
|
@ -31,48 +26,45 @@ static uint32_t furi_hal_subghz_debug_gpio_buff[2];
|
|||
#define SUBGHZ_DMA_CH1_DEF SUBGHZ_DMA, SUBGHZ_DMA_CH1_CHANNEL
|
||||
#define SUBGHZ_DMA_CH2_DEF SUBGHZ_DMA, SUBGHZ_DMA_CH2_CHANNEL
|
||||
|
||||
/** SubGhz state */
|
||||
typedef enum {
|
||||
SubGhzStateInit, /**< Init pending */
|
||||
|
||||
SubGhzStateIdle, /**< Idle, energy save mode */
|
||||
|
||||
SubGhzStateAsyncRx, /**< Async RX started */
|
||||
|
||||
SubGhzStateAsyncTx, /**< Async TX started, DMA and timer is on */
|
||||
SubGhzStateAsyncTxLast, /**< Async TX continue, DMA completed and timer got last value to go */
|
||||
SubGhzStateAsyncTxEnd, /**< Async TX complete, cleanup needed */
|
||||
|
||||
} SubGhzState;
|
||||
|
||||
/** SubGhz regulation, receive transmission on the current frequency for the
|
||||
* region */
|
||||
typedef enum {
|
||||
SubGhzRegulationOnlyRx, /**only Rx*/
|
||||
SubGhzRegulationTxRx, /**TxRx*/
|
||||
} SubGhzRegulation;
|
||||
|
||||
typedef struct {
|
||||
volatile SubGhzState state;
|
||||
volatile SubGhzRegulation regulation;
|
||||
const GpioPin* async_mirror_pin;
|
||||
|
||||
uint8_t rolling_counter_mult;
|
||||
bool timestamp_file_names : 1;
|
||||
bool dangerous_frequency_i : 1;
|
||||
} FuriHalSubGhz;
|
||||
|
||||
volatile FuriHalSubGhz furi_hal_subghz = {
|
||||
.state = SubGhzStateInit,
|
||||
.regulation = SubGhzRegulationTxRx,
|
||||
.preset = FuriHalSubGhzPresetIDLE,
|
||||
.async_mirror_pin = NULL,
|
||||
.radio_type = SubGhzRadioInternal,
|
||||
.spi_bus_handle = &furi_hal_spi_bus_handle_subghz,
|
||||
.cc1101_g0_pin = &gpio_cc1101_g0,
|
||||
.rolling_counter_mult = 1,
|
||||
.ext_module_power_disabled = false,
|
||||
.dangerous_frequency_i = false,
|
||||
};
|
||||
|
||||
void furi_hal_subghz_select_radio_type(SubGhzRadioType state) {
|
||||
furi_hal_subghz.radio_type = state;
|
||||
}
|
||||
|
||||
bool furi_hal_subghz_init_radio_type(SubGhzRadioType state) {
|
||||
if(state == SubGhzRadioInternal && furi_hal_subghz.cc1101_g0_pin == &gpio_cc1101_g0) {
|
||||
return true;
|
||||
} else if(state == SubGhzRadioExternal && furi_hal_subghz.cc1101_g0_pin == &gpio_cc1101_g0_ext) {
|
||||
return true;
|
||||
}
|
||||
furi_hal_spi_bus_handle_deinit(furi_hal_subghz.spi_bus_handle);
|
||||
|
||||
if(state == SubGhzRadioInternal) {
|
||||
furi_hal_subghz.spi_bus_handle = &furi_hal_spi_bus_handle_subghz;
|
||||
furi_hal_subghz.cc1101_g0_pin = &gpio_cc1101_g0;
|
||||
} else {
|
||||
furi_hal_subghz.spi_bus_handle = &furi_hal_spi_bus_handle_subghz_ext;
|
||||
furi_hal_subghz.cc1101_g0_pin = &gpio_cc1101_g0_ext;
|
||||
}
|
||||
|
||||
furi_hal_spi_bus_handle_init(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_subghz_init_check();
|
||||
return true;
|
||||
}
|
||||
|
||||
SubGhzRadioType furi_hal_subghz_get_radio_type(void) {
|
||||
return furi_hal_subghz.radio_type;
|
||||
}
|
||||
|
||||
uint8_t furi_hal_subghz_get_rolling_counter_mult(void) {
|
||||
return furi_hal_subghz.rolling_counter_mult;
|
||||
}
|
||||
|
@ -81,14 +73,6 @@ void furi_hal_subghz_set_rolling_counter_mult(uint8_t mult) {
|
|||
furi_hal_subghz.rolling_counter_mult = mult;
|
||||
}
|
||||
|
||||
void furi_hal_subghz_set_external_power_disable(bool state) {
|
||||
furi_hal_subghz.ext_module_power_disabled = state;
|
||||
}
|
||||
|
||||
bool furi_hal_subghz_get_external_power_disable(void) {
|
||||
return furi_hal_subghz.ext_module_power_disabled;
|
||||
}
|
||||
|
||||
void furi_hal_subghz_set_dangerous_frequency(bool state_i) {
|
||||
furi_hal_subghz.dangerous_frequency_i = state_i;
|
||||
}
|
||||
|
@ -97,180 +81,92 @@ void furi_hal_subghz_set_async_mirror_pin(const GpioPin* pin) {
|
|||
furi_hal_subghz.async_mirror_pin = pin;
|
||||
}
|
||||
|
||||
void furi_hal_subghz_init(void) {
|
||||
furi_hal_subghz_init_check();
|
||||
const GpioPin* furi_hal_subghz_get_data_gpio() {
|
||||
return &gpio_cc1101_g0;
|
||||
}
|
||||
|
||||
bool furi_hal_subghz_enable_ext_power(void) {
|
||||
if(furi_hal_subghz.ext_module_power_disabled) {
|
||||
return false;
|
||||
}
|
||||
if(furi_hal_subghz.radio_type != SubGhzRadioInternal) {
|
||||
uint8_t attempts = 0;
|
||||
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
|
||||
furi_hal_power_enable_otg();
|
||||
//CC1101 power-up time
|
||||
furi_delay_ms(10);
|
||||
}
|
||||
}
|
||||
return furi_hal_power_is_otg_enabled();
|
||||
}
|
||||
|
||||
void furi_hal_subghz_disable_ext_power(void) {
|
||||
if(furi_hal_power_is_otg_enabled()) {
|
||||
furi_hal_power_disable_otg();
|
||||
}
|
||||
}
|
||||
|
||||
bool furi_hal_subghz_check_radio(void) {
|
||||
bool result = true;
|
||||
|
||||
furi_hal_subghz_init_radio_type(furi_hal_subghz.radio_type);
|
||||
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
|
||||
uint8_t ver = cc1101_get_version(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
|
||||
if((ver != 0) && (ver != 255)) {
|
||||
FURI_LOG_D(TAG, "Radio check ok");
|
||||
} else {
|
||||
FURI_LOG_D(TAG, "Radio check failed, revert to default");
|
||||
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool furi_hal_subghz_init_check(void) {
|
||||
bool result = true;
|
||||
|
||||
void furi_hal_subghz_init() {
|
||||
furi_assert(furi_hal_subghz.state == SubGhzStateInit);
|
||||
furi_hal_subghz.state = SubGhzStateIdle;
|
||||
furi_hal_subghz.preset = FuriHalSubGhzPresetIDLE;
|
||||
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
|
||||
#ifdef FURI_HAL_SUBGHZ_TX_GPIO
|
||||
furi_hal_gpio_init(&FURI_HAL_SUBGHZ_TX_GPIO, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
#endif
|
||||
|
||||
// Reset
|
||||
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
cc1101_reset(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_write_reg(furi_hal_subghz.spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHighImpedance);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
cc1101_reset(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG0, CC1101IocfgHighImpedance);
|
||||
|
||||
// Prepare GD0 for power on self test
|
||||
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
// GD0 low
|
||||
cc1101_write_reg(furi_hal_subghz.spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHW);
|
||||
uint32_t test_start_time = furi_get_tick();
|
||||
while(furi_hal_gpio_read(furi_hal_subghz.cc1101_g0_pin) != false && result) {
|
||||
if(furi_get_tick() - test_start_time > INIT_TIMEOUT) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG0, CC1101IocfgHW);
|
||||
while(furi_hal_gpio_read(&gpio_cc1101_g0) != false)
|
||||
;
|
||||
|
||||
// GD0 high
|
||||
cc1101_write_reg(
|
||||
furi_hal_subghz.spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHW | CC1101_IOCFG_INV);
|
||||
test_start_time = furi_get_tick();
|
||||
while(furi_hal_gpio_read(furi_hal_subghz.cc1101_g0_pin) != true && result) {
|
||||
if(furi_get_tick() - test_start_time > INIT_TIMEOUT) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG0, CC1101IocfgHW | CC1101_IOCFG_INV);
|
||||
while(furi_hal_gpio_read(&gpio_cc1101_g0) != true)
|
||||
;
|
||||
|
||||
// Reset GD0 to floating state
|
||||
cc1101_write_reg(furi_hal_subghz.spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHighImpedance);
|
||||
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG0, CC1101IocfgHighImpedance);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
// RF switches
|
||||
furi_hal_gpio_init(&gpio_rf_sw_0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
cc1101_write_reg(furi_hal_subghz.spi_bus_handle, CC1101_IOCFG2, CC1101IocfgHW);
|
||||
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG2, CC1101IocfgHW);
|
||||
|
||||
// Go to sleep
|
||||
cc1101_shutdown(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_shutdown(&furi_hal_spi_bus_handle_subghz);
|
||||
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
|
||||
if(result) {
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Selected CC1101 module init failed, revert to default");
|
||||
}
|
||||
return result;
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
}
|
||||
|
||||
void furi_hal_subghz_sleep() {
|
||||
furi_assert(furi_hal_subghz.state == SubGhzStateIdle);
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
|
||||
cc1101_switch_to_idle(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_switch_to_idle(&furi_hal_spi_bus_handle_subghz);
|
||||
|
||||
cc1101_write_reg(furi_hal_subghz.spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHighImpedance);
|
||||
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG0, CC1101IocfgHighImpedance);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
cc1101_shutdown(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_shutdown(&furi_hal_spi_bus_handle_subghz);
|
||||
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
|
||||
furi_hal_subghz.preset = FuriHalSubGhzPresetIDLE;
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
}
|
||||
|
||||
void furi_hal_subghz_dump_state() {
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
printf(
|
||||
"[furi_hal_subghz] cc1101 chip %d, version %d\r\n",
|
||||
cc1101_get_partnumber(furi_hal_subghz.spi_bus_handle),
|
||||
cc1101_get_version(furi_hal_subghz.spi_bus_handle));
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_get_partnumber(&furi_hal_spi_bus_handle_subghz),
|
||||
cc1101_get_version(&furi_hal_spi_bus_handle_subghz));
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
}
|
||||
|
||||
void furi_hal_subghz_load_preset(FuriHalSubGhzPreset preset) {
|
||||
if(preset == FuriHalSubGhzPresetOok650Async) {
|
||||
furi_hal_subghz_load_registers((uint8_t*)furi_hal_subghz_preset_ook_650khz_async_regs);
|
||||
furi_hal_subghz_load_patable(furi_hal_subghz_preset_ook_async_patable);
|
||||
} else if(preset == FuriHalSubGhzPresetOok270Async) {
|
||||
furi_hal_subghz_load_registers((uint8_t*)furi_hal_subghz_preset_ook_270khz_async_regs);
|
||||
furi_hal_subghz_load_patable(furi_hal_subghz_preset_ook_async_patable);
|
||||
} else if(preset == FuriHalSubGhzPreset2FSKDev238Async) {
|
||||
furi_hal_subghz_load_registers(
|
||||
(uint8_t*)furi_hal_subghz_preset_2fsk_dev2_38khz_async_regs);
|
||||
furi_hal_subghz_load_patable(furi_hal_subghz_preset_2fsk_async_patable);
|
||||
} else if(preset == FuriHalSubGhzPreset2FSKDev476Async) {
|
||||
furi_hal_subghz_load_registers(
|
||||
(uint8_t*)furi_hal_subghz_preset_2fsk_dev47_6khz_async_regs);
|
||||
furi_hal_subghz_load_patable(furi_hal_subghz_preset_2fsk_async_patable);
|
||||
} else if(preset == FuriHalSubGhzPresetMSK99_97KbAsync) {
|
||||
furi_hal_subghz_load_registers((uint8_t*)furi_hal_subghz_preset_msk_99_97kb_async_regs);
|
||||
furi_hal_subghz_load_patable(furi_hal_subghz_preset_msk_async_patable);
|
||||
} else if(preset == FuriHalSubGhzPresetGFSK9_99KbAsync) {
|
||||
furi_hal_subghz_load_registers((uint8_t*)furi_hal_subghz_preset_gfsk_9_99kb_async_regs);
|
||||
furi_hal_subghz_load_patable(furi_hal_subghz_preset_gfsk_async_patable);
|
||||
} else {
|
||||
furi_crash("SubGhz: Missing config.");
|
||||
}
|
||||
furi_hal_subghz.preset = preset;
|
||||
}
|
||||
|
||||
void furi_hal_subghz_load_custom_preset(uint8_t* preset_data) {
|
||||
void furi_hal_subghz_load_custom_preset(const uint8_t* preset_data) {
|
||||
//load config
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_reset(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_reset(&furi_hal_spi_bus_handle_subghz);
|
||||
uint32_t i = 0;
|
||||
uint8_t pa[8] = {0};
|
||||
while(preset_data[i]) {
|
||||
cc1101_write_reg(furi_hal_subghz.spi_bus_handle, preset_data[i], preset_data[i + 1]);
|
||||
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, preset_data[i], preset_data[i + 1]);
|
||||
i += 2;
|
||||
}
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
|
||||
//load pa table
|
||||
memcpy(&pa[0], &preset_data[i + 2], 8);
|
||||
furi_hal_subghz_load_patable(pa);
|
||||
furi_hal_subghz.preset = FuriHalSubGhzPresetCustom;
|
||||
|
||||
//show debug
|
||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
||||
|
@ -286,49 +182,49 @@ void furi_hal_subghz_load_custom_preset(uint8_t* preset_data) {
|
|||
}
|
||||
}
|
||||
|
||||
void furi_hal_subghz_load_registers(uint8_t* data) {
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_reset(furi_hal_subghz.spi_bus_handle);
|
||||
void furi_hal_subghz_load_registers(const uint8_t* data) {
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_reset(&furi_hal_spi_bus_handle_subghz);
|
||||
uint32_t i = 0;
|
||||
while(data[i]) {
|
||||
cc1101_write_reg(furi_hal_subghz.spi_bus_handle, data[i], data[i + 1]);
|
||||
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, data[i], data[i + 1]);
|
||||
i += 2;
|
||||
}
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
}
|
||||
|
||||
void furi_hal_subghz_load_patable(const uint8_t data[8]) {
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_set_pa_table(furi_hal_subghz.spi_bus_handle, data);
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_set_pa_table(&furi_hal_spi_bus_handle_subghz, data);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
}
|
||||
|
||||
void furi_hal_subghz_write_packet(const uint8_t* data, uint8_t size) {
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_flush_tx(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_write_reg(furi_hal_subghz.spi_bus_handle, CC1101_FIFO, size);
|
||||
cc1101_write_fifo(furi_hal_subghz.spi_bus_handle, data, size);
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_flush_tx(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_FIFO, size);
|
||||
cc1101_write_fifo(&furi_hal_spi_bus_handle_subghz, data, size);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
}
|
||||
|
||||
void furi_hal_subghz_flush_rx() {
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_flush_rx(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_flush_rx(&furi_hal_spi_bus_handle_subghz);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
}
|
||||
|
||||
void furi_hal_subghz_flush_tx() {
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_flush_tx(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_flush_tx(&furi_hal_spi_bus_handle_subghz);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
}
|
||||
|
||||
bool furi_hal_subghz_rx_pipe_not_empty() {
|
||||
CC1101RxBytes status[1];
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_read_reg(
|
||||
furi_hal_subghz.spi_bus_handle, (CC1101_STATUS_RXBYTES) | CC1101_BURST, (uint8_t*)status);
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
&furi_hal_spi_bus_handle_subghz, (CC1101_STATUS_RXBYTES) | CC1101_BURST, (uint8_t*)status);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
// TODO: you can add a buffer overflow flag if needed
|
||||
if(status->NUM_RXBYTES > 0) {
|
||||
return true;
|
||||
|
@ -338,10 +234,10 @@ bool furi_hal_subghz_rx_pipe_not_empty() {
|
|||
}
|
||||
|
||||
bool furi_hal_subghz_is_rx_data_crc_valid() {
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
uint8_t data[1];
|
||||
cc1101_read_reg(furi_hal_subghz.spi_bus_handle, CC1101_STATUS_LQI | CC1101_BURST, data);
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_read_reg(&furi_hal_spi_bus_handle_subghz, CC1101_STATUS_LQI | CC1101_BURST, data);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
if(((data[0] >> 7) & 0x01)) {
|
||||
return true;
|
||||
} else {
|
||||
|
@ -350,51 +246,51 @@ bool furi_hal_subghz_is_rx_data_crc_valid() {
|
|||
}
|
||||
|
||||
void furi_hal_subghz_read_packet(uint8_t* data, uint8_t* size) {
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_read_fifo(furi_hal_subghz.spi_bus_handle, data, size);
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_read_fifo(&furi_hal_spi_bus_handle_subghz, data, size);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
}
|
||||
|
||||
void furi_hal_subghz_shutdown() {
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
// Reset and shutdown
|
||||
cc1101_shutdown(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_shutdown(&furi_hal_spi_bus_handle_subghz);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
}
|
||||
|
||||
void furi_hal_subghz_reset() {
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
cc1101_switch_to_idle(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_reset(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_write_reg(furi_hal_subghz.spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHighImpedance);
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
cc1101_switch_to_idle(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_reset(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG0, CC1101IocfgHighImpedance);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
}
|
||||
|
||||
void furi_hal_subghz_idle() {
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_switch_to_idle(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_switch_to_idle(&furi_hal_spi_bus_handle_subghz);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
}
|
||||
|
||||
void furi_hal_subghz_rx() {
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_switch_to_rx(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_switch_to_rx(&furi_hal_spi_bus_handle_subghz);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
}
|
||||
|
||||
bool furi_hal_subghz_tx() {
|
||||
if(furi_hal_subghz.regulation != SubGhzRegulationTxRx) return false;
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_switch_to_tx(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
||||
float furi_hal_subghz_get_rssi() {
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
int32_t rssi_dec = cc1101_get_rssi(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
int32_t rssi_dec = cc1101_get_rssi(&furi_hal_spi_bus_handle_subghz);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
|
||||
float rssi = rssi_dec;
|
||||
if(rssi_dec >= 128) {
|
||||
|
@ -407,10 +303,10 @@ float furi_hal_subghz_get_rssi() {
|
|||
}
|
||||
|
||||
uint8_t furi_hal_subghz_get_lqi() {
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
uint8_t data[1];
|
||||
cc1101_read_reg(furi_hal_subghz.spi_bus_handle, CC1101_STATUS_LQI | CC1101_BURST, data);
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
cc1101_read_reg(&furi_hal_spi_bus_handle_subghz, CC1101_STATUS_LQI | CC1101_BURST, data);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
return data[0] & 0x7F;
|
||||
}
|
||||
|
||||
|
@ -455,9 +351,7 @@ bool furi_hal_subghz_is_tx_allowed(uint32_t value) {
|
|||
return false;
|
||||
} else if(
|
||||
(allow_extended_for_int) && //
|
||||
!(value >= 281000000 && value <= 361000000) &&
|
||||
!(value >= 378000000 && value <= 481000000) &&
|
||||
!(value >= 749000000 && value <= 962000000)) {
|
||||
!furi_hal_subghz_is_frequency_valid(value)) {
|
||||
FURI_LOG_I(TAG, "Frequency blocked - outside dangerous range");
|
||||
return false;
|
||||
}
|
||||
|
@ -466,41 +360,45 @@ bool furi_hal_subghz_is_tx_allowed(uint32_t value) {
|
|||
}
|
||||
|
||||
uint32_t furi_hal_subghz_set_frequency(uint32_t value) {
|
||||
furi_hal_subghz.regulation = SubGhzRegulationTxRx;
|
||||
if(furi_hal_subghz_is_tx_allowed(value)) {
|
||||
furi_hal_subghz.regulation = SubGhzRegulationTxRx;
|
||||
} else {
|
||||
furi_hal_subghz.regulation = SubGhzRegulationOnlyRx;
|
||||
}
|
||||
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
uint32_t real_frequency = cc1101_set_frequency(furi_hal_subghz.spi_bus_handle, value);
|
||||
cc1101_calibrate(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
uint32_t real_frequency = cc1101_set_frequency(&furi_hal_spi_bus_handle_subghz, value);
|
||||
cc1101_calibrate(&furi_hal_spi_bus_handle_subghz);
|
||||
|
||||
while(true) {
|
||||
CC1101Status status = cc1101_get_status(furi_hal_subghz.spi_bus_handle);
|
||||
CC1101Status status = cc1101_get_status(&furi_hal_spi_bus_handle_subghz);
|
||||
if(status.STATE == CC1101StateIDLE) break;
|
||||
}
|
||||
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
return real_frequency;
|
||||
}
|
||||
|
||||
void furi_hal_subghz_set_path(FuriHalSubGhzPath path) {
|
||||
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
if(path == FuriHalSubGhzPath433) {
|
||||
furi_hal_gpio_write(&gpio_rf_sw_0, 0);
|
||||
cc1101_write_reg(
|
||||
furi_hal_subghz.spi_bus_handle, CC1101_IOCFG2, CC1101IocfgHW | CC1101_IOCFG_INV);
|
||||
&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG2, CC1101IocfgHW | CC1101_IOCFG_INV);
|
||||
} else if(path == FuriHalSubGhzPath315) {
|
||||
furi_hal_gpio_write(&gpio_rf_sw_0, 1);
|
||||
cc1101_write_reg(furi_hal_subghz.spi_bus_handle, CC1101_IOCFG2, CC1101IocfgHW);
|
||||
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG2, CC1101IocfgHW);
|
||||
} else if(path == FuriHalSubGhzPath868) {
|
||||
furi_hal_gpio_write(&gpio_rf_sw_0, 1);
|
||||
cc1101_write_reg(
|
||||
furi_hal_subghz.spi_bus_handle, CC1101_IOCFG2, CC1101IocfgHW | CC1101_IOCFG_INV);
|
||||
&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG2, CC1101IocfgHW | CC1101_IOCFG_INV);
|
||||
} else if(path == FuriHalSubGhzPathIsolate) {
|
||||
furi_hal_gpio_write(&gpio_rf_sw_0, 0);
|
||||
cc1101_write_reg(furi_hal_subghz.spi_bus_handle, CC1101_IOCFG2, CC1101IocfgHW);
|
||||
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG2, CC1101IocfgHW);
|
||||
} else {
|
||||
furi_crash("SubGhz: Incorrect path during set.");
|
||||
}
|
||||
furi_hal_spi_release(furi_hal_subghz.spi_bus_handle);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
}
|
||||
|
||||
static bool furi_hal_subghz_start_debug() {
|
||||
|
@ -530,7 +428,7 @@ volatile uint32_t furi_hal_subghz_capture_delta_duration = 0;
|
|||
volatile FuriHalSubGhzCaptureCallback furi_hal_subghz_capture_callback = NULL;
|
||||
volatile void* furi_hal_subghz_capture_callback_context = NULL;
|
||||
|
||||
static void furi_hal_subghz_capture_int_ISR() {
|
||||
static void furi_hal_subghz_capture_ISR() {
|
||||
// Channel 1
|
||||
if(LL_TIM_IsActiveFlag_CC1(TIM2)) {
|
||||
LL_TIM_ClearFlag_CC1(TIM2);
|
||||
|
@ -560,27 +458,6 @@ static void furi_hal_subghz_capture_int_ISR() {
|
|||
}
|
||||
}
|
||||
|
||||
static void furi_hal_subghz_capture_ext_ISR() {
|
||||
if(!furi_hal_gpio_read(furi_hal_subghz.cc1101_g0_pin)) {
|
||||
if(furi_hal_subghz_capture_callback) {
|
||||
if(furi_hal_subghz.async_mirror_pin != NULL)
|
||||
furi_hal_gpio_write(furi_hal_subghz.async_mirror_pin, false);
|
||||
|
||||
furi_hal_subghz_capture_callback(
|
||||
true, TIM2->CNT, (void*)furi_hal_subghz_capture_callback_context);
|
||||
}
|
||||
} else {
|
||||
if(furi_hal_subghz_capture_callback) {
|
||||
if(furi_hal_subghz.async_mirror_pin != NULL)
|
||||
furi_hal_gpio_write(furi_hal_subghz.async_mirror_pin, true);
|
||||
|
||||
furi_hal_subghz_capture_callback(
|
||||
false, TIM2->CNT, (void*)furi_hal_subghz_capture_callback_context);
|
||||
}
|
||||
}
|
||||
TIM2->CNT = 6;
|
||||
}
|
||||
|
||||
void furi_hal_subghz_start_async_rx(FuriHalSubGhzCaptureCallback callback, void* context) {
|
||||
furi_assert(furi_hal_subghz.state == SubGhzStateIdle);
|
||||
furi_hal_subghz.state = SubGhzStateAsyncRx;
|
||||
|
@ -588,6 +465,9 @@ void furi_hal_subghz_start_async_rx(FuriHalSubGhzCaptureCallback callback, void*
|
|||
furi_hal_subghz_capture_callback = callback;
|
||||
furi_hal_subghz_capture_callback_context = context;
|
||||
|
||||
furi_hal_gpio_init_ex(
|
||||
&gpio_cc1101_g0, GpioModeAltFunctionPushPull, GpioPullNo, GpioSpeedLow, GpioAltFn1TIM2);
|
||||
|
||||
furi_hal_bus_enable(FuriHalBusTIM2);
|
||||
|
||||
// Timer: base
|
||||
|
@ -595,62 +475,42 @@ void furi_hal_subghz_start_async_rx(FuriHalSubGhzCaptureCallback callback, void*
|
|||
TIM_InitStruct.Prescaler = 64 - 1;
|
||||
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
|
||||
TIM_InitStruct.Autoreload = 0x7FFFFFFE;
|
||||
// Clock division for capture filter (for internal radio)
|
||||
// Clock division for capture filter
|
||||
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV4;
|
||||
LL_TIM_Init(TIM2, &TIM_InitStruct);
|
||||
|
||||
// Timer: advanced
|
||||
LL_TIM_SetClockSource(TIM2, LL_TIM_CLOCKSOURCE_INTERNAL);
|
||||
LL_TIM_DisableARRPreload(TIM2);
|
||||
LL_TIM_SetTriggerInput(TIM2, LL_TIM_TS_TI2FP2);
|
||||
LL_TIM_SetSlaveMode(TIM2, LL_TIM_SLAVEMODE_RESET);
|
||||
LL_TIM_SetTriggerOutput(TIM2, LL_TIM_TRGO_RESET);
|
||||
LL_TIM_EnableMasterSlaveMode(TIM2);
|
||||
LL_TIM_DisableDMAReq_TRIG(TIM2);
|
||||
LL_TIM_DisableIT_TRIG(TIM2);
|
||||
|
||||
if(furi_hal_subghz.radio_type == SubGhzRadioInternal) {
|
||||
LL_TIM_SetTriggerInput(TIM2, LL_TIM_TS_TI2FP2);
|
||||
LL_TIM_SetSlaveMode(TIM2, LL_TIM_SLAVEMODE_RESET);
|
||||
LL_TIM_SetTriggerOutput(TIM2, LL_TIM_TRGO_RESET);
|
||||
LL_TIM_EnableMasterSlaveMode(TIM2);
|
||||
// Timer: channel 1 indirect
|
||||
LL_TIM_IC_SetActiveInput(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_ACTIVEINPUT_INDIRECTTI);
|
||||
LL_TIM_IC_SetPrescaler(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_ICPSC_DIV1);
|
||||
LL_TIM_IC_SetPolarity(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_IC_POLARITY_FALLING);
|
||||
|
||||
// Timer: channel 1 indirect
|
||||
LL_TIM_IC_SetActiveInput(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_ACTIVEINPUT_INDIRECTTI);
|
||||
LL_TIM_IC_SetPrescaler(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_ICPSC_DIV1);
|
||||
LL_TIM_IC_SetPolarity(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_IC_POLARITY_FALLING);
|
||||
LL_TIM_IC_SetFilter(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_IC_FILTER_FDIV1);
|
||||
// Timer: channel 2 direct
|
||||
LL_TIM_IC_SetActiveInput(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_ACTIVEINPUT_DIRECTTI);
|
||||
LL_TIM_IC_SetPrescaler(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_ICPSC_DIV1);
|
||||
LL_TIM_IC_SetPolarity(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_IC_POLARITY_RISING);
|
||||
LL_TIM_IC_SetFilter(
|
||||
TIM2,
|
||||
LL_TIM_CHANNEL_CH2,
|
||||
LL_TIM_IC_FILTER_FDIV32_N8); // Capture filter: 1/(64000000/64/4/32*8) = 16us
|
||||
|
||||
// Timer: channel 2 direct
|
||||
LL_TIM_IC_SetActiveInput(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_ACTIVEINPUT_DIRECTTI);
|
||||
LL_TIM_IC_SetPrescaler(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_ICPSC_DIV1);
|
||||
LL_TIM_IC_SetPolarity(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_IC_POLARITY_RISING);
|
||||
LL_TIM_IC_SetFilter(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_IC_FILTER_FDIV32_N8);
|
||||
// ISR setup
|
||||
furi_hal_interrupt_set_isr(FuriHalInterruptIdTIM2, furi_hal_subghz_capture_ISR, NULL);
|
||||
|
||||
// ISR setup
|
||||
furi_hal_interrupt_set_isr(FuriHalInterruptIdTIM2, furi_hal_subghz_capture_int_ISR, NULL);
|
||||
|
||||
// Interrupts and channels
|
||||
LL_TIM_EnableIT_CC1(TIM2);
|
||||
LL_TIM_EnableIT_CC2(TIM2);
|
||||
LL_TIM_CC_EnableChannel(TIM2, LL_TIM_CHANNEL_CH1);
|
||||
LL_TIM_CC_EnableChannel(TIM2, LL_TIM_CHANNEL_CH2);
|
||||
|
||||
furi_hal_gpio_init_ex(
|
||||
furi_hal_subghz.cc1101_g0_pin,
|
||||
GpioModeAltFunctionPushPull,
|
||||
GpioPullNo,
|
||||
GpioSpeedLow,
|
||||
GpioAltFn1TIM2);
|
||||
} else {
|
||||
furi_hal_gpio_init(
|
||||
furi_hal_subghz.cc1101_g0_pin,
|
||||
GpioModeInterruptRiseFall,
|
||||
GpioPullUp,
|
||||
GpioSpeedVeryHigh);
|
||||
furi_hal_gpio_disable_int_callback(furi_hal_subghz.cc1101_g0_pin);
|
||||
furi_hal_gpio_remove_int_callback(furi_hal_subghz.cc1101_g0_pin);
|
||||
furi_hal_gpio_add_int_callback(
|
||||
furi_hal_subghz.cc1101_g0_pin,
|
||||
furi_hal_subghz_capture_ext_ISR,
|
||||
furi_hal_subghz_capture_callback);
|
||||
}
|
||||
// Interrupts and channels
|
||||
LL_TIM_EnableIT_CC1(TIM2);
|
||||
LL_TIM_EnableIT_CC2(TIM2);
|
||||
LL_TIM_CC_EnableChannel(TIM2, LL_TIM_CHANNEL_CH1);
|
||||
LL_TIM_CC_EnableChannel(TIM2, LL_TIM_CHANNEL_CH2);
|
||||
|
||||
// Start timer
|
||||
LL_TIM_SetCounter(TIM2, 0);
|
||||
|
@ -680,14 +540,9 @@ void furi_hal_subghz_stop_async_rx() {
|
|||
furi_hal_subghz_stop_debug();
|
||||
|
||||
FURI_CRITICAL_EXIT();
|
||||
if(furi_hal_subghz.radio_type == SubGhzRadioInternal) {
|
||||
furi_hal_interrupt_set_isr(FuriHalInterruptIdTIM2, NULL, NULL);
|
||||
} else {
|
||||
furi_hal_gpio_disable_int_callback(furi_hal_subghz.cc1101_g0_pin);
|
||||
furi_hal_gpio_remove_int_callback(furi_hal_subghz.cc1101_g0_pin);
|
||||
}
|
||||
furi_hal_interrupt_set_isr(FuriHalInterruptIdTIM2, NULL, NULL);
|
||||
|
||||
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
|
@ -791,8 +646,7 @@ static void furi_hal_subghz_async_tx_timer_isr() {
|
|||
} else if(furi_hal_subghz.state == SubGhzStateAsyncTxLast) {
|
||||
furi_hal_subghz.state = SubGhzStateAsyncTxEnd;
|
||||
//forcibly pulls the pin to the ground so that there is no carrier
|
||||
furi_hal_gpio_init(
|
||||
furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullDown, GpioSpeedLow);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullDown, GpioSpeedLow);
|
||||
LL_TIM_DisableCounter(TIM2);
|
||||
} else {
|
||||
furi_crash(NULL);
|
||||
|
@ -819,20 +673,9 @@ bool furi_hal_subghz_start_async_tx(FuriHalSubGhzAsyncTxCallback callback, void*
|
|||
furi_hal_subghz_async_tx.buffer =
|
||||
malloc(API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL * sizeof(uint32_t));
|
||||
|
||||
if(furi_hal_subghz.radio_type == SubGhzRadioInternal) {
|
||||
// Connect CC1101_GD0 to TIM2 as output
|
||||
furi_hal_gpio_init_ex(
|
||||
furi_hal_subghz.cc1101_g0_pin,
|
||||
GpioModeAltFunctionPushPull,
|
||||
GpioPullDown,
|
||||
GpioSpeedLow,
|
||||
GpioAltFn1TIM2);
|
||||
} else {
|
||||
//Signal generation with mem-to-mem DMA
|
||||
furi_hal_gpio_write(furi_hal_subghz.cc1101_g0_pin, true);
|
||||
furi_hal_gpio_init(
|
||||
furi_hal_subghz.cc1101_g0_pin, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh);
|
||||
}
|
||||
// Connect CC1101_GD0 to TIM2 as output
|
||||
furi_hal_gpio_init_ex(
|
||||
&gpio_cc1101_g0, GpioModeAltFunctionPushPull, GpioPullDown, GpioSpeedLow, GpioAltFn1TIM2);
|
||||
|
||||
// Configure DMA
|
||||
LL_DMA_InitTypeDef dma_config = {0};
|
||||
|
@ -895,27 +738,15 @@ bool furi_hal_subghz_start_async_tx(FuriHalSubGhzAsyncTxCallback callback, void*
|
|||
LL_TIM_EnableCounter(TIM2);
|
||||
|
||||
// Start debug
|
||||
if(furi_hal_subghz_start_debug() || furi_hal_subghz.radio_type == SubGhzRadioExternal) {
|
||||
const GpioPin* gpio = furi_hal_subghz.cc1101_g0_pin;
|
||||
//Preparing bit mask
|
||||
//Debug pin is may be only PORTB! (PB0, PB1, .., PB15)
|
||||
furi_hal_subghz_debug_gpio_buff[0] = 0;
|
||||
furi_hal_subghz_debug_gpio_buff[1] = 0;
|
||||
if(furi_hal_subghz_start_debug()) {
|
||||
const GpioPin* gpio = furi_hal_subghz.async_mirror_pin;
|
||||
// //Preparing bit mask
|
||||
// //Debug pin is may be only PORTB! (PB0, PB1, .., PB15)
|
||||
// furi_hal_subghz_debug_gpio_buff[0] = 0;
|
||||
// furi_hal_subghz_debug_gpio_buff[1] = 0;
|
||||
|
||||
//Mirror pin (for example, speaker)
|
||||
if(furi_hal_subghz.async_mirror_pin != NULL) {
|
||||
furi_hal_subghz_debug_gpio_buff[0] |= (uint32_t)furi_hal_subghz.async_mirror_pin->pin
|
||||
<< GPIO_NUMBER;
|
||||
furi_hal_subghz_debug_gpio_buff[1] |= furi_hal_subghz.async_mirror_pin->pin;
|
||||
gpio = furi_hal_subghz.async_mirror_pin;
|
||||
}
|
||||
|
||||
//G0 singnal generation for external radio
|
||||
if(furi_hal_subghz.radio_type == SubGhzRadioExternal) {
|
||||
furi_hal_subghz_debug_gpio_buff[0] |= (uint32_t)furi_hal_subghz.cc1101_g0_pin->pin
|
||||
<< GPIO_NUMBER;
|
||||
furi_hal_subghz_debug_gpio_buff[1] |= furi_hal_subghz.cc1101_g0_pin->pin;
|
||||
}
|
||||
furi_hal_subghz_debug_gpio_buff[0] = (uint32_t)gpio->pin << GPIO_NUMBER;
|
||||
furi_hal_subghz_debug_gpio_buff[1] = gpio->pin;
|
||||
|
||||
dma_config.MemoryOrM2MDstAddress = (uint32_t)furi_hal_subghz_debug_gpio_buff;
|
||||
dma_config.PeriphOrM2MSrcAddress = (uint32_t) & (gpio->port->BSRR);
|
||||
|
@ -948,9 +779,9 @@ void furi_hal_subghz_stop_async_tx() {
|
|||
|
||||
// Shutdown radio
|
||||
furi_hal_subghz_idle();
|
||||
if(furi_hal_subghz.radio_type == SubGhzRadioExternal) {
|
||||
furi_hal_gpio_write(furi_hal_subghz.cc1101_g0_pin, false);
|
||||
}
|
||||
#ifdef FURI_HAL_SUBGHZ_TX_GPIO
|
||||
furi_hal_gpio_write(&FURI_HAL_SUBGHZ_TX_GPIO, false);
|
||||
#endif
|
||||
|
||||
// Deinitialize Timer
|
||||
FURI_CRITICAL_ENTER();
|
||||
|
@ -963,14 +794,10 @@ void furi_hal_subghz_stop_async_tx() {
|
|||
furi_hal_interrupt_set_isr(SUBGHZ_DMA_CH1_IRQ, NULL, NULL);
|
||||
|
||||
// Deinitialize GPIO
|
||||
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
// Stop debug
|
||||
furi_hal_subghz_stop_debug();
|
||||
|
||||
if(((furi_hal_subghz.async_mirror_pin != NULL) &&
|
||||
(furi_hal_subghz.radio_type == SubGhzRadioInternal)) ||
|
||||
(furi_hal_subghz.radio_type == SubGhzRadioExternal)) {
|
||||
if(furi_hal_subghz_stop_debug()) {
|
||||
LL_DMA_DisableChannel(SUBGHZ_DMA_CH2_DEF);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,12 +5,14 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <lib/subghz/devices/preset.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <toolbox/level_duration.h>
|
||||
#include <furi_hal_gpio.h>
|
||||
#include <furi_hal_spi_types.h>
|
||||
// #include <furi_hal_spi_types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -21,18 +23,6 @@ extern "C" {
|
|||
#define API_HAL_SUBGHZ_ASYNC_TX_BUFFER_HALF (API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL / 2)
|
||||
#define API_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME 999
|
||||
|
||||
/** Radio Presets */
|
||||
typedef enum {
|
||||
FuriHalSubGhzPresetIDLE, /**< default configuration */
|
||||
FuriHalSubGhzPresetOok270Async, /**< OOK, bandwidth 270kHz, asynchronous */
|
||||
FuriHalSubGhzPresetOok650Async, /**< OOK, bandwidth 650kHz, asynchronous */
|
||||
FuriHalSubGhzPreset2FSKDev238Async, /**< FM, deviation 2.380371 kHz, asynchronous */
|
||||
FuriHalSubGhzPreset2FSKDev476Async, /**< FM, deviation 47.60742 kHz, asynchronous */
|
||||
FuriHalSubGhzPresetMSK99_97KbAsync, /**< MSK, deviation 47.60742 kHz, 99.97Kb/s, asynchronous */
|
||||
FuriHalSubGhzPresetGFSK9_99KbAsync, /**< GFSK, deviation 19.042969 kHz, 9.996Kb/s, asynchronous */
|
||||
FuriHalSubGhzPresetCustom, /**Custom Preset*/
|
||||
} FuriHalSubGhzPreset;
|
||||
|
||||
/** Switchable Radio Paths */
|
||||
typedef enum {
|
||||
FuriHalSubGhzPathIsolate, /**< Isolate Radio from antenna */
|
||||
|
@ -41,50 +31,6 @@ typedef enum {
|
|||
FuriHalSubGhzPath868, /**< Center Frequency: 868MHz. Path 3: SW1RF3-SW2RF3, LCLC */
|
||||
} FuriHalSubGhzPath;
|
||||
|
||||
/** SubGhz state */
|
||||
typedef enum {
|
||||
SubGhzStateInit, /**< Init pending */
|
||||
|
||||
SubGhzStateIdle, /**< Idle, energy save mode */
|
||||
|
||||
SubGhzStateAsyncRx, /**< Async RX started */
|
||||
|
||||
SubGhzStateAsyncTx, /**< Async TX started, DMA and timer is on */
|
||||
SubGhzStateAsyncTxLast, /**< Async TX continue, DMA completed and timer got last value to go */
|
||||
SubGhzStateAsyncTxEnd, /**< Async TX complete, cleanup needed */
|
||||
|
||||
} SubGhzState;
|
||||
|
||||
/** SubGhz regulation, receive transmission on the current frequency for the
|
||||
* region */
|
||||
typedef enum {
|
||||
SubGhzRegulationOnlyRx, /**only Rx*/
|
||||
SubGhzRegulationTxRx, /**TxRx*/
|
||||
} SubGhzRegulation;
|
||||
|
||||
/** SubGhz radio types */
|
||||
typedef enum {
|
||||
SubGhzRadioInternal,
|
||||
SubGhzRadioExternal,
|
||||
} SubGhzRadioType;
|
||||
|
||||
/** Structure for accessing SubGhz settings*/
|
||||
typedef struct {
|
||||
volatile SubGhzState state;
|
||||
volatile SubGhzRegulation regulation;
|
||||
volatile FuriHalSubGhzPreset preset;
|
||||
const GpioPin* async_mirror_pin;
|
||||
SubGhzRadioType radio_type;
|
||||
FuriHalSpiBusHandle* spi_bus_handle;
|
||||
const GpioPin* cc1101_g0_pin;
|
||||
uint8_t rolling_counter_mult;
|
||||
bool ext_module_power_disabled : 1;
|
||||
bool timestamp_file_names : 1;
|
||||
bool dangerous_frequency_i : 1;
|
||||
} FuriHalSubGhz;
|
||||
|
||||
extern volatile FuriHalSubGhz furi_hal_subghz;
|
||||
|
||||
/* Mirror RX/TX async modulation signal to specified pin
|
||||
*
|
||||
* @warning Configures pin to output mode. Make sure it is not connected
|
||||
|
@ -94,19 +40,18 @@ extern volatile FuriHalSubGhz furi_hal_subghz;
|
|||
*/
|
||||
void furi_hal_subghz_set_async_mirror_pin(const GpioPin* pin);
|
||||
|
||||
/** Get data GPIO
|
||||
*
|
||||
* @return pointer to the gpio pin structure
|
||||
*/
|
||||
const GpioPin* furi_hal_subghz_get_data_gpio();
|
||||
|
||||
/** Initialize and switch to power save mode Used by internal API-HAL
|
||||
* initialization routine Can be used to reinitialize device to safe state and
|
||||
* send it to sleep
|
||||
*/
|
||||
void furi_hal_subghz_init();
|
||||
|
||||
/** Initialize and switch to power save mode Used by internal API-HAL
|
||||
* initialization routine Can be used to reinitialize device to safe state and
|
||||
* send it to sleep
|
||||
* @return true if initialisation is successfully
|
||||
*/
|
||||
bool furi_hal_subghz_init_check(void);
|
||||
|
||||
/** Send device to sleep mode
|
||||
*/
|
||||
void furi_hal_subghz_sleep();
|
||||
|
@ -115,23 +60,17 @@ void furi_hal_subghz_sleep();
|
|||
*/
|
||||
void furi_hal_subghz_dump_state();
|
||||
|
||||
/** Load registers from preset by preset name
|
||||
*
|
||||
* @param preset to load
|
||||
*/
|
||||
void furi_hal_subghz_load_preset(FuriHalSubGhzPreset preset);
|
||||
|
||||
/** Load custom registers from preset
|
||||
*
|
||||
* @param preset_data registers to load
|
||||
*/
|
||||
void furi_hal_subghz_load_custom_preset(uint8_t* preset_data);
|
||||
void furi_hal_subghz_load_custom_preset(const uint8_t* preset_data);
|
||||
|
||||
/** Load registers
|
||||
*
|
||||
* @param data Registers data
|
||||
*/
|
||||
void furi_hal_subghz_load_registers(uint8_t* data);
|
||||
void furi_hal_subghz_load_registers(const uint8_t* data);
|
||||
|
||||
/** Load PATABLE
|
||||
*
|
||||
|
@ -234,6 +173,16 @@ uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value);
|
|||
*/
|
||||
bool furi_hal_subghz_is_tx_allowed(uint32_t value);
|
||||
|
||||
/** Get the current rolling protocols counter ++ value
|
||||
* @return uint8_t current value
|
||||
*/
|
||||
uint8_t furi_hal_subghz_get_rolling_counter_mult(void);
|
||||
|
||||
/** Set the current rolling protocols counter ++ value
|
||||
* @param mult uint8_t = 1, 2, 4, 8
|
||||
*/
|
||||
void furi_hal_subghz_set_rolling_counter_mult(uint8_t mult);
|
||||
|
||||
/** Set frequency
|
||||
*
|
||||
* @param value frequency in Hz
|
||||
|
@ -289,52 +238,49 @@ bool furi_hal_subghz_is_async_tx_complete();
|
|||
*/
|
||||
void furi_hal_subghz_stop_async_tx();
|
||||
|
||||
/** Switching between internal and external radio
|
||||
* @param state SubGhzRadioInternal or SubGhzRadioExternal
|
||||
* @return true if switching is successful
|
||||
*/
|
||||
bool furi_hal_subghz_init_radio_type(SubGhzRadioType state);
|
||||
// /** Initialize and switch to power save mode Used by internal API-HAL
|
||||
// * initialization routine Can be used to reinitialize device to safe state and
|
||||
// * send it to sleep
|
||||
// * @return true if initialisation is successfully
|
||||
// */
|
||||
// bool furi_hal_subghz_init_check(void);
|
||||
|
||||
/** Get current radio
|
||||
* @return SubGhzRadioInternal or SubGhzRadioExternal
|
||||
*/
|
||||
SubGhzRadioType furi_hal_subghz_get_radio_type(void);
|
||||
// /** Switching between internal and external radio
|
||||
// * @param state SubGhzRadioInternal or SubGhzRadioExternal
|
||||
// * @return true if switching is successful
|
||||
// */
|
||||
// bool furi_hal_subghz_init_radio_type(SubGhzRadioType state);
|
||||
|
||||
/** Check for a radio module
|
||||
* @return true if check is successful
|
||||
*/
|
||||
bool furi_hal_subghz_check_radio(void);
|
||||
// /** Get current radio
|
||||
// * @return SubGhzRadioInternal or SubGhzRadioExternal
|
||||
// */
|
||||
// SubGhzRadioType furi_hal_subghz_get_radio_type(void);
|
||||
|
||||
/** Turn on the power of the external radio module
|
||||
* @return true if power-up is successful
|
||||
*/
|
||||
bool furi_hal_subghz_enable_ext_power(void);
|
||||
// /** Check for a radio module
|
||||
// * @return true if check is successful
|
||||
// */
|
||||
// bool furi_hal_subghz_check_radio(void);
|
||||
|
||||
/** Turn off the power of the external radio module
|
||||
*/
|
||||
void furi_hal_subghz_disable_ext_power(void);
|
||||
// /** Turn on the power of the external radio module
|
||||
// * @return true if power-up is successful
|
||||
// */
|
||||
// bool furi_hal_subghz_enable_ext_power(void);
|
||||
|
||||
/** Get the current rolling protocols counter ++ value
|
||||
* @return uint8_t current value
|
||||
*/
|
||||
uint8_t furi_hal_subghz_get_rolling_counter_mult(void);
|
||||
// /** Turn off the power of the external radio module
|
||||
// */
|
||||
// void furi_hal_subghz_disable_ext_power(void);
|
||||
|
||||
/** Set the current rolling protocols counter ++ value
|
||||
* @param mult uint8_t = 1, 2, 4, 8
|
||||
*/
|
||||
void furi_hal_subghz_set_rolling_counter_mult(uint8_t mult);
|
||||
// /** If true - disable 5v power of the external radio module
|
||||
// */
|
||||
// void furi_hal_subghz_set_external_power_disable(bool state);
|
||||
|
||||
/** If true - disable 5v power of the external radio module
|
||||
*/
|
||||
void furi_hal_subghz_set_external_power_disable(bool state);
|
||||
// /** Get the current state of the external power disable flag
|
||||
// */
|
||||
// bool furi_hal_subghz_get_external_power_disable(void);
|
||||
|
||||
/** Get the current state of the external power disable flag
|
||||
*/
|
||||
bool furi_hal_subghz_get_external_power_disable(void);
|
||||
|
||||
/** Set what radio module we will be using
|
||||
*/
|
||||
void furi_hal_subghz_select_radio_type(SubGhzRadioType state);
|
||||
// /** Set what radio module we will be using
|
||||
// */
|
||||
// void furi_hal_subghz_select_radio_type(SubGhzRadioType state);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,304 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <cc1101.h>
|
||||
|
||||
static const uint8_t furi_hal_subghz_preset_ook_270khz_async_regs[][2] = {
|
||||
// https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/382066/cc1101---don-t-know-the-correct-registers-configuration
|
||||
|
||||
/* GPIO GD0 */
|
||||
{CC1101_IOCFG0, 0x0D}, // GD0 as async serial data output/input
|
||||
|
||||
/* FIFO and internals */
|
||||
{CC1101_FIFOTHR, 0x47}, // The only important bit is ADC_RETENTION, FIFO Tx=33 Rx=32
|
||||
|
||||
/* Packet engine */
|
||||
{CC1101_PKTCTRL0, 0x32}, // Async, continious, no whitening
|
||||
|
||||
/* Frequency Synthesizer Control */
|
||||
{CC1101_FSCTRL1, 0x06}, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
|
||||
|
||||
// Modem Configuration
|
||||
{CC1101_MDMCFG0, 0x00}, // Channel spacing is 25kHz
|
||||
{CC1101_MDMCFG1, 0x00}, // Channel spacing is 25kHz
|
||||
{CC1101_MDMCFG2, 0x30}, // Format ASK/OOK, No preamble/sync
|
||||
{CC1101_MDMCFG3, 0x32}, // Data rate is 3.79372 kBaud
|
||||
{CC1101_MDMCFG4, 0x67}, // Rx BW filter is 270.833333kHz
|
||||
|
||||
/* Main Radio Control State Machine */
|
||||
{CC1101_MCSM0, 0x18}, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
|
||||
|
||||
/* Frequency Offset Compensation Configuration */
|
||||
{CC1101_FOCCFG,
|
||||
0x18}, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
|
||||
|
||||
/* Automatic Gain Control */
|
||||
{CC1101_AGCCTRL0,
|
||||
0x40}, // 01 - Low hysteresis, small asymmetric dead zone, medium gain; 00 - 8 samples agc; 00 - Normal AGC, 00 - 4dB boundary
|
||||
{CC1101_AGCCTRL1,
|
||||
0x00}, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
|
||||
{CC1101_AGCCTRL2, 0x03}, // 00 - DVGA all; 000 - MAX LNA+LNA2; 011 - MAIN_TARGET 24 dB
|
||||
|
||||
/* Wake on radio and timeouts control */
|
||||
{CC1101_WORCTRL, 0xFB}, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours
|
||||
|
||||
/* Frontend configuration */
|
||||
{CC1101_FREND0, 0x11}, // Adjusts current TX LO buffer + high is PATABLE[1]
|
||||
{CC1101_FREND1, 0xB6}, //
|
||||
|
||||
/* End */
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
static const uint8_t furi_hal_subghz_preset_ook_650khz_async_regs[][2] = {
|
||||
// https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/382066/cc1101---don-t-know-the-correct-registers-configuration
|
||||
|
||||
/* GPIO GD0 */
|
||||
{CC1101_IOCFG0, 0x0D}, // GD0 as async serial data output/input
|
||||
|
||||
/* FIFO and internals */
|
||||
{CC1101_FIFOTHR, 0x07}, // The only important bit is ADC_RETENTION
|
||||
|
||||
/* Packet engine */
|
||||
{CC1101_PKTCTRL0, 0x32}, // Async, continious, no whitening
|
||||
|
||||
/* Frequency Synthesizer Control */
|
||||
{CC1101_FSCTRL1, 0x06}, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
|
||||
|
||||
// Modem Configuration
|
||||
{CC1101_MDMCFG0, 0x00}, // Channel spacing is 25kHz
|
||||
{CC1101_MDMCFG1, 0x00}, // Channel spacing is 25kHz
|
||||
{CC1101_MDMCFG2, 0x30}, // Format ASK/OOK, No preamble/sync
|
||||
{CC1101_MDMCFG3, 0x32}, // Data rate is 3.79372 kBaud
|
||||
{CC1101_MDMCFG4, 0x17}, // Rx BW filter is 650.000kHz
|
||||
|
||||
/* Main Radio Control State Machine */
|
||||
{CC1101_MCSM0, 0x18}, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
|
||||
|
||||
/* Frequency Offset Compensation Configuration */
|
||||
{CC1101_FOCCFG,
|
||||
0x18}, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
|
||||
|
||||
/* Automatic Gain Control */
|
||||
// {CC1101_AGCTRL0,0x40}, // 01 - Low hysteresis, small asymmetric dead zone, medium gain; 00 - 8 samples agc; 00 - Normal AGC, 00 - 4dB boundary
|
||||
// {CC1101_AGCTRL1,0x00}, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
|
||||
// {CC1101_AGCCTRL2, 0x03}, // 00 - DVGA all; 000 - MAX LNA+LNA2; 011 - MAIN_TARGET 24 dB
|
||||
//MAGN_TARGET for RX filter BW =< 100 kHz is 0x3. For higher RX filter BW's MAGN_TARGET is 0x7.
|
||||
{CC1101_AGCCTRL0,
|
||||
0x91}, // 10 - Medium hysteresis, medium asymmetric dead zone, medium gain ; 01 - 16 samples agc; 00 - Normal AGC, 01 - 8dB boundary
|
||||
{CC1101_AGCCTRL1,
|
||||
0x0}, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
|
||||
{CC1101_AGCCTRL2, 0x07}, // 00 - DVGA all; 000 - MAX LNA+LNA2; 111 - MAIN_TARGET 42 dB
|
||||
|
||||
/* Wake on radio and timeouts control */
|
||||
{CC1101_WORCTRL, 0xFB}, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours
|
||||
|
||||
/* Frontend configuration */
|
||||
{CC1101_FREND0, 0x11}, // Adjusts current TX LO buffer + high is PATABLE[1]
|
||||
{CC1101_FREND1, 0xB6}, //
|
||||
|
||||
/* End */
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
static const uint8_t furi_hal_subghz_preset_2fsk_dev2_38khz_async_regs[][2] = {
|
||||
|
||||
/* GPIO GD0 */
|
||||
{CC1101_IOCFG0, 0x0D}, // GD0 as async serial data output/input
|
||||
|
||||
/* Frequency Synthesizer Control */
|
||||
{CC1101_FSCTRL1, 0x06}, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
|
||||
|
||||
/* Packet engine */
|
||||
{CC1101_PKTCTRL0, 0x32}, // Async, continious, no whitening
|
||||
{CC1101_PKTCTRL1, 0x04},
|
||||
|
||||
// // Modem Configuration
|
||||
{CC1101_MDMCFG0, 0x00},
|
||||
{CC1101_MDMCFG1, 0x02},
|
||||
{CC1101_MDMCFG2, 0x04}, // Format 2-FSK/FM, No preamble/sync, Disable (current optimized)
|
||||
{CC1101_MDMCFG3, 0x83}, // Data rate is 4.79794 kBaud
|
||||
{CC1101_MDMCFG4, 0x67}, //Rx BW filter is 270.833333 kHz
|
||||
{CC1101_DEVIATN, 0x04}, //Deviation 2.380371 kHz
|
||||
|
||||
/* Main Radio Control State Machine */
|
||||
{CC1101_MCSM0, 0x18}, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
|
||||
|
||||
/* Frequency Offset Compensation Configuration */
|
||||
{CC1101_FOCCFG,
|
||||
0x16}, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
|
||||
|
||||
/* Automatic Gain Control */
|
||||
{CC1101_AGCCTRL0,
|
||||
0x91}, //10 - Medium hysteresis, medium asymmetric dead zone, medium gain ; 01 - 16 samples agc; 00 - Normal AGC, 01 - 8dB boundary
|
||||
{CC1101_AGCCTRL1,
|
||||
0x00}, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
|
||||
{CC1101_AGCCTRL2, 0x07}, // 00 - DVGA all; 000 - MAX LNA+LNA2; 111 - MAIN_TARGET 42 dB
|
||||
|
||||
/* Wake on radio and timeouts control */
|
||||
{CC1101_WORCTRL, 0xFB}, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours
|
||||
|
||||
/* Frontend configuration */
|
||||
{CC1101_FREND0, 0x10}, // Adjusts current TX LO buffer
|
||||
{CC1101_FREND1, 0x56},
|
||||
|
||||
/* End */
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
static const uint8_t furi_hal_subghz_preset_2fsk_dev47_6khz_async_regs[][2] = {
|
||||
|
||||
/* GPIO GD0 */
|
||||
{CC1101_IOCFG0, 0x0D}, // GD0 as async serial data output/input
|
||||
|
||||
/* Frequency Synthesizer Control */
|
||||
{CC1101_FSCTRL1, 0x06}, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
|
||||
|
||||
/* Packet engine */
|
||||
{CC1101_PKTCTRL0, 0x32}, // Async, continious, no whitening
|
||||
{CC1101_PKTCTRL1, 0x04},
|
||||
|
||||
// // Modem Configuration
|
||||
{CC1101_MDMCFG0, 0x00},
|
||||
{CC1101_MDMCFG1, 0x02},
|
||||
{CC1101_MDMCFG2, 0x04}, // Format 2-FSK/FM, No preamble/sync, Disable (current optimized)
|
||||
{CC1101_MDMCFG3, 0x83}, // Data rate is 4.79794 kBaud
|
||||
{CC1101_MDMCFG4, 0x67}, //Rx BW filter is 270.833333 kHz
|
||||
{CC1101_DEVIATN, 0x47}, //Deviation 47.60742 kHz
|
||||
|
||||
/* Main Radio Control State Machine */
|
||||
{CC1101_MCSM0, 0x18}, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
|
||||
|
||||
/* Frequency Offset Compensation Configuration */
|
||||
{CC1101_FOCCFG,
|
||||
0x16}, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
|
||||
|
||||
/* Automatic Gain Control */
|
||||
{CC1101_AGCCTRL0,
|
||||
0x91}, //10 - Medium hysteresis, medium asymmetric dead zone, medium gain ; 01 - 16 samples agc; 00 - Normal AGC, 01 - 8dB boundary
|
||||
{CC1101_AGCCTRL1,
|
||||
0x00}, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
|
||||
{CC1101_AGCCTRL2, 0x07}, // 00 - DVGA all; 000 - MAX LNA+LNA2; 111 - MAIN_TARGET 42 dB
|
||||
|
||||
/* Wake on radio and timeouts control */
|
||||
{CC1101_WORCTRL, 0xFB}, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours
|
||||
|
||||
/* Frontend configuration */
|
||||
{CC1101_FREND0, 0x10}, // Adjusts current TX LO buffer
|
||||
{CC1101_FREND1, 0x56},
|
||||
|
||||
/* End */
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
static const uint8_t furi_hal_subghz_preset_msk_99_97kb_async_regs[][2] = {
|
||||
/* GPIO GD0 */
|
||||
{CC1101_IOCFG0, 0x06},
|
||||
|
||||
{CC1101_FIFOTHR, 0x07}, // The only important bit is ADC_RETENTION
|
||||
{CC1101_SYNC1, 0x46},
|
||||
{CC1101_SYNC0, 0x4C},
|
||||
{CC1101_ADDR, 0x00},
|
||||
{CC1101_PKTLEN, 0x00},
|
||||
{CC1101_CHANNR, 0x00},
|
||||
|
||||
{CC1101_PKTCTRL0, 0x05},
|
||||
|
||||
{CC1101_FSCTRL0, 0x23},
|
||||
{CC1101_FSCTRL1, 0x06},
|
||||
|
||||
{CC1101_MDMCFG0, 0xF8},
|
||||
{CC1101_MDMCFG1, 0x22},
|
||||
{CC1101_MDMCFG2, 0x72},
|
||||
{CC1101_MDMCFG3, 0xF8},
|
||||
{CC1101_MDMCFG4, 0x5B},
|
||||
{CC1101_DEVIATN, 0x47},
|
||||
|
||||
{CC1101_MCSM0, 0x18},
|
||||
{CC1101_FOCCFG, 0x16},
|
||||
|
||||
{CC1101_AGCCTRL0, 0xB2},
|
||||
{CC1101_AGCCTRL1, 0x00},
|
||||
{CC1101_AGCCTRL2, 0xC7},
|
||||
|
||||
{CC1101_FREND0, 0x10},
|
||||
{CC1101_FREND1, 0x56},
|
||||
|
||||
{CC1101_BSCFG, 0x1C},
|
||||
{CC1101_FSTEST, 0x59},
|
||||
|
||||
/* End */
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
static const uint8_t furi_hal_subghz_preset_gfsk_9_99kb_async_regs[][2] = {
|
||||
|
||||
{CC1101_IOCFG0, 0x06}, //GDO0 Output Pin Configuration
|
||||
{CC1101_FIFOTHR, 0x47}, //RX FIFO and TX FIFO Thresholds
|
||||
|
||||
//1 : CRC calculation in TX and CRC check in RX enabled,
|
||||
//1 : Variable packet length mode. Packet length configured by the first byte after sync word
|
||||
{CC1101_PKTCTRL0, 0x05},
|
||||
|
||||
{CC1101_FSCTRL1, 0x06}, //Frequency Synthesizer Control
|
||||
|
||||
{CC1101_SYNC1, 0x46},
|
||||
{CC1101_SYNC0, 0x4C},
|
||||
{CC1101_ADDR, 0x00},
|
||||
{CC1101_PKTLEN, 0x00},
|
||||
|
||||
{CC1101_MDMCFG4, 0xC8}, //Modem Configuration 9.99
|
||||
{CC1101_MDMCFG3, 0x93}, //Modem Configuration
|
||||
{CC1101_MDMCFG2, 0x12}, // 2: 16/16 sync word bits detected
|
||||
|
||||
{CC1101_DEVIATN, 0x34}, //Deviation = 19.042969
|
||||
{CC1101_MCSM0, 0x18}, //Main Radio Control State Machine Configuration
|
||||
{CC1101_FOCCFG, 0x16}, //Frequency Offset Compensation Configuration
|
||||
|
||||
{CC1101_AGCCTRL2, 0x43}, //AGC Control
|
||||
{CC1101_AGCCTRL1, 0x40},
|
||||
{CC1101_AGCCTRL0, 0x91},
|
||||
|
||||
{CC1101_WORCTRL, 0xFB}, //Wake On Radio Control
|
||||
/* End */
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
static const uint8_t furi_hal_subghz_preset_ook_async_patable[8] = {
|
||||
0x00,
|
||||
0xC0, // 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,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00};
|
||||
|
||||
static const uint8_t furi_hal_subghz_preset_msk_async_patable[8] = {
|
||||
0xC0, // 10dBm 0xC0, 7dBm 0xC8, 5dBm 0x84, 0dBm 0x60, -10dBm 0x34, -15dBm 0x1D, -20dBm 0x0E, -30dBm 0x12
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00};
|
||||
|
||||
static const uint8_t furi_hal_subghz_preset_gfsk_async_patable[8] = {
|
||||
0xC0, // 10dBm 0xC0, 7dBm 0xC8, 5dBm 0x84, 0dBm 0x60, -10dBm 0x34, -15dBm 0x1D, -20dBm 0x0E, -30dBm 0x12
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00};
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -21,6 +21,7 @@ env.Append(
|
|||
File("blocks/custom_btn.h"),
|
||||
File("subghz_setting.h"),
|
||||
File("subghz_protocol_registry.h"),
|
||||
File("devices/cc1101_configs.h"),
|
||||
],
|
||||
)
|
||||
|
||||
|
|
482
lib/subghz/devices/cc1101_configs.c
Normal file
482
lib/subghz/devices/cc1101_configs.c
Normal file
|
@ -0,0 +1,482 @@
|
|||
#include "cc1101_configs.h"
|
||||
#include <cc1101_regs.h>
|
||||
|
||||
const uint8_t subghz_device_cc1101_preset_ook_270khz_async_regs[] = {
|
||||
// https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/382066/cc1101---don-t-know-the-correct-registers-configuration
|
||||
|
||||
/* GPIO GD0 */
|
||||
CC1101_IOCFG0,
|
||||
0x0D, // GD0 as async serial data output/input
|
||||
|
||||
/* FIFO and internals */
|
||||
CC1101_FIFOTHR,
|
||||
0x47, // The only important bit is ADC_RETENTION, FIFO Tx=33 Rx=32
|
||||
|
||||
/* Packet engine */
|
||||
CC1101_PKTCTRL0,
|
||||
0x32, // Async, continious, no whitening
|
||||
|
||||
/* Frequency Synthesizer Control */
|
||||
CC1101_FSCTRL1,
|
||||
0x06, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
|
||||
|
||||
// Modem Configuration
|
||||
CC1101_MDMCFG0,
|
||||
0x00, // Channel spacing is 25kHz
|
||||
CC1101_MDMCFG1,
|
||||
0x00, // Channel spacing is 25kHz
|
||||
CC1101_MDMCFG2,
|
||||
0x30, // Format ASK/OOK, No preamble/sync
|
||||
CC1101_MDMCFG3,
|
||||
0x32, // Data rate is 3.79372 kBaud
|
||||
CC1101_MDMCFG4,
|
||||
0x67, // Rx BW filter is 270.833333kHz
|
||||
|
||||
/* Main Radio Control State Machine */
|
||||
CC1101_MCSM0,
|
||||
0x18, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
|
||||
|
||||
/* Frequency Offset Compensation Configuration */
|
||||
CC1101_FOCCFG,
|
||||
0x18, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
|
||||
|
||||
/* Automatic Gain Control */
|
||||
CC1101_AGCCTRL0,
|
||||
0x40, // 01 - Low hysteresis, small asymmetric dead zone, medium gain; 00 - 8 samples agc; 00 - Normal AGC, 00 - 4dB boundary
|
||||
CC1101_AGCCTRL1,
|
||||
0x00, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
|
||||
CC1101_AGCCTRL2,
|
||||
0x03, // 00 - DVGA all; 000 - MAX LNA+LNA2; 011 - MAIN_TARGET 24 dB
|
||||
|
||||
/* Wake on radio and timeouts control */
|
||||
CC1101_WORCTRL,
|
||||
0xFB, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours
|
||||
|
||||
/* Frontend configuration */
|
||||
CC1101_FREND0,
|
||||
0x11, // Adjusts current TX LO buffer + high is PATABLE[1]
|
||||
CC1101_FREND1,
|
||||
0xB6, //
|
||||
|
||||
/* End load reg */
|
||||
0,
|
||||
0,
|
||||
|
||||
//ook_async_patable[8]
|
||||
0x00,
|
||||
0xC0, // 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,
|
||||
};
|
||||
|
||||
const uint8_t subghz_device_cc1101_preset_ook_650khz_async_regs[] = {
|
||||
// https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/382066/cc1101---don-t-know-the-correct-registers-configuration
|
||||
|
||||
/* GPIO GD0 */
|
||||
CC1101_IOCFG0,
|
||||
0x0D, // GD0 as async serial data output/input
|
||||
|
||||
/* FIFO and internals */
|
||||
CC1101_FIFOTHR,
|
||||
0x07, // The only important bit is ADC_RETENTION
|
||||
|
||||
/* Packet engine */
|
||||
CC1101_PKTCTRL0,
|
||||
0x32, // Async, continious, no whitening
|
||||
|
||||
/* Frequency Synthesizer Control */
|
||||
CC1101_FSCTRL1,
|
||||
0x06, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
|
||||
|
||||
// Modem Configuration
|
||||
CC1101_MDMCFG0,
|
||||
0x00, // Channel spacing is 25kHz
|
||||
CC1101_MDMCFG1,
|
||||
0x00, // Channel spacing is 25kHz
|
||||
CC1101_MDMCFG2,
|
||||
0x30, // Format ASK/OOK, No preamble/sync
|
||||
CC1101_MDMCFG3,
|
||||
0x32, // Data rate is 3.79372 kBaud
|
||||
CC1101_MDMCFG4,
|
||||
0x17, // Rx BW filter is 650.000kHz
|
||||
|
||||
/* Main Radio Control State Machine */
|
||||
CC1101_MCSM0,
|
||||
0x18, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
|
||||
|
||||
/* Frequency Offset Compensation Configuration */
|
||||
CC1101_FOCCFG,
|
||||
0x18, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
|
||||
|
||||
/* Automatic Gain Control */
|
||||
// CC1101_AGCTRL0,0x40, // 01 - Low hysteresis, small asymmetric dead zone, medium gain; 00 - 8 samples agc; 00 - Normal AGC, 00 - 4dB boundary
|
||||
// CC1101_AGCTRL1,0x00, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
|
||||
// CC1101_AGCCTRL2, 0x03, // 00 - DVGA all; 000 - MAX LNA+LNA2; 011 - MAIN_TARGET 24 dB
|
||||
//MAGN_TARGET for RX filter BW =< 100 kHz is 0x3. For higher RX filter BW's MAGN_TARGET is 0x7.
|
||||
CC1101_AGCCTRL0,
|
||||
0x91, // 10 - Medium hysteresis, medium asymmetric dead zone, medium gain ; 01 - 16 samples agc; 00 - Normal AGC, 01 - 8dB boundary
|
||||
CC1101_AGCCTRL1,
|
||||
0x0, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
|
||||
CC1101_AGCCTRL2,
|
||||
0x07, // 00 - DVGA all; 000 - MAX LNA+LNA2; 111 - MAIN_TARGET 42 dB
|
||||
|
||||
/* Wake on radio and timeouts control */
|
||||
CC1101_WORCTRL,
|
||||
0xFB, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours
|
||||
|
||||
/* Frontend configuration */
|
||||
CC1101_FREND0,
|
||||
0x11, // Adjusts current TX LO buffer + high is PATABLE[1]
|
||||
CC1101_FREND1,
|
||||
0xB6, //
|
||||
|
||||
/* End load reg */
|
||||
0,
|
||||
0,
|
||||
|
||||
//ook_async_patable[8]
|
||||
0x00,
|
||||
0xC0, // 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,
|
||||
};
|
||||
|
||||
const uint8_t subghz_device_cc1101_preset_2fsk_dev2_38khz_async_regs[] = {
|
||||
|
||||
/* GPIO GD0 */
|
||||
CC1101_IOCFG0,
|
||||
0x0D, // GD0 as async serial data output/input
|
||||
|
||||
/* Frequency Synthesizer Control */
|
||||
CC1101_FSCTRL1,
|
||||
0x06, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
|
||||
|
||||
/* Packet engine */
|
||||
CC1101_PKTCTRL0,
|
||||
0x32, // Async, continious, no whitening
|
||||
CC1101_PKTCTRL1,
|
||||
0x04,
|
||||
|
||||
// // Modem Configuration
|
||||
CC1101_MDMCFG0,
|
||||
0x00,
|
||||
CC1101_MDMCFG1,
|
||||
0x02,
|
||||
CC1101_MDMCFG2,
|
||||
0x04, // Format 2-FSK/FM, No preamble/sync, Disable (current optimized)
|
||||
CC1101_MDMCFG3,
|
||||
0x83, // Data rate is 4.79794 kBaud
|
||||
CC1101_MDMCFG4,
|
||||
0x67, //Rx BW filter is 270.833333 kHz
|
||||
CC1101_DEVIATN,
|
||||
0x04, //Deviation 2.380371 kHz
|
||||
|
||||
/* Main Radio Control State Machine */
|
||||
CC1101_MCSM0,
|
||||
0x18, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
|
||||
|
||||
/* Frequency Offset Compensation Configuration */
|
||||
CC1101_FOCCFG,
|
||||
0x16, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
|
||||
|
||||
/* Automatic Gain Control */
|
||||
CC1101_AGCCTRL0,
|
||||
0x91, //10 - Medium hysteresis, medium asymmetric dead zone, medium gain ; 01 - 16 samples agc; 00 - Normal AGC, 01 - 8dB boundary
|
||||
CC1101_AGCCTRL1,
|
||||
0x00, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
|
||||
CC1101_AGCCTRL2,
|
||||
0x07, // 00 - DVGA all; 000 - MAX LNA+LNA2; 111 - MAIN_TARGET 42 dB
|
||||
|
||||
/* Wake on radio and timeouts control */
|
||||
CC1101_WORCTRL,
|
||||
0xFB, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours
|
||||
|
||||
/* Frontend configuration */
|
||||
CC1101_FREND0,
|
||||
0x10, // Adjusts current TX LO buffer
|
||||
CC1101_FREND1,
|
||||
0x56,
|
||||
|
||||
/* End load reg */
|
||||
0,
|
||||
0,
|
||||
|
||||
// 2fsk_async_patable[8]
|
||||
0xC0, // 10dBm 0xC0, 7dBm 0xC8, 5dBm 0x84, 0dBm 0x60, -10dBm 0x34, -15dBm 0x1D, -20dBm 0x0E, -30dBm 0x12
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
const uint8_t subghz_device_cc1101_preset_2fsk_dev47_6khz_async_regs[] = {
|
||||
|
||||
/* GPIO GD0 */
|
||||
CC1101_IOCFG0,
|
||||
0x0D, // GD0 as async serial data output/input
|
||||
|
||||
/* Frequency Synthesizer Control */
|
||||
CC1101_FSCTRL1,
|
||||
0x06, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
|
||||
|
||||
/* Packet engine */
|
||||
CC1101_PKTCTRL0,
|
||||
0x32, // Async, continious, no whitening
|
||||
CC1101_PKTCTRL1,
|
||||
0x04,
|
||||
|
||||
// // Modem Configuration
|
||||
CC1101_MDMCFG0,
|
||||
0x00,
|
||||
CC1101_MDMCFG1,
|
||||
0x02,
|
||||
CC1101_MDMCFG2,
|
||||
0x04, // Format 2-FSK/FM, No preamble/sync, Disable (current optimized)
|
||||
CC1101_MDMCFG3,
|
||||
0x83, // Data rate is 4.79794 kBaud
|
||||
CC1101_MDMCFG4,
|
||||
0x67, //Rx BW filter is 270.833333 kHz
|
||||
CC1101_DEVIATN,
|
||||
0x47, //Deviation 47.60742 kHz
|
||||
|
||||
/* Main Radio Control State Machine */
|
||||
CC1101_MCSM0,
|
||||
0x18, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
|
||||
|
||||
/* Frequency Offset Compensation Configuration */
|
||||
CC1101_FOCCFG,
|
||||
0x16, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
|
||||
|
||||
/* Automatic Gain Control */
|
||||
CC1101_AGCCTRL0,
|
||||
0x91, //10 - Medium hysteresis, medium asymmetric dead zone, medium gain ; 01 - 16 samples agc; 00 - Normal AGC, 01 - 8dB boundary
|
||||
CC1101_AGCCTRL1,
|
||||
0x00, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
|
||||
CC1101_AGCCTRL2,
|
||||
0x07, // 00 - DVGA all; 000 - MAX LNA+LNA2; 111 - MAIN_TARGET 42 dB
|
||||
|
||||
/* Wake on radio and timeouts control */
|
||||
CC1101_WORCTRL,
|
||||
0xFB, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours
|
||||
|
||||
/* Frontend configuration */
|
||||
CC1101_FREND0,
|
||||
0x10, // Adjusts current TX LO buffer
|
||||
CC1101_FREND1,
|
||||
0x56,
|
||||
|
||||
/* End load reg */
|
||||
0,
|
||||
0,
|
||||
|
||||
// 2fsk_async_patable[8]
|
||||
0xC0, // 10dBm 0xC0, 7dBm 0xC8, 5dBm 0x84, 0dBm 0x60, -10dBm 0x34, -15dBm 0x1D, -20dBm 0x0E, -30dBm 0x12
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
const uint8_t subghz_device_cc1101_preset_msk_99_97kb_async_regs[] = {
|
||||
/* GPIO GD0 */
|
||||
CC1101_IOCFG0,
|
||||
0x06,
|
||||
|
||||
CC1101_FIFOTHR,
|
||||
0x07, // The only important bit is ADC_RETENTION
|
||||
CC1101_SYNC1,
|
||||
0x46,
|
||||
CC1101_SYNC0,
|
||||
0x4C,
|
||||
CC1101_ADDR,
|
||||
0x00,
|
||||
CC1101_PKTLEN,
|
||||
0x00,
|
||||
CC1101_CHANNR,
|
||||
0x00,
|
||||
|
||||
CC1101_PKTCTRL0,
|
||||
0x05,
|
||||
|
||||
CC1101_FSCTRL0,
|
||||
0x23,
|
||||
CC1101_FSCTRL1,
|
||||
0x06,
|
||||
|
||||
CC1101_MDMCFG0,
|
||||
0xF8,
|
||||
CC1101_MDMCFG1,
|
||||
0x22,
|
||||
CC1101_MDMCFG2,
|
||||
0x72,
|
||||
CC1101_MDMCFG3,
|
||||
0xF8,
|
||||
CC1101_MDMCFG4,
|
||||
0x5B,
|
||||
CC1101_DEVIATN,
|
||||
0x47,
|
||||
|
||||
CC1101_MCSM0,
|
||||
0x18,
|
||||
CC1101_FOCCFG,
|
||||
0x16,
|
||||
|
||||
CC1101_AGCCTRL0,
|
||||
0xB2,
|
||||
CC1101_AGCCTRL1,
|
||||
0x00,
|
||||
CC1101_AGCCTRL2,
|
||||
0xC7,
|
||||
|
||||
CC1101_FREND0,
|
||||
0x10,
|
||||
CC1101_FREND1,
|
||||
0x56,
|
||||
|
||||
CC1101_BSCFG,
|
||||
0x1C,
|
||||
CC1101_FSTEST,
|
||||
0x59,
|
||||
|
||||
/* End load reg */
|
||||
0,
|
||||
0,
|
||||
|
||||
// msk_async_patable[8]
|
||||
0xC0, // 10dBm 0xC0, 7dBm 0xC8, 5dBm 0x84, 0dBm 0x60, -10dBm 0x34, -15dBm 0x1D, -20dBm 0x0E, -30dBm 0x12
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
const uint8_t subghz_device_cc1101_preset_gfsk_9_99kb_async_regs[] = {
|
||||
|
||||
CC1101_IOCFG0,
|
||||
0x06, //GDO0 Output Pin Configuration
|
||||
CC1101_FIFOTHR,
|
||||
0x47, //RX FIFO and TX FIFO Thresholds
|
||||
|
||||
//1 : CRC calculation in TX and CRC check in RX enabled,
|
||||
//1 : Variable packet length mode. Packet length configured by the first byte after sync word
|
||||
CC1101_PKTCTRL0,
|
||||
0x05,
|
||||
|
||||
CC1101_FSCTRL1,
|
||||
0x06, //Frequency Synthesizer Control
|
||||
|
||||
CC1101_SYNC1,
|
||||
0x46,
|
||||
CC1101_SYNC0,
|
||||
0x4C,
|
||||
CC1101_ADDR,
|
||||
0x00,
|
||||
CC1101_PKTLEN,
|
||||
0x00,
|
||||
|
||||
CC1101_MDMCFG4,
|
||||
0xC8, //Modem Configuration 9.99
|
||||
CC1101_MDMCFG3,
|
||||
0x93, //Modem Configuration
|
||||
CC1101_MDMCFG2,
|
||||
0x12, // 2: 16/16 sync word bits detected
|
||||
|
||||
CC1101_DEVIATN,
|
||||
0x34, //Deviation = 19.042969
|
||||
CC1101_MCSM0,
|
||||
0x18, //Main Radio Control State Machine Configuration
|
||||
CC1101_FOCCFG,
|
||||
0x16, //Frequency Offset Compensation Configuration
|
||||
|
||||
CC1101_AGCCTRL2,
|
||||
0x43, //AGC Control
|
||||
CC1101_AGCCTRL1,
|
||||
0x40,
|
||||
CC1101_AGCCTRL0,
|
||||
0x91,
|
||||
|
||||
CC1101_WORCTRL,
|
||||
0xFB, //Wake On Radio Control
|
||||
|
||||
/* End load reg */
|
||||
0,
|
||||
0,
|
||||
|
||||
// gfsk_async_patable[8]
|
||||
0xC0, // 10dBm 0xC0, 7dBm 0xC8, 5dBm 0x84, 0dBm 0x60, -10dBm 0x34, -15dBm 0x1D, -20dBm 0x0E, -30dBm 0x12
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
// Shpargalka
|
||||
// const uint8_t subghz_device_cc1101_preset_ook_async_patable[8] = {
|
||||
// 0x00,
|
||||
// 0xC0, // 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};
|
||||
|
||||
// const uint8_t subghz_device_cc1101_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};
|
||||
|
||||
// const uint8_t subghz_device_cc1101_preset_2fsk_async_patable[8] = {
|
||||
// 0xC0, // 10dBm 0xC0, 7dBm 0xC8, 5dBm 0x84, 0dBm 0x60, -10dBm 0x34, -15dBm 0x1D, -20dBm 0x0E, -30dBm 0x12
|
||||
// 0x00,
|
||||
// 0x00,
|
||||
// 0x00,
|
||||
// 0x00,
|
||||
// 0x00,
|
||||
// 0x00,
|
||||
// 0x00};
|
||||
|
||||
// const uint8_t subghz_device_cc1101_preset_msk_async_patable[8] = {
|
||||
// 0xC0, // 10dBm 0xC0, 7dBm 0xC8, 5dBm 0x84, 0dBm 0x60, -10dBm 0x34, -15dBm 0x1D, -20dBm 0x0E, -30dBm 0x12
|
||||
// 0x00,
|
||||
// 0x00,
|
||||
// 0x00,
|
||||
// 0x00,
|
||||
// 0x00,
|
||||
// 0x00,
|
||||
// 0x00};
|
||||
|
||||
// const uint8_t subghz_device_cc1101_preset_gfsk_async_patable[8] = {
|
||||
// 0xC0, // 10dBm 0xC0, 7dBm 0xC8, 5dBm 0x84, 0dBm 0x60, -10dBm 0x34, -15dBm 0x1D, -20dBm 0x0E, -30dBm 0x12
|
||||
// 0x00,
|
||||
// 0x00,
|
||||
// 0x00,
|
||||
// 0x00,
|
||||
// 0x00,
|
||||
// 0x00,
|
||||
// 0x00};
|
23
lib/subghz/devices/cc1101_configs.h
Normal file
23
lib/subghz/devices/cc1101_configs.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
#include <furi.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern const uint8_t subghz_device_cc1101_preset_ook_270khz_async_regs[];
|
||||
extern const uint8_t subghz_device_cc1101_preset_ook_650khz_async_regs[];
|
||||
extern const uint8_t subghz_device_cc1101_preset_2fsk_dev2_38khz_async_regs[];
|
||||
extern const uint8_t subghz_device_cc1101_preset_2fsk_dev47_6khz_async_regs[];
|
||||
extern const uint8_t subghz_device_cc1101_preset_msk_99_97kb_async_regs[];
|
||||
extern const uint8_t subghz_device_cc1101_preset_gfsk_9_99kb_async_regs[];
|
||||
|
||||
// extern const uint8_t subghz_device_cc1101_preset_ook_async_patable[8];
|
||||
// extern const uint8_t subghz_device_cc1101_preset_ook_async_patable_au[8];
|
||||
// extern const uint8_t subghz_device_cc1101_preset_2fsk_async_patable[8];
|
||||
// extern const uint8_t subghz_device_cc1101_preset_msk_async_patable[8];
|
||||
// extern const uint8_t subghz_device_cc1101_preset_gfsk_async_patable[8];
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
96
lib/subghz/devices/cc1101_int/cc1101_int_interconnect.c
Normal file
96
lib/subghz/devices/cc1101_int/cc1101_int_interconnect.c
Normal file
|
@ -0,0 +1,96 @@
|
|||
#include "cc1101_int_interconnect.h"
|
||||
#include <furi_hal.h>
|
||||
#include "../cc1101_configs.h"
|
||||
|
||||
#define TAG "SubGhzDeviceCC1101Int"
|
||||
|
||||
static bool subghz_device_cc1101_int_interconnect_is_frequency_valid(uint32_t frequency) {
|
||||
bool ret = furi_hal_subghz_is_frequency_valid(frequency);
|
||||
if(!ret) {
|
||||
furi_crash("SubGhz: Incorrect frequency.");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static uint32_t subghz_device_cc1101_int_interconnect_set_frequency(uint32_t frequency) {
|
||||
subghz_device_cc1101_int_interconnect_is_frequency_valid(frequency);
|
||||
return furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
}
|
||||
|
||||
static bool subghz_device_cc1101_int_interconnect_start_async_tx(void* callback, void* context) {
|
||||
return furi_hal_subghz_start_async_tx((FuriHalSubGhzAsyncTxCallback)callback, context);
|
||||
}
|
||||
|
||||
static void subghz_device_cc1101_int_interconnect_start_async_rx(void* callback, void* context) {
|
||||
furi_hal_subghz_start_async_rx((FuriHalSubGhzCaptureCallback)callback, context);
|
||||
}
|
||||
|
||||
static void subghz_device_cc1101_int_interconnect_load_preset(
|
||||
FuriHalSubGhzPreset preset,
|
||||
uint8_t* preset_data) {
|
||||
switch(preset) {
|
||||
case FuriHalSubGhzPresetOok650Async:
|
||||
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_ook_650khz_async_regs);
|
||||
break;
|
||||
case FuriHalSubGhzPresetOok270Async:
|
||||
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_ook_270khz_async_regs);
|
||||
break;
|
||||
case FuriHalSubGhzPreset2FSKDev238Async:
|
||||
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_2fsk_dev2_38khz_async_regs);
|
||||
break;
|
||||
case FuriHalSubGhzPreset2FSKDev476Async:
|
||||
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_2fsk_dev47_6khz_async_regs);
|
||||
break;
|
||||
case FuriHalSubGhzPresetMSK99_97KbAsync:
|
||||
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_msk_99_97kb_async_regs);
|
||||
break;
|
||||
case FuriHalSubGhzPresetGFSK9_99KbAsync:
|
||||
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_gfsk_9_99kb_async_regs);
|
||||
break;
|
||||
|
||||
default:
|
||||
furi_hal_subghz_load_custom_preset(preset_data);
|
||||
}
|
||||
}
|
||||
|
||||
static bool subghz_device_cc1101_int_interconnect_is_connect(void) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const SubGhzDeviceInterconnect subghz_device_cc1101_int_interconnect = {
|
||||
.begin = NULL,
|
||||
.end = furi_hal_subghz_shutdown,
|
||||
.is_connect = subghz_device_cc1101_int_interconnect_is_connect,
|
||||
.reset = furi_hal_subghz_reset,
|
||||
.sleep = furi_hal_subghz_sleep,
|
||||
.idle = furi_hal_subghz_idle,
|
||||
.load_preset = subghz_device_cc1101_int_interconnect_load_preset,
|
||||
.set_frequency = subghz_device_cc1101_int_interconnect_set_frequency,
|
||||
.is_frequency_valid = furi_hal_subghz_is_frequency_valid,
|
||||
.set_async_mirror_pin = furi_hal_subghz_set_async_mirror_pin,
|
||||
.get_data_gpio = furi_hal_subghz_get_data_gpio,
|
||||
|
||||
.set_tx = furi_hal_subghz_tx,
|
||||
.flush_tx = furi_hal_subghz_flush_tx,
|
||||
.start_async_tx = subghz_device_cc1101_int_interconnect_start_async_tx,
|
||||
.is_async_complete_tx = furi_hal_subghz_is_async_tx_complete,
|
||||
.stop_async_tx = furi_hal_subghz_stop_async_tx,
|
||||
|
||||
.set_rx = furi_hal_subghz_rx,
|
||||
.flush_rx = furi_hal_subghz_flush_rx,
|
||||
.start_async_rx = subghz_device_cc1101_int_interconnect_start_async_rx,
|
||||
.stop_async_rx = furi_hal_subghz_stop_async_rx,
|
||||
|
||||
.get_rssi = furi_hal_subghz_get_rssi,
|
||||
.get_lqi = furi_hal_subghz_get_lqi,
|
||||
|
||||
.rx_pipe_not_empty = furi_hal_subghz_rx_pipe_not_empty,
|
||||
.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,
|
||||
};
|
||||
|
||||
const SubGhzDevice subghz_device_cc1101_int = {
|
||||
.name = SUBGHZ_DEVICE_CC1101_INT_NAME,
|
||||
.interconnect = &subghz_device_cc1101_int_interconnect,
|
||||
};
|
8
lib/subghz/devices/cc1101_int/cc1101_int_interconnect.h
Normal file
8
lib/subghz/devices/cc1101_int/cc1101_int_interconnect.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
#include "../types.h"
|
||||
|
||||
#define SUBGHZ_DEVICE_CC1101_INT_NAME "cc1101_int"
|
||||
|
||||
typedef struct SubGhzDeviceCC1101Int SubGhzDeviceCC1101Int;
|
||||
|
||||
extern const SubGhzDevice subghz_device_cc1101_int;
|
13
lib/subghz/devices/device_registry.h
Normal file
13
lib/subghz/devices/device_registry.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include "registry.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern const SubGhzDeviceRegistry subghz_device_registry;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
237
lib/subghz/devices/devices.c
Normal file
237
lib/subghz/devices/devices.c
Normal file
|
@ -0,0 +1,237 @@
|
|||
#include "devices.h"
|
||||
|
||||
#include "registry.h"
|
||||
|
||||
void subghz_devices_init() {
|
||||
furi_check(!subghz_device_registry_is_valid());
|
||||
subghz_device_registry_init();
|
||||
}
|
||||
|
||||
void subghz_devices_deinit(void) {
|
||||
furi_check(subghz_device_registry_is_valid());
|
||||
subghz_device_registry_deinit();
|
||||
}
|
||||
|
||||
const SubGhzDevice* subghz_devices_get_by_name(const char* device_name) {
|
||||
furi_check(subghz_device_registry_is_valid());
|
||||
const SubGhzDevice* device = subghz_device_registry_get_by_name(device_name);
|
||||
return device;
|
||||
}
|
||||
|
||||
const char* subghz_devices_get_name(const SubGhzDevice* device) {
|
||||
const char* ret = NULL;
|
||||
if(device) {
|
||||
ret = device->name;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool subghz_devices_begin(const SubGhzDevice* device) {
|
||||
bool ret = false;
|
||||
furi_assert(device);
|
||||
if(device->interconnect->begin) {
|
||||
ret = device->interconnect->begin();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void subghz_devices_end(const SubGhzDevice* device) {
|
||||
furi_assert(device);
|
||||
if(device->interconnect->end) {
|
||||
device->interconnect->end();
|
||||
}
|
||||
}
|
||||
|
||||
bool subghz_devices_is_connect(const SubGhzDevice* device) {
|
||||
bool ret = false;
|
||||
furi_assert(device);
|
||||
if(device->interconnect->is_connect) {
|
||||
ret = device->interconnect->is_connect();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void subghz_devices_reset(const SubGhzDevice* device) {
|
||||
furi_assert(device);
|
||||
if(device->interconnect->reset) {
|
||||
device->interconnect->reset();
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_devices_sleep(const SubGhzDevice* device) {
|
||||
furi_assert(device);
|
||||
if(device->interconnect->sleep) {
|
||||
device->interconnect->sleep();
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_devices_idle(const SubGhzDevice* device) {
|
||||
furi_assert(device);
|
||||
if(device->interconnect->idle) {
|
||||
device->interconnect->idle();
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_devices_load_preset(
|
||||
const SubGhzDevice* device,
|
||||
FuriHalSubGhzPreset preset,
|
||||
uint8_t* preset_data) {
|
||||
furi_assert(device);
|
||||
if(device->interconnect->load_preset) {
|
||||
device->interconnect->load_preset(preset, preset_data);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t subghz_devices_set_frequency(const SubGhzDevice* device, uint32_t frequency) {
|
||||
uint32_t ret = 0;
|
||||
furi_assert(device);
|
||||
if(device->interconnect->set_frequency) {
|
||||
ret = device->interconnect->set_frequency(frequency);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool subghz_devices_is_frequency_valid(const SubGhzDevice* device, uint32_t frequency) {
|
||||
bool ret = false;
|
||||
furi_assert(device);
|
||||
if(device->interconnect->is_frequency_valid) {
|
||||
ret = device->interconnect->is_frequency_valid(frequency);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void subghz_devices_set_async_mirror_pin(const SubGhzDevice* device, const GpioPin* gpio) {
|
||||
furi_assert(device);
|
||||
if(device->interconnect->set_async_mirror_pin) {
|
||||
device->interconnect->set_async_mirror_pin(gpio);
|
||||
}
|
||||
}
|
||||
|
||||
const GpioPin* subghz_devices_get_data_gpio(const SubGhzDevice* device) {
|
||||
const GpioPin* ret = NULL;
|
||||
furi_assert(device);
|
||||
if(device->interconnect->get_data_gpio) {
|
||||
ret = device->interconnect->get_data_gpio();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool subghz_devices_set_tx(const SubGhzDevice* device) {
|
||||
bool ret = 0;
|
||||
furi_assert(device);
|
||||
if(device->interconnect->set_tx) {
|
||||
ret = device->interconnect->set_tx();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void subghz_devices_flush_tx(const SubGhzDevice* device) {
|
||||
furi_assert(device);
|
||||
if(device->interconnect->flush_tx) {
|
||||
device->interconnect->flush_tx();
|
||||
}
|
||||
}
|
||||
|
||||
bool subghz_devices_start_async_tx(const SubGhzDevice* device, void* callback, void* context) {
|
||||
bool ret = false;
|
||||
furi_assert(device);
|
||||
if(device->interconnect->start_async_tx) {
|
||||
ret = device->interconnect->start_async_tx(callback, context);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool subghz_devices_is_async_complete_tx(const SubGhzDevice* device) {
|
||||
bool ret = false;
|
||||
furi_assert(device);
|
||||
if(device->interconnect->is_async_complete_tx) {
|
||||
ret = device->interconnect->is_async_complete_tx();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void subghz_devices_stop_async_tx(const SubGhzDevice* device) {
|
||||
furi_assert(device);
|
||||
if(device->interconnect->stop_async_tx) {
|
||||
device->interconnect->stop_async_tx();
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_devices_set_rx(const SubGhzDevice* device) {
|
||||
furi_assert(device);
|
||||
if(device->interconnect->set_rx) {
|
||||
device->interconnect->set_rx();
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_devices_flush_rx(const SubGhzDevice* device) {
|
||||
furi_assert(device);
|
||||
if(device->interconnect->flush_rx) {
|
||||
device->interconnect->flush_rx();
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_devices_start_async_rx(const SubGhzDevice* device, void* callback, void* context) {
|
||||
furi_assert(device);
|
||||
if(device->interconnect->start_async_rx) {
|
||||
device->interconnect->start_async_rx(callback, context);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_devices_stop_async_rx(const SubGhzDevice* device) {
|
||||
furi_assert(device);
|
||||
if(device->interconnect->stop_async_rx) {
|
||||
device->interconnect->stop_async_rx();
|
||||
}
|
||||
}
|
||||
|
||||
float subghz_devices_get_rssi(const SubGhzDevice* device) {
|
||||
float ret = 0;
|
||||
furi_assert(device);
|
||||
if(device->interconnect->get_rssi) {
|
||||
ret = device->interconnect->get_rssi();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t subghz_devices_get_lqi(const SubGhzDevice* device) {
|
||||
uint8_t ret = 0;
|
||||
furi_assert(device);
|
||||
if(device->interconnect->get_lqi) {
|
||||
ret = device->interconnect->get_lqi();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool subghz_devices_rx_pipe_not_empty(const SubGhzDevice* device) {
|
||||
bool ret = false;
|
||||
furi_assert(device);
|
||||
if(device->interconnect->rx_pipe_not_empty) {
|
||||
ret = device->interconnect->rx_pipe_not_empty();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool subghz_devices_is_rx_data_crc_valid(const SubGhzDevice* device) {
|
||||
bool ret = false;
|
||||
furi_assert(device);
|
||||
if(device->interconnect->is_rx_data_crc_valid) {
|
||||
ret = device->interconnect->is_rx_data_crc_valid();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void subghz_devices_read_packet(const SubGhzDevice* device, uint8_t* data, uint8_t* size) {
|
||||
furi_assert(device);
|
||||
furi_assert(device);
|
||||
if(device->interconnect->read_packet) {
|
||||
device->interconnect->read_packet(data, size);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_devices_write_packet(const SubGhzDevice* device, const uint8_t* data, uint8_t size) {
|
||||
furi_assert(device);
|
||||
if(device->interconnect->write_packet) {
|
||||
device->interconnect->write_packet(data, size);
|
||||
}
|
||||
}
|
52
lib/subghz/devices/devices.h
Normal file
52
lib/subghz/devices/devices.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SubGhzDevice SubGhzDevice;
|
||||
|
||||
void subghz_devices_init();
|
||||
void subghz_devices_deinit(void);
|
||||
|
||||
const SubGhzDevice* subghz_devices_get_by_name(const char* device_name);
|
||||
const char* subghz_devices_get_name(const SubGhzDevice* device);
|
||||
bool subghz_devices_begin(const SubGhzDevice* device);
|
||||
void subghz_devices_end(const SubGhzDevice* device);
|
||||
bool subghz_devices_is_connect(const SubGhzDevice* device);
|
||||
void subghz_devices_reset(const SubGhzDevice* device);
|
||||
void subghz_devices_sleep(const SubGhzDevice* device);
|
||||
void subghz_devices_idle(const SubGhzDevice* device);
|
||||
void subghz_devices_load_preset(
|
||||
const SubGhzDevice* device,
|
||||
FuriHalSubGhzPreset preset,
|
||||
uint8_t* preset_data);
|
||||
uint32_t subghz_devices_set_frequency(const SubGhzDevice* device, uint32_t frequency);
|
||||
bool subghz_devices_is_frequency_valid(const SubGhzDevice* device, uint32_t frequency);
|
||||
void subghz_devices_set_async_mirror_pin(const SubGhzDevice* device, const GpioPin* gpio);
|
||||
const GpioPin* subghz_devices_get_data_gpio(const SubGhzDevice* device);
|
||||
|
||||
bool subghz_devices_set_tx(const SubGhzDevice* device);
|
||||
void subghz_devices_flush_tx(const SubGhzDevice* device);
|
||||
bool subghz_devices_start_async_tx(const SubGhzDevice* device, void* callback, void* context);
|
||||
bool subghz_devices_is_async_complete_tx(const SubGhzDevice* device);
|
||||
void subghz_devices_stop_async_tx(const SubGhzDevice* device);
|
||||
|
||||
void subghz_devices_set_rx(const SubGhzDevice* device);
|
||||
void subghz_devices_flush_rx(const SubGhzDevice* device);
|
||||
void subghz_devices_start_async_rx(const SubGhzDevice* device, void* callback, void* context);
|
||||
void subghz_devices_stop_async_rx(const SubGhzDevice* device);
|
||||
|
||||
float subghz_devices_get_rssi(const SubGhzDevice* device);
|
||||
uint8_t subghz_devices_get_lqi(const SubGhzDevice* device);
|
||||
|
||||
bool subghz_devices_rx_pipe_not_empty(const SubGhzDevice* device);
|
||||
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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
13
lib/subghz/devices/preset.h
Normal file
13
lib/subghz/devices/preset.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
/** Radio Presets */
|
||||
typedef enum {
|
||||
FuriHalSubGhzPresetIDLE, /**< default configuration */
|
||||
FuriHalSubGhzPresetOok270Async, /**< OOK, bandwidth 270kHz, asynchronous */
|
||||
FuriHalSubGhzPresetOok650Async, /**< OOK, bandwidth 650kHz, asynchronous */
|
||||
FuriHalSubGhzPreset2FSKDev238Async, /**< FM, deviation 2.380371 kHz, asynchronous */
|
||||
FuriHalSubGhzPreset2FSKDev476Async, /**< FM, deviation 47.60742 kHz, asynchronous */
|
||||
FuriHalSubGhzPresetMSK99_97KbAsync, /**< MSK, deviation 47.60742 kHz, 99.97Kb/s, asynchronous */
|
||||
FuriHalSubGhzPresetGFSK9_99KbAsync, /**< GFSK, deviation 19.042969 kHz, 9.996Kb/s, asynchronous */
|
||||
FuriHalSubGhzPresetCustom, /**Custom Preset*/
|
||||
} FuriHalSubGhzPreset;
|
76
lib/subghz/devices/registry.c
Normal file
76
lib/subghz/devices/registry.c
Normal file
|
@ -0,0 +1,76 @@
|
|||
#include "registry.h"
|
||||
|
||||
#include "cc1101_int/cc1101_int_interconnect.h"
|
||||
#include <flipper_application/plugins/plugin_manager.h>
|
||||
#include <loader/firmware_api/firmware_api.h>
|
||||
|
||||
#define TAG "SubGhzDeviceRegistry"
|
||||
|
||||
struct SubGhzDeviceRegistry {
|
||||
const SubGhzDevice** items;
|
||||
size_t size;
|
||||
PluginManager* manager;
|
||||
};
|
||||
|
||||
static SubGhzDeviceRegistry* subghz_device_registry = NULL;
|
||||
|
||||
void subghz_device_registry_init(void) {
|
||||
SubGhzDeviceRegistry* subghz_device =
|
||||
(SubGhzDeviceRegistry*)malloc(sizeof(SubGhzDeviceRegistry));
|
||||
subghz_device->manager = plugin_manager_alloc(
|
||||
SUBGHZ_RADIO_DEVICE_PLUGIN_APP_ID,
|
||||
SUBGHZ_RADIO_DEVICE_PLUGIN_API_VERSION,
|
||||
firmware_api_interface);
|
||||
|
||||
//ToDo: fix path to plugins
|
||||
if(plugin_manager_load_all(subghz_device->manager, "/any/apps_data/subghz/plugins") !=
|
||||
//if(plugin_manager_load_all(subghz_device->manager, APP_DATA_PATH("plugins")) !=
|
||||
PluginManagerErrorNone) {
|
||||
FURI_LOG_E(TAG, "Failed to load all libs");
|
||||
}
|
||||
|
||||
subghz_device->size = plugin_manager_get_count(subghz_device->manager) + 1;
|
||||
subghz_device->items =
|
||||
(const SubGhzDevice**)malloc(sizeof(SubGhzDevice*) * subghz_device->size);
|
||||
subghz_device->items[0] = &subghz_device_cc1101_int;
|
||||
for(uint32_t i = 1; i < subghz_device->size; i++) {
|
||||
const SubGhzDevice* plugin = plugin_manager_get_ep(subghz_device->manager, i - 1);
|
||||
subghz_device->items[i] = plugin;
|
||||
}
|
||||
|
||||
FURI_LOG_I(TAG, "Loaded %zu radio device", subghz_device->size);
|
||||
subghz_device_registry = subghz_device;
|
||||
}
|
||||
|
||||
void subghz_device_registry_deinit(void) {
|
||||
plugin_manager_free(subghz_device_registry->manager);
|
||||
free(subghz_device_registry->items);
|
||||
free(subghz_device_registry);
|
||||
subghz_device_registry = NULL;
|
||||
}
|
||||
|
||||
bool subghz_device_registry_is_valid(void) {
|
||||
return subghz_device_registry != NULL;
|
||||
}
|
||||
|
||||
const SubGhzDevice* subghz_device_registry_get_by_name(const char* name) {
|
||||
furi_assert(subghz_device_registry);
|
||||
|
||||
if(name != NULL) {
|
||||
for(size_t i = 0; i < subghz_device_registry->size; i++) {
|
||||
if(strcmp(name, subghz_device_registry->items[i]->name) == 0) {
|
||||
return subghz_device_registry->items[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const SubGhzDevice* subghz_device_registry_get_by_index(size_t index) {
|
||||
furi_assert(subghz_device_registry);
|
||||
if(index < subghz_device_registry->size) {
|
||||
return subghz_device_registry->items[index];
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
40
lib/subghz/devices/registry.h
Normal file
40
lib/subghz/devices/registry.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SubGhzDevice SubGhzDevice;
|
||||
|
||||
void subghz_device_registry_init(void);
|
||||
|
||||
void subghz_device_registry_deinit(void);
|
||||
|
||||
bool subghz_device_registry_is_valid(void);
|
||||
|
||||
/**
|
||||
* Registration by name SubGhzDevice.
|
||||
* @param name SubGhzDevice name
|
||||
* @return SubGhzDevice* pointer to a SubGhzDevice instance
|
||||
*/
|
||||
const SubGhzDevice* subghz_device_registry_get_by_name(const char* name);
|
||||
|
||||
/**
|
||||
* Registration subghzdevice by index in array SubGhzDevice.
|
||||
* @param index SubGhzDevice by index in array
|
||||
* @return SubGhzDevice* pointer to a SubGhzDevice instance
|
||||
*/
|
||||
const SubGhzDevice* subghz_device_registry_get_by_index(size_t index);
|
||||
|
||||
/**
|
||||
* Getting the number of registered subghzdevices.
|
||||
* @param subghz_device SubGhzDeviceRegistry
|
||||
* @return Number of subghzdevices
|
||||
*/
|
||||
size_t subghz_device_registry_count(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
91
lib/subghz/devices/types.h
Normal file
91
lib/subghz/devices/types.h
Normal file
|
@ -0,0 +1,91 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
#include "preset.h"
|
||||
|
||||
#include <flipper_application/flipper_application.h>
|
||||
|
||||
#define SUBGHZ_RADIO_DEVICE_PLUGIN_APP_ID "subghz_radio_device"
|
||||
#define SUBGHZ_RADIO_DEVICE_PLUGIN_API_VERSION 1
|
||||
|
||||
typedef struct SubGhzDeviceRegistry SubGhzDeviceRegistry;
|
||||
typedef struct SubGhzDevice SubGhzDevice;
|
||||
|
||||
typedef bool (*SubGhzBegin)(void);
|
||||
typedef void (*SubGhzEnd)(void);
|
||||
typedef bool (*SubGhzIsConnect)(void);
|
||||
typedef void (*SubGhzReset)(void);
|
||||
typedef void (*SubGhzSleep)(void);
|
||||
typedef void (*SubGhzIdle)(void);
|
||||
typedef void (*SubGhzLoadPreset)(FuriHalSubGhzPreset preset, uint8_t* preset_data);
|
||||
typedef uint32_t (*SubGhzSetFrequency)(uint32_t frequency);
|
||||
typedef bool (*SubGhzIsFrequencyValid)(uint32_t frequency);
|
||||
|
||||
typedef void (*SubGhzSetAsyncMirrorPin)(const GpioPin* gpio);
|
||||
typedef const GpioPin* (*SubGhzGetDataGpio)(void);
|
||||
|
||||
typedef bool (*SubGhzSetTx)(void);
|
||||
typedef void (*SubGhzFlushTx)(void);
|
||||
typedef bool (*SubGhzStartAsyncTx)(void* callback, void* context);
|
||||
typedef bool (*SubGhzIsAsyncCompleteTx)(void);
|
||||
typedef void (*SubGhzStopAsyncTx)(void);
|
||||
|
||||
typedef void (*SubGhzSetRx)(void);
|
||||
typedef void (*SubGhzFlushRx)(void);
|
||||
typedef void (*SubGhzStartAsyncRx)(void* callback, void* context);
|
||||
typedef void (*SubGhzStopAsyncRx)(void);
|
||||
|
||||
typedef float (*SubGhzGetRSSI)(void);
|
||||
typedef uint8_t (*SubGhzGetLQI)(void);
|
||||
|
||||
typedef bool (*SubGhzRxPipeNotEmpty)(void);
|
||||
typedef bool (*SubGhzRxIsDataCrcValid)(void);
|
||||
typedef void (*SubGhzReadPacket)(uint8_t* data, uint8_t* size);
|
||||
typedef void (*SubGhzWritePacket)(const uint8_t* data, uint8_t size);
|
||||
|
||||
typedef struct {
|
||||
SubGhzBegin begin;
|
||||
SubGhzEnd end;
|
||||
|
||||
SubGhzIsConnect is_connect;
|
||||
SubGhzReset reset;
|
||||
SubGhzSleep sleep;
|
||||
SubGhzIdle idle;
|
||||
|
||||
SubGhzLoadPreset load_preset;
|
||||
SubGhzSetFrequency set_frequency;
|
||||
SubGhzIsFrequencyValid is_frequency_valid;
|
||||
SubGhzSetAsyncMirrorPin set_async_mirror_pin;
|
||||
SubGhzGetDataGpio get_data_gpio;
|
||||
|
||||
SubGhzSetTx set_tx;
|
||||
SubGhzFlushTx flush_tx;
|
||||
SubGhzStartAsyncTx start_async_tx;
|
||||
SubGhzIsAsyncCompleteTx is_async_complete_tx;
|
||||
SubGhzStopAsyncTx stop_async_tx;
|
||||
|
||||
SubGhzSetRx set_rx;
|
||||
SubGhzFlushRx flush_rx;
|
||||
SubGhzStartAsyncRx start_async_rx;
|
||||
SubGhzStopAsyncRx stop_async_rx;
|
||||
|
||||
SubGhzGetRSSI get_rssi;
|
||||
SubGhzGetLQI get_lqi;
|
||||
|
||||
SubGhzRxPipeNotEmpty rx_pipe_not_empty;
|
||||
SubGhzRxIsDataCrcValid is_rx_data_crc_valid;
|
||||
SubGhzReadPacket read_packet;
|
||||
SubGhzWritePacket write_packet;
|
||||
|
||||
} SubGhzDeviceInterconnect;
|
||||
|
||||
struct SubGhzDevice {
|
||||
const char* name;
|
||||
const SubGhzDeviceInterconnect* interconnect;
|
||||
};
|
|
@ -40,6 +40,7 @@ struct SubGhzProtocolEncoderRAW {
|
|||
|
||||
bool is_running;
|
||||
FuriString* file_name;
|
||||
FuriString* radio_device_name;
|
||||
SubGhzFileEncoderWorker* file_worker_encoder;
|
||||
};
|
||||
|
||||
|
@ -282,6 +283,7 @@ void* subghz_protocol_encoder_raw_alloc(SubGhzEnvironment* environment) {
|
|||
|
||||
instance->base.protocol = &subghz_protocol_raw;
|
||||
instance->file_name = furi_string_alloc();
|
||||
instance->radio_device_name = furi_string_alloc();
|
||||
instance->is_running = false;
|
||||
return instance;
|
||||
}
|
||||
|
@ -300,6 +302,7 @@ void subghz_protocol_encoder_raw_free(void* context) {
|
|||
SubGhzProtocolEncoderRAW* instance = context;
|
||||
subghz_protocol_encoder_raw_stop(instance);
|
||||
furi_string_free(instance->file_name);
|
||||
furi_string_free(instance->radio_device_name);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
|
@ -318,7 +321,9 @@ static bool subghz_protocol_encoder_raw_worker_init(SubGhzProtocolEncoderRAW* in
|
|||
|
||||
instance->file_worker_encoder = subghz_file_encoder_worker_alloc();
|
||||
if(subghz_file_encoder_worker_start(
|
||||
instance->file_worker_encoder, furi_string_get_cstr(instance->file_name))) {
|
||||
instance->file_worker_encoder,
|
||||
furi_string_get_cstr(instance->file_name),
|
||||
furi_string_get_cstr(instance->radio_device_name))) {
|
||||
//the worker needs a file in order to open and read part of the file
|
||||
furi_delay_ms(100);
|
||||
instance->is_running = true;
|
||||
|
@ -328,7 +333,10 @@ static bool subghz_protocol_encoder_raw_worker_init(SubGhzProtocolEncoderRAW* in
|
|||
return instance->is_running;
|
||||
}
|
||||
|
||||
void subghz_protocol_raw_gen_fff_data(FlipperFormat* flipper_format, const char* file_path) {
|
||||
void subghz_protocol_raw_gen_fff_data(
|
||||
FlipperFormat* flipper_format,
|
||||
const char* file_path,
|
||||
const char* radio_device_name) {
|
||||
do {
|
||||
stream_clean(flipper_format_get_raw_stream(flipper_format));
|
||||
if(!flipper_format_write_string_cstr(flipper_format, "Protocol", "RAW")) {
|
||||
|
@ -340,6 +348,12 @@ void subghz_protocol_raw_gen_fff_data(FlipperFormat* flipper_format, const char*
|
|||
FURI_LOG_E(TAG, "Unable to add File_name");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_format_write_string_cstr(
|
||||
flipper_format, "Radio_device_name", radio_device_name)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Radio_device_name");
|
||||
break;
|
||||
}
|
||||
} while(false);
|
||||
}
|
||||
|
||||
|
@ -364,6 +378,13 @@ SubGhzProtocolStatus
|
|||
}
|
||||
furi_string_set(instance->file_name, temp_str);
|
||||
|
||||
if(!flipper_format_read_string(flipper_format, "Radio_device_name", temp_str)) {
|
||||
FURI_LOG_E(TAG, "Missing Radio_device_name");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
furi_string_set(instance->radio_device_name, temp_str);
|
||||
|
||||
if(!subghz_protocol_encoder_raw_worker_init(instance)) {
|
||||
res = SubGhzProtocolStatusErrorEncoderGetUpload;
|
||||
break;
|
||||
|
|
|
@ -126,8 +126,12 @@ void subghz_protocol_raw_file_encoder_worker_set_callback_end(
|
|||
* File generation for RAW work.
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @param file_path File path
|
||||
* @param radio_dev_name Radio device name
|
||||
*/
|
||||
void subghz_protocol_raw_gen_fff_data(FlipperFormat* flipper_format, const char* file_path);
|
||||
void subghz_protocol_raw_gen_fff_data(
|
||||
FlipperFormat* flipper_format,
|
||||
const char* file_path,
|
||||
const char* radio_dev_name);
|
||||
|
||||
/**
|
||||
* Deserialize and generating an upload to send.
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <toolbox/stream/stream.h>
|
||||
#include <flipper_format/flipper_format.h>
|
||||
#include <flipper_format/flipper_format_i.h>
|
||||
#include <lib/subghz/devices/devices.h>
|
||||
|
||||
#define TAG "SubGhzFileEncoderWorker"
|
||||
|
||||
|
@ -21,6 +22,7 @@ struct SubGhzFileEncoderWorker {
|
|||
bool is_storage_slow;
|
||||
FuriString* str_data;
|
||||
FuriString* file_path;
|
||||
const SubGhzDevice* device;
|
||||
|
||||
SubGhzFileEncoderWorkerCallbackEnd callback_end;
|
||||
void* context_end;
|
||||
|
@ -180,10 +182,13 @@ static int32_t subghz_file_encoder_worker_thread(void* context) {
|
|||
if(instance->is_storage_slow) {
|
||||
FURI_LOG_E(TAG, "Storage is slow");
|
||||
}
|
||||
|
||||
FURI_LOG_I(TAG, "End read file");
|
||||
while(!furi_hal_subghz_is_async_tx_complete() && instance->worker_running) {
|
||||
while(instance->device && !subghz_devices_is_async_complete_tx(instance->device) &&
|
||||
instance->worker_running) {
|
||||
furi_delay_ms(5);
|
||||
}
|
||||
|
||||
FURI_LOG_I(TAG, "End transmission");
|
||||
while(instance->worker_running) {
|
||||
if(instance->worker_stopping) {
|
||||
|
@ -230,12 +235,16 @@ void subghz_file_encoder_worker_free(SubGhzFileEncoderWorker* instance) {
|
|||
free(instance);
|
||||
}
|
||||
|
||||
bool subghz_file_encoder_worker_start(SubGhzFileEncoderWorker* instance, const char* file_path) {
|
||||
bool subghz_file_encoder_worker_start(
|
||||
SubGhzFileEncoderWorker* instance,
|
||||
const char* file_path,
|
||||
const char* radio_device_name) {
|
||||
furi_assert(instance);
|
||||
furi_assert(!instance->worker_running);
|
||||
|
||||
furi_stream_buffer_reset(instance->stream);
|
||||
furi_string_set(instance->file_path, file_path);
|
||||
instance->device = subghz_devices_get_by_name(radio_device_name);
|
||||
instance->worker_running = true;
|
||||
furi_thread_start(instance->thread);
|
||||
|
||||
|
|
|
@ -51,9 +51,14 @@ LevelDuration subghz_file_encoder_worker_get_level_duration(void* context);
|
|||
/**
|
||||
* Start SubGhzFileEncoderWorker.
|
||||
* @param instance Pointer to a SubGhzFileEncoderWorker instance
|
||||
* @param file_path File path
|
||||
* @param radio_device_name Radio device name
|
||||
* @return bool - true if ok
|
||||
*/
|
||||
bool subghz_file_encoder_worker_start(SubGhzFileEncoderWorker* instance, const char* file_path);
|
||||
bool subghz_file_encoder_worker_start(
|
||||
SubGhzFileEncoderWorker* instance,
|
||||
const char* file_path,
|
||||
const char* radio_device_name);
|
||||
|
||||
/**
|
||||
* Stop SubGhzFileEncoderWorker
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include <furi.h>
|
||||
#include <m-list.h>
|
||||
#include <furi_hal_subghz_configs.h>
|
||||
#include <lib/subghz/devices/cc1101_configs.h>
|
||||
|
||||
#define TAG "SubGhzSetting"
|
||||
|
||||
|
@ -149,8 +149,7 @@ void subghz_setting_free(SubGhzSetting* instance) {
|
|||
static void subghz_setting_load_default_preset(
|
||||
SubGhzSetting* instance,
|
||||
const char* preset_name,
|
||||
const uint8_t* preset_data,
|
||||
const uint8_t preset_pa_table[8]) {
|
||||
const uint8_t* preset_data) {
|
||||
furi_assert(instance);
|
||||
furi_assert(preset_data);
|
||||
uint32_t preset_data_count = 0;
|
||||
|
@ -166,10 +165,8 @@ static void subghz_setting_load_default_preset(
|
|||
preset_data_count += 2;
|
||||
item->custom_preset_data_size = sizeof(uint8_t) * preset_data_count + sizeof(uint8_t) * 8;
|
||||
item->custom_preset_data = malloc(item->custom_preset_data_size);
|
||||
//load preset register
|
||||
memcpy(&item->custom_preset_data[0], &preset_data[0], preset_data_count);
|
||||
//load pa table
|
||||
memcpy(&item->custom_preset_data[preset_data_count], &preset_pa_table[0], 8);
|
||||
//load preset register + pa table
|
||||
memcpy(&item->custom_preset_data[0], &preset_data[0], item->custom_preset_data_size);
|
||||
}
|
||||
|
||||
static void subghz_setting_load_default_region(
|
||||
|
@ -193,25 +190,13 @@ static void subghz_setting_load_default_region(
|
|||
}
|
||||
|
||||
subghz_setting_load_default_preset(
|
||||
instance,
|
||||
"AM270",
|
||||
(uint8_t*)furi_hal_subghz_preset_ook_270khz_async_regs,
|
||||
furi_hal_subghz_preset_ook_async_patable);
|
||||
instance, "AM270", subghz_device_cc1101_preset_ook_270khz_async_regs);
|
||||
subghz_setting_load_default_preset(
|
||||
instance,
|
||||
"AM650",
|
||||
(uint8_t*)furi_hal_subghz_preset_ook_650khz_async_regs,
|
||||
furi_hal_subghz_preset_ook_async_patable);
|
||||
instance, "AM650", subghz_device_cc1101_preset_ook_650khz_async_regs);
|
||||
subghz_setting_load_default_preset(
|
||||
instance,
|
||||
"FM238",
|
||||
(uint8_t*)furi_hal_subghz_preset_2fsk_dev2_38khz_async_regs,
|
||||
furi_hal_subghz_preset_2fsk_async_patable);
|
||||
instance, "FM238", subghz_device_cc1101_preset_2fsk_dev2_38khz_async_regs);
|
||||
subghz_setting_load_default_preset(
|
||||
instance,
|
||||
"FM476",
|
||||
(uint8_t*)furi_hal_subghz_preset_2fsk_dev47_6khz_async_regs,
|
||||
furi_hal_subghz_preset_2fsk_async_patable);
|
||||
instance, "FM476", subghz_device_cc1101_preset_2fsk_dev47_6khz_async_regs);
|
||||
}
|
||||
|
||||
// Region check removed
|
||||
|
@ -270,6 +255,7 @@ void subghz_setting_load(SubGhzSetting* instance, const char* file_path) {
|
|||
}
|
||||
while(flipper_format_read_uint32(
|
||||
fff_data_file, "Frequency", (uint32_t*)&temp_data32, 1)) {
|
||||
//Todo: add a frequency support check depending on the selected radio device
|
||||
if(furi_hal_subghz_is_frequency_valid(temp_data32)) {
|
||||
FURI_LOG_I(TAG, "Frequency loaded %lu", temp_data32);
|
||||
FrequencyList_push_back(instance->frequencies, temp_data32);
|
||||
|
|
|
@ -21,6 +21,8 @@ struct SubGhzTxRxWorker {
|
|||
SubGhzTxRxWorkerStatus status;
|
||||
|
||||
uint32_t frequency;
|
||||
const SubGhzDevice* device;
|
||||
const GpioPin* device_data_gpio;
|
||||
|
||||
SubGhzTxRxWorkerCallbackHaveRead callback_have_read;
|
||||
void* context_have_read;
|
||||
|
@ -65,33 +67,33 @@ bool subghz_tx_rx_worker_rx(SubGhzTxRxWorker* instance, uint8_t* data, uint8_t*
|
|||
uint8_t timeout = 100;
|
||||
bool ret = false;
|
||||
if(instance->status != SubGhzTxRxWorkerStatusRx) {
|
||||
furi_hal_subghz_rx();
|
||||
subghz_devices_set_rx(instance->device);
|
||||
instance->status = SubGhzTxRxWorkerStatusRx;
|
||||
furi_delay_tick(1);
|
||||
}
|
||||
//waiting for reception to complete
|
||||
while(furi_hal_gpio_read(furi_hal_subghz.cc1101_g0_pin)) {
|
||||
while(furi_hal_gpio_read(instance->device_data_gpio)) {
|
||||
furi_delay_tick(1);
|
||||
if(!--timeout) {
|
||||
FURI_LOG_W(TAG, "RX cc1101_g0 timeout");
|
||||
furi_hal_subghz_flush_rx();
|
||||
furi_hal_subghz_rx();
|
||||
subghz_devices_flush_rx(instance->device);
|
||||
subghz_devices_set_rx(instance->device);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(furi_hal_subghz_rx_pipe_not_empty()) {
|
||||
if(subghz_devices_rx_pipe_not_empty(instance->device)) {
|
||||
FURI_LOG_I(
|
||||
TAG,
|
||||
"RSSI: %03.1fdbm LQI: %d",
|
||||
(double)furi_hal_subghz_get_rssi(),
|
||||
furi_hal_subghz_get_lqi());
|
||||
if(furi_hal_subghz_is_rx_data_crc_valid()) {
|
||||
furi_hal_subghz_read_packet(data, size);
|
||||
(double)subghz_devices_get_rssi(instance->device),
|
||||
subghz_devices_get_lqi(instance->device));
|
||||
if(subghz_devices_is_rx_data_crc_valid(instance->device)) {
|
||||
subghz_devices_read_packet(instance->device, data, size);
|
||||
ret = true;
|
||||
}
|
||||
furi_hal_subghz_flush_rx();
|
||||
furi_hal_subghz_rx();
|
||||
subghz_devices_flush_rx(instance->device);
|
||||
subghz_devices_set_rx(instance->device);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -99,13 +101,13 @@ bool subghz_tx_rx_worker_rx(SubGhzTxRxWorker* instance, uint8_t* data, uint8_t*
|
|||
void subghz_tx_rx_worker_tx(SubGhzTxRxWorker* instance, uint8_t* data, size_t size) {
|
||||
uint8_t timeout = 200;
|
||||
if(instance->status != SubGhzTxRxWorkerStatusIDLE) {
|
||||
furi_hal_subghz_idle();
|
||||
subghz_devices_idle(instance->device);
|
||||
}
|
||||
furi_hal_subghz_write_packet(data, size);
|
||||
furi_hal_subghz_tx(); //start send
|
||||
subghz_devices_write_packet(instance->device, data, size);
|
||||
subghz_devices_set_tx(instance->device); //start send
|
||||
instance->status = SubGhzTxRxWorkerStatusTx;
|
||||
while(!furi_hal_gpio_read(
|
||||
furi_hal_subghz.cc1101_g0_pin)) { // Wait for GDO0 to be set -> sync transmitted
|
||||
instance->device_data_gpio)) { // Wait for GDO0 to be set -> sync transmitted
|
||||
furi_delay_tick(1);
|
||||
if(!--timeout) {
|
||||
FURI_LOG_W(TAG, "TX !cc1101_g0 timeout");
|
||||
|
@ -113,14 +115,14 @@ void subghz_tx_rx_worker_tx(SubGhzTxRxWorker* instance, uint8_t* data, size_t si
|
|||
}
|
||||
}
|
||||
while(furi_hal_gpio_read(
|
||||
furi_hal_subghz.cc1101_g0_pin)) { // Wait for GDO0 to be cleared -> end of packet
|
||||
instance->device_data_gpio)) { // Wait for GDO0 to be cleared -> end of packet
|
||||
furi_delay_tick(1);
|
||||
if(!--timeout) {
|
||||
FURI_LOG_W(TAG, "TX cc1101_g0 timeout");
|
||||
break;
|
||||
}
|
||||
}
|
||||
furi_hal_subghz_idle();
|
||||
subghz_devices_idle(instance->device);
|
||||
instance->status = SubGhzTxRxWorkerStatusIDLE;
|
||||
}
|
||||
/** Worker thread
|
||||
|
@ -130,16 +132,19 @@ void subghz_tx_rx_worker_tx(SubGhzTxRxWorker* instance, uint8_t* data, size_t si
|
|||
*/
|
||||
static int32_t subghz_tx_rx_worker_thread(void* context) {
|
||||
SubGhzTxRxWorker* instance = context;
|
||||
furi_assert(instance->device);
|
||||
FURI_LOG_I(TAG, "Worker start");
|
||||
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_idle();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetGFSK9_99KbAsync);
|
||||
//furi_hal_subghz_load_preset(FuriHalSubGhzPresetMSK99_97KbAsync);
|
||||
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
subghz_devices_begin(instance->device);
|
||||
instance->device_data_gpio = subghz_devices_get_data_gpio(instance->device);
|
||||
subghz_devices_reset(instance->device);
|
||||
subghz_devices_idle(instance->device);
|
||||
subghz_devices_load_preset(instance->device, FuriHalSubGhzPresetGFSK9_99KbAsync, NULL);
|
||||
|
||||
furi_hal_subghz_set_frequency_and_path(instance->frequency);
|
||||
furi_hal_subghz_flush_rx();
|
||||
furi_hal_gpio_init(instance->device_data_gpio, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
subghz_devices_set_frequency(instance->device, instance->frequency);
|
||||
subghz_devices_flush_rx(instance->device);
|
||||
|
||||
uint8_t data[SUBGHZ_TXRX_WORKER_MAX_TXRX_SIZE + 1] = {0};
|
||||
size_t size_tx = 0;
|
||||
|
@ -193,8 +198,8 @@ static int32_t subghz_tx_rx_worker_thread(void* context) {
|
|||
furi_delay_tick(1);
|
||||
}
|
||||
|
||||
furi_hal_subghz_set_path(FuriHalSubGhzPathIsolate);
|
||||
furi_hal_subghz_sleep();
|
||||
subghz_devices_sleep(instance->device);
|
||||
subghz_devices_end(instance->device);
|
||||
|
||||
FURI_LOG_I(TAG, "Worker stop");
|
||||
return 0;
|
||||
|
@ -226,7 +231,10 @@ void subghz_tx_rx_worker_free(SubGhzTxRxWorker* instance) {
|
|||
free(instance);
|
||||
}
|
||||
|
||||
bool subghz_tx_rx_worker_start(SubGhzTxRxWorker* instance, uint32_t frequency) {
|
||||
bool subghz_tx_rx_worker_start(
|
||||
SubGhzTxRxWorker* instance,
|
||||
const SubGhzDevice* device,
|
||||
uint32_t frequency) {
|
||||
furi_assert(instance);
|
||||
furi_assert(!instance->worker_running);
|
||||
bool res = false;
|
||||
|
@ -237,6 +245,7 @@ bool subghz_tx_rx_worker_start(SubGhzTxRxWorker* instance, uint32_t frequency) {
|
|||
|
||||
if(furi_hal_subghz_is_tx_allowed(frequency)) {
|
||||
instance->frequency = frequency;
|
||||
instance->device = device;
|
||||
res = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <furi_hal.h>
|
||||
#include <devices/devices.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -67,9 +68,13 @@ void subghz_tx_rx_worker_free(SubGhzTxRxWorker* instance);
|
|||
/**
|
||||
* Start SubGhzTxRxWorker
|
||||
* @param instance Pointer to a SubGhzTxRxWorker instance
|
||||
* @param device Pointer to a SubGhzDevice instance
|
||||
* @return bool - true if ok
|
||||
*/
|
||||
bool subghz_tx_rx_worker_start(SubGhzTxRxWorker* instance, uint32_t frequency);
|
||||
bool subghz_tx_rx_worker_start(
|
||||
SubGhzTxRxWorker* instance,
|
||||
const SubGhzDevice* device,
|
||||
uint32_t frequency);
|
||||
|
||||
/**
|
||||
* Stop SubGhzTxRxWorker
|
||||
|
|
|
@ -21,6 +21,12 @@
|
|||
#define SUBGHZ_RAW_FILE_VERSION 1
|
||||
#define SUBGHZ_RAW_FILE_TYPE "Flipper SubGhz RAW File"
|
||||
|
||||
#define SUBGHZ_KEYSTORE_DIR_NAME EXT_PATH("subghz/assets/keeloq_mfcodes")
|
||||
#define SUBGHZ_KEYSTORE_DIR_USER_NAME EXT_PATH("subghz/assets/keeloq_mfcodes_user")
|
||||
#define SUBGHZ_CAME_ATOMO_DIR_NAME EXT_PATH("subghz/assets/came_atomo")
|
||||
#define SUBGHZ_NICE_FLOR_S_DIR_NAME EXT_PATH("subghz/assets/nice_flor_s")
|
||||
#define SUBGHZ_ALUTECH_AT_4N_DIR_NAME EXT_PATH("subghz/assets/alutech_at_4n")
|
||||
|
||||
typedef struct SubGhzProtocolRegistry SubGhzProtocolRegistry;
|
||||
typedef struct SubGhzEnvironment SubGhzEnvironment;
|
||||
|
||||
|
|
|
@ -233,6 +233,7 @@ vars.AddVariables(
|
|||
("applications/debug", False),
|
||||
("applications/external", False),
|
||||
("applications/examples", False),
|
||||
("applications/drivers", False),
|
||||
("applications_user", False),
|
||||
],
|
||||
),
|
||||
|
|
Loading…
Reference in a new issue