Pārlūkot izejas kodu

Add availableForWrite() on Teensy 2.0

main
PaulStoffregen pirms 9 gadiem
vecāks
revīzija
9fbebb5145
4 mainītis faili ar 30 papildinājumiem un 19 dzēšanām
  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 Parādīt failu

@@ -91,6 +91,16 @@ int HardwareSerial::available(void)
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)
{
uint8_t head, tail;

+ 1
- 0
teensy/HardwareSerial.h Parādīt failu

@@ -17,6 +17,7 @@ public:
virtual int peek(void);
virtual int read(void);
virtual void flush(void);
int availableForWrite(void);
void clear(void);
#if ARDUINO >= 100
virtual size_t write(uint8_t);

+ 17
- 19
usb_serial/usb_api.cpp Parādīt failu

@@ -131,7 +131,6 @@ int usb_serial_class::read(void)
return c;
}

#if ARDUINO >= 100
size_t usb_serial_class::readBytes(char *buffer, size_t length)
{
size_t count=0;
@@ -173,17 +172,16 @@ size_t usb_serial_class::readBytes(char *buffer, size_t length)
setReadError();
return count;
}
#endif


#if ARDUINO >= 100
void usb_serial_class::flush()
{
send_now();
}
#else


// discard any buffered input
void usb_serial_class::flush()
void usb_serial_class::clear()
{
uint8_t intr_state;

@@ -198,7 +196,7 @@ void usb_serial_class::flush()
}
peek_buf = -1;
}
#endif

#if 0
// transmit a character.
@@ -251,18 +249,24 @@ void usb_serial_class::write(uint8_t c)
#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
#if ARDUINO >= 100
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;
#if ARDUINO >= 100
size_t count=0;
#endif

// if we're not online (enumerated and configured), error
if (!usb_configuration) {
@@ -314,9 +318,7 @@ void usb_serial_class::write(const uint8_t *buffer, uint16_t size)
write_size = CDC_TX_SIZE - UEBCLX;
if (write_size > size) write_size = size;
size -= write_size;
#if ARDUINO >= 100
count += write_size;
#endif

#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)
@@ -368,11 +370,7 @@ void usb_serial_class::write(const uint8_t *buffer, uint16_t size)
}
SREG = intr_state;
end:
#if ARDUINO >= 100
return count;
#else
return;
#endif
}

// transmit a string

+ 2
- 0
usb_serial/usb_api.h Parādīt failu

@@ -23,6 +23,8 @@ public:
virtual void write(const uint8_t *buffer, uint16_t size);
virtual void write(const char *s) { write((const uint8_t *)s, strlen(s)); }
#endif
int availableForWrite(void);
void clear(void);
void send_now(void);
uint32_t baud(void);
uint8_t stopbits(void);

Notiek ielāde…
Atcelt
Saglabāt