-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAMG88_ex.h
216 lines (173 loc) · 7.37 KB
/
AMG88_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
/*!\file AMG88_ex.h
** \author SMFSW
** \copyright MIT (c) 2017-2024, SMFSW
** \brief AMG88 Driver extensions
** \details AMG88: Infrared Array Sensor (Grid-EYE)
**/
/****************************************************************/
#ifndef __AMG88_EX_H__
#define __AMG88_EX_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "sarmfsw.h"
#include "AMG88.h"
#if defined(HAL_I2C_MODULE_ENABLED)
/****************************************************************/
// *****************************************************************************
// Section: Constants
// *****************************************************************************
// *****************************************************************************
// Section: Types
// *****************************************************************************
/*!\union uAMG88_REG_MAP
** \brief Union of AMG88 registry map
**/
typedef union uAMG88_REG_MAP {
uint8_t Bytes[256];
} uAMG88_REG_MAP;
// *****************************************************************************
// Section: Interface Routines
// *****************************************************************************
/****************************************/
/*** High level methods and functions ***/
/****************************************/
/*!\brief Convert raw thermistor temperature to celsius degrees
** \param[in] therm - Raw thermistor value
** \return Thermistor temperature (in �C)
**/
float AMG88_Convert_Thermistor_Raw(const uint16_t therm);
/*!\brief Convert raw pixel temperature to celsius degrees
** \param[in] pixel - Raw pixel value
** \return Pixel temperature (in �C)
**/
float AMG88_Convert_Pixel_Raw(const uint16_t pixel);
/*!\brief Convert temperature to AMG88 temperature coded integer
** \param[in] temp - Temperature value
** \return AMG88 temperature coded integer
**/
uint16_t AMG88_Convert_Temp_To_Int(const float temp);
/*!\brief Get thermistor temperature
** \param[in] pCpnt - Pointer to AMG88 component
** \param[in,out] temp - Pointer to temperature result
** \return Error code
**/
FctERR NONNULL__ AMG88_Get_thermistor_temp(AMG88_t * const pCpnt, float * temp);
/*!\brief Get pixel temperature
** \param[in] pCpnt - Pointer to AMG88 component
** \param[in,out] temp - Pointer to temperature result
** \param[in] pixel - Pixel index to retrieve data
** \return Error code
**/
FctERR NONNULL__ AMG88_Get_pixel_temp(AMG88_t * const pCpnt, float * temp, const uint8_t pixel);
/*!\brief Get all pixels temperature
** \param[in] pCpnt - Pointer to AMG88 component
** \param[in,out] temp - Pointer to temperature result
** \return Error code
**/
FctERR NONNULL__ AMG88_Get_pixels_temp(AMG88_t * const pCpnt, float temp[64]);
/*!\brief AMG88 reset
** \param[in] pCpnt - Pointer to AMG88 component
** \param[in] rst - Reset type
** \return Error code
**/
__INLINE FctERR NONNULL_INLINE__ AMG88_Reset(AMG88_t * const pCpnt, const AMG88_reset rst) {
return AMG88_Write(pCpnt->cfg.slave_inst, &rst, AMG88__RST, 1); }
/*!\brief AMG88 Set mode
** \param[in] pCpnt - Pointer to AMG88 component
** \param[in] mode - AMG88 mode
** \return Error code
**/
__INLINE FctERR NONNULL_INLINE__ AMG88_Set_Mode(AMG88_t * const pCpnt, const AMG88_mode mode) {
return AMG88_Write(pCpnt->cfg.slave_inst, &mode, AMG88__PCTL, 1); }
/*!\brief Set AMG88 Frame Per Seconds multiplier
** \param[in] pCpnt - Pointer to AMG88 component
** \param[in] ten - multiply by 10FPS when set to true
** \return Error code
**/
__INLINE FctERR NONNULL_INLINE__ AMG88_Set_FPS(AMG88_t * const pCpnt, const bool ten) {
uAMG88_REG__FRAME_RATE FPS = { .Bits.FPS = !ten };
return AMG88_Write(pCpnt->cfg.slave_inst, &FPS.Byte, AMG88__FPSC, 1); }
/*!\brief Set AMG88 Moving Average
** \param[in] pCpnt - Pointer to AMG88 component
** \param[in] twice - Twice moving average when set to true
** \return Error code
**/
__INLINE FctERR NONNULL_INLINE__ AMG88_Set_MA(AMG88_t * const pCpnt, const bool twice) {
uAMG88_REG__AVERAGE MA = { .Bits.MAMOD = twice };
return AMG88_Write(pCpnt->cfg.slave_inst, &MA.Byte, AMG88__AVE, 1); }
/*!\brief Set AMG88 Interrupt Level upper limit
** \param[in] pCpnt - Pointer to AMG88 component
** \param[in] temp - Temperature value
** \return Error code
**/
FctERR NONNULL__ AMG88_Set_Interrupt_LVLH(AMG88_t * const pCpnt, const float temp);
/*!\brief Set AMG88 Interrupt Level lower limit
** \param[in] pCpnt - Pointer to AMG88 component
** \param[in] temp - Temperature value
** \return Error code
**/
FctERR NONNULL__ AMG88_Set_Interrupt_LVLL(AMG88_t * const pCpnt, const float temp);
/*!\brief Set AMG88 Interrupt Hysteresis level
** \param[in] pCpnt - Pointer to AMG88 component
** \param[in] temp - Temperature value
** \return Error code
**/
FctERR NONNULL__ AMG88_Set_Interrupt_HYS(AMG88_t * const pCpnt, const float temp);
/*!\brief Set AMG88 Interrupt levels
** \param[in] pCpnt - Pointer to AMG88 component
** \param[in] temp_LVLH - Temperature Interrupt Level upper limit value
** \param[in] temp_LVLL - Temperature Interrupt Level lower limit value
** \param[in] temp_HYS - Temperature Interrupt Hysteresis level value
** \return Error code
**/
FctERR NONNULL__ AMG88_Set_Interrupt_Levels(AMG88_t * const pCpnt, const float temp_LVLH, const float temp_LVLL, const float temp_HYS);
/*!\brief Get interrupts registers
** \param[in] pCpnt - Pointer to AMG88 component
** \param[in,out] interrupts - Pointer to interrupts result
** \return Error code
**/
__INLINE FctERR NONNULL_INLINE__ AMG88_Get_interrupts(AMG88_t * const pCpnt, uAMG88_REG__INT * interrupts) {
return AMG88_Read(pCpnt->cfg.slave_inst, interrupts->Bytes, AMG88__INT0, 8); }
/*!\brief Get thermistor raw value
** \param[in] pCpnt - Pointer to AMG88 component
** \param[in,out] raw - Pointer to thermistor raw result
** \return Error code
**/
__INLINE FctERR NONNULL_INLINE__ AMG88_Get_Thermistor_Raw(AMG88_t * const pCpnt, uint16_t * raw) {
return AMG88_Read_Word(pCpnt->cfg.slave_inst, raw, AMG88__TTHL); }
/*!\brief Get pixel raw value
** \param[in] pCpnt - Pointer to AMG88 component
** \param[in,out] raw - Pointer to pixel raw result
** \param[in] pixel - Pixel index to retrieve data
** \return Error code
**/
__INLINE FctERR NONNULL_INLINE__ AMG88_Get_Pixel_Raw(AMG88_t * const pCpnt, uint16_t * raw, const uint8_t pixel) {
if ((!pixel) || (pixel > 64)) { return ERROR_VALUE; }
return AMG88_Read_Word(pCpnt->cfg.slave_inst, raw, AMG88__T01L + (2 * pixel)); }
/*******************/
/*** GPIO access ***/
/*******************/
/*!\brief Interrupt GPIO pin init for AMG88
** \weak AMG88 Interrupt GPIO pin init may be user implemented if needed
** \param[in] pCpnt - Pointer to AMG88 component
** \param[in] GPIOx - INT port
** \param[in] GPIO_Pin - INT pin
** \param[in] GPIO_Active: INT pin active state
** \return FctERR - ErrorCode
**/
FctERR NONNULL__ AMG88_INT_GPIO_Init(AMG88_t * const pCpnt, GPIO_TypeDef * const GPIOx, const uint16_t GPIO_Pin, const GPIO_PinState GPIO_Active);
/*!\brief Interrupt GPIO pin getter for AMG88
** \weak AMG88 Interrupt GPIO pin getter may be user implemented if needed
** \param[in] pCpnt - Pointer to AMG88 component
** \param[in,out] pState - Pointer to INT pin state variable (0: inactive, 1: active)
** \return FctERR - ErrorCode
**/
FctERR NONNULL__ AMG88_INT_GPIO_Get(AMG88_t * const pCpnt, bool * const pState);
/****************************************************************/
#endif
#ifdef __cplusplus
}
#endif
#endif /* __AMG88_EX_H__ */
/****************************************************************/