Skip to main content

esp_hal/usb/otg/
fs_pins.rs

1//! D+ / D- pin configuration for full-speed USB OTG.
2
3use crate::{gpio::Pin, peripherals::IO_MUX};
4
5/// USB D+ pin for full-speed OTG.
6pub trait UsbFsDp: crate::private::Sealed {
7    #[doc(hidden)]
8    fn configure(&self);
9}
10
11/// USB D- pin for full-speed OTG.
12pub trait UsbFsDm: crate::private::Sealed {
13    #[doc(hidden)]
14    fn configure(&self);
15}
16
17fn set_high_drive(pin: &impl Pin) {
18    IO_MUX::regs()
19        .gpio(pin.number() as usize)
20        .modify(|_, w| unsafe { w.fun_drv().bits(3) });
21}
22
23for_each_analog_function! {
24    (USB_FS_DM, $gpio:ident) => {
25        impl UsbFsDm for crate::peripherals::$gpio<'_> {
26            fn configure(&self) {
27                set_high_drive(self);
28            }
29        }
30    };
31    (USB_FS_DP, $gpio:ident) => {
32        impl UsbFsDp for crate::peripherals::$gpio<'_> {
33            fn configure(&self) {
34                set_high_drive(self);
35            }
36        }
37    };
38}