no-OS
lt8491.h
Go to the documentation of this file.
1 /***************************************************************************/
34 #ifndef __LT8491_H__
35 #define __LT8491_H__
36 
37 #include "no_os_i2c.h"
38 #include "no_os_util.h"
39 
40 #define LT8491_TELE_TBAT_REG 0x0
41 #define LT8491_TELE_POUT_REG 0x2
42 #define LT8491_TELE_PIN_REG 0x4
43 #define LT8491_TELE_EFF_REG 0x6
44 #define LT8491_TELE_IOUT_REG 0x8
45 #define LT8491_TELE_IIN_REG 0xA
46 #define LT8491_TELE_VBAT_REG 0xC
47 #define LT8491_TELE_VIN_REG 0xE
48 #define LT8491_TELE_VINR_REG 0x10
49 
50 #define LT8491_STAT_CHARGER_REG 0x12
51 #define LT8491_STAT_SUPPLY_REG 0x14
52 
53 #define LT8491_CTRL_CHRG_EN_REG 0x23
54 #define LT8491_CTRL_RESTART_CHIP_REG 0x24
55 #define LT8491_CTRL_UPDATE_TELEM 0x26
56 
57 #define LT8491_CFG_RSENSE1_REG 0x28
58 #define LT8491_CFG_RIMON_OUT_REG 0x2A
59 #define LT8491_CFG_RSENSE2_REG 0x2C
60 #define LT8491_CFG_RDACO_REG 0x2E
61 #define LT8491_CFG_RFBOUT1_REG 0x30
62 #define LT8491_CFG_RFBOUT2_REG 0x32
63 #define LT8491_CFG_RDACI_REG 0x34
64 #define LT8491_CFG_RFBIN2_REG 0x36
65 #define LT8491_CFG_RFBIN1_REG 0x38
66 #define LT8491_CFG_TBAT_MIN_REG 0x40
67 #define LT8491_CFG_TBAT_MAX_REG 0x41
68 #define LT8491_CFG_CHRG_MISC_REG 0x4D
69 
70 #define LT8491_CFG_USER_CODE 0x5A
71 #define LT8491_MFR_DATA1_REG 0x5C
72 #define LT8491_MFR_DATA2_REG 0x5E
73 #define LT8491_MFR_DATA3_REG 0x60
74 
75 #define LT8491_CHRG_STAGE_MASK NO_OS_GENMASK(5, 3)
76 #define LT8491_CHARGING_MASK NO_OS_BIT(2)
77 
78 #define LT8491_PS_OR_SOLAR_MASK NO_OS_BIT(3)
79 
89 };
90 
94 struct lt8491_desc {
97 };
98 
106  unsigned int rsense1_micro_ohms;
108  unsigned int rimon_out_ohms;
110  unsigned int rsense2_micro_ohms;
112  unsigned int rdaco_ohms;
114  unsigned int rfbout1_ohms;
116  unsigned int rfbout2_ohms;
118  unsigned int rdaci_ohms;
120  unsigned int rfbin2_ohms;
122  unsigned int rfbin1_ohms;
123 };
124 
126 int lt8491_reg_read(struct lt8491_desc *dev, uint8_t addr, uint16_t *val,
127  bool is_word);
128 
130 int lt8491_reg_write(struct lt8491_desc *dev, uint8_t addr, uint16_t val,
131  bool is_word);
132 
134 int lt8491_init(struct lt8491_desc **dev,
135  struct lt8491_init_param *init_param);
136 
138 int lt8491_remove(struct lt8491_desc *dev);
139 
142  struct lt8491_init_param *init_param);
143 
145 int lt8491_read_tbat(struct lt8491_desc *dev, int32_t *val);
146 
148 int lt8491_read_pout(struct lt8491_desc *dev, uint32_t *val);
149 
151 int lt8491_read_pin(struct lt8491_desc *dev, uint32_t *val);
152 
154 int lt8491_read_efficiency(struct lt8491_desc *dev, uint32_t *val);
155 
157 int lt8491_read_iout(struct lt8491_desc *dev, uint32_t *val);
158 
160 int lt8491_read_iin(struct lt8491_desc *dev, uint32_t *val);
161 
163 int lt8491_read_vbat(struct lt8491_desc *dev, uint32_t *val);
164 
166 int lt8491_read_vin(struct lt8491_desc *dev, uint32_t *val);
167 
169 int lt8491_read_charging_stage(struct lt8491_desc *dev, uint32_t *uval);
170 
172 int lt8491_read_charging_status(struct lt8491_desc *dev, uint32_t *charging);
173 
175 int lt8491_read_enable(struct lt8491_desc *dev, uint32_t *enable);
176 
178 int lt8491_write_enable(struct lt8491_desc *dev, uint32_t enable);
179 
181 int lt8491_restart_chip(struct lt8491_desc *dev);
182 
184 int lt8491_read_scratch(struct lt8491_desc *dev, uint32_t *val);
185 
187 int lt8491_write_scratch(struct lt8491_desc *dev, uint32_t val);
188 
190 int lt8491_read_serial_id(struct lt8491_desc *dev, uint32_t *val);
191 
192 #endif /* __LT8491_H__ */
lt8491_reg_read
int lt8491_reg_read(struct lt8491_desc *dev, uint8_t addr, uint16_t *val, bool is_word)
Read a register value.
Definition: lt8491.c:50
LT8491_CHARGING_MASK
#define LT8491_CHARGING_MASK
Definition: lt8491.h:76
no_os_alloc.h
LT8491_CHRG_STAGE_MASK
#define LT8491_CHRG_STAGE_MASK
Definition: lt8491.h:75
lt8491_read_iout
int lt8491_read_iout(struct lt8491_desc *dev, uint32_t *val)
Read the telemetry battery output current.
Definition: lt8491.c:320
no_os_i2c_write
int32_t no_os_i2c_write(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Write data to slave device.
Definition: no_os_i2c.c:159
LT8491_TELE_VINR_REG
#define LT8491_TELE_VINR_REG
Definition: lt8491.h:48
lt8491_read_charging_stage
int lt8491_read_charging_stage(struct lt8491_desc *dev, uint32_t *uval)
Read the telemetry battery charging stage.
Definition: lt8491.c:423
no_os_i2c_init
int32_t no_os_i2c_init(struct no_os_i2c_desc **desc, const struct no_os_i2c_init_param *param)
Initialize the I2C communication peripheral.
Definition: no_os_i2c.c:52
LT8491_TELE_VBAT_REG
#define LT8491_TELE_VBAT_REG
Definition: lt8491.h:46
lt8491_read_vin
int lt8491_read_vin(struct lt8491_desc *dev, uint32_t *val)
Read the telemetry input voltage.
Definition: lt8491.c:392
lt8491_charging_stage
lt8491_charging_stage
LT8491 charging stage.
Definition: lt8491.h:83
LT8491_TELE_IOUT_REG
#define LT8491_TELE_IOUT_REG
Definition: lt8491.h:44
lt8491_init_param::rfbin1_ohms
unsigned int rfbin1_ohms
Definition: lt8491.h:122
lt8491_read_scratch
int lt8491_read_scratch(struct lt8491_desc *dev, uint32_t *val)
Read the scratch register.
Definition: lt8491.c:510
lt8491_write_scratch
int lt8491_write_scratch(struct lt8491_desc *dev, uint32_t val)
Write the scratch register.
Definition: lt8491.c:530
no_os_i2c_remove
int32_t no_os_i2c_remove(struct no_os_i2c_desc *desc)
Free the resources allocated by no_os_i2c_init().
Definition: no_os_i2c.c:113
LT8491_STAT_SUPPLY_REG
#define LT8491_STAT_SUPPLY_REG
Definition: lt8491.h:51
lt8491_read_efficiency
int lt8491_read_efficiency(struct lt8491_desc *dev, uint32_t *val)
Read the telemetry battery efficiency.
Definition: lt8491.c:296
LT8491_CFG_USER_CODE
#define LT8491_CFG_USER_CODE
Definition: lt8491.h:70
lt8491_init_param::i2c_init_param
struct no_os_i2c_init_param i2c_init_param
Definition: lt8491.h:104
LT8491_CFG_RFBOUT2_REG
#define LT8491_CFG_RFBOUT2_REG
Definition: lt8491.h:62
LT8491_STAGE3
@ LT8491_STAGE3
Definition: lt8491.h:87
lt8491_desc::i2c_desc
struct no_os_i2c_desc * i2c_desc
Definition: lt8491.h:96
lt8491_init_param::rimon_out_ohms
unsigned int rimon_out_ohms
Definition: lt8491.h:108
LT8491_STAGE1
@ LT8491_STAGE1
Definition: lt8491.h:85
lt8491_init_param::rfbin2_ohms
unsigned int rfbin2_ohms
Definition: lt8491.h:120
LT8491_STAGE0
@ LT8491_STAGE0
Definition: lt8491.h:84
no_os_print_log.h
Print messages helpers.
lt8491_init_param::rdaci_ohms
unsigned int rdaci_ohms
Definition: lt8491.h:118
lt8491_read_iin
int lt8491_read_iin(struct lt8491_desc *dev, uint32_t *val)
Read the telemetry battery input current.
Definition: lt8491.c:344
lt8491_desc
LT8491 descriptor.
Definition: lt8491.h:94
LT8491_CFG_RIMON_OUT_REG
#define LT8491_CFG_RIMON_OUT_REG
Definition: lt8491.h:58
lt8491_init
int lt8491_init(struct lt8491_desc **dev, struct lt8491_init_param *init_param)
Device and comm init function.
Definition: lt8491.c:109
no_os_calloc
void * no_os_calloc(size_t nitems, size_t size)
Allocate memory and return a pointer to it, set memory to 0.
Definition: chibios_alloc.c:54
lt8491_remove
int lt8491_remove(struct lt8491_desc *dev)
Free resources allocated by the init function.
Definition: lt8491.c:138
lt8491_init_param::rsense1_micro_ohms
unsigned int rsense1_micro_ohms
Definition: lt8491.h:106
lt8491_reg_write
int lt8491_reg_write(struct lt8491_desc *dev, uint8_t addr, uint16_t val, bool is_word)
Write a register value.
Definition: lt8491.c:85
LT8491_TELE_PIN_REG
#define LT8491_TELE_PIN_REG
Definition: lt8491.h:42
LT8491_MFR_DATA2_REG
#define LT8491_MFR_DATA2_REG
Definition: lt8491.h:72
lt8491_init_param::rsense2_micro_ohms
unsigned int rsense2_micro_ohms
Definition: lt8491.h:110
lt8491_configure_telemetry
int lt8491_configure_telemetry(struct lt8491_desc *dev, struct lt8491_init_param *init_param)
Device and comm init function.
Definition: lt8491.c:160
LT8491_CFG_RDACI_REG
#define LT8491_CFG_RDACI_REG
Definition: lt8491.h:63
lt8491_write_scratch
int lt8491_write_scratch(struct lt8491_desc *dev, uint32_t val)
Write the scratch register.
Definition: lt8491.c:530
no_os_error.h
Error codes definition.
LT8491_CTRL_CHRG_EN_REG
#define LT8491_CTRL_CHRG_EN_REG
Definition: lt8491.h:53
LT8491_CFG_RDACO_REG
#define LT8491_CFG_RDACO_REG
Definition: lt8491.h:60
LT8491_STAT_CHARGER_REG
#define LT8491_STAT_CHARGER_REG
Definition: lt8491.h:50
LT8491_CFG_RFBIN2_REG
#define LT8491_CFG_RFBIN2_REG
Definition: lt8491.h:64
LT8491_CTRL_UPDATE_TELEM
#define LT8491_CTRL_UPDATE_TELEM
Definition: lt8491.h:55
lt8491_reg_read
int lt8491_reg_read(struct lt8491_desc *dev, uint8_t addr, uint16_t *val, bool is_word)
Read a register value.
Definition: lt8491.c:50
LT8491_TELE_EFF_REG
#define LT8491_TELE_EFF_REG
Definition: lt8491.h:43
lt8491_restart_chip
int lt8491_restart_chip(struct lt8491_desc *dev)
Restart the chip.
Definition: lt8491.c:493
lt8491_read_pout
int lt8491_read_pout(struct lt8491_desc *dev, uint32_t *val)
Read the telemetry battery output power.
Definition: lt8491.c:248
LT8491_CTRL_RESTART_CHIP_REG
#define LT8491_CTRL_RESTART_CHIP_REG
Definition: lt8491.h:54
LT8491_TELE_VIN_REG
#define LT8491_TELE_VIN_REG
Definition: lt8491.h:47
lt8491_read_charging_stage
int lt8491_read_charging_stage(struct lt8491_desc *dev, uint32_t *uval)
Read the telemetry battery charging stage.
Definition: lt8491.c:423
lt8491_read_serial_id
int lt8491_read_serial_id(struct lt8491_desc *dev, uint32_t *val)
Read the serial ID.
Definition: lt8491.c:543
lt8491_read_iin
int lt8491_read_iin(struct lt8491_desc *dev, uint32_t *val)
Read the telemetry battery input current.
Definition: lt8491.c:344
LT8491_CFG_RFBIN1_REG
#define LT8491_CFG_RFBIN1_REG
Definition: lt8491.h:65
lt8491_init
int lt8491_init(struct lt8491_desc **dev, struct lt8491_init_param *init_param)
Device and comm init function.
Definition: lt8491.c:109
lt8491_read_tbat
int lt8491_read_tbat(struct lt8491_desc *dev, int32_t *val)
Read the telemetry battery temperature.
Definition: lt8491.c:224
LT8491_TELE_POUT_REG
#define LT8491_TELE_POUT_REG
Definition: lt8491.h:41
lt8491_reg_write
int lt8491_reg_write(struct lt8491_desc *dev, uint8_t addr, uint16_t val, bool is_word)
Write a register value.
Definition: lt8491.c:85
lt8491_read_scratch
int lt8491_read_scratch(struct lt8491_desc *dev, uint32_t *val)
Read the scratch register.
Definition: lt8491.c:510
lt8491_read_charging_status
int lt8491_read_charging_status(struct lt8491_desc *dev, uint32_t *charging)
Read the telemetry battery charging status.
Definition: lt8491.c:443
LT8491_TELE_IIN_REG
#define LT8491_TELE_IIN_REG
Definition: lt8491.h:45
LT8491_MFR_DATA3_REG
#define LT8491_MFR_DATA3_REG
Definition: lt8491.h:73
lt8491_read_vbat
int lt8491_read_vbat(struct lt8491_desc *dev, uint32_t *val)
Read the telemetry battery voltage.
Definition: lt8491.c:368
LT8491_TELE_TBAT_REG
#define LT8491_TELE_TBAT_REG
Definition: lt8491.h:40
lt8491_read_enable
int lt8491_read_enable(struct lt8491_desc *dev, uint32_t *enable)
Read the telemetry battery charging enable.
Definition: lt8491.c:463
lt8491_read_iout
int lt8491_read_iout(struct lt8491_desc *dev, uint32_t *val)
Read the telemetry battery output current.
Definition: lt8491.c:320
no_os_i2c_desc
Structure holding I2C address descriptor.
Definition: no_os_i2c.h:101
no_os_i2c_read
int32_t no_os_i2c_read(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Read data from slave device.
Definition: no_os_i2c.c:190
no_os_i2c.h
Header file of I2C Interface.
lt8491_read_pin
int lt8491_read_pin(struct lt8491_desc *dev, uint32_t *val)
Read the telemetry battery input power.
Definition: lt8491.c:272
lt8491_restart_chip
int lt8491_restart_chip(struct lt8491_desc *dev)
Restart the chip.
Definition: lt8491.c:493
no_os_field_get
uint32_t no_os_field_get(uint32_t mask, uint32_t word)
lt8491_read_vin
int lt8491_read_vin(struct lt8491_desc *dev, uint32_t *val)
Read the telemetry input voltage.
Definition: lt8491.c:392
lt8491_remove
int lt8491_remove(struct lt8491_desc *dev)
Free resources allocated by the init function.
Definition: lt8491.c:138
no_os_free
void no_os_free(void *ptr)
Deallocate memory previously allocated by a call to no_os_calloc or no_os_malloc.
Definition: chibios_alloc.c:69
no_os_get_unaligned_le16
uint16_t no_os_get_unaligned_le16(uint8_t *buf)
LT8491_CFG_RFBOUT1_REG
#define LT8491_CFG_RFBOUT1_REG
Definition: lt8491.h:61
lt8491.h
Implementation of LT8491 Driver.
lt8491_read_tbat
int lt8491_read_tbat(struct lt8491_desc *dev, int32_t *val)
Read the telemetry battery temperature.
Definition: lt8491.c:224
lt8491_configure_telemetry
int lt8491_configure_telemetry(struct lt8491_desc *dev, struct lt8491_init_param *init_param)
Device and comm init function.
Definition: lt8491.c:160
no_os_i2c_init_param
Structure holding the parameters for I2C initialization.
Definition: no_os_i2c.h:64
lt8491_read_efficiency
int lt8491_read_efficiency(struct lt8491_desc *dev, uint32_t *val)
Read the telemetry battery efficiency.
Definition: lt8491.c:296
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:113
lt8491_write_enable
int lt8491_write_enable(struct lt8491_desc *dev, uint32_t enable)
Write the telemetry battery charging enable.
Definition: lt8491.c:483
lt8491_init_param::rdaco_ohms
unsigned int rdaco_ohms
Definition: lt8491.h:112
LT8491_CFG_RSENSE1_REG
#define LT8491_CFG_RSENSE1_REG
Definition: lt8491.h:57
LT8491_CFG_RSENSE2_REG
#define LT8491_CFG_RSENSE2_REG
Definition: lt8491.h:59
lt8491_read_vbat
int lt8491_read_vbat(struct lt8491_desc *dev, uint32_t *val)
Read the telemetry battery voltage.
Definition: lt8491.c:368
lt8491_init_param::rfbout2_ohms
unsigned int rfbout2_ohms
Definition: lt8491.h:116
lt8491_read_enable
int lt8491_read_enable(struct lt8491_desc *dev, uint32_t *enable)
Read the telemetry battery charging enable.
Definition: lt8491.c:463
LT8491_MFR_DATA1_REG
#define LT8491_MFR_DATA1_REG
Definition: lt8491.h:71
lt8491_read_pout
int lt8491_read_pout(struct lt8491_desc *dev, uint32_t *val)
Read the telemetry battery output power.
Definition: lt8491.c:248
no_os_util.h
Header file of utility functions.
LT8491_STAGE2
@ LT8491_STAGE2
Definition: lt8491.h:86
lt8491_read_serial_id
int lt8491_read_serial_id(struct lt8491_desc *dev, uint32_t *val)
Read the serial ID.
Definition: lt8491.c:543
lt8491_read_pin
int lt8491_read_pin(struct lt8491_desc *dev, uint32_t *val)
Read the telemetry battery input power.
Definition: lt8491.c:272
no_os_sign_extend32
int32_t no_os_sign_extend32(uint32_t value, int index)
lt8491_init_param::rfbout1_ohms
unsigned int rfbout1_ohms
Definition: lt8491.h:114
lt8491_init_param
LT8491 init param.
Definition: lt8491.h:102
LT8491_DONE_CHARGING
@ LT8491_DONE_CHARGING
Definition: lt8491.h:88
LT8491_PS_OR_SOLAR_MASK
#define LT8491_PS_OR_SOLAR_MASK
Definition: lt8491.h:78
lt8491_read_charging_status
int lt8491_read_charging_status(struct lt8491_desc *dev, uint32_t *charging)
Read the telemetry battery charging status.
Definition: lt8491.c:443
lt8491_write_enable
int lt8491_write_enable(struct lt8491_desc *dev, uint32_t enable)
Write the telemetry battery charging enable.
Definition: lt8491.c:483