X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fcommon%2Fclock.rs;h=86aa3efb884175e399aa4fe9e9269237f6f3c341;hb=1364963a63e0f2ed2c46eebbb7afcd3997258c78;hp=c1bbb10a650c483def00e442870626d4329bd4c0;hpb=4ce1b228434e7b4dfa78f71070e1d063365828eb;p=gps-watch.git diff --git a/src/common/clock.rs b/src/common/clock.rs index c1bbb10..86aa3ef 100644 --- a/src/common/clock.rs +++ b/src/common/clock.rs @@ -28,8 +28,19 @@ type Reg32 = register::Register; const SIM_BASE: u32 = 0x40047000; +const SIM_SOPT1: u32 = SIM_BASE + 0x0000; +const SIM_SOPT2: u32 = SIM_BASE + 0x1004; + +const SIM_SCGC4: u32 = SIM_BASE + 0x1034; const SIM_CLKDIV1: u32 = SIM_BASE + 0x1044; +const SIM_SOPT1_USBREGEN: u32 = 1 << 31; + +const SIM_SOPT2_PLLFLLSEL: u32 = 1 << 16; +const SIM_SOPT2_USBSRC: u32 = 1 << 18; + +const SIM_SCGC4_USBOTG: u32 = 1 << 18; + const SIM_CLKDIV1_OUTDIV4_SHIFT: u32 = 16; const SIM_CLKDIV1_OUTDIV1_SHIFT: u32 = 28; @@ -145,4 +156,23 @@ pub unsafe fn configure() { switch_to_fbe(); switch_to_pbe(); switch_to_pee(); + + let mut sopt2 = Reg32::new(SIM_SOPT2); + + sopt2.modify(|v| { + v | SIM_SOPT2_PLLFLLSEL + }); +} + +pub unsafe fn configure_usb() { + let mut scgc4 = Reg32::new(SIM_SCGC4); + scgc4.modify(|v| v & !SIM_SCGC4_USBOTG); + + let mut sopt1 = Reg32::new(SIM_SOPT1); + sopt1.modify(|v| v | SIM_SOPT1_USBREGEN); + + let mut sopt2 = Reg32::new(SIM_SOPT2); + sopt2.modify(|v| v | SIM_SOPT2_USBSRC); + + scgc4.modify(|v| v | SIM_SCGC4_USBOTG); }