Loading...
Searching...
No Matches
dfplayer.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 Marian Buschsieweke
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
177#ifndef DFPLAYER_H
178#define DFPLAYER_H
179
180#include <stdbool.h>
181#include <stdint.h>
182
183#include "dfplayer_params.h"
184#include "dfplayer_types.h"
185
186#ifdef __cplusplus
187extern "C" {
188#endif
189
194#define DFPLAYER_WAIT_MS (100U)
195
196#ifdef MODULE_AUTO_INIT_MULTIMEDIA
197
198extern dfplayer_t dfplayer_devs[DFPLAYER_NUMOF];
199
208static inline dfplayer_t * dfplayer_get(unsigned num)
209{
210 if (num < DFPLAYER_NUMOF) {
211 return &dfplayer_devs[num];
212 }
213
214 return NULL;
215}
216
217#endif /* MODULE_AUTO_INIT_MULTIMEDIA */
218
231
241
258 dfplayer_cb_src_t cb_src);
259
279static inline int dfplayer_next(dfplayer_t *dev);
280
300static inline int dfplayer_prev(dfplayer_t *dev);
301
321int dfplayer_step(dfplayer_t *dev, int step);
322
338static inline int dfplayer_set_volume(dfplayer_t *dev, uint8_t volume);
339
352static inline int dfplayer_set_equalizer(dfplayer_t *dev,
353 dfplayer_eq_t equalizer);
354
368
380static inline int dfplayer_enter_standby(dfplayer_t *dev);
381
393static inline int dfplayer_exit_standby(dfplayer_t *dev);
394
406static inline int dfplayer_play(dfplayer_t *dev);
407
419static inline int dfplayer_pause(dfplayer_t *dev);
420
442int dfplayer_play_file(dfplayer_t *dev, uint8_t folder, uint8_t file);
443
463int dfplayer_play_from_mp3(dfplayer_t *dev, uint16_t number);
464
496int dfplayer_play_from_advert(dfplayer_t *dev, uint16_t number);
497
509static inline int dfplayer_stop_advert(dfplayer_t *dev);
510
526static inline int dfplayer_repeat_folder(dfplayer_t *dev, uint8_t folder);
527
542static inline int dfplayer_shuffle_all(dfplayer_t *dev);
543
557static inline int dfplayer_repeat(dfplayer_t *dev, bool repeat);
558
577
590static inline int dfplayer_get_volume(dfplayer_t *dev, uint8_t *volume);
591
604static inline int dfplayer_get_equalizer(dfplayer_t *dev,
605 dfplayer_eq_t *equalizer);
606
619static inline int dfplayer_get_mode(dfplayer_t *dev,
620 dfplayer_mode_t *mode);
621
634static inline int dfplayer_get_version(dfplayer_t *dev, uint16_t *version);
635
648static inline int dfplayer_files_usb(dfplayer_t *dev, uint16_t *files);
649
662static inline int dfplayer_files_sdcard(dfplayer_t *dev, uint16_t *files);
663
676static inline int dfplayer_files_flash(dfplayer_t *dev, uint16_t *files);
677
692static inline int dfplayer_get_fileno_usb(dfplayer_t *dev, uint16_t *fileno);
693
708static inline int dfplayer_get_fileno_sdcard(dfplayer_t *dev, uint16_t *fileno);
709
724static inline int dfplayer_get_fileno_flash(dfplayer_t *dev, uint16_t *fileno);
725
734
746
757
768
769#ifdef __cplusplus
770}
771#endif
772
773/* Include implementation of the static inline functions */
775
776#endif /* DFPLAYER_H */
Header-only functions of the DFPlayer Mini Device driver.
Default configuration for the DFPlayer Mini driver.
#define DFPLAYER_NUMOF
Number of DFPlayer descriptors present.
Types used in the DFPlayer Mini Device Driver.
dfplayer_mode_t
Enumeration of the playback modes supported by the DFPlayer.
dfplayer_source_t
Enumeration of the different sources for playback supported.
uint8_t dfplayer_source_set_t
Set of DFPlayer playback sources.
dfplayer_eq_t
Enumeration of the equalizer settings supported by the DFPlayer.
void(* dfplayer_cb_src_t)(dfplayer_t *dev, dfplayer_source_set_t srcs)
Signature of the function called when a medium was inserted/ejected.
void(* dfplayer_cb_done_t)(dfplayer_t *dev, dfplayer_source_t src, uint16_t track)
Signature of the function called when a playback of track completed.
dfplayer_state_t
Enumeration of the detectable states of the DFPlayer.
static int dfplayer_shuffle_all(dfplayer_t *dev)
Launch shuffle playback of all files.
static int dfplayer_enter_standby(dfplayer_t *dev)
Enter standby mode.
static int dfplayer_files_flash(dfplayer_t *dev, uint16_t *files)
Query the number of files on the NOR flash.
static int dfplayer_files_usb(dfplayer_t *dev, uint16_t *files)
Query the number of files on the USB storage device.
static int dfplayer_get_equalizer(dfplayer_t *dev, dfplayer_eq_t *equalizer)
Query the current equalizer setting of the DFPlayer Mini.
static int dfplayer_stop_advert(dfplayer_t *dev)
Stop playing a file from the ADVERT folder and resume previous playback.
int dfplayer_step(dfplayer_t *dev, int step)
Step forward/backward following the currently used naming scheme.
static int dfplayer_get_mode(dfplayer_t *dev, dfplayer_mode_t *mode)
Query the current playback mode of the DFPlayer Mini.
static void dfplayer_source_set_rm(dfplayer_source_set_t *set, dfplayer_source_t src)
Remove the given source to the given source set.
static int dfplayer_get_fileno_sdcard(dfplayer_t *dev, uint16_t *fileno)
Query the selected file on the SD card.
static int dfplayer_repeat_folder(dfplayer_t *dev, uint8_t folder)
Start playing and repeating the specified folder.
int dfplayer_get_state(dfplayer_t *dev, dfplayer_state_t *state)
Query the state of the DFPlayer Mini.
int dfplayer_play_from_advert(dfplayer_t *dev, uint16_t number)
Start playing the specified number in the ADVERT folder.
static int dfplayer_get_volume(dfplayer_t *dev, uint8_t *volume)
Query the current volume of the DFPlayer Mini.
dfplayer_source_set_t dfplayer_get_sources(dfplayer_t *dev)
Get the set of available playback sources of the given DFPlayer.
static int dfplayer_next(dfplayer_t *dev)
Start playing the next song in the currently used naming scheme.
static int dfplayer_set_equalizer(dfplayer_t *dev, dfplayer_eq_t equalizer)
Apply the given equalizer setting.
static int dfplayer_pause(dfplayer_t *dev)
Pause the playback.
int dfplayer_init(dfplayer_t *dev, const dfplayer_params_t *params)
Initialize a DFPlayer Mini device descriptor.
static int dfplayer_get_version(dfplayer_t *dev, uint16_t *version)
Query the software version running on the DFPlayer Mini.
int dfplayer_play_from_mp3(dfplayer_t *dev, uint16_t number)
Start playing the specified number in the MP3 folder.
static int dfplayer_get_fileno_usb(dfplayer_t *dev, uint16_t *fileno)
Query the selected file on the USB storage device.
static int dfplayer_set_source(dfplayer_t *dev, dfplayer_source_t src)
Apply the given source.
int dfplayer_set_callbacks(dfplayer_t *dev, dfplayer_cb_done_t cb_done, dfplayer_cb_src_t cb_src)
Set/clear the event callbacks of the DFPlayer Mini.
static int dfplayer_get_fileno_flash(dfplayer_t *dev, uint16_t *fileno)
Query the selected file on the NOR flash.
static dfplayer_file_t dfplayer_get_played_file(dfplayer_t *dev)
Get the currently played file and the used naming scheme.
static int dfplayer_play(dfplayer_t *dev)
Start/resume playing.
static int dfplayer_repeat(dfplayer_t *dev, bool repeat)
Enable or disable repeat playback.
static int dfplayer_exit_standby(dfplayer_t *dev)
Exit standby mode.
int dfplayer_play_file(dfplayer_t *dev, uint8_t folder, uint8_t file)
Start playing the specified file in the specified folder.
static int dfplayer_prev(dfplayer_t *dev)
Start playing the previous song in the currently used naming scheme.
static int dfplayer_source_set_contains(dfplayer_source_set_t set, dfplayer_source_t src)
Check if the given source set contains the given source.
static int dfplayer_files_sdcard(dfplayer_t *dev, uint16_t *files)
Query the number of files on the SD card.
static int dfplayer_set_volume(dfplayer_t *dev, uint8_t volume)
Sets the volume to the given value.
static void dfplayer_source_set_add(dfplayer_source_set_t *set, dfplayer_source_t src)
Add the given source to the given source set.
Data structure representing a file on the DFPlayer.
Initialization parameters of a DFPlayer Mini device descriptor.
A DFPlayer Mini device descriptor.