Prep ESP32S2

This commit is contained in:
Theo Arends 2021-02-03 14:12:43 +01:00
parent cd38179f7f
commit 5caaf60c68
4 changed files with 23 additions and 9 deletions

View File

@ -38,7 +38,11 @@ TasmotaSerial *tms_obj_list[16];
#endif // ESP8266
#ifdef ESP32
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
static int tasmota_serial_index = 2; // Allow UART2 and UART1 only
#elif CONFIG_IDF_TARGET_ESP32S2 // ESP32-S2
static int tasmota_serial_index = 1; // Allow UART1 only
#endif
#endif // ESP32

View File

@ -1,7 +1,7 @@
/*
AudioOutputI2S
Base class for I2S interface port
Copyright (C) 2017 Earle F. Philhower, III
This program is free software: you can redistribute it and/or modify
@ -48,11 +48,13 @@ AudioOutputI2S::AudioOutputI2S(int port, int output_mode, int dma_buf_count, int
}
i2s_mode_t mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX);
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
if (output_mode == INTERNAL_DAC) {
mode = (i2s_mode_t)(mode | I2S_MODE_DAC_BUILT_IN);
} else if (output_mode == INTERNAL_PDM) {
mode = (i2s_mode_t)(mode | I2S_MODE_PDM);
}
#endif
i2s_comm_format_t comm_fmt = (i2s_comm_format_t)(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB);
if (output_mode == INTERNAL_DAC) {
@ -81,7 +83,7 @@ AudioOutputI2S::AudioOutputI2S(int port, int output_mode, int dma_buf_count, int
SetPinout(26, 25, 22);
}
i2s_zero_dma_buffer((i2s_port_t)portNo);
}
}
#else
(void) dma_buf_count;
(void) use_apll;
@ -138,7 +140,7 @@ bool AudioOutputI2S::SetRate(int hz)
// TODO - have a list of allowable rates from constructor, check them
this->hertz = hz;
#ifdef ESP32
i2s_set_sample_rates((i2s_port_t)portNo, AdjustI2SRate(hz));
i2s_set_sample_rates((i2s_port_t)portNo, AdjustI2SRate(hz));
#else
i2s_set_rate(AdjustI2SRate(hz));
#endif
@ -192,7 +194,11 @@ bool AudioOutputI2S::ConsumeSample(int16_t sample[2])
} else {
s32 = ((Amplify(ms[RIGHTCHANNEL]))<<16) | (Amplify(ms[LEFTCHANNEL]) & 0xffff);
}
return i2s_write_bytes((i2s_port_t)portNo, (const char*)&s32, sizeof(uint32_t), 0);
// Deprecated. Use i2s_write
// return i2s_write_bytes((i2s_port_t)portNo, (const char*)&s32, sizeof(uint32_t), 0);
size_t bytes_written;
return (ESP_OK == i2s_write((i2s_port_t)portNo, (const char*)&s32, sizeof(uint32_t), &bytes_written, 0));
// return bytes_written;
#else
uint32_t s32 = ((Amplify(ms[RIGHTCHANNEL]))<<16) | (Amplify(ms[LEFTCHANNEL]) & 0xffff);
return i2s_write_sample_nb(s32); // If we can't store it, return false. OTW true

View File

@ -1,7 +1,7 @@
/*
AudioOutputI2SNoDAC
Audio player using SW delta-sigma to generate "analog" on I2S data
Copyright (C) 2017 Earle F. Philhower, III
This program is free software: you can redistribute it and/or modify
@ -66,7 +66,7 @@ void AudioOutputI2SNoDAC::DeltaSigma(int16_t sample[2], uint32_t dsBuff[8])
for (int j = 0; j < oversample32; j++) {
uint32_t bits = 0; // The bits we convert the sample into, MSB to go on the wire first
for (int i = 32; i > 0; i--) {
bits = bits << 1;
if (cumErr < 0) {
@ -95,9 +95,13 @@ bool AudioOutputI2SNoDAC::ConsumeSample(int16_t sample[2])
// Either send complete pulse stream or nothing
#ifdef ESP32
if (!i2s_write_bytes((i2s_port_t)portNo, (const char *)dsBuff, sizeof(uint32_t) * (oversample/32), 0))
// Deprecated. Use i2s_write
// if (!i2s_write_bytes((i2s_port_t)portNo, (const char *)dsBuff, sizeof(uint32_t) * (oversample/32), 0))
size_t bytes_written;
if (ESP_OK != i2s_write((i2s_port_t)portNo, (const char *)dsBuff, sizeof(uint32_t) * (oversample/32), &bytes_written, 0))
return false;
#else
#else
if (!i2s_write_sample_nb(dsBuff[0])) return false; // No room at the inn
// At this point we've sent in first of possibly 8 32-bits, need to send
// remaining ones even if they block.

View File

@ -15,7 +15,7 @@
*/
//
#include "Arduino.h"
#include "lwip/apps/sntp.h"
//#include "lwip/apps/sntp.h"
#include <nvs.h>
// See libraries\ESP32\examples\ResetReason.ino