From f50e01e79ba83c2142178a0e2431034c410d7fd0 Mon Sep 17 00:00:00 2001 From: ukw Date: Mon, 11 Apr 2011 14:26:04 +0000 Subject: [PATCH 1/1] version 2.0.0-pre2: added LEGO protocol git-svn-id: svn://mikrocontroller.net/irmp@69 aeb2e35e-bfc4-4214-b83c-9e8de998ed28 --- README.txt | 4 +- irmp.c | 77 +++++++++++++++++++- irmp.h | 20 +++++- irmpconfig.h | 17 +++-- irsnd.c | 189 ++++++++++++++++++++++++++++++++++++++++++++------ irsnd.h | 8 ++- irsndconfig.h | 92 ++++++++++++++---------- irsndmain.c | 2 +- main.c | 4 +- 9 files changed, 340 insertions(+), 73 deletions(-) diff --git a/README.txt b/README.txt index f7c5c5c..fb3a571 100644 --- a/README.txt +++ b/README.txt @@ -1,8 +1,8 @@ IRMP - Infrared Multi Protocol Decoder -------------------------------------- -Version IRMP: 2.0.0-pre1 10.03.2010 -Version IRSND: 1.9.1 22.01.2010 +Version IRMP: 2.0.0-pre2 11.04.2010 +Version IRSND: 1.9.2 11.04.2010 Dokumentation: diff --git a/irmp.c b/irmp.c index 5c35ccf..46e56c5 100644 --- a/irmp.c +++ b/irmp.c @@ -1,9 +1,9 @@ /*--------------------------------------------------------------------------------------------------------------------------------------------------- * irmp.c - infrared multi-protocol decoder, supports several remote control protocols * - * Copyright (c) 2009-2010 Frank Meyer - frank(at)fli4l.de + * Copyright (c) 2009-2011 Frank Meyer - frank(at)fli4l.de * - * $Id: irmp.c,v 1.99 2011/03/10 12:29:13 fm Exp $ + * $Id: irmp.c,v 1.100 2011/04/11 12:54:24 fm Exp $ * * ATMEGA88 @ 8 MHz * @@ -32,6 +32,7 @@ * NIKON - Nikon cameras * RUWIDO - T-Home * KATHREIN - Kathrein + * LEGO - Lego Power Functions RC * *--------------------------------------------------------------------------------------------------------------------------------------------------- * @@ -675,6 +676,17 @@ typedef unsigned int16 uint16_t; #define NETBOX_PULSE_REST_LEN ((uint8_t)(F_INTERRUPTS * NETBOX_PULSE_TIME / 4)) #define NETBOX_PAUSE_REST_LEN ((uint8_t)(F_INTERRUPTS * NETBOX_PAUSE_TIME / 4)) +#define LEGO_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) +#define LEGO_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) +#define LEGO_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) +#define LEGO_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) +#define LEGO_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) +#define LEGO_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) +#define LEGO_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) +#define LEGO_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) +#define LEGO_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) +#define LEGO_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) + #define IMON_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * IMON_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) #define IMON_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * IMON_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) #define IMON_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * IMON_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) @@ -1412,6 +1424,31 @@ static PROGMEM IRMP_PARAMETER netbox_param = #endif +#if IRMP_SUPPORT_LEGO_PROTOCOL == 1 + +static PROGMEM IRMP_PARAMETER lego_param = +{ + IRMP_LEGO_PROTOCOL, // protocol: ir protocol + LEGO_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 + LEGO_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 + LEGO_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 + LEGO_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 + LEGO_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 + LEGO_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 + LEGO_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 + LEGO_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 + LEGO_ADDRESS_OFFSET, // address_offset: address offset + LEGO_ADDRESS_OFFSET + LEGO_ADDRESS_LEN, // address_end: end of address + LEGO_COMMAND_OFFSET, // command_offset: command offset + LEGO_COMMAND_OFFSET + LEGO_COMMAND_LEN, // command_end: end of command + LEGO_COMPLETE_DATA_LEN, // complete_len: complete length of frame + LEGO_STOP_BIT, // stop_bit: flag: frame has stop bit + LEGO_LSB, // lsb_first: flag: LSB first + LEGO_FLAGS // flags: some flags +}; + +#endif + #if IRMP_SUPPORT_IMON_PROTOCOL == 1 static PROGMEM IRMP_PARAMETER imon_param = @@ -1584,6 +1621,24 @@ irmp_get_data (IRMP_DATA * irmp_data_p) break; #endif #endif // 0 +#if IRMP_SUPPORT_LEGO_PROTOCOL == 1 + case IRMP_LEGO_PROTOCOL: + { + uint8_t crc = 0x0F ^ ((irmp_command & 0xF000) >> 12) ^ ((irmp_command & 0x0F00) >> 8) ^ ((irmp_command & 0x00F0) >> 4); + + if ((irmp_command & 0x000F) == crc) + { + irmp_command >>= 4; + rtc = TRUE; + } + else + { + ANALYZE_PRINTF ("CRC error in LEGO protocol\n"); + rtc = TRUE; + } + break; + } +#endif default: rtc = TRUE; } @@ -2190,6 +2245,18 @@ irmp_ISR (void) else #endif // IRMP_SUPPORT_NETBOX_PROTOCOL == 1 +#if IRMP_SUPPORT_LEGO_PROTOCOL == 1 + if (irmp_pulse_time >= LEGO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= LEGO_START_BIT_PULSE_LEN_MAX && + irmp_pause_time >= LEGO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= LEGO_START_BIT_PAUSE_LEN_MAX) + { + ANALYZE_PRINTF ("protocol = LEGO, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + LEGO_START_BIT_PULSE_LEN_MIN, LEGO_START_BIT_PULSE_LEN_MAX, + LEGO_START_BIT_PAUSE_LEN_MIN, LEGO_START_BIT_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &lego_param; + } + else +#endif // IRMP_SUPPORT_NEC_PROTOCOL == 1 + #if IRMP_SUPPORT_IMON_PROTOCOL == 1 if (irmp_pulse_time >= IMON_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= IMON_START_BIT_PULSE_LEN_MAX && irmp_pause_time >= IMON_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= IMON_START_BIT_PAUSE_LEN_MAX) @@ -3344,6 +3411,12 @@ print_timings (void) NIKON_START_BIT_PULSE_LEN_MIN, NIKON_START_BIT_PULSE_LEN_MAX, NIKON_START_BIT_PAUSE_LEN_MIN, NIKON_START_BIT_PAUSE_LEN_MAX, NIKON_PULSE_LEN_MIN, NIKON_PULSE_LEN_MAX, NIKON_0_PAUSE_LEN_MIN, NIKON_0_PAUSE_LEN_MAX, NIKON_PULSE_LEN_MIN, NIKON_PULSE_LEN_MAX, NIKON_1_PAUSE_LEN_MIN, NIKON_1_PAUSE_LEN_MAX); + + printf ("LEGO 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", + LEGO_START_BIT_PULSE_LEN_MIN, LEGO_START_BIT_PULSE_LEN_MAX, LEGO_START_BIT_PAUSE_LEN_MIN, LEGO_START_BIT_PAUSE_LEN_MAX, + LEGO_PULSE_LEN_MIN, LEGO_PULSE_LEN_MAX, LEGO_0_PAUSE_LEN_MIN, LEGO_0_PAUSE_LEN_MAX, + LEGO_PULSE_LEN_MIN, LEGO_PULSE_LEN_MAX, LEGO_1_PAUSE_LEN_MIN, LEGO_1_PAUSE_LEN_MAX); + } void diff --git a/irmp.h b/irmp.h index b123587..cac734f 100644 --- a/irmp.h +++ b/irmp.h @@ -1,9 +1,9 @@ /*--------------------------------------------------------------------------------------------------------------------------------------------------- * irmp.h * - * Copyright (c) 2009-2010 Frank Meyer - frank(at)fli4l.de + * Copyright (c) 2009-2011 Frank Meyer - frank(at)fli4l.de * - * $Id: irmp.h,v 1.59 2011/03/10 12:29:14 fm Exp $ + * $Id: irmp.h,v 1.60 2011/04/11 12:54:24 fm Exp $ * * ATMEGA88 @ 8 MHz * @@ -76,6 +76,7 @@ typedef uint8_t PAUSE_LEN; #define IRMP_NETBOX_PROTOCOL 26 // Netbox keyboard (bitserial) #define IRMP_NEC16_PROTOCOL 27 // NEC with 16 bits (incl. sync) #define IRMP_NEC42_PROTOCOL 28 // NEC with 42 bits +#define IRMP_LEGO_PROTOCOL 29 // LEGO Power Functions RC #define IRMP_IMON_PROTOCOL 99 // Imon (bitserial) PROTOTYPE! // some flags of struct IRMP_PARAMETER: @@ -446,6 +447,21 @@ typedef uint8_t PAUSE_LEN; #define NETBOX_LSB 1 // LSB #define NETBOX_FLAGS IRMP_PARAM_FLAG_IS_SERIAL // flags +#define LEGO_START_BIT_PULSE_TIME 158.0e-6 // 158 usec pulse ( 6 x 1/38kHz) +#define LEGO_START_BIT_PAUSE_TIME 1026.0e-6 // 1026 usec pause (39 x 1/38kHz) +#define LEGO_PULSE_TIME 158.0e-6 // 158 usec pulse ( 6 x 1/38kHz) +#define LEGO_1_PAUSE_TIME 553.0e-6 // 553 usec pause (21 x 1/38kHz) +#define LEGO_0_PAUSE_TIME 263.0e-6 // 263 usec pause (10 x 1/38kHz) +#define LEGO_FRAME_REPEAT_PAUSE_TIME 40.0e-3 // frame repeat after 40ms +#define LEGO_ADDRESS_OFFSET 0 // skip 0 bits +#define LEGO_ADDRESS_LEN 0 // read 0 address bits +#define LEGO_COMMAND_OFFSET 0 // skip 0 bits +#define LEGO_COMMAND_LEN 16 // read 16 bits (12 command + 4 CRC) +#define LEGO_COMPLETE_DATA_LEN 16 // complete length +#define LEGO_STOP_BIT 1 // has stop bit +#define LEGO_LSB 0 // MSB...LSB +#define LEGO_FLAGS 0 // flags + #define IMON_START_BIT_PULSE_TIME 1333.0e-6 // 1333 usec pulse #define IMON_START_BIT_PAUSE_TIME 1172.0e-6 // 1333 usec pause #define IMON_PULSE_TIME 500.0e-6 // 500 usec pulse diff --git a/irmpconfig.h b/irmpconfig.h index a34aebb..1b56408 100644 --- a/irmpconfig.h +++ b/irmpconfig.h @@ -1,9 +1,9 @@ /*--------------------------------------------------------------------------------------------------------------------------------------------------- * irmpconfig.h * - * Copyright (c) 2010 Frank Meyer - frank(at)fli4l.de + * Copyright (c) 2009-2011 Frank Meyer - frank(at)fli4l.de * - * $Id: irmpconfig.h,v 1.64 2011/03/10 12:54:37 fm Exp $ + * $Id: irmpconfig.h,v 1.65 2011/04/11 12:54:25 fm Exp $ * * ATMEGA88 @ 8 MHz * @@ -52,13 +52,16 @@ // more protocols, enable here! Enable Remarks F_INTERRUPTS Program Space #define IRMP_SUPPORT_RC5_PROTOCOL 0 // RC5 >= 10000 ~250 bytes +#define IRMP_SUPPORT_RC6_PROTOCOL 0 // RC6 & RC6A >= 10000 ~250 bytes #define IRMP_SUPPORT_JVC_PROTOCOL 0 // JVC >= 10000 ~150 bytes #define IRMP_SUPPORT_NEC16_PROTOCOL 0 // NEC16 >= 10000 ~50 bytes #define IRMP_SUPPORT_NEC42_PROTOCOL 0 // NEC42 >= 10000 ~150 bytes -#define IRMP_SUPPORT_RC6_PROTOCOL 0 // RC6 & RC6A >= 10000 ~250 bytes #define IRMP_SUPPORT_IR60_PROTOCOL 0 // IR60 (SAB2008) >= 10000 ~300 bytes #define IRMP_SUPPORT_GRUNDIG_PROTOCOL 0 // Grundig >= 10000 ~300 bytes +#define IRMP_SUPPORT_SIEMENS_PROTOCOL 0 // Siemens Gigaset >= 15000 ~550 bytes #define IRMP_SUPPORT_NOKIA_PROTOCOL 0 // Nokia >= 10000 ~300 bytes + +// exotic protocols, enable here! Enable Remarks F_INTERRUPTS Program Space #define IRMP_SUPPORT_KATHREIN_PROTOCOL 0 // Kathrein >= 10000 ~200 bytes #define IRMP_SUPPORT_NUBERT_PROTOCOL 0 // NUBERT >= 10000 ~50 bytes #define IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL 0 // Bang & Olufsen >= 10000 ~200 bytes @@ -67,10 +70,10 @@ #define IRMP_SUPPORT_IMON_PROTOCOL 0 // IMON keyboard >= 10000 ~400 bytes (PROTOTYPE!) #define IRMP_SUPPORT_FDC_PROTOCOL 0 // FDC3402 keyboard >= 10000 (better 15000) ~150 bytes (~400 in combination with RC5) #define IRMP_SUPPORT_RCCAR_PROTOCOL 0 // RC Car >= 10000 (better 15000) ~150 bytes (~500 in combination with RC5) -#define IRMP_SUPPORT_SIEMENS_PROTOCOL 0 // Siemens Gigaset >= 15000 ~550 bytes #define IRMP_SUPPORT_RUWIDO_PROTOCOL 0 // RUWIDO, T-Home >= 15000 ~550 bytes #define IRMP_SUPPORT_RECS80_PROTOCOL 0 // RECS80 (SAA3004) >= 15000 ~50 bytes #define IRMP_SUPPORT_RECS80EXT_PROTOCOL 0 // RECS80EXT (SAA3008) >= 15000 ~50 bytes +#define IRMP_SUPPORT_LEGO_PROTOCOL 0 // LEGO Power RC >= 20000 ~150 bytes /*--------------------------------------------------------------------------------------------------------------------------------------------------- * Change hardware pin here: @@ -126,6 +129,12 @@ #define IRMP_SUPPORT_RECS80EXT_PROTOCOL 0 #endif +#if IRMP_SUPPORT_LEGO_PROTOCOL == 1 && F_INTERRUPTS < 20000 +#warning F_INTERRUPTS too low, LEGO protocol disabled (should be at least 20000) +#undef IRMP_SUPPORT_LEGO_PROTOCOL +#define IRMP_SUPPORT_LEGO_PROTOCOL 0 +#endif + #if IRMP_SUPPORT_JVC_PROTOCOL == 1 && IRMP_SUPPORT_NEC_PROTOCOL == 0 #warning JVC protocol needs also NEC protocol, NEC protocol enabled #undef IRMP_SUPPORT_NEC_PROTOCOL diff --git a/irsnd.c b/irsnd.c index 5f471a6..050031c 100644 --- a/irsnd.c +++ b/irsnd.c @@ -1,9 +1,9 @@ /*--------------------------------------------------------------------------------------------------------------------------------------------------- * @file irsnd.c * - * Copyright (c) 2010 Frank Meyer - frank(at)fli4l.de + * Copyright (c) 2010-2011 Frank Meyer - frank(at)fli4l.de * - * $Id: irsnd.c,v 1.32 2011/02/22 17:05:57 fm Exp $ + * $Id: irsnd.c,v 1.35 2011/04/11 13:26:17 fm Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -54,12 +54,83 @@ typedef unsigned short uint16_t; #include "irsndconfig.h" #include "irsnd.h" +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * ATmega pin definition of OC2 / OC2A / OC2B + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +#if defined (__AVR_ATmega8__) // ATmega8 uses OC2 = PB3 +#undef IRSND_OC2 // has no OC2A / OC2B +#define IRSND_OC2 0 // magic: use OC2 +#define IRSND_PORT PORTB // port B +#define IRSND_DDR DDRB // ddr B +#define IRSND_BIT 3 // OC2A + +#elif defined (__AVR_ATmega16__) \ + || defined (__AVR_ATmega32__) // ATmega16|32 uses OC2 = PD7 +#undef IRSND_OC2 // has no OC2A / OC2B +#define IRSND_OC2 0 // magic: use OC2 +#define IRSND_PORT PORTD // port D +#define IRSND_DDR DDRD // ddr D +#define IRSND_BIT 7 // OC2 + +#elif defined (__AVR_ATmega162__) // ATmega162 uses OC2 = PB1 +#undef IRSND_OC2 // has no OC2A / OC2B +#define IRSND_OC2 0 // magic: use OC2 +#define IRSND_PORT PORTB // port B +#define IRSND_DDR DDRB // ddr B +#define IRSND_BIT 1 // OC2 + +#elif defined (__AVR_ATmega164__) \ + || defined (__AVR_ATmega324__) \ + || defined (__AVR_ATmega644__) \ + || defined (__AVR_ATmega644P__) \ + || defined (__AVR_ATmega1284__) // ATmega164|324|644|644P|1284 uses OC2A = PD7 or OC2B = PD6 +#if IRSND_OC2 == 1 // OC2A +#define IRSND_PORT PORTD // port D +#define IRSND_DDR DDRD // ddr D +#define IRSND_BIT 7 // OC2A +#elif IRSND_OC2 == 2 // OC2B +#define IRSND_PORT PORTD // port D +#define IRSND_DDR DDRD // ddr D +#define IRSND_BIT 6 // OC2B +#else +#error Wrong value for IRSND_OC2, choose 1 or 2 in irsndconfig.h +#endif // IRSND_OC2 + +#elif defined (__AVR_ATmega48__) \ + || defined (__AVR_ATmega88__) \ + || defined (__AVR_ATmega168__) \ + || defined (__AVR_ATmega168__) \ + || defined (__AVR_ATmega328__) \ + || defined (__AVR_ATmega328P__) // ATmega48|88|168|328P uses OC2A = PB3 or OC2B = PD3 +#if IRSND_OC2 == 1 // OC2A +#define IRSND_PORT PORTB // port B +#define IRSND_DDR DDRB // ddr B +#define IRSND_BIT 3 // OC2A +#elif IRSND_OC2 == 2 // OC2B +#define IRSND_PORT PORTD // port D +#define IRSND_DDR DDRD // ddr D +#define IRSND_BIT 3 // OC2B +#else +#error Wrong value for IRSND_OC2, choose 1 or 2 in irsndconfig.h +#endif // IRSND_OC2 + +#else +#if !defined (unix) && !defined (WIN32) +#error OC2A/OC2B not defined, please fill in definitions here. +#endif // unix, WIN32 +#endif // __AVR... + #if IRSND_SUPPORT_NIKON_PROTOCOL == 1 typedef uint16_t IRSND_PAUSE_LEN; #else typedef uint8_t IRSND_PAUSE_LEN; #endif +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * IR timings + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ #define SIRCS_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME + 0.5) #define SIRCS_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME + 0.5) #define SIRCS_1_PULSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME + 0.5) @@ -198,7 +269,15 @@ typedef uint8_t IRSND_PAUSE_LEN; #define NIKON_PULSE_LEN (uint8_t)(F_INTERRUPTS * NIKON_PULSE_TIME + 0.5) #define NIKON_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NIKON_1_PAUSE_TIME + 0.5) #define NIKON_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NIKON_0_PAUSE_TIME + 0.5) -#define NIKON_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NIKON_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t! +#define NIKON_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NIKON_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t! + +#define LEGO_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PULSE_TIME + 0.5) +#define LEGO_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PAUSE_TIME + 0.5) +#define LEGO_REPEAT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_REPEAT_START_BIT_PAUSE_TIME + 0.5) +#define LEGO_PULSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_PULSE_TIME + 0.5) +#define LEGO_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_1_PAUSE_TIME + 0.5) +#define LEGO_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME + 0.5) +#define LEGO_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * LEGO_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t! static volatile uint8_t irsnd_busy; static volatile uint8_t irsnd_protocol; @@ -206,6 +285,10 @@ static volatile uint8_t irsnd_buffer[6]; static volatile uint8_t irsnd_repeat; static volatile uint8_t irsnd_is_on = FALSE; +#if IRSND_USE_CALLBACK == 1 +static void (*irsnd_callback_ptr) (uint8_t); +#endif // IRSND_USE_CALLBACK == 1 + /*--------------------------------------------------------------------------------------------------------------------------------------------------- * Switch PWM on * @details Switches PWM on with a narrow spike on all 3 channels -> leds glowing @@ -217,12 +300,22 @@ irsnd_on (void) if (! irsnd_is_on) { #ifndef DEBUG -#if defined (__AVR_ATmega32__) - TCCR2 |= (1<command & 0x0F00) >> 8) ^ ((irmp_data_p->command & 0x00F0) >> 4) ^ (irmp_data_p->command & 0x000F); + + irsnd_buffer[0] = (irmp_data_p->command & 0x0FF0) >> 4; // CCCCCCCC + irsnd_buffer[1] = ((irmp_data_p->command & 0x000F) << 4) | crc; // CCCCcccc + + irsnd_protocol = IRMP_LEGO_PROTOCOL; + irsnd_busy = TRUE; + break; + } #endif default: { @@ -1073,9 +1197,9 @@ irsnd_ISR (void) pause_len = GRUNDIG_NOKIA_IR60_BIT_LEN; has_stop_bit = GRUNDIG_NOKIA_IR60_STOP_BIT; complete_data_len = NOKIA_COMPLETE_DATA_LEN; - n_auto_repetitions = NOKIA_FRAMES; // 2 frames - auto_repetition_pause_len = NOKIA_AUTO_REPETITION_PAUSE_LEN; // 20 msec pause - repeat_frame_pause_len = GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN; // 117 msec pause + n_auto_repetitions = NOKIA_FRAMES; // 2 frames + auto_repetition_pause_len = NOKIA_AUTO_REPETITION_PAUSE_LEN; // 20 msec pause + repeat_frame_pause_len = GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN; // 117 msec pause irsnd_set_freq (IRSND_FREQ_38_KHZ); break; } @@ -1175,6 +1299,24 @@ irsnd_ISR (void) break; } #endif +#if IRSND_SUPPORT_LEGO_PROTOCOL == 1 + case IRMP_LEGO_PROTOCOL: + { + startbit_pulse_len = LEGO_START_BIT_PULSE_LEN; + startbit_pause_len = LEGO_START_BIT_PAUSE_LEN - 1; + complete_data_len = LEGO_COMPLETE_DATA_LEN; + pulse_1_len = LEGO_PULSE_LEN; + pause_1_len = LEGO_1_PAUSE_LEN - 1; + pulse_0_len = LEGO_PULSE_LEN; + pause_0_len = LEGO_0_PAUSE_LEN - 1; + has_stop_bit = LEGO_STOP_BIT; + n_auto_repetitions = 1; // 1 frame + auto_repetition_pause_len = 0; + repeat_frame_pause_len = LEGO_FRAME_REPEAT_PAUSE_LEN; + irsnd_set_freq (IRSND_FREQ_38_KHZ); + break; + } +#endif default: { irsnd_busy = FALSE; @@ -1233,12 +1375,15 @@ irsnd_ISR (void) #if IRSND_SUPPORT_NIKON_PROTOCOL == 1 case IRMP_NIKON_PROTOCOL: #endif +#if IRSND_SUPPORT_LEGO_PROTOCOL == 1 + case IRMP_LEGO_PROTOCOL: +#endif #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1 || IRSND_SUPPORT_NEC_PROTOCOL == 1 || IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1 || IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1 || \ IRSND_SUPPORT_KASEIKYO_PROTOCOL == 1 || IRSND_SUPPORT_RECS80_PROTOCOL == 1 || IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1 || IRSND_SUPPORT_DENON_PROTOCOL == 1 || \ IRSND_SUPPORT_NUBERT_PROTOCOL == 1 || IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 || IRSND_SUPPORT_FDC_PROTOCOL == 1 || IRSND_SUPPORT_RCCAR_PROTOCOL == 1 || \ - IRSND_SUPPORT_JVC_PROTOCOL == 1 || IRSND_SUPPORT_NIKON_PROTOCOL == 1 + IRSND_SUPPORT_JVC_PROTOCOL == 1 || IRSND_SUPPORT_NIKON_PROTOCOL == 1 || IRSND_SUPPORT_LEGO_PROTOCOL == 1 { if (pulse_counter == 0) { diff --git a/irsnd.h b/irsnd.h index b5f214b..a71b397 100644 --- a/irsnd.h +++ b/irsnd.h @@ -1,9 +1,9 @@ /*--------------------------------------------------------------------------------------------------------------------------------------------------- * irsnd.h * - * Copyright (c) 2010 Frank Meyer - frank(at)fli4l.de + * Copyright (c) 2010-2011 Frank Meyer - frank(at)fli4l.de * - * $Id: irsnd.h,v 1.3 2010/06/10 10:05:56 fm Exp $ + * $Id: irsnd.h,v 1.4 2011/04/11 12:54:25 fm Exp $ * * ATMEGA88 @ 8 MHz * @@ -44,4 +44,8 @@ extern uint8_t irsnd_send_data (IRMP_DATA *, uint8_t); */ extern uint8_t irsnd_ISR (void); +#if IRSND_USE_CALLBACK == 1 +extern void irsnd_set_callback_ptr (void (*cb)(uint8_t)); +#endif // IRSND_USE_CALLBACK == 1 + #endif /* _WC_IRSND_H_ */ diff --git a/irsndconfig.h b/irsndconfig.h index 11fdb87..689baaa 100644 --- a/irsndconfig.h +++ b/irsndconfig.h @@ -1,9 +1,9 @@ /*--------------------------------------------------------------------------------------------------------------------------------------------------- * irsndconfig.h * - * Copyright (c) 2010 Frank Meyer - frank(at)fli4l.de + * Copyright (c) 2010-2011 Frank Meyer - frank(at)fli4l.de * - * $Id: irsndconfig.h,v 1.17 2011/01/18 13:02:15 fm Exp $ + * $Id: irsndconfig.h,v 1.20 2011/04/11 13:28:12 fm Exp $ * * ATMEGA88 @ 8 MHz * @@ -15,11 +15,11 @@ */ /*--------------------------------------------------------------------------------------------------------------------------------------------------- - * Change F_INTERRUPTS if you change the number of interrupts per second, F_INTERRUPTS should be in the range from 10000 to 15000 + * Change F_INTERRUPTS if you change the number of interrupts per second, F_INTERRUPTS should be in the range from 10000 to 20000, typically 15000 *--------------------------------------------------------------------------------------------------------------------------------------------------- */ #ifndef F_INTERRUPTS -#define F_INTERRUPTS 10000 // interrupts per second +#define F_INTERRUPTS 15000 // interrupts per second #endif /*--------------------------------------------------------------------------------------------------------------------------------------------------- @@ -29,44 +29,58 @@ * 0 disable decoder *--------------------------------------------------------------------------------------------------------------------------------------------------- */ -// Protocol Enable Remarks F_INTERRUPTS Program Space -#define IRSND_SUPPORT_SIRCS_PROTOCOL 1 // Sony SIRCS >= 10000 uses ~150 bytes -#define IRSND_SUPPORT_NEC_PROTOCOL 1 // NEC + APPLE >= 10000 uses ~100 bytes -#define IRSND_SUPPORT_SAMSUNG_PROTOCOL 1 // Samsung + Samsung32 >= 10000 uses ~300 bytes -#define IRSND_SUPPORT_MATSUSHITA_PROTOCOL 1 // Matsushita >= 10000 uses ~200 bytes -#define IRSND_SUPPORT_KASEIKYO_PROTOCOL 1 // Kaseikyo >= 10000 uses ~150 bytes -#define IRSND_SUPPORT_RC5_PROTOCOL 1 // RC5 >= 10000 uses ~150 bytes -#define IRSND_SUPPORT_DENON_PROTOCOL 1 // DENON, Sharp >= 10000 uses ~200 bytes -#define IRSND_SUPPORT_JVC_PROTOCOL 1 // JVC >= 10000 uses ~150 bytes -#define IRSND_SUPPORT_RC6_PROTOCOL 1 // RC6 >= 10000 uses ~250 bytes -#define IRSND_SUPPORT_RC6A_PROTOCOL 1 // RC6A >= 10000 uses ~250 bytes -#define IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL 1 // Bang&Olufsen >= 10000 uses ~250 bytes -#define IRSND_SUPPORT_GRUNDIG_PROTOCOL 1 // Grundig >= 10000 uses ~300 bytes -#define IRSND_SUPPORT_NOKIA_PROTOCOL 1 // Nokia >= 10000 uses ~400 bytes -#define IRSND_SUPPORT_NUBERT_PROTOCOL 0 // NUBERT >= 10000 uses ~100 bytes -#define IRSND_SUPPORT_NIKON_PROTOCOL 0 // NIKON >= 10000 uses ~150 bytes -#define IRSND_SUPPORT_FDC_PROTOCOL 0 // FDC IR keyboard >= 10000 (better 15000) uses ~150 bytes -#define IRSND_SUPPORT_RCCAR_PROTOCOL 0 // RC CAR >= 10000 (better 15000) uses ~150 bytes -#define IRSND_SUPPORT_SIEMENS_PROTOCOL 0 // Siemens, Gigaset >= 15000 uses ~150 bytes -#define IRSND_SUPPORT_RECS80_PROTOCOL 0 // RECS80 >= 20000 uses ~100 bytes -#define IRSND_SUPPORT_RECS80EXT_PROTOCOL 0 // RECS80EXT >= 20000 uses ~100 bytes + +// typical protocols, disable here! Enable Remarks F_INTERRUPTS Program Space +#define IRSND_SUPPORT_SIRCS_PROTOCOL 1 // Sony SIRCS >= 10000 ~150 bytes +#define IRSND_SUPPORT_NEC_PROTOCOL 1 // NEC + APPLE >= 10000 ~100 bytes +#define IRSND_SUPPORT_SAMSUNG_PROTOCOL 1 // Samsung + Samsung32 >= 10000 ~300 bytes +#define IRSND_SUPPORT_MATSUSHITA_PROTOCOL 1 // Matsushita >= 10000 ~200 bytes +#define IRSND_SUPPORT_KASEIKYO_PROTOCOL 1 // Kaseikyo >= 10000 ~150 bytes +#define IRSND_SUPPORT_DENON_PROTOCOL 1 // DENON, Sharp >= 10000 ~200 bytes + +// more protocols, enable here! Enable Remarks F_INTERRUPTS Program Space +#define IRSND_SUPPORT_RC5_PROTOCOL 0 // RC5 >= 10000 ~150 bytes +#define IRSND_SUPPORT_RC6_PROTOCOL 0 // RC6 >= 10000 ~250 bytes +#define IRSND_SUPPORT_RC6A_PROTOCOL 0 // RC6A >= 10000 ~250 bytes +#define IRSND_SUPPORT_JVC_PROTOCOL 0 // JVC >= 10000 ~150 bytes +#define IRSND_SUPPORT_NEC16_PROTOCOL 0 // NEC16 >= 10000 DON'T CHANGE, NOT SUPPORTED YET! +#define IRSND_SUPPORT_NEC42_PROTOCOL 0 // NEC42 >= 10000 DON'T CHANGE, NOT SUPPORTED YET! +#define IRSND_SUPPORT_IR60_PROTOCOL 0 // IR60 (SAB2008) >= 10000 DON'T CHANGE, NOT SUPPORTED YET! +#define IRSND_SUPPORT_GRUNDIG_PROTOCOL 0 // Grundig >= 10000 ~300 bytes +#define IRSND_SUPPORT_SIEMENS_PROTOCOL 0 // Siemens, Gigaset >= 15000 ~150 bytes +#define IRSND_SUPPORT_NOKIA_PROTOCOL 0 // Nokia >= 10000 ~400 bytes + +// exotic protocols, enable here! Enable Remarks F_INTERRUPTS Program Space +#define IRSND_SUPPORT_KATHREIN_PROTOCOL 0 // Kathrein >= 10000 DON'T CHANGE, NOT SUPPORTED YET! +#define IRSND_SUPPORT_NUBERT_PROTOCOL 0 // NUBERT >= 10000 ~100 bytes +#define IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL 0 // Bang&Olufsen >= 10000 ~250 bytes +#define IRSND_SUPPORT_NIKON_PROTOCOL 0 // NIKON >= 10000 ~150 bytes +#define IRSND_SUPPORT_NETBOX_PROTOCOL 0 // Netbox keyboard >= 10000 DON'T CHANGE, NOT SUPPORTED YET! +#define IRSND_SUPPORT_IMON_PROTOCOL 0 // IMON keyboard >= 10000 DON'T CHANGE, NOT SUPPORTED YET! +#define IRSND_SUPPORT_FDC_PROTOCOL 0 // FDC IR keyboard >= 10000 (better 15000) ~150 bytes +#define IRSND_SUPPORT_RCCAR_PROTOCOL 0 // RC CAR >= 10000 (better 15000) ~150 bytes +#define IRSND_SUPPORT_RUWIDO_PROTOCOL 0 // RUWIDO, T-Home >= 15000 DON'T CHANGE, NOT SUPPORTED YET! +#define IRSND_SUPPORT_RECS80_PROTOCOL 0 // RECS80 >= 20000 ~100 bytes +#define IRSND_SUPPORT_RECS80EXT_PROTOCOL 0 // RECS80EXT >= 20000 ~100 bytes +#define IRSND_SUPPORT_LEGO_PROTOCOL 0 // LEGO Power RC >= 20000 ~150 bytes /*--------------------------------------------------------------------------------------------------------------------------------------------------- * Change hardware pin here: *--------------------------------------------------------------------------------------------------------------------------------------------------- */ -#if defined (__AVR_ATmega32__) || defined (__AVR_ATmega644P__) -#define IRSND_PORT PORTD // port D -#define IRSND_DDR DDRD // ddr D -#define IRSND_BIT 7 // OC2A -#else -#define IRSND_PORT PORTB // port B -#define IRSND_DDR DDRB // ddr B -#define IRSND_BIT 3 // OC2A -#endif // __AVR... +#define IRSND_OC2 1 // 0 = OC2, 1 = OC2A, 2 = OC2B, default is 1 +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * Use Callbacks to indicate output signal or something else + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +#define IRSND_USE_CALLBACK 0 // flag: 0 = don't use callbacks, 1 = use callbacks, default is 0 +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * D O N O T C H A N G E T H E F O L L O W I N G L I N E S ! + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1 && F_INTERRUPTS < 15000 #warning F_INTERRUPTS too low, SIEMENS protocol disabled (should be at least 15000) #undef IRSND_SUPPORT_SIEMENS_PROTOCOL @@ -76,11 +90,17 @@ #if IRSND_SUPPORT_RECS80_PROTOCOL == 1 && F_INTERRUPTS < 20000 #warning F_INTERRUPTS too low, RECS80 protocol disabled (should be at least 20000) #undef IRSND_SUPPORT_RECS80_PROTOCOL -#define IRSND_SUPPORT_RECS80_PROTOCOL 0 +#define IRSND_SUPPORT_RECS80_PROTOCOL 0 // DO NOT CHANGE! F_INTERRUPTS too low! #endif #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1 && F_INTERRUPTS < 20000 #warning F_INTERRUPTS too low, RECS80EXT protocol disabled (should be at least 20000) #undef IRSND_SUPPORT_RECS80EXT_PROTOCOL -#define IRSND_SUPPORT_RECS80EXT_PROTOCOL 0 +#define IRSND_SUPPORT_RECS80EXT_PROTOCOL 0 // DO NOT CHANGE! F_INTERRUPTS too low! +#endif + +#if IRSND_SUPPORT_LEGO_PROTOCOL == 1 && F_INTERRUPTS < 20000 +#warning F_INTERRUPTS too low, LEGO protocol disabled (should be at least 20000) +#undef IRSND_SUPPORT_LEGO_PROTOCOL +#define IRSND_SUPPORT_LEGO_PROTOCOL 0 // DO NOT CHANGE! F_INTERRUPTS too low! #endif diff --git a/irsndmain.c b/irsndmain.c index e5a03cb..def3b31 100644 --- a/irsndmain.c +++ b/irsndmain.c @@ -1,7 +1,7 @@ /*--------------------------------------------------------------------------------------------------------------------------------------------------- * irsndmain.c - demo main module to test irmp decoder * - * Copyright (c) 2010 Frank Meyer - frank(at)fli4l.de + * Copyright (c) 2010-2011 Frank Meyer - frank(at)fli4l.de * * ATMEGA88 @ 8 MHz * diff --git a/main.c b/main.c index f28cce9..0248d8e 100644 --- a/main.c +++ b/main.c @@ -1,9 +1,9 @@ /*--------------------------------------------------------------------------------------------------------------------------------------------------- * main.c - demo main module to test irmp decoder * - * Copyright (c) 2009-2010 Frank Meyer - frank(at)fli4l.de + * Copyright (c) 2009-2011 Frank Meyer - frank(at)fli4l.de * - * $Id: main.c,v 1.8 2010/08/30 15:45:27 fm Exp $ + * $Id: main.c,v 1.9 2011/04/11 12:54:25 fm Exp $ * * ATMEGA88 @ 8 MHz * -- 2.39.2