api_tkey.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. u8 dlypr; //channel time period
  9. } tkey_ch_t;
  10. typedef struct {
  11. const tkey_ch_t *key[6];
  12. union {
  13. struct {
  14. u32 fil_low : 4; //touch key state low state filter length, fil_low + 1
  15. u32 fil_high : 4; //touch key state high state filter length, fil_high + 1
  16. u32 fil_except : 8; //touch key state exception filter length, fil_except + 1
  17. u32 fil_val : 4; //touch key base_cnt valid filter length, fil_val + 1
  18. u32 to_except : 12; //touch key state high timeout length
  19. };
  20. u32 reg_tktmr;
  21. };
  22. union {
  23. struct {
  24. u32 tkpthd : 14; //touch key press threshold
  25. u32 tkrthd : 14; //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 : 14; //touch key smaller threshold
  33. u32 tklthd : 14; //touch key larger threshold
  34. u32 resv : 4;
  35. };
  36. u32 reg_tkethd;
  37. };
  38. union {
  39. struct {
  40. u32 tkvthd : 16; //touch key variance threshold
  41. u32 val : 16; //touch key variance
  42. };
  43. u32 reg_tkvari;
  44. };
  45. union {
  46. struct {
  47. u32 tkarthd : 12; //touch key average range threshold
  48. u32 tkaethd : 6; //touch key average equal threshold
  49. u32 tkbadd : 6; //touch key base counter adder value
  50. u32 tkvfil : 8; //touch key variance filter count
  51. };
  52. u32 reg_tkvarithd;
  53. };
  54. union {
  55. struct {
  56. u32 tkresv1 : 24;
  57. u32 tkpwup : 8; //touch key analog setup time
  58. };
  59. u32 reg_tkcon1;
  60. };
  61. union {
  62. struct {
  63. u32 press_vari_en : 1; //press variance enable bit
  64. u32 rels_vari_en : 1; //release variance enable bit
  65. u32 press_fil_sel : 1; //press variance after filter
  66. u32 rels_fil_sel : 1; //release variance after filter
  67. u32 press_vari_thd : 12; //press variance threshold
  68. u32 rels_vari_thd : 12; //release variance threshold
  69. u32 to_bcnt_thd : 4; //time out base counter threshold
  70. };
  71. u32 reg_tkcon2;
  72. };
  73. //in ear
  74. union {
  75. struct {
  76. u32 ear_fil_low : 4;
  77. u32 ear_fil_high : 4;
  78. u32 ear_fil_except : 8;
  79. u32 ear_fil_val : 4;
  80. u32 resv1 : 12;
  81. };
  82. u32 reg_tetmr;
  83. };
  84. union {
  85. struct {
  86. u32 tepthd : 14; //touch ear press threshold
  87. u32 terthd : 14; //touch ear release threshold
  88. u32 resv2 : 4;
  89. };
  90. u32 reg_tepthd;
  91. };
  92. union {
  93. struct {
  94. u32 testhd : 14; //touch ear smaller threshold
  95. u32 telthd : 14; //touch ear larger threshold
  96. u32 resv3 : 4;
  97. };
  98. u32 reg_teethd;
  99. };
  100. } tkey_cfg_t;
  101. typedef struct {
  102. u8 te_exp; //touch ear exception pending
  103. u8 tk_exp; //touch key exception pending
  104. u16 tebcnt;
  105. u16 tkbcnt;
  106. volatile u32 flag;
  107. } tk_pnd_cb_t;
  108. extern tk_pnd_cb_t tk_pnd_cb;
  109. //库使用,勿随意修改
  110. typedef struct {
  111. u8 ch; //channel index
  112. u8 cnt;
  113. u8 limit; //方差阈值
  114. u8 stable_cnt;
  115. u8 te_flag; //是否为入耳检测
  116. u8 range_thresh; //rang校准的上限阈值
  117. u16 avg; //平均值
  118. u16 buf[8];
  119. u32 anov_cnt; //满足方差条件计数
  120. psfr_t bcnt_sfr; //BCNT寄存器
  121. u8 fil_except;
  122. u8 range_en;
  123. u16 temp_tkcnt;
  124. u32 tick;
  125. u16 to_cnt; //定时校准时间
  126. u8 small_stable_cnt;
  127. u8 resv[6];
  128. ///滑动处理
  129. u8 tkey_sta;
  130. u32 tkey_ticks;
  131. u8 press_cnt;
  132. u8 release_cnt;
  133. u8 release;
  134. u8 slide;
  135. u32 release_tick;
  136. u16 slide_interval_min;
  137. u16 slide_interval_max;
  138. } tk_cb_t;
  139. int tkey_init(void *tkey_cfg, u32 first_pwron);
  140. void tkey_sw_reset(void);
  141. void tkey_channel_disable(void *arg);
  142. void tkey_tebcnt_set(u16 val);
  143. void spp_inpcon_tx(void);
  144. void tkey_bcnt_range_exception(tk_cb_t *s, tk_cb_t *p, u16 tkcnt);
  145. int te_temp_bcnt_calibration(u16 cur_cnt, u16 prev_cnt);
  146. int tk_temp_bcnt_calibration(u16 cur_cnt, u16 prev_cnt);
  147. #endif // _API_TKEY_H