|  |  |  |  |  |  | 
														
													
														
															|  |  | return c; |  |  | return c; | 
														
													
														
															|  |  | } |  |  | } | 
														
													
														
															|  |  | 
 |  |  | 
 | 
														
													
														
															|  |  | #if ARDUINO >= 100 |  |  |  | 
														
													
														
															|  |  | size_t usb_serial_class::readBytes(char *buffer, size_t length) |  |  | size_t usb_serial_class::readBytes(char *buffer, size_t length) | 
														
													
														
															|  |  | { |  |  | { | 
														
													
														
															|  |  | size_t count=0; |  |  | size_t count=0; | 
														
													
												
													
														
															|  |  |  |  |  |  | 
														
													
														
															|  |  | setReadError(); |  |  | setReadError(); | 
														
													
														
															|  |  | return count; |  |  | return count; | 
														
													
														
															|  |  | } |  |  | } | 
														
													
														
															|  |  | #endif |  |  |  | 
														
													
														
															|  |  | 
 |  |  | 
 | 
														
													
														
															|  |  | 
 |  |  | 
 | 
														
													
														
															|  |  | #if ARDUINO >= 100 |  |  |  | 
														
													
														
															|  |  | void usb_serial_class::flush() |  |  | void usb_serial_class::flush() | 
														
													
														
															|  |  | { |  |  | { | 
														
													
														
															|  |  | send_now(); |  |  | send_now(); | 
														
													
														
															|  |  | } |  |  | } | 
														
													
														
															|  |  | #else |  |  |  | 
														
													
														
															|  |  |  |  |  | 
 | 
														
													
														
															|  |  |  |  |  | 
 | 
														
													
														
															|  |  | // discard any buffered input |  |  | // discard any buffered input | 
														
													
														
															|  |  | void usb_serial_class::flush() |  |  |  | 
														
													
														
															|  |  |  |  |  | void usb_serial_class::clear() | 
														
													
														
															|  |  | { |  |  | { | 
														
													
														
															|  |  | uint8_t intr_state; |  |  | uint8_t intr_state; | 
														
													
														
															|  |  | 
 |  |  | 
 | 
														
													
												
													
														
															|  |  |  |  |  |  | 
														
													
														
															|  |  | } |  |  | } | 
														
													
														
															|  |  | peek_buf = -1; |  |  | peek_buf = -1; | 
														
													
														
															|  |  | } |  |  | } | 
														
													
														
															|  |  | #endif |  |  |  | 
														
													
														
															|  |  |  |  |  |  | 
														
													
														
															|  |  | 
 |  |  | 
 | 
														
													
														
															|  |  | #if 0 |  |  | #if 0 | 
														
													
														
															|  |  | // transmit a character. |  |  | // transmit a character. | 
														
													
												
													
														
															|  |  |  |  |  |  | 
														
													
														
															|  |  | #endif |  |  | #endif | 
														
													
														
															|  |  | 
 |  |  | 
 | 
														
													
														
															|  |  | 
 |  |  | 
 | 
														
													
														
															|  |  |  |  |  | int usb_serial_class::availableForWrite() | 
														
													
														
															|  |  |  |  |  | { | 
														
													
														
															|  |  |  |  |  | uint8_t intr_state, write_size; | 
														
													
														
															|  |  |  |  |  | 
 | 
														
													
														
															|  |  |  |  |  | if (!usb_configuration) return 0; | 
														
													
														
															|  |  |  |  |  | intr_state = SREG; | 
														
													
														
															|  |  |  |  |  | cli(); | 
														
													
														
															|  |  |  |  |  | UENUM = CDC_TX_ENDPOINT; | 
														
													
														
															|  |  |  |  |  | write_size = CDC_TX_SIZE - UEBCLX; | 
														
													
														
															|  |  |  |  |  | SREG = intr_state; | 
														
													
														
															|  |  |  |  |  | return write_size; | 
														
													
														
															|  |  |  |  |  | } | 
														
													
														
															|  |  |  |  |  | 
 | 
														
													
														
															|  |  | // transmit a block of data |  |  | // transmit a block of data | 
														
													
														
															|  |  | #if ARDUINO >= 100 |  |  |  | 
														
													
														
															|  |  | size_t usb_serial_class::write(const uint8_t *buffer, uint16_t size) |  |  | size_t usb_serial_class::write(const uint8_t *buffer, uint16_t size) | 
														
													
														
															|  |  | #else |  |  |  | 
														
													
														
															|  |  | #define setWriteError() |  |  |  | 
														
													
														
															|  |  | void usb_serial_class::write(const uint8_t *buffer, uint16_t size) |  |  |  | 
														
													
														
															|  |  | #endif |  |  |  | 
														
													
														
															|  |  | { |  |  | { | 
														
													
														
															|  |  | uint8_t timeout, intr_state, write_size; |  |  | uint8_t timeout, intr_state, write_size; | 
														
													
														
															|  |  | #if ARDUINO >= 100 |  |  |  | 
														
													
														
															|  |  | size_t count=0; |  |  | size_t count=0; | 
														
													
														
															|  |  | #endif |  |  |  | 
														
													
														
															|  |  | 
 |  |  | 
 | 
														
													
														
															|  |  | // if we're not online (enumerated and configured), error |  |  | // if we're not online (enumerated and configured), error | 
														
													
														
															|  |  | if (!usb_configuration) { |  |  | if (!usb_configuration) { | 
														
													
												
													
														
															|  |  |  |  |  |  | 
														
													
														
															|  |  | write_size = CDC_TX_SIZE - UEBCLX; |  |  | write_size = CDC_TX_SIZE - UEBCLX; | 
														
													
														
															|  |  | if (write_size > size) write_size = size; |  |  | if (write_size > size) write_size = size; | 
														
													
														
															|  |  | size -= write_size; |  |  | size -= write_size; | 
														
													
														
															|  |  | #if ARDUINO >= 100 |  |  |  | 
														
													
														
															|  |  | count += write_size; |  |  | count += write_size; | 
														
													
														
															|  |  | #endif |  |  |  | 
														
													
														
															|  |  | 
 |  |  | 
 | 
														
													
														
															|  |  | #define ASM_COPY1(src, dest, tmp) "ld " tmp ", " src "\n\t" "st " dest ", " tmp "\n\t" |  |  | #define ASM_COPY1(src, dest, tmp) "ld " tmp ", " src "\n\t" "st " dest ", " tmp "\n\t" | 
														
													
														
															|  |  | #define ASM_COPY2(src, dest, tmp) ASM_COPY1(src, dest, tmp) ASM_COPY1(src, dest, tmp) |  |  | #define ASM_COPY2(src, dest, tmp) ASM_COPY1(src, dest, tmp) ASM_COPY1(src, dest, tmp) | 
														
													
												
													
														
															|  |  |  |  |  |  | 
														
													
														
															|  |  | } |  |  | } | 
														
													
														
															|  |  | SREG = intr_state; |  |  | SREG = intr_state; | 
														
													
														
															|  |  | end: |  |  | end: | 
														
													
														
															|  |  | #if ARDUINO >= 100 |  |  |  | 
														
													
														
															|  |  | return count; |  |  | return count; | 
														
													
														
															|  |  | #else |  |  |  | 
														
													
														
															|  |  | return; |  |  |  | 
														
													
														
															|  |  | #endif |  |  |  | 
														
													
														
															|  |  | } |  |  | } | 
														
													
														
															|  |  | 
 |  |  | 
 | 
														
													
														
															|  |  | // transmit a string |  |  | // transmit a string |