Skip to content
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

pin functions based on board depended defaults #278

Merged
merged 8 commits into from
Apr 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions Boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -665,22 +665,26 @@ writePort(port, value, bitmask): Write an 8 bit port.
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
#define PIN_TO_SERVO(p) ((p) - 2)

// ESP8266 generic
// ESP8266
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are several different popular boards using this chip. We should include a comment that states which specific boards have been tested to work with this set of pin definitions.

// note: boot mode GPIOs 0, 2 and 15 can be used as outputs, GPIOs 6-11 are in use for flash IO
#elif defined(ESP8266)
#define TOTAL_ANALOG_PINS 0
#define TOTAL_PINS 17
#define VERSION_BLINK_PIN 4
// #define IS_PIN_DIGITAL(p) ((p) == 0 || (p) == 1 || (p) == 2 || (p) == 3 || (p) == 4 || (p) == 5 || (p) == 12 || (p) == 13 || (p) == 14 || (p) == 15 || (p) == 16) //for wifi dont protect serial pins because these things only have 2 pins otherwise
#define IS_PIN_DIGITAL(p) ((p) == 0 || (p) == 2 || (p) == 4 || (p) == 5 || (p) == 12 || (p) == 13 || (p) == 14 || (p) == 15 || (p) == 16)
#define IS_PIN_ANALOG(p) (false)
#define IS_PIN_PWM(p) (false)
#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
#define IS_PIN_I2C(p) (false)
#define IS_PIN_SPI(p) (false)
#define TOTAL_ANALOG_PINS NUM_ANALOG_INPUTS
#define TOTAL_PINS A0 + NUM_ANALOG_INPUTS
#define PIN_SERIAL_RX 3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to verify - this maps to Serial (as opposed to Serial1) right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pin 3+1 are Serial (or port 0) and can be used for SerialFirmata.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PIN_SERIAL_RX and PIN_SERIAL_TX are no-ops: https://github.com/firmata/arduino/blob/master/utility/SerialFirmata.cpp#L237-L240. No harm in including them here but the use of Serial in SerialFirmata is not yet supported due to possible conflicts with boards that use Serial as the primary communication with Firmata.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per this issue: #193

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot about this, cause I'm mixing Firmata, ConfigurableFirmata and my own mods of Firmata a lot. So this is for future use.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do pins 3 and 1 appear to be common for RX and TX across all ESP8266 board variants?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Serial has some special properties with the ESP8266. I don't think they can be completely described in a Boards.h approach (e.g. similar to the PWM resolution you can change the serial pin assignment and there is a Serial1 but you typically can't use the RX pin). The details are described here.

All boards seem to have Serial in common and the default mapping for Serial is always pins 1 and 3.

#define PIN_SERIAL_TX 1
#define IS_PIN_DIGITAL(p) (((p) >= 0 && (p) <= 5) || ((p) >= 12 && (p) < A0))
#define IS_PIN_ANALOG(p) ((p) >= A0 && (p) < A0 + NUM_ANALOG_INPUTS)
#define IS_PIN_PWM(p) digitalPinHasPWM(p)
#define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) < MAX_SERVOS)
#define IS_PIN_I2C(p) ((p) == SDA || (p) == SCL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is SDA and SCL defined for all ESP variants or only specific ones?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know all these boards myself, but I checked all the "variants...\pins_arduino.h" header files. They all have the pins defined, mostly on pins 4+5, but not all. Maybe the SDA/SCL pins are not always physically available to the user. From the project documentation I get the impression that I2C is always available. The pins in the header files are defaults but can be remapped to almost any other pins with Wire.begin(...) similar to SoftwareSerial.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly on pins 4+5, but not all

Confirmed.

Sparkfun Thing:

static const uint8_t SDA = 2;
static const uint8_t SCL = 14;

(The only exception)

#define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
#define IS_PIN_INTERRUPT(p) (digitalPinToInterrupt(p) > NOT_AN_INTERRUPT)
#define IS_PIN_SERIAL(p) ((p) == PIN_SERIAL_RX || (p) == PIN_SERIAL_TX)
#define PIN_TO_DIGITAL(p) (p)
#define PIN_TO_ANALOG(p) ((p) - 17)
#define PIN_TO_ANALOG(p) ((p) - A0)
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
#define PIN_TO_SERVO(p) p
#define PIN_TO_SERVO(p) (p)
#define DEFAULT_PWM_RESOLUTION 10


// anything else
Expand All @@ -697,6 +701,9 @@ writePort(port, value, bitmask): Write an 8 bit port.
#define IS_PIN_SERIAL(p) 0
#endif

#ifndef DEFAULT_PWM_RESOLUTION
#define DEFAULT_PWM_RESOLUTION 8
#endif

/*==============================================================================
* readPort() - Read an 8 bit port
Expand Down
2 changes: 1 addition & 1 deletion examples/StandardFirmata/StandardFirmata.ino
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
}
if (IS_PIN_PWM(pin)) {
Firmata.write(PIN_MODE_PWM);
Firmata.write(8); // 8 = 8-bit resolution
Firmata.write(DEFAULT_PWM_RESOLUTION);
}
if (IS_PIN_DIGITAL(pin)) {
Firmata.write(PIN_MODE_SERVO);
Expand Down
2 changes: 1 addition & 1 deletion examples/StandardFirmataChipKIT/StandardFirmataChipKIT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
}
if (IS_PIN_PWM(pin)) {
Firmata.write(PIN_MODE_PWM);
Firmata.write(8); // 8 = 8-bit resolution
Firmata.write(DEFAULT_PWM_RESOLUTION);
}
if (IS_PIN_DIGITAL(pin)) {
Firmata.write(PIN_MODE_SERVO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
}
if (IS_PIN_PWM(pin)) {
Firmata.write(PIN_MODE_PWM);
Firmata.write(8); // 8 = 8-bit resolution
Firmata.write(DEFAULT_PWM_RESOLUTION);
}
if (IS_PIN_DIGITAL(pin)) {
Firmata.write(PIN_MODE_SERVO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
}
if (IS_PIN_PWM(pin)) {
Firmata.write(PIN_MODE_PWM);
Firmata.write(8); // 8 = 8-bit resolution
Firmata.write(DEFAULT_PWM_RESOLUTION);
}
if (IS_PIN_DIGITAL(pin)) {
Firmata.write(PIN_MODE_SERVO);
Expand Down
2 changes: 1 addition & 1 deletion examples/StandardFirmataPlus/StandardFirmataPlus.ino
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
}
if (IS_PIN_PWM(pin)) {
Firmata.write(PIN_MODE_PWM);
Firmata.write(8); // 8 = 8-bit resolution
Firmata.write(DEFAULT_PWM_RESOLUTION);
}
if (IS_PIN_DIGITAL(pin)) {
Firmata.write(PIN_MODE_SERVO);
Expand Down
2 changes: 1 addition & 1 deletion examples/StandardFirmataWiFi/StandardFirmataWiFi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
}
if (IS_PIN_PWM(pin)) {
Firmata.write(PIN_MODE_PWM);
Firmata.write(8); // 8 = 8-bit resolution
Firmata.write(DEFAULT_PWM_RESOLUTION);
}
if (IS_PIN_DIGITAL(pin)) {
Firmata.write(PIN_MODE_SERVO);
Expand Down