charger3 2.0.0.0
charger3.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef CHARGER3_H
29#define CHARGER3_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
69#define CHARGER3_COMMAND_NOP 0x00
70#define CHARGER3_COMMAND_WRITE_RDAC 0x04
71#define CHARGER3_COMMAND_READ_RDAC 0x08
72#define CHARGER3_COMMAND_STORE_WIPER 0x0C
73#define CHARGER3_COMMAND_SW_RESET 0x10
74#define CHARGER3_COMMAND_READ_50TP 0x14
75#define CHARGER3_COMMAND_READ_MEMORY 0x18
76#define CHARGER3_COMMAND_WRITE_MEMORY 0x1C
77#define CHARGER3_COMMAND_READ_CONTROL 0x20
78#define CHARGER3_COMMAND_SW_SHUTDOWN 0x24
79
80 // charger3_command
81
97#define CHARGER3_CTRL_REG_BIT_MASK 0x0B
98#define CHARGER3_FUSE_PROGRAM_SUCCESSFUL 0x00
99#define CHARGER3_FUSE_PROGRAM_UNSUCCESSFUL 0x08
100#define CHARGER3_WIPER_POS_FROZEN 0x00
101#define CHARGER3_UPDATE_WIPER_POS 0x02
102#define CHARGER3_50T_PROGRAM_DISABLED 0x00
103#define CHARGER3_50T_PROGRAM_ENABLE 0x01
104
111#define CHARGER3_SET_DEV_ADDR 0x2F
112
113 // charger3_set
114
125#define CHARGER3_ENABLE_CHARGING 0x00
126#define CHARGER3_DISABLE_CHARGING 0x01
127
128 // mode
129
140#define CHARGER3_STATUS_ERROR_SUCCESS 0x00
141#define CHARGER3_STATUS_ERROR_FAILURE 0x01
142
143 // status
144
155#define CHARGER3_DUMMY 0x00
156
157 // charger3_dummy
158
173#define CHARGER3_MAP_MIKROBUS( cfg, mikrobus ) \
174 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
175 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
176
177 // charger3_map
178 // charger3
179
184typedef struct
185{
186 // Modules
187
188 i2c_master_t i2c;
190 // I2C slave address
191
194} charger3_t;
195
200typedef struct
201{
202 pin_name_t scl;
203 pin_name_t sda;
205 uint32_t i2c_speed;
206 uint8_t i2c_address;
209
228
246
263
281err_t charger3_generic_write ( charger3_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
282
300err_t charger3_generic_read ( charger3_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
301
314
329void charger3_operating_mode ( charger3_t *ctx, uint8_t mode );
330
342void charger3_write_rdac ( charger3_t *ctx, uint16_t rdac_data );
343
359uint8_t charger3_set_digipot_res ( charger3_t *ctx, uint16_t res_ohm );
360
374uint8_t charger3_set_current ( charger3_t *ctx, float curr_value );
375
388
403
404#ifdef __cplusplus
405}
406#endif
407#endif // CHARGER3_H
408
409 // charger3
410
411// ------------------------------------------------------------------------ END
uint16_t charger3_read_rdac(charger3_t *ctx)
Charger 3 read rdac function.
err_t charger3_init(charger3_t *ctx, charger3_cfg_t *cfg)
Charger 3 initialization function.
void charger3_operating_mode(charger3_t *ctx, uint8_t mode)
Charger 3 set operating mode function.
float charger3_calc_digipot_res(charger3_t *ctx)
Charger 3 calculate digipot resistance function.
void charger3_cfg_setup(charger3_cfg_t *cfg)
Charger 3 configuration object setup function.
err_t charger3_generic_write(charger3_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Charger 3 I2C writing function.
uint8_t charger3_set_digipot_res(charger3_t *ctx, uint16_t res_ohm)
Charger 3 set digital potentiometer resistance function.
void charger3_enable_write(charger3_t *ctx)
Charger 3 enable write function.
void charger3_write_rdac(charger3_t *ctx, uint16_t rdac_data)
Charger 3 write to rdac function.
uint8_t charger3_set_current(charger3_t *ctx, float curr_value)
Charger 3 set current function.
err_t charger3_generic_read(charger3_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Charger 3 I2C reading function.
void charger3_default_cfg(charger3_t *ctx)
Charger 3 default configuration function.
Charger 3 Click configuration object.
Definition charger3.h:201
uint32_t i2c_speed
Definition charger3.h:205
pin_name_t scl
Definition charger3.h:202
pin_name_t sda
Definition charger3.h:203
uint8_t i2c_address
Definition charger3.h:206
Charger 3 Click context object.
Definition charger3.h:185
i2c_master_t i2c
Definition charger3.h:188
uint8_t slave_address
Definition charger3.h:192