hwmonitor2  2.1.0.0
hwmonitor2.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 HWMONITOR2_H
29 #define HWMONITOR2_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 HWMONITOR2_REG_CONFIGURATION 0x00
74 #define HWMONITOR2_REG_INT_STATUS_1 0x01
75 #define HWMONITOR2_REG_INT_STATUS_2 0x02
76 #define HWMONITOR2_REG_INT_MASK_1 0x03
77 #define HWMONITOR2_REG_INT_MASK_2 0x04
78 #define HWMONITOR2_REG_FAN_DIVISOR 0x05
79 #define HWMONITOR2_REG_OS_T_RES_CONFIG 0x06
80 #define HWMONITOR2_REG_CONVERSION_RATE 0x07
81 #define HWMONITOR2_REG_CHANNEL_DISABLE 0x08
82 #define HWMONITOR2_REG_INPUT_MODE 0x09
83 #define HWMONITOR2_REG_ADC_CONTROL 0x0A
84 #define HWMONITOR2_REG_CONVERS_RATE_CNT 0x0B
85 #define HWMONITOR2_REG_RAM_IN_0 0x20
86 #define HWMONITOR2_REG_RAM_IN_1 0x21
87 #define HWMONITOR2_REG_RAM_IN_2 0x22
88 #define HWMONITOR2_REG_RAM_IN_3 0x23
89 #define HWMONITOR2_REG_RAM_IN_4 0x24
90 #define HWMONITOR2_REG_RAM_IN_5 0x25
91 #define HWMONITOR2_REG_RAM_IN_6 0x26
92 #define HWMONITOR2_REG_RAM_TEMPERATURE 0x27
93 #define HWMONITOR2_REG_RAM_FAN_1 0x28
94 #define HWMONITOR2_REG_RAM_FAN_2 0x29
95 #define HWMONITOR2_REG_RAM_LIM_IN_0_H 0x2A
96 #define HWMONITOR2_REG_RAM_LIM_IN_0_L 0x2B
97 #define HWMONITOR2_REG_RAM_LIM_IN_1_H 0x2C
98 #define HWMONITOR2_REG_RAM_LIM_IN_1_L 0x2D
99 #define HWMONITOR2_REG_RAM_LIM_IN_2_H 0x2E
100 #define HWMONITOR2_REG_RAM_LIM_IN_2_L 0x2F
101 #define HWMONITOR2_REG_RAM_LIM_IN_3_H 0x30
102 #define HWMONITOR2_REG_RAM_LIM_IN_3_L 0x31
103 #define HWMONITOR2_REG_RAM_LIM_IN_4_H 0x32
104 #define HWMONITOR2_REG_RAM_LIM_IN_4_L 0x33
105 #define HWMONITOR2_REG_RAM_LIM_IN_5_H 0x34
106 #define HWMONITOR2_REG_RAM_LIM_IN_5_L 0x35
107 #define HWMONITOR2_REG_RAM_LIM_IN_6_H 0x36
108 #define HWMONITOR2_REG_RAM_LIM_IN_6_L 0x37
109 #define HWMONITOR2_REG_RAM_LIM_HOT_H 0x38
110 #define HWMONITOR2_REG_RAM_LIM_HOT_L 0x39
111 #define HWMONITOR2_REG_RAM_LIM_TEMP_H 0x3A
112 #define HWMONITOR2_REG_RAM_LIM_TEMP_L 0x3B
113 #define HWMONITOR2_REG_RAM_CURRENT_LIM_FUN_1 0x3C
114 #define HWMONITOR2_REG_RAM_CURRENT_LIM_FUN_2 0x3D
115 #define HWMONITOR2_REG_RAM_MANUFACTURE_ID 0x3E
116 #define HWMONITOR2_REG_RAM_REVISION_ID 0x3F
117  // hwmonitor2_reg
119 
134 #define HWMONITOR2_SET_CONFIG_START_DIS 0x00
135 #define HWMONITOR2_SET_CONFIG_START_EN 0x01
136 #define HWMONITOR2_SET_CONFIG_INT_DIS 0x00
137 #define HWMONITOR2_SET_CONFIG_INT_EN 0x01
138 #define HWMONITOR2_SET_CONFIG_INT_OPEN_DRAIN 0x00
139 #define HWMONITOR2_SET_CONFIG_INT_ACT_LOW 0x01
140 #define HWMONITOR2_SET_CONFIG_INT_CLR_DIS 0x00
141 #define HWMONITOR2_SET_CONFIG_INT_CLR_EN 0x01
142 #define HWMONITOR2_SET_CONFIG_CHA_NCLR_GPI 0x00
143 #define HWMONITOR2_SET_CONFIG_CHA_GPI 0x01
144 #define HWMONITOR2_SET_CONFIG_GPO_LOW 0x00
145 #define HWMONITOR2_SET_CONFIG_GPO_HIGH 0x01
146 #define HWMONITOR2_SET_CONFIG_PWR_ON 0x00
147 #define HWMONITOR2_SET_CONFIG_PWR_DIS 0x01
148 
153 #define HWMONITOR2_SET_FAN1_MODE_COUNT 0x00
154 #define HWMONITOR2_SET_FAN1_MODE_SENS_INPUT 0x01
155 #define HWMONITOR2_SET_FAN2_MODE_COUNT 0x00
156 #define HWMONITOR2_SET_FAN2_MODE_SENS_INPUT 0x02
157 #define HWMONITOR2_SET_FAN1_CTRL_SPEED_DIV1 0x00
158 #define HWMONITOR2_SET_FAN1_CTRL_SPEED_DIV2 0x04
159 #define HWMONITOR2_SET_FAN1_CTRL_SPEED_DIV4 0x08
160 #define HWMONITOR2_SET_FAN1_CTRL_SPEED_DIV8 0x0C
161 #define HWMONITOR2_SET_FAN2_CTRL_SPEED_DIV1 0x00
162 #define HWMONITOR2_SET_FAN2_CTRL_SPEED_DIV2 0x10
163 #define HWMONITOR2_SET_FAN2_CTRL_SPEED_DIV4 0x20
164 #define HWMONITOR2_SET_FAN2_CTRL_SPEED_DIV8 0x30
165 #define HWMONITOR2_SET_MODE_OS_DISABLE 0x00
166 #define HWMONITOR2_SET_MODE_OS_ENABLE 0x01
167 #define HWMONITOR2_SET_MODE_RST_DISABLE 0x00
168 #define HWMONITOR2_SET_MODE_RST_ENABLE 0x01
169 
174 #define HWMONITOR2_SET_TEMP_RES_8_bit 0x00
175 #define HWMONITOR2_SET_TEMP_RES_11_bit 0x01
176 #define HWMONITOR2_TEMP_RES_11_bit_BIT_MASK 0x08
177 
182 #define HWMONITOR2_SET_ALL_CH_ENABLE 0x00
183 #define HWMONITOR2_SET_ALL_CH_DISABLE 0xFF
184 
189 #define HWMONITOR2_MANUFACTURERS_ID 0x80
190 #define HWMONITOR2_STEPPING_DIE_REVISION_ID 0x08
191 
196 #define HWMONITOR2_CH_0 0
197 #define HWMONITOR2_CH_1 1
198 #define HWMONITOR2_CH_2 2
199 #define HWMONITOR2_CH_3 3
200 #define HWMONITOR2_CH_4 4
201 #define HWMONITOR2_CH_5 5
202 #define HWMONITOR2_CH_6 6
203 #define HWMONITOR2_FAN_1 0
204 #define HWMONITOR2_FAN_2 1
205 
211 #define HWMONITOR2_DEVICE_ADDRESS_0 0x28
212 #define HWMONITOR2_DEVICE_ADDRESS_1 0x29
213 #define HWMONITOR2_DEVICE_ADDRESS_2 0x2A
214 #define HWMONITOR2_DEVICE_ADDRESS_3 0x2B
215 #define HWMONITOR2_DEVICE_ADDRESS_4 0x2C
216 #define HWMONITOR2_DEVICE_ADDRESS_5 0x2D
217 #define HWMONITOR2_DEVICE_ADDRESS_6 0x2E
218 #define HWMONITOR2_DEVICE_ADDRESS_7 0x2F
219  // hwmonitor2_set
221 
236 #define HWMONITOR2_MAP_MIKROBUS( cfg, mikrobus ) \
237  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
238  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
239  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
240  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
241  // hwmonitor2_map // hwmonitor2
244 
249 typedef struct
250 {
251  // Output pins
252  digital_out_t rst;
254  // Input pins
255  digital_in_t int_pin;
257  // Modules
258  i2c_master_t i2c;
260  // I2C slave address
261  uint8_t slave_address;
263 } hwmonitor2_t;
264 
269 typedef struct
270 {
271  pin_name_t scl;
272  pin_name_t sda;
274  pin_name_t rst;
275  pin_name_t int_pin;
277  uint32_t i2c_speed;
278  uint8_t i2c_address;
281 
286 typedef struct
287 {
288  uint8_t start;
289  uint8_t int_enable;
290  uint8_t int_pol_sel;
291  uint8_t int_clear;
292  uint8_t chas_clear;
293  uint8_t gpo;
294  uint8_t init;
297 
302 typedef enum
303 {
305  HWMONITOR2_ERROR = -1
306 
308 
325 
340 
354 
369 err_t hwmonitor2_generic_write ( hwmonitor2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
370 
385 err_t hwmonitor2_generic_read ( hwmonitor2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
386 
398 
414 
430 
445 err_t hwmonitor2_get_device_id ( hwmonitor2_t *ctx, uint8_t *manufacture_id, uint8_t *revision_id );
446 
462 err_t hwmonitor2_set_temp_res ( hwmonitor2_t *ctx, uint8_t temp_res );
463 
477 err_t hwmonitor2_set_ch_out ( hwmonitor2_t *ctx, uint8_t ch_out );
478 
492 err_t hwmonitor2_get_temperature ( hwmonitor2_t *ctx, float *temperature );
493 
508 err_t hwmonitor2_get_analog_inputs ( hwmonitor2_t *ctx, uint8_t ch_pos, float *voltage );
509 
524 err_t hwmonitor2_get_fan_output ( hwmonitor2_t *ctx, uint8_t fan_pos, uint8_t *fan_output );
525 
538 
539 #ifdef __cplusplus
540 }
541 #endif
542 #endif // HWMONITOR2_H
543  // hwmonitor2
545 
546 // ------------------------------------------------------------------------ END
hwmonitor2_config_t::start
uint8_t start
Definition: hwmonitor2.h:288
hwmonitor2_t::int_pin
digital_in_t int_pin
Definition: hwmonitor2.h:255
hwmonitor2_get_fan_output
err_t hwmonitor2_get_fan_output(hwmonitor2_t *ctx, uint8_t fan_pos, uint8_t *fan_output)
HW Monitor 2 gets FAN output function.
hwmonitor2_config_t::gpo
uint8_t gpo
Definition: hwmonitor2.h:293
hwmonitor2_get_analog_inputs
err_t hwmonitor2_get_analog_inputs(hwmonitor2_t *ctx, uint8_t ch_pos, float *voltage)
HW Monitor 2 gets analog inputs voltage function.
hwmonitor2_get_device_id
err_t hwmonitor2_get_device_id(hwmonitor2_t *ctx, uint8_t *manufacture_id, uint8_t *revision_id)
HW Monitor 2 gets device ID function.
HWMONITOR2_OK
@ HWMONITOR2_OK
Definition: hwmonitor2.h:304
hwmonitor2_get_int_pin
uint8_t hwmonitor2_get_int_pin(hwmonitor2_t *ctx)
HW Monitor 2 gets interrupt function.
hwmonitor2_get_config
err_t hwmonitor2_get_config(hwmonitor2_t *ctx, hwmonitor2_config_t *config)
HW Monitor 2 gets configuration function.
hwmonitor2_cfg_t::sda
pin_name_t sda
Definition: hwmonitor2.h:272
hwmonitor2_generic_read
err_t hwmonitor2_generic_read(hwmonitor2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
HW Monitor 2 I2C reading function.
hwmonitor2_set_temp_res
err_t hwmonitor2_set_temp_res(hwmonitor2_t *ctx, uint8_t temp_res)
HW Monitor 2 set temperature resolution function.
hwmonitor2_get_temperature
err_t hwmonitor2_get_temperature(hwmonitor2_t *ctx, float *temperature)
HW Monitor 2 gets temperature function.
hwmonitor2_cfg_setup
void hwmonitor2_cfg_setup(hwmonitor2_cfg_t *cfg)
HW Monitor 2 configuration object setup function.
hwmonitor2_t
HW Monitor 2 Click context object.
Definition: hwmonitor2.h:250
hwmonitor2_default_cfg
err_t hwmonitor2_default_cfg(hwmonitor2_t *ctx)
HW Monitor 2 default configuration function.
hwmonitor2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: hwmonitor2.h:277
hwmonitor2_reset
void hwmonitor2_reset(hwmonitor2_t *ctx)
HW Monitor 2 reset function.
hwmonitor2_cfg_t::scl
pin_name_t scl
Definition: hwmonitor2.h:271
hwmonitor2_cfg_t::rst
pin_name_t rst
Definition: hwmonitor2.h:274
hwmonitor2_cfg_t::i2c_address
uint8_t i2c_address
Definition: hwmonitor2.h:278
hwmonitor2_t::rst
digital_out_t rst
Definition: hwmonitor2.h:252
hwmonitor2_generic_write
err_t hwmonitor2_generic_write(hwmonitor2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
HW Monitor 2 I2C writing function.
hwmonitor2_config_t
HW Monitor 2 Click configuration object.
Definition: hwmonitor2.h:287
hwmonitor2_init
err_t hwmonitor2_init(hwmonitor2_t *ctx, hwmonitor2_cfg_t *cfg)
HW Monitor 2 initialization function.
hwmonitor2_t::i2c
i2c_master_t i2c
Definition: hwmonitor2.h:258
hwmonitor2_config_t::int_clear
uint8_t int_clear
Definition: hwmonitor2.h:291
hwmonitor2_cfg_t
HW Monitor 2 Click configuration object.
Definition: hwmonitor2.h:270
hwmonitor2_t::slave_address
uint8_t slave_address
Definition: hwmonitor2.h:261
hwmonitor2_config_t::int_enable
uint8_t int_enable
Definition: hwmonitor2.h:289
hwmonitor2_config_t::chas_clear
uint8_t chas_clear
Definition: hwmonitor2.h:292
hwmonitor2_set_config
err_t hwmonitor2_set_config(hwmonitor2_t *ctx, hwmonitor2_config_t config)
HW Monitor 2 set the configuration function.
hwmonitor2_return_value_t
hwmonitor2_return_value_t
HW Monitor 2 Click return value data.
Definition: hwmonitor2.h:303
hwmonitor2_set_ch_out
err_t hwmonitor2_set_ch_out(hwmonitor2_t *ctx, uint8_t ch_out)
HW Monitor 2 set voltage/temperature channel function.
HWMONITOR2_ERROR
@ HWMONITOR2_ERROR
Definition: hwmonitor2.h:305
hwmonitor2_config_t::init
uint8_t init
Definition: hwmonitor2.h:294
hwmonitor2_cfg_t::int_pin
pin_name_t int_pin
Definition: hwmonitor2.h:275
hwmonitor2_config_t::int_pol_sel
uint8_t int_pol_sel
Definition: hwmonitor2.h:290