13#error Only the ESP32 supports ULP audio output
15#include "AudioLogger.h"
18#include <driver/dac.h>
19#include <driver/rtc_io.h>
23#include "soc/rtc_io_reg.h"
73 size_t write(
const uint8_t *data,
size_t len) {
75 int16_t *data_16 = (int16_t *)data;
79 int frames = len / frameSize;
80 for (
int j = 0; j < frames; j++) {
82 stereo[0] = data_16[pos];
83 stereo[1] =
stereoOutput ? data_16[pos + 1] : data_16[pos];
100 const ulp_insn_t stopulp[] = {
105 size_t load_addr = 0;
106 size_t size =
sizeof(stopulp) /
sizeof(ulp_insn_t);
107 ulp_process_macros_and_load(load_addr, stopulp, &size);
113 dac_output_voltage(DAC_CHANNEL_1, 128);
116 dac_output_voltage(DAC_CHANNEL_2, 128);
148 unsigned long rtc_8md256_period = rtc_clk_cal(RTC_CAL_8MD256, 1000);
149 unsigned long rtc_fast_freq_hz =
150 1000000ULL * (1 << RTC_CLK_CAL_FRACT) * 256 / rtc_8md256_period;
154 dac_output_enable(DAC_CHANNEL_1);
155 dac_output_voltage(DAC_CHANNEL_1, 128);
158 dac_output_enable(DAC_CHANNEL_2);
159 dac_output_voltage(DAC_CHANNEL_2, 128);
163 int retAddress2 = 14;
165 int loopCycles = 134;
166 int loopHalfCycles1 = 90;
167 int loopHalfCycles2 = 44;
169 LOGI(
"Real RTC clock: %d", rtc_fast_freq_hz);
171 uint32_t dt = (rtc_fast_freq_hz /
hertz) - loopCycles;
174 dt = (rtc_fast_freq_hz /
hertz) - loopHalfCycles1;
175 dt2 = (rtc_fast_freq_hz /
hertz) - loopHalfCycles2;
179 LOGI(
"dt2: %d", dt2);
181 const ulp_insn_t stereo[] = {
193 I_ANDI(R2, R1, 0x00ff),
204 I_ANDI(R2, R1, 0xff00),
206 I_RSHI(R2, R2, 8 - 1),
222 I_DELAY((
unsigned int)dt + 2),
228 size_t load_addr = 0;
229 size_t size =
sizeof(stereo) /
sizeof(ulp_insn_t);
230 ulp_process_macros_and_load(load_addr, stereo, &size);
238 for (
int i = 0; i < 256; i++) {
240 RTC_IO_PAD_DAC1_REG, 19, 26, i);
244 RTC_IO_PAD_DAC1_REG, 19, 26, i);
250 for (
int i = 0; i < 256; i++) {
252 RTC_IO_PAD_DAC2_REG, 19, 26, i);
256 RTC_IO_PAD_DAC2_REG, 19, 26, i);
262 for (
int i = 0; i < 256; i++) {
264 RTC_IO_PAD_DAC1_REG, 19, 26, i);
268 RTC_IO_PAD_DAC1_REG, 19, 26, i);
299 int currentSample = RTC_SLOW_MEM[
indexAddress] & 0xffff;
300 int currentWord = currentSample >> 1;
302 for (
int i = 0; i < 2; i++) {
303 ms[i] = ((ms[i] >> 8) + 128) & 0xff;
307 (uint16_t)(((uint32_t)((int32_t)(ms[0]) + (int32_t)(ms[1])) >> 1) &
347 const ulp_insn_t singleinstruction[] = {
348 I_WR_REG(reg, low_bit, high_bit, val)};
349 ulp_union recover_ins;
350 recover_ins.ulp_ins = singleinstruction[0];
351 return (uint32_t)(recover_ins.ulp_bin);
359 const ulp_insn_t singleinstruction[] = {I_BXI(imm_pc)};
360 ulp_union recover_ins;
361 recover_ins.ulp_ins = singleinstruction[0];
362 return (uint32_t)(recover_ins.ulp_bin);
#define TRACEI()
Definition AudioLoggerIDF.h:32
#define TRACED()
Definition AudioLoggerIDF.h:31
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define LOGE(...)
Definition AudioLoggerIDF.h:30