Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: Fixes for I2S #7117

Closed
wants to merge 58 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
306cf89
Initial support for second I2S - not tested
PilnyTomas Aug 12, 2022
f9af615
Merge branch 'master' into i2s_fix
PilnyTomas Aug 12, 2022
d87aa62
Initial support for 24 bits per second - not tested yet!
PilnyTomas Aug 12, 2022
54e9554
SimpleTone supports all available bitrates
PilnyTomas Aug 15, 2022
481c439
Merge branch 'espressif:master' into i2s_fix
PilnyTomas Sep 21, 2022
db32ea6
Minor changes to fix compilation errors
PilnyTomas Sep 21, 2022
f2fdca7
Remapped pins
PilnyTomas Sep 21, 2022
578e871
Changed default pins
PilnyTomas Sep 27, 2022
b376699
Added notes into README as a guide for propper documentation
PilnyTomas Sep 27, 2022
dc1769e
WIP Backup of documentation update
PilnyTomas Sep 30, 2022
adff9e1
Finished documenting header file + README.md
PilnyTomas Sep 30, 2022
26ac979
Updated pins in examples + removed skip files
PilnyTomas Oct 3, 2022
7a9fd45
Merge branch 'espressif:master' into i2s_fix
PilnyTomas Oct 14, 2022
c7d011e
Added C3 PDM support
PilnyTomas Oct 17, 2022
b02596b
Simplified peek() - NOT tested
PilnyTomas Oct 17, 2022
0f8e9bc
Updated README.md - section describing modes
PilnyTomas Oct 17, 2022
2b04bf8
Revert "Simplified peek() - NOT tested"
PilnyTomas Oct 18, 2022
989817c
Extended mode warning and added mode text array
PilnyTomas Oct 18, 2022
fe268c8
Added new example demonstrating usage of both I2S module (not working…
PilnyTomas Oct 24, 2022
a0ab150
Changed mutex to recursive mutex
PilnyTomas Oct 25, 2022
0b38c9b
Merge branch 'espressif:master' into i2s_fix
PilnyTomas Oct 26, 2022
d7e1228
Added missing initializers to satisfy compilier's warnings
PilnyTomas Oct 27, 2022
e96f5a9
Fix for previous commit - I2S_TDM_ACTIVE_CH
PilnyTomas Oct 27, 2022
8f6613e
First I2S tests
PilnyTomas Oct 27, 2022
5f3542c
Changed default FS pin which was accidentally set on UART TX for C3
PilnyTomas Oct 27, 2022
f67ce84
Added getI2SNum()
PilnyTomas Oct 31, 2022
0719bdc
Added function isInitialized()
PilnyTomas Oct 31, 2022
9721149
Extended begin test for slave mode + added pin setter & getter test
PilnyTomas Oct 31, 2022
2899011
Added & modified buffer functions; Renamed I2S1 to I2S_1
PilnyTomas Nov 3, 2022
d746aa2
Updated DualModule example
PilnyTomas Nov 7, 2022
de30999
Added test
PilnyTomas Nov 11, 2022
53d8f23
Updated default pins
PilnyTomas Nov 11, 2022
a3898e6
Fixed buffer calls in example
PilnyTomas Nov 11, 2022
405723a
Merge branch 'espressif:master' into i2s_fix
PilnyTomas Nov 11, 2022
6ac821e
Added skip files for DualModule example
PilnyTomas Nov 11, 2022
27149b8
Merge branch 'espressif:master' into i2s_fix
PilnyTomas Nov 23, 2022
85b0ea4
Renamed data parameter to sample; removed _buffer_byte_size - now usi…
PilnyTomas Nov 28, 2022
9fa388c
Added MCLK
PilnyTomas Nov 30, 2022
5f779df
Fixed constructor
PilnyTomas Nov 30, 2022
b8dcf69
fixed variable order
PilnyTomas Nov 30, 2022
51a7914
Merge branch 'espressif:master' into i2s_fix
PilnyTomas Dec 1, 2022
70c9e26
Fixed freezing output
PilnyTomas Dec 7, 2022
6aed27f
Separated info message with doc link for each SoC
PilnyTomas Dec 7, 2022
d831f1a
Changed default MCLK pins
PilnyTomas Dec 7, 2022
9761860
Modified MCLK code and doc
PilnyTomas Dec 8, 2022
77a876e
Added note to legacy example
PilnyTomas Dec 8, 2022
653c995
Fixed input
PilnyTomas Dec 8, 2022
83f5372
changed default input pin to match with ADC support
PilnyTomas Dec 9, 2022
94a9169
Merge branch 'espressif:master' into i2s_fix
PilnyTomas Dec 9, 2022
4af7fa3
Fixed DAC
PilnyTomas Dec 15, 2022
4d174af
Added setDMABufferSampleSize function and made few changes in README
PilnyTomas Dec 16, 2022
17caf84
Lowered I2S task priority
PilnyTomas Dec 18, 2022
b12cc18
Merge branch 'espressif:master' into i2s_fix
PilnyTomas Dec 18, 2022
46aee1f
Merge branch 'espressif:master' into i2s_fix
PilnyTomas Dec 27, 2022
d5cde9e
Merge branch 'espressif:master' into i2s_fix
PilnyTomas Jun 23, 2023
3d85853
backup
PilnyTomas Jul 17, 2023
1d85571
work in progress
PilnyTomas Jul 17, 2023
b2d000a
Merge remote-tracking branch 'origin/i2s_fix' into i2s_fix
PilnyTomas Jul 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cores/esp32/esp32-hal-gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode)
extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val)
{
#ifdef RGB_BUILTIN
log_d("RGB_BUILTIN is defined");
if(pin == RGB_BUILTIN){
log_d("and its the target");
//use RMT to set all channels on/off
const uint8_t comm_val = val != 0 ? RGB_BRIGHTNESS : 0;
neopixelWrite(RGB_BUILTIN, comm_val, comm_val, comm_val);
Expand Down
1 change: 1 addition & 0 deletions cores/esp32/esp32-hal-rgb-led.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val){
log_d("light it up to %d", red_val);
rmt_data_t led_data[24];
static rmt_obj_t* rmt_send = NULL;
static bool initialized = false;
Expand Down
2 changes: 1 addition & 1 deletion libraries/BLE/src/BLEAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BLEAddress {
bool operator>(const BLEAddress& otherAddress) const;
bool operator>=(const BLEAddress& otherAddress) const;
esp_bd_addr_t* getNative();
std::string toString();
String toString();

private:
esp_bd_addr_t m_address;
Expand Down
180 changes: 90 additions & 90 deletions libraries/BLE/src/BLEAdvertisedDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,82 +28,82 @@ class BLEScan;
*/
class BLEAdvertisedDevice {
public:
BLEAdvertisedDevice();

BLEAddress getAddress();
uint16_t getAppearance();
std::string getManufacturerData();
std::string getName();
int getRSSI();
BLEScan* getScan();
std::string getServiceData();
std::string getServiceData(int i);
BLEUUID getServiceDataUUID();
BLEUUID getServiceDataUUID(int i);
BLEUUID getServiceUUID();
BLEUUID getServiceUUID(int i);
int getServiceDataCount();
int getServiceDataUUIDCount();
int getServiceUUIDCount();
int8_t getTXPower();
uint8_t* getPayload();
size_t getPayloadLength();
esp_ble_addr_type_t getAddressType();
void setAddressType(esp_ble_addr_type_t type);


bool isAdvertisingService(BLEUUID uuid);
bool haveAppearance();
bool haveManufacturerData();
bool haveName();
bool haveRSSI();
bool haveServiceData();
bool haveServiceUUID();
bool haveTXPower();

std::string toString();
BLEAdvertisedDevice();

BLEAddress getAddress();
uint16_t getAppearance();
std::string getManufacturerData();
std::string getName();
int getRSSI();
BLEScan* getScan();
std::string getServiceData();
std::string getServiceData(int i);
BLEUUID getServiceDataUUID();
BLEUUID getServiceDataUUID(int i);
BLEUUID getServiceUUID();
BLEUUID getServiceUUID(int i);
int getServiceDataCount();
int getServiceDataUUIDCount();
int getServiceUUIDCount();
int8_t getTXPower();
uint8_t* getPayload();
size_t getPayloadLength();
esp_ble_addr_type_t getAddressType();
void setAddressType(esp_ble_addr_type_t type);


bool isAdvertisingService(BLEUUID uuid);
bool haveAppearance();
bool haveManufacturerData();
bool haveName();
bool haveRSSI();
bool haveServiceData();
bool haveServiceUUID();
bool haveTXPower();

std::string toString();

private:
friend class BLEScan;

void parseAdvertisement(uint8_t* payload, size_t total_len=62);
void setPayload(uint8_t* payload, size_t total_len=62);
void setAddress(BLEAddress address);
void setAdFlag(uint8_t adFlag);
void setAdvertizementResult(uint8_t* payload);
void setAppearance(uint16_t appearance);
void setManufacturerData(std::string manufacturerData);
void setName(std::string name);
void setRSSI(int rssi);
void setScan(BLEScan* pScan);
void setServiceData(std::string data);
void setServiceDataUUID(BLEUUID uuid);
void setServiceUUID(const char* serviceUUID);
void setServiceUUID(BLEUUID serviceUUID);
void setTXPower(int8_t txPower);

bool m_haveAppearance;
bool m_haveManufacturerData;
bool m_haveName;
bool m_haveRSSI;
bool m_haveTXPower;


BLEAddress m_address = BLEAddress((uint8_t*)"\0\0\0\0\0\0");
uint8_t m_adFlag;
uint16_t m_appearance;
int m_deviceType;
std::string m_manufacturerData;
std::string m_name;
BLEScan* m_pScan;
int m_rssi;
std::vector<BLEUUID> m_serviceUUIDs;
int8_t m_txPower;
std::vector<std::string> m_serviceData;
std::vector<BLEUUID> m_serviceDataUUIDs;
uint8_t* m_payload;
size_t m_payloadLength = 0;
esp_ble_addr_type_t m_addressType;
friend class BLEScan;

void parseAdvertisement(uint8_t* payload, size_t total_len=62);
void setPayload(uint8_t* payload, size_t total_len=62);
void setAddress(BLEAddress address);
void setAdFlag(uint8_t adFlag);
void setAdvertizementResult(uint8_t* payload);
void setAppearance(uint16_t appearance);
void setManufacturerData(std::string manufacturerData);
void setName(std::string name);
void setRSSI(int rssi);
void setScan(BLEScan* pScan);
void setServiceData(std::string data);
void setServiceDataUUID(BLEUUID uuid);
void setServiceUUID(const char* serviceUUID);
void setServiceUUID(BLEUUID serviceUUID);
void setTXPower(int8_t txPower);

bool m_haveAppearance;
bool m_haveManufacturerData;
bool m_haveName;
bool m_haveRSSI;
bool m_haveTXPower;


BLEAddress m_address = BLEAddress((uint8_t*)"\0\0\0\0\0\0");
uint8_t m_adFlag;
uint16_t m_appearance;
int m_deviceType;
std::string m_manufacturerData;
std::string m_name;
BLEScan* m_pScan;
int m_rssi;
std::vector<BLEUUID> m_serviceUUIDs;
int8_t m_txPower;
std::vector<std::string> m_serviceData;
std::vector<BLEUUID> m_serviceDataUUIDs;
uint8_t* m_payload;
size_t m_payloadLength = 0;
esp_ble_addr_type_t m_addressType;
};

/**
Expand All @@ -115,27 +115,27 @@ class BLEAdvertisedDevice {
*/
class BLEAdvertisedDeviceCallbacks {
public:
virtual ~BLEAdvertisedDeviceCallbacks() {}
/**
* @brief Called when a new scan result is detected.
*
* As we are scanning, we will find new devices. When found, this call back is invoked with a reference to the
* device that was found. During any individual scan, a device will only be detected one time.
*/
virtual void onResult(BLEAdvertisedDevice advertisedDevice) = 0;
virtual ~BLEAdvertisedDeviceCallbacks() {}
/**
* @brief Called when a new scan result is detected.
*
* As we are scanning, we will find new devices. When found, this call back is invoked with a reference to the
* device that was found. During any individual scan, a device will only be detected one time.
*/
virtual void onResult(BLEAdvertisedDevice advertisedDevice) = 0;
};

#ifdef CONFIG_BT_BLE_50_FEATURES_SUPPORTED
class BLEExtAdvertisingCallbacks {
public:
virtual ~BLEExtAdvertisingCallbacks() {}
/**
* @brief Called when a new scan result is detected.
*
* As we are scanning, we will find new devices. When found, this call back is invoked with a reference to the
* device that was found. During any individual scan, a device will only be detected one time.
*/
virtual void onResult(esp_ble_gap_ext_adv_reprot_t report) = 0;
virtual ~BLEExtAdvertisingCallbacks() {}
/**
* @brief Called when a new scan result is detected.
*
* As we are scanning, we will find new devices. When found, this call back is invoked with a reference to the
* device that was found. During any individual scan, a device will only be detected one time.
*/
virtual void onResult(esp_ble_gap_ext_adv_reprot_t report) = 0;
};
#endif // CONFIG_BT_BLE_50_FEATURES_SUPPORTED

Expand Down
1 change: 1 addition & 0 deletions libraries/BLE/src/BLEAdvertising.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ void BLEAdvertisementData::addData(std::string data) {
if ((m_payload.length() + data.length()) > ESP_BLE_ADV_DATA_LEN_MAX) {
return;
}
log_d("Appending 0x%X", data.c_str());
m_payload.append(data);
} // addData

Expand Down
1 change: 1 addition & 0 deletions libraries/BLE/src/BLEBeacon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ int8_t BLEBeacon::getSignalPower() {
* Set the raw data for the beacon record.
*/
void BLEBeacon::setData(std::string data) {
log_d("getting data of length %d", data.length());
if (data.length() != sizeof(m_beaconData)) {
log_e("Unable to set the data ... length passed in was %d and expected %d", data.length(), sizeof(m_beaconData));
return;
Expand Down
38 changes: 29 additions & 9 deletions libraries/BLE/src/BLEEddystoneURL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,26 @@ BLEEddystoneURL::BLEEddystoneURL() {
memset(m_eddystoneData.url, 0, sizeof(m_eddystoneData.url));
} // BLEEddystoneURL

std::string BLEEddystoneURL::getData() {
return std::string((char*) &m_eddystoneData, sizeof(m_eddystoneData));

BLEEddystoneURL(BLEAdvertisedDevice *advertisedDevice){
uint8_t *payLoad = advertisedDevice->getPayload();
beaconUUID = 0xFEAA;
m_eddystoneData.frameType = EDDYSTONE_URL_FRAME_TYPE;
if(payload[11] != 0x10){ // Not Eddystone URL!
log_e("Failed to interpret Advertised Device as Eddystone URL!");
lengthURL = 0;
m_eddystoneData.advertisedTxPower = 0;
memset(m_eddystoneData.url, 0, sizeof(m_eddystoneData.url));
}
lengthURL = payload[7] - 6; // Subtracting 6 Bytes containing header and other data which are not actual URL data
//setData(String((char*)payLoad+11, lengthURL));
m_eddystoneData.advertisedTxPower = payload[12];
log_d("using data from [14]=0x%02X=%c up to [%d]=0x%02X=%c", payload[14], payload[14], lengthURL, payload[14+lengthURL], payload[14+lengthURL]);
memcpy(m_eddystoneData.url, payload[14], lengthURL);
}

String BLEEddystoneURL::getData() {
return String((char*) &m_eddystoneData, sizeof(m_eddystoneData));
} // getData

BLEUUID BLEEddystoneURL::getUUID() {
Expand All @@ -32,13 +50,14 @@ int8_t BLEEddystoneURL::getPower() {
return m_eddystoneData.advertisedTxPower;
} // getPower

std::string BLEEddystoneURL::getURL() {
return std::string((char*) &m_eddystoneData.url, sizeof(m_eddystoneData.url));
String BLEEddystoneURL::getURL() {
return String((char*) &m_eddystoneData.url, sizeof(m_eddystoneData.url));
} // getURL

std::string BLEEddystoneURL::getDecodedURL() {
std::string decodedURL = "";

String BLEEddystoneURL::getDecodedURL() {
String decodedURL = "";
log_d("prefix = m_eddystoneData.url[0] 0x%02X",m_eddystoneData.url[0]);
log_e("prefix type m_eddystoneData.url[0]=%d", m_eddystoneData.url[0]); // this is actually debug
switch (m_eddystoneData.url[0]) {
case 0x00:
decodedURL += "http://www.";
Expand All @@ -60,6 +79,7 @@ std::string BLEEddystoneURL::getDecodedURL() {
if (m_eddystoneData.url[i] > 33 && m_eddystoneData.url[i] < 127) {
decodedURL += m_eddystoneData.url[i];
} else {
log_d("suffix = m_eddystoneData.url[%d] 0x%02X", i, m_eddystoneData.url[i]);
switch (m_eddystoneData.url[i]) {
case 0x00:
decodedURL += ".com/";
Expand Down Expand Up @@ -116,7 +136,7 @@ std::string BLEEddystoneURL::getDecodedURL() {
/**
* Set the raw data for the beacon record.
*/
void BLEEddystoneURL::setData(std::string data) {
void BLEEddystoneURL::setData(String data) {
if (data.length() > sizeof(m_eddystoneData)) {
log_e("Unable to set the data ... length passed in was %d and max expected %d", data.length(), sizeof(m_eddystoneData));
return;
Expand All @@ -134,7 +154,7 @@ void BLEEddystoneURL::setPower(int8_t advertisedTxPower) {
m_eddystoneData.advertisedTxPower = advertisedTxPower;
} // setPower

void BLEEddystoneURL::setURL(std::string url) {
void BLEEddystoneURL::setURL(String url) {
if (url.length() > sizeof(m_eddystoneData.url)) {
log_e("Unable to set the url ... length passed in was %d and max expected %d", url.length(), sizeof(m_eddystoneData.url));
return;
Expand Down
2 changes: 1 addition & 1 deletion libraries/BLE/src/BLEUUID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static void memrcpy(uint8_t* target, uint8_t* source, uint32_t size) {
* @param [in] value The string to build a UUID from.
*/
BLEUUID::BLEUUID(std::string value) {
Serial.printf("BLEUUID string constructor- input=\"%s\"\n", value.c_str());
m_valueSet = true;
if (value.length() == 4) {
m_uuid.len = ESP_UUID_LEN_16;
Expand Down Expand Up @@ -118,7 +119,6 @@ BLEUUID::BLEUUID(std::string value) {
}
} //BLEUUID(std::string)


/**
* @brief Create a UUID from 16 bytes of memory.
*
Expand Down
11 changes: 6 additions & 5 deletions libraries/BLE/src/BLEValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#ifndef COMPONENTS_CPP_UTILS_BLEVALUE_H_
#define COMPONENTS_CPP_UTILS_BLEVALUE_H_
#include <Arduino.h>
#include "sdkconfig.h"
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <string>
Expand All @@ -17,22 +18,22 @@
class BLEValue {
public:
BLEValue();
void addPart(std::string part);
void addPart(String part);
void addPart(uint8_t* pData, size_t length);
void cancel();
void commit();
uint8_t* getData();
size_t getLength();
uint16_t getReadOffset();
std::string getValue();
String getValue();
void setReadOffset(uint16_t readOffset);
void setValue(std::string value);
void setValue(String value);
void setValue(uint8_t* pData, size_t length);

private:
std::string m_accumulation;
String m_accumulation;
uint16_t m_readOffset;
std::string m_value;
String m_value;

};
#endif // CONFIG_BLUEDROID_ENABLED
Expand Down
3 changes: 3 additions & 0 deletions libraries/ESP32/examples/I2S/HiFreq_ADC/HiFreq_ADC.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/*
NOTE: This is a legacy example using IDF I2S driver. There is an I2S library using Arduino API.
You can find it on relative address `../../../../I2S/` or absolute address `arduino-esp32/libraries/I2S/`

This example demonstrates I2S ADC capability to sample high frequency analog signals.
The PWM signal generated with ledc is only for ease of use when first trying out.
To sample the generated signal connect default pins 27(PWM) and 32(Sampling) together.
Expand Down
Loading