Commit Graph

262 Commits

Author SHA1 Message Date
Cristian Maglie 37e2914dbb [HID] added 'const' qualifier in HID initialization
See https://github.com/arduino/Arduino/pull/3840#discussion_r40438845
2015-09-28 13:32:01 +02:00
Cristian Maglie dfe6048175 Merge branch 'pluggable_hid_impr' of https://github.com/cmaglie/Arduino 2015-09-28 12:06:35 +02:00
Arturo Guadalupi d508e4dc54 Added Arduino Zero exclusion to README 2015-09-28 11:29:18 +02:00
Cristian Maglie 5a5cf764db HID: merged HID_Descriptor into HIDDescriptorListNode
This simplifies the object model and produce a small gain in code
size and performance.
2015-09-22 16:51:30 +02:00
Cristian Maglie 9b9bf95324 HID: Renamed fields in HIDDescriptorListNode and HID_Descriptor
In particular HIDDescriptorListNode.cb has been renamed to
HIDDescriptorListNode.descriptor because it contains decriptor data
and not callbacks.

Moreover the HID_Descriptor.descriptor field has been renamed
to HID_Descriptor.data so the structure has now two fields length
and data.

   typedef struct __attribute__((packed)) {
     uint16_t length;
     const void* data;
   } HID_Descriptor;

   class HIDDescriptorListNode {
   public:
     HIDDescriptorListNode *next = NULL;
     const HID_Descriptor *descriptor;
     HIDDescriptorListNode(const HID_Descriptor *d) : descriptor(d) { }
   };

This imply a change in the use of the node from:

  node->cb->lenght
  node->cd->descriptor

to

  node->descriptor->length
  node->descriptor->data
2015-09-22 16:49:14 +02:00
Arturo Guadalupi d775df409f Modified reference to Leonardo only in the examples
According to #3786 removed the reference to Leonardo only in while(!Serial) of the examples.
Changed in in "wait for serial port to connect. Needed for native USB port only"
2015-09-21 14:58:58 +02:00
Nico 6153b93907 Remove Raw HID definitions at wrong place 2015-09-20 11:04:42 +02:00
Cristian Maglie b5911b2bc5 Fixed wrong category in EEPROM
See #3812
2015-09-18 11:23:11 +02:00
Cristian Maglie 08de587da7 Added categories to libraries
Fix #3812
2015-09-18 11:01:08 +02:00
Nate Williams 0b27210105 Wire (AVR): Fix bug with repeated START
Fix #66
2015-08-26 16:02:02 +02:00
Sandeep Mistry eab6601ebc implement Wire.end() for AVR core 2015-08-25 10:24:24 -04:00
NicoHood d1fe40060e Added 16 byte endpoint support 2015-08-12 17:48:17 +02:00
NicoHood 488ace3d13 Fixed HID Reports >255 bytes 2015-08-12 17:48:17 +02:00
Martino Facchin 99a27d0bd8 rework HID-based libraries and add Due fallback 2015-07-16 13:13:53 +02:00
Martino Facchin 3d61f6e37e 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 47efb352c9 rework HID class functions scopes 2015-07-16 13:13:52 +02:00
Martino Facchin 3cf30dff25 rename Setup typedef struct to USBSetup
was really too common
2015-07-16 13:13:52 +02:00
Martino Facchin 3d0331b8f6 fix HID headers 2015-07-16 13:13:51 +02:00
Martino Facchin 30ebf7f924 fix HID descriptors bigger than 127 bytes 2015-07-16 13:13:51 +02:00
Martino Facchin f367bcca2c move HID library to AVR specific location 2015-07-16 13:13:51 +02:00
Federico Fissore b5a130afb5 Examples: mass code format. See example_formatter.conf 2015-07-06 15:19:05 +02:00
Matthew Lowe c13cf02651 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 b40f171220 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
Federico Fissore 7c585abf3f 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
Arturo Guadalupi 9a9760cc86 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
Federico Fissore da5830c4bf LibraryManager: better type filtering 2015-03-27 14:51:19 +01:00
Martino Facchin f2debfa255 Merge pull request #2812 from facchinm/test_pr2794
EEPROM library V2
2015-03-24 09:24:00 +00:00
Martino Facchin d8656b8c52 EEPROM: examples: fix Serial for board Leonardo 2015-03-24 10:20:00 +01:00
Chris--A 5da9792cd6 Fixed EEPROM examples and added readme 2015-03-24 13:58:01 +10:00
Chris--A 26577474ef 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 fd4323f360 Small tweaks to EEPROM lib and examples. 2015-03-19 17:13:32 +10:00
Victor Aprea 8fcf5c9406 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 c9ec4eabda 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 dd1ec9920b Added additional examples to EEPROM lib 2015-03-17 17:17:08 +10:00
Chris--A 46e810cf07 Added new version of EEPROM library. 2015-03-17 17:13:47 +10:00
Martino Facchin 6b396732ca Merge branch 'ide-1.5.x' into SoftwareSerial 2015-03-05 12:33:35 +01:00
Martino Facchin 97fb130175 SoftwareSerial: match bool API with HardwareSerial 2015-03-05 12:30:01 +01:00
Cristian Maglie 17ad4fe5ef Corrected some email contacts. 2015-02-05 16:47:22 +01:00
Matthijs Kooijman 230f987ba6 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 827c349a17 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 0a6072dccb 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 08c3bfdc9f 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 5f2f0ef4c8 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 b6ba4b6aab 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 03f242b231 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 17b9b53737 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 157ec97540 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 c69c0b52aa 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 fe390c3cc8 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 ddcdc901a7 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