]> sigrok.org Git - libsigrokdecode.git/blob - irmp/irmpsystem.h
5a1a5dde5add365a2df8a5d6467e031bde5ecab7
[libsigrokdecode.git] / irmp / irmpsystem.h
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2  * irmpsystem.h - system specific includes and defines
3  *
4  * Copyright (c) 2009-2019 Frank Meyer - frank(at)fli4l.de
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *---------------------------------------------------------------------------------------------------------------------------------------------------
11  */
12
13 #ifndef _IRMPSYSTEM_H_
14 #define _IRMPSYSTEM_H_
15
16 #if !defined(_IRMP_H_) && !defined(_IRSND_H_)
17 #  error please include only irmp.h or irsnd.h, not irmpsystem.h
18 #endif
19
20 #if defined(__18CXX)                                                                // Microchip PIC C18 compiler
21 #  define PIC_C18
22 #elif defined(__XC8)                                                                // PIC XC8 compiler
23 #  include <xc.h>
24 #  define PIC_C18
25 #elif defined(__PCM__) || defined(__PCB__) || defined(__PCH__)                      // CCS PIC compiler
26 #  define PIC_CCS
27 #elif defined(STM32L1XX_MD) || defined(STM32L1XX_MDP) || defined(STM32L1XX_HD)      // ARM STM32
28 #  include <stm32l1xx.h>
29 #  define ARM_STM32
30 #  define ARM_STM32L1XX
31 #  define F_CPU (SysCtlClockGet())
32 #elif defined(STM32F10X_LD) || defined(STM32F10X_LD_VL) \
33    || defined(STM32F10X_MD) || defined(STM32F10X_MD_VL) \
34    || defined(STM32F10X_HD) || defined(STM32F10X_HD_VL) \
35    || defined(STM32F10X_XL) || defined(STM32F10X_CL)                                // ARM STM32
36 #  include <stm32f10x.h>
37 #  define ARM_STM32
38 #  define ARM_STM32F10X
39 #  define F_CPU (SysCtlClockGet())
40 #elif defined(STM32F4XX)                                                            // ARM STM32
41 #  include <stm32f4xx.h>
42 #  define ARM_STM32
43 #  define ARM_STM32F4XX
44 #elif defined(USE_HAL_DRIVER)                                                       // ARM STM32 with HAL Library
45 #  include "gpio.h"
46 #  if defined(_IRSND_H_)
47 #    include"tim.h"
48 #  endif
49 #  define ARM_STM32_HAL
50 #  define F_CPU SystemCoreClock
51 #elif defined(__SDCC_stm8)                                                          // STM8
52 #  define SDCC_STM8
53 #elif defined(TARGET_IS_BLIZZARD_RA2)                                               // TI Stellaris (tested on Stellaris Launchpad with Code Composer Studio)
54 #  define STELLARIS_ARM_CORTEX_M4
55 #  define F_CPU (SysCtlClockGet())
56 #elif defined(__xtensa__)                                                           // ESP8266 (Arduino)
57 #  include "Arduino.h"
58 #  include "ets_sys.h"
59 #  include "osapi.h"
60 #  include "gpio.h"
61 #  include "os_type.h"
62 #  include "c_types.h"
63 #  define uint_fast8_t uint8_t
64 #  define uint_fast16_t uint16_t
65 #elif defined(TEENSYDUINO) && (defined(__MK20DX256__) || defined(__MK20DX128__))    // Teensy 3.x (tested on Teensy 3.1 in Arduino 1.6.5 / Teensyduino 1.2.5)
66 #  include <core_pins.h>
67 #  define TEENSY_ARM_CORTEX_M4
68 #elif defined(unix) || defined(WIN32) || defined(__APPLE__)                         // Unix/Linux or Windows or Apple
69 #  define UNIX_OR_WINDOWS
70 #elif defined(__MBED__)                                                             // mbed platform
71 // #include "mbed.h"                                                                // if mbed.h is used, source must be compiled as cpp
72 #include "gpio_api.h"
73 #elif defined(IRMP_CHIBIOS_HAL)                                                     // ChibiOS HAL
74 #  include "hal.h"
75 #else
76 #  define ATMEL_AVR                                                                 // ATMEL AVR
77 #endif
78
79 #include <string.h>
80
81 #ifdef UNIX_OR_WINDOWS                                                              // Analyze on Unix/Linux or Windows
82 #  include <stdio.h>
83 #  include <stdlib.h>
84 #  define F_CPU 8000000L
85 #  define ANALYZE
86 #  ifdef unix
87 #    include <stdint.h>
88 #  else
89 typedef unsigned char                   uint8_t;
90 typedef unsigned short                  uint16_t;
91 #  endif
92 #endif
93
94
95 #if defined(ATMEL_AVR)
96 #  include <stdint.h>
97 #  include <stdio.h>
98 #  include <avr/io.h>
99 #  include <util/delay.h>
100 #  include <avr/pgmspace.h>
101 #  include <avr/interrupt.h>
102 #  define IRSND_OC2                     0       // OC2
103 #  define IRSND_OC2A                    1       // OC2A
104 #  define IRSND_OC2B                    2       // OC2B
105 #  define IRSND_OC0                     3       // OC0
106 #  define IRSND_OC0A                    4       // OC0A
107 #  define IRSND_OC0B                    5       // OC0B
108
109 #  define IRSND_XMEGA_OC0A              0       // OC0A
110 #  define IRSND_XMEGA_OC0B              1       // OC0B
111 #  define IRSND_XMEGA_OC0C              2       // OC0C
112 #  define IRSND_XMEGA_OC0D              3       // OC0D
113 #  define IRSND_XMEGA_OC1A              4       // OC1A
114 #  define IRSND_XMEGA_OC1B              5       // OC1B
115
116 #elif defined(STELLARIS_ARM_CORTEX_M4)
117
118 #  include "inc/hw_ints.h"
119 #  include "inc/hw_memmap.h"
120 #  include "inc/hw_types.h"
121 #  include "inc/hw_gpio.h"
122 #  include "driverlib/fpu.h"
123 #  include "driverlib/sysctl.h"
124 #  include "driverlib/interrupt.h"
125 #  include "driverlib/gpio.h"
126 #  include "driverlib/rom.h"
127 #  include "driverlib/systick.h"
128 #  include "driverlib/pin_map.h"
129 #  include "driverlib/timer.h"
130 #  define PROGMEM
131 #  define memcpy_P                      memcpy
132 #  define APP_SYSTICKS_PER_SEC          32
133
134 #elif defined(ARM_STM32F10X)
135
136 #  include "stm32f10x_gpio.h"
137 #  include "stm32f10x_rcc.h"
138 #  include "stm32f10x_tim.h"
139 #  include "misc.h"
140 #  define PROGMEM
141 #  define memcpy_P                      memcpy
142
143 #elif defined(SDCC_STM8)
144
145 #  include "stm8s.h"
146 #  define PROGMEM
147 #  define memcpy_P                      memcpy
148 #  define __attribute__(x)
149 #  define uint_fast8_t                  uint8_t
150 #  define uint_fast16_t                 uint16_t
151
152 #elif defined(TEENSY_ARM_CORTEX_M4)
153 #  define PROGMEM
154 #  define memcpy_P                      memcpy
155
156 #elif defined(__xtensa__)
157 #  define PROGMEM
158 #  define memcpy_P                      memcpy
159
160 #elif defined(__MBED__)
161 #  define PROGMEM
162 #  define memcpy_P                      memcpy
163
164 #else
165 #  define PROGMEM
166 #  define memcpy_P                      memcpy
167
168 #endif
169
170 #if defined(PIC_CCS) || defined(PIC_C18)
171 typedef unsigned char                   uint8_t;
172 typedef unsigned short                  uint16_t;
173 typedef unsigned char                   uint_fast8_t;
174 typedef unsigned short                  uint_fast16_t;
175 #endif
176
177 #if defined (PIC_C18)                                                               // PIC C18 or XC8 compiler
178 #  include <p18cxxx.h>                                                              // main PIC18 h file
179 #ifndef __XC8
180 #  include <timers.h>                                                               // timer lib
181 #  include <pwm.h>                                                                  // pwm lib
182 #endif
183 #  define IRSND_PIC_CCP1                1                                           // PIC C18 RC2 = PWM1 module
184 #  define IRSND_PIC_CCP2                2                                           // PIC C18 RC1 = PWM2 module
185 #endif
186
187 #ifndef TRUE
188 #  define TRUE                          1
189 #  define FALSE                         0
190 #endif
191
192 #if IRMP_32_BIT == 1
193
194 typedef struct
195 {
196     uint8_t                             protocol;                                   // protocol, e.g. NEC_PROTOCOL
197     uint16_t                            address;                                    // address
198     uint32_t                            command;                                    // command
199     uint8_t                             flags;                                      // flags, e.g. repetition
200 } IRMP_DATA;
201
202 #else // not IRMP_32_BIT == 1
203
204 #if defined(PIC_C18)
205 #define IRMP_PACKED_STRUCT
206 #else
207 #define IRMP_PACKED_STRUCT              __attribute__ ((__packed__))
208 #endif
209
210 typedef struct IRMP_PACKED_STRUCT
211 {
212     uint8_t                             protocol;                                   // protocol, e.g. NEC_PROTOCOL
213     uint16_t                            address;                                    // address
214     uint16_t                            command;                                    // command
215     uint8_t                             flags;                                      // flags, e.g. repetition
216 } IRMP_DATA;
217
218 #endif // IRMP_32_BIT == 1
219
220 #endif // _IRMPSYSTEM_H_