From d24cddb46eb770eb98ffc3ae2bae2b4de4b9d253 Mon Sep 17 00:00:00 2001 From: Pat Deegan Date: Sun, 28 Apr 2024 14:03:50 -0400 Subject: [PATCH] Adding some example SDK interaction with projects --- src/config.ini | 4 ++- src/examples/__init__.py | 0 src/examples/neptune.py | 72 ++++++++++++++++++++++++++++++++++++++++ src/ttboard/__init__.py | 2 +- 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 src/examples/__init__.py create mode 100644 src/examples/neptune.py diff --git a/src/config.ini b/src/config.ini index e05e869..19033d8 100644 --- a/src/config.ini +++ b/src/config.ini @@ -29,8 +29,10 @@ mode = ASIC_RP_CONTROL # - INFO # - WARN # - ERROR -log_level = WARN +log_level = INFO + +# default RP2040 system clock rp_clock_frequency = 125e6 #### PROJECT OVERRIDES #### diff --git a/src/examples/__init__.py b/src/examples/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/examples/neptune.py b/src/examples/neptune.py new file mode 100644 index 0000000..3c289f9 --- /dev/null +++ b/src/examples/neptune.py @@ -0,0 +1,72 @@ +''' +Created on Apr 28, 2024 + +@author: Pat Deegan +@copyright: Copyright (C) 2024 Pat Deegan, https://psychogenic.com +''' + +from ttboard.demoboard import DemoBoard +from ttboard.mode import RPMode +from ttboard.pins.pins import Pins + +import ttboard.logging as logging +log = logging.getLogger(__name__) + +import ttboard.util.time as time + + +def die_on_error(msg:str): + log.error(msg) + return False + +def run(tt:DemoBoard, loops:int=2, note_delay_ms:int=2000): + + if not tt.shuttle.has('tt_um_psychogenic_neptuneproportional'): + return die_on_error("This chip doesn't got neptune on-board!") + + if tt.user_config.has_section('tt_um_psychogenic_neptuneproportional'): + log.info('Found a neptune section in config--letting it handle things') + else: + log.info('No neptune section in config--doing it manual style') + tt.mode = RPMode.ASIC_RP_CONTROL + tt.reset_project(True) # hold in reset, in case something else is loaded + # input byte + # clock speed is lower bits, input comes on in5 + # display mode single/control are bits 6 and 7 + tt.input_byte = 0b11001000 + tt.clock_project_PWM(4000) + tt.bidir_mode = [Pins.IN]*8 + + tt.shuttle.tt_um_psychogenic_neptuneproportional.enable() + tt.reset_project(False) # start her up + + notes = [ + ('E2', 83), + ('A2', 110), + ('D3', 146), + ('E3', 83*2), + ('G3', 196), + ('A3', 220), + ('B3', 247), + ('D4', 146*2), + ('E4', 330), + ('G4', 196*2), + ] + + pwm = tt.in5.pwm(10) + for _i in range(loops): + for n in notes: + pwm.freq(n[1]) + print(f'"Playing" a note: {n[0]} ({n[1]}Hz)') + for _j in range(3): + time.sleep_ms(int(note_delay_ms/3)) + reported_count = tt.bidir_byte + ratio = n[1]/reported_count + print(f' Bidir count: {reported_count} (ratio {ratio:.1f}), Outputs {hex(tt.output_byte)}') + + + + pwm.deinit() # shut that down + tt.in5(0) # bring low + + \ No newline at end of file diff --git a/src/ttboard/__init__.py b/src/ttboard/__init__.py index c69af0d..f8b7877 100644 --- a/src/ttboard/__init__.py +++ b/src/ttboard/__init__.py @@ -6,4 +6,4 @@ @author: Pat Deegan @copyright: Copyright (C) 2024 Pat Deegan, https://psychogenic.com ''' -VERSION='0.9.11' +VERSION='0.9.15'