t_lev_decode.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #include "t_lev_decode.h"
  2. #if 0
  3. #include "t_icu.h"
  4. #include "t_gpio.h"
  5. #include "t_timer.h"
  6. #include "bk3231s_reg.h"
  7. uint8_t test_uart_tx[] ={0xab};
  8. //int test_ir_count;
  9. uint8_t ir_state = 0;
  10. uint8_t ir_cnt = 0;
  11. uint8_t ir_index = 0;
  12. uint8_t g_ir_code[4] = {0};
  13. uint8_t ir_tmp = 0;
  14. uint8_t g_ir_recv_done_flag = 0;
  15. //uint8_t test_ir2_count;
  16. uint32_t ir_check_clock;
  17. extern int timer_flag;
  18. void my_rx_timer_stop()
  19. {
  20. Timer_Stop(0);
  21. GPIO_output(0, 7, 0);
  22. }
  23. ///time count us
  24. void my_rx_timer_start(int time_count)
  25. {
  26. my_rx_timer_stop();
  27. timer_flag =0;
  28. Timer_Start(0,time_count);
  29. }
  30. void ir_timer_handle(uint8_t ir_gpio)
  31. {
  32. GPIO_output(0, 6, 1);
  33. GPIO_output(0, 6, 0);
  34. if(ir_gpio == 0)
  35. {
  36. if(ir_state == 0)
  37. {
  38. ir_state = 1;
  39. GpioGenCfg(MODE_KEY_PORT,MODE_KEY_PIN,GPIO_MODE_GPIO,GPIO_IO_IN,GPIO_PULL_UP);
  40. GpioIntCfg(MODE_KEY_PORT,MODE_KEY_PIN,EN,GPIO_INTERRUPT_EDGE_UP);
  41. }
  42. else if(ir_state == 1)
  43. {
  44. ir_state = 0;
  45. }
  46. else if(ir_state == 2)
  47. {
  48. if(ir_index >= 8)
  49. {
  50. ir_index = 0;
  51. g_ir_code[ir_cnt] = ir_tmp;
  52. ir_tmp = 0;
  53. ir_cnt++;
  54. if(ir_cnt >= 4)
  55. {
  56. ir_cnt = 0;
  57. ir_state = 0;
  58. g_ir_recv_done_flag = 1;
  59. //U_UART_PRINTF("BB~:%x,%x,%x,%x\r\n", g_ir_code[0],g_ir_code[1],g_ir_code[2],g_ir_code[3]);
  60. GpioGenCfg(MODE_KEY_PORT,MODE_KEY_PIN,GPIO_MODE_GPIO,GPIO_IO_IN,GPIO_PULL_UP);
  61. GpioIntCfg(MODE_KEY_PORT,MODE_KEY_PIN,EN,GPIO_INTERRUPT_EDGE_DOWN);
  62. }
  63. }
  64. }
  65. }
  66. else if(ir_gpio == 1)
  67. {
  68. //U_UART_PRINTF("ir_d\n");
  69. if(ir_state == 0)
  70. {
  71. ir_state = 0;
  72. }
  73. else if(ir_state == 1)
  74. {
  75. ir_state = 2;
  76. }
  77. else if(ir_state == 2)
  78. {
  79. ir_tmp |= 0x01;
  80. if(ir_index >= 8)
  81. {
  82. ir_index = 0;
  83. g_ir_code[ir_cnt] = ir_tmp;
  84. ir_tmp = 0;
  85. ir_cnt++;
  86. if(ir_cnt >= 4)
  87. {
  88. ir_cnt = 0;
  89. ir_state = 0;
  90. g_ir_recv_done_flag = 1;
  91. //Enable_ICU_Intr();
  92. //U_UART_PRINTF("AA:%x,%x,%x,%x\r\n",g_ir_code[0],g_ir_code[1],g_ir_code[2],g_ir_code[3]);
  93. GpioGenCfg(MODE_KEY_PORT,MODE_KEY_PIN,GPIO_MODE_GPIO,GPIO_IO_IN,GPIO_PULL_UP);
  94. GpioIntCfg(MODE_KEY_PORT,MODE_KEY_PIN,EN,GPIO_INTERRUPT_EDGE_DOWN);
  95. REG_AHB0_FIQ_PRIORITY_EN |= INT_STATUS_GPIO;
  96. }
  97. }
  98. }
  99. }
  100. }
  101. void clean_ir_status(void)
  102. {
  103. ir_cnt = 0;
  104. ir_state = 0;
  105. ir_index =0;
  106. }
  107. extern void deg_io_toggle(void);
  108. //extern int ir_check_clock;
  109. void ir_callback(void)
  110. {
  111. GPIO_output(0, 4, 0);
  112. GPIO_output(0, 4, 1);
  113. //U_UART_PRINTF("ir_c\n");
  114. //deg_io_toggle();
  115. // return;
  116. if(!GpioGetIn(MODE_KEY_PORT,MODE_KEY_PIN))
  117. {
  118. //U_UART_PRINTF("ir_d\n");
  119. if(ir_state == 0)
  120. {
  121. my_rx_timer_start(8000);
  122. }
  123. else if(ir_state == 1)
  124. {
  125. ir_check_clock = HW_Get_Native_Clk_Avoid_Race()+32000;
  126. ir_state = 0;
  127. }
  128. else if(ir_state == 2)
  129. {
  130. ir_check_clock = HW_Get_Native_Clk_Avoid_Race()+32000;
  131. }
  132. }
  133. else if(GpioGetIn(MODE_KEY_PORT,MODE_KEY_PIN))
  134. {
  135. //U_UART_PRINTF("ir_p\n");
  136. // bprintf("~%d %d %d %d\r\n",ir_state,ir_cnt,ir_index,timer_cnt);
  137. if(ir_state == 0)
  138. {
  139. GpioGenCfg(MODE_KEY_PORT,MODE_KEY_PIN,GPIO_MODE_GPIO,GPIO_IO_IN,GPIO_PULL_UP);
  140. GpioIntCfg(MODE_KEY_PORT,MODE_KEY_PIN,EN,GPIO_INTERRUPT_EDGE_DOWN);
  141. }
  142. else if(ir_state == 1)
  143. {
  144. ir_check_clock = HW_Get_Native_Clk_Avoid_Race() + 32000;
  145. my_rx_timer_start(2400);
  146. }
  147. else if(ir_state == 2)
  148. {
  149. ir_check_clock = HW_Get_Native_Clk_Avoid_Race() + 32000;
  150. ir_tmp <<= 1;
  151. ir_index++;
  152. my_rx_timer_start(650);
  153. }
  154. }
  155. }
  156. void t_ir_init(void)
  157. {
  158. GPIO_config(0, 4, 1);
  159. GPIO_output(0, 4, 0);
  160. GPIO_config(0, 6, 1);
  161. GPIO_output(0, 6, 0);
  162. //bprintf("Key_init handle\r\n");
  163. //Timer_Initial();
  164. IcuPphCfg( ICU_PPH_GPIO,
  165. ICU_MCU_CLK_SRC_APH,
  166. ICU_CLK_SRC_FREQ_DPLL_96M,
  167. ICU_CLK_PRE_DIV_NONE,
  168. ICU_CLK_EN,
  169. EN,
  170. EN,
  171. DISEN);
  172. GpioGenCfg(MODE_KEY_PORT,MODE_KEY_PIN,GPIO_MODE_GPIO,GPIO_IO_IN,GPIO_PULL_UP);
  173. GpioIntCfg(MODE_KEY_PORT,MODE_KEY_PIN,EN,GPIO_INTERRUPT_EDGE_DOWN); //Öжϴ¥·¢£¬ÖжÏʹÄÜ
  174. REG_AHB0_FIQ_PRIORITY_EN |= INT_STATUS_GPIO;
  175. GpioIntHandleCbCfg((GPIO_INT_HANDLE_CB_PFN)&ir_callback);
  176. }
  177. void t_ir_check(uint32_t current_clk)
  178. {
  179. if( current_clk > ir_check_clock && ir_check_clock > 0)
  180. {
  181. ir_check_clock = 0;
  182. clean_ir_status();
  183. }
  184. }
  185. #endif