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: SLE low latency. 16 */ 17 18 /** 19 * @defgroup sle_low_latency API 20 * @ingroup SLE 21 * @{ 22 */ 23 24 #ifndef SLE_LOW_LATENCY_H 25 #define SLE_LOW_LATENCY_H 26 27 #include <stdbool.h> 28 #include <stdint.h> 29 #include "errcode.h" 30 #include "sle_common.h" 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 /** 37 * @if Eng 38 * @brief low latency support rate 39 * @else 40 * @brief 低时延调度速率。 41 * @endif 42 */ 43 typedef enum { 44 SLE_LOW_LATENCY_125HZ = 0, /*!< @if Eng 125HZ. 45 @else 125HZ 调度。 @endif */ 46 SLE_LOW_LATENCY_500HZ, /*!< @if Eng 500HZ. 47 @else 500HZ 调度。 @endif */ 48 SLE_LOW_LATENCY_1K, /*!< @if Eng 1000HZ. 49 @else 1000Hz 调度。 @endif */ 50 SLE_LOW_LATENCY_2K, /*!< @if Eng 2000HZ. 51 @else 2000HZ 调度。 @endif */ 52 SLE_LOW_LATENCY_3K, /*!< @if Eng 3000HZ. 53 @else 3000HZ 调度。 @endif */ 54 SLE_LOW_LATENCY_4K, /*!< @if Eng 4000HZ. 55 @else 4000Hz 调度。 @endif */ 56 SLE_LOW_LATENCY_5K, /*!< @if Eng 5000HZ. 57 @else 5000Hz 调度。 @endif */ 58 SLE_LOW_LATENCY_6K, /*!< @if Eng 6000HZ. 59 @else 6000Hz 调度。 @endif */ 60 SLE_LOW_LATENCY_7K, /*!< @if Eng 7000HZ. 61 @else 7000Hz 调度。 @endif */ 62 SLE_LOW_LATENCY_8K, /*!< @if Eng 8000HZ. 63 @else 8000Hz 调度。 @endif */ 64 SLE_LOW_LATENCY_MAX, 65 } sle_low_latency_rate_t; 66 67 /** 68 * @if Eng 69 * @brief low latency enable. 70 * @else 71 * @brief 低时延使能。 72 * @endif 73 */ 74 typedef enum { 75 SLE_LOW_LATENCY_DISABLE = 0, /*!< @if Eng close low latency 76 @else 关闭低时延调度 @endif */ 77 SLE_LOW_LATENCY_ENABLE /*!< @if Eng open low latency 78 @else 打开低时延 @endif */ 79 } sle_low_latency_status_t; 80 81 /** 82 * @if Eng 83 * @brief low latency enable. 84 * @else 85 * @brief 低时延使能。 86 * @endif 87 */ 88 typedef enum { 89 SLE_LOW_LATENCY_VALUE_GET_SUCCESS = 0, /*!< @if Eng get mouse value success 90 @else 获取鼠标数据成功 @endif */ 91 SLE_LOW_LATENCY_VALUE_GET_FAIL /*!< @if Eng get mouse value fail,No data is sent after failure 92 @else 获取鼠标数据失败, 失败后不会发送数据 @endif */ 93 } sle_low_latency_value_set_status_t; 94 95 /** 96 * @brief 星闪层低时延配置接口 97 */ 98 typedef struct { 99 uint16_t conn_id; /*!< @if Eng connection ID. 100 @else 连接ID @endif */ 101 uint8_t enable; /*!< @if Eng low latency enable, { @ref sle_low_latency_rate_t }. 102 @else 低时延使能状态, { @ref sle_low_latency_rate_t } @endif */ 103 uint8_t rate; /*!< @if Eng low latency rate, { @ref sle_low_latency_rate_t }. 104 @else 低时延调度速率, { @ref sle_low_latency_rate_t } @endif */ 105 } sle_set_acb_low_latency_t; 106 107 /** 108 * @if Eng 109 * @brief The callback interface for sending data in mouse mode. 110 * @param [out] button_mask button value. 111 * @param [out] x Mouse x-coordinate. 112 * @param [out] y Mouse y-coordinate. 113 * @param [out] wheel Mouse wheel 114 * @retval error code, { @ref sle_low_latency_value_set_status_t } 115 * @else 116 * @brief Mouse模式数据发送回调接口定义。 117 * @param [out] button_mask 按键值. 118 * @param [out] x 鼠标X坐标. 119 * @param [out] y 鼠标Y坐标. 120 * @param [out] wheel Mouse 滚轮 121 * @retval error code, { @ref sle_low_latency_value_set_status_t } . 122 * @endif 123 */ 124 typedef errcode_t (*low_latency_key_value_set_callback)(int8_t *button_mask, int16_t *x, int16_t *y, int8_t *wheel); 125 126 /** 127 * @if Eng 128 * @brief The general callback interface for sending TLV data for HID device. 129 * @param [inout] len Data length. As an input parameter, len limits the max data length that can send. 130 * Meanwhile as an output parameter, len means length of data to be sent. 131 * User should use the input length first to check the length of user data to be sent. 132 * @retval Pointer to user data. If pointer is NULL, something wrong happened, then send data. 133 * @else 134 * @brief 设置HID设备TLV数据的通用接口。 135 * @param [inout] len 数据长度。当作为入参时,len解引用后表示最大支持的数据长度。当作为出参时,表示用户需要发送的数据长度。 136 * @retval 用户数据指针。如果返回值为NULL,数据不会被发送,否则指针指向的数据会被发送。 137 * @endif 138 */ 139 typedef uint8_t *(*low_latency_general_tx_callback)(uint8_t *len); 140 141 /** 142 * @if Eng 143 * @brief Definition of the low-latency mouse callback function interface. 144 * @else 145 * @brief Mouse侧发送low latency数据回调。 146 * @endif 147 */ 148 typedef struct { 149 low_latency_key_value_set_callback set_value_cb; /*!< @if Eng Set key value and coordinate data callback. 150 @else 设置键值坐标数据回调函数。 @endif */ 151 } sle_low_latency_mouse_callbacks_t; 152 153 /** 154 * @if Eng 155 * @brief Definition of the low-latency mouse callback function interface. 156 * @else 157 * @brief TX侧发送low latency数据回调。 158 * @endif 159 */ 160 typedef struct { 161 low_latency_general_tx_callback low_latency_tx_cb; /*!< @if Eng General callback for setting TX data. 162 @else 设置TX数据的通用接口。 @endif */ 163 } sle_low_latency_tx_callbacks_t; 164 165 /** 166 * @if Eng 167 * @brief Mouse mode initialization. 168 * @par Description: SLE low-latency mouse enable. 169 * @retval error code. 170 * @else 171 * @brief Mouse模式初始化。 172 * @par Description: SLE 低时延鼠标使能。 173 * @retval error code. 174 * @endif 175 */ 176 errcode_t sle_low_latency_mouse_enable(void); 177 178 /** 179 * @if Eng 180 * @brief Definition of Data Obtaining and Invoking in Mouse Mode. 181 * @par Description: Low-Latency Mouse Callback Method Registration. 182 * @param [in] mouse_cbk Callback function. 183 * @retval error code. 184 * @else 185 * @brief Mouse模式数据获取调定义。 186 * @par Description: 低时延鼠标回调方法注册。 187 * @param [in] mouse_cbk 回调函数。 188 * @retval error code. 189 * @endif 190 */ 191 errcode_t sle_low_latency_mouse_register_callbacks(sle_low_latency_mouse_callbacks_t *mouse_cbk); 192 193 /** 194 * @if Eng 195 * @brief Definition of Data Obtaining and Invoking in Mouse Mode. 196 * @par Description: Low-Latency Mouse Callback Method Registration. 197 * @param [in] data Callback function。 198 * @retval error code. 199 * @else 200 * @brief Mouse模式数据获取调定义。 201 * @par Description: 低时延鼠标回调方法注册。 202 * @param [in] data 回调函数。 203 * @retval error code. 204 * @endif 205 */ 206 typedef void(*low_latency_report_callback)(uint8_t *data, uint8_t len); 207 208 /** 209 * @if Eng 210 * @brief Definition of Data Obtaining and Invoking for general using. 211 * @param [in] len data length. 212 * @param [in] value data. 213 * @retval error code. 214 * @else 215 * @brief 通用获取数据回调定义。 216 * @param [in] len 数据长度。 217 * @param [in] value 数据。 218 * @retval error code. 219 * @endif 220 */ 221 typedef void(*low_latency_general_rx_callback)(uint8_t len, uint8_t *value); 222 223 /** 224 * @if Eng 225 * @brief Callback function for dongle to receive data. 226 * @else 227 * @brief Dongle侧接收low latency数据回调。 228 * @endif 229 */ 230 typedef struct { 231 low_latency_report_callback report_cb; /*!< @if Eng Get key value and coordinate data callback. 232 @else 接收键值坐标数据回调函数。 @endif */ 233 } sle_low_latency_dongle_callbacks_t; 234 235 /** 236 * @if Eng 237 * @brief Callback function for rx side to receive data. 238 * @else 239 * @brief RX侧接收low latency数据回调。 240 * @endif 241 */ 242 typedef struct { 243 low_latency_general_rx_callback low_latency_rx_cb; /*!< @if Eng General callback for getting RX data. 244 @else 接收RX数据的通用接口。 @endif */ 245 } sle_low_latency_rx_callbacks_t; 246 247 /** 248 * @if Eng 249 * @brief Mouse mode initialization. 250 * @par Description: SLE low-latency dongle enable. 251 * @attention NULL 252 * @retval error code. 253 * @else 254 * @brief Mouse模式初始化。 255 * @par Description: SLE 低时延Dongle使能。 256 * @attention NULL 257 * @retval error code. 258 * @endif 259 */ 260 errcode_t sle_low_latency_dongle_enable(void); 261 262 /** 263 * @if Eng 264 * @brief Low-Latency Enabling and Scheduling Parameter Configurationn. 265 * @par Description: Low-Latency Enabling and Scheduling Parameter Configuration. 266 * @param [in] conn_id Connect Handle. 267 * @param [in] enable Enable or disable low latency. { @ref sle_low_latency_status_t } 268 * @param [in] rate Report rate. { @ref sle_low_latency_rate_t }. 269 * @retval error code. 270 * @else 271 * @brief 低时延使能和调度参数配置。 272 * @par Description: 低时延使能和调度参数配置。 273 * @param [in] conn_id 连接句柄. 274 * @param [in] enable 是否使能低时延. { @ref sle_low_latency_status_t } 275 * @param [in] rate 回报率. { @ref sle_low_latency_rate_t }. 276 * @retval error code. 277 * @endif 278 */ 279 errcode_t sle_low_latency_set(uint16_t conn_id, uint8_t enable, uint16_t rate); 280 281 /** 282 * @if Eng 283 * @brief Definition of Data Obtaining and Invoking in Mouse Mode. 284 * @par Description: Low-Latency Mouse Callback Method Registration. 285 * @param [in] dongle_cbk Callback function。 286 * @retval error code. 287 * @else 288 * @brief Dongle模式数据获取回调定义。 289 * @par Description: 低时延Dongle回调方法注册。 290 * @param [in] dongle_cbk 回调函数。 291 * @retval error code. 292 * @endif 293 */ 294 errcode_t sle_low_latency_dongle_register_callbacks(sle_low_latency_dongle_callbacks_t *dongle_cbk); 295 296 /** 297 * @if Eng 298 * @brief Definition of Data Obtaining and Invoking in TX Mode. 299 * @par Description: Low-Latency TX Callback Method Registration. 300 * @param [in] tx_cbk Callback function。 301 * @retval error code. 302 * @else 303 * @brief TX模式数据获取回调定义。 304 * @par Description: 低时延TX回调方法注册。 305 * @param [in] tx_cbk 回调函数。 306 * @retval error code. 307 * @endif 308 */ 309 errcode_t sle_low_latency_tx_register_callbacks(sle_low_latency_tx_callbacks_t *tx_cbk); 310 311 /** 312 * @if Eng 313 * @brief Definition of Data Obtaining and Invoking in RX Mode. 314 * @par Description: Low-Latency RX Callback Method Registration. 315 * @param [in] rx_cbk Callback function。 316 * @retval error code. 317 * @else 318 * @brief RX模式数据获取回调定义。 319 * @par Description: 低时延RX回调方法注册。 320 * @param [in] rx_cbk 回调函数。 321 * @retval error code. 322 * @endif 323 */ 324 errcode_t sle_low_latency_rx_register_callbacks(sle_low_latency_rx_callbacks_t *rx_cbk); 325 326 /** 327 * @if Eng 328 * @brief TX mode initialization. 329 * @par Description: SLE low-latency TX enable. 330 * @retval error code. 331 * @else 332 * @brief TX模式初始化。 333 * @par Description: SLE低时延TX使能。 334 * @retval error code. 335 * @endif 336 */ 337 errcode_t sle_low_latency_tx_enable(void); 338 339 /** 340 * @if Eng 341 * @brief RX mode initialization. 342 * @par Description: SLE low-latency RX enable. 343 * @retval error code. 344 * @else 345 * @brief RX模式初始化。 346 * @par Description: SLE低时延RX使能。 347 * @retval error code. 348 * @endif 349 */ 350 errcode_t sle_low_latency_rx_enable(void); 351 352 #ifdef __cplusplus 353 } 354 #endif 355 #endif /* SLE_LOW_LATENCY_H */ 356 /** 357 * @} 358 */ 359