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 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_spi_master.h"
52 
73 #define EFUSE3_OVERFLOW_LOW 2
74 #define EFUSE3_OVERFLOW_HIGH 1
75 #define EFUSE3_NO_OVERFLOW 0
76  // efuse3_set
78 
88 #define EFUSE3_VC_SEL_6_1_V 0
89 #define EFUSE3_VC_SEL_6_9_V 1
90  // vc_sel
92 
102 #define EFUSE3_FLAG_NORMAL_OPERATION 0
103 #define EFUSE3_FLAG_DEVICE_OFF 1
104  // efuse3_get
106 
121 #define EFUSE3_MAP_MIKROBUS( cfg, mikrobus ) \
122  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
123  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
124  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
125  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
126  cfg.vsel = MIKROBUS( mikrobus, MIKROBUS_RST ); \
127  cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
128  cfg.flag = MIKROBUS( mikrobus, MIKROBUS_INT )
129  // efuse3_map // efuse3
132 
137 typedef struct
138 {
139  // Output pins
140 
141  digital_out_t vsel;
142  digital_out_t en;
144  // Input pins
145 
146  digital_in_t flag;
148  // Modules
149 
150  spi_master_t spi;
152  pin_name_t chip_select;
154 } efuse3_t;
155 
160 typedef struct
161 {
162  // Communication gpio pins
163 
164  pin_name_t miso;
165  pin_name_t mosi;
166  pin_name_t sck;
167  pin_name_t cs;
169  // Additional gpio pins
170 
171  pin_name_t vsel;
172  pin_name_t en;
173  pin_name_t flag;
175  // static variable
176 
177  uint32_t spi_speed;
178  spi_master_mode_t spi_mode;
179  spi_master_chip_select_polarity_t cs_polarity;
181 } efuse3_cfg_t;
182 
187 typedef enum
188 {
190  EFUSE3_ERROR = -1
191 
193 
210 
225 err_t efuse3_init ( efuse3_t *ctx, efuse3_cfg_t *cfg );
226 
238 
253 err_t efuse3_generic_read ( efuse3_t *ctx, uint8_t *data_out, uint8_t len );
254 
270 err_t efuse3_get_monitor_output ( efuse3_t *ctx, float *voltage, uint8_t *overflow );
271 
285 err_t efuse3_get_current ( efuse3_t *ctx, float *current );
286 
300 
313 void efuse3_reset ( efuse3_t *ctx );
314 
328 
345 void efuse3_set_overvoltage_clamp ( efuse3_t *ctx, uint8_t vc_sel );
346 
364 uint8_t efuse3_get_flag ( efuse3_t *ctx );
365 
366 #ifdef __cplusplus
367 }
368 #endif
369 #endif // EFUSE3_H
370  // efuse3
372 
373 // ------------------------------------------------------------------------ END
efuse3_cfg_t
e Fuse 3 Click configuration object.
Definition: efuse3.h:161
efuse3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: efuse3.h:179
efuse3_t::en
digital_out_t en
Definition: efuse3.h:142
efuse3_cfg_t::flag
pin_name_t flag
Definition: efuse3.h:173
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:166
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:167
efuse3_cfg_t::miso
pin_name_t miso
Definition: efuse3.h:164
efuse3_cfg_t::en
pin_name_t en
Definition: efuse3.h:172
efuse3_return_value_t
efuse3_return_value_t
e Fuse 3 Click return value data.
Definition: efuse3.h:188
efuse3_t::vsel
digital_out_t vsel
Definition: efuse3.h:141
EFUSE3_ERROR
@ EFUSE3_ERROR
Definition: efuse3.h:190
efuse3_cfg_t::mosi
pin_name_t mosi
Definition: efuse3.h:165
efuse3_t::spi
spi_master_t spi
Definition: efuse3.h:150
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:138
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:152
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:171
efuse3_t::flag
digital_in_t flag
Definition: efuse3.h:146
efuse3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: efuse3.h:178
efuse3_cfg_t::spi_speed
uint32_t spi_speed
Definition: efuse3.h:177
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:189
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.