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