ups3 2.0.0.0
ups3.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 UPS3_H
29#define UPS3_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
67#define UPS3_DIR_MODE_BACKUP 0x00
68#define UPS3_DIR_MODE_CHARGE 0x01
69
70 // dir_mode
71
81#define UPS3_ENABLE_SHUTDOWN 0x00
82#define UPS3_ENABLE_NORMAL_OPERATION 0x01
83
84 // enable
85
96#define UPS3_GET_ERROR_CMPIN_OK 0x00
97#define UPS3_GET_ERROR_CMPIN_EMPTY 0x01
98
99 // get_error
100
111#define UPS3_GET_CAP_OK_FBV_LOW 0x00
112#define UPS3_GET_CAP_OK_FBV_HIGH 0x01
113
114 // get_cap_ok
115
126#define UPS3_GET_CHRG_CHARGE_MODE 0x00
127#define UPS3_GET_CHRG_BACKUP_MODE 0x01
128
129 // get_chrg
130
141#define UPS3_SUCCESS 0
142#define UPS3_ERROR -1
143
144
145 // status
146
161#define UPS3_MAP_MIKROBUS( cfg, mikrobus ) \
162 cfg.err = MIKROBUS( mikrobus, MIKROBUS_AN ); \
163 cfg.cok = MIKROBUS( mikrobus, MIKROBUS_RST ); \
164 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_CS ); \
165 cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
166 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
167
168 // ups3_map
169 // ups3
170
175typedef struct
176{
177 // Output pins
178
179 digital_out_t dir;
180 digital_out_t en;
182 // Input pins
183
184 digital_in_t err;
185 digital_in_t cok;
186 digital_in_t int_pin;
188} ups3_t;
189
194typedef struct
195{
196 pin_name_t err;
197 pin_name_t cok;
198 pin_name_t dir;
199 pin_name_t en;
200 pin_name_t int_pin;
202} ups3_cfg_t;
203
220
235err_t ups3_init ( ups3_t *ctx, ups3_cfg_t *cfg );
236
251
263uint8_t ups3_get_error ( ups3_t *ctx );
264
276uint8_t ups3_get_cap_ok ( ups3_t *ctx );
277
289uint8_t ups3_get_chrg ( ups3_t *ctx );
290
306err_t ups3_select_dir_mode ( ups3_t *ctx, uint8_t dir_mode );
307
323err_t ups3_set_enable ( ups3_t *ctx, uint8_t enable );
324
337err_t ups3_hw_reset ( ups3_t *ctx ) ;
338
339#ifdef __cplusplus
340}
341#endif
342#endif // UPS3_H
343
344 // ups3
345
346// ------------------------------------------------------------------------ END
uint8_t ups3_get_chrg(ups3_t *ctx)
UPS 3 get charge/backup mode function.
err_t ups3_select_dir_mode(ups3_t *ctx, uint8_t dir_mode)
UPS 3 pin select direction of the operation modes function.
err_t ups3_default_cfg(ups3_t *ctx)
UPS 3 default configuration function.
uint8_t ups3_get_cap_ok(ups3_t *ctx)
UPS 3 pin get capacitor ok function.
void ups3_cfg_setup(ups3_cfg_t *cfg)
UPS 3 configuration object setup function.
err_t ups3_init(ups3_t *ctx, ups3_cfg_t *cfg)
UPS 3 initialization function.
err_t ups3_hw_reset(ups3_t *ctx)
UPS 3 reset the device function.
uint8_t ups3_get_error(ups3_t *ctx)
UPS 3 get error function.
err_t ups3_set_enable(ups3_t *ctx, uint8_t enable)
UPS 3 enable device function.
UPS 3 Click configuration object.
Definition ups3.h:195
pin_name_t cok
Definition ups3.h:197
pin_name_t err
Definition ups3.h:196
pin_name_t dir
Definition ups3.h:198
pin_name_t en
Definition ups3.h:199
pin_name_t int_pin
Definition ups3.h:200
UPS 3 Click context object.
Definition ups3.h:176
digital_in_t int_pin
Definition ups3.h:186
digital_in_t cok
Definition ups3.h:185
digital_out_t en
Definition ups3.h:180
digital_in_t err
Definition ups3.h:184
digital_out_t dir
Definition ups3.h:179