1.1.2.2 Configuring MHC

Provides examples on how to configure the MPLAB Harmony Configurator (MHC) for a specific driver.

Description

When building a new application, start by creating a 32-bit MPLAB Harmony 3 project in MPLAB X IDE by selecting File > New Project. Chose the Configuration name the based on the BSP, and select the appropriate processor (such as ATSAME70Q21B).

In the MHC, under Available Components select the appropriate BSP, such as SAM E70 Xplained Ultra. Under Audio>Templates, double-click on a codec template such as AK4954. Answer Yes to all questions.

You should end up with a project graph that looks like this, after rearranging the boxes:

Click on the AK4954 Driver component (not AK4954 Codec) and the following menu will be displayed in the Configurations Options:

  • I2C Driver Used will display the driver instance used for the I2C interface.

  • I2S Driver Used will display the driver instance used for the I2S interface.

  • Usage Mode indicates whether the AK4954 is a Host (supplies I2S clocks) or a Client (MCU supplies I2S clocks).

  • Number of AK4954 Clients indicates the maximum number of clients that can be connected to the AK4954 Driver.

  • Sampling Rate indicates the number of samples per second per channel, 8000 to 96,000.

  • Volume indicates the volume in a linear scale from 0-255.

Audio Data Format is either

  • 24-bit Left Justified (ADC), 24-bit Right-justified(DAC)

  • 24-bit Left Justified (ADC), 16-bit Right-justified(DAC)

  • 24-bit Left Justified (ADC), 24-bit Left-justified(DAC)

  • 24/16-bit I2S

  • 32-bit Left Justified (ADC), 32-bit Left-justified(DAC)

  • 32-bit I2S

It must match the audio protocol and data length set up in either the SSC or I2S PLIB.

  • Microphone/Line Input selects which microphone or line input is selected, either:

  • Internal Mic (mounted on the AK4954 daughterboard)

  • External Mic Input

  • Line Input

If External Mic input or Line Input is selected, then the following option is provided:

Ext Mic Gain in dB range 0(min) to 31(max)

If External Mic input is selected, then the following option is provided:

Enable Microphone Bias should be checked if using an electret microphone.

You can also bring in the AK4954 Driver by itself, by double clicking AK4954 under Audio_->Driver->Codec_ in the Available Components list. You will then need to add any additional needed components manually and connect them together.

Note that the AK4954 requires the TCx Peripheral Library and TIME System Service in order to perform some of its internal timing sequences.

Building the Library

This section lists the files that are available in the AK4954 Codec Driver Library.

Description

This section lists the files that are available in the src folder of the AK4954 Codec Driver. It lists which files need to be included in the build based on either a hardware feature present on the board or configuration option selected by the system.

The following three tables list and describe the header (.h) and source (.c) files that implement this library. The parent folder for these files is audio/driver/codec/AK4954.

Interface File(s)

This table lists and describes the header files that must be included (i.e., using #include) by any code that uses this library.

Source File NameDescription
drv_ak4954.hHeader file that exports the driver API.

Required File(s)

All of the required files listed in the following table are automatically added into the MPLAB X IDE project by the MHC when the library is selected for use.

This table lists and describes the source and header files that must always be included in the MPLAB X IDE project to build this library.

Source File NameDescription
/src/drv_ak4954.cThis file contains implementation of the AK4954 Codec Driver.

Optional File(s)

This table lists and describes the source and header files that may optionally be included if required for the desired implementation.

Source File NameDescription
N/ANo optional files are available for this library.

Module Dependencies

The AK4954 Codec Driver Library depends on the following modules:

  • I2S Driver Library

  • I2C Driver Library

Library Interface

Client Setup Functions

NameDescription
DRV_AK4954_OpenOpens the specified AK4954 driver instance and returns a handle to it.
DRV_AK4954_CloseCloses an opened-instance of the AK4954 driver
DRV_AK4954_BufferEventHandlerSetThis function allows a client to identify a buffer event handling function for the driver to call back when queued buffer transfers have finished.
DRV_AK4954_CommandEventHandlerSetThis function allows a client to identify a command event handling function for the driver to call back when the last submitted command have finished.

Data Transfer Functions

NameDescription
DRV_AK4954_BufferAddReadSchedule a non-blocking driver read operation.
DRV_AK4954_BufferAddWriteSchedule a non-blocking driver write operation.
DRV_AK4954_BufferAddWriteReadSchedule a non-blocking driver write-read operation.
DRV_AK4954_ReadQueuePurgeRemoves all buffer requests from the read queue.
DRV_AK4954_WriteQueuePurgeRemoves all buffer requests from the write queue.

Data Types and Constants

NameDescription
DRV_AK4954_AUDIO_DATA_FORMATIdentifies the Serial Audio data interface format.
DRV_AK4954_BUFFER_EVENTIdentifies the possible events that can result from a buffer add request.
DRV_AK4954_BUFFER_EVENT_HANDLERPointer to a AK4954 Driver Buffer Event handler function.
DRV_AK4954_BUFFER_HANDLEHandle identifying a write buffer passed to the driver.
DRV_AK4954_CHANNELIdentifies Left/Right Audio channel.
DRV_AK4954_COMMAND_EVENT_HANDLERPointer to a AK4954 Driver Command Event Handler function.
DRV_AK4954_DIGITAL_BLOCK_CONTROLIdentifies Bass-Boost Control function.
DRV_AK4954_INITDefines the data required to initialize or reinitialize the AK4954 driver.
DRV_AK4954_INT_EXT_MICIdentifies the Mic input source.
DRV_AK4954_MICThis is type DRV_AK4954_MIC.
DRV_AK4954_MONO_STEREO_MICIdentifies the Mic input as Mono / Stereo.
SAMPLE_LENGTHin bits
DRV_AK4954_AUDIO_DATA_FORMAT_I2Sfor compatability with old code.
DRV_AK4954_BUFFER_HANDLE_INVALIDDefinition of an invalid buffer handle.
DRV_AK4954_COUNTNumber of valid AK4954 driver index.
DRV_AK4954_INDEX_0AK4954 driver index definitions.
DRV_AK4954_INDEX_1This is macro DRV_AK4954_INDEX_1.
DRV_AK4954_INDEX_2This is macro DRV_AK4954_INDEX_2.
DRV_AK4954_INDEX_3This is macro DRV_AK4954_INDEX_3.
DRV_AK4954_INDEX_4This is macro DRV_AK4954_INDEX_4.
DRV_AK4954_INDEX_5This is macro DRV_AK4954_INDEX_5.

Other Functions

NameDescription
DRV_AK4954_LRCLK_SyncSynchronize to the start of the I2S LRCLK (left/right clock) signal
DRV_AK4954_GetI2SDriverGet the handle to the I2S driver for this codec instance.
DRV_AK4954_VersionStrGetThis function returns the version of AK4954 driver in string format.
DRV_AK4954_VersionGetThis function returns the version of AK4954 driver.

Settings Functions

NameDescription
DRV_AK4954_MicGainGetThis function gets the microphone gain for the AK4954 Codec.
DRV_AK4954_MicGainSetThis function sets the microphone gain for the AK4954 CODEC.
DRV_AK4954_MicMuteOffUmutes th AK4954's microphone input.
DRV_AK4954_MicMuteOnMutes the AK4954's microphone input
DRV_AK4954_MicSetThis function sets up the codec for the internal or the AK4954 Mic1 or Mic2 input.
DRV_AK4954_MonoStereoMicSetThis function sets up the codec for the Mono or Stereo microphone mode.
DRV_AK4954_MuteOffThis function disables AK4954 output for soft mute.
DRV_AK4954_MuteOnThis function allows AK4954 output for soft mute on.
DRV_AK4954_IntExtMicSetThis function sets up the codec for the X32 DB internal or the external microphone use.
DRV_AK4954_SamplingRateGetThis function gets the sampling rate set on the DAC AK4954.
DRV_AK4954_SamplingRateSetThis function sets the sampling rate of the media stream.
DRV_AK4954_VolumeGetThis function gets the volume for AK4954 Codec.
DRV_AK4954_VolumeSetThis function sets the volume for AK4954 Codec.

System Interaction Functions

NameDescription
DRV_AK4954_InitializeInitializes hardware and data for the instance of the AK4954 Codec module.
DRV_AK4954_EnableInitializationEnable delayed initialization of the driver.
DRV_AK4954_IsInitializationDelayedChecks if delayed initialization of the driver has been requested.
DRV_AK4954_DeinitializeDeinitializes the specified instance of the AK4954 driver module.
DRV_AK4954_StatusGets the current status of the AK4954 driver module.
DRV_AK4954_TasksMaintains the driver's control and data interface state machine.