/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
* irmp.c - infrared multi-protocol decoder, supports several remote control protocols\r
*\r
- * Copyright (c) 2009-2013 Frank Meyer - frank(at)fli4l.de\r
+ * Copyright (c) 2009-2014 Frank Meyer - frank(at)fli4l.de\r
*\r
- * $Id: irmp.c,v 1.154 2014/07/01 09:21:11 fm Exp $\r
+ * $Id: irmp.c,v 1.161 2014/07/21 08:58:58 fm Exp $\r
*\r
* ATMEGA88 @ 8 MHz\r
*\r
*---------------------------------------------------------------------------------------------------------------------------------------------------\r
*/\r
#if defined(UNIX_OR_WINDOWS) || IRMP_PROTOCOL_NAMES == 1\r
-char *\r
+const char *\r
irmp_protocol_names[IRMP_N_PROTOCOLS + 1] =\r
{\r
"UNKNOWN",\r
"RCMM12",\r
"SPEAKER",\r
"LGAIR",\r
+ "SAMSG48",\r
"RADIO1"\r
};\r
\r
*/\r
#if IRMP_LOGGING == 1 // logging via UART\r
\r
-#if IRMP_EXT_LOGGING == 1 // use external logging\r
-#include "irmpextlog.h"\r
-#else // normal UART log (IRMP_EXT_LOGGING == 0)\r
-#define BAUD 9600L\r
-#ifndef UNIX_OR_WINDOWS\r
-#include <util/setbaud.h>\r
-#endif\r
+#if defined(ARM_STM32F4XX)\r
+# define STM32_GPIO_CLOCK RCC_AHB1Periph_GPIOA // per UART2 an PA2\r
+# define STM32_UART_CLOCK RCC_APB1Periph_USART2\r
+# define STM32_GPIO_PORT GPIOA\r
+# define STM32_GPIO_PIN GPIO_Pin_2\r
+# define STM32_GPIO_SOURCE GPIO_PinSource2\r
+# define STM32_UART_AF GPIO_AF_USART2\r
+# define STM32_UART_COM USART2\r
+# define STM32_UART_BAUD 115200 // mit 115200 Baud\r
+# include "stm32f4xx_usart.h"\r
+#else\r
+# if IRMP_EXT_LOGGING == 1 // use external logging\r
+# include "irmpextlog.h"\r
+# else // normal UART log (IRMP_EXT_LOGGING == 0)\r
+# define BAUD 9600L\r
+# ifndef UNIX_OR_WINDOWS\r
+# include <util/setbaud.h>\r
+# endif\r
\r
#ifdef UBRR0H\r
\r
\r
#endif //UBRR0H\r
#endif //IRMP_EXT_LOGGING\r
+#endif //ARM_STM32F4XX\r
\r
/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
* Initialize UART\r
irmp_uart_init (void)\r
{\r
#ifndef UNIX_OR_WINDOWS\r
+#if defined(ARM_STM32F4XX)\r
+ GPIO_InitTypeDef GPIO_InitStructure;\r
+ USART_InitTypeDef USART_InitStructure;\r
+\r
+ // Clock enable vom TX Pin\r
+ RCC_AHB1PeriphClockCmd(STM32_GPIO_CLOCK, ENABLE);\r
+\r
+ // Clock enable der UART\r
+ RCC_APB1PeriphClockCmd(STM32_UART_CLOCK, ENABLE);\r
+\r
+ // UART Alternative-Funktion mit dem IO-Pin verbinden\r
+ GPIO_PinAFConfig(STM32_GPIO_PORT,STM32_GPIO_SOURCE,STM32_UART_AF);\r
+\r
+ // UART als Alternative-Funktion mit PushPull\r
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;\r
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;\r
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;\r
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;\r
+\r
+ // TX-Pin\r
+ GPIO_InitStructure.GPIO_Pin = STM32_GPIO_PIN;\r
+ GPIO_Init(STM32_GPIO_PORT, &GPIO_InitStructure);\r
+\r
+ // Oversampling\r
+ USART_OverSampling8Cmd(STM32_UART_COM, ENABLE);\r
+\r
+ // init mit Baudrate, 8Databits, 1Stopbit, keine Parität, kein RTS+CTS\r
+ USART_InitStructure.USART_BaudRate = STM32_UART_BAUD;\r
+ USART_InitStructure.USART_WordLength = USART_WordLength_8b;\r
+ USART_InitStructure.USART_StopBits = USART_StopBits_1;\r
+ USART_InitStructure.USART_Parity = USART_Parity_No;\r
+ USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;\r
+ USART_InitStructure.USART_Mode = USART_Mode_Tx;\r
+ USART_Init(STM32_UART_COM, &USART_InitStructure);\r
+\r
+ // UART enable\r
+ USART_Cmd(STM32_UART_COM, ENABLE);\r
+\r
+#else\r
#if (IRMP_EXT_LOGGING == 0) // use UART\r
UART0_UBRRH = UBRRH_VALUE; // set baud rate\r
UART0_UBRRL = UBRRL_VALUE;\r
UART0_UCSRC = UART0_UCSZ1_BIT_VALUE | UART0_UCSZ0_BIT_VALUE | UART0_URSEL_BIT_VALUE;\r
UART0_UCSRB |= UART0_TXEN_BIT_VALUE; // enable UART TX\r
#else // other log method\r
- initextlog(); \r
+ initextlog(); \r
#endif //IRMP_EXT_LOGGING\r
+#endif //ARM_STM32F4XX\r
#endif // UNIX_OR_WINDOWS\r
}\r
\r
irmp_uart_putc (unsigned char ch)\r
{\r
#ifndef UNIX_OR_WINDOWS\r
+#if defined(ARM_STM32F4XX)\r
+ // warten bis altes Byte gesendet wurde\r
+ while (USART_GetFlagStatus(STM32_UART_COM, USART_FLAG_TXE) == RESET)\r
+ {\r
+ ;\r
+ }\r
+\r
+ USART_SendData(STM32_UART_COM, ch);\r
+\r
+ if (ch == '\n')\r
+ {\r
+ while (USART_GetFlagStatus(STM32_UART_COM, USART_FLAG_TXE) == RESET);\r
+ USART_SendData(STM32_UART_COM, '\r');\r
+ }\r
+\r
+#else\r
#if (IRMP_EXT_LOGGING == 0)\r
+\r
while (!(UART0_UCSRA & UART0_UDRE_BIT_VALUE))\r
{\r
;\r
}\r
\r
UART0_UDR = ch;\r
+\r
#else\r
- sendextlog(ch); //Use external log\r
-#endif\r
+\r
+ sendextlog(ch); // use external log\r
+\r
+#endif //IRMP_EXT_LOGGING\r
+#endif //ARM_STM32F4XX\r
#else\r
fputc (ch, stderr);\r
#endif // UNIX_OR_WINDOWS\r
rtc = TRUE;\r
}\r
break;\r
+\r
+#if IRMP_SUPPORT_SAMSUNG48_PROTOCOL == 1\r
+ case IRMP_SAMSUNG48_PROTOCOL:\r
+ irmp_command = (irmp_command & 0x00FF) | ((irmp_id & 0x00FF) << 8);\r
+ rtc = TRUE;\r
+ break;\r
+#endif\r
#endif\r
+\r
#if IRMP_SUPPORT_NEC_PROTOCOL == 1\r
case IRMP_NEC_PROTOCOL:\r
if ((irmp_command >> 8) == (~irmp_command & 0x00FF))\r
static uint16_t irmp_tmp_address; // ir address\r
static uint16_t irmp_tmp_command; // ir command\r
\r
-#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) || IRMP_SUPPORT_NEC42_PROTOCOL == 1\r
+#if (IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)) || IRMP_SUPPORT_NEC42_PROTOCOL == 1\r
static uint16_t irmp_tmp_address2; // ir address\r
static uint16_t irmp_tmp_command2; // ir command\r
#endif\r
{\r
if (irmp_param.lsb_first)\r
{\r
- irmp_tmp_command |= (((uint16_t) (value)) << (irmp_bit - irmp_param.command_offset)); // CV wants cast\r
+#if IRMP_SUPPORT_SAMSUNG48_PROTOCOL == 1\r
+ if (irmp_param.protocol == IRMP_SAMSUNG48_PROTOCOL && irmp_bit >= 32)\r
+ {\r
+ irmp_tmp_id |= (((uint16_t) (value)) << (irmp_bit - 32)); // CV wants cast\r
+ }\r
+ else\r
+#endif\r
+ {\r
+ irmp_tmp_command |= (((uint16_t) (value)) << (irmp_bit - irmp_param.command_offset)); // CV wants cast\r
+ }\r
}\r
else\r
{\r
#if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1\r
genre2 = 0;\r
#endif\r
+#if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1\r
+ irmp_tmp_id = 0;\r
+#endif\r
\r
#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) || IRMP_SUPPORT_NEC42_PROTOCOL == 1\r
irmp_tmp_command2 = 0;\r
{\r
#ifdef ANALYZE\r
ANALYZE_PRINTF ("%8.3fms warning: did not receive inverted command repetition\n",\r
-#endif // ANALYZE\r
(double) (time_counter * 1000) / F_INTERRUPTS);\r
+#endif // ANALYZE\r
last_irmp_denon_command = 0;\r
denon_repetition_len = 0xFFFF;\r
}\r
}\r
#endif // IRMP_SUPPORT_JVC_PROTOCOL == 1\r
#endif // IRMP_SUPPORT_NEC42_PROTOCOL == 1\r
+\r
+#if IRMP_SUPPORT_SAMSUNG48_PROTOCOL == 1\r
+ else if (irmp_param.protocol == IRMP_SAMSUNG48_PROTOCOL && irmp_bit == 32) // it was a SAMSUNG32 stop bit\r
+ {\r
+#ifdef ANALYZE\r
+ ANALYZE_PRINTF ("Switching to SAMSUNG32 protocol\n");\r
+#endif // ANALYZE\r
+ irmp_param.protocol = IRMP_SAMSUNG32_PROTOCOL;\r
+ irmp_param.command_offset = SAMSUNG32_COMMAND_OFFSET;\r
+ irmp_param.command_end = SAMSUNG32_COMMAND_OFFSET + SAMSUNG32_COMMAND_LEN;\r
+ irmp_param.complete_len = SAMSUNG32_COMPLETE_DATA_LEN;\r
+ }\r
+#endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1\r
+\r
#if IRMP_SUPPORT_RCMM_PROTOCOL == 1\r
else if (irmp_param.protocol == IRMP_RCMM32_PROTOCOL && (irmp_bit == 12 || irmp_bit == 24)) // it was a RCMM stop bit\r
{\r
ANALYZE_PRINTF ("SYNC\n");\r
#endif // ANALYZE\r
wait_for_space = 0;\r
- irmp_tmp_id = 0;\r
irmp_bit++;\r
}\r
else if (irmp_pulse_time >= SAMSUNG_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_PULSE_LEN_MAX)\r
{\r
+#if IRMP_SUPPORT_SAMSUNG48_PROTOCOL == 1\r
+#ifdef ANALYZE\r
+ ANALYZE_PRINTF ("Switching to SAMSUNG48 protocol ");\r
+#endif // ANALYZE\r
+ irmp_param.protocol = IRMP_SAMSUNG48_PROTOCOL;\r
+ irmp_param.command_offset = SAMSUNG48_COMMAND_OFFSET;\r
+ irmp_param.command_end = SAMSUNG48_COMMAND_OFFSET + SAMSUNG48_COMMAND_LEN;\r
+ irmp_param.complete_len = SAMSUNG48_COMPLETE_DATA_LEN;\r
+#else\r
+#ifdef ANALYZE\r
+ ANALYZE_PRINTF ("Switching to SAMSUNG32 protocol ");\r
+#endif // ANALYZE\r
irmp_param.protocol = IRMP_SAMSUNG32_PROTOCOL;\r
irmp_param.command_offset = SAMSUNG32_COMMAND_OFFSET;\r
irmp_param.command_end = SAMSUNG32_COMMAND_OFFSET + SAMSUNG32_COMMAND_LEN;\r
irmp_param.complete_len = SAMSUNG32_COMPLETE_DATA_LEN;\r
-\r
+#endif\r
if (irmp_pause_time >= SAMSUNG_1_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_1_PAUSE_LEN_MAX)\r
{\r
#ifdef ANALYZE\r
irmp_store_bit (0);\r
wait_for_space = 0;\r
}\r
-\r
-#ifdef ANALYZE\r
- ANALYZE_PRINTF ("Switching to SAMSUNG32 protocol\n");\r
-#endif // ANALYZE\r
}\r
else\r
{ // timing incorrect!\r
#endif\r
\r
#if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1\r
- // if SAMSUNG32 protocol and the code will be repeated within 50 ms, we will ignore every 2nd frame\r
- if (irmp_param.protocol == IRMP_SAMSUNG32_PROTOCOL && (repetition_frame_number & 0x01))\r
+ // if SAMSUNG32 or SAMSUNG48 protocol and the code will be repeated within 50 ms, we will ignore every 2nd frame\r
+ if ((irmp_param.protocol == IRMP_SAMSUNG32_PROTOCOL || irmp_param.protocol == IRMP_SAMSUNG48_PROTOCOL) && (repetition_frame_number & 0x01))\r
{\r
#ifdef ANALYZE\r
- ANALYZE_PRINTF ("code skipped: SAMSUNG32 auto repetition frame #%d, counter = %d, auto repetition len = %d\n",\r
+ ANALYZE_PRINTF ("code skipped: SAMSUNG32/SAMSUNG48 auto repetition frame #%d, counter = %d, auto repetition len = %d\n",\r
repetition_frame_number + 1, key_repetition_len, AUTO_FRAME_REPETITION_LEN);\r
#endif // ANALYZE\r
key_repetition_len = 0;\r