Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
flow3r firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dos
flow3r firmware
Commits
6cbc52f8
Commit
6cbc52f8
authored
1 year ago
by
q3k
Browse files
Options
Downloads
Patches
Plain Diff
flow3r_bsp: tabs to spaces (grr)
parent
9254b01d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
components/flow3r_bsp/flow3r_bsp_audio.c
+22
-22
22 additions, 22 deletions
components/flow3r_bsp/flow3r_bsp_audio.c
components/flow3r_bsp/flow3r_bsp_max98091.c
+114
-114
114 additions, 114 deletions
components/flow3r_bsp/flow3r_bsp_max98091.c
with
136 additions
and
136 deletions
components/flow3r_bsp/flow3r_bsp_audio.c
+
22
−
22
View file @
6cbc52f8
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
static
const
char
*
TAG
=
"flow3r-bsp-audio"
;
static
const
char
*
TAG
=
"flow3r-bsp-audio"
;
esp_err_t
flow3r_bsp_audio_write
(
const
void
*
src
,
size_t
size
,
size_t
*
bytes_written
,
TickType_t
ticks_to_wait
)
{
esp_err_t
flow3r_bsp_audio_write
(
const
void
*
src
,
size_t
size
,
size_t
*
bytes_written
,
TickType_t
ticks_to_wait
)
{
return
i2s_write
(
0
,
src
,
size
,
bytes_written
,
ticks_to_wait
);
return
i2s_write
(
0
,
src
,
size
,
bytes_written
,
ticks_to_wait
);
}
}
#if defined(CONFIG_BADGE23_HW_GEN_P3) || defined(CONFIG_BADGE23_HW_GEN_P4) || defined(CONFIG_BADGE23_HW_GEN_P6)
#if defined(CONFIG_BADGE23_HW_GEN_P3) || defined(CONFIG_BADGE23_HW_GEN_P4) || defined(CONFIG_BADGE23_HW_GEN_P6)
...
@@ -72,15 +72,15 @@ void flow3r_bsp_audio_line_in_set_hardware_thru(bool enable) {
...
@@ -72,15 +72,15 @@ void flow3r_bsp_audio_line_in_set_hardware_thru(bool enable) {
}
}
bool
flow3r_bsp_audio_has_hardware_mute
(
void
)
{
bool
flow3r_bsp_audio_has_hardware_mute
(
void
)
{
return
true
;
return
true
;
}
}
void
flow3r_bsp_audio_register_poke
(
uint8_t
reg
,
uint8_t
data
)
{
void
flow3r_bsp_audio_register_poke
(
uint8_t
reg
,
uint8_t
data
)
{
flow3r_bsp_max98091_register_poke
(
reg
,
data
);
flow3r_bsp_max98091_register_poke
(
reg
,
data
);
}
}
esp_err_t
flow3r_bsp_audio_read
(
void
*
dest
,
size_t
size
,
size_t
*
bytes_read
,
TickType_t
ticks_to_wait
)
{
esp_err_t
flow3r_bsp_audio_read
(
void
*
dest
,
size_t
size
,
size_t
*
bytes_read
,
TickType_t
ticks_to_wait
)
{
return
i2s_read
(
0
,
dest
,
size
,
bytes_read
,
ticks_to_wait
);
return
i2s_read
(
0
,
dest
,
size
,
bytes_read
,
ticks_to_wait
);
}
}
#elif defined(CONFIG_BADGE23_HW_GEN_P1)
#elif defined(CONFIG_BADGE23_HW_GEN_P1)
...
@@ -107,57 +107,57 @@ void flow3r_bsp_audio_init(void) {
...
@@ -107,57 +107,57 @@ void flow3r_bsp_audio_init(void) {
ESP_ERROR_CHECK
(
i2s_driver_install
(
0
,
&
i2s_config
,
0
,
NULL
));
ESP_ERROR_CHECK
(
i2s_driver_install
(
0
,
&
i2s_config
,
0
,
NULL
));
i2s_set_pin
(
0
,
&
pin_config
);
i2s_set_pin
(
0
,
&
pin_config
);
ESP_LOGE
(
TAG
,
"Prototype1 has a very limited audio codec, most features will not work! Get a newer hardware revision."
);
ESP_LOGE
(
TAG
,
"Prototype1 has a very limited audio codec, most features will not work! Get a newer hardware revision."
);
}
}
float
flow3r_bsp_audio_headphones_set_volume
(
bool
mute
,
float
dB
)
{
float
flow3r_bsp_audio_headphones_set_volume
(
bool
mute
,
float
dB
)
{
// Not supported in this generation.
// Not supported in this generation.
return
0
.
0
;
return
0
.
0
;
}
}
float
flow3r_bsp_audio_speaker_set_volume
(
bool
mute
,
float
dB
)
{
float
flow3r_bsp_audio_speaker_set_volume
(
bool
mute
,
float
dB
)
{
return
0
.
0
;
return
0
.
0
;
}
}
void
flow3r_bsp_audio_headset_set_gain_dB
(
uint8_t
gain_dB
)
{
void
flow3r_bsp_audio_headset_set_gain_dB
(
uint8_t
gain_dB
)
{
// Not supported in this generation.
// Not supported in this generation.
}
}
void
flow3r_bsp_audio_read_jacksense
(
flow3r_bsp_audio_jacksense_state_t
*
st
)
{
void
flow3r_bsp_audio_read_jacksense
(
flow3r_bsp_audio_jacksense_state_t
*
st
)
{
// Not supported in this generation.
// Not supported in this generation.
st
->
headphones
=
false
;
st
->
headphones
=
false
;
st
->
headset
=
false
;
st
->
headset
=
false
;
}
}
void
flow3r_bsp_audio_input_set_source
(
flow3r_bsp_audio_input_source_t
source
)
{
void
flow3r_bsp_audio_input_set_source
(
flow3r_bsp_audio_input_source_t
source
)
{
// Not supported in this generation.
// Not supported in this generation.
}
}
void
flow3r_bsp_audio_headphones_line_in_set_hardware_thru
(
bool
enable
)
{
void
flow3r_bsp_audio_headphones_line_in_set_hardware_thru
(
bool
enable
)
{
// Not supported in this generation.
// Not supported in this generation.
}
}
void
flow3r_bsp_audio_speaker_line_in_set_hardware_thru
(
bool
enable
)
{
void
flow3r_bsp_audio_speaker_line_in_set_hardware_thru
(
bool
enable
)
{
// Not supported in this generation.
// Not supported in this generation.
}
}
void
flow3r_bsp_audio_line_in_set_hardware_thru
(
bool
enable
)
{
void
flow3r_bsp_audio_line_in_set_hardware_thru
(
bool
enable
)
{
// Not supported in this generation.
// Not supported in this generation.
}
}
bool
flow3r_bsp_audio_has_hardware_mute
(
void
)
{
bool
flow3r_bsp_audio_has_hardware_mute
(
void
)
{
return
false
;
return
false
;
}
}
void
flow3r_bsp_audio_register_poke
(
uint8_t
reg
,
uint8_t
data
)
{
void
flow3r_bsp_audio_register_poke
(
uint8_t
reg
,
uint8_t
data
)
{
// Not supported in this generation.
// Not supported in this generation.
}
}
esp_err_t
flow3r_bsp_audio_read
(
void
*
dest
,
size_t
size
,
size_t
*
bytes_read
,
TickType_t
ticks_to_wait
)
{
esp_err_t
flow3r_bsp_audio_read
(
void
*
dest
,
size_t
size
,
size_t
*
bytes_read
,
TickType_t
ticks_to_wait
)
{
// Not supported in this generation. But pretend we've read silence.
// Not supported in this generation. But pretend we've read silence.
memset
(
dest
,
0
,
size
);
memset
(
dest
,
0
,
size
);
*
bytes_read
=
size
;
*
bytes_read
=
size
;
return
ESP_OK
;
return
ESP_OK
;
}
}
...
...
This diff is collapsed.
Click to expand it.
components/flow3r_bsp/flow3r_bsp_max98091.c
+
114
−
114
View file @
6cbc52f8
...
@@ -32,51 +32,51 @@ static esp_err_t max98091_check(const uint8_t reg, const uint8_t data)
...
@@ -32,51 +32,51 @@ static esp_err_t max98091_check(const uint8_t reg, const uint8_t data)
if
(
ret
!=
ESP_OK
)
{
if
(
ret
!=
ESP_OK
)
{
return
ret
;
return
ret
;
}
}
switch
(
reg
)
{
switch
(
reg
)
{
// Do not attempt to read back registers that are write-only.
// Do not attempt to read back registers that are write-only.
case
MAX98091_SOFTWARE_RESET
:
case
MAX98091_SOFTWARE_RESET
:
case
MAX98091_DAI_INTERFACE
:
case
MAX98091_DAI_INTERFACE
:
case
MAX98091_DAC_PATH
:
case
MAX98091_DAC_PATH
:
case
MAX98091_LINE_TO_ADC
:
case
MAX98091_LINE_TO_ADC
:
return
ESP_OK
;
return
ESP_OK
;
}
}
uint8_t
readback
=
max98091_read
(
reg
);
uint8_t
readback
=
max98091_read
(
reg
);
if
(
readback
!=
data
)
{
if
(
readback
!=
data
)
{
ESP_LOGE
(
TAG
,
"Write of %02X failed: wanted %02x, got %02x"
,
reg
,
data
,
readback
);
ESP_LOGE
(
TAG
,
"Write of %02X failed: wanted %02x, got %02x"
,
reg
,
data
,
readback
);
}
}
return
ESP_OK
;
return
ESP_OK
;
}
}
void
flow3r_bsp_max98091_register_poke
(
uint8_t
reg
,
uint8_t
data
)
{
void
flow3r_bsp_max98091_register_poke
(
uint8_t
reg
,
uint8_t
data
)
{
max98091_check
(
reg
,
data
);
max98091_check
(
reg
,
data
);
}
}
void
flow3r_bsp_max98091_headphones_line_in_set_hardware_thru
(
bool
enable
)
{
void
flow3r_bsp_max98091_headphones_line_in_set_hardware_thru
(
bool
enable
)
{
// Enable headphone mixer.
// Enable headphone mixer.
max98091_check
(
MAX98091_HPCONTROL
,
max98091_check
(
MAX98091_HPCONTROL
,
MAX98091_ON
(
HPCONTROL_MIXHP_RSEL
)
|
MAX98091_ON
(
HPCONTROL_MIXHP_RSEL
)
|
MAX98091_ON
(
HPCONTROL_MIXHP_LSEL
));
MAX98091_ON
(
HPCONTROL_MIXHP_LSEL
));
// Line A + DAC_L -> Left HP
// Line A + DAC_L -> Left HP
max98091_check
(
MAX98091_LEFT_HP_MIXER
,
max98091_check
(
MAX98091_LEFT_HP_MIXER
,
MAX98091_BOOL
(
LEFT_HP_MIXER_LINE_A
,
enable
)
|
MAX98091_BOOL
(
LEFT_HP_MIXER_LINE_A
,
enable
)
|
MAX98091_ON
(
LEFT_HP_MIXER_LEFT_DAC
));
MAX98091_ON
(
LEFT_HP_MIXER_LEFT_DAC
));
// Line B + DAC_R -> Right HP
// Line B + DAC_R -> Right HP
max98091_check
(
MAX98091_RIGHT_HP_MIXER
,
max98091_check
(
MAX98091_RIGHT_HP_MIXER
,
MAX98091_BOOL
(
RIGHT_HP_MIXER_LINE_B
,
enable
)
|
MAX98091_BOOL
(
RIGHT_HP_MIXER_LINE_B
,
enable
)
|
MAX98091_ON
(
RIGHT_HP_MIXER_RIGHT_DAC
));
MAX98091_ON
(
RIGHT_HP_MIXER_RIGHT_DAC
));
}
}
void
flow3r_bsp_max98091_speaker_line_in_set_hardware_thru
(
bool
enable
)
{
void
flow3r_bsp_max98091_speaker_line_in_set_hardware_thru
(
bool
enable
)
{
// TODO(q3k): left/right DAC seem to have been swapped before, double-check.
// TODO(q3k): left/right DAC seem to have been swapped before, double-check.
// Line A -> Left Speaker
// Line A -> Left Speaker
max98091_check
(
MAX98091_LEFT_SPK_MIXER
,
max98091_check
(
MAX98091_LEFT_SPK_MIXER
,
MAX98091_BOOL
(
LEFT_SPK_MIXER_LINE_A
,
enable
)
|
MAX98091_BOOL
(
LEFT_SPK_MIXER_LINE_A
,
enable
)
|
MAX98091_ON
(
LEFT_SPK_MIXER_LEFT_DAC
));
MAX98091_ON
(
LEFT_SPK_MIXER_LEFT_DAC
));
// Line B -> Right Speaker
// Line B -> Right Speaker
max98091_check
(
MAX98091_RIGHT_SPK_MIXER
,
max98091_check
(
MAX98091_RIGHT_SPK_MIXER
,
MAX98091_BOOL
(
RIGHT_SPK_MIXER_LINE_B
,
enable
)
|
MAX98091_BOOL
(
RIGHT_SPK_MIXER_LINE_B
,
enable
)
|
MAX98091_ON
(
RIGHT_SPK_MIXER_RIGHT_DAC
));
MAX98091_ON
(
RIGHT_SPK_MIXER_RIGHT_DAC
));
}
}
void
flow3r_bsp_max98091_line_in_set_hardware_thru
(
bool
enable
)
{
void
flow3r_bsp_max98091_line_in_set_hardware_thru
(
bool
enable
)
{
...
@@ -85,36 +85,36 @@ void flow3r_bsp_max98091_line_in_set_hardware_thru(bool enable) {
...
@@ -85,36 +85,36 @@ void flow3r_bsp_max98091_line_in_set_hardware_thru(bool enable) {
}
}
static
void
onboard_mic_set_power
(
bool
enable
)
{
static
void
onboard_mic_set_power
(
bool
enable
)
{
// DMICCLK = 3 => f_DMC = f_PCLK / 5
// DMICCLK = 3 => f_DMC = f_PCLK / 5
max98091_check
(
MAX98091_DIGITAL_MIC_ENABLE
,
max98091_check
(
MAX98091_DIGITAL_MIC_ENABLE
,
MAX98091_BITS
(
DIGITAL_MIC_ENABLE_DMICCLK
,
3
)
|
MAX98091_BITS
(
DIGITAL_MIC_ENABLE_DMICCLK
,
3
)
|
MAX98091_BOOL
(
DIGITAL_MIC_ENABLE_DIGMIC1L
,
enable
)
|
MAX98091_BOOL
(
DIGITAL_MIC_ENABLE_DIGMIC1L
,
enable
)
|
MAX98091_BOOL
(
DIGITAL_MIC_ENABLE_DIGMIC1R
,
enable
));
MAX98091_BOOL
(
DIGITAL_MIC_ENABLE_DIGMIC1R
,
enable
));
}
}
void
flow3r_bsp_max98091_input_set_source
(
flow3r_bsp_audio_input_source_t
source
){
void
flow3r_bsp_max98091_input_set_source
(
flow3r_bsp_audio_input_source_t
source
){
switch
(
source
)
{
switch
(
source
)
{
case
flow3r_bsp_audio_input_source_none
:
case
flow3r_bsp_audio_input_source_none
:
onboard_mic_set_power
(
false
);
onboard_mic_set_power
(
false
);
max98091_check
(
MAX98091_LEFT_ADC_MIXER
,
0
);
max98091_check
(
MAX98091_LEFT_ADC_MIXER
,
0
);
max98091_check
(
MAX98091_RIGHT_ADC_MIXER
,
0
);
max98091_check
(
MAX98091_RIGHT_ADC_MIXER
,
0
);
break
;
break
;
case
flow3r_bsp_audio_input_source_line_in
:
case
flow3r_bsp_audio_input_source_line_in
:
onboard_mic_set_power
(
false
);
onboard_mic_set_power
(
false
);
max98091_check
(
MAX98091_LEFT_ADC_MIXER
,
MAX98091_ON
(
LEFT_ADC_MIXER_LINE_IN_A
));
max98091_check
(
MAX98091_LEFT_ADC_MIXER
,
MAX98091_ON
(
LEFT_ADC_MIXER_LINE_IN_A
));
max98091_check
(
MAX98091_RIGHT_ADC_MIXER
,
MAX98091_ON
(
RIGHT_ADC_MIXER_LINE_IN_B
));
max98091_check
(
MAX98091_RIGHT_ADC_MIXER
,
MAX98091_ON
(
RIGHT_ADC_MIXER_LINE_IN_B
));
break
;
break
;
case
flow3r_bsp_audio_input_source_headset_mic
:
case
flow3r_bsp_audio_input_source_headset_mic
:
onboard_mic_set_power
(
false
);
onboard_mic_set_power
(
false
);
max98091_check
(
MAX98091_LEFT_ADC_MIXER
,
MAX98091_ON
(
LEFT_ADC_MIXER_MICROPHONE_1
));
max98091_check
(
MAX98091_LEFT_ADC_MIXER
,
MAX98091_ON
(
LEFT_ADC_MIXER_MICROPHONE_1
));
max98091_check
(
MAX98091_RIGHT_ADC_MIXER
,
MAX98091_ON
(
RIGHT_ADC_MIXER_MICROPHONE_1
));
max98091_check
(
MAX98091_RIGHT_ADC_MIXER
,
MAX98091_ON
(
RIGHT_ADC_MIXER_MICROPHONE_1
));
break
;
break
;
case
flow3r_bsp_audio_input_source_onboard_mic
:
case
flow3r_bsp_audio_input_source_onboard_mic
:
onboard_mic_set_power
(
true
);
onboard_mic_set_power
(
true
);
max98091_check
(
MAX98091_LEFT_ADC_MIXER
,
0
);
max98091_check
(
MAX98091_LEFT_ADC_MIXER
,
0
);
max98091_check
(
MAX98091_RIGHT_ADC_MIXER
,
0
);
max98091_check
(
MAX98091_RIGHT_ADC_MIXER
,
0
);
break
;
break
;
}
}
}
}
void
flow3r_bsp_max98091_headset_set_gain_dB
(
uint8_t
gain_dB
){
void
flow3r_bsp_max98091_headset_set_gain_dB
(
uint8_t
gain_dB
){
...
@@ -128,34 +128,34 @@ void flow3r_bsp_max98091_headset_set_gain_dB(uint8_t gain_dB){
...
@@ -128,34 +128,34 @@ void flow3r_bsp_max98091_headset_set_gain_dB(uint8_t gain_dB){
gain_dB
-=
20
;
gain_dB
-=
20
;
pa1en
=
0
b10
;
pa1en
=
0
b10
;
}
}
max98091_check
(
MAX98091_MIC1_INPUT_LEVEL
,
max98091_check
(
MAX98091_MIC1_INPUT_LEVEL
,
MAX98091_BITS
(
MIC1_INPUT_LEVEL_PGAM1
,
0x14
-
gain_dB
)
|
MAX98091_BITS
(
MIC1_INPUT_LEVEL_PGAM1
,
0x14
-
gain_dB
)
|
MAX98091_BITS
(
MIC1_INPUT_LEVEL_PA1EN
,
pa1en
));
MAX98091_BITS
(
MIC1_INPUT_LEVEL_PA1EN
,
pa1en
));
}
}
void
flow3r_bsp_max98091_read_jacksense
(
flow3r_bsp_audio_jacksense_state_t
*
st
)
{
void
flow3r_bsp_max98091_read_jacksense
(
flow3r_bsp_audio_jacksense_state_t
*
st
)
{
// TODO: read port expander
// TODO: read port expander
st
->
line_in
=
false
;
st
->
line_in
=
false
;
uint8_t
jck
=
max98091_read
(
MAX98091_JACK_STATUS
);
uint8_t
jck
=
max98091_read
(
MAX98091_JACK_STATUS
);
switch
(
jck
)
{
switch
(
jck
)
{
case
6
:
case
6
:
st
->
headphones
=
false
;
st
->
headphones
=
false
;
st
->
headset
=
false
;
st
->
headset
=
false
;
return
;
return
;
case
0
:
case
0
:
st
->
headphones
=
true
;
st
->
headphones
=
true
;
st
->
headset
=
false
;
st
->
headset
=
false
;
return
;
return
;
case
2
:
case
2
:
st
->
headphones
=
true
;
st
->
headphones
=
true
;
st
->
headset
=
true
;
st
->
headset
=
true
;
}
}
}
}
typedef
struct
{
typedef
struct
{
uint8_t
raw_value
;
uint8_t
raw_value
;
float
volume_dB
;
float
volume_dB
;
}
volume_step_t
;
}
volume_step_t
;
static
const
uint8_t
speaker_map_len
=
40
;
static
const
uint8_t
speaker_map_len
=
40
;
...
@@ -165,9 +165,9 @@ static const volume_step_t *find_speaker_volume(float vol_dB) {
...
@@ -165,9 +165,9 @@ static const volume_step_t *find_speaker_volume(float vol_dB) {
uint8_t
map_index
=
speaker_map_len
-
1
;
uint8_t
map_index
=
speaker_map_len
-
1
;
for
(;
map_index
;
map_index
--
){
for
(;
map_index
;
map_index
--
){
if
(
speaker_map
[
map_index
].
volume_dB
>=
vol_dB
)
if
(
speaker_map
[
map_index
].
volume_dB
>=
vol_dB
)
return
&
speaker_map
[
map_index
];
return
&
speaker_map
[
map_index
];
}
}
return
&
speaker_map
[
0
];
return
&
speaker_map
[
0
];
}
}
static
const
uint8_t
headphones_map_len
=
32
;
static
const
uint8_t
headphones_map_len
=
32
;
...
@@ -177,90 +177,90 @@ static const volume_step_t *find_headphones_volume(float vol_dB) {
...
@@ -177,90 +177,90 @@ static const volume_step_t *find_headphones_volume(float vol_dB) {
uint8_t
map_index
=
headphones_map_len
-
1
;
uint8_t
map_index
=
headphones_map_len
-
1
;
for
(;
map_index
;
map_index
--
){
for
(;
map_index
;
map_index
--
){
if
(
headphones_map
[
map_index
].
volume_dB
>=
vol_dB
)
if
(
headphones_map
[
map_index
].
volume_dB
>=
vol_dB
)
return
&
headphones_map
[
map_index
];
return
&
headphones_map
[
map_index
];
}
}
return
&
headphones_map
[
0
];
return
&
headphones_map
[
0
];
}
}
float
flow3r_bsp_max98091_headphones_set_volume
(
bool
mute
,
float
dB
)
{
float
flow3r_bsp_max98091_headphones_set_volume
(
bool
mute
,
float
dB
)
{
const
volume_step_t
*
step
=
find_headphones_volume
(
dB
);
const
volume_step_t
*
step
=
find_headphones_volume
(
dB
);
ESP_LOGI
(
TAG
,
"Setting headphones volume: %d/%02x"
,
mute
,
step
->
raw_value
);
ESP_LOGI
(
TAG
,
"Setting headphones volume: %d/%02x"
,
mute
,
step
->
raw_value
);
max98091_check
(
MAX98091_LEFT_HP_VOLUME
,
max98091_check
(
MAX98091_LEFT_HP_VOLUME
,
MAX98091_BOOL
(
LEFT_HP_VOLUME_HPLM
,
mute
)
|
MAX98091_BOOL
(
LEFT_HP_VOLUME_HPLM
,
mute
)
|
MAX98091_BITS
(
LEFT_HP_VOLUME_HPVOLL
,
step
->
raw_value
));
MAX98091_BITS
(
LEFT_HP_VOLUME_HPVOLL
,
step
->
raw_value
));
max98091_check
(
MAX98091_RIGHT_HP_VOLUME
,
max98091_check
(
MAX98091_RIGHT_HP_VOLUME
,
MAX98091_BOOL
(
RIGHT_HP_VOLUME_HPRM
,
mute
)
|
MAX98091_BOOL
(
RIGHT_HP_VOLUME_HPRM
,
mute
)
|
MAX98091_BITS
(
RIGHT_HP_VOLUME_HPVOLR
,
step
->
raw_value
));
MAX98091_BITS
(
RIGHT_HP_VOLUME_HPVOLR
,
step
->
raw_value
));
return
step
->
volume_dB
;
return
step
->
volume_dB
;
}
}
float
flow3r_bsp_max98091_speaker_set_volume
(
bool
mute
,
float
dB
)
{
float
flow3r_bsp_max98091_speaker_set_volume
(
bool
mute
,
float
dB
)
{
const
volume_step_t
*
step
=
find_speaker_volume
(
dB
);
const
volume_step_t
*
step
=
find_speaker_volume
(
dB
);
ESP_LOGI
(
TAG
,
"Setting speakers volume: %d/%02x"
,
mute
,
step
->
raw_value
);
ESP_LOGI
(
TAG
,
"Setting speakers volume: %d/%02x"
,
mute
,
step
->
raw_value
);
max98091_check
(
MAX98091_LEFT_SPK_VOLUME
,
max98091_check
(
MAX98091_LEFT_SPK_VOLUME
,
MAX98091_BOOL
(
LEFT_SPK_VOLUME_SPLM
,
mute
)
|
MAX98091_BOOL
(
LEFT_SPK_VOLUME_SPLM
,
mute
)
|
MAX98091_BITS
(
LEFT_SPK_VOLUME_SPVOLL
,
step
->
raw_value
));
MAX98091_BITS
(
LEFT_SPK_VOLUME_SPVOLL
,
step
->
raw_value
));
max98091_check
(
MAX98091_RIGHT_SPK_VOLUME
,
max98091_check
(
MAX98091_RIGHT_SPK_VOLUME
,
MAX98091_BOOL
(
RIGHT_SPK_VOLUME_SPRM
,
mute
)
|
MAX98091_BOOL
(
RIGHT_SPK_VOLUME_SPRM
,
mute
)
|
MAX98091_BITS
(
RIGHT_SPK_VOLUME_SPVOLR
,
step
->
raw_value
));
MAX98091_BITS
(
RIGHT_SPK_VOLUME_SPVOLR
,
step
->
raw_value
));
return
step
->
volume_dB
;
return
step
->
volume_dB
;
}
}
void
flow3r_bsp_max98091_init
(
void
)
{
void
flow3r_bsp_max98091_init
(
void
)
{
#define POKE(n, v) ESP_ERROR_CHECK(max98091_check(MAX98091_##n, v))
#define POKE(n, v) ESP_ERROR_CHECK(max98091_check(MAX98091_##n, v))
ESP_LOGI
(
TAG
,
"Codec initializing..."
);
ESP_LOGI
(
TAG
,
"Codec initializing..."
);
vTaskDelay
(
10
/
portTICK_PERIOD_MS
);
vTaskDelay
(
10
/
portTICK_PERIOD_MS
);
POKE
(
SOFTWARE_RESET
,
0x80
);
POKE
(
SOFTWARE_RESET
,
0x80
);
vTaskDelay
(
10
/
portTICK_PERIOD_MS
);
vTaskDelay
(
10
/
portTICK_PERIOD_MS
);
POKE
(
DEVICE_SHUTDOWN
,
0
);
POKE
(
DEVICE_SHUTDOWN
,
0
);
// pclk = mclk / 1
// pclk = mclk / 1
POKE
(
SYSTEM_CLOCK
,
MAX98091_BITS
(
SYSTEM_CLOCK_PSCLK
,
1
));
POKE
(
SYSTEM_CLOCK
,
MAX98091_BITS
(
SYSTEM_CLOCK_PSCLK
,
1
));
// music, dc filter in record and playback
// music, dc filter in record and playback
POKE
(
FILTER_CONFIGURATION
,
(
1
<<
7
)
|
(
1
<<
6
)
|
(
1
<<
5
)
|
(
1
<<
2
));
POKE
(
FILTER_CONFIGURATION
,
(
1
<<
7
)
|
(
1
<<
6
)
|
(
1
<<
5
)
|
(
1
<<
2
));
// Sets up DAI for left-justified slave mode operation.
// Sets up DAI for left-justified slave mode operation.
POKE
(
DAI_INTERFACE
,
1
<<
2
);
POKE
(
DAI_INTERFACE
,
1
<<
2
);
// Sets up the DAC to speaker path
// Sets up the DAC to speaker path
POKE
(
DAC_PATH
,
1
<<
5
);
POKE
(
DAC_PATH
,
1
<<
5
);
// Somehow this was needed to get an input signal to the ADC, even though
// Somehow this was needed to get an input signal to the ADC, even though
// all other registers should be taken care of later. Don't know why.
// all other registers should be taken care of later. Don't know why.
// Sets up the line in to adc path
// Sets up the line in to adc path
POKE
(
LINE_TO_ADC
,
1
<<
6
);
POKE
(
LINE_TO_ADC
,
1
<<
6
);
// SDOUT, SDIN enabled
// SDOUT, SDIN enabled
POKE
(
IO_CONFIGURATION
,
(
1
<<
1
)
|
(
1
<<
0
));
POKE
(
IO_CONFIGURATION
,
(
1
<<
1
)
|
(
1
<<
0
));
// bandgap bias
// bandgap bias
POKE
(
BIAS_CONTROL
,
1
<<
0
);
POKE
(
BIAS_CONTROL
,
1
<<
0
);
// high performane mode
// high performane mode
POKE
(
DAC_CONTROL
,
1
<<
0
);
POKE
(
DAC_CONTROL
,
1
<<
0
);
// enable micbias, line input amps, ADCs
// enable micbias, line input amps, ADCs
POKE
(
INPUT_ENABLE
,
(
1
<<
4
)
|
(
1
<<
3
)
|
(
1
<<
2
)
|
(
1
<<
1
)
|
(
1
<<
0
));
POKE
(
INPUT_ENABLE
,
(
1
<<
4
)
|
(
1
<<
3
)
|
(
1
<<
2
)
|
(
1
<<
1
)
|
(
1
<<
0
));
// IN3 SE -> Line A, IN4 SE -> Line B
// IN3 SE -> Line A, IN4 SE -> Line B
POKE
(
LINE_INPUT_CONFIG
,
(
1
<<
3
)
|
(
1
<<
2
));
POKE
(
LINE_INPUT_CONFIG
,
(
1
<<
3
)
|
(
1
<<
2
));
// 64x oversampling, dithering, high performance ADC
// 64x oversampling, dithering, high performance ADC
POKE
(
ADC_CONTROL
,
(
1
<<
1
)
|
(
1
<<
0
));
POKE
(
ADC_CONTROL
,
(
1
<<
1
)
|
(
1
<<
0
));
POKE
(
DIGITAL_MIC_ENABLE
,
0
);
POKE
(
DIGITAL_MIC_ENABLE
,
0
);
// IN5/IN6 to MIC1
// IN5/IN6 to MIC1
POKE
(
INPUT_MODE
,
(
1
<<
0
));
POKE
(
INPUT_MODE
,
(
1
<<
0
));
flow3r_bsp_max98091_line_in_set_hardware_thru
(
0
);
flow3r_bsp_max98091_line_in_set_hardware_thru
(
0
);
flow3r_bsp_max98091_headset_set_gain_dB
(
0
);
flow3r_bsp_max98091_headset_set_gain_dB
(
0
);
flow3r_bsp_max98091_input_set_source
(
flow3r_bsp_audio_input_source_none
);
flow3r_bsp_max98091_input_set_source
(
flow3r_bsp_audio_input_source_none
);
// output enable: enable dacs
// output enable: enable dacs
POKE
(
OUTPUT_ENABLE
,
(
1
<<
1
)
|
(
1
<<
0
));
POKE
(
OUTPUT_ENABLE
,
(
1
<<
1
)
|
(
1
<<
0
));
// power up
// power up
POKE
(
DEVICE_SHUTDOWN
,
1
<<
7
);
POKE
(
DEVICE_SHUTDOWN
,
1
<<
7
);
// enable outputs, dacs
// enable outputs, dacs
POKE
(
OUTPUT_ENABLE
,
(
1
<<
7
)
|
(
1
<<
6
)
|
(
1
<<
5
)
|
(
1
<<
4
)
|
(
1
<<
1
)
|
(
1
<<
0
));
POKE
(
OUTPUT_ENABLE
,
(
1
<<
7
)
|
(
1
<<
6
)
|
(
1
<<
5
)
|
(
1
<<
4
)
|
(
1
<<
1
)
|
(
1
<<
0
));
// disable all digital filters except for dc blocking
// disable all digital filters except for dc blocking
POKE
(
DSP_FILTER_ENABLE
,
0x0
);
POKE
(
DSP_FILTER_ENABLE
,
0x0
);
// jack detect enable
// jack detect enable
POKE
(
JACK_DETECT
,
1
<<
7
);
POKE
(
JACK_DETECT
,
1
<<
7
);
// TODO(q3k): mute this
// TODO(q3k): mute this
ESP_LOGI
(
TAG
,
"Codec initilialied! Don't worry about the readback errors above."
);
ESP_LOGI
(
TAG
,
"Codec initilialied! Don't worry about the readback errors above."
);
#undef POKE
#undef POKE
}
}
\ No newline at end of file
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