aboutsummaryrefslogtreecommitdiff
path: root/embassy-usb-synopsys-otg
diff options
context:
space:
mode:
authorKevin <[email protected]>2024-09-15 02:44:16 +0200
committerKevin <[email protected]>2024-09-22 00:23:07 +0200
commit2f60d78ea318f51ff59868c348b77cf880012198 (patch)
treedb390bf1d2091f67ea21f47dde567a96a7558553 /embassy-usb-synopsys-otg
parentafd8a869620f420f9ccae3b40654c4a515b78044 (diff)
Add OTG_HS support for STM32H7R/S
Diffstat (limited to 'embassy-usb-synopsys-otg')
-rw-r--r--embassy-usb-synopsys-otg/src/lib.rs16
-rw-r--r--embassy-usb-synopsys-otg/src/otg_v1.rs171
2 files changed, 187 insertions, 0 deletions
diff --git a/embassy-usb-synopsys-otg/src/lib.rs b/embassy-usb-synopsys-otg/src/lib.rs
index b145f4aa8..3ff965149 100644
--- a/embassy-usb-synopsys-otg/src/lib.rs
+++ b/embassy-usb-synopsys-otg/src/lib.rs
@@ -584,6 +584,22 @@ impl<'d, const MAX_EP_COUNT: usize> Bus<'d, MAX_EP_COUNT> {
584 }); 584 });
585 } 585 }
586 586
587 pub fn config_v5(&mut self) {
588 let r = self.instance.regs;
589
590 r.gccfg_v3().modify(|w| {
591 w.set_vbvaloven(true);
592 w.set_vbvaloval(true);
593 w.set_vbden(self.config.vbus_detection);
594 });
595
596 // Force B-peripheral session
597 r.gotgctl().modify(|w| {
598 w.set_vbvaloen(!self.config.vbus_detection);
599 w.set_bvaloval(true);
600 });
601 }
602
587 fn init(&mut self) { 603 fn init(&mut self) {
588 let r = self.instance.regs; 604 let r = self.instance.regs;
589 let phy_type = self.instance.phy_type; 605 let phy_type = self.instance.phy_type;
diff --git a/embassy-usb-synopsys-otg/src/otg_v1.rs b/embassy-usb-synopsys-otg/src/otg_v1.rs
index d3abc328d..18e760fd1 100644
--- a/embassy-usb-synopsys-otg/src/otg_v1.rs
+++ b/embassy-usb-synopsys-otg/src/otg_v1.rs
@@ -186,6 +186,11 @@ impl Otg {
186 pub const fn gccfg_v2(self) -> Reg<regs::GccfgV2, RW> { 186 pub const fn gccfg_v2(self) -> Reg<regs::GccfgV2, RW> {
187 unsafe { Reg::from_ptr(self.ptr.add(0x38usize) as _) } 187 unsafe { Reg::from_ptr(self.ptr.add(0x38usize) as _) }
188 } 188 }
189 #[doc = "General core configuration register, for core_id 0x0000_5xxx"]
190 #[inline(always)]
191 pub const fn gccfg_v3(self) -> Reg<regs::GccfgV3, RW> {
192 unsafe { Reg::from_ptr(self.ptr.add(0x38usize) as _) }
193 }
189 #[doc = "Core ID register"] 194 #[doc = "Core ID register"]
190 #[inline(always)] 195 #[inline(always)]
191 pub const fn cid(self) -> Reg<regs::Cid, RW> { 196 pub const fn cid(self) -> Reg<regs::Cid, RW> {
@@ -1831,6 +1836,172 @@ pub mod regs {
1831 GccfgV2(0) 1836 GccfgV2(0)
1832 } 1837 }
1833 } 1838 }
1839 #[doc = "OTG general core configuration register."]
1840 #[repr(transparent)]
1841 #[derive(Copy, Clone, Eq, PartialEq)]
1842 pub struct GccfgV3(pub u32);
1843 impl GccfgV3 {
1844 #[doc = "Charger detection, result of the current mode (primary or secondary)."]
1845 #[inline(always)]
1846 pub const fn chgdet(&self) -> bool {
1847 let val = (self.0 >> 0usize) & 0x01;
1848 val != 0
1849 }
1850 #[doc = "Charger detection, result of the current mode (primary or secondary)."]
1851 #[inline(always)]
1852 pub fn set_chgdet(&mut self, val: bool) {
1853 self.0 = (self.0 & !(0x01 << 0usize)) | (((val as u32) & 0x01) << 0usize);
1854 }
1855 #[doc = "Single-Ended DP indicator This bit gives the voltage level on DP (also result of the comparison with V<sub>LGC</sub> threshold as defined in BC v1.2 standard)."]
1856 #[inline(always)]
1857 pub const fn fsvplus(&self) -> bool {
1858 let val = (self.0 >> 1usize) & 0x01;
1859 val != 0
1860 }
1861 #[doc = "Single-Ended DP indicator This bit gives the voltage level on DP (also result of the comparison with V<sub>LGC</sub> threshold as defined in BC v1.2 standard)."]
1862 #[inline(always)]
1863 pub fn set_fsvplus(&mut self, val: bool) {
1864 self.0 = (self.0 & !(0x01 << 1usize)) | (((val as u32) & 0x01) << 1usize);
1865 }
1866 #[doc = "Single-Ended DM indicator This bit gives the voltage level on DM (also result of the comparison with V<sub>LGC</sub> threshold as defined in BC v1.2 standard)."]
1867 #[inline(always)]
1868 pub const fn fsvminus(&self) -> bool {
1869 let val = (self.0 >> 2usize) & 0x01;
1870 val != 0
1871 }
1872 #[doc = "Single-Ended DM indicator This bit gives the voltage level on DM (also result of the comparison with V<sub>LGC</sub> threshold as defined in BC v1.2 standard)."]
1873 #[inline(always)]
1874 pub fn set_fsvminus(&mut self, val: bool) {
1875 self.0 = (self.0 & !(0x01 << 2usize)) | (((val as u32) & 0x01) << 2usize);
1876 }
1877 #[doc = "VBUS session indicator Indicates if VBUS is above VBUS session threshold."]
1878 #[inline(always)]
1879 pub const fn sessvld(&self) -> bool {
1880 let val = (self.0 >> 3usize) & 0x01;
1881 val != 0
1882 }
1883 #[doc = "VBUS session indicator Indicates if VBUS is above VBUS session threshold."]
1884 #[inline(always)]
1885 pub fn set_sessvld(&mut self, val: bool) {
1886 self.0 = (self.0 & !(0x01 << 3usize)) | (((val as u32) & 0x01) << 3usize);
1887 }
1888 #[doc = "Host CDP behavior enable."]
1889 #[inline(always)]
1890 pub const fn hcdpen(&self) -> bool {
1891 let val = (self.0 >> 16usize) & 0x01;
1892 val != 0
1893 }
1894 #[doc = "Host CDP behavior enable."]
1895 #[inline(always)]
1896 pub fn set_hcdpen(&mut self, val: bool) {
1897 self.0 = (self.0 & !(0x01 << 16usize)) | (((val as u32) & 0x01) << 16usize);
1898 }
1899 #[doc = "Host CDP port voltage detector enable on DP."]
1900 #[inline(always)]
1901 pub const fn hcdpdeten(&self) -> bool {
1902 let val = (self.0 >> 17usize) & 0x01;
1903 val != 0
1904 }
1905 #[doc = "Host CDP port voltage detector enable on DP."]
1906 #[inline(always)]
1907 pub fn set_hcdpdeten(&mut self, val: bool) {
1908 self.0 = (self.0 & !(0x01 << 17usize)) | (((val as u32) & 0x01) << 17usize);
1909 }
1910 #[doc = "Host CDP port Voltage source enable on DM."]
1911 #[inline(always)]
1912 pub const fn hvdmsrcen(&self) -> bool {
1913 let val = (self.0 >> 18usize) & 0x01;
1914 val != 0
1915 }
1916 #[doc = "Host CDP port Voltage source enable on DM."]
1917 #[inline(always)]
1918 pub fn set_hvdmsrcen(&mut self, val: bool) {
1919 self.0 = (self.0 & !(0x01 << 18usize)) | (((val as u32) & 0x01) << 18usize);
1920 }
1921 #[doc = "Data Contact Detection enable."]
1922 #[inline(always)]
1923 pub const fn dcden(&self) -> bool {
1924 let val = (self.0 >> 19usize) & 0x01;
1925 val != 0
1926 }
1927 #[doc = "Data Contact Detection enable."]
1928 #[inline(always)]
1929 pub fn set_dcden(&mut self, val: bool) {
1930 self.0 = (self.0 & !(0x01 << 19usize)) | (((val as u32) & 0x01) << 19usize);
1931 }
1932 #[doc = "Primary detection enable."]
1933 #[inline(always)]
1934 pub const fn pden(&self) -> bool {
1935 let val = (self.0 >> 20usize) & 0x01;
1936 val != 0
1937 }
1938 #[doc = "Primary detection enable."]
1939 #[inline(always)]
1940 pub fn set_pden(&mut self, val: bool) {
1941 self.0 = (self.0 & !(0x01 << 20usize)) | (((val as u32) & 0x01) << 20usize);
1942 }
1943 #[doc = "VBUS detection enable Enables VBUS Sensing Comparators in order to detect VBUS presence and/or perform OTG operation."]
1944 #[inline(always)]
1945 pub const fn vbden(&self) -> bool {
1946 let val = (self.0 >> 21usize) & 0x01;
1947 val != 0
1948 }
1949 #[doc = "VBUS detection enable Enables VBUS Sensing Comparators in order to detect VBUS presence and/or perform OTG operation."]
1950 #[inline(always)]
1951 pub fn set_vbden(&mut self, val: bool) {
1952 self.0 = (self.0 & !(0x01 << 21usize)) | (((val as u32) & 0x01) << 21usize);
1953 }
1954 #[doc = "Secondary detection enable."]
1955 #[inline(always)]
1956 pub const fn sden(&self) -> bool {
1957 let val = (self.0 >> 22usize) & 0x01;
1958 val != 0
1959 }
1960 #[doc = "Secondary detection enable."]
1961 #[inline(always)]
1962 pub fn set_sden(&mut self, val: bool) {
1963 self.0 = (self.0 & !(0x01 << 22usize)) | (((val as u32) & 0x01) << 22usize);
1964 }
1965 #[doc = "Software override value of the VBUS B-session detection."]
1966 #[inline(always)]
1967 pub const fn vbvaloval(&self) -> bool {
1968 let val = (self.0 >> 23usize) & 0x01;
1969 val != 0
1970 }
1971 #[doc = "Software override value of the VBUS B-session detection."]
1972 #[inline(always)]
1973 pub fn set_vbvaloval(&mut self, val: bool) {
1974 self.0 = (self.0 & !(0x01 << 23usize)) | (((val as u32) & 0x01) << 23usize);
1975 }
1976 #[doc = "Enables a software override of the VBUS B-session detection."]
1977 #[inline(always)]
1978 pub const fn vbvaloven(&self) -> bool {
1979 let val = (self.0 >> 24usize) & 0x01;
1980 val != 0
1981 }
1982 #[doc = "Enables a software override of the VBUS B-session detection."]
1983 #[inline(always)]
1984 pub fn set_vbvaloven(&mut self, val: bool) {
1985 self.0 = (self.0 & !(0x01 << 24usize)) | (((val as u32) & 0x01) << 24usize);
1986 }
1987 #[doc = "Force host mode pull-downs If the ID pin functions are enabled, the host mode pull-downs on DP and DM activate automatically. However, whenever that is not the case, yet host mode is required, this bit must be used to force the pull-downs active."]
1988 #[inline(always)]
1989 pub const fn forcehostpd(&self) -> bool {
1990 let val = (self.0 >> 25usize) & 0x01;
1991 val != 0
1992 }
1993 #[doc = "Force host mode pull-downs If the ID pin functions are enabled, the host mode pull-downs on DP and DM activate automatically. However, whenever that is not the case, yet host mode is required, this bit must be used to force the pull-downs active."]
1994 #[inline(always)]
1995 pub fn set_forcehostpd(&mut self, val: bool) {
1996 self.0 = (self.0 & !(0x01 << 25usize)) | (((val as u32) & 0x01) << 25usize);
1997 }
1998 }
1999 impl Default for GccfgV3 {
2000 #[inline(always)]
2001 fn default() -> GccfgV3 {
2002 GccfgV3(0)
2003 }
2004 }
1834 #[doc = "I2C access register"] 2005 #[doc = "I2C access register"]
1835 #[repr(transparent)] 2006 #[repr(transparent)]
1836 #[derive(Copy, Clone, Eq, PartialEq)] 2007 #[derive(Copy, Clone, Eq, PartialEq)]