Loading...
Searching...
No Matches
dfplayer_internal.h File Reference

Internal functions of DFPlayer Mini Device driver. More...

Detailed Description

Internal functions of DFPlayer Mini Device driver.

Author
Marian Buschsieweke maria.nosp@m.n.bu.nosp@m.schsi.nosp@m.ewek.nosp@m.e@ovg.nosp@m.u.de

Definition in file dfplayer_internal.h.

#include <stdint.h>
#include "dfplayer_types.h"
+ Include dependency graph for dfplayer_internal.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

int dfplayer_transceive (dfplayer_t *dev, uint16_t *resp, uint8_t cmd, uint8_t p1, uint8_t p2)
 Exchange a frame with the DFPlayer Mini.
 
int dfplayer_file_cmd (dfplayer_t *dev, uint8_t cmd, uint8_t p1, uint8_t p2)
 Send a command selecting a playback file.
 
int dfplayer_reset (dfplayer_t *dev)
 Reset the DFPlayer Mini MP3 player.
 
void dfplayer_uart_rx_cb (void *dev, uint8_t data)
 UART-ISR handler of the DFPLayer driver.
 
static int dfplayer_cmd_2param (dfplayer_t *dev, uint8_t cmd, uint8_t p1, uint8_t p2)
 Send a command with two parameters to the DFPlayer Mini.
 
static int dfplayer_cmd_1param (dfplayer_t *dev, uint8_t cmd, uint8_t param)
 Send a command with one parameter to the DFPlayer Mini.
 
static int dfplayer_cmd (dfplayer_t *dev, uint8_t cmd)
 Send a command without parameters to the DFPlayer Mini.
 
static int dfplayer_query (dfplayer_t *dev, uint16_t *resp, uint8_t cmd)
 Send a query and receive the response.
 

Function Documentation

◆ dfplayer_cmd()

static int dfplayer_cmd ( dfplayer_t dev,
uint8_t  cmd 
)
inlinestatic

Send a command without parameters to the DFPlayer Mini.

Parameters
devDevice descriptor of the DFPlayer to control
cmdCommand to send
Return values
0Success
-EAGAINDevice responded with error busy
-EIOCommunication error
-ETIMEDOUTReply from the DFPlayer timed out

Definition at line 187 of file dfplayer_internal.h.

◆ dfplayer_cmd_1param()

static int dfplayer_cmd_1param ( dfplayer_t dev,
uint8_t  cmd,
uint8_t  param 
)
inlinestatic

Send a command with one parameter to the DFPlayer Mini.

Parameters
devDevice descriptor of the DFPlayer to control
cmdCommand to send
paramThe parameter to send
Return values
0Success
-EAGAINDevice responded with error busy
-EIOCommunication error
-ETIMEDOUTReply from the DFPlayer timed out

Definition at line 171 of file dfplayer_internal.h.

◆ dfplayer_cmd_2param()

static int dfplayer_cmd_2param ( dfplayer_t dev,
uint8_t  cmd,
uint8_t  p1,
uint8_t  p2 
)
inlinestatic

Send a command with two parameters to the DFPlayer Mini.

Parameters
devDevice descriptor of the DFPlayer to control
cmdCommand to send
p1First parameter to send
p2Second parameter to send
Return values
0Success
-EAGAINDevice responded with error busy
-EIOCommunication error
-ETIMEDOUTReply from the DFPlayer timed out

Definition at line 153 of file dfplayer_internal.h.

◆ dfplayer_file_cmd()

int dfplayer_file_cmd ( dfplayer_t dev,
uint8_t  cmd,
uint8_t  p1,
uint8_t  p2 
)

Send a command selecting a playback file.

Parameters
devDevice descriptor of the DFPlayer to control
cmdCommand starting playback of a file
p1First parameter to send
p2Second parameter to send
Return values
0Success
-EINVALCalled with invalid argument
-EAGAINDevice responded with error busy
-EIOCommunication error
-ETIMEDOUTReply from the DFPlayer timed out
-ENOENTNo such file found
Warning
In contrast to all other functions in this header, this command does not lock and unlock the mutex in dev->mutex internally, but leaves this to the caller. This is required to do the booking of the currently played file consistent with the device state, even if multiple threads control the same DFPlayer.

◆ dfplayer_query()

static int dfplayer_query ( dfplayer_t dev,
uint16_t *  resp,
uint8_t  cmd 
)
inlinestatic

Send a query and receive the response.

Parameters
devDevice descriptor of the DFPlayer to control
respThe response code will be stored here
cmdQuery-command to send
Return values
0Success
-EAGAINDevice responded with error busy
-EIOCommunication error
-ETIMEDOUTReply from the DFPlayer timed out

Definition at line 204 of file dfplayer_internal.h.

◆ dfplayer_reset()

int dfplayer_reset ( dfplayer_t dev)

Reset the DFPlayer Mini MP3 player.

Parameters
devDevice to reset
Return values
0Success
-EINVALCalled with invalid argument
-EAGAINDevice responded with error busy
-EIOCommunication error
-ETIMEDOUTReply from the DFPlayer timed out

◆ dfplayer_transceive()

int dfplayer_transceive ( dfplayer_t dev,
uint16_t *  resp,
uint8_t  cmd,
uint8_t  p1,
uint8_t  p2 
)

Exchange a frame with the DFPlayer Mini.

Parameters
devDevice descriptor of the DFPlayer to control
respOn success the response info is stored if resp != NULL
cmdCommand to send
p1First parameter to send
p2Second parameter to send
Return values
0Success
-EINVALCalled with invalid argument
-EAGAINDevice responded with error busy
-EIOCommunication error
-ETIMEDOUTReply from the DFPlayer timed out

The frame format of the DFPlayer Mini is this:

0 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Start | Version |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Length | Command/Code |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Feedback | Parameter 1 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Parameter 2 | FCS (MSB) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FCS (LSB) | Stop |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

These are the values of the fields when sending a frame to the DFPlayer

Field Value
Start 0x7e
Version 0xff
Length Length of the data (always 6)
Command/Code Command to send
Feedback 0x01 if device should acknowledge command, 0x00 otherwise
Parameter 1 First parameter of the command, or 0x00
Parameter 2 Second parameter of the command, or 0x00
FCS Frame check sequence, 0 - sum(data)
Stop 0xef

These are the values of the fields when receiving a frame from the DFPlayer

Field Value
Start 0x7e
Version 0xff
Length Length of the data (always 6)
Command/Code Response code (0x41 = success, 0x40 = error, 0x3* = event)
Feedback 0x00
Parameter 1 Additional info (most significant byte)
Parameter 2 Additional info (least significant byte)
FCS Frame check sequence, 0 - sum(data)
Stop 0xef

◆ dfplayer_uart_rx_cb()

void dfplayer_uart_rx_cb ( void *  dev,
uint8_t  data 
)

UART-ISR handler of the DFPLayer driver.

Parameters
devDFPlayer device descriptor for which a byte was received
dataThe byte received over UART