thermo7  2.0.0.0
thermo7.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef THERMO7_H
36 #define THERMO7_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define THERMO7_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
56 
62 #define THERMO7_RETVAL uint8_t
63 
64 #define THERMO7_OK 0x00
65 #define THERMO7_INIT_ERROR 0xFF
66 
72 #define THERMO7_REG_AMBIENT_TEMPERATURE 0x00
73 #define THERMO7_REG_CONFIGURATION 0x01
74 #define THERMO7_REG_HYSTERESIS_TEMPERATURE 0x02
75 #define THERMO7_REG_TEMPERATURE_LIMIT_SET 0x03
76 
82 #define THERMO7_CONFIG_ONE_SHOT_ENABLE (0x01 << 7)
83 #define THERMO7_CONFIG_ONE_SHOT_DISABLE (0x00 << 7)
84 #define THERMO7_CONFIG_ADC_RESOLUTION_9bit (0x00 << 5)
85 #define THERMO7_CONFIG_ADC_RESOLUTION_10bit (0x01 << 5)
86 #define THERMO7_CONFIG_ADC_RESOLUTION_11bit (0x02 << 5)
87 #define THERMO7_CONFIG_ADC_RESOLUTION_12bit (0x03 << 5)
88 #define THERMO7_CONFIG_FAULT_QUEUE_MODE_1 (0x00 << 3)
89 #define THERMO7_CONFIG_FAULT_QUEUE_MODE_2 (0x01 << 3)
90 #define THERMO7_CONFIG_FAULT_QUEUE_MODE_4 (0x02 << 3)
91 #define THERMO7_CONFIG_FAULT_QUEUE_MODE_6 (0x03 << 3)
92 #define THERMO7_CONFIG_ALERT_POLARITY_ACTIVE_HIGH (0x01 << 2)
93 #define THERMO7_CONFIG_ALERT_POLARITY_ACTIVE_LOW (0x00 << 2)
94 #define THERMO7_CONFIG_COMPARATOR_MODE (0x00 << 1)
95 #define THERMO7_CONFIG_INTERRUPT_MODE (0x01 << 1)
96 #define THERMO7_CONFIG_SHUTDOWN_ENABLE 0x01
97 #define THERMO7_CONFIG_SHUTDOWN_DISABLE 0x00
98  // End group macro
101 // --------------------------------------------------------------- PUBLIC TYPES
110 typedef struct
111 {
112  // Input pins
113 
114  digital_in_t int_pin;
115 
116  // Modules
117 
118  i2c_master_t i2c;
119 
120  // ctx variable
121 
122  hal_i2c_address_t slave_address;
123 
124 } thermo7_t;
125 
129 typedef struct
130 {
131  // Communication gpio pins
132 
133  pin_name_t scl;
134  pin_name_t sda;
135 
136  // Additional gpio pins
137 
138  pin_name_t int_pin;
139 
140  // static variable
141 
142  hal_i2c_speed_t i2c_speed;
143  hal_i2c_address_t i2c_address;
144 
145 } thermo7_cfg_t;
146  // End types group
148 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
149 
155 #ifdef __cplusplus
156 extern "C"{
157 #endif
158 
167 void thermo7_cfg_setup ( thermo7_cfg_t *cfg );
168 
177 
188 void thermo7_generic_write ( thermo7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
189 
200 void thermo7_generic_read ( thermo7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
201 
212 
237 void thermo7_set_configuration ( thermo7_t *ctx, uint8_t configuration );
238 
247 
258 void thermo7_set_hysteresis_temperature ( thermo7_t *ctx, int8_t temperature );
259 
268 
276 void thermo7_set_limit_temperature ( thermo7_t *ctx, int16_t temperature );
277 
285 uint8_t thermo7_get_interrupt ( thermo7_t *ctx );
286 
300 void thermo7_set_resolution ( thermo7_t *ctx, uint8_t resolution );
301 
302 #ifdef __cplusplus
303 }
304 #endif
305 #endif // _THERMO7_H_
306  // End public_function group
309 
310 // ------------------------------------------------------------------------- END
#define THERMO7_RETVAL
Definition: thermo7.h:62
int16_t thermo7_get_hysteresis_temperature(thermo7_t *ctx)
Functions for reads Hysteresis Temperature.
void thermo7_cfg_setup(thermo7_cfg_t *cfg)
Config Object Initialization function.
int16_t thermo7_get_limit_temperature(thermo7_t *ctx)
Functions for get Limit Temperature.
void thermo7_set_resolution(thermo7_t *ctx, uint8_t resolution)
Functions for settings ADC resolution measurement.
void thermo7_set_limit_temperature(thermo7_t *ctx, int16_t temperature)
Functions for settings limit Temperature.
hal_i2c_address_t i2c_address
Definition: thermo7.h:143
Click configuration structure definition.
Definition: thermo7.h:129
Click ctx object definition.
Definition: thermo7.h:110
pin_name_t sda
Definition: thermo7.h:134
pin_name_t scl
Definition: thermo7.h:133
THERMO7_RETVAL thermo7_init(thermo7_t *ctx, thermo7_cfg_t *cfg)
Initialization function.
void thermo7_generic_write(thermo7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
hal_i2c_address_t slave_address
Definition: thermo7.h:122
float thermo7_read_ambient_temperature(thermo7_t *ctx)
Functions for reads ambient temperature.
digital_in_t int_pin
Definition: thermo7.h:114
void thermo7_set_hysteresis_temperature(thermo7_t *ctx, int8_t temperature)
Functions for settings Hysteresis Temperature.
hal_i2c_speed_t i2c_speed
Definition: thermo7.h:142
uint8_t thermo7_get_interrupt(thermo7_t *ctx)
Functions for reads state of interrupt pins.
void thermo7_generic_read(thermo7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void thermo7_set_configuration(thermo7_t *ctx, uint8_t configuration)
Functions for configuration chip and measurement.
pin_name_t int_pin
Definition: thermo7.h:138
i2c_master_t i2c
Definition: thermo7.h:118