Compare DMAChannel with DMASetting?

duff

Well-known member
I need to compare what DMASetting I currently working with from the DMAChannel I have. Below is a simple example that does nothing but will give the error of: no match "operator =="
Code:
#include "DMAChannel.h"

DMAChannel DMA;
DMASetting ALT1;
DMASetting ALT2;

uint8_t inbuffer1;
uint8_t inbuffer2;
uint8_t outbuffer1;
uint8_t outbuffer2;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  while (!Serial);
  delay(1000);
  Serial.println("Start");
  ALT1.source( inbuffer1 );
  ALT2.source( inbuffer2 );
  ALT1.destination( outbuffer1);
  ALT2.destination( outbuffer2);
  ALT1.interruptAtCompletion( );
  ALT2.interruptAtCompletion( );
  ALT1.replaceSettingsOnCompletion( ALT2 );
  ALT2.replaceSettingsOnCompletion( ALT1 );
  DMA = ALT1;
}

void loop() {
  if (DMA == ALT1) Serial.println("True");[COLOR=#B22222]// errors here[/COLOR]
  else Serial.println("False");
  delay(1000);
}

What I did was add Relation Operator Overloading to DMAChannel.h, but don't like my implementation. I was wondering if any the c++ gurus would have an idea how to do this correctly?

Added to DMAChannel.h:
Code:
bool operator == (const DMASetting &rhs) const {
  if (this->TCD->SADDR == rhs.TCD->SADDR) return true;
  else return false;
}
If i just compare TCD structs for the DMAChannel and DMASetting they do not compare right, so I'm thinking that DMASetting doesn't inherent all the TCD parts so the compare "==" fails but if I just compare the Source Address "SADDR" or Destination Address "DADDR" it works which make sense. I guess I need to dig into what TCD parameters gets copied into DMASettings and what TCD parameters get copied into DMAChannel?
 
ok, I think this would cover most cases where someone would need to see what DMASetting instance is currently being used by DMAChannel:

Added to class DMAChannel in DMAChannel.h
Code:
bool operator == (const DMASetting &rhs) const {
  if ((this->TCD->SADDR == rhs.TCD->SADDR) &&
      (this->TCD->DADDR == rhs.TCD->DADDR) &&
      (this->TCD->SOFF == rhs.TCD->SOFF) &&
      (this->TCD->DOFF == rhs.TCD->DOFF) &&
      (this->TCD->SLAST == rhs.TCD->SLAST) &&
      (this->TCD->DLASTSGA == rhs.TCD->DLASTSGA) &&
      (this->TCD->ATTR == rhs.TCD->ATTR) &&
      (this->TCD->CITER == rhs.TCD->CITER) &&
      (this->TCD->BITER == rhs.TCD->BITER) &&
      (this->TCD->CSR == rhs.TCD->CSR)) return true;
  else return false;
}

of course there is the chance that someone could make two identical DMASettings that would both return true but why would you do that anyway. @PaulStoffregen, would you consider a pull request for this?
 
actually not going to work, crap if you use an array for the source or destination then the above will not work the way I intended:(, back to drawing board.
 
Back
Top