Nice XXXXXXXanks a lot for your efforts about MIDI Controller. It's much useful for the smart musical TC project。
<code>static void uart_send(uint8_t *buf, uint8_t len) { uint8_t i; USART_ClearFlag(USART1, USART_FLAG_TC); for(i = 0; i < len; i ++){ USART_SendData(USART1, buf[i]); while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET); } } static void usb_send(uint8_t *buf, uint8_t len) { while(!USB_TC); USB_TC = 0; USB_SIL_Write(ENDP1, buf, len); SetEPTxValid(ENDP1); } int main(void) { uint8_t i, m, buff[4]; Set_System(); USB_Interrupts_Config(); Set_USBClock(); USB_Init(); while(1){ if(bDeviceState == CONFIGURED){ /***** UART->USB Routine ***/ if(MIDI_SendLen){ if(MIDI_SendBuff[0] == 0xF0 && MIDI_SendBuff[MIDI_SendLen - 1] == 0xF7){ /* SysEx */ m = (MIDI_SendLen - 1) / 3; for(i = 0; i <= 1 2 3 m; i ++){ if(i="=" m) switch(midi_sendlen % 3){ case 0: * sysex ends with following bytes buff[0]="0x07;" break; 1: 2: } else starts or continues buff[1]="MIDI_SendBuff[i" 3]; buff[2]="MIDI_SendBuff[1" + buff[3]="MIDI_SendBuff[2" usb_send(buff, 4); for(i="0;" < midi_sendlen; ++) midi_sendbuff[i]="0;" }else general switch(midi_sendbuff[0] & 0xf0){ 0xc0: program change 0xd0: channel if(midi_sendlen>= 2){ buff[0] = MIDI_SendBuff[0] >> 4; buff[1] = MIDI_SendBuff[0]; buff[2] = MIDI_SendBuff[1]; buff[3] = 0; MIDI_SendLen = 0; usb_send(buff, 4); } break; case 0x80: /* Note-off */ case 0x90: /* Note-on */ case 0xA0: /* Poly-KeyPress */ case 0xB0: /* Control Change */ case 0xE0: /* PitchBend Change */ if(MIDI_SendLen >= 3){ buff[0] = MIDI_SendBuff[0] >> 4; buff[1] = MIDI_SendBuff[0]; buff[2] = MIDI_SendBuff[1]; buff[3] = MIDI_SendBuff[2]; MIDI_SendLen = 0; usb_send(buff, 4); } break; default: MIDI_SendLen = 0; } } /*** USB->UART Routine ***/ if(RecvBufNE){ i = 0; do switch(MIDI_RecvBuff[i]){ case 0x05: case 0x0F: uart_send(&MIDI_RecvBuff[i + 1], 1); i += 2; break; case 0x06: case 0x0C: case 0x0D: uart_send(&MIDI_RecvBuff[i + 1], 2); i += 3; break; case 0x04: case 0x07: case 0x08: case 0x09: case 0x0A: case 0x0B: case 0x0E: uart_send(&MIDI_RecvBuff[i + 1], 3); i += 4; break; default: i ++; /* ignore 1 byte */ } while(i < MIDI_RecvLen); RecvBufNE = 0; } } } } </=></code>
时段 | 个数 |
---|---|
{{f.startingTime}}点 - {{f.endTime}}点 | {{f.fileCount}} |
200字以内,仅用于支线交流,主线讨论请采用回复功能。