efuse3  2.0.0.0
efuse3.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 EFUSE3_H
29 #define EFUSE3_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 #include "drv_spi_master.h"
48 
69 #define EFUSE3_OVERFLOW_LOW 2
70 #define EFUSE3_OVERFLOW_HIGH 1
71 #define EFUSE3_NO_OVERFLOW 0
72  // efuse3_set
74 
84 #define EFUSE3_VC_SEL_6_1_V 0
85 #define EFUSE3_VC_SEL_6_9_V 1
86  // vc_sel
88 
98 #define EFUSE3_FLAG_NORMAL_OPERATION 0
99 #define EFUSE3_FLAG_DEVICE_OFF 1
100  // efuse3_get
102 
117 #define EFUSE3_MAP_MIKROBUS( cfg, mikrobus ) \
118  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
119  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
120  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
121  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
122  cfg.vsel = MIKROBUS( mikrobus, MIKROBUS_RST ); \
123  cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
124  cfg.flag = MIKROBUS( mikrobus, MIKROBUS_INT )
125  // efuse3_map // efuse3
128 
133 typedef struct
134 {
135  // Output pins
136 
137  digital_out_t vsel;
138  digital_out_t en;
140  // Input pins
141 
142  digital_in_t flag;
144  // Modules
145 
146  spi_master_t spi;
148  pin_name_t chip_select;
150 } efuse3_t;
151 
156 typedef struct
157 {
158  // Communication gpio pins
159 
160  pin_name_t miso;
161  pin_name_t mosi;
162  pin_name_t sck;
163  pin_name_t cs;
165  // Additional gpio pins
166 
167  pin_name_t vsel;
168  pin_name_t en;
169  pin_name_t flag;
171  // static variable
172 
173  uint32_t spi_speed;
174  spi_master_mode_t spi_mode;
175  spi_master_chip_select_polarity_t cs_polarity;
177 } efuse3_cfg_t;
178 
183 typedef enum
184 {
186  EFUSE3_ERROR = -1
187 
189 
206 
221 err_t efuse3_init ( efuse3_t *ctx, efuse3_cfg_t *cfg );
222 
234 
249 err_t efuse3_generic_read ( efuse3_t *ctx, uint8_t *data_out, uint8_t len );
250 
266 err_t efuse3_get_monitor_output ( efuse3_t *ctx, float *voltage, uint8_t *overflow );
267 
281 err_t efuse3_get_current ( efuse3_t *ctx, float *current );
282 
296 
309 void efuse3_reset ( efuse3_t *ctx );
310 
324 
341 void efuse3_set_overvoltage_clamp ( efuse3_t *ctx, uint8_t vc_sel );
342 
360 uint8_t efuse3_get_flag ( efuse3_t *ctx );
361 
362 #ifdef __cplusplus
363 }
364 #endif
365 #endif // EFUSE3_H
366  // efuse3
368 
369 // ------------------------------------------------------------------------ END
efuse3_cfg_t
e Fuse 3 Click configuration object.
Definition: efuse3.h:157
efuse3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: efuse3.h:175
efuse3_t::en
digital_out_t en
Definition: efuse3.h:138
efuse3_cfg_t::flag
pin_name_t flag
Definition: efuse3.h:169
efuse3_get_flag
uint8_t efuse3_get_flag(efuse3_t *ctx)
e Fuse 3 get flag function.
efuse3_cfg_t::sck
pin_name_t sck
Definition: efuse3.h:162
efuse3_init
err_t efuse3_init(efuse3_t *ctx, efuse3_cfg_t *cfg)
e Fuse 3 initialization function.
efuse3_set_overvoltage_clamp
void efuse3_set_overvoltage_clamp(efuse3_t *ctx, uint8_t vc_sel)
e Fuse 3 set overvoltage clamp function.
efuse3_cfg_t::cs
pin_name_t cs
Definition: efuse3.h:163
efuse3_cfg_t::miso
pin_name_t miso
Definition: efuse3.h:160
efuse3_cfg_t::en
pin_name_t en
Definition: efuse3.h:168
efuse3_return_value_t
efuse3_return_value_t
e Fuse 3 Click return value data.
Definition: efuse3.h:184
efuse3_t::vsel
digital_out_t vsel
Definition: efuse3.h:137
EFUSE3_ERROR
@ EFUSE3_ERROR
Definition: efuse3.h:186
efuse3_cfg_t::mosi
pin_name_t mosi
Definition: efuse3.h:161
efuse3_t::spi
spi_master_t spi
Definition: efuse3.h:146
efuse3_disable_device
void efuse3_disable_device(efuse3_t *ctx)
e Fuse 3 disable device function.
efuse3_reset
void efuse3_reset(efuse3_t *ctx)
e Fuse 3 reset function.
efuse3_t
e Fuse 3 Click context object.
Definition: efuse3.h:134
efuse3_generic_read
err_t efuse3_generic_read(efuse3_t *ctx, uint8_t *data_out, uint8_t len)
e Fuse 3 data reading function.
efuse3_t::chip_select
pin_name_t chip_select
Definition: efuse3.h:148
efuse3_cfg_setup
void efuse3_cfg_setup(efuse3_cfg_t *cfg)
e Fuse 3 configuration object setup function.
efuse3_cfg_t::vsel
pin_name_t vsel
Definition: efuse3.h:167
efuse3_t::flag
digital_in_t flag
Definition: efuse3.h:142
efuse3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: efuse3.h:174
efuse3_cfg_t::spi_speed
uint32_t spi_speed
Definition: efuse3.h:173
efuse3_get_current
err_t efuse3_get_current(efuse3_t *ctx, float *current)
e Fuse 3 get current function.
efuse3_get_monitor_output
err_t efuse3_get_monitor_output(efuse3_t *ctx, float *voltage, uint8_t *overflow)
e Fuse 3 get monitor output function.
EFUSE3_OK
@ EFUSE3_OK
Definition: efuse3.h:185
efuse3_enable_device
void efuse3_enable_device(efuse3_t *ctx)
e Fuse 3 enable device function.
efuse3_default_cfg
void efuse3_default_cfg(efuse3_t *ctx)
e Fuse 3 default configuration function.