-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathADS1115_ex.h
246 lines (203 loc) · 8.5 KB
/
ADS1115_ex.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*!\file ADS1115_ex.h
** \author SMFSW
** \copyright MIT (c) 2017-2024, SMFSW
** \brief ADS1115 Driver extensions
** \details ADS1115: Ultra-Small, Low-Power, 16-Bit Analog-to-Digital Converter with Internal Reference
** \note Compatibility with:
** - ADS1113 (restrictions given in datasheet)
** - ADS1114 (restrictions given in datasheet)
** - ADS1115
** \note Compatibility should be assured with:
** - ADS1x1x (check datasheets for compatibility informations)
**/
/****************************************************************/
#ifndef __ADS1115_EX_H__
#define __ADS1115_EX_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "sarmfsw.h"
#include "ADS1115.h"
#if defined(HAL_I2C_MODULE_ENABLED)
/****************************************************************/
// *****************************************************************************
// Section: Constants
// *****************************************************************************
// *****************************************************************************
// Section: Types
// *****************************************************************************
/*!\union uADS1115_REG_MAP
** \brief Union of ADS1115 registry map
** \warning Using the particular union depends on the target endian (Big endian needed)
**/
typedef union uADS1115_REG_MAP {
uint16_t Words[4];
struct PACK__ {
int16_t Conversion; // Conversion register
uADS1115_REG__CFG Config; // Config register
int16_t Lo_Thresh; // Lo_thresh register
int16_t Hi_Thresh; // Hi_thresh register
} Reg;
} uADS1115_REG_MAP;
// *****************************************************************************
// Section: Interface Routines
// *****************************************************************************
/****************************************/
/*** High level methods and functions ***/
/****************************************/
/*!\brief Get conversion time for ADS1115 component (µs)
** \param[in] pCpnt - Pointer to ADS1115 component
** \return Conversion time in µs
**/
uint16_t NONNULL__ ADS1115_Get_conv_us(ADS1115_t * const pCpnt);
/*!\brief Get conversion time for ADS1115 component (ms)
** \param[in] pCpnt - Pointer to ADS1115 component
** \return Conversion time in ms
**/
uint16_t NONNULL__ ADS1115_Get_conv_ms(ADS1115_t * const pCpnt);
/*!\brief Get ADS1115 conversion
** \param[in] pCpnt - Pointer to ADS1115 component
** \return FctERR - error code
**/
FctERR NONNULL__ ADS1115_Get_Conversion(ADS1115_t * const pCpnt);
/*!\brief Set ADS1115 functional mode
** \param[in] pCpnt - Pointer to ADS1115 component
** \param[in] func - ADS1115 function
** \param[in] mode - ADS1115 mode
** \param[in] nb - Number of channels used
** \return FctERR - error code
**/
FctERR NONNULL__ ADS1115_Set_Function(ADS1115_t * const pCpnt, const ADS1115_func func, const ADS1115_mode mode, const uint8_t nb);
/*!\brief Set ADS1115 mode
** \param[in] pCpnt - Pointer to ADS1115 component
** \param[in] mode - Mode
** \return FctERR - error code
**/
FctERR NONNULL__ ADS1115_Set_Mode(ADS1115_t * const pCpnt, const ADS1115_mode mode);
/*!\brief Set ADS1115 gain
** \param[in] pCpnt - Pointer to ADS1115 component
** \param[in] gain - Gain
** \return FctERR - error code
**/
FctERR NONNULL__ ADS1115_Set_Gain(ADS1115_t * const pCpnt, const ADS1115_gain gain);
/*!\brief Set ADS1115 rate
** \param[in] pCpnt - Pointer to ADS1115 component
** \param[in] rate - Data rate
** \return FctERR - error code
**/
FctERR NONNULL__ ADS1115_Set_Rate(ADS1115_t * const pCpnt, const ADS1115_rate rate);
/*!\brief Set ADS1115 Comparator mode
** \param[in] pCpnt - Pointer to ADS1115 component
** \param[in] comp - Comparator Mode
** \return FctERR - error code
**/
FctERR NONNULL__ ADS1115_Set_CompMode(ADS1115_t * const pCpnt, const ADS1115_comp comp);
/*!\brief Set ADS1115 Comparator polarity
** \param[in] pCpnt - Pointer to ADS1115 component
** \param[in] pol - Comparator Polarity
** \return FctERR - error code
**/
FctERR NONNULL__ ADS1115_Set_CompPolarity(ADS1115_t * const pCpnt, const ADS1115_polarity pol);
/*!\brief Set ADS1115 Comparator latch
** \param[in] pCpnt - Pointer to ADS1115 component
** \param[in] latch - Comparator latch
** \return FctERR - error code
**/
FctERR NONNULL__ ADS1115_Set_CompLatch(ADS1115_t * const pCpnt, const ADS1115_latch latch);
/*!\brief Set ADS1115 Comparator queue
** \param[in] pCpnt - Pointer to ADS1115 component
** \param[in] queue - Comparator queue
** \return FctERR - error code
**/
FctERR NONNULL__ ADS1115_Set_CompQueue(ADS1115_t * const pCpnt, const ADS1115_queue queue);
/*!\brief Set ADS1115 low threshold
** \param[in] pCpnt - Pointer to ADS1115 component
** \param[in] thrh - Low threshold value
** \return FctERR - error code
**/
__INLINE FctERR NONNULL_INLINE__ ADS1115_Set_LowThreshold(ADS1115_t * const pCpnt, const int16_t thrh) {
pCpnt->cfg.Lo_Thresh = thrh;
return ADS1115_Write(pCpnt->cfg.slave_inst, (uint16_t *) &thrh, ADS1115__LOW_THRESH); }
/*!\brief Set ADS1115 high threshold
** \param[in] pCpnt - Pointer to ADS1115 component
** \param[in] thrh - High threshold value
** \return FctERR - error code
**/
__INLINE FctERR NONNULL_INLINE__ ADS1115_Set_HighThreshold(ADS1115_t * const pCpnt, const int16_t thrh) {
pCpnt->cfg.Hi_Thresh = thrh;
return ADS1115_Write(pCpnt->cfg.slave_inst, (uint16_t *) &thrh, ADS1115__HI_THRESH); }
/*!\brief Get ADS1115 low threshold
** \param[in] pCpnt - Pointer to ADS1115 component
** \return Low threshold value
**/
__INLINE int16_t NONNULL_INLINE__ ADS1115_Get_LowThreshold(ADS1115_t * const pCpnt) {
return pCpnt->cfg.Lo_Thresh; }
/*!\brief Get ADS1115 high threshold
** \param[in] pCpnt - Pointer to ADS1115 component
** \return High threshold value
**/
__INLINE int16_t NONNULL_INLINE__ ADS1115_Get_HighThreshold(ADS1115_t * const pCpnt) {
return pCpnt->cfg.Hi_Thresh; }
/*!\brief Start ADS1115 conversion
** \param[in] pCpnt - Pointer to ADS1115 component
** \param[in] chan - Channel
** \return FctERR - error code
**/
FctERR NONNULL__ ADS1115_Start_Conversion(ADS1115_t * const pCpnt, const ADS1115_mux chan);
/*!\brief Start ADS1115 Next conversion
** \note Using ADS1115__MODE_CONTINUOUS with ADS1115__FUNC_SINGLE_DIFF or single channel used, function ADS1115_Get_Conversion may be used instead
** \param[in] pCpnt - Pointer to ADS1115 component
** \return FctERR - error code
**/
FctERR NONNULL__ ADS1115_Start_NextConversion(ADS1115_t * const pCpnt);
/*!\brief Get ADS1115 raw channel value
** \param[in] pCpnt - Pointer to ADS1115 component
** \param[in] chan - ADS1115 channel
** \return Raw channel value
**/
__INLINE int16_t NONNULL_INLINE__ ADS1115_Get_raw_value(ADS1115_t * const pCpnt, const uint8_t chan) {
return (chan >= 4) ? 0 : pCpnt->AIN[chan]; }
/*!\brief Get ADS1115 raw channel value in µV
** \param[in] pCpnt - Pointer to ADS1115 component
** \param[in] chan - ADS1115 channel
** \return Converted channel value (µV)
**/
float NONNULL__ ADS1115_Get_converted_value_uV(ADS1115_t * const pCpnt, const uint8_t chan);
/*!\brief Get ADS1115 raw channel value in mV
** \param[in] pCpnt - Pointer to ADS1115 component
** \param[in] chan - ADS1115 channel
** \return Converted channel value (mV)
**/
float NONNULL__ ADS1115_Get_converted_value_mV(ADS1115_t * const pCpnt, const uint8_t chan);
/*!\brief Get ADS1115 raw channel value in V
** \param[in] pCpnt - Pointer to ADS1115 component
** \param[in] chan - ADS1115 channel
** \return Converted channel value (V)
**/
float NONNULL__ ADS1115_Get_converted_value_V(ADS1115_t * const pCpnt, const uint8_t chan);
/*******************/
/*** GPIO access ***/
/*******************/
/*!\brief Ready GPIO pin init for ADS1115
** \weak ADS1115 Ready GPIO pin init may be user implemented if needed
** \param[in] pCpnt - Pointer to ADS1115 component
** \param[in] GPIOx - RDY port
** \param[in] GPIO_Pin - RDY pin
** \param[in] GPIO_Active: RDY pin active state
** \return FctERR - ErrorCode
**/
FctERR NONNULL__ ADS1115_RDY_GPIO_Init(ADS1115_t * const pCpnt, GPIO_TypeDef * const GPIOx, const uint16_t GPIO_Pin, const GPIO_PinState GPIO_Active);
/*!\brief Ready GPIO pin getter for ADS1115
** \weak ADS1115 Ready GPIO pin getter may be user implemented if needed
** \param[in] pCpnt - Pointer to ADS1115 component
** \param[in,out] pState - Pointer to RDY pin state variable (0: inactive, 1: active)
** \return FctERR - ErrorCode
**/
FctERR NONNULL__ ADS1115_RDY_GPIO_Get(ADS1115_t * const pCpnt, bool * const pState);
/****************************************************************/
#endif
#ifdef __cplusplus
}
#endif
#endif /* __ADS1115_EX_H__ */
/****************************************************************/