Skip to content

Commit c5ce182

Browse files
committed
Split out serialnum code
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent e47ba72 commit c5ce182

File tree

4 files changed

+19
-32
lines changed

4 files changed

+19
-32
lines changed

src/bin/b1display.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,14 @@ use heapless::String;
4747

4848
use lotus_input::control::*;
4949
use lotus_input::graphics::*;
50+
use lotus_input::serialnum::get_serialnum;
5051

5152
// FRA - Framwork
5253
// KDE - Lotus C2 LED Matrix
5354
// AM - Atemitech
5455
// 00 - Default Configuration
5556
// 00000000 - Device Identifier
5657
const DEFAULT_SERIAL: &str = "FRAKDEAM0000000000";
57-
// Get serial number from last 4K block of the first 1M
58-
const FLASH_OFFSET: usize = 0x10000000;
59-
const LAST_4K_BLOCK: usize = 0xff000;
60-
const SERIALNUM_LEN: usize = 18;
61-
62-
fn get_serialnum() -> Option<&'static str> {
63-
// Flash is mapped into memory, just read it from there
64-
let ptr: *const u8 = (FLASH_OFFSET + LAST_4K_BLOCK) as *const u8;
65-
unsafe {
66-
let slice: &[u8] = core::slice::from_raw_parts(ptr, SERIALNUM_LEN);
67-
if slice[0] == 0xFF || slice[0] == 0x00 {
68-
return None;
69-
}
70-
core::str::from_utf8(slice).ok()
71-
}
72-
}
7358

7459
#[allow(clippy::large_enum_variant)]
7560
#[derive(Clone)]

src/bin/ledmatrix.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,29 +100,14 @@ use lotus_input::control::*;
100100
use lotus_input::lotus::LotusLedMatrix;
101101
use lotus_input::matrix::*;
102102
use lotus_input::patterns::*;
103+
use lotus_input::serialnum::get_serialnum;
103104

104105
// FRA - Framwork
105106
// KDE - Lotus C2 LED Matrix
106107
// AM - Atemitech
107108
// 00 - Default Configuration
108109
// 00000000 - Device Identifier
109110
const DEFAULT_SERIAL: &str = "FRAKDEAM0000000000";
110-
// Get serial number from last 4K block of the first 1M
111-
const FLASH_OFFSET: usize = 0x10000000;
112-
const LAST_4K_BLOCK: usize = 0xff000;
113-
const SERIALNUM_LEN: usize = 18;
114-
115-
fn get_serialnum() -> Option<&'static str> {
116-
// Flash is mapped into memory, just read it from there
117-
let ptr: *const u8 = (FLASH_OFFSET + LAST_4K_BLOCK) as *const u8;
118-
unsafe {
119-
let slice: &[u8] = core::slice::from_raw_parts(ptr, SERIALNUM_LEN);
120-
if slice[0] == 0xFF || slice[0] == 0x00 {
121-
return None;
122-
}
123-
core::str::from_utf8(slice).ok()
124-
}
125-
}
126111

127112
#[entry]
128113
fn main() -> ! {

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ pub mod graphics;
1717
pub mod lotus_lcd_hal;
1818

1919
pub mod control;
20+
pub mod serialnum;

src/serialnum.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Get serial number from last 4K block of the first 1M
2+
const FLASH_OFFSET: usize = 0x10000000;
3+
const LAST_4K_BLOCK: usize = 0xff000;
4+
const SERIALNUM_LEN: usize = 18;
5+
6+
pub fn get_serialnum() -> Option<&'static str> {
7+
// Flash is mapped into memory, just read it from there
8+
let ptr: *const u8 = (FLASH_OFFSET + LAST_4K_BLOCK) as *const u8;
9+
unsafe {
10+
let slice: &[u8] = core::slice::from_raw_parts(ptr, SERIALNUM_LEN);
11+
if slice[0] == 0xFF || slice[0] == 0x00 {
12+
return None;
13+
}
14+
core::str::from_utf8(slice).ok()
15+
}
16+
}

0 commit comments

Comments
 (0)