Skip to content

Commit afb6786

Browse files
cpqcesantabot
authored andcommitted
Nitpick for arch docs
PUBLISHED_FROM=b9241ebdb781c3a44b4a81cf24b6f3e8611ade1d
1 parent 524c9d5 commit afb6786

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

mos.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
author: mongoose-os
2+
description: Ethernet support
3+
type: lib
4+
version: 1.0
5+
6+
config_schema:
7+
- ["eth", "o", {title: "Ethernet settings"}]
8+
- ["eth.enable", "b", false, {title: "Enable Ethernet interface"}]
9+
10+
tags:
11+
- c
12+
- ethernet
13+
- hw
14+
15+
skeleton_version: 2017-06-16

mos_esp32.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
sources:
2+
- src/esp32
3+
4+
cdefs:
5+
# 8720 or 8710 in RMII mode.
6+
MGOS_ETH_PHY_LAN87x0: 1
7+
8+
config_schema:
9+
- ["eth.phy_addr", "i", 0, {title: "RMII PHY address"}]
10+
- ["eth.mdc_gpio", "i", 23, {title: "GPIO to use for RMII MDC signal"}]
11+
- ["eth.mdio_gpio", "i", 18, {title: "GPIO to use for RMII MDIO signal"}]

src/esp32/esp32_eth.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2014-2017 Cesanta Software Limited
3+
* All rights reserved
4+
*/
5+
6+
#include <stdbool.h>
7+
8+
#include "esp_eth.h"
9+
#include "eth_phy/phy_lan8720.h"
10+
#include "eth_phy/phy_tlk110.h"
11+
#include "tcpip_adapter.h"
12+
13+
#include "fw/src/mgos_net.h"
14+
#include "fw/src/mgos_net_hal.h"
15+
#include "fw/src/mgos_sys_config.h"
16+
17+
static void eth_config_pins(void) {
18+
phy_rmii_configure_data_interface_pins();
19+
phy_rmii_smi_configure_pins(get_cfg()->eth.mdc_gpio,
20+
get_cfg()->eth.mdio_gpio);
21+
}
22+
23+
bool mgos_ethernet_init(void) {
24+
struct sys_config_eth *ecfg = &get_cfg()->eth;
25+
if (!ecfg->enable) return true;
26+
27+
eth_config_t config;
28+
const char *phy_model;
29+
#if defined(MGOS_ETH_PHY_LAN87x0)
30+
phy_model = "LAN87x0";
31+
config = phy_lan8720_default_ethernet_config;
32+
#elif defined(MGOS_ETH_PHY_TLK110)
33+
phy_model = "TLK110";
34+
config = phy_tlk110_default_ethernet_config;
35+
#else
36+
#error Unknown/unspecified PHY model
37+
#endif
38+
39+
/* Set the PHY address in the example configuration */
40+
config.phy_addr = ecfg->phy_addr;
41+
config.gpio_config = eth_config_pins;
42+
config.tcpip_input = tcpip_adapter_eth_input;
43+
44+
LOG(LL_INFO, ("Eth init: %s PHY @ %d", phy_model, ecfg->phy_addr));
45+
esp_err_t ret = esp_eth_init(&config);
46+
if (ret == ESP_OK) {
47+
esp_eth_enable();
48+
} else {
49+
LOG(LL_ERROR, ("Ethernet init failed: %d", ret));
50+
return false;
51+
}
52+
53+
return true;
54+
}
55+
56+
bool mgos_eth_dev_get_ip_info(int if_instance,
57+
struct mgos_net_ip_info *ip_info) {
58+
tcpip_adapter_ip_info_t info;
59+
if (if_instance != 0 ||
60+
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &info) != ESP_OK ||
61+
info.ip.addr == 0) {
62+
return false;
63+
}
64+
ip_info->ip.sin_addr.s_addr = info.ip.addr;
65+
ip_info->netmask.sin_addr.s_addr = info.netmask.addr;
66+
ip_info->gw.sin_addr.s_addr = info.gw.addr;
67+
return true;
68+
}

0 commit comments

Comments
 (0)