1.1.4.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 WM8904. Answer Yes to all questions.

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

Click on the WM8904 Driver component (not WM8904 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 WM8904 is a Host (supplies I2S clocks) or a Client (MCU supplies I2S clocks).

  • Number of WM8904 Clients indicates the maximum number of clients that can be connected to the WM8904 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 16-bit Left Justified, 16-bit I2S, 32-bit Left Justified, or 32-bit I2S. It must match the audio protocol and data length set up in either the SSC or I2S PLIB.

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

  • Enable Microphone Input should be checked a microphone is being used. If checked, another option,

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

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

Description

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

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

  • I2S Driver Library

  • I2C Driver Library

Library Interface

Client Setup Functions

NameDescription
DRV_WM8904_OpenOpens the specified WM8904 driver instance and returns a handle to it
DRV_WM8904_CloseCloses an opened-instance of the WM8904 driver
DRV_WM8904_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_WM8904_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_WM8904_BufferAddReadSchedule a non-blocking driver read operation.
DRV_WM8904_BufferAddWriteSchedule a non-blocking driver write operation.
DRV_WM8904_BufferAddWriteReadSchedule a non-blocking driver write-read operation.
DRV_WM8904_ReadQueuePurgeRemoves all buffer requests from the read queue.
DRV_WM8904_WriteQueuePurgeRemoves all buffer requests from the write queue.

Data Types and Constants

NameDescription
DATA_LENGTHin bits
DRV_WM8904_AUDIO_DATA_FORMATIdentifies the Serial Audio data interface format.
DRV_WM8904_BUFFER_EVENTIdentifies the possible events that can result from a buffer add request.
DRV_WM8904_BUFFER_EVENT_HANDLERPointer to a WM8904 Driver Buffer Event handler function.
DRV_WM8904_BUFFER_HANDLEHandle identifying a write buffer passed to the driver.
DRV_WM8904_CHANNELIdentifies Left/Right Audio channel.
DRV_WM8904_COMMAND_EVENT_HANDLERPointer to a WM8904 Driver Command Event Handler function.
DRV_WM8904_INITDefines the data required to initialize or reinitialize the WM8904 driver.
DRV_WM8904_BUFFER_HANDLE_INVALIDDefinition of an invalid buffer handle.
DRV_WM8904_COUNTNumber of valid WM8904 driver index.
DRV_WM8904_INDEX_0WM8904 driver index definitions.
DRV_I2C_INDEXThis is macro DRV_I2C_INDEX.

Other Functions

NameDescription
DRV_WM8904_GetI2SDriverGet the handle to the I2S driver for this codec instance.
DRV_WM8904_VersionGetThis function returns the version of WM8904 driver
DRV_WM8904_VersionStrGetThis function returns the version of WM8904 driver in string format.
DRV_WM8904_LRCLK_SyncSynchronize to the start of the I2S LRCLK (left/right clock) signal

Settings Functions

NameDescription
DRV_WM8904_MuteOffThis function disables WM8904 output for soft mute.
DRV_WM8904_MuteOnThis function allows WM8904 output for soft mute on.
DRV_WM8904_SamplingRateGetThis function gets the sampling rate set on the WM8904.
DRV_WM8904_SamplingRateSetThis function sets the sampling rate of the media stream.
DRV_WM8904_VolumeGetThis function gets the volume for WM8904 Codec.
DRV_WM8904_VolumeSetThis function sets the volume for WM8904 Codec.

System Interaction Functions

NameDescription
DRV_WM8904_InitializeInitializes hardware and data for the instance of the WM8904 DAC module
DRV_WM8904_DeinitializeDeinitializes the specified instance of the WM8904 driver module
DRV_WM8904_StatusGets the current status of the WM8904 driver module.
DRV_WM8904_TasksMaintains the driver's control and data interface state machine.