2022-07-20 10:56:33 +00:00
|
|
|
#include <core/common_defines.h>
|
2022-06-09 07:33:46 +00:00
|
|
|
#include "furi_hal_resources.h"
|
2022-01-05 16:10:18 +00:00
|
|
|
#include <furi_hal_light.h>
|
2021-05-18 09:23:14 +00:00
|
|
|
#include <lp5562.h>
|
2022-06-09 07:33:46 +00:00
|
|
|
#include <stdint.h>
|
2021-05-18 09:23:14 +00:00
|
|
|
|
|
|
|
#define LED_CURRENT_RED 50
|
|
|
|
#define LED_CURRENT_GREEN 50
|
|
|
|
#define LED_CURRENT_BLUE 50
|
|
|
|
#define LED_CURRENT_WHITE 150
|
|
|
|
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_light_init() {
|
2021-11-28 18:28:19 +00:00
|
|
|
furi_hal_i2c_acquire(&furi_hal_i2c_handle_power);
|
2021-05-18 09:23:14 +00:00
|
|
|
|
2021-11-28 18:28:19 +00:00
|
|
|
lp5562_reset(&furi_hal_i2c_handle_power);
|
2021-05-18 09:23:14 +00:00
|
|
|
|
2021-11-28 18:28:19 +00:00
|
|
|
lp5562_set_channel_current(&furi_hal_i2c_handle_power, LP5562ChannelRed, LED_CURRENT_RED);
|
|
|
|
lp5562_set_channel_current(&furi_hal_i2c_handle_power, LP5562ChannelGreen, LED_CURRENT_GREEN);
|
|
|
|
lp5562_set_channel_current(&furi_hal_i2c_handle_power, LP5562ChannelBlue, LED_CURRENT_BLUE);
|
|
|
|
lp5562_set_channel_current(&furi_hal_i2c_handle_power, LP5562ChannelWhite, LED_CURRENT_WHITE);
|
2021-05-18 09:23:14 +00:00
|
|
|
|
2021-11-28 18:28:19 +00:00
|
|
|
lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelRed, 0x00);
|
|
|
|
lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelGreen, 0x00);
|
|
|
|
lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelBlue, 0x00);
|
|
|
|
lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelWhite, 0x00);
|
|
|
|
|
|
|
|
lp5562_enable(&furi_hal_i2c_handle_power);
|
|
|
|
lp5562_configure(&furi_hal_i2c_handle_power);
|
|
|
|
|
|
|
|
furi_hal_i2c_release(&furi_hal_i2c_handle_power);
|
2021-05-18 09:23:14 +00:00
|
|
|
}
|
|
|
|
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_light_set(Light light, uint8_t value) {
|
2021-11-28 18:28:19 +00:00
|
|
|
furi_hal_i2c_acquire(&furi_hal_i2c_handle_power);
|
2022-06-09 07:33:46 +00:00
|
|
|
if(light & LightRed) {
|
2021-11-28 18:28:19 +00:00
|
|
|
lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelRed, value);
|
2022-06-09 07:33:46 +00:00
|
|
|
}
|
|
|
|
if(light & LightGreen) {
|
2021-11-28 18:28:19 +00:00
|
|
|
lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelGreen, value);
|
2022-06-09 07:33:46 +00:00
|
|
|
}
|
|
|
|
if(light & LightBlue) {
|
2021-11-28 18:28:19 +00:00
|
|
|
lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelBlue, value);
|
2022-06-09 07:33:46 +00:00
|
|
|
}
|
|
|
|
if(light & LightBacklight) {
|
|
|
|
uint8_t prev = lp5562_get_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelWhite);
|
2022-01-21 16:55:44 +00:00
|
|
|
lp5562_execute_ramp(
|
|
|
|
&furi_hal_i2c_handle_power, LP5562Engine1, LP5562ChannelWhite, prev, value, 100);
|
2021-05-18 09:23:14 +00:00
|
|
|
}
|
2021-11-28 18:28:19 +00:00
|
|
|
furi_hal_i2c_release(&furi_hal_i2c_handle_power);
|
2022-06-09 07:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void furi_hal_light_blink_start(Light light, uint8_t brightness, uint16_t on_time, uint16_t period) {
|
|
|
|
furi_hal_i2c_acquire(&furi_hal_i2c_handle_power);
|
|
|
|
lp5562_set_channel_src(
|
|
|
|
&furi_hal_i2c_handle_power,
|
|
|
|
LP5562ChannelRed | LP5562ChannelGreen | LP5562ChannelBlue,
|
|
|
|
LP5562Direct);
|
|
|
|
LP5562Channel led_ch = 0;
|
|
|
|
if(light & LightRed) led_ch |= LP5562ChannelRed;
|
|
|
|
if(light & LightGreen) led_ch |= LP5562ChannelGreen;
|
|
|
|
if(light & LightBlue) led_ch |= LP5562ChannelBlue;
|
|
|
|
lp5562_execute_blink(
|
|
|
|
&furi_hal_i2c_handle_power, LP5562Engine2, led_ch, on_time, period, brightness);
|
|
|
|
furi_hal_i2c_release(&furi_hal_i2c_handle_power);
|
|
|
|
}
|
|
|
|
|
|
|
|
void furi_hal_light_blink_stop() {
|
|
|
|
furi_hal_i2c_acquire(&furi_hal_i2c_handle_power);
|
|
|
|
lp5562_set_channel_src(
|
|
|
|
&furi_hal_i2c_handle_power,
|
|
|
|
LP5562ChannelRed | LP5562ChannelGreen | LP5562ChannelBlue,
|
|
|
|
LP5562Direct);
|
|
|
|
lp5562_stop_program(&furi_hal_i2c_handle_power, LP5562Engine2);
|
|
|
|
furi_hal_i2c_release(&furi_hal_i2c_handle_power);
|
|
|
|
}
|
|
|
|
|
|
|
|
void furi_hal_light_blink_set_color(Light light) {
|
|
|
|
furi_hal_i2c_acquire(&furi_hal_i2c_handle_power);
|
|
|
|
LP5562Channel led_ch = 0;
|
|
|
|
lp5562_set_channel_src(
|
|
|
|
&furi_hal_i2c_handle_power,
|
|
|
|
LP5562ChannelRed | LP5562ChannelGreen | LP5562ChannelBlue,
|
|
|
|
LP5562Direct);
|
|
|
|
if(light & LightRed) led_ch |= LP5562ChannelRed;
|
|
|
|
if(light & LightGreen) led_ch |= LP5562ChannelGreen;
|
|
|
|
if(light & LightBlue) led_ch |= LP5562ChannelBlue;
|
|
|
|
lp5562_set_channel_src(&furi_hal_i2c_handle_power, led_ch, LP5562Engine2);
|
|
|
|
furi_hal_i2c_release(&furi_hal_i2c_handle_power);
|
2022-01-21 16:55:44 +00:00
|
|
|
}
|
2022-04-13 20:50:25 +00:00
|
|
|
|
|
|
|
void furi_hal_light_sequence(const char* sequence) {
|
|
|
|
do {
|
|
|
|
if(*sequence == 'R') {
|
|
|
|
furi_hal_light_set(LightRed, 0xFF);
|
|
|
|
} else if(*sequence == 'r') {
|
|
|
|
furi_hal_light_set(LightRed, 0x00);
|
|
|
|
} else if(*sequence == 'G') {
|
|
|
|
furi_hal_light_set(LightGreen, 0xFF);
|
|
|
|
} else if(*sequence == 'g') {
|
|
|
|
furi_hal_light_set(LightGreen, 0x00);
|
|
|
|
} else if(*sequence == 'B') {
|
|
|
|
furi_hal_light_set(LightBlue, 0xFF);
|
|
|
|
} else if(*sequence == 'b') {
|
|
|
|
furi_hal_light_set(LightBlue, 0x00);
|
|
|
|
} else if(*sequence == 'W') {
|
|
|
|
furi_hal_light_set(LightBacklight, 0xFF);
|
|
|
|
} else if(*sequence == 'w') {
|
|
|
|
furi_hal_light_set(LightBacklight, 0x00);
|
|
|
|
} else if(*sequence == '.') {
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_delay_ms(250);
|
2022-04-13 20:50:25 +00:00
|
|
|
} else if(*sequence == '-') {
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_delay_ms(500);
|
2022-04-13 20:50:25 +00:00
|
|
|
}
|
|
|
|
sequence++;
|
|
|
|
} while(*sequence != 0);
|
|
|
|
}
|