fixed some problems with USB

This commit is contained in:
2025-04-02 16:09:27 +03:00
parent e5b3edeffa
commit c449cb7108
4 changed files with 17 additions and 7 deletions

View File

@@ -223,6 +223,7 @@ void usb_vendor_request(config_pack_t *req, uint8_t _U_ *data, uint16_t _U_ data
int USB_sendall(){
while(lastdsz > 0){
if(!CDCready) return FALSE;
IWDG->KR = IWDG_REFRESH;
}
return TRUE;
}
@@ -232,13 +233,14 @@ int USB_send(const uint8_t *buf, int len){
if(!buf || !CDCready || !len) return FALSE;
DBG("send");
while(len){
IWDG->KR = IWDG_REFRESH;
int a = RB_write((ringbuffer*)&rbout, buf, len);
if(lastdsz == 0) send_next(); // need to run manually - all data sent, so no IRQ on IN
if(a > 0){
len -= a;
buf += a;
} else if (a < 0) continue; // do nothing if buffer is in reading state
if(lastdsz == 0) send_next(); // need to run manually - all data sent, so no IRQ on IN
}
}
return TRUE;
}
@@ -246,9 +248,10 @@ int USB_putbyte(uint8_t byte){
if(!CDCready) return FALSE;
int l = 0;
while((l = RB_write((ringbuffer*)&rbout, &byte, 1)) != 1){
IWDG->KR = IWDG_REFRESH;
if(lastdsz == 0) send_next(); // need to run manually - all data sent, so no IRQ on IN
if(l < 0) continue;
}
if(lastdsz == 0) send_next(); // need to run manually - all data sent, so no IRQ on IN
return TRUE;
}