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 235ef8c39d
commit dcbb42f5ef
2 changed files with 27 additions and 0 deletions

View File

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

View File

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