Skip to content

Commit 600f4c4

Browse files
authored
Update IDF to 1c3dd23
* Update mDNS and LEDC * update toolchain * Update IDF to 1c3dd23 * Advertise the board variant for Arduino OTA * Add generic variant definition for mDNS
1 parent 70d0d46 commit 600f4c4

File tree

150 files changed

+7079
-3732
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+7079
-3732
lines changed

cores/esp32/esp32-hal-bt.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BLUEDROID_ENABLED)
1818

1919

20-
#include "bt.h"
20+
#include "esp_bt.h"
2121
#include "esp_bt_defs.h"
2222
#include "esp_bt_main.h"
2323

cores/esp32/esp32-hal-ledc.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ static void _ledcSetupTimer(uint8_t chan, uint32_t div_num, uint8_t bit_num, boo
6868
#endif
6969
}
7070
LEDC_MUTEX_LOCK();
71-
LEDC_TIMER(group, timer).conf.div_num = div_num;//18 bit (10.8) This register is used to configure parameter for divider in timer the least significant eight bits represent the decimal part.
72-
LEDC_TIMER(group, timer).conf.bit_num = bit_num;//5 bit This register controls the range of the counter in timer. the counter range is [0 2**bit_num] the max bit width for counter is 20.
71+
LEDC_TIMER(group, timer).conf.clock_divider = div_num;//18 bit (10.8) This register is used to configure parameter for divider in timer the least significant eight bits represent the decimal part.
72+
LEDC_TIMER(group, timer).conf.duty_resolution = bit_num;//5 bit This register controls the range of the counter in timer. the counter range is [0 2**bit_num] the max bit width for counter is 20.
7373
LEDC_TIMER(group, timer).conf.tick_sel = apb_clk;//apb clock
7474
if(group) {
7575
LEDC_TIMER(group, timer).conf.low_speed_update = 1;//This bit is only useful for low speed timer channels, reserved for high speed timers
@@ -111,8 +111,8 @@ static double _ledcTimerRead(uint8_t chan)
111111
bool apb_clk;
112112
uint8_t group=(chan/8), timer=((chan/2)%4);
113113
LEDC_MUTEX_LOCK();
114-
div_num = LEDC_TIMER(group, timer).conf.div_num;//18 bit (10.8) This register is used to configure parameter for divider in timer the least significant eight bits represent the decimal part.
115-
bit_num = LEDC_TIMER(group, timer).conf.bit_num;//5 bit This register controls the range of the counter in timer. the counter range is [0 2**bit_num] the max bit width for counter is 20.
114+
div_num = LEDC_TIMER(group, timer).conf.clock_divider;//18 bit (10.8) This register is used to configure parameter for divider in timer the least significant eight bits represent the decimal part.
115+
bit_num = LEDC_TIMER(group, timer).conf.duty_resolution;//5 bit This register controls the range of the counter in timer. the counter range is [0 2**bit_num] the max bit width for counter is 20.
116116
apb_clk = LEDC_TIMER(group, timer).conf.tick_sel;//apb clock
117117
LEDC_MUTEX_UNLOCK();
118118
uint64_t clk_freq = 1000000;

libraries/ESPmDNS/src/ESPmDNS.cpp

+118-52
Original file line numberDiff line numberDiff line change
@@ -39,144 +39,210 @@ License (MIT license):
3939
#endif
4040

4141
#include "ESPmDNS.h"
42+
#include "WiFi.h"
4243
#include <functional>
4344
#include "esp_wifi.h"
4445

45-
MDNSResponder::MDNSResponder() : mdns(NULL), _if(TCPIP_ADAPTER_IF_STA) {}
46+
static void _on_sys_event(system_event_t *event){
47+
mdns_handle_system_event(NULL, event);
48+
}
49+
50+
MDNSResponder::MDNSResponder() :results(NULL) {}
4651
MDNSResponder::~MDNSResponder() {
4752
end();
4853
}
4954

50-
bool MDNSResponder::begin(const char* hostName, tcpip_adapter_if_t tcpip_if, uint32_t ttl){
51-
_if = tcpip_if;
52-
if(!mdns && mdns_init(_if, &mdns)){
55+
bool MDNSResponder::begin(const char* hostName){
56+
if(mdns_init()){
5357
log_e("Failed starting MDNS");
5458
return false;
5559
}
60+
WiFi.onEvent(_on_sys_event);
5661
_hostname = hostName;
57-
if(mdns_set_hostname(mdns, hostName)) {
62+
if(mdns_hostname_set(hostName)) {
5863
log_e("Failed setting MDNS hostname");
5964
return false;
6065
}
6166
return true;
6267
}
6368

6469
void MDNSResponder::end() {
65-
if(!mdns){
66-
return;
67-
}
68-
mdns_free(mdns);
69-
mdns = NULL;
70+
mdns_free();
7071
}
7172

7273
void MDNSResponder::setInstanceName(String name) {
7374
if (name.length() > 63) return;
74-
if(mdns_set_instance(mdns, name.c_str())){
75+
if(mdns_instance_name_set(name.c_str())){
7576
log_e("Failed setting MDNS instance");
7677
return;
7778
}
7879
}
7980

81+
8082
void MDNSResponder::enableArduino(uint16_t port, bool auth){
81-
const char * arduTxtData[4] = {
82-
"board=" ARDUINO_BOARD,
83-
"tcp_check=no",
84-
"ssh_upload=no",
85-
"auth_upload=no"
83+
mdns_txt_item_t arduTxtData[4] = {
84+
{(char*)"board" ,(char*)ARDUINO_VARIANT},
85+
{(char*)"tcp_check" ,(char*)"no"},
86+
{(char*)"ssh_upload" ,(char*)"no"},
87+
{(char*)"auth_upload" ,(char*)"no"}
8688
};
87-
if(auth){
88-
arduTxtData[3] = "auth_upload=yes";
89-
}
9089

91-
if(mdns_service_add(mdns, "_arduino", "_tcp", port)) {
90+
if(mdns_service_add(NULL, "_arduino", "_tcp", port, arduTxtData, 4)) {
9291
log_e("Failed adding Arduino service");
93-
} else if(mdns_service_txt_set(mdns, "_arduino", "_tcp", 4, arduTxtData)) {
94-
log_e("Failed setting Arduino service TXT");
92+
}
93+
94+
if(auth && mdns_service_txt_item_set("_arduino", "_tcp", "auth_upload", "yes")){
95+
log_e("Failed setting Arduino txt item");
9596
}
9697
}
9798

9899
void MDNSResponder::disableArduino(){
99-
if(mdns_service_remove(mdns, "_arduino", "_tcp")) {
100+
if(mdns_service_remove("_arduino", "_tcp")) {
100101
log_w("Failed removing Arduino service");
101102
}
102103
}
103104

104-
void MDNSResponder::enableWorkstation(){
105+
void MDNSResponder::enableWorkstation(wifi_interface_t interface){
105106
char winstance[21+_hostname.length()];
106107
uint8_t mac[6];
107-
esp_wifi_get_mac((wifi_interface_t)_if, mac);
108+
esp_wifi_get_mac(interface, mac);
108109
sprintf(winstance, "%s [%02x:%02x:%02x:%02x:%02x:%02x]", _hostname.c_str(), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
109110

110-
if(mdns_service_add(mdns, "_workstation", "_tcp", 9)) {
111+
if(mdns_service_add(NULL, "_workstation", "_tcp", 9, NULL, 0)) {
111112
log_e("Failed adding Workstation service");
112-
} else if(mdns_service_instance_set(mdns, "_workstation", "_tcp", winstance)) {
113+
} else if(mdns_service_instance_name_set("_workstation", "_tcp", winstance)) {
113114
log_e("Failed setting Workstation service instance name");
114115
}
115116
}
116117

117118
void MDNSResponder::disableWorkstation(){
118-
if(mdns_service_remove(mdns, "_workstation", "_tcp")) {
119+
if(mdns_service_remove("_workstation", "_tcp")) {
119120
log_w("Failed removing Workstation service");
120121
}
121122
}
122123

123124
void MDNSResponder::addService(char *name, char *proto, uint16_t port){
124-
if(mdns_service_add(mdns, name, proto, port)) {
125+
if(mdns_service_add(NULL, name, proto, port, NULL, 0)) {
125126
log_e("Failed adding service %s.%s.\n", name, proto);
126127
}
127128
}
128129

129130
bool MDNSResponder::addServiceTxt(char *name, char *proto, char *key, char *value){
130-
//ToDo: implement it in IDF. This will set the TXT to one record currently
131-
String txt = String(key) + "=" + String(value);
132-
const char * txt_chr[1] = {txt.c_str()};
133-
if(mdns_service_txt_set(mdns, name, proto, 1, txt_chr)) {
131+
if(mdns_service_txt_item_set(name, proto, key, value)) {
134132
log_e("Failed setting service TXT");
135133
return false;
136134
}
137135
return true;
138136
}
139137

140-
int MDNSResponder::queryService(char *service, char *proto) {
141-
mdns_result_free(mdns);
142-
if(proto){
143-
char srv[strlen(service)+2];
144-
char prt[strlen(proto)+2];
145-
sprintf(srv, "_%s", service);
146-
sprintf(prt, "_%s", proto);
147-
return mdns_query(mdns, srv, prt, 2000);
138+
IPAddress MDNSResponder::queryHost(char *host, uint32_t timeout){
139+
struct ip4_addr addr;
140+
addr.addr = 0;
141+
142+
esp_err_t err = mdns_query_a(host, timeout, &addr);
143+
if(err){
144+
if(err == ESP_ERR_NOT_FOUND){
145+
log_w("Host was not found!");
146+
return IPAddress();
147+
}
148+
log_e("Query Failed");
149+
return IPAddress();
148150
}
149-
return mdns_query(mdns, service, NULL, 2000);
151+
return IPAddress(addr.addr);
150152
}
151153

152-
IPAddress MDNSResponder::queryHost(char *host){
153-
mdns_result_free(mdns);
154-
if(!mdns_query(mdns, host, NULL, 2000)){
155-
return IPAddress();
154+
155+
int MDNSResponder::queryService(char *service, char *proto) {
156+
if(!service || !service[0] || !proto || !proto[0]){
157+
log_e("Bad Parameters");
158+
return 0;
159+
}
160+
161+
if(results){
162+
mdns_query_results_free(results);
163+
results = NULL;
156164
}
157-
return IP(0);
165+
166+
char srv[strlen(service)+2];
167+
char prt[strlen(proto)+2];
168+
sprintf(srv, "_%s", service);
169+
sprintf(prt, "_%s", proto);
170+
171+
esp_err_t err = mdns_query_ptr(srv, prt, 3000, 20, &results);
172+
if(err){
173+
log_e("Query Failed");
174+
return 0;
175+
}
176+
if(!results){
177+
log_w("No results found!");
178+
return 0;
179+
}
180+
181+
mdns_result_t * r = results;
182+
int i = 0;
183+
while(r){
184+
i++;
185+
r = r->next;
186+
}
187+
return i;
188+
}
189+
190+
mdns_result_t * MDNSResponder::_getResult(int idx){
191+
mdns_result_t * result = results;
192+
int i = 0;
193+
while(result){
194+
if(i == idx){
195+
break;
196+
}
197+
i++;
198+
result = result->next;
199+
}
200+
return result;
158201
}
159202

160203
String MDNSResponder::hostname(int idx) {
161-
const mdns_result_t * result = mdns_result_get(mdns, idx);
204+
mdns_result_t * result = _getResult(idx);
162205
if(!result){
163206
log_e("Result %d not found", idx);
164207
return String();
165208
}
166-
return String(result->host);
209+
return String(result->hostname);
167210
}
168211

169212
IPAddress MDNSResponder::IP(int idx) {
170-
const mdns_result_t * result = mdns_result_get(mdns, idx);
213+
mdns_result_t * result = _getResult(idx);
171214
if(!result){
172215
log_e("Result %d not found", idx);
173216
return IPAddress();
174217
}
175-
return IPAddress(result->addr.addr);
218+
mdns_ip_addr_t * addr = result->addr;
219+
while(addr){
220+
if(addr->addr.type == MDNS_IP_PROTOCOL_V4){
221+
return IPAddress(addr->addr.u_addr.ip4.addr);
222+
}
223+
addr = addr->next;
224+
}
225+
return IPAddress();
226+
}
227+
228+
IPv6Address MDNSResponder::IPv6(int idx) {
229+
mdns_result_t * result = _getResult(idx);
230+
if(!result){
231+
log_e("Result %d not found", idx);
232+
return IPv6Address();
233+
}
234+
mdns_ip_addr_t * addr = result->addr;
235+
while(addr){
236+
if(addr->addr.type == MDNS_IP_PROTOCOL_V6){
237+
return IPv6Address(addr->addr.u_addr.ip6.addr);
238+
}
239+
addr = addr->next;
240+
}
241+
return IPv6Address();
176242
}
177243

178244
uint16_t MDNSResponder::port(int idx) {
179-
const mdns_result_t * result = mdns_result_get(mdns, idx);
245+
mdns_result_t * result = _getResult(idx);
180246
if(!result){
181247
log_e("Result %d not found", idx);
182248
return 0;

libraries/ESPmDNS/src/ESPmDNS.h

+13-11
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,19 @@ License (MIT license):
4242
#define ESP32MDNS_H
4343

4444
#include "Arduino.h"
45+
#include "IPv6Address.h"
4546
#include "mdns.h"
4647

4748
//this should be defined at build time
48-
#ifndef ARDUINO_BOARD
49-
#define ARDUINO_BOARD "esp32"
49+
#ifndef ARDUINO_VARIANT
50+
#define ARDUINO_VARIANT "esp32"
5051
#endif
5152

5253
class MDNSResponder {
5354
public:
5455
MDNSResponder();
5556
~MDNSResponder();
56-
bool begin(const char* hostName, tcpip_adapter_if_t tcpip_if=TCPIP_ADAPTER_IF_STA, uint32_t ttl=120);
57+
bool begin(const char* hostName);
5758
void end();
5859

5960
void setInstanceName(String name);
@@ -83,15 +84,15 @@ class MDNSResponder {
8384
void enableArduino(uint16_t port=3232, bool auth=false);
8485
void disableArduino();
8586

86-
void enableWorkstation();
87+
void enableWorkstation(wifi_interface_t interface=ESP_IF_WIFI_STA);
8788
void disableWorkstation();
8889

89-
IPAddress queryHost(char *host);
90-
IPAddress queryHost(const char *host){
91-
return queryHost((char *)host);
90+
IPAddress queryHost(char *host, uint32_t timeout=2000);
91+
IPAddress queryHost(const char *host, uint32_t timeout=2000){
92+
return queryHost((char *)host, timeout);
9293
}
93-
IPAddress queryHost(String host){
94-
return queryHost(host.c_str());
94+
IPAddress queryHost(String host, uint32_t timeout=2000){
95+
return queryHost(host.c_str(), timeout);
9596
}
9697

9798
int queryService(char *service, char *proto);
@@ -104,12 +105,13 @@ class MDNSResponder {
104105

105106
String hostname(int idx);
106107
IPAddress IP(int idx);
108+
IPv6Address IPv6(int idx);
107109
uint16_t port(int idx);
108110

109111
private:
110-
mdns_server_t * mdns;
111-
tcpip_adapter_if_t _if;
112112
String _hostname;
113+
mdns_result_t * results;
114+
mdns_result_t * _getResult(int idx);
113115
};
114116

115117
extern MDNSResponder MDNS;

libraries/WiFi/src/ETH.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ extern void tcpipInit();
3030
static int _eth_phy_mdc_pin = -1;
3131
static int _eth_phy_mdio_pin = -1;
3232
static int _eth_phy_power_pin = -1;
33-
static eth_clock_mode_t _eth_clk_mode = ETH_CLOCK_GPIO0_IN;
3433
static eth_phy_power_enable_func _eth_phy_power_enable_orig = NULL;
3534

3635
static void _eth_phy_config_gpio(void)

0 commit comments

Comments
 (0)