esp32/network_lan: Add arg to constructor to set clock mode for ETH PHY.
This optional parameter for network.LAN clock_mode can be used for cases where the clock source is different from the default GPIO0. Fixes #4502.
This commit is contained in:
parent
be41d6d6f9
commit
7d8c71c222
@ -41,6 +41,7 @@
|
||||
#include "py/mphal.h"
|
||||
#include "py/mperrno.h"
|
||||
#include "netutils.h"
|
||||
#include "esp_eth.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_wifi_types.h"
|
||||
#include "esp_log.h"
|
||||
@ -697,6 +698,14 @@ STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_PHY_LAN8720), MP_ROM_INT(PHY_LAN8720) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PHY_TLK110), MP_ROM_INT(PHY_TLK110) },
|
||||
|
||||
// ETH Clock modes from ESP-IDF
|
||||
{ MP_ROM_QSTR(MP_QSTR_ETH_CLOCK_GPIO0_IN), MP_ROM_INT(ETH_CLOCK_GPIO0_IN) },
|
||||
// Disabled at Aug 22nd 2018, reenabled Jan 28th 2019 in ESP-IDF
|
||||
// Because we use older SDK, it's currently disabled
|
||||
//{ MP_ROM_QSTR(MP_QSTR_ETH_CLOCK_GPIO0_OUT), MP_ROM_INT(ETH_CLOCK_GPIO0_OUT) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_ETH_CLOCK_GPIO16_OUT), MP_ROM_INT(ETH_CLOCK_GPIO16_OUT) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_ETH_CLOCK_GPIO17_OUT), MP_ROM_INT(ETH_CLOCK_GPIO17_OUT) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_STAT_IDLE), MP_ROM_INT(STAT_IDLE)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_STAT_CONNECTING), MP_ROM_INT(STAT_CONNECTING)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_STAT_GOT_IP), MP_ROM_INT(STAT_GOT_IP)},
|
||||
|
@ -94,7 +94,7 @@ STATIC mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
||||
return MP_OBJ_FROM_PTR(&lan_obj);
|
||||
}
|
||||
|
||||
enum { ARG_id, ARG_mdc, ARG_mdio, ARG_power, ARG_phy_addr, ARG_phy_type };
|
||||
enum { ARG_id, ARG_mdc, ARG_mdio, ARG_power, ARG_phy_addr, ARG_phy_type, ARG_clock_mode };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_id, MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||
{ MP_QSTR_mdc, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
@ -102,6 +102,7 @@ STATIC mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
||||
{ MP_QSTR_power, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_phy_addr, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_phy_type, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_clock_mode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
@ -125,6 +126,15 @@ STATIC mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
||||
mp_raise_ValueError("invalid phy type");
|
||||
}
|
||||
|
||||
if (args[ARG_clock_mode].u_int != -1 &&
|
||||
args[ARG_clock_mode].u_int != ETH_CLOCK_GPIO0_IN &&
|
||||
// Disabled due ESP-IDF (see modnetwork.c note)
|
||||
//args[ARG_clock_mode].u_int != ETH_CLOCK_GPIO0_OUT &&
|
||||
args[ARG_clock_mode].u_int != ETH_CLOCK_GPIO16_OUT &&
|
||||
args[ARG_clock_mode].u_int != ETH_CLOCK_GPIO17_OUT) {
|
||||
mp_raise_ValueError("invalid clock mode");
|
||||
}
|
||||
|
||||
eth_config_t config;
|
||||
|
||||
switch (args[ARG_phy_type].u_int) {
|
||||
@ -146,6 +156,10 @@ STATIC mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
||||
config.gpio_config = init_lan_rmii;
|
||||
config.tcpip_input = tcpip_adapter_eth_input;
|
||||
|
||||
if (args[ARG_clock_mode].u_int != -1) {
|
||||
config.clock_mode = args[ARG_clock_mode].u_int;
|
||||
}
|
||||
|
||||
if (esp_eth_init(&config) == ESP_OK) {
|
||||
self->active = false;
|
||||
self->initialized = true;
|
||||
|
Loading…
Reference in New Issue
Block a user