Add code for switching the speaker respective their amps on or off.

This commit is contained in:
Fabian Schlenz 2019-08-14 06:36:26 +02:00
parent 1de12c16ed
commit c044098c8d
3 changed files with 29 additions and 0 deletions

View File

@ -37,6 +37,8 @@
#define PIN_VS1053_XDCS D1
#define PIN_VS1053_DREQ D2
#define PIN_RC522_CS D0
#define SPEAKER_L 15
#define SPEAKER_R 14
#define PIN_BTN_VOL_UP D4
#define PIN_BTN_VOL_DOWN D5

View File

@ -62,6 +62,8 @@ private:
void _unmute();
void _sleep();
void _wakeup();
void _speaker_off();
void _speaker_on();
SPISettings _spi_settings_slow = SPISettings(250000, MSBFIRST, SPI_MODE0);
SPISettings _spi_settings_fast = SPISettings(4000000, MSBFIRST, SPI_MODE0);

View File

@ -6,18 +6,25 @@
//Player::_spi_settings
Player::Player(MCP* m) {
SPIMaster::enable(PIN_MCP);
_mcp = m;
_mcp->pinMode(XRESET, OUTPUT);
_mcp->digitalWrite(XRESET, HIGH);
_mcp->pinMode(SPEAKER_L, OUTPUT);
_mcp->pinMode(SPEAKER_R, OUTPUT);
_speaker_off();
SPIMaster::disable();
pinMode(DREQ, INPUT);
_init();
}
void Player::_reset() {
SPIMaster::enable(PIN_MCP);
_mcp->digitalWrite(XRESET, LOW);
delay(100);
_mcp->digitalWrite(XRESET, HIGH);
SPIMaster::disable();
delay(100);
_state = uninitialized;
_spi_settings = &_spi_settings_slow; // After reset, communication has to be slow
@ -72,8 +79,25 @@ void Player::_init() {
_state = idle;
}
void Player::_speaker_off() {
DEBUG("Speaker off\n");
SPIMaster::enable(PIN_MCP);
_mcp->digitalWrite(SPEAKER_R, LOW);
_mcp->digitalWrite(SPEAKER_L, LOW);
SPIMaster::disable();
}
void Player::_speaker_on() {
DEBUG("Speaker on\n");
SPIMaster::enable(PIN_MCP);
_mcp->digitalWrite(SPEAKER_R, HIGH);
_mcp->digitalWrite(SPEAKER_L, HIGH);
SPIMaster::disable();
}
void Player::_sleep() {
DEBUG("VS1053 going to sleep.\n");
_speaker_off();
_write_control_register(SCI_CLOCKF, 0x0000);
_spi_settings = &_spi_settings_slow;
_write_control_register(SCI_AUDATA, 0x0010);
@ -89,6 +113,7 @@ void Player::_wakeup() {
_write_control_register(SCI_AUDATA, 0x0000);
_write_control_register(SCI_CLOCKF, 0x6000);
delay(10);
_speaker_on();
_spi_settings = &_spi_settings_fast;
_state = idle;
}