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 
38 #include "drv_spi_master.h"
39 
40 // -------------------------------------------------------------- PUBLIC MACROS
50 #define CHARGER5_RETVAL uint8_t
51 
52 #define CHARGER5_OK 0x00
53 #define CHARGER5_INIT_ERROR 0xFF
54 
60 #define CHARGER5_REG_WIPER0_VOL 0x00
61 #define CHARGER5_REG_WIPER1_VOL 0x01
62 #define CHARGER5_REG_WIPER0_NONVOL 0x02
63 #define CHARGER5_REG_WIPER1_NONVOL 0x03
64 #define CHARGER5_REG_TCONTROL_VOL 0x04
65 #define CHARGER5_REG_STATUS_VOL 0x05
66 #define CHARGER5_REG_DATA_EEPROM0 0x06
67 #define CHARGER5_REG_DATA_EEPROM1 0x07
68 #define CHARGER5_REG_DATA_EEPROM2 0x08
69 #define CHARGER5_REG_DATA_EEPROM3 0x09
70 #define CHARGER5_REG_DATA_EEPROM4 0x0A
71 #define CHARGER5_REG_DATA_EEPROM5 0x0B
72 #define CHARGER5_REG_DATA_EEPROM6 0x0C
73 #define CHARGER5_REG_DATA_EEPROM7 0x0D
74 #define CHARGER5_REG_DATA_EEPROM8 0x0E
75 #define CHARGER5_REG_DATA_EEPROM9 0x0F
76 
82 #define CHARGER5_CURRENT_100MA_MIN 0x00
83 #define CHARGER5_CURRENT_200MA 0x88
84 #define CHARGER5_CURRENT_300MA 0xBD
85 #define CHARGER5_CURRENT_400MA 0xD6
86 #define CHARGER5_CURRENT_500MA 0xE4
87 #define CHARGER5_CURRENT_600MA 0xEE
88 #define CHARGER5_CURRENT_700MA 0xF5
89 #define CHARGER5_CURRENT_800MA 0xFB
90 #define CHARGER5_CURRENT_900MA 0xFE
91 #define CHARGER5_CURRENT_950MA_MAX 0x0100
92 
98 #define CHARGER5_STEPS_1_MIN 0x01
99 #define CHARGER5_STEPS_2 0x02
100 #define CHARGER5_STEPS_5 0x05
101 #define CHARGER5_STEPS_10 0x0A
102 #define CHARGER5_STEPS_50 0x32
103 #define CHARGER5_STEPS_100 0x64
104 #define CHARGER5_STEPS_150 0x96
105 #define CHARGER5_STEPS_200 0xC8
106 #define CHARGER5_STEPS_255_MAX 0xFF
107 
113 #define CHARGER5_MAP_MIKROBUS( cfg, mikrobus ) \
114  cfg.sdo = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
115  cfg.sdi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
116  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
117  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
118  // End macros group
121 // --------------------------------------------------------------- PUBLIC TYPES
130 typedef enum
131 {
136 
138 
142 typedef struct
143 {
144  digital_out_t cs;
145 
146  // Module.
147  spi_master_t spi;
148  pin_name_t chip_select;
149 
150 } charger5_t;
151 
155 typedef struct
156 {
157  // Communication gpio pins.
158  pin_name_t sdo;
159  pin_name_t sdi;
160  pin_name_t sck;
161  pin_name_t cs;
162 
163  // SPI module config variables.
164  uint32_t spi_speed;
165  spi_master_mode_t spi_mode;
166  spi_master_chip_select_polarity_t cs_polarity;
167 
169  // End types group
171 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
177 #ifdef __cplusplus
178 extern "C"{
179 #endif
180 
190 void
192 
207 
218 void
220 
234 charger5_generic_write( charger5_t *ctx, uint8_t reg_addr,
235  uint16_t transfer_data );
236 
247 uint16_t
248 charger5_generic_read( charger5_t *ctx, uint8_t reg_addr );
249 
265 charger5_increment_wiper( charger5_t *ctx, uint8_t reg_addr, uint8_t n_steps );
266 
282 charger5_decrement_wiper( charger5_t *ctx, uint8_t reg_addr, uint8_t n_steps );
283 
284 #ifdef __cplusplus
285 }
286 #endif
287 #endif // _CHARGER5_H_
288  // End public_function group
291 
292 // ------------------------------------------------------------------------ END
charger5_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: charger5.h:165
charger5_init
charger5_err_t charger5_init(charger5_t *ctx, charger5_cfg_t *cfg)
Click Initialization function.
charger5_cfg_t
Click configuration structure definition.
Definition: charger5.h:155
charger5_decrement_wiper
charger5_err_t charger5_decrement_wiper(charger5_t *ctx, uint8_t reg_addr, uint8_t n_steps)
Decrement Wiper function.
CHARGER5_MODULE_INIT_ERROR
Definition: charger5.h:134
charger5_t::chip_select
pin_name_t chip_select
Definition: charger5.h:148
charger5_err_t
charger5_err_t
Click error code definition.
Definition: charger5.h:130
charger5_t
Click context object definition.
Definition: charger5.h:142
charger5_increment_wiper
charger5_err_t charger5_increment_wiper(charger5_t *ctx, uint8_t reg_addr, uint8_t n_steps)
Increment Wiper function.
charger5_cfg_t::sck
pin_name_t sck
Definition: charger5.h:160
charger5_cfg_t::cs
pin_name_t cs
Definition: charger5.h:161
CHARGER5_STATUS_OK
Definition: charger5.h:132
charger5_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: charger5.h:166
charger5_generic_write
charger5_err_t charger5_generic_write(charger5_t *ctx, uint8_t reg_addr, uint16_t transfer_data)
Generic Write function.
charger5_cfg_setup
void charger5_cfg_setup(charger5_cfg_t *cfg)
Configuration Object Setup function.
charger5_cfg_t::sdi
pin_name_t sdi
Definition: charger5.h:159
charger5_generic_read
uint16_t charger5_generic_read(charger5_t *ctx, uint8_t reg_addr)
Generic Read function.
charger5_t::cs
digital_out_t cs
Definition: charger5.h:144
charger5_default_cfg
void charger5_default_cfg(charger5_t *ctx)
Click Default Configuration function.
charger5_cfg_t::sdo
pin_name_t sdo
Definition: charger5.h:158
CHARGER5_STATUS_ERROR
Definition: charger5.h:133
CHARGER5_NSTEPS_RANGE_ERROR
Definition: charger5.h:135
charger5_t::spi
spi_master_t spi
Definition: charger5.h:147
charger5_cfg_t::spi_speed
uint32_t spi_speed
Definition: charger5.h:164