@@ -12,22 +12,29 @@ namespace Raspberry
1212 /// <summary>
1313 /// Represents the Raspberry Pi mainboard.
1414 /// </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>
1619 public class Board
1720 {
1821 #region Fields
1922
2023 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 ) ;
2424
25+ private readonly Dictionary < string , string > settings ;
26+ private readonly Lazy < Model > model ;
27+ private readonly Lazy < ConnectorPinout > connectorPinout ;
28+
2529 #endregion
2630
2731 #region Instance Management
2832
2933 private Board ( Dictionary < string , string > settings )
3034 {
35+ model = new Lazy < Model > ( LoadModel ) ;
36+ connectorPinout = new Lazy < ConnectorPinout > ( LoadConnectorPinout ) ;
37+
3138 this . settings = settings ;
3239 }
3340
@@ -51,13 +58,19 @@ public static Board Current
5158 /// </value>
5259 public bool IsRaspberryPi
5360 {
54- get { return raspberryPiProcessors . Contains ( Processor ) ; }
61+ get
62+ {
63+ return Processor != Processor . Unknown ;
64+ }
5565 }
5666
5767 /// <summary>
58- /// Gets the processor.
68+ /// Gets the processor name .
5969 /// </summary>
60- public string Processor
70+ /// <value>
71+ /// The name of the processor.
72+ /// </value>
73+ public string ProcessorName
6174 {
6275 get
6376 {
@@ -66,6 +79,21 @@ public string Processor
6679 }
6780 }
6881
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+
6997 /// <summary>
7098 /// Gets the board firmware version.
7199 /// </summary>
@@ -117,79 +145,24 @@ public bool IsOverclocked
117145 /// <summary>
118146 /// Gets the model.
119147 /// </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
122152 {
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 ; }
152154 }
153155
154156 /// <summary>
155- /// Gets the board revision.
157+ /// Gets the connector revision.
156158 /// </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
159164 {
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 ; }
193166 }
194167
195168 #endregion
@@ -231,6 +204,68 @@ private static Board LoadBoard()
231204 }
232205 }
233206
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+
234269 #endregion
235270 }
236271}
0 commit comments