fan 2.0.0.0
fan.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef FAN_H
36#define FAN_H
37
38#include "drv_digital_in.h"
39#include "drv_i2c_master.h"
40
41// -------------------------------------------------------------- PUBLIC MACROS
51#define FAN_MAP_MIKROBUS( cfg, mikrobus ) \
52 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
53 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
54 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
61#define FAN_CONFIGURATION 0x20
62#define FAN_STATUS 0x24
63#define FAN_STALL_STATUS 0x25
64#define FAN_SPIN_STATUS 0x26
65#define FAN_DRIVE_FAIL_STATUS 0x27
66#define FAN_INTERRUPT_ENABLE 0x29
67#define FAN_PWM_POLARITY 0x2A
68#define FAN_PWM_OUTPUT_CONFIG 0x2B
69#define FAN_PWM_BASE_FREQ 0x2D
70#define FAN_SETTING 0x30
71#define FAN_DIVIDE 0x31
72#define FAN_CONFIG1 0x32
73#define FAN_CONFIG2 0x33
74#define FAN_GAIN 0x35
75#define FAN_SPINUP 0x36
76#define FAN_MAX_STEP 0x37
77#define FAN_MIN_DRIVE 0x38
78#define FAN_VALID_TACH 0x39
79#define FAN_FAIL_LOW 0x3A
80#define FAN_FAIL_HIGH 0x3B
81#define FAN_TACH_TARGET_LOW 0x3C
82#define FAN_TACH_TARGET_HIGH 0x3D
83#define FAN_TACH_READING_HIGH 0x3E
84#define FAN_TACH_READING_LOW 0x3F
85#define FAN_SOFTWARE_LOCK 0xEF
86#define FAN_PRODUCT_ID 0xFD
87#define FAN_MANUFACTUERE_ID 0xFE
88#define FAN_REVISION 0xFF
89
90#define FAN_RPM_MIN_500 0x00
91#define FAN_RPM_MIN_1000 0x01
92#define FAN_RPM_MIN_2000 0x02
93#define FAN_RPM_MIN_4000 0x03
94#define FAN_EDGE_1_POLE 0x00
95#define FAN_EDGE_2_POLE 0x01
96#define FAN_EDGE_3_POLE 0x02
97#define FAN_EDGE_4_POLE 0x03
98#define FAN_UPDATE_100MS 0x00
99#define FAN_UPDATE_200MS 0x01
100#define FAN_UPDATE_300MS 0x02
101#define FAN_UPDATE_400MS 0x03
102#define FAN_UPDATE_500MS 0x04
103#define FAN_UPDATE_800MS 0x05
104#define FAN_UPDATE_1200MS 0x06
105#define FAN_UPDATE_1600MS 0x07
106#define FAN_DERIVATIVE_NONE 0x00
107#define FAN_DERIVATIVE_BASIC 0x01
108#define FAN_DERIVATIVE_STEP 0x02
109#define FAN_DERIVATIVE_BOTH 0x03
110#define FAN_RPM_0 0x00
111#define FAN_RPM_50 0x01
112#define FAN_RPM_100 0x02
113#define FAN_RPM_200 0x03
114#define FAN_GAIN_1X 0x00
115#define FAN_GAIN_2X 0x01
116#define FAN_GAIN_4X 0x02
117#define FAN_GAIN_8X 0x03
118#define FAN_DRIVE_CNT_DISABLED 0x0
119#define FAN_DRIVE_CNT_16 0x0
120#define FAN_DRIVE_CNT_32 0x0
121#define FAN_DRIVE_CNT_64 0x0
122#define FAN_SPINUP_30PERCENT 0x00
123#define FAN_SPINUP_35PERCENT 0x01
124#define FAN_SPINUP_40PERCENT 0x02
125#define FAN_SPINUP_45PERCENT 0x03
126#define FAN_SPINUP_50PERCENT 0x04
127#define FAN_SPINUP_55PERCENT 0x05
128#define FAN_SPINUP_60PERCENT 0x06
129#define FAN_SPINUP_65PERCENT 0x07
130#define FAN_SPINUP_250MS 0x00
131#define FAN_SPINUP_500MS 0x00
132#define FAN_SPINUP_1S 0x00
133#define FAN_SPINUP_2S 0x00
140#define EN_ALGO ( 1 << 7 )
141#define RANGE ( 1 << 5 ) | ( 1 << 6 )
142#define RANGE_BIT 5
143#define EDGES ( 1 << 3 ) | ( 1 << 4 )
144#define EDGES_BIT 3
145#define UPDATE ( 1 << 0 ) | ( 1 << 1 ) | ( 1 << 2 )
146#define UPDATE_BIT 0
147#define EN_RAMP ( 1 << 6 )
148#define GLITCH_EN ( 1 << 5 )
149#define DER_OPT ( 1 << 3 ) | ( 1 << 4 )
150#define DER_OPT_BIT 3
151#define ERR_RNG ( 1 << 2 ) | ( 1 << 1 )
152#define ERR_RNG_BIT 1
153#define GAIND ( 1 << 5 ) | ( 1 << 4 )
154#define GAIND_BIT 4
155#define GAINI ( 1 << 3 ) | ( 1 << 2 )
156#define GAINI_BIT 2
157#define GAINP ( 1 << 1 ) | ( 1 << 0 )
158#define GAINP_BIT 0
159#define NOKICK ( 1 << 5 )
160#define DRIVE_FAIL_CNT ( 1 << 7 ) | ( 1 << 6 )
161#define DRIVE_FAIL_CNT_BIT 6
162#define SPIN_LVL ( 1 << 4 ) | ( 1 << 3 ) | ( 1 << 2 )
163#define SPIN_LVL_BIT 2
164#define SPINUP_TIME ( 1 << 1 ) | ( 1 << 0 )
165#define SPINUP_TIME_BIT 0
172#define TACH_CONSTANT 3932160
173#define SEC_MIN 60
180#define FAN_DEV_ADDR 0x2F // End group macro
184// --------------------------------------------------------------- PUBLIC TYPES
193typedef struct
194{
197 uint8_t range;
198 uint8_t mul;
199 double frequency;
200 uint8_t fsc_mode;
202
204
208typedef struct
209{
210 uint8_t poles_cfg;
211 uint8_t edges_cfg;
212 uint8_t range_cfg;
213 uint8_t mul_cfg;
215 uint8_t mode_cfg;
216 uint8_t lock_cfg;
217
219
223typedef struct
224{
225 digital_in_t int_pin;
226 i2c_master_t i2c;
230} fan_t;
231
235typedef struct
236{
237 pin_name_t scl;
238 pin_name_t sda;
239 pin_name_t int_pin;
240 uint32_t i2c_speed;
241 uint8_t i2c_address;
244} fan_cfg_t;
245 // End type group
247// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
253#ifdef __cplusplus
254extern "C"{
255#endif
256
267void
269
281err_t
283
298err_t
299fan_init ( fan_t *ctx, fan_cfg_t *cfg );
300
316err_t
317fan_generic_write ( fan_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
318
334err_t
335fan_generic_read ( fan_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
336
350err_t
351fan_write_byte ( fan_t *ctx, uint8_t reg, uint8_t data_in );
352
366err_t
367fan_read_byte ( fan_t *ctx, uint8_t reg, uint8_t *data_out );
368
383err_t
384fan_lock_registers ( fan_t *ctx, uint8_t lock );
385
398err_t
399fan_device_info ( fan_t *ctx, uint8_t *info );
400
416err_t
417fan_set_valid_tach ( fan_t *ctx, uint16_t tach );
418
434err_t
435fan_get_valid_tach ( fan_t *ctx, uint16_t *data_out );
436
453err_t
454fan_get_driveband_fail ( fan_t *ctx, uint16_t *data_out );
455
469err_t
470fan_set_target_tach ( fan_t *ctx, uint16_t tach );
471
485err_t
486fan_get_tach ( fan_t *ctx, uint16_t *data_out );
487
500err_t
501fan_enable_fsc ( fan_t *ctx, uint8_t fsc );
502
516err_t
517fan_set_range ( fan_t *ctx, uint8_t range );
518
534err_t
535fan_set_edges ( fan_t *ctx, uint8_t edges );
536
552err_t
553fan_set_update ( fan_t *ctx, uint8_t update );
554
568err_t
569fan_enable_ramp ( fan_t *ctx, uint8_t ramp_control );
570
584err_t
585fan_enable_glitch ( fan_t *ctx, uint8_t glitch );
586
600err_t
601fan_set_derivative ( fan_t *ctx, uint8_t derivative );
602
617err_t
618fan_set_error_range ( fan_t *ctx, uint8_t error );
619
636err_t
637fan_set_gaind ( fan_t *ctx, uint8_t gain );
638
652err_t
653fan_set_drivefail ( fan_t *ctx, uint8_t count );
654
667err_t
668fan_enable_no_kick ( fan_t *ctx, uint8_t no_kick );
669
684err_t
685fan_set_spin_level ( fan_t *ctx, uint8_t spin );
686
700err_t
701fan_set_spin_time ( fan_t *ctx, uint8_t time );
702
718err_t
719fan_set_max_step ( fan_t *ctx, uint8_t step );
720
736err_t
737fan_set_min_drive ( fan_t *ctx, double min_drive );
738
746void
748
757void
758fan_set_clock ( fan_t *ctx, double freq );
759
773err_t
774fan_device_cfg ( fan_t *ctx, uint8_t cfg );
775
789err_t
790fan_get_status ( fan_t *ctx, uint8_t *data_out );
791
809err_t
810fan_get_stall_status ( fan_t *ctx, uint8_t *data_out );
811
827err_t
828fan_get_spin_status ( fan_t *ctx, uint8_t *data_out );
829
843err_t
844fan_get_drive_fail ( fan_t *ctx, uint8_t *data_out );
845
860err_t
861fan_interrupts ( fan_t *ctx, uint8_t enable );
862
877err_t
878fan_pwm_base ( fan_t *ctx, uint8_t freq );
879
896err_t
897fan_setting ( fan_t *ctx, double percentage );
898
908uint8_t
910
911#ifdef __cplusplus
912}
913#endif
914#endif // FAN_H
915 // End public_function group
918
919// ------------------------------------------------------------------------- END
err_t fan_get_valid_tach(fan_t *ctx, uint16_t *data_out)
Get valid tach function.
err_t fan_default_cfg(fan_t *ctx)
Click Default Configuration function.
err_t fan_generic_write(fan_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Generic write function.
err_t fan_set_edges(fan_t *ctx, uint8_t edges)
Set number of edges on fan function.
err_t fan_get_tach(fan_t *ctx, uint16_t *data_out)
Get tach function.
err_t fan_device_info(fan_t *ctx, uint8_t *info)
Get device info function.
err_t fan_get_stall_status(fan_t *ctx, uint8_t *data_out)
Get fan stall status function.
err_t fan_set_max_step(fan_t *ctx, uint8_t step)
Set maximum step function.
err_t fan_set_drivefail(fan_t *ctx, uint8_t count)
Set drive fail counter function.
err_t fan_read_byte(fan_t *ctx, uint8_t reg, uint8_t *data_out)
Read byte function.
err_t fan_set_min_drive(fan_t *ctx, double min_drive)
Set minimum drive function.
err_t fan_set_target_tach(fan_t *ctx, uint16_t tach)
Set target tach function.
err_t fan_get_spin_status(fan_t *ctx, uint8_t *data_out)
Get spin status function.
err_t fan_set_update(fan_t *ctx, uint8_t update)
Update time function.
err_t fan_set_spin_level(fan_t *ctx, uint8_t spin)
Set spin level function.
void fan_set_clock(fan_t *ctx, double freq)
Set external clock speed function.
err_t fan_set_derivative(fan_t *ctx, uint8_t derivative)
Set derivative function.
err_t fan_generic_read(fan_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Generic read function.
err_t fan_get_drive_fail(fan_t *ctx, uint8_t *data_out)
Get fan drive fail status function.
err_t fan_write_byte(fan_t *ctx, uint8_t reg, uint8_t data_in)
Write byte function.
err_t fan_pwm_base(fan_t *ctx, uint8_t freq)
Set PWM base frequency function.
err_t fan_enable_ramp(fan_t *ctx, uint8_t ramp_control)
Ramp up mode function.
err_t fan_set_gaind(fan_t *ctx, uint8_t gain)
Set gain D function.
err_t fan_enable_no_kick(fan_t *ctx, uint8_t no_kick)
No kick enable function.
err_t fan_init(fan_t *ctx, fan_cfg_t *cfg)
Initialization function.
err_t fan_set_valid_tach(fan_t *ctx, uint16_t tach)
Set valid tach function.
void fan_update_multiplier(fan_t *ctx)
Update multiplier function.
err_t fan_get_driveband_fail(fan_t *ctx, uint16_t *data_out)
Get drive band fail function.
err_t fan_enable_glitch(fan_t *ctx, uint8_t glitch)
Glitch enable function.
err_t fan_set_range(fan_t *ctx, uint8_t range)
Set number of edges that needs to be detected function.
void fan_cfg_setup(fan_cfg_t *cfg)
Config Object Initialization function.
err_t fan_enable_fsc(fan_t *ctx, uint8_t fsc)
Enable fan control algorithm function.
err_t fan_device_cfg(fan_t *ctx, uint8_t cfg)
Fan configuration function.
err_t fan_interrupts(fan_t *ctx, uint8_t enable)
Enable / disable external interrupts function.
err_t fan_setting(fan_t *ctx, double percentage)
Fan setting function.
err_t fan_lock_registers(fan_t *ctx, uint8_t lock)
Fan lock registers function.
err_t fan_set_error_range(fan_t *ctx, uint8_t error)
Set error range function.
uint8_t fan_read_int_pin(fan_t *ctx)
Read INT pin function.
err_t fan_get_status(fan_t *ctx, uint8_t *data_out)
Get fan status function.
err_t fan_set_spin_time(fan_t *ctx, uint8_t time)
Set spin time function.
Click configuration structure definition.
Definition: fan.h:236
fan_setup_cfg_t fan_setup_cfg
Definition: fan.h:242
uint32_t i2c_speed
Definition: fan.h:240
pin_name_t scl
Definition: fan.h:237
pin_name_t int_pin
Definition: fan.h:239
pin_name_t sda
Definition: fan.h:238
uint8_t i2c_address
Definition: fan.h:241
Fan setup configuration.
Definition: fan.h:209
uint8_t mode_cfg
Definition: fan.h:215
uint8_t mul_cfg
Definition: fan.h:213
double frequency_cfg
Definition: fan.h:214
uint8_t range_cfg
Definition: fan.h:212
uint8_t poles_cfg
Definition: fan.h:210
uint8_t edges_cfg
Definition: fan.h:211
uint8_t lock_cfg
Definition: fan.h:216
Fan setup definition.
Definition: fan.h:194
uint8_t fsc_mode
Definition: fan.h:200
uint8_t mul
Definition: fan.h:198
double frequency
Definition: fan.h:199
uint8_t software_lock
Definition: fan.h:201
uint8_t number_of_poles
Definition: fan.h:195
uint8_t range
Definition: fan.h:197
uint8_t number_of_edges
Definition: fan.h:196
Click context object definition.
Definition: fan.h:224
digital_in_t int_pin
Definition: fan.h:225
i2c_master_t i2c
Definition: fan.h:226
fan_setup_t fan_setup
Definition: fan.h:228
uint8_t slave_address
Definition: fan.h:227