Commit Graph

1147 Commits

Author SHA1 Message Date
Matthijs Kooijman 3babfc2a85 Use constants for register bit positions in HardwareSerial
Previously, the constants to use for the bit positions of the various
UARTs were passed to the HardwareSerial constructor. However, this
meant that whenever these values were used, the had to be indirectly
loaded, resulting in extra code overhead. Additionally, since there is
no instruction to shift a value by a variable amount, the 1 << x
expressions (inside _BV and sbi() / cbi()) would be compiled as a loop
instead of being evaluated at compiletime.

Now, the HardwareSerial class always uses the constants for the bit
positions of UART 0 (and some code is present to make sure these
constants exist, even for targets that only have a single unnumbered
UART or start at UART1).

This was already done for the TXC0 constant, for some reason. For the
actual register addresses, this approach does not work, since these are
of course different between the different UARTs on a single chip.

Of course, always using the UART 0 constants is only correct when the
constants are actually identical for the different UARTs. It has been
verified that this is currently the case for all targets supported by
avr-gcc 4.7.2, and the code contains compile-time checks to verify this
for the current target, in case a new target is added for which this
does not hold. This verification was done using:

for i in TXC RXEN TXEN RXCIE UDRIE U2X UPE; do echo $i; grep --no-filename -r "#define $i[0-9]\? " /usr/lib/avr/include/avr/io* | sed "s/#define $i[0-9]\?\s*\(\S\)\+\s*\(\/\*.*\*\/\)\?$/\1/" | sort | uniq ; done

This command shows that the above constants are identical for all uarts
on all platforms, except for TXC, which is sometimes 6 and sometimes 0.
Further investigation shows that it is always 6, except in io90scr100.h,
but that file defines TXC0 with value 6 for the UART and uses TXC with
value 0 for some USB-related register.

This commit reduces program size on the uno by around 120 bytes.
2014-01-16 16:36:06 +01:00
Matthijs Kooijman 494929495e Define a _NOP() macro
Recent avr-libc releases define one, but this allows using it also on
older avr-libc releases.
2014-01-16 16:29:41 +01:00
Matthijs Kooijman fc45ef0846 Simplify HardwareSerial::begin()
This simplifies the baud rate calculation, removing the need for a goto
and shortening the code a bit. Other than that, this code should not use
any different settings than before.

Code was suggested by Rob Tillaart on github.

Closes: #1262
2014-01-16 16:04:33 +01:00
Matthijs Kooijman d43fd2014c Remove unused variable 2014-01-16 13:52:40 +01:00
Cristian Maglie 0a0cda4f04 Slightly reduce code utilization by inlining HardwareSerail begin(baud) and operator bool() 2014-01-16 13:50:59 +01:00
Matthijs Kooijman 4bc8aa15e3 Remove duplicate code from HardwareSerial::begin() methods.
There are two begin methods, one which accepts just a baud rate and
uses the default bit settings and one which accepts both a baudrate and
a bit config. Previously, both of these contained a complete
implementation, but now the former just calls the latter, explicitely
passing the default 8N1 configuration.

Technically, this causes a small change: Before the UCSRC register was
untouched when calling begin(baud), now it is explicitely initialized
with 8N1. However, since this is the default configuration for at least
the Uno and the Mega (didn't check any others), probably for all avrs,
this shouldn't effectively change anything. Given that the Arduino
documentation also documents this as the default when none is passed,
explicitly setting it is probably a good idea in any case.
2014-01-16 13:20:11 +01:00
Matthijs Kooijman 46b0ada9a9 Make some operators in IPAddress const
These functions do not modify the IPAddress object, but were not marked
as const. This meant that you could not do:

void set_ip(const IPAddress& ip) {
	uint32_t copy = ip;
}

Since calling operator uint32_t() on ip would discard the constness of
the reference.
2014-01-15 16:20:48 +01:00
Cristian Maglie fbedfc4fbe Merge pull request #1790 from cmaglie/platform-paths
Fixed "runtime.hardware.path" and "runtime.platform.path" values
2014-01-09 04:30:00 -08:00
Cristian Maglie 2d99676e5d Merge pull request #1794 from arduino/ide-1.5.x-euler
Added new EULER constant
2014-01-07 06:46:18 -08:00
Cristian Maglie 8f58194e8c Merge branch 'master' into ide-1.5.x
Conflicts:
	build/windows/dist/drivers/arduino.cat
2014-01-07 11:19:08 +01:00
Federico Fissore 1c99bf0e83 Removed = char from #define. See https://github.com/arduino/Arduino/issues/1792#issuecomment-31650586 2014-01-06 18:20:37 +01:00
Federico Fissore 64a9681935 Added new EULER constant. Fixes #1792 2014-01-06 09:48:34 +01:00
Cristian Maglie 7ea78eed37 Fixed "runtime.hardware.path" and "runtime.platform.path" values
"runtime.hardware.path" now contains the path to the hardware folder
of the currently selected board and "runtime.platform.path" the path
to the specific platform.

This should fix #1176 and #1761.
2014-01-05 12:42:27 +01:00
Cristian Maglie 1eee97d980 Improved portability of String class (maniacbug) 2014-01-01 17:22:40 +01:00
Cristian Maglie bf37051397 Merge branch 'cast' of github.com:Lauszus/Arduino into Lauszus-cast
Conflicts:
	hardware/arduino/avr/cores/arduino/Print.cpp
2013-12-31 20:11:08 +01:00
Matthijs Kooijman 1978e82e4e Use PGM_P instead of prog_char
On later versions of avr-libc, prog_char is deprecated. In 0acebeeff48
the one occurence of prog_char was replaced by "char PROGMEM", which is
not entirely correct (PROGMEM is supposed to be an attribute on a
variable, not on a type, even though this is how things work in older
libc versions). However, in 1130fede3a2 a few new occurences of
prog_char are introduced, which break compilation on newer libc versions
again.

This commit changes all these pointer types to use the PGM_P macro from
<avr/pgmspace.h>. This macro is just "const char *" in newer libc
versions and "const prog_char *" in older versions, so it should always
work.

References #795
2013-12-31 20:01:40 +01:00
Cristian Maglie 15417bab95 Merge pull request #1762 from matthijskooijman/ide-1.5.x-write-char
Support both char* and uint8* in Stream and Print
2013-12-30 10:58:03 -08:00
Kristian Lauszus ad9f78d727 Use reinterpret_cast to cast __FlashStringHelper to const char* 2013-12-27 20:01:03 +01:00
Matthijs Kooijman 94cf4c2830 Remove unneeded casts in Print::write(const String&)
Now that Print::write(const char*) is also available, these casts are no
longer needed.
2013-12-24 13:22:43 +01:00
Matthijs Kooijman 0fd4002607 Add uint8_t* versions of methods in Stream
The new functions just call their char* equivalents, but this allows
reading bytes into a buffer of uint8_t as well as chars.
2013-12-24 13:22:42 +01:00
Matthijs Kooijman 7ded037878 Add Print::write(const char *, size_t)
The new function just calls Print::write(const uint8_t *, size_t), but
this allows writing out a buffer of chars (without having to learn about
casts).
2013-12-24 13:22:42 +01:00
Federico Fissore dce9146485 Print.print optimization. Closes #1760 2013-12-23 11:50:39 +01:00
Cristian Maglie 1a7346f8e4 Merge branch 'master' of github.com:arduino/Arduino 2013-12-13 18:26:44 +01:00
Cristian Maglie a0cd735f45 Merge branch 'pins-define' into ide-1.5.x 2013-12-13 15:09:40 +01:00
Cristian Maglie a2cc9674ba Changed pins definition in variants from constants to #defines. 2013-12-13 14:37:26 +01:00
Cristian Maglie ed03068b0a Removed redefinitions of SERIAL_* in Yun variant 2013-12-13 14:22:46 +01:00
Cristian Maglie 1131297fe3 Merge remote-tracking branch 'arduino/master' into ide-1.5.x
Conflicts:
	libraries/Ethernet/EthernetClient.cpp
2013-12-09 18:31:43 +01:00
Matthijs Kooijman 2eb6101744 In boards.txt, rename atmega328diecimila to diecimila
This board has a "cpu" submenu to select either atmega328 or atmega168,
so it does not make sense to put atmega328 in the main board name.
2013-12-08 18:16:31 +01:00
ntruchsess faffdc1585 remove all Changes besides operator== 2013-12-06 19:05:31 +01:00
Cristian Maglie dd5ce6134e Upped version to 1.5.5 2013-11-28 10:53:50 +01:00
ntruchsess 6cdf45953f add localPort to EthernetClient, simplify operator== 2013-11-27 10:40:57 +01:00
ntruchsess 68e218dda8 add operator==, remoteIP and remotePort to EthernetClient 2013-11-26 00:12:44 +01:00
Cristian Maglie 66ca83a809 Revert "SPI library to new format" 2013-11-21 15:05:36 +01:00
Cristian Maglie 0dcd4b2209 Revert "EEPROM library to the new format"
This reverts commits:
3223d4fdca32ec03de4a3a2a0c22f2d40de5f374
77f8dd63ab102ab5d2929ac4edd5c00ae9d70493
2013-11-21 11:22:44 +01:00
Cristian Maglie a5d1990afd Revert "SoftwareSerial library to the new format"
This reverts commit 38c3bbbd3c83eda057d4857635fbd78a4785c3a4.
2013-11-15 12:54:59 +01:00
Cristian Maglie f0fa1fd39a Revert "Wire library to the 1.5 format"
This reverts commit a31857688bdc270ed65307755ff3b73ef4867982.
2013-11-15 12:54:59 +01:00
Cristian Maglie 2dd6b14b21 Removed redundant LED_BUILTIN define in Yun variant. 2013-11-12 14:31:51 +01:00
Cristian Maglie 3f0cac9021 Merge pull request #1634 from cmaglie/adc-fix
Improved ADC speed on Arduino Due
2013-11-12 00:57:28 -08:00
Cristian Maglie 59edeb17e6 Merge branch 'master' into serial-variant 2013-11-11 14:01:09 +01:00
Cristian Maglie 3b51f9589f Fix SERIAL_* metadata in Arduino Ethernet variant 2013-11-11 13:54:50 +01:00
Cristian Maglie 96fa9f231e Added SERIAL metadata into variant files. 2013-11-11 13:41:04 +01:00
Cristian Maglie 79d9da6058 Merge branch 'master' into serial-variant 2013-11-11 13:03:21 +01:00
Cristian Maglie 2398409fbf Added SERIAL metadata into variant files. 2013-11-11 11:39:37 +01:00
Kristian Lauszus 09fd6d7b0a Added VID and PID for older Arduino Unos 2013-11-11 02:41:44 +01:00
Cristian Maglie a2c36f7207 Merge branch 'master' into ide-1.5.x 2013-11-03 18:18:09 +01:00
Cristian Maglie 9d48a36616 Changed LED_BUILTIN to a macro to better support boards that do not have a built-in LED.
Fixes #758
2013-11-03 18:10:22 +01:00
Cristian Maglie 0e5e67e23d Added LED_BUILTIN constant to Leonardo board 2013-11-03 18:07:01 +01:00
Cristian Maglie ac2ce91009 Merge branch 'master' into ide-1.5.x 2013-11-03 14:00:42 +01:00
Cristian Maglie 24dc51bfde Added Arduino Ethernet variant.
Fixes #925
2013-11-03 13:52:08 +01:00
Cristian Maglie 9b4562c4c5 Using NOT_AN_INTERRUPT defined constant 2013-10-31 12:44:24 +01:00