22
33use crate :: { bios, osprintln, Ctx , API } ;
44
5- pub static LSHW_ITEM : menu:: Item < Ctx > = menu:: Item {
5+ pub static LSBLK_ITEM : menu:: Item < Ctx > = menu:: Item {
66 item_type : menu:: ItemType :: Callback {
7- function : lshw ,
7+ function : lsblk ,
88 parameters : & [ ] ,
99 } ,
10- command : "lshw" ,
11- help : Some ( "List all the BIOS hardware" ) ,
10+ command : "lsblk" ,
11+ help : Some ( "List all the Block Devices" ) ,
12+ } ;
13+
14+ pub static LSBUS_ITEM : menu:: Item < Ctx > = menu:: Item {
15+ item_type : menu:: ItemType :: Callback {
16+ function : lsbus,
17+ parameters : & [ ] ,
18+ } ,
19+ command : "lsbus" ,
20+ help : Some ( "List all the Neotron Bus devices" ) ,
21+ } ;
22+
23+ pub static LSI2C_ITEM : menu:: Item < Ctx > = menu:: Item {
24+ item_type : menu:: ItemType :: Callback {
25+ function : lsi2c,
26+ parameters : & [ ] ,
27+ } ,
28+ command : "lsi2c" ,
29+ help : Some ( "List all the BIOS I2C devices" ) ,
30+ } ;
31+
32+ pub static LSMEM_ITEM : menu:: Item < Ctx > = menu:: Item {
33+ item_type : menu:: ItemType :: Callback {
34+ function : lsmem,
35+ parameters : & [ ] ,
36+ } ,
37+ command : "lsmem" ,
38+ help : Some ( "List all the BIOS Memory regions" ) ,
39+ } ;
40+
41+ pub static LSUART_ITEM : menu:: Item < Ctx > = menu:: Item {
42+ item_type : menu:: ItemType :: Callback {
43+ function : lsuart,
44+ parameters : & [ ] ,
45+ } ,
46+ command : "lsuart" ,
47+ help : Some ( "List all the BIOS UARTs" ) ,
1248} ;
1349
1450pub static SHUTDOWN_ITEM : menu:: Item < Ctx > = menu:: Item {
@@ -29,109 +65,130 @@ pub static SHUTDOWN_ITEM: menu::Item<Ctx> = menu::Item {
2965 help : Some ( "Shutdown the system" ) ,
3066} ;
3167
32- /// Called when the "lshw " command is executed.
33- fn lshw ( _menu : & menu:: Menu < Ctx > , _item : & menu:: Item < Ctx > , _args : & [ & str ] , _ctx : & mut Ctx ) {
68+ /// Called when the "lsblk " command is executed.
69+ fn lsblk ( _menu : & menu:: Menu < Ctx > , _item : & menu:: Item < Ctx > , _args : & [ & str ] , _ctx : & mut Ctx ) {
3470 let api = API . get ( ) ;
3571 let mut found = false ;
3672
37- osprintln ! ( "Memory regions:" ) ;
38- for region_idx in 0 ..=255u8 {
39- if let bios:: FfiOption :: Some ( region) = ( api. memory_get_region ) ( region_idx) {
40- osprintln ! ( " {}: {}" , region_idx, region) ;
41- found = true ;
42- }
43- }
44- if !found {
45- osprintln ! ( " None" ) ;
46- }
47-
48- found = false ;
49-
50- osprintln ! ( "Serial Devices:" ) ;
73+ osprintln ! ( "Block Devices:" ) ;
5174 for dev_idx in 0 ..=255u8 {
52- if let bios:: FfiOption :: Some ( device_info) = ( api. serial_get_info ) ( dev_idx) {
75+ if let bios:: FfiOption :: Some ( device_info) = ( api. block_dev_get_info ) ( dev_idx) {
76+ let ( bsize, bunits, dsize, dunits) =
77+ match device_info. num_blocks * u64:: from ( device_info. block_size ) {
78+ x if x < ( 1024 * 1024 * 1024 ) => {
79+ // Under 1 GiB, give it in 10s of MiB
80+ ( 10 * x / ( 1024 * 1024 ) , "MiB" , x / 100_000 , "MB" )
81+ }
82+ x => {
83+ // Anything else in GiB
84+ ( 10 * x / ( 1024 * 1024 * 1024 ) , "GiB" , x / 100_000_000 , "GB" )
85+ }
86+ } ;
87+ osprintln ! ( "Device {}:" , dev_idx) ;
88+ osprintln ! ( "\t Name: {}" , device_info. name) ;
89+ osprintln ! ( "\t Type: {:?}" , device_info. device_type) ;
90+ osprintln ! ( "\t Block size: {}" , device_info. block_size) ;
91+ osprintln ! ( "\t Num Blocks: {}" , device_info. num_blocks) ;
92+ osprintln ! (
93+ "\t Card Size: {}.{} {} ({}.{} {})" ,
94+ bsize / 10 ,
95+ bsize % 10 ,
96+ bunits,
97+ dsize / 10 ,
98+ dsize % 10 ,
99+ dunits
100+ ) ;
101+ osprintln ! ( "\t Ejectable: {}" , device_info. ejectable) ;
102+ osprintln ! ( "\t Removable: {}" , device_info. removable) ;
103+ osprintln ! ( "\t Read Only: {}" , device_info. read_only) ;
53104 osprintln ! (
54- " {}: {} {:?}" ,
55- dev_idx,
56- device_info. name,
57- device_info. device_type
105+ "\t Media: {}" ,
106+ if device_info. media_present {
107+ "Present"
108+ } else {
109+ "Missing"
110+ }
58111 ) ;
59112 found = true ;
60113 }
61114 }
62115 if !found {
63- osprintln ! ( " None " ) ;
116+ osprintln ! ( "\t None " ) ;
64117 }
118+ }
65119
66- found = false ;
67-
68- osprintln ! ( "Block Devices:" ) ;
120+ /// Called when the "lsbus" command is executed.
121+ fn lsbus ( _menu : & menu:: Menu < Ctx > , _item : & menu:: Item < Ctx > , _args : & [ & str ] , _ctx : & mut Ctx ) {
122+ let api = API . get ( ) ;
123+ let mut found = false ;
124+ osprintln ! ( "Neotron Bus Devices:" ) ;
69125 for dev_idx in 0 ..=255u8 {
70- if let bios:: FfiOption :: Some ( device_info) = ( api. block_dev_get_info ) ( dev_idx) {
71- osprintln ! (
72- " {}: {} {:?} bs={} size={} MiB" ,
73- dev_idx,
74- device_info. name,
75- device_info. device_type,
76- device_info. block_size,
77- ( device_info. num_blocks * u64 :: from( device_info. block_size) ) / ( 1024 * 1024 )
78- ) ;
126+ if let bios:: FfiOption :: Some ( device_info) = ( api. bus_get_info ) ( dev_idx) {
127+ let kind = match device_info. kind {
128+ bios:: bus:: PeripheralKind :: Slot => "Slot" ,
129+ bios:: bus:: PeripheralKind :: SdCard => "SdCard" ,
130+ bios:: bus:: PeripheralKind :: Reserved => "Reserved" ,
131+ } ;
132+ osprintln ! ( "\t {}: {} ({})" , dev_idx, device_info. name, kind) ;
79133 found = true ;
80134 }
81135 }
82136 if !found {
83- osprintln ! ( " None " ) ;
137+ osprintln ! ( "\t None " ) ;
84138 }
139+ }
85140
86- found = false ;
87-
141+ /// Called when the "lsi2c" command is executed.
142+ fn lsi2c ( _menu : & menu:: Menu < Ctx > , _item : & menu:: Item < Ctx > , _args : & [ & str ] , _ctx : & mut Ctx ) {
143+ let api = API . get ( ) ;
144+ let mut found = false ;
88145 osprintln ! ( "I2C Buses:" ) ;
89146 for dev_idx in 0 ..=255u8 {
90147 if let bios:: FfiOption :: Some ( device_info) = ( api. i2c_bus_get_info ) ( dev_idx) {
91- osprintln ! ( " {}: {:? }" , dev_idx, device_info) ;
148+ osprintln ! ( "\t {}: {}" , dev_idx, device_info. name ) ;
92149 found = true ;
93150 }
94151 }
95152 if !found {
96- osprintln ! ( " None " ) ;
153+ osprintln ! ( "\t None " ) ;
97154 }
155+ }
98156
99- found = false ;
100-
101- osprintln ! ( "Neotron Bus Devices:" ) ;
102- for dev_idx in 0 ..=255u8 {
103- if let bios:: FfiOption :: Some ( device_info) = ( api. bus_get_info ) ( dev_idx) {
104- osprintln ! ( " {}: {:?}" , dev_idx, device_info) ;
157+ /// Called when the "lsmem" command is executed.
158+ fn lsmem ( _menu : & menu:: Menu < Ctx > , _item : & menu:: Item < Ctx > , _args : & [ & str ] , _ctx : & mut Ctx ) {
159+ let api = API . get ( ) ;
160+ let mut found = false ;
161+ osprintln ! ( "Memory regions:" ) ;
162+ for region_idx in 0 ..=255u8 {
163+ if let bios:: FfiOption :: Some ( region) = ( api. memory_get_region ) ( region_idx) {
164+ osprintln ! ( "\t {}: {}" , region_idx, region) ;
105165 found = true ;
106166 }
107167 }
108168 if !found {
109- osprintln ! ( " None " ) ;
169+ osprintln ! ( "\t None " ) ;
110170 }
171+ }
111172
112- found = false ;
113-
114- osprintln ! ( "Audio Mixers:" ) ;
173+ /// Called when the "lsuart" command is executed.
174+ fn lsuart ( _menu : & menu:: Menu < Ctx > , _item : & menu:: Item < Ctx > , _args : & [ & str ] , _ctx : & mut Ctx ) {
175+ let api = API . get ( ) ;
176+ let mut found = false ;
177+ osprintln ! ( "UART Devices:" ) ;
115178 for dev_idx in 0 ..=255u8 {
116- if let bios:: FfiOption :: Some ( device_info) = ( api. audio_mixer_channel_get_info ) ( dev_idx) {
117- let dir = match device_info. direction {
118- bios:: audio:: Direction :: Input => "In" ,
119- bios:: audio:: Direction :: Output => "Out" ,
120- bios:: audio:: Direction :: Loopback => "Loop" ,
179+ if let bios:: FfiOption :: Some ( device_info) = ( api. serial_get_info ) ( dev_idx) {
180+ let device_type = match device_info. device_type {
181+ bios:: serial:: DeviceType :: Rs232 => "RS232" ,
182+ bios:: serial:: DeviceType :: TtlUart => "TTL" ,
183+ bios:: serial:: DeviceType :: UsbCdc => "USB" ,
184+ bios:: serial:: DeviceType :: Midi => "MIDI" ,
121185 } ;
122- osprintln ! (
123- " {}: {:08} ({}) {}/{}" ,
124- dev_idx,
125- device_info. name,
126- dir,
127- device_info. current_level,
128- device_info. max_level
129- ) ;
186+ osprintln ! ( "\t {}: {} ({})" , dev_idx, device_info. name, device_type) ;
130187 found = true ;
131188 }
132189 }
133190 if !found {
134- osprintln ! ( " None " ) ;
191+ osprintln ! ( "\t None " ) ;
135192 }
136193}
137194
@@ -150,3 +207,5 @@ fn shutdown(_menu: &menu::Menu<Ctx>, item: &menu::Item<Ctx>, args: &[&str], _ctx
150207 ( api. power_control ) ( bios:: PowerMode :: Off ) ;
151208 }
152209}
210+
211+ // End of file
0 commit comments