@@ -16,40 +16,29 @@ bool arduino_serial_platform_open()
1616{
1717 // Place here your initialization platform code
1818 // Return true if success
19+ while(!vcp_is_connected()){}
1920 return vcp_is_connected();
2021}
2122
2223bool arduino_serial_platform_close()
2324{
24- // Place here your closing platform code
25- // Return true if success
2625 return true;
27-
2826}
2927
3028size_t arduino_serial_platform_write(uint8_t* buf, size_t len, uint8_t* errcode)
3129{
32- // Place here your writing bytes platform code
33- // Return number of bytes written
3430 (void) errcode;
35- for(size_t i = 0; i < len; i++){
36- vcp_putch(buf[i]);
37- while( vcp_is_transmitted() == 0 );
38- }
39-
40- return len;
31+ return vcp_write(buf, len);;
4132}
4233
4334size_t arduino_serial_platform_read(uint8_t* buf, size_t len, int timeout, uint8_t* errcode)
4435{
45- // Place here your reading bytes platform code
46- // Return number of bytes read (max bytes: len)
4736 (void) errcode;
4837 uint32_t start_time = drv_micros() * 1000;
4938 size_t readed = 0;
5039
51- while((( drv_micros()*1000) - start_time) < (uint32_t) timeout){
52- while(vcp_is_available()){
40+ while((readed < len) && ((( drv_micros()*1000) - start_time) < (uint32_t) timeout) ){
41+ while((readed < len) && vcp_is_available()){
5342 buf[readed++] = vcp_getch();
5443 }
5544 }
0 commit comments