]> cloudbase.mooo.com Git - irmp.git/blobdiff - irsnd.c
Version 2.6.7: corrected minor bug: missing newline before #else
[irmp.git] / irsnd.c
diff --git a/irsnd.c b/irsnd.c
index 2ba1e288ebd5b08e15dafe220f6d1abccba106f9..00f80e3625ced58639f4d50d5ce3f86b9354e5b5 100644 (file)
--- a/irsnd.c
+++ b/irsnd.c
@@ -1,9 +1,9 @@
 /*---------------------------------------------------------------------------------------------------------------------------------------------------\r
  * @file irsnd.c\r
  *\r
- * Copyright (c) 2010-2013 Frank Meyer - frank(at)fli4l.de\r
+ * Copyright (c) 2010-2014 Frank Meyer - frank(at)fli4l.de\r
  *\r
- * Supported mikrocontrollers:\r
+ * Supported AVR mikrocontrollers:\r
  *\r
  * ATtiny87,  ATtiny167\r
  * ATtiny45,  ATtiny85\r
@@ -13,7 +13,7 @@
  * ATmega164, ATmega324, ATmega644,  ATmega644P, ATmega1284, ATmega1284P\r
  * ATmega88,  ATmega88P, ATmega168,  ATmega168P, ATmega328P\r
  *\r
- * $Id: irsnd.c,v 1.78 2014/07/10 09:48:23 fm Exp $\r
+ * $Id: irsnd.c,v 1.82 2014/09/15 10:27:38 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
@@ -505,14 +505,34 @@ irsnd_off (void)
  *  @details  sets pwm frequency\r
  *---------------------------------------------------------------------------------------------------------------------------------------------------\r
  */\r
+#if defined(__12F1840)\r
+extern void pwm_init(uint16_t freq);\r
+#include <stdio.h>\r
+#endif\r
+\r
 static void\r
 irsnd_set_freq (IRSND_FREQ_TYPE freq)\r
 {\r
 #ifndef ANALYZE\r
-#  if defined(PIC_C18)                                                                      // PIC C18\r
-         OpenPWM(freq); \r
-         SetDCPWM( (uint16_t) (freq * 2) + 1); // freq*2 = Duty cycles 50%\r
-         PWMoff();\r
+#  if defined(PIC_C18)                                                                      // PIC C18 or XC8\r
+#    if defined(__12F1840)                                                                  // XC8\r
+        TRISA2=0; \r
+        PR2=freq;\r
+        CCP1M0=1;\r
+        CCP1M1=1;\r
+        CCP1M2=1;\r
+        CCP1M3=1;\r
+        DC1B0=1;\r
+        DC1B1=0;\r
+        CCPR1L = 0b01101001;\r
+        TMR2IF = 0;\r
+        TMR2ON=1;\r
+        CCP1CON &=(~0b0011); // p 197 "active high"\r
+#    else                                                                                   // PIC C18\r
+        OpenPWM(freq); \r
+        SetDCPWM( (uint16_t) (freq * 2) + 1); // freq*2 = Duty cycles 50%\r
+#    endif\r
+        PWMoff();\r
 #  elif defined (ARM_STM32)                                                                 // STM32\r
          static uint32_t      TimeBaseFreq = 0;\r
 \r
@@ -578,8 +598,10 @@ void
 irsnd_init (void)\r
 {\r
 #ifndef ANALYZE\r
-#  if defined(PIC_C18)                                                      // PIC C18\r
+#  if defined(PIC_C18)                                                      // PIC C18 or XC8 compiler\r
+#    if ! defined(__12F1840)                                                // only C18:\r
         OpenTimer;\r
+#    endif\r
         irsnd_set_freq (IRSND_FREQ_36_KHZ);                                 // default frequency\r
         IRSND_PIN = 0;                                                      // set IO to outout\r
         PWMoff();\r
@@ -593,6 +615,7 @@ irsnd_init (void)
         RCC_AHBPeriphClockCmd(IRSND_PORT_RCC, ENABLE);\r
 #    elif defined (ARM_STM32F10X)\r
         RCC_APB2PeriphClockCmd(IRSND_PORT_RCC, ENABLE);\r
+        // RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); // only in case of remapping, not necessary for default port-timer mapping\r
 #    elif defined (ARM_STM32F4XX)\r
         RCC_AHB1PeriphClockCmd(IRSND_PORT_RCC, ENABLE);\r
 #    endif\r
@@ -610,7 +633,7 @@ irsnd_init (void)
         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;\r
         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;\r
         GPIO_Init(IRSND_PORT, &GPIO_InitStructure);\r
-        GPIO_PinRemapConfig(, ENABLE);         // TODO: remapping required\r
+        // GPIO_PinRemapConfig(GPIO_*Remap*_TIM[IRSND_TIMER_NUMBER], ENABLE); // only in case of remapping, not necessary for default port-timer mapping\r
 #    endif\r
 \r
         /* TIMx clock enable */\r
@@ -2094,7 +2117,7 @@ irsnd_ISR (void)
                                 if (current_bit < SAMSUNG_ADDRESS_LEN)                              // send address bits\r
                                 {\r
                                     pulse_len = SAMSUNG_PULSE_LEN;\r
-                                    pause_len = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ?\r
+                                    pause_len = (irsnd_buffer[current_bit >> 3] & (1<<(7-(current_bit & 7)))) ?\r
                                                     (SAMSUNG_1_PAUSE_LEN - 1) : (SAMSUNG_0_PAUSE_LEN - 1);\r
                                 }\r
                                 else if (current_bit == SAMSUNG_ADDRESS_LEN)                        // send SYNC bit (16th bit)\r
@@ -2107,7 +2130,7 @@ irsnd_ISR (void)
                                     uint8_t cur_bit = current_bit - 1;                              // sync skipped, offset = -1 !\r
 \r
                                     pulse_len = SAMSUNG_PULSE_LEN;\r
-                                    pause_len = (irsnd_buffer[cur_bit / 8] & (1<<(7-(cur_bit % 8)))) ?\r
+                                    pause_len = (irsnd_buffer[cur_bit >> 3] & (1<<(7-(cur_bit & 7)))) ?\r
                                                     (SAMSUNG_1_PAUSE_LEN - 1) : (SAMSUNG_0_PAUSE_LEN - 1);\r
                                 }\r
                             }\r
@@ -2120,7 +2143,7 @@ irsnd_ISR (void)
                                 if (current_bit < NEC16_ADDRESS_LEN)                                // send address bits\r
                                 {\r
                                     pulse_len = NEC_PULSE_LEN;\r
-                                    pause_len = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ?\r
+                                    pause_len = (irsnd_buffer[current_bit >> 3] & (1<<(7-(current_bit & 7)))) ?\r
                                                     (NEC_1_PAUSE_LEN - 1) : (NEC_0_PAUSE_LEN - 1);\r
                                 }\r
                                 else if (current_bit == NEC16_ADDRESS_LEN)                          // send SYNC bit (8th bit)\r
@@ -2133,7 +2156,7 @@ irsnd_ISR (void)
                                     uint8_t cur_bit = current_bit - 1;                              // sync skipped, offset = -1 !\r
 \r
                                     pulse_len = NEC_PULSE_LEN;\r
-                                    pause_len = (irsnd_buffer[cur_bit / 8] & (1<<(7-(cur_bit % 8)))) ?\r
+                                    pause_len = (irsnd_buffer[cur_bit >> 3] & (1<<(7-(cur_bit & 7)))) ?\r
                                                     (NEC_1_PAUSE_LEN - 1) : (NEC_0_PAUSE_LEN - 1);\r
                                 }\r
                             }\r
@@ -2165,7 +2188,7 @@ irsnd_ISR (void)
                                 }\r
                                 else if (current_bit < BANG_OLUFSEN_COMPLETE_DATA_LEN)              // send n'th bit\r
                                 {\r
-                                    uint8_t cur_bit_value = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ? 1 : 0;\r
+                                    uint8_t cur_bit_value = (irsnd_buffer[current_bit >> 3] & (1<<(7-(current_bit & 7)))) ? 1 : 0;\r
                                     pulse_len = BANG_OLUFSEN_PULSE_LEN;\r
 \r
                                     if (cur_bit_value == last_bit_value)\r
@@ -2181,7 +2204,7 @@ irsnd_ISR (void)
                             }\r
                             else\r
 #endif\r
-                            if (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8))))\r
+                            if (irsnd_buffer[current_bit >> 3] & (1<<(7-(current_bit & 7))))\r
                             {\r
                                 pulse_len = pulse_1_len;\r
                                 pause_len = pause_1_len;\r
@@ -2348,7 +2371,7 @@ irsnd_ISR (void)
                             {\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
+                                first_pulse = (irsnd_buffer[current_bit >> 3] & (1<<(7-(current_bit & 7)))) ? TRUE : FALSE;\r
                             }\r
                         }\r
                         else // if (irsnd_protocol == IRMP_RC5_PROTOCOL || irsnd_protocol == IRMP_RC6_PROTOCOL || irsnd_protocol == IRMP_RC6A_PROTOCOL ||\r
@@ -2408,7 +2431,7 @@ irsnd_ISR (void)
                                     }\r
                                 }\r
 #endif\r
-                                first_pulse = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ? TRUE : FALSE;\r
+                                first_pulse = (irsnd_buffer[current_bit >> 3] & (1<<(7-(current_bit & 7)))) ? TRUE : FALSE;\r
                             }\r
 \r
                             if (irsnd_protocol == IRMP_RC5_PROTOCOL)\r