cleanup is31fl3729 driver; LED updates only when needed now
This commit is contained in:
parent
5adce05f84
commit
5d722f41e8
|
@ -16,20 +16,17 @@
|
|||
|
||||
void is31fl3729_init(uint8_t i2c_addr, uint8_t config, uint8_t global_current)
|
||||
{
|
||||
uint8_t buf;
|
||||
|
||||
// enable device
|
||||
#ifdef FL3729_SDB_PORT
|
||||
FL3729_SDB_PORT->BSHR = FL3729_SDB_PIN;
|
||||
#endif
|
||||
|
||||
// reset config registers
|
||||
buf = FL3729_RESET_VALUE;
|
||||
i2c_write_addr1b(i2c_addr, FL3729_REG_RESET, &buf, 1);
|
||||
i2c_write_reg_8b(i2c_addr, FL3729_REG_CONFIG, FL3729_RESET_VALUE);
|
||||
|
||||
// write initial config
|
||||
i2c_write_addr1b(i2c_addr, FL3729_REG_CONFIG, &config, 1);
|
||||
i2c_write_addr1b(i2c_addr, FL3729_REG_G_CURRENT, &global_current, 1);
|
||||
i2c_write_reg_8b(i2c_addr, FL3729_REG_CONFIG, config);
|
||||
i2c_write_reg_8b(i2c_addr, FL3729_REG_G_CURRENT, global_current);
|
||||
}
|
||||
|
||||
uint8_t is31fl3729_get_addr(uint8_t adpin)
|
||||
|
@ -40,21 +37,21 @@ uint8_t is31fl3729_get_addr(uint8_t adpin)
|
|||
|
||||
void is31fl3729_set_global_current(uint8_t i2c_addr, uint8_t current)
|
||||
{
|
||||
i2c_write_addr1b(i2c_addr, FL3729_REG_G_CURRENT, ¤t, 1);
|
||||
i2c_write_reg_8b(i2c_addr, FL3729_REG_G_CURRENT, current);
|
||||
}
|
||||
|
||||
void is31fl3729_set_scaling_current(uint8_t i2c_addr, uint8_t cs, uint8_t current)
|
||||
{
|
||||
if (cs > 0xf) return;
|
||||
|
||||
i2c_write_addr1b(i2c_addr, FL3729_REG_SCALING + cs, ¤t, 1);
|
||||
i2c_write_reg_8b(i2c_addr, FL3729_REG_SCALING + cs, current);
|
||||
}
|
||||
|
||||
/*
|
||||
* sets current limit of multiple outputs simultaneously, starting from CS1.
|
||||
* useful for initial register configuration.
|
||||
*/
|
||||
void is31fl3729_set_scaling_current_multi(uint8_t i2c_addr, uint8_t *current, uint8_t count)
|
||||
void is31fl3729_set_scaling_current_multi(uint8_t i2c_addr, const uint8_t *current, uint8_t count)
|
||||
{
|
||||
if (!count) return;
|
||||
count &= 0xf;
|
||||
|
@ -67,9 +64,9 @@ void is31fl3729_set_scaling_current_multi(uint8_t i2c_addr, uint8_t *current, ui
|
|||
* sw: first switch segment to update. usually set this to 1 for the first switch.
|
||||
* if set to 0, will default to 1.
|
||||
* *out: output data buffer
|
||||
* len: length of buffer
|
||||
* len: length of buffer. up to end user to not exceed writing beyond register 0x90.
|
||||
*/
|
||||
void is31fl3729_set_outputs(uint8_t i2c_addr, uint8_t sw, uint8_t *out, uint8_t len)
|
||||
void is31fl3729_set_outputs(uint8_t i2c_addr, uint8_t sw, const uint8_t *out, uint8_t len)
|
||||
{
|
||||
if (!sw) sw = 1;
|
||||
|
||||
|
|
|
@ -25,24 +25,24 @@
|
|||
#define FL3729_REG_OUTPUT 0x01
|
||||
#define FL3729_REG_SCALING 0x90
|
||||
#define FL3729_REG_CONFIG 0xA0
|
||||
#define FL3729_REG_G_CURRENT 0xA1 // global current
|
||||
#define FL3729_REG_PUPD 0xB0 // pull up / pull down
|
||||
#define FL3729_REG_SS 0xB1 // spread spectrum
|
||||
#define FL3729_REG_G_CURRENT 0xA1 // global current
|
||||
#define FL3729_REG_PUPD 0xB0 // pull up / pull down
|
||||
#define FL3729_REG_SS 0xB1 // spread spectrum
|
||||
#define FL3729_REG_PWM 0xB2
|
||||
#define FL3729_REG_RESET 0xCF
|
||||
|
||||
|
||||
#define FL3729_GCC_MAX 64 // maximum global current level
|
||||
#define FL3729_GCC_MAX 64 // maximum global current level
|
||||
|
||||
#define FL3729_CONF_SHDN_ENA 0
|
||||
#define FL3729_CONF_SHDN_DIS ((1 << 0) << 0)
|
||||
#define FL3729_CONF_SSD_SHDN (0 << 0) // software shutdown
|
||||
#define FL3729_CONF_SSD_NRML (1 << 0) // normal operation
|
||||
|
||||
#define FL3729_CONF_OSDE_OFF 0
|
||||
#define FL3729_CONF_OSDE_OPEN ((1 << 0) << 1)
|
||||
#define FL3729_CONF_OSDE_SHORT ((1 << 1) << 1)
|
||||
#define FL3729_CONF_OSDE_OFF (0 << 1)
|
||||
#define FL3729_CONF_OSDE_OPEN (1 << 1)
|
||||
#define FL3729_CONF_OSDE_SHORT (2 << 1)
|
||||
|
||||
#define FL3729_CONF_LOGIC_LOLEV 0
|
||||
#define FL3729_CONF_LOGIC_HILEV ((1 << 0) << 3)
|
||||
#define FL3729_CONF_LOGIC_LOLEV (0 << 3)
|
||||
#define FL3729_CONF_LOGIC_HILEV (1 << 3)
|
||||
|
||||
#define FL3729_CONF_MATRIX_9x15 0x00
|
||||
#define FL3729_CONF_MATRIX_8x16 0x10
|
||||
|
@ -68,25 +68,15 @@
|
|||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
typedef struct IS31FL3729_Conf {
|
||||
uint8_t ad_pin;
|
||||
uint8_t config;
|
||||
uint8_t global_brightness;
|
||||
} IS31FL3729_Conf;
|
||||
*/
|
||||
|
||||
|
||||
void is31fl3729_init(uint8_t i2c_addr, uint8_t config, uint8_t global_current);
|
||||
|
||||
uint8_t is31fl3729_get_addr(uint8_t adpin);
|
||||
|
||||
void is31fl3729_set_global_current(uint8_t i2c_addr, uint8_t current);
|
||||
void is31fl3729_set_scaling_current(uint8_t i2c_addr, uint8_t cs, uint8_t current);
|
||||
void is31fl3729_set_scaling_current_multi(uint8_t i2c_addr, uint8_t *current, uint8_t count);
|
||||
void is31fl3729_set_scaling_current_multi(uint8_t i2c_addr, const uint8_t *current, uint8_t count);
|
||||
|
||||
void is31fl3729_set_outputs(uint8_t i2c_addr, uint8_t sw, uint8_t *out, uint8_t len);
|
||||
void is31fl3729_set_outputs(uint8_t i2c_addr, uint8_t sw, const uint8_t *out, uint8_t len);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ uint8_t i2c_read_reg_8b(uint8_t addr, uint8_t reg)
|
|||
return dat;
|
||||
}
|
||||
|
||||
int8_t i2c_write_addr1b(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len)
|
||||
int8_t i2c_write_addr1b(uint8_t addr, uint8_t reg, const uint8_t *data, uint8_t len)
|
||||
{
|
||||
timeout = I2C_TIMEOUT;
|
||||
while((I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY) != RESET) && timeout--);
|
||||
|
@ -136,7 +136,7 @@ int8_t i2c_write_addr1b(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void i2c_write_reg_8b(uint8_t addr, uint8_t reg, uint8_t dat)
|
||||
void i2c_write_reg_8b(uint8_t addr, uint8_t reg, const uint8_t dat)
|
||||
{
|
||||
i2c_write_addr1b(addr, reg, &dat, 1);
|
||||
}
|
||||
|
|
|
@ -14,10 +14,10 @@
|
|||
void i2c_init();
|
||||
|
||||
int8_t i2c_read_addr1b(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len);
|
||||
int8_t i2c_write_addr1b(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len);
|
||||
int8_t i2c_write_addr1b(uint8_t addr, uint8_t reg, const uint8_t *data, uint8_t len);
|
||||
|
||||
uint8_t i2c_read_reg_8b(uint8_t addr, uint8_t reg);
|
||||
void i2c_write_reg_8b(uint8_t addr, uint8_t reg, uint8_t dat);
|
||||
void i2c_write_reg_8b(uint8_t addr, uint8_t reg, const uint8_t dat);
|
||||
|
||||
int8_t i2c_ack_poll(uint8_t devaddr);
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ void led_init()
|
|||
uint8_t buf[FL3729_CS_OUTPUTS] = {0xff};
|
||||
|
||||
is31fl3729_init(FL3729_ADDR,
|
||||
FL3729_CONF_SHDN_DIS | FL3729_CONF_OSDE_OFF | FL3729_CONF_MATRIX_2x16,
|
||||
FL3729_CONF_SSD_NRML | FL3729_CONF_OSDE_OFF | FL3729_CONF_MATRIX_2x16,
|
||||
LED_INIT_CURRENT);
|
||||
|
||||
for (i = 0; i < FL3729_CS_OUTPUTS; i++) buf[i] = LED_INIT_SCALING;
|
||||
|
@ -83,6 +83,8 @@ void led_send()
|
|||
out[cursor_map[2]] = cursor[2];
|
||||
|
||||
is31fl3729_set_outputs(FL3729_ADDR, 1, out, 16+15);
|
||||
|
||||
led_updated = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue