fan8  2.0.0.0
fan8.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2021 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 FAN8_H
29 #define FAN8_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define FAN8_REG_TEMP_CH1 0x00
60 #define FAN8_REG_TEMP_CH2 0x01
61 #define FAN8_REG_CONFIG_BYTE 0x02
62 #define FAN8_REG_CH1_OT_LIMIT 0x03
63 #define FAN8_REG_CH2_OT_LIMIT 0x04
64 #define FAN8_REG_OT_STATUS 0x05
65 #define FAN8_REG_OT_MASK 0x06
66 #define FAN8_REG_PWM1_START_DC 0x07
67 #define FAN8_REG_PWM2_START_DC 0x08
68 #define FAN8_REG_PWM1_MAX_DC 0x09
69 #define FAN8_REG_PWM2_MAX_DC 0x0A
70 #define FAN8_REG_PWM1_TARGET_DC 0x0B
71 #define FAN8_REG_PWM2_TARGET_DC 0x0C
72 #define FAN8_REG_PWM1_INSTANTANEOUS_DC 0x0D
73 #define FAN8_REG_PWM2_INSTANTANEOUS_DC 0x0E
74 #define FAN8_REG_CH1_FAN_START_TEMP 0x0F
75 #define FAN8_REG_CH2_FAN_START_TEMP 0x10
76 #define FAN8_REG_FAN_CONFIGURATION 0x11
77 #define FAN8_REG_DC_ROC 0x12
78 #define FAN8_REG_DC_STEP_SIZE 0x13
79 #define FAN8_REG_PWM_FREQ_SEL 0x14
80 #define FAN8_REG_THERMISTOR_OFFSET 0x17
81 #define FAN8_REG_TACH1_VALUE 0x18
82 #define FAN8_REG_TACH2_VALUE 0x19
83 #define FAN8_REG_TACH1_LIMIT 0x1A
84 #define FAN8_REG_TACH2_LIMIT 0x1B
85 #define FAN8_REG_FAN_STATUS_BYTE 0x1C
86 #define FAN8_REG_CH1_TEMP_LSB 0x1E
87 #define FAN8_REG_CH2_TEMP_LSB 0x1F
88 #define FAN8_REG_DEVICE_REV 0xFD
89 #define FAN8_REG_DEVICE_ID 0xFE
90 #define FAN8_REG_MANUFACTURER_ID 0xFF
91  // fan8_reg
93 
108 #define FAN8_DEVICE_ID 0x68
109 
114 #define FAN8_RESET 0x40
115 
120 #define FAN8_FAN_CHANNEL_1 0x01
121 #define FAN8_FAN_CHANNEL_2 0x02
122 
127 #define FAN8_FAN_CHANNEL_1 0x01
128 #define FAN8_FAN_CHANNEL_2 0x02
129 
134 #define FAN8_TEMP_CHANNEL_1 0x01
135 #define FAN8_TEMP_CHANNEL_2 0x02
136 
141 #define FAN8_TEMPERATURE_RESOLUTION 0.125
142 
147 #define FAN8_MAX_DUTY_CYCLE 240
148 #define FAN8_MIN_DUTY_CYCLE 0
149 #define FAN8_DUTY_CYCLE_STEP_2 2
150 #define FAN8_DUTY_CYCLE_STEP_4 4
151 #define FAN8_DUTY_CYCLE_STEP_6 6
152 #define FAN8_DUTY_CYCLE_STEP_8 8
153 #define FAN8_DUTY_CYCLE_STEP_10 10
154 #define FAN8_DUTY_CYCLE_STEP_12 12
155 #define FAN8_DUTY_CYCLE_STEP_14 14
156 #define FAN8_DUTY_CYCLE_STEP_16 16
157 
162 #define FAN8_CLOCK_COUNTER_FREQ 1950
163 #define FAN8_SEC_PER_MIN 60
164 #define FAN8_2_PULSES_PER_REVOLUTION 2
165 #define FAN8_MAX_TACH_VALUE 255
166 
172 #define FAN8_DEV_ADDR_ADD0_GND_ADD1_GND 0x18
173 #define FAN8_DEV_ADDR_ADD0_GND_ADD1_HIGH_Z 0x19
174 #define FAN8_DEV_ADDR_ADD0_GND_ADD1_VCC 0x1A
175 #define FAN8_DEV_ADDR_ADD0_HIGH_Z_ADD1_GND 0x29
176 #define FAN8_DEV_ADDR_ADD0_HIGH_Z_ADD1_HIGH_Z 0x2A
177 #define FAN8_DEV_ADDR_ADD0_HIGH_Z_ADD1_VCC 0x2B
178 #define FAN8_DEV_ADDR_ADD0_VCC_ADD1_GND 0x4C
179 #define FAN8_DEV_ADDR_ADD0_VCC_ADD1_HIGH_Z 0x4D
180 #define FAN8_DEV_ADDR_ADD0_VCC_ADD1_VCC 0x4E
181  // fan8_set
183 
198 #define FAN8_MAP_MIKROBUS( cfg, mikrobus ) \
199  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
200  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
201  cfg.ot = MIKROBUS( mikrobus, MIKROBUS_AN ); \
202  cfg.fan_fail = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
203  cfg.fault = MIKROBUS( mikrobus, MIKROBUS_INT )
204  // fan8_map // fan8
207 
212 typedef struct
213 {
214  // Input pins
215  digital_in_t ot;
216  digital_in_t fan_fail;
217  digital_in_t fault;
219  // Modules
220  i2c_master_t i2c;
222  // I2C slave address
223  uint8_t slave_address;
225 } fan8_t;
226 
231 typedef struct
232 {
233  pin_name_t scl;
234  pin_name_t sda;
236  pin_name_t ot;
237  pin_name_t fan_fail;
238  pin_name_t fault;
240  uint32_t i2c_speed;
241  uint8_t i2c_address;
243 } fan8_cfg_t;
244 
249 typedef enum
250 {
251  FAN8_OK = 0,
252  FAN8_ERROR = -1
253 
255 
271 void fan8_cfg_setup ( fan8_cfg_t *cfg );
272 
287 err_t fan8_init ( fan8_t *ctx, fan8_cfg_t *cfg );
288 
302 err_t fan8_default_cfg ( fan8_t *ctx );
303 
317 err_t fan8_write_register ( fan8_t *ctx, uint8_t reg, uint8_t data_in );
318 
332 err_t fan8_read_register ( fan8_t *ctx, uint8_t reg, uint8_t *data_out );
333 
343 
352 uint8_t fan8_check_fan_fail_indicator ( fan8_t *ctx );
353 
362 uint8_t fan8_check_fault_indicator ( fan8_t *ctx );
363 
375 err_t fan8_check_device_id ( fan8_t *ctx );
376 
393 err_t fan8_set_duty_cycle ( fan8_t *ctx, uint8_t fan_ch, uint8_t duty_cycle );
394 
412 err_t fan8_measure_rpm ( fan8_t *ctx, uint8_t fan_ch, uint8_t num_pulses, uint16_t *fan_rpm );
413 
431 err_t fan8_read_temperature ( fan8_t *ctx, uint8_t temp_ch, float *temperature );
432 
444 err_t fan8_reset ( fan8_t *ctx );
445 
446 #ifdef __cplusplus
447 }
448 #endif
449 #endif // FAN8_H
450  // fan8
452 
453 // ------------------------------------------------------------------------ END
fan8_init
err_t fan8_init(fan8_t *ctx, fan8_cfg_t *cfg)
FAN 8 initialization function.
fan8_cfg_setup
void fan8_cfg_setup(fan8_cfg_t *cfg)
FAN 8 configuration object setup function.
fan8_check_fan_fail_indicator
uint8_t fan8_check_fan_fail_indicator(fan8_t *ctx)
FAN 8 check fan fail indicator function.
fan8_check_device_id
err_t fan8_check_device_id(fan8_t *ctx)
FAN 8 check device ID function.
fan8_check_overtemperature_indicator
uint8_t fan8_check_overtemperature_indicator(fan8_t *ctx)
FAN 8 check overtemperature indicator function.
fan8_t
FAN 8 Click context object.
Definition: fan8.h:211
fan8_reset
err_t fan8_reset(fan8_t *ctx)
FAN 8 reset function.
fan8_return_value_t
fan8_return_value_t
FAN 8 Click return value data.
Definition: fan8.h:248
fan8_read_register
err_t fan8_read_register(fan8_t *ctx, uint8_t reg, uint8_t *data_out)
FAN 8 read register function.
fan8_check_fault_indicator
uint8_t fan8_check_fault_indicator(fan8_t *ctx)
FAN 8 check fault indicator function.
fan8_set_duty_cycle
err_t fan8_set_duty_cycle(fan8_t *ctx, uint8_t fan_ch, uint8_t duty_cycle)
FAN 8 set duty cycle function.
fan8_default_cfg
err_t fan8_default_cfg(fan8_t *ctx)
FAN 8 default configuration function.
fan8_measure_rpm
err_t fan8_measure_rpm(fan8_t *ctx, uint8_t fan_ch, uint8_t num_pulses, uint16_t *fan_rpm)
FAN 8 measure fan RPM function.
fan8_cfg_t
FAN 8 Click configuration object.
Definition: fan8.h:230
FAN8_OK
Definition: fan8.h:250
fan8_read_temperature
err_t fan8_read_temperature(fan8_t *ctx, uint8_t temp_ch, float *temperature)
FAN 8 read temperature function.
FAN8_ERROR
Definition: fan8.h:251
fan8_write_register
err_t fan8_write_register(fan8_t *ctx, uint8_t reg, uint8_t data_in)
FAN 8 write register function.