From: bsvt Date: Thu, 14 Sep 2017 16:16:12 +0000 (-0700) Subject: Changes to include mic gain and other properties in the alc5658.c driver X-Git-Tag: 1.1_Public_Release~188^2~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e9494fbd7790ecb6ae30be155743640d51e949dc;p=rtos%2Ftinyara.git Changes to include mic gain and other properties in the alc5658.c driver --- diff --git a/apps/examples/testcase/ta_tc/audio/utc/utc_audio_main.c b/apps/examples/testcase/ta_tc/audio/utc/utc_audio_main.c index bbf1b31..747ee50 100644 --- a/apps/examples/testcase/ta_tc/audio/utc/utc_audio_main.c +++ b/apps/examples/testcase/ta_tc/audio/utc/utc_audio_main.c @@ -48,7 +48,7 @@ #define AUDIO_DEFAULT_FORMAT PCM_FORMAT_S16_LE -#define AUDIO_RECORD_DURATION 3 //3sec +#define AUDIO_RECORD_DURATION 1 //3sec /**************************************************************************** * Global Variables ****************************************************************************/ @@ -780,6 +780,8 @@ static int audio_tc_launcher(int argc, char **args) total_fail = 0; utc_audio_pcm_open_tc_p(); + utc_audio_pcm_readi_p(); + utc_audio_pcm_writei_p(); utc_audio_pcm_open_tc_n(); utc_audio_pcm_is_ready_tc_p(); utc_audio_pcm_is_ready_tc_n(); diff --git a/os/arch/arm/src/s5j/s5j_i2s.c b/os/arch/arm/src/s5j/s5j_i2s.c index dfe04f3..c0fa978 100644 --- a/os/arch/arm/src/s5j/s5j_i2s.c +++ b/os/arch/arm/src/s5j/s5j_i2s.c @@ -158,9 +158,7 @@ #define CONFIG_I2S_TXP_DMACH 0 #define CONFIG_I2S_TXS_DMACH 1 #define CONFIG_I2S_RX_DMACH 2 -#define CONFIG_I2S_TXP_DMACH 0 -#define CONFIG_I2S_TXS_DMACH 1 -#define CONFIG_I2S_RX_DMACH 2 + #endif #if defined(I2S_HAVE_RX) || defined(I2S_HAVE_TX_P) || defined(I2S_HAVE_TX_S) @@ -237,6 +235,7 @@ struct s5j_i2s_s { ****************************************************************************/ /* Register helpers */ +//#define CONFIG_S5J_I2S_DUMPBUFFERS #ifdef CONFIG_S5J_I2S_DUMPBUFFERS #define i2s_init_buffer(b, s) memset(b, 0x55, s); @@ -1722,6 +1721,7 @@ static int i2s_rx_configure(struct s5j_i2s_s *priv) } priv->rxenab = 1; + lldbg("i2s_rx_configure success with i2s dev addr 0x%x\n"); return OK; err: diff --git a/os/audio/pcm_decode.c b/os/audio/pcm_decode.c index 4c0c2ec..708b0e6 100644 --- a/os/audio/pcm_decode.c +++ b/os/audio/pcm_decode.c @@ -980,7 +980,8 @@ static int pcm_enqueuebuffer(FAR struct audio_lowerhalf_s *dev, FAR struct ap_bu DEBUGASSERT(lower && lower->ops->enqueuebuffer && lower->ops->configure); /* Are we streaming yet? */ - + priv->streaming =1; + if (priv->streaming) { /* Yes, we are streaming */ /* Check for the last audio buffer in the stream */ diff --git a/os/drivers/audio/alc5658.c b/os/drivers/audio/alc5658.c index 449edb4..584aee0 100644 --- a/os/drivers/audio/alc5658.c +++ b/os/drivers/audio/alc5658.c @@ -230,7 +230,7 @@ static void alc5658_takesem(sem_t *sem) /************************************************************************************ - * Name: alc5658_scalevolume + * Name: alc5658_setvolume * * Description: * Set the right and left volume values in the ALC5658 device based on the current @@ -238,14 +238,19 @@ static void alc5658_takesem(sem_t *sem) * ************************************************************************************/ #ifndef CONFIG_AUDIO_EXCLUDE_VOLUME -static inline uint16_t alc5658_scalevolume(uint16_t volume, b16_t scale) +static void alc5658_setvolume(FAR struct alc5658_dev_s *priv, uint16_t volume, bool mute) { - return b16toi((b16_t) volume * scale); + + audvdbg(" alc5658_setvolume volume=%u mute=%u\n", volume, mute); + + priv->volume = volume; + priv->mute = mute; + } #endif /* CONFIG_AUDIO_EXCLUDE_VOLUME */ /************************************************************************************ - * Name: alc5658_setvolume + * Name: alc5658_scalevolume * * Description: * Set the right and left volume values in the ALC5658 device based on the current @@ -253,19 +258,11 @@ static inline uint16_t alc5658_scalevolume(uint16_t volume, b16_t scale) * ************************************************************************************/ #ifndef CONFIG_AUDIO_EXCLUDE_VOLUME -static void alc5658_setvolume(FAR struct alc5658_dev_s *priv, uint16_t volume, bool mute) +static inline uint16_t alc5658_scalevolume(uint16_t volume, b16_t scale) { - - audvdbg(" alc5658_setvolume volume=%u mute=%u\n", volume, mute); - /* ADD VOLUME CODE HERE */ - - /* Remember the volume level and mute settings */ - alc5658_takesem(&priv->devsem); - priv->volume = volume; - priv->mute = mute; - alc5658_givesem(&priv->devsem); + return b16toi((b16_t) volume * scale); } -#endif /* CONFIG_AUDIO_EXCLUDE_VOLUME */ +#endif /************************************************************************************ * Name: alc5658_setbass @@ -491,6 +488,8 @@ static int alc5658_configure(FAR struct audio_lowerhalf_s *dev, FAR const struct #endif int ret = OK; + + DEBUGASSERT(priv && caps); audvdbg("ac_type: %d\n", caps->ac_type); @@ -617,6 +616,9 @@ static int alc5658_configure(FAR struct audio_lowerhalf_s *dev, FAR const struct break; } + alc5658_setregs(priv); + + alc5658_getregs(priv); return ret; } @@ -672,9 +674,13 @@ static int alc5658_start(FAR struct audio_lowerhalf_s *dev) alc5658_exec_i2c_script(priv, codec_init_pll_16K, sizeof(codec_init_pll_16K) / sizeof(t_codec_init_script_entry)); alc5658_exec_i2c_script(priv, codec_init_inout_script2, sizeof(codec_init_inout_script2) / sizeof(t_codec_init_script_entry)); + + alc5658_setregs(priv); + alc5658_getregs(priv); + alc5658_takesem(&priv->devsem); - priv->running = 1; + priv->running = true; dq_entry_t *tmp = NULL; dq_queue_t * q = &priv->pendq; @@ -683,6 +689,7 @@ static int alc5658_start(FAR struct audio_lowerhalf_s *dev) } alc5658_givesem(&priv->devsem); + /* Exit reduced power modes of operation */ /* REVISIT */ @@ -710,6 +717,10 @@ static int alc5658_stop(FAR struct audio_lowerhalf_s *dev) /* Need to run the stop script here */ alc5658_exec_i2c_script(priv, codec_stop_script, sizeof(codec_stop_script) / sizeof(t_codec_init_script_entry)); + alc5658_takesem(&priv->devsem); + priv->running = false; + alc5658_givesem(&priv->devsem); + /* Enter into a reduced power usage mode */ /* REVISIT: */ @@ -788,9 +799,7 @@ static void alc5658_rxtxcallback(FAR struct i2s_dev_s *dev, FAR struct ap_buffer DEBUGASSERT(priv && apb); audvdbg("alc5658_rxcallback, devaddr= 0x%x, apbaddr =0x%x\n", dev, apb); - /* Call upper callback, let it post msg to user q */ - priv->dev.upper(priv->dev.priv, AUDIO_CALLBACK_DEQUEUE, apb, OK); - + alc5658_takesem(&priv->devsem); dq_entry_t *tmp; for (tmp = (dq_entry_t*)dq_peek(&priv->pendq); tmp; tmp = dq_next(tmp)) { @@ -832,10 +841,11 @@ static int alc5658_enqueuebuffer(FAR struct audio_lowerhalf_s *dev, FAR struct a alc5658_givesem(&priv->devsem); return OK; } + if (priv->inout) /* record */ - ret = I2S_RECEIVE(priv->i2s, apb, alc5658_rxtxcallback, priv, 0); + ret = I2S_RECEIVE(priv->i2s, apb, alc5658_rxtxcallback, priv, 100); else /* playback */ - ret = I2S_SEND(priv->i2s, apb, alc5658_rxtxcallback, priv, 0); + ret = I2S_SEND(priv->i2s, apb, alc5658_rxtxcallback, priv, 100); audvdbg("I2s returned 0x%x\n", ret); @@ -1143,15 +1153,6 @@ static void alc5658_hw_reset(FAR struct alc5658_dev_s *priv) alc5658_exec_i2c_script(priv, codec_reset_script, sizeof(codec_reset_script) / sizeof(t_codec_init_script_entry)); - //alc5658_audio_output(priv); - - /* Configure interrupts */ - - /* Configure the FLL and the LRCLK */ - - //alc5658_set_i2s_samplerate(priv); - - /* NOt sure if htis is needed */ alc5658_writereg(priv, ALC5658_IN1_CTRL, (10 + 16) << 8); audvdbg("MIC GAIN 0x%x\n", (uint32_t) alc5658_readreg(priv, ALC5658_IN1_CTRL)); @@ -1187,6 +1188,8 @@ FAR struct audio_lowerhalf_s *alc5658_initialize(FAR struct i2c_dev_s *i2c, FAR /* Sanity check */ DEBUGASSERT(i2c && i2s && lower); + auddbg("I2s dev addr is 0x%x\n", i2s); + /* Allocate a ALC5658 device structure */ priv = (FAR struct alc5658_dev_s *)kmm_zalloc(sizeof(struct alc5658_dev_s)); if (priv) { diff --git a/os/drivers/audio/alc5658.h b/os/drivers/audio/alc5658.h index 318b48f..dd226a1 100644 --- a/os/drivers/audio/alc5658.h +++ b/os/drivers/audio/alc5658.h @@ -36,7 +36,7 @@ #define ALC5658_DEFAULT_NCHANNELS 2 #define ALC5658_DEFAULT_BPSAMP 16 #define FAIL 0xFFFF -#define alc5658_givesem(s) sem_post(s) +#define alc5658_givesem(s) sem_post(s) /* Commonly defined and redefined macros */ @@ -122,6 +122,7 @@ static uint16_t alc5658_modifyreg(FAR struct alc5658_dev_s *priv, uint16_t regad static inline uint16_t alc5658_scalevolume(uint16_t volume, b16_t scale); static void alc5658_setvolume(FAR struct alc5658_dev_s *priv, uint16_t volume, bool mute); #endif + #ifndef CONFIG_AUDIO_EXCLUDE_TONE static void alc5658_setbass(FAR struct alc5658_dev_s *priv, uint8_t bass); static void alc5658_settreble(FAR struct alc5658_dev_s *priv, uint8_t treble);