fan4  2.0.0.0
fan4.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * 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  hal_i2c_address_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  hal_i2c_speed_t i2c_speed;
136  hal_i2c_address_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 
169 FAN4_RETVAL fan4_init ( fan4_t *ctx, fan4_cfg_t *cfg );
170 
178 void fan4_default_cfg ( fan4_t *ctx );
179 
186 void fan4_generic_write ( fan4_t *ctx, uint8_t cmd);
187 
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::i2c_address
hal_i2c_address_t i2c_address
Definition: fan4.h:136
fan4_cfg_t::i2c_speed
hal_i2c_speed_t i2c_speed
Definition: fan4.h:135
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_cfg_setup
void fan4_cfg_setup(fan4_cfg_t *cfg)
Config Object Initialization function.
fan4_t::slave_address
hal_i2c_address_t slave_address
Definition: fan4.h:119
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_generic_read
void fan4_generic_read(fan4_t *ctx, uint8_t *data_out)
Generic read function.