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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define HWMONITOR_REG_CONFIGURATION 0x00
60 #define HWMONITOR_REG_INT_STATUS_1 0x01
61 #define HWMONITOR_REG_INT_STATUS_2 0x02
62 #define HWMONITOR_REG_INT_MASK_1 0x03
63 #define HWMONITOR_REG_INT_MASK_2 0x04
64 #define HWMONITOR_REG_FAN_DIVISOR 0x05
65 #define HWMONITOR_REG_OS_T_RES_CONFIG 0x06
66 #define HWMONITOR_REG_CONVERSION_RATE 0x07
67 #define HWMONITOR_REG_CHANNEL_DISABLE 0x08
68 #define HWMONITOR_REG_RAM_IN_0 0x20
69 #define HWMONITOR_REG_RAM_IN_1 0x21
70 #define HWMONITOR_REG_RAM_IN_2 0x22
71 #define HWMONITOR_REG_RAM_IN_3 0x23
72 #define HWMONITOR_REG_RAM_IN_4 0x24
73 #define HWMONITOR_REG_RAM_IN_5 0x25
74 #define HWMONITOR_REG_RAM_IN_6 0x26
75 #define HWMONITOR_REG_RAM_TEMPERATURE 0x27
76 #define HWMONITOR_REG_RAM_FAN_1 0x28
77 #define HWMONITOR_REG_RAM_FAN_2 0x29
78 #define HWMONITOR_REG_RAM_LIM_IN_0_H 0x2A
79 #define HWMONITOR_REG_RAM_LIM_IN_0_L 0x2B
80 #define HWMONITOR_REG_RAM_LIM_IN_1_H 0x2C
81 #define HWMONITOR_REG_RAM_LIM_IN_1_L 0x2D
82 #define HWMONITOR_REG_RAM_LIM_IN_2_H 0x2E
83 #define HWMONITOR_REG_RAM_LIM_IN_2_L 0x2F
84 #define HWMONITOR_REG_RAM_LIM_IN_3_H 0x30
85 #define HWMONITOR_REG_RAM_LIM_IN_3_L 0x31
86 #define HWMONITOR_REG_RAM_LIM_IN_4_H 0x32
87 #define HWMONITOR_REG_RAM_LIM_IN_4_L 0x33
88 #define HWMONITOR_REG_RAM_LIM_IN_5_H 0x34
89 #define HWMONITOR_REG_RAM_LIM_IN_5_L 0x35
90 #define HWMONITOR_REG_RAM_LIM_IN_6_H 0x36
91 #define HWMONITOR_REG_RAM_LIM_IN_6_L 0x37
92 #define HWMONITOR_REG_RAM_LIM_HOT_H 0x38
93 #define HWMONITOR_REG_RAM_LIM_HOT_L 0x39
94 #define HWMONITOR_REG_RAM_LIM_TEMP_H 0x3A
95 #define HWMONITOR_REG_RAM_LIM_TEMP_L 0x3B
96 #define HWMONITOR_REG_RAM_CURRENT_LIM_FUN_1 0x3C
97 #define HWMONITOR_REG_RAM_CURRENT_LIM_FUN_2 0x3D
98 #define HWMONITOR_REG_RAM_MANUFACTURE_ID 0x3E
99 #define HWMONITOR_REG_RAM_REVISION_ID 0x3F
100  // hwmonitor_reg
102 
117 #define HWMONITOR_SET_CONFIG_START_DIS 0x00
118 #define HWMONITOR_SET_CONFIG_START_EN 0x01
119 #define HWMONITOR_SET_CONFIG_INT_DIS 0x00
120 #define HWMONITOR_SET_CONFIG_INT_EN 0x01
121 #define HWMONITOR_SET_CONFIG_INT_OPEN_DRAIN 0x00
122 #define HWMONITOR_SET_CONFIG_INT_ACT_LOW 0x01
123 #define HWMONITOR_SET_CONFIG_INT_CLR_DIS 0x00
124 #define HWMONITOR_SET_CONFIG_INT_CLR_EN 0x01
125 #define HWMONITOR_SET_CONFIG_CHA_NCLR_GPI 0x00
126 #define HWMONITOR_SET_CONFIG_CHA_GPI 0x01
127 #define HWMONITOR_SET_CONFIG_GPO_LOW 0x00
128 #define HWMONITOR_SET_CONFIG_GPO_HIGH 0x01
129 #define HWMONITOR_SET_CONFIG_PWR_ON 0x00
130 #define HWMONITOR_SET_CONFIG_PWR_DIS 0x01
131 
136 #define HWMONITOR_SET_FAN1_MODE_COUNT 0x00
137 #define HWMONITOR_SET_FAN1_MODE_SENS_INPUT 0x01
138 #define HWMONITOR_SET_FAN2_MODE_COUNT 0x00
139 #define HWMONITOR_SET_FAN2_MODE_SENS_INPUT 0x02
140 #define HWMONITOR_SET_FAN1_CTRL_SPEED_DIV1 0x00
141 #define HWMONITOR_SET_FAN1_CTRL_SPEED_DIV2 0x04
142 #define HWMONITOR_SET_FAN1_CTRL_SPEED_DIV4 0x08
143 #define HWMONITOR_SET_FAN1_CTRL_SPEED_DIV8 0x0C
144 #define HWMONITOR_SET_FAN2_CTRL_SPEED_DIV1 0x00
145 #define HWMONITOR_SET_FAN2_CTRL_SPEED_DIV2 0x10
146 #define HWMONITOR_SET_FAN2_CTRL_SPEED_DIV4 0x20
147 #define HWMONITOR_SET_FAN2_CTRL_SPEED_DIV8 0x30
148 #define HWMONITOR_SET_MODE_OS_DISABLE 0x00
149 #define HWMONITOR_SET_MODE_OS_ENABLE 0x01
150 #define HWMONITOR_SET_MODE_RST_DISABLE 0x00
151 #define HWMONITOR_SET_MODE_RST_ENABLE 0x01
152 
157 #define HWMONITOR_SET_TEMP_RES_8_bit 0x00
158 #define HWMONITOR_SET_TEMP_RES_11_bit 0x01
159 #define HWMONITOR_TEMP_RES_11_bit_BIT_MASK 0x08
160 
165 #define HWMONITOR_SET_ALL_CH_ENABLE 0x00
166 #define HWMONITOR_SET_ALL_CH_DISABLE 0xFF
167 
172 #define HWMONITOR_MANUFACTURERS_ID 0x01
173 #define HWMONITOR_STEPPING_DIE_REVISION_ID 0x08
174 
179 #define HWMONITOR_IN_0 0
180 #define HWMONITOR_IN_1 1
181 #define HWMONITOR_IN_2 2
182 #define HWMONITOR_IN_3 3
183 #define HWMONITOR_IN_4 4
184 #define HWMONITOR_IN_5 5
185 #define HWMONITOR_IN_6 6
186 #define HWMONITOR_FAN_1 0
187 #define HWMONITOR_FAN_2 1
188 
194 #define HWMONITOR_DEVICE_ADDRESS_0 0x28
195 #define HWMONITOR_DEVICE_ADDRESS_1 0x29
196 #define HWMONITOR_DEVICE_ADDRESS_2 0x2A
197 #define HWMONITOR_DEVICE_ADDRESS_3 0x2B
198 #define HWMONITOR_DEVICE_ADDRESS_4 0x2C
199 #define HWMONITOR_DEVICE_ADDRESS_5 0x2D
200 #define HWMONITOR_DEVICE_ADDRESS_6 0x2E
201 #define HWMONITOR_DEVICE_ADDRESS_7 0x2F
202  // hwmonitor_set
204 
219 #define HWMONITOR_MAP_MIKROBUS( cfg, mikrobus ) \
220  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
221  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
222  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
223  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
224  // hwmonitor_map // hwmonitor
227 
232 typedef struct
233 {
234  // Output pins
235  digital_out_t rst;
237  // Input pins
238  digital_in_t int_pin;
240  // Modules
241  i2c_master_t i2c;
243  // I2C slave address
244  uint8_t slave_address;
246 } hwmonitor_t;
247 
252 typedef struct
253 {
254  pin_name_t scl;
255  pin_name_t sda;
257  pin_name_t rst;
258  pin_name_t int_pin;
260  uint32_t i2c_speed;
261  uint8_t i2c_address;
264 
269 typedef struct
270 {
271  uint8_t start;
272  uint8_t int_enable;
273  uint8_t int_pol_sel;
274  uint8_t int_clear;
275  uint8_t chas_clear;
276  uint8_t gpo;
277  uint8_t init;
280 
285 typedef enum
286 {
288  HWMONITOR_ERROR = -1
289 
291 
308 
323 
337 
352 err_t hwmonitor_generic_write ( hwmonitor_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
353 
368 err_t hwmonitor_generic_read ( hwmonitor_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
369 
381 
397 
413 
428 err_t hwmonitor_get_device_id ( hwmonitor_t *ctx, uint8_t *manufacture_id, uint8_t *revision_id );
429 
445 err_t hwmonitor_set_temp_res ( hwmonitor_t *ctx, uint8_t temp_res );
446 
460 err_t hwmonitor_set_ch_out ( hwmonitor_t *ctx, uint8_t ch_out );
461 
475 err_t hwmonitor_get_temperature ( hwmonitor_t *ctx, float *temperature );
476 
491 err_t hwmonitor_get_analog_inputs ( hwmonitor_t *ctx, uint8_t in_pos, float *voltage );
492 
507 err_t hwmonitor_get_fan_output ( hwmonitor_t *ctx, uint8_t fan_pos, uint8_t *fan_output );
508 
524 err_t hwmonitor_set_analog_in_limit ( hwmonitor_t *ctx, uint8_t in_pos, uint16_t upper_limit, uint16_t lower_limit );
525 
538 
539 #ifdef __cplusplus
540 }
541 #endif
542 #endif // HWMONITOR_H
543  // hwmonitor
545 
546 // ------------------------------------------------------------------------ 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:258
hwmonitor_config_t::init
uint8_t init
Definition: hwmonitor.h:277
hwmonitor_t::slave_address
uint8_t slave_address
Definition: hwmonitor.h:244
hwmonitor_config_t::chas_clear
uint8_t chas_clear
Definition: hwmonitor.h:275
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:276
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:272
hwmonitor_return_value_t
hwmonitor_return_value_t
HW Monitor Click return value data.
Definition: hwmonitor.h:286
hwmonitor_config_t::int_pol_sel
uint8_t int_pol_sel
Definition: hwmonitor.h:273
hwmonitor_cfg_t::scl
pin_name_t scl
Definition: hwmonitor.h:254
HWMONITOR_OK
@ HWMONITOR_OK
Definition: hwmonitor.h:287
hwmonitor_config_t::start
uint8_t start
Definition: hwmonitor.h:271
hwmonitor_t::i2c
i2c_master_t i2c
Definition: hwmonitor.h:241
hwmonitor_cfg_t::sda
pin_name_t sda
Definition: hwmonitor.h:255
hwmonitor_cfg_t::rst
pin_name_t rst
Definition: hwmonitor.h:257
HWMONITOR_ERROR
@ HWMONITOR_ERROR
Definition: hwmonitor.h:288
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:270
hwmonitor_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: hwmonitor.h:260
hwmonitor_t::int_pin
digital_in_t int_pin
Definition: hwmonitor.h:238
hwmonitor_t
HW Monitor Click context object.
Definition: hwmonitor.h:233
hwmonitor_config_t::int_clear
uint8_t int_clear
Definition: hwmonitor.h:274
hwmonitor_t::rst
digital_out_t rst
Definition: hwmonitor.h:235
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:261
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:253
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.