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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 
63 #define UPS3_DIR_MODE_BACKUP 0x00
64 #define UPS3_DIR_MODE_CHARGE 0x01
65  // dir_mode
67 
77 #define UPS3_ENABLE_SHUTDOWN 0x00
78 #define UPS3_ENABLE_NORMAL_OPERATION 0x01
79  // enable
81 
92 #define UPS3_GET_ERROR_CMPIN_OK 0x00
93 #define UPS3_GET_ERROR_CMPIN_EMPTY 0x01
94  // get_error
96 
107 #define UPS3_GET_CAP_OK_FBV_LOW 0x00
108 #define UPS3_GET_CAP_OK_FBV_HIGH 0x01
109  // get_cap_ok
111 
122 #define UPS3_GET_CHRG_CHARGE_MODE 0x00
123 #define UPS3_GET_CHRG_BACKUP_MODE 0x01
124  // get_chrg
126 
137 #define UPS3_SUCCESS 0
138 #define UPS3_ERROR -1
139 
140  // status
142 
157 #define UPS3_MAP_MIKROBUS( cfg, mikrobus ) \
158  cfg.err = MIKROBUS( mikrobus, MIKROBUS_AN ); \
159  cfg.cok = MIKROBUS( mikrobus, MIKROBUS_RST ); \
160  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_CS ); \
161  cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
162  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
163  // ups3_map // ups3
166 
171 typedef struct
172 {
173  // Output pins
174 
175  digital_out_t dir;
176  digital_out_t en;
178  // Input pins
179 
180  digital_in_t err;
181  digital_in_t cok;
182  digital_in_t int_pin;
184 } ups3_t;
185 
190 typedef struct
191 {
192  pin_name_t err;
193  pin_name_t cok;
194  pin_name_t dir;
195  pin_name_t en;
196  pin_name_t int_pin;
198 } ups3_cfg_t;
199 
216 
231 err_t ups3_init ( ups3_t *ctx, ups3_cfg_t *cfg );
232 
246 err_t ups3_default_cfg ( ups3_t *ctx );
247 
259 uint8_t ups3_get_error ( ups3_t *ctx );
260 
272 uint8_t ups3_get_cap_ok ( ups3_t *ctx );
273 
285 uint8_t ups3_get_chrg ( ups3_t *ctx );
286 
302 err_t ups3_select_dir_mode ( ups3_t *ctx, uint8_t dir_mode );
303 
319 err_t ups3_set_enable ( ups3_t *ctx, uint8_t enable );
320 
333 err_t ups3_hw_reset ( ups3_t *ctx ) ;
334 
335 #ifdef __cplusplus
336 }
337 #endif
338 #endif // UPS3_H
339  // ups3
341 
342 // ------------------------------------------------------------------------ END
ups3_t::cok
digital_in_t cok
Definition: ups3.h:181
ups3_cfg_t
UPS 3 Click configuration object.
Definition: ups3.h:191
ups3_cfg_t::dir
pin_name_t dir
Definition: ups3.h:194
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:180
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:195
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:196
ups3_cfg_t::err
pin_name_t err
Definition: ups3.h:192
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:172
ups3_t::en
digital_out_t en
Definition: ups3.h:176
ups3_cfg_t::cok
pin_name_t cok
Definition: ups3.h:193
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:175
ups3_t::int_pin
digital_in_t int_pin
Definition: ups3.h:182
ups3_set_enable
err_t ups3_set_enable(ups3_t *ctx, uint8_t enable)
UPS 3 enable device function.