fan4  2.0.0.0
fan4.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 FAN4_H
36 #define FAN4_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_i2c_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define FAN4_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
53  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
54 
60 #define FAN4_RETVAL uint8_t
61 
62 #define FAN4_OK 0x00
63 #define FAN4_INIT_ERROR 0xFF
64 
70 #define FAN4_SLAVE_ADDRESS 0x74
71 
77 #define FAN4_BOOST_START_TIMER_DIS 0x00
78 #define FAN4_BOOST_START_TIMER_EN 0x01
79 
85 #define FAN4_VOLT_RANGE_CHECK_MASK 0x01
86 #define FAN4_BS_TIMER_CHECK_MASK 0x02
87 #define FAN4_THERM_SHTDWN_CHECK_MASK 0x40
88 #define FAN4_OVERCURR_CHECK_MASK 0x80
89 #define FAN4_CHECK_OK 0x00
90 
96 #define FAN4_DAC_LSB 78
97 #define FAN4_MIN_VOLT_SCALE 0
98 #define FAN4_MAX_VOLT_SCALE 4922
99  // End group macro
102 // --------------------------------------------------------------- PUBLIC TYPES
111 typedef struct
112 {
113  // Modules
114 
115  i2c_master_t i2c;
116 
117  // ctx variable
118 
119  uint8_t slave_address;
120 
121 } fan4_t;
122 
126 typedef struct
127 {
128  // Communication gpio pins
129 
130  pin_name_t scl;
131  pin_name_t sda;
132 
133  // static variable
134 
135  uint32_t i2c_speed;
136  uint8_t i2c_address;
137 
138 } fan4_cfg_t;
139  // End types group
141 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
142 
148 #ifdef __cplusplus
149 extern "C"{
150 #endif
151 
160 void fan4_cfg_setup ( fan4_cfg_t *cfg );
161 
170 FAN4_RETVAL fan4_init ( fan4_t *ctx, fan4_cfg_t *cfg );
171 
179 void fan4_default_cfg ( fan4_t *ctx );
180 
187 void fan4_generic_write ( fan4_t *ctx, uint8_t cmd);
188 
195 void fan4_generic_read ( fan4_t *ctx, uint8_t *data_out );
196 
204 FAN4_RETVAL fan4_set_output ( fan4_t *ctx, uint16_t output_volt, uint8_t boost_start_timer );
205 
212 uint8_t fan4_check_diagnostic ( fan4_t *ctx );
213 
214 #ifdef __cplusplus
215 }
216 #endif
217 #endif // _FAN4_H_
218  // End public_function group
221 
222 // ------------------------------------------------------------------------- END
fan4_t::i2c
i2c_master_t i2c
Definition: fan4.h:115
fan4_init
FAN4_RETVAL fan4_init(fan4_t *ctx, fan4_cfg_t *cfg)
Initialization function.
fan4_t
Click ctx object definition.
Definition: fan4.h:111
FAN4_RETVAL
#define FAN4_RETVAL
Definition: fan4.h:60
fan4_cfg_t::scl
pin_name_t scl
Definition: fan4.h:130
fan4_check_diagnostic
uint8_t fan4_check_diagnostic(fan4_t *ctx)
Check diagnostic.
fan4_set_output
FAN4_RETVAL fan4_set_output(fan4_t *ctx, uint16_t output_volt, uint8_t boost_start_timer)
Set output voltage.
fan4_t::slave_address
uint8_t slave_address
Definition: fan4.h:119
fan4_cfg_setup
void fan4_cfg_setup(fan4_cfg_t *cfg)
Config Object Initialization function.
fan4_cfg_t::i2c_address
uint8_t i2c_address
Definition: fan4.h:136
fan4_cfg_t
Click configuration structure definition.
Definition: fan4.h:126
fan4_generic_write
void fan4_generic_write(fan4_t *ctx, uint8_t cmd)
Generic write function.
fan4_default_cfg
void fan4_default_cfg(fan4_t *ctx)
Click Default Configuration function.
fan4_cfg_t::sda
pin_name_t sda
Definition: fan4.h:131
fan4_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: fan4.h:135
fan4_generic_read
void fan4_generic_read(fan4_t *ctx, uint8_t *data_out)
Generic read function.