]> cloudbase.mooo.com Git - irmp.git/blob - irmp-main-esp8266.c
Version 3.0: corrected ESP8266 port, added MBED port, added several main example...
[irmp.git] / irmp-main-esp8266.c
1 /******************************************************************************
2
3 Test program IRMP for ESP8266 2015-11-16 Wolfgang Strobl, Bonn
4
5 IRMP ported to ESP8266, testet with MOD-WIFI-ESP8266-DEV on
6 ESP8266-EVB evaluation board. https://www.olimex.com/Products/IoT/ESP8266-EVB/
7
8 Connections
9 -----------
10
11 Input TSOP via 1k resistor at GPIO12 (Pin 7 UEXT),
12 Output via UART (Pin 3/4 UEXT)
13
14 example output
15 ---------------
16
17 ESP8266 IRMP Test v0.3 W.Strobl 20151120
18 F_INTERRUPTS==15000
19 SDK version: 1.4.1(pre2) Chip ID=10619495
20 data : 0x3ffe8000 ~ 0x3ffe837a, len: 890
21 rodata: 0x3ffe8380 ~ 0x3ffe891c, len: 1436
22 bss : 0x3ffe8920 ~ 0x3ffef4c0, len: 27552
23 heap : 0x3ffef4c0 ~ 0x3fffc000, len: 52032
24 free heap size=51784, system time=330392, rtc time=59472
25 IRMP listening ...
26 mode : sta(18:fe:34:a2:0a:67)
27 add if0
28
29 IRMP TELEFUNKEN(34): addr=0x0000 cmd=0x23f1, f=0
30 IRMP TELEFUNKEN(34): addr=0x0000 cmd=0x1ffe, f=0
31 IRMP TELEFUNKEN(34): addr=0x0000 cmd=0x28fc, f=0
32 IRMP TELEFUNKEN(34): addr=0x0000 cmd=0x0113, f=0
33 IRMP TELEFUNKEN(34): addr=0x0000 cmd=0x28fc, f=0
34 IRMP TELEFUNKEN(34): addr=0x0000 cmd=0x09ff, f=0
35 IRMP TELEFUNKEN(34): addr=0x0000 cmd=0x28fc, f=0
36 IRMP TELEFUNKEN(34): addr=0x0000 cmd=0x0113, f=0
37 IRMP KASEIKYO( 5): addr=0x2002 cmd=0x9001, f=0
38 IRMP KASEIKYO( 5): addr=0x2002 cmd=0x9b40, f=0
39 IRMP SIRCS( 1): addr=0x0809 cmd=0x1d0b, f=0
40 IRMP SIRCS( 1): addr=0x0809 cmd=0x1d7a, f=0
41 IRMP SIRCS( 1): addr=0x0809 cmd=0x1d7c, f=0
42 IRMP SIRCS( 1): addr=0x0809 cmd=0x1d79, f=0
43 IRMP SIRCS( 1): addr=0x0809 cmd=0x1d7c, f=0
44 IRMP SAMSG32(10): addr=0x2d2d cmd=0xc639, f=0
45 IRMP SAMSG32(10): addr=0x2d2d cmd=0xb54a, f=0
46
47 *******************************************************************************/
48
49 #include "ets_sys.h"
50 #include "osapi.h"
51 #include "driver/uart.h"
52 #include "gpio.h"
53 #include "os_type.h"
54 #include "mem.h"
55
56 #include "irmp.h"
57
58 // hardware timer (driven by NMI)
59
60 typedef enum {
61 FRC1_SOURCE = 0,
62 NMI_SOURCE = 1,
63 } FRC1_TIMER_SOURCE_TYPE;
64
65 void hw_timer_set_func (void (* user_hw_timer_cb_set)(void));
66
67 void hw_timer_init (
68 FRC1_TIMER_SOURCE_TYPE source_type,
69 u8 req)
70 ;
71
72 void irmp_timer(void)
73 {
74 irmp_ISR ();
75 }
76
77 // info
78
79 void meminfo(void)
80 {
81 os_printf("free heap size=%u, system time=%u, rtc time=%u \n",
82 system_get_free_heap_size(),
83 system_get_time(),
84 system_get_rtc_time());
85 }
86
87 void sysinfo(void)
88 {
89 os_printf("SDK version: %s Chip ID=%u\n",
90 system_get_sdk_version(),
91 system_get_chip_id());
92 system_print_meminfo();
93 meminfo();
94 }
95
96 // Tasks
97
98 #define user_procTaskPrio 0
99 #define user_procTaskQueueLen 1
100
101 os_event_t user_procTaskQueue[user_procTaskQueueLen];
102 static void user_procTask(os_event_t *events);
103
104 // unbuffered Uart-rx, based on a comment in
105 // https://github.com/SuperHouse/esp-open-rtos/issues/18
106
107 int my_rx_one_char(void) // char or -1
108 {
109 int c = READ_PERI_REG(UART_STATUS(0)) & 0xff;
110 if (c) return READ_PERI_REG(UART_FIFO(0));
111 return -1;
112 }
113
114
115 IRMP_DATA irmp_data;
116
117 //------------------ User Task ---------------------
118
119 static void
120 user_procTask(os_event_t *events)
121 {
122 int rc = irmp_get_data (&irmp_data);
123
124 if (rc)
125 {
126 os_printf("\nIRMP %10s(%2d): addr=0x%04x cmd=0x%04x, f=%d ",
127 irmp_protocol_names[ irmp_data.protocol],
128 irmp_data.protocol,
129 irmp_data.address,
130 irmp_data.command,
131 irmp_data.flags
132 );
133 }
134
135 // https://github.com/SuperHouse/esp-open-rtos/issues/18
136 // uart_rx_one_char ist offenbar eine ROM-Funktion.
137
138 int c = my_rx_one_char();
139
140 if(c != -1)
141 {
142 uart_tx_one_char(0,c);
143 os_printf("(0x%02x, %d) ",c,c);
144 switch(c)
145 {
146 case '.':
147 os_printf("\nTime=%d, GPIO12=%d, ",
148 system_get_time(),GPIO_INPUT_GET(12));
149 os_printf("gpio=%08x ",gpio_input_get());
150 break;
151 }
152 }
153 os_delay_us(100);
154 system_os_post(user_procTaskPrio, 0, 0 );
155 }
156
157 // Init function
158
159 void ICACHE_FLASH_ATTR
160 user_init()
161 {
162 void* p;
163 uint32 now,diff;
164
165 //~ system_timer_reinit(); //US_TIMER
166
167 uart_init(BIT_RATE_115200, BIT_RATE_115200);
168 os_printf("\n\nESP8266 IRMP Test v0.3 W.Strobl 20151120\n");
169
170 os_printf("F_INTERRUPTS==%d\n",F_INTERRUPTS);
171
172 sysinfo();
173
174 hw_timer_init(NMI_SOURCE,1);
175 hw_timer_set_func(irmp_timer);
176 hw_timer_arm (1000000/F_INTERRUPTS);
177
178 // Initialize the GPIO subsystem.
179 gpio_init();
180
181
182 irmp_init ();
183
184 //Start os task
185
186 system_os_task(user_procTask, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);
187 system_os_post(user_procTaskPrio, 0, 0 );
188
189 os_printf("IRMP listening ...\n");
190
191 }