-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
hardware.rs
152 lines (135 loc) · 4.34 KB
/
hardware.rs
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//! Hardware related commands for Neotron OS
use crate::{bios, osprintln, Ctx, API};
pub static LSHW_ITEM: menu::Item<Ctx> = menu::Item {
item_type: menu::ItemType::Callback {
function: lshw,
parameters: &[],
},
command: "lshw",
help: Some("List all the BIOS hardware"),
};
pub static SHUTDOWN_ITEM: menu::Item<Ctx> = menu::Item {
item_type: menu::ItemType::Callback {
function: shutdown,
parameters: &[
menu::Parameter::Named {
parameter_name: "reboot",
help: Some("Reboot after shutting down"),
},
menu::Parameter::Named {
parameter_name: "bootloader",
help: Some("Reboot into the bootloader after shutting down"),
},
],
},
command: "shutdown",
help: Some("Shutdown the system"),
};
/// Called when the "lshw" command is executed.
fn lshw(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, _args: &[&str], _ctx: &mut Ctx) {
let api = API.get();
let mut found = false;
osprintln!("Memory regions:");
for region_idx in 0..=255u8 {
if let bios::FfiOption::Some(region) = (api.memory_get_region)(region_idx) {
osprintln!(" {}: {}", region_idx, region);
found = true;
}
}
if !found {
osprintln!(" None");
}
found = false;
osprintln!("Serial Devices:");
for dev_idx in 0..=255u8 {
if let bios::FfiOption::Some(device_info) = (api.serial_get_info)(dev_idx) {
osprintln!(
" {}: {} {:?}",
dev_idx,
device_info.name,
device_info.device_type
);
found = true;
}
}
if !found {
osprintln!(" None");
}
found = false;
osprintln!("Block Devices:");
for dev_idx in 0..=255u8 {
if let bios::FfiOption::Some(device_info) = (api.block_dev_get_info)(dev_idx) {
osprintln!(
" {}: {} {:?} bs={} size={} MiB",
dev_idx,
device_info.name,
device_info.device_type,
device_info.block_size,
(device_info.num_blocks * u64::from(device_info.block_size)) / (1024 * 1024)
);
found = true;
}
}
if !found {
osprintln!(" None");
}
found = false;
osprintln!("I2C Buses:");
for dev_idx in 0..=255u8 {
if let bios::FfiOption::Some(device_info) = (api.i2c_bus_get_info)(dev_idx) {
osprintln!(" {}: {:?}", dev_idx, device_info);
found = true;
}
}
if !found {
osprintln!(" None");
}
found = false;
osprintln!("Neotron Bus Devices:");
for dev_idx in 0..=255u8 {
if let bios::FfiOption::Some(device_info) = (api.bus_get_info)(dev_idx) {
osprintln!(" {}: {:?}", dev_idx, device_info);
found = true;
}
}
if !found {
osprintln!(" None");
}
found = false;
osprintln!("Audio Mixers:");
for dev_idx in 0..=255u8 {
if let bios::FfiOption::Some(device_info) = (api.audio_mixer_channel_get_info)(dev_idx) {
let dir = match device_info.direction {
bios::audio::Direction::Input => "In",
bios::audio::Direction::Output => "Out",
bios::audio::Direction::Loopback => "Loop",
};
osprintln!(
" {}: {:08} ({}) {}/{}",
dev_idx,
device_info.name,
dir,
device_info.current_level,
device_info.max_level
);
found = true;
}
}
if !found {
osprintln!(" None");
}
}
/// Called when the "shutdown" command is executed.
fn shutdown(_menu: &menu::Menu<Ctx>, item: &menu::Item<Ctx>, args: &[&str], _ctx: &mut Ctx) {
let api = API.get();
if let Ok(Some(_)) = menu::argument_finder(item, args, "reboot") {
osprintln!("Rebooting...");
(api.power_control)(bios::PowerMode::Reset);
} else if let Ok(Some(_)) = menu::argument_finder(item, args, "bootloader") {
osprintln!("Rebooting into bootloader...");
(api.power_control)(bios::PowerMode::Bootloader);
} else {
osprintln!("Shutting down...");
(api.power_control)(bios::PowerMode::Off);
}
}