ups  2.0.0.0
ups.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef UPS_H
36 #define UPS_H
37 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 
55 // -------------------------------------------------------------- PUBLIC MACROS
65 #define UPS_MAP_MIKROBUS( cfg, mikrobus ) \
66  cfg.an= MIKROBUS( mikrobus, MIKROBUS_AN ); \
67  cfg.rst= MIKROBUS( mikrobus, MIKROBUS_RST ); \
68  cfg.cs= MIKROBUS( mikrobus, MIKROBUS_CS ); \
69 
75 #define UPS_RETVAL uint8_t
76 
77 #define UPS_OK 0x00
78 #define UPS_INIT_ERROR 0xFF
79 
85 #define UPS_MODE_ACTIVE 1
86 #define UPS_MODE_SLEEP 0
87  // End group macro
90 // --------------------------------------------------------------- PUBLIC TYPES
99 typedef struct
100 {
101  // Output pins
102 
103  digital_out_t rst;
104 
105  // Input pins
106 
107  digital_in_t an;
108  digital_in_t cs;
109 
110 } ups_t;
111 
115 typedef struct
116 {
117  // Additional gpio pins
118 
119  pin_name_t an;
120  pin_name_t rst;
121  pin_name_t cs;
122 
123 } ups_cfg_t;
124  // End types group
126 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
127 
133 #ifdef __cplusplus
134 extern "C"{
135 #endif
136 
145 void ups_cfg_setup ( ups_cfg_t *cfg );
146 
156 
170 void usp_set_mode ( ups_t *ctx, uint8_t mode );
171 
181 uint8_t ups_get_power_good ( ups_t *ctx );
182 
183 #ifdef __cplusplus
184 }
185 #endif
186 #endif // _UPS_H_
187  // End public_function group
190 
191 // ------------------------------------------------------------------------- END
ups_cfg_t::cs
pin_name_t cs
Definition: ups.h:121
ups_t::rst
digital_out_t rst
Definition: ups.h:103
ups_t
Click ctx object definition.
Definition: ups.h:100
ups_t::cs
digital_in_t cs
Definition: ups.h:108
ups_cfg_t::an
pin_name_t an
Definition: ups.h:119
ups_get_power_good
uint8_t ups_get_power_good(ups_t *ctx)
Functions for reading PGD state.
usp_set_mode
void usp_set_mode(ups_t *ctx, uint8_t mode)
Functions for settings chip mode.
ups_cfg_t
Click configuration structure definition.
Definition: ups.h:116
ups_t::an
digital_in_t an
Definition: ups.h:107
ups_cfg_t::rst
pin_name_t rst
Definition: ups.h:120
ups_init
UPS_RETVAL ups_init(ups_t *ctx, ups_cfg_t *cfg)
Initialization function.
UPS_RETVAL
#define UPS_RETVAL
Definition: ups.h:75
ups_cfg_setup
void ups_cfg_setup(ups_cfg_t *cfg)
Config Object Initialization function.