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 Tsensor driver api \n 16 * 17 * History: \n 18 * 2022-09-16, Create file. \n 19 */ 20 21 #ifndef TSENSOR_H 22 #define TSENSOR_H 23 24 #include <stdint.h> 25 #include "errcode.h" 26 #include "tsensor_porting.h" 27 28 #ifdef __cplusplus 29 #if __cplusplus 30 extern "C" { 31 #endif /* __cplusplus */ 32 #endif /* __cplusplus */ 33 34 /** 35 * @defgroup drivers_driver_tsensor Tsensor 36 * @ingroup drivers_driver 37 * @{ 38 */ 39 40 #if defined(CONFIG_TSENSOR_TEMP_COMPENSATION) 41 /** 42 * @if Eng 43 * @brief Tsensor calibration configuration. 44 * @else 45 * @brief Tsensor温度补偿点定义。 46 * @endif 47 */ 48 typedef struct tsensor_calibration_point { 49 int8_t tsensor_temp; /*!< @if Eng tsensor temp. 50 @else tsensor传感器温度。 @endif */ 51 int8_t environment_temp; /*!< @if Eng environment temp. 52 @else 真实环境温度。 @endif */ 53 } tsensor_calibration_point_t; 54 #endif /* CONFIG_TSENSOR_TEMP_COMPENSATION */ 55 56 /** 57 * @if Eng 58 * @brief Definition of the samping mode of Tsensor. 59 * @else 60 * @brief Tsensor设置采样模式定义。 61 * @endif 62 */ 63 typedef enum tsensor_samp_mode { 64 TSENSOR_SAMP_MODE_AVERAGE_ONCE, /*!< @if Eng 16-point average single report mode. 65 @else 16点平均单次上报模式。 @endif */ 66 TSENSOR_SAMP_MODE_AVERAGE_CYCLE, /*!< @if Eng 16-point average cyclic reporting mode. 67 @else 16点平均循环上报模式。 @endif */ 68 TSENSOR_SAMP_MODE_SINGLE_POINT_CYCLE, /*!< @if Eng single point cyclic reporting mode. 69 @else 单点循环上报模式。 @endif */ 70 TSENSOR_SAMP_MODE_MAX_NUM, 71 TSENSOR_SAMP_MODE_NONE = TSENSOR_SAMP_MODE_MAX_NUM 72 } tsensor_samp_mode_t; 73 74 /** 75 * @if Eng 76 * @brief Tsensor callback functions. 77 * @param [in] temp Tsensor temperature. 78 * @retval ERRCODE_SUCC Success. 79 * @retval Other Failure. For details, see @ref errcode_t . 80 * @else 81 * @brief Tsensor 回调类型定义。 82 * @param [in] temp Tsensor温度。 83 * @retval ERRCODE_SUCC 成功。 84 * @retval Other 失败,参考 @ref errcode_t 。 85 * @endif 86 */ 87 typedef errcode_t (*uapi_tsensor_callback_t)(int8_t temp); 88 89 /** 90 * @if Eng 91 * @brief Initialize Tsensor. 92 * @retval ERRCODE_SUCC Success. 93 * @retval Other Failure. For details, see @ref errcode_t . 94 * @else 95 * @brief 初始化Tsensor。 96 * @retval ERRCODE_SUCC 成功。 97 * @retval Other 失败,参考 @ref errcode_t 。 98 * @endif 99 */ 100 errcode_t uapi_tsensor_init(void); 101 102 /** 103 * @if Eng 104 * @brief Deinitialize Tsensor. 105 * @retval ERRCODE_SUCC Success. 106 * @retval Other Failure. For details, see @ref errcode_t . 107 * @else 108 * @brief 去初始化Tsensor。 109 * @retval ERRCODE_SUCC 成功。 110 * @retval Other 失败,参考 @ref errcode_t 。 111 * @endif 112 */ 113 errcode_t uapi_tsensor_deinit(void); 114 115 /** 116 * @if Eng 117 * @brief Enable Tsensor inquire mode. 118 * @param [in] mode The Tsensor samp mode. see @ref tsensor_samp_mode_t 119 * @param [in] period Tsensor samping period. 120 * @retval ERRCODE_SUCC Success. 121 * @retval Other Failure. For details, see @ref errcode_t 122 * @else 123 * @brief 配置Tsensor的采样模式。 124 * @param [in] mode 平均单次上报模式 or 平均循环上报模式。 125 * @param [in] period Tsensor采样周期。 126 * @retval ERRCODE_SUCC 成功。 127 * @retval Other 失败,参考 @ref errcode_t 。 128 * @endif 129 */ 130 errcode_t uapi_tsensor_start_inquire_mode(tsensor_samp_mode_t mode, uint32_t period); 131 132 /** 133 * @if Eng 134 * @brief Enable tsensor inquire mode, when The temperature exceeds the threshold completion interrupt. 135 * @param [in] callback: Interrupt callback function pointer. 136 * @param [in] temp_threshold_low: Tsensor low limit, minimum value is -40C. 137 * @param [in] temp_threshold_high: Tsensor high limit, maximum value is 125C. 138 * @retval ERRCODE_SUCC Success. 139 * @retval Other Failure. For details, see @ref errcode_t 140 * @else 141 * @brief 启用tsensor,当温度超出阈值时触发中断。 142 * @param [in] callback: 中断回调函数指针。 143 * @param [in] temp_threshold_low: 温度下限,最低-40C。 144 * @param [in] temp_threshold_high: 温度上限,最高125C。 145 * @retval ERRCODE_SUCC 成功。 146 * @retval Other 失败,参考 @ref errcode_t 。 147 * @endif 148 */ 149 errcode_t uapi_tsensor_enable_outtemp_interrupt(uapi_tsensor_callback_t callback, 150 int8_t temp_threshold_low, 151 int8_t temp_threshold_high); 152 153 /** 154 * @if Eng 155 * @brief Enable Tsensor interrupt mode, when The temperature exceeds the over_temp completion interrupt. 156 * @param [in] callback: Interrupt callback function pointer. 157 * @param [in] overtemp: Tsensor high limit, maximum value is 125C. 158 * @retval ERRCODE_SUCC Success. 159 * @retval Other Failure. For details, see @ref errcode_t 160 * @else 161 * @brief 启用Tsensor,当温度过温时触发中断。 162 * @param [in] callback: 中断回调函数指针。 163 * @param [in] overtemp: 温度上限,最高125C。 164 * @retval ERRCODE_SUCC 成功。 165 * @retval Other 失败,参考 @ref errcode_t 。 166 * @endif 167 */ 168 errcode_t uapi_tsensor_enable_overtemp_interrupt(uapi_tsensor_callback_t callback, int8_t overtemp); 169 170 /** 171 * @if Eng 172 * @brief Enable Tsensor interrupt mode, when the temperature collection completion interrupt. 173 * @param [in] callback: Interrupt callback function pointer. 174 * @retval ERRCODE_SUCC Success. 175 * @retval Other Failure. For details, see @ref errcode_t . 176 * @else 177 * @brief 启用Tsensor,当温度采集完毕时触发中断。 178 * @param [in] callback: 中断回调函数指针。 179 * @retval ERRCODE_SUCC 成功。 180 * @retval Other 失败,参考 @ref errcode_t 。 181 * @endif 182 */ 183 errcode_t uapi_tsensor_enable_done_interrupt(uapi_tsensor_callback_t callback); 184 185 /** 186 * @if Eng 187 * @brief Get Tsensor current temperature. 188 * @param [in] temp: Temperature pointer, output parameter. 189 * @retval ERRCODE_SUCC: Get Tsensor temperature success, temperature is valid. 190 * @retval Other: Get Tsensor temperature faild, temperature is invalid. 191 * @else 192 * @brief 获取当前温度值。 193 * @param [in] temp: 温度指针,输出参数。 194 * @retval ERRCODE_SUCC 成功。 195 * @retval Other 失败,参考 @ref errcode_t 。 196 * @endif 197 */ 198 errcode_t uapi_tsensor_get_current_temp(int8_t *temp); 199 200 #if defined(CONFIG_TSENSOR_TEMP_COMPENSATION) 201 /** 202 * @if Eng 203 * @brief Setting single-point calibration parameters. 204 * @param [in] point: Temperature pointer, abscissa is tsensor_temp, ordinate is environment_temp. 205 * @ref tsensor_calibration_point_t 206 * @else 207 * @brief 设置单点校准参数。 208 * @param [in] point: 横坐标为传感器温度,纵坐标为环境温度。 209 * @endif 210 */ 211 void uapi_tsensor_set_calibration_single_point(tsensor_calibration_point_t *point); 212 213 /** 214 * @if Eng 215 * @brief Setting two-point calibration parameters. 216 * @param [in] point_first: Temperature pointer, abscissa is tsensor_temp, ordinate is environment_temp. 217 * @ref tsensor_calibration_point_t 218 * @param [in] point_second: Temperature pointer, abscissa is tsensor_temp, ordinate is environment_temp. 219 * @ref tsensor_calibration_point_t 220 * @else 221 * @brief 设置两点校准参数。 222 * @param [in] point_first: 横坐标为传感器温度,纵坐标为环境温度。 223 * @param [in] point_second: 横坐标为传感器温度,纵坐标为环境温度。 224 * @endif 225 */ 226 void uapi_tsensor_set_calibration_two_points(const tsensor_calibration_point_t *point_first, 227 const tsensor_calibration_point_t *point_second); 228 #endif /* CONFIG_TSENSOR_TEMP_COMPENSATION */ 229 230 #if defined(CONFIG_TSENSOR_MULTILEVEL) 231 /** 232 * @if Eng 233 * @brief To set the threshold for the multi-step temperature threshold. 234 * @param [in] level Multi-step temperature range value 235 * @param [in] temp Temperature threshold. 236 * @retval ERRCODE_SUCC Success. 237 * @retval Other Failure. For details, see @ref errcode_t 238 * @else 239 * @brief 设置多步温度阈值的阈值。 240 * @param [in] level 多级温度范围值 241 * @param [in] temp 温度阈值. 242 * @retval ERRCODE_SUCC 成功。 243 * @retval Other 失败,参考 @ref errcode_t 。 244 * @endif 245 */ 246 errcode_t uapi_tsensor_set_multilevel_threshold_value(tsensor_multilevel_value_t level, int16_t temp); 247 248 /** 249 * @if Eng 250 * @brief Setting two-point calibration parameters. 251 * @param [in] level: Temperature pointer, abscissa is tsensor_temp, ordinate is environment_temp. 252 * @ref tsensor_calibration_point_t 253 * @param [in] callback: Temperature pointer, abscissa is tsensor_temp, ordinate is environment_temp. 254 * @ref tsensor_calibration_point_t 255 * @retval ERRCODE_SUCC Success. 256 * @retval Other Failure. For details, see @ref errcode_t 257 * @else 258 * @brief 设置两点校准参数。 259 * @param [in] level: 横坐标为传感器温度,纵坐标为环境温度。 260 * @param [in] callback: 横坐标为传感器温度,纵坐标为环境温度。 261 * @retval ERRCODE_SUCC 成功。 262 * @retval Other 失败,参考 @ref errcode_t 。 263 * @endif 264 */ 265 errcode_t uapi_tsensor_set_multilevel_threshold_en(tsensor_multilevel_en_t level, 266 uapi_tsensor_callback_t callback); 267 #endif /* CONFIG_TSENSOR_MULTILEVEL */ 268 269 /** 270 * @} 271 */ 272 273 #ifdef __cplusplus 274 #if __cplusplus 275 } 276 #endif /* __cplusplus */ 277 #endif /* __cplusplus */ 278 279 #endif 280