13 # error "Wrong implementation included for this platform"
18 #if MOZZI_IS(MOZZI_ANALOG_READ, MOZZI_ANALOG_READ_STANDARD)
19 #error not yet implemented
21 #define getADCReading() 0
22 #define channelNumToIndex(channel) channel
40 #if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_INTERNAL_DAC) || MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_I2S_DAC) || MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_PDM_VIA_I2S)
42 # include <driver/i2s.h>
50 # if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_INTERNAL_DAC)
52 # define ESP_SAMPLE_SIZE (2
*sizeof(uint16_t))
53 # elif MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_I2S_DAC)
55 # define ESP_SAMPLE_SIZE (2
*sizeof(int16_t))
56 # elif MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_PDM_VIA_I2S)
58 # define ESP_SAMPLE_SIZE (PDM_RESOLUTION*sizeof(uint32_t))
74 # if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_INTERNAL_DAC)
76 # if (MOZZI_AUDIO_CHANNELS > 1
)
82 # elif MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_PDM_VIA_I2S)
95 #if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_EXTERNAL_TIMED)
98 # include <driver/timer.h>
108 static void startAudio() {
109 #if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_EXTERNAL_TIMED)
110 static intr_handle_t s_timer_handle;
112 timer_config_t config = {
113 .alarm_en = (timer_alarm_t)
true,
114 .counter_en = (timer_start_t)
false,
115 .intr_type = (timer_intr_mode_t) TIMER_INTR_LEVEL,
116 .counter_dir = TIMER_COUNT_UP,
117 .auto_reload = (timer_autoreload_t)
true,
121 timer_init(TIMER_GROUP_0, TIMER_0, &config);
122 timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0);
123 timer_set_alarm_value(TIMER_GROUP_0, TIMER_0, 80000000UL / MOZZI_AUDIO_RATE / div);
124 timer_enable_intr(TIMER_GROUP_0, TIMER_0);
125 timer_isr_register(TIMER_GROUP_0, TIMER_0, &timer0_audio_output_isr,
nullptr, 0, &s_timer_handle);
126 timer_start(TIMER_GROUP_0, TIMER_0);
128 #elif !MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_EXTERNAL_CUSTOM)
129 static const i2s_config_t i2s_config = {
130 # if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_I2S_DAC) || MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_PDM_VIA_I2S)
131 .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX),
132 # elif MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_INTERNAL_DAC)
133 .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN),
135 .sample_rate = MOZZI_AUDIO_RATE * MOZZI_PDM_RESOLUTION,
136 .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
137 .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
138 .communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_LSB),
139 .intr_alloc_flags = 0,
145 i2s_driver_install(i2s_num, &i2s_config, 0, NULL);
146 # if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_I2S_DAC) || MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_PDM_VIA_I2S)
147 static const i2s_pin_config_t pin_config = {
148 .bck_io_num = MOZZI_I2S_PIN_BCK,
149 .ws_io_num = MOZZI_I2S_PIN_WS,
150 .data_out_num = MOZZI_I2S_PIN_DATA,
153 i2s_set_pin((i2s_port_t)i2s_num, &pin_config);
154 # elif MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_INTERNAL_DAC)
155 i2s_set_pin((i2s_port_t)i2s_num, NULL);
156 i2s_set_dac_mode(I2S_DAC_CHANNEL_BOTH_EN);
158 i2s_zero_dma_buffer((i2s_port_t)i2s_num);
176 #undef ESP_SAMPLE_SIZE