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
31 changes: 19 additions & 12 deletions Boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -665,22 +665,29 @@ 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.

// hardware: TX0=1, TX1=2, RX0=3, MISO=12, MOSI=13, SCLK=14, CS=15, A0=17
// board depended defaults: LED_BUILTIN, SDA, SCL
// 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 1
#define TOTAL_PINS 18 // 11 digital + 1 analog + 6 inaccessible
#define VERSION_BLINK_PIN LED_BUILTIN
Copy link
Member

Choose a reason for hiding this comment

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

Remove VERSION_BLINK_PIN. The version blink sequence takes too long and excluding this define will exclude the version blink sequence - saving up to 2.5 seconds or more of startup time (since each Firmata version increment adds additional time to the sequence).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will be removed with next commit

#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 PIN_SERIAL1_TX 2
Copy link
Member

Choose a reason for hiding this comment

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

I don't think Firmata Serial supports just a TX pin without the RX pair.

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 thought so and that is way I choose to set #define IS_PIN_SERIAL(p) ((p) == 1 || (p) == 3). It's more to be complete about the theoretical possibilities but maybe it is better to remove the PIN_SERIAL1_TX.

#define IS_PIN_DIGITAL(p) (((p) >= 0 && (p) <= 5) || ((p) >= 12 && (p) <= 16))
#define IS_PIN_ANALOG(p) ((p) == A0)
Copy link
Contributor

Choose a reason for hiding this comment

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

What about the wifio?

static const uint8_t A0 = 14;
static const uint8_t A1 = 15;
static const uint8_t A2 = 16;
static const uint8_t A3 = 17;
static const uint8_t A4 = 18;
static const uint8_t A5 = 19;
static const uint8_t A6 = 20;
static const uint8_t A7 = 21;

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please tell me where these constants are needed for. A0 = 17 is already in use in the esp8266/Arduino project for the one and only analog input pin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, found it myself. For this board probably a separate definition is needed in Board.h and that may not be enough to make it work.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

#define IS_PIN_PWM(p) IS_PIN_DIGITAL(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) >= 12 && (p) <= 15)
#define IS_PIN_INTERRUPT(p) (((p) >= 0 && (p) <= 5) || ((p) >= 12 && (p) <= 15))
#define IS_PIN_SERIAL(p) ((p) == 1 || (p) == 3)
#define PIN_TO_DIGITAL(p) (p)
#define PIN_TO_ANALOG(p) ((p) - 17)
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
#define PIN_TO_SERVO(p) p
#define PIN_TO_SERVO(p) (p)


// anything else
Expand Down