From 0f700c8ea4b0e9729805828c4fab5ab0fe2b6443 Mon Sep 17 00:00:00 2001 From: ukw Date: Mon, 13 Feb 2012 11:18:28 +0000 Subject: [PATCH] Version 2.0.3: irmp: - fixed bug when switching from nec42 to nec protocol - corrected timing for samsung/samsung32 protocol - added genre bits for kaseikyo irsnd: - corrected timing for samsung/samsung32 protocol - added pause after sending last frame - added genre bits for kaseikyo git-svn-id: svn://mikrocontroller.net/irmp@85 aeb2e35e-bfc4-4214-b83c-9e8de998ed28 --- IR-Data/samsung32-15kHz.txt | 4 +++ IR-Data/test-suite.sh | 1 + README.txt | 4 +-- irmp.c | 58 ++++++++++++++++++++++--------------- irmp.h | 9 +++--- irsnd.aps | 2 +- irsnd.c | 39 +++++++++++++++++++------ main.c | 9 +++++- 8 files changed, 86 insertions(+), 40 deletions(-) create mode 100644 IR-Data/samsung32-15kHz.txt diff --git a/IR-Data/samsung32-15kHz.txt b/IR-Data/samsung32-15kHz.txt new file mode 100644 index 0000000..9ad8a3a --- /dev/null +++ b/IR-Data/samsung32-15kHz.txt @@ -0,0 +1,4 @@ +# 62 +00000000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111111111111111111100000000011111111111111111111111110000000001111111100000000011111111111111111111111100000000011111111000000000111111110000000001111111100000000011111111000000000111111100000000001111111111111111111111110000000001111111100000000011111111111111111111111110000000001111111000000000011111110000000000111111100000000001111111000000000111111110000000001111111100000000011111111111111111111111110000000001111111000000000111111110000000001111111100000000011111111000000000111111110000000001111111100000000011111111111111111111111100000000011111111000000000111111111111111111111111100000000011111111111111111111111100000000001111111111111111111111110000000001111111111111111111111111000000000111111111111111111111111000000000011111111111111111111111100000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000000000000000000000000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111111110000000000111111111111111111111111000000000111111110000000001111111111111111111111111000000000111111100000000011111111000000000111111110000000001111111100000000011111111000000000111111111111111111111111000000000011111110000000000111111111111111111111111000000000111111110000000001111111100000000011111110000000000111111100000000011111111000000000111111110000000001111111111111111111111111000000000111111110000000001111111000000000111111110000000001111111100000000011111111000000000111111110000000001111111111111111111111110000000001111111100000000011111111111111111111111110000000001111111111111111111111110000000000111111111111111111111111000000000111111111111111111111111100000000011111111111111111111111100000000001111111111111111111111110000000001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000000000000000000000000000000000000000000000000000000000000000000111111111111111111111111111111111111111111111111111111111111111111000000000011111111111111111111111100000000011111111000000000111111111111111111111111100000000011111111000000000111111100000000001111111000000000011111110000000001111111100000000011111111111111111111111100000000001111111000000000011111111111111111111111100000000011111111000000000111111110000000001111111100000000011111111000000000111111100000000011111111000000000111111111111111111111111100000000011111111000000000111111110000000001111111000000000011111110000000001111111100000000011111111000000000111111111111111111111111100000000011111111000000001111111111111111111111111000000000111111111111111111111111100000000011111111111111111111111100000000011111111111111111111111110000000001111111111111111111111111000000000111111111111111111111111000000000111111111111111111111 +# 71 +000000000000000000000000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111111111000000000111111111111111111111111000000000011111110000000001111111100000000011111111000000000111111110000000001111111000000000011111110000000000111111111111111111111111000000000011111111111111111111111100000000011111111000000000111111110000000001111111100000000011111110000000000111111100000000001111111000000000011111111111111111111111100000000011111111000000000111111110000000001111111100000000011111110000000001111111100000000001111111111111111111111110000000001111111111111111111111111000000000111111111111111111111111000000000011111111111111111111111100000000001111111111111111111111110000000001111111111111111111111111000000000111111111111111111111111000000000011111111111111111111111100000000001111111000000000111111110000000001111111100000000011111111111111 diff --git a/IR-Data/test-suite.sh b/IR-Data/test-suite.sh index 94a7974..58a2c9a 100644 --- a/IR-Data/test-suite.sh +++ b/IR-Data/test-suite.sh @@ -83,6 +83,7 @@ for j in \ irc-15kHz.txt \ kathrein-15kHz.txt \ recs80-15kHz.txt \ + samsung32-15kHz.txt \ t-home-mediareceiver-15kHz.txt \ universal-15kHz.txt \ xbox360-15kHz.txt diff --git a/README.txt b/README.txt index 61fa72c..83e2a6a 100644 --- a/README.txt +++ b/README.txt @@ -1,8 +1,8 @@ IRMP - Infrared Multi Protocol Decoder -------------------------------------- -Version IRMP: 2.0.2 22.09.2011 -Version IRSND: 2.0.1 20.09.2011 +Version IRMP: 2.0.3 13.02.2012 +Version IRSND: 2.0.3 13.02.2012 Dokumentation: diff --git a/irmp.c b/irmp.c index 020860f..9a707ba 100644 --- a/irmp.c +++ b/irmp.c @@ -3,7 +3,7 @@ * * Copyright (c) 2009-2011 Frank Meyer - frank(at)fli4l.de * - * $Id: irmp.c,v 1.110 2011/09/22 10:19:44 fm Exp $ + * $Id: irmp.c,v 1.112 2012/02/13 10:59:07 fm Exp $ * * ATMEGA88 @ 8 MHz * @@ -1736,6 +1736,7 @@ static uint16_t irmp_tmp_id; #endif #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 static uint8_t xor_check[6]; // check kaseikyo "parity" bits +static uint8_t genre2; // save genre2 bits here, later copied to MSB in flags #endif /*--------------------------------------------------------------------------------------------------------------------------------------------------- @@ -1798,23 +1799,29 @@ irmp_store_bit (uint8_t value) #endif #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 - else if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL && irmp_bit >= 20 && irmp_bit < 24) + else if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL) { - irmp_tmp_command |= (((uint16_t) (value)) << (irmp_bit - 8)); // store 4 system bits in upper nibble with LSB first - } - - if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL && irmp_bit < KASEIKYO_COMPLETE_DATA_LEN) - { - if (value) + if (irmp_bit >= 20 && irmp_bit < 24) { - xor_check[irmp_bit / 8] |= 1 << (irmp_bit % 8); + irmp_tmp_command |= (((uint16_t) (value)) << (irmp_bit - 8)); // store 4 system bits (genre 1) in upper nibble with LSB first } - else + else if (irmp_bit >= 24 && irmp_bit < 28) { - xor_check[irmp_bit / 8] &= ~(1 << (irmp_bit % 8)); + genre2 |= (((uint8_t) (value)) << (irmp_bit - 20)); // store 4 system bits (genre 2) in upper nibble with LSB first } - } + if (irmp_bit < KASEIKYO_COMPLETE_DATA_LEN) + { + if (value) + { + xor_check[irmp_bit / 8] |= 1 << (irmp_bit % 8); + } + else + { + xor_check[irmp_bit / 8] &= ~(1 << (irmp_bit % 8)); + } + } + } #endif irmp_bit++; @@ -1914,7 +1921,7 @@ irmp_ISR (void) #ifdef ANALYZE if (! irmp_pulse_time) { - ANALYZE_PRINTF("%8d [starting pulse]\n", time_counter); + ANALYZE_PRINTF("%8.3fms [starting pulse]\n", (double) (time_counter * 1000) / F_INTERRUPTS); } #endif irmp_pulse_time++; // increment counter @@ -1928,6 +1935,9 @@ irmp_ISR (void) wait_for_space = 0; irmp_tmp_command = 0; irmp_tmp_address = 0; +#if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 + genre2 = 0; +#endif #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) || IRMP_SUPPORT_NEC42_PROTOCOL == 1 irmp_tmp_command2 = 0; @@ -1972,7 +1982,7 @@ irmp_ISR (void) else #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1 { - ANALYZE_PRINTF ("%8d error 1: pause after start bit pulse %d too long: %d\n", time_counter, irmp_pulse_time, irmp_pause_time); + ANALYZE_PRINTF ("%8.3fms error 1: pause after start bit pulse %d too long: %d\n", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_pulse_time, irmp_pause_time); ANALYZE_ONLY_NORMAL_PUTCHAR ('\n'); } // irmp_busy_flag = FALSE; @@ -1989,7 +1999,7 @@ irmp_ISR (void) irmp_param2.protocol = 0; #endif - ANALYZE_PRINTF ("%8d [start-bit: pulse = %2d, pause = %2d]\n", time_counter, irmp_pulse_time, irmp_pause_time); + ANALYZE_PRINTF ("%8.3fms [start-bit: pulse = %2d, pause = %2d]\n", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_pulse_time, irmp_pause_time); #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1 if (irmp_pulse_time >= SIRCS_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SIRCS_START_BIT_PULSE_LEN_MAX && @@ -2453,14 +2463,14 @@ irmp_ISR (void) { if (irmp_pause_time > irmp_param.pulse_1_len_max && irmp_pause_time <= 2 * irmp_param.pulse_1_len_max) { - ANALYZE_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time); + ANALYZE_PRINTF ("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time); ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '0' : '1'); ANALYZE_NEWLINE (); irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 0 : 1); } else if (! last_value) // && irmp_pause_time >= irmp_param.pause_1_len_min && irmp_pause_time <= irmp_param.pause_1_len_max) { - ANALYZE_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time); + ANALYZE_PRINTF ("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time); ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '1' : '0'); ANALYZE_NEWLINE (); @@ -2482,7 +2492,7 @@ irmp_ISR (void) #if IRMP_SUPPORT_DENON_PROTOCOL == 1 if (irmp_param.protocol == IRMP_DENON_PROTOCOL) { - ANALYZE_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time); + ANALYZE_PRINTF ("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time); if (irmp_pause_time >= DENON_1_PAUSE_LEN_MIN && irmp_pause_time <= DENON_1_PAUSE_LEN_MAX) { // pause timings correct for "1"? @@ -2502,7 +2512,7 @@ irmp_ISR (void) #if IRMP_SUPPORT_THOMSON_PROTOCOL == 1 if (irmp_param.protocol == IRMP_THOMSON_PROTOCOL) { - ANALYZE_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time); + ANALYZE_PRINTF ("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time); if (irmp_pause_time >= THOMSON_1_PAUSE_LEN_MIN && irmp_pause_time <= THOMSON_1_PAUSE_LEN_MAX) { // pause timings correct for "1"? @@ -2703,7 +2713,7 @@ irmp_ISR (void) // 0123456789ABC0123456789ABC0123456701234567 // NEC42: AAAAAAAAAAAAAaaaaaaaaaaaaaCCCCCCCCcccccccc // NEC: AAAAAAAAaaaaaaaaCCCCCCCCcccccccc - irmp_tmp_address |= (irmp_tmp_address2 & 0x0007) << 12; + irmp_tmp_address |= (irmp_tmp_address2 & 0x0007) << 13; // fm 2012-02-13: 12 -> 13 irmp_tmp_command = (irmp_tmp_address2 >> 3) | (irmp_tmp_command << 10); } #endif // IRMP_SUPPORT_NEC_PROTOCOL == 1 @@ -2743,7 +2753,7 @@ irmp_ISR (void) if (got_light) { - ANALYZE_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time); + ANALYZE_PRINTF ("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time); #if IRMP_SUPPORT_MANCHESTER == 1 if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER)) // Manchester @@ -3252,7 +3262,7 @@ irmp_ISR (void) #endif { - ANALYZE_PRINTF ("%8d code detected, length = %d\n", time_counter, irmp_bit); + ANALYZE_PRINTF ("%8.3fms code detected, length = %d\n", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit); irmp_ir_detected = TRUE; #if IRMP_SUPPORT_DENON_PROTOCOL == 1 @@ -3336,6 +3346,8 @@ irmp_ISR (void) ANALYZE_PRINTF ("error 4: wrong XOR check for data bits: 0x%02x 0x%02x\n", xor, xor_check[5]); irmp_ir_detected = FALSE; } + + irmp_flags |= genre2; // write the genre2 bits into MSB of the flag byte } #endif // IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 @@ -3806,7 +3818,7 @@ next_tick (void) if (verbose) { - printf ("%8d ", time_counter); + printf ("%8.3fms ", (double) (time_counter * 1000) / F_INTERRUPTS); } if (irmp_data.protocol == IRMP_FDC_PROTOCOL && (key = get_fdc_key (irmp_data.command)) != 0) diff --git a/irmp.h b/irmp.h index 4ac14b0..ccaee81 100644 --- a/irmp.h +++ b/irmp.h @@ -3,7 +3,7 @@ * * Copyright (c) 2009-2011 Frank Meyer - frank(at)fli4l.de * - * $Id: irmp.h,v 1.67 2011/09/22 10:19:44 fm Exp $ + * $Id: irmp.h,v 1.68 2012/02/13 10:55:50 fm Exp $ * * ATMEGA88 @ 8 MHz * @@ -136,8 +136,9 @@ typedef uint8_t PAUSE_LEN; #define SAMSUNG_START_BIT_PULSE_TIME 4500.0e-6 // 4500 usec pulse #define SAMSUNG_START_BIT_PAUSE_TIME 4500.0e-6 // 4500 usec pause #define SAMSUNG_PULSE_TIME 550.0e-6 // 550 usec pulse -#define SAMSUNG_1_PAUSE_TIME 1450.0e-6 // 1450 usec pause -#define SAMSUNG_0_PAUSE_TIME 450.0e-6 // 450 usec pause +#define SAMSUNG_1_PAUSE_TIME 1650.0e-6 // 1650 usec pause +#define SAMSUNG_0_PAUSE_TIME 550.0e-6 // 550 usec pause + #define SAMSUNG_FRAME_REPEAT_PAUSE_TIME 25.0e-3 // frame repeat after 25ms #define SAMSUNG_ADDRESS_OFFSET 0 // skip 0 bits #define SAMSUNG_ADDRESS_LEN 16 // read 16 address bits @@ -153,7 +154,7 @@ typedef uint8_t PAUSE_LEN; #define SAMSUNG32_COMMAND_OFFSET 16 // skip 16 bits #define SAMSUNG32_COMMAND_LEN 16 // read 16 command bits #define SAMSUNG32_COMPLETE_DATA_LEN 32 // complete length -#define SAMSUNG32_FRAMES 2 // SAMSUNG32 sends each frame 2 times +#define SAMSUNG32_FRAMES 1 // SAMSUNG32 sends each frame 1 times #define SAMSUNG32_AUTO_REPETITION_PAUSE_TIME 47.0e-3 // repetition after 47 ms #define SAMSUNG32_FRAME_REPEAT_PAUSE_TIME 47.0e-3 // frame repeat after 40ms diff --git a/irsnd.aps b/irsnd.aps index 386137e..6b9e031 100644 --- a/irsnd.aps +++ b/irsnd.aps @@ -1 +1 @@ -irsnd07-Jan-2010 20:23:4907-Sep-2011 16:01:18241007-Jan-2010 20:23:4944, 18, 0, 670AVR GCCdefault\irsnd.elfC:\avr\irmp\AVR SimulatorATmega88.xmlfalseR00R01R02R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25R26R27R28R29R30R31Auto000irsndmain.cirsnd.cirmp.hirsnd.hirsndconfig.hdefault\irsnd.lssdefault\irsnd.mapdefaultNOatmega88111irsnd.elfdefault\0-Wall -gdwarf-2 -std=gnu99 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enumsdefault1C:\Program Files\WinAVR-20100110\bin\avr-gcc.exeC:\Program Files\WinAVR-20100110\utils\bin\make.exe00000irsndmain.c100001irmp.h100002irsnd.c100003irsnd.h100004irsndconfig.h1 +irsnd07-Jan-2010 20:23:4909-Oct-2011 12:13:26241007-Jan-2010 20:23:4944, 18, 0, 670AVR GCCdefault\irsnd.elfC:\avr\irmp\AVR SimulatorATmega88.xmlfalseR00R01R02R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25R26R27R28R29R30R31Auto000irsndmain.cirsnd.cirmp.hirsnd.hirsndconfig.hdefault\irsnd.lssdefault\irsnd.mapdefaultNOatmega1284p111irsnd.elfdefault\0-Wall -gdwarf-2 -std=gnu99 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enumsdefault1C:\Program Files\WinAVR-20100110\bin\avr-gcc.exeC:\Program Files\WinAVR-20100110\utils\bin\make.exe00000irsndmain.c100001irmp.h100002irsnd.c100003irsnd.h100004irsndconfig.h1 diff --git a/irsnd.c b/irsnd.c index 09fa295..ce93c1a 100644 --- a/irsnd.c +++ b/irsnd.c @@ -12,7 +12,7 @@ * ATmega164, ATmega324, ATmega644, ATmega644P, ATmega1284 * ATmega88, ATmega88P, ATmega168, ATmega168P, ATmega328P * - * $Id: irsnd.c,v 1.41 2011/09/20 10:45:28 fm Exp $ + * $Id: irsnd.c,v 1.45 2012/02/13 11:02:29 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 @@ -136,7 +136,8 @@ typedef unsigned short uint16_t; || defined (__AVR_ATmega324__) \ || defined (__AVR_ATmega644__) \ || defined (__AVR_ATmega644P__) \ - || defined (__AVR_ATmega1284__) // ATmega164|324|644|644P|1284 uses OC2A = PD7 or OC2B = PD6 or OC0A = PB3 or OC0B = PB4 + || defined (__AVR_ATmega1284__) \ + || defined (__AVR_ATmega1284P__) // ATmega164|324|644|644P|1284 uses OC2A = PD7 or OC2B = PD6 or OC0A = PB3 or OC0B = PB4 #if IRSND_OCx == IRSND_OC2A // OC2A #define IRSND_PORT PORTD // port D #define IRSND_DDR DDRD // ddr D @@ -182,6 +183,21 @@ typedef unsigned short uint16_t; #else #error Wrong value for IRSND_OCx, choose IRSND_OC2A, IRSND_OC2B, IRSND_OC0A, or IRSND_OC0B in irsndconfig.h #endif // IRSND_OCx +#elif defined (__AVR_ATmega8515__) +#if IRSND_OCx == IRSND_OC0 +#define IRSND_PORT PORTB // port B +#define IRSND_DDR DDRB // ddr B +#define IRSND_BIT 0 // OC0 +#elif IRSND_OCx == IRSND_OC1A +#define IRSND_PORT PORTD // port D +#define IRSND_DDR DDRD // ddr D +#define IRSND_BIT 5 // OC1A +#elif IRSND_OCx == IRSND_OC1B +#define IRSND_PORT PORTE // port E +#define IRSND_DDR DDRE // ddr E +#define IRSND_BIT 2 // OC1E +#error Wrong value for IRSND_OCx, choose IRSND_OC0, IRSND_OC1A, or IRSND_OC1B in irsndconfig.h +#endif // IRSND_OCx #else #if !defined (unix) && !defined (WIN32) @@ -713,16 +729,18 @@ irsnd_send_data (IRMP_DATA * irmp_data_p, uint8_t do_wait) case IRMP_KASEIKYO_PROTOCOL: { uint8_t xor; + uint16_t genre2; address = bitsrevervse (irmp_data_p->address, KASEIKYO_ADDRESS_LEN); command = bitsrevervse (irmp_data_p->command, KASEIKYO_COMMAND_LEN + 4); + genre2 = bitsrevervse ((irmp_data_p->flags & ~IRSND_REPETITION_MASK) >> 4, 4); xor = ((address & 0x000F) ^ ((address & 0x00F0) >> 4) ^ ((address & 0x0F00) >> 8) ^ ((address & 0xF000) >> 12)) & 0x0F; irsnd_buffer[0] = (address & 0xFF00) >> 8; // AAAAAAAA irsnd_buffer[1] = (address & 0x00FF); // AAAAAAAA irsnd_buffer[2] = xor << 4 | (command & 0x000F); // XXXXCCCC - irsnd_buffer[3] = 0 | (command & 0xF000) >> 12; // 0000CCCC + irsnd_buffer[3] = (genre2 << 4) | (command & 0xF000) >> 12; // ggggCCCC irsnd_buffer[4] = (command & 0x0FF0) >> 4; // CCCCCCCC xor = irsnd_buffer[2] ^ irsnd_buffer[3] ^ irsnd_buffer[4]; @@ -962,6 +980,7 @@ irsnd_stop (void) uint8_t irsnd_ISR (void) { + static uint8_t send_trailer; static uint8_t current_bit = 0xFF; static uint8_t pulse_counter; static IRSND_PAUSE_LEN pause_counter; @@ -1061,6 +1080,12 @@ irsnd_ISR (void) } else { + if (send_trailer) + { + irsnd_busy = FALSE; + return irsnd_busy; + } + n_repeat_frames = irsnd_repeat; if (n_repeat_frames == IRSND_ENDLESS_REPETITION) @@ -1984,6 +2009,8 @@ irsnd_ISR (void) } else { + irsnd_busy = TRUE; + send_trailer = TRUE; n_repeat_frames = 0; repeat_counter = 0; } @@ -2016,7 +2043,6 @@ irsnd_ISR (void) int main (int argc, char ** argv) { - int idx; int protocol; int address; int command; @@ -2054,11 +2080,6 @@ main (int argc, char ** argv) irsnd_ISR (); } - for (idx = 0; idx < 20; idx++) - { - irsnd_ISR (); - } - putchar ('\n'); } else diff --git a/main.c b/main.c index 28bbe14..4e666da 100644 --- a/main.c +++ b/main.c @@ -3,7 +3,7 @@ * * Copyright (c) 2009-2011 Frank Meyer - frank(at)fli4l.de * - * $Id: main.c,v 1.11 2011/09/20 10:45:28 fm Exp $ + * $Id: main.c,v 1.12 2012/02/13 10:59:07 fm Exp $ * * ATMEGA88 @ 8 MHz * @@ -33,8 +33,15 @@ void timer1_init (void) { #if defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) // ATtiny45 / ATtiny85: + +#if F_CPU >= 16000000L + OCR1C = (F_CPU / F_INTERRUPTS / 8) - 1; // compare value: 1/15000 of CPU frequency, presc = 8 + TCCR1 = (1 << CTC1) | (1 << CS12); // switch CTC Mode on, set prescaler to 8 +#else OCR1C = (F_CPU / F_INTERRUPTS / 4) - 1; // compare value: 1/15000 of CPU frequency, presc = 4 TCCR1 = (1 << CTC1) | (1 << CS11) | (1 << CS10); // switch CTC Mode on, set prescaler to 4 +#endif + #else // ATmegaXX: OCR1A = (F_CPU / F_INTERRUPTS) - 1; // compare value: 1/15000 of CPU frequency TCCR1B = (1 << WGM12) | (1 << CS10); // switch CTC Mode on, set prescaler to 1 -- 2.39.2