remote_Panasonic.c
4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#include "os_config.h"
#include "c_def.h"
#include "debug.h"
#include "oem.h"
#include "regmap.h"
//#include "interrupt.h"
//#include "hw_gpio.h"
//#include "hw_timer.h"
//#include "app_gpio.h"
#include "remote.h"
#include "message.h"
#include "key_scan.h"
#include "app_main.h"
//#include "oem_string.h"
//#include <string.h>
#include "app_key.h"
//#include "app_ver.h"
//#include "hw_pll.h"
#include "mem_reloc.h"
#ifdef REMOTE_ENABLE
#ifdef REMOTE_PANASONIC_FORMAT
void app_ir_message_send(int level, U32 time) __INTERNAL_RAM_TEXT;
//#define SWAP_HIG_BIT_TO_LOW_BIT
#ifdef SWAP_HIG_BIT_TO_LOW_BIT
#define PANASONIC_MARK_CODE 0x2002
#define PAPASONICS_MODE1 0xA00050F
#define PAPASONICS_MODE2 0xA00151F
#else
#define PANASONIC_MARK_CODE 0x4004
#define PAPASONICS_MODE1 0x5000A0F
#define PAPASONICS_MODE2 0x5008A8F
#endif
//Counter incr = RC_TB_DEN/RC_TB_NUM
#define LEADER_ON_PULSE_MIN (3500 - 350)
#define LEADER_ON_PULSE_MAX (3500 + 350)
#define LEADER_OFF_PULSE_MIN (1700 - 170)
#define LEADER_OFF_PULSE_MAX (1700 + 170)
#define LEADER_2T_PULSE_MIN (1200 - 120)
#define LEADER_2T_PULSE_MAX (1200 + 120)
#define LEADER_1T_PULSE_MIN (400 - 40)
#define LEADER_1T_PULSE_MAX (400 + 40)
#define LEADER_REPTAT_PULSE_MIN (1200 - 220)
#define LEADER_REPTAT_PULSE_MAX (1200 + 220)
void app_ir_message_send(int level, U32 time)
{
volatile U32 pulse_width;
static U8 count;
static U32 data;
#ifdef REMOTE_CONTROL_DEBUG
DBG_Printf("IR_Message:%d,%x\n", level, time);
#endif
pulse_width = time * RC_TB_VAL;
switch (remote_state)
{
case RC_IDLE:
if (!level)
{
remote_state = RC_LEADER_ON;
}
else
{
break;
}
case RC_LEADER_ON:
if (pulse_width > LEADER_ON_PULSE_MIN && pulse_width < LEADER_ON_PULSE_MAX)
{
remote_state = RC_LEADER_OFF;
#ifdef REMOTE_CONTROL_DEBUG
DBG_Puts("RC L On ok\n\r");
#endif
}
else
{
remote_state = RC_IDLE;
remote_repeat_valid = FALSE;
#ifdef REMOTE_CONTROL_DEBUG
DBG_RMTPrintf("RC L On Err:%d\n\r", pulse_width);
#endif
}
break;
case RC_LEADER_OFF:
if (pulse_width > LEADER_OFF_PULSE_MIN && pulse_width < LEADER_OFF_PULSE_MAX)
{
remote_state = RC_DATA;
data = 0;
count = 0;
#ifdef REMOTE_CONTROL_DEBUG
DBG_Puts("RC L Off ok\n\r");
#endif
}
else
{
if (!level)
break;
remote_state = RC_DATA_END;
}
break;
case RC_DATA:
if (!level)
break;
count++;
if (pulse_width > LEADER_1T_PULSE_MIN && pulse_width < LEADER_1T_PULSE_MAX)
{
#ifdef SWAP_HIG_BIT_TO_LOW_BIT
//empty
#else
data <<= 1;
#endif
}
else
{
if (pulse_width > LEADER_2T_PULSE_MIN && pulse_width < LEADER_2T_PULSE_MAX)
{
#ifdef SWAP_HIG_BIT_TO_LOW_BIT
data = (data | (1 << (count - 17)));
#else
data = (data << 1) | 1;
#endif
}
else
{
remote_state = RC_IDLE;
remote_repeat_valid = FALSE;
#ifdef REMOTE_CONTROL_DEBUG
DBG_RMTPrintf("panasonic Data Err:%d\n\r", pulse_width);
#endif
break;
}
}
if (count == 16)
{
#ifdef SWAP_HIG_BIT_TO_LOW_BIT
data >>= 16;
#endif
if (data != PANASONIC_MARK_CODE)
{
#ifdef REMOTE_KEY_VALUE_DEBUG
DBG_Printf("customer code err:0x%x\n\r", data);
#endif
remote_state = RC_IDLE;
remote_data = APP_KEY_INVALID;
break;
}
else
{
#ifdef REMOTE_KEY_VALUE_DEBUG
DBG_RMTPrintf("customer code ok:0x%x\n\r", data);
#endif
}
data = 0;
}
if (count == 48)
{
if (remote_repeat_valid)
{
#ifdef REMOTE_KEY_VALUE_DEBUG
DBG_RMTPrintf("PANASONIC Data:0x%x\n\r", data);
#endif
remote_state = RC_DATA_END;
if ((remote_data == data))
{
app_timer_remoteKeyUpTimer_set(175);
#ifdef REMOTE_CONTROL_DEBUG
DBG_Puts("P RPT\n\r");
#endif
}
else
{
app_timer_remoteKeyUpTimer_set(25);
remote_repeat_valid = FALSE;
#ifdef REMOTE_CONTROL_DEBUG
DBG_Puts("P RPT err\n\r");
#endif
}
}
else
{
#ifdef REMOTE_KEY_VALUE_DEBUG
DBG_RMTPrintf("Pansonic Data:0x%x\n\r", data);
#endif
if ((data == PAPASONICS_MODE1) || (data == PAPASONICS_MODE2))
{
if (data == PAPASONICS_MODE1)
{
//mode1
//DBG_Printf("Panasonic IR MODE 1\n\r");
}
else
{
//mode2
//DBG_Printf("Panasonic IR MODE 2\n\r");
}
}
remote_state = RC_DATA_END;
remote_repeat_valid = TRUE;
remote_data = data;
app_ir_keypress(data);
}
}
break;
case RC_DATA_END:
#ifdef REMOTE_CONTROL_DEBUG
DBG_RMTPrintf("Pansonic Data End:%d\n\r", pulse_width);
#endif
remote_state = RC_IDLE;
default:
remote_state = RC_IDLE;
break;
}
}
#endif //REMOTE_MIXED_FORMAT
#endif //REMOTE_ENABLE