/*---------------------------------------------------------------------------------------------------------------------------------------------------\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
* ATmega164, ATmega324, ATmega644, ATmega644P, ATmega1284, ATmega1284P\r
* ATmega88, ATmega88P, ATmega168, ATmega168P, ATmega328P\r
*\r
- * $Id: irsnd.c,v 1.77 2014/07/09 14:45:56 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
#define SAMSUNG32_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SAMSUNG32_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!\r
#define SAMSUNG32_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SAMSUNG32_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!\r
\r
+#define SAMSUNG48_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SAMSUNG48_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!\r
+#define SAMSUNG48_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SAMSUNG48_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!\r
+\r
#define MATSUSHITA_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME + 0.5)\r
#define MATSUSHITA_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME + 0.5)\r
#define MATSUSHITA_PULSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME + 0.5)\r
* @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
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
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
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
break;\r
}\r
#endif\r
+#if IRSND_SUPPORT_SAMSUNG48_PROTOCOL == 1\r
+ case IRMP_SAMSUNG48_PROTOCOL:\r
+ {\r
+ address = bitsrevervse (irmp_data_p->address, SAMSUNG_ADDRESS_LEN);\r
+ command = bitsrevervse (irmp_data_p->command, 16);\r
+\r
+ irsnd_buffer[0] = (address & 0xFF00) >> 8; // AAAAAAAA\r
+ irsnd_buffer[1] = (address & 0x00FF); // AAAAAAAA\r
+ irsnd_buffer[2] = ((command & 0xFF00) >> 8); // CCCCCCCC\r
+ irsnd_buffer[3] = ~((command & 0xFF00) >> 8); // cccccccc\r
+ irsnd_buffer[4] = (command & 0x00FF); // CCCCCCCC\r
+ irsnd_buffer[5] = ~(command & 0x00FF); // cccccccc\r
+ irsnd_busy = TRUE;\r
+ break;\r
+ }\r
+#endif\r
#if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1\r
case IRMP_MATSUSHITA_PROTOCOL:\r
{\r
break;\r
}\r
#endif\r
+#if IRSND_SUPPORT_SAMSUNG48_PROTOCOL == 1\r
+ case IRMP_SAMSUNG48_PROTOCOL:\r
+ {\r
+ startbit_pulse_len = SAMSUNG_START_BIT_PULSE_LEN;\r
+ startbit_pause_len = SAMSUNG_START_BIT_PAUSE_LEN - 1;\r
+ pulse_1_len = SAMSUNG_PULSE_LEN;\r
+ pause_1_len = SAMSUNG_1_PAUSE_LEN - 1;\r
+ pulse_0_len = SAMSUNG_PULSE_LEN;\r
+ pause_0_len = SAMSUNG_0_PAUSE_LEN - 1;\r
+ has_stop_bit = SAMSUNG_STOP_BIT;\r
+ complete_data_len = SAMSUNG48_COMPLETE_DATA_LEN;\r
+ n_auto_repetitions = SAMSUNG48_FRAMES; // 1 frame\r
+ auto_repetition_pause_len = SAMSUNG48_AUTO_REPETITION_PAUSE_LEN; // 47 ms pause\r
+ repeat_frame_pause_len = SAMSUNG48_FRAME_REPEAT_PAUSE_LEN;\r
+ irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
+ break;\r
+ }\r
+#endif\r
#if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1\r
case IRMP_MATSUSHITA_PROTOCOL:\r
{\r
case IRMP_SAMSUNG_PROTOCOL:\r
case IRMP_SAMSUNG32_PROTOCOL:\r
#endif\r
+#if IRSND_SUPPORT_SAMSUNG48_PROTOCOL == 1\r
+ case IRMP_SAMSUNG48_PROTOCOL:\r
+#endif\r
#if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1\r
case IRMP_MATSUSHITA_PROTOCOL:\r
#endif\r
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
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
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
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
}\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
}\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
{\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
}\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