thermo7  2.0.0.0
thermo7.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef THERMO7_H
36 #define THERMO7_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define THERMO7_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
66 
72 #define THERMO7_RETVAL uint8_t
73 
74 #define THERMO7_OK 0x00
75 #define THERMO7_INIT_ERROR 0xFF
76 
82 #define THERMO7_REG_AMBIENT_TEMPERATURE 0x00
83 #define THERMO7_REG_CONFIGURATION 0x01
84 #define THERMO7_REG_HYSTERESIS_TEMPERATURE 0x02
85 #define THERMO7_REG_TEMPERATURE_LIMIT_SET 0x03
86 
92 #define THERMO7_CONFIG_ONE_SHOT_ENABLE (0x01 << 7)
93 #define THERMO7_CONFIG_ONE_SHOT_DISABLE (0x00 << 7)
94 #define THERMO7_CONFIG_ADC_RESOLUTION_9bit (0x00 << 5)
95 #define THERMO7_CONFIG_ADC_RESOLUTION_10bit (0x01 << 5)
96 #define THERMO7_CONFIG_ADC_RESOLUTION_11bit (0x02 << 5)
97 #define THERMO7_CONFIG_ADC_RESOLUTION_12bit (0x03 << 5)
98 #define THERMO7_CONFIG_FAULT_QUEUE_MODE_1 (0x00 << 3)
99 #define THERMO7_CONFIG_FAULT_QUEUE_MODE_2 (0x01 << 3)
100 #define THERMO7_CONFIG_FAULT_QUEUE_MODE_4 (0x02 << 3)
101 #define THERMO7_CONFIG_FAULT_QUEUE_MODE_6 (0x03 << 3)
102 #define THERMO7_CONFIG_ALERT_POLARITY_ACTIVE_HIGH (0x01 << 2)
103 #define THERMO7_CONFIG_ALERT_POLARITY_ACTIVE_LOW (0x00 << 2)
104 #define THERMO7_CONFIG_COMPARATOR_MODE (0x00 << 1)
105 #define THERMO7_CONFIG_INTERRUPT_MODE (0x01 << 1)
106 #define THERMO7_CONFIG_SHUTDOWN_ENABLE 0x01
107 #define THERMO7_CONFIG_SHUTDOWN_DISABLE 0x00
108  // End group macro
111 // --------------------------------------------------------------- PUBLIC TYPES
120 typedef struct
121 {
122  // Input pins
123 
124  digital_in_t int_pin;
125 
126  // Modules
127 
128  i2c_master_t i2c;
129 
130  // ctx variable
131 
132  uint8_t slave_address;
133 
134 } thermo7_t;
135 
139 typedef struct
140 {
141  // Communication gpio pins
142 
143  pin_name_t scl;
144  pin_name_t sda;
145 
146  // Additional gpio pins
147 
148  pin_name_t int_pin;
149 
150  // static variable
151 
152  uint32_t i2c_speed;
153  uint8_t i2c_address;
154 
155 } thermo7_cfg_t;
156  // End types group
158 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
159 
165 #ifdef __cplusplus
166 extern "C"{
167 #endif
168 
178 
187 
198 void thermo7_generic_write ( thermo7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
199 
210 void thermo7_generic_read ( thermo7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
211 
222 
247 void thermo7_set_configuration ( thermo7_t *ctx, uint8_t configuration );
248 
257 
268 void thermo7_set_hysteresis_temperature ( thermo7_t *ctx, int8_t temperature );
269 
278 
286 void thermo7_set_limit_temperature ( thermo7_t *ctx, int16_t temperature );
287 
296 
310 void thermo7_set_resolution ( thermo7_t *ctx, uint8_t resolution );
311 
312 #ifdef __cplusplus
313 }
314 #endif
315 #endif // _THERMO7_H_
316  // End public_function group
319 
320 // ------------------------------------------------------------------------- END
thermo7_set_configuration
void thermo7_set_configuration(thermo7_t *ctx, uint8_t configuration)
Functions for configuration chip and measurement.
thermo7_t::slave_address
uint8_t slave_address
Definition: thermo7.h:132
THERMO7_RETVAL
#define THERMO7_RETVAL
Definition: thermo7.h:72
thermo7_generic_write
void thermo7_generic_write(thermo7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
thermo7_generic_read
void thermo7_generic_read(thermo7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
thermo7_set_hysteresis_temperature
void thermo7_set_hysteresis_temperature(thermo7_t *ctx, int8_t temperature)
Functions for settings Hysteresis Temperature.
thermo7_cfg_t
Click configuration structure definition.
Definition: thermo7.h:140
thermo7_t::i2c
i2c_master_t i2c
Definition: thermo7.h:128
thermo7_get_limit_temperature
int16_t thermo7_get_limit_temperature(thermo7_t *ctx)
Functions for get Limit Temperature.
thermo7_t
Click ctx object definition.
Definition: thermo7.h:121
thermo7_get_hysteresis_temperature
int16_t thermo7_get_hysteresis_temperature(thermo7_t *ctx)
Functions for reads Hysteresis Temperature.
thermo7_set_resolution
void thermo7_set_resolution(thermo7_t *ctx, uint8_t resolution)
Functions for settings ADC resolution measurement.
thermo7_cfg_t::i2c_address
uint8_t i2c_address
Definition: thermo7.h:153
thermo7_set_limit_temperature
void thermo7_set_limit_temperature(thermo7_t *ctx, int16_t temperature)
Functions for settings limit Temperature.
thermo7_cfg_t::int_pin
pin_name_t int_pin
Definition: thermo7.h:148
thermo7_cfg_t::scl
pin_name_t scl
Definition: thermo7.h:143
thermo7_read_ambient_temperature
float thermo7_read_ambient_temperature(thermo7_t *ctx)
Functions for reads ambient temperature.
thermo7_get_interrupt
uint8_t thermo7_get_interrupt(thermo7_t *ctx)
Functions for reads state of interrupt pins.
thermo7_cfg_setup
void thermo7_cfg_setup(thermo7_cfg_t *cfg)
Config Object Initialization function.
thermo7_t::int_pin
digital_in_t int_pin
Definition: thermo7.h:124
thermo7_init
THERMO7_RETVAL thermo7_init(thermo7_t *ctx, thermo7_cfg_t *cfg)
Initialization function.
thermo7_cfg_t::sda
pin_name_t sda
Definition: thermo7.h:144
thermo7_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: thermo7.h:152