Skip to content

Commit 8890447

Browse files
committed
Updated ethernet code to match latest networking plugin. Untested!
1 parent 5933cd3 commit 8890447

File tree

3 files changed

+80
-44
lines changed

3 files changed

+80
-44
lines changed

driver.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
"symbol": "BOARD_BTT_RODENT",
7878
"URL": "https://github.com/bigtreetech/Rodent/tree/master",
7979
"MAP": "main/boards/btt_rodent_map.h",
80-
"notes": "Not tested!",
8180
"caps": {
8281
"axes": 5,
8382
"usb_cdc": 0,

main/driver.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3439,7 +3439,7 @@ bool driver_init (void)
34393439
#else
34403440
hal.info = "ESP32";
34413441
#endif
3442-
hal.driver_version = "250420";
3442+
hal.driver_version = "250501";
34433443
hal.driver_url = GRBL_URL "/ESP32";
34443444
#ifdef BOARD_NAME
34453445
hal.board = BOARD_NAME;
@@ -3949,15 +3949,15 @@ IRAM_ATTR static void stepper_driver_isr (void *arg)
39493949

39503950
IRAM_ATTR static void gpio_limit_isr (void *signal)
39513951
{
3952-
if(((input_signal_t *)signal)->debounce)
3952+
if(((input_signal_t *)signal)->cap.debounce)
39533953
task_add_delayed(pin_debounce, (input_signal_t *)signal, 40);
39543954
else
39553955
hal.limits.interrupt_callback(limitsGetState());
39563956
}
39573957

39583958
IRAM_ATTR static void gpio_control_isr (void *signal)
39593959
{
3960-
if(((input_signal_t *)signal)->debounce)
3960+
if(((input_signal_t *)signal)->cap.debounce)
39613961
task_add_delayed(pin_debounce, (input_signal_t *)signal, 40);
39623962
else
39633963
hal.control.interrupt_callback(systemGetState());

main/enet.c

Lines changed: 77 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/*
66
7-
Copyright (c) 2018-2023, Terje Io
7+
Copyright (c) 2018-2025, Terje Io
88
Copyright (c) 2022, @Henrikastro
99
All rights reserved.
1010
@@ -60,6 +60,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6060

6161
#include "grbl/report.h"
6262
#include "grbl/nvs_buffer.h"
63+
#include "grbl/task.h"
64+
6365
#include "networking/networking.h"
6466

6567
#define SYSTICK_INT_PRIORITY 0x80
@@ -87,7 +89,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8789

8890
//
8991

90-
static volatile bool linkUp = false;
92+
static char if_name[NETIF_NAMESIZE] = "";
9193
static stream_type_t active_stream = StreamType_Null;
9294
static network_settings_t network, ethernet;
9395
static network_services_t services = {0}, allowed_services;
@@ -96,6 +98,7 @@ static on_report_options_ptr on_report_options;
9698
static on_stream_changed_ptr on_stream_changed;
9799
static uint8_t mac_addr[6] = {0};
98100
static esp_netif_ip_info_t *ip_info = NULL;
101+
static network_flags_t network_status = {};
99102

100103
static char netservices[NETWORK_SERVICES_LEN] = "";
101104

@@ -110,6 +113,42 @@ static char *enet_ip_address (void)
110113
return ip;
111114
}
112115

116+
static network_info_t *get_info (const char *interface)
117+
{
118+
static network_info_t info = {};
119+
120+
if(interface == if_name) {
121+
122+
memcpy(&info.status, &network, sizeof(network_settings_t));
123+
124+
info.interface = (const char *)if_name;
125+
info.is_ethernet = true;
126+
info.link_up = network_status.link_up;
127+
info.mbps = 100;
128+
info.status.services = services;
129+
*info.mac = *info.status.ip = *info.status.gateway = *info.status.mask = '\0';
130+
131+
struct netif *netif = netif_default;
132+
133+
if(netif) {
134+
135+
sprintf(info.mac, MAC_FORMAT_STRING, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
136+
137+
if(network_status.link_up) {
138+
strcpy(info.status.ip, enet_ip_address());
139+
}
140+
}
141+
142+
#if MQTT_ENABLE
143+
networking_make_mqtt_clientid(info.mac, info.mqtt_client_id);
144+
#endif
145+
146+
return &info;
147+
}
148+
149+
return NULL;
150+
}
151+
113152
static void report_options (bool newopt)
114153
{
115154
on_report_options(newopt);
@@ -122,50 +161,35 @@ static void report_options (bool newopt)
122161
#endif
123162
} else {
124163

125-
network_info_t *net = networking_get_info();
164+
network_info_t *network;
126165

127-
hal.stream.write("[MAC:");
128-
hal.stream.write(net->mac);
129-
hal.stream.write("]" ASCII_EOL);
166+
if((network = get_info(if_name))) {
130167

131-
hal.stream.write("[IP:");
132-
hal.stream.write(net->status.ip);
133-
hal.stream.write("]" ASCII_EOL);
168+
hal.stream.write("[MAC:");
169+
hal.stream.write(network->mac);
170+
hal.stream.write("]" ASCII_EOL);
134171

135-
if(active_stream == StreamType_Telnet || active_stream == StreamType_WebSocket) {
136-
hal.stream.write("[NETCON:");
137-
hal.stream.write(active_stream == StreamType_Telnet ? "Telnet" : "Websocket");
172+
hal.stream.write("[IP:");
173+
hal.stream.write(network->status.ip);
138174
hal.stream.write("]" ASCII_EOL);
175+
176+
if(active_stream == StreamType_Telnet || active_stream == StreamType_WebSocket) {
177+
hal.stream.write("[NETCON:");
178+
hal.stream.write(active_stream == StreamType_Telnet ? "Telnet" : "Websocket");
179+
hal.stream.write("]" ASCII_EOL);
180+
}
139181
}
140182
}
141183
}
142184

143-
network_info_t *networking_get_info (void)
185+
static void status_event_out (void *data)
144186
{
145-
static network_info_t info;
146-
147-
memcpy(&info.status, &network, sizeof(network_settings_t));
148-
149-
sprintf(info.mac, MAC_FORMAT_STRING, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
150-
151-
if(ip_info)
152-
strcpy(info.status.ip, enet_ip_address());
153-
154-
if(info.status.ip_mode == IpMode_DHCP) {
155-
*info.status.gateway = '\0';
156-
*info.status.mask = '\0';
157-
}
158-
159-
info.is_ethernet = true;
160-
info.link_up = linkUp;
161-
info.mbps = 100;
162-
info.status.services = services;
163-
164-
#if MQTT_ENABLE
165-
networking_make_mqtt_clientid(info.mac, info.mqtt_client_id);
166-
#endif
187+
networking.event(if_name, (network_status_t){ .value = (uint32_t)data });
188+
}
167189

168-
return &info;
190+
static void status_event_publish (network_flags_t changed)
191+
{
192+
task_add_immediate(status_event_out, (void *)((network_status_t){ .changed = changed, .flags = network_status }).value);
169193
}
170194

171195
static void lwIPHostTimerHandler (void *arg)
@@ -208,6 +232,11 @@ static void start_services (void)
208232
#if TELNET_ENABLE || WEBSOCKET_ENABLE || FTP_ENABLE
209233
sys_timeout(STREAM_POLL_INTERVAL, lwIPHostTimerHandler, NULL);
210234
#endif
235+
236+
if(!network_status.ip_aquired) {
237+
network_status.ip_aquired = On;
238+
status_event_publish((network_flags_t){ .ip_aquired = On });
239+
}
211240
}
212241

213242
/** Event handler for Ethernet events */
@@ -216,13 +245,15 @@ static void eth_event_handler (void *arg, esp_event_base_t event_base, int32_t e
216245
switch (event_id) {
217246

218247
case ETHERNET_EVENT_CONNECTED:
219-
linkUp = true;
220248
esp_eth_ioctl(*(esp_eth_handle_t *)event_data, ETH_CMD_G_MAC_ADDR, mac_addr);
249+
network_status.link_up = On;
250+
status_event_publish((network_flags_t){ .link_up = On });
221251
break;
222252

223253
case ETHERNET_EVENT_DISCONNECTED:
224-
linkUp = false;
225254
ip_info = NULL;
255+
network_status.link_up = Off;
256+
status_event_publish((network_flags_t){ .link_up = On });
226257
break;
227258
/*
228259
case ETHERNET_EVENT_START:
@@ -237,7 +268,7 @@ static void eth_event_handler (void *arg, esp_event_base_t event_base, int32_t e
237268
}
238269

239270
/** Event handler for IP_EVENT_ETH_GOT_IP */
240-
static void got_ip_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
271+
static void got_ip_event_handler (void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
241272
{
242273
static esp_netif_ip_info_t info;
243274

@@ -339,6 +370,11 @@ bool enet_start (void)
339370
/* start Ethernet driver state machine */
340371
ESP_ERROR_CHECK(esp_eth_start(eth_handle));
341372

373+
netif_index_to_name(1, if_name);
374+
375+
network_status.interface_up = On;
376+
status_event_publish((network_flags_t){ .interface_up = On });
377+
342378
return true;
343379
}
344380

@@ -544,10 +580,11 @@ bool enet_init (void)
544580

545581
settings_register(&setting_details);
546582

583+
networking.get_info = get_info;
547584
allowed_services.mask = networking_get_services_list((char *)netservices).mask;
548585
}
549586

550587
return true;
551588
}
552589

553-
#endif
590+
#endif // ETHERNET_ENABLE

0 commit comments

Comments
 (0)