Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
thermo3_click.h
Go to the documentation of this file.
1 
5 /*
6  * Copyright (c) 2022, Cascoda Ltd.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the copyright holder nor the
17  * names of its contributors may be used to endorse or promote products
18  * derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*
33  * Example click interface driver
34 */
35 
36 #ifndef THERMO3_CLICK_H
37 #define THERMO3_CLICK_H
38 
39 #include <stdint.h>
40 
41 /* use alarm pin as interrupt (1) with continuous mode instead of polling (0) with one-shot mode */
42 #define THERMO3_USE_INTERRUPT 0
43 
44 /* all tmp102 registers are 2 bytes */
45 #define TMP102_REGLEN 2
46 /* I2C slave address + register address */
47 #define TMP102_ADDLEN 2
48 
49 /* tmp102 i2c address */
50 #define TMP102_I2C_ADDR 0x48
51 
52 /* register addresses */
53 #define MIKROSDK_THERMO3_REGADD_TEMP 0x00
54 #define MIKROSDK_THERMO3_REGADD_CONFIG 0x01
55 #define MIKROSDK_THERMO3_REGADD_TLOW 0x02
56 #define MIKROSDK_THERMO3_REGADD_THIGH 0x03
57 
58 /* configuration register bit mapping */
59 #define MIKROSDK_THERMO3_CONFIG_SHUTDOWN 0x01
60 #define MIKROSDK_THERMO3_CONFIG_TMMODE 0x02
61 #define MIKROSDK_THERMO3_CONFIG_ONESHOT 0x80
62 
63 /* configuration register byte 1 default */
64 #define MIKROSDK_THERMO3_DEFAULT_CONFIG_0 0x60
65 /* configuration register byte 2 default */
66 #define MIKROSDK_THERMO3_DEFAULT_CONFIG_1 0xA0
67 
68 #if (THERMO3_USE_INTERRUPT)
69 /* continuous mode */
70 #define MIKROSDK_THERMO3_CONFIG \
71  ((MIKROSDK_THERMO3_DEFAULT_CONFIG_1 << 8) + (MIKROSDK_THERMO3_DEFAULT_CONFIG_0 | MIKROSDK_THERMO3_CONFIG_TMMODE))
72 #else
73 /* one-shot mode */
74 #define MIKROSDK_THERMO3_CONFIG \
75  ((MIKROSDK_THERMO3_DEFAULT_CONFIG_1 << 8) + (MIKROSDK_THERMO3_DEFAULT_CONFIG_0 | MIKROSDK_THERMO3_CONFIG_ONESHOT | \
76  MIKROSDK_THERMO3_CONFIG_TMMODE | MIKROSDK_THERMO3_CONFIG_SHUTDOWN))
77 #endif
78 
79 /* default temperature limits (in T['C] * 16) */
80 #define MIKROSDK_THERMO3_TEMP_LIMIT_LOW 0x01B0 /* +27.0000 'C */
81 #define MIKROSDK_THERMO3_TEMP_LIMIT_HIGH 0x01C8 /* +28.5000 'C */
82 
83 /* timing parameters [ms] */
84 #define THERMO3_T_POWERUP 35 /* tmp102 35 ms power-up (conversion time max) */
85 
86 /* alarm active low */
88 {
91 };
92 
93 /* data acquisition status */
95 {
96  THERMO3_ST_OK = 0, /* read values ok */
97  THERMO3_ST_ALARM_CLEARED = 1, /* alarm has been cleared (values ok) */
98  THERMO3_ST_ALARM_TRIGGERED = 2, /* alarm has been triggered (values ok) */
99  THERMO3_ST_FAIL = 3 /* acquisition failed */
100 };
101 
102 /* new functions */
103 uint8_t MIKROSDK_THERMO3_get_config(uint16_t *configuration);
104 uint8_t MIKROSDK_THERMO3_set_config(uint16_t config);
105 uint8_t MIKROSDK_THERMO3_get_temperature_limits(uint16_t *temp_limit_low, uint16_t *temp_limit_high);
106 uint8_t MIKROSDK_THERMO3_set_temperature_limits(uint16_t temp_limit_low, uint16_t temp_limit_high);
107 uint8_t MIKROSDK_THERMO3_get_alarm(void);
109 uint8_t MIKROSDK_THERMO3_get_temperature(uint16_t *temperature);
110 void MIKROSDK_THERMO3_pin_mapping(uint8_t alarm);
111 uint8_t MIKROSDK_THERMO3_Initialise(void);
112 uint8_t MIKROSDK_THERMO3_Reinitialise(void);
113 uint8_t MIKROSDK_THERMO3_Acquire(uint16_t *temperature);
114 
115 #endif // THERMO3_CLICK_H
uint8_t MIKROSDK_THERMO3_get_alarm(void)
Definition: thermo3.c:144
void MIKROSDK_THERMO3_pin_mapping(uint8_t alarm)
Definition: thermo3.c:261
uint8_t MIKROSDK_THERMO3_get_temperature_limits(uint16_t *temp_limit_low, uint16_t *temp_limit_high)
Definition: thermo3.c:181
uint8_t MIKROSDK_THERMO3_get_config(uint16_t *configuration)
Definition: thermo3.c:154
uint8_t MIKROSDK_THERMO3_set_config(uint16_t config)
Definition: thermo3.c:167
uint8_t MIKROSDK_THERMO3_Reinitialise(void)
Definition: thermo3.c:296
thermo3_alarm_state
Definition: thermo3_click.h:88
@ THERMO3_ALARM_TRIGGERED
Definition: thermo3_click.h:89
@ THERMO3_ALARM_CLEARED
Definition: thermo3_click.h:90
uint8_t MIKROSDK_THERMO3_Acquire(uint16_t *temperature)
Definition: thermo3.c:312
uint8_t MIKROSDK_THERMO3_get_temperature(uint16_t *temperature)
Definition: thermo3.c:228
uint8_t MIKROSDK_THERMO3_Initialise(void)
Definition: thermo3.c:267
uint8_t MIKROSDK_THERMO3_alarm_triggered(void)
Definition: thermo3.c:136
thermo3_status
Definition: thermo3_click.h:95
@ THERMO3_ST_ALARM_CLEARED
Definition: thermo3_click.h:97
@ THERMO3_ST_ALARM_TRIGGERED
Definition: thermo3_click.h:98
@ THERMO3_ST_OK
Definition: thermo3_click.h:96
@ THERMO3_ST_FAIL
Definition: thermo3_click.h:99
uint8_t MIKROSDK_THERMO3_set_temperature_limits(uint16_t temp_limit_low, uint16_t temp_limit_high)
Definition: thermo3.c:209