42#ifdef PREINIT_SUPPORTED
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
52#include "drv_digital_in.h"
53#include "drv_i2c_master.h"
70#define FAN2_REG_CTRL1 0x0
71#define FAN2_REG_CTRL2 0x1
72#define FAN2_REG_CTRL3 0x2
73#define FAN2_REG_FF_DUTY_CYCLE 0x3
74#define FAN2_REG_ALERT_MASK 0x4
75#define FAN2_REG_IDEALITY_FACTOR 0x5
76#define FAN2_REG_REMOTE_HIGH_SETPOINT 0x6
77#define FAN2_REG_LOCAL_OVERTEMP_SETPOINT 0x8
78#define FAN2_REG_REMOTE_OVERTEMP_SETPOINT 0xA
79#define FAN2_REG_LOCAL_HIGH_SETPOINT 0xC
80#define FAN2_REG_TACH_CNT_THRSH 0xE
81#define FAN2_REG_GENERAL_PURPOSE_FIRST_MEM 0x10
82#define FAN2_REG_GENERAL_PURPOSE_LAST_MEM 0x17
83#define FAN2_REG_LUT_START 0x20
84#define FAN2_REG_LUT_END 0x4F
85#define FAN2_REG_DIRECT_DUTY_CYCLE_CTRL 0x50
86#define FAN2_REG_CURRENT_PWM_DUTY_CYCLE 0x51
87#define FAN2_REG_TACH1_CNT 0x52
88#define FAN2_REG_TACH2_CNT 0x54
89#define FAN2_REG_REMOTE_TEMP_READ 0x56
90#define FAN2_REG_LOCAL_TEMP_READ 0x58
91#define FAN2_REG_STATUS 0x5A
92#define FAN2_REG_EEPROM_TO_RAM 0x5B
104#define FAN2_CTRL1_MASK_TEMP_ALERTS 0x80
105#define FAN2_CTRL1_SW_POR 0x40
106#define FAN2_CTRL1_LUT_HYST_2_CELS 0x0
107#define FAN2_CTRL1_LUT_HYST_4_CELS 0x20
108#define FAN2_CTRL1_PWM_FREQ_33_HZ 0x0
109#define FAN2_CTRL1_PWM_FREQ_150_HZ 0x8
110#define FAN2_CTRL1_PWM_FREQ_1500_HZ 0x10
111#define FAN2_CTRL1_PWM_FREQ_25_KHZ 0x18
112#define FAN2_CTRL1_PWM_POL_POS 0x0
113#define FAN2_CTRL1_PWM_POL_NEG 0x4
114#define FAN2_CTRL1_TEMP_IDX_TIS 0x0
115#define FAN2_CTRL1_TEMP_IDX_GREATER 0x2
116#define FAN2_CTRL1_LUT_IDX_LOCAL_TEMP 0x0
117#define FAN2_CTRL1_LUT_IDX_REMOTE_TEMP 0x1
124#define FAN2_CTRL2_NORMAL_MODE 0x0
125#define FAN2_CTRL2_STANDBY_MODE 0x80
126#define FAN2_CTRL2_ALERT_INTERR 0x0
127#define FAN2_CTRL2_ALERT_COMP 0x40
128#define FAN2_CTRL2_SPIN_UP_EN 0x20
129#define FAN2_CTRL2_FF_OUTPUT_INTERR 0x0
130#define FAN2_CTRL2_FF_OUTPUT_COMP 0x10
131#define FAN2_CTRL2_FS_INPUT_EN 0x8
132#define FAN2_CTRL2_RD_ACTIVE_LOW 0x0
133#define FAN2_CTRL2_RD_ACTIVE_HIGH 0x4
134#define FAN2_CTRL2_TACHO_SQUARE_WAVE 0x0
135#define FAN2_CTRL2_TACHO_RD 0x2
136#define FAN2_CTRL2_DIRECT_FAN_CTRL_EN 0x1
143#define FAN2_CTRL3_CLR_FAIL 0x80
144#define FAN2_CTRL3_FF_DETECT_EN 0x40
145#define FAN2_CTRL3_PWM_RAMP_RATE_SLOW 0x0
146#define FAN2_CTRL3_PWM_RAMP_RATE_SLOW_MEDIUM 0x10
147#define FAN2_CTRL3_PWM_RAMP_RATE_MEDIUM_FAST 0x20
148#define FAN2_CTRL3_PWM_RAMP_RATE_FAST 0x30
149#define FAN2_CTRL3_TACHFULL_EN 0x8
150#define FAN2_CTRL3_PULSE_STRETCH_EN 0x4
151#define FAN2_CTRL3_TACH2_EN 0x2
152#define FAN2_CTRL3_TACH1_EN 0x1
159#define FAN2_MASK_ALARM_LOCAL_TEMP_HIGH 0x20
160#define FAN2_MASK_ALARM_LOCAL_OVERTEMP 0x10
161#define FAN2_MASK_ALARM_REMOTE_TEMP_HIGH 0x8
162#define FAN2_MASK_ALARM_REMOTE_OVERTEMP 0x4
163#define FAN2_MASK_ALARM_TACH2 0x2
164#define FAN2_MASK_ALARM_TACH1 0x1
165#define FAN2_MASK_ALARM_RESERVED_BITS 0xC0
166#define FAN2_MASK_ALARM_NONE 0x0
173#define FAN2_EEPROM_WRITE 0x0
174#define FAN2_EEPROM_LOAD 0x80
175#define FAN2_EEPROM_40H_TO_4FH 0x10
176#define FAN2_EEPROM_30H_TO_3FH 0x8
177#define FAN2_EEPROM_20H_TO_2FH 0x4
178#define FAN2_EEPROM_10H_TO_1FH 0x2
179#define FAN2_EEPROM_00H_TO_0FH 0x1
193#define FAN2_TEMP_DATA_OFFSET 5
194#define FAN2_TEMP_DATA_MASK 0xFFE0
203#define FAN2_STAT_FLAG_PROGRAM_CORRUPT 0x80
204#define FAN2_STAT_FLAG_REMOTE_DIODE_FAULT 0x40
205#define FAN2_STAT_FLAG_LOCAL_HIGH_TEMP_ALARM 0x20
206#define FAN2_STAT_FLAG_LOCAL_OVERTEMP_ALARM 0x10
207#define FAN2_STAT_FLAG_REMOTE_HIGH_TEMP_ALARM 0x8
208#define FAN2_STAT_FLAG_REMOTE_OVERTEMP_ALARM 0x4
209#define FAN2_STAT_FLAG_TACH2_ALARM 0x2
210#define FAN2_STAT_FLAG_TACH1_ALARM 0x1
224#define FAN2_MAX_TEMP_CELS 125
225#define FAN2_ZERO_TEMP_CELS 0
226#define FAN2_MIN_TEMP_CELS -55
233#define FAN2_MAX_SPEED_PER 100
234#define FAN2_HALF_SPEED_PER 50
235#define FAN2_MIN_SPEED_PER 0
242#define FAN2_LUT_NBYTES 48
251#define FAN2_MAP_MIKROBUS( cfg, mikrobus ) \
252 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
253 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
254 cfg.alr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
255 cfg.shd = MIKROBUS( mikrobus, MIKROBUS_RST ); \
256 cfg.ff = MIKROBUS( mikrobus, MIKROBUS_CS ); \
257 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
uint8_t fan2_get_ff_pin(fan2_t *ctx)
Fan-Failure Pin Check function.
fan2_err_t fan2_write_temp(fan2_t *ctx, uint8_t temp_addr, float temp_cels)
Temperature Write function.
uint8_t fan2_get_int_pin(fan2_t *ctx)
Fault Pin Check function.
fan2_err_t fan2_direct_speed_control(fan2_t *ctx, float speed_per)
Direct Fan Speed Control function.
fan2_err_t fan2_generic_write_word(fan2_t *ctx, uint8_t reg_addr, uint16_t data_in)
Generic Word Write function.
fan2_err_t fan2_generic_read_word(fan2_t *ctx, uint8_t reg_addr, uint16_t *data_out)
Generic Word Read function.
void fan2_cfg_setup(fan2_cfg_t *cfg)
Configuration Object Initialization function.
uint8_t fan2_get_shd_pin(fan2_t *ctx)
Shutdown Pin Check function.
fan2_err_t fan2_generic_read_byte(fan2_t *ctx, uint8_t reg_addr, uint8_t *data_out)
Generic Byte Read function.
fan2_err_t fan2_read_tacho(fan2_t *ctx, uint8_t tacho_addr, uint16_t *tacho_rpm)
Tachometer Read function.
uint8_t fan2_status(fan2_t *ctx, uint8_t flag_mask)
Status Check function.
void fan2_write_tacho_threshold(fan2_t *ctx, uint32_t tacho_rpm)
Tachometer Threshold Write function.
void fan2_sw_reset(fan2_t *ctx)
Software Reset function.
float fan2_read_current_speed(fan2_t *ctx)
Current Fan Speed Read function.
uint8_t fan2_get_alr_pin(fan2_t *ctx)
Alert Pin Check function.
void fan2_default_cfg(fan2_t *ctx)
Click Default Configuration function.
fan2_err_t fan2_read_temp(fan2_t *ctx, uint8_t temp_addr, float *temp_cels)
Temperature Read function.
fan2_err_t fan2_generic_write_byte(fan2_t *ctx, uint8_t reg_addr, uint8_t data_in)
Generic Byte Write function.
fan2_err_t fan2_write_lut(fan2_t *ctx, uint8_t lut_addr, uint8_t *lut_data, uint8_t n_data)
Lookup Table Write function.
fan2_err_t fan2_init(fan2_t *ctx, fan2_cfg_t *cfg)
Click Initialization function.
fan2_i2c_addr_t
Click I2C address selection.
Definition fan2.h:286
fan2_err_t
Click error code definition.
Definition fan2.h:271
@ FAN2_I2C_ADDR_111
Definition fan2.h:294
@ FAN2_I2C_ADDR_001
Definition fan2.h:288
@ FAN2_I2C_ADDR_000
Definition fan2.h:287
@ FAN2_I2C_ADDR_010
Definition fan2.h:289
@ FAN2_I2C_ADDR_101
Definition fan2.h:292
@ FAN2_I2C_ADDR_110
Definition fan2.h:293
@ FAN2_I2C_ADDR_100
Definition fan2.h:291
@ FAN2_I2C_ADDR_011
Definition fan2.h:290
@ FAN2_ERR_NDATA
Definition fan2.h:276
@ FAN2_ERR_PWM_DUTY_RANGE
Definition fan2.h:278
@ FAN2_ERR_REG_ADDR
Definition fan2.h:275
@ FAN2_ERR_TEMP_RANGE
Definition fan2.h:277
@ FAN2_ERR_UNSUPPORTED_PIN
Definition fan2.h:274
@ FAN2_ERR_INIT_DRV
Definition fan2.h:273
@ FAN2_OK
Definition fan2.h:272
Click configuration structure definition.
Definition fan2.h:321
uint8_t i2c_addr
Definition fan2.h:334
pin_name_t alr
Definition fan2.h:327
uint32_t i2c_speed
Definition fan2.h:333
pin_name_t ff
Definition fan2.h:329
pin_name_t shd
Definition fan2.h:328
pin_name_t scl
Definition fan2.h:323
pin_name_t int_pin
Definition fan2.h:330
pin_name_t sda
Definition fan2.h:324
Click context object definition.
Definition fan2.h:302
digital_in_t alr
Definition fan2.h:304
digital_in_t int_pin
Definition fan2.h:307
digital_in_t ff
Definition fan2.h:306
i2c_master_t i2c
Definition fan2.h:310
uint8_t slave_addr
Definition fan2.h:313
digital_in_t shd
Definition fan2.h:305