Created
May 22, 2024 16:03
-
-
Save urish/8c5ef132a415b5ebb07df29467d64b83 to your computer and use it in GitHub Desktop.
This file contains 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 time | |
import machine | |
from ttboard.demoboard import DemoBoard | |
from ttboard.mode import RPMode | |
from ttboard.pins.pins import Pins | |
import rp2 | |
# We use the PIO as we need to generate a tx_valid pulse of a single clock cycle | |
@rp2.asm_pio(set_init=(rp2.PIO.OUT_LOW)) | |
def pio_tx_valid_pulse(): | |
wrap_target() | |
pull(block) # 0 | |
set(pins, 1) # 1 | |
set(pins, 0) # 2 | |
wrap() | |
def run(): | |
tt = DemoBoard.get() | |
tt.shuttle.tt_um_urish_usb_cdc.enable() | |
tt.mode = RPMode.ASIC_RP_CONTROL | |
machine.freq(96_000_000) | |
tt.clock_project_PWM(48_000_000) # 48 MHz | |
tt.reset_project(True) | |
tt.reset_project(False) | |
tx_valid = tt.bidirs[2] | |
tx_ready = tt.bidirs[3] | |
rx_valid = tt.bidirs[4] | |
rx_ready = tt.bidirs[5] | |
configured = tt.bidirs[7] | |
tx_valid.mode = Pins.OUT | |
rx_ready.mode = Pins.OUT | |
tx_valid_sm = rp2.StateMachine( | |
0, pio_tx_valid_pulse, freq=48_000_000, set_base=tx_valid.raw_pin | |
) | |
tx_valid_sm.active(1) | |
OUTPUT_MESSAGE = "Hello, Tiny Tapeout 4!\r\n" | |
output_index = 0 | |
while True: | |
if not configured.value(): | |
print("Waiting for a USB connection...") | |
while not configured.value(): | |
time.sleep(0.1) | |
print("USB connected! Will print received data.") | |
rx_ready.off() | |
output_index = 0 | |
elif rx_valid.value(): | |
print( | |
"Received byte: ", | |
tt.output_byte, | |
chr(tt.output_byte) if tt.output_byte in range(32, 128) else ".", | |
) | |
rx_ready.on() | |
rx_ready.off() | |
elif tx_ready.value(): | |
tt.input_byte = ord(OUTPUT_MESSAGE[output_index]) | |
output_index = (output_index + 1) % len(OUTPUT_MESSAGE) | |
tx_valid_sm.put(1) # Generate a single clock cycle pulse on tx_valid | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment