1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-12 04:34:43 +04:00

Option to disable auto 5v power for external radio module

Now you can use 3.3v modules without wasting a battery (bonus a bit low noise on power line)
This commit is contained in:
MX
2023-03-09 04:02:31 +03:00
parent da9b968fc9
commit 1249ce9b94
4 changed files with 50 additions and 2 deletions

View File

@@ -4,6 +4,7 @@
uint8_t value_index_exm;
uint8_t value_index_dpin;
uint8_t value_index_cnt;
uint8_t value_index_pwr;
#define EXT_MODULES_COUNT (sizeof(radio_modules_variables_text) / sizeof(char* const))
const char* const radio_modules_variables_text[] = {
@@ -11,6 +12,12 @@ const char* const radio_modules_variables_text[] = {
"External",
};
#define EXT_MOD_POWER_COUNT 2
const char* const ext_mod_power_text[EXT_MOD_POWER_COUNT] = {
"ON",
"OFF",
};
#define DEBUG_P_COUNT 2
const char* const debug_pin_text[DEBUG_P_COUNT] = {
"OFF",
@@ -77,6 +84,14 @@ static void subghz_scene_receiver_config_set_debug_counter(VariableItem* item) {
}
}
static void subghz_scene_receiver_config_set_ext_mod_power(VariableItem* item) {
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, ext_mod_power_text[index]);
furi_hal_subghz_set_external_power_disable(index == 1);
}
void subghz_scene_ext_module_settings_on_enter(void* context) {
SubGhz* subghz = context;
@@ -92,10 +107,20 @@ void subghz_scene_ext_module_settings_on_enter(void* context) {
variable_item_set_current_value_index(item, value_index_exm);
variable_item_set_current_value_text(item, radio_modules_variables_text[value_index_exm]);
item = variable_item_list_add(
subghz->variable_item_list,
"Ext Radio 5v",
EXT_MOD_POWER_COUNT,
subghz_scene_receiver_config_set_ext_mod_power,
subghz);
value_index_pwr = furi_hal_subghz_get_external_power_disable();
variable_item_set_current_value_index(item, value_index_pwr);
variable_item_set_current_value_text(item, ext_mod_power_text[value_index_pwr]);
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
item = variable_item_list_add(
subghz->variable_item_list,
"Debug Pin:",
"Debug Pin",
DEBUG_P_COUNT,
subghz_scene_receiver_config_set_debug_pin,
subghz);
@@ -105,7 +130,7 @@ void subghz_scene_ext_module_settings_on_enter(void* context) {
item = variable_item_list_add(
subghz->variable_item_list,
"Counter Mult:",
"Counter incr.",
DEBUG_COUNTER_COUNT,
subghz_scene_receiver_config_set_debug_counter,
subghz);

View File

@@ -1357,6 +1357,7 @@ 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_lqi,uint8_t,
Function,+,furi_hal_subghz_get_radio_type,SubGhzRadioType,
Function,+,furi_hal_subghz_get_rolling_counter_mult,uint8_t,
@@ -1377,6 +1378,7 @@ 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_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
1 entry status name type params
1357 Function + furi_hal_subghz_enable_ext_power _Bool
1358 Function + furi_hal_subghz_flush_rx void
1359 Function + furi_hal_subghz_flush_tx void
1360 Function + furi_hal_subghz_get_external_power_disable _Bool
1361 Function + furi_hal_subghz_get_lqi uint8_t
1362 Function + furi_hal_subghz_get_radio_type SubGhzRadioType
1363 Function + furi_hal_subghz_get_rolling_counter_mult uint8_t
1378 Function + furi_hal_subghz_rx void
1379 Function + furi_hal_subghz_rx_pipe_not_empty _Bool
1380 Function + furi_hal_subghz_set_async_mirror_pin void const GpioPin*
1381 Function + furi_hal_subghz_set_external_power_disable void _Bool
1382 Function + furi_hal_subghz_set_frequency uint32_t uint32_t
1383 Function + furi_hal_subghz_set_frequency_and_path uint32_t uint32_t
1384 Function + furi_hal_subghz_set_path void FuriHalSubGhzPath

View File

@@ -39,6 +39,7 @@ volatile FuriHalSubGhz furi_hal_subghz = {
.spi_bus_handle = &furi_hal_spi_bus_handle_subghz,
.cc1101_g0_pin = &gpio_cc1101_g0,
.rolling_counter_mult = 1,
.ext_module_power_disabled = false,
};
bool furi_hal_subghz_set_radio_type(SubGhzRadioType state) {
@@ -70,6 +71,14 @@ 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_async_mirror_pin(const GpioPin* pin) {
furi_hal_subghz.async_mirror_pin = pin;
}
@@ -79,6 +88,9 @@ void furi_hal_subghz_init(void) {
}
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++ < 2) {

View File

@@ -78,6 +78,7 @@ typedef struct {
FuriHalSpiBusHandle* spi_bus_handle;
const GpioPin* cc1101_g0_pin;
uint8_t rolling_counter_mult;
bool ext_module_power_disabled;
} FuriHalSubGhz;
extern volatile FuriHalSubGhz furi_hal_subghz;
@@ -321,6 +322,14 @@ uint8_t furi_hal_subghz_get_rolling_counter_mult(void);
*/
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);
/** Get the current state of the external power disable flag
*/
bool furi_hal_subghz_get_external_power_disable(void);
#ifdef __cplusplus
}
#endif