Skip to content

Commit

Permalink
Add method to allow USBBus to be constructed with v2 clock
Browse files Browse the repository at this point in the history
  • Loading branch information
rnd-ash committed Jan 7, 2025
1 parent d7ce590 commit dc5275e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions hal/src/peripherals/usb/d5x/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use super::Descriptors;
use crate::calibration::{usb_transn_cal, usb_transp_cal, usb_trim_cal};
use crate::clock;
use crate::clock::v2::pclk::{Pclk, PclkSourceId};
use crate::clock::v2::types::Usb as UsbClk;
use crate::gpio::{AlternateH, AnyPin, Pin, PA24, PA25};
use crate::pac;
use crate::pac::usb::Device;
Expand Down Expand Up @@ -549,6 +551,31 @@ impl UsbBus {
inner: Mutex::new(RefCell::new(inner)),
}
}

pub fn new_with_v2_clock<PS: PclkSourceId>(
_pclk: Pclk<UsbClk, PS>,
mclk: &mut Mclk,
dm_pad: impl AnyPin<Id = PA24>,
dp_pad: impl AnyPin<Id = PA25>,
_usb: Usb,
) -> Self {
mclk.ahbmask().modify(|_, w| w.usb_().set_bit());
mclk.apbbmask().modify(|_, w| w.usb_().set_bit());

let desc = RefCell::new(Descriptors::new());

let inner = Inner {
_dm_pad: dm_pad.into().into_mode::<AlternateH>(),
_dp_pad: dp_pad.into().into_mode::<AlternateH>(),
desc,
buffers: RefCell::new(BufferAllocator::new()),
endpoints: RefCell::new(AllEndpoints::new()),
};

Self {
inner: Mutex::new(RefCell::new(inner)),
}
}
}

impl Inner {
Expand Down

0 comments on commit dc5275e

Please sign in to comment.