File tree Expand file tree Collapse file tree 1 file changed +15
-12
lines changed Expand file tree Collapse file tree 1 file changed +15
-12
lines changed Original file line number Diff line number Diff line change 29
29
#include "serial.h"
30
30
#include "motion_control.h"
31
31
#include "protocol.h"
32
+ #include "print.h"
32
33
33
34
#define GET_STATUS 0
34
35
#define CLEAR_FEATURE 1
@@ -303,15 +304,23 @@ static uint8_t cdc_line_rtsdtr=0;
303
304
void
304
305
serial_init ()
305
306
{
307
+ usb_configuration = 0 ;
308
+ cdc_line_rtsdtr = 0 ;
309
+ #if 1
306
310
HW_CONFIG ();
307
311
USB_FREEZE (); // enable USB
308
312
PLL_CONFIG (); // config PLL, 16 MHz xtal
309
313
while (!(PLLCSR & (1 <<PLOCK ))) ; // wait for PLL lock
310
314
USB_CONFIG (); // start USB clock
311
- UDCON = 0 ; // enable attach resistor
315
+ #else
316
+ UHWCON = (1 << UVREGE );
317
+ USBCON = (1 << USBE );
318
+ PLLCSR = (1 << PINDIV )|(1 << PLLE )|(1 << PLOCK );
319
+ UECONX = (1 << STALLRQ )|(1 << EPEN );
320
+ USBCON = (1 << USBE )|(1 <<OTGPADE );
321
+ #endif
312
322
313
- usb_configuration = 0 ;
314
- cdc_line_rtsdtr = 0 ;
323
+ UDCON = 0 ; // enable attach resistor
315
324
UDIEN = (1 <<EORSTE )|(1 <<SOFE );
316
325
}
317
326
@@ -398,26 +407,20 @@ uint8_t
398
407
serial_read ()
399
408
{
400
409
uint8_t intr_state , ret = 0 ;
401
- volatile uint8_t c ;
402
410
403
411
if (!usb_configuration )
404
412
return ret ;
405
413
406
414
intr_state = SREG ;
407
415
UENUM = CDC_RX_ENDPOINT ;
408
416
409
- while (!((c = UEINTX ) & (1 <<RWAL )) ) {
410
- if (!(c & (1 <<RXOUTI )))
411
- goto exit ;
412
-
413
- // no data in buffer
417
+ if (UEBCLX <=0 ) {
414
418
UEINTX = 0x6B ;
419
+ goto exit ;
415
420
}
416
421
417
422
// take one byte out of the buffer
418
- ret = UEDATX ;
419
- // if buffer completely used, release it
420
- if (!(UEINTX & (1 <<RWAL ))) UEINTX = 0x6B ;
423
+ ret = UEDATX ; // Read 8byte
421
424
exit :
422
425
SREG = intr_state ;
423
426
return ret ;
You can’t perform that action at this time.
0 commit comments