mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
Move amped code
This commit is contained in:
@@ -21,6 +21,10 @@
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO &gpio_ext_pb2
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_EXTENDED_RANGE false
|
||||
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_E07M20S_AMP_GPIO &gpio_ext_pc3
|
||||
|
||||
#define SUBGHZ_DEVICE_CC1101_CONFIG_VER 1
|
||||
|
||||
/* DMA Channels definition */
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_DMA DMA2
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_CHANNEL LL_DMA_CHANNEL_3
|
||||
@@ -79,6 +83,8 @@ typedef struct {
|
||||
const GpioPin* g0_pin;
|
||||
SubGhzDeviceCC1101ExtAsyncTx async_tx;
|
||||
SubGhzDeviceCC1101ExtAsyncRx async_rx;
|
||||
bool power_amp;
|
||||
bool extended_range;
|
||||
} SubGhzDeviceCC1101Ext;
|
||||
|
||||
static SubGhzDeviceCC1101Ext* subghz_device_cc1101_ext = NULL;
|
||||
@@ -188,16 +194,24 @@ static bool subghz_device_cc1101_ext_check_init() {
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool subghz_device_cc1101_ext_alloc() {
|
||||
bool subghz_device_cc1101_ext_alloc(SubGhzDeviceConf* conf) {
|
||||
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->g0_pin = SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO;
|
||||
|
||||
subghz_device_cc1101_ext->async_rx.capture_delta_duration = 0;
|
||||
subghz_device_cc1101_ext->power_amp = false;
|
||||
subghz_device_cc1101_ext->extended_range = false;
|
||||
if(conf) {
|
||||
if(conf->ver == SUBGHZ_DEVICE_CC1101_CONFIG_VER) {
|
||||
subghz_device_cc1101_ext->power_amp = conf->power_amp;
|
||||
subghz_device_cc1101_ext->extended_range = conf->extended_range;
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Config version mismatch");
|
||||
}
|
||||
}
|
||||
|
||||
subghz_device_cc1101_ext->spi_bus_handle =
|
||||
(XTREME_SETTINGS()->spi_cc1101_handle == SpiDefault ?
|
||||
@@ -215,6 +229,13 @@ bool subghz_device_cc1101_ext_alloc() {
|
||||
}
|
||||
|
||||
furi_hal_spi_bus_handle_init(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
|
||||
if(subghz_device_cc1101_ext->power_amp) {
|
||||
furi_hal_gpio_init_simple(
|
||||
SUBGHZ_DEVICE_CC1101_EXT_E07M20S_AMP_GPIO, GpioModeOutputPushPull);
|
||||
furi_hal_gpio_write(SUBGHZ_DEVICE_CC1101_EXT_E07M20S_AMP_GPIO, 0);
|
||||
}
|
||||
|
||||
return subghz_device_cc1101_ext_check_init();
|
||||
}
|
||||
|
||||
@@ -222,14 +243,15 @@ 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;
|
||||
|
||||
// resetting the CS pins to floating
|
||||
if(XTREME_SETTINGS()->spi_nrf24_handle == SpiDefault) {
|
||||
if(XTREME_SETTINGS()->spi_nrf24_handle == SpiDefault || subghz_device_cc1101_ext->power_amp) {
|
||||
furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog);
|
||||
} else if(XTREME_SETTINGS()->spi_nrf24_handle == SpiExtra) {
|
||||
furi_hal_gpio_init_simple(&gpio_ext_pa4, GpioModeAnalog);
|
||||
}
|
||||
|
||||
subghz_device_cc1101_ext = NULL;
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_set_async_mirror_pin(const GpioPin* pin) {
|
||||
@@ -244,7 +266,7 @@ bool subghz_device_cc1101_ext_is_connect() {
|
||||
bool ret = false;
|
||||
|
||||
if(subghz_device_cc1101_ext == NULL) { // not initialized
|
||||
ret = subghz_device_cc1101_ext_alloc();
|
||||
ret = subghz_device_cc1101_ext_alloc(NULL);
|
||||
subghz_device_cc1101_ext_free();
|
||||
} else { // initialized
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
@@ -404,12 +426,18 @@ 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);
|
||||
if(subghz_device_cc1101_ext->power_amp) {
|
||||
furi_hal_gpio_write(SUBGHZ_DEVICE_CC1101_EXT_E07M20S_AMP_GPIO, 0);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
if(subghz_device_cc1101_ext->power_amp) {
|
||||
furi_hal_gpio_write(SUBGHZ_DEVICE_CC1101_EXT_E07M20S_AMP_GPIO, 0);
|
||||
}
|
||||
}
|
||||
|
||||
bool subghz_device_cc1101_ext_tx() {
|
||||
@@ -417,6 +445,9 @@ bool subghz_device_cc1101_ext_tx() {
|
||||
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);
|
||||
if(subghz_device_cc1101_ext->power_amp) {
|
||||
furi_hal_gpio_write(SUBGHZ_DEVICE_CC1101_EXT_E07M20S_AMP_GPIO, 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#pragma once
|
||||
#include <lib/subghz/devices/preset.h>
|
||||
#include <lib/subghz/devices/types.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
@@ -35,7 +36,7 @@ const GpioPin* subghz_device_cc1101_ext_get_data_gpio();
|
||||
*
|
||||
* @return true if success
|
||||
*/
|
||||
bool subghz_device_cc1101_ext_alloc();
|
||||
bool subghz_device_cc1101_ext_alloc(SubGhzDeviceConf* conf);
|
||||
|
||||
/** Deinitialize device
|
||||
*/
|
||||
|
||||
@@ -117,19 +117,19 @@ static void subghz_scene_reciever_config_set_ext_mod_power_amp_text(VariableItem
|
||||
|
||||
variable_item_set_current_value_text(item, ext_mod_power_amp_text[index]);
|
||||
|
||||
if(index == 1) {
|
||||
furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull);
|
||||
furi_hal_gpio_write(&gpio_ext_pc3, 0);
|
||||
} else {
|
||||
furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog);
|
||||
}
|
||||
|
||||
subghz->last_settings->external_module_power_amp = index == 1;
|
||||
|
||||
// Set globally in furi hal
|
||||
furi_hal_subghz_set_ext_power_amp(subghz->last_settings->external_module_power_amp);
|
||||
|
||||
subghz_last_settings_save(subghz->last_settings);
|
||||
|
||||
// reinit external device
|
||||
const SubGhzRadioDeviceType current = subghz_txrx_radio_device_get(subghz->txrx);
|
||||
if(current != SubGhzRadioDeviceTypeInternal) {
|
||||
subghz_txrx_radio_device_set(subghz->txrx, SubGhzRadioDeviceTypeInternal);
|
||||
subghz_txrx_radio_device_set(subghz->txrx, current);
|
||||
}
|
||||
}
|
||||
|
||||
static void subghz_scene_receiver_config_set_timestamp_file_names(VariableItem* item) {
|
||||
|
||||
@@ -12,10 +12,6 @@ void subghz_devices_init() {
|
||||
void subghz_devices_deinit(void) {
|
||||
furi_check(subghz_device_registry_is_valid());
|
||||
subghz_device_registry_deinit();
|
||||
|
||||
if(furi_hal_subghz_get_ext_power_amp()) {
|
||||
furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog);
|
||||
}
|
||||
}
|
||||
|
||||
const SubGhzDevice* subghz_devices_get_by_name(const char* device_name) {
|
||||
@@ -36,24 +32,13 @@ bool subghz_devices_begin(const SubGhzDevice* device) {
|
||||
bool ret = false;
|
||||
furi_assert(device);
|
||||
if(device->interconnect->begin) {
|
||||
// TODO: Remake this check and move this code
|
||||
if(strcmp("cc1101_ext", device->name) == 0) {
|
||||
SubGhzLastSettings* last_settings = subghz_last_settings_alloc();
|
||||
subghz_last_settings_load(last_settings, 0);
|
||||
SubGhzDeviceConf conf = {
|
||||
.ver = 1,
|
||||
.extended_range = false, // TODO
|
||||
.power_amp = furi_hal_subghz_get_ext_power_amp(),
|
||||
};
|
||||
|
||||
if(last_settings->external_module_power_amp) {
|
||||
furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull);
|
||||
furi_hal_subghz_set_ext_power_amp(true);
|
||||
}
|
||||
|
||||
subghz_last_settings_free(last_settings);
|
||||
|
||||
if(furi_hal_subghz_get_ext_power_amp()) {
|
||||
furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull);
|
||||
}
|
||||
}
|
||||
|
||||
ret = device->interconnect->begin();
|
||||
ret = device->interconnect->begin(&conf);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -61,12 +46,6 @@ bool subghz_devices_begin(const SubGhzDevice* device) {
|
||||
void subghz_devices_end(const SubGhzDevice* device) {
|
||||
furi_assert(device);
|
||||
if(device->interconnect->end) {
|
||||
// TODO: Remake this check and move this code
|
||||
if(strcmp("cc1101_ext", device->name) == 0) {
|
||||
if(furi_hal_subghz_get_ext_power_amp()) {
|
||||
furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog);
|
||||
}
|
||||
}
|
||||
device->interconnect->end();
|
||||
}
|
||||
}
|
||||
@@ -98,12 +77,6 @@ void subghz_devices_idle(const SubGhzDevice* device) {
|
||||
furi_assert(device);
|
||||
if(device->interconnect->idle) {
|
||||
device->interconnect->idle();
|
||||
// TODO: Remake this check and move this code
|
||||
if(strcmp("cc1101_ext", device->name) == 0) {
|
||||
if(furi_hal_subghz_get_ext_power_amp()) {
|
||||
furi_hal_gpio_write(&gpio_ext_pc3, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,13 +129,6 @@ bool subghz_devices_set_tx(const SubGhzDevice* device) {
|
||||
furi_assert(device);
|
||||
if(device->interconnect->set_tx) {
|
||||
ret = device->interconnect->set_tx();
|
||||
|
||||
// TODO: Remake this check and move this code
|
||||
if(strcmp("cc1101_ext", device->name) == 0) {
|
||||
if(furi_hal_subghz_get_ext_power_amp()) {
|
||||
furi_hal_gpio_write(&gpio_ext_pc3, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -203,13 +169,6 @@ void subghz_devices_set_rx(const SubGhzDevice* device) {
|
||||
furi_assert(device);
|
||||
if(device->interconnect->set_rx) {
|
||||
device->interconnect->set_rx();
|
||||
|
||||
// TODO: Remake this check and move this code
|
||||
if(strcmp("cc1101_ext", device->name) == 0) {
|
||||
if(furi_hal_subghz_get_ext_power_amp()) {
|
||||
furi_hal_gpio_write(&gpio_ext_pc3, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,12 +12,14 @@
|
||||
#include <flipper_application/flipper_application.h>
|
||||
|
||||
#define SUBGHZ_RADIO_DEVICE_PLUGIN_APP_ID "subghz_radio_device"
|
||||
#define SUBGHZ_RADIO_DEVICE_PLUGIN_API_VERSION 1
|
||||
#define SUBGHZ_RADIO_DEVICE_PLUGIN_API_VERSION 2
|
||||
|
||||
typedef struct SubGhzDeviceRegistry SubGhzDeviceRegistry;
|
||||
typedef struct SubGhzDevice SubGhzDevice;
|
||||
typedef struct SubGhzDeviceConf SubGhzDeviceConf;
|
||||
|
||||
typedef bool (*SubGhzBegin)(void);
|
||||
// typedef bool (*SubGhzBegin)(void);
|
||||
typedef bool (*SubGhzBegin)(SubGhzDeviceConf* conf);
|
||||
typedef void (*SubGhzEnd)(void);
|
||||
typedef bool (*SubGhzIsConnect)(void);
|
||||
typedef void (*SubGhzReset)(void);
|
||||
@@ -89,3 +91,9 @@ struct SubGhzDevice {
|
||||
const char* name;
|
||||
const SubGhzDeviceInterconnect* interconnect;
|
||||
};
|
||||
|
||||
struct SubGhzDeviceConf {
|
||||
uint8_t ver;
|
||||
bool extended_range;
|
||||
bool power_amp;
|
||||
};
|
||||
Reference in New Issue
Block a user