From 98cd9f81ab1d8d6a30a1857b6da9646f408c77ab Mon Sep 17 00:00:00 2001
From: Willy-JL <49810075+Willy-JL@users.noreply.github.com>
Date: Fri, 24 Mar 2023 17:55:52 +0000
Subject: [PATCH] Remove unused rgb backlight code
---
applications/system/updater/application.fam | 1 +
lib/drivers/WS2812B.c | 217 --------------------
lib/drivers/WS2812B.h | 54 -----
3 files changed, 1 insertion(+), 271 deletions(-)
delete mode 100644 lib/drivers/WS2812B.c
delete mode 100644 lib/drivers/WS2812B.h
diff --git a/applications/system/updater/application.fam b/applications/system/updater/application.fam
index a693fa6f5..ae6914eb7 100644
--- a/applications/system/updater/application.fam
+++ b/applications/system/updater/application.fam
@@ -6,6 +6,7 @@ App(
requires=[
"gui",
"storage",
+ "rgb_backlight",
],
conflicts=["desktop"],
entry_point="updater_srv",
diff --git a/lib/drivers/WS2812B.c b/lib/drivers/WS2812B.c
deleted file mode 100644
index fcdbfe4cd..000000000
--- a/lib/drivers/WS2812B.c
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- WS2812B FlipperZero driver
- Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n)
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
-*/
-
-#include "WS2812B.h"
-#include
-#include
-#include "furi_hal_light.h"
-#include
-#include
-#include
-#include
-
-#define TAG "RGB Backlight"
-#define RGB_BACKLIGHT_SETTINGS_VERSION 5
-#define RGB_BACKLIGHT_SETTINGS_FILE_NAME ".rgb_backlight.settings"
-#define RGB_BACKLIGHT_SETTINGS_PATH EXT_PATH(RGB_BACKLIGHT_SETTINGS_FILE_NAME)
-
-static uint8_t WS2812B_ledbuffer[WS2812B_LEDS][3];
-
-static RGBBacklightSettings rgb_settings = {
- .version = RGB_BACKLIGHT_SETTINGS_VERSION,
- .display_color_index = 0,
- .settings_is_loaded = false};
-
-#define COLOR_COUNT (sizeof(colors) / sizeof(WS2812B_Color))
-
-const WS2812B_Color colors[] = {
- {"Orange", 255, 165, 0},
- {"Red", 255, 0, 0},
- {"Maroon", 128, 0, 0},
- {"Yellow", 255, 255, 0},
- {"Olive", 128, 128, 0},
- {"Lime", 0, 255, 0},
- {"Green", 0, 128, 0},
- {"Aqua", 0, 255, 127},
- {"Cyan", 0, 210, 210},
- {"Azure", 0, 127, 255},
- {"Teal", 0, 128, 128},
- {"Blue", 0, 0, 255},
- {"Navy", 0, 0, 128},
- {"Purple", 128, 0, 128},
- {"Fuchsia", 255, 0, 255},
- {"Pink", 255, 192, 203},
- {"Brown", 165, 42, 42},
- {"White", 255, 255, 255},
-};
-
-static void _port_init(void) {
- furi_hal_gpio_write(LED_PIN, true);
- furi_hal_gpio_init(LED_PIN, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh);
-}
-
-void WS2812B_send(void) {
- _port_init();
- furi_kernel_lock();
- /* Последовательная отправка цветов светодиодов */
- for(uint8_t lednumber = 0; lednumber < WS2812B_LEDS; lednumber++) {
- //Последовательная отправка цветов светодиода
- for(uint8_t color = 0; color < 3; color++) {
- //Последовательная отправка битов цвета
- for(uint8_t i = 7; i != 255; i--) {
- if(WS2812B_ledbuffer[lednumber][color] & (1 << i)) {
- furi_hal_gpio_write(LED_PIN, true);
- uint32_t start = DWT->CYCCNT;
- while((DWT->CYCCNT - start) < 31) {
- }
- furi_hal_gpio_write(LED_PIN, false);
- start = DWT->CYCCNT;
- while((DWT->CYCCNT - start) < 15) {
- }
- } else {
- furi_hal_gpio_write(LED_PIN, true);
- uint32_t start = DWT->CYCCNT;
- while((DWT->CYCCNT - start) < 15) {
- }
- furi_hal_gpio_write(LED_PIN, false);
- start = DWT->CYCCNT;
- while((DWT->CYCCNT - start) < 31) {
- }
- }
- }
- }
- }
- furi_kernel_unlock();
- //Необходимая задержка - признак окончания передачи
- furi_delay_us(100);
-}
-
-uint8_t rgb_backlight_get_color_count(void) {
- return COLOR_COUNT;
-}
-
-const char* rgb_backlight_get_color_text(uint8_t index) {
- return colors[index].name;
-}
-
-static void rgb_backlight_load_settings(void) {
- _port_init();
-
- FuriHalRtcBootMode bm = furi_hal_rtc_get_boot_mode();
- if(bm == FuriHalRtcBootModeDfu) {
- rgb_settings.settings_is_loaded = true;
- return;
- }
-
- RGBBacklightSettings settings;
- File* file = storage_file_alloc(furi_record_open(RECORD_STORAGE));
- const size_t settings_size = sizeof(RGBBacklightSettings);
-
- FURI_LOG_I(TAG, "loading settings from \"%s\"", RGB_BACKLIGHT_SETTINGS_PATH);
- bool fs_result =
- storage_file_open(file, RGB_BACKLIGHT_SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
-
- if(fs_result) {
- uint16_t bytes_count = storage_file_read(file, &settings, settings_size);
-
- if(bytes_count != settings_size) {
- fs_result = false;
- }
- }
-
- if(fs_result) {
- FURI_LOG_I(TAG, "load success");
- if(settings.version != RGB_BACKLIGHT_SETTINGS_VERSION) {
- FURI_LOG_E(
- TAG,
- "version(%d != %d) mismatch",
- settings.version,
- RGB_BACKLIGHT_SETTINGS_VERSION);
- } else {
- memcpy(&rgb_settings, &settings, settings_size);
- }
- } else {
- FURI_LOG_E(TAG, "load failed, %s", storage_file_get_error_desc(file));
- }
-
- storage_file_close(file);
- storage_file_free(file);
- furi_record_close(RECORD_STORAGE);
- rgb_settings.settings_is_loaded = true;
-};
-
-void rgb_backlight_save_settings(void) {
- RGBBacklightSettings settings;
- File* file = storage_file_alloc(furi_record_open(RECORD_STORAGE));
- const size_t settings_size = sizeof(RGBBacklightSettings);
-
- FURI_LOG_I(TAG, "saving settings to \"%s\"", RGB_BACKLIGHT_SETTINGS_PATH);
-
- memcpy(&settings, &rgb_settings, settings_size);
-
- bool fs_result =
- storage_file_open(file, RGB_BACKLIGHT_SETTINGS_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS);
-
- if(fs_result) {
- uint16_t bytes_count = storage_file_write(file, &settings, settings_size);
-
- if(bytes_count != settings_size) {
- fs_result = false;
- }
- }
-
- if(fs_result) {
- FURI_LOG_I(TAG, "save success");
- } else {
- FURI_LOG_E(TAG, "save failed, %s", storage_file_get_error_desc(file));
- }
-
- storage_file_close(file);
- storage_file_free(file);
- furi_record_close(RECORD_STORAGE);
-};
-
-RGBBacklightSettings* rgb_backlight_get_settings(void) {
- if(!rgb_settings.settings_is_loaded) {
- rgb_backlight_load_settings();
- }
- return &rgb_settings;
-}
-
-void rgb_backlight_set_color(uint8_t color_index) {
- rgb_settings.display_color_index = color_index;
-}
-
-void rgb_backlight_update(uint8_t backlight) {
- if(!rgb_settings.settings_is_loaded) {
- rgb_backlight_load_settings();
- }
- for(uint8_t i = 0; i < WS2812B_LEDS; i++) {
- //Green
- WS2812B_ledbuffer[i][0] =
- colors[rgb_settings.display_color_index].green * (backlight / 255.0f);
- //Red
- WS2812B_ledbuffer[i][1] =
- colors[rgb_settings.display_color_index].red * (backlight / 255.0f);
- //Blue
- WS2812B_ledbuffer[i][2] =
- colors[rgb_settings.display_color_index].blue * (backlight / 255.0f);
- }
-
- WS2812B_send();
-}
diff --git a/lib/drivers/WS2812B.h b/lib/drivers/WS2812B.h
deleted file mode 100644
index 4f0dfabce..000000000
--- a/lib/drivers/WS2812B.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- WS2812B FlipperZero driver
- Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n)
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
-*/
-
-#ifndef WS2812B_H_
-#define WS2812B_H_
-
-#include "furi.h"
-#include
-#include
-#include
-
-typedef struct {
- uint8_t version;
- uint8_t display_color_index;
- bool settings_is_loaded;
-} RGBBacklightSettings;
-
-typedef struct {
- char* name;
- uint8_t red;
- uint8_t green;
- uint8_t blue;
-} WS2812B_Color;
-
-#define LED_PIN &gpio_ext_pa7
-#define WS2812B_LEDS 3
-
-void rgb_backlight_save_settings(void);
-
-void rgb_backlight_update(uint8_t backlight);
-
-void rgb_backlight_set_color(uint8_t color_index);
-void rgb_backlight_set_color(uint8_t color_index);
-
-RGBBacklightSettings* rgb_backlight_get_settings(void);
-uint8_t rgb_backlight_get_color_count(void);
-const char* rgb_backlight_get_color_text(uint8_t index);
-
-#endif /* WS2812B_H_ */
\ No newline at end of file