From 53efa59e12f2de50bdb54e4a590c680063c39e1c Mon Sep 17 00:00:00 2001 From: Sebastian Leonhardt Date: Fri, 30 May 2014 00:26:27 +0200 Subject: recording on Samsung YH-820/YH-92x Change-Id: I6eac4cf6c16a322910ad17bfbf3105e330cd0e36 Reviewed-on: http://gerrit.rockbox.org/815 Reviewed-by: Szymon Dziok Tested: Szymon Dziok --- apps/keymaps/keymap-yh8xx_yh9xx.c | 13 ++--- firmware/drivers/audio/ak4537.c | 104 ++++++++++++++++++++++++++++++++-- firmware/export/ak4537.h | 11 ++++ firmware/export/config/samsungyh820.h | 2 +- firmware/export/config/samsungyh920.h | 2 +- firmware/export/config/samsungyh925.h | 2 +- 6 files changed, 118 insertions(+), 16 deletions(-) diff --git a/apps/keymaps/keymap-yh8xx_yh9xx.c b/apps/keymaps/keymap-yh8xx_yh9xx.c index db468a88b7..7125134d8c 100644 --- a/apps/keymaps/keymap-yh8xx_yh9xx.c +++ b/apps/keymaps/keymap-yh8xx_yh9xx.c @@ -253,17 +253,14 @@ static const struct button_mapping button_context_pitchscreen[] = { static const struct button_mapping button_context_recscreen[] = { { ACTION_REC_PAUSE, BUTTON_PLAY|BUTTON_REL, BUTTON_NONE }, -#ifdef SAMSUNG_YH820 - /* the yh-820 has a rec button */ - { ACTION_REC_NEWFILE, BUTTON_REC, BUTTON_NONE }, -#else - /* the yh-920 & yh-925 have a rec switch */ - { ACTION_REC_NEWFILE, BUTTON_PLAY|BUTTON_REPEAT, BUTTON_NONE }, -#endif + { ACTION_REC_NEWFILE, BUTTON_FFWD|BUTTON_REL, BUTTON_NONE }, + + { ACTION_STD_MENU, BUTTON_REC, BUTTON_NONE }, + { ACTION_STD_MENU, BUTTON_REW|BUTTON_REPEAT, BUTTON_REW }, + { ACTION_STD_CANCEL, BUTTON_REW|BUTTON_REL, BUTTON_NONE }, { ACTION_SETTINGS_INC, BUTTON_RIGHT, BUTTON_NONE }, { ACTION_SETTINGS_INCREPEAT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE }, - { ACTION_SETTINGS_DEC, BUTTON_LEFT, BUTTON_NONE }, { ACTION_SETTINGS_DECREPEAT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE }, diff --git a/firmware/drivers/audio/ak4537.c b/firmware/drivers/audio/ak4537.c index 90d264e445..799bf83946 100644 --- a/firmware/drivers/audio/ak4537.c +++ b/firmware/drivers/audio/ak4537.c @@ -223,22 +223,116 @@ void audiohw_set_frequency(int fsel) #if defined(HAVE_RECORDING) void audiohw_enable_recording(bool source_mic) { - (void)source_mic; + if (source_mic) + { + /* enable mic power supply */ +#if defined(SAMSUNG_YH920) || defined(SAMSUNG_YH925) + /* additionally select external mic */ + akc_set(AK4537_MIC, MPWRE | MSEL); +#else + akc_set(AK4537_MIC, MPWRI); +#endif + + /* mic out is connected to line1 input */ + akc_clear(AK4537_PM3, INL | INR); + + /* route ALC output to ADC input */ + akc_set(AK4537_MIC, MICAD); + /* set ALC (automatic level control) to manual mode */ + akc_clear(AK4537_ALC1, ALC1); + /* set gain control to 'dependent' (left&right at the same time) */ + akc_clear(AK4537_MIC, IPGAC); + /* power up mic preamp, left channel ADC and line in */ + akc_set(AK4537_PM1, PMMICL | PMIPGL | PMADL); + /* power up right channel ADC and line in */ + akc_set(AK4537_PM3, PMADR | PMIPGR); + } + else + { + /* disable mic power supply */ +#if defined(SAMSUNG_YH920) || defined(SAMSUNG_YH925) + akc_clear(AK4537_MIC, MPWRE); +#else + akc_clear(AK4537_MIC, MPWRI); +#endif + /* disable mic preamp */ + akc_clear(AK4537_PM1, PMMICL); + + /* Select line1 input */ + akc_clear(AK4537_PM3, INL | INR); + /* route ALC output to ADC input */ + akc_set(AK4537_MIC, MICAD); + /* set ALC (automatic level control) to manual mode */ + akc_clear(AK4537_ALC1, ALC1); + + /* set gain control to independent left & right gain */ + akc_set(AK4537_MIC, IPGAC); + + /* power up left channel input and ADC */ + akc_set(AK4537_PM1, PMADL | PMIPGL); + /* power up right channel input and ADC */ + akc_set(AK4537_PM3, PMADR | PMIPGR); + } } void audiohw_disable_recording(void) { + /* disable mic power supply */ +#if defined(SAMSUNG_YH920) || defined(SAMSUNG_YH925) + akc_clear(AK4537_MIC, MPWRE); +#else + akc_clear(AK4537_MIC, MPWRI); +#endif + /* power down ADC, mic preamp and line amp */ + akc_clear(AK4537_PM1, PMADL | PMMICL | PMIPGL); + akc_clear(AK4537_PM3, PMADR | PMMICR | PMIPGR); } void audiohw_set_recvol(int left, int right, int type) { - (void)left; - (void)right; - (void)type; + switch (type) + { + case AUDIO_GAIN_MIC: + /* the mic preamp has a fixed gain of +15 dB. There's an additional + * activatable +20dB mic gain stage. The signal is then routed to + * the Line1 input, where you find the line attenuator with a range + * from -23.5 to +12dB, so we have a total gain range of -8.0 .. +47dB. + * NOTE: the datasheet state's different attenuator levels for mic and + * line input, but that's not precise. The +15dB difference result only + * from the mic stage. + * NOTE2: the mic is connected to the line1 input (via mic preamp), + * so if a line signal is present, you will always record a mixup. + */ + /* If gain is > 20 dB we use the additional gain stage */ + if (left > 20) { + akc_set(AK4537_MIC, MGAIN); + left -= 20; + } + else { + akc_clear(AK4537_MIC, MGAIN); + } + /* the remains is done by the line input amp */ + left = (left+8)*2; + akc_write(AK4537_IPGAL, left); + break; + case AUDIO_GAIN_LINEIN: + /* convert dB to register value */ + left = (left+23)*2+1; + right = (right+23)*2+1; + akc_write(AK4537_IPGAL, left); + akc_write(AK4537_IPGAR, right); + break; + default: + return; + } } void audiohw_set_monitor(bool enable) { - (void)enable; + if (enable) + /* mix input signal to headphone output */ + akc_set(AK4537_SIGSEL2, MICL); + else + akc_clear(AK4537_SIGSEL2, MICL); } #endif /* HAVE_RECORDING */ diff --git a/firmware/export/ak4537.h b/firmware/export/ak4537.h index d66205af7c..1c09b5aa2f 100644 --- a/firmware/export/ak4537.h +++ b/firmware/export/ak4537.h @@ -22,8 +22,19 @@ #ifndef _AK4537_H #define _AK4537_H + +#define AUDIOHW_CAPS (LIN_GAIN_CAP | MIC_GAIN_CAP) + /* Volume goes from -127.0 ... 0 dB in 0.5 dB increments */ AUDIOHW_SETTING(VOLUME, "dB", 0, 1, -128, 0, -25) +#ifdef HAVE_RECORDING +/* line input: -23 .. +12dB */ +AUDIOHW_SETTING(LEFT_GAIN, "dB", 0, 1, -23, 12, 0) +AUDIOHW_SETTING(RIGHT_GAIN, "dB", 0, 1, -23, 12, 0) +/* mic gain: +15dB fixed +20dB switchable mic preamp gain + and the line stage of -23..+12dB make a total range of -8..+47dB */ +AUDIOHW_SETTING(MIC_GAIN, "dB", 0, 1, -8, 47, 20) +#endif /* HAVE_RECORDING */ #define AKC_NUM_REGS 0x11 diff --git a/firmware/export/config/samsungyh820.h b/firmware/export/config/samsungyh820.h index 0b9c603850..5e4c79d3ab 100644 --- a/firmware/export/config/samsungyh820.h +++ b/firmware/export/config/samsungyh820.h @@ -7,7 +7,7 @@ #define MODEL_NAME "Samsung YH-820" /* define this if you have recording possibility */ -/* todo #define HAVE_RECORDING */ +#define HAVE_RECORDING /* Define bitmask of input sources - recordable bitmask can be defined explicitly if different */ diff --git a/firmware/export/config/samsungyh920.h b/firmware/export/config/samsungyh920.h index 04487bc2db..61e6bf0017 100644 --- a/firmware/export/config/samsungyh920.h +++ b/firmware/export/config/samsungyh920.h @@ -7,7 +7,7 @@ #define MODEL_NAME "Samsung YH-920" /* define this if you have recording possibility */ -/* todo #define HAVE_RECORDING */ +#define HAVE_RECORDING /* Define bitmask of input sources - recordable bitmask can be defined explicitly if different */ diff --git a/firmware/export/config/samsungyh925.h b/firmware/export/config/samsungyh925.h index aeb9cb6829..ad04f6c81e 100644 --- a/firmware/export/config/samsungyh925.h +++ b/firmware/export/config/samsungyh925.h @@ -7,7 +7,7 @@ #define MODEL_NAME "Samsung YH-925" /* define this if you have recording possibility */ -/* todo #define HAVE_RECORDING */ +#define HAVE_RECORDING /* Define bitmask of input sources - recordable bitmask can be defined explicitly if different */ -- cgit v1.2.3