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
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
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
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
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
# Set the EN bit to enable the PCM block. | |
mem32[CS_A] = 1 | |
# Set all operational values to define the frame and channel settings. | |
mem32[MODE_A] = 1<<24 | 1<<22 | 1<<20 | 31<<10 | 16 | |
mem32[TXC_A] = 1<<30 | 1<<20 | (16-8)<<16 | 1<<14 | 17<<4 | (16-8) | |
# Assert RXCLR and/or TXCLR wait for 2 PCM clocks to ensure the FIFOs are reset. | |
mem32[CS_A] |= 1<<4 | 1<<3 | |
# The SYNC bit can be used to determine when 2 clocks have passed. | |
mem32[CS_A] |= 1<<24 | |
while (mem32[CS_A] & 1<<24) == 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
# Set TXON and/or RXON to begin operation. | |
mem32[CS_A] |= 1 | |
mem32[CS_A] |= 1<<15 | 1<<16 | |
mem32[CS_A] |= 1<<2 | |
# Poll TXW writing sample words to PCMFIFO and RXR reading sample words from PCMFIFO | |
# until all data is transferred. | |
print("transmit start") | |
while True: | |
while(mem32[CS_A] & (1<<17))==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
from machine import SD | |
import os | |
sd = SD() | |
os.mount(sd, '/sd') | |
os.chdir('/sd') | |
os.listdir() | |
f=open('wtest2.txt','w') | |
f.write("MicroPython!") |
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 SD | |
import os | |
sd = SD() | |
sd.ioctl(1,0) | |
def pr(buf): | |
l=len(buf) | |
c=0 | |
while(c<l): |
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 framebuf | |
import uio | |
HEX="0123456789ABCDEF" | |
class DumpConsole(uio.IOBase): | |
def __init__(self, fb, bgcolor=0, fgcolor=-1, width=-1, height=-1, readobj=None): | |
self.readobj = readobj | |
self.fb = fb | |
if width > 0: |