Last active
October 8, 2018 00:51
-
-
Save boochow/10b29262b16a226367ddac259025c2dd 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
# GPIO alternate functions | |
ALT0 = const(4) | |
ALT1 = const(5) | |
ALT5 = const(2) | |
Pin_AF_PWM = {12:(ALT0,0), 13:(ALT0,1), 18:(ALT5,0), 19:(ALT5,1), \ | |
40:(ALT0,0), 41:(ALT0,1), 45:(ALT0,1), 52:(ALT1,0), 53:(ALT1,1)} | |
def select_PWM_pin(pin): | |
if pin in Pin_AF_PWM.keys(): | |
af, pwm = Pin_AF_PWM[pin] | |
reg = 0x20200000 + 4 * (pin // 10) | |
bit = (pin % 10) * 3 | |
mem32[reg] = (mem32[reg] & ~(7 << bit)) | af << bit | |
return pwm | |
else: | |
return -1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment