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
32extern "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_i2c_master.h"
52
73#define FAN8_REG_TEMP_CH1 0x00
74#define FAN8_REG_TEMP_CH2 0x01
75#define FAN8_REG_CONFIG_BYTE 0x02
76#define FAN8_REG_CH1_OT_LIMIT 0x03
77#define FAN8_REG_CH2_OT_LIMIT 0x04
78#define FAN8_REG_OT_STATUS 0x05
79#define FAN8_REG_OT_MASK 0x06
80#define FAN8_REG_PWM1_START_DC 0x07
81#define FAN8_REG_PWM2_START_DC 0x08
82#define FAN8_REG_PWM1_MAX_DC 0x09
83#define FAN8_REG_PWM2_MAX_DC 0x0A
84#define FAN8_REG_PWM1_TARGET_DC 0x0B
85#define FAN8_REG_PWM2_TARGET_DC 0x0C
86#define FAN8_REG_PWM1_INSTANTANEOUS_DC 0x0D
87#define FAN8_REG_PWM2_INSTANTANEOUS_DC 0x0E
88#define FAN8_REG_CH1_FAN_START_TEMP 0x0F
89#define FAN8_REG_CH2_FAN_START_TEMP 0x10
90#define FAN8_REG_FAN_CONFIGURATION 0x11
91#define FAN8_REG_DC_ROC 0x12
92#define FAN8_REG_DC_STEP_SIZE 0x13
93#define FAN8_REG_PWM_FREQ_SEL 0x14
94#define FAN8_REG_THERMISTOR_OFFSET 0x17
95#define FAN8_REG_TACH1_VALUE 0x18
96#define FAN8_REG_TACH2_VALUE 0x19
97#define FAN8_REG_TACH1_LIMIT 0x1A
98#define FAN8_REG_TACH2_LIMIT 0x1B
99#define FAN8_REG_FAN_STATUS_BYTE 0x1C
100#define FAN8_REG_CH1_TEMP_LSB 0x1E
101#define FAN8_REG_CH2_TEMP_LSB 0x1F
102#define FAN8_REG_DEVICE_REV 0xFD
103#define FAN8_REG_DEVICE_ID 0xFE
104#define FAN8_REG_MANUFACTURER_ID 0xFF
105
106 // fan8_reg
107
122#define FAN8_DEVICE_ID 0x68
123
128#define FAN8_RESET 0x40
129
134#define FAN8_FAN_CHANNEL_1 0x01
135#define FAN8_FAN_CHANNEL_2 0x02
136
141#define FAN8_FAN_CHANNEL_1 0x01
142#define FAN8_FAN_CHANNEL_2 0x02
143
148#define FAN8_TEMP_CHANNEL_1 0x01
149#define FAN8_TEMP_CHANNEL_2 0x02
150
155#define FAN8_TEMPERATURE_RESOLUTION 0.125
156
161#define FAN8_MAX_DUTY_CYCLE 240
162#define FAN8_MIN_DUTY_CYCLE 0
163#define FAN8_DUTY_CYCLE_STEP_2 2
164#define FAN8_DUTY_CYCLE_STEP_4 4
165#define FAN8_DUTY_CYCLE_STEP_6 6
166#define FAN8_DUTY_CYCLE_STEP_8 8
167#define FAN8_DUTY_CYCLE_STEP_10 10
168#define FAN8_DUTY_CYCLE_STEP_12 12
169#define FAN8_DUTY_CYCLE_STEP_14 14
170#define FAN8_DUTY_CYCLE_STEP_16 16
171
176#define FAN8_CLOCK_COUNTER_FREQ 1950
177#define FAN8_SEC_PER_MIN 60
178#define FAN8_2_PULSES_PER_REVOLUTION 2
179#define FAN8_MAX_TACH_VALUE 255
180
186#define FAN8_DEV_ADDR_ADD0_GND_ADD1_GND 0x18
187#define FAN8_DEV_ADDR_ADD0_GND_ADD1_HIGH_Z 0x19
188#define FAN8_DEV_ADDR_ADD0_GND_ADD1_VCC 0x1A
189#define FAN8_DEV_ADDR_ADD0_HIGH_Z_ADD1_GND 0x29
190#define FAN8_DEV_ADDR_ADD0_HIGH_Z_ADD1_HIGH_Z 0x2A
191#define FAN8_DEV_ADDR_ADD0_HIGH_Z_ADD1_VCC 0x2B
192#define FAN8_DEV_ADDR_ADD0_VCC_ADD1_GND 0x4C
193#define FAN8_DEV_ADDR_ADD0_VCC_ADD1_HIGH_Z 0x4D
194#define FAN8_DEV_ADDR_ADD0_VCC_ADD1_VCC 0x4E
195
196 // fan8_set
197
212#define FAN8_MAP_MIKROBUS( cfg, mikrobus ) \
213 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
214 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
215 cfg.ot = MIKROBUS( mikrobus, MIKROBUS_AN ); \
216 cfg.fan_fail = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
217 cfg.fault = MIKROBUS( mikrobus, MIKROBUS_INT )
218
219 // fan8_map
220 // fan8
221
226typedef struct
227{
228 // Input pins
229 digital_in_t ot;
230 digital_in_t fan_fail;
231 digital_in_t fault;
233 // Modules
234 i2c_master_t i2c;
236 // I2C slave address
239} fan8_t;
240
245typedef struct
246{
247 pin_name_t scl;
248 pin_name_t sda;
250 pin_name_t ot;
251 pin_name_t fan_fail;
252 pin_name_t fault;
254 uint32_t i2c_speed;
255 uint8_t i2c_address;
257} fan8_cfg_t;
258
263typedef enum
264{
266 FAN8_ERROR = -1
267
269
286
301err_t fan8_init ( fan8_t *ctx, fan8_cfg_t *cfg );
302
317
331err_t fan8_write_register ( fan8_t *ctx, uint8_t reg, uint8_t data_in );
332
346err_t fan8_read_register ( fan8_t *ctx, uint8_t reg, uint8_t *data_out );
347
357
367
377
390
407err_t fan8_set_duty_cycle ( fan8_t *ctx, uint8_t fan_ch, uint8_t duty_cycle );
408
426err_t fan8_measure_rpm ( fan8_t *ctx, uint8_t fan_ch, uint8_t num_pulses, uint16_t *fan_rpm );
427
445err_t fan8_read_temperature ( fan8_t *ctx, uint8_t temp_ch, float *temperature );
446
458err_t fan8_reset ( fan8_t *ctx );
459
460#ifdef __cplusplus
461}
462#endif
463#endif // FAN8_H
464
465 // fan8
466
467// ------------------------------------------------------------------------ END
fan8_return_value_t
FAN 8 Click return value data.
Definition fan8.h:264
@ FAN8_ERROR
Definition fan8.h:266
@ FAN8_OK
Definition fan8.h:265
err_t fan8_read_register(fan8_t *ctx, uint8_t reg, uint8_t *data_out)
FAN 8 read register function.
void fan8_cfg_setup(fan8_cfg_t *cfg)
FAN 8 configuration object setup function.
err_t fan8_write_register(fan8_t *ctx, uint8_t reg, uint8_t data_in)
FAN 8 write register function.
err_t fan8_read_temperature(fan8_t *ctx, uint8_t temp_ch, float *temperature)
FAN 8 read temperature function.
uint8_t fan8_check_overtemperature_indicator(fan8_t *ctx)
FAN 8 check overtemperature indicator function.
uint8_t fan8_check_fan_fail_indicator(fan8_t *ctx)
FAN 8 check fan fail indicator function.
err_t fan8_set_duty_cycle(fan8_t *ctx, uint8_t fan_ch, uint8_t duty_cycle)
FAN 8 set duty cycle function.
uint8_t fan8_check_fault_indicator(fan8_t *ctx)
FAN 8 check fault indicator function.
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.
err_t fan8_default_cfg(fan8_t *ctx)
FAN 8 default configuration function.
err_t fan8_reset(fan8_t *ctx)
FAN 8 reset function.
err_t fan8_init(fan8_t *ctx, fan8_cfg_t *cfg)
FAN 8 initialization function.
err_t fan8_check_device_id(fan8_t *ctx)
FAN 8 check device ID function.
FAN 8 Click configuration object.
Definition fan8.h:246
uint32_t i2c_speed
Definition fan8.h:254
pin_name_t fan_fail
Definition fan8.h:251
pin_name_t scl
Definition fan8.h:247
pin_name_t sda
Definition fan8.h:248
pin_name_t ot
Definition fan8.h:250
pin_name_t fault
Definition fan8.h:252
uint8_t i2c_address
Definition fan8.h:255
FAN 8 Click context object.
Definition fan8.h:227
digital_in_t ot
Definition fan8.h:229
digital_in_t fan_fail
Definition fan8.h:230
i2c_master_t i2c
Definition fan8.h:234
digital_in_t fault
Definition fan8.h:231
uint8_t slave_address
Definition fan8.h:237