1.1.3.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 Generic. Answer Yes to all questions.

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

Click on the Generic Driver component (not Generic 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.

  • Number of Generic Clients indicates the maximum number of clients that can be connected to the Generic 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..

You can also bring in the Generic Driver by itself, by double clicking Generic 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 Generic 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 Generic Codec Driver Library.

Description

This section lists the files that are available in the src folder of the Generic 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/Generic.

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_genericcodec.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_genericcodec.cThis file contains implementation of the Generic 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 Generic Codec Driver Library depends on the following modules:

  • I2S Driver Library

  • I2C Driver Library

Library Interface

Client Setup Functions

NameDescription
DRV_GENERICCODEC_OpenOpens the specified Generic Codec driver instance and returns a handle to it
DRV_GENERICCODEC_CloseCloses an opened-instance of the Generic Codec driver
DRV_GENERICCODEC_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_GENERICCODEC_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 Types and Constants

NameDescription
DRV_GENERICCODEC_BUFFER_EVENTIdentifies the possible events that can result from a buffer add request.
DRV_GENERICCODEC_BUFFER_EVENT_HANDLERPointer to a Generic Codec Driver Buffer Event handler function.
DRV_GENERICCODEC_BUFFER_HANDLEHandle identifying a write buffer passed to the driver.
DRV_GENERICCODEC_CHANNELIdentifies Left/Right Audio channel.
DRV_GENERICCODEC_COMMAND_EVENT_HANDLERPointer to a Generic Codec Driver Command Event Handler function.
DRV_GENERICCODEC_INITDefines the data required to initialize or reinitialize the Generic Codec driver.
DRV_GENERICCODEC_BUFFER_HANDLE_INVALIDDefinition of an invalid buffer handle.
DRV_GENERICCODEC_COUNTNumber of valid Generic Codec driver index.
DRV_GENERICCODEC_INDEX_0Generic Codec driver index definitions.
DRV_GENERICCODEC_INDEX_1This is macro DRV_GENERICCODEC_INDEX_1.
DRV_GENERICCODEC_INDEX_2This is macro DRV_GENERICCODEC_INDEX_2.
DRV_GENERICCODEC_INDEX_3This is macro DRV_GENERICCODEC_INDEX_3.
DRV_GENERICCODEC_INDEX_4This is macro DRV_GENERICCODEC_INDEX_4.
DRV_GENERICCODEC_INDEX_5This is macro DRV_GENERICCODEC_INDEX_5.
DRV_GENERICCODEC_AUDIO_DATA_FORMATIdentifies the Serial Audio data interface format.

Data Transfer Functions

NameDescription
DRV_GENERICCODEC_BufferAddReadSchedule a non-blocking driver read operation.
DRV_GENERICCODEC_BufferAddWriteSchedule a non-blocking driver write operation.
DRV_GENERICCODEC_BufferAddWriteReadSchedule a non-blocking driver write-read operation.
DRV_GENERICCODEC_ReadQueuePurgeRemoves all buffer requests from the read queue.
DRV_GENERICCODEC_WriteQueuePurgeRemoves all buffer requests from the write queue.

Other Functions

NameDescription
DRV_GENERICCODEC_GetI2SDriverGet the handle to the I2S driver for this codec instance.
DRV_GENERICCODEC_LRCLK_SyncSynchronize to the start of the I2S LRCLK (left/right clock) signal

Settings Functions

NameDescription
DRV_GENERICCODEC_MicGainGetThis function gets the microphone gain for the Generic Codec.
DRV_GENERICCODEC_MicGainSetThis function sets the microphone gain for the Generic Codec CODEC.
DRV_GENERICCODEC_MicMuteOffUmutes th Generic Codec's microphone input.
DRV_GENERICCODEC_MicMuteOnMutes the Generic Codec's microphone input
DRV_GENERICCODEC_MuteOffThis function disables Generic Codec output for soft mute.
DRV_GENERICCODEC_MuteOnThis function allows Generic Codec output for soft mute on.
DRV_GENERICCODEC_SamplingRateGetThis function gets the sampling rate set on the Generic Codec.
DRV_GENERICCODEC_SamplingRateSetThis function sets the sampling rate of the media stream.
DRV_GENERICCODEC_VersionGetThis function returns the version of Generic Codec driver
DRV_GENERICCODEC_VersionStrGetThis function returns the version of Generic Codec driver in string format.
DRV_GENERICCODEC_VolumeGetThis function gets the volume for Generic Codec.
DRV_GENERICCODEC_VolumeSetThis function sets the volume for Generic Codec.

System Interaction Functions

NameDescription
DRV_GENERICCODEC_InitializeInitializes hardware and data for the instance of the Generic Codec module
DRV_GENERICCODEC_DeinitializeDeinitializes the specified instance of the Generic Codec driver module
DRV_GENERICCODEC_StatusGets the current status of the Generic Codec driver module.
DRV_GENERICCODEC_TasksMaintains the driver's control and data interface state machine.