1.1.1 AK4953 CODEC Driver Library Help
This topic describes the AK4953 Codec Driver Library.
Introduction
This topic describes the basic architecture of the AK4953 Codec Driver Library and provides information and examples on its use.
Interface Header File: drv_AK4953.h
The interface to the AK4953 Codec Driver library is defined in the audio/driver/codec/AK4953/drv_AK4953.h header file. Any C language source (.c) file that uses the AK4953 Codec Driver library should include this header.
Library Source Files:
The AK4953 Codec Driver library source files are provided in the audio/driver/codec/AK4953/src directory. This folder may contain optional files and alternate implementations. Please refer to Configuring the Library for instructions on how to select optional features and to Building the Library for instructions on how to build the library.
Abstraction Model
This library provides a low-level abstraction of the AK4954 Codec Driver Library on the Microchip family microcontrollers with a convenient C language interface. This topic describes how that abstraction is modeled in software and introduces the library's interface.
Description
The abstraction model shown in the following diagram depicts how the AK4953 Codec Driver is positioned in the MPLAB Harmony framework. The AK4953 Codec Driver uses the I2C and I2S drivers for control and audio data transfers to the AK4953 module.
AK4953 Driver Abstraction Model

Library Overview
Refer to the Driver Library Overview section for information on how the driver operates in a system.
The AK4953 Codec Driver Library provides an API interface to transfer control commands and digital audio data to the serially interfaced AK4953 Codec module. The library interface routines are divided into various sub-sections, which address one of the blocks or the overall operation of the AK4953 Codec Driver Library.
Library Interface Section | Description |
---|---|
System Functions | Provides system module interfaces, device initialization, deinitialization, reinitialization, tasks and status functions. |
Client Setup Functions | Provides open and close functions. |
Data Transfer Functions | Provides data transfer functions, such as Buffer Read and Write. |
Settings Functions | Provides driver specific functions for settings, such as volume control and sampling rate. |
Other Functions | Miscellaneous functions, such as getting the driver’s version number and syncing to the LRCLK signal. |
Data Types and Constants | These data types and constants are required while interacting and setting up the AK4953 Codec Driver Library. |

How the Library Works
How the Library Works
The library provides interfaces to support:
- System Functionality
- Client Functionality
Description
Setup (Initialization)
This topic describes system initialization, implementations, and includes a system access code example.
Description
The system performs the initialization of the device driver with settings that affect only the instance of the device that is being initialized. During system initialization in the system_init.c file, each instance of the AK4953 module would be initialized with the following configuration settings (either passed dynamically at run time using DRV_AK4953_INIT or by using Initialization Overrides) that are supported by the specific AK4953 device hardware:
- Device requested power state: one of the System Module Power States. For specific details please refer to Data Types and Constants in the Library Interface section.
- I2C driver module index. The module index should be same as the one used in initializing the I2C Driver
- I2S driver module index. The module index should be same as the one used in initializing the I2S Driver
- Sampling rate
- Volume
- Audio data format. The audio data format should match with the audio data format settings done in I2S driver initialization
- Determines whether or not the microphone input is enabled
The DRV_AK4953_Initialize API returns an object handle of the type SYS_MODULE_OBJ. The object handle returned by the Initialize interface would be used by the other system interfaces such as DRV_AK4953_Deinitialize, DRV_AK4953_Status and DRV_I2S_Tasks.
Client Access
This topic describes driver initialization and provides a code example.
Description
For the application to start using an instance of the module, it must call the DRV_AK4953_Open function. The DRV_AK4953_Open function provides a driver handle to the AK4953 Codec Driver instance for operations. If the driver is deinitialized using the function DRV_AK4953_Deinitialize, the application must call the DRV_AK4953_Open function again to set up the instance of the driver.
For the various options available for IO_INTENT, please refer to Data Types and Constants in the Library Interface section.

Example:
DRV_HANDLE handle; SYS_STATUS ak4953Status; ak4953Status Status = DRV_AK4953_Status(sysObjects.ak4953Status DevObject); if (SYS_STATUS_READY == ak4953Status) { \/\/ The driver can now be opened. appData.ak4953Client.handle = DRV_AK4953_Open (DRV_AK4953_INDEX_0, DRV_IO_INTENT_WRITE | DRV_IO_INTENT_EXCLUSIVE); if(appData.ak4953Client.handle != DRV_HANDLE_INVALID) { appData.state = APP_STATE_AK4953_SET_BUFFER_HANDLER; } else { SYS_DEBUG(0, "Find out what's wrong \r\n"); } } else { \/* AK4953 Driver Is not ready *\/ }
Client Operations
This topic provides information on client operations.
Description
Client operations provide the API interface for control command and audio data transfer to the AK4953 Codec.
The following AK4953 Codec specific control command functions are provided:
- DRV_AK4953_SamplingRateSet
- DRV_AK4953_SamplingRateGet
- DRV_AK4953_VolumeSet
- DRV_AK4953_VolumeGet
- DRV_AK4953_MuteOn
- DRV_AK4953_MuteOff
These functions schedule a non-blocking control command transfer operation. These functions submit the control command request to the AK4953 Codec. These functions submit the control command request to I2C Driver transmit queue, the request is processed immediately if it is the first request, or processed when the previous request is complete.
DRV_AK4953_BufferAddWrite, DRV_AK4953_BufferAddRead, and DRV_AK4953_BufferAddWriteRead are buffered data operation functions. These functions schedule non-blocking audio data transfer operations. These functions add the request to I2S Driver transmit or receive buffer queue depends on the request type, and are executed immediately if it is the first buffer, or executed later when the previous buffer is complete. The driver notifies the client with
DRV_AK4953_BUFFER_EVENT_COMPLETE, DRV_AK4953_BUFFER_EVENT_ERROR, or DRV_AK4953_BUFFER_EVENT_ABORT events.

Configuring the Library
The configuration of the I2S Driver Library is based on the file configurations.h, as generated by the MCC.
This header file contains the configuration selection for the I2S Driver Library. Based on the selections made, the I2S Driver Library may support the selected features. These configuration settings will apply to all instances of the I2S Driver Library.
This header can be placed anywhere; however, the path of this header needs to be present in the include search path for a successful build. Refer to the Applications Help section for more details.
System Configuration
Configuring MCC
Provides examples on how to configure the MPLAB Code Configurator (MCC) 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.
In the MCC, under Available Components select the appropriate BSP. Under Audio>Templates, double-click on a codec template such as AK4953. Answer Yes to all questions.
You should end up with a project graph that looks like this, after rearranging the boxes:

Click on the AK4953 Driver component (not AK4953 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 AK4953 is a Host (supplies I2S clocks) or a Client (MCU supplies I2S clocks).
- Number of AK4953 Clients indicates the maximum number of clients that can be connected to the AK4953 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
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 AK4953 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 AK4953 Driver by itself, by double clicking AK4953 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 AK4953 requires the TCx Peripheral Library and TIME System Service in order to perform some of its internal timing sequences.
Bulding the Library
This section lists the files that are available in the AK4953 Codec Driver Library.
Description
This section lists the files that are available in the src folder of the AK4953 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/AK4953\. 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 Name | Description |
---|---|
drv_ak4953.h | Header 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 MCC 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 Name | Description |
---|---|
/src/drv_ak4953.c | This file contains implementation of the AK4953 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 Name | Description |
---|---|
N/A | No optional files are available for this library. |
Module Dependencies
The AK4953 Codec Driver Library depends on the following modules:
- I2S Driver Library
- I2C Driver Library
Library Interface
Client Setup Functions
Name | Description |
---|---|
DRV_AK4953_Close | Closes an opened-instance of the AK4953 driver |
DRV_AK4953_CommandEventHandlerSet | This function allows a client to identify a command event handling function for the driver to call back when the last submitted command have finished. |
DRV_AK4953_Open | Opens the specified AK4953 driver instance and returns a handle to it. |
DRV_AK4953_BufferEventHandlerSet | This function allows a client to identify a buffer event handling function for the driver to call back when queued buffer transfers have finished. |
Data Transfer Functions
Name | Description |
---|---|
DRV_AK4953_BufferAddRead | Schedule a non-blocking driver read operation. |
DRV_AK4953_BufferAddWrite | Schedule a non-blocking driver write operation. |
DRV_AK4953_BufferAddWriteRead | Schedule a non-blocking driver write-read operation. |
DRV_AK4953_ReadQueuePurge | Removes all buffer requests from the read queue. |
DRV_AK4953_WriteQueuePurge | Removes all buffer requests from the write queue. |
Data Types and Constants
Name | Description |
---|---|
DRV_AK4953_AUDIO_DATA_FORMAT | Identifies the Serial Audio data interface format. |
DRV_AK4953_BUFFER_EVENT | Identifies the possible events that can result from a buffer add request. |
DRV_AK4953_BUFFER_EVENT_HANDLER | Pointer to a AK4953 Driver Buffer Event handler function |
DRV_AK4953_BUFFER_HANDLE | Handle identifying a write buffer passed to the driver. |
DRV_AK4953_CHANNEL | Identifies Left/Right Audio channel |
DRV_AK4953_COMMAND_EVENT_HANDLER | Pointer to a AK4953 Driver Command Event Handler Function |
DRV_AK4953_DIGITAL_BLOCK_CONTROL | Identifies Bass-Boost Control function |
DRV_AK4953_INIT | Defines the data required to initialize or reinitialize the AK4953 driver |
DRV_AK4953_INT_EXT_MIC | Identifies the Mic input source. |
DRV_AK4953_MIC | This is type DRV_AK4953_MIC. |
DRV_AK4953_MONO_STEREO_MIC | Identifies the Mic input as Mono / Stereo. |
Other Functions
Name | Description |
---|---|
DRV_AK4953_GetI2SDriver | Get the handle to the I2S driver for this codec instance. |
DRV_AK4953_LRCLK_Sync | Synchronize to the start of the I2S LRCLK (left/right clock) signal |
DRV_AK4953_VersionGet | This function returns the version of AK4953 driver. |
DRV_AK4953_VersionStrGet | This function returns the version of AK4953 driver in string format. |
Settings Functions
Name | Description |
---|---|
DRV_AK4953_IntExtMicSet | This function sets up the codec for the X32 DB internal or the external microphone use. |
DRV_AK4953_MicGainGet | This function gets the microphone gain for the AK4953 Codec. |
DRV_AK4953_MicGainSet | This function sets the microphone gain for the AK4953 CODEC. |
DRV_AK4953_MicMuteOff | Umutes th AK4953's microphone input. |
DRV_AK4953_MicMuteOn | Mutes the AK4953's microphone input |
DRV_AK4953_MicSet | This function sets up the codec for the internal or the AK4953 Mic1 or Mic2 input. |
DRV_AK4953_MonoStereoMicSet | This function sets up the codec for the Mono or Stereo microphone mode. |
DRV_AK4953_MuteOff | This function disables AK4953 output for soft mute. |
DRV_AK4953_MuteOn | This function allows AK4953 output for soft mute on. |
DRV_AK4953_SamplingRateGet | This function gets the sampling rate set on the DAC AK4953. |
DRV_AK4953_SamplingRateSet | This function sets the sampling rate of the media stream. |
DRV_AK4953_VolumeGet | This function gets the volume for AK4953 Codec. |
DRV_AK4953_VolumeSet | This function sets the volume for AK4953 Codec. |
System Interaction Functions
Name | Description |
---|---|
DRV_AK4953_Deinitialize | Deinitializes the specified instance of the AK4953 driver module. |
DRV_AK4953_EnableInitialization | Enable delayed initialization of the driver. |
DRV_AK4953_Initialize | Initializes hardware and data for the instance of the AK4953 Codec module. |
DRV_AK4953_IsInitializationDelayed | Checks if delayed initialization of the driver has been requested. |
DRV_AK4953_Status | Gets the current status of the AK4953 driver module. |
DRV_AK4953_Tasks | Maintains the driver's control and data interface state machine. |