Skip to content

Commit 96f04e4

Browse files
Merge pull request #8 from RetiredWizard
PyDOS updates and board generalizations
2 parents 85aa892 + 520deb9 commit 96f04e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1976
-1854
lines changed

PyBasic/basicparser.py

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,28 @@
2525
from pydos_ui import input
2626
except:
2727
pass
28+
try:
29+
from pydos_hw import Pydos_hw
30+
except:
31+
Pydos_hw.sndPin = None
32+
2833
if implementation.name.upper() == 'MICROPYTHON':
29-
from machine import Pin, PWM
34+
if Pydos_hw.sndPin:
35+
from machine import PWM
3036
from time import ticks_ms as monotonic
37+
3138
elif implementation.name.upper() == 'CIRCUITPYTHON':
3239
from time import monotonic
3340
from board import board_id
34-
if board_id != 'raspberrypi_zero2w': # temporary? until broadcom port supports pwmio
35-
from pwmio import PWMOut
36-
if board_id == "arduino_nano_rp2040_connect":
37-
#A5 is GPIO D19 on Nano Connect
38-
from board import A5 as sndPin
39-
elif board_id == "raspberry_pi_pico":
40-
#D12 is GP11 on the Raspberry PICO
41-
from board import GP11 as sndPin
42-
elif board_id == "cytron_maker_pi_rp2040":
43-
from board import GP22 as sndPin
44-
else:
45-
try:
46-
#Use D12 on Feathers
47-
from board import D12 as sndPin
48-
except:
49-
pass
41+
if Pydos_hw.sndPin:
42+
if board_id != 'raspberrypi_zero2w': # temporary? until broadcom port supports pwmio
43+
from pwmio import PWMOut
5044
else:
5145
import winsound
5246
from time import monotonic
47+
5348
import gc
5449
gc.collect()
55-
#if implementation.name.upper() == 'MICROPYTHON':
56-
#gc.threshold(gc.mem_free() // 4 + gc.mem_alloc())
5750

5851
"""Implements a BASIC array, which may have up
5952
to three dimensions of fixed size.
@@ -129,10 +122,11 @@ def __init__(self):
129122
self.__file_handles = {}
130123

131124
if implementation.name.upper() == 'MICROPYTHON':
132-
try:
133-
self.__pwm = PWM(Pin(19),freq=0)
134-
except:
135-
self.__pwm = PWM(Pin(19))
125+
if Pydos_hw.sndPin:
126+
try:
127+
self.__pwm = PWM(Pydos_hw.sndPin,freq=0)
128+
except:
129+
self.__pwm = PWM(Pydos_hw.sndPin)
136130

137131
def parse(self, tokenlist, line_number, cstmt_number, infile, tmpfile, datastmts):
138132
"""Must be initialised with the list of
@@ -894,23 +888,26 @@ def __soundstmt(self):
894888
volume = 800
895889

896890
if implementation.name.upper() == 'MICROPYTHON':
897-
self.__pwm.freq(freq)
898-
if "duty_u16" in dir(self.__pwm):
899-
self.__pwm.duty_u16(volume)
900-
sleep(duration/18.2)
901-
self.__pwm.duty_u16(0)
902-
else:
903-
self.__pwm.duty(int((volume/65535)*1023))
904-
sleep(duration/18.2)
905-
self.__pwm.duty(0)
891+
if Pydos_hw.sndPin:
892+
self.__pwm.freq(freq)
893+
if "duty_u16" in dir(self.__pwm):
894+
self.__pwm.duty_u16(volume)
895+
sleep(duration/18.2)
896+
self.__pwm.duty_u16(0)
897+
else:
898+
self.__pwm.duty(int((volume/65535)*1023))
899+
sleep(duration/18.2)
900+
self.__pwm.duty(0)
906901
elif implementation.name.upper() == 'CIRCUITPYTHON':
907902
try:
908-
audioPin = PWMOut(sndPin, duty_cycle=0, frequency=440, variable_frequency=True)
903+
Pydos_hw.sndGPIO.deinit() # Workaround for ESP32-S2 GPIO issue
904+
audioPin = PWMOut(Pydos_hw.sndPin, duty_cycle=0, frequency=440, variable_frequency=True)
909905
audioPin.frequency = freq
910906
audioPin.duty_cycle = volume
911907
sleep(duration/18.2)
912908
audioPin.duty_cycle = 0
913909
audioPin.deinit()
910+
Pydos_hw.quietSnd() # Workaround for ESP32-S2 GPIO issue
914911
except:
915912
pass
916913
else:

0 commit comments

Comments
 (0)