mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-03-20 08:40:57 +03:00
add LIDAR chronometer (pre-alpha)
This commit is contained in:
Binary file not shown.
@@ -144,7 +144,7 @@ void USB_send(char *buf){
|
||||
* @param buf (i) - buffer for received data
|
||||
* @param bufsize - its size
|
||||
* @return amount of received bytes
|
||||
*/
|
||||
*
|
||||
int USB_receive(char *buf, int bufsize){
|
||||
if(!bufsize || !idatalen) return 0;
|
||||
USB->CNTR = 0;
|
||||
@@ -163,6 +163,36 @@ int USB_receive(char *buf, int bufsize){
|
||||
}
|
||||
USB->CNTR = USB_CNTR_RESETM | USB_CNTR_CTRM;
|
||||
return sz;
|
||||
}*/
|
||||
|
||||
int USB_receive(char *buf, int bufsize){
|
||||
if(bufsize<1 || !idatalen) return 0;
|
||||
IWDG->KR = IWDG_REFRESH;
|
||||
int stlen = 0;
|
||||
for(int i = 0; i < idatalen; ++i){
|
||||
if(incoming_data[i] == '\n'){
|
||||
stlen = i+1;
|
||||
incoming_data[i] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(stlen == 0) return 0;
|
||||
USB->CNTR = 0;
|
||||
int sz = (stlen > bufsize) ? bufsize : stlen, rest = idatalen - sz;
|
||||
memcpy(buf, incoming_data, sz);
|
||||
if(rest > 0){
|
||||
memmove(incoming_data, &incoming_data[sz], rest);
|
||||
idatalen = rest;
|
||||
}else idatalen = 0;
|
||||
if(ovfl){
|
||||
EP23_Handler(endpoints[2]);
|
||||
uint16_t epstatus = USB->EPnR[2];
|
||||
epstatus = CLEAR_DTOG_RX(epstatus);
|
||||
epstatus = SET_VALID_RX(epstatus);
|
||||
USB->EPnR[2] = epstatus;
|
||||
}
|
||||
USB->CNTR = USB_CNTR_RESETM | USB_CNTR_CTRM;
|
||||
return sz;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user