[FL-2256] USB Service (#998)

* usb service, removed power observer
* fix usb restart after disable
* remove usb service from apps
* Applcations: remove dead extern
* New thread naming scheme for drivers
* New thread symbol naming scheme for drivers

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Nikolay Minaylov
2022-02-16 20:52:34 +03:00
committed by GitHub
parent a37f1d0f6f
commit 242241987e
17 changed files with 356 additions and 286 deletions

View File

@@ -11,7 +11,6 @@ extern int32_t gui_srv(void* p);
extern int32_t input_srv(void* p);
extern int32_t loader_srv(void* p);
extern int32_t notification_srv(void* p);
extern int32_t power_observer_srv(void* p);
extern int32_t power_srv(void* p);
extern int32_t storage_srv(void* p);
extern int32_t desktop_srv(void* p);
@@ -115,10 +114,6 @@ const FlipperApplication FLIPPER_SERVICES[] = {
{.app = power_srv, .name = "PowerSrv", .stack_size = 1024, .icon = NULL},
#endif
#ifdef SRV_POWER_OBSERVER
{.app = power_observer_srv, .name = "PowerAuditSrv", .stack_size = 1024, .icon = NULL},
#endif
#ifdef SRV_STORAGE
{.app = storage_srv, .name = "StorageSrv", .stack_size = 3072, .icon = NULL},
#endif

View File

@@ -18,7 +18,6 @@ SRV_INPUT = 1
SRV_LOADER = 1
SRV_NOTIFICATION = 1
SRV_POWER = 1
SRV_POWER_OBSERVER = 1
SRV_RPC = 1
SRV_STORAGE = 1
@@ -256,13 +255,6 @@ endif
endif
SRV_POWER_OBSERVER ?= 0
ifeq ($(SRV_POWER_OBSERVER), 1)
CFLAGS += -DSRV_POWER_OBSERVER
SRV_POWER = 1
endif
SRV_POWER ?= 0
ifeq ($(SRV_POWER), 1)
CFLAGS += -DSRV_POWER

View File

@@ -196,6 +196,11 @@ int32_t power_srv(void* p) {
// Update battery view port
if(need_refresh) view_port_update(power->battery_view_port);
// Check OTG status and disable it in case of fault
if(furi_hal_power_is_otg_enabled()) {
furi_hal_power_check_otg_status();
}
osDelay(1000);
}

View File

@@ -1,76 +0,0 @@
#include <furi.h>
#include <furi_hal.h>
#include <notification/notification_messages.h>
typedef struct {
osThreadId_t thread;
} PowerObserverSrv;
const NotificationMessage message_green_110 = {
.type = NotificationMessageTypeLedGreen,
.data.led.value = 110,
};
static const NotificationSequence sequence_overconsumption = {
&message_green_110,
&message_red_255,
&message_delay_100,
NULL,
};
typedef enum {
EventReset = (1 << 0),
EventRequest = (1 << 1),
} UsbEvent;
static void usb_state_callback(FuriHalUsbStateEvent state, void* context) {
PowerObserverSrv* srv = (PowerObserverSrv*)(context);
if(state == FuriHalUsbStateEventReset) {
osThreadFlagsSet(srv->thread, EventReset);
} else if(state == FuriHalUsbStateEventDescriptorRequest) {
osThreadFlagsSet(srv->thread, EventRequest);
}
}
int32_t power_observer_srv(void* p) {
NotificationApp* notifications = furi_record_open("notification");
PowerObserverSrv* srv = furi_alloc(sizeof(PowerObserverSrv));
srv->thread = osThreadGetId();
const float overconsumption_limit = 0.03f;
bool usb_request_pending = false;
uint8_t usb_wait_time = 0;
furi_hal_usb_set_state_callback(usb_state_callback, srv);
while(true) {
uint32_t flags = osThreadFlagsWait(EventReset | EventRequest, osFlagsWaitAny, 500);
if((flags & osFlagsError) == 0) {
if(flags & EventReset) {
usb_request_pending = true;
usb_wait_time = 0;
}
if(flags & EventRequest) {
usb_request_pending = false;
}
} else if(usb_request_pending) {
usb_wait_time++;
if(usb_wait_time > 4) {
furi_hal_usb_reinit();
usb_request_pending = false;
}
}
float current = -furi_hal_power_get_battery_current(FuriHalPowerICFuelGauge);
if(current > overconsumption_limit) {
notification_message_block(notifications, &sequence_overconsumption);
}
if(furi_hal_power_is_otg_enabled()) {
furi_hal_power_check_otg_status();
}
}
free(srv);
return 0;
}