esp8266 / esp8266/Arduino

[Enhancement] Make Wire and SPI lib compatible between ESP32 and ESP8266

Open
#3,691 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
16.7k
Forks
13.1k
PR merge metrics
No merged PRs in 30d

Description

### Basic Infos
This is a feature extension request to make the ESP32 and ESP8266 library compatible with each other.
From my analysis i would suggest to modify ESP8266 library and align with ESP32 library. However other modifications are also thinkable. For more specific suggestions, see below.

Discussion reference:
https://github.com/olikraus/u8g2/issues/377
https://github.com/olikraus/u8g2/issues/378

#### Hardware
Hardware: n.a.
Core Version: head

### Description

Problem description

Assigning movable pins for ESP32 and ESP8266 differs between the projects.

### Settings in IDE

n.a.

### Sketch
n.a.

### Debug Messages

n.a.

### Analysis of the Problem

SPI Lib ESP8266:
Link: https://github.com/esp8266/Arduino/blob/master/libraries/SPI/SPI.h#L56
Uses "pins" member function to assign movable pins:
pins(int8_t sck, int8_t miso, int8_t mosi, int8_t ss);
Note, that ss and mosi are required areguments

SPI Lib ESP32:
Link: https://github.com/espressif/arduino-esp32/blob/master/libraries/SPI/src/SPI.h#L55
The begin() member function accepts several (optional) arguments for
the assignment of the pin numbers:
"void begin(int8_t sck=SCK, int8_t miso=MISO, int8_t mosi=MOSI, int8_t ss=-1);"

Wire Lib ESP8266
Link: https://github.com/esp8266/Arduino/blob/master/libraries/Wire/Wire.h#L53
Has a "pins" member function which is declared as deprecated.
"pins(int sda, int scl)"
Instead use "begin(int sda, int scl);"

Wire Lib ESP32
Link: https://github.com/espressif/arduino-esp32/blob/master/libraries/Wire/src/Wire.h#L55
The ESP32 Wire lib extends the begin() member function with optional pin
arguments and also a frequency paramenter:
"void begin(int sda=-1, int scl=-1, uint32_t frequency=100000);"

### Conclusion

1. All four extensions are none-standard extensions on the Arduino Core libraries (not
sure whether they are documented)
2. SPI Lib extensions are completly incompatible between ESP32 and ESP8266
3. Wire extensions partly compatible between ESP32 and ESP8266, but ESP has
an extra frequency parameter and scl line is optional, this means you can specify "begin(X)"
to move the sd line to pin X, which is not possible on ESP8266.
4. The extension of "begin()" member function is used in 3 of 4 cases. So the
approach in SPI lib of ESP8266 does not seem to fit.

### Suggestions for modification

ESP8266 and ESP32 should agree on common code regarding the extension
for movable pins for SPI and Wire functionality.

From seeing the above differences my suggestion is to modify the ESP8266 project
to make it compatible to the ESP32 project:
- SPI Lib: Introduce void begin(int8_t sck=SCK, int8_t miso=MISO, int8_t mosi=MOSI, int8_t ss=-1);
- Wire Lib: Modify "begin(int sda, int scl);" to "void begin(int sda=-1, int scl=-1, uint32_t frequency=100000);"

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.