From 1e40f873a5e4ccc7362718acbe63c981e5b40c5c Mon Sep 17 00:00:00 2001 From: aanper Date: Thu, 15 Oct 2020 19:15:53 +0300 Subject: [PATCH] backlight control --- applications/applications.mk | 1 + .../backlight-control/backlight-control.c | 30 +++++++++++++++++++ applications/startup.h | 2 ++ 3 files changed, 33 insertions(+) create mode 100644 applications/backlight-control/backlight-control.c diff --git a/applications/applications.mk b/applications/applications.mk index d60ed2d5..e8f61573 100644 --- a/applications/applications.mk +++ b/applications/applications.mk @@ -81,6 +81,7 @@ APP_GUI ?= 0 ifeq ($(APP_GUI), 1) CFLAGS += -DAPP_GUI C_SOURCES += $(wildcard $(APP_DIR)/gui/*.c) +C_SOURCES += $(wildcard $(APP_DIR)/backlight-control/*.c) endif ifeq ($(APP_DISPLAY), 1) diff --git a/applications/backlight-control/backlight-control.c b/applications/backlight-control/backlight-control.c new file mode 100644 index 00000000..ef22f3df --- /dev/null +++ b/applications/backlight-control/backlight-control.c @@ -0,0 +1,30 @@ +#include "flipper.h" + +static void event_cb(const void* value, size_t size, void* ctx) { + xSemaphoreGive((SemaphoreHandle_t*)ctx); +} + +const uint32_t BACKLIGHT_TIME = 10000; + +void backlight_control(void* p) { + // TODO use FURI + HAL_GPIO_WritePin(DISPLAY_BACKLIGHT_GPIO_Port, DISPLAY_BACKLIGHT_Pin, GPIO_PIN_SET); + + StaticSemaphore_t event_descriptor; + SemaphoreHandle_t update = xSemaphoreCreateCountingStatic(255, 0, &event_descriptor); + + // open record + furi_open_deprecated("input_events", false, false, event_cb, NULL, (void*)update); + + // we ready to work + furiac_ready(); + + while(1) { + // wait for event + if(xSemaphoreTake(update, BACKLIGHT_TIME) == pdTRUE) { + HAL_GPIO_WritePin(DISPLAY_BACKLIGHT_GPIO_Port, DISPLAY_BACKLIGHT_Pin, GPIO_PIN_SET); + } else { + HAL_GPIO_WritePin(DISPLAY_BACKLIGHT_GPIO_Port, DISPLAY_BACKLIGHT_Pin, GPIO_PIN_RESET); + } + } +} \ No newline at end of file diff --git a/applications/startup.h b/applications/startup.h index 58c8c11d..847009dc 100644 --- a/applications/startup.h +++ b/applications/startup.h @@ -26,6 +26,7 @@ void coreglitch_demo_0(void* p); void u8g2_qrcode(void* p); void fatfs_list(void* p); void gui_task(void* p); +void backlight_control(void* p); const FlipperStartupApp FLIPPER_STARTUP[] = { #ifdef APP_DISPLAY @@ -37,6 +38,7 @@ const FlipperStartupApp FLIPPER_STARTUP[] = { #endif #ifdef APP_GUI + {.app = backlight_control, .name = "backlight_control", .libs = {1, FURI_LIB{"input_task"}}}, {.app = gui_task, .name = "gui_task", .libs = {0}}, #endif