hwmonitor  2.1.0.0
hwmonitor.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 HWMONITOR_H
29 #define HWMONITOR_H
30 
31 #ifdef __cplusplus
32 extern "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 HWMONITOR_REG_CONFIGURATION 0x00
74 #define HWMONITOR_REG_INT_STATUS_1 0x01
75 #define HWMONITOR_REG_INT_STATUS_2 0x02
76 #define HWMONITOR_REG_INT_MASK_1 0x03
77 #define HWMONITOR_REG_INT_MASK_2 0x04
78 #define HWMONITOR_REG_FAN_DIVISOR 0x05
79 #define HWMONITOR_REG_OS_T_RES_CONFIG 0x06
80 #define HWMONITOR_REG_CONVERSION_RATE 0x07
81 #define HWMONITOR_REG_CHANNEL_DISABLE 0x08
82 #define HWMONITOR_REG_RAM_IN_0 0x20
83 #define HWMONITOR_REG_RAM_IN_1 0x21
84 #define HWMONITOR_REG_RAM_IN_2 0x22
85 #define HWMONITOR_REG_RAM_IN_3 0x23
86 #define HWMONITOR_REG_RAM_IN_4 0x24
87 #define HWMONITOR_REG_RAM_IN_5 0x25
88 #define HWMONITOR_REG_RAM_IN_6 0x26
89 #define HWMONITOR_REG_RAM_TEMPERATURE 0x27
90 #define HWMONITOR_REG_RAM_FAN_1 0x28
91 #define HWMONITOR_REG_RAM_FAN_2 0x29
92 #define HWMONITOR_REG_RAM_LIM_IN_0_H 0x2A
93 #define HWMONITOR_REG_RAM_LIM_IN_0_L 0x2B
94 #define HWMONITOR_REG_RAM_LIM_IN_1_H 0x2C
95 #define HWMONITOR_REG_RAM_LIM_IN_1_L 0x2D
96 #define HWMONITOR_REG_RAM_LIM_IN_2_H 0x2E
97 #define HWMONITOR_REG_RAM_LIM_IN_2_L 0x2F
98 #define HWMONITOR_REG_RAM_LIM_IN_3_H 0x30
99 #define HWMONITOR_REG_RAM_LIM_IN_3_L 0x31
100 #define HWMONITOR_REG_RAM_LIM_IN_4_H 0x32
101 #define HWMONITOR_REG_RAM_LIM_IN_4_L 0x33
102 #define HWMONITOR_REG_RAM_LIM_IN_5_H 0x34
103 #define HWMONITOR_REG_RAM_LIM_IN_5_L 0x35
104 #define HWMONITOR_REG_RAM_LIM_IN_6_H 0x36
105 #define HWMONITOR_REG_RAM_LIM_IN_6_L 0x37
106 #define HWMONITOR_REG_RAM_LIM_HOT_H 0x38
107 #define HWMONITOR_REG_RAM_LIM_HOT_L 0x39
108 #define HWMONITOR_REG_RAM_LIM_TEMP_H 0x3A
109 #define HWMONITOR_REG_RAM_LIM_TEMP_L 0x3B
110 #define HWMONITOR_REG_RAM_CURRENT_LIM_FUN_1 0x3C
111 #define HWMONITOR_REG_RAM_CURRENT_LIM_FUN_2 0x3D
112 #define HWMONITOR_REG_RAM_MANUFACTURE_ID 0x3E
113 #define HWMONITOR_REG_RAM_REVISION_ID 0x3F
114  // hwmonitor_reg
116 
131 #define HWMONITOR_SET_CONFIG_START_DIS 0x00
132 #define HWMONITOR_SET_CONFIG_START_EN 0x01
133 #define HWMONITOR_SET_CONFIG_INT_DIS 0x00
134 #define HWMONITOR_SET_CONFIG_INT_EN 0x01
135 #define HWMONITOR_SET_CONFIG_INT_OPEN_DRAIN 0x00
136 #define HWMONITOR_SET_CONFIG_INT_ACT_LOW 0x01
137 #define HWMONITOR_SET_CONFIG_INT_CLR_DIS 0x00
138 #define HWMONITOR_SET_CONFIG_INT_CLR_EN 0x01
139 #define HWMONITOR_SET_CONFIG_CHA_NCLR_GPI 0x00
140 #define HWMONITOR_SET_CONFIG_CHA_GPI 0x01
141 #define HWMONITOR_SET_CONFIG_GPO_LOW 0x00
142 #define HWMONITOR_SET_CONFIG_GPO_HIGH 0x01
143 #define HWMONITOR_SET_CONFIG_PWR_ON 0x00
144 #define HWMONITOR_SET_CONFIG_PWR_DIS 0x01
145 
150 #define HWMONITOR_SET_FAN1_MODE_COUNT 0x00
151 #define HWMONITOR_SET_FAN1_MODE_SENS_INPUT 0x01
152 #define HWMONITOR_SET_FAN2_MODE_COUNT 0x00
153 #define HWMONITOR_SET_FAN2_MODE_SENS_INPUT 0x02
154 #define HWMONITOR_SET_FAN1_CTRL_SPEED_DIV1 0x00
155 #define HWMONITOR_SET_FAN1_CTRL_SPEED_DIV2 0x04
156 #define HWMONITOR_SET_FAN1_CTRL_SPEED_DIV4 0x08
157 #define HWMONITOR_SET_FAN1_CTRL_SPEED_DIV8 0x0C
158 #define HWMONITOR_SET_FAN2_CTRL_SPEED_DIV1 0x00
159 #define HWMONITOR_SET_FAN2_CTRL_SPEED_DIV2 0x10
160 #define HWMONITOR_SET_FAN2_CTRL_SPEED_DIV4 0x20
161 #define HWMONITOR_SET_FAN2_CTRL_SPEED_DIV8 0x30
162 #define HWMONITOR_SET_MODE_OS_DISABLE 0x00
163 #define HWMONITOR_SET_MODE_OS_ENABLE 0x01
164 #define HWMONITOR_SET_MODE_RST_DISABLE 0x00
165 #define HWMONITOR_SET_MODE_RST_ENABLE 0x01
166 
171 #define HWMONITOR_SET_TEMP_RES_8_bit 0x00
172 #define HWMONITOR_SET_TEMP_RES_11_bit 0x01
173 #define HWMONITOR_TEMP_RES_11_bit_BIT_MASK 0x08
174 
179 #define HWMONITOR_SET_ALL_CH_ENABLE 0x00
180 #define HWMONITOR_SET_ALL_CH_DISABLE 0xFF
181 
186 #define HWMONITOR_MANUFACTURERS_ID 0x01
187 #define HWMONITOR_STEPPING_DIE_REVISION_ID 0x08
188 
193 #define HWMONITOR_IN_0 0
194 #define HWMONITOR_IN_1 1
195 #define HWMONITOR_IN_2 2
196 #define HWMONITOR_IN_3 3
197 #define HWMONITOR_IN_4 4
198 #define HWMONITOR_IN_5 5
199 #define HWMONITOR_IN_6 6
200 #define HWMONITOR_FAN_1 0
201 #define HWMONITOR_FAN_2 1
202 
208 #define HWMONITOR_DEVICE_ADDRESS_0 0x28
209 #define HWMONITOR_DEVICE_ADDRESS_1 0x29
210 #define HWMONITOR_DEVICE_ADDRESS_2 0x2A
211 #define HWMONITOR_DEVICE_ADDRESS_3 0x2B
212 #define HWMONITOR_DEVICE_ADDRESS_4 0x2C
213 #define HWMONITOR_DEVICE_ADDRESS_5 0x2D
214 #define HWMONITOR_DEVICE_ADDRESS_6 0x2E
215 #define HWMONITOR_DEVICE_ADDRESS_7 0x2F
216  // hwmonitor_set
218 
233 #define HWMONITOR_MAP_MIKROBUS( cfg, mikrobus ) \
234  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
235  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
236  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
237  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
238  // hwmonitor_map // hwmonitor
241 
246 typedef struct
247 {
248  // Output pins
249  digital_out_t rst;
251  // Input pins
252  digital_in_t int_pin;
254  // Modules
255  i2c_master_t i2c;
257  // I2C slave address
258  uint8_t slave_address;
260 } hwmonitor_t;
261 
266 typedef struct
267 {
268  pin_name_t scl;
269  pin_name_t sda;
271  pin_name_t rst;
272  pin_name_t int_pin;
274  uint32_t i2c_speed;
275  uint8_t i2c_address;
278 
283 typedef struct
284 {
285  uint8_t start;
286  uint8_t int_enable;
287  uint8_t int_pol_sel;
288  uint8_t int_clear;
289  uint8_t chas_clear;
290  uint8_t gpo;
291  uint8_t init;
294 
299 typedef enum
300 {
302  HWMONITOR_ERROR = -1
303 
305 
322 
337 
351 
366 err_t hwmonitor_generic_write ( hwmonitor_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
367 
382 err_t hwmonitor_generic_read ( hwmonitor_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
383 
395 
411 
427 
442 err_t hwmonitor_get_device_id ( hwmonitor_t *ctx, uint8_t *manufacture_id, uint8_t *revision_id );
443 
459 err_t hwmonitor_set_temp_res ( hwmonitor_t *ctx, uint8_t temp_res );
460 
474 err_t hwmonitor_set_ch_out ( hwmonitor_t *ctx, uint8_t ch_out );
475 
489 err_t hwmonitor_get_temperature ( hwmonitor_t *ctx, float *temperature );
490 
505 err_t hwmonitor_get_analog_inputs ( hwmonitor_t *ctx, uint8_t in_pos, float *voltage );
506 
521 err_t hwmonitor_get_fan_output ( hwmonitor_t *ctx, uint8_t fan_pos, uint8_t *fan_output );
522 
538 err_t hwmonitor_set_analog_in_limit ( hwmonitor_t *ctx, uint8_t in_pos, uint16_t upper_limit, uint16_t lower_limit );
539 
552 
553 #ifdef __cplusplus
554 }
555 #endif
556 #endif // HWMONITOR_H
557  // hwmonitor
559 
560 // ------------------------------------------------------------------------ END
hwmonitor_generic_write
err_t hwmonitor_generic_write(hwmonitor_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
HW Monitor I2C writing function.
hwmonitor_set_config
err_t hwmonitor_set_config(hwmonitor_t *ctx, hwmonitor_config_t config)
HW Monitor set the configuration function.
hwmonitor_init
err_t hwmonitor_init(hwmonitor_t *ctx, hwmonitor_cfg_t *cfg)
HW Monitor initialization function.
hwmonitor_get_int_pin
uint8_t hwmonitor_get_int_pin(hwmonitor_t *ctx)
HW Monitor gets interrupt function.
hwmonitor_cfg_t::int_pin
pin_name_t int_pin
Definition: hwmonitor.h:272
hwmonitor_config_t::init
uint8_t init
Definition: hwmonitor.h:291
hwmonitor_t::slave_address
uint8_t slave_address
Definition: hwmonitor.h:258
hwmonitor_config_t::chas_clear
uint8_t chas_clear
Definition: hwmonitor.h:289
hwmonitor_set_analog_in_limit
err_t hwmonitor_set_analog_in_limit(hwmonitor_t *ctx, uint8_t in_pos, uint16_t upper_limit, uint16_t lower_limit)
HW Monitor set analog inputs voltage limits function.
hwmonitor_set_ch_out
err_t hwmonitor_set_ch_out(hwmonitor_t *ctx, uint8_t ch_out)
HW Monitor set voltage/temperature channel function.
hwmonitor_config_t::gpo
uint8_t gpo
Definition: hwmonitor.h:290
hwmonitor_get_temperature
err_t hwmonitor_get_temperature(hwmonitor_t *ctx, float *temperature)
HW Monitor gets temperature function.
hwmonitor_generic_read
err_t hwmonitor_generic_read(hwmonitor_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
HW Monitor I2C reading function.
hwmonitor_default_cfg
err_t hwmonitor_default_cfg(hwmonitor_t *ctx)
HW Monitor default configuration function.
hwmonitor_config_t::int_enable
uint8_t int_enable
Definition: hwmonitor.h:286
hwmonitor_return_value_t
hwmonitor_return_value_t
HW Monitor Click return value data.
Definition: hwmonitor.h:300
hwmonitor_config_t::int_pol_sel
uint8_t int_pol_sel
Definition: hwmonitor.h:287
hwmonitor_cfg_t::scl
pin_name_t scl
Definition: hwmonitor.h:268
HWMONITOR_OK
@ HWMONITOR_OK
Definition: hwmonitor.h:301
hwmonitor_config_t::start
uint8_t start
Definition: hwmonitor.h:285
hwmonitor_t::i2c
i2c_master_t i2c
Definition: hwmonitor.h:255
hwmonitor_cfg_t::sda
pin_name_t sda
Definition: hwmonitor.h:269
hwmonitor_cfg_t::rst
pin_name_t rst
Definition: hwmonitor.h:271
HWMONITOR_ERROR
@ HWMONITOR_ERROR
Definition: hwmonitor.h:302
hwmonitor_get_analog_inputs
err_t hwmonitor_get_analog_inputs(hwmonitor_t *ctx, uint8_t in_pos, float *voltage)
HW Monitor gets analog inputs voltage function.
hwmonitor_config_t
HW Monitor Click configuration object.
Definition: hwmonitor.h:284
hwmonitor_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: hwmonitor.h:274
hwmonitor_t::int_pin
digital_in_t int_pin
Definition: hwmonitor.h:252
hwmonitor_t
HW Monitor Click context object.
Definition: hwmonitor.h:247
hwmonitor_config_t::int_clear
uint8_t int_clear
Definition: hwmonitor.h:288
hwmonitor_t::rst
digital_out_t rst
Definition: hwmonitor.h:249
hwmonitor_set_temp_res
err_t hwmonitor_set_temp_res(hwmonitor_t *ctx, uint8_t temp_res)
HW Monitor set temperature resolution function.
hwmonitor_get_device_id
err_t hwmonitor_get_device_id(hwmonitor_t *ctx, uint8_t *manufacture_id, uint8_t *revision_id)
HW Monitor gets device ID function.
hwmonitor_cfg_t::i2c_address
uint8_t i2c_address
Definition: hwmonitor.h:275
hwmonitor_get_fan_output
err_t hwmonitor_get_fan_output(hwmonitor_t *ctx, uint8_t fan_pos, uint8_t *fan_output)
HW Monitor gets FAN output function.
hwmonitor_cfg_t
HW Monitor Click configuration object.
Definition: hwmonitor.h:267
hwmonitor_cfg_setup
void hwmonitor_cfg_setup(hwmonitor_cfg_t *cfg)
HW Monitor configuration object setup function.
hwmonitor_reset
void hwmonitor_reset(hwmonitor_t *ctx)
HW Monitor reset function.
hwmonitor_get_config
err_t hwmonitor_get_config(hwmonitor_t *ctx, hwmonitor_config_t *config)
HW Monitor gets configuration function.