-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from Krupskis/esp32
Add ESP32
- Loading branch information
Showing
24 changed files
with
5,105 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,4 +68,6 @@ _site/ | |
.bundle/ | ||
vendor/ | ||
|
||
venv/ | ||
venv/ | ||
|
||
**/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "devices/coralai/coralmicro"] | ||
path = devices/coralai/coralmicro | ||
url = https://github.com/google-coral/coralmicro | ||
[submodule "devices/esp32-c3/components/arduino"] | ||
path = devices/esp32-c3/components/arduino | ||
url = https://github.com/espressif/arduino-esp32.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# The following lines of boilerplate have to be in your project's | ||
# CMakeLists in this exact order for cmake to work correctly | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
project(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
### [Click Here For Setup Guide](https://docs.adeus.ai/guides/esp32-c3.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
dependencies: | ||
chmorgan/esp-libhelix-mp3: | ||
component_hash: cbb76089dc2c5749f7b470e2e70aedc44c9da519e04eb9a67d4c7ec275229e53 | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
type: service | ||
version: 1.0.3 | ||
espressif/cbor: | ||
component_hash: 440f4ee4504841cc9b4f3a8ef755776a612ac9dace355514c68b999868f990ff | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
type: service | ||
version: 0.6.0~1 | ||
espressif/esp-dsp: | ||
component_hash: 46498b4973097cac29cfc6a692abef44375ffb7b00b73b3f354124efc626a154 | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
type: service | ||
version: 1.4.10 | ||
espressif/esp-zboss-lib: | ||
component_hash: a9e17babb2d43edc4bb6bc320f88560860122ac97e8fd72d7d5d9b3cd1578607 | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
type: service | ||
version: 1.1.1 | ||
espressif/esp-zigbee-lib: | ||
component_hash: a1a23f47316d2d44b1573459c8cf547da7f2c8ea987154ad8d28235db69f1481 | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
type: service | ||
version: 1.1.1 | ||
espressif/esp_diag_data_store: | ||
component_hash: 8849195251dbb8a2d7268335277cfa310cef36e4ac1e90cd59ad3be4269a30d7 | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
type: service | ||
version: 1.0.1 | ||
espressif/esp_diagnostics: | ||
component_hash: fe19f5ee7f0145f406d36a4d5310e4ae0c6ee1afa47f2681ada8a2ea8582d390 | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
type: service | ||
version: 1.0.2 | ||
espressif/esp_insights: | ||
component_hash: 2472a19de98a8b991baeeac7209765b70ce14ec2b1435dbed3abd020dd0f7227 | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
type: service | ||
version: 1.0.1 | ||
espressif/esp_rainmaker: | ||
component_hash: 232425d1c9b9dbdaa5c109b3e359fba0e6956e35fcf22725f07ed7e4389e1191 | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
type: service | ||
version: 1.1.0 | ||
espressif/esp_schedule: | ||
component_hash: 2cbc7e2584f523d10fbfb4ecb7d25c07fa7d7757ab23d7a127494b1a58131ffe | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
type: service | ||
version: 1.1.0 | ||
espressif/esp_secure_cert_mgr: | ||
component_hash: a20007d67e65a000670ab77e45d7554c943eb8dcb0abeada0a57dd9adac3a703 | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
type: service | ||
version: 2.4.1 | ||
espressif/jsmn: | ||
component_hash: d80350c41bbaa827c98a25b6072df00884e72f54885996fab4a4f0aebce6b6c3 | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
type: service | ||
version: 1.1.0 | ||
espressif/json_generator: | ||
component_hash: 45033e1c199b13f1c8c1b544fb7d4e2df6a8e3071ebdcb1b22582b61a7974ff2 | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
type: service | ||
version: 1.1.2 | ||
espressif/json_parser: | ||
component_hash: d74b81729ad06ec11ff5eb5b1b0d7df1d00e6027fc11471f4b139c70dcf1b1e4 | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
type: service | ||
version: 1.0.3 | ||
espressif/mdns: | ||
component_hash: d6665090cf41eb399c184aab6f34234251a773e052fb53ca044dcb576264c646 | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
type: service | ||
version: 1.2.1 | ||
espressif/qrcode: | ||
component_hash: 3b493771bc5d6ad30cbf87c25bf784aada8a08c941504355b55d6b75518ed7bc | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
type: service | ||
version: 0.1.0~2 | ||
espressif/rmaker_common: | ||
component_hash: 021c02465e4996dd3292db36ea47b5e3122e7e2d3514797735a96bc12598b44f | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
type: service | ||
version: 1.4.5 | ||
idf: | ||
component_hash: null | ||
source: | ||
type: idf | ||
version: 5.1.2 | ||
joltwallet/littlefs: | ||
component_hash: 03a21848de65d85a1f914dd6fb9dea5e75e794989d70d185a007e27c3046bb92 | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
type: service | ||
version: 1.14.1 | ||
manifest_hash: 84a72f99bd35e36c30205cb29810146868a5d1ed843e9421c3418bc6781b1981 | ||
target: esp32c3 | ||
version: 1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include "Server.h" | ||
#include <BLEDevice.h> | ||
#include <BLEUtils.h> | ||
#include <BLEServer.h> | ||
#include <Arduino.h> | ||
|
||
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" | ||
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" | ||
|
||
static bool s_is_connected = false; | ||
|
||
|
||
class ServerHandler: public BLEServerCallbacks { | ||
void onConnect(BLEServer* pServer) { | ||
s_is_connected = true; | ||
Serial.println("Connected"); | ||
} | ||
|
||
void onDisconnect(BLEServer* pServer) { | ||
s_is_connected = false; | ||
Serial.println("Disconnected"); | ||
BLEDevice::startAdvertising(); | ||
} | ||
}; | ||
|
||
BluetoothServer::BluetoothServer() {} | ||
|
||
void BluetoothServer::startAdvertising() | ||
{ | ||
|
||
Serial.println("Starting BLE Server"); | ||
BLEDevice::init("ESP32"); | ||
BLEDevice::setMTU(185); | ||
pServer = BLEDevice::createServer(); | ||
pServer->setCallbacks(new ServerHandler()); | ||
pService = pServer->createService(SERVICE_UUID); | ||
audioCharacteristic = pService->createCharacteristic( | ||
CHARACTERISTIC_UUID, | ||
BLECharacteristic::PROPERTY_READ | | ||
BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_NOTIFY); | ||
|
||
|
||
|
||
audioCharacteristic->setValue("ESP32Hello World says ESP32Hello World"); | ||
pService->start(); | ||
|
||
|
||
// BLEAdvertising *pAdvertising = pServer->getAdvertising(); // this still is working for backward compatibility | ||
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising(); | ||
pAdvertising->addServiceUUID(SERVICE_UUID); | ||
pAdvertising->setScanResponse(true); | ||
pAdvertising->setMinPreferred(0x06); | ||
pAdvertising->setMinPreferred(0x12); | ||
pAdvertising->setMinInterval(0x20); | ||
pAdvertising->setMaxInterval(0x40); | ||
BLEDevice::startAdvertising(); | ||
Serial.printf("MTU size: %d bytes\n", BLEDevice::getMTU()); | ||
} | ||
|
||
void BluetoothServer::setValue(uint8_t *value, size_t len) | ||
{ | ||
if (!s_is_connected) { | ||
delay(50); // Wait for a connection | ||
return; | ||
} | ||
|
||
audioCharacteristic->setValue(value, len); | ||
audioCharacteristic->notify(); | ||
delay(4); | ||
|
||
delay(4); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef BLESERVER_H | ||
#define BLESERVER_H | ||
|
||
#include <Arduino.h> | ||
#include <BLEDevice.h> | ||
#include <BLEUtils.h> | ||
#include <BLEServer.h> | ||
|
||
class BluetoothServer | ||
{ | ||
private: | ||
BLEServer *pServer; | ||
BLEService *pService; | ||
BLECharacteristic *audioCharacteristic; | ||
|
||
public: | ||
BluetoothServer(); | ||
void startAdvertising(); | ||
void setValue(uint8_t *value, size_t len); | ||
}; | ||
#endif // BLESERVER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
idf_component_register(SRCS "main.cpp" | ||
"BLE/server.cpp" | ||
INCLUDE_DIRS "." REQUIRES bt PRIV_REQUIRES arduino) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include <Arduino.h> | ||
#include "BLE/Server.h" | ||
#include "esp_log.h" | ||
#include <driver/i2s.h> | ||
|
||
BluetoothServer BLEServer; | ||
|
||
// you shouldn't need to change these settings | ||
#define BUFFER_SIZE 182 | ||
#define SAMPLE_RATE 8000 | ||
// most microphones will probably default to left channel but you may need to tie the L/R pin low | ||
#define I2S_MIC_CHANNEL I2S_CHANNEL_FMT_ONLY_LEFT | ||
// either wire your microphone to the same pins or change these to match your wiring | ||
#define I2S_MIC_SERIAL_CLOCK 3 // bck, bclk, sclk | ||
#define I2S_MIC_LEFT_RIGHT_CLOCK 2 // ws, lrclk, fs | ||
#define I2S_MIC_SERIAL_DATA 4 // sd | ||
|
||
i2s_config_t i2s_config = { | ||
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX), | ||
.sample_rate = SAMPLE_RATE, | ||
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, | ||
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, | ||
.communication_format = I2S_COMM_FORMAT_I2S, | ||
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, | ||
.dma_buf_count = 4, | ||
.dma_buf_len = 1024, | ||
.use_apll = false, | ||
.tx_desc_auto_clear = false, | ||
.fixed_mclk = 0}; | ||
|
||
i2s_pin_config_t i2s_mic_pins = { | ||
.bck_io_num = I2S_MIC_SERIAL_CLOCK, | ||
.ws_io_num = I2S_MIC_LEFT_RIGHT_CLOCK, | ||
.data_out_num = I2S_PIN_NO_CHANGE, | ||
.data_in_num = I2S_MIC_SERIAL_DATA}; | ||
|
||
void setup() | ||
{ | ||
ESP_LOGW("LOG", "Starting BLE Server"); | ||
BLEServer.startAdvertising(); | ||
ESP_LOGW("LOG", "BLE Server started"); | ||
|
||
// start up the I2S peripheral | ||
i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL); | ||
i2s_set_pin(I2S_NUM_0, &i2s_mic_pins); | ||
ESP_LOGW("LOG", "I2S pins set"); | ||
} | ||
|
||
#define LOG_BUFFER_BYTES_PER_LINE 16 // Adjust as needed for readability | ||
|
||
void logBufferHex(const uint8_t *buffer, size_t length) | ||
{ | ||
for (size_t i = 0; i < length; i += LOG_BUFFER_BYTES_PER_LINE) | ||
{ | ||
char line[LOG_BUFFER_BYTES_PER_LINE * 3 + 1] = {0}; // Initialize with 0 to ensure null-terminated | ||
size_t lineIndex = 0; | ||
for (size_t j = i; j < i + LOG_BUFFER_BYTES_PER_LINE && j < length; ++j) | ||
{ | ||
lineIndex += snprintf(&line[lineIndex], sizeof(line) - lineIndex, "%02X ", buffer[j]); | ||
if (lineIndex >= sizeof(line) - 3) | ||
break; // Prevent buffer overrun | ||
} | ||
ESP_LOGW("LOG", "%s", line); | ||
} | ||
} | ||
|
||
uint8_t raw_samples[BUFFER_SIZE]; | ||
void loop() | ||
{ | ||
// read from the I2S device | ||
size_t bytes_read = 0; | ||
i2s_read(I2S_NUM_0, raw_samples, sizeof(uint8_t) * BUFFER_SIZE, &bytes_read, portMAX_DELAY); | ||
// logBufferHex(raw_samples, bytes_read); | ||
|
||
// Send the data over BLE | ||
if (bytes_read > 0) | ||
{ | ||
BLEServer.setValue(reinterpret_cast<uint8_t *>(raw_samples), bytes_read); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "I2SRecorder.h" | ||
#include "soc/i2s_reg.h" | ||
// Constructor with renamed parameters | ||
I2SRecorder::I2SRecorder(int sck, int ws, int din, int mclk) | ||
: sck(sck), ws(ws), din(din), mclk(mclk) // Use member initializer list | ||
{ | ||
} | ||
|
||
void I2SRecorder::setup() | ||
{ | ||
I2S.setPins(sck, ws, -1, din, mclk); // Use the renamed variables | ||
I2S.begin(I2S_MODE_STD, 16000, I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_MONO); | ||
// REG_SET_BIT(I2S_TIMING_REG(I2S_NUM_0), BIT(9)); | ||
// REG_SET_BIT(I2S_CONF_REG(I2S_NUM_0), I2S_RX_MSB_SHIFT); | ||
} | ||
|
||
size_t I2SRecorder::record(char *buffer, size_t bufferSize) | ||
{ | ||
return I2S.readBytes(buffer, bufferSize); // Read data from I2S | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef I2SRECORDER_H | ||
#define I2SRECORDER_H | ||
|
||
#include <Arduino.h> | ||
#include <ESP_I2S.h> | ||
|
||
class I2SRecorder | ||
{ | ||
private: | ||
I2SClass I2S; | ||
int sck, ws, din, mclk; // Renamed variables | ||
|
||
public: | ||
// Updated constructor with renamed parameters | ||
I2SRecorder(int sck, int ws, int din, int mclk); | ||
|
||
void setup(); | ||
size_t record(char *buffer, size_t bufferSize); | ||
}; | ||
|
||
#endif // I2SRECORDER_H |
Oops, something went wrong.