Skip to content

Commit

Permalink
modules/audio : Support I2S Inputs
Browse files Browse the repository at this point in the history
Support I2S input mode.
  • Loading branch information
SPRESENSE committed Dec 16, 2021
1 parent c180296 commit 7d58aa1
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 6 deletions.
4 changes: 4 additions & 0 deletions sdk/modules/audio/components/capture/capture_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,10 @@ bool AS_get_capture_comp_handler(CaptureComponentHandler *p_handle,
param.act_param.dma_path_id = CXD56_AUDIO_DMA_PATH_MIC_TO_MEM;
break;

case CaptureDeviceI2S:
param.act_param.dma_path_id = CXD56_AUDIO_DMA_PATH_I2S0_TO_MEM;
break;

default:
CAPTURE_ERR(AS_ATTENTION_SUB_CODE_UNEXPECTED_PARAM);
return false;
Expand Down
1 change: 1 addition & 0 deletions sdk/modules/audio/components/capture/capture_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ enum CaptureDevice
{
CaptureDeviceAnalogMic = 0,
CaptureDeviceDigitalMic,
CaptureDeviceI2S,
CaptureDeviceTypeNum
};

Expand Down
2 changes: 1 addition & 1 deletion sdk/modules/audio/dma_controller/audio_bb_drv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ E_AS dmaDrvDeactive(cxd56_audio_dma_t dmacId)

static bool activateDmac[DMA_INST_NUM] =
{
false, false, false
false, false, false, false, false
};

/*--------------------------------------------------------------------*/
Expand Down
16 changes: 16 additions & 0 deletions sdk/modules/audio/dma_controller/audio_dma_drv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,22 @@ void AsDmaDrv::dmaCmplt(void)
(void *)dmaParam.addr_dest);
}

if ((cxd56_audio_get_dmafmt() == CXD56_AUDIO_DMA_FMT_RL)
&& (m_dma_byte_len == AS_DMAC_BYTE_WT_16BIT) )
{
switch (m_dmac_id)
{
case CXD56_AUDIO_DMAC_I2S0_UP:
case CXD56_AUDIO_DMAC_I2S1_UP:
AS_AudioDrvDmaGetSwapData(dmaParam.split_addr,
dmaParam.split_size);
break;

default:
break;
}
}

if (dmaParam.overlap_cnt == 0)
{
if (dmaParam.p_dmadone_func != NULL)
Expand Down
4 changes: 4 additions & 0 deletions sdk/modules/audio/dma_controller/audio_dma_drv_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ E_AS AS_ReadDmac(asReadDmacParam *pReadDmacParam)
switch (pReadDmacParam->dmacId)
{
case CXD56_AUDIO_DMAC_MIC:
case CXD56_AUDIO_DMAC_I2S0_UP:
case CXD56_AUDIO_DMAC_I2S1_UP:
break;

case CXD56_AUDIO_DMAC_I2S0_DOWN:
Expand Down Expand Up @@ -224,6 +226,8 @@ E_AS AS_WriteDmac(asWriteDmacParam *pWriteDmacParam)
switch (pWriteDmacParam->dmacId)
{
case CXD56_AUDIO_DMAC_MIC:
case CXD56_AUDIO_DMAC_I2S0_UP:
case CXD56_AUDIO_DMAC_I2S1_UP:
DMAC_ERR(AS_ATTENTION_SUB_CODE_UNEXPECTED_PARAM);
_err("ERR: dma(%d) ID error\n", pWriteDmacParam->dmacId);
return E_AS_DMAC_ID_PARAM;
Expand Down
6 changes: 6 additions & 0 deletions sdk/modules/audio/manager/audio_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2564,6 +2564,12 @@ void AudioManager::setRecorder(AudioCommand &cmd)
case AS_SETRECDR_STS_INPUTDEVICE_MIC:
break;

case AS_SETRECDR_STS_INPUTDEVICE_I2S:
/* Enable I2S pin. */

cxd56_audio_en_i2s_io();
break;

default:
MANAGER_ERR(AS_ATTENTION_SUB_CODE_UNEXPECTED_PARAM);
sendErrRespResult(cmd.header.sub_code,
Expand Down
13 changes: 12 additions & 1 deletion sdk/modules/audio/objects/front_end/front_end_obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,10 @@ uint32_t MicFrontEndObject::activateParamCheck(
}
break;

case AsMicFrontendDeviceI2S:
m_input_device = CaptureDeviceI2S;
break;

default:
MIC_FRONTEND_ERR(AS_ATTENTION_SUB_CODE_UNEXPECTED_PARAM);
return AS_ECODE_COMMAND_PARAM_INPUT_DEVICE;
Expand All @@ -1369,9 +1373,16 @@ uint32_t MicFrontEndObject::initParamCheck(const MicFrontendCommand& cmd)

switch(cmd.init_param.channel_number)
{
case AS_CHANNEL_MONO:
case AS_CHANNEL_STEREO:
break;

case AS_CHANNEL_MONO:
case AS_CHANNEL_4CH:
if (m_input_device == CaptureDeviceI2S)
{
MIC_FRONTEND_ERR(AS_ATTENTION_SUB_CODE_UNEXPECTED_PARAM);
return AS_ECODE_COMMAND_PARAM_CHANNEL_NUMBER;
}
break;

case AS_CHANNEL_6CH:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,7 @@ void MediaRecorderObject::activateOnBooted(MsgPacket *msg)
uint32_t rst;
AsActivateRecorder act = msg->moveParam<RecorderCommand>().act_param;

MEDIA_RECORDER_DBG("ACT: indev %d, outdev %d\n",
act.param.input_device,
act.param.output_device);
MEDIA_RECORDER_DBG("ACT: outdev %d\n", act.param.output_device);

/* Set event callback */

Expand Down Expand Up @@ -1620,7 +1618,7 @@ uint32_t MediaRecorderObject::isValidInitParamLPCM(
case AS_CHANNEL_4CH:
case AS_CHANNEL_6CH:
case AS_CHANNEL_8CH:
break;
break;

default:
MEDIA_RECORDER_ERR(AS_ATTENTION_SUB_CODE_UNEXPECTED_PARAM);
Expand Down
1 change: 1 addition & 0 deletions sdk/modules/include/audio/audio_frontend_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ typedef enum
typedef enum
{
AsMicFrontendDeviceMic = 0,
AsMicFrontendDeviceI2S,

} AsMicFrontendInputDevice;

Expand Down
5 changes: 5 additions & 0 deletions sdk/modules/include/audio/audio_recorder_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,17 @@ typedef enum

AS_SETRECDR_STS_INPUTDEVICE_MIC = 0,

/*! \brief I2S Input */

AS_SETRECDR_STS_INPUTDEVICE_I2S,

/* Note:
* Delete this definition with Ver 1.1.0
*/

AS_SETRECDR_STS_INPUTDEVICE_MIC_A = AS_SETRECDR_STS_INPUTDEVICE_MIC,
AS_SETRECDR_STS_INPUTDEVICE_MIC_D = AS_SETRECDR_STS_INPUTDEVICE_MIC,
AS_SETRECDR_STS_INPUTDEVICE_I2S_IN = AS_SETRECDR_STS_INPUTDEVICE_I2S,

AS_SETRECDR_STS_INPUTDEVICE_NUM
} AsSetRecorderStsInputDevice;
Expand Down

0 comments on commit 7d58aa1

Please sign in to comment.