backlight-control.c 986 B

1234567891011121314151617181920212223242526272829303132
  1. #include "flipper_v2.h"
  2. static void event_cb(const void* value, void* ctx) {
  3. xSemaphoreGive((SemaphoreHandle_t*)ctx);
  4. }
  5. const uint32_t BACKLIGHT_TIME = 10000;
  6. void backlight_control(void* p) {
  7. // TODO use FURI
  8. HAL_GPIO_WritePin(DISPLAY_BACKLIGHT_GPIO_Port, DISPLAY_BACKLIGHT_Pin, GPIO_PIN_SET);
  9. StaticSemaphore_t event_descriptor;
  10. SemaphoreHandle_t update = xSemaphoreCreateCountingStatic(255, 0, &event_descriptor);
  11. // open record
  12. PubSub* event_record = furi_open("input_events");
  13. furi_check(event_record);
  14. subscribe_pubsub(event_record, event_cb, (void*)update);
  15. // we ready to work
  16. furiac_ready();
  17. while(1) {
  18. // wait for event
  19. if(xSemaphoreTake(update, BACKLIGHT_TIME) == pdTRUE) {
  20. HAL_GPIO_WritePin(DISPLAY_BACKLIGHT_GPIO_Port, DISPLAY_BACKLIGHT_Pin, GPIO_PIN_SET);
  21. } else {
  22. HAL_GPIO_WritePin(DISPLAY_BACKLIGHT_GPIO_Port, DISPLAY_BACKLIGHT_Pin, GPIO_PIN_RESET);
  23. }
  24. }
  25. }