diff --git a/Audio_10_BT/Audio_10_BT.ino b/Audio_10_BT/Audio_10_BT.ino
index 5f761af2e308e4c9dffd4b10f3b3c4c6aa53f82e..04eb3d8d9c2224d5b234a535107f6a83ea8ae676 100644
--- a/Audio_10_BT/Audio_10_BT.ino
+++ b/Audio_10_BT/Audio_10_BT.ino
@@ -32,6 +32,10 @@
#define PIN_CCPSE 22
#define PIN_LED 23
#define PIN_WAKEUP GPIO_NUM_15
+#define PIN_MUTE 14
+#define PIN_WSEL 25
+#define PIN_DIN 26
+#define PIN_BCLK 27
#define TRIGGER_GND HIGH
#define TRIGGER_5V LOW
@@ -74,18 +78,24 @@ RTC_DATA_ATTR struct States {
} ccState;
i2s_config_t i2s_config = {
- .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN),
- .sample_rate = 44100, // corrected by info from bluetooth
- .bits_per_sample = (i2s_bits_per_sample_t)16, //the DAC module will only take the 8bits from MSB
+ .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX ),
+ .sample_rate = 48000, // corrected by info from bluetooth
+ .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, //the DAC module will only take the 8bits from MSB
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
- .communication_format = I2S_COMM_FORMAT_I2S_MSB,
+ .communication_format = I2S_COMM_FORMAT_I2S,
.intr_alloc_flags = 0, // default interrupt priority
.dma_buf_count = 8,
.dma_buf_len = 64,
.use_apll = false
};
-String sMessage;
+static const i2s_pin_config_t pin_config = {
+ .bck_io_num = PIN_BCLK,
+ .ws_io_num = PIN_WSEL,
+ .data_out_num = PIN_DIN,
+ .data_in_num = I2S_PIN_NO_CHANGE
+};
+
bool blockOpto = true;
///////////////////////////////////////////////////////////////////////////////
@@ -101,8 +111,6 @@ void cb_a2d(esp_a2d_cb_event_t event, esp_a2d_cb_param_t* param) {
if (param->conn_stat.state == ESP_A2D_CONNECTION_STATE_DISCONNECTED) {
Serial.write("DISCONNECTED\n");
- //TODO: change inside state, or does radio change??
- // Maybe stop opto
digitalWrite(PIN_CCINS, TRIGGER_GND);
digitalWrite(PIN_CCPSE, TRIGGER_GND);
digitalWrite(PIN_CCMOD, TRIGGER_5V);
@@ -340,8 +348,6 @@ bool send_media_cmd(uint8_t cmd) {
}
void new_gear_state() {
-
- //TODO: maybe need to stop music play somewhere else
// make sure it is a new brake operation
if (ccState.timeStamp > (ccState.brakeTime + 200)) {
@@ -353,14 +359,17 @@ void new_gear_state() {
{
case GearState::empty:
esp_a2d_sink_disconnect(ccState.lastDevice);
+ digitalWrite(PIN_MUTE, TRIGGER_5V);
ccState.gearTime = 50;
break;
case GearState::connected:
send_media_cmd(ESP_AVRC_PT_CMD_PAUSE);
+ digitalWrite(PIN_MUTE, TRIGGER_5V);
ccState.gearTime = 150;
break;
case GearState::play2:
send_media_cmd(ESP_AVRC_PT_CMD_PAUSE);
+ digitalWrite(PIN_MUTE, TRIGGER_5V);
ccState.gearTime = 952;
break;
case GearState::idle:
@@ -376,6 +385,7 @@ void new_gear_state() {
break;
case GearState::play1:
send_media_cmd(ESP_AVRC_PT_CMD_PLAY);
+ digitalWrite(PIN_MUTE, TRIGGER_GND);
ccState.gearTime = 782;
break;
default:
@@ -384,6 +394,7 @@ void new_gear_state() {
ccState.gear = GearState::empty;
digitalWrite(PIN_CCINS, TRIGGER_GND);
digitalWrite(PIN_CCPSE, TRIGGER_GND);
+ digitalWrite(PIN_MUTE, TRIGGER_5V);
digitalWrite(PIN_CCMOD, TRIGGER_5V);
break;
}
@@ -399,6 +410,7 @@ void setup_pin_mods() {
pinMode(PIN_CCMOD, OUTPUT);
pinMode(PIN_CCINS, OUTPUT);
pinMode(PIN_OPTO, OUTPUT);
+ pinMode(PIN_MUTE, OUTPUT);
pinMode(PIN_CCEJT, INPUT);
pinMode(PIN_LED, INPUT);
@@ -421,6 +433,7 @@ void setup_default_states() {
digitalWrite(PIN_CCPSE, TRIGGER_GND);
digitalWrite(PIN_CCMOD, TRIGGER_5V);
+ digitalWrite(PIN_MUTE, TRIGGER_5V);
if (ccState.gear == GearState::connected)
digitalWrite(PIN_CCINS, TRIGGER_5V);
else
@@ -429,11 +442,6 @@ void setup_default_states() {
void setup() {
-
- //setup_freq_measure();
- //setup_operation_measure();
- //return;
-
Serial.begin(115200); delay(1000);
Serial.println("MB Audio 10 BT start");
@@ -444,11 +452,7 @@ void setup() {
else
Serial.println("was something else");
- Serial.print("Geartime: ");
- Serial.println(ccState.gearTime);
-
setup_pin_mods();
-
setup_default_states();
if (!bt_init("Mercedes Audio 10 BT", cb_a2d, cb_audiodata, cb_avrc_ct)) {
@@ -469,34 +473,6 @@ void setup() {
///////////////////////////////////////////////////////////////////////////////
// loop
-void loop_input() {
-
- if (Serial.available()) {
- char cInput = Serial.read();
-
- if (cInput != '\n')
- sMessage += String(cInput);
- else
- sMessage = "";
-
- if (sMessage == "sleep") {
- go_to_sleep();
- }
- else if (sMessage == "play") {
- send_media_cmd(ESP_AVRC_PT_CMD_PLAY);
- }
- else if (sMessage == "pause") {
- send_media_cmd(ESP_AVRC_PT_CMD_PAUSE);
- }
- else if (sMessage == "next") {
- send_media_cmd(ESP_AVRC_PT_CMD_FORWARD);
- }
- else if (sMessage == "prev") {
- send_media_cmd(ESP_AVRC_PT_CMD_BACKWARD);
- }
- }
-}
-
void loop_emulation() {
// get current states ////////////////////////////////////////////////////////
@@ -530,7 +506,7 @@ void loop_emulation() {
}
}
else if (readLED == LOW && ccState.optoTime != 2 * OPTO_PERIOD) {
- Serial.println("end PWM signal");
+ //Serial.println("end PWM signal");
digitalWrite(PIN_OPTO, LOW);
ccState.optoTime = 2 * OPTO_PERIOD;
}
@@ -560,7 +536,7 @@ void loop_emulation() {
if (ccState.gearTime < 100 && ccState.gear != GearState::empty) {
digitalWrite(PIN_CCINS, TRIGGER_GND);
- Serial.println("Gear: empty");
+ //Serial.println("Gear: empty");
ccState.gear = GearState::empty;
}
@@ -569,7 +545,7 @@ void loop_emulation() {
if (ccState.gear == GearState::idle)
digitalWrite(PIN_CCPSE, TRIGGER_GND);
- Serial.println("Gear: connected");
+ //Serial.println("Gear: connected");
ccState.gear = GearState::connected;
}
@@ -580,72 +556,46 @@ void loop_emulation() {
else if (ccState.gear == GearState::is1)
digitalWrite(PIN_CCMOD, TRIGGER_5V);
- Serial.println("Gear: idle");
-
ccState.gear = GearState::idle;
}
//is1
else if (240 <= ccState.gearTime && ccState.gearTime < 320 && ccState.gear != GearState::is1) {
digitalWrite(PIN_CCMOD, TRIGGER_GND);
-
- Serial.println("Gear: is1");
-
ccState.gear = GearState::is1;
}
//rev
else if (320 <= ccState.gearTime && ccState.gearTime < 385 && ccState.gear != GearState::rev) {
digitalWrite(PIN_CCMOD, TRIGGER_5V);
-
- Serial.println("Gear: rev");
-
ccState.gear = GearState::rev;
}
//is2
else if (385 <= ccState.gearTime && ccState.gearTime < 560 && ccState.gear != GearState::is2) {
digitalWrite(PIN_CCMOD, TRIGGER_GND);
-
- Serial.println("Gear: is2");
-
ccState.gear = GearState::is2;
}
//ff
else if (560 <= ccState.gearTime && ccState.gearTime < 625 && ccState.gear != GearState::ff) {
digitalWrite(PIN_CCMOD, TRIGGER_5V);
-
- Serial.println("Gear: ff");
-
ccState.gear = GearState::ff;
}
//is3
else if (625 <= ccState.gearTime && ccState.gearTime < 750 && ccState.gear != GearState::is3) {
digitalWrite(PIN_CCMOD, TRIGGER_GND);
-
- Serial.println("Gear: is3");
-
ccState.gear = GearState::is3;
}
//play1
else if (750 <= ccState.gearTime && ccState.gearTime < 815 && ccState.gear != GearState::play1) {
digitalWrite(PIN_CCMOD, TRIGGER_5V);
-
- Serial.println("Gear: play1");
-
ccState.gear = GearState::play1;
}
//is4
else if (815 <= ccState.gearTime && ccState.gearTime < 920 && ccState.gear != GearState::is4) {
digitalWrite(PIN_CCMOD, TRIGGER_GND);
-
- Serial.println("Gear: is4");
-
ccState.gear = GearState::is4;
}
//play2
else if (920 <= ccState.gearTime && ccState.gear != GearState::play2) {
digitalWrite(PIN_CCMOD, TRIGGER_5V);
-
- Serial.println("Gear: play2");
-
ccState.gear = GearState::play2;
}
@@ -658,15 +608,11 @@ void loop_emulation() {
void loop() {
- //loop_freq_measure();
- //loop_operation_measure();
- //return;
-
if (digitalRead(PIN_WAKEUP) == LOW)
go_to_sleep();
// delay 0
- loop_input();
+ //loop_input();
// delay 5
loop_emulation();