i2c, IS31FL3729 cleanup
This commit is contained in:
parent
8fb1368e0a
commit
5177b02ab0
|
@ -44,7 +44,7 @@ void gpio_init()
|
||||||
|
|
||||||
gpio.GPIO_Speed = GPIO_Speed_2MHz;
|
gpio.GPIO_Speed = GPIO_Speed_2MHz;
|
||||||
|
|
||||||
// Soft I2C, USART TX/RX; currently unused
|
// GAT SoftI2C, USART TX/RX; currently unused
|
||||||
gpio.GPIO_Mode = GPIO_Mode_IPD;
|
gpio.GPIO_Mode = GPIO_Mode_IPD;
|
||||||
gpio.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6;
|
gpio.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6;
|
||||||
GPIO_Init(GPIOD, &gpio);
|
GPIO_Init(GPIOD, &gpio);
|
||||||
|
@ -65,10 +65,13 @@ void gpio_init()
|
||||||
gpio.GPIO_Pin = GPIO_Pin_2;
|
gpio.GPIO_Pin = GPIO_Pin_2;
|
||||||
GPIO_Init(GPIOD, &gpio);
|
GPIO_Init(GPIOD, &gpio);
|
||||||
|
|
||||||
// I2C will be handled by the driver
|
// I2C SCL, SCA for on-board devices
|
||||||
|
gpio.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2;
|
||||||
|
gpio.GPIO_Mode = GPIO_Mode_AF_OD;
|
||||||
|
GPIO_Init(GPIOC, &gpio);
|
||||||
|
|
||||||
// IS_SDB IS31FL3729 shutdown pin (active low)
|
// IS_SDB (PC3) IS31FL3729 shutdown pin (active low)
|
||||||
// WP for EEPROM
|
// WP (PC6) for EEPROM
|
||||||
GPIOC->BCR = GPIO_Pin_3;
|
GPIOC->BCR = GPIO_Pin_3;
|
||||||
GPIOC->BSHR = GPIO_Pin_6;
|
GPIOC->BSHR = GPIO_Pin_6;
|
||||||
gpio.GPIO_Mode = GPIO_Mode_Out_PP;
|
gpio.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||||
|
|
|
@ -9,11 +9,23 @@
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
|
|
||||||
|
|
||||||
/* sends the IS31FL3729 general config.
|
|
||||||
|
void is31fl3729_set_global_current(uint8_t i2c_addr, uint8_t global_current)
|
||||||
|
{
|
||||||
|
i2c_write_reg_8b(i2c_addr, FL3729_REG_G_CURRENT, global_current);
|
||||||
|
}
|
||||||
|
|
||||||
|
void is31fl3729_set_scaling_current(uint8_t i2c_addr, uint8_t cs, uint8_t current)
|
||||||
|
{
|
||||||
|
if (cs > 0xf) return;
|
||||||
|
|
||||||
|
i2c_write_reg_8b(i2c_addr, FL3729_REG_SCALING + cs, current);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* sends the IS31FL3729 initial config.
|
||||||
* does not configure per-channel current sink limits; do that separately.
|
* does not configure per-channel current sink limits; do that separately.
|
||||||
* does not configure other sane defaults; do that separately.
|
* does not configure other sane defaults; do that separately.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void is31fl3729_init(uint8_t i2c_addr, uint8_t config, uint8_t global_current)
|
void is31fl3729_init(uint8_t i2c_addr, uint8_t config, uint8_t global_current)
|
||||||
{
|
{
|
||||||
// enable device
|
// enable device
|
||||||
|
@ -26,7 +38,7 @@ void is31fl3729_init(uint8_t i2c_addr, uint8_t config, uint8_t global_current)
|
||||||
|
|
||||||
// write initial config
|
// write initial config
|
||||||
i2c_write_reg_8b(i2c_addr, FL3729_REG_CONFIG, config);
|
i2c_write_reg_8b(i2c_addr, FL3729_REG_CONFIG, config);
|
||||||
i2c_write_reg_8b(i2c_addr, FL3729_REG_G_CURRENT, global_current);
|
is31fl3729_set_global_current(i2c_addr, global_current);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t is31fl3729_get_addr(uint8_t adpin)
|
uint8_t is31fl3729_get_addr(uint8_t adpin)
|
||||||
|
@ -35,18 +47,6 @@ uint8_t is31fl3729_get_addr(uint8_t adpin)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void is31fl3729_set_global_current(uint8_t i2c_addr, uint8_t current)
|
|
||||||
{
|
|
||||||
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_reg_8b(i2c_addr, FL3729_REG_SCALING + cs, current);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* sets current limit of multiple outputs simultaneously, starting from CS1.
|
* sets current limit of multiple outputs simultaneously, starting from CS1.
|
||||||
* useful for initial register configuration.
|
* useful for initial register configuration.
|
||||||
|
|
|
@ -72,7 +72,7 @@ void is31fl3729_init(uint8_t i2c_addr, uint8_t config, uint8_t global_current);
|
||||||
|
|
||||||
uint8_t is31fl3729_get_addr(uint8_t adpin);
|
uint8_t is31fl3729_get_addr(uint8_t adpin);
|
||||||
|
|
||||||
void is31fl3729_set_global_current(uint8_t i2c_addr, uint8_t current);
|
void is31fl3729_set_global_current(uint8_t i2c_addr, uint8_t global_current);
|
||||||
void is31fl3729_set_scaling_current(uint8_t i2c_addr, uint8_t cs, 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, const uint8_t *current, uint8_t count);
|
void is31fl3729_set_scaling_current_multi(uint8_t i2c_addr, const uint8_t *current, uint8_t count);
|
||||||
|
|
||||||
|
|
|
@ -23,13 +23,9 @@ static uint32_t timeout;
|
||||||
|
|
||||||
void i2c_init()
|
void i2c_init()
|
||||||
{
|
{
|
||||||
GPIO_InitTypeDef gpio = {0};
|
|
||||||
I2C_InitTypeDef i2c = {0};
|
I2C_InitTypeDef i2c = {0};
|
||||||
|
|
||||||
gpio.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2;
|
// ensure GPIO pins are configured before initializing
|
||||||
gpio.GPIO_Mode = GPIO_Mode_AF_OD;
|
|
||||||
gpio.GPIO_Speed = GPIO_Speed_2MHz;
|
|
||||||
GPIO_Init(GPIOC, &gpio);
|
|
||||||
|
|
||||||
i2c.I2C_ClockSpeed = 666666;
|
i2c.I2C_ClockSpeed = 666666;
|
||||||
i2c.I2C_Mode = I2C_Mode_I2C;
|
i2c.I2C_Mode = I2C_Mode_I2C;
|
||||||
|
|
Loading…
Reference in New Issue