You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
fri3d_2026: fix audio
This commit is contained in:
@@ -329,7 +329,6 @@ class WAVStream:
|
||||
|
||||
# Decide playback rate (force >=22050 Hz) - but why?! the DAC should support down to 8kHz!
|
||||
target_rate = 22050 # slower is faster (less data)
|
||||
target_rate = 22050 * 2 # CJC only supports 30kHz and up?
|
||||
if original_rate >= target_rate:
|
||||
playback_rate = original_rate
|
||||
upsample_factor = 1
|
||||
@@ -365,17 +364,29 @@ class WAVStream:
|
||||
print(f"MCLK PWM init failed: {e}")
|
||||
# fallback or error handling
|
||||
|
||||
self._i2s = machine.I2S(
|
||||
0,
|
||||
sck=machine.Pin(self.i2s_pins['sck'], machine.Pin.OUT),
|
||||
ws=machine.Pin(self.i2s_pins['ws'], machine.Pin.OUT),
|
||||
sd=machine.Pin(self.i2s_pins['sd'], machine.Pin.OUT),
|
||||
mode=machine.I2S.TX,
|
||||
bits=16,
|
||||
format=i2s_format,
|
||||
rate=playback_rate,
|
||||
ibuf=32000
|
||||
)
|
||||
if self.i2s_pins.get("sck"):
|
||||
self._i2s = machine.I2S(
|
||||
0,
|
||||
sck=machine.Pin(self.i2s_pins['sck'], machine.Pin.OUT),
|
||||
ws=machine.Pin(self.i2s_pins['ws'], machine.Pin.OUT),
|
||||
sd=machine.Pin(self.i2s_pins['sd'], machine.Pin.OUT),
|
||||
mode=machine.I2S.TX,
|
||||
bits=16,
|
||||
format=i2s_format,
|
||||
rate=playback_rate,
|
||||
ibuf=32000
|
||||
)
|
||||
else:
|
||||
self._i2s = machine.I2S(
|
||||
0,
|
||||
ws=machine.Pin(self.i2s_pins['ws'], machine.Pin.OUT),
|
||||
sd=machine.Pin(self.i2s_pins['sd'], machine.Pin.OUT),
|
||||
mode=machine.I2S.TX,
|
||||
bits=16,
|
||||
format=i2s_format,
|
||||
rate=playback_rate,
|
||||
ibuf=32000
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"WAVStream: I2S init failed: {e}")
|
||||
return
|
||||
|
||||
@@ -198,7 +198,6 @@ mpos.sdcard.init(spi_bus=spi_bus, cs_pin=14)
|
||||
|
||||
# === AUDIO HARDWARE ===
|
||||
from machine import PWM, Pin
|
||||
from mpos import AudioManager
|
||||
|
||||
# Initialize buzzer: now sits on PC14/CC1 of the CH32X035GxUx so needs custom code
|
||||
#buzzer = PWM(Pin(46), freq=550, duty=0)
|
||||
@@ -208,26 +207,18 @@ from mpos import AudioManager
|
||||
# The DAC uses BCK (bit clock) on GPIO 2, while the microphone uses SCLK on GPIO 17
|
||||
# See schematics: DAC has BCK=2, WS=47, SD=16; Microphone has SCLK=17, WS=47, DIN=15
|
||||
|
||||
# This worked briefly, way too loud and with distortion:
|
||||
i2s_pins = {
|
||||
'sck': 2, # SCLK or BCLK (optional)
|
||||
'ws': 47, # Word Select / LRCLK shared between DAC and mic (mandatory)
|
||||
'sd': 16, # Serial Data OUT (speaker/DAC)
|
||||
'sck_in': 17, # SCLK - Serial Clock for microphone input (optional for audio out)
|
||||
}
|
||||
'''
|
||||
# This is how it should be (untested)
|
||||
i2s_pins = {
|
||||
# Output (DAC/speaker) pins
|
||||
'mck': 2, # MCLK (mandatory)
|
||||
#'sck': 17, # SCLK aka BCLK (optional)
|
||||
'sck': 17, # SCLK aka BCLK (optional)
|
||||
'ws': 47, # Word Select / LRCLK shared between DAC and mic (mandatory)
|
||||
'sd': 16, # Serial Data OUT (speaker/DAC)
|
||||
}
|
||||
'''
|
||||
|
||||
# Initialize AudioManager with I2S (buzzer TODO)
|
||||
# ADC microphone is on GPIO 1
|
||||
#AudioManager(i2s_pins=i2s_pins, adc_mic_pin=1)
|
||||
from mpos import AudioManager
|
||||
AudioManager(i2s_pins=i2s_pins, adc_mic_pin=1)
|
||||
|
||||
# === SENSOR HARDWARE ===
|
||||
from mpos import SensorManager
|
||||
|
||||
@@ -132,7 +132,7 @@ def detect_board():
|
||||
|
||||
if i2c0 := fail_save_i2c(sda=10, scl=11):
|
||||
if single_address_i2c_scan(i2c0, 0x20): # IMU
|
||||
return "lilygo_t_watch_s3_plus"
|
||||
return "lilygo_t_watch_s3_plus" # example MAC address: D0:CF:13:33:36:306
|
||||
|
||||
print("Unknown board: couldn't detect known I2C devices or unique_id prefix")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user