Fix issues with external module 5v power

This commit is contained in:
MX 2023-03-06 10:08:59 +03:00
parent 507c8582ca
commit f25af91d23
No known key found for this signature in database
GPG Key ID: 7CCC66B7DBDD1C83
8 changed files with 47 additions and 5 deletions

View File

@ -402,7 +402,8 @@ bool unirfremix_key_load(
preset->decoder = subghz_receiver_search_decoder_base_by_name(
receiver, furi_string_get_cstr(preset->protocol));
if(preset->decoder) {
SubGhzProtocolStatus status = subghz_protocol_decoder_base_deserialize(preset->decoder, fff_data);
SubGhzProtocolStatus status =
subghz_protocol_decoder_base_deserialize(preset->decoder, fff_data);
if(status != SubGhzProtocolStatusOk) {
FURI_LOG_E(TAG, "Protocol deserialize failed, status = %d", status);
break;
@ -736,6 +737,8 @@ UniRFRemix* unirfremix_alloc(void) {
UniRFRemix* app = malloc(sizeof(UniRFRemix));
furi_hal_power_suppress_charge_enter();
// Enable power for External CC1101 if it is connected
furi_hal_subghz_enable_ext_power();
app->model_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
@ -757,6 +760,9 @@ UniRFRemix* unirfremix_alloc(void) {
void unirfremix_free(UniRFRemix* app, bool with_subghz) {
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();
furi_string_free(app->up_file);
furi_string_free(app->down_file);
furi_string_free(app->left_file);

View File

@ -674,6 +674,9 @@ int32_t playlist_app(void* p) {
furi_hal_power_suppress_charge_enter();
// Enable power for External CC1101 if it is connected
furi_hal_subghz_enable_ext_power();
// select playlist file
{
DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
@ -752,6 +755,8 @@ 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();
if(app->worker != NULL) {
if(playlist_worker_running(app->worker)) {

View File

@ -124,6 +124,9 @@ POCSAGPagerApp* pocsag_pager_app_alloc() {
furi_hal_power_suppress_charge_enter();
// Enable power for External CC1101 if it is connected
furi_hal_subghz_enable_ext_power();
scene_manager_next_scene(app->scene_manager, POCSAGPagerSceneStart);
return app;
@ -135,6 +138,9 @@ void pocsag_pager_app_free(POCSAGPagerApp* app) {
//CC1101 off
pcsg_sleep(app);
// Disable power for External CC1101 if it was enabled and module is connected
furi_hal_subghz_disable_ext_power();
// Submenu
view_dispatcher_remove_view(app->view_dispatcher, POCSAGPagerViewSubmenu);
submenu_free(app->submenu);

View File

@ -170,6 +170,9 @@ ProtoViewApp* protoview_app_alloc() {
furi_hal_power_suppress_charge_enter();
app->running = 1;
// Enable power for External CC1101 if it is connected
furi_hal_subghz_enable_ext_power();
return app;
}
@ -182,6 +185,9 @@ void protoview_app_free(ProtoViewApp* app) {
// Put CC1101 on sleep, this also restores charging.
radio_sleep(app);
// Disable power for External CC1101 if it was enabled and module is connected
furi_hal_subghz_disable_ext_power();
// View related.
view_port_enabled_set(app->view_port, false);
gui_remove_view_port(app->gui, app->view_port);

View File

@ -392,6 +392,9 @@ void spectrum_analyzer_free(SpectrumAnalyzer* 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();
}
int32_t spectrum_analyzer_app(void* p) {
@ -402,6 +405,9 @@ int32_t spectrum_analyzer_app(void* p) {
furi_hal_power_suppress_charge_enter();
// Enable power for External CC1101 if it is connected
furi_hal_subghz_enable_ext_power();
FURI_LOG_D("Spectrum", "Main Loop - Starting worker");
furi_delay_ms(50);

@ -1 +1 @@
Subproject commit 7cdb9e1386778ad7351f7e3b3389980afaeafea3
Subproject commit 552bd12d0f710501c31f7d44b4755d7fa89de303

View File

@ -107,6 +107,9 @@ WeatherStationApp* weather_station_app_alloc() {
furi_hal_power_suppress_charge_enter();
// Enable power for External CC1101 if it is connected
furi_hal_subghz_enable_ext_power();
scene_manager_next_scene(app->scene_manager, WeatherStationSceneStart);
return app;
@ -118,6 +121,9 @@ void weather_station_app_free(WeatherStationApp* app) {
//CC1101 off
ws_sleep(app);
// Disable power for External CC1101 if it was enabled and module is connected
furi_hal_subghz_disable_ext_power();
// Submenu
view_dispatcher_remove_view(app->view_dispatcher, WeatherStationViewSubmenu);
submenu_free(app->submenu);

View File

@ -22,6 +22,7 @@
static uint32_t furi_hal_subghz_debug_gpio_buff[2];
static bool last_OTG_state = false;
static bool ext_power_is_enabled_already = false;
/* DMA Channels definition */
#define SUBGHZ_DMA DMA2
@ -80,12 +81,16 @@ void furi_hal_subghz_init(void) {
}
void furi_hal_subghz_enable_ext_power(void) {
if(ext_power_is_enabled_already) return;
ext_power_is_enabled_already = true;
last_OTG_state = furi_hal_power_is_otg_enabled();
if(furi_hal_subghz.radio_type != SubGhzRadioInternal && !furi_hal_power_is_otg_enabled()) {
furi_hal_power_enable_otg();
}
}
void furi_hal_subghz_disable_ext_power(void) {
ext_power_is_enabled_already = false;
if(furi_hal_subghz.radio_type != SubGhzRadioInternal && !last_OTG_state) {
furi_hal_power_disable_otg();
}
@ -97,6 +102,7 @@ bool furi_hal_subghz_check_radio(void) {
furi_hal_subghz_enable_ext_power();
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);
@ -104,9 +110,10 @@ bool furi_hal_subghz_check_radio(void) {
FURI_LOG_D(TAG, "Radio check ok");
} else {
FURI_LOG_D(TAG, "Radio check failed");
furi_hal_subghz_disable_ext_power();
result = false;
}
furi_hal_subghz_disable_ext_power();
return result;
}
@ -117,7 +124,6 @@ bool furi_hal_subghz_init_check(void) {
furi_hal_subghz.state = SubGhzStateIdle;
furi_hal_subghz.preset = FuriHalSubGhzPresetIDLE;
last_OTG_state = furi_hal_power_is_otg_enabled();
furi_hal_subghz_enable_ext_power();
furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle);
@ -169,8 +175,8 @@ bool furi_hal_subghz_init_check(void) {
FURI_LOG_I(TAG, "Init OK");
} else {
FURI_LOG_E(TAG, "Failed to initialization");
furi_hal_subghz_disable_ext_power();
}
furi_hal_subghz_disable_ext_power();
return result;
}
@ -346,6 +352,7 @@ void furi_hal_subghz_reset() {
}
void furi_hal_subghz_idle() {
furi_hal_subghz_enable_ext_power();
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);