Created
October 6, 2018 15:41
-
-
Save boochow/2ecd6a538f65075a76a15223e0018d24 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mcu import mem32 | |
# PWM clock manager | |
CLK_GND = const(0) | |
CLK_OSC = const(1) | |
CLK_PLLA = const(4) | |
CLK_PLLC = const(5) | |
CLK_PLLD = const(6) | |
CLK_HDMI = const(7) | |
def set_CM_CTL(reg): | |
mem32[0x201010a0] = 0x5a000000 | reg | |
def set_CM_DIV(divi, divf=0): | |
mem32[0x201010a4] = 0x5a000000 | (divi << 12) | divf | |
def PWM_clock_config(src, divi, divf=0, mash=1): | |
set_CM_CTL(mem32[0x201010a0] & 0xffef) # disable clock | |
while mem32[0x201010a0] & 0x0080: # wait for the end of clock | |
pass | |
set_CM_CTL(src | ((mash & 3) << 9)) # set clock source and mash | |
set_CM_DIV(divi, divf) | |
set_CM_CTL(mem32[0x201010a0] | (1<<4)) # enable clock |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment