aboutsummaryrefslogtreecommitdiffstats
path: root/src-riscv/usb.rs
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2022-10-25 12:20:32 -0400
committerBrian Cully <bjc@kublai.com>2022-10-25 12:20:32 -0400
commit0c4eb964b015961e3c90e45ef498f6c7f89eddba (patch)
treeb0cc3b540e7123b45da044c73d1f47f98ce010ef /src-riscv/usb.rs
parent0f80c612d59c855a99073e583db339fe6a42b883 (diff)
downloadluchie-0c4eb964b015961e3c90e45ef498f6c7f89eddba.tar.gz
luchie-0c4eb964b015961e3c90e45ef498f6c7f89eddba.zip
convert to gd32f303 (stm32f103) bluepill variant
Diffstat (limited to 'src-riscv/usb.rs')
-rwxr-xr-xsrc-riscv/usb.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/src-riscv/usb.rs b/src-riscv/usb.rs
new file mode 100755
index 0000000..1ec36af
--- /dev/null
+++ b/src-riscv/usb.rs
@@ -0,0 +1,42 @@
+use gd32vf103xx_hal::pac;
+use gd32vf103xx_hal::gpio::{Input, Floating, gpioa::{PA11, PA12}};
+use gd32vf103xx_hal::time::Hertz;
+pub use synopsys_usb_otg::UsbBus;
+use synopsys_usb_otg::UsbPeripheral;
+
+#[allow(dead_code)]
+pub struct USB {
+ pub usb_global: pac::USBFS_GLOBAL,
+ pub usb_device: pac::USBFS_DEVICE,
+ pub usb_pwrclk: pac::USBFS_PWRCLK,
+ pub pin_dm: PA11<Input<Floating>>,
+ pub pin_dp: PA12<Input<Floating>>,
+ pub hclk: Hertz,
+}
+
+unsafe impl Sync for USB {}
+
+unsafe impl UsbPeripheral for USB {
+ const REGISTERS: *const () = pac::USBFS_GLOBAL::ptr() as *const ();
+
+ const HIGH_SPEED: bool = false;
+ const FIFO_DEPTH_WORDS: usize = 320;
+ const ENDPOINT_COUNT: usize = 4;
+
+ fn enable() {
+ let rcu = unsafe { &*pac::RCU::ptr() };
+
+ riscv::interrupt::free(|_| {
+ // Enable USB peripheral
+ rcu.ahben.modify(|_, w| w.usbfsen().set_bit());
+
+ // Reset USB peripheral
+ rcu.ahbrst.modify(|_, w| w.usbfsrst().set_bit());
+ rcu.ahbrst.modify(|_, w| w.usbfsrst().clear_bit());
+ });
+ }
+
+ fn ahb_frequency_hz(&self) -> u32 {
+ self.hclk.0
+ }
+}