X-Git-Url: http://cloudbase.mooo.com/gitweb/irmp.git/blobdiff_plain/3a7e26e1f87a0e738f763d2df005d5da1690696d..a03ad359eac6c94c5a136e48c66b435544def63c:/irsnd.c diff --git a/irsnd.c b/irsnd.c index caac904..ad14dd8 100644 --- a/irsnd.c +++ b/irsnd.c @@ -13,7 +13,7 @@ * ATmega164, ATmega324, ATmega644, ATmega644P, ATmega1284 * ATmega88, ATmega88P, ATmega168, ATmega168P, ATmega328P * - * $Id: irsnd.c,v 1.59 2012/06/18 09:00:46 fm Exp $ + * $Id: irsnd.c,v 1.60 2012/10/05 07:58:39 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 @@ -24,6 +24,10 @@ #include "irsnd.h" +#ifndef F_CPU +# error F_CPU unkown +#endif + /*--------------------------------------------------------------------------------------------------------------------------------------------------- * ATtiny pin definition of OC0A / OC0B * ATmega pin definition of OC2 / OC2A / OC2B / OC0 / OC0A / OC0B @@ -306,14 +310,19 @@ # define IRSND_FREQ_56_KHZ (IRSND_FREQ_TYPE) (56000) # define IRSND_FREQ_455_KHZ (IRSND_FREQ_TYPE) (455000) #else // AVR +# if F_CPU >= 16000000L +# define AVR_PRESCALER 8 +# else +# define AVR_PRESCALER 1 +# endif # define IRSND_FREQ_TYPE uint8_t -# define IRSND_FREQ_30_KHZ (IRSND_FREQ_TYPE) ((F_CPU / 30000 / 2) - 1) -# define IRSND_FREQ_32_KHZ (IRSND_FREQ_TYPE) ((F_CPU / 32000 / 2) - 1) -# define IRSND_FREQ_36_KHZ (IRSND_FREQ_TYPE) ((F_CPU / 36000 / 2) - 1) -# define IRSND_FREQ_38_KHZ (IRSND_FREQ_TYPE) ((F_CPU / 38000 / 2) - 1) -# define IRSND_FREQ_40_KHZ (IRSND_FREQ_TYPE) ((F_CPU / 40000 / 2) - 1) -# define IRSND_FREQ_56_KHZ (IRSND_FREQ_TYPE) ((F_CPU / 56000 / 2) - 1) -# define IRSND_FREQ_455_KHZ (IRSND_FREQ_TYPE) ((F_CPU / 455000 / 2) - 1) +# define IRSND_FREQ_30_KHZ (IRSND_FREQ_TYPE) ((F_CPU / 30000 / AVR_PRESCALER / 2) - 1) +# define IRSND_FREQ_32_KHZ (IRSND_FREQ_TYPE) ((F_CPU / 32000 / AVR_PRESCALER / 2) - 1) +# define IRSND_FREQ_36_KHZ (IRSND_FREQ_TYPE) ((F_CPU / 36000 / AVR_PRESCALER / 2) - 1) +# define IRSND_FREQ_38_KHZ (IRSND_FREQ_TYPE) ((F_CPU / 38000 / AVR_PRESCALER / 2) - 1) +# define IRSND_FREQ_40_KHZ (IRSND_FREQ_TYPE) ((F_CPU / 40000 / AVR_PRESCALER / 2) - 1) +# define IRSND_FREQ_56_KHZ (IRSND_FREQ_TYPE) ((F_CPU / 56000 / AVR_PRESCALER / 2) - 1) +# define IRSND_FREQ_455_KHZ (IRSND_FREQ_TYPE) ((F_CPU / 455000 / AVR_PRESCALER / 2) - 1) #endif #define FDC_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME + 0.5) @@ -366,7 +375,6 @@ static void (*irsnd_callback_ptr) (uint8_t); /*--------------------------------------------------------------------------------------------------------------------------------------------------- * Switch PWM on - * @details Switches PWM on with a narrow spike on all 3 channels -> leds glowing *--------------------------------------------------------------------------------------------------------------------------------------------------- */ static void @@ -605,16 +613,32 @@ irsnd_init (void) # if IRSND_OCx == IRSND_OC2 // use OC2 TCCR2 = (1<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; + xor_value = ((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[2] = xor_value << 4 | (command & 0x000F); // XXXXCCCC 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]; + xor_value = irsnd_buffer[2] ^ irsnd_buffer[3] ^ irsnd_buffer[4]; - irsnd_buffer[5] = xor; + irsnd_buffer[5] = xor_value; irsnd_busy = TRUE; break; } @@ -2145,6 +2169,8 @@ irsnd_ISR (void) } else { + // printf ("current_bit: %d %d < %d %d < %d\n", current_bit, pause_counter, pause_len, pulse_counter, pulse_len); + if (pause_counter < pause_len) { if (pause_counter == 0) @@ -2263,6 +2289,15 @@ main (int argc, char ** argv) } putchar ('\n'); + + (void) irsnd_send_data (&irmp_data, TRUE); + + while (irsnd_busy) + { + irsnd_ISR (); + } + + putchar ('\n'); } else {