charger 2.1.0.0
charger.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 CHARGER_H
29#define CHARGER_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_one_wire.h"
52
73#define CHARGER_CMD_WRITE_SCRATCHPAD 0x4E
74#define CHARGER_CMD_READ_SCRATCHPAD 0xBE
75#define CHARGER_CMD_COPY_SCRATCHPAD 0x48
76#define CHARGER_CMD_RECALL_MEMORY 0xB8
77#define CHARGER_CMD_CONVERT_T 0x44
78#define CHARGER_CMD_CONVERT_V 0xB4
79
80 // charger_cmd
81
96#define CHARGER_PAGE_0 0
97#define CHARGER_PAGE_1 1
98#define CHARGER_PAGE_2 2
99#define CHARGER_PAGE_3 3
100#define CHARGER_PAGE_4 4
101#define CHARGER_PAGE_5 5
102#define CHARGER_PAGE_6 6
103#define CHARGER_PAGE_7 7
104#define CHARGER_PAGE_SIZE 8
105
110#define CHARGER_CONFIG_IAD 0x01
111#define CHARGER_CONFIG_CA 0x02
112#define CHARGER_CONFIG_EE 0x04
113#define CHARGER_CONFIG_AD 0x08
114#define CHARGER_CONFIG_TB 0x10
115#define CHARGER_CONFIG_NVM 0x20
116#define CHARGER_CONFIG_ADB 0x40
117
122#define CHARGER_TEMPERATURE_RES 0.03125f
123#define CHARGER_VOLTAGE_RES 0.01f
124#define CHARGER_CURRENT_RES 204.8f
125
130#define CHARGER_FAMILY_CODE 0x26
131
136#define CHARGER_ADDRESS_0 0x00
137#define CHARGER_ADDRESS_ALL 0xFF
138
139 // charger_set
140
155#define CHARGER_MAP_MIKROBUS( cfg, mikrobus ) \
156 cfg.ow1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
157 cfg.ow2 = MIKROBUS( mikrobus, MIKROBUS_AN );
158
159 // charger_map
160 // charger
161
172
177typedef struct
178{
179 // Modules
180 one_wire_t ow;
182 one_wire_rom_address_t rom_addr;
183 uint8_t address;
185} charger_t;
186
191typedef struct
192{
193 // Communication gpio pins
194 pin_name_t ow1;
195 pin_name_t ow2;
200
205typedef enum
206{
208 CHARGER_ERROR = -1
209
211
228
244
259
273
286
299
313err_t charger_read_scratchpad ( charger_t *ctx, uint8_t page, uint8_t *data_out, uint8_t len );
314
328err_t charger_write_scratchpad ( charger_t *ctx, uint8_t page, uint8_t *data_in, uint8_t len );
329
341err_t charger_copy_scratchpad ( charger_t *ctx, uint8_t page );
342
354err_t charger_recall_memory ( charger_t *ctx, uint8_t page );
355
367
379
391err_t charger_read_temperature ( charger_t *ctx, float *temperature );
392
404err_t charger_read_batt_vdd ( charger_t *ctx, float *voltage );
405
417err_t charger_read_system_vdd ( charger_t *ctx, float *voltage );
418
430err_t charger_read_current ( charger_t *ctx, float *current );
431
443
455err_t charger_write_elapsed_time ( charger_t *ctx, uint32_t seconds );
456
468err_t charger_read_elapsed_time ( charger_t *ctx, uint32_t *seconds );
469
470#ifdef __cplusplus
471}
472#endif
473#endif // CHARGER_H
474
475 // charger
476
477// ------------------------------------------------------------------------ END
charger_gpio_sel_t
Charger Click gpio selector.
Definition charger.h:167
@ CHARGER_GPIO_OW2
Definition charger.h:169
@ CHARGER_GPIO_OW1
Definition charger.h:168
charger_return_value_t
Charger Click return value data.
Definition charger.h:206
@ CHARGER_ERROR
Definition charger.h:208
@ CHARGER_OK
Definition charger.h:207
err_t charger_convert_voltage(charger_t *ctx)
Charger convert voltage function.
err_t charger_default_cfg(charger_t *ctx)
Charger default configuration function.
err_t charger_init(charger_t *ctx, charger_cfg_t *cfg)
Charger initialization function.
err_t charger_read_current(charger_t *ctx, float *current)
Charger read current function.
err_t charger_read_scratchpad(charger_t *ctx, uint8_t page, uint8_t *data_out, uint8_t len)
Charger read scratchpad function.
void charger_cfg_setup(charger_cfg_t *cfg)
Charger configuration object setup function.
err_t charger_read_batt_vdd(charger_t *ctx, float *voltage)
Charger read battery VDD function.
err_t charger_read_system_vdd(charger_t *ctx, float *voltage)
Charger read system VDD function.
void charger_gpio_selection(charger_cfg_t *cfg, charger_gpio_sel_t gpio_sel)
Charger driver interface setup function.
err_t charger_read_temperature(charger_t *ctx, float *temperature)
Charger read temperature function.
err_t charger_copy_scratchpad(charger_t *ctx, uint8_t page)
Charger copy scratchpad function.
err_t charger_calibrate_current(charger_t *ctx)
Charger calibrate current function.
err_t charger_recall_memory(charger_t *ctx, uint8_t page)
Charger recall scratchpad function.
err_t charger_read_elapsed_time(charger_t *ctx, uint32_t *seconds)
Charger read elapsed time function.
err_t charger_convert_temperature(charger_t *ctx)
Charger convert temperature function.
err_t charger_check_communication(charger_t *ctx)
Charger check communication function.
err_t charger_write_elapsed_time(charger_t *ctx, uint32_t seconds)
Charger write elapsed time function.
err_t charger_select_device(charger_t *ctx)
Charger select device function.
err_t charger_write_scratchpad(charger_t *ctx, uint8_t page, uint8_t *data_in, uint8_t len)
Charger write scratchpad function.
Charger Click configuration object.
Definition charger.h:192
pin_name_t ow2
Definition charger.h:195
charger_gpio_sel_t gpio_sel
Definition charger.h:197
pin_name_t ow1
Definition charger.h:194
Charger Click context object.
Definition charger.h:178
one_wire_rom_address_t rom_addr
Definition charger.h:182
uint8_t address
Definition charger.h:183
one_wire_t ow
Definition charger.h:180