fan5  2.1.0.0
fan5.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 FAN5_H
29 #define FAN5_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_i2c_master.h"
48 
69 #define FAN5_RPM1_REG 0x00
70 #define FAN5_RPM2_REG 0x01
71 #define FAN5_FAN_FAULT1_REG 0x02
72 #define FAN5_FAN_FAULT2_REG 0x03
73 #define FAN5_CONFIG_REG 0x04
74 #define FAN5_STATUS_REG 0x05
75 #define FAN5_DUTY_CYCLE_REG 0x06
76 #define FAN5_MFR_ID_REG 0x07
77 #define FAN5_VER_ID_REG 0x08
78  // fan5_reg
80 
95 #define FAN5_CLEAR_FLT 0x80
96 #define FAN5_8_BIT_RESOLUTION 0x00
97 #define FAN5_9_BIT_RESOLUTION 0x40
98 #define FAN5_VOUT_BASED_ON_DYTY_REG 0x20
99 #define FAN5_VOUT_BASED_ON_VIN 0x00
100 #define FAN5_FAN2_PPR_1 0x00
101 #define FAN5_FAN2_PPR_2 0x08
102 #define FAN5_FAN2_PPR_4 0x10
103 #define FAN5_FAN2_PPR_8 0x18
104 #define FAN5_FAN1_PPR_1 0x00
105 #define FAN5_FAN1_PPR_2 0x02
106 #define FAN5_FAN1_PPR_4 0x04
107 #define FAN5_FAN1_PPR_8 0x06
108 #define FAN5_SHUTDOWN_MODE 0x01
109 #define FAN5_NORMAL_MODE 0x00
110 
111 #define FAN5_MAX_RPM_VALUE 12750
112 
117 #define FAN5_OTF_FLAG 0x20
118 #define FAN5_R2CO_FLAG 0x10
119 #define FAN5_R1CO_FLAG 0x08
120 #define FAN5_VSTAT_FLAG 0x04
121 #define FAN5_F2F_FLAG 0x02
122 #define FAN5_F1F_FLAG 0x01
123 
128 #define FAN5_30_PER_DUTY 0x00
129 #define FAN5_35_PER_DUTY 0x01
130 #define FAN5_40_PER_DUTY 0x02
131 #define FAN5_44_PER_DUTY 0x03
132 #define FAN5_49_PER_DUTY 0x04
133 #define FAN5_53_PER_DUTY 0x05
134 #define FAN5_58_PER_DUTY 0x06
135 #define FAN5_63_PER_DUTY 0x07
136 #define FAN5_67_PER_DUTY 0x08
137 #define FAN5_72_PER_DUTY 0x09
138 #define FAN5_77_PER_DUTY 0x0A
139 #define FAN5_81_PER_DUTY 0x0B
140 #define FAN5_86_PER_DUTY 0x0C
141 #define FAN5_90_PER_DUTY 0x0D
142 #define FAN5_95_PER_DUTY 0x0E
143 #define FAN5_100_PER_DUTY 0x0F
144 
150 #define FAN5_DEVICE_ADDRESS 0x1B
151  // fan5_set
153 
168 #define FAN5_MAP_MIKROBUS( cfg, mikrobus ) \
169  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
170  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
171  cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
172  // fan5_map // fan5
175 
180 typedef struct
181 {
182  // Input pins
183  digital_in_t flt;
185  // Modules
186  i2c_master_t i2c;
188  // I2C slave address
189  uint8_t slave_address;
191 } fan5_t;
192 
197 typedef struct
198 {
199  pin_name_t scl;
200  pin_name_t sda;
202  pin_name_t flt;
204  uint32_t i2c_speed;
205  uint8_t i2c_address;
207 } fan5_cfg_t;
208 
213 typedef enum
214 {
215  FAN5_OK = 0,
217  FAN5_FAULT = -2
218 
220 
237 
251 err_t fan5_init ( fan5_t *ctx, fan5_cfg_t *cfg );
252 
265 err_t fan5_default_cfg ( fan5_t *ctx );
266 
281 err_t fan5_generic_write ( fan5_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
282 
297 err_t fan5_generic_read ( fan5_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
298 
312 err_t fan5_reg_write ( fan5_t *ctx, uint8_t reg, uint8_t data_in );
313 
327 err_t fan5_reg_read ( fan5_t *ctx, uint8_t reg, uint8_t *data_out );
328 
341 err_t fan5_get_mfr_id( fan5_t *ctx, uint8_t *mfr_id );
342 
355 err_t fan5_get_rpm1 ( fan5_t *ctx, uint16_t *fan1_speed );
356 
369 err_t fan5_get_rpm2 ( fan5_t *ctx, uint16_t *fan2_speed );
370 
383 err_t fan5_set_fan_fault1 ( fan5_t *ctx, uint16_t fault1_value );
384 
397 err_t fan5_set_fan_fault2 ( fan5_t *ctx, uint16_t fault2_value );
398 
410 err_t fan5_set_duty_cycle ( fan5_t *ctx, uint8_t duty_cycle );
411 
424 err_t fan5_get_status_flags ( fan5_t *ctx, uint8_t *status_data );
425 
437 
449 
460 err_t fan5_turn_on_fans ( fan5_t *ctx );
461 
472 err_t fan5_turn_off_fans ( fan5_t *ctx );
473 
474 #ifdef __cplusplus
475 }
476 #endif
477 #endif // FAN5_H
478  // fan5
480 
481 // ------------------------------------------------------------------------ END
FAN5_OK
@ FAN5_OK
Definition: fan5.h:215
fan5_generic_read
err_t fan5_generic_read(fan5_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Fan 5 I2C reading function.
fan5_get_status_flags
err_t fan5_get_status_flags(fan5_t *ctx, uint8_t *status_data)
Fan 5 get status flags.
fan5_set_duty_cycle
err_t fan5_set_duty_cycle(fan5_t *ctx, uint8_t duty_cycle)
Fan 5 set duty cycle.
fan5_init
err_t fan5_init(fan5_t *ctx, fan5_cfg_t *cfg)
Fan 5 initialization function.
fan5_turn_on_fans
err_t fan5_turn_on_fans(fan5_t *ctx)
Fan 5 turn on fans.
fan5_return_value_t
fan5_return_value_t
Fan 5 Click return value data.
Definition: fan5.h:214
fan5_set_fan_fault1
err_t fan5_set_fan_fault1(fan5_t *ctx, uint16_t fault1_value)
Fan 5 set FAN1 fault threshold.
fan5_t::slave_address
uint8_t slave_address
Definition: fan5.h:189
fan5_t
Fan 5 Click context object.
Definition: fan5.h:181
fan5_reg_read
err_t fan5_reg_read(fan5_t *ctx, uint8_t reg, uint8_t *data_out)
Fan 5 I2C reading register function.
fan5_get_rpm2
err_t fan5_get_rpm2(fan5_t *ctx, uint16_t *fan2_speed)
Fan 5 get speed of FAN2.
fan5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: fan5.h:204
fan5_get_fault_state
err_t fan5_get_fault_state(fan5_t *ctx)
Fan 5 get fault state.
fan5_cfg_t::i2c_address
uint8_t i2c_address
Definition: fan5.h:205
fan5_set_fan_fault2
err_t fan5_set_fan_fault2(fan5_t *ctx, uint16_t fault2_value)
Fan 5 set FAN2 fault threshold.
fan5_reg_write
err_t fan5_reg_write(fan5_t *ctx, uint8_t reg, uint8_t data_in)
Fan 5 I2C writing into register function.
fan5_cfg_t
Fan 5 Click configuration object.
Definition: fan5.h:198
fan5_get_rpm1
err_t fan5_get_rpm1(fan5_t *ctx, uint16_t *fan1_speed)
Fan 5 get speed of FAN1.
fan5_cfg_setup
void fan5_cfg_setup(fan5_cfg_t *cfg)
Fan 5 configuration object setup function.
fan5_t::i2c
i2c_master_t i2c
Definition: fan5.h:186
fan5_cfg_t::flt
pin_name_t flt
Definition: fan5.h:202
fan5_get_mfr_id
err_t fan5_get_mfr_id(fan5_t *ctx, uint8_t *mfr_id)
Fan 5 read manufacturer identification.
fan5_default_cfg
err_t fan5_default_cfg(fan5_t *ctx)
Fan 5 default configuration function.
fan5_t::flt
digital_in_t flt
Definition: fan5.h:183
FAN5_ERROR
@ FAN5_ERROR
Definition: fan5.h:216
fan5_cfg_t::scl
pin_name_t scl
Definition: fan5.h:199
fan5_generic_write
err_t fan5_generic_write(fan5_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Fan 5 I2C writing function.
fan5_cfg_t::sda
pin_name_t sda
Definition: fan5.h:200
fan5_clear_flt_flag
err_t fan5_clear_flt_flag(fan5_t *ctx)
Fan 5 clear status flags.
fan5_turn_off_fans
err_t fan5_turn_off_fans(fan5_t *ctx)
Fan 5 turn off fans.
FAN5_FAULT
@ FAN5_FAULT
Definition: fan5.h:217