Browse Source

Improve formatting, remove unused code

Clara Hobbs 6 years ago
parent
commit
d34f1e1f87
1 changed files with 54 additions and 78 deletions
  1. 54
    78
      src/main.c

+ 54
- 78
src/main.c View File

57
 #include "ch.h"
57
 #include "ch.h"
58
 #include "hal.h"
58
 #include "hal.h"
59
 
59
 
60
-static event_listener_t el;
61
-static event_source_t IR_receiver;
62
-/*===========================================================================*/
63
-/* IR remote related code.                                                   */
64
-/*===========================================================================*/
65
 
60
 
61
+/*
62
+ * NEC timing macros
63
+ */
66
 #define DELTA          5
64
 #define DELTA          5
67
 #define START_PULSE    45
65
 #define START_PULSE    45
68
 #define END_PULSE      405
66
 #define END_PULSE      405
71
 #define ONE_PULSE      17
69
 #define ONE_PULSE      17
72
 #define COMMA_PULSE    23
70
 #define COMMA_PULSE    23
73
 
71
 
72
+
73
+static event_listener_t el;
74
+static event_source_t IR_receiver;
75
+
74
 /* PWM configuration for IR output */
76
 /* PWM configuration for IR output */
75
 static PWMConfig pwmcfg = {
77
 static PWMConfig pwmcfg = {
76
-    380000, /* 380 kHz PWM clock frequency. */
77
-    10, /* PWM period 10 clock cycles.   */
78
+    380000, /* 380 kHz PWM clock frequency */
79
+    10, /* PWM period 10 clock cycles */
78
     NULL,
80
     NULL,
79
     {
81
     {
80
         {PWM_OUTPUT_ACTIVE_HIGH, NULL},
82
         {PWM_OUTPUT_ACTIVE_HIGH, NULL},
88
 
90
 
89
 /* Timer configuration for IR output */
91
 /* Timer configuration for IR output */
90
 static const GPTConfig gpt4cfg = {
92
 static const GPTConfig gpt4cfg = {
91
-  1000000, // 1 MHz timer clock.
92
-  NULL, // No callback
93
-  0, 0
93
+    1000000, /* 1 MHz timer clock */
94
+    NULL, /* No callback */
95
+    0, 0
94
 };
96
 };
95
 
97
 
96
 /*===========================================================================*/
98
 /*===========================================================================*/
99
 static int32_t index = -1;
101
 static int32_t index = -1;
100
 static bool START_OCCURED = FALSE, REPEAT_FLAG = FALSE;
102
 static bool START_OCCURED = FALSE, REPEAT_FLAG = FALSE;
101
 static uint32_t tmp, command;
103
 static uint32_t tmp, command;
102
-static void icuwidthcb(ICUDriver *icup) {
103
 
104
 
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;
105
+static void icuwidthcb(ICUDriver *icup) {
106
+    icucnt_t cnt = icuGetWidthX(icup);
107
+    if ((cnt > (START_PULSE - DELTA)) && (cnt < (START_PULSE + DELTA))) {
108
+        index = 0;
109
+        START_OCCURED = TRUE;
110
+    } else if ((cnt > (ONE_PULSE - DELTA)) && (cnt < (ONE_PULSE + DELTA))) {
111
+        tmp |= 1 << (31 - index);
112
+        index++;
113
+    } else if ((cnt > (ZERO_PULSE - DELTA)) && (cnt < (ZERO_PULSE + DELTA))) {
114
+        tmp &= ~(1 << (31 - index));
115
+        index++;
116
+    } else if ((cnt > (END_PULSE - 4*DELTA)) && (cnt < (END_PULSE + 4*DELTA))) {
117
+        if ((START_OCCURED) && (index == 32)) {
118
+            command = tmp;
119
+        } else {
120
+            command = 0;
121
+        }
122
+        REPEAT_FLAG = FALSE;
123
+        START_OCCURED = FALSE;
124
+        index = -1;
125
+    } else if ((cnt > (RPT_CMD_PULSE - DELTA)) && (cnt < (RPT_CMD_PULSE + DELTA))) {
126
+        REPEAT_FLAG = TRUE;
127
+    } else if ((cnt > (COMMA_PULSE - DELTA)) && (cnt < (COMMA_PULSE + DELTA))) {
128
+        chEvtBroadcastFlags(&IR_receiver, 0);
120
     } else {
129
     } else {
121
-      command = 0;
130
+        /* Long dead pulse nothing to do */
122
     }
131
     }
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
 }
132
 }
137
 
133
 
138
 static ICUConfig icucfg = {
134
 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
135
+    ICU_INPUT_ACTIVE_HIGH,
136
+    10000,            /* 10kHz ICU clock frequency. */
137
+    icuwidthcb,
138
+    NULL,
139
+    NULL,
140
+    ICU_CHANNEL_1,
141
+    0
146
 };
142
 };
147
 
143
 
148
-/*
149
- * Green LED blinker thread, times are in milliseconds.
150
- */
151
-static THD_WORKING_AREA(waThread1, 128);
152
-static THD_FUNCTION(Thread1, arg) {
153
-
154
-    (void)arg;
155
-    while (true) {
156
-        palClearPad(GPIOC, GPIOC_LED);
157
-        chThdSleepMilliseconds(500);
158
-        palSetPad(GPIOC, GPIOC_LED);
159
-        chThdSleepMilliseconds(500);
160
-    }
161
-}
162
-
163
 /*
144
 /*
164
  * Synchronously send one bit for RC5
145
  * Synchronously send one bit for RC5
165
  */
146
  */
213
     halInit();
194
     halInit();
214
     chSysInit();
195
     chSysInit();
215
 
196
 
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
-
197
+    chEvtObjectInit(&IR_receiver);
198
+    chEvtRegister(&IR_receiver, &el, 0);
229
     /*
199
     /*
230
-     * Creates the blinker thread.
200
+     * Initializes the ICU driver 3.
201
+     * GPIOC6 is the ICU input.
202
+     * The two pins have to be externally connected together.
231
      */
203
      */
232
-    //chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
204
+    sdStart(&SD2, NULL);
205
+    icuStart(&ICUD3, &icucfg);
206
+    palSetPadMode(GPIOA, 6, PAL_MODE_INPUT_PULLDOWN);
207
+    icuStartCapture(&ICUD3);
208
+    icuEnableNotifications(&ICUD3);
233
 
209
 
234
     /* Configure PWM */
210
     /* Configure PWM */
235
     pwmStart(&PWMD1, &pwmcfg);
211
     pwmStart(&PWMD1, &pwmcfg);

Loading…
Cancel
Save