Skip to content

Commit

Permalink
Add new/new_unchecked methods for USB structures
Browse files Browse the repository at this point in the history
Breaking change on USB API, since the structure no longer contains instances of
the pin types
  • Loading branch information
richardeoin committed Feb 14, 2021
1 parent 08231e3 commit 1ff969b
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 52 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## [Unreleased]

* **Breaking**: Add new/new_unchecked methods for USB structures, remove pin
types from structure
* Add support for USB1_ULPI #184


## [v0.8.0] 2020-10-26

* **Breaking**: Ethernet PHY configuration feature flags removed. The user must
Expand Down
37 changes: 19 additions & 18 deletions examples/usb_passthrough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,25 @@ fn main() -> ! {
let gpioa = dp.GPIOA.split(ccdr.peripheral.GPIOA);
let gpiob = dp.GPIOB.split(ccdr.peripheral.GPIOB);

let usb1 = USB1 {
usb_global: dp.OTG1_HS_GLOBAL,
usb_device: dp.OTG1_HS_DEVICE,
usb_pwrclk: dp.OTG1_HS_PWRCLK,
pin_dm: gpiob.pb14.into_alternate_af12(),
pin_dp: gpiob.pb15.into_alternate_af12(),
prec: ccdr.peripheral.USB1OTG,
hclk: ccdr.clocks.hclk(),
};
let usb2 = USB2 {
usb_global: dp.OTG2_HS_GLOBAL,
usb_device: dp.OTG2_HS_DEVICE,
usb_pwrclk: dp.OTG2_HS_PWRCLK,
pin_dm: gpioa.pa11.into_alternate_af10(),
pin_dp: gpioa.pa12.into_alternate_af10(),
prec: ccdr.peripheral.USB2OTG,
hclk: ccdr.clocks.hclk(),
};
let usb1 = USB1::new(
dp.OTG1_HS_GLOBAL,
dp.OTG1_HS_DEVICE,
dp.OTG1_HS_PWRCLK,
gpiob.pb14.into_alternate_af12(),
gpiob.pb15.into_alternate_af12(),
ccdr.peripheral.USB1OTG,
ccdr.clocks.hclk(),
);

let usb2 = USB2::new(
dp.OTG2_HS_GLOBAL,
dp.OTG2_HS_DEVICE,
dp.OTG2_HS_PWRCLK,
gpioa.pa11.into_alternate_af10(),
gpioa.pa12.into_alternate_af10(),
ccdr.peripheral.USB2OTG,
ccdr.clocks.hclk(),
);

// Port 1
let usb1_bus = UsbBus::new(usb1, unsafe { &mut EP_MEMORY_1 });
Expand Down
14 changes: 7 additions & 7 deletions examples/usb_serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ fn main() -> ! {
)
};

let usb = USB1 {
usb_global: dp.OTG1_HS_GLOBAL,
usb_device: dp.OTG1_HS_DEVICE,
usb_pwrclk: dp.OTG1_HS_PWRCLK,
let usb = USB1::new(
dp.OTG1_HS_GLOBAL,
dp.OTG1_HS_DEVICE,
dp.OTG1_HS_PWRCLK,
pin_dm,
pin_dp,
prec: ccdr.peripheral.USB1OTG,
hclk: ccdr.clocks.hclk(),
};
ccdr.peripheral.USB1OTG,
ccdr.clocks.hclk(),
);

let usb_bus = UsbBus::new(usb, unsafe { &mut EP_MEMORY });

Expand Down
135 changes: 108 additions & 27 deletions src/usb_hs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,91 @@ use crate::time::Hertz;
pub use synopsys_usb_otg::UsbBus;
use synopsys_usb_otg::UsbPeripheral;

#[cfg(not(feature = "rm0455"))]
pub struct USB1 {
pub usb_global: stm32::OTG1_HS_GLOBAL,
pub usb_device: stm32::OTG1_HS_DEVICE,
pub usb_pwrclk: stm32::OTG1_HS_PWRCLK,
pub pin_dm: PB14<Alternate<AF12>>,
pub pin_dp: PB15<Alternate<AF12>>,
pub prec: rcc::rec::Usb1Otg,
pub hclk: Hertz,
}
impl USB1 {
#[cfg(not(feature = "rm0455"))]
pub fn new(
usb_global: stm32::OTG1_HS_GLOBAL,
usb_device: stm32::OTG1_HS_DEVICE,
usb_pwrclk: stm32::OTG1_HS_PWRCLK,
_pin_dm: PB14<Alternate<AF12>>,
_pin_dp: PB15<Alternate<AF12>>,
prec: rcc::rec::Usb1Otg,
hclk: Hertz,
) -> Self {
Self::new_unchecked(usb_global, usb_device, usb_pwrclk, prec, hclk)
}
#[cfg(feature = "rm0455")]
pub fn new(
usb_global: stm32::OTG1_HS_GLOBAL,
usb_device: stm32::OTG1_HS_DEVICE,
usb_pwrclk: stm32::OTG1_HS_PWRCLK,
_pin_dm: PA11<Alternate<AF10>>,
_pin_dp: PA12<Alternate<AF10>>,
prec: rcc::rec::Usb1Otg,
hclk: Hertz,
) -> Self {
Self::new_unchecked(usb_global, usb_device, usb_pwrclk, prec, hclk)
}
pub fn new_unchecked(
usb_global: stm32::OTG1_HS_GLOBAL,
usb_device: stm32::OTG1_HS_DEVICE,
usb_pwrclk: stm32::OTG1_HS_PWRCLK,
prec: rcc::rec::Usb1Otg,
hclk: Hertz,
) -> Self {
USB1 {
usb_global,
usb_device,
usb_pwrclk,
prec,
hclk,
}
}
}

#[cfg(not(feature = "rm0455"))]
pub struct USB2 {
pub usb_global: stm32::OTG2_HS_GLOBAL,
pub usb_device: stm32::OTG2_HS_DEVICE,
pub usb_pwrclk: stm32::OTG2_HS_PWRCLK,
pub pin_dm: PA11<Alternate<AF10>>,
pub pin_dp: PA12<Alternate<AF10>>,
pub prec: rcc::rec::Usb2Otg,
pub hclk: Hertz,
}

#[cfg(feature = "rm0455")]
pub struct USB1 {
pub usb_global: stm32::OTG1_HS_GLOBAL,
pub usb_device: stm32::OTG1_HS_DEVICE,
pub usb_pwrclk: stm32::OTG1_HS_PWRCLK,
pub pin_dm: PA11<Alternate<AF10>>,
pub pin_dp: PA12<Alternate<AF10>>,
pub prec: rcc::rec::Usb1Otg,
pub hclk: Hertz,
#[cfg(not(feature = "rm0455"))]
impl USB2 {
pub fn new(
usb_global: stm32::OTG2_HS_GLOBAL,
usb_device: stm32::OTG2_HS_DEVICE,
usb_pwrclk: stm32::OTG2_HS_PWRCLK,
_pin_dm: PA11<Alternate<AF10>>,
_pin_dp: PA12<Alternate<AF10>>,
prec: rcc::rec::Usb2Otg,
hclk: Hertz,
) -> Self {
Self::new_unchecked(usb_global, usb_device, usb_pwrclk, prec, hclk)
}
pub fn new_unchecked(
usb_global: stm32::OTG2_HS_GLOBAL,
usb_device: stm32::OTG2_HS_DEVICE,
usb_pwrclk: stm32::OTG2_HS_PWRCLK,
prec: rcc::rec::Usb2Otg,
hclk: Hertz,
) -> Self {
USB2 {
usb_global,
usb_device,
usb_pwrclk,
prec,
hclk,
}
}
}

macro_rules! usb_peripheral {
Expand Down Expand Up @@ -115,18 +169,6 @@ pub struct USB1_ULPI {
pub usb_pwrclk: stm32::OTG1_HS_PWRCLK,
pub prec: rcc::rec::Usb1Otg,
pub hclk: Hertz,
pub ulpi_clk: PA5<Alternate<AF10>>,
pub ulpi_dir: Usb1UlpiDirPin,
pub ulpi_nxt: Usb1UlpiNxtPin,
pub ulpi_stp: PC0<Alternate<AF10>>,
pub ulpi_d0: PA3<Alternate<AF10>>,
pub ulpi_d1: PB0<Alternate<AF10>>,
pub ulpi_d2: PB1<Alternate<AF10>>,
pub ulpi_d3: PB10<Alternate<AF10>>,
pub ulpi_d4: PB11<Alternate<AF10>>,
pub ulpi_d5: PB12<Alternate<AF10>>,
pub ulpi_d6: PB13<Alternate<AF10>>,
pub ulpi_d7: PB5<Alternate<AF10>>,
}

pub enum Usb1UlpiDirPin {
Expand Down Expand Up @@ -163,6 +205,45 @@ impl From<PC3<Alternate<AF10>>> for Usb1UlpiNxtPin {
}
}

impl USB1_ULPI {
pub fn new(
usb_global: stm32::OTG1_HS_GLOBAL,
usb_device: stm32::OTG1_HS_DEVICE,
usb_pwrclk: stm32::OTG1_HS_PWRCLK,
_ulpi_clk: PA5<Alternate<AF10>>,
_ulpi_dir: impl Into<Usb1UlpiDirPin>,
_ulpi_nxt: impl Into<Usb1UlpiNxtPin>,
_ulpi_stp: PC0<Alternate<AF10>>,
_ulpi_d0: PA3<Alternate<AF10>>,
_ulpi_d1: PB0<Alternate<AF10>>,
_ulpi_d2: PB1<Alternate<AF10>>,
_ulpi_d3: PB10<Alternate<AF10>>,
_ulpi_d4: PB11<Alternate<AF10>>,
_ulpi_d5: PB12<Alternate<AF10>>,
_ulpi_d6: PB13<Alternate<AF10>>,
_ulpi_d7: PB5<Alternate<AF10>>,
prec: rcc::rec::Usb1Otg,
hclk: Hertz,
) -> Self {
Self::new_unchecked(usb_global, usb_device, usb_pwrclk, prec, hclk)
}
pub fn new_unchecked(
usb_global: stm32::OTG1_HS_GLOBAL,
usb_device: stm32::OTG1_HS_DEVICE,
usb_pwrclk: stm32::OTG1_HS_PWRCLK,
prec: rcc::rec::Usb1Otg,
hclk: Hertz,
) -> Self {
USB1_ULPI {
usb_global,
usb_device,
usb_pwrclk,
prec,
hclk,
}
}
}

unsafe impl Sync for USB1_ULPI {}

unsafe impl UsbPeripheral for USB1_ULPI {
Expand Down

0 comments on commit 1ff969b

Please sign in to comment.