• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15  * Description: Provides hal Tsensor \n
16  *
17  * History: \n
18  * 2023-03-06, Create file. \n
19  */
20 #ifndef HAL_TSENSOR_H
21 #define HAL_TSENSOR_H
22 
23 #include <stdint.h>
24 #include "errcode.h"
25 #include "tsensor_porting.h"
26 
27 #ifdef __cplusplus
28 #if __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31 #endif /* __cplusplus */
32 
33 /**
34  * @defgroup drivers_hal_tsensor_api Tsensor
35  * @ingroup  drivers_hal_tsensor
36  * @{
37  */
38 
39 #define HAL_TSENSOR_TEMP_THRESHOLD_L_MAX ((int8_t)(-40))
40 #define HAL_TSENSOR_TEMP_THRESHOLD_H_MAX ((int8_t)(125))
41 
42 /**
43  * @if Eng
44  * @brief  Definition of the samping mode of hal Tsensor.
45  * @else
46  * @brief  Tsensor设置采样模式定义。
47  * @endif
48  */
49 typedef enum hal_tsensor_samp_mode {
50     HAL_TSENSOR_SAMP_MODE_AVERAGE_ONCE,        /*!< @if Eng 16-point average single report mode.
51                                                     @else   16点平均单次上报模式。  @endif */
52     HAL_TSENSOR_SAMP_MODE_AVERAGE_CYCLE,       /*!< @if Eng 16-point average cyclic reporting mode.
53                                                     @else   16点平均循环上报模式。  @endif */
54     HAL_TSENSOR_SAMP_MODE_SINGLE_POINT_CYCLE,  /*!< @if Eng single point cyclic reporting mode.
55                                                     @else   单点循环上报模式。  @endif */
56     HAL_TSENSOR_SAMP_MODE_MAX_NUM,
57     HAL_TSENSOR_SAMP_MODE_NONE = HAL_TSENSOR_SAMP_MODE_MAX_NUM
58 } hal_tsensor_samp_mode_t;
59 
60 /**
61  * @if Eng
62  * @brief  Definition of the interript type hal Tsensor.
63  * @else
64  * @brief  Tsensor中断类别定义。
65  * @endif
66  */
67 typedef enum hal_tsensor_interript_type {
68     HAL_TSENSOR_INTERRIPT_TYPE_DONE,
69     HAL_TSENSOR_INTERRIPT_TYPE_OUT_THRESH,
70     HAL_TSENSOR_INTERRIPT_TYPE_OVERTEMP,
71     HAL_TSENSOR_INTERRIPT_TYPE_MAX_NUM,
72     HAL_TSENSOR_INTERRIPT_TYPE_NONE = HAL_TSENSOR_INTERRIPT_TYPE_MAX_NUM
73 } hal_tsensor_interript_type_t;
74 
75 /**
76  * @if Eng
77  * @brief  Definition of the set low/high threshold ID of hal Tsensor.
78  * @else
79  * @brief  Tsensor设置高低温度阈值ID定义。
80  * @endif
81  */
82 typedef enum hal_tsensor_set_temp_id {
83     TSENSOR_SET_LOW_TEMP,           /*!< @if Eng Set TSENSOR low temp threshold.
84                                          @else   设置TSENSOR低温阈值。 @endif */
85     TSENSOR_SET_HIGH_TEMP,          /*!< @if Eng Set  TSENSOR high temp threshold.
86                                          @else   设置TSENSOR高温阈值。 @endif */
87     TSENSOR_SET_OVER_TEMP,          /*!< @if Eng Set  TSENSOR over temp threshold.
88                                          @else   设置TSENSOR过温阈值。 @endif */
89     TSENSOR_SET_OFFSET_TEMP,        /*!< @if Eng TSENSOR offset threshold.
90                                          @else   TSENSOR相位。 @endif */
91     TSENSOR_SET_TEMP_MAX
92 } hal_tsensor_set_temp_id_t;
93 
94 /**
95  * @if Eng
96  * @brief  Definition of the calibration point nums.
97  * @else
98  * @brief  Tsensor温度补偿点数量定义。
99  * @endif
100  */
101 typedef enum hal_tsensor_calibration_num {
102     HAL_TSENSOR_CALIBRATION_NUM_ZERO,
103     HAL_TSENSOR_CALIBRATION_NUM_SINGLE,
104     HAL_TSENSOR_CALIBRATION_NUM_TWO,
105     HAL_TSENSOR_CALIBRATION_NUM_MAX,
106     HAL_TSENSOR_CALIBRATION_NUM_NONE = HAL_TSENSOR_CALIBRATION_NUM_MAX
107 } hal_tsensor_calibration_num_t;
108 
109 #if defined(CONFIG_TSENSOR_TEMP_COMPENSATION)
110 /**
111  * @if Eng
112  * @brief  HAL Tsensor calibration configuration.
113  * @else
114  * @brief  HAL Tsensor温度补偿点定义。
115  * @endif
116  */
117 typedef struct {
118     int8_t tsensor_temp;            /*!< @if Eng tsensor temp.
119                                          @else   tsensor传感器温度。  @endif */
120     int8_t environment_temp;        /*!< @if Eng environment temp.
121                                          @else   真实环境温度。  @endif */
122 } hal_tsensor_calibration_point_t;
123 #endif /* CONFIG_TSENSOR_TEMP_COMPENSATION */
124 
125  /**
126  * @if Eng
127  * @brief  Definition of hal TSENSOR callback type.
128  * @param  [in]  temp TSENSOR temperature.
129  * @retval ERRCODE_SUCC   Success.
130  * @retval Other        Failure. For details, see @ref errcode_t.
131  * @else
132  * @brief  TSENSOR hal层回调类型定义。
133  * @param  [in]  temp TSENSOR温度。
134  * @retval ERRCODE_SUCC 成功。
135  * @retval Other        失败,参考 @ref errcode_t 。
136  * @endif
137  */
138 typedef errcode_t (*hal_tsensor_callback_t)(int8_t temp);
139 
140 /**
141  * @if Eng
142  * @brief  Initialize device for hal TSENSOR.
143  * @retval ERRCODE_SUCC   Success.
144  * @retval Other        Failure. For details, see @ref errcode_t .
145  * @else
146  * @brief  HAL层TSENSOR的初始化接口。
147  * @retval ERRCODE_SUCC 成功。
148  * @retval Other        失败,参考 @ref errcode_t 。
149  * @endif
150  */
151 typedef errcode_t (*hal_tsensor_init_t)(void);
152 
153 /**
154  * @if Eng
155  * @brief  Deinitialize device for hal TSENSOR.
156  * @else
157  * @brief  HAL层TSENSOR的去初始化接口。
158  * @endif
159  */
160 typedef void (*hal_tsensor_deinit_t)(void);
161 
162 /**
163  * @if Eng
164  * @brief  Enable and config tsensor samping mode.
165  * @param  [in] mode Tsensor samping mode.
166  * @param  [in] period Tsensor samping period.
167  * @else
168  * @brief  使能并配置Tsensor采样模式。
169  * @param  [in] mode Tsensor采样模式。
170  * @param  [in] period Tsensor采样周期。
171  * @endif
172  */
173 typedef void (*hal_tsensor_set_samp_mode_t)(hal_tsensor_samp_mode_t mode, uint32_t period);
174 
175 /**
176  * @if Eng
177  * @brief  set tsensor temperature high limit, only can be used in interrupt mode.
178  * @param  [in]  id Low/high temp threshold ID.
179  * @param  [in]  temp  The value to set the low/high temp of TSENSOR.
180  * @else
181  * @brief  设置TSENSOR传感器温度阈值,仅可在中断模式下使用。
182  * @param  [in]  id 高低温度ID。
183  * @param  [in]  temp  用于设置TSENSOR高低温度的阈值。
184  * @endif
185  */
186 typedef void (*hal_tsensor_set_temp_threshold_t)(hal_tsensor_set_temp_id_t id, int8_t temp);
187 
188 /**
189  * @if Eng
190  * @brief  enable Interrupt for hal TSENSOR.
191  * @param  [in] interrupt_type tsensor interrupt type.
192  * @param  [in] value Control interrupt switch of the tsensor.
193  * @else
194  * @brief  HAL层TSENSOR的使能中断接口。
195  * @param  [in] interrupt_type TSENSOR中断类型。
196  * @param  [in] value 控制TSENSOR的中断开关。
197  * @endif
198  */
199 typedef void (*hal_tsensor_set_interrupt_t)(hal_tsensor_interript_type_t interrupt_type, bool value);
200 
201  /**
202  * @if Eng
203  * @brief  Register a callback asociated with a TSENSOR interrupt cause.
204  * @param  [in]  interrupt_type tsensor interrupt type.
205  * @param  [in]  callback  The interrupt callback to register.
206  * @else
207  * @brief  注册与TSENSOR中断原因关联的回调。
208  * @param  [in]  interrupt_type TSENSOR中断类型。
209  * @param  [in]  callback  寄存器的中断回调。
210  * @endif
211  */
212 typedef void (*hal_tsensor_set_callback_t)(hal_tsensor_interript_type_t interrupt_type,
213                                            hal_tsensor_callback_t callback);
214 
215 #if defined(CONFIG_TSENSOR_MULTILEVEL)
216 /**
217  * @if Eng
218  * @brief  To set the threshold for the multi-step temperature threshold.
219  * @param  [in]  level Multi-step temperature range value
220  * @param  [in]  temp  Temperature threshold.
221  * @retval ERRCODE_SUCC Success.
222  * @retval Other        Failure. For details, see @ref errcode_t
223  * @else
224  * @brief  设置多步温度阈值的阈值。
225  * @param  [in]  level 多级温度范围值
226  * @param  [in]  temp  温度阈值.
227  * @retval ERRCODE_SUCC 成功。
228  * @retval Other        失败,参考 @ref errcode_t 。
229  * @endif
230  */
231 typedef errcode_t (*hal_tsensor_set_multilevel_value_t)(tsensor_multilevel_value_t level, int16_t temp);
232 
233 /**
234  * @if Eng
235  * @brief  Setting two-point calibration parameters.
236  * @param  [in]  level: Temperature pointer, abscissa is tsensor_temp, ordinate is environment_temp.
237  *         @ref tsensor_calibration_point_t
238  * @param  [in]  callback: Temperature pointer, abscissa is tsensor_temp, ordinate is environment_temp.
239  *         @ref tsensor_calibration_point_t
240  * @retval ERRCODE_SUCC Success.
241  * @retval Other        Failure. For details, see @ref errcode_t
242  * @else
243  * @brief  设置两点校准参数。
244  * @param  [in]  level: 横坐标为传感器温度,纵坐标为环境温度。
245  * @param  [in]  callback: 横坐标为传感器温度,纵坐标为环境温度。
246  * @retval ERRCODE_SUCC 成功。
247  * @retval Other        失败,参考 @ref errcode_t 。
248  * @endif
249  */
250 typedef errcode_t (*hal_tsensor_set_multilevel_en_t)(tsensor_multilevel_en_t level,
251                                                      hal_tsensor_callback_t callback);
252 #endif /* CONFIG_TSENSOR_MULTILEVEL */
253 
254 #if defined(CONFIG_TSENSOR_TEMP_COMPENSATION)
255 /**
256  * @if Eng
257  * @brief  enable tsensor calibration.
258  * @param  [in]  point_data: Temperature compensation point data.
259  * @param  [in]  point_num: Number of temperature compensation points.
260  * @else
261  * @brief  HAL层TSENSOR的使能校准接口。
262  * @param  [in]  point_data: 温度补偿点数据。
263  * @param  [in]  point_num: 温度补偿点数量。
264  * @endif
265  */
266 typedef void (*hal_tsensor_enable_calibration_t)(hal_tsensor_calibration_point_t *point_data, int8_t point_num);
267 #endif /* CONFIG_TSENSOR_TEMP_COMPENSATION */
268 
269 /**
270  * @if Eng
271  * @brief  refresh tsensor temperature.
272  * @else
273  * @brief  HAL层TSENSOR的温度刷新接口。
274  * @endif
275  */
276 typedef void (*hal_tsensor_refresh_temp_t)(void);
277 
278 /**
279  * @if Eng
280  * @brief  get tsensor current temperature.
281  * @param  [in] data temperature pointer, output parameter.
282  * @retval ture: temperature is valid, get tsensor temperature success.
283  * @retval false: temperature is invalid, get tsensor temperature faild.
284  * @else
285  * @brief  HAL层TSENSOR的获取当前温度接口。
286  * @param  [in] data 温度指针,输出参数。
287  * @retval ture  对: 温度有效,获取传感器温度成功。
288  * @retval false 错:温度无效,获取传感器温度失败。
289  * @endif
290  */
291 typedef bool (*hal_tsensor_get_temp_t)(volatile int8_t *data);
292 
293 /**
294  * @if Eng
295  * @brief  Interface between TSENSOR driver and TSENSOR hal.
296  * @else
297  * @brief  Driver层TSENSOR和HAL层TSENSOR的接口。
298  * @endif
299  */
300 typedef struct {
301     hal_tsensor_init_t init;                                 /*!< @if Eng Init device interface.
302                                                                   @else   HAL层TSENSOR的初始化接口 @endif */
303     hal_tsensor_deinit_t deinit;                             /*!< @if Eng Deinit device interface.
304                                                                   @else   HAL层TSENSOR去初始化接口 @endif */
305     hal_tsensor_set_samp_mode_t set_samp_mode;               /*!< @if Eng Control tsensor set samping mode interface.
306                                                                   @else   HAL层TSENSOR设置采样模式接口 @endif */
307     hal_tsensor_set_temp_threshold_t set_temp_threshold;     /*!< @if Eng Control tsensor set temp limit interface.
308                                                                   @else   HAL层TSENSOR设置温度上限接口 @endif */
309     hal_tsensor_set_interrupt_t set_interrupt;               /*!< @if Eng Control device interrupt interface.
310                                                                   @else   HAL层TSENSOR中断使能接口 @endif */
311     hal_tsensor_set_callback_t set_callback;                 /*!< @if Eng Set Callback function.
312                                                                   @else   HAL层TSENSOR设置回调函数接口 @endif */
313 #if defined(CONFIG_TSENSOR_MULTILEVEL)
314     hal_tsensor_set_multilevel_value_t set_multilevel_value; /*!< @if Eng Control tsensor set multilevel threshold.
315                                                                   @else   HAL层TSENSOR设置多级阈值接口 @endif */
316     hal_tsensor_set_multilevel_en_t set_multilevel_en;       /*!< @if Eng Control tsensor set multilevel enable.
317                                                                   @else   HAL层TSENSOR设置多级使能接口 @endif */
318 #endif /* CONFIG_TSENSOR_MULTILEVEL */
319 #if defined(CONFIG_TSENSOR_TEMP_COMPENSATION)
320     hal_tsensor_enable_calibration_t enable_calibration;     /*!< @if Eng Control tsensor calibration interface.
321                                                                   @else   HAL层TSENSOR设置校准使能接口 @endif */
322 #endif /* CONFIG_TSENSOR_TEMP_COMPENSATION */
323     hal_tsensor_refresh_temp_t refresh_temp;                 /*!< @if Eng Control tsensor refresh temp interface.
324                                                                   @else   HAL层TSENSOR温度刷新接口 @endif */
325     hal_tsensor_get_temp_t get_temp;                         /*!< @if Eng Control tsensor get temp interface.
326                                                                   @else   HAL层TSENSOR温度获取接口 @endif */
327 } hal_tsensor_funcs_t;
328 
329 /**
330  * @if Eng
331  * @brief  Init the registers of Tsensor IPs.
332  * @retval ERRCODE_SUCC Success.
333  * @retval Other        Failure. For details, see @ref errcode_t
334  * @else
335  * @brief  初始化寄存器基地址列表。
336  * @retval ERRCODE_SUCC 成功。
337  * @retval Other        失败。参考 @ref errcode_t
338  * @endif
339  */
340 errcode_t hal_tsensor_regs_init(void);
341 
342 /**
343  * @if Eng
344  * @brief  Deinit the registers of Tsensor IPs.
345  * @else
346  * @brief  去初始化寄存器基地址列表。
347  * @endif
348  */
349 void hal_tsensor_regs_deinit(void);
350 
351 /**
352  * @if Eng
353  * @brief  Register @ref hal_tsensor_funcs_t into the g_hal_tsensors_funcs.
354  * @param  [out] funcs Interface between TSENSOR driver and TSENSOR hal.
355  * @retval ERRCODE_SUCC   Success.
356  * @retval Other        Failure. For details, see @ref errcode_t .
357  * @else
358  * @brief  注册 @ref hal_tsensor_funcs_t 到 g_hal_tsensors_funcs 。
359  * @param  [out] funcs Driver层TSENSOR和HAL层TSENSOR的接口实例。
360  * @retval ERRCODE_SUCC 成功。
361  * @retval Other        失败,参考 @ref errcode_t 。
362  * @endif
363  */
364 errcode_t hal_tsensor_register_funcs(hal_tsensor_funcs_t *funcs);
365 
366 /**
367  * @if Eng
368  * @brief  Unregister @ref hal_tsensor_funcs_t from the g_hal_tsensors_funcs.
369  * @return ERRCODE_SUCC   Success.
370  * @retval Other        Failure. For details, see @ref errcode_t .
371  * @else
372  * @brief  从g_hal_tsensors_funcs注销 @ref hal_tsensor_funcs_t 。
373  * @return ERRCODE_SUCC 成功。
374  * @retval Other        失败,参考 @ref errcode_t 。
375  * @endif
376  */
377 errcode_t hal_tsensor_unregister_funcs(void);
378 
379 /**
380  * @if Eng
381  * @brief  Get interface between TSENSOR driver and TSENSOR hal, see @ref hal_tsensor_funcs_t.
382  * @return Interface between TSENSOR driver and TSENSOR hal, see @ref hal_tsensor_funcs_t.
383  * @else
384  * @brief  获取Driver层tsensor和HAL层TSENSOR的接口实例,参考 @ref hal_tsensor_funcs_t 。
385  * @return Driver层tsensor和HAL层TSENSOR的接口实例,参考 @ref hal_tsensor_funcs_t 。
386  * @endif
387  */
388 hal_tsensor_funcs_t *hal_tsensor_get_funcs(void);
389 
390 /**
391  * @}
392  */
393 
394 #ifdef __cplusplus
395 #if __cplusplus
396 }
397 #endif /* __cplusplus */
398 #endif /* __cplusplus */
399 
400 #endif