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 | |
from machine import Pin,Clock | |
# GPIO alternate functions | |
ALT0 = const(4) | |
def set_PCM_pin(): | |
for pin in (18, 19, 20, 21): | |
reg = 0x20200000 + 4 * (pin // 10) | |
bit = (pin % 10) * 3 |
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 machine import * | |
def test(): | |
saw = [] | |
sqw = [] | |
tri = [] | |
for i in range(64): | |
saw.append(i*4) | |
sqw.append(255 if i < 32 else 0) | |
tri.append(abs(i - 32)*8) | |
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
def test2(): | |
saw = [] | |
sqw = [] | |
tri = [] | |
for i in range(64): | |
saw.append(i*4) | |
sqw.append(255 if i < 32 else 0) | |
tri.append(abs(i - 32)*8) | |
p=PWM(0, pin=18, ms=MS_DISABLE, use_fifo=1, fifo_repeat=0) |
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
def fifo_write(self, buf): | |
for b in buf: | |
while (mem32[0x2020c004] & 1): | |
pass | |
mem32[0x2020c018] = b |
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 time import sleep_ms | |
from machine import PWM | |
def test(): | |
p=PWM(pin=18) | |
while True: | |
for i in range(p.range() // 2): | |
p.data(i) | |
sleep_ms(1) | |
for i in range(p.range() // 2 - 1, 0, -1): | |
p.data(i) |
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 time import sleep_ms | |
def test(): | |
p=PWM(0, pin=18, ms=MS_ENABLE) | |
p.freq(1000) | |
p.range(DEFAULT_RANGE) | |
while True: | |
for i in range(DEFAULT_RANGE // 2): | |
p.data(i) | |
sleep_ms(1) | |
for i in range(DEFAULT_RANGE // 2 - 1, 0, -1): |
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
# Hardware PWM | |
MS_DISABLE = const(0) | |
MS_ENABLE = const(1) | |
MODE_PWM = const(0) | |
MODE_SERIALIZER = const(1) | |
DEFAULT_RANGE = const(960) | |
class PWM: |
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(): |
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) |
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
import gpu | |
import framebuf | |
import FBConsole | |
class RPiScreen(framebuf.FrameBuffer): | |
def __init__(self, width, height): | |
self.width = width | |
self.height = height | |
gpu.fb_init(width,height,screen_w=1920,screen_h=1080) | |
super().__init__(gpu.fb_data(),width,height,framebuf.RGB565) |