ups  2.0.0.0
ups.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 UPS_H
36 #define UPS_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define UPS_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.an= MIKROBUS( mikrobus, MIKROBUS_AN ); \
53  cfg.rst= MIKROBUS( mikrobus, MIKROBUS_RST ); \
54  cfg.cs= MIKROBUS( mikrobus, MIKROBUS_CS ); \
55 
61 #define UPS_RETVAL uint8_t
62 
63 #define UPS_OK 0x00
64 #define UPS_INIT_ERROR 0xFF
65 
71 #define UPS_MODE_ACTIVE 1
72 #define UPS_MODE_SLEEP 0
73  // End group macro
76 // --------------------------------------------------------------- PUBLIC TYPES
85 typedef struct
86 {
87  // Output pins
88 
89  digital_out_t rst;
90 
91  // Input pins
92 
93  digital_in_t an;
94  digital_in_t cs;
95 
96 } ups_t;
97 
101 typedef struct
102 {
103  // Additional gpio pins
104 
105  pin_name_t an;
106  pin_name_t rst;
107  pin_name_t cs;
108 
109 } ups_cfg_t;
110  // End types group
112 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
113 
119 #ifdef __cplusplus
120 extern "C"{
121 #endif
122 
131 void ups_cfg_setup ( ups_cfg_t *cfg );
132 
141 UPS_RETVAL ups_init ( ups_t *ctx, ups_cfg_t *cfg );
142 
156 void usp_set_mode ( ups_t *ctx, uint8_t mode );
157 
167 uint8_t ups_get_power_good ( ups_t *ctx );
168 
169 #ifdef __cplusplus
170 }
171 #endif
172 #endif // _UPS_H_
173  // End public_function group
176 
177 // ------------------------------------------------------------------------- END
digital_out_t rst
Definition: ups.h:89
uint8_t ups_get_power_good(ups_t *ctx)
Functions for reading PGD state.
Click configuration structure definition.
Definition: ups.h:101
digital_in_t an
Definition: ups.h:93
pin_name_t an
Definition: ups.h:105
#define UPS_RETVAL
Definition: ups.h:61
Click ctx object definition.
Definition: ups.h:85
pin_name_t rst
Definition: ups.h:106
void ups_cfg_setup(ups_cfg_t *cfg)
Config Object Initialization function.
void usp_set_mode(ups_t *ctx, uint8_t mode)
Functions for settings chip mode.
UPS_RETVAL ups_init(ups_t *ctx, ups_cfg_t *cfg)
Initialization function.
pin_name_t cs
Definition: ups.h:107
digital_in_t cs
Definition: ups.h:94