hwmonitor3  2.1.0.0
hwmonitor3.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 HWMONITOR3_H
29 #define HWMONITOR3_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 HWMONITOR3_REG_INT_SRC 0x10
74 #define HWMONITOR3_REG_INT_MONITOR 0x11
75 #define HWMONITOR3_REG_INT_UVHF 0x12
76 #define HWMONITOR3_REG_INT_UVLF 0x14
77 #define HWMONITOR3_REG_INT_OVHF 0x16
78 #define HWMONITOR3_REG_INT_OVLF 0x18
79 #define HWMONITOR3_REG_INT_SEQ_ON 0x1A
80 #define HWMONITOR3_REG_INT_SEQ_OFF 0x1C
81 #define HWMONITOR3_REG_INT_SEQ_EXS 0x1E
82 #define HWMONITOR3_REG_INT_SEQ_ENS 0x20
83 #define HWMONITOR3_REG_INT_CONTROL 0x22
84 #define HWMONITOR3_REG_INT_TEST 0x23
85 #define HWMONITOR3_REG_INT_VENDOR 0x24
86 #define HWMONITOR3_REG_VMON_STAT 0x30
87 #define HWMONITOR3_REG_TEST_INFO 0x31
88 #define HWMONITOR3_REG_OFF_STAT 0x32
89 #define HWMONITOR3_REG_SEQ_REC_STAT 0x34
90 #define HWMONITOR3_REG_SEQ_OW_STAT 0x35
91 #define HWMONITOR3_REG_SEQ_ORD_STAT 0x36
92 #define HWMONITOR3_REG_MON_LVL_1 0x40
93 #define HWMONITOR3_REG_MON_LVL_2 0x41
94 #define HWMONITOR3_REG_MON_LVL_3 0x42
95 #define HWMONITOR3_REG_MON_LVL_4 0x43
96 #define HWMONITOR3_REG_MON_LVL_5 0x44
97 #define HWMONITOR3_REG_MON_LVL_6 0x45
98 #define HWMONITOR3_REG_SEQ_ON_LOG_1 0x50
99 #define HWMONITOR3_REG_SEQ_ON_LOG_2 0x51
100 #define HWMONITOR3_REG_SEQ_ON_LOG_3 0x52
101 #define HWMONITOR3_REG_SEQ_ON_LOG_4 0x53
102 #define HWMONITOR3_REG_SEQ_ON_LOG_5 0x54
103 #define HWMONITOR3_REG_SEQ_ON_LOG_6 0x55
104 #define HWMONITOR3_REG_SEQ_OFF_LOG_1 0x60
105 #define HWMONITOR3_REG_SEQ_OFF_LOG_2 0x61
106 #define HWMONITOR3_REG_SEQ_OFF_LOG_3 0x62
107 #define HWMONITOR3_REG_SEQ_OFF_LOG_4 0x63
108 #define HWMONITOR3_REG_SEQ_OFF_LOG_5 0x64
109 #define HWMONITOR3_REG_SEQ_OFF_LOG_6 0x65
110 #define HWMONITOR3_REG_SEQ_EXS_LOG_1 0x70
111 #define HWMONITOR3_REG_SEQ_EXS_LOG_2 0x71
112 #define HWMONITOR3_REG_SEQ_EXS_LOG_3 0x72
113 #define HWMONITOR3_REG_SEQ_EXS_LOG_4 0x73
114 #define HWMONITOR3_REG_SEQ_EXS_LOG_5 0x74
115 #define HWMONITOR3_REG_SEQ_EXS_LOG_6 0x75
116 #define HWMONITOR3_REG_SEQ_ENS_LOG_1 0x80
117 #define HWMONITOR3_REG_SEQ_ENS_LOG_2 0x81
118 #define HWMONITOR3_REG_SEQ_ENS_LOG_3 0x82
119 #define HWMONITOR3_REG_SEQ_ENS_LOG_4 0x83
120 #define HWMONITOR3_REG_SEQ_ENS_LOG_5 0x84
121 #define HWMONITOR3_REG_SEQ_ENS_LOG_6 0x85
122 #define HWMONITOR3_REG_SEQ_TIME_MSB_1 0x90
123 #define HWMONITOR3_REG_SEQ_TIME_LSB_1 0x91
124 #define HWMONITOR3_REG_SEQ_TIME_MSB_2 0x92
125 #define HWMONITOR3_REG_SEQ_TIME_LSB_2 0x93
126 #define HWMONITOR3_REG_SEQ_TIME_MSB_3 0x94
127 #define HWMONITOR3_REG_SEQ_TIME_LSB_3 0x95
128 #define HWMONITOR3_REG_SEQ_TIME_MSB_4 0x96
129 #define HWMONITOR3_REG_SEQ_TIME_LSB_4 0x97
130 #define HWMONITOR3_REG_SEQ_TIME_MSB_5 0x98
131 #define HWMONITOR3_REG_SEQ_TIME_LSB_5 0x99
132 #define HWMONITOR3_REG_SEQ_TIME_MSB_6 0x9A
133 #define HWMONITOR3_REG_SEQ_TIME_LSB_6 0x9B
134 #define HWMONITOR3_REG_BANK_SEL 0xF0
135 #define HWMONITOR3_REG_PROT1 0xF1
136 #define HWMONITOR3_REG_PROT2 0xF2
137 #define HWMONITOR3_REG_PROT_MON2 0xF3
138 #define HWMONITOR3_REG_I2CADDR 0xF9
139 #define HWMONITOR3_REG_DEV_CFG 0xFA
140 
145 #define HWMONITOR3_REG_VMON_CTL 0x10
146 #define HWMONITOR3_REG_VMON_MISC 0x11
147 #define HWMONITOR3_REG_TEST_CFG 0x12
148 #define HWMONITOR3_REG_IEN_UVHF 0x13
149 #define HWMONITOR3_REG_IEN_UVLF 0x14
150 #define HWMONITOR3_REG_IEN_OVHF 0x15
151 #define HWMONITOR3_REG_IEN_OVLF 0x16
152 #define HWMONITOR3_REG_IEN_SEQ_ON 0x17
153 #define HWMONITOR3_REG_IEN_SEQ_OFF 0x18
154 #define HWMONITOR3_REG_IEN_SEQ_EXS 0x19
155 #define HWMONITOR3_REG_IEN_SEQ_ENS 0x1A
156 #define HWMONITOR3_REG_IEN_CONTROL 0x1B
157 #define HWMONITOR3_REG_IEN_TEST 0x1C
158 #define HWMONITOR3_REG_MON_CH_EN 0x1E
159 #define HWMONITOR3_REG_VRANGE_MULT 0x1F
160 #define HWMONITOR3_REG_UV_HF_1 0x20
161 #define HWMONITOR3_REG_OV_HF_1 0x21
162 #define HWMONITOR3_REG_UV_LF_1 0x22
163 #define HWMONITOR3_REG_OV_LF_1 0x23
164 #define HWMONITOR3_REG_FLT_HF_1 0x24
165 #define HWMONITOR3_REG_FC_LF_1 0x25
166 #define HWMONITOR3_REG_UV_HF_2 0x30
167 #define HWMONITOR3_REG_OV_HF_2 0x31
168 #define HWMONITOR3_REG_UV_LF_2 0x32
169 #define HWMONITOR3_REG_OV_LF_2 0x33
170 #define HWMONITOR3_REG_FLT_HF_2 0x34
171 #define HWMONITOR3_REG_FC_LF_2 0x35
172 #define HWMONITOR3_REG_UV_HF_3 0x40
173 #define HWMONITOR3_REG_OV_HF_3 0x41
174 #define HWMONITOR3_REG_UV_LF_3 0x42
175 #define HWMONITOR3_REG_OV_LF_3 0x43
176 #define HWMONITOR3_REG_FLT_HF_3 0x44
177 #define HWMONITOR3_REG_FC_LF_3 0x45
178 #define HWMONITOR3_REG_UV_HF_4 0x50
179 #define HWMONITOR3_REG_OV_HF_4 0x51
180 #define HWMONITOR3_REG_UV_LF_4 0x52
181 #define HWMONITOR3_REG_OV_LF_4 0x53
182 #define HWMONITOR3_REG_FLT_HF_4 0x54
183 #define HWMONITOR3_REG_FC_LF_4 0x55
184 #define HWMONITOR3_REG_UV_HF_5 0x60
185 #define HWMONITOR3_REG_OV_HF_5 0x61
186 #define HWMONITOR3_REG_UV_LF_5 0x62
187 #define HWMONITOR3_REG_OV_LF_5 0x63
188 #define HWMONITOR3_REG_FLT_HF_5 0x64
189 #define HWMONITOR3_REG_FC_LF_5 0x65
190 #define HWMONITOR3_REG_UV_HF_6 0x70
191 #define HWMONITOR3_REG_OV_HF_6 0x71
192 #define HWMONITOR3_REG_UV_LF_6 0x72
193 #define HWMONITOR3_REG_OV_LF_6 0x73
194 #define HWMONITOR3_REG_FLT_HF_6 0x74
195 #define HWMONITOR3_REG_FC_LF_6 0x75
196 #define HWMONITOR3_REG_TI_CONTROL 0x9F
197 #define HWMONITOR3_REG_SEQ_REC_CTL 0xA0
198 #define HWMONITOR3_REG_AMSK_ON 0xA1
199 #define HWMONITOR3_REG_AMSK_OFF 0xA2
200 #define HWMONITOR3_REG_AMSK_EXS 0xA3
201 #define HWMONITOR3_REG_AMSK_ENS 0xA4
202 #define HWMONITOR3_REG_SEQ_TOUT_MSB 0xA5
203 #define HWMONITOR3_REG_SEQ_TOUT_LSB 0xA6
204 #define HWMONITOR3_REG_SEQ_SYNC 0xA7
205 #define HWMONITOR3_REG_SEQ_UP_THLD 0xA8
206 #define HWMONITOR3_REG_SEQ_DN_THLD 0xA9
207 #define HWMONITOR3_REG_SEQ_DN_THLD 0xA9
208 #define HWMONITOR3_REG_SEQ_ON_EXP_1 0xB0
209 #define HWMONITOR3_REG_SEQ_ON_EXP_2 0xB1
210 #define HWMONITOR3_REG_SEQ_ON_EXP_3 0xB2
211 #define HWMONITOR3_REG_SEQ_ON_EXP_4 0xB3
212 #define HWMONITOR3_REG_SEQ_ON_EXP_5 0xB4
213 #define HWMONITOR3_REG_SEQ_ON_EXP_6 0xB5
214 #define HWMONITOR3_REG_SEQ_OFF_EXP_1 0xC0
215 #define HWMONITOR3_REG_SEQ_OFF_EXP_2 0xC1
216 #define HWMONITOR3_REG_SEQ_OFF_EXP_3 0xC2
217 #define HWMONITOR3_REG_SEQ_OFF_EXP_4 0xC3
218 #define HWMONITOR3_REG_SEQ_OFF_EXP_5 0xC4
219 #define HWMONITOR3_REG_SEQ_OFF_EXP_6 0xC5
220 #define HWMONITOR3_REG_SEQ_EXS_EXP_1 0xD0
221 #define HWMONITOR3_REG_SEQ_EXS_EXP_2 0xD1
222 #define HWMONITOR3_REG_SEQ_EXS_EXP_3 0xD2
223 #define HWMONITOR3_REG_SEQ_EXS_EXP_4 0xD3
224 #define HWMONITOR3_REG_SEQ_EXS_EXP_5 0xD4
225 #define HWMONITOR3_REG_SEQ_EXS_EXP_6 0xD5
226 #define HWMONITOR3_REG_SEQ_ENS_EXP_1 0xE0
227 #define HWMONITOR3_REG_SEQ_ENS_EXP_2 0xE1
228 #define HWMONITOR3_REG_SEQ_ENS_EXP_3 0xE2
229 #define HWMONITOR3_REG_SEQ_ENS_EXP_4 0xE3
230 #define HWMONITOR3_REG_SEQ_ENS_EXP_5 0xE4
231 #define HWMONITOR3_REG_SEQ_ENS_EXP_6 0xE5
232  // hwmonitor3_reg
234 
249 #define HWMONITOR3_SCALING_1X 0
250 #define HWMONITOR3_SCALING_4X 1
251 
256 #define HWMONITOR3_CHANNEL_NONE 0x00
257 #define HWMONITOR3_CHANNEL_1 0x01
258 #define HWMONITOR3_CHANNEL_2 0x02
259 #define HWMONITOR3_CHANNEL_3 0x04
260 #define HWMONITOR3_CHANNEL_4 0x08
261 #define HWMONITOR3_CHANNEL_5 0x10
262 #define HWMONITOR3_CHANNEL_6 0x20
263 #define HWMONITOR3_CHANNEL_ALL 0x3F
264 
269 #define HWMONITOR3_DATA_RES 0.005
270 #define HWMONITOR3_DATA_OFFSET 0.2
271 #define HWMONITOR3_DATA_SCALE_4X 4.0
272 
278 #define HWMONITOR3_DEVICE_ADDRESS_0 0x33
279 #define HWMONITOR3_DEVICE_ADDRESS_1 0x37
280  // hwmonitor3_set
282 
297 #define HWMONITOR3_MAP_MIKROBUS( cfg, mikrobus ) \
298  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
299  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
300  cfg.sync = MIKROBUS( mikrobus, MIKROBUS_AN ); \
301  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
302  cfg.sleep = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
303  cfg.irq = MIKROBUS( mikrobus, MIKROBUS_INT )
304  // hwmonitor3_map // hwmonitor3
307 
312 typedef struct
313 {
314  float ch1_v;
315  float ch2_v;
316  float ch3_v;
317  float ch4_v;
318  float ch5_v;
319  float ch6_v;
322 
327 typedef struct
328 {
329  // Output pins
330  digital_out_t en;
331  digital_out_t sleep;
333  // Input pins
334  digital_in_t sync;
335  digital_in_t irq;
337  // Modules
338  i2c_master_t i2c;
340  // I2C slave address
341  uint8_t slave_address;
343  uint8_t scaling;
345 } hwmonitor3_t;
346 
351 typedef struct
352 {
353  pin_name_t scl;
354  pin_name_t sda;
356  pin_name_t sync;
357  pin_name_t en;
358  pin_name_t sleep;
359  pin_name_t irq;
361  uint32_t i2c_speed;
362  uint8_t i2c_address;
365 
370 typedef enum
371 {
373  HWMONITOR3_ERROR = -1
374 
376 
393 
408 
422 
435 err_t hwmonitor3_write_reg ( hwmonitor3_t *ctx, uint8_t reg, uint8_t data_in );
436 
451 err_t hwmonitor3_write_regs ( hwmonitor3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
452 
465 err_t hwmonitor3_read_reg ( hwmonitor3_t *ctx, uint8_t reg, uint8_t *data_out );
466 
481 err_t hwmonitor3_read_regs ( hwmonitor3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
482 
492 void hwmonitor3_set_en_pin ( hwmonitor3_t *ctx, uint8_t state );
493 
503 void hwmonitor3_set_sleep_pin ( hwmonitor3_t *ctx, uint8_t state );
504 
514 
524 
536 
548 
561 
574 err_t hwmonitor3_enable_channel ( hwmonitor3_t *ctx, uint8_t ch_mask );
575 
588 err_t hwmonitor3_disable_channel ( hwmonitor3_t *ctx, uint8_t ch_mask );
589 
603 err_t hwmonitor3_set_scaling ( hwmonitor3_t *ctx, uint8_t scaling, uint8_t ch_mask );
604 
619 
620 #ifdef __cplusplus
621 }
622 #endif
623 #endif // HWMONITOR3_H
624  // hwmonitor3
626 
627 // ------------------------------------------------------------------------ END
hwmonitor3_ch_mon_t
HW Monitor 3 Click channel voltage monitor object.
Definition: hwmonitor3.h:313
hwmonitor3_ch_mon_t::ch5_v
float ch5_v
Definition: hwmonitor3.h:318
hwmonitor3_enable_channel
err_t hwmonitor3_enable_channel(hwmonitor3_t *ctx, uint8_t ch_mask)
HW Monitor 3 enable channel function.
hwmonitor3_ch_mon_t::ch6_v
float ch6_v
Definition: hwmonitor3.h:319
hwmonitor3_cfg_t::sleep
pin_name_t sleep
Definition: hwmonitor3.h:358
hwmonitor3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: hwmonitor3.h:361
hwmonitor3_cfg_t::irq
pin_name_t irq
Definition: hwmonitor3.h:359
hwmonitor3_ch_mon_t::ch2_v
float ch2_v
Definition: hwmonitor3.h:315
hwmonitor3_default_cfg
err_t hwmonitor3_default_cfg(hwmonitor3_t *ctx)
HW Monitor 3 default configuration function.
hwmonitor3_read_voltage
err_t hwmonitor3_read_voltage(hwmonitor3_t *ctx, hwmonitor3_ch_mon_t *ch_mon)
HW Monitor 3 read voltage function.
hwmonitor3_t::sleep
digital_out_t sleep
Definition: hwmonitor3.h:331
hwmonitor3_read_regs
err_t hwmonitor3_read_regs(hwmonitor3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
HW Monitor 3 read regs function.
hwmonitor3_t::irq
digital_in_t irq
Definition: hwmonitor3.h:335
hwmonitor3_t::slave_address
uint8_t slave_address
Definition: hwmonitor3.h:341
hwmonitor3_disable_channel
err_t hwmonitor3_disable_channel(hwmonitor3_t *ctx, uint8_t ch_mask)
HW Monitor 3 disable channel function.
hwmonitor3_t
HW Monitor 3 Click context object.
Definition: hwmonitor3.h:328
hwmonitor3_ch_mon_t::ch4_v
float ch4_v
Definition: hwmonitor3.h:317
hwmonitor3_ch_mon_t::ch3_v
float ch3_v
Definition: hwmonitor3.h:316
hwmonitor3_set_en_pin
void hwmonitor3_set_en_pin(hwmonitor3_t *ctx, uint8_t state)
HW Monitor 3 set en pin function.
hwmonitor3_cfg_setup
void hwmonitor3_cfg_setup(hwmonitor3_cfg_t *cfg)
HW Monitor 3 configuration object setup function.
hwmonitor3_read_reg
err_t hwmonitor3_read_reg(hwmonitor3_t *ctx, uint8_t reg, uint8_t *data_out)
HW Monitor 3 read reg function.
hwmonitor3_get_irq_pin
uint8_t hwmonitor3_get_irq_pin(hwmonitor3_t *ctx)
HW Monitor 3 get irq pin function.
hwmonitor3_cfg_t::sync
pin_name_t sync
Definition: hwmonitor3.h:356
hwmonitor3_write_regs
err_t hwmonitor3_write_regs(hwmonitor3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
HW Monitor 3 write regs function.
hwmonitor3_set_sleep_pin
void hwmonitor3_set_sleep_pin(hwmonitor3_t *ctx, uint8_t state)
HW Monitor 3 set sleep pin function.
hwmonitor3_t::sync
digital_in_t sync
Definition: hwmonitor3.h:334
hwmonitor3_cfg_t
HW Monitor 3 Click configuration object.
Definition: hwmonitor3.h:352
hwmonitor3_t::en
digital_out_t en
Definition: hwmonitor3.h:330
hwmonitor3_cfg_t::scl
pin_name_t scl
Definition: hwmonitor3.h:353
hwmonitor3_get_sync_pin
uint8_t hwmonitor3_get_sync_pin(hwmonitor3_t *ctx)
HW Monitor 3 get sync pin function.
hwmonitor3_select_bank1
err_t hwmonitor3_select_bank1(hwmonitor3_t *ctx)
HW Monitor 3 select bank1 function.
hwmonitor3_cfg_t::i2c_address
uint8_t i2c_address
Definition: hwmonitor3.h:362
hwmonitor3_init
err_t hwmonitor3_init(hwmonitor3_t *ctx, hwmonitor3_cfg_t *cfg)
HW Monitor 3 initialization function.
hwmonitor3_t::i2c
i2c_master_t i2c
Definition: hwmonitor3.h:338
hwmonitor3_cfg_t::en
pin_name_t en
Definition: hwmonitor3.h:357
hwmonitor3_check_communication
err_t hwmonitor3_check_communication(hwmonitor3_t *ctx)
HW Monitor 3 check communication function.
hwmonitor3_t::scaling
uint8_t scaling
Definition: hwmonitor3.h:343
HWMONITOR3_OK
@ HWMONITOR3_OK
Definition: hwmonitor3.h:372
hwmonitor3_write_reg
err_t hwmonitor3_write_reg(hwmonitor3_t *ctx, uint8_t reg, uint8_t data_in)
HW Monitor 3 write reg function.
HWMONITOR3_ERROR
@ HWMONITOR3_ERROR
Definition: hwmonitor3.h:373
hwmonitor3_return_value_t
hwmonitor3_return_value_t
HW Monitor 3 Click return value data.
Definition: hwmonitor3.h:371
hwmonitor3_set_scaling
err_t hwmonitor3_set_scaling(hwmonitor3_t *ctx, uint8_t scaling, uint8_t ch_mask)
HW Monitor 3 set scaling function.
hwmonitor3_ch_mon_t::ch1_v
float ch1_v
Definition: hwmonitor3.h:314
hwmonitor3_select_bank0
err_t hwmonitor3_select_bank0(hwmonitor3_t *ctx)
HW Monitor 3 select bank0 function.
hwmonitor3_cfg_t::sda
pin_name_t sda
Definition: hwmonitor3.h:354