Skip to content

Commit

Permalink
Support eth boards without power pin, extend docs (#2855)
Browse files Browse the repository at this point in the history
* fix handling of optional power pin

* add init example for wESP32

* add example for eth.on()
  • Loading branch information
devsaurus authored Aug 12, 2019
1 parent 7ad6bc1 commit d20778e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion components/modules/eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ typedef enum {

static struct {
const eth_config_t *eth_config;
gpio_num_t pin_power, pin_mdc, pin_mdio;
int pin_power;
gpio_num_t pin_mdc, pin_mdio;
} module_config;


Expand Down
27 changes: 27 additions & 0 deletions docs/modules/eth.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,20 @@ An error is thrown in case of invalid parameters or if the ethernet driver faile

#### Example
```lua
-- Initialize ESP32-GATEWAY
eth.init({phy = eth.PHY_LAN8720,
addr = 0,
clock_mode = eth.CLOCK_GPIO17_OUT,
power = 5,
mdc = 23,
mdio = 18})

-- Initialize wESP32
eth.init({phy = eth.PHY_LAN8720,
addr = 0,
clock_mode = eth.CLOCK_GPIO0_IN,
mdc = 16,
mdio = 17})
```


Expand Down Expand Up @@ -111,6 +119,25 @@ Event information provided for each event is as follows:
- `netmask`: the IP netmask
- `gw`: the gateway ("0.0.0.0" if no gateway)

#### Example
```lua
function ev(event, info)
print("event", event)
if event == "got_ip" then
print("ip:"..info.ip..", nm:"..info.netmask..", gw:"..info.gw)
elseif event == "connected" then
print("speed:", eth.get_speed())
print("mac:", eth.get_mac())
end
end

eth.on("connected", ev)
eth.on("disconnected", ev)
eth.on("start", ev)
eth.on("stop", ev)
eth.on("got_ip", ev)
```


## eth.set_mac()
Set MAC address.
Expand Down

0 comments on commit d20778e

Please sign in to comment.