trevden - I'd like a way to remove that check for 4 bytes completely.
I think this is a rare case, but having the flexibility to ignore DTR+signature seems to be reasonable.
I'd be okay if the code:
char chkBuf[4];
char cmpBuf[4] = {0x31, 0x45, 0x41, 0x46};
//...
int i;
USB_Bool cmpMatch = TRUE;
for (i=0; i<4; i++) {
if (chkBuf[i] != cmpBuf[i]) {
cmpMatch = FALSE;
}
}
were wrapped up in a little function:
int checkDTRSignature(char chkBuf[]) {
// ... insert here
return cmpMatch;
}
and called via an initialised function pointer:
static int (*cmpDTRSignatureFunction)(char chkBuf[]) = checkDTRSignature;
then the existing function vcomDataRxCb changes to:
if (newBytes >= 4) {
unsigned int target = (unsigned int)usbWaitReset | 0x1;
PMAToUserBufferCopy(chkBuf,VCOM_RX_ADDR,4);
if (cmpDTRSignatureFunction && (*cmpDTRSignatureFunction)(chkBuf)) {
asm volatile("mov r0, %[stack_top] \n\t" // Reset the stack
The cmpDTRSignatureFunction could be set via a little wrapper function that I could call.
I think that is all that is required.
I could write a dummy function:
int dummyCheckDTRSignature(char chkBuf[]) { return 0; }
or just intialise cmpDTRSignatureFunction to NULL and its done.
I could also do smarter things if I wanted to. I would know this function is only being called when DTR has been received, so I could use that for my own purposes.
99% of users might ignore this completely
0.9% of users might just set the cmpDTRSignatureFunction callback to NULL so that DTR is ignored,
and the other 0.1% might do something more.
I don't think it's urgent unless there are people trying to make dataloggers (in which case I want to catch the DTR anyway) or communication gateways (in which case I don't want anything interpreting *anything* in the byte streams) using Maple.
Of course, I'd prefer to switch off the Mac's auto-DTR 'feature', and use DTR as a valid out-of-band signal.
(full disclosure: I am not a member of LeafLabs staff)