1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-24 08:36:14 +01:00

Compare commits

..

No commits in common. "0e9caa11c8b423ce55c1a6ca4144e92fb3569a15" and "c4689795010406fc623b45bccfef79b0d8de3e85" have entirely different histories.

View File

@ -76,6 +76,7 @@ private:
I2CAddress _I2CAddress; I2CAddress _I2CAddress;
I2CRB _rb; I2CRB _rb;
uint8_t _UART_CH; uint8_t _UART_CH;
uint8_t _audioMixer = 0x01; // Default to output amplifier 1
// Communication parameters for the DFPlayer are fixed at 8 bit, No parity, 1 stopbit // Communication parameters for the DFPlayer are fixed at 8 bit, No parity, 1 stopbit
uint8_t WORD_LEN = 0x03; // Value LCR bit 0,1 uint8_t WORD_LEN = 0x03; // Value LCR bit 0,1
uint8_t STOP_BIT = 0x00; // Value LCR bit 2 uint8_t STOP_BIT = 0x00; // Value LCR bit 2
@ -99,8 +100,6 @@ private:
uint8_t _requestedEQValue = NORMAL; uint8_t _requestedEQValue = NORMAL;
uint8_t _currentEQvalue = NORMAL; // start equalizer value uint8_t _currentEQvalue = NORMAL; // start equalizer value
bool _daconCmd = false; bool _daconCmd = false;
uint8_t _audioMixer = 0x01; // Default to output amplifier 1
bool _setamCmd = false; // Set the Audio mixer channel
uint8_t _outbuffer [11]; // DFPlayer command is 10 bytes + 1 byte register address & UART channel uint8_t _outbuffer [11]; // DFPlayer command is 10 bytes + 1 byte register address & UART channel
uint8_t _inbuffer[10]; // expected DFPlayer return 10 bytes uint8_t _inbuffer[10]; // expected DFPlayer return 10 bytes
@ -357,27 +356,6 @@ public:
sendPacket(0x07,0x00,_currentEQvalue); sendPacket(0x07,0x00,_currentEQvalue);
} }
_eqCmd = false; _eqCmd = false;
} else if (_setamCmd == true){ // Set Audio mixer channel
setGPIO(); // Set the audio mixer channel
/*
if (_audioMixer == 1){ // set to audio mixer 1
if (_UART_CH == 0){
TEMP_REG_VAL |= (0x01 << _UART_CH); //Set GPIO pin 0 to high
} else { // must be UART 1
TEMP_REG_VAL |= (0x01 << _UART_CH); //Set GPIO pin 1 to high
}
//_setamCmd = false;
//UART_WriteRegister(REG_IOSTATE, TEMP_REG_VAL);
} else { // set to audio mixer 2
if (_UART_CH == 0){
TEMP_REG_VAL &= (0x00 << _UART_CH); //Set GPIO pin 0 to Low
} else { // must be UART 1
TEMP_REG_VAL &= (0x00 << _UART_CH); //Set GPIO pin 1 to Low
}
//_setamCmd = false;
//UART_WriteRegister(REG_IOSTATE, TEMP_REG_VAL);
}*/
_setamCmd = false;
} else if ((int32_t)currentMicros - _commandSendTime > 1000000) { } else if ((int32_t)currentMicros - _commandSendTime > 1000000) {
// Poll device every second that other commands aren't being sent, // Poll device every second that other commands aren't being sent,
// to check if it's still connected and responding. // to check if it's still connected and responding.
@ -439,7 +417,7 @@ public:
break; break;
case FOLDER: case FOLDER:
_folderCmd = true; _folderCmd = true;
if (volume <= 0 || volume > 99){ // Range checking, valid values 1-99, else default to 1 if (volume <= 0 && volume > 99){ // Range checking
_requestedFolder = 0x01; // if outside range, default to folder 01 _requestedFolder = 0x01; // if outside range, default to folder 01
} else { } else {
_requestedFolder = volume; _requestedFolder = volume;
@ -464,9 +442,9 @@ public:
DIAG(F("I2CDFPlayer: WriteAnalog EQ: cmd: 0x%x, EQ value: 0x%x"), cmd, volume); DIAG(F("I2CDFPlayer: WriteAnalog EQ: cmd: 0x%x, EQ value: 0x%x"), cmd, volume);
#endif #endif
_eqCmd = true; _eqCmd = true;
if (volume <= 0 || volume > 5) { // If out of range, default to NORMAL if (volume <= NORMAL) { // to keep backward compatibility the volume parameter is used for values of the EQ cmd
_requestedEQValue = NORMAL; _requestedEQValue = NORMAL;
} else { // Valid EQ parameter range } else if (volume <= 0x05) { // Validate EQ parameters
_requestedEQValue = volume; _requestedEQValue = volume;
} }
break; break;
@ -479,17 +457,6 @@ public:
#endif #endif
_daconCmd = true; _daconCmd = true;
break; break;
case SETAM: // Set the audio mixer channel to 1 or 2
_setamCmd = true;
#ifdef DIAG_I2CDFplayer_playing
DIAG(F("I2CDFPlayer: WrtieAnalog SETAM: cmd: 0x%x"), cmd);
#endif
if (volume <= 0 || volume > 2) { // If out of range, default to 1
_audioMixer = 1;
} else { // Valid SETAM parameter in range
_audioMixer = volume; // _audioMixer valid values 1 or 2
}
break;
default: default:
break; break;
} }
@ -613,15 +580,12 @@ private:
UART_WriteRegister(REG_IODIR, TEMP_REG_VAL); UART_WriteRegister(REG_IODIR, TEMP_REG_VAL);
UART_ReadRegister(REG_IOSTATE); // Read current state as not to overwrite the other GPIO pins UART_ReadRegister(REG_IOSTATE); // Read current state as not to overwrite the other GPIO pins
TEMP_REG_VAL = _inbuffer[0]; TEMP_REG_VAL = _inbuffer[0];
setGPIO(); // Set the audio mixer channel if (_UART_CH == 0){
/*
if (_UART_CH == 0){ // Set Audio mixer channel
TEMP_REG_VAL |= (0x01 << _UART_CH); //Set GPIO pin 0 to high TEMP_REG_VAL |= (0x01 << _UART_CH); //Set GPIO pin 0 to high
} else { // must be UART 1 } else { // must be UART 1
TEMP_REG_VAL |= (0x01 << _UART_CH); //Set GPIO pin 1 to high TEMP_REG_VAL |= (0x01 << _UART_CH); //Set GPIO pin 1 to high
} }
UART_WriteRegister(REG_IOSTATE, TEMP_REG_VAL); UART_WriteRegister(REG_IOSTATE, TEMP_REG_VAL);
*/
TEMP_REG_VAL = 0x07; // Reset FIFO, clear RX & TX FIFO TEMP_REG_VAL = 0x07; // Reset FIFO, clear RX & TX FIFO
UART_WriteRegister(REG_FCR, TEMP_REG_VAL); UART_WriteRegister(REG_FCR, TEMP_REG_VAL);
TEMP_REG_VAL = 0x00; // Set MCR to all 0, includes Clock divisor TEMP_REG_VAL = 0x00; // Set MCR to all 0, includes Clock divisor
@ -675,29 +639,6 @@ private:
UART_WriteRegister(REG_FCR, TEMP_REG_VAL); UART_WriteRegister(REG_FCR, TEMP_REG_VAL);
} }
// Set or reset GPIO pin 0 and 1 depending on the UART ch
// This function may be modified in a future release to enable all 8 pins to be set or reset with EX-Rail
// for various auxilary functions
void setGPIO(){
UART_ReadRegister(REG_IOSTATE); // Get the current GPIO pins state from the IOSTATE register
TEMP_REG_VAL = _inbuffer[0];
if (_audioMixer == 1){ // set to audio mixer 1
if (_UART_CH == 0){
TEMP_REG_VAL |= (0x01 << _UART_CH); //Set GPIO pin 0 to high
} else { // must be UART 1
TEMP_REG_VAL |= (0x01 << _UART_CH); //Set GPIO pin 1 to high
}
} else { // set to audio mixer 2
if (_UART_CH == 0){
TEMP_REG_VAL &= ~(0x01 << _UART_CH); //Set GPIO pin 0 to Low
} else { // must be UART 1
TEMP_REG_VAL &= ~(0x01 << _UART_CH); //Set GPIO pin 1 to Low
}
}
UART_WriteRegister(REG_IOSTATE, TEMP_REG_VAL);
_setamCmd = false;
}
// Read the Tranmit FIFO Level register (TXLVL), return a single unsigned integer // Read the Tranmit FIFO Level register (TXLVL), return a single unsigned integer
// of nr characters free in the TX FIFO, bit 6:0, 7 not used, set to zero // of nr characters free in the TX FIFO, bit 6:0, 7 not used, set to zero
@ -779,8 +720,7 @@ enum : uint8_t{
STOPPLAY = 0x16, STOPPLAY = 0x16,
EQ = 0x07, // Set equaliser, require parameter NORMAL, POP, ROCK, JAZZ, CLASSIC or BASS EQ = 0x07, // Set equaliser, require parameter NORMAL, POP, ROCK, JAZZ, CLASSIC or BASS
RESET = 0x0C, RESET = 0x0C,
DACON = 0x1A, DACON = 0x1A, // Not a DFLayer command,need to sent 0x1A and 3rd byte to 0x01 in processOutgoing()
SETAM = 0x2A, // Set audio mixer 1 or 2 for this DFPLayer
NORMAL = 0x00, // Equalizer parameters NORMAL = 0x00, // Equalizer parameters
POP = 0x01, POP = 0x01,
ROCK = 0x02, ROCK = 0x02,