charger5  2.0.0.0
charger5.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef _CHARGER5_H_
36 #define _CHARGER5_H_
37 
38 #include "drv_spi_master.h"
39 
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define CHARGER5_REG_WIPER0_VOL 0x00
52 #define CHARGER5_REG_WIPER1_VOL 0x01
53 #define CHARGER5_REG_WIPER0_NONVOL 0x02
54 #define CHARGER5_REG_WIPER1_NONVOL 0x03
55 #define CHARGER5_REG_TCONTROL_VOL 0x04
56 #define CHARGER5_REG_STATUS_VOL 0x05
57 #define CHARGER5_REG_DATA_EEPROM0 0x06
58 #define CHARGER5_REG_DATA_EEPROM1 0x07
59 #define CHARGER5_REG_DATA_EEPROM2 0x08
60 #define CHARGER5_REG_DATA_EEPROM3 0x09
61 #define CHARGER5_REG_DATA_EEPROM4 0x0A
62 #define CHARGER5_REG_DATA_EEPROM5 0x0B
63 #define CHARGER5_REG_DATA_EEPROM6 0x0C
64 #define CHARGER5_REG_DATA_EEPROM7 0x0D
65 #define CHARGER5_REG_DATA_EEPROM8 0x0E
66 #define CHARGER5_REG_DATA_EEPROM9 0x0F
67 
73 #define CHARGER5_CURRENT_100MA_MIN 0x00
74 #define CHARGER5_CURRENT_200MA 0x88
75 #define CHARGER5_CURRENT_300MA 0xBD
76 #define CHARGER5_CURRENT_400MA 0xD6
77 #define CHARGER5_CURRENT_500MA 0xE4
78 #define CHARGER5_CURRENT_600MA 0xEE
79 #define CHARGER5_CURRENT_700MA 0xF5
80 #define CHARGER5_CURRENT_800MA 0xFB
81 #define CHARGER5_CURRENT_900MA 0xFE
82 #define CHARGER5_CURRENT_950MA_MAX 0x0100
83 
89 #define CHARGER5_STEPS_1_MIN 0x01
90 #define CHARGER5_STEPS_2 0x02
91 #define CHARGER5_STEPS_5 0x05
92 #define CHARGER5_STEPS_10 0x0A
93 #define CHARGER5_STEPS_50 0x32
94 #define CHARGER5_STEPS_100 0x64
95 #define CHARGER5_STEPS_150 0x96
96 #define CHARGER5_STEPS_200 0xC8
97 #define CHARGER5_STEPS_255_MAX 0xFF
98 
104 #define CHARGER5_MAP_MIKROBUS( cfg, mikrobus ) \
105  cfg.sdi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
106  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
107  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
108  // End macros group
111 // --------------------------------------------------------------- PUBLIC TYPES
120 typedef enum
121 {
126 
128 
132 typedef struct
133 {
134  // Module.
135  spi_master_t spi;
136 
137 } charger5_t;
138 
142 typedef struct
143 {
144  // Communication gpio pins.
145  pin_name_t sdi;
146  pin_name_t sck;
147  pin_name_t cs;
148 
149  // SPI module config variables.
150  hal_spi_speed_t spi_speed;
151  hal_spi_mode_t spi_mode;
152 
154  // End types group
156 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
162 #ifdef __cplusplus
163 extern "C"{
164 #endif
165 
175 void
177 
192 
203 void
205 
219 charger5_generic_write( charger5_t *ctx, uint8_t reg_addr,
220  uint16_t transfer_data );
221 
232 uint16_t
233 charger5_generic_read( charger5_t *ctx, uint8_t reg_addr );
234 
250 charger5_increment_wiper( charger5_t *ctx, uint8_t reg_addr, uint8_t n_steps );
251 
267 charger5_decrement_wiper( charger5_t *ctx, uint8_t reg_addr, uint8_t n_steps );
268 
269 #ifdef __cplusplus
270 }
271 #endif
272 #endif // _CHARGER5_H_
273  // End public_function group
276 
277 // ------------------------------------------------------------------------ END
charger5_err_t charger5_increment_wiper(charger5_t *ctx, uint8_t reg_addr, uint8_t n_steps)
Increment Wiper function.
spi_master_t spi
Definition: charger5.h:135
void charger5_cfg_setup(charger5_cfg_t *cfg)
Configuration Object Setup function.
uint16_t charger5_generic_read(charger5_t *ctx, uint8_t reg_addr)
Generic Read function.
Click context object definition.
Definition: charger5.h:132
charger5_err_t charger5_decrement_wiper(charger5_t *ctx, uint8_t reg_addr, uint8_t n_steps)
Decrement Wiper function.
Definition: charger5.h:122
Definition: charger5.h:125
void charger5_default_cfg(charger5_t *ctx)
Click Default Configuration function.
hal_spi_mode_t spi_mode
Definition: charger5.h:151
pin_name_t cs
Definition: charger5.h:147
charger5_err_t
Click error code definition.
Definition: charger5.h:120
charger5_err_t charger5_generic_write(charger5_t *ctx, uint8_t reg_addr, uint16_t transfer_data)
Generic Write function.
Click configuration structure definition.
Definition: charger5.h:142
pin_name_t sck
Definition: charger5.h:146
hal_spi_speed_t spi_speed
Definition: charger5.h:150
pin_name_t sdi
Definition: charger5.h:145
Definition: charger5.h:124
charger5_err_t charger5_init(charger5_t *ctx, charger5_cfg_t *cfg)
Click Initialization function.
Definition: charger5.h:123