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 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
61 #define UPS_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.an= MIKROBUS( mikrobus, MIKROBUS_AN ); \
63  cfg.rst= MIKROBUS( mikrobus, MIKROBUS_RST ); \
64  cfg.cs= MIKROBUS( mikrobus, MIKROBUS_CS ); \
65 
71 #define UPS_RETVAL uint8_t
72 
73 #define UPS_OK 0x00
74 #define UPS_INIT_ERROR 0xFF
75 
81 #define UPS_MODE_ACTIVE 1
82 #define UPS_MODE_SLEEP 0
83  // End group macro
86 // --------------------------------------------------------------- PUBLIC TYPES
95 typedef struct
96 {
97  // Output pins
98 
99  digital_out_t rst;
100 
101  // Input pins
102 
103  digital_in_t an;
104  digital_in_t cs;
105 
106 } ups_t;
107 
111 typedef struct
112 {
113  // Additional gpio pins
114 
115  pin_name_t an;
116  pin_name_t rst;
117  pin_name_t cs;
118 
119 } ups_cfg_t;
120  // End types group
122 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
123 
129 #ifdef __cplusplus
130 extern "C"{
131 #endif
132 
141 void ups_cfg_setup ( ups_cfg_t *cfg );
142 
152 
166 void usp_set_mode ( ups_t *ctx, uint8_t mode );
167 
177 uint8_t ups_get_power_good ( ups_t *ctx );
178 
179 #ifdef __cplusplus
180 }
181 #endif
182 #endif // _UPS_H_
183  // End public_function group
186 
187 // ------------------------------------------------------------------------- END
ups_cfg_t::cs
pin_name_t cs
Definition: ups.h:117
ups_t::rst
digital_out_t rst
Definition: ups.h:99
ups_t
Click ctx object definition.
Definition: ups.h:96
ups_t::cs
digital_in_t cs
Definition: ups.h:104
ups_cfg_t::an
pin_name_t an
Definition: ups.h:115
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:112
ups_t::an
digital_in_t an
Definition: ups.h:103
ups_cfg_t::rst
pin_name_t rst
Definition: ups.h:116
ups_init
UPS_RETVAL ups_init(ups_t *ctx, ups_cfg_t *cfg)
Initialization function.
UPS_RETVAL
#define UPS_RETVAL
Definition: ups.h:71
ups_cfg_setup
void ups_cfg_setup(ups_cfg_t *cfg)
Config Object Initialization function.