luat_tp_cst9220.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. #include "luat_base.h"
  2. #include "luat_tp.h"
  3. #include "luat_gpio.h"
  4. #include "luat_mem.h"
  5. #include "luat_rtos.h"
  6. #include "luat_tp_reg.h"
  7. #include "cst92xx_fw.h"
  8. #define LUAT_LOG_TAG "cst92xx"
  9. #include "luat_log.h"
  10. #define CST92XX_ADDRESS (0x5A)
  11. #define CST9217_CHIP_ID_CODE (0x9217)
  12. #define CST9220_CHIP_ID_CODE (0x9220)
  13. #define CST92XX_CHIP_ID (0xA7)
  14. #define CST92XX_STATUS (0x02)
  15. #define CST92XX_POINT1_REG (0x03)
  16. #define CST92XX_CONFIG_SIZE (CST92XX_CONFIG_FRESH - CST92XX_CONFIG_REG + 1)
  17. #define CST92XX_POINT_INFO_NUM (5)
  18. #define CST92XX_TOUCH_NUMBER_MIN (1)
  19. #define CST92XX_TOUCH_NUMBER_MAX (2)
  20. #define CST92XX_REFRESH_RATE_MIN (5)
  21. #define CST92XX_REFRESH_RATE_MAX (20)
  22. #define U8TO16(x1,x2) ((((x1)&0xFF)<<8)|((x2)&0xFF))
  23. #define U8TO32(x1,x2,x3,x4) ((((x1)&0xFF)<<24)|(((x2)&0xFF)<<16)|(((x3)&0xFF)<<8)|((x4)&0xFF))
  24. #define U16REV(x) ((((x)<<8)&0xFF00)|(((x)>>8)&0x00FF))
  25. #define DISABLE (0)
  26. #define ENABLE (1)
  27. enum work_mode{
  28. NOMAL_MODE = 0,
  29. GESTURE_MODE = 1,
  30. LP_MODE = 2,
  31. DEEPSLEEP = 3,
  32. DIFF_MODE = 4,
  33. RAWDATA_MODE = 5,
  34. BASELINE_MODE = 6,
  35. CALIBRATE_MODE = 7,
  36. FAC_TEST_MODE = 8,
  37. ENTER_BOOT_MODE = 0xCA,
  38. };
  39. struct tp_info{
  40. uint8_t fw_sensor_txnum;
  41. uint8_t fw_sensor_rxnum;
  42. uint8_t fw_key_num;
  43. uint8_t reserve;
  44. uint16_t fw_res_y;
  45. uint16_t fw_res_x;
  46. uint32_t fw_boot_time;
  47. uint32_t fw_project_id;
  48. uint32_t fw_chip_type;
  49. uint32_t fw_ver;
  50. uint32_t ic_fw_checksum;
  51. uint32_t fw_module_id;
  52. };
  53. typedef struct hyn_ts_data {
  54. enum work_mode work_mode;
  55. struct tp_info hw_info;
  56. int boot_is_pass;
  57. int need_updata_fw;
  58. }hyn_ts_data_t;
  59. static hyn_ts_data_t hyn_92xxdata = {0};
  60. typedef struct luat_touch_info{
  61. union{
  62. struct {
  63. uint64_t version:8;
  64. uint64_t x_max:16;
  65. uint64_t y_max:16;
  66. uint64_t touch_num:4;
  67. uint64_t :4;
  68. uint64_t int_type:2;
  69. uint64_t :1;
  70. uint64_t x2y:1;
  71. uint64_t stretch_rank:2;
  72. uint64_t :2;
  73. uint64_t :8;
  74. };
  75. uint64_t info;
  76. };
  77. }luat_tp_info_t;
  78. static uint8_t cst92xx_init_state = 0;
  79. static int hyn_wr_reg(luat_tp_config_t* luat_tp_config, uint32_t reg_addr, uint8_t reg_len, uint8_t *rbuf, uint16_t rlen){
  80. int ret = 0,i=0;
  81. uint8_t wbuf[4] = {0};
  82. i = reg_len;
  83. while(i){
  84. i--;
  85. wbuf[i] = reg_addr;
  86. reg_addr >>= 8;
  87. }
  88. if (rlen){
  89. if (luat_tp_config->soft_i2c != NULL){
  90. ret = i2c_soft_send(luat_tp_config->soft_i2c, luat_tp_config->address, (char *)wbuf, reg_len, 1);
  91. ret |= i2c_soft_recv(luat_tp_config->soft_i2c, luat_tp_config->address, (char *)rbuf, rlen);
  92. }else{
  93. ret = luat_i2c_transfer(luat_tp_config->i2c_id, luat_tp_config->address, wbuf, reg_len, rbuf, rlen);
  94. }
  95. }else{
  96. if (luat_tp_config->soft_i2c != NULL){
  97. ret = i2c_soft_send(luat_tp_config->soft_i2c, luat_tp_config->address, (char *)wbuf, reg_len, 1);
  98. }else{
  99. ret = luat_i2c_send(luat_tp_config->i2c_id, luat_tp_config->address, wbuf, reg_len, 1);
  100. }
  101. }
  102. return ret;
  103. }
  104. static int tp_cst92xx_detect(luat_tp_config_t* luat_tp_config){
  105. struct tp_info *ic = &hyn_92xxdata.hw_info;
  106. // LLOGD("module_id: 0x%04x", ic->fw_chip_type);
  107. if ((ic->fw_chip_type != CST9217_CHIP_ID_CODE) && (ic->fw_chip_type != CST9220_CHIP_ID_CODE)){
  108. LLOGE("fw_chip_type error 0x%04x", ic->fw_chip_type);
  109. return -1;
  110. }else{
  111. LLOGI("TP find device CST9220 ,address:0x%02X",luat_tp_config->address);
  112. }
  113. return 0;
  114. }
  115. static int luat_tp_irq_cb(int pin, void *args){
  116. if (cst92xx_init_state == 0){
  117. return -1;
  118. }
  119. luat_tp_config_t* luat_tp_config = (luat_tp_config_t*)args;
  120. luat_tp_irq_enable(luat_tp_config, 0);
  121. luat_rtos_message_send(luat_tp_config->task_handle, 1, args);
  122. return 0;
  123. }
  124. static int tp_cst92xx_set_workmode(luat_tp_config_t* luat_tp_config, enum work_mode mode,uint8_t enable){
  125. int ret = -1;
  126. uint8_t i2c_buf[4] = {0};
  127. uint8_t i = 0;
  128. hyn_92xxdata.work_mode = mode;
  129. if(mode != NOMAL_MODE){
  130. }
  131. for(i=0;i<3;i++){
  132. luat_rtos_task_sleep(2);
  133. if (hyn_wr_reg(luat_tp_config,0xD11E,2,i2c_buf,0)) {
  134. luat_rtos_task_sleep(1);
  135. continue;
  136. }
  137. luat_rtos_task_sleep(2);
  138. if (hyn_wr_reg(luat_tp_config,0x0002,2,i2c_buf,2)) {
  139. luat_rtos_task_sleep(1);
  140. continue;
  141. }
  142. if(i2c_buf[1] == 0x1E){
  143. break;
  144. }
  145. }
  146. switch(mode){
  147. case NOMAL_MODE:
  148. luat_tp_irq_enable(luat_tp_config, 1);
  149. if (hyn_wr_reg(luat_tp_config,0xD109,2,i2c_buf,0)) {
  150. return -1;
  151. }
  152. break;
  153. case GESTURE_MODE:
  154. if (hyn_wr_reg(luat_tp_config,0xD104,2,i2c_buf,0)) {
  155. return -1;
  156. }
  157. break;
  158. case LP_MODE:
  159. if (hyn_wr_reg(luat_tp_config,0xD107,2,i2c_buf,0)) {
  160. return -1;
  161. }
  162. break;
  163. case DIFF_MODE:
  164. if (hyn_wr_reg(luat_tp_config,0xD10D,2,i2c_buf,0)) {
  165. return -1;
  166. }
  167. break;
  168. case RAWDATA_MODE:
  169. if (hyn_wr_reg(luat_tp_config,0xD10A,2,i2c_buf,0)) {
  170. return -1;
  171. }
  172. break;
  173. case FAC_TEST_MODE:
  174. hyn_wr_reg(luat_tp_config,0xD114,2,i2c_buf,0);
  175. break;
  176. case DEEPSLEEP:
  177. hyn_wr_reg(luat_tp_config,0xD105,2,i2c_buf,0);
  178. break;
  179. default :
  180. hyn_92xxdata.work_mode = NOMAL_MODE;
  181. break;
  182. }
  183. return 0;
  184. }
  185. static int tp_cst92xx_updata_tpinfo(luat_tp_config_t* luat_tp_config){
  186. uint8_t buf[30] = {0};
  187. struct tp_info *ic = &hyn_92xxdata.hw_info;
  188. tp_cst92xx_set_workmode(luat_tp_config, 0xff,DISABLE);
  189. if(hyn_wr_reg(luat_tp_config,0xD101,2,buf,0)){
  190. return -1;
  191. }
  192. luat_rtos_task_sleep(5);
  193. //firmware_project_id firmware_ic_type
  194. if(hyn_wr_reg(luat_tp_config,0xD1F4,2,buf,28)){
  195. return -1;
  196. }
  197. ic->fw_project_id = ((uint16_t)buf[17] <<8) + buf[16];
  198. ic->fw_chip_type = ((uint16_t)buf[19] <<8) + buf[18];
  199. //firmware_version
  200. ic->fw_ver = (buf[23]<<24)|(buf[22]<<16)|(buf[21]<<8)|buf[20];
  201. //tx_num rx_num key_num
  202. ic->fw_sensor_txnum = ((uint16_t)buf[1]<<8) + buf[0];
  203. ic->fw_sensor_rxnum = buf[2];
  204. ic->fw_key_num = buf[3];
  205. ic->fw_res_y = (buf[7]<<8)|buf[6];
  206. ic->fw_res_x = (buf[5]<<8)|buf[4];
  207. //fw_checksum
  208. ic->ic_fw_checksum = (buf[27]<<24)|(buf[26]<<16)|(buf[25]<<8)|buf[24];
  209. LLOGD("IC_info project_id:%04x ictype:%04x fw_ver:%x checksum:%#x",ic->fw_project_id,ic->fw_chip_type,ic->fw_ver,ic->ic_fw_checksum);
  210. tp_cst92xx_set_workmode(luat_tp_config,NOMAL_MODE,ENABLE);
  211. return 0;
  212. }
  213. static int tp_cst92xx_hw_reset(luat_tp_config_t* luat_tp_config){
  214. if (luat_tp_config->pin_rst != LUAT_GPIO_NONE){
  215. luat_gpio_set(luat_tp_config->pin_rst, Luat_GPIO_LOW);
  216. luat_rtos_task_sleep(1);
  217. luat_gpio_set(luat_tp_config->pin_rst, Luat_GPIO_HIGH);
  218. }
  219. return 0;
  220. }
  221. static int16_t read_word_from_mem(luat_tp_config_t* luat_tp_config, uint8_t type, uint16_t addr, uint32_t *value){
  222. uint8_t i2c_buf[4] = {0};
  223. i2c_buf[0] = 0xA0;
  224. i2c_buf[1] = 0x10;
  225. i2c_buf[2] = type;
  226. if (tp_i2c_write(luat_tp_config, i2c_buf, 3, NULL, 0)){
  227. return -1;
  228. }
  229. i2c_buf[0] = 0xA0;
  230. i2c_buf[1] = 0x0C;
  231. i2c_buf[2] = addr;
  232. i2c_buf[3] = addr >> 8;
  233. if (tp_i2c_write(luat_tp_config, i2c_buf, 4, NULL, 0)){
  234. return -1;
  235. }
  236. i2c_buf[0] = 0xA0;
  237. i2c_buf[1] = 0x04;
  238. i2c_buf[2] = 0xE4;
  239. if (tp_i2c_write(luat_tp_config, i2c_buf, 3, NULL, 0)){
  240. return -1;
  241. }
  242. for (uint8_t t = 0;; t++){
  243. if (t >= 100){
  244. return -1;
  245. }
  246. if (hyn_wr_reg(luat_tp_config, 0xA004,2,i2c_buf,1)){
  247. continue;
  248. }
  249. if (i2c_buf[0] == 0x00){
  250. break;
  251. }
  252. }
  253. if (hyn_wr_reg(luat_tp_config, 0xA018,2, i2c_buf, 4)){
  254. return -1;
  255. }
  256. *value = ((uint32_t)(i2c_buf[0])) |
  257. (((uint32_t)(i2c_buf[1])) << 8) |
  258. (((uint32_t)(i2c_buf[2])) << 16) |
  259. (((uint32_t)(i2c_buf[3])) << 24);
  260. return 0;
  261. }
  262. static int tp_cst92xx_enter_boot(luat_tp_config_t* luat_tp_config){
  263. uint8_t i2c_buf[4] = {0};
  264. for (uint8_t t = 10; t < 30; t += 2){
  265. tp_cst92xx_hw_reset(luat_tp_config);
  266. luat_rtos_task_sleep(t);
  267. if(hyn_wr_reg(luat_tp_config, 0xA001AA, 3, i2c_buf, 0)){
  268. continue;
  269. }
  270. luat_rtos_task_sleep(1);
  271. if(hyn_wr_reg(luat_tp_config, 0xA002, 2, i2c_buf, 2)){
  272. continue;
  273. }
  274. if ((i2c_buf[0] == 0x55) && (i2c_buf[1] == 0xB0)) {
  275. break;
  276. }
  277. }
  278. if(hyn_wr_reg(luat_tp_config, 0xA00100, 3, i2c_buf, 0)){
  279. return -1;
  280. }
  281. return 0;
  282. }
  283. static int tp_cst92xx_read_chip_id(luat_tp_config_t* luat_tp_config){
  284. int16_t ret = 0;
  285. uint8_t retry = 3;
  286. uint32_t partno_chip_type,module_id;
  287. if (tp_cst92xx_enter_boot(luat_tp_config)){
  288. LLOGE("enter_bootloader error");
  289. return -1;
  290. }
  291. for (; retry > 0; retry--){
  292. // partno
  293. ret = read_word_from_mem(luat_tp_config, 1, 0x077C, &partno_chip_type);
  294. if (ret){
  295. continue;
  296. }
  297. // module id
  298. ret = read_word_from_mem(luat_tp_config, 0, 0x7FC0, &module_id);
  299. if (ret){
  300. continue;
  301. }
  302. if ((partno_chip_type >> 16) == 0xCACA){
  303. partno_chip_type &= 0xffff;
  304. break;
  305. }
  306. }
  307. tp_cst92xx_hw_reset(luat_tp_config);
  308. luat_rtos_task_sleep(30);
  309. LLOGD("partno_chip_type: 0x%04x", partno_chip_type);
  310. LLOGD("module_id: 0x%04x", module_id);
  311. if ((partno_chip_type != CST9217_CHIP_ID_CODE) && (partno_chip_type != CST9220_CHIP_ID_CODE)){
  312. LLOGE("partno_chip_type error 0x%04x", partno_chip_type);
  313. // return -1;
  314. }
  315. return 0;
  316. }
  317. static int tp_cst92xx_gpio_init(luat_tp_config_t* luat_tp_config){
  318. luat_gpio_mode(luat_tp_config->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH);
  319. luat_gpio_mode(luat_tp_config->pin_int, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH);
  320. luat_gpio_set(luat_tp_config->pin_rst, Luat_GPIO_HIGH);
  321. luat_gpio_set(luat_tp_config->pin_int, Luat_GPIO_HIGH);
  322. luat_tp_config->int_type = Luat_GPIO_FALLING;
  323. luat_gpio_t gpio = {0};
  324. gpio.pin = luat_tp_config->pin_int;
  325. gpio.mode = Luat_GPIO_IRQ;
  326. gpio.pull = Luat_GPIO_PULLUP;
  327. gpio.irq = luat_tp_config->int_type;
  328. gpio.irq_cb = luat_tp_irq_cb;
  329. gpio.irq_args = luat_tp_config;
  330. luat_gpio_setup(&gpio);
  331. luat_rtos_task_sleep(10);
  332. return 0;
  333. }
  334. static int tp_cst92xx_init(luat_tp_config_t* luat_tp_config){
  335. int ret = 0;
  336. luat_rtos_task_sleep(50);
  337. luat_tp_config->address = CST92XX_ADDRESS;
  338. tp_cst92xx_gpio_init(luat_tp_config);
  339. tp_cst92xx_hw_reset(luat_tp_config);
  340. luat_rtos_task_sleep(40);
  341. ret = tp_cst92xx_updata_tpinfo(luat_tp_config);
  342. if(ret){
  343. LLOGE("cst92xx_updata_tpinfo failed");
  344. return ret;
  345. }
  346. ret = tp_cst92xx_detect(luat_tp_config);
  347. if (ret){
  348. LLOGE("tp detect fail!");
  349. return ret;
  350. }
  351. ret |= tp_cst92xx_set_workmode(luat_tp_config, NOMAL_MODE,0);
  352. luat_rtos_task_sleep(10);
  353. cst92xx_init_state = 1;
  354. return ret;
  355. }
  356. static int tp_cst92xx_deinit(luat_tp_config_t* luat_tp_config){
  357. cst92xx_init_state = 0;
  358. if (luat_tp_config->pin_int != LUAT_GPIO_NONE){
  359. luat_gpio_close(luat_tp_config->pin_int);
  360. }
  361. if (luat_tp_config->pin_rst != LUAT_GPIO_NONE){
  362. luat_gpio_close(luat_tp_config->pin_rst);
  363. }
  364. return 0;
  365. }
  366. static void tp_cst92xx_read_done(luat_tp_config_t * luat_tp_config){
  367. luat_tp_irq_enable(luat_tp_config, 1);
  368. }
  369. // cst92xx get tp info.
  370. typedef struct {
  371. uint8_t switch_ : 4;
  372. uint8_t id : 4;
  373. uint8_t x_h : 4;
  374. uint8_t : 4;
  375. uint8_t y_h : 4;
  376. uint8_t : 4;
  377. uint8_t y_l : 4;
  378. uint8_t x_l : 4;
  379. uint8_t z : 7;
  380. uint8_t : 1;
  381. } point_data_t;
  382. static int16_t pre_x[CST92XX_TOUCH_NUMBER_MAX] = {-1, -1};
  383. static int16_t pre_y[CST92XX_TOUCH_NUMBER_MAX] = {-1, -1};
  384. static int16_t pre_w[CST92XX_TOUCH_NUMBER_MAX] = {-1, -1};
  385. static uint8_t s_tp_down[CST92XX_TOUCH_NUMBER_MAX];
  386. static uint8_t read_buff[CST92XX_POINT_INFO_NUM * CST92XX_TOUCH_NUMBER_MAX + 5] = {0};
  387. void cst92xx_touch_up(void *buf, int8_t id){
  388. luat_tp_data_t *read_data = (luat_tp_data_t *)buf;
  389. if(s_tp_down[id] == 1){
  390. s_tp_down[id] = 0;
  391. read_data[id].event = TP_EVENT_TYPE_UP;
  392. }else{
  393. read_data[id].event = TP_EVENT_TYPE_NONE;
  394. }
  395. read_data[id].timestamp = luat_mcu_ticks();
  396. read_data[id].width = pre_w[id];
  397. read_data[id].x_coordinate = pre_x[id];
  398. read_data[id].y_coordinate = pre_y[id];
  399. read_data[id].track_id = id;
  400. pre_x[id] = -1; /* last point is none */
  401. pre_y[id] = -1;
  402. pre_w[id] = -1;
  403. }
  404. void cst92xx_touch_down(void *buf, int8_t id, int16_t x, int16_t y, int16_t w){
  405. luat_tp_data_t *read_data = (luat_tp_data_t *)buf;
  406. if (s_tp_down[id] == 1){
  407. read_data[id].event = TP_EVENT_TYPE_MOVE;
  408. }else{
  409. read_data[id].event = TP_EVENT_TYPE_DOWN;
  410. s_tp_down[id] = 1;
  411. }
  412. read_data[id].timestamp = luat_mcu_ticks();
  413. read_data[id].width = w;
  414. read_data[id].x_coordinate = x;
  415. read_data[id].y_coordinate = y;
  416. read_data[id].track_id = id;
  417. pre_x[id] = x; /* save last point */
  418. pre_y[id] = y;
  419. pre_w[id] = w;
  420. }
  421. void cst92xx_read_point(uint8_t *input_buff, void *buf, uint8_t touch_num){
  422. uint8_t *read_buf = input_buff;
  423. uint8_t read_index;
  424. int8_t read_id = 0;
  425. int16_t input_x = 0;
  426. int16_t input_y = 0;
  427. int16_t input_w = 0;
  428. static uint8_t pre_touch = 0;
  429. static int8_t pre_id[CST92XX_TOUCH_NUMBER_MAX] = {0};
  430. if (pre_touch > touch_num){ /* point up */
  431. for (read_index = 0; read_index < pre_touch; read_index++){
  432. uint8_t j;
  433. for (j = 0; j < touch_num; j++){ /* this time touch num */
  434. read_id = j;
  435. if (read_id >= CST92XX_POINT_INFO_NUM){
  436. LLOGE("%s, touch ID %d is out range!\r\n", __func__, read_id);
  437. return;
  438. }
  439. if (pre_id[read_index] == read_id) /* this id is not free */
  440. break;
  441. if (j >= touch_num - 1){
  442. uint8_t up_id;
  443. up_id = pre_id[read_index];
  444. cst92xx_touch_up(buf, up_id);
  445. }
  446. }
  447. }
  448. }
  449. if (touch_num){ /* point down */
  450. uint8_t off_set = 0;
  451. for (read_index = 0; read_index < touch_num; read_index++){
  452. if (read_index){
  453. off_set = read_index * CST92XX_POINT_INFO_NUM + 2;
  454. }
  455. point_data_t* point_buff = &read_buf[off_set];
  456. read_id = point_buff->id;
  457. if (read_id >= CST92XX_POINT_INFO_NUM){
  458. LLOGE("%s, touch ID %d is out range!", __func__, read_id);
  459. return;
  460. }
  461. pre_id[read_index] = read_id;
  462. input_x = point_buff->x_h << 4 | point_buff->x_l; /* x */
  463. input_y = point_buff->y_h << 4 | point_buff->y_l; /* y */
  464. // LLOGD("%s, id %d switch:0x%02x x:%d y:%d z:%d", __func__, point_buff->id,point_buff->switch_,input_x,input_y,point_buff->z);
  465. if (point_buff->switch_ == 0){
  466. cst92xx_touch_up(buf, pre_id[read_index]);
  467. }else{
  468. cst92xx_touch_down(buf, read_id, input_x, input_y, input_w);
  469. }
  470. }
  471. }else if (pre_touch){
  472. for(read_index = 0; read_index < pre_touch; read_index++){
  473. cst92xx_touch_up(buf, pre_id[read_index]);
  474. }
  475. }
  476. pre_touch = touch_num;
  477. }
  478. static int tp_cst92xx_read(luat_tp_config_t* luat_tp_config, luat_tp_data_t *luat_tp_data){
  479. uint8_t touch_num=0, point_status=0;
  480. // uint8_t i2c_buf[CST92XX_TOUCH_NUMBER_MAX*5+5] = {0};
  481. memset(read_buff, 0x00, sizeof(read_buff));
  482. if (hyn_wr_reg(luat_tp_config, 0xD000,2,read_buff,sizeof(read_buff))){
  483. goto exit_;
  484. }
  485. if (read_buff[0] & 0x0F)
  486. {
  487. if (hyn_wr_reg(luat_tp_config, 0xD000AB,3,read_buff,0)){
  488. goto exit_;
  489. }
  490. }
  491. else
  492. {
  493. if (hyn_wr_reg(luat_tp_config, 0xD000CC,3,read_buff,0)){
  494. goto exit_;
  495. }
  496. }
  497. // luat_rtos_task_sleep(8);
  498. // for (size_t i = 0; i < sizeof(read_buff); i++){
  499. // LLOGD("read_buff[%d] = 0x%02X", i, read_buff[i]);
  500. // }
  501. if (read_buff[6] != 0xAB) {
  502. // LLOGE("fail buf[6]=0x%02x",i2c_buf[6]);
  503. goto exit_;
  504. }
  505. touch_num = read_buff[5] & 0x7F;
  506. if (touch_num > CST92XX_TOUCH_NUMBER_MAX) {
  507. LLOGE("fail touch_num=%d",touch_num);
  508. goto exit_;
  509. }
  510. // LLOGD("touch_num = %d",touch_num);
  511. if (touch_num > CST92XX_TOUCH_NUMBER_MAX) {/* point num is not correct */
  512. touch_num = 0;
  513. goto exit_;
  514. }
  515. if (touch_num){
  516. // tp_i2c_read_reg8(luat_tp_config, CST92XX_POINT1_REG, read_buff, touch_num * CST92XX_POINT_INFO_NUM, 0);
  517. }else{
  518. memset(read_buff, 0x00, sizeof(read_buff));
  519. }
  520. cst92xx_read_point(read_buff, luat_tp_data, touch_num);
  521. exit_:
  522. return touch_num;
  523. }
  524. luat_tp_opts_t tp_config_cst92xx = {
  525. .name = "cst92xx",
  526. .init = tp_cst92xx_init,
  527. .deinit = tp_cst92xx_deinit,
  528. .read = tp_cst92xx_read,
  529. .read_done = tp_cst92xx_read_done,
  530. };