2019-08-02 21:48:36 +00:00
|
|
|
#pragma once
|
2019-08-04 11:42:07 +00:00
|
|
|
#include "config.h"
|
2019-08-06 18:50:11 +00:00
|
|
|
#include <SPI.h>
|
|
|
|
#include <SD.h>
|
2019-11-10 13:45:33 +00:00
|
|
|
#include "spi_master.h"
|
2019-11-14 19:42:02 +00:00
|
|
|
#include "playlist.h"
|
2019-11-20 04:04:27 +00:00
|
|
|
#include "data_sources.h"
|
2019-08-04 11:42:07 +00:00
|
|
|
|
2019-11-16 22:03:13 +00:00
|
|
|
class Player;
|
|
|
|
|
|
|
|
#include "controller.h"
|
|
|
|
|
2019-08-04 11:42:07 +00:00
|
|
|
#define SCI_MODE 0x00
|
|
|
|
#define SCI_STATUS 0x01
|
2019-11-13 05:51:38 +00:00
|
|
|
#define SCI_BASS 0x02
|
2019-08-04 11:42:07 +00:00
|
|
|
#define SCI_CLOCKF 0x03
|
2019-08-06 18:50:11 +00:00
|
|
|
#define SCI_DECODE_TIME 0x04
|
2019-08-12 18:15:00 +00:00
|
|
|
#define SCI_AUDATA 0x05
|
2019-08-06 18:50:11 +00:00
|
|
|
#define SCI_VOL 0x0B
|
|
|
|
#define SCI_WRAMADDR 0x07
|
|
|
|
#define SCI_WRAM 0x06
|
2019-11-11 16:40:47 +00:00
|
|
|
#define SCI_HDAT0 0x08
|
|
|
|
#define SCI_HDAT1 0x09
|
2019-11-13 05:51:38 +00:00
|
|
|
#define SCI_AIADDR 0x0A
|
2019-11-11 16:40:47 +00:00
|
|
|
#define SCI_AICTRL0 0x0C
|
|
|
|
#define SCI_AICTRL1 0x0D
|
|
|
|
#define SCI_AICTRL2 0x0E
|
|
|
|
#define SCI_AICTRL3 0x0F
|
2019-08-04 11:42:07 +00:00
|
|
|
|
|
|
|
#define CMD_WRITE 0x02
|
|
|
|
#define CMD_READ 0x03
|
|
|
|
|
2019-08-06 18:50:11 +00:00
|
|
|
#define ADDR_ENDBYTE 0x1E06
|
|
|
|
|
2019-11-13 19:13:52 +00:00
|
|
|
#define SM_LAYER12 0x0001
|
2019-11-11 16:40:47 +00:00
|
|
|
#define SM_RESET 0x0004
|
2019-08-06 18:50:11 +00:00
|
|
|
#define SM_CANCEL 0x0008
|
2019-11-13 05:51:38 +00:00
|
|
|
#define SM_SDINEW 0x0800
|
2019-11-11 16:40:47 +00:00
|
|
|
#define SM_ADPCM 0x1000
|
2019-08-06 18:50:11 +00:00
|
|
|
#define SS_DO_NOT_JUMP 0x8000
|
|
|
|
|
2019-08-02 21:48:36 +00:00
|
|
|
class Player {
|
2019-08-04 11:42:07 +00:00
|
|
|
private:
|
2019-08-08 03:31:27 +00:00
|
|
|
enum state { uninitialized, idle, playing, stopping,
|
2019-11-11 16:40:47 +00:00
|
|
|
sleeping, recording };
|
2019-08-04 11:42:07 +00:00
|
|
|
void _reset();
|
|
|
|
void _wait();
|
2019-11-14 05:50:13 +00:00
|
|
|
uint16_t _read_control_register(uint8_t address, bool do_wait=true);
|
|
|
|
void _write_control_register(uint8_t address, uint16_t value, bool do_wait=true);
|
2019-11-11 16:40:47 +00:00
|
|
|
void _write_direct(uint8_t address, uint16_t value);
|
2019-08-06 18:50:11 +00:00
|
|
|
void _write_data(uint8_t* data);
|
|
|
|
uint16_t _read_wram(uint16_t address);
|
|
|
|
state _state = state::uninitialized;
|
|
|
|
void _refill();
|
2019-08-08 03:31:27 +00:00
|
|
|
bool _refill_needed();
|
2019-08-06 18:50:11 +00:00
|
|
|
void _flush_and_cancel();
|
2019-08-09 04:27:33 +00:00
|
|
|
int8_t _get_endbyte();
|
|
|
|
void _flush(uint count, int8_t fill_byte);
|
2019-11-14 19:42:02 +00:00
|
|
|
void _play_file(String filename, uint32_t offset);
|
2019-08-06 18:50:11 +00:00
|
|
|
void _finish_playing();
|
2019-08-14 19:01:01 +00:00
|
|
|
void _finish_stopping(bool turn_speaker_off);
|
2019-08-06 18:50:11 +00:00
|
|
|
void _mute();
|
|
|
|
void _unmute();
|
2019-08-12 18:15:00 +00:00
|
|
|
void _sleep();
|
|
|
|
void _wakeup();
|
2019-11-11 16:40:47 +00:00
|
|
|
void _record();
|
|
|
|
void _patch_adpcm();
|
2019-08-14 04:36:26 +00:00
|
|
|
void _speaker_off();
|
|
|
|
void _speaker_on();
|
2019-08-06 18:50:11 +00:00
|
|
|
|
|
|
|
SPISettings _spi_settings_slow = SPISettings(250000, MSBFIRST, SPI_MODE0);
|
|
|
|
SPISettings _spi_settings_fast = SPISettings(4000000, MSBFIRST, SPI_MODE0);
|
|
|
|
SPISettings* _spi_settings = &_spi_settings_slow;
|
|
|
|
|
2019-11-20 04:04:27 +00:00
|
|
|
DataSource* _file;
|
2019-11-16 22:03:13 +00:00
|
|
|
uint32_t _file_size = 0;
|
2019-08-06 18:50:11 +00:00
|
|
|
uint8_t _buffer[32];
|
2019-11-16 22:03:13 +00:00
|
|
|
uint32_t _current_play_position = 0;
|
|
|
|
Playlist* _current_playlist = NULL;
|
2019-08-06 18:50:11 +00:00
|
|
|
uint _refills;
|
|
|
|
uint8_t _volume;
|
|
|
|
uint16_t _stop_delay;
|
|
|
|
uint32_t _skip_to;
|
2019-11-10 13:45:33 +00:00
|
|
|
SPIMaster* _spi;
|
2019-11-16 22:03:13 +00:00
|
|
|
Controller* _controller;
|
2019-08-12 18:15:00 +00:00
|
|
|
unsigned long _stopped_at;
|
2019-08-02 21:48:36 +00:00
|
|
|
public:
|
2019-11-11 04:32:41 +00:00
|
|
|
Player(SPIMaster* s);
|
2019-11-16 22:03:13 +00:00
|
|
|
void init();
|
|
|
|
void register_controller(Controller* c);
|
2019-08-02 21:48:36 +00:00
|
|
|
void vol_up();
|
|
|
|
void vol_down();
|
|
|
|
void track_next();
|
|
|
|
void track_prev();
|
2019-11-16 22:03:13 +00:00
|
|
|
void set_track(uint8_t track);
|
2019-08-12 18:15:00 +00:00
|
|
|
bool is_playing();
|
2019-11-14 19:42:02 +00:00
|
|
|
bool play();
|
|
|
|
bool play(Playlist* p);
|
2019-08-14 19:01:01 +00:00
|
|
|
void stop(bool turn_speaker_off=true);
|
2019-08-06 18:50:11 +00:00
|
|
|
bool loop();
|
|
|
|
void set_volume(uint8_t vol, bool save = true);
|
2019-11-16 22:03:13 +00:00
|
|
|
String position_json();
|
|
|
|
String json();
|
2019-08-02 21:48:36 +00:00
|
|
|
};
|