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 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define HWMONITOR_REG_CONFIGURATION 0x00
70 #define HWMONITOR_REG_INT_STATUS_1 0x01
71 #define HWMONITOR_REG_INT_STATUS_2 0x02
72 #define HWMONITOR_REG_INT_MASK_1 0x03
73 #define HWMONITOR_REG_INT_MASK_2 0x04
74 #define HWMONITOR_REG_FAN_DIVISOR 0x05
75 #define HWMONITOR_REG_OS_T_RES_CONFIG 0x06
76 #define HWMONITOR_REG_CONVERSION_RATE 0x07
77 #define HWMONITOR_REG_CHANNEL_DISABLE 0x08
78 #define HWMONITOR_REG_RAM_IN_0 0x20
79 #define HWMONITOR_REG_RAM_IN_1 0x21
80 #define HWMONITOR_REG_RAM_IN_2 0x22
81 #define HWMONITOR_REG_RAM_IN_3 0x23
82 #define HWMONITOR_REG_RAM_IN_4 0x24
83 #define HWMONITOR_REG_RAM_IN_5 0x25
84 #define HWMONITOR_REG_RAM_IN_6 0x26
85 #define HWMONITOR_REG_RAM_TEMPERATURE 0x27
86 #define HWMONITOR_REG_RAM_FAN_1 0x28
87 #define HWMONITOR_REG_RAM_FAN_2 0x29
88 #define HWMONITOR_REG_RAM_LIM_IN_0_H 0x2A
89 #define HWMONITOR_REG_RAM_LIM_IN_0_L 0x2B
90 #define HWMONITOR_REG_RAM_LIM_IN_1_H 0x2C
91 #define HWMONITOR_REG_RAM_LIM_IN_1_L 0x2D
92 #define HWMONITOR_REG_RAM_LIM_IN_2_H 0x2E
93 #define HWMONITOR_REG_RAM_LIM_IN_2_L 0x2F
94 #define HWMONITOR_REG_RAM_LIM_IN_3_H 0x30
95 #define HWMONITOR_REG_RAM_LIM_IN_3_L 0x31
96 #define HWMONITOR_REG_RAM_LIM_IN_4_H 0x32
97 #define HWMONITOR_REG_RAM_LIM_IN_4_L 0x33
98 #define HWMONITOR_REG_RAM_LIM_IN_5_H 0x34
99 #define HWMONITOR_REG_RAM_LIM_IN_5_L 0x35
100 #define HWMONITOR_REG_RAM_LIM_IN_6_H 0x36
101 #define HWMONITOR_REG_RAM_LIM_IN_6_L 0x37
102 #define HWMONITOR_REG_RAM_LIM_HOT_H 0x38
103 #define HWMONITOR_REG_RAM_LIM_HOT_L 0x39
104 #define HWMONITOR_REG_RAM_LIM_TEMP_H 0x3A
105 #define HWMONITOR_REG_RAM_LIM_TEMP_L 0x3B
106 #define HWMONITOR_REG_RAM_CURRENT_LIM_FUN_1 0x3C
107 #define HWMONITOR_REG_RAM_CURRENT_LIM_FUN_2 0x3D
108 #define HWMONITOR_REG_RAM_MANUFACTURE_ID 0x3E
109 #define HWMONITOR_REG_RAM_REVISION_ID 0x3F
110  // hwmonitor_reg
112 
127 #define HWMONITOR_SET_CONFIG_START_DIS 0x00
128 #define HWMONITOR_SET_CONFIG_START_EN 0x01
129 #define HWMONITOR_SET_CONFIG_INT_DIS 0x00
130 #define HWMONITOR_SET_CONFIG_INT_EN 0x01
131 #define HWMONITOR_SET_CONFIG_INT_OPEN_DRAIN 0x00
132 #define HWMONITOR_SET_CONFIG_INT_ACT_LOW 0x01
133 #define HWMONITOR_SET_CONFIG_INT_CLR_DIS 0x00
134 #define HWMONITOR_SET_CONFIG_INT_CLR_EN 0x01
135 #define HWMONITOR_SET_CONFIG_CHA_NCLR_GPI 0x00
136 #define HWMONITOR_SET_CONFIG_CHA_GPI 0x01
137 #define HWMONITOR_SET_CONFIG_GPO_LOW 0x00
138 #define HWMONITOR_SET_CONFIG_GPO_HIGH 0x01
139 #define HWMONITOR_SET_CONFIG_PWR_ON 0x00
140 #define HWMONITOR_SET_CONFIG_PWR_DIS 0x01
141 
146 #define HWMONITOR_SET_FAN1_MODE_COUNT 0x00
147 #define HWMONITOR_SET_FAN1_MODE_SENS_INPUT 0x01
148 #define HWMONITOR_SET_FAN2_MODE_COUNT 0x00
149 #define HWMONITOR_SET_FAN2_MODE_SENS_INPUT 0x02
150 #define HWMONITOR_SET_FAN1_CTRL_SPEED_DIV1 0x00
151 #define HWMONITOR_SET_FAN1_CTRL_SPEED_DIV2 0x04
152 #define HWMONITOR_SET_FAN1_CTRL_SPEED_DIV4 0x08
153 #define HWMONITOR_SET_FAN1_CTRL_SPEED_DIV8 0x0C
154 #define HWMONITOR_SET_FAN2_CTRL_SPEED_DIV1 0x00
155 #define HWMONITOR_SET_FAN2_CTRL_SPEED_DIV2 0x10
156 #define HWMONITOR_SET_FAN2_CTRL_SPEED_DIV4 0x20
157 #define HWMONITOR_SET_FAN2_CTRL_SPEED_DIV8 0x30
158 #define HWMONITOR_SET_MODE_OS_DISABLE 0x00
159 #define HWMONITOR_SET_MODE_OS_ENABLE 0x01
160 #define HWMONITOR_SET_MODE_RST_DISABLE 0x00
161 #define HWMONITOR_SET_MODE_RST_ENABLE 0x01
162 
167 #define HWMONITOR_SET_TEMP_RES_8_bit 0x00
168 #define HWMONITOR_SET_TEMP_RES_11_bit 0x01
169 #define HWMONITOR_TEMP_RES_11_bit_BIT_MASK 0x08
170 
175 #define HWMONITOR_SET_ALL_CH_ENABLE 0x00
176 #define HWMONITOR_SET_ALL_CH_DISABLE 0xFF
177 
182 #define HWMONITOR_MANUFACTURERS_ID 0x01
183 #define HWMONITOR_STEPPING_DIE_REVISION_ID 0x08
184 
189 #define HWMONITOR_IN_0 0
190 #define HWMONITOR_IN_1 1
191 #define HWMONITOR_IN_2 2
192 #define HWMONITOR_IN_3 3
193 #define HWMONITOR_IN_4 4
194 #define HWMONITOR_IN_5 5
195 #define HWMONITOR_IN_6 6
196 #define HWMONITOR_FAN_1 0
197 #define HWMONITOR_FAN_2 1
198 
204 #define HWMONITOR_DEVICE_ADDRESS_0 0x28
205 #define HWMONITOR_DEVICE_ADDRESS_1 0x29
206 #define HWMONITOR_DEVICE_ADDRESS_2 0x2A
207 #define HWMONITOR_DEVICE_ADDRESS_3 0x2B
208 #define HWMONITOR_DEVICE_ADDRESS_4 0x2C
209 #define HWMONITOR_DEVICE_ADDRESS_5 0x2D
210 #define HWMONITOR_DEVICE_ADDRESS_6 0x2E
211 #define HWMONITOR_DEVICE_ADDRESS_7 0x2F
212  // hwmonitor_set
214 
229 #define HWMONITOR_MAP_MIKROBUS( cfg, mikrobus ) \
230  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
231  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
232  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
233  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
234  // hwmonitor_map // hwmonitor
237 
242 typedef struct
243 {
244  // Output pins
245  digital_out_t rst;
247  // Input pins
248  digital_in_t int_pin;
250  // Modules
251  i2c_master_t i2c;
253  // I2C slave address
254  uint8_t slave_address;
256 } hwmonitor_t;
257 
262 typedef struct
263 {
264  pin_name_t scl;
265  pin_name_t sda;
267  pin_name_t rst;
268  pin_name_t int_pin;
270  uint32_t i2c_speed;
271  uint8_t i2c_address;
274 
279 typedef struct
280 {
281  uint8_t start;
282  uint8_t int_enable;
283  uint8_t int_pol_sel;
284  uint8_t int_clear;
285  uint8_t chas_clear;
286  uint8_t gpo;
287  uint8_t init;
290 
295 typedef enum
296 {
298  HWMONITOR_ERROR = -1
299 
301 
318 
333 
347 
362 err_t hwmonitor_generic_write ( hwmonitor_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
363 
378 err_t hwmonitor_generic_read ( hwmonitor_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
379 
391 
407 
423 
438 err_t hwmonitor_get_device_id ( hwmonitor_t *ctx, uint8_t *manufacture_id, uint8_t *revision_id );
439 
455 err_t hwmonitor_set_temp_res ( hwmonitor_t *ctx, uint8_t temp_res );
456 
470 err_t hwmonitor_set_ch_out ( hwmonitor_t *ctx, uint8_t ch_out );
471 
485 err_t hwmonitor_get_temperature ( hwmonitor_t *ctx, float *temperature );
486 
501 err_t hwmonitor_get_analog_inputs ( hwmonitor_t *ctx, uint8_t in_pos, float *voltage );
502 
517 err_t hwmonitor_get_fan_output ( hwmonitor_t *ctx, uint8_t fan_pos, uint8_t *fan_output );
518 
534 err_t hwmonitor_set_analog_in_limit ( hwmonitor_t *ctx, uint8_t in_pos, uint16_t upper_limit, uint16_t lower_limit );
535 
548 
549 #ifdef __cplusplus
550 }
551 #endif
552 #endif // HWMONITOR_H
553  // hwmonitor
555 
556 // ------------------------------------------------------------------------ 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:268
hwmonitor_config_t::init
uint8_t init
Definition: hwmonitor.h:287
hwmonitor_t::slave_address
uint8_t slave_address
Definition: hwmonitor.h:254
hwmonitor_config_t::chas_clear
uint8_t chas_clear
Definition: hwmonitor.h:285
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:286
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:282
hwmonitor_return_value_t
hwmonitor_return_value_t
HW Monitor Click return value data.
Definition: hwmonitor.h:296
hwmonitor_config_t::int_pol_sel
uint8_t int_pol_sel
Definition: hwmonitor.h:283
hwmonitor_cfg_t::scl
pin_name_t scl
Definition: hwmonitor.h:264
HWMONITOR_OK
@ HWMONITOR_OK
Definition: hwmonitor.h:297
hwmonitor_config_t::start
uint8_t start
Definition: hwmonitor.h:281
hwmonitor_t::i2c
i2c_master_t i2c
Definition: hwmonitor.h:251
hwmonitor_cfg_t::sda
pin_name_t sda
Definition: hwmonitor.h:265
hwmonitor_cfg_t::rst
pin_name_t rst
Definition: hwmonitor.h:267
HWMONITOR_ERROR
@ HWMONITOR_ERROR
Definition: hwmonitor.h:298
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:280
hwmonitor_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: hwmonitor.h:270
hwmonitor_t::int_pin
digital_in_t int_pin
Definition: hwmonitor.h:248
hwmonitor_t
HW Monitor Click context object.
Definition: hwmonitor.h:243
hwmonitor_config_t::int_clear
uint8_t int_clear
Definition: hwmonitor.h:284
hwmonitor_t::rst
digital_out_t rst
Definition: hwmonitor.h:245
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:271
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:263
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.