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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! Version information.
use core::ffi::CStr;
use flipperzero_sys as sys;
#[repr(transparent)]
pub struct Version(sys::Version);
impl Version {
/// Get current running firmware version.
pub fn get() -> &'static Self {
// SAFETY: Returned pointer is a pointer to static, so never NULL.
unsafe { Self::from_ptr(sys::version_get()) }
}
/// Get version from pointer.
///
/// # Safety
/// Pointer must be non-NULL and valid for `'a`.
pub unsafe fn from_ptr<'a>(ptr: *const sys::Version) -> &'a Version {
// SAFETY: Version has same layout as C Version struct.
unsafe { &*ptr.cast() }
}
/// Pointer to version data.
pub fn as_ptr(&self) -> *const sys::Version {
&raw const self.0
}
/// git commit hash.
pub fn git_hash(&self) -> &'static CStr {
// SAFETY: Returned pointer is a pointer to static, so never NULL.
unsafe { CStr::from_ptr(sys::version_get_githash(self.as_ptr())) }
}
/// git branch.
pub fn git_branch(&self) -> &'static CStr {
// SAFETY: Returned pointer is a pointer to static, so never NULL.
unsafe { CStr::from_ptr(sys::version_get_gitbranch(self.as_ptr())) }
}
/// Number of commits in git branch.
pub fn git_branchnum(&self) -> &'static CStr {
// SAFETY: Returned pointer is a pointer to static, so never NULL.
unsafe { CStr::from_ptr(sys::version_get_gitbranchnum(self.as_ptr())) }
}
/// Build version.
pub fn version(&self) -> &'static CStr {
// SAFETY: Returned pointer is a pointer to static, so never NULL.
unsafe { CStr::from_ptr(sys::version_get_version(self.as_ptr())) }
}
/// Hardware target this firmware was built for.
pub fn target(&self) -> u8 {
unsafe { sys::version_get_target(self.as_ptr()) }
}
/// Check if this build is "dirty" (source code had uncommited changes).
pub fn is_dirty(&self) -> bool {
unsafe { sys::version_get_dirty_flag(self.as_ptr()) }
}
/// Get firmware origin. "Official" for mainline firmware, fork name for forks.
pub fn firmware_origin(&self) -> &'static CStr {
// SAFETY: Returned pointer is a pointer to static, so never NULL.
unsafe { CStr::from_ptr(sys::version_get_firmware_origin(self.as_ptr())) }
}
/// Get git repo origin.
pub fn git_origin(&self) -> &'static CStr {
// SAFETY: Returned pointer is a pointer to static, so never NULL.
unsafe { CStr::from_ptr(sys::version_get_git_origin(self.as_ptr())) }
}
}