diff options
author | robert-hh <robert@hammelrath.com> | 2022-12-24 16:52:55 +0100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2023-01-18 10:05:13 +1100 |
commit | 4b52003fb822c04651009b109ba403a23965cb0d (patch) | |
tree | 9103011856472fc202443234f8e0da6405412ff9 | |
parent | efb4bd35551ef1de393c088ce6d75ced7e810b64 (diff) |
esp32/network_lan: Support configuration of ETH ref_clk pin.
Both the direction and the Pin used for ref_clk can now be configured. It
Requires at least idf v4.4. The new keyword arguments to the constructor
are:
- ref_clk_mode=mode: with mode being Pin.IN or Pin.OUT. If it is not set,
then the default configuration is used, which may be configured by
kconfig settings.
- ref_clk=pin_obj: which defines the Pin used for ref_clk. This is either
Pin(0), Pin(16) or Pin(17). No check is done for the pin number. If it
is the wrong one, it simply will not work. Besides that, no harm.
-rw-r--r-- | ports/esp32/network_lan.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/ports/esp32/network_lan.c b/ports/esp32/network_lan.c index 3cd1efc04..471e31d62 100644 --- a/ports/esp32/network_lan.c +++ b/ports/esp32/network_lan.c @@ -97,7 +97,8 @@ 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_ref_clk_mode, ARG_ref_clk }; 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 }, @@ -105,6 +106,11 @@ 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_OBJ, {.u_obj = mp_const_none} }, { 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 }, + // Dynamic ref_clk configuration available at v4.4 + #if ESP_IDF_VERSION_MINOR >= 4 + { MP_QSTR_ref_clk_mode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, + { MP_QSTR_ref_clk, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, + #endif }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; @@ -139,6 +145,17 @@ STATIC mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); mac_config.smi_mdc_gpio_num = self->mdc_pin; mac_config.smi_mdio_gpio_num = self->mdio_pin; + // Dynamic ref_clk configuration available at v4.4 + #if ESP_IDF_VERSION_MINOR >= 4 + if (args[ARG_ref_clk_mode].u_int != -1) { + // Map the GPIO_MODE constants to EMAC_CLK constants. + mac_config.clock_config.rmii.clock_mode = + args[ARG_ref_clk_mode].u_int == GPIO_MODE_INPUT ? EMAC_CLK_EXT_IN : EMAC_CLK_OUT; + } + if (args[ARG_ref_clk].u_obj != mp_const_none) { + mac_config.clock_config.rmii.clock_gpio = machine_pin_get_id(args[ARG_ref_clk].u_obj); + } + #endif esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); |