diff options
author | Dana Conrad <dconrad@fastmail.com> | 2023-11-21 19:28:51 -0600 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2024-01-02 06:51:07 -0500 |
commit | a3fe07ff128e521051aee8bc91add071724d6538 (patch) | |
tree | 9e3eb34908a4571f85686877085d9f5b200d1c2a /firmware/drivers/audio/eros_qn_codec.c | |
parent | 161c861153f67c2436affc11860ed932a0d21c30 (diff) | |
download | rockbox-a3fe07ff128e521051aee8bc91add071724d6538.tar.gz rockbox-a3fe07ff128e521051aee8bc91add071724d6538.zip |
ErosQ New Revision HW volume
Add HW volume control via ES9018K2M, and reorganize
eros_qn_codec.c/.h, audiohw-erosqnative.c.
This automatically detects the presence of the new DAC and
uses its hardware volume scaling. If not present, use same
SWVOL we have been using so far.
Add debug menu readout of SWVOL/I2C result.
Break out es9018k2m stuff into its own file so that
maybe it can be useful to other ports.
Note that we may need to get smarter about detecting the DAC
type if/when another model emerges.
Change-Id: I586a1cf7f150dd6b4e221157859825952840af56
Diffstat (limited to 'firmware/drivers/audio/eros_qn_codec.c')
-rw-r--r-- | firmware/drivers/audio/eros_qn_codec.c | 50 |
1 files changed, 12 insertions, 38 deletions
diff --git a/firmware/drivers/audio/eros_qn_codec.c b/firmware/drivers/audio/eros_qn_codec.c index 39a421ee92..095b3b5305 100644 --- a/firmware/drivers/audio/eros_qn_codec.c +++ b/firmware/drivers/audio/eros_qn_codec.c | |||
@@ -26,56 +26,30 @@ | |||
26 | #include "audiohw.h" | 26 | #include "audiohw.h" |
27 | #include "settings.h" | 27 | #include "settings.h" |
28 | #include "pcm_sw_volume.h" | 28 | #include "pcm_sw_volume.h" |
29 | #include "gpio-x1000.h" | ||
30 | 29 | ||
31 | static long int vol_l_hw = 0; | 30 | #include "gpio-x1000.h" |
32 | static long int vol_r_hw = 0; | ||
33 | 31 | ||
34 | /* internal: Switch the output sink. 0 - headphones, 1 - line out */ | 32 | static long int vol_l_hw = PCM5102A_VOLUME_MIN; |
35 | void audiohw_switch_output(int select); | 33 | static long int vol_r_hw = PCM5102A_VOLUME_MIN; |
34 | int es9018k2m_present_flag = 0; | ||
36 | 35 | ||
37 | void dac_set_outputs(void) | 36 | void eros_qn_set_outputs(void) |
38 | { | 37 | { |
39 | audiohw_set_volume(vol_l_hw, vol_r_hw); | 38 | audiohw_set_volume(vol_l_hw, vol_r_hw); |
40 | } | 39 | } |
41 | 40 | ||
42 | /* this makes less sense here than it does in the audiohw-*.c file, | 41 | void eros_qn_set_last_vol(long int vol_l, long int vol_r) |
43 | * but we need access to settings.h */ | ||
44 | void audiohw_set_volume(int vol_l, int vol_r) | ||
45 | { | 42 | { |
46 | int l, r; | ||
47 | |||
48 | vol_l_hw = vol_l; | 43 | vol_l_hw = vol_l; |
49 | vol_r_hw = vol_r; | 44 | vol_r_hw = vol_r; |
45 | } | ||
50 | 46 | ||
51 | l = vol_l; | 47 | int eros_qn_get_volume_limit(void) |
52 | r = vol_r; | 48 | { |
53 | 49 | return (global_settings.volume_limit * 10); | |
54 | #if (defined(HAVE_HEADPHONE_DETECTION) && defined(HAVE_LINEOUT_DETECTION)) | ||
55 | /* make sure headphones aren't present - don't want to | ||
56 | * blow out our eardrums cranking it to full */ | ||
57 | if (lineout_inserted() && !headphones_inserted()) | ||
58 | { | ||
59 | audiohw_switch_output(1); | ||
60 | |||
61 | l = r = global_settings.volume_limit * 10; | ||
62 | } | ||
63 | else | ||
64 | { | ||
65 | audiohw_switch_output(0); | ||
66 | |||
67 | l = vol_l; | ||
68 | r = vol_r; | ||
69 | } | ||
70 | #endif | ||
71 | |||
72 | l = l <= PCM5102A_VOLUME_MIN ? PCM_MUTE_LEVEL : (l / 20); | ||
73 | r = r <= PCM5102A_VOLUME_MIN ? PCM_MUTE_LEVEL : (r / 20); | ||
74 | |||
75 | pcm_set_master_volume(l, r); | ||
76 | } | 50 | } |
77 | 51 | ||
78 | void audiohw_switch_output(int select) | 52 | void eros_qn_switch_output(int select) |
79 | { | 53 | { |
80 | if (select == 0) | 54 | if (select == 0) |
81 | { | 55 | { |
@@ -85,4 +59,4 @@ void audiohw_switch_output(int select) | |||
85 | { | 59 | { |
86 | gpio_set_level(GPIO_STEREOSW_SEL, 1); | 60 | gpio_set_level(GPIO_STEREOSW_SEL, 1); |
87 | } | 61 | } |
88 | } | 62 | } \ No newline at end of file |