I am using a simple midi library for ch55x boards. Midi out works fine, but midi in doesn’t.
The library correctly handles the incoming message, but things go wrong (empty values) when data is passed on to the callback function.
In the sketch I have:
void onNoteOn(__xdata uint8_t ch, __xdata uint8_t note, __xdata uint8_t vel) {
sendNoteOn(ch,note,vel); // loopback
USBSerial_println("onNoteOn");
}
With the callback registered in setup:
setHdlNoteOn(onNoteOn);
The library has:
hdlMidiMessage cbNoteOn;
hdlNoteOff cbNoteOff;
hdlMidiMessage cbCtlChange;
void setHdlNoteOn(hdlMidiMessage pfunc){
cbNoteOn = pfunc;
}
void processMidiMessage(){
uint8_t cnt, kindmessage;
uint8_t len = USBMIDIAvailable();
uint8_t *p;
if(len > 0){
memcpy(rcvBuffer,Ep2Buffer+32,USBByteCountEP3);
rcvIndex = 0;
rcvLength = USBByteCountEP3;
UEP3_CTRL = UEP3_CTRL & ~ MASK_UEP_R_RES | UEP_R_RES_ACK;
USBByteCountEP3 = 0;
for(cnt=0;cnt<rcvLength;cnt+=4){
p = (uint8_t *)(rcvBuffer + cnt);
kindmessage = checkMidiMessage(p);
if(kindmessage == 1){
if(cbNoteOff != NULL){
(*cbNoteOff)(*(p+1)&0x0f,*(p+2)&0x7f);
}
}else if(kindmessage == 2){
if(cbNoteOn != NULL){
(*cbNoteOn)(*(p+1)&0x0f,*(p+2)&0x7f,*(p+3)&0x7f);
}
}else if(kindmessage == 3){
if(cbCtlChange != NULL){
(*cbCtlChange)(*(p+1)&0x0f,*(p+2)&0x7f,*(p+3)&0x7f);
}
}
}
}
}
The data is present in processMidiMessage (both in rcvMessage and p, just before handin stuff over to
(*cbNoteOn)(*(p+1)&0x0f,*(p+2)&0x7f,*(p+3)&0x7f);
Ch, note and vel are zero when the callback is reached in the sketch.
I have searched extensively, gotten co-pilot to help me etc, but this is a mix of pointers, sdcc, weird mcs51 memorymap that goes beyond my capabilities. Can anybody help me out?