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
187 extern "C" {
188 #endif
189 
194 #define DFPLAYER_WAIT_MS (100U)
195 
196 #ifdef MODULE_AUTO_INIT_MULTIMEDIA
197 
198 extern dfplayer_t dfplayer_devs[DFPLAYER_NUMOF];
199 
208 static 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 
230 int dfplayer_init(dfplayer_t *dev, const dfplayer_params_t *params);
231 
241 
258  dfplayer_cb_src_t cb_src);
259 
279 static inline int dfplayer_next(dfplayer_t *dev);
280 
300 static inline int dfplayer_prev(dfplayer_t *dev);
301 
321 int dfplayer_step(dfplayer_t *dev, int step);
322 
338 static inline int dfplayer_set_volume(dfplayer_t *dev, uint8_t volume);
339 
352 static inline int dfplayer_set_equalizer(dfplayer_t *dev,
353  dfplayer_eq_t equalizer);
354 
367 static inline int dfplayer_set_source(dfplayer_t *dev, dfplayer_source_t src);
368 
380 static inline int dfplayer_enter_standby(dfplayer_t *dev);
381 
393 static inline int dfplayer_exit_standby(dfplayer_t *dev);
394 
406 static inline int dfplayer_play(dfplayer_t *dev);
407 
419 static inline int dfplayer_pause(dfplayer_t *dev);
420 
442 int dfplayer_play_file(dfplayer_t *dev, uint8_t folder, uint8_t file);
443 
463 int dfplayer_play_from_mp3(dfplayer_t *dev, uint16_t number);
464 
496 int dfplayer_play_from_advert(dfplayer_t *dev, uint16_t number);
497 
509 static inline int dfplayer_stop_advert(dfplayer_t *dev);
510 
526 static inline int dfplayer_repeat_folder(dfplayer_t *dev, uint8_t folder);
527 
542 static inline int dfplayer_shuffle_all(dfplayer_t *dev);
543 
557 static inline int dfplayer_repeat(dfplayer_t *dev, bool repeat);
558 
577 
590 static inline int dfplayer_get_volume(dfplayer_t *dev, uint8_t *volume);
591 
604 static inline int dfplayer_get_equalizer(dfplayer_t *dev,
605  dfplayer_eq_t *equalizer);
606 
619 static inline int dfplayer_get_mode(dfplayer_t *dev,
620  dfplayer_mode_t *mode);
621 
634 static inline int dfplayer_get_version(dfplayer_t *dev, uint16_t *version);
635 
648 static inline int dfplayer_files_usb(dfplayer_t *dev, uint16_t *files);
649 
662 static inline int dfplayer_files_sdcard(dfplayer_t *dev, uint16_t *files);
663 
676 static inline int dfplayer_files_flash(dfplayer_t *dev, uint16_t *files);
677 
692 static inline int dfplayer_get_fileno_usb(dfplayer_t *dev, uint16_t *fileno);
693 
708 static inline int dfplayer_get_fileno_sdcard(dfplayer_t *dev, uint16_t *fileno);
709 
724 static inline int dfplayer_get_fileno_flash(dfplayer_t *dev, uint16_t *fileno);
725 
734 
745  dfplayer_source_t src);
746 
755 static inline void dfplayer_source_set_add(dfplayer_source_set_t set,
756  dfplayer_source_t src);
757 
766 static inline void dfplayer_source_set_rm(dfplayer_source_set_t set,
767  dfplayer_source_t src);
768 
769 #ifdef __cplusplus
770 }
771 #endif
772 
773 /* Include implementation of the static inline functions */
774 #include "dfplayer_implementation.h"
775 
776 #endif /* DFPLAYER_H */
777 
dfplayer_mode_t
dfplayer_mode_t
Enumeration of the playback modes supported by the DFPlayer.
Definition: dfplayer_types.h:61
dfplayer_set_volume
static int dfplayer_set_volume(dfplayer_t *dev, uint8_t volume)
Sets the volume to the given value.
dfplayer_step
int dfplayer_step(dfplayer_t *dev, int step)
Step forward/backward following the currently used naming scheme.
dfplayer_next
static int dfplayer_next(dfplayer_t *dev)
Start playing the next song in the currently used naming scheme.
dfplayer_source_set_add
static void dfplayer_source_set_add(dfplayer_source_set_t set, dfplayer_source_t src)
Add the given source to the given source set.
dfplayer_play_from_advert
int dfplayer_play_from_advert(dfplayer_t *dev, uint16_t number)
Start playing the specified number in the ADVERT folder.
dfplayer_get_played_file
static dfplayer_file_t dfplayer_get_played_file(dfplayer_t *dev)
Get the currently played file and the used naming scheme.
dfplayer_set_source
static int dfplayer_set_source(dfplayer_t *dev, dfplayer_source_t src)
Apply the given source.
dfplayer_set_callbacks
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.
dfplayer_stop_advert
static int dfplayer_stop_advert(dfplayer_t *dev)
Stop playing a file from the ADVERT folder and resume previous playback.
dfplayer_get_fileno_flash
static int dfplayer_get_fileno_flash(dfplayer_t *dev, uint16_t *fileno)
Query the selected file on the NOR flash.
dfplayer_eq_t
dfplayer_eq_t
Enumeration of the equalizer settings supported by the DFPlayer.
Definition: dfplayer_types.h:48
dfplayer_shuffle_all
static int dfplayer_shuffle_all(dfplayer_t *dev)
Launch shuffle playback of all files.
dfplayer_get_fileno_usb
static int dfplayer_get_fileno_usb(dfplayer_t *dev, uint16_t *fileno)
Query the selected file on the USB storage device.
dfplayer_get_equalizer
static int dfplayer_get_equalizer(dfplayer_t *dev, dfplayer_eq_t *equalizer)
Query the current equalizer setting of the DFPlayer Mini.
dfplayer_get_mode
static int dfplayer_get_mode(dfplayer_t *dev, dfplayer_mode_t *mode)
Query the current playback mode of the DFPlayer Mini.
dfplayer_play
static int dfplayer_play(dfplayer_t *dev)
Start/resume playing.
dfplayer_types.h
Types used in the DFPlayer Mini Device Driver.
dfplayer_get_fileno_sdcard
static int dfplayer_get_fileno_sdcard(dfplayer_t *dev, uint16_t *fileno)
Query the selected file on the SD card.
dfplayer_set_equalizer
static int dfplayer_set_equalizer(dfplayer_t *dev, dfplayer_eq_t equalizer)
Apply the given equalizer setting.
dfplayer_enter_standby
static int dfplayer_enter_standby(dfplayer_t *dev)
Enter standby mode.
dfplayer_state_t
dfplayer_state_t
Enumeration of the detectable states of the DFPlayer.
Definition: dfplayer_types.h:85
dfplayer_source_t
dfplayer_source_t
Enumeration of the different sources for playback supported.
Definition: dfplayer_types.h:73
dfplayer_implementation.h
Header-only functions of the DFPlayer Mini Device driver.
dfplayer_get_version
static int dfplayer_get_version(dfplayer_t *dev, uint16_t *version)
Query the software version running on the DFPlayer Mini.
dfplayer_files_sdcard
static int dfplayer_files_sdcard(dfplayer_t *dev, uint16_t *files)
Query the number of files on the SD card.
dfplayer_get_sources
dfplayer_source_set_t dfplayer_get_sources(dfplayer_t *dev)
Get the set of available playback sources of the given DFPlayer.
dfplayer_exit_standby
static int dfplayer_exit_standby(dfplayer_t *dev)
Exit standby mode.
DFPLAYER_NUMOF
#define DFPLAYER_NUMOF
Number of DFPlayer descriptors present.
Definition: dfplayer_params.h:66
dfplayer_params_t
Initialization parameters of a DFPlayer Mini device descriptor.
Definition: dfplayer_types.h:136
dfplayer_params.h
Default configuration for the DFPlayer Mini driver.
dfplayer_pause
static int dfplayer_pause(dfplayer_t *dev)
Pause the playback.
dfplayer_get_state
int dfplayer_get_state(dfplayer_t *dev, dfplayer_state_t *state)
Query the state of the DFPlayer Mini.
dfplayer_repeat_folder
static int dfplayer_repeat_folder(dfplayer_t *dev, uint8_t folder)
Start playing and repeating the specified folder.
dfplayer_files_usb
static int dfplayer_files_usb(dfplayer_t *dev, uint16_t *files)
Query the number of files on the USB storage device.
dfplayer_source_set_rm
static void dfplayer_source_set_rm(dfplayer_source_set_t set, dfplayer_source_t src)
Remove the given source to the given source set.
dfplayer_init
int dfplayer_init(dfplayer_t *dev, const dfplayer_params_t *params)
Initialize a DFPlayer Mini device descriptor.
dfplayer_prev
static int dfplayer_prev(dfplayer_t *dev)
Start playing the previous song in the currently used naming scheme.
dfplayer_source_set_contains
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.
dfplayer_play_file
int dfplayer_play_file(dfplayer_t *dev, uint8_t folder, uint8_t file)
Start playing the specified file in the specified folder.
dfplayer_get_volume
static int dfplayer_get_volume(dfplayer_t *dev, uint8_t *volume)
Query the current volume of the DFPlayer Mini.
dfplayer_play_from_mp3
int dfplayer_play_from_mp3(dfplayer_t *dev, uint16_t number)
Start playing the specified number in the MP3 folder.
dfplayer_cb_src_t
void(* dfplayer_cb_src_t)(dfplayer_t *dev, dfplayer_source_set_t srcs)
Signature of the function called when a medium was inserted/ejected.
Definition: dfplayer_types.h:131
dfplayer_repeat
static int dfplayer_repeat(dfplayer_t *dev, bool repeat)
Enable or disable repeat playback.
dfplayer_cb_done_t
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.
Definition: dfplayer_types.h:120
dfplayer_files_flash
static int dfplayer_files_flash(dfplayer_t *dev, uint16_t *files)
Query the number of files on the NOR flash.
dfplayer_file_t
Data structure representing a file on the DFPlayer.
Definition: dfplayer_types.h:170
dfplayer_source_set_t
uint8_t dfplayer_source_set_t
Set of DFPlayer playback sources.
Definition: dfplayer_types.h:104
dfplayer
A DFPlayer Mini device descriptor.
Definition: dfplayer_types.h:184