charger5 2.0.0.0
charger5.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef _CHARGER5_H_
36#define _CHARGER5_H_
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_spi_master.h"
53
54// -------------------------------------------------------------- PUBLIC MACROS
64#define CHARGER5_RETVAL uint8_t
65
66#define CHARGER5_OK 0x00
67#define CHARGER5_INIT_ERROR 0xFF
74#define CHARGER5_REG_WIPER0_VOL 0x00
75#define CHARGER5_REG_WIPER1_VOL 0x01
76#define CHARGER5_REG_WIPER0_NONVOL 0x02
77#define CHARGER5_REG_WIPER1_NONVOL 0x03
78#define CHARGER5_REG_TCONTROL_VOL 0x04
79#define CHARGER5_REG_STATUS_VOL 0x05
80#define CHARGER5_REG_DATA_EEPROM0 0x06
81#define CHARGER5_REG_DATA_EEPROM1 0x07
82#define CHARGER5_REG_DATA_EEPROM2 0x08
83#define CHARGER5_REG_DATA_EEPROM3 0x09
84#define CHARGER5_REG_DATA_EEPROM4 0x0A
85#define CHARGER5_REG_DATA_EEPROM5 0x0B
86#define CHARGER5_REG_DATA_EEPROM6 0x0C
87#define CHARGER5_REG_DATA_EEPROM7 0x0D
88#define CHARGER5_REG_DATA_EEPROM8 0x0E
89#define CHARGER5_REG_DATA_EEPROM9 0x0F
96#define CHARGER5_CURRENT_100MA_MIN 0x00
97#define CHARGER5_CURRENT_200MA 0x88
98#define CHARGER5_CURRENT_300MA 0xBD
99#define CHARGER5_CURRENT_400MA 0xD6
100#define CHARGER5_CURRENT_500MA 0xE4
101#define CHARGER5_CURRENT_600MA 0xEE
102#define CHARGER5_CURRENT_700MA 0xF5
103#define CHARGER5_CURRENT_800MA 0xFB
104#define CHARGER5_CURRENT_900MA 0xFE
105#define CHARGER5_CURRENT_950MA_MAX 0x0100
112#define CHARGER5_STEPS_1_MIN 0x01
113#define CHARGER5_STEPS_2 0x02
114#define CHARGER5_STEPS_5 0x05
115#define CHARGER5_STEPS_10 0x0A
116#define CHARGER5_STEPS_50 0x32
117#define CHARGER5_STEPS_100 0x64
118#define CHARGER5_STEPS_150 0x96
119#define CHARGER5_STEPS_200 0xC8
120#define CHARGER5_STEPS_255_MAX 0xFF
127#define CHARGER5_MAP_MIKROBUS( cfg, mikrobus ) \
128 cfg.sdo = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
129 cfg.sdi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
130 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
131 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
134 // End macros group
135// --------------------------------------------------------------- PUBLIC TYPES
152
156typedef struct
157{
158 digital_out_t cs;
159
160 // Module.
161 spi_master_t spi;
162 pin_name_t chip_select;
163
164} charger5_t;
165
169typedef struct
170{
171 // Communication gpio pins.
172 pin_name_t sdo;
173 pin_name_t sdi;
174 pin_name_t sck;
175 pin_name_t cs;
176
177 // SPI module config variables.
178 uint32_t spi_speed;
179 spi_master_mode_t spi_mode;
180 spi_master_chip_select_polarity_t cs_polarity;
181
183
184 // End types group
185// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
191#ifdef __cplusplus
192extern "C"{
193#endif
194
204void
206
221
232void
234
248charger5_generic_write( charger5_t *ctx, uint8_t reg_addr,
249 uint16_t transfer_data );
250
261uint16_t
262charger5_generic_read( charger5_t *ctx, uint8_t reg_addr );
263
279charger5_increment_wiper( charger5_t *ctx, uint8_t reg_addr, uint8_t n_steps );
280
296charger5_decrement_wiper( charger5_t *ctx, uint8_t reg_addr, uint8_t n_steps );
297
298#ifdef __cplusplus
299}
300#endif
301#endif // _CHARGER5_H_
302
303 // End public_function group
305
306// ------------------------------------------------------------------------ END
void charger5_cfg_setup(charger5_cfg_t *cfg)
Configuration Object Setup function.
charger5_err_t charger5_init(charger5_t *ctx, charger5_cfg_t *cfg)
Click Initialization function.
void charger5_default_cfg(charger5_t *ctx)
Click Default Configuration function.
charger5_err_t charger5_decrement_wiper(charger5_t *ctx, uint8_t reg_addr, uint8_t n_steps)
Decrement Wiper function.
charger5_err_t charger5_increment_wiper(charger5_t *ctx, uint8_t reg_addr, uint8_t n_steps)
Increment Wiper function.
charger5_err_t charger5_generic_write(charger5_t *ctx, uint8_t reg_addr, uint16_t transfer_data)
Generic Write function.
uint16_t charger5_generic_read(charger5_t *ctx, uint8_t reg_addr)
Generic Read function.
charger5_err_t
Click error code definition.
Definition charger5.h:145
@ CHARGER5_MODULE_INIT_ERROR
Definition charger5.h:148
@ CHARGER5_STATUS_ERROR
Definition charger5.h:147
@ CHARGER5_STATUS_OK
Definition charger5.h:146
@ CHARGER5_NSTEPS_RANGE_ERROR
Definition charger5.h:149
Click configuration structure definition.
Definition charger5.h:170
pin_name_t sdi
Definition charger5.h:173
spi_master_chip_select_polarity_t cs_polarity
Definition charger5.h:180
pin_name_t sck
Definition charger5.h:174
spi_master_mode_t spi_mode
Definition charger5.h:179
uint32_t spi_speed
Definition charger5.h:178
pin_name_t sdo
Definition charger5.h:172
pin_name_t cs
Definition charger5.h:175
Click context object definition.
Definition charger5.h:157
digital_out_t cs
Definition charger5.h:158
spi_master_t spi
Definition charger5.h:161
pin_name_t chip_select
Definition charger5.h:162