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 
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_analog_in.h"
52 #include "drv_i2c_master.h"
53 
74 #define COOLER_REG_SENSOR_VOLTAGE 0x00
75 #define COOLER_REG_LOCAL_TEMPERATURE 0x01
76 #define COOLER_REG_CONFIGURATION 0x02
77 #define COOLER_REG_OBJECT_TEMPERATURE 0x03
78 #define COOLER_REG_STATUS 0x04
79 #define COOLER_REG_STATUS_MASK_AND_ENABLE 0x05
80 #define COOLER_REG_OBJECT_HIGH_LIMIT_TEMP 0x06
81 #define COOLER_REG_OBJECT_LOW_LIMIT_TEMP 0x07
82 #define COOLER_REG_LOCAL_HIGH_LIMIT_TEMP 0x08
83 #define COOLER_REG_LOCAL_LOW_LIMIT_TEMP 0x09
84 #define COOLER_REG_S0_COEFFICIENT 0x0A
85 #define COOLER_REG_A0_COEFFICIENT 0x0B
86 #define COOLER_REG_A1_COEFFICIENT 0x0C
87 #define COOLER_REG_B0_COEFFICIENT 0x0D
88 #define COOLER_REG_B1_COEFFICIENT 0x0E
89 #define COOLER_REG_B2_COEFFICIENT 0x0F
90 #define COOLER_REG_C_COEFFICIENT 0x10
91 #define COOLER_REG_TC0_COEFFICIENT 0X11
92 #define COOLER_REG_TC1_COEFFICIENT 0x12
93 #define COOLER_REG_MANUFACTURER_ID 0x1E
94 #define COOLER_REG_DEVICE_ID 0x1F
95 #define COOLER_REG_MEMORY_ACCESS 0x2A
96  // cooler_reg
98 
113 #define COOLER_CFG_MODEON 0x1000u
114 #define COOLER_CFG_RESET 0x8000u
115 #define COOLER_CFG_1SAMPLE 0x0000u
116 #define COOLER_CFG_2SAMPLE 0x0200u
117 #define COOLER_CFG_4SAMPLE 0x0400u
118 #define COOLER_CFG_8SAMPLE 0x0600u
119 #define COOLER_CFG_16SAMPLE 0x0800u
120 #define COOLER_CFG_ALERTEN 0x0100u
121 #define COOLER_CFG_ALERTF 0x0080u
122 #define COOLER_CFG_TRANSC 0x0040u
123 
128 #define COOLER_STAT_ALERTEN 0x8000u
129 #define COOLER_STAT_CRTEN 0x4000u
130 
135 #define COOLER_DEVICE_ID 0x0078u
136 
141 #define COOLER_TEMPERATURE_SENS 0.03125f
142 #define COOLER_SENSOR_VTG_SENS 0.15625f
143 
148 #define COOLER_ADC_RESOLUTION 0x0FFFu
149 #define COOLER_VREF_3V3 3.3f
150 #define COOLER_VREF_5V 5.0f
151 
157 #define COOLER_SET_DEV_ADDR_0 0x40
158 #define COOLER_SET_DEV_ADDR_1 0x41
159 #define COOLER_SET_DEV_ADDR_2 0x44
160 #define COOLER_SET_DEV_ADDR_3 0x45
161  // cooler_set
163 
178 #define COOLER_MAP_MIKROBUS( cfg, mikrobus ) \
179  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
180  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
181  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
182  cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
183  cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
184  cfg.alr = MIKROBUS( mikrobus, MIKROBUS_INT )
185  // cooler_map // cooler
188 
193 typedef enum
194 {
199 
204 typedef struct
205 {
206  digital_out_t in2;
207  digital_out_t in1;
209  digital_in_t alr;
211  analog_in_t adc;
212  i2c_master_t i2c;
214  uint8_t slave_address;
215  float vref;
217 } cooler_t;
218 
223 typedef struct
224 {
225  pin_name_t an;
226  pin_name_t scl;
227  pin_name_t sda;
228  pin_name_t in2;
229  pin_name_t in1;
230  pin_name_t alr;
232  analog_in_resolution_t resolution;
233  float vref;
235  uint32_t i2c_speed;
236  uint8_t i2c_address;
238 } cooler_cfg_t;
239 
244 typedef enum
245 {
247  COOLER_ERROR = -1
248 
250 
255 typedef enum
256 {
259 
261 
278 
279 
293 err_t cooler_init ( cooler_t *ctx, cooler_cfg_t *cfg );
294 
308 
323 err_t cooler_generic_write ( cooler_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
324 
339 err_t cooler_generic_read ( cooler_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
340 
355 err_t cooler_data_write ( cooler_t *ctx, uint8_t reg, uint16_t data_in );
356 
371 err_t cooler_data_read ( cooler_t *ctx, uint8_t reg, uint16_t *data_out );
372 
386 err_t cooler_get_device_id ( cooler_t *ctx, uint16_t *device_id );
387 
401 err_t cooler_sensor_voltage ( cooler_t *ctx, float *voltage );
402 
416 err_t cooler_get_object_temperature ( cooler_t *ctx, float *temperature );
417 
428 uint8_t cooler_get_alert ( cooler_t *ctx );
429 
441 err_t cooler_read_raw_adc ( cooler_t *ctx, uint16_t *raw_adc );
442 
454 err_t cooler_read_voltage ( cooler_t *ctx, float *voltage );
455 
467 err_t cooler_set_vref ( cooler_t *ctx, float vref );
468 
481 
494 
507 
520 
537 
538 #ifdef __cplusplus
539 }
540 #endif
541 #endif // COOLER_H
542  // cooler
544 
545 // ------------------------------------------------------------------------ END
cooler_cfg_t::an
pin_name_t an
Definition: cooler.h:225
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:194
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:206
COOLER_DISABLE
@ COOLER_DISABLE
Definition: cooler.h:258
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:246
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:228
cooler_t::alr
digital_in_t alr
Definition: cooler.h:209
cooler_cfg_t::in1
pin_name_t in1
Definition: cooler.h:229
cooler_t::in1
digital_out_t in1
Definition: cooler.h:207
cooler_t::vref
float vref
Definition: cooler.h:215
cooler_cfg_t::i2c_address
uint8_t i2c_address
Definition: cooler.h:236
cooler_cfg_t::alr
pin_name_t alr
Definition: cooler.h:230
cooler_cfg_t::vref
float vref
Definition: cooler.h:233
COOLER_ERROR
@ COOLER_ERROR
Definition: cooler.h:247
COOLER_DRV_SEL_I2C
@ COOLER_DRV_SEL_I2C
Definition: cooler.h:196
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:245
cooler_out_state_t
cooler_out_state_t
Cooler Click cooler states selection.
Definition: cooler.h:256
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:212
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:235
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:227
cooler_get_alert
uint8_t cooler_get_alert(cooler_t *ctx)
Cooler fault indication function.
COOLER_ENABLE
@ COOLER_ENABLE
Definition: cooler.h:257
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:224
cooler_cfg_t::resolution
analog_in_resolution_t resolution
Definition: cooler.h:232
COOLER_DRV_SEL_ADC
@ COOLER_DRV_SEL_ADC
Definition: cooler.h:195
cooler_t::slave_address
uint8_t slave_address
Definition: cooler.h:214
cooler_cfg_t::scl
pin_name_t scl
Definition: cooler.h:226
cooler_t
Cooler Click context object.
Definition: cooler.h:205
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:211
cooler_clear_in2_pin
void cooler_clear_in2_pin(cooler_t *ctx)
Cooler IN2 pin clearing function.