Commit Graph

1702 Commits

Author SHA1 Message Date
NicoHood fd6f57d2d7 Added 16 byte endpoint support 2015-08-12 17:48:17 +02:00
NicoHood a1cf7042b2 Fixed HID Reports >255 bytes 2015-08-12 17:48:17 +02:00
NicoHood b97b2519d1 Added missing static inline to USB Recv function 2015-08-12 17:48:17 +02:00
NicoHood 344897301c Made Magic Key Settings more flexible 2015-08-12 17:48:09 +02:00
Chuck Todd 25d81c98e4 Print not Aborting on Write() failure
Print::write(const uint8_t *buffer, size_t size) and Print::print(const
__FlashStringHelper *ifsh) would continue calling write(char) after a
failed write(char) this behavior would render returned count unuseable
see arduino/Arduino issue #3614
2015-08-12 11:47:57 +02:00
Reilly Grant a20b44801a Fix links to 3rd party hardware specification.
The number of hyphens in this URL has apparently changed.
2015-07-31 15:54:22 -07:00
Peter Van Hoyweghen 4f87112c2e Add Serial_::availableForWrite().
This makes the CDC "Serial" object on the Leonardo and similar boards
support this recently introduced method as well. The CDC code in the sam
core is not changed.
2015-07-31 14:06:20 +02:00
Matthijs Kooijman 9b7b23f045 Prevent losing bytes in HardwareSerial::end()
end() already waited for the buffer to be empty, but then there could
still be two bytes in the hardware registers that still need to be
transmitted (which were dropped or kept in the buffer, depending on the
exact timing).

This changes the wait loop to a call to the flush() function, which
already takes care of really waiting for all bytes to be transmitted,
meaning it is safe to turn off the transmitter.
2015-07-31 14:06:20 +02:00
Matthijs Kooijman b58f239400 Add Serial_::readBreak() to process SEND_BREAK requests
This allows detecting when the USB host sends a break request and what
the value of the request was. See the comments in USBAPI.h for details.

This just modifies the avr core, not the sam core.
2015-07-31 14:06:19 +02:00
Matthijs Kooijman 96f7b966bc Expose serial settings from CDC virtual serial port
This allows a sketch to find out the settings chosen by the USB host
(computer) and act accordingly.

Other than reading the DTR flag and checking if the baudrate is 1200,
the regular CDC code doesn't actually use any of these settings.

By exposing these settings to the sketch, it can for example copy them
to the hardware UART, turning the Leonardo into a proper USB-to-serial
device. This can be useful to let the computer directly talk to whatever
device is connected to the hardware serial port (like an XBee module).

The Teensy core already supported these methods. This code was
independently developed, but the method names were chosen to match the
Teensy code, for compatibility (except that `dtr()` and `rtr()` return
`bool`, while the Teensy version return a `uint8_t`).

This change is applied to both the avr and sam cores, which have a very
similar CDC implementation.
2015-07-31 13:40:43 +02:00
Martino Facchin 2acda414aa port PluggableUSB to sam core 2015-07-17 12:16:38 +02:00
Martino Facchin a261e6cf7c remove HID from core 2015-07-17 12:16:09 +02:00
Martino Facchin b2381506a2 sam: add HID library 2015-07-17 12:13:21 +02:00
Martino Facchin af290fc5a3 rework HID-based libraries and add Due fallback 2015-07-16 13:13:53 +02:00
Martino Facchin e1a0350062 allow HID submodules to create runtime descriptors
with this PR you can add

\#include Keyboard.h
\#include Mouse.h
\#include HID.h

in the top of the sketch and you will expose a Mouse+Keyboard

From the library pow, simply add

static HID_Descriptor cb = {
	.length = sizeof(_hidReportDescriptor),
	.descriptor = _hidReportDescriptor,
};
static HIDDescriptorListNode node(&cb);
HID.AppendDescriptor(&node);

in the class' constructor and you are done!
2015-07-16 13:13:52 +02:00
Martino Facchin 6a9568d3e1 fix pluggableUSB linked list 2015-07-16 13:13:52 +02:00
Martino Facchin 8a45883230 save RAM content overridden by bootloader magic
and restore it in case of aborted reboot
use RAMEND-1 as suggested by @yyyc514 in PR #2474

of course it's not a real solution but we cannot force everyone to update the bootloader using an external programmer
2015-07-16 13:13:52 +02:00
Martino Facchin 5defaeaa97 rework HID class functions scopes 2015-07-16 13:13:52 +02:00
Martino Facchin 97a3771772 rename Setup typedef struct to USBSetup
was really too common
2015-07-16 13:13:52 +02:00
Martino Facchin dee43a19d7 fix HID headers 2015-07-16 13:13:51 +02:00
Martino Facchin 9074b1ed18 fix HID descriptors bigger than 127 bytes 2015-07-16 13:13:51 +02:00
Martino Facchin 175240a906 Add support for waking up a host via USB HID
this is a rework of commit fbcf94801b8bba7f1c8c79cc7ae402b6b9dbb2d3
2015-07-16 13:13:51 +02:00
Martino Facchin 91a115a353 move HID library to AVR specific location 2015-07-16 13:13:51 +02:00
Martino Facchin e211f1ea76 remove setupUSB weak hook and replace with global constructors
thanks @matthijskooijman
2015-07-16 13:13:49 +02:00
Martino Facchin 89928b4e15 rework PUSBCallbacks initialization 2015-07-16 13:13:39 +02:00
Martino Facchin ada0e4c2f3 remove 3 endpoints to match at32u4 limit 2015-07-16 13:12:15 +02:00
Martino Facchin f37547e8fd add numInterfaces field to PUSBCallbacks 2015-07-16 13:12:15 +02:00
Martino Facchin 7b5c25f534 implement PUSB modules as linked list 2015-07-16 13:12:14 +02:00
Martino Facchin f67318a8b1 remove useless variables 2015-07-16 13:12:14 +02:00
Martino Facchin 91ccab4f09 make CDC function non removable 2015-07-16 13:12:14 +02:00
Martino Facchin b2a6b61a2f add weak setupUSB() hook
override this function to insert additional USB endpoints
2015-07-16 13:12:14 +02:00
Martino Facchin ec43b6c829 remove useless variable 2015-07-16 13:12:14 +02:00
Martino Facchin 1aec25b855 add PluggableUSB module 2015-07-16 13:12:14 +02:00
Martino Facchin 1f534eac35 move _initEndpoints from PROGMEM to RAM 2015-07-16 13:12:14 +02:00
Martino Facchin 2c5dd20298 Use generic composite device descriptor 2015-07-16 13:12:13 +02:00
Martino Facchin 5ee69a70ee Move EP defines to header 2015-07-16 13:12:13 +02:00
Martino Facchin 09460dd8c9 Remove HID core library 2015-07-16 13:12:13 +02:00
Matthijs Kooijman 7fd6244621 Enable C11 support
This uses the gnu11 standard, which is C11 with GNU extensions.
Previously, gnu89 was being used, which is pretty ancient by now. C99
brings some important improvements, some of which were already available
and used even without this option. C11 is more recent and brings more
minor improvements. Most notable feature is the static_assert statement,
allowing checking invariants at compiletime using the full C
expressions.
2015-07-16 13:06:10 +02:00
Matthijs Kooijman ebeb7843d2 Check for __cplusplus >= 201103L as well as __GXX_EXPERIMENTAL_CXX0X__
Gcc 4.8 defines __cplusplus as 201103L, so we can check for that now. It
still also defines __GXX_EXPERIMENTAL_CXX0X__, but this could help on
other compilers, or if gcc ever decides to stop defining the
experimental macro.
2015-07-16 13:06:10 +02:00
Matthijs Kooijman ddf4d878fd Enable C++11 support
This uses the gnu++11 standard, which is C++11 with GNU extensions.
C++11 should be full compatible with the previously used C++98
standards, so all pre-existing sketches should continue to work.
2015-07-16 13:06:09 +02:00
Matthijs Kooijman 770a695c85 Explicitely specify C and C++ standards to use
This does not change anything, it just makes the defaults explicit.
2015-07-16 13:06:09 +02:00
Martyn Ranyard 94af627772 Bootloaders: wrong #ifdefs, should be defined() not just tested (i.e. noteq 0)
Close #126
2015-07-14 16:16:31 +02:00
Martyn Ranyard 59b5311cdf Bootloaders: adds support for 328-nonp chips 2015-07-14 12:55:22 +02:00
Martyn Ranyard 3831c9c519 -O2 in new avr-gcc makes too big a bootloader to fit on 328(and 328p) 2015-07-14 12:37:36 +02:00
Martyn Ranyard 8f5ca0a943 Fixed EEPE flag check.
Here, using the flag itself makes the bootloader build where it currently does not for the 328 amongst others
2015-07-14 12:28:13 +02:00
Federico Fissore fe3fa56a15 Yun bootloader without blink 2015-07-07 17:15:42 +02:00
Federico Fissore 5e98cd8528 Examples: mass code format. See example_formatter.conf 2015-07-06 15:19:05 +02:00
Matthew Lowe 39c3f8bf61 Support for repeated starts added to SAM Wire library
Additional interface method ported to avr for compatibility
Fix issue #2428.
2015-07-03 16:59:30 +02:00
Federico Fissore 431f319aca Removed a handful of SVN expansion keywords. See #277 2015-07-03 10:38:07 +02:00
Martino Facchin 98d0a72fdd Merge pull request #1869 from kevin-pololu/due-wire-available
SAM Wire: fixed NACK/timeout behavior of requestFrom() and available()
2015-07-01 12:43:44 +00:00
Federico Fissore 5f31f4b8dd Fixed missing "sketch" folders in some paths of both AVR and SAM cores 2015-06-29 16:10:54 +02:00
Federico Fissore e097439eab Compiler: sketch files get compiled into "sketch" 2015-06-29 15:11:45 +02:00
Federico Fissore 5a35be06da Compiler: cores files get compiled under "core", libraries under "libraries". Fixes #2997 2015-06-29 15:11:45 +02:00
Matthijs Kooijman 07c4d958c0 Warn about increasing HardwareSerial buffers to > 256
Properly supporting bigger buffers need better atomicity code, which
isn't implemented yet. Until it is, best to add a warning. See #2405.
2015-06-18 16:36:07 +02:00
Matthijs Kooijman 5b4ebcf959 Support the Atmel STK500 development board for ISP 2015-06-05 18:43:25 +02:00
ziotibia81 ec4006d1ee Added comment about Bus Pirate 2015-06-05 18:43:23 +02:00
ziotibia81 cb9a14835c Added support for Dangerous Prototypes Bus Pirate as ISP
Close #2385
2015-06-05 18:43:12 +02:00
Fede85 4f957da22a add Arduino Gemma Bootloader source files 2015-06-01 20:00:54 +02:00
Martino Facchin ed1b8eb486 Add a Stream::find(char) method 2015-06-01 14:06:32 +00:00
Cristian Maglie 074d910857 Fixed unused argument warning 2015-05-30 15:19:44 +02:00
Cristian Maglie 2cbdc121e9 Fixed unused variables warnings and indentation 2015-05-29 20:02:50 +02:00
chromhelm cd9d30a8fe Saving some bytes in HardwareSerial::write 2015-05-29 18:12:24 +02:00
Martino Facchin a7d81d0b1c pulseIn: add alternative implementation based on micros() 2015-05-29 15:01:38 +02:00
Martino Facchin bb3963c0e9 pulseIn: add ASM implementation for Due 2015-05-29 15:01:38 +02:00
Martino Facchin 7a22827359 pulseIn: be consistent with standard API
return 0 if timeout has been reached
2015-05-29 15:01:38 +02:00
Martino Facchin 689c654e8d pulseInASM: rework comment style 2015-05-29 15:01:38 +02:00
Martino Facchin d4a80be045 pulseIn: add alternative implementation based on micros()
pulseInLong is suitable for long pulses in interrupt context
2015-05-29 15:01:38 +02:00
Martino Facchin 93f74f84ce pulseIn: modify function to use ASM implementation 2015-05-29 15:01:37 +02:00
Martino Facchin b37b0d1b6d pulseIn: add ASM implementation
this assembly code was generated by avr-gcc 4.8.3
2015-05-29 15:01:37 +02:00
Martino Facchin 0c9f0d50a5 Revert "Temporary fix for pulseIn() regression."
This reverts commit 8ddc5198f6.
To be substituted by ASM generated code
2015-05-29 15:01:37 +02:00
Martino Facchin d92bf5bdaa Merge pull request #3202 from Chris--A/randomSeed
Modified randomSeed, now uses unsigned long.
2015-05-28 10:54:26 +02:00
Martino Facchin 9d13023075 Merge pull request #3211 from Chris--A/println-optimize
Println optimize
2015-05-28 10:24:12 +02:00
Cristian Maglie b4c5fa7109 Merge pull request #3244 from Lauszus/INT2
Check if INT2 is actually defined before issuing warning in detachInterrupt
2015-05-28 09:51:25 +02:00
Martino Facchin f816e76d47 Merge pull request #3207 from chromhelm/master
Fixed bug with HWSerial flushing
2015-05-28 09:44:46 +02:00
Kristian Sloth Lauszus 272d5cc93d Check if INT2 is actually defined before issuing warning in detachInterrupt
This was caused after: https://github.com/arduino/Arduino/pull/3221
2015-05-28 03:42:32 +02:00
Victor Aprea e9045d8b8a Add missing case to detachinterrupt 2015-05-24 20:35:23 -04:00
Christopher Andrews 527c7c2572 Updated printLn on SAM core 2015-05-23 01:56:06 +10:00
Cristian Maglie e273178425 Indent fix. 2015-05-22 17:23:46 +02:00
Cano c4080efdb5 zero delay fix, ADC prescaler fix 2015-05-22 17:23:46 +02:00
Cano 219914ef22 delayMicroseconds(): added support for 1Mhz, 12Mhz and 24Mhz
1Mhz is a default clock speed on Atmega328, many users run it on the
internal 1Mhz clock to save battery power. Up until now
delayMicroseconds() function wasn't taking this frequencies into an
account.
2015-05-22 17:23:45 +02:00
Chris--A c617562e74 Optimize printLn calls. 2015-05-22 23:00:07 +10:00
chromhelm ed331a817a Fixed bug with flushing 2015-05-21 21:42:40 +02:00
Chris--A 0051eadd2a Modified randomSeed, now uses unsigned long. 2015-05-21 16:52:42 +10:00
Federico Fissore 9166828bfe Due to website configuration changes, every url starting with http://arduino.cc has been changed to http://www.arduino.cc. Fixes #3191 2015-05-20 17:10:06 +02:00
Cristian Maglie 977ccc6910 Added missing license on samd's pgmspace.h
Fixes #3145
2015-05-19 20:01:50 +02:00
Federico Fissore 42b07f0337 Libraries bundled with cores will take the type of that core, instead of relying on an undocumented 'types' property. Fixes #2875 2015-05-19 12:24:11 +02:00
Federico Fissore c14d4fa8b4 Merge pull request #3109 from agdl/fix_i2cexamples
Fix for #2969 (I2C reserved addresses)
2015-05-14 14:07:43 +02:00
Arturo Guadalupi 5199b0f6d3 Fixes #2969:
This fixes the Wire examples that uses I2C reserved address (from 0 to 7) substituting them with 8 that is the first one available and that can be used.

I also modified the wire reference
http://www.arduino.cc/en/reference/wire
according to this fact.
2015-05-14 11:27:00 +02:00
Nico d2595129c5 RX and TX Serial buffer sizes can now be defined independently
Fixes #2597
2015-05-12 15:09:48 +02:00
Martino Facchin 7f8cba667d Due watchdog: change flags to effectively reset board 2015-05-08 14:16:12 +02:00
Bob Cousins d2c510d166 Add Due watchdog functions; modified according to feedback supplied 2015-05-08 14:16:12 +02:00
Bob Cousins 4725d75054 Add watchdog routines for Due. 2015-05-08 14:16:12 +02:00
Arnav Gupta 4d029de000 saveHex: rename recipe.hex -> recipe.output
Signed-off-by: Arnav Gupta <championswimmer@gmail.com>
2015-05-07 11:57:12 +02:00
Arnav Gupta 78936541b7 update Sketch menu, add Save hex option
* Moving Upload options from "File" menu to "Sketch" menu as those
     are sketch actions more than file actions.

Signed-off-by: Arnav Gupta <championswimmer@gmail.com>
2015-05-07 11:57:12 +02:00
Federico Fissore 5a68e3441b AVR core version bump 2015-05-06 16:24:13 +02:00
Cristian Maglie 79c77ae884 [gemma] Integration of Gemma board 2015-05-06 15:55:56 +02:00
Federico Fissore 90026f3764 Disabling uncertified warning, leaving vids/pids 2015-04-27 10:55:16 +02:00
Federico Fissore d805fb4e1f Renamed compiler.warning_flags pref to compiler.warning_level
Provided a default value for compiler.warning_flags
Releasing avr core 1.6.5
2015-04-24 09:27:28 +02:00
Federico Fissore 2f31b8a80c AVR: upgrading avr core version 2015-04-23 11:10:17 +02:00
Cristian Maglie c944a4c84d Updated Stream.cpp in SAM core to the latest version 2015-04-21 18:11:05 +02:00
Cristian Maglie c96c917dd0 Fixed indentation in Stream.cpp, no code change 2015-04-21 18:10:32 +02:00
Cristian Maglie 35fc66c23d Fixed wrong bracket placement (see #3011) 2015-04-21 18:07:42 +02:00
Kristian Sloth Lauszus 91489d7ba8 Fixed: warning: comparison between signed and unsigned integer expressions 2015-04-21 00:08:11 +02:00
Kristian Sloth Lauszus f3e7a3909d Fixed: warning: suggest explicit braces to avoid ambiguous 'else' 2015-04-21 00:08:02 +02:00
Federico Fissore 38d5e916ca Merge pull request #2973 from ffissore/warnings
Reviewed warnings key names and dropdown in Preferences
2015-04-17 23:55:54 +02:00
Martino Facchin b41e4a3d7d Merge branch 'jipp-master' 2015-04-14 10:13:58 +02:00
Martino Facchin 3bbdf495f2 Merge pull request #2961 from jan-r/issue292-fix
Tone: fix for ATmega8
2015-04-14 08:36:12 +01:00
Jan df577bf244 Fix for issue #292
Replaced direct register manipulation with calls to bitWrite(). Fixed TIMSK5 usage on Leonardo (as well as some other preprocessor statements).
2015-04-13 20:36:28 +02:00
Federico Fissore f7fe11c825 Reviewed warnings key names and dropdown in Preferences 2015-04-13 17:18:23 +02:00
jipp b5cc55ec3e Update Tone.cpp
Tone.cpp stops compile when TCCR0A/TCCR0B defined and WGM01 not defined #2923
2015-04-13 16:18:18 +02:00
Federico Fissore b42c6667e1 Better preference for setting warnings level. See 61592d78fa (commitcomment-10668365) 2015-04-13 12:22:37 +02:00
Jan 3cde93501c Update Tone.cpp
Rebased the bugfix from the original Google Code issue #292 to work with Arduino 1.6.x

Description of original fix provided by Pete62:
The later 8 bit AVR's use two registers (TCCRxA, TCCRxB) whereas the ATmega8 only uses a single register (TCCR2) to house the control bits for Timer 2.  Bits were inadvertently being cleared.
2015-04-11 00:15:58 +02:00
Federico Fissore ecde17b6e2 Platform.txt in-memory rewrite rules: whenever loaded, if a property is set to a value known to be wrong/old, that property is replaced with the current/right value.
This happens in-memory, no platform.txt file were harmed during rewriting
Mitigate #2838
2015-03-30 16:18:08 +02:00
Federico Fissore ea5155656a Starting 1.6.3
Updated toolchains: linux statically compiled, added gcc lto plugin (disabled)
2015-03-30 15:06:59 +02:00
Federico Fissore 6e498ee5b9 LibraryManager: better type filtering 2015-03-27 14:51:19 +01:00
Federico Fissore e884789322 Not using gcc version, hard to maintain 2015-03-27 14:51:15 +01:00
Federico Fissore 3be821dfcf avr platform: fixed avrdude path 2015-03-27 14:51:12 +01:00
Federico Fissore 7d6729ab93 Fixed platforms(.txt) 2015-03-27 14:51:12 +01:00
Martino Facchin ab5aea40a6 Stream: set findMulti function as protected
let's not expose it until the API is not accepted
widely by the dev mailing list
2015-03-24 17:13:14 +01:00
Martino Facchin c25dc61bd6 Merge pull request #2814 from facchinm/test_pr2696
Fix findUntil in Stream library
2015-03-24 15:24:42 +00:00
Jim Leonard (Xuth) f43a7a698e Fix findUntil in Stream library
PR #2696 without timeout-related changes
2015-03-24 12:31:50 +01:00
Martino Facchin 046f335d5f Merge pull request #2812 from facchinm/test_pr2794
EEPROM library V2
2015-03-24 09:24:00 +00:00
Martino Facchin 54da627789 EEPROM: examples: fix Serial for board Leonardo 2015-03-24 10:20:00 +01:00
Chris--A bd2b9d1afd Fixed EEPROM examples and added readme 2015-03-24 13:58:01 +10:00
Chris--A ab14475248 Updated EEPROM examples.
Removed hard coded lengths, which were incorrect for standard Arduino's
now.
2015-03-20 12:06:20 +10:00
Chris--A 28cff64b80 Small tweaks to EEPROM lib and examples. 2015-03-19 17:13:32 +10:00
Victor Aprea 0e898d5e03 Do not influence state of SS if it's already been set to an output previously, e.g. by user sketch
squashes and closes PR #2659
2015-03-18 10:37:40 +01:00
Chris--A d6637e7f08 Updated EEPROM storage class
To avoid having a .cpp just for an extern variable definition, `static`
has been chosen over `extern`.

As the `EEPROMClass` class simply wraps functionality located elsewhere,
it is completely compiled away. Even though each translation unit which
includes the header will get a copy with internal linkage, there is no
associated overhead.

More info
[here](http://stackoverflow.com/questions/29098518/extern-variable-only-in-header-unexpectedly-working-why)
2015-03-18 18:56:08 +10:00
Chris--A 80f01fbab1 Added additional examples to EEPROM lib 2015-03-17 17:17:08 +10:00
Chris--A bed78fd144 Added new version of EEPROM library. 2015-03-17 17:13:47 +10:00
Federico Fissore c46e667e7a Started working on 1.6.2 2015-03-11 11:42:55 +01:00
Federico Fissore 39d1dfc999 Added warning for uncertified boards 2015-03-10 08:52:41 +01:00
Martino Facchin 6a86cbc793 Merge branch 'ide-1.5.x' into SoftwareSerial 2015-03-05 12:33:35 +01:00
Martino Facchin b95533ffd0 SoftwareSerial: match bool API with HardwareSerial 2015-03-05 12:30:01 +01:00
Cristian Maglie 606604d7d6 Update revision log. Version set to 1.6.1. 2015-02-19 18:22:43 +01:00
Cristian Maglie a39364193f "objcopy" recipes are no more tied to "hex" extension
This allow to define specific recipes for every platform
but keeps backward compatibility.

See #2614
2015-02-16 14:39:55 +01:00
Arnav Gupta 79a74aa667 rename hex -> output
using generic term 'output', because for samx32,
output is .bin format and not .hex

Signed-off-by: Arnav Gupta <championswimmer@gmail.com>
2015-02-10 04:31:51 +05:30
Cristian Maglie e93be4855f Corrected some email contacts. 2015-02-05 16:47:22 +01:00
Matthijs Kooijman 90ca3934f2 Prevent low pulse on TX initialization in SoftwareSerial
Previously, the TX pin would be set to output first and then written
high (assuming non-inverted logic). When the pin was previously
configured for input without pullup (which is normal reset state), this
results in driving the pin low for a short when initializing. This could
accidenttally be seen as a stop bit by the receiving side.

By first writing HIGH and then setting the mode to OUTPUT, the pin will
have its pullup enabled for a short while, which is harmless.
2015-01-26 17:04:26 +01:00
Matthijs Kooijman 9cf3740a03 Remove unneeded #ifdef in SoftwareSerial
The debugPulse function definition already checks for _DEBUG, resulting
in an empty function definiton and the function call being optimized
away.
2015-01-26 17:03:25 +01:00
Matthijs Kooijman ead2881b1c Fix SoftwareSerial timings
Instead of using a lookup table with (wrong) timings, this calculates
the timings in SoftwareSerial::begin. This is probably a bit slower, but
since it typically happens once, this shouldn't be a problem.
Additionally, since the lookup tables can be removed, this is also a lot
smaller, as well as supporting arbitrary CPU speeds and baudrates,
instead of the limited set that was defined before.

Furthermore, this switches to use the _delay_loop_2 function from
avr-libc instead of a handcoded delay function. The avr-libc function
only takes two instructions, as opposed to four instructions for the old
one. The compiler also inlines the avr-libc function, which makes the
timings more reliable.

The calculated timings directly rely on the instructions generated by
the compiler, since a significant amount of time is spent processing
(compared to the delays, especially at higher speeds). This means that
if the code is changed, or a different compiler is used, the
calculations might need changing (though a few cycles more or less
shouldn't cause immediate breakage).

The timings in the code have been calculated from the assembly generated
by gcc 4.8.2 and gcc 4.3.2.

The RX baudrates supported by SoftwareSerial are still not unlimited. At
16Mhz, using gcc 4.8.2, everything up to 115200 works. At 8Mhz, it works
up to 57600. Using gcc 4.3.2, it also works up to 57600 at 16Mhz and up
to 38400 at 8Mhz. Note that at these highest speeds, communication
works, but is still quite sensitive to other interrupts (like the
millis() interrupts) when bytes are sent back-to-back, so there still
are corrupted bytes in RX.

TX works up to 115200 for all combinations of compiler and clock rates.

This fixes #2019
2015-01-26 17:03:25 +01:00
Matthijs Kooijman 08fa593916 Disable the RX PCINT inside SoftwareSerial::recv
Before, the interrupt would remain enabled during reception, which would
re-set the PCINT flag because of the level changes inside the received
byte. Because interrupts are globally disabled, this would not
immediately trigger an interrupt, but the flag would be remembered to
trigger another PCINT interrupt immediately after the first one is
processed.

Typically this was not a problem, because the second interrupt would see
the stop bit, or an idle line, and decide that the interrupt triggered
for someone else. However, at high baud rates, this could cause the
next interrupt for the real start bit to be delayed so much that the
byte got corrupted.

By clearing the interrupt mask bit for just the RX pin (as opposed to
the PCINT mask bit for the entire port), any PCINT events on other bits
can still set the PCINT flag and be processed as normal. In this case,
it's likely that there will be corruption, but that's inevitable when
(other) interrupts happen during SoftwareSerial reception.
2015-01-26 17:03:25 +01:00
Matthijs Kooijman ce6b0f89e3 Optimize SoftwareSerial::setRxIntMsk()
This precalculates the mask register and value, making setRxIntMask
considerably less complicated. Right now, this is not a big deal, but
simplifying it allows using it inside the ISR next.
2015-01-26 17:03:25 +01:00
Matthijs Kooijman ddbe3174f0 In SoftwareSerial::recv, only calculate the new tail once
This shortens the generated code a bit more.
2015-01-26 17:03:25 +01:00
Matthijs Kooijman 9d8f350ffe Mark SoftwareSerial::recv and handle_interrupt as always_inline
Since those functions are only called once now, it makes sense to inline
them. This saves a few bytes of program space, but also saves a few
cycles in the critical RX path.
2015-01-26 17:03:25 +01:00
Matthijs Kooijman 5af847d3a4 In SoftwareSerial, use ISR_ALIASOF to prevent duplication
Previously, up to four separate but identical ISR routines were defined,
for PCINT0, PCINT1, PCINT2 and PCINT3. Each of these would generate
their own function, with a lot of push-popping because another function
was called.

Now, the ISR_ALIASOF macro from avr-libc is used to declare just the
PCINT0 version and make all other ISRs point to that one, saving a lot
of program space, as well as some speed because of improved inlining.

On an Arduino Uno with gcc 4.3, this saves 168 bytes. With gcc 4.8, this
saves 150 bytes.
2015-01-26 17:03:25 +01:00
Matthijs Kooijman 87f89f6100 Optimize SoftwareSerial::recv
Similar to SoftwareSerial::write, this rewrites the loop to only touch
the MSB and then shift those bits up, allowing the compiler to generate
more efficient code. Unlike the write function however, it is not needed
to put all instance variables used into local variables, for some reason
the compiler already does this (and doing it manually even makes the
code bigger).

On the Arduino Uno using gcc 4.3 this saves 26 bytes. Using gcc 4.8 this
saves 30 bytes.

Note that this removes the else clause in the code, making the C code
unbalanced, which looks like it breaks timing balance. However, looking
at the code generated by the compiler, it turns out that the old code
was actually unbalanced, while the new code is properly balanced.
2015-01-26 17:03:25 +01:00
Matthijs Kooijman 764f24266e Further optimize SoftwareSerial::write
This change restructures the loop, to help the compiler generate shorter
code (because now only the LSB of the data byte is checked and
subsequent bytes are shifted down one by one, it can use th "skip if bit
set" instruction).

Furthermore, it puts most attributes in local variables, which causes
the compiler to put them into registers. This makes the timing-critical
part of the code smaller, making it easier to provide accurate timings.

On an Arduino uno using gcc 4.3, this saves 58 bytes. On gcc 4.8, this
saves 14 bytes.
2015-01-26 17:03:25 +01:00
Matthijs Kooijman 80ea38b1dc Mark SoftwareSerial::tx_pin_write as "always_inline"
Somehow gcc 4.8 doesn't inline this function, even though it is always
called with constant arguments and can be reduced to just a few
instructions when inlined. Adding the always_inline attribute makes gcc
inline it, saving 46 bytes on the Arduino uno.

gcc 4.3 already inlined this function, so there are no space
savings there.
2015-01-26 17:03:25 +01:00
Matthijs Kooijman 416198a03b Simplify SoftwareSerial::write
Before, there was nearly identical code for the inverted and regular
cases. However, simply inverting the byte in the inverted case allows
using the regular code twice, reducing the generated code size by 100
bytes (on an Arduino Uno and gcc 4.3, on gcc 4.8 the reduction is 50
bytes).
2015-01-26 17:03:25 +01:00