2022-01-05 19:10:18 +03:00
|
|
|
#include <furi_hal_light.h>
|
2021-09-10 05:19:02 +03:00
|
|
|
#include <lp5562.h>
|
|
|
|
|
|
|
|
#define LED_CURRENT_RED 50
|
|
|
|
#define LED_CURRENT_GREEN 50
|
|
|
|
#define LED_CURRENT_BLUE 50
|
|
|
|
#define LED_CURRENT_WHITE 150
|
|
|
|
|
|
|
|
void furi_hal_light_init() {
|
2021-11-28 21:28:19 +03:00
|
|
|
furi_hal_i2c_acquire(&furi_hal_i2c_handle_power);
|
2021-09-10 05:19:02 +03:00
|
|
|
|
2021-11-28 21:28:19 +03:00
|
|
|
lp5562_reset(&furi_hal_i2c_handle_power);
|
2021-09-10 05:19:02 +03:00
|
|
|
|
2021-11-28 21:28:19 +03: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-09-10 05:19:02 +03:00
|
|
|
|
2021-11-28 21:28:19 +03: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-09-10 05:19:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void furi_hal_light_set(Light light, uint8_t value) {
|
2022-01-21 19:55:44 +03:00
|
|
|
uint8_t prev = 0;
|
2021-11-28 21:28:19 +03:00
|
|
|
furi_hal_i2c_acquire(&furi_hal_i2c_handle_power);
|
2021-09-10 05:19:02 +03:00
|
|
|
switch(light) {
|
|
|
|
case LightRed:
|
2021-11-28 21:28:19 +03:00
|
|
|
lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelRed, value);
|
2021-09-10 05:19:02 +03:00
|
|
|
break;
|
|
|
|
case LightGreen:
|
2021-11-28 21:28:19 +03:00
|
|
|
lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelGreen, value);
|
2021-09-10 05:19:02 +03:00
|
|
|
break;
|
|
|
|
case LightBlue:
|
2021-11-28 21:28:19 +03:00
|
|
|
lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelBlue, value);
|
2021-09-10 05:19:02 +03:00
|
|
|
break;
|
|
|
|
case LightBacklight:
|
2022-01-21 19:55:44 +03:00
|
|
|
prev = lp5562_get_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelWhite);
|
|
|
|
lp5562_execute_ramp(
|
|
|
|
&furi_hal_i2c_handle_power, LP5562Engine1, LP5562ChannelWhite, prev, value, 100);
|
2021-09-10 05:19:02 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2021-11-28 21:28:19 +03:00
|
|
|
furi_hal_i2c_release(&furi_hal_i2c_handle_power);
|
2022-01-21 19:55:44 +03:00
|
|
|
}
|