Skip to content

Commit

Permalink
fix: libraries: manually handled pin remapping files
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pillo79 committed Nov 28, 2023
1 parent 61890e2 commit 2dce29f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
3 changes: 3 additions & 0 deletions libraries/ESP_I2S/src/ESP_I2S.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Disable the automatic pin remapping of the API calls in this file
#define ARDUINO_CORE_BUILD

#include "ESP_I2S.h"

#if SOC_I2S_SUPPORTED
Expand Down
27 changes: 15 additions & 12 deletions libraries/Ethernet/src/ETH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

// Disable the automatic pin remapping of the API calls in this file
#define ARDUINO_CORE_BUILD

#include "ETH.h"
#include "esp_system.h"
#include "esp_event.h"
Expand Down Expand Up @@ -98,13 +101,13 @@ bool ETHClass::begin(eth_phy_type_t type, uint8_t phy_addr, int mdc, int mdio, i
eth_esp32_emac_config_t mac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG();
mac_config.clock_config.rmii.clock_mode = (clock_mode) ? EMAC_CLK_OUT : EMAC_CLK_EXT_IN;
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;
mac_config.smi_mdc_gpio_num = mdc;
mac_config.smi_mdio_gpio_num = mdio;
mac_config.smi_mdc_gpio_num = digitalPinToGPIONumber(mdc);
mac_config.smi_mdio_gpio_num = digitalPinToGPIONumber(mdio);

_pin_mcd = mdc;
_pin_mdio = mdio;
_pin_mcd = digitalPinToGPIONumber(mdc);
_pin_mdio = digitalPinToGPIONumber(mdio);
_pin_rmii_clock = mac_config.clock_config.rmii.clock_gpio;
_pin_power = power;
_pin_power = digitalPinToGPIONumber(power);

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

eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
phy_config.phy_addr = phy_addr;
phy_config.reset_gpio_num = power;
phy_config.reset_gpio_num = _pin_power;

esp_eth_phy_t *phy = NULL;
switch(type){
Expand Down Expand Up @@ -381,12 +384,12 @@ bool ETHClass::beginSPI(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq,
_spi_freq_mhz = spi_freq_mhz;
}
_phy_type = type;
_pin_cs = cs;
_pin_irq = irq;
_pin_rst = rst;
_pin_sck = sck;
_pin_miso = miso;
_pin_mosi = mosi;
_pin_cs = digitalPinToGPIONumber(cs);
_pin_irq = digitalPinToGPIONumber(irq);
_pin_rst = digitalPinToGPIONumber(rst);
_pin_sck = digitalPinToGPIONumber(sck);
_pin_miso = digitalPinToGPIONumber(miso);
_pin_mosi = digitalPinToGPIONumber(mosi);

#if ETH_SPI_SUPPORTS_CUSTOM
if(_spi != NULL){
Expand Down
3 changes: 3 additions & 0 deletions libraries/SD_MMC/src/SD_MMC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Disable the automatic pin remapping of the API calls in this file
#define ARDUINO_CORE_BUILD

#include "pins_arduino.h"
#include "io_pin_remap.h"
#include "SD_MMC.h"
Expand Down

0 comments on commit 2dce29f

Please sign in to comment.