From c044098c8d49aa22000e019b3e717e0e31f6b28f Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Wed, 14 Aug 2019 06:36:26 +0200 Subject: [PATCH] Add code for switching the speaker respective their amps on or off. --- include/config.h | 2 ++ include/player.h | 2 ++ src/player.cpp | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/include/config.h b/include/config.h index 4faf1f8..0f5a50f 100644 --- a/include/config.h +++ b/include/config.h @@ -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 diff --git a/include/player.h b/include/player.h index d8a7df0..483e40d 100644 --- a/include/player.h +++ b/include/player.h @@ -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); diff --git a/src/player.cpp b/src/player.cpp index 2962731..1fa744d 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -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; }