Skip to content

Commit 2ac2764

Browse files
authored
Merge pull request #194 from tasmota/Tasmota/207
upstream changes
2 parents 1ab3a68 + cfd008b commit 2ac2764

File tree

14 files changed

+116
-24
lines changed

14 files changed

+116
-24
lines changed

cores/esp32/esp32-hal-tinyusb.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "esp32s2/rom/usb/chip_usb_dw_wrapper.h"
4141
#elif CONFIG_IDF_TARGET_ESP32S3
4242
#include "hal/usb_serial_jtag_ll.h"
43+
#include "hal/usb_phy_ll.h"
4344
#include "esp32s3/rom/usb/usb_persist.h"
4445
#include "esp32s3/rom/usb/usb_dc.h"
4546
#include "esp32s3/rom/usb/chip_usb_dw_wrapper.h"
@@ -415,6 +416,7 @@ static void usb_switch_to_cdc_jtag(){
415416
digitalWrite(USBPHY_DP_NUM, LOW);
416417

417418
// Initialize CDC+JTAG ISR to listen for BUS_RESET
419+
usb_phy_ll_int_jtag_enable(&USB_SERIAL_JTAG);
418420
usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_LL_INTR_MASK);
419421
usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_LL_INTR_MASK);
420422
usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_BUS_RESET);

libraries/BluetoothSerial/examples/GetLocalMAC/.skip.esp32c3

Whitespace-only changes.

libraries/BluetoothSerial/examples/GetLocalMAC/.skip.esp32s2

Whitespace-only changes.

libraries/BluetoothSerial/examples/GetLocalMAC/.skip.esp32s3

Whitespace-only changes.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// This example demonstrates usage of BluetoothSerial method to retrieve MAC address of local BT device in various formats.
2+
// By Tomas Pilny - 2023
3+
4+
#include "BluetoothSerial.h"
5+
6+
String device_name = "ESP32-example";
7+
8+
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
9+
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
10+
#endif
11+
12+
#if !defined(CONFIG_BT_SPP_ENABLED)
13+
#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.
14+
#endif
15+
16+
BluetoothSerial SerialBT;
17+
18+
void setup() {
19+
Serial.begin(115200);
20+
SerialBT.begin(device_name); //Bluetooth device name
21+
22+
uint8_t mac_arr[6]; // Byte array to hold the MAC address from getBtAddress()
23+
BTAddress mac_obj; // Object holding instance of BTAddress with the MAC (for more details see libraries/BluetoothSerial/src/BTAddress.h)
24+
String mac_str; // String holding the text version of MAC in format AA:BB:CC:DD:EE:FF
25+
26+
SerialBT.getBtAddress(mac_arr); // Fill in the array
27+
mac_obj = SerialBT.getBtAddressObject(); // Instantiate the object
28+
mac_str = SerialBT.getBtAddressString(); // Copy the string
29+
30+
Serial.print("This device is instantiated with name "); Serial.println(device_name);
31+
32+
Serial.print("The mac address using byte array: ");
33+
for(int i = 0; i < ESP_BD_ADDR_LEN-1; i++){
34+
Serial.print(mac_arr[i], HEX); Serial.print(":");
35+
}
36+
Serial.println(mac_arr[ESP_BD_ADDR_LEN-1], HEX);
37+
38+
Serial.print("The mac address using BTAddress object using default method `toString()`: "); Serial.println(mac_obj.toString().c_str());
39+
Serial.print("The mac address using BTAddress object using method `toString(true)`\n\twhich prints the MAC with capital letters: "); Serial.println(mac_obj.toString(true).c_str()); // This actually what is used inside the getBtAddressString()
40+
41+
Serial.print("The mac address using string: "); Serial.println(mac_str.c_str());
42+
}
43+
44+
void loop(){
45+
46+
}

libraries/BluetoothSerial/src/BTAddress.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ BTAddress::BTAddress() {
4444
*
4545
* @param [in] stringAddress The hex representation of the address.
4646
*/
47-
BTAddress::BTAddress(std::string stringAddress) {
47+
BTAddress::BTAddress(String stringAddress) {
4848
if (stringAddress.length() != 17) return;
4949

5050
int data[6];
@@ -86,20 +86,26 @@ esp_bd_addr_t *BTAddress::getNative() const {
8686

8787
/**
8888
* @brief Convert a BT address to a string.
89-
*
90-
* A string representation of an address is in the format:
91-
*
89+
* @param [in] capital changes the letter size
90+
* By default the parameter `capital` == false and the string representation of an address is in the format:
9291
* ```
9392
* xx:xx:xx:xx:xx:xx
9493
* ```
95-
*
94+
* When the parameter `capital` == true the format uses capital letters:
95+
* ```
96+
* XX:XX:XX:XX:XX:XX
97+
* ```
9698
* @return The string representation of the address.
9799
*/
98-
std::string BTAddress::toString() const {
100+
String BTAddress::toString(bool capital) const {
99101
auto size = 18;
100102
char *res = (char*)malloc(size);
101-
snprintf(res, size, "%02x:%02x:%02x:%02x:%02x:%02x", m_address[0], m_address[1], m_address[2], m_address[3], m_address[4], m_address[5]);
102-
std::string ret(res);
103+
if(capital){
104+
snprintf(res, size, "%02X:%02X:%02X:%02X:%02X:%02X", m_address[0], m_address[1], m_address[2], m_address[3], m_address[4], m_address[5]);
105+
}else{
106+
snprintf(res, size, "%02x:%02x:%02x:%02x:%02x:%02x", m_address[0], m_address[1], m_address[2], m_address[3], m_address[4], m_address[5]);
107+
}
108+
String ret(res);
103109
free(res);
104110
return ret;
105111
} // toString

libraries/BluetoothSerial/src/BTAddress.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "sdkconfig.h"
1313
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BLUEDROID_ENABLED)
1414
#include <esp_gap_bt_api.h> // ESP32 BT
15-
#include <string>
15+
#include <Arduino.h>
1616

1717

1818
/**
@@ -24,12 +24,12 @@ class BTAddress {
2424
public:
2525
BTAddress();
2626
BTAddress(esp_bd_addr_t address);
27-
BTAddress(std::string stringAddress);
27+
BTAddress(String stringAddress);
2828
bool equals(BTAddress otherAddress);
2929
operator bool () const;
3030

3131
esp_bd_addr_t* getNative() const;
32-
std::string toString() const;
32+
String toString(bool capital = false) const;
3333

3434
private:
3535
esp_bd_addr_t m_address;

libraries/BluetoothSerial/src/BTAdvertisedDeviceSet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ bool BTAdvertisedDeviceSet::haveRSSI() const { return m_haveRSSI; }
3939
* @return A string representation of this device.
4040
*/
4141
std::string BTAdvertisedDeviceSet::toString() {
42-
std::string res = "Name: " + getName() + ", Address: " + getAddress().toString();
42+
std::string res = "Name: " + getName() + ", Address: " + std::string(getAddress().toString().c_str(), getAddress().toString().length());
4343
if (haveCOD()) {
4444
char val[6];
4545
snprintf(val, sizeof(val), "%d", getCOD());

libraries/BluetoothSerial/src/BTScanResultsSet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void BTScanResultsSet::clear() {
8484
}
8585

8686
bool BTScanResultsSet::add(BTAdvertisedDeviceSet advertisedDevice, bool unique) {
87-
std::string key = advertisedDevice.getAddress().toString();
87+
std::string key = std::string(advertisedDevice.getAddress().toString().c_str(), advertisedDevice.getAddress().toString().length());
8888
if (!unique || m_vectorAdvertisedDevices.count(key) == 0) {
8989
m_vectorAdvertisedDevices.insert(std::pair<std::string, BTAdvertisedDeviceSet>(key, advertisedDevice));
9090
return true;

libraries/BluetoothSerial/src/BluetoothSerial.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,6 @@ static bool _init_bt(const char *deviceName)
661661
}
662662
}
663663

664-
// Why only master need this? Slave need this during pairing as well
665-
// if (_isMaster && esp_bt_gap_register_callback(esp_bt_gap_cb) != ESP_OK) {
666664
if (esp_bt_gap_register_callback(esp_bt_gap_cb) != ESP_OK) {
667665
log_e("gap register failed");
668666
return false;
@@ -1183,4 +1181,31 @@ std::map<int, std::string> BluetoothSerial::getChannels(const BTAddress &remoteA
11831181
return sdpRecords;
11841182
}
11851183

1184+
/**
1185+
* @brief Gets the MAC address of local BT device in byte array.
1186+
*
1187+
* @param mac [out] The mac
1188+
*/
1189+
void BluetoothSerial::getBtAddress(uint8_t *mac) {
1190+
const uint8_t *dev_mac = esp_bt_dev_get_address();
1191+
memcpy(mac, dev_mac, ESP_BD_ADDR_LEN);
1192+
}
1193+
/**
1194+
* @brief Gets the MAC address of local BT device as BTAddress object.
1195+
*
1196+
* @return The BTAddress object.
1197+
*/
1198+
BTAddress BluetoothSerial::getBtAddressObject() {
1199+
uint8_t mac_arr[ESP_BD_ADDR_LEN];
1200+
getBtAddress(mac_arr);
1201+
return BTAddress(mac_arr);
1202+
}
1203+
/**
1204+
* @brief Gets the MAC address of local BT device as string.
1205+
*
1206+
* @return The BT MAC address string.
1207+
*/
1208+
String BluetoothSerial::getBtAddressString() {
1209+
return getBtAddressObject().toString(true);
1210+
}
11861211
#endif

libraries/BluetoothSerial/src/BluetoothSerial.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class BluetoothSerial: public Stream
8585
const int MAX_INQ_TIME = (ESP_BT_GAP_MAX_INQ_LEN * INQ_TIME);
8686

8787
operator bool() const;
88+
void getBtAddress(uint8_t *mac);
89+
BTAddress getBtAddressObject();
90+
String getBtAddressString();
8891
private:
8992
String local_name;
9093
int timeoutTicks=0;

libraries/WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ void setup() {
3232
Serial.println("Configuring access point...");
3333

3434
// You can remove the password parameter if you want the AP to be open.
35-
WiFi.softAP(ssid, password);
35+
// a valid password must have more than 7 characters
36+
if (!WiFi.softAP(ssid, password)) {
37+
log_e("Soft AP creation failed.");
38+
while(1);
39+
}
3640
IPAddress myIP = WiFi.softAPIP();
3741
Serial.print("AP IP address: ");
3842
Serial.println(myIP);

libraries/WiFi/src/WiFiAP.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,6 @@ void wifi_softap_config(wifi_config_t *wifi_config, const char * ssid=NULL, cons
136136
bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel, int ssid_hidden, int max_connection, bool ftm_responder)
137137
{
138138

139-
if(!WiFi.enableAP(true)) {
140-
// enable AP failed
141-
log_e("enable AP first!");
142-
return false;
143-
}
144-
145139
if(!ssid || *ssid == 0) {
146140
// fail SSID missing
147141
log_e("SSID missing!");
@@ -154,6 +148,13 @@ bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel,
154148
return false;
155149
}
156150

151+
// last step after checking the SSID and password
152+
if(!WiFi.enableAP(true)) {
153+
// enable AP failed
154+
log_e("enable AP first!");
155+
return false;
156+
}
157+
157158
wifi_config_t conf;
158159
wifi_config_t conf_current;
159160
wifi_softap_config(&conf, ssid, passphrase, channel, WIFI_AUTH_WPA2_PSK, ssid_hidden, max_connection, ftm_responder);

variants/redpill_esp32s3/pins_arduino.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ static const uint8_t LED_BUILTIN = 3;
2323
static const uint8_t TX = 43;
2424
static const uint8_t RX = 44;
2525

26-
static const uint8_t SDA = 11;
27-
static const uint8_t SCL = 10;
26+
static const uint8_t SDA = 8;
27+
static const uint8_t SCL = 9;
28+
29+
static const uint8_t SS = 15;
30+
static const uint8_t MOSI = 16;
31+
static const uint8_t MISO = 17;
32+
static const uint8_t SCK = 18;
2833

2934
static const uint8_t A0 = 1;
3035
static const uint8_t A1 = 2;

0 commit comments

Comments
 (0)