api_tkey.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #ifndef _API_TKEY_H
  2. #define _API_TKEY_H
  3. typedef struct {
  4. u16 cdpr;
  5. u8 type; //0: disable channel, 1: touch key channel, 2: touch ear channel
  6. u8 ctrim; //cur channel ctrim select
  7. u8 itrim; //cur channel itrim select
  8. } tkey_ch_t;
  9. typedef struct {
  10. const tkey_ch_t *key[4];
  11. union {
  12. struct {
  13. u32 fil_low : 4; //touch key state low state filter length, fil_low + 1
  14. u32 fil_high : 4; //touch key state high state filter length, fil_high + 1
  15. u32 fil_except : 8; //touch key state exception filter length, fil_except + 1
  16. u32 fil_val : 4; //touch key base_cnt valid filter length, fil_val + 1
  17. u32 to_except : 12; //touch key state high timeout length
  18. };
  19. u32 reg_tktmr;
  20. };
  21. union {
  22. struct {
  23. u32 tkpthd : 12; //touch key press threshold
  24. u32 resv0 : 4;
  25. u32 tkrthd : 12; //touch key release threshold
  26. u32 pto_except : 4; //touch key press time out length. (pto_except << 8)
  27. };
  28. u32 reg_tkpthd;
  29. };
  30. union {
  31. struct {
  32. u32 tksthd : 12; //touch key smaller threshold
  33. u32 resv1 : 4;
  34. u32 tklthd : 12; //touch key larger threshold
  35. u32 resv2 : 4;
  36. };
  37. u32 reg_tkethd;
  38. };
  39. union {
  40. struct {
  41. u32 tkvthd : 16; //touch key variance threshold
  42. u32 val : 16; //touch key variance
  43. };
  44. u32 reg_tkvari;
  45. };
  46. union {
  47. struct {
  48. u32 tkarthd : 12; //touch key average range threshold
  49. u32 tkaethd : 4; //touch key average equal threshold
  50. u32 tkvfil : 8; //touch key variance filter count
  51. u32 tkbadd : 8; //touch key base counter adder value
  52. };
  53. u32 reg_tkvarithd;
  54. };
  55. union {
  56. struct {
  57. u32 press_vari_en : 1; //press variance enable bit
  58. u32 rels_vari_en : 1; //release variance enable bit
  59. u32 press_fil_sel : 1; //press variance after filter
  60. u32 rels_fil_sel : 1; //release variance after filter
  61. u32 press_vari_thd : 12; //press variance threshold
  62. u32 rels_vari_thd : 12; //release variance threshold
  63. u32 to_bcnt_thd : 4; //time out base counter threshold
  64. };
  65. u32 reg_tkcon2;
  66. };
  67. //in ear
  68. union {
  69. struct {
  70. u32 ear_fil_low : 4;
  71. u32 ear_fil_high : 4;
  72. u32 ear_fil_except : 8;
  73. u32 ear_fil_val : 4;
  74. u32 tkpwup : 6;
  75. };
  76. u32 reg_tetmr;
  77. };
  78. union {
  79. struct {
  80. u32 tepthd : 12; //touch ear press threshold
  81. u32 resv3 : 4;
  82. u32 terthd : 12; //touch ear release threshold
  83. u32 tefathd : 4;
  84. };
  85. u32 reg_tepthd;
  86. };
  87. union {
  88. struct {
  89. u32 testhd : 12; //touch ear smaller threshold
  90. u32 resv5 : 4;
  91. u32 telthd : 12; //touch ear larger threshold
  92. u32 resv6 : 4;
  93. };
  94. u32 reg_teethd;
  95. };
  96. } tkey_cfg_t;
  97. ///需要备份在全局变量的寄存器
  98. typedef struct {
  99. u32 tkcdpr0;
  100. u32 tkcdpr1;
  101. u32 tktmr;
  102. u32 tkpthd;
  103. u32 tkethd;
  104. u32 tetmr;
  105. } tk_reg_cb_t;
  106. extern tk_reg_cb_t tk_reg_cb;
  107. ///用于蓝牙SPP调试
  108. typedef struct {
  109. u8 te_exp; //touch ear exception pending
  110. u8 tk_exp; //touch key exception pending
  111. u16 tebcnt;
  112. u16 tkbcnt;
  113. volatile u32 flag;
  114. } tk_pnd_cb_t;
  115. extern tk_pnd_cb_t tk_pnd_cb;
  116. typedef struct {
  117. u8 ch; //channel index
  118. u8 cnt;
  119. u8 limit; //方差阈值
  120. u8 stable_cnt;
  121. u8 te_flag; //是否为入耳检测
  122. u8 range_thresh; //rang校准的上限阈值
  123. u16 avg; //平均值
  124. u16 buf[8];
  125. u32 anov_cnt; //满足方差条件计数
  126. psfr_t bcnt_sfr; //BCNT寄存器
  127. u8 fil_except;
  128. u8 range_en; //是否使能range校准
  129. u16 to_cnt; //定时校准时间
  130. u32 tmr_cnt; //8ms单位
  131. u32 thd_save;
  132. s8 thd_avg;
  133. u8 thd_delta;
  134. u8 dcnt;
  135. u8 avg_exp_en;
  136. s16 delta;
  137. u8 slide_ch;
  138. u8 resv0;
  139. } tk_cb_t;
  140. extern tk_cb_t tk_cb;
  141. extern tk_cb_t te_cb;
  142. typedef struct {
  143. u8 tkey_sta;
  144. u32 tkey_ticks;
  145. tk_cb_t *tkey;
  146. } tk_multi_cb_t;
  147. #if USER_TKEY_SLIDE_OLD
  148. ///2点滑动处理
  149. typedef struct {
  150. u8 tkey_sta;
  151. u8 press_cnt;
  152. u8 release_cnt;
  153. u8 release;
  154. u8 slide;
  155. u8 press_flag;
  156. u8 slide_interval_min;
  157. u8 slide_interval_max;
  158. u32 tkey_ticks;
  159. u32 release_tick;
  160. } tk_slide_cb_t;
  161. #else
  162. ///2点滑动处理
  163. typedef struct {
  164. u8 tkey_sta;
  165. u8 press_interval;
  166. u8 release_cnt;
  167. u8 release;
  168. u8 slide;
  169. u8 press_flag;
  170. u8 slide_interval_min;
  171. u8 slide_interval_max;
  172. tk_multi_cb_t *tk_slide;
  173. u32 release_tick;
  174. } tk_slide_cb_t;
  175. #endif
  176. extern tk_slide_cb_t slide_cb[2];
  177. //滑动键值处理结构体
  178. typedef struct {
  179. u16 key_val;
  180. u32 slide_cnt;
  181. u8 slide_timeout;
  182. u16 delay; //滑动检测延时
  183. } key_slide_cb_t;
  184. extern key_slide_cb_t key_slide_cb;
  185. int tkey_init(void *tkey_cfg, u32 first_pwron);
  186. void spp_inpcon_tx(void);
  187. int te_temp_bcnt_calibration(u16 cur_cnt, u16 prev_cnt);
  188. void tkey_bcnt_range_exception(tk_cb_t *s, u16 tkcnt);
  189. u32 tkey_tcnt_variance_calc(tk_cb_t *s, u16 tkcnt);
  190. void tkey_sw_reset(void);
  191. #endif // _API_TKEY_H