1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use Error;
use std::str::FromStr;
#[macro_export]
macro_rules! make_version {
($a:expr, $b:expr, $c:expr, $d:expr) => {
(($a << 24) & 0xff000000) | (($b << 16) & 0x00ff0000)
| (($c << 8) & 0x0000ff00) | ($d & 0x000000ff)
}
}
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum Platform {
M100,
A3,
}
impl FromStr for Platform {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"m100" => Ok(Platform::M100),
"a3" => Ok(Platform::A3),
_ => Err(Error::UnknownPlatform),
}
}
}
pub mod sdk {
use super::Platform;
use std::sync::{ONCE_INIT, Once};
static ONCE: Once = ONCE_INIT;
static mut PLATFORM: Platform = Platform::M100;
pub fn set_platform(platform: Platform) {
ONCE.call_once(|| unsafe {
PLATFORM = platform;
});
}
pub fn platform() -> Platform {
*unsafe { &PLATFORM }
}
}