Skip to content

Commit

Permalink
USB route api change
Browse files Browse the repository at this point in the history
The boot pin state is added to the USB state, as its closely related to
the different roles a given node forfills.

THIS BREAKS the storage layout. -> reset of storage required
  • Loading branch information
svenrademakers committed Nov 23, 2023
1 parent ebb4240 commit 3ada3a1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/api/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ async fn set_usb_mode(bmc: &BmcApplication, query: Query) -> LegacyResult<()> {

let mode = UsbMode::from_api_mode(mode_num);

let route = if (mode_num >> 1) & 0x1 == 1 {
let route = if (mode_num >> 2) & 0x1 == 1 {
UsbRoute::Bmc
} else {
UsbRoute::UsbA
Expand All @@ -497,6 +497,7 @@ async fn set_usb_mode(bmc: &BmcApplication, query: Query) -> LegacyResult<()> {
(UsbMode::Device, UsbRoute::UsbA) => UsbConfig::UsbA(node),
(UsbMode::Device, UsbRoute::Bmc) => UsbConfig::Bmc(node),
(UsbMode::Host, route) => UsbConfig::Node(node, route),
(UsbMode::Flash, route) => UsbConfig::Flashing(node, route),
};

bmc.configure_usb(cfg)
Expand All @@ -513,6 +514,7 @@ async fn get_usb_mode(bmc: &BmcApplication) -> impl Into<LegacyResponse> {
UsbConfig::UsbA(node) => (node, UsbMode::Device, UsbRoute::UsbA),
UsbConfig::Bmc(node) => (node, UsbMode::Device, UsbRoute::Bmc),
UsbConfig::Node(node, route) => (node, UsbMode::Host, route),
UsbConfig::Flashing(node, route) => (node, UsbMode::Flash, route),
};

json!(
Expand Down
11 changes: 5 additions & 6 deletions src/app/bmc_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub enum UsbConfig {
Bmc(NodeId),
/// NodeId is host, [UsbRoute] is configured for device
Node(NodeId, UsbRoute),
Flashing(NodeId, UsbRoute),
}

/// Encodings used when reading from a serial port
Expand Down Expand Up @@ -171,11 +172,13 @@ impl BmcApplication {
let (mode, dest, route) = match config {
UsbConfig::UsbA(device) => (UsbMode::Device, device, UsbRoute::UsbA),
UsbConfig::Bmc(device) => (UsbMode::Device, device, UsbRoute::Bmc),
UsbConfig::Flashing(device, route) => (UsbMode::Flash, device, route),
UsbConfig::Node(host, route) => (UsbMode::Host, host, route),
};

self.pin_controller.set_usb_route(route).await?;
self.pin_controller.select_usb(dest, mode)?;

Ok(())
}

Expand Down Expand Up @@ -218,12 +221,8 @@ impl BmcApplication {

sleep(REBOOT_DELAY).await;

let config = match router {
UsbRoute::Bmc => UsbConfig::Bmc(node),
UsbRoute::UsbA => UsbConfig::UsbA(node),
};
self.usb_boot(node, true).await?;
self.configure_usb_internal(config).await?;
self.configure_usb_internal(UsbConfig::Flashing(node, router))
.await?;

log::info!("Prerequisite settings toggled, powering on...");
self.activate_slot(node.to_bitfield(), node.to_bitfield())
Expand Down
2 changes: 2 additions & 0 deletions src/hal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,15 @@ pub enum UsbRoute {
pub enum UsbMode {
Host,
Device,
Flash,
}

impl UsbMode {
pub fn from_api_mode(value: i32) -> Self {
match value & 0x1 {
0 => UsbMode::Host,
1 => UsbMode::Device,
2 => UsbMode::Flash,
_ => unreachable!(),
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/hal/pin_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,15 @@ impl PinController {

let vbus = match mode {
UsbMode::Host => node.to_inverse_bitfield(),
UsbMode::Device => 0b1111,
UsbMode::Device | UsbMode::Flash => 0b1111,
};
self.usb_vbus.set_values(vbus)
self.usb_vbus.set_values(vbus)?;

if UsbMode::Flash == mode {
self.set_usb_boot(node.to_bitfield(), node.to_bitfield())?;
}

Ok(())
}

/// Set which way the USB is routed: USB-A ↔ PORTx (`UsbRoute::UsbA`) or BMC ↔ PORTx
Expand Down

0 comments on commit 3ada3a1

Please sign in to comment.