Преглед изворни кода

Made a mostly-working remote control translator

It looks for the signal sent by the MINIX remote's power button and
sends the one sent by the GO.VIDEO remote's power button.  It has a few
reliability problems and the code's a bit of a mess, so there's still
work to do.
Clara Hobbs пре 7 година
родитељ
комит
6361231abb
3 измењених фајлова са 114 додато и 6 уклоњено
  1. 1
    1
      halconf.h
  2. 1
    1
      mcuconf.h
  3. 112
    4
      src/main.c

+ 1
- 1
halconf.h Прегледај датотеку

@@ -90,7 +90,7 @@
90 90
  * @brief   Enables the ICU subsystem.
91 91
  */
92 92
 #if !defined(HAL_USE_ICU) || defined(__DOXYGEN__)
93
-#define HAL_USE_ICU                 FALSE
93
+#define HAL_USE_ICU                 TRUE
94 94
 #endif
95 95
 
96 96
 /**

+ 1
- 1
mcuconf.h Прегледај датотеку

@@ -117,7 +117,7 @@
117 117
  */
118 118
 #define STM32_ICU_USE_TIM1                  FALSE
119 119
 #define STM32_ICU_USE_TIM2                  FALSE
120
-#define STM32_ICU_USE_TIM3                  FALSE
120
+#define STM32_ICU_USE_TIM3                  TRUE
121 121
 #define STM32_ICU_USE_TIM4                  FALSE
122 122
 #define STM32_ICU_USE_TIM5                  FALSE
123 123
 #define STM32_ICU_USE_TIM8                  FALSE

+ 112
- 4
src/main.c Прегледај датотеку

@@ -16,6 +16,8 @@
16 16
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 17
  */
18 18
 
19
+/* Portions subject to the following copyright notices */
20
+
19 21
 /*
20 22
     ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
21 23
 
@@ -32,11 +34,43 @@
32 34
     limitations under the License.
33 35
 */
34 36
 
37
+/*
38
+  PLAY Embedded demos - Copyright (C) 2014-2017 Rocco Marco Guglielmi
39
+
40
+  This file is part of PLAY Embedded demos.
41
+
42
+  Licensed under the Apache License, Version 2.0 (the "License");
43
+  you may not use this file except in compliance with the License.
44
+  You may obtain a copy of the License at
45
+
46
+    http://www.apache.org/licenses/LICENSE-2.0
47
+
48
+  Unless required by applicable law or agreed to in writing, software
49
+  distributed under the License is distributed on an "AS IS" BASIS,
50
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
51
+  See the License for the specific language governing permissions and
52
+  limitations under the License.
53
+*/
54
+
35 55
 #include <stdbool.h>
36 56
 
37 57
 #include "ch.h"
38 58
 #include "hal.h"
39 59
 
60
+static event_listener_t el;
61
+static event_source_t IR_receiver;
62
+/*===========================================================================*/
63
+/* IR remote related code.                                                   */
64
+/*===========================================================================*/
65
+
66
+#define DELTA          5
67
+#define START_PULSE    45
68
+#define END_PULSE      405
69
+#define RPT_CMD_PULSE  959
70
+#define ZERO_PULSE     6
71
+#define ONE_PULSE      17
72
+#define COMMA_PULSE    23
73
+
40 74
 /* PWM configuration for IR output */
41 75
 static PWMConfig pwmcfg = {
42 76
     380000, /* 380 kHz PWM clock frequency. */
@@ -59,6 +93,58 @@ static const GPTConfig gpt4cfg = {
59 93
   0, 0
60 94
 };
61 95
 
96
+/*===========================================================================*/
97
+/* ICU related code.                                                         */
98
+/*===========================================================================*/
99
+static int32_t index = -1;
100
+static bool START_OCCURED = FALSE, REPEAT_FLAG = FALSE;
101
+static uint32_t tmp, command;
102
+static void icuwidthcb(ICUDriver *icup) {
103
+
104
+  icucnt_t cnt = icuGetWidthX(icup);
105
+  if((cnt > (START_PULSE - DELTA)) && (cnt < (START_PULSE + DELTA))){
106
+    index = 0;
107
+    START_OCCURED = TRUE;
108
+  }
109
+  else if((cnt > (ONE_PULSE - DELTA)) && (cnt < (ONE_PULSE + DELTA))){
110
+    tmp |= 1 << (31 - index);
111
+    index++;
112
+  }
113
+  else if((cnt > (ZERO_PULSE - DELTA)) && (cnt < (ZERO_PULSE + DELTA))){
114
+    tmp &= ~(1 << (31 - index));
115
+    index++;
116
+  }
117
+  else if((cnt > (END_PULSE - 4*DELTA)) && (cnt < (END_PULSE + 4*DELTA))){
118
+    if((START_OCCURED) && (index == 32)) {
119
+      command = tmp;
120
+    } else {
121
+      command = 0;
122
+    }
123
+    REPEAT_FLAG = FALSE;
124
+    START_OCCURED = FALSE;
125
+    index = -1;
126
+  }
127
+  else if((cnt > (RPT_CMD_PULSE - DELTA)) && (cnt < (RPT_CMD_PULSE + DELTA))){
128
+    REPEAT_FLAG = TRUE;
129
+  }
130
+  else if((cnt > (COMMA_PULSE - DELTA)) && (cnt < (COMMA_PULSE + DELTA))){
131
+    chEvtBroadcastFlags(&IR_receiver, 0);
132
+  }
133
+  else{
134
+    /* Long dead pulse nothing to do */
135
+  }
136
+}
137
+
138
+static ICUConfig icucfg = {
139
+  ICU_INPUT_ACTIVE_HIGH,
140
+  10000,            /* 10kHz ICU clock frequency. */
141
+  icuwidthcb,
142
+  NULL,
143
+  NULL,
144
+  ICU_CHANNEL_1,
145
+  0
146
+};
147
+
62 148
 /*
63 149
  * Green LED blinker thread, times are in milliseconds.
64 150
  */
@@ -127,10 +213,23 @@ int main(void) {
127 213
     halInit();
128 214
     chSysInit();
129 215
 
216
+      chEvtObjectInit(&IR_receiver);
217
+  chEvtRegister(&IR_receiver, &el, 0);
218
+/*
219
+ * Initializes the ICU driver 3.
220
+ * GPIOC6 is the ICU input.
221
+ * The two pins have to be externally connected together.
222
+ */
223
+  sdStart(&SD2, NULL);
224
+  icuStart(&ICUD3, &icucfg);
225
+  palSetPadMode(GPIOA, 6, PAL_MODE_INPUT_PULLDOWN);
226
+  icuStartCapture(&ICUD3);
227
+  icuEnableNotifications(&ICUD3);
228
+
130 229
     /*
131 230
      * Creates the blinker thread.
132 231
      */
133
-    chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
232
+    //chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
134 233
 
135 234
     /* Configure PWM */
136 235
     pwmStart(&PWMD1, &pwmcfg);
@@ -141,8 +240,17 @@ int main(void) {
141 240
 
142 241
     /* Send a continuous stream of power off signals to the TV */
143 242
     while (true) {
144
-        rc5_frame(false, 0x00, 0x0C);
145
-
146
-        chThdSleepMilliseconds(90);
243
+        if (command == 0x807F18E7) {
244
+            if (chEvtWaitAnyTimeout(ALL_EVENTS, MS2ST(200))) {
245
+                continue;
246
+            }
247
+            palClearPad(GPIOC, GPIOC_LED);
248
+            for (int i = 0; i < 3; i++) {
249
+                rc5_frame(false, 0x00, 0x0C);
250
+                chThdSleepMilliseconds(90);
251
+            }
252
+            palSetPad(GPIOC, GPIOC_LED);
253
+        }
254
+        chEvtWaitAny(ALL_EVENTS);
147 255
     }
148 256
 }

Loading…
Откажи
Сачувај