Browse Source

Add availableForWrite() on Teensy 2.0

teensy4-core
PaulStoffregen 9 years ago
parent
commit
9fbebb5145
4 changed files with 30 additions and 19 deletions
  1. +10
    -0
      teensy/HardwareSerial.cpp
  2. +1
    -0
      teensy/HardwareSerial.h
  3. +17
    -19
      usb_serial/usb_api.cpp
  4. +2
    -0
      usb_serial/usb_api.h

+ 10
- 0
teensy/HardwareSerial.cpp View File

return RX_BUFFER_SIZE + head - tail; return RX_BUFFER_SIZE + head - tail;
} }


int HardwareSerial::availableForWrite(void)
{
uint8_t head, tail;

head = rx_buffer_head;
tail = rx_buffer_tail;
if (head >= tail) return TX_BUFFER_SIZE - 1 - head + tail;
return tail - head - 1;
}

int HardwareSerial::peek(void) int HardwareSerial::peek(void)
{ {
uint8_t head, tail; uint8_t head, tail;

+ 1
- 0
teensy/HardwareSerial.h View File

virtual int peek(void); virtual int peek(void);
virtual int read(void); virtual int read(void);
virtual void flush(void); virtual void flush(void);
int availableForWrite(void);
void clear(void); void clear(void);
#if ARDUINO >= 100 #if ARDUINO >= 100
virtual size_t write(uint8_t); virtual size_t write(uint8_t);

+ 17
- 19
usb_serial/usb_api.cpp View File

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

+ 2
- 0
usb_serial/usb_api.h View File

virtual void write(const uint8_t *buffer, uint16_t size); virtual void write(const uint8_t *buffer, uint16_t size);
virtual void write(const char *s) { write((const uint8_t *)s, strlen(s)); } virtual void write(const char *s) { write((const uint8_t *)s, strlen(s)); }
#endif #endif
int availableForWrite(void);
void clear(void);
void send_now(void); void send_now(void);
uint32_t baud(void); uint32_t baud(void);
uint8_t stopbits(void); uint8_t stopbits(void);

Loading…
Cancel
Save