MD_YX5300 Library
1.3
Library for YX5300 MP3 player IC
|
#include <MD_YX5300.h>
Classes | |
struct | cbData |
Public Types | |
enum | status_t { STS_OK = 0x00 , STS_TIMEOUT = 0x01 , STS_VERSION = 0x02 , STS_CHECKSUM = 0x03 , STS_TF_INSERT = 0x3a , STS_TF_REMOVE = 0x3b , STS_FILE_END = 0x3d , STS_INIT = 0x3f , STS_ERR_FILE = 0x40 , STS_ACK_OK = 0x41 , STS_STATUS = 0x42 , STS_VOLUME = 0x43 , STS_EQUALIZER = 0x44 , STS_TOT_FILES = 0x48 , STS_PLAYING = 0x4c , STS_FLDR_FILES = 0x4e , STS_TOT_FLDR = 0x4f } |
Public Member Functions | |
MD_YX5300 (Stream &S) | |
~MD_YX5300 (void) | |
void | begin (void) |
bool | check (void) |
Methods for object management. | |
void | setSynchronous (bool b) |
void | setTimeout (uint32_t t) |
void | setCallback (void(*cb)(const cbData *data)) |
const cbData * | getStatus (void) |
status_t | getStsCode (void) |
uint16_t | getStsData (void) |
Methods for device management. | |
bool | device (uint8_t devId) |
bool | equalizer (uint8_t eqId) |
bool | sleep (void) |
bool | wakeUp (void) |
bool | shuffle (bool b) |
bool | repeat (bool b) |
bool | reset (void) |
Methods for controlling playing MP3 files. | |
bool | playNext (void) |
bool | playPrev (void) |
bool | playStop (void) |
bool | playPause (void) |
bool | playStart (void) |
bool | playTrack (uint8_t t) |
bool | playTrackRepeat (uint8_t file) |
bool | playSpecific (uint8_t fldr, uint8_t file) |
bool | playFolderRepeat (uint8_t folder) |
bool | playFolderShuffle (uint8_t folder) |
Methods for controlling MP3 output volume. | |
bool | volume (uint8_t vol) |
uint8_t | volumeMax (void) |
bool | volumeInc (void) |
bool | volumeDec (void) |
bool | volumeMute (bool b) |
bool | volumeQuery (void) |
Methods for querying MP3 device parameters. | |
bool | queryStatus (void) |
bool | queryVolume (void) |
bool | queryEqualizer (void) |
bool | queryFolderFiles (uint8_t folder) |
bool | queryFolderCount (void) |
bool | queryFilesCount (void) |
bool | queryFile (void) |
Static Public Attributes | |
static const uint16_t | SERIAL_BPS = 9600 |
Core object for the MD_YX5300 library
enum MD_YX5300::status_t |
Status code enumerated type specification.
Used by the cbData status structure in the code field to identify the type of status data contained.
MD_YX5300::MD_YX5300 | ( | Stream & | S | ) |
Class Constructor.
Instantiate a new instance of the class. The parameters passed are used to connect the software to the hardware.
The Stream object passed to the constructor must be initialized in the main application. For convenience the constant SERIAL_BPS can be used for consistency when setting the serial interface speed.
S | Serial stream to be used for the connection to the device. |
MD_YX5300::~MD_YX5300 | ( | void | ) |
Class Destructor.
Release any necessary resources and and does the necessary to clean up once the object is no longer required.
Note that output stream is not managed by this destructor and should be handled in the application.
void MD_YX5300::begin | ( | void | ) |
Initialize the object.
Initialize the object data. This needs to be called during setup() to initialize new data for the class that cannot be done during the object creation.
The MP3 device is reset and the TF card set as the input file system, with appropriate delays after each operation.
bool MD_YX5300::check | ( | void | ) |
Receive and process serial messages.
The check function should be called repeatedly in loop() to allow the library to receive and process device messages. The MP3 device can send messages as a response to a request or unsolicited to inform of state changes, such a track play completing. A true value returned indicates that a message has been received and the status is ready to be processed.
With callbacks disabled, the application should use getStatus() to retrieve and process this status. With callbacks enabled, the check() will cause the callback to be processed before returning to the application.
If synchronous mode is enabled only unsolicited messages will be processed through the call to check(), as the other messages will have been processed synchronously as part of the request.
bool MD_YX5300::device | ( | uint8_t | devId | ) |
Set the file store device.
Set the file store device to the specified type. Currently the only type available is a TF device (CMD_OPT_TF). The application should allow 200ms for the file system to be initialized before further interacting with the MP3 device.
The TF file system is set at begin() and this method should not need to be called from application code.
devId | the device id for the type of device. Currently only 0x02 (TF). |
bool MD_YX5300::equalizer | ( | uint8_t | eqId | ) |
Set equalizer mode.
Set the equalizer mode to one of the preset types - 0:Normal, 1:Pop, 2:Rock, 3:Jazz, 4:Classic or 5:Base
eqId | the equalizer type requested [1..5]. |
const cbData* MD_YX5300::getStatus | ( | void | ) |
Get the status of last device operation.
Get the status of the last requested operation of the MP3 device. A pointer to the library's status block is returned to the application. The status code is one of the status_t enumerated types and the data component returned will depend status value. The code and data depend on the original request made of the device.
status_t MD_YX5300::getStsCode | ( | void | ) |
Get the status code of last device operation.
Get the status code of the of the last MP3 operation. The status code is one of the status_t enumerated types.
uint16_t MD_YX5300::getStsData | ( | void | ) |
Get the status data of last device operation.
Get the status data of the of the last MP3 operation. The meaning of the data will depend on the associated status code.
bool MD_YX5300::playFolderRepeat | ( | uint8_t | folder | ) |
Control repeat play mode (specific folder).
Set or reset the repeat playing mode for the specified folder. At the end of playing each file the device will send a STS_FILE_END unsolicited message.
folder | the folder number containing the files to repeat. |
bool MD_YX5300::playFolderShuffle | ( | uint8_t | folder | ) |
Control shuffle play mode (specific folder).
Set or reset the shuffle playing mode for the specified folder. At the end of playing each file the device will send a STS_FILE_END unsolicited message.
folder | the folder number containing the files to repeat. |
bool MD_YX5300::playNext | ( | void | ) |
Play the next MP3 file.
Play the next MP3 file in numeric order. At the end of playing the file the device will send a STS_FILE_END unsolicited message.
bool MD_YX5300::playPause | ( | void | ) |
Pause playing the current MP3 file.
Pause playing playing the current MP3 file. playStart() should follow to restart the same MP3 file. playStop() should be use to stop playing and abort current playing mode.
bool MD_YX5300::playPrev | ( | void | ) |
Play the previous MP3 file.
Play the previous MP3 file in numeric order. At the end of playing the file the device will send a STS_FILE_END unsolicited message.
bool MD_YX5300::playSpecific | ( | uint8_t | fldr, |
uint8_t | file | ||
) |
Play a specific file in a folder.
Play a file by specifying the folder and file to be played. At the end of playing the file the device will send a STS_FILE_END unsolicited message.
fldr | the folder number containing the files. |
file | the file within the folder. |
bool MD_YX5300::playStart | ( | void | ) |
Restart playing the current MP3 file.
Restart playing playing the current MP3 file after a playPause(). At the end of playing the file the device will send a STS_FILE_END unsolicited message.
bool MD_YX5300::playStop | ( | void | ) |
Stop playing the current MP3 file.
Stop playing the current MP3 file and cancel the current playing mode. playPause() should be used for a temporary playing stop.
bool MD_YX5300::playTrack | ( | uint8_t | t | ) |
Play a specific file.
Play a file by specifying the file index number. At the end of playing the file the device will send a STS_FILE_END unsolicited message.
t | the file indexed (0-255) to be played. |
bool MD_YX5300::playTrackRepeat | ( | uint8_t | file | ) |
Play repeat specific track.
Play a track in repeat mode. At the end of playing the file the device will send a STS_FILE_END unsolicited message.
file | the file index. |
bool MD_YX5300::queryEqualizer | ( | void | ) |
Query the current equalizer setting.
Request the current equalizer setting from the device. The response will be in an unsolicited message following the initial request.
bool MD_YX5300::queryFile | ( | void | ) |
Query the file currently playing.
Request the index of the file currently being played. The response will be in an unsolicited message following the initial request.
bool MD_YX5300::queryFilesCount | ( | void | ) |
Query the total number of files.
Request the count of files on the TF device. The response will be in an unsolicited message following the initial request.
bool MD_YX5300::queryFolderCount | ( | void | ) |
Query the total number of folders.
Request the count of folder on the TF device. The response will be in an unsolicited message following the initial request.
bool MD_YX5300::queryFolderFiles | ( | uint8_t | folder | ) |
Query the number of files in the specified folder.
Request the count of files in the specified folder number. The response will be in an unsolicited message following the initial request.
folder | the folder number whose files are to be counted. |
bool MD_YX5300::queryStatus | ( | void | ) |
Query the current status.
Request the current status setting from the device. The response will be in an unsolicited message following the initial request.
bool MD_YX5300::queryVolume | ( | void | ) |
Query the current volume setting.
Request the current volume setting from the device. This is a wrapper alternative for volumeQuery(). The response will be in an unsolicited message following the initial request.
bool MD_YX5300::repeat | ( | bool | b | ) |
Control repeat play mode (current file).
Set or reset the repeat playing mode for the currently playing track. At the end of each repeat play the device will send a STS_FILE_END unsolicited message.
b | true to enable mode, false to disable. |
bool MD_YX5300::reset | ( | void | ) |
Reset the MP3 player.
Put the MP3 player into reset mode. The payer will return to its power up state. The application should allow 500ms between the rest command and any subsequent interaction with the device.
void MD_YX5300::setCallback | ( | void(*)(const cbData *data) | cb | ) |
Set the status callback.
Set status callback function that will be invoked when a device status serial message is received. The callback will include the status encoded in the serial message. If callback is not required, the callback should be set to nullptr (the default). The callback is invoked when the last character of response message is received from the device.
Callbacks and synchronous mode are set and operate independently.
cb | the address of the callback function in user code. |
void MD_YX5300::setSynchronous | ( | bool | b | ) |
Set or clear Synchronous mode.
Set/reset synchronous mode operation for the library. In synchronous mode, the library will wait for device response message immediately after sending the request. On return the status result of the operation will be available using the getStatus() method. If synchronous mode is disabled, then the code must be retrieved using getStatus() when the check() method returns true.
Synchronous mode and callbacks are set and operate independently.
b | true to set the mode, false to disable. |
void MD_YX5300::setTimeout | ( | uint32_t | t | ) |
Set serial response timeout.
Set the device response timeout in milliseconds. If a message is not received within this time a timeout error status will be generated. The default timeout is 200 milliseconds.
t | timeout in milliseconds |
bool MD_YX5300::shuffle | ( | bool | b | ) |
Control shuffle playing mode.
Set or reset the playing mode to/from random shuffle. At the end of playing each file the device will send a STS_FILE_END unsolicited message.
b | true to enable mode, false to disable. |
bool MD_YX5300::sleep | ( | void | ) |
Set sleep mode.
Enables the MP3 player sleep mode. The device will stop playing but still respond to serial messages. Use wakeUp() to disable sleep mode.
bool MD_YX5300::volume | ( | uint8_t | vol | ) |
Set specified volume.
Set the output volume to the specified level. Maximum volume is volumeMax().
vol | the volume specified [0..MAX_VOLUME]. |
bool MD_YX5300::volumeDec | ( | void | ) |
Decrement the volume.
Decrement the output volume by 1.
bool MD_YX5300::volumeInc | ( | void | ) |
Increment the volume.
Increment the output volume by 1.
uint8_t MD_YX5300::volumeMax | ( | void | ) |
Return the maximum possible volume.
Return the maximum allowable volume level.
bool MD_YX5300::volumeMute | ( | bool | b | ) |
Mute the sound output.
Mute the sound output by suppressing the output from the DAC. The MP3 file will continue playing but will not be heard. To temporarily halt the playing use playPause().
b | true to enable mode, false to disable. |
bool MD_YX5300::volumeQuery | ( | void | ) |
Query the current volume setting.
Request the current volume setting from the device. This is a wrapper alternative for queryVolume(). The response will be in an unsolicited message following the initial request.
bool MD_YX5300::wakeUp | ( | void | ) |
Set awake mode.
Wakes up the MP3 player from sleep mode. Use sleep() to enable sleep mode.
|
static |
Speed for the serial interfac e on the YX5300