flipperzero-firmware/applications/backlight-control/backlight-control.c
DrZlo13 8aeafd8179
furi_check - a new way to asserting (#204)
* hal-related task_is_isr_context function
* furi_check implementation
* change application to use furi_check
* add second level of assertion
* add TODO about ISR context
* Applications: refactor furi_check and furi_assert.
* Apploader: propwer widget usage. Menu: check on furi resource request.
* refactor furi_check

Co-authored-by: Aleksandr Kutuzov <aku@plooks.com>
Co-authored-by: coreglitch <mail@s3f.ru>
2020-10-29 09:27:17 +03:00

32 lines
986 B
C

#include "flipper_v2.h"
static void event_cb(const void* value, 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
PubSub* event_record = furi_open("input_events");
furi_check(event_record);
subscribe_pubsub(event_record, event_cb, (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);
}
}
}