-
Notifications
You must be signed in to change notification settings - Fork 1
/
lmt01.h
148 lines (127 loc) · 3.9 KB
/
lmt01.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* MIT License
*
* Copyright (c) 2019 Sean Farrelly
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* File lmt01.h
* Created by Sean Farrelly
* Version 1.0
*
*/
/*! @file lmt01.h
* @brief Driver for LMT01 temperature sensor.
*/
#ifndef _LMT01_H_
#define _LMT01_H_
/*! CPP guard */
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
/*!
* @brief Enum defining the different temperature conversion techniques.
* These are either by Equation, or by Lookup Table.
*/
typedef enum {
CONV_TYPE_EQU,
CONV_TYPE_LUT
} lmt_conv_t;
/*!
* @brief lmt API return codes
*/
typedef enum {
LMT_OK,
LMT_E_NULL_PTR,
LMT_E_DEV_NOT_FOUND,
LMT_E_TIMEOUT
} lmt_status_t;
/*!
* @brief Type definitions
*/
typedef void (*lmt_timer_mode_fptr_t)(void* timer);
typedef void (*lmt_timer_cnt_fptr_t)(void* timer, uint32_t *cnt);
typedef void (*lmt_delay_ms_fptr_t)(uint32_t ms);
/*!
* @brief lmt01 device structure
*/
typedef struct
{
/* Timer context pointer */
void *timer;
/* Start timer function pointer */
lmt_timer_mode_fptr_t start_timer;
/* Stop timer function pointer */
lmt_timer_mode_fptr_t stop_timer;
/* Set timer count function pointer */
lmt_timer_cnt_fptr_t set_timer_cnt;
/* Get timer count function pointer */
lmt_timer_cnt_fptr_t get_timer_cnt;
/* Delay (ms) function pointer */
lmt_delay_ms_fptr_t delay_ms;
} lmt01_dev_t;
/**
* @brief Initialise lmt01 device and check if alive.
*
* @param[in] dev : LMT01 device structure
*
* @return result of API execution status
* @retval lmt_status_t
*/
lmt_status_t lmt_init(const lmt01_dev_t *dev);
/**
* @brief Obtains a pulse count reading from the LMT device
* and converts this value to temperature equivalent
* according to the type parameter.
*
* @param[in] lmt : LMT Handle
* @param[out] temp : Temperature reading
* @param[in] type : Conversion type (EQU, LUT)
*
* @return Result of API execution status
* @retval lmt_status_t
*/
lmt_status_t lmt_get_temperature(const lmt01_dev_t *dev, float *temp, lmt_conv_t type);
/**
* @brief Obtain one temperature reading from device by counting pulses.
*
* @param[in] dev : LMT01 device structure.
* @param[out] pulses : Pointer to variable to store pulse count.
*
* @return result of API execution status
* @retval lmt_status_t
*/
lmt_status_t lmt_get_pulse_count(const lmt01_dev_t *dev, uint32_t *pulses);
/**
* @brief Converts a pulse count to temperature equivalent
* according to the type parameter.
*
* @param[in] pulses : Number of pulses
* @param[in] type : Conversion type (EQU, LUT)
*
* @return Result of pulses -> temperature conversion
* @retval temp
*/
float lmt_pulses_to_temperature(uint32_t pulses, lmt_conv_t type);
#ifdef __cplusplus
}
#endif /* End of CPP guard */
#endif /* LMT01_H_ */
/** @}*/