]> cloudbase.mooo.com Git - irmp.git/blobdiff - irsnd.c
version 2.0.0-pre3: changed handling of double width pulses/pauses in manchester...
[irmp.git] / irsnd.c
diff --git a/irsnd.c b/irsnd.c
index da0996086486018b4d35fff6163d696a3f7988bb..fb7e449a93ece0492393acb9811ea4416dd183a7 100644 (file)
--- a/irsnd.c
+++ b/irsnd.c
@@ -1,9 +1,9 @@
 /*---------------------------------------------------------------------------------------------------------------------------------------------------\r
  * @file irsnd.c\r
  *\r
- * Copyright (c) 2010 Frank Meyer - frank(at)fli4l.de\r
+ * Copyright (c) 2010-2011 Frank Meyer - frank(at)fli4l.de\r
  *\r
- * $Id: irsnd.c,v 1.29 2011/01/18 13:02:15 fm Exp $\r
+ * $Id: irsnd.c,v 1.36 2011/04/20 09:09:48 fm Exp $\r
  *\r
  * This program is free software; you can redistribute it and/or modify\r
  * it under the terms of the GNU General Public License as published by\r
@@ -30,8 +30,8 @@
 #include <string.h>\r
 \r
 #define F_CPU 8000000L\r
-typedef unsigned char    uint8_t;\r
-typedef unsigned short    uint16_t;\r
+typedef unsigned char   uint8_t;\r
+typedef unsigned short  uint16_t;\r
 #define DEBUG\r
 \r
 #else\r
@@ -54,12 +54,83 @@ typedef unsigned short    uint16_t;
 #include "irsndconfig.h"\r
 #include "irsnd.h"\r
 \r
+/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
+ *  ATmega pin definition of OC2 / OC2A / OC2B\r
+ *---------------------------------------------------------------------------------------------------------------------------------------------------\r
+ */\r
+#if defined (__AVR_ATmega8__)                           // ATmega8 uses OC2 = PB3\r
+#undef  IRSND_OC2                                       // has no OC2A / OC2B\r
+#define IRSND_OC2                               0       // magic: use OC2\r
+#define IRSND_PORT                              PORTB   // port B\r
+#define IRSND_DDR                               DDRB    // ddr B\r
+#define IRSND_BIT                               3       // OC2A\r
+\r
+#elif defined (__AVR_ATmega16__)    \\r
+  ||  defined (__AVR_ATmega32__)                        // ATmega16|32 uses OC2 = PD7\r
+#undef  IRSND_OC2                                       // has no OC2A / OC2B\r
+#define IRSND_OC2                               0       // magic: use OC2\r
+#define IRSND_PORT                              PORTD   // port D\r
+#define IRSND_DDR                               DDRD    // ddr D\r
+#define IRSND_BIT                               7       // OC2\r
+\r
+#elif defined (__AVR_ATmega162__)                       // ATmega162 uses OC2 = PB1\r
+#undef  IRSND_OC2                                       // has no OC2A / OC2B\r
+#define IRSND_OC2                               0       // magic: use OC2\r
+#define IRSND_PORT                              PORTB   // port B\r
+#define IRSND_DDR                               DDRB    // ddr B\r
+#define IRSND_BIT                               1       // OC2\r
+\r
+#elif defined (__AVR_ATmega164__)   \\r
+   || defined (__AVR_ATmega324__)   \\r
+   || defined (__AVR_ATmega644__)   \\r
+   || defined (__AVR_ATmega644P__)  \\r
+   || defined (__AVR_ATmega1284__)                      // ATmega164|324|644|644P|1284 uses OC2A = PD7 or OC2B = PD6\r
+#if IRSND_OC2 == 1                                      // OC2A\r
+#define IRSND_PORT                              PORTD   // port D\r
+#define IRSND_DDR                               DDRD    // ddr D\r
+#define IRSND_BIT                               7       // OC2A\r
+#elif IRSND_OC2 == 2                                    // OC2B\r
+#define IRSND_PORT                              PORTD   // port D\r
+#define IRSND_DDR                               DDRD    // ddr D\r
+#define IRSND_BIT                               6       // OC2B\r
+#else\r
+#error Wrong value for IRSND_OC2, choose 1 or 2 in irsndconfig.h\r
+#endif // IRSND_OC2\r
+\r
+#elif defined (__AVR_ATmega48__)    \\r
+   || defined (__AVR_ATmega88__)    \\r
+   || defined (__AVR_ATmega168__)   \\r
+   || defined (__AVR_ATmega168__)   \\r
+   || defined (__AVR_ATmega328__)   \\r
+   || defined (__AVR_ATmega328P__)                      // ATmega48|88|168|328P uses OC2A = PB3 or OC2B = PD3\r
+#if IRSND_OC2 == 1                                      // OC2A\r
+#define IRSND_PORT                              PORTB   // port B\r
+#define IRSND_DDR                               DDRB    // ddr B\r
+#define IRSND_BIT                               3       // OC2A\r
+#elif IRSND_OC2 == 2                                    // OC2B\r
+#define IRSND_PORT                              PORTD   // port D\r
+#define IRSND_DDR                               DDRD    // ddr D\r
+#define IRSND_BIT                               3       // OC2B\r
+#else\r
+#error Wrong value for IRSND_OC2, choose 1 or 2 in irsndconfig.h\r
+#endif // IRSND_OC2\r
+\r
+#else\r
+#if !defined (unix) && !defined (WIN32)\r
+#error OC2A/OC2B not defined, please fill in definitions here.\r
+#endif // unix, WIN32\r
+#endif // __AVR...\r
+\r
 #if IRSND_SUPPORT_NIKON_PROTOCOL == 1\r
 typedef uint16_t    IRSND_PAUSE_LEN;\r
 #else\r
 typedef uint8_t     IRSND_PAUSE_LEN;\r
 #endif\r
 \r
+/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
+ *  IR timings\r
+ *---------------------------------------------------------------------------------------------------------------------------------------------------\r
+ */\r
 #define SIRCS_START_BIT_PULSE_LEN               (uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME + 0.5)\r
 #define SIRCS_START_BIT_PAUSE_LEN               (uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME + 0.5)\r
 #define SIRCS_1_PULSE_LEN                       (uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME + 0.5)\r
@@ -153,15 +224,15 @@ typedef uint8_t     IRSND_PAUSE_LEN;
 #define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN      (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME + 0.5)\r
 #define BANG_OLUFSEN_FRAME_REPEAT_PAUSE_LEN     (uint16_t)(F_INTERRUPTS * BANG_OLUFSEN_FRAME_REPEAT_PAUSE_TIME + 0.5)       // use uint16_t!\r
 \r
-#define GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN          (uint8_t)(F_INTERRUPTS * GRUNDIG_OR_NOKIA_PRE_PAUSE_TIME + 0.5)\r
-#define GRUNDIG_OR_NOKIA_BIT_LEN                (uint8_t)(F_INTERRUPTS * GRUNDIG_OR_NOKIA_BIT_TIME + 0.5)\r
+#define GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN  (uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_PRE_PAUSE_TIME + 0.5)\r
+#define GRUNDIG_NOKIA_IR60_BIT_LEN        (uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME + 0.5)\r
 #define GRUNDIG_AUTO_REPETITION_PAUSE_LEN       (uint16_t)(F_INTERRUPTS * GRUNDIG_AUTO_REPETITION_PAUSE_TIME + 0.5)         // use uint16_t!\r
 #define NOKIA_AUTO_REPETITION_PAUSE_LEN         (uint16_t)(F_INTERRUPTS * NOKIA_AUTO_REPETITION_PAUSE_TIME + 0.5)           // use uint16_t!\r
-#define GRUNDIG_OR_NOKIA_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * GRUNDIG_OR_NOKIA_FRAME_REPEAT_PAUSE_TIME + 0.5)   // use uint16_t!\r
+#define GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_TIME + 0.5)   // use uint16_t!\r
 \r
-#define SIEMENS_START_BIT_LEN                   (uint8_t)(F_INTERRUPTS * SIEMENS_BIT_TIME + 0.5)\r
-#define SIEMENS_BIT_LEN                         (uint8_t)(F_INTERRUPTS * SIEMENS_BIT_TIME + 0.5)\r
-#define SIEMENS_FRAME_REPEAT_PAUSE_LEN          (uint16_t)(F_INTERRUPTS * SIEMENS_FRAME_REPEAT_PAUSE_TIME + 0.5)            // use uint16_t!\r
+#define SIEMENS_START_BIT_LEN                   (uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PULSE_TIME + 0.5)\r
+#define SIEMENS_BIT_LEN                         (uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PULSE_TIME + 0.5)\r
+#define SIEMENS_FRAME_REPEAT_PAUSE_LEN          (uint16_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_FRAME_REPEAT_PAUSE_TIME + 0.5)  // use uint16_t!\r
 \r
 #define IRSND_FREQ_32_KHZ                       (uint8_t) ((F_CPU / 32000 / 2) - 1)\r
 #define IRSND_FREQ_36_KHZ                       (uint8_t) ((F_CPU / 36000 / 2) - 1)\r
@@ -198,7 +269,15 @@ typedef uint8_t     IRSND_PAUSE_LEN;
 #define NIKON_PULSE_LEN                         (uint8_t)(F_INTERRUPTS * NIKON_PULSE_TIME + 0.5)\r
 #define NIKON_1_PAUSE_LEN                       (uint8_t)(F_INTERRUPTS * NIKON_1_PAUSE_TIME + 0.5)\r
 #define NIKON_0_PAUSE_LEN                       (uint8_t)(F_INTERRUPTS * NIKON_0_PAUSE_TIME + 0.5)\r
-#define NIKON_FRAME_REPEAT_PAUSE_LEN            (uint16_t)(F_INTERRUPTS * NIKON_FRAME_REPEAT_PAUSE_TIME + 0.5)                // use uint16_t!\r
+#define NIKON_FRAME_REPEAT_PAUSE_LEN            (uint16_t)(F_INTERRUPTS * NIKON_FRAME_REPEAT_PAUSE_TIME + 0.5)              // use uint16_t!\r
+\r
+#define LEGO_START_BIT_PULSE_LEN                (uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PULSE_TIME + 0.5)\r
+#define LEGO_START_BIT_PAUSE_LEN                (uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PAUSE_TIME + 0.5)\r
+#define LEGO_REPEAT_START_BIT_PAUSE_LEN         (uint8_t)(F_INTERRUPTS * LEGO_REPEAT_START_BIT_PAUSE_TIME + 0.5)\r
+#define LEGO_PULSE_LEN                          (uint8_t)(F_INTERRUPTS * LEGO_PULSE_TIME + 0.5)\r
+#define LEGO_1_PAUSE_LEN                        (uint8_t)(F_INTERRUPTS * LEGO_1_PAUSE_TIME + 0.5)\r
+#define LEGO_0_PAUSE_LEN                        (uint8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME + 0.5)\r
+#define LEGO_FRAME_REPEAT_PAUSE_LEN             (uint16_t)(F_INTERRUPTS * LEGO_FRAME_REPEAT_PAUSE_TIME + 0.5)               // use uint16_t!\r
 \r
 static volatile uint8_t                         irsnd_busy;\r
 static volatile uint8_t                         irsnd_protocol;\r
@@ -206,6 +285,10 @@ static volatile uint8_t                         irsnd_buffer[6];
 static volatile uint8_t                         irsnd_repeat;\r
 static volatile uint8_t                         irsnd_is_on = FALSE;\r
 \r
+#if IRSND_USE_CALLBACK == 1\r
+static void                                     (*irsnd_callback_ptr) (uint8_t);\r
+#endif // IRSND_USE_CALLBACK == 1\r
+\r
 /*---------------------------------------------------------------------------------------------------------------------------------------------------\r
  *  Switch PWM on\r
  *  @details  Switches PWM on with a narrow spike on all 3 channels -> leds glowing\r
@@ -217,12 +300,22 @@ irsnd_on (void)
     if (! irsnd_is_on)\r
     {\r
 #ifndef DEBUG\r
-#if defined (__AVR_ATmega32__)\r
-        TCCR2 |= (1<<COM20)|(1<<WGM21);                 // = 0x42: toggle OC2A on compare match, clear Timer 2 at compare match OCR2A\r
-#else\r
-        TCCR2A |= (1<<COM2A0)|(1<<WGM21);               // = 0x42: toggle OC2A on compare match, clear Timer 2 at compare match OCR2A\r
-#endif  // __AVR...\r
+#if   IRSND_OC2 == 0                                    // use OC2\r
+        TCCR2 |= (1<<COM20)|(1<<WGM21);                 // toggle OC2 on compare match, clear Timer 2 at compare match OCR2\r
+#elif IRSND_OC2 == 1                                    // use OC2A\r
+        TCCR2A |= (1<<COM2A0)|(1<<WGM21);               // toggle OC2A on compare match, clear Timer 2 at compare match OCR2A\r
+#else                                                   // use OC2B\r
+        TCCR2A |= (1<<COM2B0)|(1<<WGM21);               // toggle OC2B on compare match, clear Timer 2 at compare match OCR2A (yes: A, not B!)\r
+#endif // IRSND_OC2\r
 #endif // DEBUG\r
+\r
+#if IRSND_USE_CALLBACK == 1\r
+        if (irsnd_callback_ptr)\r
+        {\r
+            (*irsnd_callback_ptr) (TRUE);\r
+        }\r
+#endif // IRSND_USE_CALLBACK == 1\r
+\r
         irsnd_is_on = TRUE;\r
     }\r
 }\r
@@ -238,13 +331,23 @@ irsnd_off (void)
     if (irsnd_is_on)\r
     {\r
 #ifndef DEBUG\r
-#if defined (__AVR_ATmega32__)\r
-        TCCR2 &= ~(1<<COM20);                                                           // normal port operation, OC2A disconnected.\r
-#else\r
-        TCCR2A &= ~(1<<COM2A0);                                                         // normal port operation, OC2A disconnected.\r
-#endif  // __AVR...\r
-        IRSND_PORT  &= ~(1<<IRSND_BIT);                                                 // set IRSND_BIT to low\r
+#if   IRSND_OC2 == 0                                    // use OC2\r
+        TCCR2 &= ~(1<<COM20);                           // normal port operation, OC2 disconnected.\r
+#elif IRSND_OC2 == 1                                    // use OC2A\r
+        TCCR2A &= ~(1<<COM2A0);                         // normal port operation, OC2A disconnected.\r
+#else                                                   // use OC2B\r
+        TCCR2A &= ~(1<<COM2B0);                         // normal port operation, OC2B disconnected.\r
+#endif // IRSND_OC2\r
+        IRSND_PORT  &= ~(1<<IRSND_BIT);                 // set IRSND_BIT to low\r
 #endif // DEBUG\r
+\r
+#if IRSND_USE_CALLBACK == 1\r
+        if (irsnd_callback_ptr)\r
+        {\r
+           (*irsnd_callback_ptr) (FALSE);\r
+        }\r
+#endif // IRSND_USE_CALLBACK == 1\r
+\r
         irsnd_is_on = FALSE;\r
     }\r
 }\r
@@ -258,11 +361,11 @@ static void
 irsnd_set_freq (uint8_t freq)\r
 {\r
 #ifndef DEBUG\r
-#if defined (__AVR_ATmega32__)\r
-    OCR2 = freq;\r
+#if IRSND_OC2 == 0\r
+    OCR2 = freq;                                                                        // use register OCR2 for OC2\r
 #else\r
-    OCR2A = freq;\r
-#endif  // __AVR...\r
+    OCR2A = freq;                                                                       // use register OCR2A for OC2A and OC2B!\r
+#endif\r
 #endif // DEBUG\r
 }\r
 \r
@@ -290,6 +393,14 @@ irsnd_init (void)
 #endif // DEBUG\r
 }\r
 \r
+#if IRSND_USE_CALLBACK == 1\r
+void\r
+irsnd_set_callback_ptr (void (*cb)(uint8_t))\r
+{\r
+    irsnd_callback_ptr = cb;\r
+}\r
+#endif // IRSND_USE_CALLBACK == 1\r
+\r
 uint8_t\r
 irsnd_is_busy (void)\r
 {\r
@@ -671,6 +782,19 @@ irsnd_send_data (IRMP_DATA * irmp_data_p, uint8_t do_wait)
             irsnd_busy      = TRUE;\r
             break;\r
         }\r
+#endif\r
+#if IRSND_SUPPORT_LEGO_PROTOCOL == 1\r
+        case IRMP_LEGO_PROTOCOL:\r
+        {\r
+            uint8_t crc = 0x0F ^ ((irmp_data_p->command & 0x0F00) >> 8) ^ ((irmp_data_p->command & 0x00F0) >> 4) ^ (irmp_data_p->command & 0x000F);\r
+\r
+            irsnd_buffer[0] = (irmp_data_p->command & 0x0FF0) >> 4;                                             // CCCCCCCC\r
+            irsnd_buffer[1] = ((irmp_data_p->command & 0x000F) << 4) | crc;                                     // CCCCcccc\r
+\r
+            irsnd_protocol = IRMP_LEGO_PROTOCOL;\r
+            irsnd_busy      = TRUE;\r
+            break;\r
+        }\r
 #endif\r
         default:\r
         {\r
@@ -1050,15 +1174,15 @@ irsnd_ISR (void)
 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1\r
                     case IRMP_GRUNDIG_PROTOCOL:\r
                     {\r
-                        startbit_pulse_len          = GRUNDIG_OR_NOKIA_BIT_LEN;\r
-                        startbit_pause_len          = GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN - 1;\r
-                        pulse_len                   = GRUNDIG_OR_NOKIA_BIT_LEN;\r
-                        pause_len                   = GRUNDIG_OR_NOKIA_BIT_LEN;\r
-                        has_stop_bit                = GRUNDIG_OR_NOKIA_STOP_BIT;\r
+                        startbit_pulse_len          = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
+                        startbit_pause_len          = GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN - 1;\r
+                        pulse_len                   = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
+                        pause_len                   = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
+                        has_stop_bit                = GRUNDIG_NOKIA_IR60_STOP_BIT;\r
                         complete_data_len           = GRUNDIG_COMPLETE_DATA_LEN;\r
                         n_auto_repetitions          = GRUNDIG_FRAMES;                               // 2 frames\r
                         auto_repetition_pause_len   = GRUNDIG_AUTO_REPETITION_PAUSE_LEN;            // 20m sec pause\r
-                        repeat_frame_pause_len      = GRUNDIG_OR_NOKIA_FRAME_REPEAT_PAUSE_LEN;      // 117 msec pause\r
+                        repeat_frame_pause_len      = GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN;      // 117 msec pause\r
                         irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
 \r
                         break;\r
@@ -1067,15 +1191,15 @@ irsnd_ISR (void)
 #if IRSND_SUPPORT_NOKIA_PROTOCOL == 1\r
                     case IRMP_NOKIA_PROTOCOL:\r
                     {\r
-                        startbit_pulse_len          = GRUNDIG_OR_NOKIA_BIT_LEN;\r
-                        startbit_pause_len          = GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN - 1;\r
-                        pulse_len                   = GRUNDIG_OR_NOKIA_BIT_LEN;\r
-                        pause_len                   = GRUNDIG_OR_NOKIA_BIT_LEN;\r
-                        has_stop_bit                = GRUNDIG_OR_NOKIA_STOP_BIT;\r
+                        startbit_pulse_len          = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
+                        startbit_pause_len          = GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN - 1;\r
+                        pulse_len                   = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
+                        pause_len                   = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
+                        has_stop_bit                = GRUNDIG_NOKIA_IR60_STOP_BIT;\r
                         complete_data_len           = NOKIA_COMPLETE_DATA_LEN;\r
-                        n_auto_repetitions          = NOKIA_FRAMES;                                 // 2 frames\r
-                        auto_repetition_pause_len   = NOKIA_AUTO_REPETITION_PAUSE_LEN;              // 20 msec pause\r
-                        repeat_frame_pause_len      = GRUNDIG_OR_NOKIA_FRAME_REPEAT_PAUSE_LEN;      // 117 msec pause\r
+                        n_auto_repetitions          = NOKIA_FRAMES;                                             // 2 frames\r
+                        auto_repetition_pause_len   = NOKIA_AUTO_REPETITION_PAUSE_LEN;                          // 20 msec pause\r
+                        repeat_frame_pause_len      = GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN;                // 117 msec pause\r
                         irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
                         break;\r
                     }\r
@@ -1087,7 +1211,7 @@ irsnd_ISR (void)
                         startbit_pause_len          = SIEMENS_BIT_LEN;\r
                         pulse_len                   = SIEMENS_BIT_LEN;\r
                         pause_len                   = SIEMENS_BIT_LEN;\r
-                        has_stop_bit                = SIEMENS_STOP_BIT;\r
+                        has_stop_bit                = SIEMENS_OR_RUWIDO_STOP_BIT;\r
                         complete_data_len           = SIEMENS_COMPLETE_DATA_LEN - 1;\r
                         n_auto_repetitions          = 1;                                            // 1 frame\r
                         auto_repetition_pause_len   = 0;\r
@@ -1175,6 +1299,24 @@ irsnd_ISR (void)
                         break;\r
                     }\r
 #endif\r
+#if IRSND_SUPPORT_LEGO_PROTOCOL == 1\r
+                    case IRMP_LEGO_PROTOCOL:\r
+                    {\r
+                        startbit_pulse_len          = LEGO_START_BIT_PULSE_LEN;\r
+                        startbit_pause_len          = LEGO_START_BIT_PAUSE_LEN - 1;\r
+                        complete_data_len           = LEGO_COMPLETE_DATA_LEN;\r
+                        pulse_1_len                 = LEGO_PULSE_LEN;\r
+                        pause_1_len                 = LEGO_1_PAUSE_LEN - 1;\r
+                        pulse_0_len                 = LEGO_PULSE_LEN;\r
+                        pause_0_len                 = LEGO_0_PAUSE_LEN - 1;\r
+                        has_stop_bit                = LEGO_STOP_BIT;\r
+                        n_auto_repetitions          = 1;                                            // 1 frame\r
+                        auto_repetition_pause_len   = 0;\r
+                        repeat_frame_pause_len      = LEGO_FRAME_REPEAT_PAUSE_LEN;\r
+                        irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
+                        break;\r
+                    }\r
+#endif\r
                     default:\r
                     {\r
                         irsnd_busy = FALSE;\r
@@ -1233,12 +1375,15 @@ irsnd_ISR (void)
 #if IRSND_SUPPORT_NIKON_PROTOCOL == 1\r
                 case IRMP_NIKON_PROTOCOL:\r
 #endif\r
+#if IRSND_SUPPORT_LEGO_PROTOCOL == 1\r
+                case IRMP_LEGO_PROTOCOL:\r
+#endif\r
 \r
 \r
 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1  || IRSND_SUPPORT_NEC_PROTOCOL == 1 || IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1 || IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1 ||   \\r
     IRSND_SUPPORT_KASEIKYO_PROTOCOL == 1 || IRSND_SUPPORT_RECS80_PROTOCOL == 1 || IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1 || IRSND_SUPPORT_DENON_PROTOCOL == 1 || \\r
     IRSND_SUPPORT_NUBERT_PROTOCOL == 1 || IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 || IRSND_SUPPORT_FDC_PROTOCOL == 1 || IRSND_SUPPORT_RCCAR_PROTOCOL == 1 ||   \\r
-    IRSND_SUPPORT_JVC_PROTOCOL == 1 || IRSND_SUPPORT_NIKON_PROTOCOL == 1\r
+    IRSND_SUPPORT_JVC_PROTOCOL == 1 || IRSND_SUPPORT_NIKON_PROTOCOL == 1 || IRSND_SUPPORT_LEGO_PROTOCOL == 1 \r
                 {\r
                     if (pulse_counter == 0)\r
                     {\r
@@ -1419,7 +1564,7 @@ irsnd_ISR (void)
 \r
                                 if (repeat_counter > 0)\r
                                 {                                       // set 117 msec pause time\r
-                                    auto_repetition_pause_len = GRUNDIG_OR_NOKIA_FRAME_REPEAT_PAUSE_LEN;\r
+                                    auto_repetition_pause_len = GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN;\r
                                 }\r
 \r
                                 if (repeat_counter < n_repeat_frames)       // tricky: repeat n info frames per auto repetition before sending last stop frame\r
@@ -1464,8 +1609,8 @@ irsnd_ISR (void)
                             }\r
                             else                                                                        // send n'th bit\r
                             {\r
-                                pulse_len = GRUNDIG_OR_NOKIA_BIT_LEN;\r
-                                pause_len = GRUNDIG_OR_NOKIA_BIT_LEN;\r
+                                pulse_len = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
+                                pause_len = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
                                 first_pulse = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ? TRUE : FALSE;\r
                             }\r
                         }\r