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 
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  // dir_mode
71 
81 #define UPS3_ENABLE_SHUTDOWN 0x00
82 #define UPS3_ENABLE_NORMAL_OPERATION 0x01
83  // enable
85 
96 #define UPS3_GET_ERROR_CMPIN_OK 0x00
97 #define UPS3_GET_ERROR_CMPIN_EMPTY 0x01
98  // get_error
100 
111 #define UPS3_GET_CAP_OK_FBV_LOW 0x00
112 #define UPS3_GET_CAP_OK_FBV_HIGH 0x01
113  // get_cap_ok
115 
126 #define UPS3_GET_CHRG_CHARGE_MODE 0x00
127 #define UPS3_GET_CHRG_BACKUP_MODE 0x01
128  // get_chrg
130 
141 #define UPS3_SUCCESS 0
142 #define UPS3_ERROR -1
143 
144  // 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  // ups3_map // ups3
170 
175 typedef 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 
194 typedef 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 
235 err_t ups3_init ( ups3_t *ctx, ups3_cfg_t *cfg );
236 
250 err_t ups3_default_cfg ( ups3_t *ctx );
251 
263 uint8_t ups3_get_error ( ups3_t *ctx );
264 
276 uint8_t ups3_get_cap_ok ( ups3_t *ctx );
277 
289 uint8_t ups3_get_chrg ( ups3_t *ctx );
290 
306 err_t ups3_select_dir_mode ( ups3_t *ctx, uint8_t dir_mode );
307 
323 err_t ups3_set_enable ( ups3_t *ctx, uint8_t enable );
324 
337 err_t ups3_hw_reset ( ups3_t *ctx ) ;
338 
339 #ifdef __cplusplus
340 }
341 #endif
342 #endif // UPS3_H
343  // ups3
345 
346 // ------------------------------------------------------------------------ END
ups3_t::cok
digital_in_t cok
Definition: ups3.h:185
ups3_cfg_t
UPS 3 Click configuration object.
Definition: ups3.h:195
ups3_cfg_t::dir
pin_name_t dir
Definition: ups3.h:198
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:184
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:199
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:200
ups3_cfg_t::err
pin_name_t err
Definition: ups3.h:196
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:176
ups3_t::en
digital_out_t en
Definition: ups3.h:180
ups3_cfg_t::cok
pin_name_t cok
Definition: ups3.h:197
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:179
ups3_t::int_pin
digital_in_t int_pin
Definition: ups3.h:186
ups3_set_enable
err_t ups3_set_enable(ups3_t *ctx, uint8_t enable)
UPS 3 enable device function.