Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ESP32
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
C-Fu
ESP32
Commits
f8c89df3
Commit
f8c89df3
authored
Dec 27, 2020
by
Carsten Fuhrmann
Browse files
Options
Downloads
Patches
Plain Diff
Code Anpassungen DAC,
Erste Radio Testversion
parent
b1102e37
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Audio_10_BT/Audio_10_BT.ino
+26
-80
26 additions, 80 deletions
Audio_10_BT/Audio_10_BT.ino
with
26 additions
and
80 deletions
Audio_10_BT/Audio_10_BT.ino
+
26
−
80
View file @
f8c89df3
...
@@ -32,6 +32,10 @@
...
@@ -32,6 +32,10 @@
#define PIN_CCPSE 22
#define PIN_CCPSE 22
#define PIN_LED 23
#define PIN_LED 23
#define PIN_WAKEUP GPIO_NUM_15
#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_GND HIGH
#define TRIGGER_5V LOW
#define TRIGGER_5V LOW
...
@@ -74,18 +78,24 @@ RTC_DATA_ATTR struct States {
...
@@ -74,18 +78,24 @@ RTC_DATA_ATTR struct States {
}
ccState
;
}
ccState
;
i2s_config_t
i2s_config
=
{
i2s_config_t
i2s_config
=
{
.
mode
=
(
i2s_mode_t
)(
I2S_MODE_MASTER
|
I2S_MODE_TX
|
I2S_MODE_DAC_BUILT_IN
),
.
mode
=
(
i2s_mode_t
)(
I2S_MODE_MASTER
|
I2S_MODE_TX
),
.
sample_rate
=
4
41
00
,
// corrected by info from bluetooth
.
sample_rate
=
4
80
00
,
// corrected by info from bluetooth
.
bits_per_sample
=
(
i2s_bits_per_sample_t
)
16
,
//the DAC module will only take the 8bits from MSB
.
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
,
.
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
.
intr_alloc_flags
=
0
,
// default interrupt priority
.
dma_buf_count
=
8
,
.
dma_buf_count
=
8
,
.
dma_buf_len
=
64
,
.
dma_buf_len
=
64
,
.
use_apll
=
false
.
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
;
bool
blockOpto
=
true
;
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
...
@@ -101,8 +111,6 @@ void cb_a2d(esp_a2d_cb_event_t event, esp_a2d_cb_param_t* param) {
...
@@ -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
)
{
if
(
param
->
conn_stat
.
state
==
ESP_A2D_CONNECTION_STATE_DISCONNECTED
)
{
Serial
.
write
(
"DISCONNECTED
\n
"
);
Serial
.
write
(
"DISCONNECTED
\n
"
);
//TODO: change inside state, or does radio change??
// Maybe stop opto
digitalWrite
(
PIN_CCINS
,
TRIGGER_GND
);
digitalWrite
(
PIN_CCINS
,
TRIGGER_GND
);
digitalWrite
(
PIN_CCPSE
,
TRIGGER_GND
);
digitalWrite
(
PIN_CCPSE
,
TRIGGER_GND
);
digitalWrite
(
PIN_CCMOD
,
TRIGGER_5V
);
digitalWrite
(
PIN_CCMOD
,
TRIGGER_5V
);
...
@@ -341,8 +349,6 @@ bool send_media_cmd(uint8_t cmd) {
...
@@ -341,8 +349,6 @@ bool send_media_cmd(uint8_t cmd) {
void
new_gear_state
()
{
void
new_gear_state
()
{
//TODO: maybe need to stop music play somewhere else
// make sure it is a new brake operation
// make sure it is a new brake operation
if
(
ccState
.
timeStamp
>
(
ccState
.
brakeTime
+
200
))
{
if
(
ccState
.
timeStamp
>
(
ccState
.
brakeTime
+
200
))
{
ccState
.
brakeTime
=
ccState
.
timeStamp
;
ccState
.
brakeTime
=
ccState
.
timeStamp
;
...
@@ -353,14 +359,17 @@ void new_gear_state() {
...
@@ -353,14 +359,17 @@ void new_gear_state() {
{
{
case
GearState
::
empty
:
case
GearState
::
empty
:
esp_a2d_sink_disconnect
(
ccState
.
lastDevice
);
esp_a2d_sink_disconnect
(
ccState
.
lastDevice
);
digitalWrite
(
PIN_MUTE
,
TRIGGER_5V
);
ccState
.
gearTime
=
50
;
ccState
.
gearTime
=
50
;
break
;
break
;
case
GearState
::
connected
:
case
GearState
::
connected
:
send_media_cmd
(
ESP_AVRC_PT_CMD_PAUSE
);
send_media_cmd
(
ESP_AVRC_PT_CMD_PAUSE
);
digitalWrite
(
PIN_MUTE
,
TRIGGER_5V
);
ccState
.
gearTime
=
150
;
ccState
.
gearTime
=
150
;
break
;
break
;
case
GearState
::
play2
:
case
GearState
::
play2
:
send_media_cmd
(
ESP_AVRC_PT_CMD_PAUSE
);
send_media_cmd
(
ESP_AVRC_PT_CMD_PAUSE
);
digitalWrite
(
PIN_MUTE
,
TRIGGER_5V
);
ccState
.
gearTime
=
952
;
ccState
.
gearTime
=
952
;
break
;
break
;
case
GearState
::
idle
:
case
GearState
::
idle
:
...
@@ -376,6 +385,7 @@ void new_gear_state() {
...
@@ -376,6 +385,7 @@ void new_gear_state() {
break
;
break
;
case
GearState
::
play1
:
case
GearState
::
play1
:
send_media_cmd
(
ESP_AVRC_PT_CMD_PLAY
);
send_media_cmd
(
ESP_AVRC_PT_CMD_PLAY
);
digitalWrite
(
PIN_MUTE
,
TRIGGER_GND
);
ccState
.
gearTime
=
782
;
ccState
.
gearTime
=
782
;
break
;
break
;
default:
default:
...
@@ -384,6 +394,7 @@ void new_gear_state() {
...
@@ -384,6 +394,7 @@ void new_gear_state() {
ccState
.
gear
=
GearState
::
empty
;
ccState
.
gear
=
GearState
::
empty
;
digitalWrite
(
PIN_CCINS
,
TRIGGER_GND
);
digitalWrite
(
PIN_CCINS
,
TRIGGER_GND
);
digitalWrite
(
PIN_CCPSE
,
TRIGGER_GND
);
digitalWrite
(
PIN_CCPSE
,
TRIGGER_GND
);
digitalWrite
(
PIN_MUTE
,
TRIGGER_5V
);
digitalWrite
(
PIN_CCMOD
,
TRIGGER_5V
);
digitalWrite
(
PIN_CCMOD
,
TRIGGER_5V
);
break
;
break
;
}
}
...
@@ -399,6 +410,7 @@ void setup_pin_mods() {
...
@@ -399,6 +410,7 @@ void setup_pin_mods() {
pinMode
(
PIN_CCMOD
,
OUTPUT
);
pinMode
(
PIN_CCMOD
,
OUTPUT
);
pinMode
(
PIN_CCINS
,
OUTPUT
);
pinMode
(
PIN_CCINS
,
OUTPUT
);
pinMode
(
PIN_OPTO
,
OUTPUT
);
pinMode
(
PIN_OPTO
,
OUTPUT
);
pinMode
(
PIN_MUTE
,
OUTPUT
);
pinMode
(
PIN_CCEJT
,
INPUT
);
pinMode
(
PIN_CCEJT
,
INPUT
);
pinMode
(
PIN_LED
,
INPUT
);
pinMode
(
PIN_LED
,
INPUT
);
...
@@ -421,6 +433,7 @@ void setup_default_states() {
...
@@ -421,6 +433,7 @@ void setup_default_states() {
digitalWrite
(
PIN_CCPSE
,
TRIGGER_GND
);
digitalWrite
(
PIN_CCPSE
,
TRIGGER_GND
);
digitalWrite
(
PIN_CCMOD
,
TRIGGER_5V
);
digitalWrite
(
PIN_CCMOD
,
TRIGGER_5V
);
digitalWrite
(
PIN_MUTE
,
TRIGGER_5V
);
if
(
ccState
.
gear
==
GearState
::
connected
)
if
(
ccState
.
gear
==
GearState
::
connected
)
digitalWrite
(
PIN_CCINS
,
TRIGGER_5V
);
digitalWrite
(
PIN_CCINS
,
TRIGGER_5V
);
else
else
...
@@ -429,11 +442,6 @@ void setup_default_states() {
...
@@ -429,11 +442,6 @@ void setup_default_states() {
void
setup
()
{
void
setup
()
{
//setup_freq_measure();
//setup_operation_measure();
//return;
Serial
.
begin
(
115200
);
delay
(
1000
);
Serial
.
begin
(
115200
);
delay
(
1000
);
Serial
.
println
(
"MB Audio 10 BT start"
);
Serial
.
println
(
"MB Audio 10 BT start"
);
...
@@ -444,11 +452,7 @@ void setup() {
...
@@ -444,11 +452,7 @@ void setup() {
else
else
Serial
.
println
(
"was something else"
);
Serial
.
println
(
"was something else"
);
Serial
.
print
(
"Geartime: "
);
Serial
.
println
(
ccState
.
gearTime
);
setup_pin_mods
();
setup_pin_mods
();
setup_default_states
();
setup_default_states
();
if
(
!
bt_init
(
"Mercedes Audio 10 BT"
,
cb_a2d
,
cb_audiodata
,
cb_avrc_ct
))
{
if
(
!
bt_init
(
"Mercedes Audio 10 BT"
,
cb_a2d
,
cb_audiodata
,
cb_avrc_ct
))
{
...
@@ -469,34 +473,6 @@ void setup() {
...
@@ -469,34 +473,6 @@ void setup() {
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// loop
// 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
()
{
void
loop_emulation
()
{
// get current states ////////////////////////////////////////////////////////
// get current states ////////////////////////////////////////////////////////
...
@@ -530,7 +506,7 @@ void loop_emulation() {
...
@@ -530,7 +506,7 @@ void loop_emulation() {
}
}
}
}
else
if
(
readLED
==
LOW
&&
ccState
.
optoTime
!=
2
*
OPTO_PERIOD
)
{
else
if
(
readLED
==
LOW
&&
ccState
.
optoTime
!=
2
*
OPTO_PERIOD
)
{
Serial
.
println
(
"end PWM signal"
);
//
Serial.println("end PWM signal");
digitalWrite
(
PIN_OPTO
,
LOW
);
digitalWrite
(
PIN_OPTO
,
LOW
);
ccState
.
optoTime
=
2
*
OPTO_PERIOD
;
ccState
.
optoTime
=
2
*
OPTO_PERIOD
;
}
}
...
@@ -560,7 +536,7 @@ void loop_emulation() {
...
@@ -560,7 +536,7 @@ void loop_emulation() {
if
(
ccState
.
gearTime
<
100
&&
ccState
.
gear
!=
GearState
::
empty
)
{
if
(
ccState
.
gearTime
<
100
&&
ccState
.
gear
!=
GearState
::
empty
)
{
digitalWrite
(
PIN_CCINS
,
TRIGGER_GND
);
digitalWrite
(
PIN_CCINS
,
TRIGGER_GND
);
Serial
.
println
(
"Gear: empty"
);
//
Serial.println("Gear: empty");
ccState
.
gear
=
GearState
::
empty
;
ccState
.
gear
=
GearState
::
empty
;
}
}
...
@@ -569,7 +545,7 @@ void loop_emulation() {
...
@@ -569,7 +545,7 @@ void loop_emulation() {
if
(
ccState
.
gear
==
GearState
::
idle
)
if
(
ccState
.
gear
==
GearState
::
idle
)
digitalWrite
(
PIN_CCPSE
,
TRIGGER_GND
);
digitalWrite
(
PIN_CCPSE
,
TRIGGER_GND
);
Serial
.
println
(
"Gear: connected"
);
//
Serial.println("Gear: connected");
ccState
.
gear
=
GearState
::
connected
;
ccState
.
gear
=
GearState
::
connected
;
}
}
...
@@ -580,72 +556,46 @@ void loop_emulation() {
...
@@ -580,72 +556,46 @@ void loop_emulation() {
else
if
(
ccState
.
gear
==
GearState
::
is1
)
else
if
(
ccState
.
gear
==
GearState
::
is1
)
digitalWrite
(
PIN_CCMOD
,
TRIGGER_5V
);
digitalWrite
(
PIN_CCMOD
,
TRIGGER_5V
);
Serial
.
println
(
"Gear: idle"
);
ccState
.
gear
=
GearState
::
idle
;
ccState
.
gear
=
GearState
::
idle
;
}
}
//is1
//is1
else
if
(
240
<=
ccState
.
gearTime
&&
ccState
.
gearTime
<
320
&&
ccState
.
gear
!=
GearState
::
is1
)
{
else
if
(
240
<=
ccState
.
gearTime
&&
ccState
.
gearTime
<
320
&&
ccState
.
gear
!=
GearState
::
is1
)
{
digitalWrite
(
PIN_CCMOD
,
TRIGGER_GND
);
digitalWrite
(
PIN_CCMOD
,
TRIGGER_GND
);
Serial
.
println
(
"Gear: is1"
);
ccState
.
gear
=
GearState
::
is1
;
ccState
.
gear
=
GearState
::
is1
;
}
}
//rev
//rev
else
if
(
320
<=
ccState
.
gearTime
&&
ccState
.
gearTime
<
385
&&
ccState
.
gear
!=
GearState
::
rev
)
{
else
if
(
320
<=
ccState
.
gearTime
&&
ccState
.
gearTime
<
385
&&
ccState
.
gear
!=
GearState
::
rev
)
{
digitalWrite
(
PIN_CCMOD
,
TRIGGER_5V
);
digitalWrite
(
PIN_CCMOD
,
TRIGGER_5V
);
Serial
.
println
(
"Gear: rev"
);
ccState
.
gear
=
GearState
::
rev
;
ccState
.
gear
=
GearState
::
rev
;
}
}
//is2
//is2
else
if
(
385
<=
ccState
.
gearTime
&&
ccState
.
gearTime
<
560
&&
ccState
.
gear
!=
GearState
::
is2
)
{
else
if
(
385
<=
ccState
.
gearTime
&&
ccState
.
gearTime
<
560
&&
ccState
.
gear
!=
GearState
::
is2
)
{
digitalWrite
(
PIN_CCMOD
,
TRIGGER_GND
);
digitalWrite
(
PIN_CCMOD
,
TRIGGER_GND
);
Serial
.
println
(
"Gear: is2"
);
ccState
.
gear
=
GearState
::
is2
;
ccState
.
gear
=
GearState
::
is2
;
}
}
//ff
//ff
else
if
(
560
<=
ccState
.
gearTime
&&
ccState
.
gearTime
<
625
&&
ccState
.
gear
!=
GearState
::
ff
)
{
else
if
(
560
<=
ccState
.
gearTime
&&
ccState
.
gearTime
<
625
&&
ccState
.
gear
!=
GearState
::
ff
)
{
digitalWrite
(
PIN_CCMOD
,
TRIGGER_5V
);
digitalWrite
(
PIN_CCMOD
,
TRIGGER_5V
);
Serial
.
println
(
"Gear: ff"
);
ccState
.
gear
=
GearState
::
ff
;
ccState
.
gear
=
GearState
::
ff
;
}
}
//is3
//is3
else
if
(
625
<=
ccState
.
gearTime
&&
ccState
.
gearTime
<
750
&&
ccState
.
gear
!=
GearState
::
is3
)
{
else
if
(
625
<=
ccState
.
gearTime
&&
ccState
.
gearTime
<
750
&&
ccState
.
gear
!=
GearState
::
is3
)
{
digitalWrite
(
PIN_CCMOD
,
TRIGGER_GND
);
digitalWrite
(
PIN_CCMOD
,
TRIGGER_GND
);
Serial
.
println
(
"Gear: is3"
);
ccState
.
gear
=
GearState
::
is3
;
ccState
.
gear
=
GearState
::
is3
;
}
}
//play1
//play1
else
if
(
750
<=
ccState
.
gearTime
&&
ccState
.
gearTime
<
815
&&
ccState
.
gear
!=
GearState
::
play1
)
{
else
if
(
750
<=
ccState
.
gearTime
&&
ccState
.
gearTime
<
815
&&
ccState
.
gear
!=
GearState
::
play1
)
{
digitalWrite
(
PIN_CCMOD
,
TRIGGER_5V
);
digitalWrite
(
PIN_CCMOD
,
TRIGGER_5V
);
Serial
.
println
(
"Gear: play1"
);
ccState
.
gear
=
GearState
::
play1
;
ccState
.
gear
=
GearState
::
play1
;
}
}
//is4
//is4
else
if
(
815
<=
ccState
.
gearTime
&&
ccState
.
gearTime
<
920
&&
ccState
.
gear
!=
GearState
::
is4
)
{
else
if
(
815
<=
ccState
.
gearTime
&&
ccState
.
gearTime
<
920
&&
ccState
.
gear
!=
GearState
::
is4
)
{
digitalWrite
(
PIN_CCMOD
,
TRIGGER_GND
);
digitalWrite
(
PIN_CCMOD
,
TRIGGER_GND
);
Serial
.
println
(
"Gear: is4"
);
ccState
.
gear
=
GearState
::
is4
;
ccState
.
gear
=
GearState
::
is4
;
}
}
//play2
//play2
else
if
(
920
<=
ccState
.
gearTime
&&
ccState
.
gear
!=
GearState
::
play2
)
{
else
if
(
920
<=
ccState
.
gearTime
&&
ccState
.
gear
!=
GearState
::
play2
)
{
digitalWrite
(
PIN_CCMOD
,
TRIGGER_5V
);
digitalWrite
(
PIN_CCMOD
,
TRIGGER_5V
);
Serial
.
println
(
"Gear: play2"
);
ccState
.
gear
=
GearState
::
play2
;
ccState
.
gear
=
GearState
::
play2
;
}
}
...
@@ -658,15 +608,11 @@ void loop_emulation() {
...
@@ -658,15 +608,11 @@ void loop_emulation() {
void
loop
()
{
void
loop
()
{
//loop_freq_measure();
//loop_operation_measure();
//return;
if
(
digitalRead
(
PIN_WAKEUP
)
==
LOW
)
if
(
digitalRead
(
PIN_WAKEUP
)
==
LOW
)
go_to_sleep
();
go_to_sleep
();
// delay 0
// delay 0
loop_input
();
//
loop_input();
// delay 5
// delay 5
loop_emulation
();
loop_emulation
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment