The T-Watch 2020 sound system
The t-watch has an integrated loudspeaker which is driven by a
MAX9835a PCM Input Class A Audio Power Amplifier. This system allows us to play wav files on the t-watch.
The MAX9835a uses I2S communication invented by Philips in the late 1980 ies for the transfer of digital sound samples. The protocol uses 3 signals:
The MAX9835a is a mono decoder, taking digital sound data (we use 16 bits per sample), converts them to an analogue signals which is amplified and fed into the loudspeaker.
The software
We use the
I2S driver developed by M. Teachman. Unfortunately this driver has not been integrated into the MicroPython sources and a few modifications to the ESP32 port must be made to include it:
- first the driver itself (machine_i2s.c) must be copied to ports/esp32
-
{ MP_ROM_QSTR(MP_QSTR_I2S), MP_ROM_PTR(&machine_i2s_type) },
must be included into
-
STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
in modmachine.c
-
extern const mp_obj_type_t machine_i2s_type;
must be included in modmachine.h
-
machine_i2s.c \
must be added to the C sources SRC_C
in the Makefile in order to compile the module into the MicroPython binary.
With this new MicroPython binary you should be able to
import machine.I2S
Enabling the sound system
In the t-watch the MAX9835a is powered through the AXP202 power manager and the power line to the sound chip must be enabled before using it. Here is the initialization procedure I use:
from machine import Pin,I2S
import ttgo
from axp_constants import AXP202_VBUS_VOL_ADC1,AXP202_VBUS_CUR_ADC1,AXP202_BATT_CUR_ADC1,AXP202_BATT_VOL_ADC1
watch = ttgo.Watch()
watch = watch
tft = watch.tft
power = watch.pmu
power.adc1Enable(AXP202_VBUS_VOL_ADC1
| AXP202_VBUS_CUR_ADC1
| AXP202_BATT_CUR_ADC1
| AXP202_BATT_VOL_ADC1, True)
watch.lvgl_begin()
watch.tft.backlight_fade(100)
print("enable power")
watch.enable_audio_power()
Mike Teachman's example programs with the power initialization added in, have been uploaded to
https://github.com/uraich/twatch2020_firmware/tree/main/hardware/sound.
Before running these however you should create a directory /wav on the ESP32 file system and copy the sound file
https://github.com/miketeachman/micropython-esp32-i2s-examples/blob/master/wav_files/taunt-16k-16bits-mono-12db.wav to this directory.
--
Uli Raich - 2021-01-25
Comments