Skip to content

Commit adbde96

Browse files
Merge pull request #91 from Krupskis/esp32
Add ESP32
2 parents 5c8c250 + 3dfd6b2 commit adbde96

24 files changed

+5105
-2
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,6 @@ _site/
6868
.bundle/
6969
vendor/
7070

71-
venv/
71+
venv/
72+
73+
**/build

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "devices/coralai/coralmicro"]
22
path = devices/coralai/coralmicro
33
url = https://github.com/google-coral/coralmicro
4+
[submodule "devices/esp32-c3/components/arduino"]
5+
path = devices/esp32-c3/components/arduino
6+
url = https://github.com/espressif/arduino-esp32.git

app/ios/App/App.xcodeproj/project.pbxproj

+2
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@
347347
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
348348
CODE_SIGN_STYLE = Automatic;
349349
CURRENT_PROJECT_VERSION = 1;
350+
DEVELOPMENT_TEAM = 658U36Q86D;
350351
INFOPLIST_FILE = App/Info.plist;
351352
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
352353
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@@ -367,6 +368,7 @@
367368
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
368369
CODE_SIGN_STYLE = Automatic;
369370
CURRENT_PROJECT_VERSION = 1;
371+
DEVELOPMENT_TEAM = 658U36Q86D;
370372
INFOPLIST_FILE = App/Info.plist;
371373
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
372374
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";

devices/esp32-c3/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# The following lines of boilerplate have to be in your project's
2+
# CMakeLists in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.16)
4+
5+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
6+
project(main)

devices/esp32-c3/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
### [Click Here For Setup Guide](https://docs.adeus.ai/guides/esp32-c3.html)

devices/esp32-c3/components/arduino

Submodule arduino added at 48072ee

devices/esp32-c3/dependencies.lock

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
dependencies:
2+
chmorgan/esp-libhelix-mp3:
3+
component_hash: cbb76089dc2c5749f7b470e2e70aedc44c9da519e04eb9a67d4c7ec275229e53
4+
source:
5+
service_url: https://api.components.espressif.com/
6+
type: service
7+
version: 1.0.3
8+
espressif/cbor:
9+
component_hash: 440f4ee4504841cc9b4f3a8ef755776a612ac9dace355514c68b999868f990ff
10+
source:
11+
service_url: https://api.components.espressif.com/
12+
type: service
13+
version: 0.6.0~1
14+
espressif/esp-dsp:
15+
component_hash: 46498b4973097cac29cfc6a692abef44375ffb7b00b73b3f354124efc626a154
16+
source:
17+
service_url: https://api.components.espressif.com/
18+
type: service
19+
version: 1.4.10
20+
espressif/esp-zboss-lib:
21+
component_hash: a9e17babb2d43edc4bb6bc320f88560860122ac97e8fd72d7d5d9b3cd1578607
22+
source:
23+
service_url: https://api.components.espressif.com/
24+
type: service
25+
version: 1.1.1
26+
espressif/esp-zigbee-lib:
27+
component_hash: a1a23f47316d2d44b1573459c8cf547da7f2c8ea987154ad8d28235db69f1481
28+
source:
29+
service_url: https://api.components.espressif.com/
30+
type: service
31+
version: 1.1.1
32+
espressif/esp_diag_data_store:
33+
component_hash: 8849195251dbb8a2d7268335277cfa310cef36e4ac1e90cd59ad3be4269a30d7
34+
source:
35+
service_url: https://api.components.espressif.com/
36+
type: service
37+
version: 1.0.1
38+
espressif/esp_diagnostics:
39+
component_hash: fe19f5ee7f0145f406d36a4d5310e4ae0c6ee1afa47f2681ada8a2ea8582d390
40+
source:
41+
service_url: https://api.components.espressif.com/
42+
type: service
43+
version: 1.0.2
44+
espressif/esp_insights:
45+
component_hash: 2472a19de98a8b991baeeac7209765b70ce14ec2b1435dbed3abd020dd0f7227
46+
source:
47+
service_url: https://api.components.espressif.com/
48+
type: service
49+
version: 1.0.1
50+
espressif/esp_rainmaker:
51+
component_hash: 232425d1c9b9dbdaa5c109b3e359fba0e6956e35fcf22725f07ed7e4389e1191
52+
source:
53+
service_url: https://api.components.espressif.com/
54+
type: service
55+
version: 1.1.0
56+
espressif/esp_schedule:
57+
component_hash: 2cbc7e2584f523d10fbfb4ecb7d25c07fa7d7757ab23d7a127494b1a58131ffe
58+
source:
59+
service_url: https://api.components.espressif.com/
60+
type: service
61+
version: 1.1.0
62+
espressif/esp_secure_cert_mgr:
63+
component_hash: a20007d67e65a000670ab77e45d7554c943eb8dcb0abeada0a57dd9adac3a703
64+
source:
65+
service_url: https://api.components.espressif.com/
66+
type: service
67+
version: 2.4.1
68+
espressif/jsmn:
69+
component_hash: d80350c41bbaa827c98a25b6072df00884e72f54885996fab4a4f0aebce6b6c3
70+
source:
71+
service_url: https://api.components.espressif.com/
72+
type: service
73+
version: 1.1.0
74+
espressif/json_generator:
75+
component_hash: 45033e1c199b13f1c8c1b544fb7d4e2df6a8e3071ebdcb1b22582b61a7974ff2
76+
source:
77+
service_url: https://api.components.espressif.com/
78+
type: service
79+
version: 1.1.2
80+
espressif/json_parser:
81+
component_hash: d74b81729ad06ec11ff5eb5b1b0d7df1d00e6027fc11471f4b139c70dcf1b1e4
82+
source:
83+
service_url: https://api.components.espressif.com/
84+
type: service
85+
version: 1.0.3
86+
espressif/mdns:
87+
component_hash: d6665090cf41eb399c184aab6f34234251a773e052fb53ca044dcb576264c646
88+
source:
89+
service_url: https://api.components.espressif.com/
90+
type: service
91+
version: 1.2.1
92+
espressif/qrcode:
93+
component_hash: 3b493771bc5d6ad30cbf87c25bf784aada8a08c941504355b55d6b75518ed7bc
94+
source:
95+
service_url: https://api.components.espressif.com/
96+
type: service
97+
version: 0.1.0~2
98+
espressif/rmaker_common:
99+
component_hash: 021c02465e4996dd3292db36ea47b5e3122e7e2d3514797735a96bc12598b44f
100+
source:
101+
service_url: https://api.components.espressif.com/
102+
type: service
103+
version: 1.4.5
104+
idf:
105+
component_hash: null
106+
source:
107+
type: idf
108+
version: 5.1.2
109+
joltwallet/littlefs:
110+
component_hash: 03a21848de65d85a1f914dd6fb9dea5e75e794989d70d185a007e27c3046bb92
111+
source:
112+
service_url: https://api.components.espressif.com/
113+
type: service
114+
version: 1.14.1
115+
manifest_hash: 84a72f99bd35e36c30205cb29810146868a5d1ed843e9421c3418bc6781b1981
116+
target: esp32c3
117+
version: 1.0.0

devices/esp32-c3/main/BLE/Server.cpp

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include "Server.h"
2+
#include <BLEDevice.h>
3+
#include <BLEUtils.h>
4+
#include <BLEServer.h>
5+
#include <Arduino.h>
6+
7+
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
8+
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
9+
10+
static bool s_is_connected = false;
11+
12+
13+
class ServerHandler: public BLEServerCallbacks {
14+
void onConnect(BLEServer* pServer) {
15+
s_is_connected = true;
16+
Serial.println("Connected");
17+
}
18+
19+
void onDisconnect(BLEServer* pServer) {
20+
s_is_connected = false;
21+
Serial.println("Disconnected");
22+
BLEDevice::startAdvertising();
23+
}
24+
};
25+
26+
BluetoothServer::BluetoothServer() {}
27+
28+
void BluetoothServer::startAdvertising()
29+
{
30+
31+
Serial.println("Starting BLE Server");
32+
BLEDevice::init("ESP32");
33+
BLEDevice::setMTU(185);
34+
pServer = BLEDevice::createServer();
35+
pServer->setCallbacks(new ServerHandler());
36+
pService = pServer->createService(SERVICE_UUID);
37+
audioCharacteristic = pService->createCharacteristic(
38+
CHARACTERISTIC_UUID,
39+
BLECharacteristic::PROPERTY_READ |
40+
BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_NOTIFY);
41+
42+
43+
44+
audioCharacteristic->setValue("ESP32Hello World says ESP32Hello World");
45+
pService->start();
46+
47+
48+
// BLEAdvertising *pAdvertising = pServer->getAdvertising(); // this still is working for backward compatibility
49+
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
50+
pAdvertising->addServiceUUID(SERVICE_UUID);
51+
pAdvertising->setScanResponse(true);
52+
pAdvertising->setMinPreferred(0x06);
53+
pAdvertising->setMinPreferred(0x12);
54+
pAdvertising->setMinInterval(0x20);
55+
pAdvertising->setMaxInterval(0x40);
56+
BLEDevice::startAdvertising();
57+
Serial.printf("MTU size: %d bytes\n", BLEDevice::getMTU());
58+
}
59+
60+
void BluetoothServer::setValue(uint8_t *value, size_t len)
61+
{
62+
if (!s_is_connected) {
63+
delay(50); // Wait for a connection
64+
return;
65+
}
66+
67+
audioCharacteristic->setValue(value, len);
68+
audioCharacteristic->notify();
69+
delay(4);
70+
71+
delay(4);
72+
}

devices/esp32-c3/main/BLE/Server.h

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef BLESERVER_H
2+
#define BLESERVER_H
3+
4+
#include <Arduino.h>
5+
#include <BLEDevice.h>
6+
#include <BLEUtils.h>
7+
#include <BLEServer.h>
8+
9+
class BluetoothServer
10+
{
11+
private:
12+
BLEServer *pServer;
13+
BLEService *pService;
14+
BLECharacteristic *audioCharacteristic;
15+
16+
public:
17+
BluetoothServer();
18+
void startAdvertising();
19+
void setValue(uint8_t *value, size_t len);
20+
};
21+
#endif // BLESERVER_H

devices/esp32-c3/main/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
idf_component_register(SRCS "main.cpp"
2+
"BLE/server.cpp"
3+
INCLUDE_DIRS "." REQUIRES bt PRIV_REQUIRES arduino)

devices/esp32-c3/main/main.cpp

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include <Arduino.h>
2+
#include "BLE/Server.h"
3+
#include "esp_log.h"
4+
#include <driver/i2s.h>
5+
6+
BluetoothServer BLEServer;
7+
8+
// you shouldn't need to change these settings
9+
#define BUFFER_SIZE 182
10+
#define SAMPLE_RATE 8000
11+
// most microphones will probably default to left channel but you may need to tie the L/R pin low
12+
#define I2S_MIC_CHANNEL I2S_CHANNEL_FMT_ONLY_LEFT
13+
// either wire your microphone to the same pins or change these to match your wiring
14+
#define I2S_MIC_SERIAL_CLOCK 3 // bck, bclk, sclk
15+
#define I2S_MIC_LEFT_RIGHT_CLOCK 2 // ws, lrclk, fs
16+
#define I2S_MIC_SERIAL_DATA 4 // sd
17+
18+
i2s_config_t i2s_config = {
19+
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),
20+
.sample_rate = SAMPLE_RATE,
21+
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
22+
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
23+
.communication_format = I2S_COMM_FORMAT_I2S,
24+
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
25+
.dma_buf_count = 4,
26+
.dma_buf_len = 1024,
27+
.use_apll = false,
28+
.tx_desc_auto_clear = false,
29+
.fixed_mclk = 0};
30+
31+
i2s_pin_config_t i2s_mic_pins = {
32+
.bck_io_num = I2S_MIC_SERIAL_CLOCK,
33+
.ws_io_num = I2S_MIC_LEFT_RIGHT_CLOCK,
34+
.data_out_num = I2S_PIN_NO_CHANGE,
35+
.data_in_num = I2S_MIC_SERIAL_DATA};
36+
37+
void setup()
38+
{
39+
ESP_LOGW("LOG", "Starting BLE Server");
40+
BLEServer.startAdvertising();
41+
ESP_LOGW("LOG", "BLE Server started");
42+
43+
// start up the I2S peripheral
44+
i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
45+
i2s_set_pin(I2S_NUM_0, &i2s_mic_pins);
46+
ESP_LOGW("LOG", "I2S pins set");
47+
}
48+
49+
#define LOG_BUFFER_BYTES_PER_LINE 16 // Adjust as needed for readability
50+
51+
void logBufferHex(const uint8_t *buffer, size_t length)
52+
{
53+
for (size_t i = 0; i < length; i += LOG_BUFFER_BYTES_PER_LINE)
54+
{
55+
char line[LOG_BUFFER_BYTES_PER_LINE * 3 + 1] = {0}; // Initialize with 0 to ensure null-terminated
56+
size_t lineIndex = 0;
57+
for (size_t j = i; j < i + LOG_BUFFER_BYTES_PER_LINE && j < length; ++j)
58+
{
59+
lineIndex += snprintf(&line[lineIndex], sizeof(line) - lineIndex, "%02X ", buffer[j]);
60+
if (lineIndex >= sizeof(line) - 3)
61+
break; // Prevent buffer overrun
62+
}
63+
ESP_LOGW("LOG", "%s", line);
64+
}
65+
}
66+
67+
uint8_t raw_samples[BUFFER_SIZE];
68+
void loop()
69+
{
70+
// read from the I2S device
71+
size_t bytes_read = 0;
72+
i2s_read(I2S_NUM_0, raw_samples, sizeof(uint8_t) * BUFFER_SIZE, &bytes_read, portMAX_DELAY);
73+
// logBufferHex(raw_samples, bytes_read);
74+
75+
// Send the data over BLE
76+
if (bytes_read > 0)
77+
{
78+
BLEServer.setValue(reinterpret_cast<uint8_t *>(raw_samples), bytes_read);
79+
}
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "I2SRecorder.h"
2+
#include "soc/i2s_reg.h"
3+
// Constructor with renamed parameters
4+
I2SRecorder::I2SRecorder(int sck, int ws, int din, int mclk)
5+
: sck(sck), ws(ws), din(din), mclk(mclk) // Use member initializer list
6+
{
7+
}
8+
9+
void I2SRecorder::setup()
10+
{
11+
I2S.setPins(sck, ws, -1, din, mclk); // Use the renamed variables
12+
I2S.begin(I2S_MODE_STD, 16000, I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_MONO);
13+
// REG_SET_BIT(I2S_TIMING_REG(I2S_NUM_0), BIT(9));
14+
// REG_SET_BIT(I2S_CONF_REG(I2S_NUM_0), I2S_RX_MSB_SHIFT);
15+
}
16+
17+
size_t I2SRecorder::record(char *buffer, size_t bufferSize)
18+
{
19+
return I2S.readBytes(buffer, bufferSize); // Read data from I2S
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef I2SRECORDER_H
2+
#define I2SRECORDER_H
3+
4+
#include <Arduino.h>
5+
#include <ESP_I2S.h>
6+
7+
class I2SRecorder
8+
{
9+
private:
10+
I2SClass I2S;
11+
int sck, ws, din, mclk; // Renamed variables
12+
13+
public:
14+
// Updated constructor with renamed parameters
15+
I2SRecorder(int sck, int ws, int din, int mclk);
16+
17+
void setup();
18+
size_t record(char *buffer, size_t bufferSize);
19+
};
20+
21+
#endif // I2SRECORDER_H

0 commit comments

Comments
 (0)