From 5515442dbb3efe23bc7572c80270829257371bb8 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Fri, 25 Feb 2011 18:36:46 -0500 Subject: Small optimization in HardwareSerial. begin(long) -> begin(unsigned long) --- cores/arduino/HardwareSerial.cpp | 2 +- cores/arduino/HardwareSerial.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'cores/arduino') diff --git a/cores/arduino/HardwareSerial.cpp b/cores/arduino/HardwareSerial.cpp index 4397efb..38e87c4 100644 --- a/cores/arduino/HardwareSerial.cpp +++ b/cores/arduino/HardwareSerial.cpp @@ -191,7 +191,7 @@ HardwareSerial::HardwareSerial(ring_buffer *rx_buffer, // Public Methods ////////////////////////////////////////////////////////////// -void HardwareSerial::begin(long baud) +void HardwareSerial::begin(unsigned long baud) { uint16_t baud_setting; bool use_u2x = true; diff --git a/cores/arduino/HardwareSerial.h b/cores/arduino/HardwareSerial.h index 3efa775..9dc67c4 100644 --- a/cores/arduino/HardwareSerial.h +++ b/cores/arduino/HardwareSerial.h @@ -48,7 +48,7 @@ class HardwareSerial : public Stream volatile uint8_t *ucsra, volatile uint8_t *ucsrb, volatile uint8_t *udr, uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x); - void begin(long); + void begin(unsigned long); void end(); virtual int available(void); virtual int peek(void); -- cgit v1.2.3-18-g5258 From 5e721df32a49d8f74058ba0f824ffe9686a0c9d7 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Thu, 3 Mar 2011 22:56:20 -0500 Subject: Fixing warnings (David H. Lynch Jr). --- cores/arduino/Print.cpp | 2 +- cores/arduino/WString.h | 2 +- cores/arduino/pins_arduino.c | 84 ++++++++++++++++++++++---------------------- 3 files changed, 44 insertions(+), 44 deletions(-) (limited to 'cores/arduino') diff --git a/cores/arduino/Print.cpp b/cores/arduino/Print.cpp index 4ee556d..fd68942 100755 --- a/cores/arduino/Print.cpp +++ b/cores/arduino/Print.cpp @@ -45,7 +45,7 @@ void Print::write(const uint8_t *buffer, size_t size) void Print::print(const String &s) { - for (int i = 0; i < s.length(); i++) { + for (unsigned int i = 0; i < s.length(); i++) { write(s[i]); } } diff --git a/cores/arduino/WString.h b/cores/arduino/WString.h index cadddb9..56faf9a 100644 --- a/cores/arduino/WString.h +++ b/cores/arduino/WString.h @@ -67,7 +67,7 @@ class String int lastIndexOf( char ch, unsigned int fromIndex ) const; int lastIndexOf( const String &str ) const; int lastIndexOf( const String &str, unsigned int fromIndex ) const; - const unsigned int length( ) const { return _length; } + unsigned int length( ) const { return _length; } void setCharAt(unsigned int index, const char ch); unsigned char startsWith( const String &prefix ) const; unsigned char startsWith( const String &prefix, unsigned int toffset ) const; diff --git a/cores/arduino/pins_arduino.c b/cores/arduino/pins_arduino.c index 0c816e9..62e10ad 100755 --- a/cores/arduino/pins_arduino.c +++ b/cores/arduino/pins_arduino.c @@ -81,50 +81,50 @@ #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) const uint16_t PROGMEM port_to_mode_PGM[] = { NOT_A_PORT, - &DDRA, - &DDRB, - &DDRC, - &DDRD, - &DDRE, - &DDRF, - &DDRG, - &DDRH, + (uint16_t) &DDRA, + (uint16_t) &DDRB, + (uint16_t) &DDRC, + (uint16_t) &DDRD, + (uint16_t) &DDRE, + (uint16_t) &DDRF, + (uint16_t) &DDRG, + (uint16_t) &DDRH, NOT_A_PORT, - &DDRJ, - &DDRK, - &DDRL, + (uint16_t) &DDRJ, + (uint16_t) &DDRK, + (uint16_t) &DDRL, }; const uint16_t PROGMEM port_to_output_PGM[] = { NOT_A_PORT, - &PORTA, - &PORTB, - &PORTC, - &PORTD, - &PORTE, - &PORTF, - &PORTG, - &PORTH, + (uint16_t) &PORTA, + (uint16_t) &PORTB, + (uint16_t) &PORTC, + (uint16_t) &PORTD, + (uint16_t) &PORTE, + (uint16_t) &PORTF, + (uint16_t) &PORTG, + (uint16_t) &PORTH, NOT_A_PORT, - &PORTJ, - &PORTK, - &PORTL, + (uint16_t) &PORTJ, + (uint16_t) &PORTK, + (uint16_t) &PORTL, }; const uint16_t PROGMEM port_to_input_PGM[] = { NOT_A_PIN, - &PINA, - &PINB, - &PINC, - &PIND, - &PINE, - &PINF, - &PING, - &PINH, + (uint16_t) &PINA, + (uint16_t) &PINB, + (uint16_t) &PINC, + (uint16_t) &PIND, + (uint16_t) &PINE, + (uint16_t) &PINF, + (uint16_t) &PING, + (uint16_t) &PINH, NOT_A_PIN, - &PINJ, - &PINK, - &PINL, + (uint16_t) &PINJ, + (uint16_t) &PINK, + (uint16_t) &PINL, }; const uint8_t PROGMEM digital_pin_to_port_PGM[] = { @@ -358,25 +358,25 @@ const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { const uint16_t PROGMEM port_to_mode_PGM[] = { NOT_A_PORT, NOT_A_PORT, - &DDRB, - &DDRC, - &DDRD, + (uint16_t) &DDRB, + (uint16_t) &DDRC, + (uint16_t) &DDRD, }; const uint16_t PROGMEM port_to_output_PGM[] = { NOT_A_PORT, NOT_A_PORT, - &PORTB, - &PORTC, - &PORTD, + (uint16_t) &PORTB, + (uint16_t) &PORTC, + (uint16_t) &PORTD, }; const uint16_t PROGMEM port_to_input_PGM[] = { NOT_A_PORT, NOT_A_PORT, - &PINB, - &PINC, - &PIND, + (uint16_t) &PINB, + (uint16_t) &PINC, + (uint16_t) &PIND, }; const uint8_t PROGMEM digital_pin_to_port_PGM[] = { -- cgit v1.2.3-18-g5258 From f25e71c3c1e96d50ffd5684d0409890a2378d113 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sat, 14 May 2011 12:25:39 -0400 Subject: Fixing 300 baud communication for serial. Because UBBR is only 12 bits, we were overflowing it at 300 baud because of the use of the U2X bit. Now we turn off U2X if it would yield a UBBR value that would overflow. Note that this breaks 300 baud communication with the computer on the Uno and Mega 2560 because the 8U2 USB-serial firmware has this same bug (and previously they cancelled each other out). Since, however, it seems more likely that people will need to use 300 baud to communicate with other (legacy) hardware than with the computer, I'm making this change. Issue for 8U2 firmware bug: http://code.google.com/p/arduino/issues/detail?id=542 http://code.google.com/p/arduino/issues/detail?id=522 --- cores/arduino/HardwareSerial.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'cores/arduino') diff --git a/cores/arduino/HardwareSerial.cpp b/cores/arduino/HardwareSerial.cpp index 38e87c4..b5dba1e 100644 --- a/cores/arduino/HardwareSerial.cpp +++ b/cores/arduino/HardwareSerial.cpp @@ -204,6 +204,8 @@ void HardwareSerial::begin(unsigned long baud) use_u2x = false; } #endif + +try_again: if (use_u2x) { *_ucsra = 1 << _u2x; @@ -212,6 +214,12 @@ void HardwareSerial::begin(unsigned long baud) *_ucsra = 0; baud_setting = (F_CPU / 8 / baud - 1) / 2; } + + if ((baud_setting > 4095) && use_u2x) + { + use_u2x = false; + goto try_again; + } // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register) *_ubrrh = baud_setting >> 8; -- cgit v1.2.3-18-g5258