Step 6: Review the Application Code

Last modified by Microchip on 2024/02/06 14:19

Application File: app_sdcard_audio_task.h

This file remains the same as in audio_player_lab4. No changes are needed. Review the Application code section in Lab 4.

Application File: app_display _task.h

Open file app_ display _task.h (in the MPLAB® X IDE Projects pane, under Header Files > app folder). This file defines application enums, data, and APIs.

The volume mute enumerator helps manage the current audio activity and acts (on a button press) to mute and un-mute, or control volume increase and decrease.

Volume mute enumeration


The app mode enumerator helps manage the mode selected by the user on the User Interface (UI).

Display app mode


The display data structure holds the volume/mute information, the ID of the current track being played, and a handle to the system timer for implementing de-bouncing for the volume slider.

Display data structure

Back to Top

Application File: app_sdcard_audio_task.c

This file remains the same as in audio_player_lab4, except for a function call that is added to notify the display task of any changes to the track list. No other changes are needed. Review the Application Code section in Lab 4.

Back to Top

Application File: app_display_task.c

Open file app_display_task.c (in the MPLAB X IDE Projects pane, under Source Files > app folder). This file contains the display task initialization and task functions.

The function APP_DISPAY_Initialize sets up the default value for the volume/mute variable as not changed.

The function APP_DISPLAY_Tasks performs the following tasks:

Once the display screen has been drawn by the gfx library state machine, it initializes the list box object with tracks from the SD card, whenever the track list is updated by the SD card audio task. It also sets the default volume level in the volume slider.
It handles changes to the application mode. When the user switches from the SD card player mode to USB SD card reader mode, it suspends the streaming, attaches the USB device, and then switches the application mode to reader mode. When the user switches back to SD card player mode, it reinitializes the SD card audio task, detaches the USB device, and then switches the application mode to player mode.
It handles the volume and mute control. The user can increase or decrease the volume through the volume slider. For mute control, the volume slider is disabled or enabled based on whether the volume is mute or un-mute. Also, the audio CODEC is updated with the new volume level. Note that the volume slider has de-bounce logic implemented by registering a call-back with the system timer service. This avoids having multiple Inter-Integrated Circuit (I²C) transactions to the audio CODEC for volume changes.
It updates the list box object with the current audio track being played. The audio files are played one after the other from the SD card, and hence, when the current audio track changes, the list box object’s focus is updated to reflect the current (changed) track being played.

The function _APP_DISPLAY_HandleMuteOn handles the volume mute event by setting the level of the volume slider object to zero and then disabling the volume slider object.

The function _APP_DISPLAY_HandleMuteOff reverses the action by setting the level of the volume slider object to its previous position and then enabling the volume slider object.

The function _APP_DISPLAY_HandleVolumeIncreaseDecrease scales the level of volume slider object to the volume level of audio CODEC.

Back to Top