]> cloudbase.mooo.com Git - irmp.git/blobdiff - irmp.c
libopencm3: Set PWM duty cycle to 33%. Improve timer handling.
[irmp.git] / irmp.c
diff --git a/irmp.c b/irmp.c
index 6297aa5905cb6f83653d2d351547e353dd9d61d0..c37449cd8564a9e93d52083e5c24888fc29876d8 100644 (file)
--- a/irmp.c
+++ b/irmp.c
@@ -3,7 +3,7 @@
  *\r
  * Copyright (c) 2009-2016 Frank Meyer - frank(at)fli4l.de\r
  *\r
- * $Id: irmp.c,v 1.188 2016/09/14 06:31:48 fm Exp $\r
+ * $Id: irmp.c,v 1.192 2017/02/17 09:13:06 fm Exp $\r
  *\r
  * Supported AVR mikrocontrollers:\r
  *\r
 #define SAMSUNG_0_PAUSE_LEN_MIN                 ((uint_fast8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)\r
 #define SAMSUNG_0_PAUSE_LEN_MAX                 ((uint_fast8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)\r
 \r
+#define SAMSUNGAH_START_BIT_PULSE_LEN_MIN       ((uint_fast8_t)(F_INTERRUPTS * SAMSUNGAH_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)\r
+#define SAMSUNGAH_START_BIT_PULSE_LEN_MAX       ((uint_fast8_t)(F_INTERRUPTS * SAMSUNGAH_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)\r
+#define SAMSUNGAH_START_BIT_PAUSE_LEN_MIN       ((uint_fast8_t)(F_INTERRUPTS * SAMSUNGAH_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)\r
+#define SAMSUNGAH_START_BIT_PAUSE_LEN_MAX       ((uint_fast8_t)(F_INTERRUPTS * SAMSUNGAH_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)\r
+#define SAMSUNGAH_PULSE_LEN_MIN                 ((uint_fast8_t)(F_INTERRUPTS * SAMSUNGAH_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)\r
+#define SAMSUNGAH_PULSE_LEN_MAX                 ((uint_fast8_t)(F_INTERRUPTS * SAMSUNGAH_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)\r
+#define SAMSUNGAH_1_PAUSE_LEN_MIN               ((uint_fast8_t)(F_INTERRUPTS * SAMSUNGAH_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)\r
+#define SAMSUNGAH_1_PAUSE_LEN_MAX               ((uint_fast8_t)(F_INTERRUPTS * SAMSUNGAH_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)\r
+#define SAMSUNGAH_0_PAUSE_LEN_MIN               ((uint_fast8_t)(F_INTERRUPTS * SAMSUNGAH_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)\r
+#define SAMSUNGAH_0_PAUSE_LEN_MAX               ((uint_fast8_t)(F_INTERRUPTS * SAMSUNGAH_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)\r
+\r
 #define MATSUSHITA_START_BIT_PULSE_LEN_MIN      ((uint_fast8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)\r
 #define MATSUSHITA_START_BIT_PULSE_LEN_MAX      ((uint_fast8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)\r
 #define MATSUSHITA_START_BIT_PAUSE_LEN_MIN      ((uint_fast8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)\r
@@ -647,6 +658,7 @@ static const char proto_technics[]      PROGMEM = "TECHNICS";
 static const char proto_panasonic[]     PROGMEM = "PANASONIC";\r
 static const char proto_mitsu_heavy[]   PROGMEM = "MITSU_HEAVY";\r
 static const char proto_vincent[]       PROGMEM = "VINCENT";\r
+static const char proto_samsungah[]     PROGMEM = "SAMSUNGAH";\r
 \r
 static const char proto_radio1[]        PROGMEM = "RADIO1";\r
 \r
@@ -704,6 +716,7 @@ irmp_protocol_names[IRMP_N_PROTOCOLS + 1] PROGMEM =
     proto_panasonic,\r
     proto_mitsu_heavy,\r
     proto_vincent,\r
+    proto_samsungah,\r
     proto_radio1\r
 };\r
 \r
@@ -863,7 +876,7 @@ irmp_uart_init (void)
 \r
     // UART enable\r
     USART_Cmd(STM32_UART_COM, ENABLE);\r
-        \r
+\r
 #elif defined(ARDUINO)\r
     // we use the Arduino Serial Imlementation\r
     // you have to call Serial.begin(SER_BAUD); in Arduino setup() function\r
@@ -932,25 +945,31 @@ irmp_uart_putc (unsigned char ch)
 \r
 #else\r
 #if (IRMP_EXT_LOGGING == 0)\r
-        \r
-        #       if defined (__AVR_XMEGA__)\r
-        while (!(USARTC1.STATUS & USART_DREIF_bm));\r
-        USARTC1.DATA = ch;\r
-        \r
-        #       else //AVR_MEGA\r
+\r
+#  if defined (__AVR_XMEGA__)\r
+    while (!(USARTC1.STATUS & USART_DREIF_bm))\r
+    {\r
+        ;\r
+    }\r
+\r
+    USARTC1.DATA = ch;\r
+\r
+#  else // AVR_MEGA\r
     while (!(UART0_UCSRA & UART0_UDRE_BIT_VALUE))\r
     {\r
         ;\r
     }\r
 \r
     UART0_UDR = ch;\r
-        #endif //__AVR_XMEGA__\r
+\r
+#  endif // __AVR_XMEGA__\r
+\r
 #else\r
 \r
     sendextlog(ch);                                                         // use external log\r
 \r
-#endif //IRMP_EXT_LOGGING\r
-#endif //ARM_STM32F4XX\r
+#endif // IRMP_EXT_LOGGING\r
+#endif // ARM_STM32F4XX\r
 #else\r
     fputc (ch, stderr);\r
 #endif // UNIX_OR_WINDOWS\r
@@ -1224,6 +1243,31 @@ static const PROGMEM IRMP_PARAMETER samsung_param =
 \r
 #endif\r
 \r
+#if IRMP_SUPPORT_SAMSUNGAH_PROTOCOL == 1\r
+\r
+static const PROGMEM IRMP_PARAMETER samsungah_param =\r
+{\r
+    IRMP_SAMSUNGAH_PROTOCOL,                                            // protocol:        ir protocol\r
+    SAMSUNGAH_PULSE_LEN_MIN,                                            // pulse_1_len_min: minimum length of pulse with bit value 1\r
+    SAMSUNGAH_PULSE_LEN_MAX,                                            // pulse_1_len_max: maximum length of pulse with bit value 1\r
+    SAMSUNGAH_1_PAUSE_LEN_MIN,                                          // pause_1_len_min: minimum length of pause with bit value 1\r
+    SAMSUNGAH_1_PAUSE_LEN_MAX,                                          // pause_1_len_max: maximum length of pause with bit value 1\r
+    SAMSUNGAH_PULSE_LEN_MIN,                                            // pulse_0_len_min: minimum length of pulse with bit value 0\r
+    SAMSUNGAH_PULSE_LEN_MAX,                                            // pulse_0_len_max: maximum length of pulse with bit value 0\r
+    SAMSUNGAH_0_PAUSE_LEN_MIN,                                          // pause_0_len_min: minimum length of pause with bit value 0\r
+    SAMSUNGAH_0_PAUSE_LEN_MAX,                                          // pause_0_len_max: maximum length of pause with bit value 0\r
+    SAMSUNGAH_ADDRESS_OFFSET,                                           // address_offset:  address offset\r
+    SAMSUNGAH_ADDRESS_OFFSET + SAMSUNGAH_ADDRESS_LEN,                   // address_end:     end of address\r
+    SAMSUNGAH_COMMAND_OFFSET,                                           // command_offset:  command offset\r
+    SAMSUNGAH_COMMAND_OFFSET + SAMSUNGAH_COMMAND_LEN,                   // command_end:     end of command\r
+    SAMSUNGAH_COMPLETE_DATA_LEN,                                        // complete_len:    complete length of frame\r
+    SAMSUNGAH_STOP_BIT,                                                 // stop_bit:        flag: frame has stop bit\r
+    SAMSUNGAH_LSB,                                                      // lsb_first:       flag: LSB first\r
+    SAMSUNGAH_FLAGS                                                     // flags:           some flags\r
+};\r
+\r
+#endif\r
+\r
 #if IRMP_SUPPORT_TELEFUNKEN_PROTOCOL == 1\r
 \r
 static const PROGMEM IRMP_PARAMETER telefunken_param =\r
@@ -2145,6 +2189,13 @@ irmp_init (void)
 #  endif\r
     GPIO_Init(IRMP_PORT, &GPIO_InitStructure);\r
 \r
+#elif defined (LIBOPENCM3)                                             // STM32 with libopencm3\r
+\r
+    /* GPIOx clock enable */\r
+    rcc_periph_clock_enable(IRMP_PORT_RCC);\r
+    /* GPIO Configuration */\r
+    gpio_set_mode(IRMP_PORT, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, IRMP_BIT);\r
+\r
 #elif defined(STELLARIS_ARM_CORTEX_M4)\r
     // Enable the GPIO port\r
     ROM_SysCtlPeripheralEnable(IRMP_PORT_PERIPH);\r
@@ -2161,6 +2212,7 @@ irmp_init (void)
     pinMode(IRMP_PIN, INPUT);\r
 \r
 #elif defined(__xtensa__)                                               // ESP8266\r
+    pinMode(IRMP_BIT_NUMBER, INPUT);\r
                                                                         // select pin function\r
 #  if (IRMP_BIT_NUMBER == 12)\r
     PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12);\r
@@ -3060,6 +3112,20 @@ irmp_ISR (void)
                     else\r
 #endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1\r
 \r
+#if IRMP_SUPPORT_SAMSUNGAH_PROTOCOL == 1\r
+                    if (irmp_pulse_time >= SAMSUNGAH_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNGAH_START_BIT_PULSE_LEN_MAX &&\r
+                        irmp_pause_time >= SAMSUNGAH_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNGAH_START_BIT_PAUSE_LEN_MAX)\r
+                    {                                                           // it's SAMSUNGAH\r
+#ifdef ANALYZE\r
+                        ANALYZE_PRINTF ("protocol = SAMSUNGAH, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",\r
+                                        SAMSUNGAH_START_BIT_PULSE_LEN_MIN, SAMSUNGAH_START_BIT_PULSE_LEN_MAX,\r
+                                        SAMSUNGAH_START_BIT_PAUSE_LEN_MIN, SAMSUNGAH_START_BIT_PAUSE_LEN_MAX);\r
+#endif // ANALYZE\r
+                        irmp_param_p = (IRMP_PARAMETER *) &samsungah_param;\r
+                    }\r
+                    else\r
+#endif // IRMP_SUPPORT_SAMSUNGAH_PROTOCOL == 1\r
+\r
 #if IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1\r
                     if (irmp_pulse_time >= MATSUSHITA_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= MATSUSHITA_START_BIT_PULSE_LEN_MAX &&\r
                         irmp_pause_time >= MATSUSHITA_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= MATSUSHITA_START_BIT_PAUSE_LEN_MAX)\r
@@ -3944,6 +4010,32 @@ irmp_ISR (void)
                             {\r
                                 irmp_bit++;\r
                             }\r
+#if IRMP_SUPPORT_NEC_PROTOCOL == 1\r
+                            else if ((irmp_param.protocol == IRMP_NEC_PROTOCOL || irmp_param.protocol == IRMP_NEC42_PROTOCOL) && irmp_bit == 0)\r
+                            {                                                               // it was a non-standard repetition frame\r
+#ifdef ANALYZE                                                                              // with 4500µs pause instead of 2250µs\r
+                                ANALYZE_PRINTF ("Detected non-standard repetition frame, switching to NEC repetition\n");\r
+#endif // ANALYZE\r
+                                if (key_repetition_len < NEC_FRAME_REPEAT_PAUSE_LEN_MAX)\r
+                                {\r
+                                    irmp_param.stop_bit     = TRUE;                         // set flag\r
+                                    irmp_param.protocol     = IRMP_NEC_PROTOCOL;            // switch protocol\r
+                                    irmp_param.complete_len = irmp_bit;                     // patch length: 16 or 17\r
+                                    irmp_tmp_address = last_irmp_address;                   // address is last address\r
+                                    irmp_tmp_command = last_irmp_command;                   // command is last command\r
+                                    irmp_flags |= IRMP_FLAG_REPETITION;\r
+                                    key_repetition_len = 0;\r
+                                }\r
+                                else\r
+                                {\r
+#ifdef ANALYZE\r
+                                    ANALYZE_PRINTF ("ignoring NEC repetition frame: timeout occured, key_repetition_len = %d > %d\n",\r
+                                                    key_repetition_len, NEC_FRAME_REPEAT_PAUSE_LEN_MAX);\r
+#endif // ANALYZE\r
+                                    irmp_ir_detected = FALSE;\r
+                                }\r
+                            }\r
+#endif // IRMP_SUPPORT_NEC_PROTOCOL == 1\r
 #if IRMP_SUPPORT_JVC_PROTOCOL == 1\r
                             else if (irmp_param.protocol == IRMP_NEC_PROTOCOL && (irmp_bit == 16 || irmp_bit == 17))      // it was a JVC stop bit\r
                             {\r