@@ -12,22 +12,29 @@ namespace Raspberry
12
12
/// <summary>
13
13
/// Represents the Raspberry Pi mainboard.
14
14
/// </summary>
15
- /// <remarks>Version and revisions are based on <see cref="http://raspberryalphaomega.org.uk/2013/02/06/automatic-raspberry-pi-board-revision-detection-model-a-b1-and-b2/"/>.</remarks>
15
+ /// <remarks>
16
+ /// Version and revisions are based on <see cref="http://raspberryalphaomega.org.uk/2013/02/06/automatic-raspberry-pi-board-revision-detection-model-a-b1-and-b2/"/>.
17
+ /// <see cref="http://www.raspberrypi-spy.co.uk/2012/09/checking-your-raspberry-pi-board-version/"/> for information.
18
+ /// </remarks>
16
19
public class Board
17
20
{
18
21
#region Fields
19
22
20
23
private static readonly Lazy < Board > board = new Lazy < Board > ( LoadBoard ) ;
21
-
22
- private readonly Dictionary < string , string > settings ;
23
- private readonly HashSet < string > raspberryPiProcessors = new HashSet < string > ( new [ ] { "BCM2708" , "BCM2709" } , StringComparer . InvariantCultureIgnoreCase ) ;
24
24
25
+ private readonly Dictionary < string , string > settings ;
26
+ private readonly Lazy < Model > model ;
27
+ private readonly Lazy < ConnectorPinout > connectorPinout ;
28
+
25
29
#endregion
26
30
27
31
#region Instance Management
28
32
29
33
private Board ( Dictionary < string , string > settings )
30
34
{
35
+ model = new Lazy < Model > ( LoadModel ) ;
36
+ connectorPinout = new Lazy < ConnectorPinout > ( LoadConnectorPinout ) ;
37
+
31
38
this . settings = settings ;
32
39
}
33
40
@@ -51,13 +58,19 @@ public static Board Current
51
58
/// </value>
52
59
public bool IsRaspberryPi
53
60
{
54
- get { return raspberryPiProcessors . Contains ( Processor ) ; }
61
+ get
62
+ {
63
+ return Processor != Processor . Unknown ;
64
+ }
55
65
}
56
66
57
67
/// <summary>
58
- /// Gets the processor.
68
+ /// Gets the processor name .
59
69
/// </summary>
60
- public string Processor
70
+ /// <value>
71
+ /// The name of the processor.
72
+ /// </value>
73
+ public string ProcessorName
61
74
{
62
75
get
63
76
{
@@ -66,6 +79,21 @@ public string Processor
66
79
}
67
80
}
68
81
82
+ /// <summary>
83
+ /// Gets the processor.
84
+ /// </summary>
85
+ /// <value>
86
+ /// The processor.
87
+ /// </value>
88
+ public Processor Processor
89
+ {
90
+ get
91
+ {
92
+ Processor processor ;
93
+ return Enum . TryParse ( ProcessorName , true , out processor ) ? processor : Processor . Unknown ;
94
+ }
95
+ }
96
+
69
97
/// <summary>
70
98
/// Gets the board firmware version.
71
99
/// </summary>
@@ -117,79 +145,24 @@ public bool IsOverclocked
117
145
/// <summary>
118
146
/// Gets the model.
119
147
/// </summary>
120
- /// <returns>The model name (<c>A</c> or <c>B</c>) if known; otherwise, <c>(char)0</c>.</returns>
121
- public char Model
148
+ /// <value>
149
+ /// The model.
150
+ /// </value>
151
+ public Model Model
122
152
{
123
- get
124
- {
125
- var firmware = Firmware ;
126
- switch ( firmware & 0xFFFF )
127
- {
128
- case 0x7 :
129
- case 0x8 :
130
- case 0x9 :
131
- return 'A' ;
132
-
133
- case 0x2 :
134
- case 0x3 :
135
- case 0x4 :
136
- case 0x5 :
137
- case 0x6 :
138
- case 0xd :
139
- case 0xe :
140
- case 0xf :
141
- case 0x10 :
142
- return 'B' ;
143
-
144
- case 0x1040 :
145
- case 0x1041 :
146
- return '2' ;
147
-
148
- default :
149
- return ( char ) 0 ;
150
- }
151
- }
153
+ get { return model . Value ; }
152
154
}
153
155
154
156
/// <summary>
155
- /// Gets the board revision.
157
+ /// Gets the connector revision.
156
158
/// </summary>
157
- /// <returns>The board revision for the given <see cref="Model"/> if known; otherwise, <c>0</c>.</returns>
158
- public int Revision
159
+ /// <value>
160
+ /// The connector revision.
161
+ /// </value>
162
+ /// <remarks>See <see cref="http://raspi.tv/2014/rpi-gpio-quick-reference-updated-for-raspberry-pi-b"/> for more information.</remarks>
163
+ public ConnectorPinout ConnectorPinout
159
164
{
160
- get
161
- {
162
- var firmware = Firmware ;
163
- switch ( firmware & 0xFFFF )
164
- {
165
- case 0x7 :
166
- case 0x8 :
167
- case 0x9 :
168
- return 1 ; // Model A, rev1
169
-
170
- case 0x2 :
171
- case 0x3 :
172
- return 1 ; // Model B, rev1
173
-
174
- case 0x4 :
175
- case 0x5 :
176
- case 0x6 :
177
- case 0xd :
178
- case 0xe :
179
- case 0xf :
180
- return 2 ; // Model B, rev2
181
-
182
- case 0x10 :
183
- return 3 ; // Model B+, rev3
184
-
185
- case 0x1040 :
186
- case 0x1041 :
187
- return 4 ;
188
-
189
- default :
190
- return 0 ; // Unknown
191
- }
192
- }
165
+ get { return connectorPinout . Value ; }
193
166
}
194
167
195
168
#endregion
@@ -231,6 +204,68 @@ private static Board LoadBoard()
231
204
}
232
205
}
233
206
207
+ private Model LoadModel ( )
208
+ {
209
+ var firmware = Firmware ;
210
+ switch ( firmware & 0xFFFF )
211
+ {
212
+ case 0x2 :
213
+ case 0x3 :
214
+ return Model . BRev1 ;
215
+
216
+ case 0x4 :
217
+ case 0x5 :
218
+ case 0x6 :
219
+ case 0xd :
220
+ case 0xe :
221
+ case 0xf :
222
+ return Model . BRev2 ;
223
+
224
+ case 0x7 :
225
+ case 0x8 :
226
+ case 0x9 :
227
+ return Model . A ;
228
+
229
+ case 0x10 :
230
+ return Model . BPlus ;
231
+
232
+ case 0x11 :
233
+ return Model . ComputeModule ;
234
+
235
+ case 0x12 :
236
+ return Model . APlus ;
237
+
238
+ case 0x1040 :
239
+ case 0x1041 :
240
+ return Model . B2 ;
241
+
242
+ default :
243
+ return Model . Unknown ;
244
+ }
245
+ }
246
+
247
+ private ConnectorPinout LoadConnectorPinout ( )
248
+ {
249
+ switch ( Model )
250
+ {
251
+ case Model . BRev1 :
252
+ return ConnectorPinout . Rev1 ;
253
+
254
+ case Model . BRev2 :
255
+ case Model . A :
256
+ return ConnectorPinout . Rev2 ;
257
+
258
+ case Model . BPlus :
259
+ case Model . ComputeModule :
260
+ case Model . APlus :
261
+ case Model . B2 :
262
+ return ConnectorPinout . Plus ;
263
+
264
+ default :
265
+ return ConnectorPinout . Unknown ;
266
+ }
267
+ }
268
+
234
269
#endregion
235
270
}
236
271
}
0 commit comments