Skip to content

upstream changes #194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cores/esp32/esp32-hal-tinyusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "esp32s2/rom/usb/chip_usb_dw_wrapper.h"
#elif CONFIG_IDF_TARGET_ESP32S3
#include "hal/usb_serial_jtag_ll.h"
#include "hal/usb_phy_ll.h"
#include "esp32s3/rom/usb/usb_persist.h"
#include "esp32s3/rom/usb/usb_dc.h"
#include "esp32s3/rom/usb/chip_usb_dw_wrapper.h"
Expand Down Expand Up @@ -415,6 +416,7 @@ static void usb_switch_to_cdc_jtag(){
digitalWrite(USBPHY_DP_NUM, LOW);

// Initialize CDC+JTAG ISR to listen for BUS_RESET
usb_phy_ll_int_jtag_enable(&USB_SERIAL_JTAG);
usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_LL_INTR_MASK);
usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_LL_INTR_MASK);
usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_BUS_RESET);
Expand Down
Empty file.
Empty file.
Empty file.
46 changes: 46 additions & 0 deletions libraries/BluetoothSerial/examples/GetLocalMAC/GetLocalMAC.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// This example demonstrates usage of BluetoothSerial method to retrieve MAC address of local BT device in various formats.
// By Tomas Pilny - 2023

#include "BluetoothSerial.h"

String device_name = "ESP32-example";

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.
#endif

BluetoothSerial SerialBT;

void setup() {
Serial.begin(115200);
SerialBT.begin(device_name); //Bluetooth device name

uint8_t mac_arr[6]; // Byte array to hold the MAC address from getBtAddress()
BTAddress mac_obj; // Object holding instance of BTAddress with the MAC (for more details see libraries/BluetoothSerial/src/BTAddress.h)
String mac_str; // String holding the text version of MAC in format AA:BB:CC:DD:EE:FF

SerialBT.getBtAddress(mac_arr); // Fill in the array
mac_obj = SerialBT.getBtAddressObject(); // Instantiate the object
mac_str = SerialBT.getBtAddressString(); // Copy the string

Serial.print("This device is instantiated with name "); Serial.println(device_name);

Serial.print("The mac address using byte array: ");
for(int i = 0; i < ESP_BD_ADDR_LEN-1; i++){
Serial.print(mac_arr[i], HEX); Serial.print(":");
}
Serial.println(mac_arr[ESP_BD_ADDR_LEN-1], HEX);

Serial.print("The mac address using BTAddress object using default method `toString()`: "); Serial.println(mac_obj.toString().c_str());
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()

Serial.print("The mac address using string: "); Serial.println(mac_str.c_str());
}

void loop(){

}
22 changes: 14 additions & 8 deletions libraries/BluetoothSerial/src/BTAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ BTAddress::BTAddress() {
*
* @param [in] stringAddress The hex representation of the address.
*/
BTAddress::BTAddress(std::string stringAddress) {
BTAddress::BTAddress(String stringAddress) {
if (stringAddress.length() != 17) return;

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

/**
* @brief Convert a BT address to a string.
*
* A string representation of an address is in the format:
*
* @param [in] capital changes the letter size
* By default the parameter `capital` == false and the string representation of an address is in the format:
* ```
* xx:xx:xx:xx:xx:xx
* ```
*
* When the parameter `capital` == true the format uses capital letters:
* ```
* XX:XX:XX:XX:XX:XX
* ```
* @return The string representation of the address.
*/
std::string BTAddress::toString() const {
String BTAddress::toString(bool capital) const {
auto size = 18;
char *res = (char*)malloc(size);
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]);
std::string ret(res);
if(capital){
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]);
}else{
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]);
}
String ret(res);
free(res);
return ret;
} // toString
Expand Down
6 changes: 3 additions & 3 deletions libraries/BluetoothSerial/src/BTAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BLUEDROID_ENABLED)
#include <esp_gap_bt_api.h> // ESP32 BT
#include <string>
#include <Arduino.h>


/**
Expand All @@ -24,12 +24,12 @@ class BTAddress {
public:
BTAddress();
BTAddress(esp_bd_addr_t address);
BTAddress(std::string stringAddress);
BTAddress(String stringAddress);
bool equals(BTAddress otherAddress);
operator bool () const;

esp_bd_addr_t* getNative() const;
std::string toString() const;
String toString(bool capital = false) const;

private:
esp_bd_addr_t m_address;
Expand Down
2 changes: 1 addition & 1 deletion libraries/BluetoothSerial/src/BTAdvertisedDeviceSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bool BTAdvertisedDeviceSet::haveRSSI() const { return m_haveRSSI; }
* @return A string representation of this device.
*/
std::string BTAdvertisedDeviceSet::toString() {
std::string res = "Name: " + getName() + ", Address: " + getAddress().toString();
std::string res = "Name: " + getName() + ", Address: " + std::string(getAddress().toString().c_str(), getAddress().toString().length());
if (haveCOD()) {
char val[6];
snprintf(val, sizeof(val), "%d", getCOD());
Expand Down
2 changes: 1 addition & 1 deletion libraries/BluetoothSerial/src/BTScanResultsSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void BTScanResultsSet::clear() {
}

bool BTScanResultsSet::add(BTAdvertisedDeviceSet advertisedDevice, bool unique) {
std::string key = advertisedDevice.getAddress().toString();
std::string key = std::string(advertisedDevice.getAddress().toString().c_str(), advertisedDevice.getAddress().toString().length());
if (!unique || m_vectorAdvertisedDevices.count(key) == 0) {
m_vectorAdvertisedDevices.insert(std::pair<std::string, BTAdvertisedDeviceSet>(key, advertisedDevice));
return true;
Expand Down
29 changes: 27 additions & 2 deletions libraries/BluetoothSerial/src/BluetoothSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,6 @@ static bool _init_bt(const char *deviceName)
}
}

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

/**
* @brief Gets the MAC address of local BT device in byte array.
*
* @param mac [out] The mac
*/
void BluetoothSerial::getBtAddress(uint8_t *mac) {
const uint8_t *dev_mac = esp_bt_dev_get_address();
memcpy(mac, dev_mac, ESP_BD_ADDR_LEN);
}
/**
* @brief Gets the MAC address of local BT device as BTAddress object.
*
* @return The BTAddress object.
*/
BTAddress BluetoothSerial::getBtAddressObject() {
uint8_t mac_arr[ESP_BD_ADDR_LEN];
getBtAddress(mac_arr);
return BTAddress(mac_arr);
}
/**
* @brief Gets the MAC address of local BT device as string.
*
* @return The BT MAC address string.
*/
String BluetoothSerial::getBtAddressString() {
return getBtAddressObject().toString(true);
}
#endif
3 changes: 3 additions & 0 deletions libraries/BluetoothSerial/src/BluetoothSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class BluetoothSerial: public Stream
const int MAX_INQ_TIME = (ESP_BT_GAP_MAX_INQ_LEN * INQ_TIME);

operator bool() const;
void getBtAddress(uint8_t *mac);
BTAddress getBtAddressObject();
String getBtAddressString();
private:
String local_name;
int timeoutTicks=0;
Expand Down
6 changes: 5 additions & 1 deletion libraries/WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ void setup() {
Serial.println("Configuring access point...");

// You can remove the password parameter if you want the AP to be open.
WiFi.softAP(ssid, password);
// a valid password must have more than 7 characters
if (!WiFi.softAP(ssid, password)) {
log_e("Soft AP creation failed.");
while(1);
}
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
Expand Down
13 changes: 7 additions & 6 deletions libraries/WiFi/src/WiFiAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,6 @@ void wifi_softap_config(wifi_config_t *wifi_config, const char * ssid=NULL, cons
bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel, int ssid_hidden, int max_connection, bool ftm_responder)
{

if(!WiFi.enableAP(true)) {
// enable AP failed
log_e("enable AP first!");
return false;
}

if(!ssid || *ssid == 0) {
// fail SSID missing
log_e("SSID missing!");
Expand All @@ -154,6 +148,13 @@ bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel,
return false;
}

// last step after checking the SSID and password
if(!WiFi.enableAP(true)) {
// enable AP failed
log_e("enable AP first!");
return false;
}

wifi_config_t conf;
wifi_config_t conf_current;
wifi_softap_config(&conf, ssid, passphrase, channel, WIFI_AUTH_WPA2_PSK, ssid_hidden, max_connection, ftm_responder);
Expand Down
9 changes: 7 additions & 2 deletions variants/redpill_esp32s3/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ static const uint8_t LED_BUILTIN = 3;
static const uint8_t TX = 43;
static const uint8_t RX = 44;

static const uint8_t SDA = 11;
static const uint8_t SCL = 10;
static const uint8_t SDA = 8;
static const uint8_t SCL = 9;

static const uint8_t SS = 15;
static const uint8_t MOSI = 16;
static const uint8_t MISO = 17;
static const uint8_t SCK = 18;

static const uint8_t A0 = 1;
static const uint8_t A1 = 2;
Expand Down