init
This commit is contained in:
commit
fa5e1082fe
37
headphones/headphone_master/headphone_master.ino
Normal file
37
headphones/headphone_master/headphone_master.ino
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include "BluetoothA2DPSink.h"
|
||||||
|
#include <esp_now.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
|
||||||
|
BluetoothA2DPSink a2dp_sink;
|
||||||
|
|
||||||
|
uint8_t slave_mac[] = {0x24, 0x6F, 0x28, 0xXX, 0xXX, 0xXX}; // MAC-адрес второго наушника (Slave)
|
||||||
|
|
||||||
|
void audio_data_callback(const uint8_t *data, uint32_t length) {
|
||||||
|
// Разделяем стереоданные на левый и правый канал
|
||||||
|
// Отправляем правый канал на Slave
|
||||||
|
esp_now_send(slave_mac, data, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
// Настройка I2S
|
||||||
|
i2s_pin_config_t pin_config = {26, 25, 22, I2S_PIN_NO_CHANGE};
|
||||||
|
a2dp_sink.set_pin_config(pin_config);
|
||||||
|
|
||||||
|
// Настройка ESP-NOW
|
||||||
|
WiFi.mode(WIFI_STA);
|
||||||
|
esp_now_init();
|
||||||
|
esp_now_peer_info_t peerInfo = {};
|
||||||
|
memcpy(peerInfo.peer_addr, slave_mac, 6);
|
||||||
|
peerInfo.channel = 0;
|
||||||
|
peerInfo.encrypt = false;
|
||||||
|
esp_now_add_peer(&peerInfo);
|
||||||
|
|
||||||
|
// A2DP с коллбэком
|
||||||
|
a2dp_sink.set_stream_reader(audio_data_callback, false);
|
||||||
|
a2dp_sink.start("ESP32_TWS_Master");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {}
|
39
headphones/headphone_slave/headphone_slave.ino
Normal file
39
headphones/headphone_slave/headphone_slave.ino
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include <esp_now.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include "driver/i2s.h"
|
||||||
|
|
||||||
|
void on_audio_receive(const uint8_t *data, int len) {
|
||||||
|
// Воспроизводим аудио через I2S
|
||||||
|
size_t bytes_written;
|
||||||
|
i2s_write(I2S_NUM_0, data, len, &bytes_written, portMAX_DELAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
// Настройка I2S
|
||||||
|
i2s_config_t i2s_config = {
|
||||||
|
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX),
|
||||||
|
.sample_rate = 44100,
|
||||||
|
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
|
||||||
|
.channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT, // Только правый канал
|
||||||
|
.communication_format = I2S_COMM_FORMAT_I2S_MSB,
|
||||||
|
.intr_alloc_flags = 0,
|
||||||
|
.dma_buf_count = 8,
|
||||||
|
.dma_buf_len = 64,
|
||||||
|
.use_apll = false
|
||||||
|
};
|
||||||
|
i2s_pin_config_t pin_config = {26, 25, 22, I2S_PIN_NO_CHANGE};
|
||||||
|
i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
|
||||||
|
i2s_set_pin(I2S_NUM_0, &pin_config);
|
||||||
|
|
||||||
|
// Настройка ESP-NOW
|
||||||
|
WiFi.mode(WIFI_STA);
|
||||||
|
esp_now_init();
|
||||||
|
esp_now_register_recv_cb([](const uint8_t *mac, const uint8_t *data, int len) {
|
||||||
|
on_audio_receive(data, len);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {}
|
Loading…
Reference in New Issue
Block a user