ソースを参照

Added main library header file

For now, the new <pdb.h> file only has a function to start the library,
based on the old start_pd function from main.c.  It'll eventually be all
a user needs to include, but there's a lot more refactoring to do.
Clara Hobbs 7年前
コミット
e6fe5ece3d
4個のファイルの変更78行の追加31行の削除
  1. 29
    0
      lib/include/pdb.h
  2. 0
    0
      lib/include/policy_engine.h
  3. 43
    0
      lib/src/pdb.c
  4. 6
    31
      src/main.c

+ 29
- 0
lib/include/pdb.h ファイルの表示

@@ -0,0 +1,29 @@
1
+/*
2
+ * PD Buddy - USB Power Delivery for everyone
3
+ * Copyright (C) 2017 Clayton G. Hobbs <clay@lakeserv.net>
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+#ifndef PDB_H
20
+#define PDB_H
21
+
22
+
23
+/*
24
+ * Initialize the PD Buddy firmware library, starting all its threads
25
+ */
26
+void pdb_init(void);
27
+
28
+
29
+#endif /* PDB_H */

lib/src/policy_engine.h → lib/include/policy_engine.h ファイルの表示


+ 43
- 0
lib/src/pdb.c ファイルの表示

@@ -0,0 +1,43 @@
1
+/*
2
+ * PD Buddy - USB Power Delivery for everyone
3
+ * Copyright (C) 2017 Clayton G. Hobbs <clay@lakeserv.net>
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+#include <pdb.h>
20
+#include "policy_engine.h"
21
+#include "protocol_rx.h"
22
+#include "protocol_tx.h"
23
+#include "hard_reset.h"
24
+#include "int_n.h"
25
+#include "fusb302b.h"
26
+
27
+
28
+void pdb_init(void)
29
+{
30
+    /* Initialize the FUSB302B */
31
+    fusb_setup();
32
+
33
+    /* Create the policy engine thread. */
34
+    pdb_pe_run();
35
+
36
+    /* Create the protocol layer threads. */
37
+    pdb_prlrx_run();
38
+    pdb_prltx_run();
39
+    pdb_hardrst_run();
40
+
41
+    /* Create the INT_N thread. */
42
+    pdb_int_n_run();
43
+}

+ 6
- 31
src/main.c ファイルの表示

@@ -40,14 +40,9 @@
40 40
 #include "shell.h"
41 41
 #include "usbcfg.h"
42 42
 
43
+#include <pdb.h>
43 44
 #include "led.h"
44 45
 #include "device_policy_manager.h"
45
-#include "policy_engine.h"
46
-#include "protocol_tx.h"
47
-#include "protocol_rx.h"
48
-#include "hard_reset.h"
49
-#include "int_n.h"
50
-#include "fusb302b.h"
51 46
 #include "messages.h"
52 47
 
53 48
 /*
@@ -61,29 +56,6 @@ static const I2CConfig i2c2config = {
61 56
     0
62 57
 };
63 58
 
64
-/*
65
- * Start the USB Power Delivery threads
66
- */
67
-static void start_pd(void)
68
-{
69
-    /* Start I2C2 to make communication with the PHY possible */
70
-    i2cStart(&I2CD2, &i2c2config);
71
-
72
-    /* Initialize the FUSB302B */
73
-    fusb_setup();
74
-
75
-    /* Create the policy engine thread. */
76
-    pdb_pe_run();
77
-
78
-    /* Create the protocol layer threads. */
79
-    pdb_prlrx_run();
80
-    pdb_prltx_run();
81
-    pdb_hardrst_run();
82
-
83
-    /* Create the INT_N thread. */
84
-    pdb_int_n_run();
85
-}
86
-
87 59
 /*
88 60
  * Enter setup mode
89 61
  */
@@ -95,7 +67,7 @@ static void setup(void)
95 67
     pdb_dpm_usb_comms = true;
96 68
 
97 69
     /* Start the USB Power Delivery threads */
98
-    start_pd();
70
+    pdb_init();
99 71
 
100 72
     /* Indicate that we're in setup mode */
101 73
     chEvtSignal(pdb_led_thread, PDB_EVT_LED_CONFIG);
@@ -122,7 +94,7 @@ static void setup(void)
122 94
 static void sink(void)
123 95
 {
124 96
     /* Start the USB Power Delivery threads */
125
-    start_pd();
97
+    pdb_init();
126 98
 
127 99
     /* Wait, letting all the other threads do their work. */
128 100
     while (true) {
@@ -151,6 +123,9 @@ int main(void) {
151 123
     /* Create the LED thread. */
152 124
     pdb_led_run();
153 125
 
126
+    /* Start I2C2 to make communication with the PHY possible */
127
+    i2cStart(&I2CD2, &i2c2config);
128
+
154 129
     /* Decide what mode to enter by the state of the button */
155 130
     if (palReadLine(LINE_BUTTON) == PAL_HIGH) {
156 131
         /* Button pressed -> setup mode */

読み込み中…
キャンセル
保存