cooler  2.1.0.0
cooler.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 COOLER_H
29 #define COOLER_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_analog_in.h"
48 #include "drv_i2c_master.h"
49 
70 #define COOLER_REG_SENSOR_VOLTAGE 0x00
71 #define COOLER_REG_LOCAL_TEMPERATURE 0x01
72 #define COOLER_REG_CONFIGURATION 0x02
73 #define COOLER_REG_OBJECT_TEMPERATURE 0x03
74 #define COOLER_REG_STATUS 0x04
75 #define COOLER_REG_STATUS_MASK_AND_ENABLE 0x05
76 #define COOLER_REG_OBJECT_HIGH_LIMIT_TEMP 0x06
77 #define COOLER_REG_OBJECT_LOW_LIMIT_TEMP 0x07
78 #define COOLER_REG_LOCAL_HIGH_LIMIT_TEMP 0x08
79 #define COOLER_REG_LOCAL_LOW_LIMIT_TEMP 0x09
80 #define COOLER_REG_S0_COEFFICIENT 0x0A
81 #define COOLER_REG_A0_COEFFICIENT 0x0B
82 #define COOLER_REG_A1_COEFFICIENT 0x0C
83 #define COOLER_REG_B0_COEFFICIENT 0x0D
84 #define COOLER_REG_B1_COEFFICIENT 0x0E
85 #define COOLER_REG_B2_COEFFICIENT 0x0F
86 #define COOLER_REG_C_COEFFICIENT 0x10
87 #define COOLER_REG_TC0_COEFFICIENT 0X11
88 #define COOLER_REG_TC1_COEFFICIENT 0x12
89 #define COOLER_REG_MANUFACTURER_ID 0x1E
90 #define COOLER_REG_DEVICE_ID 0x1F
91 #define COOLER_REG_MEMORY_ACCESS 0x2A
92  // cooler_reg
94 
109 #define COOLER_CFG_MODEON 0x1000u
110 #define COOLER_CFG_RESET 0x8000u
111 #define COOLER_CFG_1SAMPLE 0x0000u
112 #define COOLER_CFG_2SAMPLE 0x0200u
113 #define COOLER_CFG_4SAMPLE 0x0400u
114 #define COOLER_CFG_8SAMPLE 0x0600u
115 #define COOLER_CFG_16SAMPLE 0x0800u
116 #define COOLER_CFG_ALERTEN 0x0100u
117 #define COOLER_CFG_ALERTF 0x0080u
118 #define COOLER_CFG_TRANSC 0x0040u
119 
124 #define COOLER_STAT_ALERTEN 0x8000u
125 #define COOLER_STAT_CRTEN 0x4000u
126 
131 #define COOLER_DEVICE_ID 0x0078u
132 
137 #define COOLER_TEMPERATURE_SENS 0.03125f
138 #define COOLER_SENSOR_VTG_SENS 0.15625f
139 
144 #define COOLER_ADC_RESOLUTION 0x0FFFu
145 #define COOLER_VREF_3V3 3.3f
146 #define COOLER_VREF_5V 5.0f
147 
153 #define COOLER_SET_DEV_ADDR_0 0x40
154 #define COOLER_SET_DEV_ADDR_1 0x41
155 #define COOLER_SET_DEV_ADDR_2 0x44
156 #define COOLER_SET_DEV_ADDR_3 0x45
157  // cooler_set
159 
174 #define COOLER_MAP_MIKROBUS( cfg, mikrobus ) \
175  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
176  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
177  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
178  cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
179  cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
180  cfg.alr = MIKROBUS( mikrobus, MIKROBUS_INT )
181  // cooler_map // cooler
184 
189 typedef enum
190 {
195 
200 typedef struct
201 {
202  digital_out_t in2;
203  digital_out_t in1;
205  digital_in_t alr;
207  analog_in_t adc;
208  i2c_master_t i2c;
210  uint8_t slave_address;
211  float vref;
213 } cooler_t;
214 
219 typedef struct
220 {
221  pin_name_t an;
222  pin_name_t scl;
223  pin_name_t sda;
224  pin_name_t in2;
225  pin_name_t in1;
226  pin_name_t alr;
228  analog_in_resolution_t resolution;
229  float vref;
231  uint32_t i2c_speed;
232  uint8_t i2c_address;
234 } cooler_cfg_t;
235 
240 typedef enum
241 {
243  COOLER_ERROR = -1
244 
246 
251 typedef enum
252 {
255 
257 
274 
275 
289 err_t cooler_init ( cooler_t *ctx, cooler_cfg_t *cfg );
290 
304 
319 err_t cooler_generic_write ( cooler_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
320 
335 err_t cooler_generic_read ( cooler_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
336 
351 err_t cooler_data_write ( cooler_t *ctx, uint8_t reg, uint16_t data_in );
352 
367 err_t cooler_data_read ( cooler_t *ctx, uint8_t reg, uint16_t *data_out );
368 
382 err_t cooler_get_device_id ( cooler_t *ctx, uint16_t *device_id );
383 
397 err_t cooler_sensor_voltage ( cooler_t *ctx, float *voltage );
398 
412 err_t cooler_get_object_temperature ( cooler_t *ctx, float *temperature );
413 
424 uint8_t cooler_get_alert ( cooler_t *ctx );
425 
437 err_t cooler_read_raw_adc ( cooler_t *ctx, uint16_t *raw_adc );
438 
450 err_t cooler_read_voltage ( cooler_t *ctx, float *voltage );
451 
463 err_t cooler_set_vref ( cooler_t *ctx, float vref );
464 
477 
490 
503 
516 
533 
534 #ifdef __cplusplus
535 }
536 #endif
537 #endif // COOLER_H
538  // cooler
540 
541 // ------------------------------------------------------------------------ END
cooler_cfg_t::an
pin_name_t an
Definition: cooler.h:221
cooler_cfg_setup
void cooler_cfg_setup(cooler_cfg_t *cfg)
Cooler configuration object setup function.
cooler_drv_t
cooler_drv_t
Cooler Click driver selector.
Definition: cooler.h:190
cooler_data_write
err_t cooler_data_write(cooler_t *ctx, uint8_t reg, uint16_t data_in)
Cooler 16-bit data writing function.
cooler_t::in2
digital_out_t in2
Definition: cooler.h:202
COOLER_DISABLE
@ COOLER_DISABLE
Definition: cooler.h:254
cooler_clear_in1_pin
void cooler_clear_in1_pin(cooler_t *ctx)
Cooler IN1 pin clearing function.
cooler_init
err_t cooler_init(cooler_t *ctx, cooler_cfg_t *cfg)
Cooler initialization function.
COOLER_OK
@ COOLER_OK
Definition: cooler.h:242
cooler_set_out_state
err_t cooler_set_out_state(cooler_t *ctx, cooler_out_state_t out_state)
Cooler set output function.
cooler_set_in2_pin
void cooler_set_in2_pin(cooler_t *ctx)
Cooler set IN2 pin state function.
cooler_generic_read
err_t cooler_generic_read(cooler_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Cooler data reading function.
cooler_cfg_t::in2
pin_name_t in2
Definition: cooler.h:224
cooler_t::alr
digital_in_t alr
Definition: cooler.h:205
cooler_cfg_t::in1
pin_name_t in1
Definition: cooler.h:225
cooler_t::in1
digital_out_t in1
Definition: cooler.h:203
cooler_t::vref
float vref
Definition: cooler.h:211
cooler_cfg_t::i2c_address
uint8_t i2c_address
Definition: cooler.h:232
cooler_cfg_t::alr
pin_name_t alr
Definition: cooler.h:226
cooler_cfg_t::vref
float vref
Definition: cooler.h:229
COOLER_ERROR
@ COOLER_ERROR
Definition: cooler.h:243
COOLER_DRV_SEL_I2C
@ COOLER_DRV_SEL_I2C
Definition: cooler.h:192
cooler_read_raw_adc
err_t cooler_read_raw_adc(cooler_t *ctx, uint16_t *raw_adc)
Cooler read raw ADC value function.
cooler_return_value_t
cooler_return_value_t
Cooler Click return value data.
Definition: cooler.h:241
cooler_out_state_t
cooler_out_state_t
Cooler Click cooler states selection.
Definition: cooler.h:252
cooler_sensor_voltage
err_t cooler_sensor_voltage(cooler_t *ctx, float *voltage)
Cooler get sensor voltage result function.
cooler_t::i2c
i2c_master_t i2c
Definition: cooler.h:208
cooler_data_read
err_t cooler_data_read(cooler_t *ctx, uint8_t reg, uint16_t *data_out)
Cooler 16-bit data reading function.
cooler_get_object_temperature
err_t cooler_get_object_temperature(cooler_t *ctx, float *temperature)
Cooler get object temperature function.
cooler_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: cooler.h:231
cooler_get_device_id
err_t cooler_get_device_id(cooler_t *ctx, uint16_t *device_id)
Cooler get device ID function.
cooler_read_voltage
err_t cooler_read_voltage(cooler_t *ctx, float *voltage)
Cooler read voltage level function.
cooler_set_in1_pin
void cooler_set_in1_pin(cooler_t *ctx)
Cooler set IN1 pin state function.
cooler_cfg_t::sda
pin_name_t sda
Definition: cooler.h:223
cooler_get_alert
uint8_t cooler_get_alert(cooler_t *ctx)
Cooler fault indication function.
COOLER_ENABLE
@ COOLER_ENABLE
Definition: cooler.h:253
cooler_generic_write
err_t cooler_generic_write(cooler_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Cooler data writing function.
cooler_cfg_t
Cooler Click configuration object.
Definition: cooler.h:220
cooler_cfg_t::resolution
analog_in_resolution_t resolution
Definition: cooler.h:228
COOLER_DRV_SEL_ADC
@ COOLER_DRV_SEL_ADC
Definition: cooler.h:191
cooler_t::slave_address
uint8_t slave_address
Definition: cooler.h:210
cooler_cfg_t::scl
pin_name_t scl
Definition: cooler.h:222
cooler_t
Cooler Click context object.
Definition: cooler.h:201
cooler_default_cfg
err_t cooler_default_cfg(cooler_t *ctx)
Cooler default configuration function.
cooler_set_vref
err_t cooler_set_vref(cooler_t *ctx, float vref)
Cooler set vref function.
cooler_t::adc
analog_in_t adc
Definition: cooler.h:207
cooler_clear_in2_pin
void cooler_clear_in2_pin(cooler_t *ctx)
Cooler IN2 pin clearing function.