1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-12 04:34:43 +04:00

Merge pull request #877 from Dmitry422/dev

Сombining rgb_backlight (by @quen0n) and original_backlight in one firmware
This commit is contained in:
MMX
2025-03-15 07:59:51 +03:00
committed by GitHub
17 changed files with 1002 additions and 12 deletions

102
lib/drivers/SK6805.c Normal file
View File

@@ -0,0 +1,102 @@
/*
SK6805 FlipperZero driver
Copyright (C) 2022-2023 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 <https://www.gnu.org/licenses/>.
*/
#include "SK6805.h"
#include <furi_hal.h>
/* Настройки */
#define SK6805_LED_COUNT 3 //Количество светодиодов на плате подсветки
#define SK6805_LED_PIN &led_pin //Порт подключения светодиодов
#ifdef FURI_DEBUG
#define DEBUG_PIN &gpio_ext_pa7
#define DEBUG_INIT() \
furi_hal_gpio_init(DEBUG_PIN, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh)
#define DEBUG_SET_HIGH() furi_hal_gpio_write(DEBUG_PIN, true)
#define DEBUG_SET_LOW() furi_hal_gpio_write(DEBUG_PIN, false)
#else
#define DEBUG_INIT()
#define DEBUG_SET_HIGH()
#define DEBUG_SET_LOW()
#endif
static const GpioPin led_pin = {.port = GPIOA, .pin = LL_GPIO_PIN_8};
static uint8_t led_buffer[SK6805_LED_COUNT][3];
void SK6805_init(void) {
DEBUG_INIT();
furi_hal_gpio_write(SK6805_LED_PIN, false);
furi_hal_gpio_init(SK6805_LED_PIN, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh);
}
uint8_t SK6805_get_led_count(void) {
return (const uint8_t)SK6805_LED_COUNT;
}
void SK6805_set_led_color(uint8_t led_index, uint8_t r, uint8_t g, uint8_t b) {
furi_check(led_index < SK6805_LED_COUNT);
led_buffer[led_index][0] = g;
led_buffer[led_index][1] = r;
led_buffer[led_index][2] = b;
}
void SK6805_update(void) {
SK6805_init();
FURI_CRITICAL_ENTER();
furi_delay_us(100);
uint32_t end;
/* Последовательная отправка цветов светодиодов */
for(uint8_t lednumber = 0; lednumber < SK6805_LED_COUNT; lednumber++) {
//Последовательная отправка цветов светодиода
for(uint8_t color = 0; color < 3; color++) {
//Последовательная отправка битов цвета
uint8_t i = 0b10000000;
while(i != 0) {
if(led_buffer[lednumber][color] & (i)) {
furi_hal_gpio_write(SK6805_LED_PIN, true);
DEBUG_SET_HIGH();
end = DWT->CYCCNT + 30;
//T1H 600 us (615 us)
while(DWT->CYCCNT < end) {
}
furi_hal_gpio_write(SK6805_LED_PIN, false);
DEBUG_SET_LOW();
end = DWT->CYCCNT + 26;
//T1L 600 us (587 us)
while(DWT->CYCCNT < end) {
}
} else {
furi_hal_gpio_write(SK6805_LED_PIN, true);
DEBUG_SET_HIGH();
end = DWT->CYCCNT + 11;
//T0H 300 ns (312 ns)
while(DWT->CYCCNT < end) {
}
furi_hal_gpio_write(SK6805_LED_PIN, false);
DEBUG_SET_LOW();
end = DWT->CYCCNT + 43;
//T0L 900 ns (890 ns)
while(DWT->CYCCNT < end) {
}
}
i >>= 1;
}
}
}
FURI_CRITICAL_EXIT();
}

58
lib/drivers/SK6805.h Normal file
View File

@@ -0,0 +1,58 @@
/*
SK6805 FlipperZero driver
Copyright (C) 2022-2023 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 <https://www.gnu.org/licenses/>.
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifndef SK6805_H_
#define SK6805_H_
#include <furi.h>
/**
* @brief Инициализация линии управления подсветкой
*/
void SK6805_init(void);
/**
* @brief Получить количество светодиодов в подсветке
*
* @return Количество светодиодов
*/
uint8_t SK6805_get_led_count(void);
/**
* @brief Установить цвет свечения светодиода
*
* @param led_index номер светодиода (от 0 до SK6805_get_led_count())
* @param r значение красного (0-255)
* @param g значение зелёного (0-255)
* @param b значение синего (0-255)
*/
void SK6805_set_led_color(uint8_t led_index, uint8_t r, uint8_t g, uint8_t b);
/**
* @brief Обновление состояния подсветки дисплея
*/
void SK6805_update(void);
#endif /* SK6805_H_ */
#ifdef __cplusplus
}
#endif