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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 
53 #define UPS3_DIR_MODE_BACKUP 0x00
54 #define UPS3_DIR_MODE_CHARGE 0x01
55  // dir_mode
57 
67 #define UPS3_ENABLE_SHUTDOWN 0x00
68 #define UPS3_ENABLE_NORMAL_OPERATION 0x01
69  // enable
71 
82 #define UPS3_GET_ERROR_CMPIN_OK 0x00
83 #define UPS3_GET_ERROR_CMPIN_EMPTY 0x01
84  // get_error
86 
97 #define UPS3_GET_CAP_OK_FBV_LOW 0x00
98 #define UPS3_GET_CAP_OK_FBV_HIGH 0x01
99  // get_cap_ok
101 
112 #define UPS3_GET_CHRG_CHARGE_MODE 0x00
113 #define UPS3_GET_CHRG_BACKUP_MODE 0x01
114  // get_chrg
116 
127 #define UPS3_SUCCESS 0
128 #define UPS3_ERROR -1
129 
130  // status
132 
147 #define UPS3_MAP_MIKROBUS( cfg, mikrobus ) \
148  cfg.err = MIKROBUS( mikrobus, MIKROBUS_AN ); \
149  cfg.cok = MIKROBUS( mikrobus, MIKROBUS_RST ); \
150  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_CS ); \
151  cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
152  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
153  // ups3_map // ups3
156 
161 typedef struct
162 {
163  // Output pins
164 
165  digital_out_t dir;
166  digital_out_t en;
168  // Input pins
169 
170  digital_in_t err;
171  digital_in_t cok;
172  digital_in_t int_pin;
174 } ups3_t;
175 
180 typedef struct
181 {
182  pin_name_t err;
183  pin_name_t cok;
184  pin_name_t dir;
185  pin_name_t en;
186  pin_name_t int_pin;
188 } ups3_cfg_t;
189 
206 
221 err_t ups3_init ( ups3_t *ctx, ups3_cfg_t *cfg );
222 
236 err_t ups3_default_cfg ( ups3_t *ctx );
237 
249 uint8_t ups3_get_error ( ups3_t *ctx );
250 
262 uint8_t ups3_get_cap_ok ( ups3_t *ctx );
263 
275 uint8_t ups3_get_chrg ( ups3_t *ctx );
276 
292 err_t ups3_select_dir_mode ( ups3_t *ctx, uint8_t dir_mode );
293 
309 err_t ups3_set_enable ( ups3_t *ctx, uint8_t enable );
310 
323 err_t ups3_hw_reset ( ups3_t *ctx ) ;
324 
325 #ifdef __cplusplus
326 }
327 #endif
328 #endif // UPS3_H
329  // ups3
331 
332 // ------------------------------------------------------------------------ END
ups3_t::cok
digital_in_t cok
Definition: ups3.h:171
ups3_cfg_t
UPS 3 Click configuration object.
Definition: ups3.h:181
ups3_cfg_t::dir
pin_name_t dir
Definition: ups3.h:184
ups3_init
err_t ups3_init(ups3_t *ctx, ups3_cfg_t *cfg)
UPS 3 initialization function.
ups3_t::err
digital_in_t err
Definition: ups3.h:170
ups3_select_dir_mode
err_t ups3_select_dir_mode(ups3_t *ctx, uint8_t dir_mode)
UPS 3 pin select direction of the operation modes function.
ups3_cfg_t::en
pin_name_t en
Definition: ups3.h:185
ups3_default_cfg
err_t ups3_default_cfg(ups3_t *ctx)
UPS 3 default configuration function.
ups3_get_error
uint8_t ups3_get_error(ups3_t *ctx)
UPS 3 get error function.
ups3_cfg_t::int_pin
pin_name_t int_pin
Definition: ups3.h:186
ups3_cfg_t::err
pin_name_t err
Definition: ups3.h:182
ups3_cfg_setup
void ups3_cfg_setup(ups3_cfg_t *cfg)
UPS 3 configuration object setup function.
ups3_get_chrg
uint8_t ups3_get_chrg(ups3_t *ctx)
UPS 3 get charge/backup mode function.
ups3_t
UPS 3 Click context object.
Definition: ups3.h:162
ups3_t::en
digital_out_t en
Definition: ups3.h:166
ups3_cfg_t::cok
pin_name_t cok
Definition: ups3.h:183
ups3_hw_reset
err_t ups3_hw_reset(ups3_t *ctx)
UPS 3 reset the device function.
ups3_get_cap_ok
uint8_t ups3_get_cap_ok(ups3_t *ctx)
UPS 3 pin get capacitor ok function.
ups3_t::dir
digital_out_t dir
Definition: ups3.h:165
ups3_t::int_pin
digital_in_t int_pin
Definition: ups3.h:172
ups3_set_enable
err_t ups3_set_enable(ups3_t *ctx, uint8_t enable)
UPS 3 enable device function.