2021-02-18 12:49:32 +00:00
|
|
|
#include "lp5562.h"
|
|
|
|
#include "lp5562_reg.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2021-11-28 18:28:19 +00:00
|
|
|
static bool lp5562_write_reg(FuriHalI2cBusHandle* handle, uint8_t address, uint8_t* data) {
|
2021-03-10 13:23:54 +00:00
|
|
|
uint8_t buffer[2] = {address, *data};
|
2021-11-28 18:28:19 +00:00
|
|
|
return furi_hal_i2c_tx(handle, LP5562_ADDRESS, buffer, 2, LP5562_I2C_TIMEOUT);
|
2021-02-18 12:49:32 +00:00
|
|
|
}
|
|
|
|
|
2021-11-28 18:28:19 +00:00
|
|
|
void lp5562_reset(FuriHalI2cBusHandle* handle) {
|
2021-03-10 13:23:54 +00:00
|
|
|
Reg0D_Reset reg = {.value = 0xFF};
|
2021-11-28 18:28:19 +00:00
|
|
|
lp5562_write_reg(handle, 0x0D, (uint8_t*)®);
|
2021-02-18 12:49:32 +00:00
|
|
|
}
|
|
|
|
|
2021-11-28 18:28:19 +00:00
|
|
|
void lp5562_configure(FuriHalI2cBusHandle* handle) {
|
2021-03-10 13:23:54 +00:00
|
|
|
Reg08_Config config = {.INT_CLK_EN = true, .PS_EN = true, .PWM_HF = true};
|
2021-11-28 18:28:19 +00:00
|
|
|
lp5562_write_reg(handle, 0x08, (uint8_t*)&config);
|
2021-03-10 13:23:54 +00:00
|
|
|
|
2021-02-18 12:49:32 +00:00
|
|
|
Reg70_LedMap map = {
|
|
|
|
.red = EngSelectI2C,
|
|
|
|
.green = EngSelectI2C,
|
|
|
|
.blue = EngSelectI2C,
|
|
|
|
.white = EngSelectI2C,
|
|
|
|
};
|
2021-11-28 18:28:19 +00:00
|
|
|
lp5562_write_reg(handle, 0x70, (uint8_t*)&map);
|
2021-02-18 12:49:32 +00:00
|
|
|
}
|
|
|
|
|
2021-11-28 18:28:19 +00:00
|
|
|
void lp5562_enable(FuriHalI2cBusHandle* handle) {
|
2021-03-10 13:23:54 +00:00
|
|
|
Reg00_Enable reg = {.CHIP_EN = true, .LOG_EN = true};
|
2021-11-28 18:28:19 +00:00
|
|
|
lp5562_write_reg(handle, 0x00, (uint8_t*)®);
|
2021-02-18 12:49:32 +00:00
|
|
|
}
|
|
|
|
|
2021-11-28 18:28:19 +00:00
|
|
|
void lp5562_set_channel_current(FuriHalI2cBusHandle* handle, LP5562Channel channel, uint8_t value) {
|
2021-02-18 12:49:32 +00:00
|
|
|
uint8_t reg_no;
|
2021-03-10 13:23:54 +00:00
|
|
|
if(channel == LP5562ChannelRed) {
|
2021-02-18 12:49:32 +00:00
|
|
|
reg_no = 0x07;
|
2021-03-10 13:23:54 +00:00
|
|
|
} else if(channel == LP5562ChannelGreen) {
|
2021-02-18 12:49:32 +00:00
|
|
|
reg_no = 0x06;
|
2021-03-10 13:23:54 +00:00
|
|
|
} else if(channel == LP5562ChannelBlue) {
|
2021-02-18 12:49:32 +00:00
|
|
|
reg_no = 0x05;
|
2021-03-10 13:23:54 +00:00
|
|
|
} else if(channel == LP5562ChannelWhite) {
|
2021-02-18 12:49:32 +00:00
|
|
|
reg_no = 0x0F;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2021-11-28 18:28:19 +00:00
|
|
|
lp5562_write_reg(handle, reg_no, &value);
|
2021-02-18 12:49:32 +00:00
|
|
|
}
|
|
|
|
|
2021-11-28 18:28:19 +00:00
|
|
|
void lp5562_set_channel_value(FuriHalI2cBusHandle* handle, LP5562Channel channel, uint8_t value) {
|
2021-02-18 12:49:32 +00:00
|
|
|
uint8_t reg_no;
|
2021-03-10 13:23:54 +00:00
|
|
|
if(channel == LP5562ChannelRed) {
|
2021-02-18 12:49:32 +00:00
|
|
|
reg_no = 0x04;
|
2021-03-10 13:23:54 +00:00
|
|
|
} else if(channel == LP5562ChannelGreen) {
|
2021-02-18 12:49:32 +00:00
|
|
|
reg_no = 0x03;
|
2021-03-10 13:23:54 +00:00
|
|
|
} else if(channel == LP5562ChannelBlue) {
|
2021-02-18 12:49:32 +00:00
|
|
|
reg_no = 0x02;
|
2021-03-10 13:23:54 +00:00
|
|
|
} else if(channel == LP5562ChannelWhite) {
|
2021-02-18 12:49:32 +00:00
|
|
|
reg_no = 0x0E;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2021-11-28 18:28:19 +00:00
|
|
|
lp5562_write_reg(handle, reg_no, &value);
|
2021-02-18 12:49:32 +00:00
|
|
|
}
|