feat: add optional USB SOF output

This commit is contained in:
elagil 2025-03-12 23:18:34 +01:00
parent 38f26137fc
commit f1db070f78
2 changed files with 22 additions and 0 deletions

View File

@ -876,6 +876,7 @@ fn main() {
(("ltdc", "B7"), quote!(crate::ltdc::B7Pin)), (("ltdc", "B7"), quote!(crate::ltdc::B7Pin)),
(("usb", "DP"), quote!(crate::usb::DpPin)), (("usb", "DP"), quote!(crate::usb::DpPin)),
(("usb", "DM"), quote!(crate::usb::DmPin)), (("usb", "DM"), quote!(crate::usb::DmPin)),
(("usb", "SOF"), quote!(crate::usb::SofPin)),
(("otg", "DP"), quote!(crate::usb::DpPin)), (("otg", "DP"), quote!(crate::usb::DpPin)),
(("otg", "DM"), quote!(crate::usb::DmPin)), (("otg", "DM"), quote!(crate::usb::DmPin)),
(("otg", "ULPI_CK"), quote!(crate::usb::UlpiClkPin)), (("otg", "ULPI_CK"), quote!(crate::usb::UlpiClkPin)),

View File

@ -287,6 +287,26 @@ pub struct Driver<'d, T: Instance> {
} }
impl<'d, T: Instance> Driver<'d, T> { impl<'d, T: Instance> Driver<'d, T> {
/// Create a new USB driver with start-of-frame (SOF) output.
pub fn new_with_sof(
_usb: impl Peripheral<P = T> + 'd,
_irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
dp: impl Peripheral<P = impl DpPin<T>> + 'd,
dm: impl Peripheral<P = impl DmPin<T>> + 'd,
sof: impl Peripheral<P = impl SofPin<T>> + 'd,
) -> Self {
into_ref!(sof);
#[cfg(not(stm32l1))]
{
use crate::gpio::{AfType, OutputType, Speed};
sof.set_as_af(sof.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
}
#[cfg(stm32l1)]
let _ = sof; // suppress "unused" warning.
Self::new(_usb, _irq, dp, dm)
}
/// Create a new USB driver. /// Create a new USB driver.
pub fn new( pub fn new(
_usb: impl Peripheral<P = T> + 'd, _usb: impl Peripheral<P = T> + 'd,
@ -1208,6 +1228,7 @@ pub trait Instance: SealedInstance + RccPeripheral + 'static {
// Internal PHY pins // Internal PHY pins
pin_trait!(DpPin, Instance); pin_trait!(DpPin, Instance);
pin_trait!(DmPin, Instance); pin_trait!(DmPin, Instance);
pin_trait!(SofPin, Instance);
foreach_interrupt!( foreach_interrupt!(
($inst:ident, usb, $block:ident, LP, $irq:ident) => { ($inst:ident, usb, $block:ident, LP, $irq:ident) => {