remote.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #include "FreeRTOS.h"
  2. #include "chip.h"
  3. #include "board.h"
  4. #ifdef REMOTE_SUPPORT
  5. /* Remote */
  6. #define rRC_DATA0 0x00
  7. #define rRC_DATA1 0x04
  8. #define rRC_DATA2 0x08
  9. #define rRC_DATA3 0x0C
  10. #define rRC_DATA4 0x10
  11. #define rRC_DATA5 0x14
  12. #define rRC_DATA6 0x18
  13. #define rRC_DATA7 0x1C
  14. #define rRC_CODEBUF 0x20
  15. #define rRC_CODEVAL 0x24
  16. #define rRC_KEYVAL 0x28
  17. #define rRC_STATUS 0x2C
  18. #define rRC_RT_USER_CODE_3_4 0x30
  19. #define rRC_RT_INTER_REQ_CLR 0x34
  20. #define NORMAL_KEY 0
  21. #define RELEASE_KEY 1
  22. #define REPEAT_KEY 2
  23. #define REMOTE_NULL 0
  24. #define REMOTE_SCAN 1 // scan state
  25. #define REMOTE_CHECK 2 // check state
  26. #define REMOTE_DELAY 3 // repeat delay state
  27. #define REMOTE_REPEAT 4 // repeat state
  28. #define REMOTE_STATE_IDLE 0
  29. #define REMOTE_STATE_PRESS 1
  30. #define REMOTE_STATE_REPEATE 2
  31. #define REMOTE_PRESS_EVENT 0
  32. #define REMOTE_RELEASE_EVENT 1
  33. #define REMOTE_REPEATE_EVENT 2
  34. //static UINT32 lg_ulRemoteStateMachine = REMOTE_STATE_IDLE;
  35. //static unsigned short Remotekey_delay_time;
  36. //static int Remotekey_state;
  37. //static UINT32 lg_ulLastRepeatMs = 0;
  38. static UINT32 lg_ulMaxRepeatMs = 0;
  39. volatile UINT32 cRemoteKey; // 当前键值
  40. volatile UINT32 cRemoteStatus; // 当前键状态
  41. static void remote_config(void) //进行遥控接收器的参数配置
  42. {
  43. printf("remote_config\n");
  44. #if 1
  45. // nec
  46. INT8 pulse_data_polarity = 0x01;//[3 :0 ]
  47. INT8 valid_bitrange = 0x04;//[6 :4 ]
  48. INT8 dispersion = 0x5;//[15:8 ]
  49. INT8 prediv = 0x3f;//[23:16] 24M: 0x1f 48M: 0x3f
  50. INT8 filtertime = 0x10;//[31:24]
  51. INT8 start_valueh = 0x69;//[23:16]
  52. INT8 start_valuel = 0x34;//[31:24]
  53. INT8 one_valueh = 0x6; //0x6;//[7 : 0]
  54. INT8 one_valuel = 0x13;//[15: 8]
  55. INT8 zero_valueh = 0x6;//[23:16]
  56. INT8 zero_valuel = 0x6;//[31:24]
  57. INT8 rp0_valueh = 0x0f;//[7 : 0]
  58. INT8 rp0_valuel = 0x0f;//[15: 8]
  59. INT8 rp1_valueh = 0x0f;//[23:16]
  60. INT8 rp1_valuel = 0x0f;//[31:24]
  61. INT8 rp2_3_valueh = 0x69;//[7 : 0]
  62. INT8 rp2_3_valuel = 0x1c;//[15: 8]
  63. INT8 rp4_5_valueh =0x6;//[23:16]
  64. INT8 rp4_5_valuel = 0xf5;//[31:24]
  65. INT8 keyrelease_timeh = 0x00;//[7 : 0]
  66. INT8 keyrelease_timel = 0x59;//[15: 8]
  67. INT8 RP_5L_delta=0XF0;
  68. INT8 int_num = 0x01;//[23:16]
  69. INT8 mode_sel_reg = 0x03;//[25:24]
  70. INT8 nec_release_int_en = 0x01;//[26]
  71. UINT8 user_code1_l = 0x00;//[7 : 0]
  72. UINT8 user_code1_h = 0xFF;//[15: 8]
  73. UINT8 user_code2_l = 0x00;//[23:16]
  74. UINT8 user_code2_h =0xFF;//[31:24]
  75. INT32 NEC_bit_2_pulse = 0x2ff;//[15: 0]
  76. // INT8 user_code_sel_reg = 0x01;//[23:16]
  77. // INT8 user_code3_l = 0x02;//[7 : 0]
  78. // INT8 user_code3_h = 0x00;//[15: 8]
  79. // INT8 user_code4_l = 0xff;//[23:16]
  80. // INT8 user_code4_h =0x00;//[31:24]
  81. INT8 user_code_sel =0;
  82. INT8 custom_jud_sel=1;
  83. INT8 custom_not_jud_sel=1;
  84. INT8 data_not_jud_sel=1;
  85. uint32_t val;
  86. uint32_t remote_param0, remote_param1, remote_param2, remote_param3 ;
  87. uint32_t remote_param4, remote_param5, remote_param6, remote_param7 ;
  88. #endif
  89. remote_param0 = (pulse_data_polarity<<0)
  90. + (valid_bitrange<<4)
  91. + (dispersion<<7)
  92. + (prediv<<15)
  93. + (filtertime<<24);
  94. remote_param1 = (RP_5L_delta<< 0)
  95. + (start_valueh<<16)
  96. + (start_valuel<<24);
  97. remote_param2 = (one_valueh<<0)
  98. + (one_valuel<<8)
  99. + (zero_valueh<<16)
  100. + (zero_valuel<<24);
  101. remote_param3 = (rp0_valueh<<0)
  102. + (rp0_valuel<<8)
  103. + (rp1_valueh<<16)
  104. + (rp1_valuel<<24);
  105. remote_param4 = (rp2_3_valueh<<0)
  106. + (rp2_3_valuel<<8)
  107. + (rp4_5_valueh<<16)
  108. + (rp4_5_valuel<<24);
  109. remote_param5 = (keyrelease_timel<<0)
  110. + (keyrelease_timeh<<8)
  111. + (int_num<<16)
  112. + (mode_sel_reg<<24)
  113. + (nec_release_int_en << 26);
  114. remote_param6 = ((user_code1_l<<0)
  115. + (user_code1_h<<8)
  116. + (user_code2_l<<16)
  117. + (user_code2_h<<24));
  118. /* rRC_RT_USER_CODE_3_4 = (user_code3_l<<0)
  119. + (user_code3_h<<8)
  120. + (user_code4_l<<16)
  121. + (user_code4_h<<24);
  122. */
  123. remote_param7 =(NEC_bit_2_pulse<<0)
  124. + (user_code_sel<<16)
  125. +(custom_jud_sel<<24)
  126. +(custom_not_jud_sel<<25)
  127. +(data_not_jud_sel<<26);
  128. val = readl(REGS_SYSCTL_BASE + SYS_PER_CLK_CFG);
  129. val &= ~0x0f;
  130. writel(val, REGS_SYSCTL_BASE + SYS_PER_CLK_CFG);
  131. writel(remote_param0, REGS_RCRT_BASE+rRC_DATA0);
  132. writel(remote_param1, REGS_RCRT_BASE+rRC_DATA1);
  133. writel(remote_param2, REGS_RCRT_BASE+rRC_DATA2);
  134. writel(remote_param3, REGS_RCRT_BASE+rRC_DATA3);
  135. writel(remote_param4, REGS_RCRT_BASE+rRC_DATA4);
  136. writel(remote_param5, REGS_RCRT_BASE+rRC_DATA5);
  137. writel(remote_param6, REGS_RCRT_BASE+rRC_DATA6);
  138. writel(remote_param7, REGS_RCRT_BASE+rRC_DATA7);
  139. }
  140. /*********************************************************************
  141. Set the report interval for remote repeating event
  142. Parameter:
  143. ulMillisecond: interval, unit as millisecond, this parameter should be the multiply of
  144. 10 millsecond.
  145. *********************************************************************/
  146. void SetRemoteKeyRepeateInterval(UINT32 ulMillisecond)
  147. {
  148. lg_ulMaxRepeatMs = ulMillisecond/10;
  149. }
  150. /*********************************************************************
  151. Get the report interval for remote repeating event
  152. Return:
  153. millisendonds for interval
  154. *********************************************************************/
  155. UINT32 GetRemoteKeyRepeatInterval(void)
  156. {
  157. return lg_ulMaxRepeatMs * 10;
  158. }
  159. static void remote_int_handler(void *param)
  160. {
  161. // printf("Enter remote interrupt!\n");
  162. cRemoteStatus=(readl(REGS_RCRT_BASE + rRC_STATUS))&0x0F;// 取遥控码状态
  163. cRemoteKey=readl(REGS_RCRT_BASE + rRC_KEYVAL);
  164. printf(" cRemoteKey is%x.\n",cRemoteKey);
  165. writel(0xff, REGS_RCRT_BASE+rRC_RT_INTER_REQ_CLR);
  166. if(cRemoteStatus & 0x01)
  167. printf(" release detect\n");
  168. else
  169. printf(" cRemoteStatus: %x cRemoteKey: %x\n",cRemoteStatus,cRemoteKey);
  170. }
  171. void RemoteKeyInit(void)
  172. {
  173. cRemoteKey = REMOTE_NULL;
  174. cRemoteStatus = NORMAL_KEY;
  175. sys_soft_reset(softreset_rcrt);
  176. remote_config();
  177. request_irq(RCRT_IRQn,0,remote_int_handler,NULL);
  178. printf("RemoteKeyInit\n");
  179. }
  180. #endif