-
Notifications
You must be signed in to change notification settings - Fork 517
Spark #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spark #141
Changes from all commits
58b3d58
c04a31c
10168c1
0893eb5
b4ca774
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,11 +5,15 @@ | |
|
|
||
| #include <inttypes.h> | ||
|
|
||
| #ifdef SPARK | ||
| #include "application.h" | ||
| #else | ||
| #if defined(ARDUINO) && ARDUINO >= 100 | ||
| #include "Arduino.h" // for digitalRead, digitalWrite, etc | ||
| #include "Arduino.h" // for digitalRead, digitalWrite, etc | ||
| #else | ||
| #include "WProgram.h" | ||
| #endif | ||
| #endif | ||
|
|
||
| // Normally Servo.h must be included before Firmata.h (which then includes | ||
| // this file). If Servo.h wasn't included, this allows the code to still | ||
|
|
@@ -332,6 +336,22 @@ writePort(port, value, bitmask): Write an 8 bit port. | |
| #define PIN_TO_SERVO(p) ((p) - 2) | ||
|
|
||
|
|
||
| // Spark | ||
| #elif defined(SPARK) | ||
| #define TOTAL_ANALOG_PINS 8 | ||
| #define VERSION_BLINK_PIN 7 | ||
| #define IS_PIN_DIGITAL(p) (((p) >= 0 && (p) <= 7) || ((p) >= 10 && (p) <= 17)) | ||
| #define IS_PIN_ANALOG(p) ((p) >= 10 && (p) <= 17) | ||
| #define IS_PIN_PWM(p) digitalPinHasPWM(p) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This won't work as it does with the other boards defined in this file. The Spark's PWM support is available on D0, D1, A0, A1, A4, A5, A6 and A7.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it will work as long as the spark core firmware defines digitalPinHasPWM
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about #define IS_PIN_PWM(p) ((p) == 0 || (p) == 1 || ((p) >= 10 && (p) <= 17))
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally the equivalent of an arduino variant pins_arduino.h file should be added to spark/core-firmware. Here's an example from the standard arduino variant: https://github.com/arduino/Arduino/blob/master/hardware/arduino/variants/standard/pins_arduino.h |
||
| #define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS) //?? | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an issue with Firmata in general. When servo support was first added the number of pins supporting Servo (via the Servo library) was equal to the number of Arduino pins supporting servo. This is no longer the case (and has not been for a few years). MAX_SERVOS is defined in the servo library and is determined by the number of timers available and the number of servos supported by each timer.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for reference: #62
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about #define IS_PIN_SERVO(p) ((p) == 0 || (p) == 1 || ((p) >= 10 && (p) <= 17)) |
||
| #define IS_PIN_I2C(p) ((p) == 0 || (p) == 1) | ||
| #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK) | ||
| #define PIN_TO_DIGITAL(p) (p) | ||
| #define PIN_TO_ANALOG(p) (p)-10 | ||
| #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p) | ||
| #define PIN_TO_SERVO(p) (p) | ||
| #define IS_PIN_DISABLED(p) ((p) == 8 || (p) == 9) | ||
|
|
||
| // anything else | ||
| #else | ||
| #error "Please edit Boards.h with a hardware abstraction for this board" | ||
|
|
@@ -402,14 +422,14 @@ static inline unsigned char writePort(byte port, byte value, byte bitmask) | |
| } | ||
| #else | ||
| byte pin=port*8; | ||
| if ((bitmask & 0x01)) digitalWrite(PIN_TO_DIGITAL(pin+0), (value & 0x01)); | ||
| if ((bitmask & 0x02)) digitalWrite(PIN_TO_DIGITAL(pin+1), (value & 0x02)); | ||
| if ((bitmask & 0x04)) digitalWrite(PIN_TO_DIGITAL(pin+2), (value & 0x04)); | ||
| if ((bitmask & 0x08)) digitalWrite(PIN_TO_DIGITAL(pin+3), (value & 0x08)); | ||
| if ((bitmask & 0x10)) digitalWrite(PIN_TO_DIGITAL(pin+4), (value & 0x10)); | ||
| if ((bitmask & 0x20)) digitalWrite(PIN_TO_DIGITAL(pin+5), (value & 0x20)); | ||
| if ((bitmask & 0x40)) digitalWrite(PIN_TO_DIGITAL(pin+6), (value & 0x40)); | ||
| if ((bitmask & 0x80)) digitalWrite(PIN_TO_DIGITAL(pin+7), (value & 0x80)); | ||
| if ((bitmask & 0x01)) digitalWrite(PIN_TO_DIGITAL(pin+0), (value & 0x01) == 0x01 ? 1 : 0 ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reasoning behind this change?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spark (and maybe others) don't support any random positive number as a truth value. @rwaldron is attempting to push a fix upstream https://github.com/spark/core-firmware/issues/247 so it may not be necessary |
||
| if ((bitmask & 0x02)) digitalWrite(PIN_TO_DIGITAL(pin+1), (value & 0x02) == 0x02 ? 1 : 0 ); | ||
| if ((bitmask & 0x04)) digitalWrite(PIN_TO_DIGITAL(pin+2), (value & 0x04) == 0x04 ? 1 : 0 ); | ||
| if ((bitmask & 0x08)) digitalWrite(PIN_TO_DIGITAL(pin+3), (value & 0x08) == 0x08 ? 1 : 0 ); | ||
| if ((bitmask & 0x10)) digitalWrite(PIN_TO_DIGITAL(pin+4), (value & 0x10) == 0x10 ? 1 : 0 ); | ||
| if ((bitmask & 0x20)) digitalWrite(PIN_TO_DIGITAL(pin+5), (value & 0x20) == 0x20 ? 1 : 0 ); | ||
| if ((bitmask & 0x40)) digitalWrite(PIN_TO_DIGITAL(pin+6), (value & 0x40) == 0x40 ? 1 : 0 ); | ||
| if ((bitmask & 0x80)) digitalWrite(PIN_TO_DIGITAL(pin+7), (value & 0x80) == 0x80 ? 1 : 0 ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
if (value == LOW)
{
PIN_MAP[pin].gpio_peripheral->BRR = PIN_MAP[pin].gpio_pin;
} else
{
PIN_MAP[pin].gpio_peripheral->BSRR = PIN_MAP[pin].gpio_pin;
}That would allow this changeset to be reverted. I've filed this bug: https://github.com/spark/core-firmware/issues/247
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The necessary patch to Spark's core-firmware has landed, so this whole block can be reverted now. particle-iot/device-os@337a86b |
||
| #endif | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,10 @@ | |
| //****************************************************************************** | ||
|
|
||
| #include "Firmata.h" | ||
|
|
||
| #ifndef SPARK | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the SPARK library included in the Arduino core distribution?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spark is a compiler define, not unlike ARDUINO for version
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the difference I'm getting at is that ARDUINO covers all arduino variants but I'm assuming Spark core is not an arduino variant (and included in the Arduino distribution) unless I'm mistaken.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No Spark isnt an arduino variant .. I have no idea what it takes to get that blessing..
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As long as it's in line with an arduino variant (having the correct pin defines, etc) it should be okay to include. Up to this point everything in firmata/arduino has been specific to boards included in the core distribution (well at least included at one time or another... some have been dropped). Are all of the same basic features as something like an Arduino UNO supported for Spark Core (I2C, analog pins can be set as digital pins, etc) or are exceptions needed - not sure how to handle that.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reviewing this again I've realized that HardwareSerial should no longer be included in Firmata.cpp anyway. Stream.h should be included in it's place and then HardwareSerial.h should be included in StandardFirmata.ino before the Firmata.h include. If someone creates an ethernet version of StandardFirmata they would include Ethernet rather than HardwareSerial. So someone should try to get Stream included (and properly integrated) in spark/core-firmware. I'll make the necessary updates to Firmata.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's the proposed change to Firmata.cpp (and all Firmata examples): #144. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For reference, here is an ethernet version of
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @blakejakopovic We have Ethernet support in the configurable branch. I recommend adding a similar keep alive functionality (see the maintain method here) to your library. |
||
| #include "HardwareSerial.h" | ||
| #endif | ||
|
|
||
| extern "C" { | ||
| #include <string.h> | ||
|
|
@@ -28,8 +31,8 @@ extern "C" { | |
|
|
||
| void FirmataClass::sendValueAsTwo7bitBytes(int value) | ||
| { | ||
| FirmataSerial->write(value & B01111111); // LSB | ||
| FirmataSerial->write(value >> 7 & B01111111); // MSB | ||
| FirmataSerial->write(value & 127); // LSB | ||
| FirmataSerial->write(value >> 7 & 127); // MSB | ||
| } | ||
|
|
||
| void FirmataClass::startSysex(void) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this include "application" is way too generic. Should be renamed in core project if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i guess it's okay though since it's within the ifdef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arguably this could be part of a SparkFirmata.ino that's tailored to the Spark
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the Spark is just another "arduino" then it may make sense to included it with the firmata/arduino stuff. By this I mean if you can already use most Arduino libraries with the Spark, you program it with the Arduino IDE, etc. If that is not the case it may be better to create a separate repo firmata/spark. The reason being that I wouldn't want to maintain exceptions for boards that are only partially Arduino compatible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also if Firmata.cpp is 100% compatible then simply a separate SparkFirmata.ino could work as well, but we also need to consider the role of configurable firmata not just another variant of StandardFirmata (I finally got around to starting on the firmatabuilder tool).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's an issue: there are similar, but Spark-specific versions of all the libraries, I any speak to the compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't* not "any"