93 lines
2.3 KiB
C++
93 lines
2.3 KiB
C++
#pragma once
|
|
#include "config.h"
|
|
#include <SPI.h>
|
|
#include <SD.h>
|
|
#include <list>
|
|
#include <map>
|
|
#include <MCP23S17/MCP23S17.h>
|
|
|
|
#define SCI_MODE 0x00
|
|
#define SCI_STATUS 0x01
|
|
#define SCI_CLOCKF 0x03
|
|
#define SCI_DECODE_TIME 0x04
|
|
#define SCI_VOL 0x0B
|
|
#define SCI_WRAMADDR 0x07
|
|
#define SCI_WRAM 0x06
|
|
|
|
#define CMD_WRITE 0x02
|
|
#define CMD_READ 0x03
|
|
|
|
#define ADDR_ENDBYTE 0x1E06
|
|
|
|
#define SM_CANCEL 0x0008
|
|
#define SS_DO_NOT_JUMP 0x8000
|
|
|
|
#define XRESET PIN_VS1053_XRESET
|
|
#define DREQ PIN_VS1053_DREQ
|
|
#define XCS PIN_VS1053_XCS
|
|
#define XDCS PIN_VS1053_XDCS
|
|
|
|
class Player {
|
|
private:
|
|
enum state { uninitialized, idle, playing, stopping,
|
|
system_sound_while_playing, system_sound_while_stopped };
|
|
struct album_state {
|
|
uint8_t index;
|
|
uint32_t position;
|
|
};
|
|
void _check_system_sound(String filename);
|
|
void _reset();
|
|
void _init();
|
|
void _wait();
|
|
uint16_t _read_control_register(uint8_t address);
|
|
void _write_control_register(uint8_t address, uint16_t value);
|
|
void _write_data(uint8_t* data);
|
|
uint16_t _read_wram(uint16_t address);
|
|
state _state = state::uninitialized;
|
|
void _refill();
|
|
bool _refill_needed();
|
|
void _flush_and_cancel();
|
|
int8_t _get_endbyte();
|
|
void _flush(uint count, int8_t fill_byte);
|
|
void _set_last_track(const char* album, uint8_t track, uint32_t position);
|
|
std::map<String, album_state> _last_tracks;
|
|
void _play_file(String filename, uint32_t offset);
|
|
uint32_t _id3_tag_offset(File f);
|
|
void _finish_playing();
|
|
void _finish_stopping();
|
|
void _mute();
|
|
void _unmute();
|
|
|
|
SPISettings _spi_settings_slow = SPISettings(250000, MSBFIRST, SPI_MODE0);
|
|
SPISettings _spi_settings_fast = SPISettings(4000000, MSBFIRST, SPI_MODE0);
|
|
SPISettings* _spi_settings = &_spi_settings_slow;
|
|
|
|
std::list<String> _files_in_dir(String dir);
|
|
String _find_album_dir(String album);
|
|
File _file;
|
|
uint8_t _buffer[32];
|
|
String _playing_album;
|
|
uint8_t _playing_index;
|
|
uint8_t _playing_album_songs;
|
|
uint32_t _current_play_position;
|
|
uint _refills;
|
|
uint8_t _volume;
|
|
uint16_t _stop_delay;
|
|
uint32_t _skip_to;
|
|
MCP* _mcp;
|
|
public:
|
|
Player(MCP* m);
|
|
void vol_up();
|
|
void vol_down();
|
|
void track_next();
|
|
void track_prev();
|
|
|
|
bool play_album(String album);
|
|
bool play_song(String album, uint8_t song_index, uint32_t offset=0);
|
|
void play_system_sound(String filename);
|
|
void stop();
|
|
bool loop();
|
|
void set_volume(uint8_t vol, bool save = true);
|
|
std::list<String> ls(String path);
|
|
};
|