2 Achegas 8f75dfaa7f ... 5bca0f3aa2

Autor SHA1 Mensaxe Data
  xnecas 5bca0f3aa2 Merge branch 'master' of repo.vyskumnecentrum.sk:esp32-drivers/wireless-serial-for-esp32 hai 1 semana
  xnecas ea7f1dbc42 Updated to Arduiono Core 3X hai 1 semana

+ 8 - 5
src/BleSerial/Client/BleSerialClient.cpp

@@ -1,5 +1,7 @@
 #include "BleSerialClient.h"
-#include "Arduino.h"
+
+#if defined(SOC_BLE_SUPPORTED) || defined(CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE)
+#if defined(CONFIG_BLUEDROID_ENABLED) || defined(CONFIG_NIMBLE_ENABLED)
 
 BleSerialClient::BleSerialClient(const char* server_name) : _xAdvertisedCallbacks{server_name}
 {
@@ -77,7 +79,7 @@ bool BleSerialClient::connect()
 
     _pClient->setClientCallbacks(&_xClientCallbacks);
     _pClient->connect(_xAdvertisedCallbacks.getAdvertisedDevice());
-    _pClient->setMTU(ESP_GATT_MAX_MTU_SIZE);
+    _pClient->setMTU(BLE_SERIAL_MAX_MTU_SIZE);
 
     // Get reference to remote service
     _pNusRemoteService = _pClient->getService(BLE_SERIAL_NUS_SERVICE_UUID);
@@ -114,13 +116,11 @@ bool BleSerialClient::BleSerialClientCallbacks::isConnected()
 void BleSerialClient::BleSerialClientCallbacks::onConnect(BLEClient* pclient) 
 {
     _bConnected = true;
-   // digitalWrite(8, LOW);
 }
 
 void BleSerialClient::BleSerialClientCallbacks::onDisconnect(BLEClient* pclient) 
 {
     _bConnected = false;
-   // digitalWrite(8, HIGH);
 }
 
 BleSerialClient::BleSerialAdvertisedCallbacks::BleSerialAdvertisedCallbacks(const char* server_name) 
@@ -153,4 +153,7 @@ void BleSerialClient::BleSerialAdvertisedCallbacks::onResult(BLEAdvertisedDevice
         _xAdvertisedDevice = advertisedDevice;
         _bFound = true;
     }
-}
+}
+
+#endif /* CONFIG_BLUEDROID_ENABLED || CONFIG_NIMBLE_ENABLED */
+#endif /* SOC_BLE_SUPPORTED || CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE */

+ 10 - 0
src/BleSerial/Client/BleSerialClient.h

@@ -1,6 +1,12 @@
 #ifndef _BLE_SERIAL_CLIENT_H_
 #define _BLE_SERIAL_CLIENT_H_
 
+// check if BLE supported
+#include "sdkconfig.h"
+#include "soc/soc_caps.h"
+#if defined(SOC_BLE_SUPPORTED) || defined(CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE)
+#if defined(CONFIG_BLUEDROID_ENABLED) || defined(CONFIG_NIMBLE_ENABLED)
+
 #include <BLEDevice.h>
 #include <Stream.h>
 #include "IoQueue/IoQueue.h"
@@ -102,4 +108,8 @@ private:
     BLERemoteCharacteristic*              _pTxRemoteCharacteristic{nullptr};
 };
 
+#endif /* CONFIG_BLUEDROID_ENABLED || CONFIG_NIMBLE_ENABLED */
+#endif /* SOC_BLE_SUPPORTED || CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE */
+
+
 #endif // _BLE_SERIAL_CLIENT_H_

+ 8 - 2
src/BleSerial/Server/BleSerialServer.cpp

@@ -1,5 +1,8 @@
 #include "BleSerialServer.h"
 
+#if defined(SOC_BLE_SUPPORTED) || defined(CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE)
+#if defined(CONFIG_BLUEDROID_ENABLED) || defined(CONFIG_NIMBLE_ENABLED)
+
 bool BleSerialServer::begin(const char *server_name)
 {
     // Create the BLE Device
@@ -10,7 +13,7 @@ bool BleSerialServer::begin(const char *server_name)
     _rxBuffer.init();                                                
 
     BLEDevice::init(server_name);
-    BLEDevice::setMTU(BLE_SERIAL_RX_BUFFER_SIZE);
+    BLEDevice::setMTU(BLE_SERIAL_MAX_MTU_SIZE);
 
     // Create the BLE Server
     _pServer = BLEDevice::createServer();
@@ -119,4 +122,7 @@ void BleSerialServer::BleSerialRxCharCallbacks::onWrite(BLECharacteristic *pChar
 {
     if (pCharacteristic == _pServerInstance->_pRxCharacteristic)
         _pServerInstance->_rxBuffer.write_data(pCharacteristic->getData(), pCharacteristic->getLength());
-}
+}
+
+#endif /* CONFIG_BLUEDROID_ENABLED || CONFIG_NIMBLE_ENABLED */
+#endif /* SOC_BLE_SUPPORTED || CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE */

+ 11 - 0
src/BleSerial/Server/BleSerialServer.h

@@ -1,6 +1,12 @@
 #ifndef _BLE_SERIAL_SERVER_H_
 #define _BLE_SERIAL_SERVER_H_
 
+// check if BLE supported
+#include "sdkconfig.h"
+#include "soc/soc_caps.h"
+#if defined(SOC_BLE_SUPPORTED) || defined(CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE)
+#if defined(CONFIG_BLUEDROID_ENABLED) || defined(CONFIG_NIMBLE_ENABLED)
+
 #include <BLEDevice.h>
 #include <BLE2902.h>
 #include <Stream.h>
@@ -84,4 +90,9 @@ private:
     BLEServerCallbacks*                   _pServerCallbacks = nullptr;
 };
 
+
+#endif /* CONFIG_BLUEDROID_ENABLED || CONFIG_NIMBLE_ENABLED */
+#endif /* SOC_BLE_SUPPORTED || CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE */
+
+
 #endif // _BLE_SERIAL_SERVER_H_

+ 16 - 2
src/BleSerial/defines.h

@@ -1,11 +1,25 @@
 #ifndef _BLE_SERIAL_DEFINES_H_
 #define _BLE_SERIAL_DEFINES_H_
 
-#include <esp_gatt_common_api.h>    // for ESP_GATT_MAX_MTU_SIZE
+// check if BLE supported
+#include "sdkconfig.h"
+#include "soc/soc_caps.h"
+#if defined(SOC_BLE_SUPPORTED) || defined(CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE)
+#if defined(CONFIG_BLUEDROID_ENABLED) || defined(CONFIG_NIMBLE_ENABLED)
 
-#define BLE_SERIAL_RX_BUFFER_SIZE           ESP_GATT_MAX_MTU_SIZE
+
+// include MTU SIZE
+#include <esp_gatt_common_api.h> 
+#define BLE_SERIAL_MAX_MTU_SIZE             ESP_GATT_MAX_MTU_SIZE
+
+#define BLE_SERIAL_RX_BUFFER_SIZE           BLE_SERIAL_MAX_MTU_SIZE
 #define BLE_SERIAL_NUS_SERVICE_UUID         "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"
 #define BLE_SERIAL_CHARACTERISTIC_RX_UUID   "6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
 #define BLE_SERIAL_CHARACTERISTIC_TX_UUID   "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"
 
+
+#endif /* CONFIG_BLUEDROID_ENABLED || CONFIG_NIMBLE_ENABLED */
+#endif /* SOC_BLE_SUPPORTED || CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE */
+
+
 #endif // _BLE_SERIAL_DEFINES_H_

+ 25 - 1
src/EspNowSerial/EspNowSerial.cpp

@@ -1,5 +1,8 @@
 #include "EspNowSerial.h"
 
+#if SOC_WIFI_SUPPORTED || CONFIG_ESP_HOSTED_ENABLED
+
+
 EspNowSerial* EspNowSerial::_instance = nullptr;
 
 EspNowSerial::EspNowSerial(wifi_mode_t mode)
@@ -137,6 +140,8 @@ size_t EspNowSerial::write(const uint8_t *buffer, size_t size)
     return size;
 }
 
+#if !defined(ARDUINO_CORE_3X)
+
 void EspNowSerial::_on_data_sent(const uint8_t *mac_addr, esp_now_send_status_t status) 
 {
     EspNowSerial::_instance->_data_sent = status;
@@ -145,4 +150,23 @@ void EspNowSerial::_on_data_sent(const uint8_t *mac_addr, esp_now_send_status_t
 void EspNowSerial::_on_data_recv(const uint8_t *mac_addr, const uint8_t *data, int len) 
 {
     EspNowSerial::_instance->_rx_queue.write_data((uint8_t*)data, len);
-}
+}
+
+#else // ARDUINO_CORE_3X
+
+void EspNowSerial::_on_data_sent(const esp_now_send_info_t *tx_info, esp_now_send_status_t status)
+{
+    EspNowSerial::_instance->_data_sent = 1;
+}
+
+
+void EspNowSerial::_on_data_recv(const esp_now_recv_info_t * esp_now_info, const uint8_t *data, int data_len)
+{
+    EspNowSerial::_instance->_rx_queue.write_data((uint8_t*)data, data_len);
+}
+
+
+#endif /* SOC_WIFI_SUPPORTED */
+
+
+#endif // ARDUINO_CORE_3X

+ 28 - 0
src/EspNowSerial/EspNowSerial.h

@@ -1,6 +1,10 @@
 #ifndef _ESPNOW_SERIAL_H_
 #define _ESPNOW_SERIAL_H_
 
+#include "soc/soc_caps.h"
+#include "sdkconfig.h"
+#if SOC_WIFI_SUPPORTED || CONFIG_ESP_HOSTED_ENABLED
+
 #include <Stream.h>
 #include <WiFi.h>
 #include <esp_wifi.h>
@@ -139,6 +143,7 @@ public:
 
 private:
 
+#if !defined(ARDUINO_CORE_3X)
     /**
      * @brief ESP-NOW send-complete callback.
      *
@@ -158,6 +163,25 @@ private:
     static void _on_data_recv(const uint8_t *mac_addr,
                               const uint8_t *data,
                               int len);
+#else // ARDUINO_CORE_3X
+
+    /**
+     * @brief     Callback function of sending ESPNOW data
+     * @param     tx_info Sending information for ESPNOW data
+     * @param     status status of sending ESPNOW data (succeed or fail).
+     */
+    static void _on_data_sent(const esp_now_send_info_t *tx_info, esp_now_send_status_t status);
+
+    /**
+     * @brief     Callback function of receiving ESPNOW data
+     * @param     esp_now_info received ESPNOW packet information
+     * @param     data received data
+     * @param     data_len length of received data
+     * @attention esp_now_info is a local variable,it can only be used in the callback.
+     */
+    static void _on_data_recv(const esp_now_recv_info_t * esp_now_info, const uint8_t *data, int data_len);
+
+#endif // ARDUINO_CORE_3X
 
     wifi_mode_t _wifi_mode;                                        ///< Configured WiFi mode
     wifi_interface_t _wifi_if;                                     ///< WiFi interface in use
@@ -172,4 +196,8 @@ private:
     IoQueue<ESP_NOW_MAX_DATA_LEN> _rx_queue;                       ///< Internal RX buffer
 };
 
+
+#endif /* SOC_WIFI_SUPPORTED */
+
+
 #endif // _ESPNOW_SERIAL_H_