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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_spi_master.h"
49 
50 // -------------------------------------------------------------- PUBLIC MACROS
60 #define CHARGER5_RETVAL uint8_t
61 
62 #define CHARGER5_OK 0x00
63 #define CHARGER5_INIT_ERROR 0xFF
64 
70 #define CHARGER5_REG_WIPER0_VOL 0x00
71 #define CHARGER5_REG_WIPER1_VOL 0x01
72 #define CHARGER5_REG_WIPER0_NONVOL 0x02
73 #define CHARGER5_REG_WIPER1_NONVOL 0x03
74 #define CHARGER5_REG_TCONTROL_VOL 0x04
75 #define CHARGER5_REG_STATUS_VOL 0x05
76 #define CHARGER5_REG_DATA_EEPROM0 0x06
77 #define CHARGER5_REG_DATA_EEPROM1 0x07
78 #define CHARGER5_REG_DATA_EEPROM2 0x08
79 #define CHARGER5_REG_DATA_EEPROM3 0x09
80 #define CHARGER5_REG_DATA_EEPROM4 0x0A
81 #define CHARGER5_REG_DATA_EEPROM5 0x0B
82 #define CHARGER5_REG_DATA_EEPROM6 0x0C
83 #define CHARGER5_REG_DATA_EEPROM7 0x0D
84 #define CHARGER5_REG_DATA_EEPROM8 0x0E
85 #define CHARGER5_REG_DATA_EEPROM9 0x0F
86 
92 #define CHARGER5_CURRENT_100MA_MIN 0x00
93 #define CHARGER5_CURRENT_200MA 0x88
94 #define CHARGER5_CURRENT_300MA 0xBD
95 #define CHARGER5_CURRENT_400MA 0xD6
96 #define CHARGER5_CURRENT_500MA 0xE4
97 #define CHARGER5_CURRENT_600MA 0xEE
98 #define CHARGER5_CURRENT_700MA 0xF5
99 #define CHARGER5_CURRENT_800MA 0xFB
100 #define CHARGER5_CURRENT_900MA 0xFE
101 #define CHARGER5_CURRENT_950MA_MAX 0x0100
102 
108 #define CHARGER5_STEPS_1_MIN 0x01
109 #define CHARGER5_STEPS_2 0x02
110 #define CHARGER5_STEPS_5 0x05
111 #define CHARGER5_STEPS_10 0x0A
112 #define CHARGER5_STEPS_50 0x32
113 #define CHARGER5_STEPS_100 0x64
114 #define CHARGER5_STEPS_150 0x96
115 #define CHARGER5_STEPS_200 0xC8
116 #define CHARGER5_STEPS_255_MAX 0xFF
117 
123 #define CHARGER5_MAP_MIKROBUS( cfg, mikrobus ) \
124  cfg.sdo = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
125  cfg.sdi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
126  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
127  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
128  // End macros group
131 // --------------------------------------------------------------- PUBLIC TYPES
140 typedef enum
141 {
146 
148 
152 typedef struct
153 {
154  digital_out_t cs;
155 
156  // Module.
157  spi_master_t spi;
158  pin_name_t chip_select;
159 
160 } charger5_t;
161 
165 typedef struct
166 {
167  // Communication gpio pins.
168  pin_name_t sdo;
169  pin_name_t sdi;
170  pin_name_t sck;
171  pin_name_t cs;
172 
173  // SPI module config variables.
174  uint32_t spi_speed;
175  spi_master_mode_t spi_mode;
176  spi_master_chip_select_polarity_t cs_polarity;
177 
179  // End types group
181 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
187 #ifdef __cplusplus
188 extern "C"{
189 #endif
190 
200 void
202 
217 
228 void
230 
244 charger5_generic_write( charger5_t *ctx, uint8_t reg_addr,
245  uint16_t transfer_data );
246 
257 uint16_t
258 charger5_generic_read( charger5_t *ctx, uint8_t reg_addr );
259 
275 charger5_increment_wiper( charger5_t *ctx, uint8_t reg_addr, uint8_t n_steps );
276 
292 charger5_decrement_wiper( charger5_t *ctx, uint8_t reg_addr, uint8_t n_steps );
293 
294 #ifdef __cplusplus
295 }
296 #endif
297 #endif // _CHARGER5_H_
298  // End public_function group
301 
302 // ------------------------------------------------------------------------ END
charger5_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: charger5.h:175
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:166
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
@ CHARGER5_MODULE_INIT_ERROR
Definition: charger5.h:144
charger5_t::chip_select
pin_name_t chip_select
Definition: charger5.h:158
charger5_err_t
charger5_err_t
Click error code definition.
Definition: charger5.h:141
charger5_t
Click context object definition.
Definition: charger5.h:153
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:170
charger5_cfg_t::cs
pin_name_t cs
Definition: charger5.h:171
CHARGER5_STATUS_OK
@ CHARGER5_STATUS_OK
Definition: charger5.h:142
charger5_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: charger5.h:176
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:169
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:154
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:168
CHARGER5_STATUS_ERROR
@ CHARGER5_STATUS_ERROR
Definition: charger5.h:143
CHARGER5_NSTEPS_RANGE_ERROR
@ CHARGER5_NSTEPS_RANGE_ERROR
Definition: charger5.h:145
charger5_t::spi
spi_master_t spi
Definition: charger5.h:157
charger5_cfg_t::spi_speed
uint32_t spi_speed
Definition: charger5.h:174