Internal functions of DFPlayer Mini Device driver.
More...
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"
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. More...
|
|
int | dfplayer_file_cmd (dfplayer_t *dev, uint8_t cmd, uint8_t p1, uint8_t p2) |
| Send a command selecting a playback file. More...
|
|
int | dfplayer_reset (dfplayer_t *dev) |
| Reset the DFPlayer Mini MP3 player. More...
|
|
void | dfplayer_uart_rx_cb (void *dev, uint8_t data) |
| UART-ISR handler of the DFPLayer driver. More...
|
|
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. More...
|
|
static int | dfplayer_cmd_1param (dfplayer_t *dev, uint8_t cmd, uint8_t param) |
| Send a command with one parameter to the DFPlayer Mini. More...
|
|
static int | dfplayer_cmd (dfplayer_t *dev, uint8_t cmd) |
| Send a command without parameters to the DFPlayer Mini. More...
|
|
static int | dfplayer_query (dfplayer_t *dev, uint16_t *resp, uint8_t cmd) |
| Send a query and receive the response. More...
|
|
◆ dfplayer_cmd()
static int dfplayer_cmd |
( |
dfplayer_t * |
dev, |
|
|
uint8_t |
cmd |
|
) |
| |
|
inlinestatic |
Send a command without parameters to the DFPlayer Mini.
- Parameters
-
dev | Device descriptor of the DFPlayer to control |
cmd | Command to send |
- Return values
-
0 | Success |
-EAGAIN | Device responded with error busy |
-EIO | Communication error |
-ETIMEDOUT | Reply 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
-
dev | Device descriptor of the DFPlayer to control |
cmd | Command to send |
param | The parameter to send |
- Return values
-
0 | Success |
-EAGAIN | Device responded with error busy |
-EIO | Communication error |
-ETIMEDOUT | Reply 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
-
dev | Device descriptor of the DFPlayer to control |
cmd | Command to send |
p1 | First parameter to send |
p2 | Second parameter to send |
- Return values
-
0 | Success |
-EAGAIN | Device responded with error busy |
-EIO | Communication error |
-ETIMEDOUT | Reply 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
-
dev | Device descriptor of the DFPlayer to control |
cmd | Command starting playback of a file |
p1 | First parameter to send |
p2 | Second parameter to send |
- Return values
-
0 | Success |
-EINVAL | Called with invalid argument |
-EAGAIN | Device responded with error busy |
-EIO | Communication error |
-ETIMEDOUT | Reply from the DFPlayer timed out |
-ENOENT | No 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
-
dev | Device descriptor of the DFPlayer to control |
resp | The response code will be stored here |
cmd | Query-command to send |
- Return values
-
0 | Success |
-EAGAIN | Device responded with error busy |
-EIO | Communication error |
-ETIMEDOUT | Reply from the DFPlayer timed out |
Definition at line 204 of file dfplayer_internal.h.
◆ dfplayer_reset()
Reset the DFPlayer Mini MP3 player.
- Parameters
-
- Return values
-
0 | Success |
-EINVAL | Called with invalid argument |
-EAGAIN | Device responded with error busy |
-EIO | Communication error |
-ETIMEDOUT | Reply 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
-
dev | Device descriptor of the DFPlayer to control |
resp | On success the response info is stored if resp != NULL |
cmd | Command to send |
p1 | First parameter to send |
p2 | Second parameter to send |
- Return values
-
0 | Success |
-EINVAL | Called with invalid argument |
-EAGAIN | Device responded with error busy |
-EIO | Communication error |
-ETIMEDOUT | Reply 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
-
dev | DFPlayer device descriptor for which a byte was received |
data | The byte received over UART |