1 // Copyright (C) 2022 Beken Corporation 2 // 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 #pragma once 16 17 #include <common/bk_include.h> 18 #include <driver/touch_types.h> 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 /* @brief Overview about this API header 25 * 26 */ 27 28 /** 29 * @brief TOUCH API 30 * @defgroup touch.h TOUCH API group 31 * @{ 32 */ 33 34 /** 35 * @brief Init the touch gpio pin 36 * 37 * This API init the GPIO pin corresponding to touch channel: 38 * - Unmap gpio pin function 39 * - Change gpio pin function to touch 40 * - Configure gpio to be high impedance 41 * 42 * This API should be called before any other TOUCH APIs. 43 * 44 * @param 45 * - touch_id: touch channel, channel 0 ~ channel 15 46 * 47 * @return 48 * - BK_OK: succeed 49 * - others: other errors. 50 */ 51 bk_err_t bk_touch_gpio_init(touch_channel_t touch_id); 52 53 /** 54 * @brief enable touch function 55 * 56 * This API enable the touch function: 57 * - Select the touch channel 58 * - Power on the touch module 59 * 60 * 61 * @param 62 * - touch_id: touch channel, channel 0 ~ channel 15 63 * 64 * @return 65 * - BK_OK: succeed 66 * - others: other errors. 67 */ 68 bk_err_t bk_touch_enable(touch_channel_t touch_id); 69 70 /** 71 * @brief disable touch function 72 * 73 * This API disable the touch function: 74 * - Power down the touch module 75 * 76 * 77 * @param 78 * - None 79 * 80 * @return 81 * - BK_OK: succeed 82 */ 83 bk_err_t bk_touch_disable(void); 84 85 /** 86 * @brief config touch function 87 * 88 * This API config the touch function: 89 * - Set touch sensitivity level, the smaller the value, the more sensitive. The range of level value from 0 to 3 90 * - Set touch detect threshold, the range of value from 0 to 7. 91 * - Set touch detect range, 8pF/12pF/19pF/27pF 92 * 93 * 94 * @param 95 * - touch_config: the config of touch work mode 96 * 97 * @return 98 * - BK_OK: succeed 99 * 100 * 101 * Usage example: 102 * 103 * touch_config_t touch_config; 104 * touch_config.sensitivity_level = TOUCH_SENSITIVITY_LEVLE_3; 105 * touch_config.detect_threshold = TOUCH_DETECT_THRESHOLD_6; 106 * touch_config.detect_range = TOUCH_DETECT_RANGE_27PF; 107 * bk_touch_config(&touch_config); 108 */ 109 bk_err_t bk_touch_config(const touch_config_t *touch_config); 110 111 /** 112 * @brief start calibrating touch channel 113 * 114 * This API start calibrating the touch channel that selected. 115 * 116 * 117 * @param 118 * - None 119 * 120 * @return 121 * - BK_OK: succeed 122 */ 123 bk_err_t bk_touch_calibration_start(void); 124 125 /** 126 * @brief enable/disable scan mode of touch channel 127 * 128 * This API enable or disable the scan mode of touch channel. 129 * 130 * 131 * @param 132 * - enable: enable —— 1; disable —— 0; 133 * 134 * @return 135 * - BK_OK: succeed 136 */ 137 bk_err_t bk_touch_scan_mode_enable(uint32_t enable); 138 139 /** 140 * @brief enable manul calibration mode of touch channel 141 * 142 * This API enable the manul calibration mode of touch channel: 143 * - set the calibration value of manul mode; 144 * - enable the manul calibretion mode; 145 * 146 * 147 * @param 148 * - calib_value: calibration value of manul mode, the max value is 0x1FF; 149 * 150 * @return 151 * - BK_OK: succeed 152 */ 153 bk_err_t bk_touch_manul_mode_enable(uint32_t calib_value); 154 155 /** 156 * @brief disable manul calibration mode of touch channel 157 * 158 * This API disable the manul calibration mode of touch channel 159 * 160 * @param 161 * - None 162 * 163 * @return 164 * - BK_OK: succeed 165 */ 166 bk_err_t bk_touch_manul_mode_disable(void); 167 168 /** 169 * @brief set multi channels that need to scan 170 * 171 * This API set multi channels that need to scan 172 * 173 * 174 * @param 175 * - touch_id: the multi channels that need to scan. See the enum of touch_channel_t. 176 * 177 * @return 178 * - BK_OK: succeed 179 */ 180 bk_err_t bk_touch_scan_mode_multi_channl_set(touch_channel_t touch_id); 181 182 /** 183 * @brief enable/disable touch channel interrupt 184 * 185 * This API enable or disable the touch channel interrupt: 186 * - register the interrupt service handle; 187 * - enable or disable the touch interrupt; 188 * 189 * 190 * @param 191 * - touch_id: touch channel, channel 0 ~ channel 15; 192 * - enable: enable —— 1; disable —— 0; 193 * 194 * @return 195 * - BK_OK: succeed 196 */ 197 bk_err_t bk_touch_int_enable(touch_channel_t touch_id, uint32_t enable); 198 199 /** 200 * @brief get the calibration value of touch channel 201 * 202 * This API get the calibration value of touch channel. 203 * 204 * 205 * @param 206 * - None 207 * 208 * @return 209 * - calib_value: the max value is 0x1FF. 210 */ 211 uint32_t bk_touch_get_calib_value(void); 212 213 /** 214 * @brief get the status of touch channel 215 * 216 * This API get the status of touch channel: 217 * 218 * 219 * @param 220 * - None 221 * 222 * @return 223 * - touch_status: the touch status of every channel. One bit corresponding to one channel. 1 —— the channel is touched; 0 —— the channel is idle. 224 */ 225 uint32_t bk_touch_get_touch_status(void); 226 227 /** 228 * @brief Register touch isr 229 * 230 * This API register touch isr 231 * 232 * 233 * @param 234 * - touch_id: touch channel, channel 0 ~ channel 15; 235 * - isr: touch isr callback; 236 * - param: touch isr callback parameter; 237 * 238 * 239 * @return 240 * - BK_OK: succeed 241 * - others: other errors. 242 */ 243 bk_err_t bk_touch_register_touch_isr(touch_channel_t touch_id, touch_isr_t isr, void *param); 244 245 /** 246 * @} 247 */ 248 249 250 #ifdef __cplusplus 251 } 252 #endif 253 254 255