void USBCtrHandler(void)
{
uint8_t epindex = heap.istr & USB_ISTR_EP_ID;
uint16_t epr = USB->EPR[epindex];
if(epindex == 0) {
if((heap.istr & USB_ISTR_DIR) == 0) {
if(heap.devAddress != 0) {
USB->DADDR = USB_DADDR_EF | heap.devAddress;
heap.devAddress = 0;
}
if(heap.cntTx != 0) {
USBWriteEP(0);
USBStatusEP(epindex, USB_EP_TX_VALID, TX);
}
USB->EPR[0] &= 0x870f;
} else {
if((epr & USB_EP_SETUP) != 0) {
USBReadEP(0, (uint8_t *)heap.buffSetup, 8);
USBRequest(&SetupPacket, (uint8_t *)heap.buffSetup);
USBSetup();
} else if((epr & USB_EP_CTR_RX) != 0){
}
USB->EPR[0] &= 0x78f;
USBStatusEP(epindex, USB_EP_RX_VALID, RX);
}
} else if(epindex == 1){
if((heap.istr & USB_ISTR_DIR) == 0) {
USB->EPR[epindex] &= ~USB_EP_CTR_TX;
} else {
USB->EPR[epindex] &= ~USB_EP_CTR_RX;
USBReadEP(epindex, (uint8_t *)heap.buffRx, 64);
USBStatusEP(epindex, USB_EP_RX_VALID, RX);
// start = atof((const char*)heap.buffRx);
}
} else if(epindex == 2){
USB->EPR[epindex] &= ~USB_EP_CTR_RX;
USBReadEP(epindex, (uint8_t *)heap.buffRx, 2);
USBStatusEP(epindex, USB_EP_RX_VALID, RX);
cmd = atoi((const char*)heap.buffRx);
GPIOC->ODR ^= GPIO_ODR_ODR13;
}
}