diff options
-rwxr-xr-x | cores/arduino/Arduino.h | 1 | ||||
-rw-r--r-- | cores/arduino/CDC.cpp | 75 | ||||
-rw-r--r-- | cores/arduino/USBAPI.h | 5 | ||||
-rw-r--r-- | cores/arduino/USBCore.cpp | 7 | ||||
-rw-r--r-- | cores/arduino/main.cpp | 7 | ||||
-rwxr-xr-x[-rw-r--r--] | firmwares/wifishield/scripts/ArduinoWifiShield_upgrade_mac.sh | 2 | ||||
-rw-r--r-- | variants/leonardo/pins_arduino.h | 2 | ||||
-rw-r--r-- | variants/mega/pins_arduino.h | 2 | ||||
-rw-r--r-- | variants/robot_control/pins_arduino.h | 2 | ||||
-rw-r--r-- | variants/robot_motor/pins_arduino.h | 2 | ||||
-rw-r--r-- | variants/standard/pins_arduino.h | 2 |
11 files changed, 46 insertions, 61 deletions
diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index 93a3525..425dfcb 100755 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -113,6 +113,7 @@ typedef uint8_t boolean; typedef uint8_t byte; void init(void); +void initVariant(void); void pinMode(uint8_t, uint8_t); void digitalWrite(uint8_t, uint8_t); diff --git a/cores/arduino/CDC.cpp b/cores/arduino/CDC.cpp index e1e859d..aae91c2 100644 --- a/cores/arduino/CDC.cpp +++ b/cores/arduino/CDC.cpp @@ -23,21 +23,6 @@ #if defined(USBCON) #ifdef CDC_ENABLED -#if (RAMEND < 1000) -#define SERIAL_BUFFER_SIZE 16 -#else -#define SERIAL_BUFFER_SIZE 64 -#endif - -struct ring_buffer -{ - unsigned char buffer[SERIAL_BUFFER_SIZE]; - volatile int head; - volatile int tail; -}; - -ring_buffer cdc_rx_buffer = { { 0 }, 0, 0}; - typedef struct { u32 dwDTERate; @@ -129,68 +114,43 @@ bool WEAK CDC_Setup(Setup& setup) } -int _serialPeek = -1; void Serial_::begin(unsigned long baud_count) { + peek_buffer = -1; } void Serial_::begin(unsigned long baud_count, byte config) { + peek_buffer = -1; } void Serial_::end(void) { } -void Serial_::accept(void) -{ - ring_buffer *buffer = &cdc_rx_buffer; - int i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE; - - // if we should be storing the received character into the location - // just before the tail (meaning that the head would advance to the - // current location of the tail), we're about to overflow the buffer - // and so we don't write the character or advance the head. - - // while we have room to store a byte - while (i != buffer->tail) { - int c = USB_Recv(CDC_RX); - if (c == -1) - break; // no more data - buffer->buffer[buffer->head] = c; - buffer->head = i; - - i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE; - } -} - int Serial_::available(void) { - ring_buffer *buffer = &cdc_rx_buffer; - return (unsigned int)(SERIAL_BUFFER_SIZE + buffer->head - buffer->tail) % SERIAL_BUFFER_SIZE; + if (peek_buffer >= 0) { + return 1 + USB_Available(CDC_RX); + } + return USB_Available(CDC_RX); } int Serial_::peek(void) { - ring_buffer *buffer = &cdc_rx_buffer; - if (buffer->head == buffer->tail) { - return -1; - } else { - return buffer->buffer[buffer->tail]; - } + if (peek_buffer < 0) + peek_buffer = USB_Recv(CDC_RX); + return peek_buffer; } int Serial_::read(void) { - ring_buffer *buffer = &cdc_rx_buffer; - // if the head isn't ahead of the tail, we don't have any characters - if (buffer->head == buffer->tail) { - return -1; - } else { - unsigned char c = buffer->buffer[buffer->tail]; - buffer->tail = (unsigned int)(buffer->tail + 1) % SERIAL_BUFFER_SIZE; + if (peek_buffer >= 0) { + int c = peek_buffer; + peek_buffer = -1; return c; - } + } + return USB_Recv(CDC_RX); } void Serial_::flush(void) @@ -200,6 +160,11 @@ void Serial_::flush(void) size_t Serial_::write(uint8_t c) { + return write(&c, 1); +} + +size_t Serial_::write(const uint8_t *buffer, size_t size) +{ /* only try to send bytes if the high-level CDC connection itself is open (not just the pipe) - the OS should set lineState when the port is opened and clear lineState when the port is closed. @@ -210,7 +175,7 @@ size_t Serial_::write(uint8_t c) // open connection isn't broken cleanly (cable is yanked out, host dies // or locks up, or host virtual serial port hangs) if (_usbLineInfo.lineState > 0) { - int r = USB_Send(CDC_TX,&c,1); + int r = USB_Send(CDC_TX,buffer,size); if (r > 0) { return r; } else { diff --git a/cores/arduino/USBAPI.h b/cores/arduino/USBAPI.h index 7a14285..4846fc2 100644 --- a/cores/arduino/USBAPI.h +++ b/cores/arduino/USBAPI.h @@ -28,18 +28,19 @@ extern USBDevice_ USBDevice; class Serial_ : public Stream { private: - ring_buffer *_cdc_rx_buffer; + int peek_buffer; public: + Serial_() { peek_buffer = -1; }; void begin(unsigned long); void begin(unsigned long, uint8_t); void end(void); virtual int available(void); - virtual void accept(void); virtual int peek(void); virtual int read(void); virtual void flush(void); virtual size_t write(uint8_t); + virtual size_t write(const uint8_t*, size_t); using Print::write; // pull in write(str) and write(buf, size) from Print operator bool(); }; diff --git a/cores/arduino/USBCore.cpp b/cores/arduino/USBCore.cpp index d3e0170..f8123e5 100644 --- a/cores/arduino/USBCore.cpp +++ b/cores/arduino/USBCore.cpp @@ -290,9 +290,12 @@ int USB_Send(u8 ep, const void* d, int len) if (n > len) n = len; - len -= n; { LockEP lock(ep); + // Frame may have been released by the SOF interrupt handler + if (!ReadWriteAllowed()) + continue; + len -= n; if (ep & TRANSFER_ZERO) { while (n--) @@ -611,8 +614,6 @@ ISR(USB_GEN_vect) { #ifdef CDC_ENABLED USB_Flush(CDC_TX); // Send a tx frame if found - if (USB_Available(CDC_RX)) // Handle received bytes (if any) - Serial.accept(); #endif // check whether the one-shot period has elapsed. if so, turn off the LED diff --git a/cores/arduino/main.cpp b/cores/arduino/main.cpp index 0ad6962..091c365 100644 --- a/cores/arduino/main.cpp +++ b/cores/arduino/main.cpp @@ -19,10 +19,17 @@ #include <Arduino.h> +// Weak empty variant initialization function. +// May be redefined by variant files. +void initVariant() __attribute__((weak)); +void initVariant() { } + int main(void) { init(); + initVariant(); + #if defined(USBCON) USBDevice.attach(); #endif diff --git a/firmwares/wifishield/scripts/ArduinoWifiShield_upgrade_mac.sh b/firmwares/wifishield/scripts/ArduinoWifiShield_upgrade_mac.sh index 5082392..c627895 100644..100755 --- a/firmwares/wifishield/scripts/ArduinoWifiShield_upgrade_mac.sh +++ b/firmwares/wifishield/scripts/ArduinoWifiShield_upgrade_mac.sh @@ -1,6 +1,6 @@ #!/bin/sh -WIFI_FW_PATH="/hardware/arduino/firmwares/wifi-shield" +WIFI_FW_PATH="/hardware/arduino/firmwares/wifishield/binary" AVR_TOOLS_PATH="/hardware/tools/avr/bin" progname=$0 diff --git a/variants/leonardo/pins_arduino.h b/variants/leonardo/pins_arduino.h index 473b92e..fd75373 100644 --- a/variants/leonardo/pins_arduino.h +++ b/variants/leonardo/pins_arduino.h @@ -133,6 +133,8 @@ static const uint8_t A11 = 29; // D12 extern const uint8_t PROGMEM analog_pin_to_channel_PGM[]; #define analogPinToChannel(P) ( pgm_read_byte( analog_pin_to_channel_PGM + (P) ) ) +#define digitalPinToInterrupt(p) ((p) == 0 ? 2 : ((p) == 1 ? 3 : ((p) == 2 ? 1 : ((p) == 3 ? 0 : ((p) == 7 ? 4 : NOT_AN_INTERRUPT))))) + #ifdef ARDUINO_MAIN // On the Arduino board, digital pins are also used diff --git a/variants/mega/pins_arduino.h b/variants/mega/pins_arduino.h index 9991a21..a80991b 100644 --- a/variants/mega/pins_arduino.h +++ b/variants/mega/pins_arduino.h @@ -83,6 +83,8 @@ static const uint8_t A15 = 69; ( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \ 0 ) ) ) ) ) ) +#define digitalPinToInterrupt(p) ((p) == 2 ? 0 : ((p) == 3 ? 1 : ((p) >= 18 && (p) <= 21 ? 23 - (p) : NOT_AN_INTERRUPT))) + #ifdef ARDUINO_MAIN const uint16_t PROGMEM port_to_mode_PGM[] = { diff --git a/variants/robot_control/pins_arduino.h b/variants/robot_control/pins_arduino.h index 4acfc0d..b868064 100644 --- a/variants/robot_control/pins_arduino.h +++ b/variants/robot_control/pins_arduino.h @@ -94,6 +94,8 @@ static const uint8_t LED1 = 17; // D17 - RX_Led extern const uint8_t PROGMEM analog_pin_to_channel_PGM[]; #define analogPinToChannel(P) ( pgm_read_byte( analog_pin_to_channel_PGM + (P) ) ) +#define digitalPinToInterrupt(p) ((p) == 0 ? 2 : ((p) == 1 ? 3 : ((p) == 2 ? 1 : ((p) == 3 ? 0 : ((p) == 7 ? 4 : NOT_AN_INTERRUPT))))) + #ifdef ARDUINO_MAIN // On the Arduino board, digital pins are also used diff --git a/variants/robot_motor/pins_arduino.h b/variants/robot_motor/pins_arduino.h index fdb4c67..7dc4a79 100644 --- a/variants/robot_motor/pins_arduino.h +++ b/variants/robot_motor/pins_arduino.h @@ -89,6 +89,8 @@ static const uint8_t TK4 = 12; // A11 extern const uint8_t PROGMEM analog_pin_to_channel_PGM[]; #define analogPinToChannel(P) ( pgm_read_byte( analog_pin_to_channel_PGM + (P) ) ) +#define digitalPinToInterrupt(p) ((p) == 0 ? 2 : ((p) == 1 ? 3 : ((p) == 2 ? 1 : ((p) == 3 ? 0 : ((p) == 7 ? 4 : NOT_AN_INTERRUPT))))) + #ifdef ARDUINO_MAIN // On the Arduino board, digital pins are also used diff --git a/variants/standard/pins_arduino.h b/variants/standard/pins_arduino.h index 2e24e19..3d4a9f6 100644 --- a/variants/standard/pins_arduino.h +++ b/variants/standard/pins_arduino.h @@ -60,6 +60,8 @@ static const uint8_t A7 = 21; #define digitalPinToPCMSK(p) (((p) <= 7) ? (&PCMSK2) : (((p) <= 13) ? (&PCMSK0) : (((p) <= 21) ? (&PCMSK1) : ((uint8_t *)0)))) #define digitalPinToPCMSKbit(p) (((p) <= 7) ? (p) : (((p) <= 13) ? ((p) - 8) : ((p) - 14))) +#define digitalPinToInterrupt(p) ((p) == 2 ? 0 : ((p) == 3 ? 1 : NOT_AN_INTERRUPT)) + #ifdef ARDUINO_MAIN // On the Arduino board, digital pins are also used |