-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathirmp-main-esp8266.c
190 lines (146 loc) · 4.8 KB
/
irmp-main-esp8266.c
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
/******************************************************************************
Test program IRMP for ESP8266 2015-11-16 Wolfgang Strobl, Bonn
IRMP ported to ESP8266, testet with MOD-WIFI-ESP8266-DEV on
ESP8266-EVB evaluation board. https://www.olimex.com/Products/IoT/ESP8266-EVB/
Connections
-----------
Input TSOP via 1k resistor at GPIO12 (Pin 7 UEXT),
Output via UART (Pin 3/4 UEXT)
example output
---------------
ESP8266 IRMP Test v0.3 W.Strobl 20151120
F_INTERRUPTS==15000
SDK version: 1.4.1(pre2) Chip ID=10619495
data : 0x3ffe8000 ~ 0x3ffe837a, len: 890
rodata: 0x3ffe8380 ~ 0x3ffe891c, len: 1436
bss : 0x3ffe8920 ~ 0x3ffef4c0, len: 27552
heap : 0x3ffef4c0 ~ 0x3fffc000, len: 52032
free heap size=51784, system time=330392, rtc time=59472
IRMP listening ...
mode : sta(18:fe:34:a2:0a:67)
add if0
IRMP TELEFUNKEN(34): addr=0x0000 cmd=0x23f1, f=0
IRMP TELEFUNKEN(34): addr=0x0000 cmd=0x1ffe, f=0
IRMP TELEFUNKEN(34): addr=0x0000 cmd=0x28fc, f=0
IRMP TELEFUNKEN(34): addr=0x0000 cmd=0x0113, f=0
IRMP TELEFUNKEN(34): addr=0x0000 cmd=0x28fc, f=0
IRMP TELEFUNKEN(34): addr=0x0000 cmd=0x09ff, f=0
IRMP TELEFUNKEN(34): addr=0x0000 cmd=0x28fc, f=0
IRMP TELEFUNKEN(34): addr=0x0000 cmd=0x0113, f=0
IRMP KASEIKYO( 5): addr=0x2002 cmd=0x9001, f=0
IRMP KASEIKYO( 5): addr=0x2002 cmd=0x9b40, f=0
IRMP SIRCS( 1): addr=0x0809 cmd=0x1d0b, f=0
IRMP SIRCS( 1): addr=0x0809 cmd=0x1d7a, f=0
IRMP SIRCS( 1): addr=0x0809 cmd=0x1d7c, f=0
IRMP SIRCS( 1): addr=0x0809 cmd=0x1d79, f=0
IRMP SIRCS( 1): addr=0x0809 cmd=0x1d7c, f=0
IRMP SAMSG32(10): addr=0x2d2d cmd=0xc639, f=0
IRMP SAMSG32(10): addr=0x2d2d cmd=0xb54a, f=0
*******************************************************************************/
#include "ets_sys.h"
#include "osapi.h"
#include "driver/uart.h"
#include "gpio.h"
#include "os_type.h"
#include "mem.h"
#include "irmp.h"
// hardware timer (driven by NMI)
typedef enum {
FRC1_SOURCE = 0,
NMI_SOURCE = 1,
} FRC1_TIMER_SOURCE_TYPE;
void hw_timer_set_func (void (* user_hw_timer_cb_set)(void));
void hw_timer_init (
FRC1_TIMER_SOURCE_TYPE source_type,
u8 req)
;
void irmp_timer(void)
{
irmp_ISR ();
}
// info
void meminfo(void)
{
os_printf("free heap size=%u, system time=%u, rtc time=%u \n",
system_get_free_heap_size(),
system_get_time(),
system_get_rtc_time());
}
void sysinfo(void)
{
os_printf("SDK version: %s Chip ID=%u\n",
system_get_sdk_version(),
system_get_chip_id());
system_print_meminfo();
meminfo();
}
// Tasks
#define user_procTaskPrio 0
#define user_procTaskQueueLen 1
os_event_t user_procTaskQueue[user_procTaskQueueLen];
static void user_procTask(os_event_t *events);
// unbuffered Uart-rx, based on a comment in
// https://github.com/SuperHouse/esp-open-rtos/issues/18
int my_rx_one_char(void) // char or -1
{
int c = READ_PERI_REG(UART_STATUS(0)) & 0xff;
if (c) return READ_PERI_REG(UART_FIFO(0));
return -1;
}
IRMP_DATA irmp_data;
//------------------ User Task ---------------------
static void
user_procTask(os_event_t *events)
{
int rc = irmp_get_data (&irmp_data);
if (rc)
{
os_printf("\nIRMP %10s(%2d): addr=0x%04x cmd=0x%04x, f=%d ",
irmp_protocol_names[ irmp_data.protocol],
irmp_data.protocol,
irmp_data.address,
irmp_data.command,
irmp_data.flags
);
}
// https://github.com/SuperHouse/esp-open-rtos/issues/18
// uart_rx_one_char ist offenbar eine ROM-Funktion.
int c = my_rx_one_char();
if(c != -1)
{
uart_tx_one_char(0,c);
os_printf("(0x%02x, %d) ",c,c);
switch(c)
{
case '.':
os_printf("\nTime=%d, GPIO12=%d, ",
system_get_time(),GPIO_INPUT_GET(12));
os_printf("gpio=%08x ",gpio_input_get());
break;
}
}
os_delay_us(100);
system_os_post(user_procTaskPrio, 0, 0 );
}
// Init function
void ICACHE_FLASH_ATTR
user_init()
{
void* p;
uint32 now,diff;
//~ system_timer_reinit(); //US_TIMER
uart_init(BIT_RATE_115200, BIT_RATE_115200);
os_printf("\n\nESP8266 IRMP Test v0.3 W.Strobl 20151120\n");
os_printf("F_INTERRUPTS==%d\n",F_INTERRUPTS);
sysinfo();
hw_timer_init(NMI_SOURCE,1);
hw_timer_set_func(irmp_timer);
hw_timer_arm (1000000/F_INTERRUPTS);
// Initialize the GPIO subsystem.
gpio_init();
irmp_init ();
//Start os task
system_os_task(user_procTask, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);
system_os_post(user_procTaskPrio, 0, 0 );
os_printf("IRMP listening ...\n");
}