Skip to content

Commit 2dce29f

Browse files
committed
fix: libraries: manually handled pin remapping files
Previously all libraries invoked either high-level APIs (transparently remapped, like the user sketch) or low-level ESP-IDF calls (where the remap to GPIO numbers had to be added manually). Since 3.x, some of these are mixed (for example, periman* APIs are remapped, while soc* are not). This must be handled by disabling the automatic API remapping and making sure all calls use GPIO numbers.
1 parent 61890e2 commit 2dce29f

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

Diff for: libraries/ESP_I2S/src/ESP_I2S.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Disable the automatic pin remapping of the API calls in this file
2+
#define ARDUINO_CORE_BUILD
3+
14
#include "ESP_I2S.h"
25

36
#if SOC_I2S_SUPPORTED

Diff for: libraries/Ethernet/src/ETH.cpp

+15-12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1919
*/
2020

21+
// Disable the automatic pin remapping of the API calls in this file
22+
#define ARDUINO_CORE_BUILD
23+
2124
#include "ETH.h"
2225
#include "esp_system.h"
2326
#include "esp_event.h"
@@ -98,13 +101,13 @@ bool ETHClass::begin(eth_phy_type_t type, uint8_t phy_addr, int mdc, int mdio, i
98101
eth_esp32_emac_config_t mac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG();
99102
mac_config.clock_config.rmii.clock_mode = (clock_mode) ? EMAC_CLK_OUT : EMAC_CLK_EXT_IN;
100103
mac_config.clock_config.rmii.clock_gpio = (1 == clock_mode) ? EMAC_APPL_CLK_OUT_GPIO : (2 == clock_mode) ? EMAC_CLK_OUT_GPIO : (3 == clock_mode) ? EMAC_CLK_OUT_180_GPIO : EMAC_CLK_IN_GPIO;
101-
mac_config.smi_mdc_gpio_num = mdc;
102-
mac_config.smi_mdio_gpio_num = mdio;
104+
mac_config.smi_mdc_gpio_num = digitalPinToGPIONumber(mdc);
105+
mac_config.smi_mdio_gpio_num = digitalPinToGPIONumber(mdio);
103106

104-
_pin_mcd = mdc;
105-
_pin_mdio = mdio;
107+
_pin_mcd = digitalPinToGPIONumber(mdc);
108+
_pin_mdio = digitalPinToGPIONumber(mdio);
106109
_pin_rmii_clock = mac_config.clock_config.rmii.clock_gpio;
107-
_pin_power = power;
110+
_pin_power = digitalPinToGPIONumber(power);
108111

109112
if(!perimanClearPinBus(_pin_rmii_clock)){ return false; }
110113
if(!perimanClearPinBus(_pin_mcd)){ return false; }
@@ -130,7 +133,7 @@ bool ETHClass::begin(eth_phy_type_t type, uint8_t phy_addr, int mdc, int mdio, i
130133

131134
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
132135
phy_config.phy_addr = phy_addr;
133-
phy_config.reset_gpio_num = power;
136+
phy_config.reset_gpio_num = _pin_power;
134137

135138
esp_eth_phy_t *phy = NULL;
136139
switch(type){
@@ -381,12 +384,12 @@ bool ETHClass::beginSPI(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq,
381384
_spi_freq_mhz = spi_freq_mhz;
382385
}
383386
_phy_type = type;
384-
_pin_cs = cs;
385-
_pin_irq = irq;
386-
_pin_rst = rst;
387-
_pin_sck = sck;
388-
_pin_miso = miso;
389-
_pin_mosi = mosi;
387+
_pin_cs = digitalPinToGPIONumber(cs);
388+
_pin_irq = digitalPinToGPIONumber(irq);
389+
_pin_rst = digitalPinToGPIONumber(rst);
390+
_pin_sck = digitalPinToGPIONumber(sck);
391+
_pin_miso = digitalPinToGPIONumber(miso);
392+
_pin_mosi = digitalPinToGPIONumber(mosi);
390393

391394
#if ETH_SPI_SUPPORTS_CUSTOM
392395
if(_spi != NULL){

Diff for: libraries/SD_MMC/src/SD_MMC.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// Disable the automatic pin remapping of the API calls in this file
16+
#define ARDUINO_CORE_BUILD
17+
1518
#include "pins_arduino.h"
1619
#include "io_pin_remap.h"
1720
#include "SD_MMC.h"

0 commit comments

Comments
 (0)